[PATCH 2/57][Arm][GAS] Add support for MVE instructions: vpst, vadd, vsub and vabd
[binutils-gdb.git] / gas / config / tc-arm.c
blob46d0f4e7b59914ebc7e01730b549215a4dd435bf
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2019 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"
36 #ifdef OBJ_ELF
37 #include "elf/arm.h"
38 #include "dw2gencfi.h"
39 #endif
41 #include "dwarf2dbg.h"
43 #ifdef OBJ_ELF
44 /* Must be at least the size of the largest unwind opcode (currently two). */
45 #define ARM_OPCODE_CHUNK_SIZE 8
47 /* This structure holds the unwinding state. */
49 static struct
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
55 /* The segment containing the function. */
56 segT saved_seg;
57 subsegT saved_subseg;
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
60 int opcode_count;
61 int opcode_alloc;
62 /* The number of bytes pushed to the stack. */
63 offsetT frame_size;
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
67 offsetT pending_offset;
68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
72 /* Nonzero if an unwind_setfp directive has been seen. */
73 unsigned fp_used:1;
74 /* Nonzero if the last opcode restores sp from fp_reg. */
75 unsigned sp_restored:1;
76 } unwind;
78 /* Whether --fdpic was given. */
79 static int arm_fdpic;
81 #endif /* OBJ_ELF */
83 /* Results from operand parsing worker functions. */
85 typedef enum
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90 } parse_operand_result;
92 enum arm_float_abi
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
99 /* Types of processor to assemble for. */
100 #ifndef CPU_DEFAULT
101 /* The code that was here used to select a default CPU depending on compiler
102 pre-defines which were only present when doing native builds, thus
103 changing gas' default behaviour depending upon the build host.
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
107 #endif
109 #ifndef FPU_DEFAULT
110 # ifdef TE_LINUX
111 # define FPU_DEFAULT FPU_ARCH_FPA
112 # elif defined (TE_NetBSD)
113 # ifdef OBJ_ELF
114 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115 # else
116 /* Legacy a.out format. */
117 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118 # endif
119 # elif defined (TE_VXWORKS)
120 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
121 # else
122 /* For backwards compatibility, default to FPA. */
123 # define FPU_DEFAULT FPU_ARCH_FPA
124 # endif
125 #endif /* ifndef FPU_DEFAULT */
127 #define streq(a, b) (strcmp (a, b) == 0)
129 /* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
132 static arm_feature_set cpu_variant;
133 /* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
135 static arm_feature_set arm_arch_used;
136 static arm_feature_set thumb_arch_used;
138 /* Flags stored in private area of BFD structure. */
139 static int uses_apcs_26 = FALSE;
140 static int atpcs = FALSE;
141 static int support_interwork = FALSE;
142 static int uses_apcs_float = FALSE;
143 static int pic_code = FALSE;
144 static int fix_v4bx = FALSE;
145 /* Warn on using deprecated features. */
146 static int warn_on_deprecated = TRUE;
148 /* Understand CodeComposer Studio assembly syntax. */
149 bfd_boolean codecomposer_syntax = FALSE;
151 /* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
155 /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157 static const arm_feature_set *legacy_cpu = NULL;
158 static const arm_feature_set *legacy_fpu = NULL;
160 /* CPU, extension and FPU feature bits selected by -mcpu. */
161 static const arm_feature_set *mcpu_cpu_opt = NULL;
162 static arm_feature_set *mcpu_ext_opt = NULL;
163 static const arm_feature_set *mcpu_fpu_opt = NULL;
165 /* CPU, extension and FPU feature bits selected by -march. */
166 static const arm_feature_set *march_cpu_opt = NULL;
167 static arm_feature_set *march_ext_opt = NULL;
168 static const arm_feature_set *march_fpu_opt = NULL;
170 /* Feature bits selected by -mfpu. */
171 static const arm_feature_set *mfpu_opt = NULL;
173 /* Constants for known architecture features. */
174 static const arm_feature_set fpu_default = FPU_DEFAULT;
175 static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
176 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
177 static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178 static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
179 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
181 #ifdef OBJ_ELF
182 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
183 #endif
184 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
186 #ifdef CPU_DEFAULT
187 static const arm_feature_set cpu_default = CPU_DEFAULT;
188 #endif
190 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
191 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
192 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
198 static const arm_feature_set arm_ext_v4t_5 =
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
207 /* Only for compatability of hint instructions. */
208 static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
210 static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212 static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214 static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216 static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
222 #ifdef OBJ_ELF
223 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
224 #endif
225 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
226 static const arm_feature_set arm_ext_m =
227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
229 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
234 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
235 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
236 static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
238 static const arm_feature_set arm_ext_v8_1m_main =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
240 /* Instructions in ARMv8-M only found in M profile architectures. */
241 static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
243 static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
245 /* Instructions shared between ARMv8-A and ARMv8-M. */
246 static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
248 #ifdef OBJ_ELF
249 /* DSP instructions Tag_DSP_extension refers to. */
250 static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
252 #endif
253 static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
255 /* FP16 instructions. */
256 static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
258 static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
260 static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
262 static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
264 static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
266 static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
269 static const arm_feature_set arm_arch_any = ARM_ANY;
270 #ifdef OBJ_ELF
271 static const arm_feature_set fpu_any = FPU_ANY;
272 #endif
273 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
274 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
277 static const arm_feature_set arm_cext_iwmmxt2 =
278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
279 static const arm_feature_set arm_cext_iwmmxt =
280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
281 static const arm_feature_set arm_cext_xscale =
282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
283 static const arm_feature_set arm_cext_maverick =
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285 static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287 static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
289 static const arm_feature_set fpu_vfp_ext_v1xd =
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291 static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293 static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295 static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297 static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
299 static const arm_feature_set fpu_vfp_ext_d32 =
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301 static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
303 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
305 static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307 static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
309 #ifdef OBJ_ELF
310 static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312 static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
314 #endif
315 static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
317 static const arm_feature_set fpu_vfp_ext_armv8 =
318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
319 static const arm_feature_set fpu_vfp_ext_armv8xd =
320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
321 static const arm_feature_set fpu_neon_ext_armv8 =
322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
323 static const arm_feature_set fpu_crypto_ext_armv8 =
324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
325 static const arm_feature_set crc_ext_armv8 =
326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
327 static const arm_feature_set fpu_neon_ext_v8_1 =
328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
329 static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
332 static int mfloat_abi_opt = -1;
333 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335 static arm_feature_set selected_arch = ARM_ARCH_NONE;
336 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338 static arm_feature_set selected_ext = ARM_ARCH_NONE;
339 /* Feature bits selected by the last -mcpu/-march or by the combination of the
340 last .cpu/.arch directive .arch_extension directives since that
341 directive. */
342 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
343 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
344 static arm_feature_set selected_fpu = FPU_NONE;
345 /* Feature bits selected by the last .object_arch directive. */
346 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
347 /* Must be long enough to hold any of the names in arm_cpus. */
348 static char selected_cpu_name[20];
350 extern FLONUM_TYPE generic_floating_point_number;
352 /* Return if no cpu was selected on command-line. */
353 static bfd_boolean
354 no_cpu_selected (void)
356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
359 #ifdef OBJ_ELF
360 # ifdef EABI_DEFAULT
361 static int meabi_flags = EABI_DEFAULT;
362 # else
363 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
364 # endif
366 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
368 bfd_boolean
369 arm_is_eabi (void)
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
373 #endif
375 #ifdef OBJ_ELF
376 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
377 symbolS * GOT_symbol;
378 #endif
380 /* 0: assemble for ARM,
381 1: assemble for Thumb,
382 2: assemble for Thumb even though target CPU does not support thumb
383 instructions. */
384 static int thumb_mode = 0;
385 /* A value distinct from the possible values for thumb_mode that we
386 can use to record whether thumb_mode has been copied into the
387 tc_frag_data field of a frag. */
388 #define MODE_RECORDED (1 << 4)
390 /* Specifies the intrinsic IT insn behavior mode. */
391 enum implicit_it_mode
393 IMPLICIT_IT_MODE_NEVER = 0x00,
394 IMPLICIT_IT_MODE_ARM = 0x01,
395 IMPLICIT_IT_MODE_THUMB = 0x02,
396 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
398 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
400 /* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
403 - Immediate operands do not require a # prefix.
404 - Conditional affixes always appear at the end of the
405 instruction. (For backward compatibility, those instructions
406 that formerly had them in the middle, continue to accept them
407 there.)
408 - The IT instruction may appear, and if it does is validated
409 against subsequent conditional affixes. It does not generate
410 machine code.
412 Important differences from the old Thumb mode:
414 - Immediate operands do not require a # prefix.
415 - Most of the V6T2 instructions are only available in unified mode.
416 - The .N and .W suffixes are recognized and honored (it is an error
417 if they cannot be honored).
418 - All instructions set the flags if and only if they have an 's' affix.
419 - Conditional affixes may be used. They are validated against
420 preceding IT instructions. Unlike ARM mode, you cannot use a
421 conditional affix except in the scope of an IT instruction. */
423 static bfd_boolean unified_syntax = FALSE;
425 /* An immediate operand can start with #, and ld*, st*, pld operands
426 can contain [ and ]. We need to tell APP not to elide whitespace
427 before a [, which can appear as the first operand for pld.
428 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
429 const char arm_symbol_chars[] = "#[]{}";
431 enum neon_el_type
433 NT_invtype,
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
439 NT_unsigned
442 struct neon_type_el
444 enum neon_el_type type;
445 unsigned size;
448 #define NEON_MAX_TYPE_ELS 4
450 struct neon_type
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
456 enum pred_instruction_type
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
463 if inside, should be the last one. */
464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
465 i.e. BKPT and NOP. */
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
468 MVE_OUTSIDE_PRED_INSN /* Instruction to indicate a MVE instruction without
469 a predication code. */
472 /* The maximum number of operands we need. */
473 #define ARM_IT_MAX_OPERANDS 6
474 #define ARM_IT_MAX_RELOCS 3
476 struct arm_it
478 const char * error;
479 unsigned long instruction;
480 int size;
481 int size_req;
482 int cond;
483 /* "uncond_value" is set to the value in place of the conditional field in
484 unconditional versions of the instruction, or -1 if nothing is
485 appropriate. */
486 int uncond_value;
487 struct neon_type vectype;
488 /* This does not indicate an actual NEON instruction, only that
489 the mnemonic accepts neon-style type suffixes. */
490 int is_neon;
491 /* Set to the opcode if the instruction needs relaxation.
492 Zero if the instruction is not relaxed. */
493 unsigned long relax;
494 struct
496 bfd_reloc_code_real_type type;
497 expressionS exp;
498 int pc_rel;
499 } relocs[ARM_IT_MAX_RELOCS];
501 enum pred_instruction_type pred_insn_type;
503 struct
505 unsigned reg;
506 signed int imm;
507 struct neon_type_el vectype;
508 unsigned present : 1; /* Operand present. */
509 unsigned isreg : 1; /* Operand was a register. */
510 unsigned immisreg : 1; /* .imm field is a second register. */
511 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
512 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
513 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
514 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
515 instructions. This allows us to disambiguate ARM <-> vector insns. */
516 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
517 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
518 unsigned isquad : 1; /* Operand is SIMD quad register. */
519 unsigned issingle : 1; /* Operand is VFP single-precision register. */
520 unsigned hasreloc : 1; /* Operand has relocation suffix. */
521 unsigned writeback : 1; /* Operand has trailing ! */
522 unsigned preind : 1; /* Preindexed address. */
523 unsigned postind : 1; /* Postindexed address. */
524 unsigned negative : 1; /* Index register was negated. */
525 unsigned shifted : 1; /* Shift applied to operation. */
526 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
527 } operands[ARM_IT_MAX_OPERANDS];
530 static struct arm_it inst;
532 #define NUM_FLOAT_VALS 8
534 const char * fp_const[] =
536 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
539 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
541 #define FAIL (-1)
542 #define SUCCESS (0)
544 #define SUFF_S 1
545 #define SUFF_D 2
546 #define SUFF_E 3
547 #define SUFF_P 4
549 #define CP_T_X 0x00008000
550 #define CP_T_Y 0x00400000
552 #define CONDS_BIT 0x00100000
553 #define LOAD_BIT 0x00100000
555 #define DOUBLE_LOAD_FLAG 0x00000001
557 struct asm_cond
559 const char * template_name;
560 unsigned long value;
563 #define COND_ALWAYS 0xE
565 struct asm_psr
567 const char * template_name;
568 unsigned long field;
571 struct asm_barrier_opt
573 const char * template_name;
574 unsigned long value;
575 const arm_feature_set arch;
578 /* The bit that distinguishes CPSR and SPSR. */
579 #define SPSR_BIT (1 << 22)
581 /* The individual PSR flag bits. */
582 #define PSR_c (1 << 16)
583 #define PSR_x (1 << 17)
584 #define PSR_s (1 << 18)
585 #define PSR_f (1 << 19)
587 struct reloc_entry
589 const char * name;
590 bfd_reloc_code_real_type reloc;
593 enum vfp_reg_pos
595 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
596 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
599 enum vfp_ldstm_type
601 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
604 /* Bits for DEFINED field in neon_typed_alias. */
605 #define NTA_HASTYPE 1
606 #define NTA_HASINDEX 2
608 struct neon_typed_alias
610 unsigned char defined;
611 unsigned char index;
612 struct neon_type_el eltype;
615 /* ARM register categories. This includes coprocessor numbers and various
616 architecture extensions' registers. Each entry should have an error message
617 in reg_expected_msgs below. */
618 enum arm_reg_type
620 REG_TYPE_RN,
621 REG_TYPE_CP,
622 REG_TYPE_CN,
623 REG_TYPE_FN,
624 REG_TYPE_VFS,
625 REG_TYPE_VFD,
626 REG_TYPE_NQ,
627 REG_TYPE_VFSD,
628 REG_TYPE_NDQ,
629 REG_TYPE_NSD,
630 REG_TYPE_NSDQ,
631 REG_TYPE_VFC,
632 REG_TYPE_MVF,
633 REG_TYPE_MVD,
634 REG_TYPE_MVFX,
635 REG_TYPE_MVDX,
636 REG_TYPE_MVAX,
637 REG_TYPE_MQ,
638 REG_TYPE_DSPSC,
639 REG_TYPE_MMXWR,
640 REG_TYPE_MMXWC,
641 REG_TYPE_MMXWCG,
642 REG_TYPE_XSCALE,
643 REG_TYPE_RNB,
646 /* Structure for a hash table entry for a register.
647 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
648 information which states whether a vector type or index is specified (for a
649 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
650 struct reg_entry
652 const char * name;
653 unsigned int number;
654 unsigned char type;
655 unsigned char builtin;
656 struct neon_typed_alias * neon;
659 /* Diagnostics used when we don't get a register of the expected type. */
660 const char * const reg_expected_msgs[] =
662 [REG_TYPE_RN] = N_("ARM register expected"),
663 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
664 [REG_TYPE_CN] = N_("co-processor register expected"),
665 [REG_TYPE_FN] = N_("FPA register expected"),
666 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
667 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
668 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
669 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
670 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
671 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
672 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
673 " expected"),
674 [REG_TYPE_VFC] = N_("VFP system register expected"),
675 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
676 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
677 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
678 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
679 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
680 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
681 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
682 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
683 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
684 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
685 [REG_TYPE_MQ] = N_("MVE vector register expected"),
686 [REG_TYPE_RNB] = N_("")
689 /* Some well known registers that we refer to directly elsewhere. */
690 #define REG_R12 12
691 #define REG_SP 13
692 #define REG_LR 14
693 #define REG_PC 15
695 /* ARM instructions take 4bytes in the object file, Thumb instructions
696 take 2: */
697 #define INSN_SIZE 4
699 struct asm_opcode
701 /* Basic string to match. */
702 const char * template_name;
704 /* Parameters to instruction. */
705 unsigned int operands[8];
707 /* Conditional tag - see opcode_lookup. */
708 unsigned int tag : 4;
710 /* Basic instruction code. */
711 unsigned int avalue : 28;
713 /* Thumb-format instruction code. */
714 unsigned int tvalue;
716 /* Which architecture variant provides this instruction. */
717 const arm_feature_set * avariant;
718 const arm_feature_set * tvariant;
720 /* Function to call to encode instruction in ARM format. */
721 void (* aencode) (void);
723 /* Function to call to encode instruction in Thumb format. */
724 void (* tencode) (void);
726 /* Indicates whether this instruction may be vector predicated. */
727 unsigned int mayBeVecPred : 1;
730 /* Defines for various bits that we will want to toggle. */
731 #define INST_IMMEDIATE 0x02000000
732 #define OFFSET_REG 0x02000000
733 #define HWOFFSET_IMM 0x00400000
734 #define SHIFT_BY_REG 0x00000010
735 #define PRE_INDEX 0x01000000
736 #define INDEX_UP 0x00800000
737 #define WRITE_BACK 0x00200000
738 #define LDM_TYPE_2_OR_3 0x00400000
739 #define CPSI_MMOD 0x00020000
741 #define LITERAL_MASK 0xf000f000
742 #define OPCODE_MASK 0xfe1fffff
743 #define V4_STR_BIT 0x00000020
744 #define VLDR_VMOV_SAME 0x0040f000
746 #define T2_SUBS_PC_LR 0xf3de8f00
748 #define DATA_OP_SHIFT 21
749 #define SBIT_SHIFT 20
751 #define T2_OPCODE_MASK 0xfe1fffff
752 #define T2_DATA_OP_SHIFT 21
753 #define T2_SBIT_SHIFT 20
755 #define A_COND_MASK 0xf0000000
756 #define A_PUSH_POP_OP_MASK 0x0fff0000
758 /* Opcodes for pushing/poping registers to/from the stack. */
759 #define A1_OPCODE_PUSH 0x092d0000
760 #define A2_OPCODE_PUSH 0x052d0004
761 #define A2_OPCODE_POP 0x049d0004
763 /* Codes to distinguish the arithmetic instructions. */
764 #define OPCODE_AND 0
765 #define OPCODE_EOR 1
766 #define OPCODE_SUB 2
767 #define OPCODE_RSB 3
768 #define OPCODE_ADD 4
769 #define OPCODE_ADC 5
770 #define OPCODE_SBC 6
771 #define OPCODE_RSC 7
772 #define OPCODE_TST 8
773 #define OPCODE_TEQ 9
774 #define OPCODE_CMP 10
775 #define OPCODE_CMN 11
776 #define OPCODE_ORR 12
777 #define OPCODE_MOV 13
778 #define OPCODE_BIC 14
779 #define OPCODE_MVN 15
781 #define T2_OPCODE_AND 0
782 #define T2_OPCODE_BIC 1
783 #define T2_OPCODE_ORR 2
784 #define T2_OPCODE_ORN 3
785 #define T2_OPCODE_EOR 4
786 #define T2_OPCODE_ADD 8
787 #define T2_OPCODE_ADC 10
788 #define T2_OPCODE_SBC 11
789 #define T2_OPCODE_SUB 13
790 #define T2_OPCODE_RSB 14
792 #define T_OPCODE_MUL 0x4340
793 #define T_OPCODE_TST 0x4200
794 #define T_OPCODE_CMN 0x42c0
795 #define T_OPCODE_NEG 0x4240
796 #define T_OPCODE_MVN 0x43c0
798 #define T_OPCODE_ADD_R3 0x1800
799 #define T_OPCODE_SUB_R3 0x1a00
800 #define T_OPCODE_ADD_HI 0x4400
801 #define T_OPCODE_ADD_ST 0xb000
802 #define T_OPCODE_SUB_ST 0xb080
803 #define T_OPCODE_ADD_SP 0xa800
804 #define T_OPCODE_ADD_PC 0xa000
805 #define T_OPCODE_ADD_I8 0x3000
806 #define T_OPCODE_SUB_I8 0x3800
807 #define T_OPCODE_ADD_I3 0x1c00
808 #define T_OPCODE_SUB_I3 0x1e00
810 #define T_OPCODE_ASR_R 0x4100
811 #define T_OPCODE_LSL_R 0x4080
812 #define T_OPCODE_LSR_R 0x40c0
813 #define T_OPCODE_ROR_R 0x41c0
814 #define T_OPCODE_ASR_I 0x1000
815 #define T_OPCODE_LSL_I 0x0000
816 #define T_OPCODE_LSR_I 0x0800
818 #define T_OPCODE_MOV_I8 0x2000
819 #define T_OPCODE_CMP_I8 0x2800
820 #define T_OPCODE_CMP_LR 0x4280
821 #define T_OPCODE_MOV_HR 0x4600
822 #define T_OPCODE_CMP_HR 0x4500
824 #define T_OPCODE_LDR_PC 0x4800
825 #define T_OPCODE_LDR_SP 0x9800
826 #define T_OPCODE_STR_SP 0x9000
827 #define T_OPCODE_LDR_IW 0x6800
828 #define T_OPCODE_STR_IW 0x6000
829 #define T_OPCODE_LDR_IH 0x8800
830 #define T_OPCODE_STR_IH 0x8000
831 #define T_OPCODE_LDR_IB 0x7800
832 #define T_OPCODE_STR_IB 0x7000
833 #define T_OPCODE_LDR_RW 0x5800
834 #define T_OPCODE_STR_RW 0x5000
835 #define T_OPCODE_LDR_RH 0x5a00
836 #define T_OPCODE_STR_RH 0x5200
837 #define T_OPCODE_LDR_RB 0x5c00
838 #define T_OPCODE_STR_RB 0x5400
840 #define T_OPCODE_PUSH 0xb400
841 #define T_OPCODE_POP 0xbc00
843 #define T_OPCODE_BRANCH 0xe000
845 #define THUMB_SIZE 2 /* Size of thumb instruction. */
846 #define THUMB_PP_PC_LR 0x0100
847 #define THUMB_LOAD_BIT 0x0800
848 #define THUMB2_LOAD_BIT 0x00100000
850 #define BAD_SYNTAX _("syntax error")
851 #define BAD_ARGS _("bad arguments to instruction")
852 #define BAD_SP _("r13 not allowed here")
853 #define BAD_PC _("r15 not allowed here")
854 #define BAD_COND _("instruction cannot be conditional")
855 #define BAD_OVERLAP _("registers may not be the same")
856 #define BAD_HIREG _("lo register required")
857 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
858 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
859 #define BAD_BRANCH _("branch must be last instruction in IT block")
860 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
861 #define BAD_NOT_IT _("instruction not allowed in IT block")
862 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
863 #define BAD_FPU _("selected FPU does not support instruction")
864 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
865 #define BAD_OUT_VPT \
866 _("vector predicated instruction should be in VPT/VPST block")
867 #define BAD_IT_COND _("incorrect condition in IT block")
868 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
869 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
870 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
871 #define BAD_PC_ADDRESSING \
872 _("cannot use register index with PC-relative addressing")
873 #define BAD_PC_WRITEBACK \
874 _("cannot use writeback with PC-relative addressing")
875 #define BAD_RANGE _("branch out of range")
876 #define BAD_FP16 _("selected processor does not support fp16 instruction")
877 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
878 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
879 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
880 "block")
881 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
882 "block")
883 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
884 " operand")
885 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
886 " operand")
888 static struct hash_control * arm_ops_hsh;
889 static struct hash_control * arm_cond_hsh;
890 static struct hash_control * arm_vcond_hsh;
891 static struct hash_control * arm_shift_hsh;
892 static struct hash_control * arm_psr_hsh;
893 static struct hash_control * arm_v7m_psr_hsh;
894 static struct hash_control * arm_reg_hsh;
895 static struct hash_control * arm_reloc_hsh;
896 static struct hash_control * arm_barrier_opt_hsh;
898 /* Stuff needed to resolve the label ambiguity
901 label: <insn>
902 may differ from:
904 label:
905 <insn> */
907 symbolS * last_label_seen;
908 static int label_is_thumb_function_name = FALSE;
910 /* Literal pool structure. Held on a per-section
911 and per-sub-section basis. */
913 #define MAX_LITERAL_POOL_SIZE 1024
914 typedef struct literal_pool
916 expressionS literals [MAX_LITERAL_POOL_SIZE];
917 unsigned int next_free_entry;
918 unsigned int id;
919 symbolS * symbol;
920 segT section;
921 subsegT sub_section;
922 #ifdef OBJ_ELF
923 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
924 #endif
925 struct literal_pool * next;
926 unsigned int alignment;
927 } literal_pool;
929 /* Pointer to a linked list of literal pools. */
930 literal_pool * list_of_pools = NULL;
932 typedef enum asmfunc_states
934 OUTSIDE_ASMFUNC,
935 WAITING_ASMFUNC_NAME,
936 WAITING_ENDASMFUNC
937 } asmfunc_states;
939 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
941 #ifdef OBJ_ELF
942 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
943 #else
944 static struct current_pred now_pred;
945 #endif
947 static inline int
948 now_pred_compatible (int cond)
950 return (cond & ~1) == (now_pred.cc & ~1);
953 static inline int
954 conditional_insn (void)
956 return inst.cond != COND_ALWAYS;
959 static int in_pred_block (void);
961 static int handle_pred_state (void);
963 static void force_automatic_it_block_close (void);
965 static void it_fsm_post_encode (void);
967 #define set_pred_insn_type(type) \
968 do \
970 inst.pred_insn_type = type; \
971 if (handle_pred_state () == FAIL) \
972 return; \
974 while (0)
976 #define set_pred_insn_type_nonvoid(type, failret) \
977 do \
979 inst.pred_insn_type = type; \
980 if (handle_pred_state () == FAIL) \
981 return failret; \
983 while(0)
985 #define set_pred_insn_type_last() \
986 do \
988 if (inst.cond == COND_ALWAYS) \
989 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
990 else \
991 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
993 while (0)
995 /* Pure syntax. */
997 /* This array holds the chars that always start a comment. If the
998 pre-processor is disabled, these aren't very useful. */
999 char arm_comment_chars[] = "@";
1001 /* This array holds the chars that only start a comment at the beginning of
1002 a line. If the line seems to have the form '# 123 filename'
1003 .line and .file directives will appear in the pre-processed output. */
1004 /* Note that input_file.c hand checks for '#' at the beginning of the
1005 first line of the input file. This is because the compiler outputs
1006 #NO_APP at the beginning of its output. */
1007 /* Also note that comments like this one will always work. */
1008 const char line_comment_chars[] = "#";
1010 char arm_line_separator_chars[] = ";";
1012 /* Chars that can be used to separate mant
1013 from exp in floating point numbers. */
1014 const char EXP_CHARS[] = "eE";
1016 /* Chars that mean this number is a floating point constant. */
1017 /* As in 0f12.456 */
1018 /* or 0d1.2345e12 */
1020 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
1022 /* Prefix characters that indicate the start of an immediate
1023 value. */
1024 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1026 /* Separator character handling. */
1028 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1030 static inline int
1031 skip_past_char (char ** str, char c)
1033 /* PR gas/14987: Allow for whitespace before the expected character. */
1034 skip_whitespace (*str);
1036 if (**str == c)
1038 (*str)++;
1039 return SUCCESS;
1041 else
1042 return FAIL;
1045 #define skip_past_comma(str) skip_past_char (str, ',')
1047 /* Arithmetic expressions (possibly involving symbols). */
1049 /* Return TRUE if anything in the expression is a bignum. */
1051 static bfd_boolean
1052 walk_no_bignums (symbolS * sp)
1054 if (symbol_get_value_expression (sp)->X_op == O_big)
1055 return TRUE;
1057 if (symbol_get_value_expression (sp)->X_add_symbol)
1059 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1060 || (symbol_get_value_expression (sp)->X_op_symbol
1061 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1064 return FALSE;
1067 static bfd_boolean in_my_get_expression = FALSE;
1069 /* Third argument to my_get_expression. */
1070 #define GE_NO_PREFIX 0
1071 #define GE_IMM_PREFIX 1
1072 #define GE_OPT_PREFIX 2
1073 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1074 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1075 #define GE_OPT_PREFIX_BIG 3
1077 static int
1078 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1080 char * save_in;
1082 /* In unified syntax, all prefixes are optional. */
1083 if (unified_syntax)
1084 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1085 : GE_OPT_PREFIX;
1087 switch (prefix_mode)
1089 case GE_NO_PREFIX: break;
1090 case GE_IMM_PREFIX:
1091 if (!is_immediate_prefix (**str))
1093 inst.error = _("immediate expression requires a # prefix");
1094 return FAIL;
1096 (*str)++;
1097 break;
1098 case GE_OPT_PREFIX:
1099 case GE_OPT_PREFIX_BIG:
1100 if (is_immediate_prefix (**str))
1101 (*str)++;
1102 break;
1103 default:
1104 abort ();
1107 memset (ep, 0, sizeof (expressionS));
1109 save_in = input_line_pointer;
1110 input_line_pointer = *str;
1111 in_my_get_expression = TRUE;
1112 expression (ep);
1113 in_my_get_expression = FALSE;
1115 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1117 /* We found a bad or missing expression in md_operand(). */
1118 *str = input_line_pointer;
1119 input_line_pointer = save_in;
1120 if (inst.error == NULL)
1121 inst.error = (ep->X_op == O_absent
1122 ? _("missing expression") :_("bad expression"));
1123 return 1;
1126 /* Get rid of any bignums now, so that we don't generate an error for which
1127 we can't establish a line number later on. Big numbers are never valid
1128 in instructions, which is where this routine is always called. */
1129 if (prefix_mode != GE_OPT_PREFIX_BIG
1130 && (ep->X_op == O_big
1131 || (ep->X_add_symbol
1132 && (walk_no_bignums (ep->X_add_symbol)
1133 || (ep->X_op_symbol
1134 && walk_no_bignums (ep->X_op_symbol))))))
1136 inst.error = _("invalid constant");
1137 *str = input_line_pointer;
1138 input_line_pointer = save_in;
1139 return 1;
1142 *str = input_line_pointer;
1143 input_line_pointer = save_in;
1144 return SUCCESS;
1147 /* Turn a string in input_line_pointer into a floating point constant
1148 of type TYPE, and store the appropriate bytes in *LITP. The number
1149 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1150 returned, or NULL on OK.
1152 Note that fp constants aren't represent in the normal way on the ARM.
1153 In big endian mode, things are as expected. However, in little endian
1154 mode fp constants are big-endian word-wise, and little-endian byte-wise
1155 within the words. For example, (double) 1.1 in big endian mode is
1156 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1157 the byte sequence 99 99 f1 3f 9a 99 99 99.
1159 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1161 const char *
1162 md_atof (int type, char * litP, int * sizeP)
1164 int prec;
1165 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1166 char *t;
1167 int i;
1169 switch (type)
1171 case 'f':
1172 case 'F':
1173 case 's':
1174 case 'S':
1175 prec = 2;
1176 break;
1178 case 'd':
1179 case 'D':
1180 case 'r':
1181 case 'R':
1182 prec = 4;
1183 break;
1185 case 'x':
1186 case 'X':
1187 prec = 5;
1188 break;
1190 case 'p':
1191 case 'P':
1192 prec = 5;
1193 break;
1195 default:
1196 *sizeP = 0;
1197 return _("Unrecognized or unsupported floating point constant");
1200 t = atof_ieee (input_line_pointer, type, words);
1201 if (t)
1202 input_line_pointer = t;
1203 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1205 if (target_big_endian)
1207 for (i = 0; i < prec; i++)
1209 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1210 litP += sizeof (LITTLENUM_TYPE);
1213 else
1215 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1216 for (i = prec - 1; i >= 0; i--)
1218 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1219 litP += sizeof (LITTLENUM_TYPE);
1221 else
1222 /* For a 4 byte float the order of elements in `words' is 1 0.
1223 For an 8 byte float the order is 1 0 3 2. */
1224 for (i = 0; i < prec; i += 2)
1226 md_number_to_chars (litP, (valueT) words[i + 1],
1227 sizeof (LITTLENUM_TYPE));
1228 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1229 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1230 litP += 2 * sizeof (LITTLENUM_TYPE);
1234 return NULL;
1237 /* We handle all bad expressions here, so that we can report the faulty
1238 instruction in the error message. */
1240 void
1241 md_operand (expressionS * exp)
1243 if (in_my_get_expression)
1244 exp->X_op = O_illegal;
1247 /* Immediate values. */
1249 #ifdef OBJ_ELF
1250 /* Generic immediate-value read function for use in directives.
1251 Accepts anything that 'expression' can fold to a constant.
1252 *val receives the number. */
1254 static int
1255 immediate_for_directive (int *val)
1257 expressionS exp;
1258 exp.X_op = O_illegal;
1260 if (is_immediate_prefix (*input_line_pointer))
1262 input_line_pointer++;
1263 expression (&exp);
1266 if (exp.X_op != O_constant)
1268 as_bad (_("expected #constant"));
1269 ignore_rest_of_line ();
1270 return FAIL;
1272 *val = exp.X_add_number;
1273 return SUCCESS;
1275 #endif
1277 /* Register parsing. */
1279 /* Generic register parser. CCP points to what should be the
1280 beginning of a register name. If it is indeed a valid register
1281 name, advance CCP over it and return the reg_entry structure;
1282 otherwise return NULL. Does not issue diagnostics. */
1284 static struct reg_entry *
1285 arm_reg_parse_multi (char **ccp)
1287 char *start = *ccp;
1288 char *p;
1289 struct reg_entry *reg;
1291 skip_whitespace (start);
1293 #ifdef REGISTER_PREFIX
1294 if (*start != REGISTER_PREFIX)
1295 return NULL;
1296 start++;
1297 #endif
1298 #ifdef OPTIONAL_REGISTER_PREFIX
1299 if (*start == OPTIONAL_REGISTER_PREFIX)
1300 start++;
1301 #endif
1303 p = start;
1304 if (!ISALPHA (*p) || !is_name_beginner (*p))
1305 return NULL;
1308 p++;
1309 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1311 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1313 if (!reg)
1314 return NULL;
1316 *ccp = p;
1317 return reg;
1320 static int
1321 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1322 enum arm_reg_type type)
1324 /* Alternative syntaxes are accepted for a few register classes. */
1325 switch (type)
1327 case REG_TYPE_MVF:
1328 case REG_TYPE_MVD:
1329 case REG_TYPE_MVFX:
1330 case REG_TYPE_MVDX:
1331 /* Generic coprocessor register names are allowed for these. */
1332 if (reg && reg->type == REG_TYPE_CN)
1333 return reg->number;
1334 break;
1336 case REG_TYPE_CP:
1337 /* For backward compatibility, a bare number is valid here. */
1339 unsigned long processor = strtoul (start, ccp, 10);
1340 if (*ccp != start && processor <= 15)
1341 return processor;
1343 /* Fall through. */
1345 case REG_TYPE_MMXWC:
1346 /* WC includes WCG. ??? I'm not sure this is true for all
1347 instructions that take WC registers. */
1348 if (reg && reg->type == REG_TYPE_MMXWCG)
1349 return reg->number;
1350 break;
1352 default:
1353 break;
1356 return FAIL;
1359 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1360 return value is the register number or FAIL. */
1362 static int
1363 arm_reg_parse (char **ccp, enum arm_reg_type type)
1365 char *start = *ccp;
1366 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1367 int ret;
1369 /* Do not allow a scalar (reg+index) to parse as a register. */
1370 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1371 return FAIL;
1373 if (reg && reg->type == type)
1374 return reg->number;
1376 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1377 return ret;
1379 *ccp = start;
1380 return FAIL;
1383 /* Parse a Neon type specifier. *STR should point at the leading '.'
1384 character. Does no verification at this stage that the type fits the opcode
1385 properly. E.g.,
1387 .i32.i32.s16
1388 .s32.f32
1389 .u16
1391 Can all be legally parsed by this function.
1393 Fills in neon_type struct pointer with parsed information, and updates STR
1394 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1395 type, FAIL if not. */
1397 static int
1398 parse_neon_type (struct neon_type *type, char **str)
1400 char *ptr = *str;
1402 if (type)
1403 type->elems = 0;
1405 while (type->elems < NEON_MAX_TYPE_ELS)
1407 enum neon_el_type thistype = NT_untyped;
1408 unsigned thissize = -1u;
1410 if (*ptr != '.')
1411 break;
1413 ptr++;
1415 /* Just a size without an explicit type. */
1416 if (ISDIGIT (*ptr))
1417 goto parsesize;
1419 switch (TOLOWER (*ptr))
1421 case 'i': thistype = NT_integer; break;
1422 case 'f': thistype = NT_float; break;
1423 case 'p': thistype = NT_poly; break;
1424 case 's': thistype = NT_signed; break;
1425 case 'u': thistype = NT_unsigned; break;
1426 case 'd':
1427 thistype = NT_float;
1428 thissize = 64;
1429 ptr++;
1430 goto done;
1431 default:
1432 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1433 return FAIL;
1436 ptr++;
1438 /* .f is an abbreviation for .f32. */
1439 if (thistype == NT_float && !ISDIGIT (*ptr))
1440 thissize = 32;
1441 else
1443 parsesize:
1444 thissize = strtoul (ptr, &ptr, 10);
1446 if (thissize != 8 && thissize != 16 && thissize != 32
1447 && thissize != 64)
1449 as_bad (_("bad size %d in type specifier"), thissize);
1450 return FAIL;
1454 done:
1455 if (type)
1457 type->el[type->elems].type = thistype;
1458 type->el[type->elems].size = thissize;
1459 type->elems++;
1463 /* Empty/missing type is not a successful parse. */
1464 if (type->elems == 0)
1465 return FAIL;
1467 *str = ptr;
1469 return SUCCESS;
1472 /* Errors may be set multiple times during parsing or bit encoding
1473 (particularly in the Neon bits), but usually the earliest error which is set
1474 will be the most meaningful. Avoid overwriting it with later (cascading)
1475 errors by calling this function. */
1477 static void
1478 first_error (const char *err)
1480 if (!inst.error)
1481 inst.error = err;
1484 /* Parse a single type, e.g. ".s32", leading period included. */
1485 static int
1486 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1488 char *str = *ccp;
1489 struct neon_type optype;
1491 if (*str == '.')
1493 if (parse_neon_type (&optype, &str) == SUCCESS)
1495 if (optype.elems == 1)
1496 *vectype = optype.el[0];
1497 else
1499 first_error (_("only one type should be specified for operand"));
1500 return FAIL;
1503 else
1505 first_error (_("vector type expected"));
1506 return FAIL;
1509 else
1510 return FAIL;
1512 *ccp = str;
1514 return SUCCESS;
1517 /* Special meanings for indices (which have a range of 0-7), which will fit into
1518 a 4-bit integer. */
1520 #define NEON_ALL_LANES 15
1521 #define NEON_INTERLEAVE_LANES 14
1523 /* Record a use of the given feature. */
1524 static void
1525 record_feature_use (const arm_feature_set *feature)
1527 if (thumb_mode)
1528 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1529 else
1530 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1533 /* If the given feature available in the selected CPU, mark it as used.
1534 Returns TRUE iff feature is available. */
1535 static bfd_boolean
1536 mark_feature_used (const arm_feature_set *feature)
1538 /* Ensure the option is valid on the current architecture. */
1539 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1540 return FALSE;
1542 /* Add the appropriate architecture feature for the barrier option used.
1544 record_feature_use (feature);
1546 return TRUE;
1549 /* Parse either a register or a scalar, with an optional type. Return the
1550 register number, and optionally fill in the actual type of the register
1551 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1552 type/index information in *TYPEINFO. */
1554 static int
1555 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1556 enum arm_reg_type *rtype,
1557 struct neon_typed_alias *typeinfo)
1559 char *str = *ccp;
1560 struct reg_entry *reg = arm_reg_parse_multi (&str);
1561 struct neon_typed_alias atype;
1562 struct neon_type_el parsetype;
1564 atype.defined = 0;
1565 atype.index = -1;
1566 atype.eltype.type = NT_invtype;
1567 atype.eltype.size = -1;
1569 /* Try alternate syntax for some types of register. Note these are mutually
1570 exclusive with the Neon syntax extensions. */
1571 if (reg == NULL)
1573 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1574 if (altreg != FAIL)
1575 *ccp = str;
1576 if (typeinfo)
1577 *typeinfo = atype;
1578 return altreg;
1581 /* Undo polymorphism when a set of register types may be accepted. */
1582 if ((type == REG_TYPE_NDQ
1583 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1584 || (type == REG_TYPE_VFSD
1585 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1586 || (type == REG_TYPE_NSDQ
1587 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1588 || reg->type == REG_TYPE_NQ))
1589 || (type == REG_TYPE_NSD
1590 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1591 || (type == REG_TYPE_MMXWC
1592 && (reg->type == REG_TYPE_MMXWCG)))
1593 type = (enum arm_reg_type) reg->type;
1595 if (type == REG_TYPE_MQ)
1597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1598 return FAIL;
1600 if (!reg || reg->type != REG_TYPE_NQ)
1601 return FAIL;
1603 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1605 first_error (_("expected MVE register [q0..q7]"));
1606 return FAIL;
1608 type = REG_TYPE_NQ;
1610 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1611 && (type == REG_TYPE_NQ))
1612 return FAIL;
1615 if (type != reg->type)
1616 return FAIL;
1618 if (reg->neon)
1619 atype = *reg->neon;
1621 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1623 if ((atype.defined & NTA_HASTYPE) != 0)
1625 first_error (_("can't redefine type for operand"));
1626 return FAIL;
1628 atype.defined |= NTA_HASTYPE;
1629 atype.eltype = parsetype;
1632 if (skip_past_char (&str, '[') == SUCCESS)
1634 if (type != REG_TYPE_VFD
1635 && !(type == REG_TYPE_VFS
1636 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
1638 first_error (_("only D registers may be indexed"));
1639 return FAIL;
1642 if ((atype.defined & NTA_HASINDEX) != 0)
1644 first_error (_("can't change index for operand"));
1645 return FAIL;
1648 atype.defined |= NTA_HASINDEX;
1650 if (skip_past_char (&str, ']') == SUCCESS)
1651 atype.index = NEON_ALL_LANES;
1652 else
1654 expressionS exp;
1656 my_get_expression (&exp, &str, GE_NO_PREFIX);
1658 if (exp.X_op != O_constant)
1660 first_error (_("constant expression required"));
1661 return FAIL;
1664 if (skip_past_char (&str, ']') == FAIL)
1665 return FAIL;
1667 atype.index = exp.X_add_number;
1671 if (typeinfo)
1672 *typeinfo = atype;
1674 if (rtype)
1675 *rtype = type;
1677 *ccp = str;
1679 return reg->number;
1682 /* Like arm_reg_parse, but also allow the following extra features:
1683 - If RTYPE is non-zero, return the (possibly restricted) type of the
1684 register (e.g. Neon double or quad reg when either has been requested).
1685 - If this is a Neon vector type with additional type information, fill
1686 in the struct pointed to by VECTYPE (if non-NULL).
1687 This function will fault on encountering a scalar. */
1689 static int
1690 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1691 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1693 struct neon_typed_alias atype;
1694 char *str = *ccp;
1695 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1697 if (reg == FAIL)
1698 return FAIL;
1700 /* Do not allow regname(... to parse as a register. */
1701 if (*str == '(')
1702 return FAIL;
1704 /* Do not allow a scalar (reg+index) to parse as a register. */
1705 if ((atype.defined & NTA_HASINDEX) != 0)
1707 first_error (_("register operand expected, but got scalar"));
1708 return FAIL;
1711 if (vectype)
1712 *vectype = atype.eltype;
1714 *ccp = str;
1716 return reg;
1719 #define NEON_SCALAR_REG(X) ((X) >> 4)
1720 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1722 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1723 have enough information to be able to do a good job bounds-checking. So, we
1724 just do easy checks here, and do further checks later. */
1726 static int
1727 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1729 int reg;
1730 char *str = *ccp;
1731 struct neon_typed_alias atype;
1732 enum arm_reg_type reg_type = REG_TYPE_VFD;
1734 if (elsize == 4)
1735 reg_type = REG_TYPE_VFS;
1737 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1739 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1740 return FAIL;
1742 if (atype.index == NEON_ALL_LANES)
1744 first_error (_("scalar must have an index"));
1745 return FAIL;
1747 else if (atype.index >= 64 / elsize)
1749 first_error (_("scalar index out of range"));
1750 return FAIL;
1753 if (type)
1754 *type = atype.eltype;
1756 *ccp = str;
1758 return reg * 16 + atype.index;
1761 /* Types of registers in a list. */
1763 enum reg_list_els
1765 REGLIST_RN,
1766 REGLIST_CLRM,
1767 REGLIST_VFP_S,
1768 REGLIST_VFP_S_VPR,
1769 REGLIST_VFP_D,
1770 REGLIST_VFP_D_VPR,
1771 REGLIST_NEON_D
1774 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1776 static long
1777 parse_reg_list (char ** strp, enum reg_list_els etype)
1779 char *str = *strp;
1780 long range = 0;
1781 int another_range;
1783 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
1785 /* We come back here if we get ranges concatenated by '+' or '|'. */
1788 skip_whitespace (str);
1790 another_range = 0;
1792 if (*str == '{')
1794 int in_range = 0;
1795 int cur_reg = -1;
1797 str++;
1800 int reg;
1801 const char apsr_str[] = "apsr";
1802 int apsr_str_len = strlen (apsr_str);
1804 reg = arm_reg_parse (&str, REGLIST_RN);
1805 if (etype == REGLIST_CLRM)
1807 if (reg == REG_SP || reg == REG_PC)
1808 reg = FAIL;
1809 else if (reg == FAIL
1810 && !strncasecmp (str, apsr_str, apsr_str_len)
1811 && !ISALPHA (*(str + apsr_str_len)))
1813 reg = 15;
1814 str += apsr_str_len;
1817 if (reg == FAIL)
1819 first_error (_("r0-r12, lr or APSR expected"));
1820 return FAIL;
1823 else /* etype == REGLIST_RN. */
1825 if (reg == FAIL)
1827 first_error (_(reg_expected_msgs[REGLIST_RN]));
1828 return FAIL;
1832 if (in_range)
1834 int i;
1836 if (reg <= cur_reg)
1838 first_error (_("bad range in register list"));
1839 return FAIL;
1842 for (i = cur_reg + 1; i < reg; i++)
1844 if (range & (1 << i))
1845 as_tsktsk
1846 (_("Warning: duplicated register (r%d) in register list"),
1848 else
1849 range |= 1 << i;
1851 in_range = 0;
1854 if (range & (1 << reg))
1855 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1856 reg);
1857 else if (reg <= cur_reg)
1858 as_tsktsk (_("Warning: register range not in ascending order"));
1860 range |= 1 << reg;
1861 cur_reg = reg;
1863 while (skip_past_comma (&str) != FAIL
1864 || (in_range = 1, *str++ == '-'));
1865 str--;
1867 if (skip_past_char (&str, '}') == FAIL)
1869 first_error (_("missing `}'"));
1870 return FAIL;
1873 else if (etype == REGLIST_RN)
1875 expressionS exp;
1877 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1878 return FAIL;
1880 if (exp.X_op == O_constant)
1882 if (exp.X_add_number
1883 != (exp.X_add_number & 0x0000ffff))
1885 inst.error = _("invalid register mask");
1886 return FAIL;
1889 if ((range & exp.X_add_number) != 0)
1891 int regno = range & exp.X_add_number;
1893 regno &= -regno;
1894 regno = (1 << regno) - 1;
1895 as_tsktsk
1896 (_("Warning: duplicated register (r%d) in register list"),
1897 regno);
1900 range |= exp.X_add_number;
1902 else
1904 if (inst.relocs[0].type != 0)
1906 inst.error = _("expression too complex");
1907 return FAIL;
1910 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1911 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1912 inst.relocs[0].pc_rel = 0;
1916 if (*str == '|' || *str == '+')
1918 str++;
1919 another_range = 1;
1922 while (another_range);
1924 *strp = str;
1925 return range;
1928 /* Parse a VFP register list. If the string is invalid return FAIL.
1929 Otherwise return the number of registers, and set PBASE to the first
1930 register. Parses registers of type ETYPE.
1931 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1932 - Q registers can be used to specify pairs of D registers
1933 - { } can be omitted from around a singleton register list
1934 FIXME: This is not implemented, as it would require backtracking in
1935 some cases, e.g.:
1936 vtbl.8 d3,d4,d5
1937 This could be done (the meaning isn't really ambiguous), but doesn't
1938 fit in well with the current parsing framework.
1939 - 32 D registers may be used (also true for VFPv3).
1940 FIXME: Types are ignored in these register lists, which is probably a
1941 bug. */
1943 static int
1944 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
1945 bfd_boolean *partial_match)
1947 char *str = *ccp;
1948 int base_reg;
1949 int new_base;
1950 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1951 int max_regs = 0;
1952 int count = 0;
1953 int warned = 0;
1954 unsigned long mask = 0;
1955 int i;
1956 bfd_boolean vpr_seen = FALSE;
1957 bfd_boolean expect_vpr =
1958 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
1960 if (skip_past_char (&str, '{') == FAIL)
1962 inst.error = _("expecting {");
1963 return FAIL;
1966 switch (etype)
1968 case REGLIST_VFP_S:
1969 case REGLIST_VFP_S_VPR:
1970 regtype = REG_TYPE_VFS;
1971 max_regs = 32;
1972 break;
1974 case REGLIST_VFP_D:
1975 case REGLIST_VFP_D_VPR:
1976 regtype = REG_TYPE_VFD;
1977 break;
1979 case REGLIST_NEON_D:
1980 regtype = REG_TYPE_NDQ;
1981 break;
1983 default:
1984 gas_assert (0);
1987 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
1989 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1990 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1992 max_regs = 32;
1993 if (thumb_mode)
1994 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1995 fpu_vfp_ext_d32);
1996 else
1997 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1998 fpu_vfp_ext_d32);
2000 else
2001 max_regs = 16;
2004 base_reg = max_regs;
2005 *partial_match = FALSE;
2009 int setmask = 1, addregs = 1;
2010 const char vpr_str[] = "vpr";
2011 int vpr_str_len = strlen (vpr_str);
2013 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2015 if (expect_vpr)
2017 if (new_base == FAIL
2018 && !strncasecmp (str, vpr_str, vpr_str_len)
2019 && !ISALPHA (*(str + vpr_str_len))
2020 && !vpr_seen)
2022 vpr_seen = TRUE;
2023 str += vpr_str_len;
2024 if (count == 0)
2025 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2027 else if (vpr_seen)
2029 first_error (_("VPR expected last"));
2030 return FAIL;
2032 else if (new_base == FAIL)
2034 if (regtype == REG_TYPE_VFS)
2035 first_error (_("VFP single precision register or VPR "
2036 "expected"));
2037 else /* regtype == REG_TYPE_VFD. */
2038 first_error (_("VFP/Neon double precision register or VPR "
2039 "expected"));
2040 return FAIL;
2043 else if (new_base == FAIL)
2045 first_error (_(reg_expected_msgs[regtype]));
2046 return FAIL;
2049 *partial_match = TRUE;
2050 if (vpr_seen)
2051 continue;
2053 if (new_base >= max_regs)
2055 first_error (_("register out of range in list"));
2056 return FAIL;
2059 /* Note: a value of 2 * n is returned for the register Q<n>. */
2060 if (regtype == REG_TYPE_NQ)
2062 setmask = 3;
2063 addregs = 2;
2066 if (new_base < base_reg)
2067 base_reg = new_base;
2069 if (mask & (setmask << new_base))
2071 first_error (_("invalid register list"));
2072 return FAIL;
2075 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2077 as_tsktsk (_("register list not in ascending order"));
2078 warned = 1;
2081 mask |= setmask << new_base;
2082 count += addregs;
2084 if (*str == '-') /* We have the start of a range expression */
2086 int high_range;
2088 str++;
2090 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2091 == FAIL)
2093 inst.error = gettext (reg_expected_msgs[regtype]);
2094 return FAIL;
2097 if (high_range >= max_regs)
2099 first_error (_("register out of range in list"));
2100 return FAIL;
2103 if (regtype == REG_TYPE_NQ)
2104 high_range = high_range + 1;
2106 if (high_range <= new_base)
2108 inst.error = _("register range not in ascending order");
2109 return FAIL;
2112 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2114 if (mask & (setmask << new_base))
2116 inst.error = _("invalid register list");
2117 return FAIL;
2120 mask |= setmask << new_base;
2121 count += addregs;
2125 while (skip_past_comma (&str) != FAIL);
2127 str++;
2129 /* Sanity check -- should have raised a parse error above. */
2130 if ((!vpr_seen && count == 0) || count > max_regs)
2131 abort ();
2133 *pbase = base_reg;
2135 if (expect_vpr && !vpr_seen)
2137 first_error (_("VPR expected last"));
2138 return FAIL;
2141 /* Final test -- the registers must be consecutive. */
2142 mask >>= base_reg;
2143 for (i = 0; i < count; i++)
2145 if ((mask & (1u << i)) == 0)
2147 inst.error = _("non-contiguous register range");
2148 return FAIL;
2152 *ccp = str;
2154 return count;
2157 /* True if two alias types are the same. */
2159 static bfd_boolean
2160 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2162 if (!a && !b)
2163 return TRUE;
2165 if (!a || !b)
2166 return FALSE;
2168 if (a->defined != b->defined)
2169 return FALSE;
2171 if ((a->defined & NTA_HASTYPE) != 0
2172 && (a->eltype.type != b->eltype.type
2173 || a->eltype.size != b->eltype.size))
2174 return FALSE;
2176 if ((a->defined & NTA_HASINDEX) != 0
2177 && (a->index != b->index))
2178 return FALSE;
2180 return TRUE;
2183 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2184 The base register is put in *PBASE.
2185 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2186 the return value.
2187 The register stride (minus one) is put in bit 4 of the return value.
2188 Bits [6:5] encode the list length (minus one).
2189 The type of the list elements is put in *ELTYPE, if non-NULL. */
2191 #define NEON_LANE(X) ((X) & 0xf)
2192 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2193 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2195 static int
2196 parse_neon_el_struct_list (char **str, unsigned *pbase,
2197 struct neon_type_el *eltype)
2199 char *ptr = *str;
2200 int base_reg = -1;
2201 int reg_incr = -1;
2202 int count = 0;
2203 int lane = -1;
2204 int leading_brace = 0;
2205 enum arm_reg_type rtype = REG_TYPE_NDQ;
2206 const char *const incr_error = _("register stride must be 1 or 2");
2207 const char *const type_error = _("mismatched element/structure types in list");
2208 struct neon_typed_alias firsttype;
2209 firsttype.defined = 0;
2210 firsttype.eltype.type = NT_invtype;
2211 firsttype.eltype.size = -1;
2212 firsttype.index = -1;
2214 if (skip_past_char (&ptr, '{') == SUCCESS)
2215 leading_brace = 1;
2219 struct neon_typed_alias atype;
2220 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2222 if (getreg == FAIL)
2224 first_error (_(reg_expected_msgs[rtype]));
2225 return FAIL;
2228 if (base_reg == -1)
2230 base_reg = getreg;
2231 if (rtype == REG_TYPE_NQ)
2233 reg_incr = 1;
2235 firsttype = atype;
2237 else if (reg_incr == -1)
2239 reg_incr = getreg - base_reg;
2240 if (reg_incr < 1 || reg_incr > 2)
2242 first_error (_(incr_error));
2243 return FAIL;
2246 else if (getreg != base_reg + reg_incr * count)
2248 first_error (_(incr_error));
2249 return FAIL;
2252 if (! neon_alias_types_same (&atype, &firsttype))
2254 first_error (_(type_error));
2255 return FAIL;
2258 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2259 modes. */
2260 if (ptr[0] == '-')
2262 struct neon_typed_alias htype;
2263 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2264 if (lane == -1)
2265 lane = NEON_INTERLEAVE_LANES;
2266 else if (lane != NEON_INTERLEAVE_LANES)
2268 first_error (_(type_error));
2269 return FAIL;
2271 if (reg_incr == -1)
2272 reg_incr = 1;
2273 else if (reg_incr != 1)
2275 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2276 return FAIL;
2278 ptr++;
2279 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2280 if (hireg == FAIL)
2282 first_error (_(reg_expected_msgs[rtype]));
2283 return FAIL;
2285 if (! neon_alias_types_same (&htype, &firsttype))
2287 first_error (_(type_error));
2288 return FAIL;
2290 count += hireg + dregs - getreg;
2291 continue;
2294 /* If we're using Q registers, we can't use [] or [n] syntax. */
2295 if (rtype == REG_TYPE_NQ)
2297 count += 2;
2298 continue;
2301 if ((atype.defined & NTA_HASINDEX) != 0)
2303 if (lane == -1)
2304 lane = atype.index;
2305 else if (lane != atype.index)
2307 first_error (_(type_error));
2308 return FAIL;
2311 else if (lane == -1)
2312 lane = NEON_INTERLEAVE_LANES;
2313 else if (lane != NEON_INTERLEAVE_LANES)
2315 first_error (_(type_error));
2316 return FAIL;
2318 count++;
2320 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2322 /* No lane set by [x]. We must be interleaving structures. */
2323 if (lane == -1)
2324 lane = NEON_INTERLEAVE_LANES;
2326 /* Sanity check. */
2327 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2328 || (count > 1 && reg_incr == -1))
2330 first_error (_("error parsing element/structure list"));
2331 return FAIL;
2334 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2336 first_error (_("expected }"));
2337 return FAIL;
2340 if (reg_incr == -1)
2341 reg_incr = 1;
2343 if (eltype)
2344 *eltype = firsttype.eltype;
2346 *pbase = base_reg;
2347 *str = ptr;
2349 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2352 /* Parse an explicit relocation suffix on an expression. This is
2353 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2354 arm_reloc_hsh contains no entries, so this function can only
2355 succeed if there is no () after the word. Returns -1 on error,
2356 BFD_RELOC_UNUSED if there wasn't any suffix. */
2358 static int
2359 parse_reloc (char **str)
2361 struct reloc_entry *r;
2362 char *p, *q;
2364 if (**str != '(')
2365 return BFD_RELOC_UNUSED;
2367 p = *str + 1;
2368 q = p;
2370 while (*q && *q != ')' && *q != ',')
2371 q++;
2372 if (*q != ')')
2373 return -1;
2375 if ((r = (struct reloc_entry *)
2376 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2377 return -1;
2379 *str = q + 1;
2380 return r->reloc;
2383 /* Directives: register aliases. */
2385 static struct reg_entry *
2386 insert_reg_alias (char *str, unsigned number, int type)
2388 struct reg_entry *new_reg;
2389 const char *name;
2391 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2393 if (new_reg->builtin)
2394 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2396 /* Only warn about a redefinition if it's not defined as the
2397 same register. */
2398 else if (new_reg->number != number || new_reg->type != type)
2399 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2401 return NULL;
2404 name = xstrdup (str);
2405 new_reg = XNEW (struct reg_entry);
2407 new_reg->name = name;
2408 new_reg->number = number;
2409 new_reg->type = type;
2410 new_reg->builtin = FALSE;
2411 new_reg->neon = NULL;
2413 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2414 abort ();
2416 return new_reg;
2419 static void
2420 insert_neon_reg_alias (char *str, int number, int type,
2421 struct neon_typed_alias *atype)
2423 struct reg_entry *reg = insert_reg_alias (str, number, type);
2425 if (!reg)
2427 first_error (_("attempt to redefine typed alias"));
2428 return;
2431 if (atype)
2433 reg->neon = XNEW (struct neon_typed_alias);
2434 *reg->neon = *atype;
2438 /* Look for the .req directive. This is of the form:
2440 new_register_name .req existing_register_name
2442 If we find one, or if it looks sufficiently like one that we want to
2443 handle any error here, return TRUE. Otherwise return FALSE. */
2445 static bfd_boolean
2446 create_register_alias (char * newname, char *p)
2448 struct reg_entry *old;
2449 char *oldname, *nbuf;
2450 size_t nlen;
2452 /* The input scrubber ensures that whitespace after the mnemonic is
2453 collapsed to single spaces. */
2454 oldname = p;
2455 if (strncmp (oldname, " .req ", 6) != 0)
2456 return FALSE;
2458 oldname += 6;
2459 if (*oldname == '\0')
2460 return FALSE;
2462 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2463 if (!old)
2465 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2466 return TRUE;
2469 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2470 the desired alias name, and p points to its end. If not, then
2471 the desired alias name is in the global original_case_string. */
2472 #ifdef TC_CASE_SENSITIVE
2473 nlen = p - newname;
2474 #else
2475 newname = original_case_string;
2476 nlen = strlen (newname);
2477 #endif
2479 nbuf = xmemdup0 (newname, nlen);
2481 /* Create aliases under the new name as stated; an all-lowercase
2482 version of the new name; and an all-uppercase version of the new
2483 name. */
2484 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2486 for (p = nbuf; *p; p++)
2487 *p = TOUPPER (*p);
2489 if (strncmp (nbuf, newname, nlen))
2491 /* If this attempt to create an additional alias fails, do not bother
2492 trying to create the all-lower case alias. We will fail and issue
2493 a second, duplicate error message. This situation arises when the
2494 programmer does something like:
2495 foo .req r0
2496 Foo .req r1
2497 The second .req creates the "Foo" alias but then fails to create
2498 the artificial FOO alias because it has already been created by the
2499 first .req. */
2500 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2502 free (nbuf);
2503 return TRUE;
2507 for (p = nbuf; *p; p++)
2508 *p = TOLOWER (*p);
2510 if (strncmp (nbuf, newname, nlen))
2511 insert_reg_alias (nbuf, old->number, old->type);
2514 free (nbuf);
2515 return TRUE;
2518 /* Create a Neon typed/indexed register alias using directives, e.g.:
2519 X .dn d5.s32[1]
2520 Y .qn 6.s16
2521 Z .dn d7
2522 T .dn Z[0]
2523 These typed registers can be used instead of the types specified after the
2524 Neon mnemonic, so long as all operands given have types. Types can also be
2525 specified directly, e.g.:
2526 vadd d0.s32, d1.s32, d2.s32 */
2528 static bfd_boolean
2529 create_neon_reg_alias (char *newname, char *p)
2531 enum arm_reg_type basetype;
2532 struct reg_entry *basereg;
2533 struct reg_entry mybasereg;
2534 struct neon_type ntype;
2535 struct neon_typed_alias typeinfo;
2536 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2537 int namelen;
2539 typeinfo.defined = 0;
2540 typeinfo.eltype.type = NT_invtype;
2541 typeinfo.eltype.size = -1;
2542 typeinfo.index = -1;
2544 nameend = p;
2546 if (strncmp (p, " .dn ", 5) == 0)
2547 basetype = REG_TYPE_VFD;
2548 else if (strncmp (p, " .qn ", 5) == 0)
2549 basetype = REG_TYPE_NQ;
2550 else
2551 return FALSE;
2553 p += 5;
2555 if (*p == '\0')
2556 return FALSE;
2558 basereg = arm_reg_parse_multi (&p);
2560 if (basereg && basereg->type != basetype)
2562 as_bad (_("bad type for register"));
2563 return FALSE;
2566 if (basereg == NULL)
2568 expressionS exp;
2569 /* Try parsing as an integer. */
2570 my_get_expression (&exp, &p, GE_NO_PREFIX);
2571 if (exp.X_op != O_constant)
2573 as_bad (_("expression must be constant"));
2574 return FALSE;
2576 basereg = &mybasereg;
2577 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2578 : exp.X_add_number;
2579 basereg->neon = 0;
2582 if (basereg->neon)
2583 typeinfo = *basereg->neon;
2585 if (parse_neon_type (&ntype, &p) == SUCCESS)
2587 /* We got a type. */
2588 if (typeinfo.defined & NTA_HASTYPE)
2590 as_bad (_("can't redefine the type of a register alias"));
2591 return FALSE;
2594 typeinfo.defined |= NTA_HASTYPE;
2595 if (ntype.elems != 1)
2597 as_bad (_("you must specify a single type only"));
2598 return FALSE;
2600 typeinfo.eltype = ntype.el[0];
2603 if (skip_past_char (&p, '[') == SUCCESS)
2605 expressionS exp;
2606 /* We got a scalar index. */
2608 if (typeinfo.defined & NTA_HASINDEX)
2610 as_bad (_("can't redefine the index of a scalar alias"));
2611 return FALSE;
2614 my_get_expression (&exp, &p, GE_NO_PREFIX);
2616 if (exp.X_op != O_constant)
2618 as_bad (_("scalar index must be constant"));
2619 return FALSE;
2622 typeinfo.defined |= NTA_HASINDEX;
2623 typeinfo.index = exp.X_add_number;
2625 if (skip_past_char (&p, ']') == FAIL)
2627 as_bad (_("expecting ]"));
2628 return FALSE;
2632 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2633 the desired alias name, and p points to its end. If not, then
2634 the desired alias name is in the global original_case_string. */
2635 #ifdef TC_CASE_SENSITIVE
2636 namelen = nameend - newname;
2637 #else
2638 newname = original_case_string;
2639 namelen = strlen (newname);
2640 #endif
2642 namebuf = xmemdup0 (newname, namelen);
2644 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2645 typeinfo.defined != 0 ? &typeinfo : NULL);
2647 /* Insert name in all uppercase. */
2648 for (p = namebuf; *p; p++)
2649 *p = TOUPPER (*p);
2651 if (strncmp (namebuf, newname, namelen))
2652 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2653 typeinfo.defined != 0 ? &typeinfo : NULL);
2655 /* Insert name in all lowercase. */
2656 for (p = namebuf; *p; p++)
2657 *p = TOLOWER (*p);
2659 if (strncmp (namebuf, newname, namelen))
2660 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2661 typeinfo.defined != 0 ? &typeinfo : NULL);
2663 free (namebuf);
2664 return TRUE;
2667 /* Should never be called, as .req goes between the alias and the
2668 register name, not at the beginning of the line. */
2670 static void
2671 s_req (int a ATTRIBUTE_UNUSED)
2673 as_bad (_("invalid syntax for .req directive"));
2676 static void
2677 s_dn (int a ATTRIBUTE_UNUSED)
2679 as_bad (_("invalid syntax for .dn directive"));
2682 static void
2683 s_qn (int a ATTRIBUTE_UNUSED)
2685 as_bad (_("invalid syntax for .qn directive"));
2688 /* The .unreq directive deletes an alias which was previously defined
2689 by .req. For example:
2691 my_alias .req r11
2692 .unreq my_alias */
2694 static void
2695 s_unreq (int a ATTRIBUTE_UNUSED)
2697 char * name;
2698 char saved_char;
2700 name = input_line_pointer;
2702 while (*input_line_pointer != 0
2703 && *input_line_pointer != ' '
2704 && *input_line_pointer != '\n')
2705 ++input_line_pointer;
2707 saved_char = *input_line_pointer;
2708 *input_line_pointer = 0;
2710 if (!*name)
2711 as_bad (_("invalid syntax for .unreq directive"));
2712 else
2714 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2715 name);
2717 if (!reg)
2718 as_bad (_("unknown register alias '%s'"), name);
2719 else if (reg->builtin)
2720 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2721 name);
2722 else
2724 char * p;
2725 char * nbuf;
2727 hash_delete (arm_reg_hsh, name, FALSE);
2728 free ((char *) reg->name);
2729 if (reg->neon)
2730 free (reg->neon);
2731 free (reg);
2733 /* Also locate the all upper case and all lower case versions.
2734 Do not complain if we cannot find one or the other as it
2735 was probably deleted above. */
2737 nbuf = strdup (name);
2738 for (p = nbuf; *p; p++)
2739 *p = TOUPPER (*p);
2740 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2741 if (reg)
2743 hash_delete (arm_reg_hsh, nbuf, FALSE);
2744 free ((char *) reg->name);
2745 if (reg->neon)
2746 free (reg->neon);
2747 free (reg);
2750 for (p = nbuf; *p; p++)
2751 *p = TOLOWER (*p);
2752 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2753 if (reg)
2755 hash_delete (arm_reg_hsh, nbuf, FALSE);
2756 free ((char *) reg->name);
2757 if (reg->neon)
2758 free (reg->neon);
2759 free (reg);
2762 free (nbuf);
2766 *input_line_pointer = saved_char;
2767 demand_empty_rest_of_line ();
2770 /* Directives: Instruction set selection. */
2772 #ifdef OBJ_ELF
2773 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2774 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2775 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2776 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2778 /* Create a new mapping symbol for the transition to STATE. */
2780 static void
2781 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2783 symbolS * symbolP;
2784 const char * symname;
2785 int type;
2787 switch (state)
2789 case MAP_DATA:
2790 symname = "$d";
2791 type = BSF_NO_FLAGS;
2792 break;
2793 case MAP_ARM:
2794 symname = "$a";
2795 type = BSF_NO_FLAGS;
2796 break;
2797 case MAP_THUMB:
2798 symname = "$t";
2799 type = BSF_NO_FLAGS;
2800 break;
2801 default:
2802 abort ();
2805 symbolP = symbol_new (symname, now_seg, value, frag);
2806 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2808 switch (state)
2810 case MAP_ARM:
2811 THUMB_SET_FUNC (symbolP, 0);
2812 ARM_SET_THUMB (symbolP, 0);
2813 ARM_SET_INTERWORK (symbolP, support_interwork);
2814 break;
2816 case MAP_THUMB:
2817 THUMB_SET_FUNC (symbolP, 1);
2818 ARM_SET_THUMB (symbolP, 1);
2819 ARM_SET_INTERWORK (symbolP, support_interwork);
2820 break;
2822 case MAP_DATA:
2823 default:
2824 break;
2827 /* Save the mapping symbols for future reference. Also check that
2828 we do not place two mapping symbols at the same offset within a
2829 frag. We'll handle overlap between frags in
2830 check_mapping_symbols.
2832 If .fill or other data filling directive generates zero sized data,
2833 the mapping symbol for the following code will have the same value
2834 as the one generated for the data filling directive. In this case,
2835 we replace the old symbol with the new one at the same address. */
2836 if (value == 0)
2838 if (frag->tc_frag_data.first_map != NULL)
2840 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2841 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2843 frag->tc_frag_data.first_map = symbolP;
2845 if (frag->tc_frag_data.last_map != NULL)
2847 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2848 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2849 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2851 frag->tc_frag_data.last_map = symbolP;
2854 /* We must sometimes convert a region marked as code to data during
2855 code alignment, if an odd number of bytes have to be padded. The
2856 code mapping symbol is pushed to an aligned address. */
2858 static void
2859 insert_data_mapping_symbol (enum mstate state,
2860 valueT value, fragS *frag, offsetT bytes)
2862 /* If there was already a mapping symbol, remove it. */
2863 if (frag->tc_frag_data.last_map != NULL
2864 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2866 symbolS *symp = frag->tc_frag_data.last_map;
2868 if (value == 0)
2870 know (frag->tc_frag_data.first_map == symp);
2871 frag->tc_frag_data.first_map = NULL;
2873 frag->tc_frag_data.last_map = NULL;
2874 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2877 make_mapping_symbol (MAP_DATA, value, frag);
2878 make_mapping_symbol (state, value + bytes, frag);
2881 static void mapping_state_2 (enum mstate state, int max_chars);
2883 /* Set the mapping state to STATE. Only call this when about to
2884 emit some STATE bytes to the file. */
2886 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2887 void
2888 mapping_state (enum mstate state)
2890 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2892 if (mapstate == state)
2893 /* The mapping symbol has already been emitted.
2894 There is nothing else to do. */
2895 return;
2897 if (state == MAP_ARM || state == MAP_THUMB)
2898 /* PR gas/12931
2899 All ARM instructions require 4-byte alignment.
2900 (Almost) all Thumb instructions require 2-byte alignment.
2902 When emitting instructions into any section, mark the section
2903 appropriately.
2905 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2906 but themselves require 2-byte alignment; this applies to some
2907 PC- relative forms. However, these cases will involve implicit
2908 literal pool generation or an explicit .align >=2, both of
2909 which will cause the section to me marked with sufficient
2910 alignment. Thus, we don't handle those cases here. */
2911 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2913 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2914 /* This case will be evaluated later. */
2915 return;
2917 mapping_state_2 (state, 0);
2920 /* Same as mapping_state, but MAX_CHARS bytes have already been
2921 allocated. Put the mapping symbol that far back. */
2923 static void
2924 mapping_state_2 (enum mstate state, int max_chars)
2926 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2928 if (!SEG_NORMAL (now_seg))
2929 return;
2931 if (mapstate == state)
2932 /* The mapping symbol has already been emitted.
2933 There is nothing else to do. */
2934 return;
2936 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2937 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2939 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2940 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2942 if (add_symbol)
2943 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2946 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2947 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2949 #undef TRANSITION
2950 #else
2951 #define mapping_state(x) ((void)0)
2952 #define mapping_state_2(x, y) ((void)0)
2953 #endif
2955 /* Find the real, Thumb encoded start of a Thumb function. */
2957 #ifdef OBJ_COFF
2958 static symbolS *
2959 find_real_start (symbolS * symbolP)
2961 char * real_start;
2962 const char * name = S_GET_NAME (symbolP);
2963 symbolS * new_target;
2965 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2966 #define STUB_NAME ".real_start_of"
2968 if (name == NULL)
2969 abort ();
2971 /* The compiler may generate BL instructions to local labels because
2972 it needs to perform a branch to a far away location. These labels
2973 do not have a corresponding ".real_start_of" label. We check
2974 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2975 the ".real_start_of" convention for nonlocal branches. */
2976 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2977 return symbolP;
2979 real_start = concat (STUB_NAME, name, NULL);
2980 new_target = symbol_find (real_start);
2981 free (real_start);
2983 if (new_target == NULL)
2985 as_warn (_("Failed to find real start of function: %s\n"), name);
2986 new_target = symbolP;
2989 return new_target;
2991 #endif
2993 static void
2994 opcode_select (int width)
2996 switch (width)
2998 case 16:
2999 if (! thumb_mode)
3001 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3002 as_bad (_("selected processor does not support THUMB opcodes"));
3004 thumb_mode = 1;
3005 /* No need to force the alignment, since we will have been
3006 coming from ARM mode, which is word-aligned. */
3007 record_alignment (now_seg, 1);
3009 break;
3011 case 32:
3012 if (thumb_mode)
3014 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3015 as_bad (_("selected processor does not support ARM opcodes"));
3017 thumb_mode = 0;
3019 if (!need_pass_2)
3020 frag_align (2, 0, 0);
3022 record_alignment (now_seg, 1);
3024 break;
3026 default:
3027 as_bad (_("invalid instruction size selected (%d)"), width);
3031 static void
3032 s_arm (int ignore ATTRIBUTE_UNUSED)
3034 opcode_select (32);
3035 demand_empty_rest_of_line ();
3038 static void
3039 s_thumb (int ignore ATTRIBUTE_UNUSED)
3041 opcode_select (16);
3042 demand_empty_rest_of_line ();
3045 static void
3046 s_code (int unused ATTRIBUTE_UNUSED)
3048 int temp;
3050 temp = get_absolute_expression ();
3051 switch (temp)
3053 case 16:
3054 case 32:
3055 opcode_select (temp);
3056 break;
3058 default:
3059 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3063 static void
3064 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3066 /* If we are not already in thumb mode go into it, EVEN if
3067 the target processor does not support thumb instructions.
3068 This is used by gcc/config/arm/lib1funcs.asm for example
3069 to compile interworking support functions even if the
3070 target processor should not support interworking. */
3071 if (! thumb_mode)
3073 thumb_mode = 2;
3074 record_alignment (now_seg, 1);
3077 demand_empty_rest_of_line ();
3080 static void
3081 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3083 s_thumb (0);
3085 /* The following label is the name/address of the start of a Thumb function.
3086 We need to know this for the interworking support. */
3087 label_is_thumb_function_name = TRUE;
3090 /* Perform a .set directive, but also mark the alias as
3091 being a thumb function. */
3093 static void
3094 s_thumb_set (int equiv)
3096 /* XXX the following is a duplicate of the code for s_set() in read.c
3097 We cannot just call that code as we need to get at the symbol that
3098 is created. */
3099 char * name;
3100 char delim;
3101 char * end_name;
3102 symbolS * symbolP;
3104 /* Especial apologies for the random logic:
3105 This just grew, and could be parsed much more simply!
3106 Dean - in haste. */
3107 delim = get_symbol_name (& name);
3108 end_name = input_line_pointer;
3109 (void) restore_line_pointer (delim);
3111 if (*input_line_pointer != ',')
3113 *end_name = 0;
3114 as_bad (_("expected comma after name \"%s\""), name);
3115 *end_name = delim;
3116 ignore_rest_of_line ();
3117 return;
3120 input_line_pointer++;
3121 *end_name = 0;
3123 if (name[0] == '.' && name[1] == '\0')
3125 /* XXX - this should not happen to .thumb_set. */
3126 abort ();
3129 if ((symbolP = symbol_find (name)) == NULL
3130 && (symbolP = md_undefined_symbol (name)) == NULL)
3132 #ifndef NO_LISTING
3133 /* When doing symbol listings, play games with dummy fragments living
3134 outside the normal fragment chain to record the file and line info
3135 for this symbol. */
3136 if (listing & LISTING_SYMBOLS)
3138 extern struct list_info_struct * listing_tail;
3139 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3141 memset (dummy_frag, 0, sizeof (fragS));
3142 dummy_frag->fr_type = rs_fill;
3143 dummy_frag->line = listing_tail;
3144 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3145 dummy_frag->fr_symbol = symbolP;
3147 else
3148 #endif
3149 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3151 #ifdef OBJ_COFF
3152 /* "set" symbols are local unless otherwise specified. */
3153 SF_SET_LOCAL (symbolP);
3154 #endif /* OBJ_COFF */
3155 } /* Make a new symbol. */
3157 symbol_table_insert (symbolP);
3159 * end_name = delim;
3161 if (equiv
3162 && S_IS_DEFINED (symbolP)
3163 && S_GET_SEGMENT (symbolP) != reg_section)
3164 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3166 pseudo_set (symbolP);
3168 demand_empty_rest_of_line ();
3170 /* XXX Now we come to the Thumb specific bit of code. */
3172 THUMB_SET_FUNC (symbolP, 1);
3173 ARM_SET_THUMB (symbolP, 1);
3174 #if defined OBJ_ELF || defined OBJ_COFF
3175 ARM_SET_INTERWORK (symbolP, support_interwork);
3176 #endif
3179 /* Directives: Mode selection. */
3181 /* .syntax [unified|divided] - choose the new unified syntax
3182 (same for Arm and Thumb encoding, modulo slight differences in what
3183 can be represented) or the old divergent syntax for each mode. */
3184 static void
3185 s_syntax (int unused ATTRIBUTE_UNUSED)
3187 char *name, delim;
3189 delim = get_symbol_name (& name);
3191 if (!strcasecmp (name, "unified"))
3192 unified_syntax = TRUE;
3193 else if (!strcasecmp (name, "divided"))
3194 unified_syntax = FALSE;
3195 else
3197 as_bad (_("unrecognized syntax mode \"%s\""), name);
3198 return;
3200 (void) restore_line_pointer (delim);
3201 demand_empty_rest_of_line ();
3204 /* Directives: sectioning and alignment. */
3206 static void
3207 s_bss (int ignore ATTRIBUTE_UNUSED)
3209 /* We don't support putting frags in the BSS segment, we fake it by
3210 marking in_bss, then looking at s_skip for clues. */
3211 subseg_set (bss_section, 0);
3212 demand_empty_rest_of_line ();
3214 #ifdef md_elf_section_change_hook
3215 md_elf_section_change_hook ();
3216 #endif
3219 static void
3220 s_even (int ignore ATTRIBUTE_UNUSED)
3222 /* Never make frag if expect extra pass. */
3223 if (!need_pass_2)
3224 frag_align (1, 0, 0);
3226 record_alignment (now_seg, 1);
3228 demand_empty_rest_of_line ();
3231 /* Directives: CodeComposer Studio. */
3233 /* .ref (for CodeComposer Studio syntax only). */
3234 static void
3235 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3237 if (codecomposer_syntax)
3238 ignore_rest_of_line ();
3239 else
3240 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3243 /* If name is not NULL, then it is used for marking the beginning of a
3244 function, whereas if it is NULL then it means the function end. */
3245 static void
3246 asmfunc_debug (const char * name)
3248 static const char * last_name = NULL;
3250 if (name != NULL)
3252 gas_assert (last_name == NULL);
3253 last_name = name;
3255 if (debug_type == DEBUG_STABS)
3256 stabs_generate_asm_func (name, name);
3258 else
3260 gas_assert (last_name != NULL);
3262 if (debug_type == DEBUG_STABS)
3263 stabs_generate_asm_endfunc (last_name, last_name);
3265 last_name = NULL;
3269 static void
3270 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3272 if (codecomposer_syntax)
3274 switch (asmfunc_state)
3276 case OUTSIDE_ASMFUNC:
3277 asmfunc_state = WAITING_ASMFUNC_NAME;
3278 break;
3280 case WAITING_ASMFUNC_NAME:
3281 as_bad (_(".asmfunc repeated."));
3282 break;
3284 case WAITING_ENDASMFUNC:
3285 as_bad (_(".asmfunc without function."));
3286 break;
3288 demand_empty_rest_of_line ();
3290 else
3291 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3294 static void
3295 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3297 if (codecomposer_syntax)
3299 switch (asmfunc_state)
3301 case OUTSIDE_ASMFUNC:
3302 as_bad (_(".endasmfunc without a .asmfunc."));
3303 break;
3305 case WAITING_ASMFUNC_NAME:
3306 as_bad (_(".endasmfunc without function."));
3307 break;
3309 case WAITING_ENDASMFUNC:
3310 asmfunc_state = OUTSIDE_ASMFUNC;
3311 asmfunc_debug (NULL);
3312 break;
3314 demand_empty_rest_of_line ();
3316 else
3317 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3320 static void
3321 s_ccs_def (int name)
3323 if (codecomposer_syntax)
3324 s_globl (name);
3325 else
3326 as_bad (_(".def pseudo-op only available with -mccs flag."));
3329 /* Directives: Literal pools. */
3331 static literal_pool *
3332 find_literal_pool (void)
3334 literal_pool * pool;
3336 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3338 if (pool->section == now_seg
3339 && pool->sub_section == now_subseg)
3340 break;
3343 return pool;
3346 static literal_pool *
3347 find_or_make_literal_pool (void)
3349 /* Next literal pool ID number. */
3350 static unsigned int latest_pool_num = 1;
3351 literal_pool * pool;
3353 pool = find_literal_pool ();
3355 if (pool == NULL)
3357 /* Create a new pool. */
3358 pool = XNEW (literal_pool);
3359 if (! pool)
3360 return NULL;
3362 pool->next_free_entry = 0;
3363 pool->section = now_seg;
3364 pool->sub_section = now_subseg;
3365 pool->next = list_of_pools;
3366 pool->symbol = NULL;
3367 pool->alignment = 2;
3369 /* Add it to the list. */
3370 list_of_pools = pool;
3373 /* New pools, and emptied pools, will have a NULL symbol. */
3374 if (pool->symbol == NULL)
3376 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3377 (valueT) 0, &zero_address_frag);
3378 pool->id = latest_pool_num ++;
3381 /* Done. */
3382 return pool;
3385 /* Add the literal in the global 'inst'
3386 structure to the relevant literal pool. */
3388 static int
3389 add_to_lit_pool (unsigned int nbytes)
3391 #define PADDING_SLOT 0x1
3392 #define LIT_ENTRY_SIZE_MASK 0xFF
3393 literal_pool * pool;
3394 unsigned int entry, pool_size = 0;
3395 bfd_boolean padding_slot_p = FALSE;
3396 unsigned imm1 = 0;
3397 unsigned imm2 = 0;
3399 if (nbytes == 8)
3401 imm1 = inst.operands[1].imm;
3402 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3403 : inst.relocs[0].exp.X_unsigned ? 0
3404 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3405 if (target_big_endian)
3407 imm1 = imm2;
3408 imm2 = inst.operands[1].imm;
3412 pool = find_or_make_literal_pool ();
3414 /* Check if this literal value is already in the pool. */
3415 for (entry = 0; entry < pool->next_free_entry; entry ++)
3417 if (nbytes == 4)
3419 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3420 && (inst.relocs[0].exp.X_op == O_constant)
3421 && (pool->literals[entry].X_add_number
3422 == inst.relocs[0].exp.X_add_number)
3423 && (pool->literals[entry].X_md == nbytes)
3424 && (pool->literals[entry].X_unsigned
3425 == inst.relocs[0].exp.X_unsigned))
3426 break;
3428 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3429 && (inst.relocs[0].exp.X_op == O_symbol)
3430 && (pool->literals[entry].X_add_number
3431 == inst.relocs[0].exp.X_add_number)
3432 && (pool->literals[entry].X_add_symbol
3433 == inst.relocs[0].exp.X_add_symbol)
3434 && (pool->literals[entry].X_op_symbol
3435 == inst.relocs[0].exp.X_op_symbol)
3436 && (pool->literals[entry].X_md == nbytes))
3437 break;
3439 else if ((nbytes == 8)
3440 && !(pool_size & 0x7)
3441 && ((entry + 1) != pool->next_free_entry)
3442 && (pool->literals[entry].X_op == O_constant)
3443 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3444 && (pool->literals[entry].X_unsigned
3445 == inst.relocs[0].exp.X_unsigned)
3446 && (pool->literals[entry + 1].X_op == O_constant)
3447 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3448 && (pool->literals[entry + 1].X_unsigned
3449 == inst.relocs[0].exp.X_unsigned))
3450 break;
3452 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3453 if (padding_slot_p && (nbytes == 4))
3454 break;
3456 pool_size += 4;
3459 /* Do we need to create a new entry? */
3460 if (entry == pool->next_free_entry)
3462 if (entry >= MAX_LITERAL_POOL_SIZE)
3464 inst.error = _("literal pool overflow");
3465 return FAIL;
3468 if (nbytes == 8)
3470 /* For 8-byte entries, we align to an 8-byte boundary,
3471 and split it into two 4-byte entries, because on 32-bit
3472 host, 8-byte constants are treated as big num, thus
3473 saved in "generic_bignum" which will be overwritten
3474 by later assignments.
3476 We also need to make sure there is enough space for
3477 the split.
3479 We also check to make sure the literal operand is a
3480 constant number. */
3481 if (!(inst.relocs[0].exp.X_op == O_constant
3482 || inst.relocs[0].exp.X_op == O_big))
3484 inst.error = _("invalid type for literal pool");
3485 return FAIL;
3487 else if (pool_size & 0x7)
3489 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3491 inst.error = _("literal pool overflow");
3492 return FAIL;
3495 pool->literals[entry] = inst.relocs[0].exp;
3496 pool->literals[entry].X_op = O_constant;
3497 pool->literals[entry].X_add_number = 0;
3498 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3499 pool->next_free_entry += 1;
3500 pool_size += 4;
3502 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3504 inst.error = _("literal pool overflow");
3505 return FAIL;
3508 pool->literals[entry] = inst.relocs[0].exp;
3509 pool->literals[entry].X_op = O_constant;
3510 pool->literals[entry].X_add_number = imm1;
3511 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3512 pool->literals[entry++].X_md = 4;
3513 pool->literals[entry] = inst.relocs[0].exp;
3514 pool->literals[entry].X_op = O_constant;
3515 pool->literals[entry].X_add_number = imm2;
3516 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3517 pool->literals[entry].X_md = 4;
3518 pool->alignment = 3;
3519 pool->next_free_entry += 1;
3521 else
3523 pool->literals[entry] = inst.relocs[0].exp;
3524 pool->literals[entry].X_md = 4;
3527 #ifdef OBJ_ELF
3528 /* PR ld/12974: Record the location of the first source line to reference
3529 this entry in the literal pool. If it turns out during linking that the
3530 symbol does not exist we will be able to give an accurate line number for
3531 the (first use of the) missing reference. */
3532 if (debug_type == DEBUG_DWARF2)
3533 dwarf2_where (pool->locs + entry);
3534 #endif
3535 pool->next_free_entry += 1;
3537 else if (padding_slot_p)
3539 pool->literals[entry] = inst.relocs[0].exp;
3540 pool->literals[entry].X_md = nbytes;
3543 inst.relocs[0].exp.X_op = O_symbol;
3544 inst.relocs[0].exp.X_add_number = pool_size;
3545 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3547 return SUCCESS;
3550 bfd_boolean
3551 tc_start_label_without_colon (void)
3553 bfd_boolean ret = TRUE;
3555 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3557 const char *label = input_line_pointer;
3559 while (!is_end_of_line[(int) label[-1]])
3560 --label;
3562 if (*label == '.')
3564 as_bad (_("Invalid label '%s'"), label);
3565 ret = FALSE;
3568 asmfunc_debug (label);
3570 asmfunc_state = WAITING_ENDASMFUNC;
3573 return ret;
3576 /* Can't use symbol_new here, so have to create a symbol and then at
3577 a later date assign it a value. That's what these functions do. */
3579 static void
3580 symbol_locate (symbolS * symbolP,
3581 const char * name, /* It is copied, the caller can modify. */
3582 segT segment, /* Segment identifier (SEG_<something>). */
3583 valueT valu, /* Symbol value. */
3584 fragS * frag) /* Associated fragment. */
3586 size_t name_length;
3587 char * preserved_copy_of_name;
3589 name_length = strlen (name) + 1; /* +1 for \0. */
3590 obstack_grow (&notes, name, name_length);
3591 preserved_copy_of_name = (char *) obstack_finish (&notes);
3593 #ifdef tc_canonicalize_symbol_name
3594 preserved_copy_of_name =
3595 tc_canonicalize_symbol_name (preserved_copy_of_name);
3596 #endif
3598 S_SET_NAME (symbolP, preserved_copy_of_name);
3600 S_SET_SEGMENT (symbolP, segment);
3601 S_SET_VALUE (symbolP, valu);
3602 symbol_clear_list_pointers (symbolP);
3604 symbol_set_frag (symbolP, frag);
3606 /* Link to end of symbol chain. */
3608 extern int symbol_table_frozen;
3610 if (symbol_table_frozen)
3611 abort ();
3614 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3616 obj_symbol_new_hook (symbolP);
3618 #ifdef tc_symbol_new_hook
3619 tc_symbol_new_hook (symbolP);
3620 #endif
3622 #ifdef DEBUG_SYMS
3623 verify_symbol_chain (symbol_rootP, symbol_lastP);
3624 #endif /* DEBUG_SYMS */
3627 static void
3628 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3630 unsigned int entry;
3631 literal_pool * pool;
3632 char sym_name[20];
3634 pool = find_literal_pool ();
3635 if (pool == NULL
3636 || pool->symbol == NULL
3637 || pool->next_free_entry == 0)
3638 return;
3640 /* Align pool as you have word accesses.
3641 Only make a frag if we have to. */
3642 if (!need_pass_2)
3643 frag_align (pool->alignment, 0, 0);
3645 record_alignment (now_seg, 2);
3647 #ifdef OBJ_ELF
3648 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3649 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3650 #endif
3651 sprintf (sym_name, "$$lit_\002%x", pool->id);
3653 symbol_locate (pool->symbol, sym_name, now_seg,
3654 (valueT) frag_now_fix (), frag_now);
3655 symbol_table_insert (pool->symbol);
3657 ARM_SET_THUMB (pool->symbol, thumb_mode);
3659 #if defined OBJ_COFF || defined OBJ_ELF
3660 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3661 #endif
3663 for (entry = 0; entry < pool->next_free_entry; entry ++)
3665 #ifdef OBJ_ELF
3666 if (debug_type == DEBUG_DWARF2)
3667 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3668 #endif
3669 /* First output the expression in the instruction to the pool. */
3670 emit_expr (&(pool->literals[entry]),
3671 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3674 /* Mark the pool as empty. */
3675 pool->next_free_entry = 0;
3676 pool->symbol = NULL;
3679 #ifdef OBJ_ELF
3680 /* Forward declarations for functions below, in the MD interface
3681 section. */
3682 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3683 static valueT create_unwind_entry (int);
3684 static void start_unwind_section (const segT, int);
3685 static void add_unwind_opcode (valueT, int);
3686 static void flush_pending_unwind (void);
3688 /* Directives: Data. */
3690 static void
3691 s_arm_elf_cons (int nbytes)
3693 expressionS exp;
3695 #ifdef md_flush_pending_output
3696 md_flush_pending_output ();
3697 #endif
3699 if (is_it_end_of_statement ())
3701 demand_empty_rest_of_line ();
3702 return;
3705 #ifdef md_cons_align
3706 md_cons_align (nbytes);
3707 #endif
3709 mapping_state (MAP_DATA);
3712 int reloc;
3713 char *base = input_line_pointer;
3715 expression (& exp);
3717 if (exp.X_op != O_symbol)
3718 emit_expr (&exp, (unsigned int) nbytes);
3719 else
3721 char *before_reloc = input_line_pointer;
3722 reloc = parse_reloc (&input_line_pointer);
3723 if (reloc == -1)
3725 as_bad (_("unrecognized relocation suffix"));
3726 ignore_rest_of_line ();
3727 return;
3729 else if (reloc == BFD_RELOC_UNUSED)
3730 emit_expr (&exp, (unsigned int) nbytes);
3731 else
3733 reloc_howto_type *howto = (reloc_howto_type *)
3734 bfd_reloc_type_lookup (stdoutput,
3735 (bfd_reloc_code_real_type) reloc);
3736 int size = bfd_get_reloc_size (howto);
3738 if (reloc == BFD_RELOC_ARM_PLT32)
3740 as_bad (_("(plt) is only valid on branch targets"));
3741 reloc = BFD_RELOC_UNUSED;
3742 size = 0;
3745 if (size > nbytes)
3746 as_bad (ngettext ("%s relocations do not fit in %d byte",
3747 "%s relocations do not fit in %d bytes",
3748 nbytes),
3749 howto->name, nbytes);
3750 else
3752 /* We've parsed an expression stopping at O_symbol.
3753 But there may be more expression left now that we
3754 have parsed the relocation marker. Parse it again.
3755 XXX Surely there is a cleaner way to do this. */
3756 char *p = input_line_pointer;
3757 int offset;
3758 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3760 memcpy (save_buf, base, input_line_pointer - base);
3761 memmove (base + (input_line_pointer - before_reloc),
3762 base, before_reloc - base);
3764 input_line_pointer = base + (input_line_pointer-before_reloc);
3765 expression (&exp);
3766 memcpy (base, save_buf, p - base);
3768 offset = nbytes - size;
3769 p = frag_more (nbytes);
3770 memset (p, 0, nbytes);
3771 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3772 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3773 free (save_buf);
3778 while (*input_line_pointer++ == ',');
3780 /* Put terminator back into stream. */
3781 input_line_pointer --;
3782 demand_empty_rest_of_line ();
3785 /* Emit an expression containing a 32-bit thumb instruction.
3786 Implementation based on put_thumb32_insn. */
3788 static void
3789 emit_thumb32_expr (expressionS * exp)
3791 expressionS exp_high = *exp;
3793 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3794 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3795 exp->X_add_number &= 0xffff;
3796 emit_expr (exp, (unsigned int) THUMB_SIZE);
3799 /* Guess the instruction size based on the opcode. */
3801 static int
3802 thumb_insn_size (int opcode)
3804 if ((unsigned int) opcode < 0xe800u)
3805 return 2;
3806 else if ((unsigned int) opcode >= 0xe8000000u)
3807 return 4;
3808 else
3809 return 0;
3812 static bfd_boolean
3813 emit_insn (expressionS *exp, int nbytes)
3815 int size = 0;
3817 if (exp->X_op == O_constant)
3819 size = nbytes;
3821 if (size == 0)
3822 size = thumb_insn_size (exp->X_add_number);
3824 if (size != 0)
3826 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3828 as_bad (_(".inst.n operand too big. "\
3829 "Use .inst.w instead"));
3830 size = 0;
3832 else
3834 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3835 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
3836 else
3837 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3839 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3840 emit_thumb32_expr (exp);
3841 else
3842 emit_expr (exp, (unsigned int) size);
3844 it_fsm_post_encode ();
3847 else
3848 as_bad (_("cannot determine Thumb instruction size. " \
3849 "Use .inst.n/.inst.w instead"));
3851 else
3852 as_bad (_("constant expression required"));
3854 return (size != 0);
3857 /* Like s_arm_elf_cons but do not use md_cons_align and
3858 set the mapping state to MAP_ARM/MAP_THUMB. */
3860 static void
3861 s_arm_elf_inst (int nbytes)
3863 if (is_it_end_of_statement ())
3865 demand_empty_rest_of_line ();
3866 return;
3869 /* Calling mapping_state () here will not change ARM/THUMB,
3870 but will ensure not to be in DATA state. */
3872 if (thumb_mode)
3873 mapping_state (MAP_THUMB);
3874 else
3876 if (nbytes != 0)
3878 as_bad (_("width suffixes are invalid in ARM mode"));
3879 ignore_rest_of_line ();
3880 return;
3883 nbytes = 4;
3885 mapping_state (MAP_ARM);
3890 expressionS exp;
3892 expression (& exp);
3894 if (! emit_insn (& exp, nbytes))
3896 ignore_rest_of_line ();
3897 return;
3900 while (*input_line_pointer++ == ',');
3902 /* Put terminator back into stream. */
3903 input_line_pointer --;
3904 demand_empty_rest_of_line ();
3907 /* Parse a .rel31 directive. */
3909 static void
3910 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3912 expressionS exp;
3913 char *p;
3914 valueT highbit;
3916 highbit = 0;
3917 if (*input_line_pointer == '1')
3918 highbit = 0x80000000;
3919 else if (*input_line_pointer != '0')
3920 as_bad (_("expected 0 or 1"));
3922 input_line_pointer++;
3923 if (*input_line_pointer != ',')
3924 as_bad (_("missing comma"));
3925 input_line_pointer++;
3927 #ifdef md_flush_pending_output
3928 md_flush_pending_output ();
3929 #endif
3931 #ifdef md_cons_align
3932 md_cons_align (4);
3933 #endif
3935 mapping_state (MAP_DATA);
3937 expression (&exp);
3939 p = frag_more (4);
3940 md_number_to_chars (p, highbit, 4);
3941 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3942 BFD_RELOC_ARM_PREL31);
3944 demand_empty_rest_of_line ();
3947 /* Directives: AEABI stack-unwind tables. */
3949 /* Parse an unwind_fnstart directive. Simply records the current location. */
3951 static void
3952 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3954 demand_empty_rest_of_line ();
3955 if (unwind.proc_start)
3957 as_bad (_("duplicate .fnstart directive"));
3958 return;
3961 /* Mark the start of the function. */
3962 unwind.proc_start = expr_build_dot ();
3964 /* Reset the rest of the unwind info. */
3965 unwind.opcode_count = 0;
3966 unwind.table_entry = NULL;
3967 unwind.personality_routine = NULL;
3968 unwind.personality_index = -1;
3969 unwind.frame_size = 0;
3970 unwind.fp_offset = 0;
3971 unwind.fp_reg = REG_SP;
3972 unwind.fp_used = 0;
3973 unwind.sp_restored = 0;
3977 /* Parse a handlerdata directive. Creates the exception handling table entry
3978 for the function. */
3980 static void
3981 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3983 demand_empty_rest_of_line ();
3984 if (!unwind.proc_start)
3985 as_bad (MISSING_FNSTART);
3987 if (unwind.table_entry)
3988 as_bad (_("duplicate .handlerdata directive"));
3990 create_unwind_entry (1);
3993 /* Parse an unwind_fnend directive. Generates the index table entry. */
3995 static void
3996 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3998 long where;
3999 char *ptr;
4000 valueT val;
4001 unsigned int marked_pr_dependency;
4003 demand_empty_rest_of_line ();
4005 if (!unwind.proc_start)
4007 as_bad (_(".fnend directive without .fnstart"));
4008 return;
4011 /* Add eh table entry. */
4012 if (unwind.table_entry == NULL)
4013 val = create_unwind_entry (0);
4014 else
4015 val = 0;
4017 /* Add index table entry. This is two words. */
4018 start_unwind_section (unwind.saved_seg, 1);
4019 frag_align (2, 0, 0);
4020 record_alignment (now_seg, 2);
4022 ptr = frag_more (8);
4023 memset (ptr, 0, 8);
4024 where = frag_now_fix () - 8;
4026 /* Self relative offset of the function start. */
4027 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4028 BFD_RELOC_ARM_PREL31);
4030 /* Indicate dependency on EHABI-defined personality routines to the
4031 linker, if it hasn't been done already. */
4032 marked_pr_dependency
4033 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4034 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4035 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4037 static const char *const name[] =
4039 "__aeabi_unwind_cpp_pr0",
4040 "__aeabi_unwind_cpp_pr1",
4041 "__aeabi_unwind_cpp_pr2"
4043 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4044 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4045 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4046 |= 1 << unwind.personality_index;
4049 if (val)
4050 /* Inline exception table entry. */
4051 md_number_to_chars (ptr + 4, val, 4);
4052 else
4053 /* Self relative offset of the table entry. */
4054 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4055 BFD_RELOC_ARM_PREL31);
4057 /* Restore the original section. */
4058 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4060 unwind.proc_start = NULL;
4064 /* Parse an unwind_cantunwind directive. */
4066 static void
4067 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4069 demand_empty_rest_of_line ();
4070 if (!unwind.proc_start)
4071 as_bad (MISSING_FNSTART);
4073 if (unwind.personality_routine || unwind.personality_index != -1)
4074 as_bad (_("personality routine specified for cantunwind frame"));
4076 unwind.personality_index = -2;
4080 /* Parse a personalityindex directive. */
4082 static void
4083 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4085 expressionS exp;
4087 if (!unwind.proc_start)
4088 as_bad (MISSING_FNSTART);
4090 if (unwind.personality_routine || unwind.personality_index != -1)
4091 as_bad (_("duplicate .personalityindex directive"));
4093 expression (&exp);
4095 if (exp.X_op != O_constant
4096 || exp.X_add_number < 0 || exp.X_add_number > 15)
4098 as_bad (_("bad personality routine number"));
4099 ignore_rest_of_line ();
4100 return;
4103 unwind.personality_index = exp.X_add_number;
4105 demand_empty_rest_of_line ();
4109 /* Parse a personality directive. */
4111 static void
4112 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4114 char *name, *p, c;
4116 if (!unwind.proc_start)
4117 as_bad (MISSING_FNSTART);
4119 if (unwind.personality_routine || unwind.personality_index != -1)
4120 as_bad (_("duplicate .personality directive"));
4122 c = get_symbol_name (& name);
4123 p = input_line_pointer;
4124 if (c == '"')
4125 ++ input_line_pointer;
4126 unwind.personality_routine = symbol_find_or_make (name);
4127 *p = c;
4128 demand_empty_rest_of_line ();
4132 /* Parse a directive saving core registers. */
4134 static void
4135 s_arm_unwind_save_core (void)
4137 valueT op;
4138 long range;
4139 int n;
4141 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
4142 if (range == FAIL)
4144 as_bad (_("expected register list"));
4145 ignore_rest_of_line ();
4146 return;
4149 demand_empty_rest_of_line ();
4151 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4152 into .unwind_save {..., sp...}. We aren't bothered about the value of
4153 ip because it is clobbered by calls. */
4154 if (unwind.sp_restored && unwind.fp_reg == 12
4155 && (range & 0x3000) == 0x1000)
4157 unwind.opcode_count--;
4158 unwind.sp_restored = 0;
4159 range = (range | 0x2000) & ~0x1000;
4160 unwind.pending_offset = 0;
4163 /* Pop r4-r15. */
4164 if (range & 0xfff0)
4166 /* See if we can use the short opcodes. These pop a block of up to 8
4167 registers starting with r4, plus maybe r14. */
4168 for (n = 0; n < 8; n++)
4170 /* Break at the first non-saved register. */
4171 if ((range & (1 << (n + 4))) == 0)
4172 break;
4174 /* See if there are any other bits set. */
4175 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4177 /* Use the long form. */
4178 op = 0x8000 | ((range >> 4) & 0xfff);
4179 add_unwind_opcode (op, 2);
4181 else
4183 /* Use the short form. */
4184 if (range & 0x4000)
4185 op = 0xa8; /* Pop r14. */
4186 else
4187 op = 0xa0; /* Do not pop r14. */
4188 op |= (n - 1);
4189 add_unwind_opcode (op, 1);
4193 /* Pop r0-r3. */
4194 if (range & 0xf)
4196 op = 0xb100 | (range & 0xf);
4197 add_unwind_opcode (op, 2);
4200 /* Record the number of bytes pushed. */
4201 for (n = 0; n < 16; n++)
4203 if (range & (1 << n))
4204 unwind.frame_size += 4;
4209 /* Parse a directive saving FPA registers. */
4211 static void
4212 s_arm_unwind_save_fpa (int reg)
4214 expressionS exp;
4215 int num_regs;
4216 valueT op;
4218 /* Get Number of registers to transfer. */
4219 if (skip_past_comma (&input_line_pointer) != FAIL)
4220 expression (&exp);
4221 else
4222 exp.X_op = O_illegal;
4224 if (exp.X_op != O_constant)
4226 as_bad (_("expected , <constant>"));
4227 ignore_rest_of_line ();
4228 return;
4231 num_regs = exp.X_add_number;
4233 if (num_regs < 1 || num_regs > 4)
4235 as_bad (_("number of registers must be in the range [1:4]"));
4236 ignore_rest_of_line ();
4237 return;
4240 demand_empty_rest_of_line ();
4242 if (reg == 4)
4244 /* Short form. */
4245 op = 0xb4 | (num_regs - 1);
4246 add_unwind_opcode (op, 1);
4248 else
4250 /* Long form. */
4251 op = 0xc800 | (reg << 4) | (num_regs - 1);
4252 add_unwind_opcode (op, 2);
4254 unwind.frame_size += num_regs * 12;
4258 /* Parse a directive saving VFP registers for ARMv6 and above. */
4260 static void
4261 s_arm_unwind_save_vfp_armv6 (void)
4263 int count;
4264 unsigned int start;
4265 valueT op;
4266 int num_vfpv3_regs = 0;
4267 int num_regs_below_16;
4268 bfd_boolean partial_match;
4270 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4271 &partial_match);
4272 if (count == FAIL)
4274 as_bad (_("expected register list"));
4275 ignore_rest_of_line ();
4276 return;
4279 demand_empty_rest_of_line ();
4281 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4282 than FSTMX/FLDMX-style ones). */
4284 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4285 if (start >= 16)
4286 num_vfpv3_regs = count;
4287 else if (start + count > 16)
4288 num_vfpv3_regs = start + count - 16;
4290 if (num_vfpv3_regs > 0)
4292 int start_offset = start > 16 ? start - 16 : 0;
4293 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4294 add_unwind_opcode (op, 2);
4297 /* Generate opcode for registers numbered in the range 0 .. 15. */
4298 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4299 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4300 if (num_regs_below_16 > 0)
4302 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4303 add_unwind_opcode (op, 2);
4306 unwind.frame_size += count * 8;
4310 /* Parse a directive saving VFP registers for pre-ARMv6. */
4312 static void
4313 s_arm_unwind_save_vfp (void)
4315 int count;
4316 unsigned int reg;
4317 valueT op;
4318 bfd_boolean partial_match;
4320 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4321 &partial_match);
4322 if (count == FAIL)
4324 as_bad (_("expected register list"));
4325 ignore_rest_of_line ();
4326 return;
4329 demand_empty_rest_of_line ();
4331 if (reg == 8)
4333 /* Short form. */
4334 op = 0xb8 | (count - 1);
4335 add_unwind_opcode (op, 1);
4337 else
4339 /* Long form. */
4340 op = 0xb300 | (reg << 4) | (count - 1);
4341 add_unwind_opcode (op, 2);
4343 unwind.frame_size += count * 8 + 4;
4347 /* Parse a directive saving iWMMXt data registers. */
4349 static void
4350 s_arm_unwind_save_mmxwr (void)
4352 int reg;
4353 int hi_reg;
4354 int i;
4355 unsigned mask = 0;
4356 valueT op;
4358 if (*input_line_pointer == '{')
4359 input_line_pointer++;
4363 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4365 if (reg == FAIL)
4367 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4368 goto error;
4371 if (mask >> reg)
4372 as_tsktsk (_("register list not in ascending order"));
4373 mask |= 1 << reg;
4375 if (*input_line_pointer == '-')
4377 input_line_pointer++;
4378 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4379 if (hi_reg == FAIL)
4381 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4382 goto error;
4384 else if (reg >= hi_reg)
4386 as_bad (_("bad register range"));
4387 goto error;
4389 for (; reg < hi_reg; reg++)
4390 mask |= 1 << reg;
4393 while (skip_past_comma (&input_line_pointer) != FAIL);
4395 skip_past_char (&input_line_pointer, '}');
4397 demand_empty_rest_of_line ();
4399 /* Generate any deferred opcodes because we're going to be looking at
4400 the list. */
4401 flush_pending_unwind ();
4403 for (i = 0; i < 16; i++)
4405 if (mask & (1 << i))
4406 unwind.frame_size += 8;
4409 /* Attempt to combine with a previous opcode. We do this because gcc
4410 likes to output separate unwind directives for a single block of
4411 registers. */
4412 if (unwind.opcode_count > 0)
4414 i = unwind.opcodes[unwind.opcode_count - 1];
4415 if ((i & 0xf8) == 0xc0)
4417 i &= 7;
4418 /* Only merge if the blocks are contiguous. */
4419 if (i < 6)
4421 if ((mask & 0xfe00) == (1 << 9))
4423 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4424 unwind.opcode_count--;
4427 else if (i == 6 && unwind.opcode_count >= 2)
4429 i = unwind.opcodes[unwind.opcode_count - 2];
4430 reg = i >> 4;
4431 i &= 0xf;
4433 op = 0xffff << (reg - 1);
4434 if (reg > 0
4435 && ((mask & op) == (1u << (reg - 1))))
4437 op = (1 << (reg + i + 1)) - 1;
4438 op &= ~((1 << reg) - 1);
4439 mask |= op;
4440 unwind.opcode_count -= 2;
4446 hi_reg = 15;
4447 /* We want to generate opcodes in the order the registers have been
4448 saved, ie. descending order. */
4449 for (reg = 15; reg >= -1; reg--)
4451 /* Save registers in blocks. */
4452 if (reg < 0
4453 || !(mask & (1 << reg)))
4455 /* We found an unsaved reg. Generate opcodes to save the
4456 preceding block. */
4457 if (reg != hi_reg)
4459 if (reg == 9)
4461 /* Short form. */
4462 op = 0xc0 | (hi_reg - 10);
4463 add_unwind_opcode (op, 1);
4465 else
4467 /* Long form. */
4468 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4469 add_unwind_opcode (op, 2);
4472 hi_reg = reg - 1;
4476 return;
4477 error:
4478 ignore_rest_of_line ();
4481 static void
4482 s_arm_unwind_save_mmxwcg (void)
4484 int reg;
4485 int hi_reg;
4486 unsigned mask = 0;
4487 valueT op;
4489 if (*input_line_pointer == '{')
4490 input_line_pointer++;
4492 skip_whitespace (input_line_pointer);
4496 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4498 if (reg == FAIL)
4500 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4501 goto error;
4504 reg -= 8;
4505 if (mask >> reg)
4506 as_tsktsk (_("register list not in ascending order"));
4507 mask |= 1 << reg;
4509 if (*input_line_pointer == '-')
4511 input_line_pointer++;
4512 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4513 if (hi_reg == FAIL)
4515 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4516 goto error;
4518 else if (reg >= hi_reg)
4520 as_bad (_("bad register range"));
4521 goto error;
4523 for (; reg < hi_reg; reg++)
4524 mask |= 1 << reg;
4527 while (skip_past_comma (&input_line_pointer) != FAIL);
4529 skip_past_char (&input_line_pointer, '}');
4531 demand_empty_rest_of_line ();
4533 /* Generate any deferred opcodes because we're going to be looking at
4534 the list. */
4535 flush_pending_unwind ();
4537 for (reg = 0; reg < 16; reg++)
4539 if (mask & (1 << reg))
4540 unwind.frame_size += 4;
4542 op = 0xc700 | mask;
4543 add_unwind_opcode (op, 2);
4544 return;
4545 error:
4546 ignore_rest_of_line ();
4550 /* Parse an unwind_save directive.
4551 If the argument is non-zero, this is a .vsave directive. */
4553 static void
4554 s_arm_unwind_save (int arch_v6)
4556 char *peek;
4557 struct reg_entry *reg;
4558 bfd_boolean had_brace = FALSE;
4560 if (!unwind.proc_start)
4561 as_bad (MISSING_FNSTART);
4563 /* Figure out what sort of save we have. */
4564 peek = input_line_pointer;
4566 if (*peek == '{')
4568 had_brace = TRUE;
4569 peek++;
4572 reg = arm_reg_parse_multi (&peek);
4574 if (!reg)
4576 as_bad (_("register expected"));
4577 ignore_rest_of_line ();
4578 return;
4581 switch (reg->type)
4583 case REG_TYPE_FN:
4584 if (had_brace)
4586 as_bad (_("FPA .unwind_save does not take a register list"));
4587 ignore_rest_of_line ();
4588 return;
4590 input_line_pointer = peek;
4591 s_arm_unwind_save_fpa (reg->number);
4592 return;
4594 case REG_TYPE_RN:
4595 s_arm_unwind_save_core ();
4596 return;
4598 case REG_TYPE_VFD:
4599 if (arch_v6)
4600 s_arm_unwind_save_vfp_armv6 ();
4601 else
4602 s_arm_unwind_save_vfp ();
4603 return;
4605 case REG_TYPE_MMXWR:
4606 s_arm_unwind_save_mmxwr ();
4607 return;
4609 case REG_TYPE_MMXWCG:
4610 s_arm_unwind_save_mmxwcg ();
4611 return;
4613 default:
4614 as_bad (_(".unwind_save does not support this kind of register"));
4615 ignore_rest_of_line ();
4620 /* Parse an unwind_movsp directive. */
4622 static void
4623 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4625 int reg;
4626 valueT op;
4627 int offset;
4629 if (!unwind.proc_start)
4630 as_bad (MISSING_FNSTART);
4632 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4633 if (reg == FAIL)
4635 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4636 ignore_rest_of_line ();
4637 return;
4640 /* Optional constant. */
4641 if (skip_past_comma (&input_line_pointer) != FAIL)
4643 if (immediate_for_directive (&offset) == FAIL)
4644 return;
4646 else
4647 offset = 0;
4649 demand_empty_rest_of_line ();
4651 if (reg == REG_SP || reg == REG_PC)
4653 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4654 return;
4657 if (unwind.fp_reg != REG_SP)
4658 as_bad (_("unexpected .unwind_movsp directive"));
4660 /* Generate opcode to restore the value. */
4661 op = 0x90 | reg;
4662 add_unwind_opcode (op, 1);
4664 /* Record the information for later. */
4665 unwind.fp_reg = reg;
4666 unwind.fp_offset = unwind.frame_size - offset;
4667 unwind.sp_restored = 1;
4670 /* Parse an unwind_pad directive. */
4672 static void
4673 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4675 int offset;
4677 if (!unwind.proc_start)
4678 as_bad (MISSING_FNSTART);
4680 if (immediate_for_directive (&offset) == FAIL)
4681 return;
4683 if (offset & 3)
4685 as_bad (_("stack increment must be multiple of 4"));
4686 ignore_rest_of_line ();
4687 return;
4690 /* Don't generate any opcodes, just record the details for later. */
4691 unwind.frame_size += offset;
4692 unwind.pending_offset += offset;
4694 demand_empty_rest_of_line ();
4697 /* Parse an unwind_setfp directive. */
4699 static void
4700 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4702 int sp_reg;
4703 int fp_reg;
4704 int offset;
4706 if (!unwind.proc_start)
4707 as_bad (MISSING_FNSTART);
4709 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4710 if (skip_past_comma (&input_line_pointer) == FAIL)
4711 sp_reg = FAIL;
4712 else
4713 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4715 if (fp_reg == FAIL || sp_reg == FAIL)
4717 as_bad (_("expected <reg>, <reg>"));
4718 ignore_rest_of_line ();
4719 return;
4722 /* Optional constant. */
4723 if (skip_past_comma (&input_line_pointer) != FAIL)
4725 if (immediate_for_directive (&offset) == FAIL)
4726 return;
4728 else
4729 offset = 0;
4731 demand_empty_rest_of_line ();
4733 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4735 as_bad (_("register must be either sp or set by a previous"
4736 "unwind_movsp directive"));
4737 return;
4740 /* Don't generate any opcodes, just record the information for later. */
4741 unwind.fp_reg = fp_reg;
4742 unwind.fp_used = 1;
4743 if (sp_reg == REG_SP)
4744 unwind.fp_offset = unwind.frame_size - offset;
4745 else
4746 unwind.fp_offset -= offset;
4749 /* Parse an unwind_raw directive. */
4751 static void
4752 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4754 expressionS exp;
4755 /* This is an arbitrary limit. */
4756 unsigned char op[16];
4757 int count;
4759 if (!unwind.proc_start)
4760 as_bad (MISSING_FNSTART);
4762 expression (&exp);
4763 if (exp.X_op == O_constant
4764 && skip_past_comma (&input_line_pointer) != FAIL)
4766 unwind.frame_size += exp.X_add_number;
4767 expression (&exp);
4769 else
4770 exp.X_op = O_illegal;
4772 if (exp.X_op != O_constant)
4774 as_bad (_("expected <offset>, <opcode>"));
4775 ignore_rest_of_line ();
4776 return;
4779 count = 0;
4781 /* Parse the opcode. */
4782 for (;;)
4784 if (count >= 16)
4786 as_bad (_("unwind opcode too long"));
4787 ignore_rest_of_line ();
4789 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4791 as_bad (_("invalid unwind opcode"));
4792 ignore_rest_of_line ();
4793 return;
4795 op[count++] = exp.X_add_number;
4797 /* Parse the next byte. */
4798 if (skip_past_comma (&input_line_pointer) == FAIL)
4799 break;
4801 expression (&exp);
4804 /* Add the opcode bytes in reverse order. */
4805 while (count--)
4806 add_unwind_opcode (op[count], 1);
4808 demand_empty_rest_of_line ();
4812 /* Parse a .eabi_attribute directive. */
4814 static void
4815 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4817 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4819 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4820 attributes_set_explicitly[tag] = 1;
4823 /* Emit a tls fix for the symbol. */
4825 static void
4826 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4828 char *p;
4829 expressionS exp;
4830 #ifdef md_flush_pending_output
4831 md_flush_pending_output ();
4832 #endif
4834 #ifdef md_cons_align
4835 md_cons_align (4);
4836 #endif
4838 /* Since we're just labelling the code, there's no need to define a
4839 mapping symbol. */
4840 expression (&exp);
4841 p = obstack_next_free (&frchain_now->frch_obstack);
4842 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4843 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4844 : BFD_RELOC_ARM_TLS_DESCSEQ);
4846 #endif /* OBJ_ELF */
4848 static void s_arm_arch (int);
4849 static void s_arm_object_arch (int);
4850 static void s_arm_cpu (int);
4851 static void s_arm_fpu (int);
4852 static void s_arm_arch_extension (int);
4854 #ifdef TE_PE
4856 static void
4857 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4859 expressionS exp;
4863 expression (&exp);
4864 if (exp.X_op == O_symbol)
4865 exp.X_op = O_secrel;
4867 emit_expr (&exp, 4);
4869 while (*input_line_pointer++ == ',');
4871 input_line_pointer--;
4872 demand_empty_rest_of_line ();
4874 #endif /* TE_PE */
4876 /* This table describes all the machine specific pseudo-ops the assembler
4877 has to support. The fields are:
4878 pseudo-op name without dot
4879 function to call to execute this pseudo-op
4880 Integer arg to pass to the function. */
4882 const pseudo_typeS md_pseudo_table[] =
4884 /* Never called because '.req' does not start a line. */
4885 { "req", s_req, 0 },
4886 /* Following two are likewise never called. */
4887 { "dn", s_dn, 0 },
4888 { "qn", s_qn, 0 },
4889 { "unreq", s_unreq, 0 },
4890 { "bss", s_bss, 0 },
4891 { "align", s_align_ptwo, 2 },
4892 { "arm", s_arm, 0 },
4893 { "thumb", s_thumb, 0 },
4894 { "code", s_code, 0 },
4895 { "force_thumb", s_force_thumb, 0 },
4896 { "thumb_func", s_thumb_func, 0 },
4897 { "thumb_set", s_thumb_set, 0 },
4898 { "even", s_even, 0 },
4899 { "ltorg", s_ltorg, 0 },
4900 { "pool", s_ltorg, 0 },
4901 { "syntax", s_syntax, 0 },
4902 { "cpu", s_arm_cpu, 0 },
4903 { "arch", s_arm_arch, 0 },
4904 { "object_arch", s_arm_object_arch, 0 },
4905 { "fpu", s_arm_fpu, 0 },
4906 { "arch_extension", s_arm_arch_extension, 0 },
4907 #ifdef OBJ_ELF
4908 { "word", s_arm_elf_cons, 4 },
4909 { "long", s_arm_elf_cons, 4 },
4910 { "inst.n", s_arm_elf_inst, 2 },
4911 { "inst.w", s_arm_elf_inst, 4 },
4912 { "inst", s_arm_elf_inst, 0 },
4913 { "rel31", s_arm_rel31, 0 },
4914 { "fnstart", s_arm_unwind_fnstart, 0 },
4915 { "fnend", s_arm_unwind_fnend, 0 },
4916 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4917 { "personality", s_arm_unwind_personality, 0 },
4918 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4919 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4920 { "save", s_arm_unwind_save, 0 },
4921 { "vsave", s_arm_unwind_save, 1 },
4922 { "movsp", s_arm_unwind_movsp, 0 },
4923 { "pad", s_arm_unwind_pad, 0 },
4924 { "setfp", s_arm_unwind_setfp, 0 },
4925 { "unwind_raw", s_arm_unwind_raw, 0 },
4926 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4927 { "tlsdescseq", s_arm_tls_descseq, 0 },
4928 #else
4929 { "word", cons, 4},
4931 /* These are used for dwarf. */
4932 {"2byte", cons, 2},
4933 {"4byte", cons, 4},
4934 {"8byte", cons, 8},
4935 /* These are used for dwarf2. */
4936 { "file", dwarf2_directive_file, 0 },
4937 { "loc", dwarf2_directive_loc, 0 },
4938 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4939 #endif
4940 { "extend", float_cons, 'x' },
4941 { "ldouble", float_cons, 'x' },
4942 { "packed", float_cons, 'p' },
4943 #ifdef TE_PE
4944 {"secrel32", pe_directive_secrel, 0},
4945 #endif
4947 /* These are for compatibility with CodeComposer Studio. */
4948 {"ref", s_ccs_ref, 0},
4949 {"def", s_ccs_def, 0},
4950 {"asmfunc", s_ccs_asmfunc, 0},
4951 {"endasmfunc", s_ccs_endasmfunc, 0},
4953 { 0, 0, 0 }
4956 /* Parser functions used exclusively in instruction operands. */
4958 /* Generic immediate-value read function for use in insn parsing.
4959 STR points to the beginning of the immediate (the leading #);
4960 VAL receives the value; if the value is outside [MIN, MAX]
4961 issue an error. PREFIX_OPT is true if the immediate prefix is
4962 optional. */
4964 static int
4965 parse_immediate (char **str, int *val, int min, int max,
4966 bfd_boolean prefix_opt)
4968 expressionS exp;
4970 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4971 if (exp.X_op != O_constant)
4973 inst.error = _("constant expression required");
4974 return FAIL;
4977 if (exp.X_add_number < min || exp.X_add_number > max)
4979 inst.error = _("immediate value out of range");
4980 return FAIL;
4983 *val = exp.X_add_number;
4984 return SUCCESS;
4987 /* Less-generic immediate-value read function with the possibility of loading a
4988 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4989 instructions. Puts the result directly in inst.operands[i]. */
4991 static int
4992 parse_big_immediate (char **str, int i, expressionS *in_exp,
4993 bfd_boolean allow_symbol_p)
4995 expressionS exp;
4996 expressionS *exp_p = in_exp ? in_exp : &exp;
4997 char *ptr = *str;
4999 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5001 if (exp_p->X_op == O_constant)
5003 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5004 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5005 O_constant. We have to be careful not to break compilation for
5006 32-bit X_add_number, though. */
5007 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5009 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5010 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5011 & 0xffffffff);
5012 inst.operands[i].regisimm = 1;
5015 else if (exp_p->X_op == O_big
5016 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5018 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5020 /* Bignums have their least significant bits in
5021 generic_bignum[0]. Make sure we put 32 bits in imm and
5022 32 bits in reg, in a (hopefully) portable way. */
5023 gas_assert (parts != 0);
5025 /* Make sure that the number is not too big.
5026 PR 11972: Bignums can now be sign-extended to the
5027 size of a .octa so check that the out of range bits
5028 are all zero or all one. */
5029 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5031 LITTLENUM_TYPE m = -1;
5033 if (generic_bignum[parts * 2] != 0
5034 && generic_bignum[parts * 2] != m)
5035 return FAIL;
5037 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5038 if (generic_bignum[j] != generic_bignum[j-1])
5039 return FAIL;
5042 inst.operands[i].imm = 0;
5043 for (j = 0; j < parts; j++, idx++)
5044 inst.operands[i].imm |= generic_bignum[idx]
5045 << (LITTLENUM_NUMBER_OF_BITS * j);
5046 inst.operands[i].reg = 0;
5047 for (j = 0; j < parts; j++, idx++)
5048 inst.operands[i].reg |= generic_bignum[idx]
5049 << (LITTLENUM_NUMBER_OF_BITS * j);
5050 inst.operands[i].regisimm = 1;
5052 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5053 return FAIL;
5055 *str = ptr;
5057 return SUCCESS;
5060 /* Returns the pseudo-register number of an FPA immediate constant,
5061 or FAIL if there isn't a valid constant here. */
5063 static int
5064 parse_fpa_immediate (char ** str)
5066 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5067 char * save_in;
5068 expressionS exp;
5069 int i;
5070 int j;
5072 /* First try and match exact strings, this is to guarantee
5073 that some formats will work even for cross assembly. */
5075 for (i = 0; fp_const[i]; i++)
5077 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
5079 char *start = *str;
5081 *str += strlen (fp_const[i]);
5082 if (is_end_of_line[(unsigned char) **str])
5083 return i + 8;
5084 *str = start;
5088 /* Just because we didn't get a match doesn't mean that the constant
5089 isn't valid, just that it is in a format that we don't
5090 automatically recognize. Try parsing it with the standard
5091 expression routines. */
5093 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
5095 /* Look for a raw floating point number. */
5096 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5097 && is_end_of_line[(unsigned char) *save_in])
5099 for (i = 0; i < NUM_FLOAT_VALS; i++)
5101 for (j = 0; j < MAX_LITTLENUMS; j++)
5103 if (words[j] != fp_values[i][j])
5104 break;
5107 if (j == MAX_LITTLENUMS)
5109 *str = save_in;
5110 return i + 8;
5115 /* Try and parse a more complex expression, this will probably fail
5116 unless the code uses a floating point prefix (eg "0f"). */
5117 save_in = input_line_pointer;
5118 input_line_pointer = *str;
5119 if (expression (&exp) == absolute_section
5120 && exp.X_op == O_big
5121 && exp.X_add_number < 0)
5123 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5124 Ditto for 15. */
5125 #define X_PRECISION 5
5126 #define E_PRECISION 15L
5127 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
5129 for (i = 0; i < NUM_FLOAT_VALS; i++)
5131 for (j = 0; j < MAX_LITTLENUMS; j++)
5133 if (words[j] != fp_values[i][j])
5134 break;
5137 if (j == MAX_LITTLENUMS)
5139 *str = input_line_pointer;
5140 input_line_pointer = save_in;
5141 return i + 8;
5147 *str = input_line_pointer;
5148 input_line_pointer = save_in;
5149 inst.error = _("invalid FPA immediate expression");
5150 return FAIL;
5153 /* Returns 1 if a number has "quarter-precision" float format
5154 0baBbbbbbc defgh000 00000000 00000000. */
5156 static int
5157 is_quarter_float (unsigned imm)
5159 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5160 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5164 /* Detect the presence of a floating point or integer zero constant,
5165 i.e. #0.0 or #0. */
5167 static bfd_boolean
5168 parse_ifimm_zero (char **in)
5170 int error_code;
5172 if (!is_immediate_prefix (**in))
5174 /* In unified syntax, all prefixes are optional. */
5175 if (!unified_syntax)
5176 return FALSE;
5178 else
5179 ++*in;
5181 /* Accept #0x0 as a synonym for #0. */
5182 if (strncmp (*in, "0x", 2) == 0)
5184 int val;
5185 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5186 return FALSE;
5187 return TRUE;
5190 error_code = atof_generic (in, ".", EXP_CHARS,
5191 &generic_floating_point_number);
5193 if (!error_code
5194 && generic_floating_point_number.sign == '+'
5195 && (generic_floating_point_number.low
5196 > generic_floating_point_number.leader))
5197 return TRUE;
5199 return FALSE;
5202 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5203 0baBbbbbbc defgh000 00000000 00000000.
5204 The zero and minus-zero cases need special handling, since they can't be
5205 encoded in the "quarter-precision" float format, but can nonetheless be
5206 loaded as integer constants. */
5208 static unsigned
5209 parse_qfloat_immediate (char **ccp, int *immed)
5211 char *str = *ccp;
5212 char *fpnum;
5213 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5214 int found_fpchar = 0;
5216 skip_past_char (&str, '#');
5218 /* We must not accidentally parse an integer as a floating-point number. Make
5219 sure that the value we parse is not an integer by checking for special
5220 characters '.' or 'e'.
5221 FIXME: This is a horrible hack, but doing better is tricky because type
5222 information isn't in a very usable state at parse time. */
5223 fpnum = str;
5224 skip_whitespace (fpnum);
5226 if (strncmp (fpnum, "0x", 2) == 0)
5227 return FAIL;
5228 else
5230 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5231 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5233 found_fpchar = 1;
5234 break;
5237 if (!found_fpchar)
5238 return FAIL;
5241 if ((str = atof_ieee (str, 's', words)) != NULL)
5243 unsigned fpword = 0;
5244 int i;
5246 /* Our FP word must be 32 bits (single-precision FP). */
5247 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5249 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5250 fpword |= words[i];
5253 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5254 *immed = fpword;
5255 else
5256 return FAIL;
5258 *ccp = str;
5260 return SUCCESS;
5263 return FAIL;
5266 /* Shift operands. */
5267 enum shift_kind
5269 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5272 struct asm_shift_name
5274 const char *name;
5275 enum shift_kind kind;
5278 /* Third argument to parse_shift. */
5279 enum parse_shift_mode
5281 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5282 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5283 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5284 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5285 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5288 /* Parse a <shift> specifier on an ARM data processing instruction.
5289 This has three forms:
5291 (LSL|LSR|ASL|ASR|ROR) Rs
5292 (LSL|LSR|ASL|ASR|ROR) #imm
5295 Note that ASL is assimilated to LSL in the instruction encoding, and
5296 RRX to ROR #0 (which cannot be written as such). */
5298 static int
5299 parse_shift (char **str, int i, enum parse_shift_mode mode)
5301 const struct asm_shift_name *shift_name;
5302 enum shift_kind shift;
5303 char *s = *str;
5304 char *p = s;
5305 int reg;
5307 for (p = *str; ISALPHA (*p); p++)
5310 if (p == *str)
5312 inst.error = _("shift expression expected");
5313 return FAIL;
5316 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5317 p - *str);
5319 if (shift_name == NULL)
5321 inst.error = _("shift expression expected");
5322 return FAIL;
5325 shift = shift_name->kind;
5327 switch (mode)
5329 case NO_SHIFT_RESTRICT:
5330 case SHIFT_IMMEDIATE: break;
5332 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5333 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5335 inst.error = _("'LSL' or 'ASR' required");
5336 return FAIL;
5338 break;
5340 case SHIFT_LSL_IMMEDIATE:
5341 if (shift != SHIFT_LSL)
5343 inst.error = _("'LSL' required");
5344 return FAIL;
5346 break;
5348 case SHIFT_ASR_IMMEDIATE:
5349 if (shift != SHIFT_ASR)
5351 inst.error = _("'ASR' required");
5352 return FAIL;
5354 break;
5356 default: abort ();
5359 if (shift != SHIFT_RRX)
5361 /* Whitespace can appear here if the next thing is a bare digit. */
5362 skip_whitespace (p);
5364 if (mode == NO_SHIFT_RESTRICT
5365 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5367 inst.operands[i].imm = reg;
5368 inst.operands[i].immisreg = 1;
5370 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5371 return FAIL;
5373 inst.operands[i].shift_kind = shift;
5374 inst.operands[i].shifted = 1;
5375 *str = p;
5376 return SUCCESS;
5379 /* Parse a <shifter_operand> for an ARM data processing instruction:
5381 #<immediate>
5382 #<immediate>, <rotate>
5383 <Rm>
5384 <Rm>, <shift>
5386 where <shift> is defined by parse_shift above, and <rotate> is a
5387 multiple of 2 between 0 and 30. Validation of immediate operands
5388 is deferred to md_apply_fix. */
5390 static int
5391 parse_shifter_operand (char **str, int i)
5393 int value;
5394 expressionS exp;
5396 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5398 inst.operands[i].reg = value;
5399 inst.operands[i].isreg = 1;
5401 /* parse_shift will override this if appropriate */
5402 inst.relocs[0].exp.X_op = O_constant;
5403 inst.relocs[0].exp.X_add_number = 0;
5405 if (skip_past_comma (str) == FAIL)
5406 return SUCCESS;
5408 /* Shift operation on register. */
5409 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5412 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5413 return FAIL;
5415 if (skip_past_comma (str) == SUCCESS)
5417 /* #x, y -- ie explicit rotation by Y. */
5418 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5419 return FAIL;
5421 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5423 inst.error = _("constant expression expected");
5424 return FAIL;
5427 value = exp.X_add_number;
5428 if (value < 0 || value > 30 || value % 2 != 0)
5430 inst.error = _("invalid rotation");
5431 return FAIL;
5433 if (inst.relocs[0].exp.X_add_number < 0
5434 || inst.relocs[0].exp.X_add_number > 255)
5436 inst.error = _("invalid constant");
5437 return FAIL;
5440 /* Encode as specified. */
5441 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5442 return SUCCESS;
5445 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5446 inst.relocs[0].pc_rel = 0;
5447 return SUCCESS;
5450 /* Group relocation information. Each entry in the table contains the
5451 textual name of the relocation as may appear in assembler source
5452 and must end with a colon.
5453 Along with this textual name are the relocation codes to be used if
5454 the corresponding instruction is an ALU instruction (ADD or SUB only),
5455 an LDR, an LDRS, or an LDC. */
5457 struct group_reloc_table_entry
5459 const char *name;
5460 int alu_code;
5461 int ldr_code;
5462 int ldrs_code;
5463 int ldc_code;
5466 typedef enum
5468 /* Varieties of non-ALU group relocation. */
5470 GROUP_LDR,
5471 GROUP_LDRS,
5472 GROUP_LDC
5473 } group_reloc_type;
5475 static struct group_reloc_table_entry group_reloc_table[] =
5476 { /* Program counter relative: */
5477 { "pc_g0_nc",
5478 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5479 0, /* LDR */
5480 0, /* LDRS */
5481 0 }, /* LDC */
5482 { "pc_g0",
5483 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5484 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5485 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5486 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5487 { "pc_g1_nc",
5488 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5489 0, /* LDR */
5490 0, /* LDRS */
5491 0 }, /* LDC */
5492 { "pc_g1",
5493 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5494 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5495 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5496 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5497 { "pc_g2",
5498 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5499 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5500 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5501 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5502 /* Section base relative */
5503 { "sb_g0_nc",
5504 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5505 0, /* LDR */
5506 0, /* LDRS */
5507 0 }, /* LDC */
5508 { "sb_g0",
5509 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5510 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5511 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5512 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5513 { "sb_g1_nc",
5514 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5515 0, /* LDR */
5516 0, /* LDRS */
5517 0 }, /* LDC */
5518 { "sb_g1",
5519 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5520 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5521 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5522 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5523 { "sb_g2",
5524 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5525 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5526 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5527 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5528 /* Absolute thumb alu relocations. */
5529 { "lower0_7",
5530 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5531 0, /* LDR. */
5532 0, /* LDRS. */
5533 0 }, /* LDC. */
5534 { "lower8_15",
5535 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5536 0, /* LDR. */
5537 0, /* LDRS. */
5538 0 }, /* LDC. */
5539 { "upper0_7",
5540 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5541 0, /* LDR. */
5542 0, /* LDRS. */
5543 0 }, /* LDC. */
5544 { "upper8_15",
5545 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5546 0, /* LDR. */
5547 0, /* LDRS. */
5548 0 } }; /* LDC. */
5550 /* Given the address of a pointer pointing to the textual name of a group
5551 relocation as may appear in assembler source, attempt to find its details
5552 in group_reloc_table. The pointer will be updated to the character after
5553 the trailing colon. On failure, FAIL will be returned; SUCCESS
5554 otherwise. On success, *entry will be updated to point at the relevant
5555 group_reloc_table entry. */
5557 static int
5558 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5560 unsigned int i;
5561 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5563 int length = strlen (group_reloc_table[i].name);
5565 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5566 && (*str)[length] == ':')
5568 *out = &group_reloc_table[i];
5569 *str += (length + 1);
5570 return SUCCESS;
5574 return FAIL;
5577 /* Parse a <shifter_operand> for an ARM data processing instruction
5578 (as for parse_shifter_operand) where group relocations are allowed:
5580 #<immediate>
5581 #<immediate>, <rotate>
5582 #:<group_reloc>:<expression>
5583 <Rm>
5584 <Rm>, <shift>
5586 where <group_reloc> is one of the strings defined in group_reloc_table.
5587 The hashes are optional.
5589 Everything else is as for parse_shifter_operand. */
5591 static parse_operand_result
5592 parse_shifter_operand_group_reloc (char **str, int i)
5594 /* Determine if we have the sequence of characters #: or just :
5595 coming next. If we do, then we check for a group relocation.
5596 If we don't, punt the whole lot to parse_shifter_operand. */
5598 if (((*str)[0] == '#' && (*str)[1] == ':')
5599 || (*str)[0] == ':')
5601 struct group_reloc_table_entry *entry;
5603 if ((*str)[0] == '#')
5604 (*str) += 2;
5605 else
5606 (*str)++;
5608 /* Try to parse a group relocation. Anything else is an error. */
5609 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5611 inst.error = _("unknown group relocation");
5612 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5615 /* We now have the group relocation table entry corresponding to
5616 the name in the assembler source. Next, we parse the expression. */
5617 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5618 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5620 /* Record the relocation type (always the ALU variant here). */
5621 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5622 gas_assert (inst.relocs[0].type != 0);
5624 return PARSE_OPERAND_SUCCESS;
5626 else
5627 return parse_shifter_operand (str, i) == SUCCESS
5628 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5630 /* Never reached. */
5633 /* Parse a Neon alignment expression. Information is written to
5634 inst.operands[i]. We assume the initial ':' has been skipped.
5636 align .imm = align << 8, .immisalign=1, .preind=0 */
5637 static parse_operand_result
5638 parse_neon_alignment (char **str, int i)
5640 char *p = *str;
5641 expressionS exp;
5643 my_get_expression (&exp, &p, GE_NO_PREFIX);
5645 if (exp.X_op != O_constant)
5647 inst.error = _("alignment must be constant");
5648 return PARSE_OPERAND_FAIL;
5651 inst.operands[i].imm = exp.X_add_number << 8;
5652 inst.operands[i].immisalign = 1;
5653 /* Alignments are not pre-indexes. */
5654 inst.operands[i].preind = 0;
5656 *str = p;
5657 return PARSE_OPERAND_SUCCESS;
5660 /* Parse all forms of an ARM address expression. Information is written
5661 to inst.operands[i] and/or inst.relocs[0].
5663 Preindexed addressing (.preind=1):
5665 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5666 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5667 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5668 .shift_kind=shift .relocs[0].exp=shift_imm
5670 These three may have a trailing ! which causes .writeback to be set also.
5672 Postindexed addressing (.postind=1, .writeback=1):
5674 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5675 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5676 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5677 .shift_kind=shift .relocs[0].exp=shift_imm
5679 Unindexed addressing (.preind=0, .postind=0):
5681 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5683 Other:
5685 [Rn]{!} shorthand for [Rn,#0]{!}
5686 =immediate .isreg=0 .relocs[0].exp=immediate
5687 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5689 It is the caller's responsibility to check for addressing modes not
5690 supported by the instruction, and to set inst.relocs[0].type. */
5692 static parse_operand_result
5693 parse_address_main (char **str, int i, int group_relocations,
5694 group_reloc_type group_type)
5696 char *p = *str;
5697 int reg;
5699 if (skip_past_char (&p, '[') == FAIL)
5701 if (skip_past_char (&p, '=') == FAIL)
5703 /* Bare address - translate to PC-relative offset. */
5704 inst.relocs[0].pc_rel = 1;
5705 inst.operands[i].reg = REG_PC;
5706 inst.operands[i].isreg = 1;
5707 inst.operands[i].preind = 1;
5709 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5710 return PARSE_OPERAND_FAIL;
5712 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5713 /*allow_symbol_p=*/TRUE))
5714 return PARSE_OPERAND_FAIL;
5716 *str = p;
5717 return PARSE_OPERAND_SUCCESS;
5720 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5721 skip_whitespace (p);
5723 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5725 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5726 return PARSE_OPERAND_FAIL;
5728 inst.operands[i].reg = reg;
5729 inst.operands[i].isreg = 1;
5731 if (skip_past_comma (&p) == SUCCESS)
5733 inst.operands[i].preind = 1;
5735 if (*p == '+') p++;
5736 else if (*p == '-') p++, inst.operands[i].negative = 1;
5738 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5740 inst.operands[i].imm = reg;
5741 inst.operands[i].immisreg = 1;
5743 if (skip_past_comma (&p) == SUCCESS)
5744 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5745 return PARSE_OPERAND_FAIL;
5747 else if (skip_past_char (&p, ':') == SUCCESS)
5749 /* FIXME: '@' should be used here, but it's filtered out by generic
5750 code before we get to see it here. This may be subject to
5751 change. */
5752 parse_operand_result result = parse_neon_alignment (&p, i);
5754 if (result != PARSE_OPERAND_SUCCESS)
5755 return result;
5757 else
5759 if (inst.operands[i].negative)
5761 inst.operands[i].negative = 0;
5762 p--;
5765 if (group_relocations
5766 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5768 struct group_reloc_table_entry *entry;
5770 /* Skip over the #: or : sequence. */
5771 if (*p == '#')
5772 p += 2;
5773 else
5774 p++;
5776 /* Try to parse a group relocation. Anything else is an
5777 error. */
5778 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5780 inst.error = _("unknown group relocation");
5781 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5784 /* We now have the group relocation table entry corresponding to
5785 the name in the assembler source. Next, we parse the
5786 expression. */
5787 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5788 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5790 /* Record the relocation type. */
5791 switch (group_type)
5793 case GROUP_LDR:
5794 inst.relocs[0].type
5795 = (bfd_reloc_code_real_type) entry->ldr_code;
5796 break;
5798 case GROUP_LDRS:
5799 inst.relocs[0].type
5800 = (bfd_reloc_code_real_type) entry->ldrs_code;
5801 break;
5803 case GROUP_LDC:
5804 inst.relocs[0].type
5805 = (bfd_reloc_code_real_type) entry->ldc_code;
5806 break;
5808 default:
5809 gas_assert (0);
5812 if (inst.relocs[0].type == 0)
5814 inst.error = _("this group relocation is not allowed on this instruction");
5815 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5818 else
5820 char *q = p;
5822 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5823 return PARSE_OPERAND_FAIL;
5824 /* If the offset is 0, find out if it's a +0 or -0. */
5825 if (inst.relocs[0].exp.X_op == O_constant
5826 && inst.relocs[0].exp.X_add_number == 0)
5828 skip_whitespace (q);
5829 if (*q == '#')
5831 q++;
5832 skip_whitespace (q);
5834 if (*q == '-')
5835 inst.operands[i].negative = 1;
5840 else if (skip_past_char (&p, ':') == SUCCESS)
5842 /* FIXME: '@' should be used here, but it's filtered out by generic code
5843 before we get to see it here. This may be subject to change. */
5844 parse_operand_result result = parse_neon_alignment (&p, i);
5846 if (result != PARSE_OPERAND_SUCCESS)
5847 return result;
5850 if (skip_past_char (&p, ']') == FAIL)
5852 inst.error = _("']' expected");
5853 return PARSE_OPERAND_FAIL;
5856 if (skip_past_char (&p, '!') == SUCCESS)
5857 inst.operands[i].writeback = 1;
5859 else if (skip_past_comma (&p) == SUCCESS)
5861 if (skip_past_char (&p, '{') == SUCCESS)
5863 /* [Rn], {expr} - unindexed, with option */
5864 if (parse_immediate (&p, &inst.operands[i].imm,
5865 0, 255, TRUE) == FAIL)
5866 return PARSE_OPERAND_FAIL;
5868 if (skip_past_char (&p, '}') == FAIL)
5870 inst.error = _("'}' expected at end of 'option' field");
5871 return PARSE_OPERAND_FAIL;
5873 if (inst.operands[i].preind)
5875 inst.error = _("cannot combine index with option");
5876 return PARSE_OPERAND_FAIL;
5878 *str = p;
5879 return PARSE_OPERAND_SUCCESS;
5881 else
5883 inst.operands[i].postind = 1;
5884 inst.operands[i].writeback = 1;
5886 if (inst.operands[i].preind)
5888 inst.error = _("cannot combine pre- and post-indexing");
5889 return PARSE_OPERAND_FAIL;
5892 if (*p == '+') p++;
5893 else if (*p == '-') p++, inst.operands[i].negative = 1;
5895 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5897 /* We might be using the immediate for alignment already. If we
5898 are, OR the register number into the low-order bits. */
5899 if (inst.operands[i].immisalign)
5900 inst.operands[i].imm |= reg;
5901 else
5902 inst.operands[i].imm = reg;
5903 inst.operands[i].immisreg = 1;
5905 if (skip_past_comma (&p) == SUCCESS)
5906 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5907 return PARSE_OPERAND_FAIL;
5909 else
5911 char *q = p;
5913 if (inst.operands[i].negative)
5915 inst.operands[i].negative = 0;
5916 p--;
5918 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5919 return PARSE_OPERAND_FAIL;
5920 /* If the offset is 0, find out if it's a +0 or -0. */
5921 if (inst.relocs[0].exp.X_op == O_constant
5922 && inst.relocs[0].exp.X_add_number == 0)
5924 skip_whitespace (q);
5925 if (*q == '#')
5927 q++;
5928 skip_whitespace (q);
5930 if (*q == '-')
5931 inst.operands[i].negative = 1;
5937 /* If at this point neither .preind nor .postind is set, we have a
5938 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5939 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5941 inst.operands[i].preind = 1;
5942 inst.relocs[0].exp.X_op = O_constant;
5943 inst.relocs[0].exp.X_add_number = 0;
5945 *str = p;
5946 return PARSE_OPERAND_SUCCESS;
5949 static int
5950 parse_address (char **str, int i)
5952 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5953 ? SUCCESS : FAIL;
5956 static parse_operand_result
5957 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5959 return parse_address_main (str, i, 1, type);
5962 /* Parse an operand for a MOVW or MOVT instruction. */
5963 static int
5964 parse_half (char **str)
5966 char * p;
5968 p = *str;
5969 skip_past_char (&p, '#');
5970 if (strncasecmp (p, ":lower16:", 9) == 0)
5971 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
5972 else if (strncasecmp (p, ":upper16:", 9) == 0)
5973 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
5975 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
5977 p += 9;
5978 skip_whitespace (p);
5981 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5982 return FAIL;
5984 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
5986 if (inst.relocs[0].exp.X_op != O_constant)
5988 inst.error = _("constant expression expected");
5989 return FAIL;
5991 if (inst.relocs[0].exp.X_add_number < 0
5992 || inst.relocs[0].exp.X_add_number > 0xffff)
5994 inst.error = _("immediate value out of range");
5995 return FAIL;
5998 *str = p;
5999 return SUCCESS;
6002 /* Miscellaneous. */
6004 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6005 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6006 static int
6007 parse_psr (char **str, bfd_boolean lhs)
6009 char *p;
6010 unsigned long psr_field;
6011 const struct asm_psr *psr;
6012 char *start;
6013 bfd_boolean is_apsr = FALSE;
6014 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6016 /* PR gas/12698: If the user has specified -march=all then m_profile will
6017 be TRUE, but we want to ignore it in this case as we are building for any
6018 CPU type, including non-m variants. */
6019 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6020 m_profile = FALSE;
6022 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6023 feature for ease of use and backwards compatibility. */
6024 p = *str;
6025 if (strncasecmp (p, "SPSR", 4) == 0)
6027 if (m_profile)
6028 goto unsupported_psr;
6030 psr_field = SPSR_BIT;
6032 else if (strncasecmp (p, "CPSR", 4) == 0)
6034 if (m_profile)
6035 goto unsupported_psr;
6037 psr_field = 0;
6039 else if (strncasecmp (p, "APSR", 4) == 0)
6041 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6042 and ARMv7-R architecture CPUs. */
6043 is_apsr = TRUE;
6044 psr_field = 0;
6046 else if (m_profile)
6048 start = p;
6050 p++;
6051 while (ISALNUM (*p) || *p == '_');
6053 if (strncasecmp (start, "iapsr", 5) == 0
6054 || strncasecmp (start, "eapsr", 5) == 0
6055 || strncasecmp (start, "xpsr", 4) == 0
6056 || strncasecmp (start, "psr", 3) == 0)
6057 p = start + strcspn (start, "rR") + 1;
6059 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
6060 p - start);
6062 if (!psr)
6063 return FAIL;
6065 /* If APSR is being written, a bitfield may be specified. Note that
6066 APSR itself is handled above. */
6067 if (psr->field <= 3)
6069 psr_field = psr->field;
6070 is_apsr = TRUE;
6071 goto check_suffix;
6074 *str = p;
6075 /* M-profile MSR instructions have the mask field set to "10", except
6076 *PSR variants which modify APSR, which may use a different mask (and
6077 have been handled already). Do that by setting the PSR_f field
6078 here. */
6079 return psr->field | (lhs ? PSR_f : 0);
6081 else
6082 goto unsupported_psr;
6084 p += 4;
6085 check_suffix:
6086 if (*p == '_')
6088 /* A suffix follows. */
6089 p++;
6090 start = p;
6093 p++;
6094 while (ISALNUM (*p) || *p == '_');
6096 if (is_apsr)
6098 /* APSR uses a notation for bits, rather than fields. */
6099 unsigned int nzcvq_bits = 0;
6100 unsigned int g_bit = 0;
6101 char *bit;
6103 for (bit = start; bit != p; bit++)
6105 switch (TOLOWER (*bit))
6107 case 'n':
6108 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6109 break;
6111 case 'z':
6112 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6113 break;
6115 case 'c':
6116 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6117 break;
6119 case 'v':
6120 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6121 break;
6123 case 'q':
6124 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6125 break;
6127 case 'g':
6128 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6129 break;
6131 default:
6132 inst.error = _("unexpected bit specified after APSR");
6133 return FAIL;
6137 if (nzcvq_bits == 0x1f)
6138 psr_field |= PSR_f;
6140 if (g_bit == 0x1)
6142 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6144 inst.error = _("selected processor does not "
6145 "support DSP extension");
6146 return FAIL;
6149 psr_field |= PSR_s;
6152 if ((nzcvq_bits & 0x20) != 0
6153 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6154 || (g_bit & 0x2) != 0)
6156 inst.error = _("bad bitmask specified after APSR");
6157 return FAIL;
6160 else
6162 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
6163 p - start);
6164 if (!psr)
6165 goto error;
6167 psr_field |= psr->field;
6170 else
6172 if (ISALNUM (*p))
6173 goto error; /* Garbage after "[CS]PSR". */
6175 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6176 is deprecated, but allow it anyway. */
6177 if (is_apsr && lhs)
6179 psr_field |= PSR_f;
6180 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6181 "deprecated"));
6183 else if (!m_profile)
6184 /* These bits are never right for M-profile devices: don't set them
6185 (only code paths which read/write APSR reach here). */
6186 psr_field |= (PSR_c | PSR_f);
6188 *str = p;
6189 return psr_field;
6191 unsupported_psr:
6192 inst.error = _("selected processor does not support requested special "
6193 "purpose register");
6194 return FAIL;
6196 error:
6197 inst.error = _("flag for {c}psr instruction expected");
6198 return FAIL;
6201 static int
6202 parse_sys_vldr_vstr (char **str)
6204 unsigned i;
6205 int val = FAIL;
6206 struct {
6207 const char *name;
6208 int regl;
6209 int regh;
6210 } sysregs[] = {
6211 {"FPSCR", 0x1, 0x0},
6212 {"FPSCR_nzcvqc", 0x2, 0x0},
6213 {"VPR", 0x4, 0x1},
6214 {"P0", 0x5, 0x1},
6215 {"FPCXTNS", 0x6, 0x1},
6216 {"FPCXTS", 0x7, 0x1}
6218 char *op_end = strchr (*str, ',');
6219 size_t op_strlen = op_end - *str;
6221 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6223 if (!strncmp (*str, sysregs[i].name, op_strlen))
6225 val = sysregs[i].regl | (sysregs[i].regh << 3);
6226 *str = op_end;
6227 break;
6231 return val;
6234 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6235 value suitable for splatting into the AIF field of the instruction. */
6237 static int
6238 parse_cps_flags (char **str)
6240 int val = 0;
6241 int saw_a_flag = 0;
6242 char *s = *str;
6244 for (;;)
6245 switch (*s++)
6247 case '\0': case ',':
6248 goto done;
6250 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6251 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6252 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6254 default:
6255 inst.error = _("unrecognized CPS flag");
6256 return FAIL;
6259 done:
6260 if (saw_a_flag == 0)
6262 inst.error = _("missing CPS flags");
6263 return FAIL;
6266 *str = s - 1;
6267 return val;
6270 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6271 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6273 static int
6274 parse_endian_specifier (char **str)
6276 int little_endian;
6277 char *s = *str;
6279 if (strncasecmp (s, "BE", 2))
6280 little_endian = 0;
6281 else if (strncasecmp (s, "LE", 2))
6282 little_endian = 1;
6283 else
6285 inst.error = _("valid endian specifiers are be or le");
6286 return FAIL;
6289 if (ISALNUM (s[2]) || s[2] == '_')
6291 inst.error = _("valid endian specifiers are be or le");
6292 return FAIL;
6295 *str = s + 2;
6296 return little_endian;
6299 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6300 value suitable for poking into the rotate field of an sxt or sxta
6301 instruction, or FAIL on error. */
6303 static int
6304 parse_ror (char **str)
6306 int rot;
6307 char *s = *str;
6309 if (strncasecmp (s, "ROR", 3) == 0)
6310 s += 3;
6311 else
6313 inst.error = _("missing rotation field after comma");
6314 return FAIL;
6317 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6318 return FAIL;
6320 switch (rot)
6322 case 0: *str = s; return 0x0;
6323 case 8: *str = s; return 0x1;
6324 case 16: *str = s; return 0x2;
6325 case 24: *str = s; return 0x3;
6327 default:
6328 inst.error = _("rotation can only be 0, 8, 16, or 24");
6329 return FAIL;
6333 /* Parse a conditional code (from conds[] below). The value returned is in the
6334 range 0 .. 14, or FAIL. */
6335 static int
6336 parse_cond (char **str)
6338 char *q;
6339 const struct asm_cond *c;
6340 int n;
6341 /* Condition codes are always 2 characters, so matching up to
6342 3 characters is sufficient. */
6343 char cond[3];
6345 q = *str;
6346 n = 0;
6347 while (ISALPHA (*q) && n < 3)
6349 cond[n] = TOLOWER (*q);
6350 q++;
6351 n++;
6354 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6355 if (!c)
6357 inst.error = _("condition required");
6358 return FAIL;
6361 *str = q;
6362 return c->value;
6365 /* Parse an option for a barrier instruction. Returns the encoding for the
6366 option, or FAIL. */
6367 static int
6368 parse_barrier (char **str)
6370 char *p, *q;
6371 const struct asm_barrier_opt *o;
6373 p = q = *str;
6374 while (ISALPHA (*q))
6375 q++;
6377 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6378 q - p);
6379 if (!o)
6380 return FAIL;
6382 if (!mark_feature_used (&o->arch))
6383 return FAIL;
6385 *str = q;
6386 return o->value;
6389 /* Parse the operands of a table branch instruction. Similar to a memory
6390 operand. */
6391 static int
6392 parse_tb (char **str)
6394 char * p = *str;
6395 int reg;
6397 if (skip_past_char (&p, '[') == FAIL)
6399 inst.error = _("'[' expected");
6400 return FAIL;
6403 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6405 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6406 return FAIL;
6408 inst.operands[0].reg = reg;
6410 if (skip_past_comma (&p) == FAIL)
6412 inst.error = _("',' expected");
6413 return FAIL;
6416 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6418 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6419 return FAIL;
6421 inst.operands[0].imm = reg;
6423 if (skip_past_comma (&p) == SUCCESS)
6425 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6426 return FAIL;
6427 if (inst.relocs[0].exp.X_add_number != 1)
6429 inst.error = _("invalid shift");
6430 return FAIL;
6432 inst.operands[0].shifted = 1;
6435 if (skip_past_char (&p, ']') == FAIL)
6437 inst.error = _("']' expected");
6438 return FAIL;
6440 *str = p;
6441 return SUCCESS;
6444 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6445 information on the types the operands can take and how they are encoded.
6446 Up to four operands may be read; this function handles setting the
6447 ".present" field for each read operand itself.
6448 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6449 else returns FAIL. */
6451 static int
6452 parse_neon_mov (char **str, int *which_operand)
6454 int i = *which_operand, val;
6455 enum arm_reg_type rtype;
6456 char *ptr = *str;
6457 struct neon_type_el optype;
6459 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6461 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6462 inst.operands[i].reg = val;
6463 inst.operands[i].isscalar = 1;
6464 inst.operands[i].vectype = optype;
6465 inst.operands[i++].present = 1;
6467 if (skip_past_comma (&ptr) == FAIL)
6468 goto wanted_comma;
6470 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6471 goto wanted_arm;
6473 inst.operands[i].reg = val;
6474 inst.operands[i].isreg = 1;
6475 inst.operands[i].present = 1;
6477 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6478 != FAIL)
6480 /* Cases 0, 1, 2, 3, 5 (D only). */
6481 if (skip_past_comma (&ptr) == FAIL)
6482 goto wanted_comma;
6484 inst.operands[i].reg = val;
6485 inst.operands[i].isreg = 1;
6486 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6487 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6488 inst.operands[i].isvec = 1;
6489 inst.operands[i].vectype = optype;
6490 inst.operands[i++].present = 1;
6492 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6494 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6495 Case 13: VMOV <Sd>, <Rm> */
6496 inst.operands[i].reg = val;
6497 inst.operands[i].isreg = 1;
6498 inst.operands[i].present = 1;
6500 if (rtype == REG_TYPE_NQ)
6502 first_error (_("can't use Neon quad register here"));
6503 return FAIL;
6505 else if (rtype != REG_TYPE_VFS)
6507 i++;
6508 if (skip_past_comma (&ptr) == FAIL)
6509 goto wanted_comma;
6510 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6511 goto wanted_arm;
6512 inst.operands[i].reg = val;
6513 inst.operands[i].isreg = 1;
6514 inst.operands[i].present = 1;
6517 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6518 &optype)) != FAIL)
6520 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6521 Case 1: VMOV<c><q> <Dd>, <Dm>
6522 Case 8: VMOV.F32 <Sd>, <Sm>
6523 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6525 inst.operands[i].reg = val;
6526 inst.operands[i].isreg = 1;
6527 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6528 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6529 inst.operands[i].isvec = 1;
6530 inst.operands[i].vectype = optype;
6531 inst.operands[i].present = 1;
6533 if (skip_past_comma (&ptr) == SUCCESS)
6535 /* Case 15. */
6536 i++;
6538 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6539 goto wanted_arm;
6541 inst.operands[i].reg = val;
6542 inst.operands[i].isreg = 1;
6543 inst.operands[i++].present = 1;
6545 if (skip_past_comma (&ptr) == FAIL)
6546 goto wanted_comma;
6548 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6549 goto wanted_arm;
6551 inst.operands[i].reg = val;
6552 inst.operands[i].isreg = 1;
6553 inst.operands[i].present = 1;
6556 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6557 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6558 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6559 Case 10: VMOV.F32 <Sd>, #<imm>
6560 Case 11: VMOV.F64 <Dd>, #<imm> */
6561 inst.operands[i].immisfloat = 1;
6562 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6563 == SUCCESS)
6564 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6565 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6567 else
6569 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6570 return FAIL;
6573 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6575 /* Cases 6, 7. */
6576 inst.operands[i].reg = val;
6577 inst.operands[i].isreg = 1;
6578 inst.operands[i++].present = 1;
6580 if (skip_past_comma (&ptr) == FAIL)
6581 goto wanted_comma;
6583 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6585 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6586 inst.operands[i].reg = val;
6587 inst.operands[i].isscalar = 1;
6588 inst.operands[i].present = 1;
6589 inst.operands[i].vectype = optype;
6591 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6593 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6594 inst.operands[i].reg = val;
6595 inst.operands[i].isreg = 1;
6596 inst.operands[i++].present = 1;
6598 if (skip_past_comma (&ptr) == FAIL)
6599 goto wanted_comma;
6601 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6602 == FAIL)
6604 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6605 return FAIL;
6608 inst.operands[i].reg = val;
6609 inst.operands[i].isreg = 1;
6610 inst.operands[i].isvec = 1;
6611 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6612 inst.operands[i].vectype = optype;
6613 inst.operands[i].present = 1;
6615 if (rtype == REG_TYPE_VFS)
6617 /* Case 14. */
6618 i++;
6619 if (skip_past_comma (&ptr) == FAIL)
6620 goto wanted_comma;
6621 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6622 &optype)) == FAIL)
6624 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6625 return FAIL;
6627 inst.operands[i].reg = val;
6628 inst.operands[i].isreg = 1;
6629 inst.operands[i].isvec = 1;
6630 inst.operands[i].issingle = 1;
6631 inst.operands[i].vectype = optype;
6632 inst.operands[i].present = 1;
6635 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6636 != FAIL)
6638 /* Case 13. */
6639 inst.operands[i].reg = val;
6640 inst.operands[i].isreg = 1;
6641 inst.operands[i].isvec = 1;
6642 inst.operands[i].issingle = 1;
6643 inst.operands[i].vectype = optype;
6644 inst.operands[i].present = 1;
6647 else
6649 first_error (_("parse error"));
6650 return FAIL;
6653 /* Successfully parsed the operands. Update args. */
6654 *which_operand = i;
6655 *str = ptr;
6656 return SUCCESS;
6658 wanted_comma:
6659 first_error (_("expected comma"));
6660 return FAIL;
6662 wanted_arm:
6663 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6664 return FAIL;
6667 /* Use this macro when the operand constraints are different
6668 for ARM and THUMB (e.g. ldrd). */
6669 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6670 ((arm_operand) | ((thumb_operand) << 16))
6672 /* Matcher codes for parse_operands. */
6673 enum operand_parse_code
6675 OP_stop, /* end of line */
6677 OP_RR, /* ARM register */
6678 OP_RRnpc, /* ARM register, not r15 */
6679 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6680 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6681 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6682 optional trailing ! */
6683 OP_RRw, /* ARM register, not r15, optional trailing ! */
6684 OP_RCP, /* Coprocessor number */
6685 OP_RCN, /* Coprocessor register */
6686 OP_RF, /* FPA register */
6687 OP_RVS, /* VFP single precision register */
6688 OP_RVD, /* VFP double precision register (0..15) */
6689 OP_RND, /* Neon double precision register (0..31) */
6690 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6691 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
6693 OP_RNQ, /* Neon quad precision register */
6694 OP_RNQMQ, /* Neon quad or MVE vector register. */
6695 OP_RVSD, /* VFP single or double precision register */
6696 OP_RNSD, /* Neon single or double precision register */
6697 OP_RNDQ, /* Neon double or quad precision register */
6698 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
6699 OP_RNSDQ, /* Neon single, double or quad precision register */
6700 OP_RNSC, /* Neon scalar D[X] */
6701 OP_RVC, /* VFP control register */
6702 OP_RMF, /* Maverick F register */
6703 OP_RMD, /* Maverick D register */
6704 OP_RMFX, /* Maverick FX register */
6705 OP_RMDX, /* Maverick DX register */
6706 OP_RMAX, /* Maverick AX register */
6707 OP_RMDS, /* Maverick DSPSC register */
6708 OP_RIWR, /* iWMMXt wR register */
6709 OP_RIWC, /* iWMMXt wC register */
6710 OP_RIWG, /* iWMMXt wCG register */
6711 OP_RXA, /* XScale accumulator register */
6713 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
6715 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
6716 GPR (no SP/SP) */
6717 /* New operands for Armv8.1-M Mainline. */
6718 OP_LR, /* ARM LR register */
6719 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
6721 OP_REGLST, /* ARM register list */
6722 OP_CLRMLST, /* CLRM register list */
6723 OP_VRSLST, /* VFP single-precision register list */
6724 OP_VRDLST, /* VFP double-precision register list */
6725 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6726 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6727 OP_NSTRLST, /* Neon element/structure list */
6728 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
6730 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6731 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6732 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
6733 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6734 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
6735 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6736 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6737 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6738 OP_VMOV, /* Neon VMOV operands. */
6739 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6740 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6741 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6742 OP_VLDR, /* VLDR operand. */
6744 OP_I0, /* immediate zero */
6745 OP_I7, /* immediate value 0 .. 7 */
6746 OP_I15, /* 0 .. 15 */
6747 OP_I16, /* 1 .. 16 */
6748 OP_I16z, /* 0 .. 16 */
6749 OP_I31, /* 0 .. 31 */
6750 OP_I31w, /* 0 .. 31, optional trailing ! */
6751 OP_I32, /* 1 .. 32 */
6752 OP_I32z, /* 0 .. 32 */
6753 OP_I63, /* 0 .. 63 */
6754 OP_I63s, /* -64 .. 63 */
6755 OP_I64, /* 1 .. 64 */
6756 OP_I64z, /* 0 .. 64 */
6757 OP_I255, /* 0 .. 255 */
6759 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6760 OP_I7b, /* 0 .. 7 */
6761 OP_I15b, /* 0 .. 15 */
6762 OP_I31b, /* 0 .. 31 */
6764 OP_SH, /* shifter operand */
6765 OP_SHG, /* shifter operand with possible group relocation */
6766 OP_ADDR, /* Memory address expression (any mode) */
6767 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6768 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6769 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6770 OP_EXP, /* arbitrary expression */
6771 OP_EXPi, /* same, with optional immediate prefix */
6772 OP_EXPr, /* same, with optional relocation suffix */
6773 OP_EXPs, /* same, with optional non-first operand relocation suffix */
6774 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6775 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6776 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
6778 OP_CPSF, /* CPS flags */
6779 OP_ENDI, /* Endianness specifier */
6780 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6781 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6782 OP_COND, /* conditional code */
6783 OP_TB, /* Table branch. */
6785 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6787 OP_RRnpc_I0, /* ARM register or literal 0 */
6788 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
6789 OP_RR_EXi, /* ARM register or expression with imm prefix */
6790 OP_RF_IF, /* FPA register or immediate */
6791 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6792 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6794 /* Optional operands. */
6795 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6796 OP_oI31b, /* 0 .. 31 */
6797 OP_oI32b, /* 1 .. 32 */
6798 OP_oI32z, /* 0 .. 32 */
6799 OP_oIffffb, /* 0 .. 65535 */
6800 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6802 OP_oRR, /* ARM register */
6803 OP_oLR, /* ARM LR register */
6804 OP_oRRnpc, /* ARM register, not the PC */
6805 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6806 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6807 OP_oRND, /* Optional Neon double precision register */
6808 OP_oRNQ, /* Optional Neon quad precision register */
6809 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
6810 OP_oRNDQ, /* Optional Neon double or quad precision register */
6811 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6812 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
6813 register. */
6814 OP_oSHll, /* LSL immediate */
6815 OP_oSHar, /* ASR immediate */
6816 OP_oSHllar, /* LSL or ASR immediate */
6817 OP_oROR, /* ROR 0/8/16/24 */
6818 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6820 /* Some pre-defined mixed (ARM/THUMB) operands. */
6821 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6822 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6823 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6825 OP_FIRST_OPTIONAL = OP_oI7b
6828 /* Generic instruction operand parser. This does no encoding and no
6829 semantic validation; it merely squirrels values away in the inst
6830 structure. Returns SUCCESS or FAIL depending on whether the
6831 specified grammar matched. */
6832 static int
6833 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6835 unsigned const int *upat = pattern;
6836 char *backtrack_pos = 0;
6837 const char *backtrack_error = 0;
6838 int i, val = 0, backtrack_index = 0;
6839 enum arm_reg_type rtype;
6840 parse_operand_result result;
6841 unsigned int op_parse_code;
6842 bfd_boolean partial_match;
6844 #define po_char_or_fail(chr) \
6845 do \
6847 if (skip_past_char (&str, chr) == FAIL) \
6848 goto bad_args; \
6850 while (0)
6852 #define po_reg_or_fail(regtype) \
6853 do \
6855 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6856 & inst.operands[i].vectype); \
6857 if (val == FAIL) \
6859 first_error (_(reg_expected_msgs[regtype])); \
6860 goto failure; \
6862 inst.operands[i].reg = val; \
6863 inst.operands[i].isreg = 1; \
6864 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6865 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6866 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6867 || rtype == REG_TYPE_VFD \
6868 || rtype == REG_TYPE_NQ); \
6870 while (0)
6872 #define po_reg_or_goto(regtype, label) \
6873 do \
6875 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6876 & inst.operands[i].vectype); \
6877 if (val == FAIL) \
6878 goto label; \
6880 inst.operands[i].reg = val; \
6881 inst.operands[i].isreg = 1; \
6882 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6883 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6884 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6885 || rtype == REG_TYPE_VFD \
6886 || rtype == REG_TYPE_NQ); \
6888 while (0)
6890 #define po_imm_or_fail(min, max, popt) \
6891 do \
6893 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6894 goto failure; \
6895 inst.operands[i].imm = val; \
6897 while (0)
6899 #define po_scalar_or_goto(elsz, label) \
6900 do \
6902 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6903 if (val == FAIL) \
6904 goto label; \
6905 inst.operands[i].reg = val; \
6906 inst.operands[i].isscalar = 1; \
6908 while (0)
6910 #define po_misc_or_fail(expr) \
6911 do \
6913 if (expr) \
6914 goto failure; \
6916 while (0)
6918 #define po_misc_or_fail_no_backtrack(expr) \
6919 do \
6921 result = expr; \
6922 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6923 backtrack_pos = 0; \
6924 if (result != PARSE_OPERAND_SUCCESS) \
6925 goto failure; \
6927 while (0)
6929 #define po_barrier_or_imm(str) \
6930 do \
6932 val = parse_barrier (&str); \
6933 if (val == FAIL && ! ISALPHA (*str)) \
6934 goto immediate; \
6935 if (val == FAIL \
6936 /* ISB can only take SY as an option. */ \
6937 || ((inst.instruction & 0xf0) == 0x60 \
6938 && val != 0xf)) \
6940 inst.error = _("invalid barrier type"); \
6941 backtrack_pos = 0; \
6942 goto failure; \
6945 while (0)
6947 skip_whitespace (str);
6949 for (i = 0; upat[i] != OP_stop; i++)
6951 op_parse_code = upat[i];
6952 if (op_parse_code >= 1<<16)
6953 op_parse_code = thumb ? (op_parse_code >> 16)
6954 : (op_parse_code & ((1<<16)-1));
6956 if (op_parse_code >= OP_FIRST_OPTIONAL)
6958 /* Remember where we are in case we need to backtrack. */
6959 gas_assert (!backtrack_pos);
6960 backtrack_pos = str;
6961 backtrack_error = inst.error;
6962 backtrack_index = i;
6965 if (i > 0 && (i > 1 || inst.operands[0].present))
6966 po_char_or_fail (',');
6968 switch (op_parse_code)
6970 /* Registers */
6971 case OP_oRRnpc:
6972 case OP_oRRnpcsp:
6973 case OP_RRnpc:
6974 case OP_RRnpcsp:
6975 case OP_oRR:
6976 case OP_LR:
6977 case OP_oLR:
6978 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6979 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6980 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6981 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6982 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6983 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6984 case OP_oRND:
6985 case OP_RNDMQR:
6986 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
6987 break;
6988 try_rndmq:
6989 case OP_RNDMQ:
6990 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
6991 break;
6992 try_rnd:
6993 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6994 case OP_RVC:
6995 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6996 break;
6997 /* Also accept generic coprocessor regs for unknown registers. */
6998 coproc_reg:
6999 po_reg_or_fail (REG_TYPE_CN);
7000 break;
7001 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7002 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7003 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7004 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7005 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7006 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7007 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7008 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7009 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7010 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7011 case OP_oRNQ:
7012 case OP_RNQMQ:
7013 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7014 break;
7015 try_nq:
7016 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7017 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7018 case OP_oRNDQMQ:
7019 case OP_RNDQMQ:
7020 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7021 break;
7022 try_rndq:
7023 case OP_oRNDQ:
7024 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7025 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7026 case OP_oRNSDQ:
7027 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7028 case OP_RNSDQMQR:
7029 po_reg_or_goto (REG_TYPE_RN, try_mq);
7030 break;
7031 try_mq:
7032 case OP_oRNSDQMQ:
7033 case OP_RNSDQMQ:
7034 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7035 break;
7036 try_nsdq2:
7037 po_reg_or_fail (REG_TYPE_NSDQ);
7038 inst.error = 0;
7039 break;
7040 /* Neon scalar. Using an element size of 8 means that some invalid
7041 scalars are accepted here, so deal with those in later code. */
7042 case OP_RNSC: po_scalar_or_goto (8, failure); break;
7044 case OP_RNDQ_I0:
7046 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7047 break;
7048 try_imm0:
7049 po_imm_or_fail (0, 0, TRUE);
7051 break;
7053 case OP_RVSD_I0:
7054 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7055 break;
7057 case OP_RSVD_FI0:
7059 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7060 break;
7061 try_ifimm0:
7062 if (parse_ifimm_zero (&str))
7063 inst.operands[i].imm = 0;
7064 else
7066 inst.error
7067 = _("only floating point zero is allowed as immediate value");
7068 goto failure;
7071 break;
7073 case OP_RR_RNSC:
7075 po_scalar_or_goto (8, try_rr);
7076 break;
7077 try_rr:
7078 po_reg_or_fail (REG_TYPE_RN);
7080 break;
7082 case OP_RNSDQ_RNSC:
7084 po_scalar_or_goto (8, try_nsdq);
7085 break;
7086 try_nsdq:
7087 po_reg_or_fail (REG_TYPE_NSDQ);
7089 break;
7091 case OP_RNSD_RNSC:
7093 po_scalar_or_goto (8, try_s_scalar);
7094 break;
7095 try_s_scalar:
7096 po_scalar_or_goto (4, try_nsd);
7097 break;
7098 try_nsd:
7099 po_reg_or_fail (REG_TYPE_NSD);
7101 break;
7103 case OP_RNDQ_RNSC:
7105 po_scalar_or_goto (8, try_ndq);
7106 break;
7107 try_ndq:
7108 po_reg_or_fail (REG_TYPE_NDQ);
7110 break;
7112 case OP_RND_RNSC:
7114 po_scalar_or_goto (8, try_vfd);
7115 break;
7116 try_vfd:
7117 po_reg_or_fail (REG_TYPE_VFD);
7119 break;
7121 case OP_VMOV:
7122 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7123 not careful then bad things might happen. */
7124 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7125 break;
7127 case OP_RNDQ_Ibig:
7129 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7130 break;
7131 try_immbig:
7132 /* There's a possibility of getting a 64-bit immediate here, so
7133 we need special handling. */
7134 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7135 == FAIL)
7137 inst.error = _("immediate value is out of range");
7138 goto failure;
7141 break;
7143 case OP_RNDQ_I63b:
7145 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7146 break;
7147 try_shimm:
7148 po_imm_or_fail (0, 63, TRUE);
7150 break;
7152 case OP_RRnpcb:
7153 po_char_or_fail ('[');
7154 po_reg_or_fail (REG_TYPE_RN);
7155 po_char_or_fail (']');
7156 break;
7158 case OP_RRnpctw:
7159 case OP_RRw:
7160 case OP_oRRw:
7161 po_reg_or_fail (REG_TYPE_RN);
7162 if (skip_past_char (&str, '!') == SUCCESS)
7163 inst.operands[i].writeback = 1;
7164 break;
7166 /* Immediates */
7167 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7168 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7169 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
7170 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
7171 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7172 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
7173 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
7174 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
7175 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7176 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7177 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
7178 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
7180 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7181 case OP_oI7b:
7182 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7183 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7184 case OP_oI31b:
7185 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
7186 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7187 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
7188 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7190 /* Immediate variants */
7191 case OP_oI255c:
7192 po_char_or_fail ('{');
7193 po_imm_or_fail (0, 255, TRUE);
7194 po_char_or_fail ('}');
7195 break;
7197 case OP_I31w:
7198 /* The expression parser chokes on a trailing !, so we have
7199 to find it first and zap it. */
7201 char *s = str;
7202 while (*s && *s != ',')
7203 s++;
7204 if (s[-1] == '!')
7206 s[-1] = '\0';
7207 inst.operands[i].writeback = 1;
7209 po_imm_or_fail (0, 31, TRUE);
7210 if (str == s - 1)
7211 str = s;
7213 break;
7215 /* Expressions */
7216 case OP_EXPi: EXPi:
7217 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7218 GE_OPT_PREFIX));
7219 break;
7221 case OP_EXP:
7222 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7223 GE_NO_PREFIX));
7224 break;
7226 case OP_EXPr: EXPr:
7227 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7228 GE_NO_PREFIX));
7229 if (inst.relocs[0].exp.X_op == O_symbol)
7231 val = parse_reloc (&str);
7232 if (val == -1)
7234 inst.error = _("unrecognized relocation suffix");
7235 goto failure;
7237 else if (val != BFD_RELOC_UNUSED)
7239 inst.operands[i].imm = val;
7240 inst.operands[i].hasreloc = 1;
7243 break;
7245 case OP_EXPs:
7246 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7247 GE_NO_PREFIX));
7248 if (inst.relocs[i].exp.X_op == O_symbol)
7250 inst.operands[i].hasreloc = 1;
7252 else if (inst.relocs[i].exp.X_op == O_constant)
7254 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7255 inst.operands[i].hasreloc = 0;
7257 break;
7259 /* Operand for MOVW or MOVT. */
7260 case OP_HALF:
7261 po_misc_or_fail (parse_half (&str));
7262 break;
7264 /* Register or expression. */
7265 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7266 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7268 /* Register or immediate. */
7269 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7270 I0: po_imm_or_fail (0, 0, FALSE); break;
7272 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7274 if (!is_immediate_prefix (*str))
7275 goto bad_args;
7276 str++;
7277 val = parse_fpa_immediate (&str);
7278 if (val == FAIL)
7279 goto failure;
7280 /* FPA immediates are encoded as registers 8-15.
7281 parse_fpa_immediate has already applied the offset. */
7282 inst.operands[i].reg = val;
7283 inst.operands[i].isreg = 1;
7284 break;
7286 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7287 I32z: po_imm_or_fail (0, 32, FALSE); break;
7289 /* Two kinds of register. */
7290 case OP_RIWR_RIWC:
7292 struct reg_entry *rege = arm_reg_parse_multi (&str);
7293 if (!rege
7294 || (rege->type != REG_TYPE_MMXWR
7295 && rege->type != REG_TYPE_MMXWC
7296 && rege->type != REG_TYPE_MMXWCG))
7298 inst.error = _("iWMMXt data or control register expected");
7299 goto failure;
7301 inst.operands[i].reg = rege->number;
7302 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7304 break;
7306 case OP_RIWC_RIWG:
7308 struct reg_entry *rege = arm_reg_parse_multi (&str);
7309 if (!rege
7310 || (rege->type != REG_TYPE_MMXWC
7311 && rege->type != REG_TYPE_MMXWCG))
7313 inst.error = _("iWMMXt control register expected");
7314 goto failure;
7316 inst.operands[i].reg = rege->number;
7317 inst.operands[i].isreg = 1;
7319 break;
7321 /* Misc */
7322 case OP_CPSF: val = parse_cps_flags (&str); break;
7323 case OP_ENDI: val = parse_endian_specifier (&str); break;
7324 case OP_oROR: val = parse_ror (&str); break;
7325 case OP_COND: val = parse_cond (&str); break;
7326 case OP_oBARRIER_I15:
7327 po_barrier_or_imm (str); break;
7328 immediate:
7329 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7330 goto failure;
7331 break;
7333 case OP_wPSR:
7334 case OP_rPSR:
7335 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7336 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7338 inst.error = _("Banked registers are not available with this "
7339 "architecture.");
7340 goto failure;
7342 break;
7343 try_psr:
7344 val = parse_psr (&str, op_parse_code == OP_wPSR);
7345 break;
7347 case OP_VLDR:
7348 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7349 break;
7350 try_sysreg:
7351 val = parse_sys_vldr_vstr (&str);
7352 break;
7354 case OP_APSR_RR:
7355 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7356 break;
7357 try_apsr:
7358 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7359 instruction). */
7360 if (strncasecmp (str, "APSR_", 5) == 0)
7362 unsigned found = 0;
7363 str += 5;
7364 while (found < 15)
7365 switch (*str++)
7367 case 'c': found = (found & 1) ? 16 : found | 1; break;
7368 case 'n': found = (found & 2) ? 16 : found | 2; break;
7369 case 'z': found = (found & 4) ? 16 : found | 4; break;
7370 case 'v': found = (found & 8) ? 16 : found | 8; break;
7371 default: found = 16;
7373 if (found != 15)
7374 goto failure;
7375 inst.operands[i].isvec = 1;
7376 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7377 inst.operands[i].reg = REG_PC;
7379 else
7380 goto failure;
7381 break;
7383 case OP_TB:
7384 po_misc_or_fail (parse_tb (&str));
7385 break;
7387 /* Register lists. */
7388 case OP_REGLST:
7389 val = parse_reg_list (&str, REGLIST_RN);
7390 if (*str == '^')
7392 inst.operands[i].writeback = 1;
7393 str++;
7395 break;
7397 case OP_CLRMLST:
7398 val = parse_reg_list (&str, REGLIST_CLRM);
7399 break;
7401 case OP_VRSLST:
7402 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7403 &partial_match);
7404 break;
7406 case OP_VRDLST:
7407 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7408 &partial_match);
7409 break;
7411 case OP_VRSDLST:
7412 /* Allow Q registers too. */
7413 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7414 REGLIST_NEON_D, &partial_match);
7415 if (val == FAIL)
7417 inst.error = NULL;
7418 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7419 REGLIST_VFP_S, &partial_match);
7420 inst.operands[i].issingle = 1;
7422 break;
7424 case OP_VRSDVLST:
7425 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7426 REGLIST_VFP_D_VPR, &partial_match);
7427 if (val == FAIL && !partial_match)
7429 inst.error = NULL;
7430 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7431 REGLIST_VFP_S_VPR, &partial_match);
7432 inst.operands[i].issingle = 1;
7434 break;
7436 case OP_NRDLST:
7437 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7438 REGLIST_NEON_D, &partial_match);
7439 break;
7441 case OP_NSTRLST:
7442 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7443 &inst.operands[i].vectype);
7444 break;
7446 /* Addressing modes */
7447 case OP_ADDR:
7448 po_misc_or_fail (parse_address (&str, i));
7449 break;
7451 case OP_ADDRGLDR:
7452 po_misc_or_fail_no_backtrack (
7453 parse_address_group_reloc (&str, i, GROUP_LDR));
7454 break;
7456 case OP_ADDRGLDRS:
7457 po_misc_or_fail_no_backtrack (
7458 parse_address_group_reloc (&str, i, GROUP_LDRS));
7459 break;
7461 case OP_ADDRGLDC:
7462 po_misc_or_fail_no_backtrack (
7463 parse_address_group_reloc (&str, i, GROUP_LDC));
7464 break;
7466 case OP_SH:
7467 po_misc_or_fail (parse_shifter_operand (&str, i));
7468 break;
7470 case OP_SHG:
7471 po_misc_or_fail_no_backtrack (
7472 parse_shifter_operand_group_reloc (&str, i));
7473 break;
7475 case OP_oSHll:
7476 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7477 break;
7479 case OP_oSHar:
7480 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7481 break;
7483 case OP_oSHllar:
7484 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7485 break;
7487 default:
7488 as_fatal (_("unhandled operand code %d"), op_parse_code);
7491 /* Various value-based sanity checks and shared operations. We
7492 do not signal immediate failures for the register constraints;
7493 this allows a syntax error to take precedence. */
7494 switch (op_parse_code)
7496 case OP_oRRnpc:
7497 case OP_RRnpc:
7498 case OP_RRnpcb:
7499 case OP_RRw:
7500 case OP_oRRw:
7501 case OP_RRnpc_I0:
7502 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7503 inst.error = BAD_PC;
7504 break;
7506 case OP_oRRnpcsp:
7507 case OP_RRnpcsp:
7508 if (inst.operands[i].isreg)
7510 if (inst.operands[i].reg == REG_PC)
7511 inst.error = BAD_PC;
7512 else if (inst.operands[i].reg == REG_SP
7513 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7514 relaxed since ARMv8-A. */
7515 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7517 gas_assert (thumb);
7518 inst.error = BAD_SP;
7521 break;
7523 case OP_RRnpctw:
7524 if (inst.operands[i].isreg
7525 && inst.operands[i].reg == REG_PC
7526 && (inst.operands[i].writeback || thumb))
7527 inst.error = BAD_PC;
7528 break;
7530 case OP_VLDR:
7531 if (inst.operands[i].isreg)
7532 break;
7533 /* fall through. */
7534 case OP_CPSF:
7535 case OP_ENDI:
7536 case OP_oROR:
7537 case OP_wPSR:
7538 case OP_rPSR:
7539 case OP_COND:
7540 case OP_oBARRIER_I15:
7541 case OP_REGLST:
7542 case OP_CLRMLST:
7543 case OP_VRSLST:
7544 case OP_VRDLST:
7545 case OP_VRSDLST:
7546 case OP_VRSDVLST:
7547 case OP_NRDLST:
7548 case OP_NSTRLST:
7549 if (val == FAIL)
7550 goto failure;
7551 inst.operands[i].imm = val;
7552 break;
7554 case OP_LR:
7555 case OP_oLR:
7556 if (inst.operands[i].reg != REG_LR)
7557 inst.error = _("operand must be LR register");
7558 break;
7560 default:
7561 break;
7564 /* If we get here, this operand was successfully parsed. */
7565 inst.operands[i].present = 1;
7566 continue;
7568 bad_args:
7569 inst.error = BAD_ARGS;
7571 failure:
7572 if (!backtrack_pos)
7574 /* The parse routine should already have set inst.error, but set a
7575 default here just in case. */
7576 if (!inst.error)
7577 inst.error = BAD_SYNTAX;
7578 return FAIL;
7581 /* Do not backtrack over a trailing optional argument that
7582 absorbed some text. We will only fail again, with the
7583 'garbage following instruction' error message, which is
7584 probably less helpful than the current one. */
7585 if (backtrack_index == i && backtrack_pos != str
7586 && upat[i+1] == OP_stop)
7588 if (!inst.error)
7589 inst.error = BAD_SYNTAX;
7590 return FAIL;
7593 /* Try again, skipping the optional argument at backtrack_pos. */
7594 str = backtrack_pos;
7595 inst.error = backtrack_error;
7596 inst.operands[backtrack_index].present = 0;
7597 i = backtrack_index;
7598 backtrack_pos = 0;
7601 /* Check that we have parsed all the arguments. */
7602 if (*str != '\0' && !inst.error)
7603 inst.error = _("garbage following instruction");
7605 return inst.error ? FAIL : SUCCESS;
7608 #undef po_char_or_fail
7609 #undef po_reg_or_fail
7610 #undef po_reg_or_goto
7611 #undef po_imm_or_fail
7612 #undef po_scalar_or_fail
7613 #undef po_barrier_or_imm
7615 /* Shorthand macro for instruction encoding functions issuing errors. */
7616 #define constraint(expr, err) \
7617 do \
7619 if (expr) \
7621 inst.error = err; \
7622 return; \
7625 while (0)
7627 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7628 instructions are unpredictable if these registers are used. This
7629 is the BadReg predicate in ARM's Thumb-2 documentation.
7631 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7632 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7633 #define reject_bad_reg(reg) \
7634 do \
7635 if (reg == REG_PC) \
7637 inst.error = BAD_PC; \
7638 return; \
7640 else if (reg == REG_SP \
7641 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7643 inst.error = BAD_SP; \
7644 return; \
7646 while (0)
7648 /* If REG is R13 (the stack pointer), warn that its use is
7649 deprecated. */
7650 #define warn_deprecated_sp(reg) \
7651 do \
7652 if (warn_on_deprecated && reg == REG_SP) \
7653 as_tsktsk (_("use of r13 is deprecated")); \
7654 while (0)
7656 /* Functions for operand encoding. ARM, then Thumb. */
7658 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
7660 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7662 The only binary encoding difference is the Coprocessor number. Coprocessor
7663 9 is used for half-precision calculations or conversions. The format of the
7664 instruction is the same as the equivalent Coprocessor 10 instruction that
7665 exists for Single-Precision operation. */
7667 static void
7668 do_scalar_fp16_v82_encode (void)
7670 if (inst.cond < COND_ALWAYS)
7671 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7672 " the behaviour is UNPREDICTABLE"));
7673 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7674 _(BAD_FP16));
7676 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7677 mark_feature_used (&arm_ext_fp16);
7680 /* If VAL can be encoded in the immediate field of an ARM instruction,
7681 return the encoded form. Otherwise, return FAIL. */
7683 static unsigned int
7684 encode_arm_immediate (unsigned int val)
7686 unsigned int a, i;
7688 if (val <= 0xff)
7689 return val;
7691 for (i = 2; i < 32; i += 2)
7692 if ((a = rotate_left (val, i)) <= 0xff)
7693 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7695 return FAIL;
7698 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7699 return the encoded form. Otherwise, return FAIL. */
7700 static unsigned int
7701 encode_thumb32_immediate (unsigned int val)
7703 unsigned int a, i;
7705 if (val <= 0xff)
7706 return val;
7708 for (i = 1; i <= 24; i++)
7710 a = val >> i;
7711 if ((val & ~(0xff << i)) == 0)
7712 return ((val >> i) & 0x7f) | ((32 - i) << 7);
7715 a = val & 0xff;
7716 if (val == ((a << 16) | a))
7717 return 0x100 | a;
7718 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7719 return 0x300 | a;
7721 a = val & 0xff00;
7722 if (val == ((a << 16) | a))
7723 return 0x200 | (a >> 8);
7725 return FAIL;
7727 /* Encode a VFP SP or DP register number into inst.instruction. */
7729 static void
7730 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7732 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7733 && reg > 15)
7735 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
7737 if (thumb_mode)
7738 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7739 fpu_vfp_ext_d32);
7740 else
7741 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7742 fpu_vfp_ext_d32);
7744 else
7746 first_error (_("D register out of range for selected VFP version"));
7747 return;
7751 switch (pos)
7753 case VFP_REG_Sd:
7754 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7755 break;
7757 case VFP_REG_Sn:
7758 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7759 break;
7761 case VFP_REG_Sm:
7762 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7763 break;
7765 case VFP_REG_Dd:
7766 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7767 break;
7769 case VFP_REG_Dn:
7770 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7771 break;
7773 case VFP_REG_Dm:
7774 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7775 break;
7777 default:
7778 abort ();
7782 /* Encode a <shift> in an ARM-format instruction. The immediate,
7783 if any, is handled by md_apply_fix. */
7784 static void
7785 encode_arm_shift (int i)
7787 /* register-shifted register. */
7788 if (inst.operands[i].immisreg)
7790 int op_index;
7791 for (op_index = 0; op_index <= i; ++op_index)
7793 /* Check the operand only when it's presented. In pre-UAL syntax,
7794 if the destination register is the same as the first operand, two
7795 register form of the instruction can be used. */
7796 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7797 && inst.operands[op_index].reg == REG_PC)
7798 as_warn (UNPRED_REG ("r15"));
7801 if (inst.operands[i].imm == REG_PC)
7802 as_warn (UNPRED_REG ("r15"));
7805 if (inst.operands[i].shift_kind == SHIFT_RRX)
7806 inst.instruction |= SHIFT_ROR << 5;
7807 else
7809 inst.instruction |= inst.operands[i].shift_kind << 5;
7810 if (inst.operands[i].immisreg)
7812 inst.instruction |= SHIFT_BY_REG;
7813 inst.instruction |= inst.operands[i].imm << 8;
7815 else
7816 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
7820 static void
7821 encode_arm_shifter_operand (int i)
7823 if (inst.operands[i].isreg)
7825 inst.instruction |= inst.operands[i].reg;
7826 encode_arm_shift (i);
7828 else
7830 inst.instruction |= INST_IMMEDIATE;
7831 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
7832 inst.instruction |= inst.operands[i].imm;
7836 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7837 static void
7838 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7840 /* PR 14260:
7841 Generate an error if the operand is not a register. */
7842 constraint (!inst.operands[i].isreg,
7843 _("Instruction does not support =N addresses"));
7845 inst.instruction |= inst.operands[i].reg << 16;
7847 if (inst.operands[i].preind)
7849 if (is_t)
7851 inst.error = _("instruction does not accept preindexed addressing");
7852 return;
7854 inst.instruction |= PRE_INDEX;
7855 if (inst.operands[i].writeback)
7856 inst.instruction |= WRITE_BACK;
7859 else if (inst.operands[i].postind)
7861 gas_assert (inst.operands[i].writeback);
7862 if (is_t)
7863 inst.instruction |= WRITE_BACK;
7865 else /* unindexed - only for coprocessor */
7867 inst.error = _("instruction does not accept unindexed addressing");
7868 return;
7871 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7872 && (((inst.instruction & 0x000f0000) >> 16)
7873 == ((inst.instruction & 0x0000f000) >> 12)))
7874 as_warn ((inst.instruction & LOAD_BIT)
7875 ? _("destination register same as write-back base")
7876 : _("source register same as write-back base"));
7879 /* inst.operands[i] was set up by parse_address. Encode it into an
7880 ARM-format mode 2 load or store instruction. If is_t is true,
7881 reject forms that cannot be used with a T instruction (i.e. not
7882 post-indexed). */
7883 static void
7884 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7886 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7888 encode_arm_addr_mode_common (i, is_t);
7890 if (inst.operands[i].immisreg)
7892 constraint ((inst.operands[i].imm == REG_PC
7893 || (is_pc && inst.operands[i].writeback)),
7894 BAD_PC_ADDRESSING);
7895 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7896 inst.instruction |= inst.operands[i].imm;
7897 if (!inst.operands[i].negative)
7898 inst.instruction |= INDEX_UP;
7899 if (inst.operands[i].shifted)
7901 if (inst.operands[i].shift_kind == SHIFT_RRX)
7902 inst.instruction |= SHIFT_ROR << 5;
7903 else
7905 inst.instruction |= inst.operands[i].shift_kind << 5;
7906 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
7910 else /* immediate offset in inst.relocs[0] */
7912 if (is_pc && !inst.relocs[0].pc_rel)
7914 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7916 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7917 cannot use PC in addressing.
7918 PC cannot be used in writeback addressing, either. */
7919 constraint ((is_t || inst.operands[i].writeback),
7920 BAD_PC_ADDRESSING);
7922 /* Use of PC in str is deprecated for ARMv7. */
7923 if (warn_on_deprecated
7924 && !is_load
7925 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7926 as_tsktsk (_("use of PC in this instruction is deprecated"));
7929 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
7931 /* Prefer + for zero encoded value. */
7932 if (!inst.operands[i].negative)
7933 inst.instruction |= INDEX_UP;
7934 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
7939 /* inst.operands[i] was set up by parse_address. Encode it into an
7940 ARM-format mode 3 load or store instruction. Reject forms that
7941 cannot be used with such instructions. If is_t is true, reject
7942 forms that cannot be used with a T instruction (i.e. not
7943 post-indexed). */
7944 static void
7945 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7947 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7949 inst.error = _("instruction does not accept scaled register index");
7950 return;
7953 encode_arm_addr_mode_common (i, is_t);
7955 if (inst.operands[i].immisreg)
7957 constraint ((inst.operands[i].imm == REG_PC
7958 || (is_t && inst.operands[i].reg == REG_PC)),
7959 BAD_PC_ADDRESSING);
7960 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7961 BAD_PC_WRITEBACK);
7962 inst.instruction |= inst.operands[i].imm;
7963 if (!inst.operands[i].negative)
7964 inst.instruction |= INDEX_UP;
7966 else /* immediate offset in inst.relocs[0] */
7968 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
7969 && inst.operands[i].writeback),
7970 BAD_PC_WRITEBACK);
7971 inst.instruction |= HWOFFSET_IMM;
7972 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
7974 /* Prefer + for zero encoded value. */
7975 if (!inst.operands[i].negative)
7976 inst.instruction |= INDEX_UP;
7978 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
7983 /* Write immediate bits [7:0] to the following locations:
7985 |28/24|23 19|18 16|15 4|3 0|
7986 | 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|
7988 This function is used by VMOV/VMVN/VORR/VBIC. */
7990 static void
7991 neon_write_immbits (unsigned immbits)
7993 inst.instruction |= immbits & 0xf;
7994 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7995 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7998 /* Invert low-order SIZE bits of XHI:XLO. */
8000 static void
8001 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8003 unsigned immlo = xlo ? *xlo : 0;
8004 unsigned immhi = xhi ? *xhi : 0;
8006 switch (size)
8008 case 8:
8009 immlo = (~immlo) & 0xff;
8010 break;
8012 case 16:
8013 immlo = (~immlo) & 0xffff;
8014 break;
8016 case 64:
8017 immhi = (~immhi) & 0xffffffff;
8018 /* fall through. */
8020 case 32:
8021 immlo = (~immlo) & 0xffffffff;
8022 break;
8024 default:
8025 abort ();
8028 if (xlo)
8029 *xlo = immlo;
8031 if (xhi)
8032 *xhi = immhi;
8035 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8036 A, B, C, D. */
8038 static int
8039 neon_bits_same_in_bytes (unsigned imm)
8041 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8042 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8043 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8044 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8047 /* For immediate of above form, return 0bABCD. */
8049 static unsigned
8050 neon_squash_bits (unsigned imm)
8052 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8053 | ((imm & 0x01000000) >> 21);
8056 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8058 static unsigned
8059 neon_qfloat_bits (unsigned imm)
8061 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8064 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8065 the instruction. *OP is passed as the initial value of the op field, and
8066 may be set to a different value depending on the constant (i.e.
8067 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8068 MVN). If the immediate looks like a repeated pattern then also
8069 try smaller element sizes. */
8071 static int
8072 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8073 unsigned *immbits, int *op, int size,
8074 enum neon_el_type type)
8076 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8077 float. */
8078 if (type == NT_float && !float_p)
8079 return FAIL;
8081 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8083 if (size != 32 || *op == 1)
8084 return FAIL;
8085 *immbits = neon_qfloat_bits (immlo);
8086 return 0xf;
8089 if (size == 64)
8091 if (neon_bits_same_in_bytes (immhi)
8092 && neon_bits_same_in_bytes (immlo))
8094 if (*op == 1)
8095 return FAIL;
8096 *immbits = (neon_squash_bits (immhi) << 4)
8097 | neon_squash_bits (immlo);
8098 *op = 1;
8099 return 0xe;
8102 if (immhi != immlo)
8103 return FAIL;
8106 if (size >= 32)
8108 if (immlo == (immlo & 0x000000ff))
8110 *immbits = immlo;
8111 return 0x0;
8113 else if (immlo == (immlo & 0x0000ff00))
8115 *immbits = immlo >> 8;
8116 return 0x2;
8118 else if (immlo == (immlo & 0x00ff0000))
8120 *immbits = immlo >> 16;
8121 return 0x4;
8123 else if (immlo == (immlo & 0xff000000))
8125 *immbits = immlo >> 24;
8126 return 0x6;
8128 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8130 *immbits = (immlo >> 8) & 0xff;
8131 return 0xc;
8133 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8135 *immbits = (immlo >> 16) & 0xff;
8136 return 0xd;
8139 if ((immlo & 0xffff) != (immlo >> 16))
8140 return FAIL;
8141 immlo &= 0xffff;
8144 if (size >= 16)
8146 if (immlo == (immlo & 0x000000ff))
8148 *immbits = immlo;
8149 return 0x8;
8151 else if (immlo == (immlo & 0x0000ff00))
8153 *immbits = immlo >> 8;
8154 return 0xa;
8157 if ((immlo & 0xff) != (immlo >> 8))
8158 return FAIL;
8159 immlo &= 0xff;
8162 if (immlo == (immlo & 0x000000ff))
8164 /* Don't allow MVN with 8-bit immediate. */
8165 if (*op == 1)
8166 return FAIL;
8167 *immbits = immlo;
8168 return 0xe;
8171 return FAIL;
8174 #if defined BFD_HOST_64_BIT
8175 /* Returns TRUE if double precision value V may be cast
8176 to single precision without loss of accuracy. */
8178 static bfd_boolean
8179 is_double_a_single (bfd_int64_t v)
8181 int exp = (int)((v >> 52) & 0x7FF);
8182 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8184 return (exp == 0 || exp == 0x7FF
8185 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8186 && (mantissa & 0x1FFFFFFFl) == 0;
8189 /* Returns a double precision value casted to single precision
8190 (ignoring the least significant bits in exponent and mantissa). */
8192 static int
8193 double_to_single (bfd_int64_t v)
8195 int sign = (int) ((v >> 63) & 1l);
8196 int exp = (int) ((v >> 52) & 0x7FF);
8197 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8199 if (exp == 0x7FF)
8200 exp = 0xFF;
8201 else
8203 exp = exp - 1023 + 127;
8204 if (exp >= 0xFF)
8206 /* Infinity. */
8207 exp = 0x7F;
8208 mantissa = 0;
8210 else if (exp < 0)
8212 /* No denormalized numbers. */
8213 exp = 0;
8214 mantissa = 0;
8217 mantissa >>= 29;
8218 return (sign << 31) | (exp << 23) | mantissa;
8220 #endif /* BFD_HOST_64_BIT */
8222 enum lit_type
8224 CONST_THUMB,
8225 CONST_ARM,
8226 CONST_VEC
8229 static void do_vfp_nsyn_opcode (const char *);
8231 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8232 Determine whether it can be performed with a move instruction; if
8233 it can, convert inst.instruction to that move instruction and
8234 return TRUE; if it can't, convert inst.instruction to a literal-pool
8235 load and return FALSE. If this is not a valid thing to do in the
8236 current context, set inst.error and return TRUE.
8238 inst.operands[i] describes the destination register. */
8240 static bfd_boolean
8241 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
8243 unsigned long tbit;
8244 bfd_boolean thumb_p = (t == CONST_THUMB);
8245 bfd_boolean arm_p = (t == CONST_ARM);
8247 if (thumb_p)
8248 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8249 else
8250 tbit = LOAD_BIT;
8252 if ((inst.instruction & tbit) == 0)
8254 inst.error = _("invalid pseudo operation");
8255 return TRUE;
8258 if (inst.relocs[0].exp.X_op != O_constant
8259 && inst.relocs[0].exp.X_op != O_symbol
8260 && inst.relocs[0].exp.X_op != O_big)
8262 inst.error = _("constant expression expected");
8263 return TRUE;
8266 if (inst.relocs[0].exp.X_op == O_constant
8267 || inst.relocs[0].exp.X_op == O_big)
8269 #if defined BFD_HOST_64_BIT
8270 bfd_int64_t v;
8271 #else
8272 offsetT v;
8273 #endif
8274 if (inst.relocs[0].exp.X_op == O_big)
8276 LITTLENUM_TYPE w[X_PRECISION];
8277 LITTLENUM_TYPE * l;
8279 if (inst.relocs[0].exp.X_add_number == -1)
8281 gen_to_words (w, X_PRECISION, E_PRECISION);
8282 l = w;
8283 /* FIXME: Should we check words w[2..5] ? */
8285 else
8286 l = generic_bignum;
8288 #if defined BFD_HOST_64_BIT
8290 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8291 << LITTLENUM_NUMBER_OF_BITS)
8292 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8293 << LITTLENUM_NUMBER_OF_BITS)
8294 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8295 << LITTLENUM_NUMBER_OF_BITS)
8296 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8297 #else
8298 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8299 | (l[0] & LITTLENUM_MASK);
8300 #endif
8302 else
8303 v = inst.relocs[0].exp.X_add_number;
8305 if (!inst.operands[i].issingle)
8307 if (thumb_p)
8309 /* LDR should not use lead in a flag-setting instruction being
8310 chosen so we do not check whether movs can be used. */
8312 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8313 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8314 && inst.operands[i].reg != 13
8315 && inst.operands[i].reg != 15)
8317 /* Check if on thumb2 it can be done with a mov.w, mvn or
8318 movw instruction. */
8319 unsigned int newimm;
8320 bfd_boolean isNegated;
8322 newimm = encode_thumb32_immediate (v);
8323 if (newimm != (unsigned int) FAIL)
8324 isNegated = FALSE;
8325 else
8327 newimm = encode_thumb32_immediate (~v);
8328 if (newimm != (unsigned int) FAIL)
8329 isNegated = TRUE;
8332 /* The number can be loaded with a mov.w or mvn
8333 instruction. */
8334 if (newimm != (unsigned int) FAIL
8335 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8337 inst.instruction = (0xf04f0000 /* MOV.W. */
8338 | (inst.operands[i].reg << 8));
8339 /* Change to MOVN. */
8340 inst.instruction |= (isNegated ? 0x200000 : 0);
8341 inst.instruction |= (newimm & 0x800) << 15;
8342 inst.instruction |= (newimm & 0x700) << 4;
8343 inst.instruction |= (newimm & 0x0ff);
8344 return TRUE;
8346 /* The number can be loaded with a movw instruction. */
8347 else if ((v & ~0xFFFF) == 0
8348 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8350 int imm = v & 0xFFFF;
8352 inst.instruction = 0xf2400000; /* MOVW. */
8353 inst.instruction |= (inst.operands[i].reg << 8);
8354 inst.instruction |= (imm & 0xf000) << 4;
8355 inst.instruction |= (imm & 0x0800) << 15;
8356 inst.instruction |= (imm & 0x0700) << 4;
8357 inst.instruction |= (imm & 0x00ff);
8358 return TRUE;
8362 else if (arm_p)
8364 int value = encode_arm_immediate (v);
8366 if (value != FAIL)
8368 /* This can be done with a mov instruction. */
8369 inst.instruction &= LITERAL_MASK;
8370 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8371 inst.instruction |= value & 0xfff;
8372 return TRUE;
8375 value = encode_arm_immediate (~ v);
8376 if (value != FAIL)
8378 /* This can be done with a mvn instruction. */
8379 inst.instruction &= LITERAL_MASK;
8380 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8381 inst.instruction |= value & 0xfff;
8382 return TRUE;
8385 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8387 int op = 0;
8388 unsigned immbits = 0;
8389 unsigned immlo = inst.operands[1].imm;
8390 unsigned immhi = inst.operands[1].regisimm
8391 ? inst.operands[1].reg
8392 : inst.relocs[0].exp.X_unsigned
8394 : ((bfd_int64_t)((int) immlo)) >> 32;
8395 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8396 &op, 64, NT_invtype);
8398 if (cmode == FAIL)
8400 neon_invert_size (&immlo, &immhi, 64);
8401 op = !op;
8402 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8403 &op, 64, NT_invtype);
8406 if (cmode != FAIL)
8408 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8409 | (1 << 23)
8410 | (cmode << 8)
8411 | (op << 5)
8412 | (1 << 4);
8414 /* Fill other bits in vmov encoding for both thumb and arm. */
8415 if (thumb_mode)
8416 inst.instruction |= (0x7U << 29) | (0xF << 24);
8417 else
8418 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8419 neon_write_immbits (immbits);
8420 return TRUE;
8425 if (t == CONST_VEC)
8427 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8428 if (inst.operands[i].issingle
8429 && is_quarter_float (inst.operands[1].imm)
8430 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8432 inst.operands[1].imm =
8433 neon_qfloat_bits (v);
8434 do_vfp_nsyn_opcode ("fconsts");
8435 return TRUE;
8438 /* If our host does not support a 64-bit type then we cannot perform
8439 the following optimization. This mean that there will be a
8440 discrepancy between the output produced by an assembler built for
8441 a 32-bit-only host and the output produced from a 64-bit host, but
8442 this cannot be helped. */
8443 #if defined BFD_HOST_64_BIT
8444 else if (!inst.operands[1].issingle
8445 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8447 if (is_double_a_single (v)
8448 && is_quarter_float (double_to_single (v)))
8450 inst.operands[1].imm =
8451 neon_qfloat_bits (double_to_single (v));
8452 do_vfp_nsyn_opcode ("fconstd");
8453 return TRUE;
8456 #endif
8460 if (add_to_lit_pool ((!inst.operands[i].isvec
8461 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8462 return TRUE;
8464 inst.operands[1].reg = REG_PC;
8465 inst.operands[1].isreg = 1;
8466 inst.operands[1].preind = 1;
8467 inst.relocs[0].pc_rel = 1;
8468 inst.relocs[0].type = (thumb_p
8469 ? BFD_RELOC_ARM_THUMB_OFFSET
8470 : (mode_3
8471 ? BFD_RELOC_ARM_HWLITERAL
8472 : BFD_RELOC_ARM_LITERAL));
8473 return FALSE;
8476 /* inst.operands[i] was set up by parse_address. Encode it into an
8477 ARM-format instruction. Reject all forms which cannot be encoded
8478 into a coprocessor load/store instruction. If wb_ok is false,
8479 reject use of writeback; if unind_ok is false, reject use of
8480 unindexed addressing. If reloc_override is not 0, use it instead
8481 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8482 (in which case it is preserved). */
8484 static int
8485 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8487 if (!inst.operands[i].isreg)
8489 /* PR 18256 */
8490 if (! inst.operands[0].isvec)
8492 inst.error = _("invalid co-processor operand");
8493 return FAIL;
8495 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8496 return SUCCESS;
8499 inst.instruction |= inst.operands[i].reg << 16;
8501 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8503 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8505 gas_assert (!inst.operands[i].writeback);
8506 if (!unind_ok)
8508 inst.error = _("instruction does not support unindexed addressing");
8509 return FAIL;
8511 inst.instruction |= inst.operands[i].imm;
8512 inst.instruction |= INDEX_UP;
8513 return SUCCESS;
8516 if (inst.operands[i].preind)
8517 inst.instruction |= PRE_INDEX;
8519 if (inst.operands[i].writeback)
8521 if (inst.operands[i].reg == REG_PC)
8523 inst.error = _("pc may not be used with write-back");
8524 return FAIL;
8526 if (!wb_ok)
8528 inst.error = _("instruction does not support writeback");
8529 return FAIL;
8531 inst.instruction |= WRITE_BACK;
8534 if (reloc_override)
8535 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8536 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8537 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8538 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
8540 if (thumb_mode)
8541 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8542 else
8543 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
8546 /* Prefer + for zero encoded value. */
8547 if (!inst.operands[i].negative)
8548 inst.instruction |= INDEX_UP;
8550 return SUCCESS;
8553 /* Functions for instruction encoding, sorted by sub-architecture.
8554 First some generics; their names are taken from the conventional
8555 bit positions for register arguments in ARM format instructions. */
8557 static void
8558 do_noargs (void)
8562 static void
8563 do_rd (void)
8565 inst.instruction |= inst.operands[0].reg << 12;
8568 static void
8569 do_rn (void)
8571 inst.instruction |= inst.operands[0].reg << 16;
8574 static void
8575 do_rd_rm (void)
8577 inst.instruction |= inst.operands[0].reg << 12;
8578 inst.instruction |= inst.operands[1].reg;
8581 static void
8582 do_rm_rn (void)
8584 inst.instruction |= inst.operands[0].reg;
8585 inst.instruction |= inst.operands[1].reg << 16;
8588 static void
8589 do_rd_rn (void)
8591 inst.instruction |= inst.operands[0].reg << 12;
8592 inst.instruction |= inst.operands[1].reg << 16;
8595 static void
8596 do_rn_rd (void)
8598 inst.instruction |= inst.operands[0].reg << 16;
8599 inst.instruction |= inst.operands[1].reg << 12;
8602 static void
8603 do_tt (void)
8605 inst.instruction |= inst.operands[0].reg << 8;
8606 inst.instruction |= inst.operands[1].reg << 16;
8609 static bfd_boolean
8610 check_obsolete (const arm_feature_set *feature, const char *msg)
8612 if (ARM_CPU_IS_ANY (cpu_variant))
8614 as_tsktsk ("%s", msg);
8615 return TRUE;
8617 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8619 as_bad ("%s", msg);
8620 return TRUE;
8623 return FALSE;
8626 static void
8627 do_rd_rm_rn (void)
8629 unsigned Rn = inst.operands[2].reg;
8630 /* Enforce restrictions on SWP instruction. */
8631 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
8633 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8634 _("Rn must not overlap other operands"));
8636 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8638 if (!check_obsolete (&arm_ext_v8,
8639 _("swp{b} use is obsoleted for ARMv8 and later"))
8640 && warn_on_deprecated
8641 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
8642 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
8645 inst.instruction |= inst.operands[0].reg << 12;
8646 inst.instruction |= inst.operands[1].reg;
8647 inst.instruction |= Rn << 16;
8650 static void
8651 do_rd_rn_rm (void)
8653 inst.instruction |= inst.operands[0].reg << 12;
8654 inst.instruction |= inst.operands[1].reg << 16;
8655 inst.instruction |= inst.operands[2].reg;
8658 static void
8659 do_rm_rd_rn (void)
8661 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8662 constraint (((inst.relocs[0].exp.X_op != O_constant
8663 && inst.relocs[0].exp.X_op != O_illegal)
8664 || inst.relocs[0].exp.X_add_number != 0),
8665 BAD_ADDR_MODE);
8666 inst.instruction |= inst.operands[0].reg;
8667 inst.instruction |= inst.operands[1].reg << 12;
8668 inst.instruction |= inst.operands[2].reg << 16;
8671 static void
8672 do_imm0 (void)
8674 inst.instruction |= inst.operands[0].imm;
8677 static void
8678 do_rd_cpaddr (void)
8680 inst.instruction |= inst.operands[0].reg << 12;
8681 encode_arm_cp_address (1, TRUE, TRUE, 0);
8684 /* ARM instructions, in alphabetical order by function name (except
8685 that wrapper functions appear immediately after the function they
8686 wrap). */
8688 /* This is a pseudo-op of the form "adr rd, label" to be converted
8689 into a relative address of the form "add rd, pc, #label-.-8". */
8691 static void
8692 do_adr (void)
8694 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8696 /* Frag hacking will turn this into a sub instruction if the offset turns
8697 out to be negative. */
8698 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
8699 inst.relocs[0].pc_rel = 1;
8700 inst.relocs[0].exp.X_add_number -= 8;
8702 if (support_interwork
8703 && inst.relocs[0].exp.X_op == O_symbol
8704 && inst.relocs[0].exp.X_add_symbol != NULL
8705 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8706 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8707 inst.relocs[0].exp.X_add_number |= 1;
8710 /* This is a pseudo-op of the form "adrl rd, label" to be converted
8711 into a relative address of the form:
8712 add rd, pc, #low(label-.-8)"
8713 add rd, rd, #high(label-.-8)" */
8715 static void
8716 do_adrl (void)
8718 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8720 /* Frag hacking will turn this into a sub instruction if the offset turns
8721 out to be negative. */
8722 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8723 inst.relocs[0].pc_rel = 1;
8724 inst.size = INSN_SIZE * 2;
8725 inst.relocs[0].exp.X_add_number -= 8;
8727 if (support_interwork
8728 && inst.relocs[0].exp.X_op == O_symbol
8729 && inst.relocs[0].exp.X_add_symbol != NULL
8730 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8731 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8732 inst.relocs[0].exp.X_add_number |= 1;
8735 static void
8736 do_arit (void)
8738 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8739 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8740 THUMB1_RELOC_ONLY);
8741 if (!inst.operands[1].present)
8742 inst.operands[1].reg = inst.operands[0].reg;
8743 inst.instruction |= inst.operands[0].reg << 12;
8744 inst.instruction |= inst.operands[1].reg << 16;
8745 encode_arm_shifter_operand (2);
8748 static void
8749 do_barrier (void)
8751 if (inst.operands[0].present)
8752 inst.instruction |= inst.operands[0].imm;
8753 else
8754 inst.instruction |= 0xf;
8757 static void
8758 do_bfc (void)
8760 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8761 constraint (msb > 32, _("bit-field extends past end of register"));
8762 /* The instruction encoding stores the LSB and MSB,
8763 not the LSB and width. */
8764 inst.instruction |= inst.operands[0].reg << 12;
8765 inst.instruction |= inst.operands[1].imm << 7;
8766 inst.instruction |= (msb - 1) << 16;
8769 static void
8770 do_bfi (void)
8772 unsigned int msb;
8774 /* #0 in second position is alternative syntax for bfc, which is
8775 the same instruction but with REG_PC in the Rm field. */
8776 if (!inst.operands[1].isreg)
8777 inst.operands[1].reg = REG_PC;
8779 msb = inst.operands[2].imm + inst.operands[3].imm;
8780 constraint (msb > 32, _("bit-field extends past end of register"));
8781 /* The instruction encoding stores the LSB and MSB,
8782 not the LSB and width. */
8783 inst.instruction |= inst.operands[0].reg << 12;
8784 inst.instruction |= inst.operands[1].reg;
8785 inst.instruction |= inst.operands[2].imm << 7;
8786 inst.instruction |= (msb - 1) << 16;
8789 static void
8790 do_bfx (void)
8792 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8793 _("bit-field extends past end of register"));
8794 inst.instruction |= inst.operands[0].reg << 12;
8795 inst.instruction |= inst.operands[1].reg;
8796 inst.instruction |= inst.operands[2].imm << 7;
8797 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8800 /* ARM V5 breakpoint instruction (argument parse)
8801 BKPT <16 bit unsigned immediate>
8802 Instruction is not conditional.
8803 The bit pattern given in insns[] has the COND_ALWAYS condition,
8804 and it is an error if the caller tried to override that. */
8806 static void
8807 do_bkpt (void)
8809 /* Top 12 of 16 bits to bits 19:8. */
8810 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
8812 /* Bottom 4 of 16 bits to bits 3:0. */
8813 inst.instruction |= inst.operands[0].imm & 0xf;
8816 static void
8817 encode_branch (int default_reloc)
8819 if (inst.operands[0].hasreloc)
8821 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8822 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8823 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8824 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8825 ? BFD_RELOC_ARM_PLT32
8826 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
8828 else
8829 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
8830 inst.relocs[0].pc_rel = 1;
8833 static void
8834 do_branch (void)
8836 #ifdef OBJ_ELF
8837 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8838 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8839 else
8840 #endif
8841 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8844 static void
8845 do_bl (void)
8847 #ifdef OBJ_ELF
8848 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8850 if (inst.cond == COND_ALWAYS)
8851 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8852 else
8853 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8855 else
8856 #endif
8857 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8860 /* ARM V5 branch-link-exchange instruction (argument parse)
8861 BLX <target_addr> ie BLX(1)
8862 BLX{<condition>} <Rm> ie BLX(2)
8863 Unfortunately, there are two different opcodes for this mnemonic.
8864 So, the insns[].value is not used, and the code here zaps values
8865 into inst.instruction.
8866 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
8868 static void
8869 do_blx (void)
8871 if (inst.operands[0].isreg)
8873 /* Arg is a register; the opcode provided by insns[] is correct.
8874 It is not illegal to do "blx pc", just useless. */
8875 if (inst.operands[0].reg == REG_PC)
8876 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
8878 inst.instruction |= inst.operands[0].reg;
8880 else
8882 /* Arg is an address; this instruction cannot be executed
8883 conditionally, and the opcode must be adjusted.
8884 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8885 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
8886 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8887 inst.instruction = 0xfa000000;
8888 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
8892 static void
8893 do_bx (void)
8895 bfd_boolean want_reloc;
8897 if (inst.operands[0].reg == REG_PC)
8898 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
8900 inst.instruction |= inst.operands[0].reg;
8901 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8902 it is for ARMv4t or earlier. */
8903 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8904 if (!ARM_FEATURE_ZERO (selected_object_arch)
8905 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
8906 want_reloc = TRUE;
8908 #ifdef OBJ_ELF
8909 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
8910 #endif
8911 want_reloc = FALSE;
8913 if (want_reloc)
8914 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
8918 /* ARM v5TEJ. Jump to Jazelle code. */
8920 static void
8921 do_bxj (void)
8923 if (inst.operands[0].reg == REG_PC)
8924 as_tsktsk (_("use of r15 in bxj is not really useful"));
8926 inst.instruction |= inst.operands[0].reg;
8929 /* Co-processor data operation:
8930 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8931 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8932 static void
8933 do_cdp (void)
8935 inst.instruction |= inst.operands[0].reg << 8;
8936 inst.instruction |= inst.operands[1].imm << 20;
8937 inst.instruction |= inst.operands[2].reg << 12;
8938 inst.instruction |= inst.operands[3].reg << 16;
8939 inst.instruction |= inst.operands[4].reg;
8940 inst.instruction |= inst.operands[5].imm << 5;
8943 static void
8944 do_cmp (void)
8946 inst.instruction |= inst.operands[0].reg << 16;
8947 encode_arm_shifter_operand (1);
8950 /* Transfer between coprocessor and ARM registers.
8951 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8952 MRC2
8953 MCR{cond}
8954 MCR2
8956 No special properties. */
8958 struct deprecated_coproc_regs_s
8960 unsigned cp;
8961 int opc1;
8962 unsigned crn;
8963 unsigned crm;
8964 int opc2;
8965 arm_feature_set deprecated;
8966 arm_feature_set obsoleted;
8967 const char *dep_msg;
8968 const char *obs_msg;
8971 #define DEPR_ACCESS_V8 \
8972 N_("This coprocessor register access is deprecated in ARMv8")
8974 /* Table of all deprecated coprocessor registers. */
8975 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8977 {15, 0, 7, 10, 5, /* CP15DMB. */
8978 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8979 DEPR_ACCESS_V8, NULL},
8980 {15, 0, 7, 10, 4, /* CP15DSB. */
8981 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8982 DEPR_ACCESS_V8, NULL},
8983 {15, 0, 7, 5, 4, /* CP15ISB. */
8984 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8985 DEPR_ACCESS_V8, NULL},
8986 {14, 6, 1, 0, 0, /* TEEHBR. */
8987 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8988 DEPR_ACCESS_V8, NULL},
8989 {14, 6, 0, 0, 0, /* TEECR. */
8990 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8991 DEPR_ACCESS_V8, NULL},
8994 #undef DEPR_ACCESS_V8
8996 static const size_t deprecated_coproc_reg_count =
8997 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8999 static void
9000 do_co_reg (void)
9002 unsigned Rd;
9003 size_t i;
9005 Rd = inst.operands[2].reg;
9006 if (thumb_mode)
9008 if (inst.instruction == 0xee000010
9009 || inst.instruction == 0xfe000010)
9010 /* MCR, MCR2 */
9011 reject_bad_reg (Rd);
9012 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9013 /* MRC, MRC2 */
9014 constraint (Rd == REG_SP, BAD_SP);
9016 else
9018 /* MCR */
9019 if (inst.instruction == 0xe000010)
9020 constraint (Rd == REG_PC, BAD_PC);
9023 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9025 const struct deprecated_coproc_regs_s *r =
9026 deprecated_coproc_regs + i;
9028 if (inst.operands[0].reg == r->cp
9029 && inst.operands[1].imm == r->opc1
9030 && inst.operands[3].reg == r->crn
9031 && inst.operands[4].reg == r->crm
9032 && inst.operands[5].imm == r->opc2)
9034 if (! ARM_CPU_IS_ANY (cpu_variant)
9035 && warn_on_deprecated
9036 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9037 as_tsktsk ("%s", r->dep_msg);
9041 inst.instruction |= inst.operands[0].reg << 8;
9042 inst.instruction |= inst.operands[1].imm << 21;
9043 inst.instruction |= Rd << 12;
9044 inst.instruction |= inst.operands[3].reg << 16;
9045 inst.instruction |= inst.operands[4].reg;
9046 inst.instruction |= inst.operands[5].imm << 5;
9049 /* Transfer between coprocessor register and pair of ARM registers.
9050 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9051 MCRR2
9052 MRRC{cond}
9053 MRRC2
9055 Two XScale instructions are special cases of these:
9057 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9058 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9060 Result unpredictable if Rd or Rn is R15. */
9062 static void
9063 do_co_reg2c (void)
9065 unsigned Rd, Rn;
9067 Rd = inst.operands[2].reg;
9068 Rn = inst.operands[3].reg;
9070 if (thumb_mode)
9072 reject_bad_reg (Rd);
9073 reject_bad_reg (Rn);
9075 else
9077 constraint (Rd == REG_PC, BAD_PC);
9078 constraint (Rn == REG_PC, BAD_PC);
9081 /* Only check the MRRC{2} variants. */
9082 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9084 /* If Rd == Rn, error that the operation is
9085 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9086 constraint (Rd == Rn, BAD_OVERLAP);
9089 inst.instruction |= inst.operands[0].reg << 8;
9090 inst.instruction |= inst.operands[1].imm << 4;
9091 inst.instruction |= Rd << 12;
9092 inst.instruction |= Rn << 16;
9093 inst.instruction |= inst.operands[4].reg;
9096 static void
9097 do_cpsi (void)
9099 inst.instruction |= inst.operands[0].imm << 6;
9100 if (inst.operands[1].present)
9102 inst.instruction |= CPSI_MMOD;
9103 inst.instruction |= inst.operands[1].imm;
9107 static void
9108 do_dbg (void)
9110 inst.instruction |= inst.operands[0].imm;
9113 static void
9114 do_div (void)
9116 unsigned Rd, Rn, Rm;
9118 Rd = inst.operands[0].reg;
9119 Rn = (inst.operands[1].present
9120 ? inst.operands[1].reg : Rd);
9121 Rm = inst.operands[2].reg;
9123 constraint ((Rd == REG_PC), BAD_PC);
9124 constraint ((Rn == REG_PC), BAD_PC);
9125 constraint ((Rm == REG_PC), BAD_PC);
9127 inst.instruction |= Rd << 16;
9128 inst.instruction |= Rn << 0;
9129 inst.instruction |= Rm << 8;
9132 static void
9133 do_it (void)
9135 /* There is no IT instruction in ARM mode. We
9136 process it to do the validation as if in
9137 thumb mode, just in case the code gets
9138 assembled for thumb using the unified syntax. */
9140 inst.size = 0;
9141 if (unified_syntax)
9143 set_pred_insn_type (IT_INSN);
9144 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9145 now_pred.cc = inst.operands[0].imm;
9149 /* If there is only one register in the register list,
9150 then return its register number. Otherwise return -1. */
9151 static int
9152 only_one_reg_in_list (int range)
9154 int i = ffs (range) - 1;
9155 return (i > 15 || range != (1 << i)) ? -1 : i;
9158 static void
9159 encode_ldmstm(int from_push_pop_mnem)
9161 int base_reg = inst.operands[0].reg;
9162 int range = inst.operands[1].imm;
9163 int one_reg;
9165 inst.instruction |= base_reg << 16;
9166 inst.instruction |= range;
9168 if (inst.operands[1].writeback)
9169 inst.instruction |= LDM_TYPE_2_OR_3;
9171 if (inst.operands[0].writeback)
9173 inst.instruction |= WRITE_BACK;
9174 /* Check for unpredictable uses of writeback. */
9175 if (inst.instruction & LOAD_BIT)
9177 /* Not allowed in LDM type 2. */
9178 if ((inst.instruction & LDM_TYPE_2_OR_3)
9179 && ((range & (1 << REG_PC)) == 0))
9180 as_warn (_("writeback of base register is UNPREDICTABLE"));
9181 /* Only allowed if base reg not in list for other types. */
9182 else if (range & (1 << base_reg))
9183 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9185 else /* STM. */
9187 /* Not allowed for type 2. */
9188 if (inst.instruction & LDM_TYPE_2_OR_3)
9189 as_warn (_("writeback of base register is UNPREDICTABLE"));
9190 /* Only allowed if base reg not in list, or first in list. */
9191 else if ((range & (1 << base_reg))
9192 && (range & ((1 << base_reg) - 1)))
9193 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9197 /* If PUSH/POP has only one register, then use the A2 encoding. */
9198 one_reg = only_one_reg_in_list (range);
9199 if (from_push_pop_mnem && one_reg >= 0)
9201 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9203 if (is_push && one_reg == 13 /* SP */)
9204 /* PR 22483: The A2 encoding cannot be used when
9205 pushing the stack pointer as this is UNPREDICTABLE. */
9206 return;
9208 inst.instruction &= A_COND_MASK;
9209 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9210 inst.instruction |= one_reg << 12;
9214 static void
9215 do_ldmstm (void)
9217 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
9220 /* ARMv5TE load-consecutive (argument parse)
9221 Mode is like LDRH.
9223 LDRccD R, mode
9224 STRccD R, mode. */
9226 static void
9227 do_ldrd (void)
9229 constraint (inst.operands[0].reg % 2 != 0,
9230 _("first transfer register must be even"));
9231 constraint (inst.operands[1].present
9232 && inst.operands[1].reg != inst.operands[0].reg + 1,
9233 _("can only transfer two consecutive registers"));
9234 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9235 constraint (!inst.operands[2].isreg, _("'[' expected"));
9237 if (!inst.operands[1].present)
9238 inst.operands[1].reg = inst.operands[0].reg + 1;
9240 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9241 register and the first register written; we have to diagnose
9242 overlap between the base and the second register written here. */
9244 if (inst.operands[2].reg == inst.operands[1].reg
9245 && (inst.operands[2].writeback || inst.operands[2].postind))
9246 as_warn (_("base register written back, and overlaps "
9247 "second transfer register"));
9249 if (!(inst.instruction & V4_STR_BIT))
9251 /* For an index-register load, the index register must not overlap the
9252 destination (even if not write-back). */
9253 if (inst.operands[2].immisreg
9254 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9255 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9256 as_warn (_("index register overlaps transfer register"));
9258 inst.instruction |= inst.operands[0].reg << 12;
9259 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
9262 static void
9263 do_ldrex (void)
9265 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9266 || inst.operands[1].postind || inst.operands[1].writeback
9267 || inst.operands[1].immisreg || inst.operands[1].shifted
9268 || inst.operands[1].negative
9269 /* This can arise if the programmer has written
9270 strex rN, rM, foo
9271 or if they have mistakenly used a register name as the last
9272 operand, eg:
9273 strex rN, rM, rX
9274 It is very difficult to distinguish between these two cases
9275 because "rX" might actually be a label. ie the register
9276 name has been occluded by a symbol of the same name. So we
9277 just generate a general 'bad addressing mode' type error
9278 message and leave it up to the programmer to discover the
9279 true cause and fix their mistake. */
9280 || (inst.operands[1].reg == REG_PC),
9281 BAD_ADDR_MODE);
9283 constraint (inst.relocs[0].exp.X_op != O_constant
9284 || inst.relocs[0].exp.X_add_number != 0,
9285 _("offset must be zero in ARM encoding"));
9287 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9289 inst.instruction |= inst.operands[0].reg << 12;
9290 inst.instruction |= inst.operands[1].reg << 16;
9291 inst.relocs[0].type = BFD_RELOC_UNUSED;
9294 static void
9295 do_ldrexd (void)
9297 constraint (inst.operands[0].reg % 2 != 0,
9298 _("even register required"));
9299 constraint (inst.operands[1].present
9300 && inst.operands[1].reg != inst.operands[0].reg + 1,
9301 _("can only load two consecutive registers"));
9302 /* If op 1 were present and equal to PC, this function wouldn't
9303 have been called in the first place. */
9304 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9306 inst.instruction |= inst.operands[0].reg << 12;
9307 inst.instruction |= inst.operands[2].reg << 16;
9310 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9311 which is not a multiple of four is UNPREDICTABLE. */
9312 static void
9313 check_ldr_r15_aligned (void)
9315 constraint (!(inst.operands[1].immisreg)
9316 && (inst.operands[0].reg == REG_PC
9317 && inst.operands[1].reg == REG_PC
9318 && (inst.relocs[0].exp.X_add_number & 0x3)),
9319 _("ldr to register 15 must be 4-byte aligned"));
9322 static void
9323 do_ldst (void)
9325 inst.instruction |= inst.operands[0].reg << 12;
9326 if (!inst.operands[1].isreg)
9327 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9328 return;
9329 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9330 check_ldr_r15_aligned ();
9333 static void
9334 do_ldstt (void)
9336 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9337 reject [Rn,...]. */
9338 if (inst.operands[1].preind)
9340 constraint (inst.relocs[0].exp.X_op != O_constant
9341 || inst.relocs[0].exp.X_add_number != 0,
9342 _("this instruction requires a post-indexed address"));
9344 inst.operands[1].preind = 0;
9345 inst.operands[1].postind = 1;
9346 inst.operands[1].writeback = 1;
9348 inst.instruction |= inst.operands[0].reg << 12;
9349 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9352 /* Halfword and signed-byte load/store operations. */
9354 static void
9355 do_ldstv4 (void)
9357 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9358 inst.instruction |= inst.operands[0].reg << 12;
9359 if (!inst.operands[1].isreg)
9360 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9361 return;
9362 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9365 static void
9366 do_ldsttv4 (void)
9368 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9369 reject [Rn,...]. */
9370 if (inst.operands[1].preind)
9372 constraint (inst.relocs[0].exp.X_op != O_constant
9373 || inst.relocs[0].exp.X_add_number != 0,
9374 _("this instruction requires a post-indexed address"));
9376 inst.operands[1].preind = 0;
9377 inst.operands[1].postind = 1;
9378 inst.operands[1].writeback = 1;
9380 inst.instruction |= inst.operands[0].reg << 12;
9381 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9384 /* Co-processor register load/store.
9385 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9386 static void
9387 do_lstc (void)
9389 inst.instruction |= inst.operands[0].reg << 8;
9390 inst.instruction |= inst.operands[1].reg << 12;
9391 encode_arm_cp_address (2, TRUE, TRUE, 0);
9394 static void
9395 do_mlas (void)
9397 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9398 if (inst.operands[0].reg == inst.operands[1].reg
9399 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9400 && !(inst.instruction & 0x00400000))
9401 as_tsktsk (_("Rd and Rm should be different in mla"));
9403 inst.instruction |= inst.operands[0].reg << 16;
9404 inst.instruction |= inst.operands[1].reg;
9405 inst.instruction |= inst.operands[2].reg << 8;
9406 inst.instruction |= inst.operands[3].reg << 12;
9409 static void
9410 do_mov (void)
9412 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9413 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9414 THUMB1_RELOC_ONLY);
9415 inst.instruction |= inst.operands[0].reg << 12;
9416 encode_arm_shifter_operand (1);
9419 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9420 static void
9421 do_mov16 (void)
9423 bfd_vma imm;
9424 bfd_boolean top;
9426 top = (inst.instruction & 0x00400000) != 0;
9427 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
9428 _(":lower16: not allowed in this instruction"));
9429 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
9430 _(":upper16: not allowed in this instruction"));
9431 inst.instruction |= inst.operands[0].reg << 12;
9432 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
9434 imm = inst.relocs[0].exp.X_add_number;
9435 /* The value is in two pieces: 0:11, 16:19. */
9436 inst.instruction |= (imm & 0x00000fff);
9437 inst.instruction |= (imm & 0x0000f000) << 4;
9441 static int
9442 do_vfp_nsyn_mrs (void)
9444 if (inst.operands[0].isvec)
9446 if (inst.operands[1].reg != 1)
9447 first_error (_("operand 1 must be FPSCR"));
9448 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9449 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9450 do_vfp_nsyn_opcode ("fmstat");
9452 else if (inst.operands[1].isvec)
9453 do_vfp_nsyn_opcode ("fmrx");
9454 else
9455 return FAIL;
9457 return SUCCESS;
9460 static int
9461 do_vfp_nsyn_msr (void)
9463 if (inst.operands[0].isvec)
9464 do_vfp_nsyn_opcode ("fmxr");
9465 else
9466 return FAIL;
9468 return SUCCESS;
9471 static void
9472 do_vmrs (void)
9474 unsigned Rt = inst.operands[0].reg;
9476 if (thumb_mode && Rt == REG_SP)
9478 inst.error = BAD_SP;
9479 return;
9482 /* MVFR2 is only valid at ARMv8-A. */
9483 if (inst.operands[1].reg == 5)
9484 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9485 _(BAD_FPU));
9487 /* APSR_ sets isvec. All other refs to PC are illegal. */
9488 if (!inst.operands[0].isvec && Rt == REG_PC)
9490 inst.error = BAD_PC;
9491 return;
9494 /* If we get through parsing the register name, we just insert the number
9495 generated into the instruction without further validation. */
9496 inst.instruction |= (inst.operands[1].reg << 16);
9497 inst.instruction |= (Rt << 12);
9500 static void
9501 do_vmsr (void)
9503 unsigned Rt = inst.operands[1].reg;
9505 if (thumb_mode)
9506 reject_bad_reg (Rt);
9507 else if (Rt == REG_PC)
9509 inst.error = BAD_PC;
9510 return;
9513 /* MVFR2 is only valid for ARMv8-A. */
9514 if (inst.operands[0].reg == 5)
9515 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9516 _(BAD_FPU));
9518 /* If we get through parsing the register name, we just insert the number
9519 generated into the instruction without further validation. */
9520 inst.instruction |= (inst.operands[0].reg << 16);
9521 inst.instruction |= (Rt << 12);
9524 static void
9525 do_mrs (void)
9527 unsigned br;
9529 if (do_vfp_nsyn_mrs () == SUCCESS)
9530 return;
9532 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9533 inst.instruction |= inst.operands[0].reg << 12;
9535 if (inst.operands[1].isreg)
9537 br = inst.operands[1].reg;
9538 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
9539 as_bad (_("bad register for mrs"));
9541 else
9543 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9544 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9545 != (PSR_c|PSR_f),
9546 _("'APSR', 'CPSR' or 'SPSR' expected"));
9547 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9550 inst.instruction |= br;
9553 /* Two possible forms:
9554 "{C|S}PSR_<field>, Rm",
9555 "{C|S}PSR_f, #expression". */
9557 static void
9558 do_msr (void)
9560 if (do_vfp_nsyn_msr () == SUCCESS)
9561 return;
9563 inst.instruction |= inst.operands[0].imm;
9564 if (inst.operands[1].isreg)
9565 inst.instruction |= inst.operands[1].reg;
9566 else
9568 inst.instruction |= INST_IMMEDIATE;
9569 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9570 inst.relocs[0].pc_rel = 0;
9574 static void
9575 do_mul (void)
9577 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9579 if (!inst.operands[2].present)
9580 inst.operands[2].reg = inst.operands[0].reg;
9581 inst.instruction |= inst.operands[0].reg << 16;
9582 inst.instruction |= inst.operands[1].reg;
9583 inst.instruction |= inst.operands[2].reg << 8;
9585 if (inst.operands[0].reg == inst.operands[1].reg
9586 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9587 as_tsktsk (_("Rd and Rm should be different in mul"));
9590 /* Long Multiply Parser
9591 UMULL RdLo, RdHi, Rm, Rs
9592 SMULL RdLo, RdHi, Rm, Rs
9593 UMLAL RdLo, RdHi, Rm, Rs
9594 SMLAL RdLo, RdHi, Rm, Rs. */
9596 static void
9597 do_mull (void)
9599 inst.instruction |= inst.operands[0].reg << 12;
9600 inst.instruction |= inst.operands[1].reg << 16;
9601 inst.instruction |= inst.operands[2].reg;
9602 inst.instruction |= inst.operands[3].reg << 8;
9604 /* rdhi and rdlo must be different. */
9605 if (inst.operands[0].reg == inst.operands[1].reg)
9606 as_tsktsk (_("rdhi and rdlo must be different"));
9608 /* rdhi, rdlo and rm must all be different before armv6. */
9609 if ((inst.operands[0].reg == inst.operands[2].reg
9610 || inst.operands[1].reg == inst.operands[2].reg)
9611 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9612 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9615 static void
9616 do_nop (void)
9618 if (inst.operands[0].present
9619 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
9621 /* Architectural NOP hints are CPSR sets with no bits selected. */
9622 inst.instruction &= 0xf0000000;
9623 inst.instruction |= 0x0320f000;
9624 if (inst.operands[0].present)
9625 inst.instruction |= inst.operands[0].imm;
9629 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9630 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9631 Condition defaults to COND_ALWAYS.
9632 Error if Rd, Rn or Rm are R15. */
9634 static void
9635 do_pkhbt (void)
9637 inst.instruction |= inst.operands[0].reg << 12;
9638 inst.instruction |= inst.operands[1].reg << 16;
9639 inst.instruction |= inst.operands[2].reg;
9640 if (inst.operands[3].present)
9641 encode_arm_shift (3);
9644 /* ARM V6 PKHTB (Argument Parse). */
9646 static void
9647 do_pkhtb (void)
9649 if (!inst.operands[3].present)
9651 /* If the shift specifier is omitted, turn the instruction
9652 into pkhbt rd, rm, rn. */
9653 inst.instruction &= 0xfff00010;
9654 inst.instruction |= inst.operands[0].reg << 12;
9655 inst.instruction |= inst.operands[1].reg;
9656 inst.instruction |= inst.operands[2].reg << 16;
9658 else
9660 inst.instruction |= inst.operands[0].reg << 12;
9661 inst.instruction |= inst.operands[1].reg << 16;
9662 inst.instruction |= inst.operands[2].reg;
9663 encode_arm_shift (3);
9667 /* ARMv5TE: Preload-Cache
9668 MP Extensions: Preload for write
9670 PLD(W) <addr_mode>
9672 Syntactically, like LDR with B=1, W=0, L=1. */
9674 static void
9675 do_pld (void)
9677 constraint (!inst.operands[0].isreg,
9678 _("'[' expected after PLD mnemonic"));
9679 constraint (inst.operands[0].postind,
9680 _("post-indexed expression used in preload instruction"));
9681 constraint (inst.operands[0].writeback,
9682 _("writeback used in preload instruction"));
9683 constraint (!inst.operands[0].preind,
9684 _("unindexed addressing used in preload instruction"));
9685 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9688 /* ARMv7: PLI <addr_mode> */
9689 static void
9690 do_pli (void)
9692 constraint (!inst.operands[0].isreg,
9693 _("'[' expected after PLI mnemonic"));
9694 constraint (inst.operands[0].postind,
9695 _("post-indexed expression used in preload instruction"));
9696 constraint (inst.operands[0].writeback,
9697 _("writeback used in preload instruction"));
9698 constraint (!inst.operands[0].preind,
9699 _("unindexed addressing used in preload instruction"));
9700 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9701 inst.instruction &= ~PRE_INDEX;
9704 static void
9705 do_push_pop (void)
9707 constraint (inst.operands[0].writeback,
9708 _("push/pop do not support {reglist}^"));
9709 inst.operands[1] = inst.operands[0];
9710 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9711 inst.operands[0].isreg = 1;
9712 inst.operands[0].writeback = 1;
9713 inst.operands[0].reg = REG_SP;
9714 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
9717 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9718 word at the specified address and the following word
9719 respectively.
9720 Unconditionally executed.
9721 Error if Rn is R15. */
9723 static void
9724 do_rfe (void)
9726 inst.instruction |= inst.operands[0].reg << 16;
9727 if (inst.operands[0].writeback)
9728 inst.instruction |= WRITE_BACK;
9731 /* ARM V6 ssat (argument parse). */
9733 static void
9734 do_ssat (void)
9736 inst.instruction |= inst.operands[0].reg << 12;
9737 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9738 inst.instruction |= inst.operands[2].reg;
9740 if (inst.operands[3].present)
9741 encode_arm_shift (3);
9744 /* ARM V6 usat (argument parse). */
9746 static void
9747 do_usat (void)
9749 inst.instruction |= inst.operands[0].reg << 12;
9750 inst.instruction |= inst.operands[1].imm << 16;
9751 inst.instruction |= inst.operands[2].reg;
9753 if (inst.operands[3].present)
9754 encode_arm_shift (3);
9757 /* ARM V6 ssat16 (argument parse). */
9759 static void
9760 do_ssat16 (void)
9762 inst.instruction |= inst.operands[0].reg << 12;
9763 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9764 inst.instruction |= inst.operands[2].reg;
9767 static void
9768 do_usat16 (void)
9770 inst.instruction |= inst.operands[0].reg << 12;
9771 inst.instruction |= inst.operands[1].imm << 16;
9772 inst.instruction |= inst.operands[2].reg;
9775 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9776 preserving the other bits.
9778 setend <endian_specifier>, where <endian_specifier> is either
9779 BE or LE. */
9781 static void
9782 do_setend (void)
9784 if (warn_on_deprecated
9785 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9786 as_tsktsk (_("setend use is deprecated for ARMv8"));
9788 if (inst.operands[0].imm)
9789 inst.instruction |= 0x200;
9792 static void
9793 do_shift (void)
9795 unsigned int Rm = (inst.operands[1].present
9796 ? inst.operands[1].reg
9797 : inst.operands[0].reg);
9799 inst.instruction |= inst.operands[0].reg << 12;
9800 inst.instruction |= Rm;
9801 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
9803 inst.instruction |= inst.operands[2].reg << 8;
9804 inst.instruction |= SHIFT_BY_REG;
9805 /* PR 12854: Error on extraneous shifts. */
9806 constraint (inst.operands[2].shifted,
9807 _("extraneous shift as part of operand to shift insn"));
9809 else
9810 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
9813 static void
9814 do_smc (void)
9816 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
9817 inst.relocs[0].pc_rel = 0;
9820 static void
9821 do_hvc (void)
9823 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
9824 inst.relocs[0].pc_rel = 0;
9827 static void
9828 do_swi (void)
9830 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
9831 inst.relocs[0].pc_rel = 0;
9834 static void
9835 do_setpan (void)
9837 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9838 _("selected processor does not support SETPAN instruction"));
9840 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9843 static void
9844 do_t_setpan (void)
9846 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9847 _("selected processor does not support SETPAN instruction"));
9849 inst.instruction |= (inst.operands[0].imm << 3);
9852 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9853 SMLAxy{cond} Rd,Rm,Rs,Rn
9854 SMLAWy{cond} Rd,Rm,Rs,Rn
9855 Error if any register is R15. */
9857 static void
9858 do_smla (void)
9860 inst.instruction |= inst.operands[0].reg << 16;
9861 inst.instruction |= inst.operands[1].reg;
9862 inst.instruction |= inst.operands[2].reg << 8;
9863 inst.instruction |= inst.operands[3].reg << 12;
9866 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9867 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9868 Error if any register is R15.
9869 Warning if Rdlo == Rdhi. */
9871 static void
9872 do_smlal (void)
9874 inst.instruction |= inst.operands[0].reg << 12;
9875 inst.instruction |= inst.operands[1].reg << 16;
9876 inst.instruction |= inst.operands[2].reg;
9877 inst.instruction |= inst.operands[3].reg << 8;
9879 if (inst.operands[0].reg == inst.operands[1].reg)
9880 as_tsktsk (_("rdhi and rdlo must be different"));
9883 /* ARM V5E (El Segundo) signed-multiply (argument parse)
9884 SMULxy{cond} Rd,Rm,Rs
9885 Error if any register is R15. */
9887 static void
9888 do_smul (void)
9890 inst.instruction |= inst.operands[0].reg << 16;
9891 inst.instruction |= inst.operands[1].reg;
9892 inst.instruction |= inst.operands[2].reg << 8;
9895 /* ARM V6 srs (argument parse). The variable fields in the encoding are
9896 the same for both ARM and Thumb-2. */
9898 static void
9899 do_srs (void)
9901 int reg;
9903 if (inst.operands[0].present)
9905 reg = inst.operands[0].reg;
9906 constraint (reg != REG_SP, _("SRS base register must be r13"));
9908 else
9909 reg = REG_SP;
9911 inst.instruction |= reg << 16;
9912 inst.instruction |= inst.operands[1].imm;
9913 if (inst.operands[0].writeback || inst.operands[1].writeback)
9914 inst.instruction |= WRITE_BACK;
9917 /* ARM V6 strex (argument parse). */
9919 static void
9920 do_strex (void)
9922 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9923 || inst.operands[2].postind || inst.operands[2].writeback
9924 || inst.operands[2].immisreg || inst.operands[2].shifted
9925 || inst.operands[2].negative
9926 /* See comment in do_ldrex(). */
9927 || (inst.operands[2].reg == REG_PC),
9928 BAD_ADDR_MODE);
9930 constraint (inst.operands[0].reg == inst.operands[1].reg
9931 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9933 constraint (inst.relocs[0].exp.X_op != O_constant
9934 || inst.relocs[0].exp.X_add_number != 0,
9935 _("offset must be zero in ARM encoding"));
9937 inst.instruction |= inst.operands[0].reg << 12;
9938 inst.instruction |= inst.operands[1].reg;
9939 inst.instruction |= inst.operands[2].reg << 16;
9940 inst.relocs[0].type = BFD_RELOC_UNUSED;
9943 static void
9944 do_t_strexbh (void)
9946 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9947 || inst.operands[2].postind || inst.operands[2].writeback
9948 || inst.operands[2].immisreg || inst.operands[2].shifted
9949 || inst.operands[2].negative,
9950 BAD_ADDR_MODE);
9952 constraint (inst.operands[0].reg == inst.operands[1].reg
9953 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9955 do_rm_rd_rn ();
9958 static void
9959 do_strexd (void)
9961 constraint (inst.operands[1].reg % 2 != 0,
9962 _("even register required"));
9963 constraint (inst.operands[2].present
9964 && inst.operands[2].reg != inst.operands[1].reg + 1,
9965 _("can only store two consecutive registers"));
9966 /* If op 2 were present and equal to PC, this function wouldn't
9967 have been called in the first place. */
9968 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
9970 constraint (inst.operands[0].reg == inst.operands[1].reg
9971 || inst.operands[0].reg == inst.operands[1].reg + 1
9972 || inst.operands[0].reg == inst.operands[3].reg,
9973 BAD_OVERLAP);
9975 inst.instruction |= inst.operands[0].reg << 12;
9976 inst.instruction |= inst.operands[1].reg;
9977 inst.instruction |= inst.operands[3].reg << 16;
9980 /* ARM V8 STRL. */
9981 static void
9982 do_stlex (void)
9984 constraint (inst.operands[0].reg == inst.operands[1].reg
9985 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9987 do_rd_rm_rn ();
9990 static void
9991 do_t_stlex (void)
9993 constraint (inst.operands[0].reg == inst.operands[1].reg
9994 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9996 do_rm_rd_rn ();
9999 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10000 extends it to 32-bits, and adds the result to a value in another
10001 register. You can specify a rotation by 0, 8, 16, or 24 bits
10002 before extracting the 16-bit value.
10003 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10004 Condition defaults to COND_ALWAYS.
10005 Error if any register uses R15. */
10007 static void
10008 do_sxtah (void)
10010 inst.instruction |= inst.operands[0].reg << 12;
10011 inst.instruction |= inst.operands[1].reg << 16;
10012 inst.instruction |= inst.operands[2].reg;
10013 inst.instruction |= inst.operands[3].imm << 10;
10016 /* ARM V6 SXTH.
10018 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10019 Condition defaults to COND_ALWAYS.
10020 Error if any register uses R15. */
10022 static void
10023 do_sxth (void)
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 inst.instruction |= inst.operands[1].reg;
10027 inst.instruction |= inst.operands[2].imm << 10;
10030 /* VFP instructions. In a logical order: SP variant first, monad
10031 before dyad, arithmetic then move then load/store. */
10033 static void
10034 do_vfp_sp_monadic (void)
10036 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10037 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10040 static void
10041 do_vfp_sp_dyadic (void)
10043 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10044 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10045 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10048 static void
10049 do_vfp_sp_compare_z (void)
10051 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10054 static void
10055 do_vfp_dp_sp_cvt (void)
10057 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10058 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10061 static void
10062 do_vfp_sp_dp_cvt (void)
10064 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10065 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10068 static void
10069 do_vfp_reg_from_sp (void)
10071 inst.instruction |= inst.operands[0].reg << 12;
10072 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10075 static void
10076 do_vfp_reg2_from_sp2 (void)
10078 constraint (inst.operands[2].imm != 2,
10079 _("only two consecutive VFP SP registers allowed here"));
10080 inst.instruction |= inst.operands[0].reg << 12;
10081 inst.instruction |= inst.operands[1].reg << 16;
10082 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10085 static void
10086 do_vfp_sp_from_reg (void)
10088 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10089 inst.instruction |= inst.operands[1].reg << 12;
10092 static void
10093 do_vfp_sp2_from_reg2 (void)
10095 constraint (inst.operands[0].imm != 2,
10096 _("only two consecutive VFP SP registers allowed here"));
10097 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10098 inst.instruction |= inst.operands[1].reg << 12;
10099 inst.instruction |= inst.operands[2].reg << 16;
10102 static void
10103 do_vfp_sp_ldst (void)
10105 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10106 encode_arm_cp_address (1, FALSE, TRUE, 0);
10109 static void
10110 do_vfp_dp_ldst (void)
10112 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10113 encode_arm_cp_address (1, FALSE, TRUE, 0);
10117 static void
10118 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10120 if (inst.operands[0].writeback)
10121 inst.instruction |= WRITE_BACK;
10122 else
10123 constraint (ldstm_type != VFP_LDSTMIA,
10124 _("this addressing mode requires base-register writeback"));
10125 inst.instruction |= inst.operands[0].reg << 16;
10126 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10127 inst.instruction |= inst.operands[1].imm;
10130 static void
10131 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10133 int count;
10135 if (inst.operands[0].writeback)
10136 inst.instruction |= WRITE_BACK;
10137 else
10138 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10139 _("this addressing mode requires base-register writeback"));
10141 inst.instruction |= inst.operands[0].reg << 16;
10142 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10144 count = inst.operands[1].imm << 1;
10145 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10146 count += 1;
10148 inst.instruction |= count;
10151 static void
10152 do_vfp_sp_ldstmia (void)
10154 vfp_sp_ldstm (VFP_LDSTMIA);
10157 static void
10158 do_vfp_sp_ldstmdb (void)
10160 vfp_sp_ldstm (VFP_LDSTMDB);
10163 static void
10164 do_vfp_dp_ldstmia (void)
10166 vfp_dp_ldstm (VFP_LDSTMIA);
10169 static void
10170 do_vfp_dp_ldstmdb (void)
10172 vfp_dp_ldstm (VFP_LDSTMDB);
10175 static void
10176 do_vfp_xp_ldstmia (void)
10178 vfp_dp_ldstm (VFP_LDSTMIAX);
10181 static void
10182 do_vfp_xp_ldstmdb (void)
10184 vfp_dp_ldstm (VFP_LDSTMDBX);
10187 static void
10188 do_vfp_dp_rd_rm (void)
10190 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10191 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10194 static void
10195 do_vfp_dp_rn_rd (void)
10197 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10198 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10201 static void
10202 do_vfp_dp_rd_rn (void)
10204 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10205 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10208 static void
10209 do_vfp_dp_rd_rn_rm (void)
10211 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10212 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10213 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10216 static void
10217 do_vfp_dp_rd (void)
10219 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10222 static void
10223 do_vfp_dp_rm_rd_rn (void)
10225 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10226 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10227 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10230 /* VFPv3 instructions. */
10231 static void
10232 do_vfp_sp_const (void)
10234 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10235 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10236 inst.instruction |= (inst.operands[1].imm & 0x0f);
10239 static void
10240 do_vfp_dp_const (void)
10242 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10243 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10244 inst.instruction |= (inst.operands[1].imm & 0x0f);
10247 static void
10248 vfp_conv (int srcsize)
10250 int immbits = srcsize - inst.operands[1].imm;
10252 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10254 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10255 i.e. immbits must be in range 0 - 16. */
10256 inst.error = _("immediate value out of range, expected range [0, 16]");
10257 return;
10259 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10261 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10262 i.e. immbits must be in range 0 - 31. */
10263 inst.error = _("immediate value out of range, expected range [1, 32]");
10264 return;
10267 inst.instruction |= (immbits & 1) << 5;
10268 inst.instruction |= (immbits >> 1);
10271 static void
10272 do_vfp_sp_conv_16 (void)
10274 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10275 vfp_conv (16);
10278 static void
10279 do_vfp_dp_conv_16 (void)
10281 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10282 vfp_conv (16);
10285 static void
10286 do_vfp_sp_conv_32 (void)
10288 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10289 vfp_conv (32);
10292 static void
10293 do_vfp_dp_conv_32 (void)
10295 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10296 vfp_conv (32);
10299 /* FPA instructions. Also in a logical order. */
10301 static void
10302 do_fpa_cmp (void)
10304 inst.instruction |= inst.operands[0].reg << 16;
10305 inst.instruction |= inst.operands[1].reg;
10308 static void
10309 do_fpa_ldmstm (void)
10311 inst.instruction |= inst.operands[0].reg << 12;
10312 switch (inst.operands[1].imm)
10314 case 1: inst.instruction |= CP_T_X; break;
10315 case 2: inst.instruction |= CP_T_Y; break;
10316 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10317 case 4: break;
10318 default: abort ();
10321 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10323 /* The instruction specified "ea" or "fd", so we can only accept
10324 [Rn]{!}. The instruction does not really support stacking or
10325 unstacking, so we have to emulate these by setting appropriate
10326 bits and offsets. */
10327 constraint (inst.relocs[0].exp.X_op != O_constant
10328 || inst.relocs[0].exp.X_add_number != 0,
10329 _("this instruction does not support indexing"));
10331 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10332 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
10334 if (!(inst.instruction & INDEX_UP))
10335 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
10337 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10339 inst.operands[2].preind = 0;
10340 inst.operands[2].postind = 1;
10344 encode_arm_cp_address (2, TRUE, TRUE, 0);
10347 /* iWMMXt instructions: strictly in alphabetical order. */
10349 static void
10350 do_iwmmxt_tandorc (void)
10352 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10355 static void
10356 do_iwmmxt_textrc (void)
10358 inst.instruction |= inst.operands[0].reg << 12;
10359 inst.instruction |= inst.operands[1].imm;
10362 static void
10363 do_iwmmxt_textrm (void)
10365 inst.instruction |= inst.operands[0].reg << 12;
10366 inst.instruction |= inst.operands[1].reg << 16;
10367 inst.instruction |= inst.operands[2].imm;
10370 static void
10371 do_iwmmxt_tinsr (void)
10373 inst.instruction |= inst.operands[0].reg << 16;
10374 inst.instruction |= inst.operands[1].reg << 12;
10375 inst.instruction |= inst.operands[2].imm;
10378 static void
10379 do_iwmmxt_tmia (void)
10381 inst.instruction |= inst.operands[0].reg << 5;
10382 inst.instruction |= inst.operands[1].reg;
10383 inst.instruction |= inst.operands[2].reg << 12;
10386 static void
10387 do_iwmmxt_waligni (void)
10389 inst.instruction |= inst.operands[0].reg << 12;
10390 inst.instruction |= inst.operands[1].reg << 16;
10391 inst.instruction |= inst.operands[2].reg;
10392 inst.instruction |= inst.operands[3].imm << 20;
10395 static void
10396 do_iwmmxt_wmerge (void)
10398 inst.instruction |= inst.operands[0].reg << 12;
10399 inst.instruction |= inst.operands[1].reg << 16;
10400 inst.instruction |= inst.operands[2].reg;
10401 inst.instruction |= inst.operands[3].imm << 21;
10404 static void
10405 do_iwmmxt_wmov (void)
10407 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10408 inst.instruction |= inst.operands[0].reg << 12;
10409 inst.instruction |= inst.operands[1].reg << 16;
10410 inst.instruction |= inst.operands[1].reg;
10413 static void
10414 do_iwmmxt_wldstbh (void)
10416 int reloc;
10417 inst.instruction |= inst.operands[0].reg << 12;
10418 if (thumb_mode)
10419 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10420 else
10421 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10422 encode_arm_cp_address (1, TRUE, FALSE, reloc);
10425 static void
10426 do_iwmmxt_wldstw (void)
10428 /* RIWR_RIWC clears .isreg for a control register. */
10429 if (!inst.operands[0].isreg)
10431 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10432 inst.instruction |= 0xf0000000;
10435 inst.instruction |= inst.operands[0].reg << 12;
10436 encode_arm_cp_address (1, TRUE, TRUE, 0);
10439 static void
10440 do_iwmmxt_wldstd (void)
10442 inst.instruction |= inst.operands[0].reg << 12;
10443 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10444 && inst.operands[1].immisreg)
10446 inst.instruction &= ~0x1a000ff;
10447 inst.instruction |= (0xfU << 28);
10448 if (inst.operands[1].preind)
10449 inst.instruction |= PRE_INDEX;
10450 if (!inst.operands[1].negative)
10451 inst.instruction |= INDEX_UP;
10452 if (inst.operands[1].writeback)
10453 inst.instruction |= WRITE_BACK;
10454 inst.instruction |= inst.operands[1].reg << 16;
10455 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
10456 inst.instruction |= inst.operands[1].imm;
10458 else
10459 encode_arm_cp_address (1, TRUE, FALSE, 0);
10462 static void
10463 do_iwmmxt_wshufh (void)
10465 inst.instruction |= inst.operands[0].reg << 12;
10466 inst.instruction |= inst.operands[1].reg << 16;
10467 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10468 inst.instruction |= (inst.operands[2].imm & 0x0f);
10471 static void
10472 do_iwmmxt_wzero (void)
10474 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10475 inst.instruction |= inst.operands[0].reg;
10476 inst.instruction |= inst.operands[0].reg << 12;
10477 inst.instruction |= inst.operands[0].reg << 16;
10480 static void
10481 do_iwmmxt_wrwrwr_or_imm5 (void)
10483 if (inst.operands[2].isreg)
10484 do_rd_rn_rm ();
10485 else {
10486 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10487 _("immediate operand requires iWMMXt2"));
10488 do_rd_rn ();
10489 if (inst.operands[2].imm == 0)
10491 switch ((inst.instruction >> 20) & 0xf)
10493 case 4:
10494 case 5:
10495 case 6:
10496 case 7:
10497 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10498 inst.operands[2].imm = 16;
10499 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10500 break;
10501 case 8:
10502 case 9:
10503 case 10:
10504 case 11:
10505 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10506 inst.operands[2].imm = 32;
10507 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10508 break;
10509 case 12:
10510 case 13:
10511 case 14:
10512 case 15:
10514 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10515 unsigned long wrn;
10516 wrn = (inst.instruction >> 16) & 0xf;
10517 inst.instruction &= 0xff0fff0f;
10518 inst.instruction |= wrn;
10519 /* Bail out here; the instruction is now assembled. */
10520 return;
10524 /* Map 32 -> 0, etc. */
10525 inst.operands[2].imm &= 0x1f;
10526 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
10530 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10531 operations first, then control, shift, and load/store. */
10533 /* Insns like "foo X,Y,Z". */
10535 static void
10536 do_mav_triple (void)
10538 inst.instruction |= inst.operands[0].reg << 16;
10539 inst.instruction |= inst.operands[1].reg;
10540 inst.instruction |= inst.operands[2].reg << 12;
10543 /* Insns like "foo W,X,Y,Z".
10544 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
10546 static void
10547 do_mav_quad (void)
10549 inst.instruction |= inst.operands[0].reg << 5;
10550 inst.instruction |= inst.operands[1].reg << 12;
10551 inst.instruction |= inst.operands[2].reg << 16;
10552 inst.instruction |= inst.operands[3].reg;
10555 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10556 static void
10557 do_mav_dspsc (void)
10559 inst.instruction |= inst.operands[1].reg << 12;
10562 /* Maverick shift immediate instructions.
10563 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10564 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
10566 static void
10567 do_mav_shift (void)
10569 int imm = inst.operands[2].imm;
10571 inst.instruction |= inst.operands[0].reg << 12;
10572 inst.instruction |= inst.operands[1].reg << 16;
10574 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10575 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10576 Bit 4 should be 0. */
10577 imm = (imm & 0xf) | ((imm & 0x70) << 1);
10579 inst.instruction |= imm;
10582 /* XScale instructions. Also sorted arithmetic before move. */
10584 /* Xscale multiply-accumulate (argument parse)
10585 MIAcc acc0,Rm,Rs
10586 MIAPHcc acc0,Rm,Rs
10587 MIAxycc acc0,Rm,Rs. */
10589 static void
10590 do_xsc_mia (void)
10592 inst.instruction |= inst.operands[1].reg;
10593 inst.instruction |= inst.operands[2].reg << 12;
10596 /* Xscale move-accumulator-register (argument parse)
10598 MARcc acc0,RdLo,RdHi. */
10600 static void
10601 do_xsc_mar (void)
10603 inst.instruction |= inst.operands[1].reg << 12;
10604 inst.instruction |= inst.operands[2].reg << 16;
10607 /* Xscale move-register-accumulator (argument parse)
10609 MRAcc RdLo,RdHi,acc0. */
10611 static void
10612 do_xsc_mra (void)
10614 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10615 inst.instruction |= inst.operands[0].reg << 12;
10616 inst.instruction |= inst.operands[1].reg << 16;
10619 /* Encoding functions relevant only to Thumb. */
10621 /* inst.operands[i] is a shifted-register operand; encode
10622 it into inst.instruction in the format used by Thumb32. */
10624 static void
10625 encode_thumb32_shifted_operand (int i)
10627 unsigned int value = inst.relocs[0].exp.X_add_number;
10628 unsigned int shift = inst.operands[i].shift_kind;
10630 constraint (inst.operands[i].immisreg,
10631 _("shift by register not allowed in thumb mode"));
10632 inst.instruction |= inst.operands[i].reg;
10633 if (shift == SHIFT_RRX)
10634 inst.instruction |= SHIFT_ROR << 4;
10635 else
10637 constraint (inst.relocs[0].exp.X_op != O_constant,
10638 _("expression too complex"));
10640 constraint (value > 32
10641 || (value == 32 && (shift == SHIFT_LSL
10642 || shift == SHIFT_ROR)),
10643 _("shift expression is too large"));
10645 if (value == 0)
10646 shift = SHIFT_LSL;
10647 else if (value == 32)
10648 value = 0;
10650 inst.instruction |= shift << 4;
10651 inst.instruction |= (value & 0x1c) << 10;
10652 inst.instruction |= (value & 0x03) << 6;
10657 /* inst.operands[i] was set up by parse_address. Encode it into a
10658 Thumb32 format load or store instruction. Reject forms that cannot
10659 be used with such instructions. If is_t is true, reject forms that
10660 cannot be used with a T instruction; if is_d is true, reject forms
10661 that cannot be used with a D instruction. If it is a store insn,
10662 reject PC in Rn. */
10664 static void
10665 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10667 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
10669 constraint (!inst.operands[i].isreg,
10670 _("Instruction does not support =N addresses"));
10672 inst.instruction |= inst.operands[i].reg << 16;
10673 if (inst.operands[i].immisreg)
10675 constraint (is_pc, BAD_PC_ADDRESSING);
10676 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10677 constraint (inst.operands[i].negative,
10678 _("Thumb does not support negative register indexing"));
10679 constraint (inst.operands[i].postind,
10680 _("Thumb does not support register post-indexing"));
10681 constraint (inst.operands[i].writeback,
10682 _("Thumb does not support register indexing with writeback"));
10683 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10684 _("Thumb supports only LSL in shifted register indexing"));
10686 inst.instruction |= inst.operands[i].imm;
10687 if (inst.operands[i].shifted)
10689 constraint (inst.relocs[0].exp.X_op != O_constant,
10690 _("expression too complex"));
10691 constraint (inst.relocs[0].exp.X_add_number < 0
10692 || inst.relocs[0].exp.X_add_number > 3,
10693 _("shift out of range"));
10694 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
10696 inst.relocs[0].type = BFD_RELOC_UNUSED;
10698 else if (inst.operands[i].preind)
10700 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
10701 constraint (is_t && inst.operands[i].writeback,
10702 _("cannot use writeback with this instruction"));
10703 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10704 BAD_PC_ADDRESSING);
10706 if (is_d)
10708 inst.instruction |= 0x01000000;
10709 if (inst.operands[i].writeback)
10710 inst.instruction |= 0x00200000;
10712 else
10714 inst.instruction |= 0x00000c00;
10715 if (inst.operands[i].writeback)
10716 inst.instruction |= 0x00000100;
10718 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10720 else if (inst.operands[i].postind)
10722 gas_assert (inst.operands[i].writeback);
10723 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10724 constraint (is_t, _("cannot use post-indexing with this instruction"));
10726 if (is_d)
10727 inst.instruction |= 0x00200000;
10728 else
10729 inst.instruction |= 0x00000900;
10730 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10732 else /* unindexed - only for coprocessor */
10733 inst.error = _("instruction does not accept unindexed addressing");
10736 /* Table of Thumb instructions which exist in both 16- and 32-bit
10737 encodings (the latter only in post-V6T2 cores). The index is the
10738 value used in the insns table below. When there is more than one
10739 possible 16-bit encoding for the instruction, this table always
10740 holds variant (1).
10741 Also contains several pseudo-instructions used during relaxation. */
10742 #define T16_32_TAB \
10743 X(_adc, 4140, eb400000), \
10744 X(_adcs, 4140, eb500000), \
10745 X(_add, 1c00, eb000000), \
10746 X(_adds, 1c00, eb100000), \
10747 X(_addi, 0000, f1000000), \
10748 X(_addis, 0000, f1100000), \
10749 X(_add_pc,000f, f20f0000), \
10750 X(_add_sp,000d, f10d0000), \
10751 X(_adr, 000f, f20f0000), \
10752 X(_and, 4000, ea000000), \
10753 X(_ands, 4000, ea100000), \
10754 X(_asr, 1000, fa40f000), \
10755 X(_asrs, 1000, fa50f000), \
10756 X(_b, e000, f000b000), \
10757 X(_bcond, d000, f0008000), \
10758 X(_bf, 0000, f040e001), \
10759 X(_bfcsel,0000, f000e001), \
10760 X(_bfx, 0000, f060e001), \
10761 X(_bfl, 0000, f000c001), \
10762 X(_bflx, 0000, f070e001), \
10763 X(_bic, 4380, ea200000), \
10764 X(_bics, 4380, ea300000), \
10765 X(_cmn, 42c0, eb100f00), \
10766 X(_cmp, 2800, ebb00f00), \
10767 X(_cpsie, b660, f3af8400), \
10768 X(_cpsid, b670, f3af8600), \
10769 X(_cpy, 4600, ea4f0000), \
10770 X(_dec_sp,80dd, f1ad0d00), \
10771 X(_dls, 0000, f040e001), \
10772 X(_eor, 4040, ea800000), \
10773 X(_eors, 4040, ea900000), \
10774 X(_inc_sp,00dd, f10d0d00), \
10775 X(_ldmia, c800, e8900000), \
10776 X(_ldr, 6800, f8500000), \
10777 X(_ldrb, 7800, f8100000), \
10778 X(_ldrh, 8800, f8300000), \
10779 X(_ldrsb, 5600, f9100000), \
10780 X(_ldrsh, 5e00, f9300000), \
10781 X(_ldr_pc,4800, f85f0000), \
10782 X(_ldr_pc2,4800, f85f0000), \
10783 X(_ldr_sp,9800, f85d0000), \
10784 X(_le, 0000, f00fc001), \
10785 X(_lsl, 0000, fa00f000), \
10786 X(_lsls, 0000, fa10f000), \
10787 X(_lsr, 0800, fa20f000), \
10788 X(_lsrs, 0800, fa30f000), \
10789 X(_mov, 2000, ea4f0000), \
10790 X(_movs, 2000, ea5f0000), \
10791 X(_mul, 4340, fb00f000), \
10792 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10793 X(_mvn, 43c0, ea6f0000), \
10794 X(_mvns, 43c0, ea7f0000), \
10795 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10796 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10797 X(_orr, 4300, ea400000), \
10798 X(_orrs, 4300, ea500000), \
10799 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10800 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10801 X(_rev, ba00, fa90f080), \
10802 X(_rev16, ba40, fa90f090), \
10803 X(_revsh, bac0, fa90f0b0), \
10804 X(_ror, 41c0, fa60f000), \
10805 X(_rors, 41c0, fa70f000), \
10806 X(_sbc, 4180, eb600000), \
10807 X(_sbcs, 4180, eb700000), \
10808 X(_stmia, c000, e8800000), \
10809 X(_str, 6000, f8400000), \
10810 X(_strb, 7000, f8000000), \
10811 X(_strh, 8000, f8200000), \
10812 X(_str_sp,9000, f84d0000), \
10813 X(_sub, 1e00, eba00000), \
10814 X(_subs, 1e00, ebb00000), \
10815 X(_subi, 8000, f1a00000), \
10816 X(_subis, 8000, f1b00000), \
10817 X(_sxtb, b240, fa4ff080), \
10818 X(_sxth, b200, fa0ff080), \
10819 X(_tst, 4200, ea100f00), \
10820 X(_uxtb, b2c0, fa5ff080), \
10821 X(_uxth, b280, fa1ff080), \
10822 X(_nop, bf00, f3af8000), \
10823 X(_yield, bf10, f3af8001), \
10824 X(_wfe, bf20, f3af8002), \
10825 X(_wfi, bf30, f3af8003), \
10826 X(_wls, 0000, f040c001), \
10827 X(_sev, bf40, f3af8004), \
10828 X(_sevl, bf50, f3af8005), \
10829 X(_udf, de00, f7f0a000)
10831 /* To catch errors in encoding functions, the codes are all offset by
10832 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10833 as 16-bit instructions. */
10834 #define X(a,b,c) T_MNEM##a
10835 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10836 #undef X
10838 #define X(a,b,c) 0x##b
10839 static const unsigned short thumb_op16[] = { T16_32_TAB };
10840 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10841 #undef X
10843 #define X(a,b,c) 0x##c
10844 static const unsigned int thumb_op32[] = { T16_32_TAB };
10845 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10846 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
10847 #undef X
10848 #undef T16_32_TAB
10850 /* Thumb instruction encoders, in alphabetical order. */
10852 /* ADDW or SUBW. */
10854 static void
10855 do_t_add_sub_w (void)
10857 int Rd, Rn;
10859 Rd = inst.operands[0].reg;
10860 Rn = inst.operands[1].reg;
10862 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10863 is the SP-{plus,minus}-immediate form of the instruction. */
10864 if (Rn == REG_SP)
10865 constraint (Rd == REG_PC, BAD_PC);
10866 else
10867 reject_bad_reg (Rd);
10869 inst.instruction |= (Rn << 16) | (Rd << 8);
10870 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
10873 /* Parse an add or subtract instruction. We get here with inst.instruction
10874 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
10876 static void
10877 do_t_add_sub (void)
10879 int Rd, Rs, Rn;
10881 Rd = inst.operands[0].reg;
10882 Rs = (inst.operands[1].present
10883 ? inst.operands[1].reg /* Rd, Rs, foo */
10884 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10886 if (Rd == REG_PC)
10887 set_pred_insn_type_last ();
10889 if (unified_syntax)
10891 bfd_boolean flags;
10892 bfd_boolean narrow;
10893 int opcode;
10895 flags = (inst.instruction == T_MNEM_adds
10896 || inst.instruction == T_MNEM_subs);
10897 if (flags)
10898 narrow = !in_pred_block ();
10899 else
10900 narrow = in_pred_block ();
10901 if (!inst.operands[2].isreg)
10903 int add;
10905 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10906 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10908 add = (inst.instruction == T_MNEM_add
10909 || inst.instruction == T_MNEM_adds);
10910 opcode = 0;
10911 if (inst.size_req != 4)
10913 /* Attempt to use a narrow opcode, with relaxation if
10914 appropriate. */
10915 if (Rd == REG_SP && Rs == REG_SP && !flags)
10916 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10917 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10918 opcode = T_MNEM_add_sp;
10919 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10920 opcode = T_MNEM_add_pc;
10921 else if (Rd <= 7 && Rs <= 7 && narrow)
10923 if (flags)
10924 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10925 else
10926 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10928 if (opcode)
10930 inst.instruction = THUMB_OP16(opcode);
10931 inst.instruction |= (Rd << 4) | Rs;
10932 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10933 || (inst.relocs[0].type
10934 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
10936 if (inst.size_req == 2)
10937 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10938 else
10939 inst.relax = opcode;
10942 else
10943 constraint (inst.size_req == 2, BAD_HIREG);
10945 if (inst.size_req == 4
10946 || (inst.size_req != 2 && !opcode))
10948 constraint ((inst.relocs[0].type
10949 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
10950 && (inst.relocs[0].type
10951 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
10952 THUMB1_RELOC_ONLY);
10953 if (Rd == REG_PC)
10955 constraint (add, BAD_PC);
10956 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10957 _("only SUBS PC, LR, #const allowed"));
10958 constraint (inst.relocs[0].exp.X_op != O_constant,
10959 _("expression too complex"));
10960 constraint (inst.relocs[0].exp.X_add_number < 0
10961 || inst.relocs[0].exp.X_add_number > 0xff,
10962 _("immediate value out of range"));
10963 inst.instruction = T2_SUBS_PC_LR
10964 | inst.relocs[0].exp.X_add_number;
10965 inst.relocs[0].type = BFD_RELOC_UNUSED;
10966 return;
10968 else if (Rs == REG_PC)
10970 /* Always use addw/subw. */
10971 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10972 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
10974 else
10976 inst.instruction = THUMB_OP32 (inst.instruction);
10977 inst.instruction = (inst.instruction & 0xe1ffffff)
10978 | 0x10000000;
10979 if (flags)
10980 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
10981 else
10982 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
10984 inst.instruction |= Rd << 8;
10985 inst.instruction |= Rs << 16;
10988 else
10990 unsigned int value = inst.relocs[0].exp.X_add_number;
10991 unsigned int shift = inst.operands[2].shift_kind;
10993 Rn = inst.operands[2].reg;
10994 /* See if we can do this with a 16-bit instruction. */
10995 if (!inst.operands[2].shifted && inst.size_req != 4)
10997 if (Rd > 7 || Rs > 7 || Rn > 7)
10998 narrow = FALSE;
11000 if (narrow)
11002 inst.instruction = ((inst.instruction == T_MNEM_adds
11003 || inst.instruction == T_MNEM_add)
11004 ? T_OPCODE_ADD_R3
11005 : T_OPCODE_SUB_R3);
11006 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11007 return;
11010 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11012 /* Thumb-1 cores (except v6-M) require at least one high
11013 register in a narrow non flag setting add. */
11014 if (Rd > 7 || Rn > 7
11015 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11016 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11018 if (Rd == Rn)
11020 Rn = Rs;
11021 Rs = Rd;
11023 inst.instruction = T_OPCODE_ADD_HI;
11024 inst.instruction |= (Rd & 8) << 4;
11025 inst.instruction |= (Rd & 7);
11026 inst.instruction |= Rn << 3;
11027 return;
11032 constraint (Rd == REG_PC, BAD_PC);
11033 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11034 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11035 constraint (Rs == REG_PC, BAD_PC);
11036 reject_bad_reg (Rn);
11038 /* If we get here, it can't be done in 16 bits. */
11039 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11040 _("shift must be constant"));
11041 inst.instruction = THUMB_OP32 (inst.instruction);
11042 inst.instruction |= Rd << 8;
11043 inst.instruction |= Rs << 16;
11044 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11045 _("shift value over 3 not allowed in thumb mode"));
11046 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11047 _("only LSL shift allowed in thumb mode"));
11048 encode_thumb32_shifted_operand (2);
11051 else
11053 constraint (inst.instruction == T_MNEM_adds
11054 || inst.instruction == T_MNEM_subs,
11055 BAD_THUMB32);
11057 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11059 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11060 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11061 BAD_HIREG);
11063 inst.instruction = (inst.instruction == T_MNEM_add
11064 ? 0x0000 : 0x8000);
11065 inst.instruction |= (Rd << 4) | Rs;
11066 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11067 return;
11070 Rn = inst.operands[2].reg;
11071 constraint (inst.operands[2].shifted, _("unshifted register required"));
11073 /* We now have Rd, Rs, and Rn set to registers. */
11074 if (Rd > 7 || Rs > 7 || Rn > 7)
11076 /* Can't do this for SUB. */
11077 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11078 inst.instruction = T_OPCODE_ADD_HI;
11079 inst.instruction |= (Rd & 8) << 4;
11080 inst.instruction |= (Rd & 7);
11081 if (Rs == Rd)
11082 inst.instruction |= Rn << 3;
11083 else if (Rn == Rd)
11084 inst.instruction |= Rs << 3;
11085 else
11086 constraint (1, _("dest must overlap one source register"));
11088 else
11090 inst.instruction = (inst.instruction == T_MNEM_add
11091 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11092 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11097 static void
11098 do_t_adr (void)
11100 unsigned Rd;
11102 Rd = inst.operands[0].reg;
11103 reject_bad_reg (Rd);
11105 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11107 /* Defer to section relaxation. */
11108 inst.relax = inst.instruction;
11109 inst.instruction = THUMB_OP16 (inst.instruction);
11110 inst.instruction |= Rd << 4;
11112 else if (unified_syntax && inst.size_req != 2)
11114 /* Generate a 32-bit opcode. */
11115 inst.instruction = THUMB_OP32 (inst.instruction);
11116 inst.instruction |= Rd << 8;
11117 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11118 inst.relocs[0].pc_rel = 1;
11120 else
11122 /* Generate a 16-bit opcode. */
11123 inst.instruction = THUMB_OP16 (inst.instruction);
11124 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11125 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11126 inst.relocs[0].pc_rel = 1;
11127 inst.instruction |= Rd << 4;
11130 if (inst.relocs[0].exp.X_op == O_symbol
11131 && inst.relocs[0].exp.X_add_symbol != NULL
11132 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11133 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11134 inst.relocs[0].exp.X_add_number += 1;
11137 /* Arithmetic instructions for which there is just one 16-bit
11138 instruction encoding, and it allows only two low registers.
11139 For maximal compatibility with ARM syntax, we allow three register
11140 operands even when Thumb-32 instructions are not available, as long
11141 as the first two are identical. For instance, both "sbc r0,r1" and
11142 "sbc r0,r0,r1" are allowed. */
11143 static void
11144 do_t_arit3 (void)
11146 int Rd, Rs, Rn;
11148 Rd = inst.operands[0].reg;
11149 Rs = (inst.operands[1].present
11150 ? inst.operands[1].reg /* Rd, Rs, foo */
11151 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11152 Rn = inst.operands[2].reg;
11154 reject_bad_reg (Rd);
11155 reject_bad_reg (Rs);
11156 if (inst.operands[2].isreg)
11157 reject_bad_reg (Rn);
11159 if (unified_syntax)
11161 if (!inst.operands[2].isreg)
11163 /* For an immediate, we always generate a 32-bit opcode;
11164 section relaxation will shrink it later if possible. */
11165 inst.instruction = THUMB_OP32 (inst.instruction);
11166 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11167 inst.instruction |= Rd << 8;
11168 inst.instruction |= Rs << 16;
11169 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11171 else
11173 bfd_boolean narrow;
11175 /* See if we can do this with a 16-bit instruction. */
11176 if (THUMB_SETS_FLAGS (inst.instruction))
11177 narrow = !in_pred_block ();
11178 else
11179 narrow = in_pred_block ();
11181 if (Rd > 7 || Rn > 7 || Rs > 7)
11182 narrow = FALSE;
11183 if (inst.operands[2].shifted)
11184 narrow = FALSE;
11185 if (inst.size_req == 4)
11186 narrow = FALSE;
11188 if (narrow
11189 && Rd == Rs)
11191 inst.instruction = THUMB_OP16 (inst.instruction);
11192 inst.instruction |= Rd;
11193 inst.instruction |= Rn << 3;
11194 return;
11197 /* If we get here, it can't be done in 16 bits. */
11198 constraint (inst.operands[2].shifted
11199 && inst.operands[2].immisreg,
11200 _("shift must be constant"));
11201 inst.instruction = THUMB_OP32 (inst.instruction);
11202 inst.instruction |= Rd << 8;
11203 inst.instruction |= Rs << 16;
11204 encode_thumb32_shifted_operand (2);
11207 else
11209 /* On its face this is a lie - the instruction does set the
11210 flags. However, the only supported mnemonic in this mode
11211 says it doesn't. */
11212 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11214 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11215 _("unshifted register required"));
11216 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11217 constraint (Rd != Rs,
11218 _("dest and source1 must be the same register"));
11220 inst.instruction = THUMB_OP16 (inst.instruction);
11221 inst.instruction |= Rd;
11222 inst.instruction |= Rn << 3;
11226 /* Similarly, but for instructions where the arithmetic operation is
11227 commutative, so we can allow either of them to be different from
11228 the destination operand in a 16-bit instruction. For instance, all
11229 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11230 accepted. */
11231 static void
11232 do_t_arit3c (void)
11234 int Rd, Rs, Rn;
11236 Rd = inst.operands[0].reg;
11237 Rs = (inst.operands[1].present
11238 ? inst.operands[1].reg /* Rd, Rs, foo */
11239 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11240 Rn = inst.operands[2].reg;
11242 reject_bad_reg (Rd);
11243 reject_bad_reg (Rs);
11244 if (inst.operands[2].isreg)
11245 reject_bad_reg (Rn);
11247 if (unified_syntax)
11249 if (!inst.operands[2].isreg)
11251 /* For an immediate, we always generate a 32-bit opcode;
11252 section relaxation will shrink it later if possible. */
11253 inst.instruction = THUMB_OP32 (inst.instruction);
11254 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11255 inst.instruction |= Rd << 8;
11256 inst.instruction |= Rs << 16;
11257 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11259 else
11261 bfd_boolean narrow;
11263 /* See if we can do this with a 16-bit instruction. */
11264 if (THUMB_SETS_FLAGS (inst.instruction))
11265 narrow = !in_pred_block ();
11266 else
11267 narrow = in_pred_block ();
11269 if (Rd > 7 || Rn > 7 || Rs > 7)
11270 narrow = FALSE;
11271 if (inst.operands[2].shifted)
11272 narrow = FALSE;
11273 if (inst.size_req == 4)
11274 narrow = FALSE;
11276 if (narrow)
11278 if (Rd == Rs)
11280 inst.instruction = THUMB_OP16 (inst.instruction);
11281 inst.instruction |= Rd;
11282 inst.instruction |= Rn << 3;
11283 return;
11285 if (Rd == Rn)
11287 inst.instruction = THUMB_OP16 (inst.instruction);
11288 inst.instruction |= Rd;
11289 inst.instruction |= Rs << 3;
11290 return;
11294 /* If we get here, it can't be done in 16 bits. */
11295 constraint (inst.operands[2].shifted
11296 && inst.operands[2].immisreg,
11297 _("shift must be constant"));
11298 inst.instruction = THUMB_OP32 (inst.instruction);
11299 inst.instruction |= Rd << 8;
11300 inst.instruction |= Rs << 16;
11301 encode_thumb32_shifted_operand (2);
11304 else
11306 /* On its face this is a lie - the instruction does set the
11307 flags. However, the only supported mnemonic in this mode
11308 says it doesn't. */
11309 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11311 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11312 _("unshifted register required"));
11313 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11315 inst.instruction = THUMB_OP16 (inst.instruction);
11316 inst.instruction |= Rd;
11318 if (Rd == Rs)
11319 inst.instruction |= Rn << 3;
11320 else if (Rd == Rn)
11321 inst.instruction |= Rs << 3;
11322 else
11323 constraint (1, _("dest must overlap one source register"));
11327 static void
11328 do_t_bfc (void)
11330 unsigned Rd;
11331 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11332 constraint (msb > 32, _("bit-field extends past end of register"));
11333 /* The instruction encoding stores the LSB and MSB,
11334 not the LSB and width. */
11335 Rd = inst.operands[0].reg;
11336 reject_bad_reg (Rd);
11337 inst.instruction |= Rd << 8;
11338 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11339 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11340 inst.instruction |= msb - 1;
11343 static void
11344 do_t_bfi (void)
11346 int Rd, Rn;
11347 unsigned int msb;
11349 Rd = inst.operands[0].reg;
11350 reject_bad_reg (Rd);
11352 /* #0 in second position is alternative syntax for bfc, which is
11353 the same instruction but with REG_PC in the Rm field. */
11354 if (!inst.operands[1].isreg)
11355 Rn = REG_PC;
11356 else
11358 Rn = inst.operands[1].reg;
11359 reject_bad_reg (Rn);
11362 msb = inst.operands[2].imm + inst.operands[3].imm;
11363 constraint (msb > 32, _("bit-field extends past end of register"));
11364 /* The instruction encoding stores the LSB and MSB,
11365 not the LSB and width. */
11366 inst.instruction |= Rd << 8;
11367 inst.instruction |= Rn << 16;
11368 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11369 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11370 inst.instruction |= msb - 1;
11373 static void
11374 do_t_bfx (void)
11376 unsigned Rd, Rn;
11378 Rd = inst.operands[0].reg;
11379 Rn = inst.operands[1].reg;
11381 reject_bad_reg (Rd);
11382 reject_bad_reg (Rn);
11384 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11385 _("bit-field extends past end of register"));
11386 inst.instruction |= Rd << 8;
11387 inst.instruction |= Rn << 16;
11388 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11389 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11390 inst.instruction |= inst.operands[3].imm - 1;
11393 /* ARM V5 Thumb BLX (argument parse)
11394 BLX <target_addr> which is BLX(1)
11395 BLX <Rm> which is BLX(2)
11396 Unfortunately, there are two different opcodes for this mnemonic.
11397 So, the insns[].value is not used, and the code here zaps values
11398 into inst.instruction.
11400 ??? How to take advantage of the additional two bits of displacement
11401 available in Thumb32 mode? Need new relocation? */
11403 static void
11404 do_t_blx (void)
11406 set_pred_insn_type_last ();
11408 if (inst.operands[0].isreg)
11410 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11411 /* We have a register, so this is BLX(2). */
11412 inst.instruction |= inst.operands[0].reg << 3;
11414 else
11416 /* No register. This must be BLX(1). */
11417 inst.instruction = 0xf000e800;
11418 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
11422 static void
11423 do_t_branch (void)
11425 int opcode;
11426 int cond;
11427 bfd_reloc_code_real_type reloc;
11429 cond = inst.cond;
11430 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
11432 if (in_pred_block ())
11434 /* Conditional branches inside IT blocks are encoded as unconditional
11435 branches. */
11436 cond = COND_ALWAYS;
11438 else
11439 cond = inst.cond;
11441 if (cond != COND_ALWAYS)
11442 opcode = T_MNEM_bcond;
11443 else
11444 opcode = inst.instruction;
11446 if (unified_syntax
11447 && (inst.size_req == 4
11448 || (inst.size_req != 2
11449 && (inst.operands[0].hasreloc
11450 || inst.relocs[0].exp.X_op == O_constant))))
11452 inst.instruction = THUMB_OP32(opcode);
11453 if (cond == COND_ALWAYS)
11454 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
11455 else
11457 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11458 _("selected architecture does not support "
11459 "wide conditional branch instruction"));
11461 gas_assert (cond != 0xF);
11462 inst.instruction |= cond << 22;
11463 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
11466 else
11468 inst.instruction = THUMB_OP16(opcode);
11469 if (cond == COND_ALWAYS)
11470 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
11471 else
11473 inst.instruction |= cond << 8;
11474 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
11476 /* Allow section relaxation. */
11477 if (unified_syntax && inst.size_req != 2)
11478 inst.relax = opcode;
11480 inst.relocs[0].type = reloc;
11481 inst.relocs[0].pc_rel = 1;
11484 /* Actually do the work for Thumb state bkpt and hlt. The only difference
11485 between the two is the maximum immediate allowed - which is passed in
11486 RANGE. */
11487 static void
11488 do_t_bkpt_hlt1 (int range)
11490 constraint (inst.cond != COND_ALWAYS,
11491 _("instruction is always unconditional"));
11492 if (inst.operands[0].present)
11494 constraint (inst.operands[0].imm > range,
11495 _("immediate value out of range"));
11496 inst.instruction |= inst.operands[0].imm;
11499 set_pred_insn_type (NEUTRAL_IT_INSN);
11502 static void
11503 do_t_hlt (void)
11505 do_t_bkpt_hlt1 (63);
11508 static void
11509 do_t_bkpt (void)
11511 do_t_bkpt_hlt1 (255);
11514 static void
11515 do_t_branch23 (void)
11517 set_pred_insn_type_last ();
11518 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
11520 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11521 this file. We used to simply ignore the PLT reloc type here --
11522 the branch encoding is now needed to deal with TLSCALL relocs.
11523 So if we see a PLT reloc now, put it back to how it used to be to
11524 keep the preexisting behaviour. */
11525 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11526 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
11528 #if defined(OBJ_COFF)
11529 /* If the destination of the branch is a defined symbol which does not have
11530 the THUMB_FUNC attribute, then we must be calling a function which has
11531 the (interfacearm) attribute. We look for the Thumb entry point to that
11532 function and change the branch to refer to that function instead. */
11533 if ( inst.relocs[0].exp.X_op == O_symbol
11534 && inst.relocs[0].exp.X_add_symbol != NULL
11535 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11536 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11537 inst.relocs[0].exp.X_add_symbol
11538 = find_real_start (inst.relocs[0].exp.X_add_symbol);
11539 #endif
11542 static void
11543 do_t_bx (void)
11545 set_pred_insn_type_last ();
11546 inst.instruction |= inst.operands[0].reg << 3;
11547 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11548 should cause the alignment to be checked once it is known. This is
11549 because BX PC only works if the instruction is word aligned. */
11552 static void
11553 do_t_bxj (void)
11555 int Rm;
11557 set_pred_insn_type_last ();
11558 Rm = inst.operands[0].reg;
11559 reject_bad_reg (Rm);
11560 inst.instruction |= Rm << 16;
11563 static void
11564 do_t_clz (void)
11566 unsigned Rd;
11567 unsigned Rm;
11569 Rd = inst.operands[0].reg;
11570 Rm = inst.operands[1].reg;
11572 reject_bad_reg (Rd);
11573 reject_bad_reg (Rm);
11575 inst.instruction |= Rd << 8;
11576 inst.instruction |= Rm << 16;
11577 inst.instruction |= Rm;
11580 static void
11581 do_t_csdb (void)
11583 set_pred_insn_type (OUTSIDE_PRED_INSN);
11586 static void
11587 do_t_cps (void)
11589 set_pred_insn_type (OUTSIDE_PRED_INSN);
11590 inst.instruction |= inst.operands[0].imm;
11593 static void
11594 do_t_cpsi (void)
11596 set_pred_insn_type (OUTSIDE_PRED_INSN);
11597 if (unified_syntax
11598 && (inst.operands[1].present || inst.size_req == 4)
11599 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
11601 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11602 inst.instruction = 0xf3af8000;
11603 inst.instruction |= imod << 9;
11604 inst.instruction |= inst.operands[0].imm << 5;
11605 if (inst.operands[1].present)
11606 inst.instruction |= 0x100 | inst.operands[1].imm;
11608 else
11610 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11611 && (inst.operands[0].imm & 4),
11612 _("selected processor does not support 'A' form "
11613 "of this instruction"));
11614 constraint (inst.operands[1].present || inst.size_req == 4,
11615 _("Thumb does not support the 2-argument "
11616 "form of this instruction"));
11617 inst.instruction |= inst.operands[0].imm;
11621 /* THUMB CPY instruction (argument parse). */
11623 static void
11624 do_t_cpy (void)
11626 if (inst.size_req == 4)
11628 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11629 inst.instruction |= inst.operands[0].reg << 8;
11630 inst.instruction |= inst.operands[1].reg;
11632 else
11634 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11635 inst.instruction |= (inst.operands[0].reg & 0x7);
11636 inst.instruction |= inst.operands[1].reg << 3;
11640 static void
11641 do_t_cbz (void)
11643 set_pred_insn_type (OUTSIDE_PRED_INSN);
11644 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11645 inst.instruction |= inst.operands[0].reg;
11646 inst.relocs[0].pc_rel = 1;
11647 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11650 static void
11651 do_t_dbg (void)
11653 inst.instruction |= inst.operands[0].imm;
11656 static void
11657 do_t_div (void)
11659 unsigned Rd, Rn, Rm;
11661 Rd = inst.operands[0].reg;
11662 Rn = (inst.operands[1].present
11663 ? inst.operands[1].reg : Rd);
11664 Rm = inst.operands[2].reg;
11666 reject_bad_reg (Rd);
11667 reject_bad_reg (Rn);
11668 reject_bad_reg (Rm);
11670 inst.instruction |= Rd << 8;
11671 inst.instruction |= Rn << 16;
11672 inst.instruction |= Rm;
11675 static void
11676 do_t_hint (void)
11678 if (unified_syntax && inst.size_req == 4)
11679 inst.instruction = THUMB_OP32 (inst.instruction);
11680 else
11681 inst.instruction = THUMB_OP16 (inst.instruction);
11684 static void
11685 do_t_it (void)
11687 unsigned int cond = inst.operands[0].imm;
11689 set_pred_insn_type (IT_INSN);
11690 now_pred.mask = (inst.instruction & 0xf) | 0x10;
11691 now_pred.cc = cond;
11692 now_pred.warn_deprecated = FALSE;
11693 now_pred.type = SCALAR_PRED;
11695 /* If the condition is a negative condition, invert the mask. */
11696 if ((cond & 0x1) == 0x0)
11698 unsigned int mask = inst.instruction & 0x000f;
11700 if ((mask & 0x7) == 0)
11702 /* No conversion needed. */
11703 now_pred.block_length = 1;
11705 else if ((mask & 0x3) == 0)
11707 mask ^= 0x8;
11708 now_pred.block_length = 2;
11710 else if ((mask & 0x1) == 0)
11712 mask ^= 0xC;
11713 now_pred.block_length = 3;
11715 else
11717 mask ^= 0xE;
11718 now_pred.block_length = 4;
11721 inst.instruction &= 0xfff0;
11722 inst.instruction |= mask;
11725 inst.instruction |= cond << 4;
11728 static void
11729 do_mve_vpt (void)
11731 /* We are dealing with a vector predicated block. */
11732 set_pred_insn_type (VPT_INSN);
11733 now_pred.cc = 0;
11734 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
11735 | ((inst.instruction & 0xe000) >> 13);
11736 now_pred.warn_deprecated = FALSE;
11737 now_pred.type = VECTOR_PRED;
11740 /* Helper function used for both push/pop and ldm/stm. */
11741 static void
11742 encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
11743 bfd_boolean writeback)
11745 bfd_boolean load, store;
11747 gas_assert (base != -1 || !do_io);
11748 load = do_io && ((inst.instruction & (1 << 20)) != 0);
11749 store = do_io && !load;
11751 if (mask & (1 << 13))
11752 inst.error = _("SP not allowed in register list");
11754 if (do_io && (mask & (1 << base)) != 0
11755 && writeback)
11756 inst.error = _("having the base register in the register list when "
11757 "using write back is UNPREDICTABLE");
11759 if (load)
11761 if (mask & (1 << 15))
11763 if (mask & (1 << 14))
11764 inst.error = _("LR and PC should not both be in register list");
11765 else
11766 set_pred_insn_type_last ();
11769 else if (store)
11771 if (mask & (1 << 15))
11772 inst.error = _("PC not allowed in register list");
11775 if (do_io && ((mask & (mask - 1)) == 0))
11777 /* Single register transfers implemented as str/ldr. */
11778 if (writeback)
11780 if (inst.instruction & (1 << 23))
11781 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11782 else
11783 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11785 else
11787 if (inst.instruction & (1 << 23))
11788 inst.instruction = 0x00800000; /* ia -> [base] */
11789 else
11790 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11793 inst.instruction |= 0xf8400000;
11794 if (load)
11795 inst.instruction |= 0x00100000;
11797 mask = ffs (mask) - 1;
11798 mask <<= 12;
11800 else if (writeback)
11801 inst.instruction |= WRITE_BACK;
11803 inst.instruction |= mask;
11804 if (do_io)
11805 inst.instruction |= base << 16;
11808 static void
11809 do_t_ldmstm (void)
11811 /* This really doesn't seem worth it. */
11812 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
11813 _("expression too complex"));
11814 constraint (inst.operands[1].writeback,
11815 _("Thumb load/store multiple does not support {reglist}^"));
11817 if (unified_syntax)
11819 bfd_boolean narrow;
11820 unsigned mask;
11822 narrow = FALSE;
11823 /* See if we can use a 16-bit instruction. */
11824 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11825 && inst.size_req != 4
11826 && !(inst.operands[1].imm & ~0xff))
11828 mask = 1 << inst.operands[0].reg;
11830 if (inst.operands[0].reg <= 7)
11832 if (inst.instruction == T_MNEM_stmia
11833 ? inst.operands[0].writeback
11834 : (inst.operands[0].writeback
11835 == !(inst.operands[1].imm & mask)))
11837 if (inst.instruction == T_MNEM_stmia
11838 && (inst.operands[1].imm & mask)
11839 && (inst.operands[1].imm & (mask - 1)))
11840 as_warn (_("value stored for r%d is UNKNOWN"),
11841 inst.operands[0].reg);
11843 inst.instruction = THUMB_OP16 (inst.instruction);
11844 inst.instruction |= inst.operands[0].reg << 8;
11845 inst.instruction |= inst.operands[1].imm;
11846 narrow = TRUE;
11848 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11850 /* This means 1 register in reg list one of 3 situations:
11851 1. Instruction is stmia, but without writeback.
11852 2. lmdia without writeback, but with Rn not in
11853 reglist.
11854 3. ldmia with writeback, but with Rn in reglist.
11855 Case 3 is UNPREDICTABLE behaviour, so we handle
11856 case 1 and 2 which can be converted into a 16-bit
11857 str or ldr. The SP cases are handled below. */
11858 unsigned long opcode;
11859 /* First, record an error for Case 3. */
11860 if (inst.operands[1].imm & mask
11861 && inst.operands[0].writeback)
11862 inst.error =
11863 _("having the base register in the register list when "
11864 "using write back is UNPREDICTABLE");
11866 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
11867 : T_MNEM_ldr);
11868 inst.instruction = THUMB_OP16 (opcode);
11869 inst.instruction |= inst.operands[0].reg << 3;
11870 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11871 narrow = TRUE;
11874 else if (inst.operands[0] .reg == REG_SP)
11876 if (inst.operands[0].writeback)
11878 inst.instruction =
11879 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11880 ? T_MNEM_push : T_MNEM_pop);
11881 inst.instruction |= inst.operands[1].imm;
11882 narrow = TRUE;
11884 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11886 inst.instruction =
11887 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11888 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
11889 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
11890 narrow = TRUE;
11895 if (!narrow)
11897 if (inst.instruction < 0xffff)
11898 inst.instruction = THUMB_OP32 (inst.instruction);
11900 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
11901 inst.operands[1].imm,
11902 inst.operands[0].writeback);
11905 else
11907 constraint (inst.operands[0].reg > 7
11908 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
11909 constraint (inst.instruction != T_MNEM_ldmia
11910 && inst.instruction != T_MNEM_stmia,
11911 _("Thumb-2 instruction only valid in unified syntax"));
11912 if (inst.instruction == T_MNEM_stmia)
11914 if (!inst.operands[0].writeback)
11915 as_warn (_("this instruction will write back the base register"));
11916 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11917 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
11918 as_warn (_("value stored for r%d is UNKNOWN"),
11919 inst.operands[0].reg);
11921 else
11923 if (!inst.operands[0].writeback
11924 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11925 as_warn (_("this instruction will write back the base register"));
11926 else if (inst.operands[0].writeback
11927 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11928 as_warn (_("this instruction will not write back the base register"));
11931 inst.instruction = THUMB_OP16 (inst.instruction);
11932 inst.instruction |= inst.operands[0].reg << 8;
11933 inst.instruction |= inst.operands[1].imm;
11937 static void
11938 do_t_ldrex (void)
11940 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11941 || inst.operands[1].postind || inst.operands[1].writeback
11942 || inst.operands[1].immisreg || inst.operands[1].shifted
11943 || inst.operands[1].negative,
11944 BAD_ADDR_MODE);
11946 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11948 inst.instruction |= inst.operands[0].reg << 12;
11949 inst.instruction |= inst.operands[1].reg << 16;
11950 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
11953 static void
11954 do_t_ldrexd (void)
11956 if (!inst.operands[1].present)
11958 constraint (inst.operands[0].reg == REG_LR,
11959 _("r14 not allowed as first register "
11960 "when second register is omitted"));
11961 inst.operands[1].reg = inst.operands[0].reg + 1;
11963 constraint (inst.operands[0].reg == inst.operands[1].reg,
11964 BAD_OVERLAP);
11966 inst.instruction |= inst.operands[0].reg << 12;
11967 inst.instruction |= inst.operands[1].reg << 8;
11968 inst.instruction |= inst.operands[2].reg << 16;
11971 static void
11972 do_t_ldst (void)
11974 unsigned long opcode;
11975 int Rn;
11977 if (inst.operands[0].isreg
11978 && !inst.operands[0].preind
11979 && inst.operands[0].reg == REG_PC)
11980 set_pred_insn_type_last ();
11982 opcode = inst.instruction;
11983 if (unified_syntax)
11985 if (!inst.operands[1].isreg)
11987 if (opcode <= 0xffff)
11988 inst.instruction = THUMB_OP32 (opcode);
11989 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11990 return;
11992 if (inst.operands[1].isreg
11993 && !inst.operands[1].writeback
11994 && !inst.operands[1].shifted && !inst.operands[1].postind
11995 && !inst.operands[1].negative && inst.operands[0].reg <= 7
11996 && opcode <= 0xffff
11997 && inst.size_req != 4)
11999 /* Insn may have a 16-bit form. */
12000 Rn = inst.operands[1].reg;
12001 if (inst.operands[1].immisreg)
12003 inst.instruction = THUMB_OP16 (opcode);
12004 /* [Rn, Rik] */
12005 if (Rn <= 7 && inst.operands[1].imm <= 7)
12006 goto op16;
12007 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12008 reject_bad_reg (inst.operands[1].imm);
12010 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12011 && opcode != T_MNEM_ldrsb)
12012 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12013 || (Rn == REG_SP && opcode == T_MNEM_str))
12015 /* [Rn, #const] */
12016 if (Rn > 7)
12018 if (Rn == REG_PC)
12020 if (inst.relocs[0].pc_rel)
12021 opcode = T_MNEM_ldr_pc2;
12022 else
12023 opcode = T_MNEM_ldr_pc;
12025 else
12027 if (opcode == T_MNEM_ldr)
12028 opcode = T_MNEM_ldr_sp;
12029 else
12030 opcode = T_MNEM_str_sp;
12032 inst.instruction = inst.operands[0].reg << 8;
12034 else
12036 inst.instruction = inst.operands[0].reg;
12037 inst.instruction |= inst.operands[1].reg << 3;
12039 inst.instruction |= THUMB_OP16 (opcode);
12040 if (inst.size_req == 2)
12041 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12042 else
12043 inst.relax = opcode;
12044 return;
12047 /* Definitely a 32-bit variant. */
12049 /* Warning for Erratum 752419. */
12050 if (opcode == T_MNEM_ldr
12051 && inst.operands[0].reg == REG_SP
12052 && inst.operands[1].writeback == 1
12053 && !inst.operands[1].immisreg)
12055 if (no_cpu_selected ()
12056 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12057 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12058 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12059 as_warn (_("This instruction may be unpredictable "
12060 "if executed on M-profile cores "
12061 "with interrupts enabled."));
12064 /* Do some validations regarding addressing modes. */
12065 if (inst.operands[1].immisreg)
12066 reject_bad_reg (inst.operands[1].imm);
12068 constraint (inst.operands[1].writeback == 1
12069 && inst.operands[0].reg == inst.operands[1].reg,
12070 BAD_OVERLAP);
12072 inst.instruction = THUMB_OP32 (opcode);
12073 inst.instruction |= inst.operands[0].reg << 12;
12074 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
12075 check_ldr_r15_aligned ();
12076 return;
12079 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12081 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12083 /* Only [Rn,Rm] is acceptable. */
12084 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12085 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12086 || inst.operands[1].postind || inst.operands[1].shifted
12087 || inst.operands[1].negative,
12088 _("Thumb does not support this addressing mode"));
12089 inst.instruction = THUMB_OP16 (inst.instruction);
12090 goto op16;
12093 inst.instruction = THUMB_OP16 (inst.instruction);
12094 if (!inst.operands[1].isreg)
12095 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12096 return;
12098 constraint (!inst.operands[1].preind
12099 || inst.operands[1].shifted
12100 || inst.operands[1].writeback,
12101 _("Thumb does not support this addressing mode"));
12102 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12104 constraint (inst.instruction & 0x0600,
12105 _("byte or halfword not valid for base register"));
12106 constraint (inst.operands[1].reg == REG_PC
12107 && !(inst.instruction & THUMB_LOAD_BIT),
12108 _("r15 based store not allowed"));
12109 constraint (inst.operands[1].immisreg,
12110 _("invalid base register for register offset"));
12112 if (inst.operands[1].reg == REG_PC)
12113 inst.instruction = T_OPCODE_LDR_PC;
12114 else if (inst.instruction & THUMB_LOAD_BIT)
12115 inst.instruction = T_OPCODE_LDR_SP;
12116 else
12117 inst.instruction = T_OPCODE_STR_SP;
12119 inst.instruction |= inst.operands[0].reg << 8;
12120 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12121 return;
12124 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12125 if (!inst.operands[1].immisreg)
12127 /* Immediate offset. */
12128 inst.instruction |= inst.operands[0].reg;
12129 inst.instruction |= inst.operands[1].reg << 3;
12130 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12131 return;
12134 /* Register offset. */
12135 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12136 constraint (inst.operands[1].negative,
12137 _("Thumb does not support this addressing mode"));
12139 op16:
12140 switch (inst.instruction)
12142 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12143 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12144 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12145 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12146 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12147 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12148 case 0x5600 /* ldrsb */:
12149 case 0x5e00 /* ldrsh */: break;
12150 default: abort ();
12153 inst.instruction |= inst.operands[0].reg;
12154 inst.instruction |= inst.operands[1].reg << 3;
12155 inst.instruction |= inst.operands[1].imm << 6;
12158 static void
12159 do_t_ldstd (void)
12161 if (!inst.operands[1].present)
12163 inst.operands[1].reg = inst.operands[0].reg + 1;
12164 constraint (inst.operands[0].reg == REG_LR,
12165 _("r14 not allowed here"));
12166 constraint (inst.operands[0].reg == REG_R12,
12167 _("r12 not allowed here"));
12170 if (inst.operands[2].writeback
12171 && (inst.operands[0].reg == inst.operands[2].reg
12172 || inst.operands[1].reg == inst.operands[2].reg))
12173 as_warn (_("base register written back, and overlaps "
12174 "one of transfer registers"));
12176 inst.instruction |= inst.operands[0].reg << 12;
12177 inst.instruction |= inst.operands[1].reg << 8;
12178 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
12181 static void
12182 do_t_ldstt (void)
12184 inst.instruction |= inst.operands[0].reg << 12;
12185 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12188 static void
12189 do_t_mla (void)
12191 unsigned Rd, Rn, Rm, Ra;
12193 Rd = inst.operands[0].reg;
12194 Rn = inst.operands[1].reg;
12195 Rm = inst.operands[2].reg;
12196 Ra = inst.operands[3].reg;
12198 reject_bad_reg (Rd);
12199 reject_bad_reg (Rn);
12200 reject_bad_reg (Rm);
12201 reject_bad_reg (Ra);
12203 inst.instruction |= Rd << 8;
12204 inst.instruction |= Rn << 16;
12205 inst.instruction |= Rm;
12206 inst.instruction |= Ra << 12;
12209 static void
12210 do_t_mlal (void)
12212 unsigned RdLo, RdHi, Rn, Rm;
12214 RdLo = inst.operands[0].reg;
12215 RdHi = inst.operands[1].reg;
12216 Rn = inst.operands[2].reg;
12217 Rm = inst.operands[3].reg;
12219 reject_bad_reg (RdLo);
12220 reject_bad_reg (RdHi);
12221 reject_bad_reg (Rn);
12222 reject_bad_reg (Rm);
12224 inst.instruction |= RdLo << 12;
12225 inst.instruction |= RdHi << 8;
12226 inst.instruction |= Rn << 16;
12227 inst.instruction |= Rm;
12230 static void
12231 do_t_mov_cmp (void)
12233 unsigned Rn, Rm;
12235 Rn = inst.operands[0].reg;
12236 Rm = inst.operands[1].reg;
12238 if (Rn == REG_PC)
12239 set_pred_insn_type_last ();
12241 if (unified_syntax)
12243 int r0off = (inst.instruction == T_MNEM_mov
12244 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12245 unsigned long opcode;
12246 bfd_boolean narrow;
12247 bfd_boolean low_regs;
12249 low_regs = (Rn <= 7 && Rm <= 7);
12250 opcode = inst.instruction;
12251 if (in_pred_block ())
12252 narrow = opcode != T_MNEM_movs;
12253 else
12254 narrow = opcode != T_MNEM_movs || low_regs;
12255 if (inst.size_req == 4
12256 || inst.operands[1].shifted)
12257 narrow = FALSE;
12259 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12260 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12261 && !inst.operands[1].shifted
12262 && Rn == REG_PC
12263 && Rm == REG_LR)
12265 inst.instruction = T2_SUBS_PC_LR;
12266 return;
12269 if (opcode == T_MNEM_cmp)
12271 constraint (Rn == REG_PC, BAD_PC);
12272 if (narrow)
12274 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12275 but valid. */
12276 warn_deprecated_sp (Rm);
12277 /* R15 was documented as a valid choice for Rm in ARMv6,
12278 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12279 tools reject R15, so we do too. */
12280 constraint (Rm == REG_PC, BAD_PC);
12282 else
12283 reject_bad_reg (Rm);
12285 else if (opcode == T_MNEM_mov
12286 || opcode == T_MNEM_movs)
12288 if (inst.operands[1].isreg)
12290 if (opcode == T_MNEM_movs)
12292 reject_bad_reg (Rn);
12293 reject_bad_reg (Rm);
12295 else if (narrow)
12297 /* This is mov.n. */
12298 if ((Rn == REG_SP || Rn == REG_PC)
12299 && (Rm == REG_SP || Rm == REG_PC))
12301 as_tsktsk (_("Use of r%u as a source register is "
12302 "deprecated when r%u is the destination "
12303 "register."), Rm, Rn);
12306 else
12308 /* This is mov.w. */
12309 constraint (Rn == REG_PC, BAD_PC);
12310 constraint (Rm == REG_PC, BAD_PC);
12311 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12312 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
12315 else
12316 reject_bad_reg (Rn);
12319 if (!inst.operands[1].isreg)
12321 /* Immediate operand. */
12322 if (!in_pred_block () && opcode == T_MNEM_mov)
12323 narrow = 0;
12324 if (low_regs && narrow)
12326 inst.instruction = THUMB_OP16 (opcode);
12327 inst.instruction |= Rn << 8;
12328 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12329 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
12331 if (inst.size_req == 2)
12332 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12333 else
12334 inst.relax = opcode;
12337 else
12339 constraint ((inst.relocs[0].type
12340 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12341 && (inst.relocs[0].type
12342 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
12343 THUMB1_RELOC_ONLY);
12345 inst.instruction = THUMB_OP32 (inst.instruction);
12346 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12347 inst.instruction |= Rn << r0off;
12348 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12351 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12352 && (inst.instruction == T_MNEM_mov
12353 || inst.instruction == T_MNEM_movs))
12355 /* Register shifts are encoded as separate shift instructions. */
12356 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12358 if (in_pred_block ())
12359 narrow = !flags;
12360 else
12361 narrow = flags;
12363 if (inst.size_req == 4)
12364 narrow = FALSE;
12366 if (!low_regs || inst.operands[1].imm > 7)
12367 narrow = FALSE;
12369 if (Rn != Rm)
12370 narrow = FALSE;
12372 switch (inst.operands[1].shift_kind)
12374 case SHIFT_LSL:
12375 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12376 break;
12377 case SHIFT_ASR:
12378 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12379 break;
12380 case SHIFT_LSR:
12381 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12382 break;
12383 case SHIFT_ROR:
12384 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12385 break;
12386 default:
12387 abort ();
12390 inst.instruction = opcode;
12391 if (narrow)
12393 inst.instruction |= Rn;
12394 inst.instruction |= inst.operands[1].imm << 3;
12396 else
12398 if (flags)
12399 inst.instruction |= CONDS_BIT;
12401 inst.instruction |= Rn << 8;
12402 inst.instruction |= Rm << 16;
12403 inst.instruction |= inst.operands[1].imm;
12406 else if (!narrow)
12408 /* Some mov with immediate shift have narrow variants.
12409 Register shifts are handled above. */
12410 if (low_regs && inst.operands[1].shifted
12411 && (inst.instruction == T_MNEM_mov
12412 || inst.instruction == T_MNEM_movs))
12414 if (in_pred_block ())
12415 narrow = (inst.instruction == T_MNEM_mov);
12416 else
12417 narrow = (inst.instruction == T_MNEM_movs);
12420 if (narrow)
12422 switch (inst.operands[1].shift_kind)
12424 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12425 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12426 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12427 default: narrow = FALSE; break;
12431 if (narrow)
12433 inst.instruction |= Rn;
12434 inst.instruction |= Rm << 3;
12435 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
12437 else
12439 inst.instruction = THUMB_OP32 (inst.instruction);
12440 inst.instruction |= Rn << r0off;
12441 encode_thumb32_shifted_operand (1);
12444 else
12445 switch (inst.instruction)
12447 case T_MNEM_mov:
12448 /* In v4t or v5t a move of two lowregs produces unpredictable
12449 results. Don't allow this. */
12450 if (low_regs)
12452 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12453 "MOV Rd, Rs with two low registers is not "
12454 "permitted on this architecture");
12455 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
12456 arm_ext_v6);
12459 inst.instruction = T_OPCODE_MOV_HR;
12460 inst.instruction |= (Rn & 0x8) << 4;
12461 inst.instruction |= (Rn & 0x7);
12462 inst.instruction |= Rm << 3;
12463 break;
12465 case T_MNEM_movs:
12466 /* We know we have low registers at this point.
12467 Generate LSLS Rd, Rs, #0. */
12468 inst.instruction = T_OPCODE_LSL_I;
12469 inst.instruction |= Rn;
12470 inst.instruction |= Rm << 3;
12471 break;
12473 case T_MNEM_cmp:
12474 if (low_regs)
12476 inst.instruction = T_OPCODE_CMP_LR;
12477 inst.instruction |= Rn;
12478 inst.instruction |= Rm << 3;
12480 else
12482 inst.instruction = T_OPCODE_CMP_HR;
12483 inst.instruction |= (Rn & 0x8) << 4;
12484 inst.instruction |= (Rn & 0x7);
12485 inst.instruction |= Rm << 3;
12487 break;
12489 return;
12492 inst.instruction = THUMB_OP16 (inst.instruction);
12494 /* PR 10443: Do not silently ignore shifted operands. */
12495 constraint (inst.operands[1].shifted,
12496 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12498 if (inst.operands[1].isreg)
12500 if (Rn < 8 && Rm < 8)
12502 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12503 since a MOV instruction produces unpredictable results. */
12504 if (inst.instruction == T_OPCODE_MOV_I8)
12505 inst.instruction = T_OPCODE_ADD_I3;
12506 else
12507 inst.instruction = T_OPCODE_CMP_LR;
12509 inst.instruction |= Rn;
12510 inst.instruction |= Rm << 3;
12512 else
12514 if (inst.instruction == T_OPCODE_MOV_I8)
12515 inst.instruction = T_OPCODE_MOV_HR;
12516 else
12517 inst.instruction = T_OPCODE_CMP_HR;
12518 do_t_cpy ();
12521 else
12523 constraint (Rn > 7,
12524 _("only lo regs allowed with immediate"));
12525 inst.instruction |= Rn << 8;
12526 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12530 static void
12531 do_t_mov16 (void)
12533 unsigned Rd;
12534 bfd_vma imm;
12535 bfd_boolean top;
12537 top = (inst.instruction & 0x00800000) != 0;
12538 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
12540 constraint (top, _(":lower16: not allowed in this instruction"));
12541 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
12543 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
12545 constraint (!top, _(":upper16: not allowed in this instruction"));
12546 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
12549 Rd = inst.operands[0].reg;
12550 reject_bad_reg (Rd);
12552 inst.instruction |= Rd << 8;
12553 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
12555 imm = inst.relocs[0].exp.X_add_number;
12556 inst.instruction |= (imm & 0xf000) << 4;
12557 inst.instruction |= (imm & 0x0800) << 15;
12558 inst.instruction |= (imm & 0x0700) << 4;
12559 inst.instruction |= (imm & 0x00ff);
12563 static void
12564 do_t_mvn_tst (void)
12566 unsigned Rn, Rm;
12568 Rn = inst.operands[0].reg;
12569 Rm = inst.operands[1].reg;
12571 if (inst.instruction == T_MNEM_cmp
12572 || inst.instruction == T_MNEM_cmn)
12573 constraint (Rn == REG_PC, BAD_PC);
12574 else
12575 reject_bad_reg (Rn);
12576 reject_bad_reg (Rm);
12578 if (unified_syntax)
12580 int r0off = (inst.instruction == T_MNEM_mvn
12581 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
12582 bfd_boolean narrow;
12584 if (inst.size_req == 4
12585 || inst.instruction > 0xffff
12586 || inst.operands[1].shifted
12587 || Rn > 7 || Rm > 7)
12588 narrow = FALSE;
12589 else if (inst.instruction == T_MNEM_cmn
12590 || inst.instruction == T_MNEM_tst)
12591 narrow = TRUE;
12592 else if (THUMB_SETS_FLAGS (inst.instruction))
12593 narrow = !in_pred_block ();
12594 else
12595 narrow = in_pred_block ();
12597 if (!inst.operands[1].isreg)
12599 /* For an immediate, we always generate a 32-bit opcode;
12600 section relaxation will shrink it later if possible. */
12601 if (inst.instruction < 0xffff)
12602 inst.instruction = THUMB_OP32 (inst.instruction);
12603 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12604 inst.instruction |= Rn << r0off;
12605 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12607 else
12609 /* See if we can do this with a 16-bit instruction. */
12610 if (narrow)
12612 inst.instruction = THUMB_OP16 (inst.instruction);
12613 inst.instruction |= Rn;
12614 inst.instruction |= Rm << 3;
12616 else
12618 constraint (inst.operands[1].shifted
12619 && inst.operands[1].immisreg,
12620 _("shift must be constant"));
12621 if (inst.instruction < 0xffff)
12622 inst.instruction = THUMB_OP32 (inst.instruction);
12623 inst.instruction |= Rn << r0off;
12624 encode_thumb32_shifted_operand (1);
12628 else
12630 constraint (inst.instruction > 0xffff
12631 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12632 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12633 _("unshifted register required"));
12634 constraint (Rn > 7 || Rm > 7,
12635 BAD_HIREG);
12637 inst.instruction = THUMB_OP16 (inst.instruction);
12638 inst.instruction |= Rn;
12639 inst.instruction |= Rm << 3;
12643 static void
12644 do_t_mrs (void)
12646 unsigned Rd;
12648 if (do_vfp_nsyn_mrs () == SUCCESS)
12649 return;
12651 Rd = inst.operands[0].reg;
12652 reject_bad_reg (Rd);
12653 inst.instruction |= Rd << 8;
12655 if (inst.operands[1].isreg)
12657 unsigned br = inst.operands[1].reg;
12658 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12659 as_bad (_("bad register for mrs"));
12661 inst.instruction |= br & (0xf << 16);
12662 inst.instruction |= (br & 0x300) >> 4;
12663 inst.instruction |= (br & SPSR_BIT) >> 2;
12665 else
12667 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12669 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12671 /* PR gas/12698: The constraint is only applied for m_profile.
12672 If the user has specified -march=all, we want to ignore it as
12673 we are building for any CPU type, including non-m variants. */
12674 bfd_boolean m_profile =
12675 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12676 constraint ((flags != 0) && m_profile, _("selected processor does "
12677 "not support requested special purpose register"));
12679 else
12680 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12681 devices). */
12682 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12683 _("'APSR', 'CPSR' or 'SPSR' expected"));
12685 inst.instruction |= (flags & SPSR_BIT) >> 2;
12686 inst.instruction |= inst.operands[1].imm & 0xff;
12687 inst.instruction |= 0xf0000;
12691 static void
12692 do_t_msr (void)
12694 int flags;
12695 unsigned Rn;
12697 if (do_vfp_nsyn_msr () == SUCCESS)
12698 return;
12700 constraint (!inst.operands[1].isreg,
12701 _("Thumb encoding does not support an immediate here"));
12703 if (inst.operands[0].isreg)
12704 flags = (int)(inst.operands[0].reg);
12705 else
12706 flags = inst.operands[0].imm;
12708 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12710 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12712 /* PR gas/12698: The constraint is only applied for m_profile.
12713 If the user has specified -march=all, we want to ignore it as
12714 we are building for any CPU type, including non-m variants. */
12715 bfd_boolean m_profile =
12716 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12717 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12718 && (bits & ~(PSR_s | PSR_f)) != 0)
12719 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12720 && bits != PSR_f)) && m_profile,
12721 _("selected processor does not support requested special "
12722 "purpose register"));
12724 else
12725 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12726 "requested special purpose register"));
12728 Rn = inst.operands[1].reg;
12729 reject_bad_reg (Rn);
12731 inst.instruction |= (flags & SPSR_BIT) >> 2;
12732 inst.instruction |= (flags & 0xf0000) >> 8;
12733 inst.instruction |= (flags & 0x300) >> 4;
12734 inst.instruction |= (flags & 0xff);
12735 inst.instruction |= Rn << 16;
12738 static void
12739 do_t_mul (void)
12741 bfd_boolean narrow;
12742 unsigned Rd, Rn, Rm;
12744 if (!inst.operands[2].present)
12745 inst.operands[2].reg = inst.operands[0].reg;
12747 Rd = inst.operands[0].reg;
12748 Rn = inst.operands[1].reg;
12749 Rm = inst.operands[2].reg;
12751 if (unified_syntax)
12753 if (inst.size_req == 4
12754 || (Rd != Rn
12755 && Rd != Rm)
12756 || Rn > 7
12757 || Rm > 7)
12758 narrow = FALSE;
12759 else if (inst.instruction == T_MNEM_muls)
12760 narrow = !in_pred_block ();
12761 else
12762 narrow = in_pred_block ();
12764 else
12766 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
12767 constraint (Rn > 7 || Rm > 7,
12768 BAD_HIREG);
12769 narrow = TRUE;
12772 if (narrow)
12774 /* 16-bit MULS/Conditional MUL. */
12775 inst.instruction = THUMB_OP16 (inst.instruction);
12776 inst.instruction |= Rd;
12778 if (Rd == Rn)
12779 inst.instruction |= Rm << 3;
12780 else if (Rd == Rm)
12781 inst.instruction |= Rn << 3;
12782 else
12783 constraint (1, _("dest must overlap one source register"));
12785 else
12787 constraint (inst.instruction != T_MNEM_mul,
12788 _("Thumb-2 MUL must not set flags"));
12789 /* 32-bit MUL. */
12790 inst.instruction = THUMB_OP32 (inst.instruction);
12791 inst.instruction |= Rd << 8;
12792 inst.instruction |= Rn << 16;
12793 inst.instruction |= Rm << 0;
12795 reject_bad_reg (Rd);
12796 reject_bad_reg (Rn);
12797 reject_bad_reg (Rm);
12801 static void
12802 do_t_mull (void)
12804 unsigned RdLo, RdHi, Rn, Rm;
12806 RdLo = inst.operands[0].reg;
12807 RdHi = inst.operands[1].reg;
12808 Rn = inst.operands[2].reg;
12809 Rm = inst.operands[3].reg;
12811 reject_bad_reg (RdLo);
12812 reject_bad_reg (RdHi);
12813 reject_bad_reg (Rn);
12814 reject_bad_reg (Rm);
12816 inst.instruction |= RdLo << 12;
12817 inst.instruction |= RdHi << 8;
12818 inst.instruction |= Rn << 16;
12819 inst.instruction |= Rm;
12821 if (RdLo == RdHi)
12822 as_tsktsk (_("rdhi and rdlo must be different"));
12825 static void
12826 do_t_nop (void)
12828 set_pred_insn_type (NEUTRAL_IT_INSN);
12830 if (unified_syntax)
12832 if (inst.size_req == 4 || inst.operands[0].imm > 15)
12834 inst.instruction = THUMB_OP32 (inst.instruction);
12835 inst.instruction |= inst.operands[0].imm;
12837 else
12839 /* PR9722: Check for Thumb2 availability before
12840 generating a thumb2 nop instruction. */
12841 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
12843 inst.instruction = THUMB_OP16 (inst.instruction);
12844 inst.instruction |= inst.operands[0].imm << 4;
12846 else
12847 inst.instruction = 0x46c0;
12850 else
12852 constraint (inst.operands[0].present,
12853 _("Thumb does not support NOP with hints"));
12854 inst.instruction = 0x46c0;
12858 static void
12859 do_t_neg (void)
12861 if (unified_syntax)
12863 bfd_boolean narrow;
12865 if (THUMB_SETS_FLAGS (inst.instruction))
12866 narrow = !in_pred_block ();
12867 else
12868 narrow = in_pred_block ();
12869 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12870 narrow = FALSE;
12871 if (inst.size_req == 4)
12872 narrow = FALSE;
12874 if (!narrow)
12876 inst.instruction = THUMB_OP32 (inst.instruction);
12877 inst.instruction |= inst.operands[0].reg << 8;
12878 inst.instruction |= inst.operands[1].reg << 16;
12880 else
12882 inst.instruction = THUMB_OP16 (inst.instruction);
12883 inst.instruction |= inst.operands[0].reg;
12884 inst.instruction |= inst.operands[1].reg << 3;
12887 else
12889 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12890 BAD_HIREG);
12891 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12893 inst.instruction = THUMB_OP16 (inst.instruction);
12894 inst.instruction |= inst.operands[0].reg;
12895 inst.instruction |= inst.operands[1].reg << 3;
12899 static void
12900 do_t_orn (void)
12902 unsigned Rd, Rn;
12904 Rd = inst.operands[0].reg;
12905 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12907 reject_bad_reg (Rd);
12908 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12909 reject_bad_reg (Rn);
12911 inst.instruction |= Rd << 8;
12912 inst.instruction |= Rn << 16;
12914 if (!inst.operands[2].isreg)
12916 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12917 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12919 else
12921 unsigned Rm;
12923 Rm = inst.operands[2].reg;
12924 reject_bad_reg (Rm);
12926 constraint (inst.operands[2].shifted
12927 && inst.operands[2].immisreg,
12928 _("shift must be constant"));
12929 encode_thumb32_shifted_operand (2);
12933 static void
12934 do_t_pkhbt (void)
12936 unsigned Rd, Rn, Rm;
12938 Rd = inst.operands[0].reg;
12939 Rn = inst.operands[1].reg;
12940 Rm = inst.operands[2].reg;
12942 reject_bad_reg (Rd);
12943 reject_bad_reg (Rn);
12944 reject_bad_reg (Rm);
12946 inst.instruction |= Rd << 8;
12947 inst.instruction |= Rn << 16;
12948 inst.instruction |= Rm;
12949 if (inst.operands[3].present)
12951 unsigned int val = inst.relocs[0].exp.X_add_number;
12952 constraint (inst.relocs[0].exp.X_op != O_constant,
12953 _("expression too complex"));
12954 inst.instruction |= (val & 0x1c) << 10;
12955 inst.instruction |= (val & 0x03) << 6;
12959 static void
12960 do_t_pkhtb (void)
12962 if (!inst.operands[3].present)
12964 unsigned Rtmp;
12966 inst.instruction &= ~0x00000020;
12968 /* PR 10168. Swap the Rm and Rn registers. */
12969 Rtmp = inst.operands[1].reg;
12970 inst.operands[1].reg = inst.operands[2].reg;
12971 inst.operands[2].reg = Rtmp;
12973 do_t_pkhbt ();
12976 static void
12977 do_t_pld (void)
12979 if (inst.operands[0].immisreg)
12980 reject_bad_reg (inst.operands[0].imm);
12982 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12985 static void
12986 do_t_push_pop (void)
12988 unsigned mask;
12990 constraint (inst.operands[0].writeback,
12991 _("push/pop do not support {reglist}^"));
12992 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12993 _("expression too complex"));
12995 mask = inst.operands[0].imm;
12996 if (inst.size_req != 4 && (mask & ~0xff) == 0)
12997 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
12998 else if (inst.size_req != 4
12999 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13000 ? REG_LR : REG_PC)))
13002 inst.instruction = THUMB_OP16 (inst.instruction);
13003 inst.instruction |= THUMB_PP_PC_LR;
13004 inst.instruction |= mask & 0xff;
13006 else if (unified_syntax)
13008 inst.instruction = THUMB_OP32 (inst.instruction);
13009 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13011 else
13013 inst.error = _("invalid register list to push/pop instruction");
13014 return;
13018 static void
13019 do_t_clrm (void)
13021 if (unified_syntax)
13022 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
13023 else
13025 inst.error = _("invalid register list to push/pop instruction");
13026 return;
13030 static void
13031 do_t_vscclrm (void)
13033 if (inst.operands[0].issingle)
13035 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13036 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13037 inst.instruction |= inst.operands[0].imm;
13039 else
13041 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13042 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13043 inst.instruction |= 1 << 8;
13044 inst.instruction |= inst.operands[0].imm << 1;
13048 static void
13049 do_t_rbit (void)
13051 unsigned Rd, Rm;
13053 Rd = inst.operands[0].reg;
13054 Rm = inst.operands[1].reg;
13056 reject_bad_reg (Rd);
13057 reject_bad_reg (Rm);
13059 inst.instruction |= Rd << 8;
13060 inst.instruction |= Rm << 16;
13061 inst.instruction |= Rm;
13064 static void
13065 do_t_rev (void)
13067 unsigned Rd, Rm;
13069 Rd = inst.operands[0].reg;
13070 Rm = inst.operands[1].reg;
13072 reject_bad_reg (Rd);
13073 reject_bad_reg (Rm);
13075 if (Rd <= 7 && Rm <= 7
13076 && inst.size_req != 4)
13078 inst.instruction = THUMB_OP16 (inst.instruction);
13079 inst.instruction |= Rd;
13080 inst.instruction |= Rm << 3;
13082 else if (unified_syntax)
13084 inst.instruction = THUMB_OP32 (inst.instruction);
13085 inst.instruction |= Rd << 8;
13086 inst.instruction |= Rm << 16;
13087 inst.instruction |= Rm;
13089 else
13090 inst.error = BAD_HIREG;
13093 static void
13094 do_t_rrx (void)
13096 unsigned Rd, Rm;
13098 Rd = inst.operands[0].reg;
13099 Rm = inst.operands[1].reg;
13101 reject_bad_reg (Rd);
13102 reject_bad_reg (Rm);
13104 inst.instruction |= Rd << 8;
13105 inst.instruction |= Rm;
13108 static void
13109 do_t_rsb (void)
13111 unsigned Rd, Rs;
13113 Rd = inst.operands[0].reg;
13114 Rs = (inst.operands[1].present
13115 ? inst.operands[1].reg /* Rd, Rs, foo */
13116 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13118 reject_bad_reg (Rd);
13119 reject_bad_reg (Rs);
13120 if (inst.operands[2].isreg)
13121 reject_bad_reg (inst.operands[2].reg);
13123 inst.instruction |= Rd << 8;
13124 inst.instruction |= Rs << 16;
13125 if (!inst.operands[2].isreg)
13127 bfd_boolean narrow;
13129 if ((inst.instruction & 0x00100000) != 0)
13130 narrow = !in_pred_block ();
13131 else
13132 narrow = in_pred_block ();
13134 if (Rd > 7 || Rs > 7)
13135 narrow = FALSE;
13137 if (inst.size_req == 4 || !unified_syntax)
13138 narrow = FALSE;
13140 if (inst.relocs[0].exp.X_op != O_constant
13141 || inst.relocs[0].exp.X_add_number != 0)
13142 narrow = FALSE;
13144 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13145 relaxation, but it doesn't seem worth the hassle. */
13146 if (narrow)
13148 inst.relocs[0].type = BFD_RELOC_UNUSED;
13149 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13150 inst.instruction |= Rs << 3;
13151 inst.instruction |= Rd;
13153 else
13155 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13156 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13159 else
13160 encode_thumb32_shifted_operand (2);
13163 static void
13164 do_t_setend (void)
13166 if (warn_on_deprecated
13167 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13168 as_tsktsk (_("setend use is deprecated for ARMv8"));
13170 set_pred_insn_type (OUTSIDE_PRED_INSN);
13171 if (inst.operands[0].imm)
13172 inst.instruction |= 0x8;
13175 static void
13176 do_t_shift (void)
13178 if (!inst.operands[1].present)
13179 inst.operands[1].reg = inst.operands[0].reg;
13181 if (unified_syntax)
13183 bfd_boolean narrow;
13184 int shift_kind;
13186 switch (inst.instruction)
13188 case T_MNEM_asr:
13189 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13190 case T_MNEM_lsl:
13191 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13192 case T_MNEM_lsr:
13193 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13194 case T_MNEM_ror:
13195 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13196 default: abort ();
13199 if (THUMB_SETS_FLAGS (inst.instruction))
13200 narrow = !in_pred_block ();
13201 else
13202 narrow = in_pred_block ();
13203 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13204 narrow = FALSE;
13205 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13206 narrow = FALSE;
13207 if (inst.operands[2].isreg
13208 && (inst.operands[1].reg != inst.operands[0].reg
13209 || inst.operands[2].reg > 7))
13210 narrow = FALSE;
13211 if (inst.size_req == 4)
13212 narrow = FALSE;
13214 reject_bad_reg (inst.operands[0].reg);
13215 reject_bad_reg (inst.operands[1].reg);
13217 if (!narrow)
13219 if (inst.operands[2].isreg)
13221 reject_bad_reg (inst.operands[2].reg);
13222 inst.instruction = THUMB_OP32 (inst.instruction);
13223 inst.instruction |= inst.operands[0].reg << 8;
13224 inst.instruction |= inst.operands[1].reg << 16;
13225 inst.instruction |= inst.operands[2].reg;
13227 /* PR 12854: Error on extraneous shifts. */
13228 constraint (inst.operands[2].shifted,
13229 _("extraneous shift as part of operand to shift insn"));
13231 else
13233 inst.operands[1].shifted = 1;
13234 inst.operands[1].shift_kind = shift_kind;
13235 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13236 ? T_MNEM_movs : T_MNEM_mov);
13237 inst.instruction |= inst.operands[0].reg << 8;
13238 encode_thumb32_shifted_operand (1);
13239 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13240 inst.relocs[0].type = BFD_RELOC_UNUSED;
13243 else
13245 if (inst.operands[2].isreg)
13247 switch (shift_kind)
13249 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13250 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13251 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13252 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13253 default: abort ();
13256 inst.instruction |= inst.operands[0].reg;
13257 inst.instruction |= inst.operands[2].reg << 3;
13259 /* PR 12854: Error on extraneous shifts. */
13260 constraint (inst.operands[2].shifted,
13261 _("extraneous shift as part of operand to shift insn"));
13263 else
13265 switch (shift_kind)
13267 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13268 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13269 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13270 default: abort ();
13272 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13273 inst.instruction |= inst.operands[0].reg;
13274 inst.instruction |= inst.operands[1].reg << 3;
13278 else
13280 constraint (inst.operands[0].reg > 7
13281 || inst.operands[1].reg > 7, BAD_HIREG);
13282 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13284 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13286 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13287 constraint (inst.operands[0].reg != inst.operands[1].reg,
13288 _("source1 and dest must be same register"));
13290 switch (inst.instruction)
13292 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13293 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13294 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13295 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13296 default: abort ();
13299 inst.instruction |= inst.operands[0].reg;
13300 inst.instruction |= inst.operands[2].reg << 3;
13302 /* PR 12854: Error on extraneous shifts. */
13303 constraint (inst.operands[2].shifted,
13304 _("extraneous shift as part of operand to shift insn"));
13306 else
13308 switch (inst.instruction)
13310 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13311 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13312 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13313 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13314 default: abort ();
13316 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13317 inst.instruction |= inst.operands[0].reg;
13318 inst.instruction |= inst.operands[1].reg << 3;
13323 static void
13324 do_t_simd (void)
13326 unsigned Rd, Rn, Rm;
13328 Rd = inst.operands[0].reg;
13329 Rn = inst.operands[1].reg;
13330 Rm = inst.operands[2].reg;
13332 reject_bad_reg (Rd);
13333 reject_bad_reg (Rn);
13334 reject_bad_reg (Rm);
13336 inst.instruction |= Rd << 8;
13337 inst.instruction |= Rn << 16;
13338 inst.instruction |= Rm;
13341 static void
13342 do_t_simd2 (void)
13344 unsigned Rd, Rn, Rm;
13346 Rd = inst.operands[0].reg;
13347 Rm = inst.operands[1].reg;
13348 Rn = inst.operands[2].reg;
13350 reject_bad_reg (Rd);
13351 reject_bad_reg (Rn);
13352 reject_bad_reg (Rm);
13354 inst.instruction |= Rd << 8;
13355 inst.instruction |= Rn << 16;
13356 inst.instruction |= Rm;
13359 static void
13360 do_t_smc (void)
13362 unsigned int value = inst.relocs[0].exp.X_add_number;
13363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13364 _("SMC is not permitted on this architecture"));
13365 constraint (inst.relocs[0].exp.X_op != O_constant,
13366 _("expression too complex"));
13367 inst.relocs[0].type = BFD_RELOC_UNUSED;
13368 inst.instruction |= (value & 0xf000) >> 12;
13369 inst.instruction |= (value & 0x0ff0);
13370 inst.instruction |= (value & 0x000f) << 16;
13371 /* PR gas/15623: SMC instructions must be last in an IT block. */
13372 set_pred_insn_type_last ();
13375 static void
13376 do_t_hvc (void)
13378 unsigned int value = inst.relocs[0].exp.X_add_number;
13380 inst.relocs[0].type = BFD_RELOC_UNUSED;
13381 inst.instruction |= (value & 0x0fff);
13382 inst.instruction |= (value & 0xf000) << 4;
13385 static void
13386 do_t_ssat_usat (int bias)
13388 unsigned Rd, Rn;
13390 Rd = inst.operands[0].reg;
13391 Rn = inst.operands[2].reg;
13393 reject_bad_reg (Rd);
13394 reject_bad_reg (Rn);
13396 inst.instruction |= Rd << 8;
13397 inst.instruction |= inst.operands[1].imm - bias;
13398 inst.instruction |= Rn << 16;
13400 if (inst.operands[3].present)
13402 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
13404 inst.relocs[0].type = BFD_RELOC_UNUSED;
13406 constraint (inst.relocs[0].exp.X_op != O_constant,
13407 _("expression too complex"));
13409 if (shift_amount != 0)
13411 constraint (shift_amount > 31,
13412 _("shift expression is too large"));
13414 if (inst.operands[3].shift_kind == SHIFT_ASR)
13415 inst.instruction |= 0x00200000; /* sh bit. */
13417 inst.instruction |= (shift_amount & 0x1c) << 10;
13418 inst.instruction |= (shift_amount & 0x03) << 6;
13423 static void
13424 do_t_ssat (void)
13426 do_t_ssat_usat (1);
13429 static void
13430 do_t_ssat16 (void)
13432 unsigned Rd, Rn;
13434 Rd = inst.operands[0].reg;
13435 Rn = inst.operands[2].reg;
13437 reject_bad_reg (Rd);
13438 reject_bad_reg (Rn);
13440 inst.instruction |= Rd << 8;
13441 inst.instruction |= inst.operands[1].imm - 1;
13442 inst.instruction |= Rn << 16;
13445 static void
13446 do_t_strex (void)
13448 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13449 || inst.operands[2].postind || inst.operands[2].writeback
13450 || inst.operands[2].immisreg || inst.operands[2].shifted
13451 || inst.operands[2].negative,
13452 BAD_ADDR_MODE);
13454 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13456 inst.instruction |= inst.operands[0].reg << 8;
13457 inst.instruction |= inst.operands[1].reg << 12;
13458 inst.instruction |= inst.operands[2].reg << 16;
13459 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
13462 static void
13463 do_t_strexd (void)
13465 if (!inst.operands[2].present)
13466 inst.operands[2].reg = inst.operands[1].reg + 1;
13468 constraint (inst.operands[0].reg == inst.operands[1].reg
13469 || inst.operands[0].reg == inst.operands[2].reg
13470 || inst.operands[0].reg == inst.operands[3].reg,
13471 BAD_OVERLAP);
13473 inst.instruction |= inst.operands[0].reg;
13474 inst.instruction |= inst.operands[1].reg << 12;
13475 inst.instruction |= inst.operands[2].reg << 8;
13476 inst.instruction |= inst.operands[3].reg << 16;
13479 static void
13480 do_t_sxtah (void)
13482 unsigned Rd, Rn, Rm;
13484 Rd = inst.operands[0].reg;
13485 Rn = inst.operands[1].reg;
13486 Rm = inst.operands[2].reg;
13488 reject_bad_reg (Rd);
13489 reject_bad_reg (Rn);
13490 reject_bad_reg (Rm);
13492 inst.instruction |= Rd << 8;
13493 inst.instruction |= Rn << 16;
13494 inst.instruction |= Rm;
13495 inst.instruction |= inst.operands[3].imm << 4;
13498 static void
13499 do_t_sxth (void)
13501 unsigned Rd, Rm;
13503 Rd = inst.operands[0].reg;
13504 Rm = inst.operands[1].reg;
13506 reject_bad_reg (Rd);
13507 reject_bad_reg (Rm);
13509 if (inst.instruction <= 0xffff
13510 && inst.size_req != 4
13511 && Rd <= 7 && Rm <= 7
13512 && (!inst.operands[2].present || inst.operands[2].imm == 0))
13514 inst.instruction = THUMB_OP16 (inst.instruction);
13515 inst.instruction |= Rd;
13516 inst.instruction |= Rm << 3;
13518 else if (unified_syntax)
13520 if (inst.instruction <= 0xffff)
13521 inst.instruction = THUMB_OP32 (inst.instruction);
13522 inst.instruction |= Rd << 8;
13523 inst.instruction |= Rm;
13524 inst.instruction |= inst.operands[2].imm << 4;
13526 else
13528 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13529 _("Thumb encoding does not support rotation"));
13530 constraint (1, BAD_HIREG);
13534 static void
13535 do_t_swi (void)
13537 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
13540 static void
13541 do_t_tb (void)
13543 unsigned Rn, Rm;
13544 int half;
13546 half = (inst.instruction & 0x10) != 0;
13547 set_pred_insn_type_last ();
13548 constraint (inst.operands[0].immisreg,
13549 _("instruction requires register index"));
13551 Rn = inst.operands[0].reg;
13552 Rm = inst.operands[0].imm;
13554 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13555 constraint (Rn == REG_SP, BAD_SP);
13556 reject_bad_reg (Rm);
13558 constraint (!half && inst.operands[0].shifted,
13559 _("instruction does not allow shifted index"));
13560 inst.instruction |= (Rn << 16) | Rm;
13563 static void
13564 do_t_udf (void)
13566 if (!inst.operands[0].present)
13567 inst.operands[0].imm = 0;
13569 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13571 constraint (inst.size_req == 2,
13572 _("immediate value out of range"));
13573 inst.instruction = THUMB_OP32 (inst.instruction);
13574 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13575 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13577 else
13579 inst.instruction = THUMB_OP16 (inst.instruction);
13580 inst.instruction |= inst.operands[0].imm;
13583 set_pred_insn_type (NEUTRAL_IT_INSN);
13587 static void
13588 do_t_usat (void)
13590 do_t_ssat_usat (0);
13593 static void
13594 do_t_usat16 (void)
13596 unsigned Rd, Rn;
13598 Rd = inst.operands[0].reg;
13599 Rn = inst.operands[2].reg;
13601 reject_bad_reg (Rd);
13602 reject_bad_reg (Rn);
13604 inst.instruction |= Rd << 8;
13605 inst.instruction |= inst.operands[1].imm;
13606 inst.instruction |= Rn << 16;
13609 /* Checking the range of the branch offset (VAL) with NBITS bits
13610 and IS_SIGNED signedness. Also checks the LSB to be 0. */
13611 static int
13612 v8_1_branch_value_check (int val, int nbits, int is_signed)
13614 gas_assert (nbits > 0 && nbits <= 32);
13615 if (is_signed)
13617 int cmp = (1 << (nbits - 1));
13618 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
13619 return FAIL;
13621 else
13623 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
13624 return FAIL;
13626 return SUCCESS;
13629 /* For branches in Armv8.1-M Mainline. */
13630 static void
13631 do_t_branch_future (void)
13633 unsigned long insn = inst.instruction;
13635 inst.instruction = THUMB_OP32 (inst.instruction);
13636 if (inst.operands[0].hasreloc == 0)
13638 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
13639 as_bad (BAD_BRANCH_OFF);
13641 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
13643 else
13645 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
13646 inst.relocs[0].pc_rel = 1;
13649 switch (insn)
13651 case T_MNEM_bf:
13652 if (inst.operands[1].hasreloc == 0)
13654 int val = inst.operands[1].imm;
13655 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
13656 as_bad (BAD_BRANCH_OFF);
13658 int immA = (val & 0x0001f000) >> 12;
13659 int immB = (val & 0x00000ffc) >> 2;
13660 int immC = (val & 0x00000002) >> 1;
13661 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13663 else
13665 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
13666 inst.relocs[1].pc_rel = 1;
13668 break;
13670 case T_MNEM_bfl:
13671 if (inst.operands[1].hasreloc == 0)
13673 int val = inst.operands[1].imm;
13674 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
13675 as_bad (BAD_BRANCH_OFF);
13677 int immA = (val & 0x0007f000) >> 12;
13678 int immB = (val & 0x00000ffc) >> 2;
13679 int immC = (val & 0x00000002) >> 1;
13680 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13682 else
13684 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
13685 inst.relocs[1].pc_rel = 1;
13687 break;
13689 case T_MNEM_bfcsel:
13690 /* Operand 1. */
13691 if (inst.operands[1].hasreloc == 0)
13693 int val = inst.operands[1].imm;
13694 int immA = (val & 0x00001000) >> 12;
13695 int immB = (val & 0x00000ffc) >> 2;
13696 int immC = (val & 0x00000002) >> 1;
13697 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
13699 else
13701 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
13702 inst.relocs[1].pc_rel = 1;
13705 /* Operand 2. */
13706 if (inst.operands[2].hasreloc == 0)
13708 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
13709 int val2 = inst.operands[2].imm;
13710 int val0 = inst.operands[0].imm & 0x1f;
13711 int diff = val2 - val0;
13712 if (diff == 4)
13713 inst.instruction |= 1 << 17; /* T bit. */
13714 else if (diff != 2)
13715 as_bad (_("out of range label-relative fixup value"));
13717 else
13719 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
13720 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
13721 inst.relocs[2].pc_rel = 1;
13724 /* Operand 3. */
13725 constraint (inst.cond != COND_ALWAYS, BAD_COND);
13726 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
13727 break;
13729 case T_MNEM_bfx:
13730 case T_MNEM_bflx:
13731 inst.instruction |= inst.operands[1].reg << 16;
13732 break;
13734 default: abort ();
13738 /* Helper function for do_t_loloop to handle relocations. */
13739 static void
13740 v8_1_loop_reloc (int is_le)
13742 if (inst.relocs[0].exp.X_op == O_constant)
13744 int value = inst.relocs[0].exp.X_add_number;
13745 value = (is_le) ? -value : value;
13747 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
13748 as_bad (BAD_BRANCH_OFF);
13750 int imml, immh;
13752 immh = (value & 0x00000ffc) >> 2;
13753 imml = (value & 0x00000002) >> 1;
13755 inst.instruction |= (imml << 11) | (immh << 1);
13757 else
13759 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
13760 inst.relocs[0].pc_rel = 1;
13764 /* To handle the Scalar Low Overhead Loop instructions
13765 in Armv8.1-M Mainline. */
13766 static void
13767 do_t_loloop (void)
13769 unsigned long insn = inst.instruction;
13771 set_pred_insn_type (OUTSIDE_PRED_INSN);
13772 inst.instruction = THUMB_OP32 (inst.instruction);
13774 switch (insn)
13776 case T_MNEM_le:
13777 /* le <label>. */
13778 if (!inst.operands[0].present)
13779 inst.instruction |= 1 << 21;
13781 v8_1_loop_reloc (TRUE);
13782 break;
13784 case T_MNEM_wls:
13785 v8_1_loop_reloc (FALSE);
13786 /* Fall through. */
13787 case T_MNEM_dls:
13788 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
13789 inst.instruction |= (inst.operands[1].reg << 16);
13790 break;
13792 default: abort();
13796 /* Neon instruction encoder helpers. */
13798 /* Encodings for the different types for various Neon opcodes. */
13800 /* An "invalid" code for the following tables. */
13801 #define N_INV -1u
13803 struct neon_tab_entry
13805 unsigned integer;
13806 unsigned float_or_poly;
13807 unsigned scalar_or_imm;
13810 /* Map overloaded Neon opcodes to their respective encodings. */
13811 #define NEON_ENC_TAB \
13812 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13813 X(vabdl, 0x0800700, N_INV, N_INV), \
13814 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13815 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13816 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13817 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13818 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13819 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13820 X(vaddl, 0x0800000, N_INV, N_INV), \
13821 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13822 X(vsubl, 0x0800200, N_INV, N_INV), \
13823 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13824 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13825 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13826 /* Register variants of the following two instructions are encoded as
13827 vcge / vcgt with the operands reversed. */ \
13828 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13829 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
13830 X(vfma, N_INV, 0x0000c10, N_INV), \
13831 X(vfms, N_INV, 0x0200c10, N_INV), \
13832 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13833 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13834 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13835 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13836 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13837 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13838 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13839 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13840 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13841 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13842 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
13843 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13844 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
13845 X(vshl, 0x0000400, N_INV, 0x0800510), \
13846 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13847 X(vand, 0x0000110, N_INV, 0x0800030), \
13848 X(vbic, 0x0100110, N_INV, 0x0800030), \
13849 X(veor, 0x1000110, N_INV, N_INV), \
13850 X(vorn, 0x0300110, N_INV, 0x0800010), \
13851 X(vorr, 0x0200110, N_INV, 0x0800010), \
13852 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13853 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13854 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13855 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13856 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13857 X(vst1, 0x0000000, 0x0800000, N_INV), \
13858 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13859 X(vst2, 0x0000100, 0x0800100, N_INV), \
13860 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13861 X(vst3, 0x0000200, 0x0800200, N_INV), \
13862 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13863 X(vst4, 0x0000300, 0x0800300, N_INV), \
13864 X(vmovn, 0x1b20200, N_INV, N_INV), \
13865 X(vtrn, 0x1b20080, N_INV, N_INV), \
13866 X(vqmovn, 0x1b20200, N_INV, N_INV), \
13867 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13868 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
13869 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13870 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
13871 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13872 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
13873 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13874 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13875 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
13876 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13877 X(vseleq, 0xe000a00, N_INV, N_INV), \
13878 X(vselvs, 0xe100a00, N_INV, N_INV), \
13879 X(vselge, 0xe200a00, N_INV, N_INV), \
13880 X(vselgt, 0xe300a00, N_INV, N_INV), \
13881 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
13882 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
13883 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13884 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
13885 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
13886 X(aes, 0x3b00300, N_INV, N_INV), \
13887 X(sha3op, 0x2000c00, N_INV, N_INV), \
13888 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13889 X(sha2op, 0x3ba0380, N_INV, N_INV)
13891 enum neon_opc
13893 #define X(OPC,I,F,S) N_MNEM_##OPC
13894 NEON_ENC_TAB
13895 #undef X
13898 static const struct neon_tab_entry neon_enc_tab[] =
13900 #define X(OPC,I,F,S) { (I), (F), (S) }
13901 NEON_ENC_TAB
13902 #undef X
13905 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
13906 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13907 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13908 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13909 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13910 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13911 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13912 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13913 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13914 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13915 #define NEON_ENC_SINGLE_(X) \
13916 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
13917 #define NEON_ENC_DOUBLE_(X) \
13918 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
13919 #define NEON_ENC_FPV8_(X) \
13920 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
13922 #define NEON_ENCODE(type, inst) \
13923 do \
13925 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13926 inst.is_neon = 1; \
13928 while (0)
13930 #define check_neon_suffixes \
13931 do \
13933 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13935 as_bad (_("invalid neon suffix for non neon instruction")); \
13936 return; \
13939 while (0)
13941 /* Define shapes for instruction operands. The following mnemonic characters
13942 are used in this table:
13944 F - VFP S<n> register
13945 D - Neon D<n> register
13946 Q - Neon Q<n> register
13947 I - Immediate
13948 S - Scalar
13949 R - ARM register
13950 L - D<n> register list
13952 This table is used to generate various data:
13953 - enumerations of the form NS_DDR to be used as arguments to
13954 neon_select_shape.
13955 - a table classifying shapes into single, double, quad, mixed.
13956 - a table used to drive neon_select_shape. */
13958 #define NEON_SHAPE_DEF \
13959 X(3, (D, D, D), DOUBLE), \
13960 X(3, (Q, Q, Q), QUAD), \
13961 X(3, (D, D, I), DOUBLE), \
13962 X(3, (Q, Q, I), QUAD), \
13963 X(3, (D, D, S), DOUBLE), \
13964 X(3, (Q, Q, S), QUAD), \
13965 X(3, (Q, Q, R), QUAD), \
13966 X(2, (D, D), DOUBLE), \
13967 X(2, (Q, Q), QUAD), \
13968 X(2, (D, S), DOUBLE), \
13969 X(2, (Q, S), QUAD), \
13970 X(2, (D, R), DOUBLE), \
13971 X(2, (Q, R), QUAD), \
13972 X(2, (D, I), DOUBLE), \
13973 X(2, (Q, I), QUAD), \
13974 X(3, (D, L, D), DOUBLE), \
13975 X(2, (D, Q), MIXED), \
13976 X(2, (Q, D), MIXED), \
13977 X(3, (D, Q, I), MIXED), \
13978 X(3, (Q, D, I), MIXED), \
13979 X(3, (Q, D, D), MIXED), \
13980 X(3, (D, Q, Q), MIXED), \
13981 X(3, (Q, Q, D), MIXED), \
13982 X(3, (Q, D, S), MIXED), \
13983 X(3, (D, Q, S), MIXED), \
13984 X(4, (D, D, D, I), DOUBLE), \
13985 X(4, (Q, Q, Q, I), QUAD), \
13986 X(4, (D, D, S, I), DOUBLE), \
13987 X(4, (Q, Q, S, I), QUAD), \
13988 X(2, (F, F), SINGLE), \
13989 X(3, (F, F, F), SINGLE), \
13990 X(2, (F, I), SINGLE), \
13991 X(2, (F, D), MIXED), \
13992 X(2, (D, F), MIXED), \
13993 X(3, (F, F, I), MIXED), \
13994 X(4, (R, R, F, F), SINGLE), \
13995 X(4, (F, F, R, R), SINGLE), \
13996 X(3, (D, R, R), DOUBLE), \
13997 X(3, (R, R, D), DOUBLE), \
13998 X(2, (S, R), SINGLE), \
13999 X(2, (R, S), SINGLE), \
14000 X(2, (F, R), SINGLE), \
14001 X(2, (R, F), SINGLE), \
14002 /* Half float shape supported so far. */\
14003 X (2, (H, D), MIXED), \
14004 X (2, (D, H), MIXED), \
14005 X (2, (H, F), MIXED), \
14006 X (2, (F, H), MIXED), \
14007 X (2, (H, H), HALF), \
14008 X (2, (H, R), HALF), \
14009 X (2, (R, H), HALF), \
14010 X (2, (H, I), HALF), \
14011 X (3, (H, H, H), HALF), \
14012 X (3, (H, F, I), MIXED), \
14013 X (3, (F, H, I), MIXED), \
14014 X (3, (D, H, H), MIXED), \
14015 X (3, (D, H, S), MIXED)
14017 #define S2(A,B) NS_##A##B
14018 #define S3(A,B,C) NS_##A##B##C
14019 #define S4(A,B,C,D) NS_##A##B##C##D
14021 #define X(N, L, C) S##N L
14023 enum neon_shape
14025 NEON_SHAPE_DEF,
14026 NS_NULL
14029 #undef X
14030 #undef S2
14031 #undef S3
14032 #undef S4
14034 enum neon_shape_class
14036 SC_HALF,
14037 SC_SINGLE,
14038 SC_DOUBLE,
14039 SC_QUAD,
14040 SC_MIXED
14043 #define X(N, L, C) SC_##C
14045 static enum neon_shape_class neon_shape_class[] =
14047 NEON_SHAPE_DEF
14050 #undef X
14052 enum neon_shape_el
14054 SE_H,
14055 SE_F,
14056 SE_D,
14057 SE_Q,
14058 SE_I,
14059 SE_S,
14060 SE_R,
14061 SE_L
14064 /* Register widths of above. */
14065 static unsigned neon_shape_el_size[] =
14070 128,
14077 struct neon_shape_info
14079 unsigned els;
14080 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14083 #define S2(A,B) { SE_##A, SE_##B }
14084 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14085 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14087 #define X(N, L, C) { N, S##N L }
14089 static struct neon_shape_info neon_shape_tab[] =
14091 NEON_SHAPE_DEF
14094 #undef X
14095 #undef S2
14096 #undef S3
14097 #undef S4
14099 /* Bit masks used in type checking given instructions.
14100 'N_EQK' means the type must be the same as (or based on in some way) the key
14101 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14102 set, various other bits can be set as well in order to modify the meaning of
14103 the type constraint. */
14105 enum neon_type_mask
14107 N_S8 = 0x0000001,
14108 N_S16 = 0x0000002,
14109 N_S32 = 0x0000004,
14110 N_S64 = 0x0000008,
14111 N_U8 = 0x0000010,
14112 N_U16 = 0x0000020,
14113 N_U32 = 0x0000040,
14114 N_U64 = 0x0000080,
14115 N_I8 = 0x0000100,
14116 N_I16 = 0x0000200,
14117 N_I32 = 0x0000400,
14118 N_I64 = 0x0000800,
14119 N_8 = 0x0001000,
14120 N_16 = 0x0002000,
14121 N_32 = 0x0004000,
14122 N_64 = 0x0008000,
14123 N_P8 = 0x0010000,
14124 N_P16 = 0x0020000,
14125 N_F16 = 0x0040000,
14126 N_F32 = 0x0080000,
14127 N_F64 = 0x0100000,
14128 N_P64 = 0x0200000,
14129 N_KEY = 0x1000000, /* Key element (main type specifier). */
14130 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14131 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14132 N_UNT = 0x8000000, /* Must be explicitly untyped. */
14133 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14134 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14135 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14136 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14137 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14138 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14139 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
14140 N_UTYP = 0,
14141 N_MAX_NONSPECIAL = N_P64
14144 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14146 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14147 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14148 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
14149 #define N_S_32 (N_S8 | N_S16 | N_S32)
14150 #define N_F_16_32 (N_F16 | N_F32)
14151 #define N_SUF_32 (N_SU_32 | N_F_16_32)
14152 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
14153 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
14154 #define N_F_ALL (N_F16 | N_F32 | N_F64)
14155 #define N_I_MVE (N_I8 | N_I16 | N_I32)
14156 #define N_F_MVE (N_F16 | N_F32)
14157 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14159 /* Pass this as the first type argument to neon_check_type to ignore types
14160 altogether. */
14161 #define N_IGNORE_TYPE (N_KEY | N_EQK)
14163 /* Select a "shape" for the current instruction (describing register types or
14164 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14165 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14166 function of operand parsing, so this function doesn't need to be called.
14167 Shapes should be listed in order of decreasing length. */
14169 static enum neon_shape
14170 neon_select_shape (enum neon_shape shape, ...)
14172 va_list ap;
14173 enum neon_shape first_shape = shape;
14175 /* Fix missing optional operands. FIXME: we don't know at this point how
14176 many arguments we should have, so this makes the assumption that we have
14177 > 1. This is true of all current Neon opcodes, I think, but may not be
14178 true in the future. */
14179 if (!inst.operands[1].present)
14180 inst.operands[1] = inst.operands[0];
14182 va_start (ap, shape);
14184 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
14186 unsigned j;
14187 int matches = 1;
14189 for (j = 0; j < neon_shape_tab[shape].els; j++)
14191 if (!inst.operands[j].present)
14193 matches = 0;
14194 break;
14197 switch (neon_shape_tab[shape].el[j])
14199 /* If a .f16, .16, .u16, .s16 type specifier is given over
14200 a VFP single precision register operand, it's essentially
14201 means only half of the register is used.
14203 If the type specifier is given after the mnemonics, the
14204 information is stored in inst.vectype. If the type specifier
14205 is given after register operand, the information is stored
14206 in inst.operands[].vectype.
14208 When there is only one type specifier, and all the register
14209 operands are the same type of hardware register, the type
14210 specifier applies to all register operands.
14212 If no type specifier is given, the shape is inferred from
14213 operand information.
14215 for example:
14216 vadd.f16 s0, s1, s2: NS_HHH
14217 vabs.f16 s0, s1: NS_HH
14218 vmov.f16 s0, r1: NS_HR
14219 vmov.f16 r0, s1: NS_RH
14220 vcvt.f16 r0, s1: NS_RH
14221 vcvt.f16.s32 s2, s2, #29: NS_HFI
14222 vcvt.f16.s32 s2, s2: NS_HF
14224 case SE_H:
14225 if (!(inst.operands[j].isreg
14226 && inst.operands[j].isvec
14227 && inst.operands[j].issingle
14228 && !inst.operands[j].isquad
14229 && ((inst.vectype.elems == 1
14230 && inst.vectype.el[0].size == 16)
14231 || (inst.vectype.elems > 1
14232 && inst.vectype.el[j].size == 16)
14233 || (inst.vectype.elems == 0
14234 && inst.operands[j].vectype.type != NT_invtype
14235 && inst.operands[j].vectype.size == 16))))
14236 matches = 0;
14237 break;
14239 case SE_F:
14240 if (!(inst.operands[j].isreg
14241 && inst.operands[j].isvec
14242 && inst.operands[j].issingle
14243 && !inst.operands[j].isquad
14244 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14245 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14246 || (inst.vectype.elems == 0
14247 && (inst.operands[j].vectype.size == 32
14248 || inst.operands[j].vectype.type == NT_invtype)))))
14249 matches = 0;
14250 break;
14252 case SE_D:
14253 if (!(inst.operands[j].isreg
14254 && inst.operands[j].isvec
14255 && !inst.operands[j].isquad
14256 && !inst.operands[j].issingle))
14257 matches = 0;
14258 break;
14260 case SE_R:
14261 if (!(inst.operands[j].isreg
14262 && !inst.operands[j].isvec))
14263 matches = 0;
14264 break;
14266 case SE_Q:
14267 if (!(inst.operands[j].isreg
14268 && inst.operands[j].isvec
14269 && inst.operands[j].isquad
14270 && !inst.operands[j].issingle))
14271 matches = 0;
14272 break;
14274 case SE_I:
14275 if (!(!inst.operands[j].isreg
14276 && !inst.operands[j].isscalar))
14277 matches = 0;
14278 break;
14280 case SE_S:
14281 if (!(!inst.operands[j].isreg
14282 && inst.operands[j].isscalar))
14283 matches = 0;
14284 break;
14286 case SE_L:
14287 break;
14289 if (!matches)
14290 break;
14292 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14293 /* We've matched all the entries in the shape table, and we don't
14294 have any left over operands which have not been matched. */
14295 break;
14298 va_end (ap);
14300 if (shape == NS_NULL && first_shape != NS_NULL)
14301 first_error (_("invalid instruction shape"));
14303 return shape;
14306 /* True if SHAPE is predominantly a quadword operation (most of the time, this
14307 means the Q bit should be set). */
14309 static int
14310 neon_quad (enum neon_shape shape)
14312 return neon_shape_class[shape] == SC_QUAD;
14315 static void
14316 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
14317 unsigned *g_size)
14319 /* Allow modification to be made to types which are constrained to be
14320 based on the key element, based on bits set alongside N_EQK. */
14321 if ((typebits & N_EQK) != 0)
14323 if ((typebits & N_HLF) != 0)
14324 *g_size /= 2;
14325 else if ((typebits & N_DBL) != 0)
14326 *g_size *= 2;
14327 if ((typebits & N_SGN) != 0)
14328 *g_type = NT_signed;
14329 else if ((typebits & N_UNS) != 0)
14330 *g_type = NT_unsigned;
14331 else if ((typebits & N_INT) != 0)
14332 *g_type = NT_integer;
14333 else if ((typebits & N_FLT) != 0)
14334 *g_type = NT_float;
14335 else if ((typebits & N_SIZ) != 0)
14336 *g_type = NT_untyped;
14340 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
14341 operand type, i.e. the single type specified in a Neon instruction when it
14342 is the only one given. */
14344 static struct neon_type_el
14345 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
14347 struct neon_type_el dest = *key;
14349 gas_assert ((thisarg & N_EQK) != 0);
14351 neon_modify_type_size (thisarg, &dest.type, &dest.size);
14353 return dest;
14356 /* Convert Neon type and size into compact bitmask representation. */
14358 static enum neon_type_mask
14359 type_chk_of_el_type (enum neon_el_type type, unsigned size)
14361 switch (type)
14363 case NT_untyped:
14364 switch (size)
14366 case 8: return N_8;
14367 case 16: return N_16;
14368 case 32: return N_32;
14369 case 64: return N_64;
14370 default: ;
14372 break;
14374 case NT_integer:
14375 switch (size)
14377 case 8: return N_I8;
14378 case 16: return N_I16;
14379 case 32: return N_I32;
14380 case 64: return N_I64;
14381 default: ;
14383 break;
14385 case NT_float:
14386 switch (size)
14388 case 16: return N_F16;
14389 case 32: return N_F32;
14390 case 64: return N_F64;
14391 default: ;
14393 break;
14395 case NT_poly:
14396 switch (size)
14398 case 8: return N_P8;
14399 case 16: return N_P16;
14400 case 64: return N_P64;
14401 default: ;
14403 break;
14405 case NT_signed:
14406 switch (size)
14408 case 8: return N_S8;
14409 case 16: return N_S16;
14410 case 32: return N_S32;
14411 case 64: return N_S64;
14412 default: ;
14414 break;
14416 case NT_unsigned:
14417 switch (size)
14419 case 8: return N_U8;
14420 case 16: return N_U16;
14421 case 32: return N_U32;
14422 case 64: return N_U64;
14423 default: ;
14425 break;
14427 default: ;
14430 return N_UTYP;
14433 /* Convert compact Neon bitmask type representation to a type and size. Only
14434 handles the case where a single bit is set in the mask. */
14436 static int
14437 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
14438 enum neon_type_mask mask)
14440 if ((mask & N_EQK) != 0)
14441 return FAIL;
14443 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
14444 *size = 8;
14445 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
14446 *size = 16;
14447 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
14448 *size = 32;
14449 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
14450 *size = 64;
14451 else
14452 return FAIL;
14454 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
14455 *type = NT_signed;
14456 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
14457 *type = NT_unsigned;
14458 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
14459 *type = NT_integer;
14460 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
14461 *type = NT_untyped;
14462 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
14463 *type = NT_poly;
14464 else if ((mask & (N_F_ALL)) != 0)
14465 *type = NT_float;
14466 else
14467 return FAIL;
14469 return SUCCESS;
14472 /* Modify a bitmask of allowed types. This is only needed for type
14473 relaxation. */
14475 static unsigned
14476 modify_types_allowed (unsigned allowed, unsigned mods)
14478 unsigned size;
14479 enum neon_el_type type;
14480 unsigned destmask;
14481 int i;
14483 destmask = 0;
14485 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
14487 if (el_type_of_type_chk (&type, &size,
14488 (enum neon_type_mask) (allowed & i)) == SUCCESS)
14490 neon_modify_type_size (mods, &type, &size);
14491 destmask |= type_chk_of_el_type (type, size);
14495 return destmask;
14498 /* Check type and return type classification.
14499 The manual states (paraphrase): If one datatype is given, it indicates the
14500 type given in:
14501 - the second operand, if there is one
14502 - the operand, if there is no second operand
14503 - the result, if there are no operands.
14504 This isn't quite good enough though, so we use a concept of a "key" datatype
14505 which is set on a per-instruction basis, which is the one which matters when
14506 only one data type is written.
14507 Note: this function has side-effects (e.g. filling in missing operands). All
14508 Neon instructions should call it before performing bit encoding. */
14510 static struct neon_type_el
14511 neon_check_type (unsigned els, enum neon_shape ns, ...)
14513 va_list ap;
14514 unsigned i, pass, key_el = 0;
14515 unsigned types[NEON_MAX_TYPE_ELS];
14516 enum neon_el_type k_type = NT_invtype;
14517 unsigned k_size = -1u;
14518 struct neon_type_el badtype = {NT_invtype, -1};
14519 unsigned key_allowed = 0;
14521 /* Optional registers in Neon instructions are always (not) in operand 1.
14522 Fill in the missing operand here, if it was omitted. */
14523 if (els > 1 && !inst.operands[1].present)
14524 inst.operands[1] = inst.operands[0];
14526 /* Suck up all the varargs. */
14527 va_start (ap, ns);
14528 for (i = 0; i < els; i++)
14530 unsigned thisarg = va_arg (ap, unsigned);
14531 if (thisarg == N_IGNORE_TYPE)
14533 va_end (ap);
14534 return badtype;
14536 types[i] = thisarg;
14537 if ((thisarg & N_KEY) != 0)
14538 key_el = i;
14540 va_end (ap);
14542 if (inst.vectype.elems > 0)
14543 for (i = 0; i < els; i++)
14544 if (inst.operands[i].vectype.type != NT_invtype)
14546 first_error (_("types specified in both the mnemonic and operands"));
14547 return badtype;
14550 /* Duplicate inst.vectype elements here as necessary.
14551 FIXME: No idea if this is exactly the same as the ARM assembler,
14552 particularly when an insn takes one register and one non-register
14553 operand. */
14554 if (inst.vectype.elems == 1 && els > 1)
14556 unsigned j;
14557 inst.vectype.elems = els;
14558 inst.vectype.el[key_el] = inst.vectype.el[0];
14559 for (j = 0; j < els; j++)
14560 if (j != key_el)
14561 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14562 types[j]);
14564 else if (inst.vectype.elems == 0 && els > 0)
14566 unsigned j;
14567 /* No types were given after the mnemonic, so look for types specified
14568 after each operand. We allow some flexibility here; as long as the
14569 "key" operand has a type, we can infer the others. */
14570 for (j = 0; j < els; j++)
14571 if (inst.operands[j].vectype.type != NT_invtype)
14572 inst.vectype.el[j] = inst.operands[j].vectype;
14574 if (inst.operands[key_el].vectype.type != NT_invtype)
14576 for (j = 0; j < els; j++)
14577 if (inst.operands[j].vectype.type == NT_invtype)
14578 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14579 types[j]);
14581 else
14583 first_error (_("operand types can't be inferred"));
14584 return badtype;
14587 else if (inst.vectype.elems != els)
14589 first_error (_("type specifier has the wrong number of parts"));
14590 return badtype;
14593 for (pass = 0; pass < 2; pass++)
14595 for (i = 0; i < els; i++)
14597 unsigned thisarg = types[i];
14598 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14599 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14600 enum neon_el_type g_type = inst.vectype.el[i].type;
14601 unsigned g_size = inst.vectype.el[i].size;
14603 /* Decay more-specific signed & unsigned types to sign-insensitive
14604 integer types if sign-specific variants are unavailable. */
14605 if ((g_type == NT_signed || g_type == NT_unsigned)
14606 && (types_allowed & N_SU_ALL) == 0)
14607 g_type = NT_integer;
14609 /* If only untyped args are allowed, decay any more specific types to
14610 them. Some instructions only care about signs for some element
14611 sizes, so handle that properly. */
14612 if (((types_allowed & N_UNT) == 0)
14613 && ((g_size == 8 && (types_allowed & N_8) != 0)
14614 || (g_size == 16 && (types_allowed & N_16) != 0)
14615 || (g_size == 32 && (types_allowed & N_32) != 0)
14616 || (g_size == 64 && (types_allowed & N_64) != 0)))
14617 g_type = NT_untyped;
14619 if (pass == 0)
14621 if ((thisarg & N_KEY) != 0)
14623 k_type = g_type;
14624 k_size = g_size;
14625 key_allowed = thisarg & ~N_KEY;
14627 /* Check architecture constraint on FP16 extension. */
14628 if (k_size == 16
14629 && k_type == NT_float
14630 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14632 inst.error = _(BAD_FP16);
14633 return badtype;
14637 else
14639 if ((thisarg & N_VFP) != 0)
14641 enum neon_shape_el regshape;
14642 unsigned regwidth, match;
14644 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14645 if (ns == NS_NULL)
14647 first_error (_("invalid instruction shape"));
14648 return badtype;
14650 regshape = neon_shape_tab[ns].el[i];
14651 regwidth = neon_shape_el_size[regshape];
14653 /* In VFP mode, operands must match register widths. If we
14654 have a key operand, use its width, else use the width of
14655 the current operand. */
14656 if (k_size != -1u)
14657 match = k_size;
14658 else
14659 match = g_size;
14661 /* FP16 will use a single precision register. */
14662 if (regwidth == 32 && match == 16)
14664 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14665 match = regwidth;
14666 else
14668 inst.error = _(BAD_FP16);
14669 return badtype;
14673 if (regwidth != match)
14675 first_error (_("operand size must match register width"));
14676 return badtype;
14680 if ((thisarg & N_EQK) == 0)
14682 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14684 if ((given_type & types_allowed) == 0)
14686 first_error (_("bad type in SIMD instruction"));
14687 return badtype;
14690 else
14692 enum neon_el_type mod_k_type = k_type;
14693 unsigned mod_k_size = k_size;
14694 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14695 if (g_type != mod_k_type || g_size != mod_k_size)
14697 first_error (_("inconsistent types in Neon instruction"));
14698 return badtype;
14705 return inst.vectype.el[key_el];
14708 /* Neon-style VFP instruction forwarding. */
14710 /* Thumb VFP instructions have 0xE in the condition field. */
14712 static void
14713 do_vfp_cond_or_thumb (void)
14715 inst.is_neon = 1;
14717 if (thumb_mode)
14718 inst.instruction |= 0xe0000000;
14719 else
14720 inst.instruction |= inst.cond << 28;
14723 /* Look up and encode a simple mnemonic, for use as a helper function for the
14724 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14725 etc. It is assumed that operand parsing has already been done, and that the
14726 operands are in the form expected by the given opcode (this isn't necessarily
14727 the same as the form in which they were parsed, hence some massaging must
14728 take place before this function is called).
14729 Checks current arch version against that in the looked-up opcode. */
14731 static void
14732 do_vfp_nsyn_opcode (const char *opname)
14734 const struct asm_opcode *opcode;
14736 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
14738 if (!opcode)
14739 abort ();
14741 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
14742 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14743 _(BAD_FPU));
14745 inst.is_neon = 1;
14747 if (thumb_mode)
14749 inst.instruction = opcode->tvalue;
14750 opcode->tencode ();
14752 else
14754 inst.instruction = (inst.cond << 28) | opcode->avalue;
14755 opcode->aencode ();
14759 static void
14760 do_vfp_nsyn_add_sub (enum neon_shape rs)
14762 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14764 if (rs == NS_FFF || rs == NS_HHH)
14766 if (is_add)
14767 do_vfp_nsyn_opcode ("fadds");
14768 else
14769 do_vfp_nsyn_opcode ("fsubs");
14771 /* ARMv8.2 fp16 instruction. */
14772 if (rs == NS_HHH)
14773 do_scalar_fp16_v82_encode ();
14775 else
14777 if (is_add)
14778 do_vfp_nsyn_opcode ("faddd");
14779 else
14780 do_vfp_nsyn_opcode ("fsubd");
14784 /* Check operand types to see if this is a VFP instruction, and if so call
14785 PFN (). */
14787 static int
14788 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14790 enum neon_shape rs;
14791 struct neon_type_el et;
14793 switch (args)
14795 case 2:
14796 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14797 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14798 break;
14800 case 3:
14801 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14802 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14803 N_F_ALL | N_KEY | N_VFP);
14804 break;
14806 default:
14807 abort ();
14810 if (et.type != NT_invtype)
14812 pfn (rs);
14813 return SUCCESS;
14816 inst.error = NULL;
14817 return FAIL;
14820 static void
14821 do_vfp_nsyn_mla_mls (enum neon_shape rs)
14823 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
14825 if (rs == NS_FFF || rs == NS_HHH)
14827 if (is_mla)
14828 do_vfp_nsyn_opcode ("fmacs");
14829 else
14830 do_vfp_nsyn_opcode ("fnmacs");
14832 /* ARMv8.2 fp16 instruction. */
14833 if (rs == NS_HHH)
14834 do_scalar_fp16_v82_encode ();
14836 else
14838 if (is_mla)
14839 do_vfp_nsyn_opcode ("fmacd");
14840 else
14841 do_vfp_nsyn_opcode ("fnmacd");
14845 static void
14846 do_vfp_nsyn_fma_fms (enum neon_shape rs)
14848 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14850 if (rs == NS_FFF || rs == NS_HHH)
14852 if (is_fma)
14853 do_vfp_nsyn_opcode ("ffmas");
14854 else
14855 do_vfp_nsyn_opcode ("ffnmas");
14857 /* ARMv8.2 fp16 instruction. */
14858 if (rs == NS_HHH)
14859 do_scalar_fp16_v82_encode ();
14861 else
14863 if (is_fma)
14864 do_vfp_nsyn_opcode ("ffmad");
14865 else
14866 do_vfp_nsyn_opcode ("ffnmad");
14870 static void
14871 do_vfp_nsyn_mul (enum neon_shape rs)
14873 if (rs == NS_FFF || rs == NS_HHH)
14875 do_vfp_nsyn_opcode ("fmuls");
14877 /* ARMv8.2 fp16 instruction. */
14878 if (rs == NS_HHH)
14879 do_scalar_fp16_v82_encode ();
14881 else
14882 do_vfp_nsyn_opcode ("fmuld");
14885 static void
14886 do_vfp_nsyn_abs_neg (enum neon_shape rs)
14888 int is_neg = (inst.instruction & 0x80) != 0;
14889 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
14891 if (rs == NS_FF || rs == NS_HH)
14893 if (is_neg)
14894 do_vfp_nsyn_opcode ("fnegs");
14895 else
14896 do_vfp_nsyn_opcode ("fabss");
14898 /* ARMv8.2 fp16 instruction. */
14899 if (rs == NS_HH)
14900 do_scalar_fp16_v82_encode ();
14902 else
14904 if (is_neg)
14905 do_vfp_nsyn_opcode ("fnegd");
14906 else
14907 do_vfp_nsyn_opcode ("fabsd");
14911 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14912 insns belong to Neon, and are handled elsewhere. */
14914 static void
14915 do_vfp_nsyn_ldm_stm (int is_dbmode)
14917 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14918 if (is_ldm)
14920 if (is_dbmode)
14921 do_vfp_nsyn_opcode ("fldmdbs");
14922 else
14923 do_vfp_nsyn_opcode ("fldmias");
14925 else
14927 if (is_dbmode)
14928 do_vfp_nsyn_opcode ("fstmdbs");
14929 else
14930 do_vfp_nsyn_opcode ("fstmias");
14934 static void
14935 do_vfp_nsyn_sqrt (void)
14937 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14938 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14940 if (rs == NS_FF || rs == NS_HH)
14942 do_vfp_nsyn_opcode ("fsqrts");
14944 /* ARMv8.2 fp16 instruction. */
14945 if (rs == NS_HH)
14946 do_scalar_fp16_v82_encode ();
14948 else
14949 do_vfp_nsyn_opcode ("fsqrtd");
14952 static void
14953 do_vfp_nsyn_div (void)
14955 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14956 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14957 N_F_ALL | N_KEY | N_VFP);
14959 if (rs == NS_FFF || rs == NS_HHH)
14961 do_vfp_nsyn_opcode ("fdivs");
14963 /* ARMv8.2 fp16 instruction. */
14964 if (rs == NS_HHH)
14965 do_scalar_fp16_v82_encode ();
14967 else
14968 do_vfp_nsyn_opcode ("fdivd");
14971 static void
14972 do_vfp_nsyn_nmul (void)
14974 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14975 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14976 N_F_ALL | N_KEY | N_VFP);
14978 if (rs == NS_FFF || rs == NS_HHH)
14980 NEON_ENCODE (SINGLE, inst);
14981 do_vfp_sp_dyadic ();
14983 /* ARMv8.2 fp16 instruction. */
14984 if (rs == NS_HHH)
14985 do_scalar_fp16_v82_encode ();
14987 else
14989 NEON_ENCODE (DOUBLE, inst);
14990 do_vfp_dp_rd_rn_rm ();
14992 do_vfp_cond_or_thumb ();
14996 static void
14997 do_vfp_nsyn_cmp (void)
14999 enum neon_shape rs;
15000 if (inst.operands[1].isreg)
15002 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15003 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15005 if (rs == NS_FF || rs == NS_HH)
15007 NEON_ENCODE (SINGLE, inst);
15008 do_vfp_sp_monadic ();
15010 else
15012 NEON_ENCODE (DOUBLE, inst);
15013 do_vfp_dp_rd_rm ();
15016 else
15018 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
15019 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
15021 switch (inst.instruction & 0x0fffffff)
15023 case N_MNEM_vcmp:
15024 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
15025 break;
15026 case N_MNEM_vcmpe:
15027 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
15028 break;
15029 default:
15030 abort ();
15033 if (rs == NS_FI || rs == NS_HI)
15035 NEON_ENCODE (SINGLE, inst);
15036 do_vfp_sp_compare_z ();
15038 else
15040 NEON_ENCODE (DOUBLE, inst);
15041 do_vfp_dp_rd ();
15044 do_vfp_cond_or_thumb ();
15046 /* ARMv8.2 fp16 instruction. */
15047 if (rs == NS_HI || rs == NS_HH)
15048 do_scalar_fp16_v82_encode ();
15051 static void
15052 nsyn_insert_sp (void)
15054 inst.operands[1] = inst.operands[0];
15055 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
15056 inst.operands[0].reg = REG_SP;
15057 inst.operands[0].isreg = 1;
15058 inst.operands[0].writeback = 1;
15059 inst.operands[0].present = 1;
15062 static void
15063 do_vfp_nsyn_push (void)
15065 nsyn_insert_sp ();
15067 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15068 _("register list must contain at least 1 and at most 16 "
15069 "registers"));
15071 if (inst.operands[1].issingle)
15072 do_vfp_nsyn_opcode ("fstmdbs");
15073 else
15074 do_vfp_nsyn_opcode ("fstmdbd");
15077 static void
15078 do_vfp_nsyn_pop (void)
15080 nsyn_insert_sp ();
15082 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15083 _("register list must contain at least 1 and at most 16 "
15084 "registers"));
15086 if (inst.operands[1].issingle)
15087 do_vfp_nsyn_opcode ("fldmias");
15088 else
15089 do_vfp_nsyn_opcode ("fldmiad");
15092 /* Fix up Neon data-processing instructions, ORing in the correct bits for
15093 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
15095 static void
15096 neon_dp_fixup (struct arm_it* insn)
15098 unsigned int i = insn->instruction;
15099 insn->is_neon = 1;
15101 if (thumb_mode)
15103 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
15104 if (i & (1 << 24))
15105 i |= 1 << 28;
15107 i &= ~(1 << 24);
15109 i |= 0xef000000;
15111 else
15112 i |= 0xf2000000;
15114 insn->instruction = i;
15117 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15118 (0, 1, 2, 3). */
15120 static unsigned
15121 neon_logbits (unsigned x)
15123 return ffs (x) - 4;
15126 #define LOW4(R) ((R) & 0xf)
15127 #define HI1(R) (((R) >> 4) & 1)
15129 static void
15130 mve_encode_qqr (int size, int fp)
15132 if (inst.operands[2].reg == REG_SP)
15133 as_tsktsk (MVE_BAD_SP);
15134 else if (inst.operands[2].reg == REG_PC)
15135 as_tsktsk (MVE_BAD_PC);
15137 if (fp)
15139 /* vadd. */
15140 if (((unsigned)inst.instruction) == 0xd00)
15141 inst.instruction = 0xee300f40;
15142 /* vsub. */
15143 else if (((unsigned)inst.instruction) == 0x200d00)
15144 inst.instruction = 0xee301f40;
15146 /* Setting size which is 1 for F16 and 0 for F32. */
15147 inst.instruction |= (size == 16) << 28;
15149 else
15151 /* vadd. */
15152 if (((unsigned)inst.instruction) == 0x800)
15153 inst.instruction = 0xee010f40;
15154 /* vsub. */
15155 else if (((unsigned)inst.instruction) == 0x1000800)
15156 inst.instruction = 0xee011f40;
15157 /* Setting bits for size. */
15158 inst.instruction |= neon_logbits (size) << 20;
15160 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15161 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15162 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15163 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15164 inst.instruction |= inst.operands[2].reg;
15165 inst.is_neon = 1;
15168 /* Encode insns with bit pattern:
15170 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
15171 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
15173 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
15174 different meaning for some instruction. */
15176 static void
15177 neon_three_same (int isquad, int ubit, int size)
15179 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15180 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15181 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15182 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15183 inst.instruction |= LOW4 (inst.operands[2].reg);
15184 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15185 inst.instruction |= (isquad != 0) << 6;
15186 inst.instruction |= (ubit != 0) << 24;
15187 if (size != -1)
15188 inst.instruction |= neon_logbits (size) << 20;
15190 neon_dp_fixup (&inst);
15193 /* Encode instructions of the form:
15195 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
15196 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
15198 Don't write size if SIZE == -1. */
15200 static void
15201 neon_two_same (int qbit, int ubit, int size)
15203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15205 inst.instruction |= LOW4 (inst.operands[1].reg);
15206 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15207 inst.instruction |= (qbit != 0) << 6;
15208 inst.instruction |= (ubit != 0) << 24;
15210 if (size != -1)
15211 inst.instruction |= neon_logbits (size) << 18;
15213 neon_dp_fixup (&inst);
15216 /* Neon instruction encoders, in approximate order of appearance. */
15218 static void
15219 do_neon_dyadic_i_su (void)
15221 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15222 struct neon_type_el et = neon_check_type (3, rs,
15223 N_EQK, N_EQK, N_SU_32 | N_KEY);
15224 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15227 static void
15228 do_neon_dyadic_i64_su (void)
15230 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15231 struct neon_type_el et = neon_check_type (3, rs,
15232 N_EQK, N_EQK, N_SU_ALL | N_KEY);
15233 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15236 static void
15237 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
15238 unsigned immbits)
15240 unsigned size = et.size >> 3;
15241 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15242 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15243 inst.instruction |= LOW4 (inst.operands[1].reg);
15244 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15245 inst.instruction |= (isquad != 0) << 6;
15246 inst.instruction |= immbits << 16;
15247 inst.instruction |= (size >> 3) << 7;
15248 inst.instruction |= (size & 0x7) << 19;
15249 if (write_ubit)
15250 inst.instruction |= (uval != 0) << 24;
15252 neon_dp_fixup (&inst);
15255 static void
15256 do_neon_shl_imm (void)
15258 if (!inst.operands[2].isreg)
15260 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15261 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
15262 int imm = inst.operands[2].imm;
15264 constraint (imm < 0 || (unsigned)imm >= et.size,
15265 _("immediate out of range for shift"));
15266 NEON_ENCODE (IMMED, inst);
15267 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15269 else
15271 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15272 struct neon_type_el et = neon_check_type (3, rs,
15273 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
15274 unsigned int tmp;
15276 /* VSHL/VQSHL 3-register variants have syntax such as:
15277 vshl.xx Dd, Dm, Dn
15278 whereas other 3-register operations encoded by neon_three_same have
15279 syntax like:
15280 vadd.xx Dd, Dn, Dm
15281 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
15282 here. */
15283 tmp = inst.operands[2].reg;
15284 inst.operands[2].reg = inst.operands[1].reg;
15285 inst.operands[1].reg = tmp;
15286 NEON_ENCODE (INTEGER, inst);
15287 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15291 static void
15292 do_neon_qshl_imm (void)
15294 if (!inst.operands[2].isreg)
15296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15297 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15298 int imm = inst.operands[2].imm;
15300 constraint (imm < 0 || (unsigned)imm >= et.size,
15301 _("immediate out of range for shift"));
15302 NEON_ENCODE (IMMED, inst);
15303 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
15305 else
15307 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15308 struct neon_type_el et = neon_check_type (3, rs,
15309 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
15310 unsigned int tmp;
15312 /* See note in do_neon_shl_imm. */
15313 tmp = inst.operands[2].reg;
15314 inst.operands[2].reg = inst.operands[1].reg;
15315 inst.operands[1].reg = tmp;
15316 NEON_ENCODE (INTEGER, inst);
15317 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15321 static void
15322 do_neon_rshl (void)
15324 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15325 struct neon_type_el et = neon_check_type (3, rs,
15326 N_EQK, N_EQK, N_SU_ALL | N_KEY);
15327 unsigned int tmp;
15329 tmp = inst.operands[2].reg;
15330 inst.operands[2].reg = inst.operands[1].reg;
15331 inst.operands[1].reg = tmp;
15332 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
15335 static int
15336 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
15338 /* Handle .I8 pseudo-instructions. */
15339 if (size == 8)
15341 /* Unfortunately, this will make everything apart from zero out-of-range.
15342 FIXME is this the intended semantics? There doesn't seem much point in
15343 accepting .I8 if so. */
15344 immediate |= immediate << 8;
15345 size = 16;
15348 if (size >= 32)
15350 if (immediate == (immediate & 0x000000ff))
15352 *immbits = immediate;
15353 return 0x1;
15355 else if (immediate == (immediate & 0x0000ff00))
15357 *immbits = immediate >> 8;
15358 return 0x3;
15360 else if (immediate == (immediate & 0x00ff0000))
15362 *immbits = immediate >> 16;
15363 return 0x5;
15365 else if (immediate == (immediate & 0xff000000))
15367 *immbits = immediate >> 24;
15368 return 0x7;
15370 if ((immediate & 0xffff) != (immediate >> 16))
15371 goto bad_immediate;
15372 immediate &= 0xffff;
15375 if (immediate == (immediate & 0x000000ff))
15377 *immbits = immediate;
15378 return 0x9;
15380 else if (immediate == (immediate & 0x0000ff00))
15382 *immbits = immediate >> 8;
15383 return 0xb;
15386 bad_immediate:
15387 first_error (_("immediate value out of range"));
15388 return FAIL;
15391 static void
15392 do_neon_logic (void)
15394 if (inst.operands[2].present && inst.operands[2].isreg)
15396 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15397 neon_check_type (3, rs, N_IGNORE_TYPE);
15398 /* U bit and size field were set as part of the bitmask. */
15399 NEON_ENCODE (INTEGER, inst);
15400 neon_three_same (neon_quad (rs), 0, -1);
15402 else
15404 const int three_ops_form = (inst.operands[2].present
15405 && !inst.operands[2].isreg);
15406 const int immoperand = (three_ops_form ? 2 : 1);
15407 enum neon_shape rs = (three_ops_form
15408 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
15409 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
15410 struct neon_type_el et = neon_check_type (2, rs,
15411 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
15412 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
15413 unsigned immbits;
15414 int cmode;
15416 if (et.type == NT_invtype)
15417 return;
15419 if (three_ops_form)
15420 constraint (inst.operands[0].reg != inst.operands[1].reg,
15421 _("first and second operands shall be the same register"));
15423 NEON_ENCODE (IMMED, inst);
15425 immbits = inst.operands[immoperand].imm;
15426 if (et.size == 64)
15428 /* .i64 is a pseudo-op, so the immediate must be a repeating
15429 pattern. */
15430 if (immbits != (inst.operands[immoperand].regisimm ?
15431 inst.operands[immoperand].reg : 0))
15433 /* Set immbits to an invalid constant. */
15434 immbits = 0xdeadbeef;
15438 switch (opcode)
15440 case N_MNEM_vbic:
15441 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15442 break;
15444 case N_MNEM_vorr:
15445 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15446 break;
15448 case N_MNEM_vand:
15449 /* Pseudo-instruction for VBIC. */
15450 neon_invert_size (&immbits, 0, et.size);
15451 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15452 break;
15454 case N_MNEM_vorn:
15455 /* Pseudo-instruction for VORR. */
15456 neon_invert_size (&immbits, 0, et.size);
15457 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
15458 break;
15460 default:
15461 abort ();
15464 if (cmode == FAIL)
15465 return;
15467 inst.instruction |= neon_quad (rs) << 6;
15468 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15469 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15470 inst.instruction |= cmode << 8;
15471 neon_write_immbits (immbits);
15473 neon_dp_fixup (&inst);
15477 static void
15478 do_neon_bitfield (void)
15480 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15481 neon_check_type (3, rs, N_IGNORE_TYPE);
15482 neon_three_same (neon_quad (rs), 0, -1);
15485 static void
15486 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
15487 unsigned destbits)
15489 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
15490 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
15491 types | N_KEY);
15492 if (et.type == NT_float)
15494 NEON_ENCODE (FLOAT, inst);
15495 if (rs == NS_QQR)
15496 mve_encode_qqr (et.size, 1);
15497 else
15498 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
15500 else
15502 NEON_ENCODE (INTEGER, inst);
15503 if (rs == NS_QQR)
15504 mve_encode_qqr (et.size, 0);
15505 else
15506 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
15511 static void
15512 do_neon_dyadic_if_su_d (void)
15514 /* This version only allow D registers, but that constraint is enforced during
15515 operand parsing so we don't need to do anything extra here. */
15516 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
15519 static void
15520 do_neon_dyadic_if_i_d (void)
15522 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15523 affected if we specify unsigned args. */
15524 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15527 enum vfp_or_neon_is_neon_bits
15529 NEON_CHECK_CC = 1,
15530 NEON_CHECK_ARCH = 2,
15531 NEON_CHECK_ARCH8 = 4
15534 /* Call this function if an instruction which may have belonged to the VFP or
15535 Neon instruction sets, but turned out to be a Neon instruction (due to the
15536 operand types involved, etc.). We have to check and/or fix-up a couple of
15537 things:
15539 - Make sure the user hasn't attempted to make a Neon instruction
15540 conditional.
15541 - Alter the value in the condition code field if necessary.
15542 - Make sure that the arch supports Neon instructions.
15544 Which of these operations take place depends on bits from enum
15545 vfp_or_neon_is_neon_bits.
15547 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
15548 current instruction's condition is COND_ALWAYS, the condition field is
15549 changed to inst.uncond_value. This is necessary because instructions shared
15550 between VFP and Neon may be conditional for the VFP variants only, and the
15551 unconditional Neon version must have, e.g., 0xF in the condition field. */
15553 static int
15554 vfp_or_neon_is_neon (unsigned check)
15556 /* Conditions are always legal in Thumb mode (IT blocks). */
15557 if (!thumb_mode && (check & NEON_CHECK_CC))
15559 if (inst.cond != COND_ALWAYS)
15561 first_error (_(BAD_COND));
15562 return FAIL;
15564 if (inst.uncond_value != -1)
15565 inst.instruction |= inst.uncond_value << 28;
15569 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
15570 || ((check & NEON_CHECK_ARCH8)
15571 && !mark_feature_used (&fpu_neon_ext_armv8)))
15573 first_error (_(BAD_FPU));
15574 return FAIL;
15577 return SUCCESS;
15580 static int
15581 check_simd_pred_availability (int fp, unsigned check)
15583 if (inst.cond > COND_ALWAYS)
15585 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15587 inst.error = BAD_FPU;
15588 return 1;
15590 inst.pred_insn_type = INSIDE_VPT_INSN;
15592 else if (inst.cond < COND_ALWAYS)
15594 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15595 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15596 else if (vfp_or_neon_is_neon (check) == FAIL)
15597 return 2;
15599 else
15601 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
15602 && vfp_or_neon_is_neon (check) == FAIL)
15603 return 3;
15605 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
15606 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15608 return 0;
15611 static void
15612 do_neon_dyadic_if_su (void)
15614 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
15615 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
15616 N_SUF_32 | N_KEY);
15618 if (check_simd_pred_availability (et.type == NT_float,
15619 NEON_CHECK_ARCH | NEON_CHECK_CC))
15620 return;
15622 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
15625 static void
15626 do_neon_addsub_if_i (void)
15628 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
15629 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15630 return;
15632 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
15633 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
15634 N_EQK, N_IF_32 | N_I64 | N_KEY);
15636 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
15637 /* If we are parsing Q registers and the element types match MVE, which NEON
15638 also supports, then we must check whether this is an instruction that can
15639 be used by both MVE/NEON. This distinction can be made based on whether
15640 they are predicated or not. */
15641 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
15643 if (check_simd_pred_availability (et.type == NT_float,
15644 NEON_CHECK_ARCH | NEON_CHECK_CC))
15645 return;
15647 else
15649 /* If they are either in a D register or are using an unsupported. */
15650 if (rs != NS_QQR
15651 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15652 return;
15655 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15656 affected if we specify unsigned args. */
15657 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
15660 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15661 result to be:
15662 V<op> A,B (A is operand 0, B is operand 2)
15663 to mean:
15664 V<op> A,B,A
15665 not:
15666 V<op> A,B,B
15667 so handle that case specially. */
15669 static void
15670 neon_exchange_operands (void)
15672 if (inst.operands[1].present)
15674 void *scratch = xmalloc (sizeof (inst.operands[0]));
15676 /* Swap operands[1] and operands[2]. */
15677 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15678 inst.operands[1] = inst.operands[2];
15679 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
15680 free (scratch);
15682 else
15684 inst.operands[1] = inst.operands[2];
15685 inst.operands[2] = inst.operands[0];
15689 static void
15690 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15692 if (inst.operands[2].isreg)
15694 if (invert)
15695 neon_exchange_operands ();
15696 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
15698 else
15700 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15701 struct neon_type_el et = neon_check_type (2, rs,
15702 N_EQK | N_SIZ, immtypes | N_KEY);
15704 NEON_ENCODE (IMMED, inst);
15705 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15707 inst.instruction |= LOW4 (inst.operands[1].reg);
15708 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15709 inst.instruction |= neon_quad (rs) << 6;
15710 inst.instruction |= (et.type == NT_float) << 10;
15711 inst.instruction |= neon_logbits (et.size) << 18;
15713 neon_dp_fixup (&inst);
15717 static void
15718 do_neon_cmp (void)
15720 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
15723 static void
15724 do_neon_cmp_inv (void)
15726 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
15729 static void
15730 do_neon_ceq (void)
15732 neon_compare (N_IF_32, N_IF_32, FALSE);
15735 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
15736 scalars, which are encoded in 5 bits, M : Rm.
15737 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15738 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15739 index in M.
15741 Dot Product instructions are similar to multiply instructions except elsize
15742 should always be 32.
15744 This function translates SCALAR, which is GAS's internal encoding of indexed
15745 scalar register, to raw encoding. There is also register and index range
15746 check based on ELSIZE. */
15748 static unsigned
15749 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15751 unsigned regno = NEON_SCALAR_REG (scalar);
15752 unsigned elno = NEON_SCALAR_INDEX (scalar);
15754 switch (elsize)
15756 case 16:
15757 if (regno > 7 || elno > 3)
15758 goto bad_scalar;
15759 return regno | (elno << 3);
15761 case 32:
15762 if (regno > 15 || elno > 1)
15763 goto bad_scalar;
15764 return regno | (elno << 4);
15766 default:
15767 bad_scalar:
15768 first_error (_("scalar out of range for multiply instruction"));
15771 return 0;
15774 /* Encode multiply / multiply-accumulate scalar instructions. */
15776 static void
15777 neon_mul_mac (struct neon_type_el et, int ubit)
15779 unsigned scalar;
15781 /* Give a more helpful error message if we have an invalid type. */
15782 if (et.type == NT_invtype)
15783 return;
15785 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
15786 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15787 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15788 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15789 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15790 inst.instruction |= LOW4 (scalar);
15791 inst.instruction |= HI1 (scalar) << 5;
15792 inst.instruction |= (et.type == NT_float) << 8;
15793 inst.instruction |= neon_logbits (et.size) << 20;
15794 inst.instruction |= (ubit != 0) << 24;
15796 neon_dp_fixup (&inst);
15799 static void
15800 do_neon_mac_maybe_scalar (void)
15802 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15803 return;
15805 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15806 return;
15808 if (inst.operands[2].isscalar)
15810 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15811 struct neon_type_el et = neon_check_type (3, rs,
15812 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
15813 NEON_ENCODE (SCALAR, inst);
15814 neon_mul_mac (et, neon_quad (rs));
15816 else
15818 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15819 affected if we specify unsigned args. */
15820 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15824 static void
15825 do_neon_fmac (void)
15827 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15828 return;
15830 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15831 return;
15833 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15836 static void
15837 do_neon_tst (void)
15839 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15840 struct neon_type_el et = neon_check_type (3, rs,
15841 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
15842 neon_three_same (neon_quad (rs), 0, et.size);
15845 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
15846 same types as the MAC equivalents. The polynomial type for this instruction
15847 is encoded the same as the integer type. */
15849 static void
15850 do_neon_mul (void)
15852 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15853 return;
15855 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15856 return;
15858 if (inst.operands[2].isscalar)
15859 do_neon_mac_maybe_scalar ();
15860 else
15861 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
15864 static void
15865 do_neon_qdmulh (void)
15867 if (inst.operands[2].isscalar)
15869 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15870 struct neon_type_el et = neon_check_type (3, rs,
15871 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15872 NEON_ENCODE (SCALAR, inst);
15873 neon_mul_mac (et, neon_quad (rs));
15875 else
15877 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15878 struct neon_type_el et = neon_check_type (3, rs,
15879 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15880 NEON_ENCODE (INTEGER, inst);
15881 /* The U bit (rounding) comes from bit mask. */
15882 neon_three_same (neon_quad (rs), 0, et.size);
15886 static void
15887 do_neon_qrdmlah (void)
15889 /* Check we're on the correct architecture. */
15890 if (!mark_feature_used (&fpu_neon_ext_armv8))
15891 inst.error =
15892 _("instruction form not available on this architecture.");
15893 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15895 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15896 record_feature_use (&fpu_neon_ext_v8_1);
15899 if (inst.operands[2].isscalar)
15901 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15902 struct neon_type_el et = neon_check_type (3, rs,
15903 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15904 NEON_ENCODE (SCALAR, inst);
15905 neon_mul_mac (et, neon_quad (rs));
15907 else
15909 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15910 struct neon_type_el et = neon_check_type (3, rs,
15911 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15912 NEON_ENCODE (INTEGER, inst);
15913 /* The U bit (rounding) comes from bit mask. */
15914 neon_three_same (neon_quad (rs), 0, et.size);
15918 static void
15919 do_neon_fcmp_absolute (void)
15921 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15922 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15923 N_F_16_32 | N_KEY);
15924 /* Size field comes from bit mask. */
15925 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
15928 static void
15929 do_neon_fcmp_absolute_inv (void)
15931 neon_exchange_operands ();
15932 do_neon_fcmp_absolute ();
15935 static void
15936 do_neon_step (void)
15938 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15939 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15940 N_F_16_32 | N_KEY);
15941 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
15944 static void
15945 do_neon_abs_neg (void)
15947 enum neon_shape rs;
15948 struct neon_type_el et;
15950 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15951 return;
15953 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15954 return;
15956 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15957 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
15959 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15960 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15961 inst.instruction |= LOW4 (inst.operands[1].reg);
15962 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15963 inst.instruction |= neon_quad (rs) << 6;
15964 inst.instruction |= (et.type == NT_float) << 10;
15965 inst.instruction |= neon_logbits (et.size) << 18;
15967 neon_dp_fixup (&inst);
15970 static void
15971 do_neon_sli (void)
15973 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15974 struct neon_type_el et = neon_check_type (2, rs,
15975 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15976 int imm = inst.operands[2].imm;
15977 constraint (imm < 0 || (unsigned)imm >= et.size,
15978 _("immediate out of range for insert"));
15979 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15982 static void
15983 do_neon_sri (void)
15985 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15986 struct neon_type_el et = neon_check_type (2, rs,
15987 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15988 int imm = inst.operands[2].imm;
15989 constraint (imm < 1 || (unsigned)imm > et.size,
15990 _("immediate out of range for insert"));
15991 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
15994 static void
15995 do_neon_qshlu_imm (void)
15997 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15998 struct neon_type_el et = neon_check_type (2, rs,
15999 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
16000 int imm = inst.operands[2].imm;
16001 constraint (imm < 0 || (unsigned)imm >= et.size,
16002 _("immediate out of range for shift"));
16003 /* Only encodes the 'U present' variant of the instruction.
16004 In this case, signed types have OP (bit 8) set to 0.
16005 Unsigned types have OP set to 1. */
16006 inst.instruction |= (et.type == NT_unsigned) << 8;
16007 /* The rest of the bits are the same as other immediate shifts. */
16008 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
16011 static void
16012 do_neon_qmovn (void)
16014 struct neon_type_el et = neon_check_type (2, NS_DQ,
16015 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16016 /* Saturating move where operands can be signed or unsigned, and the
16017 destination has the same signedness. */
16018 NEON_ENCODE (INTEGER, inst);
16019 if (et.type == NT_unsigned)
16020 inst.instruction |= 0xc0;
16021 else
16022 inst.instruction |= 0x80;
16023 neon_two_same (0, 1, et.size / 2);
16026 static void
16027 do_neon_qmovun (void)
16029 struct neon_type_el et = neon_check_type (2, NS_DQ,
16030 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16031 /* Saturating move with unsigned results. Operands must be signed. */
16032 NEON_ENCODE (INTEGER, inst);
16033 neon_two_same (0, 1, et.size / 2);
16036 static void
16037 do_neon_rshift_sat_narrow (void)
16039 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16040 or unsigned. If operands are unsigned, results must also be unsigned. */
16041 struct neon_type_el et = neon_check_type (2, NS_DQI,
16042 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
16043 int imm = inst.operands[2].imm;
16044 /* This gets the bounds check, size encoding and immediate bits calculation
16045 right. */
16046 et.size /= 2;
16048 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
16049 VQMOVN.I<size> <Dd>, <Qm>. */
16050 if (imm == 0)
16052 inst.operands[2].present = 0;
16053 inst.instruction = N_MNEM_vqmovn;
16054 do_neon_qmovn ();
16055 return;
16058 constraint (imm < 1 || (unsigned)imm > et.size,
16059 _("immediate out of range"));
16060 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
16063 static void
16064 do_neon_rshift_sat_narrow_u (void)
16066 /* FIXME: Types for narrowing. If operands are signed, results can be signed
16067 or unsigned. If operands are unsigned, results must also be unsigned. */
16068 struct neon_type_el et = neon_check_type (2, NS_DQI,
16069 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
16070 int imm = inst.operands[2].imm;
16071 /* This gets the bounds check, size encoding and immediate bits calculation
16072 right. */
16073 et.size /= 2;
16075 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
16076 VQMOVUN.I<size> <Dd>, <Qm>. */
16077 if (imm == 0)
16079 inst.operands[2].present = 0;
16080 inst.instruction = N_MNEM_vqmovun;
16081 do_neon_qmovun ();
16082 return;
16085 constraint (imm < 1 || (unsigned)imm > et.size,
16086 _("immediate out of range"));
16087 /* FIXME: The manual is kind of unclear about what value U should have in
16088 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
16089 must be 1. */
16090 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
16093 static void
16094 do_neon_movn (void)
16096 struct neon_type_el et = neon_check_type (2, NS_DQ,
16097 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
16098 NEON_ENCODE (INTEGER, inst);
16099 neon_two_same (0, 1, et.size / 2);
16102 static void
16103 do_neon_rshift_narrow (void)
16105 struct neon_type_el et = neon_check_type (2, NS_DQI,
16106 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
16107 int imm = inst.operands[2].imm;
16108 /* This gets the bounds check, size encoding and immediate bits calculation
16109 right. */
16110 et.size /= 2;
16112 /* If immediate is zero then we are a pseudo-instruction for
16113 VMOVN.I<size> <Dd>, <Qm> */
16114 if (imm == 0)
16116 inst.operands[2].present = 0;
16117 inst.instruction = N_MNEM_vmovn;
16118 do_neon_movn ();
16119 return;
16122 constraint (imm < 1 || (unsigned)imm > et.size,
16123 _("immediate out of range for narrowing operation"));
16124 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
16127 static void
16128 do_neon_shll (void)
16130 /* FIXME: Type checking when lengthening. */
16131 struct neon_type_el et = neon_check_type (2, NS_QDI,
16132 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
16133 unsigned imm = inst.operands[2].imm;
16135 if (imm == et.size)
16137 /* Maximum shift variant. */
16138 NEON_ENCODE (INTEGER, inst);
16139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16141 inst.instruction |= LOW4 (inst.operands[1].reg);
16142 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16143 inst.instruction |= neon_logbits (et.size) << 18;
16145 neon_dp_fixup (&inst);
16147 else
16149 /* A more-specific type check for non-max versions. */
16150 et = neon_check_type (2, NS_QDI,
16151 N_EQK | N_DBL, N_SU_32 | N_KEY);
16152 NEON_ENCODE (IMMED, inst);
16153 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
16157 /* Check the various types for the VCVT instruction, and return which version
16158 the current instruction is. */
16160 #define CVT_FLAVOUR_VAR \
16161 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
16162 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
16163 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
16164 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
16165 /* Half-precision conversions. */ \
16166 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16167 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
16168 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
16169 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
16170 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
16171 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
16172 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
16173 Compared with single/double precision variants, only the co-processor \
16174 field is different, so the encoding flow is reused here. */ \
16175 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
16176 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
16177 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
16178 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
16179 /* VFP instructions. */ \
16180 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
16181 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
16182 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
16183 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
16184 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
16185 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
16186 /* VFP instructions with bitshift. */ \
16187 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
16188 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
16189 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
16190 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
16191 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
16192 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
16193 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
16194 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
16196 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
16197 neon_cvt_flavour_##C,
16199 /* The different types of conversions we can do. */
16200 enum neon_cvt_flavour
16202 CVT_FLAVOUR_VAR
16203 neon_cvt_flavour_invalid,
16204 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
16207 #undef CVT_VAR
16209 static enum neon_cvt_flavour
16210 get_neon_cvt_flavour (enum neon_shape rs)
16212 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
16213 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
16214 if (et.type != NT_invtype) \
16216 inst.error = NULL; \
16217 return (neon_cvt_flavour_##C); \
16220 struct neon_type_el et;
16221 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
16222 || rs == NS_FF) ? N_VFP : 0;
16223 /* The instruction versions which take an immediate take one register
16224 argument, which is extended to the width of the full register. Thus the
16225 "source" and "destination" registers must have the same width. Hack that
16226 here by making the size equal to the key (wider, in this case) operand. */
16227 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
16229 CVT_FLAVOUR_VAR;
16231 return neon_cvt_flavour_invalid;
16232 #undef CVT_VAR
16235 enum neon_cvt_mode
16237 neon_cvt_mode_a,
16238 neon_cvt_mode_n,
16239 neon_cvt_mode_p,
16240 neon_cvt_mode_m,
16241 neon_cvt_mode_z,
16242 neon_cvt_mode_x,
16243 neon_cvt_mode_r
16246 /* Neon-syntax VFP conversions. */
16248 static void
16249 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
16251 const char *opname = 0;
16253 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
16254 || rs == NS_FHI || rs == NS_HFI)
16256 /* Conversions with immediate bitshift. */
16257 const char *enc[] =
16259 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
16260 CVT_FLAVOUR_VAR
16261 NULL
16262 #undef CVT_VAR
16265 if (flavour < (int) ARRAY_SIZE (enc))
16267 opname = enc[flavour];
16268 constraint (inst.operands[0].reg != inst.operands[1].reg,
16269 _("operands 0 and 1 must be the same register"));
16270 inst.operands[1] = inst.operands[2];
16271 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
16274 else
16276 /* Conversions without bitshift. */
16277 const char *enc[] =
16279 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
16280 CVT_FLAVOUR_VAR
16281 NULL
16282 #undef CVT_VAR
16285 if (flavour < (int) ARRAY_SIZE (enc))
16286 opname = enc[flavour];
16289 if (opname)
16290 do_vfp_nsyn_opcode (opname);
16292 /* ARMv8.2 fp16 VCVT instruction. */
16293 if (flavour == neon_cvt_flavour_s32_f16
16294 || flavour == neon_cvt_flavour_u32_f16
16295 || flavour == neon_cvt_flavour_f16_u32
16296 || flavour == neon_cvt_flavour_f16_s32)
16297 do_scalar_fp16_v82_encode ();
16300 static void
16301 do_vfp_nsyn_cvtz (void)
16303 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
16304 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
16305 const char *enc[] =
16307 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
16308 CVT_FLAVOUR_VAR
16309 NULL
16310 #undef CVT_VAR
16313 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
16314 do_vfp_nsyn_opcode (enc[flavour]);
16317 static void
16318 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
16319 enum neon_cvt_mode mode)
16321 int sz, op;
16322 int rm;
16324 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16325 D register operands. */
16326 if (flavour == neon_cvt_flavour_s32_f64
16327 || flavour == neon_cvt_flavour_u32_f64)
16328 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16329 _(BAD_FPU));
16331 if (flavour == neon_cvt_flavour_s32_f16
16332 || flavour == neon_cvt_flavour_u32_f16)
16333 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
16334 _(BAD_FP16));
16336 set_pred_insn_type (OUTSIDE_PRED_INSN);
16338 switch (flavour)
16340 case neon_cvt_flavour_s32_f64:
16341 sz = 1;
16342 op = 1;
16343 break;
16344 case neon_cvt_flavour_s32_f32:
16345 sz = 0;
16346 op = 1;
16347 break;
16348 case neon_cvt_flavour_s32_f16:
16349 sz = 0;
16350 op = 1;
16351 break;
16352 case neon_cvt_flavour_u32_f64:
16353 sz = 1;
16354 op = 0;
16355 break;
16356 case neon_cvt_flavour_u32_f32:
16357 sz = 0;
16358 op = 0;
16359 break;
16360 case neon_cvt_flavour_u32_f16:
16361 sz = 0;
16362 op = 0;
16363 break;
16364 default:
16365 first_error (_("invalid instruction shape"));
16366 return;
16369 switch (mode)
16371 case neon_cvt_mode_a: rm = 0; break;
16372 case neon_cvt_mode_n: rm = 1; break;
16373 case neon_cvt_mode_p: rm = 2; break;
16374 case neon_cvt_mode_m: rm = 3; break;
16375 default: first_error (_("invalid rounding mode")); return;
16378 NEON_ENCODE (FPV8, inst);
16379 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
16380 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
16381 inst.instruction |= sz << 8;
16383 /* ARMv8.2 fp16 VCVT instruction. */
16384 if (flavour == neon_cvt_flavour_s32_f16
16385 ||flavour == neon_cvt_flavour_u32_f16)
16386 do_scalar_fp16_v82_encode ();
16387 inst.instruction |= op << 7;
16388 inst.instruction |= rm << 16;
16389 inst.instruction |= 0xf0000000;
16390 inst.is_neon = TRUE;
16393 static void
16394 do_neon_cvt_1 (enum neon_cvt_mode mode)
16396 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
16397 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
16398 NS_FH, NS_HF, NS_FHI, NS_HFI,
16399 NS_NULL);
16400 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
16402 if (flavour == neon_cvt_flavour_invalid)
16403 return;
16405 /* PR11109: Handle round-to-zero for VCVT conversions. */
16406 if (mode == neon_cvt_mode_z
16407 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
16408 && (flavour == neon_cvt_flavour_s16_f16
16409 || flavour == neon_cvt_flavour_u16_f16
16410 || flavour == neon_cvt_flavour_s32_f32
16411 || flavour == neon_cvt_flavour_u32_f32
16412 || flavour == neon_cvt_flavour_s32_f64
16413 || flavour == neon_cvt_flavour_u32_f64)
16414 && (rs == NS_FD || rs == NS_FF))
16416 do_vfp_nsyn_cvtz ();
16417 return;
16420 /* ARMv8.2 fp16 VCVT conversions. */
16421 if (mode == neon_cvt_mode_z
16422 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
16423 && (flavour == neon_cvt_flavour_s32_f16
16424 || flavour == neon_cvt_flavour_u32_f16)
16425 && (rs == NS_FH))
16427 do_vfp_nsyn_cvtz ();
16428 do_scalar_fp16_v82_encode ();
16429 return;
16432 /* VFP rather than Neon conversions. */
16433 if (flavour >= neon_cvt_flavour_first_fp)
16435 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16436 do_vfp_nsyn_cvt (rs, flavour);
16437 else
16438 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16440 return;
16443 switch (rs)
16445 case NS_DDI:
16446 case NS_QQI:
16448 unsigned immbits;
16449 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
16450 0x0000100, 0x1000100, 0x0, 0x1000000};
16452 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16453 return;
16455 /* Fixed-point conversion with #0 immediate is encoded as an
16456 integer conversion. */
16457 if (inst.operands[2].present && inst.operands[2].imm == 0)
16458 goto int_encode;
16459 NEON_ENCODE (IMMED, inst);
16460 if (flavour != neon_cvt_flavour_invalid)
16461 inst.instruction |= enctab[flavour];
16462 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16463 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16464 inst.instruction |= LOW4 (inst.operands[1].reg);
16465 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16466 inst.instruction |= neon_quad (rs) << 6;
16467 inst.instruction |= 1 << 21;
16468 if (flavour < neon_cvt_flavour_s16_f16)
16470 inst.instruction |= 1 << 21;
16471 immbits = 32 - inst.operands[2].imm;
16472 inst.instruction |= immbits << 16;
16474 else
16476 inst.instruction |= 3 << 20;
16477 immbits = 16 - inst.operands[2].imm;
16478 inst.instruction |= immbits << 16;
16479 inst.instruction &= ~(1 << 9);
16482 neon_dp_fixup (&inst);
16484 break;
16486 case NS_DD:
16487 case NS_QQ:
16488 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
16490 NEON_ENCODE (FLOAT, inst);
16491 set_pred_insn_type (OUTSIDE_PRED_INSN);
16493 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16494 return;
16496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16498 inst.instruction |= LOW4 (inst.operands[1].reg);
16499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16500 inst.instruction |= neon_quad (rs) << 6;
16501 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
16502 || flavour == neon_cvt_flavour_u32_f32) << 7;
16503 inst.instruction |= mode << 8;
16504 if (flavour == neon_cvt_flavour_u16_f16
16505 || flavour == neon_cvt_flavour_s16_f16)
16506 /* Mask off the original size bits and reencode them. */
16507 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
16509 if (thumb_mode)
16510 inst.instruction |= 0xfc000000;
16511 else
16512 inst.instruction |= 0xf0000000;
16514 else
16516 int_encode:
16518 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
16519 0x100, 0x180, 0x0, 0x080};
16521 NEON_ENCODE (INTEGER, inst);
16523 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16524 return;
16526 if (flavour != neon_cvt_flavour_invalid)
16527 inst.instruction |= enctab[flavour];
16529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16531 inst.instruction |= LOW4 (inst.operands[1].reg);
16532 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16533 inst.instruction |= neon_quad (rs) << 6;
16534 if (flavour >= neon_cvt_flavour_s16_f16
16535 && flavour <= neon_cvt_flavour_f16_u16)
16536 /* Half precision. */
16537 inst.instruction |= 1 << 18;
16538 else
16539 inst.instruction |= 2 << 18;
16541 neon_dp_fixup (&inst);
16544 break;
16546 /* Half-precision conversions for Advanced SIMD -- neon. */
16547 case NS_QD:
16548 case NS_DQ:
16549 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16550 return;
16552 if ((rs == NS_DQ)
16553 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
16555 as_bad (_("operand size must match register width"));
16556 break;
16559 if ((rs == NS_QD)
16560 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
16562 as_bad (_("operand size must match register width"));
16563 break;
16566 if (rs == NS_DQ)
16567 inst.instruction = 0x3b60600;
16568 else
16569 inst.instruction = 0x3b60700;
16571 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16572 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16573 inst.instruction |= LOW4 (inst.operands[1].reg);
16574 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16575 neon_dp_fixup (&inst);
16576 break;
16578 default:
16579 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
16580 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16581 do_vfp_nsyn_cvt (rs, flavour);
16582 else
16583 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16587 static void
16588 do_neon_cvtr (void)
16590 do_neon_cvt_1 (neon_cvt_mode_x);
16593 static void
16594 do_neon_cvt (void)
16596 do_neon_cvt_1 (neon_cvt_mode_z);
16599 static void
16600 do_neon_cvta (void)
16602 do_neon_cvt_1 (neon_cvt_mode_a);
16605 static void
16606 do_neon_cvtn (void)
16608 do_neon_cvt_1 (neon_cvt_mode_n);
16611 static void
16612 do_neon_cvtp (void)
16614 do_neon_cvt_1 (neon_cvt_mode_p);
16617 static void
16618 do_neon_cvtm (void)
16620 do_neon_cvt_1 (neon_cvt_mode_m);
16623 static void
16624 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
16626 if (is_double)
16627 mark_feature_used (&fpu_vfp_ext_armv8);
16629 encode_arm_vfp_reg (inst.operands[0].reg,
16630 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16631 encode_arm_vfp_reg (inst.operands[1].reg,
16632 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16633 inst.instruction |= to ? 0x10000 : 0;
16634 inst.instruction |= t ? 0x80 : 0;
16635 inst.instruction |= is_double ? 0x100 : 0;
16636 do_vfp_cond_or_thumb ();
16639 static void
16640 do_neon_cvttb_1 (bfd_boolean t)
16642 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16643 NS_DF, NS_DH, NS_NULL);
16645 if (rs == NS_NULL)
16646 return;
16647 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16649 inst.error = NULL;
16650 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16652 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16654 inst.error = NULL;
16655 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16657 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16659 /* The VCVTB and VCVTT instructions with D-register operands
16660 don't work for SP only targets. */
16661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16662 _(BAD_FPU));
16664 inst.error = NULL;
16665 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16667 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16669 /* The VCVTB and VCVTT instructions with D-register operands
16670 don't work for SP only targets. */
16671 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16672 _(BAD_FPU));
16674 inst.error = NULL;
16675 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16677 else
16678 return;
16681 static void
16682 do_neon_cvtb (void)
16684 do_neon_cvttb_1 (FALSE);
16688 static void
16689 do_neon_cvtt (void)
16691 do_neon_cvttb_1 (TRUE);
16694 static void
16695 neon_move_immediate (void)
16697 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16698 struct neon_type_el et = neon_check_type (2, rs,
16699 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
16700 unsigned immlo, immhi = 0, immbits;
16701 int op, cmode, float_p;
16703 constraint (et.type == NT_invtype,
16704 _("operand size must be specified for immediate VMOV"));
16706 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16707 op = (inst.instruction & (1 << 5)) != 0;
16709 immlo = inst.operands[1].imm;
16710 if (inst.operands[1].regisimm)
16711 immhi = inst.operands[1].reg;
16713 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
16714 _("immediate has bits set outside the operand size"));
16716 float_p = inst.operands[1].immisfloat;
16718 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
16719 et.size, et.type)) == FAIL)
16721 /* Invert relevant bits only. */
16722 neon_invert_size (&immlo, &immhi, et.size);
16723 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
16724 with one or the other; those cases are caught by
16725 neon_cmode_for_move_imm. */
16726 op = !op;
16727 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16728 &op, et.size, et.type)) == FAIL)
16730 first_error (_("immediate out of range"));
16731 return;
16735 inst.instruction &= ~(1 << 5);
16736 inst.instruction |= op << 5;
16738 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16739 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16740 inst.instruction |= neon_quad (rs) << 6;
16741 inst.instruction |= cmode << 8;
16743 neon_write_immbits (immbits);
16746 static void
16747 do_neon_mvn (void)
16749 if (inst.operands[1].isreg)
16751 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16753 NEON_ENCODE (INTEGER, inst);
16754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16756 inst.instruction |= LOW4 (inst.operands[1].reg);
16757 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16758 inst.instruction |= neon_quad (rs) << 6;
16760 else
16762 NEON_ENCODE (IMMED, inst);
16763 neon_move_immediate ();
16766 neon_dp_fixup (&inst);
16769 /* Encode instructions of form:
16771 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16772 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
16774 static void
16775 neon_mixed_length (struct neon_type_el et, unsigned size)
16777 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16778 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16779 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16780 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16781 inst.instruction |= LOW4 (inst.operands[2].reg);
16782 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16783 inst.instruction |= (et.type == NT_unsigned) << 24;
16784 inst.instruction |= neon_logbits (size) << 20;
16786 neon_dp_fixup (&inst);
16789 static void
16790 do_neon_dyadic_long (void)
16792 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
16793 if (rs == NS_QDD)
16795 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
16796 return;
16798 NEON_ENCODE (INTEGER, inst);
16799 /* FIXME: Type checking for lengthening op. */
16800 struct neon_type_el et = neon_check_type (3, NS_QDD,
16801 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16802 neon_mixed_length (et, et.size);
16804 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
16805 && (inst.cond == 0xf || inst.cond == 0x10))
16807 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
16808 in an IT block with le/lt conditions. */
16810 if (inst.cond == 0xf)
16811 inst.cond = 0xb;
16812 else if (inst.cond == 0x10)
16813 inst.cond = 0xd;
16815 inst.pred_insn_type = INSIDE_IT_INSN;
16817 if (inst.instruction == N_MNEM_vaddl)
16819 inst.instruction = N_MNEM_vadd;
16820 do_neon_addsub_if_i ();
16822 else if (inst.instruction == N_MNEM_vsubl)
16824 inst.instruction = N_MNEM_vsub;
16825 do_neon_addsub_if_i ();
16827 else if (inst.instruction == N_MNEM_vabdl)
16829 inst.instruction = N_MNEM_vabd;
16830 do_neon_dyadic_if_su ();
16833 else
16834 first_error (BAD_FPU);
16837 static void
16838 do_neon_abal (void)
16840 struct neon_type_el et = neon_check_type (3, NS_QDD,
16841 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16842 neon_mixed_length (et, et.size);
16845 static void
16846 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16848 if (inst.operands[2].isscalar)
16850 struct neon_type_el et = neon_check_type (3, NS_QDS,
16851 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
16852 NEON_ENCODE (SCALAR, inst);
16853 neon_mul_mac (et, et.type == NT_unsigned);
16855 else
16857 struct neon_type_el et = neon_check_type (3, NS_QDD,
16858 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
16859 NEON_ENCODE (INTEGER, inst);
16860 neon_mixed_length (et, et.size);
16864 static void
16865 do_neon_mac_maybe_scalar_long (void)
16867 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16870 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16871 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16873 static unsigned
16874 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16876 unsigned regno = NEON_SCALAR_REG (scalar);
16877 unsigned elno = NEON_SCALAR_INDEX (scalar);
16879 if (quad_p)
16881 if (regno > 7 || elno > 3)
16882 goto bad_scalar;
16884 return ((regno & 0x7)
16885 | ((elno & 0x1) << 3)
16886 | (((elno >> 1) & 0x1) << 5));
16888 else
16890 if (regno > 15 || elno > 1)
16891 goto bad_scalar;
16893 return (((regno & 0x1) << 5)
16894 | ((regno >> 1) & 0x7)
16895 | ((elno & 0x1) << 3));
16898 bad_scalar:
16899 first_error (_("scalar out of range for multiply instruction"));
16900 return 0;
16903 static void
16904 do_neon_fmac_maybe_scalar_long (int subtype)
16906 enum neon_shape rs;
16907 int high8;
16908 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16909 field (bits[21:20]) has different meaning. For scalar index variant, it's
16910 used to differentiate add and subtract, otherwise it's with fixed value
16911 0x2. */
16912 int size = -1;
16914 if (inst.cond != COND_ALWAYS)
16915 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16916 "behaviour is UNPREDICTABLE"));
16918 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
16919 _(BAD_FP16));
16921 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16922 _(BAD_FPU));
16924 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16925 be a scalar index register. */
16926 if (inst.operands[2].isscalar)
16928 high8 = 0xfe000000;
16929 if (subtype)
16930 size = 16;
16931 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16933 else
16935 high8 = 0xfc000000;
16936 size = 32;
16937 if (subtype)
16938 inst.instruction |= (0x1 << 23);
16939 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16942 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16944 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16945 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16946 so we simply pass -1 as size. */
16947 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16948 neon_three_same (quad_p, 0, size);
16950 /* Undo neon_dp_fixup. Redo the high eight bits. */
16951 inst.instruction &= 0x00ffffff;
16952 inst.instruction |= high8;
16954 #define LOW1(R) ((R) & 0x1)
16955 #define HI4(R) (((R) >> 1) & 0xf)
16956 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16957 whether the instruction is in Q form and whether Vm is a scalar indexed
16958 operand. */
16959 if (inst.operands[2].isscalar)
16961 unsigned rm
16962 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16963 inst.instruction &= 0xffffffd0;
16964 inst.instruction |= rm;
16966 if (!quad_p)
16968 /* Redo Rn as well. */
16969 inst.instruction &= 0xfff0ff7f;
16970 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16971 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16974 else if (!quad_p)
16976 /* Redo Rn and Rm. */
16977 inst.instruction &= 0xfff0ff50;
16978 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16979 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16980 inst.instruction |= HI4 (inst.operands[2].reg);
16981 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16985 static void
16986 do_neon_vfmal (void)
16988 return do_neon_fmac_maybe_scalar_long (0);
16991 static void
16992 do_neon_vfmsl (void)
16994 return do_neon_fmac_maybe_scalar_long (1);
16997 static void
16998 do_neon_dyadic_wide (void)
17000 struct neon_type_el et = neon_check_type (3, NS_QQD,
17001 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
17002 neon_mixed_length (et, et.size);
17005 static void
17006 do_neon_dyadic_narrow (void)
17008 struct neon_type_el et = neon_check_type (3, NS_QDD,
17009 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
17010 /* Operand sign is unimportant, and the U bit is part of the opcode,
17011 so force the operand type to integer. */
17012 et.type = NT_integer;
17013 neon_mixed_length (et, et.size / 2);
17016 static void
17017 do_neon_mul_sat_scalar_long (void)
17019 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
17022 static void
17023 do_neon_vmull (void)
17025 if (inst.operands[2].isscalar)
17026 do_neon_mac_maybe_scalar_long ();
17027 else
17029 struct neon_type_el et = neon_check_type (3, NS_QDD,
17030 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
17032 if (et.type == NT_poly)
17033 NEON_ENCODE (POLY, inst);
17034 else
17035 NEON_ENCODE (INTEGER, inst);
17037 /* For polynomial encoding the U bit must be zero, and the size must
17038 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
17039 obviously, as 0b10). */
17040 if (et.size == 64)
17042 /* Check we're on the correct architecture. */
17043 if (!mark_feature_used (&fpu_crypto_ext_armv8))
17044 inst.error =
17045 _("Instruction form not available on this architecture.");
17047 et.size = 32;
17050 neon_mixed_length (et, et.size);
17054 static void
17055 do_neon_ext (void)
17057 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17058 struct neon_type_el et = neon_check_type (3, rs,
17059 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
17060 unsigned imm = (inst.operands[3].imm * et.size) / 8;
17062 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
17063 _("shift out of range"));
17064 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17065 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17066 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17067 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17068 inst.instruction |= LOW4 (inst.operands[2].reg);
17069 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17070 inst.instruction |= neon_quad (rs) << 6;
17071 inst.instruction |= imm << 8;
17073 neon_dp_fixup (&inst);
17076 static void
17077 do_neon_rev (void)
17079 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17080 struct neon_type_el et = neon_check_type (2, rs,
17081 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17082 unsigned op = (inst.instruction >> 7) & 3;
17083 /* N (width of reversed regions) is encoded as part of the bitmask. We
17084 extract it here to check the elements to be reversed are smaller.
17085 Otherwise we'd get a reserved instruction. */
17086 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
17087 gas_assert (elsize != 0);
17088 constraint (et.size >= elsize,
17089 _("elements must be smaller than reversal region"));
17090 neon_two_same (neon_quad (rs), 1, et.size);
17093 static void
17094 do_neon_dup (void)
17096 if (inst.operands[1].isscalar)
17098 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
17099 struct neon_type_el et = neon_check_type (2, rs,
17100 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17101 unsigned sizebits = et.size >> 3;
17102 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
17103 int logsize = neon_logbits (et.size);
17104 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
17106 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
17107 return;
17109 NEON_ENCODE (SCALAR, inst);
17110 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17111 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17112 inst.instruction |= LOW4 (dm);
17113 inst.instruction |= HI1 (dm) << 5;
17114 inst.instruction |= neon_quad (rs) << 6;
17115 inst.instruction |= x << 17;
17116 inst.instruction |= sizebits << 16;
17118 neon_dp_fixup (&inst);
17120 else
17122 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
17123 struct neon_type_el et = neon_check_type (2, rs,
17124 N_8 | N_16 | N_32 | N_KEY, N_EQK);
17125 /* Duplicate ARM register to lanes of vector. */
17126 NEON_ENCODE (ARMREG, inst);
17127 switch (et.size)
17129 case 8: inst.instruction |= 0x400000; break;
17130 case 16: inst.instruction |= 0x000020; break;
17131 case 32: inst.instruction |= 0x000000; break;
17132 default: break;
17134 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17135 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
17136 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
17137 inst.instruction |= neon_quad (rs) << 21;
17138 /* The encoding for this instruction is identical for the ARM and Thumb
17139 variants, except for the condition field. */
17140 do_vfp_cond_or_thumb ();
17144 /* VMOV has particularly many variations. It can be one of:
17145 0. VMOV<c><q> <Qd>, <Qm>
17146 1. VMOV<c><q> <Dd>, <Dm>
17147 (Register operations, which are VORR with Rm = Rn.)
17148 2. VMOV<c><q>.<dt> <Qd>, #<imm>
17149 3. VMOV<c><q>.<dt> <Dd>, #<imm>
17150 (Immediate loads.)
17151 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
17152 (ARM register to scalar.)
17153 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
17154 (Two ARM registers to vector.)
17155 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
17156 (Scalar to ARM register.)
17157 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
17158 (Vector to two ARM registers.)
17159 8. VMOV.F32 <Sd>, <Sm>
17160 9. VMOV.F64 <Dd>, <Dm>
17161 (VFP register moves.)
17162 10. VMOV.F32 <Sd>, #imm
17163 11. VMOV.F64 <Dd>, #imm
17164 (VFP float immediate load.)
17165 12. VMOV <Rd>, <Sm>
17166 (VFP single to ARM reg.)
17167 13. VMOV <Sd>, <Rm>
17168 (ARM reg to VFP single.)
17169 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
17170 (Two ARM regs to two VFP singles.)
17171 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
17172 (Two VFP singles to two ARM regs.)
17174 These cases can be disambiguated using neon_select_shape, except cases 1/9
17175 and 3/11 which depend on the operand type too.
17177 All the encoded bits are hardcoded by this function.
17179 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
17180 Cases 5, 7 may be used with VFPv2 and above.
17182 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
17183 can specify a type where it doesn't make sense to, and is ignored). */
17185 static void
17186 do_neon_mov (void)
17188 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
17189 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
17190 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
17191 NS_HR, NS_RH, NS_HI, NS_NULL);
17192 struct neon_type_el et;
17193 const char *ldconst = 0;
17195 switch (rs)
17197 case NS_DD: /* case 1/9. */
17198 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17199 /* It is not an error here if no type is given. */
17200 inst.error = NULL;
17201 if (et.type == NT_float && et.size == 64)
17203 do_vfp_nsyn_opcode ("fcpyd");
17204 break;
17206 /* fall through. */
17208 case NS_QQ: /* case 0/1. */
17210 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17211 return;
17212 /* The architecture manual I have doesn't explicitly state which
17213 value the U bit should have for register->register moves, but
17214 the equivalent VORR instruction has U = 0, so do that. */
17215 inst.instruction = 0x0200110;
17216 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17217 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17218 inst.instruction |= LOW4 (inst.operands[1].reg);
17219 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17220 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17221 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17222 inst.instruction |= neon_quad (rs) << 6;
17224 neon_dp_fixup (&inst);
17226 break;
17228 case NS_DI: /* case 3/11. */
17229 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
17230 inst.error = NULL;
17231 if (et.type == NT_float && et.size == 64)
17233 /* case 11 (fconstd). */
17234 ldconst = "fconstd";
17235 goto encode_fconstd;
17237 /* fall through. */
17239 case NS_QI: /* case 2/3. */
17240 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17241 return;
17242 inst.instruction = 0x0800010;
17243 neon_move_immediate ();
17244 neon_dp_fixup (&inst);
17245 break;
17247 case NS_SR: /* case 4. */
17249 unsigned bcdebits = 0;
17250 int logsize;
17251 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
17252 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
17254 /* .<size> is optional here, defaulting to .32. */
17255 if (inst.vectype.elems == 0
17256 && inst.operands[0].vectype.type == NT_invtype
17257 && inst.operands[1].vectype.type == NT_invtype)
17259 inst.vectype.el[0].type = NT_untyped;
17260 inst.vectype.el[0].size = 32;
17261 inst.vectype.elems = 1;
17264 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
17265 logsize = neon_logbits (et.size);
17267 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17268 _(BAD_FPU));
17269 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17270 && et.size != 32, _(BAD_FPU));
17271 constraint (et.type == NT_invtype, _("bad type for scalar"));
17272 constraint (x >= 64 / et.size, _("scalar index out of range"));
17274 switch (et.size)
17276 case 8: bcdebits = 0x8; break;
17277 case 16: bcdebits = 0x1; break;
17278 case 32: bcdebits = 0x0; break;
17279 default: ;
17282 bcdebits |= x << logsize;
17284 inst.instruction = 0xe000b10;
17285 do_vfp_cond_or_thumb ();
17286 inst.instruction |= LOW4 (dn) << 16;
17287 inst.instruction |= HI1 (dn) << 7;
17288 inst.instruction |= inst.operands[1].reg << 12;
17289 inst.instruction |= (bcdebits & 3) << 5;
17290 inst.instruction |= (bcdebits >> 2) << 21;
17292 break;
17294 case NS_DRR: /* case 5 (fmdrr). */
17295 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
17296 _(BAD_FPU));
17298 inst.instruction = 0xc400b10;
17299 do_vfp_cond_or_thumb ();
17300 inst.instruction |= LOW4 (inst.operands[0].reg);
17301 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
17302 inst.instruction |= inst.operands[1].reg << 12;
17303 inst.instruction |= inst.operands[2].reg << 16;
17304 break;
17306 case NS_RS: /* case 6. */
17308 unsigned logsize;
17309 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
17310 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
17311 unsigned abcdebits = 0;
17313 /* .<dt> is optional here, defaulting to .32. */
17314 if (inst.vectype.elems == 0
17315 && inst.operands[0].vectype.type == NT_invtype
17316 && inst.operands[1].vectype.type == NT_invtype)
17318 inst.vectype.el[0].type = NT_untyped;
17319 inst.vectype.el[0].size = 32;
17320 inst.vectype.elems = 1;
17323 et = neon_check_type (2, NS_NULL,
17324 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
17325 logsize = neon_logbits (et.size);
17327 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
17328 _(BAD_FPU));
17329 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
17330 && et.size != 32, _(BAD_FPU));
17331 constraint (et.type == NT_invtype, _("bad type for scalar"));
17332 constraint (x >= 64 / et.size, _("scalar index out of range"));
17334 switch (et.size)
17336 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
17337 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
17338 case 32: abcdebits = 0x00; break;
17339 default: ;
17342 abcdebits |= x << logsize;
17343 inst.instruction = 0xe100b10;
17344 do_vfp_cond_or_thumb ();
17345 inst.instruction |= LOW4 (dn) << 16;
17346 inst.instruction |= HI1 (dn) << 7;
17347 inst.instruction |= inst.operands[0].reg << 12;
17348 inst.instruction |= (abcdebits & 3) << 5;
17349 inst.instruction |= (abcdebits >> 2) << 21;
17351 break;
17353 case NS_RRD: /* case 7 (fmrrd). */
17354 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
17355 _(BAD_FPU));
17357 inst.instruction = 0xc500b10;
17358 do_vfp_cond_or_thumb ();
17359 inst.instruction |= inst.operands[0].reg << 12;
17360 inst.instruction |= inst.operands[1].reg << 16;
17361 inst.instruction |= LOW4 (inst.operands[2].reg);
17362 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17363 break;
17365 case NS_FF: /* case 8 (fcpys). */
17366 do_vfp_nsyn_opcode ("fcpys");
17367 break;
17369 case NS_HI:
17370 case NS_FI: /* case 10 (fconsts). */
17371 ldconst = "fconsts";
17372 encode_fconstd:
17373 if (!inst.operands[1].immisfloat)
17375 unsigned new_imm;
17376 /* Immediate has to fit in 8 bits so float is enough. */
17377 float imm = (float) inst.operands[1].imm;
17378 memcpy (&new_imm, &imm, sizeof (float));
17379 /* But the assembly may have been written to provide an integer
17380 bit pattern that equates to a float, so check that the
17381 conversion has worked. */
17382 if (is_quarter_float (new_imm))
17384 if (is_quarter_float (inst.operands[1].imm))
17385 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
17387 inst.operands[1].imm = new_imm;
17388 inst.operands[1].immisfloat = 1;
17392 if (is_quarter_float (inst.operands[1].imm))
17394 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
17395 do_vfp_nsyn_opcode (ldconst);
17397 /* ARMv8.2 fp16 vmov.f16 instruction. */
17398 if (rs == NS_HI)
17399 do_scalar_fp16_v82_encode ();
17401 else
17402 first_error (_("immediate out of range"));
17403 break;
17405 case NS_RH:
17406 case NS_RF: /* case 12 (fmrs). */
17407 do_vfp_nsyn_opcode ("fmrs");
17408 /* ARMv8.2 fp16 vmov.f16 instruction. */
17409 if (rs == NS_RH)
17410 do_scalar_fp16_v82_encode ();
17411 break;
17413 case NS_HR:
17414 case NS_FR: /* case 13 (fmsr). */
17415 do_vfp_nsyn_opcode ("fmsr");
17416 /* ARMv8.2 fp16 vmov.f16 instruction. */
17417 if (rs == NS_HR)
17418 do_scalar_fp16_v82_encode ();
17419 break;
17421 /* The encoders for the fmrrs and fmsrr instructions expect three operands
17422 (one of which is a list), but we have parsed four. Do some fiddling to
17423 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
17424 expect. */
17425 case NS_RRFF: /* case 14 (fmrrs). */
17426 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
17427 _("VFP registers must be adjacent"));
17428 inst.operands[2].imm = 2;
17429 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17430 do_vfp_nsyn_opcode ("fmrrs");
17431 break;
17433 case NS_FFRR: /* case 15 (fmsrr). */
17434 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
17435 _("VFP registers must be adjacent"));
17436 inst.operands[1] = inst.operands[2];
17437 inst.operands[2] = inst.operands[3];
17438 inst.operands[0].imm = 2;
17439 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
17440 do_vfp_nsyn_opcode ("fmsrr");
17441 break;
17443 case NS_NULL:
17444 /* neon_select_shape has determined that the instruction
17445 shape is wrong and has already set the error message. */
17446 break;
17448 default:
17449 abort ();
17453 static void
17454 do_neon_rshift_round_imm (void)
17456 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17457 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17458 int imm = inst.operands[2].imm;
17460 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
17461 if (imm == 0)
17463 inst.operands[2].present = 0;
17464 do_neon_mov ();
17465 return;
17468 constraint (imm < 1 || (unsigned)imm > et.size,
17469 _("immediate out of range for shift"));
17470 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
17471 et.size - imm);
17474 static void
17475 do_neon_movhf (void)
17477 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
17478 constraint (rs != NS_HH, _("invalid suffix"));
17480 if (inst.cond != COND_ALWAYS)
17482 if (thumb_mode)
17484 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
17485 " the behaviour is UNPREDICTABLE"));
17487 else
17489 inst.error = BAD_COND;
17490 return;
17494 do_vfp_sp_monadic ();
17496 inst.is_neon = 1;
17497 inst.instruction |= 0xf0000000;
17500 static void
17501 do_neon_movl (void)
17503 struct neon_type_el et = neon_check_type (2, NS_QD,
17504 N_EQK | N_DBL, N_SU_32 | N_KEY);
17505 unsigned sizebits = et.size >> 3;
17506 inst.instruction |= sizebits << 19;
17507 neon_two_same (0, et.type == NT_unsigned, -1);
17510 static void
17511 do_neon_trn (void)
17513 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17514 struct neon_type_el et = neon_check_type (2, rs,
17515 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17516 NEON_ENCODE (INTEGER, inst);
17517 neon_two_same (neon_quad (rs), 1, et.size);
17520 static void
17521 do_neon_zip_uzp (void)
17523 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17524 struct neon_type_el et = neon_check_type (2, rs,
17525 N_EQK, N_8 | N_16 | N_32 | N_KEY);
17526 if (rs == NS_DD && et.size == 32)
17528 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
17529 inst.instruction = N_MNEM_vtrn;
17530 do_neon_trn ();
17531 return;
17533 neon_two_same (neon_quad (rs), 1, et.size);
17536 static void
17537 do_neon_sat_abs_neg (void)
17539 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17540 struct neon_type_el et = neon_check_type (2, rs,
17541 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17542 neon_two_same (neon_quad (rs), 1, et.size);
17545 static void
17546 do_neon_pair_long (void)
17548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17549 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17550 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
17551 inst.instruction |= (et.type == NT_unsigned) << 7;
17552 neon_two_same (neon_quad (rs), 1, et.size);
17555 static void
17556 do_neon_recip_est (void)
17558 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17559 struct neon_type_el et = neon_check_type (2, rs,
17560 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
17561 inst.instruction |= (et.type == NT_float) << 8;
17562 neon_two_same (neon_quad (rs), 1, et.size);
17565 static void
17566 do_neon_cls (void)
17568 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17569 struct neon_type_el et = neon_check_type (2, rs,
17570 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17571 neon_two_same (neon_quad (rs), 1, et.size);
17574 static void
17575 do_neon_clz (void)
17577 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17578 struct neon_type_el et = neon_check_type (2, rs,
17579 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
17580 neon_two_same (neon_quad (rs), 1, et.size);
17583 static void
17584 do_neon_cnt (void)
17586 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17587 struct neon_type_el et = neon_check_type (2, rs,
17588 N_EQK | N_INT, N_8 | N_KEY);
17589 neon_two_same (neon_quad (rs), 1, et.size);
17592 static void
17593 do_neon_swp (void)
17595 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
17596 neon_two_same (neon_quad (rs), 1, -1);
17599 static void
17600 do_neon_tbl_tbx (void)
17602 unsigned listlenbits;
17603 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
17605 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
17607 first_error (_("bad list length for table lookup"));
17608 return;
17611 listlenbits = inst.operands[1].imm - 1;
17612 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17613 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17614 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17615 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17616 inst.instruction |= LOW4 (inst.operands[2].reg);
17617 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
17618 inst.instruction |= listlenbits << 8;
17620 neon_dp_fixup (&inst);
17623 static void
17624 do_neon_ldm_stm (void)
17626 /* P, U and L bits are part of bitmask. */
17627 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17628 unsigned offsetbits = inst.operands[1].imm * 2;
17630 if (inst.operands[1].issingle)
17632 do_vfp_nsyn_ldm_stm (is_dbmode);
17633 return;
17636 constraint (is_dbmode && !inst.operands[0].writeback,
17637 _("writeback (!) must be used for VLDMDB and VSTMDB"));
17639 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
17640 _("register list must contain at least 1 and at most 16 "
17641 "registers"));
17643 inst.instruction |= inst.operands[0].reg << 16;
17644 inst.instruction |= inst.operands[0].writeback << 21;
17645 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17646 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17648 inst.instruction |= offsetbits;
17650 do_vfp_cond_or_thumb ();
17653 static void
17654 do_neon_ldr_str (void)
17656 int is_ldr = (inst.instruction & (1 << 20)) != 0;
17658 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17659 And is UNPREDICTABLE in thumb mode. */
17660 if (!is_ldr
17661 && inst.operands[1].reg == REG_PC
17662 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
17664 if (thumb_mode)
17665 inst.error = _("Use of PC here is UNPREDICTABLE");
17666 else if (warn_on_deprecated)
17667 as_tsktsk (_("Use of PC here is deprecated"));
17670 if (inst.operands[0].issingle)
17672 if (is_ldr)
17673 do_vfp_nsyn_opcode ("flds");
17674 else
17675 do_vfp_nsyn_opcode ("fsts");
17677 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17678 if (inst.vectype.el[0].size == 16)
17679 do_scalar_fp16_v82_encode ();
17681 else
17683 if (is_ldr)
17684 do_vfp_nsyn_opcode ("fldd");
17685 else
17686 do_vfp_nsyn_opcode ("fstd");
17690 static void
17691 do_t_vldr_vstr_sysreg (void)
17693 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
17694 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
17696 /* Use of PC is UNPREDICTABLE. */
17697 if (inst.operands[1].reg == REG_PC)
17698 inst.error = _("Use of PC here is UNPREDICTABLE");
17700 if (inst.operands[1].immisreg)
17701 inst.error = _("instruction does not accept register index");
17703 if (!inst.operands[1].isreg)
17704 inst.error = _("instruction does not accept PC-relative addressing");
17706 if (abs (inst.operands[1].imm) >= (1 << 7))
17707 inst.error = _("immediate value out of range");
17709 inst.instruction = 0xec000f80;
17710 if (is_vldr)
17711 inst.instruction |= 1 << sysreg_vldr_bitno;
17712 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
17713 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
17714 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
17717 static void
17718 do_vldr_vstr (void)
17720 bfd_boolean sysreg_op = !inst.operands[0].isreg;
17722 /* VLDR/VSTR (System Register). */
17723 if (sysreg_op)
17725 if (!mark_feature_used (&arm_ext_v8_1m_main))
17726 as_bad (_("Instruction not permitted on this architecture"));
17728 do_t_vldr_vstr_sysreg ();
17730 /* VLDR/VSTR. */
17731 else
17733 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
17734 as_bad (_("Instruction not permitted on this architecture"));
17735 do_neon_ldr_str ();
17739 /* "interleave" version also handles non-interleaving register VLD1/VST1
17740 instructions. */
17742 static void
17743 do_neon_ld_st_interleave (void)
17745 struct neon_type_el et = neon_check_type (1, NS_NULL,
17746 N_8 | N_16 | N_32 | N_64);
17747 unsigned alignbits = 0;
17748 unsigned idx;
17749 /* The bits in this table go:
17750 0: register stride of one (0) or two (1)
17751 1,2: register list length, minus one (1, 2, 3, 4).
17752 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17753 We use -1 for invalid entries. */
17754 const int typetable[] =
17756 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17757 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17758 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17759 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17761 int typebits;
17763 if (et.type == NT_invtype)
17764 return;
17766 if (inst.operands[1].immisalign)
17767 switch (inst.operands[1].imm >> 8)
17769 case 64: alignbits = 1; break;
17770 case 128:
17771 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
17772 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17773 goto bad_alignment;
17774 alignbits = 2;
17775 break;
17776 case 256:
17777 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17778 goto bad_alignment;
17779 alignbits = 3;
17780 break;
17781 default:
17782 bad_alignment:
17783 first_error (_("bad alignment"));
17784 return;
17787 inst.instruction |= alignbits << 4;
17788 inst.instruction |= neon_logbits (et.size) << 6;
17790 /* Bits [4:6] of the immediate in a list specifier encode register stride
17791 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17792 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17793 up the right value for "type" in a table based on this value and the given
17794 list style, then stick it back. */
17795 idx = ((inst.operands[0].imm >> 4) & 7)
17796 | (((inst.instruction >> 8) & 3) << 3);
17798 typebits = typetable[idx];
17800 constraint (typebits == -1, _("bad list type for instruction"));
17801 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17802 _("bad element type for instruction"));
17804 inst.instruction &= ~0xf00;
17805 inst.instruction |= typebits << 8;
17808 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17809 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17810 otherwise. The variable arguments are a list of pairs of legal (size, align)
17811 values, terminated with -1. */
17813 static int
17814 neon_alignment_bit (int size, int align, int *do_alignment, ...)
17816 va_list ap;
17817 int result = FAIL, thissize, thisalign;
17819 if (!inst.operands[1].immisalign)
17821 *do_alignment = 0;
17822 return SUCCESS;
17825 va_start (ap, do_alignment);
17829 thissize = va_arg (ap, int);
17830 if (thissize == -1)
17831 break;
17832 thisalign = va_arg (ap, int);
17834 if (size == thissize && align == thisalign)
17835 result = SUCCESS;
17837 while (result != SUCCESS);
17839 va_end (ap);
17841 if (result == SUCCESS)
17842 *do_alignment = 1;
17843 else
17844 first_error (_("unsupported alignment for instruction"));
17846 return result;
17849 static void
17850 do_neon_ld_st_lane (void)
17852 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17853 int align_good, do_alignment = 0;
17854 int logsize = neon_logbits (et.size);
17855 int align = inst.operands[1].imm >> 8;
17856 int n = (inst.instruction >> 8) & 3;
17857 int max_el = 64 / et.size;
17859 if (et.type == NT_invtype)
17860 return;
17862 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
17863 _("bad list length"));
17864 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
17865 _("scalar index out of range"));
17866 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
17867 && et.size == 8,
17868 _("stride of 2 unavailable when element size is 8"));
17870 switch (n)
17872 case 0: /* VLD1 / VST1. */
17873 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
17874 32, 32, -1);
17875 if (align_good == FAIL)
17876 return;
17877 if (do_alignment)
17879 unsigned alignbits = 0;
17880 switch (et.size)
17882 case 16: alignbits = 0x1; break;
17883 case 32: alignbits = 0x3; break;
17884 default: ;
17886 inst.instruction |= alignbits << 4;
17888 break;
17890 case 1: /* VLD2 / VST2. */
17891 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17892 16, 32, 32, 64, -1);
17893 if (align_good == FAIL)
17894 return;
17895 if (do_alignment)
17896 inst.instruction |= 1 << 4;
17897 break;
17899 case 2: /* VLD3 / VST3. */
17900 constraint (inst.operands[1].immisalign,
17901 _("can't use alignment with this instruction"));
17902 break;
17904 case 3: /* VLD4 / VST4. */
17905 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17906 16, 64, 32, 64, 32, 128, -1);
17907 if (align_good == FAIL)
17908 return;
17909 if (do_alignment)
17911 unsigned alignbits = 0;
17912 switch (et.size)
17914 case 8: alignbits = 0x1; break;
17915 case 16: alignbits = 0x1; break;
17916 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17917 default: ;
17919 inst.instruction |= alignbits << 4;
17921 break;
17923 default: ;
17926 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17927 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17928 inst.instruction |= 1 << (4 + logsize);
17930 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17931 inst.instruction |= logsize << 10;
17934 /* Encode single n-element structure to all lanes VLD<n> instructions. */
17936 static void
17937 do_neon_ld_dup (void)
17939 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17940 int align_good, do_alignment = 0;
17942 if (et.type == NT_invtype)
17943 return;
17945 switch ((inst.instruction >> 8) & 3)
17947 case 0: /* VLD1. */
17948 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
17949 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17950 &do_alignment, 16, 16, 32, 32, -1);
17951 if (align_good == FAIL)
17952 return;
17953 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
17955 case 1: break;
17956 case 2: inst.instruction |= 1 << 5; break;
17957 default: first_error (_("bad list length")); return;
17959 inst.instruction |= neon_logbits (et.size) << 6;
17960 break;
17962 case 1: /* VLD2. */
17963 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17964 &do_alignment, 8, 16, 16, 32, 32, 64,
17965 -1);
17966 if (align_good == FAIL)
17967 return;
17968 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
17969 _("bad list length"));
17970 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17971 inst.instruction |= 1 << 5;
17972 inst.instruction |= neon_logbits (et.size) << 6;
17973 break;
17975 case 2: /* VLD3. */
17976 constraint (inst.operands[1].immisalign,
17977 _("can't use alignment with this instruction"));
17978 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
17979 _("bad list length"));
17980 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17981 inst.instruction |= 1 << 5;
17982 inst.instruction |= neon_logbits (et.size) << 6;
17983 break;
17985 case 3: /* VLD4. */
17987 int align = inst.operands[1].imm >> 8;
17988 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17989 16, 64, 32, 64, 32, 128, -1);
17990 if (align_good == FAIL)
17991 return;
17992 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17993 _("bad list length"));
17994 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17995 inst.instruction |= 1 << 5;
17996 if (et.size == 32 && align == 128)
17997 inst.instruction |= 0x3 << 6;
17998 else
17999 inst.instruction |= neon_logbits (et.size) << 6;
18001 break;
18003 default: ;
18006 inst.instruction |= do_alignment << 4;
18009 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
18010 apart from bits [11:4]. */
18012 static void
18013 do_neon_ldx_stx (void)
18015 if (inst.operands[1].isreg)
18016 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18018 switch (NEON_LANE (inst.operands[0].imm))
18020 case NEON_INTERLEAVE_LANES:
18021 NEON_ENCODE (INTERLV, inst);
18022 do_neon_ld_st_interleave ();
18023 break;
18025 case NEON_ALL_LANES:
18026 NEON_ENCODE (DUP, inst);
18027 if (inst.instruction == N_INV)
18029 first_error ("only loads support such operands");
18030 break;
18032 do_neon_ld_dup ();
18033 break;
18035 default:
18036 NEON_ENCODE (LANE, inst);
18037 do_neon_ld_st_lane ();
18040 /* L bit comes from bit mask. */
18041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18042 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18043 inst.instruction |= inst.operands[1].reg << 16;
18045 if (inst.operands[1].postind)
18047 int postreg = inst.operands[1].imm & 0xf;
18048 constraint (!inst.operands[1].immisreg,
18049 _("post-index must be a register"));
18050 constraint (postreg == 0xd || postreg == 0xf,
18051 _("bad register for post-index"));
18052 inst.instruction |= postreg;
18054 else
18056 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
18057 constraint (inst.relocs[0].exp.X_op != O_constant
18058 || inst.relocs[0].exp.X_add_number != 0,
18059 BAD_ADDR_MODE);
18061 if (inst.operands[1].writeback)
18063 inst.instruction |= 0xd;
18065 else
18066 inst.instruction |= 0xf;
18069 if (thumb_mode)
18070 inst.instruction |= 0xf9000000;
18071 else
18072 inst.instruction |= 0xf4000000;
18075 /* FP v8. */
18076 static void
18077 do_vfp_nsyn_fpv8 (enum neon_shape rs)
18079 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18080 D register operands. */
18081 if (neon_shape_class[rs] == SC_DOUBLE)
18082 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18083 _(BAD_FPU));
18085 NEON_ENCODE (FPV8, inst);
18087 if (rs == NS_FFF || rs == NS_HHH)
18089 do_vfp_sp_dyadic ();
18091 /* ARMv8.2 fp16 instruction. */
18092 if (rs == NS_HHH)
18093 do_scalar_fp16_v82_encode ();
18095 else
18096 do_vfp_dp_rd_rn_rm ();
18098 if (rs == NS_DDD)
18099 inst.instruction |= 0x100;
18101 inst.instruction |= 0xf0000000;
18104 static void
18105 do_vsel (void)
18107 set_pred_insn_type (OUTSIDE_PRED_INSN);
18109 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
18110 first_error (_("invalid instruction shape"));
18113 static void
18114 do_vmaxnm (void)
18116 set_pred_insn_type (OUTSIDE_PRED_INSN);
18118 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
18119 return;
18121 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18122 return;
18124 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
18127 static void
18128 do_vrint_1 (enum neon_cvt_mode mode)
18130 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
18131 struct neon_type_el et;
18133 if (rs == NS_NULL)
18134 return;
18136 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18137 D register operands. */
18138 if (neon_shape_class[rs] == SC_DOUBLE)
18139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18140 _(BAD_FPU));
18142 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
18143 | N_VFP);
18144 if (et.type != NT_invtype)
18146 /* VFP encodings. */
18147 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
18148 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
18149 set_pred_insn_type (OUTSIDE_PRED_INSN);
18151 NEON_ENCODE (FPV8, inst);
18152 if (rs == NS_FF || rs == NS_HH)
18153 do_vfp_sp_monadic ();
18154 else
18155 do_vfp_dp_rd_rm ();
18157 switch (mode)
18159 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
18160 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
18161 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
18162 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
18163 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
18164 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
18165 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
18166 default: abort ();
18169 inst.instruction |= (rs == NS_DD) << 8;
18170 do_vfp_cond_or_thumb ();
18172 /* ARMv8.2 fp16 vrint instruction. */
18173 if (rs == NS_HH)
18174 do_scalar_fp16_v82_encode ();
18176 else
18178 /* Neon encodings (or something broken...). */
18179 inst.error = NULL;
18180 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
18182 if (et.type == NT_invtype)
18183 return;
18185 set_pred_insn_type (OUTSIDE_PRED_INSN);
18186 NEON_ENCODE (FLOAT, inst);
18188 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
18189 return;
18191 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18193 inst.instruction |= LOW4 (inst.operands[1].reg);
18194 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18195 inst.instruction |= neon_quad (rs) << 6;
18196 /* Mask off the original size bits and reencode them. */
18197 inst.instruction = ((inst.instruction & 0xfff3ffff)
18198 | neon_logbits (et.size) << 18);
18200 switch (mode)
18202 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
18203 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
18204 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
18205 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
18206 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
18207 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
18208 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
18209 default: abort ();
18212 if (thumb_mode)
18213 inst.instruction |= 0xfc000000;
18214 else
18215 inst.instruction |= 0xf0000000;
18219 static void
18220 do_vrintx (void)
18222 do_vrint_1 (neon_cvt_mode_x);
18225 static void
18226 do_vrintz (void)
18228 do_vrint_1 (neon_cvt_mode_z);
18231 static void
18232 do_vrintr (void)
18234 do_vrint_1 (neon_cvt_mode_r);
18237 static void
18238 do_vrinta (void)
18240 do_vrint_1 (neon_cvt_mode_a);
18243 static void
18244 do_vrintn (void)
18246 do_vrint_1 (neon_cvt_mode_n);
18249 static void
18250 do_vrintp (void)
18252 do_vrint_1 (neon_cvt_mode_p);
18255 static void
18256 do_vrintm (void)
18258 do_vrint_1 (neon_cvt_mode_m);
18261 static unsigned
18262 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
18264 unsigned regno = NEON_SCALAR_REG (opnd);
18265 unsigned elno = NEON_SCALAR_INDEX (opnd);
18267 if (elsize == 16 && elno < 2 && regno < 16)
18268 return regno | (elno << 4);
18269 else if (elsize == 32 && elno == 0)
18270 return regno;
18272 first_error (_("scalar out of range"));
18273 return 0;
18276 static void
18277 do_vcmla (void)
18279 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18280 _(BAD_FPU));
18281 constraint (inst.relocs[0].exp.X_op != O_constant,
18282 _("expression too complex"));
18283 unsigned rot = inst.relocs[0].exp.X_add_number;
18284 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
18285 _("immediate out of range"));
18286 rot /= 90;
18287 if (inst.operands[2].isscalar)
18289 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
18290 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18291 N_KEY | N_F16 | N_F32).size;
18292 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
18293 inst.is_neon = 1;
18294 inst.instruction = 0xfe000800;
18295 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18296 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18297 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
18298 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
18299 inst.instruction |= LOW4 (m);
18300 inst.instruction |= HI1 (m) << 5;
18301 inst.instruction |= neon_quad (rs) << 6;
18302 inst.instruction |= rot << 20;
18303 inst.instruction |= (size == 32) << 23;
18305 else
18307 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18308 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18309 N_KEY | N_F16 | N_F32).size;
18310 neon_three_same (neon_quad (rs), 0, -1);
18311 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18312 inst.instruction |= 0xfc200800;
18313 inst.instruction |= rot << 23;
18314 inst.instruction |= (size == 32) << 20;
18318 static void
18319 do_vcadd (void)
18321 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18322 _(BAD_FPU));
18323 constraint (inst.relocs[0].exp.X_op != O_constant,
18324 _("expression too complex"));
18325 unsigned rot = inst.relocs[0].exp.X_add_number;
18326 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18327 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
18328 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
18329 N_KEY | N_F16 | N_F32).size;
18330 neon_three_same (neon_quad (rs), 0, -1);
18331 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
18332 inst.instruction |= 0xfc800800;
18333 inst.instruction |= (rot == 270) << 24;
18334 inst.instruction |= (size == 32) << 20;
18337 /* Dot Product instructions encoding support. */
18339 static void
18340 do_neon_dotproduct (int unsigned_p)
18342 enum neon_shape rs;
18343 unsigned scalar_oprd2 = 0;
18344 int high8;
18346 if (inst.cond != COND_ALWAYS)
18347 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
18348 "is UNPREDICTABLE"));
18350 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
18351 _(BAD_FPU));
18353 /* Dot Product instructions are in three-same D/Q register format or the third
18354 operand can be a scalar index register. */
18355 if (inst.operands[2].isscalar)
18357 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
18358 high8 = 0xfe000000;
18359 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18361 else
18363 high8 = 0xfc000000;
18364 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18367 if (unsigned_p)
18368 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
18369 else
18370 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
18372 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
18373 Product instruction, so we pass 0 as the "ubit" parameter. And the
18374 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
18375 neon_three_same (neon_quad (rs), 0, 32);
18377 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
18378 different NEON three-same encoding. */
18379 inst.instruction &= 0x00ffffff;
18380 inst.instruction |= high8;
18381 /* Encode 'U' bit which indicates signedness. */
18382 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
18383 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
18384 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
18385 the instruction encoding. */
18386 if (inst.operands[2].isscalar)
18388 inst.instruction &= 0xffffffd0;
18389 inst.instruction |= LOW4 (scalar_oprd2);
18390 inst.instruction |= HI1 (scalar_oprd2) << 5;
18394 /* Dot Product instructions for signed integer. */
18396 static void
18397 do_neon_dotproduct_s (void)
18399 return do_neon_dotproduct (0);
18402 /* Dot Product instructions for unsigned integer. */
18404 static void
18405 do_neon_dotproduct_u (void)
18407 return do_neon_dotproduct (1);
18410 /* Crypto v1 instructions. */
18411 static void
18412 do_crypto_2op_1 (unsigned elttype, int op)
18414 set_pred_insn_type (OUTSIDE_PRED_INSN);
18416 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
18417 == NT_invtype)
18418 return;
18420 inst.error = NULL;
18422 NEON_ENCODE (INTEGER, inst);
18423 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18424 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18425 inst.instruction |= LOW4 (inst.operands[1].reg);
18426 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18427 if (op != -1)
18428 inst.instruction |= op << 6;
18430 if (thumb_mode)
18431 inst.instruction |= 0xfc000000;
18432 else
18433 inst.instruction |= 0xf0000000;
18436 static void
18437 do_crypto_3op_1 (int u, int op)
18439 set_pred_insn_type (OUTSIDE_PRED_INSN);
18441 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
18442 N_32 | N_UNT | N_KEY).type == NT_invtype)
18443 return;
18445 inst.error = NULL;
18447 NEON_ENCODE (INTEGER, inst);
18448 neon_three_same (1, u, 8 << op);
18451 static void
18452 do_aese (void)
18454 do_crypto_2op_1 (N_8, 0);
18457 static void
18458 do_aesd (void)
18460 do_crypto_2op_1 (N_8, 1);
18463 static void
18464 do_aesmc (void)
18466 do_crypto_2op_1 (N_8, 2);
18469 static void
18470 do_aesimc (void)
18472 do_crypto_2op_1 (N_8, 3);
18475 static void
18476 do_sha1c (void)
18478 do_crypto_3op_1 (0, 0);
18481 static void
18482 do_sha1p (void)
18484 do_crypto_3op_1 (0, 1);
18487 static void
18488 do_sha1m (void)
18490 do_crypto_3op_1 (0, 2);
18493 static void
18494 do_sha1su0 (void)
18496 do_crypto_3op_1 (0, 3);
18499 static void
18500 do_sha256h (void)
18502 do_crypto_3op_1 (1, 0);
18505 static void
18506 do_sha256h2 (void)
18508 do_crypto_3op_1 (1, 1);
18511 static void
18512 do_sha256su1 (void)
18514 do_crypto_3op_1 (1, 2);
18517 static void
18518 do_sha1h (void)
18520 do_crypto_2op_1 (N_32, -1);
18523 static void
18524 do_sha1su1 (void)
18526 do_crypto_2op_1 (N_32, 0);
18529 static void
18530 do_sha256su0 (void)
18532 do_crypto_2op_1 (N_32, 1);
18535 static void
18536 do_crc32_1 (unsigned int poly, unsigned int sz)
18538 unsigned int Rd = inst.operands[0].reg;
18539 unsigned int Rn = inst.operands[1].reg;
18540 unsigned int Rm = inst.operands[2].reg;
18542 set_pred_insn_type (OUTSIDE_PRED_INSN);
18543 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
18544 inst.instruction |= LOW4 (Rn) << 16;
18545 inst.instruction |= LOW4 (Rm);
18546 inst.instruction |= sz << (thumb_mode ? 4 : 21);
18547 inst.instruction |= poly << (thumb_mode ? 20 : 9);
18549 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
18550 as_warn (UNPRED_REG ("r15"));
18553 static void
18554 do_crc32b (void)
18556 do_crc32_1 (0, 0);
18559 static void
18560 do_crc32h (void)
18562 do_crc32_1 (0, 1);
18565 static void
18566 do_crc32w (void)
18568 do_crc32_1 (0, 2);
18571 static void
18572 do_crc32cb (void)
18574 do_crc32_1 (1, 0);
18577 static void
18578 do_crc32ch (void)
18580 do_crc32_1 (1, 1);
18583 static void
18584 do_crc32cw (void)
18586 do_crc32_1 (1, 2);
18589 static void
18590 do_vjcvt (void)
18592 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18593 _(BAD_FPU));
18594 neon_check_type (2, NS_FD, N_S32, N_F64);
18595 do_vfp_sp_dp_cvt ();
18596 do_vfp_cond_or_thumb ();
18600 /* Overall per-instruction processing. */
18602 /* We need to be able to fix up arbitrary expressions in some statements.
18603 This is so that we can handle symbols that are an arbitrary distance from
18604 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
18605 which returns part of an address in a form which will be valid for
18606 a data instruction. We do this by pushing the expression into a symbol
18607 in the expr_section, and creating a fix for that. */
18609 static void
18610 fix_new_arm (fragS * frag,
18611 int where,
18612 short int size,
18613 expressionS * exp,
18614 int pc_rel,
18615 int reloc)
18617 fixS * new_fix;
18619 switch (exp->X_op)
18621 case O_constant:
18622 if (pc_rel)
18624 /* Create an absolute valued symbol, so we have something to
18625 refer to in the object file. Unfortunately for us, gas's
18626 generic expression parsing will already have folded out
18627 any use of .set foo/.type foo %function that may have
18628 been used to set type information of the target location,
18629 that's being specified symbolically. We have to presume
18630 the user knows what they are doing. */
18631 char name[16 + 8];
18632 symbolS *symbol;
18634 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
18636 symbol = symbol_find_or_make (name);
18637 S_SET_SEGMENT (symbol, absolute_section);
18638 symbol_set_frag (symbol, &zero_address_frag);
18639 S_SET_VALUE (symbol, exp->X_add_number);
18640 exp->X_op = O_symbol;
18641 exp->X_add_symbol = symbol;
18642 exp->X_add_number = 0;
18644 /* FALLTHROUGH */
18645 case O_symbol:
18646 case O_add:
18647 case O_subtract:
18648 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
18649 (enum bfd_reloc_code_real) reloc);
18650 break;
18652 default:
18653 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
18654 pc_rel, (enum bfd_reloc_code_real) reloc);
18655 break;
18658 /* Mark whether the fix is to a THUMB instruction, or an ARM
18659 instruction. */
18660 new_fix->tc_fix_data = thumb_mode;
18663 /* Create a frg for an instruction requiring relaxation. */
18664 static void
18665 output_relax_insn (void)
18667 char * to;
18668 symbolS *sym;
18669 int offset;
18671 /* The size of the instruction is unknown, so tie the debug info to the
18672 start of the instruction. */
18673 dwarf2_emit_insn (0);
18675 switch (inst.relocs[0].exp.X_op)
18677 case O_symbol:
18678 sym = inst.relocs[0].exp.X_add_symbol;
18679 offset = inst.relocs[0].exp.X_add_number;
18680 break;
18681 case O_constant:
18682 sym = NULL;
18683 offset = inst.relocs[0].exp.X_add_number;
18684 break;
18685 default:
18686 sym = make_expr_symbol (&inst.relocs[0].exp);
18687 offset = 0;
18688 break;
18690 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18691 inst.relax, sym, offset, NULL/*offset, opcode*/);
18692 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
18695 /* Write a 32-bit thumb instruction to buf. */
18696 static void
18697 put_thumb32_insn (char * buf, unsigned long insn)
18699 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18700 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18703 static void
18704 output_inst (const char * str)
18706 char * to = NULL;
18708 if (inst.error)
18710 as_bad ("%s -- `%s'", inst.error, str);
18711 return;
18713 if (inst.relax)
18715 output_relax_insn ();
18716 return;
18718 if (inst.size == 0)
18719 return;
18721 to = frag_more (inst.size);
18722 /* PR 9814: Record the thumb mode into the current frag so that we know
18723 what type of NOP padding to use, if necessary. We override any previous
18724 setting so that if the mode has changed then the NOPS that we use will
18725 match the encoding of the last instruction in the frag. */
18726 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18728 if (thumb_mode && (inst.size > THUMB_SIZE))
18730 gas_assert (inst.size == (2 * THUMB_SIZE));
18731 put_thumb32_insn (to, inst.instruction);
18733 else if (inst.size > INSN_SIZE)
18735 gas_assert (inst.size == (2 * INSN_SIZE));
18736 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18737 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
18739 else
18740 md_number_to_chars (to, inst.instruction, inst.size);
18742 int r;
18743 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18745 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18746 fix_new_arm (frag_now, to - frag_now->fr_literal,
18747 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18748 inst.relocs[r].type);
18751 dwarf2_emit_insn (inst.size);
18754 static char *
18755 output_it_inst (int cond, int mask, char * to)
18757 unsigned long instruction = 0xbf00;
18759 mask &= 0xf;
18760 instruction |= mask;
18761 instruction |= cond << 4;
18763 if (to == NULL)
18765 to = frag_more (2);
18766 #ifdef OBJ_ELF
18767 dwarf2_emit_insn (2);
18768 #endif
18771 md_number_to_chars (to, instruction, 2);
18773 return to;
18776 /* Tag values used in struct asm_opcode's tag field. */
18777 enum opcode_tag
18779 OT_unconditional, /* Instruction cannot be conditionalized.
18780 The ARM condition field is still 0xE. */
18781 OT_unconditionalF, /* Instruction cannot be conditionalized
18782 and carries 0xF in its ARM condition field. */
18783 OT_csuffix, /* Instruction takes a conditional suffix. */
18784 OT_csuffixF, /* Some forms of the instruction take a scalar
18785 conditional suffix, others place 0xF where the
18786 condition field would be, others take a vector
18787 conditional suffix. */
18788 OT_cinfix3, /* Instruction takes a conditional infix,
18789 beginning at character index 3. (In
18790 unified mode, it becomes a suffix.) */
18791 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18792 tsts, cmps, cmns, and teqs. */
18793 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18794 character index 3, even in unified mode. Used for
18795 legacy instructions where suffix and infix forms
18796 may be ambiguous. */
18797 OT_csuf_or_in3, /* Instruction takes either a conditional
18798 suffix or an infix at character index 3. */
18799 OT_odd_infix_unc, /* This is the unconditional variant of an
18800 instruction that takes a conditional infix
18801 at an unusual position. In unified mode,
18802 this variant will accept a suffix. */
18803 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18804 are the conditional variants of instructions that
18805 take conditional infixes in unusual positions.
18806 The infix appears at character index
18807 (tag - OT_odd_infix_0). These are not accepted
18808 in unified mode. */
18811 /* Subroutine of md_assemble, responsible for looking up the primary
18812 opcode from the mnemonic the user wrote. STR points to the
18813 beginning of the mnemonic.
18815 This is not simply a hash table lookup, because of conditional
18816 variants. Most instructions have conditional variants, which are
18817 expressed with a _conditional affix_ to the mnemonic. If we were
18818 to encode each conditional variant as a literal string in the opcode
18819 table, it would have approximately 20,000 entries.
18821 Most mnemonics take this affix as a suffix, and in unified syntax,
18822 'most' is upgraded to 'all'. However, in the divided syntax, some
18823 instructions take the affix as an infix, notably the s-variants of
18824 the arithmetic instructions. Of those instructions, all but six
18825 have the infix appear after the third character of the mnemonic.
18827 Accordingly, the algorithm for looking up primary opcodes given
18828 an identifier is:
18830 1. Look up the identifier in the opcode table.
18831 If we find a match, go to step U.
18833 2. Look up the last two characters of the identifier in the
18834 conditions table. If we find a match, look up the first N-2
18835 characters of the identifier in the opcode table. If we
18836 find a match, go to step CE.
18838 3. Look up the fourth and fifth characters of the identifier in
18839 the conditions table. If we find a match, extract those
18840 characters from the identifier, and look up the remaining
18841 characters in the opcode table. If we find a match, go
18842 to step CM.
18844 4. Fail.
18846 U. Examine the tag field of the opcode structure, in case this is
18847 one of the six instructions with its conditional infix in an
18848 unusual place. If it is, the tag tells us where to find the
18849 infix; look it up in the conditions table and set inst.cond
18850 accordingly. Otherwise, this is an unconditional instruction.
18851 Again set inst.cond accordingly. Return the opcode structure.
18853 CE. Examine the tag field to make sure this is an instruction that
18854 should receive a conditional suffix. If it is not, fail.
18855 Otherwise, set inst.cond from the suffix we already looked up,
18856 and return the opcode structure.
18858 CM. Examine the tag field to make sure this is an instruction that
18859 should receive a conditional infix after the third character.
18860 If it is not, fail. Otherwise, undo the edits to the current
18861 line of input and proceed as for case CE. */
18863 static const struct asm_opcode *
18864 opcode_lookup (char **str)
18866 char *end, *base;
18867 char *affix;
18868 const struct asm_opcode *opcode;
18869 const struct asm_cond *cond;
18870 char save[2];
18872 /* Scan up to the end of the mnemonic, which must end in white space,
18873 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
18874 for (base = end = *str; *end != '\0'; end++)
18875 if (*end == ' ' || *end == '.')
18876 break;
18878 if (end == base)
18879 return NULL;
18881 /* Handle a possible width suffix and/or Neon type suffix. */
18882 if (end[0] == '.')
18884 int offset = 2;
18886 /* The .w and .n suffixes are only valid if the unified syntax is in
18887 use. */
18888 if (unified_syntax && end[1] == 'w')
18889 inst.size_req = 4;
18890 else if (unified_syntax && end[1] == 'n')
18891 inst.size_req = 2;
18892 else
18893 offset = 0;
18895 inst.vectype.elems = 0;
18897 *str = end + offset;
18899 if (end[offset] == '.')
18901 /* See if we have a Neon type suffix (possible in either unified or
18902 non-unified ARM syntax mode). */
18903 if (parse_neon_type (&inst.vectype, str) == FAIL)
18904 return NULL;
18906 else if (end[offset] != '\0' && end[offset] != ' ')
18907 return NULL;
18909 else
18910 *str = end;
18912 /* Look for unaffixed or special-case affixed mnemonic. */
18913 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18914 end - base);
18915 if (opcode)
18917 /* step U */
18918 if (opcode->tag < OT_odd_infix_0)
18920 inst.cond = COND_ALWAYS;
18921 return opcode;
18924 if (warn_on_deprecated && unified_syntax)
18925 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
18926 affix = base + (opcode->tag - OT_odd_infix_0);
18927 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18928 gas_assert (cond);
18930 inst.cond = cond->value;
18931 return opcode;
18933 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18935 /* Cannot have a conditional suffix on a mnemonic of less than a character.
18937 if (end - base < 2)
18938 return NULL;
18939 affix = end - 1;
18940 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
18941 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18942 affix - base);
18943 /* If this opcode can not be vector predicated then don't accept it with a
18944 vector predication code. */
18945 if (opcode && !opcode->mayBeVecPred)
18946 opcode = NULL;
18948 if (!opcode || !cond)
18950 /* Cannot have a conditional suffix on a mnemonic of less than two
18951 characters. */
18952 if (end - base < 3)
18953 return NULL;
18955 /* Look for suffixed mnemonic. */
18956 affix = end - 2;
18957 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18958 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18959 affix - base);
18962 if (opcode && cond)
18964 /* step CE */
18965 switch (opcode->tag)
18967 case OT_cinfix3_legacy:
18968 /* Ignore conditional suffixes matched on infix only mnemonics. */
18969 break;
18971 case OT_cinfix3:
18972 case OT_cinfix3_deprecated:
18973 case OT_odd_infix_unc:
18974 if (!unified_syntax)
18975 return NULL;
18976 /* Fall through. */
18978 case OT_csuffix:
18979 case OT_csuffixF:
18980 case OT_csuf_or_in3:
18981 inst.cond = cond->value;
18982 return opcode;
18984 case OT_unconditional:
18985 case OT_unconditionalF:
18986 if (thumb_mode)
18987 inst.cond = cond->value;
18988 else
18990 /* Delayed diagnostic. */
18991 inst.error = BAD_COND;
18992 inst.cond = COND_ALWAYS;
18994 return opcode;
18996 default:
18997 return NULL;
19001 /* Cannot have a usual-position infix on a mnemonic of less than
19002 six characters (five would be a suffix). */
19003 if (end - base < 6)
19004 return NULL;
19006 /* Look for infixed mnemonic in the usual position. */
19007 affix = base + 3;
19008 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
19009 if (!cond)
19010 return NULL;
19012 memcpy (save, affix, 2);
19013 memmove (affix, affix + 2, (end - affix) - 2);
19014 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
19015 (end - base) - 2);
19016 memmove (affix + 2, affix, (end - affix) - 2);
19017 memcpy (affix, save, 2);
19019 if (opcode
19020 && (opcode->tag == OT_cinfix3
19021 || opcode->tag == OT_cinfix3_deprecated
19022 || opcode->tag == OT_csuf_or_in3
19023 || opcode->tag == OT_cinfix3_legacy))
19025 /* Step CM. */
19026 if (warn_on_deprecated && unified_syntax
19027 && (opcode->tag == OT_cinfix3
19028 || opcode->tag == OT_cinfix3_deprecated))
19029 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
19031 inst.cond = cond->value;
19032 return opcode;
19035 return NULL;
19038 /* This function generates an initial IT instruction, leaving its block
19039 virtually open for the new instructions. Eventually,
19040 the mask will be updated by now_pred_add_mask () each time
19041 a new instruction needs to be included in the IT block.
19042 Finally, the block is closed with close_automatic_it_block ().
19043 The block closure can be requested either from md_assemble (),
19044 a tencode (), or due to a label hook. */
19046 static void
19047 new_automatic_it_block (int cond)
19049 now_pred.state = AUTOMATIC_PRED_BLOCK;
19050 now_pred.mask = 0x18;
19051 now_pred.cc = cond;
19052 now_pred.block_length = 1;
19053 mapping_state (MAP_THUMB);
19054 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
19055 now_pred.warn_deprecated = FALSE;
19056 now_pred.insn_cond = TRUE;
19059 /* Close an automatic IT block.
19060 See comments in new_automatic_it_block (). */
19062 static void
19063 close_automatic_it_block (void)
19065 now_pred.mask = 0x10;
19066 now_pred.block_length = 0;
19069 /* Update the mask of the current automatically-generated IT
19070 instruction. See comments in new_automatic_it_block (). */
19072 static void
19073 now_pred_add_mask (int cond)
19075 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
19076 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
19077 | ((bitvalue) << (nbit)))
19078 const int resulting_bit = (cond & 1);
19080 now_pred.mask &= 0xf;
19081 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
19082 resulting_bit,
19083 (5 - now_pred.block_length));
19084 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
19086 ((5 - now_pred.block_length) - 1));
19087 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
19089 #undef CLEAR_BIT
19090 #undef SET_BIT_VALUE
19093 /* The IT blocks handling machinery is accessed through the these functions:
19094 it_fsm_pre_encode () from md_assemble ()
19095 set_pred_insn_type () optional, from the tencode functions
19096 set_pred_insn_type_last () ditto
19097 in_pred_block () ditto
19098 it_fsm_post_encode () from md_assemble ()
19099 force_automatic_it_block_close () from label handling functions
19101 Rationale:
19102 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
19103 initializing the IT insn type with a generic initial value depending
19104 on the inst.condition.
19105 2) During the tencode function, two things may happen:
19106 a) The tencode function overrides the IT insn type by
19107 calling either set_pred_insn_type (type) or
19108 set_pred_insn_type_last ().
19109 b) The tencode function queries the IT block state by
19110 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
19112 Both set_pred_insn_type and in_pred_block run the internal FSM state
19113 handling function (handle_pred_state), because: a) setting the IT insn
19114 type may incur in an invalid state (exiting the function),
19115 and b) querying the state requires the FSM to be updated.
19116 Specifically we want to avoid creating an IT block for conditional
19117 branches, so it_fsm_pre_encode is actually a guess and we can't
19118 determine whether an IT block is required until the tencode () routine
19119 has decided what type of instruction this actually it.
19120 Because of this, if set_pred_insn_type and in_pred_block have to be
19121 used, set_pred_insn_type has to be called first.
19123 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
19124 that determines the insn IT type depending on the inst.cond code.
19125 When a tencode () routine encodes an instruction that can be
19126 either outside an IT block, or, in the case of being inside, has to be
19127 the last one, set_pred_insn_type_last () will determine the proper
19128 IT instruction type based on the inst.cond code. Otherwise,
19129 set_pred_insn_type can be called for overriding that logic or
19130 for covering other cases.
19132 Calling handle_pred_state () may not transition the IT block state to
19133 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
19134 still queried. Instead, if the FSM determines that the state should
19135 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
19136 after the tencode () function: that's what it_fsm_post_encode () does.
19138 Since in_pred_block () calls the state handling function to get an
19139 updated state, an error may occur (due to invalid insns combination).
19140 In that case, inst.error is set.
19141 Therefore, inst.error has to be checked after the execution of
19142 the tencode () routine.
19144 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
19145 any pending state change (if any) that didn't take place in
19146 handle_pred_state () as explained above. */
19148 static void
19149 it_fsm_pre_encode (void)
19151 if (inst.cond != COND_ALWAYS)
19152 inst.pred_insn_type = INSIDE_IT_INSN;
19153 else
19154 inst.pred_insn_type = OUTSIDE_PRED_INSN;
19156 now_pred.state_handled = 0;
19159 /* IT state FSM handling function. */
19160 /* MVE instructions and non-MVE instructions are handled differently because of
19161 the introduction of VPT blocks.
19162 Specifications say that any non-MVE instruction inside a VPT block is
19163 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
19164 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
19165 few exceptions this will be handled at their respective handler functions.
19166 The error messages provided depending on the different combinations possible
19167 are described in the cases below:
19168 For 'most' MVE instructions:
19169 1) In an IT block, with an IT code: syntax error
19170 2) In an IT block, with a VPT code: error: must be in a VPT block
19171 3) In an IT block, with no code: warning: UNPREDICTABLE
19172 4) In a VPT block, with an IT code: syntax error
19173 5) In a VPT block, with a VPT code: OK!
19174 6) In a VPT block, with no code: error: missing code
19175 7) Outside a pred block, with an IT code: error: syntax error
19176 8) Outside a pred block, with a VPT code: error: should be in a VPT block
19177 9) Outside a pred block, with no code: OK!
19178 For non-MVE instructions:
19179 10) In an IT block, with an IT code: OK!
19180 11) In an IT block, with a VPT code: syntax error
19181 12) In an IT block, with no code: error: missing code
19182 13) In a VPT block, with an IT code: error: should be in an IT block
19183 14) In a VPT block, with a VPT code: syntax error
19184 15) In a VPT block, with no code: UNPREDICTABLE
19185 16) Outside a pred block, with an IT code: error: should be in an IT block
19186 17) Outside a pred block, with a VPT code: syntax error
19187 18) Outside a pred block, with no code: OK!
19191 static int
19192 handle_pred_state (void)
19194 now_pred.state_handled = 1;
19195 now_pred.insn_cond = FALSE;
19197 switch (now_pred.state)
19199 case OUTSIDE_PRED_BLOCK:
19200 switch (inst.pred_insn_type)
19202 case MVE_OUTSIDE_PRED_INSN:
19203 if (inst.cond < COND_ALWAYS)
19205 /* Case 7: Outside a pred block, with an IT code: error: syntax
19206 error. */
19207 inst.error = BAD_SYNTAX;
19208 return FAIL;
19210 /* Case 9: Outside a pred block, with no code: OK! */
19211 break;
19212 case OUTSIDE_PRED_INSN:
19213 if (inst.cond > COND_ALWAYS)
19215 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19217 inst.error = BAD_SYNTAX;
19218 return FAIL;
19220 /* Case 18: Outside a pred block, with no code: OK! */
19221 break;
19223 case INSIDE_VPT_INSN:
19224 /* Case 8: Outside a pred block, with a VPT code: error: should be in
19225 a VPT block. */
19226 inst.error = BAD_OUT_VPT;
19227 return FAIL;
19229 case INSIDE_IT_INSN:
19230 case INSIDE_IT_LAST_INSN:
19231 if (inst.cond < COND_ALWAYS)
19233 /* Case 16: Outside a pred block, with an IT code: error: should
19234 be in an IT block. */
19235 if (thumb_mode == 0)
19237 if (unified_syntax
19238 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
19239 as_tsktsk (_("Warning: conditional outside an IT block"\
19240 " for Thumb."));
19242 else
19244 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
19245 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
19247 /* Automatically generate the IT instruction. */
19248 new_automatic_it_block (inst.cond);
19249 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
19250 close_automatic_it_block ();
19252 else
19254 inst.error = BAD_OUT_IT;
19255 return FAIL;
19258 break;
19260 else if (inst.cond > COND_ALWAYS)
19262 /* Case 17: Outside a pred block, with a VPT code: syntax error.
19264 inst.error = BAD_SYNTAX;
19265 return FAIL;
19267 else
19268 gas_assert (0);
19269 case IF_INSIDE_IT_LAST_INSN:
19270 case NEUTRAL_IT_INSN:
19271 break;
19273 case VPT_INSN:
19274 if (inst.cond != COND_ALWAYS)
19275 first_error (BAD_SYNTAX);
19276 now_pred.state = MANUAL_PRED_BLOCK;
19277 now_pred.block_length = 0;
19278 now_pred.type = VECTOR_PRED;
19279 now_pred.cc = 0;
19280 break;
19281 case IT_INSN:
19282 now_pred.state = MANUAL_PRED_BLOCK;
19283 now_pred.block_length = 0;
19284 now_pred.type = SCALAR_PRED;
19285 break;
19287 break;
19289 case AUTOMATIC_PRED_BLOCK:
19290 /* Three things may happen now:
19291 a) We should increment current it block size;
19292 b) We should close current it block (closing insn or 4 insns);
19293 c) We should close current it block and start a new one (due
19294 to incompatible conditions or
19295 4 insns-length block reached). */
19297 switch (inst.pred_insn_type)
19299 case INSIDE_VPT_INSN:
19300 case VPT_INSN:
19301 case MVE_OUTSIDE_PRED_INSN:
19302 gas_assert (0);
19303 case OUTSIDE_PRED_INSN:
19304 /* The closure of the block shall happen immediately,
19305 so any in_pred_block () call reports the block as closed. */
19306 force_automatic_it_block_close ();
19307 break;
19309 case INSIDE_IT_INSN:
19310 case INSIDE_IT_LAST_INSN:
19311 case IF_INSIDE_IT_LAST_INSN:
19312 now_pred.block_length++;
19314 if (now_pred.block_length > 4
19315 || !now_pred_compatible (inst.cond))
19317 force_automatic_it_block_close ();
19318 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
19319 new_automatic_it_block (inst.cond);
19321 else
19323 now_pred.insn_cond = TRUE;
19324 now_pred_add_mask (inst.cond);
19327 if (now_pred.state == AUTOMATIC_PRED_BLOCK
19328 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
19329 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
19330 close_automatic_it_block ();
19331 break;
19333 case NEUTRAL_IT_INSN:
19334 now_pred.block_length++;
19335 now_pred.insn_cond = TRUE;
19337 if (now_pred.block_length > 4)
19338 force_automatic_it_block_close ();
19339 else
19340 now_pred_add_mask (now_pred.cc & 1);
19341 break;
19343 case IT_INSN:
19344 close_automatic_it_block ();
19345 now_pred.state = MANUAL_PRED_BLOCK;
19346 break;
19348 break;
19350 case MANUAL_PRED_BLOCK:
19352 int cond, is_last;
19353 if (now_pred.type == SCALAR_PRED)
19355 /* Check conditional suffixes. */
19356 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
19357 now_pred.mask <<= 1;
19358 now_pred.mask &= 0x1f;
19359 is_last = (now_pred.mask == 0x10);
19361 else
19363 now_pred.cc ^= (now_pred.mask >> 4);
19364 cond = now_pred.cc + 0xf;
19365 now_pred.mask <<= 1;
19366 now_pred.mask &= 0x1f;
19367 is_last = now_pred.mask == 0x10;
19369 now_pred.insn_cond = TRUE;
19371 switch (inst.pred_insn_type)
19373 case OUTSIDE_PRED_INSN:
19374 if (now_pred.type == SCALAR_PRED)
19376 if (inst.cond == COND_ALWAYS)
19378 /* Case 12: In an IT block, with no code: error: missing
19379 code. */
19380 inst.error = BAD_NOT_IT;
19381 return FAIL;
19383 else if (inst.cond > COND_ALWAYS)
19385 /* Case 11: In an IT block, with a VPT code: syntax error.
19387 inst.error = BAD_SYNTAX;
19388 return FAIL;
19390 else if (thumb_mode)
19392 /* This is for some special cases where a non-MVE
19393 instruction is not allowed in an IT block, such as cbz,
19394 but are put into one with a condition code.
19395 You could argue this should be a syntax error, but we
19396 gave the 'not allowed in IT block' diagnostic in the
19397 past so we will keep doing so. */
19398 inst.error = BAD_NOT_IT;
19399 return FAIL;
19401 break;
19403 else
19405 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
19406 as_tsktsk (MVE_NOT_VPT);
19407 return SUCCESS;
19409 case MVE_OUTSIDE_PRED_INSN:
19410 if (now_pred.type == SCALAR_PRED)
19412 if (inst.cond == COND_ALWAYS)
19414 /* Case 3: In an IT block, with no code: warning:
19415 UNPREDICTABLE. */
19416 as_tsktsk (MVE_NOT_IT);
19417 return SUCCESS;
19419 else if (inst.cond < COND_ALWAYS)
19421 /* Case 1: In an IT block, with an IT code: syntax error.
19423 inst.error = BAD_SYNTAX;
19424 return FAIL;
19426 else
19427 gas_assert (0);
19429 else
19431 if (inst.cond < COND_ALWAYS)
19433 /* Case 4: In a VPT block, with an IT code: syntax error.
19435 inst.error = BAD_SYNTAX;
19436 return FAIL;
19438 else if (inst.cond == COND_ALWAYS)
19440 /* Case 6: In a VPT block, with no code: error: missing
19441 code. */
19442 inst.error = BAD_NOT_VPT;
19443 return FAIL;
19445 else
19447 gas_assert (0);
19450 case INSIDE_IT_INSN:
19451 if (inst.cond > COND_ALWAYS)
19453 /* Case 11: In an IT block, with a VPT code: syntax error. */
19454 /* Case 14: In a VPT block, with a VPT code: syntax error. */
19455 inst.error = BAD_SYNTAX;
19456 return FAIL;
19458 else if (now_pred.type == SCALAR_PRED)
19460 /* Case 10: In an IT block, with an IT code: OK! */
19461 if (cond != inst.cond)
19463 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
19464 BAD_VPT_COND;
19465 return FAIL;
19468 else
19470 /* Case 13: In a VPT block, with an IT code: error: should be
19471 in an IT block. */
19472 inst.error = BAD_OUT_IT;
19473 return FAIL;
19475 break;
19477 case INSIDE_VPT_INSN:
19478 if (now_pred.type == SCALAR_PRED)
19480 /* Case 2: In an IT block, with a VPT code: error: must be in a
19481 VPT block. */
19482 inst.error = BAD_OUT_VPT;
19483 return FAIL;
19485 /* Case 5: In a VPT block, with a VPT code: OK! */
19486 else if (cond != inst.cond)
19488 inst.error = BAD_VPT_COND;
19489 return FAIL;
19491 break;
19492 case INSIDE_IT_LAST_INSN:
19493 case IF_INSIDE_IT_LAST_INSN:
19494 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
19496 /* Case 4: In a VPT block, with an IT code: syntax error. */
19497 /* Case 11: In an IT block, with a VPT code: syntax error. */
19498 inst.error = BAD_SYNTAX;
19499 return FAIL;
19501 else if (cond != inst.cond)
19503 inst.error = BAD_IT_COND;
19504 return FAIL;
19506 if (!is_last)
19508 inst.error = BAD_BRANCH;
19509 return FAIL;
19511 break;
19513 case NEUTRAL_IT_INSN:
19514 /* The BKPT instruction is unconditional even in a IT or VPT
19515 block. */
19516 break;
19518 case IT_INSN:
19519 if (now_pred.type == SCALAR_PRED)
19521 inst.error = BAD_IT_IT;
19522 return FAIL;
19524 /* fall through. */
19525 case VPT_INSN:
19526 if (inst.cond == COND_ALWAYS)
19528 /* Executing a VPT/VPST instruction inside an IT block or a
19529 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
19531 if (now_pred.type == SCALAR_PRED)
19532 as_tsktsk (MVE_NOT_IT);
19533 else
19534 as_tsktsk (MVE_NOT_VPT);
19535 return SUCCESS;
19537 else
19539 /* VPT/VPST do not accept condition codes. */
19540 inst.error = BAD_SYNTAX;
19541 return FAIL;
19545 break;
19548 return SUCCESS;
19551 struct depr_insn_mask
19553 unsigned long pattern;
19554 unsigned long mask;
19555 const char* description;
19558 /* List of 16-bit instruction patterns deprecated in an IT block in
19559 ARMv8. */
19560 static const struct depr_insn_mask depr_it_insns[] = {
19561 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
19562 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
19563 { 0xa000, 0xb800, N_("ADR") },
19564 { 0x4800, 0xf800, N_("Literal loads") },
19565 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
19566 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
19567 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
19568 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
19569 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
19570 { 0, 0, NULL }
19573 static void
19574 it_fsm_post_encode (void)
19576 int is_last;
19578 if (!now_pred.state_handled)
19579 handle_pred_state ();
19581 if (now_pred.insn_cond
19582 && !now_pred.warn_deprecated
19583 && warn_on_deprecated
19584 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
19585 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
19587 if (inst.instruction >= 0x10000)
19589 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
19590 "performance deprecated in ARMv8-A and ARMv8-R"));
19591 now_pred.warn_deprecated = TRUE;
19593 else
19595 const struct depr_insn_mask *p = depr_it_insns;
19597 while (p->mask != 0)
19599 if ((inst.instruction & p->mask) == p->pattern)
19601 as_tsktsk (_("IT blocks containing 16-bit Thumb "
19602 "instructions of the following class are "
19603 "performance deprecated in ARMv8-A and "
19604 "ARMv8-R: %s"), p->description);
19605 now_pred.warn_deprecated = TRUE;
19606 break;
19609 ++p;
19613 if (now_pred.block_length > 1)
19615 as_tsktsk (_("IT blocks containing more than one conditional "
19616 "instruction are performance deprecated in ARMv8-A and "
19617 "ARMv8-R"));
19618 now_pred.warn_deprecated = TRUE;
19622 is_last = (now_pred.mask == 0x10);
19623 if (is_last)
19625 now_pred.state = OUTSIDE_PRED_BLOCK;
19626 now_pred.mask = 0;
19630 static void
19631 force_automatic_it_block_close (void)
19633 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
19635 close_automatic_it_block ();
19636 now_pred.state = OUTSIDE_PRED_BLOCK;
19637 now_pred.mask = 0;
19641 static int
19642 in_pred_block (void)
19644 if (!now_pred.state_handled)
19645 handle_pred_state ();
19647 return now_pred.state != OUTSIDE_PRED_BLOCK;
19650 /* Whether OPCODE only has T32 encoding. Since this function is only used by
19651 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
19652 here, hence the "known" in the function name. */
19654 static bfd_boolean
19655 known_t32_only_insn (const struct asm_opcode *opcode)
19657 /* Original Thumb-1 wide instruction. */
19658 if (opcode->tencode == do_t_blx
19659 || opcode->tencode == do_t_branch23
19660 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
19661 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
19662 return TRUE;
19664 /* Wide-only instruction added to ARMv8-M Baseline. */
19665 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
19666 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
19667 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
19668 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
19669 return TRUE;
19671 return FALSE;
19674 /* Whether wide instruction variant can be used if available for a valid OPCODE
19675 in ARCH. */
19677 static bfd_boolean
19678 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
19680 if (known_t32_only_insn (opcode))
19681 return TRUE;
19683 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
19684 of variant T3 of B.W is checked in do_t_branch. */
19685 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19686 && opcode->tencode == do_t_branch)
19687 return TRUE;
19689 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
19690 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
19691 && opcode->tencode == do_t_mov_cmp
19692 /* Make sure CMP instruction is not affected. */
19693 && opcode->aencode == do_mov)
19694 return TRUE;
19696 /* Wide instruction variants of all instructions with narrow *and* wide
19697 variants become available with ARMv6t2. Other opcodes are either
19698 narrow-only or wide-only and are thus available if OPCODE is valid. */
19699 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
19700 return TRUE;
19702 /* OPCODE with narrow only instruction variant or wide variant not
19703 available. */
19704 return FALSE;
19707 void
19708 md_assemble (char *str)
19710 char *p = str;
19711 const struct asm_opcode * opcode;
19713 /* Align the previous label if needed. */
19714 if (last_label_seen != NULL)
19716 symbol_set_frag (last_label_seen, frag_now);
19717 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
19718 S_SET_SEGMENT (last_label_seen, now_seg);
19721 memset (&inst, '\0', sizeof (inst));
19722 int r;
19723 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
19724 inst.relocs[r].type = BFD_RELOC_UNUSED;
19726 opcode = opcode_lookup (&p);
19727 if (!opcode)
19729 /* It wasn't an instruction, but it might be a register alias of
19730 the form alias .req reg, or a Neon .dn/.qn directive. */
19731 if (! create_register_alias (str, p)
19732 && ! create_neon_reg_alias (str, p))
19733 as_bad (_("bad instruction `%s'"), str);
19735 return;
19738 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
19739 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
19741 /* The value which unconditional instructions should have in place of the
19742 condition field. */
19743 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
19745 if (thumb_mode)
19747 arm_feature_set variant;
19749 variant = cpu_variant;
19750 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
19751 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
19752 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
19753 /* Check that this instruction is supported for this CPU. */
19754 if (!opcode->tvariant
19755 || (thumb_mode == 1
19756 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
19758 if (opcode->tencode == do_t_swi)
19759 as_bad (_("SVC is not permitted on this architecture"));
19760 else
19761 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
19762 return;
19764 if (inst.cond != COND_ALWAYS && !unified_syntax
19765 && opcode->tencode != do_t_branch)
19767 as_bad (_("Thumb does not support conditional execution"));
19768 return;
19771 /* Two things are addressed here:
19772 1) Implicit require narrow instructions on Thumb-1.
19773 This avoids relaxation accidentally introducing Thumb-2
19774 instructions.
19775 2) Reject wide instructions in non Thumb-2 cores.
19777 Only instructions with narrow and wide variants need to be handled
19778 but selecting all non wide-only instructions is easier. */
19779 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
19780 && !t32_insn_ok (variant, opcode))
19782 if (inst.size_req == 0)
19783 inst.size_req = 2;
19784 else if (inst.size_req == 4)
19786 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
19787 as_bad (_("selected processor does not support 32bit wide "
19788 "variant of instruction `%s'"), str);
19789 else
19790 as_bad (_("selected processor does not support `%s' in "
19791 "Thumb-2 mode"), str);
19792 return;
19796 inst.instruction = opcode->tvalue;
19798 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
19800 /* Prepare the pred_insn_type for those encodings that don't set
19801 it. */
19802 it_fsm_pre_encode ();
19804 opcode->tencode ();
19806 it_fsm_post_encode ();
19809 if (!(inst.error || inst.relax))
19811 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
19812 inst.size = (inst.instruction > 0xffff ? 4 : 2);
19813 if (inst.size_req && inst.size_req != inst.size)
19815 as_bad (_("cannot honor width suffix -- `%s'"), str);
19816 return;
19820 /* Something has gone badly wrong if we try to relax a fixed size
19821 instruction. */
19822 gas_assert (inst.size_req == 0 || !inst.relax);
19824 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19825 *opcode->tvariant);
19826 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
19827 set those bits when Thumb-2 32-bit instructions are seen. The impact
19828 of relaxable instructions will be considered later after we finish all
19829 relaxation. */
19830 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
19831 variant = arm_arch_none;
19832 else
19833 variant = cpu_variant;
19834 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
19835 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
19836 arm_ext_v6t2);
19838 check_neon_suffixes;
19840 if (!inst.error)
19842 mapping_state (MAP_THUMB);
19845 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19847 bfd_boolean is_bx;
19849 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
19850 is_bx = (opcode->aencode == do_bx);
19852 /* Check that this instruction is supported for this CPU. */
19853 if (!(is_bx && fix_v4bx)
19854 && !(opcode->avariant &&
19855 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
19857 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
19858 return;
19860 if (inst.size_req)
19862 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
19863 return;
19866 inst.instruction = opcode->avalue;
19867 if (opcode->tag == OT_unconditionalF)
19868 inst.instruction |= 0xFU << 28;
19869 else
19870 inst.instruction |= inst.cond << 28;
19871 inst.size = INSN_SIZE;
19872 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
19874 it_fsm_pre_encode ();
19875 opcode->aencode ();
19876 it_fsm_post_encode ();
19878 /* Arm mode bx is marked as both v4T and v5 because it's still required
19879 on a hypothetical non-thumb v5 core. */
19880 if (is_bx)
19881 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
19882 else
19883 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
19884 *opcode->avariant);
19886 check_neon_suffixes;
19888 if (!inst.error)
19890 mapping_state (MAP_ARM);
19893 else
19895 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
19896 "-- `%s'"), str);
19897 return;
19899 output_inst (str);
19902 static void
19903 check_pred_blocks_finished (void)
19905 #ifdef OBJ_ELF
19906 asection *sect;
19908 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
19909 if (seg_info (sect)->tc_segment_info_data.current_pred.state
19910 == MANUAL_PRED_BLOCK)
19912 if (now_pred.type == SCALAR_PRED)
19913 as_warn (_("section '%s' finished with an open IT block."),
19914 sect->name);
19915 else
19916 as_warn (_("section '%s' finished with an open VPT/VPST block."),
19917 sect->name);
19919 #else
19920 if (now_pred.state == MANUAL_PRED_BLOCK)
19922 if (now_pred.type == SCALAR_PRED)
19923 as_warn (_("file finished with an open IT block."));
19924 else
19925 as_warn (_("file finished with an open VPT/VPST block."));
19927 #endif
19930 /* Various frobbings of labels and their addresses. */
19932 void
19933 arm_start_line_hook (void)
19935 last_label_seen = NULL;
19938 void
19939 arm_frob_label (symbolS * sym)
19941 last_label_seen = sym;
19943 ARM_SET_THUMB (sym, thumb_mode);
19945 #if defined OBJ_COFF || defined OBJ_ELF
19946 ARM_SET_INTERWORK (sym, support_interwork);
19947 #endif
19949 force_automatic_it_block_close ();
19951 /* Note - do not allow local symbols (.Lxxx) to be labelled
19952 as Thumb functions. This is because these labels, whilst
19953 they exist inside Thumb code, are not the entry points for
19954 possible ARM->Thumb calls. Also, these labels can be used
19955 as part of a computed goto or switch statement. eg gcc
19956 can generate code that looks like this:
19958 ldr r2, [pc, .Laaa]
19959 lsl r3, r3, #2
19960 ldr r2, [r3, r2]
19961 mov pc, r2
19963 .Lbbb: .word .Lxxx
19964 .Lccc: .word .Lyyy
19965 ..etc...
19966 .Laaa: .word Lbbb
19968 The first instruction loads the address of the jump table.
19969 The second instruction converts a table index into a byte offset.
19970 The third instruction gets the jump address out of the table.
19971 The fourth instruction performs the jump.
19973 If the address stored at .Laaa is that of a symbol which has the
19974 Thumb_Func bit set, then the linker will arrange for this address
19975 to have the bottom bit set, which in turn would mean that the
19976 address computation performed by the third instruction would end
19977 up with the bottom bit set. Since the ARM is capable of unaligned
19978 word loads, the instruction would then load the incorrect address
19979 out of the jump table, and chaos would ensue. */
19980 if (label_is_thumb_function_name
19981 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19982 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
19984 /* When the address of a Thumb function is taken the bottom
19985 bit of that address should be set. This will allow
19986 interworking between Arm and Thumb functions to work
19987 correctly. */
19989 THUMB_SET_FUNC (sym, 1);
19991 label_is_thumb_function_name = FALSE;
19994 dwarf2_emit_label (sym);
19997 bfd_boolean
19998 arm_data_in_code (void)
20000 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
20002 *input_line_pointer = '/';
20003 input_line_pointer += 5;
20004 *input_line_pointer = 0;
20005 return TRUE;
20008 return FALSE;
20011 char *
20012 arm_canonicalize_symbol_name (char * name)
20014 int len;
20016 if (thumb_mode && (len = strlen (name)) > 5
20017 && streq (name + len - 5, "/data"))
20018 *(name + len - 5) = 0;
20020 return name;
20023 /* Table of all register names defined by default. The user can
20024 define additional names with .req. Note that all register names
20025 should appear in both upper and lowercase variants. Some registers
20026 also have mixed-case names. */
20028 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
20029 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
20030 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
20031 #define REGSET(p,t) \
20032 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
20033 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
20034 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
20035 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
20036 #define REGSETH(p,t) \
20037 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
20038 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
20039 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
20040 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
20041 #define REGSET2(p,t) \
20042 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
20043 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
20044 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
20045 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
20046 #define SPLRBANK(base,bank,t) \
20047 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
20048 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
20049 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
20050 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
20051 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
20052 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
20054 static const struct reg_entry reg_names[] =
20056 /* ARM integer registers. */
20057 REGSET(r, RN), REGSET(R, RN),
20059 /* ATPCS synonyms. */
20060 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
20061 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
20062 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
20064 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
20065 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
20066 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
20068 /* Well-known aliases. */
20069 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
20070 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
20072 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
20073 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
20075 /* Coprocessor numbers. */
20076 REGSET(p, CP), REGSET(P, CP),
20078 /* Coprocessor register numbers. The "cr" variants are for backward
20079 compatibility. */
20080 REGSET(c, CN), REGSET(C, CN),
20081 REGSET(cr, CN), REGSET(CR, CN),
20083 /* ARM banked registers. */
20084 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
20085 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
20086 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
20087 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
20088 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
20089 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
20090 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
20092 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
20093 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
20094 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
20095 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
20096 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
20097 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
20098 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
20099 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
20101 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
20102 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
20103 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
20104 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
20105 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
20106 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
20107 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
20108 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
20109 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
20111 /* FPA registers. */
20112 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
20113 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
20115 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
20116 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
20118 /* VFP SP registers. */
20119 REGSET(s,VFS), REGSET(S,VFS),
20120 REGSETH(s,VFS), REGSETH(S,VFS),
20122 /* VFP DP Registers. */
20123 REGSET(d,VFD), REGSET(D,VFD),
20124 /* Extra Neon DP registers. */
20125 REGSETH(d,VFD), REGSETH(D,VFD),
20127 /* Neon QP registers. */
20128 REGSET2(q,NQ), REGSET2(Q,NQ),
20130 /* VFP control registers. */
20131 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
20132 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
20133 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
20134 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
20135 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
20136 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
20137 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
20139 /* Maverick DSP coprocessor registers. */
20140 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
20141 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
20143 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
20144 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
20145 REGDEF(dspsc,0,DSPSC),
20147 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
20148 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
20149 REGDEF(DSPSC,0,DSPSC),
20151 /* iWMMXt data registers - p0, c0-15. */
20152 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
20154 /* iWMMXt control registers - p1, c0-3. */
20155 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
20156 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
20157 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
20158 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
20160 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
20161 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
20162 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
20163 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
20164 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
20166 /* XScale accumulator registers. */
20167 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
20169 #undef REGDEF
20170 #undef REGNUM
20171 #undef REGSET
20173 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
20174 within psr_required_here. */
20175 static const struct asm_psr psrs[] =
20177 /* Backward compatibility notation. Note that "all" is no longer
20178 truly all possible PSR bits. */
20179 {"all", PSR_c | PSR_f},
20180 {"flg", PSR_f},
20181 {"ctl", PSR_c},
20183 /* Individual flags. */
20184 {"f", PSR_f},
20185 {"c", PSR_c},
20186 {"x", PSR_x},
20187 {"s", PSR_s},
20189 /* Combinations of flags. */
20190 {"fs", PSR_f | PSR_s},
20191 {"fx", PSR_f | PSR_x},
20192 {"fc", PSR_f | PSR_c},
20193 {"sf", PSR_s | PSR_f},
20194 {"sx", PSR_s | PSR_x},
20195 {"sc", PSR_s | PSR_c},
20196 {"xf", PSR_x | PSR_f},
20197 {"xs", PSR_x | PSR_s},
20198 {"xc", PSR_x | PSR_c},
20199 {"cf", PSR_c | PSR_f},
20200 {"cs", PSR_c | PSR_s},
20201 {"cx", PSR_c | PSR_x},
20202 {"fsx", PSR_f | PSR_s | PSR_x},
20203 {"fsc", PSR_f | PSR_s | PSR_c},
20204 {"fxs", PSR_f | PSR_x | PSR_s},
20205 {"fxc", PSR_f | PSR_x | PSR_c},
20206 {"fcs", PSR_f | PSR_c | PSR_s},
20207 {"fcx", PSR_f | PSR_c | PSR_x},
20208 {"sfx", PSR_s | PSR_f | PSR_x},
20209 {"sfc", PSR_s | PSR_f | PSR_c},
20210 {"sxf", PSR_s | PSR_x | PSR_f},
20211 {"sxc", PSR_s | PSR_x | PSR_c},
20212 {"scf", PSR_s | PSR_c | PSR_f},
20213 {"scx", PSR_s | PSR_c | PSR_x},
20214 {"xfs", PSR_x | PSR_f | PSR_s},
20215 {"xfc", PSR_x | PSR_f | PSR_c},
20216 {"xsf", PSR_x | PSR_s | PSR_f},
20217 {"xsc", PSR_x | PSR_s | PSR_c},
20218 {"xcf", PSR_x | PSR_c | PSR_f},
20219 {"xcs", PSR_x | PSR_c | PSR_s},
20220 {"cfs", PSR_c | PSR_f | PSR_s},
20221 {"cfx", PSR_c | PSR_f | PSR_x},
20222 {"csf", PSR_c | PSR_s | PSR_f},
20223 {"csx", PSR_c | PSR_s | PSR_x},
20224 {"cxf", PSR_c | PSR_x | PSR_f},
20225 {"cxs", PSR_c | PSR_x | PSR_s},
20226 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
20227 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
20228 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
20229 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
20230 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
20231 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
20232 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
20233 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
20234 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
20235 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
20236 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
20237 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
20238 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
20239 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
20240 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
20241 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
20242 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
20243 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
20244 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
20245 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
20246 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
20247 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
20248 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
20249 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
20252 /* Table of V7M psr names. */
20253 static const struct asm_psr v7m_psrs[] =
20255 {"apsr", 0x0 }, {"APSR", 0x0 },
20256 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
20257 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
20258 {"psr", 0x3 }, {"PSR", 0x3 },
20259 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
20260 {"ipsr", 0x5 }, {"IPSR", 0x5 },
20261 {"epsr", 0x6 }, {"EPSR", 0x6 },
20262 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
20263 {"msp", 0x8 }, {"MSP", 0x8 },
20264 {"psp", 0x9 }, {"PSP", 0x9 },
20265 {"msplim", 0xa }, {"MSPLIM", 0xa },
20266 {"psplim", 0xb }, {"PSPLIM", 0xb },
20267 {"primask", 0x10}, {"PRIMASK", 0x10},
20268 {"basepri", 0x11}, {"BASEPRI", 0x11},
20269 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
20270 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
20271 {"control", 0x14}, {"CONTROL", 0x14},
20272 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
20273 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
20274 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
20275 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
20276 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
20277 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
20278 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
20279 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
20280 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
20283 /* Table of all shift-in-operand names. */
20284 static const struct asm_shift_name shift_names [] =
20286 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
20287 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
20288 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
20289 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
20290 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
20291 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
20294 /* Table of all explicit relocation names. */
20295 #ifdef OBJ_ELF
20296 static struct reloc_entry reloc_names[] =
20298 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
20299 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
20300 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
20301 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
20302 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
20303 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
20304 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
20305 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
20306 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
20307 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
20308 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
20309 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
20310 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
20311 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
20312 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
20313 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
20314 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
20315 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
20316 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
20317 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
20318 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20319 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
20320 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
20321 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
20322 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
20323 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
20324 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
20326 #endif
20328 /* Table of all conditional affixes. */
20329 static const struct asm_cond conds[] =
20331 {"eq", 0x0},
20332 {"ne", 0x1},
20333 {"cs", 0x2}, {"hs", 0x2},
20334 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
20335 {"mi", 0x4},
20336 {"pl", 0x5},
20337 {"vs", 0x6},
20338 {"vc", 0x7},
20339 {"hi", 0x8},
20340 {"ls", 0x9},
20341 {"ge", 0xa},
20342 {"lt", 0xb},
20343 {"gt", 0xc},
20344 {"le", 0xd},
20345 {"al", 0xe}
20347 static const struct asm_cond vconds[] =
20349 {"t", 0xf},
20350 {"e", 0x10}
20353 #define UL_BARRIER(L,U,CODE,FEAT) \
20354 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
20355 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
20357 static struct asm_barrier_opt barrier_opt_names[] =
20359 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
20360 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
20361 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
20362 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
20363 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
20364 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
20365 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
20366 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
20367 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
20368 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
20369 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
20370 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
20371 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
20372 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
20373 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
20374 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
20377 #undef UL_BARRIER
20379 /* Table of ARM-format instructions. */
20381 /* Macros for gluing together operand strings. N.B. In all cases
20382 other than OPS0, the trailing OP_stop comes from default
20383 zero-initialization of the unspecified elements of the array. */
20384 #define OPS0() { OP_stop, }
20385 #define OPS1(a) { OP_##a, }
20386 #define OPS2(a,b) { OP_##a,OP_##b, }
20387 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
20388 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
20389 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
20390 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
20392 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
20393 This is useful when mixing operands for ARM and THUMB, i.e. using the
20394 MIX_ARM_THUMB_OPERANDS macro.
20395 In order to use these macros, prefix the number of operands with _
20396 e.g. _3. */
20397 #define OPS_1(a) { a, }
20398 #define OPS_2(a,b) { a,b, }
20399 #define OPS_3(a,b,c) { a,b,c, }
20400 #define OPS_4(a,b,c,d) { a,b,c,d, }
20401 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
20402 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
20404 /* These macros abstract out the exact format of the mnemonic table and
20405 save some repeated characters. */
20407 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
20408 #define TxCE(mnem, op, top, nops, ops, ae, te) \
20409 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
20410 THUMB_VARIANT, do_##ae, do_##te, 0 }
20412 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
20413 a T_MNEM_xyz enumerator. */
20414 #define TCE(mnem, aop, top, nops, ops, ae, te) \
20415 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
20416 #define tCE(mnem, aop, top, nops, ops, ae, te) \
20417 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
20419 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
20420 infix after the third character. */
20421 #define TxC3(mnem, op, top, nops, ops, ae, te) \
20422 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
20423 THUMB_VARIANT, do_##ae, do_##te, 0 }
20424 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
20425 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
20426 THUMB_VARIANT, do_##ae, do_##te, 0 }
20427 #define TC3(mnem, aop, top, nops, ops, ae, te) \
20428 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
20429 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
20430 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
20431 #define tC3(mnem, aop, top, nops, ops, ae, te) \
20432 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
20433 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
20434 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
20436 /* Mnemonic that cannot be conditionalized. The ARM condition-code
20437 field is still 0xE. Many of the Thumb variants can be executed
20438 conditionally, so this is checked separately. */
20439 #define TUE(mnem, op, top, nops, ops, ae, te) \
20440 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
20441 THUMB_VARIANT, do_##ae, do_##te, 0 }
20443 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
20444 Used by mnemonics that have very minimal differences in the encoding for
20445 ARM and Thumb variants and can be handled in a common function. */
20446 #define TUEc(mnem, op, top, nops, ops, en) \
20447 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
20448 THUMB_VARIANT, do_##en, do_##en, 0 }
20450 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
20451 condition code field. */
20452 #define TUF(mnem, op, top, nops, ops, ae, te) \
20453 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
20454 THUMB_VARIANT, do_##ae, do_##te, 0 }
20456 /* ARM-only variants of all the above. */
20457 #define CE(mnem, op, nops, ops, ae) \
20458 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20460 #define C3(mnem, op, nops, ops, ae) \
20461 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20463 /* Thumb-only variants of TCE and TUE. */
20464 #define ToC(mnem, top, nops, ops, te) \
20465 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
20466 do_##te, 0 }
20468 #define ToU(mnem, top, nops, ops, te) \
20469 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
20470 NULL, do_##te, 0 }
20472 /* T_MNEM_xyz enumerator variants of ToC. */
20473 #define toC(mnem, top, nops, ops, te) \
20474 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
20475 do_##te, 0 }
20477 /* T_MNEM_xyz enumerator variants of ToU. */
20478 #define toU(mnem, top, nops, ops, te) \
20479 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
20480 NULL, do_##te, 0 }
20482 /* Legacy mnemonics that always have conditional infix after the third
20483 character. */
20484 #define CL(mnem, op, nops, ops, ae) \
20485 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
20486 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20488 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
20489 #define cCE(mnem, op, nops, ops, ae) \
20490 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
20492 /* Legacy coprocessor instructions where conditional infix and conditional
20493 suffix are ambiguous. For consistency this includes all FPA instructions,
20494 not just the potentially ambiguous ones. */
20495 #define cCL(mnem, op, nops, ops, ae) \
20496 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
20497 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
20499 /* Coprocessor, takes either a suffix or a position-3 infix
20500 (for an FPA corner case). */
20501 #define C3E(mnem, op, nops, ops, ae) \
20502 { mnem, OPS##nops ops, OT_csuf_or_in3, \
20503 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
20505 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
20506 { m1 #m2 m3, OPS##nops ops, \
20507 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
20508 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20510 #define CM(m1, m2, op, nops, ops, ae) \
20511 xCM_ (m1, , m2, op, nops, ops, ae), \
20512 xCM_ (m1, eq, m2, op, nops, ops, ae), \
20513 xCM_ (m1, ne, m2, op, nops, ops, ae), \
20514 xCM_ (m1, cs, m2, op, nops, ops, ae), \
20515 xCM_ (m1, hs, m2, op, nops, ops, ae), \
20516 xCM_ (m1, cc, m2, op, nops, ops, ae), \
20517 xCM_ (m1, ul, m2, op, nops, ops, ae), \
20518 xCM_ (m1, lo, m2, op, nops, ops, ae), \
20519 xCM_ (m1, mi, m2, op, nops, ops, ae), \
20520 xCM_ (m1, pl, m2, op, nops, ops, ae), \
20521 xCM_ (m1, vs, m2, op, nops, ops, ae), \
20522 xCM_ (m1, vc, m2, op, nops, ops, ae), \
20523 xCM_ (m1, hi, m2, op, nops, ops, ae), \
20524 xCM_ (m1, ls, m2, op, nops, ops, ae), \
20525 xCM_ (m1, ge, m2, op, nops, ops, ae), \
20526 xCM_ (m1, lt, m2, op, nops, ops, ae), \
20527 xCM_ (m1, gt, m2, op, nops, ops, ae), \
20528 xCM_ (m1, le, m2, op, nops, ops, ae), \
20529 xCM_ (m1, al, m2, op, nops, ops, ae)
20531 #define UE(mnem, op, nops, ops, ae) \
20532 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20534 #define UF(mnem, op, nops, ops, ae) \
20535 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
20537 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
20538 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
20539 use the same encoding function for each. */
20540 #define NUF(mnem, op, nops, ops, enc) \
20541 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
20542 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
20544 /* Neon data processing, version which indirects through neon_enc_tab for
20545 the various overloaded versions of opcodes. */
20546 #define nUF(mnem, op, nops, ops, enc) \
20547 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
20548 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
20550 /* Neon insn with conditional suffix for the ARM version, non-overloaded
20551 version. */
20552 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
20553 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
20554 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
20556 #define NCE(mnem, op, nops, ops, enc) \
20557 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
20559 #define NCEF(mnem, op, nops, ops, enc) \
20560 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
20562 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
20563 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
20564 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
20565 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
20567 #define nCE(mnem, op, nops, ops, enc) \
20568 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
20570 #define nCEF(mnem, op, nops, ops, enc) \
20571 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
20573 /* */
20574 #define mCEF(mnem, op, nops, ops, enc) \
20575 { #mnem, OPS##nops ops, OT_csuffixF, 0, M_MNEM##op, \
20576 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20579 /* nCEF but for MVE predicated instructions. */
20580 #define mnCEF(mnem, op, nops, ops, enc) \
20581 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
20583 /* nCE but for MVE predicated instructions. */
20584 #define mnCE(mnem, op, nops, ops, enc) \
20585 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
20587 /* NUF but for potentially MVE predicated instructions. */
20588 #define MNUF(mnem, op, nops, ops, enc) \
20589 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
20590 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20592 /* nUF but for potentially MVE predicated instructions. */
20593 #define mnUF(mnem, op, nops, ops, enc) \
20594 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
20595 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
20597 /* ToC but for potentially MVE predicated instructions. */
20598 #define mToC(mnem, top, nops, ops, te) \
20599 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
20600 do_##te, 1 }
20602 /* NCE but for MVE predicated instructions. */
20603 #define MNCE(mnem, op, nops, ops, enc) \
20604 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
20606 /* NCEF but for MVE predicated instructions. */
20607 #define MNCEF(mnem, op, nops, ops, enc) \
20608 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
20609 #define do_0 0
20611 static const struct asm_opcode insns[] =
20613 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
20614 #define THUMB_VARIANT & arm_ext_v4t
20615 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
20616 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
20617 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
20618 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
20619 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
20620 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
20621 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
20622 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
20623 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
20624 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
20625 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
20626 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
20627 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
20628 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
20629 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
20630 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
20632 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
20633 for setting PSR flag bits. They are obsolete in V6 and do not
20634 have Thumb equivalents. */
20635 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20636 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
20637 CL("tstp", 110f000, 2, (RR, SH), cmp),
20638 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20639 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
20640 CL("cmpp", 150f000, 2, (RR, SH), cmp),
20641 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20642 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
20643 CL("cmnp", 170f000, 2, (RR, SH), cmp),
20645 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
20646 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
20647 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
20648 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
20650 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
20651 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
20652 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
20653 OP_RRnpc),
20654 OP_ADDRGLDR),ldst, t_ldst),
20655 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
20657 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20658 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20659 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20660 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20661 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20662 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20664 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
20665 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
20667 /* Pseudo ops. */
20668 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
20669 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
20670 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
20671 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
20673 /* Thumb-compatibility pseudo ops. */
20674 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
20675 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
20676 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
20677 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
20678 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
20679 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
20680 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
20681 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
20682 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
20683 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
20684 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
20685 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
20687 /* These may simplify to neg. */
20688 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
20689 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
20691 #undef THUMB_VARIANT
20692 #define THUMB_VARIANT & arm_ext_os
20694 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
20695 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
20697 #undef THUMB_VARIANT
20698 #define THUMB_VARIANT & arm_ext_v6
20700 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
20702 /* V1 instructions with no Thumb analogue prior to V6T2. */
20703 #undef THUMB_VARIANT
20704 #define THUMB_VARIANT & arm_ext_v6t2
20706 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20707 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
20708 CL("teqp", 130f000, 2, (RR, SH), cmp),
20710 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20711 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20712 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
20713 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
20715 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20716 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20718 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20719 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
20721 /* V1 instructions with no Thumb analogue at all. */
20722 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
20723 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
20725 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
20726 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
20727 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
20728 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
20729 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
20730 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
20731 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
20732 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
20734 #undef ARM_VARIANT
20735 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
20736 #undef THUMB_VARIANT
20737 #define THUMB_VARIANT & arm_ext_v4t
20739 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
20740 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
20742 #undef THUMB_VARIANT
20743 #define THUMB_VARIANT & arm_ext_v6t2
20745 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
20746 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
20748 /* Generic coprocessor instructions. */
20749 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20750 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20751 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20752 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20753 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20754 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20755 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
20757 #undef ARM_VARIANT
20758 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
20760 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
20761 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
20763 #undef ARM_VARIANT
20764 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
20765 #undef THUMB_VARIANT
20766 #define THUMB_VARIANT & arm_ext_msr
20768 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
20769 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
20771 #undef ARM_VARIANT
20772 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
20773 #undef THUMB_VARIANT
20774 #define THUMB_VARIANT & arm_ext_v6t2
20776 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20777 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20778 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20779 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20780 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20781 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20782 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
20783 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
20785 #undef ARM_VARIANT
20786 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
20787 #undef THUMB_VARIANT
20788 #define THUMB_VARIANT & arm_ext_v4t
20790 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20791 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20792 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20793 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20794 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20795 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
20797 #undef ARM_VARIANT
20798 #define ARM_VARIANT & arm_ext_v4t_5
20800 /* ARM Architecture 4T. */
20801 /* Note: bx (and blx) are required on V5, even if the processor does
20802 not support Thumb. */
20803 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
20805 #undef ARM_VARIANT
20806 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
20807 #undef THUMB_VARIANT
20808 #define THUMB_VARIANT & arm_ext_v5t
20810 /* Note: blx has 2 variants; the .value coded here is for
20811 BLX(2). Only this variant has conditional execution. */
20812 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
20813 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
20815 #undef THUMB_VARIANT
20816 #define THUMB_VARIANT & arm_ext_v6t2
20818 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
20819 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20820 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20821 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20822 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
20823 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
20824 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20825 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
20827 #undef ARM_VARIANT
20828 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
20829 #undef THUMB_VARIANT
20830 #define THUMB_VARIANT & arm_ext_v5exp
20832 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20833 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20834 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20835 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20837 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20838 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
20840 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20841 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20842 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20843 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
20845 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20846 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20847 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20848 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20850 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20851 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20853 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20854 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20855 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20856 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
20858 #undef ARM_VARIANT
20859 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
20860 #undef THUMB_VARIANT
20861 #define THUMB_VARIANT & arm_ext_v6t2
20863 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
20864 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
20865 ldrd, t_ldstd),
20866 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
20867 ADDRGLDRS), ldrd, t_ldstd),
20869 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20870 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20872 #undef ARM_VARIANT
20873 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
20875 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
20877 #undef ARM_VARIANT
20878 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
20879 #undef THUMB_VARIANT
20880 #define THUMB_VARIANT & arm_ext_v6
20882 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
20883 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
20884 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20885 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20886 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
20887 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20888 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20889 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20890 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20891 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
20893 #undef THUMB_VARIANT
20894 #define THUMB_VARIANT & arm_ext_v6t2_v8m
20896 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
20897 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20898 strex, t_strex),
20899 #undef THUMB_VARIANT
20900 #define THUMB_VARIANT & arm_ext_v6t2
20902 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20903 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
20905 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
20906 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
20908 /* ARM V6 not included in V7M. */
20909 #undef THUMB_VARIANT
20910 #define THUMB_VARIANT & arm_ext_v6_notm
20911 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
20912 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
20913 UF(rfeib, 9900a00, 1, (RRw), rfe),
20914 UF(rfeda, 8100a00, 1, (RRw), rfe),
20915 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20916 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
20917 UF(rfefa, 8100a00, 1, (RRw), rfe),
20918 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
20919 UF(rfeed, 9900a00, 1, (RRw), rfe),
20920 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20921 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20922 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
20923 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
20924 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
20925 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
20926 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
20927 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
20928 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
20929 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
20931 /* ARM V6 not included in V7M (eg. integer SIMD). */
20932 #undef THUMB_VARIANT
20933 #define THUMB_VARIANT & arm_ext_v6_dsp
20934 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
20935 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
20936 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20937 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20938 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20939 /* Old name for QASX. */
20940 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20941 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20942 /* Old name for QSAX. */
20943 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20944 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20945 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20946 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20947 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20948 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20949 /* Old name for SASX. */
20950 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20951 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20952 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20953 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20954 /* Old name for SHASX. */
20955 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20956 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20957 /* Old name for SHSAX. */
20958 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20959 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20960 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20961 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20962 /* Old name for SSAX. */
20963 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20964 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20965 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20966 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20967 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20968 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20969 /* Old name for UASX. */
20970 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20971 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20972 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20973 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20974 /* Old name for UHASX. */
20975 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20976 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20977 /* Old name for UHSAX. */
20978 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20979 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20980 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20981 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20982 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20983 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20984 /* Old name for UQASX. */
20985 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20986 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20987 /* Old name for UQSAX. */
20988 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20989 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20990 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20991 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20992 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20993 /* Old name for USAX. */
20994 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20995 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20996 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20997 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20998 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20999 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21000 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21001 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21002 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
21003 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
21004 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21005 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21006 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21007 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21008 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21009 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21010 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21011 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21012 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
21013 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21014 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21015 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21016 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21017 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21018 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21019 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21020 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21021 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21022 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21023 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
21024 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
21025 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21026 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
21027 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
21029 #undef ARM_VARIANT
21030 #define ARM_VARIANT & arm_ext_v6k_v6t2
21031 #undef THUMB_VARIANT
21032 #define THUMB_VARIANT & arm_ext_v6k_v6t2
21034 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
21035 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
21036 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
21037 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
21039 #undef THUMB_VARIANT
21040 #define THUMB_VARIANT & arm_ext_v6_notm
21041 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
21042 ldrexd, t_ldrexd),
21043 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
21044 RRnpcb), strexd, t_strexd),
21046 #undef THUMB_VARIANT
21047 #define THUMB_VARIANT & arm_ext_v6t2_v8m
21048 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
21049 rd_rn, rd_rn),
21050 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
21051 rd_rn, rd_rn),
21052 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
21053 strex, t_strexbh),
21054 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
21055 strex, t_strexbh),
21056 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
21058 #undef ARM_VARIANT
21059 #define ARM_VARIANT & arm_ext_sec
21060 #undef THUMB_VARIANT
21061 #define THUMB_VARIANT & arm_ext_sec
21063 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
21065 #undef ARM_VARIANT
21066 #define ARM_VARIANT & arm_ext_virt
21067 #undef THUMB_VARIANT
21068 #define THUMB_VARIANT & arm_ext_virt
21070 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
21071 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
21073 #undef ARM_VARIANT
21074 #define ARM_VARIANT & arm_ext_pan
21075 #undef THUMB_VARIANT
21076 #define THUMB_VARIANT & arm_ext_pan
21078 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
21080 #undef ARM_VARIANT
21081 #define ARM_VARIANT & arm_ext_v6t2
21082 #undef THUMB_VARIANT
21083 #define THUMB_VARIANT & arm_ext_v6t2
21085 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
21086 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
21087 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
21088 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
21090 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21091 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
21093 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21094 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21095 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21096 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
21098 #undef ARM_VARIANT
21099 #define ARM_VARIANT & arm_ext_v3
21100 #undef THUMB_VARIANT
21101 #define THUMB_VARIANT & arm_ext_v6t2
21103 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
21104 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
21105 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
21107 #undef ARM_VARIANT
21108 #define ARM_VARIANT & arm_ext_v6t2
21109 #undef THUMB_VARIANT
21110 #define THUMB_VARIANT & arm_ext_v6t2_v8m
21111 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
21112 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
21114 /* Thumb-only instructions. */
21115 #undef ARM_VARIANT
21116 #define ARM_VARIANT NULL
21117 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
21118 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
21120 /* ARM does not really have an IT instruction, so always allow it.
21121 The opcode is copied from Thumb in order to allow warnings in
21122 -mimplicit-it=[never | arm] modes. */
21123 #undef ARM_VARIANT
21124 #define ARM_VARIANT & arm_ext_v1
21125 #undef THUMB_VARIANT
21126 #define THUMB_VARIANT & arm_ext_v6t2
21128 TUE("it", bf08, bf08, 1, (COND), it, t_it),
21129 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
21130 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
21131 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
21132 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
21133 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
21134 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
21135 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
21136 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
21137 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
21138 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
21139 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
21140 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
21141 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
21142 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
21143 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21144 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
21145 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
21147 /* Thumb2 only instructions. */
21148 #undef ARM_VARIANT
21149 #define ARM_VARIANT NULL
21151 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21152 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
21153 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
21154 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
21155 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
21156 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
21158 /* Hardware division instructions. */
21159 #undef ARM_VARIANT
21160 #define ARM_VARIANT & arm_ext_adiv
21161 #undef THUMB_VARIANT
21162 #define THUMB_VARIANT & arm_ext_div
21164 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
21165 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
21167 /* ARM V6M/V7 instructions. */
21168 #undef ARM_VARIANT
21169 #define ARM_VARIANT & arm_ext_barrier
21170 #undef THUMB_VARIANT
21171 #define THUMB_VARIANT & arm_ext_barrier
21173 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
21174 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
21175 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
21177 /* ARM V7 instructions. */
21178 #undef ARM_VARIANT
21179 #define ARM_VARIANT & arm_ext_v7
21180 #undef THUMB_VARIANT
21181 #define THUMB_VARIANT & arm_ext_v7
21183 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
21184 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
21186 #undef ARM_VARIANT
21187 #define ARM_VARIANT & arm_ext_mp
21188 #undef THUMB_VARIANT
21189 #define THUMB_VARIANT & arm_ext_mp
21191 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
21193 /* AArchv8 instructions. */
21194 #undef ARM_VARIANT
21195 #define ARM_VARIANT & arm_ext_v8
21197 /* Instructions shared between armv8-a and armv8-m. */
21198 #undef THUMB_VARIANT
21199 #define THUMB_VARIANT & arm_ext_atomics
21201 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21202 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21203 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21204 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21205 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21206 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
21207 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21208 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
21209 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
21210 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
21211 stlex, t_stlex),
21212 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
21213 stlex, t_stlex),
21214 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
21215 stlex, t_stlex),
21216 #undef THUMB_VARIANT
21217 #define THUMB_VARIANT & arm_ext_v8
21219 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
21220 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
21221 ldrexd, t_ldrexd),
21222 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
21223 strexd, t_strexd),
21225 /* Defined in V8 but is in undefined encoding space for earlier
21226 architectures. However earlier architectures are required to treat
21227 this instuction as a semihosting trap as well. Hence while not explicitly
21228 defined as such, it is in fact correct to define the instruction for all
21229 architectures. */
21230 #undef THUMB_VARIANT
21231 #define THUMB_VARIANT & arm_ext_v1
21232 #undef ARM_VARIANT
21233 #define ARM_VARIANT & arm_ext_v1
21234 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
21236 /* ARMv8 T32 only. */
21237 #undef ARM_VARIANT
21238 #define ARM_VARIANT NULL
21239 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
21240 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
21241 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
21243 /* FP for ARMv8. */
21244 #undef ARM_VARIANT
21245 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
21246 #undef THUMB_VARIANT
21247 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
21249 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
21250 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
21251 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
21252 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
21253 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
21254 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
21255 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
21256 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
21257 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
21258 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
21259 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
21260 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
21261 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
21262 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
21263 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
21264 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
21265 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
21267 /* Crypto v1 extensions. */
21268 #undef ARM_VARIANT
21269 #define ARM_VARIANT & fpu_crypto_ext_armv8
21270 #undef THUMB_VARIANT
21271 #define THUMB_VARIANT & fpu_crypto_ext_armv8
21273 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
21274 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
21275 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
21276 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
21277 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
21278 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
21279 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
21280 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
21281 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
21282 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
21283 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
21284 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
21285 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
21286 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
21288 #undef ARM_VARIANT
21289 #define ARM_VARIANT & crc_ext_armv8
21290 #undef THUMB_VARIANT
21291 #define THUMB_VARIANT & crc_ext_armv8
21292 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
21293 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
21294 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
21295 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
21296 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
21297 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
21299 /* ARMv8.2 RAS extension. */
21300 #undef ARM_VARIANT
21301 #define ARM_VARIANT & arm_ext_ras
21302 #undef THUMB_VARIANT
21303 #define THUMB_VARIANT & arm_ext_ras
21304 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
21306 #undef ARM_VARIANT
21307 #define ARM_VARIANT & arm_ext_v8_3
21308 #undef THUMB_VARIANT
21309 #define THUMB_VARIANT & arm_ext_v8_3
21310 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
21311 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
21312 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
21314 #undef ARM_VARIANT
21315 #define ARM_VARIANT & fpu_neon_ext_dotprod
21316 #undef THUMB_VARIANT
21317 #define THUMB_VARIANT & fpu_neon_ext_dotprod
21318 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
21319 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
21321 #undef ARM_VARIANT
21322 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
21323 #undef THUMB_VARIANT
21324 #define THUMB_VARIANT NULL
21326 cCE("wfs", e200110, 1, (RR), rd),
21327 cCE("rfs", e300110, 1, (RR), rd),
21328 cCE("wfc", e400110, 1, (RR), rd),
21329 cCE("rfc", e500110, 1, (RR), rd),
21331 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
21332 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
21333 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
21334 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
21336 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
21337 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
21338 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
21339 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
21341 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
21342 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
21343 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
21344 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
21345 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
21346 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
21347 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
21348 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
21349 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
21350 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
21351 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
21352 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
21354 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
21355 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
21356 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
21357 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
21358 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
21359 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
21360 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
21361 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
21362 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
21363 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
21364 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
21365 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
21367 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
21368 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
21369 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
21370 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
21371 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
21372 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
21373 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
21374 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
21375 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
21376 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
21377 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
21378 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
21380 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
21381 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
21382 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
21383 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
21384 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
21385 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
21386 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
21387 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
21388 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
21389 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
21390 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
21391 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
21393 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
21394 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
21395 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
21396 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
21397 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
21398 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
21399 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
21400 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
21401 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
21402 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
21403 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
21404 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
21406 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
21407 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
21408 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
21409 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
21410 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
21411 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
21412 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
21413 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
21414 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
21415 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
21416 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
21417 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
21419 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
21420 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
21421 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
21422 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
21423 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
21424 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
21425 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
21426 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
21427 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
21428 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
21429 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
21430 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
21432 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
21433 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
21434 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
21435 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
21436 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
21437 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
21438 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
21439 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
21440 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
21441 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
21442 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
21443 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
21445 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
21446 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
21447 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
21448 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
21449 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
21450 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
21451 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
21452 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
21453 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
21454 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
21455 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
21456 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
21458 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
21459 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
21460 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
21461 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
21462 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
21463 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
21464 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
21465 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
21466 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
21467 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
21468 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
21469 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
21471 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
21472 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
21473 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
21474 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
21475 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
21476 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
21477 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
21478 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
21479 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
21480 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
21481 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
21482 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
21484 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
21485 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
21486 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
21487 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
21488 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
21489 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
21490 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
21491 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
21492 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
21493 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
21494 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
21495 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
21497 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
21498 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
21499 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
21500 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
21501 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
21502 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
21503 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
21504 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
21505 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
21506 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
21507 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
21508 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
21510 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
21511 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
21512 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
21513 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
21514 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
21515 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
21516 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
21517 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
21518 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
21519 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
21520 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
21521 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
21523 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
21524 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
21525 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
21526 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
21527 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
21528 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
21529 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
21530 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
21531 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
21532 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
21533 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
21534 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
21536 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
21537 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
21538 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
21539 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
21540 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
21541 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
21542 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
21543 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
21544 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
21545 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
21546 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
21547 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
21549 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
21550 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
21551 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
21552 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
21553 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
21554 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21555 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21556 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21557 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
21558 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
21559 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
21560 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
21562 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
21563 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
21564 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
21565 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
21566 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
21567 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21568 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21569 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21570 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
21571 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
21572 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
21573 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
21575 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
21576 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
21577 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
21578 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
21579 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
21580 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21581 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21582 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21583 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
21584 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
21585 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
21586 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
21588 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
21589 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
21590 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
21591 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
21592 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
21593 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21594 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21595 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21596 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
21597 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
21598 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
21599 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
21601 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
21602 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
21603 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
21604 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
21605 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
21606 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21607 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21608 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21609 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
21610 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
21611 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
21612 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
21614 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
21615 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
21616 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
21617 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
21618 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
21619 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21620 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21621 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21622 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
21623 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
21624 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
21625 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
21627 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
21628 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
21629 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
21630 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
21631 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
21632 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21633 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21634 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21635 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
21636 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
21637 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
21638 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
21640 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
21641 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
21642 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
21643 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
21644 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
21645 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21646 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21647 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21648 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
21649 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
21650 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
21651 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
21653 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
21654 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
21655 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
21656 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
21657 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
21658 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21659 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21660 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21661 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
21662 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
21663 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
21664 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
21666 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
21667 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
21668 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
21669 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
21670 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
21671 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21672 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21673 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21674 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
21675 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
21676 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
21677 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
21679 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21680 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21681 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21682 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21683 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21684 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21685 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21686 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21687 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21688 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21689 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21690 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21692 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21693 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21694 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21695 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21696 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21697 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21698 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21699 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21700 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21701 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21702 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21703 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21705 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
21706 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
21707 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
21708 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
21709 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
21710 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
21711 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
21712 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
21713 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
21714 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
21715 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
21716 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
21718 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
21719 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
21720 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
21721 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
21723 cCL("flts", e000110, 2, (RF, RR), rn_rd),
21724 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
21725 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
21726 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
21727 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
21728 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
21729 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
21730 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
21731 cCL("flte", e080110, 2, (RF, RR), rn_rd),
21732 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
21733 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
21734 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
21736 /* The implementation of the FIX instruction is broken on some
21737 assemblers, in that it accepts a precision specifier as well as a
21738 rounding specifier, despite the fact that this is meaningless.
21739 To be more compatible, we accept it as well, though of course it
21740 does not set any bits. */
21741 cCE("fix", e100110, 2, (RR, RF), rd_rm),
21742 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
21743 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
21744 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
21745 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
21746 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
21747 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
21748 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
21749 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
21750 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
21751 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
21752 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
21753 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
21755 /* Instructions that were new with the real FPA, call them V2. */
21756 #undef ARM_VARIANT
21757 #define ARM_VARIANT & fpu_fpa_ext_v2
21759 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21760 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21761 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21762 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21763 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21764 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
21766 #undef ARM_VARIANT
21767 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
21769 /* Moves and type conversions. */
21770 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
21771 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
21772 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
21773 cCE("fmstat", ef1fa10, 0, (), noargs),
21774 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
21775 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21776 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
21777 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
21778 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
21779 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21780 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
21781 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
21782 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
21783 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
21785 /* Memory operations. */
21786 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
21787 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
21788 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21789 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21790 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21791 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21792 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21793 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21794 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21795 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21796 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21797 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
21798 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21799 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
21800 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21801 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
21802 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21803 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
21805 /* Monadic operations. */
21806 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
21807 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
21808 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
21810 /* Dyadic operations. */
21811 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21812 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21813 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21814 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21815 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21816 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21817 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21818 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21819 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21821 /* Comparisons. */
21822 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
21823 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
21824 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
21825 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
21827 /* Double precision load/store are still present on single precision
21828 implementations. */
21829 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
21830 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
21831 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21832 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21833 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21834 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21835 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21836 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
21837 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21838 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
21840 #undef ARM_VARIANT
21841 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
21843 /* Moves and type conversions. */
21844 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21845 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21846 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21847 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
21848 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
21849 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
21850 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
21851 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
21852 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
21853 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21854 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21855 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
21856 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
21858 /* Monadic operations. */
21859 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21860 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21861 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21863 /* Dyadic operations. */
21864 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21865 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21866 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21867 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21868 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21869 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21870 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21871 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21872 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21874 /* Comparisons. */
21875 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
21876 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
21877 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
21878 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
21880 #undef ARM_VARIANT
21881 #define ARM_VARIANT & fpu_vfp_ext_v2
21883 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
21884 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
21885 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
21886 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
21888 /* Instructions which may belong to either the Neon or VFP instruction sets.
21889 Individual encoder functions perform additional architecture checks. */
21890 #undef ARM_VARIANT
21891 #define ARM_VARIANT & fpu_vfp_ext_v1xd
21892 #undef THUMB_VARIANT
21893 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
21895 /* These mnemonics are unique to VFP. */
21896 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
21897 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21898 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21899 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21900 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21901 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
21902 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
21903 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
21904 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
21905 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
21907 /* Mnemonics shared by Neon and VFP. */
21908 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
21909 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
21910 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
21912 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21913 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
21915 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21916 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21917 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21918 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21919 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21920 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
21922 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
21923 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21924 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
21925 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
21928 /* NOTE: All VMOV encoding is special-cased! */
21929 NCE(vmov, 0, 1, (VMOV), neon_mov),
21930 NCE(vmovq, 0, 1, (VMOV), neon_mov),
21932 #undef THUMB_VARIANT
21933 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
21934 by different feature bits. Since we are setting the Thumb guard, we can
21935 require Thumb-1 which makes it a nop guard and set the right feature bit in
21936 do_vldr_vstr (). */
21937 #define THUMB_VARIANT & arm_ext_v4t
21938 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21939 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
21941 #undef ARM_VARIANT
21942 #define ARM_VARIANT & arm_ext_fp16
21943 #undef THUMB_VARIANT
21944 #define THUMB_VARIANT & arm_ext_fp16
21945 /* New instructions added from v8.2, allowing the extraction and insertion of
21946 the upper 16 bits of a 32-bit vector register. */
21947 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
21948 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
21950 /* New backported fma/fms instructions optional in v8.2. */
21951 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
21952 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
21954 #undef THUMB_VARIANT
21955 #define THUMB_VARIANT & fpu_neon_ext_v1
21956 #undef ARM_VARIANT
21957 #define ARM_VARIANT & fpu_neon_ext_v1
21959 /* Data processing with three registers of the same length. */
21960 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
21961 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
21962 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
21963 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21964 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21965 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21966 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21967 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
21968 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
21969 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
21970 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21971 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21972 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
21973 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
21974 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21975 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21976 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
21977 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
21978 /* If not immediate, fall back to neon_dyadic_i64_su.
21979 shl_imm should accept I8 I16 I32 I64,
21980 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21981 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21982 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21983 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21984 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
21985 /* Logic ops, types optional & ignored. */
21986 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21987 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21988 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21989 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21990 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21991 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21992 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21993 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21994 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21995 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
21996 /* Bitfield ops, untyped. */
21997 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21998 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21999 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
22000 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
22001 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
22002 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
22003 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
22004 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22005 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22006 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22007 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
22008 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
22009 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
22010 back to neon_dyadic_if_su. */
22011 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22012 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22013 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
22014 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
22015 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22016 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
22017 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
22018 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
22019 /* Comparison. Type I8 I16 I32 F32. */
22020 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
22021 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
22022 /* As above, D registers only. */
22023 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
22024 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
22025 /* Int and float variants, signedness unimportant. */
22026 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22027 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
22028 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
22029 /* Add/sub take types I8 I16 I32 I64 F32. */
22030 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
22031 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
22032 /* vtst takes sizes 8, 16, 32. */
22033 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
22034 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
22035 /* VMUL takes I8 I16 I32 F32 P8. */
22036 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
22037 /* VQD{R}MULH takes S16 S32. */
22038 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22039 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
22040 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
22041 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
22042 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22043 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
22044 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
22045 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
22046 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22047 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
22048 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
22049 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
22050 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22051 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
22052 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
22053 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
22054 /* ARM v8.1 extension. */
22055 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22056 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
22057 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
22058 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
22060 /* Two address, int/float. Types S8 S16 S32 F32. */
22061 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
22062 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
22064 /* Data processing with two registers and a shift amount. */
22065 /* Right shifts, and variants with rounding.
22066 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
22067 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22068 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22069 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
22070 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
22071 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22072 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22073 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
22074 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
22075 /* Shift and insert. Sizes accepted 8 16 32 64. */
22076 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
22077 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
22078 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
22079 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
22080 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
22081 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
22082 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
22083 /* Right shift immediate, saturating & narrowing, with rounding variants.
22084 Types accepted S16 S32 S64 U16 U32 U64. */
22085 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22086 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
22087 /* As above, unsigned. Types accepted S16 S32 S64. */
22088 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22089 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
22090 /* Right shift narrowing. Types accepted I16 I32 I64. */
22091 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22092 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
22093 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
22094 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
22095 /* CVT with optional immediate for fixed-point variant. */
22096 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
22098 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
22099 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
22101 /* Data processing, three registers of different lengths. */
22102 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
22103 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
22104 /* If not scalar, fall back to neon_dyadic_long.
22105 Vector types as above, scalar types S16 S32 U16 U32. */
22106 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
22107 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
22108 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
22109 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22110 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
22111 /* Dyadic, narrowing insns. Types I16 I32 I64. */
22112 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22113 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22114 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22115 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
22116 /* Saturating doubling multiplies. Types S16 S32. */
22117 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22118 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22119 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
22120 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
22121 S16 S32 U16 U32. */
22122 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
22124 /* Extract. Size 8. */
22125 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
22126 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
22128 /* Two registers, miscellaneous. */
22129 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
22130 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
22131 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
22132 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
22133 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
22134 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
22135 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
22136 /* Vector replicate. Sizes 8 16 32. */
22137 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
22138 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
22139 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
22140 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
22141 /* VMOVN. Types I16 I32 I64. */
22142 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
22143 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
22144 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
22145 /* VQMOVUN. Types S16 S32 S64. */
22146 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
22147 /* VZIP / VUZP. Sizes 8 16 32. */
22148 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
22149 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
22150 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
22151 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
22152 /* VQABS / VQNEG. Types S8 S16 S32. */
22153 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22154 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
22155 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
22156 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
22157 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
22158 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
22159 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
22160 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
22161 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
22162 /* Reciprocal estimates. Types U32 F16 F32. */
22163 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
22164 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
22165 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
22166 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
22167 /* VCLS. Types S8 S16 S32. */
22168 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
22169 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
22170 /* VCLZ. Types I8 I16 I32. */
22171 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
22172 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
22173 /* VCNT. Size 8. */
22174 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
22175 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
22176 /* Two address, untyped. */
22177 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
22178 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
22179 /* VTRN. Sizes 8 16 32. */
22180 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
22181 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
22183 /* Table lookup. Size 8. */
22184 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22185 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
22187 #undef THUMB_VARIANT
22188 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
22189 #undef ARM_VARIANT
22190 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
22192 /* Neon element/structure load/store. */
22193 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22194 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
22195 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22196 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
22197 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22198 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
22199 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
22200 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
22202 #undef THUMB_VARIANT
22203 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
22204 #undef ARM_VARIANT
22205 #define ARM_VARIANT & fpu_vfp_ext_v3xd
22206 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
22207 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22208 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22209 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22210 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22211 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22212 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22213 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
22214 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
22216 #undef THUMB_VARIANT
22217 #define THUMB_VARIANT & fpu_vfp_ext_v3
22218 #undef ARM_VARIANT
22219 #define ARM_VARIANT & fpu_vfp_ext_v3
22221 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
22222 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
22223 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
22224 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
22225 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
22226 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
22227 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
22228 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
22229 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
22231 #undef ARM_VARIANT
22232 #define ARM_VARIANT & fpu_vfp_ext_fma
22233 #undef THUMB_VARIANT
22234 #define THUMB_VARIANT & fpu_vfp_ext_fma
22235 /* Mnemonics shared by Neon and VFP. These are included in the
22236 VFP FMA variant; NEON and VFP FMA always includes the NEON
22237 FMA instructions. */
22238 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22239 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
22240 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
22241 the v form should always be used. */
22242 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22243 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
22244 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22245 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
22246 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22247 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
22249 #undef THUMB_VARIANT
22250 #undef ARM_VARIANT
22251 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
22253 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22254 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22255 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22256 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22257 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22258 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
22259 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
22260 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
22262 #undef ARM_VARIANT
22263 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
22265 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
22266 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
22267 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
22268 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
22269 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
22270 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
22271 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
22272 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
22273 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
22274 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22275 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22276 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
22277 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22278 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22279 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
22280 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22281 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22282 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
22283 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
22284 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
22285 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22286 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22287 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22288 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22289 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22290 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
22291 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
22292 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
22293 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
22294 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
22295 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
22296 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
22297 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
22298 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
22299 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
22300 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
22301 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
22302 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22303 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22304 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22305 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22306 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22307 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22308 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22309 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22310 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22311 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
22312 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22313 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22314 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22315 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22316 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22317 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22318 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22319 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22320 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22321 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22322 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22323 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22324 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22325 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22326 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22327 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22328 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22329 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22330 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22331 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22332 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22333 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22334 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22335 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22336 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22337 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22338 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22339 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22340 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22341 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22342 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22343 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22344 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22345 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22346 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22347 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22348 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22349 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22350 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22351 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22352 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22353 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
22354 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22355 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22356 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22357 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22358 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22359 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22360 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22361 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22362 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22363 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22364 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22365 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22366 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22367 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22368 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22369 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22370 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22371 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22372 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22373 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22374 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22375 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
22376 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22377 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22378 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22379 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22380 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22381 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22382 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22383 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22384 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22385 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22386 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22387 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22388 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22389 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22390 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22391 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22392 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
22393 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
22394 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22395 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
22396 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
22397 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
22398 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22399 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22400 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22401 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22402 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22403 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22404 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22405 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22406 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22407 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
22408 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
22409 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
22410 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
22411 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
22412 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
22413 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22414 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22415 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22416 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
22417 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
22418 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
22419 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
22420 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
22421 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
22422 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22423 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22424 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22425 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22426 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
22428 #undef ARM_VARIANT
22429 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
22431 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
22432 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
22433 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
22434 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
22435 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
22436 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
22437 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22438 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22439 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22440 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22441 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22442 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22443 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22444 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22445 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22446 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22447 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22448 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22449 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22450 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22451 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
22452 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22453 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22454 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22455 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22456 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22457 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22458 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22459 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22460 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22461 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22462 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22463 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22464 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22465 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22466 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22467 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22468 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22469 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22470 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22471 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22472 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22473 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22474 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22475 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22476 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22477 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22478 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22479 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22480 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22481 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22482 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22483 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22484 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22485 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22486 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22487 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
22489 #undef ARM_VARIANT
22490 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
22492 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22493 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22494 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22495 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22496 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
22497 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
22498 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
22499 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
22500 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
22501 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
22502 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
22503 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
22504 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
22505 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
22506 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
22507 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
22508 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
22509 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
22510 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
22511 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
22512 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
22513 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
22514 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
22515 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
22516 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
22517 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
22518 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
22519 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
22520 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
22521 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
22522 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
22523 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
22524 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
22525 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
22526 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
22527 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
22528 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
22529 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
22530 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
22531 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
22532 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
22533 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
22534 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
22535 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
22536 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
22537 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
22538 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
22539 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
22540 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
22541 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
22542 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
22543 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
22544 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
22545 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
22546 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
22547 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
22548 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
22549 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
22550 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
22551 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
22552 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
22553 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
22554 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
22555 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
22556 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22557 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22558 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22559 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22560 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22561 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
22562 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22563 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
22564 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
22565 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
22566 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
22567 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
22569 /* ARMv8.5-A instructions. */
22570 #undef ARM_VARIANT
22571 #define ARM_VARIANT & arm_ext_sb
22572 #undef THUMB_VARIANT
22573 #define THUMB_VARIANT & arm_ext_sb
22574 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
22576 #undef ARM_VARIANT
22577 #define ARM_VARIANT & arm_ext_predres
22578 #undef THUMB_VARIANT
22579 #define THUMB_VARIANT & arm_ext_predres
22580 CE("cfprctx", e070f93, 1, (RRnpc), rd),
22581 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
22582 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
22584 /* ARMv8-M instructions. */
22585 #undef ARM_VARIANT
22586 #define ARM_VARIANT NULL
22587 #undef THUMB_VARIANT
22588 #define THUMB_VARIANT & arm_ext_v8m
22589 ToU("sg", e97fe97f, 0, (), noargs),
22590 ToC("blxns", 4784, 1, (RRnpc), t_blx),
22591 ToC("bxns", 4704, 1, (RRnpc), t_bx),
22592 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
22593 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
22594 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
22595 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
22597 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
22598 instructions behave as nop if no VFP is present. */
22599 #undef THUMB_VARIANT
22600 #define THUMB_VARIANT & arm_ext_v8m_main
22601 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
22602 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
22604 /* Armv8.1-M Mainline instructions. */
22605 #undef THUMB_VARIANT
22606 #define THUMB_VARIANT & arm_ext_v8_1m_main
22607 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
22608 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
22609 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
22610 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
22611 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
22613 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
22614 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
22615 toU("le", _le, 2, (oLR, EXP), t_loloop),
22617 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
22618 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
22620 #undef THUMB_VARIANT
22621 #define THUMB_VARIANT & mve_ext
22622 ToC("vpst", fe710f4d, 0, (), mve_vpt),
22623 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
22624 ToC("vpste", fe718f4d, 0, (), mve_vpt),
22625 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
22626 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
22627 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
22628 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
22629 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
22630 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
22631 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
22632 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
22633 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
22634 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
22635 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
22636 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
22638 #undef ARM_VARIANT
22639 #define ARM_VARIANT & fpu_vfp_ext_v1xd
22640 #undef THUMB_VARIANT
22641 #define THUMB_VARIANT & arm_ext_v6t2
22643 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22644 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
22646 #undef ARM_VARIANT
22647 #define ARM_VARIANT & fpu_neon_ext_v1
22648 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
22649 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
22650 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
22651 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
22653 #undef ARM_VARIANT
22654 #undef THUMB_VARIANT
22655 #undef TCE
22656 #undef TUE
22657 #undef TUF
22658 #undef TCC
22659 #undef cCE
22660 #undef cCL
22661 #undef C3E
22662 #undef C3
22663 #undef CE
22664 #undef CM
22665 #undef CL
22666 #undef UE
22667 #undef UF
22668 #undef UT
22669 #undef NUF
22670 #undef nUF
22671 #undef NCE
22672 #undef nCE
22673 #undef OPS0
22674 #undef OPS1
22675 #undef OPS2
22676 #undef OPS3
22677 #undef OPS4
22678 #undef OPS5
22679 #undef OPS6
22680 #undef do_0
22681 #undef ToC
22682 #undef toC
22683 #undef ToU
22684 #undef toU
22686 /* MD interface: bits in the object file. */
22688 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
22689 for use in the a.out file, and stores them in the array pointed to by buf.
22690 This knows about the endian-ness of the target machine and does
22691 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
22692 2 (short) and 4 (long) Floating numbers are put out as a series of
22693 LITTLENUMS (shorts, here at least). */
22695 void
22696 md_number_to_chars (char * buf, valueT val, int n)
22698 if (target_big_endian)
22699 number_to_chars_bigendian (buf, val, n);
22700 else
22701 number_to_chars_littleendian (buf, val, n);
22704 static valueT
22705 md_chars_to_number (char * buf, int n)
22707 valueT result = 0;
22708 unsigned char * where = (unsigned char *) buf;
22710 if (target_big_endian)
22712 while (n--)
22714 result <<= 8;
22715 result |= (*where++ & 255);
22718 else
22720 while (n--)
22722 result <<= 8;
22723 result |= (where[n] & 255);
22727 return result;
22730 /* MD interface: Sections. */
22732 /* Calculate the maximum variable size (i.e., excluding fr_fix)
22733 that an rs_machine_dependent frag may reach. */
22735 unsigned int
22736 arm_frag_max_var (fragS *fragp)
22738 /* We only use rs_machine_dependent for variable-size Thumb instructions,
22739 which are either THUMB_SIZE (2) or INSN_SIZE (4).
22741 Note that we generate relaxable instructions even for cases that don't
22742 really need it, like an immediate that's a trivial constant. So we're
22743 overestimating the instruction size for some of those cases. Rather
22744 than putting more intelligence here, it would probably be better to
22745 avoid generating a relaxation frag in the first place when it can be
22746 determined up front that a short instruction will suffice. */
22748 gas_assert (fragp->fr_type == rs_machine_dependent);
22749 return INSN_SIZE;
22752 /* Estimate the size of a frag before relaxing. Assume everything fits in
22753 2 bytes. */
22756 md_estimate_size_before_relax (fragS * fragp,
22757 segT segtype ATTRIBUTE_UNUSED)
22759 fragp->fr_var = 2;
22760 return 2;
22763 /* Convert a machine dependent frag. */
22765 void
22766 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
22768 unsigned long insn;
22769 unsigned long old_op;
22770 char *buf;
22771 expressionS exp;
22772 fixS *fixp;
22773 int reloc_type;
22774 int pc_rel;
22775 int opcode;
22777 buf = fragp->fr_literal + fragp->fr_fix;
22779 old_op = bfd_get_16(abfd, buf);
22780 if (fragp->fr_symbol)
22782 exp.X_op = O_symbol;
22783 exp.X_add_symbol = fragp->fr_symbol;
22785 else
22787 exp.X_op = O_constant;
22789 exp.X_add_number = fragp->fr_offset;
22790 opcode = fragp->fr_subtype;
22791 switch (opcode)
22793 case T_MNEM_ldr_pc:
22794 case T_MNEM_ldr_pc2:
22795 case T_MNEM_ldr_sp:
22796 case T_MNEM_str_sp:
22797 case T_MNEM_ldr:
22798 case T_MNEM_ldrb:
22799 case T_MNEM_ldrh:
22800 case T_MNEM_str:
22801 case T_MNEM_strb:
22802 case T_MNEM_strh:
22803 if (fragp->fr_var == 4)
22805 insn = THUMB_OP32 (opcode);
22806 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
22808 insn |= (old_op & 0x700) << 4;
22810 else
22812 insn |= (old_op & 7) << 12;
22813 insn |= (old_op & 0x38) << 13;
22815 insn |= 0x00000c00;
22816 put_thumb32_insn (buf, insn);
22817 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
22819 else
22821 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
22823 pc_rel = (opcode == T_MNEM_ldr_pc2);
22824 break;
22825 case T_MNEM_adr:
22826 if (fragp->fr_var == 4)
22828 insn = THUMB_OP32 (opcode);
22829 insn |= (old_op & 0xf0) << 4;
22830 put_thumb32_insn (buf, insn);
22831 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
22833 else
22835 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22836 exp.X_add_number -= 4;
22838 pc_rel = 1;
22839 break;
22840 case T_MNEM_mov:
22841 case T_MNEM_movs:
22842 case T_MNEM_cmp:
22843 case T_MNEM_cmn:
22844 if (fragp->fr_var == 4)
22846 int r0off = (opcode == T_MNEM_mov
22847 || opcode == T_MNEM_movs) ? 0 : 8;
22848 insn = THUMB_OP32 (opcode);
22849 insn = (insn & 0xe1ffffff) | 0x10000000;
22850 insn |= (old_op & 0x700) << r0off;
22851 put_thumb32_insn (buf, insn);
22852 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
22854 else
22856 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
22858 pc_rel = 0;
22859 break;
22860 case T_MNEM_b:
22861 if (fragp->fr_var == 4)
22863 insn = THUMB_OP32(opcode);
22864 put_thumb32_insn (buf, insn);
22865 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
22867 else
22868 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
22869 pc_rel = 1;
22870 break;
22871 case T_MNEM_bcond:
22872 if (fragp->fr_var == 4)
22874 insn = THUMB_OP32(opcode);
22875 insn |= (old_op & 0xf00) << 14;
22876 put_thumb32_insn (buf, insn);
22877 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
22879 else
22880 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
22881 pc_rel = 1;
22882 break;
22883 case T_MNEM_add_sp:
22884 case T_MNEM_add_pc:
22885 case T_MNEM_inc_sp:
22886 case T_MNEM_dec_sp:
22887 if (fragp->fr_var == 4)
22889 /* ??? Choose between add and addw. */
22890 insn = THUMB_OP32 (opcode);
22891 insn |= (old_op & 0xf0) << 4;
22892 put_thumb32_insn (buf, insn);
22893 if (opcode == T_MNEM_add_pc)
22894 reloc_type = BFD_RELOC_ARM_T32_IMM12;
22895 else
22896 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
22898 else
22899 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22900 pc_rel = 0;
22901 break;
22903 case T_MNEM_addi:
22904 case T_MNEM_addis:
22905 case T_MNEM_subi:
22906 case T_MNEM_subis:
22907 if (fragp->fr_var == 4)
22909 insn = THUMB_OP32 (opcode);
22910 insn |= (old_op & 0xf0) << 4;
22911 insn |= (old_op & 0xf) << 16;
22912 put_thumb32_insn (buf, insn);
22913 if (insn & (1 << 20))
22914 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
22915 else
22916 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
22918 else
22919 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
22920 pc_rel = 0;
22921 break;
22922 default:
22923 abort ();
22925 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
22926 (enum bfd_reloc_code_real) reloc_type);
22927 fixp->fx_file = fragp->fr_file;
22928 fixp->fx_line = fragp->fr_line;
22929 fragp->fr_fix += fragp->fr_var;
22931 /* Set whether we use thumb-2 ISA based on final relaxation results. */
22932 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
22933 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
22934 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
22937 /* Return the size of a relaxable immediate operand instruction.
22938 SHIFT and SIZE specify the form of the allowable immediate. */
22939 static int
22940 relax_immediate (fragS *fragp, int size, int shift)
22942 offsetT offset;
22943 offsetT mask;
22944 offsetT low;
22946 /* ??? Should be able to do better than this. */
22947 if (fragp->fr_symbol)
22948 return 4;
22950 low = (1 << shift) - 1;
22951 mask = (1 << (shift + size)) - (1 << shift);
22952 offset = fragp->fr_offset;
22953 /* Force misaligned offsets to 32-bit variant. */
22954 if (offset & low)
22955 return 4;
22956 if (offset & ~mask)
22957 return 4;
22958 return 2;
22961 /* Get the address of a symbol during relaxation. */
22962 static addressT
22963 relaxed_symbol_addr (fragS *fragp, long stretch)
22965 fragS *sym_frag;
22966 addressT addr;
22967 symbolS *sym;
22969 sym = fragp->fr_symbol;
22970 sym_frag = symbol_get_frag (sym);
22971 know (S_GET_SEGMENT (sym) != absolute_section
22972 || sym_frag == &zero_address_frag);
22973 addr = S_GET_VALUE (sym) + fragp->fr_offset;
22975 /* If frag has yet to be reached on this pass, assume it will
22976 move by STRETCH just as we did. If this is not so, it will
22977 be because some frag between grows, and that will force
22978 another pass. */
22980 if (stretch != 0
22981 && sym_frag->relax_marker != fragp->relax_marker)
22983 fragS *f;
22985 /* Adjust stretch for any alignment frag. Note that if have
22986 been expanding the earlier code, the symbol may be
22987 defined in what appears to be an earlier frag. FIXME:
22988 This doesn't handle the fr_subtype field, which specifies
22989 a maximum number of bytes to skip when doing an
22990 alignment. */
22991 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
22993 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
22995 if (stretch < 0)
22996 stretch = - ((- stretch)
22997 & ~ ((1 << (int) f->fr_offset) - 1));
22998 else
22999 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
23000 if (stretch == 0)
23001 break;
23004 if (f != NULL)
23005 addr += stretch;
23008 return addr;
23011 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
23012 load. */
23013 static int
23014 relax_adr (fragS *fragp, asection *sec, long stretch)
23016 addressT addr;
23017 offsetT val;
23019 /* Assume worst case for symbols not known to be in the same section. */
23020 if (fragp->fr_symbol == NULL
23021 || !S_IS_DEFINED (fragp->fr_symbol)
23022 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23023 || S_IS_WEAK (fragp->fr_symbol))
23024 return 4;
23026 val = relaxed_symbol_addr (fragp, stretch);
23027 addr = fragp->fr_address + fragp->fr_fix;
23028 addr = (addr + 4) & ~3;
23029 /* Force misaligned targets to 32-bit variant. */
23030 if (val & 3)
23031 return 4;
23032 val -= addr;
23033 if (val < 0 || val > 1020)
23034 return 4;
23035 return 2;
23038 /* Return the size of a relaxable add/sub immediate instruction. */
23039 static int
23040 relax_addsub (fragS *fragp, asection *sec)
23042 char *buf;
23043 int op;
23045 buf = fragp->fr_literal + fragp->fr_fix;
23046 op = bfd_get_16(sec->owner, buf);
23047 if ((op & 0xf) == ((op >> 4) & 0xf))
23048 return relax_immediate (fragp, 8, 0);
23049 else
23050 return relax_immediate (fragp, 3, 0);
23053 /* Return TRUE iff the definition of symbol S could be pre-empted
23054 (overridden) at link or load time. */
23055 static bfd_boolean
23056 symbol_preemptible (symbolS *s)
23058 /* Weak symbols can always be pre-empted. */
23059 if (S_IS_WEAK (s))
23060 return TRUE;
23062 /* Non-global symbols cannot be pre-empted. */
23063 if (! S_IS_EXTERNAL (s))
23064 return FALSE;
23066 #ifdef OBJ_ELF
23067 /* In ELF, a global symbol can be marked protected, or private. In that
23068 case it can't be pre-empted (other definitions in the same link unit
23069 would violate the ODR). */
23070 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
23071 return FALSE;
23072 #endif
23074 /* Other global symbols might be pre-empted. */
23075 return TRUE;
23078 /* Return the size of a relaxable branch instruction. BITS is the
23079 size of the offset field in the narrow instruction. */
23081 static int
23082 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
23084 addressT addr;
23085 offsetT val;
23086 offsetT limit;
23088 /* Assume worst case for symbols not known to be in the same section. */
23089 if (!S_IS_DEFINED (fragp->fr_symbol)
23090 || sec != S_GET_SEGMENT (fragp->fr_symbol)
23091 || S_IS_WEAK (fragp->fr_symbol))
23092 return 4;
23094 #ifdef OBJ_ELF
23095 /* A branch to a function in ARM state will require interworking. */
23096 if (S_IS_DEFINED (fragp->fr_symbol)
23097 && ARM_IS_FUNC (fragp->fr_symbol))
23098 return 4;
23099 #endif
23101 if (symbol_preemptible (fragp->fr_symbol))
23102 return 4;
23104 val = relaxed_symbol_addr (fragp, stretch);
23105 addr = fragp->fr_address + fragp->fr_fix + 4;
23106 val -= addr;
23108 /* Offset is a signed value *2 */
23109 limit = 1 << bits;
23110 if (val >= limit || val < -limit)
23111 return 4;
23112 return 2;
23116 /* Relax a machine dependent frag. This returns the amount by which
23117 the current size of the frag should change. */
23120 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
23122 int oldsize;
23123 int newsize;
23125 oldsize = fragp->fr_var;
23126 switch (fragp->fr_subtype)
23128 case T_MNEM_ldr_pc2:
23129 newsize = relax_adr (fragp, sec, stretch);
23130 break;
23131 case T_MNEM_ldr_pc:
23132 case T_MNEM_ldr_sp:
23133 case T_MNEM_str_sp:
23134 newsize = relax_immediate (fragp, 8, 2);
23135 break;
23136 case T_MNEM_ldr:
23137 case T_MNEM_str:
23138 newsize = relax_immediate (fragp, 5, 2);
23139 break;
23140 case T_MNEM_ldrh:
23141 case T_MNEM_strh:
23142 newsize = relax_immediate (fragp, 5, 1);
23143 break;
23144 case T_MNEM_ldrb:
23145 case T_MNEM_strb:
23146 newsize = relax_immediate (fragp, 5, 0);
23147 break;
23148 case T_MNEM_adr:
23149 newsize = relax_adr (fragp, sec, stretch);
23150 break;
23151 case T_MNEM_mov:
23152 case T_MNEM_movs:
23153 case T_MNEM_cmp:
23154 case T_MNEM_cmn:
23155 newsize = relax_immediate (fragp, 8, 0);
23156 break;
23157 case T_MNEM_b:
23158 newsize = relax_branch (fragp, sec, 11, stretch);
23159 break;
23160 case T_MNEM_bcond:
23161 newsize = relax_branch (fragp, sec, 8, stretch);
23162 break;
23163 case T_MNEM_add_sp:
23164 case T_MNEM_add_pc:
23165 newsize = relax_immediate (fragp, 8, 2);
23166 break;
23167 case T_MNEM_inc_sp:
23168 case T_MNEM_dec_sp:
23169 newsize = relax_immediate (fragp, 7, 2);
23170 break;
23171 case T_MNEM_addi:
23172 case T_MNEM_addis:
23173 case T_MNEM_subi:
23174 case T_MNEM_subis:
23175 newsize = relax_addsub (fragp, sec);
23176 break;
23177 default:
23178 abort ();
23181 fragp->fr_var = newsize;
23182 /* Freeze wide instructions that are at or before the same location as
23183 in the previous pass. This avoids infinite loops.
23184 Don't freeze them unconditionally because targets may be artificially
23185 misaligned by the expansion of preceding frags. */
23186 if (stretch <= 0 && newsize > 2)
23188 md_convert_frag (sec->owner, sec, fragp);
23189 frag_wane (fragp);
23192 return newsize - oldsize;
23195 /* Round up a section size to the appropriate boundary. */
23197 valueT
23198 md_section_align (segT segment ATTRIBUTE_UNUSED,
23199 valueT size)
23201 return size;
23204 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
23205 of an rs_align_code fragment. */
23207 void
23208 arm_handle_align (fragS * fragP)
23210 static unsigned char const arm_noop[2][2][4] =
23212 { /* ARMv1 */
23213 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
23214 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
23216 { /* ARMv6k */
23217 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
23218 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
23221 static unsigned char const thumb_noop[2][2][2] =
23223 { /* Thumb-1 */
23224 {0xc0, 0x46}, /* LE */
23225 {0x46, 0xc0}, /* BE */
23227 { /* Thumb-2 */
23228 {0x00, 0xbf}, /* LE */
23229 {0xbf, 0x00} /* BE */
23232 static unsigned char const wide_thumb_noop[2][4] =
23233 { /* Wide Thumb-2 */
23234 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
23235 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
23238 unsigned bytes, fix, noop_size;
23239 char * p;
23240 const unsigned char * noop;
23241 const unsigned char *narrow_noop = NULL;
23242 #ifdef OBJ_ELF
23243 enum mstate state;
23244 #endif
23246 if (fragP->fr_type != rs_align_code)
23247 return;
23249 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
23250 p = fragP->fr_literal + fragP->fr_fix;
23251 fix = 0;
23253 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
23254 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
23256 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
23258 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
23260 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23261 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
23263 narrow_noop = thumb_noop[1][target_big_endian];
23264 noop = wide_thumb_noop[target_big_endian];
23266 else
23267 noop = thumb_noop[0][target_big_endian];
23268 noop_size = 2;
23269 #ifdef OBJ_ELF
23270 state = MAP_THUMB;
23271 #endif
23273 else
23275 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
23276 ? selected_cpu : arm_arch_none,
23277 arm_ext_v6k) != 0]
23278 [target_big_endian];
23279 noop_size = 4;
23280 #ifdef OBJ_ELF
23281 state = MAP_ARM;
23282 #endif
23285 fragP->fr_var = noop_size;
23287 if (bytes & (noop_size - 1))
23289 fix = bytes & (noop_size - 1);
23290 #ifdef OBJ_ELF
23291 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
23292 #endif
23293 memset (p, 0, fix);
23294 p += fix;
23295 bytes -= fix;
23298 if (narrow_noop)
23300 if (bytes & noop_size)
23302 /* Insert a narrow noop. */
23303 memcpy (p, narrow_noop, noop_size);
23304 p += noop_size;
23305 bytes -= noop_size;
23306 fix += noop_size;
23309 /* Use wide noops for the remainder */
23310 noop_size = 4;
23313 while (bytes >= noop_size)
23315 memcpy (p, noop, noop_size);
23316 p += noop_size;
23317 bytes -= noop_size;
23318 fix += noop_size;
23321 fragP->fr_fix += fix;
23324 /* Called from md_do_align. Used to create an alignment
23325 frag in a code section. */
23327 void
23328 arm_frag_align_code (int n, int max)
23330 char * p;
23332 /* We assume that there will never be a requirement
23333 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
23334 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
23336 char err_msg[128];
23338 sprintf (err_msg,
23339 _("alignments greater than %d bytes not supported in .text sections."),
23340 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
23341 as_fatal ("%s", err_msg);
23344 p = frag_var (rs_align_code,
23345 MAX_MEM_FOR_RS_ALIGN_CODE,
23347 (relax_substateT) max,
23348 (symbolS *) NULL,
23349 (offsetT) n,
23350 (char *) NULL);
23351 *p = 0;
23354 /* Perform target specific initialisation of a frag.
23355 Note - despite the name this initialisation is not done when the frag
23356 is created, but only when its type is assigned. A frag can be created
23357 and used a long time before its type is set, so beware of assuming that
23358 this initialisation is performed first. */
23360 #ifndef OBJ_ELF
23361 void
23362 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
23364 /* Record whether this frag is in an ARM or a THUMB area. */
23365 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
23368 #else /* OBJ_ELF is defined. */
23369 void
23370 arm_init_frag (fragS * fragP, int max_chars)
23372 bfd_boolean frag_thumb_mode;
23374 /* If the current ARM vs THUMB mode has not already
23375 been recorded into this frag then do so now. */
23376 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
23377 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
23379 /* PR 21809: Do not set a mapping state for debug sections
23380 - it just confuses other tools. */
23381 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
23382 return;
23384 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
23386 /* Record a mapping symbol for alignment frags. We will delete this
23387 later if the alignment ends up empty. */
23388 switch (fragP->fr_type)
23390 case rs_align:
23391 case rs_align_test:
23392 case rs_fill:
23393 mapping_state_2 (MAP_DATA, max_chars);
23394 break;
23395 case rs_align_code:
23396 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
23397 break;
23398 default:
23399 break;
23403 /* When we change sections we need to issue a new mapping symbol. */
23405 void
23406 arm_elf_change_section (void)
23408 /* Link an unlinked unwind index table section to the .text section. */
23409 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
23410 && elf_linked_to_section (now_seg) == NULL)
23411 elf_linked_to_section (now_seg) = text_section;
23415 arm_elf_section_type (const char * str, size_t len)
23417 if (len == 5 && strncmp (str, "exidx", 5) == 0)
23418 return SHT_ARM_EXIDX;
23420 return -1;
23423 /* Code to deal with unwinding tables. */
23425 static void add_unwind_adjustsp (offsetT);
23427 /* Generate any deferred unwind frame offset. */
23429 static void
23430 flush_pending_unwind (void)
23432 offsetT offset;
23434 offset = unwind.pending_offset;
23435 unwind.pending_offset = 0;
23436 if (offset != 0)
23437 add_unwind_adjustsp (offset);
23440 /* Add an opcode to this list for this function. Two-byte opcodes should
23441 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
23442 order. */
23444 static void
23445 add_unwind_opcode (valueT op, int length)
23447 /* Add any deferred stack adjustment. */
23448 if (unwind.pending_offset)
23449 flush_pending_unwind ();
23451 unwind.sp_restored = 0;
23453 if (unwind.opcode_count + length > unwind.opcode_alloc)
23455 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
23456 if (unwind.opcodes)
23457 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
23458 unwind.opcode_alloc);
23459 else
23460 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
23462 while (length > 0)
23464 length--;
23465 unwind.opcodes[unwind.opcode_count] = op & 0xff;
23466 op >>= 8;
23467 unwind.opcode_count++;
23471 /* Add unwind opcodes to adjust the stack pointer. */
23473 static void
23474 add_unwind_adjustsp (offsetT offset)
23476 valueT op;
23478 if (offset > 0x200)
23480 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
23481 char bytes[5];
23482 int n;
23483 valueT o;
23485 /* Long form: 0xb2, uleb128. */
23486 /* This might not fit in a word so add the individual bytes,
23487 remembering the list is built in reverse order. */
23488 o = (valueT) ((offset - 0x204) >> 2);
23489 if (o == 0)
23490 add_unwind_opcode (0, 1);
23492 /* Calculate the uleb128 encoding of the offset. */
23493 n = 0;
23494 while (o)
23496 bytes[n] = o & 0x7f;
23497 o >>= 7;
23498 if (o)
23499 bytes[n] |= 0x80;
23500 n++;
23502 /* Add the insn. */
23503 for (; n; n--)
23504 add_unwind_opcode (bytes[n - 1], 1);
23505 add_unwind_opcode (0xb2, 1);
23507 else if (offset > 0x100)
23509 /* Two short opcodes. */
23510 add_unwind_opcode (0x3f, 1);
23511 op = (offset - 0x104) >> 2;
23512 add_unwind_opcode (op, 1);
23514 else if (offset > 0)
23516 /* Short opcode. */
23517 op = (offset - 4) >> 2;
23518 add_unwind_opcode (op, 1);
23520 else if (offset < 0)
23522 offset = -offset;
23523 while (offset > 0x100)
23525 add_unwind_opcode (0x7f, 1);
23526 offset -= 0x100;
23528 op = ((offset - 4) >> 2) | 0x40;
23529 add_unwind_opcode (op, 1);
23533 /* Finish the list of unwind opcodes for this function. */
23535 static void
23536 finish_unwind_opcodes (void)
23538 valueT op;
23540 if (unwind.fp_used)
23542 /* Adjust sp as necessary. */
23543 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
23544 flush_pending_unwind ();
23546 /* After restoring sp from the frame pointer. */
23547 op = 0x90 | unwind.fp_reg;
23548 add_unwind_opcode (op, 1);
23550 else
23551 flush_pending_unwind ();
23555 /* Start an exception table entry. If idx is nonzero this is an index table
23556 entry. */
23558 static void
23559 start_unwind_section (const segT text_seg, int idx)
23561 const char * text_name;
23562 const char * prefix;
23563 const char * prefix_once;
23564 const char * group_name;
23565 char * sec_name;
23566 int type;
23567 int flags;
23568 int linkonce;
23570 if (idx)
23572 prefix = ELF_STRING_ARM_unwind;
23573 prefix_once = ELF_STRING_ARM_unwind_once;
23574 type = SHT_ARM_EXIDX;
23576 else
23578 prefix = ELF_STRING_ARM_unwind_info;
23579 prefix_once = ELF_STRING_ARM_unwind_info_once;
23580 type = SHT_PROGBITS;
23583 text_name = segment_name (text_seg);
23584 if (streq (text_name, ".text"))
23585 text_name = "";
23587 if (strncmp (text_name, ".gnu.linkonce.t.",
23588 strlen (".gnu.linkonce.t.")) == 0)
23590 prefix = prefix_once;
23591 text_name += strlen (".gnu.linkonce.t.");
23594 sec_name = concat (prefix, text_name, (char *) NULL);
23596 flags = SHF_ALLOC;
23597 linkonce = 0;
23598 group_name = 0;
23600 /* Handle COMDAT group. */
23601 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
23603 group_name = elf_group_name (text_seg);
23604 if (group_name == NULL)
23606 as_bad (_("Group section `%s' has no group signature"),
23607 segment_name (text_seg));
23608 ignore_rest_of_line ();
23609 return;
23611 flags |= SHF_GROUP;
23612 linkonce = 1;
23615 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
23616 linkonce, 0);
23618 /* Set the section link for index tables. */
23619 if (idx)
23620 elf_linked_to_section (now_seg) = text_seg;
23624 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
23625 personality routine data. Returns zero, or the index table value for
23626 an inline entry. */
23628 static valueT
23629 create_unwind_entry (int have_data)
23631 int size;
23632 addressT where;
23633 char *ptr;
23634 /* The current word of data. */
23635 valueT data;
23636 /* The number of bytes left in this word. */
23637 int n;
23639 finish_unwind_opcodes ();
23641 /* Remember the current text section. */
23642 unwind.saved_seg = now_seg;
23643 unwind.saved_subseg = now_subseg;
23645 start_unwind_section (now_seg, 0);
23647 if (unwind.personality_routine == NULL)
23649 if (unwind.personality_index == -2)
23651 if (have_data)
23652 as_bad (_("handlerdata in cantunwind frame"));
23653 return 1; /* EXIDX_CANTUNWIND. */
23656 /* Use a default personality routine if none is specified. */
23657 if (unwind.personality_index == -1)
23659 if (unwind.opcode_count > 3)
23660 unwind.personality_index = 1;
23661 else
23662 unwind.personality_index = 0;
23665 /* Space for the personality routine entry. */
23666 if (unwind.personality_index == 0)
23668 if (unwind.opcode_count > 3)
23669 as_bad (_("too many unwind opcodes for personality routine 0"));
23671 if (!have_data)
23673 /* All the data is inline in the index table. */
23674 data = 0x80;
23675 n = 3;
23676 while (unwind.opcode_count > 0)
23678 unwind.opcode_count--;
23679 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23680 n--;
23683 /* Pad with "finish" opcodes. */
23684 while (n--)
23685 data = (data << 8) | 0xb0;
23687 return data;
23689 size = 0;
23691 else
23692 /* We get two opcodes "free" in the first word. */
23693 size = unwind.opcode_count - 2;
23695 else
23697 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
23698 if (unwind.personality_index != -1)
23700 as_bad (_("attempt to recreate an unwind entry"));
23701 return 1;
23704 /* An extra byte is required for the opcode count. */
23705 size = unwind.opcode_count + 1;
23708 size = (size + 3) >> 2;
23709 if (size > 0xff)
23710 as_bad (_("too many unwind opcodes"));
23712 frag_align (2, 0, 0);
23713 record_alignment (now_seg, 2);
23714 unwind.table_entry = expr_build_dot ();
23716 /* Allocate the table entry. */
23717 ptr = frag_more ((size << 2) + 4);
23718 /* PR 13449: Zero the table entries in case some of them are not used. */
23719 memset (ptr, 0, (size << 2) + 4);
23720 where = frag_now_fix () - ((size << 2) + 4);
23722 switch (unwind.personality_index)
23724 case -1:
23725 /* ??? Should this be a PLT generating relocation? */
23726 /* Custom personality routine. */
23727 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
23728 BFD_RELOC_ARM_PREL31);
23730 where += 4;
23731 ptr += 4;
23733 /* Set the first byte to the number of additional words. */
23734 data = size > 0 ? size - 1 : 0;
23735 n = 3;
23736 break;
23738 /* ABI defined personality routines. */
23739 case 0:
23740 /* Three opcodes bytes are packed into the first word. */
23741 data = 0x80;
23742 n = 3;
23743 break;
23745 case 1:
23746 case 2:
23747 /* The size and first two opcode bytes go in the first word. */
23748 data = ((0x80 + unwind.personality_index) << 8) | size;
23749 n = 2;
23750 break;
23752 default:
23753 /* Should never happen. */
23754 abort ();
23757 /* Pack the opcodes into words (MSB first), reversing the list at the same
23758 time. */
23759 while (unwind.opcode_count > 0)
23761 if (n == 0)
23763 md_number_to_chars (ptr, data, 4);
23764 ptr += 4;
23765 n = 4;
23766 data = 0;
23768 unwind.opcode_count--;
23769 n--;
23770 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
23773 /* Finish off the last word. */
23774 if (n < 4)
23776 /* Pad with "finish" opcodes. */
23777 while (n--)
23778 data = (data << 8) | 0xb0;
23780 md_number_to_chars (ptr, data, 4);
23783 if (!have_data)
23785 /* Add an empty descriptor if there is no user-specified data. */
23786 ptr = frag_more (4);
23787 md_number_to_chars (ptr, 0, 4);
23790 return 0;
23794 /* Initialize the DWARF-2 unwind information for this procedure. */
23796 void
23797 tc_arm_frame_initial_instructions (void)
23799 cfi_add_CFA_def_cfa (REG_SP, 0);
23801 #endif /* OBJ_ELF */
23803 /* Convert REGNAME to a DWARF-2 register number. */
23806 tc_arm_regname_to_dw2regnum (char *regname)
23808 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
23809 if (reg != FAIL)
23810 return reg;
23812 /* PR 16694: Allow VFP registers as well. */
23813 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
23814 if (reg != FAIL)
23815 return 64 + reg;
23817 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
23818 if (reg != FAIL)
23819 return reg + 256;
23821 return FAIL;
23824 #ifdef TE_PE
23825 void
23826 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
23828 expressionS exp;
23830 exp.X_op = O_secrel;
23831 exp.X_add_symbol = symbol;
23832 exp.X_add_number = 0;
23833 emit_expr (&exp, size);
23835 #endif
23837 /* MD interface: Symbol and relocation handling. */
23839 /* Return the address within the segment that a PC-relative fixup is
23840 relative to. For ARM, PC-relative fixups applied to instructions
23841 are generally relative to the location of the fixup plus 8 bytes.
23842 Thumb branches are offset by 4, and Thumb loads relative to PC
23843 require special handling. */
23845 long
23846 md_pcrel_from_section (fixS * fixP, segT seg)
23848 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
23850 /* If this is pc-relative and we are going to emit a relocation
23851 then we just want to put out any pipeline compensation that the linker
23852 will need. Otherwise we want to use the calculated base.
23853 For WinCE we skip the bias for externals as well, since this
23854 is how the MS ARM-CE assembler behaves and we want to be compatible. */
23855 if (fixP->fx_pcrel
23856 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
23857 || (arm_force_relocation (fixP)
23858 #ifdef TE_WINCE
23859 && !S_IS_EXTERNAL (fixP->fx_addsy)
23860 #endif
23862 base = 0;
23865 switch (fixP->fx_r_type)
23867 /* PC relative addressing on the Thumb is slightly odd as the
23868 bottom two bits of the PC are forced to zero for the
23869 calculation. This happens *after* application of the
23870 pipeline offset. However, Thumb adrl already adjusts for
23871 this, so we need not do it again. */
23872 case BFD_RELOC_ARM_THUMB_ADD:
23873 return base & ~3;
23875 case BFD_RELOC_ARM_THUMB_OFFSET:
23876 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23877 case BFD_RELOC_ARM_T32_ADD_PC12:
23878 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
23879 return (base + 4) & ~3;
23881 /* Thumb branches are simply offset by +4. */
23882 case BFD_RELOC_THUMB_PCREL_BRANCH5:
23883 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23884 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23885 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23886 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23887 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23888 case BFD_RELOC_THUMB_PCREL_BFCSEL:
23889 case BFD_RELOC_ARM_THUMB_BF17:
23890 case BFD_RELOC_ARM_THUMB_BF19:
23891 case BFD_RELOC_ARM_THUMB_BF13:
23892 case BFD_RELOC_ARM_THUMB_LOOP12:
23893 return base + 4;
23895 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23896 if (fixP->fx_addsy
23897 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23898 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23899 && ARM_IS_FUNC (fixP->fx_addsy)
23900 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23901 base = fixP->fx_where + fixP->fx_frag->fr_address;
23902 return base + 4;
23904 /* BLX is like branches above, but forces the low two bits of PC to
23905 zero. */
23906 case BFD_RELOC_THUMB_PCREL_BLX:
23907 if (fixP->fx_addsy
23908 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23909 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23910 && THUMB_IS_FUNC (fixP->fx_addsy)
23911 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23912 base = fixP->fx_where + fixP->fx_frag->fr_address;
23913 return (base + 4) & ~3;
23915 /* ARM mode branches are offset by +8. However, the Windows CE
23916 loader expects the relocation not to take this into account. */
23917 case BFD_RELOC_ARM_PCREL_BLX:
23918 if (fixP->fx_addsy
23919 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23920 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23921 && ARM_IS_FUNC (fixP->fx_addsy)
23922 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23923 base = fixP->fx_where + fixP->fx_frag->fr_address;
23924 return base + 8;
23926 case BFD_RELOC_ARM_PCREL_CALL:
23927 if (fixP->fx_addsy
23928 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23929 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23930 && THUMB_IS_FUNC (fixP->fx_addsy)
23931 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23932 base = fixP->fx_where + fixP->fx_frag->fr_address;
23933 return base + 8;
23935 case BFD_RELOC_ARM_PCREL_BRANCH:
23936 case BFD_RELOC_ARM_PCREL_JUMP:
23937 case BFD_RELOC_ARM_PLT32:
23938 #ifdef TE_WINCE
23939 /* When handling fixups immediately, because we have already
23940 discovered the value of a symbol, or the address of the frag involved
23941 we must account for the offset by +8, as the OS loader will never see the reloc.
23942 see fixup_segment() in write.c
23943 The S_IS_EXTERNAL test handles the case of global symbols.
23944 Those need the calculated base, not just the pipe compensation the linker will need. */
23945 if (fixP->fx_pcrel
23946 && fixP->fx_addsy != NULL
23947 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23948 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
23949 return base + 8;
23950 return base;
23951 #else
23952 return base + 8;
23953 #endif
23956 /* ARM mode loads relative to PC are also offset by +8. Unlike
23957 branches, the Windows CE loader *does* expect the relocation
23958 to take this into account. */
23959 case BFD_RELOC_ARM_OFFSET_IMM:
23960 case BFD_RELOC_ARM_OFFSET_IMM8:
23961 case BFD_RELOC_ARM_HWLITERAL:
23962 case BFD_RELOC_ARM_LITERAL:
23963 case BFD_RELOC_ARM_CP_OFF_IMM:
23964 return base + 8;
23967 /* Other PC-relative relocations are un-offset. */
23968 default:
23969 return base;
23973 static bfd_boolean flag_warn_syms = TRUE;
23975 bfd_boolean
23976 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
23978 /* PR 18347 - Warn if the user attempts to create a symbol with the same
23979 name as an ARM instruction. Whilst strictly speaking it is allowed, it
23980 does mean that the resulting code might be very confusing to the reader.
23981 Also this warning can be triggered if the user omits an operand before
23982 an immediate address, eg:
23984 LDR =foo
23986 GAS treats this as an assignment of the value of the symbol foo to a
23987 symbol LDR, and so (without this code) it will not issue any kind of
23988 warning or error message.
23990 Note - ARM instructions are case-insensitive but the strings in the hash
23991 table are all stored in lower case, so we must first ensure that name is
23992 lower case too. */
23993 if (flag_warn_syms && arm_ops_hsh)
23995 char * nbuf = strdup (name);
23996 char * p;
23998 for (p = nbuf; *p; p++)
23999 *p = TOLOWER (*p);
24000 if (hash_find (arm_ops_hsh, nbuf) != NULL)
24002 static struct hash_control * already_warned = NULL;
24004 if (already_warned == NULL)
24005 already_warned = hash_new ();
24006 /* Only warn about the symbol once. To keep the code
24007 simple we let hash_insert do the lookup for us. */
24008 if (hash_insert (already_warned, nbuf, NULL) == NULL)
24009 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
24011 else
24012 free (nbuf);
24015 return FALSE;
24018 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
24019 Otherwise we have no need to default values of symbols. */
24021 symbolS *
24022 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
24024 #ifdef OBJ_ELF
24025 if (name[0] == '_' && name[1] == 'G'
24026 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
24028 if (!GOT_symbol)
24030 if (symbol_find (name))
24031 as_bad (_("GOT already in the symbol table"));
24033 GOT_symbol = symbol_new (name, undefined_section,
24034 (valueT) 0, & zero_address_frag);
24037 return GOT_symbol;
24039 #endif
24041 return NULL;
24044 /* Subroutine of md_apply_fix. Check to see if an immediate can be
24045 computed as two separate immediate values, added together. We
24046 already know that this value cannot be computed by just one ARM
24047 instruction. */
24049 static unsigned int
24050 validate_immediate_twopart (unsigned int val,
24051 unsigned int * highpart)
24053 unsigned int a;
24054 unsigned int i;
24056 for (i = 0; i < 32; i += 2)
24057 if (((a = rotate_left (val, i)) & 0xff) != 0)
24059 if (a & 0xff00)
24061 if (a & ~ 0xffff)
24062 continue;
24063 * highpart = (a >> 8) | ((i + 24) << 7);
24065 else if (a & 0xff0000)
24067 if (a & 0xff000000)
24068 continue;
24069 * highpart = (a >> 16) | ((i + 16) << 7);
24071 else
24073 gas_assert (a & 0xff000000);
24074 * highpart = (a >> 24) | ((i + 8) << 7);
24077 return (a & 0xff) | (i << 7);
24080 return FAIL;
24083 static int
24084 validate_offset_imm (unsigned int val, int hwse)
24086 if ((hwse && val > 255) || val > 4095)
24087 return FAIL;
24088 return val;
24091 /* Subroutine of md_apply_fix. Do those data_ops which can take a
24092 negative immediate constant by altering the instruction. A bit of
24093 a hack really.
24094 MOV <-> MVN
24095 AND <-> BIC
24096 ADC <-> SBC
24097 by inverting the second operand, and
24098 ADD <-> SUB
24099 CMP <-> CMN
24100 by negating the second operand. */
24102 static int
24103 negate_data_op (unsigned long * instruction,
24104 unsigned long value)
24106 int op, new_inst;
24107 unsigned long negated, inverted;
24109 negated = encode_arm_immediate (-value);
24110 inverted = encode_arm_immediate (~value);
24112 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
24113 switch (op)
24115 /* First negates. */
24116 case OPCODE_SUB: /* ADD <-> SUB */
24117 new_inst = OPCODE_ADD;
24118 value = negated;
24119 break;
24121 case OPCODE_ADD:
24122 new_inst = OPCODE_SUB;
24123 value = negated;
24124 break;
24126 case OPCODE_CMP: /* CMP <-> CMN */
24127 new_inst = OPCODE_CMN;
24128 value = negated;
24129 break;
24131 case OPCODE_CMN:
24132 new_inst = OPCODE_CMP;
24133 value = negated;
24134 break;
24136 /* Now Inverted ops. */
24137 case OPCODE_MOV: /* MOV <-> MVN */
24138 new_inst = OPCODE_MVN;
24139 value = inverted;
24140 break;
24142 case OPCODE_MVN:
24143 new_inst = OPCODE_MOV;
24144 value = inverted;
24145 break;
24147 case OPCODE_AND: /* AND <-> BIC */
24148 new_inst = OPCODE_BIC;
24149 value = inverted;
24150 break;
24152 case OPCODE_BIC:
24153 new_inst = OPCODE_AND;
24154 value = inverted;
24155 break;
24157 case OPCODE_ADC: /* ADC <-> SBC */
24158 new_inst = OPCODE_SBC;
24159 value = inverted;
24160 break;
24162 case OPCODE_SBC:
24163 new_inst = OPCODE_ADC;
24164 value = inverted;
24165 break;
24167 /* We cannot do anything. */
24168 default:
24169 return FAIL;
24172 if (value == (unsigned) FAIL)
24173 return FAIL;
24175 *instruction &= OPCODE_MASK;
24176 *instruction |= new_inst << DATA_OP_SHIFT;
24177 return value;
24180 /* Like negate_data_op, but for Thumb-2. */
24182 static unsigned int
24183 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
24185 int op, new_inst;
24186 int rd;
24187 unsigned int negated, inverted;
24189 negated = encode_thumb32_immediate (-value);
24190 inverted = encode_thumb32_immediate (~value);
24192 rd = (*instruction >> 8) & 0xf;
24193 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
24194 switch (op)
24196 /* ADD <-> SUB. Includes CMP <-> CMN. */
24197 case T2_OPCODE_SUB:
24198 new_inst = T2_OPCODE_ADD;
24199 value = negated;
24200 break;
24202 case T2_OPCODE_ADD:
24203 new_inst = T2_OPCODE_SUB;
24204 value = negated;
24205 break;
24207 /* ORR <-> ORN. Includes MOV <-> MVN. */
24208 case T2_OPCODE_ORR:
24209 new_inst = T2_OPCODE_ORN;
24210 value = inverted;
24211 break;
24213 case T2_OPCODE_ORN:
24214 new_inst = T2_OPCODE_ORR;
24215 value = inverted;
24216 break;
24218 /* AND <-> BIC. TST has no inverted equivalent. */
24219 case T2_OPCODE_AND:
24220 new_inst = T2_OPCODE_BIC;
24221 if (rd == 15)
24222 value = FAIL;
24223 else
24224 value = inverted;
24225 break;
24227 case T2_OPCODE_BIC:
24228 new_inst = T2_OPCODE_AND;
24229 value = inverted;
24230 break;
24232 /* ADC <-> SBC */
24233 case T2_OPCODE_ADC:
24234 new_inst = T2_OPCODE_SBC;
24235 value = inverted;
24236 break;
24238 case T2_OPCODE_SBC:
24239 new_inst = T2_OPCODE_ADC;
24240 value = inverted;
24241 break;
24243 /* We cannot do anything. */
24244 default:
24245 return FAIL;
24248 if (value == (unsigned int)FAIL)
24249 return FAIL;
24251 *instruction &= T2_OPCODE_MASK;
24252 *instruction |= new_inst << T2_DATA_OP_SHIFT;
24253 return value;
24256 /* Read a 32-bit thumb instruction from buf. */
24258 static unsigned long
24259 get_thumb32_insn (char * buf)
24261 unsigned long insn;
24262 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
24263 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24265 return insn;
24268 /* We usually want to set the low bit on the address of thumb function
24269 symbols. In particular .word foo - . should have the low bit set.
24270 Generic code tries to fold the difference of two symbols to
24271 a constant. Prevent this and force a relocation when the first symbols
24272 is a thumb function. */
24274 bfd_boolean
24275 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
24277 if (op == O_subtract
24278 && l->X_op == O_symbol
24279 && r->X_op == O_symbol
24280 && THUMB_IS_FUNC (l->X_add_symbol))
24282 l->X_op = O_subtract;
24283 l->X_op_symbol = r->X_add_symbol;
24284 l->X_add_number -= r->X_add_number;
24285 return TRUE;
24288 /* Process as normal. */
24289 return FALSE;
24292 /* Encode Thumb2 unconditional branches and calls. The encoding
24293 for the 2 are identical for the immediate values. */
24295 static void
24296 encode_thumb2_b_bl_offset (char * buf, offsetT value)
24298 #define T2I1I2MASK ((1 << 13) | (1 << 11))
24299 offsetT newval;
24300 offsetT newval2;
24301 addressT S, I1, I2, lo, hi;
24303 S = (value >> 24) & 0x01;
24304 I1 = (value >> 23) & 0x01;
24305 I2 = (value >> 22) & 0x01;
24306 hi = (value >> 12) & 0x3ff;
24307 lo = (value >> 1) & 0x7ff;
24308 newval = md_chars_to_number (buf, THUMB_SIZE);
24309 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24310 newval |= (S << 10) | hi;
24311 newval2 &= ~T2I1I2MASK;
24312 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
24313 md_number_to_chars (buf, newval, THUMB_SIZE);
24314 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24317 void
24318 md_apply_fix (fixS * fixP,
24319 valueT * valP,
24320 segT seg)
24322 offsetT value = * valP;
24323 offsetT newval;
24324 unsigned int newimm;
24325 unsigned long temp;
24326 int sign;
24327 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
24329 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
24331 /* Note whether this will delete the relocation. */
24333 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
24334 fixP->fx_done = 1;
24336 /* On a 64-bit host, silently truncate 'value' to 32 bits for
24337 consistency with the behaviour on 32-bit hosts. Remember value
24338 for emit_reloc. */
24339 value &= 0xffffffff;
24340 value ^= 0x80000000;
24341 value -= 0x80000000;
24343 *valP = value;
24344 fixP->fx_addnumber = value;
24346 /* Same treatment for fixP->fx_offset. */
24347 fixP->fx_offset &= 0xffffffff;
24348 fixP->fx_offset ^= 0x80000000;
24349 fixP->fx_offset -= 0x80000000;
24351 switch (fixP->fx_r_type)
24353 case BFD_RELOC_NONE:
24354 /* This will need to go in the object file. */
24355 fixP->fx_done = 0;
24356 break;
24358 case BFD_RELOC_ARM_IMMEDIATE:
24359 /* We claim that this fixup has been processed here,
24360 even if in fact we generate an error because we do
24361 not have a reloc for it, so tc_gen_reloc will reject it. */
24362 fixP->fx_done = 1;
24364 if (fixP->fx_addsy)
24366 const char *msg = 0;
24368 if (! S_IS_DEFINED (fixP->fx_addsy))
24369 msg = _("undefined symbol %s used as an immediate value");
24370 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24371 msg = _("symbol %s is in a different section");
24372 else if (S_IS_WEAK (fixP->fx_addsy))
24373 msg = _("symbol %s is weak and may be overridden later");
24375 if (msg)
24377 as_bad_where (fixP->fx_file, fixP->fx_line,
24378 msg, S_GET_NAME (fixP->fx_addsy));
24379 break;
24383 temp = md_chars_to_number (buf, INSN_SIZE);
24385 /* If the offset is negative, we should use encoding A2 for ADR. */
24386 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
24387 newimm = negate_data_op (&temp, value);
24388 else
24390 newimm = encode_arm_immediate (value);
24392 /* If the instruction will fail, see if we can fix things up by
24393 changing the opcode. */
24394 if (newimm == (unsigned int) FAIL)
24395 newimm = negate_data_op (&temp, value);
24396 /* MOV accepts both ARM modified immediate (A1 encoding) and
24397 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
24398 When disassembling, MOV is preferred when there is no encoding
24399 overlap. */
24400 if (newimm == (unsigned int) FAIL
24401 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
24402 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
24403 && !((temp >> SBIT_SHIFT) & 0x1)
24404 && value >= 0 && value <= 0xffff)
24406 /* Clear bits[23:20] to change encoding from A1 to A2. */
24407 temp &= 0xff0fffff;
24408 /* Encoding high 4bits imm. Code below will encode the remaining
24409 low 12bits. */
24410 temp |= (value & 0x0000f000) << 4;
24411 newimm = value & 0x00000fff;
24415 if (newimm == (unsigned int) FAIL)
24417 as_bad_where (fixP->fx_file, fixP->fx_line,
24418 _("invalid constant (%lx) after fixup"),
24419 (unsigned long) value);
24420 break;
24423 newimm |= (temp & 0xfffff000);
24424 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
24425 break;
24427 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24429 unsigned int highpart = 0;
24430 unsigned int newinsn = 0xe1a00000; /* nop. */
24432 if (fixP->fx_addsy)
24434 const char *msg = 0;
24436 if (! S_IS_DEFINED (fixP->fx_addsy))
24437 msg = _("undefined symbol %s used as an immediate value");
24438 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
24439 msg = _("symbol %s is in a different section");
24440 else if (S_IS_WEAK (fixP->fx_addsy))
24441 msg = _("symbol %s is weak and may be overridden later");
24443 if (msg)
24445 as_bad_where (fixP->fx_file, fixP->fx_line,
24446 msg, S_GET_NAME (fixP->fx_addsy));
24447 break;
24451 newimm = encode_arm_immediate (value);
24452 temp = md_chars_to_number (buf, INSN_SIZE);
24454 /* If the instruction will fail, see if we can fix things up by
24455 changing the opcode. */
24456 if (newimm == (unsigned int) FAIL
24457 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
24459 /* No ? OK - try using two ADD instructions to generate
24460 the value. */
24461 newimm = validate_immediate_twopart (value, & highpart);
24463 /* Yes - then make sure that the second instruction is
24464 also an add. */
24465 if (newimm != (unsigned int) FAIL)
24466 newinsn = temp;
24467 /* Still No ? Try using a negated value. */
24468 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
24469 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
24470 /* Otherwise - give up. */
24471 else
24473 as_bad_where (fixP->fx_file, fixP->fx_line,
24474 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
24475 (long) value);
24476 break;
24479 /* Replace the first operand in the 2nd instruction (which
24480 is the PC) with the destination register. We have
24481 already added in the PC in the first instruction and we
24482 do not want to do it again. */
24483 newinsn &= ~ 0xf0000;
24484 newinsn |= ((newinsn & 0x0f000) << 4);
24487 newimm |= (temp & 0xfffff000);
24488 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
24490 highpart |= (newinsn & 0xfffff000);
24491 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
24493 break;
24495 case BFD_RELOC_ARM_OFFSET_IMM:
24496 if (!fixP->fx_done && seg->use_rela_p)
24497 value = 0;
24498 /* Fall through. */
24500 case BFD_RELOC_ARM_LITERAL:
24501 sign = value > 0;
24503 if (value < 0)
24504 value = - value;
24506 if (validate_offset_imm (value, 0) == FAIL)
24508 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
24509 as_bad_where (fixP->fx_file, fixP->fx_line,
24510 _("invalid literal constant: pool needs to be closer"));
24511 else
24512 as_bad_where (fixP->fx_file, fixP->fx_line,
24513 _("bad immediate value for offset (%ld)"),
24514 (long) value);
24515 break;
24518 newval = md_chars_to_number (buf, INSN_SIZE);
24519 if (value == 0)
24520 newval &= 0xfffff000;
24521 else
24523 newval &= 0xff7ff000;
24524 newval |= value | (sign ? INDEX_UP : 0);
24526 md_number_to_chars (buf, newval, INSN_SIZE);
24527 break;
24529 case BFD_RELOC_ARM_OFFSET_IMM8:
24530 case BFD_RELOC_ARM_HWLITERAL:
24531 sign = value > 0;
24533 if (value < 0)
24534 value = - value;
24536 if (validate_offset_imm (value, 1) == FAIL)
24538 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
24539 as_bad_where (fixP->fx_file, fixP->fx_line,
24540 _("invalid literal constant: pool needs to be closer"));
24541 else
24542 as_bad_where (fixP->fx_file, fixP->fx_line,
24543 _("bad immediate value for 8-bit offset (%ld)"),
24544 (long) value);
24545 break;
24548 newval = md_chars_to_number (buf, INSN_SIZE);
24549 if (value == 0)
24550 newval &= 0xfffff0f0;
24551 else
24553 newval &= 0xff7ff0f0;
24554 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
24556 md_number_to_chars (buf, newval, INSN_SIZE);
24557 break;
24559 case BFD_RELOC_ARM_T32_OFFSET_U8:
24560 if (value < 0 || value > 1020 || value % 4 != 0)
24561 as_bad_where (fixP->fx_file, fixP->fx_line,
24562 _("bad immediate value for offset (%ld)"), (long) value);
24563 value /= 4;
24565 newval = md_chars_to_number (buf+2, THUMB_SIZE);
24566 newval |= value;
24567 md_number_to_chars (buf+2, newval, THUMB_SIZE);
24568 break;
24570 case BFD_RELOC_ARM_T32_OFFSET_IMM:
24571 /* This is a complicated relocation used for all varieties of Thumb32
24572 load/store instruction with immediate offset:
24574 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
24575 *4, optional writeback(W)
24576 (doubleword load/store)
24578 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
24579 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
24580 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
24581 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
24582 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
24584 Uppercase letters indicate bits that are already encoded at
24585 this point. Lowercase letters are our problem. For the
24586 second block of instructions, the secondary opcode nybble
24587 (bits 8..11) is present, and bit 23 is zero, even if this is
24588 a PC-relative operation. */
24589 newval = md_chars_to_number (buf, THUMB_SIZE);
24590 newval <<= 16;
24591 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
24593 if ((newval & 0xf0000000) == 0xe0000000)
24595 /* Doubleword load/store: 8-bit offset, scaled by 4. */
24596 if (value >= 0)
24597 newval |= (1 << 23);
24598 else
24599 value = -value;
24600 if (value % 4 != 0)
24602 as_bad_where (fixP->fx_file, fixP->fx_line,
24603 _("offset not a multiple of 4"));
24604 break;
24606 value /= 4;
24607 if (value > 0xff)
24609 as_bad_where (fixP->fx_file, fixP->fx_line,
24610 _("offset out of range"));
24611 break;
24613 newval &= ~0xff;
24615 else if ((newval & 0x000f0000) == 0x000f0000)
24617 /* PC-relative, 12-bit offset. */
24618 if (value >= 0)
24619 newval |= (1 << 23);
24620 else
24621 value = -value;
24622 if (value > 0xfff)
24624 as_bad_where (fixP->fx_file, fixP->fx_line,
24625 _("offset out of range"));
24626 break;
24628 newval &= ~0xfff;
24630 else if ((newval & 0x00000100) == 0x00000100)
24632 /* Writeback: 8-bit, +/- offset. */
24633 if (value >= 0)
24634 newval |= (1 << 9);
24635 else
24636 value = -value;
24637 if (value > 0xff)
24639 as_bad_where (fixP->fx_file, fixP->fx_line,
24640 _("offset out of range"));
24641 break;
24643 newval &= ~0xff;
24645 else if ((newval & 0x00000f00) == 0x00000e00)
24647 /* T-instruction: positive 8-bit offset. */
24648 if (value < 0 || value > 0xff)
24650 as_bad_where (fixP->fx_file, fixP->fx_line,
24651 _("offset out of range"));
24652 break;
24654 newval &= ~0xff;
24655 newval |= value;
24657 else
24659 /* Positive 12-bit or negative 8-bit offset. */
24660 int limit;
24661 if (value >= 0)
24663 newval |= (1 << 23);
24664 limit = 0xfff;
24666 else
24668 value = -value;
24669 limit = 0xff;
24671 if (value > limit)
24673 as_bad_where (fixP->fx_file, fixP->fx_line,
24674 _("offset out of range"));
24675 break;
24677 newval &= ~limit;
24680 newval |= value;
24681 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
24682 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
24683 break;
24685 case BFD_RELOC_ARM_SHIFT_IMM:
24686 newval = md_chars_to_number (buf, INSN_SIZE);
24687 if (((unsigned long) value) > 32
24688 || (value == 32
24689 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
24691 as_bad_where (fixP->fx_file, fixP->fx_line,
24692 _("shift expression is too large"));
24693 break;
24696 if (value == 0)
24697 /* Shifts of zero must be done as lsl. */
24698 newval &= ~0x60;
24699 else if (value == 32)
24700 value = 0;
24701 newval &= 0xfffff07f;
24702 newval |= (value & 0x1f) << 7;
24703 md_number_to_chars (buf, newval, INSN_SIZE);
24704 break;
24706 case BFD_RELOC_ARM_T32_IMMEDIATE:
24707 case BFD_RELOC_ARM_T32_ADD_IMM:
24708 case BFD_RELOC_ARM_T32_IMM12:
24709 case BFD_RELOC_ARM_T32_ADD_PC12:
24710 /* We claim that this fixup has been processed here,
24711 even if in fact we generate an error because we do
24712 not have a reloc for it, so tc_gen_reloc will reject it. */
24713 fixP->fx_done = 1;
24715 if (fixP->fx_addsy
24716 && ! S_IS_DEFINED (fixP->fx_addsy))
24718 as_bad_where (fixP->fx_file, fixP->fx_line,
24719 _("undefined symbol %s used as an immediate value"),
24720 S_GET_NAME (fixP->fx_addsy));
24721 break;
24724 newval = md_chars_to_number (buf, THUMB_SIZE);
24725 newval <<= 16;
24726 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
24728 newimm = FAIL;
24729 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24730 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
24731 Thumb2 modified immediate encoding (T2). */
24732 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
24733 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
24735 newimm = encode_thumb32_immediate (value);
24736 if (newimm == (unsigned int) FAIL)
24737 newimm = thumb32_negate_data_op (&newval, value);
24739 if (newimm == (unsigned int) FAIL)
24741 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
24743 /* Turn add/sum into addw/subw. */
24744 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
24745 newval = (newval & 0xfeffffff) | 0x02000000;
24746 /* No flat 12-bit imm encoding for addsw/subsw. */
24747 if ((newval & 0x00100000) == 0)
24749 /* 12 bit immediate for addw/subw. */
24750 if (value < 0)
24752 value = -value;
24753 newval ^= 0x00a00000;
24755 if (value > 0xfff)
24756 newimm = (unsigned int) FAIL;
24757 else
24758 newimm = value;
24761 else
24763 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
24764 UINT16 (T3 encoding), MOVW only accepts UINT16. When
24765 disassembling, MOV is preferred when there is no encoding
24766 overlap. */
24767 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
24768 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
24769 but with the Rn field [19:16] set to 1111. */
24770 && (((newval >> 16) & 0xf) == 0xf)
24771 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
24772 && !((newval >> T2_SBIT_SHIFT) & 0x1)
24773 && value >= 0 && value <= 0xffff)
24775 /* Toggle bit[25] to change encoding from T2 to T3. */
24776 newval ^= 1 << 25;
24777 /* Clear bits[19:16]. */
24778 newval &= 0xfff0ffff;
24779 /* Encoding high 4bits imm. Code below will encode the
24780 remaining low 12bits. */
24781 newval |= (value & 0x0000f000) << 4;
24782 newimm = value & 0x00000fff;
24787 if (newimm == (unsigned int)FAIL)
24789 as_bad_where (fixP->fx_file, fixP->fx_line,
24790 _("invalid constant (%lx) after fixup"),
24791 (unsigned long) value);
24792 break;
24795 newval |= (newimm & 0x800) << 15;
24796 newval |= (newimm & 0x700) << 4;
24797 newval |= (newimm & 0x0ff);
24799 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
24800 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
24801 break;
24803 case BFD_RELOC_ARM_SMC:
24804 if (((unsigned long) value) > 0xffff)
24805 as_bad_where (fixP->fx_file, fixP->fx_line,
24806 _("invalid smc expression"));
24807 newval = md_chars_to_number (buf, INSN_SIZE);
24808 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24809 md_number_to_chars (buf, newval, INSN_SIZE);
24810 break;
24812 case BFD_RELOC_ARM_HVC:
24813 if (((unsigned long) value) > 0xffff)
24814 as_bad_where (fixP->fx_file, fixP->fx_line,
24815 _("invalid hvc expression"));
24816 newval = md_chars_to_number (buf, INSN_SIZE);
24817 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
24818 md_number_to_chars (buf, newval, INSN_SIZE);
24819 break;
24821 case BFD_RELOC_ARM_SWI:
24822 if (fixP->tc_fix_data != 0)
24824 if (((unsigned long) value) > 0xff)
24825 as_bad_where (fixP->fx_file, fixP->fx_line,
24826 _("invalid swi expression"));
24827 newval = md_chars_to_number (buf, THUMB_SIZE);
24828 newval |= value;
24829 md_number_to_chars (buf, newval, THUMB_SIZE);
24831 else
24833 if (((unsigned long) value) > 0x00ffffff)
24834 as_bad_where (fixP->fx_file, fixP->fx_line,
24835 _("invalid swi expression"));
24836 newval = md_chars_to_number (buf, INSN_SIZE);
24837 newval |= value;
24838 md_number_to_chars (buf, newval, INSN_SIZE);
24840 break;
24842 case BFD_RELOC_ARM_MULTI:
24843 if (((unsigned long) value) > 0xffff)
24844 as_bad_where (fixP->fx_file, fixP->fx_line,
24845 _("invalid expression in load/store multiple"));
24846 newval = value | md_chars_to_number (buf, INSN_SIZE);
24847 md_number_to_chars (buf, newval, INSN_SIZE);
24848 break;
24850 #ifdef OBJ_ELF
24851 case BFD_RELOC_ARM_PCREL_CALL:
24853 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24854 && fixP->fx_addsy
24855 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24857 && THUMB_IS_FUNC (fixP->fx_addsy))
24858 /* Flip the bl to blx. This is a simple flip
24859 bit here because we generate PCREL_CALL for
24860 unconditional bls. */
24862 newval = md_chars_to_number (buf, INSN_SIZE);
24863 newval = newval | 0x10000000;
24864 md_number_to_chars (buf, newval, INSN_SIZE);
24865 temp = 1;
24866 fixP->fx_done = 1;
24868 else
24869 temp = 3;
24870 goto arm_branch_common;
24872 case BFD_RELOC_ARM_PCREL_JUMP:
24873 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24874 && fixP->fx_addsy
24875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24877 && THUMB_IS_FUNC (fixP->fx_addsy))
24879 /* This would map to a bl<cond>, b<cond>,
24880 b<always> to a Thumb function. We
24881 need to force a relocation for this particular
24882 case. */
24883 newval = md_chars_to_number (buf, INSN_SIZE);
24884 fixP->fx_done = 0;
24886 /* Fall through. */
24888 case BFD_RELOC_ARM_PLT32:
24889 #endif
24890 case BFD_RELOC_ARM_PCREL_BRANCH:
24891 temp = 3;
24892 goto arm_branch_common;
24894 case BFD_RELOC_ARM_PCREL_BLX:
24896 temp = 1;
24897 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24898 && fixP->fx_addsy
24899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24901 && ARM_IS_FUNC (fixP->fx_addsy))
24903 /* Flip the blx to a bl and warn. */
24904 const char *name = S_GET_NAME (fixP->fx_addsy);
24905 newval = 0xeb000000;
24906 as_warn_where (fixP->fx_file, fixP->fx_line,
24907 _("blx to '%s' an ARM ISA state function changed to bl"),
24908 name);
24909 md_number_to_chars (buf, newval, INSN_SIZE);
24910 temp = 3;
24911 fixP->fx_done = 1;
24914 #ifdef OBJ_ELF
24915 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24916 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
24917 #endif
24919 arm_branch_common:
24920 /* We are going to store value (shifted right by two) in the
24921 instruction, in a 24 bit, signed field. Bits 26 through 32 either
24922 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
24923 also be clear. */
24924 if (value & temp)
24925 as_bad_where (fixP->fx_file, fixP->fx_line,
24926 _("misaligned branch destination"));
24927 if ((value & (offsetT)0xfe000000) != (offsetT)0
24928 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
24929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24931 if (fixP->fx_done || !seg->use_rela_p)
24933 newval = md_chars_to_number (buf, INSN_SIZE);
24934 newval |= (value >> 2) & 0x00ffffff;
24935 /* Set the H bit on BLX instructions. */
24936 if (temp == 1)
24938 if (value & 2)
24939 newval |= 0x01000000;
24940 else
24941 newval &= ~0x01000000;
24943 md_number_to_chars (buf, newval, INSN_SIZE);
24945 break;
24947 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
24948 /* CBZ can only branch forward. */
24950 /* Attempts to use CBZ to branch to the next instruction
24951 (which, strictly speaking, are prohibited) will be turned into
24952 no-ops.
24954 FIXME: It may be better to remove the instruction completely and
24955 perform relaxation. */
24956 if (value == -2)
24958 newval = md_chars_to_number (buf, THUMB_SIZE);
24959 newval = 0xbf00; /* NOP encoding T1 */
24960 md_number_to_chars (buf, newval, THUMB_SIZE);
24962 else
24964 if (value & ~0x7e)
24965 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24967 if (fixP->fx_done || !seg->use_rela_p)
24969 newval = md_chars_to_number (buf, THUMB_SIZE);
24970 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
24971 md_number_to_chars (buf, newval, THUMB_SIZE);
24974 break;
24976 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
24977 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
24978 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24980 if (fixP->fx_done || !seg->use_rela_p)
24982 newval = md_chars_to_number (buf, THUMB_SIZE);
24983 newval |= (value & 0x1ff) >> 1;
24984 md_number_to_chars (buf, newval, THUMB_SIZE);
24986 break;
24988 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
24989 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
24990 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24992 if (fixP->fx_done || !seg->use_rela_p)
24994 newval = md_chars_to_number (buf, THUMB_SIZE);
24995 newval |= (value & 0xfff) >> 1;
24996 md_number_to_chars (buf, newval, THUMB_SIZE);
24998 break;
25000 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25001 if (fixP->fx_addsy
25002 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25003 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25004 && ARM_IS_FUNC (fixP->fx_addsy)
25005 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25007 /* Force a relocation for a branch 20 bits wide. */
25008 fixP->fx_done = 0;
25010 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
25011 as_bad_where (fixP->fx_file, fixP->fx_line,
25012 _("conditional branch out of range"));
25014 if (fixP->fx_done || !seg->use_rela_p)
25016 offsetT newval2;
25017 addressT S, J1, J2, lo, hi;
25019 S = (value & 0x00100000) >> 20;
25020 J2 = (value & 0x00080000) >> 19;
25021 J1 = (value & 0x00040000) >> 18;
25022 hi = (value & 0x0003f000) >> 12;
25023 lo = (value & 0x00000ffe) >> 1;
25025 newval = md_chars_to_number (buf, THUMB_SIZE);
25026 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25027 newval |= (S << 10) | hi;
25028 newval2 |= (J1 << 13) | (J2 << 11) | lo;
25029 md_number_to_chars (buf, newval, THUMB_SIZE);
25030 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25032 break;
25034 case BFD_RELOC_THUMB_PCREL_BLX:
25035 /* If there is a blx from a thumb state function to
25036 another thumb function flip this to a bl and warn
25037 about it. */
25039 if (fixP->fx_addsy
25040 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25041 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25042 && THUMB_IS_FUNC (fixP->fx_addsy))
25044 const char *name = S_GET_NAME (fixP->fx_addsy);
25045 as_warn_where (fixP->fx_file, fixP->fx_line,
25046 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
25047 name);
25048 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25049 newval = newval | 0x1000;
25050 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25051 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25052 fixP->fx_done = 1;
25056 goto thumb_bl_common;
25058 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25059 /* A bl from Thumb state ISA to an internal ARM state function
25060 is converted to a blx. */
25061 if (fixP->fx_addsy
25062 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25063 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25064 && ARM_IS_FUNC (fixP->fx_addsy)
25065 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
25067 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25068 newval = newval & ~0x1000;
25069 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
25070 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
25071 fixP->fx_done = 1;
25074 thumb_bl_common:
25076 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25077 /* For a BLX instruction, make sure that the relocation is rounded up
25078 to a word boundary. This follows the semantics of the instruction
25079 which specifies that bit 1 of the target address will come from bit
25080 1 of the base address. */
25081 value = (value + 3) & ~ 3;
25083 #ifdef OBJ_ELF
25084 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
25085 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
25086 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
25087 #endif
25089 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
25091 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
25092 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
25093 else if ((value & ~0x1ffffff)
25094 && ((value & ~0x1ffffff) != ~0x1ffffff))
25095 as_bad_where (fixP->fx_file, fixP->fx_line,
25096 _("Thumb2 branch out of range"));
25099 if (fixP->fx_done || !seg->use_rela_p)
25100 encode_thumb2_b_bl_offset (buf, value);
25102 break;
25104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25105 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
25106 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
25108 if (fixP->fx_done || !seg->use_rela_p)
25109 encode_thumb2_b_bl_offset (buf, value);
25111 break;
25113 case BFD_RELOC_8:
25114 if (fixP->fx_done || !seg->use_rela_p)
25115 *buf = value;
25116 break;
25118 case BFD_RELOC_16:
25119 if (fixP->fx_done || !seg->use_rela_p)
25120 md_number_to_chars (buf, value, 2);
25121 break;
25123 #ifdef OBJ_ELF
25124 case BFD_RELOC_ARM_TLS_CALL:
25125 case BFD_RELOC_ARM_THM_TLS_CALL:
25126 case BFD_RELOC_ARM_TLS_DESCSEQ:
25127 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
25128 case BFD_RELOC_ARM_TLS_GOTDESC:
25129 case BFD_RELOC_ARM_TLS_GD32:
25130 case BFD_RELOC_ARM_TLS_LE32:
25131 case BFD_RELOC_ARM_TLS_IE32:
25132 case BFD_RELOC_ARM_TLS_LDM32:
25133 case BFD_RELOC_ARM_TLS_LDO32:
25134 S_SET_THREAD_LOCAL (fixP->fx_addsy);
25135 break;
25137 /* Same handling as above, but with the arm_fdpic guard. */
25138 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
25139 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
25140 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
25141 if (arm_fdpic)
25143 S_SET_THREAD_LOCAL (fixP->fx_addsy);
25145 else
25147 as_bad_where (fixP->fx_file, fixP->fx_line,
25148 _("Relocation supported only in FDPIC mode"));
25150 break;
25152 case BFD_RELOC_ARM_GOT32:
25153 case BFD_RELOC_ARM_GOTOFF:
25154 break;
25156 case BFD_RELOC_ARM_GOT_PREL:
25157 if (fixP->fx_done || !seg->use_rela_p)
25158 md_number_to_chars (buf, value, 4);
25159 break;
25161 case BFD_RELOC_ARM_TARGET2:
25162 /* TARGET2 is not partial-inplace, so we need to write the
25163 addend here for REL targets, because it won't be written out
25164 during reloc processing later. */
25165 if (fixP->fx_done || !seg->use_rela_p)
25166 md_number_to_chars (buf, fixP->fx_offset, 4);
25167 break;
25169 /* Relocations for FDPIC. */
25170 case BFD_RELOC_ARM_GOTFUNCDESC:
25171 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
25172 case BFD_RELOC_ARM_FUNCDESC:
25173 if (arm_fdpic)
25175 if (fixP->fx_done || !seg->use_rela_p)
25176 md_number_to_chars (buf, 0, 4);
25178 else
25180 as_bad_where (fixP->fx_file, fixP->fx_line,
25181 _("Relocation supported only in FDPIC mode"));
25183 break;
25184 #endif
25186 case BFD_RELOC_RVA:
25187 case BFD_RELOC_32:
25188 case BFD_RELOC_ARM_TARGET1:
25189 case BFD_RELOC_ARM_ROSEGREL32:
25190 case BFD_RELOC_ARM_SBREL32:
25191 case BFD_RELOC_32_PCREL:
25192 #ifdef TE_PE
25193 case BFD_RELOC_32_SECREL:
25194 #endif
25195 if (fixP->fx_done || !seg->use_rela_p)
25196 #ifdef TE_WINCE
25197 /* For WinCE we only do this for pcrel fixups. */
25198 if (fixP->fx_done || fixP->fx_pcrel)
25199 #endif
25200 md_number_to_chars (buf, value, 4);
25201 break;
25203 #ifdef OBJ_ELF
25204 case BFD_RELOC_ARM_PREL31:
25205 if (fixP->fx_done || !seg->use_rela_p)
25207 newval = md_chars_to_number (buf, 4) & 0x80000000;
25208 if ((value ^ (value >> 1)) & 0x40000000)
25210 as_bad_where (fixP->fx_file, fixP->fx_line,
25211 _("rel31 relocation overflow"));
25213 newval |= value & 0x7fffffff;
25214 md_number_to_chars (buf, newval, 4);
25216 break;
25217 #endif
25219 case BFD_RELOC_ARM_CP_OFF_IMM:
25220 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
25221 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
25222 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
25223 newval = md_chars_to_number (buf, INSN_SIZE);
25224 else
25225 newval = get_thumb32_insn (buf);
25226 if ((newval & 0x0f200f00) == 0x0d000900)
25228 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
25229 has permitted values that are multiples of 2, in the range 0
25230 to 510. */
25231 if (value < -510 || value > 510 || (value & 1))
25232 as_bad_where (fixP->fx_file, fixP->fx_line,
25233 _("co-processor offset out of range"));
25235 else if ((newval & 0xfe001f80) == 0xec000f80)
25237 if (value < -511 || value > 512 || (value & 3))
25238 as_bad_where (fixP->fx_file, fixP->fx_line,
25239 _("co-processor offset out of range"));
25241 else if (value < -1023 || value > 1023 || (value & 3))
25242 as_bad_where (fixP->fx_file, fixP->fx_line,
25243 _("co-processor offset out of range"));
25244 cp_off_common:
25245 sign = value > 0;
25246 if (value < 0)
25247 value = -value;
25248 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25249 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25250 newval = md_chars_to_number (buf, INSN_SIZE);
25251 else
25252 newval = get_thumb32_insn (buf);
25253 if (value == 0)
25255 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25256 newval &= 0xffffff80;
25257 else
25258 newval &= 0xffffff00;
25260 else
25262 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
25263 newval &= 0xff7fff80;
25264 else
25265 newval &= 0xff7fff00;
25266 if ((newval & 0x0f200f00) == 0x0d000900)
25268 /* This is a fp16 vstr/vldr.
25270 It requires the immediate offset in the instruction is shifted
25271 left by 1 to be a half-word offset.
25273 Here, left shift by 1 first, and later right shift by 2
25274 should get the right offset. */
25275 value <<= 1;
25277 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
25279 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25280 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
25281 md_number_to_chars (buf, newval, INSN_SIZE);
25282 else
25283 put_thumb32_insn (buf, newval);
25284 break;
25286 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
25287 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
25288 if (value < -255 || value > 255)
25289 as_bad_where (fixP->fx_file, fixP->fx_line,
25290 _("co-processor offset out of range"));
25291 value *= 4;
25292 goto cp_off_common;
25294 case BFD_RELOC_ARM_THUMB_OFFSET:
25295 newval = md_chars_to_number (buf, THUMB_SIZE);
25296 /* Exactly what ranges, and where the offset is inserted depends
25297 on the type of instruction, we can establish this from the
25298 top 4 bits. */
25299 switch (newval >> 12)
25301 case 4: /* PC load. */
25302 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
25303 forced to zero for these loads; md_pcrel_from has already
25304 compensated for this. */
25305 if (value & 3)
25306 as_bad_where (fixP->fx_file, fixP->fx_line,
25307 _("invalid offset, target not word aligned (0x%08lX)"),
25308 (((unsigned long) fixP->fx_frag->fr_address
25309 + (unsigned long) fixP->fx_where) & ~3)
25310 + (unsigned long) value);
25312 if (value & ~0x3fc)
25313 as_bad_where (fixP->fx_file, fixP->fx_line,
25314 _("invalid offset, value too big (0x%08lX)"),
25315 (long) value);
25317 newval |= value >> 2;
25318 break;
25320 case 9: /* SP load/store. */
25321 if (value & ~0x3fc)
25322 as_bad_where (fixP->fx_file, fixP->fx_line,
25323 _("invalid offset, value too big (0x%08lX)"),
25324 (long) value);
25325 newval |= value >> 2;
25326 break;
25328 case 6: /* Word load/store. */
25329 if (value & ~0x7c)
25330 as_bad_where (fixP->fx_file, fixP->fx_line,
25331 _("invalid offset, value too big (0x%08lX)"),
25332 (long) value);
25333 newval |= value << 4; /* 6 - 2. */
25334 break;
25336 case 7: /* Byte load/store. */
25337 if (value & ~0x1f)
25338 as_bad_where (fixP->fx_file, fixP->fx_line,
25339 _("invalid offset, value too big (0x%08lX)"),
25340 (long) value);
25341 newval |= value << 6;
25342 break;
25344 case 8: /* Halfword load/store. */
25345 if (value & ~0x3e)
25346 as_bad_where (fixP->fx_file, fixP->fx_line,
25347 _("invalid offset, value too big (0x%08lX)"),
25348 (long) value);
25349 newval |= value << 5; /* 6 - 1. */
25350 break;
25352 default:
25353 as_bad_where (fixP->fx_file, fixP->fx_line,
25354 "Unable to process relocation for thumb opcode: %lx",
25355 (unsigned long) newval);
25356 break;
25358 md_number_to_chars (buf, newval, THUMB_SIZE);
25359 break;
25361 case BFD_RELOC_ARM_THUMB_ADD:
25362 /* This is a complicated relocation, since we use it for all of
25363 the following immediate relocations:
25365 3bit ADD/SUB
25366 8bit ADD/SUB
25367 9bit ADD/SUB SP word-aligned
25368 10bit ADD PC/SP word-aligned
25370 The type of instruction being processed is encoded in the
25371 instruction field:
25373 0x8000 SUB
25374 0x00F0 Rd
25375 0x000F Rs
25377 newval = md_chars_to_number (buf, THUMB_SIZE);
25379 int rd = (newval >> 4) & 0xf;
25380 int rs = newval & 0xf;
25381 int subtract = !!(newval & 0x8000);
25383 /* Check for HI regs, only very restricted cases allowed:
25384 Adjusting SP, and using PC or SP to get an address. */
25385 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
25386 || (rs > 7 && rs != REG_SP && rs != REG_PC))
25387 as_bad_where (fixP->fx_file, fixP->fx_line,
25388 _("invalid Hi register with immediate"));
25390 /* If value is negative, choose the opposite instruction. */
25391 if (value < 0)
25393 value = -value;
25394 subtract = !subtract;
25395 if (value < 0)
25396 as_bad_where (fixP->fx_file, fixP->fx_line,
25397 _("immediate value out of range"));
25400 if (rd == REG_SP)
25402 if (value & ~0x1fc)
25403 as_bad_where (fixP->fx_file, fixP->fx_line,
25404 _("invalid immediate for stack address calculation"));
25405 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
25406 newval |= value >> 2;
25408 else if (rs == REG_PC || rs == REG_SP)
25410 /* PR gas/18541. If the addition is for a defined symbol
25411 within range of an ADR instruction then accept it. */
25412 if (subtract
25413 && value == 4
25414 && fixP->fx_addsy != NULL)
25416 subtract = 0;
25418 if (! S_IS_DEFINED (fixP->fx_addsy)
25419 || S_GET_SEGMENT (fixP->fx_addsy) != seg
25420 || S_IS_WEAK (fixP->fx_addsy))
25422 as_bad_where (fixP->fx_file, fixP->fx_line,
25423 _("address calculation needs a strongly defined nearby symbol"));
25425 else
25427 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
25429 /* Round up to the next 4-byte boundary. */
25430 if (v & 3)
25431 v = (v + 3) & ~ 3;
25432 else
25433 v += 4;
25434 v = S_GET_VALUE (fixP->fx_addsy) - v;
25436 if (v & ~0x3fc)
25438 as_bad_where (fixP->fx_file, fixP->fx_line,
25439 _("symbol too far away"));
25441 else
25443 fixP->fx_done = 1;
25444 value = v;
25449 if (subtract || value & ~0x3fc)
25450 as_bad_where (fixP->fx_file, fixP->fx_line,
25451 _("invalid immediate for address calculation (value = 0x%08lX)"),
25452 (unsigned long) (subtract ? - value : value));
25453 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
25454 newval |= rd << 8;
25455 newval |= value >> 2;
25457 else if (rs == rd)
25459 if (value & ~0xff)
25460 as_bad_where (fixP->fx_file, fixP->fx_line,
25461 _("immediate value out of range"));
25462 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
25463 newval |= (rd << 8) | value;
25465 else
25467 if (value & ~0x7)
25468 as_bad_where (fixP->fx_file, fixP->fx_line,
25469 _("immediate value out of range"));
25470 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
25471 newval |= rd | (rs << 3) | (value << 6);
25474 md_number_to_chars (buf, newval, THUMB_SIZE);
25475 break;
25477 case BFD_RELOC_ARM_THUMB_IMM:
25478 newval = md_chars_to_number (buf, THUMB_SIZE);
25479 if (value < 0 || value > 255)
25480 as_bad_where (fixP->fx_file, fixP->fx_line,
25481 _("invalid immediate: %ld is out of range"),
25482 (long) value);
25483 newval |= value;
25484 md_number_to_chars (buf, newval, THUMB_SIZE);
25485 break;
25487 case BFD_RELOC_ARM_THUMB_SHIFT:
25488 /* 5bit shift value (0..32). LSL cannot take 32. */
25489 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
25490 temp = newval & 0xf800;
25491 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
25492 as_bad_where (fixP->fx_file, fixP->fx_line,
25493 _("invalid shift value: %ld"), (long) value);
25494 /* Shifts of zero must be encoded as LSL. */
25495 if (value == 0)
25496 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
25497 /* Shifts of 32 are encoded as zero. */
25498 else if (value == 32)
25499 value = 0;
25500 newval |= value << 6;
25501 md_number_to_chars (buf, newval, THUMB_SIZE);
25502 break;
25504 case BFD_RELOC_VTABLE_INHERIT:
25505 case BFD_RELOC_VTABLE_ENTRY:
25506 fixP->fx_done = 0;
25507 return;
25509 case BFD_RELOC_ARM_MOVW:
25510 case BFD_RELOC_ARM_MOVT:
25511 case BFD_RELOC_ARM_THUMB_MOVW:
25512 case BFD_RELOC_ARM_THUMB_MOVT:
25513 if (fixP->fx_done || !seg->use_rela_p)
25515 /* REL format relocations are limited to a 16-bit addend. */
25516 if (!fixP->fx_done)
25518 if (value < -0x8000 || value > 0x7fff)
25519 as_bad_where (fixP->fx_file, fixP->fx_line,
25520 _("offset out of range"));
25522 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25523 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25525 value >>= 16;
25528 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25529 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
25531 newval = get_thumb32_insn (buf);
25532 newval &= 0xfbf08f00;
25533 newval |= (value & 0xf000) << 4;
25534 newval |= (value & 0x0800) << 15;
25535 newval |= (value & 0x0700) << 4;
25536 newval |= (value & 0x00ff);
25537 put_thumb32_insn (buf, newval);
25539 else
25541 newval = md_chars_to_number (buf, 4);
25542 newval &= 0xfff0f000;
25543 newval |= value & 0x0fff;
25544 newval |= (value & 0xf000) << 4;
25545 md_number_to_chars (buf, newval, 4);
25548 return;
25550 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
25551 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
25552 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
25553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
25554 gas_assert (!fixP->fx_done);
25556 bfd_vma insn;
25557 bfd_boolean is_mov;
25558 bfd_vma encoded_addend = value;
25560 /* Check that addend can be encoded in instruction. */
25561 if (!seg->use_rela_p && (value < 0 || value > 255))
25562 as_bad_where (fixP->fx_file, fixP->fx_line,
25563 _("the offset 0x%08lX is not representable"),
25564 (unsigned long) encoded_addend);
25566 /* Extract the instruction. */
25567 insn = md_chars_to_number (buf, THUMB_SIZE);
25568 is_mov = (insn & 0xf800) == 0x2000;
25570 /* Encode insn. */
25571 if (is_mov)
25573 if (!seg->use_rela_p)
25574 insn |= encoded_addend;
25576 else
25578 int rd, rs;
25580 /* Extract the instruction. */
25581 /* Encoding is the following
25582 0x8000 SUB
25583 0x00F0 Rd
25584 0x000F Rs
25586 /* The following conditions must be true :
25587 - ADD
25588 - Rd == Rs
25589 - Rd <= 7
25591 rd = (insn >> 4) & 0xf;
25592 rs = insn & 0xf;
25593 if ((insn & 0x8000) || (rd != rs) || rd > 7)
25594 as_bad_where (fixP->fx_file, fixP->fx_line,
25595 _("Unable to process relocation for thumb opcode: %lx"),
25596 (unsigned long) insn);
25598 /* Encode as ADD immediate8 thumb 1 code. */
25599 insn = 0x3000 | (rd << 8);
25601 /* Place the encoded addend into the first 8 bits of the
25602 instruction. */
25603 if (!seg->use_rela_p)
25604 insn |= encoded_addend;
25607 /* Update the instruction. */
25608 md_number_to_chars (buf, insn, THUMB_SIZE);
25610 break;
25612 case BFD_RELOC_ARM_ALU_PC_G0_NC:
25613 case BFD_RELOC_ARM_ALU_PC_G0:
25614 case BFD_RELOC_ARM_ALU_PC_G1_NC:
25615 case BFD_RELOC_ARM_ALU_PC_G1:
25616 case BFD_RELOC_ARM_ALU_PC_G2:
25617 case BFD_RELOC_ARM_ALU_SB_G0_NC:
25618 case BFD_RELOC_ARM_ALU_SB_G0:
25619 case BFD_RELOC_ARM_ALU_SB_G1_NC:
25620 case BFD_RELOC_ARM_ALU_SB_G1:
25621 case BFD_RELOC_ARM_ALU_SB_G2:
25622 gas_assert (!fixP->fx_done);
25623 if (!seg->use_rela_p)
25625 bfd_vma insn;
25626 bfd_vma encoded_addend;
25627 bfd_vma addend_abs = llabs (value);
25629 /* Check that the absolute value of the addend can be
25630 expressed as an 8-bit constant plus a rotation. */
25631 encoded_addend = encode_arm_immediate (addend_abs);
25632 if (encoded_addend == (unsigned int) FAIL)
25633 as_bad_where (fixP->fx_file, fixP->fx_line,
25634 _("the offset 0x%08lX is not representable"),
25635 (unsigned long) addend_abs);
25637 /* Extract the instruction. */
25638 insn = md_chars_to_number (buf, INSN_SIZE);
25640 /* If the addend is positive, use an ADD instruction.
25641 Otherwise use a SUB. Take care not to destroy the S bit. */
25642 insn &= 0xff1fffff;
25643 if (value < 0)
25644 insn |= 1 << 22;
25645 else
25646 insn |= 1 << 23;
25648 /* Place the encoded addend into the first 12 bits of the
25649 instruction. */
25650 insn &= 0xfffff000;
25651 insn |= encoded_addend;
25653 /* Update the instruction. */
25654 md_number_to_chars (buf, insn, INSN_SIZE);
25656 break;
25658 case BFD_RELOC_ARM_LDR_PC_G0:
25659 case BFD_RELOC_ARM_LDR_PC_G1:
25660 case BFD_RELOC_ARM_LDR_PC_G2:
25661 case BFD_RELOC_ARM_LDR_SB_G0:
25662 case BFD_RELOC_ARM_LDR_SB_G1:
25663 case BFD_RELOC_ARM_LDR_SB_G2:
25664 gas_assert (!fixP->fx_done);
25665 if (!seg->use_rela_p)
25667 bfd_vma insn;
25668 bfd_vma addend_abs = llabs (value);
25670 /* Check that the absolute value of the addend can be
25671 encoded in 12 bits. */
25672 if (addend_abs >= 0x1000)
25673 as_bad_where (fixP->fx_file, fixP->fx_line,
25674 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
25675 (unsigned long) addend_abs);
25677 /* Extract the instruction. */
25678 insn = md_chars_to_number (buf, INSN_SIZE);
25680 /* If the addend is negative, clear bit 23 of the instruction.
25681 Otherwise set it. */
25682 if (value < 0)
25683 insn &= ~(1 << 23);
25684 else
25685 insn |= 1 << 23;
25687 /* Place the absolute value of the addend into the first 12 bits
25688 of the instruction. */
25689 insn &= 0xfffff000;
25690 insn |= addend_abs;
25692 /* Update the instruction. */
25693 md_number_to_chars (buf, insn, INSN_SIZE);
25695 break;
25697 case BFD_RELOC_ARM_LDRS_PC_G0:
25698 case BFD_RELOC_ARM_LDRS_PC_G1:
25699 case BFD_RELOC_ARM_LDRS_PC_G2:
25700 case BFD_RELOC_ARM_LDRS_SB_G0:
25701 case BFD_RELOC_ARM_LDRS_SB_G1:
25702 case BFD_RELOC_ARM_LDRS_SB_G2:
25703 gas_assert (!fixP->fx_done);
25704 if (!seg->use_rela_p)
25706 bfd_vma insn;
25707 bfd_vma addend_abs = llabs (value);
25709 /* Check that the absolute value of the addend can be
25710 encoded in 8 bits. */
25711 if (addend_abs >= 0x100)
25712 as_bad_where (fixP->fx_file, fixP->fx_line,
25713 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
25714 (unsigned long) addend_abs);
25716 /* Extract the instruction. */
25717 insn = md_chars_to_number (buf, INSN_SIZE);
25719 /* If the addend is negative, clear bit 23 of the instruction.
25720 Otherwise set it. */
25721 if (value < 0)
25722 insn &= ~(1 << 23);
25723 else
25724 insn |= 1 << 23;
25726 /* Place the first four bits of the absolute value of the addend
25727 into the first 4 bits of the instruction, and the remaining
25728 four into bits 8 .. 11. */
25729 insn &= 0xfffff0f0;
25730 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
25732 /* Update the instruction. */
25733 md_number_to_chars (buf, insn, INSN_SIZE);
25735 break;
25737 case BFD_RELOC_ARM_LDC_PC_G0:
25738 case BFD_RELOC_ARM_LDC_PC_G1:
25739 case BFD_RELOC_ARM_LDC_PC_G2:
25740 case BFD_RELOC_ARM_LDC_SB_G0:
25741 case BFD_RELOC_ARM_LDC_SB_G1:
25742 case BFD_RELOC_ARM_LDC_SB_G2:
25743 gas_assert (!fixP->fx_done);
25744 if (!seg->use_rela_p)
25746 bfd_vma insn;
25747 bfd_vma addend_abs = llabs (value);
25749 /* Check that the absolute value of the addend is a multiple of
25750 four and, when divided by four, fits in 8 bits. */
25751 if (addend_abs & 0x3)
25752 as_bad_where (fixP->fx_file, fixP->fx_line,
25753 _("bad offset 0x%08lX (must be word-aligned)"),
25754 (unsigned long) addend_abs);
25756 if ((addend_abs >> 2) > 0xff)
25757 as_bad_where (fixP->fx_file, fixP->fx_line,
25758 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
25759 (unsigned long) addend_abs);
25761 /* Extract the instruction. */
25762 insn = md_chars_to_number (buf, INSN_SIZE);
25764 /* If the addend is negative, clear bit 23 of the instruction.
25765 Otherwise set it. */
25766 if (value < 0)
25767 insn &= ~(1 << 23);
25768 else
25769 insn |= 1 << 23;
25771 /* Place the addend (divided by four) into the first eight
25772 bits of the instruction. */
25773 insn &= 0xfffffff0;
25774 insn |= addend_abs >> 2;
25776 /* Update the instruction. */
25777 md_number_to_chars (buf, insn, INSN_SIZE);
25779 break;
25781 case BFD_RELOC_THUMB_PCREL_BRANCH5:
25782 if (fixP->fx_addsy
25783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25784 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25785 && ARM_IS_FUNC (fixP->fx_addsy)
25786 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25788 /* Force a relocation for a branch 5 bits wide. */
25789 fixP->fx_done = 0;
25791 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
25792 as_bad_where (fixP->fx_file, fixP->fx_line,
25793 BAD_BRANCH_OFF);
25795 if (fixP->fx_done || !seg->use_rela_p)
25797 addressT boff = value >> 1;
25799 newval = md_chars_to_number (buf, THUMB_SIZE);
25800 newval |= (boff << 7);
25801 md_number_to_chars (buf, newval, THUMB_SIZE);
25803 break;
25805 case BFD_RELOC_THUMB_PCREL_BFCSEL:
25806 if (fixP->fx_addsy
25807 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25809 && ARM_IS_FUNC (fixP->fx_addsy)
25810 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25812 fixP->fx_done = 0;
25814 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
25815 as_bad_where (fixP->fx_file, fixP->fx_line,
25816 _("branch out of range"));
25818 if (fixP->fx_done || !seg->use_rela_p)
25820 newval = md_chars_to_number (buf, THUMB_SIZE);
25822 addressT boff = ((newval & 0x0780) >> 7) << 1;
25823 addressT diff = value - boff;
25825 if (diff == 4)
25827 newval |= 1 << 1; /* T bit. */
25829 else if (diff != 2)
25831 as_bad_where (fixP->fx_file, fixP->fx_line,
25832 _("out of range label-relative fixup value"));
25834 md_number_to_chars (buf, newval, THUMB_SIZE);
25836 break;
25838 case BFD_RELOC_ARM_THUMB_BF17:
25839 if (fixP->fx_addsy
25840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25841 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25842 && ARM_IS_FUNC (fixP->fx_addsy)
25843 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25845 /* Force a relocation for a branch 17 bits wide. */
25846 fixP->fx_done = 0;
25849 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
25850 as_bad_where (fixP->fx_file, fixP->fx_line,
25851 BAD_BRANCH_OFF);
25853 if (fixP->fx_done || !seg->use_rela_p)
25855 offsetT newval2;
25856 addressT immA, immB, immC;
25858 immA = (value & 0x0001f000) >> 12;
25859 immB = (value & 0x00000ffc) >> 2;
25860 immC = (value & 0x00000002) >> 1;
25862 newval = md_chars_to_number (buf, THUMB_SIZE);
25863 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25864 newval |= immA;
25865 newval2 |= (immC << 11) | (immB << 1);
25866 md_number_to_chars (buf, newval, THUMB_SIZE);
25867 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25869 break;
25871 case BFD_RELOC_ARM_THUMB_BF19:
25872 if (fixP->fx_addsy
25873 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25874 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25875 && ARM_IS_FUNC (fixP->fx_addsy)
25876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25878 /* Force a relocation for a branch 19 bits wide. */
25879 fixP->fx_done = 0;
25882 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
25883 as_bad_where (fixP->fx_file, fixP->fx_line,
25884 BAD_BRANCH_OFF);
25886 if (fixP->fx_done || !seg->use_rela_p)
25888 offsetT newval2;
25889 addressT immA, immB, immC;
25891 immA = (value & 0x0007f000) >> 12;
25892 immB = (value & 0x00000ffc) >> 2;
25893 immC = (value & 0x00000002) >> 1;
25895 newval = md_chars_to_number (buf, THUMB_SIZE);
25896 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25897 newval |= immA;
25898 newval2 |= (immC << 11) | (immB << 1);
25899 md_number_to_chars (buf, newval, THUMB_SIZE);
25900 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25902 break;
25904 case BFD_RELOC_ARM_THUMB_BF13:
25905 if (fixP->fx_addsy
25906 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25907 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25908 && ARM_IS_FUNC (fixP->fx_addsy)
25909 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25911 /* Force a relocation for a branch 13 bits wide. */
25912 fixP->fx_done = 0;
25915 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
25916 as_bad_where (fixP->fx_file, fixP->fx_line,
25917 BAD_BRANCH_OFF);
25919 if (fixP->fx_done || !seg->use_rela_p)
25921 offsetT newval2;
25922 addressT immA, immB, immC;
25924 immA = (value & 0x00001000) >> 12;
25925 immB = (value & 0x00000ffc) >> 2;
25926 immC = (value & 0x00000002) >> 1;
25928 newval = md_chars_to_number (buf, THUMB_SIZE);
25929 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25930 newval |= immA;
25931 newval2 |= (immC << 11) | (immB << 1);
25932 md_number_to_chars (buf, newval, THUMB_SIZE);
25933 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
25935 break;
25937 case BFD_RELOC_ARM_THUMB_LOOP12:
25938 if (fixP->fx_addsy
25939 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
25940 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
25941 && ARM_IS_FUNC (fixP->fx_addsy)
25942 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
25944 /* Force a relocation for a branch 12 bits wide. */
25945 fixP->fx_done = 0;
25948 bfd_vma insn = get_thumb32_insn (buf);
25949 /* le lr, <label> or le <label> */
25950 if (((insn & 0xffffffff) == 0xf00fc001)
25951 || ((insn & 0xffffffff) == 0xf02fc001))
25952 value = -value;
25954 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
25955 as_bad_where (fixP->fx_file, fixP->fx_line,
25956 BAD_BRANCH_OFF);
25957 if (fixP->fx_done || !seg->use_rela_p)
25959 addressT imml, immh;
25961 immh = (value & 0x00000ffc) >> 2;
25962 imml = (value & 0x00000002) >> 1;
25964 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
25965 newval |= (imml << 11) | (immh << 1);
25966 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
25968 break;
25970 case BFD_RELOC_ARM_V4BX:
25971 /* This will need to go in the object file. */
25972 fixP->fx_done = 0;
25973 break;
25975 case BFD_RELOC_UNUSED:
25976 default:
25977 as_bad_where (fixP->fx_file, fixP->fx_line,
25978 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
25982 /* Translate internal representation of relocation info to BFD target
25983 format. */
25985 arelent *
25986 tc_gen_reloc (asection *section, fixS *fixp)
25988 arelent * reloc;
25989 bfd_reloc_code_real_type code;
25991 reloc = XNEW (arelent);
25993 reloc->sym_ptr_ptr = XNEW (asymbol *);
25994 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
25995 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
25997 if (fixp->fx_pcrel)
25999 if (section->use_rela_p)
26000 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
26001 else
26002 fixp->fx_offset = reloc->address;
26004 reloc->addend = fixp->fx_offset;
26006 switch (fixp->fx_r_type)
26008 case BFD_RELOC_8:
26009 if (fixp->fx_pcrel)
26011 code = BFD_RELOC_8_PCREL;
26012 break;
26014 /* Fall through. */
26016 case BFD_RELOC_16:
26017 if (fixp->fx_pcrel)
26019 code = BFD_RELOC_16_PCREL;
26020 break;
26022 /* Fall through. */
26024 case BFD_RELOC_32:
26025 if (fixp->fx_pcrel)
26027 code = BFD_RELOC_32_PCREL;
26028 break;
26030 /* Fall through. */
26032 case BFD_RELOC_ARM_MOVW:
26033 if (fixp->fx_pcrel)
26035 code = BFD_RELOC_ARM_MOVW_PCREL;
26036 break;
26038 /* Fall through. */
26040 case BFD_RELOC_ARM_MOVT:
26041 if (fixp->fx_pcrel)
26043 code = BFD_RELOC_ARM_MOVT_PCREL;
26044 break;
26046 /* Fall through. */
26048 case BFD_RELOC_ARM_THUMB_MOVW:
26049 if (fixp->fx_pcrel)
26051 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
26052 break;
26054 /* Fall through. */
26056 case BFD_RELOC_ARM_THUMB_MOVT:
26057 if (fixp->fx_pcrel)
26059 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
26060 break;
26062 /* Fall through. */
26064 case BFD_RELOC_NONE:
26065 case BFD_RELOC_ARM_PCREL_BRANCH:
26066 case BFD_RELOC_ARM_PCREL_BLX:
26067 case BFD_RELOC_RVA:
26068 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26069 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26070 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26071 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26072 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26073 case BFD_RELOC_THUMB_PCREL_BRANCH25:
26074 case BFD_RELOC_VTABLE_ENTRY:
26075 case BFD_RELOC_VTABLE_INHERIT:
26076 #ifdef TE_PE
26077 case BFD_RELOC_32_SECREL:
26078 #endif
26079 code = fixp->fx_r_type;
26080 break;
26082 case BFD_RELOC_THUMB_PCREL_BLX:
26083 #ifdef OBJ_ELF
26084 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
26085 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
26086 else
26087 #endif
26088 code = BFD_RELOC_THUMB_PCREL_BLX;
26089 break;
26091 case BFD_RELOC_ARM_LITERAL:
26092 case BFD_RELOC_ARM_HWLITERAL:
26093 /* If this is called then the a literal has
26094 been referenced across a section boundary. */
26095 as_bad_where (fixp->fx_file, fixp->fx_line,
26096 _("literal referenced across section boundary"));
26097 return NULL;
26099 #ifdef OBJ_ELF
26100 case BFD_RELOC_ARM_TLS_CALL:
26101 case BFD_RELOC_ARM_THM_TLS_CALL:
26102 case BFD_RELOC_ARM_TLS_DESCSEQ:
26103 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
26104 case BFD_RELOC_ARM_GOT32:
26105 case BFD_RELOC_ARM_GOTOFF:
26106 case BFD_RELOC_ARM_GOT_PREL:
26107 case BFD_RELOC_ARM_PLT32:
26108 case BFD_RELOC_ARM_TARGET1:
26109 case BFD_RELOC_ARM_ROSEGREL32:
26110 case BFD_RELOC_ARM_SBREL32:
26111 case BFD_RELOC_ARM_PREL31:
26112 case BFD_RELOC_ARM_TARGET2:
26113 case BFD_RELOC_ARM_TLS_LDO32:
26114 case BFD_RELOC_ARM_PCREL_CALL:
26115 case BFD_RELOC_ARM_PCREL_JUMP:
26116 case BFD_RELOC_ARM_ALU_PC_G0_NC:
26117 case BFD_RELOC_ARM_ALU_PC_G0:
26118 case BFD_RELOC_ARM_ALU_PC_G1_NC:
26119 case BFD_RELOC_ARM_ALU_PC_G1:
26120 case BFD_RELOC_ARM_ALU_PC_G2:
26121 case BFD_RELOC_ARM_LDR_PC_G0:
26122 case BFD_RELOC_ARM_LDR_PC_G1:
26123 case BFD_RELOC_ARM_LDR_PC_G2:
26124 case BFD_RELOC_ARM_LDRS_PC_G0:
26125 case BFD_RELOC_ARM_LDRS_PC_G1:
26126 case BFD_RELOC_ARM_LDRS_PC_G2:
26127 case BFD_RELOC_ARM_LDC_PC_G0:
26128 case BFD_RELOC_ARM_LDC_PC_G1:
26129 case BFD_RELOC_ARM_LDC_PC_G2:
26130 case BFD_RELOC_ARM_ALU_SB_G0_NC:
26131 case BFD_RELOC_ARM_ALU_SB_G0:
26132 case BFD_RELOC_ARM_ALU_SB_G1_NC:
26133 case BFD_RELOC_ARM_ALU_SB_G1:
26134 case BFD_RELOC_ARM_ALU_SB_G2:
26135 case BFD_RELOC_ARM_LDR_SB_G0:
26136 case BFD_RELOC_ARM_LDR_SB_G1:
26137 case BFD_RELOC_ARM_LDR_SB_G2:
26138 case BFD_RELOC_ARM_LDRS_SB_G0:
26139 case BFD_RELOC_ARM_LDRS_SB_G1:
26140 case BFD_RELOC_ARM_LDRS_SB_G2:
26141 case BFD_RELOC_ARM_LDC_SB_G0:
26142 case BFD_RELOC_ARM_LDC_SB_G1:
26143 case BFD_RELOC_ARM_LDC_SB_G2:
26144 case BFD_RELOC_ARM_V4BX:
26145 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
26146 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
26147 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
26148 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
26149 case BFD_RELOC_ARM_GOTFUNCDESC:
26150 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
26151 case BFD_RELOC_ARM_FUNCDESC:
26152 case BFD_RELOC_ARM_THUMB_BF17:
26153 case BFD_RELOC_ARM_THUMB_BF19:
26154 case BFD_RELOC_ARM_THUMB_BF13:
26155 code = fixp->fx_r_type;
26156 break;
26158 case BFD_RELOC_ARM_TLS_GOTDESC:
26159 case BFD_RELOC_ARM_TLS_GD32:
26160 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
26161 case BFD_RELOC_ARM_TLS_LE32:
26162 case BFD_RELOC_ARM_TLS_IE32:
26163 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
26164 case BFD_RELOC_ARM_TLS_LDM32:
26165 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
26166 /* BFD will include the symbol's address in the addend.
26167 But we don't want that, so subtract it out again here. */
26168 if (!S_IS_COMMON (fixp->fx_addsy))
26169 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
26170 code = fixp->fx_r_type;
26171 break;
26172 #endif
26174 case BFD_RELOC_ARM_IMMEDIATE:
26175 as_bad_where (fixp->fx_file, fixp->fx_line,
26176 _("internal relocation (type: IMMEDIATE) not fixed up"));
26177 return NULL;
26179 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
26180 as_bad_where (fixp->fx_file, fixp->fx_line,
26181 _("ADRL used for a symbol not defined in the same file"));
26182 return NULL;
26184 case BFD_RELOC_THUMB_PCREL_BRANCH5:
26185 case BFD_RELOC_THUMB_PCREL_BFCSEL:
26186 case BFD_RELOC_ARM_THUMB_LOOP12:
26187 as_bad_where (fixp->fx_file, fixp->fx_line,
26188 _("%s used for a symbol not defined in the same file"),
26189 bfd_get_reloc_code_name (fixp->fx_r_type));
26190 return NULL;
26192 case BFD_RELOC_ARM_OFFSET_IMM:
26193 if (section->use_rela_p)
26195 code = fixp->fx_r_type;
26196 break;
26199 if (fixp->fx_addsy != NULL
26200 && !S_IS_DEFINED (fixp->fx_addsy)
26201 && S_IS_LOCAL (fixp->fx_addsy))
26203 as_bad_where (fixp->fx_file, fixp->fx_line,
26204 _("undefined local label `%s'"),
26205 S_GET_NAME (fixp->fx_addsy));
26206 return NULL;
26209 as_bad_where (fixp->fx_file, fixp->fx_line,
26210 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
26211 return NULL;
26213 default:
26215 const char * type;
26217 switch (fixp->fx_r_type)
26219 case BFD_RELOC_NONE: type = "NONE"; break;
26220 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
26221 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
26222 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
26223 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
26224 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
26225 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
26226 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
26227 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
26228 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
26229 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
26230 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
26231 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
26232 default: type = _("<unknown>"); break;
26234 as_bad_where (fixp->fx_file, fixp->fx_line,
26235 _("cannot represent %s relocation in this object file format"),
26236 type);
26237 return NULL;
26241 #ifdef OBJ_ELF
26242 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
26243 && GOT_symbol
26244 && fixp->fx_addsy == GOT_symbol)
26246 code = BFD_RELOC_ARM_GOTPC;
26247 reloc->addend = fixp->fx_offset = reloc->address;
26249 #endif
26251 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
26253 if (reloc->howto == NULL)
26255 as_bad_where (fixp->fx_file, fixp->fx_line,
26256 _("cannot represent %s relocation in this object file format"),
26257 bfd_get_reloc_code_name (code));
26258 return NULL;
26261 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
26262 vtable entry to be used in the relocation's section offset. */
26263 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
26264 reloc->address = fixp->fx_offset;
26266 return reloc;
26269 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
26271 void
26272 cons_fix_new_arm (fragS * frag,
26273 int where,
26274 int size,
26275 expressionS * exp,
26276 bfd_reloc_code_real_type reloc)
26278 int pcrel = 0;
26280 /* Pick a reloc.
26281 FIXME: @@ Should look at CPU word size. */
26282 switch (size)
26284 case 1:
26285 reloc = BFD_RELOC_8;
26286 break;
26287 case 2:
26288 reloc = BFD_RELOC_16;
26289 break;
26290 case 4:
26291 default:
26292 reloc = BFD_RELOC_32;
26293 break;
26294 case 8:
26295 reloc = BFD_RELOC_64;
26296 break;
26299 #ifdef TE_PE
26300 if (exp->X_op == O_secrel)
26302 exp->X_op = O_symbol;
26303 reloc = BFD_RELOC_32_SECREL;
26305 #endif
26307 fix_new_exp (frag, where, size, exp, pcrel, reloc);
26310 #if defined (OBJ_COFF)
26311 void
26312 arm_validate_fix (fixS * fixP)
26314 /* If the destination of the branch is a defined symbol which does not have
26315 the THUMB_FUNC attribute, then we must be calling a function which has
26316 the (interfacearm) attribute. We look for the Thumb entry point to that
26317 function and change the branch to refer to that function instead. */
26318 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
26319 && fixP->fx_addsy != NULL
26320 && S_IS_DEFINED (fixP->fx_addsy)
26321 && ! THUMB_IS_FUNC (fixP->fx_addsy))
26323 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
26326 #endif
26330 arm_force_relocation (struct fix * fixp)
26332 #if defined (OBJ_COFF) && defined (TE_PE)
26333 if (fixp->fx_r_type == BFD_RELOC_RVA)
26334 return 1;
26335 #endif
26337 /* In case we have a call or a branch to a function in ARM ISA mode from
26338 a thumb function or vice-versa force the relocation. These relocations
26339 are cleared off for some cores that might have blx and simple transformations
26340 are possible. */
26342 #ifdef OBJ_ELF
26343 switch (fixp->fx_r_type)
26345 case BFD_RELOC_ARM_PCREL_JUMP:
26346 case BFD_RELOC_ARM_PCREL_CALL:
26347 case BFD_RELOC_THUMB_PCREL_BLX:
26348 if (THUMB_IS_FUNC (fixp->fx_addsy))
26349 return 1;
26350 break;
26352 case BFD_RELOC_ARM_PCREL_BLX:
26353 case BFD_RELOC_THUMB_PCREL_BRANCH25:
26354 case BFD_RELOC_THUMB_PCREL_BRANCH20:
26355 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26356 if (ARM_IS_FUNC (fixp->fx_addsy))
26357 return 1;
26358 break;
26360 default:
26361 break;
26363 #endif
26365 /* Resolve these relocations even if the symbol is extern or weak.
26366 Technically this is probably wrong due to symbol preemption.
26367 In practice these relocations do not have enough range to be useful
26368 at dynamic link time, and some code (e.g. in the Linux kernel)
26369 expects these references to be resolved. */
26370 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
26371 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
26372 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
26373 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
26374 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
26375 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
26376 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
26377 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
26378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
26379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
26380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
26381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
26382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
26383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
26384 return 0;
26386 /* Always leave these relocations for the linker. */
26387 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26388 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26389 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
26390 return 1;
26392 /* Always generate relocations against function symbols. */
26393 if (fixp->fx_r_type == BFD_RELOC_32
26394 && fixp->fx_addsy
26395 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
26396 return 1;
26398 return generic_force_reloc (fixp);
26401 #if defined (OBJ_ELF) || defined (OBJ_COFF)
26402 /* Relocations against function names must be left unadjusted,
26403 so that the linker can use this information to generate interworking
26404 stubs. The MIPS version of this function
26405 also prevents relocations that are mips-16 specific, but I do not
26406 know why it does this.
26408 FIXME:
26409 There is one other problem that ought to be addressed here, but
26410 which currently is not: Taking the address of a label (rather
26411 than a function) and then later jumping to that address. Such
26412 addresses also ought to have their bottom bit set (assuming that
26413 they reside in Thumb code), but at the moment they will not. */
26415 bfd_boolean
26416 arm_fix_adjustable (fixS * fixP)
26418 if (fixP->fx_addsy == NULL)
26419 return 1;
26421 /* Preserve relocations against symbols with function type. */
26422 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
26423 return FALSE;
26425 if (THUMB_IS_FUNC (fixP->fx_addsy)
26426 && fixP->fx_subsy == NULL)
26427 return FALSE;
26429 /* We need the symbol name for the VTABLE entries. */
26430 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
26431 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
26432 return FALSE;
26434 /* Don't allow symbols to be discarded on GOT related relocs. */
26435 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
26436 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
26437 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
26438 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
26439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
26440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
26441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
26442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
26443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
26444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
26445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
26446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
26447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
26448 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
26449 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
26450 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
26451 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
26452 return FALSE;
26454 /* Similarly for group relocations. */
26455 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
26456 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
26457 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
26458 return FALSE;
26460 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
26461 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
26462 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
26463 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
26464 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
26465 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
26466 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
26467 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
26468 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
26469 return FALSE;
26471 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
26472 offsets, so keep these symbols. */
26473 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
26474 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
26475 return FALSE;
26477 return TRUE;
26479 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
26481 #ifdef OBJ_ELF
26482 const char *
26483 elf32_arm_target_format (void)
26485 #ifdef TE_SYMBIAN
26486 return (target_big_endian
26487 ? "elf32-bigarm-symbian"
26488 : "elf32-littlearm-symbian");
26489 #elif defined (TE_VXWORKS)
26490 return (target_big_endian
26491 ? "elf32-bigarm-vxworks"
26492 : "elf32-littlearm-vxworks");
26493 #elif defined (TE_NACL)
26494 return (target_big_endian
26495 ? "elf32-bigarm-nacl"
26496 : "elf32-littlearm-nacl");
26497 #else
26498 if (arm_fdpic)
26500 if (target_big_endian)
26501 return "elf32-bigarm-fdpic";
26502 else
26503 return "elf32-littlearm-fdpic";
26505 else
26507 if (target_big_endian)
26508 return "elf32-bigarm";
26509 else
26510 return "elf32-littlearm";
26512 #endif
26515 void
26516 armelf_frob_symbol (symbolS * symp,
26517 int * puntp)
26519 elf_frob_symbol (symp, puntp);
26521 #endif
26523 /* MD interface: Finalization. */
26525 void
26526 arm_cleanup (void)
26528 literal_pool * pool;
26530 /* Ensure that all the predication blocks are properly closed. */
26531 check_pred_blocks_finished ();
26533 for (pool = list_of_pools; pool; pool = pool->next)
26535 /* Put it at the end of the relevant section. */
26536 subseg_set (pool->section, pool->sub_section);
26537 #ifdef OBJ_ELF
26538 arm_elf_change_section ();
26539 #endif
26540 s_ltorg (0);
26544 #ifdef OBJ_ELF
26545 /* Remove any excess mapping symbols generated for alignment frags in
26546 SEC. We may have created a mapping symbol before a zero byte
26547 alignment; remove it if there's a mapping symbol after the
26548 alignment. */
26549 static void
26550 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
26551 void *dummy ATTRIBUTE_UNUSED)
26553 segment_info_type *seginfo = seg_info (sec);
26554 fragS *fragp;
26556 if (seginfo == NULL || seginfo->frchainP == NULL)
26557 return;
26559 for (fragp = seginfo->frchainP->frch_root;
26560 fragp != NULL;
26561 fragp = fragp->fr_next)
26563 symbolS *sym = fragp->tc_frag_data.last_map;
26564 fragS *next = fragp->fr_next;
26566 /* Variable-sized frags have been converted to fixed size by
26567 this point. But if this was variable-sized to start with,
26568 there will be a fixed-size frag after it. So don't handle
26569 next == NULL. */
26570 if (sym == NULL || next == NULL)
26571 continue;
26573 if (S_GET_VALUE (sym) < next->fr_address)
26574 /* Not at the end of this frag. */
26575 continue;
26576 know (S_GET_VALUE (sym) == next->fr_address);
26580 if (next->tc_frag_data.first_map != NULL)
26582 /* Next frag starts with a mapping symbol. Discard this
26583 one. */
26584 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26585 break;
26588 if (next->fr_next == NULL)
26590 /* This mapping symbol is at the end of the section. Discard
26591 it. */
26592 know (next->fr_fix == 0 && next->fr_var == 0);
26593 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
26594 break;
26597 /* As long as we have empty frags without any mapping symbols,
26598 keep looking. */
26599 /* If the next frag is non-empty and does not start with a
26600 mapping symbol, then this mapping symbol is required. */
26601 if (next->fr_address != next->fr_next->fr_address)
26602 break;
26604 next = next->fr_next;
26606 while (next != NULL);
26609 #endif
26611 /* Adjust the symbol table. This marks Thumb symbols as distinct from
26612 ARM ones. */
26614 void
26615 arm_adjust_symtab (void)
26617 #ifdef OBJ_COFF
26618 symbolS * sym;
26620 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
26622 if (ARM_IS_THUMB (sym))
26624 if (THUMB_IS_FUNC (sym))
26626 /* Mark the symbol as a Thumb function. */
26627 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
26628 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
26629 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
26631 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
26632 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
26633 else
26634 as_bad (_("%s: unexpected function type: %d"),
26635 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
26637 else switch (S_GET_STORAGE_CLASS (sym))
26639 case C_EXT:
26640 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
26641 break;
26642 case C_STAT:
26643 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
26644 break;
26645 case C_LABEL:
26646 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
26647 break;
26648 default:
26649 /* Do nothing. */
26650 break;
26654 if (ARM_IS_INTERWORK (sym))
26655 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
26657 #endif
26658 #ifdef OBJ_ELF
26659 symbolS * sym;
26660 char bind;
26662 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
26664 if (ARM_IS_THUMB (sym))
26666 elf_symbol_type * elf_sym;
26668 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
26669 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
26671 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
26672 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
26674 /* If it's a .thumb_func, declare it as so,
26675 otherwise tag label as .code 16. */
26676 if (THUMB_IS_FUNC (sym))
26677 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
26678 ST_BRANCH_TO_THUMB);
26679 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26680 elf_sym->internal_elf_sym.st_info =
26681 ELF_ST_INFO (bind, STT_ARM_16BIT);
26686 /* Remove any overlapping mapping symbols generated by alignment frags. */
26687 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
26688 /* Now do generic ELF adjustments. */
26689 elf_adjust_symtab ();
26690 #endif
26693 /* MD interface: Initialization. */
26695 static void
26696 set_constant_flonums (void)
26698 int i;
26700 for (i = 0; i < NUM_FLOAT_VALS; i++)
26701 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
26702 abort ();
26705 /* Auto-select Thumb mode if it's the only available instruction set for the
26706 given architecture. */
26708 static void
26709 autoselect_thumb_from_cpu_variant (void)
26711 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
26712 opcode_select (16);
26715 void
26716 md_begin (void)
26718 unsigned mach;
26719 unsigned int i;
26721 if ( (arm_ops_hsh = hash_new ()) == NULL
26722 || (arm_cond_hsh = hash_new ()) == NULL
26723 || (arm_vcond_hsh = hash_new ()) == NULL
26724 || (arm_shift_hsh = hash_new ()) == NULL
26725 || (arm_psr_hsh = hash_new ()) == NULL
26726 || (arm_v7m_psr_hsh = hash_new ()) == NULL
26727 || (arm_reg_hsh = hash_new ()) == NULL
26728 || (arm_reloc_hsh = hash_new ()) == NULL
26729 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
26730 as_fatal (_("virtual memory exhausted"));
26732 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
26733 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
26734 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
26735 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
26736 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
26737 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
26738 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
26739 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
26740 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
26741 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
26742 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
26743 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
26744 (void *) (v7m_psrs + i));
26745 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
26746 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
26747 for (i = 0;
26748 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
26749 i++)
26750 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
26751 (void *) (barrier_opt_names + i));
26752 #ifdef OBJ_ELF
26753 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
26755 struct reloc_entry * entry = reloc_names + i;
26757 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
26758 /* This makes encode_branch() use the EABI versions of this relocation. */
26759 entry->reloc = BFD_RELOC_UNUSED;
26761 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
26763 #endif
26765 set_constant_flonums ();
26767 /* Set the cpu variant based on the command-line options. We prefer
26768 -mcpu= over -march= if both are set (as for GCC); and we prefer
26769 -mfpu= over any other way of setting the floating point unit.
26770 Use of legacy options with new options are faulted. */
26771 if (legacy_cpu)
26773 if (mcpu_cpu_opt || march_cpu_opt)
26774 as_bad (_("use of old and new-style options to set CPU type"));
26776 selected_arch = *legacy_cpu;
26778 else if (mcpu_cpu_opt)
26780 selected_arch = *mcpu_cpu_opt;
26781 selected_ext = *mcpu_ext_opt;
26783 else if (march_cpu_opt)
26785 selected_arch = *march_cpu_opt;
26786 selected_ext = *march_ext_opt;
26788 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
26790 if (legacy_fpu)
26792 if (mfpu_opt)
26793 as_bad (_("use of old and new-style options to set FPU type"));
26795 selected_fpu = *legacy_fpu;
26797 else if (mfpu_opt)
26798 selected_fpu = *mfpu_opt;
26799 else
26801 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
26802 || defined (TE_NetBSD) || defined (TE_VXWORKS))
26803 /* Some environments specify a default FPU. If they don't, infer it
26804 from the processor. */
26805 if (mcpu_fpu_opt)
26806 selected_fpu = *mcpu_fpu_opt;
26807 else if (march_fpu_opt)
26808 selected_fpu = *march_fpu_opt;
26809 #else
26810 selected_fpu = fpu_default;
26811 #endif
26814 if (ARM_FEATURE_ZERO (selected_fpu))
26816 if (!no_cpu_selected ())
26817 selected_fpu = fpu_default;
26818 else
26819 selected_fpu = fpu_arch_fpa;
26822 #ifdef CPU_DEFAULT
26823 if (ARM_FEATURE_ZERO (selected_arch))
26825 selected_arch = cpu_default;
26826 selected_cpu = selected_arch;
26828 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
26829 #else
26830 /* Autodection of feature mode: allow all features in cpu_variant but leave
26831 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
26832 after all instruction have been processed and we can decide what CPU
26833 should be selected. */
26834 if (ARM_FEATURE_ZERO (selected_arch))
26835 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
26836 else
26837 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
26838 #endif
26840 autoselect_thumb_from_cpu_variant ();
26842 arm_arch_used = thumb_arch_used = arm_arch_none;
26844 #if defined OBJ_COFF || defined OBJ_ELF
26846 unsigned int flags = 0;
26848 #if defined OBJ_ELF
26849 flags = meabi_flags;
26851 switch (meabi_flags)
26853 case EF_ARM_EABI_UNKNOWN:
26854 #endif
26855 /* Set the flags in the private structure. */
26856 if (uses_apcs_26) flags |= F_APCS26;
26857 if (support_interwork) flags |= F_INTERWORK;
26858 if (uses_apcs_float) flags |= F_APCS_FLOAT;
26859 if (pic_code) flags |= F_PIC;
26860 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
26861 flags |= F_SOFT_FLOAT;
26863 switch (mfloat_abi_opt)
26865 case ARM_FLOAT_ABI_SOFT:
26866 case ARM_FLOAT_ABI_SOFTFP:
26867 flags |= F_SOFT_FLOAT;
26868 break;
26870 case ARM_FLOAT_ABI_HARD:
26871 if (flags & F_SOFT_FLOAT)
26872 as_bad (_("hard-float conflicts with specified fpu"));
26873 break;
26876 /* Using pure-endian doubles (even if soft-float). */
26877 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
26878 flags |= F_VFP_FLOAT;
26880 #if defined OBJ_ELF
26881 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
26882 flags |= EF_ARM_MAVERICK_FLOAT;
26883 break;
26885 case EF_ARM_EABI_VER4:
26886 case EF_ARM_EABI_VER5:
26887 /* No additional flags to set. */
26888 break;
26890 default:
26891 abort ();
26893 #endif
26894 bfd_set_private_flags (stdoutput, flags);
26896 /* We have run out flags in the COFF header to encode the
26897 status of ATPCS support, so instead we create a dummy,
26898 empty, debug section called .arm.atpcs. */
26899 if (atpcs)
26901 asection * sec;
26903 sec = bfd_make_section (stdoutput, ".arm.atpcs");
26905 if (sec != NULL)
26907 bfd_set_section_flags
26908 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
26909 bfd_set_section_size (stdoutput, sec, 0);
26910 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
26914 #endif
26916 /* Record the CPU type as well. */
26917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
26918 mach = bfd_mach_arm_iWMMXt2;
26919 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
26920 mach = bfd_mach_arm_iWMMXt;
26921 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
26922 mach = bfd_mach_arm_XScale;
26923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
26924 mach = bfd_mach_arm_ep9312;
26925 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
26926 mach = bfd_mach_arm_5TE;
26927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
26929 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
26930 mach = bfd_mach_arm_5T;
26931 else
26932 mach = bfd_mach_arm_5;
26934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
26936 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
26937 mach = bfd_mach_arm_4T;
26938 else
26939 mach = bfd_mach_arm_4;
26941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
26942 mach = bfd_mach_arm_3M;
26943 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
26944 mach = bfd_mach_arm_3;
26945 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
26946 mach = bfd_mach_arm_2a;
26947 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
26948 mach = bfd_mach_arm_2;
26949 else
26950 mach = bfd_mach_arm_unknown;
26952 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
26955 /* Command line processing. */
26957 /* md_parse_option
26958 Invocation line includes a switch not recognized by the base assembler.
26959 See if it's a processor-specific option.
26961 This routine is somewhat complicated by the need for backwards
26962 compatibility (since older releases of gcc can't be changed).
26963 The new options try to make the interface as compatible as
26964 possible with GCC.
26966 New options (supported) are:
26968 -mcpu=<cpu name> Assemble for selected processor
26969 -march=<architecture name> Assemble for selected architecture
26970 -mfpu=<fpu architecture> Assemble for selected FPU.
26971 -EB/-mbig-endian Big-endian
26972 -EL/-mlittle-endian Little-endian
26973 -k Generate PIC code
26974 -mthumb Start in Thumb mode
26975 -mthumb-interwork Code supports ARM/Thumb interworking
26977 -m[no-]warn-deprecated Warn about deprecated features
26978 -m[no-]warn-syms Warn when symbols match instructions
26980 For now we will also provide support for:
26982 -mapcs-32 32-bit Program counter
26983 -mapcs-26 26-bit Program counter
26984 -macps-float Floats passed in FP registers
26985 -mapcs-reentrant Reentrant code
26986 -matpcs
26987 (sometime these will probably be replaced with -mapcs=<list of options>
26988 and -matpcs=<list of options>)
26990 The remaining options are only supported for back-wards compatibility.
26991 Cpu variants, the arm part is optional:
26992 -m[arm]1 Currently not supported.
26993 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
26994 -m[arm]3 Arm 3 processor
26995 -m[arm]6[xx], Arm 6 processors
26996 -m[arm]7[xx][t][[d]m] Arm 7 processors
26997 -m[arm]8[10] Arm 8 processors
26998 -m[arm]9[20][tdmi] Arm 9 processors
26999 -mstrongarm[110[0]] StrongARM processors
27000 -mxscale XScale processors
27001 -m[arm]v[2345[t[e]]] Arm architectures
27002 -mall All (except the ARM1)
27003 FP variants:
27004 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
27005 -mfpe-old (No float load/store multiples)
27006 -mvfpxd VFP Single precision
27007 -mvfp All VFP
27008 -mno-fpu Disable all floating point instructions
27010 The following CPU names are recognized:
27011 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
27012 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
27013 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
27014 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
27015 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
27016 arm10t arm10e, arm1020t, arm1020e, arm10200e,
27017 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
27021 const char * md_shortopts = "m:k";
27023 #ifdef ARM_BI_ENDIAN
27024 #define OPTION_EB (OPTION_MD_BASE + 0)
27025 #define OPTION_EL (OPTION_MD_BASE + 1)
27026 #else
27027 #if TARGET_BYTES_BIG_ENDIAN
27028 #define OPTION_EB (OPTION_MD_BASE + 0)
27029 #else
27030 #define OPTION_EL (OPTION_MD_BASE + 1)
27031 #endif
27032 #endif
27033 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
27034 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
27036 struct option md_longopts[] =
27038 #ifdef OPTION_EB
27039 {"EB", no_argument, NULL, OPTION_EB},
27040 #endif
27041 #ifdef OPTION_EL
27042 {"EL", no_argument, NULL, OPTION_EL},
27043 #endif
27044 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
27045 #ifdef OBJ_ELF
27046 {"fdpic", no_argument, NULL, OPTION_FDPIC},
27047 #endif
27048 {NULL, no_argument, NULL, 0}
27051 size_t md_longopts_size = sizeof (md_longopts);
27053 struct arm_option_table
27055 const char * option; /* Option name to match. */
27056 const char * help; /* Help information. */
27057 int * var; /* Variable to change. */
27058 int value; /* What to change it to. */
27059 const char * deprecated; /* If non-null, print this message. */
27062 struct arm_option_table arm_opts[] =
27064 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
27065 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
27066 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
27067 &support_interwork, 1, NULL},
27068 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
27069 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
27070 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
27071 1, NULL},
27072 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
27073 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
27074 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
27075 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
27076 NULL},
27078 /* These are recognized by the assembler, but have no affect on code. */
27079 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
27080 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
27082 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
27083 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
27084 &warn_on_deprecated, 0, NULL},
27085 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
27086 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
27087 {NULL, NULL, NULL, 0, NULL}
27090 struct arm_legacy_option_table
27092 const char * option; /* Option name to match. */
27093 const arm_feature_set ** var; /* Variable to change. */
27094 const arm_feature_set value; /* What to change it to. */
27095 const char * deprecated; /* If non-null, print this message. */
27098 const struct arm_legacy_option_table arm_legacy_opts[] =
27100 /* DON'T add any new processors to this list -- we want the whole list
27101 to go away... Add them to the processors table instead. */
27102 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27103 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
27104 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27105 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
27106 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27107 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
27108 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27109 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
27110 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27111 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
27112 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27113 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
27114 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27115 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
27116 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27117 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
27118 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27119 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
27120 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27121 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
27122 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27123 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
27124 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27125 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
27126 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27127 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
27128 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27129 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
27130 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27131 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
27132 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27133 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
27134 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27135 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
27136 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27137 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
27138 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27139 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
27140 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27141 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
27142 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27143 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
27144 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27145 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
27146 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27147 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
27148 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27149 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27150 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27151 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
27152 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27153 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
27154 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27155 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
27156 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27157 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
27158 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27159 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
27160 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27161 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
27162 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27163 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
27164 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27165 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
27166 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27167 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
27168 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27169 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
27170 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
27171 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
27172 N_("use -mcpu=strongarm110")},
27173 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
27174 N_("use -mcpu=strongarm1100")},
27175 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
27176 N_("use -mcpu=strongarm1110")},
27177 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
27178 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
27179 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
27181 /* Architecture variants -- don't add any more to this list either. */
27182 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27183 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
27184 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27185 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
27186 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27187 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
27188 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27189 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
27190 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27191 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
27192 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27193 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
27194 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27195 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
27196 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27197 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
27198 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
27199 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
27201 /* Floating point variants -- don't add any more to this list either. */
27202 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
27203 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
27204 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
27205 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
27206 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
27208 {NULL, NULL, ARM_ARCH_NONE, NULL}
27211 struct arm_cpu_option_table
27213 const char * name;
27214 size_t name_len;
27215 const arm_feature_set value;
27216 const arm_feature_set ext;
27217 /* For some CPUs we assume an FPU unless the user explicitly sets
27218 -mfpu=... */
27219 const arm_feature_set default_fpu;
27220 /* The canonical name of the CPU, or NULL to use NAME converted to upper
27221 case. */
27222 const char * canonical_name;
27225 /* This list should, at a minimum, contain all the cpu names
27226 recognized by GCC. */
27227 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
27229 static const struct arm_cpu_option_table arm_cpus[] =
27231 ARM_CPU_OPT ("all", NULL, ARM_ANY,
27232 ARM_ARCH_NONE,
27233 FPU_ARCH_FPA),
27234 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
27235 ARM_ARCH_NONE,
27236 FPU_ARCH_FPA),
27237 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
27238 ARM_ARCH_NONE,
27239 FPU_ARCH_FPA),
27240 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
27241 ARM_ARCH_NONE,
27242 FPU_ARCH_FPA),
27243 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
27244 ARM_ARCH_NONE,
27245 FPU_ARCH_FPA),
27246 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
27247 ARM_ARCH_NONE,
27248 FPU_ARCH_FPA),
27249 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
27250 ARM_ARCH_NONE,
27251 FPU_ARCH_FPA),
27252 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
27253 ARM_ARCH_NONE,
27254 FPU_ARCH_FPA),
27255 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
27256 ARM_ARCH_NONE,
27257 FPU_ARCH_FPA),
27258 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
27259 ARM_ARCH_NONE,
27260 FPU_ARCH_FPA),
27261 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
27262 ARM_ARCH_NONE,
27263 FPU_ARCH_FPA),
27264 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
27265 ARM_ARCH_NONE,
27266 FPU_ARCH_FPA),
27267 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
27268 ARM_ARCH_NONE,
27269 FPU_ARCH_FPA),
27270 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
27271 ARM_ARCH_NONE,
27272 FPU_ARCH_FPA),
27273 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
27274 ARM_ARCH_NONE,
27275 FPU_ARCH_FPA),
27276 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
27277 ARM_ARCH_NONE,
27278 FPU_ARCH_FPA),
27279 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
27280 ARM_ARCH_NONE,
27281 FPU_ARCH_FPA),
27282 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
27283 ARM_ARCH_NONE,
27284 FPU_ARCH_FPA),
27285 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
27286 ARM_ARCH_NONE,
27287 FPU_ARCH_FPA),
27288 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
27289 ARM_ARCH_NONE,
27290 FPU_ARCH_FPA),
27291 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
27292 ARM_ARCH_NONE,
27293 FPU_ARCH_FPA),
27294 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
27295 ARM_ARCH_NONE,
27296 FPU_ARCH_FPA),
27297 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
27298 ARM_ARCH_NONE,
27299 FPU_ARCH_FPA),
27300 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
27301 ARM_ARCH_NONE,
27302 FPU_ARCH_FPA),
27303 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
27304 ARM_ARCH_NONE,
27305 FPU_ARCH_FPA),
27306 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
27307 ARM_ARCH_NONE,
27308 FPU_ARCH_FPA),
27309 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
27310 ARM_ARCH_NONE,
27311 FPU_ARCH_FPA),
27312 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
27313 ARM_ARCH_NONE,
27314 FPU_ARCH_FPA),
27315 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
27316 ARM_ARCH_NONE,
27317 FPU_ARCH_FPA),
27318 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
27319 ARM_ARCH_NONE,
27320 FPU_ARCH_FPA),
27321 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
27322 ARM_ARCH_NONE,
27323 FPU_ARCH_FPA),
27324 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
27325 ARM_ARCH_NONE,
27326 FPU_ARCH_FPA),
27327 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
27328 ARM_ARCH_NONE,
27329 FPU_ARCH_FPA),
27330 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
27331 ARM_ARCH_NONE,
27332 FPU_ARCH_FPA),
27333 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
27334 ARM_ARCH_NONE,
27335 FPU_ARCH_FPA),
27336 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
27337 ARM_ARCH_NONE,
27338 FPU_ARCH_FPA),
27339 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
27340 ARM_ARCH_NONE,
27341 FPU_ARCH_FPA),
27342 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
27343 ARM_ARCH_NONE,
27344 FPU_ARCH_FPA),
27345 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
27346 ARM_ARCH_NONE,
27347 FPU_ARCH_FPA),
27348 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
27349 ARM_ARCH_NONE,
27350 FPU_ARCH_FPA),
27351 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
27352 ARM_ARCH_NONE,
27353 FPU_ARCH_FPA),
27354 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
27355 ARM_ARCH_NONE,
27356 FPU_ARCH_FPA),
27357 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
27358 ARM_ARCH_NONE,
27359 FPU_ARCH_FPA),
27360 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
27361 ARM_ARCH_NONE,
27362 FPU_ARCH_FPA),
27363 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
27364 ARM_ARCH_NONE,
27365 FPU_ARCH_FPA),
27366 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
27367 ARM_ARCH_NONE,
27368 FPU_ARCH_FPA),
27370 /* For V5 or later processors we default to using VFP; but the user
27371 should really set the FPU type explicitly. */
27372 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
27373 ARM_ARCH_NONE,
27374 FPU_ARCH_VFP_V2),
27375 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
27376 ARM_ARCH_NONE,
27377 FPU_ARCH_VFP_V2),
27378 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27379 ARM_ARCH_NONE,
27380 FPU_ARCH_VFP_V2),
27381 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
27382 ARM_ARCH_NONE,
27383 FPU_ARCH_VFP_V2),
27384 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
27385 ARM_ARCH_NONE,
27386 FPU_ARCH_VFP_V2),
27387 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
27388 ARM_ARCH_NONE,
27389 FPU_ARCH_VFP_V2),
27390 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
27391 ARM_ARCH_NONE,
27392 FPU_ARCH_VFP_V2),
27393 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
27394 ARM_ARCH_NONE,
27395 FPU_ARCH_VFP_V2),
27396 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
27397 ARM_ARCH_NONE,
27398 FPU_ARCH_VFP_V2),
27399 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
27400 ARM_ARCH_NONE,
27401 FPU_ARCH_VFP_V2),
27402 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
27403 ARM_ARCH_NONE,
27404 FPU_ARCH_VFP_V2),
27405 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
27406 ARM_ARCH_NONE,
27407 FPU_ARCH_VFP_V2),
27408 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
27409 ARM_ARCH_NONE,
27410 FPU_ARCH_VFP_V1),
27411 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
27412 ARM_ARCH_NONE,
27413 FPU_ARCH_VFP_V1),
27414 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
27415 ARM_ARCH_NONE,
27416 FPU_ARCH_VFP_V2),
27417 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
27418 ARM_ARCH_NONE,
27419 FPU_ARCH_VFP_V2),
27420 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
27421 ARM_ARCH_NONE,
27422 FPU_ARCH_VFP_V1),
27423 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
27424 ARM_ARCH_NONE,
27425 FPU_ARCH_VFP_V2),
27426 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
27427 ARM_ARCH_NONE,
27428 FPU_ARCH_VFP_V2),
27429 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
27430 ARM_ARCH_NONE,
27431 FPU_ARCH_VFP_V2),
27432 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
27433 ARM_ARCH_NONE,
27434 FPU_ARCH_VFP_V2),
27435 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
27436 ARM_ARCH_NONE,
27437 FPU_ARCH_VFP_V2),
27438 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
27439 ARM_ARCH_NONE,
27440 FPU_ARCH_VFP_V2),
27441 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
27442 ARM_ARCH_NONE,
27443 FPU_ARCH_VFP_V2),
27444 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
27445 ARM_ARCH_NONE,
27446 FPU_ARCH_VFP_V2),
27447 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
27448 ARM_ARCH_NONE,
27449 FPU_ARCH_VFP_V2),
27450 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
27451 ARM_ARCH_NONE,
27452 FPU_NONE),
27453 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
27454 ARM_ARCH_NONE,
27455 FPU_NONE),
27456 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
27457 ARM_ARCH_NONE,
27458 FPU_ARCH_VFP_V2),
27459 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
27460 ARM_ARCH_NONE,
27461 FPU_ARCH_VFP_V2),
27462 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
27463 ARM_ARCH_NONE,
27464 FPU_ARCH_VFP_V2),
27465 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
27466 ARM_ARCH_NONE,
27467 FPU_NONE),
27468 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
27469 ARM_ARCH_NONE,
27470 FPU_NONE),
27471 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
27472 ARM_ARCH_NONE,
27473 FPU_ARCH_VFP_V2),
27474 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
27475 ARM_ARCH_NONE,
27476 FPU_NONE),
27477 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
27478 ARM_ARCH_NONE,
27479 FPU_ARCH_VFP_V2),
27480 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
27481 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27482 FPU_NONE),
27483 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
27484 ARM_ARCH_NONE,
27485 FPU_ARCH_NEON_VFP_V4),
27486 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
27487 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
27488 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27489 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
27490 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27491 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
27492 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
27493 ARM_ARCH_NONE,
27494 FPU_ARCH_NEON_VFP_V4),
27495 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
27496 ARM_ARCH_NONE,
27497 FPU_ARCH_NEON_VFP_V4),
27498 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
27499 ARM_ARCH_NONE,
27500 FPU_ARCH_NEON_VFP_V4),
27501 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
27502 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27503 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27504 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
27505 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27506 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27507 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
27508 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27509 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27510 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
27511 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27512 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
27513 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
27514 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27515 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27516 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
27517 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27518 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27519 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
27520 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27521 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27522 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
27523 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27524 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
27525 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
27526 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27527 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
27528 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
27529 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27530 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
27531 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
27532 ARM_ARCH_NONE,
27533 FPU_NONE),
27534 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
27535 ARM_ARCH_NONE,
27536 FPU_ARCH_VFP_V3D16),
27537 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
27538 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27539 FPU_NONE),
27540 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
27541 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27542 FPU_ARCH_VFP_V3D16),
27543 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
27544 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
27545 FPU_ARCH_VFP_V3D16),
27546 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
27547 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27548 FPU_ARCH_NEON_VFP_ARMV8),
27549 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
27550 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27551 FPU_NONE),
27552 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
27553 ARM_ARCH_NONE,
27554 FPU_NONE),
27555 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
27556 ARM_ARCH_NONE,
27557 FPU_NONE),
27558 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
27559 ARM_ARCH_NONE,
27560 FPU_NONE),
27561 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
27562 ARM_ARCH_NONE,
27563 FPU_NONE),
27564 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
27565 ARM_ARCH_NONE,
27566 FPU_NONE),
27567 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
27568 ARM_ARCH_NONE,
27569 FPU_NONE),
27570 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
27571 ARM_ARCH_NONE,
27572 FPU_NONE),
27573 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
27574 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27575 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27576 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
27577 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27578 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
27579 /* ??? XSCALE is really an architecture. */
27580 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
27581 ARM_ARCH_NONE,
27582 FPU_ARCH_VFP_V2),
27584 /* ??? iwmmxt is not a processor. */
27585 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
27586 ARM_ARCH_NONE,
27587 FPU_ARCH_VFP_V2),
27588 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
27589 ARM_ARCH_NONE,
27590 FPU_ARCH_VFP_V2),
27591 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
27592 ARM_ARCH_NONE,
27593 FPU_ARCH_VFP_V2),
27595 /* Maverick. */
27596 ARM_CPU_OPT ("ep9312", "ARM920T",
27597 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
27598 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
27600 /* Marvell processors. */
27601 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
27602 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27603 FPU_ARCH_VFP_V3D16),
27604 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
27605 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
27606 FPU_ARCH_NEON_VFP_V4),
27608 /* APM X-Gene family. */
27609 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
27610 ARM_ARCH_NONE,
27611 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27612 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
27613 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27614 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
27616 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
27618 #undef ARM_CPU_OPT
27620 struct arm_ext_table
27622 const char * name;
27623 size_t name_len;
27624 const arm_feature_set merge;
27625 const arm_feature_set clear;
27628 struct arm_arch_option_table
27630 const char * name;
27631 size_t name_len;
27632 const arm_feature_set value;
27633 const arm_feature_set default_fpu;
27634 const struct arm_ext_table * ext_table;
27637 /* Used to add support for +E and +noE extension. */
27638 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
27639 /* Used to add support for a +E extension. */
27640 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
27641 /* Used to add support for a +noE extension. */
27642 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
27644 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
27645 ~0 & ~FPU_ENDIAN_PURE)
27647 static const struct arm_ext_table armv5te_ext_table[] =
27649 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
27650 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27653 static const struct arm_ext_table armv7_ext_table[] =
27655 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27656 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27659 static const struct arm_ext_table armv7ve_ext_table[] =
27661 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
27662 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
27663 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27664 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27665 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27666 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
27667 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27669 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
27670 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27672 /* Aliases for +simd. */
27673 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27675 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27676 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27677 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27679 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27682 static const struct arm_ext_table armv7a_ext_table[] =
27684 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27685 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27686 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
27687 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27688 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
27689 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
27690 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
27692 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
27693 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
27695 /* Aliases for +simd. */
27696 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27697 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
27699 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
27700 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
27702 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
27703 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
27704 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27707 static const struct arm_ext_table armv7r_ext_table[] =
27709 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
27710 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
27711 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
27712 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
27713 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
27714 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
27715 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
27716 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
27717 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27720 static const struct arm_ext_table armv7em_ext_table[] =
27722 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
27723 /* Alias for +fp, used to be known as fpv4-sp-d16. */
27724 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
27725 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
27726 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27727 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
27728 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27731 static const struct arm_ext_table armv8a_ext_table[] =
27733 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27734 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27735 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27736 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27738 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27739 should use the +simd option to turn on FP. */
27740 ARM_REMOVE ("fp", ALL_FP),
27741 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27742 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27743 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27747 static const struct arm_ext_table armv81a_ext_table[] =
27749 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27750 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27751 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27753 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27754 should use the +simd option to turn on FP. */
27755 ARM_REMOVE ("fp", ALL_FP),
27756 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27757 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27758 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27761 static const struct arm_ext_table armv82a_ext_table[] =
27763 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
27764 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
27765 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
27766 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
27767 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27768 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27770 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27771 should use the +simd option to turn on FP. */
27772 ARM_REMOVE ("fp", ALL_FP),
27773 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27774 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27775 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27778 static const struct arm_ext_table armv84a_ext_table[] =
27780 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27781 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27782 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27783 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27785 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27786 should use the +simd option to turn on FP. */
27787 ARM_REMOVE ("fp", ALL_FP),
27788 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
27789 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
27790 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27793 static const struct arm_ext_table armv85a_ext_table[] =
27795 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
27796 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
27797 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
27798 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27800 /* Armv8-a does not allow an FP implementation without SIMD, so the user
27801 should use the +simd option to turn on FP. */
27802 ARM_REMOVE ("fp", ALL_FP),
27803 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27806 static const struct arm_ext_table armv8m_main_ext_table[] =
27808 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27809 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27810 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
27811 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
27812 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27815 static const struct arm_ext_table armv8_1m_main_ext_table[] =
27817 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27818 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
27819 ARM_EXT ("fp",
27820 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27821 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
27822 ALL_FP),
27823 ARM_ADD ("fp.dp",
27824 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27825 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
27826 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
27827 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
27828 ARM_ADD ("mve.fp",
27829 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
27830 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
27831 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
27832 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27835 static const struct arm_ext_table armv8r_ext_table[] =
27837 ARM_ADD ("crc", ARCH_CRC_ARMV8),
27838 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
27839 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27840 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
27841 ARM_REMOVE ("fp", ALL_FP),
27842 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
27843 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
27846 /* This list should, at a minimum, contain all the architecture names
27847 recognized by GCC. */
27848 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
27849 #define ARM_ARCH_OPT2(N, V, DF, ext) \
27850 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
27852 static const struct arm_arch_option_table arm_archs[] =
27854 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
27855 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
27856 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
27857 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
27858 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
27859 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
27860 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
27861 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
27862 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
27863 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
27864 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
27865 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
27866 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
27867 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
27868 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
27869 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
27870 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
27871 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27872 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
27873 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
27874 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
27875 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
27876 kept to preserve existing behaviour. */
27877 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27878 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
27879 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
27880 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
27881 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
27882 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
27883 kept to preserve existing behaviour. */
27884 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
27885 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
27886 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
27887 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
27888 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
27889 /* The official spelling of the ARMv7 profile variants is the dashed form.
27890 Accept the non-dashed form for compatibility with old toolchains. */
27891 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27892 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
27893 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
27894 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
27895 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
27896 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
27897 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
27898 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
27899 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
27900 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
27901 armv8m_main),
27902 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
27903 armv8_1m_main),
27904 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
27905 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
27906 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
27907 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
27908 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
27909 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
27910 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
27911 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
27912 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
27913 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
27914 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
27916 #undef ARM_ARCH_OPT
27918 /* ISA extensions in the co-processor and main instruction set space. */
27920 struct arm_option_extension_value_table
27922 const char * name;
27923 size_t name_len;
27924 const arm_feature_set merge_value;
27925 const arm_feature_set clear_value;
27926 /* List of architectures for which an extension is available. ARM_ARCH_NONE
27927 indicates that an extension is available for all architectures while
27928 ARM_ANY marks an empty entry. */
27929 const arm_feature_set allowed_archs[2];
27932 /* The following table must be in alphabetical order with a NULL last entry. */
27934 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
27935 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
27937 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
27938 use the context sensitive approach using arm_ext_table's. */
27939 static const struct arm_option_extension_value_table arm_extensions[] =
27941 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
27942 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
27943 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
27944 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
27945 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
27946 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
27947 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
27948 ARM_ARCH_V8_2A),
27949 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27950 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
27951 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
27952 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
27953 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
27954 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27955 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
27956 ARM_ARCH_V8_2A),
27957 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27958 | ARM_EXT2_FP16_FML),
27959 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
27960 | ARM_EXT2_FP16_FML),
27961 ARM_ARCH_V8_2A),
27962 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
27963 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
27964 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27965 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
27966 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
27967 Thumb divide instruction. Due to this having the same name as the
27968 previous entry, this will be ignored when doing command-line parsing and
27969 only considered by build attribute selection code. */
27970 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27971 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
27972 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
27973 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
27974 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
27975 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
27976 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
27977 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
27978 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
27979 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
27980 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
27981 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
27982 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
27983 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27984 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
27985 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
27986 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
27987 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
27988 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
27989 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27990 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
27991 ARM_ARCH_V8A),
27992 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
27993 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
27994 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
27995 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
27996 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
27997 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
27998 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
27999 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
28000 ARM_ARCH_V8A),
28001 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
28002 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
28003 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
28004 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
28005 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
28006 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
28007 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
28008 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
28009 | ARM_EXT_DIV),
28010 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
28011 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
28012 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
28013 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
28014 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
28016 #undef ARM_EXT_OPT
28018 /* ISA floating-point and Advanced SIMD extensions. */
28019 struct arm_option_fpu_value_table
28021 const char * name;
28022 const arm_feature_set value;
28025 /* This list should, at a minimum, contain all the fpu names
28026 recognized by GCC. */
28027 static const struct arm_option_fpu_value_table arm_fpus[] =
28029 {"softfpa", FPU_NONE},
28030 {"fpe", FPU_ARCH_FPE},
28031 {"fpe2", FPU_ARCH_FPE},
28032 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
28033 {"fpa", FPU_ARCH_FPA},
28034 {"fpa10", FPU_ARCH_FPA},
28035 {"fpa11", FPU_ARCH_FPA},
28036 {"arm7500fe", FPU_ARCH_FPA},
28037 {"softvfp", FPU_ARCH_VFP},
28038 {"softvfp+vfp", FPU_ARCH_VFP_V2},
28039 {"vfp", FPU_ARCH_VFP_V2},
28040 {"vfp9", FPU_ARCH_VFP_V2},
28041 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
28042 {"vfp10", FPU_ARCH_VFP_V2},
28043 {"vfp10-r0", FPU_ARCH_VFP_V1},
28044 {"vfpxd", FPU_ARCH_VFP_V1xD},
28045 {"vfpv2", FPU_ARCH_VFP_V2},
28046 {"vfpv3", FPU_ARCH_VFP_V3},
28047 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
28048 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
28049 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
28050 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
28051 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
28052 {"arm1020t", FPU_ARCH_VFP_V1},
28053 {"arm1020e", FPU_ARCH_VFP_V2},
28054 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
28055 {"arm1136jf-s", FPU_ARCH_VFP_V2},
28056 {"maverick", FPU_ARCH_MAVERICK},
28057 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
28058 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
28059 {"neon-fp16", FPU_ARCH_NEON_FP16},
28060 {"vfpv4", FPU_ARCH_VFP_V4},
28061 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
28062 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
28063 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
28064 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
28065 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
28066 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
28067 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
28068 {"crypto-neon-fp-armv8",
28069 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
28070 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
28071 {"crypto-neon-fp-armv8.1",
28072 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
28073 {NULL, ARM_ARCH_NONE}
28076 struct arm_option_value_table
28078 const char *name;
28079 long value;
28082 static const struct arm_option_value_table arm_float_abis[] =
28084 {"hard", ARM_FLOAT_ABI_HARD},
28085 {"softfp", ARM_FLOAT_ABI_SOFTFP},
28086 {"soft", ARM_FLOAT_ABI_SOFT},
28087 {NULL, 0}
28090 #ifdef OBJ_ELF
28091 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
28092 static const struct arm_option_value_table arm_eabis[] =
28094 {"gnu", EF_ARM_EABI_UNKNOWN},
28095 {"4", EF_ARM_EABI_VER4},
28096 {"5", EF_ARM_EABI_VER5},
28097 {NULL, 0}
28099 #endif
28101 struct arm_long_option_table
28103 const char * option; /* Substring to match. */
28104 const char * help; /* Help information. */
28105 int (* func) (const char * subopt); /* Function to decode sub-option. */
28106 const char * deprecated; /* If non-null, print this message. */
28109 static bfd_boolean
28110 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
28111 arm_feature_set *ext_set,
28112 const struct arm_ext_table *ext_table)
28114 /* We insist on extensions being specified in alphabetical order, and with
28115 extensions being added before being removed. We achieve this by having
28116 the global ARM_EXTENSIONS table in alphabetical order, and using the
28117 ADDING_VALUE variable to indicate whether we are adding an extension (1)
28118 or removing it (0) and only allowing it to change in the order
28119 -1 -> 1 -> 0. */
28120 const struct arm_option_extension_value_table * opt = NULL;
28121 const arm_feature_set arm_any = ARM_ANY;
28122 int adding_value = -1;
28124 while (str != NULL && *str != 0)
28126 const char *ext;
28127 size_t len;
28129 if (*str != '+')
28131 as_bad (_("invalid architectural extension"));
28132 return FALSE;
28135 str++;
28136 ext = strchr (str, '+');
28138 if (ext != NULL)
28139 len = ext - str;
28140 else
28141 len = strlen (str);
28143 if (len >= 2 && strncmp (str, "no", 2) == 0)
28145 if (adding_value != 0)
28147 adding_value = 0;
28148 opt = arm_extensions;
28151 len -= 2;
28152 str += 2;
28154 else if (len > 0)
28156 if (adding_value == -1)
28158 adding_value = 1;
28159 opt = arm_extensions;
28161 else if (adding_value != 1)
28163 as_bad (_("must specify extensions to add before specifying "
28164 "those to remove"));
28165 return FALSE;
28169 if (len == 0)
28171 as_bad (_("missing architectural extension"));
28172 return FALSE;
28175 gas_assert (adding_value != -1);
28176 gas_assert (opt != NULL);
28178 if (ext_table != NULL)
28180 const struct arm_ext_table * ext_opt = ext_table;
28181 bfd_boolean found = FALSE;
28182 for (; ext_opt->name != NULL; ext_opt++)
28183 if (ext_opt->name_len == len
28184 && strncmp (ext_opt->name, str, len) == 0)
28186 if (adding_value)
28188 if (ARM_FEATURE_ZERO (ext_opt->merge))
28189 /* TODO: Option not supported. When we remove the
28190 legacy table this case should error out. */
28191 continue;
28193 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
28195 else
28197 if (ARM_FEATURE_ZERO (ext_opt->clear))
28198 /* TODO: Option not supported. When we remove the
28199 legacy table this case should error out. */
28200 continue;
28201 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
28203 found = TRUE;
28204 break;
28206 if (found)
28208 str = ext;
28209 continue;
28213 /* Scan over the options table trying to find an exact match. */
28214 for (; opt->name != NULL; opt++)
28215 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
28217 int i, nb_allowed_archs =
28218 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
28219 /* Check we can apply the extension to this architecture. */
28220 for (i = 0; i < nb_allowed_archs; i++)
28222 /* Empty entry. */
28223 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
28224 continue;
28225 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
28226 break;
28228 if (i == nb_allowed_archs)
28230 as_bad (_("extension does not apply to the base architecture"));
28231 return FALSE;
28234 /* Add or remove the extension. */
28235 if (adding_value)
28236 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
28237 else
28238 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
28240 /* Allowing Thumb division instructions for ARMv7 in autodetection
28241 rely on this break so that duplicate extensions (extensions
28242 with the same name as a previous extension in the list) are not
28243 considered for command-line parsing. */
28244 break;
28247 if (opt->name == NULL)
28249 /* Did we fail to find an extension because it wasn't specified in
28250 alphabetical order, or because it does not exist? */
28252 for (opt = arm_extensions; opt->name != NULL; opt++)
28253 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
28254 break;
28256 if (opt->name == NULL)
28257 as_bad (_("unknown architectural extension `%s'"), str);
28258 else
28259 as_bad (_("architectural extensions must be specified in "
28260 "alphabetical order"));
28262 return FALSE;
28264 else
28266 /* We should skip the extension we've just matched the next time
28267 round. */
28268 opt++;
28271 str = ext;
28274 return TRUE;
28277 static bfd_boolean
28278 arm_parse_cpu (const char *str)
28280 const struct arm_cpu_option_table *opt;
28281 const char *ext = strchr (str, '+');
28282 size_t len;
28284 if (ext != NULL)
28285 len = ext - str;
28286 else
28287 len = strlen (str);
28289 if (len == 0)
28291 as_bad (_("missing cpu name `%s'"), str);
28292 return FALSE;
28295 for (opt = arm_cpus; opt->name != NULL; opt++)
28296 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
28298 mcpu_cpu_opt = &opt->value;
28299 if (mcpu_ext_opt == NULL)
28300 mcpu_ext_opt = XNEW (arm_feature_set);
28301 *mcpu_ext_opt = opt->ext;
28302 mcpu_fpu_opt = &opt->default_fpu;
28303 if (opt->canonical_name)
28305 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
28306 strcpy (selected_cpu_name, opt->canonical_name);
28308 else
28310 size_t i;
28312 if (len >= sizeof selected_cpu_name)
28313 len = (sizeof selected_cpu_name) - 1;
28315 for (i = 0; i < len; i++)
28316 selected_cpu_name[i] = TOUPPER (opt->name[i]);
28317 selected_cpu_name[i] = 0;
28320 if (ext != NULL)
28321 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
28323 return TRUE;
28326 as_bad (_("unknown cpu `%s'"), str);
28327 return FALSE;
28330 static bfd_boolean
28331 arm_parse_arch (const char *str)
28333 const struct arm_arch_option_table *opt;
28334 const char *ext = strchr (str, '+');
28335 size_t len;
28337 if (ext != NULL)
28338 len = ext - str;
28339 else
28340 len = strlen (str);
28342 if (len == 0)
28344 as_bad (_("missing architecture name `%s'"), str);
28345 return FALSE;
28348 for (opt = arm_archs; opt->name != NULL; opt++)
28349 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
28351 march_cpu_opt = &opt->value;
28352 if (march_ext_opt == NULL)
28353 march_ext_opt = XNEW (arm_feature_set);
28354 *march_ext_opt = arm_arch_none;
28355 march_fpu_opt = &opt->default_fpu;
28356 strcpy (selected_cpu_name, opt->name);
28358 if (ext != NULL)
28359 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
28360 opt->ext_table);
28362 return TRUE;
28365 as_bad (_("unknown architecture `%s'\n"), str);
28366 return FALSE;
28369 static bfd_boolean
28370 arm_parse_fpu (const char * str)
28372 const struct arm_option_fpu_value_table * opt;
28374 for (opt = arm_fpus; opt->name != NULL; opt++)
28375 if (streq (opt->name, str))
28377 mfpu_opt = &opt->value;
28378 return TRUE;
28381 as_bad (_("unknown floating point format `%s'\n"), str);
28382 return FALSE;
28385 static bfd_boolean
28386 arm_parse_float_abi (const char * str)
28388 const struct arm_option_value_table * opt;
28390 for (opt = arm_float_abis; opt->name != NULL; opt++)
28391 if (streq (opt->name, str))
28393 mfloat_abi_opt = opt->value;
28394 return TRUE;
28397 as_bad (_("unknown floating point abi `%s'\n"), str);
28398 return FALSE;
28401 #ifdef OBJ_ELF
28402 static bfd_boolean
28403 arm_parse_eabi (const char * str)
28405 const struct arm_option_value_table *opt;
28407 for (opt = arm_eabis; opt->name != NULL; opt++)
28408 if (streq (opt->name, str))
28410 meabi_flags = opt->value;
28411 return TRUE;
28413 as_bad (_("unknown EABI `%s'\n"), str);
28414 return FALSE;
28416 #endif
28418 static bfd_boolean
28419 arm_parse_it_mode (const char * str)
28421 bfd_boolean ret = TRUE;
28423 if (streq ("arm", str))
28424 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
28425 else if (streq ("thumb", str))
28426 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
28427 else if (streq ("always", str))
28428 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
28429 else if (streq ("never", str))
28430 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
28431 else
28433 as_bad (_("unknown implicit IT mode `%s', should be "\
28434 "arm, thumb, always, or never."), str);
28435 ret = FALSE;
28438 return ret;
28441 static bfd_boolean
28442 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
28444 codecomposer_syntax = TRUE;
28445 arm_comment_chars[0] = ';';
28446 arm_line_separator_chars[0] = 0;
28447 return TRUE;
28450 struct arm_long_option_table arm_long_opts[] =
28452 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
28453 arm_parse_cpu, NULL},
28454 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
28455 arm_parse_arch, NULL},
28456 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
28457 arm_parse_fpu, NULL},
28458 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
28459 arm_parse_float_abi, NULL},
28460 #ifdef OBJ_ELF
28461 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
28462 arm_parse_eabi, NULL},
28463 #endif
28464 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
28465 arm_parse_it_mode, NULL},
28466 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
28467 arm_ccs_mode, NULL},
28468 {NULL, NULL, 0, NULL}
28472 md_parse_option (int c, const char * arg)
28474 struct arm_option_table *opt;
28475 const struct arm_legacy_option_table *fopt;
28476 struct arm_long_option_table *lopt;
28478 switch (c)
28480 #ifdef OPTION_EB
28481 case OPTION_EB:
28482 target_big_endian = 1;
28483 break;
28484 #endif
28486 #ifdef OPTION_EL
28487 case OPTION_EL:
28488 target_big_endian = 0;
28489 break;
28490 #endif
28492 case OPTION_FIX_V4BX:
28493 fix_v4bx = TRUE;
28494 break;
28496 #ifdef OBJ_ELF
28497 case OPTION_FDPIC:
28498 arm_fdpic = TRUE;
28499 break;
28500 #endif /* OBJ_ELF */
28502 case 'a':
28503 /* Listing option. Just ignore these, we don't support additional
28504 ones. */
28505 return 0;
28507 default:
28508 for (opt = arm_opts; opt->option != NULL; opt++)
28510 if (c == opt->option[0]
28511 && ((arg == NULL && opt->option[1] == 0)
28512 || streq (arg, opt->option + 1)))
28514 /* If the option is deprecated, tell the user. */
28515 if (warn_on_deprecated && opt->deprecated != NULL)
28516 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28517 arg ? arg : "", _(opt->deprecated));
28519 if (opt->var != NULL)
28520 *opt->var = opt->value;
28522 return 1;
28526 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
28528 if (c == fopt->option[0]
28529 && ((arg == NULL && fopt->option[1] == 0)
28530 || streq (arg, fopt->option + 1)))
28532 /* If the option is deprecated, tell the user. */
28533 if (warn_on_deprecated && fopt->deprecated != NULL)
28534 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
28535 arg ? arg : "", _(fopt->deprecated));
28537 if (fopt->var != NULL)
28538 *fopt->var = &fopt->value;
28540 return 1;
28544 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28546 /* These options are expected to have an argument. */
28547 if (c == lopt->option[0]
28548 && arg != NULL
28549 && strncmp (arg, lopt->option + 1,
28550 strlen (lopt->option + 1)) == 0)
28552 /* If the option is deprecated, tell the user. */
28553 if (warn_on_deprecated && lopt->deprecated != NULL)
28554 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
28555 _(lopt->deprecated));
28557 /* Call the sup-option parser. */
28558 return lopt->func (arg + strlen (lopt->option) - 1);
28562 return 0;
28565 return 1;
28568 void
28569 md_show_usage (FILE * fp)
28571 struct arm_option_table *opt;
28572 struct arm_long_option_table *lopt;
28574 fprintf (fp, _(" ARM-specific assembler options:\n"));
28576 for (opt = arm_opts; opt->option != NULL; opt++)
28577 if (opt->help != NULL)
28578 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
28580 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
28581 if (lopt->help != NULL)
28582 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
28584 #ifdef OPTION_EB
28585 fprintf (fp, _("\
28586 -EB assemble code for a big-endian cpu\n"));
28587 #endif
28589 #ifdef OPTION_EL
28590 fprintf (fp, _("\
28591 -EL assemble code for a little-endian cpu\n"));
28592 #endif
28594 fprintf (fp, _("\
28595 --fix-v4bx Allow BX in ARMv4 code\n"));
28597 #ifdef OBJ_ELF
28598 fprintf (fp, _("\
28599 --fdpic generate an FDPIC object file\n"));
28600 #endif /* OBJ_ELF */
28603 #ifdef OBJ_ELF
28605 typedef struct
28607 int val;
28608 arm_feature_set flags;
28609 } cpu_arch_ver_table;
28611 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
28612 chronologically for architectures, with an exception for ARMv6-M and
28613 ARMv6S-M due to legacy reasons. No new architecture should have a
28614 special case. This allows for build attribute selection results to be
28615 stable when new architectures are added. */
28616 static const cpu_arch_ver_table cpu_arch_ver[] =
28618 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
28619 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
28620 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
28621 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
28622 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
28623 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
28624 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
28625 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
28626 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
28627 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
28628 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
28629 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
28630 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
28631 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
28632 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
28633 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
28634 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
28635 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
28636 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
28637 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
28638 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
28639 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
28640 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
28641 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
28643 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
28644 always selected build attributes to match those of ARMv6-M
28645 (resp. ARMv6S-M). However, due to these architectures being a strict
28646 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
28647 would be selected when fully respecting chronology of architectures.
28648 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
28649 move them before ARMv7 architectures. */
28650 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
28651 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
28653 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
28654 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
28655 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
28656 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
28657 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
28658 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
28659 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
28660 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
28661 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
28662 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
28663 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
28664 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
28665 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
28666 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
28667 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
28668 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
28669 {-1, ARM_ARCH_NONE}
28672 /* Set an attribute if it has not already been set by the user. */
28674 static void
28675 aeabi_set_attribute_int (int tag, int value)
28677 if (tag < 1
28678 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28679 || !attributes_set_explicitly[tag])
28680 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
28683 static void
28684 aeabi_set_attribute_string (int tag, const char *value)
28686 if (tag < 1
28687 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
28688 || !attributes_set_explicitly[tag])
28689 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
28692 /* Return whether features in the *NEEDED feature set are available via
28693 extensions for the architecture whose feature set is *ARCH_FSET. */
28695 static bfd_boolean
28696 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
28697 const arm_feature_set *needed)
28699 int i, nb_allowed_archs;
28700 arm_feature_set ext_fset;
28701 const struct arm_option_extension_value_table *opt;
28703 ext_fset = arm_arch_none;
28704 for (opt = arm_extensions; opt->name != NULL; opt++)
28706 /* Extension does not provide any feature we need. */
28707 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
28708 continue;
28710 nb_allowed_archs =
28711 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
28712 for (i = 0; i < nb_allowed_archs; i++)
28714 /* Empty entry. */
28715 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
28716 break;
28718 /* Extension is available, add it. */
28719 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
28720 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
28724 /* Can we enable all features in *needed? */
28725 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
28728 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
28729 a given architecture feature set *ARCH_EXT_FSET including extension feature
28730 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
28731 - if true, check for an exact match of the architecture modulo extensions;
28732 - otherwise, select build attribute value of the first superset
28733 architecture released so that results remains stable when new architectures
28734 are added.
28735 For -march/-mcpu=all the build attribute value of the most featureful
28736 architecture is returned. Tag_CPU_arch_profile result is returned in
28737 PROFILE. */
28739 static int
28740 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
28741 const arm_feature_set *ext_fset,
28742 char *profile, int exact_match)
28744 arm_feature_set arch_fset;
28745 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
28747 /* Select most featureful architecture with all its extensions if building
28748 for -march=all as the feature sets used to set build attributes. */
28749 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
28751 /* Force revisiting of decision for each new architecture. */
28752 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
28753 *profile = 'A';
28754 return TAG_CPU_ARCH_V8;
28757 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
28759 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
28761 arm_feature_set known_arch_fset;
28763 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
28764 if (exact_match)
28766 /* Base architecture match user-specified architecture and
28767 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
28768 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
28770 p_ver_ret = p_ver;
28771 goto found;
28773 /* Base architecture match user-specified architecture only
28774 (eg. ARMv6-M in the same case as above). Record it in case we
28775 find a match with above condition. */
28776 else if (p_ver_ret == NULL
28777 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
28778 p_ver_ret = p_ver;
28780 else
28783 /* Architecture has all features wanted. */
28784 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
28786 arm_feature_set added_fset;
28788 /* Compute features added by this architecture over the one
28789 recorded in p_ver_ret. */
28790 if (p_ver_ret != NULL)
28791 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
28792 p_ver_ret->flags);
28793 /* First architecture that match incl. with extensions, or the
28794 only difference in features over the recorded match is
28795 features that were optional and are now mandatory. */
28796 if (p_ver_ret == NULL
28797 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
28799 p_ver_ret = p_ver;
28800 goto found;
28803 else if (p_ver_ret == NULL)
28805 arm_feature_set needed_ext_fset;
28807 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
28809 /* Architecture has all features needed when using some
28810 extensions. Record it and continue searching in case there
28811 exist an architecture providing all needed features without
28812 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
28813 OS extension). */
28814 if (have_ext_for_needed_feat_p (&known_arch_fset,
28815 &needed_ext_fset))
28816 p_ver_ret = p_ver;
28821 if (p_ver_ret == NULL)
28822 return -1;
28824 found:
28825 /* Tag_CPU_arch_profile. */
28826 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
28827 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
28828 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
28829 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
28830 *profile = 'A';
28831 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
28832 *profile = 'R';
28833 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
28834 *profile = 'M';
28835 else
28836 *profile = '\0';
28837 return p_ver_ret->val;
28840 /* Set the public EABI object attributes. */
28842 static void
28843 aeabi_set_public_attributes (void)
28845 char profile = '\0';
28846 int arch = -1;
28847 int virt_sec = 0;
28848 int fp16_optional = 0;
28849 int skip_exact_match = 0;
28850 arm_feature_set flags, flags_arch, flags_ext;
28852 /* Autodetection mode, choose the architecture based the instructions
28853 actually used. */
28854 if (no_cpu_selected ())
28856 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
28858 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
28859 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
28861 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
28862 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
28864 /* Code run during relaxation relies on selected_cpu being set. */
28865 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
28866 flags_ext = arm_arch_none;
28867 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
28868 selected_ext = flags_ext;
28869 selected_cpu = flags;
28871 /* Otherwise, choose the architecture based on the capabilities of the
28872 requested cpu. */
28873 else
28875 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
28876 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
28877 flags_ext = selected_ext;
28878 flags = selected_cpu;
28880 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
28882 /* Allow the user to override the reported architecture. */
28883 if (!ARM_FEATURE_ZERO (selected_object_arch))
28885 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
28886 flags_ext = arm_arch_none;
28888 else
28889 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
28891 /* When this function is run again after relaxation has happened there is no
28892 way to determine whether an architecture or CPU was specified by the user:
28893 - selected_cpu is set above for relaxation to work;
28894 - march_cpu_opt is not set if only -mcpu or .cpu is used;
28895 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
28896 Therefore, if not in -march=all case we first try an exact match and fall
28897 back to autodetection. */
28898 if (!skip_exact_match)
28899 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
28900 if (arch == -1)
28901 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
28902 if (arch == -1)
28903 as_bad (_("no architecture contains all the instructions used\n"));
28905 /* Tag_CPU_name. */
28906 if (selected_cpu_name[0])
28908 char *q;
28910 q = selected_cpu_name;
28911 if (strncmp (q, "armv", 4) == 0)
28913 int i;
28915 q += 4;
28916 for (i = 0; q[i]; i++)
28917 q[i] = TOUPPER (q[i]);
28919 aeabi_set_attribute_string (Tag_CPU_name, q);
28922 /* Tag_CPU_arch. */
28923 aeabi_set_attribute_int (Tag_CPU_arch, arch);
28925 /* Tag_CPU_arch_profile. */
28926 if (profile != '\0')
28927 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
28929 /* Tag_DSP_extension. */
28930 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
28931 aeabi_set_attribute_int (Tag_DSP_extension, 1);
28933 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
28934 /* Tag_ARM_ISA_use. */
28935 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
28936 || ARM_FEATURE_ZERO (flags_arch))
28937 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
28939 /* Tag_THUMB_ISA_use. */
28940 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
28941 || ARM_FEATURE_ZERO (flags_arch))
28943 int thumb_isa_use;
28945 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
28946 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
28947 thumb_isa_use = 3;
28948 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
28949 thumb_isa_use = 2;
28950 else
28951 thumb_isa_use = 1;
28952 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
28955 /* Tag_VFP_arch. */
28956 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
28957 aeabi_set_attribute_int (Tag_VFP_arch,
28958 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28959 ? 7 : 8);
28960 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
28961 aeabi_set_attribute_int (Tag_VFP_arch,
28962 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
28963 ? 5 : 6);
28964 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
28966 fp16_optional = 1;
28967 aeabi_set_attribute_int (Tag_VFP_arch, 3);
28969 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
28971 aeabi_set_attribute_int (Tag_VFP_arch, 4);
28972 fp16_optional = 1;
28974 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
28975 aeabi_set_attribute_int (Tag_VFP_arch, 2);
28976 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
28977 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
28978 aeabi_set_attribute_int (Tag_VFP_arch, 1);
28980 /* Tag_ABI_HardFP_use. */
28981 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
28982 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
28983 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
28985 /* Tag_WMMX_arch. */
28986 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
28987 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
28988 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
28989 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
28991 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
28992 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
28993 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
28994 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
28995 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
28996 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
28998 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
29000 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
29002 else
29004 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
29005 fp16_optional = 1;
29009 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
29010 aeabi_set_attribute_int (Tag_MVE_arch, 2);
29011 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
29012 aeabi_set_attribute_int (Tag_MVE_arch, 1);
29014 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
29015 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
29016 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
29018 /* Tag_DIV_use.
29020 We set Tag_DIV_use to two when integer divide instructions have been used
29021 in ARM state, or when Thumb integer divide instructions have been used,
29022 but we have no architecture profile set, nor have we any ARM instructions.
29024 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
29025 by the base architecture.
29027 For new architectures we will have to check these tests. */
29028 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
29029 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
29030 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
29031 aeabi_set_attribute_int (Tag_DIV_use, 0);
29032 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
29033 || (profile == '\0'
29034 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
29035 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
29036 aeabi_set_attribute_int (Tag_DIV_use, 2);
29038 /* Tag_MP_extension_use. */
29039 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
29040 aeabi_set_attribute_int (Tag_MPextension_use, 1);
29042 /* Tag Virtualization_use. */
29043 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
29044 virt_sec |= 1;
29045 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
29046 virt_sec |= 2;
29047 if (virt_sec != 0)
29048 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
29051 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
29052 finished and free extension feature bits which will not be used anymore. */
29054 void
29055 arm_md_post_relax (void)
29057 aeabi_set_public_attributes ();
29058 XDELETE (mcpu_ext_opt);
29059 mcpu_ext_opt = NULL;
29060 XDELETE (march_ext_opt);
29061 march_ext_opt = NULL;
29064 /* Add the default contents for the .ARM.attributes section. */
29066 void
29067 arm_md_end (void)
29069 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
29070 return;
29072 aeabi_set_public_attributes ();
29074 #endif /* OBJ_ELF */
29076 /* Parse a .cpu directive. */
29078 static void
29079 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
29081 const struct arm_cpu_option_table *opt;
29082 char *name;
29083 char saved_char;
29085 name = input_line_pointer;
29086 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29087 input_line_pointer++;
29088 saved_char = *input_line_pointer;
29089 *input_line_pointer = 0;
29091 /* Skip the first "all" entry. */
29092 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
29093 if (streq (opt->name, name))
29095 selected_arch = opt->value;
29096 selected_ext = opt->ext;
29097 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
29098 if (opt->canonical_name)
29099 strcpy (selected_cpu_name, opt->canonical_name);
29100 else
29102 int i;
29103 for (i = 0; opt->name[i]; i++)
29104 selected_cpu_name[i] = TOUPPER (opt->name[i]);
29106 selected_cpu_name[i] = 0;
29108 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29110 *input_line_pointer = saved_char;
29111 demand_empty_rest_of_line ();
29112 return;
29114 as_bad (_("unknown cpu `%s'"), name);
29115 *input_line_pointer = saved_char;
29116 ignore_rest_of_line ();
29119 /* Parse a .arch directive. */
29121 static void
29122 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
29124 const struct arm_arch_option_table *opt;
29125 char saved_char;
29126 char *name;
29128 name = input_line_pointer;
29129 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29130 input_line_pointer++;
29131 saved_char = *input_line_pointer;
29132 *input_line_pointer = 0;
29134 /* Skip the first "all" entry. */
29135 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29136 if (streq (opt->name, name))
29138 selected_arch = opt->value;
29139 selected_ext = arm_arch_none;
29140 selected_cpu = selected_arch;
29141 strcpy (selected_cpu_name, opt->name);
29142 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29143 *input_line_pointer = saved_char;
29144 demand_empty_rest_of_line ();
29145 return;
29148 as_bad (_("unknown architecture `%s'\n"), name);
29149 *input_line_pointer = saved_char;
29150 ignore_rest_of_line ();
29153 /* Parse a .object_arch directive. */
29155 static void
29156 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
29158 const struct arm_arch_option_table *opt;
29159 char saved_char;
29160 char *name;
29162 name = input_line_pointer;
29163 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29164 input_line_pointer++;
29165 saved_char = *input_line_pointer;
29166 *input_line_pointer = 0;
29168 /* Skip the first "all" entry. */
29169 for (opt = arm_archs + 1; opt->name != NULL; opt++)
29170 if (streq (opt->name, name))
29172 selected_object_arch = opt->value;
29173 *input_line_pointer = saved_char;
29174 demand_empty_rest_of_line ();
29175 return;
29178 as_bad (_("unknown architecture `%s'\n"), name);
29179 *input_line_pointer = saved_char;
29180 ignore_rest_of_line ();
29183 /* Parse a .arch_extension directive. */
29185 static void
29186 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
29188 const struct arm_option_extension_value_table *opt;
29189 char saved_char;
29190 char *name;
29191 int adding_value = 1;
29193 name = input_line_pointer;
29194 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29195 input_line_pointer++;
29196 saved_char = *input_line_pointer;
29197 *input_line_pointer = 0;
29199 if (strlen (name) >= 2
29200 && strncmp (name, "no", 2) == 0)
29202 adding_value = 0;
29203 name += 2;
29206 for (opt = arm_extensions; opt->name != NULL; opt++)
29207 if (streq (opt->name, name))
29209 int i, nb_allowed_archs =
29210 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
29211 for (i = 0; i < nb_allowed_archs; i++)
29213 /* Empty entry. */
29214 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
29215 continue;
29216 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
29217 break;
29220 if (i == nb_allowed_archs)
29222 as_bad (_("architectural extension `%s' is not allowed for the "
29223 "current base architecture"), name);
29224 break;
29227 if (adding_value)
29228 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
29229 opt->merge_value);
29230 else
29231 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
29233 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
29234 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29235 *input_line_pointer = saved_char;
29236 demand_empty_rest_of_line ();
29237 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
29238 on this return so that duplicate extensions (extensions with the
29239 same name as a previous extension in the list) are not considered
29240 for command-line parsing. */
29241 return;
29244 if (opt->name == NULL)
29245 as_bad (_("unknown architecture extension `%s'\n"), name);
29247 *input_line_pointer = saved_char;
29248 ignore_rest_of_line ();
29251 /* Parse a .fpu directive. */
29253 static void
29254 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
29256 const struct arm_option_fpu_value_table *opt;
29257 char saved_char;
29258 char *name;
29260 name = input_line_pointer;
29261 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
29262 input_line_pointer++;
29263 saved_char = *input_line_pointer;
29264 *input_line_pointer = 0;
29266 for (opt = arm_fpus; opt->name != NULL; opt++)
29267 if (streq (opt->name, name))
29269 selected_fpu = opt->value;
29270 #ifndef CPU_DEFAULT
29271 if (no_cpu_selected ())
29272 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
29273 else
29274 #endif
29275 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29276 *input_line_pointer = saved_char;
29277 demand_empty_rest_of_line ();
29278 return;
29281 as_bad (_("unknown floating point format `%s'\n"), name);
29282 *input_line_pointer = saved_char;
29283 ignore_rest_of_line ();
29286 /* Copy symbol information. */
29288 void
29289 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
29291 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
29294 #ifdef OBJ_ELF
29295 /* Given a symbolic attribute NAME, return the proper integer value.
29296 Returns -1 if the attribute is not known. */
29299 arm_convert_symbolic_attribute (const char *name)
29301 static const struct
29303 const char * name;
29304 const int tag;
29306 attribute_table[] =
29308 /* When you modify this table you should
29309 also modify the list in doc/c-arm.texi. */
29310 #define T(tag) {#tag, tag}
29311 T (Tag_CPU_raw_name),
29312 T (Tag_CPU_name),
29313 T (Tag_CPU_arch),
29314 T (Tag_CPU_arch_profile),
29315 T (Tag_ARM_ISA_use),
29316 T (Tag_THUMB_ISA_use),
29317 T (Tag_FP_arch),
29318 T (Tag_VFP_arch),
29319 T (Tag_WMMX_arch),
29320 T (Tag_Advanced_SIMD_arch),
29321 T (Tag_PCS_config),
29322 T (Tag_ABI_PCS_R9_use),
29323 T (Tag_ABI_PCS_RW_data),
29324 T (Tag_ABI_PCS_RO_data),
29325 T (Tag_ABI_PCS_GOT_use),
29326 T (Tag_ABI_PCS_wchar_t),
29327 T (Tag_ABI_FP_rounding),
29328 T (Tag_ABI_FP_denormal),
29329 T (Tag_ABI_FP_exceptions),
29330 T (Tag_ABI_FP_user_exceptions),
29331 T (Tag_ABI_FP_number_model),
29332 T (Tag_ABI_align_needed),
29333 T (Tag_ABI_align8_needed),
29334 T (Tag_ABI_align_preserved),
29335 T (Tag_ABI_align8_preserved),
29336 T (Tag_ABI_enum_size),
29337 T (Tag_ABI_HardFP_use),
29338 T (Tag_ABI_VFP_args),
29339 T (Tag_ABI_WMMX_args),
29340 T (Tag_ABI_optimization_goals),
29341 T (Tag_ABI_FP_optimization_goals),
29342 T (Tag_compatibility),
29343 T (Tag_CPU_unaligned_access),
29344 T (Tag_FP_HP_extension),
29345 T (Tag_VFP_HP_extension),
29346 T (Tag_ABI_FP_16bit_format),
29347 T (Tag_MPextension_use),
29348 T (Tag_DIV_use),
29349 T (Tag_nodefaults),
29350 T (Tag_also_compatible_with),
29351 T (Tag_conformance),
29352 T (Tag_T2EE_use),
29353 T (Tag_Virtualization_use),
29354 T (Tag_DSP_extension),
29355 T (Tag_MVE_arch),
29356 /* We deliberately do not include Tag_MPextension_use_legacy. */
29357 #undef T
29359 unsigned int i;
29361 if (name == NULL)
29362 return -1;
29364 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
29365 if (streq (name, attribute_table[i].name))
29366 return attribute_table[i].tag;
29368 return -1;
29371 /* Apply sym value for relocations only in the case that they are for
29372 local symbols in the same segment as the fixup and you have the
29373 respective architectural feature for blx and simple switches. */
29376 arm_apply_sym_value (struct fix * fixP, segT this_seg)
29378 if (fixP->fx_addsy
29379 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
29380 /* PR 17444: If the local symbol is in a different section then a reloc
29381 will always be generated for it, so applying the symbol value now
29382 will result in a double offset being stored in the relocation. */
29383 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
29384 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
29386 switch (fixP->fx_r_type)
29388 case BFD_RELOC_ARM_PCREL_BLX:
29389 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29390 if (ARM_IS_FUNC (fixP->fx_addsy))
29391 return 1;
29392 break;
29394 case BFD_RELOC_ARM_PCREL_CALL:
29395 case BFD_RELOC_THUMB_PCREL_BLX:
29396 if (THUMB_IS_FUNC (fixP->fx_addsy))
29397 return 1;
29398 break;
29400 default:
29401 break;
29405 return 0;
29407 #endif /* OBJ_ELF */