Add generic and ARM specific support for half-precision IEEE 754 floating point numbe...
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
82704155 2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
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
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
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
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
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
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
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. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
18a20338
CL
78/* Whether --fdpic was given. */
79static int arm_fdpic;
80
8b1ad454
NC
81#endif /* OBJ_ELF */
82
4962c51a
MS
83/* Results from operand parsing worker functions. */
84
85typedef enum
86{
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90} parse_operand_result;
91
33a392fb
PB
92enum arm_float_abi
93{
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97};
98
c19d1205 99/* Types of processor to assemble for. */
b99bd4ef 100#ifndef CPU_DEFAULT
8a59fff3 101/* The code that was here used to select a default CPU depending on compiler
fa94de6b 102 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
b99bd4ef
NC
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
4d354d8b
TP
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. */
e74cfd16 132static arm_feature_set cpu_variant;
4d354d8b
TP
133/* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
2e6976a8
DG
148/* Understand CodeComposer Studio assembly syntax. */
149bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
150
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. */
4d354d8b
TP
154
155/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157static const arm_feature_set *legacy_cpu = NULL;
158static const arm_feature_set *legacy_fpu = NULL;
159
160/* CPU, extension and FPU feature bits selected by -mcpu. */
161static const arm_feature_set *mcpu_cpu_opt = NULL;
162static arm_feature_set *mcpu_ext_opt = NULL;
163static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165/* CPU, extension and FPU feature bits selected by -march. */
166static const arm_feature_set *march_cpu_opt = NULL;
167static arm_feature_set *march_ext_opt = NULL;
168static const arm_feature_set *march_fpu_opt = NULL;
169
170/* Feature bits selected by -mfpu. */
171static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
172
173/* Constants for known architecture features. */
174static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 175static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 176static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
177static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
179static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 181#ifdef OBJ_ELF
e74cfd16 182static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 183#endif
e74cfd16
PB
184static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186#ifdef CPU_DEFAULT
187static const arm_feature_set cpu_default = CPU_DEFAULT;
188#endif
189
823d2571 190static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 191static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
192static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 198static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
207/* Only for compatability of hint instructions. */
208static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
210static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 222#ifdef OBJ_ELF
e7d39ed3 223static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 224#endif
823d2571 225static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 226static const arm_feature_set arm_ext_m =
173205ca 227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
229static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 234static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 235static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
236static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
238static const arm_feature_set arm_ext_v8_1m_main =
239ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
240/* Instructions in ARMv8-M only found in M profile architectures. */
241static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
243static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
245/* Instructions shared between ARMv8-A and ARMv8-M. */
246static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 248#ifdef OBJ_ELF
15afaa63
TP
249/* DSP instructions Tag_DSP_extension refers to. */
250static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 252#endif
4d1464f2
MW
253static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
255/* FP16 instructions. */
256static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
258static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
260static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
262static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
264static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
266static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
268
269static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 270#ifdef OBJ_ELF
2c6b98ea 271static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 272#endif
f85d59c3 273static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
274static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
2d447fca 277static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 279static const arm_feature_set arm_cext_iwmmxt =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 281static const arm_feature_set arm_cext_xscale =
823d2571 282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 283static const arm_feature_set arm_cext_maverick =
823d2571
TG
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 289static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 299static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 303static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c
AV
305static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
69c9e028 309#ifdef OBJ_ELF
823d2571
TG
310static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 314#endif
823d2571
TG
315static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 317static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 319static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 321static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 323static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 325static const arm_feature_set crc_ext_armv8 =
823d2571 326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 327static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
329static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 331
33a392fb 332static int mfloat_abi_opt = -1;
4d354d8b
TP
333/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335static arm_feature_set selected_arch = ARM_ARCH_NONE;
336/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338static 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. */
e74cfd16 342static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
343/* FPU feature bits selected by the last -mfpu or .fpu directive. */
344static arm_feature_set selected_fpu = FPU_NONE;
345/* Feature bits selected by the last .object_arch directive. */
346static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 347/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 348static char selected_cpu_name[20];
8d67f500 349
aacf0b33
KT
350extern FLONUM_TYPE generic_floating_point_number;
351
8d67f500
NC
352/* Return if no cpu was selected on command-line. */
353static bfd_boolean
354no_cpu_selected (void)
355{
823d2571 356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
357}
358
7cc69913 359#ifdef OBJ_ELF
deeaaff8
DJ
360# ifdef EABI_DEFAULT
361static int meabi_flags = EABI_DEFAULT;
362# else
d507cf36 363static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 364# endif
e1da3f5b 365
ee3c0378
AS
366static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
367
e1da3f5b 368bfd_boolean
5f4273c7 369arm_is_eabi (void)
e1da3f5b
PB
370{
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
372}
7cc69913 373#endif
b99bd4ef 374
b99bd4ef 375#ifdef OBJ_ELF
c19d1205 376/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
377symbolS * GOT_symbol;
378#endif
379
b99bd4ef
NC
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. */
384static int thumb_mode = 0;
8dc2430f
NC
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)
b99bd4ef 389
e07e6e58
NC
390/* Specifies the intrinsic IT insn behavior mode. */
391enum implicit_it_mode
392{
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)
397};
398static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
399
c19d1205
ZW
400/* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
402
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.
411
412 Important differences from the old Thumb mode:
413
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. */
422
423static bfd_boolean unified_syntax = FALSE;
b99bd4ef 424
bacebabc
RM
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
477330fc
RM
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. */
429const char arm_symbol_chars[] = "#[]{}";
bacebabc 430
5287ad62
JB
431enum neon_el_type
432{
dcbf9037 433 NT_invtype,
5287ad62
JB
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
dcbf9037 439 NT_unsigned
5287ad62
JB
440};
441
442struct neon_type_el
443{
444 enum neon_el_type type;
445 unsigned size;
446};
447
448#define NEON_MAX_TYPE_ELS 4
449
450struct neon_type
451{
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
454};
455
5ee91343 456enum pred_instruction_type
e07e6e58 457{
5ee91343
AV
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
e07e6e58
NC
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 463 if inside, should be the last one. */
e07e6e58 464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 465 i.e. BKPT and NOP. */
5ee91343
AV
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 468 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 469 a predication code. */
35c228db 470 MVE_UNPREDICABLE_INSN /* MVE instruction that is non-predicable. */
e07e6e58
NC
471};
472
ad6cec43
MGD
473/* The maximum number of operands we need. */
474#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 475#define ARM_IT_MAX_RELOCS 3
ad6cec43 476
b99bd4ef
NC
477struct arm_it
478{
c19d1205 479 const char * error;
b99bd4ef 480 unsigned long instruction;
c19d1205
ZW
481 int size;
482 int size_req;
483 int cond;
037e8744
JB
484 /* "uncond_value" is set to the value in place of the conditional field in
485 unconditional versions of the instruction, or -1 if nothing is
486 appropriate. */
487 int uncond_value;
5287ad62 488 struct neon_type vectype;
88714cb8
DG
489 /* This does not indicate an actual NEON instruction, only that
490 the mnemonic accepts neon-style type suffixes. */
491 int is_neon;
0110f2b8
PB
492 /* Set to the opcode if the instruction needs relaxation.
493 Zero if the instruction is not relaxed. */
494 unsigned long relax;
b99bd4ef
NC
495 struct
496 {
497 bfd_reloc_code_real_type type;
c19d1205
ZW
498 expressionS exp;
499 int pc_rel;
e2b0ab59 500 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 501
5ee91343 502 enum pred_instruction_type pred_insn_type;
e07e6e58 503
c19d1205
ZW
504 struct
505 {
506 unsigned reg;
ca3f61f7 507 signed int imm;
dcbf9037 508 struct neon_type_el vectype;
ca3f61f7
NC
509 unsigned present : 1; /* Operand present. */
510 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
511 unsigned immisreg : 2; /* .imm field is a second register.
512 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
513 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
514 0) not scalar,
515 1) Neon scalar,
516 2) MVE scalar. */
5287ad62 517 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 518 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
519 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
520 instructions. This allows us to disambiguate ARM <-> vector insns. */
521 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 522 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 523 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 524 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 525 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
526 unsigned hasreloc : 1; /* Operand has relocation suffix. */
527 unsigned writeback : 1; /* Operand has trailing ! */
528 unsigned preind : 1; /* Preindexed address. */
529 unsigned postind : 1; /* Postindexed address. */
530 unsigned negative : 1; /* Index register was negated. */
531 unsigned shifted : 1; /* Shift applied to operation. */
532 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 533 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
534};
535
c19d1205 536static struct arm_it inst;
b99bd4ef
NC
537
538#define NUM_FLOAT_VALS 8
539
05d2d07e 540const char * fp_const[] =
b99bd4ef
NC
541{
542 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
543};
544
b99bd4ef
NC
545LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
546
547#define FAIL (-1)
548#define SUCCESS (0)
549
550#define SUFF_S 1
551#define SUFF_D 2
552#define SUFF_E 3
553#define SUFF_P 4
554
c19d1205
ZW
555#define CP_T_X 0x00008000
556#define CP_T_Y 0x00400000
b99bd4ef 557
c19d1205
ZW
558#define CONDS_BIT 0x00100000
559#define LOAD_BIT 0x00100000
b99bd4ef
NC
560
561#define DOUBLE_LOAD_FLAG 0x00000001
562
563struct asm_cond
564{
d3ce72d0 565 const char * template_name;
c921be7d 566 unsigned long value;
b99bd4ef
NC
567};
568
c19d1205 569#define COND_ALWAYS 0xE
b99bd4ef 570
b99bd4ef
NC
571struct asm_psr
572{
d3ce72d0 573 const char * template_name;
c921be7d 574 unsigned long field;
b99bd4ef
NC
575};
576
62b3e311
PB
577struct asm_barrier_opt
578{
e797f7e0
MGD
579 const char * template_name;
580 unsigned long value;
581 const arm_feature_set arch;
62b3e311
PB
582};
583
2d2255b5 584/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
585#define SPSR_BIT (1 << 22)
586
c19d1205
ZW
587/* The individual PSR flag bits. */
588#define PSR_c (1 << 16)
589#define PSR_x (1 << 17)
590#define PSR_s (1 << 18)
591#define PSR_f (1 << 19)
b99bd4ef 592
c19d1205 593struct reloc_entry
bfae80f2 594{
0198d5e6 595 const char * name;
c921be7d 596 bfd_reloc_code_real_type reloc;
bfae80f2
RE
597};
598
5287ad62 599enum vfp_reg_pos
bfae80f2 600{
5287ad62
JB
601 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
602 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
603};
604
605enum vfp_ldstm_type
606{
607 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
608};
609
dcbf9037
JB
610/* Bits for DEFINED field in neon_typed_alias. */
611#define NTA_HASTYPE 1
612#define NTA_HASINDEX 2
613
614struct neon_typed_alias
615{
c921be7d
NC
616 unsigned char defined;
617 unsigned char index;
618 struct neon_type_el eltype;
dcbf9037
JB
619};
620
c19d1205 621/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
622 architecture extensions' registers. Each entry should have an error message
623 in reg_expected_msgs below. */
c19d1205 624enum arm_reg_type
bfae80f2 625{
c19d1205
ZW
626 REG_TYPE_RN,
627 REG_TYPE_CP,
628 REG_TYPE_CN,
629 REG_TYPE_FN,
630 REG_TYPE_VFS,
631 REG_TYPE_VFD,
5287ad62 632 REG_TYPE_NQ,
037e8744 633 REG_TYPE_VFSD,
5287ad62 634 REG_TYPE_NDQ,
dec41383 635 REG_TYPE_NSD,
037e8744 636 REG_TYPE_NSDQ,
c19d1205
ZW
637 REG_TYPE_VFC,
638 REG_TYPE_MVF,
639 REG_TYPE_MVD,
640 REG_TYPE_MVFX,
641 REG_TYPE_MVDX,
642 REG_TYPE_MVAX,
5ee91343 643 REG_TYPE_MQ,
c19d1205
ZW
644 REG_TYPE_DSPSC,
645 REG_TYPE_MMXWR,
646 REG_TYPE_MMXWC,
647 REG_TYPE_MMXWCG,
648 REG_TYPE_XSCALE,
5ee91343 649 REG_TYPE_RNB,
1b883319 650 REG_TYPE_ZR
bfae80f2
RE
651};
652
dcbf9037
JB
653/* Structure for a hash table entry for a register.
654 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
655 information which states whether a vector type or index is specified (for a
656 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
657struct reg_entry
658{
c921be7d 659 const char * name;
90ec0d68 660 unsigned int number;
c921be7d
NC
661 unsigned char type;
662 unsigned char builtin;
663 struct neon_typed_alias * neon;
6c43fab6
RE
664};
665
c19d1205 666/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 667const char * const reg_expected_msgs[] =
c19d1205 668{
5aa75429
TP
669 [REG_TYPE_RN] = N_("ARM register expected"),
670 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
671 [REG_TYPE_CN] = N_("co-processor register expected"),
672 [REG_TYPE_FN] = N_("FPA register expected"),
673 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
674 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
675 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
676 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
677 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
678 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
679 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
680 " expected"),
681 [REG_TYPE_VFC] = N_("VFP system register expected"),
682 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
683 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
684 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
685 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
686 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
687 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
688 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
689 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
690 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
691 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 692 [REG_TYPE_MQ] = N_("MVE vector register expected"),
5aa75429 693 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
694};
695
c19d1205 696/* Some well known registers that we refer to directly elsewhere. */
bd340a04 697#define REG_R12 12
c19d1205
ZW
698#define REG_SP 13
699#define REG_LR 14
700#define REG_PC 15
404ff6b5 701
b99bd4ef
NC
702/* ARM instructions take 4bytes in the object file, Thumb instructions
703 take 2: */
c19d1205 704#define INSN_SIZE 4
b99bd4ef
NC
705
706struct asm_opcode
707{
708 /* Basic string to match. */
d3ce72d0 709 const char * template_name;
c19d1205
ZW
710
711 /* Parameters to instruction. */
5be8be5d 712 unsigned int operands[8];
c19d1205
ZW
713
714 /* Conditional tag - see opcode_lookup. */
715 unsigned int tag : 4;
b99bd4ef
NC
716
717 /* Basic instruction code. */
a302e574 718 unsigned int avalue;
b99bd4ef 719
c19d1205
ZW
720 /* Thumb-format instruction code. */
721 unsigned int tvalue;
b99bd4ef 722
90e4755a 723 /* Which architecture variant provides this instruction. */
c921be7d
NC
724 const arm_feature_set * avariant;
725 const arm_feature_set * tvariant;
c19d1205
ZW
726
727 /* Function to call to encode instruction in ARM format. */
728 void (* aencode) (void);
b99bd4ef 729
c19d1205
ZW
730 /* Function to call to encode instruction in Thumb format. */
731 void (* tencode) (void);
5ee91343
AV
732
733 /* Indicates whether this instruction may be vector predicated. */
734 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
735};
736
a737bd4d
NC
737/* Defines for various bits that we will want to toggle. */
738#define INST_IMMEDIATE 0x02000000
739#define OFFSET_REG 0x02000000
c19d1205 740#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
741#define SHIFT_BY_REG 0x00000010
742#define PRE_INDEX 0x01000000
743#define INDEX_UP 0x00800000
744#define WRITE_BACK 0x00200000
745#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 746#define CPSI_MMOD 0x00020000
90e4755a 747
a737bd4d
NC
748#define LITERAL_MASK 0xf000f000
749#define OPCODE_MASK 0xfe1fffff
750#define V4_STR_BIT 0x00000020
8335d6aa 751#define VLDR_VMOV_SAME 0x0040f000
90e4755a 752
efd81785
PB
753#define T2_SUBS_PC_LR 0xf3de8f00
754
a737bd4d 755#define DATA_OP_SHIFT 21
bada4342 756#define SBIT_SHIFT 20
90e4755a 757
ef8d22e6
PB
758#define T2_OPCODE_MASK 0xfe1fffff
759#define T2_DATA_OP_SHIFT 21
bada4342 760#define T2_SBIT_SHIFT 20
ef8d22e6 761
6530b175
NC
762#define A_COND_MASK 0xf0000000
763#define A_PUSH_POP_OP_MASK 0x0fff0000
764
765/* Opcodes for pushing/poping registers to/from the stack. */
766#define A1_OPCODE_PUSH 0x092d0000
767#define A2_OPCODE_PUSH 0x052d0004
768#define A2_OPCODE_POP 0x049d0004
769
a737bd4d
NC
770/* Codes to distinguish the arithmetic instructions. */
771#define OPCODE_AND 0
772#define OPCODE_EOR 1
773#define OPCODE_SUB 2
774#define OPCODE_RSB 3
775#define OPCODE_ADD 4
776#define OPCODE_ADC 5
777#define OPCODE_SBC 6
778#define OPCODE_RSC 7
779#define OPCODE_TST 8
780#define OPCODE_TEQ 9
781#define OPCODE_CMP 10
782#define OPCODE_CMN 11
783#define OPCODE_ORR 12
784#define OPCODE_MOV 13
785#define OPCODE_BIC 14
786#define OPCODE_MVN 15
90e4755a 787
ef8d22e6
PB
788#define T2_OPCODE_AND 0
789#define T2_OPCODE_BIC 1
790#define T2_OPCODE_ORR 2
791#define T2_OPCODE_ORN 3
792#define T2_OPCODE_EOR 4
793#define T2_OPCODE_ADD 8
794#define T2_OPCODE_ADC 10
795#define T2_OPCODE_SBC 11
796#define T2_OPCODE_SUB 13
797#define T2_OPCODE_RSB 14
798
a737bd4d
NC
799#define T_OPCODE_MUL 0x4340
800#define T_OPCODE_TST 0x4200
801#define T_OPCODE_CMN 0x42c0
802#define T_OPCODE_NEG 0x4240
803#define T_OPCODE_MVN 0x43c0
90e4755a 804
a737bd4d
NC
805#define T_OPCODE_ADD_R3 0x1800
806#define T_OPCODE_SUB_R3 0x1a00
807#define T_OPCODE_ADD_HI 0x4400
808#define T_OPCODE_ADD_ST 0xb000
809#define T_OPCODE_SUB_ST 0xb080
810#define T_OPCODE_ADD_SP 0xa800
811#define T_OPCODE_ADD_PC 0xa000
812#define T_OPCODE_ADD_I8 0x3000
813#define T_OPCODE_SUB_I8 0x3800
814#define T_OPCODE_ADD_I3 0x1c00
815#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 816
a737bd4d
NC
817#define T_OPCODE_ASR_R 0x4100
818#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
819#define T_OPCODE_LSR_R 0x40c0
820#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
821#define T_OPCODE_ASR_I 0x1000
822#define T_OPCODE_LSL_I 0x0000
823#define T_OPCODE_LSR_I 0x0800
b99bd4ef 824
a737bd4d
NC
825#define T_OPCODE_MOV_I8 0x2000
826#define T_OPCODE_CMP_I8 0x2800
827#define T_OPCODE_CMP_LR 0x4280
828#define T_OPCODE_MOV_HR 0x4600
829#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 830
a737bd4d
NC
831#define T_OPCODE_LDR_PC 0x4800
832#define T_OPCODE_LDR_SP 0x9800
833#define T_OPCODE_STR_SP 0x9000
834#define T_OPCODE_LDR_IW 0x6800
835#define T_OPCODE_STR_IW 0x6000
836#define T_OPCODE_LDR_IH 0x8800
837#define T_OPCODE_STR_IH 0x8000
838#define T_OPCODE_LDR_IB 0x7800
839#define T_OPCODE_STR_IB 0x7000
840#define T_OPCODE_LDR_RW 0x5800
841#define T_OPCODE_STR_RW 0x5000
842#define T_OPCODE_LDR_RH 0x5a00
843#define T_OPCODE_STR_RH 0x5200
844#define T_OPCODE_LDR_RB 0x5c00
845#define T_OPCODE_STR_RB 0x5400
c9b604bd 846
a737bd4d
NC
847#define T_OPCODE_PUSH 0xb400
848#define T_OPCODE_POP 0xbc00
b99bd4ef 849
2fc8bdac 850#define T_OPCODE_BRANCH 0xe000
b99bd4ef 851
a737bd4d 852#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 853#define THUMB_PP_PC_LR 0x0100
c19d1205 854#define THUMB_LOAD_BIT 0x0800
53365c0d 855#define THUMB2_LOAD_BIT 0x00100000
c19d1205 856
5ee91343 857#define BAD_SYNTAX _("syntax error")
c19d1205 858#define BAD_ARGS _("bad arguments to instruction")
fdfde340 859#define BAD_SP _("r13 not allowed here")
c19d1205 860#define BAD_PC _("r15 not allowed here")
a302e574
AV
861#define BAD_ODD _("Odd register not allowed here")
862#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
863#define BAD_COND _("instruction cannot be conditional")
864#define BAD_OVERLAP _("registers may not be the same")
865#define BAD_HIREG _("lo register required")
866#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 867#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 868#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 869#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
dfa9f0d5 870#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 871#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 872#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 873#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
874#define BAD_OUT_VPT \
875 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 876#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 877#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 878#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 879#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
880#define BAD_PC_ADDRESSING \
881 _("cannot use register index with PC-relative addressing")
882#define BAD_PC_WRITEBACK \
883 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
884#define BAD_RANGE _("branch out of range")
885#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 886#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 887#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
888#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
889 "block")
890#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
891 "block")
892#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
893 " operand")
894#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
895 " operand")
a302e574 896#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
897#define BAD_MVE_AUTO \
898 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
899 " use a valid -march or -mcpu option.")
900#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
901 "and source operands makes instruction UNPREDICTABLE")
35c228db 902#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 903#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 904
c921be7d
NC
905static struct hash_control * arm_ops_hsh;
906static struct hash_control * arm_cond_hsh;
5ee91343 907static struct hash_control * arm_vcond_hsh;
c921be7d
NC
908static struct hash_control * arm_shift_hsh;
909static struct hash_control * arm_psr_hsh;
910static struct hash_control * arm_v7m_psr_hsh;
911static struct hash_control * arm_reg_hsh;
912static struct hash_control * arm_reloc_hsh;
913static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 914
b99bd4ef
NC
915/* Stuff needed to resolve the label ambiguity
916 As:
917 ...
918 label: <insn>
919 may differ from:
920 ...
921 label:
5f4273c7 922 <insn> */
b99bd4ef
NC
923
924symbolS * last_label_seen;
b34976b6 925static int label_is_thumb_function_name = FALSE;
e07e6e58 926
3d0c9500
NC
927/* Literal pool structure. Held on a per-section
928 and per-sub-section basis. */
a737bd4d 929
c19d1205 930#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 931typedef struct literal_pool
b99bd4ef 932{
c921be7d
NC
933 expressionS literals [MAX_LITERAL_POOL_SIZE];
934 unsigned int next_free_entry;
935 unsigned int id;
936 symbolS * symbol;
937 segT section;
938 subsegT sub_section;
a8040cf2
NC
939#ifdef OBJ_ELF
940 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
941#endif
c921be7d 942 struct literal_pool * next;
8335d6aa 943 unsigned int alignment;
3d0c9500 944} literal_pool;
b99bd4ef 945
3d0c9500
NC
946/* Pointer to a linked list of literal pools. */
947literal_pool * list_of_pools = NULL;
e27ec89e 948
2e6976a8
DG
949typedef enum asmfunc_states
950{
951 OUTSIDE_ASMFUNC,
952 WAITING_ASMFUNC_NAME,
953 WAITING_ENDASMFUNC
954} asmfunc_states;
955
956static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
957
e07e6e58 958#ifdef OBJ_ELF
5ee91343 959# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 960#else
5ee91343 961static struct current_pred now_pred;
e07e6e58
NC
962#endif
963
964static inline int
5ee91343 965now_pred_compatible (int cond)
e07e6e58 966{
5ee91343 967 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
968}
969
970static inline int
971conditional_insn (void)
972{
973 return inst.cond != COND_ALWAYS;
974}
975
5ee91343 976static int in_pred_block (void);
e07e6e58 977
5ee91343 978static int handle_pred_state (void);
e07e6e58
NC
979
980static void force_automatic_it_block_close (void);
981
c921be7d
NC
982static void it_fsm_post_encode (void);
983
5ee91343 984#define set_pred_insn_type(type) \
e07e6e58
NC
985 do \
986 { \
5ee91343
AV
987 inst.pred_insn_type = type; \
988 if (handle_pred_state () == FAIL) \
477330fc 989 return; \
e07e6e58
NC
990 } \
991 while (0)
992
5ee91343 993#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
994 do \
995 { \
5ee91343
AV
996 inst.pred_insn_type = type; \
997 if (handle_pred_state () == FAIL) \
477330fc 998 return failret; \
c921be7d
NC
999 } \
1000 while(0)
1001
5ee91343 1002#define set_pred_insn_type_last() \
e07e6e58
NC
1003 do \
1004 { \
1005 if (inst.cond == COND_ALWAYS) \
5ee91343 1006 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1007 else \
5ee91343 1008 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1009 } \
1010 while (0)
1011
e39c1607
SD
1012/* Toggle value[pos]. */
1013#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1014
c19d1205 1015/* Pure syntax. */
b99bd4ef 1016
c19d1205
ZW
1017/* This array holds the chars that always start a comment. If the
1018 pre-processor is disabled, these aren't very useful. */
2e6976a8 1019char arm_comment_chars[] = "@";
3d0c9500 1020
c19d1205
ZW
1021/* This array holds the chars that only start a comment at the beginning of
1022 a line. If the line seems to have the form '# 123 filename'
1023 .line and .file directives will appear in the pre-processed output. */
1024/* Note that input_file.c hand checks for '#' at the beginning of the
1025 first line of the input file. This is because the compiler outputs
1026 #NO_APP at the beginning of its output. */
1027/* Also note that comments like this one will always work. */
1028const char line_comment_chars[] = "#";
3d0c9500 1029
2e6976a8 1030char arm_line_separator_chars[] = ";";
b99bd4ef 1031
c19d1205
ZW
1032/* Chars that can be used to separate mant
1033 from exp in floating point numbers. */
1034const char EXP_CHARS[] = "eE";
3d0c9500 1035
c19d1205
ZW
1036/* Chars that mean this number is a floating point constant. */
1037/* As in 0f12.456 */
1038/* or 0d1.2345e12 */
b99bd4ef 1039
5312fe52 1040const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1041
c19d1205
ZW
1042/* Prefix characters that indicate the start of an immediate
1043 value. */
1044#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1045
c19d1205
ZW
1046/* Separator character handling. */
1047
1048#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1049
5312fe52
BW
1050enum fp_16bit_format
1051{
1052 ARM_FP16_FORMAT_IEEE = 0x1,
1053 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1054 ARM_FP16_FORMAT_DEFAULT = 0x3
1055};
1056
1057static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1058
1059
c19d1205
ZW
1060static inline int
1061skip_past_char (char ** str, char c)
1062{
8ab8155f
NC
1063 /* PR gas/14987: Allow for whitespace before the expected character. */
1064 skip_whitespace (*str);
427d0db6 1065
c19d1205
ZW
1066 if (**str == c)
1067 {
1068 (*str)++;
1069 return SUCCESS;
3d0c9500 1070 }
c19d1205
ZW
1071 else
1072 return FAIL;
1073}
c921be7d 1074
c19d1205 1075#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1076
c19d1205
ZW
1077/* Arithmetic expressions (possibly involving symbols). */
1078
1079/* Return TRUE if anything in the expression is a bignum. */
1080
0198d5e6 1081static bfd_boolean
c19d1205
ZW
1082walk_no_bignums (symbolS * sp)
1083{
1084 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1085 return TRUE;
c19d1205
ZW
1086
1087 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1088 {
c19d1205
ZW
1089 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1090 || (symbol_get_value_expression (sp)->X_op_symbol
1091 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1092 }
1093
0198d5e6 1094 return FALSE;
3d0c9500
NC
1095}
1096
0198d5e6 1097static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1098
1099/* Third argument to my_get_expression. */
1100#define GE_NO_PREFIX 0
1101#define GE_IMM_PREFIX 1
1102#define GE_OPT_PREFIX 2
5287ad62
JB
1103/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1104 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1105#define GE_OPT_PREFIX_BIG 3
a737bd4d 1106
b99bd4ef 1107static int
c19d1205 1108my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1109{
c19d1205 1110 char * save_in;
b99bd4ef 1111
c19d1205
ZW
1112 /* In unified syntax, all prefixes are optional. */
1113 if (unified_syntax)
5287ad62 1114 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1115 : GE_OPT_PREFIX;
b99bd4ef 1116
c19d1205 1117 switch (prefix_mode)
b99bd4ef 1118 {
c19d1205
ZW
1119 case GE_NO_PREFIX: break;
1120 case GE_IMM_PREFIX:
1121 if (!is_immediate_prefix (**str))
1122 {
1123 inst.error = _("immediate expression requires a # prefix");
1124 return FAIL;
1125 }
1126 (*str)++;
1127 break;
1128 case GE_OPT_PREFIX:
5287ad62 1129 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1130 if (is_immediate_prefix (**str))
1131 (*str)++;
1132 break;
0198d5e6
TC
1133 default:
1134 abort ();
c19d1205 1135 }
b99bd4ef 1136
c19d1205 1137 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1138
c19d1205
ZW
1139 save_in = input_line_pointer;
1140 input_line_pointer = *str;
0198d5e6 1141 in_my_get_expression = TRUE;
2ac93be7 1142 expression (ep);
0198d5e6 1143 in_my_get_expression = FALSE;
c19d1205 1144
f86adc07 1145 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1146 {
f86adc07 1147 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1148 *str = input_line_pointer;
1149 input_line_pointer = save_in;
1150 if (inst.error == NULL)
f86adc07
NS
1151 inst.error = (ep->X_op == O_absent
1152 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1153 return 1;
1154 }
b99bd4ef 1155
c19d1205
ZW
1156 /* Get rid of any bignums now, so that we don't generate an error for which
1157 we can't establish a line number later on. Big numbers are never valid
1158 in instructions, which is where this routine is always called. */
5287ad62
JB
1159 if (prefix_mode != GE_OPT_PREFIX_BIG
1160 && (ep->X_op == O_big
477330fc 1161 || (ep->X_add_symbol
5287ad62 1162 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1163 || (ep->X_op_symbol
5287ad62 1164 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1165 {
1166 inst.error = _("invalid constant");
1167 *str = input_line_pointer;
1168 input_line_pointer = save_in;
1169 return 1;
1170 }
b99bd4ef 1171
c19d1205
ZW
1172 *str = input_line_pointer;
1173 input_line_pointer = save_in;
0198d5e6 1174 return SUCCESS;
b99bd4ef
NC
1175}
1176
c19d1205
ZW
1177/* Turn a string in input_line_pointer into a floating point constant
1178 of type TYPE, and store the appropriate bytes in *LITP. The number
1179 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1180 returned, or NULL on OK.
b99bd4ef 1181
c19d1205
ZW
1182 Note that fp constants aren't represent in the normal way on the ARM.
1183 In big endian mode, things are as expected. However, in little endian
1184 mode fp constants are big-endian word-wise, and little-endian byte-wise
1185 within the words. For example, (double) 1.1 in big endian mode is
1186 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1187 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1188
c19d1205 1189 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1190
6d4af3c2 1191const char *
c19d1205
ZW
1192md_atof (int type, char * litP, int * sizeP)
1193{
1194 int prec;
1195 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1196 char *t;
1197 int i;
b99bd4ef 1198
c19d1205
ZW
1199 switch (type)
1200 {
5312fe52
BW
1201 case 'H':
1202 case 'h':
1203 prec = 1;
1204 break;
1205
c19d1205
ZW
1206 case 'f':
1207 case 'F':
1208 case 's':
1209 case 'S':
1210 prec = 2;
1211 break;
b99bd4ef 1212
c19d1205
ZW
1213 case 'd':
1214 case 'D':
1215 case 'r':
1216 case 'R':
1217 prec = 4;
1218 break;
b99bd4ef 1219
c19d1205
ZW
1220 case 'x':
1221 case 'X':
499ac353 1222 prec = 5;
c19d1205 1223 break;
b99bd4ef 1224
c19d1205
ZW
1225 case 'p':
1226 case 'P':
499ac353 1227 prec = 5;
c19d1205 1228 break;
a737bd4d 1229
c19d1205
ZW
1230 default:
1231 *sizeP = 0;
499ac353 1232 return _("Unrecognized or unsupported floating point constant");
c19d1205 1233 }
b99bd4ef 1234
c19d1205
ZW
1235 t = atof_ieee (input_line_pointer, type, words);
1236 if (t)
1237 input_line_pointer = t;
499ac353 1238 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1239
c19d1205
ZW
1240 if (target_big_endian)
1241 {
1242 for (i = 0; i < prec; i++)
1243 {
499ac353
NC
1244 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1245 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1246 }
1247 }
1248 else
1249 {
e74cfd16 1250 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1251 for (i = prec - 1; i >= 0; i--)
1252 {
499ac353
NC
1253 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1254 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1255 }
1256 else
1257 /* For a 4 byte float the order of elements in `words' is 1 0.
1258 For an 8 byte float the order is 1 0 3 2. */
1259 for (i = 0; i < prec; i += 2)
1260 {
499ac353
NC
1261 md_number_to_chars (litP, (valueT) words[i + 1],
1262 sizeof (LITTLENUM_TYPE));
1263 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1264 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1265 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1266 }
1267 }
b99bd4ef 1268
499ac353 1269 return NULL;
c19d1205 1270}
b99bd4ef 1271
c19d1205
ZW
1272/* We handle all bad expressions here, so that we can report the faulty
1273 instruction in the error message. */
0198d5e6 1274
c19d1205 1275void
91d6fa6a 1276md_operand (expressionS * exp)
c19d1205
ZW
1277{
1278 if (in_my_get_expression)
91d6fa6a 1279 exp->X_op = O_illegal;
b99bd4ef
NC
1280}
1281
c19d1205 1282/* Immediate values. */
b99bd4ef 1283
0198d5e6 1284#ifdef OBJ_ELF
c19d1205
ZW
1285/* Generic immediate-value read function for use in directives.
1286 Accepts anything that 'expression' can fold to a constant.
1287 *val receives the number. */
0198d5e6 1288
c19d1205
ZW
1289static int
1290immediate_for_directive (int *val)
b99bd4ef 1291{
c19d1205
ZW
1292 expressionS exp;
1293 exp.X_op = O_illegal;
b99bd4ef 1294
c19d1205
ZW
1295 if (is_immediate_prefix (*input_line_pointer))
1296 {
1297 input_line_pointer++;
1298 expression (&exp);
1299 }
b99bd4ef 1300
c19d1205
ZW
1301 if (exp.X_op != O_constant)
1302 {
1303 as_bad (_("expected #constant"));
1304 ignore_rest_of_line ();
1305 return FAIL;
1306 }
1307 *val = exp.X_add_number;
1308 return SUCCESS;
b99bd4ef 1309}
c19d1205 1310#endif
b99bd4ef 1311
c19d1205 1312/* Register parsing. */
b99bd4ef 1313
c19d1205
ZW
1314/* Generic register parser. CCP points to what should be the
1315 beginning of a register name. If it is indeed a valid register
1316 name, advance CCP over it and return the reg_entry structure;
1317 otherwise return NULL. Does not issue diagnostics. */
1318
1319static struct reg_entry *
1320arm_reg_parse_multi (char **ccp)
b99bd4ef 1321{
c19d1205
ZW
1322 char *start = *ccp;
1323 char *p;
1324 struct reg_entry *reg;
b99bd4ef 1325
477330fc
RM
1326 skip_whitespace (start);
1327
c19d1205
ZW
1328#ifdef REGISTER_PREFIX
1329 if (*start != REGISTER_PREFIX)
01cfc07f 1330 return NULL;
c19d1205
ZW
1331 start++;
1332#endif
1333#ifdef OPTIONAL_REGISTER_PREFIX
1334 if (*start == OPTIONAL_REGISTER_PREFIX)
1335 start++;
1336#endif
b99bd4ef 1337
c19d1205
ZW
1338 p = start;
1339 if (!ISALPHA (*p) || !is_name_beginner (*p))
1340 return NULL;
b99bd4ef 1341
c19d1205
ZW
1342 do
1343 p++;
1344 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1345
1346 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1347
1348 if (!reg)
1349 return NULL;
1350
1351 *ccp = p;
1352 return reg;
b99bd4ef
NC
1353}
1354
1355static int
dcbf9037 1356arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1357 enum arm_reg_type type)
b99bd4ef 1358{
c19d1205
ZW
1359 /* Alternative syntaxes are accepted for a few register classes. */
1360 switch (type)
1361 {
1362 case REG_TYPE_MVF:
1363 case REG_TYPE_MVD:
1364 case REG_TYPE_MVFX:
1365 case REG_TYPE_MVDX:
1366 /* Generic coprocessor register names are allowed for these. */
79134647 1367 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1368 return reg->number;
1369 break;
69b97547 1370
c19d1205
ZW
1371 case REG_TYPE_CP:
1372 /* For backward compatibility, a bare number is valid here. */
1373 {
1374 unsigned long processor = strtoul (start, ccp, 10);
1375 if (*ccp != start && processor <= 15)
1376 return processor;
1377 }
1a0670f3 1378 /* Fall through. */
6057a28f 1379
c19d1205
ZW
1380 case REG_TYPE_MMXWC:
1381 /* WC includes WCG. ??? I'm not sure this is true for all
1382 instructions that take WC registers. */
79134647 1383 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1384 return reg->number;
6057a28f 1385 break;
c19d1205 1386
6057a28f 1387 default:
c19d1205 1388 break;
6057a28f
NC
1389 }
1390
dcbf9037
JB
1391 return FAIL;
1392}
1393
1394/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1395 return value is the register number or FAIL. */
1396
1397static int
1398arm_reg_parse (char **ccp, enum arm_reg_type type)
1399{
1400 char *start = *ccp;
1401 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1402 int ret;
1403
1404 /* Do not allow a scalar (reg+index) to parse as a register. */
1405 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1406 return FAIL;
1407
1408 if (reg && reg->type == type)
1409 return reg->number;
1410
1411 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1412 return ret;
1413
c19d1205
ZW
1414 *ccp = start;
1415 return FAIL;
1416}
69b97547 1417
dcbf9037
JB
1418/* Parse a Neon type specifier. *STR should point at the leading '.'
1419 character. Does no verification at this stage that the type fits the opcode
1420 properly. E.g.,
1421
1422 .i32.i32.s16
1423 .s32.f32
1424 .u16
1425
1426 Can all be legally parsed by this function.
1427
1428 Fills in neon_type struct pointer with parsed information, and updates STR
1429 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1430 type, FAIL if not. */
1431
1432static int
1433parse_neon_type (struct neon_type *type, char **str)
1434{
1435 char *ptr = *str;
1436
1437 if (type)
1438 type->elems = 0;
1439
1440 while (type->elems < NEON_MAX_TYPE_ELS)
1441 {
1442 enum neon_el_type thistype = NT_untyped;
1443 unsigned thissize = -1u;
1444
1445 if (*ptr != '.')
1446 break;
1447
1448 ptr++;
1449
1450 /* Just a size without an explicit type. */
1451 if (ISDIGIT (*ptr))
1452 goto parsesize;
1453
1454 switch (TOLOWER (*ptr))
1455 {
1456 case 'i': thistype = NT_integer; break;
1457 case 'f': thistype = NT_float; break;
1458 case 'p': thistype = NT_poly; break;
1459 case 's': thistype = NT_signed; break;
1460 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1461 case 'd':
1462 thistype = NT_float;
1463 thissize = 64;
1464 ptr++;
1465 goto done;
dcbf9037
JB
1466 default:
1467 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1468 return FAIL;
1469 }
1470
1471 ptr++;
1472
1473 /* .f is an abbreviation for .f32. */
1474 if (thistype == NT_float && !ISDIGIT (*ptr))
1475 thissize = 32;
1476 else
1477 {
1478 parsesize:
1479 thissize = strtoul (ptr, &ptr, 10);
1480
1481 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1482 && thissize != 64)
1483 {
1484 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1485 return FAIL;
1486 }
1487 }
1488
037e8744 1489 done:
dcbf9037 1490 if (type)
477330fc
RM
1491 {
1492 type->el[type->elems].type = thistype;
dcbf9037
JB
1493 type->el[type->elems].size = thissize;
1494 type->elems++;
1495 }
1496 }
1497
1498 /* Empty/missing type is not a successful parse. */
1499 if (type->elems == 0)
1500 return FAIL;
1501
1502 *str = ptr;
1503
1504 return SUCCESS;
1505}
1506
1507/* Errors may be set multiple times during parsing or bit encoding
1508 (particularly in the Neon bits), but usually the earliest error which is set
1509 will be the most meaningful. Avoid overwriting it with later (cascading)
1510 errors by calling this function. */
1511
1512static void
1513first_error (const char *err)
1514{
1515 if (!inst.error)
1516 inst.error = err;
1517}
1518
1519/* Parse a single type, e.g. ".s32", leading period included. */
1520static int
1521parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1522{
1523 char *str = *ccp;
1524 struct neon_type optype;
1525
1526 if (*str == '.')
1527 {
1528 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1529 {
1530 if (optype.elems == 1)
1531 *vectype = optype.el[0];
1532 else
1533 {
1534 first_error (_("only one type should be specified for operand"));
1535 return FAIL;
1536 }
1537 }
dcbf9037 1538 else
477330fc
RM
1539 {
1540 first_error (_("vector type expected"));
1541 return FAIL;
1542 }
dcbf9037
JB
1543 }
1544 else
1545 return FAIL;
5f4273c7 1546
dcbf9037 1547 *ccp = str;
5f4273c7 1548
dcbf9037
JB
1549 return SUCCESS;
1550}
1551
1552/* Special meanings for indices (which have a range of 0-7), which will fit into
1553 a 4-bit integer. */
1554
1555#define NEON_ALL_LANES 15
1556#define NEON_INTERLEAVE_LANES 14
1557
5ee91343
AV
1558/* Record a use of the given feature. */
1559static void
1560record_feature_use (const arm_feature_set *feature)
1561{
1562 if (thumb_mode)
1563 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1564 else
1565 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1566}
1567
1568/* If the given feature available in the selected CPU, mark it as used.
1569 Returns TRUE iff feature is available. */
1570static bfd_boolean
1571mark_feature_used (const arm_feature_set *feature)
1572{
886e1c73
AV
1573
1574 /* Do not support the use of MVE only instructions when in auto-detection or
1575 -march=all. */
1576 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1577 && ARM_CPU_IS_ANY (cpu_variant))
1578 {
1579 first_error (BAD_MVE_AUTO);
1580 return FALSE;
1581 }
5ee91343
AV
1582 /* Ensure the option is valid on the current architecture. */
1583 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1584 return FALSE;
1585
1586 /* Add the appropriate architecture feature for the barrier option used.
1587 */
1588 record_feature_use (feature);
1589
1590 return TRUE;
1591}
1592
dcbf9037
JB
1593/* Parse either a register or a scalar, with an optional type. Return the
1594 register number, and optionally fill in the actual type of the register
1595 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1596 type/index information in *TYPEINFO. */
1597
1598static int
1599parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1600 enum arm_reg_type *rtype,
1601 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1602{
1603 char *str = *ccp;
1604 struct reg_entry *reg = arm_reg_parse_multi (&str);
1605 struct neon_typed_alias atype;
1606 struct neon_type_el parsetype;
1607
1608 atype.defined = 0;
1609 atype.index = -1;
1610 atype.eltype.type = NT_invtype;
1611 atype.eltype.size = -1;
1612
1613 /* Try alternate syntax for some types of register. Note these are mutually
1614 exclusive with the Neon syntax extensions. */
1615 if (reg == NULL)
1616 {
1617 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1618 if (altreg != FAIL)
477330fc 1619 *ccp = str;
dcbf9037 1620 if (typeinfo)
477330fc 1621 *typeinfo = atype;
dcbf9037
JB
1622 return altreg;
1623 }
1624
037e8744
JB
1625 /* Undo polymorphism when a set of register types may be accepted. */
1626 if ((type == REG_TYPE_NDQ
1627 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1628 || (type == REG_TYPE_VFSD
477330fc 1629 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1630 || (type == REG_TYPE_NSDQ
477330fc
RM
1631 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1632 || reg->type == REG_TYPE_NQ))
dec41383
JW
1633 || (type == REG_TYPE_NSD
1634 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1635 || (type == REG_TYPE_MMXWC
1636 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1637 type = (enum arm_reg_type) reg->type;
dcbf9037 1638
5ee91343
AV
1639 if (type == REG_TYPE_MQ)
1640 {
1641 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1642 return FAIL;
1643
1644 if (!reg || reg->type != REG_TYPE_NQ)
1645 return FAIL;
1646
1647 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1648 {
1649 first_error (_("expected MVE register [q0..q7]"));
1650 return FAIL;
1651 }
1652 type = REG_TYPE_NQ;
1653 }
1654 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1655 && (type == REG_TYPE_NQ))
1656 return FAIL;
1657
1658
dcbf9037
JB
1659 if (type != reg->type)
1660 return FAIL;
1661
1662 if (reg->neon)
1663 atype = *reg->neon;
5f4273c7 1664
dcbf9037
JB
1665 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1666 {
1667 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1668 {
1669 first_error (_("can't redefine type for operand"));
1670 return FAIL;
1671 }
dcbf9037
JB
1672 atype.defined |= NTA_HASTYPE;
1673 atype.eltype = parsetype;
1674 }
5f4273c7 1675
dcbf9037
JB
1676 if (skip_past_char (&str, '[') == SUCCESS)
1677 {
dec41383
JW
1678 if (type != REG_TYPE_VFD
1679 && !(type == REG_TYPE_VFS
57785aa2
AV
1680 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1681 && !(type == REG_TYPE_NQ
1682 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1683 {
57785aa2
AV
1684 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1685 first_error (_("only D and Q registers may be indexed"));
1686 else
1687 first_error (_("only D registers may be indexed"));
477330fc
RM
1688 return FAIL;
1689 }
5f4273c7 1690
dcbf9037 1691 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1692 {
1693 first_error (_("can't change index for operand"));
1694 return FAIL;
1695 }
dcbf9037
JB
1696
1697 atype.defined |= NTA_HASINDEX;
1698
1699 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1700 atype.index = NEON_ALL_LANES;
dcbf9037 1701 else
477330fc
RM
1702 {
1703 expressionS exp;
dcbf9037 1704
477330fc 1705 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1706
477330fc
RM
1707 if (exp.X_op != O_constant)
1708 {
1709 first_error (_("constant expression required"));
1710 return FAIL;
1711 }
dcbf9037 1712
477330fc
RM
1713 if (skip_past_char (&str, ']') == FAIL)
1714 return FAIL;
dcbf9037 1715
477330fc
RM
1716 atype.index = exp.X_add_number;
1717 }
dcbf9037 1718 }
5f4273c7 1719
dcbf9037
JB
1720 if (typeinfo)
1721 *typeinfo = atype;
5f4273c7 1722
dcbf9037
JB
1723 if (rtype)
1724 *rtype = type;
5f4273c7 1725
dcbf9037 1726 *ccp = str;
5f4273c7 1727
dcbf9037
JB
1728 return reg->number;
1729}
1730
efd6b359 1731/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1732 - If RTYPE is non-zero, return the (possibly restricted) type of the
1733 register (e.g. Neon double or quad reg when either has been requested).
1734 - If this is a Neon vector type with additional type information, fill
1735 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1736 This function will fault on encountering a scalar. */
dcbf9037
JB
1737
1738static int
1739arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1740 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1741{
1742 struct neon_typed_alias atype;
1743 char *str = *ccp;
1744 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1745
1746 if (reg == FAIL)
1747 return FAIL;
1748
0855e32b
NS
1749 /* Do not allow regname(... to parse as a register. */
1750 if (*str == '(')
1751 return FAIL;
1752
dcbf9037
JB
1753 /* Do not allow a scalar (reg+index) to parse as a register. */
1754 if ((atype.defined & NTA_HASINDEX) != 0)
1755 {
1756 first_error (_("register operand expected, but got scalar"));
1757 return FAIL;
1758 }
1759
1760 if (vectype)
1761 *vectype = atype.eltype;
1762
1763 *ccp = str;
1764
1765 return reg;
1766}
1767
1768#define NEON_SCALAR_REG(X) ((X) >> 4)
1769#define NEON_SCALAR_INDEX(X) ((X) & 15)
1770
5287ad62
JB
1771/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1772 have enough information to be able to do a good job bounds-checking. So, we
1773 just do easy checks here, and do further checks later. */
1774
1775static int
57785aa2
AV
1776parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1777 arm_reg_type reg_type)
5287ad62 1778{
dcbf9037 1779 int reg;
5287ad62 1780 char *str = *ccp;
dcbf9037 1781 struct neon_typed_alias atype;
57785aa2 1782 unsigned reg_size;
5f4273c7 1783
dec41383 1784 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1785
57785aa2
AV
1786 switch (reg_type)
1787 {
1788 case REG_TYPE_VFS:
1789 reg_size = 32;
1790 break;
1791 case REG_TYPE_VFD:
1792 reg_size = 64;
1793 break;
1794 case REG_TYPE_MQ:
1795 reg_size = 128;
1796 break;
1797 default:
1798 gas_assert (0);
1799 return FAIL;
1800 }
1801
dcbf9037 1802 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1803 return FAIL;
5f4273c7 1804
57785aa2 1805 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1806 {
dcbf9037 1807 first_error (_("scalar must have an index"));
5287ad62
JB
1808 return FAIL;
1809 }
57785aa2 1810 else if (atype.index >= reg_size / elsize)
5287ad62 1811 {
dcbf9037 1812 first_error (_("scalar index out of range"));
5287ad62
JB
1813 return FAIL;
1814 }
5f4273c7 1815
dcbf9037
JB
1816 if (type)
1817 *type = atype.eltype;
5f4273c7 1818
5287ad62 1819 *ccp = str;
5f4273c7 1820
dcbf9037 1821 return reg * 16 + atype.index;
5287ad62
JB
1822}
1823
4b5a202f
AV
1824/* Types of registers in a list. */
1825
1826enum reg_list_els
1827{
1828 REGLIST_RN,
1829 REGLIST_CLRM,
1830 REGLIST_VFP_S,
efd6b359 1831 REGLIST_VFP_S_VPR,
4b5a202f 1832 REGLIST_VFP_D,
efd6b359 1833 REGLIST_VFP_D_VPR,
4b5a202f
AV
1834 REGLIST_NEON_D
1835};
1836
c19d1205 1837/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1838
c19d1205 1839static long
4b5a202f 1840parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1841{
4b5a202f
AV
1842 char *str = *strp;
1843 long range = 0;
1844 int another_range;
1845
1846 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1847
c19d1205
ZW
1848 /* We come back here if we get ranges concatenated by '+' or '|'. */
1849 do
6057a28f 1850 {
477330fc
RM
1851 skip_whitespace (str);
1852
c19d1205 1853 another_range = 0;
a737bd4d 1854
c19d1205
ZW
1855 if (*str == '{')
1856 {
1857 int in_range = 0;
1858 int cur_reg = -1;
a737bd4d 1859
c19d1205
ZW
1860 str++;
1861 do
1862 {
1863 int reg;
4b5a202f
AV
1864 const char apsr_str[] = "apsr";
1865 int apsr_str_len = strlen (apsr_str);
6057a28f 1866
4b5a202f
AV
1867 reg = arm_reg_parse (&str, REGLIST_RN);
1868 if (etype == REGLIST_CLRM)
c19d1205 1869 {
4b5a202f
AV
1870 if (reg == REG_SP || reg == REG_PC)
1871 reg = FAIL;
1872 else if (reg == FAIL
1873 && !strncasecmp (str, apsr_str, apsr_str_len)
1874 && !ISALPHA (*(str + apsr_str_len)))
1875 {
1876 reg = 15;
1877 str += apsr_str_len;
1878 }
1879
1880 if (reg == FAIL)
1881 {
1882 first_error (_("r0-r12, lr or APSR expected"));
1883 return FAIL;
1884 }
1885 }
1886 else /* etype == REGLIST_RN. */
1887 {
1888 if (reg == FAIL)
1889 {
1890 first_error (_(reg_expected_msgs[REGLIST_RN]));
1891 return FAIL;
1892 }
c19d1205 1893 }
a737bd4d 1894
c19d1205
ZW
1895 if (in_range)
1896 {
1897 int i;
a737bd4d 1898
c19d1205
ZW
1899 if (reg <= cur_reg)
1900 {
dcbf9037 1901 first_error (_("bad range in register list"));
c19d1205
ZW
1902 return FAIL;
1903 }
40a18ebd 1904
c19d1205
ZW
1905 for (i = cur_reg + 1; i < reg; i++)
1906 {
1907 if (range & (1 << i))
1908 as_tsktsk
1909 (_("Warning: duplicated register (r%d) in register list"),
1910 i);
1911 else
1912 range |= 1 << i;
1913 }
1914 in_range = 0;
1915 }
a737bd4d 1916
c19d1205
ZW
1917 if (range & (1 << reg))
1918 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1919 reg);
1920 else if (reg <= cur_reg)
1921 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1922
c19d1205
ZW
1923 range |= 1 << reg;
1924 cur_reg = reg;
1925 }
1926 while (skip_past_comma (&str) != FAIL
1927 || (in_range = 1, *str++ == '-'));
1928 str--;
a737bd4d 1929
d996d970 1930 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1931 {
dcbf9037 1932 first_error (_("missing `}'"));
c19d1205
ZW
1933 return FAIL;
1934 }
1935 }
4b5a202f 1936 else if (etype == REGLIST_RN)
c19d1205 1937 {
91d6fa6a 1938 expressionS exp;
40a18ebd 1939
91d6fa6a 1940 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1941 return FAIL;
40a18ebd 1942
91d6fa6a 1943 if (exp.X_op == O_constant)
c19d1205 1944 {
91d6fa6a
NC
1945 if (exp.X_add_number
1946 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1947 {
1948 inst.error = _("invalid register mask");
1949 return FAIL;
1950 }
a737bd4d 1951
91d6fa6a 1952 if ((range & exp.X_add_number) != 0)
c19d1205 1953 {
91d6fa6a 1954 int regno = range & exp.X_add_number;
a737bd4d 1955
c19d1205
ZW
1956 regno &= -regno;
1957 regno = (1 << regno) - 1;
1958 as_tsktsk
1959 (_("Warning: duplicated register (r%d) in register list"),
1960 regno);
1961 }
a737bd4d 1962
91d6fa6a 1963 range |= exp.X_add_number;
c19d1205
ZW
1964 }
1965 else
1966 {
e2b0ab59 1967 if (inst.relocs[0].type != 0)
c19d1205
ZW
1968 {
1969 inst.error = _("expression too complex");
1970 return FAIL;
1971 }
a737bd4d 1972
e2b0ab59
AV
1973 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1974 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1975 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
1976 }
1977 }
a737bd4d 1978
c19d1205
ZW
1979 if (*str == '|' || *str == '+')
1980 {
1981 str++;
1982 another_range = 1;
1983 }
a737bd4d 1984 }
c19d1205 1985 while (another_range);
a737bd4d 1986
c19d1205
ZW
1987 *strp = str;
1988 return range;
a737bd4d
NC
1989}
1990
c19d1205
ZW
1991/* Parse a VFP register list. If the string is invalid return FAIL.
1992 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1993 register. Parses registers of type ETYPE.
1994 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1995 - Q registers can be used to specify pairs of D registers
1996 - { } can be omitted from around a singleton register list
477330fc
RM
1997 FIXME: This is not implemented, as it would require backtracking in
1998 some cases, e.g.:
1999 vtbl.8 d3,d4,d5
2000 This could be done (the meaning isn't really ambiguous), but doesn't
2001 fit in well with the current parsing framework.
dcbf9037
JB
2002 - 32 D registers may be used (also true for VFPv3).
2003 FIXME: Types are ignored in these register lists, which is probably a
2004 bug. */
6057a28f 2005
c19d1205 2006static int
efd6b359
AV
2007parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2008 bfd_boolean *partial_match)
6057a28f 2009{
037e8744 2010 char *str = *ccp;
c19d1205
ZW
2011 int base_reg;
2012 int new_base;
21d799b5 2013 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2014 int max_regs = 0;
c19d1205
ZW
2015 int count = 0;
2016 int warned = 0;
2017 unsigned long mask = 0;
a737bd4d 2018 int i;
efd6b359
AV
2019 bfd_boolean vpr_seen = FALSE;
2020 bfd_boolean expect_vpr =
2021 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2022
477330fc 2023 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2024 {
2025 inst.error = _("expecting {");
2026 return FAIL;
2027 }
6057a28f 2028
5287ad62 2029 switch (etype)
c19d1205 2030 {
5287ad62 2031 case REGLIST_VFP_S:
efd6b359 2032 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2033 regtype = REG_TYPE_VFS;
2034 max_regs = 32;
5287ad62 2035 break;
5f4273c7 2036
5287ad62 2037 case REGLIST_VFP_D:
efd6b359 2038 case REGLIST_VFP_D_VPR:
5287ad62 2039 regtype = REG_TYPE_VFD;
b7fc2769 2040 break;
5f4273c7 2041
b7fc2769
JB
2042 case REGLIST_NEON_D:
2043 regtype = REG_TYPE_NDQ;
2044 break;
4b5a202f
AV
2045
2046 default:
2047 gas_assert (0);
b7fc2769
JB
2048 }
2049
efd6b359 2050 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2051 {
b1cc4aeb
PB
2052 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2053 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2054 {
2055 max_regs = 32;
2056 if (thumb_mode)
2057 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2058 fpu_vfp_ext_d32);
2059 else
2060 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2061 fpu_vfp_ext_d32);
2062 }
5287ad62 2063 else
477330fc 2064 max_regs = 16;
c19d1205 2065 }
6057a28f 2066
c19d1205 2067 base_reg = max_regs;
efd6b359 2068 *partial_match = FALSE;
a737bd4d 2069
c19d1205
ZW
2070 do
2071 {
5287ad62 2072 int setmask = 1, addregs = 1;
efd6b359
AV
2073 const char vpr_str[] = "vpr";
2074 int vpr_str_len = strlen (vpr_str);
dcbf9037 2075
037e8744 2076 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2077
efd6b359
AV
2078 if (expect_vpr)
2079 {
2080 if (new_base == FAIL
2081 && !strncasecmp (str, vpr_str, vpr_str_len)
2082 && !ISALPHA (*(str + vpr_str_len))
2083 && !vpr_seen)
2084 {
2085 vpr_seen = TRUE;
2086 str += vpr_str_len;
2087 if (count == 0)
2088 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2089 }
2090 else if (vpr_seen)
2091 {
2092 first_error (_("VPR expected last"));
2093 return FAIL;
2094 }
2095 else if (new_base == FAIL)
2096 {
2097 if (regtype == REG_TYPE_VFS)
2098 first_error (_("VFP single precision register or VPR "
2099 "expected"));
2100 else /* regtype == REG_TYPE_VFD. */
2101 first_error (_("VFP/Neon double precision register or VPR "
2102 "expected"));
2103 return FAIL;
2104 }
2105 }
2106 else if (new_base == FAIL)
a737bd4d 2107 {
dcbf9037 2108 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2109 return FAIL;
2110 }
5f4273c7 2111
efd6b359
AV
2112 *partial_match = TRUE;
2113 if (vpr_seen)
2114 continue;
2115
b7fc2769 2116 if (new_base >= max_regs)
477330fc
RM
2117 {
2118 first_error (_("register out of range in list"));
2119 return FAIL;
2120 }
5f4273c7 2121
5287ad62
JB
2122 /* Note: a value of 2 * n is returned for the register Q<n>. */
2123 if (regtype == REG_TYPE_NQ)
477330fc
RM
2124 {
2125 setmask = 3;
2126 addregs = 2;
2127 }
5287ad62 2128
c19d1205
ZW
2129 if (new_base < base_reg)
2130 base_reg = new_base;
a737bd4d 2131
5287ad62 2132 if (mask & (setmask << new_base))
c19d1205 2133 {
dcbf9037 2134 first_error (_("invalid register list"));
c19d1205 2135 return FAIL;
a737bd4d 2136 }
a737bd4d 2137
efd6b359 2138 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2139 {
2140 as_tsktsk (_("register list not in ascending order"));
2141 warned = 1;
2142 }
0bbf2aa4 2143
5287ad62
JB
2144 mask |= setmask << new_base;
2145 count += addregs;
0bbf2aa4 2146
037e8744 2147 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2148 {
2149 int high_range;
0bbf2aa4 2150
037e8744 2151 str++;
0bbf2aa4 2152
037e8744 2153 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2154 == FAIL)
c19d1205
ZW
2155 {
2156 inst.error = gettext (reg_expected_msgs[regtype]);
2157 return FAIL;
2158 }
0bbf2aa4 2159
477330fc
RM
2160 if (high_range >= max_regs)
2161 {
2162 first_error (_("register out of range in list"));
2163 return FAIL;
2164 }
b7fc2769 2165
477330fc
RM
2166 if (regtype == REG_TYPE_NQ)
2167 high_range = high_range + 1;
5287ad62 2168
c19d1205
ZW
2169 if (high_range <= new_base)
2170 {
2171 inst.error = _("register range not in ascending order");
2172 return FAIL;
2173 }
0bbf2aa4 2174
5287ad62 2175 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2176 {
5287ad62 2177 if (mask & (setmask << new_base))
0bbf2aa4 2178 {
c19d1205
ZW
2179 inst.error = _("invalid register list");
2180 return FAIL;
0bbf2aa4 2181 }
c19d1205 2182
5287ad62
JB
2183 mask |= setmask << new_base;
2184 count += addregs;
0bbf2aa4 2185 }
0bbf2aa4 2186 }
0bbf2aa4 2187 }
037e8744 2188 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2189
037e8744 2190 str++;
0bbf2aa4 2191
c19d1205 2192 /* Sanity check -- should have raised a parse error above. */
efd6b359 2193 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2194 abort ();
2195
2196 *pbase = base_reg;
2197
efd6b359
AV
2198 if (expect_vpr && !vpr_seen)
2199 {
2200 first_error (_("VPR expected last"));
2201 return FAIL;
2202 }
2203
c19d1205
ZW
2204 /* Final test -- the registers must be consecutive. */
2205 mask >>= base_reg;
2206 for (i = 0; i < count; i++)
2207 {
2208 if ((mask & (1u << i)) == 0)
2209 {
2210 inst.error = _("non-contiguous register range");
2211 return FAIL;
2212 }
2213 }
2214
037e8744
JB
2215 *ccp = str;
2216
c19d1205 2217 return count;
b99bd4ef
NC
2218}
2219
dcbf9037
JB
2220/* True if two alias types are the same. */
2221
c921be7d 2222static bfd_boolean
dcbf9037
JB
2223neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2224{
2225 if (!a && !b)
c921be7d 2226 return TRUE;
5f4273c7 2227
dcbf9037 2228 if (!a || !b)
c921be7d 2229 return FALSE;
dcbf9037
JB
2230
2231 if (a->defined != b->defined)
c921be7d 2232 return FALSE;
5f4273c7 2233
dcbf9037
JB
2234 if ((a->defined & NTA_HASTYPE) != 0
2235 && (a->eltype.type != b->eltype.type
477330fc 2236 || a->eltype.size != b->eltype.size))
c921be7d 2237 return FALSE;
dcbf9037
JB
2238
2239 if ((a->defined & NTA_HASINDEX) != 0
2240 && (a->index != b->index))
c921be7d 2241 return FALSE;
5f4273c7 2242
c921be7d 2243 return TRUE;
dcbf9037
JB
2244}
2245
5287ad62
JB
2246/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2247 The base register is put in *PBASE.
dcbf9037 2248 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2249 the return value.
2250 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2251 Bits [6:5] encode the list length (minus one).
2252 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2253
5287ad62 2254#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2255#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2256#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2257
2258static int
dcbf9037 2259parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2260 int mve,
477330fc 2261 struct neon_type_el *eltype)
5287ad62
JB
2262{
2263 char *ptr = *str;
2264 int base_reg = -1;
2265 int reg_incr = -1;
2266 int count = 0;
2267 int lane = -1;
2268 int leading_brace = 0;
2269 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2270 const char *const incr_error = mve ? _("register stride must be 1") :
2271 _("register stride must be 1 or 2");
20203fb9 2272 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2273 struct neon_typed_alias firsttype;
f85d59c3
KT
2274 firsttype.defined = 0;
2275 firsttype.eltype.type = NT_invtype;
2276 firsttype.eltype.size = -1;
2277 firsttype.index = -1;
5f4273c7 2278
5287ad62
JB
2279 if (skip_past_char (&ptr, '{') == SUCCESS)
2280 leading_brace = 1;
5f4273c7 2281
5287ad62
JB
2282 do
2283 {
dcbf9037 2284 struct neon_typed_alias atype;
35c228db
AV
2285 if (mve)
2286 rtype = REG_TYPE_MQ;
dcbf9037
JB
2287 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2288
5287ad62 2289 if (getreg == FAIL)
477330fc
RM
2290 {
2291 first_error (_(reg_expected_msgs[rtype]));
2292 return FAIL;
2293 }
5f4273c7 2294
5287ad62 2295 if (base_reg == -1)
477330fc
RM
2296 {
2297 base_reg = getreg;
2298 if (rtype == REG_TYPE_NQ)
2299 {
2300 reg_incr = 1;
2301 }
2302 firsttype = atype;
2303 }
5287ad62 2304 else if (reg_incr == -1)
477330fc
RM
2305 {
2306 reg_incr = getreg - base_reg;
2307 if (reg_incr < 1 || reg_incr > 2)
2308 {
2309 first_error (_(incr_error));
2310 return FAIL;
2311 }
2312 }
5287ad62 2313 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2314 {
2315 first_error (_(incr_error));
2316 return FAIL;
2317 }
dcbf9037 2318
c921be7d 2319 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2320 {
2321 first_error (_(type_error));
2322 return FAIL;
2323 }
5f4273c7 2324
5287ad62 2325 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2326 modes. */
5287ad62 2327 if (ptr[0] == '-')
477330fc
RM
2328 {
2329 struct neon_typed_alias htype;
2330 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2331 if (lane == -1)
2332 lane = NEON_INTERLEAVE_LANES;
2333 else if (lane != NEON_INTERLEAVE_LANES)
2334 {
2335 first_error (_(type_error));
2336 return FAIL;
2337 }
2338 if (reg_incr == -1)
2339 reg_incr = 1;
2340 else if (reg_incr != 1)
2341 {
2342 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2343 return FAIL;
2344 }
2345 ptr++;
2346 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2347 if (hireg == FAIL)
2348 {
2349 first_error (_(reg_expected_msgs[rtype]));
2350 return FAIL;
2351 }
2352 if (! neon_alias_types_same (&htype, &firsttype))
2353 {
2354 first_error (_(type_error));
2355 return FAIL;
2356 }
2357 count += hireg + dregs - getreg;
2358 continue;
2359 }
5f4273c7 2360
5287ad62
JB
2361 /* If we're using Q registers, we can't use [] or [n] syntax. */
2362 if (rtype == REG_TYPE_NQ)
477330fc
RM
2363 {
2364 count += 2;
2365 continue;
2366 }
5f4273c7 2367
dcbf9037 2368 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2369 {
2370 if (lane == -1)
2371 lane = atype.index;
2372 else if (lane != atype.index)
2373 {
2374 first_error (_(type_error));
2375 return FAIL;
2376 }
2377 }
5287ad62 2378 else if (lane == -1)
477330fc 2379 lane = NEON_INTERLEAVE_LANES;
5287ad62 2380 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2381 {
2382 first_error (_(type_error));
2383 return FAIL;
2384 }
5287ad62
JB
2385 count++;
2386 }
2387 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2388
5287ad62
JB
2389 /* No lane set by [x]. We must be interleaving structures. */
2390 if (lane == -1)
2391 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2392
5287ad62 2393 /* Sanity check. */
35c228db 2394 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2395 || (count > 1 && reg_incr == -1))
2396 {
dcbf9037 2397 first_error (_("error parsing element/structure list"));
5287ad62
JB
2398 return FAIL;
2399 }
2400
2401 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2402 {
dcbf9037 2403 first_error (_("expected }"));
5287ad62
JB
2404 return FAIL;
2405 }
5f4273c7 2406
5287ad62
JB
2407 if (reg_incr == -1)
2408 reg_incr = 1;
2409
dcbf9037
JB
2410 if (eltype)
2411 *eltype = firsttype.eltype;
2412
5287ad62
JB
2413 *pbase = base_reg;
2414 *str = ptr;
5f4273c7 2415
5287ad62
JB
2416 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2417}
2418
c19d1205
ZW
2419/* Parse an explicit relocation suffix on an expression. This is
2420 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2421 arm_reloc_hsh contains no entries, so this function can only
2422 succeed if there is no () after the word. Returns -1 on error,
2423 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2424
c19d1205
ZW
2425static int
2426parse_reloc (char **str)
b99bd4ef 2427{
c19d1205
ZW
2428 struct reloc_entry *r;
2429 char *p, *q;
b99bd4ef 2430
c19d1205
ZW
2431 if (**str != '(')
2432 return BFD_RELOC_UNUSED;
b99bd4ef 2433
c19d1205
ZW
2434 p = *str + 1;
2435 q = p;
2436
2437 while (*q && *q != ')' && *q != ',')
2438 q++;
2439 if (*q != ')')
2440 return -1;
2441
21d799b5
NC
2442 if ((r = (struct reloc_entry *)
2443 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2444 return -1;
2445
2446 *str = q + 1;
2447 return r->reloc;
b99bd4ef
NC
2448}
2449
c19d1205
ZW
2450/* Directives: register aliases. */
2451
dcbf9037 2452static struct reg_entry *
90ec0d68 2453insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2454{
d3ce72d0 2455 struct reg_entry *new_reg;
c19d1205 2456 const char *name;
b99bd4ef 2457
d3ce72d0 2458 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2459 {
d3ce72d0 2460 if (new_reg->builtin)
c19d1205 2461 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2462
c19d1205
ZW
2463 /* Only warn about a redefinition if it's not defined as the
2464 same register. */
d3ce72d0 2465 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2466 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2467
d929913e 2468 return NULL;
c19d1205 2469 }
b99bd4ef 2470
c19d1205 2471 name = xstrdup (str);
325801bd 2472 new_reg = XNEW (struct reg_entry);
b99bd4ef 2473
d3ce72d0
NC
2474 new_reg->name = name;
2475 new_reg->number = number;
2476 new_reg->type = type;
2477 new_reg->builtin = FALSE;
2478 new_reg->neon = NULL;
b99bd4ef 2479
d3ce72d0 2480 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2481 abort ();
5f4273c7 2482
d3ce72d0 2483 return new_reg;
dcbf9037
JB
2484}
2485
2486static void
2487insert_neon_reg_alias (char *str, int number, int type,
477330fc 2488 struct neon_typed_alias *atype)
dcbf9037
JB
2489{
2490 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2491
dcbf9037
JB
2492 if (!reg)
2493 {
2494 first_error (_("attempt to redefine typed alias"));
2495 return;
2496 }
5f4273c7 2497
dcbf9037
JB
2498 if (atype)
2499 {
325801bd 2500 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2501 *reg->neon = *atype;
2502 }
c19d1205 2503}
b99bd4ef 2504
c19d1205 2505/* Look for the .req directive. This is of the form:
b99bd4ef 2506
c19d1205 2507 new_register_name .req existing_register_name
b99bd4ef 2508
c19d1205 2509 If we find one, or if it looks sufficiently like one that we want to
d929913e 2510 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2511
d929913e 2512static bfd_boolean
c19d1205
ZW
2513create_register_alias (char * newname, char *p)
2514{
2515 struct reg_entry *old;
2516 char *oldname, *nbuf;
2517 size_t nlen;
b99bd4ef 2518
c19d1205
ZW
2519 /* The input scrubber ensures that whitespace after the mnemonic is
2520 collapsed to single spaces. */
2521 oldname = p;
2522 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2523 return FALSE;
b99bd4ef 2524
c19d1205
ZW
2525 oldname += 6;
2526 if (*oldname == '\0')
d929913e 2527 return FALSE;
b99bd4ef 2528
21d799b5 2529 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2530 if (!old)
b99bd4ef 2531 {
c19d1205 2532 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2533 return TRUE;
b99bd4ef
NC
2534 }
2535
c19d1205
ZW
2536 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2537 the desired alias name, and p points to its end. If not, then
2538 the desired alias name is in the global original_case_string. */
2539#ifdef TC_CASE_SENSITIVE
2540 nlen = p - newname;
2541#else
2542 newname = original_case_string;
2543 nlen = strlen (newname);
2544#endif
b99bd4ef 2545
29a2809e 2546 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2547
c19d1205
ZW
2548 /* Create aliases under the new name as stated; an all-lowercase
2549 version of the new name; and an all-uppercase version of the new
2550 name. */
d929913e
NC
2551 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2552 {
2553 for (p = nbuf; *p; p++)
2554 *p = TOUPPER (*p);
c19d1205 2555
d929913e
NC
2556 if (strncmp (nbuf, newname, nlen))
2557 {
2558 /* If this attempt to create an additional alias fails, do not bother
2559 trying to create the all-lower case alias. We will fail and issue
2560 a second, duplicate error message. This situation arises when the
2561 programmer does something like:
2562 foo .req r0
2563 Foo .req r1
2564 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2565 the artificial FOO alias because it has already been created by the
d929913e
NC
2566 first .req. */
2567 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2568 {
2569 free (nbuf);
2570 return TRUE;
2571 }
d929913e 2572 }
c19d1205 2573
d929913e
NC
2574 for (p = nbuf; *p; p++)
2575 *p = TOLOWER (*p);
c19d1205 2576
d929913e
NC
2577 if (strncmp (nbuf, newname, nlen))
2578 insert_reg_alias (nbuf, old->number, old->type);
2579 }
c19d1205 2580
e1fa0163 2581 free (nbuf);
d929913e 2582 return TRUE;
b99bd4ef
NC
2583}
2584
dcbf9037
JB
2585/* Create a Neon typed/indexed register alias using directives, e.g.:
2586 X .dn d5.s32[1]
2587 Y .qn 6.s16
2588 Z .dn d7
2589 T .dn Z[0]
2590 These typed registers can be used instead of the types specified after the
2591 Neon mnemonic, so long as all operands given have types. Types can also be
2592 specified directly, e.g.:
5f4273c7 2593 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2594
c921be7d 2595static bfd_boolean
dcbf9037
JB
2596create_neon_reg_alias (char *newname, char *p)
2597{
2598 enum arm_reg_type basetype;
2599 struct reg_entry *basereg;
2600 struct reg_entry mybasereg;
2601 struct neon_type ntype;
2602 struct neon_typed_alias typeinfo;
12d6b0b7 2603 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2604 int namelen;
5f4273c7 2605
dcbf9037
JB
2606 typeinfo.defined = 0;
2607 typeinfo.eltype.type = NT_invtype;
2608 typeinfo.eltype.size = -1;
2609 typeinfo.index = -1;
5f4273c7 2610
dcbf9037 2611 nameend = p;
5f4273c7 2612
dcbf9037
JB
2613 if (strncmp (p, " .dn ", 5) == 0)
2614 basetype = REG_TYPE_VFD;
2615 else if (strncmp (p, " .qn ", 5) == 0)
2616 basetype = REG_TYPE_NQ;
2617 else
c921be7d 2618 return FALSE;
5f4273c7 2619
dcbf9037 2620 p += 5;
5f4273c7 2621
dcbf9037 2622 if (*p == '\0')
c921be7d 2623 return FALSE;
5f4273c7 2624
dcbf9037
JB
2625 basereg = arm_reg_parse_multi (&p);
2626
2627 if (basereg && basereg->type != basetype)
2628 {
2629 as_bad (_("bad type for register"));
c921be7d 2630 return FALSE;
dcbf9037
JB
2631 }
2632
2633 if (basereg == NULL)
2634 {
2635 expressionS exp;
2636 /* Try parsing as an integer. */
2637 my_get_expression (&exp, &p, GE_NO_PREFIX);
2638 if (exp.X_op != O_constant)
477330fc
RM
2639 {
2640 as_bad (_("expression must be constant"));
2641 return FALSE;
2642 }
dcbf9037
JB
2643 basereg = &mybasereg;
2644 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2645 : exp.X_add_number;
dcbf9037
JB
2646 basereg->neon = 0;
2647 }
2648
2649 if (basereg->neon)
2650 typeinfo = *basereg->neon;
2651
2652 if (parse_neon_type (&ntype, &p) == SUCCESS)
2653 {
2654 /* We got a type. */
2655 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2656 {
2657 as_bad (_("can't redefine the type of a register alias"));
2658 return FALSE;
2659 }
5f4273c7 2660
dcbf9037
JB
2661 typeinfo.defined |= NTA_HASTYPE;
2662 if (ntype.elems != 1)
477330fc
RM
2663 {
2664 as_bad (_("you must specify a single type only"));
2665 return FALSE;
2666 }
dcbf9037
JB
2667 typeinfo.eltype = ntype.el[0];
2668 }
5f4273c7 2669
dcbf9037
JB
2670 if (skip_past_char (&p, '[') == SUCCESS)
2671 {
2672 expressionS exp;
2673 /* We got a scalar index. */
5f4273c7 2674
dcbf9037 2675 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2676 {
2677 as_bad (_("can't redefine the index of a scalar alias"));
2678 return FALSE;
2679 }
5f4273c7 2680
dcbf9037 2681 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2682
dcbf9037 2683 if (exp.X_op != O_constant)
477330fc
RM
2684 {
2685 as_bad (_("scalar index must be constant"));
2686 return FALSE;
2687 }
5f4273c7 2688
dcbf9037
JB
2689 typeinfo.defined |= NTA_HASINDEX;
2690 typeinfo.index = exp.X_add_number;
5f4273c7 2691
dcbf9037 2692 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2693 {
2694 as_bad (_("expecting ]"));
2695 return FALSE;
2696 }
dcbf9037
JB
2697 }
2698
15735687
NS
2699 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2700 the desired alias name, and p points to its end. If not, then
2701 the desired alias name is in the global original_case_string. */
2702#ifdef TC_CASE_SENSITIVE
dcbf9037 2703 namelen = nameend - newname;
15735687
NS
2704#else
2705 newname = original_case_string;
2706 namelen = strlen (newname);
2707#endif
2708
29a2809e 2709 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2710
dcbf9037 2711 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2712 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2713
dcbf9037
JB
2714 /* Insert name in all uppercase. */
2715 for (p = namebuf; *p; p++)
2716 *p = TOUPPER (*p);
5f4273c7 2717
dcbf9037
JB
2718 if (strncmp (namebuf, newname, namelen))
2719 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2720 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2721
dcbf9037
JB
2722 /* Insert name in all lowercase. */
2723 for (p = namebuf; *p; p++)
2724 *p = TOLOWER (*p);
5f4273c7 2725
dcbf9037
JB
2726 if (strncmp (namebuf, newname, namelen))
2727 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2728 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2729
e1fa0163 2730 free (namebuf);
c921be7d 2731 return TRUE;
dcbf9037
JB
2732}
2733
c19d1205
ZW
2734/* Should never be called, as .req goes between the alias and the
2735 register name, not at the beginning of the line. */
c921be7d 2736
b99bd4ef 2737static void
c19d1205 2738s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2739{
c19d1205
ZW
2740 as_bad (_("invalid syntax for .req directive"));
2741}
b99bd4ef 2742
dcbf9037
JB
2743static void
2744s_dn (int a ATTRIBUTE_UNUSED)
2745{
2746 as_bad (_("invalid syntax for .dn directive"));
2747}
2748
2749static void
2750s_qn (int a ATTRIBUTE_UNUSED)
2751{
2752 as_bad (_("invalid syntax for .qn directive"));
2753}
2754
c19d1205
ZW
2755/* The .unreq directive deletes an alias which was previously defined
2756 by .req. For example:
b99bd4ef 2757
c19d1205
ZW
2758 my_alias .req r11
2759 .unreq my_alias */
b99bd4ef
NC
2760
2761static void
c19d1205 2762s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2763{
c19d1205
ZW
2764 char * name;
2765 char saved_char;
b99bd4ef 2766
c19d1205
ZW
2767 name = input_line_pointer;
2768
2769 while (*input_line_pointer != 0
2770 && *input_line_pointer != ' '
2771 && *input_line_pointer != '\n')
2772 ++input_line_pointer;
2773
2774 saved_char = *input_line_pointer;
2775 *input_line_pointer = 0;
2776
2777 if (!*name)
2778 as_bad (_("invalid syntax for .unreq directive"));
2779 else
2780 {
21d799b5 2781 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2782 name);
c19d1205
ZW
2783
2784 if (!reg)
2785 as_bad (_("unknown register alias '%s'"), name);
2786 else if (reg->builtin)
a1727c1a 2787 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2788 name);
2789 else
2790 {
d929913e
NC
2791 char * p;
2792 char * nbuf;
2793
db0bc284 2794 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2795 free ((char *) reg->name);
477330fc
RM
2796 if (reg->neon)
2797 free (reg->neon);
c19d1205 2798 free (reg);
d929913e
NC
2799
2800 /* Also locate the all upper case and all lower case versions.
2801 Do not complain if we cannot find one or the other as it
2802 was probably deleted above. */
5f4273c7 2803
d929913e
NC
2804 nbuf = strdup (name);
2805 for (p = nbuf; *p; p++)
2806 *p = TOUPPER (*p);
21d799b5 2807 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2808 if (reg)
2809 {
db0bc284 2810 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2811 free ((char *) reg->name);
2812 if (reg->neon)
2813 free (reg->neon);
2814 free (reg);
2815 }
2816
2817 for (p = nbuf; *p; p++)
2818 *p = TOLOWER (*p);
21d799b5 2819 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2820 if (reg)
2821 {
db0bc284 2822 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2823 free ((char *) reg->name);
2824 if (reg->neon)
2825 free (reg->neon);
2826 free (reg);
2827 }
2828
2829 free (nbuf);
c19d1205
ZW
2830 }
2831 }
b99bd4ef 2832
c19d1205 2833 *input_line_pointer = saved_char;
b99bd4ef
NC
2834 demand_empty_rest_of_line ();
2835}
2836
c19d1205
ZW
2837/* Directives: Instruction set selection. */
2838
2839#ifdef OBJ_ELF
2840/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2841 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2842 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2843 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2844
cd000bff
DJ
2845/* Create a new mapping symbol for the transition to STATE. */
2846
2847static void
2848make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2849{
a737bd4d 2850 symbolS * symbolP;
c19d1205
ZW
2851 const char * symname;
2852 int type;
b99bd4ef 2853
c19d1205 2854 switch (state)
b99bd4ef 2855 {
c19d1205
ZW
2856 case MAP_DATA:
2857 symname = "$d";
2858 type = BSF_NO_FLAGS;
2859 break;
2860 case MAP_ARM:
2861 symname = "$a";
2862 type = BSF_NO_FLAGS;
2863 break;
2864 case MAP_THUMB:
2865 symname = "$t";
2866 type = BSF_NO_FLAGS;
2867 break;
c19d1205
ZW
2868 default:
2869 abort ();
2870 }
2871
cd000bff 2872 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2873 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2874
2875 switch (state)
2876 {
2877 case MAP_ARM:
2878 THUMB_SET_FUNC (symbolP, 0);
2879 ARM_SET_THUMB (symbolP, 0);
2880 ARM_SET_INTERWORK (symbolP, support_interwork);
2881 break;
2882
2883 case MAP_THUMB:
2884 THUMB_SET_FUNC (symbolP, 1);
2885 ARM_SET_THUMB (symbolP, 1);
2886 ARM_SET_INTERWORK (symbolP, support_interwork);
2887 break;
2888
2889 case MAP_DATA:
2890 default:
cd000bff
DJ
2891 break;
2892 }
2893
2894 /* Save the mapping symbols for future reference. Also check that
2895 we do not place two mapping symbols at the same offset within a
2896 frag. We'll handle overlap between frags in
2de7820f
JZ
2897 check_mapping_symbols.
2898
2899 If .fill or other data filling directive generates zero sized data,
2900 the mapping symbol for the following code will have the same value
2901 as the one generated for the data filling directive. In this case,
2902 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2903 if (value == 0)
2904 {
2de7820f
JZ
2905 if (frag->tc_frag_data.first_map != NULL)
2906 {
2907 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2908 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2909 }
cd000bff
DJ
2910 frag->tc_frag_data.first_map = symbolP;
2911 }
2912 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2913 {
2914 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2915 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2916 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2917 }
cd000bff
DJ
2918 frag->tc_frag_data.last_map = symbolP;
2919}
2920
2921/* We must sometimes convert a region marked as code to data during
2922 code alignment, if an odd number of bytes have to be padded. The
2923 code mapping symbol is pushed to an aligned address. */
2924
2925static void
2926insert_data_mapping_symbol (enum mstate state,
2927 valueT value, fragS *frag, offsetT bytes)
2928{
2929 /* If there was already a mapping symbol, remove it. */
2930 if (frag->tc_frag_data.last_map != NULL
2931 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2932 {
2933 symbolS *symp = frag->tc_frag_data.last_map;
2934
2935 if (value == 0)
2936 {
2937 know (frag->tc_frag_data.first_map == symp);
2938 frag->tc_frag_data.first_map = NULL;
2939 }
2940 frag->tc_frag_data.last_map = NULL;
2941 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2942 }
cd000bff
DJ
2943
2944 make_mapping_symbol (MAP_DATA, value, frag);
2945 make_mapping_symbol (state, value + bytes, frag);
2946}
2947
2948static void mapping_state_2 (enum mstate state, int max_chars);
2949
2950/* Set the mapping state to STATE. Only call this when about to
2951 emit some STATE bytes to the file. */
2952
4e9aaefb 2953#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2954void
2955mapping_state (enum mstate state)
2956{
940b5ce0
DJ
2957 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2958
cd000bff
DJ
2959 if (mapstate == state)
2960 /* The mapping symbol has already been emitted.
2961 There is nothing else to do. */
2962 return;
49c62a33
NC
2963
2964 if (state == MAP_ARM || state == MAP_THUMB)
2965 /* PR gas/12931
2966 All ARM instructions require 4-byte alignment.
2967 (Almost) all Thumb instructions require 2-byte alignment.
2968
2969 When emitting instructions into any section, mark the section
2970 appropriately.
2971
2972 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2973 but themselves require 2-byte alignment; this applies to some
33eaf5de 2974 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2975 literal pool generation or an explicit .align >=2, both of
2976 which will cause the section to me marked with sufficient
2977 alignment. Thus, we don't handle those cases here. */
2978 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2979
2980 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2981 /* This case will be evaluated later. */
cd000bff 2982 return;
cd000bff
DJ
2983
2984 mapping_state_2 (state, 0);
cd000bff
DJ
2985}
2986
2987/* Same as mapping_state, but MAX_CHARS bytes have already been
2988 allocated. Put the mapping symbol that far back. */
2989
2990static void
2991mapping_state_2 (enum mstate state, int max_chars)
2992{
940b5ce0
DJ
2993 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2994
2995 if (!SEG_NORMAL (now_seg))
2996 return;
2997
cd000bff
DJ
2998 if (mapstate == state)
2999 /* The mapping symbol has already been emitted.
3000 There is nothing else to do. */
3001 return;
3002
4e9aaefb
SA
3003 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3004 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3005 {
3006 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3007 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3008
3009 if (add_symbol)
3010 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3011 }
3012
cd000bff
DJ
3013 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3014 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3015}
4e9aaefb 3016#undef TRANSITION
c19d1205 3017#else
d3106081
NS
3018#define mapping_state(x) ((void)0)
3019#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3020#endif
3021
3022/* Find the real, Thumb encoded start of a Thumb function. */
3023
4343666d 3024#ifdef OBJ_COFF
c19d1205
ZW
3025static symbolS *
3026find_real_start (symbolS * symbolP)
3027{
3028 char * real_start;
3029 const char * name = S_GET_NAME (symbolP);
3030 symbolS * new_target;
3031
3032 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3033#define STUB_NAME ".real_start_of"
3034
3035 if (name == NULL)
3036 abort ();
3037
37f6032b
ZW
3038 /* The compiler may generate BL instructions to local labels because
3039 it needs to perform a branch to a far away location. These labels
3040 do not have a corresponding ".real_start_of" label. We check
3041 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3042 the ".real_start_of" convention for nonlocal branches. */
3043 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3044 return symbolP;
3045
e1fa0163 3046 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3047 new_target = symbol_find (real_start);
e1fa0163 3048 free (real_start);
c19d1205
ZW
3049
3050 if (new_target == NULL)
3051 {
bd3ba5d1 3052 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3053 new_target = symbolP;
3054 }
3055
c19d1205
ZW
3056 return new_target;
3057}
4343666d 3058#endif
c19d1205
ZW
3059
3060static void
3061opcode_select (int width)
3062{
3063 switch (width)
3064 {
3065 case 16:
3066 if (! thumb_mode)
3067 {
e74cfd16 3068 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3069 as_bad (_("selected processor does not support THUMB opcodes"));
3070
3071 thumb_mode = 1;
3072 /* No need to force the alignment, since we will have been
3073 coming from ARM mode, which is word-aligned. */
3074 record_alignment (now_seg, 1);
3075 }
c19d1205
ZW
3076 break;
3077
3078 case 32:
3079 if (thumb_mode)
3080 {
e74cfd16 3081 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3082 as_bad (_("selected processor does not support ARM opcodes"));
3083
3084 thumb_mode = 0;
3085
3086 if (!need_pass_2)
3087 frag_align (2, 0, 0);
3088
3089 record_alignment (now_seg, 1);
3090 }
c19d1205
ZW
3091 break;
3092
3093 default:
3094 as_bad (_("invalid instruction size selected (%d)"), width);
3095 }
3096}
3097
3098static void
3099s_arm (int ignore ATTRIBUTE_UNUSED)
3100{
3101 opcode_select (32);
3102 demand_empty_rest_of_line ();
3103}
3104
3105static void
3106s_thumb (int ignore ATTRIBUTE_UNUSED)
3107{
3108 opcode_select (16);
3109 demand_empty_rest_of_line ();
3110}
3111
3112static void
3113s_code (int unused ATTRIBUTE_UNUSED)
3114{
3115 int temp;
3116
3117 temp = get_absolute_expression ();
3118 switch (temp)
3119 {
3120 case 16:
3121 case 32:
3122 opcode_select (temp);
3123 break;
3124
3125 default:
3126 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3127 }
3128}
3129
3130static void
3131s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3132{
3133 /* If we are not already in thumb mode go into it, EVEN if
3134 the target processor does not support thumb instructions.
3135 This is used by gcc/config/arm/lib1funcs.asm for example
3136 to compile interworking support functions even if the
3137 target processor should not support interworking. */
3138 if (! thumb_mode)
3139 {
3140 thumb_mode = 2;
3141 record_alignment (now_seg, 1);
3142 }
3143
3144 demand_empty_rest_of_line ();
3145}
3146
3147static void
3148s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3149{
3150 s_thumb (0);
3151
3152 /* The following label is the name/address of the start of a Thumb function.
3153 We need to know this for the interworking support. */
3154 label_is_thumb_function_name = TRUE;
3155}
3156
3157/* Perform a .set directive, but also mark the alias as
3158 being a thumb function. */
3159
3160static void
3161s_thumb_set (int equiv)
3162{
3163 /* XXX the following is a duplicate of the code for s_set() in read.c
3164 We cannot just call that code as we need to get at the symbol that
3165 is created. */
3166 char * name;
3167 char delim;
3168 char * end_name;
3169 symbolS * symbolP;
3170
3171 /* Especial apologies for the random logic:
3172 This just grew, and could be parsed much more simply!
3173 Dean - in haste. */
d02603dc 3174 delim = get_symbol_name (& name);
c19d1205 3175 end_name = input_line_pointer;
d02603dc 3176 (void) restore_line_pointer (delim);
c19d1205
ZW
3177
3178 if (*input_line_pointer != ',')
3179 {
3180 *end_name = 0;
3181 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3182 *end_name = delim;
3183 ignore_rest_of_line ();
3184 return;
3185 }
3186
3187 input_line_pointer++;
3188 *end_name = 0;
3189
3190 if (name[0] == '.' && name[1] == '\0')
3191 {
3192 /* XXX - this should not happen to .thumb_set. */
3193 abort ();
3194 }
3195
3196 if ((symbolP = symbol_find (name)) == NULL
3197 && (symbolP = md_undefined_symbol (name)) == NULL)
3198 {
3199#ifndef NO_LISTING
3200 /* When doing symbol listings, play games with dummy fragments living
3201 outside the normal fragment chain to record the file and line info
c19d1205 3202 for this symbol. */
b99bd4ef
NC
3203 if (listing & LISTING_SYMBOLS)
3204 {
3205 extern struct list_info_struct * listing_tail;
21d799b5 3206 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3207
3208 memset (dummy_frag, 0, sizeof (fragS));
3209 dummy_frag->fr_type = rs_fill;
3210 dummy_frag->line = listing_tail;
3211 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3212 dummy_frag->fr_symbol = symbolP;
3213 }
3214 else
3215#endif
3216 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3217
3218#ifdef OBJ_COFF
3219 /* "set" symbols are local unless otherwise specified. */
3220 SF_SET_LOCAL (symbolP);
3221#endif /* OBJ_COFF */
3222 } /* Make a new symbol. */
3223
3224 symbol_table_insert (symbolP);
3225
3226 * end_name = delim;
3227
3228 if (equiv
3229 && S_IS_DEFINED (symbolP)
3230 && S_GET_SEGMENT (symbolP) != reg_section)
3231 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3232
3233 pseudo_set (symbolP);
3234
3235 demand_empty_rest_of_line ();
3236
c19d1205 3237 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3238
3239 THUMB_SET_FUNC (symbolP, 1);
3240 ARM_SET_THUMB (symbolP, 1);
3241#if defined OBJ_ELF || defined OBJ_COFF
3242 ARM_SET_INTERWORK (symbolP, support_interwork);
3243#endif
3244}
3245
c19d1205 3246/* Directives: Mode selection. */
b99bd4ef 3247
c19d1205
ZW
3248/* .syntax [unified|divided] - choose the new unified syntax
3249 (same for Arm and Thumb encoding, modulo slight differences in what
3250 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3251static void
c19d1205 3252s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3253{
c19d1205
ZW
3254 char *name, delim;
3255
d02603dc 3256 delim = get_symbol_name (& name);
c19d1205
ZW
3257
3258 if (!strcasecmp (name, "unified"))
3259 unified_syntax = TRUE;
3260 else if (!strcasecmp (name, "divided"))
3261 unified_syntax = FALSE;
3262 else
3263 {
3264 as_bad (_("unrecognized syntax mode \"%s\""), name);
3265 return;
3266 }
d02603dc 3267 (void) restore_line_pointer (delim);
b99bd4ef
NC
3268 demand_empty_rest_of_line ();
3269}
3270
c19d1205
ZW
3271/* Directives: sectioning and alignment. */
3272
c19d1205
ZW
3273static void
3274s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3275{
c19d1205
ZW
3276 /* We don't support putting frags in the BSS segment, we fake it by
3277 marking in_bss, then looking at s_skip for clues. */
3278 subseg_set (bss_section, 0);
3279 demand_empty_rest_of_line ();
cd000bff
DJ
3280
3281#ifdef md_elf_section_change_hook
3282 md_elf_section_change_hook ();
3283#endif
c19d1205 3284}
b99bd4ef 3285
c19d1205
ZW
3286static void
3287s_even (int ignore ATTRIBUTE_UNUSED)
3288{
3289 /* Never make frag if expect extra pass. */
3290 if (!need_pass_2)
3291 frag_align (1, 0, 0);
b99bd4ef 3292
c19d1205 3293 record_alignment (now_seg, 1);
b99bd4ef 3294
c19d1205 3295 demand_empty_rest_of_line ();
b99bd4ef
NC
3296}
3297
2e6976a8
DG
3298/* Directives: CodeComposer Studio. */
3299
3300/* .ref (for CodeComposer Studio syntax only). */
3301static void
3302s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3303{
3304 if (codecomposer_syntax)
3305 ignore_rest_of_line ();
3306 else
3307 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3308}
3309
3310/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3311 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3312static void
3313asmfunc_debug (const char * name)
3314{
3315 static const char * last_name = NULL;
3316
3317 if (name != NULL)
3318 {
3319 gas_assert (last_name == NULL);
3320 last_name = name;
3321
3322 if (debug_type == DEBUG_STABS)
3323 stabs_generate_asm_func (name, name);
3324 }
3325 else
3326 {
3327 gas_assert (last_name != NULL);
3328
3329 if (debug_type == DEBUG_STABS)
3330 stabs_generate_asm_endfunc (last_name, last_name);
3331
3332 last_name = NULL;
3333 }
3334}
3335
3336static void
3337s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3338{
3339 if (codecomposer_syntax)
3340 {
3341 switch (asmfunc_state)
3342 {
3343 case OUTSIDE_ASMFUNC:
3344 asmfunc_state = WAITING_ASMFUNC_NAME;
3345 break;
3346
3347 case WAITING_ASMFUNC_NAME:
3348 as_bad (_(".asmfunc repeated."));
3349 break;
3350
3351 case WAITING_ENDASMFUNC:
3352 as_bad (_(".asmfunc without function."));
3353 break;
3354 }
3355 demand_empty_rest_of_line ();
3356 }
3357 else
3358 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3359}
3360
3361static void
3362s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3363{
3364 if (codecomposer_syntax)
3365 {
3366 switch (asmfunc_state)
3367 {
3368 case OUTSIDE_ASMFUNC:
3369 as_bad (_(".endasmfunc without a .asmfunc."));
3370 break;
3371
3372 case WAITING_ASMFUNC_NAME:
3373 as_bad (_(".endasmfunc without function."));
3374 break;
3375
3376 case WAITING_ENDASMFUNC:
3377 asmfunc_state = OUTSIDE_ASMFUNC;
3378 asmfunc_debug (NULL);
3379 break;
3380 }
3381 demand_empty_rest_of_line ();
3382 }
3383 else
3384 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3385}
3386
3387static void
3388s_ccs_def (int name)
3389{
3390 if (codecomposer_syntax)
3391 s_globl (name);
3392 else
3393 as_bad (_(".def pseudo-op only available with -mccs flag."));
3394}
3395
c19d1205 3396/* Directives: Literal pools. */
a737bd4d 3397
c19d1205
ZW
3398static literal_pool *
3399find_literal_pool (void)
a737bd4d 3400{
c19d1205 3401 literal_pool * pool;
a737bd4d 3402
c19d1205 3403 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3404 {
c19d1205
ZW
3405 if (pool->section == now_seg
3406 && pool->sub_section == now_subseg)
3407 break;
a737bd4d
NC
3408 }
3409
c19d1205 3410 return pool;
a737bd4d
NC
3411}
3412
c19d1205
ZW
3413static literal_pool *
3414find_or_make_literal_pool (void)
a737bd4d 3415{
c19d1205
ZW
3416 /* Next literal pool ID number. */
3417 static unsigned int latest_pool_num = 1;
3418 literal_pool * pool;
a737bd4d 3419
c19d1205 3420 pool = find_literal_pool ();
a737bd4d 3421
c19d1205 3422 if (pool == NULL)
a737bd4d 3423 {
c19d1205 3424 /* Create a new pool. */
325801bd 3425 pool = XNEW (literal_pool);
c19d1205
ZW
3426 if (! pool)
3427 return NULL;
a737bd4d 3428
c19d1205
ZW
3429 pool->next_free_entry = 0;
3430 pool->section = now_seg;
3431 pool->sub_section = now_subseg;
3432 pool->next = list_of_pools;
3433 pool->symbol = NULL;
8335d6aa 3434 pool->alignment = 2;
c19d1205
ZW
3435
3436 /* Add it to the list. */
3437 list_of_pools = pool;
a737bd4d 3438 }
a737bd4d 3439
c19d1205
ZW
3440 /* New pools, and emptied pools, will have a NULL symbol. */
3441 if (pool->symbol == NULL)
a737bd4d 3442 {
c19d1205
ZW
3443 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3444 (valueT) 0, &zero_address_frag);
3445 pool->id = latest_pool_num ++;
a737bd4d
NC
3446 }
3447
c19d1205
ZW
3448 /* Done. */
3449 return pool;
a737bd4d
NC
3450}
3451
c19d1205 3452/* Add the literal in the global 'inst'
5f4273c7 3453 structure to the relevant literal pool. */
b99bd4ef
NC
3454
3455static int
8335d6aa 3456add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3457{
8335d6aa
JW
3458#define PADDING_SLOT 0x1
3459#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3460 literal_pool * pool;
8335d6aa
JW
3461 unsigned int entry, pool_size = 0;
3462 bfd_boolean padding_slot_p = FALSE;
e56c722b 3463 unsigned imm1 = 0;
8335d6aa
JW
3464 unsigned imm2 = 0;
3465
3466 if (nbytes == 8)
3467 {
3468 imm1 = inst.operands[1].imm;
3469 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3470 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3471 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3472 if (target_big_endian)
3473 {
3474 imm1 = imm2;
3475 imm2 = inst.operands[1].imm;
3476 }
3477 }
b99bd4ef 3478
c19d1205
ZW
3479 pool = find_or_make_literal_pool ();
3480
3481 /* Check if this literal value is already in the pool. */
3482 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3483 {
8335d6aa
JW
3484 if (nbytes == 4)
3485 {
e2b0ab59
AV
3486 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3487 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3488 && (pool->literals[entry].X_add_number
e2b0ab59 3489 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3490 && (pool->literals[entry].X_md == nbytes)
3491 && (pool->literals[entry].X_unsigned
e2b0ab59 3492 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3493 break;
3494
e2b0ab59
AV
3495 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3496 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3497 && (pool->literals[entry].X_add_number
e2b0ab59 3498 == inst.relocs[0].exp.X_add_number)
8335d6aa 3499 && (pool->literals[entry].X_add_symbol
e2b0ab59 3500 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3501 && (pool->literals[entry].X_op_symbol
e2b0ab59 3502 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3503 && (pool->literals[entry].X_md == nbytes))
3504 break;
3505 }
3506 else if ((nbytes == 8)
3507 && !(pool_size & 0x7)
3508 && ((entry + 1) != pool->next_free_entry)
3509 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3510 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3511 && (pool->literals[entry].X_unsigned
e2b0ab59 3512 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3513 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3514 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3515 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3516 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3517 break;
3518
8335d6aa
JW
3519 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3520 if (padding_slot_p && (nbytes == 4))
c19d1205 3521 break;
8335d6aa
JW
3522
3523 pool_size += 4;
b99bd4ef
NC
3524 }
3525
c19d1205
ZW
3526 /* Do we need to create a new entry? */
3527 if (entry == pool->next_free_entry)
3528 {
3529 if (entry >= MAX_LITERAL_POOL_SIZE)
3530 {
3531 inst.error = _("literal pool overflow");
3532 return FAIL;
3533 }
3534
8335d6aa
JW
3535 if (nbytes == 8)
3536 {
3537 /* For 8-byte entries, we align to an 8-byte boundary,
3538 and split it into two 4-byte entries, because on 32-bit
3539 host, 8-byte constants are treated as big num, thus
3540 saved in "generic_bignum" which will be overwritten
3541 by later assignments.
3542
3543 We also need to make sure there is enough space for
3544 the split.
3545
3546 We also check to make sure the literal operand is a
3547 constant number. */
e2b0ab59
AV
3548 if (!(inst.relocs[0].exp.X_op == O_constant
3549 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3550 {
3551 inst.error = _("invalid type for literal pool");
3552 return FAIL;
3553 }
3554 else if (pool_size & 0x7)
3555 {
3556 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3557 {
3558 inst.error = _("literal pool overflow");
3559 return FAIL;
3560 }
3561
e2b0ab59 3562 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3563 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3564 pool->literals[entry].X_add_number = 0;
3565 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3566 pool->next_free_entry += 1;
3567 pool_size += 4;
3568 }
3569 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3570 {
3571 inst.error = _("literal pool overflow");
3572 return FAIL;
3573 }
3574
e2b0ab59 3575 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3576 pool->literals[entry].X_op = O_constant;
3577 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3578 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3579 pool->literals[entry++].X_md = 4;
e2b0ab59 3580 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3581 pool->literals[entry].X_op = O_constant;
3582 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3583 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3584 pool->literals[entry].X_md = 4;
3585 pool->alignment = 3;
3586 pool->next_free_entry += 1;
3587 }
3588 else
3589 {
e2b0ab59 3590 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3591 pool->literals[entry].X_md = 4;
3592 }
3593
a8040cf2
NC
3594#ifdef OBJ_ELF
3595 /* PR ld/12974: Record the location of the first source line to reference
3596 this entry in the literal pool. If it turns out during linking that the
3597 symbol does not exist we will be able to give an accurate line number for
3598 the (first use of the) missing reference. */
3599 if (debug_type == DEBUG_DWARF2)
3600 dwarf2_where (pool->locs + entry);
3601#endif
c19d1205
ZW
3602 pool->next_free_entry += 1;
3603 }
8335d6aa
JW
3604 else if (padding_slot_p)
3605 {
e2b0ab59 3606 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3607 pool->literals[entry].X_md = nbytes;
3608 }
b99bd4ef 3609
e2b0ab59
AV
3610 inst.relocs[0].exp.X_op = O_symbol;
3611 inst.relocs[0].exp.X_add_number = pool_size;
3612 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3613
c19d1205 3614 return SUCCESS;
b99bd4ef
NC
3615}
3616
2e6976a8 3617bfd_boolean
2e57ce7b 3618tc_start_label_without_colon (void)
2e6976a8
DG
3619{
3620 bfd_boolean ret = TRUE;
3621
3622 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3623 {
2e57ce7b 3624 const char *label = input_line_pointer;
2e6976a8
DG
3625
3626 while (!is_end_of_line[(int) label[-1]])
3627 --label;
3628
3629 if (*label == '.')
3630 {
3631 as_bad (_("Invalid label '%s'"), label);
3632 ret = FALSE;
3633 }
3634
3635 asmfunc_debug (label);
3636
3637 asmfunc_state = WAITING_ENDASMFUNC;
3638 }
3639
3640 return ret;
3641}
3642
c19d1205 3643/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3644 a later date assign it a value. That's what these functions do. */
e16bb312 3645
c19d1205
ZW
3646static void
3647symbol_locate (symbolS * symbolP,
3648 const char * name, /* It is copied, the caller can modify. */
3649 segT segment, /* Segment identifier (SEG_<something>). */
3650 valueT valu, /* Symbol value. */
3651 fragS * frag) /* Associated fragment. */
3652{
e57e6ddc 3653 size_t name_length;
c19d1205 3654 char * preserved_copy_of_name;
e16bb312 3655
c19d1205
ZW
3656 name_length = strlen (name) + 1; /* +1 for \0. */
3657 obstack_grow (&notes, name, name_length);
21d799b5 3658 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3659
c19d1205
ZW
3660#ifdef tc_canonicalize_symbol_name
3661 preserved_copy_of_name =
3662 tc_canonicalize_symbol_name (preserved_copy_of_name);
3663#endif
b99bd4ef 3664
c19d1205 3665 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3666
c19d1205
ZW
3667 S_SET_SEGMENT (symbolP, segment);
3668 S_SET_VALUE (symbolP, valu);
3669 symbol_clear_list_pointers (symbolP);
b99bd4ef 3670
c19d1205 3671 symbol_set_frag (symbolP, frag);
b99bd4ef 3672
c19d1205
ZW
3673 /* Link to end of symbol chain. */
3674 {
3675 extern int symbol_table_frozen;
b99bd4ef 3676
c19d1205
ZW
3677 if (symbol_table_frozen)
3678 abort ();
3679 }
b99bd4ef 3680
c19d1205 3681 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3682
c19d1205 3683 obj_symbol_new_hook (symbolP);
b99bd4ef 3684
c19d1205
ZW
3685#ifdef tc_symbol_new_hook
3686 tc_symbol_new_hook (symbolP);
3687#endif
3688
3689#ifdef DEBUG_SYMS
3690 verify_symbol_chain (symbol_rootP, symbol_lastP);
3691#endif /* DEBUG_SYMS */
b99bd4ef
NC
3692}
3693
c19d1205
ZW
3694static void
3695s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3696{
c19d1205
ZW
3697 unsigned int entry;
3698 literal_pool * pool;
3699 char sym_name[20];
b99bd4ef 3700
c19d1205
ZW
3701 pool = find_literal_pool ();
3702 if (pool == NULL
3703 || pool->symbol == NULL
3704 || pool->next_free_entry == 0)
3705 return;
b99bd4ef 3706
c19d1205
ZW
3707 /* Align pool as you have word accesses.
3708 Only make a frag if we have to. */
3709 if (!need_pass_2)
8335d6aa 3710 frag_align (pool->alignment, 0, 0);
b99bd4ef 3711
c19d1205 3712 record_alignment (now_seg, 2);
b99bd4ef 3713
aaca88ef 3714#ifdef OBJ_ELF
47fc6e36
WN
3715 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3716 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3717#endif
c19d1205 3718 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3719
c19d1205
ZW
3720 symbol_locate (pool->symbol, sym_name, now_seg,
3721 (valueT) frag_now_fix (), frag_now);
3722 symbol_table_insert (pool->symbol);
b99bd4ef 3723
c19d1205 3724 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3725
c19d1205
ZW
3726#if defined OBJ_COFF || defined OBJ_ELF
3727 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3728#endif
6c43fab6 3729
c19d1205 3730 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3731 {
3732#ifdef OBJ_ELF
3733 if (debug_type == DEBUG_DWARF2)
3734 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3735#endif
3736 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3737 emit_expr (&(pool->literals[entry]),
3738 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3739 }
b99bd4ef 3740
c19d1205
ZW
3741 /* Mark the pool as empty. */
3742 pool->next_free_entry = 0;
3743 pool->symbol = NULL;
b99bd4ef
NC
3744}
3745
c19d1205
ZW
3746#ifdef OBJ_ELF
3747/* Forward declarations for functions below, in the MD interface
3748 section. */
3749static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3750static valueT create_unwind_entry (int);
3751static void start_unwind_section (const segT, int);
3752static void add_unwind_opcode (valueT, int);
3753static void flush_pending_unwind (void);
b99bd4ef 3754
c19d1205 3755/* Directives: Data. */
b99bd4ef 3756
c19d1205
ZW
3757static void
3758s_arm_elf_cons (int nbytes)
3759{
3760 expressionS exp;
b99bd4ef 3761
c19d1205
ZW
3762#ifdef md_flush_pending_output
3763 md_flush_pending_output ();
3764#endif
b99bd4ef 3765
c19d1205 3766 if (is_it_end_of_statement ())
b99bd4ef 3767 {
c19d1205
ZW
3768 demand_empty_rest_of_line ();
3769 return;
b99bd4ef
NC
3770 }
3771
c19d1205
ZW
3772#ifdef md_cons_align
3773 md_cons_align (nbytes);
3774#endif
b99bd4ef 3775
c19d1205
ZW
3776 mapping_state (MAP_DATA);
3777 do
b99bd4ef 3778 {
c19d1205
ZW
3779 int reloc;
3780 char *base = input_line_pointer;
b99bd4ef 3781
c19d1205 3782 expression (& exp);
b99bd4ef 3783
c19d1205
ZW
3784 if (exp.X_op != O_symbol)
3785 emit_expr (&exp, (unsigned int) nbytes);
3786 else
3787 {
3788 char *before_reloc = input_line_pointer;
3789 reloc = parse_reloc (&input_line_pointer);
3790 if (reloc == -1)
3791 {
3792 as_bad (_("unrecognized relocation suffix"));
3793 ignore_rest_of_line ();
3794 return;
3795 }
3796 else if (reloc == BFD_RELOC_UNUSED)
3797 emit_expr (&exp, (unsigned int) nbytes);
3798 else
3799 {
21d799b5 3800 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3801 bfd_reloc_type_lookup (stdoutput,
3802 (bfd_reloc_code_real_type) reloc);
c19d1205 3803 int size = bfd_get_reloc_size (howto);
b99bd4ef 3804
2fc8bdac
ZW
3805 if (reloc == BFD_RELOC_ARM_PLT32)
3806 {
3807 as_bad (_("(plt) is only valid on branch targets"));
3808 reloc = BFD_RELOC_UNUSED;
3809 size = 0;
3810 }
3811
c19d1205 3812 if (size > nbytes)
992a06ee
AM
3813 as_bad (ngettext ("%s relocations do not fit in %d byte",
3814 "%s relocations do not fit in %d bytes",
3815 nbytes),
c19d1205
ZW
3816 howto->name, nbytes);
3817 else
3818 {
3819 /* We've parsed an expression stopping at O_symbol.
3820 But there may be more expression left now that we
3821 have parsed the relocation marker. Parse it again.
3822 XXX Surely there is a cleaner way to do this. */
3823 char *p = input_line_pointer;
3824 int offset;
325801bd 3825 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3826
c19d1205
ZW
3827 memcpy (save_buf, base, input_line_pointer - base);
3828 memmove (base + (input_line_pointer - before_reloc),
3829 base, before_reloc - base);
3830
3831 input_line_pointer = base + (input_line_pointer-before_reloc);
3832 expression (&exp);
3833 memcpy (base, save_buf, p - base);
3834
3835 offset = nbytes - size;
4b1a927e
AM
3836 p = frag_more (nbytes);
3837 memset (p, 0, nbytes);
c19d1205 3838 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3839 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3840 free (save_buf);
c19d1205
ZW
3841 }
3842 }
3843 }
b99bd4ef 3844 }
c19d1205 3845 while (*input_line_pointer++ == ',');
b99bd4ef 3846
c19d1205
ZW
3847 /* Put terminator back into stream. */
3848 input_line_pointer --;
3849 demand_empty_rest_of_line ();
b99bd4ef
NC
3850}
3851
c921be7d
NC
3852/* Emit an expression containing a 32-bit thumb instruction.
3853 Implementation based on put_thumb32_insn. */
3854
3855static void
3856emit_thumb32_expr (expressionS * exp)
3857{
3858 expressionS exp_high = *exp;
3859
3860 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3861 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3862 exp->X_add_number &= 0xffff;
3863 emit_expr (exp, (unsigned int) THUMB_SIZE);
3864}
3865
3866/* Guess the instruction size based on the opcode. */
3867
3868static int
3869thumb_insn_size (int opcode)
3870{
3871 if ((unsigned int) opcode < 0xe800u)
3872 return 2;
3873 else if ((unsigned int) opcode >= 0xe8000000u)
3874 return 4;
3875 else
3876 return 0;
3877}
3878
3879static bfd_boolean
3880emit_insn (expressionS *exp, int nbytes)
3881{
3882 int size = 0;
3883
3884 if (exp->X_op == O_constant)
3885 {
3886 size = nbytes;
3887
3888 if (size == 0)
3889 size = thumb_insn_size (exp->X_add_number);
3890
3891 if (size != 0)
3892 {
3893 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3894 {
3895 as_bad (_(".inst.n operand too big. "\
3896 "Use .inst.w instead"));
3897 size = 0;
3898 }
3899 else
3900 {
5ee91343
AV
3901 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3902 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 3903 else
5ee91343 3904 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
3905
3906 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3907 emit_thumb32_expr (exp);
3908 else
3909 emit_expr (exp, (unsigned int) size);
3910
3911 it_fsm_post_encode ();
3912 }
3913 }
3914 else
3915 as_bad (_("cannot determine Thumb instruction size. " \
3916 "Use .inst.n/.inst.w instead"));
3917 }
3918 else
3919 as_bad (_("constant expression required"));
3920
3921 return (size != 0);
3922}
3923
3924/* Like s_arm_elf_cons but do not use md_cons_align and
3925 set the mapping state to MAP_ARM/MAP_THUMB. */
3926
3927static void
3928s_arm_elf_inst (int nbytes)
3929{
3930 if (is_it_end_of_statement ())
3931 {
3932 demand_empty_rest_of_line ();
3933 return;
3934 }
3935
3936 /* Calling mapping_state () here will not change ARM/THUMB,
3937 but will ensure not to be in DATA state. */
3938
3939 if (thumb_mode)
3940 mapping_state (MAP_THUMB);
3941 else
3942 {
3943 if (nbytes != 0)
3944 {
3945 as_bad (_("width suffixes are invalid in ARM mode"));
3946 ignore_rest_of_line ();
3947 return;
3948 }
3949
3950 nbytes = 4;
3951
3952 mapping_state (MAP_ARM);
3953 }
3954
3955 do
3956 {
3957 expressionS exp;
3958
3959 expression (& exp);
3960
3961 if (! emit_insn (& exp, nbytes))
3962 {
3963 ignore_rest_of_line ();
3964 return;
3965 }
3966 }
3967 while (*input_line_pointer++ == ',');
3968
3969 /* Put terminator back into stream. */
3970 input_line_pointer --;
3971 demand_empty_rest_of_line ();
3972}
b99bd4ef 3973
c19d1205 3974/* Parse a .rel31 directive. */
b99bd4ef 3975
c19d1205
ZW
3976static void
3977s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3978{
3979 expressionS exp;
3980 char *p;
3981 valueT highbit;
b99bd4ef 3982
c19d1205
ZW
3983 highbit = 0;
3984 if (*input_line_pointer == '1')
3985 highbit = 0x80000000;
3986 else if (*input_line_pointer != '0')
3987 as_bad (_("expected 0 or 1"));
b99bd4ef 3988
c19d1205
ZW
3989 input_line_pointer++;
3990 if (*input_line_pointer != ',')
3991 as_bad (_("missing comma"));
3992 input_line_pointer++;
b99bd4ef 3993
c19d1205
ZW
3994#ifdef md_flush_pending_output
3995 md_flush_pending_output ();
3996#endif
b99bd4ef 3997
c19d1205
ZW
3998#ifdef md_cons_align
3999 md_cons_align (4);
4000#endif
b99bd4ef 4001
c19d1205 4002 mapping_state (MAP_DATA);
b99bd4ef 4003
c19d1205 4004 expression (&exp);
b99bd4ef 4005
c19d1205
ZW
4006 p = frag_more (4);
4007 md_number_to_chars (p, highbit, 4);
4008 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4009 BFD_RELOC_ARM_PREL31);
b99bd4ef 4010
c19d1205 4011 demand_empty_rest_of_line ();
b99bd4ef
NC
4012}
4013
c19d1205 4014/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4015
c19d1205 4016/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4017
c19d1205
ZW
4018static void
4019s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4020{
4021 demand_empty_rest_of_line ();
921e5f0a
PB
4022 if (unwind.proc_start)
4023 {
c921be7d 4024 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4025 return;
4026 }
4027
c19d1205
ZW
4028 /* Mark the start of the function. */
4029 unwind.proc_start = expr_build_dot ();
b99bd4ef 4030
c19d1205
ZW
4031 /* Reset the rest of the unwind info. */
4032 unwind.opcode_count = 0;
4033 unwind.table_entry = NULL;
4034 unwind.personality_routine = NULL;
4035 unwind.personality_index = -1;
4036 unwind.frame_size = 0;
4037 unwind.fp_offset = 0;
fdfde340 4038 unwind.fp_reg = REG_SP;
c19d1205
ZW
4039 unwind.fp_used = 0;
4040 unwind.sp_restored = 0;
4041}
b99bd4ef 4042
b99bd4ef 4043
c19d1205
ZW
4044/* Parse a handlerdata directive. Creates the exception handling table entry
4045 for the function. */
b99bd4ef 4046
c19d1205
ZW
4047static void
4048s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4049{
4050 demand_empty_rest_of_line ();
921e5f0a 4051 if (!unwind.proc_start)
c921be7d 4052 as_bad (MISSING_FNSTART);
921e5f0a 4053
c19d1205 4054 if (unwind.table_entry)
6decc662 4055 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4056
c19d1205
ZW
4057 create_unwind_entry (1);
4058}
a737bd4d 4059
c19d1205 4060/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4061
c19d1205
ZW
4062static void
4063s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4064{
4065 long where;
4066 char *ptr;
4067 valueT val;
940b5ce0 4068 unsigned int marked_pr_dependency;
f02232aa 4069
c19d1205 4070 demand_empty_rest_of_line ();
f02232aa 4071
921e5f0a
PB
4072 if (!unwind.proc_start)
4073 {
c921be7d 4074 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4075 return;
4076 }
4077
c19d1205
ZW
4078 /* Add eh table entry. */
4079 if (unwind.table_entry == NULL)
4080 val = create_unwind_entry (0);
4081 else
4082 val = 0;
f02232aa 4083
c19d1205
ZW
4084 /* Add index table entry. This is two words. */
4085 start_unwind_section (unwind.saved_seg, 1);
4086 frag_align (2, 0, 0);
4087 record_alignment (now_seg, 2);
b99bd4ef 4088
c19d1205 4089 ptr = frag_more (8);
5011093d 4090 memset (ptr, 0, 8);
c19d1205 4091 where = frag_now_fix () - 8;
f02232aa 4092
c19d1205
ZW
4093 /* Self relative offset of the function start. */
4094 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4095 BFD_RELOC_ARM_PREL31);
f02232aa 4096
c19d1205
ZW
4097 /* Indicate dependency on EHABI-defined personality routines to the
4098 linker, if it hasn't been done already. */
940b5ce0
DJ
4099 marked_pr_dependency
4100 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4101 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4102 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4103 {
5f4273c7
NC
4104 static const char *const name[] =
4105 {
4106 "__aeabi_unwind_cpp_pr0",
4107 "__aeabi_unwind_cpp_pr1",
4108 "__aeabi_unwind_cpp_pr2"
4109 };
c19d1205
ZW
4110 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4111 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4112 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4113 |= 1 << unwind.personality_index;
c19d1205 4114 }
f02232aa 4115
c19d1205
ZW
4116 if (val)
4117 /* Inline exception table entry. */
4118 md_number_to_chars (ptr + 4, val, 4);
4119 else
4120 /* Self relative offset of the table entry. */
4121 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4122 BFD_RELOC_ARM_PREL31);
f02232aa 4123
c19d1205
ZW
4124 /* Restore the original section. */
4125 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4126
4127 unwind.proc_start = NULL;
c19d1205 4128}
f02232aa 4129
f02232aa 4130
c19d1205 4131/* Parse an unwind_cantunwind directive. */
b99bd4ef 4132
c19d1205
ZW
4133static void
4134s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4135{
4136 demand_empty_rest_of_line ();
921e5f0a 4137 if (!unwind.proc_start)
c921be7d 4138 as_bad (MISSING_FNSTART);
921e5f0a 4139
c19d1205
ZW
4140 if (unwind.personality_routine || unwind.personality_index != -1)
4141 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4142
c19d1205
ZW
4143 unwind.personality_index = -2;
4144}
b99bd4ef 4145
b99bd4ef 4146
c19d1205 4147/* Parse a personalityindex directive. */
b99bd4ef 4148
c19d1205
ZW
4149static void
4150s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4151{
4152 expressionS exp;
b99bd4ef 4153
921e5f0a 4154 if (!unwind.proc_start)
c921be7d 4155 as_bad (MISSING_FNSTART);
921e5f0a 4156
c19d1205
ZW
4157 if (unwind.personality_routine || unwind.personality_index != -1)
4158 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4159
c19d1205 4160 expression (&exp);
b99bd4ef 4161
c19d1205
ZW
4162 if (exp.X_op != O_constant
4163 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4164 {
c19d1205
ZW
4165 as_bad (_("bad personality routine number"));
4166 ignore_rest_of_line ();
4167 return;
b99bd4ef
NC
4168 }
4169
c19d1205 4170 unwind.personality_index = exp.X_add_number;
b99bd4ef 4171
c19d1205
ZW
4172 demand_empty_rest_of_line ();
4173}
e16bb312 4174
e16bb312 4175
c19d1205 4176/* Parse a personality directive. */
e16bb312 4177
c19d1205
ZW
4178static void
4179s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4180{
4181 char *name, *p, c;
a737bd4d 4182
921e5f0a 4183 if (!unwind.proc_start)
c921be7d 4184 as_bad (MISSING_FNSTART);
921e5f0a 4185
c19d1205
ZW
4186 if (unwind.personality_routine || unwind.personality_index != -1)
4187 as_bad (_("duplicate .personality directive"));
a737bd4d 4188
d02603dc 4189 c = get_symbol_name (& name);
c19d1205 4190 p = input_line_pointer;
d02603dc
NC
4191 if (c == '"')
4192 ++ input_line_pointer;
c19d1205
ZW
4193 unwind.personality_routine = symbol_find_or_make (name);
4194 *p = c;
4195 demand_empty_rest_of_line ();
4196}
e16bb312 4197
e16bb312 4198
c19d1205 4199/* Parse a directive saving core registers. */
e16bb312 4200
c19d1205
ZW
4201static void
4202s_arm_unwind_save_core (void)
e16bb312 4203{
c19d1205
ZW
4204 valueT op;
4205 long range;
4206 int n;
e16bb312 4207
4b5a202f 4208 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4209 if (range == FAIL)
e16bb312 4210 {
c19d1205
ZW
4211 as_bad (_("expected register list"));
4212 ignore_rest_of_line ();
4213 return;
4214 }
e16bb312 4215
c19d1205 4216 demand_empty_rest_of_line ();
e16bb312 4217
c19d1205
ZW
4218 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4219 into .unwind_save {..., sp...}. We aren't bothered about the value of
4220 ip because it is clobbered by calls. */
4221 if (unwind.sp_restored && unwind.fp_reg == 12
4222 && (range & 0x3000) == 0x1000)
4223 {
4224 unwind.opcode_count--;
4225 unwind.sp_restored = 0;
4226 range = (range | 0x2000) & ~0x1000;
4227 unwind.pending_offset = 0;
4228 }
e16bb312 4229
01ae4198
DJ
4230 /* Pop r4-r15. */
4231 if (range & 0xfff0)
c19d1205 4232 {
01ae4198
DJ
4233 /* See if we can use the short opcodes. These pop a block of up to 8
4234 registers starting with r4, plus maybe r14. */
4235 for (n = 0; n < 8; n++)
4236 {
4237 /* Break at the first non-saved register. */
4238 if ((range & (1 << (n + 4))) == 0)
4239 break;
4240 }
4241 /* See if there are any other bits set. */
4242 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4243 {
4244 /* Use the long form. */
4245 op = 0x8000 | ((range >> 4) & 0xfff);
4246 add_unwind_opcode (op, 2);
4247 }
0dd132b6 4248 else
01ae4198
DJ
4249 {
4250 /* Use the short form. */
4251 if (range & 0x4000)
4252 op = 0xa8; /* Pop r14. */
4253 else
4254 op = 0xa0; /* Do not pop r14. */
4255 op |= (n - 1);
4256 add_unwind_opcode (op, 1);
4257 }
c19d1205 4258 }
0dd132b6 4259
c19d1205
ZW
4260 /* Pop r0-r3. */
4261 if (range & 0xf)
4262 {
4263 op = 0xb100 | (range & 0xf);
4264 add_unwind_opcode (op, 2);
0dd132b6
NC
4265 }
4266
c19d1205
ZW
4267 /* Record the number of bytes pushed. */
4268 for (n = 0; n < 16; n++)
4269 {
4270 if (range & (1 << n))
4271 unwind.frame_size += 4;
4272 }
0dd132b6
NC
4273}
4274
c19d1205
ZW
4275
4276/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4277
4278static void
c19d1205 4279s_arm_unwind_save_fpa (int reg)
b99bd4ef 4280{
c19d1205
ZW
4281 expressionS exp;
4282 int num_regs;
4283 valueT op;
b99bd4ef 4284
c19d1205
ZW
4285 /* Get Number of registers to transfer. */
4286 if (skip_past_comma (&input_line_pointer) != FAIL)
4287 expression (&exp);
4288 else
4289 exp.X_op = O_illegal;
b99bd4ef 4290
c19d1205 4291 if (exp.X_op != O_constant)
b99bd4ef 4292 {
c19d1205
ZW
4293 as_bad (_("expected , <constant>"));
4294 ignore_rest_of_line ();
b99bd4ef
NC
4295 return;
4296 }
4297
c19d1205
ZW
4298 num_regs = exp.X_add_number;
4299
4300 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4301 {
c19d1205
ZW
4302 as_bad (_("number of registers must be in the range [1:4]"));
4303 ignore_rest_of_line ();
b99bd4ef
NC
4304 return;
4305 }
4306
c19d1205 4307 demand_empty_rest_of_line ();
b99bd4ef 4308
c19d1205
ZW
4309 if (reg == 4)
4310 {
4311 /* Short form. */
4312 op = 0xb4 | (num_regs - 1);
4313 add_unwind_opcode (op, 1);
4314 }
b99bd4ef
NC
4315 else
4316 {
c19d1205
ZW
4317 /* Long form. */
4318 op = 0xc800 | (reg << 4) | (num_regs - 1);
4319 add_unwind_opcode (op, 2);
b99bd4ef 4320 }
c19d1205 4321 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4322}
4323
c19d1205 4324
fa073d69
MS
4325/* Parse a directive saving VFP registers for ARMv6 and above. */
4326
4327static void
4328s_arm_unwind_save_vfp_armv6 (void)
4329{
4330 int count;
4331 unsigned int start;
4332 valueT op;
4333 int num_vfpv3_regs = 0;
4334 int num_regs_below_16;
efd6b359 4335 bfd_boolean partial_match;
fa073d69 4336
efd6b359
AV
4337 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4338 &partial_match);
fa073d69
MS
4339 if (count == FAIL)
4340 {
4341 as_bad (_("expected register list"));
4342 ignore_rest_of_line ();
4343 return;
4344 }
4345
4346 demand_empty_rest_of_line ();
4347
4348 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4349 than FSTMX/FLDMX-style ones). */
4350
4351 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4352 if (start >= 16)
4353 num_vfpv3_regs = count;
4354 else if (start + count > 16)
4355 num_vfpv3_regs = start + count - 16;
4356
4357 if (num_vfpv3_regs > 0)
4358 {
4359 int start_offset = start > 16 ? start - 16 : 0;
4360 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4361 add_unwind_opcode (op, 2);
4362 }
4363
4364 /* Generate opcode for registers numbered in the range 0 .. 15. */
4365 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4366 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4367 if (num_regs_below_16 > 0)
4368 {
4369 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4370 add_unwind_opcode (op, 2);
4371 }
4372
4373 unwind.frame_size += count * 8;
4374}
4375
4376
4377/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4378
4379static void
c19d1205 4380s_arm_unwind_save_vfp (void)
b99bd4ef 4381{
c19d1205 4382 int count;
ca3f61f7 4383 unsigned int reg;
c19d1205 4384 valueT op;
efd6b359 4385 bfd_boolean partial_match;
b99bd4ef 4386
efd6b359
AV
4387 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4388 &partial_match);
c19d1205 4389 if (count == FAIL)
b99bd4ef 4390 {
c19d1205
ZW
4391 as_bad (_("expected register list"));
4392 ignore_rest_of_line ();
b99bd4ef
NC
4393 return;
4394 }
4395
c19d1205 4396 demand_empty_rest_of_line ();
b99bd4ef 4397
c19d1205 4398 if (reg == 8)
b99bd4ef 4399 {
c19d1205
ZW
4400 /* Short form. */
4401 op = 0xb8 | (count - 1);
4402 add_unwind_opcode (op, 1);
b99bd4ef 4403 }
c19d1205 4404 else
b99bd4ef 4405 {
c19d1205
ZW
4406 /* Long form. */
4407 op = 0xb300 | (reg << 4) | (count - 1);
4408 add_unwind_opcode (op, 2);
b99bd4ef 4409 }
c19d1205
ZW
4410 unwind.frame_size += count * 8 + 4;
4411}
b99bd4ef 4412
b99bd4ef 4413
c19d1205
ZW
4414/* Parse a directive saving iWMMXt data registers. */
4415
4416static void
4417s_arm_unwind_save_mmxwr (void)
4418{
4419 int reg;
4420 int hi_reg;
4421 int i;
4422 unsigned mask = 0;
4423 valueT op;
b99bd4ef 4424
c19d1205
ZW
4425 if (*input_line_pointer == '{')
4426 input_line_pointer++;
b99bd4ef 4427
c19d1205 4428 do
b99bd4ef 4429 {
dcbf9037 4430 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4431
c19d1205 4432 if (reg == FAIL)
b99bd4ef 4433 {
9b7132d3 4434 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4435 goto error;
b99bd4ef
NC
4436 }
4437
c19d1205
ZW
4438 if (mask >> reg)
4439 as_tsktsk (_("register list not in ascending order"));
4440 mask |= 1 << reg;
b99bd4ef 4441
c19d1205
ZW
4442 if (*input_line_pointer == '-')
4443 {
4444 input_line_pointer++;
dcbf9037 4445 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4446 if (hi_reg == FAIL)
4447 {
9b7132d3 4448 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4449 goto error;
4450 }
4451 else if (reg >= hi_reg)
4452 {
4453 as_bad (_("bad register range"));
4454 goto error;
4455 }
4456 for (; reg < hi_reg; reg++)
4457 mask |= 1 << reg;
4458 }
4459 }
4460 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4461
d996d970 4462 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4463
c19d1205 4464 demand_empty_rest_of_line ();
b99bd4ef 4465
708587a4 4466 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4467 the list. */
4468 flush_pending_unwind ();
b99bd4ef 4469
c19d1205 4470 for (i = 0; i < 16; i++)
b99bd4ef 4471 {
c19d1205
ZW
4472 if (mask & (1 << i))
4473 unwind.frame_size += 8;
b99bd4ef
NC
4474 }
4475
c19d1205
ZW
4476 /* Attempt to combine with a previous opcode. We do this because gcc
4477 likes to output separate unwind directives for a single block of
4478 registers. */
4479 if (unwind.opcode_count > 0)
b99bd4ef 4480 {
c19d1205
ZW
4481 i = unwind.opcodes[unwind.opcode_count - 1];
4482 if ((i & 0xf8) == 0xc0)
4483 {
4484 i &= 7;
4485 /* Only merge if the blocks are contiguous. */
4486 if (i < 6)
4487 {
4488 if ((mask & 0xfe00) == (1 << 9))
4489 {
4490 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4491 unwind.opcode_count--;
4492 }
4493 }
4494 else if (i == 6 && unwind.opcode_count >= 2)
4495 {
4496 i = unwind.opcodes[unwind.opcode_count - 2];
4497 reg = i >> 4;
4498 i &= 0xf;
b99bd4ef 4499
c19d1205
ZW
4500 op = 0xffff << (reg - 1);
4501 if (reg > 0
87a1fd79 4502 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4503 {
4504 op = (1 << (reg + i + 1)) - 1;
4505 op &= ~((1 << reg) - 1);
4506 mask |= op;
4507 unwind.opcode_count -= 2;
4508 }
4509 }
4510 }
b99bd4ef
NC
4511 }
4512
c19d1205
ZW
4513 hi_reg = 15;
4514 /* We want to generate opcodes in the order the registers have been
4515 saved, ie. descending order. */
4516 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4517 {
c19d1205
ZW
4518 /* Save registers in blocks. */
4519 if (reg < 0
4520 || !(mask & (1 << reg)))
4521 {
4522 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4523 preceding block. */
c19d1205
ZW
4524 if (reg != hi_reg)
4525 {
4526 if (reg == 9)
4527 {
4528 /* Short form. */
4529 op = 0xc0 | (hi_reg - 10);
4530 add_unwind_opcode (op, 1);
4531 }
4532 else
4533 {
4534 /* Long form. */
4535 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4536 add_unwind_opcode (op, 2);
4537 }
4538 }
4539 hi_reg = reg - 1;
4540 }
b99bd4ef
NC
4541 }
4542
c19d1205
ZW
4543 return;
4544error:
4545 ignore_rest_of_line ();
b99bd4ef
NC
4546}
4547
4548static void
c19d1205 4549s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4550{
c19d1205
ZW
4551 int reg;
4552 int hi_reg;
4553 unsigned mask = 0;
4554 valueT op;
b99bd4ef 4555
c19d1205
ZW
4556 if (*input_line_pointer == '{')
4557 input_line_pointer++;
b99bd4ef 4558
477330fc
RM
4559 skip_whitespace (input_line_pointer);
4560
c19d1205 4561 do
b99bd4ef 4562 {
dcbf9037 4563 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4564
c19d1205
ZW
4565 if (reg == FAIL)
4566 {
9b7132d3 4567 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4568 goto error;
4569 }
b99bd4ef 4570
c19d1205
ZW
4571 reg -= 8;
4572 if (mask >> reg)
4573 as_tsktsk (_("register list not in ascending order"));
4574 mask |= 1 << reg;
b99bd4ef 4575
c19d1205
ZW
4576 if (*input_line_pointer == '-')
4577 {
4578 input_line_pointer++;
dcbf9037 4579 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4580 if (hi_reg == FAIL)
4581 {
9b7132d3 4582 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4583 goto error;
4584 }
4585 else if (reg >= hi_reg)
4586 {
4587 as_bad (_("bad register range"));
4588 goto error;
4589 }
4590 for (; reg < hi_reg; reg++)
4591 mask |= 1 << reg;
4592 }
b99bd4ef 4593 }
c19d1205 4594 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4595
d996d970 4596 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4597
c19d1205
ZW
4598 demand_empty_rest_of_line ();
4599
708587a4 4600 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4601 the list. */
4602 flush_pending_unwind ();
b99bd4ef 4603
c19d1205 4604 for (reg = 0; reg < 16; reg++)
b99bd4ef 4605 {
c19d1205
ZW
4606 if (mask & (1 << reg))
4607 unwind.frame_size += 4;
b99bd4ef 4608 }
c19d1205
ZW
4609 op = 0xc700 | mask;
4610 add_unwind_opcode (op, 2);
4611 return;
4612error:
4613 ignore_rest_of_line ();
b99bd4ef
NC
4614}
4615
c19d1205 4616
fa073d69
MS
4617/* Parse an unwind_save directive.
4618 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4619
b99bd4ef 4620static void
fa073d69 4621s_arm_unwind_save (int arch_v6)
b99bd4ef 4622{
c19d1205
ZW
4623 char *peek;
4624 struct reg_entry *reg;
4625 bfd_boolean had_brace = FALSE;
b99bd4ef 4626
921e5f0a 4627 if (!unwind.proc_start)
c921be7d 4628 as_bad (MISSING_FNSTART);
921e5f0a 4629
c19d1205
ZW
4630 /* Figure out what sort of save we have. */
4631 peek = input_line_pointer;
b99bd4ef 4632
c19d1205 4633 if (*peek == '{')
b99bd4ef 4634 {
c19d1205
ZW
4635 had_brace = TRUE;
4636 peek++;
b99bd4ef
NC
4637 }
4638
c19d1205 4639 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4640
c19d1205 4641 if (!reg)
b99bd4ef 4642 {
c19d1205
ZW
4643 as_bad (_("register expected"));
4644 ignore_rest_of_line ();
b99bd4ef
NC
4645 return;
4646 }
4647
c19d1205 4648 switch (reg->type)
b99bd4ef 4649 {
c19d1205
ZW
4650 case REG_TYPE_FN:
4651 if (had_brace)
4652 {
4653 as_bad (_("FPA .unwind_save does not take a register list"));
4654 ignore_rest_of_line ();
4655 return;
4656 }
93ac2687 4657 input_line_pointer = peek;
c19d1205 4658 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4659 return;
c19d1205 4660
1f5afe1c
NC
4661 case REG_TYPE_RN:
4662 s_arm_unwind_save_core ();
4663 return;
4664
fa073d69
MS
4665 case REG_TYPE_VFD:
4666 if (arch_v6)
477330fc 4667 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4668 else
477330fc 4669 s_arm_unwind_save_vfp ();
fa073d69 4670 return;
1f5afe1c
NC
4671
4672 case REG_TYPE_MMXWR:
4673 s_arm_unwind_save_mmxwr ();
4674 return;
4675
4676 case REG_TYPE_MMXWCG:
4677 s_arm_unwind_save_mmxwcg ();
4678 return;
c19d1205
ZW
4679
4680 default:
4681 as_bad (_(".unwind_save does not support this kind of register"));
4682 ignore_rest_of_line ();
b99bd4ef 4683 }
c19d1205 4684}
b99bd4ef 4685
b99bd4ef 4686
c19d1205
ZW
4687/* Parse an unwind_movsp directive. */
4688
4689static void
4690s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4691{
4692 int reg;
4693 valueT op;
4fa3602b 4694 int offset;
c19d1205 4695
921e5f0a 4696 if (!unwind.proc_start)
c921be7d 4697 as_bad (MISSING_FNSTART);
921e5f0a 4698
dcbf9037 4699 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4700 if (reg == FAIL)
b99bd4ef 4701 {
9b7132d3 4702 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4703 ignore_rest_of_line ();
b99bd4ef
NC
4704 return;
4705 }
4fa3602b
PB
4706
4707 /* Optional constant. */
4708 if (skip_past_comma (&input_line_pointer) != FAIL)
4709 {
4710 if (immediate_for_directive (&offset) == FAIL)
4711 return;
4712 }
4713 else
4714 offset = 0;
4715
c19d1205 4716 demand_empty_rest_of_line ();
b99bd4ef 4717
c19d1205 4718 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4719 {
c19d1205 4720 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4721 return;
4722 }
4723
c19d1205
ZW
4724 if (unwind.fp_reg != REG_SP)
4725 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4726
c19d1205
ZW
4727 /* Generate opcode to restore the value. */
4728 op = 0x90 | reg;
4729 add_unwind_opcode (op, 1);
4730
4731 /* Record the information for later. */
4732 unwind.fp_reg = reg;
4fa3602b 4733 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4734 unwind.sp_restored = 1;
b05fe5cf
ZW
4735}
4736
c19d1205
ZW
4737/* Parse an unwind_pad directive. */
4738
b05fe5cf 4739static void
c19d1205 4740s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4741{
c19d1205 4742 int offset;
b05fe5cf 4743
921e5f0a 4744 if (!unwind.proc_start)
c921be7d 4745 as_bad (MISSING_FNSTART);
921e5f0a 4746
c19d1205
ZW
4747 if (immediate_for_directive (&offset) == FAIL)
4748 return;
b99bd4ef 4749
c19d1205
ZW
4750 if (offset & 3)
4751 {
4752 as_bad (_("stack increment must be multiple of 4"));
4753 ignore_rest_of_line ();
4754 return;
4755 }
b99bd4ef 4756
c19d1205
ZW
4757 /* Don't generate any opcodes, just record the details for later. */
4758 unwind.frame_size += offset;
4759 unwind.pending_offset += offset;
4760
4761 demand_empty_rest_of_line ();
4762}
4763
4764/* Parse an unwind_setfp directive. */
4765
4766static void
4767s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4768{
c19d1205
ZW
4769 int sp_reg;
4770 int fp_reg;
4771 int offset;
4772
921e5f0a 4773 if (!unwind.proc_start)
c921be7d 4774 as_bad (MISSING_FNSTART);
921e5f0a 4775
dcbf9037 4776 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4777 if (skip_past_comma (&input_line_pointer) == FAIL)
4778 sp_reg = FAIL;
4779 else
dcbf9037 4780 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4781
c19d1205
ZW
4782 if (fp_reg == FAIL || sp_reg == FAIL)
4783 {
4784 as_bad (_("expected <reg>, <reg>"));
4785 ignore_rest_of_line ();
4786 return;
4787 }
b99bd4ef 4788
c19d1205
ZW
4789 /* Optional constant. */
4790 if (skip_past_comma (&input_line_pointer) != FAIL)
4791 {
4792 if (immediate_for_directive (&offset) == FAIL)
4793 return;
4794 }
4795 else
4796 offset = 0;
a737bd4d 4797
c19d1205 4798 demand_empty_rest_of_line ();
a737bd4d 4799
fdfde340 4800 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4801 {
c19d1205
ZW
4802 as_bad (_("register must be either sp or set by a previous"
4803 "unwind_movsp directive"));
4804 return;
a737bd4d
NC
4805 }
4806
c19d1205
ZW
4807 /* Don't generate any opcodes, just record the information for later. */
4808 unwind.fp_reg = fp_reg;
4809 unwind.fp_used = 1;
fdfde340 4810 if (sp_reg == REG_SP)
c19d1205
ZW
4811 unwind.fp_offset = unwind.frame_size - offset;
4812 else
4813 unwind.fp_offset -= offset;
a737bd4d
NC
4814}
4815
c19d1205
ZW
4816/* Parse an unwind_raw directive. */
4817
4818static void
4819s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4820{
c19d1205 4821 expressionS exp;
708587a4 4822 /* This is an arbitrary limit. */
c19d1205
ZW
4823 unsigned char op[16];
4824 int count;
a737bd4d 4825
921e5f0a 4826 if (!unwind.proc_start)
c921be7d 4827 as_bad (MISSING_FNSTART);
921e5f0a 4828
c19d1205
ZW
4829 expression (&exp);
4830 if (exp.X_op == O_constant
4831 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4832 {
c19d1205
ZW
4833 unwind.frame_size += exp.X_add_number;
4834 expression (&exp);
4835 }
4836 else
4837 exp.X_op = O_illegal;
a737bd4d 4838
c19d1205
ZW
4839 if (exp.X_op != O_constant)
4840 {
4841 as_bad (_("expected <offset>, <opcode>"));
4842 ignore_rest_of_line ();
4843 return;
4844 }
a737bd4d 4845
c19d1205 4846 count = 0;
a737bd4d 4847
c19d1205
ZW
4848 /* Parse the opcode. */
4849 for (;;)
4850 {
4851 if (count >= 16)
4852 {
4853 as_bad (_("unwind opcode too long"));
4854 ignore_rest_of_line ();
a737bd4d 4855 }
c19d1205 4856 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4857 {
c19d1205
ZW
4858 as_bad (_("invalid unwind opcode"));
4859 ignore_rest_of_line ();
4860 return;
a737bd4d 4861 }
c19d1205 4862 op[count++] = exp.X_add_number;
a737bd4d 4863
c19d1205
ZW
4864 /* Parse the next byte. */
4865 if (skip_past_comma (&input_line_pointer) == FAIL)
4866 break;
a737bd4d 4867
c19d1205
ZW
4868 expression (&exp);
4869 }
b99bd4ef 4870
c19d1205
ZW
4871 /* Add the opcode bytes in reverse order. */
4872 while (count--)
4873 add_unwind_opcode (op[count], 1);
b99bd4ef 4874
c19d1205 4875 demand_empty_rest_of_line ();
b99bd4ef 4876}
ee065d83
PB
4877
4878
4879/* Parse a .eabi_attribute directive. */
4880
4881static void
4882s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4883{
0420f52b 4884 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4885
3076e594 4886 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4887 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4888}
4889
0855e32b
NS
4890/* Emit a tls fix for the symbol. */
4891
4892static void
4893s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4894{
4895 char *p;
4896 expressionS exp;
4897#ifdef md_flush_pending_output
4898 md_flush_pending_output ();
4899#endif
4900
4901#ifdef md_cons_align
4902 md_cons_align (4);
4903#endif
4904
4905 /* Since we're just labelling the code, there's no need to define a
4906 mapping symbol. */
4907 expression (&exp);
4908 p = obstack_next_free (&frchain_now->frch_obstack);
4909 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4910 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4911 : BFD_RELOC_ARM_TLS_DESCSEQ);
4912}
cdf9ccec 4913#endif /* OBJ_ELF */
0855e32b 4914
ee065d83 4915static void s_arm_arch (int);
7a1d4c38 4916static void s_arm_object_arch (int);
ee065d83
PB
4917static void s_arm_cpu (int);
4918static void s_arm_fpu (int);
69133863 4919static void s_arm_arch_extension (int);
b99bd4ef 4920
f0927246
NC
4921#ifdef TE_PE
4922
4923static void
5f4273c7 4924pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4925{
4926 expressionS exp;
4927
4928 do
4929 {
4930 expression (&exp);
4931 if (exp.X_op == O_symbol)
4932 exp.X_op = O_secrel;
4933
4934 emit_expr (&exp, 4);
4935 }
4936 while (*input_line_pointer++ == ',');
4937
4938 input_line_pointer--;
4939 demand_empty_rest_of_line ();
4940}
4941#endif /* TE_PE */
4942
5312fe52
BW
4943int
4944arm_is_largest_exponent_ok (int precision)
4945{
4946 /* precision == 1 ensures that this will only return
4947 true for 16 bit floats. */
4948 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
4949}
4950
4951static void
4952set_fp16_format (int dummy ATTRIBUTE_UNUSED)
4953{
4954 char saved_char;
4955 char* name;
4956 enum fp_16bit_format new_format;
4957
4958 new_format = ARM_FP16_FORMAT_DEFAULT;
4959
4960 name = input_line_pointer;
4961 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
4962 input_line_pointer++;
4963
4964 saved_char = *input_line_pointer;
4965 *input_line_pointer = 0;
4966
4967 if (strcasecmp (name, "ieee") == 0)
4968 new_format = ARM_FP16_FORMAT_IEEE;
4969 else if (strcasecmp (name, "alternative") == 0)
4970 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
4971 else
4972 {
4973 as_bad (_("unrecognised float16 format \"%s\""), name);
4974 goto cleanup;
4975 }
4976
4977 /* Only set fp16_format if it is still the default (aka not already
4978 been set yet). */
4979 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
4980 fp16_format = new_format;
4981 else
4982 {
4983 if (new_format != fp16_format)
4984 as_warn (_("float16 format cannot be set more than once, ignoring."));
4985 }
4986
4987cleanup:
4988 *input_line_pointer = saved_char;
4989 ignore_rest_of_line ();
4990}
4991
c19d1205
ZW
4992/* This table describes all the machine specific pseudo-ops the assembler
4993 has to support. The fields are:
4994 pseudo-op name without dot
4995 function to call to execute this pseudo-op
4996 Integer arg to pass to the function. */
b99bd4ef 4997
c19d1205 4998const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4999{
c19d1205
ZW
5000 /* Never called because '.req' does not start a line. */
5001 { "req", s_req, 0 },
dcbf9037
JB
5002 /* Following two are likewise never called. */
5003 { "dn", s_dn, 0 },
5004 { "qn", s_qn, 0 },
c19d1205
ZW
5005 { "unreq", s_unreq, 0 },
5006 { "bss", s_bss, 0 },
db2ed2e0 5007 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5008 { "arm", s_arm, 0 },
5009 { "thumb", s_thumb, 0 },
5010 { "code", s_code, 0 },
5011 { "force_thumb", s_force_thumb, 0 },
5012 { "thumb_func", s_thumb_func, 0 },
5013 { "thumb_set", s_thumb_set, 0 },
5014 { "even", s_even, 0 },
5015 { "ltorg", s_ltorg, 0 },
5016 { "pool", s_ltorg, 0 },
5017 { "syntax", s_syntax, 0 },
8463be01
PB
5018 { "cpu", s_arm_cpu, 0 },
5019 { "arch", s_arm_arch, 0 },
7a1d4c38 5020 { "object_arch", s_arm_object_arch, 0 },
8463be01 5021 { "fpu", s_arm_fpu, 0 },
69133863 5022 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5023#ifdef OBJ_ELF
c921be7d
NC
5024 { "word", s_arm_elf_cons, 4 },
5025 { "long", s_arm_elf_cons, 4 },
5026 { "inst.n", s_arm_elf_inst, 2 },
5027 { "inst.w", s_arm_elf_inst, 4 },
5028 { "inst", s_arm_elf_inst, 0 },
5029 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5030 { "fnstart", s_arm_unwind_fnstart, 0 },
5031 { "fnend", s_arm_unwind_fnend, 0 },
5032 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5033 { "personality", s_arm_unwind_personality, 0 },
5034 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5035 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5036 { "save", s_arm_unwind_save, 0 },
fa073d69 5037 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5038 { "movsp", s_arm_unwind_movsp, 0 },
5039 { "pad", s_arm_unwind_pad, 0 },
5040 { "setfp", s_arm_unwind_setfp, 0 },
5041 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5042 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5043 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5044#else
5045 { "word", cons, 4},
f0927246
NC
5046
5047 /* These are used for dwarf. */
5048 {"2byte", cons, 2},
5049 {"4byte", cons, 4},
5050 {"8byte", cons, 8},
5051 /* These are used for dwarf2. */
68d20676 5052 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5053 { "loc", dwarf2_directive_loc, 0 },
5054 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5055#endif
5056 { "extend", float_cons, 'x' },
5057 { "ldouble", float_cons, 'x' },
5058 { "packed", float_cons, 'p' },
f0927246
NC
5059#ifdef TE_PE
5060 {"secrel32", pe_directive_secrel, 0},
5061#endif
2e6976a8
DG
5062
5063 /* These are for compatibility with CodeComposer Studio. */
5064 {"ref", s_ccs_ref, 0},
5065 {"def", s_ccs_def, 0},
5066 {"asmfunc", s_ccs_asmfunc, 0},
5067 {"endasmfunc", s_ccs_endasmfunc, 0},
5068
5312fe52
BW
5069 {"float16", float_cons, 'h' },
5070 {"float16_format", set_fp16_format, 0 },
5071
c19d1205
ZW
5072 { 0, 0, 0 }
5073};
5312fe52 5074
c19d1205 5075/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5076
c19d1205
ZW
5077/* Generic immediate-value read function for use in insn parsing.
5078 STR points to the beginning of the immediate (the leading #);
5079 VAL receives the value; if the value is outside [MIN, MAX]
5080 issue an error. PREFIX_OPT is true if the immediate prefix is
5081 optional. */
b99bd4ef 5082
c19d1205
ZW
5083static int
5084parse_immediate (char **str, int *val, int min, int max,
5085 bfd_boolean prefix_opt)
5086{
5087 expressionS exp;
0198d5e6 5088
c19d1205
ZW
5089 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5090 if (exp.X_op != O_constant)
b99bd4ef 5091 {
c19d1205
ZW
5092 inst.error = _("constant expression required");
5093 return FAIL;
5094 }
b99bd4ef 5095
c19d1205
ZW
5096 if (exp.X_add_number < min || exp.X_add_number > max)
5097 {
5098 inst.error = _("immediate value out of range");
5099 return FAIL;
5100 }
b99bd4ef 5101
c19d1205
ZW
5102 *val = exp.X_add_number;
5103 return SUCCESS;
5104}
b99bd4ef 5105
5287ad62 5106/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5107 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5108 instructions. Puts the result directly in inst.operands[i]. */
5109
5110static int
8335d6aa
JW
5111parse_big_immediate (char **str, int i, expressionS *in_exp,
5112 bfd_boolean allow_symbol_p)
5287ad62
JB
5113{
5114 expressionS exp;
8335d6aa 5115 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5116 char *ptr = *str;
5117
8335d6aa 5118 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5119
8335d6aa 5120 if (exp_p->X_op == O_constant)
036dc3f7 5121 {
8335d6aa 5122 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5123 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5124 O_constant. We have to be careful not to break compilation for
5125 32-bit X_add_number, though. */
8335d6aa 5126 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5127 {
8335d6aa
JW
5128 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5129 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5130 & 0xffffffff);
036dc3f7
PB
5131 inst.operands[i].regisimm = 1;
5132 }
5133 }
8335d6aa
JW
5134 else if (exp_p->X_op == O_big
5135 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5136 {
5137 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5138
5287ad62 5139 /* Bignums have their least significant bits in
477330fc
RM
5140 generic_bignum[0]. Make sure we put 32 bits in imm and
5141 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5142 gas_assert (parts != 0);
95b75c01
NC
5143
5144 /* Make sure that the number is not too big.
5145 PR 11972: Bignums can now be sign-extended to the
5146 size of a .octa so check that the out of range bits
5147 are all zero or all one. */
8335d6aa 5148 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5149 {
5150 LITTLENUM_TYPE m = -1;
5151
5152 if (generic_bignum[parts * 2] != 0
5153 && generic_bignum[parts * 2] != m)
5154 return FAIL;
5155
8335d6aa 5156 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5157 if (generic_bignum[j] != generic_bignum[j-1])
5158 return FAIL;
5159 }
5160
5287ad62
JB
5161 inst.operands[i].imm = 0;
5162 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5163 inst.operands[i].imm |= generic_bignum[idx]
5164 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5165 inst.operands[i].reg = 0;
5166 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5167 inst.operands[i].reg |= generic_bignum[idx]
5168 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5169 inst.operands[i].regisimm = 1;
5170 }
8335d6aa 5171 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5172 return FAIL;
5f4273c7 5173
5287ad62
JB
5174 *str = ptr;
5175
5176 return SUCCESS;
5177}
5178
c19d1205
ZW
5179/* Returns the pseudo-register number of an FPA immediate constant,
5180 or FAIL if there isn't a valid constant here. */
b99bd4ef 5181
c19d1205
ZW
5182static int
5183parse_fpa_immediate (char ** str)
5184{
5185 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5186 char * save_in;
5187 expressionS exp;
5188 int i;
5189 int j;
b99bd4ef 5190
c19d1205
ZW
5191 /* First try and match exact strings, this is to guarantee
5192 that some formats will work even for cross assembly. */
b99bd4ef 5193
c19d1205
ZW
5194 for (i = 0; fp_const[i]; i++)
5195 {
5196 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5197 {
c19d1205 5198 char *start = *str;
b99bd4ef 5199
c19d1205
ZW
5200 *str += strlen (fp_const[i]);
5201 if (is_end_of_line[(unsigned char) **str])
5202 return i + 8;
5203 *str = start;
5204 }
5205 }
b99bd4ef 5206
c19d1205
ZW
5207 /* Just because we didn't get a match doesn't mean that the constant
5208 isn't valid, just that it is in a format that we don't
5209 automatically recognize. Try parsing it with the standard
5210 expression routines. */
b99bd4ef 5211
c19d1205 5212 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5213
c19d1205
ZW
5214 /* Look for a raw floating point number. */
5215 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5216 && is_end_of_line[(unsigned char) *save_in])
5217 {
5218 for (i = 0; i < NUM_FLOAT_VALS; i++)
5219 {
5220 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5221 {
c19d1205
ZW
5222 if (words[j] != fp_values[i][j])
5223 break;
b99bd4ef
NC
5224 }
5225
c19d1205 5226 if (j == MAX_LITTLENUMS)
b99bd4ef 5227 {
c19d1205
ZW
5228 *str = save_in;
5229 return i + 8;
b99bd4ef
NC
5230 }
5231 }
5232 }
b99bd4ef 5233
c19d1205
ZW
5234 /* Try and parse a more complex expression, this will probably fail
5235 unless the code uses a floating point prefix (eg "0f"). */
5236 save_in = input_line_pointer;
5237 input_line_pointer = *str;
5238 if (expression (&exp) == absolute_section
5239 && exp.X_op == O_big
5240 && exp.X_add_number < 0)
5241 {
5242 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5243 Ditto for 15. */
ba592044
AM
5244#define X_PRECISION 5
5245#define E_PRECISION 15L
5246 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5247 {
5248 for (i = 0; i < NUM_FLOAT_VALS; i++)
5249 {
5250 for (j = 0; j < MAX_LITTLENUMS; j++)
5251 {
5252 if (words[j] != fp_values[i][j])
5253 break;
5254 }
b99bd4ef 5255
c19d1205
ZW
5256 if (j == MAX_LITTLENUMS)
5257 {
5258 *str = input_line_pointer;
5259 input_line_pointer = save_in;
5260 return i + 8;
5261 }
5262 }
5263 }
b99bd4ef
NC
5264 }
5265
c19d1205
ZW
5266 *str = input_line_pointer;
5267 input_line_pointer = save_in;
5268 inst.error = _("invalid FPA immediate expression");
5269 return FAIL;
b99bd4ef
NC
5270}
5271
136da414
JB
5272/* Returns 1 if a number has "quarter-precision" float format
5273 0baBbbbbbc defgh000 00000000 00000000. */
5274
5275static int
5276is_quarter_float (unsigned imm)
5277{
5278 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5279 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5280}
5281
aacf0b33
KT
5282
5283/* Detect the presence of a floating point or integer zero constant,
5284 i.e. #0.0 or #0. */
5285
5286static bfd_boolean
5287parse_ifimm_zero (char **in)
5288{
5289 int error_code;
5290
5291 if (!is_immediate_prefix (**in))
3c6452ae
TP
5292 {
5293 /* In unified syntax, all prefixes are optional. */
5294 if (!unified_syntax)
5295 return FALSE;
5296 }
5297 else
5298 ++*in;
0900a05b
JW
5299
5300 /* Accept #0x0 as a synonym for #0. */
5301 if (strncmp (*in, "0x", 2) == 0)
5302 {
5303 int val;
5304 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5305 return FALSE;
5306 return TRUE;
5307 }
5308
aacf0b33
KT
5309 error_code = atof_generic (in, ".", EXP_CHARS,
5310 &generic_floating_point_number);
5311
5312 if (!error_code
5313 && generic_floating_point_number.sign == '+'
5314 && (generic_floating_point_number.low
5315 > generic_floating_point_number.leader))
5316 return TRUE;
5317
5318 return FALSE;
5319}
5320
136da414
JB
5321/* Parse an 8-bit "quarter-precision" floating point number of the form:
5322 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5323 The zero and minus-zero cases need special handling, since they can't be
5324 encoded in the "quarter-precision" float format, but can nonetheless be
5325 loaded as integer constants. */
136da414
JB
5326
5327static unsigned
5328parse_qfloat_immediate (char **ccp, int *immed)
5329{
5330 char *str = *ccp;
c96612cc 5331 char *fpnum;
136da414 5332 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5333 int found_fpchar = 0;
5f4273c7 5334
136da414 5335 skip_past_char (&str, '#');
5f4273c7 5336
c96612cc
JB
5337 /* We must not accidentally parse an integer as a floating-point number. Make
5338 sure that the value we parse is not an integer by checking for special
5339 characters '.' or 'e'.
5340 FIXME: This is a horrible hack, but doing better is tricky because type
5341 information isn't in a very usable state at parse time. */
5342 fpnum = str;
5343 skip_whitespace (fpnum);
5344
5345 if (strncmp (fpnum, "0x", 2) == 0)
5346 return FAIL;
5347 else
5348 {
5349 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5350 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5351 {
5352 found_fpchar = 1;
5353 break;
5354 }
c96612cc
JB
5355
5356 if (!found_fpchar)
477330fc 5357 return FAIL;
c96612cc 5358 }
5f4273c7 5359
136da414
JB
5360 if ((str = atof_ieee (str, 's', words)) != NULL)
5361 {
5362 unsigned fpword = 0;
5363 int i;
5f4273c7 5364
136da414
JB
5365 /* Our FP word must be 32 bits (single-precision FP). */
5366 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5367 {
5368 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5369 fpword |= words[i];
5370 }
5f4273c7 5371
c96612cc 5372 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5373 *immed = fpword;
136da414 5374 else
477330fc 5375 return FAIL;
136da414
JB
5376
5377 *ccp = str;
5f4273c7 5378
136da414
JB
5379 return SUCCESS;
5380 }
5f4273c7 5381
136da414
JB
5382 return FAIL;
5383}
5384
c19d1205
ZW
5385/* Shift operands. */
5386enum shift_kind
b99bd4ef 5387{
f5f10c66 5388 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5389};
b99bd4ef 5390
c19d1205
ZW
5391struct asm_shift_name
5392{
5393 const char *name;
5394 enum shift_kind kind;
5395};
b99bd4ef 5396
c19d1205
ZW
5397/* Third argument to parse_shift. */
5398enum parse_shift_mode
5399{
5400 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5401 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5402 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5403 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5404 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5405 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5406};
b99bd4ef 5407
c19d1205
ZW
5408/* Parse a <shift> specifier on an ARM data processing instruction.
5409 This has three forms:
b99bd4ef 5410
c19d1205
ZW
5411 (LSL|LSR|ASL|ASR|ROR) Rs
5412 (LSL|LSR|ASL|ASR|ROR) #imm
5413 RRX
b99bd4ef 5414
c19d1205
ZW
5415 Note that ASL is assimilated to LSL in the instruction encoding, and
5416 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5417
c19d1205
ZW
5418static int
5419parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5420{
c19d1205
ZW
5421 const struct asm_shift_name *shift_name;
5422 enum shift_kind shift;
5423 char *s = *str;
5424 char *p = s;
5425 int reg;
b99bd4ef 5426
c19d1205
ZW
5427 for (p = *str; ISALPHA (*p); p++)
5428 ;
b99bd4ef 5429
c19d1205 5430 if (p == *str)
b99bd4ef 5431 {
c19d1205
ZW
5432 inst.error = _("shift expression expected");
5433 return FAIL;
b99bd4ef
NC
5434 }
5435
21d799b5 5436 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5437 p - *str);
c19d1205
ZW
5438
5439 if (shift_name == NULL)
b99bd4ef 5440 {
c19d1205
ZW
5441 inst.error = _("shift expression expected");
5442 return FAIL;
b99bd4ef
NC
5443 }
5444
c19d1205 5445 shift = shift_name->kind;
b99bd4ef 5446
c19d1205
ZW
5447 switch (mode)
5448 {
5449 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5450 case SHIFT_IMMEDIATE:
5451 if (shift == SHIFT_UXTW)
5452 {
5453 inst.error = _("'UXTW' not allowed here");
5454 return FAIL;
5455 }
5456 break;
b99bd4ef 5457
c19d1205
ZW
5458 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5459 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5460 {
5461 inst.error = _("'LSL' or 'ASR' required");
5462 return FAIL;
5463 }
5464 break;
b99bd4ef 5465
c19d1205
ZW
5466 case SHIFT_LSL_IMMEDIATE:
5467 if (shift != SHIFT_LSL)
5468 {
5469 inst.error = _("'LSL' required");
5470 return FAIL;
5471 }
5472 break;
b99bd4ef 5473
c19d1205
ZW
5474 case SHIFT_ASR_IMMEDIATE:
5475 if (shift != SHIFT_ASR)
5476 {
5477 inst.error = _("'ASR' required");
5478 return FAIL;
5479 }
5480 break;
f5f10c66
AV
5481 case SHIFT_UXTW_IMMEDIATE:
5482 if (shift != SHIFT_UXTW)
5483 {
5484 inst.error = _("'UXTW' required");
5485 return FAIL;
5486 }
5487 break;
b99bd4ef 5488
c19d1205
ZW
5489 default: abort ();
5490 }
b99bd4ef 5491
c19d1205
ZW
5492 if (shift != SHIFT_RRX)
5493 {
5494 /* Whitespace can appear here if the next thing is a bare digit. */
5495 skip_whitespace (p);
b99bd4ef 5496
c19d1205 5497 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5498 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5499 {
5500 inst.operands[i].imm = reg;
5501 inst.operands[i].immisreg = 1;
5502 }
e2b0ab59 5503 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5504 return FAIL;
5505 }
5506 inst.operands[i].shift_kind = shift;
5507 inst.operands[i].shifted = 1;
5508 *str = p;
5509 return SUCCESS;
b99bd4ef
NC
5510}
5511
c19d1205 5512/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5513
c19d1205
ZW
5514 #<immediate>
5515 #<immediate>, <rotate>
5516 <Rm>
5517 <Rm>, <shift>
b99bd4ef 5518
c19d1205
ZW
5519 where <shift> is defined by parse_shift above, and <rotate> is a
5520 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5521 is deferred to md_apply_fix. */
b99bd4ef 5522
c19d1205
ZW
5523static int
5524parse_shifter_operand (char **str, int i)
5525{
5526 int value;
91d6fa6a 5527 expressionS exp;
b99bd4ef 5528
dcbf9037 5529 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5530 {
5531 inst.operands[i].reg = value;
5532 inst.operands[i].isreg = 1;
b99bd4ef 5533
c19d1205 5534 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5535 inst.relocs[0].exp.X_op = O_constant;
5536 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5537
c19d1205
ZW
5538 if (skip_past_comma (str) == FAIL)
5539 return SUCCESS;
b99bd4ef 5540
c19d1205
ZW
5541 /* Shift operation on register. */
5542 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5543 }
5544
e2b0ab59 5545 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5546 return FAIL;
b99bd4ef 5547
c19d1205 5548 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5549 {
c19d1205 5550 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5551 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5552 return FAIL;
b99bd4ef 5553
e2b0ab59 5554 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5555 {
5556 inst.error = _("constant expression expected");
5557 return FAIL;
5558 }
b99bd4ef 5559
91d6fa6a 5560 value = exp.X_add_number;
c19d1205
ZW
5561 if (value < 0 || value > 30 || value % 2 != 0)
5562 {
5563 inst.error = _("invalid rotation");
5564 return FAIL;
5565 }
e2b0ab59
AV
5566 if (inst.relocs[0].exp.X_add_number < 0
5567 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5568 {
5569 inst.error = _("invalid constant");
5570 return FAIL;
5571 }
09d92015 5572
a415b1cd 5573 /* Encode as specified. */
e2b0ab59 5574 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5575 return SUCCESS;
09d92015
MM
5576 }
5577
e2b0ab59
AV
5578 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5579 inst.relocs[0].pc_rel = 0;
c19d1205 5580 return SUCCESS;
09d92015
MM
5581}
5582
4962c51a
MS
5583/* Group relocation information. Each entry in the table contains the
5584 textual name of the relocation as may appear in assembler source
5585 and must end with a colon.
5586 Along with this textual name are the relocation codes to be used if
5587 the corresponding instruction is an ALU instruction (ADD or SUB only),
5588 an LDR, an LDRS, or an LDC. */
5589
5590struct group_reloc_table_entry
5591{
5592 const char *name;
5593 int alu_code;
5594 int ldr_code;
5595 int ldrs_code;
5596 int ldc_code;
5597};
5598
5599typedef enum
5600{
5601 /* Varieties of non-ALU group relocation. */
5602
5603 GROUP_LDR,
5604 GROUP_LDRS,
35c228db
AV
5605 GROUP_LDC,
5606 GROUP_MVE
4962c51a
MS
5607} group_reloc_type;
5608
5609static struct group_reloc_table_entry group_reloc_table[] =
5610 { /* Program counter relative: */
5611 { "pc_g0_nc",
5612 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5613 0, /* LDR */
5614 0, /* LDRS */
5615 0 }, /* LDC */
5616 { "pc_g0",
5617 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5618 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5619 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5620 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5621 { "pc_g1_nc",
5622 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5623 0, /* LDR */
5624 0, /* LDRS */
5625 0 }, /* LDC */
5626 { "pc_g1",
5627 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5628 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5629 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5630 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5631 { "pc_g2",
5632 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5633 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5634 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5635 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5636 /* Section base relative */
5637 { "sb_g0_nc",
5638 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5639 0, /* LDR */
5640 0, /* LDRS */
5641 0 }, /* LDC */
5642 { "sb_g0",
5643 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5644 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5645 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5646 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5647 { "sb_g1_nc",
5648 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5649 0, /* LDR */
5650 0, /* LDRS */
5651 0 }, /* LDC */
5652 { "sb_g1",
5653 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5654 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5655 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5656 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5657 { "sb_g2",
5658 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5659 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5660 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5661 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5662 /* Absolute thumb alu relocations. */
5663 { "lower0_7",
5664 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5665 0, /* LDR. */
5666 0, /* LDRS. */
5667 0 }, /* LDC. */
5668 { "lower8_15",
5669 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5670 0, /* LDR. */
5671 0, /* LDRS. */
5672 0 }, /* LDC. */
5673 { "upper0_7",
5674 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5675 0, /* LDR. */
5676 0, /* LDRS. */
5677 0 }, /* LDC. */
5678 { "upper8_15",
5679 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5680 0, /* LDR. */
5681 0, /* LDRS. */
5682 0 } }; /* LDC. */
4962c51a
MS
5683
5684/* Given the address of a pointer pointing to the textual name of a group
5685 relocation as may appear in assembler source, attempt to find its details
5686 in group_reloc_table. The pointer will be updated to the character after
5687 the trailing colon. On failure, FAIL will be returned; SUCCESS
5688 otherwise. On success, *entry will be updated to point at the relevant
5689 group_reloc_table entry. */
5690
5691static int
5692find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5693{
5694 unsigned int i;
5695 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5696 {
5697 int length = strlen (group_reloc_table[i].name);
5698
5f4273c7
NC
5699 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5700 && (*str)[length] == ':')
477330fc
RM
5701 {
5702 *out = &group_reloc_table[i];
5703 *str += (length + 1);
5704 return SUCCESS;
5705 }
4962c51a
MS
5706 }
5707
5708 return FAIL;
5709}
5710
5711/* Parse a <shifter_operand> for an ARM data processing instruction
5712 (as for parse_shifter_operand) where group relocations are allowed:
5713
5714 #<immediate>
5715 #<immediate>, <rotate>
5716 #:<group_reloc>:<expression>
5717 <Rm>
5718 <Rm>, <shift>
5719
5720 where <group_reloc> is one of the strings defined in group_reloc_table.
5721 The hashes are optional.
5722
5723 Everything else is as for parse_shifter_operand. */
5724
5725static parse_operand_result
5726parse_shifter_operand_group_reloc (char **str, int i)
5727{
5728 /* Determine if we have the sequence of characters #: or just :
5729 coming next. If we do, then we check for a group relocation.
5730 If we don't, punt the whole lot to parse_shifter_operand. */
5731
5732 if (((*str)[0] == '#' && (*str)[1] == ':')
5733 || (*str)[0] == ':')
5734 {
5735 struct group_reloc_table_entry *entry;
5736
5737 if ((*str)[0] == '#')
477330fc 5738 (*str) += 2;
4962c51a 5739 else
477330fc 5740 (*str)++;
4962c51a
MS
5741
5742 /* Try to parse a group relocation. Anything else is an error. */
5743 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5744 {
5745 inst.error = _("unknown group relocation");
5746 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5747 }
4962c51a
MS
5748
5749 /* We now have the group relocation table entry corresponding to
477330fc 5750 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5751 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5752 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5753
5754 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5755 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5756 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5757
5758 return PARSE_OPERAND_SUCCESS;
5759 }
5760 else
5761 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5762 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5763
5764 /* Never reached. */
5765}
5766
8e560766
MGD
5767/* Parse a Neon alignment expression. Information is written to
5768 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5769
8e560766
MGD
5770 align .imm = align << 8, .immisalign=1, .preind=0 */
5771static parse_operand_result
5772parse_neon_alignment (char **str, int i)
5773{
5774 char *p = *str;
5775 expressionS exp;
5776
5777 my_get_expression (&exp, &p, GE_NO_PREFIX);
5778
5779 if (exp.X_op != O_constant)
5780 {
5781 inst.error = _("alignment must be constant");
5782 return PARSE_OPERAND_FAIL;
5783 }
5784
5785 inst.operands[i].imm = exp.X_add_number << 8;
5786 inst.operands[i].immisalign = 1;
5787 /* Alignments are not pre-indexes. */
5788 inst.operands[i].preind = 0;
5789
5790 *str = p;
5791 return PARSE_OPERAND_SUCCESS;
5792}
5793
c19d1205 5794/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5795 to inst.operands[i] and/or inst.relocs[0].
09d92015 5796
c19d1205 5797 Preindexed addressing (.preind=1):
09d92015 5798
e2b0ab59 5799 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5800 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5801 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5802 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5803
c19d1205 5804 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5805
c19d1205 5806 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5807
e2b0ab59 5808 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5809 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5810 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5811 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5812
c19d1205 5813 Unindexed addressing (.preind=0, .postind=0):
09d92015 5814
c19d1205 5815 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5816
c19d1205 5817 Other:
09d92015 5818
c19d1205 5819 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5820 =immediate .isreg=0 .relocs[0].exp=immediate
5821 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5822
c19d1205 5823 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5824 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5825
4962c51a
MS
5826static parse_operand_result
5827parse_address_main (char **str, int i, int group_relocations,
477330fc 5828 group_reloc_type group_type)
09d92015 5829{
c19d1205
ZW
5830 char *p = *str;
5831 int reg;
09d92015 5832
c19d1205 5833 if (skip_past_char (&p, '[') == FAIL)
09d92015 5834 {
c19d1205
ZW
5835 if (skip_past_char (&p, '=') == FAIL)
5836 {
974da60d 5837 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5838 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5839 inst.operands[i].reg = REG_PC;
5840 inst.operands[i].isreg = 1;
5841 inst.operands[i].preind = 1;
09d92015 5842
e2b0ab59 5843 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5844 return PARSE_OPERAND_FAIL;
5845 }
e2b0ab59 5846 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5847 /*allow_symbol_p=*/TRUE))
4962c51a 5848 return PARSE_OPERAND_FAIL;
09d92015 5849
c19d1205 5850 *str = p;
4962c51a 5851 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5852 }
5853
8ab8155f
NC
5854 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5855 skip_whitespace (p);
5856
f5f10c66
AV
5857 if (group_type == GROUP_MVE)
5858 {
5859 enum arm_reg_type rtype = REG_TYPE_MQ;
5860 struct neon_type_el et;
5861 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5862 {
5863 inst.operands[i].isquad = 1;
5864 }
5865 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5866 {
5867 inst.error = BAD_ADDR_MODE;
5868 return PARSE_OPERAND_FAIL;
5869 }
5870 }
5871 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5872 {
35c228db
AV
5873 if (group_type == GROUP_MVE)
5874 inst.error = BAD_ADDR_MODE;
5875 else
5876 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5877 return PARSE_OPERAND_FAIL;
09d92015 5878 }
c19d1205
ZW
5879 inst.operands[i].reg = reg;
5880 inst.operands[i].isreg = 1;
09d92015 5881
c19d1205 5882 if (skip_past_comma (&p) == SUCCESS)
09d92015 5883 {
c19d1205 5884 inst.operands[i].preind = 1;
09d92015 5885
c19d1205
ZW
5886 if (*p == '+') p++;
5887 else if (*p == '-') p++, inst.operands[i].negative = 1;
5888
f5f10c66
AV
5889 enum arm_reg_type rtype = REG_TYPE_MQ;
5890 struct neon_type_el et;
5891 if (group_type == GROUP_MVE
5892 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5893 {
5894 inst.operands[i].immisreg = 2;
5895 inst.operands[i].imm = reg;
5896
5897 if (skip_past_comma (&p) == SUCCESS)
5898 {
5899 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
5900 {
5901 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
5902 inst.relocs[0].exp.X_add_number = 0;
5903 }
5904 else
5905 return PARSE_OPERAND_FAIL;
5906 }
5907 }
5908 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5909 {
c19d1205
ZW
5910 inst.operands[i].imm = reg;
5911 inst.operands[i].immisreg = 1;
5912
5913 if (skip_past_comma (&p) == SUCCESS)
5914 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5915 return PARSE_OPERAND_FAIL;
c19d1205 5916 }
5287ad62 5917 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5918 {
5919 /* FIXME: '@' should be used here, but it's filtered out by generic
5920 code before we get to see it here. This may be subject to
5921 change. */
5922 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5923
8e560766
MGD
5924 if (result != PARSE_OPERAND_SUCCESS)
5925 return result;
5926 }
c19d1205
ZW
5927 else
5928 {
5929 if (inst.operands[i].negative)
5930 {
5931 inst.operands[i].negative = 0;
5932 p--;
5933 }
4962c51a 5934
5f4273c7
NC
5935 if (group_relocations
5936 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5937 {
5938 struct group_reloc_table_entry *entry;
5939
477330fc
RM
5940 /* Skip over the #: or : sequence. */
5941 if (*p == '#')
5942 p += 2;
5943 else
5944 p++;
4962c51a
MS
5945
5946 /* Try to parse a group relocation. Anything else is an
477330fc 5947 error. */
4962c51a
MS
5948 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5949 {
5950 inst.error = _("unknown group relocation");
5951 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5952 }
5953
5954 /* We now have the group relocation table entry corresponding to
5955 the name in the assembler source. Next, we parse the
477330fc 5956 expression. */
e2b0ab59 5957 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
5958 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5959
5960 /* Record the relocation type. */
477330fc
RM
5961 switch (group_type)
5962 {
5963 case GROUP_LDR:
e2b0ab59
AV
5964 inst.relocs[0].type
5965 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 5966 break;
4962c51a 5967
477330fc 5968 case GROUP_LDRS:
e2b0ab59
AV
5969 inst.relocs[0].type
5970 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 5971 break;
4962c51a 5972
477330fc 5973 case GROUP_LDC:
e2b0ab59
AV
5974 inst.relocs[0].type
5975 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 5976 break;
4962c51a 5977
477330fc
RM
5978 default:
5979 gas_assert (0);
5980 }
4962c51a 5981
e2b0ab59 5982 if (inst.relocs[0].type == 0)
4962c51a
MS
5983 {
5984 inst.error = _("this group relocation is not allowed on this instruction");
5985 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5986 }
477330fc
RM
5987 }
5988 else
26d97720
NS
5989 {
5990 char *q = p;
0198d5e6 5991
e2b0ab59 5992 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
5993 return PARSE_OPERAND_FAIL;
5994 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5995 if (inst.relocs[0].exp.X_op == O_constant
5996 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5997 {
5998 skip_whitespace (q);
5999 if (*q == '#')
6000 {
6001 q++;
6002 skip_whitespace (q);
6003 }
6004 if (*q == '-')
6005 inst.operands[i].negative = 1;
6006 }
6007 }
09d92015
MM
6008 }
6009 }
8e560766
MGD
6010 else if (skip_past_char (&p, ':') == SUCCESS)
6011 {
6012 /* FIXME: '@' should be used here, but it's filtered out by generic code
6013 before we get to see it here. This may be subject to change. */
6014 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6015
8e560766
MGD
6016 if (result != PARSE_OPERAND_SUCCESS)
6017 return result;
6018 }
09d92015 6019
c19d1205 6020 if (skip_past_char (&p, ']') == FAIL)
09d92015 6021 {
c19d1205 6022 inst.error = _("']' expected");
4962c51a 6023 return PARSE_OPERAND_FAIL;
09d92015
MM
6024 }
6025
c19d1205
ZW
6026 if (skip_past_char (&p, '!') == SUCCESS)
6027 inst.operands[i].writeback = 1;
09d92015 6028
c19d1205 6029 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6030 {
c19d1205
ZW
6031 if (skip_past_char (&p, '{') == SUCCESS)
6032 {
6033 /* [Rn], {expr} - unindexed, with option */
6034 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6035 0, 255, TRUE) == FAIL)
4962c51a 6036 return PARSE_OPERAND_FAIL;
09d92015 6037
c19d1205
ZW
6038 if (skip_past_char (&p, '}') == FAIL)
6039 {
6040 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6041 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6042 }
6043 if (inst.operands[i].preind)
6044 {
6045 inst.error = _("cannot combine index with option");
4962c51a 6046 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6047 }
6048 *str = p;
4962c51a 6049 return PARSE_OPERAND_SUCCESS;
09d92015 6050 }
c19d1205
ZW
6051 else
6052 {
6053 inst.operands[i].postind = 1;
6054 inst.operands[i].writeback = 1;
09d92015 6055
c19d1205
ZW
6056 if (inst.operands[i].preind)
6057 {
6058 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6059 return PARSE_OPERAND_FAIL;
c19d1205 6060 }
09d92015 6061
c19d1205
ZW
6062 if (*p == '+') p++;
6063 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6064
f5f10c66
AV
6065 enum arm_reg_type rtype = REG_TYPE_MQ;
6066 struct neon_type_el et;
6067 if (group_type == GROUP_MVE
6068 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6069 {
6070 inst.operands[i].immisreg = 2;
6071 inst.operands[i].imm = reg;
6072 }
6073 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6074 {
477330fc
RM
6075 /* We might be using the immediate for alignment already. If we
6076 are, OR the register number into the low-order bits. */
6077 if (inst.operands[i].immisalign)
6078 inst.operands[i].imm |= reg;
6079 else
6080 inst.operands[i].imm = reg;
c19d1205 6081 inst.operands[i].immisreg = 1;
a737bd4d 6082
c19d1205
ZW
6083 if (skip_past_comma (&p) == SUCCESS)
6084 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6085 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6086 }
6087 else
6088 {
26d97720 6089 char *q = p;
0198d5e6 6090
c19d1205
ZW
6091 if (inst.operands[i].negative)
6092 {
6093 inst.operands[i].negative = 0;
6094 p--;
6095 }
e2b0ab59 6096 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6097 return PARSE_OPERAND_FAIL;
26d97720 6098 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6099 if (inst.relocs[0].exp.X_op == O_constant
6100 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6101 {
6102 skip_whitespace (q);
6103 if (*q == '#')
6104 {
6105 q++;
6106 skip_whitespace (q);
6107 }
6108 if (*q == '-')
6109 inst.operands[i].negative = 1;
6110 }
c19d1205
ZW
6111 }
6112 }
a737bd4d
NC
6113 }
6114
c19d1205
ZW
6115 /* If at this point neither .preind nor .postind is set, we have a
6116 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6117 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6118 {
6119 inst.operands[i].preind = 1;
e2b0ab59
AV
6120 inst.relocs[0].exp.X_op = O_constant;
6121 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6122 }
6123 *str = p;
4962c51a
MS
6124 return PARSE_OPERAND_SUCCESS;
6125}
6126
6127static int
6128parse_address (char **str, int i)
6129{
21d799b5 6130 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6131 ? SUCCESS : FAIL;
4962c51a
MS
6132}
6133
6134static parse_operand_result
6135parse_address_group_reloc (char **str, int i, group_reloc_type type)
6136{
6137 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6138}
6139
b6895b4f
PB
6140/* Parse an operand for a MOVW or MOVT instruction. */
6141static int
6142parse_half (char **str)
6143{
6144 char * p;
5f4273c7 6145
b6895b4f
PB
6146 p = *str;
6147 skip_past_char (&p, '#');
5f4273c7 6148 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6149 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6150 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6151 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6152
e2b0ab59 6153 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6154 {
6155 p += 9;
5f4273c7 6156 skip_whitespace (p);
b6895b4f
PB
6157 }
6158
e2b0ab59 6159 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6160 return FAIL;
6161
e2b0ab59 6162 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6163 {
e2b0ab59 6164 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6165 {
6166 inst.error = _("constant expression expected");
6167 return FAIL;
6168 }
e2b0ab59
AV
6169 if (inst.relocs[0].exp.X_add_number < 0
6170 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6171 {
6172 inst.error = _("immediate value out of range");
6173 return FAIL;
6174 }
6175 }
6176 *str = p;
6177 return SUCCESS;
6178}
6179
c19d1205 6180/* Miscellaneous. */
a737bd4d 6181
c19d1205
ZW
6182/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6183 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6184static int
d2cd1205 6185parse_psr (char **str, bfd_boolean lhs)
09d92015 6186{
c19d1205
ZW
6187 char *p;
6188 unsigned long psr_field;
62b3e311
PB
6189 const struct asm_psr *psr;
6190 char *start;
d2cd1205 6191 bfd_boolean is_apsr = FALSE;
ac7f631b 6192 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6193
a4482bb6
NC
6194 /* PR gas/12698: If the user has specified -march=all then m_profile will
6195 be TRUE, but we want to ignore it in this case as we are building for any
6196 CPU type, including non-m variants. */
823d2571 6197 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6198 m_profile = FALSE;
6199
c19d1205
ZW
6200 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6201 feature for ease of use and backwards compatibility. */
6202 p = *str;
62b3e311 6203 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6204 {
6205 if (m_profile)
6206 goto unsupported_psr;
fa94de6b 6207
d2cd1205
JB
6208 psr_field = SPSR_BIT;
6209 }
6210 else if (strncasecmp (p, "CPSR", 4) == 0)
6211 {
6212 if (m_profile)
6213 goto unsupported_psr;
6214
6215 psr_field = 0;
6216 }
6217 else if (strncasecmp (p, "APSR", 4) == 0)
6218 {
6219 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6220 and ARMv7-R architecture CPUs. */
6221 is_apsr = TRUE;
6222 psr_field = 0;
6223 }
6224 else if (m_profile)
62b3e311
PB
6225 {
6226 start = p;
6227 do
6228 p++;
6229 while (ISALNUM (*p) || *p == '_');
6230
d2cd1205
JB
6231 if (strncasecmp (start, "iapsr", 5) == 0
6232 || strncasecmp (start, "eapsr", 5) == 0
6233 || strncasecmp (start, "xpsr", 4) == 0
6234 || strncasecmp (start, "psr", 3) == 0)
6235 p = start + strcspn (start, "rR") + 1;
6236
21d799b5 6237 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6238 p - start);
d2cd1205 6239
62b3e311
PB
6240 if (!psr)
6241 return FAIL;
09d92015 6242
d2cd1205
JB
6243 /* If APSR is being written, a bitfield may be specified. Note that
6244 APSR itself is handled above. */
6245 if (psr->field <= 3)
6246 {
6247 psr_field = psr->field;
6248 is_apsr = TRUE;
6249 goto check_suffix;
6250 }
6251
62b3e311 6252 *str = p;
d2cd1205
JB
6253 /* M-profile MSR instructions have the mask field set to "10", except
6254 *PSR variants which modify APSR, which may use a different mask (and
6255 have been handled already). Do that by setting the PSR_f field
6256 here. */
6257 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6258 }
d2cd1205
JB
6259 else
6260 goto unsupported_psr;
09d92015 6261
62b3e311 6262 p += 4;
d2cd1205 6263check_suffix:
c19d1205
ZW
6264 if (*p == '_')
6265 {
6266 /* A suffix follows. */
c19d1205
ZW
6267 p++;
6268 start = p;
a737bd4d 6269
c19d1205
ZW
6270 do
6271 p++;
6272 while (ISALNUM (*p) || *p == '_');
a737bd4d 6273
d2cd1205
JB
6274 if (is_apsr)
6275 {
6276 /* APSR uses a notation for bits, rather than fields. */
6277 unsigned int nzcvq_bits = 0;
6278 unsigned int g_bit = 0;
6279 char *bit;
fa94de6b 6280
d2cd1205
JB
6281 for (bit = start; bit != p; bit++)
6282 {
6283 switch (TOLOWER (*bit))
477330fc 6284 {
d2cd1205
JB
6285 case 'n':
6286 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6287 break;
6288
6289 case 'z':
6290 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6291 break;
6292
6293 case 'c':
6294 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6295 break;
6296
6297 case 'v':
6298 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6299 break;
fa94de6b 6300
d2cd1205
JB
6301 case 'q':
6302 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6303 break;
fa94de6b 6304
d2cd1205
JB
6305 case 'g':
6306 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6307 break;
fa94de6b 6308
d2cd1205
JB
6309 default:
6310 inst.error = _("unexpected bit specified after APSR");
6311 return FAIL;
6312 }
6313 }
fa94de6b 6314
d2cd1205
JB
6315 if (nzcvq_bits == 0x1f)
6316 psr_field |= PSR_f;
fa94de6b 6317
d2cd1205
JB
6318 if (g_bit == 0x1)
6319 {
6320 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6321 {
d2cd1205
JB
6322 inst.error = _("selected processor does not "
6323 "support DSP extension");
6324 return FAIL;
6325 }
6326
6327 psr_field |= PSR_s;
6328 }
fa94de6b 6329
d2cd1205
JB
6330 if ((nzcvq_bits & 0x20) != 0
6331 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6332 || (g_bit & 0x2) != 0)
6333 {
6334 inst.error = _("bad bitmask specified after APSR");
6335 return FAIL;
6336 }
6337 }
6338 else
477330fc 6339 {
d2cd1205 6340 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6341 p - start);
d2cd1205 6342 if (!psr)
477330fc 6343 goto error;
a737bd4d 6344
d2cd1205
JB
6345 psr_field |= psr->field;
6346 }
a737bd4d 6347 }
c19d1205 6348 else
a737bd4d 6349 {
c19d1205
ZW
6350 if (ISALNUM (*p))
6351 goto error; /* Garbage after "[CS]PSR". */
6352
d2cd1205 6353 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6354 is deprecated, but allow it anyway. */
d2cd1205
JB
6355 if (is_apsr && lhs)
6356 {
6357 psr_field |= PSR_f;
6358 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6359 "deprecated"));
6360 }
6361 else if (!m_profile)
6362 /* These bits are never right for M-profile devices: don't set them
6363 (only code paths which read/write APSR reach here). */
6364 psr_field |= (PSR_c | PSR_f);
a737bd4d 6365 }
c19d1205
ZW
6366 *str = p;
6367 return psr_field;
a737bd4d 6368
d2cd1205
JB
6369 unsupported_psr:
6370 inst.error = _("selected processor does not support requested special "
6371 "purpose register");
6372 return FAIL;
6373
c19d1205
ZW
6374 error:
6375 inst.error = _("flag for {c}psr instruction expected");
6376 return FAIL;
a737bd4d
NC
6377}
6378
32c36c3c
AV
6379static int
6380parse_sys_vldr_vstr (char **str)
6381{
6382 unsigned i;
6383 int val = FAIL;
6384 struct {
6385 const char *name;
6386 int regl;
6387 int regh;
6388 } sysregs[] = {
6389 {"FPSCR", 0x1, 0x0},
6390 {"FPSCR_nzcvqc", 0x2, 0x0},
6391 {"VPR", 0x4, 0x1},
6392 {"P0", 0x5, 0x1},
6393 {"FPCXTNS", 0x6, 0x1},
6394 {"FPCXTS", 0x7, 0x1}
6395 };
6396 char *op_end = strchr (*str, ',');
6397 size_t op_strlen = op_end - *str;
6398
6399 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6400 {
6401 if (!strncmp (*str, sysregs[i].name, op_strlen))
6402 {
6403 val = sysregs[i].regl | (sysregs[i].regh << 3);
6404 *str = op_end;
6405 break;
6406 }
6407 }
6408
6409 return val;
6410}
6411
c19d1205
ZW
6412/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6413 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6414
c19d1205
ZW
6415static int
6416parse_cps_flags (char **str)
a737bd4d 6417{
c19d1205
ZW
6418 int val = 0;
6419 int saw_a_flag = 0;
6420 char *s = *str;
a737bd4d 6421
c19d1205
ZW
6422 for (;;)
6423 switch (*s++)
6424 {
6425 case '\0': case ',':
6426 goto done;
a737bd4d 6427
c19d1205
ZW
6428 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6429 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6430 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6431
c19d1205
ZW
6432 default:
6433 inst.error = _("unrecognized CPS flag");
6434 return FAIL;
6435 }
a737bd4d 6436
c19d1205
ZW
6437 done:
6438 if (saw_a_flag == 0)
a737bd4d 6439 {
c19d1205
ZW
6440 inst.error = _("missing CPS flags");
6441 return FAIL;
a737bd4d 6442 }
a737bd4d 6443
c19d1205
ZW
6444 *str = s - 1;
6445 return val;
a737bd4d
NC
6446}
6447
c19d1205
ZW
6448/* Parse an endian specifier ("BE" or "LE", case insensitive);
6449 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6450
6451static int
c19d1205 6452parse_endian_specifier (char **str)
a737bd4d 6453{
c19d1205
ZW
6454 int little_endian;
6455 char *s = *str;
a737bd4d 6456
c19d1205
ZW
6457 if (strncasecmp (s, "BE", 2))
6458 little_endian = 0;
6459 else if (strncasecmp (s, "LE", 2))
6460 little_endian = 1;
6461 else
a737bd4d 6462 {
c19d1205 6463 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6464 return FAIL;
6465 }
6466
c19d1205 6467 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6468 {
c19d1205 6469 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6470 return FAIL;
6471 }
6472
c19d1205
ZW
6473 *str = s + 2;
6474 return little_endian;
6475}
a737bd4d 6476
c19d1205
ZW
6477/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6478 value suitable for poking into the rotate field of an sxt or sxta
6479 instruction, or FAIL on error. */
6480
6481static int
6482parse_ror (char **str)
6483{
6484 int rot;
6485 char *s = *str;
6486
6487 if (strncasecmp (s, "ROR", 3) == 0)
6488 s += 3;
6489 else
a737bd4d 6490 {
c19d1205 6491 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6492 return FAIL;
6493 }
c19d1205
ZW
6494
6495 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6496 return FAIL;
6497
6498 switch (rot)
a737bd4d 6499 {
c19d1205
ZW
6500 case 0: *str = s; return 0x0;
6501 case 8: *str = s; return 0x1;
6502 case 16: *str = s; return 0x2;
6503 case 24: *str = s; return 0x3;
6504
6505 default:
6506 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6507 return FAIL;
6508 }
c19d1205 6509}
a737bd4d 6510
c19d1205
ZW
6511/* Parse a conditional code (from conds[] below). The value returned is in the
6512 range 0 .. 14, or FAIL. */
6513static int
6514parse_cond (char **str)
6515{
c462b453 6516 char *q;
c19d1205 6517 const struct asm_cond *c;
c462b453
PB
6518 int n;
6519 /* Condition codes are always 2 characters, so matching up to
6520 3 characters is sufficient. */
6521 char cond[3];
a737bd4d 6522
c462b453
PB
6523 q = *str;
6524 n = 0;
6525 while (ISALPHA (*q) && n < 3)
6526 {
e07e6e58 6527 cond[n] = TOLOWER (*q);
c462b453
PB
6528 q++;
6529 n++;
6530 }
a737bd4d 6531
21d799b5 6532 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6533 if (!c)
a737bd4d 6534 {
c19d1205 6535 inst.error = _("condition required");
a737bd4d
NC
6536 return FAIL;
6537 }
6538
c19d1205
ZW
6539 *str = q;
6540 return c->value;
6541}
6542
62b3e311
PB
6543/* Parse an option for a barrier instruction. Returns the encoding for the
6544 option, or FAIL. */
6545static int
6546parse_barrier (char **str)
6547{
6548 char *p, *q;
6549 const struct asm_barrier_opt *o;
6550
6551 p = q = *str;
6552 while (ISALPHA (*q))
6553 q++;
6554
21d799b5 6555 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6556 q - p);
62b3e311
PB
6557 if (!o)
6558 return FAIL;
6559
e797f7e0
MGD
6560 if (!mark_feature_used (&o->arch))
6561 return FAIL;
6562
62b3e311
PB
6563 *str = q;
6564 return o->value;
6565}
6566
92e90b6e
PB
6567/* Parse the operands of a table branch instruction. Similar to a memory
6568 operand. */
6569static int
6570parse_tb (char **str)
6571{
6572 char * p = *str;
6573 int reg;
6574
6575 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6576 {
6577 inst.error = _("'[' expected");
6578 return FAIL;
6579 }
92e90b6e 6580
dcbf9037 6581 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6582 {
6583 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6584 return FAIL;
6585 }
6586 inst.operands[0].reg = reg;
6587
6588 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6589 {
6590 inst.error = _("',' expected");
6591 return FAIL;
6592 }
5f4273c7 6593
dcbf9037 6594 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6595 {
6596 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6597 return FAIL;
6598 }
6599 inst.operands[0].imm = reg;
6600
6601 if (skip_past_comma (&p) == SUCCESS)
6602 {
6603 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6604 return FAIL;
e2b0ab59 6605 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6606 {
6607 inst.error = _("invalid shift");
6608 return FAIL;
6609 }
6610 inst.operands[0].shifted = 1;
6611 }
6612
6613 if (skip_past_char (&p, ']') == FAIL)
6614 {
6615 inst.error = _("']' expected");
6616 return FAIL;
6617 }
6618 *str = p;
6619 return SUCCESS;
6620}
6621
5287ad62
JB
6622/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6623 information on the types the operands can take and how they are encoded.
037e8744
JB
6624 Up to four operands may be read; this function handles setting the
6625 ".present" field for each read operand itself.
5287ad62
JB
6626 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6627 else returns FAIL. */
6628
6629static int
6630parse_neon_mov (char **str, int *which_operand)
6631{
6632 int i = *which_operand, val;
6633 enum arm_reg_type rtype;
6634 char *ptr = *str;
dcbf9037 6635 struct neon_type_el optype;
5f4273c7 6636
57785aa2
AV
6637 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6638 {
6639 /* Cases 17 or 19. */
6640 inst.operands[i].reg = val;
6641 inst.operands[i].isvec = 1;
6642 inst.operands[i].isscalar = 2;
6643 inst.operands[i].vectype = optype;
6644 inst.operands[i++].present = 1;
6645
6646 if (skip_past_comma (&ptr) == FAIL)
6647 goto wanted_comma;
6648
6649 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6650 {
6651 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6652 inst.operands[i].reg = val;
6653 inst.operands[i].isreg = 1;
6654 inst.operands[i].present = 1;
6655 }
6656 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6657 {
6658 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6659 inst.operands[i].reg = val;
6660 inst.operands[i].isvec = 1;
6661 inst.operands[i].isscalar = 2;
6662 inst.operands[i].vectype = optype;
6663 inst.operands[i++].present = 1;
6664
6665 if (skip_past_comma (&ptr) == FAIL)
6666 goto wanted_comma;
6667
6668 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6669 goto wanted_arm;
6670
6671 inst.operands[i].reg = val;
6672 inst.operands[i].isreg = 1;
6673 inst.operands[i++].present = 1;
6674
6675 if (skip_past_comma (&ptr) == FAIL)
6676 goto wanted_comma;
6677
6678 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6679 goto wanted_arm;
6680
6681 inst.operands[i].reg = val;
6682 inst.operands[i].isreg = 1;
6683 inst.operands[i].present = 1;
6684 }
6685 else
6686 {
6687 first_error (_("expected ARM or MVE vector register"));
6688 return FAIL;
6689 }
6690 }
6691 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6692 {
6693 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6694 inst.operands[i].reg = val;
6695 inst.operands[i].isscalar = 1;
dcbf9037 6696 inst.operands[i].vectype = optype;
5287ad62
JB
6697 inst.operands[i++].present = 1;
6698
6699 if (skip_past_comma (&ptr) == FAIL)
477330fc 6700 goto wanted_comma;
5f4273c7 6701
dcbf9037 6702 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6703 goto wanted_arm;
5f4273c7 6704
5287ad62
JB
6705 inst.operands[i].reg = val;
6706 inst.operands[i].isreg = 1;
6707 inst.operands[i].present = 1;
6708 }
57785aa2
AV
6709 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6710 != FAIL)
6711 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6712 != FAIL))
5287ad62
JB
6713 {
6714 /* Cases 0, 1, 2, 3, 5 (D only). */
6715 if (skip_past_comma (&ptr) == FAIL)
477330fc 6716 goto wanted_comma;
5f4273c7 6717
5287ad62
JB
6718 inst.operands[i].reg = val;
6719 inst.operands[i].isreg = 1;
6720 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6721 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6722 inst.operands[i].isvec = 1;
dcbf9037 6723 inst.operands[i].vectype = optype;
5287ad62
JB
6724 inst.operands[i++].present = 1;
6725
dcbf9037 6726 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6727 {
6728 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6729 Case 13: VMOV <Sd>, <Rm> */
6730 inst.operands[i].reg = val;
6731 inst.operands[i].isreg = 1;
6732 inst.operands[i].present = 1;
6733
6734 if (rtype == REG_TYPE_NQ)
6735 {
6736 first_error (_("can't use Neon quad register here"));
6737 return FAIL;
6738 }
6739 else if (rtype != REG_TYPE_VFS)
6740 {
6741 i++;
6742 if (skip_past_comma (&ptr) == FAIL)
6743 goto wanted_comma;
6744 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6745 goto wanted_arm;
6746 inst.operands[i].reg = val;
6747 inst.operands[i].isreg = 1;
6748 inst.operands[i].present = 1;
6749 }
6750 }
037e8744 6751 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6752 &optype)) != FAIL)
6753 {
6754 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6755 Case 1: VMOV<c><q> <Dd>, <Dm>
6756 Case 8: VMOV.F32 <Sd>, <Sm>
6757 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6758
6759 inst.operands[i].reg = val;
6760 inst.operands[i].isreg = 1;
6761 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6762 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6763 inst.operands[i].isvec = 1;
6764 inst.operands[i].vectype = optype;
6765 inst.operands[i].present = 1;
6766
6767 if (skip_past_comma (&ptr) == SUCCESS)
6768 {
6769 /* Case 15. */
6770 i++;
6771
6772 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6773 goto wanted_arm;
6774
6775 inst.operands[i].reg = val;
6776 inst.operands[i].isreg = 1;
6777 inst.operands[i++].present = 1;
6778
6779 if (skip_past_comma (&ptr) == FAIL)
6780 goto wanted_comma;
6781
6782 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6783 goto wanted_arm;
6784
6785 inst.operands[i].reg = val;
6786 inst.operands[i].isreg = 1;
6787 inst.operands[i].present = 1;
6788 }
6789 }
4641781c 6790 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6791 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6792 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6793 Case 10: VMOV.F32 <Sd>, #<imm>
6794 Case 11: VMOV.F64 <Dd>, #<imm> */
6795 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6796 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6797 == SUCCESS)
477330fc
RM
6798 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6799 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6800 ;
5287ad62 6801 else
477330fc
RM
6802 {
6803 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6804 return FAIL;
6805 }
5287ad62 6806 }
dcbf9037 6807 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6808 {
57785aa2 6809 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6810 inst.operands[i].reg = val;
6811 inst.operands[i].isreg = 1;
6812 inst.operands[i++].present = 1;
5f4273c7 6813
5287ad62 6814 if (skip_past_comma (&ptr) == FAIL)
477330fc 6815 goto wanted_comma;
5f4273c7 6816
57785aa2
AV
6817 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6818 {
6819 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6820 inst.operands[i].reg = val;
6821 inst.operands[i].isscalar = 2;
6822 inst.operands[i].present = 1;
6823 inst.operands[i].vectype = optype;
6824 }
6825 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6826 {
6827 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6828 inst.operands[i].reg = val;
6829 inst.operands[i].isscalar = 1;
6830 inst.operands[i].present = 1;
6831 inst.operands[i].vectype = optype;
6832 }
dcbf9037 6833 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6834 {
477330fc
RM
6835 inst.operands[i].reg = val;
6836 inst.operands[i].isreg = 1;
6837 inst.operands[i++].present = 1;
6838
6839 if (skip_past_comma (&ptr) == FAIL)
6840 goto wanted_comma;
6841
6842 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6843 != FAIL)
477330fc 6844 {
57785aa2 6845 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6846
477330fc
RM
6847 inst.operands[i].reg = val;
6848 inst.operands[i].isreg = 1;
6849 inst.operands[i].isvec = 1;
57785aa2 6850 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6851 inst.operands[i].vectype = optype;
6852 inst.operands[i].present = 1;
57785aa2
AV
6853
6854 if (rtype == REG_TYPE_VFS)
6855 {
6856 /* Case 14. */
6857 i++;
6858 if (skip_past_comma (&ptr) == FAIL)
6859 goto wanted_comma;
6860 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6861 &optype)) == FAIL)
6862 {
6863 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6864 return FAIL;
6865 }
6866 inst.operands[i].reg = val;
6867 inst.operands[i].isreg = 1;
6868 inst.operands[i].isvec = 1;
6869 inst.operands[i].issingle = 1;
6870 inst.operands[i].vectype = optype;
6871 inst.operands[i].present = 1;
6872 }
6873 }
6874 else
6875 {
6876 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6877 != FAIL)
6878 {
6879 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6880 inst.operands[i].reg = val;
6881 inst.operands[i].isvec = 1;
6882 inst.operands[i].isscalar = 2;
6883 inst.operands[i].vectype = optype;
6884 inst.operands[i++].present = 1;
6885
6886 if (skip_past_comma (&ptr) == FAIL)
6887 goto wanted_comma;
6888
6889 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6890 == FAIL)
6891 {
6892 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6893 return FAIL;
6894 }
6895 inst.operands[i].reg = val;
6896 inst.operands[i].isvec = 1;
6897 inst.operands[i].isscalar = 2;
6898 inst.operands[i].vectype = optype;
6899 inst.operands[i].present = 1;
6900 }
6901 else
6902 {
6903 first_error (_("VFP single, double or MVE vector register"
6904 " expected"));
6905 return FAIL;
6906 }
477330fc
RM
6907 }
6908 }
037e8744 6909 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6910 != FAIL)
6911 {
6912 /* Case 13. */
6913 inst.operands[i].reg = val;
6914 inst.operands[i].isreg = 1;
6915 inst.operands[i].isvec = 1;
6916 inst.operands[i].issingle = 1;
6917 inst.operands[i].vectype = optype;
6918 inst.operands[i].present = 1;
6919 }
5287ad62
JB
6920 }
6921 else
6922 {
dcbf9037 6923 first_error (_("parse error"));
5287ad62
JB
6924 return FAIL;
6925 }
6926
6927 /* Successfully parsed the operands. Update args. */
6928 *which_operand = i;
6929 *str = ptr;
6930 return SUCCESS;
6931
5f4273c7 6932 wanted_comma:
dcbf9037 6933 first_error (_("expected comma"));
5287ad62 6934 return FAIL;
5f4273c7
NC
6935
6936 wanted_arm:
dcbf9037 6937 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6938 return FAIL;
5287ad62
JB
6939}
6940
5be8be5d
DG
6941/* Use this macro when the operand constraints are different
6942 for ARM and THUMB (e.g. ldrd). */
6943#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6944 ((arm_operand) | ((thumb_operand) << 16))
6945
c19d1205
ZW
6946/* Matcher codes for parse_operands. */
6947enum operand_parse_code
6948{
6949 OP_stop, /* end of line */
6950
6951 OP_RR, /* ARM register */
6952 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6953 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6954 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6955 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6956 optional trailing ! */
c19d1205
ZW
6957 OP_RRw, /* ARM register, not r15, optional trailing ! */
6958 OP_RCP, /* Coprocessor number */
6959 OP_RCN, /* Coprocessor register */
6960 OP_RF, /* FPA register */
6961 OP_RVS, /* VFP single precision register */
5287ad62
JB
6962 OP_RVD, /* VFP double precision register (0..15) */
6963 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
6964 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6965 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
6966 */
5287ad62 6967 OP_RNQ, /* Neon quad precision register */
5ee91343 6968 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 6969 OP_RVSD, /* VFP single or double precision register */
1b883319 6970 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 6971 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 6972 OP_RNSD, /* Neon single or double precision register */
5287ad62 6973 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 6974 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 6975 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 6976 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6977 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6978 OP_RVC, /* VFP control register */
6979 OP_RMF, /* Maverick F register */
6980 OP_RMD, /* Maverick D register */
6981 OP_RMFX, /* Maverick FX register */
6982 OP_RMDX, /* Maverick DX register */
6983 OP_RMAX, /* Maverick AX register */
6984 OP_RMDS, /* Maverick DSPSC register */
6985 OP_RIWR, /* iWMMXt wR register */
6986 OP_RIWC, /* iWMMXt wC register */
6987 OP_RIWG, /* iWMMXt wCG register */
6988 OP_RXA, /* XScale accumulator register */
6989
5ee91343
AV
6990 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
6991 */
6992 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
6993 GPR (no SP/SP) */
a302e574 6994 OP_RMQ, /* MVE vector register. */
1b883319 6995 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 6996 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 6997
60f993ce
AV
6998 /* New operands for Armv8.1-M Mainline. */
6999 OP_LR, /* ARM LR register */
a302e574
AV
7000 OP_RRe, /* ARM register, only even numbered. */
7001 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7002 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7003 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7004
c19d1205 7005 OP_REGLST, /* ARM register list */
4b5a202f 7006 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7007 OP_VRSLST, /* VFP single-precision register list */
7008 OP_VRDLST, /* VFP double-precision register list */
037e8744 7009 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7010 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7011 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7012 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7013 OP_MSTRLST2, /* MVE vector list with two elements. */
7014 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7015
5287ad62 7016 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7017 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7018 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7019 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7020 zero. */
5287ad62 7021 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7022 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7023 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7024 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7025 */
a8465a06
AV
7026 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7027 scalar, or ARM register. */
5287ad62 7028 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7029 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7030 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7031 register. */
5d281bf0 7032 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7033 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7034 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7035 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7036 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7037 OP_RNDQMQ_Ibig,
5287ad62 7038 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7039 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7040 ARM register. */
2d447fca 7041 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7042 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7043
7044 OP_I0, /* immediate zero */
c19d1205
ZW
7045 OP_I7, /* immediate value 0 .. 7 */
7046 OP_I15, /* 0 .. 15 */
7047 OP_I16, /* 1 .. 16 */
5287ad62 7048 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7049 OP_I31, /* 0 .. 31 */
7050 OP_I31w, /* 0 .. 31, optional trailing ! */
7051 OP_I32, /* 1 .. 32 */
5287ad62
JB
7052 OP_I32z, /* 0 .. 32 */
7053 OP_I63, /* 0 .. 63 */
c19d1205 7054 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7055 OP_I64, /* 1 .. 64 */
7056 OP_I64z, /* 0 .. 64 */
c19d1205 7057 OP_I255, /* 0 .. 255 */
c19d1205
ZW
7058
7059 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7060 OP_I7b, /* 0 .. 7 */
7061 OP_I15b, /* 0 .. 15 */
7062 OP_I31b, /* 0 .. 31 */
7063
7064 OP_SH, /* shifter operand */
4962c51a 7065 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7066 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7067 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7068 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7069 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7070 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7071 OP_EXP, /* arbitrary expression */
7072 OP_EXPi, /* same, with optional immediate prefix */
7073 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7074 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7075 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7076 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7077 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7078
7079 OP_CPSF, /* CPS flags */
7080 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7081 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7082 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7083 OP_COND, /* conditional code */
92e90b6e 7084 OP_TB, /* Table branch. */
c19d1205 7085
037e8744
JB
7086 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7087
c19d1205 7088 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7089 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7090 OP_RR_EXi, /* ARM register or expression with imm prefix */
7091 OP_RF_IF, /* FPA register or immediate */
7092 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7093 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7094
7095 /* Optional operands. */
7096 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7097 OP_oI31b, /* 0 .. 31 */
5287ad62 7098 OP_oI32b, /* 1 .. 32 */
5f1af56b 7099 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7100 OP_oIffffb, /* 0 .. 65535 */
7101 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7102
7103 OP_oRR, /* ARM register */
60f993ce 7104 OP_oLR, /* ARM LR register */
c19d1205 7105 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7106 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7107 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7108 OP_oRND, /* Optional Neon double precision register */
7109 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7110 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7111 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7112 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7113 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7114 register. */
c19d1205
ZW
7115 OP_oSHll, /* LSL immediate */
7116 OP_oSHar, /* ASR immediate */
7117 OP_oSHllar, /* LSL or ASR immediate */
7118 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7119 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7120
1b883319
AV
7121 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7122
5be8be5d
DG
7123 /* Some pre-defined mixed (ARM/THUMB) operands. */
7124 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7125 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7126 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7127
c19d1205
ZW
7128 OP_FIRST_OPTIONAL = OP_oI7b
7129};
a737bd4d 7130
c19d1205
ZW
7131/* Generic instruction operand parser. This does no encoding and no
7132 semantic validation; it merely squirrels values away in the inst
7133 structure. Returns SUCCESS or FAIL depending on whether the
7134 specified grammar matched. */
7135static int
5be8be5d 7136parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7137{
5be8be5d 7138 unsigned const int *upat = pattern;
c19d1205
ZW
7139 char *backtrack_pos = 0;
7140 const char *backtrack_error = 0;
99aad254 7141 int i, val = 0, backtrack_index = 0;
5287ad62 7142 enum arm_reg_type rtype;
4962c51a 7143 parse_operand_result result;
5be8be5d 7144 unsigned int op_parse_code;
efd6b359 7145 bfd_boolean partial_match;
c19d1205 7146
e07e6e58
NC
7147#define po_char_or_fail(chr) \
7148 do \
7149 { \
7150 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7151 goto bad_args; \
e07e6e58
NC
7152 } \
7153 while (0)
c19d1205 7154
e07e6e58
NC
7155#define po_reg_or_fail(regtype) \
7156 do \
dcbf9037 7157 { \
e07e6e58 7158 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7159 & inst.operands[i].vectype); \
e07e6e58 7160 if (val == FAIL) \
477330fc
RM
7161 { \
7162 first_error (_(reg_expected_msgs[regtype])); \
7163 goto failure; \
7164 } \
e07e6e58
NC
7165 inst.operands[i].reg = val; \
7166 inst.operands[i].isreg = 1; \
7167 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7168 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7169 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7170 || rtype == REG_TYPE_VFD \
7171 || rtype == REG_TYPE_NQ); \
1b883319 7172 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7173 } \
e07e6e58
NC
7174 while (0)
7175
7176#define po_reg_or_goto(regtype, label) \
7177 do \
7178 { \
7179 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7180 & inst.operands[i].vectype); \
7181 if (val == FAIL) \
7182 goto label; \
dcbf9037 7183 \
e07e6e58
NC
7184 inst.operands[i].reg = val; \
7185 inst.operands[i].isreg = 1; \
7186 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7187 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7188 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7189 || rtype == REG_TYPE_VFD \
e07e6e58 7190 || rtype == REG_TYPE_NQ); \
1b883319 7191 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7192 } \
7193 while (0)
7194
7195#define po_imm_or_fail(min, max, popt) \
7196 do \
7197 { \
7198 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7199 goto failure; \
7200 inst.operands[i].imm = val; \
7201 } \
7202 while (0)
7203
57785aa2 7204#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7205 do \
7206 { \
57785aa2
AV
7207 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7208 reg_type); \
e07e6e58
NC
7209 if (val == FAIL) \
7210 goto label; \
7211 inst.operands[i].reg = val; \
7212 inst.operands[i].isscalar = 1; \
7213 } \
7214 while (0)
7215
7216#define po_misc_or_fail(expr) \
7217 do \
7218 { \
7219 if (expr) \
7220 goto failure; \
7221 } \
7222 while (0)
7223
7224#define po_misc_or_fail_no_backtrack(expr) \
7225 do \
7226 { \
7227 result = expr; \
7228 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7229 backtrack_pos = 0; \
7230 if (result != PARSE_OPERAND_SUCCESS) \
7231 goto failure; \
7232 } \
7233 while (0)
4962c51a 7234
52e7f43d
RE
7235#define po_barrier_or_imm(str) \
7236 do \
7237 { \
7238 val = parse_barrier (&str); \
ccb84d65
JB
7239 if (val == FAIL && ! ISALPHA (*str)) \
7240 goto immediate; \
7241 if (val == FAIL \
7242 /* ISB can only take SY as an option. */ \
7243 || ((inst.instruction & 0xf0) == 0x60 \
7244 && val != 0xf)) \
52e7f43d 7245 { \
ccb84d65
JB
7246 inst.error = _("invalid barrier type"); \
7247 backtrack_pos = 0; \
7248 goto failure; \
52e7f43d
RE
7249 } \
7250 } \
7251 while (0)
7252
c19d1205
ZW
7253 skip_whitespace (str);
7254
7255 for (i = 0; upat[i] != OP_stop; i++)
7256 {
5be8be5d
DG
7257 op_parse_code = upat[i];
7258 if (op_parse_code >= 1<<16)
7259 op_parse_code = thumb ? (op_parse_code >> 16)
7260 : (op_parse_code & ((1<<16)-1));
7261
7262 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7263 {
7264 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7265 backtrack_pos = str;
7266 backtrack_error = inst.error;
7267 backtrack_index = i;
7268 }
7269
b6702015 7270 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7271 po_char_or_fail (',');
7272
5be8be5d 7273 switch (op_parse_code)
c19d1205
ZW
7274 {
7275 /* Registers */
7276 case OP_oRRnpc:
5be8be5d 7277 case OP_oRRnpcsp:
c19d1205 7278 case OP_RRnpc:
5be8be5d 7279 case OP_RRnpcsp:
c19d1205 7280 case OP_oRR:
a302e574
AV
7281 case OP_RRe:
7282 case OP_RRo:
60f993ce
AV
7283 case OP_LR:
7284 case OP_oLR:
c19d1205
ZW
7285 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7286 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7287 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7288 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7289 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7290 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7291 case OP_oRND:
5ee91343
AV
7292 case OP_RNDMQR:
7293 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7294 break;
7295 try_rndmq:
7296 case OP_RNDMQ:
7297 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7298 break;
7299 try_rnd:
5287ad62 7300 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7301 case OP_RVC:
7302 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7303 break;
7304 /* Also accept generic coprocessor regs for unknown registers. */
7305 coproc_reg:
ba6cd17f
SD
7306 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7307 break;
7308 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7309 existing register with a value of 0, this seems like the
7310 best way to parse P0. */
7311 vpr_po:
7312 if (strncasecmp (str, "P0", 2) == 0)
7313 {
7314 str += 2;
7315 inst.operands[i].isreg = 1;
7316 inst.operands[i].reg = 13;
7317 }
7318 else
7319 goto failure;
cd2cf30b 7320 break;
c19d1205
ZW
7321 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7322 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7323 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7324 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7325 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7326 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7327 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7328 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7329 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7330 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7331 case OP_oRNQ:
5ee91343
AV
7332 case OP_RNQMQ:
7333 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7334 break;
7335 try_nq:
5287ad62 7336 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7337 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7338 case OP_RNDQMQR:
7339 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7340 break;
7341 try_rndqmq:
5ee91343
AV
7342 case OP_oRNDQMQ:
7343 case OP_RNDQMQ:
7344 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7345 break;
7346 try_rndq:
477330fc 7347 case OP_oRNDQ:
5287ad62 7348 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7349 case OP_RVSDMQ:
7350 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7351 break;
7352 try_rvsd:
477330fc 7353 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7354 case OP_RVSD_COND:
7355 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7356 break;
477330fc
RM
7357 case OP_oRNSDQ:
7358 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7359 case OP_RNSDQMQR:
7360 po_reg_or_goto (REG_TYPE_RN, try_mq);
7361 break;
7362 try_mq:
7363 case OP_oRNSDQMQ:
7364 case OP_RNSDQMQ:
7365 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7366 break;
7367 try_nsdq2:
7368 po_reg_or_fail (REG_TYPE_NSDQ);
7369 inst.error = 0;
7370 break;
35d1cfc2
AV
7371 case OP_RMQRR:
7372 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7373 break;
7374 try_rmq:
a302e574
AV
7375 case OP_RMQ:
7376 po_reg_or_fail (REG_TYPE_MQ);
7377 break;
477330fc
RM
7378 /* Neon scalar. Using an element size of 8 means that some invalid
7379 scalars are accepted here, so deal with those in later code. */
57785aa2 7380 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7381
7382 case OP_RNDQ_I0:
7383 {
7384 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7385 break;
7386 try_imm0:
7387 po_imm_or_fail (0, 0, TRUE);
7388 }
7389 break;
7390
7391 case OP_RVSD_I0:
7392 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7393 break;
7394
1b883319
AV
7395 case OP_RSVDMQ_FI0:
7396 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7397 break;
7398 try_rsvd_fi0:
aacf0b33
KT
7399 case OP_RSVD_FI0:
7400 {
7401 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7402 break;
7403 try_ifimm0:
7404 if (parse_ifimm_zero (&str))
7405 inst.operands[i].imm = 0;
7406 else
7407 {
7408 inst.error
7409 = _("only floating point zero is allowed as immediate value");
7410 goto failure;
7411 }
7412 }
7413 break;
7414
477330fc
RM
7415 case OP_RR_RNSC:
7416 {
57785aa2 7417 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7418 break;
7419 try_rr:
7420 po_reg_or_fail (REG_TYPE_RN);
7421 }
7422 break;
7423
a8465a06
AV
7424 case OP_RNSDQ_RNSC_MQ_RR:
7425 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7426 break;
7427 try_rnsdq_rnsc_mq:
886e1c73
AV
7428 case OP_RNSDQ_RNSC_MQ:
7429 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7430 break;
7431 try_rnsdq_rnsc:
477330fc
RM
7432 case OP_RNSDQ_RNSC:
7433 {
57785aa2
AV
7434 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7435 inst.error = 0;
477330fc
RM
7436 break;
7437 try_nsdq:
7438 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7439 inst.error = 0;
477330fc
RM
7440 }
7441 break;
7442
dec41383
JW
7443 case OP_RNSD_RNSC:
7444 {
57785aa2 7445 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7446 break;
7447 try_s_scalar:
57785aa2 7448 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7449 break;
7450 try_nsd:
7451 po_reg_or_fail (REG_TYPE_NSD);
7452 }
7453 break;
7454
42b16635
AV
7455 case OP_RNDQMQ_RNSC_RR:
7456 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7457 break;
7458 try_rndq_rnsc_rr:
7459 case OP_RNDQ_RNSC_RR:
7460 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7461 break;
5d281bf0
AV
7462 case OP_RNDQMQ_RNSC:
7463 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7464 break;
7465 try_rndq_rnsc:
477330fc
RM
7466 case OP_RNDQ_RNSC:
7467 {
57785aa2 7468 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7469 break;
7470 try_ndq:
7471 po_reg_or_fail (REG_TYPE_NDQ);
7472 }
7473 break;
7474
7475 case OP_RND_RNSC:
7476 {
57785aa2 7477 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7478 break;
7479 try_vfd:
7480 po_reg_or_fail (REG_TYPE_VFD);
7481 }
7482 break;
7483
7484 case OP_VMOV:
7485 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7486 not careful then bad things might happen. */
7487 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7488 break;
7489
f601a00c
AV
7490 case OP_RNDQMQ_Ibig:
7491 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7492 break;
7493 try_rndq_ibig:
477330fc
RM
7494 case OP_RNDQ_Ibig:
7495 {
7496 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7497 break;
7498 try_immbig:
7499 /* There's a possibility of getting a 64-bit immediate here, so
7500 we need special handling. */
8335d6aa
JW
7501 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7502 == FAIL)
477330fc
RM
7503 {
7504 inst.error = _("immediate value is out of range");
7505 goto failure;
7506 }
7507 }
7508 break;
7509
5150f0d8
AV
7510 case OP_RNDQMQ_I63b_RR:
7511 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7512 break;
7513 try_rndq_i63b_rr:
7514 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7515 break;
7516 try_rndq_i63b:
477330fc
RM
7517 case OP_RNDQ_I63b:
7518 {
7519 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7520 break;
7521 try_shimm:
7522 po_imm_or_fail (0, 63, TRUE);
7523 }
7524 break;
c19d1205
ZW
7525
7526 case OP_RRnpcb:
7527 po_char_or_fail ('[');
7528 po_reg_or_fail (REG_TYPE_RN);
7529 po_char_or_fail (']');
7530 break;
a737bd4d 7531
55881a11 7532 case OP_RRnpctw:
c19d1205 7533 case OP_RRw:
b6702015 7534 case OP_oRRw:
c19d1205
ZW
7535 po_reg_or_fail (REG_TYPE_RN);
7536 if (skip_past_char (&str, '!') == SUCCESS)
7537 inst.operands[i].writeback = 1;
7538 break;
7539
7540 /* Immediates */
7541 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7542 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7543 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7544 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7545 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7546 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7547 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 7548 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7549 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7550 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7551 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 7552 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
7553
7554 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7555 case OP_oI7b:
7556 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7557 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7558 case OP_oI31b:
7559 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7560 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7561 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7562 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7563
7564 /* Immediate variants */
7565 case OP_oI255c:
7566 po_char_or_fail ('{');
7567 po_imm_or_fail (0, 255, TRUE);
7568 po_char_or_fail ('}');
7569 break;
7570
7571 case OP_I31w:
7572 /* The expression parser chokes on a trailing !, so we have
7573 to find it first and zap it. */
7574 {
7575 char *s = str;
7576 while (*s && *s != ',')
7577 s++;
7578 if (s[-1] == '!')
7579 {
7580 s[-1] = '\0';
7581 inst.operands[i].writeback = 1;
7582 }
7583 po_imm_or_fail (0, 31, TRUE);
7584 if (str == s - 1)
7585 str = s;
7586 }
7587 break;
7588
7589 /* Expressions */
7590 case OP_EXPi: EXPi:
e2b0ab59 7591 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7592 GE_OPT_PREFIX));
7593 break;
7594
7595 case OP_EXP:
e2b0ab59 7596 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7597 GE_NO_PREFIX));
7598 break;
7599
7600 case OP_EXPr: EXPr:
e2b0ab59 7601 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7602 GE_NO_PREFIX));
e2b0ab59 7603 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7604 {
c19d1205
ZW
7605 val = parse_reloc (&str);
7606 if (val == -1)
7607 {
7608 inst.error = _("unrecognized relocation suffix");
7609 goto failure;
7610 }
7611 else if (val != BFD_RELOC_UNUSED)
7612 {
7613 inst.operands[i].imm = val;
7614 inst.operands[i].hasreloc = 1;
7615 }
a737bd4d 7616 }
c19d1205 7617 break;
a737bd4d 7618
e2b0ab59
AV
7619 case OP_EXPs:
7620 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7621 GE_NO_PREFIX));
7622 if (inst.relocs[i].exp.X_op == O_symbol)
7623 {
7624 inst.operands[i].hasreloc = 1;
7625 }
7626 else if (inst.relocs[i].exp.X_op == O_constant)
7627 {
7628 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7629 inst.operands[i].hasreloc = 0;
7630 }
7631 break;
7632
b6895b4f
PB
7633 /* Operand for MOVW or MOVT. */
7634 case OP_HALF:
7635 po_misc_or_fail (parse_half (&str));
7636 break;
7637
e07e6e58 7638 /* Register or expression. */
c19d1205
ZW
7639 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7640 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7641
e07e6e58 7642 /* Register or immediate. */
c19d1205
ZW
7643 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7644 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7645
23d00a41
SD
7646 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7647 I32: po_imm_or_fail (1, 32, FALSE); break;
7648
c19d1205
ZW
7649 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7650 IF:
7651 if (!is_immediate_prefix (*str))
7652 goto bad_args;
7653 str++;
7654 val = parse_fpa_immediate (&str);
7655 if (val == FAIL)
7656 goto failure;
7657 /* FPA immediates are encoded as registers 8-15.
7658 parse_fpa_immediate has already applied the offset. */
7659 inst.operands[i].reg = val;
7660 inst.operands[i].isreg = 1;
7661 break;
09d92015 7662
2d447fca
JM
7663 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7664 I32z: po_imm_or_fail (0, 32, FALSE); break;
7665
e07e6e58 7666 /* Two kinds of register. */
c19d1205
ZW
7667 case OP_RIWR_RIWC:
7668 {
7669 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7670 if (!rege
7671 || (rege->type != REG_TYPE_MMXWR
7672 && rege->type != REG_TYPE_MMXWC
7673 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7674 {
7675 inst.error = _("iWMMXt data or control register expected");
7676 goto failure;
7677 }
7678 inst.operands[i].reg = rege->number;
7679 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7680 }
7681 break;
09d92015 7682
41adaa5c
JM
7683 case OP_RIWC_RIWG:
7684 {
7685 struct reg_entry *rege = arm_reg_parse_multi (&str);
7686 if (!rege
7687 || (rege->type != REG_TYPE_MMXWC
7688 && rege->type != REG_TYPE_MMXWCG))
7689 {
7690 inst.error = _("iWMMXt control register expected");
7691 goto failure;
7692 }
7693 inst.operands[i].reg = rege->number;
7694 inst.operands[i].isreg = 1;
7695 }
7696 break;
7697
c19d1205
ZW
7698 /* Misc */
7699 case OP_CPSF: val = parse_cps_flags (&str); break;
7700 case OP_ENDI: val = parse_endian_specifier (&str); break;
7701 case OP_oROR: val = parse_ror (&str); break;
1b883319 7702 try_cond:
c19d1205 7703 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7704 case OP_oBARRIER_I15:
7705 po_barrier_or_imm (str); break;
7706 immediate:
7707 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7708 goto failure;
52e7f43d 7709 break;
c19d1205 7710
fa94de6b 7711 case OP_wPSR:
d2cd1205 7712 case OP_rPSR:
90ec0d68
MGD
7713 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7714 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7715 {
7716 inst.error = _("Banked registers are not available with this "
7717 "architecture.");
7718 goto failure;
7719 }
7720 break;
d2cd1205
JB
7721 try_psr:
7722 val = parse_psr (&str, op_parse_code == OP_wPSR);
7723 break;
037e8744 7724
32c36c3c
AV
7725 case OP_VLDR:
7726 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7727 break;
7728 try_sysreg:
7729 val = parse_sys_vldr_vstr (&str);
7730 break;
7731
477330fc
RM
7732 case OP_APSR_RR:
7733 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7734 break;
7735 try_apsr:
7736 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7737 instruction). */
7738 if (strncasecmp (str, "APSR_", 5) == 0)
7739 {
7740 unsigned found = 0;
7741 str += 5;
7742 while (found < 15)
7743 switch (*str++)
7744 {
7745 case 'c': found = (found & 1) ? 16 : found | 1; break;
7746 case 'n': found = (found & 2) ? 16 : found | 2; break;
7747 case 'z': found = (found & 4) ? 16 : found | 4; break;
7748 case 'v': found = (found & 8) ? 16 : found | 8; break;
7749 default: found = 16;
7750 }
7751 if (found != 15)
7752 goto failure;
7753 inst.operands[i].isvec = 1;
f7c21dc7
NC
7754 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7755 inst.operands[i].reg = REG_PC;
477330fc
RM
7756 }
7757 else
7758 goto failure;
7759 break;
037e8744 7760
92e90b6e
PB
7761 case OP_TB:
7762 po_misc_or_fail (parse_tb (&str));
7763 break;
7764
e07e6e58 7765 /* Register lists. */
c19d1205 7766 case OP_REGLST:
4b5a202f 7767 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7768 if (*str == '^')
7769 {
5e0d7f77 7770 inst.operands[i].writeback = 1;
c19d1205
ZW
7771 str++;
7772 }
7773 break;
09d92015 7774
4b5a202f
AV
7775 case OP_CLRMLST:
7776 val = parse_reg_list (&str, REGLIST_CLRM);
7777 break;
7778
c19d1205 7779 case OP_VRSLST:
efd6b359
AV
7780 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7781 &partial_match);
c19d1205 7782 break;
09d92015 7783
c19d1205 7784 case OP_VRDLST:
efd6b359
AV
7785 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7786 &partial_match);
c19d1205 7787 break;
a737bd4d 7788
477330fc
RM
7789 case OP_VRSDLST:
7790 /* Allow Q registers too. */
7791 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7792 REGLIST_NEON_D, &partial_match);
477330fc
RM
7793 if (val == FAIL)
7794 {
7795 inst.error = NULL;
7796 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7797 REGLIST_VFP_S, &partial_match);
7798 inst.operands[i].issingle = 1;
7799 }
7800 break;
7801
7802 case OP_VRSDVLST:
7803 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7804 REGLIST_VFP_D_VPR, &partial_match);
7805 if (val == FAIL && !partial_match)
7806 {
7807 inst.error = NULL;
7808 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7809 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7810 inst.operands[i].issingle = 1;
7811 }
7812 break;
7813
7814 case OP_NRDLST:
7815 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7816 REGLIST_NEON_D, &partial_match);
477330fc 7817 break;
5287ad62 7818
35c228db
AV
7819 case OP_MSTRLST4:
7820 case OP_MSTRLST2:
7821 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7822 1, &inst.operands[i].vectype);
7823 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7824 goto failure;
7825 break;
5287ad62 7826 case OP_NSTRLST:
477330fc 7827 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7828 0, &inst.operands[i].vectype);
477330fc 7829 break;
5287ad62 7830
c19d1205 7831 /* Addressing modes */
35c228db
AV
7832 case OP_ADDRMVE:
7833 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7834 break;
7835
c19d1205
ZW
7836 case OP_ADDR:
7837 po_misc_or_fail (parse_address (&str, i));
7838 break;
09d92015 7839
4962c51a
MS
7840 case OP_ADDRGLDR:
7841 po_misc_or_fail_no_backtrack (
477330fc 7842 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7843 break;
7844
7845 case OP_ADDRGLDRS:
7846 po_misc_or_fail_no_backtrack (
477330fc 7847 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7848 break;
7849
7850 case OP_ADDRGLDC:
7851 po_misc_or_fail_no_backtrack (
477330fc 7852 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7853 break;
7854
c19d1205
ZW
7855 case OP_SH:
7856 po_misc_or_fail (parse_shifter_operand (&str, i));
7857 break;
09d92015 7858
4962c51a
MS
7859 case OP_SHG:
7860 po_misc_or_fail_no_backtrack (
477330fc 7861 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7862 break;
7863
c19d1205
ZW
7864 case OP_oSHll:
7865 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7866 break;
09d92015 7867
c19d1205
ZW
7868 case OP_oSHar:
7869 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7870 break;
09d92015 7871
c19d1205
ZW
7872 case OP_oSHllar:
7873 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7874 break;
09d92015 7875
1b883319
AV
7876 case OP_RMQRZ:
7877 case OP_oRMQRZ:
7878 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
7879 break;
e39c1607
SD
7880
7881 case OP_RR_ZR:
1b883319
AV
7882 try_rr_zr:
7883 po_reg_or_goto (REG_TYPE_RN, ZR);
7884 break;
7885 ZR:
7886 po_reg_or_fail (REG_TYPE_ZR);
7887 break;
7888
c19d1205 7889 default:
5be8be5d 7890 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7891 }
09d92015 7892
c19d1205
ZW
7893 /* Various value-based sanity checks and shared operations. We
7894 do not signal immediate failures for the register constraints;
7895 this allows a syntax error to take precedence. */
5be8be5d 7896 switch (op_parse_code)
c19d1205
ZW
7897 {
7898 case OP_oRRnpc:
7899 case OP_RRnpc:
7900 case OP_RRnpcb:
7901 case OP_RRw:
b6702015 7902 case OP_oRRw:
c19d1205
ZW
7903 case OP_RRnpc_I0:
7904 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7905 inst.error = BAD_PC;
7906 break;
09d92015 7907
5be8be5d
DG
7908 case OP_oRRnpcsp:
7909 case OP_RRnpcsp:
23d00a41 7910 case OP_RRnpcsp_I32:
5be8be5d
DG
7911 if (inst.operands[i].isreg)
7912 {
7913 if (inst.operands[i].reg == REG_PC)
7914 inst.error = BAD_PC;
5c8ed6a4
JW
7915 else if (inst.operands[i].reg == REG_SP
7916 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7917 relaxed since ARMv8-A. */
7918 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7919 {
7920 gas_assert (thumb);
7921 inst.error = BAD_SP;
7922 }
5be8be5d
DG
7923 }
7924 break;
7925
55881a11 7926 case OP_RRnpctw:
fa94de6b
RM
7927 if (inst.operands[i].isreg
7928 && inst.operands[i].reg == REG_PC
55881a11
MGD
7929 && (inst.operands[i].writeback || thumb))
7930 inst.error = BAD_PC;
7931 break;
7932
1b883319 7933 case OP_RVSD_COND:
32c36c3c
AV
7934 case OP_VLDR:
7935 if (inst.operands[i].isreg)
7936 break;
7937 /* fall through. */
1b883319 7938
c19d1205
ZW
7939 case OP_CPSF:
7940 case OP_ENDI:
7941 case OP_oROR:
d2cd1205
JB
7942 case OP_wPSR:
7943 case OP_rPSR:
c19d1205 7944 case OP_COND:
52e7f43d 7945 case OP_oBARRIER_I15:
c19d1205 7946 case OP_REGLST:
4b5a202f 7947 case OP_CLRMLST:
c19d1205
ZW
7948 case OP_VRSLST:
7949 case OP_VRDLST:
477330fc 7950 case OP_VRSDLST:
efd6b359 7951 case OP_VRSDVLST:
477330fc
RM
7952 case OP_NRDLST:
7953 case OP_NSTRLST:
35c228db
AV
7954 case OP_MSTRLST2:
7955 case OP_MSTRLST4:
c19d1205
ZW
7956 if (val == FAIL)
7957 goto failure;
7958 inst.operands[i].imm = val;
7959 break;
a737bd4d 7960
60f993ce
AV
7961 case OP_LR:
7962 case OP_oLR:
7963 if (inst.operands[i].reg != REG_LR)
7964 inst.error = _("operand must be LR register");
7965 break;
7966
1b883319
AV
7967 case OP_RMQRZ:
7968 case OP_oRMQRZ:
e39c1607 7969 case OP_RR_ZR:
1b883319
AV
7970 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
7971 inst.error = BAD_PC;
7972 break;
7973
a302e574
AV
7974 case OP_RRe:
7975 if (inst.operands[i].isreg
7976 && (inst.operands[i].reg & 0x00000001) != 0)
7977 inst.error = BAD_ODD;
7978 break;
7979
7980 case OP_RRo:
7981 if (inst.operands[i].isreg)
7982 {
7983 if ((inst.operands[i].reg & 0x00000001) != 1)
7984 inst.error = BAD_EVEN;
7985 else if (inst.operands[i].reg == REG_SP)
7986 as_tsktsk (MVE_BAD_SP);
7987 else if (inst.operands[i].reg == REG_PC)
7988 inst.error = BAD_PC;
7989 }
7990 break;
7991
c19d1205
ZW
7992 default:
7993 break;
7994 }
09d92015 7995
c19d1205
ZW
7996 /* If we get here, this operand was successfully parsed. */
7997 inst.operands[i].present = 1;
7998 continue;
09d92015 7999
c19d1205 8000 bad_args:
09d92015 8001 inst.error = BAD_ARGS;
c19d1205
ZW
8002
8003 failure:
8004 if (!backtrack_pos)
d252fdde
PB
8005 {
8006 /* The parse routine should already have set inst.error, but set a
5f4273c7 8007 default here just in case. */
d252fdde 8008 if (!inst.error)
5ee91343 8009 inst.error = BAD_SYNTAX;
d252fdde
PB
8010 return FAIL;
8011 }
c19d1205
ZW
8012
8013 /* Do not backtrack over a trailing optional argument that
8014 absorbed some text. We will only fail again, with the
8015 'garbage following instruction' error message, which is
8016 probably less helpful than the current one. */
8017 if (backtrack_index == i && backtrack_pos != str
8018 && upat[i+1] == OP_stop)
d252fdde
PB
8019 {
8020 if (!inst.error)
5ee91343 8021 inst.error = BAD_SYNTAX;
d252fdde
PB
8022 return FAIL;
8023 }
c19d1205
ZW
8024
8025 /* Try again, skipping the optional argument at backtrack_pos. */
8026 str = backtrack_pos;
8027 inst.error = backtrack_error;
8028 inst.operands[backtrack_index].present = 0;
8029 i = backtrack_index;
8030 backtrack_pos = 0;
09d92015 8031 }
09d92015 8032
c19d1205
ZW
8033 /* Check that we have parsed all the arguments. */
8034 if (*str != '\0' && !inst.error)
8035 inst.error = _("garbage following instruction");
09d92015 8036
c19d1205 8037 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8038}
8039
c19d1205
ZW
8040#undef po_char_or_fail
8041#undef po_reg_or_fail
8042#undef po_reg_or_goto
8043#undef po_imm_or_fail
5287ad62 8044#undef po_scalar_or_fail
52e7f43d 8045#undef po_barrier_or_imm
e07e6e58 8046
c19d1205 8047/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8048#define constraint(expr, err) \
8049 do \
c19d1205 8050 { \
e07e6e58
NC
8051 if (expr) \
8052 { \
8053 inst.error = err; \
8054 return; \
8055 } \
c19d1205 8056 } \
e07e6e58 8057 while (0)
c19d1205 8058
fdfde340
JM
8059/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8060 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8061 is the BadReg predicate in ARM's Thumb-2 documentation.
8062
8063 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8064 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8065#define reject_bad_reg(reg) \
8066 do \
8067 if (reg == REG_PC) \
8068 { \
8069 inst.error = BAD_PC; \
8070 return; \
8071 } \
8072 else if (reg == REG_SP \
8073 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8074 { \
8075 inst.error = BAD_SP; \
8076 return; \
8077 } \
fdfde340
JM
8078 while (0)
8079
94206790
MM
8080/* If REG is R13 (the stack pointer), warn that its use is
8081 deprecated. */
8082#define warn_deprecated_sp(reg) \
8083 do \
8084 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8085 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8086 while (0)
8087
c19d1205
ZW
8088/* Functions for operand encoding. ARM, then Thumb. */
8089
d840c081 8090#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8091
9db2f6b4
RL
8092/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8093
8094 The only binary encoding difference is the Coprocessor number. Coprocessor
8095 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8096 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8097 exists for Single-Precision operation. */
8098
8099static void
8100do_scalar_fp16_v82_encode (void)
8101{
5ee91343 8102 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8103 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8104 " the behaviour is UNPREDICTABLE"));
8105 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8106 _(BAD_FP16));
8107
8108 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8109 mark_feature_used (&arm_ext_fp16);
8110}
8111
c19d1205
ZW
8112/* If VAL can be encoded in the immediate field of an ARM instruction,
8113 return the encoded form. Otherwise, return FAIL. */
8114
8115static unsigned int
8116encode_arm_immediate (unsigned int val)
09d92015 8117{
c19d1205
ZW
8118 unsigned int a, i;
8119
4f1d6205
L
8120 if (val <= 0xff)
8121 return val;
8122
8123 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8124 if ((a = rotate_left (val, i)) <= 0xff)
8125 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8126
8127 return FAIL;
09d92015
MM
8128}
8129
c19d1205
ZW
8130/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8131 return the encoded form. Otherwise, return FAIL. */
8132static unsigned int
8133encode_thumb32_immediate (unsigned int val)
09d92015 8134{
c19d1205 8135 unsigned int a, i;
09d92015 8136
9c3c69f2 8137 if (val <= 0xff)
c19d1205 8138 return val;
a737bd4d 8139
9c3c69f2 8140 for (i = 1; i <= 24; i++)
09d92015 8141 {
9c3c69f2
PB
8142 a = val >> i;
8143 if ((val & ~(0xff << i)) == 0)
8144 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8145 }
a737bd4d 8146
c19d1205
ZW
8147 a = val & 0xff;
8148 if (val == ((a << 16) | a))
8149 return 0x100 | a;
8150 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8151 return 0x300 | a;
09d92015 8152
c19d1205
ZW
8153 a = val & 0xff00;
8154 if (val == ((a << 16) | a))
8155 return 0x200 | (a >> 8);
a737bd4d 8156
c19d1205 8157 return FAIL;
09d92015 8158}
5287ad62 8159/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8160
8161static void
5287ad62
JB
8162encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8163{
8164 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8165 && reg > 15)
8166 {
b1cc4aeb 8167 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8168 {
8169 if (thumb_mode)
8170 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8171 fpu_vfp_ext_d32);
8172 else
8173 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8174 fpu_vfp_ext_d32);
8175 }
5287ad62 8176 else
477330fc
RM
8177 {
8178 first_error (_("D register out of range for selected VFP version"));
8179 return;
8180 }
5287ad62
JB
8181 }
8182
c19d1205 8183 switch (pos)
09d92015 8184 {
c19d1205
ZW
8185 case VFP_REG_Sd:
8186 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8187 break;
8188
8189 case VFP_REG_Sn:
8190 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8191 break;
8192
8193 case VFP_REG_Sm:
8194 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8195 break;
8196
5287ad62
JB
8197 case VFP_REG_Dd:
8198 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8199 break;
5f4273c7 8200
5287ad62
JB
8201 case VFP_REG_Dn:
8202 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8203 break;
5f4273c7 8204
5287ad62
JB
8205 case VFP_REG_Dm:
8206 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8207 break;
8208
c19d1205
ZW
8209 default:
8210 abort ();
09d92015 8211 }
09d92015
MM
8212}
8213
c19d1205 8214/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8215 if any, is handled by md_apply_fix. */
09d92015 8216static void
c19d1205 8217encode_arm_shift (int i)
09d92015 8218{
008a97ef
RL
8219 /* register-shifted register. */
8220 if (inst.operands[i].immisreg)
8221 {
bf355b69
MR
8222 int op_index;
8223 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8224 {
5689c942
RL
8225 /* Check the operand only when it's presented. In pre-UAL syntax,
8226 if the destination register is the same as the first operand, two
8227 register form of the instruction can be used. */
bf355b69
MR
8228 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8229 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8230 as_warn (UNPRED_REG ("r15"));
8231 }
8232
8233 if (inst.operands[i].imm == REG_PC)
8234 as_warn (UNPRED_REG ("r15"));
8235 }
8236
c19d1205
ZW
8237 if (inst.operands[i].shift_kind == SHIFT_RRX)
8238 inst.instruction |= SHIFT_ROR << 5;
8239 else
09d92015 8240 {
c19d1205
ZW
8241 inst.instruction |= inst.operands[i].shift_kind << 5;
8242 if (inst.operands[i].immisreg)
8243 {
8244 inst.instruction |= SHIFT_BY_REG;
8245 inst.instruction |= inst.operands[i].imm << 8;
8246 }
8247 else
e2b0ab59 8248 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8249 }
c19d1205 8250}
09d92015 8251
c19d1205
ZW
8252static void
8253encode_arm_shifter_operand (int i)
8254{
8255 if (inst.operands[i].isreg)
09d92015 8256 {
c19d1205
ZW
8257 inst.instruction |= inst.operands[i].reg;
8258 encode_arm_shift (i);
09d92015 8259 }
c19d1205 8260 else
a415b1cd
JB
8261 {
8262 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8263 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8264 inst.instruction |= inst.operands[i].imm;
8265 }
09d92015
MM
8266}
8267
c19d1205 8268/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8269static void
c19d1205 8270encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8271{
2b2f5df9
NC
8272 /* PR 14260:
8273 Generate an error if the operand is not a register. */
8274 constraint (!inst.operands[i].isreg,
8275 _("Instruction does not support =N addresses"));
8276
c19d1205 8277 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8278
c19d1205 8279 if (inst.operands[i].preind)
09d92015 8280 {
c19d1205
ZW
8281 if (is_t)
8282 {
8283 inst.error = _("instruction does not accept preindexed addressing");
8284 return;
8285 }
8286 inst.instruction |= PRE_INDEX;
8287 if (inst.operands[i].writeback)
8288 inst.instruction |= WRITE_BACK;
09d92015 8289
c19d1205
ZW
8290 }
8291 else if (inst.operands[i].postind)
8292 {
9c2799c2 8293 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8294 if (is_t)
8295 inst.instruction |= WRITE_BACK;
8296 }
8297 else /* unindexed - only for coprocessor */
09d92015 8298 {
c19d1205 8299 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8300 return;
8301 }
8302
c19d1205
ZW
8303 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8304 && (((inst.instruction & 0x000f0000) >> 16)
8305 == ((inst.instruction & 0x0000f000) >> 12)))
8306 as_warn ((inst.instruction & LOAD_BIT)
8307 ? _("destination register same as write-back base")
8308 : _("source register same as write-back base"));
09d92015
MM
8309}
8310
c19d1205
ZW
8311/* inst.operands[i] was set up by parse_address. Encode it into an
8312 ARM-format mode 2 load or store instruction. If is_t is true,
8313 reject forms that cannot be used with a T instruction (i.e. not
8314 post-indexed). */
a737bd4d 8315static void
c19d1205 8316encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8317{
5be8be5d
DG
8318 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8319
c19d1205 8320 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8321
c19d1205 8322 if (inst.operands[i].immisreg)
09d92015 8323 {
5be8be5d
DG
8324 constraint ((inst.operands[i].imm == REG_PC
8325 || (is_pc && inst.operands[i].writeback)),
8326 BAD_PC_ADDRESSING);
c19d1205
ZW
8327 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8328 inst.instruction |= inst.operands[i].imm;
8329 if (!inst.operands[i].negative)
8330 inst.instruction |= INDEX_UP;
8331 if (inst.operands[i].shifted)
8332 {
8333 if (inst.operands[i].shift_kind == SHIFT_RRX)
8334 inst.instruction |= SHIFT_ROR << 5;
8335 else
8336 {
8337 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8338 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8339 }
8340 }
09d92015 8341 }
e2b0ab59 8342 else /* immediate offset in inst.relocs[0] */
09d92015 8343 {
e2b0ab59 8344 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8345 {
8346 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8347
8348 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8349 cannot use PC in addressing.
8350 PC cannot be used in writeback addressing, either. */
8351 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8352 BAD_PC_ADDRESSING);
23a10334 8353
dc5ec521 8354 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8355 if (warn_on_deprecated
8356 && !is_load
8357 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8358 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8359 }
8360
e2b0ab59 8361 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8362 {
8363 /* Prefer + for zero encoded value. */
8364 if (!inst.operands[i].negative)
8365 inst.instruction |= INDEX_UP;
e2b0ab59 8366 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8367 }
09d92015 8368 }
09d92015
MM
8369}
8370
c19d1205
ZW
8371/* inst.operands[i] was set up by parse_address. Encode it into an
8372 ARM-format mode 3 load or store instruction. Reject forms that
8373 cannot be used with such instructions. If is_t is true, reject
8374 forms that cannot be used with a T instruction (i.e. not
8375 post-indexed). */
8376static void
8377encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8378{
c19d1205 8379 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8380 {
c19d1205
ZW
8381 inst.error = _("instruction does not accept scaled register index");
8382 return;
09d92015 8383 }
a737bd4d 8384
c19d1205 8385 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8386
c19d1205
ZW
8387 if (inst.operands[i].immisreg)
8388 {
5be8be5d 8389 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8390 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8391 BAD_PC_ADDRESSING);
eb9f3f00
JB
8392 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8393 BAD_PC_WRITEBACK);
c19d1205
ZW
8394 inst.instruction |= inst.operands[i].imm;
8395 if (!inst.operands[i].negative)
8396 inst.instruction |= INDEX_UP;
8397 }
e2b0ab59 8398 else /* immediate offset in inst.relocs[0] */
c19d1205 8399 {
e2b0ab59 8400 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8401 && inst.operands[i].writeback),
8402 BAD_PC_WRITEBACK);
c19d1205 8403 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8404 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8405 {
8406 /* Prefer + for zero encoded value. */
8407 if (!inst.operands[i].negative)
8408 inst.instruction |= INDEX_UP;
8409
e2b0ab59 8410 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8411 }
c19d1205 8412 }
a737bd4d
NC
8413}
8414
8335d6aa
JW
8415/* Write immediate bits [7:0] to the following locations:
8416
8417 |28/24|23 19|18 16|15 4|3 0|
8418 | 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|
8419
8420 This function is used by VMOV/VMVN/VORR/VBIC. */
8421
8422static void
8423neon_write_immbits (unsigned immbits)
8424{
8425 inst.instruction |= immbits & 0xf;
8426 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8427 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8428}
8429
8430/* Invert low-order SIZE bits of XHI:XLO. */
8431
8432static void
8433neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8434{
8435 unsigned immlo = xlo ? *xlo : 0;
8436 unsigned immhi = xhi ? *xhi : 0;
8437
8438 switch (size)
8439 {
8440 case 8:
8441 immlo = (~immlo) & 0xff;
8442 break;
8443
8444 case 16:
8445 immlo = (~immlo) & 0xffff;
8446 break;
8447
8448 case 64:
8449 immhi = (~immhi) & 0xffffffff;
8450 /* fall through. */
8451
8452 case 32:
8453 immlo = (~immlo) & 0xffffffff;
8454 break;
8455
8456 default:
8457 abort ();
8458 }
8459
8460 if (xlo)
8461 *xlo = immlo;
8462
8463 if (xhi)
8464 *xhi = immhi;
8465}
8466
8467/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8468 A, B, C, D. */
09d92015 8469
c19d1205 8470static int
8335d6aa 8471neon_bits_same_in_bytes (unsigned imm)
09d92015 8472{
8335d6aa
JW
8473 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8474 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8475 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8476 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8477}
a737bd4d 8478
8335d6aa 8479/* For immediate of above form, return 0bABCD. */
09d92015 8480
8335d6aa
JW
8481static unsigned
8482neon_squash_bits (unsigned imm)
8483{
8484 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8485 | ((imm & 0x01000000) >> 21);
8486}
8487
8488/* Compress quarter-float representation to 0b...000 abcdefgh. */
8489
8490static unsigned
8491neon_qfloat_bits (unsigned imm)
8492{
8493 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8494}
8495
8496/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8497 the instruction. *OP is passed as the initial value of the op field, and
8498 may be set to a different value depending on the constant (i.e.
8499 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8500 MVN). If the immediate looks like a repeated pattern then also
8501 try smaller element sizes. */
8502
8503static int
8504neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8505 unsigned *immbits, int *op, int size,
8506 enum neon_el_type type)
8507{
8508 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8509 float. */
8510 if (type == NT_float && !float_p)
8511 return FAIL;
8512
8513 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8514 {
8335d6aa
JW
8515 if (size != 32 || *op == 1)
8516 return FAIL;
8517 *immbits = neon_qfloat_bits (immlo);
8518 return 0xf;
8519 }
8520
8521 if (size == 64)
8522 {
8523 if (neon_bits_same_in_bytes (immhi)
8524 && neon_bits_same_in_bytes (immlo))
c19d1205 8525 {
8335d6aa
JW
8526 if (*op == 1)
8527 return FAIL;
8528 *immbits = (neon_squash_bits (immhi) << 4)
8529 | neon_squash_bits (immlo);
8530 *op = 1;
8531 return 0xe;
c19d1205 8532 }
a737bd4d 8533
8335d6aa
JW
8534 if (immhi != immlo)
8535 return FAIL;
8536 }
a737bd4d 8537
8335d6aa 8538 if (size >= 32)
09d92015 8539 {
8335d6aa 8540 if (immlo == (immlo & 0x000000ff))
c19d1205 8541 {
8335d6aa
JW
8542 *immbits = immlo;
8543 return 0x0;
c19d1205 8544 }
8335d6aa 8545 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8546 {
8335d6aa
JW
8547 *immbits = immlo >> 8;
8548 return 0x2;
c19d1205 8549 }
8335d6aa
JW
8550 else if (immlo == (immlo & 0x00ff0000))
8551 {
8552 *immbits = immlo >> 16;
8553 return 0x4;
8554 }
8555 else if (immlo == (immlo & 0xff000000))
8556 {
8557 *immbits = immlo >> 24;
8558 return 0x6;
8559 }
8560 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8561 {
8562 *immbits = (immlo >> 8) & 0xff;
8563 return 0xc;
8564 }
8565 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8566 {
8567 *immbits = (immlo >> 16) & 0xff;
8568 return 0xd;
8569 }
8570
8571 if ((immlo & 0xffff) != (immlo >> 16))
8572 return FAIL;
8573 immlo &= 0xffff;
09d92015 8574 }
a737bd4d 8575
8335d6aa 8576 if (size >= 16)
4962c51a 8577 {
8335d6aa
JW
8578 if (immlo == (immlo & 0x000000ff))
8579 {
8580 *immbits = immlo;
8581 return 0x8;
8582 }
8583 else if (immlo == (immlo & 0x0000ff00))
8584 {
8585 *immbits = immlo >> 8;
8586 return 0xa;
8587 }
8588
8589 if ((immlo & 0xff) != (immlo >> 8))
8590 return FAIL;
8591 immlo &= 0xff;
4962c51a
MS
8592 }
8593
8335d6aa
JW
8594 if (immlo == (immlo & 0x000000ff))
8595 {
8596 /* Don't allow MVN with 8-bit immediate. */
8597 if (*op == 1)
8598 return FAIL;
8599 *immbits = immlo;
8600 return 0xe;
8601 }
26d97720 8602
8335d6aa 8603 return FAIL;
c19d1205 8604}
a737bd4d 8605
5fc177c8 8606#if defined BFD_HOST_64_BIT
ba592044
AM
8607/* Returns TRUE if double precision value V may be cast
8608 to single precision without loss of accuracy. */
8609
8610static bfd_boolean
5fc177c8 8611is_double_a_single (bfd_int64_t v)
ba592044 8612{
5fc177c8 8613 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8614 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8615
8616 return (exp == 0 || exp == 0x7FF
8617 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8618 && (mantissa & 0x1FFFFFFFl) == 0;
8619}
8620
3739860c 8621/* Returns a double precision value casted to single precision
ba592044
AM
8622 (ignoring the least significant bits in exponent and mantissa). */
8623
8624static int
5fc177c8 8625double_to_single (bfd_int64_t v)
ba592044
AM
8626{
8627 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8628 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8629 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8630
8631 if (exp == 0x7FF)
8632 exp = 0xFF;
8633 else
8634 {
8635 exp = exp - 1023 + 127;
8636 if (exp >= 0xFF)
8637 {
8638 /* Infinity. */
8639 exp = 0x7F;
8640 mantissa = 0;
8641 }
8642 else if (exp < 0)
8643 {
8644 /* No denormalized numbers. */
8645 exp = 0;
8646 mantissa = 0;
8647 }
8648 }
8649 mantissa >>= 29;
8650 return (sign << 31) | (exp << 23) | mantissa;
8651}
5fc177c8 8652#endif /* BFD_HOST_64_BIT */
ba592044 8653
8335d6aa
JW
8654enum lit_type
8655{
8656 CONST_THUMB,
8657 CONST_ARM,
8658 CONST_VEC
8659};
8660
ba592044
AM
8661static void do_vfp_nsyn_opcode (const char *);
8662
e2b0ab59 8663/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8664 Determine whether it can be performed with a move instruction; if
8665 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8666 return TRUE; if it can't, convert inst.instruction to a literal-pool
8667 load and return FALSE. If this is not a valid thing to do in the
8668 current context, set inst.error and return TRUE.
a737bd4d 8669
c19d1205
ZW
8670 inst.operands[i] describes the destination register. */
8671
c921be7d 8672static bfd_boolean
8335d6aa 8673move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8674{
53365c0d 8675 unsigned long tbit;
8335d6aa
JW
8676 bfd_boolean thumb_p = (t == CONST_THUMB);
8677 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8678
8679 if (thumb_p)
8680 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8681 else
8682 tbit = LOAD_BIT;
8683
8684 if ((inst.instruction & tbit) == 0)
09d92015 8685 {
c19d1205 8686 inst.error = _("invalid pseudo operation");
c921be7d 8687 return TRUE;
09d92015 8688 }
ba592044 8689
e2b0ab59
AV
8690 if (inst.relocs[0].exp.X_op != O_constant
8691 && inst.relocs[0].exp.X_op != O_symbol
8692 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8693 {
8694 inst.error = _("constant expression expected");
c921be7d 8695 return TRUE;
09d92015 8696 }
ba592044 8697
e2b0ab59
AV
8698 if (inst.relocs[0].exp.X_op == O_constant
8699 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8700 {
5fc177c8
NC
8701#if defined BFD_HOST_64_BIT
8702 bfd_int64_t v;
8703#else
ba592044 8704 offsetT v;
5fc177c8 8705#endif
e2b0ab59 8706 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8707 {
ba592044
AM
8708 LITTLENUM_TYPE w[X_PRECISION];
8709 LITTLENUM_TYPE * l;
8710
e2b0ab59 8711 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8712 {
ba592044
AM
8713 gen_to_words (w, X_PRECISION, E_PRECISION);
8714 l = w;
8715 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8716 }
ba592044
AM
8717 else
8718 l = generic_bignum;
3739860c 8719
5fc177c8
NC
8720#if defined BFD_HOST_64_BIT
8721 v =
8722 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8723 << LITTLENUM_NUMBER_OF_BITS)
8724 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8725 << LITTLENUM_NUMBER_OF_BITS)
8726 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8727 << LITTLENUM_NUMBER_OF_BITS)
8728 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8729#else
ba592044
AM
8730 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8731 | (l[0] & LITTLENUM_MASK);
5fc177c8 8732#endif
8335d6aa 8733 }
ba592044 8734 else
e2b0ab59 8735 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8736
8737 if (!inst.operands[i].issingle)
8335d6aa 8738 {
12569877 8739 if (thumb_p)
8335d6aa 8740 {
53445554
TP
8741 /* LDR should not use lead in a flag-setting instruction being
8742 chosen so we do not check whether movs can be used. */
12569877 8743
53445554 8744 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8745 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8746 && inst.operands[i].reg != 13
8747 && inst.operands[i].reg != 15)
12569877 8748 {
fc289b0a
TP
8749 /* Check if on thumb2 it can be done with a mov.w, mvn or
8750 movw instruction. */
12569877
AM
8751 unsigned int newimm;
8752 bfd_boolean isNegated;
8753
8754 newimm = encode_thumb32_immediate (v);
8755 if (newimm != (unsigned int) FAIL)
8756 isNegated = FALSE;
8757 else
8758 {
582cfe03 8759 newimm = encode_thumb32_immediate (~v);
12569877
AM
8760 if (newimm != (unsigned int) FAIL)
8761 isNegated = TRUE;
8762 }
8763
fc289b0a
TP
8764 /* The number can be loaded with a mov.w or mvn
8765 instruction. */
ff8646ee
TP
8766 if (newimm != (unsigned int) FAIL
8767 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8768 {
fc289b0a 8769 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8770 | (inst.operands[i].reg << 8));
fc289b0a 8771 /* Change to MOVN. */
582cfe03 8772 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8773 inst.instruction |= (newimm & 0x800) << 15;
8774 inst.instruction |= (newimm & 0x700) << 4;
8775 inst.instruction |= (newimm & 0x0ff);
8776 return TRUE;
8777 }
fc289b0a 8778 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8779 else if ((v & ~0xFFFF) == 0
8780 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8781 {
582cfe03 8782 int imm = v & 0xFFFF;
12569877 8783
582cfe03 8784 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8785 inst.instruction |= (inst.operands[i].reg << 8);
8786 inst.instruction |= (imm & 0xf000) << 4;
8787 inst.instruction |= (imm & 0x0800) << 15;
8788 inst.instruction |= (imm & 0x0700) << 4;
8789 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8790 /* In case this replacement is being done on Armv8-M
8791 Baseline we need to make sure to disable the
8792 instruction size check, as otherwise GAS will reject
8793 the use of this T32 instruction. */
8794 inst.size_req = 0;
12569877
AM
8795 return TRUE;
8796 }
8797 }
8335d6aa 8798 }
12569877 8799 else if (arm_p)
ba592044
AM
8800 {
8801 int value = encode_arm_immediate (v);
12569877 8802
ba592044
AM
8803 if (value != FAIL)
8804 {
8805 /* This can be done with a mov instruction. */
8806 inst.instruction &= LITERAL_MASK;
8807 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8808 inst.instruction |= value & 0xfff;
8809 return TRUE;
8810 }
8335d6aa 8811
ba592044
AM
8812 value = encode_arm_immediate (~ v);
8813 if (value != FAIL)
8814 {
8815 /* This can be done with a mvn instruction. */
8816 inst.instruction &= LITERAL_MASK;
8817 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8818 inst.instruction |= value & 0xfff;
8819 return TRUE;
8820 }
8821 }
934c2632 8822 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8823 {
ba592044
AM
8824 int op = 0;
8825 unsigned immbits = 0;
8826 unsigned immlo = inst.operands[1].imm;
8827 unsigned immhi = inst.operands[1].regisimm
8828 ? inst.operands[1].reg
e2b0ab59 8829 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8830 ? 0
8831 : ((bfd_int64_t)((int) immlo)) >> 32;
8832 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8833 &op, 64, NT_invtype);
8834
8835 if (cmode == FAIL)
8836 {
8837 neon_invert_size (&immlo, &immhi, 64);
8838 op = !op;
8839 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8840 &op, 64, NT_invtype);
8841 }
8842
8843 if (cmode != FAIL)
8844 {
8845 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8846 | (1 << 23)
8847 | (cmode << 8)
8848 | (op << 5)
8849 | (1 << 4);
8850
8851 /* Fill other bits in vmov encoding for both thumb and arm. */
8852 if (thumb_mode)
eff0bc54 8853 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8854 else
eff0bc54 8855 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8856 neon_write_immbits (immbits);
8857 return TRUE;
8858 }
8335d6aa
JW
8859 }
8860 }
8335d6aa 8861
ba592044
AM
8862 if (t == CONST_VEC)
8863 {
8864 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8865 if (inst.operands[i].issingle
8866 && is_quarter_float (inst.operands[1].imm)
8867 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8868 {
ba592044
AM
8869 inst.operands[1].imm =
8870 neon_qfloat_bits (v);
8871 do_vfp_nsyn_opcode ("fconsts");
8872 return TRUE;
8335d6aa 8873 }
5fc177c8
NC
8874
8875 /* If our host does not support a 64-bit type then we cannot perform
8876 the following optimization. This mean that there will be a
8877 discrepancy between the output produced by an assembler built for
8878 a 32-bit-only host and the output produced from a 64-bit host, but
8879 this cannot be helped. */
8880#if defined BFD_HOST_64_BIT
ba592044
AM
8881 else if (!inst.operands[1].issingle
8882 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8883 {
ba592044
AM
8884 if (is_double_a_single (v)
8885 && is_quarter_float (double_to_single (v)))
8886 {
8887 inst.operands[1].imm =
8888 neon_qfloat_bits (double_to_single (v));
8889 do_vfp_nsyn_opcode ("fconstd");
8890 return TRUE;
8891 }
8335d6aa 8892 }
5fc177c8 8893#endif
8335d6aa
JW
8894 }
8895 }
8896
8897 if (add_to_lit_pool ((!inst.operands[i].isvec
8898 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8899 return TRUE;
8900
8901 inst.operands[1].reg = REG_PC;
8902 inst.operands[1].isreg = 1;
8903 inst.operands[1].preind = 1;
e2b0ab59
AV
8904 inst.relocs[0].pc_rel = 1;
8905 inst.relocs[0].type = (thumb_p
8335d6aa
JW
8906 ? BFD_RELOC_ARM_THUMB_OFFSET
8907 : (mode_3
8908 ? BFD_RELOC_ARM_HWLITERAL
8909 : BFD_RELOC_ARM_LITERAL));
8910 return FALSE;
8911}
8912
8913/* inst.operands[i] was set up by parse_address. Encode it into an
8914 ARM-format instruction. Reject all forms which cannot be encoded
8915 into a coprocessor load/store instruction. If wb_ok is false,
8916 reject use of writeback; if unind_ok is false, reject use of
8917 unindexed addressing. If reloc_override is not 0, use it instead
8918 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8919 (in which case it is preserved). */
8920
8921static int
8922encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8923{
8924 if (!inst.operands[i].isreg)
8925 {
99b2a2dd
NC
8926 /* PR 18256 */
8927 if (! inst.operands[0].isvec)
8928 {
8929 inst.error = _("invalid co-processor operand");
8930 return FAIL;
8931 }
8335d6aa
JW
8932 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8933 return SUCCESS;
8934 }
8935
8936 inst.instruction |= inst.operands[i].reg << 16;
8937
8938 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8939
8940 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8941 {
8942 gas_assert (!inst.operands[i].writeback);
8943 if (!unind_ok)
8944 {
8945 inst.error = _("instruction does not support unindexed addressing");
8946 return FAIL;
8947 }
8948 inst.instruction |= inst.operands[i].imm;
8949 inst.instruction |= INDEX_UP;
8950 return SUCCESS;
8951 }
8952
8953 if (inst.operands[i].preind)
8954 inst.instruction |= PRE_INDEX;
8955
8956 if (inst.operands[i].writeback)
09d92015 8957 {
8335d6aa 8958 if (inst.operands[i].reg == REG_PC)
c19d1205 8959 {
8335d6aa
JW
8960 inst.error = _("pc may not be used with write-back");
8961 return FAIL;
c19d1205 8962 }
8335d6aa 8963 if (!wb_ok)
c19d1205 8964 {
8335d6aa
JW
8965 inst.error = _("instruction does not support writeback");
8966 return FAIL;
c19d1205 8967 }
8335d6aa 8968 inst.instruction |= WRITE_BACK;
09d92015
MM
8969 }
8970
8335d6aa 8971 if (reloc_override)
e2b0ab59
AV
8972 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8973 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8974 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8975 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8976 {
8335d6aa 8977 if (thumb_mode)
e2b0ab59 8978 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 8979 else
e2b0ab59 8980 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8981 }
8335d6aa
JW
8982
8983 /* Prefer + for zero encoded value. */
8984 if (!inst.operands[i].negative)
8985 inst.instruction |= INDEX_UP;
8986
8987 return SUCCESS;
09d92015
MM
8988}
8989
5f4273c7 8990/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8991 First some generics; their names are taken from the conventional
8992 bit positions for register arguments in ARM format instructions. */
09d92015 8993
a737bd4d 8994static void
c19d1205 8995do_noargs (void)
09d92015 8996{
c19d1205 8997}
a737bd4d 8998
c19d1205
ZW
8999static void
9000do_rd (void)
9001{
9002 inst.instruction |= inst.operands[0].reg << 12;
9003}
a737bd4d 9004
16a1fa25
TP
9005static void
9006do_rn (void)
9007{
9008 inst.instruction |= inst.operands[0].reg << 16;
9009}
9010
c19d1205
ZW
9011static void
9012do_rd_rm (void)
9013{
9014 inst.instruction |= inst.operands[0].reg << 12;
9015 inst.instruction |= inst.operands[1].reg;
9016}
09d92015 9017
9eb6c0f1
MGD
9018static void
9019do_rm_rn (void)
9020{
9021 inst.instruction |= inst.operands[0].reg;
9022 inst.instruction |= inst.operands[1].reg << 16;
9023}
9024
c19d1205
ZW
9025static void
9026do_rd_rn (void)
9027{
9028 inst.instruction |= inst.operands[0].reg << 12;
9029 inst.instruction |= inst.operands[1].reg << 16;
9030}
a737bd4d 9031
c19d1205
ZW
9032static void
9033do_rn_rd (void)
9034{
9035 inst.instruction |= inst.operands[0].reg << 16;
9036 inst.instruction |= inst.operands[1].reg << 12;
9037}
09d92015 9038
4ed7ed8d
TP
9039static void
9040do_tt (void)
9041{
9042 inst.instruction |= inst.operands[0].reg << 8;
9043 inst.instruction |= inst.operands[1].reg << 16;
9044}
9045
59d09be6
MGD
9046static bfd_boolean
9047check_obsolete (const arm_feature_set *feature, const char *msg)
9048{
9049 if (ARM_CPU_IS_ANY (cpu_variant))
9050 {
5c3696f8 9051 as_tsktsk ("%s", msg);
59d09be6
MGD
9052 return TRUE;
9053 }
9054 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9055 {
9056 as_bad ("%s", msg);
9057 return TRUE;
9058 }
9059
9060 return FALSE;
9061}
9062
c19d1205
ZW
9063static void
9064do_rd_rm_rn (void)
9065{
9a64e435 9066 unsigned Rn = inst.operands[2].reg;
708587a4 9067 /* Enforce restrictions on SWP instruction. */
9a64e435 9068 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9069 {
9070 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9071 _("Rn must not overlap other operands"));
9072
59d09be6
MGD
9073 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9074 */
9075 if (!check_obsolete (&arm_ext_v8,
9076 _("swp{b} use is obsoleted for ARMv8 and later"))
9077 && warn_on_deprecated
9078 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9079 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9080 }
59d09be6 9081
c19d1205
ZW
9082 inst.instruction |= inst.operands[0].reg << 12;
9083 inst.instruction |= inst.operands[1].reg;
9a64e435 9084 inst.instruction |= Rn << 16;
c19d1205 9085}
09d92015 9086
c19d1205
ZW
9087static void
9088do_rd_rn_rm (void)
9089{
9090 inst.instruction |= inst.operands[0].reg << 12;
9091 inst.instruction |= inst.operands[1].reg << 16;
9092 inst.instruction |= inst.operands[2].reg;
9093}
a737bd4d 9094
c19d1205
ZW
9095static void
9096do_rm_rd_rn (void)
9097{
5be8be5d 9098 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9099 constraint (((inst.relocs[0].exp.X_op != O_constant
9100 && inst.relocs[0].exp.X_op != O_illegal)
9101 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9102 BAD_ADDR_MODE);
c19d1205
ZW
9103 inst.instruction |= inst.operands[0].reg;
9104 inst.instruction |= inst.operands[1].reg << 12;
9105 inst.instruction |= inst.operands[2].reg << 16;
9106}
09d92015 9107
c19d1205
ZW
9108static void
9109do_imm0 (void)
9110{
9111 inst.instruction |= inst.operands[0].imm;
9112}
09d92015 9113
c19d1205
ZW
9114static void
9115do_rd_cpaddr (void)
9116{
9117 inst.instruction |= inst.operands[0].reg << 12;
9118 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9119}
a737bd4d 9120
c19d1205
ZW
9121/* ARM instructions, in alphabetical order by function name (except
9122 that wrapper functions appear immediately after the function they
9123 wrap). */
09d92015 9124
c19d1205
ZW
9125/* This is a pseudo-op of the form "adr rd, label" to be converted
9126 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9127
9128static void
c19d1205 9129do_adr (void)
09d92015 9130{
c19d1205 9131 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9132
c19d1205
ZW
9133 /* Frag hacking will turn this into a sub instruction if the offset turns
9134 out to be negative. */
e2b0ab59
AV
9135 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9136 inst.relocs[0].pc_rel = 1;
9137 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9138
fc6141f0 9139 if (support_interwork
e2b0ab59
AV
9140 && inst.relocs[0].exp.X_op == O_symbol
9141 && inst.relocs[0].exp.X_add_symbol != NULL
9142 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9143 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9144 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9145}
b99bd4ef 9146
c19d1205
ZW
9147/* This is a pseudo-op of the form "adrl rd, label" to be converted
9148 into a relative address of the form:
9149 add rd, pc, #low(label-.-8)"
9150 add rd, rd, #high(label-.-8)" */
b99bd4ef 9151
c19d1205
ZW
9152static void
9153do_adrl (void)
9154{
9155 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9156
c19d1205
ZW
9157 /* Frag hacking will turn this into a sub instruction if the offset turns
9158 out to be negative. */
e2b0ab59
AV
9159 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9160 inst.relocs[0].pc_rel = 1;
c19d1205 9161 inst.size = INSN_SIZE * 2;
e2b0ab59 9162 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9163
fc6141f0 9164 if (support_interwork
e2b0ab59
AV
9165 && inst.relocs[0].exp.X_op == O_symbol
9166 && inst.relocs[0].exp.X_add_symbol != NULL
9167 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9168 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9169 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9170}
9171
b99bd4ef 9172static void
c19d1205 9173do_arit (void)
b99bd4ef 9174{
e2b0ab59
AV
9175 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9176 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9177 THUMB1_RELOC_ONLY);
c19d1205
ZW
9178 if (!inst.operands[1].present)
9179 inst.operands[1].reg = inst.operands[0].reg;
9180 inst.instruction |= inst.operands[0].reg << 12;
9181 inst.instruction |= inst.operands[1].reg << 16;
9182 encode_arm_shifter_operand (2);
9183}
b99bd4ef 9184
62b3e311
PB
9185static void
9186do_barrier (void)
9187{
9188 if (inst.operands[0].present)
ccb84d65 9189 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9190 else
9191 inst.instruction |= 0xf;
9192}
9193
c19d1205
ZW
9194static void
9195do_bfc (void)
9196{
9197 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9198 constraint (msb > 32, _("bit-field extends past end of register"));
9199 /* The instruction encoding stores the LSB and MSB,
9200 not the LSB and width. */
9201 inst.instruction |= inst.operands[0].reg << 12;
9202 inst.instruction |= inst.operands[1].imm << 7;
9203 inst.instruction |= (msb - 1) << 16;
9204}
b99bd4ef 9205
c19d1205
ZW
9206static void
9207do_bfi (void)
9208{
9209 unsigned int msb;
b99bd4ef 9210
c19d1205
ZW
9211 /* #0 in second position is alternative syntax for bfc, which is
9212 the same instruction but with REG_PC in the Rm field. */
9213 if (!inst.operands[1].isreg)
9214 inst.operands[1].reg = REG_PC;
b99bd4ef 9215
c19d1205
ZW
9216 msb = inst.operands[2].imm + inst.operands[3].imm;
9217 constraint (msb > 32, _("bit-field extends past end of register"));
9218 /* The instruction encoding stores the LSB and MSB,
9219 not the LSB and width. */
9220 inst.instruction |= inst.operands[0].reg << 12;
9221 inst.instruction |= inst.operands[1].reg;
9222 inst.instruction |= inst.operands[2].imm << 7;
9223 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9224}
9225
b99bd4ef 9226static void
c19d1205 9227do_bfx (void)
b99bd4ef 9228{
c19d1205
ZW
9229 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9230 _("bit-field extends past end of register"));
9231 inst.instruction |= inst.operands[0].reg << 12;
9232 inst.instruction |= inst.operands[1].reg;
9233 inst.instruction |= inst.operands[2].imm << 7;
9234 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9235}
09d92015 9236
c19d1205
ZW
9237/* ARM V5 breakpoint instruction (argument parse)
9238 BKPT <16 bit unsigned immediate>
9239 Instruction is not conditional.
9240 The bit pattern given in insns[] has the COND_ALWAYS condition,
9241 and it is an error if the caller tried to override that. */
b99bd4ef 9242
c19d1205
ZW
9243static void
9244do_bkpt (void)
9245{
9246 /* Top 12 of 16 bits to bits 19:8. */
9247 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9248
c19d1205
ZW
9249 /* Bottom 4 of 16 bits to bits 3:0. */
9250 inst.instruction |= inst.operands[0].imm & 0xf;
9251}
09d92015 9252
c19d1205
ZW
9253static void
9254encode_branch (int default_reloc)
9255{
9256 if (inst.operands[0].hasreloc)
9257 {
0855e32b
NS
9258 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9259 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9260 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9261 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9262 ? BFD_RELOC_ARM_PLT32
9263 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9264 }
b99bd4ef 9265 else
e2b0ab59
AV
9266 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9267 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9268}
9269
b99bd4ef 9270static void
c19d1205 9271do_branch (void)
b99bd4ef 9272{
39b41c9c
PB
9273#ifdef OBJ_ELF
9274 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9275 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9276 else
9277#endif
9278 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9279}
9280
9281static void
9282do_bl (void)
9283{
9284#ifdef OBJ_ELF
9285 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9286 {
9287 if (inst.cond == COND_ALWAYS)
9288 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9289 else
9290 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9291 }
9292 else
9293#endif
9294 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9295}
b99bd4ef 9296
c19d1205
ZW
9297/* ARM V5 branch-link-exchange instruction (argument parse)
9298 BLX <target_addr> ie BLX(1)
9299 BLX{<condition>} <Rm> ie BLX(2)
9300 Unfortunately, there are two different opcodes for this mnemonic.
9301 So, the insns[].value is not used, and the code here zaps values
9302 into inst.instruction.
9303 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9304
c19d1205
ZW
9305static void
9306do_blx (void)
9307{
9308 if (inst.operands[0].isreg)
b99bd4ef 9309 {
c19d1205
ZW
9310 /* Arg is a register; the opcode provided by insns[] is correct.
9311 It is not illegal to do "blx pc", just useless. */
9312 if (inst.operands[0].reg == REG_PC)
9313 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9314
c19d1205
ZW
9315 inst.instruction |= inst.operands[0].reg;
9316 }
9317 else
b99bd4ef 9318 {
c19d1205 9319 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9320 conditionally, and the opcode must be adjusted.
9321 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9322 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9323 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9324 inst.instruction = 0xfa000000;
267bf995 9325 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9326 }
c19d1205
ZW
9327}
9328
9329static void
9330do_bx (void)
9331{
845b51d6
PB
9332 bfd_boolean want_reloc;
9333
c19d1205
ZW
9334 if (inst.operands[0].reg == REG_PC)
9335 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9336
c19d1205 9337 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9338 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9339 it is for ARMv4t or earlier. */
9340 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9341 if (!ARM_FEATURE_ZERO (selected_object_arch)
9342 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9343 want_reloc = TRUE;
9344
5ad34203 9345#ifdef OBJ_ELF
845b51d6 9346 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9347#endif
584206db 9348 want_reloc = FALSE;
845b51d6
PB
9349
9350 if (want_reloc)
e2b0ab59 9351 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9352}
9353
c19d1205
ZW
9354
9355/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9356
9357static void
c19d1205 9358do_bxj (void)
a737bd4d 9359{
c19d1205
ZW
9360 if (inst.operands[0].reg == REG_PC)
9361 as_tsktsk (_("use of r15 in bxj is not really useful"));
9362
9363 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9364}
9365
c19d1205
ZW
9366/* Co-processor data operation:
9367 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9368 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9369static void
9370do_cdp (void)
9371{
9372 inst.instruction |= inst.operands[0].reg << 8;
9373 inst.instruction |= inst.operands[1].imm << 20;
9374 inst.instruction |= inst.operands[2].reg << 12;
9375 inst.instruction |= inst.operands[3].reg << 16;
9376 inst.instruction |= inst.operands[4].reg;
9377 inst.instruction |= inst.operands[5].imm << 5;
9378}
a737bd4d
NC
9379
9380static void
c19d1205 9381do_cmp (void)
a737bd4d 9382{
c19d1205
ZW
9383 inst.instruction |= inst.operands[0].reg << 16;
9384 encode_arm_shifter_operand (1);
a737bd4d
NC
9385}
9386
c19d1205
ZW
9387/* Transfer between coprocessor and ARM registers.
9388 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9389 MRC2
9390 MCR{cond}
9391 MCR2
9392
9393 No special properties. */
09d92015 9394
dcbd0d71
MGD
9395struct deprecated_coproc_regs_s
9396{
9397 unsigned cp;
9398 int opc1;
9399 unsigned crn;
9400 unsigned crm;
9401 int opc2;
9402 arm_feature_set deprecated;
9403 arm_feature_set obsoleted;
9404 const char *dep_msg;
9405 const char *obs_msg;
9406};
9407
9408#define DEPR_ACCESS_V8 \
9409 N_("This coprocessor register access is deprecated in ARMv8")
9410
9411/* Table of all deprecated coprocessor registers. */
9412static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9413{
9414 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9415 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9416 DEPR_ACCESS_V8, NULL},
9417 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9418 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9419 DEPR_ACCESS_V8, NULL},
9420 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9421 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9422 DEPR_ACCESS_V8, NULL},
9423 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9424 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9425 DEPR_ACCESS_V8, NULL},
9426 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9427 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9428 DEPR_ACCESS_V8, NULL},
9429};
9430
9431#undef DEPR_ACCESS_V8
9432
9433static const size_t deprecated_coproc_reg_count =
9434 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9435
09d92015 9436static void
c19d1205 9437do_co_reg (void)
09d92015 9438{
fdfde340 9439 unsigned Rd;
dcbd0d71 9440 size_t i;
fdfde340
JM
9441
9442 Rd = inst.operands[2].reg;
9443 if (thumb_mode)
9444 {
9445 if (inst.instruction == 0xee000010
9446 || inst.instruction == 0xfe000010)
9447 /* MCR, MCR2 */
9448 reject_bad_reg (Rd);
5c8ed6a4 9449 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9450 /* MRC, MRC2 */
9451 constraint (Rd == REG_SP, BAD_SP);
9452 }
9453 else
9454 {
9455 /* MCR */
9456 if (inst.instruction == 0xe000010)
9457 constraint (Rd == REG_PC, BAD_PC);
9458 }
9459
dcbd0d71
MGD
9460 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9461 {
9462 const struct deprecated_coproc_regs_s *r =
9463 deprecated_coproc_regs + i;
9464
9465 if (inst.operands[0].reg == r->cp
9466 && inst.operands[1].imm == r->opc1
9467 && inst.operands[3].reg == r->crn
9468 && inst.operands[4].reg == r->crm
9469 && inst.operands[5].imm == r->opc2)
9470 {
b10bf8c5 9471 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9472 && warn_on_deprecated
dcbd0d71 9473 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9474 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9475 }
9476 }
fdfde340 9477
c19d1205
ZW
9478 inst.instruction |= inst.operands[0].reg << 8;
9479 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9480 inst.instruction |= Rd << 12;
c19d1205
ZW
9481 inst.instruction |= inst.operands[3].reg << 16;
9482 inst.instruction |= inst.operands[4].reg;
9483 inst.instruction |= inst.operands[5].imm << 5;
9484}
09d92015 9485
c19d1205
ZW
9486/* Transfer between coprocessor register and pair of ARM registers.
9487 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9488 MCRR2
9489 MRRC{cond}
9490 MRRC2
b99bd4ef 9491
c19d1205 9492 Two XScale instructions are special cases of these:
09d92015 9493
c19d1205
ZW
9494 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9495 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9496
5f4273c7 9497 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9498
c19d1205
ZW
9499static void
9500do_co_reg2c (void)
9501{
fdfde340
JM
9502 unsigned Rd, Rn;
9503
9504 Rd = inst.operands[2].reg;
9505 Rn = inst.operands[3].reg;
9506
9507 if (thumb_mode)
9508 {
9509 reject_bad_reg (Rd);
9510 reject_bad_reg (Rn);
9511 }
9512 else
9513 {
9514 constraint (Rd == REG_PC, BAD_PC);
9515 constraint (Rn == REG_PC, BAD_PC);
9516 }
9517
873f10f0
TC
9518 /* Only check the MRRC{2} variants. */
9519 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9520 {
9521 /* If Rd == Rn, error that the operation is
9522 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9523 constraint (Rd == Rn, BAD_OVERLAP);
9524 }
9525
c19d1205
ZW
9526 inst.instruction |= inst.operands[0].reg << 8;
9527 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9528 inst.instruction |= Rd << 12;
9529 inst.instruction |= Rn << 16;
c19d1205 9530 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9531}
9532
c19d1205
ZW
9533static void
9534do_cpsi (void)
9535{
9536 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9537 if (inst.operands[1].present)
9538 {
9539 inst.instruction |= CPSI_MMOD;
9540 inst.instruction |= inst.operands[1].imm;
9541 }
c19d1205 9542}
b99bd4ef 9543
62b3e311
PB
9544static void
9545do_dbg (void)
9546{
9547 inst.instruction |= inst.operands[0].imm;
9548}
9549
eea54501
MGD
9550static void
9551do_div (void)
9552{
9553 unsigned Rd, Rn, Rm;
9554
9555 Rd = inst.operands[0].reg;
9556 Rn = (inst.operands[1].present
9557 ? inst.operands[1].reg : Rd);
9558 Rm = inst.operands[2].reg;
9559
9560 constraint ((Rd == REG_PC), BAD_PC);
9561 constraint ((Rn == REG_PC), BAD_PC);
9562 constraint ((Rm == REG_PC), BAD_PC);
9563
9564 inst.instruction |= Rd << 16;
9565 inst.instruction |= Rn << 0;
9566 inst.instruction |= Rm << 8;
9567}
9568
b99bd4ef 9569static void
c19d1205 9570do_it (void)
b99bd4ef 9571{
c19d1205 9572 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9573 process it to do the validation as if in
9574 thumb mode, just in case the code gets
9575 assembled for thumb using the unified syntax. */
9576
c19d1205 9577 inst.size = 0;
e07e6e58
NC
9578 if (unified_syntax)
9579 {
5ee91343
AV
9580 set_pred_insn_type (IT_INSN);
9581 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9582 now_pred.cc = inst.operands[0].imm;
e07e6e58 9583 }
09d92015 9584}
b99bd4ef 9585
6530b175
NC
9586/* If there is only one register in the register list,
9587 then return its register number. Otherwise return -1. */
9588static int
9589only_one_reg_in_list (int range)
9590{
9591 int i = ffs (range) - 1;
9592 return (i > 15 || range != (1 << i)) ? -1 : i;
9593}
9594
09d92015 9595static void
6530b175 9596encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9597{
c19d1205
ZW
9598 int base_reg = inst.operands[0].reg;
9599 int range = inst.operands[1].imm;
6530b175 9600 int one_reg;
ea6ef066 9601
c19d1205
ZW
9602 inst.instruction |= base_reg << 16;
9603 inst.instruction |= range;
ea6ef066 9604
c19d1205
ZW
9605 if (inst.operands[1].writeback)
9606 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9607
c19d1205 9608 if (inst.operands[0].writeback)
ea6ef066 9609 {
c19d1205
ZW
9610 inst.instruction |= WRITE_BACK;
9611 /* Check for unpredictable uses of writeback. */
9612 if (inst.instruction & LOAD_BIT)
09d92015 9613 {
c19d1205
ZW
9614 /* Not allowed in LDM type 2. */
9615 if ((inst.instruction & LDM_TYPE_2_OR_3)
9616 && ((range & (1 << REG_PC)) == 0))
9617 as_warn (_("writeback of base register is UNPREDICTABLE"));
9618 /* Only allowed if base reg not in list for other types. */
9619 else if (range & (1 << base_reg))
9620 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9621 }
9622 else /* STM. */
9623 {
9624 /* Not allowed for type 2. */
9625 if (inst.instruction & LDM_TYPE_2_OR_3)
9626 as_warn (_("writeback of base register is UNPREDICTABLE"));
9627 /* Only allowed if base reg not in list, or first in list. */
9628 else if ((range & (1 << base_reg))
9629 && (range & ((1 << base_reg) - 1)))
9630 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9631 }
ea6ef066 9632 }
6530b175
NC
9633
9634 /* If PUSH/POP has only one register, then use the A2 encoding. */
9635 one_reg = only_one_reg_in_list (range);
9636 if (from_push_pop_mnem && one_reg >= 0)
9637 {
9638 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9639
4f588891
NC
9640 if (is_push && one_reg == 13 /* SP */)
9641 /* PR 22483: The A2 encoding cannot be used when
9642 pushing the stack pointer as this is UNPREDICTABLE. */
9643 return;
9644
6530b175
NC
9645 inst.instruction &= A_COND_MASK;
9646 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9647 inst.instruction |= one_reg << 12;
9648 }
9649}
9650
9651static void
9652do_ldmstm (void)
9653{
9654 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9655}
9656
c19d1205
ZW
9657/* ARMv5TE load-consecutive (argument parse)
9658 Mode is like LDRH.
9659
9660 LDRccD R, mode
9661 STRccD R, mode. */
9662
a737bd4d 9663static void
c19d1205 9664do_ldrd (void)
a737bd4d 9665{
c19d1205 9666 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9667 _("first transfer register must be even"));
c19d1205
ZW
9668 constraint (inst.operands[1].present
9669 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9670 _("can only transfer two consecutive registers"));
c19d1205
ZW
9671 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9672 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9673
c19d1205
ZW
9674 if (!inst.operands[1].present)
9675 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9676
c56791bb
RE
9677 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9678 register and the first register written; we have to diagnose
9679 overlap between the base and the second register written here. */
ea6ef066 9680
c56791bb
RE
9681 if (inst.operands[2].reg == inst.operands[1].reg
9682 && (inst.operands[2].writeback || inst.operands[2].postind))
9683 as_warn (_("base register written back, and overlaps "
9684 "second transfer register"));
b05fe5cf 9685
c56791bb
RE
9686 if (!(inst.instruction & V4_STR_BIT))
9687 {
c19d1205 9688 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9689 destination (even if not write-back). */
9690 if (inst.operands[2].immisreg
9691 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9692 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9693 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9694 }
c19d1205
ZW
9695 inst.instruction |= inst.operands[0].reg << 12;
9696 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9697}
9698
9699static void
c19d1205 9700do_ldrex (void)
b05fe5cf 9701{
c19d1205
ZW
9702 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9703 || inst.operands[1].postind || inst.operands[1].writeback
9704 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9705 || inst.operands[1].negative
9706 /* This can arise if the programmer has written
9707 strex rN, rM, foo
9708 or if they have mistakenly used a register name as the last
9709 operand, eg:
9710 strex rN, rM, rX
9711 It is very difficult to distinguish between these two cases
9712 because "rX" might actually be a label. ie the register
9713 name has been occluded by a symbol of the same name. So we
9714 just generate a general 'bad addressing mode' type error
9715 message and leave it up to the programmer to discover the
9716 true cause and fix their mistake. */
9717 || (inst.operands[1].reg == REG_PC),
9718 BAD_ADDR_MODE);
b05fe5cf 9719
e2b0ab59
AV
9720 constraint (inst.relocs[0].exp.X_op != O_constant
9721 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9722 _("offset must be zero in ARM encoding"));
b05fe5cf 9723
5be8be5d
DG
9724 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9725
c19d1205
ZW
9726 inst.instruction |= inst.operands[0].reg << 12;
9727 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9728 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9729}
9730
9731static void
c19d1205 9732do_ldrexd (void)
b05fe5cf 9733{
c19d1205
ZW
9734 constraint (inst.operands[0].reg % 2 != 0,
9735 _("even register required"));
9736 constraint (inst.operands[1].present
9737 && inst.operands[1].reg != inst.operands[0].reg + 1,
9738 _("can only load two consecutive registers"));
9739 /* If op 1 were present and equal to PC, this function wouldn't
9740 have been called in the first place. */
9741 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9742
c19d1205
ZW
9743 inst.instruction |= inst.operands[0].reg << 12;
9744 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9745}
9746
1be5fd2e
NC
9747/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9748 which is not a multiple of four is UNPREDICTABLE. */
9749static void
9750check_ldr_r15_aligned (void)
9751{
9752 constraint (!(inst.operands[1].immisreg)
9753 && (inst.operands[0].reg == REG_PC
9754 && inst.operands[1].reg == REG_PC
e2b0ab59 9755 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9756 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9757}
9758
b05fe5cf 9759static void
c19d1205 9760do_ldst (void)
b05fe5cf 9761{
c19d1205
ZW
9762 inst.instruction |= inst.operands[0].reg << 12;
9763 if (!inst.operands[1].isreg)
8335d6aa 9764 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9765 return;
c19d1205 9766 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9767 check_ldr_r15_aligned ();
b05fe5cf
ZW
9768}
9769
9770static void
c19d1205 9771do_ldstt (void)
b05fe5cf 9772{
c19d1205
ZW
9773 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9774 reject [Rn,...]. */
9775 if (inst.operands[1].preind)
b05fe5cf 9776 {
e2b0ab59
AV
9777 constraint (inst.relocs[0].exp.X_op != O_constant
9778 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9779 _("this instruction requires a post-indexed address"));
b05fe5cf 9780
c19d1205
ZW
9781 inst.operands[1].preind = 0;
9782 inst.operands[1].postind = 1;
9783 inst.operands[1].writeback = 1;
b05fe5cf 9784 }
c19d1205
ZW
9785 inst.instruction |= inst.operands[0].reg << 12;
9786 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9787}
b05fe5cf 9788
c19d1205 9789/* Halfword and signed-byte load/store operations. */
b05fe5cf 9790
c19d1205
ZW
9791static void
9792do_ldstv4 (void)
9793{
ff4a8d2b 9794 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9795 inst.instruction |= inst.operands[0].reg << 12;
9796 if (!inst.operands[1].isreg)
8335d6aa 9797 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9798 return;
c19d1205 9799 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9800}
9801
9802static void
c19d1205 9803do_ldsttv4 (void)
b05fe5cf 9804{
c19d1205
ZW
9805 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9806 reject [Rn,...]. */
9807 if (inst.operands[1].preind)
b05fe5cf 9808 {
e2b0ab59
AV
9809 constraint (inst.relocs[0].exp.X_op != O_constant
9810 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9811 _("this instruction requires a post-indexed address"));
b05fe5cf 9812
c19d1205
ZW
9813 inst.operands[1].preind = 0;
9814 inst.operands[1].postind = 1;
9815 inst.operands[1].writeback = 1;
b05fe5cf 9816 }
c19d1205
ZW
9817 inst.instruction |= inst.operands[0].reg << 12;
9818 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9819}
b05fe5cf 9820
c19d1205
ZW
9821/* Co-processor register load/store.
9822 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9823static void
9824do_lstc (void)
9825{
9826 inst.instruction |= inst.operands[0].reg << 8;
9827 inst.instruction |= inst.operands[1].reg << 12;
9828 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9829}
9830
b05fe5cf 9831static void
c19d1205 9832do_mlas (void)
b05fe5cf 9833{
8fb9d7b9 9834 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9835 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9836 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9837 && !(inst.instruction & 0x00400000))
8fb9d7b9 9838 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9839
c19d1205
ZW
9840 inst.instruction |= inst.operands[0].reg << 16;
9841 inst.instruction |= inst.operands[1].reg;
9842 inst.instruction |= inst.operands[2].reg << 8;
9843 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9844}
b05fe5cf 9845
c19d1205
ZW
9846static void
9847do_mov (void)
9848{
e2b0ab59
AV
9849 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9850 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9851 THUMB1_RELOC_ONLY);
c19d1205
ZW
9852 inst.instruction |= inst.operands[0].reg << 12;
9853 encode_arm_shifter_operand (1);
9854}
b05fe5cf 9855
c19d1205
ZW
9856/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9857static void
9858do_mov16 (void)
9859{
b6895b4f
PB
9860 bfd_vma imm;
9861 bfd_boolean top;
9862
9863 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9864 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9865 _(":lower16: not allowed in this instruction"));
e2b0ab59 9866 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9867 _(":upper16: not allowed in this instruction"));
c19d1205 9868 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9869 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9870 {
e2b0ab59 9871 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
9872 /* The value is in two pieces: 0:11, 16:19. */
9873 inst.instruction |= (imm & 0x00000fff);
9874 inst.instruction |= (imm & 0x0000f000) << 4;
9875 }
b05fe5cf 9876}
b99bd4ef 9877
037e8744
JB
9878static int
9879do_vfp_nsyn_mrs (void)
9880{
9881 if (inst.operands[0].isvec)
9882 {
9883 if (inst.operands[1].reg != 1)
477330fc 9884 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9885 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9886 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9887 do_vfp_nsyn_opcode ("fmstat");
9888 }
9889 else if (inst.operands[1].isvec)
9890 do_vfp_nsyn_opcode ("fmrx");
9891 else
9892 return FAIL;
5f4273c7 9893
037e8744
JB
9894 return SUCCESS;
9895}
9896
9897static int
9898do_vfp_nsyn_msr (void)
9899{
9900 if (inst.operands[0].isvec)
9901 do_vfp_nsyn_opcode ("fmxr");
9902 else
9903 return FAIL;
9904
9905 return SUCCESS;
9906}
9907
f7c21dc7
NC
9908static void
9909do_vmrs (void)
9910{
9911 unsigned Rt = inst.operands[0].reg;
fa94de6b 9912
16d02dc9 9913 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9914 {
9915 inst.error = BAD_SP;
9916 return;
9917 }
9918
ba6cd17f
SD
9919 switch (inst.operands[1].reg)
9920 {
9921 /* MVFR2 is only valid for Armv8-A. */
9922 case 5:
9923 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9924 _(BAD_FPU));
9925 break;
9926
9927 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9928 case 1: /* fpscr. */
9929 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9930 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9931 _(BAD_FPU));
9932 break;
9933
9934 case 14: /* fpcxt_ns. */
9935 case 15: /* fpcxt_s. */
9936 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
9937 _("selected processor does not support instruction"));
9938 break;
9939
9940 case 2: /* fpscr_nzcvqc. */
9941 case 12: /* vpr. */
9942 case 13: /* p0. */
9943 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
9944 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9945 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9946 _("selected processor does not support instruction"));
9947 if (inst.operands[0].reg != 2
9948 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
9949 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
9950 break;
9951
9952 default:
9953 break;
9954 }
40c7d507 9955
f7c21dc7 9956 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9957 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9958 {
9959 inst.error = BAD_PC;
9960 return;
9961 }
9962
16d02dc9
JB
9963 /* If we get through parsing the register name, we just insert the number
9964 generated into the instruction without further validation. */
9965 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9966 inst.instruction |= (Rt << 12);
9967}
9968
9969static void
9970do_vmsr (void)
9971{
9972 unsigned Rt = inst.operands[1].reg;
fa94de6b 9973
f7c21dc7
NC
9974 if (thumb_mode)
9975 reject_bad_reg (Rt);
9976 else if (Rt == REG_PC)
9977 {
9978 inst.error = BAD_PC;
9979 return;
9980 }
9981
ba6cd17f
SD
9982 switch (inst.operands[0].reg)
9983 {
9984 /* MVFR2 is only valid for Armv8-A. */
9985 case 5:
9986 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9987 _(BAD_FPU));
9988 break;
9989
9990 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9991 case 1: /* fpcr. */
9992 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9993 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9994 _(BAD_FPU));
9995 break;
9996
9997 case 14: /* fpcxt_ns. */
9998 case 15: /* fpcxt_s. */
9999 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10000 _("selected processor does not support instruction"));
10001 break;
10002
10003 case 2: /* fpscr_nzcvqc. */
10004 case 12: /* vpr. */
10005 case 13: /* p0. */
10006 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10007 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10008 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10009 _("selected processor does not support instruction"));
10010 if (inst.operands[0].reg != 2
10011 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10012 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10013 break;
10014
10015 default:
10016 break;
10017 }
40c7d507 10018
16d02dc9
JB
10019 /* If we get through parsing the register name, we just insert the number
10020 generated into the instruction without further validation. */
10021 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10022 inst.instruction |= (Rt << 12);
10023}
10024
b99bd4ef 10025static void
c19d1205 10026do_mrs (void)
b99bd4ef 10027{
90ec0d68
MGD
10028 unsigned br;
10029
037e8744
JB
10030 if (do_vfp_nsyn_mrs () == SUCCESS)
10031 return;
10032
ff4a8d2b 10033 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10034 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10035
10036 if (inst.operands[1].isreg)
10037 {
10038 br = inst.operands[1].reg;
806ab1c0 10039 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10040 as_bad (_("bad register for mrs"));
10041 }
10042 else
10043 {
10044 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10045 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10046 != (PSR_c|PSR_f),
d2cd1205 10047 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10048 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10049 }
10050
10051 inst.instruction |= br;
c19d1205 10052}
b99bd4ef 10053
c19d1205
ZW
10054/* Two possible forms:
10055 "{C|S}PSR_<field>, Rm",
10056 "{C|S}PSR_f, #expression". */
b99bd4ef 10057
c19d1205
ZW
10058static void
10059do_msr (void)
10060{
037e8744
JB
10061 if (do_vfp_nsyn_msr () == SUCCESS)
10062 return;
10063
c19d1205
ZW
10064 inst.instruction |= inst.operands[0].imm;
10065 if (inst.operands[1].isreg)
10066 inst.instruction |= inst.operands[1].reg;
10067 else
b99bd4ef 10068 {
c19d1205 10069 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10070 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10071 inst.relocs[0].pc_rel = 0;
b99bd4ef 10072 }
b99bd4ef
NC
10073}
10074
c19d1205
ZW
10075static void
10076do_mul (void)
a737bd4d 10077{
ff4a8d2b
NC
10078 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10079
c19d1205
ZW
10080 if (!inst.operands[2].present)
10081 inst.operands[2].reg = inst.operands[0].reg;
10082 inst.instruction |= inst.operands[0].reg << 16;
10083 inst.instruction |= inst.operands[1].reg;
10084 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10085
8fb9d7b9
MS
10086 if (inst.operands[0].reg == inst.operands[1].reg
10087 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10088 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10089}
10090
c19d1205
ZW
10091/* Long Multiply Parser
10092 UMULL RdLo, RdHi, Rm, Rs
10093 SMULL RdLo, RdHi, Rm, Rs
10094 UMLAL RdLo, RdHi, Rm, Rs
10095 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10096
10097static void
c19d1205 10098do_mull (void)
b99bd4ef 10099{
c19d1205
ZW
10100 inst.instruction |= inst.operands[0].reg << 12;
10101 inst.instruction |= inst.operands[1].reg << 16;
10102 inst.instruction |= inst.operands[2].reg;
10103 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10104
682b27ad
PB
10105 /* rdhi and rdlo must be different. */
10106 if (inst.operands[0].reg == inst.operands[1].reg)
10107 as_tsktsk (_("rdhi and rdlo must be different"));
10108
10109 /* rdhi, rdlo and rm must all be different before armv6. */
10110 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10111 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10112 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10113 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10114}
b99bd4ef 10115
c19d1205
ZW
10116static void
10117do_nop (void)
10118{
e7495e45
NS
10119 if (inst.operands[0].present
10120 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10121 {
10122 /* Architectural NOP hints are CPSR sets with no bits selected. */
10123 inst.instruction &= 0xf0000000;
e7495e45
NS
10124 inst.instruction |= 0x0320f000;
10125 if (inst.operands[0].present)
10126 inst.instruction |= inst.operands[0].imm;
c19d1205 10127 }
b99bd4ef
NC
10128}
10129
c19d1205
ZW
10130/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10131 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10132 Condition defaults to COND_ALWAYS.
10133 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10134
10135static void
c19d1205 10136do_pkhbt (void)
b99bd4ef 10137{
c19d1205
ZW
10138 inst.instruction |= inst.operands[0].reg << 12;
10139 inst.instruction |= inst.operands[1].reg << 16;
10140 inst.instruction |= inst.operands[2].reg;
10141 if (inst.operands[3].present)
10142 encode_arm_shift (3);
10143}
b99bd4ef 10144
c19d1205 10145/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10146
c19d1205
ZW
10147static void
10148do_pkhtb (void)
10149{
10150 if (!inst.operands[3].present)
b99bd4ef 10151 {
c19d1205
ZW
10152 /* If the shift specifier is omitted, turn the instruction
10153 into pkhbt rd, rm, rn. */
10154 inst.instruction &= 0xfff00010;
10155 inst.instruction |= inst.operands[0].reg << 12;
10156 inst.instruction |= inst.operands[1].reg;
10157 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10158 }
10159 else
10160 {
c19d1205
ZW
10161 inst.instruction |= inst.operands[0].reg << 12;
10162 inst.instruction |= inst.operands[1].reg << 16;
10163 inst.instruction |= inst.operands[2].reg;
10164 encode_arm_shift (3);
b99bd4ef
NC
10165 }
10166}
10167
c19d1205 10168/* ARMv5TE: Preload-Cache
60e5ef9f 10169 MP Extensions: Preload for write
c19d1205 10170
60e5ef9f 10171 PLD(W) <addr_mode>
c19d1205
ZW
10172
10173 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10174
10175static void
c19d1205 10176do_pld (void)
b99bd4ef 10177{
c19d1205
ZW
10178 constraint (!inst.operands[0].isreg,
10179 _("'[' expected after PLD mnemonic"));
10180 constraint (inst.operands[0].postind,
10181 _("post-indexed expression used in preload instruction"));
10182 constraint (inst.operands[0].writeback,
10183 _("writeback used in preload instruction"));
10184 constraint (!inst.operands[0].preind,
10185 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10186 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10187}
b99bd4ef 10188
62b3e311
PB
10189/* ARMv7: PLI <addr_mode> */
10190static void
10191do_pli (void)
10192{
10193 constraint (!inst.operands[0].isreg,
10194 _("'[' expected after PLI mnemonic"));
10195 constraint (inst.operands[0].postind,
10196 _("post-indexed expression used in preload instruction"));
10197 constraint (inst.operands[0].writeback,
10198 _("writeback used in preload instruction"));
10199 constraint (!inst.operands[0].preind,
10200 _("unindexed addressing used in preload instruction"));
10201 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10202 inst.instruction &= ~PRE_INDEX;
10203}
10204
c19d1205
ZW
10205static void
10206do_push_pop (void)
10207{
5e0d7f77
MP
10208 constraint (inst.operands[0].writeback,
10209 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10210 inst.operands[1] = inst.operands[0];
10211 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10212 inst.operands[0].isreg = 1;
10213 inst.operands[0].writeback = 1;
10214 inst.operands[0].reg = REG_SP;
6530b175 10215 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10216}
b99bd4ef 10217
c19d1205
ZW
10218/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10219 word at the specified address and the following word
10220 respectively.
10221 Unconditionally executed.
10222 Error if Rn is R15. */
b99bd4ef 10223
c19d1205
ZW
10224static void
10225do_rfe (void)
10226{
10227 inst.instruction |= inst.operands[0].reg << 16;
10228 if (inst.operands[0].writeback)
10229 inst.instruction |= WRITE_BACK;
10230}
b99bd4ef 10231
c19d1205 10232/* ARM V6 ssat (argument parse). */
b99bd4ef 10233
c19d1205
ZW
10234static void
10235do_ssat (void)
10236{
10237 inst.instruction |= inst.operands[0].reg << 12;
10238 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10239 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10240
c19d1205
ZW
10241 if (inst.operands[3].present)
10242 encode_arm_shift (3);
b99bd4ef
NC
10243}
10244
c19d1205 10245/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10246
10247static void
c19d1205 10248do_usat (void)
b99bd4ef 10249{
c19d1205
ZW
10250 inst.instruction |= inst.operands[0].reg << 12;
10251 inst.instruction |= inst.operands[1].imm << 16;
10252 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10253
c19d1205
ZW
10254 if (inst.operands[3].present)
10255 encode_arm_shift (3);
b99bd4ef
NC
10256}
10257
c19d1205 10258/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10259
10260static void
c19d1205 10261do_ssat16 (void)
09d92015 10262{
c19d1205
ZW
10263 inst.instruction |= inst.operands[0].reg << 12;
10264 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10265 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10266}
10267
c19d1205
ZW
10268static void
10269do_usat16 (void)
a737bd4d 10270{
c19d1205
ZW
10271 inst.instruction |= inst.operands[0].reg << 12;
10272 inst.instruction |= inst.operands[1].imm << 16;
10273 inst.instruction |= inst.operands[2].reg;
10274}
a737bd4d 10275
c19d1205
ZW
10276/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10277 preserving the other bits.
a737bd4d 10278
c19d1205
ZW
10279 setend <endian_specifier>, where <endian_specifier> is either
10280 BE or LE. */
a737bd4d 10281
c19d1205
ZW
10282static void
10283do_setend (void)
10284{
12e37cbc
MGD
10285 if (warn_on_deprecated
10286 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10287 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10288
c19d1205
ZW
10289 if (inst.operands[0].imm)
10290 inst.instruction |= 0x200;
a737bd4d
NC
10291}
10292
10293static void
c19d1205 10294do_shift (void)
a737bd4d 10295{
c19d1205
ZW
10296 unsigned int Rm = (inst.operands[1].present
10297 ? inst.operands[1].reg
10298 : inst.operands[0].reg);
a737bd4d 10299
c19d1205
ZW
10300 inst.instruction |= inst.operands[0].reg << 12;
10301 inst.instruction |= Rm;
10302 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10303 {
c19d1205
ZW
10304 inst.instruction |= inst.operands[2].reg << 8;
10305 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10306 /* PR 12854: Error on extraneous shifts. */
10307 constraint (inst.operands[2].shifted,
10308 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10309 }
10310 else
e2b0ab59 10311 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10312}
10313
09d92015 10314static void
3eb17e6b 10315do_smc (void)
09d92015 10316{
ba85f98c
BW
10317 unsigned int value = inst.relocs[0].exp.X_add_number;
10318 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10319
e2b0ab59
AV
10320 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10321 inst.relocs[0].pc_rel = 0;
09d92015
MM
10322}
10323
90ec0d68
MGD
10324static void
10325do_hvc (void)
10326{
e2b0ab59
AV
10327 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10328 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10329}
10330
09d92015 10331static void
c19d1205 10332do_swi (void)
09d92015 10333{
e2b0ab59
AV
10334 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10335 inst.relocs[0].pc_rel = 0;
09d92015
MM
10336}
10337
ddfded2f
MW
10338static void
10339do_setpan (void)
10340{
10341 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10342 _("selected processor does not support SETPAN instruction"));
10343
10344 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10345}
10346
10347static void
10348do_t_setpan (void)
10349{
10350 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10351 _("selected processor does not support SETPAN instruction"));
10352
10353 inst.instruction |= (inst.operands[0].imm << 3);
10354}
10355
c19d1205
ZW
10356/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10357 SMLAxy{cond} Rd,Rm,Rs,Rn
10358 SMLAWy{cond} Rd,Rm,Rs,Rn
10359 Error if any register is R15. */
e16bb312 10360
c19d1205
ZW
10361static void
10362do_smla (void)
e16bb312 10363{
c19d1205
ZW
10364 inst.instruction |= inst.operands[0].reg << 16;
10365 inst.instruction |= inst.operands[1].reg;
10366 inst.instruction |= inst.operands[2].reg << 8;
10367 inst.instruction |= inst.operands[3].reg << 12;
10368}
a737bd4d 10369
c19d1205
ZW
10370/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10371 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10372 Error if any register is R15.
10373 Warning if Rdlo == Rdhi. */
a737bd4d 10374
c19d1205
ZW
10375static void
10376do_smlal (void)
10377{
10378 inst.instruction |= inst.operands[0].reg << 12;
10379 inst.instruction |= inst.operands[1].reg << 16;
10380 inst.instruction |= inst.operands[2].reg;
10381 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10382
c19d1205
ZW
10383 if (inst.operands[0].reg == inst.operands[1].reg)
10384 as_tsktsk (_("rdhi and rdlo must be different"));
10385}
a737bd4d 10386
c19d1205
ZW
10387/* ARM V5E (El Segundo) signed-multiply (argument parse)
10388 SMULxy{cond} Rd,Rm,Rs
10389 Error if any register is R15. */
a737bd4d 10390
c19d1205
ZW
10391static void
10392do_smul (void)
10393{
10394 inst.instruction |= inst.operands[0].reg << 16;
10395 inst.instruction |= inst.operands[1].reg;
10396 inst.instruction |= inst.operands[2].reg << 8;
10397}
a737bd4d 10398
b6702015
PB
10399/* ARM V6 srs (argument parse). The variable fields in the encoding are
10400 the same for both ARM and Thumb-2. */
a737bd4d 10401
c19d1205
ZW
10402static void
10403do_srs (void)
10404{
b6702015
PB
10405 int reg;
10406
10407 if (inst.operands[0].present)
10408 {
10409 reg = inst.operands[0].reg;
fdfde340 10410 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10411 }
10412 else
fdfde340 10413 reg = REG_SP;
b6702015
PB
10414
10415 inst.instruction |= reg << 16;
10416 inst.instruction |= inst.operands[1].imm;
10417 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10418 inst.instruction |= WRITE_BACK;
10419}
a737bd4d 10420
c19d1205 10421/* ARM V6 strex (argument parse). */
a737bd4d 10422
c19d1205
ZW
10423static void
10424do_strex (void)
10425{
10426 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10427 || inst.operands[2].postind || inst.operands[2].writeback
10428 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10429 || inst.operands[2].negative
10430 /* See comment in do_ldrex(). */
10431 || (inst.operands[2].reg == REG_PC),
10432 BAD_ADDR_MODE);
a737bd4d 10433
c19d1205
ZW
10434 constraint (inst.operands[0].reg == inst.operands[1].reg
10435 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10436
e2b0ab59
AV
10437 constraint (inst.relocs[0].exp.X_op != O_constant
10438 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10439 _("offset must be zero in ARM encoding"));
a737bd4d 10440
c19d1205
ZW
10441 inst.instruction |= inst.operands[0].reg << 12;
10442 inst.instruction |= inst.operands[1].reg;
10443 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10444 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10445}
10446
877807f8
NC
10447static void
10448do_t_strexbh (void)
10449{
10450 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10451 || inst.operands[2].postind || inst.operands[2].writeback
10452 || inst.operands[2].immisreg || inst.operands[2].shifted
10453 || inst.operands[2].negative,
10454 BAD_ADDR_MODE);
10455
10456 constraint (inst.operands[0].reg == inst.operands[1].reg
10457 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10458
10459 do_rm_rd_rn ();
10460}
10461
e16bb312 10462static void
c19d1205 10463do_strexd (void)
e16bb312 10464{
c19d1205
ZW
10465 constraint (inst.operands[1].reg % 2 != 0,
10466 _("even register required"));
10467 constraint (inst.operands[2].present
10468 && inst.operands[2].reg != inst.operands[1].reg + 1,
10469 _("can only store two consecutive registers"));
10470 /* If op 2 were present and equal to PC, this function wouldn't
10471 have been called in the first place. */
10472 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10473
c19d1205
ZW
10474 constraint (inst.operands[0].reg == inst.operands[1].reg
10475 || inst.operands[0].reg == inst.operands[1].reg + 1
10476 || inst.operands[0].reg == inst.operands[3].reg,
10477 BAD_OVERLAP);
e16bb312 10478
c19d1205
ZW
10479 inst.instruction |= inst.operands[0].reg << 12;
10480 inst.instruction |= inst.operands[1].reg;
10481 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10482}
10483
9eb6c0f1
MGD
10484/* ARM V8 STRL. */
10485static void
4b8c8c02 10486do_stlex (void)
9eb6c0f1
MGD
10487{
10488 constraint (inst.operands[0].reg == inst.operands[1].reg
10489 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10490
10491 do_rd_rm_rn ();
10492}
10493
10494static void
4b8c8c02 10495do_t_stlex (void)
9eb6c0f1
MGD
10496{
10497 constraint (inst.operands[0].reg == inst.operands[1].reg
10498 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10499
10500 do_rm_rd_rn ();
10501}
10502
c19d1205
ZW
10503/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10504 extends it to 32-bits, and adds the result to a value in another
10505 register. You can specify a rotation by 0, 8, 16, or 24 bits
10506 before extracting the 16-bit value.
10507 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10508 Condition defaults to COND_ALWAYS.
10509 Error if any register uses R15. */
10510
e16bb312 10511static void
c19d1205 10512do_sxtah (void)
e16bb312 10513{
c19d1205
ZW
10514 inst.instruction |= inst.operands[0].reg << 12;
10515 inst.instruction |= inst.operands[1].reg << 16;
10516 inst.instruction |= inst.operands[2].reg;
10517 inst.instruction |= inst.operands[3].imm << 10;
10518}
e16bb312 10519
c19d1205 10520/* ARM V6 SXTH.
e16bb312 10521
c19d1205
ZW
10522 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10523 Condition defaults to COND_ALWAYS.
10524 Error if any register uses R15. */
e16bb312
NC
10525
10526static void
c19d1205 10527do_sxth (void)
e16bb312 10528{
c19d1205
ZW
10529 inst.instruction |= inst.operands[0].reg << 12;
10530 inst.instruction |= inst.operands[1].reg;
10531 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10532}
c19d1205
ZW
10533\f
10534/* VFP instructions. In a logical order: SP variant first, monad
10535 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10536
10537static void
c19d1205 10538do_vfp_sp_monadic (void)
e16bb312 10539{
57785aa2
AV
10540 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10541 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10542 _(BAD_FPU));
10543
5287ad62
JB
10544 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10545 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10546}
10547
10548static void
c19d1205 10549do_vfp_sp_dyadic (void)
e16bb312 10550{
5287ad62
JB
10551 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10552 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10553 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10554}
10555
10556static void
c19d1205 10557do_vfp_sp_compare_z (void)
e16bb312 10558{
5287ad62 10559 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10560}
10561
10562static void
c19d1205 10563do_vfp_dp_sp_cvt (void)
e16bb312 10564{
5287ad62
JB
10565 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10566 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10567}
10568
10569static void
c19d1205 10570do_vfp_sp_dp_cvt (void)
e16bb312 10571{
5287ad62
JB
10572 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10573 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10574}
10575
10576static void
c19d1205 10577do_vfp_reg_from_sp (void)
e16bb312 10578{
57785aa2
AV
10579 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10580 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10581 _(BAD_FPU));
10582
c19d1205 10583 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10584 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10585}
10586
10587static void
c19d1205 10588do_vfp_reg2_from_sp2 (void)
e16bb312 10589{
c19d1205
ZW
10590 constraint (inst.operands[2].imm != 2,
10591 _("only two consecutive VFP SP registers allowed here"));
10592 inst.instruction |= inst.operands[0].reg << 12;
10593 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10594 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10595}
10596
10597static void
c19d1205 10598do_vfp_sp_from_reg (void)
e16bb312 10599{
57785aa2
AV
10600 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10601 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10602 _(BAD_FPU));
10603
5287ad62 10604 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10605 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10606}
10607
10608static void
c19d1205 10609do_vfp_sp2_from_reg2 (void)
e16bb312 10610{
c19d1205
ZW
10611 constraint (inst.operands[0].imm != 2,
10612 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10613 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10614 inst.instruction |= inst.operands[1].reg << 12;
10615 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10616}
10617
10618static void
c19d1205 10619do_vfp_sp_ldst (void)
e16bb312 10620{
5287ad62 10621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10622 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10623}
10624
10625static void
c19d1205 10626do_vfp_dp_ldst (void)
e16bb312 10627{
5287ad62 10628 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10629 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10630}
10631
c19d1205 10632
e16bb312 10633static void
c19d1205 10634vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10635{
c19d1205
ZW
10636 if (inst.operands[0].writeback)
10637 inst.instruction |= WRITE_BACK;
10638 else
10639 constraint (ldstm_type != VFP_LDSTMIA,
10640 _("this addressing mode requires base-register writeback"));
10641 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10642 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10643 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10644}
10645
10646static void
c19d1205 10647vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10648{
c19d1205 10649 int count;
e16bb312 10650
c19d1205
ZW
10651 if (inst.operands[0].writeback)
10652 inst.instruction |= WRITE_BACK;
10653 else
10654 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10655 _("this addressing mode requires base-register writeback"));
e16bb312 10656
c19d1205 10657 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10658 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10659
c19d1205
ZW
10660 count = inst.operands[1].imm << 1;
10661 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10662 count += 1;
e16bb312 10663
c19d1205 10664 inst.instruction |= count;
e16bb312
NC
10665}
10666
10667static void
c19d1205 10668do_vfp_sp_ldstmia (void)
e16bb312 10669{
c19d1205 10670 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10671}
10672
10673static void
c19d1205 10674do_vfp_sp_ldstmdb (void)
e16bb312 10675{
c19d1205 10676 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10677}
10678
10679static void
c19d1205 10680do_vfp_dp_ldstmia (void)
e16bb312 10681{
c19d1205 10682 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10683}
10684
10685static void
c19d1205 10686do_vfp_dp_ldstmdb (void)
e16bb312 10687{
c19d1205 10688 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10689}
10690
10691static void
c19d1205 10692do_vfp_xp_ldstmia (void)
e16bb312 10693{
c19d1205
ZW
10694 vfp_dp_ldstm (VFP_LDSTMIAX);
10695}
e16bb312 10696
c19d1205
ZW
10697static void
10698do_vfp_xp_ldstmdb (void)
10699{
10700 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10701}
5287ad62
JB
10702
10703static void
10704do_vfp_dp_rd_rm (void)
10705{
57785aa2
AV
10706 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10707 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10708 _(BAD_FPU));
10709
5287ad62
JB
10710 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10711 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10712}
10713
10714static void
10715do_vfp_dp_rn_rd (void)
10716{
10717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10718 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10719}
10720
10721static void
10722do_vfp_dp_rd_rn (void)
10723{
10724 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10725 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10726}
10727
10728static void
10729do_vfp_dp_rd_rn_rm (void)
10730{
57785aa2
AV
10731 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10732 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10733 _(BAD_FPU));
10734
5287ad62
JB
10735 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10736 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10737 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10738}
10739
10740static void
10741do_vfp_dp_rd (void)
10742{
10743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10744}
10745
10746static void
10747do_vfp_dp_rm_rd_rn (void)
10748{
57785aa2
AV
10749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10750 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10751 _(BAD_FPU));
10752
5287ad62
JB
10753 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10754 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10755 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10756}
10757
10758/* VFPv3 instructions. */
10759static void
10760do_vfp_sp_const (void)
10761{
10762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10763 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10764 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10765}
10766
10767static void
10768do_vfp_dp_const (void)
10769{
10770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10771 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10772 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10773}
10774
10775static void
10776vfp_conv (int srcsize)
10777{
5f1af56b
MGD
10778 int immbits = srcsize - inst.operands[1].imm;
10779
fa94de6b
RM
10780 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10781 {
5f1af56b 10782 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10783 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10784 inst.error = _("immediate value out of range, expected range [0, 16]");
10785 return;
10786 }
fa94de6b 10787 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10788 {
10789 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10790 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10791 inst.error = _("immediate value out of range, expected range [1, 32]");
10792 return;
10793 }
10794
5287ad62
JB
10795 inst.instruction |= (immbits & 1) << 5;
10796 inst.instruction |= (immbits >> 1);
10797}
10798
10799static void
10800do_vfp_sp_conv_16 (void)
10801{
10802 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10803 vfp_conv (16);
10804}
10805
10806static void
10807do_vfp_dp_conv_16 (void)
10808{
10809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10810 vfp_conv (16);
10811}
10812
10813static void
10814do_vfp_sp_conv_32 (void)
10815{
10816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10817 vfp_conv (32);
10818}
10819
10820static void
10821do_vfp_dp_conv_32 (void)
10822{
10823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10824 vfp_conv (32);
10825}
c19d1205
ZW
10826\f
10827/* FPA instructions. Also in a logical order. */
e16bb312 10828
c19d1205
ZW
10829static void
10830do_fpa_cmp (void)
10831{
10832 inst.instruction |= inst.operands[0].reg << 16;
10833 inst.instruction |= inst.operands[1].reg;
10834}
b99bd4ef
NC
10835
10836static void
c19d1205 10837do_fpa_ldmstm (void)
b99bd4ef 10838{
c19d1205
ZW
10839 inst.instruction |= inst.operands[0].reg << 12;
10840 switch (inst.operands[1].imm)
10841 {
10842 case 1: inst.instruction |= CP_T_X; break;
10843 case 2: inst.instruction |= CP_T_Y; break;
10844 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10845 case 4: break;
10846 default: abort ();
10847 }
b99bd4ef 10848
c19d1205
ZW
10849 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10850 {
10851 /* The instruction specified "ea" or "fd", so we can only accept
10852 [Rn]{!}. The instruction does not really support stacking or
10853 unstacking, so we have to emulate these by setting appropriate
10854 bits and offsets. */
e2b0ab59
AV
10855 constraint (inst.relocs[0].exp.X_op != O_constant
10856 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10857 _("this instruction does not support indexing"));
b99bd4ef 10858
c19d1205 10859 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10860 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10861
c19d1205 10862 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10863 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10864
c19d1205
ZW
10865 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10866 {
10867 inst.operands[2].preind = 0;
10868 inst.operands[2].postind = 1;
10869 }
10870 }
b99bd4ef 10871
c19d1205 10872 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10873}
c19d1205
ZW
10874\f
10875/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10876
c19d1205
ZW
10877static void
10878do_iwmmxt_tandorc (void)
10879{
10880 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10881}
b99bd4ef 10882
c19d1205
ZW
10883static void
10884do_iwmmxt_textrc (void)
10885{
10886 inst.instruction |= inst.operands[0].reg << 12;
10887 inst.instruction |= inst.operands[1].imm;
10888}
b99bd4ef
NC
10889
10890static void
c19d1205 10891do_iwmmxt_textrm (void)
b99bd4ef 10892{
c19d1205
ZW
10893 inst.instruction |= inst.operands[0].reg << 12;
10894 inst.instruction |= inst.operands[1].reg << 16;
10895 inst.instruction |= inst.operands[2].imm;
10896}
b99bd4ef 10897
c19d1205
ZW
10898static void
10899do_iwmmxt_tinsr (void)
10900{
10901 inst.instruction |= inst.operands[0].reg << 16;
10902 inst.instruction |= inst.operands[1].reg << 12;
10903 inst.instruction |= inst.operands[2].imm;
10904}
b99bd4ef 10905
c19d1205
ZW
10906static void
10907do_iwmmxt_tmia (void)
10908{
10909 inst.instruction |= inst.operands[0].reg << 5;
10910 inst.instruction |= inst.operands[1].reg;
10911 inst.instruction |= inst.operands[2].reg << 12;
10912}
b99bd4ef 10913
c19d1205
ZW
10914static void
10915do_iwmmxt_waligni (void)
10916{
10917 inst.instruction |= inst.operands[0].reg << 12;
10918 inst.instruction |= inst.operands[1].reg << 16;
10919 inst.instruction |= inst.operands[2].reg;
10920 inst.instruction |= inst.operands[3].imm << 20;
10921}
b99bd4ef 10922
2d447fca
JM
10923static void
10924do_iwmmxt_wmerge (void)
10925{
10926 inst.instruction |= inst.operands[0].reg << 12;
10927 inst.instruction |= inst.operands[1].reg << 16;
10928 inst.instruction |= inst.operands[2].reg;
10929 inst.instruction |= inst.operands[3].imm << 21;
10930}
10931
c19d1205
ZW
10932static void
10933do_iwmmxt_wmov (void)
10934{
10935 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10936 inst.instruction |= inst.operands[0].reg << 12;
10937 inst.instruction |= inst.operands[1].reg << 16;
10938 inst.instruction |= inst.operands[1].reg;
10939}
b99bd4ef 10940
c19d1205
ZW
10941static void
10942do_iwmmxt_wldstbh (void)
10943{
8f06b2d8 10944 int reloc;
c19d1205 10945 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10946 if (thumb_mode)
10947 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10948 else
10949 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10950 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10951}
10952
c19d1205
ZW
10953static void
10954do_iwmmxt_wldstw (void)
10955{
10956 /* RIWR_RIWC clears .isreg for a control register. */
10957 if (!inst.operands[0].isreg)
10958 {
10959 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10960 inst.instruction |= 0xf0000000;
10961 }
b99bd4ef 10962
c19d1205
ZW
10963 inst.instruction |= inst.operands[0].reg << 12;
10964 encode_arm_cp_address (1, TRUE, TRUE, 0);
10965}
b99bd4ef
NC
10966
10967static void
c19d1205 10968do_iwmmxt_wldstd (void)
b99bd4ef 10969{
c19d1205 10970 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10971 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10972 && inst.operands[1].immisreg)
10973 {
10974 inst.instruction &= ~0x1a000ff;
eff0bc54 10975 inst.instruction |= (0xfU << 28);
2d447fca
JM
10976 if (inst.operands[1].preind)
10977 inst.instruction |= PRE_INDEX;
10978 if (!inst.operands[1].negative)
10979 inst.instruction |= INDEX_UP;
10980 if (inst.operands[1].writeback)
10981 inst.instruction |= WRITE_BACK;
10982 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 10983 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
10984 inst.instruction |= inst.operands[1].imm;
10985 }
10986 else
10987 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10988}
b99bd4ef 10989
c19d1205
ZW
10990static void
10991do_iwmmxt_wshufh (void)
10992{
10993 inst.instruction |= inst.operands[0].reg << 12;
10994 inst.instruction |= inst.operands[1].reg << 16;
10995 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10996 inst.instruction |= (inst.operands[2].imm & 0x0f);
10997}
b99bd4ef 10998
c19d1205
ZW
10999static void
11000do_iwmmxt_wzero (void)
11001{
11002 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11003 inst.instruction |= inst.operands[0].reg;
11004 inst.instruction |= inst.operands[0].reg << 12;
11005 inst.instruction |= inst.operands[0].reg << 16;
11006}
2d447fca
JM
11007
11008static void
11009do_iwmmxt_wrwrwr_or_imm5 (void)
11010{
11011 if (inst.operands[2].isreg)
11012 do_rd_rn_rm ();
11013 else {
11014 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11015 _("immediate operand requires iWMMXt2"));
11016 do_rd_rn ();
11017 if (inst.operands[2].imm == 0)
11018 {
11019 switch ((inst.instruction >> 20) & 0xf)
11020 {
11021 case 4:
11022 case 5:
11023 case 6:
5f4273c7 11024 case 7:
2d447fca
JM
11025 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11026 inst.operands[2].imm = 16;
11027 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11028 break;
11029 case 8:
11030 case 9:
11031 case 10:
11032 case 11:
11033 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11034 inst.operands[2].imm = 32;
11035 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11036 break;
11037 case 12:
11038 case 13:
11039 case 14:
11040 case 15:
11041 {
11042 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11043 unsigned long wrn;
11044 wrn = (inst.instruction >> 16) & 0xf;
11045 inst.instruction &= 0xff0fff0f;
11046 inst.instruction |= wrn;
11047 /* Bail out here; the instruction is now assembled. */
11048 return;
11049 }
11050 }
11051 }
11052 /* Map 32 -> 0, etc. */
11053 inst.operands[2].imm &= 0x1f;
eff0bc54 11054 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11055 }
11056}
c19d1205
ZW
11057\f
11058/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11059 operations first, then control, shift, and load/store. */
b99bd4ef 11060
c19d1205 11061/* Insns like "foo X,Y,Z". */
b99bd4ef 11062
c19d1205
ZW
11063static void
11064do_mav_triple (void)
11065{
11066 inst.instruction |= inst.operands[0].reg << 16;
11067 inst.instruction |= inst.operands[1].reg;
11068 inst.instruction |= inst.operands[2].reg << 12;
11069}
b99bd4ef 11070
c19d1205
ZW
11071/* Insns like "foo W,X,Y,Z".
11072 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11073
c19d1205
ZW
11074static void
11075do_mav_quad (void)
11076{
11077 inst.instruction |= inst.operands[0].reg << 5;
11078 inst.instruction |= inst.operands[1].reg << 12;
11079 inst.instruction |= inst.operands[2].reg << 16;
11080 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11081}
11082
c19d1205
ZW
11083/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11084static void
11085do_mav_dspsc (void)
a737bd4d 11086{
c19d1205
ZW
11087 inst.instruction |= inst.operands[1].reg << 12;
11088}
a737bd4d 11089
c19d1205
ZW
11090/* Maverick shift immediate instructions.
11091 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11092 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11093
c19d1205
ZW
11094static void
11095do_mav_shift (void)
11096{
11097 int imm = inst.operands[2].imm;
a737bd4d 11098
c19d1205
ZW
11099 inst.instruction |= inst.operands[0].reg << 12;
11100 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11101
c19d1205
ZW
11102 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11103 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11104 Bit 4 should be 0. */
11105 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11106
c19d1205
ZW
11107 inst.instruction |= imm;
11108}
11109\f
11110/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11111
c19d1205
ZW
11112/* Xscale multiply-accumulate (argument parse)
11113 MIAcc acc0,Rm,Rs
11114 MIAPHcc acc0,Rm,Rs
11115 MIAxycc acc0,Rm,Rs. */
a737bd4d 11116
c19d1205
ZW
11117static void
11118do_xsc_mia (void)
11119{
11120 inst.instruction |= inst.operands[1].reg;
11121 inst.instruction |= inst.operands[2].reg << 12;
11122}
a737bd4d 11123
c19d1205 11124/* Xscale move-accumulator-register (argument parse)
a737bd4d 11125
c19d1205 11126 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11127
c19d1205
ZW
11128static void
11129do_xsc_mar (void)
11130{
11131 inst.instruction |= inst.operands[1].reg << 12;
11132 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11133}
11134
c19d1205 11135/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11136
c19d1205 11137 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11138
11139static void
c19d1205 11140do_xsc_mra (void)
b99bd4ef 11141{
c19d1205
ZW
11142 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11143 inst.instruction |= inst.operands[0].reg << 12;
11144 inst.instruction |= inst.operands[1].reg << 16;
11145}
11146\f
11147/* Encoding functions relevant only to Thumb. */
b99bd4ef 11148
c19d1205
ZW
11149/* inst.operands[i] is a shifted-register operand; encode
11150 it into inst.instruction in the format used by Thumb32. */
11151
11152static void
11153encode_thumb32_shifted_operand (int i)
11154{
e2b0ab59 11155 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11156 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11157
9c3c69f2
PB
11158 constraint (inst.operands[i].immisreg,
11159 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11160 inst.instruction |= inst.operands[i].reg;
11161 if (shift == SHIFT_RRX)
11162 inst.instruction |= SHIFT_ROR << 4;
11163 else
b99bd4ef 11164 {
e2b0ab59 11165 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11166 _("expression too complex"));
11167
11168 constraint (value > 32
11169 || (value == 32 && (shift == SHIFT_LSL
11170 || shift == SHIFT_ROR)),
11171 _("shift expression is too large"));
11172
11173 if (value == 0)
11174 shift = SHIFT_LSL;
11175 else if (value == 32)
11176 value = 0;
11177
11178 inst.instruction |= shift << 4;
11179 inst.instruction |= (value & 0x1c) << 10;
11180 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11181 }
c19d1205 11182}
b99bd4ef 11183
b99bd4ef 11184
c19d1205
ZW
11185/* inst.operands[i] was set up by parse_address. Encode it into a
11186 Thumb32 format load or store instruction. Reject forms that cannot
11187 be used with such instructions. If is_t is true, reject forms that
11188 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11189 that cannot be used with a D instruction. If it is a store insn,
11190 reject PC in Rn. */
b99bd4ef 11191
c19d1205
ZW
11192static void
11193encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11194{
5be8be5d 11195 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11196
11197 constraint (!inst.operands[i].isreg,
53365c0d 11198 _("Instruction does not support =N addresses"));
b99bd4ef 11199
c19d1205
ZW
11200 inst.instruction |= inst.operands[i].reg << 16;
11201 if (inst.operands[i].immisreg)
b99bd4ef 11202 {
5be8be5d 11203 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11204 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11205 constraint (inst.operands[i].negative,
11206 _("Thumb does not support negative register indexing"));
11207 constraint (inst.operands[i].postind,
11208 _("Thumb does not support register post-indexing"));
11209 constraint (inst.operands[i].writeback,
11210 _("Thumb does not support register indexing with writeback"));
11211 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11212 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11213
f40d1643 11214 inst.instruction |= inst.operands[i].imm;
c19d1205 11215 if (inst.operands[i].shifted)
b99bd4ef 11216 {
e2b0ab59 11217 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11218 _("expression too complex"));
e2b0ab59
AV
11219 constraint (inst.relocs[0].exp.X_add_number < 0
11220 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11221 _("shift out of range"));
e2b0ab59 11222 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11223 }
e2b0ab59 11224 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11225 }
11226 else if (inst.operands[i].preind)
11227 {
5be8be5d 11228 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11229 constraint (is_t && inst.operands[i].writeback,
c19d1205 11230 _("cannot use writeback with this instruction"));
4755303e
WN
11231 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11232 BAD_PC_ADDRESSING);
c19d1205
ZW
11233
11234 if (is_d)
11235 {
11236 inst.instruction |= 0x01000000;
11237 if (inst.operands[i].writeback)
11238 inst.instruction |= 0x00200000;
b99bd4ef 11239 }
c19d1205 11240 else
b99bd4ef 11241 {
c19d1205
ZW
11242 inst.instruction |= 0x00000c00;
11243 if (inst.operands[i].writeback)
11244 inst.instruction |= 0x00000100;
b99bd4ef 11245 }
e2b0ab59 11246 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11247 }
c19d1205 11248 else if (inst.operands[i].postind)
b99bd4ef 11249 {
9c2799c2 11250 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11251 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11252 constraint (is_t, _("cannot use post-indexing with this instruction"));
11253
11254 if (is_d)
11255 inst.instruction |= 0x00200000;
11256 else
11257 inst.instruction |= 0x00000900;
e2b0ab59 11258 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11259 }
11260 else /* unindexed - only for coprocessor */
11261 inst.error = _("instruction does not accept unindexed addressing");
11262}
11263
e39c1607 11264/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11265 encodings (the latter only in post-V6T2 cores). The index is the
11266 value used in the insns table below. When there is more than one
11267 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11268 holds variant (1).
11269 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11270#define T16_32_TAB \
21d799b5
NC
11271 X(_adc, 4140, eb400000), \
11272 X(_adcs, 4140, eb500000), \
11273 X(_add, 1c00, eb000000), \
11274 X(_adds, 1c00, eb100000), \
11275 X(_addi, 0000, f1000000), \
11276 X(_addis, 0000, f1100000), \
11277 X(_add_pc,000f, f20f0000), \
11278 X(_add_sp,000d, f10d0000), \
11279 X(_adr, 000f, f20f0000), \
11280 X(_and, 4000, ea000000), \
11281 X(_ands, 4000, ea100000), \
11282 X(_asr, 1000, fa40f000), \
11283 X(_asrs, 1000, fa50f000), \
11284 X(_b, e000, f000b000), \
11285 X(_bcond, d000, f0008000), \
4389b29a 11286 X(_bf, 0000, f040e001), \
f6b2b12d 11287 X(_bfcsel,0000, f000e001), \
f1c7f421 11288 X(_bfx, 0000, f060e001), \
65d1bc05 11289 X(_bfl, 0000, f000c001), \
f1c7f421 11290 X(_bflx, 0000, f070e001), \
21d799b5
NC
11291 X(_bic, 4380, ea200000), \
11292 X(_bics, 4380, ea300000), \
e39c1607
SD
11293 X(_cinc, 0000, ea509000), \
11294 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11295 X(_cmn, 42c0, eb100f00), \
11296 X(_cmp, 2800, ebb00f00), \
e39c1607 11297 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11298 X(_cpsie, b660, f3af8400), \
11299 X(_cpsid, b670, f3af8600), \
11300 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11301 X(_csel, 0000, ea508000), \
11302 X(_cset, 0000, ea5f900f), \
11303 X(_csetm, 0000, ea5fa00f), \
11304 X(_csinc, 0000, ea509000), \
11305 X(_csinv, 0000, ea50a000), \
11306 X(_csneg, 0000, ea50b000), \
21d799b5 11307 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11308 X(_dls, 0000, f040e001), \
1f6234a3 11309 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11310 X(_eor, 4040, ea800000), \
11311 X(_eors, 4040, ea900000), \
11312 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11313 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11314 X(_ldmia, c800, e8900000), \
11315 X(_ldr, 6800, f8500000), \
11316 X(_ldrb, 7800, f8100000), \
11317 X(_ldrh, 8800, f8300000), \
11318 X(_ldrsb, 5600, f9100000), \
11319 X(_ldrsh, 5e00, f9300000), \
11320 X(_ldr_pc,4800, f85f0000), \
11321 X(_ldr_pc2,4800, f85f0000), \
11322 X(_ldr_sp,9800, f85d0000), \
60f993ce 11323 X(_le, 0000, f00fc001), \
1f6234a3 11324 X(_letp, 0000, f01fc001), \
21d799b5
NC
11325 X(_lsl, 0000, fa00f000), \
11326 X(_lsls, 0000, fa10f000), \
11327 X(_lsr, 0800, fa20f000), \
11328 X(_lsrs, 0800, fa30f000), \
11329 X(_mov, 2000, ea4f0000), \
11330 X(_movs, 2000, ea5f0000), \
11331 X(_mul, 4340, fb00f000), \
11332 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11333 X(_mvn, 43c0, ea6f0000), \
11334 X(_mvns, 43c0, ea7f0000), \
11335 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11336 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11337 X(_orr, 4300, ea400000), \
11338 X(_orrs, 4300, ea500000), \
11339 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11340 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11341 X(_rev, ba00, fa90f080), \
11342 X(_rev16, ba40, fa90f090), \
11343 X(_revsh, bac0, fa90f0b0), \
11344 X(_ror, 41c0, fa60f000), \
11345 X(_rors, 41c0, fa70f000), \
11346 X(_sbc, 4180, eb600000), \
11347 X(_sbcs, 4180, eb700000), \
11348 X(_stmia, c000, e8800000), \
11349 X(_str, 6000, f8400000), \
11350 X(_strb, 7000, f8000000), \
11351 X(_strh, 8000, f8200000), \
11352 X(_str_sp,9000, f84d0000), \
11353 X(_sub, 1e00, eba00000), \
11354 X(_subs, 1e00, ebb00000), \
11355 X(_subi, 8000, f1a00000), \
11356 X(_subis, 8000, f1b00000), \
11357 X(_sxtb, b240, fa4ff080), \
11358 X(_sxth, b200, fa0ff080), \
11359 X(_tst, 4200, ea100f00), \
11360 X(_uxtb, b2c0, fa5ff080), \
11361 X(_uxth, b280, fa1ff080), \
11362 X(_nop, bf00, f3af8000), \
11363 X(_yield, bf10, f3af8001), \
11364 X(_wfe, bf20, f3af8002), \
11365 X(_wfi, bf30, f3af8003), \
60f993ce 11366 X(_wls, 0000, f040c001), \
1f6234a3 11367 X(_wlstp, 0000, f000c001), \
53c4b28b 11368 X(_sev, bf40, f3af8004), \
74db7efb
NC
11369 X(_sevl, bf50, f3af8005), \
11370 X(_udf, de00, f7f0a000)
c19d1205
ZW
11371
11372/* To catch errors in encoding functions, the codes are all offset by
11373 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11374 as 16-bit instructions. */
21d799b5 11375#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11376enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11377#undef X
11378
11379#define X(a,b,c) 0x##b
11380static const unsigned short thumb_op16[] = { T16_32_TAB };
11381#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11382#undef X
11383
11384#define X(a,b,c) 0x##c
11385static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11386#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11387#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11388#undef X
11389#undef T16_32_TAB
11390
11391/* Thumb instruction encoders, in alphabetical order. */
11392
92e90b6e 11393/* ADDW or SUBW. */
c921be7d 11394
92e90b6e
PB
11395static void
11396do_t_add_sub_w (void)
11397{
11398 int Rd, Rn;
11399
11400 Rd = inst.operands[0].reg;
11401 Rn = inst.operands[1].reg;
11402
539d4391
NC
11403 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11404 is the SP-{plus,minus}-immediate form of the instruction. */
11405 if (Rn == REG_SP)
11406 constraint (Rd == REG_PC, BAD_PC);
11407 else
11408 reject_bad_reg (Rd);
fdfde340 11409
92e90b6e 11410 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11411 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11412}
11413
c19d1205 11414/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11415 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11416
11417static void
11418do_t_add_sub (void)
11419{
11420 int Rd, Rs, Rn;
11421
11422 Rd = inst.operands[0].reg;
11423 Rs = (inst.operands[1].present
11424 ? inst.operands[1].reg /* Rd, Rs, foo */
11425 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11426
e07e6e58 11427 if (Rd == REG_PC)
5ee91343 11428 set_pred_insn_type_last ();
e07e6e58 11429
c19d1205
ZW
11430 if (unified_syntax)
11431 {
0110f2b8
PB
11432 bfd_boolean flags;
11433 bfd_boolean narrow;
11434 int opcode;
11435
11436 flags = (inst.instruction == T_MNEM_adds
11437 || inst.instruction == T_MNEM_subs);
11438 if (flags)
5ee91343 11439 narrow = !in_pred_block ();
0110f2b8 11440 else
5ee91343 11441 narrow = in_pred_block ();
c19d1205 11442 if (!inst.operands[2].isreg)
b99bd4ef 11443 {
16805f35
PB
11444 int add;
11445
5c8ed6a4
JW
11446 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11447 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11448
16805f35
PB
11449 add = (inst.instruction == T_MNEM_add
11450 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11451 opcode = 0;
11452 if (inst.size_req != 4)
11453 {
0110f2b8 11454 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11455 appropriate. */
0110f2b8
PB
11456 if (Rd == REG_SP && Rs == REG_SP && !flags)
11457 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11458 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11459 opcode = T_MNEM_add_sp;
11460 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11461 opcode = T_MNEM_add_pc;
11462 else if (Rd <= 7 && Rs <= 7 && narrow)
11463 {
11464 if (flags)
11465 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11466 else
11467 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11468 }
11469 if (opcode)
11470 {
11471 inst.instruction = THUMB_OP16(opcode);
11472 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11473 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11474 || (inst.relocs[0].type
11475 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11476 {
11477 if (inst.size_req == 2)
e2b0ab59 11478 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11479 else
11480 inst.relax = opcode;
11481 }
0110f2b8
PB
11482 }
11483 else
11484 constraint (inst.size_req == 2, BAD_HIREG);
11485 }
11486 if (inst.size_req == 4
11487 || (inst.size_req != 2 && !opcode))
11488 {
e2b0ab59
AV
11489 constraint ((inst.relocs[0].type
11490 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11491 && (inst.relocs[0].type
11492 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11493 THUMB1_RELOC_ONLY);
efd81785
PB
11494 if (Rd == REG_PC)
11495 {
fdfde340 11496 constraint (add, BAD_PC);
efd81785
PB
11497 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11498 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11499 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11500 _("expression too complex"));
e2b0ab59
AV
11501 constraint (inst.relocs[0].exp.X_add_number < 0
11502 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11503 _("immediate value out of range"));
11504 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11505 | inst.relocs[0].exp.X_add_number;
11506 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11507 return;
11508 }
11509 else if (Rs == REG_PC)
16805f35
PB
11510 {
11511 /* Always use addw/subw. */
11512 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11513 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11514 }
11515 else
11516 {
11517 inst.instruction = THUMB_OP32 (inst.instruction);
11518 inst.instruction = (inst.instruction & 0xe1ffffff)
11519 | 0x10000000;
11520 if (flags)
e2b0ab59 11521 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11522 else
e2b0ab59 11523 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11524 }
dc4503c6
PB
11525 inst.instruction |= Rd << 8;
11526 inst.instruction |= Rs << 16;
0110f2b8 11527 }
b99bd4ef 11528 }
c19d1205
ZW
11529 else
11530 {
e2b0ab59 11531 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11532 unsigned int shift = inst.operands[2].shift_kind;
11533
c19d1205
ZW
11534 Rn = inst.operands[2].reg;
11535 /* See if we can do this with a 16-bit instruction. */
11536 if (!inst.operands[2].shifted && inst.size_req != 4)
11537 {
e27ec89e
PB
11538 if (Rd > 7 || Rs > 7 || Rn > 7)
11539 narrow = FALSE;
11540
11541 if (narrow)
c19d1205 11542 {
e27ec89e
PB
11543 inst.instruction = ((inst.instruction == T_MNEM_adds
11544 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11545 ? T_OPCODE_ADD_R3
11546 : T_OPCODE_SUB_R3);
11547 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11548 return;
11549 }
b99bd4ef 11550
7e806470 11551 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11552 {
7e806470
PB
11553 /* Thumb-1 cores (except v6-M) require at least one high
11554 register in a narrow non flag setting add. */
11555 if (Rd > 7 || Rn > 7
11556 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11557 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11558 {
7e806470
PB
11559 if (Rd == Rn)
11560 {
11561 Rn = Rs;
11562 Rs = Rd;
11563 }
c19d1205
ZW
11564 inst.instruction = T_OPCODE_ADD_HI;
11565 inst.instruction |= (Rd & 8) << 4;
11566 inst.instruction |= (Rd & 7);
11567 inst.instruction |= Rn << 3;
11568 return;
11569 }
c19d1205
ZW
11570 }
11571 }
c921be7d 11572
fdfde340 11573 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11574 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11575 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11576 constraint (Rs == REG_PC, BAD_PC);
11577 reject_bad_reg (Rn);
11578
c19d1205
ZW
11579 /* If we get here, it can't be done in 16 bits. */
11580 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11581 _("shift must be constant"));
11582 inst.instruction = THUMB_OP32 (inst.instruction);
11583 inst.instruction |= Rd << 8;
11584 inst.instruction |= Rs << 16;
5f4cb198
NC
11585 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11586 _("shift value over 3 not allowed in thumb mode"));
11587 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11588 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11589 encode_thumb32_shifted_operand (2);
11590 }
11591 }
11592 else
11593 {
11594 constraint (inst.instruction == T_MNEM_adds
11595 || inst.instruction == T_MNEM_subs,
11596 BAD_THUMB32);
b99bd4ef 11597
c19d1205 11598 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11599 {
c19d1205
ZW
11600 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11601 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11602 BAD_HIREG);
11603
11604 inst.instruction = (inst.instruction == T_MNEM_add
11605 ? 0x0000 : 0x8000);
11606 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11607 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11608 return;
11609 }
11610
c19d1205
ZW
11611 Rn = inst.operands[2].reg;
11612 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11613
c19d1205
ZW
11614 /* We now have Rd, Rs, and Rn set to registers. */
11615 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11616 {
c19d1205
ZW
11617 /* Can't do this for SUB. */
11618 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11619 inst.instruction = T_OPCODE_ADD_HI;
11620 inst.instruction |= (Rd & 8) << 4;
11621 inst.instruction |= (Rd & 7);
11622 if (Rs == Rd)
11623 inst.instruction |= Rn << 3;
11624 else if (Rn == Rd)
11625 inst.instruction |= Rs << 3;
11626 else
11627 constraint (1, _("dest must overlap one source register"));
11628 }
11629 else
11630 {
11631 inst.instruction = (inst.instruction == T_MNEM_add
11632 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11633 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11634 }
b99bd4ef 11635 }
b99bd4ef
NC
11636}
11637
c19d1205
ZW
11638static void
11639do_t_adr (void)
11640{
fdfde340
JM
11641 unsigned Rd;
11642
11643 Rd = inst.operands[0].reg;
11644 reject_bad_reg (Rd);
11645
11646 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11647 {
11648 /* Defer to section relaxation. */
11649 inst.relax = inst.instruction;
11650 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11651 inst.instruction |= Rd << 4;
0110f2b8
PB
11652 }
11653 else if (unified_syntax && inst.size_req != 2)
e9f89963 11654 {
0110f2b8 11655 /* Generate a 32-bit opcode. */
e9f89963 11656 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11657 inst.instruction |= Rd << 8;
e2b0ab59
AV
11658 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11659 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11660 }
11661 else
11662 {
0110f2b8 11663 /* Generate a 16-bit opcode. */
e9f89963 11664 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11665 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11666 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11667 inst.relocs[0].pc_rel = 1;
fdfde340 11668 inst.instruction |= Rd << 4;
e9f89963 11669 }
52a86f84 11670
e2b0ab59
AV
11671 if (inst.relocs[0].exp.X_op == O_symbol
11672 && inst.relocs[0].exp.X_add_symbol != NULL
11673 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11674 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11675 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11676}
b99bd4ef 11677
c19d1205
ZW
11678/* Arithmetic instructions for which there is just one 16-bit
11679 instruction encoding, and it allows only two low registers.
11680 For maximal compatibility with ARM syntax, we allow three register
11681 operands even when Thumb-32 instructions are not available, as long
11682 as the first two are identical. For instance, both "sbc r0,r1" and
11683 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11684static void
c19d1205 11685do_t_arit3 (void)
b99bd4ef 11686{
c19d1205 11687 int Rd, Rs, Rn;
b99bd4ef 11688
c19d1205
ZW
11689 Rd = inst.operands[0].reg;
11690 Rs = (inst.operands[1].present
11691 ? inst.operands[1].reg /* Rd, Rs, foo */
11692 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11693 Rn = inst.operands[2].reg;
b99bd4ef 11694
fdfde340
JM
11695 reject_bad_reg (Rd);
11696 reject_bad_reg (Rs);
11697 if (inst.operands[2].isreg)
11698 reject_bad_reg (Rn);
11699
c19d1205 11700 if (unified_syntax)
b99bd4ef 11701 {
c19d1205
ZW
11702 if (!inst.operands[2].isreg)
11703 {
11704 /* For an immediate, we always generate a 32-bit opcode;
11705 section relaxation will shrink it later if possible. */
11706 inst.instruction = THUMB_OP32 (inst.instruction);
11707 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11708 inst.instruction |= Rd << 8;
11709 inst.instruction |= Rs << 16;
e2b0ab59 11710 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11711 }
11712 else
11713 {
e27ec89e
PB
11714 bfd_boolean narrow;
11715
c19d1205 11716 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11717 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11718 narrow = !in_pred_block ();
e27ec89e 11719 else
5ee91343 11720 narrow = in_pred_block ();
e27ec89e
PB
11721
11722 if (Rd > 7 || Rn > 7 || Rs > 7)
11723 narrow = FALSE;
11724 if (inst.operands[2].shifted)
11725 narrow = FALSE;
11726 if (inst.size_req == 4)
11727 narrow = FALSE;
11728
11729 if (narrow
c19d1205
ZW
11730 && Rd == Rs)
11731 {
11732 inst.instruction = THUMB_OP16 (inst.instruction);
11733 inst.instruction |= Rd;
11734 inst.instruction |= Rn << 3;
11735 return;
11736 }
b99bd4ef 11737
c19d1205
ZW
11738 /* If we get here, it can't be done in 16 bits. */
11739 constraint (inst.operands[2].shifted
11740 && inst.operands[2].immisreg,
11741 _("shift must be constant"));
11742 inst.instruction = THUMB_OP32 (inst.instruction);
11743 inst.instruction |= Rd << 8;
11744 inst.instruction |= Rs << 16;
11745 encode_thumb32_shifted_operand (2);
11746 }
a737bd4d 11747 }
c19d1205 11748 else
b99bd4ef 11749 {
c19d1205
ZW
11750 /* On its face this is a lie - the instruction does set the
11751 flags. However, the only supported mnemonic in this mode
11752 says it doesn't. */
11753 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11754
c19d1205
ZW
11755 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11756 _("unshifted register required"));
11757 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11758 constraint (Rd != Rs,
11759 _("dest and source1 must be the same register"));
a737bd4d 11760
c19d1205
ZW
11761 inst.instruction = THUMB_OP16 (inst.instruction);
11762 inst.instruction |= Rd;
11763 inst.instruction |= Rn << 3;
b99bd4ef 11764 }
a737bd4d 11765}
b99bd4ef 11766
c19d1205
ZW
11767/* Similarly, but for instructions where the arithmetic operation is
11768 commutative, so we can allow either of them to be different from
11769 the destination operand in a 16-bit instruction. For instance, all
11770 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11771 accepted. */
11772static void
11773do_t_arit3c (void)
a737bd4d 11774{
c19d1205 11775 int Rd, Rs, Rn;
b99bd4ef 11776
c19d1205
ZW
11777 Rd = inst.operands[0].reg;
11778 Rs = (inst.operands[1].present
11779 ? inst.operands[1].reg /* Rd, Rs, foo */
11780 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11781 Rn = inst.operands[2].reg;
c921be7d 11782
fdfde340
JM
11783 reject_bad_reg (Rd);
11784 reject_bad_reg (Rs);
11785 if (inst.operands[2].isreg)
11786 reject_bad_reg (Rn);
a737bd4d 11787
c19d1205 11788 if (unified_syntax)
a737bd4d 11789 {
c19d1205 11790 if (!inst.operands[2].isreg)
b99bd4ef 11791 {
c19d1205
ZW
11792 /* For an immediate, we always generate a 32-bit opcode;
11793 section relaxation will shrink it later if possible. */
11794 inst.instruction = THUMB_OP32 (inst.instruction);
11795 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11796 inst.instruction |= Rd << 8;
11797 inst.instruction |= Rs << 16;
e2b0ab59 11798 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11799 }
c19d1205 11800 else
a737bd4d 11801 {
e27ec89e
PB
11802 bfd_boolean narrow;
11803
c19d1205 11804 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11805 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11806 narrow = !in_pred_block ();
e27ec89e 11807 else
5ee91343 11808 narrow = in_pred_block ();
e27ec89e
PB
11809
11810 if (Rd > 7 || Rn > 7 || Rs > 7)
11811 narrow = FALSE;
11812 if (inst.operands[2].shifted)
11813 narrow = FALSE;
11814 if (inst.size_req == 4)
11815 narrow = FALSE;
11816
11817 if (narrow)
a737bd4d 11818 {
c19d1205 11819 if (Rd == Rs)
a737bd4d 11820 {
c19d1205
ZW
11821 inst.instruction = THUMB_OP16 (inst.instruction);
11822 inst.instruction |= Rd;
11823 inst.instruction |= Rn << 3;
11824 return;
a737bd4d 11825 }
c19d1205 11826 if (Rd == Rn)
a737bd4d 11827 {
c19d1205
ZW
11828 inst.instruction = THUMB_OP16 (inst.instruction);
11829 inst.instruction |= Rd;
11830 inst.instruction |= Rs << 3;
11831 return;
a737bd4d
NC
11832 }
11833 }
c19d1205
ZW
11834
11835 /* If we get here, it can't be done in 16 bits. */
11836 constraint (inst.operands[2].shifted
11837 && inst.operands[2].immisreg,
11838 _("shift must be constant"));
11839 inst.instruction = THUMB_OP32 (inst.instruction);
11840 inst.instruction |= Rd << 8;
11841 inst.instruction |= Rs << 16;
11842 encode_thumb32_shifted_operand (2);
a737bd4d 11843 }
b99bd4ef 11844 }
c19d1205
ZW
11845 else
11846 {
11847 /* On its face this is a lie - the instruction does set the
11848 flags. However, the only supported mnemonic in this mode
11849 says it doesn't. */
11850 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11851
c19d1205
ZW
11852 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11853 _("unshifted register required"));
11854 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11855
11856 inst.instruction = THUMB_OP16 (inst.instruction);
11857 inst.instruction |= Rd;
11858
11859 if (Rd == Rs)
11860 inst.instruction |= Rn << 3;
11861 else if (Rd == Rn)
11862 inst.instruction |= Rs << 3;
11863 else
11864 constraint (1, _("dest must overlap one source register"));
11865 }
a737bd4d
NC
11866}
11867
c19d1205
ZW
11868static void
11869do_t_bfc (void)
a737bd4d 11870{
fdfde340 11871 unsigned Rd;
c19d1205
ZW
11872 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11873 constraint (msb > 32, _("bit-field extends past end of register"));
11874 /* The instruction encoding stores the LSB and MSB,
11875 not the LSB and width. */
fdfde340
JM
11876 Rd = inst.operands[0].reg;
11877 reject_bad_reg (Rd);
11878 inst.instruction |= Rd << 8;
c19d1205
ZW
11879 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11880 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11881 inst.instruction |= msb - 1;
b99bd4ef
NC
11882}
11883
c19d1205
ZW
11884static void
11885do_t_bfi (void)
b99bd4ef 11886{
fdfde340 11887 int Rd, Rn;
c19d1205 11888 unsigned int msb;
b99bd4ef 11889
fdfde340
JM
11890 Rd = inst.operands[0].reg;
11891 reject_bad_reg (Rd);
11892
c19d1205
ZW
11893 /* #0 in second position is alternative syntax for bfc, which is
11894 the same instruction but with REG_PC in the Rm field. */
11895 if (!inst.operands[1].isreg)
fdfde340
JM
11896 Rn = REG_PC;
11897 else
11898 {
11899 Rn = inst.operands[1].reg;
11900 reject_bad_reg (Rn);
11901 }
b99bd4ef 11902
c19d1205
ZW
11903 msb = inst.operands[2].imm + inst.operands[3].imm;
11904 constraint (msb > 32, _("bit-field extends past end of register"));
11905 /* The instruction encoding stores the LSB and MSB,
11906 not the LSB and width. */
fdfde340
JM
11907 inst.instruction |= Rd << 8;
11908 inst.instruction |= Rn << 16;
c19d1205
ZW
11909 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11910 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11911 inst.instruction |= msb - 1;
b99bd4ef
NC
11912}
11913
c19d1205
ZW
11914static void
11915do_t_bfx (void)
b99bd4ef 11916{
fdfde340
JM
11917 unsigned Rd, Rn;
11918
11919 Rd = inst.operands[0].reg;
11920 Rn = inst.operands[1].reg;
11921
11922 reject_bad_reg (Rd);
11923 reject_bad_reg (Rn);
11924
c19d1205
ZW
11925 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11926 _("bit-field extends past end of register"));
fdfde340
JM
11927 inst.instruction |= Rd << 8;
11928 inst.instruction |= Rn << 16;
c19d1205
ZW
11929 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11930 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11931 inst.instruction |= inst.operands[3].imm - 1;
11932}
b99bd4ef 11933
c19d1205
ZW
11934/* ARM V5 Thumb BLX (argument parse)
11935 BLX <target_addr> which is BLX(1)
11936 BLX <Rm> which is BLX(2)
11937 Unfortunately, there are two different opcodes for this mnemonic.
11938 So, the insns[].value is not used, and the code here zaps values
11939 into inst.instruction.
b99bd4ef 11940
c19d1205
ZW
11941 ??? How to take advantage of the additional two bits of displacement
11942 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11943
c19d1205
ZW
11944static void
11945do_t_blx (void)
11946{
5ee91343 11947 set_pred_insn_type_last ();
e07e6e58 11948
c19d1205 11949 if (inst.operands[0].isreg)
fdfde340
JM
11950 {
11951 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11952 /* We have a register, so this is BLX(2). */
11953 inst.instruction |= inst.operands[0].reg << 3;
11954 }
b99bd4ef
NC
11955 else
11956 {
c19d1205 11957 /* No register. This must be BLX(1). */
2fc8bdac 11958 inst.instruction = 0xf000e800;
0855e32b 11959 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11960 }
11961}
11962
c19d1205
ZW
11963static void
11964do_t_branch (void)
b99bd4ef 11965{
0110f2b8 11966 int opcode;
dfa9f0d5 11967 int cond;
2fe88214 11968 bfd_reloc_code_real_type reloc;
dfa9f0d5 11969
e07e6e58 11970 cond = inst.cond;
5ee91343 11971 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 11972
5ee91343 11973 if (in_pred_block ())
dfa9f0d5
PB
11974 {
11975 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11976 branches. */
dfa9f0d5 11977 cond = COND_ALWAYS;
dfa9f0d5
PB
11978 }
11979 else
11980 cond = inst.cond;
11981
11982 if (cond != COND_ALWAYS)
0110f2b8
PB
11983 opcode = T_MNEM_bcond;
11984 else
11985 opcode = inst.instruction;
11986
12d6b0b7
RS
11987 if (unified_syntax
11988 && (inst.size_req == 4
10960bfb
PB
11989 || (inst.size_req != 2
11990 && (inst.operands[0].hasreloc
e2b0ab59 11991 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 11992 {
0110f2b8 11993 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11994 if (cond == COND_ALWAYS)
9ae92b05 11995 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11996 else
11997 {
ff8646ee
TP
11998 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11999 _("selected architecture does not support "
12000 "wide conditional branch instruction"));
12001
9c2799c2 12002 gas_assert (cond != 0xF);
dfa9f0d5 12003 inst.instruction |= cond << 22;
9ae92b05 12004 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12005 }
12006 }
b99bd4ef
NC
12007 else
12008 {
0110f2b8 12009 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12010 if (cond == COND_ALWAYS)
9ae92b05 12011 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12012 else
b99bd4ef 12013 {
dfa9f0d5 12014 inst.instruction |= cond << 8;
9ae92b05 12015 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12016 }
0110f2b8
PB
12017 /* Allow section relaxation. */
12018 if (unified_syntax && inst.size_req != 2)
12019 inst.relax = opcode;
b99bd4ef 12020 }
e2b0ab59
AV
12021 inst.relocs[0].type = reloc;
12022 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12023}
12024
8884b720 12025/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12026 between the two is the maximum immediate allowed - which is passed in
8884b720 12027 RANGE. */
b99bd4ef 12028static void
8884b720 12029do_t_bkpt_hlt1 (int range)
b99bd4ef 12030{
dfa9f0d5
PB
12031 constraint (inst.cond != COND_ALWAYS,
12032 _("instruction is always unconditional"));
c19d1205 12033 if (inst.operands[0].present)
b99bd4ef 12034 {
8884b720 12035 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12036 _("immediate value out of range"));
12037 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12038 }
8884b720 12039
5ee91343 12040 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12041}
12042
12043static void
12044do_t_hlt (void)
12045{
12046 do_t_bkpt_hlt1 (63);
12047}
12048
12049static void
12050do_t_bkpt (void)
12051{
12052 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12053}
12054
12055static void
c19d1205 12056do_t_branch23 (void)
b99bd4ef 12057{
5ee91343 12058 set_pred_insn_type_last ();
0855e32b 12059 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12060
0855e32b
NS
12061 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12062 this file. We used to simply ignore the PLT reloc type here --
12063 the branch encoding is now needed to deal with TLSCALL relocs.
12064 So if we see a PLT reloc now, put it back to how it used to be to
12065 keep the preexisting behaviour. */
e2b0ab59
AV
12066 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12067 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12068
4343666d 12069#if defined(OBJ_COFF)
c19d1205
ZW
12070 /* If the destination of the branch is a defined symbol which does not have
12071 the THUMB_FUNC attribute, then we must be calling a function which has
12072 the (interfacearm) attribute. We look for the Thumb entry point to that
12073 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12074 if ( inst.relocs[0].exp.X_op == O_symbol
12075 && inst.relocs[0].exp.X_add_symbol != NULL
12076 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12077 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12078 inst.relocs[0].exp.X_add_symbol
12079 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12080#endif
90e4755a
RE
12081}
12082
12083static void
c19d1205 12084do_t_bx (void)
90e4755a 12085{
5ee91343 12086 set_pred_insn_type_last ();
c19d1205
ZW
12087 inst.instruction |= inst.operands[0].reg << 3;
12088 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12089 should cause the alignment to be checked once it is known. This is
12090 because BX PC only works if the instruction is word aligned. */
12091}
90e4755a 12092
c19d1205
ZW
12093static void
12094do_t_bxj (void)
12095{
fdfde340 12096 int Rm;
90e4755a 12097
5ee91343 12098 set_pred_insn_type_last ();
fdfde340
JM
12099 Rm = inst.operands[0].reg;
12100 reject_bad_reg (Rm);
12101 inst.instruction |= Rm << 16;
90e4755a
RE
12102}
12103
12104static void
c19d1205 12105do_t_clz (void)
90e4755a 12106{
fdfde340
JM
12107 unsigned Rd;
12108 unsigned Rm;
12109
12110 Rd = inst.operands[0].reg;
12111 Rm = inst.operands[1].reg;
12112
12113 reject_bad_reg (Rd);
12114 reject_bad_reg (Rm);
12115
12116 inst.instruction |= Rd << 8;
12117 inst.instruction |= Rm << 16;
12118 inst.instruction |= Rm;
c19d1205 12119}
90e4755a 12120
e39c1607
SD
12121/* For the Armv8.1-M conditional instructions. */
12122static void
12123do_t_cond (void)
12124{
12125 unsigned Rd, Rn, Rm;
12126 signed int cond;
12127
12128 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12129
12130 Rd = inst.operands[0].reg;
12131 switch (inst.instruction)
12132 {
12133 case T_MNEM_csinc:
12134 case T_MNEM_csinv:
12135 case T_MNEM_csneg:
12136 case T_MNEM_csel:
12137 Rn = inst.operands[1].reg;
12138 Rm = inst.operands[2].reg;
12139 cond = inst.operands[3].imm;
12140 constraint (Rn == REG_SP, BAD_SP);
12141 constraint (Rm == REG_SP, BAD_SP);
12142 break;
12143
12144 case T_MNEM_cinc:
12145 case T_MNEM_cinv:
12146 case T_MNEM_cneg:
12147 Rn = inst.operands[1].reg;
12148 cond = inst.operands[2].imm;
12149 /* Invert the last bit to invert the cond. */
12150 cond = TOGGLE_BIT (cond, 0);
12151 constraint (Rn == REG_SP, BAD_SP);
12152 Rm = Rn;
12153 break;
12154
12155 case T_MNEM_csetm:
12156 case T_MNEM_cset:
12157 cond = inst.operands[1].imm;
12158 /* Invert the last bit to invert the cond. */
12159 cond = TOGGLE_BIT (cond, 0);
12160 Rn = REG_PC;
12161 Rm = REG_PC;
12162 break;
12163
12164 default: abort ();
12165 }
12166
12167 set_pred_insn_type (OUTSIDE_PRED_INSN);
12168 inst.instruction = THUMB_OP32 (inst.instruction);
12169 inst.instruction |= Rd << 8;
12170 inst.instruction |= Rn << 16;
12171 inst.instruction |= Rm;
12172 inst.instruction |= cond << 4;
12173}
12174
91d8b670
JG
12175static void
12176do_t_csdb (void)
12177{
5ee91343 12178 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12179}
12180
dfa9f0d5
PB
12181static void
12182do_t_cps (void)
12183{
5ee91343 12184 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12185 inst.instruction |= inst.operands[0].imm;
12186}
12187
c19d1205
ZW
12188static void
12189do_t_cpsi (void)
12190{
5ee91343 12191 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12192 if (unified_syntax
62b3e311
PB
12193 && (inst.operands[1].present || inst.size_req == 4)
12194 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12195 {
c19d1205
ZW
12196 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12197 inst.instruction = 0xf3af8000;
12198 inst.instruction |= imod << 9;
12199 inst.instruction |= inst.operands[0].imm << 5;
12200 if (inst.operands[1].present)
12201 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12202 }
c19d1205 12203 else
90e4755a 12204 {
62b3e311
PB
12205 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12206 && (inst.operands[0].imm & 4),
12207 _("selected processor does not support 'A' form "
12208 "of this instruction"));
12209 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12210 _("Thumb does not support the 2-argument "
12211 "form of this instruction"));
12212 inst.instruction |= inst.operands[0].imm;
90e4755a 12213 }
90e4755a
RE
12214}
12215
c19d1205
ZW
12216/* THUMB CPY instruction (argument parse). */
12217
90e4755a 12218static void
c19d1205 12219do_t_cpy (void)
90e4755a 12220{
c19d1205 12221 if (inst.size_req == 4)
90e4755a 12222 {
c19d1205
ZW
12223 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12224 inst.instruction |= inst.operands[0].reg << 8;
12225 inst.instruction |= inst.operands[1].reg;
90e4755a 12226 }
c19d1205 12227 else
90e4755a 12228 {
c19d1205
ZW
12229 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12230 inst.instruction |= (inst.operands[0].reg & 0x7);
12231 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12232 }
90e4755a
RE
12233}
12234
90e4755a 12235static void
25fe350b 12236do_t_cbz (void)
90e4755a 12237{
5ee91343 12238 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12239 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12240 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12241 inst.relocs[0].pc_rel = 1;
12242 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12243}
90e4755a 12244
62b3e311
PB
12245static void
12246do_t_dbg (void)
12247{
12248 inst.instruction |= inst.operands[0].imm;
12249}
12250
12251static void
12252do_t_div (void)
12253{
fdfde340
JM
12254 unsigned Rd, Rn, Rm;
12255
12256 Rd = inst.operands[0].reg;
12257 Rn = (inst.operands[1].present
12258 ? inst.operands[1].reg : Rd);
12259 Rm = inst.operands[2].reg;
12260
12261 reject_bad_reg (Rd);
12262 reject_bad_reg (Rn);
12263 reject_bad_reg (Rm);
12264
12265 inst.instruction |= Rd << 8;
12266 inst.instruction |= Rn << 16;
12267 inst.instruction |= Rm;
62b3e311
PB
12268}
12269
c19d1205
ZW
12270static void
12271do_t_hint (void)
12272{
12273 if (unified_syntax && inst.size_req == 4)
12274 inst.instruction = THUMB_OP32 (inst.instruction);
12275 else
12276 inst.instruction = THUMB_OP16 (inst.instruction);
12277}
90e4755a 12278
c19d1205
ZW
12279static void
12280do_t_it (void)
12281{
12282 unsigned int cond = inst.operands[0].imm;
e27ec89e 12283
5ee91343
AV
12284 set_pred_insn_type (IT_INSN);
12285 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12286 now_pred.cc = cond;
12287 now_pred.warn_deprecated = FALSE;
12288 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12289
12290 /* If the condition is a negative condition, invert the mask. */
c19d1205 12291 if ((cond & 0x1) == 0x0)
90e4755a 12292 {
c19d1205 12293 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12294
c19d1205 12295 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12296 {
12297 /* No conversion needed. */
5ee91343 12298 now_pred.block_length = 1;
5a01bb1d 12299 }
c19d1205 12300 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12301 {
12302 mask ^= 0x8;
5ee91343 12303 now_pred.block_length = 2;
5a01bb1d 12304 }
e27ec89e 12305 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12306 {
12307 mask ^= 0xC;
5ee91343 12308 now_pred.block_length = 3;
5a01bb1d 12309 }
c19d1205 12310 else
5a01bb1d
MGD
12311 {
12312 mask ^= 0xE;
5ee91343 12313 now_pred.block_length = 4;
5a01bb1d 12314 }
90e4755a 12315
e27ec89e
PB
12316 inst.instruction &= 0xfff0;
12317 inst.instruction |= mask;
c19d1205 12318 }
90e4755a 12319
c19d1205
ZW
12320 inst.instruction |= cond << 4;
12321}
90e4755a 12322
3c707909
PB
12323/* Helper function used for both push/pop and ldm/stm. */
12324static void
4b5a202f
AV
12325encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12326 bfd_boolean writeback)
3c707909 12327{
4b5a202f 12328 bfd_boolean load, store;
3c707909 12329
4b5a202f
AV
12330 gas_assert (base != -1 || !do_io);
12331 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12332 store = do_io && !load;
3c707909
PB
12333
12334 if (mask & (1 << 13))
12335 inst.error = _("SP not allowed in register list");
1e5b0379 12336
4b5a202f 12337 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12338 && writeback)
12339 inst.error = _("having the base register in the register list when "
12340 "using write back is UNPREDICTABLE");
12341
3c707909
PB
12342 if (load)
12343 {
e07e6e58 12344 if (mask & (1 << 15))
477330fc
RM
12345 {
12346 if (mask & (1 << 14))
12347 inst.error = _("LR and PC should not both be in register list");
12348 else
5ee91343 12349 set_pred_insn_type_last ();
477330fc 12350 }
3c707909 12351 }
4b5a202f 12352 else if (store)
3c707909
PB
12353 {
12354 if (mask & (1 << 15))
12355 inst.error = _("PC not allowed in register list");
3c707909
PB
12356 }
12357
4b5a202f 12358 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12359 {
12360 /* Single register transfers implemented as str/ldr. */
12361 if (writeback)
12362 {
12363 if (inst.instruction & (1 << 23))
12364 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12365 else
12366 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12367 }
12368 else
12369 {
12370 if (inst.instruction & (1 << 23))
12371 inst.instruction = 0x00800000; /* ia -> [base] */
12372 else
12373 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12374 }
12375
12376 inst.instruction |= 0xf8400000;
12377 if (load)
12378 inst.instruction |= 0x00100000;
12379
5f4273c7 12380 mask = ffs (mask) - 1;
3c707909
PB
12381 mask <<= 12;
12382 }
12383 else if (writeback)
12384 inst.instruction |= WRITE_BACK;
12385
12386 inst.instruction |= mask;
4b5a202f
AV
12387 if (do_io)
12388 inst.instruction |= base << 16;
3c707909
PB
12389}
12390
c19d1205
ZW
12391static void
12392do_t_ldmstm (void)
12393{
12394 /* This really doesn't seem worth it. */
e2b0ab59 12395 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12396 _("expression too complex"));
12397 constraint (inst.operands[1].writeback,
12398 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12399
c19d1205
ZW
12400 if (unified_syntax)
12401 {
3c707909
PB
12402 bfd_boolean narrow;
12403 unsigned mask;
12404
12405 narrow = FALSE;
c19d1205
ZW
12406 /* See if we can use a 16-bit instruction. */
12407 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12408 && inst.size_req != 4
3c707909 12409 && !(inst.operands[1].imm & ~0xff))
90e4755a 12410 {
3c707909 12411 mask = 1 << inst.operands[0].reg;
90e4755a 12412
eab4f823 12413 if (inst.operands[0].reg <= 7)
90e4755a 12414 {
3c707909 12415 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12416 ? inst.operands[0].writeback
12417 : (inst.operands[0].writeback
12418 == !(inst.operands[1].imm & mask)))
477330fc 12419 {
eab4f823
MGD
12420 if (inst.instruction == T_MNEM_stmia
12421 && (inst.operands[1].imm & mask)
12422 && (inst.operands[1].imm & (mask - 1)))
12423 as_warn (_("value stored for r%d is UNKNOWN"),
12424 inst.operands[0].reg);
3c707909 12425
eab4f823
MGD
12426 inst.instruction = THUMB_OP16 (inst.instruction);
12427 inst.instruction |= inst.operands[0].reg << 8;
12428 inst.instruction |= inst.operands[1].imm;
12429 narrow = TRUE;
12430 }
12431 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12432 {
12433 /* This means 1 register in reg list one of 3 situations:
12434 1. Instruction is stmia, but without writeback.
12435 2. lmdia without writeback, but with Rn not in
477330fc 12436 reglist.
eab4f823
MGD
12437 3. ldmia with writeback, but with Rn in reglist.
12438 Case 3 is UNPREDICTABLE behaviour, so we handle
12439 case 1 and 2 which can be converted into a 16-bit
12440 str or ldr. The SP cases are handled below. */
12441 unsigned long opcode;
12442 /* First, record an error for Case 3. */
12443 if (inst.operands[1].imm & mask
12444 && inst.operands[0].writeback)
fa94de6b 12445 inst.error =
eab4f823
MGD
12446 _("having the base register in the register list when "
12447 "using write back is UNPREDICTABLE");
fa94de6b
RM
12448
12449 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12450 : T_MNEM_ldr);
12451 inst.instruction = THUMB_OP16 (opcode);
12452 inst.instruction |= inst.operands[0].reg << 3;
12453 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12454 narrow = TRUE;
12455 }
90e4755a 12456 }
eab4f823 12457 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12458 {
eab4f823
MGD
12459 if (inst.operands[0].writeback)
12460 {
fa94de6b 12461 inst.instruction =
eab4f823 12462 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12463 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12464 inst.instruction |= inst.operands[1].imm;
477330fc 12465 narrow = TRUE;
eab4f823
MGD
12466 }
12467 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12468 {
fa94de6b 12469 inst.instruction =
eab4f823 12470 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12471 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12472 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12473 narrow = TRUE;
eab4f823 12474 }
90e4755a 12475 }
3c707909
PB
12476 }
12477
12478 if (!narrow)
12479 {
c19d1205
ZW
12480 if (inst.instruction < 0xffff)
12481 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12482
4b5a202f
AV
12483 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12484 inst.operands[1].imm,
12485 inst.operands[0].writeback);
90e4755a
RE
12486 }
12487 }
c19d1205 12488 else
90e4755a 12489 {
c19d1205
ZW
12490 constraint (inst.operands[0].reg > 7
12491 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12492 constraint (inst.instruction != T_MNEM_ldmia
12493 && inst.instruction != T_MNEM_stmia,
12494 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12495 if (inst.instruction == T_MNEM_stmia)
f03698e6 12496 {
c19d1205
ZW
12497 if (!inst.operands[0].writeback)
12498 as_warn (_("this instruction will write back the base register"));
12499 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12500 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12501 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12502 inst.operands[0].reg);
f03698e6 12503 }
c19d1205 12504 else
90e4755a 12505 {
c19d1205
ZW
12506 if (!inst.operands[0].writeback
12507 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12508 as_warn (_("this instruction will write back the base register"));
12509 else if (inst.operands[0].writeback
12510 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12511 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12512 }
12513
c19d1205
ZW
12514 inst.instruction = THUMB_OP16 (inst.instruction);
12515 inst.instruction |= inst.operands[0].reg << 8;
12516 inst.instruction |= inst.operands[1].imm;
12517 }
12518}
e28cd48c 12519
c19d1205
ZW
12520static void
12521do_t_ldrex (void)
12522{
12523 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12524 || inst.operands[1].postind || inst.operands[1].writeback
12525 || inst.operands[1].immisreg || inst.operands[1].shifted
12526 || inst.operands[1].negative,
01cfc07f 12527 BAD_ADDR_MODE);
e28cd48c 12528
5be8be5d
DG
12529 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12530
c19d1205
ZW
12531 inst.instruction |= inst.operands[0].reg << 12;
12532 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12533 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12534}
e28cd48c 12535
c19d1205
ZW
12536static void
12537do_t_ldrexd (void)
12538{
12539 if (!inst.operands[1].present)
1cac9012 12540 {
c19d1205
ZW
12541 constraint (inst.operands[0].reg == REG_LR,
12542 _("r14 not allowed as first register "
12543 "when second register is omitted"));
12544 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12545 }
c19d1205
ZW
12546 constraint (inst.operands[0].reg == inst.operands[1].reg,
12547 BAD_OVERLAP);
b99bd4ef 12548
c19d1205
ZW
12549 inst.instruction |= inst.operands[0].reg << 12;
12550 inst.instruction |= inst.operands[1].reg << 8;
12551 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12552}
12553
12554static void
c19d1205 12555do_t_ldst (void)
b99bd4ef 12556{
0110f2b8
PB
12557 unsigned long opcode;
12558 int Rn;
12559
e07e6e58
NC
12560 if (inst.operands[0].isreg
12561 && !inst.operands[0].preind
12562 && inst.operands[0].reg == REG_PC)
5ee91343 12563 set_pred_insn_type_last ();
e07e6e58 12564
0110f2b8 12565 opcode = inst.instruction;
c19d1205 12566 if (unified_syntax)
b99bd4ef 12567 {
53365c0d
PB
12568 if (!inst.operands[1].isreg)
12569 {
12570 if (opcode <= 0xffff)
12571 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12572 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12573 return;
12574 }
0110f2b8
PB
12575 if (inst.operands[1].isreg
12576 && !inst.operands[1].writeback
c19d1205
ZW
12577 && !inst.operands[1].shifted && !inst.operands[1].postind
12578 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12579 && opcode <= 0xffff
12580 && inst.size_req != 4)
c19d1205 12581 {
0110f2b8
PB
12582 /* Insn may have a 16-bit form. */
12583 Rn = inst.operands[1].reg;
12584 if (inst.operands[1].immisreg)
12585 {
12586 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12587 /* [Rn, Rik] */
0110f2b8
PB
12588 if (Rn <= 7 && inst.operands[1].imm <= 7)
12589 goto op16;
5be8be5d
DG
12590 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12591 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12592 }
12593 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12594 && opcode != T_MNEM_ldrsb)
12595 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12596 || (Rn == REG_SP && opcode == T_MNEM_str))
12597 {
12598 /* [Rn, #const] */
12599 if (Rn > 7)
12600 {
12601 if (Rn == REG_PC)
12602 {
e2b0ab59 12603 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12604 opcode = T_MNEM_ldr_pc2;
12605 else
12606 opcode = T_MNEM_ldr_pc;
12607 }
12608 else
12609 {
12610 if (opcode == T_MNEM_ldr)
12611 opcode = T_MNEM_ldr_sp;
12612 else
12613 opcode = T_MNEM_str_sp;
12614 }
12615 inst.instruction = inst.operands[0].reg << 8;
12616 }
12617 else
12618 {
12619 inst.instruction = inst.operands[0].reg;
12620 inst.instruction |= inst.operands[1].reg << 3;
12621 }
12622 inst.instruction |= THUMB_OP16 (opcode);
12623 if (inst.size_req == 2)
e2b0ab59 12624 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12625 else
12626 inst.relax = opcode;
12627 return;
12628 }
c19d1205 12629 }
0110f2b8 12630 /* Definitely a 32-bit variant. */
5be8be5d 12631
8d67f500
NC
12632 /* Warning for Erratum 752419. */
12633 if (opcode == T_MNEM_ldr
12634 && inst.operands[0].reg == REG_SP
12635 && inst.operands[1].writeback == 1
12636 && !inst.operands[1].immisreg)
12637 {
12638 if (no_cpu_selected ()
12639 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12640 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12641 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12642 as_warn (_("This instruction may be unpredictable "
12643 "if executed on M-profile cores "
12644 "with interrupts enabled."));
12645 }
12646
5be8be5d 12647 /* Do some validations regarding addressing modes. */
1be5fd2e 12648 if (inst.operands[1].immisreg)
5be8be5d
DG
12649 reject_bad_reg (inst.operands[1].imm);
12650
1be5fd2e
NC
12651 constraint (inst.operands[1].writeback == 1
12652 && inst.operands[0].reg == inst.operands[1].reg,
12653 BAD_OVERLAP);
12654
0110f2b8 12655 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12656 inst.instruction |= inst.operands[0].reg << 12;
12657 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12658 check_ldr_r15_aligned ();
b99bd4ef
NC
12659 return;
12660 }
12661
c19d1205
ZW
12662 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12663
12664 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12665 {
c19d1205
ZW
12666 /* Only [Rn,Rm] is acceptable. */
12667 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12668 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12669 || inst.operands[1].postind || inst.operands[1].shifted
12670 || inst.operands[1].negative,
12671 _("Thumb does not support this addressing mode"));
12672 inst.instruction = THUMB_OP16 (inst.instruction);
12673 goto op16;
b99bd4ef 12674 }
5f4273c7 12675
c19d1205
ZW
12676 inst.instruction = THUMB_OP16 (inst.instruction);
12677 if (!inst.operands[1].isreg)
8335d6aa 12678 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12679 return;
b99bd4ef 12680
c19d1205
ZW
12681 constraint (!inst.operands[1].preind
12682 || inst.operands[1].shifted
12683 || inst.operands[1].writeback,
12684 _("Thumb does not support this addressing mode"));
12685 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12686 {
c19d1205
ZW
12687 constraint (inst.instruction & 0x0600,
12688 _("byte or halfword not valid for base register"));
12689 constraint (inst.operands[1].reg == REG_PC
12690 && !(inst.instruction & THUMB_LOAD_BIT),
12691 _("r15 based store not allowed"));
12692 constraint (inst.operands[1].immisreg,
12693 _("invalid base register for register offset"));
b99bd4ef 12694
c19d1205
ZW
12695 if (inst.operands[1].reg == REG_PC)
12696 inst.instruction = T_OPCODE_LDR_PC;
12697 else if (inst.instruction & THUMB_LOAD_BIT)
12698 inst.instruction = T_OPCODE_LDR_SP;
12699 else
12700 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12701
c19d1205 12702 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12703 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12704 return;
12705 }
90e4755a 12706
c19d1205
ZW
12707 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12708 if (!inst.operands[1].immisreg)
12709 {
12710 /* Immediate offset. */
12711 inst.instruction |= inst.operands[0].reg;
12712 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12713 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12714 return;
12715 }
90e4755a 12716
c19d1205
ZW
12717 /* Register offset. */
12718 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12719 constraint (inst.operands[1].negative,
12720 _("Thumb does not support this addressing mode"));
90e4755a 12721
c19d1205
ZW
12722 op16:
12723 switch (inst.instruction)
12724 {
12725 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12726 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12727 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12728 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12729 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12730 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12731 case 0x5600 /* ldrsb */:
12732 case 0x5e00 /* ldrsh */: break;
12733 default: abort ();
12734 }
90e4755a 12735
c19d1205
ZW
12736 inst.instruction |= inst.operands[0].reg;
12737 inst.instruction |= inst.operands[1].reg << 3;
12738 inst.instruction |= inst.operands[1].imm << 6;
12739}
90e4755a 12740
c19d1205
ZW
12741static void
12742do_t_ldstd (void)
12743{
12744 if (!inst.operands[1].present)
b99bd4ef 12745 {
c19d1205
ZW
12746 inst.operands[1].reg = inst.operands[0].reg + 1;
12747 constraint (inst.operands[0].reg == REG_LR,
12748 _("r14 not allowed here"));
bd340a04 12749 constraint (inst.operands[0].reg == REG_R12,
477330fc 12750 _("r12 not allowed here"));
b99bd4ef 12751 }
bd340a04
MGD
12752
12753 if (inst.operands[2].writeback
12754 && (inst.operands[0].reg == inst.operands[2].reg
12755 || inst.operands[1].reg == inst.operands[2].reg))
12756 as_warn (_("base register written back, and overlaps "
477330fc 12757 "one of transfer registers"));
bd340a04 12758
c19d1205
ZW
12759 inst.instruction |= inst.operands[0].reg << 12;
12760 inst.instruction |= inst.operands[1].reg << 8;
12761 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12762}
12763
c19d1205
ZW
12764static void
12765do_t_ldstt (void)
12766{
12767 inst.instruction |= inst.operands[0].reg << 12;
12768 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12769}
a737bd4d 12770
b99bd4ef 12771static void
c19d1205 12772do_t_mla (void)
b99bd4ef 12773{
fdfde340 12774 unsigned Rd, Rn, Rm, Ra;
c921be7d 12775
fdfde340
JM
12776 Rd = inst.operands[0].reg;
12777 Rn = inst.operands[1].reg;
12778 Rm = inst.operands[2].reg;
12779 Ra = inst.operands[3].reg;
12780
12781 reject_bad_reg (Rd);
12782 reject_bad_reg (Rn);
12783 reject_bad_reg (Rm);
12784 reject_bad_reg (Ra);
12785
12786 inst.instruction |= Rd << 8;
12787 inst.instruction |= Rn << 16;
12788 inst.instruction |= Rm;
12789 inst.instruction |= Ra << 12;
c19d1205 12790}
b99bd4ef 12791
c19d1205
ZW
12792static void
12793do_t_mlal (void)
12794{
fdfde340
JM
12795 unsigned RdLo, RdHi, Rn, Rm;
12796
12797 RdLo = inst.operands[0].reg;
12798 RdHi = inst.operands[1].reg;
12799 Rn = inst.operands[2].reg;
12800 Rm = inst.operands[3].reg;
12801
12802 reject_bad_reg (RdLo);
12803 reject_bad_reg (RdHi);
12804 reject_bad_reg (Rn);
12805 reject_bad_reg (Rm);
12806
12807 inst.instruction |= RdLo << 12;
12808 inst.instruction |= RdHi << 8;
12809 inst.instruction |= Rn << 16;
12810 inst.instruction |= Rm;
c19d1205 12811}
b99bd4ef 12812
c19d1205
ZW
12813static void
12814do_t_mov_cmp (void)
12815{
fdfde340
JM
12816 unsigned Rn, Rm;
12817
12818 Rn = inst.operands[0].reg;
12819 Rm = inst.operands[1].reg;
12820
e07e6e58 12821 if (Rn == REG_PC)
5ee91343 12822 set_pred_insn_type_last ();
e07e6e58 12823
c19d1205 12824 if (unified_syntax)
b99bd4ef 12825 {
c19d1205
ZW
12826 int r0off = (inst.instruction == T_MNEM_mov
12827 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12828 unsigned long opcode;
3d388997
PB
12829 bfd_boolean narrow;
12830 bfd_boolean low_regs;
12831
fdfde340 12832 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12833 opcode = inst.instruction;
5ee91343 12834 if (in_pred_block ())
0110f2b8 12835 narrow = opcode != T_MNEM_movs;
3d388997 12836 else
0110f2b8 12837 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12838 if (inst.size_req == 4
12839 || inst.operands[1].shifted)
12840 narrow = FALSE;
12841
efd81785
PB
12842 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12843 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12844 && !inst.operands[1].shifted
fdfde340
JM
12845 && Rn == REG_PC
12846 && Rm == REG_LR)
efd81785
PB
12847 {
12848 inst.instruction = T2_SUBS_PC_LR;
12849 return;
12850 }
12851
fdfde340
JM
12852 if (opcode == T_MNEM_cmp)
12853 {
12854 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12855 if (narrow)
12856 {
12857 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12858 but valid. */
12859 warn_deprecated_sp (Rm);
12860 /* R15 was documented as a valid choice for Rm in ARMv6,
12861 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12862 tools reject R15, so we do too. */
12863 constraint (Rm == REG_PC, BAD_PC);
12864 }
12865 else
12866 reject_bad_reg (Rm);
fdfde340
JM
12867 }
12868 else if (opcode == T_MNEM_mov
12869 || opcode == T_MNEM_movs)
12870 {
12871 if (inst.operands[1].isreg)
12872 {
12873 if (opcode == T_MNEM_movs)
12874 {
12875 reject_bad_reg (Rn);
12876 reject_bad_reg (Rm);
12877 }
76fa04a4
MGD
12878 else if (narrow)
12879 {
12880 /* This is mov.n. */
12881 if ((Rn == REG_SP || Rn == REG_PC)
12882 && (Rm == REG_SP || Rm == REG_PC))
12883 {
5c3696f8 12884 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12885 "deprecated when r%u is the destination "
12886 "register."), Rm, Rn);
12887 }
12888 }
12889 else
12890 {
12891 /* This is mov.w. */
12892 constraint (Rn == REG_PC, BAD_PC);
12893 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12894 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12895 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12896 }
fdfde340
JM
12897 }
12898 else
12899 reject_bad_reg (Rn);
12900 }
12901
c19d1205
ZW
12902 if (!inst.operands[1].isreg)
12903 {
0110f2b8 12904 /* Immediate operand. */
5ee91343 12905 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12906 narrow = 0;
12907 if (low_regs && narrow)
12908 {
12909 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12910 inst.instruction |= Rn << 8;
e2b0ab59
AV
12911 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12912 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12913 {
a9f02af8 12914 if (inst.size_req == 2)
e2b0ab59 12915 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12916 else
12917 inst.relax = opcode;
72d98d16 12918 }
0110f2b8
PB
12919 }
12920 else
12921 {
e2b0ab59
AV
12922 constraint ((inst.relocs[0].type
12923 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12924 && (inst.relocs[0].type
12925 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
12926 THUMB1_RELOC_ONLY);
12927
0110f2b8
PB
12928 inst.instruction = THUMB_OP32 (inst.instruction);
12929 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12930 inst.instruction |= Rn << r0off;
e2b0ab59 12931 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 12932 }
c19d1205 12933 }
728ca7c9
PB
12934 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12935 && (inst.instruction == T_MNEM_mov
12936 || inst.instruction == T_MNEM_movs))
12937 {
12938 /* Register shifts are encoded as separate shift instructions. */
12939 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12940
5ee91343 12941 if (in_pred_block ())
728ca7c9
PB
12942 narrow = !flags;
12943 else
12944 narrow = flags;
12945
12946 if (inst.size_req == 4)
12947 narrow = FALSE;
12948
12949 if (!low_regs || inst.operands[1].imm > 7)
12950 narrow = FALSE;
12951
fdfde340 12952 if (Rn != Rm)
728ca7c9
PB
12953 narrow = FALSE;
12954
12955 switch (inst.operands[1].shift_kind)
12956 {
12957 case SHIFT_LSL:
12958 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12959 break;
12960 case SHIFT_ASR:
12961 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12962 break;
12963 case SHIFT_LSR:
12964 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12965 break;
12966 case SHIFT_ROR:
12967 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12968 break;
12969 default:
5f4273c7 12970 abort ();
728ca7c9
PB
12971 }
12972
12973 inst.instruction = opcode;
12974 if (narrow)
12975 {
fdfde340 12976 inst.instruction |= Rn;
728ca7c9
PB
12977 inst.instruction |= inst.operands[1].imm << 3;
12978 }
12979 else
12980 {
12981 if (flags)
12982 inst.instruction |= CONDS_BIT;
12983
fdfde340
JM
12984 inst.instruction |= Rn << 8;
12985 inst.instruction |= Rm << 16;
728ca7c9
PB
12986 inst.instruction |= inst.operands[1].imm;
12987 }
12988 }
3d388997 12989 else if (!narrow)
c19d1205 12990 {
728ca7c9
PB
12991 /* Some mov with immediate shift have narrow variants.
12992 Register shifts are handled above. */
12993 if (low_regs && inst.operands[1].shifted
12994 && (inst.instruction == T_MNEM_mov
12995 || inst.instruction == T_MNEM_movs))
12996 {
5ee91343 12997 if (in_pred_block ())
728ca7c9
PB
12998 narrow = (inst.instruction == T_MNEM_mov);
12999 else
13000 narrow = (inst.instruction == T_MNEM_movs);
13001 }
13002
13003 if (narrow)
13004 {
13005 switch (inst.operands[1].shift_kind)
13006 {
13007 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13008 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13009 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13010 default: narrow = FALSE; break;
13011 }
13012 }
13013
13014 if (narrow)
13015 {
fdfde340
JM
13016 inst.instruction |= Rn;
13017 inst.instruction |= Rm << 3;
e2b0ab59 13018 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13019 }
13020 else
13021 {
13022 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13023 inst.instruction |= Rn << r0off;
728ca7c9
PB
13024 encode_thumb32_shifted_operand (1);
13025 }
c19d1205
ZW
13026 }
13027 else
13028 switch (inst.instruction)
13029 {
13030 case T_MNEM_mov:
837b3435 13031 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13032 results. Don't allow this. */
13033 if (low_regs)
13034 {
13035 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13036 "MOV Rd, Rs with two low registers is not "
13037 "permitted on this architecture");
fa94de6b 13038 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13039 arm_ext_v6);
13040 }
13041
c19d1205 13042 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13043 inst.instruction |= (Rn & 0x8) << 4;
13044 inst.instruction |= (Rn & 0x7);
13045 inst.instruction |= Rm << 3;
c19d1205 13046 break;
b99bd4ef 13047
c19d1205
ZW
13048 case T_MNEM_movs:
13049 /* We know we have low registers at this point.
941a8a52
MGD
13050 Generate LSLS Rd, Rs, #0. */
13051 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13052 inst.instruction |= Rn;
13053 inst.instruction |= Rm << 3;
c19d1205
ZW
13054 break;
13055
13056 case T_MNEM_cmp:
3d388997 13057 if (low_regs)
c19d1205
ZW
13058 {
13059 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13060 inst.instruction |= Rn;
13061 inst.instruction |= Rm << 3;
c19d1205
ZW
13062 }
13063 else
13064 {
13065 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13066 inst.instruction |= (Rn & 0x8) << 4;
13067 inst.instruction |= (Rn & 0x7);
13068 inst.instruction |= Rm << 3;
c19d1205
ZW
13069 }
13070 break;
13071 }
b99bd4ef
NC
13072 return;
13073 }
13074
c19d1205 13075 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13076
13077 /* PR 10443: Do not silently ignore shifted operands. */
13078 constraint (inst.operands[1].shifted,
13079 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13080
c19d1205 13081 if (inst.operands[1].isreg)
b99bd4ef 13082 {
fdfde340 13083 if (Rn < 8 && Rm < 8)
b99bd4ef 13084 {
c19d1205
ZW
13085 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13086 since a MOV instruction produces unpredictable results. */
13087 if (inst.instruction == T_OPCODE_MOV_I8)
13088 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13089 else
c19d1205 13090 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13091
fdfde340
JM
13092 inst.instruction |= Rn;
13093 inst.instruction |= Rm << 3;
b99bd4ef
NC
13094 }
13095 else
13096 {
c19d1205
ZW
13097 if (inst.instruction == T_OPCODE_MOV_I8)
13098 inst.instruction = T_OPCODE_MOV_HR;
13099 else
13100 inst.instruction = T_OPCODE_CMP_HR;
13101 do_t_cpy ();
b99bd4ef
NC
13102 }
13103 }
c19d1205 13104 else
b99bd4ef 13105 {
fdfde340 13106 constraint (Rn > 7,
c19d1205 13107 _("only lo regs allowed with immediate"));
fdfde340 13108 inst.instruction |= Rn << 8;
e2b0ab59 13109 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13110 }
13111}
b99bd4ef 13112
c19d1205
ZW
13113static void
13114do_t_mov16 (void)
13115{
fdfde340 13116 unsigned Rd;
b6895b4f
PB
13117 bfd_vma imm;
13118 bfd_boolean top;
13119
13120 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13121 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13122 {
33eaf5de 13123 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13124 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13125 }
e2b0ab59 13126 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13127 {
33eaf5de 13128 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13129 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13130 }
13131
fdfde340
JM
13132 Rd = inst.operands[0].reg;
13133 reject_bad_reg (Rd);
13134
13135 inst.instruction |= Rd << 8;
e2b0ab59 13136 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13137 {
e2b0ab59 13138 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13139 inst.instruction |= (imm & 0xf000) << 4;
13140 inst.instruction |= (imm & 0x0800) << 15;
13141 inst.instruction |= (imm & 0x0700) << 4;
13142 inst.instruction |= (imm & 0x00ff);
13143 }
c19d1205 13144}
b99bd4ef 13145
c19d1205
ZW
13146static void
13147do_t_mvn_tst (void)
13148{
fdfde340 13149 unsigned Rn, Rm;
c921be7d 13150
fdfde340
JM
13151 Rn = inst.operands[0].reg;
13152 Rm = inst.operands[1].reg;
13153
13154 if (inst.instruction == T_MNEM_cmp
13155 || inst.instruction == T_MNEM_cmn)
13156 constraint (Rn == REG_PC, BAD_PC);
13157 else
13158 reject_bad_reg (Rn);
13159 reject_bad_reg (Rm);
13160
c19d1205
ZW
13161 if (unified_syntax)
13162 {
13163 int r0off = (inst.instruction == T_MNEM_mvn
13164 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13165 bfd_boolean narrow;
13166
13167 if (inst.size_req == 4
13168 || inst.instruction > 0xffff
13169 || inst.operands[1].shifted
fdfde340 13170 || Rn > 7 || Rm > 7)
3d388997 13171 narrow = FALSE;
fe8b4cc3
KT
13172 else if (inst.instruction == T_MNEM_cmn
13173 || inst.instruction == T_MNEM_tst)
3d388997
PB
13174 narrow = TRUE;
13175 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13176 narrow = !in_pred_block ();
3d388997 13177 else
5ee91343 13178 narrow = in_pred_block ();
3d388997 13179
c19d1205 13180 if (!inst.operands[1].isreg)
b99bd4ef 13181 {
c19d1205
ZW
13182 /* For an immediate, we always generate a 32-bit opcode;
13183 section relaxation will shrink it later if possible. */
13184 if (inst.instruction < 0xffff)
13185 inst.instruction = THUMB_OP32 (inst.instruction);
13186 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13187 inst.instruction |= Rn << r0off;
e2b0ab59 13188 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13189 }
c19d1205 13190 else
b99bd4ef 13191 {
c19d1205 13192 /* See if we can do this with a 16-bit instruction. */
3d388997 13193 if (narrow)
b99bd4ef 13194 {
c19d1205 13195 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13196 inst.instruction |= Rn;
13197 inst.instruction |= Rm << 3;
b99bd4ef 13198 }
c19d1205 13199 else
b99bd4ef 13200 {
c19d1205
ZW
13201 constraint (inst.operands[1].shifted
13202 && inst.operands[1].immisreg,
13203 _("shift must be constant"));
13204 if (inst.instruction < 0xffff)
13205 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13206 inst.instruction |= Rn << r0off;
c19d1205 13207 encode_thumb32_shifted_operand (1);
b99bd4ef 13208 }
b99bd4ef
NC
13209 }
13210 }
13211 else
13212 {
c19d1205
ZW
13213 constraint (inst.instruction > 0xffff
13214 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13215 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13216 _("unshifted register required"));
fdfde340 13217 constraint (Rn > 7 || Rm > 7,
c19d1205 13218 BAD_HIREG);
b99bd4ef 13219
c19d1205 13220 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13221 inst.instruction |= Rn;
13222 inst.instruction |= Rm << 3;
b99bd4ef 13223 }
b99bd4ef
NC
13224}
13225
b05fe5cf 13226static void
c19d1205 13227do_t_mrs (void)
b05fe5cf 13228{
fdfde340 13229 unsigned Rd;
037e8744
JB
13230
13231 if (do_vfp_nsyn_mrs () == SUCCESS)
13232 return;
13233
90ec0d68
MGD
13234 Rd = inst.operands[0].reg;
13235 reject_bad_reg (Rd);
13236 inst.instruction |= Rd << 8;
13237
13238 if (inst.operands[1].isreg)
62b3e311 13239 {
90ec0d68
MGD
13240 unsigned br = inst.operands[1].reg;
13241 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13242 as_bad (_("bad register for mrs"));
13243
13244 inst.instruction |= br & (0xf << 16);
13245 inst.instruction |= (br & 0x300) >> 4;
13246 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13247 }
13248 else
13249 {
90ec0d68 13250 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13251
d2cd1205 13252 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13253 {
13254 /* PR gas/12698: The constraint is only applied for m_profile.
13255 If the user has specified -march=all, we want to ignore it as
13256 we are building for any CPU type, including non-m variants. */
823d2571
TG
13257 bfd_boolean m_profile =
13258 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13259 constraint ((flags != 0) && m_profile, _("selected processor does "
13260 "not support requested special purpose register"));
13261 }
90ec0d68 13262 else
d2cd1205
JB
13263 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13264 devices). */
13265 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13266 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13267
90ec0d68
MGD
13268 inst.instruction |= (flags & SPSR_BIT) >> 2;
13269 inst.instruction |= inst.operands[1].imm & 0xff;
13270 inst.instruction |= 0xf0000;
13271 }
c19d1205 13272}
b05fe5cf 13273
c19d1205
ZW
13274static void
13275do_t_msr (void)
13276{
62b3e311 13277 int flags;
fdfde340 13278 unsigned Rn;
62b3e311 13279
037e8744
JB
13280 if (do_vfp_nsyn_msr () == SUCCESS)
13281 return;
13282
c19d1205
ZW
13283 constraint (!inst.operands[1].isreg,
13284 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13285
13286 if (inst.operands[0].isreg)
13287 flags = (int)(inst.operands[0].reg);
13288 else
13289 flags = inst.operands[0].imm;
13290
d2cd1205 13291 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13292 {
d2cd1205
JB
13293 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13294
1a43faaf 13295 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13296 If the user has specified -march=all, we want to ignore it as
13297 we are building for any CPU type, including non-m variants. */
823d2571
TG
13298 bfd_boolean m_profile =
13299 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13300 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13301 && (bits & ~(PSR_s | PSR_f)) != 0)
13302 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13303 && bits != PSR_f)) && m_profile,
13304 _("selected processor does not support requested special "
13305 "purpose register"));
62b3e311
PB
13306 }
13307 else
d2cd1205
JB
13308 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13309 "requested special purpose register"));
c921be7d 13310
fdfde340
JM
13311 Rn = inst.operands[1].reg;
13312 reject_bad_reg (Rn);
13313
62b3e311 13314 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13315 inst.instruction |= (flags & 0xf0000) >> 8;
13316 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13317 inst.instruction |= (flags & 0xff);
fdfde340 13318 inst.instruction |= Rn << 16;
c19d1205 13319}
b05fe5cf 13320
c19d1205
ZW
13321static void
13322do_t_mul (void)
13323{
17828f45 13324 bfd_boolean narrow;
fdfde340 13325 unsigned Rd, Rn, Rm;
17828f45 13326
c19d1205
ZW
13327 if (!inst.operands[2].present)
13328 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13329
fdfde340
JM
13330 Rd = inst.operands[0].reg;
13331 Rn = inst.operands[1].reg;
13332 Rm = inst.operands[2].reg;
13333
17828f45 13334 if (unified_syntax)
b05fe5cf 13335 {
17828f45 13336 if (inst.size_req == 4
fdfde340
JM
13337 || (Rd != Rn
13338 && Rd != Rm)
13339 || Rn > 7
13340 || Rm > 7)
17828f45
JM
13341 narrow = FALSE;
13342 else if (inst.instruction == T_MNEM_muls)
5ee91343 13343 narrow = !in_pred_block ();
17828f45 13344 else
5ee91343 13345 narrow = in_pred_block ();
b05fe5cf 13346 }
c19d1205 13347 else
b05fe5cf 13348 {
17828f45 13349 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13350 constraint (Rn > 7 || Rm > 7,
c19d1205 13351 BAD_HIREG);
17828f45
JM
13352 narrow = TRUE;
13353 }
b05fe5cf 13354
17828f45
JM
13355 if (narrow)
13356 {
13357 /* 16-bit MULS/Conditional MUL. */
c19d1205 13358 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13359 inst.instruction |= Rd;
b05fe5cf 13360
fdfde340
JM
13361 if (Rd == Rn)
13362 inst.instruction |= Rm << 3;
13363 else if (Rd == Rm)
13364 inst.instruction |= Rn << 3;
c19d1205
ZW
13365 else
13366 constraint (1, _("dest must overlap one source register"));
13367 }
17828f45
JM
13368 else
13369 {
e07e6e58
NC
13370 constraint (inst.instruction != T_MNEM_mul,
13371 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13372 /* 32-bit MUL. */
13373 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13374 inst.instruction |= Rd << 8;
13375 inst.instruction |= Rn << 16;
13376 inst.instruction |= Rm << 0;
13377
13378 reject_bad_reg (Rd);
13379 reject_bad_reg (Rn);
13380 reject_bad_reg (Rm);
17828f45 13381 }
c19d1205 13382}
b05fe5cf 13383
c19d1205
ZW
13384static void
13385do_t_mull (void)
13386{
fdfde340 13387 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13388
fdfde340
JM
13389 RdLo = inst.operands[0].reg;
13390 RdHi = inst.operands[1].reg;
13391 Rn = inst.operands[2].reg;
13392 Rm = inst.operands[3].reg;
13393
13394 reject_bad_reg (RdLo);
13395 reject_bad_reg (RdHi);
13396 reject_bad_reg (Rn);
13397 reject_bad_reg (Rm);
13398
13399 inst.instruction |= RdLo << 12;
13400 inst.instruction |= RdHi << 8;
13401 inst.instruction |= Rn << 16;
13402 inst.instruction |= Rm;
13403
13404 if (RdLo == RdHi)
c19d1205
ZW
13405 as_tsktsk (_("rdhi and rdlo must be different"));
13406}
b05fe5cf 13407
c19d1205
ZW
13408static void
13409do_t_nop (void)
13410{
5ee91343 13411 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13412
c19d1205
ZW
13413 if (unified_syntax)
13414 {
13415 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13416 {
c19d1205
ZW
13417 inst.instruction = THUMB_OP32 (inst.instruction);
13418 inst.instruction |= inst.operands[0].imm;
13419 }
13420 else
13421 {
bc2d1808
NC
13422 /* PR9722: Check for Thumb2 availability before
13423 generating a thumb2 nop instruction. */
afa62d5e 13424 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13425 {
13426 inst.instruction = THUMB_OP16 (inst.instruction);
13427 inst.instruction |= inst.operands[0].imm << 4;
13428 }
13429 else
13430 inst.instruction = 0x46c0;
c19d1205
ZW
13431 }
13432 }
13433 else
13434 {
13435 constraint (inst.operands[0].present,
13436 _("Thumb does not support NOP with hints"));
13437 inst.instruction = 0x46c0;
13438 }
13439}
b05fe5cf 13440
c19d1205
ZW
13441static void
13442do_t_neg (void)
13443{
13444 if (unified_syntax)
13445 {
3d388997
PB
13446 bfd_boolean narrow;
13447
13448 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13449 narrow = !in_pred_block ();
3d388997 13450 else
5ee91343 13451 narrow = in_pred_block ();
3d388997
PB
13452 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13453 narrow = FALSE;
13454 if (inst.size_req == 4)
13455 narrow = FALSE;
13456
13457 if (!narrow)
c19d1205
ZW
13458 {
13459 inst.instruction = THUMB_OP32 (inst.instruction);
13460 inst.instruction |= inst.operands[0].reg << 8;
13461 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13462 }
13463 else
13464 {
c19d1205
ZW
13465 inst.instruction = THUMB_OP16 (inst.instruction);
13466 inst.instruction |= inst.operands[0].reg;
13467 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13468 }
13469 }
13470 else
13471 {
c19d1205
ZW
13472 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13473 BAD_HIREG);
13474 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13475
13476 inst.instruction = THUMB_OP16 (inst.instruction);
13477 inst.instruction |= inst.operands[0].reg;
13478 inst.instruction |= inst.operands[1].reg << 3;
13479 }
13480}
13481
1c444d06
JM
13482static void
13483do_t_orn (void)
13484{
13485 unsigned Rd, Rn;
13486
13487 Rd = inst.operands[0].reg;
13488 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13489
fdfde340
JM
13490 reject_bad_reg (Rd);
13491 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13492 reject_bad_reg (Rn);
13493
1c444d06
JM
13494 inst.instruction |= Rd << 8;
13495 inst.instruction |= Rn << 16;
13496
13497 if (!inst.operands[2].isreg)
13498 {
13499 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13500 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13501 }
13502 else
13503 {
13504 unsigned Rm;
13505
13506 Rm = inst.operands[2].reg;
fdfde340 13507 reject_bad_reg (Rm);
1c444d06
JM
13508
13509 constraint (inst.operands[2].shifted
13510 && inst.operands[2].immisreg,
13511 _("shift must be constant"));
13512 encode_thumb32_shifted_operand (2);
13513 }
13514}
13515
c19d1205
ZW
13516static void
13517do_t_pkhbt (void)
13518{
fdfde340
JM
13519 unsigned Rd, Rn, Rm;
13520
13521 Rd = inst.operands[0].reg;
13522 Rn = inst.operands[1].reg;
13523 Rm = inst.operands[2].reg;
13524
13525 reject_bad_reg (Rd);
13526 reject_bad_reg (Rn);
13527 reject_bad_reg (Rm);
13528
13529 inst.instruction |= Rd << 8;
13530 inst.instruction |= Rn << 16;
13531 inst.instruction |= Rm;
c19d1205
ZW
13532 if (inst.operands[3].present)
13533 {
e2b0ab59
AV
13534 unsigned int val = inst.relocs[0].exp.X_add_number;
13535 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13536 _("expression too complex"));
13537 inst.instruction |= (val & 0x1c) << 10;
13538 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13539 }
c19d1205 13540}
b05fe5cf 13541
c19d1205
ZW
13542static void
13543do_t_pkhtb (void)
13544{
13545 if (!inst.operands[3].present)
1ef52f49
NC
13546 {
13547 unsigned Rtmp;
13548
13549 inst.instruction &= ~0x00000020;
13550
13551 /* PR 10168. Swap the Rm and Rn registers. */
13552 Rtmp = inst.operands[1].reg;
13553 inst.operands[1].reg = inst.operands[2].reg;
13554 inst.operands[2].reg = Rtmp;
13555 }
c19d1205 13556 do_t_pkhbt ();
b05fe5cf
ZW
13557}
13558
c19d1205
ZW
13559static void
13560do_t_pld (void)
13561{
fdfde340
JM
13562 if (inst.operands[0].immisreg)
13563 reject_bad_reg (inst.operands[0].imm);
13564
c19d1205
ZW
13565 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13566}
b05fe5cf 13567
c19d1205
ZW
13568static void
13569do_t_push_pop (void)
b99bd4ef 13570{
e9f89963 13571 unsigned mask;
5f4273c7 13572
c19d1205
ZW
13573 constraint (inst.operands[0].writeback,
13574 _("push/pop do not support {reglist}^"));
e2b0ab59 13575 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13576 _("expression too complex"));
b99bd4ef 13577
e9f89963 13578 mask = inst.operands[0].imm;
d3bfe16e 13579 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13580 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13581 else if (inst.size_req != 4
c6025a80 13582 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13583 ? REG_LR : REG_PC)))
b99bd4ef 13584 {
c19d1205
ZW
13585 inst.instruction = THUMB_OP16 (inst.instruction);
13586 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13587 inst.instruction |= mask & 0xff;
c19d1205
ZW
13588 }
13589 else if (unified_syntax)
13590 {
3c707909 13591 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13592 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13593 }
13594 else
13595 {
13596 inst.error = _("invalid register list to push/pop instruction");
13597 return;
c19d1205 13598 }
4b5a202f
AV
13599}
13600
13601static void
13602do_t_clrm (void)
13603{
13604 if (unified_syntax)
13605 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13606 else
13607 {
13608 inst.error = _("invalid register list to push/pop instruction");
13609 return;
13610 }
c19d1205 13611}
b99bd4ef 13612
efd6b359
AV
13613static void
13614do_t_vscclrm (void)
13615{
13616 if (inst.operands[0].issingle)
13617 {
13618 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13619 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13620 inst.instruction |= inst.operands[0].imm;
13621 }
13622 else
13623 {
13624 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13625 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13626 inst.instruction |= 1 << 8;
13627 inst.instruction |= inst.operands[0].imm << 1;
13628 }
13629}
13630
c19d1205
ZW
13631static void
13632do_t_rbit (void)
13633{
fdfde340
JM
13634 unsigned Rd, Rm;
13635
13636 Rd = inst.operands[0].reg;
13637 Rm = inst.operands[1].reg;
13638
13639 reject_bad_reg (Rd);
13640 reject_bad_reg (Rm);
13641
13642 inst.instruction |= Rd << 8;
13643 inst.instruction |= Rm << 16;
13644 inst.instruction |= Rm;
c19d1205 13645}
b99bd4ef 13646
c19d1205
ZW
13647static void
13648do_t_rev (void)
13649{
fdfde340
JM
13650 unsigned Rd, Rm;
13651
13652 Rd = inst.operands[0].reg;
13653 Rm = inst.operands[1].reg;
13654
13655 reject_bad_reg (Rd);
13656 reject_bad_reg (Rm);
13657
13658 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13659 && inst.size_req != 4)
13660 {
13661 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13662 inst.instruction |= Rd;
13663 inst.instruction |= Rm << 3;
c19d1205
ZW
13664 }
13665 else if (unified_syntax)
13666 {
13667 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13668 inst.instruction |= Rd << 8;
13669 inst.instruction |= Rm << 16;
13670 inst.instruction |= Rm;
c19d1205
ZW
13671 }
13672 else
13673 inst.error = BAD_HIREG;
13674}
b99bd4ef 13675
1c444d06
JM
13676static void
13677do_t_rrx (void)
13678{
13679 unsigned Rd, Rm;
13680
13681 Rd = inst.operands[0].reg;
13682 Rm = inst.operands[1].reg;
13683
fdfde340
JM
13684 reject_bad_reg (Rd);
13685 reject_bad_reg (Rm);
c921be7d 13686
1c444d06
JM
13687 inst.instruction |= Rd << 8;
13688 inst.instruction |= Rm;
13689}
13690
c19d1205
ZW
13691static void
13692do_t_rsb (void)
13693{
fdfde340 13694 unsigned Rd, Rs;
b99bd4ef 13695
c19d1205
ZW
13696 Rd = inst.operands[0].reg;
13697 Rs = (inst.operands[1].present
13698 ? inst.operands[1].reg /* Rd, Rs, foo */
13699 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13700
fdfde340
JM
13701 reject_bad_reg (Rd);
13702 reject_bad_reg (Rs);
13703 if (inst.operands[2].isreg)
13704 reject_bad_reg (inst.operands[2].reg);
13705
c19d1205
ZW
13706 inst.instruction |= Rd << 8;
13707 inst.instruction |= Rs << 16;
13708 if (!inst.operands[2].isreg)
13709 {
026d3abb
PB
13710 bfd_boolean narrow;
13711
13712 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13713 narrow = !in_pred_block ();
026d3abb 13714 else
5ee91343 13715 narrow = in_pred_block ();
026d3abb
PB
13716
13717 if (Rd > 7 || Rs > 7)
13718 narrow = FALSE;
13719
13720 if (inst.size_req == 4 || !unified_syntax)
13721 narrow = FALSE;
13722
e2b0ab59
AV
13723 if (inst.relocs[0].exp.X_op != O_constant
13724 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13725 narrow = FALSE;
13726
13727 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13728 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13729 if (narrow)
13730 {
e2b0ab59 13731 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13732 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13733 inst.instruction |= Rs << 3;
13734 inst.instruction |= Rd;
13735 }
13736 else
13737 {
13738 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13739 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13740 }
c19d1205
ZW
13741 }
13742 else
13743 encode_thumb32_shifted_operand (2);
13744}
b99bd4ef 13745
c19d1205
ZW
13746static void
13747do_t_setend (void)
13748{
12e37cbc
MGD
13749 if (warn_on_deprecated
13750 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13751 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13752
5ee91343 13753 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13754 if (inst.operands[0].imm)
13755 inst.instruction |= 0x8;
13756}
b99bd4ef 13757
c19d1205
ZW
13758static void
13759do_t_shift (void)
13760{
13761 if (!inst.operands[1].present)
13762 inst.operands[1].reg = inst.operands[0].reg;
13763
13764 if (unified_syntax)
13765 {
3d388997
PB
13766 bfd_boolean narrow;
13767 int shift_kind;
13768
13769 switch (inst.instruction)
13770 {
13771 case T_MNEM_asr:
13772 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13773 case T_MNEM_lsl:
13774 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13775 case T_MNEM_lsr:
13776 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13777 case T_MNEM_ror:
13778 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13779 default: abort ();
13780 }
13781
13782 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13783 narrow = !in_pred_block ();
3d388997 13784 else
5ee91343 13785 narrow = in_pred_block ();
3d388997
PB
13786 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13787 narrow = FALSE;
13788 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13789 narrow = FALSE;
13790 if (inst.operands[2].isreg
13791 && (inst.operands[1].reg != inst.operands[0].reg
13792 || inst.operands[2].reg > 7))
13793 narrow = FALSE;
13794 if (inst.size_req == 4)
13795 narrow = FALSE;
13796
fdfde340
JM
13797 reject_bad_reg (inst.operands[0].reg);
13798 reject_bad_reg (inst.operands[1].reg);
c921be7d 13799
3d388997 13800 if (!narrow)
c19d1205
ZW
13801 {
13802 if (inst.operands[2].isreg)
b99bd4ef 13803 {
fdfde340 13804 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13805 inst.instruction = THUMB_OP32 (inst.instruction);
13806 inst.instruction |= inst.operands[0].reg << 8;
13807 inst.instruction |= inst.operands[1].reg << 16;
13808 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13809
13810 /* PR 12854: Error on extraneous shifts. */
13811 constraint (inst.operands[2].shifted,
13812 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13813 }
13814 else
13815 {
13816 inst.operands[1].shifted = 1;
3d388997 13817 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13818 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13819 ? T_MNEM_movs : T_MNEM_mov);
13820 inst.instruction |= inst.operands[0].reg << 8;
13821 encode_thumb32_shifted_operand (1);
13822 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13823 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13824 }
13825 }
13826 else
13827 {
c19d1205 13828 if (inst.operands[2].isreg)
b99bd4ef 13829 {
3d388997 13830 switch (shift_kind)
b99bd4ef 13831 {
3d388997
PB
13832 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13833 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13834 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13835 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13836 default: abort ();
b99bd4ef 13837 }
5f4273c7 13838
c19d1205
ZW
13839 inst.instruction |= inst.operands[0].reg;
13840 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13841
13842 /* PR 12854: Error on extraneous shifts. */
13843 constraint (inst.operands[2].shifted,
13844 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13845 }
13846 else
13847 {
3d388997 13848 switch (shift_kind)
b99bd4ef 13849 {
3d388997
PB
13850 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13851 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13852 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13853 default: abort ();
b99bd4ef 13854 }
e2b0ab59 13855 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13856 inst.instruction |= inst.operands[0].reg;
13857 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13858 }
13859 }
c19d1205
ZW
13860 }
13861 else
13862 {
13863 constraint (inst.operands[0].reg > 7
13864 || inst.operands[1].reg > 7, BAD_HIREG);
13865 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 13866
c19d1205
ZW
13867 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13868 {
13869 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13870 constraint (inst.operands[0].reg != inst.operands[1].reg,
13871 _("source1 and dest must be same register"));
b99bd4ef 13872
c19d1205
ZW
13873 switch (inst.instruction)
13874 {
13875 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13876 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13877 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13878 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13879 default: abort ();
13880 }
5f4273c7 13881
c19d1205
ZW
13882 inst.instruction |= inst.operands[0].reg;
13883 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13884
13885 /* PR 12854: Error on extraneous shifts. */
13886 constraint (inst.operands[2].shifted,
13887 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13888 }
13889 else
b99bd4ef 13890 {
c19d1205
ZW
13891 switch (inst.instruction)
13892 {
13893 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13894 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13895 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13896 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13897 default: abort ();
13898 }
e2b0ab59 13899 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13900 inst.instruction |= inst.operands[0].reg;
13901 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13902 }
13903 }
b99bd4ef
NC
13904}
13905
13906static void
c19d1205 13907do_t_simd (void)
b99bd4ef 13908{
fdfde340
JM
13909 unsigned Rd, Rn, Rm;
13910
13911 Rd = inst.operands[0].reg;
13912 Rn = inst.operands[1].reg;
13913 Rm = inst.operands[2].reg;
13914
13915 reject_bad_reg (Rd);
13916 reject_bad_reg (Rn);
13917 reject_bad_reg (Rm);
13918
13919 inst.instruction |= Rd << 8;
13920 inst.instruction |= Rn << 16;
13921 inst.instruction |= Rm;
c19d1205 13922}
b99bd4ef 13923
03ee1b7f
NC
13924static void
13925do_t_simd2 (void)
13926{
13927 unsigned Rd, Rn, Rm;
13928
13929 Rd = inst.operands[0].reg;
13930 Rm = inst.operands[1].reg;
13931 Rn = inst.operands[2].reg;
13932
13933 reject_bad_reg (Rd);
13934 reject_bad_reg (Rn);
13935 reject_bad_reg (Rm);
13936
13937 inst.instruction |= Rd << 8;
13938 inst.instruction |= Rn << 16;
13939 inst.instruction |= Rm;
13940}
13941
c19d1205 13942static void
3eb17e6b 13943do_t_smc (void)
c19d1205 13944{
e2b0ab59 13945 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
13946 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13947 _("SMC is not permitted on this architecture"));
e2b0ab59 13948 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13949 _("expression too complex"));
ba85f98c
BW
13950 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
13951
e2b0ab59 13952 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 13953 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 13954
24382199 13955 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 13956 set_pred_insn_type_last ();
c19d1205 13957}
b99bd4ef 13958
90ec0d68
MGD
13959static void
13960do_t_hvc (void)
13961{
e2b0ab59 13962 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 13963
e2b0ab59 13964 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
13965 inst.instruction |= (value & 0x0fff);
13966 inst.instruction |= (value & 0xf000) << 4;
13967}
13968
c19d1205 13969static void
3a21c15a 13970do_t_ssat_usat (int bias)
c19d1205 13971{
fdfde340
JM
13972 unsigned Rd, Rn;
13973
13974 Rd = inst.operands[0].reg;
13975 Rn = inst.operands[2].reg;
13976
13977 reject_bad_reg (Rd);
13978 reject_bad_reg (Rn);
13979
13980 inst.instruction |= Rd << 8;
3a21c15a 13981 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13982 inst.instruction |= Rn << 16;
b99bd4ef 13983
c19d1205 13984 if (inst.operands[3].present)
b99bd4ef 13985 {
e2b0ab59 13986 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 13987
e2b0ab59 13988 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 13989
e2b0ab59 13990 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13991 _("expression too complex"));
b99bd4ef 13992
3a21c15a 13993 if (shift_amount != 0)
6189168b 13994 {
3a21c15a
NC
13995 constraint (shift_amount > 31,
13996 _("shift expression is too large"));
13997
c19d1205 13998 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13999 inst.instruction |= 0x00200000; /* sh bit. */
14000
14001 inst.instruction |= (shift_amount & 0x1c) << 10;
14002 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14003 }
14004 }
b99bd4ef 14005}
c921be7d 14006
3a21c15a
NC
14007static void
14008do_t_ssat (void)
14009{
14010 do_t_ssat_usat (1);
14011}
b99bd4ef 14012
0dd132b6 14013static void
c19d1205 14014do_t_ssat16 (void)
0dd132b6 14015{
fdfde340
JM
14016 unsigned Rd, Rn;
14017
14018 Rd = inst.operands[0].reg;
14019 Rn = inst.operands[2].reg;
14020
14021 reject_bad_reg (Rd);
14022 reject_bad_reg (Rn);
14023
14024 inst.instruction |= Rd << 8;
c19d1205 14025 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14026 inst.instruction |= Rn << 16;
c19d1205 14027}
0dd132b6 14028
c19d1205
ZW
14029static void
14030do_t_strex (void)
14031{
14032 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14033 || inst.operands[2].postind || inst.operands[2].writeback
14034 || inst.operands[2].immisreg || inst.operands[2].shifted
14035 || inst.operands[2].negative,
01cfc07f 14036 BAD_ADDR_MODE);
0dd132b6 14037
5be8be5d
DG
14038 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14039
c19d1205
ZW
14040 inst.instruction |= inst.operands[0].reg << 8;
14041 inst.instruction |= inst.operands[1].reg << 12;
14042 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14043 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14044}
14045
b99bd4ef 14046static void
c19d1205 14047do_t_strexd (void)
b99bd4ef 14048{
c19d1205
ZW
14049 if (!inst.operands[2].present)
14050 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14051
c19d1205
ZW
14052 constraint (inst.operands[0].reg == inst.operands[1].reg
14053 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14054 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14055 BAD_OVERLAP);
b99bd4ef 14056
c19d1205
ZW
14057 inst.instruction |= inst.operands[0].reg;
14058 inst.instruction |= inst.operands[1].reg << 12;
14059 inst.instruction |= inst.operands[2].reg << 8;
14060 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14061}
14062
14063static void
c19d1205 14064do_t_sxtah (void)
b99bd4ef 14065{
fdfde340
JM
14066 unsigned Rd, Rn, Rm;
14067
14068 Rd = inst.operands[0].reg;
14069 Rn = inst.operands[1].reg;
14070 Rm = inst.operands[2].reg;
14071
14072 reject_bad_reg (Rd);
14073 reject_bad_reg (Rn);
14074 reject_bad_reg (Rm);
14075
14076 inst.instruction |= Rd << 8;
14077 inst.instruction |= Rn << 16;
14078 inst.instruction |= Rm;
c19d1205
ZW
14079 inst.instruction |= inst.operands[3].imm << 4;
14080}
b99bd4ef 14081
c19d1205
ZW
14082static void
14083do_t_sxth (void)
14084{
fdfde340
JM
14085 unsigned Rd, Rm;
14086
14087 Rd = inst.operands[0].reg;
14088 Rm = inst.operands[1].reg;
14089
14090 reject_bad_reg (Rd);
14091 reject_bad_reg (Rm);
c921be7d
NC
14092
14093 if (inst.instruction <= 0xffff
14094 && inst.size_req != 4
fdfde340 14095 && Rd <= 7 && Rm <= 7
c19d1205 14096 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14097 {
c19d1205 14098 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14099 inst.instruction |= Rd;
14100 inst.instruction |= Rm << 3;
b99bd4ef 14101 }
c19d1205 14102 else if (unified_syntax)
b99bd4ef 14103 {
c19d1205
ZW
14104 if (inst.instruction <= 0xffff)
14105 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14106 inst.instruction |= Rd << 8;
14107 inst.instruction |= Rm;
c19d1205 14108 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14109 }
c19d1205 14110 else
b99bd4ef 14111 {
c19d1205
ZW
14112 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14113 _("Thumb encoding does not support rotation"));
14114 constraint (1, BAD_HIREG);
b99bd4ef 14115 }
c19d1205 14116}
b99bd4ef 14117
c19d1205
ZW
14118static void
14119do_t_swi (void)
14120{
e2b0ab59 14121 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14122}
b99bd4ef 14123
92e90b6e
PB
14124static void
14125do_t_tb (void)
14126{
fdfde340 14127 unsigned Rn, Rm;
92e90b6e
PB
14128 int half;
14129
14130 half = (inst.instruction & 0x10) != 0;
5ee91343 14131 set_pred_insn_type_last ();
dfa9f0d5
PB
14132 constraint (inst.operands[0].immisreg,
14133 _("instruction requires register index"));
fdfde340
JM
14134
14135 Rn = inst.operands[0].reg;
14136 Rm = inst.operands[0].imm;
c921be7d 14137
5c8ed6a4
JW
14138 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14139 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14140 reject_bad_reg (Rm);
14141
92e90b6e
PB
14142 constraint (!half && inst.operands[0].shifted,
14143 _("instruction does not allow shifted index"));
fdfde340 14144 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14145}
14146
74db7efb
NC
14147static void
14148do_t_udf (void)
14149{
14150 if (!inst.operands[0].present)
14151 inst.operands[0].imm = 0;
14152
14153 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14154 {
14155 constraint (inst.size_req == 2,
14156 _("immediate value out of range"));
14157 inst.instruction = THUMB_OP32 (inst.instruction);
14158 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14159 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14160 }
14161 else
14162 {
14163 inst.instruction = THUMB_OP16 (inst.instruction);
14164 inst.instruction |= inst.operands[0].imm;
14165 }
14166
5ee91343 14167 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14168}
14169
14170
c19d1205
ZW
14171static void
14172do_t_usat (void)
14173{
3a21c15a 14174 do_t_ssat_usat (0);
b99bd4ef
NC
14175}
14176
14177static void
c19d1205 14178do_t_usat16 (void)
b99bd4ef 14179{
fdfde340
JM
14180 unsigned Rd, Rn;
14181
14182 Rd = inst.operands[0].reg;
14183 Rn = inst.operands[2].reg;
14184
14185 reject_bad_reg (Rd);
14186 reject_bad_reg (Rn);
14187
14188 inst.instruction |= Rd << 8;
c19d1205 14189 inst.instruction |= inst.operands[1].imm;
fdfde340 14190 inst.instruction |= Rn << 16;
b99bd4ef 14191}
c19d1205 14192
e12437dc
AV
14193/* Checking the range of the branch offset (VAL) with NBITS bits
14194 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14195static int
14196v8_1_branch_value_check (int val, int nbits, int is_signed)
14197{
14198 gas_assert (nbits > 0 && nbits <= 32);
14199 if (is_signed)
14200 {
14201 int cmp = (1 << (nbits - 1));
14202 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14203 return FAIL;
14204 }
14205 else
14206 {
14207 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14208 return FAIL;
14209 }
14210 return SUCCESS;
14211}
14212
4389b29a
AV
14213/* For branches in Armv8.1-M Mainline. */
14214static void
14215do_t_branch_future (void)
14216{
14217 unsigned long insn = inst.instruction;
14218
14219 inst.instruction = THUMB_OP32 (inst.instruction);
14220 if (inst.operands[0].hasreloc == 0)
14221 {
14222 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14223 as_bad (BAD_BRANCH_OFF);
14224
14225 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14226 }
14227 else
14228 {
14229 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14230 inst.relocs[0].pc_rel = 1;
14231 }
14232
14233 switch (insn)
14234 {
14235 case T_MNEM_bf:
14236 if (inst.operands[1].hasreloc == 0)
14237 {
14238 int val = inst.operands[1].imm;
14239 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14240 as_bad (BAD_BRANCH_OFF);
14241
14242 int immA = (val & 0x0001f000) >> 12;
14243 int immB = (val & 0x00000ffc) >> 2;
14244 int immC = (val & 0x00000002) >> 1;
14245 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14246 }
14247 else
14248 {
14249 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14250 inst.relocs[1].pc_rel = 1;
14251 }
14252 break;
14253
65d1bc05
AV
14254 case T_MNEM_bfl:
14255 if (inst.operands[1].hasreloc == 0)
14256 {
14257 int val = inst.operands[1].imm;
14258 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14259 as_bad (BAD_BRANCH_OFF);
14260
14261 int immA = (val & 0x0007f000) >> 12;
14262 int immB = (val & 0x00000ffc) >> 2;
14263 int immC = (val & 0x00000002) >> 1;
14264 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14265 }
14266 else
14267 {
14268 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14269 inst.relocs[1].pc_rel = 1;
14270 }
14271 break;
14272
f6b2b12d
AV
14273 case T_MNEM_bfcsel:
14274 /* Operand 1. */
14275 if (inst.operands[1].hasreloc == 0)
14276 {
14277 int val = inst.operands[1].imm;
14278 int immA = (val & 0x00001000) >> 12;
14279 int immB = (val & 0x00000ffc) >> 2;
14280 int immC = (val & 0x00000002) >> 1;
14281 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14282 }
14283 else
14284 {
14285 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14286 inst.relocs[1].pc_rel = 1;
14287 }
14288
14289 /* Operand 2. */
14290 if (inst.operands[2].hasreloc == 0)
14291 {
14292 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14293 int val2 = inst.operands[2].imm;
14294 int val0 = inst.operands[0].imm & 0x1f;
14295 int diff = val2 - val0;
14296 if (diff == 4)
14297 inst.instruction |= 1 << 17; /* T bit. */
14298 else if (diff != 2)
14299 as_bad (_("out of range label-relative fixup value"));
14300 }
14301 else
14302 {
14303 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14304 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14305 inst.relocs[2].pc_rel = 1;
14306 }
14307
14308 /* Operand 3. */
14309 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14310 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14311 break;
14312
f1c7f421
AV
14313 case T_MNEM_bfx:
14314 case T_MNEM_bflx:
14315 inst.instruction |= inst.operands[1].reg << 16;
14316 break;
14317
4389b29a
AV
14318 default: abort ();
14319 }
14320}
14321
60f993ce
AV
14322/* Helper function for do_t_loloop to handle relocations. */
14323static void
14324v8_1_loop_reloc (int is_le)
14325{
14326 if (inst.relocs[0].exp.X_op == O_constant)
14327 {
14328 int value = inst.relocs[0].exp.X_add_number;
14329 value = (is_le) ? -value : value;
14330
14331 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14332 as_bad (BAD_BRANCH_OFF);
14333
14334 int imml, immh;
14335
14336 immh = (value & 0x00000ffc) >> 2;
14337 imml = (value & 0x00000002) >> 1;
14338
14339 inst.instruction |= (imml << 11) | (immh << 1);
14340 }
14341 else
14342 {
14343 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14344 inst.relocs[0].pc_rel = 1;
14345 }
14346}
14347
23d00a41
SD
14348/* For shifts in MVE. */
14349static void
14350do_mve_scalar_shift (void)
14351{
14352 if (!inst.operands[2].present)
14353 {
14354 inst.operands[2] = inst.operands[1];
14355 inst.operands[1].reg = 0xf;
14356 }
14357
14358 inst.instruction |= inst.operands[0].reg << 16;
14359 inst.instruction |= inst.operands[1].reg << 8;
14360
14361 if (inst.operands[2].isreg)
14362 {
14363 /* Assuming Rm is already checked not to be 11x1. */
14364 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14365 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14366 inst.instruction |= inst.operands[2].reg << 12;
14367 }
14368 else
14369 {
14370 /* Assuming imm is already checked as [1,32]. */
14371 unsigned int value = inst.operands[2].imm;
14372 inst.instruction |= (value & 0x1c) << 10;
14373 inst.instruction |= (value & 0x03) << 6;
14374 /* Change last 4 bits from 0xd to 0xf. */
14375 inst.instruction |= 0x2;
14376 }
14377}
14378
a302e574
AV
14379/* MVE instruction encoder helpers. */
14380#define M_MNEM_vabav 0xee800f01
14381#define M_MNEM_vmladav 0xeef00e00
14382#define M_MNEM_vmladava 0xeef00e20
14383#define M_MNEM_vmladavx 0xeef01e00
14384#define M_MNEM_vmladavax 0xeef01e20
14385#define M_MNEM_vmlsdav 0xeef00e01
14386#define M_MNEM_vmlsdava 0xeef00e21
14387#define M_MNEM_vmlsdavx 0xeef01e01
14388#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14389#define M_MNEM_vmullt 0xee011e00
14390#define M_MNEM_vmullb 0xee010e00
35c228db
AV
14391#define M_MNEM_vst20 0xfc801e00
14392#define M_MNEM_vst21 0xfc801e20
14393#define M_MNEM_vst40 0xfc801e01
14394#define M_MNEM_vst41 0xfc801e21
14395#define M_MNEM_vst42 0xfc801e41
14396#define M_MNEM_vst43 0xfc801e61
14397#define M_MNEM_vld20 0xfc901e00
14398#define M_MNEM_vld21 0xfc901e20
14399#define M_MNEM_vld40 0xfc901e01
14400#define M_MNEM_vld41 0xfc901e21
14401#define M_MNEM_vld42 0xfc901e41
14402#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14403#define M_MNEM_vstrb 0xec000e00
14404#define M_MNEM_vstrh 0xec000e10
14405#define M_MNEM_vstrw 0xec000e40
14406#define M_MNEM_vstrd 0xec000e50
14407#define M_MNEM_vldrb 0xec100e00
14408#define M_MNEM_vldrh 0xec100e10
14409#define M_MNEM_vldrw 0xec100e40
14410#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14411#define M_MNEM_vmovlt 0xeea01f40
14412#define M_MNEM_vmovlb 0xeea00f40
14413#define M_MNEM_vmovnt 0xfe311e81
14414#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14415#define M_MNEM_vadc 0xee300f00
14416#define M_MNEM_vadci 0xee301f00
14417#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14418#define M_MNEM_vaddlv 0xee890f00
14419#define M_MNEM_vaddlva 0xee890f20
14420#define M_MNEM_vaddv 0xeef10f00
14421#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14422#define M_MNEM_vddup 0xee011f6e
14423#define M_MNEM_vdwdup 0xee011f60
14424#define M_MNEM_vidup 0xee010f6e
14425#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14426#define M_MNEM_vmaxv 0xeee20f00
14427#define M_MNEM_vmaxav 0xeee00f00
14428#define M_MNEM_vminv 0xeee20f80
14429#define M_MNEM_vminav 0xeee00f80
93925576
AV
14430#define M_MNEM_vmlaldav 0xee800e00
14431#define M_MNEM_vmlaldava 0xee800e20
14432#define M_MNEM_vmlaldavx 0xee801e00
14433#define M_MNEM_vmlaldavax 0xee801e20
14434#define M_MNEM_vmlsldav 0xee800e01
14435#define M_MNEM_vmlsldava 0xee800e21
14436#define M_MNEM_vmlsldavx 0xee801e01
14437#define M_MNEM_vmlsldavax 0xee801e21
14438#define M_MNEM_vrmlaldavhx 0xee801f00
14439#define M_MNEM_vrmlaldavhax 0xee801f20
14440#define M_MNEM_vrmlsldavh 0xfe800e01
14441#define M_MNEM_vrmlsldavha 0xfe800e21
14442#define M_MNEM_vrmlsldavhx 0xfe801e01
14443#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14444#define M_MNEM_vqmovnt 0xee331e01
14445#define M_MNEM_vqmovnb 0xee330e01
14446#define M_MNEM_vqmovunt 0xee311e81
14447#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14448#define M_MNEM_vshrnt 0xee801fc1
14449#define M_MNEM_vshrnb 0xee800fc1
14450#define M_MNEM_vrshrnt 0xfe801fc1
14451#define M_MNEM_vqshrnt 0xee801f40
14452#define M_MNEM_vqshrnb 0xee800f40
14453#define M_MNEM_vqshrunt 0xee801fc0
14454#define M_MNEM_vqshrunb 0xee800fc0
14455#define M_MNEM_vrshrnb 0xfe800fc1
14456#define M_MNEM_vqrshrnt 0xee801f41
14457#define M_MNEM_vqrshrnb 0xee800f41
14458#define M_MNEM_vqrshrunt 0xfe801fc0
14459#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14460
5287ad62 14461/* Neon instruction encoder helpers. */
5f4273c7 14462
5287ad62 14463/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14464
5287ad62
JB
14465/* An "invalid" code for the following tables. */
14466#define N_INV -1u
14467
14468struct neon_tab_entry
b99bd4ef 14469{
5287ad62
JB
14470 unsigned integer;
14471 unsigned float_or_poly;
14472 unsigned scalar_or_imm;
14473};
5f4273c7 14474
5287ad62
JB
14475/* Map overloaded Neon opcodes to their respective encodings. */
14476#define NEON_ENC_TAB \
14477 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14478 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14479 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14480 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14481 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14482 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14483 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14484 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14485 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14486 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14487 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14488 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14489 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14490 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14491 /* Register variants of the following two instructions are encoded as
e07e6e58 14492 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14493 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14494 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14495 X(vfma, N_INV, 0x0000c10, N_INV), \
14496 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14497 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14498 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14499 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14500 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14501 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14502 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14503 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14504 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14505 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14506 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14507 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14508 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14509 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14510 X(vshl, 0x0000400, N_INV, 0x0800510), \
14511 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14512 X(vand, 0x0000110, N_INV, 0x0800030), \
14513 X(vbic, 0x0100110, N_INV, 0x0800030), \
14514 X(veor, 0x1000110, N_INV, N_INV), \
14515 X(vorn, 0x0300110, N_INV, 0x0800010), \
14516 X(vorr, 0x0200110, N_INV, 0x0800010), \
14517 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14518 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14519 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14520 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14521 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14522 X(vst1, 0x0000000, 0x0800000, N_INV), \
14523 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14524 X(vst2, 0x0000100, 0x0800100, N_INV), \
14525 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14526 X(vst3, 0x0000200, 0x0800200, N_INV), \
14527 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14528 X(vst4, 0x0000300, 0x0800300, N_INV), \
14529 X(vmovn, 0x1b20200, N_INV, N_INV), \
14530 X(vtrn, 0x1b20080, N_INV, N_INV), \
14531 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14532 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14533 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14534 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14535 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14536 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14537 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14538 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14539 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14540 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14541 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14542 X(vseleq, 0xe000a00, N_INV, N_INV), \
14543 X(vselvs, 0xe100a00, N_INV, N_INV), \
14544 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14545 X(vselgt, 0xe300a00, N_INV, N_INV), \
14546 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14547 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14548 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14549 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14550 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14551 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14552 X(sha3op, 0x2000c00, N_INV, N_INV), \
14553 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14554 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14555
14556enum neon_opc
14557{
14558#define X(OPC,I,F,S) N_MNEM_##OPC
14559NEON_ENC_TAB
14560#undef X
14561};
b99bd4ef 14562
5287ad62
JB
14563static const struct neon_tab_entry neon_enc_tab[] =
14564{
14565#define X(OPC,I,F,S) { (I), (F), (S) }
14566NEON_ENC_TAB
14567#undef X
14568};
b99bd4ef 14569
88714cb8
DG
14570/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14571#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14572#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14573#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14574#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14575#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14576#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14577#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14578#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14579#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14580#define NEON_ENC_SINGLE_(X) \
037e8744 14581 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14582#define NEON_ENC_DOUBLE_(X) \
037e8744 14583 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14584#define NEON_ENC_FPV8_(X) \
14585 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14586
88714cb8
DG
14587#define NEON_ENCODE(type, inst) \
14588 do \
14589 { \
14590 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14591 inst.is_neon = 1; \
14592 } \
14593 while (0)
14594
14595#define check_neon_suffixes \
14596 do \
14597 { \
14598 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14599 { \
14600 as_bad (_("invalid neon suffix for non neon instruction")); \
14601 return; \
14602 } \
14603 } \
14604 while (0)
14605
037e8744
JB
14606/* Define shapes for instruction operands. The following mnemonic characters
14607 are used in this table:
5287ad62 14608
037e8744 14609 F - VFP S<n> register
5287ad62
JB
14610 D - Neon D<n> register
14611 Q - Neon Q<n> register
14612 I - Immediate
14613 S - Scalar
14614 R - ARM register
14615 L - D<n> register list
5f4273c7 14616
037e8744
JB
14617 This table is used to generate various data:
14618 - enumerations of the form NS_DDR to be used as arguments to
14619 neon_select_shape.
14620 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14621 - a table used to drive neon_select_shape. */
b99bd4ef 14622
037e8744 14623#define NEON_SHAPE_DEF \
93925576 14624 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14625 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14626 X(4, (R, R, S, S), QUAD), \
14627 X(4, (S, S, R, R), QUAD), \
b409bdb6 14628 X(3, (Q, R, I), QUAD), \
1b883319
AV
14629 X(3, (I, Q, Q), QUAD), \
14630 X(3, (I, Q, R), QUAD), \
a302e574 14631 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14632 X(3, (D, D, D), DOUBLE), \
14633 X(3, (Q, Q, Q), QUAD), \
14634 X(3, (D, D, I), DOUBLE), \
14635 X(3, (Q, Q, I), QUAD), \
14636 X(3, (D, D, S), DOUBLE), \
14637 X(3, (Q, Q, S), QUAD), \
5ee91343 14638 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14639 X(3, (R, R, Q), QUAD), \
14640 X(2, (R, Q), QUAD), \
037e8744
JB
14641 X(2, (D, D), DOUBLE), \
14642 X(2, (Q, Q), QUAD), \
14643 X(2, (D, S), DOUBLE), \
14644 X(2, (Q, S), QUAD), \
14645 X(2, (D, R), DOUBLE), \
14646 X(2, (Q, R), QUAD), \
14647 X(2, (D, I), DOUBLE), \
14648 X(2, (Q, I), QUAD), \
14649 X(3, (D, L, D), DOUBLE), \
14650 X(2, (D, Q), MIXED), \
14651 X(2, (Q, D), MIXED), \
14652 X(3, (D, Q, I), MIXED), \
14653 X(3, (Q, D, I), MIXED), \
14654 X(3, (Q, D, D), MIXED), \
14655 X(3, (D, Q, Q), MIXED), \
14656 X(3, (Q, Q, D), MIXED), \
14657 X(3, (Q, D, S), MIXED), \
14658 X(3, (D, Q, S), MIXED), \
14659 X(4, (D, D, D, I), DOUBLE), \
14660 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14661 X(4, (D, D, S, I), DOUBLE), \
14662 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14663 X(2, (F, F), SINGLE), \
14664 X(3, (F, F, F), SINGLE), \
14665 X(2, (F, I), SINGLE), \
14666 X(2, (F, D), MIXED), \
14667 X(2, (D, F), MIXED), \
14668 X(3, (F, F, I), MIXED), \
14669 X(4, (R, R, F, F), SINGLE), \
14670 X(4, (F, F, R, R), SINGLE), \
14671 X(3, (D, R, R), DOUBLE), \
14672 X(3, (R, R, D), DOUBLE), \
14673 X(2, (S, R), SINGLE), \
14674 X(2, (R, S), SINGLE), \
14675 X(2, (F, R), SINGLE), \
d54af2d0 14676 X(2, (R, F), SINGLE), \
1f6234a3
AV
14677/* Used for MVE tail predicated loop instructions. */\
14678 X(2, (R, R), QUAD), \
d54af2d0
RL
14679/* Half float shape supported so far. */\
14680 X (2, (H, D), MIXED), \
14681 X (2, (D, H), MIXED), \
14682 X (2, (H, F), MIXED), \
14683 X (2, (F, H), MIXED), \
14684 X (2, (H, H), HALF), \
14685 X (2, (H, R), HALF), \
14686 X (2, (R, H), HALF), \
14687 X (2, (H, I), HALF), \
14688 X (3, (H, H, H), HALF), \
14689 X (3, (H, F, I), MIXED), \
dec41383
JW
14690 X (3, (F, H, I), MIXED), \
14691 X (3, (D, H, H), MIXED), \
14692 X (3, (D, H, S), MIXED)
037e8744
JB
14693
14694#define S2(A,B) NS_##A##B
14695#define S3(A,B,C) NS_##A##B##C
14696#define S4(A,B,C,D) NS_##A##B##C##D
14697
14698#define X(N, L, C) S##N L
14699
5287ad62
JB
14700enum neon_shape
14701{
037e8744
JB
14702 NEON_SHAPE_DEF,
14703 NS_NULL
5287ad62 14704};
b99bd4ef 14705
037e8744
JB
14706#undef X
14707#undef S2
14708#undef S3
14709#undef S4
14710
14711enum neon_shape_class
14712{
d54af2d0 14713 SC_HALF,
037e8744
JB
14714 SC_SINGLE,
14715 SC_DOUBLE,
14716 SC_QUAD,
14717 SC_MIXED
14718};
14719
14720#define X(N, L, C) SC_##C
14721
14722static enum neon_shape_class neon_shape_class[] =
14723{
14724 NEON_SHAPE_DEF
14725};
14726
14727#undef X
14728
14729enum neon_shape_el
14730{
d54af2d0 14731 SE_H,
037e8744
JB
14732 SE_F,
14733 SE_D,
14734 SE_Q,
14735 SE_I,
14736 SE_S,
14737 SE_R,
14738 SE_L
14739};
14740
14741/* Register widths of above. */
14742static unsigned neon_shape_el_size[] =
14743{
d54af2d0 14744 16,
037e8744
JB
14745 32,
14746 64,
14747 128,
14748 0,
14749 32,
14750 32,
14751 0
14752};
14753
14754struct neon_shape_info
14755{
14756 unsigned els;
14757 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14758};
14759
14760#define S2(A,B) { SE_##A, SE_##B }
14761#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14762#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14763
14764#define X(N, L, C) { N, S##N L }
14765
14766static struct neon_shape_info neon_shape_tab[] =
14767{
14768 NEON_SHAPE_DEF
14769};
14770
14771#undef X
14772#undef S2
14773#undef S3
14774#undef S4
14775
5287ad62
JB
14776/* Bit masks used in type checking given instructions.
14777 'N_EQK' means the type must be the same as (or based on in some way) the key
14778 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14779 set, various other bits can be set as well in order to modify the meaning of
14780 the type constraint. */
14781
14782enum neon_type_mask
14783{
8e79c3df
CM
14784 N_S8 = 0x0000001,
14785 N_S16 = 0x0000002,
14786 N_S32 = 0x0000004,
14787 N_S64 = 0x0000008,
14788 N_U8 = 0x0000010,
14789 N_U16 = 0x0000020,
14790 N_U32 = 0x0000040,
14791 N_U64 = 0x0000080,
14792 N_I8 = 0x0000100,
14793 N_I16 = 0x0000200,
14794 N_I32 = 0x0000400,
14795 N_I64 = 0x0000800,
14796 N_8 = 0x0001000,
14797 N_16 = 0x0002000,
14798 N_32 = 0x0004000,
14799 N_64 = 0x0008000,
14800 N_P8 = 0x0010000,
14801 N_P16 = 0x0020000,
14802 N_F16 = 0x0040000,
14803 N_F32 = 0x0080000,
14804 N_F64 = 0x0100000,
4f51b4bd 14805 N_P64 = 0x0200000,
c921be7d
NC
14806 N_KEY = 0x1000000, /* Key element (main type specifier). */
14807 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14808 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14809 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14810 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14811 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14812 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14813 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14814 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14815 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14816 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 14817 N_UTYP = 0,
4f51b4bd 14818 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
14819};
14820
dcbf9037
JB
14821#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14822
5287ad62
JB
14823#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14824#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14825#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
14826#define N_S_32 (N_S8 | N_S16 | N_S32)
14827#define N_F_16_32 (N_F16 | N_F32)
14828#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 14829#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 14830#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 14831#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
14832#define N_I_MVE (N_I8 | N_I16 | N_I32)
14833#define N_F_MVE (N_F16 | N_F32)
14834#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
14835
14836/* Pass this as the first type argument to neon_check_type to ignore types
14837 altogether. */
14838#define N_IGNORE_TYPE (N_KEY | N_EQK)
14839
037e8744
JB
14840/* Select a "shape" for the current instruction (describing register types or
14841 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14842 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14843 function of operand parsing, so this function doesn't need to be called.
14844 Shapes should be listed in order of decreasing length. */
5287ad62
JB
14845
14846static enum neon_shape
037e8744 14847neon_select_shape (enum neon_shape shape, ...)
5287ad62 14848{
037e8744
JB
14849 va_list ap;
14850 enum neon_shape first_shape = shape;
5287ad62
JB
14851
14852 /* Fix missing optional operands. FIXME: we don't know at this point how
14853 many arguments we should have, so this makes the assumption that we have
14854 > 1. This is true of all current Neon opcodes, I think, but may not be
14855 true in the future. */
14856 if (!inst.operands[1].present)
14857 inst.operands[1] = inst.operands[0];
14858
037e8744 14859 va_start (ap, shape);
5f4273c7 14860
21d799b5 14861 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
14862 {
14863 unsigned j;
14864 int matches = 1;
14865
14866 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
14867 {
14868 if (!inst.operands[j].present)
14869 {
14870 matches = 0;
14871 break;
14872 }
14873
14874 switch (neon_shape_tab[shape].el[j])
14875 {
d54af2d0
RL
14876 /* If a .f16, .16, .u16, .s16 type specifier is given over
14877 a VFP single precision register operand, it's essentially
14878 means only half of the register is used.
14879
14880 If the type specifier is given after the mnemonics, the
14881 information is stored in inst.vectype. If the type specifier
14882 is given after register operand, the information is stored
14883 in inst.operands[].vectype.
14884
14885 When there is only one type specifier, and all the register
14886 operands are the same type of hardware register, the type
14887 specifier applies to all register operands.
14888
14889 If no type specifier is given, the shape is inferred from
14890 operand information.
14891
14892 for example:
14893 vadd.f16 s0, s1, s2: NS_HHH
14894 vabs.f16 s0, s1: NS_HH
14895 vmov.f16 s0, r1: NS_HR
14896 vmov.f16 r0, s1: NS_RH
14897 vcvt.f16 r0, s1: NS_RH
14898 vcvt.f16.s32 s2, s2, #29: NS_HFI
14899 vcvt.f16.s32 s2, s2: NS_HF
14900 */
14901 case SE_H:
14902 if (!(inst.operands[j].isreg
14903 && inst.operands[j].isvec
14904 && inst.operands[j].issingle
14905 && !inst.operands[j].isquad
14906 && ((inst.vectype.elems == 1
14907 && inst.vectype.el[0].size == 16)
14908 || (inst.vectype.elems > 1
14909 && inst.vectype.el[j].size == 16)
14910 || (inst.vectype.elems == 0
14911 && inst.operands[j].vectype.type != NT_invtype
14912 && inst.operands[j].vectype.size == 16))))
14913 matches = 0;
14914 break;
14915
477330fc
RM
14916 case SE_F:
14917 if (!(inst.operands[j].isreg
14918 && inst.operands[j].isvec
14919 && inst.operands[j].issingle
d54af2d0
RL
14920 && !inst.operands[j].isquad
14921 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14922 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14923 || (inst.vectype.elems == 0
14924 && (inst.operands[j].vectype.size == 32
14925 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
14926 matches = 0;
14927 break;
14928
14929 case SE_D:
14930 if (!(inst.operands[j].isreg
14931 && inst.operands[j].isvec
14932 && !inst.operands[j].isquad
14933 && !inst.operands[j].issingle))
14934 matches = 0;
14935 break;
14936
14937 case SE_R:
14938 if (!(inst.operands[j].isreg
14939 && !inst.operands[j].isvec))
14940 matches = 0;
14941 break;
14942
14943 case SE_Q:
14944 if (!(inst.operands[j].isreg
14945 && inst.operands[j].isvec
14946 && inst.operands[j].isquad
14947 && !inst.operands[j].issingle))
14948 matches = 0;
14949 break;
14950
14951 case SE_I:
14952 if (!(!inst.operands[j].isreg
14953 && !inst.operands[j].isscalar))
14954 matches = 0;
14955 break;
14956
14957 case SE_S:
14958 if (!(!inst.operands[j].isreg
14959 && inst.operands[j].isscalar))
14960 matches = 0;
14961 break;
14962
14963 case SE_L:
14964 break;
14965 }
3fde54a2
JZ
14966 if (!matches)
14967 break;
477330fc 14968 }
ad6cec43
MGD
14969 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14970 /* We've matched all the entries in the shape table, and we don't
14971 have any left over operands which have not been matched. */
477330fc 14972 break;
037e8744 14973 }
5f4273c7 14974
037e8744 14975 va_end (ap);
5287ad62 14976
037e8744
JB
14977 if (shape == NS_NULL && first_shape != NS_NULL)
14978 first_error (_("invalid instruction shape"));
5287ad62 14979
037e8744
JB
14980 return shape;
14981}
5287ad62 14982
037e8744
JB
14983/* True if SHAPE is predominantly a quadword operation (most of the time, this
14984 means the Q bit should be set). */
14985
14986static int
14987neon_quad (enum neon_shape shape)
14988{
14989 return neon_shape_class[shape] == SC_QUAD;
5287ad62 14990}
037e8744 14991
5287ad62
JB
14992static void
14993neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 14994 unsigned *g_size)
5287ad62
JB
14995{
14996 /* Allow modification to be made to types which are constrained to be
14997 based on the key element, based on bits set alongside N_EQK. */
14998 if ((typebits & N_EQK) != 0)
14999 {
15000 if ((typebits & N_HLF) != 0)
15001 *g_size /= 2;
15002 else if ((typebits & N_DBL) != 0)
15003 *g_size *= 2;
15004 if ((typebits & N_SGN) != 0)
15005 *g_type = NT_signed;
15006 else if ((typebits & N_UNS) != 0)
477330fc 15007 *g_type = NT_unsigned;
5287ad62 15008 else if ((typebits & N_INT) != 0)
477330fc 15009 *g_type = NT_integer;
5287ad62 15010 else if ((typebits & N_FLT) != 0)
477330fc 15011 *g_type = NT_float;
dcbf9037 15012 else if ((typebits & N_SIZ) != 0)
477330fc 15013 *g_type = NT_untyped;
5287ad62
JB
15014 }
15015}
5f4273c7 15016
5287ad62
JB
15017/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15018 operand type, i.e. the single type specified in a Neon instruction when it
15019 is the only one given. */
15020
15021static struct neon_type_el
15022neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15023{
15024 struct neon_type_el dest = *key;
5f4273c7 15025
9c2799c2 15026 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15027
5287ad62
JB
15028 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15029
15030 return dest;
15031}
15032
15033/* Convert Neon type and size into compact bitmask representation. */
15034
15035static enum neon_type_mask
15036type_chk_of_el_type (enum neon_el_type type, unsigned size)
15037{
15038 switch (type)
15039 {
15040 case NT_untyped:
15041 switch (size)
477330fc
RM
15042 {
15043 case 8: return N_8;
15044 case 16: return N_16;
15045 case 32: return N_32;
15046 case 64: return N_64;
15047 default: ;
15048 }
5287ad62
JB
15049 break;
15050
15051 case NT_integer:
15052 switch (size)
477330fc
RM
15053 {
15054 case 8: return N_I8;
15055 case 16: return N_I16;
15056 case 32: return N_I32;
15057 case 64: return N_I64;
15058 default: ;
15059 }
5287ad62
JB
15060 break;
15061
15062 case NT_float:
037e8744 15063 switch (size)
477330fc 15064 {
8e79c3df 15065 case 16: return N_F16;
477330fc
RM
15066 case 32: return N_F32;
15067 case 64: return N_F64;
15068 default: ;
15069 }
5287ad62
JB
15070 break;
15071
15072 case NT_poly:
15073 switch (size)
477330fc
RM
15074 {
15075 case 8: return N_P8;
15076 case 16: return N_P16;
4f51b4bd 15077 case 64: return N_P64;
477330fc
RM
15078 default: ;
15079 }
5287ad62
JB
15080 break;
15081
15082 case NT_signed:
15083 switch (size)
477330fc
RM
15084 {
15085 case 8: return N_S8;
15086 case 16: return N_S16;
15087 case 32: return N_S32;
15088 case 64: return N_S64;
15089 default: ;
15090 }
5287ad62
JB
15091 break;
15092
15093 case NT_unsigned:
15094 switch (size)
477330fc
RM
15095 {
15096 case 8: return N_U8;
15097 case 16: return N_U16;
15098 case 32: return N_U32;
15099 case 64: return N_U64;
15100 default: ;
15101 }
5287ad62
JB
15102 break;
15103
15104 default: ;
15105 }
5f4273c7 15106
5287ad62
JB
15107 return N_UTYP;
15108}
15109
15110/* Convert compact Neon bitmask type representation to a type and size. Only
15111 handles the case where a single bit is set in the mask. */
15112
dcbf9037 15113static int
5287ad62 15114el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15115 enum neon_type_mask mask)
5287ad62 15116{
dcbf9037
JB
15117 if ((mask & N_EQK) != 0)
15118 return FAIL;
15119
5287ad62
JB
15120 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15121 *size = 8;
c70a8987 15122 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 15123 *size = 16;
dcbf9037 15124 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15125 *size = 32;
4f51b4bd 15126 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15127 *size = 64;
dcbf9037
JB
15128 else
15129 return FAIL;
15130
5287ad62
JB
15131 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15132 *type = NT_signed;
dcbf9037 15133 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15134 *type = NT_unsigned;
dcbf9037 15135 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15136 *type = NT_integer;
dcbf9037 15137 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15138 *type = NT_untyped;
4f51b4bd 15139 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15140 *type = NT_poly;
d54af2d0 15141 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15142 *type = NT_float;
dcbf9037
JB
15143 else
15144 return FAIL;
5f4273c7 15145
dcbf9037 15146 return SUCCESS;
5287ad62
JB
15147}
15148
15149/* Modify a bitmask of allowed types. This is only needed for type
15150 relaxation. */
15151
15152static unsigned
15153modify_types_allowed (unsigned allowed, unsigned mods)
15154{
15155 unsigned size;
15156 enum neon_el_type type;
15157 unsigned destmask;
15158 int i;
5f4273c7 15159
5287ad62 15160 destmask = 0;
5f4273c7 15161
5287ad62
JB
15162 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15163 {
21d799b5 15164 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15165 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15166 {
15167 neon_modify_type_size (mods, &type, &size);
15168 destmask |= type_chk_of_el_type (type, size);
15169 }
5287ad62 15170 }
5f4273c7 15171
5287ad62
JB
15172 return destmask;
15173}
15174
15175/* Check type and return type classification.
15176 The manual states (paraphrase): If one datatype is given, it indicates the
15177 type given in:
15178 - the second operand, if there is one
15179 - the operand, if there is no second operand
15180 - the result, if there are no operands.
15181 This isn't quite good enough though, so we use a concept of a "key" datatype
15182 which is set on a per-instruction basis, which is the one which matters when
15183 only one data type is written.
15184 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15185 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15186
15187static struct neon_type_el
15188neon_check_type (unsigned els, enum neon_shape ns, ...)
15189{
15190 va_list ap;
15191 unsigned i, pass, key_el = 0;
15192 unsigned types[NEON_MAX_TYPE_ELS];
15193 enum neon_el_type k_type = NT_invtype;
15194 unsigned k_size = -1u;
15195 struct neon_type_el badtype = {NT_invtype, -1};
15196 unsigned key_allowed = 0;
15197
15198 /* Optional registers in Neon instructions are always (not) in operand 1.
15199 Fill in the missing operand here, if it was omitted. */
15200 if (els > 1 && !inst.operands[1].present)
15201 inst.operands[1] = inst.operands[0];
15202
15203 /* Suck up all the varargs. */
15204 va_start (ap, ns);
15205 for (i = 0; i < els; i++)
15206 {
15207 unsigned thisarg = va_arg (ap, unsigned);
15208 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15209 {
15210 va_end (ap);
15211 return badtype;
15212 }
5287ad62
JB
15213 types[i] = thisarg;
15214 if ((thisarg & N_KEY) != 0)
477330fc 15215 key_el = i;
5287ad62
JB
15216 }
15217 va_end (ap);
15218
dcbf9037
JB
15219 if (inst.vectype.elems > 0)
15220 for (i = 0; i < els; i++)
15221 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15222 {
15223 first_error (_("types specified in both the mnemonic and operands"));
15224 return badtype;
15225 }
dcbf9037 15226
5287ad62
JB
15227 /* Duplicate inst.vectype elements here as necessary.
15228 FIXME: No idea if this is exactly the same as the ARM assembler,
15229 particularly when an insn takes one register and one non-register
15230 operand. */
15231 if (inst.vectype.elems == 1 && els > 1)
15232 {
15233 unsigned j;
15234 inst.vectype.elems = els;
15235 inst.vectype.el[key_el] = inst.vectype.el[0];
15236 for (j = 0; j < els; j++)
477330fc
RM
15237 if (j != key_el)
15238 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15239 types[j]);
dcbf9037
JB
15240 }
15241 else if (inst.vectype.elems == 0 && els > 0)
15242 {
15243 unsigned j;
15244 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15245 after each operand. We allow some flexibility here; as long as the
15246 "key" operand has a type, we can infer the others. */
dcbf9037 15247 for (j = 0; j < els; j++)
477330fc
RM
15248 if (inst.operands[j].vectype.type != NT_invtype)
15249 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15250
15251 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15252 {
15253 for (j = 0; j < els; j++)
15254 if (inst.operands[j].vectype.type == NT_invtype)
15255 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15256 types[j]);
15257 }
dcbf9037 15258 else
477330fc
RM
15259 {
15260 first_error (_("operand types can't be inferred"));
15261 return badtype;
15262 }
5287ad62
JB
15263 }
15264 else if (inst.vectype.elems != els)
15265 {
dcbf9037 15266 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15267 return badtype;
15268 }
15269
15270 for (pass = 0; pass < 2; pass++)
15271 {
15272 for (i = 0; i < els; i++)
477330fc
RM
15273 {
15274 unsigned thisarg = types[i];
15275 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15276 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15277 enum neon_el_type g_type = inst.vectype.el[i].type;
15278 unsigned g_size = inst.vectype.el[i].size;
15279
15280 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15281 integer types if sign-specific variants are unavailable. */
477330fc 15282 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15283 && (types_allowed & N_SU_ALL) == 0)
15284 g_type = NT_integer;
15285
477330fc 15286 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15287 them. Some instructions only care about signs for some element
15288 sizes, so handle that properly. */
477330fc 15289 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15290 && ((g_size == 8 && (types_allowed & N_8) != 0)
15291 || (g_size == 16 && (types_allowed & N_16) != 0)
15292 || (g_size == 32 && (types_allowed & N_32) != 0)
15293 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15294 g_type = NT_untyped;
15295
477330fc
RM
15296 if (pass == 0)
15297 {
15298 if ((thisarg & N_KEY) != 0)
15299 {
15300 k_type = g_type;
15301 k_size = g_size;
15302 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15303
15304 /* Check architecture constraint on FP16 extension. */
15305 if (k_size == 16
15306 && k_type == NT_float
15307 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15308 {
15309 inst.error = _(BAD_FP16);
15310 return badtype;
15311 }
477330fc
RM
15312 }
15313 }
15314 else
15315 {
15316 if ((thisarg & N_VFP) != 0)
15317 {
15318 enum neon_shape_el regshape;
15319 unsigned regwidth, match;
99b253c5
NC
15320
15321 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15322 if (ns == NS_NULL)
15323 {
15324 first_error (_("invalid instruction shape"));
15325 return badtype;
15326 }
477330fc
RM
15327 regshape = neon_shape_tab[ns].el[i];
15328 regwidth = neon_shape_el_size[regshape];
15329
15330 /* In VFP mode, operands must match register widths. If we
15331 have a key operand, use its width, else use the width of
15332 the current operand. */
15333 if (k_size != -1u)
15334 match = k_size;
15335 else
15336 match = g_size;
15337
9db2f6b4
RL
15338 /* FP16 will use a single precision register. */
15339 if (regwidth == 32 && match == 16)
15340 {
15341 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15342 match = regwidth;
15343 else
15344 {
15345 inst.error = _(BAD_FP16);
15346 return badtype;
15347 }
15348 }
15349
477330fc
RM
15350 if (regwidth != match)
15351 {
15352 first_error (_("operand size must match register width"));
15353 return badtype;
15354 }
15355 }
15356
15357 if ((thisarg & N_EQK) == 0)
15358 {
15359 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15360
15361 if ((given_type & types_allowed) == 0)
15362 {
a302e574 15363 first_error (BAD_SIMD_TYPE);
477330fc
RM
15364 return badtype;
15365 }
15366 }
15367 else
15368 {
15369 enum neon_el_type mod_k_type = k_type;
15370 unsigned mod_k_size = k_size;
15371 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15372 if (g_type != mod_k_type || g_size != mod_k_size)
15373 {
15374 first_error (_("inconsistent types in Neon instruction"));
15375 return badtype;
15376 }
15377 }
15378 }
15379 }
5287ad62
JB
15380 }
15381
15382 return inst.vectype.el[key_el];
15383}
15384
037e8744 15385/* Neon-style VFP instruction forwarding. */
5287ad62 15386
037e8744
JB
15387/* Thumb VFP instructions have 0xE in the condition field. */
15388
15389static void
15390do_vfp_cond_or_thumb (void)
5287ad62 15391{
88714cb8
DG
15392 inst.is_neon = 1;
15393
5287ad62 15394 if (thumb_mode)
037e8744 15395 inst.instruction |= 0xe0000000;
5287ad62 15396 else
037e8744 15397 inst.instruction |= inst.cond << 28;
5287ad62
JB
15398}
15399
037e8744
JB
15400/* Look up and encode a simple mnemonic, for use as a helper function for the
15401 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15402 etc. It is assumed that operand parsing has already been done, and that the
15403 operands are in the form expected by the given opcode (this isn't necessarily
15404 the same as the form in which they were parsed, hence some massaging must
15405 take place before this function is called).
15406 Checks current arch version against that in the looked-up opcode. */
5287ad62 15407
037e8744
JB
15408static void
15409do_vfp_nsyn_opcode (const char *opname)
5287ad62 15410{
037e8744 15411 const struct asm_opcode *opcode;
5f4273c7 15412
21d799b5 15413 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 15414
037e8744
JB
15415 if (!opcode)
15416 abort ();
5287ad62 15417
037e8744 15418 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15419 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15420 _(BAD_FPU));
5287ad62 15421
88714cb8
DG
15422 inst.is_neon = 1;
15423
037e8744
JB
15424 if (thumb_mode)
15425 {
15426 inst.instruction = opcode->tvalue;
15427 opcode->tencode ();
15428 }
15429 else
15430 {
15431 inst.instruction = (inst.cond << 28) | opcode->avalue;
15432 opcode->aencode ();
15433 }
15434}
5287ad62
JB
15435
15436static void
037e8744 15437do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15438{
037e8744
JB
15439 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15440
9db2f6b4 15441 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15442 {
15443 if (is_add)
477330fc 15444 do_vfp_nsyn_opcode ("fadds");
037e8744 15445 else
477330fc 15446 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15447
15448 /* ARMv8.2 fp16 instruction. */
15449 if (rs == NS_HHH)
15450 do_scalar_fp16_v82_encode ();
037e8744
JB
15451 }
15452 else
15453 {
15454 if (is_add)
477330fc 15455 do_vfp_nsyn_opcode ("faddd");
037e8744 15456 else
477330fc 15457 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15458 }
15459}
15460
15461/* Check operand types to see if this is a VFP instruction, and if so call
15462 PFN (). */
15463
15464static int
15465try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15466{
15467 enum neon_shape rs;
15468 struct neon_type_el et;
15469
15470 switch (args)
15471 {
15472 case 2:
9db2f6b4
RL
15473 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15474 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15475 break;
5f4273c7 15476
037e8744 15477 case 3:
9db2f6b4
RL
15478 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15479 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15480 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15481 break;
15482
15483 default:
15484 abort ();
15485 }
15486
15487 if (et.type != NT_invtype)
15488 {
15489 pfn (rs);
15490 return SUCCESS;
15491 }
037e8744 15492
99b253c5 15493 inst.error = NULL;
037e8744
JB
15494 return FAIL;
15495}
15496
15497static void
15498do_vfp_nsyn_mla_mls (enum neon_shape rs)
15499{
15500 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15501
9db2f6b4 15502 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15503 {
15504 if (is_mla)
477330fc 15505 do_vfp_nsyn_opcode ("fmacs");
037e8744 15506 else
477330fc 15507 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15508
15509 /* ARMv8.2 fp16 instruction. */
15510 if (rs == NS_HHH)
15511 do_scalar_fp16_v82_encode ();
037e8744
JB
15512 }
15513 else
15514 {
15515 if (is_mla)
477330fc 15516 do_vfp_nsyn_opcode ("fmacd");
037e8744 15517 else
477330fc 15518 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15519 }
15520}
15521
62f3b8c8
PB
15522static void
15523do_vfp_nsyn_fma_fms (enum neon_shape rs)
15524{
15525 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15526
9db2f6b4 15527 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15528 {
15529 if (is_fma)
477330fc 15530 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15531 else
477330fc 15532 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15533
15534 /* ARMv8.2 fp16 instruction. */
15535 if (rs == NS_HHH)
15536 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15537 }
15538 else
15539 {
15540 if (is_fma)
477330fc 15541 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15542 else
477330fc 15543 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15544 }
15545}
15546
037e8744
JB
15547static void
15548do_vfp_nsyn_mul (enum neon_shape rs)
15549{
9db2f6b4
RL
15550 if (rs == NS_FFF || rs == NS_HHH)
15551 {
15552 do_vfp_nsyn_opcode ("fmuls");
15553
15554 /* ARMv8.2 fp16 instruction. */
15555 if (rs == NS_HHH)
15556 do_scalar_fp16_v82_encode ();
15557 }
037e8744
JB
15558 else
15559 do_vfp_nsyn_opcode ("fmuld");
15560}
15561
15562static void
15563do_vfp_nsyn_abs_neg (enum neon_shape rs)
15564{
15565 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15566 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15567
9db2f6b4 15568 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15569 {
15570 if (is_neg)
477330fc 15571 do_vfp_nsyn_opcode ("fnegs");
037e8744 15572 else
477330fc 15573 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15574
15575 /* ARMv8.2 fp16 instruction. */
15576 if (rs == NS_HH)
15577 do_scalar_fp16_v82_encode ();
037e8744
JB
15578 }
15579 else
15580 {
15581 if (is_neg)
477330fc 15582 do_vfp_nsyn_opcode ("fnegd");
037e8744 15583 else
477330fc 15584 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15585 }
15586}
15587
15588/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15589 insns belong to Neon, and are handled elsewhere. */
15590
15591static void
15592do_vfp_nsyn_ldm_stm (int is_dbmode)
15593{
15594 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15595 if (is_ldm)
15596 {
15597 if (is_dbmode)
477330fc 15598 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15599 else
477330fc 15600 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15601 }
15602 else
15603 {
15604 if (is_dbmode)
477330fc 15605 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15606 else
477330fc 15607 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15608 }
15609}
15610
037e8744
JB
15611static void
15612do_vfp_nsyn_sqrt (void)
15613{
9db2f6b4
RL
15614 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15615 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15616
9db2f6b4
RL
15617 if (rs == NS_FF || rs == NS_HH)
15618 {
15619 do_vfp_nsyn_opcode ("fsqrts");
15620
15621 /* ARMv8.2 fp16 instruction. */
15622 if (rs == NS_HH)
15623 do_scalar_fp16_v82_encode ();
15624 }
037e8744
JB
15625 else
15626 do_vfp_nsyn_opcode ("fsqrtd");
15627}
15628
15629static void
15630do_vfp_nsyn_div (void)
15631{
9db2f6b4 15632 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15633 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15634 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15635
9db2f6b4
RL
15636 if (rs == NS_FFF || rs == NS_HHH)
15637 {
15638 do_vfp_nsyn_opcode ("fdivs");
15639
15640 /* ARMv8.2 fp16 instruction. */
15641 if (rs == NS_HHH)
15642 do_scalar_fp16_v82_encode ();
15643 }
037e8744
JB
15644 else
15645 do_vfp_nsyn_opcode ("fdivd");
15646}
15647
15648static void
15649do_vfp_nsyn_nmul (void)
15650{
9db2f6b4 15651 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15652 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15653 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15654
9db2f6b4 15655 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15656 {
88714cb8 15657 NEON_ENCODE (SINGLE, inst);
037e8744 15658 do_vfp_sp_dyadic ();
9db2f6b4
RL
15659
15660 /* ARMv8.2 fp16 instruction. */
15661 if (rs == NS_HHH)
15662 do_scalar_fp16_v82_encode ();
037e8744
JB
15663 }
15664 else
15665 {
88714cb8 15666 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15667 do_vfp_dp_rd_rn_rm ();
15668 }
15669 do_vfp_cond_or_thumb ();
9db2f6b4 15670
037e8744
JB
15671}
15672
1b883319
AV
15673/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15674 (0, 1, 2, 3). */
15675
15676static unsigned
15677neon_logbits (unsigned x)
15678{
15679 return ffs (x) - 4;
15680}
15681
15682#define LOW4(R) ((R) & 0xf)
15683#define HI1(R) (((R) >> 4) & 1)
15684
15685static unsigned
15686mve_get_vcmp_vpt_cond (struct neon_type_el et)
15687{
15688 switch (et.type)
15689 {
15690 default:
15691 first_error (BAD_EL_TYPE);
15692 return 0;
15693 case NT_float:
15694 switch (inst.operands[0].imm)
15695 {
15696 default:
15697 first_error (_("invalid condition"));
15698 return 0;
15699 case 0x0:
15700 /* eq. */
15701 return 0;
15702 case 0x1:
15703 /* ne. */
15704 return 1;
15705 case 0xa:
15706 /* ge/ */
15707 return 4;
15708 case 0xb:
15709 /* lt. */
15710 return 5;
15711 case 0xc:
15712 /* gt. */
15713 return 6;
15714 case 0xd:
15715 /* le. */
15716 return 7;
15717 }
15718 case NT_integer:
15719 /* only accept eq and ne. */
15720 if (inst.operands[0].imm > 1)
15721 {
15722 first_error (_("invalid condition"));
15723 return 0;
15724 }
15725 return inst.operands[0].imm;
15726 case NT_unsigned:
15727 if (inst.operands[0].imm == 0x2)
15728 return 2;
15729 else if (inst.operands[0].imm == 0x8)
15730 return 3;
15731 else
15732 {
15733 first_error (_("invalid condition"));
15734 return 0;
15735 }
15736 case NT_signed:
15737 switch (inst.operands[0].imm)
15738 {
15739 default:
15740 first_error (_("invalid condition"));
15741 return 0;
15742 case 0xa:
15743 /* ge. */
15744 return 4;
15745 case 0xb:
15746 /* lt. */
15747 return 5;
15748 case 0xc:
15749 /* gt. */
15750 return 6;
15751 case 0xd:
15752 /* le. */
15753 return 7;
15754 }
15755 }
15756 /* Should be unreachable. */
15757 abort ();
15758}
15759
15760static void
15761do_mve_vpt (void)
15762{
15763 /* We are dealing with a vector predicated block. */
15764 if (inst.operands[0].present)
15765 {
15766 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15767 struct neon_type_el et
15768 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15769 N_EQK);
15770
15771 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15772
15773 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15774
15775 if (et.type == NT_invtype)
15776 return;
15777
15778 if (et.type == NT_float)
15779 {
15780 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15781 BAD_FPU);
15782 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
15783 inst.instruction |= (et.size == 16) << 28;
15784 inst.instruction |= 0x3 << 20;
15785 }
15786 else
15787 {
15788 constraint (et.size != 8 && et.size != 16 && et.size != 32,
15789 BAD_EL_TYPE);
15790 inst.instruction |= 1 << 28;
15791 inst.instruction |= neon_logbits (et.size) << 20;
15792 }
15793
15794 if (inst.operands[2].isquad)
15795 {
15796 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15797 inst.instruction |= LOW4 (inst.operands[2].reg);
15798 inst.instruction |= (fcond & 0x2) >> 1;
15799 }
15800 else
15801 {
15802 if (inst.operands[2].reg == REG_SP)
15803 as_tsktsk (MVE_BAD_SP);
15804 inst.instruction |= 1 << 6;
15805 inst.instruction |= (fcond & 0x2) << 4;
15806 inst.instruction |= inst.operands[2].reg;
15807 }
15808 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15809 inst.instruction |= (fcond & 0x4) << 10;
15810 inst.instruction |= (fcond & 0x1) << 7;
15811
15812 }
15813 set_pred_insn_type (VPT_INSN);
15814 now_pred.cc = 0;
15815 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
15816 | ((inst.instruction & 0xe000) >> 13);
15817 now_pred.warn_deprecated = FALSE;
15818 now_pred.type = VECTOR_PRED;
15819 inst.is_neon = 1;
15820}
15821
15822static void
15823do_mve_vcmp (void)
15824{
15825 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
15826 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
15827 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
15828 if (!inst.operands[2].present)
15829 first_error (_("MVE vector or ARM register expected"));
15830 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15831
15832 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
15833 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
15834 && inst.operands[1].isquad)
15835 {
15836 inst.instruction = N_MNEM_vcmp;
15837 inst.cond = 0x10;
15838 }
15839
15840 if (inst.cond > COND_ALWAYS)
15841 inst.pred_insn_type = INSIDE_VPT_INSN;
15842 else
15843 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15844
15845 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15846 struct neon_type_el et
15847 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15848 N_EQK);
15849
15850 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
15851 && !inst.operands[2].iszr, BAD_PC);
15852
15853 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15854
15855 inst.instruction = 0xee010f00;
15856 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15857 inst.instruction |= (fcond & 0x4) << 10;
15858 inst.instruction |= (fcond & 0x1) << 7;
15859 if (et.type == NT_float)
15860 {
15861 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15862 BAD_FPU);
15863 inst.instruction |= (et.size == 16) << 28;
15864 inst.instruction |= 0x3 << 20;
15865 }
15866 else
15867 {
15868 inst.instruction |= 1 << 28;
15869 inst.instruction |= neon_logbits (et.size) << 20;
15870 }
15871 if (inst.operands[2].isquad)
15872 {
15873 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15874 inst.instruction |= (fcond & 0x2) >> 1;
15875 inst.instruction |= LOW4 (inst.operands[2].reg);
15876 }
15877 else
15878 {
15879 if (inst.operands[2].reg == REG_SP)
15880 as_tsktsk (MVE_BAD_SP);
15881 inst.instruction |= 1 << 6;
15882 inst.instruction |= (fcond & 0x2) << 4;
15883 inst.instruction |= inst.operands[2].reg;
15884 }
15885
15886 inst.is_neon = 1;
15887 return;
15888}
15889
935295b5
AV
15890static void
15891do_mve_vmaxa_vmina (void)
15892{
15893 if (inst.cond > COND_ALWAYS)
15894 inst.pred_insn_type = INSIDE_VPT_INSN;
15895 else
15896 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15897
15898 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
15899 struct neon_type_el et
15900 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
15901
15902 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15903 inst.instruction |= neon_logbits (et.size) << 18;
15904 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15905 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15906 inst.instruction |= LOW4 (inst.operands[1].reg);
15907 inst.is_neon = 1;
15908}
15909
f30ee27c
AV
15910static void
15911do_mve_vfmas (void)
15912{
15913 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15914 struct neon_type_el et
15915 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
15916
15917 if (inst.cond > COND_ALWAYS)
15918 inst.pred_insn_type = INSIDE_VPT_INSN;
15919 else
15920 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15921
15922 if (inst.operands[2].reg == REG_SP)
15923 as_tsktsk (MVE_BAD_SP);
15924 else if (inst.operands[2].reg == REG_PC)
15925 as_tsktsk (MVE_BAD_PC);
15926
15927 inst.instruction |= (et.size == 16) << 28;
15928 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15929 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15930 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15931 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15932 inst.instruction |= inst.operands[2].reg;
15933 inst.is_neon = 1;
15934}
15935
b409bdb6
AV
15936static void
15937do_mve_viddup (void)
15938{
15939 if (inst.cond > COND_ALWAYS)
15940 inst.pred_insn_type = INSIDE_VPT_INSN;
15941 else
15942 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15943
15944 unsigned imm = inst.relocs[0].exp.X_add_number;
15945 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
15946 _("immediate must be either 1, 2, 4 or 8"));
15947
15948 enum neon_shape rs;
15949 struct neon_type_el et;
15950 unsigned Rm;
15951 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
15952 {
15953 rs = neon_select_shape (NS_QRI, NS_NULL);
15954 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
15955 Rm = 7;
15956 }
15957 else
15958 {
15959 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
15960 if (inst.operands[2].reg == REG_SP)
15961 as_tsktsk (MVE_BAD_SP);
15962 else if (inst.operands[2].reg == REG_PC)
15963 first_error (BAD_PC);
15964
15965 rs = neon_select_shape (NS_QRRI, NS_NULL);
15966 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
15967 Rm = inst.operands[2].reg >> 1;
15968 }
15969 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15970 inst.instruction |= neon_logbits (et.size) << 20;
15971 inst.instruction |= inst.operands[1].reg << 16;
15972 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15973 inst.instruction |= (imm > 2) << 7;
15974 inst.instruction |= Rm << 1;
15975 inst.instruction |= (imm == 2 || imm == 8);
15976 inst.is_neon = 1;
15977}
15978
2d78f95b
AV
15979static void
15980do_mve_vmlas (void)
15981{
15982 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15983 struct neon_type_el et
15984 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
15985
15986 if (inst.operands[2].reg == REG_PC)
15987 as_tsktsk (MVE_BAD_PC);
15988 else if (inst.operands[2].reg == REG_SP)
15989 as_tsktsk (MVE_BAD_SP);
15990
15991 if (inst.cond > COND_ALWAYS)
15992 inst.pred_insn_type = INSIDE_VPT_INSN;
15993 else
15994 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15995
15996 inst.instruction |= (et.type == NT_unsigned) << 28;
15997 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15998 inst.instruction |= neon_logbits (et.size) << 20;
15999 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16000 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16001 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16002 inst.instruction |= inst.operands[2].reg;
16003 inst.is_neon = 1;
16004}
16005
acca5630
AV
16006static void
16007do_mve_vshll (void)
16008{
16009 struct neon_type_el et
16010 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16011
16012 if (inst.cond > COND_ALWAYS)
16013 inst.pred_insn_type = INSIDE_VPT_INSN;
16014 else
16015 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16016
16017 int imm = inst.operands[2].imm;
16018 constraint (imm < 1 || (unsigned)imm > et.size,
16019 _("immediate value out of range"));
16020
16021 if ((unsigned)imm == et.size)
16022 {
16023 inst.instruction |= neon_logbits (et.size) << 18;
16024 inst.instruction |= 0x110001;
16025 }
16026 else
16027 {
16028 inst.instruction |= (et.size + imm) << 16;
16029 inst.instruction |= 0x800140;
16030 }
16031
16032 inst.instruction |= (et.type == NT_unsigned) << 28;
16033 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16034 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16035 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16036 inst.instruction |= LOW4 (inst.operands[1].reg);
16037 inst.is_neon = 1;
16038}
16039
16040static void
16041do_mve_vshlc (void)
16042{
16043 if (inst.cond > COND_ALWAYS)
16044 inst.pred_insn_type = INSIDE_VPT_INSN;
16045 else
16046 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16047
16048 if (inst.operands[1].reg == REG_PC)
16049 as_tsktsk (MVE_BAD_PC);
16050 else if (inst.operands[1].reg == REG_SP)
16051 as_tsktsk (MVE_BAD_SP);
16052
16053 int imm = inst.operands[2].imm;
16054 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16055
16056 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16057 inst.instruction |= (imm & 0x1f) << 16;
16058 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16059 inst.instruction |= inst.operands[1].reg;
16060 inst.is_neon = 1;
16061}
16062
4aa88b50
AV
16063static void
16064do_mve_vshrn (void)
16065{
16066 unsigned types;
16067 switch (inst.instruction)
16068 {
16069 case M_MNEM_vshrnt:
16070 case M_MNEM_vshrnb:
16071 case M_MNEM_vrshrnt:
16072 case M_MNEM_vrshrnb:
16073 types = N_I16 | N_I32;
16074 break;
16075 case M_MNEM_vqshrnt:
16076 case M_MNEM_vqshrnb:
16077 case M_MNEM_vqrshrnt:
16078 case M_MNEM_vqrshrnb:
16079 types = N_U16 | N_U32 | N_S16 | N_S32;
16080 break;
16081 case M_MNEM_vqshrunt:
16082 case M_MNEM_vqshrunb:
16083 case M_MNEM_vqrshrunt:
16084 case M_MNEM_vqrshrunb:
16085 types = N_S16 | N_S32;
16086 break;
16087 default:
16088 abort ();
16089 }
16090
16091 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16092
16093 if (inst.cond > COND_ALWAYS)
16094 inst.pred_insn_type = INSIDE_VPT_INSN;
16095 else
16096 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16097
16098 unsigned Qd = inst.operands[0].reg;
16099 unsigned Qm = inst.operands[1].reg;
16100 unsigned imm = inst.operands[2].imm;
16101 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16102 et.size == 16
16103 ? _("immediate operand expected in the range [1,8]")
16104 : _("immediate operand expected in the range [1,16]"));
16105
16106 inst.instruction |= (et.type == NT_unsigned) << 28;
16107 inst.instruction |= HI1 (Qd) << 22;
16108 inst.instruction |= (et.size - imm) << 16;
16109 inst.instruction |= LOW4 (Qd) << 12;
16110 inst.instruction |= HI1 (Qm) << 5;
16111 inst.instruction |= LOW4 (Qm);
16112 inst.is_neon = 1;
16113}
16114
1be7aba3
AV
16115static void
16116do_mve_vqmovn (void)
16117{
16118 struct neon_type_el et;
16119 if (inst.instruction == M_MNEM_vqmovnt
16120 || inst.instruction == M_MNEM_vqmovnb)
16121 et = neon_check_type (2, NS_QQ, N_EQK,
16122 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16123 else
16124 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16125
16126 if (inst.cond > COND_ALWAYS)
16127 inst.pred_insn_type = INSIDE_VPT_INSN;
16128 else
16129 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16130
16131 inst.instruction |= (et.type == NT_unsigned) << 28;
16132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16133 inst.instruction |= (et.size == 32) << 18;
16134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16135 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16136 inst.instruction |= LOW4 (inst.operands[1].reg);
16137 inst.is_neon = 1;
16138}
16139
3063888e
AV
16140static void
16141do_mve_vpsel (void)
16142{
16143 neon_select_shape (NS_QQQ, NS_NULL);
16144
16145 if (inst.cond > COND_ALWAYS)
16146 inst.pred_insn_type = INSIDE_VPT_INSN;
16147 else
16148 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16149
16150 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16151 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16152 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16153 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16154 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16155 inst.instruction |= LOW4 (inst.operands[2].reg);
16156 inst.is_neon = 1;
16157}
16158
16159static void
16160do_mve_vpnot (void)
16161{
16162 if (inst.cond > COND_ALWAYS)
16163 inst.pred_insn_type = INSIDE_VPT_INSN;
16164 else
16165 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16166}
16167
935295b5
AV
16168static void
16169do_mve_vmaxnma_vminnma (void)
16170{
16171 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16172 struct neon_type_el et
16173 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16174
16175 if (inst.cond > COND_ALWAYS)
16176 inst.pred_insn_type = INSIDE_VPT_INSN;
16177 else
16178 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16179
16180 inst.instruction |= (et.size == 16) << 28;
16181 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16182 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16183 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16184 inst.instruction |= LOW4 (inst.operands[1].reg);
16185 inst.is_neon = 1;
16186}
16187
5d281bf0
AV
16188static void
16189do_mve_vcmul (void)
16190{
16191 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16192 struct neon_type_el et
16193 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16194
16195 if (inst.cond > COND_ALWAYS)
16196 inst.pred_insn_type = INSIDE_VPT_INSN;
16197 else
16198 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16199
16200 unsigned rot = inst.relocs[0].exp.X_add_number;
16201 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16202 _("immediate out of range"));
16203
16204 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16205 || inst.operands[0].reg == inst.operands[2].reg))
16206 as_tsktsk (BAD_MVE_SRCDEST);
16207
16208 inst.instruction |= (et.size == 32) << 28;
16209 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16210 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16211 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16212 inst.instruction |= (rot > 90) << 12;
16213 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16214 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16215 inst.instruction |= LOW4 (inst.operands[2].reg);
16216 inst.instruction |= (rot == 90 || rot == 270);
16217 inst.is_neon = 1;
16218}
16219
1f6234a3
AV
16220/* To handle the Low Overhead Loop instructions
16221 in Armv8.1-M Mainline and MVE. */
16222static void
16223do_t_loloop (void)
16224{
16225 unsigned long insn = inst.instruction;
16226
16227 inst.instruction = THUMB_OP32 (inst.instruction);
16228
16229 if (insn == T_MNEM_lctp)
16230 return;
16231
16232 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16233
16234 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16235 {
16236 struct neon_type_el et
16237 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16238 inst.instruction |= neon_logbits (et.size) << 20;
16239 inst.is_neon = 1;
16240 }
16241
16242 switch (insn)
16243 {
16244 case T_MNEM_letp:
16245 constraint (!inst.operands[0].present,
16246 _("expected LR"));
16247 /* fall through. */
16248 case T_MNEM_le:
16249 /* le <label>. */
16250 if (!inst.operands[0].present)
16251 inst.instruction |= 1 << 21;
16252
16253 v8_1_loop_reloc (TRUE);
16254 break;
16255
16256 case T_MNEM_wls:
16257 case T_MNEM_wlstp:
16258 v8_1_loop_reloc (FALSE);
16259 /* fall through. */
16260 case T_MNEM_dlstp:
16261 case T_MNEM_dls:
16262 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16263
16264 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16265 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16266 else if (inst.operands[1].reg == REG_PC)
16267 as_tsktsk (MVE_BAD_PC);
16268 if (inst.operands[1].reg == REG_SP)
16269 as_tsktsk (MVE_BAD_SP);
16270
16271 inst.instruction |= (inst.operands[1].reg << 16);
16272 break;
16273
16274 default:
16275 abort ();
16276 }
16277}
16278
16279
037e8744
JB
16280static void
16281do_vfp_nsyn_cmp (void)
16282{
9db2f6b4 16283 enum neon_shape rs;
1b883319
AV
16284 if (!inst.operands[0].isreg)
16285 {
16286 do_mve_vcmp ();
16287 return;
16288 }
16289 else
16290 {
16291 constraint (inst.operands[2].present, BAD_SYNTAX);
16292 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16293 BAD_FPU);
16294 }
16295
037e8744
JB
16296 if (inst.operands[1].isreg)
16297 {
9db2f6b4
RL
16298 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16299 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16300
9db2f6b4 16301 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16302 {
16303 NEON_ENCODE (SINGLE, inst);
16304 do_vfp_sp_monadic ();
16305 }
037e8744 16306 else
477330fc
RM
16307 {
16308 NEON_ENCODE (DOUBLE, inst);
16309 do_vfp_dp_rd_rm ();
16310 }
037e8744
JB
16311 }
16312 else
16313 {
9db2f6b4
RL
16314 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16315 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16316
16317 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16318 {
16319 case N_MNEM_vcmp:
16320 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16321 break;
16322 case N_MNEM_vcmpe:
16323 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16324 break;
16325 default:
16326 abort ();
16327 }
5f4273c7 16328
9db2f6b4 16329 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16330 {
16331 NEON_ENCODE (SINGLE, inst);
16332 do_vfp_sp_compare_z ();
16333 }
037e8744 16334 else
477330fc
RM
16335 {
16336 NEON_ENCODE (DOUBLE, inst);
16337 do_vfp_dp_rd ();
16338 }
037e8744
JB
16339 }
16340 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16341
16342 /* ARMv8.2 fp16 instruction. */
16343 if (rs == NS_HI || rs == NS_HH)
16344 do_scalar_fp16_v82_encode ();
037e8744
JB
16345}
16346
16347static void
16348nsyn_insert_sp (void)
16349{
16350 inst.operands[1] = inst.operands[0];
16351 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16352 inst.operands[0].reg = REG_SP;
037e8744
JB
16353 inst.operands[0].isreg = 1;
16354 inst.operands[0].writeback = 1;
16355 inst.operands[0].present = 1;
16356}
16357
16358static void
16359do_vfp_nsyn_push (void)
16360{
16361 nsyn_insert_sp ();
b126985e
NC
16362
16363 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16364 _("register list must contain at least 1 and at most 16 "
16365 "registers"));
16366
037e8744
JB
16367 if (inst.operands[1].issingle)
16368 do_vfp_nsyn_opcode ("fstmdbs");
16369 else
16370 do_vfp_nsyn_opcode ("fstmdbd");
16371}
16372
16373static void
16374do_vfp_nsyn_pop (void)
16375{
16376 nsyn_insert_sp ();
b126985e
NC
16377
16378 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16379 _("register list must contain at least 1 and at most 16 "
16380 "registers"));
16381
037e8744 16382 if (inst.operands[1].issingle)
22b5b651 16383 do_vfp_nsyn_opcode ("fldmias");
037e8744 16384 else
22b5b651 16385 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
16386}
16387
16388/* Fix up Neon data-processing instructions, ORing in the correct bits for
16389 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16390
88714cb8
DG
16391static void
16392neon_dp_fixup (struct arm_it* insn)
037e8744 16393{
88714cb8
DG
16394 unsigned int i = insn->instruction;
16395 insn->is_neon = 1;
16396
037e8744
JB
16397 if (thumb_mode)
16398 {
16399 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16400 if (i & (1 << 24))
477330fc 16401 i |= 1 << 28;
5f4273c7 16402
037e8744 16403 i &= ~(1 << 24);
5f4273c7 16404
037e8744
JB
16405 i |= 0xef000000;
16406 }
16407 else
16408 i |= 0xf2000000;
5f4273c7 16409
88714cb8 16410 insn->instruction = i;
037e8744
JB
16411}
16412
5ee91343 16413static void
7df54120 16414mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16415{
16416 if (inst.operands[2].reg == REG_SP)
16417 as_tsktsk (MVE_BAD_SP);
16418 else if (inst.operands[2].reg == REG_PC)
16419 as_tsktsk (MVE_BAD_PC);
16420
16421 if (fp)
16422 {
16423 /* vadd. */
16424 if (((unsigned)inst.instruction) == 0xd00)
16425 inst.instruction = 0xee300f40;
16426 /* vsub. */
16427 else if (((unsigned)inst.instruction) == 0x200d00)
16428 inst.instruction = 0xee301f40;
a8465a06
AV
16429 /* vmul. */
16430 else if (((unsigned)inst.instruction) == 0x1000d10)
16431 inst.instruction = 0xee310e60;
5ee91343
AV
16432
16433 /* Setting size which is 1 for F16 and 0 for F32. */
16434 inst.instruction |= (size == 16) << 28;
16435 }
16436 else
16437 {
16438 /* vadd. */
16439 if (((unsigned)inst.instruction) == 0x800)
16440 inst.instruction = 0xee010f40;
16441 /* vsub. */
16442 else if (((unsigned)inst.instruction) == 0x1000800)
16443 inst.instruction = 0xee011f40;
7df54120
AV
16444 /* vhadd. */
16445 else if (((unsigned)inst.instruction) == 0)
16446 inst.instruction = 0xee000f40;
16447 /* vhsub. */
16448 else if (((unsigned)inst.instruction) == 0x200)
16449 inst.instruction = 0xee001f40;
a8465a06
AV
16450 /* vmla. */
16451 else if (((unsigned)inst.instruction) == 0x900)
16452 inst.instruction = 0xee010e40;
16453 /* vmul. */
16454 else if (((unsigned)inst.instruction) == 0x910)
16455 inst.instruction = 0xee011e60;
16456 /* vqadd. */
16457 else if (((unsigned)inst.instruction) == 0x10)
16458 inst.instruction = 0xee000f60;
16459 /* vqsub. */
16460 else if (((unsigned)inst.instruction) == 0x210)
16461 inst.instruction = 0xee001f60;
42b16635
AV
16462 /* vqrdmlah. */
16463 else if (((unsigned)inst.instruction) == 0x3000b10)
16464 inst.instruction = 0xee000e40;
16465 /* vqdmulh. */
16466 else if (((unsigned)inst.instruction) == 0x0000b00)
16467 inst.instruction = 0xee010e60;
16468 /* vqrdmulh. */
16469 else if (((unsigned)inst.instruction) == 0x1000b00)
16470 inst.instruction = 0xfe010e60;
7df54120
AV
16471
16472 /* Set U-bit. */
16473 inst.instruction |= U << 28;
16474
5ee91343
AV
16475 /* Setting bits for size. */
16476 inst.instruction |= neon_logbits (size) << 20;
16477 }
16478 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16479 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16480 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16481 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16482 inst.instruction |= inst.operands[2].reg;
16483 inst.is_neon = 1;
16484}
16485
a302e574
AV
16486static void
16487mve_encode_rqq (unsigned bit28, unsigned size)
16488{
16489 inst.instruction |= bit28 << 28;
16490 inst.instruction |= neon_logbits (size) << 20;
16491 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16492 inst.instruction |= inst.operands[0].reg << 12;
16493 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16494 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16495 inst.instruction |= LOW4 (inst.operands[2].reg);
16496 inst.is_neon = 1;
16497}
16498
886e1c73
AV
16499static void
16500mve_encode_qqq (int ubit, int size)
16501{
16502
16503 inst.instruction |= (ubit != 0) << 28;
16504 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16505 inst.instruction |= neon_logbits (size) << 20;
16506 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16507 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16508 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16509 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16510 inst.instruction |= LOW4 (inst.operands[2].reg);
16511
16512 inst.is_neon = 1;
16513}
16514
26c1e780
AV
16515static void
16516mve_encode_rq (unsigned bit28, unsigned size)
16517{
16518 inst.instruction |= bit28 << 28;
16519 inst.instruction |= neon_logbits (size) << 18;
16520 inst.instruction |= inst.operands[0].reg << 12;
16521 inst.instruction |= LOW4 (inst.operands[1].reg);
16522 inst.is_neon = 1;
16523}
886e1c73 16524
93925576
AV
16525static void
16526mve_encode_rrqq (unsigned U, unsigned size)
16527{
16528 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16529
16530 inst.instruction |= U << 28;
16531 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16532 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16533 inst.instruction |= (size == 32) << 16;
16534 inst.instruction |= inst.operands[0].reg << 12;
16535 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16536 inst.instruction |= inst.operands[3].reg;
16537 inst.is_neon = 1;
16538}
16539
037e8744
JB
16540/* Encode insns with bit pattern:
16541
16542 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16543 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16544
037e8744
JB
16545 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16546 different meaning for some instruction. */
16547
16548static void
16549neon_three_same (int isquad, int ubit, int size)
16550{
16551 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16552 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16553 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16554 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16555 inst.instruction |= LOW4 (inst.operands[2].reg);
16556 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16557 inst.instruction |= (isquad != 0) << 6;
16558 inst.instruction |= (ubit != 0) << 24;
16559 if (size != -1)
16560 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16561
88714cb8 16562 neon_dp_fixup (&inst);
037e8744
JB
16563}
16564
16565/* Encode instructions of the form:
16566
16567 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16568 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16569
16570 Don't write size if SIZE == -1. */
16571
16572static void
16573neon_two_same (int qbit, int ubit, int size)
16574{
16575 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16576 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16577 inst.instruction |= LOW4 (inst.operands[1].reg);
16578 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16579 inst.instruction |= (qbit != 0) << 6;
16580 inst.instruction |= (ubit != 0) << 24;
16581
16582 if (size != -1)
16583 inst.instruction |= neon_logbits (size) << 18;
16584
88714cb8 16585 neon_dp_fixup (&inst);
5287ad62
JB
16586}
16587
7df54120
AV
16588enum vfp_or_neon_is_neon_bits
16589{
16590NEON_CHECK_CC = 1,
16591NEON_CHECK_ARCH = 2,
16592NEON_CHECK_ARCH8 = 4
16593};
16594
16595/* Call this function if an instruction which may have belonged to the VFP or
16596 Neon instruction sets, but turned out to be a Neon instruction (due to the
16597 operand types involved, etc.). We have to check and/or fix-up a couple of
16598 things:
16599
16600 - Make sure the user hasn't attempted to make a Neon instruction
16601 conditional.
16602 - Alter the value in the condition code field if necessary.
16603 - Make sure that the arch supports Neon instructions.
16604
16605 Which of these operations take place depends on bits from enum
16606 vfp_or_neon_is_neon_bits.
16607
16608 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16609 current instruction's condition is COND_ALWAYS, the condition field is
16610 changed to inst.uncond_value. This is necessary because instructions shared
16611 between VFP and Neon may be conditional for the VFP variants only, and the
16612 unconditional Neon version must have, e.g., 0xF in the condition field. */
16613
16614static int
16615vfp_or_neon_is_neon (unsigned check)
16616{
16617/* Conditions are always legal in Thumb mode (IT blocks). */
16618if (!thumb_mode && (check & NEON_CHECK_CC))
16619 {
16620 if (inst.cond != COND_ALWAYS)
16621 {
16622 first_error (_(BAD_COND));
16623 return FAIL;
16624 }
16625 if (inst.uncond_value != -1)
16626 inst.instruction |= inst.uncond_value << 28;
16627 }
16628
16629
16630 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16631 || ((check & NEON_CHECK_ARCH8)
16632 && !mark_feature_used (&fpu_neon_ext_armv8)))
16633 {
16634 first_error (_(BAD_FPU));
16635 return FAIL;
16636 }
16637
16638return SUCCESS;
16639}
16640
64c350f2
AV
16641
16642/* Return TRUE if the SIMD instruction is available for the current
16643 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16644 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16645 vfp_or_neon_is_neon for the NEON specific checks. */
16646
16647static bfd_boolean
7df54120
AV
16648check_simd_pred_availability (int fp, unsigned check)
16649{
16650if (inst.cond > COND_ALWAYS)
16651 {
16652 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16653 {
16654 inst.error = BAD_FPU;
64c350f2 16655 return FALSE;
7df54120
AV
16656 }
16657 inst.pred_insn_type = INSIDE_VPT_INSN;
16658 }
16659else if (inst.cond < COND_ALWAYS)
16660 {
16661 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16662 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16663 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16664 return FALSE;
7df54120
AV
16665 }
16666else
16667 {
16668 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16669 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16670 return FALSE;
7df54120
AV
16671
16672 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16673 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16674 }
64c350f2 16675return TRUE;
7df54120
AV
16676}
16677
5287ad62
JB
16678/* Neon instruction encoders, in approximate order of appearance. */
16679
16680static void
16681do_neon_dyadic_i_su (void)
16682{
64c350f2 16683 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16684 return;
16685
16686 enum neon_shape rs;
16687 struct neon_type_el et;
16688 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16689 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16690 else
16691 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16692
16693 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16694
16695
16696 if (rs != NS_QQR)
16697 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16698 else
16699 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16700}
16701
16702static void
16703do_neon_dyadic_i64_su (void)
16704{
64c350f2 16705 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16706 return;
16707 enum neon_shape rs;
16708 struct neon_type_el et;
16709 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16710 {
16711 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16712 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16713 }
16714 else
16715 {
16716 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16717 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16718 }
16719 if (rs == NS_QQR)
16720 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16721 else
16722 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16723}
16724
16725static void
16726neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16727 unsigned immbits)
5287ad62
JB
16728{
16729 unsigned size = et.size >> 3;
16730 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16731 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16732 inst.instruction |= LOW4 (inst.operands[1].reg);
16733 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16734 inst.instruction |= (isquad != 0) << 6;
16735 inst.instruction |= immbits << 16;
16736 inst.instruction |= (size >> 3) << 7;
16737 inst.instruction |= (size & 0x7) << 19;
16738 if (write_ubit)
16739 inst.instruction |= (uval != 0) << 24;
16740
88714cb8 16741 neon_dp_fixup (&inst);
5287ad62
JB
16742}
16743
16744static void
5150f0d8 16745do_neon_shl (void)
5287ad62 16746{
64c350f2 16747 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16748 return;
16749
5287ad62
JB
16750 if (!inst.operands[2].isreg)
16751 {
5150f0d8
AV
16752 enum neon_shape rs;
16753 struct neon_type_el et;
16754 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16755 {
16756 rs = neon_select_shape (NS_QQI, NS_NULL);
16757 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16758 }
16759 else
16760 {
16761 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16762 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16763 }
cb3b1e65
JB
16764 int imm = inst.operands[2].imm;
16765
16766 constraint (imm < 0 || (unsigned)imm >= et.size,
16767 _("immediate out of range for shift"));
88714cb8 16768 NEON_ENCODE (IMMED, inst);
cb3b1e65 16769 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16770 }
16771 else
16772 {
5150f0d8
AV
16773 enum neon_shape rs;
16774 struct neon_type_el et;
16775 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16776 {
16777 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16778 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16779 }
16780 else
16781 {
16782 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16783 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16784 }
16785
16786
16787 if (rs == NS_QQR)
16788 {
16789 constraint (inst.operands[0].reg != inst.operands[1].reg,
16790 _("invalid instruction shape"));
16791 if (inst.operands[2].reg == REG_SP)
16792 as_tsktsk (MVE_BAD_SP);
16793 else if (inst.operands[2].reg == REG_PC)
16794 as_tsktsk (MVE_BAD_PC);
16795
16796 inst.instruction = 0xee311e60;
16797 inst.instruction |= (et.type == NT_unsigned) << 28;
16798 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16799 inst.instruction |= neon_logbits (et.size) << 18;
16800 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16801 inst.instruction |= inst.operands[2].reg;
16802 inst.is_neon = 1;
16803 }
16804 else
16805 {
16806 unsigned int tmp;
16807
16808 /* VSHL/VQSHL 3-register variants have syntax such as:
16809 vshl.xx Dd, Dm, Dn
16810 whereas other 3-register operations encoded by neon_three_same have
16811 syntax like:
16812 vadd.xx Dd, Dn, Dm
16813 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
16814 operands[2].reg here. */
16815 tmp = inst.operands[2].reg;
16816 inst.operands[2].reg = inst.operands[1].reg;
16817 inst.operands[1].reg = tmp;
16818 NEON_ENCODE (INTEGER, inst);
16819 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16820 }
5287ad62
JB
16821 }
16822}
16823
16824static void
5150f0d8 16825do_neon_qshl (void)
5287ad62 16826{
64c350f2 16827 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16828 return;
16829
5287ad62
JB
16830 if (!inst.operands[2].isreg)
16831 {
5150f0d8
AV
16832 enum neon_shape rs;
16833 struct neon_type_el et;
16834 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16835 {
16836 rs = neon_select_shape (NS_QQI, NS_NULL);
16837 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
16838 }
16839 else
16840 {
16841 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16842 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16843 }
cb3b1e65 16844 int imm = inst.operands[2].imm;
627907b7 16845
cb3b1e65
JB
16846 constraint (imm < 0 || (unsigned)imm >= et.size,
16847 _("immediate out of range for shift"));
88714cb8 16848 NEON_ENCODE (IMMED, inst);
cb3b1e65 16849 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
16850 }
16851 else
16852 {
5150f0d8
AV
16853 enum neon_shape rs;
16854 struct neon_type_el et;
627907b7 16855
5150f0d8
AV
16856 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16857 {
16858 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16859 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16860 }
16861 else
16862 {
16863 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16864 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16865 }
16866
16867 if (rs == NS_QQR)
16868 {
16869 constraint (inst.operands[0].reg != inst.operands[1].reg,
16870 _("invalid instruction shape"));
16871 if (inst.operands[2].reg == REG_SP)
16872 as_tsktsk (MVE_BAD_SP);
16873 else if (inst.operands[2].reg == REG_PC)
16874 as_tsktsk (MVE_BAD_PC);
16875
16876 inst.instruction = 0xee311ee0;
16877 inst.instruction |= (et.type == NT_unsigned) << 28;
16878 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16879 inst.instruction |= neon_logbits (et.size) << 18;
16880 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16881 inst.instruction |= inst.operands[2].reg;
16882 inst.is_neon = 1;
16883 }
16884 else
16885 {
16886 unsigned int tmp;
16887
16888 /* See note in do_neon_shl. */
16889 tmp = inst.operands[2].reg;
16890 inst.operands[2].reg = inst.operands[1].reg;
16891 inst.operands[1].reg = tmp;
16892 NEON_ENCODE (INTEGER, inst);
16893 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16894 }
5287ad62
JB
16895 }
16896}
16897
627907b7
JB
16898static void
16899do_neon_rshl (void)
16900{
64c350f2 16901 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
16902 return;
16903
16904 enum neon_shape rs;
16905 struct neon_type_el et;
16906 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16907 {
16908 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16909 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16910 }
16911 else
16912 {
16913 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16914 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16915 }
16916
627907b7
JB
16917 unsigned int tmp;
16918
1be7aba3
AV
16919 if (rs == NS_QQR)
16920 {
16921 if (inst.operands[2].reg == REG_PC)
16922 as_tsktsk (MVE_BAD_PC);
16923 else if (inst.operands[2].reg == REG_SP)
16924 as_tsktsk (MVE_BAD_SP);
16925
16926 constraint (inst.operands[0].reg != inst.operands[1].reg,
16927 _("invalid instruction shape"));
16928
16929 if (inst.instruction == 0x0000510)
16930 /* We are dealing with vqrshl. */
16931 inst.instruction = 0xee331ee0;
16932 else
16933 /* We are dealing with vrshl. */
16934 inst.instruction = 0xee331e60;
16935
16936 inst.instruction |= (et.type == NT_unsigned) << 28;
16937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16938 inst.instruction |= neon_logbits (et.size) << 18;
16939 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16940 inst.instruction |= inst.operands[2].reg;
16941 inst.is_neon = 1;
16942 }
16943 else
16944 {
16945 tmp = inst.operands[2].reg;
16946 inst.operands[2].reg = inst.operands[1].reg;
16947 inst.operands[1].reg = tmp;
16948 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16949 }
627907b7
JB
16950}
16951
5287ad62
JB
16952static int
16953neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
16954{
036dc3f7
PB
16955 /* Handle .I8 pseudo-instructions. */
16956 if (size == 8)
5287ad62 16957 {
5287ad62 16958 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
16959 FIXME is this the intended semantics? There doesn't seem much point in
16960 accepting .I8 if so. */
5287ad62
JB
16961 immediate |= immediate << 8;
16962 size = 16;
036dc3f7
PB
16963 }
16964
16965 if (size >= 32)
16966 {
16967 if (immediate == (immediate & 0x000000ff))
16968 {
16969 *immbits = immediate;
16970 return 0x1;
16971 }
16972 else if (immediate == (immediate & 0x0000ff00))
16973 {
16974 *immbits = immediate >> 8;
16975 return 0x3;
16976 }
16977 else if (immediate == (immediate & 0x00ff0000))
16978 {
16979 *immbits = immediate >> 16;
16980 return 0x5;
16981 }
16982 else if (immediate == (immediate & 0xff000000))
16983 {
16984 *immbits = immediate >> 24;
16985 return 0x7;
16986 }
16987 if ((immediate & 0xffff) != (immediate >> 16))
16988 goto bad_immediate;
16989 immediate &= 0xffff;
5287ad62
JB
16990 }
16991
16992 if (immediate == (immediate & 0x000000ff))
16993 {
16994 *immbits = immediate;
036dc3f7 16995 return 0x9;
5287ad62
JB
16996 }
16997 else if (immediate == (immediate & 0x0000ff00))
16998 {
16999 *immbits = immediate >> 8;
036dc3f7 17000 return 0xb;
5287ad62
JB
17001 }
17002
17003 bad_immediate:
dcbf9037 17004 first_error (_("immediate value out of range"));
5287ad62
JB
17005 return FAIL;
17006}
17007
5287ad62
JB
17008static void
17009do_neon_logic (void)
17010{
17011 if (inst.operands[2].present && inst.operands[2].isreg)
17012 {
037e8744 17013 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17014 if (rs == NS_QQQ
64c350f2
AV
17015 && !check_simd_pred_availability (FALSE,
17016 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17017 return;
17018 else if (rs != NS_QQQ
17019 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17020 first_error (BAD_FPU);
17021
5287ad62
JB
17022 neon_check_type (3, rs, N_IGNORE_TYPE);
17023 /* U bit and size field were set as part of the bitmask. */
88714cb8 17024 NEON_ENCODE (INTEGER, inst);
037e8744 17025 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17026 }
17027 else
17028 {
4316f0d2
DG
17029 const int three_ops_form = (inst.operands[2].present
17030 && !inst.operands[2].isreg);
17031 const int immoperand = (three_ops_form ? 2 : 1);
17032 enum neon_shape rs = (three_ops_form
17033 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17034 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17035 /* Because neon_select_shape makes the second operand a copy of the first
17036 if the second operand is not present. */
17037 if (rs == NS_QQI
64c350f2
AV
17038 && !check_simd_pred_availability (FALSE,
17039 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17040 return;
17041 else if (rs != NS_QQI
17042 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17043 first_error (BAD_FPU);
17044
17045 struct neon_type_el et;
17046 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17047 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17048 else
17049 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17050 | N_KEY, N_EQK);
17051
17052 if (et.type == NT_invtype)
17053 return;
21d799b5 17054 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17055 unsigned immbits;
17056 int cmode;
5f4273c7 17057
5f4273c7 17058
4316f0d2
DG
17059 if (three_ops_form)
17060 constraint (inst.operands[0].reg != inst.operands[1].reg,
17061 _("first and second operands shall be the same register"));
17062
88714cb8 17063 NEON_ENCODE (IMMED, inst);
5287ad62 17064
4316f0d2 17065 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17066 if (et.size == 64)
17067 {
17068 /* .i64 is a pseudo-op, so the immediate must be a repeating
17069 pattern. */
4316f0d2
DG
17070 if (immbits != (inst.operands[immoperand].regisimm ?
17071 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17072 {
17073 /* Set immbits to an invalid constant. */
17074 immbits = 0xdeadbeef;
17075 }
17076 }
17077
5287ad62 17078 switch (opcode)
477330fc
RM
17079 {
17080 case N_MNEM_vbic:
17081 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17082 break;
17083
17084 case N_MNEM_vorr:
17085 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17086 break;
17087
17088 case N_MNEM_vand:
17089 /* Pseudo-instruction for VBIC. */
17090 neon_invert_size (&immbits, 0, et.size);
17091 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17092 break;
17093
17094 case N_MNEM_vorn:
17095 /* Pseudo-instruction for VORR. */
17096 neon_invert_size (&immbits, 0, et.size);
17097 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17098 break;
17099
17100 default:
17101 abort ();
17102 }
5287ad62
JB
17103
17104 if (cmode == FAIL)
477330fc 17105 return;
5287ad62 17106
037e8744 17107 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17108 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17109 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17110 inst.instruction |= cmode << 8;
17111 neon_write_immbits (immbits);
5f4273c7 17112
88714cb8 17113 neon_dp_fixup (&inst);
5287ad62
JB
17114 }
17115}
17116
17117static void
17118do_neon_bitfield (void)
17119{
037e8744 17120 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17121 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17122 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17123}
17124
17125static void
dcbf9037 17126neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17127 unsigned destbits)
5287ad62 17128{
5ee91343 17129 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17130 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17131 types | N_KEY);
5287ad62
JB
17132 if (et.type == NT_float)
17133 {
88714cb8 17134 NEON_ENCODE (FLOAT, inst);
5ee91343 17135 if (rs == NS_QQR)
7df54120 17136 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17137 else
17138 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17139 }
17140 else
17141 {
88714cb8 17142 NEON_ENCODE (INTEGER, inst);
5ee91343 17143 if (rs == NS_QQR)
a8465a06 17144 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17145 else
17146 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17147 }
17148}
17149
5287ad62
JB
17150
17151static void
17152do_neon_dyadic_if_su_d (void)
17153{
17154 /* This version only allow D registers, but that constraint is enforced during
17155 operand parsing so we don't need to do anything extra here. */
dcbf9037 17156 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17157}
17158
5287ad62
JB
17159static void
17160do_neon_dyadic_if_i_d (void)
17161{
428e3f1f
PB
17162 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17163 affected if we specify unsigned args. */
17164 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17165}
17166
f5f10c66
AV
17167static void
17168do_mve_vstr_vldr_QI (int size, int elsize, int load)
17169{
17170 constraint (size < 32, BAD_ADDR_MODE);
17171 constraint (size != elsize, BAD_EL_TYPE);
17172 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17173 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17174 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17175 _("destination register and offset register may not be the"
17176 " same"));
17177
17178 int imm = inst.relocs[0].exp.X_add_number;
17179 int add = 1;
17180 if (imm < 0)
17181 {
17182 add = 0;
17183 imm = -imm;
17184 }
17185 constraint ((imm % (size / 8) != 0)
17186 || imm > (0x7f << neon_logbits (size)),
17187 (size == 32) ? _("immediate must be a multiple of 4 in the"
17188 " range of +/-[0,508]")
17189 : _("immediate must be a multiple of 8 in the"
17190 " range of +/-[0,1016]"));
17191 inst.instruction |= 0x11 << 24;
17192 inst.instruction |= add << 23;
17193 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17194 inst.instruction |= inst.operands[1].writeback << 21;
17195 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17196 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17197 inst.instruction |= 1 << 12;
17198 inst.instruction |= (size == 64) << 8;
17199 inst.instruction &= 0xffffff00;
17200 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17201 inst.instruction |= imm >> neon_logbits (size);
17202}
17203
17204static void
17205do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17206{
17207 unsigned os = inst.operands[1].imm >> 5;
17208 constraint (os != 0 && size == 8,
17209 _("can not shift offsets when accessing less than half-word"));
17210 constraint (os && os != neon_logbits (size),
17211 _("shift immediate must be 1, 2 or 3 for half-word, word"
17212 " or double-word accesses respectively"));
17213 if (inst.operands[1].reg == REG_PC)
17214 as_tsktsk (MVE_BAD_PC);
17215
17216 switch (size)
17217 {
17218 case 8:
17219 constraint (elsize >= 64, BAD_EL_TYPE);
17220 break;
17221 case 16:
17222 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17223 break;
17224 case 32:
17225 case 64:
17226 constraint (elsize != size, BAD_EL_TYPE);
17227 break;
17228 default:
17229 break;
17230 }
17231 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17232 BAD_ADDR_MODE);
17233 if (load)
17234 {
17235 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17236 _("destination register and offset register may not be"
17237 " the same"));
17238 constraint (size == elsize && inst.vectype.el[0].type != NT_unsigned,
17239 BAD_EL_TYPE);
17240 constraint (inst.vectype.el[0].type != NT_unsigned
17241 && inst.vectype.el[0].type != NT_signed, BAD_EL_TYPE);
17242 inst.instruction |= (inst.vectype.el[0].type == NT_unsigned) << 28;
17243 }
17244 else
17245 {
17246 constraint (inst.vectype.el[0].type != NT_untyped, BAD_EL_TYPE);
17247 }
17248
17249 inst.instruction |= 1 << 23;
17250 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17251 inst.instruction |= inst.operands[1].reg << 16;
17252 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17253 inst.instruction |= neon_logbits (elsize) << 7;
17254 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17255 inst.instruction |= LOW4 (inst.operands[1].imm);
17256 inst.instruction |= !!os;
17257}
17258
17259static void
17260do_mve_vstr_vldr_RI (int size, int elsize, int load)
17261{
17262 enum neon_el_type type = inst.vectype.el[0].type;
17263
17264 constraint (size >= 64, BAD_ADDR_MODE);
17265 switch (size)
17266 {
17267 case 16:
17268 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17269 break;
17270 case 32:
17271 constraint (elsize != size, BAD_EL_TYPE);
17272 break;
17273 default:
17274 break;
17275 }
17276 if (load)
17277 {
17278 constraint (elsize != size && type != NT_unsigned
17279 && type != NT_signed, BAD_EL_TYPE);
17280 }
17281 else
17282 {
17283 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17284 }
17285
17286 int imm = inst.relocs[0].exp.X_add_number;
17287 int add = 1;
17288 if (imm < 0)
17289 {
17290 add = 0;
17291 imm = -imm;
17292 }
17293
17294 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17295 {
17296 switch (size)
17297 {
17298 case 8:
17299 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17300 break;
17301 case 16:
17302 constraint (1, _("immediate must be a multiple of 2 in the"
17303 " range of +/-[0,254]"));
17304 break;
17305 case 32:
17306 constraint (1, _("immediate must be a multiple of 4 in the"
17307 " range of +/-[0,508]"));
17308 break;
17309 }
17310 }
17311
17312 if (size != elsize)
17313 {
17314 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17315 constraint (inst.operands[0].reg > 14,
17316 _("MVE vector register in the range [Q0..Q7] expected"));
17317 inst.instruction |= (load && type == NT_unsigned) << 28;
17318 inst.instruction |= (size == 16) << 19;
17319 inst.instruction |= neon_logbits (elsize) << 7;
17320 }
17321 else
17322 {
17323 if (inst.operands[1].reg == REG_PC)
17324 as_tsktsk (MVE_BAD_PC);
17325 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17326 as_tsktsk (MVE_BAD_SP);
17327 inst.instruction |= 1 << 12;
17328 inst.instruction |= neon_logbits (size) << 7;
17329 }
17330 inst.instruction |= inst.operands[1].preind << 24;
17331 inst.instruction |= add << 23;
17332 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17333 inst.instruction |= inst.operands[1].writeback << 21;
17334 inst.instruction |= inst.operands[1].reg << 16;
17335 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17336 inst.instruction &= 0xffffff80;
17337 inst.instruction |= imm >> neon_logbits (size);
17338
17339}
17340
17341static void
17342do_mve_vstr_vldr (void)
17343{
17344 unsigned size;
17345 int load = 0;
17346
17347 if (inst.cond > COND_ALWAYS)
17348 inst.pred_insn_type = INSIDE_VPT_INSN;
17349 else
17350 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17351
17352 switch (inst.instruction)
17353 {
17354 default:
17355 gas_assert (0);
17356 break;
17357 case M_MNEM_vldrb:
17358 load = 1;
17359 /* fall through. */
17360 case M_MNEM_vstrb:
17361 size = 8;
17362 break;
17363 case M_MNEM_vldrh:
17364 load = 1;
17365 /* fall through. */
17366 case M_MNEM_vstrh:
17367 size = 16;
17368 break;
17369 case M_MNEM_vldrw:
17370 load = 1;
17371 /* fall through. */
17372 case M_MNEM_vstrw:
17373 size = 32;
17374 break;
17375 case M_MNEM_vldrd:
17376 load = 1;
17377 /* fall through. */
17378 case M_MNEM_vstrd:
17379 size = 64;
17380 break;
17381 }
17382 unsigned elsize = inst.vectype.el[0].size;
17383
17384 if (inst.operands[1].isquad)
17385 {
17386 /* We are dealing with [Q, imm]{!} cases. */
17387 do_mve_vstr_vldr_QI (size, elsize, load);
17388 }
17389 else
17390 {
17391 if (inst.operands[1].immisreg == 2)
17392 {
17393 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17394 do_mve_vstr_vldr_RQ (size, elsize, load);
17395 }
17396 else if (!inst.operands[1].immisreg)
17397 {
17398 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17399 do_mve_vstr_vldr_RI (size, elsize, load);
17400 }
17401 else
17402 constraint (1, BAD_ADDR_MODE);
17403 }
17404
17405 inst.is_neon = 1;
17406}
17407
35c228db
AV
17408static void
17409do_mve_vst_vld (void)
17410{
17411 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17412 return;
17413
17414 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17415 || inst.relocs[0].exp.X_add_number != 0
17416 || inst.operands[1].immisreg != 0,
17417 BAD_ADDR_MODE);
17418 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17419 if (inst.operands[1].reg == REG_PC)
17420 as_tsktsk (MVE_BAD_PC);
17421 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17422 as_tsktsk (MVE_BAD_SP);
17423
17424
17425 /* These instructions are one of the "exceptions" mentioned in
17426 handle_pred_state. They are MVE instructions that are not VPT compatible
17427 and do not accept a VPT code, thus appending such a code is a syntax
17428 error. */
17429 if (inst.cond > COND_ALWAYS)
17430 first_error (BAD_SYNTAX);
17431 /* If we append a scalar condition code we can set this to
17432 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17433 else if (inst.cond < COND_ALWAYS)
17434 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17435 else
17436 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17437
17438 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17439 inst.instruction |= inst.operands[1].writeback << 21;
17440 inst.instruction |= inst.operands[1].reg << 16;
17441 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17442 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17443 inst.is_neon = 1;
17444}
17445
26c1e780
AV
17446static void
17447do_mve_vaddlv (void)
17448{
17449 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17450 struct neon_type_el et
17451 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17452
17453 if (et.type == NT_invtype)
17454 first_error (BAD_EL_TYPE);
17455
17456 if (inst.cond > COND_ALWAYS)
17457 inst.pred_insn_type = INSIDE_VPT_INSN;
17458 else
17459 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17460
17461 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17462
17463 inst.instruction |= (et.type == NT_unsigned) << 28;
17464 inst.instruction |= inst.operands[1].reg << 19;
17465 inst.instruction |= inst.operands[0].reg << 12;
17466 inst.instruction |= inst.operands[2].reg;
17467 inst.is_neon = 1;
17468}
17469
5287ad62 17470static void
5ee91343 17471do_neon_dyadic_if_su (void)
5287ad62 17472{
5ee91343
AV
17473 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17474 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17475 N_SUF_32 | N_KEY);
17476
935295b5
AV
17477 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17478 || inst.instruction == ((unsigned) N_MNEM_vmin))
17479 && et.type == NT_float
17480 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17481
64c350f2
AV
17482 if (!check_simd_pred_availability (et.type == NT_float,
17483 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17484 return;
17485
5ee91343
AV
17486 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17487}
17488
17489static void
17490do_neon_addsub_if_i (void)
17491{
17492 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17493 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17494 return;
17495
5ee91343
AV
17496 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17497 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17498 N_EQK, N_IF_32 | N_I64 | N_KEY);
17499
17500 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17501 /* If we are parsing Q registers and the element types match MVE, which NEON
17502 also supports, then we must check whether this is an instruction that can
17503 be used by both MVE/NEON. This distinction can be made based on whether
17504 they are predicated or not. */
17505 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17506 {
64c350f2
AV
17507 if (!check_simd_pred_availability (et.type == NT_float,
17508 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17509 return;
17510 }
17511 else
17512 {
17513 /* If they are either in a D register or are using an unsupported. */
17514 if (rs != NS_QQR
17515 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17516 return;
17517 }
17518
5287ad62
JB
17519 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17520 affected if we specify unsigned args. */
dcbf9037 17521 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17522}
17523
17524/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17525 result to be:
17526 V<op> A,B (A is operand 0, B is operand 2)
17527 to mean:
17528 V<op> A,B,A
17529 not:
17530 V<op> A,B,B
17531 so handle that case specially. */
17532
17533static void
17534neon_exchange_operands (void)
17535{
5287ad62
JB
17536 if (inst.operands[1].present)
17537 {
e1fa0163
NC
17538 void *scratch = xmalloc (sizeof (inst.operands[0]));
17539
5287ad62
JB
17540 /* Swap operands[1] and operands[2]. */
17541 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17542 inst.operands[1] = inst.operands[2];
17543 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17544 free (scratch);
5287ad62
JB
17545 }
17546 else
17547 {
17548 inst.operands[1] = inst.operands[2];
17549 inst.operands[2] = inst.operands[0];
17550 }
17551}
17552
17553static void
17554neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17555{
17556 if (inst.operands[2].isreg)
17557 {
17558 if (invert)
477330fc 17559 neon_exchange_operands ();
dcbf9037 17560 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17561 }
17562 else
17563 {
037e8744 17564 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17565 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17566 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17567
88714cb8 17568 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17569 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17570 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17571 inst.instruction |= LOW4 (inst.operands[1].reg);
17572 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17573 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17574 inst.instruction |= (et.type == NT_float) << 10;
17575 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17576
88714cb8 17577 neon_dp_fixup (&inst);
5287ad62
JB
17578 }
17579}
17580
17581static void
17582do_neon_cmp (void)
17583{
cc933301 17584 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17585}
17586
17587static void
17588do_neon_cmp_inv (void)
17589{
cc933301 17590 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17591}
17592
17593static void
17594do_neon_ceq (void)
17595{
17596 neon_compare (N_IF_32, N_IF_32, FALSE);
17597}
17598
17599/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17600 scalars, which are encoded in 5 bits, M : Rm.
17601 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17602 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17603 index in M.
17604
17605 Dot Product instructions are similar to multiply instructions except elsize
17606 should always be 32.
17607
17608 This function translates SCALAR, which is GAS's internal encoding of indexed
17609 scalar register, to raw encoding. There is also register and index range
17610 check based on ELSIZE. */
5287ad62
JB
17611
17612static unsigned
17613neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17614{
dcbf9037
JB
17615 unsigned regno = NEON_SCALAR_REG (scalar);
17616 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17617
17618 switch (elsize)
17619 {
17620 case 16:
17621 if (regno > 7 || elno > 3)
477330fc 17622 goto bad_scalar;
5287ad62 17623 return regno | (elno << 3);
5f4273c7 17624
5287ad62
JB
17625 case 32:
17626 if (regno > 15 || elno > 1)
477330fc 17627 goto bad_scalar;
5287ad62
JB
17628 return regno | (elno << 4);
17629
17630 default:
17631 bad_scalar:
dcbf9037 17632 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17633 }
17634
17635 return 0;
17636}
17637
17638/* Encode multiply / multiply-accumulate scalar instructions. */
17639
17640static void
17641neon_mul_mac (struct neon_type_el et, int ubit)
17642{
dcbf9037
JB
17643 unsigned scalar;
17644
17645 /* Give a more helpful error message if we have an invalid type. */
17646 if (et.type == NT_invtype)
17647 return;
5f4273c7 17648
dcbf9037 17649 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17650 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17651 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17652 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17653 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17654 inst.instruction |= LOW4 (scalar);
17655 inst.instruction |= HI1 (scalar) << 5;
17656 inst.instruction |= (et.type == NT_float) << 8;
17657 inst.instruction |= neon_logbits (et.size) << 20;
17658 inst.instruction |= (ubit != 0) << 24;
17659
88714cb8 17660 neon_dp_fixup (&inst);
5287ad62
JB
17661}
17662
17663static void
17664do_neon_mac_maybe_scalar (void)
17665{
037e8744
JB
17666 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17667 return;
17668
64c350f2 17669 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17670 return;
17671
5287ad62
JB
17672 if (inst.operands[2].isscalar)
17673 {
a8465a06 17674 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17675 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17676 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17677 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17678 NEON_ENCODE (SCALAR, inst);
037e8744 17679 neon_mul_mac (et, neon_quad (rs));
5287ad62 17680 }
a8465a06
AV
17681 else if (!inst.operands[2].isvec)
17682 {
17683 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17684
17685 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17686 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17687
17688 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17689 }
5287ad62 17690 else
428e3f1f 17691 {
a8465a06 17692 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17693 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17694 affected if we specify unsigned args. */
17695 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17696 }
5287ad62
JB
17697}
17698
62f3b8c8
PB
17699static void
17700do_neon_fmac (void)
17701{
d58196e0
AV
17702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17703 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17704 return;
17705
64c350f2 17706 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17707 return;
17708
d58196e0
AV
17709 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17710 {
17711 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17712 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17713 N_EQK);
17714
17715 if (rs == NS_QQR)
17716 {
17717 if (inst.operands[2].reg == REG_SP)
17718 as_tsktsk (MVE_BAD_SP);
17719 else if (inst.operands[2].reg == REG_PC)
17720 as_tsktsk (MVE_BAD_PC);
17721
17722 inst.instruction = 0xee310e40;
17723 inst.instruction |= (et.size == 16) << 28;
17724 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17725 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17726 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17727 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17728 inst.instruction |= inst.operands[2].reg;
17729 inst.is_neon = 1;
17730 return;
17731 }
17732 }
17733 else
17734 {
17735 constraint (!inst.operands[2].isvec, BAD_FPU);
17736 }
17737
62f3b8c8
PB
17738 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17739}
17740
5287ad62
JB
17741static void
17742do_neon_tst (void)
17743{
037e8744 17744 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
17745 struct neon_type_el et = neon_check_type (3, rs,
17746 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 17747 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
17748}
17749
17750/* VMUL with 3 registers allows the P8 type. The scalar version supports the
17751 same types as the MAC equivalents. The polynomial type for this instruction
17752 is encoded the same as the integer type. */
17753
17754static void
17755do_neon_mul (void)
17756{
037e8744
JB
17757 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
17758 return;
17759
64c350f2 17760 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17761 return;
17762
5287ad62 17763 if (inst.operands[2].isscalar)
a8465a06
AV
17764 {
17765 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17766 do_neon_mac_maybe_scalar ();
17767 }
5287ad62 17768 else
a8465a06
AV
17769 {
17770 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17771 {
17772 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17773 struct neon_type_el et
17774 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
17775 if (et.type == NT_float)
17776 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
17777 BAD_FPU);
17778
17779 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
17780 }
17781 else
17782 {
17783 constraint (!inst.operands[2].isvec, BAD_FPU);
17784 neon_dyadic_misc (NT_poly,
17785 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
17786 }
17787 }
5287ad62
JB
17788}
17789
17790static void
17791do_neon_qdmulh (void)
17792{
64c350f2 17793 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
17794 return;
17795
5287ad62
JB
17796 if (inst.operands[2].isscalar)
17797 {
42b16635 17798 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17799 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17800 struct neon_type_el et = neon_check_type (3, rs,
477330fc 17801 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 17802 NEON_ENCODE (SCALAR, inst);
037e8744 17803 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
17804 }
17805 else
17806 {
42b16635
AV
17807 enum neon_shape rs;
17808 struct neon_type_el et;
17809 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17810 {
17811 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17812 et = neon_check_type (3, rs,
17813 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17814 }
17815 else
17816 {
17817 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17818 et = neon_check_type (3, rs,
17819 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17820 }
17821
88714cb8 17822 NEON_ENCODE (INTEGER, inst);
42b16635
AV
17823 if (rs == NS_QQR)
17824 mve_encode_qqr (et.size, 0, 0);
17825 else
17826 /* The U bit (rounding) comes from bit mask. */
17827 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
17828 }
17829}
17830
26c1e780
AV
17831static void
17832do_mve_vaddv (void)
17833{
17834 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
17835 struct neon_type_el et
17836 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17837
17838 if (et.type == NT_invtype)
17839 first_error (BAD_EL_TYPE);
17840
17841 if (inst.cond > COND_ALWAYS)
17842 inst.pred_insn_type = INSIDE_VPT_INSN;
17843 else
17844 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17845
17846 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17847
17848 mve_encode_rq (et.type == NT_unsigned, et.size);
17849}
17850
7df54120
AV
17851static void
17852do_mve_vhcadd (void)
17853{
17854 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
17855 struct neon_type_el et
17856 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17857
17858 if (inst.cond > COND_ALWAYS)
17859 inst.pred_insn_type = INSIDE_VPT_INSN;
17860 else
17861 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17862
17863 unsigned rot = inst.relocs[0].exp.X_add_number;
17864 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17865
17866 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
17867 as_tsktsk (_("Warning: 32-bit element size and same first and third "
17868 "operand makes instruction UNPREDICTABLE"));
17869
17870 mve_encode_qqq (0, et.size);
17871 inst.instruction |= (rot == 270) << 12;
17872 inst.is_neon = 1;
17873}
17874
35d1cfc2
AV
17875static void
17876do_mve_vqdmull (void)
17877{
17878 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17879 struct neon_type_el et
17880 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17881
17882 if (et.size == 32
17883 && (inst.operands[0].reg == inst.operands[1].reg
17884 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
17885 as_tsktsk (BAD_MVE_SRCDEST);
17886
17887 if (inst.cond > COND_ALWAYS)
17888 inst.pred_insn_type = INSIDE_VPT_INSN;
17889 else
17890 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17891
17892 if (rs == NS_QQQ)
17893 {
17894 mve_encode_qqq (et.size == 32, 64);
17895 inst.instruction |= 1;
17896 }
17897 else
17898 {
17899 mve_encode_qqr (64, et.size == 32, 0);
17900 inst.instruction |= 0x3 << 5;
17901 }
17902}
17903
c2dafc2a
AV
17904static void
17905do_mve_vadc (void)
17906{
17907 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17908 struct neon_type_el et
17909 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
17910
17911 if (et.type == NT_invtype)
17912 first_error (BAD_EL_TYPE);
17913
17914 if (inst.cond > COND_ALWAYS)
17915 inst.pred_insn_type = INSIDE_VPT_INSN;
17916 else
17917 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17918
17919 mve_encode_qqq (0, 64);
17920}
17921
17922static void
17923do_mve_vbrsr (void)
17924{
17925 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17926 struct neon_type_el et
17927 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
17928
17929 if (inst.cond > COND_ALWAYS)
17930 inst.pred_insn_type = INSIDE_VPT_INSN;
17931 else
17932 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17933
7df54120 17934 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
17935}
17936
17937static void
17938do_mve_vsbc (void)
17939{
17940 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
17941
17942 if (inst.cond > COND_ALWAYS)
17943 inst.pred_insn_type = INSIDE_VPT_INSN;
17944 else
17945 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17946
17947 mve_encode_qqq (1, 64);
17948}
17949
2d78f95b
AV
17950static void
17951do_mve_vmulh (void)
17952{
17953 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17954 struct neon_type_el et
17955 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17956
17957 if (inst.cond > COND_ALWAYS)
17958 inst.pred_insn_type = INSIDE_VPT_INSN;
17959 else
17960 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17961
17962 mve_encode_qqq (et.type == NT_unsigned, et.size);
17963}
17964
42b16635
AV
17965static void
17966do_mve_vqdmlah (void)
17967{
17968 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17969 struct neon_type_el et
23d188c7 17970 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
17971
17972 if (inst.cond > COND_ALWAYS)
17973 inst.pred_insn_type = INSIDE_VPT_INSN;
17974 else
17975 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17976
17977 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
17978}
8b8b22a4
AV
17979
17980static void
17981do_mve_vqdmladh (void)
17982{
17983 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17984 struct neon_type_el et
17985 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17986
17987 if (inst.cond > COND_ALWAYS)
17988 inst.pred_insn_type = INSIDE_VPT_INSN;
17989 else
17990 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17991
8b8b22a4
AV
17992 mve_encode_qqq (0, et.size);
17993}
17994
17995
886e1c73
AV
17996static void
17997do_mve_vmull (void)
17998{
17999
18000 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18001 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18002 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18003 && inst.cond == COND_ALWAYS
18004 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18005 {
18006 if (rs == NS_QQQ)
18007 {
18008
18009 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18010 N_SUF_32 | N_F64 | N_P8
18011 | N_P16 | N_I_MVE | N_KEY);
18012 if (((et.type == NT_poly) && et.size == 8
18013 && ARM_CPU_IS_ANY (cpu_variant))
18014 || (et.type == NT_integer) || (et.type == NT_float))
18015 goto neon_vmul;
18016 }
18017 else
18018 goto neon_vmul;
18019 }
18020
18021 constraint (rs != NS_QQQ, BAD_FPU);
18022 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18023 N_SU_32 | N_P8 | N_P16 | N_KEY);
18024
18025 /* We are dealing with MVE's vmullt. */
18026 if (et.size == 32
18027 && (inst.operands[0].reg == inst.operands[1].reg
18028 || inst.operands[0].reg == inst.operands[2].reg))
18029 as_tsktsk (BAD_MVE_SRCDEST);
18030
18031 if (inst.cond > COND_ALWAYS)
18032 inst.pred_insn_type = INSIDE_VPT_INSN;
18033 else
18034 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18035
18036 if (et.type == NT_poly)
18037 mve_encode_qqq (neon_logbits (et.size), 64);
18038 else
18039 mve_encode_qqq (et.type == NT_unsigned, et.size);
18040
18041 return;
18042
18043neon_vmul:
18044 inst.instruction = N_MNEM_vmul;
18045 inst.cond = 0xb;
18046 if (thumb_mode)
18047 inst.pred_insn_type = INSIDE_IT_INSN;
18048 do_neon_mul ();
18049}
18050
a302e574
AV
18051static void
18052do_mve_vabav (void)
18053{
18054 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18055
18056 if (rs == NS_NULL)
18057 return;
18058
18059 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18060 return;
18061
18062 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18063 | N_S16 | N_S32 | N_U8 | N_U16
18064 | N_U32);
18065
18066 if (inst.cond > COND_ALWAYS)
18067 inst.pred_insn_type = INSIDE_VPT_INSN;
18068 else
18069 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18070
18071 mve_encode_rqq (et.type == NT_unsigned, et.size);
18072}
18073
18074static void
18075do_mve_vmladav (void)
18076{
18077 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18078 struct neon_type_el et = neon_check_type (3, rs,
18079 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18080
18081 if (et.type == NT_unsigned
18082 && (inst.instruction == M_MNEM_vmladavx
18083 || inst.instruction == M_MNEM_vmladavax
18084 || inst.instruction == M_MNEM_vmlsdav
18085 || inst.instruction == M_MNEM_vmlsdava
18086 || inst.instruction == M_MNEM_vmlsdavx
18087 || inst.instruction == M_MNEM_vmlsdavax))
18088 first_error (BAD_SIMD_TYPE);
18089
18090 constraint (inst.operands[2].reg > 14,
18091 _("MVE vector register in the range [Q0..Q7] expected"));
18092
18093 if (inst.cond > COND_ALWAYS)
18094 inst.pred_insn_type = INSIDE_VPT_INSN;
18095 else
18096 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18097
18098 if (inst.instruction == M_MNEM_vmlsdav
18099 || inst.instruction == M_MNEM_vmlsdava
18100 || inst.instruction == M_MNEM_vmlsdavx
18101 || inst.instruction == M_MNEM_vmlsdavax)
18102 inst.instruction |= (et.size == 8) << 28;
18103 else
18104 inst.instruction |= (et.size == 8) << 8;
18105
18106 mve_encode_rqq (et.type == NT_unsigned, 64);
18107 inst.instruction |= (et.size == 32) << 16;
18108}
18109
93925576
AV
18110static void
18111do_mve_vmlaldav (void)
18112{
18113 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18114 struct neon_type_el et
18115 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18116 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18117
18118 if (et.type == NT_unsigned
18119 && (inst.instruction == M_MNEM_vmlsldav
18120 || inst.instruction == M_MNEM_vmlsldava
18121 || inst.instruction == M_MNEM_vmlsldavx
18122 || inst.instruction == M_MNEM_vmlsldavax))
18123 first_error (BAD_SIMD_TYPE);
18124
18125 if (inst.cond > COND_ALWAYS)
18126 inst.pred_insn_type = INSIDE_VPT_INSN;
18127 else
18128 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18129
18130 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18131}
18132
18133static void
18134do_mve_vrmlaldavh (void)
18135{
18136 struct neon_type_el et;
18137 if (inst.instruction == M_MNEM_vrmlsldavh
18138 || inst.instruction == M_MNEM_vrmlsldavha
18139 || inst.instruction == M_MNEM_vrmlsldavhx
18140 || inst.instruction == M_MNEM_vrmlsldavhax)
18141 {
18142 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18143 if (inst.operands[1].reg == REG_SP)
18144 as_tsktsk (MVE_BAD_SP);
18145 }
18146 else
18147 {
18148 if (inst.instruction == M_MNEM_vrmlaldavhx
18149 || inst.instruction == M_MNEM_vrmlaldavhax)
18150 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18151 else
18152 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18153 N_U32 | N_S32 | N_KEY);
18154 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18155 with vmax/min instructions, making the use of SP in assembly really
18156 nonsensical, so instead of issuing a warning like we do for other uses
18157 of SP for the odd register operand we error out. */
18158 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18159 }
18160
18161 /* Make sure we still check the second operand is an odd one and that PC is
18162 disallowed. This because we are parsing for any GPR operand, to be able
18163 to distinguish between giving a warning or an error for SP as described
18164 above. */
18165 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18166 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18167
18168 if (inst.cond > COND_ALWAYS)
18169 inst.pred_insn_type = INSIDE_VPT_INSN;
18170 else
18171 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18172
18173 mve_encode_rrqq (et.type == NT_unsigned, 0);
18174}
18175
18176
8cd78170
AV
18177static void
18178do_mve_vmaxnmv (void)
18179{
18180 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18181 struct neon_type_el et
18182 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18183
18184 if (inst.cond > COND_ALWAYS)
18185 inst.pred_insn_type = INSIDE_VPT_INSN;
18186 else
18187 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18188
18189 if (inst.operands[0].reg == REG_SP)
18190 as_tsktsk (MVE_BAD_SP);
18191 else if (inst.operands[0].reg == REG_PC)
18192 as_tsktsk (MVE_BAD_PC);
18193
18194 mve_encode_rq (et.size == 16, 64);
18195}
18196
13ccd4c0
AV
18197static void
18198do_mve_vmaxv (void)
18199{
18200 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18201 struct neon_type_el et;
18202
18203 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18204 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18205 else
18206 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18207
18208 if (inst.cond > COND_ALWAYS)
18209 inst.pred_insn_type = INSIDE_VPT_INSN;
18210 else
18211 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18212
18213 if (inst.operands[0].reg == REG_SP)
18214 as_tsktsk (MVE_BAD_SP);
18215 else if (inst.operands[0].reg == REG_PC)
18216 as_tsktsk (MVE_BAD_PC);
18217
18218 mve_encode_rq (et.type == NT_unsigned, et.size);
18219}
18220
18221
643afb90
MW
18222static void
18223do_neon_qrdmlah (void)
18224{
64c350f2 18225 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18226 return;
18227 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18228 {
42b16635
AV
18229 /* Check we're on the correct architecture. */
18230 if (!mark_feature_used (&fpu_neon_ext_armv8))
18231 inst.error
18232 = _("instruction form not available on this architecture.");
18233 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18234 {
18235 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18236 record_feature_use (&fpu_neon_ext_v8_1);
18237 }
18238 if (inst.operands[2].isscalar)
18239 {
18240 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18241 struct neon_type_el et = neon_check_type (3, rs,
18242 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18243 NEON_ENCODE (SCALAR, inst);
18244 neon_mul_mac (et, neon_quad (rs));
18245 }
18246 else
18247 {
18248 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18249 struct neon_type_el et = neon_check_type (3, rs,
18250 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18251 NEON_ENCODE (INTEGER, inst);
18252 /* The U bit (rounding) comes from bit mask. */
18253 neon_three_same (neon_quad (rs), 0, et.size);
18254 }
643afb90
MW
18255 }
18256 else
18257 {
42b16635
AV
18258 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18259 struct neon_type_el et
23d188c7 18260 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18261
643afb90 18262 NEON_ENCODE (INTEGER, inst);
42b16635 18263 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18264 }
18265}
18266
5287ad62
JB
18267static void
18268do_neon_fcmp_absolute (void)
18269{
037e8744 18270 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18271 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18272 N_F_16_32 | N_KEY);
5287ad62 18273 /* Size field comes from bit mask. */
cc933301 18274 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18275}
18276
18277static void
18278do_neon_fcmp_absolute_inv (void)
18279{
18280 neon_exchange_operands ();
18281 do_neon_fcmp_absolute ();
18282}
18283
18284static void
18285do_neon_step (void)
18286{
037e8744 18287 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18288 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18289 N_F_16_32 | N_KEY);
18290 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18291}
18292
18293static void
18294do_neon_abs_neg (void)
18295{
037e8744
JB
18296 enum neon_shape rs;
18297 struct neon_type_el et;
5f4273c7 18298
037e8744
JB
18299 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18300 return;
18301
037e8744 18302 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18303 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18304
64c350f2
AV
18305 if (!check_simd_pred_availability (et.type == NT_float,
18306 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18307 return;
18308
5287ad62
JB
18309 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18310 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18311 inst.instruction |= LOW4 (inst.operands[1].reg);
18312 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18313 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18314 inst.instruction |= (et.type == NT_float) << 10;
18315 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18316
88714cb8 18317 neon_dp_fixup (&inst);
5287ad62
JB
18318}
18319
18320static void
18321do_neon_sli (void)
18322{
64c350f2 18323 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18324 return;
18325
18326 enum neon_shape rs;
18327 struct neon_type_el et;
18328 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18329 {
18330 rs = neon_select_shape (NS_QQI, NS_NULL);
18331 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18332 }
18333 else
18334 {
18335 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18336 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18337 }
18338
18339
5287ad62
JB
18340 int imm = inst.operands[2].imm;
18341 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18342 _("immediate out of range for insert"));
037e8744 18343 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18344}
18345
18346static void
18347do_neon_sri (void)
18348{
64c350f2 18349 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18350 return;
18351
18352 enum neon_shape rs;
18353 struct neon_type_el et;
18354 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18355 {
18356 rs = neon_select_shape (NS_QQI, NS_NULL);
18357 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18358 }
18359 else
18360 {
18361 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18362 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18363 }
18364
5287ad62
JB
18365 int imm = inst.operands[2].imm;
18366 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18367 _("immediate out of range for insert"));
037e8744 18368 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18369}
18370
18371static void
18372do_neon_qshlu_imm (void)
18373{
64c350f2 18374 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18375 return;
18376
18377 enum neon_shape rs;
18378 struct neon_type_el et;
18379 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18380 {
18381 rs = neon_select_shape (NS_QQI, NS_NULL);
18382 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18383 }
18384 else
18385 {
18386 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18387 et = neon_check_type (2, rs, N_EQK | N_UNS,
18388 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18389 }
18390
5287ad62
JB
18391 int imm = inst.operands[2].imm;
18392 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18393 _("immediate out of range for shift"));
5287ad62
JB
18394 /* Only encodes the 'U present' variant of the instruction.
18395 In this case, signed types have OP (bit 8) set to 0.
18396 Unsigned types have OP set to 1. */
18397 inst.instruction |= (et.type == NT_unsigned) << 8;
18398 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18399 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18400}
18401
18402static void
18403do_neon_qmovn (void)
18404{
18405 struct neon_type_el et = neon_check_type (2, NS_DQ,
18406 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18407 /* Saturating move where operands can be signed or unsigned, and the
18408 destination has the same signedness. */
88714cb8 18409 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18410 if (et.type == NT_unsigned)
18411 inst.instruction |= 0xc0;
18412 else
18413 inst.instruction |= 0x80;
18414 neon_two_same (0, 1, et.size / 2);
18415}
18416
18417static void
18418do_neon_qmovun (void)
18419{
18420 struct neon_type_el et = neon_check_type (2, NS_DQ,
18421 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18422 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18423 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18424 neon_two_same (0, 1, et.size / 2);
18425}
18426
18427static void
18428do_neon_rshift_sat_narrow (void)
18429{
18430 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18431 or unsigned. If operands are unsigned, results must also be unsigned. */
18432 struct neon_type_el et = neon_check_type (2, NS_DQI,
18433 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18434 int imm = inst.operands[2].imm;
18435 /* This gets the bounds check, size encoding and immediate bits calculation
18436 right. */
18437 et.size /= 2;
5f4273c7 18438
5287ad62
JB
18439 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18440 VQMOVN.I<size> <Dd>, <Qm>. */
18441 if (imm == 0)
18442 {
18443 inst.operands[2].present = 0;
18444 inst.instruction = N_MNEM_vqmovn;
18445 do_neon_qmovn ();
18446 return;
18447 }
5f4273c7 18448
5287ad62 18449 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18450 _("immediate out of range"));
5287ad62
JB
18451 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18452}
18453
18454static void
18455do_neon_rshift_sat_narrow_u (void)
18456{
18457 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18458 or unsigned. If operands are unsigned, results must also be unsigned. */
18459 struct neon_type_el et = neon_check_type (2, NS_DQI,
18460 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18461 int imm = inst.operands[2].imm;
18462 /* This gets the bounds check, size encoding and immediate bits calculation
18463 right. */
18464 et.size /= 2;
18465
18466 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18467 VQMOVUN.I<size> <Dd>, <Qm>. */
18468 if (imm == 0)
18469 {
18470 inst.operands[2].present = 0;
18471 inst.instruction = N_MNEM_vqmovun;
18472 do_neon_qmovun ();
18473 return;
18474 }
18475
18476 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18477 _("immediate out of range"));
5287ad62
JB
18478 /* FIXME: The manual is kind of unclear about what value U should have in
18479 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18480 must be 1. */
18481 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18482}
18483
18484static void
18485do_neon_movn (void)
18486{
18487 struct neon_type_el et = neon_check_type (2, NS_DQ,
18488 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18489 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18490 neon_two_same (0, 1, et.size / 2);
18491}
18492
18493static void
18494do_neon_rshift_narrow (void)
18495{
18496 struct neon_type_el et = neon_check_type (2, NS_DQI,
18497 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18498 int imm = inst.operands[2].imm;
18499 /* This gets the bounds check, size encoding and immediate bits calculation
18500 right. */
18501 et.size /= 2;
5f4273c7 18502
5287ad62
JB
18503 /* If immediate is zero then we are a pseudo-instruction for
18504 VMOVN.I<size> <Dd>, <Qm> */
18505 if (imm == 0)
18506 {
18507 inst.operands[2].present = 0;
18508 inst.instruction = N_MNEM_vmovn;
18509 do_neon_movn ();
18510 return;
18511 }
5f4273c7 18512
5287ad62 18513 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18514 _("immediate out of range for narrowing operation"));
5287ad62
JB
18515 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18516}
18517
18518static void
18519do_neon_shll (void)
18520{
18521 /* FIXME: Type checking when lengthening. */
18522 struct neon_type_el et = neon_check_type (2, NS_QDI,
18523 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18524 unsigned imm = inst.operands[2].imm;
18525
18526 if (imm == et.size)
18527 {
18528 /* Maximum shift variant. */
88714cb8 18529 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18530 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18531 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18532 inst.instruction |= LOW4 (inst.operands[1].reg);
18533 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18534 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18535
88714cb8 18536 neon_dp_fixup (&inst);
5287ad62
JB
18537 }
18538 else
18539 {
18540 /* A more-specific type check for non-max versions. */
18541 et = neon_check_type (2, NS_QDI,
477330fc 18542 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18543 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18544 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18545 }
18546}
18547
037e8744 18548/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18549 the current instruction is. */
18550
6b9a8b67
MGD
18551#define CVT_FLAVOUR_VAR \
18552 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18553 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18554 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18555 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18556 /* Half-precision conversions. */ \
cc933301
JW
18557 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18558 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18559 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18560 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18561 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18562 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18563 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18564 Compared with single/double precision variants, only the co-processor \
18565 field is different, so the encoding flow is reused here. */ \
18566 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18567 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18568 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18569 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
18570 /* VFP instructions. */ \
18571 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18572 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18573 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18574 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18575 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18576 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18577 /* VFP instructions with bitshift. */ \
18578 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18579 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18580 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18581 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18582 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18583 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18584 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18585 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18586
18587#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18588 neon_cvt_flavour_##C,
18589
18590/* The different types of conversions we can do. */
18591enum neon_cvt_flavour
18592{
18593 CVT_FLAVOUR_VAR
18594 neon_cvt_flavour_invalid,
18595 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18596};
18597
18598#undef CVT_VAR
18599
18600static enum neon_cvt_flavour
18601get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18602{
6b9a8b67
MGD
18603#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18604 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18605 if (et.type != NT_invtype) \
18606 { \
18607 inst.error = NULL; \
18608 return (neon_cvt_flavour_##C); \
5287ad62 18609 }
6b9a8b67 18610
5287ad62 18611 struct neon_type_el et;
037e8744 18612 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18613 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18614 /* The instruction versions which take an immediate take one register
18615 argument, which is extended to the width of the full register. Thus the
18616 "source" and "destination" registers must have the same width. Hack that
18617 here by making the size equal to the key (wider, in this case) operand. */
18618 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18619
6b9a8b67
MGD
18620 CVT_FLAVOUR_VAR;
18621
18622 return neon_cvt_flavour_invalid;
5287ad62
JB
18623#undef CVT_VAR
18624}
18625
7e8e6784
MGD
18626enum neon_cvt_mode
18627{
18628 neon_cvt_mode_a,
18629 neon_cvt_mode_n,
18630 neon_cvt_mode_p,
18631 neon_cvt_mode_m,
18632 neon_cvt_mode_z,
30bdf752
MGD
18633 neon_cvt_mode_x,
18634 neon_cvt_mode_r
7e8e6784
MGD
18635};
18636
037e8744
JB
18637/* Neon-syntax VFP conversions. */
18638
5287ad62 18639static void
6b9a8b67 18640do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18641{
037e8744 18642 const char *opname = 0;
5f4273c7 18643
d54af2d0
RL
18644 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18645 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18646 {
037e8744
JB
18647 /* Conversions with immediate bitshift. */
18648 const char *enc[] =
477330fc 18649 {
6b9a8b67
MGD
18650#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18651 CVT_FLAVOUR_VAR
18652 NULL
18653#undef CVT_VAR
477330fc 18654 };
037e8744 18655
6b9a8b67 18656 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18657 {
18658 opname = enc[flavour];
18659 constraint (inst.operands[0].reg != inst.operands[1].reg,
18660 _("operands 0 and 1 must be the same register"));
18661 inst.operands[1] = inst.operands[2];
18662 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18663 }
5287ad62
JB
18664 }
18665 else
18666 {
037e8744
JB
18667 /* Conversions without bitshift. */
18668 const char *enc[] =
477330fc 18669 {
6b9a8b67
MGD
18670#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18671 CVT_FLAVOUR_VAR
18672 NULL
18673#undef CVT_VAR
477330fc 18674 };
037e8744 18675
6b9a8b67 18676 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18677 opname = enc[flavour];
037e8744
JB
18678 }
18679
18680 if (opname)
18681 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18682
18683 /* ARMv8.2 fp16 VCVT instruction. */
18684 if (flavour == neon_cvt_flavour_s32_f16
18685 || flavour == neon_cvt_flavour_u32_f16
18686 || flavour == neon_cvt_flavour_f16_u32
18687 || flavour == neon_cvt_flavour_f16_s32)
18688 do_scalar_fp16_v82_encode ();
037e8744
JB
18689}
18690
18691static void
18692do_vfp_nsyn_cvtz (void)
18693{
d54af2d0 18694 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18695 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18696 const char *enc[] =
18697 {
6b9a8b67
MGD
18698#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18699 CVT_FLAVOUR_VAR
18700 NULL
18701#undef CVT_VAR
037e8744
JB
18702 };
18703
6b9a8b67 18704 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18705 do_vfp_nsyn_opcode (enc[flavour]);
18706}
f31fef98 18707
037e8744 18708static void
bacebabc 18709do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18710 enum neon_cvt_mode mode)
18711{
18712 int sz, op;
18713 int rm;
18714
a715796b
TG
18715 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18716 D register operands. */
18717 if (flavour == neon_cvt_flavour_s32_f64
18718 || flavour == neon_cvt_flavour_u32_f64)
18719 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18720 _(BAD_FPU));
18721
9db2f6b4
RL
18722 if (flavour == neon_cvt_flavour_s32_f16
18723 || flavour == neon_cvt_flavour_u32_f16)
18724 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18725 _(BAD_FP16));
18726
5ee91343 18727 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18728
18729 switch (flavour)
18730 {
18731 case neon_cvt_flavour_s32_f64:
18732 sz = 1;
827f64ff 18733 op = 1;
7e8e6784
MGD
18734 break;
18735 case neon_cvt_flavour_s32_f32:
18736 sz = 0;
18737 op = 1;
18738 break;
9db2f6b4
RL
18739 case neon_cvt_flavour_s32_f16:
18740 sz = 0;
18741 op = 1;
18742 break;
7e8e6784
MGD
18743 case neon_cvt_flavour_u32_f64:
18744 sz = 1;
18745 op = 0;
18746 break;
18747 case neon_cvt_flavour_u32_f32:
18748 sz = 0;
18749 op = 0;
18750 break;
9db2f6b4
RL
18751 case neon_cvt_flavour_u32_f16:
18752 sz = 0;
18753 op = 0;
18754 break;
7e8e6784
MGD
18755 default:
18756 first_error (_("invalid instruction shape"));
18757 return;
18758 }
18759
18760 switch (mode)
18761 {
18762 case neon_cvt_mode_a: rm = 0; break;
18763 case neon_cvt_mode_n: rm = 1; break;
18764 case neon_cvt_mode_p: rm = 2; break;
18765 case neon_cvt_mode_m: rm = 3; break;
18766 default: first_error (_("invalid rounding mode")); return;
18767 }
18768
18769 NEON_ENCODE (FPV8, inst);
18770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
18771 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
18772 inst.instruction |= sz << 8;
9db2f6b4
RL
18773
18774 /* ARMv8.2 fp16 VCVT instruction. */
18775 if (flavour == neon_cvt_flavour_s32_f16
18776 ||flavour == neon_cvt_flavour_u32_f16)
18777 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
18778 inst.instruction |= op << 7;
18779 inst.instruction |= rm << 16;
18780 inst.instruction |= 0xf0000000;
18781 inst.is_neon = TRUE;
18782}
18783
18784static void
18785do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
18786{
18787 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
18788 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
18789 NS_FH, NS_HF, NS_FHI, NS_HFI,
18790 NS_NULL);
6b9a8b67 18791 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 18792
cc933301
JW
18793 if (flavour == neon_cvt_flavour_invalid)
18794 return;
18795
e3e535bc 18796 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 18797 if (mode == neon_cvt_mode_z
e3e535bc 18798 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
18799 && (flavour == neon_cvt_flavour_s16_f16
18800 || flavour == neon_cvt_flavour_u16_f16
18801 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
18802 || flavour == neon_cvt_flavour_u32_f32
18803 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 18804 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
18805 && (rs == NS_FD || rs == NS_FF))
18806 {
18807 do_vfp_nsyn_cvtz ();
18808 return;
18809 }
18810
9db2f6b4
RL
18811 /* ARMv8.2 fp16 VCVT conversions. */
18812 if (mode == neon_cvt_mode_z
18813 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
18814 && (flavour == neon_cvt_flavour_s32_f16
18815 || flavour == neon_cvt_flavour_u32_f16)
18816 && (rs == NS_FH))
18817 {
18818 do_vfp_nsyn_cvtz ();
18819 do_scalar_fp16_v82_encode ();
18820 return;
18821 }
18822
037e8744 18823 /* VFP rather than Neon conversions. */
6b9a8b67 18824 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 18825 {
7e8e6784
MGD
18826 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
18827 do_vfp_nsyn_cvt (rs, flavour);
18828 else
18829 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
18830
037e8744
JB
18831 return;
18832 }
18833
18834 switch (rs)
18835 {
037e8744 18836 case NS_QQI:
dd9634d9
AV
18837 if (mode == neon_cvt_mode_z
18838 && (flavour == neon_cvt_flavour_f16_s16
18839 || flavour == neon_cvt_flavour_f16_u16
18840 || flavour == neon_cvt_flavour_s16_f16
18841 || flavour == neon_cvt_flavour_u16_f16
18842 || flavour == neon_cvt_flavour_f32_u32
18843 || flavour == neon_cvt_flavour_f32_s32
18844 || flavour == neon_cvt_flavour_s32_f32
18845 || flavour == neon_cvt_flavour_u32_f32))
18846 {
64c350f2
AV
18847 if (!check_simd_pred_availability (TRUE,
18848 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
18849 return;
18850 }
18851 else if (mode == neon_cvt_mode_n)
18852 {
18853 /* We are dealing with vcvt with the 'ne' condition. */
18854 inst.cond = 0x1;
18855 inst.instruction = N_MNEM_vcvt;
18856 do_neon_cvt_1 (neon_cvt_mode_z);
18857 return;
18858 }
18859 /* fall through. */
18860 case NS_DDI:
037e8744 18861 {
477330fc 18862 unsigned immbits;
cc933301
JW
18863 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
18864 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 18865
dd9634d9
AV
18866 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18867 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18868 return;
18869
18870 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18871 {
18872 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
18873 _("immediate value out of range"));
18874 switch (flavour)
18875 {
18876 case neon_cvt_flavour_f16_s16:
18877 case neon_cvt_flavour_f16_u16:
18878 case neon_cvt_flavour_s16_f16:
18879 case neon_cvt_flavour_u16_f16:
18880 constraint (inst.operands[2].imm > 16,
18881 _("immediate value out of range"));
18882 break;
18883 case neon_cvt_flavour_f32_u32:
18884 case neon_cvt_flavour_f32_s32:
18885 case neon_cvt_flavour_s32_f32:
18886 case neon_cvt_flavour_u32_f32:
18887 constraint (inst.operands[2].imm > 32,
18888 _("immediate value out of range"));
18889 break;
18890 default:
18891 inst.error = BAD_FPU;
18892 return;
18893 }
18894 }
037e8744 18895
477330fc
RM
18896 /* Fixed-point conversion with #0 immediate is encoded as an
18897 integer conversion. */
18898 if (inst.operands[2].present && inst.operands[2].imm == 0)
18899 goto int_encode;
477330fc
RM
18900 NEON_ENCODE (IMMED, inst);
18901 if (flavour != neon_cvt_flavour_invalid)
18902 inst.instruction |= enctab[flavour];
18903 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18904 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18905 inst.instruction |= LOW4 (inst.operands[1].reg);
18906 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18907 inst.instruction |= neon_quad (rs) << 6;
18908 inst.instruction |= 1 << 21;
cc933301
JW
18909 if (flavour < neon_cvt_flavour_s16_f16)
18910 {
18911 inst.instruction |= 1 << 21;
18912 immbits = 32 - inst.operands[2].imm;
18913 inst.instruction |= immbits << 16;
18914 }
18915 else
18916 {
18917 inst.instruction |= 3 << 20;
18918 immbits = 16 - inst.operands[2].imm;
18919 inst.instruction |= immbits << 16;
18920 inst.instruction &= ~(1 << 9);
18921 }
477330fc
RM
18922
18923 neon_dp_fixup (&inst);
037e8744
JB
18924 }
18925 break;
18926
037e8744 18927 case NS_QQ:
dd9634d9
AV
18928 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
18929 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
18930 && (flavour == neon_cvt_flavour_s16_f16
18931 || flavour == neon_cvt_flavour_u16_f16
18932 || flavour == neon_cvt_flavour_s32_f32
18933 || flavour == neon_cvt_flavour_u32_f32))
18934 {
64c350f2
AV
18935 if (!check_simd_pred_availability (TRUE,
18936 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
18937 return;
18938 }
18939 else if (mode == neon_cvt_mode_z
18940 && (flavour == neon_cvt_flavour_f16_s16
18941 || flavour == neon_cvt_flavour_f16_u16
18942 || flavour == neon_cvt_flavour_s16_f16
18943 || flavour == neon_cvt_flavour_u16_f16
18944 || flavour == neon_cvt_flavour_f32_u32
18945 || flavour == neon_cvt_flavour_f32_s32
18946 || flavour == neon_cvt_flavour_s32_f32
18947 || flavour == neon_cvt_flavour_u32_f32))
18948 {
64c350f2
AV
18949 if (!check_simd_pred_availability (TRUE,
18950 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
18951 return;
18952 }
18953 /* fall through. */
18954 case NS_DD:
7e8e6784
MGD
18955 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
18956 {
7e8e6784 18957
dd9634d9 18958 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
18959 if (!check_simd_pred_availability (TRUE,
18960 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
18961 return;
18962
18963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18965 inst.instruction |= LOW4 (inst.operands[1].reg);
18966 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18967 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
18968 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
18969 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 18970 inst.instruction |= mode << 8;
cc933301
JW
18971 if (flavour == neon_cvt_flavour_u16_f16
18972 || flavour == neon_cvt_flavour_s16_f16)
18973 /* Mask off the original size bits and reencode them. */
18974 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
18975
7e8e6784
MGD
18976 if (thumb_mode)
18977 inst.instruction |= 0xfc000000;
18978 else
18979 inst.instruction |= 0xf0000000;
18980 }
18981 else
18982 {
037e8744 18983 int_encode:
7e8e6784 18984 {
cc933301
JW
18985 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
18986 0x100, 0x180, 0x0, 0x080};
037e8744 18987
7e8e6784 18988 NEON_ENCODE (INTEGER, inst);
037e8744 18989
dd9634d9
AV
18990 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18991 {
18992 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18993 return;
18994 }
037e8744 18995
7e8e6784
MGD
18996 if (flavour != neon_cvt_flavour_invalid)
18997 inst.instruction |= enctab[flavour];
037e8744 18998
7e8e6784
MGD
18999 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19000 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19001 inst.instruction |= LOW4 (inst.operands[1].reg);
19002 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19003 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19004 if (flavour >= neon_cvt_flavour_s16_f16
19005 && flavour <= neon_cvt_flavour_f16_u16)
19006 /* Half precision. */
19007 inst.instruction |= 1 << 18;
19008 else
19009 inst.instruction |= 2 << 18;
037e8744 19010
7e8e6784
MGD
19011 neon_dp_fixup (&inst);
19012 }
19013 }
19014 break;
037e8744 19015
8e79c3df
CM
19016 /* Half-precision conversions for Advanced SIMD -- neon. */
19017 case NS_QD:
19018 case NS_DQ:
bc52d49c
MM
19019 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19020 return;
8e79c3df
CM
19021
19022 if ((rs == NS_DQ)
19023 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19024 {
19025 as_bad (_("operand size must match register width"));
19026 break;
19027 }
19028
19029 if ((rs == NS_QD)
19030 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19031 {
19032 as_bad (_("operand size must match register width"));
19033 break;
19034 }
19035
19036 if (rs == NS_DQ)
477330fc 19037 inst.instruction = 0x3b60600;
8e79c3df
CM
19038 else
19039 inst.instruction = 0x3b60700;
19040
19041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19042 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19043 inst.instruction |= LOW4 (inst.operands[1].reg);
19044 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19045 neon_dp_fixup (&inst);
8e79c3df
CM
19046 break;
19047
037e8744
JB
19048 default:
19049 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19050 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19051 do_vfp_nsyn_cvt (rs, flavour);
19052 else
19053 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19054 }
5287ad62
JB
19055}
19056
e3e535bc
NC
19057static void
19058do_neon_cvtr (void)
19059{
7e8e6784 19060 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19061}
19062
19063static void
19064do_neon_cvt (void)
19065{
7e8e6784
MGD
19066 do_neon_cvt_1 (neon_cvt_mode_z);
19067}
19068
19069static void
19070do_neon_cvta (void)
19071{
19072 do_neon_cvt_1 (neon_cvt_mode_a);
19073}
19074
19075static void
19076do_neon_cvtn (void)
19077{
19078 do_neon_cvt_1 (neon_cvt_mode_n);
19079}
19080
19081static void
19082do_neon_cvtp (void)
19083{
19084 do_neon_cvt_1 (neon_cvt_mode_p);
19085}
19086
19087static void
19088do_neon_cvtm (void)
19089{
19090 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19091}
19092
8e79c3df 19093static void
c70a8987 19094do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19095{
c70a8987
MGD
19096 if (is_double)
19097 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19098
c70a8987
MGD
19099 encode_arm_vfp_reg (inst.operands[0].reg,
19100 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19101 encode_arm_vfp_reg (inst.operands[1].reg,
19102 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19103 inst.instruction |= to ? 0x10000 : 0;
19104 inst.instruction |= t ? 0x80 : 0;
19105 inst.instruction |= is_double ? 0x100 : 0;
19106 do_vfp_cond_or_thumb ();
19107}
8e79c3df 19108
c70a8987
MGD
19109static void
19110do_neon_cvttb_1 (bfd_boolean t)
19111{
d54af2d0 19112 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19113 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19114
c70a8987
MGD
19115 if (rs == NS_NULL)
19116 return;
dd9634d9
AV
19117 else if (rs == NS_QQ || rs == NS_QQI)
19118 {
19119 int single_to_half = 0;
64c350f2 19120 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19121 return;
19122
19123 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19124
19125 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19126 && (flavour == neon_cvt_flavour_u16_f16
19127 || flavour == neon_cvt_flavour_s16_f16
19128 || flavour == neon_cvt_flavour_f16_s16
19129 || flavour == neon_cvt_flavour_f16_u16
19130 || flavour == neon_cvt_flavour_u32_f32
19131 || flavour == neon_cvt_flavour_s32_f32
19132 || flavour == neon_cvt_flavour_f32_s32
19133 || flavour == neon_cvt_flavour_f32_u32))
19134 {
19135 inst.cond = 0xf;
19136 inst.instruction = N_MNEM_vcvt;
19137 set_pred_insn_type (INSIDE_VPT_INSN);
19138 do_neon_cvt_1 (neon_cvt_mode_z);
19139 return;
19140 }
19141 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19142 single_to_half = 1;
19143 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19144 {
19145 first_error (BAD_FPU);
19146 return;
19147 }
19148
19149 inst.instruction = 0xee3f0e01;
19150 inst.instruction |= single_to_half << 28;
19151 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19152 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19153 inst.instruction |= t << 12;
19154 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19155 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19156 inst.is_neon = 1;
19157 }
c70a8987
MGD
19158 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19159 {
19160 inst.error = NULL;
19161 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19162 }
19163 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19164 {
19165 inst.error = NULL;
19166 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19167 }
19168 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19169 {
a715796b
TG
19170 /* The VCVTB and VCVTT instructions with D-register operands
19171 don't work for SP only targets. */
19172 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19173 _(BAD_FPU));
19174
c70a8987
MGD
19175 inst.error = NULL;
19176 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19177 }
19178 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19179 {
a715796b
TG
19180 /* The VCVTB and VCVTT instructions with D-register operands
19181 don't work for SP only targets. */
19182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19183 _(BAD_FPU));
19184
c70a8987
MGD
19185 inst.error = NULL;
19186 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19187 }
19188 else
19189 return;
19190}
19191
19192static void
19193do_neon_cvtb (void)
19194{
19195 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19196}
19197
19198
19199static void
19200do_neon_cvtt (void)
19201{
c70a8987 19202 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19203}
19204
5287ad62
JB
19205static void
19206neon_move_immediate (void)
19207{
037e8744
JB
19208 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19209 struct neon_type_el et = neon_check_type (2, rs,
19210 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19211 unsigned immlo, immhi = 0, immbits;
c96612cc 19212 int op, cmode, float_p;
5287ad62 19213
037e8744 19214 constraint (et.type == NT_invtype,
477330fc 19215 _("operand size must be specified for immediate VMOV"));
037e8744 19216
5287ad62
JB
19217 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19218 op = (inst.instruction & (1 << 5)) != 0;
19219
19220 immlo = inst.operands[1].imm;
19221 if (inst.operands[1].regisimm)
19222 immhi = inst.operands[1].reg;
19223
19224 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19225 _("immediate has bits set outside the operand size"));
5287ad62 19226
c96612cc
JB
19227 float_p = inst.operands[1].immisfloat;
19228
19229 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19230 et.size, et.type)) == FAIL)
5287ad62
JB
19231 {
19232 /* Invert relevant bits only. */
19233 neon_invert_size (&immlo, &immhi, et.size);
19234 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19235 with one or the other; those cases are caught by
19236 neon_cmode_for_move_imm. */
5287ad62 19237 op = !op;
c96612cc
JB
19238 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19239 &op, et.size, et.type)) == FAIL)
477330fc
RM
19240 {
19241 first_error (_("immediate out of range"));
19242 return;
19243 }
5287ad62
JB
19244 }
19245
19246 inst.instruction &= ~(1 << 5);
19247 inst.instruction |= op << 5;
19248
19249 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19250 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19251 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19252 inst.instruction |= cmode << 8;
19253
19254 neon_write_immbits (immbits);
19255}
19256
19257static void
19258do_neon_mvn (void)
19259{
64c350f2 19260 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19261 return;
19262
5287ad62
JB
19263 if (inst.operands[1].isreg)
19264 {
1a186d29
AV
19265 enum neon_shape rs;
19266 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19267 rs = neon_select_shape (NS_QQ, NS_NULL);
19268 else
19269 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19270
88714cb8 19271 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19272 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19273 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19274 inst.instruction |= LOW4 (inst.operands[1].reg);
19275 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19276 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19277 }
19278 else
19279 {
88714cb8 19280 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19281 neon_move_immediate ();
19282 }
19283
88714cb8 19284 neon_dp_fixup (&inst);
1a186d29
AV
19285
19286 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19287 {
19288 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19289 constraint ((inst.instruction & 0xd00) == 0xd00,
19290 _("immediate value out of range"));
19291 }
5287ad62
JB
19292}
19293
19294/* Encode instructions of form:
19295
19296 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19297 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19298
19299static void
19300neon_mixed_length (struct neon_type_el et, unsigned size)
19301{
19302 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19303 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19304 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19305 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19306 inst.instruction |= LOW4 (inst.operands[2].reg);
19307 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19308 inst.instruction |= (et.type == NT_unsigned) << 24;
19309 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19310
88714cb8 19311 neon_dp_fixup (&inst);
5287ad62
JB
19312}
19313
19314static void
19315do_neon_dyadic_long (void)
19316{
5ee91343
AV
19317 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19318 if (rs == NS_QDD)
19319 {
19320 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19321 return;
19322
19323 NEON_ENCODE (INTEGER, inst);
19324 /* FIXME: Type checking for lengthening op. */
19325 struct neon_type_el et = neon_check_type (3, NS_QDD,
19326 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19327 neon_mixed_length (et, et.size);
19328 }
19329 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19330 && (inst.cond == 0xf || inst.cond == 0x10))
19331 {
19332 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19333 in an IT block with le/lt conditions. */
19334
19335 if (inst.cond == 0xf)
19336 inst.cond = 0xb;
19337 else if (inst.cond == 0x10)
19338 inst.cond = 0xd;
19339
19340 inst.pred_insn_type = INSIDE_IT_INSN;
19341
19342 if (inst.instruction == N_MNEM_vaddl)
19343 {
19344 inst.instruction = N_MNEM_vadd;
19345 do_neon_addsub_if_i ();
19346 }
19347 else if (inst.instruction == N_MNEM_vsubl)
19348 {
19349 inst.instruction = N_MNEM_vsub;
19350 do_neon_addsub_if_i ();
19351 }
19352 else if (inst.instruction == N_MNEM_vabdl)
19353 {
19354 inst.instruction = N_MNEM_vabd;
19355 do_neon_dyadic_if_su ();
19356 }
19357 }
19358 else
19359 first_error (BAD_FPU);
5287ad62
JB
19360}
19361
19362static void
19363do_neon_abal (void)
19364{
19365 struct neon_type_el et = neon_check_type (3, NS_QDD,
19366 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19367 neon_mixed_length (et, et.size);
19368}
19369
19370static void
19371neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19372{
19373 if (inst.operands[2].isscalar)
19374 {
dcbf9037 19375 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19376 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19377 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19378 neon_mul_mac (et, et.type == NT_unsigned);
19379 }
19380 else
19381 {
19382 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19383 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19384 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19385 neon_mixed_length (et, et.size);
19386 }
19387}
19388
19389static void
19390do_neon_mac_maybe_scalar_long (void)
19391{
19392 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19393}
19394
dec41383
JW
19395/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19396 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19397
19398static unsigned
19399neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19400{
19401 unsigned regno = NEON_SCALAR_REG (scalar);
19402 unsigned elno = NEON_SCALAR_INDEX (scalar);
19403
19404 if (quad_p)
19405 {
19406 if (regno > 7 || elno > 3)
19407 goto bad_scalar;
19408
19409 return ((regno & 0x7)
19410 | ((elno & 0x1) << 3)
19411 | (((elno >> 1) & 0x1) << 5));
19412 }
19413 else
19414 {
19415 if (regno > 15 || elno > 1)
19416 goto bad_scalar;
19417
19418 return (((regno & 0x1) << 5)
19419 | ((regno >> 1) & 0x7)
19420 | ((elno & 0x1) << 3));
19421 }
19422
19423bad_scalar:
19424 first_error (_("scalar out of range for multiply instruction"));
19425 return 0;
19426}
19427
19428static void
19429do_neon_fmac_maybe_scalar_long (int subtype)
19430{
19431 enum neon_shape rs;
19432 int high8;
19433 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19434 field (bits[21:20]) has different meaning. For scalar index variant, it's
19435 used to differentiate add and subtract, otherwise it's with fixed value
19436 0x2. */
19437 int size = -1;
19438
19439 if (inst.cond != COND_ALWAYS)
19440 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19441 "behaviour is UNPREDICTABLE"));
19442
01f48020 19443 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
19444 _(BAD_FP16));
19445
19446 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19447 _(BAD_FPU));
19448
19449 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19450 be a scalar index register. */
19451 if (inst.operands[2].isscalar)
19452 {
19453 high8 = 0xfe000000;
19454 if (subtype)
19455 size = 16;
19456 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19457 }
19458 else
19459 {
19460 high8 = 0xfc000000;
19461 size = 32;
19462 if (subtype)
19463 inst.instruction |= (0x1 << 23);
19464 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19465 }
19466
19467 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
19468
19469 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19470 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19471 so we simply pass -1 as size. */
19472 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19473 neon_three_same (quad_p, 0, size);
19474
19475 /* Undo neon_dp_fixup. Redo the high eight bits. */
19476 inst.instruction &= 0x00ffffff;
19477 inst.instruction |= high8;
19478
19479#define LOW1(R) ((R) & 0x1)
19480#define HI4(R) (((R) >> 1) & 0xf)
19481 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19482 whether the instruction is in Q form and whether Vm is a scalar indexed
19483 operand. */
19484 if (inst.operands[2].isscalar)
19485 {
19486 unsigned rm
19487 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19488 inst.instruction &= 0xffffffd0;
19489 inst.instruction |= rm;
19490
19491 if (!quad_p)
19492 {
19493 /* Redo Rn as well. */
19494 inst.instruction &= 0xfff0ff7f;
19495 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19496 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19497 }
19498 }
19499 else if (!quad_p)
19500 {
19501 /* Redo Rn and Rm. */
19502 inst.instruction &= 0xfff0ff50;
19503 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19504 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19505 inst.instruction |= HI4 (inst.operands[2].reg);
19506 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19507 }
19508}
19509
19510static void
19511do_neon_vfmal (void)
19512{
19513 return do_neon_fmac_maybe_scalar_long (0);
19514}
19515
19516static void
19517do_neon_vfmsl (void)
19518{
19519 return do_neon_fmac_maybe_scalar_long (1);
19520}
19521
5287ad62
JB
19522static void
19523do_neon_dyadic_wide (void)
19524{
19525 struct neon_type_el et = neon_check_type (3, NS_QQD,
19526 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19527 neon_mixed_length (et, et.size);
19528}
19529
19530static void
19531do_neon_dyadic_narrow (void)
19532{
19533 struct neon_type_el et = neon_check_type (3, NS_QDD,
19534 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19535 /* Operand sign is unimportant, and the U bit is part of the opcode,
19536 so force the operand type to integer. */
19537 et.type = NT_integer;
5287ad62
JB
19538 neon_mixed_length (et, et.size / 2);
19539}
19540
19541static void
19542do_neon_mul_sat_scalar_long (void)
19543{
19544 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19545}
19546
19547static void
19548do_neon_vmull (void)
19549{
19550 if (inst.operands[2].isscalar)
19551 do_neon_mac_maybe_scalar_long ();
19552 else
19553 {
19554 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19555 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19556
5287ad62 19557 if (et.type == NT_poly)
477330fc 19558 NEON_ENCODE (POLY, inst);
5287ad62 19559 else
477330fc 19560 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19561
19562 /* For polynomial encoding the U bit must be zero, and the size must
19563 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19564 obviously, as 0b10). */
19565 if (et.size == 64)
19566 {
19567 /* Check we're on the correct architecture. */
19568 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19569 inst.error =
19570 _("Instruction form not available on this architecture.");
19571
19572 et.size = 32;
19573 }
19574
5287ad62
JB
19575 neon_mixed_length (et, et.size);
19576 }
19577}
19578
19579static void
19580do_neon_ext (void)
19581{
037e8744 19582 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19583 struct neon_type_el et = neon_check_type (3, rs,
19584 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19585 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19586
19587 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19588 _("shift out of range"));
5287ad62
JB
19589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19591 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19592 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19593 inst.instruction |= LOW4 (inst.operands[2].reg);
19594 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19595 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19596 inst.instruction |= imm << 8;
5f4273c7 19597
88714cb8 19598 neon_dp_fixup (&inst);
5287ad62
JB
19599}
19600
19601static void
19602do_neon_rev (void)
19603{
64c350f2 19604 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19605 return;
19606
19607 enum neon_shape rs;
19608 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19609 rs = neon_select_shape (NS_QQ, NS_NULL);
19610 else
19611 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19612
5287ad62
JB
19613 struct neon_type_el et = neon_check_type (2, rs,
19614 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19615
5287ad62
JB
19616 unsigned op = (inst.instruction >> 7) & 3;
19617 /* N (width of reversed regions) is encoded as part of the bitmask. We
19618 extract it here to check the elements to be reversed are smaller.
19619 Otherwise we'd get a reserved instruction. */
19620 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19621
19622 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19623 && inst.operands[0].reg == inst.operands[1].reg)
19624 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19625 " operands makes instruction UNPREDICTABLE"));
19626
9c2799c2 19627 gas_assert (elsize != 0);
5287ad62 19628 constraint (et.size >= elsize,
477330fc 19629 _("elements must be smaller than reversal region"));
037e8744 19630 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19631}
19632
19633static void
19634do_neon_dup (void)
19635{
19636 if (inst.operands[1].isscalar)
19637 {
b409bdb6
AV
19638 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19639 BAD_FPU);
037e8744 19640 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19641 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19642 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19643 unsigned sizebits = et.size >> 3;
dcbf9037 19644 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19645 int logsize = neon_logbits (et.size);
dcbf9037 19646 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19647
19648 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19649 return;
037e8744 19650
88714cb8 19651 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19652 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19653 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19654 inst.instruction |= LOW4 (dm);
19655 inst.instruction |= HI1 (dm) << 5;
037e8744 19656 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19657 inst.instruction |= x << 17;
19658 inst.instruction |= sizebits << 16;
5f4273c7 19659
88714cb8 19660 neon_dp_fixup (&inst);
5287ad62
JB
19661 }
19662 else
19663 {
037e8744
JB
19664 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19665 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19666 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19667 if (rs == NS_QR)
19668 {
64c350f2 19669 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19670 return;
19671 }
19672 else
19673 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19674 BAD_FPU);
19675
19676 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19677 {
19678 if (inst.operands[1].reg == REG_SP)
19679 as_tsktsk (MVE_BAD_SP);
19680 else if (inst.operands[1].reg == REG_PC)
19681 as_tsktsk (MVE_BAD_PC);
19682 }
19683
5287ad62 19684 /* Duplicate ARM register to lanes of vector. */
88714cb8 19685 NEON_ENCODE (ARMREG, inst);
5287ad62 19686 switch (et.size)
477330fc
RM
19687 {
19688 case 8: inst.instruction |= 0x400000; break;
19689 case 16: inst.instruction |= 0x000020; break;
19690 case 32: inst.instruction |= 0x000000; break;
19691 default: break;
19692 }
5287ad62
JB
19693 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19694 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19695 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19696 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19697 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19698 variants, except for the condition field. */
037e8744 19699 do_vfp_cond_or_thumb ();
5287ad62
JB
19700 }
19701}
19702
57785aa2
AV
19703static void
19704do_mve_mov (int toQ)
19705{
19706 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19707 return;
19708 if (inst.cond > COND_ALWAYS)
19709 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19710
19711 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19712 if (toQ)
19713 {
19714 Q0 = 0;
19715 Q1 = 1;
19716 Rt = 2;
19717 Rt2 = 3;
19718 }
19719
19720 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19721 _("Index one must be [2,3] and index two must be two less than"
19722 " index one."));
19723 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
19724 _("General purpose registers may not be the same"));
19725 constraint (inst.operands[Rt].reg == REG_SP
19726 || inst.operands[Rt2].reg == REG_SP,
19727 BAD_SP);
19728 constraint (inst.operands[Rt].reg == REG_PC
19729 || inst.operands[Rt2].reg == REG_PC,
19730 BAD_PC);
19731
19732 inst.instruction = 0xec000f00;
19733 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
19734 inst.instruction |= !!toQ << 20;
19735 inst.instruction |= inst.operands[Rt2].reg << 16;
19736 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
19737 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
19738 inst.instruction |= inst.operands[Rt].reg;
19739}
19740
19741static void
19742do_mve_movn (void)
19743{
19744 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19745 return;
19746
19747 if (inst.cond > COND_ALWAYS)
19748 inst.pred_insn_type = INSIDE_VPT_INSN;
19749 else
19750 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
19751
19752 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
19753 | N_KEY);
19754
19755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19756 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
19757 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19758 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19759 inst.instruction |= LOW4 (inst.operands[1].reg);
19760 inst.is_neon = 1;
19761
19762}
19763
5287ad62
JB
19764/* VMOV has particularly many variations. It can be one of:
19765 0. VMOV<c><q> <Qd>, <Qm>
19766 1. VMOV<c><q> <Dd>, <Dm>
19767 (Register operations, which are VORR with Rm = Rn.)
19768 2. VMOV<c><q>.<dt> <Qd>, #<imm>
19769 3. VMOV<c><q>.<dt> <Dd>, #<imm>
19770 (Immediate loads.)
19771 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
19772 (ARM register to scalar.)
19773 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
19774 (Two ARM registers to vector.)
19775 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
19776 (Scalar to ARM register.)
19777 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
19778 (Vector to two ARM registers.)
037e8744
JB
19779 8. VMOV.F32 <Sd>, <Sm>
19780 9. VMOV.F64 <Dd>, <Dm>
19781 (VFP register moves.)
19782 10. VMOV.F32 <Sd>, #imm
19783 11. VMOV.F64 <Dd>, #imm
19784 (VFP float immediate load.)
19785 12. VMOV <Rd>, <Sm>
19786 (VFP single to ARM reg.)
19787 13. VMOV <Sd>, <Rm>
19788 (ARM reg to VFP single.)
19789 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
19790 (Two ARM regs to two VFP singles.)
19791 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
19792 (Two VFP singles to two ARM regs.)
57785aa2
AV
19793 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
19794 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
19795 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
19796 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 19797
037e8744
JB
19798 These cases can be disambiguated using neon_select_shape, except cases 1/9
19799 and 3/11 which depend on the operand type too.
5f4273c7 19800
5287ad62 19801 All the encoded bits are hardcoded by this function.
5f4273c7 19802
b7fc2769
JB
19803 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
19804 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 19805
5287ad62 19806 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 19807 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
19808
19809static void
19810do_neon_mov (void)
19811{
57785aa2
AV
19812 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
19813 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
19814 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
19815 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
19816 NS_NULL);
037e8744
JB
19817 struct neon_type_el et;
19818 const char *ldconst = 0;
5287ad62 19819
037e8744 19820 switch (rs)
5287ad62 19821 {
037e8744
JB
19822 case NS_DD: /* case 1/9. */
19823 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19824 /* It is not an error here if no type is given. */
19825 inst.error = NULL;
19826 if (et.type == NT_float && et.size == 64)
477330fc
RM
19827 {
19828 do_vfp_nsyn_opcode ("fcpyd");
19829 break;
19830 }
037e8744 19831 /* fall through. */
5287ad62 19832
037e8744
JB
19833 case NS_QQ: /* case 0/1. */
19834 {
64c350f2
AV
19835 if (!check_simd_pred_availability (FALSE,
19836 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
19837 return;
19838 /* The architecture manual I have doesn't explicitly state which
19839 value the U bit should have for register->register moves, but
19840 the equivalent VORR instruction has U = 0, so do that. */
19841 inst.instruction = 0x0200110;
19842 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19843 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19844 inst.instruction |= LOW4 (inst.operands[1].reg);
19845 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19846 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19847 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19848 inst.instruction |= neon_quad (rs) << 6;
19849
19850 neon_dp_fixup (&inst);
037e8744
JB
19851 }
19852 break;
5f4273c7 19853
037e8744
JB
19854 case NS_DI: /* case 3/11. */
19855 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19856 inst.error = NULL;
19857 if (et.type == NT_float && et.size == 64)
477330fc
RM
19858 {
19859 /* case 11 (fconstd). */
19860 ldconst = "fconstd";
19861 goto encode_fconstd;
19862 }
037e8744
JB
19863 /* fall through. */
19864
19865 case NS_QI: /* case 2/3. */
64c350f2
AV
19866 if (!check_simd_pred_availability (FALSE,
19867 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 19868 return;
037e8744
JB
19869 inst.instruction = 0x0800010;
19870 neon_move_immediate ();
88714cb8 19871 neon_dp_fixup (&inst);
5287ad62 19872 break;
5f4273c7 19873
037e8744
JB
19874 case NS_SR: /* case 4. */
19875 {
477330fc
RM
19876 unsigned bcdebits = 0;
19877 int logsize;
19878 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
19879 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 19880
05ac0ffb
JB
19881 /* .<size> is optional here, defaulting to .32. */
19882 if (inst.vectype.elems == 0
19883 && inst.operands[0].vectype.type == NT_invtype
19884 && inst.operands[1].vectype.type == NT_invtype)
19885 {
19886 inst.vectype.el[0].type = NT_untyped;
19887 inst.vectype.el[0].size = 32;
19888 inst.vectype.elems = 1;
19889 }
19890
477330fc
RM
19891 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
19892 logsize = neon_logbits (et.size);
19893
57785aa2
AV
19894 if (et.size != 32)
19895 {
19896 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19897 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
19898 return;
19899 }
19900 else
19901 {
19902 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
19903 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
19904 _(BAD_FPU));
19905 }
19906
19907 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19908 {
19909 if (inst.operands[1].reg == REG_SP)
19910 as_tsktsk (MVE_BAD_SP);
19911 else if (inst.operands[1].reg == REG_PC)
19912 as_tsktsk (MVE_BAD_PC);
19913 }
19914 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
19915
477330fc 19916 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
19917 constraint (x >= size / et.size, _("scalar index out of range"));
19918
477330fc
RM
19919
19920 switch (et.size)
19921 {
19922 case 8: bcdebits = 0x8; break;
19923 case 16: bcdebits = 0x1; break;
19924 case 32: bcdebits = 0x0; break;
19925 default: ;
19926 }
19927
57785aa2 19928 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
19929
19930 inst.instruction = 0xe000b10;
19931 do_vfp_cond_or_thumb ();
19932 inst.instruction |= LOW4 (dn) << 16;
19933 inst.instruction |= HI1 (dn) << 7;
19934 inst.instruction |= inst.operands[1].reg << 12;
19935 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
19936 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
19937 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
19938 }
19939 break;
5f4273c7 19940
037e8744 19941 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
19942 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
19943 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 19944 _(BAD_FPU));
b7fc2769 19945
037e8744
JB
19946 inst.instruction = 0xc400b10;
19947 do_vfp_cond_or_thumb ();
19948 inst.instruction |= LOW4 (inst.operands[0].reg);
19949 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
19950 inst.instruction |= inst.operands[1].reg << 12;
19951 inst.instruction |= inst.operands[2].reg << 16;
19952 break;
5f4273c7 19953
037e8744
JB
19954 case NS_RS: /* case 6. */
19955 {
477330fc
RM
19956 unsigned logsize;
19957 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
19958 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
19959 unsigned abcdebits = 0;
037e8744 19960
05ac0ffb
JB
19961 /* .<dt> is optional here, defaulting to .32. */
19962 if (inst.vectype.elems == 0
19963 && inst.operands[0].vectype.type == NT_invtype
19964 && inst.operands[1].vectype.type == NT_invtype)
19965 {
19966 inst.vectype.el[0].type = NT_untyped;
19967 inst.vectype.el[0].size = 32;
19968 inst.vectype.elems = 1;
19969 }
19970
91d6fa6a
NC
19971 et = neon_check_type (2, NS_NULL,
19972 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
19973 logsize = neon_logbits (et.size);
19974
57785aa2
AV
19975 if (et.size != 32)
19976 {
19977 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19978 && vfp_or_neon_is_neon (NEON_CHECK_CC
19979 | NEON_CHECK_ARCH) == FAIL)
19980 return;
19981 }
19982 else
19983 {
19984 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
19985 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
19986 _(BAD_FPU));
19987 }
19988
19989 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19990 {
19991 if (inst.operands[0].reg == REG_SP)
19992 as_tsktsk (MVE_BAD_SP);
19993 else if (inst.operands[0].reg == REG_PC)
19994 as_tsktsk (MVE_BAD_PC);
19995 }
19996
19997 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
19998
477330fc 19999 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 20000 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
20001
20002 switch (et.size)
20003 {
20004 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20005 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20006 case 32: abcdebits = 0x00; break;
20007 default: ;
20008 }
20009
57785aa2 20010 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20011 inst.instruction = 0xe100b10;
20012 do_vfp_cond_or_thumb ();
20013 inst.instruction |= LOW4 (dn) << 16;
20014 inst.instruction |= HI1 (dn) << 7;
20015 inst.instruction |= inst.operands[0].reg << 12;
20016 inst.instruction |= (abcdebits & 3) << 5;
20017 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 20018 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20019 }
20020 break;
5f4273c7 20021
037e8744 20022 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
20023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20024 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20025 _(BAD_FPU));
037e8744
JB
20026
20027 inst.instruction = 0xc500b10;
20028 do_vfp_cond_or_thumb ();
20029 inst.instruction |= inst.operands[0].reg << 12;
20030 inst.instruction |= inst.operands[1].reg << 16;
20031 inst.instruction |= LOW4 (inst.operands[2].reg);
20032 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20033 break;
5f4273c7 20034
037e8744
JB
20035 case NS_FF: /* case 8 (fcpys). */
20036 do_vfp_nsyn_opcode ("fcpys");
20037 break;
5f4273c7 20038
9db2f6b4 20039 case NS_HI:
037e8744
JB
20040 case NS_FI: /* case 10 (fconsts). */
20041 ldconst = "fconsts";
4ef4710f 20042 encode_fconstd:
58ed5c38
TC
20043 if (!inst.operands[1].immisfloat)
20044 {
4ef4710f 20045 unsigned new_imm;
58ed5c38 20046 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
20047 float imm = (float) inst.operands[1].imm;
20048 memcpy (&new_imm, &imm, sizeof (float));
20049 /* But the assembly may have been written to provide an integer
20050 bit pattern that equates to a float, so check that the
20051 conversion has worked. */
20052 if (is_quarter_float (new_imm))
20053 {
20054 if (is_quarter_float (inst.operands[1].imm))
20055 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20056
20057 inst.operands[1].imm = new_imm;
20058 inst.operands[1].immisfloat = 1;
20059 }
58ed5c38
TC
20060 }
20061
037e8744 20062 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
20063 {
20064 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20065 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20066
20067 /* ARMv8.2 fp16 vmov.f16 instruction. */
20068 if (rs == NS_HI)
20069 do_scalar_fp16_v82_encode ();
477330fc 20070 }
5287ad62 20071 else
477330fc 20072 first_error (_("immediate out of range"));
037e8744 20073 break;
5f4273c7 20074
9db2f6b4 20075 case NS_RH:
037e8744
JB
20076 case NS_RF: /* case 12 (fmrs). */
20077 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20078 /* ARMv8.2 fp16 vmov.f16 instruction. */
20079 if (rs == NS_RH)
20080 do_scalar_fp16_v82_encode ();
037e8744 20081 break;
5f4273c7 20082
9db2f6b4 20083 case NS_HR:
037e8744
JB
20084 case NS_FR: /* case 13 (fmsr). */
20085 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20086 /* ARMv8.2 fp16 vmov.f16 instruction. */
20087 if (rs == NS_HR)
20088 do_scalar_fp16_v82_encode ();
037e8744 20089 break;
5f4273c7 20090
57785aa2
AV
20091 case NS_RRSS:
20092 do_mve_mov (0);
20093 break;
20094 case NS_SSRR:
20095 do_mve_mov (1);
20096 break;
20097
037e8744
JB
20098 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20099 (one of which is a list), but we have parsed four. Do some fiddling to
20100 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20101 expect. */
20102 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20103 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20104 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20105 _(BAD_FPU));
037e8744 20106 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20107 _("VFP registers must be adjacent"));
037e8744
JB
20108 inst.operands[2].imm = 2;
20109 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20110 do_vfp_nsyn_opcode ("fmrrs");
20111 break;
5f4273c7 20112
037e8744 20113 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20114 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20115 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20116 _(BAD_FPU));
037e8744 20117 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20118 _("VFP registers must be adjacent"));
037e8744
JB
20119 inst.operands[1] = inst.operands[2];
20120 inst.operands[2] = inst.operands[3];
20121 inst.operands[0].imm = 2;
20122 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20123 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20124 break;
5f4273c7 20125
4c261dff
NC
20126 case NS_NULL:
20127 /* neon_select_shape has determined that the instruction
20128 shape is wrong and has already set the error message. */
20129 break;
20130
5287ad62
JB
20131 default:
20132 abort ();
20133 }
20134}
20135
57785aa2
AV
20136static void
20137do_mve_movl (void)
20138{
20139 if (!(inst.operands[0].present && inst.operands[0].isquad
20140 && inst.operands[1].present && inst.operands[1].isquad
20141 && !inst.operands[2].present))
20142 {
20143 inst.instruction = 0;
20144 inst.cond = 0xb;
20145 if (thumb_mode)
20146 set_pred_insn_type (INSIDE_IT_INSN);
20147 do_neon_mov ();
20148 return;
20149 }
20150
20151 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20152 return;
20153
20154 if (inst.cond != COND_ALWAYS)
20155 inst.pred_insn_type = INSIDE_VPT_INSN;
20156
20157 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20158 | N_S16 | N_U16 | N_KEY);
20159
20160 inst.instruction |= (et.type == NT_unsigned) << 28;
20161 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20162 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20163 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20164 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20165 inst.instruction |= LOW4 (inst.operands[1].reg);
20166 inst.is_neon = 1;
20167}
20168
5287ad62
JB
20169static void
20170do_neon_rshift_round_imm (void)
20171{
64c350f2 20172 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20173 return;
20174
20175 enum neon_shape rs;
20176 struct neon_type_el et;
20177
20178 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20179 {
20180 rs = neon_select_shape (NS_QQI, NS_NULL);
20181 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20182 }
20183 else
20184 {
20185 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20186 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20187 }
5287ad62
JB
20188 int imm = inst.operands[2].imm;
20189
20190 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20191 if (imm == 0)
20192 {
20193 inst.operands[2].present = 0;
20194 do_neon_mov ();
20195 return;
20196 }
20197
20198 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20199 _("immediate out of range for shift"));
037e8744 20200 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20201 et.size - imm);
5287ad62
JB
20202}
20203
9db2f6b4
RL
20204static void
20205do_neon_movhf (void)
20206{
20207 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20208 constraint (rs != NS_HH, _("invalid suffix"));
20209
7bdf778b
ASDV
20210 if (inst.cond != COND_ALWAYS)
20211 {
20212 if (thumb_mode)
20213 {
20214 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20215 " the behaviour is UNPREDICTABLE"));
20216 }
20217 else
20218 {
20219 inst.error = BAD_COND;
20220 return;
20221 }
20222 }
20223
9db2f6b4
RL
20224 do_vfp_sp_monadic ();
20225
20226 inst.is_neon = 1;
20227 inst.instruction |= 0xf0000000;
20228}
20229
5287ad62
JB
20230static void
20231do_neon_movl (void)
20232{
20233 struct neon_type_el et = neon_check_type (2, NS_QD,
20234 N_EQK | N_DBL, N_SU_32 | N_KEY);
20235 unsigned sizebits = et.size >> 3;
20236 inst.instruction |= sizebits << 19;
20237 neon_two_same (0, et.type == NT_unsigned, -1);
20238}
20239
20240static void
20241do_neon_trn (void)
20242{
037e8744 20243 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20244 struct neon_type_el et = neon_check_type (2, rs,
20245 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20246 NEON_ENCODE (INTEGER, inst);
037e8744 20247 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20248}
20249
20250static void
20251do_neon_zip_uzp (void)
20252{
037e8744 20253 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20254 struct neon_type_el et = neon_check_type (2, rs,
20255 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20256 if (rs == NS_DD && et.size == 32)
20257 {
20258 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20259 inst.instruction = N_MNEM_vtrn;
20260 do_neon_trn ();
20261 return;
20262 }
037e8744 20263 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20264}
20265
20266static void
20267do_neon_sat_abs_neg (void)
20268{
64c350f2 20269 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20270 return;
20271
20272 enum neon_shape rs;
20273 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20274 rs = neon_select_shape (NS_QQ, NS_NULL);
20275 else
20276 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20277 struct neon_type_el et = neon_check_type (2, rs,
20278 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20279 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20280}
20281
20282static void
20283do_neon_pair_long (void)
20284{
037e8744 20285 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20286 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20287 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20288 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20289 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20290}
20291
20292static void
20293do_neon_recip_est (void)
20294{
037e8744 20295 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20296 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20297 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20298 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20299 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20300}
20301
20302static void
20303do_neon_cls (void)
20304{
64c350f2 20305 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20306 return;
20307
20308 enum neon_shape rs;
20309 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20310 rs = neon_select_shape (NS_QQ, NS_NULL);
20311 else
20312 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20313
5287ad62
JB
20314 struct neon_type_el et = neon_check_type (2, rs,
20315 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20316 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20317}
20318
20319static void
20320do_neon_clz (void)
20321{
64c350f2 20322 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20323 return;
20324
20325 enum neon_shape rs;
20326 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20327 rs = neon_select_shape (NS_QQ, NS_NULL);
20328 else
20329 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20330
5287ad62
JB
20331 struct neon_type_el et = neon_check_type (2, rs,
20332 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20333 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20334}
20335
20336static void
20337do_neon_cnt (void)
20338{
037e8744 20339 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20340 struct neon_type_el et = neon_check_type (2, rs,
20341 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20342 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20343}
20344
20345static void
20346do_neon_swp (void)
20347{
037e8744
JB
20348 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20349 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20350}
20351
20352static void
20353do_neon_tbl_tbx (void)
20354{
20355 unsigned listlenbits;
dcbf9037 20356 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20357
5287ad62
JB
20358 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20359 {
dcbf9037 20360 first_error (_("bad list length for table lookup"));
5287ad62
JB
20361 return;
20362 }
5f4273c7 20363
5287ad62
JB
20364 listlenbits = inst.operands[1].imm - 1;
20365 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20366 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20367 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20368 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20369 inst.instruction |= LOW4 (inst.operands[2].reg);
20370 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20371 inst.instruction |= listlenbits << 8;
5f4273c7 20372
88714cb8 20373 neon_dp_fixup (&inst);
5287ad62
JB
20374}
20375
20376static void
20377do_neon_ldm_stm (void)
20378{
20379 /* P, U and L bits are part of bitmask. */
20380 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20381 unsigned offsetbits = inst.operands[1].imm * 2;
20382
037e8744
JB
20383 if (inst.operands[1].issingle)
20384 {
20385 do_vfp_nsyn_ldm_stm (is_dbmode);
20386 return;
20387 }
20388
5287ad62 20389 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20390 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20391
20392 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20393 _("register list must contain at least 1 and at most 16 "
20394 "registers"));
5287ad62
JB
20395
20396 inst.instruction |= inst.operands[0].reg << 16;
20397 inst.instruction |= inst.operands[0].writeback << 21;
20398 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20399 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20400
20401 inst.instruction |= offsetbits;
5f4273c7 20402
037e8744 20403 do_vfp_cond_or_thumb ();
5287ad62
JB
20404}
20405
20406static void
20407do_neon_ldr_str (void)
20408{
5287ad62 20409 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20410
6844b2c2
MGD
20411 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20412 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20413 if (!is_ldr
6844b2c2 20414 && inst.operands[1].reg == REG_PC
ba86b375 20415 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20416 {
94dcf8bf 20417 if (thumb_mode)
6844b2c2 20418 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20419 else if (warn_on_deprecated)
5c3696f8 20420 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20421 }
20422
037e8744
JB
20423 if (inst.operands[0].issingle)
20424 {
cd2f129f 20425 if (is_ldr)
477330fc 20426 do_vfp_nsyn_opcode ("flds");
cd2f129f 20427 else
477330fc 20428 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20429
20430 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20431 if (inst.vectype.el[0].size == 16)
20432 do_scalar_fp16_v82_encode ();
5287ad62
JB
20433 }
20434 else
5287ad62 20435 {
cd2f129f 20436 if (is_ldr)
477330fc 20437 do_vfp_nsyn_opcode ("fldd");
5287ad62 20438 else
477330fc 20439 do_vfp_nsyn_opcode ("fstd");
5287ad62 20440 }
5287ad62
JB
20441}
20442
32c36c3c
AV
20443static void
20444do_t_vldr_vstr_sysreg (void)
20445{
20446 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20447 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20448
20449 /* Use of PC is UNPREDICTABLE. */
20450 if (inst.operands[1].reg == REG_PC)
20451 inst.error = _("Use of PC here is UNPREDICTABLE");
20452
20453 if (inst.operands[1].immisreg)
20454 inst.error = _("instruction does not accept register index");
20455
20456 if (!inst.operands[1].isreg)
20457 inst.error = _("instruction does not accept PC-relative addressing");
20458
20459 if (abs (inst.operands[1].imm) >= (1 << 7))
20460 inst.error = _("immediate value out of range");
20461
20462 inst.instruction = 0xec000f80;
20463 if (is_vldr)
20464 inst.instruction |= 1 << sysreg_vldr_bitno;
20465 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20466 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20467 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20468}
20469
20470static void
20471do_vldr_vstr (void)
20472{
20473 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20474
20475 /* VLDR/VSTR (System Register). */
20476 if (sysreg_op)
20477 {
20478 if (!mark_feature_used (&arm_ext_v8_1m_main))
20479 as_bad (_("Instruction not permitted on this architecture"));
20480
20481 do_t_vldr_vstr_sysreg ();
20482 }
20483 /* VLDR/VSTR. */
20484 else
20485 {
20486 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
20487 as_bad (_("Instruction not permitted on this architecture"));
20488 do_neon_ldr_str ();
20489 }
20490}
20491
5287ad62
JB
20492/* "interleave" version also handles non-interleaving register VLD1/VST1
20493 instructions. */
20494
20495static void
20496do_neon_ld_st_interleave (void)
20497{
037e8744 20498 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20499 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20500 unsigned alignbits = 0;
20501 unsigned idx;
20502 /* The bits in this table go:
20503 0: register stride of one (0) or two (1)
20504 1,2: register list length, minus one (1, 2, 3, 4).
20505 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20506 We use -1 for invalid entries. */
20507 const int typetable[] =
20508 {
20509 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20510 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20511 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20512 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20513 };
20514 int typebits;
20515
dcbf9037
JB
20516 if (et.type == NT_invtype)
20517 return;
20518
5287ad62
JB
20519 if (inst.operands[1].immisalign)
20520 switch (inst.operands[1].imm >> 8)
20521 {
20522 case 64: alignbits = 1; break;
20523 case 128:
477330fc 20524 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20525 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20526 goto bad_alignment;
20527 alignbits = 2;
20528 break;
5287ad62 20529 case 256:
477330fc
RM
20530 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20531 goto bad_alignment;
20532 alignbits = 3;
20533 break;
5287ad62
JB
20534 default:
20535 bad_alignment:
477330fc
RM
20536 first_error (_("bad alignment"));
20537 return;
5287ad62
JB
20538 }
20539
20540 inst.instruction |= alignbits << 4;
20541 inst.instruction |= neon_logbits (et.size) << 6;
20542
20543 /* Bits [4:6] of the immediate in a list specifier encode register stride
20544 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20545 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20546 up the right value for "type" in a table based on this value and the given
20547 list style, then stick it back. */
20548 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20549 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20550
20551 typebits = typetable[idx];
5f4273c7 20552
5287ad62 20553 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20554 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20555 BAD_EL_TYPE);
5287ad62
JB
20556
20557 inst.instruction &= ~0xf00;
20558 inst.instruction |= typebits << 8;
20559}
20560
20561/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20562 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20563 otherwise. The variable arguments are a list of pairs of legal (size, align)
20564 values, terminated with -1. */
20565
20566static int
aa8a0863 20567neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20568{
20569 va_list ap;
20570 int result = FAIL, thissize, thisalign;
5f4273c7 20571
5287ad62
JB
20572 if (!inst.operands[1].immisalign)
20573 {
aa8a0863 20574 *do_alignment = 0;
5287ad62
JB
20575 return SUCCESS;
20576 }
5f4273c7 20577
aa8a0863 20578 va_start (ap, do_alignment);
5287ad62
JB
20579
20580 do
20581 {
20582 thissize = va_arg (ap, int);
20583 if (thissize == -1)
477330fc 20584 break;
5287ad62
JB
20585 thisalign = va_arg (ap, int);
20586
20587 if (size == thissize && align == thisalign)
477330fc 20588 result = SUCCESS;
5287ad62
JB
20589 }
20590 while (result != SUCCESS);
20591
20592 va_end (ap);
20593
20594 if (result == SUCCESS)
aa8a0863 20595 *do_alignment = 1;
5287ad62 20596 else
dcbf9037 20597 first_error (_("unsupported alignment for instruction"));
5f4273c7 20598
5287ad62
JB
20599 return result;
20600}
20601
20602static void
20603do_neon_ld_st_lane (void)
20604{
037e8744 20605 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20606 int align_good, do_alignment = 0;
5287ad62
JB
20607 int logsize = neon_logbits (et.size);
20608 int align = inst.operands[1].imm >> 8;
20609 int n = (inst.instruction >> 8) & 3;
20610 int max_el = 64 / et.size;
5f4273c7 20611
dcbf9037
JB
20612 if (et.type == NT_invtype)
20613 return;
5f4273c7 20614
5287ad62 20615 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20616 _("bad list length"));
5287ad62 20617 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20618 _("scalar index out of range"));
5287ad62 20619 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20620 && et.size == 8,
20621 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20622
5287ad62
JB
20623 switch (n)
20624 {
20625 case 0: /* VLD1 / VST1. */
aa8a0863 20626 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20627 32, 32, -1);
5287ad62 20628 if (align_good == FAIL)
477330fc 20629 return;
aa8a0863 20630 if (do_alignment)
477330fc
RM
20631 {
20632 unsigned alignbits = 0;
20633 switch (et.size)
20634 {
20635 case 16: alignbits = 0x1; break;
20636 case 32: alignbits = 0x3; break;
20637 default: ;
20638 }
20639 inst.instruction |= alignbits << 4;
20640 }
5287ad62
JB
20641 break;
20642
20643 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20644 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20645 16, 32, 32, 64, -1);
5287ad62 20646 if (align_good == FAIL)
477330fc 20647 return;
aa8a0863 20648 if (do_alignment)
477330fc 20649 inst.instruction |= 1 << 4;
5287ad62
JB
20650 break;
20651
20652 case 2: /* VLD3 / VST3. */
20653 constraint (inst.operands[1].immisalign,
477330fc 20654 _("can't use alignment with this instruction"));
5287ad62
JB
20655 break;
20656
20657 case 3: /* VLD4 / VST4. */
aa8a0863 20658 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20659 16, 64, 32, 64, 32, 128, -1);
5287ad62 20660 if (align_good == FAIL)
477330fc 20661 return;
aa8a0863 20662 if (do_alignment)
477330fc
RM
20663 {
20664 unsigned alignbits = 0;
20665 switch (et.size)
20666 {
20667 case 8: alignbits = 0x1; break;
20668 case 16: alignbits = 0x1; break;
20669 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20670 default: ;
20671 }
20672 inst.instruction |= alignbits << 4;
20673 }
5287ad62
JB
20674 break;
20675
20676 default: ;
20677 }
20678
20679 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
20680 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20681 inst.instruction |= 1 << (4 + logsize);
5f4273c7 20682
5287ad62
JB
20683 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
20684 inst.instruction |= logsize << 10;
20685}
20686
20687/* Encode single n-element structure to all lanes VLD<n> instructions. */
20688
20689static void
20690do_neon_ld_dup (void)
20691{
037e8744 20692 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20693 int align_good, do_alignment = 0;
5287ad62 20694
dcbf9037
JB
20695 if (et.type == NT_invtype)
20696 return;
20697
5287ad62
JB
20698 switch ((inst.instruction >> 8) & 3)
20699 {
20700 case 0: /* VLD1. */
9c2799c2 20701 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 20702 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 20703 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 20704 if (align_good == FAIL)
477330fc 20705 return;
5287ad62 20706 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
20707 {
20708 case 1: break;
20709 case 2: inst.instruction |= 1 << 5; break;
20710 default: first_error (_("bad list length")); return;
20711 }
5287ad62
JB
20712 inst.instruction |= neon_logbits (et.size) << 6;
20713 break;
20714
20715 case 1: /* VLD2. */
20716 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
20717 &do_alignment, 8, 16, 16, 32, 32, 64,
20718 -1);
5287ad62 20719 if (align_good == FAIL)
477330fc 20720 return;
5287ad62 20721 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 20722 _("bad list length"));
5287ad62 20723 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 20724 inst.instruction |= 1 << 5;
5287ad62
JB
20725 inst.instruction |= neon_logbits (et.size) << 6;
20726 break;
20727
20728 case 2: /* VLD3. */
20729 constraint (inst.operands[1].immisalign,
477330fc 20730 _("can't use alignment with this instruction"));
5287ad62 20731 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 20732 _("bad list length"));
5287ad62 20733 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 20734 inst.instruction |= 1 << 5;
5287ad62
JB
20735 inst.instruction |= neon_logbits (et.size) << 6;
20736 break;
20737
20738 case 3: /* VLD4. */
20739 {
477330fc 20740 int align = inst.operands[1].imm >> 8;
aa8a0863 20741 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
20742 16, 64, 32, 64, 32, 128, -1);
20743 if (align_good == FAIL)
20744 return;
20745 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
20746 _("bad list length"));
20747 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20748 inst.instruction |= 1 << 5;
20749 if (et.size == 32 && align == 128)
20750 inst.instruction |= 0x3 << 6;
20751 else
20752 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
20753 }
20754 break;
20755
20756 default: ;
20757 }
20758
aa8a0863 20759 inst.instruction |= do_alignment << 4;
5287ad62
JB
20760}
20761
20762/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
20763 apart from bits [11:4]. */
20764
20765static void
20766do_neon_ldx_stx (void)
20767{
b1a769ed
DG
20768 if (inst.operands[1].isreg)
20769 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
20770
5287ad62
JB
20771 switch (NEON_LANE (inst.operands[0].imm))
20772 {
20773 case NEON_INTERLEAVE_LANES:
88714cb8 20774 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
20775 do_neon_ld_st_interleave ();
20776 break;
5f4273c7 20777
5287ad62 20778 case NEON_ALL_LANES:
88714cb8 20779 NEON_ENCODE (DUP, inst);
2d51fb74
JB
20780 if (inst.instruction == N_INV)
20781 {
20782 first_error ("only loads support such operands");
20783 break;
20784 }
5287ad62
JB
20785 do_neon_ld_dup ();
20786 break;
5f4273c7 20787
5287ad62 20788 default:
88714cb8 20789 NEON_ENCODE (LANE, inst);
5287ad62
JB
20790 do_neon_ld_st_lane ();
20791 }
20792
20793 /* L bit comes from bit mask. */
20794 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20795 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20796 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 20797
5287ad62
JB
20798 if (inst.operands[1].postind)
20799 {
20800 int postreg = inst.operands[1].imm & 0xf;
20801 constraint (!inst.operands[1].immisreg,
477330fc 20802 _("post-index must be a register"));
5287ad62 20803 constraint (postreg == 0xd || postreg == 0xf,
477330fc 20804 _("bad register for post-index"));
5287ad62
JB
20805 inst.instruction |= postreg;
20806 }
4f2374c7 20807 else
5287ad62 20808 {
4f2374c7 20809 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
20810 constraint (inst.relocs[0].exp.X_op != O_constant
20811 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
20812 BAD_ADDR_MODE);
20813
20814 if (inst.operands[1].writeback)
20815 {
20816 inst.instruction |= 0xd;
20817 }
20818 else
20819 inst.instruction |= 0xf;
5287ad62 20820 }
5f4273c7 20821
5287ad62
JB
20822 if (thumb_mode)
20823 inst.instruction |= 0xf9000000;
20824 else
20825 inst.instruction |= 0xf4000000;
20826}
33399f07
MGD
20827
20828/* FP v8. */
20829static void
20830do_vfp_nsyn_fpv8 (enum neon_shape rs)
20831{
a715796b
TG
20832 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20833 D register operands. */
20834 if (neon_shape_class[rs] == SC_DOUBLE)
20835 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20836 _(BAD_FPU));
20837
33399f07
MGD
20838 NEON_ENCODE (FPV8, inst);
20839
9db2f6b4
RL
20840 if (rs == NS_FFF || rs == NS_HHH)
20841 {
20842 do_vfp_sp_dyadic ();
20843
20844 /* ARMv8.2 fp16 instruction. */
20845 if (rs == NS_HHH)
20846 do_scalar_fp16_v82_encode ();
20847 }
33399f07
MGD
20848 else
20849 do_vfp_dp_rd_rn_rm ();
20850
20851 if (rs == NS_DDD)
20852 inst.instruction |= 0x100;
20853
20854 inst.instruction |= 0xf0000000;
20855}
20856
20857static void
20858do_vsel (void)
20859{
5ee91343 20860 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
20861
20862 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
20863 first_error (_("invalid instruction shape"));
20864}
20865
73924fbc
MGD
20866static void
20867do_vmaxnm (void)
20868{
935295b5
AV
20869 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20870 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
20871
20872 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
20873 return;
20874
64c350f2 20875 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
20876 return;
20877
cc933301 20878 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
20879}
20880
30bdf752
MGD
20881static void
20882do_vrint_1 (enum neon_cvt_mode mode)
20883{
9db2f6b4 20884 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
20885 struct neon_type_el et;
20886
20887 if (rs == NS_NULL)
20888 return;
20889
a715796b
TG
20890 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20891 D register operands. */
20892 if (neon_shape_class[rs] == SC_DOUBLE)
20893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20894 _(BAD_FPU));
20895
9db2f6b4
RL
20896 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
20897 | N_VFP);
30bdf752
MGD
20898 if (et.type != NT_invtype)
20899 {
20900 /* VFP encodings. */
20901 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
20902 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 20903 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
20904
20905 NEON_ENCODE (FPV8, inst);
9db2f6b4 20906 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
20907 do_vfp_sp_monadic ();
20908 else
20909 do_vfp_dp_rd_rm ();
20910
20911 switch (mode)
20912 {
20913 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
20914 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
20915 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
20916 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
20917 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
20918 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
20919 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
20920 default: abort ();
20921 }
20922
20923 inst.instruction |= (rs == NS_DD) << 8;
20924 do_vfp_cond_or_thumb ();
9db2f6b4
RL
20925
20926 /* ARMv8.2 fp16 vrint instruction. */
20927 if (rs == NS_HH)
20928 do_scalar_fp16_v82_encode ();
30bdf752
MGD
20929 }
20930 else
20931 {
20932 /* Neon encodings (or something broken...). */
20933 inst.error = NULL;
cc933301 20934 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
20935
20936 if (et.type == NT_invtype)
20937 return;
20938
64c350f2
AV
20939 if (!check_simd_pred_availability (TRUE,
20940 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
20941 return;
20942
a710b305
AV
20943 NEON_ENCODE (FLOAT, inst);
20944
30bdf752
MGD
20945 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20946 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20947 inst.instruction |= LOW4 (inst.operands[1].reg);
20948 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20949 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
20950 /* Mask off the original size bits and reencode them. */
20951 inst.instruction = ((inst.instruction & 0xfff3ffff)
20952 | neon_logbits (et.size) << 18);
20953
30bdf752
MGD
20954 switch (mode)
20955 {
20956 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
20957 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
20958 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
20959 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
20960 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
20961 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
20962 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
20963 default: abort ();
20964 }
20965
20966 if (thumb_mode)
20967 inst.instruction |= 0xfc000000;
20968 else
20969 inst.instruction |= 0xf0000000;
20970 }
20971}
20972
20973static void
20974do_vrintx (void)
20975{
20976 do_vrint_1 (neon_cvt_mode_x);
20977}
20978
20979static void
20980do_vrintz (void)
20981{
20982 do_vrint_1 (neon_cvt_mode_z);
20983}
20984
20985static void
20986do_vrintr (void)
20987{
20988 do_vrint_1 (neon_cvt_mode_r);
20989}
20990
20991static void
20992do_vrinta (void)
20993{
20994 do_vrint_1 (neon_cvt_mode_a);
20995}
20996
20997static void
20998do_vrintn (void)
20999{
21000 do_vrint_1 (neon_cvt_mode_n);
21001}
21002
21003static void
21004do_vrintp (void)
21005{
21006 do_vrint_1 (neon_cvt_mode_p);
21007}
21008
21009static void
21010do_vrintm (void)
21011{
21012 do_vrint_1 (neon_cvt_mode_m);
21013}
21014
c28eeff2
SN
21015static unsigned
21016neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21017{
21018 unsigned regno = NEON_SCALAR_REG (opnd);
21019 unsigned elno = NEON_SCALAR_INDEX (opnd);
21020
21021 if (elsize == 16 && elno < 2 && regno < 16)
21022 return regno | (elno << 4);
21023 else if (elsize == 32 && elno == 0)
21024 return regno;
21025
21026 first_error (_("scalar out of range"));
21027 return 0;
21028}
21029
21030static void
21031do_vcmla (void)
21032{
5d281bf0
AV
21033 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21034 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21035 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21036 constraint (inst.relocs[0].exp.X_op != O_constant,
21037 _("expression too complex"));
21038 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21039 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21040 _("immediate out of range"));
21041 rot /= 90;
5d281bf0 21042
64c350f2
AV
21043 if (!check_simd_pred_availability (TRUE,
21044 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21045 return;
21046
c28eeff2
SN
21047 if (inst.operands[2].isscalar)
21048 {
5d281bf0
AV
21049 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21050 first_error (_("invalid instruction shape"));
c28eeff2
SN
21051 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21052 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21053 N_KEY | N_F16 | N_F32).size;
21054 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21055 inst.is_neon = 1;
21056 inst.instruction = 0xfe000800;
21057 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21058 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21059 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21060 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21061 inst.instruction |= LOW4 (m);
21062 inst.instruction |= HI1 (m) << 5;
21063 inst.instruction |= neon_quad (rs) << 6;
21064 inst.instruction |= rot << 20;
21065 inst.instruction |= (size == 32) << 23;
21066 }
21067 else
21068 {
5d281bf0
AV
21069 enum neon_shape rs;
21070 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21071 rs = neon_select_shape (NS_QQQI, NS_NULL);
21072 else
21073 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21074
c28eeff2
SN
21075 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21076 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21077 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21078 && (inst.operands[0].reg == inst.operands[1].reg
21079 || inst.operands[0].reg == inst.operands[2].reg))
21080 as_tsktsk (BAD_MVE_SRCDEST);
21081
c28eeff2
SN
21082 neon_three_same (neon_quad (rs), 0, -1);
21083 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21084 inst.instruction |= 0xfc200800;
21085 inst.instruction |= rot << 23;
21086 inst.instruction |= (size == 32) << 20;
21087 }
21088}
21089
21090static void
21091do_vcadd (void)
21092{
5d281bf0
AV
21093 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21094 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21095 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21096 constraint (inst.relocs[0].exp.X_op != O_constant,
21097 _("expression too complex"));
5d281bf0 21098
e2b0ab59 21099 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21100 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21101 enum neon_shape rs;
21102 struct neon_type_el et;
21103 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21104 {
21105 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21106 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21107 }
21108 else
21109 {
21110 rs = neon_select_shape (NS_QQQI, NS_NULL);
21111 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21112 | N_I16 | N_I32);
21113 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21114 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21115 "operand makes instruction UNPREDICTABLE"));
21116 }
21117
21118 if (et.type == NT_invtype)
21119 return;
21120
64c350f2
AV
21121 if (!check_simd_pred_availability (et.type == NT_float,
21122 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21123 return;
21124
21125 if (et.type == NT_float)
21126 {
21127 neon_three_same (neon_quad (rs), 0, -1);
21128 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21129 inst.instruction |= 0xfc800800;
21130 inst.instruction |= (rot == 270) << 24;
21131 inst.instruction |= (et.size == 32) << 20;
21132 }
21133 else
21134 {
21135 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21136 inst.instruction = 0xfe000f00;
21137 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21138 inst.instruction |= neon_logbits (et.size) << 20;
21139 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21140 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21141 inst.instruction |= (rot == 270) << 12;
21142 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21143 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21144 inst.instruction |= LOW4 (inst.operands[2].reg);
21145 inst.is_neon = 1;
21146 }
c28eeff2
SN
21147}
21148
c604a79a
JW
21149/* Dot Product instructions encoding support. */
21150
21151static void
21152do_neon_dotproduct (int unsigned_p)
21153{
21154 enum neon_shape rs;
21155 unsigned scalar_oprd2 = 0;
21156 int high8;
21157
21158 if (inst.cond != COND_ALWAYS)
21159 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21160 "is UNPREDICTABLE"));
21161
21162 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21163 _(BAD_FPU));
21164
21165 /* Dot Product instructions are in three-same D/Q register format or the third
21166 operand can be a scalar index register. */
21167 if (inst.operands[2].isscalar)
21168 {
21169 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21170 high8 = 0xfe000000;
21171 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21172 }
21173 else
21174 {
21175 high8 = 0xfc000000;
21176 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21177 }
21178
21179 if (unsigned_p)
21180 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21181 else
21182 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21183
21184 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21185 Product instruction, so we pass 0 as the "ubit" parameter. And the
21186 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21187 neon_three_same (neon_quad (rs), 0, 32);
21188
21189 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21190 different NEON three-same encoding. */
21191 inst.instruction &= 0x00ffffff;
21192 inst.instruction |= high8;
21193 /* Encode 'U' bit which indicates signedness. */
21194 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21195 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21196 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21197 the instruction encoding. */
21198 if (inst.operands[2].isscalar)
21199 {
21200 inst.instruction &= 0xffffffd0;
21201 inst.instruction |= LOW4 (scalar_oprd2);
21202 inst.instruction |= HI1 (scalar_oprd2) << 5;
21203 }
21204}
21205
21206/* Dot Product instructions for signed integer. */
21207
21208static void
21209do_neon_dotproduct_s (void)
21210{
21211 return do_neon_dotproduct (0);
21212}
21213
21214/* Dot Product instructions for unsigned integer. */
21215
21216static void
21217do_neon_dotproduct_u (void)
21218{
21219 return do_neon_dotproduct (1);
21220}
21221
91ff7894
MGD
21222/* Crypto v1 instructions. */
21223static void
21224do_crypto_2op_1 (unsigned elttype, int op)
21225{
5ee91343 21226 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
21227
21228 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
21229 == NT_invtype)
21230 return;
21231
21232 inst.error = NULL;
21233
21234 NEON_ENCODE (INTEGER, inst);
21235 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21237 inst.instruction |= LOW4 (inst.operands[1].reg);
21238 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21239 if (op != -1)
21240 inst.instruction |= op << 6;
21241
21242 if (thumb_mode)
21243 inst.instruction |= 0xfc000000;
21244 else
21245 inst.instruction |= 0xf0000000;
21246}
21247
48adcd8e
MGD
21248static void
21249do_crypto_3op_1 (int u, int op)
21250{
5ee91343 21251 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
21252
21253 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
21254 N_32 | N_UNT | N_KEY).type == NT_invtype)
21255 return;
21256
21257 inst.error = NULL;
21258
21259 NEON_ENCODE (INTEGER, inst);
21260 neon_three_same (1, u, 8 << op);
21261}
21262
91ff7894
MGD
21263static void
21264do_aese (void)
21265{
21266 do_crypto_2op_1 (N_8, 0);
21267}
21268
21269static void
21270do_aesd (void)
21271{
21272 do_crypto_2op_1 (N_8, 1);
21273}
21274
21275static void
21276do_aesmc (void)
21277{
21278 do_crypto_2op_1 (N_8, 2);
21279}
21280
21281static void
21282do_aesimc (void)
21283{
21284 do_crypto_2op_1 (N_8, 3);
21285}
21286
48adcd8e
MGD
21287static void
21288do_sha1c (void)
21289{
21290 do_crypto_3op_1 (0, 0);
21291}
21292
21293static void
21294do_sha1p (void)
21295{
21296 do_crypto_3op_1 (0, 1);
21297}
21298
21299static void
21300do_sha1m (void)
21301{
21302 do_crypto_3op_1 (0, 2);
21303}
21304
21305static void
21306do_sha1su0 (void)
21307{
21308 do_crypto_3op_1 (0, 3);
21309}
91ff7894 21310
48adcd8e
MGD
21311static void
21312do_sha256h (void)
21313{
21314 do_crypto_3op_1 (1, 0);
21315}
21316
21317static void
21318do_sha256h2 (void)
21319{
21320 do_crypto_3op_1 (1, 1);
21321}
21322
21323static void
21324do_sha256su1 (void)
21325{
21326 do_crypto_3op_1 (1, 2);
21327}
3c9017d2
MGD
21328
21329static void
21330do_sha1h (void)
21331{
21332 do_crypto_2op_1 (N_32, -1);
21333}
21334
21335static void
21336do_sha1su1 (void)
21337{
21338 do_crypto_2op_1 (N_32, 0);
21339}
21340
21341static void
21342do_sha256su0 (void)
21343{
21344 do_crypto_2op_1 (N_32, 1);
21345}
dd5181d5
KT
21346
21347static void
21348do_crc32_1 (unsigned int poly, unsigned int sz)
21349{
21350 unsigned int Rd = inst.operands[0].reg;
21351 unsigned int Rn = inst.operands[1].reg;
21352 unsigned int Rm = inst.operands[2].reg;
21353
5ee91343 21354 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
21355 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
21356 inst.instruction |= LOW4 (Rn) << 16;
21357 inst.instruction |= LOW4 (Rm);
21358 inst.instruction |= sz << (thumb_mode ? 4 : 21);
21359 inst.instruction |= poly << (thumb_mode ? 20 : 9);
21360
21361 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
21362 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
21363}
21364
21365static void
21366do_crc32b (void)
21367{
21368 do_crc32_1 (0, 0);
21369}
21370
21371static void
21372do_crc32h (void)
21373{
21374 do_crc32_1 (0, 1);
21375}
21376
21377static void
21378do_crc32w (void)
21379{
21380 do_crc32_1 (0, 2);
21381}
21382
21383static void
21384do_crc32cb (void)
21385{
21386 do_crc32_1 (1, 0);
21387}
21388
21389static void
21390do_crc32ch (void)
21391{
21392 do_crc32_1 (1, 1);
21393}
21394
21395static void
21396do_crc32cw (void)
21397{
21398 do_crc32_1 (1, 2);
21399}
21400
49e8a725
SN
21401static void
21402do_vjcvt (void)
21403{
21404 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21405 _(BAD_FPU));
21406 neon_check_type (2, NS_FD, N_S32, N_F64);
21407 do_vfp_sp_dp_cvt ();
21408 do_vfp_cond_or_thumb ();
21409}
21410
5287ad62
JB
21411\f
21412/* Overall per-instruction processing. */
21413
21414/* We need to be able to fix up arbitrary expressions in some statements.
21415 This is so that we can handle symbols that are an arbitrary distance from
21416 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
21417 which returns part of an address in a form which will be valid for
21418 a data instruction. We do this by pushing the expression into a symbol
21419 in the expr_section, and creating a fix for that. */
21420
21421static void
21422fix_new_arm (fragS * frag,
21423 int where,
21424 short int size,
21425 expressionS * exp,
21426 int pc_rel,
21427 int reloc)
21428{
21429 fixS * new_fix;
21430
21431 switch (exp->X_op)
21432 {
21433 case O_constant:
6e7ce2cd
PB
21434 if (pc_rel)
21435 {
21436 /* Create an absolute valued symbol, so we have something to
477330fc
RM
21437 refer to in the object file. Unfortunately for us, gas's
21438 generic expression parsing will already have folded out
21439 any use of .set foo/.type foo %function that may have
21440 been used to set type information of the target location,
21441 that's being specified symbolically. We have to presume
21442 the user knows what they are doing. */
6e7ce2cd
PB
21443 char name[16 + 8];
21444 symbolS *symbol;
21445
21446 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
21447
21448 symbol = symbol_find_or_make (name);
21449 S_SET_SEGMENT (symbol, absolute_section);
21450 symbol_set_frag (symbol, &zero_address_frag);
21451 S_SET_VALUE (symbol, exp->X_add_number);
21452 exp->X_op = O_symbol;
21453 exp->X_add_symbol = symbol;
21454 exp->X_add_number = 0;
21455 }
21456 /* FALLTHROUGH */
5287ad62
JB
21457 case O_symbol:
21458 case O_add:
21459 case O_subtract:
21d799b5 21460 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 21461 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
21462 break;
21463
21464 default:
21d799b5 21465 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 21466 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
21467 break;
21468 }
21469
21470 /* Mark whether the fix is to a THUMB instruction, or an ARM
21471 instruction. */
21472 new_fix->tc_fix_data = thumb_mode;
21473}
21474
21475/* Create a frg for an instruction requiring relaxation. */
21476static void
21477output_relax_insn (void)
21478{
21479 char * to;
21480 symbolS *sym;
0110f2b8
PB
21481 int offset;
21482
6e1cb1a6
PB
21483 /* The size of the instruction is unknown, so tie the debug info to the
21484 start of the instruction. */
21485 dwarf2_emit_insn (0);
6e1cb1a6 21486
e2b0ab59 21487 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
21488 {
21489 case O_symbol:
e2b0ab59
AV
21490 sym = inst.relocs[0].exp.X_add_symbol;
21491 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
21492 break;
21493 case O_constant:
21494 sym = NULL;
e2b0ab59 21495 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
21496 break;
21497 default:
e2b0ab59 21498 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
21499 offset = 0;
21500 break;
21501 }
21502 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
21503 inst.relax, sym, offset, NULL/*offset, opcode*/);
21504 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
21505}
21506
21507/* Write a 32-bit thumb instruction to buf. */
21508static void
21509put_thumb32_insn (char * buf, unsigned long insn)
21510{
21511 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
21512 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
21513}
21514
b99bd4ef 21515static void
c19d1205 21516output_inst (const char * str)
b99bd4ef 21517{
c19d1205 21518 char * to = NULL;
b99bd4ef 21519
c19d1205 21520 if (inst.error)
b99bd4ef 21521 {
c19d1205 21522 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
21523 return;
21524 }
5f4273c7
NC
21525 if (inst.relax)
21526 {
21527 output_relax_insn ();
0110f2b8 21528 return;
5f4273c7 21529 }
c19d1205
ZW
21530 if (inst.size == 0)
21531 return;
b99bd4ef 21532
c19d1205 21533 to = frag_more (inst.size);
8dc2430f
NC
21534 /* PR 9814: Record the thumb mode into the current frag so that we know
21535 what type of NOP padding to use, if necessary. We override any previous
21536 setting so that if the mode has changed then the NOPS that we use will
21537 match the encoding of the last instruction in the frag. */
cd000bff 21538 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
21539
21540 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 21541 {
9c2799c2 21542 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 21543 put_thumb32_insn (to, inst.instruction);
b99bd4ef 21544 }
c19d1205 21545 else if (inst.size > INSN_SIZE)
b99bd4ef 21546 {
9c2799c2 21547 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
21548 md_number_to_chars (to, inst.instruction, INSN_SIZE);
21549 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 21550 }
c19d1205
ZW
21551 else
21552 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 21553
e2b0ab59
AV
21554 int r;
21555 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
21556 {
21557 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
21558 fix_new_arm (frag_now, to - frag_now->fr_literal,
21559 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
21560 inst.relocs[r].type);
21561 }
b99bd4ef 21562
c19d1205 21563 dwarf2_emit_insn (inst.size);
c19d1205 21564}
b99bd4ef 21565
e07e6e58
NC
21566static char *
21567output_it_inst (int cond, int mask, char * to)
21568{
21569 unsigned long instruction = 0xbf00;
21570
21571 mask &= 0xf;
21572 instruction |= mask;
21573 instruction |= cond << 4;
21574
21575 if (to == NULL)
21576 {
21577 to = frag_more (2);
21578#ifdef OBJ_ELF
21579 dwarf2_emit_insn (2);
21580#endif
21581 }
21582
21583 md_number_to_chars (to, instruction, 2);
21584
21585 return to;
21586}
21587
c19d1205
ZW
21588/* Tag values used in struct asm_opcode's tag field. */
21589enum opcode_tag
21590{
21591 OT_unconditional, /* Instruction cannot be conditionalized.
21592 The ARM condition field is still 0xE. */
21593 OT_unconditionalF, /* Instruction cannot be conditionalized
21594 and carries 0xF in its ARM condition field. */
21595 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
21596 OT_csuffixF, /* Some forms of the instruction take a scalar
21597 conditional suffix, others place 0xF where the
21598 condition field would be, others take a vector
21599 conditional suffix. */
c19d1205
ZW
21600 OT_cinfix3, /* Instruction takes a conditional infix,
21601 beginning at character index 3. (In
21602 unified mode, it becomes a suffix.) */
088fa78e
KH
21603 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
21604 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
21605 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
21606 character index 3, even in unified mode. Used for
21607 legacy instructions where suffix and infix forms
21608 may be ambiguous. */
c19d1205 21609 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 21610 suffix or an infix at character index 3. */
c19d1205
ZW
21611 OT_odd_infix_unc, /* This is the unconditional variant of an
21612 instruction that takes a conditional infix
21613 at an unusual position. In unified mode,
21614 this variant will accept a suffix. */
21615 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
21616 are the conditional variants of instructions that
21617 take conditional infixes in unusual positions.
21618 The infix appears at character index
21619 (tag - OT_odd_infix_0). These are not accepted
21620 in unified mode. */
21621};
b99bd4ef 21622
c19d1205
ZW
21623/* Subroutine of md_assemble, responsible for looking up the primary
21624 opcode from the mnemonic the user wrote. STR points to the
21625 beginning of the mnemonic.
21626
21627 This is not simply a hash table lookup, because of conditional
21628 variants. Most instructions have conditional variants, which are
21629 expressed with a _conditional affix_ to the mnemonic. If we were
21630 to encode each conditional variant as a literal string in the opcode
21631 table, it would have approximately 20,000 entries.
21632
21633 Most mnemonics take this affix as a suffix, and in unified syntax,
21634 'most' is upgraded to 'all'. However, in the divided syntax, some
21635 instructions take the affix as an infix, notably the s-variants of
21636 the arithmetic instructions. Of those instructions, all but six
21637 have the infix appear after the third character of the mnemonic.
21638
21639 Accordingly, the algorithm for looking up primary opcodes given
21640 an identifier is:
21641
21642 1. Look up the identifier in the opcode table.
21643 If we find a match, go to step U.
21644
21645 2. Look up the last two characters of the identifier in the
21646 conditions table. If we find a match, look up the first N-2
21647 characters of the identifier in the opcode table. If we
21648 find a match, go to step CE.
21649
21650 3. Look up the fourth and fifth characters of the identifier in
21651 the conditions table. If we find a match, extract those
21652 characters from the identifier, and look up the remaining
21653 characters in the opcode table. If we find a match, go
21654 to step CM.
21655
21656 4. Fail.
21657
21658 U. Examine the tag field of the opcode structure, in case this is
21659 one of the six instructions with its conditional infix in an
21660 unusual place. If it is, the tag tells us where to find the
21661 infix; look it up in the conditions table and set inst.cond
21662 accordingly. Otherwise, this is an unconditional instruction.
21663 Again set inst.cond accordingly. Return the opcode structure.
21664
21665 CE. Examine the tag field to make sure this is an instruction that
21666 should receive a conditional suffix. If it is not, fail.
21667 Otherwise, set inst.cond from the suffix we already looked up,
21668 and return the opcode structure.
21669
21670 CM. Examine the tag field to make sure this is an instruction that
21671 should receive a conditional infix after the third character.
21672 If it is not, fail. Otherwise, undo the edits to the current
21673 line of input and proceed as for case CE. */
21674
21675static const struct asm_opcode *
21676opcode_lookup (char **str)
21677{
21678 char *end, *base;
21679 char *affix;
21680 const struct asm_opcode *opcode;
21681 const struct asm_cond *cond;
e3cb604e 21682 char save[2];
c19d1205
ZW
21683
21684 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 21685 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 21686 for (base = end = *str; *end != '\0'; end++)
721a8186 21687 if (*end == ' ' || *end == '.')
c19d1205 21688 break;
b99bd4ef 21689
c19d1205 21690 if (end == base)
c921be7d 21691 return NULL;
b99bd4ef 21692
5287ad62 21693 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 21694 if (end[0] == '.')
b99bd4ef 21695 {
5287ad62 21696 int offset = 2;
5f4273c7 21697
267d2029 21698 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 21699 use. */
267d2029 21700 if (unified_syntax && end[1] == 'w')
c19d1205 21701 inst.size_req = 4;
267d2029 21702 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
21703 inst.size_req = 2;
21704 else
477330fc 21705 offset = 0;
5287ad62
JB
21706
21707 inst.vectype.elems = 0;
21708
21709 *str = end + offset;
b99bd4ef 21710
5f4273c7 21711 if (end[offset] == '.')
5287ad62 21712 {
267d2029 21713 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
21714 non-unified ARM syntax mode). */
21715 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 21716 return NULL;
477330fc 21717 }
5287ad62 21718 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 21719 return NULL;
b99bd4ef 21720 }
c19d1205
ZW
21721 else
21722 *str = end;
b99bd4ef 21723
c19d1205 21724 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 21725 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 21726 end - base);
c19d1205 21727 if (opcode)
b99bd4ef 21728 {
c19d1205
ZW
21729 /* step U */
21730 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 21731 {
c19d1205
ZW
21732 inst.cond = COND_ALWAYS;
21733 return opcode;
b99bd4ef 21734 }
b99bd4ef 21735
278df34e 21736 if (warn_on_deprecated && unified_syntax)
5c3696f8 21737 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 21738 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 21739 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 21740 gas_assert (cond);
b99bd4ef 21741
c19d1205
ZW
21742 inst.cond = cond->value;
21743 return opcode;
21744 }
5ee91343
AV
21745 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21746 {
21747 /* Cannot have a conditional suffix on a mnemonic of less than a character.
21748 */
21749 if (end - base < 2)
21750 return NULL;
21751 affix = end - 1;
21752 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
21753 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21754 affix - base);
21755 /* If this opcode can not be vector predicated then don't accept it with a
21756 vector predication code. */
21757 if (opcode && !opcode->mayBeVecPred)
21758 opcode = NULL;
21759 }
21760 if (!opcode || !cond)
21761 {
21762 /* Cannot have a conditional suffix on a mnemonic of less than two
21763 characters. */
21764 if (end - base < 3)
21765 return NULL;
b99bd4ef 21766
5ee91343
AV
21767 /* Look for suffixed mnemonic. */
21768 affix = end - 2;
21769 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
21770 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21771 affix - base);
21772 }
b99bd4ef 21773
c19d1205
ZW
21774 if (opcode && cond)
21775 {
21776 /* step CE */
21777 switch (opcode->tag)
21778 {
e3cb604e
PB
21779 case OT_cinfix3_legacy:
21780 /* Ignore conditional suffixes matched on infix only mnemonics. */
21781 break;
21782
c19d1205 21783 case OT_cinfix3:
088fa78e 21784 case OT_cinfix3_deprecated:
c19d1205
ZW
21785 case OT_odd_infix_unc:
21786 if (!unified_syntax)
0198d5e6 21787 return NULL;
1a0670f3 21788 /* Fall through. */
c19d1205
ZW
21789
21790 case OT_csuffix:
477330fc 21791 case OT_csuffixF:
c19d1205
ZW
21792 case OT_csuf_or_in3:
21793 inst.cond = cond->value;
21794 return opcode;
21795
21796 case OT_unconditional:
21797 case OT_unconditionalF:
dfa9f0d5 21798 if (thumb_mode)
c921be7d 21799 inst.cond = cond->value;
dfa9f0d5
PB
21800 else
21801 {
c921be7d 21802 /* Delayed diagnostic. */
dfa9f0d5
PB
21803 inst.error = BAD_COND;
21804 inst.cond = COND_ALWAYS;
21805 }
c19d1205 21806 return opcode;
b99bd4ef 21807
c19d1205 21808 default:
c921be7d 21809 return NULL;
c19d1205
ZW
21810 }
21811 }
b99bd4ef 21812
c19d1205
ZW
21813 /* Cannot have a usual-position infix on a mnemonic of less than
21814 six characters (five would be a suffix). */
21815 if (end - base < 6)
c921be7d 21816 return NULL;
b99bd4ef 21817
c19d1205
ZW
21818 /* Look for infixed mnemonic in the usual position. */
21819 affix = base + 3;
21d799b5 21820 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 21821 if (!cond)
c921be7d 21822 return NULL;
e3cb604e
PB
21823
21824 memcpy (save, affix, 2);
21825 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 21826 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 21827 (end - base) - 2);
e3cb604e
PB
21828 memmove (affix + 2, affix, (end - affix) - 2);
21829 memcpy (affix, save, 2);
21830
088fa78e
KH
21831 if (opcode
21832 && (opcode->tag == OT_cinfix3
21833 || opcode->tag == OT_cinfix3_deprecated
21834 || opcode->tag == OT_csuf_or_in3
21835 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 21836 {
c921be7d 21837 /* Step CM. */
278df34e 21838 if (warn_on_deprecated && unified_syntax
088fa78e
KH
21839 && (opcode->tag == OT_cinfix3
21840 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 21841 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
21842
21843 inst.cond = cond->value;
21844 return opcode;
b99bd4ef
NC
21845 }
21846
c921be7d 21847 return NULL;
b99bd4ef
NC
21848}
21849
e07e6e58
NC
21850/* This function generates an initial IT instruction, leaving its block
21851 virtually open for the new instructions. Eventually,
5ee91343 21852 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
21853 a new instruction needs to be included in the IT block.
21854 Finally, the block is closed with close_automatic_it_block ().
21855 The block closure can be requested either from md_assemble (),
21856 a tencode (), or due to a label hook. */
21857
21858static void
21859new_automatic_it_block (int cond)
21860{
5ee91343
AV
21861 now_pred.state = AUTOMATIC_PRED_BLOCK;
21862 now_pred.mask = 0x18;
21863 now_pred.cc = cond;
21864 now_pred.block_length = 1;
cd000bff 21865 mapping_state (MAP_THUMB);
5ee91343
AV
21866 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
21867 now_pred.warn_deprecated = FALSE;
21868 now_pred.insn_cond = TRUE;
e07e6e58
NC
21869}
21870
21871/* Close an automatic IT block.
21872 See comments in new_automatic_it_block (). */
21873
21874static void
21875close_automatic_it_block (void)
21876{
5ee91343
AV
21877 now_pred.mask = 0x10;
21878 now_pred.block_length = 0;
e07e6e58
NC
21879}
21880
21881/* Update the mask of the current automatically-generated IT
21882 instruction. See comments in new_automatic_it_block (). */
21883
21884static void
5ee91343 21885now_pred_add_mask (int cond)
e07e6e58
NC
21886{
21887#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
21888#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 21889 | ((bitvalue) << (nbit)))
e07e6e58 21890 const int resulting_bit = (cond & 1);
c921be7d 21891
5ee91343
AV
21892 now_pred.mask &= 0xf;
21893 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 21894 resulting_bit,
5ee91343
AV
21895 (5 - now_pred.block_length));
21896 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 21897 1,
5ee91343
AV
21898 ((5 - now_pred.block_length) - 1));
21899 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
21900
21901#undef CLEAR_BIT
21902#undef SET_BIT_VALUE
e07e6e58
NC
21903}
21904
21905/* The IT blocks handling machinery is accessed through the these functions:
21906 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
21907 set_pred_insn_type () optional, from the tencode functions
21908 set_pred_insn_type_last () ditto
21909 in_pred_block () ditto
e07e6e58 21910 it_fsm_post_encode () from md_assemble ()
33eaf5de 21911 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
21912
21913 Rationale:
21914 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
21915 initializing the IT insn type with a generic initial value depending
21916 on the inst.condition.
e07e6e58 21917 2) During the tencode function, two things may happen:
477330fc 21918 a) The tencode function overrides the IT insn type by
5ee91343
AV
21919 calling either set_pred_insn_type (type) or
21920 set_pred_insn_type_last ().
477330fc 21921 b) The tencode function queries the IT block state by
5ee91343 21922 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 21923
5ee91343
AV
21924 Both set_pred_insn_type and in_pred_block run the internal FSM state
21925 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
21926 type may incur in an invalid state (exiting the function),
21927 and b) querying the state requires the FSM to be updated.
21928 Specifically we want to avoid creating an IT block for conditional
21929 branches, so it_fsm_pre_encode is actually a guess and we can't
21930 determine whether an IT block is required until the tencode () routine
21931 has decided what type of instruction this actually it.
5ee91343
AV
21932 Because of this, if set_pred_insn_type and in_pred_block have to be
21933 used, set_pred_insn_type has to be called first.
477330fc 21934
5ee91343
AV
21935 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
21936 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
21937 When a tencode () routine encodes an instruction that can be
21938 either outside an IT block, or, in the case of being inside, has to be
5ee91343 21939 the last one, set_pred_insn_type_last () will determine the proper
477330fc 21940 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 21941 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
21942 for covering other cases.
21943
5ee91343
AV
21944 Calling handle_pred_state () may not transition the IT block state to
21945 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 21946 still queried. Instead, if the FSM determines that the state should
5ee91343 21947 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
21948 after the tencode () function: that's what it_fsm_post_encode () does.
21949
5ee91343 21950 Since in_pred_block () calls the state handling function to get an
477330fc
RM
21951 updated state, an error may occur (due to invalid insns combination).
21952 In that case, inst.error is set.
21953 Therefore, inst.error has to be checked after the execution of
21954 the tencode () routine.
e07e6e58
NC
21955
21956 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 21957 any pending state change (if any) that didn't take place in
5ee91343 21958 handle_pred_state () as explained above. */
e07e6e58
NC
21959
21960static void
21961it_fsm_pre_encode (void)
21962{
21963 if (inst.cond != COND_ALWAYS)
5ee91343 21964 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 21965 else
5ee91343 21966 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 21967
5ee91343 21968 now_pred.state_handled = 0;
e07e6e58
NC
21969}
21970
21971/* IT state FSM handling function. */
5ee91343
AV
21972/* MVE instructions and non-MVE instructions are handled differently because of
21973 the introduction of VPT blocks.
21974 Specifications say that any non-MVE instruction inside a VPT block is
21975 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
21976 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 21977 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
21978 The error messages provided depending on the different combinations possible
21979 are described in the cases below:
21980 For 'most' MVE instructions:
21981 1) In an IT block, with an IT code: syntax error
21982 2) In an IT block, with a VPT code: error: must be in a VPT block
21983 3) In an IT block, with no code: warning: UNPREDICTABLE
21984 4) In a VPT block, with an IT code: syntax error
21985 5) In a VPT block, with a VPT code: OK!
21986 6) In a VPT block, with no code: error: missing code
21987 7) Outside a pred block, with an IT code: error: syntax error
21988 8) Outside a pred block, with a VPT code: error: should be in a VPT block
21989 9) Outside a pred block, with no code: OK!
21990 For non-MVE instructions:
21991 10) In an IT block, with an IT code: OK!
21992 11) In an IT block, with a VPT code: syntax error
21993 12) In an IT block, with no code: error: missing code
21994 13) In a VPT block, with an IT code: error: should be in an IT block
21995 14) In a VPT block, with a VPT code: syntax error
21996 15) In a VPT block, with no code: UNPREDICTABLE
21997 16) Outside a pred block, with an IT code: error: should be in an IT block
21998 17) Outside a pred block, with a VPT code: syntax error
21999 18) Outside a pred block, with no code: OK!
22000 */
22001
e07e6e58
NC
22002
22003static int
5ee91343 22004handle_pred_state (void)
e07e6e58 22005{
5ee91343
AV
22006 now_pred.state_handled = 1;
22007 now_pred.insn_cond = FALSE;
e07e6e58 22008
5ee91343 22009 switch (now_pred.state)
e07e6e58 22010 {
5ee91343
AV
22011 case OUTSIDE_PRED_BLOCK:
22012 switch (inst.pred_insn_type)
e07e6e58 22013 {
35c228db 22014 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22015 case MVE_OUTSIDE_PRED_INSN:
22016 if (inst.cond < COND_ALWAYS)
22017 {
22018 /* Case 7: Outside a pred block, with an IT code: error: syntax
22019 error. */
22020 inst.error = BAD_SYNTAX;
22021 return FAIL;
22022 }
22023 /* Case 9: Outside a pred block, with no code: OK! */
22024 break;
22025 case OUTSIDE_PRED_INSN:
22026 if (inst.cond > COND_ALWAYS)
22027 {
22028 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22029 */
22030 inst.error = BAD_SYNTAX;
22031 return FAIL;
22032 }
22033 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22034 break;
22035
5ee91343
AV
22036 case INSIDE_VPT_INSN:
22037 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22038 a VPT block. */
22039 inst.error = BAD_OUT_VPT;
22040 return FAIL;
22041
e07e6e58
NC
22042 case INSIDE_IT_INSN:
22043 case INSIDE_IT_LAST_INSN:
5ee91343 22044 if (inst.cond < COND_ALWAYS)
e07e6e58 22045 {
5ee91343
AV
22046 /* Case 16: Outside a pred block, with an IT code: error: should
22047 be in an IT block. */
22048 if (thumb_mode == 0)
e07e6e58 22049 {
5ee91343
AV
22050 if (unified_syntax
22051 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22052 as_tsktsk (_("Warning: conditional outside an IT block"\
22053 " for Thumb."));
e07e6e58
NC
22054 }
22055 else
22056 {
5ee91343
AV
22057 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22058 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22059 {
22060 /* Automatically generate the IT instruction. */
22061 new_automatic_it_block (inst.cond);
22062 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22063 close_automatic_it_block ();
22064 }
22065 else
22066 {
22067 inst.error = BAD_OUT_IT;
22068 return FAIL;
22069 }
e07e6e58 22070 }
5ee91343 22071 break;
e07e6e58 22072 }
5ee91343
AV
22073 else if (inst.cond > COND_ALWAYS)
22074 {
22075 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22076 */
22077 inst.error = BAD_SYNTAX;
22078 return FAIL;
22079 }
22080 else
22081 gas_assert (0);
e07e6e58
NC
22082 case IF_INSIDE_IT_LAST_INSN:
22083 case NEUTRAL_IT_INSN:
22084 break;
22085
5ee91343
AV
22086 case VPT_INSN:
22087 if (inst.cond != COND_ALWAYS)
22088 first_error (BAD_SYNTAX);
22089 now_pred.state = MANUAL_PRED_BLOCK;
22090 now_pred.block_length = 0;
22091 now_pred.type = VECTOR_PRED;
22092 now_pred.cc = 0;
22093 break;
e07e6e58 22094 case IT_INSN:
5ee91343
AV
22095 now_pred.state = MANUAL_PRED_BLOCK;
22096 now_pred.block_length = 0;
22097 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22098 break;
22099 }
22100 break;
22101
5ee91343 22102 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
22103 /* Three things may happen now:
22104 a) We should increment current it block size;
22105 b) We should close current it block (closing insn or 4 insns);
22106 c) We should close current it block and start a new one (due
22107 to incompatible conditions or
22108 4 insns-length block reached). */
22109
5ee91343 22110 switch (inst.pred_insn_type)
e07e6e58 22111 {
5ee91343
AV
22112 case INSIDE_VPT_INSN:
22113 case VPT_INSN:
35c228db 22114 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22115 case MVE_OUTSIDE_PRED_INSN:
22116 gas_assert (0);
22117 case OUTSIDE_PRED_INSN:
2b0f3761 22118 /* The closure of the block shall happen immediately,
5ee91343 22119 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
22120 force_automatic_it_block_close ();
22121 break;
22122
22123 case INSIDE_IT_INSN:
22124 case INSIDE_IT_LAST_INSN:
22125 case IF_INSIDE_IT_LAST_INSN:
5ee91343 22126 now_pred.block_length++;
e07e6e58 22127
5ee91343
AV
22128 if (now_pred.block_length > 4
22129 || !now_pred_compatible (inst.cond))
e07e6e58
NC
22130 {
22131 force_automatic_it_block_close ();
5ee91343 22132 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
22133 new_automatic_it_block (inst.cond);
22134 }
22135 else
22136 {
5ee91343
AV
22137 now_pred.insn_cond = TRUE;
22138 now_pred_add_mask (inst.cond);
e07e6e58
NC
22139 }
22140
5ee91343
AV
22141 if (now_pred.state == AUTOMATIC_PRED_BLOCK
22142 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
22143 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
22144 close_automatic_it_block ();
22145 break;
22146
22147 case NEUTRAL_IT_INSN:
5ee91343
AV
22148 now_pred.block_length++;
22149 now_pred.insn_cond = TRUE;
e07e6e58 22150
5ee91343 22151 if (now_pred.block_length > 4)
e07e6e58
NC
22152 force_automatic_it_block_close ();
22153 else
5ee91343 22154 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
22155 break;
22156
22157 case IT_INSN:
22158 close_automatic_it_block ();
5ee91343 22159 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
22160 break;
22161 }
22162 break;
22163
5ee91343 22164 case MANUAL_PRED_BLOCK:
e07e6e58 22165 {
5ee91343
AV
22166 int cond, is_last;
22167 if (now_pred.type == SCALAR_PRED)
e07e6e58 22168 {
5ee91343
AV
22169 /* Check conditional suffixes. */
22170 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
22171 now_pred.mask <<= 1;
22172 now_pred.mask &= 0x1f;
22173 is_last = (now_pred.mask == 0x10);
22174 }
22175 else
22176 {
22177 now_pred.cc ^= (now_pred.mask >> 4);
22178 cond = now_pred.cc + 0xf;
22179 now_pred.mask <<= 1;
22180 now_pred.mask &= 0x1f;
22181 is_last = now_pred.mask == 0x10;
22182 }
22183 now_pred.insn_cond = TRUE;
e07e6e58 22184
5ee91343
AV
22185 switch (inst.pred_insn_type)
22186 {
22187 case OUTSIDE_PRED_INSN:
22188 if (now_pred.type == SCALAR_PRED)
22189 {
22190 if (inst.cond == COND_ALWAYS)
22191 {
22192 /* Case 12: In an IT block, with no code: error: missing
22193 code. */
22194 inst.error = BAD_NOT_IT;
22195 return FAIL;
22196 }
22197 else if (inst.cond > COND_ALWAYS)
22198 {
22199 /* Case 11: In an IT block, with a VPT code: syntax error.
22200 */
22201 inst.error = BAD_SYNTAX;
22202 return FAIL;
22203 }
22204 else if (thumb_mode)
22205 {
22206 /* This is for some special cases where a non-MVE
22207 instruction is not allowed in an IT block, such as cbz,
22208 but are put into one with a condition code.
22209 You could argue this should be a syntax error, but we
22210 gave the 'not allowed in IT block' diagnostic in the
22211 past so we will keep doing so. */
22212 inst.error = BAD_NOT_IT;
22213 return FAIL;
22214 }
22215 break;
22216 }
22217 else
22218 {
22219 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
22220 as_tsktsk (MVE_NOT_VPT);
22221 return SUCCESS;
22222 }
22223 case MVE_OUTSIDE_PRED_INSN:
22224 if (now_pred.type == SCALAR_PRED)
22225 {
22226 if (inst.cond == COND_ALWAYS)
22227 {
22228 /* Case 3: In an IT block, with no code: warning:
22229 UNPREDICTABLE. */
22230 as_tsktsk (MVE_NOT_IT);
22231 return SUCCESS;
22232 }
22233 else if (inst.cond < COND_ALWAYS)
22234 {
22235 /* Case 1: In an IT block, with an IT code: syntax error.
22236 */
22237 inst.error = BAD_SYNTAX;
22238 return FAIL;
22239 }
22240 else
22241 gas_assert (0);
22242 }
22243 else
22244 {
22245 if (inst.cond < COND_ALWAYS)
22246 {
22247 /* Case 4: In a VPT block, with an IT code: syntax error.
22248 */
22249 inst.error = BAD_SYNTAX;
22250 return FAIL;
22251 }
22252 else if (inst.cond == COND_ALWAYS)
22253 {
22254 /* Case 6: In a VPT block, with no code: error: missing
22255 code. */
22256 inst.error = BAD_NOT_VPT;
22257 return FAIL;
22258 }
22259 else
22260 {
22261 gas_assert (0);
22262 }
22263 }
35c228db
AV
22264 case MVE_UNPREDICABLE_INSN:
22265 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
22266 return SUCCESS;
e07e6e58 22267 case INSIDE_IT_INSN:
5ee91343 22268 if (inst.cond > COND_ALWAYS)
e07e6e58 22269 {
5ee91343
AV
22270 /* Case 11: In an IT block, with a VPT code: syntax error. */
22271 /* Case 14: In a VPT block, with a VPT code: syntax error. */
22272 inst.error = BAD_SYNTAX;
22273 return FAIL;
22274 }
22275 else if (now_pred.type == SCALAR_PRED)
22276 {
22277 /* Case 10: In an IT block, with an IT code: OK! */
22278 if (cond != inst.cond)
22279 {
22280 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
22281 BAD_VPT_COND;
22282 return FAIL;
22283 }
22284 }
22285 else
22286 {
22287 /* Case 13: In a VPT block, with an IT code: error: should be
22288 in an IT block. */
22289 inst.error = BAD_OUT_IT;
e07e6e58
NC
22290 return FAIL;
22291 }
22292 break;
22293
5ee91343
AV
22294 case INSIDE_VPT_INSN:
22295 if (now_pred.type == SCALAR_PRED)
22296 {
22297 /* Case 2: In an IT block, with a VPT code: error: must be in a
22298 VPT block. */
22299 inst.error = BAD_OUT_VPT;
22300 return FAIL;
22301 }
22302 /* Case 5: In a VPT block, with a VPT code: OK! */
22303 else if (cond != inst.cond)
22304 {
22305 inst.error = BAD_VPT_COND;
22306 return FAIL;
22307 }
22308 break;
e07e6e58
NC
22309 case INSIDE_IT_LAST_INSN:
22310 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
22311 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
22312 {
22313 /* Case 4: In a VPT block, with an IT code: syntax error. */
22314 /* Case 11: In an IT block, with a VPT code: syntax error. */
22315 inst.error = BAD_SYNTAX;
22316 return FAIL;
22317 }
22318 else if (cond != inst.cond)
e07e6e58
NC
22319 {
22320 inst.error = BAD_IT_COND;
22321 return FAIL;
22322 }
22323 if (!is_last)
22324 {
22325 inst.error = BAD_BRANCH;
22326 return FAIL;
22327 }
22328 break;
22329
22330 case NEUTRAL_IT_INSN:
5ee91343
AV
22331 /* The BKPT instruction is unconditional even in a IT or VPT
22332 block. */
e07e6e58
NC
22333 break;
22334
22335 case IT_INSN:
5ee91343
AV
22336 if (now_pred.type == SCALAR_PRED)
22337 {
22338 inst.error = BAD_IT_IT;
22339 return FAIL;
22340 }
22341 /* fall through. */
22342 case VPT_INSN:
22343 if (inst.cond == COND_ALWAYS)
22344 {
22345 /* Executing a VPT/VPST instruction inside an IT block or a
22346 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
22347 */
22348 if (now_pred.type == SCALAR_PRED)
22349 as_tsktsk (MVE_NOT_IT);
22350 else
22351 as_tsktsk (MVE_NOT_VPT);
22352 return SUCCESS;
22353 }
22354 else
22355 {
22356 /* VPT/VPST do not accept condition codes. */
22357 inst.error = BAD_SYNTAX;
22358 return FAIL;
22359 }
e07e6e58 22360 }
5ee91343 22361 }
e07e6e58
NC
22362 break;
22363 }
22364
22365 return SUCCESS;
22366}
22367
5a01bb1d
MGD
22368struct depr_insn_mask
22369{
22370 unsigned long pattern;
22371 unsigned long mask;
22372 const char* description;
22373};
22374
22375/* List of 16-bit instruction patterns deprecated in an IT block in
22376 ARMv8. */
22377static const struct depr_insn_mask depr_it_insns[] = {
22378 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
22379 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
22380 { 0xa000, 0xb800, N_("ADR") },
22381 { 0x4800, 0xf800, N_("Literal loads") },
22382 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
22383 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
22384 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
22385 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
22386 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
22387 { 0, 0, NULL }
22388};
22389
e07e6e58
NC
22390static void
22391it_fsm_post_encode (void)
22392{
22393 int is_last;
22394
5ee91343
AV
22395 if (!now_pred.state_handled)
22396 handle_pred_state ();
e07e6e58 22397
5ee91343
AV
22398 if (now_pred.insn_cond
22399 && !now_pred.warn_deprecated
5a01bb1d 22400 && warn_on_deprecated
df9909b8
TP
22401 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
22402 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
22403 {
22404 if (inst.instruction >= 0x10000)
22405 {
5c3696f8 22406 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 22407 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 22408 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22409 }
22410 else
22411 {
22412 const struct depr_insn_mask *p = depr_it_insns;
22413
22414 while (p->mask != 0)
22415 {
22416 if ((inst.instruction & p->mask) == p->pattern)
22417 {
df9909b8
TP
22418 as_tsktsk (_("IT blocks containing 16-bit Thumb "
22419 "instructions of the following class are "
22420 "performance deprecated in ARMv8-A and "
22421 "ARMv8-R: %s"), p->description);
5ee91343 22422 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22423 break;
22424 }
22425
22426 ++p;
22427 }
22428 }
22429
5ee91343 22430 if (now_pred.block_length > 1)
5a01bb1d 22431 {
5c3696f8 22432 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
22433 "instruction are performance deprecated in ARMv8-A and "
22434 "ARMv8-R"));
5ee91343 22435 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22436 }
22437 }
22438
5ee91343
AV
22439 is_last = (now_pred.mask == 0x10);
22440 if (is_last)
22441 {
22442 now_pred.state = OUTSIDE_PRED_BLOCK;
22443 now_pred.mask = 0;
22444 }
e07e6e58
NC
22445}
22446
22447static void
22448force_automatic_it_block_close (void)
22449{
5ee91343 22450 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
22451 {
22452 close_automatic_it_block ();
5ee91343
AV
22453 now_pred.state = OUTSIDE_PRED_BLOCK;
22454 now_pred.mask = 0;
e07e6e58
NC
22455 }
22456}
22457
22458static int
5ee91343 22459in_pred_block (void)
e07e6e58 22460{
5ee91343
AV
22461 if (!now_pred.state_handled)
22462 handle_pred_state ();
e07e6e58 22463
5ee91343 22464 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
22465}
22466
ff8646ee
TP
22467/* Whether OPCODE only has T32 encoding. Since this function is only used by
22468 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
22469 here, hence the "known" in the function name. */
fc289b0a
TP
22470
22471static bfd_boolean
ff8646ee 22472known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
22473{
22474 /* Original Thumb-1 wide instruction. */
22475 if (opcode->tencode == do_t_blx
22476 || opcode->tencode == do_t_branch23
22477 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
22478 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
22479 return TRUE;
22480
16a1fa25
TP
22481 /* Wide-only instruction added to ARMv8-M Baseline. */
22482 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
22483 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
22484 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
22485 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
22486 return TRUE;
22487
22488 return FALSE;
22489}
22490
22491/* Whether wide instruction variant can be used if available for a valid OPCODE
22492 in ARCH. */
22493
22494static bfd_boolean
22495t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
22496{
22497 if (known_t32_only_insn (opcode))
22498 return TRUE;
22499
22500 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
22501 of variant T3 of B.W is checked in do_t_branch. */
22502 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22503 && opcode->tencode == do_t_branch)
22504 return TRUE;
22505
bada4342
JW
22506 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
22507 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22508 && opcode->tencode == do_t_mov_cmp
22509 /* Make sure CMP instruction is not affected. */
22510 && opcode->aencode == do_mov)
22511 return TRUE;
22512
ff8646ee
TP
22513 /* Wide instruction variants of all instructions with narrow *and* wide
22514 variants become available with ARMv6t2. Other opcodes are either
22515 narrow-only or wide-only and are thus available if OPCODE is valid. */
22516 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
22517 return TRUE;
22518
22519 /* OPCODE with narrow only instruction variant or wide variant not
22520 available. */
fc289b0a
TP
22521 return FALSE;
22522}
22523
c19d1205
ZW
22524void
22525md_assemble (char *str)
b99bd4ef 22526{
c19d1205
ZW
22527 char *p = str;
22528 const struct asm_opcode * opcode;
b99bd4ef 22529
c19d1205
ZW
22530 /* Align the previous label if needed. */
22531 if (last_label_seen != NULL)
b99bd4ef 22532 {
c19d1205
ZW
22533 symbol_set_frag (last_label_seen, frag_now);
22534 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
22535 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
22536 }
22537
c19d1205 22538 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
22539 int r;
22540 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22541 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 22542
c19d1205
ZW
22543 opcode = opcode_lookup (&p);
22544 if (!opcode)
b99bd4ef 22545 {
c19d1205 22546 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 22547 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 22548 if (! create_register_alias (str, p)
477330fc 22549 && ! create_neon_reg_alias (str, p))
c19d1205 22550 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 22551
b99bd4ef
NC
22552 return;
22553 }
22554
278df34e 22555 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 22556 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 22557
037e8744
JB
22558 /* The value which unconditional instructions should have in place of the
22559 condition field. */
22560 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
22561
c19d1205 22562 if (thumb_mode)
b99bd4ef 22563 {
e74cfd16 22564 arm_feature_set variant;
8f06b2d8
PB
22565
22566 variant = cpu_variant;
22567 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
22568 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
22569 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 22570 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
22571 if (!opcode->tvariant
22572 || (thumb_mode == 1
22573 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 22574 {
173205ca
TP
22575 if (opcode->tencode == do_t_swi)
22576 as_bad (_("SVC is not permitted on this architecture"));
22577 else
22578 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
22579 return;
22580 }
c19d1205
ZW
22581 if (inst.cond != COND_ALWAYS && !unified_syntax
22582 && opcode->tencode != do_t_branch)
b99bd4ef 22583 {
c19d1205 22584 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
22585 return;
22586 }
22587
fc289b0a
TP
22588 /* Two things are addressed here:
22589 1) Implicit require narrow instructions on Thumb-1.
22590 This avoids relaxation accidentally introducing Thumb-2
22591 instructions.
22592 2) Reject wide instructions in non Thumb-2 cores.
22593
22594 Only instructions with narrow and wide variants need to be handled
22595 but selecting all non wide-only instructions is easier. */
22596 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 22597 && !t32_insn_ok (variant, opcode))
076d447c 22598 {
fc289b0a
TP
22599 if (inst.size_req == 0)
22600 inst.size_req = 2;
22601 else if (inst.size_req == 4)
752d5da4 22602 {
ff8646ee
TP
22603 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
22604 as_bad (_("selected processor does not support 32bit wide "
22605 "variant of instruction `%s'"), str);
22606 else
22607 as_bad (_("selected processor does not support `%s' in "
22608 "Thumb-2 mode"), str);
fc289b0a 22609 return;
752d5da4 22610 }
076d447c
PB
22611 }
22612
c19d1205
ZW
22613 inst.instruction = opcode->tvalue;
22614
5be8be5d 22615 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 22616 {
5ee91343 22617 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
22618 it. */
22619 it_fsm_pre_encode ();
c19d1205 22620
477330fc 22621 opcode->tencode ();
e07e6e58 22622
477330fc
RM
22623 it_fsm_post_encode ();
22624 }
e27ec89e 22625
0110f2b8 22626 if (!(inst.error || inst.relax))
b99bd4ef 22627 {
9c2799c2 22628 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
22629 inst.size = (inst.instruction > 0xffff ? 4 : 2);
22630 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 22631 {
c19d1205 22632 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
22633 return;
22634 }
22635 }
076d447c
PB
22636
22637 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 22638 instruction. */
9c2799c2 22639 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 22640
e74cfd16
PB
22641 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22642 *opcode->tvariant);
ee065d83 22643 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
22644 set those bits when Thumb-2 32-bit instructions are seen. The impact
22645 of relaxable instructions will be considered later after we finish all
22646 relaxation. */
ff8646ee
TP
22647 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
22648 variant = arm_arch_none;
22649 else
22650 variant = cpu_variant;
22651 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
22652 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22653 arm_ext_v6t2);
cd000bff 22654
88714cb8
DG
22655 check_neon_suffixes;
22656
cd000bff 22657 if (!inst.error)
c877a2f2
NC
22658 {
22659 mapping_state (MAP_THUMB);
22660 }
c19d1205 22661 }
3e9e4fcf 22662 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 22663 {
845b51d6
PB
22664 bfd_boolean is_bx;
22665
22666 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
22667 is_bx = (opcode->aencode == do_bx);
22668
c19d1205 22669 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
22670 if (!(is_bx && fix_v4bx)
22671 && !(opcode->avariant &&
22672 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 22673 {
84b52b66 22674 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 22675 return;
b99bd4ef 22676 }
c19d1205 22677 if (inst.size_req)
b99bd4ef 22678 {
c19d1205
ZW
22679 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
22680 return;
b99bd4ef
NC
22681 }
22682
c19d1205
ZW
22683 inst.instruction = opcode->avalue;
22684 if (opcode->tag == OT_unconditionalF)
eff0bc54 22685 inst.instruction |= 0xFU << 28;
c19d1205
ZW
22686 else
22687 inst.instruction |= inst.cond << 28;
22688 inst.size = INSN_SIZE;
5be8be5d 22689 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
22690 {
22691 it_fsm_pre_encode ();
22692 opcode->aencode ();
22693 it_fsm_post_encode ();
22694 }
ee065d83 22695 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 22696 on a hypothetical non-thumb v5 core. */
845b51d6 22697 if (is_bx)
e74cfd16 22698 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 22699 else
e74cfd16
PB
22700 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
22701 *opcode->avariant);
88714cb8
DG
22702
22703 check_neon_suffixes;
22704
cd000bff 22705 if (!inst.error)
c877a2f2
NC
22706 {
22707 mapping_state (MAP_ARM);
22708 }
b99bd4ef 22709 }
3e9e4fcf
JB
22710 else
22711 {
22712 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
22713 "-- `%s'"), str);
22714 return;
22715 }
c19d1205
ZW
22716 output_inst (str);
22717}
b99bd4ef 22718
e07e6e58 22719static void
5ee91343 22720check_pred_blocks_finished (void)
e07e6e58
NC
22721{
22722#ifdef OBJ_ELF
22723 asection *sect;
22724
22725 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
22726 if (seg_info (sect)->tc_segment_info_data.current_pred.state
22727 == MANUAL_PRED_BLOCK)
e07e6e58 22728 {
5ee91343
AV
22729 if (now_pred.type == SCALAR_PRED)
22730 as_warn (_("section '%s' finished with an open IT block."),
22731 sect->name);
22732 else
22733 as_warn (_("section '%s' finished with an open VPT/VPST block."),
22734 sect->name);
e07e6e58
NC
22735 }
22736#else
5ee91343
AV
22737 if (now_pred.state == MANUAL_PRED_BLOCK)
22738 {
22739 if (now_pred.type == SCALAR_PRED)
22740 as_warn (_("file finished with an open IT block."));
22741 else
22742 as_warn (_("file finished with an open VPT/VPST block."));
22743 }
e07e6e58
NC
22744#endif
22745}
22746
c19d1205
ZW
22747/* Various frobbings of labels and their addresses. */
22748
22749void
22750arm_start_line_hook (void)
22751{
22752 last_label_seen = NULL;
b99bd4ef
NC
22753}
22754
c19d1205
ZW
22755void
22756arm_frob_label (symbolS * sym)
b99bd4ef 22757{
c19d1205 22758 last_label_seen = sym;
b99bd4ef 22759
c19d1205 22760 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 22761
c19d1205
ZW
22762#if defined OBJ_COFF || defined OBJ_ELF
22763 ARM_SET_INTERWORK (sym, support_interwork);
22764#endif
b99bd4ef 22765
e07e6e58
NC
22766 force_automatic_it_block_close ();
22767
5f4273c7 22768 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
22769 as Thumb functions. This is because these labels, whilst
22770 they exist inside Thumb code, are not the entry points for
22771 possible ARM->Thumb calls. Also, these labels can be used
22772 as part of a computed goto or switch statement. eg gcc
22773 can generate code that looks like this:
b99bd4ef 22774
c19d1205
ZW
22775 ldr r2, [pc, .Laaa]
22776 lsl r3, r3, #2
22777 ldr r2, [r3, r2]
22778 mov pc, r2
b99bd4ef 22779
c19d1205
ZW
22780 .Lbbb: .word .Lxxx
22781 .Lccc: .word .Lyyy
22782 ..etc...
22783 .Laaa: .word Lbbb
b99bd4ef 22784
c19d1205
ZW
22785 The first instruction loads the address of the jump table.
22786 The second instruction converts a table index into a byte offset.
22787 The third instruction gets the jump address out of the table.
22788 The fourth instruction performs the jump.
b99bd4ef 22789
c19d1205
ZW
22790 If the address stored at .Laaa is that of a symbol which has the
22791 Thumb_Func bit set, then the linker will arrange for this address
22792 to have the bottom bit set, which in turn would mean that the
22793 address computation performed by the third instruction would end
22794 up with the bottom bit set. Since the ARM is capable of unaligned
22795 word loads, the instruction would then load the incorrect address
22796 out of the jump table, and chaos would ensue. */
22797 if (label_is_thumb_function_name
22798 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
22799 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 22800 {
c19d1205
ZW
22801 /* When the address of a Thumb function is taken the bottom
22802 bit of that address should be set. This will allow
22803 interworking between Arm and Thumb functions to work
22804 correctly. */
b99bd4ef 22805
c19d1205 22806 THUMB_SET_FUNC (sym, 1);
b99bd4ef 22807
c19d1205 22808 label_is_thumb_function_name = FALSE;
b99bd4ef 22809 }
07a53e5c 22810
07a53e5c 22811 dwarf2_emit_label (sym);
b99bd4ef
NC
22812}
22813
c921be7d 22814bfd_boolean
c19d1205 22815arm_data_in_code (void)
b99bd4ef 22816{
c19d1205 22817 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 22818 {
c19d1205
ZW
22819 *input_line_pointer = '/';
22820 input_line_pointer += 5;
22821 *input_line_pointer = 0;
c921be7d 22822 return TRUE;
b99bd4ef
NC
22823 }
22824
c921be7d 22825 return FALSE;
b99bd4ef
NC
22826}
22827
c19d1205
ZW
22828char *
22829arm_canonicalize_symbol_name (char * name)
b99bd4ef 22830{
c19d1205 22831 int len;
b99bd4ef 22832
c19d1205
ZW
22833 if (thumb_mode && (len = strlen (name)) > 5
22834 && streq (name + len - 5, "/data"))
22835 *(name + len - 5) = 0;
b99bd4ef 22836
c19d1205 22837 return name;
b99bd4ef 22838}
c19d1205
ZW
22839\f
22840/* Table of all register names defined by default. The user can
22841 define additional names with .req. Note that all register names
22842 should appear in both upper and lowercase variants. Some registers
22843 also have mixed-case names. */
b99bd4ef 22844
dcbf9037 22845#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 22846#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 22847#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
22848#define REGSET(p,t) \
22849 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
22850 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
22851 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
22852 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
22853#define REGSETH(p,t) \
22854 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
22855 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
22856 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
22857 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
22858#define REGSET2(p,t) \
22859 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
22860 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
22861 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
22862 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
22863#define SPLRBANK(base,bank,t) \
22864 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
22865 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
22866 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
22867 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
22868 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
22869 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 22870
c19d1205 22871static const struct reg_entry reg_names[] =
7ed4c4c5 22872{
c19d1205
ZW
22873 /* ARM integer registers. */
22874 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 22875
c19d1205
ZW
22876 /* ATPCS synonyms. */
22877 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
22878 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
22879 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 22880
c19d1205
ZW
22881 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
22882 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
22883 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 22884
c19d1205
ZW
22885 /* Well-known aliases. */
22886 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
22887 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
22888
22889 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
22890 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
22891
1b883319
AV
22892 /* Defining the new Zero register from ARMv8.1-M. */
22893 REGDEF(zr,15,ZR),
22894 REGDEF(ZR,15,ZR),
22895
c19d1205
ZW
22896 /* Coprocessor numbers. */
22897 REGSET(p, CP), REGSET(P, CP),
22898
22899 /* Coprocessor register numbers. The "cr" variants are for backward
22900 compatibility. */
22901 REGSET(c, CN), REGSET(C, CN),
22902 REGSET(cr, CN), REGSET(CR, CN),
22903
90ec0d68
MGD
22904 /* ARM banked registers. */
22905 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
22906 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
22907 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
22908 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
22909 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
22910 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
22911 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
22912
22913 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
22914 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
22915 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
22916 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
22917 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 22918 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
22919 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
22920 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
22921
22922 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
22923 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
22924 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
22925 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
22926 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
22927 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
22928 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 22929 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
22930 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
22931
c19d1205
ZW
22932 /* FPA registers. */
22933 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
22934 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
22935
22936 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
22937 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
22938
22939 /* VFP SP registers. */
5287ad62
JB
22940 REGSET(s,VFS), REGSET(S,VFS),
22941 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
22942
22943 /* VFP DP Registers. */
5287ad62
JB
22944 REGSET(d,VFD), REGSET(D,VFD),
22945 /* Extra Neon DP registers. */
22946 REGSETH(d,VFD), REGSETH(D,VFD),
22947
22948 /* Neon QP registers. */
22949 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
22950
22951 /* VFP control registers. */
22952 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
22953 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
22954 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
22955 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
22956 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
22957 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 22958 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
22959 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
22960 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
22961 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
22962 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
22963
22964 /* Maverick DSP coprocessor registers. */
22965 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
22966 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
22967
22968 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
22969 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
22970 REGDEF(dspsc,0,DSPSC),
22971
22972 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
22973 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
22974 REGDEF(DSPSC,0,DSPSC),
22975
22976 /* iWMMXt data registers - p0, c0-15. */
22977 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
22978
22979 /* iWMMXt control registers - p1, c0-3. */
22980 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
22981 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
22982 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
22983 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
22984
22985 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
22986 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
22987 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
22988 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
22989 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
22990
22991 /* XScale accumulator registers. */
22992 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
22993};
22994#undef REGDEF
22995#undef REGNUM
22996#undef REGSET
7ed4c4c5 22997
c19d1205
ZW
22998/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
22999 within psr_required_here. */
23000static const struct asm_psr psrs[] =
23001{
23002 /* Backward compatibility notation. Note that "all" is no longer
23003 truly all possible PSR bits. */
23004 {"all", PSR_c | PSR_f},
23005 {"flg", PSR_f},
23006 {"ctl", PSR_c},
23007
23008 /* Individual flags. */
23009 {"f", PSR_f},
23010 {"c", PSR_c},
23011 {"x", PSR_x},
23012 {"s", PSR_s},
59b42a0d 23013
c19d1205
ZW
23014 /* Combinations of flags. */
23015 {"fs", PSR_f | PSR_s},
23016 {"fx", PSR_f | PSR_x},
23017 {"fc", PSR_f | PSR_c},
23018 {"sf", PSR_s | PSR_f},
23019 {"sx", PSR_s | PSR_x},
23020 {"sc", PSR_s | PSR_c},
23021 {"xf", PSR_x | PSR_f},
23022 {"xs", PSR_x | PSR_s},
23023 {"xc", PSR_x | PSR_c},
23024 {"cf", PSR_c | PSR_f},
23025 {"cs", PSR_c | PSR_s},
23026 {"cx", PSR_c | PSR_x},
23027 {"fsx", PSR_f | PSR_s | PSR_x},
23028 {"fsc", PSR_f | PSR_s | PSR_c},
23029 {"fxs", PSR_f | PSR_x | PSR_s},
23030 {"fxc", PSR_f | PSR_x | PSR_c},
23031 {"fcs", PSR_f | PSR_c | PSR_s},
23032 {"fcx", PSR_f | PSR_c | PSR_x},
23033 {"sfx", PSR_s | PSR_f | PSR_x},
23034 {"sfc", PSR_s | PSR_f | PSR_c},
23035 {"sxf", PSR_s | PSR_x | PSR_f},
23036 {"sxc", PSR_s | PSR_x | PSR_c},
23037 {"scf", PSR_s | PSR_c | PSR_f},
23038 {"scx", PSR_s | PSR_c | PSR_x},
23039 {"xfs", PSR_x | PSR_f | PSR_s},
23040 {"xfc", PSR_x | PSR_f | PSR_c},
23041 {"xsf", PSR_x | PSR_s | PSR_f},
23042 {"xsc", PSR_x | PSR_s | PSR_c},
23043 {"xcf", PSR_x | PSR_c | PSR_f},
23044 {"xcs", PSR_x | PSR_c | PSR_s},
23045 {"cfs", PSR_c | PSR_f | PSR_s},
23046 {"cfx", PSR_c | PSR_f | PSR_x},
23047 {"csf", PSR_c | PSR_s | PSR_f},
23048 {"csx", PSR_c | PSR_s | PSR_x},
23049 {"cxf", PSR_c | PSR_x | PSR_f},
23050 {"cxs", PSR_c | PSR_x | PSR_s},
23051 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23052 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23053 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23054 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23055 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23056 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23057 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23058 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23059 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23060 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23061 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23062 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23063 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23064 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23065 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23066 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23067 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23068 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23069 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23070 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23071 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23072 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23073 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23074 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23075};
23076
62b3e311
PB
23077/* Table of V7M psr names. */
23078static const struct asm_psr v7m_psrs[] =
23079{
1a336194
TP
23080 {"apsr", 0x0 }, {"APSR", 0x0 },
23081 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23082 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23083 {"psr", 0x3 }, {"PSR", 0x3 },
23084 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23085 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23086 {"epsr", 0x6 }, {"EPSR", 0x6 },
23087 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23088 {"msp", 0x8 }, {"MSP", 0x8 },
23089 {"psp", 0x9 }, {"PSP", 0x9 },
23090 {"msplim", 0xa }, {"MSPLIM", 0xa },
23091 {"psplim", 0xb }, {"PSPLIM", 0xb },
23092 {"primask", 0x10}, {"PRIMASK", 0x10},
23093 {"basepri", 0x11}, {"BASEPRI", 0x11},
23094 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
23095 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23096 {"control", 0x14}, {"CONTROL", 0x14},
23097 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23098 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23099 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
23100 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
23101 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
23102 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
23103 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
23104 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
23105 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
23106};
23107
c19d1205
ZW
23108/* Table of all shift-in-operand names. */
23109static const struct asm_shift_name shift_names [] =
b99bd4ef 23110{
c19d1205
ZW
23111 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
23112 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
23113 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
23114 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
23115 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
23116 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
23117 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 23118};
b99bd4ef 23119
c19d1205
ZW
23120/* Table of all explicit relocation names. */
23121#ifdef OBJ_ELF
23122static struct reloc_entry reloc_names[] =
23123{
23124 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
23125 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
23126 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
23127 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
23128 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
23129 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
23130 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
23131 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
23132 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
23133 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 23134 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
23135 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
23136 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 23137 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 23138 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 23139 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 23140 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
23141 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
23142 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
23143 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
23144 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23145 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23146 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
23147 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
23148 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
23149 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
23150 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
23151};
23152#endif
b99bd4ef 23153
5ee91343 23154/* Table of all conditional affixes. */
c19d1205
ZW
23155static const struct asm_cond conds[] =
23156{
23157 {"eq", 0x0},
23158 {"ne", 0x1},
23159 {"cs", 0x2}, {"hs", 0x2},
23160 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
23161 {"mi", 0x4},
23162 {"pl", 0x5},
23163 {"vs", 0x6},
23164 {"vc", 0x7},
23165 {"hi", 0x8},
23166 {"ls", 0x9},
23167 {"ge", 0xa},
23168 {"lt", 0xb},
23169 {"gt", 0xc},
23170 {"le", 0xd},
23171 {"al", 0xe}
23172};
5ee91343
AV
23173static const struct asm_cond vconds[] =
23174{
23175 {"t", 0xf},
23176 {"e", 0x10}
23177};
bfae80f2 23178
e797f7e0 23179#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
23180 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
23181 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 23182
62b3e311
PB
23183static struct asm_barrier_opt barrier_opt_names[] =
23184{
e797f7e0
MGD
23185 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
23186 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
23187 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
23188 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
23189 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
23190 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
23191 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
23192 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
23193 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
23194 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
23195 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
23196 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
23197 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
23198 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
23199 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
23200 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
23201};
23202
e797f7e0
MGD
23203#undef UL_BARRIER
23204
c19d1205
ZW
23205/* Table of ARM-format instructions. */
23206
23207/* Macros for gluing together operand strings. N.B. In all cases
23208 other than OPS0, the trailing OP_stop comes from default
23209 zero-initialization of the unspecified elements of the array. */
23210#define OPS0() { OP_stop, }
23211#define OPS1(a) { OP_##a, }
23212#define OPS2(a,b) { OP_##a,OP_##b, }
23213#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
23214#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
23215#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
23216#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
23217
5be8be5d
DG
23218/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
23219 This is useful when mixing operands for ARM and THUMB, i.e. using the
23220 MIX_ARM_THUMB_OPERANDS macro.
23221 In order to use these macros, prefix the number of operands with _
23222 e.g. _3. */
23223#define OPS_1(a) { a, }
23224#define OPS_2(a,b) { a,b, }
23225#define OPS_3(a,b,c) { a,b,c, }
23226#define OPS_4(a,b,c,d) { a,b,c,d, }
23227#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
23228#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
23229
c19d1205
ZW
23230/* These macros abstract out the exact format of the mnemonic table and
23231 save some repeated characters. */
23232
23233/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
23234#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23235 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 23236 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23237
23238/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
23239 a T_MNEM_xyz enumerator. */
23240#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23241 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23242#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23243 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
23244
23245/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
23246 infix after the third character. */
23247#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 23248 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 23249 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 23250#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 23251 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 23252 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23253#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23254 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 23255#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23256 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23257#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23258 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 23259#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23260 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 23261
c19d1205 23262/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
23263 field is still 0xE. Many of the Thumb variants can be executed
23264 conditionally, so this is checked separately. */
c19d1205 23265#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23266 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23267 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23268
dd5181d5
KT
23269/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
23270 Used by mnemonics that have very minimal differences in the encoding for
23271 ARM and Thumb variants and can be handled in a common function. */
23272#define TUEc(mnem, op, top, nops, ops, en) \
23273 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23274 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 23275
c19d1205
ZW
23276/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
23277 condition code field. */
23278#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 23279 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23280 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23281
23282/* ARM-only variants of all the above. */
6a86118a 23283#define CE(mnem, op, nops, ops, ae) \
5ee91343 23284 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23285
23286#define C3(mnem, op, nops, ops, ae) \
5ee91343 23287 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 23288
cf3cf39d
TP
23289/* Thumb-only variants of TCE and TUE. */
23290#define ToC(mnem, top, nops, ops, te) \
23291 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23292 do_##te, 0 }
cf3cf39d
TP
23293
23294#define ToU(mnem, top, nops, ops, te) \
23295 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 23296 NULL, do_##te, 0 }
cf3cf39d 23297
4389b29a
AV
23298/* T_MNEM_xyz enumerator variants of ToC. */
23299#define toC(mnem, top, nops, ops, te) \
23300 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23301 do_##te, 0 }
4389b29a 23302
f6b2b12d
AV
23303/* T_MNEM_xyz enumerator variants of ToU. */
23304#define toU(mnem, top, nops, ops, te) \
23305 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 23306 NULL, do_##te, 0 }
f6b2b12d 23307
e3cb604e
PB
23308/* Legacy mnemonics that always have conditional infix after the third
23309 character. */
23310#define CL(mnem, op, nops, ops, ae) \
21d799b5 23311 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 23312 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 23313
8f06b2d8
PB
23314/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
23315#define cCE(mnem, op, nops, ops, ae) \
5ee91343 23316 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 23317
57785aa2
AV
23318/* mov instructions that are shared between coprocessor and MVE. */
23319#define mcCE(mnem, op, nops, ops, ae) \
23320 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
23321
e3cb604e
PB
23322/* Legacy coprocessor instructions where conditional infix and conditional
23323 suffix are ambiguous. For consistency this includes all FPA instructions,
23324 not just the potentially ambiguous ones. */
23325#define cCL(mnem, op, nops, ops, ae) \
21d799b5 23326 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 23327 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
23328
23329/* Coprocessor, takes either a suffix or a position-3 infix
23330 (for an FPA corner case). */
23331#define C3E(mnem, op, nops, ops, ae) \
21d799b5 23332 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 23333 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 23334
6a86118a 23335#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
23336 { m1 #m2 m3, OPS##nops ops, \
23337 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 23338 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23339
23340#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
23341 xCM_ (m1, , m2, op, nops, ops, ae), \
23342 xCM_ (m1, eq, m2, op, nops, ops, ae), \
23343 xCM_ (m1, ne, m2, op, nops, ops, ae), \
23344 xCM_ (m1, cs, m2, op, nops, ops, ae), \
23345 xCM_ (m1, hs, m2, op, nops, ops, ae), \
23346 xCM_ (m1, cc, m2, op, nops, ops, ae), \
23347 xCM_ (m1, ul, m2, op, nops, ops, ae), \
23348 xCM_ (m1, lo, m2, op, nops, ops, ae), \
23349 xCM_ (m1, mi, m2, op, nops, ops, ae), \
23350 xCM_ (m1, pl, m2, op, nops, ops, ae), \
23351 xCM_ (m1, vs, m2, op, nops, ops, ae), \
23352 xCM_ (m1, vc, m2, op, nops, ops, ae), \
23353 xCM_ (m1, hi, m2, op, nops, ops, ae), \
23354 xCM_ (m1, ls, m2, op, nops, ops, ae), \
23355 xCM_ (m1, ge, m2, op, nops, ops, ae), \
23356 xCM_ (m1, lt, m2, op, nops, ops, ae), \
23357 xCM_ (m1, gt, m2, op, nops, ops, ae), \
23358 xCM_ (m1, le, m2, op, nops, ops, ae), \
23359 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
23360
23361#define UE(mnem, op, nops, ops, ae) \
5ee91343 23362 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23363
23364#define UF(mnem, op, nops, ops, ae) \
5ee91343 23365 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 23366
5287ad62
JB
23367/* Neon data-processing. ARM versions are unconditional with cond=0xf.
23368 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
23369 use the same encoding function for each. */
23370#define NUF(mnem, op, nops, ops, enc) \
23371 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 23372 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
23373
23374/* Neon data processing, version which indirects through neon_enc_tab for
23375 the various overloaded versions of opcodes. */
23376#define nUF(mnem, op, nops, ops, enc) \
21d799b5 23377 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 23378 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
23379
23380/* Neon insn with conditional suffix for the ARM version, non-overloaded
23381 version. */
5ee91343 23382#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 23383 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 23384 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 23385
037e8744 23386#define NCE(mnem, op, nops, ops, enc) \
5ee91343 23387 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
23388
23389#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 23390 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 23391
5287ad62 23392/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 23393#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 23394 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 23395 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 23396
037e8744 23397#define nCE(mnem, op, nops, ops, enc) \
5ee91343 23398 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
23399
23400#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
23401 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
23402
23403/* */
23404#define mCEF(mnem, op, nops, ops, enc) \
a302e574 23405 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
23406 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23407
23408
23409/* nCEF but for MVE predicated instructions. */
23410#define mnCEF(mnem, op, nops, ops, enc) \
23411 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
23412
23413/* nCE but for MVE predicated instructions. */
23414#define mnCE(mnem, op, nops, ops, enc) \
23415 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 23416
5ee91343
AV
23417/* NUF but for potentially MVE predicated instructions. */
23418#define MNUF(mnem, op, nops, ops, enc) \
23419 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
23420 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23421
23422/* nUF but for potentially MVE predicated instructions. */
23423#define mnUF(mnem, op, nops, ops, enc) \
23424 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
23425 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23426
23427/* ToC but for potentially MVE predicated instructions. */
23428#define mToC(mnem, top, nops, ops, te) \
23429 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
23430 do_##te, 1 }
23431
23432/* NCE but for MVE predicated instructions. */
23433#define MNCE(mnem, op, nops, ops, enc) \
23434 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
23435
23436/* NCEF but for MVE predicated instructions. */
23437#define MNCEF(mnem, op, nops, ops, enc) \
23438 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
23439#define do_0 0
23440
c19d1205 23441static const struct asm_opcode insns[] =
bfae80f2 23442{
74db7efb
NC
23443#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
23444#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
23445 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
23446 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
23447 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
23448 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
23449 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
23450 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
23451 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
23452 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
23453 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
23454 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
23455 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
23456 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
23457 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
23458 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
23459 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
23460 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
23461
23462 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
23463 for setting PSR flag bits. They are obsolete in V6 and do not
23464 have Thumb equivalents. */
21d799b5
NC
23465 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23466 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23467 CL("tstp", 110f000, 2, (RR, SH), cmp),
23468 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23469 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23470 CL("cmpp", 150f000, 2, (RR, SH), cmp),
23471 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23472 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23473 CL("cmnp", 170f000, 2, (RR, SH), cmp),
23474
23475 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 23476 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
23477 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
23478 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
23479
23480 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
23481 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
23482 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
23483 OP_RRnpc),
23484 OP_ADDRGLDR),ldst, t_ldst),
23485 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
23486
23487 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23488 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23489 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23490 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23491 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23492 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23493
21d799b5
NC
23494 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
23495 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 23496
c19d1205 23497 /* Pseudo ops. */
21d799b5 23498 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 23499 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 23500 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 23501 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
23502
23503 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
23504 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
23505 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
23506 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
23507 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
23508 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
23509 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
23510 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
23511 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
23512 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
23513 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
23514 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
23515 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 23516
16a4cf17 23517 /* These may simplify to neg. */
21d799b5
NC
23518 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
23519 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 23520
173205ca
TP
23521#undef THUMB_VARIANT
23522#define THUMB_VARIANT & arm_ext_os
23523
23524 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
23525 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
23526
c921be7d
NC
23527#undef THUMB_VARIANT
23528#define THUMB_VARIANT & arm_ext_v6
23529
21d799b5 23530 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
23531
23532 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
23533#undef THUMB_VARIANT
23534#define THUMB_VARIANT & arm_ext_v6t2
23535
21d799b5
NC
23536 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23537 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23538 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 23539
5be8be5d
DG
23540 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23541 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23542 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
23543 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 23544
21d799b5
NC
23545 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23546 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 23547
21d799b5
NC
23548 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23549 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
23550
23551 /* V1 instructions with no Thumb analogue at all. */
21d799b5 23552 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
23553 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
23554
23555 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
23556 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
23557 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
23558 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
23559 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
23560 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
23561 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
23562 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
23563
c921be7d
NC
23564#undef ARM_VARIANT
23565#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
23566#undef THUMB_VARIANT
23567#define THUMB_VARIANT & arm_ext_v4t
23568
21d799b5
NC
23569 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
23570 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 23571
c921be7d
NC
23572#undef THUMB_VARIANT
23573#define THUMB_VARIANT & arm_ext_v6t2
23574
21d799b5 23575 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
23576 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
23577
23578 /* Generic coprocessor instructions. */
21d799b5
NC
23579 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23580 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23581 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23582 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23583 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23584 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 23585 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 23586
c921be7d
NC
23587#undef ARM_VARIANT
23588#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
23589
21d799b5 23590 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
23591 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
23592
c921be7d
NC
23593#undef ARM_VARIANT
23594#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
23595#undef THUMB_VARIANT
23596#define THUMB_VARIANT & arm_ext_msr
23597
d2cd1205
JB
23598 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
23599 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 23600
c921be7d
NC
23601#undef ARM_VARIANT
23602#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
23603#undef THUMB_VARIANT
23604#define THUMB_VARIANT & arm_ext_v6t2
23605
21d799b5
NC
23606 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23607 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23608 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23609 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23610 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23611 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23612 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23613 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 23614
c921be7d
NC
23615#undef ARM_VARIANT
23616#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
23617#undef THUMB_VARIANT
23618#define THUMB_VARIANT & arm_ext_v4t
23619
5be8be5d
DG
23620 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23621 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23622 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23623 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
23624 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23625 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 23626
c921be7d
NC
23627#undef ARM_VARIANT
23628#define ARM_VARIANT & arm_ext_v4t_5
23629
c19d1205
ZW
23630 /* ARM Architecture 4T. */
23631 /* Note: bx (and blx) are required on V5, even if the processor does
23632 not support Thumb. */
21d799b5 23633 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 23634
c921be7d
NC
23635#undef ARM_VARIANT
23636#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
23637#undef THUMB_VARIANT
23638#define THUMB_VARIANT & arm_ext_v5t
23639
c19d1205
ZW
23640 /* Note: blx has 2 variants; the .value coded here is for
23641 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
23642 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
23643 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 23644
c921be7d
NC
23645#undef THUMB_VARIANT
23646#define THUMB_VARIANT & arm_ext_v6t2
23647
21d799b5
NC
23648 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
23649 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23650 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23651 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23652 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23653 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23654 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
23655 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 23656
c921be7d 23657#undef ARM_VARIANT
74db7efb
NC
23658#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
23659#undef THUMB_VARIANT
23660#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 23661
21d799b5
NC
23662 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23663 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23664 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23665 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 23666
21d799b5
NC
23667 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23668 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 23669
21d799b5
NC
23670 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23671 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23672 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23673 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 23674
21d799b5
NC
23675 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23676 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23677 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23678 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 23679
21d799b5
NC
23680 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23681 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 23682
03ee1b7f
NC
23683 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23684 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23685 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23686 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 23687
c921be7d 23688#undef ARM_VARIANT
74db7efb
NC
23689#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
23690#undef THUMB_VARIANT
23691#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23692
21d799b5 23693 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
23694 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
23695 ldrd, t_ldstd),
23696 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
23697 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 23698
21d799b5
NC
23699 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23700 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 23701
c921be7d
NC
23702#undef ARM_VARIANT
23703#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
23704
21d799b5 23705 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 23706
c921be7d
NC
23707#undef ARM_VARIANT
23708#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
23709#undef THUMB_VARIANT
23710#define THUMB_VARIANT & arm_ext_v6
23711
21d799b5
NC
23712 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
23713 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
23714 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23715 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23716 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23717 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23718 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23719 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23720 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23721 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 23722
c921be7d 23723#undef THUMB_VARIANT
ff8646ee 23724#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 23725
5be8be5d
DG
23726 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
23727 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
23728 strex, t_strex),
ff8646ee
TP
23729#undef THUMB_VARIANT
23730#define THUMB_VARIANT & arm_ext_v6t2
23731
21d799b5
NC
23732 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23733 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 23734
21d799b5
NC
23735 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
23736 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 23737
9e3c6df6 23738/* ARM V6 not included in V7M. */
c921be7d
NC
23739#undef THUMB_VARIANT
23740#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 23741 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 23742 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
23743 UF(rfeib, 9900a00, 1, (RRw), rfe),
23744 UF(rfeda, 8100a00, 1, (RRw), rfe),
23745 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23746 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
23747 UF(rfefa, 8100a00, 1, (RRw), rfe),
23748 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23749 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 23750 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
23751 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
23752 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 23753 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 23754 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 23755 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 23756 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 23757 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 23758 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 23759 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 23760
9e3c6df6
PB
23761/* ARM V6 not included in V7M (eg. integer SIMD). */
23762#undef THUMB_VARIANT
23763#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
23764 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
23765 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
23766 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23767 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23768 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23769 /* Old name for QASX. */
74db7efb 23770 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 23771 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23772 /* Old name for QSAX. */
74db7efb 23773 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23774 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23775 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23776 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23777 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23778 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23779 /* Old name for SASX. */
74db7efb 23780 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23781 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23782 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23783 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23784 /* Old name for SHASX. */
21d799b5 23785 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23786 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23787 /* Old name for SHSAX. */
21d799b5
NC
23788 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23789 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23790 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23791 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23792 /* Old name for SSAX. */
74db7efb 23793 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23794 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23795 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23796 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23797 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23798 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23799 /* Old name for UASX. */
74db7efb 23800 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23801 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23802 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23803 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23804 /* Old name for UHASX. */
21d799b5
NC
23805 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23806 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23807 /* Old name for UHSAX. */
21d799b5
NC
23808 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23809 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23810 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23811 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23812 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23813 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23814 /* Old name for UQASX. */
21d799b5
NC
23815 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23816 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23817 /* Old name for UQSAX. */
21d799b5
NC
23818 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23819 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23820 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23821 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23822 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23823 /* Old name for USAX. */
74db7efb 23824 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 23825 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23826 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23827 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23828 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23829 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23830 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23831 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23832 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23833 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23834 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23835 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23836 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23837 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23838 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23839 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23840 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23841 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23842 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23843 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23844 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23845 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23846 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23847 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23848 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23849 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23850 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23851 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23852 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
23853 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
23854 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
23855 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23856 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23857 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 23858
c921be7d 23859#undef ARM_VARIANT
55e8aae7 23860#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 23861#undef THUMB_VARIANT
55e8aae7 23862#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 23863
21d799b5
NC
23864 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
23865 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
23866 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
23867 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 23868
c921be7d
NC
23869#undef THUMB_VARIANT
23870#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
23871 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
23872 ldrexd, t_ldrexd),
23873 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
23874 RRnpcb), strexd, t_strexd),
ebdca51a 23875
c921be7d 23876#undef THUMB_VARIANT
ff8646ee 23877#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
23878 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
23879 rd_rn, rd_rn),
23880 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
23881 rd_rn, rd_rn),
23882 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 23883 strex, t_strexbh),
5be8be5d 23884 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 23885 strex, t_strexbh),
21d799b5 23886 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 23887
c921be7d 23888#undef ARM_VARIANT
f4c65163 23889#define ARM_VARIANT & arm_ext_sec
74db7efb 23890#undef THUMB_VARIANT
f4c65163 23891#define THUMB_VARIANT & arm_ext_sec
c921be7d 23892
21d799b5 23893 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 23894
90ec0d68
MGD
23895#undef ARM_VARIANT
23896#define ARM_VARIANT & arm_ext_virt
23897#undef THUMB_VARIANT
23898#define THUMB_VARIANT & arm_ext_virt
23899
23900 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
23901 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
23902
ddfded2f
MW
23903#undef ARM_VARIANT
23904#define ARM_VARIANT & arm_ext_pan
23905#undef THUMB_VARIANT
23906#define THUMB_VARIANT & arm_ext_pan
23907
23908 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
23909
c921be7d 23910#undef ARM_VARIANT
74db7efb 23911#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
23912#undef THUMB_VARIANT
23913#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23914
21d799b5
NC
23915 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
23916 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
23917 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
23918 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 23919
21d799b5 23920 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 23921 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 23922
5be8be5d
DG
23923 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23924 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23925 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23926 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 23927
91d8b670
JG
23928#undef ARM_VARIANT
23929#define ARM_VARIANT & arm_ext_v3
23930#undef THUMB_VARIANT
23931#define THUMB_VARIANT & arm_ext_v6t2
23932
23933 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
23934 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
23935 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
23936
23937#undef ARM_VARIANT
23938#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
23939#undef THUMB_VARIANT
23940#define THUMB_VARIANT & arm_ext_v6t2_v8m
23941 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
23942 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
23943
bf3eeda7 23944 /* Thumb-only instructions. */
74db7efb 23945#undef ARM_VARIANT
bf3eeda7
NS
23946#define ARM_VARIANT NULL
23947 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
23948 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
23949
23950 /* ARM does not really have an IT instruction, so always allow it.
23951 The opcode is copied from Thumb in order to allow warnings in
23952 -mimplicit-it=[never | arm] modes. */
23953#undef ARM_VARIANT
23954#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
23955#undef THUMB_VARIANT
23956#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23957
21d799b5
NC
23958 TUE("it", bf08, bf08, 1, (COND), it, t_it),
23959 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
23960 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
23961 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
23962 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
23963 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
23964 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
23965 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
23966 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
23967 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
23968 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
23969 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
23970 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
23971 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
23972 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 23973 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
23974 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
23975 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 23976
92e90b6e 23977 /* Thumb2 only instructions. */
c921be7d
NC
23978#undef ARM_VARIANT
23979#define ARM_VARIANT NULL
92e90b6e 23980
21d799b5
NC
23981 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
23982 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
23983 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
23984 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
23985 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
23986 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 23987
eea54501
MGD
23988 /* Hardware division instructions. */
23989#undef ARM_VARIANT
23990#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
23991#undef THUMB_VARIANT
23992#define THUMB_VARIANT & arm_ext_div
23993
eea54501
MGD
23994 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
23995 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 23996
7e806470 23997 /* ARM V6M/V7 instructions. */
c921be7d
NC
23998#undef ARM_VARIANT
23999#define ARM_VARIANT & arm_ext_barrier
24000#undef THUMB_VARIANT
24001#define THUMB_VARIANT & arm_ext_barrier
24002
ccb84d65
JB
24003 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24004 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24005 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24006
62b3e311 24007 /* ARM V7 instructions. */
c921be7d
NC
24008#undef ARM_VARIANT
24009#define ARM_VARIANT & arm_ext_v7
24010#undef THUMB_VARIANT
24011#define THUMB_VARIANT & arm_ext_v7
24012
21d799b5
NC
24013 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24014 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24015
74db7efb 24016#undef ARM_VARIANT
60e5ef9f 24017#define ARM_VARIANT & arm_ext_mp
74db7efb 24018#undef THUMB_VARIANT
60e5ef9f
MGD
24019#define THUMB_VARIANT & arm_ext_mp
24020
24021 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24022
53c4b28b
MGD
24023 /* AArchv8 instructions. */
24024#undef ARM_VARIANT
24025#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24026
24027/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24028#undef THUMB_VARIANT
4ed7ed8d 24029#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24030
4ed7ed8d
TP
24031 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24032 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24033 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24034 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24035 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24036 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24037 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24038 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24039 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24040 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24041 stlex, t_stlex),
4b8c8c02
RE
24042 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24043 stlex, t_stlex),
24044 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24045 stlex, t_stlex),
4ed7ed8d
TP
24046#undef THUMB_VARIANT
24047#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24048
4ed7ed8d 24049 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24050 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24051 ldrexd, t_ldrexd),
24052 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24053 strexd, t_strexd),
f7dd2fb2
TC
24054
24055/* Defined in V8 but is in undefined encoding space for earlier
24056 architectures. However earlier architectures are required to treat
24057 this instuction as a semihosting trap as well. Hence while not explicitly
24058 defined as such, it is in fact correct to define the instruction for all
24059 architectures. */
24060#undef THUMB_VARIANT
24061#define THUMB_VARIANT & arm_ext_v1
24062#undef ARM_VARIANT
24063#define ARM_VARIANT & arm_ext_v1
24064 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24065
8884b720 24066 /* ARMv8 T32 only. */
74db7efb 24067#undef ARM_VARIANT
b79f7053
MGD
24068#define ARM_VARIANT NULL
24069 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24070 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24071 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24072
33399f07
MGD
24073 /* FP for ARMv8. */
24074#undef ARM_VARIANT
a715796b 24075#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24076#undef THUMB_VARIANT
a715796b 24077#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24078
24079 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24080 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24081 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24082 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24083 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24084 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24085 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24086 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24087 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24088 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24089 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 24090
91ff7894
MGD
24091 /* Crypto v1 extensions. */
24092#undef ARM_VARIANT
24093#define ARM_VARIANT & fpu_crypto_ext_armv8
24094#undef THUMB_VARIANT
24095#define THUMB_VARIANT & fpu_crypto_ext_armv8
24096
24097 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24098 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24099 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
24100 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
24101 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
24102 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
24103 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
24104 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
24105 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
24106 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
24107 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
24108 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
24109 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
24110 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 24111
dd5181d5 24112#undef ARM_VARIANT
74db7efb 24113#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
24114#undef THUMB_VARIANT
24115#define THUMB_VARIANT & crc_ext_armv8
24116 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
24117 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
24118 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
24119 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
24120 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
24121 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
24122
105bde57
MW
24123 /* ARMv8.2 RAS extension. */
24124#undef ARM_VARIANT
4d1464f2 24125#define ARM_VARIANT & arm_ext_ras
105bde57 24126#undef THUMB_VARIANT
4d1464f2 24127#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
24128 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
24129
49e8a725
SN
24130#undef ARM_VARIANT
24131#define ARM_VARIANT & arm_ext_v8_3
24132#undef THUMB_VARIANT
24133#define THUMB_VARIANT & arm_ext_v8_3
24134 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
24135
c604a79a
JW
24136#undef ARM_VARIANT
24137#define ARM_VARIANT & fpu_neon_ext_dotprod
24138#undef THUMB_VARIANT
24139#define THUMB_VARIANT & fpu_neon_ext_dotprod
24140 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
24141 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
24142
c921be7d
NC
24143#undef ARM_VARIANT
24144#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
24145#undef THUMB_VARIANT
24146#define THUMB_VARIANT NULL
c921be7d 24147
21d799b5
NC
24148 cCE("wfs", e200110, 1, (RR), rd),
24149 cCE("rfs", e300110, 1, (RR), rd),
24150 cCE("wfc", e400110, 1, (RR), rd),
24151 cCE("rfc", e500110, 1, (RR), rd),
24152
24153 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
24154 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
24155 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
24156 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
24157
24158 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
24159 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
24160 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
24161 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
24162
24163 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
24164 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
24165 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
24166 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
24167 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
24168 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
24169 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
24170 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
24171 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
24172 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
24173 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
24174 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
24175
24176 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
24177 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
24178 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
24179 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
24180 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
24181 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
24182 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
24183 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
24184 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
24185 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
24186 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
24187 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
24188
24189 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
24190 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
24191 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
24192 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
24193 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
24194 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
24195 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
24196 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
24197 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
24198 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
24199 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
24200 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
24201
24202 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
24203 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
24204 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
24205 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
24206 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
24207 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
24208 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
24209 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
24210 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
24211 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
24212 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
24213 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
24214
24215 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
24216 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
24217 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
24218 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
24219 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
24220 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
24221 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
24222 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
24223 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
24224 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
24225 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
24226 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
24227
24228 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
24229 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
24230 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
24231 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
24232 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
24233 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
24234 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
24235 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
24236 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
24237 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
24238 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
24239 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
24240
24241 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
24242 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
24243 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
24244 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
24245 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
24246 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
24247 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
24248 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
24249 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
24250 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
24251 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
24252 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
24253
24254 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
24255 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
24256 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
24257 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
24258 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
24259 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
24260 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
24261 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
24262 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
24263 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
24264 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
24265 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
24266
24267 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
24268 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
24269 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
24270 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
24271 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
24272 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
24273 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
24274 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
24275 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
24276 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
24277 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
24278 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
24279
24280 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
24281 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
24282 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
24283 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
24284 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
24285 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
24286 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
24287 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
24288 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
24289 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
24290 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
24291 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
24292
24293 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
24294 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
24295 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
24296 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
24297 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
24298 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
24299 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
24300 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
24301 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
24302 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
24303 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
24304 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
24305
24306 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
24307 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
24308 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
24309 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
24310 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
24311 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
24312 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
24313 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
24314 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
24315 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
24316 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
24317 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
24318
24319 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
24320 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
24321 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
24322 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
24323 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
24324 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
24325 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
24326 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
24327 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
24328 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
24329 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
24330 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
24331
24332 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
24333 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
24334 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
24335 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
24336 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
24337 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
24338 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
24339 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
24340 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
24341 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
24342 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
24343 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
24344
24345 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
24346 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
24347 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
24348 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
24349 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
24350 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
24351 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
24352 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
24353 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
24354 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
24355 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
24356 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
24357
24358 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
24359 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
24360 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
24361 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
24362 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
24363 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
24364 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
24365 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
24366 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
24367 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
24368 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
24369 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
24370
24371 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
24372 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
24373 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
24374 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
24375 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
24376 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24377 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24378 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24379 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
24380 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
24381 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
24382 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
24383
24384 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
24385 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
24386 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
24387 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
24388 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
24389 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24390 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24391 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24392 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
24393 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
24394 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
24395 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
24396
24397 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
24398 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
24399 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
24400 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
24401 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
24402 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24403 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24404 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24405 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
24406 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
24407 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
24408 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
24409
24410 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
24411 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
24412 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
24413 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
24414 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
24415 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24416 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24417 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24418 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
24419 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
24420 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
24421 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
24422
24423 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
24424 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
24425 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
24426 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
24427 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
24428 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24429 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24430 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24431 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
24432 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
24433 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
24434 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
24435
24436 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
24437 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
24438 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
24439 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
24440 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
24441 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24442 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24443 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24444 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
24445 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
24446 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
24447 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
24448
24449 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
24450 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
24451 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
24452 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
24453 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
24454 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24455 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24456 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24457 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
24458 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
24459 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
24460 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
24461
24462 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
24463 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
24464 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
24465 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
24466 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
24467 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24468 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24469 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24470 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
24471 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
24472 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
24473 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
24474
24475 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
24476 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
24477 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
24478 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
24479 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
24480 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24481 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24482 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24483 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
24484 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
24485 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
24486 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
24487
24488 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
24489 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
24490 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
24491 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
24492 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
24493 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24494 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24495 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24496 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
24497 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
24498 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
24499 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
24500
24501 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24502 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24503 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24504 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24505 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24506 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24507 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24508 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24509 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24510 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24511 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24512 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24513
24514 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24515 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24516 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24517 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24518 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24519 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24520 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24521 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24522 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24523 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24524 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24525 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24526
24527 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24528 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24529 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24530 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24531 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24532 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24533 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24534 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24535 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24536 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24537 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24538 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24539
24540 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
24541 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
24542 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
24543 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
24544
24545 cCL("flts", e000110, 2, (RF, RR), rn_rd),
24546 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
24547 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
24548 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
24549 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
24550 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
24551 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
24552 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
24553 cCL("flte", e080110, 2, (RF, RR), rn_rd),
24554 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
24555 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
24556 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 24557
c19d1205
ZW
24558 /* The implementation of the FIX instruction is broken on some
24559 assemblers, in that it accepts a precision specifier as well as a
24560 rounding specifier, despite the fact that this is meaningless.
24561 To be more compatible, we accept it as well, though of course it
24562 does not set any bits. */
21d799b5
NC
24563 cCE("fix", e100110, 2, (RR, RF), rd_rm),
24564 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
24565 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
24566 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
24567 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
24568 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
24569 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
24570 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
24571 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
24572 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
24573 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
24574 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
24575 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 24576
c19d1205 24577 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
24578#undef ARM_VARIANT
24579#define ARM_VARIANT & fpu_fpa_ext_v2
24580
21d799b5
NC
24581 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24582 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24583 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24584 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24585 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24586 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 24587
c921be7d
NC
24588#undef ARM_VARIANT
24589#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
24590#undef THUMB_VARIANT
24591#define THUMB_VARIANT & arm_ext_v6t2
24592 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
24593 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
24594#undef THUMB_VARIANT
c921be7d 24595
c19d1205 24596 /* Moves and type conversions. */
21d799b5
NC
24597 cCE("fmstat", ef1fa10, 0, (), noargs),
24598 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
24599 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
24600 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
24601 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24602 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
24603 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24604 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
24605 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
24606
24607 /* Memory operations. */
21d799b5
NC
24608 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24609 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
24610 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24611 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24612 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24613 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24614 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24615 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24616 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24617 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24618 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24619 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24620 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24621 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24622 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24623 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24624 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24625 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 24626
c19d1205 24627 /* Monadic operations. */
21d799b5
NC
24628 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
24629 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
24630 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
24631
24632 /* Dyadic operations. */
21d799b5
NC
24633 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24634 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24635 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24636 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24637 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24638 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24639 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24640 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24641 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 24642
c19d1205 24643 /* Comparisons. */
21d799b5
NC
24644 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
24645 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
24646 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
24647 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 24648
62f3b8c8
PB
24649 /* Double precision load/store are still present on single precision
24650 implementations. */
24651 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24652 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
24653 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24654 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24655 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24656 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24657 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24658 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24659 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24660 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 24661
c921be7d
NC
24662#undef ARM_VARIANT
24663#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
24664
c19d1205 24665 /* Moves and type conversions. */
21d799b5
NC
24666 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24667 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24668 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
24669 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
24670 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
24671 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
24672 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24673 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
24674 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24675 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24676 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24677 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 24678
c19d1205 24679 /* Monadic operations. */
21d799b5
NC
24680 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24681 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24682 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
24683
24684 /* Dyadic operations. */
21d799b5
NC
24685 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24686 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24687 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24688 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24689 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24690 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24691 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24692 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24693 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 24694
c19d1205 24695 /* Comparisons. */
21d799b5
NC
24696 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24697 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
24698 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24699 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 24700
037e8744
JB
24701/* Instructions which may belong to either the Neon or VFP instruction sets.
24702 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
24703#undef ARM_VARIANT
24704#define ARM_VARIANT & fpu_vfp_ext_v1xd
24705#undef THUMB_VARIANT
24706#define THUMB_VARIANT & fpu_vfp_ext_v1xd
24707
037e8744
JB
24708 /* These mnemonics are unique to VFP. */
24709 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
24710 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
24711 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24712 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24713 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
24714 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
24715 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
24716 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
24717
24718 /* Mnemonics shared by Neon and VFP. */
21d799b5 24719 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 24720
55881a11
MGD
24721 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24722 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24723 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24724 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24725 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24726 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
037e8744 24727
dd9634d9 24728 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 24729 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
24730 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
24731 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 24732
037e8744
JB
24733
24734 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
24735 NCE(vmovq, 0, 1, (VMOV), neon_mov),
24736
32c36c3c
AV
24737#undef THUMB_VARIANT
24738/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
24739 by different feature bits. Since we are setting the Thumb guard, we can
24740 require Thumb-1 which makes it a nop guard and set the right feature bit in
24741 do_vldr_vstr (). */
24742#define THUMB_VARIANT & arm_ext_v4t
24743 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24744 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24745
9db2f6b4
RL
24746#undef ARM_VARIANT
24747#define ARM_VARIANT & arm_ext_fp16
24748#undef THUMB_VARIANT
24749#define THUMB_VARIANT & arm_ext_fp16
24750 /* New instructions added from v8.2, allowing the extraction and insertion of
24751 the upper 16 bits of a 32-bit vector register. */
24752 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
24753 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
24754
dec41383
JW
24755 /* New backported fma/fms instructions optional in v8.2. */
24756 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
24757 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
24758
c921be7d
NC
24759#undef THUMB_VARIANT
24760#define THUMB_VARIANT & fpu_neon_ext_v1
24761#undef ARM_VARIANT
24762#define ARM_VARIANT & fpu_neon_ext_v1
24763
5287ad62
JB
24764 /* Data processing with three registers of the same length. */
24765 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
24766 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
24767 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 24768 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 24769 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
24770 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
24771 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 24772 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 24773 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 24774 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 24775 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 24776 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
24777 shl should accept I8 I16 I32 I64,
24778 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
24779 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
24780 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 24781 /* Logic ops, types optional & ignored. */
4316f0d2 24782 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24783 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24784 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24785 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24786 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
24787 /* Bitfield ops, untyped. */
24788 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24789 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24790 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24791 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24792 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24793 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 24794 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 24795 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 24796 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 24797 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
24798 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
24799 back to neon_dyadic_if_su. */
21d799b5
NC
24800 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24801 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24802 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24803 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24804 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24805 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
24806 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24807 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 24808 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
24809 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
24810 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 24811 /* As above, D registers only. */
21d799b5
NC
24812 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
24813 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 24814 /* Int and float variants, signedness unimportant. */
21d799b5
NC
24815 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24816 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24817 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 24818 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
24819 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
24820 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
24821 /* vtst takes sizes 8, 16, 32. */
24822 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
24823 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
24824 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 24825 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 24826 /* VQD{R}MULH takes S16 S32. */
21d799b5 24827 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 24828 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
24829 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24830 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
24831 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24832 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
24833 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24834 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
24835 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24836 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
24837 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24838 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
24839 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24840 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 24841 /* ARM v8.1 extension. */
643afb90
MW
24842 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
24843 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
24844 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
24845
24846 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 24847 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
24848 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
24849
24850 /* Data processing with two registers and a shift amount. */
24851 /* Right shifts, and variants with rounding.
24852 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 24853 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
24854 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
24855 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24856 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24857 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24858 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24859 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 24860 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
24861 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
24862 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
24863 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
24864 /* Right shift immediate, saturating & narrowing, with rounding variants.
24865 Types accepted S16 S32 S64 U16 U32 U64. */
24866 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24867 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24868 /* As above, unsigned. Types accepted S16 S32 S64. */
24869 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24870 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24871 /* Right shift narrowing. Types accepted I16 I32 I64. */
24872 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24873 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24874 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 24875 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 24876 /* CVT with optional immediate for fixed-point variant. */
21d799b5 24877 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 24878
4316f0d2 24879 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
24880
24881 /* Data processing, three registers of different lengths. */
24882 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
24883 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
24884 /* If not scalar, fall back to neon_dyadic_long.
24885 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
24886 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
24887 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
24888 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
24889 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24890 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24891 /* Dyadic, narrowing insns. Types I16 I32 I64. */
24892 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24893 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24894 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24895 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24896 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
24897 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24898 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24899 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
24900 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
24901 S16 S32 U16 U32. */
21d799b5 24902 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
24903
24904 /* Extract. Size 8. */
3b8d421e
PB
24905 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
24906 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
24907
24908 /* Two registers, miscellaneous. */
24909 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 24910 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 24911 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
24912 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
24913 /* Vector replicate. Sizes 8 16 32. */
21d799b5 24914 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
24915 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
24916 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
24917 /* VMOVN. Types I16 I32 I64. */
21d799b5 24918 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 24919 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 24920 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 24921 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 24922 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
24923 /* VZIP / VUZP. Sizes 8 16 32. */
24924 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
24925 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
24926 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
24927 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
24928 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 24929 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
24930 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
24931 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
24932 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
24933 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
24934 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
24935 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 24936 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
24937 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
24938 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
24939 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
24940 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
24941 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
24942 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
24943 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
24944 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
24945 /* VCNT. Size 8. */
24946 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
24947 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
24948 /* Two address, untyped. */
24949 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
24950 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
24951 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
24952 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
24953 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
24954
24955 /* Table lookup. Size 8. */
24956 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
24957 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
24958
c921be7d
NC
24959#undef THUMB_VARIANT
24960#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
24961#undef ARM_VARIANT
24962#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
24963
5287ad62 24964 /* Neon element/structure load/store. */
21d799b5
NC
24965 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
24966 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
24967 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
24968 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
24969 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
24970 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
24971 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
24972 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 24973
c921be7d 24974#undef THUMB_VARIANT
74db7efb
NC
24975#define THUMB_VARIANT & fpu_vfp_ext_v3xd
24976#undef ARM_VARIANT
24977#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
24978 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
24979 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24980 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24981 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24982 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24983 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24984 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24985 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24986 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24987
74db7efb 24988#undef THUMB_VARIANT
c921be7d
NC
24989#define THUMB_VARIANT & fpu_vfp_ext_v3
24990#undef ARM_VARIANT
24991#define ARM_VARIANT & fpu_vfp_ext_v3
24992
21d799b5 24993 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 24994 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24995 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 24996 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24997 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 24998 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24999 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25000 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25001 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25002
74db7efb
NC
25003#undef ARM_VARIANT
25004#define ARM_VARIANT & fpu_vfp_ext_fma
25005#undef THUMB_VARIANT
25006#define THUMB_VARIANT & fpu_vfp_ext_fma
d58196e0 25007 /* Mnemonics shared by Neon, VFP and MVE. These are included in the
62f3b8c8
PB
25008 VFP FMA variant; NEON and VFP FMA always includes the NEON
25009 FMA instructions. */
d58196e0
AV
25010 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25011 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25012
62f3b8c8
PB
25013 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25014 the v form should always be used. */
25015 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25016 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25017 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25018 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25019 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25020 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25021
5287ad62 25022#undef THUMB_VARIANT
c921be7d
NC
25023#undef ARM_VARIANT
25024#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25025
21d799b5
NC
25026 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25027 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25028 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25029 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25030 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25031 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25032 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25033 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25034
c921be7d
NC
25035#undef ARM_VARIANT
25036#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25037
21d799b5
NC
25038 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25039 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25040 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25041 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25042 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25043 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25044 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25045 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25046 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25047 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25048 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25049 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25050 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25051 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25052 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25053 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25054 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25055 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25056 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25057 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25058 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25059 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25060 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25061 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25062 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25063 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25064 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25065 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25066 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25067 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25068 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25069 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25070 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25071 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25072 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25073 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25074 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25075 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25076 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25077 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25078 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25079 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25080 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25081 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25082 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25083 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25084 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
25085 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25086 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25087 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25088 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25089 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25090 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25091 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25092 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25093 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25094 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25095 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25096 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25097 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25098 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25099 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25100 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25101 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25102 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25103 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25104 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25105 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25106 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25107 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25108 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25109 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25110 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25111 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25112 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25113 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25114 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25115 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25116 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25117 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25118 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25119 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25120 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25121 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25122 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25123 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25124 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25125 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25126 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
25127 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25128 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25129 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25130 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25131 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25132 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25133 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25134 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25135 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25136 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25137 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25138 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25139 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25140 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25141 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25142 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25143 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25144 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25145 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25146 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25147 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25148 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
25149 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25150 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25151 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25152 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25153 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25154 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25155 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25156 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25157 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25158 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25159 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25160 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25161 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25162 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25163 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25164 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25165 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25166 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25167 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25168 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25169 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25170 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25171 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25172 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25173 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25174 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25175 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25176 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25177 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25178 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25179 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25180 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
25181 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
25182 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
25183 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
25184 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
25185 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
25186 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25187 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25188 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25189 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
25190 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
25191 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
25192 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
25193 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
25194 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
25195 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25196 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25197 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25198 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25199 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 25200
c921be7d
NC
25201#undef ARM_VARIANT
25202#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
25203
21d799b5
NC
25204 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
25205 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
25206 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
25207 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
25208 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
25209 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
25210 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25211 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25212 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25213 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25214 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25215 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25216 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25217 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25218 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25219 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25220 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25221 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25222 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25223 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25224 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
25225 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25226 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25227 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25228 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25229 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25230 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25231 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25232 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25233 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25234 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25235 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25236 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25237 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25238 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25239 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25240 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25241 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25242 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25243 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25244 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25245 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25246 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25247 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25248 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25249 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25250 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25251 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25252 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25253 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25254 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25255 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25256 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25257 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25258 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25259 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25260 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 25261
c921be7d
NC
25262#undef ARM_VARIANT
25263#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
25264
21d799b5
NC
25265 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25266 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25267 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25268 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25269 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25270 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25271 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25272 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25273 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
25274 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
25275 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
25276 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
25277 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
25278 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
25279 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
25280 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
25281 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
25282 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
25283 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
25284 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
25285 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
25286 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
25287 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
25288 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
25289 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
25290 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
25291 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
25292 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
25293 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
25294 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
25295 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
25296 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
25297 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
25298 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
25299 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
25300 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
25301 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
25302 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
25303 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
25304 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
25305 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
25306 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
25307 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
25308 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
25309 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
25310 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
25311 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
25312 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
25313 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
25314 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
25315 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
25316 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
25317 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
25318 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
25319 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
25320 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
25321 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
25322 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
25323 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
25324 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
25325 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
25326 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
25327 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
25328 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
25329 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25330 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25331 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25332 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25333 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25334 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25335 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25336 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
25337 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
25338 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
25339 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
25340 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 25341
7fadb25d
SD
25342 /* ARMv8.5-A instructions. */
25343#undef ARM_VARIANT
25344#define ARM_VARIANT & arm_ext_sb
25345#undef THUMB_VARIANT
25346#define THUMB_VARIANT & arm_ext_sb
25347 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
25348
dad0c3bf
SD
25349#undef ARM_VARIANT
25350#define ARM_VARIANT & arm_ext_predres
25351#undef THUMB_VARIANT
25352#define THUMB_VARIANT & arm_ext_predres
25353 CE("cfprctx", e070f93, 1, (RRnpc), rd),
25354 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
25355 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
25356
16a1fa25 25357 /* ARMv8-M instructions. */
4ed7ed8d
TP
25358#undef ARM_VARIANT
25359#define ARM_VARIANT NULL
25360#undef THUMB_VARIANT
25361#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
25362 ToU("sg", e97fe97f, 0, (), noargs),
25363 ToC("blxns", 4784, 1, (RRnpc), t_blx),
25364 ToC("bxns", 4704, 1, (RRnpc), t_bx),
25365 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
25366 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
25367 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
25368 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
25369
25370 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
25371 instructions behave as nop if no VFP is present. */
25372#undef THUMB_VARIANT
25373#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
25374 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
25375 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
25376
25377 /* Armv8.1-M Mainline instructions. */
25378#undef THUMB_VARIANT
25379#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
25380 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25381 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25382 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25383 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25384 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
25385 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
25386 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25387 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25388 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25389
4389b29a 25390 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 25391 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 25392 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 25393 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 25394 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
25395
25396 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
25397 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
25398 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 25399
efd6b359 25400 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
25401 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
25402
25403#undef THUMB_VARIANT
25404#define THUMB_VARIANT & mve_ext
23d00a41
SD
25405 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25406 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25407 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25408 ToC("uqrshll", ea51010d, 3, (RRe, RRo, RRnpcsp), mve_scalar_shift),
25409 ToC("sqrshrl", ea51012d, 3, (RRe, RRo, RRnpcsp), mve_scalar_shift),
25410 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
25411 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25412 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
25413 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
25414 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25415 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25416 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
25417 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
25418 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
25419 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
25420
25421 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25422 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25423 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25424 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25425 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25426 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25427 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25428 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25429 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25430 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25431 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25432 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25433 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25434 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25435 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25436
5ee91343
AV
25437 ToC("vpst", fe710f4d, 0, (), mve_vpt),
25438 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
25439 ToC("vpste", fe718f4d, 0, (), mve_vpt),
25440 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
25441 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
25442 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
25443 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
25444 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
25445 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
25446 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
25447 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
25448 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
25449 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
25450 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
25451 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
25452
a302e574 25453 /* MVE and MVE FP only. */
7df54120 25454 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
c2dafc2a
AV
25455 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
25456 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
25457 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25458 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 25459 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
25460 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
25461 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25462 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25463 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25464 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25465 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25466 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25467 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25468 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25469 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25470 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25471
35c228db
AV
25472 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25473 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25474 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25475 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25476 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25477 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25478 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25479 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25480 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25481 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25482 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25483 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
25484 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25485 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25486 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25487 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25488 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25489 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25490 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25491 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 25492
57785aa2
AV
25493 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
25494 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 25495 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
25496 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
25497 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
25498 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
25499 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
25500 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
25501 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25502 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
25503 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
25504 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25505 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
25506 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
25507 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
25508 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
25509 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 25510
93925576
AV
25511 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25512 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25513 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25514 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25515 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25516 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25517 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25518 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25519 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25520 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25521 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25522 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25523 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25524 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25525 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25526 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25527 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25528 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25529 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25530 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25531
2d78f95b
AV
25532 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
25533 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25534 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
25535 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
25536 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 25537
8b8b22a4
AV
25538 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25539 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25540 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25541 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25542 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25543 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25544 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25545 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
25546 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25547 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25548 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
25549 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25550 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
25551 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
25552 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
25553 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
25554 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 25555
4aa88b50
AV
25556 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25557 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25558 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25559 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25560 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25561 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25562 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25563 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25564 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25565 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25566 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25567 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25568
acca5630
AV
25569 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
25570 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
25571 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
25572
1f6234a3
AV
25573 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
25574 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
25575 toU("letp", _letp, 2, (LR, EXP), t_loloop),
25576 toU("lctp", _lctp, 0, (), t_loloop),
25577
5d281bf0
AV
25578#undef THUMB_VARIANT
25579#define THUMB_VARIANT & mve_fp_ext
25580 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 25581 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
25582 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25583 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
25584 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
25585 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
25586 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
25587 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 25588
5ee91343 25589#undef ARM_VARIANT
57785aa2 25590#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
25591#undef THUMB_VARIANT
25592#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
25593 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
25594 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 25595
57785aa2
AV
25596 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25597
25598#undef ARM_VARIANT
25599#define ARM_VARIANT & fpu_vfp_ext_v1xd
25600
25601 MNCE(vmov, 0, 1, (VMOV), neon_mov),
25602 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
25603 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
25604 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
25605
886e1c73
AV
25606 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
25607 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25608 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 25609
485dee97
AV
25610 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25611 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25612
57785aa2
AV
25613 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
25614 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
25615
1b883319
AV
25616 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25617 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25618
57785aa2
AV
25619#undef ARM_VARIANT
25620#define ARM_VARIANT & fpu_vfp_ext_v2
25621
25622 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
25623 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
25624 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
25625 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
25626
dd9634d9
AV
25627#undef ARM_VARIANT
25628#define ARM_VARIANT & fpu_vfp_ext_armv8xd
25629 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
25630 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
25631 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
25632 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
25633 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25634 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
25635
25636#undef ARM_VARIANT
5ee91343 25637#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 25638 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343
AV
25639 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
25640 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
25641 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
f601a00c
AV
25642 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25643 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25644 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25645 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25646 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
25647 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
25648 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 25649 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
25650 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25651 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
25652 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
25653 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25654 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
25655 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25656 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
25657 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
25658 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25659 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
25660 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
25661 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25662 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
25663 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25664 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
25665 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25666 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25667 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
25668 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
25669 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
25670 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
25671 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
25672 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
25673 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
25674 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
25675
25676#undef ARM_VARIANT
25677#define ARM_VARIANT & arm_ext_v8_3
25678#undef THUMB_VARIANT
25679#define THUMB_VARIANT & arm_ext_v6t2_v8m
25680 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
25681 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
c19d1205
ZW
25682};
25683#undef ARM_VARIANT
25684#undef THUMB_VARIANT
25685#undef TCE
c19d1205
ZW
25686#undef TUE
25687#undef TUF
25688#undef TCC
8f06b2d8 25689#undef cCE
e3cb604e
PB
25690#undef cCL
25691#undef C3E
4389b29a 25692#undef C3
c19d1205
ZW
25693#undef CE
25694#undef CM
4389b29a 25695#undef CL
c19d1205
ZW
25696#undef UE
25697#undef UF
25698#undef UT
5287ad62
JB
25699#undef NUF
25700#undef nUF
25701#undef NCE
25702#undef nCE
c19d1205
ZW
25703#undef OPS0
25704#undef OPS1
25705#undef OPS2
25706#undef OPS3
25707#undef OPS4
25708#undef OPS5
25709#undef OPS6
25710#undef do_0
4389b29a
AV
25711#undef ToC
25712#undef toC
25713#undef ToU
f6b2b12d 25714#undef toU
c19d1205
ZW
25715\f
25716/* MD interface: bits in the object file. */
bfae80f2 25717
c19d1205
ZW
25718/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
25719 for use in the a.out file, and stores them in the array pointed to by buf.
25720 This knows about the endian-ness of the target machine and does
25721 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
25722 2 (short) and 4 (long) Floating numbers are put out as a series of
25723 LITTLENUMS (shorts, here at least). */
b99bd4ef 25724
c19d1205
ZW
25725void
25726md_number_to_chars (char * buf, valueT val, int n)
25727{
25728 if (target_big_endian)
25729 number_to_chars_bigendian (buf, val, n);
25730 else
25731 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
25732}
25733
c19d1205
ZW
25734static valueT
25735md_chars_to_number (char * buf, int n)
bfae80f2 25736{
c19d1205
ZW
25737 valueT result = 0;
25738 unsigned char * where = (unsigned char *) buf;
bfae80f2 25739
c19d1205 25740 if (target_big_endian)
b99bd4ef 25741 {
c19d1205
ZW
25742 while (n--)
25743 {
25744 result <<= 8;
25745 result |= (*where++ & 255);
25746 }
b99bd4ef 25747 }
c19d1205 25748 else
b99bd4ef 25749 {
c19d1205
ZW
25750 while (n--)
25751 {
25752 result <<= 8;
25753 result |= (where[n] & 255);
25754 }
bfae80f2 25755 }
b99bd4ef 25756
c19d1205 25757 return result;
bfae80f2 25758}
b99bd4ef 25759
c19d1205 25760/* MD interface: Sections. */
b99bd4ef 25761
fa94de6b
RM
25762/* Calculate the maximum variable size (i.e., excluding fr_fix)
25763 that an rs_machine_dependent frag may reach. */
25764
25765unsigned int
25766arm_frag_max_var (fragS *fragp)
25767{
25768 /* We only use rs_machine_dependent for variable-size Thumb instructions,
25769 which are either THUMB_SIZE (2) or INSN_SIZE (4).
25770
25771 Note that we generate relaxable instructions even for cases that don't
25772 really need it, like an immediate that's a trivial constant. So we're
25773 overestimating the instruction size for some of those cases. Rather
25774 than putting more intelligence here, it would probably be better to
25775 avoid generating a relaxation frag in the first place when it can be
25776 determined up front that a short instruction will suffice. */
25777
25778 gas_assert (fragp->fr_type == rs_machine_dependent);
25779 return INSN_SIZE;
25780}
25781
0110f2b8
PB
25782/* Estimate the size of a frag before relaxing. Assume everything fits in
25783 2 bytes. */
25784
c19d1205 25785int
0110f2b8 25786md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
25787 segT segtype ATTRIBUTE_UNUSED)
25788{
0110f2b8
PB
25789 fragp->fr_var = 2;
25790 return 2;
25791}
25792
25793/* Convert a machine dependent frag. */
25794
25795void
25796md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
25797{
25798 unsigned long insn;
25799 unsigned long old_op;
25800 char *buf;
25801 expressionS exp;
25802 fixS *fixp;
25803 int reloc_type;
25804 int pc_rel;
25805 int opcode;
25806
25807 buf = fragp->fr_literal + fragp->fr_fix;
25808
25809 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
25810 if (fragp->fr_symbol)
25811 {
0110f2b8
PB
25812 exp.X_op = O_symbol;
25813 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
25814 }
25815 else
25816 {
0110f2b8 25817 exp.X_op = O_constant;
5f4273c7 25818 }
0110f2b8
PB
25819 exp.X_add_number = fragp->fr_offset;
25820 opcode = fragp->fr_subtype;
25821 switch (opcode)
25822 {
25823 case T_MNEM_ldr_pc:
25824 case T_MNEM_ldr_pc2:
25825 case T_MNEM_ldr_sp:
25826 case T_MNEM_str_sp:
25827 case T_MNEM_ldr:
25828 case T_MNEM_ldrb:
25829 case T_MNEM_ldrh:
25830 case T_MNEM_str:
25831 case T_MNEM_strb:
25832 case T_MNEM_strh:
25833 if (fragp->fr_var == 4)
25834 {
5f4273c7 25835 insn = THUMB_OP32 (opcode);
0110f2b8
PB
25836 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
25837 {
25838 insn |= (old_op & 0x700) << 4;
25839 }
25840 else
25841 {
25842 insn |= (old_op & 7) << 12;
25843 insn |= (old_op & 0x38) << 13;
25844 }
25845 insn |= 0x00000c00;
25846 put_thumb32_insn (buf, insn);
25847 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
25848 }
25849 else
25850 {
25851 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
25852 }
25853 pc_rel = (opcode == T_MNEM_ldr_pc2);
25854 break;
25855 case T_MNEM_adr:
25856 if (fragp->fr_var == 4)
25857 {
25858 insn = THUMB_OP32 (opcode);
25859 insn |= (old_op & 0xf0) << 4;
25860 put_thumb32_insn (buf, insn);
25861 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
25862 }
25863 else
25864 {
25865 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25866 exp.X_add_number -= 4;
25867 }
25868 pc_rel = 1;
25869 break;
25870 case T_MNEM_mov:
25871 case T_MNEM_movs:
25872 case T_MNEM_cmp:
25873 case T_MNEM_cmn:
25874 if (fragp->fr_var == 4)
25875 {
25876 int r0off = (opcode == T_MNEM_mov
25877 || opcode == T_MNEM_movs) ? 0 : 8;
25878 insn = THUMB_OP32 (opcode);
25879 insn = (insn & 0xe1ffffff) | 0x10000000;
25880 insn |= (old_op & 0x700) << r0off;
25881 put_thumb32_insn (buf, insn);
25882 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
25883 }
25884 else
25885 {
25886 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
25887 }
25888 pc_rel = 0;
25889 break;
25890 case T_MNEM_b:
25891 if (fragp->fr_var == 4)
25892 {
25893 insn = THUMB_OP32(opcode);
25894 put_thumb32_insn (buf, insn);
25895 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
25896 }
25897 else
25898 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
25899 pc_rel = 1;
25900 break;
25901 case T_MNEM_bcond:
25902 if (fragp->fr_var == 4)
25903 {
25904 insn = THUMB_OP32(opcode);
25905 insn |= (old_op & 0xf00) << 14;
25906 put_thumb32_insn (buf, insn);
25907 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
25908 }
25909 else
25910 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
25911 pc_rel = 1;
25912 break;
25913 case T_MNEM_add_sp:
25914 case T_MNEM_add_pc:
25915 case T_MNEM_inc_sp:
25916 case T_MNEM_dec_sp:
25917 if (fragp->fr_var == 4)
25918 {
25919 /* ??? Choose between add and addw. */
25920 insn = THUMB_OP32 (opcode);
25921 insn |= (old_op & 0xf0) << 4;
25922 put_thumb32_insn (buf, insn);
16805f35
PB
25923 if (opcode == T_MNEM_add_pc)
25924 reloc_type = BFD_RELOC_ARM_T32_IMM12;
25925 else
25926 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
25927 }
25928 else
25929 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25930 pc_rel = 0;
25931 break;
25932
25933 case T_MNEM_addi:
25934 case T_MNEM_addis:
25935 case T_MNEM_subi:
25936 case T_MNEM_subis:
25937 if (fragp->fr_var == 4)
25938 {
25939 insn = THUMB_OP32 (opcode);
25940 insn |= (old_op & 0xf0) << 4;
25941 insn |= (old_op & 0xf) << 16;
25942 put_thumb32_insn (buf, insn);
16805f35
PB
25943 if (insn & (1 << 20))
25944 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
25945 else
25946 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
25947 }
25948 else
25949 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25950 pc_rel = 0;
25951 break;
25952 default:
5f4273c7 25953 abort ();
0110f2b8
PB
25954 }
25955 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 25956 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
25957 fixp->fx_file = fragp->fr_file;
25958 fixp->fx_line = fragp->fr_line;
25959 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
25960
25961 /* Set whether we use thumb-2 ISA based on final relaxation results. */
25962 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
25963 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
25964 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
25965}
25966
25967/* Return the size of a relaxable immediate operand instruction.
25968 SHIFT and SIZE specify the form of the allowable immediate. */
25969static int
25970relax_immediate (fragS *fragp, int size, int shift)
25971{
25972 offsetT offset;
25973 offsetT mask;
25974 offsetT low;
25975
25976 /* ??? Should be able to do better than this. */
25977 if (fragp->fr_symbol)
25978 return 4;
25979
25980 low = (1 << shift) - 1;
25981 mask = (1 << (shift + size)) - (1 << shift);
25982 offset = fragp->fr_offset;
25983 /* Force misaligned offsets to 32-bit variant. */
25984 if (offset & low)
5e77afaa 25985 return 4;
0110f2b8
PB
25986 if (offset & ~mask)
25987 return 4;
25988 return 2;
25989}
25990
5e77afaa
PB
25991/* Get the address of a symbol during relaxation. */
25992static addressT
5f4273c7 25993relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
25994{
25995 fragS *sym_frag;
25996 addressT addr;
25997 symbolS *sym;
25998
25999 sym = fragp->fr_symbol;
26000 sym_frag = symbol_get_frag (sym);
26001 know (S_GET_SEGMENT (sym) != absolute_section
26002 || sym_frag == &zero_address_frag);
26003 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26004
26005 /* If frag has yet to be reached on this pass, assume it will
26006 move by STRETCH just as we did. If this is not so, it will
26007 be because some frag between grows, and that will force
26008 another pass. */
26009
26010 if (stretch != 0
26011 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26012 {
26013 fragS *f;
26014
26015 /* Adjust stretch for any alignment frag. Note that if have
26016 been expanding the earlier code, the symbol may be
26017 defined in what appears to be an earlier frag. FIXME:
26018 This doesn't handle the fr_subtype field, which specifies
26019 a maximum number of bytes to skip when doing an
26020 alignment. */
26021 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26022 {
26023 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26024 {
26025 if (stretch < 0)
26026 stretch = - ((- stretch)
26027 & ~ ((1 << (int) f->fr_offset) - 1));
26028 else
26029 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26030 if (stretch == 0)
26031 break;
26032 }
26033 }
26034 if (f != NULL)
26035 addr += stretch;
26036 }
5e77afaa
PB
26037
26038 return addr;
26039}
26040
0110f2b8
PB
26041/* Return the size of a relaxable adr pseudo-instruction or PC-relative
26042 load. */
26043static int
5e77afaa 26044relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
26045{
26046 addressT addr;
26047 offsetT val;
26048
26049 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
26050 if (fragp->fr_symbol == NULL
26051 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
26052 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26053 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
26054 return 4;
26055
5f4273c7 26056 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
26057 addr = fragp->fr_address + fragp->fr_fix;
26058 addr = (addr + 4) & ~3;
5e77afaa 26059 /* Force misaligned targets to 32-bit variant. */
0110f2b8 26060 if (val & 3)
5e77afaa 26061 return 4;
0110f2b8
PB
26062 val -= addr;
26063 if (val < 0 || val > 1020)
26064 return 4;
26065 return 2;
26066}
26067
26068/* Return the size of a relaxable add/sub immediate instruction. */
26069static int
26070relax_addsub (fragS *fragp, asection *sec)
26071{
26072 char *buf;
26073 int op;
26074
26075 buf = fragp->fr_literal + fragp->fr_fix;
26076 op = bfd_get_16(sec->owner, buf);
26077 if ((op & 0xf) == ((op >> 4) & 0xf))
26078 return relax_immediate (fragp, 8, 0);
26079 else
26080 return relax_immediate (fragp, 3, 0);
26081}
26082
e83a675f
RE
26083/* Return TRUE iff the definition of symbol S could be pre-empted
26084 (overridden) at link or load time. */
26085static bfd_boolean
26086symbol_preemptible (symbolS *s)
26087{
26088 /* Weak symbols can always be pre-empted. */
26089 if (S_IS_WEAK (s))
26090 return TRUE;
26091
26092 /* Non-global symbols cannot be pre-empted. */
26093 if (! S_IS_EXTERNAL (s))
26094 return FALSE;
26095
26096#ifdef OBJ_ELF
26097 /* In ELF, a global symbol can be marked protected, or private. In that
26098 case it can't be pre-empted (other definitions in the same link unit
26099 would violate the ODR). */
26100 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
26101 return FALSE;
26102#endif
26103
26104 /* Other global symbols might be pre-empted. */
26105 return TRUE;
26106}
0110f2b8
PB
26107
26108/* Return the size of a relaxable branch instruction. BITS is the
26109 size of the offset field in the narrow instruction. */
26110
26111static int
5e77afaa 26112relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
26113{
26114 addressT addr;
26115 offsetT val;
26116 offsetT limit;
26117
26118 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 26119 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
26120 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26121 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
26122 return 4;
26123
267bf995 26124#ifdef OBJ_ELF
e83a675f 26125 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
26126 if (S_IS_DEFINED (fragp->fr_symbol)
26127 && ARM_IS_FUNC (fragp->fr_symbol))
26128 return 4;
e83a675f 26129#endif
0d9b4b55 26130
e83a675f 26131 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 26132 return 4;
267bf995 26133
5f4273c7 26134 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
26135 addr = fragp->fr_address + fragp->fr_fix + 4;
26136 val -= addr;
26137
26138 /* Offset is a signed value *2 */
26139 limit = 1 << bits;
26140 if (val >= limit || val < -limit)
26141 return 4;
26142 return 2;
26143}
26144
26145
26146/* Relax a machine dependent frag. This returns the amount by which
26147 the current size of the frag should change. */
26148
26149int
5e77afaa 26150arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
26151{
26152 int oldsize;
26153 int newsize;
26154
26155 oldsize = fragp->fr_var;
26156 switch (fragp->fr_subtype)
26157 {
26158 case T_MNEM_ldr_pc2:
5f4273c7 26159 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26160 break;
26161 case T_MNEM_ldr_pc:
26162 case T_MNEM_ldr_sp:
26163 case T_MNEM_str_sp:
5f4273c7 26164 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
26165 break;
26166 case T_MNEM_ldr:
26167 case T_MNEM_str:
5f4273c7 26168 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
26169 break;
26170 case T_MNEM_ldrh:
26171 case T_MNEM_strh:
5f4273c7 26172 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
26173 break;
26174 case T_MNEM_ldrb:
26175 case T_MNEM_strb:
5f4273c7 26176 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
26177 break;
26178 case T_MNEM_adr:
5f4273c7 26179 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26180 break;
26181 case T_MNEM_mov:
26182 case T_MNEM_movs:
26183 case T_MNEM_cmp:
26184 case T_MNEM_cmn:
5f4273c7 26185 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
26186 break;
26187 case T_MNEM_b:
5f4273c7 26188 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
26189 break;
26190 case T_MNEM_bcond:
5f4273c7 26191 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
26192 break;
26193 case T_MNEM_add_sp:
26194 case T_MNEM_add_pc:
26195 newsize = relax_immediate (fragp, 8, 2);
26196 break;
26197 case T_MNEM_inc_sp:
26198 case T_MNEM_dec_sp:
26199 newsize = relax_immediate (fragp, 7, 2);
26200 break;
26201 case T_MNEM_addi:
26202 case T_MNEM_addis:
26203 case T_MNEM_subi:
26204 case T_MNEM_subis:
26205 newsize = relax_addsub (fragp, sec);
26206 break;
26207 default:
5f4273c7 26208 abort ();
0110f2b8 26209 }
5e77afaa
PB
26210
26211 fragp->fr_var = newsize;
26212 /* Freeze wide instructions that are at or before the same location as
26213 in the previous pass. This avoids infinite loops.
5f4273c7
NC
26214 Don't freeze them unconditionally because targets may be artificially
26215 misaligned by the expansion of preceding frags. */
5e77afaa 26216 if (stretch <= 0 && newsize > 2)
0110f2b8 26217 {
0110f2b8 26218 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 26219 frag_wane (fragp);
0110f2b8 26220 }
5e77afaa 26221
0110f2b8 26222 return newsize - oldsize;
c19d1205 26223}
b99bd4ef 26224
c19d1205 26225/* Round up a section size to the appropriate boundary. */
b99bd4ef 26226
c19d1205
ZW
26227valueT
26228md_section_align (segT segment ATTRIBUTE_UNUSED,
26229 valueT size)
26230{
6844c0cc 26231 return size;
bfae80f2 26232}
b99bd4ef 26233
c19d1205
ZW
26234/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
26235 of an rs_align_code fragment. */
26236
26237void
26238arm_handle_align (fragS * fragP)
bfae80f2 26239{
d9235011 26240 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
26241 {
26242 { /* ARMv1 */
26243 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
26244 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
26245 },
26246 { /* ARMv6k */
26247 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
26248 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
26249 },
26250 };
d9235011 26251 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
26252 {
26253 { /* Thumb-1 */
26254 {0xc0, 0x46}, /* LE */
26255 {0x46, 0xc0}, /* BE */
26256 },
26257 { /* Thumb-2 */
26258 {0x00, 0xbf}, /* LE */
26259 {0xbf, 0x00} /* BE */
26260 }
26261 };
d9235011 26262 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
26263 { /* Wide Thumb-2 */
26264 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
26265 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
26266 };
c921be7d 26267
e7495e45 26268 unsigned bytes, fix, noop_size;
c19d1205 26269 char * p;
d9235011
TS
26270 const unsigned char * noop;
26271 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
26272#ifdef OBJ_ELF
26273 enum mstate state;
26274#endif
bfae80f2 26275
c19d1205 26276 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
26277 return;
26278
c19d1205
ZW
26279 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
26280 p = fragP->fr_literal + fragP->fr_fix;
26281 fix = 0;
bfae80f2 26282
c19d1205
ZW
26283 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
26284 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 26285
cd000bff 26286 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 26287
cd000bff 26288 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 26289 {
7f78eb34
JW
26290 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26291 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
26292 {
26293 narrow_noop = thumb_noop[1][target_big_endian];
26294 noop = wide_thumb_noop[target_big_endian];
26295 }
c19d1205 26296 else
e7495e45
NS
26297 noop = thumb_noop[0][target_big_endian];
26298 noop_size = 2;
cd000bff
DJ
26299#ifdef OBJ_ELF
26300 state = MAP_THUMB;
26301#endif
7ed4c4c5
NC
26302 }
26303 else
26304 {
7f78eb34
JW
26305 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26306 ? selected_cpu : arm_arch_none,
26307 arm_ext_v6k) != 0]
e7495e45
NS
26308 [target_big_endian];
26309 noop_size = 4;
cd000bff
DJ
26310#ifdef OBJ_ELF
26311 state = MAP_ARM;
26312#endif
7ed4c4c5 26313 }
c921be7d 26314
e7495e45 26315 fragP->fr_var = noop_size;
c921be7d 26316
c19d1205 26317 if (bytes & (noop_size - 1))
7ed4c4c5 26318 {
c19d1205 26319 fix = bytes & (noop_size - 1);
cd000bff
DJ
26320#ifdef OBJ_ELF
26321 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
26322#endif
c19d1205
ZW
26323 memset (p, 0, fix);
26324 p += fix;
26325 bytes -= fix;
a737bd4d 26326 }
a737bd4d 26327
e7495e45
NS
26328 if (narrow_noop)
26329 {
26330 if (bytes & noop_size)
26331 {
26332 /* Insert a narrow noop. */
26333 memcpy (p, narrow_noop, noop_size);
26334 p += noop_size;
26335 bytes -= noop_size;
26336 fix += noop_size;
26337 }
26338
26339 /* Use wide noops for the remainder */
26340 noop_size = 4;
26341 }
26342
c19d1205 26343 while (bytes >= noop_size)
a737bd4d 26344 {
c19d1205
ZW
26345 memcpy (p, noop, noop_size);
26346 p += noop_size;
26347 bytes -= noop_size;
26348 fix += noop_size;
a737bd4d
NC
26349 }
26350
c19d1205 26351 fragP->fr_fix += fix;
a737bd4d
NC
26352}
26353
c19d1205
ZW
26354/* Called from md_do_align. Used to create an alignment
26355 frag in a code section. */
26356
26357void
26358arm_frag_align_code (int n, int max)
bfae80f2 26359{
c19d1205 26360 char * p;
7ed4c4c5 26361
c19d1205 26362 /* We assume that there will never be a requirement
6ec8e702 26363 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 26364 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
26365 {
26366 char err_msg[128];
26367
fa94de6b 26368 sprintf (err_msg,
477330fc
RM
26369 _("alignments greater than %d bytes not supported in .text sections."),
26370 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 26371 as_fatal ("%s", err_msg);
6ec8e702 26372 }
bfae80f2 26373
c19d1205
ZW
26374 p = frag_var (rs_align_code,
26375 MAX_MEM_FOR_RS_ALIGN_CODE,
26376 1,
26377 (relax_substateT) max,
26378 (symbolS *) NULL,
26379 (offsetT) n,
26380 (char *) NULL);
26381 *p = 0;
26382}
bfae80f2 26383
8dc2430f
NC
26384/* Perform target specific initialisation of a frag.
26385 Note - despite the name this initialisation is not done when the frag
26386 is created, but only when its type is assigned. A frag can be created
26387 and used a long time before its type is set, so beware of assuming that
33eaf5de 26388 this initialisation is performed first. */
bfae80f2 26389
cd000bff
DJ
26390#ifndef OBJ_ELF
26391void
26392arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
26393{
26394 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 26395 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
26396}
26397
26398#else /* OBJ_ELF is defined. */
c19d1205 26399void
cd000bff 26400arm_init_frag (fragS * fragP, int max_chars)
c19d1205 26401{
e8d84ca1 26402 bfd_boolean frag_thumb_mode;
b968d18a 26403
8dc2430f
NC
26404 /* If the current ARM vs THUMB mode has not already
26405 been recorded into this frag then do so now. */
cd000bff 26406 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
26407 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26408
e8d84ca1
NC
26409 /* PR 21809: Do not set a mapping state for debug sections
26410 - it just confuses other tools. */
26411 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
26412 return;
26413
b968d18a 26414 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 26415
f9c1b181
RL
26416 /* Record a mapping symbol for alignment frags. We will delete this
26417 later if the alignment ends up empty. */
26418 switch (fragP->fr_type)
26419 {
26420 case rs_align:
26421 case rs_align_test:
26422 case rs_fill:
26423 mapping_state_2 (MAP_DATA, max_chars);
26424 break;
26425 case rs_align_code:
b968d18a 26426 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
26427 break;
26428 default:
26429 break;
cd000bff 26430 }
bfae80f2
RE
26431}
26432
c19d1205
ZW
26433/* When we change sections we need to issue a new mapping symbol. */
26434
26435void
26436arm_elf_change_section (void)
bfae80f2 26437{
c19d1205
ZW
26438 /* Link an unlinked unwind index table section to the .text section. */
26439 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
26440 && elf_linked_to_section (now_seg) == NULL)
26441 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
26442}
26443
c19d1205
ZW
26444int
26445arm_elf_section_type (const char * str, size_t len)
e45d0630 26446{
c19d1205
ZW
26447 if (len == 5 && strncmp (str, "exidx", 5) == 0)
26448 return SHT_ARM_EXIDX;
e45d0630 26449
c19d1205
ZW
26450 return -1;
26451}
26452\f
26453/* Code to deal with unwinding tables. */
e45d0630 26454
c19d1205 26455static void add_unwind_adjustsp (offsetT);
e45d0630 26456
5f4273c7 26457/* Generate any deferred unwind frame offset. */
e45d0630 26458
bfae80f2 26459static void
c19d1205 26460flush_pending_unwind (void)
bfae80f2 26461{
c19d1205 26462 offsetT offset;
bfae80f2 26463
c19d1205
ZW
26464 offset = unwind.pending_offset;
26465 unwind.pending_offset = 0;
26466 if (offset != 0)
26467 add_unwind_adjustsp (offset);
bfae80f2
RE
26468}
26469
c19d1205
ZW
26470/* Add an opcode to this list for this function. Two-byte opcodes should
26471 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
26472 order. */
26473
bfae80f2 26474static void
c19d1205 26475add_unwind_opcode (valueT op, int length)
bfae80f2 26476{
c19d1205
ZW
26477 /* Add any deferred stack adjustment. */
26478 if (unwind.pending_offset)
26479 flush_pending_unwind ();
bfae80f2 26480
c19d1205 26481 unwind.sp_restored = 0;
bfae80f2 26482
c19d1205 26483 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 26484 {
c19d1205
ZW
26485 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
26486 if (unwind.opcodes)
325801bd
TS
26487 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
26488 unwind.opcode_alloc);
c19d1205 26489 else
325801bd 26490 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 26491 }
c19d1205 26492 while (length > 0)
bfae80f2 26493 {
c19d1205
ZW
26494 length--;
26495 unwind.opcodes[unwind.opcode_count] = op & 0xff;
26496 op >>= 8;
26497 unwind.opcode_count++;
bfae80f2 26498 }
bfae80f2
RE
26499}
26500
c19d1205
ZW
26501/* Add unwind opcodes to adjust the stack pointer. */
26502
bfae80f2 26503static void
c19d1205 26504add_unwind_adjustsp (offsetT offset)
bfae80f2 26505{
c19d1205 26506 valueT op;
bfae80f2 26507
c19d1205 26508 if (offset > 0x200)
bfae80f2 26509 {
c19d1205
ZW
26510 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
26511 char bytes[5];
26512 int n;
26513 valueT o;
bfae80f2 26514
c19d1205
ZW
26515 /* Long form: 0xb2, uleb128. */
26516 /* This might not fit in a word so add the individual bytes,
26517 remembering the list is built in reverse order. */
26518 o = (valueT) ((offset - 0x204) >> 2);
26519 if (o == 0)
26520 add_unwind_opcode (0, 1);
bfae80f2 26521
c19d1205
ZW
26522 /* Calculate the uleb128 encoding of the offset. */
26523 n = 0;
26524 while (o)
26525 {
26526 bytes[n] = o & 0x7f;
26527 o >>= 7;
26528 if (o)
26529 bytes[n] |= 0x80;
26530 n++;
26531 }
26532 /* Add the insn. */
26533 for (; n; n--)
26534 add_unwind_opcode (bytes[n - 1], 1);
26535 add_unwind_opcode (0xb2, 1);
26536 }
26537 else if (offset > 0x100)
bfae80f2 26538 {
c19d1205
ZW
26539 /* Two short opcodes. */
26540 add_unwind_opcode (0x3f, 1);
26541 op = (offset - 0x104) >> 2;
26542 add_unwind_opcode (op, 1);
bfae80f2 26543 }
c19d1205
ZW
26544 else if (offset > 0)
26545 {
26546 /* Short opcode. */
26547 op = (offset - 4) >> 2;
26548 add_unwind_opcode (op, 1);
26549 }
26550 else if (offset < 0)
bfae80f2 26551 {
c19d1205
ZW
26552 offset = -offset;
26553 while (offset > 0x100)
bfae80f2 26554 {
c19d1205
ZW
26555 add_unwind_opcode (0x7f, 1);
26556 offset -= 0x100;
bfae80f2 26557 }
c19d1205
ZW
26558 op = ((offset - 4) >> 2) | 0x40;
26559 add_unwind_opcode (op, 1);
bfae80f2 26560 }
bfae80f2
RE
26561}
26562
c19d1205 26563/* Finish the list of unwind opcodes for this function. */
0198d5e6 26564
c19d1205
ZW
26565static void
26566finish_unwind_opcodes (void)
bfae80f2 26567{
c19d1205 26568 valueT op;
bfae80f2 26569
c19d1205 26570 if (unwind.fp_used)
bfae80f2 26571 {
708587a4 26572 /* Adjust sp as necessary. */
c19d1205
ZW
26573 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
26574 flush_pending_unwind ();
bfae80f2 26575
c19d1205
ZW
26576 /* After restoring sp from the frame pointer. */
26577 op = 0x90 | unwind.fp_reg;
26578 add_unwind_opcode (op, 1);
26579 }
26580 else
26581 flush_pending_unwind ();
bfae80f2
RE
26582}
26583
bfae80f2 26584
c19d1205
ZW
26585/* Start an exception table entry. If idx is nonzero this is an index table
26586 entry. */
bfae80f2
RE
26587
26588static void
c19d1205 26589start_unwind_section (const segT text_seg, int idx)
bfae80f2 26590{
c19d1205
ZW
26591 const char * text_name;
26592 const char * prefix;
26593 const char * prefix_once;
26594 const char * group_name;
c19d1205 26595 char * sec_name;
c19d1205
ZW
26596 int type;
26597 int flags;
26598 int linkonce;
bfae80f2 26599
c19d1205 26600 if (idx)
bfae80f2 26601 {
c19d1205
ZW
26602 prefix = ELF_STRING_ARM_unwind;
26603 prefix_once = ELF_STRING_ARM_unwind_once;
26604 type = SHT_ARM_EXIDX;
bfae80f2 26605 }
c19d1205 26606 else
bfae80f2 26607 {
c19d1205
ZW
26608 prefix = ELF_STRING_ARM_unwind_info;
26609 prefix_once = ELF_STRING_ARM_unwind_info_once;
26610 type = SHT_PROGBITS;
bfae80f2
RE
26611 }
26612
c19d1205
ZW
26613 text_name = segment_name (text_seg);
26614 if (streq (text_name, ".text"))
26615 text_name = "";
26616
26617 if (strncmp (text_name, ".gnu.linkonce.t.",
26618 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 26619 {
c19d1205
ZW
26620 prefix = prefix_once;
26621 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
26622 }
26623
29a2809e 26624 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 26625
c19d1205
ZW
26626 flags = SHF_ALLOC;
26627 linkonce = 0;
26628 group_name = 0;
bfae80f2 26629
c19d1205
ZW
26630 /* Handle COMDAT group. */
26631 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 26632 {
c19d1205
ZW
26633 group_name = elf_group_name (text_seg);
26634 if (group_name == NULL)
26635 {
bd3ba5d1 26636 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
26637 segment_name (text_seg));
26638 ignore_rest_of_line ();
26639 return;
26640 }
26641 flags |= SHF_GROUP;
26642 linkonce = 1;
bfae80f2
RE
26643 }
26644
a91e1603
L
26645 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
26646 linkonce, 0);
bfae80f2 26647
5f4273c7 26648 /* Set the section link for index tables. */
c19d1205
ZW
26649 if (idx)
26650 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
26651}
26652
bfae80f2 26653
c19d1205
ZW
26654/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
26655 personality routine data. Returns zero, or the index table value for
cad0da33 26656 an inline entry. */
c19d1205
ZW
26657
26658static valueT
26659create_unwind_entry (int have_data)
bfae80f2 26660{
c19d1205
ZW
26661 int size;
26662 addressT where;
26663 char *ptr;
26664 /* The current word of data. */
26665 valueT data;
26666 /* The number of bytes left in this word. */
26667 int n;
bfae80f2 26668
c19d1205 26669 finish_unwind_opcodes ();
bfae80f2 26670
c19d1205
ZW
26671 /* Remember the current text section. */
26672 unwind.saved_seg = now_seg;
26673 unwind.saved_subseg = now_subseg;
bfae80f2 26674
c19d1205 26675 start_unwind_section (now_seg, 0);
bfae80f2 26676
c19d1205 26677 if (unwind.personality_routine == NULL)
bfae80f2 26678 {
c19d1205
ZW
26679 if (unwind.personality_index == -2)
26680 {
26681 if (have_data)
5f4273c7 26682 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
26683 return 1; /* EXIDX_CANTUNWIND. */
26684 }
bfae80f2 26685
c19d1205
ZW
26686 /* Use a default personality routine if none is specified. */
26687 if (unwind.personality_index == -1)
26688 {
26689 if (unwind.opcode_count > 3)
26690 unwind.personality_index = 1;
26691 else
26692 unwind.personality_index = 0;
26693 }
bfae80f2 26694
c19d1205
ZW
26695 /* Space for the personality routine entry. */
26696 if (unwind.personality_index == 0)
26697 {
26698 if (unwind.opcode_count > 3)
26699 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 26700
c19d1205
ZW
26701 if (!have_data)
26702 {
26703 /* All the data is inline in the index table. */
26704 data = 0x80;
26705 n = 3;
26706 while (unwind.opcode_count > 0)
26707 {
26708 unwind.opcode_count--;
26709 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26710 n--;
26711 }
bfae80f2 26712
c19d1205
ZW
26713 /* Pad with "finish" opcodes. */
26714 while (n--)
26715 data = (data << 8) | 0xb0;
bfae80f2 26716
c19d1205
ZW
26717 return data;
26718 }
26719 size = 0;
26720 }
26721 else
26722 /* We get two opcodes "free" in the first word. */
26723 size = unwind.opcode_count - 2;
26724 }
26725 else
5011093d 26726 {
cad0da33
NC
26727 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
26728 if (unwind.personality_index != -1)
26729 {
26730 as_bad (_("attempt to recreate an unwind entry"));
26731 return 1;
26732 }
5011093d
NC
26733
26734 /* An extra byte is required for the opcode count. */
26735 size = unwind.opcode_count + 1;
26736 }
bfae80f2 26737
c19d1205
ZW
26738 size = (size + 3) >> 2;
26739 if (size > 0xff)
26740 as_bad (_("too many unwind opcodes"));
bfae80f2 26741
c19d1205
ZW
26742 frag_align (2, 0, 0);
26743 record_alignment (now_seg, 2);
26744 unwind.table_entry = expr_build_dot ();
26745
26746 /* Allocate the table entry. */
26747 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
26748 /* PR 13449: Zero the table entries in case some of them are not used. */
26749 memset (ptr, 0, (size << 2) + 4);
c19d1205 26750 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 26751
c19d1205 26752 switch (unwind.personality_index)
bfae80f2 26753 {
c19d1205
ZW
26754 case -1:
26755 /* ??? Should this be a PLT generating relocation? */
26756 /* Custom personality routine. */
26757 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
26758 BFD_RELOC_ARM_PREL31);
bfae80f2 26759
c19d1205
ZW
26760 where += 4;
26761 ptr += 4;
bfae80f2 26762
c19d1205 26763 /* Set the first byte to the number of additional words. */
5011093d 26764 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
26765 n = 3;
26766 break;
bfae80f2 26767
c19d1205
ZW
26768 /* ABI defined personality routines. */
26769 case 0:
26770 /* Three opcodes bytes are packed into the first word. */
26771 data = 0x80;
26772 n = 3;
26773 break;
bfae80f2 26774
c19d1205
ZW
26775 case 1:
26776 case 2:
26777 /* The size and first two opcode bytes go in the first word. */
26778 data = ((0x80 + unwind.personality_index) << 8) | size;
26779 n = 2;
26780 break;
bfae80f2 26781
c19d1205
ZW
26782 default:
26783 /* Should never happen. */
26784 abort ();
26785 }
bfae80f2 26786
c19d1205
ZW
26787 /* Pack the opcodes into words (MSB first), reversing the list at the same
26788 time. */
26789 while (unwind.opcode_count > 0)
26790 {
26791 if (n == 0)
26792 {
26793 md_number_to_chars (ptr, data, 4);
26794 ptr += 4;
26795 n = 4;
26796 data = 0;
26797 }
26798 unwind.opcode_count--;
26799 n--;
26800 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26801 }
26802
26803 /* Finish off the last word. */
26804 if (n < 4)
26805 {
26806 /* Pad with "finish" opcodes. */
26807 while (n--)
26808 data = (data << 8) | 0xb0;
26809
26810 md_number_to_chars (ptr, data, 4);
26811 }
26812
26813 if (!have_data)
26814 {
26815 /* Add an empty descriptor if there is no user-specified data. */
26816 ptr = frag_more (4);
26817 md_number_to_chars (ptr, 0, 4);
26818 }
26819
26820 return 0;
bfae80f2
RE
26821}
26822
f0927246
NC
26823
26824/* Initialize the DWARF-2 unwind information for this procedure. */
26825
26826void
26827tc_arm_frame_initial_instructions (void)
26828{
26829 cfi_add_CFA_def_cfa (REG_SP, 0);
26830}
26831#endif /* OBJ_ELF */
26832
c19d1205
ZW
26833/* Convert REGNAME to a DWARF-2 register number. */
26834
26835int
1df69f4f 26836tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 26837{
1df69f4f 26838 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
26839 if (reg != FAIL)
26840 return reg;
c19d1205 26841
1f5afe1c
NC
26842 /* PR 16694: Allow VFP registers as well. */
26843 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
26844 if (reg != FAIL)
26845 return 64 + reg;
c19d1205 26846
1f5afe1c
NC
26847 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
26848 if (reg != FAIL)
26849 return reg + 256;
26850
0198d5e6 26851 return FAIL;
bfae80f2
RE
26852}
26853
f0927246 26854#ifdef TE_PE
c19d1205 26855void
f0927246 26856tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 26857{
91d6fa6a 26858 expressionS exp;
bfae80f2 26859
91d6fa6a
NC
26860 exp.X_op = O_secrel;
26861 exp.X_add_symbol = symbol;
26862 exp.X_add_number = 0;
26863 emit_expr (&exp, size);
f0927246
NC
26864}
26865#endif
bfae80f2 26866
c19d1205 26867/* MD interface: Symbol and relocation handling. */
bfae80f2 26868
2fc8bdac
ZW
26869/* Return the address within the segment that a PC-relative fixup is
26870 relative to. For ARM, PC-relative fixups applied to instructions
26871 are generally relative to the location of the fixup plus 8 bytes.
26872 Thumb branches are offset by 4, and Thumb loads relative to PC
26873 require special handling. */
bfae80f2 26874
c19d1205 26875long
2fc8bdac 26876md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 26877{
2fc8bdac
ZW
26878 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
26879
26880 /* If this is pc-relative and we are going to emit a relocation
26881 then we just want to put out any pipeline compensation that the linker
53baae48
NC
26882 will need. Otherwise we want to use the calculated base.
26883 For WinCE we skip the bias for externals as well, since this
26884 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 26885 if (fixP->fx_pcrel
2fc8bdac 26886 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
26887 || (arm_force_relocation (fixP)
26888#ifdef TE_WINCE
26889 && !S_IS_EXTERNAL (fixP->fx_addsy)
26890#endif
26891 )))
2fc8bdac 26892 base = 0;
bfae80f2 26893
267bf995 26894
c19d1205 26895 switch (fixP->fx_r_type)
bfae80f2 26896 {
2fc8bdac
ZW
26897 /* PC relative addressing on the Thumb is slightly odd as the
26898 bottom two bits of the PC are forced to zero for the
26899 calculation. This happens *after* application of the
26900 pipeline offset. However, Thumb adrl already adjusts for
26901 this, so we need not do it again. */
c19d1205 26902 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 26903 return base & ~3;
c19d1205
ZW
26904
26905 case BFD_RELOC_ARM_THUMB_OFFSET:
26906 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 26907 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 26908 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 26909 return (base + 4) & ~3;
c19d1205 26910
2fc8bdac 26911 /* Thumb branches are simply offset by +4. */
e12437dc 26912 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
26913 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26914 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26915 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26916 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 26917 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 26918 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 26919 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 26920 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 26921 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 26922 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 26923 return base + 4;
bfae80f2 26924
267bf995 26925 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
26926 if (fixP->fx_addsy
26927 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26928 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 26929 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
26930 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26931 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
26932 return base + 4;
26933
00adf2d4
JB
26934 /* BLX is like branches above, but forces the low two bits of PC to
26935 zero. */
486499d0
CL
26936 case BFD_RELOC_THUMB_PCREL_BLX:
26937 if (fixP->fx_addsy
26938 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26939 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26940 && THUMB_IS_FUNC (fixP->fx_addsy)
26941 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26942 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
26943 return (base + 4) & ~3;
26944
2fc8bdac
ZW
26945 /* ARM mode branches are offset by +8. However, the Windows CE
26946 loader expects the relocation not to take this into account. */
267bf995 26947 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
26948 if (fixP->fx_addsy
26949 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26950 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26951 && ARM_IS_FUNC (fixP->fx_addsy)
26952 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26953 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 26954 return base + 8;
267bf995 26955
486499d0
CL
26956 case BFD_RELOC_ARM_PCREL_CALL:
26957 if (fixP->fx_addsy
26958 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26959 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26960 && THUMB_IS_FUNC (fixP->fx_addsy)
26961 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26962 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 26963 return base + 8;
267bf995 26964
2fc8bdac 26965 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 26966 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 26967 case BFD_RELOC_ARM_PLT32:
c19d1205 26968#ifdef TE_WINCE
5f4273c7 26969 /* When handling fixups immediately, because we have already
477330fc 26970 discovered the value of a symbol, or the address of the frag involved
53baae48 26971 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
26972 see fixup_segment() in write.c
26973 The S_IS_EXTERNAL test handles the case of global symbols.
26974 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
26975 if (fixP->fx_pcrel
26976 && fixP->fx_addsy != NULL
26977 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
26978 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
26979 return base + 8;
2fc8bdac 26980 return base;
c19d1205 26981#else
2fc8bdac 26982 return base + 8;
c19d1205 26983#endif
2fc8bdac 26984
267bf995 26985
2fc8bdac
ZW
26986 /* ARM mode loads relative to PC are also offset by +8. Unlike
26987 branches, the Windows CE loader *does* expect the relocation
26988 to take this into account. */
26989 case BFD_RELOC_ARM_OFFSET_IMM:
26990 case BFD_RELOC_ARM_OFFSET_IMM8:
26991 case BFD_RELOC_ARM_HWLITERAL:
26992 case BFD_RELOC_ARM_LITERAL:
26993 case BFD_RELOC_ARM_CP_OFF_IMM:
26994 return base + 8;
26995
26996
26997 /* Other PC-relative relocations are un-offset. */
26998 default:
26999 return base;
27000 }
bfae80f2
RE
27001}
27002
8b2d793c
NC
27003static bfd_boolean flag_warn_syms = TRUE;
27004
ae8714c2
NC
27005bfd_boolean
27006arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27007{
8b2d793c
NC
27008 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27009 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27010 does mean that the resulting code might be very confusing to the reader.
27011 Also this warning can be triggered if the user omits an operand before
27012 an immediate address, eg:
27013
27014 LDR =foo
27015
27016 GAS treats this as an assignment of the value of the symbol foo to a
27017 symbol LDR, and so (without this code) it will not issue any kind of
27018 warning or error message.
27019
27020 Note - ARM instructions are case-insensitive but the strings in the hash
27021 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27022 lower case too. */
27023 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27024 {
27025 char * nbuf = strdup (name);
27026 char * p;
27027
27028 for (p = nbuf; *p; p++)
27029 *p = TOLOWER (*p);
27030 if (hash_find (arm_ops_hsh, nbuf) != NULL)
27031 {
27032 static struct hash_control * already_warned = NULL;
27033
27034 if (already_warned == NULL)
27035 already_warned = hash_new ();
27036 /* Only warn about the symbol once. To keep the code
27037 simple we let hash_insert do the lookup for us. */
3076e594 27038 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 27039 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
27040 }
27041 else
27042 free (nbuf);
27043 }
3739860c 27044
ae8714c2
NC
27045 return FALSE;
27046}
27047
27048/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
27049 Otherwise we have no need to default values of symbols. */
27050
27051symbolS *
27052md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
27053{
27054#ifdef OBJ_ELF
27055 if (name[0] == '_' && name[1] == 'G'
27056 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
27057 {
27058 if (!GOT_symbol)
27059 {
27060 if (symbol_find (name))
27061 as_bad (_("GOT already in the symbol table"));
27062
27063 GOT_symbol = symbol_new (name, undefined_section,
27064 (valueT) 0, & zero_address_frag);
27065 }
27066
27067 return GOT_symbol;
27068 }
27069#endif
27070
c921be7d 27071 return NULL;
bfae80f2
RE
27072}
27073
55cf6793 27074/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
27075 computed as two separate immediate values, added together. We
27076 already know that this value cannot be computed by just one ARM
27077 instruction. */
27078
27079static unsigned int
27080validate_immediate_twopart (unsigned int val,
27081 unsigned int * highpart)
bfae80f2 27082{
c19d1205
ZW
27083 unsigned int a;
27084 unsigned int i;
bfae80f2 27085
c19d1205
ZW
27086 for (i = 0; i < 32; i += 2)
27087 if (((a = rotate_left (val, i)) & 0xff) != 0)
27088 {
27089 if (a & 0xff00)
27090 {
27091 if (a & ~ 0xffff)
27092 continue;
27093 * highpart = (a >> 8) | ((i + 24) << 7);
27094 }
27095 else if (a & 0xff0000)
27096 {
27097 if (a & 0xff000000)
27098 continue;
27099 * highpart = (a >> 16) | ((i + 16) << 7);
27100 }
27101 else
27102 {
9c2799c2 27103 gas_assert (a & 0xff000000);
c19d1205
ZW
27104 * highpart = (a >> 24) | ((i + 8) << 7);
27105 }
bfae80f2 27106
c19d1205
ZW
27107 return (a & 0xff) | (i << 7);
27108 }
bfae80f2 27109
c19d1205 27110 return FAIL;
bfae80f2
RE
27111}
27112
c19d1205
ZW
27113static int
27114validate_offset_imm (unsigned int val, int hwse)
27115{
27116 if ((hwse && val > 255) || val > 4095)
27117 return FAIL;
27118 return val;
27119}
bfae80f2 27120
55cf6793 27121/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
27122 negative immediate constant by altering the instruction. A bit of
27123 a hack really.
27124 MOV <-> MVN
27125 AND <-> BIC
27126 ADC <-> SBC
27127 by inverting the second operand, and
27128 ADD <-> SUB
27129 CMP <-> CMN
27130 by negating the second operand. */
bfae80f2 27131
c19d1205
ZW
27132static int
27133negate_data_op (unsigned long * instruction,
27134 unsigned long value)
bfae80f2 27135{
c19d1205
ZW
27136 int op, new_inst;
27137 unsigned long negated, inverted;
bfae80f2 27138
c19d1205
ZW
27139 negated = encode_arm_immediate (-value);
27140 inverted = encode_arm_immediate (~value);
bfae80f2 27141
c19d1205
ZW
27142 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
27143 switch (op)
bfae80f2 27144 {
c19d1205
ZW
27145 /* First negates. */
27146 case OPCODE_SUB: /* ADD <-> SUB */
27147 new_inst = OPCODE_ADD;
27148 value = negated;
27149 break;
bfae80f2 27150
c19d1205
ZW
27151 case OPCODE_ADD:
27152 new_inst = OPCODE_SUB;
27153 value = negated;
27154 break;
bfae80f2 27155
c19d1205
ZW
27156 case OPCODE_CMP: /* CMP <-> CMN */
27157 new_inst = OPCODE_CMN;
27158 value = negated;
27159 break;
bfae80f2 27160
c19d1205
ZW
27161 case OPCODE_CMN:
27162 new_inst = OPCODE_CMP;
27163 value = negated;
27164 break;
bfae80f2 27165
c19d1205
ZW
27166 /* Now Inverted ops. */
27167 case OPCODE_MOV: /* MOV <-> MVN */
27168 new_inst = OPCODE_MVN;
27169 value = inverted;
27170 break;
bfae80f2 27171
c19d1205
ZW
27172 case OPCODE_MVN:
27173 new_inst = OPCODE_MOV;
27174 value = inverted;
27175 break;
bfae80f2 27176
c19d1205
ZW
27177 case OPCODE_AND: /* AND <-> BIC */
27178 new_inst = OPCODE_BIC;
27179 value = inverted;
27180 break;
bfae80f2 27181
c19d1205
ZW
27182 case OPCODE_BIC:
27183 new_inst = OPCODE_AND;
27184 value = inverted;
27185 break;
bfae80f2 27186
c19d1205
ZW
27187 case OPCODE_ADC: /* ADC <-> SBC */
27188 new_inst = OPCODE_SBC;
27189 value = inverted;
27190 break;
bfae80f2 27191
c19d1205
ZW
27192 case OPCODE_SBC:
27193 new_inst = OPCODE_ADC;
27194 value = inverted;
27195 break;
bfae80f2 27196
c19d1205
ZW
27197 /* We cannot do anything. */
27198 default:
27199 return FAIL;
b99bd4ef
NC
27200 }
27201
c19d1205
ZW
27202 if (value == (unsigned) FAIL)
27203 return FAIL;
27204
27205 *instruction &= OPCODE_MASK;
27206 *instruction |= new_inst << DATA_OP_SHIFT;
27207 return value;
b99bd4ef
NC
27208}
27209
ef8d22e6
PB
27210/* Like negate_data_op, but for Thumb-2. */
27211
27212static unsigned int
16dd5e42 27213thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
27214{
27215 int op, new_inst;
27216 int rd;
16dd5e42 27217 unsigned int negated, inverted;
ef8d22e6
PB
27218
27219 negated = encode_thumb32_immediate (-value);
27220 inverted = encode_thumb32_immediate (~value);
27221
27222 rd = (*instruction >> 8) & 0xf;
27223 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
27224 switch (op)
27225 {
27226 /* ADD <-> SUB. Includes CMP <-> CMN. */
27227 case T2_OPCODE_SUB:
27228 new_inst = T2_OPCODE_ADD;
27229 value = negated;
27230 break;
27231
27232 case T2_OPCODE_ADD:
27233 new_inst = T2_OPCODE_SUB;
27234 value = negated;
27235 break;
27236
27237 /* ORR <-> ORN. Includes MOV <-> MVN. */
27238 case T2_OPCODE_ORR:
27239 new_inst = T2_OPCODE_ORN;
27240 value = inverted;
27241 break;
27242
27243 case T2_OPCODE_ORN:
27244 new_inst = T2_OPCODE_ORR;
27245 value = inverted;
27246 break;
27247
27248 /* AND <-> BIC. TST has no inverted equivalent. */
27249 case T2_OPCODE_AND:
27250 new_inst = T2_OPCODE_BIC;
27251 if (rd == 15)
27252 value = FAIL;
27253 else
27254 value = inverted;
27255 break;
27256
27257 case T2_OPCODE_BIC:
27258 new_inst = T2_OPCODE_AND;
27259 value = inverted;
27260 break;
27261
27262 /* ADC <-> SBC */
27263 case T2_OPCODE_ADC:
27264 new_inst = T2_OPCODE_SBC;
27265 value = inverted;
27266 break;
27267
27268 case T2_OPCODE_SBC:
27269 new_inst = T2_OPCODE_ADC;
27270 value = inverted;
27271 break;
27272
27273 /* We cannot do anything. */
27274 default:
27275 return FAIL;
27276 }
27277
16dd5e42 27278 if (value == (unsigned int)FAIL)
ef8d22e6
PB
27279 return FAIL;
27280
27281 *instruction &= T2_OPCODE_MASK;
27282 *instruction |= new_inst << T2_DATA_OP_SHIFT;
27283 return value;
27284}
27285
8f06b2d8 27286/* Read a 32-bit thumb instruction from buf. */
0198d5e6 27287
8f06b2d8
PB
27288static unsigned long
27289get_thumb32_insn (char * buf)
27290{
27291 unsigned long insn;
27292 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
27293 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27294
27295 return insn;
27296}
27297
a8bc6c78
PB
27298/* We usually want to set the low bit on the address of thumb function
27299 symbols. In particular .word foo - . should have the low bit set.
27300 Generic code tries to fold the difference of two symbols to
27301 a constant. Prevent this and force a relocation when the first symbols
27302 is a thumb function. */
c921be7d
NC
27303
27304bfd_boolean
a8bc6c78
PB
27305arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
27306{
27307 if (op == O_subtract
27308 && l->X_op == O_symbol
27309 && r->X_op == O_symbol
27310 && THUMB_IS_FUNC (l->X_add_symbol))
27311 {
27312 l->X_op = O_subtract;
27313 l->X_op_symbol = r->X_add_symbol;
27314 l->X_add_number -= r->X_add_number;
c921be7d 27315 return TRUE;
a8bc6c78 27316 }
c921be7d 27317
a8bc6c78 27318 /* Process as normal. */
c921be7d 27319 return FALSE;
a8bc6c78
PB
27320}
27321
4a42ebbc
RR
27322/* Encode Thumb2 unconditional branches and calls. The encoding
27323 for the 2 are identical for the immediate values. */
27324
27325static void
27326encode_thumb2_b_bl_offset (char * buf, offsetT value)
27327{
27328#define T2I1I2MASK ((1 << 13) | (1 << 11))
27329 offsetT newval;
27330 offsetT newval2;
27331 addressT S, I1, I2, lo, hi;
27332
27333 S = (value >> 24) & 0x01;
27334 I1 = (value >> 23) & 0x01;
27335 I2 = (value >> 22) & 0x01;
27336 hi = (value >> 12) & 0x3ff;
fa94de6b 27337 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
27338 newval = md_chars_to_number (buf, THUMB_SIZE);
27339 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27340 newval |= (S << 10) | hi;
27341 newval2 &= ~T2I1I2MASK;
27342 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
27343 md_number_to_chars (buf, newval, THUMB_SIZE);
27344 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
27345}
27346
c19d1205 27347void
55cf6793 27348md_apply_fix (fixS * fixP,
c19d1205
ZW
27349 valueT * valP,
27350 segT seg)
27351{
27352 offsetT value = * valP;
27353 offsetT newval;
27354 unsigned int newimm;
27355 unsigned long temp;
27356 int sign;
27357 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 27358
9c2799c2 27359 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 27360
c19d1205 27361 /* Note whether this will delete the relocation. */
4962c51a 27362
c19d1205
ZW
27363 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
27364 fixP->fx_done = 1;
b99bd4ef 27365
adbaf948 27366 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 27367 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
27368 for emit_reloc. */
27369 value &= 0xffffffff;
27370 value ^= 0x80000000;
5f4273c7 27371 value -= 0x80000000;
adbaf948
ZW
27372
27373 *valP = value;
c19d1205 27374 fixP->fx_addnumber = value;
b99bd4ef 27375
adbaf948
ZW
27376 /* Same treatment for fixP->fx_offset. */
27377 fixP->fx_offset &= 0xffffffff;
27378 fixP->fx_offset ^= 0x80000000;
27379 fixP->fx_offset -= 0x80000000;
27380
c19d1205 27381 switch (fixP->fx_r_type)
b99bd4ef 27382 {
c19d1205
ZW
27383 case BFD_RELOC_NONE:
27384 /* This will need to go in the object file. */
27385 fixP->fx_done = 0;
27386 break;
b99bd4ef 27387
c19d1205
ZW
27388 case BFD_RELOC_ARM_IMMEDIATE:
27389 /* We claim that this fixup has been processed here,
27390 even if in fact we generate an error because we do
27391 not have a reloc for it, so tc_gen_reloc will reject it. */
27392 fixP->fx_done = 1;
b99bd4ef 27393
77db8e2e 27394 if (fixP->fx_addsy)
b99bd4ef 27395 {
77db8e2e 27396 const char *msg = 0;
b99bd4ef 27397
77db8e2e
NC
27398 if (! S_IS_DEFINED (fixP->fx_addsy))
27399 msg = _("undefined symbol %s used as an immediate value");
27400 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27401 msg = _("symbol %s is in a different section");
27402 else if (S_IS_WEAK (fixP->fx_addsy))
27403 msg = _("symbol %s is weak and may be overridden later");
27404
27405 if (msg)
27406 {
27407 as_bad_where (fixP->fx_file, fixP->fx_line,
27408 msg, S_GET_NAME (fixP->fx_addsy));
27409 break;
27410 }
42e5fcbf
AS
27411 }
27412
c19d1205
ZW
27413 temp = md_chars_to_number (buf, INSN_SIZE);
27414
5e73442d
SL
27415 /* If the offset is negative, we should use encoding A2 for ADR. */
27416 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
27417 newimm = negate_data_op (&temp, value);
27418 else
27419 {
27420 newimm = encode_arm_immediate (value);
27421
27422 /* If the instruction will fail, see if we can fix things up by
27423 changing the opcode. */
27424 if (newimm == (unsigned int) FAIL)
27425 newimm = negate_data_op (&temp, value);
bada4342
JW
27426 /* MOV accepts both ARM modified immediate (A1 encoding) and
27427 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
27428 When disassembling, MOV is preferred when there is no encoding
27429 overlap. */
27430 if (newimm == (unsigned int) FAIL
27431 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
27432 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
27433 && !((temp >> SBIT_SHIFT) & 0x1)
27434 && value >= 0 && value <= 0xffff)
27435 {
27436 /* Clear bits[23:20] to change encoding from A1 to A2. */
27437 temp &= 0xff0fffff;
27438 /* Encoding high 4bits imm. Code below will encode the remaining
27439 low 12bits. */
27440 temp |= (value & 0x0000f000) << 4;
27441 newimm = value & 0x00000fff;
27442 }
5e73442d
SL
27443 }
27444
27445 if (newimm == (unsigned int) FAIL)
b99bd4ef 27446 {
c19d1205
ZW
27447 as_bad_where (fixP->fx_file, fixP->fx_line,
27448 _("invalid constant (%lx) after fixup"),
27449 (unsigned long) value);
27450 break;
b99bd4ef 27451 }
b99bd4ef 27452
c19d1205
ZW
27453 newimm |= (temp & 0xfffff000);
27454 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27455 break;
b99bd4ef 27456
c19d1205
ZW
27457 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
27458 {
27459 unsigned int highpart = 0;
27460 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 27461
77db8e2e 27462 if (fixP->fx_addsy)
42e5fcbf 27463 {
77db8e2e 27464 const char *msg = 0;
42e5fcbf 27465
77db8e2e
NC
27466 if (! S_IS_DEFINED (fixP->fx_addsy))
27467 msg = _("undefined symbol %s used as an immediate value");
27468 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27469 msg = _("symbol %s is in a different section");
27470 else if (S_IS_WEAK (fixP->fx_addsy))
27471 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 27472
77db8e2e
NC
27473 if (msg)
27474 {
27475 as_bad_where (fixP->fx_file, fixP->fx_line,
27476 msg, S_GET_NAME (fixP->fx_addsy));
27477 break;
27478 }
27479 }
fa94de6b 27480
c19d1205
ZW
27481 newimm = encode_arm_immediate (value);
27482 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 27483
c19d1205
ZW
27484 /* If the instruction will fail, see if we can fix things up by
27485 changing the opcode. */
27486 if (newimm == (unsigned int) FAIL
27487 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
27488 {
27489 /* No ? OK - try using two ADD instructions to generate
27490 the value. */
27491 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 27492
c19d1205
ZW
27493 /* Yes - then make sure that the second instruction is
27494 also an add. */
27495 if (newimm != (unsigned int) FAIL)
27496 newinsn = temp;
27497 /* Still No ? Try using a negated value. */
27498 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
27499 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
27500 /* Otherwise - give up. */
27501 else
27502 {
27503 as_bad_where (fixP->fx_file, fixP->fx_line,
27504 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
27505 (long) value);
27506 break;
27507 }
b99bd4ef 27508
c19d1205
ZW
27509 /* Replace the first operand in the 2nd instruction (which
27510 is the PC) with the destination register. We have
27511 already added in the PC in the first instruction and we
27512 do not want to do it again. */
27513 newinsn &= ~ 0xf0000;
27514 newinsn |= ((newinsn & 0x0f000) << 4);
27515 }
b99bd4ef 27516
c19d1205
ZW
27517 newimm |= (temp & 0xfffff000);
27518 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 27519
c19d1205
ZW
27520 highpart |= (newinsn & 0xfffff000);
27521 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
27522 }
27523 break;
b99bd4ef 27524
c19d1205 27525 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
27526 if (!fixP->fx_done && seg->use_rela_p)
27527 value = 0;
1a0670f3 27528 /* Fall through. */
00a97672 27529
c19d1205 27530 case BFD_RELOC_ARM_LITERAL:
26d97720 27531 sign = value > 0;
b99bd4ef 27532
c19d1205
ZW
27533 if (value < 0)
27534 value = - value;
b99bd4ef 27535
c19d1205 27536 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 27537 {
c19d1205
ZW
27538 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
27539 as_bad_where (fixP->fx_file, fixP->fx_line,
27540 _("invalid literal constant: pool needs to be closer"));
27541 else
27542 as_bad_where (fixP->fx_file, fixP->fx_line,
27543 _("bad immediate value for offset (%ld)"),
27544 (long) value);
27545 break;
f03698e6
RE
27546 }
27547
c19d1205 27548 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
27549 if (value == 0)
27550 newval &= 0xfffff000;
27551 else
27552 {
27553 newval &= 0xff7ff000;
27554 newval |= value | (sign ? INDEX_UP : 0);
27555 }
c19d1205
ZW
27556 md_number_to_chars (buf, newval, INSN_SIZE);
27557 break;
b99bd4ef 27558
c19d1205
ZW
27559 case BFD_RELOC_ARM_OFFSET_IMM8:
27560 case BFD_RELOC_ARM_HWLITERAL:
26d97720 27561 sign = value > 0;
b99bd4ef 27562
c19d1205
ZW
27563 if (value < 0)
27564 value = - value;
b99bd4ef 27565
c19d1205 27566 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 27567 {
c19d1205
ZW
27568 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
27569 as_bad_where (fixP->fx_file, fixP->fx_line,
27570 _("invalid literal constant: pool needs to be closer"));
27571 else
427d0db6
RM
27572 as_bad_where (fixP->fx_file, fixP->fx_line,
27573 _("bad immediate value for 8-bit offset (%ld)"),
27574 (long) value);
c19d1205 27575 break;
b99bd4ef
NC
27576 }
27577
c19d1205 27578 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
27579 if (value == 0)
27580 newval &= 0xfffff0f0;
27581 else
27582 {
27583 newval &= 0xff7ff0f0;
27584 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
27585 }
c19d1205
ZW
27586 md_number_to_chars (buf, newval, INSN_SIZE);
27587 break;
b99bd4ef 27588
c19d1205
ZW
27589 case BFD_RELOC_ARM_T32_OFFSET_U8:
27590 if (value < 0 || value > 1020 || value % 4 != 0)
27591 as_bad_where (fixP->fx_file, fixP->fx_line,
27592 _("bad immediate value for offset (%ld)"), (long) value);
27593 value /= 4;
b99bd4ef 27594
c19d1205 27595 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
27596 newval |= value;
27597 md_number_to_chars (buf+2, newval, THUMB_SIZE);
27598 break;
b99bd4ef 27599
c19d1205
ZW
27600 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27601 /* This is a complicated relocation used for all varieties of Thumb32
27602 load/store instruction with immediate offset:
27603
27604 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 27605 *4, optional writeback(W)
c19d1205
ZW
27606 (doubleword load/store)
27607
27608 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
27609 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
27610 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
27611 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
27612 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
27613
27614 Uppercase letters indicate bits that are already encoded at
27615 this point. Lowercase letters are our problem. For the
27616 second block of instructions, the secondary opcode nybble
27617 (bits 8..11) is present, and bit 23 is zero, even if this is
27618 a PC-relative operation. */
27619 newval = md_chars_to_number (buf, THUMB_SIZE);
27620 newval <<= 16;
27621 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 27622
c19d1205 27623 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 27624 {
c19d1205
ZW
27625 /* Doubleword load/store: 8-bit offset, scaled by 4. */
27626 if (value >= 0)
27627 newval |= (1 << 23);
27628 else
27629 value = -value;
27630 if (value % 4 != 0)
27631 {
27632 as_bad_where (fixP->fx_file, fixP->fx_line,
27633 _("offset not a multiple of 4"));
27634 break;
27635 }
27636 value /= 4;
216d22bc 27637 if (value > 0xff)
c19d1205
ZW
27638 {
27639 as_bad_where (fixP->fx_file, fixP->fx_line,
27640 _("offset out of range"));
27641 break;
27642 }
27643 newval &= ~0xff;
b99bd4ef 27644 }
c19d1205 27645 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 27646 {
c19d1205
ZW
27647 /* PC-relative, 12-bit offset. */
27648 if (value >= 0)
27649 newval |= (1 << 23);
27650 else
27651 value = -value;
216d22bc 27652 if (value > 0xfff)
c19d1205
ZW
27653 {
27654 as_bad_where (fixP->fx_file, fixP->fx_line,
27655 _("offset out of range"));
27656 break;
27657 }
27658 newval &= ~0xfff;
b99bd4ef 27659 }
c19d1205 27660 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 27661 {
c19d1205
ZW
27662 /* Writeback: 8-bit, +/- offset. */
27663 if (value >= 0)
27664 newval |= (1 << 9);
27665 else
27666 value = -value;
216d22bc 27667 if (value > 0xff)
c19d1205
ZW
27668 {
27669 as_bad_where (fixP->fx_file, fixP->fx_line,
27670 _("offset out of range"));
27671 break;
27672 }
27673 newval &= ~0xff;
b99bd4ef 27674 }
c19d1205 27675 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 27676 {
c19d1205 27677 /* T-instruction: positive 8-bit offset. */
216d22bc 27678 if (value < 0 || value > 0xff)
b99bd4ef 27679 {
c19d1205
ZW
27680 as_bad_where (fixP->fx_file, fixP->fx_line,
27681 _("offset out of range"));
27682 break;
b99bd4ef 27683 }
c19d1205
ZW
27684 newval &= ~0xff;
27685 newval |= value;
b99bd4ef
NC
27686 }
27687 else
b99bd4ef 27688 {
c19d1205
ZW
27689 /* Positive 12-bit or negative 8-bit offset. */
27690 int limit;
27691 if (value >= 0)
b99bd4ef 27692 {
c19d1205
ZW
27693 newval |= (1 << 23);
27694 limit = 0xfff;
27695 }
27696 else
27697 {
27698 value = -value;
27699 limit = 0xff;
27700 }
27701 if (value > limit)
27702 {
27703 as_bad_where (fixP->fx_file, fixP->fx_line,
27704 _("offset out of range"));
27705 break;
b99bd4ef 27706 }
c19d1205 27707 newval &= ~limit;
b99bd4ef 27708 }
b99bd4ef 27709
c19d1205
ZW
27710 newval |= value;
27711 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
27712 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
27713 break;
404ff6b5 27714
c19d1205
ZW
27715 case BFD_RELOC_ARM_SHIFT_IMM:
27716 newval = md_chars_to_number (buf, INSN_SIZE);
27717 if (((unsigned long) value) > 32
27718 || (value == 32
27719 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
27720 {
27721 as_bad_where (fixP->fx_file, fixP->fx_line,
27722 _("shift expression is too large"));
27723 break;
27724 }
404ff6b5 27725
c19d1205
ZW
27726 if (value == 0)
27727 /* Shifts of zero must be done as lsl. */
27728 newval &= ~0x60;
27729 else if (value == 32)
27730 value = 0;
27731 newval &= 0xfffff07f;
27732 newval |= (value & 0x1f) << 7;
27733 md_number_to_chars (buf, newval, INSN_SIZE);
27734 break;
404ff6b5 27735
c19d1205 27736 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 27737 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 27738 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 27739 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
27740 /* We claim that this fixup has been processed here,
27741 even if in fact we generate an error because we do
27742 not have a reloc for it, so tc_gen_reloc will reject it. */
27743 fixP->fx_done = 1;
404ff6b5 27744
c19d1205
ZW
27745 if (fixP->fx_addsy
27746 && ! S_IS_DEFINED (fixP->fx_addsy))
27747 {
27748 as_bad_where (fixP->fx_file, fixP->fx_line,
27749 _("undefined symbol %s used as an immediate value"),
27750 S_GET_NAME (fixP->fx_addsy));
27751 break;
27752 }
404ff6b5 27753
c19d1205
ZW
27754 newval = md_chars_to_number (buf, THUMB_SIZE);
27755 newval <<= 16;
27756 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 27757
16805f35 27758 newimm = FAIL;
bada4342
JW
27759 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
27760 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
27761 Thumb2 modified immediate encoding (T2). */
27762 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 27763 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
27764 {
27765 newimm = encode_thumb32_immediate (value);
27766 if (newimm == (unsigned int) FAIL)
27767 newimm = thumb32_negate_data_op (&newval, value);
27768 }
bada4342 27769 if (newimm == (unsigned int) FAIL)
92e90b6e 27770 {
bada4342 27771 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 27772 {
bada4342
JW
27773 /* Turn add/sum into addw/subw. */
27774 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
27775 newval = (newval & 0xfeffffff) | 0x02000000;
27776 /* No flat 12-bit imm encoding for addsw/subsw. */
27777 if ((newval & 0x00100000) == 0)
40f246e3 27778 {
bada4342
JW
27779 /* 12 bit immediate for addw/subw. */
27780 if (value < 0)
27781 {
27782 value = -value;
27783 newval ^= 0x00a00000;
27784 }
27785 if (value > 0xfff)
27786 newimm = (unsigned int) FAIL;
27787 else
27788 newimm = value;
27789 }
27790 }
27791 else
27792 {
27793 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
27794 UINT16 (T3 encoding), MOVW only accepts UINT16. When
27795 disassembling, MOV is preferred when there is no encoding
db7bf105 27796 overlap. */
bada4342 27797 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
27798 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
27799 but with the Rn field [19:16] set to 1111. */
27800 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
27801 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
27802 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 27803 && value >= 0 && value <= 0xffff)
bada4342
JW
27804 {
27805 /* Toggle bit[25] to change encoding from T2 to T3. */
27806 newval ^= 1 << 25;
27807 /* Clear bits[19:16]. */
27808 newval &= 0xfff0ffff;
27809 /* Encoding high 4bits imm. Code below will encode the
27810 remaining low 12bits. */
27811 newval |= (value & 0x0000f000) << 4;
27812 newimm = value & 0x00000fff;
40f246e3 27813 }
e9f89963 27814 }
92e90b6e 27815 }
cc8a6dd0 27816
c19d1205 27817 if (newimm == (unsigned int)FAIL)
3631a3c8 27818 {
c19d1205
ZW
27819 as_bad_where (fixP->fx_file, fixP->fx_line,
27820 _("invalid constant (%lx) after fixup"),
27821 (unsigned long) value);
27822 break;
3631a3c8
NC
27823 }
27824
c19d1205
ZW
27825 newval |= (newimm & 0x800) << 15;
27826 newval |= (newimm & 0x700) << 4;
27827 newval |= (newimm & 0x0ff);
cc8a6dd0 27828
c19d1205
ZW
27829 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
27830 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
27831 break;
a737bd4d 27832
3eb17e6b 27833 case BFD_RELOC_ARM_SMC:
ba85f98c 27834 if (((unsigned long) value) > 0xf)
c19d1205 27835 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 27836 _("invalid smc expression"));
ba85f98c 27837
2fc8bdac 27838 newval = md_chars_to_number (buf, INSN_SIZE);
ba85f98c 27839 newval |= (value & 0xf);
c19d1205
ZW
27840 md_number_to_chars (buf, newval, INSN_SIZE);
27841 break;
a737bd4d 27842
90ec0d68
MGD
27843 case BFD_RELOC_ARM_HVC:
27844 if (((unsigned long) value) > 0xffff)
27845 as_bad_where (fixP->fx_file, fixP->fx_line,
27846 _("invalid hvc expression"));
27847 newval = md_chars_to_number (buf, INSN_SIZE);
27848 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
27849 md_number_to_chars (buf, newval, INSN_SIZE);
27850 break;
27851
c19d1205 27852 case BFD_RELOC_ARM_SWI:
adbaf948 27853 if (fixP->tc_fix_data != 0)
c19d1205
ZW
27854 {
27855 if (((unsigned long) value) > 0xff)
27856 as_bad_where (fixP->fx_file, fixP->fx_line,
27857 _("invalid swi expression"));
2fc8bdac 27858 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
27859 newval |= value;
27860 md_number_to_chars (buf, newval, THUMB_SIZE);
27861 }
27862 else
27863 {
27864 if (((unsigned long) value) > 0x00ffffff)
27865 as_bad_where (fixP->fx_file, fixP->fx_line,
27866 _("invalid swi expression"));
2fc8bdac 27867 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
27868 newval |= value;
27869 md_number_to_chars (buf, newval, INSN_SIZE);
27870 }
27871 break;
a737bd4d 27872
c19d1205
ZW
27873 case BFD_RELOC_ARM_MULTI:
27874 if (((unsigned long) value) > 0xffff)
27875 as_bad_where (fixP->fx_file, fixP->fx_line,
27876 _("invalid expression in load/store multiple"));
27877 newval = value | md_chars_to_number (buf, INSN_SIZE);
27878 md_number_to_chars (buf, newval, INSN_SIZE);
27879 break;
a737bd4d 27880
c19d1205 27881#ifdef OBJ_ELF
39b41c9c 27882 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
27883
27884 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27885 && fixP->fx_addsy
34e77a92 27886 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27887 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27888 && THUMB_IS_FUNC (fixP->fx_addsy))
27889 /* Flip the bl to blx. This is a simple flip
27890 bit here because we generate PCREL_CALL for
27891 unconditional bls. */
27892 {
27893 newval = md_chars_to_number (buf, INSN_SIZE);
27894 newval = newval | 0x10000000;
27895 md_number_to_chars (buf, newval, INSN_SIZE);
27896 temp = 1;
27897 fixP->fx_done = 1;
27898 }
39b41c9c
PB
27899 else
27900 temp = 3;
27901 goto arm_branch_common;
27902
27903 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
27904 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27905 && fixP->fx_addsy
34e77a92 27906 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27907 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27908 && THUMB_IS_FUNC (fixP->fx_addsy))
27909 {
27910 /* This would map to a bl<cond>, b<cond>,
27911 b<always> to a Thumb function. We
27912 need to force a relocation for this particular
27913 case. */
27914 newval = md_chars_to_number (buf, INSN_SIZE);
27915 fixP->fx_done = 0;
27916 }
1a0670f3 27917 /* Fall through. */
267bf995 27918
2fc8bdac 27919 case BFD_RELOC_ARM_PLT32:
c19d1205 27920#endif
39b41c9c
PB
27921 case BFD_RELOC_ARM_PCREL_BRANCH:
27922 temp = 3;
27923 goto arm_branch_common;
a737bd4d 27924
39b41c9c 27925 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 27926
39b41c9c 27927 temp = 1;
267bf995
RR
27928 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27929 && fixP->fx_addsy
34e77a92 27930 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27931 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27932 && ARM_IS_FUNC (fixP->fx_addsy))
27933 {
27934 /* Flip the blx to a bl and warn. */
27935 const char *name = S_GET_NAME (fixP->fx_addsy);
27936 newval = 0xeb000000;
27937 as_warn_where (fixP->fx_file, fixP->fx_line,
27938 _("blx to '%s' an ARM ISA state function changed to bl"),
27939 name);
27940 md_number_to_chars (buf, newval, INSN_SIZE);
27941 temp = 3;
27942 fixP->fx_done = 1;
27943 }
27944
27945#ifdef OBJ_ELF
27946 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 27947 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
27948#endif
27949
39b41c9c 27950 arm_branch_common:
c19d1205 27951 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
27952 instruction, in a 24 bit, signed field. Bits 26 through 32 either
27953 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 27954 also be clear. */
39b41c9c 27955 if (value & temp)
c19d1205 27956 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
27957 _("misaligned branch destination"));
27958 if ((value & (offsetT)0xfe000000) != (offsetT)0
27959 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 27960 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 27961
2fc8bdac 27962 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 27963 {
2fc8bdac
ZW
27964 newval = md_chars_to_number (buf, INSN_SIZE);
27965 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
27966 /* Set the H bit on BLX instructions. */
27967 if (temp == 1)
27968 {
27969 if (value & 2)
27970 newval |= 0x01000000;
27971 else
27972 newval &= ~0x01000000;
27973 }
2fc8bdac 27974 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 27975 }
c19d1205 27976 break;
a737bd4d 27977
25fe350b
MS
27978 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
27979 /* CBZ can only branch forward. */
a737bd4d 27980
738755b0 27981 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
27982 (which, strictly speaking, are prohibited) will be turned into
27983 no-ops.
738755b0
MS
27984
27985 FIXME: It may be better to remove the instruction completely and
27986 perform relaxation. */
27987 if (value == -2)
2fc8bdac
ZW
27988 {
27989 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 27990 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
27991 md_number_to_chars (buf, newval, THUMB_SIZE);
27992 }
738755b0
MS
27993 else
27994 {
27995 if (value & ~0x7e)
08f10d51 27996 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 27997
477330fc 27998 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
27999 {
28000 newval = md_chars_to_number (buf, THUMB_SIZE);
28001 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28002 md_number_to_chars (buf, newval, THUMB_SIZE);
28003 }
28004 }
c19d1205 28005 break;
a737bd4d 28006
c19d1205 28007 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 28008 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 28009 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28010
2fc8bdac
ZW
28011 if (fixP->fx_done || !seg->use_rela_p)
28012 {
28013 newval = md_chars_to_number (buf, THUMB_SIZE);
28014 newval |= (value & 0x1ff) >> 1;
28015 md_number_to_chars (buf, newval, THUMB_SIZE);
28016 }
c19d1205 28017 break;
a737bd4d 28018
c19d1205 28019 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 28020 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 28021 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28022
2fc8bdac
ZW
28023 if (fixP->fx_done || !seg->use_rela_p)
28024 {
28025 newval = md_chars_to_number (buf, THUMB_SIZE);
28026 newval |= (value & 0xfff) >> 1;
28027 md_number_to_chars (buf, newval, THUMB_SIZE);
28028 }
c19d1205 28029 break;
a737bd4d 28030
c19d1205 28031 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
28032 if (fixP->fx_addsy
28033 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28034 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28035 && ARM_IS_FUNC (fixP->fx_addsy)
28036 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28037 {
28038 /* Force a relocation for a branch 20 bits wide. */
28039 fixP->fx_done = 0;
28040 }
08f10d51 28041 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
28042 as_bad_where (fixP->fx_file, fixP->fx_line,
28043 _("conditional branch out of range"));
404ff6b5 28044
2fc8bdac
ZW
28045 if (fixP->fx_done || !seg->use_rela_p)
28046 {
28047 offsetT newval2;
28048 addressT S, J1, J2, lo, hi;
404ff6b5 28049
2fc8bdac
ZW
28050 S = (value & 0x00100000) >> 20;
28051 J2 = (value & 0x00080000) >> 19;
28052 J1 = (value & 0x00040000) >> 18;
28053 hi = (value & 0x0003f000) >> 12;
28054 lo = (value & 0x00000ffe) >> 1;
6c43fab6 28055
2fc8bdac
ZW
28056 newval = md_chars_to_number (buf, THUMB_SIZE);
28057 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28058 newval |= (S << 10) | hi;
28059 newval2 |= (J1 << 13) | (J2 << 11) | lo;
28060 md_number_to_chars (buf, newval, THUMB_SIZE);
28061 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28062 }
c19d1205 28063 break;
6c43fab6 28064
c19d1205 28065 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
28066 /* If there is a blx from a thumb state function to
28067 another thumb function flip this to a bl and warn
28068 about it. */
28069
28070 if (fixP->fx_addsy
34e77a92 28071 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28072 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28073 && THUMB_IS_FUNC (fixP->fx_addsy))
28074 {
28075 const char *name = S_GET_NAME (fixP->fx_addsy);
28076 as_warn_where (fixP->fx_file, fixP->fx_line,
28077 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
28078 name);
28079 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28080 newval = newval | 0x1000;
28081 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28082 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28083 fixP->fx_done = 1;
28084 }
28085
28086
28087 goto thumb_bl_common;
28088
c19d1205 28089 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
28090 /* A bl from Thumb state ISA to an internal ARM state function
28091 is converted to a blx. */
28092 if (fixP->fx_addsy
28093 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28094 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28095 && ARM_IS_FUNC (fixP->fx_addsy)
28096 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28097 {
28098 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28099 newval = newval & ~0x1000;
28100 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28101 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
28102 fixP->fx_done = 1;
28103 }
28104
28105 thumb_bl_common:
28106
2fc8bdac
ZW
28107 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28108 /* For a BLX instruction, make sure that the relocation is rounded up
28109 to a word boundary. This follows the semantics of the instruction
28110 which specifies that bit 1 of the target address will come from bit
28111 1 of the base address. */
d406f3e4
JB
28112 value = (value + 3) & ~ 3;
28113
28114#ifdef OBJ_ELF
28115 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
28116 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28117 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28118#endif
404ff6b5 28119
2b2f5df9
NC
28120 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
28121 {
fc289b0a 28122 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
28123 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28124 else if ((value & ~0x1ffffff)
28125 && ((value & ~0x1ffffff) != ~0x1ffffff))
28126 as_bad_where (fixP->fx_file, fixP->fx_line,
28127 _("Thumb2 branch out of range"));
28128 }
4a42ebbc
RR
28129
28130 if (fixP->fx_done || !seg->use_rela_p)
28131 encode_thumb2_b_bl_offset (buf, value);
28132
c19d1205 28133 break;
404ff6b5 28134
c19d1205 28135 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
28136 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
28137 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 28138
2fc8bdac 28139 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 28140 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 28141
2fc8bdac 28142 break;
a737bd4d 28143
2fc8bdac
ZW
28144 case BFD_RELOC_8:
28145 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 28146 *buf = value;
c19d1205 28147 break;
a737bd4d 28148
c19d1205 28149 case BFD_RELOC_16:
2fc8bdac 28150 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28151 md_number_to_chars (buf, value, 2);
c19d1205 28152 break;
a737bd4d 28153
c19d1205 28154#ifdef OBJ_ELF
0855e32b
NS
28155 case BFD_RELOC_ARM_TLS_CALL:
28156 case BFD_RELOC_ARM_THM_TLS_CALL:
28157 case BFD_RELOC_ARM_TLS_DESCSEQ:
28158 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 28159 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
28160 case BFD_RELOC_ARM_TLS_GD32:
28161 case BFD_RELOC_ARM_TLS_LE32:
28162 case BFD_RELOC_ARM_TLS_IE32:
28163 case BFD_RELOC_ARM_TLS_LDM32:
28164 case BFD_RELOC_ARM_TLS_LDO32:
28165 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 28166 break;
6c43fab6 28167
5c5a4843
CL
28168 /* Same handling as above, but with the arm_fdpic guard. */
28169 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
28170 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
28171 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
28172 if (arm_fdpic)
28173 {
28174 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28175 }
28176 else
28177 {
28178 as_bad_where (fixP->fx_file, fixP->fx_line,
28179 _("Relocation supported only in FDPIC mode"));
28180 }
28181 break;
28182
c19d1205
ZW
28183 case BFD_RELOC_ARM_GOT32:
28184 case BFD_RELOC_ARM_GOTOFF:
c19d1205 28185 break;
b43420e6
NC
28186
28187 case BFD_RELOC_ARM_GOT_PREL:
28188 if (fixP->fx_done || !seg->use_rela_p)
477330fc 28189 md_number_to_chars (buf, value, 4);
b43420e6
NC
28190 break;
28191
9a6f4e97
NS
28192 case BFD_RELOC_ARM_TARGET2:
28193 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
28194 addend here for REL targets, because it won't be written out
28195 during reloc processing later. */
9a6f4e97
NS
28196 if (fixP->fx_done || !seg->use_rela_p)
28197 md_number_to_chars (buf, fixP->fx_offset, 4);
28198 break;
188fd7ae
CL
28199
28200 /* Relocations for FDPIC. */
28201 case BFD_RELOC_ARM_GOTFUNCDESC:
28202 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
28203 case BFD_RELOC_ARM_FUNCDESC:
28204 if (arm_fdpic)
28205 {
28206 if (fixP->fx_done || !seg->use_rela_p)
28207 md_number_to_chars (buf, 0, 4);
28208 }
28209 else
28210 {
28211 as_bad_where (fixP->fx_file, fixP->fx_line,
28212 _("Relocation supported only in FDPIC mode"));
28213 }
28214 break;
c19d1205 28215#endif
6c43fab6 28216
c19d1205
ZW
28217 case BFD_RELOC_RVA:
28218 case BFD_RELOC_32:
28219 case BFD_RELOC_ARM_TARGET1:
28220 case BFD_RELOC_ARM_ROSEGREL32:
28221 case BFD_RELOC_ARM_SBREL32:
28222 case BFD_RELOC_32_PCREL:
f0927246
NC
28223#ifdef TE_PE
28224 case BFD_RELOC_32_SECREL:
28225#endif
2fc8bdac 28226 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
28227#ifdef TE_WINCE
28228 /* For WinCE we only do this for pcrel fixups. */
28229 if (fixP->fx_done || fixP->fx_pcrel)
28230#endif
28231 md_number_to_chars (buf, value, 4);
c19d1205 28232 break;
6c43fab6 28233
c19d1205
ZW
28234#ifdef OBJ_ELF
28235 case BFD_RELOC_ARM_PREL31:
2fc8bdac 28236 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
28237 {
28238 newval = md_chars_to_number (buf, 4) & 0x80000000;
28239 if ((value ^ (value >> 1)) & 0x40000000)
28240 {
28241 as_bad_where (fixP->fx_file, fixP->fx_line,
28242 _("rel31 relocation overflow"));
28243 }
28244 newval |= value & 0x7fffffff;
28245 md_number_to_chars (buf, newval, 4);
28246 }
28247 break;
c19d1205 28248#endif
a737bd4d 28249
c19d1205 28250 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 28251 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 28252 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
28253 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
28254 newval = md_chars_to_number (buf, INSN_SIZE);
28255 else
28256 newval = get_thumb32_insn (buf);
28257 if ((newval & 0x0f200f00) == 0x0d000900)
28258 {
28259 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
28260 has permitted values that are multiples of 2, in the range 0
28261 to 510. */
28262 if (value < -510 || value > 510 || (value & 1))
28263 as_bad_where (fixP->fx_file, fixP->fx_line,
28264 _("co-processor offset out of range"));
28265 }
32c36c3c
AV
28266 else if ((newval & 0xfe001f80) == 0xec000f80)
28267 {
28268 if (value < -511 || value > 512 || (value & 3))
28269 as_bad_where (fixP->fx_file, fixP->fx_line,
28270 _("co-processor offset out of range"));
28271 }
9db2f6b4 28272 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
28273 as_bad_where (fixP->fx_file, fixP->fx_line,
28274 _("co-processor offset out of range"));
28275 cp_off_common:
26d97720 28276 sign = value > 0;
c19d1205
ZW
28277 if (value < 0)
28278 value = -value;
8f06b2d8
PB
28279 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28280 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28281 newval = md_chars_to_number (buf, INSN_SIZE);
28282 else
28283 newval = get_thumb32_insn (buf);
26d97720 28284 if (value == 0)
32c36c3c
AV
28285 {
28286 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28287 newval &= 0xffffff80;
28288 else
28289 newval &= 0xffffff00;
28290 }
26d97720
NS
28291 else
28292 {
32c36c3c
AV
28293 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28294 newval &= 0xff7fff80;
28295 else
28296 newval &= 0xff7fff00;
9db2f6b4
RL
28297 if ((newval & 0x0f200f00) == 0x0d000900)
28298 {
28299 /* This is a fp16 vstr/vldr.
28300
28301 It requires the immediate offset in the instruction is shifted
28302 left by 1 to be a half-word offset.
28303
28304 Here, left shift by 1 first, and later right shift by 2
28305 should get the right offset. */
28306 value <<= 1;
28307 }
26d97720
NS
28308 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
28309 }
8f06b2d8
PB
28310 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28311 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28312 md_number_to_chars (buf, newval, INSN_SIZE);
28313 else
28314 put_thumb32_insn (buf, newval);
c19d1205 28315 break;
a737bd4d 28316
c19d1205 28317 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 28318 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
28319 if (value < -255 || value > 255)
28320 as_bad_where (fixP->fx_file, fixP->fx_line,
28321 _("co-processor offset out of range"));
df7849c5 28322 value *= 4;
c19d1205 28323 goto cp_off_common;
6c43fab6 28324
c19d1205
ZW
28325 case BFD_RELOC_ARM_THUMB_OFFSET:
28326 newval = md_chars_to_number (buf, THUMB_SIZE);
28327 /* Exactly what ranges, and where the offset is inserted depends
28328 on the type of instruction, we can establish this from the
28329 top 4 bits. */
28330 switch (newval >> 12)
28331 {
28332 case 4: /* PC load. */
28333 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
28334 forced to zero for these loads; md_pcrel_from has already
28335 compensated for this. */
28336 if (value & 3)
28337 as_bad_where (fixP->fx_file, fixP->fx_line,
28338 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
28339 (((unsigned long) fixP->fx_frag->fr_address
28340 + (unsigned long) fixP->fx_where) & ~3)
28341 + (unsigned long) value);
a737bd4d 28342
c19d1205
ZW
28343 if (value & ~0x3fc)
28344 as_bad_where (fixP->fx_file, fixP->fx_line,
28345 _("invalid offset, value too big (0x%08lX)"),
28346 (long) value);
a737bd4d 28347
c19d1205
ZW
28348 newval |= value >> 2;
28349 break;
a737bd4d 28350
c19d1205
ZW
28351 case 9: /* SP load/store. */
28352 if (value & ~0x3fc)
28353 as_bad_where (fixP->fx_file, fixP->fx_line,
28354 _("invalid offset, value too big (0x%08lX)"),
28355 (long) value);
28356 newval |= value >> 2;
28357 break;
6c43fab6 28358
c19d1205
ZW
28359 case 6: /* Word load/store. */
28360 if (value & ~0x7c)
28361 as_bad_where (fixP->fx_file, fixP->fx_line,
28362 _("invalid offset, value too big (0x%08lX)"),
28363 (long) value);
28364 newval |= value << 4; /* 6 - 2. */
28365 break;
a737bd4d 28366
c19d1205
ZW
28367 case 7: /* Byte load/store. */
28368 if (value & ~0x1f)
28369 as_bad_where (fixP->fx_file, fixP->fx_line,
28370 _("invalid offset, value too big (0x%08lX)"),
28371 (long) value);
28372 newval |= value << 6;
28373 break;
a737bd4d 28374
c19d1205
ZW
28375 case 8: /* Halfword load/store. */
28376 if (value & ~0x3e)
28377 as_bad_where (fixP->fx_file, fixP->fx_line,
28378 _("invalid offset, value too big (0x%08lX)"),
28379 (long) value);
28380 newval |= value << 5; /* 6 - 1. */
28381 break;
a737bd4d 28382
c19d1205
ZW
28383 default:
28384 as_bad_where (fixP->fx_file, fixP->fx_line,
28385 "Unable to process relocation for thumb opcode: %lx",
28386 (unsigned long) newval);
28387 break;
28388 }
28389 md_number_to_chars (buf, newval, THUMB_SIZE);
28390 break;
a737bd4d 28391
c19d1205
ZW
28392 case BFD_RELOC_ARM_THUMB_ADD:
28393 /* This is a complicated relocation, since we use it for all of
28394 the following immediate relocations:
a737bd4d 28395
c19d1205
ZW
28396 3bit ADD/SUB
28397 8bit ADD/SUB
28398 9bit ADD/SUB SP word-aligned
28399 10bit ADD PC/SP word-aligned
a737bd4d 28400
c19d1205
ZW
28401 The type of instruction being processed is encoded in the
28402 instruction field:
a737bd4d 28403
c19d1205
ZW
28404 0x8000 SUB
28405 0x00F0 Rd
28406 0x000F Rs
28407 */
28408 newval = md_chars_to_number (buf, THUMB_SIZE);
28409 {
28410 int rd = (newval >> 4) & 0xf;
28411 int rs = newval & 0xf;
28412 int subtract = !!(newval & 0x8000);
a737bd4d 28413
c19d1205
ZW
28414 /* Check for HI regs, only very restricted cases allowed:
28415 Adjusting SP, and using PC or SP to get an address. */
28416 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
28417 || (rs > 7 && rs != REG_SP && rs != REG_PC))
28418 as_bad_where (fixP->fx_file, fixP->fx_line,
28419 _("invalid Hi register with immediate"));
a737bd4d 28420
c19d1205
ZW
28421 /* If value is negative, choose the opposite instruction. */
28422 if (value < 0)
28423 {
28424 value = -value;
28425 subtract = !subtract;
28426 if (value < 0)
28427 as_bad_where (fixP->fx_file, fixP->fx_line,
28428 _("immediate value out of range"));
28429 }
a737bd4d 28430
c19d1205
ZW
28431 if (rd == REG_SP)
28432 {
75c11999 28433 if (value & ~0x1fc)
c19d1205
ZW
28434 as_bad_where (fixP->fx_file, fixP->fx_line,
28435 _("invalid immediate for stack address calculation"));
28436 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
28437 newval |= value >> 2;
28438 }
28439 else if (rs == REG_PC || rs == REG_SP)
28440 {
c12d2c9d
NC
28441 /* PR gas/18541. If the addition is for a defined symbol
28442 within range of an ADR instruction then accept it. */
28443 if (subtract
28444 && value == 4
28445 && fixP->fx_addsy != NULL)
28446 {
28447 subtract = 0;
28448
28449 if (! S_IS_DEFINED (fixP->fx_addsy)
28450 || S_GET_SEGMENT (fixP->fx_addsy) != seg
28451 || S_IS_WEAK (fixP->fx_addsy))
28452 {
28453 as_bad_where (fixP->fx_file, fixP->fx_line,
28454 _("address calculation needs a strongly defined nearby symbol"));
28455 }
28456 else
28457 {
28458 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
28459
28460 /* Round up to the next 4-byte boundary. */
28461 if (v & 3)
28462 v = (v + 3) & ~ 3;
28463 else
28464 v += 4;
28465 v = S_GET_VALUE (fixP->fx_addsy) - v;
28466
28467 if (v & ~0x3fc)
28468 {
28469 as_bad_where (fixP->fx_file, fixP->fx_line,
28470 _("symbol too far away"));
28471 }
28472 else
28473 {
28474 fixP->fx_done = 1;
28475 value = v;
28476 }
28477 }
28478 }
28479
c19d1205
ZW
28480 if (subtract || value & ~0x3fc)
28481 as_bad_where (fixP->fx_file, fixP->fx_line,
28482 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 28483 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
28484 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
28485 newval |= rd << 8;
28486 newval |= value >> 2;
28487 }
28488 else if (rs == rd)
28489 {
28490 if (value & ~0xff)
28491 as_bad_where (fixP->fx_file, fixP->fx_line,
28492 _("immediate value out of range"));
28493 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
28494 newval |= (rd << 8) | value;
28495 }
28496 else
28497 {
28498 if (value & ~0x7)
28499 as_bad_where (fixP->fx_file, fixP->fx_line,
28500 _("immediate value out of range"));
28501 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
28502 newval |= rd | (rs << 3) | (value << 6);
28503 }
28504 }
28505 md_number_to_chars (buf, newval, THUMB_SIZE);
28506 break;
a737bd4d 28507
c19d1205
ZW
28508 case BFD_RELOC_ARM_THUMB_IMM:
28509 newval = md_chars_to_number (buf, THUMB_SIZE);
28510 if (value < 0 || value > 255)
28511 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 28512 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
28513 (long) value);
28514 newval |= value;
28515 md_number_to_chars (buf, newval, THUMB_SIZE);
28516 break;
a737bd4d 28517
c19d1205
ZW
28518 case BFD_RELOC_ARM_THUMB_SHIFT:
28519 /* 5bit shift value (0..32). LSL cannot take 32. */
28520 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
28521 temp = newval & 0xf800;
28522 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
28523 as_bad_where (fixP->fx_file, fixP->fx_line,
28524 _("invalid shift value: %ld"), (long) value);
28525 /* Shifts of zero must be encoded as LSL. */
28526 if (value == 0)
28527 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
28528 /* Shifts of 32 are encoded as zero. */
28529 else if (value == 32)
28530 value = 0;
28531 newval |= value << 6;
28532 md_number_to_chars (buf, newval, THUMB_SIZE);
28533 break;
a737bd4d 28534
c19d1205
ZW
28535 case BFD_RELOC_VTABLE_INHERIT:
28536 case BFD_RELOC_VTABLE_ENTRY:
28537 fixP->fx_done = 0;
28538 return;
6c43fab6 28539
b6895b4f
PB
28540 case BFD_RELOC_ARM_MOVW:
28541 case BFD_RELOC_ARM_MOVT:
28542 case BFD_RELOC_ARM_THUMB_MOVW:
28543 case BFD_RELOC_ARM_THUMB_MOVT:
28544 if (fixP->fx_done || !seg->use_rela_p)
28545 {
28546 /* REL format relocations are limited to a 16-bit addend. */
28547 if (!fixP->fx_done)
28548 {
39623e12 28549 if (value < -0x8000 || value > 0x7fff)
b6895b4f 28550 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 28551 _("offset out of range"));
b6895b4f
PB
28552 }
28553 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
28554 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28555 {
28556 value >>= 16;
28557 }
28558
28559 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
28560 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28561 {
28562 newval = get_thumb32_insn (buf);
28563 newval &= 0xfbf08f00;
28564 newval |= (value & 0xf000) << 4;
28565 newval |= (value & 0x0800) << 15;
28566 newval |= (value & 0x0700) << 4;
28567 newval |= (value & 0x00ff);
28568 put_thumb32_insn (buf, newval);
28569 }
28570 else
28571 {
28572 newval = md_chars_to_number (buf, 4);
28573 newval &= 0xfff0f000;
28574 newval |= value & 0x0fff;
28575 newval |= (value & 0xf000) << 4;
28576 md_number_to_chars (buf, newval, 4);
28577 }
28578 }
28579 return;
28580
72d98d16
MG
28581 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
28582 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
28583 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
28584 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
28585 gas_assert (!fixP->fx_done);
28586 {
28587 bfd_vma insn;
28588 bfd_boolean is_mov;
28589 bfd_vma encoded_addend = value;
28590
28591 /* Check that addend can be encoded in instruction. */
28592 if (!seg->use_rela_p && (value < 0 || value > 255))
28593 as_bad_where (fixP->fx_file, fixP->fx_line,
28594 _("the offset 0x%08lX is not representable"),
28595 (unsigned long) encoded_addend);
28596
28597 /* Extract the instruction. */
28598 insn = md_chars_to_number (buf, THUMB_SIZE);
28599 is_mov = (insn & 0xf800) == 0x2000;
28600
28601 /* Encode insn. */
28602 if (is_mov)
28603 {
28604 if (!seg->use_rela_p)
28605 insn |= encoded_addend;
28606 }
28607 else
28608 {
28609 int rd, rs;
28610
28611 /* Extract the instruction. */
28612 /* Encoding is the following
28613 0x8000 SUB
28614 0x00F0 Rd
28615 0x000F Rs
28616 */
28617 /* The following conditions must be true :
28618 - ADD
28619 - Rd == Rs
28620 - Rd <= 7
28621 */
28622 rd = (insn >> 4) & 0xf;
28623 rs = insn & 0xf;
28624 if ((insn & 0x8000) || (rd != rs) || rd > 7)
28625 as_bad_where (fixP->fx_file, fixP->fx_line,
28626 _("Unable to process relocation for thumb opcode: %lx"),
28627 (unsigned long) insn);
28628
28629 /* Encode as ADD immediate8 thumb 1 code. */
28630 insn = 0x3000 | (rd << 8);
28631
28632 /* Place the encoded addend into the first 8 bits of the
28633 instruction. */
28634 if (!seg->use_rela_p)
28635 insn |= encoded_addend;
28636 }
28637
28638 /* Update the instruction. */
28639 md_number_to_chars (buf, insn, THUMB_SIZE);
28640 }
28641 break;
28642
4962c51a
MS
28643 case BFD_RELOC_ARM_ALU_PC_G0_NC:
28644 case BFD_RELOC_ARM_ALU_PC_G0:
28645 case BFD_RELOC_ARM_ALU_PC_G1_NC:
28646 case BFD_RELOC_ARM_ALU_PC_G1:
28647 case BFD_RELOC_ARM_ALU_PC_G2:
28648 case BFD_RELOC_ARM_ALU_SB_G0_NC:
28649 case BFD_RELOC_ARM_ALU_SB_G0:
28650 case BFD_RELOC_ARM_ALU_SB_G1_NC:
28651 case BFD_RELOC_ARM_ALU_SB_G1:
28652 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 28653 gas_assert (!fixP->fx_done);
4962c51a
MS
28654 if (!seg->use_rela_p)
28655 {
477330fc
RM
28656 bfd_vma insn;
28657 bfd_vma encoded_addend;
3ca4a8ec 28658 bfd_vma addend_abs = llabs (value);
477330fc
RM
28659
28660 /* Check that the absolute value of the addend can be
28661 expressed as an 8-bit constant plus a rotation. */
28662 encoded_addend = encode_arm_immediate (addend_abs);
28663 if (encoded_addend == (unsigned int) FAIL)
4962c51a 28664 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28665 _("the offset 0x%08lX is not representable"),
28666 (unsigned long) addend_abs);
28667
28668 /* Extract the instruction. */
28669 insn = md_chars_to_number (buf, INSN_SIZE);
28670
28671 /* If the addend is positive, use an ADD instruction.
28672 Otherwise use a SUB. Take care not to destroy the S bit. */
28673 insn &= 0xff1fffff;
28674 if (value < 0)
28675 insn |= 1 << 22;
28676 else
28677 insn |= 1 << 23;
28678
28679 /* Place the encoded addend into the first 12 bits of the
28680 instruction. */
28681 insn &= 0xfffff000;
28682 insn |= encoded_addend;
28683
28684 /* Update the instruction. */
28685 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
28686 }
28687 break;
28688
28689 case BFD_RELOC_ARM_LDR_PC_G0:
28690 case BFD_RELOC_ARM_LDR_PC_G1:
28691 case BFD_RELOC_ARM_LDR_PC_G2:
28692 case BFD_RELOC_ARM_LDR_SB_G0:
28693 case BFD_RELOC_ARM_LDR_SB_G1:
28694 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 28695 gas_assert (!fixP->fx_done);
4962c51a 28696 if (!seg->use_rela_p)
477330fc
RM
28697 {
28698 bfd_vma insn;
3ca4a8ec 28699 bfd_vma addend_abs = llabs (value);
4962c51a 28700
477330fc
RM
28701 /* Check that the absolute value of the addend can be
28702 encoded in 12 bits. */
28703 if (addend_abs >= 0x1000)
4962c51a 28704 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28705 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
28706 (unsigned long) addend_abs);
28707
28708 /* Extract the instruction. */
28709 insn = md_chars_to_number (buf, INSN_SIZE);
28710
28711 /* If the addend is negative, clear bit 23 of the instruction.
28712 Otherwise set it. */
28713 if (value < 0)
28714 insn &= ~(1 << 23);
28715 else
28716 insn |= 1 << 23;
28717
28718 /* Place the absolute value of the addend into the first 12 bits
28719 of the instruction. */
28720 insn &= 0xfffff000;
28721 insn |= addend_abs;
28722
28723 /* Update the instruction. */
28724 md_number_to_chars (buf, insn, INSN_SIZE);
28725 }
4962c51a
MS
28726 break;
28727
28728 case BFD_RELOC_ARM_LDRS_PC_G0:
28729 case BFD_RELOC_ARM_LDRS_PC_G1:
28730 case BFD_RELOC_ARM_LDRS_PC_G2:
28731 case BFD_RELOC_ARM_LDRS_SB_G0:
28732 case BFD_RELOC_ARM_LDRS_SB_G1:
28733 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 28734 gas_assert (!fixP->fx_done);
4962c51a 28735 if (!seg->use_rela_p)
477330fc
RM
28736 {
28737 bfd_vma insn;
3ca4a8ec 28738 bfd_vma addend_abs = llabs (value);
4962c51a 28739
477330fc
RM
28740 /* Check that the absolute value of the addend can be
28741 encoded in 8 bits. */
28742 if (addend_abs >= 0x100)
4962c51a 28743 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28744 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
28745 (unsigned long) addend_abs);
28746
28747 /* Extract the instruction. */
28748 insn = md_chars_to_number (buf, INSN_SIZE);
28749
28750 /* If the addend is negative, clear bit 23 of the instruction.
28751 Otherwise set it. */
28752 if (value < 0)
28753 insn &= ~(1 << 23);
28754 else
28755 insn |= 1 << 23;
28756
28757 /* Place the first four bits of the absolute value of the addend
28758 into the first 4 bits of the instruction, and the remaining
28759 four into bits 8 .. 11. */
28760 insn &= 0xfffff0f0;
28761 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
28762
28763 /* Update the instruction. */
28764 md_number_to_chars (buf, insn, INSN_SIZE);
28765 }
4962c51a
MS
28766 break;
28767
28768 case BFD_RELOC_ARM_LDC_PC_G0:
28769 case BFD_RELOC_ARM_LDC_PC_G1:
28770 case BFD_RELOC_ARM_LDC_PC_G2:
28771 case BFD_RELOC_ARM_LDC_SB_G0:
28772 case BFD_RELOC_ARM_LDC_SB_G1:
28773 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 28774 gas_assert (!fixP->fx_done);
4962c51a 28775 if (!seg->use_rela_p)
477330fc
RM
28776 {
28777 bfd_vma insn;
3ca4a8ec 28778 bfd_vma addend_abs = llabs (value);
4962c51a 28779
477330fc
RM
28780 /* Check that the absolute value of the addend is a multiple of
28781 four and, when divided by four, fits in 8 bits. */
28782 if (addend_abs & 0x3)
4962c51a 28783 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28784 _("bad offset 0x%08lX (must be word-aligned)"),
28785 (unsigned long) addend_abs);
4962c51a 28786
477330fc 28787 if ((addend_abs >> 2) > 0xff)
4962c51a 28788 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28789 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
28790 (unsigned long) addend_abs);
28791
28792 /* Extract the instruction. */
28793 insn = md_chars_to_number (buf, INSN_SIZE);
28794
28795 /* If the addend is negative, clear bit 23 of the instruction.
28796 Otherwise set it. */
28797 if (value < 0)
28798 insn &= ~(1 << 23);
28799 else
28800 insn |= 1 << 23;
28801
28802 /* Place the addend (divided by four) into the first eight
28803 bits of the instruction. */
28804 insn &= 0xfffffff0;
28805 insn |= addend_abs >> 2;
28806
28807 /* Update the instruction. */
28808 md_number_to_chars (buf, insn, INSN_SIZE);
28809 }
4962c51a
MS
28810 break;
28811
e12437dc
AV
28812 case BFD_RELOC_THUMB_PCREL_BRANCH5:
28813 if (fixP->fx_addsy
28814 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28815 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28816 && ARM_IS_FUNC (fixP->fx_addsy)
28817 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28818 {
28819 /* Force a relocation for a branch 5 bits wide. */
28820 fixP->fx_done = 0;
28821 }
28822 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
28823 as_bad_where (fixP->fx_file, fixP->fx_line,
28824 BAD_BRANCH_OFF);
28825
28826 if (fixP->fx_done || !seg->use_rela_p)
28827 {
28828 addressT boff = value >> 1;
28829
28830 newval = md_chars_to_number (buf, THUMB_SIZE);
28831 newval |= (boff << 7);
28832 md_number_to_chars (buf, newval, THUMB_SIZE);
28833 }
28834 break;
28835
f6b2b12d
AV
28836 case BFD_RELOC_THUMB_PCREL_BFCSEL:
28837 if (fixP->fx_addsy
28838 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28839 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28840 && ARM_IS_FUNC (fixP->fx_addsy)
28841 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28842 {
28843 fixP->fx_done = 0;
28844 }
28845 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
28846 as_bad_where (fixP->fx_file, fixP->fx_line,
28847 _("branch out of range"));
28848
28849 if (fixP->fx_done || !seg->use_rela_p)
28850 {
28851 newval = md_chars_to_number (buf, THUMB_SIZE);
28852
28853 addressT boff = ((newval & 0x0780) >> 7) << 1;
28854 addressT diff = value - boff;
28855
28856 if (diff == 4)
28857 {
28858 newval |= 1 << 1; /* T bit. */
28859 }
28860 else if (diff != 2)
28861 {
28862 as_bad_where (fixP->fx_file, fixP->fx_line,
28863 _("out of range label-relative fixup value"));
28864 }
28865 md_number_to_chars (buf, newval, THUMB_SIZE);
28866 }
28867 break;
28868
e5d6e09e
AV
28869 case BFD_RELOC_ARM_THUMB_BF17:
28870 if (fixP->fx_addsy
28871 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28872 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28873 && ARM_IS_FUNC (fixP->fx_addsy)
28874 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28875 {
28876 /* Force a relocation for a branch 17 bits wide. */
28877 fixP->fx_done = 0;
28878 }
28879
28880 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
28881 as_bad_where (fixP->fx_file, fixP->fx_line,
28882 BAD_BRANCH_OFF);
28883
28884 if (fixP->fx_done || !seg->use_rela_p)
28885 {
28886 offsetT newval2;
28887 addressT immA, immB, immC;
28888
28889 immA = (value & 0x0001f000) >> 12;
28890 immB = (value & 0x00000ffc) >> 2;
28891 immC = (value & 0x00000002) >> 1;
28892
28893 newval = md_chars_to_number (buf, THUMB_SIZE);
28894 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28895 newval |= immA;
28896 newval2 |= (immC << 11) | (immB << 1);
28897 md_number_to_chars (buf, newval, THUMB_SIZE);
28898 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28899 }
28900 break;
28901
1caf72a5
AV
28902 case BFD_RELOC_ARM_THUMB_BF19:
28903 if (fixP->fx_addsy
28904 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28905 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28906 && ARM_IS_FUNC (fixP->fx_addsy)
28907 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28908 {
28909 /* Force a relocation for a branch 19 bits wide. */
28910 fixP->fx_done = 0;
28911 }
28912
28913 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
28914 as_bad_where (fixP->fx_file, fixP->fx_line,
28915 BAD_BRANCH_OFF);
28916
28917 if (fixP->fx_done || !seg->use_rela_p)
28918 {
28919 offsetT newval2;
28920 addressT immA, immB, immC;
28921
28922 immA = (value & 0x0007f000) >> 12;
28923 immB = (value & 0x00000ffc) >> 2;
28924 immC = (value & 0x00000002) >> 1;
28925
28926 newval = md_chars_to_number (buf, THUMB_SIZE);
28927 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28928 newval |= immA;
28929 newval2 |= (immC << 11) | (immB << 1);
28930 md_number_to_chars (buf, newval, THUMB_SIZE);
28931 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28932 }
28933 break;
28934
1889da70
AV
28935 case BFD_RELOC_ARM_THUMB_BF13:
28936 if (fixP->fx_addsy
28937 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28938 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28939 && ARM_IS_FUNC (fixP->fx_addsy)
28940 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28941 {
28942 /* Force a relocation for a branch 13 bits wide. */
28943 fixP->fx_done = 0;
28944 }
28945
28946 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
28947 as_bad_where (fixP->fx_file, fixP->fx_line,
28948 BAD_BRANCH_OFF);
28949
28950 if (fixP->fx_done || !seg->use_rela_p)
28951 {
28952 offsetT newval2;
28953 addressT immA, immB, immC;
28954
28955 immA = (value & 0x00001000) >> 12;
28956 immB = (value & 0x00000ffc) >> 2;
28957 immC = (value & 0x00000002) >> 1;
28958
28959 newval = md_chars_to_number (buf, THUMB_SIZE);
28960 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28961 newval |= immA;
28962 newval2 |= (immC << 11) | (immB << 1);
28963 md_number_to_chars (buf, newval, THUMB_SIZE);
28964 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28965 }
28966 break;
28967
60f993ce
AV
28968 case BFD_RELOC_ARM_THUMB_LOOP12:
28969 if (fixP->fx_addsy
28970 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28971 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28972 && ARM_IS_FUNC (fixP->fx_addsy)
28973 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28974 {
28975 /* Force a relocation for a branch 12 bits wide. */
28976 fixP->fx_done = 0;
28977 }
28978
28979 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 28980 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 28981 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
28982 || ((insn & 0xffffffff) == 0xf02fc001)
28983 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
28984 value = -value;
28985
28986 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
28987 as_bad_where (fixP->fx_file, fixP->fx_line,
28988 BAD_BRANCH_OFF);
28989 if (fixP->fx_done || !seg->use_rela_p)
28990 {
28991 addressT imml, immh;
28992
28993 immh = (value & 0x00000ffc) >> 2;
28994 imml = (value & 0x00000002) >> 1;
28995
28996 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28997 newval |= (imml << 11) | (immh << 1);
28998 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
28999 }
29000 break;
29001
845b51d6
PB
29002 case BFD_RELOC_ARM_V4BX:
29003 /* This will need to go in the object file. */
29004 fixP->fx_done = 0;
29005 break;
29006
c19d1205
ZW
29007 case BFD_RELOC_UNUSED:
29008 default:
29009 as_bad_where (fixP->fx_file, fixP->fx_line,
29010 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29011 }
6c43fab6
RE
29012}
29013
c19d1205
ZW
29014/* Translate internal representation of relocation info to BFD target
29015 format. */
a737bd4d 29016
c19d1205 29017arelent *
00a97672 29018tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29019{
c19d1205
ZW
29020 arelent * reloc;
29021 bfd_reloc_code_real_type code;
a737bd4d 29022
325801bd 29023 reloc = XNEW (arelent);
a737bd4d 29024
325801bd 29025 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
29026 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29027 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 29028
2fc8bdac 29029 if (fixp->fx_pcrel)
00a97672
RS
29030 {
29031 if (section->use_rela_p)
29032 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29033 else
29034 fixp->fx_offset = reloc->address;
29035 }
c19d1205 29036 reloc->addend = fixp->fx_offset;
a737bd4d 29037
c19d1205 29038 switch (fixp->fx_r_type)
a737bd4d 29039 {
c19d1205
ZW
29040 case BFD_RELOC_8:
29041 if (fixp->fx_pcrel)
29042 {
29043 code = BFD_RELOC_8_PCREL;
29044 break;
29045 }
1a0670f3 29046 /* Fall through. */
a737bd4d 29047
c19d1205
ZW
29048 case BFD_RELOC_16:
29049 if (fixp->fx_pcrel)
29050 {
29051 code = BFD_RELOC_16_PCREL;
29052 break;
29053 }
1a0670f3 29054 /* Fall through. */
6c43fab6 29055
c19d1205
ZW
29056 case BFD_RELOC_32:
29057 if (fixp->fx_pcrel)
29058 {
29059 code = BFD_RELOC_32_PCREL;
29060 break;
29061 }
1a0670f3 29062 /* Fall through. */
a737bd4d 29063
b6895b4f
PB
29064 case BFD_RELOC_ARM_MOVW:
29065 if (fixp->fx_pcrel)
29066 {
29067 code = BFD_RELOC_ARM_MOVW_PCREL;
29068 break;
29069 }
1a0670f3 29070 /* Fall through. */
b6895b4f
PB
29071
29072 case BFD_RELOC_ARM_MOVT:
29073 if (fixp->fx_pcrel)
29074 {
29075 code = BFD_RELOC_ARM_MOVT_PCREL;
29076 break;
29077 }
1a0670f3 29078 /* Fall through. */
b6895b4f
PB
29079
29080 case BFD_RELOC_ARM_THUMB_MOVW:
29081 if (fixp->fx_pcrel)
29082 {
29083 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
29084 break;
29085 }
1a0670f3 29086 /* Fall through. */
b6895b4f
PB
29087
29088 case BFD_RELOC_ARM_THUMB_MOVT:
29089 if (fixp->fx_pcrel)
29090 {
29091 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
29092 break;
29093 }
1a0670f3 29094 /* Fall through. */
b6895b4f 29095
c19d1205
ZW
29096 case BFD_RELOC_NONE:
29097 case BFD_RELOC_ARM_PCREL_BRANCH:
29098 case BFD_RELOC_ARM_PCREL_BLX:
29099 case BFD_RELOC_RVA:
29100 case BFD_RELOC_THUMB_PCREL_BRANCH7:
29101 case BFD_RELOC_THUMB_PCREL_BRANCH9:
29102 case BFD_RELOC_THUMB_PCREL_BRANCH12:
29103 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29104 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29105 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
29106 case BFD_RELOC_VTABLE_ENTRY:
29107 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
29108#ifdef TE_PE
29109 case BFD_RELOC_32_SECREL:
29110#endif
c19d1205
ZW
29111 code = fixp->fx_r_type;
29112 break;
a737bd4d 29113
00adf2d4
JB
29114 case BFD_RELOC_THUMB_PCREL_BLX:
29115#ifdef OBJ_ELF
29116 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
29117 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
29118 else
29119#endif
29120 code = BFD_RELOC_THUMB_PCREL_BLX;
29121 break;
29122
c19d1205
ZW
29123 case BFD_RELOC_ARM_LITERAL:
29124 case BFD_RELOC_ARM_HWLITERAL:
29125 /* If this is called then the a literal has
29126 been referenced across a section boundary. */
29127 as_bad_where (fixp->fx_file, fixp->fx_line,
29128 _("literal referenced across section boundary"));
29129 return NULL;
a737bd4d 29130
c19d1205 29131#ifdef OBJ_ELF
0855e32b
NS
29132 case BFD_RELOC_ARM_TLS_CALL:
29133 case BFD_RELOC_ARM_THM_TLS_CALL:
29134 case BFD_RELOC_ARM_TLS_DESCSEQ:
29135 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
29136 case BFD_RELOC_ARM_GOT32:
29137 case BFD_RELOC_ARM_GOTOFF:
b43420e6 29138 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
29139 case BFD_RELOC_ARM_PLT32:
29140 case BFD_RELOC_ARM_TARGET1:
29141 case BFD_RELOC_ARM_ROSEGREL32:
29142 case BFD_RELOC_ARM_SBREL32:
29143 case BFD_RELOC_ARM_PREL31:
29144 case BFD_RELOC_ARM_TARGET2:
c19d1205 29145 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
29146 case BFD_RELOC_ARM_PCREL_CALL:
29147 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
29148 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29149 case BFD_RELOC_ARM_ALU_PC_G0:
29150 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29151 case BFD_RELOC_ARM_ALU_PC_G1:
29152 case BFD_RELOC_ARM_ALU_PC_G2:
29153 case BFD_RELOC_ARM_LDR_PC_G0:
29154 case BFD_RELOC_ARM_LDR_PC_G1:
29155 case BFD_RELOC_ARM_LDR_PC_G2:
29156 case BFD_RELOC_ARM_LDRS_PC_G0:
29157 case BFD_RELOC_ARM_LDRS_PC_G1:
29158 case BFD_RELOC_ARM_LDRS_PC_G2:
29159 case BFD_RELOC_ARM_LDC_PC_G0:
29160 case BFD_RELOC_ARM_LDC_PC_G1:
29161 case BFD_RELOC_ARM_LDC_PC_G2:
29162 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29163 case BFD_RELOC_ARM_ALU_SB_G0:
29164 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29165 case BFD_RELOC_ARM_ALU_SB_G1:
29166 case BFD_RELOC_ARM_ALU_SB_G2:
29167 case BFD_RELOC_ARM_LDR_SB_G0:
29168 case BFD_RELOC_ARM_LDR_SB_G1:
29169 case BFD_RELOC_ARM_LDR_SB_G2:
29170 case BFD_RELOC_ARM_LDRS_SB_G0:
29171 case BFD_RELOC_ARM_LDRS_SB_G1:
29172 case BFD_RELOC_ARM_LDRS_SB_G2:
29173 case BFD_RELOC_ARM_LDC_SB_G0:
29174 case BFD_RELOC_ARM_LDC_SB_G1:
29175 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 29176 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
29177 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29178 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29179 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29180 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
29181 case BFD_RELOC_ARM_GOTFUNCDESC:
29182 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29183 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 29184 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 29185 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 29186 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
29187 code = fixp->fx_r_type;
29188 break;
a737bd4d 29189
0855e32b 29190 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 29191 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 29192 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 29193 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 29194 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 29195 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 29196 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 29197 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
29198 /* BFD will include the symbol's address in the addend.
29199 But we don't want that, so subtract it out again here. */
29200 if (!S_IS_COMMON (fixp->fx_addsy))
29201 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
29202 code = fixp->fx_r_type;
29203 break;
29204#endif
a737bd4d 29205
c19d1205
ZW
29206 case BFD_RELOC_ARM_IMMEDIATE:
29207 as_bad_where (fixp->fx_file, fixp->fx_line,
29208 _("internal relocation (type: IMMEDIATE) not fixed up"));
29209 return NULL;
a737bd4d 29210
c19d1205
ZW
29211 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
29212 as_bad_where (fixp->fx_file, fixp->fx_line,
29213 _("ADRL used for a symbol not defined in the same file"));
29214 return NULL;
a737bd4d 29215
e12437dc 29216 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 29217 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 29218 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
29219 as_bad_where (fixp->fx_file, fixp->fx_line,
29220 _("%s used for a symbol not defined in the same file"),
29221 bfd_get_reloc_code_name (fixp->fx_r_type));
29222 return NULL;
29223
c19d1205 29224 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
29225 if (section->use_rela_p)
29226 {
29227 code = fixp->fx_r_type;
29228 break;
29229 }
29230
c19d1205
ZW
29231 if (fixp->fx_addsy != NULL
29232 && !S_IS_DEFINED (fixp->fx_addsy)
29233 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 29234 {
c19d1205
ZW
29235 as_bad_where (fixp->fx_file, fixp->fx_line,
29236 _("undefined local label `%s'"),
29237 S_GET_NAME (fixp->fx_addsy));
29238 return NULL;
a737bd4d
NC
29239 }
29240
c19d1205
ZW
29241 as_bad_where (fixp->fx_file, fixp->fx_line,
29242 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
29243 return NULL;
a737bd4d 29244
c19d1205
ZW
29245 default:
29246 {
e0471c16 29247 const char * type;
6c43fab6 29248
c19d1205
ZW
29249 switch (fixp->fx_r_type)
29250 {
29251 case BFD_RELOC_NONE: type = "NONE"; break;
29252 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
29253 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 29254 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
29255 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
29256 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
29257 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 29258 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 29259 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
29260 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
29261 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
29262 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
29263 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
29264 default: type = _("<unknown>"); break;
29265 }
29266 as_bad_where (fixp->fx_file, fixp->fx_line,
29267 _("cannot represent %s relocation in this object file format"),
29268 type);
29269 return NULL;
29270 }
a737bd4d 29271 }
6c43fab6 29272
c19d1205
ZW
29273#ifdef OBJ_ELF
29274 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
29275 && GOT_symbol
29276 && fixp->fx_addsy == GOT_symbol)
29277 {
29278 code = BFD_RELOC_ARM_GOTPC;
29279 reloc->addend = fixp->fx_offset = reloc->address;
29280 }
29281#endif
6c43fab6 29282
c19d1205 29283 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 29284
c19d1205
ZW
29285 if (reloc->howto == NULL)
29286 {
29287 as_bad_where (fixp->fx_file, fixp->fx_line,
29288 _("cannot represent %s relocation in this object file format"),
29289 bfd_get_reloc_code_name (code));
29290 return NULL;
29291 }
6c43fab6 29292
c19d1205
ZW
29293 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
29294 vtable entry to be used in the relocation's section offset. */
29295 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29296 reloc->address = fixp->fx_offset;
6c43fab6 29297
c19d1205 29298 return reloc;
6c43fab6
RE
29299}
29300
c19d1205 29301/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 29302
c19d1205
ZW
29303void
29304cons_fix_new_arm (fragS * frag,
29305 int where,
29306 int size,
62ebcb5c
AM
29307 expressionS * exp,
29308 bfd_reloc_code_real_type reloc)
6c43fab6 29309{
c19d1205 29310 int pcrel = 0;
6c43fab6 29311
c19d1205
ZW
29312 /* Pick a reloc.
29313 FIXME: @@ Should look at CPU word size. */
29314 switch (size)
29315 {
29316 case 1:
62ebcb5c 29317 reloc = BFD_RELOC_8;
c19d1205
ZW
29318 break;
29319 case 2:
62ebcb5c 29320 reloc = BFD_RELOC_16;
c19d1205
ZW
29321 break;
29322 case 4:
29323 default:
62ebcb5c 29324 reloc = BFD_RELOC_32;
c19d1205
ZW
29325 break;
29326 case 8:
62ebcb5c 29327 reloc = BFD_RELOC_64;
c19d1205
ZW
29328 break;
29329 }
6c43fab6 29330
f0927246
NC
29331#ifdef TE_PE
29332 if (exp->X_op == O_secrel)
29333 {
29334 exp->X_op = O_symbol;
62ebcb5c 29335 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
29336 }
29337#endif
29338
62ebcb5c 29339 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 29340}
6c43fab6 29341
4343666d 29342#if defined (OBJ_COFF)
c19d1205
ZW
29343void
29344arm_validate_fix (fixS * fixP)
6c43fab6 29345{
c19d1205
ZW
29346 /* If the destination of the branch is a defined symbol which does not have
29347 the THUMB_FUNC attribute, then we must be calling a function which has
29348 the (interfacearm) attribute. We look for the Thumb entry point to that
29349 function and change the branch to refer to that function instead. */
29350 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
29351 && fixP->fx_addsy != NULL
29352 && S_IS_DEFINED (fixP->fx_addsy)
29353 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 29354 {
c19d1205 29355 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 29356 }
c19d1205
ZW
29357}
29358#endif
6c43fab6 29359
267bf995 29360
c19d1205
ZW
29361int
29362arm_force_relocation (struct fix * fixp)
29363{
29364#if defined (OBJ_COFF) && defined (TE_PE)
29365 if (fixp->fx_r_type == BFD_RELOC_RVA)
29366 return 1;
29367#endif
6c43fab6 29368
267bf995
RR
29369 /* In case we have a call or a branch to a function in ARM ISA mode from
29370 a thumb function or vice-versa force the relocation. These relocations
29371 are cleared off for some cores that might have blx and simple transformations
29372 are possible. */
29373
29374#ifdef OBJ_ELF
29375 switch (fixp->fx_r_type)
29376 {
29377 case BFD_RELOC_ARM_PCREL_JUMP:
29378 case BFD_RELOC_ARM_PCREL_CALL:
29379 case BFD_RELOC_THUMB_PCREL_BLX:
29380 if (THUMB_IS_FUNC (fixp->fx_addsy))
29381 return 1;
29382 break;
29383
29384 case BFD_RELOC_ARM_PCREL_BLX:
29385 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29386 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29387 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29388 if (ARM_IS_FUNC (fixp->fx_addsy))
29389 return 1;
29390 break;
29391
29392 default:
29393 break;
29394 }
29395#endif
29396
b5884301
PB
29397 /* Resolve these relocations even if the symbol is extern or weak.
29398 Technically this is probably wrong due to symbol preemption.
29399 In practice these relocations do not have enough range to be useful
29400 at dynamic link time, and some code (e.g. in the Linux kernel)
29401 expects these references to be resolved. */
c19d1205
ZW
29402 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
29403 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 29404 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 29405 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
29406 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29407 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
29408 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 29409 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
29410 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
29411 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
29412 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
29413 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
29414 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
29415 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 29416 return 0;
a737bd4d 29417
4962c51a
MS
29418 /* Always leave these relocations for the linker. */
29419 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29420 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29421 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29422 return 1;
29423
f0291e4c
PB
29424 /* Always generate relocations against function symbols. */
29425 if (fixp->fx_r_type == BFD_RELOC_32
29426 && fixp->fx_addsy
29427 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
29428 return 1;
29429
c19d1205 29430 return generic_force_reloc (fixp);
404ff6b5
AH
29431}
29432
0ffdc86c 29433#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
29434/* Relocations against function names must be left unadjusted,
29435 so that the linker can use this information to generate interworking
29436 stubs. The MIPS version of this function
c19d1205
ZW
29437 also prevents relocations that are mips-16 specific, but I do not
29438 know why it does this.
404ff6b5 29439
c19d1205
ZW
29440 FIXME:
29441 There is one other problem that ought to be addressed here, but
29442 which currently is not: Taking the address of a label (rather
29443 than a function) and then later jumping to that address. Such
29444 addresses also ought to have their bottom bit set (assuming that
29445 they reside in Thumb code), but at the moment they will not. */
404ff6b5 29446
c19d1205
ZW
29447bfd_boolean
29448arm_fix_adjustable (fixS * fixP)
404ff6b5 29449{
c19d1205
ZW
29450 if (fixP->fx_addsy == NULL)
29451 return 1;
404ff6b5 29452
e28387c3
PB
29453 /* Preserve relocations against symbols with function type. */
29454 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 29455 return FALSE;
e28387c3 29456
c19d1205
ZW
29457 if (THUMB_IS_FUNC (fixP->fx_addsy)
29458 && fixP->fx_subsy == NULL)
c921be7d 29459 return FALSE;
a737bd4d 29460
c19d1205
ZW
29461 /* We need the symbol name for the VTABLE entries. */
29462 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
29463 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 29464 return FALSE;
404ff6b5 29465
c19d1205
ZW
29466 /* Don't allow symbols to be discarded on GOT related relocs. */
29467 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
29468 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
29469 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
29470 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 29471 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
29472 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
29473 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 29474 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 29475 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 29476 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 29477 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
29478 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
29479 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
29480 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
29481 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
29482 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 29483 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 29484 return FALSE;
a737bd4d 29485
4962c51a
MS
29486 /* Similarly for group relocations. */
29487 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29488 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29489 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 29490 return FALSE;
4962c51a 29491
79947c54
CD
29492 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
29493 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
29494 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29495 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
29496 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
29497 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29498 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
29499 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
29500 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 29501 return FALSE;
79947c54 29502
72d98d16
MG
29503 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
29504 offsets, so keep these symbols. */
29505 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
29506 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
29507 return FALSE;
29508
c921be7d 29509 return TRUE;
a737bd4d 29510}
0ffdc86c
NC
29511#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
29512
29513#ifdef OBJ_ELF
c19d1205
ZW
29514const char *
29515elf32_arm_target_format (void)
404ff6b5 29516{
c19d1205
ZW
29517#ifdef TE_SYMBIAN
29518 return (target_big_endian
29519 ? "elf32-bigarm-symbian"
29520 : "elf32-littlearm-symbian");
29521#elif defined (TE_VXWORKS)
29522 return (target_big_endian
29523 ? "elf32-bigarm-vxworks"
29524 : "elf32-littlearm-vxworks");
b38cadfb
NC
29525#elif defined (TE_NACL)
29526 return (target_big_endian
29527 ? "elf32-bigarm-nacl"
29528 : "elf32-littlearm-nacl");
c19d1205 29529#else
18a20338
CL
29530 if (arm_fdpic)
29531 {
29532 if (target_big_endian)
29533 return "elf32-bigarm-fdpic";
29534 else
29535 return "elf32-littlearm-fdpic";
29536 }
c19d1205 29537 else
18a20338
CL
29538 {
29539 if (target_big_endian)
29540 return "elf32-bigarm";
29541 else
29542 return "elf32-littlearm";
29543 }
c19d1205 29544#endif
404ff6b5
AH
29545}
29546
c19d1205
ZW
29547void
29548armelf_frob_symbol (symbolS * symp,
29549 int * puntp)
404ff6b5 29550{
c19d1205
ZW
29551 elf_frob_symbol (symp, puntp);
29552}
29553#endif
404ff6b5 29554
c19d1205 29555/* MD interface: Finalization. */
a737bd4d 29556
c19d1205
ZW
29557void
29558arm_cleanup (void)
29559{
29560 literal_pool * pool;
a737bd4d 29561
5ee91343
AV
29562 /* Ensure that all the predication blocks are properly closed. */
29563 check_pred_blocks_finished ();
e07e6e58 29564
c19d1205
ZW
29565 for (pool = list_of_pools; pool; pool = pool->next)
29566 {
5f4273c7 29567 /* Put it at the end of the relevant section. */
c19d1205
ZW
29568 subseg_set (pool->section, pool->sub_section);
29569#ifdef OBJ_ELF
29570 arm_elf_change_section ();
29571#endif
29572 s_ltorg (0);
29573 }
404ff6b5
AH
29574}
29575
cd000bff
DJ
29576#ifdef OBJ_ELF
29577/* Remove any excess mapping symbols generated for alignment frags in
29578 SEC. We may have created a mapping symbol before a zero byte
29579 alignment; remove it if there's a mapping symbol after the
29580 alignment. */
29581static void
29582check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
29583 void *dummy ATTRIBUTE_UNUSED)
29584{
29585 segment_info_type *seginfo = seg_info (sec);
29586 fragS *fragp;
29587
29588 if (seginfo == NULL || seginfo->frchainP == NULL)
29589 return;
29590
29591 for (fragp = seginfo->frchainP->frch_root;
29592 fragp != NULL;
29593 fragp = fragp->fr_next)
29594 {
29595 symbolS *sym = fragp->tc_frag_data.last_map;
29596 fragS *next = fragp->fr_next;
29597
29598 /* Variable-sized frags have been converted to fixed size by
29599 this point. But if this was variable-sized to start with,
29600 there will be a fixed-size frag after it. So don't handle
29601 next == NULL. */
29602 if (sym == NULL || next == NULL)
29603 continue;
29604
29605 if (S_GET_VALUE (sym) < next->fr_address)
29606 /* Not at the end of this frag. */
29607 continue;
29608 know (S_GET_VALUE (sym) == next->fr_address);
29609
29610 do
29611 {
29612 if (next->tc_frag_data.first_map != NULL)
29613 {
29614 /* Next frag starts with a mapping symbol. Discard this
29615 one. */
29616 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29617 break;
29618 }
29619
29620 if (next->fr_next == NULL)
29621 {
29622 /* This mapping symbol is at the end of the section. Discard
29623 it. */
29624 know (next->fr_fix == 0 && next->fr_var == 0);
29625 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29626 break;
29627 }
29628
29629 /* As long as we have empty frags without any mapping symbols,
29630 keep looking. */
29631 /* If the next frag is non-empty and does not start with a
29632 mapping symbol, then this mapping symbol is required. */
29633 if (next->fr_address != next->fr_next->fr_address)
29634 break;
29635
29636 next = next->fr_next;
29637 }
29638 while (next != NULL);
29639 }
29640}
29641#endif
29642
c19d1205
ZW
29643/* Adjust the symbol table. This marks Thumb symbols as distinct from
29644 ARM ones. */
404ff6b5 29645
c19d1205
ZW
29646void
29647arm_adjust_symtab (void)
404ff6b5 29648{
c19d1205
ZW
29649#ifdef OBJ_COFF
29650 symbolS * sym;
404ff6b5 29651
c19d1205
ZW
29652 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
29653 {
29654 if (ARM_IS_THUMB (sym))
29655 {
29656 if (THUMB_IS_FUNC (sym))
29657 {
29658 /* Mark the symbol as a Thumb function. */
29659 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
29660 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
29661 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 29662
c19d1205
ZW
29663 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
29664 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
29665 else
29666 as_bad (_("%s: unexpected function type: %d"),
29667 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
29668 }
29669 else switch (S_GET_STORAGE_CLASS (sym))
29670 {
29671 case C_EXT:
29672 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
29673 break;
29674 case C_STAT:
29675 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
29676 break;
29677 case C_LABEL:
29678 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
29679 break;
29680 default:
29681 /* Do nothing. */
29682 break;
29683 }
29684 }
a737bd4d 29685
c19d1205
ZW
29686 if (ARM_IS_INTERWORK (sym))
29687 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 29688 }
c19d1205
ZW
29689#endif
29690#ifdef OBJ_ELF
29691 symbolS * sym;
29692 char bind;
404ff6b5 29693
c19d1205 29694 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 29695 {
c19d1205
ZW
29696 if (ARM_IS_THUMB (sym))
29697 {
29698 elf_symbol_type * elf_sym;
404ff6b5 29699
c19d1205
ZW
29700 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
29701 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 29702
b0796911
PB
29703 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
29704 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
29705 {
29706 /* If it's a .thumb_func, declare it as so,
29707 otherwise tag label as .code 16. */
29708 if (THUMB_IS_FUNC (sym))
39d911fc
TP
29709 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
29710 ST_BRANCH_TO_THUMB);
3ba67470 29711 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
29712 elf_sym->internal_elf_sym.st_info =
29713 ELF_ST_INFO (bind, STT_ARM_16BIT);
29714 }
29715 }
29716 }
cd000bff
DJ
29717
29718 /* Remove any overlapping mapping symbols generated by alignment frags. */
29719 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
29720 /* Now do generic ELF adjustments. */
29721 elf_adjust_symtab ();
c19d1205 29722#endif
404ff6b5
AH
29723}
29724
c19d1205 29725/* MD interface: Initialization. */
404ff6b5 29726
a737bd4d 29727static void
c19d1205 29728set_constant_flonums (void)
a737bd4d 29729{
c19d1205 29730 int i;
404ff6b5 29731
c19d1205
ZW
29732 for (i = 0; i < NUM_FLOAT_VALS; i++)
29733 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
29734 abort ();
a737bd4d 29735}
404ff6b5 29736
3e9e4fcf
JB
29737/* Auto-select Thumb mode if it's the only available instruction set for the
29738 given architecture. */
29739
29740static void
29741autoselect_thumb_from_cpu_variant (void)
29742{
29743 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
29744 opcode_select (16);
29745}
29746
c19d1205
ZW
29747void
29748md_begin (void)
a737bd4d 29749{
c19d1205
ZW
29750 unsigned mach;
29751 unsigned int i;
404ff6b5 29752
c19d1205
ZW
29753 if ( (arm_ops_hsh = hash_new ()) == NULL
29754 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 29755 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
29756 || (arm_shift_hsh = hash_new ()) == NULL
29757 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 29758 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 29759 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
29760 || (arm_reloc_hsh = hash_new ()) == NULL
29761 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
29762 as_fatal (_("virtual memory exhausted"));
29763
29764 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 29765 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 29766 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 29767 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
29768 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
29769 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 29770 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 29771 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 29772 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 29773 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 29774 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 29775 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 29776 (void *) (v7m_psrs + i));
c19d1205 29777 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 29778 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
29779 for (i = 0;
29780 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
29781 i++)
d3ce72d0 29782 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 29783 (void *) (barrier_opt_names + i));
c19d1205 29784#ifdef OBJ_ELF
3da1d841
NC
29785 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
29786 {
29787 struct reloc_entry * entry = reloc_names + i;
29788
29789 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
29790 /* This makes encode_branch() use the EABI versions of this relocation. */
29791 entry->reloc = BFD_RELOC_UNUSED;
29792
29793 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
29794 }
c19d1205
ZW
29795#endif
29796
29797 set_constant_flonums ();
404ff6b5 29798
c19d1205
ZW
29799 /* Set the cpu variant based on the command-line options. We prefer
29800 -mcpu= over -march= if both are set (as for GCC); and we prefer
29801 -mfpu= over any other way of setting the floating point unit.
29802 Use of legacy options with new options are faulted. */
e74cfd16 29803 if (legacy_cpu)
404ff6b5 29804 {
e74cfd16 29805 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
29806 as_bad (_("use of old and new-style options to set CPU type"));
29807
4d354d8b 29808 selected_arch = *legacy_cpu;
404ff6b5 29809 }
4d354d8b
TP
29810 else if (mcpu_cpu_opt)
29811 {
29812 selected_arch = *mcpu_cpu_opt;
29813 selected_ext = *mcpu_ext_opt;
29814 }
29815 else if (march_cpu_opt)
c168ce07 29816 {
4d354d8b
TP
29817 selected_arch = *march_cpu_opt;
29818 selected_ext = *march_ext_opt;
c168ce07 29819 }
4d354d8b 29820 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 29821
e74cfd16 29822 if (legacy_fpu)
c19d1205 29823 {
e74cfd16 29824 if (mfpu_opt)
c19d1205 29825 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 29826
4d354d8b 29827 selected_fpu = *legacy_fpu;
03b1477f 29828 }
4d354d8b
TP
29829 else if (mfpu_opt)
29830 selected_fpu = *mfpu_opt;
29831 else
03b1477f 29832 {
45eb4c1b
NS
29833#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
29834 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
29835 /* Some environments specify a default FPU. If they don't, infer it
29836 from the processor. */
e74cfd16 29837 if (mcpu_fpu_opt)
4d354d8b 29838 selected_fpu = *mcpu_fpu_opt;
e7da50fa 29839 else if (march_fpu_opt)
4d354d8b 29840 selected_fpu = *march_fpu_opt;
39c2da32 29841#else
4d354d8b 29842 selected_fpu = fpu_default;
39c2da32 29843#endif
03b1477f
RE
29844 }
29845
4d354d8b 29846 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 29847 {
4d354d8b
TP
29848 if (!no_cpu_selected ())
29849 selected_fpu = fpu_default;
03b1477f 29850 else
4d354d8b 29851 selected_fpu = fpu_arch_fpa;
03b1477f
RE
29852 }
29853
ee065d83 29854#ifdef CPU_DEFAULT
4d354d8b 29855 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 29856 {
4d354d8b
TP
29857 selected_arch = cpu_default;
29858 selected_cpu = selected_arch;
ee065d83 29859 }
4d354d8b 29860 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 29861#else
4d354d8b
TP
29862 /* Autodection of feature mode: allow all features in cpu_variant but leave
29863 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
29864 after all instruction have been processed and we can decide what CPU
29865 should be selected. */
29866 if (ARM_FEATURE_ZERO (selected_arch))
29867 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 29868 else
4d354d8b 29869 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 29870#endif
03b1477f 29871
3e9e4fcf
JB
29872 autoselect_thumb_from_cpu_variant ();
29873
e74cfd16 29874 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 29875
f17c130b 29876#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 29877 {
7cc69913
NC
29878 unsigned int flags = 0;
29879
29880#if defined OBJ_ELF
29881 flags = meabi_flags;
d507cf36
PB
29882
29883 switch (meabi_flags)
33a392fb 29884 {
d507cf36 29885 case EF_ARM_EABI_UNKNOWN:
7cc69913 29886#endif
d507cf36
PB
29887 /* Set the flags in the private structure. */
29888 if (uses_apcs_26) flags |= F_APCS26;
29889 if (support_interwork) flags |= F_INTERWORK;
29890 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 29891 if (pic_code) flags |= F_PIC;
e74cfd16 29892 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
29893 flags |= F_SOFT_FLOAT;
29894
d507cf36
PB
29895 switch (mfloat_abi_opt)
29896 {
29897 case ARM_FLOAT_ABI_SOFT:
29898 case ARM_FLOAT_ABI_SOFTFP:
29899 flags |= F_SOFT_FLOAT;
29900 break;
33a392fb 29901
d507cf36
PB
29902 case ARM_FLOAT_ABI_HARD:
29903 if (flags & F_SOFT_FLOAT)
29904 as_bad (_("hard-float conflicts with specified fpu"));
29905 break;
29906 }
03b1477f 29907
e74cfd16
PB
29908 /* Using pure-endian doubles (even if soft-float). */
29909 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 29910 flags |= F_VFP_FLOAT;
f17c130b 29911
fde78edd 29912#if defined OBJ_ELF
e74cfd16 29913 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 29914 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
29915 break;
29916
8cb51566 29917 case EF_ARM_EABI_VER4:
3a4a14e9 29918 case EF_ARM_EABI_VER5:
c19d1205 29919 /* No additional flags to set. */
d507cf36
PB
29920 break;
29921
29922 default:
29923 abort ();
29924 }
7cc69913 29925#endif
b99bd4ef
NC
29926 bfd_set_private_flags (stdoutput, flags);
29927
29928 /* We have run out flags in the COFF header to encode the
29929 status of ATPCS support, so instead we create a dummy,
c19d1205 29930 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
29931 if (atpcs)
29932 {
29933 asection * sec;
29934
29935 sec = bfd_make_section (stdoutput, ".arm.atpcs");
29936
29937 if (sec != NULL)
29938 {
29939 bfd_set_section_flags
29940 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
29941 bfd_set_section_size (stdoutput, sec, 0);
29942 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
29943 }
29944 }
7cc69913 29945 }
f17c130b 29946#endif
b99bd4ef
NC
29947
29948 /* Record the CPU type as well. */
2d447fca
JM
29949 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
29950 mach = bfd_mach_arm_iWMMXt2;
29951 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 29952 mach = bfd_mach_arm_iWMMXt;
e74cfd16 29953 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 29954 mach = bfd_mach_arm_XScale;
e74cfd16 29955 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 29956 mach = bfd_mach_arm_ep9312;
e74cfd16 29957 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 29958 mach = bfd_mach_arm_5TE;
e74cfd16 29959 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 29960 {
e74cfd16 29961 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
29962 mach = bfd_mach_arm_5T;
29963 else
29964 mach = bfd_mach_arm_5;
29965 }
e74cfd16 29966 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 29967 {
e74cfd16 29968 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
29969 mach = bfd_mach_arm_4T;
29970 else
29971 mach = bfd_mach_arm_4;
29972 }
e74cfd16 29973 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 29974 mach = bfd_mach_arm_3M;
e74cfd16
PB
29975 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
29976 mach = bfd_mach_arm_3;
29977 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
29978 mach = bfd_mach_arm_2a;
29979 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
29980 mach = bfd_mach_arm_2;
29981 else
29982 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
29983
29984 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
29985}
29986
c19d1205 29987/* Command line processing. */
b99bd4ef 29988
c19d1205
ZW
29989/* md_parse_option
29990 Invocation line includes a switch not recognized by the base assembler.
29991 See if it's a processor-specific option.
b99bd4ef 29992
c19d1205
ZW
29993 This routine is somewhat complicated by the need for backwards
29994 compatibility (since older releases of gcc can't be changed).
29995 The new options try to make the interface as compatible as
29996 possible with GCC.
b99bd4ef 29997
c19d1205 29998 New options (supported) are:
b99bd4ef 29999
c19d1205
ZW
30000 -mcpu=<cpu name> Assemble for selected processor
30001 -march=<architecture name> Assemble for selected architecture
30002 -mfpu=<fpu architecture> Assemble for selected FPU.
30003 -EB/-mbig-endian Big-endian
30004 -EL/-mlittle-endian Little-endian
30005 -k Generate PIC code
30006 -mthumb Start in Thumb mode
30007 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30008
278df34e 30009 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30010 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30011
c19d1205 30012 For now we will also provide support for:
b99bd4ef 30013
c19d1205
ZW
30014 -mapcs-32 32-bit Program counter
30015 -mapcs-26 26-bit Program counter
30016 -macps-float Floats passed in FP registers
30017 -mapcs-reentrant Reentrant code
30018 -matpcs
30019 (sometime these will probably be replaced with -mapcs=<list of options>
30020 and -matpcs=<list of options>)
b99bd4ef 30021
c19d1205
ZW
30022 The remaining options are only supported for back-wards compatibility.
30023 Cpu variants, the arm part is optional:
30024 -m[arm]1 Currently not supported.
30025 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30026 -m[arm]3 Arm 3 processor
30027 -m[arm]6[xx], Arm 6 processors
30028 -m[arm]7[xx][t][[d]m] Arm 7 processors
30029 -m[arm]8[10] Arm 8 processors
30030 -m[arm]9[20][tdmi] Arm 9 processors
30031 -mstrongarm[110[0]] StrongARM processors
30032 -mxscale XScale processors
30033 -m[arm]v[2345[t[e]]] Arm architectures
30034 -mall All (except the ARM1)
30035 FP variants:
30036 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
30037 -mfpe-old (No float load/store multiples)
30038 -mvfpxd VFP Single precision
30039 -mvfp All VFP
30040 -mno-fpu Disable all floating point instructions
b99bd4ef 30041
c19d1205
ZW
30042 The following CPU names are recognized:
30043 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
30044 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
30045 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
30046 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
30047 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
30048 arm10t arm10e, arm1020t, arm1020e, arm10200e,
30049 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 30050
c19d1205 30051 */
b99bd4ef 30052
c19d1205 30053const char * md_shortopts = "m:k";
b99bd4ef 30054
c19d1205
ZW
30055#ifdef ARM_BI_ENDIAN
30056#define OPTION_EB (OPTION_MD_BASE + 0)
30057#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 30058#else
c19d1205
ZW
30059#if TARGET_BYTES_BIG_ENDIAN
30060#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 30061#else
c19d1205
ZW
30062#define OPTION_EL (OPTION_MD_BASE + 1)
30063#endif
b99bd4ef 30064#endif
845b51d6 30065#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 30066#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 30067
c19d1205 30068struct option md_longopts[] =
b99bd4ef 30069{
c19d1205
ZW
30070#ifdef OPTION_EB
30071 {"EB", no_argument, NULL, OPTION_EB},
30072#endif
30073#ifdef OPTION_EL
30074 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 30075#endif
845b51d6 30076 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
30077#ifdef OBJ_ELF
30078 {"fdpic", no_argument, NULL, OPTION_FDPIC},
30079#endif
c19d1205
ZW
30080 {NULL, no_argument, NULL, 0}
30081};
b99bd4ef 30082
c19d1205 30083size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 30084
c19d1205 30085struct arm_option_table
b99bd4ef 30086{
0198d5e6
TC
30087 const char * option; /* Option name to match. */
30088 const char * help; /* Help information. */
30089 int * var; /* Variable to change. */
30090 int value; /* What to change it to. */
30091 const char * deprecated; /* If non-null, print this message. */
c19d1205 30092};
b99bd4ef 30093
c19d1205
ZW
30094struct arm_option_table arm_opts[] =
30095{
30096 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
30097 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
30098 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
30099 &support_interwork, 1, NULL},
30100 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
30101 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
30102 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
30103 1, NULL},
30104 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
30105 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
30106 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
30107 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
30108 NULL},
b99bd4ef 30109
c19d1205
ZW
30110 /* These are recognized by the assembler, but have no affect on code. */
30111 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
30112 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
30113
30114 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
30115 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
30116 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
30117 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
30118 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
30119 {NULL, NULL, NULL, 0, NULL}
30120};
30121
30122struct arm_legacy_option_table
30123{
0198d5e6
TC
30124 const char * option; /* Option name to match. */
30125 const arm_feature_set ** var; /* Variable to change. */
30126 const arm_feature_set value; /* What to change it to. */
30127 const char * deprecated; /* If non-null, print this message. */
e74cfd16 30128};
b99bd4ef 30129
e74cfd16
PB
30130const struct arm_legacy_option_table arm_legacy_opts[] =
30131{
c19d1205
ZW
30132 /* DON'T add any new processors to this list -- we want the whole list
30133 to go away... Add them to the processors table instead. */
e74cfd16
PB
30134 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30135 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30136 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30137 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30138 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30139 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30140 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30141 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30142 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30143 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30144 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30145 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30146 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30147 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30148 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30149 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30150 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30151 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30152 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30153 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30154 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30155 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30156 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30157 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30158 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30159 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30160 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30161 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30162 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30163 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30164 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30165 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30166 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30167 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30168 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30169 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30170 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30171 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30172 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30173 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30174 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30175 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30176 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30177 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30178 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30179 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30180 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30181 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30182 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30183 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30184 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30185 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30186 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30187 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30188 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30189 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30190 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30191 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30192 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30193 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30194 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30195 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30196 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30197 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30198 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30199 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30200 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30201 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30202 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
30203 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30204 N_("use -mcpu=strongarm110")},
e74cfd16 30205 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30206 N_("use -mcpu=strongarm1100")},
e74cfd16 30207 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30208 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
30209 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
30210 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
30211 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 30212
c19d1205 30213 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
30214 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30215 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30216 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30217 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30218 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30219 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30220 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30221 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30222 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30223 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30224 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30225 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30226 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30227 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30228 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30229 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30230 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30231 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 30232
c19d1205 30233 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
30234 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
30235 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
30236 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
30237 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 30238 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 30239
e74cfd16 30240 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 30241};
7ed4c4c5 30242
c19d1205 30243struct arm_cpu_option_table
7ed4c4c5 30244{
0198d5e6
TC
30245 const char * name;
30246 size_t name_len;
30247 const arm_feature_set value;
30248 const arm_feature_set ext;
c19d1205
ZW
30249 /* For some CPUs we assume an FPU unless the user explicitly sets
30250 -mfpu=... */
0198d5e6 30251 const arm_feature_set default_fpu;
ee065d83
PB
30252 /* The canonical name of the CPU, or NULL to use NAME converted to upper
30253 case. */
0198d5e6 30254 const char * canonical_name;
c19d1205 30255};
7ed4c4c5 30256
c19d1205
ZW
30257/* This list should, at a minimum, contain all the cpu names
30258 recognized by GCC. */
996b5569 30259#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 30260
e74cfd16 30261static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 30262{
996b5569
TP
30263 ARM_CPU_OPT ("all", NULL, ARM_ANY,
30264 ARM_ARCH_NONE,
30265 FPU_ARCH_FPA),
30266 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
30267 ARM_ARCH_NONE,
30268 FPU_ARCH_FPA),
30269 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
30270 ARM_ARCH_NONE,
30271 FPU_ARCH_FPA),
30272 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
30273 ARM_ARCH_NONE,
30274 FPU_ARCH_FPA),
30275 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
30276 ARM_ARCH_NONE,
30277 FPU_ARCH_FPA),
30278 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
30279 ARM_ARCH_NONE,
30280 FPU_ARCH_FPA),
30281 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
30282 ARM_ARCH_NONE,
30283 FPU_ARCH_FPA),
30284 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
30285 ARM_ARCH_NONE,
30286 FPU_ARCH_FPA),
30287 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
30288 ARM_ARCH_NONE,
30289 FPU_ARCH_FPA),
30290 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
30291 ARM_ARCH_NONE,
30292 FPU_ARCH_FPA),
30293 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
30294 ARM_ARCH_NONE,
30295 FPU_ARCH_FPA),
30296 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
30297 ARM_ARCH_NONE,
30298 FPU_ARCH_FPA),
30299 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
30300 ARM_ARCH_NONE,
30301 FPU_ARCH_FPA),
30302 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
30303 ARM_ARCH_NONE,
30304 FPU_ARCH_FPA),
30305 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
30306 ARM_ARCH_NONE,
30307 FPU_ARCH_FPA),
30308 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
30309 ARM_ARCH_NONE,
30310 FPU_ARCH_FPA),
30311 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
30312 ARM_ARCH_NONE,
30313 FPU_ARCH_FPA),
30314 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
30315 ARM_ARCH_NONE,
30316 FPU_ARCH_FPA),
30317 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
30318 ARM_ARCH_NONE,
30319 FPU_ARCH_FPA),
30320 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
30321 ARM_ARCH_NONE,
30322 FPU_ARCH_FPA),
30323 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
30324 ARM_ARCH_NONE,
30325 FPU_ARCH_FPA),
30326 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
30327 ARM_ARCH_NONE,
30328 FPU_ARCH_FPA),
30329 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
30330 ARM_ARCH_NONE,
30331 FPU_ARCH_FPA),
30332 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
30333 ARM_ARCH_NONE,
30334 FPU_ARCH_FPA),
30335 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
30336 ARM_ARCH_NONE,
30337 FPU_ARCH_FPA),
30338 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
30339 ARM_ARCH_NONE,
30340 FPU_ARCH_FPA),
30341 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
30342 ARM_ARCH_NONE,
30343 FPU_ARCH_FPA),
30344 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
30345 ARM_ARCH_NONE,
30346 FPU_ARCH_FPA),
30347 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
30348 ARM_ARCH_NONE,
30349 FPU_ARCH_FPA),
30350 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
30351 ARM_ARCH_NONE,
30352 FPU_ARCH_FPA),
30353 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
30354 ARM_ARCH_NONE,
30355 FPU_ARCH_FPA),
30356 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
30357 ARM_ARCH_NONE,
30358 FPU_ARCH_FPA),
30359 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
30360 ARM_ARCH_NONE,
30361 FPU_ARCH_FPA),
30362 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
30363 ARM_ARCH_NONE,
30364 FPU_ARCH_FPA),
30365 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
30366 ARM_ARCH_NONE,
30367 FPU_ARCH_FPA),
30368 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
30369 ARM_ARCH_NONE,
30370 FPU_ARCH_FPA),
30371 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
30372 ARM_ARCH_NONE,
30373 FPU_ARCH_FPA),
30374 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
30375 ARM_ARCH_NONE,
30376 FPU_ARCH_FPA),
30377 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
30378 ARM_ARCH_NONE,
30379 FPU_ARCH_FPA),
30380 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
30381 ARM_ARCH_NONE,
30382 FPU_ARCH_FPA),
30383 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
30384 ARM_ARCH_NONE,
30385 FPU_ARCH_FPA),
30386 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
30387 ARM_ARCH_NONE,
30388 FPU_ARCH_FPA),
30389 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
30390 ARM_ARCH_NONE,
30391 FPU_ARCH_FPA),
30392 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
30393 ARM_ARCH_NONE,
30394 FPU_ARCH_FPA),
30395 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
30396 ARM_ARCH_NONE,
30397 FPU_ARCH_FPA),
30398 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
30399 ARM_ARCH_NONE,
30400 FPU_ARCH_FPA),
30401
c19d1205
ZW
30402 /* For V5 or later processors we default to using VFP; but the user
30403 should really set the FPU type explicitly. */
996b5569
TP
30404 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
30405 ARM_ARCH_NONE,
30406 FPU_ARCH_VFP_V2),
30407 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
30408 ARM_ARCH_NONE,
30409 FPU_ARCH_VFP_V2),
30410 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30411 ARM_ARCH_NONE,
30412 FPU_ARCH_VFP_V2),
30413 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30414 ARM_ARCH_NONE,
30415 FPU_ARCH_VFP_V2),
30416 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
30417 ARM_ARCH_NONE,
30418 FPU_ARCH_VFP_V2),
30419 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
30420 ARM_ARCH_NONE,
30421 FPU_ARCH_VFP_V2),
30422 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
30423 ARM_ARCH_NONE,
30424 FPU_ARCH_VFP_V2),
30425 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
30426 ARM_ARCH_NONE,
30427 FPU_ARCH_VFP_V2),
30428 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
30429 ARM_ARCH_NONE,
30430 FPU_ARCH_VFP_V2),
30431 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
30432 ARM_ARCH_NONE,
30433 FPU_ARCH_VFP_V2),
30434 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
30435 ARM_ARCH_NONE,
30436 FPU_ARCH_VFP_V2),
30437 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
30438 ARM_ARCH_NONE,
30439 FPU_ARCH_VFP_V2),
30440 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
30441 ARM_ARCH_NONE,
30442 FPU_ARCH_VFP_V1),
30443 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
30444 ARM_ARCH_NONE,
30445 FPU_ARCH_VFP_V1),
30446 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
30447 ARM_ARCH_NONE,
30448 FPU_ARCH_VFP_V2),
30449 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
30450 ARM_ARCH_NONE,
30451 FPU_ARCH_VFP_V2),
30452 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
30453 ARM_ARCH_NONE,
30454 FPU_ARCH_VFP_V1),
30455 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
30456 ARM_ARCH_NONE,
30457 FPU_ARCH_VFP_V2),
30458 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
30459 ARM_ARCH_NONE,
30460 FPU_ARCH_VFP_V2),
30461 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
30462 ARM_ARCH_NONE,
30463 FPU_ARCH_VFP_V2),
30464 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
30465 ARM_ARCH_NONE,
30466 FPU_ARCH_VFP_V2),
30467 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
30468 ARM_ARCH_NONE,
30469 FPU_ARCH_VFP_V2),
30470 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
30471 ARM_ARCH_NONE,
30472 FPU_ARCH_VFP_V2),
30473 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
30474 ARM_ARCH_NONE,
30475 FPU_ARCH_VFP_V2),
30476 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
30477 ARM_ARCH_NONE,
30478 FPU_ARCH_VFP_V2),
30479 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
30480 ARM_ARCH_NONE,
30481 FPU_ARCH_VFP_V2),
30482 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
30483 ARM_ARCH_NONE,
30484 FPU_NONE),
30485 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
30486 ARM_ARCH_NONE,
30487 FPU_NONE),
30488 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
30489 ARM_ARCH_NONE,
30490 FPU_ARCH_VFP_V2),
30491 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
30492 ARM_ARCH_NONE,
30493 FPU_ARCH_VFP_V2),
30494 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
30495 ARM_ARCH_NONE,
30496 FPU_ARCH_VFP_V2),
30497 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
30498 ARM_ARCH_NONE,
30499 FPU_NONE),
30500 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
30501 ARM_ARCH_NONE,
30502 FPU_NONE),
30503 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
30504 ARM_ARCH_NONE,
30505 FPU_ARCH_VFP_V2),
30506 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
30507 ARM_ARCH_NONE,
30508 FPU_NONE),
30509 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
30510 ARM_ARCH_NONE,
30511 FPU_ARCH_VFP_V2),
30512 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
30513 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30514 FPU_NONE),
30515 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
30516 ARM_ARCH_NONE,
30517 FPU_ARCH_NEON_VFP_V4),
30518 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
30519 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
30520 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30521 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
30522 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30523 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30524 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
30525 ARM_ARCH_NONE,
30526 FPU_ARCH_NEON_VFP_V4),
30527 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
30528 ARM_ARCH_NONE,
30529 FPU_ARCH_NEON_VFP_V4),
30530 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
30531 ARM_ARCH_NONE,
30532 FPU_ARCH_NEON_VFP_V4),
30533 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
30534 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30536 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
30537 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30538 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30539 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
30540 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30541 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
30542 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
30543 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 30544 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
30545 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
30546 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30547 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30548 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
30549 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30550 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30551 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
30552 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30553 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
30554 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
30555 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 30556 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 30557 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
30558 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30559 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
30560 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
30561 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30562 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
30563 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
30564 ARM_ARCH_NONE,
30565 FPU_NONE),
30566 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
30567 ARM_ARCH_NONE,
30568 FPU_ARCH_VFP_V3D16),
30569 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
30570 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30571 FPU_NONE),
30572 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
30573 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30574 FPU_ARCH_VFP_V3D16),
30575 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
30576 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30577 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
30578 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
30579 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30580 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
30581 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
30582 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30583 FPU_NONE),
30584 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
30585 ARM_ARCH_NONE,
30586 FPU_NONE),
30587 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
30588 ARM_ARCH_NONE,
30589 FPU_NONE),
30590 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
30591 ARM_ARCH_NONE,
30592 FPU_NONE),
30593 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
30594 ARM_ARCH_NONE,
30595 FPU_NONE),
30596 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
30597 ARM_ARCH_NONE,
30598 FPU_NONE),
30599 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
30600 ARM_ARCH_NONE,
30601 FPU_NONE),
30602 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
30603 ARM_ARCH_NONE,
30604 FPU_NONE),
30605 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
30606 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30607 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
30608 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
30609 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30610 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 30611 /* ??? XSCALE is really an architecture. */
996b5569
TP
30612 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
30613 ARM_ARCH_NONE,
30614 FPU_ARCH_VFP_V2),
30615
c19d1205 30616 /* ??? iwmmxt is not a processor. */
996b5569
TP
30617 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
30618 ARM_ARCH_NONE,
30619 FPU_ARCH_VFP_V2),
30620 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
30621 ARM_ARCH_NONE,
30622 FPU_ARCH_VFP_V2),
30623 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
30624 ARM_ARCH_NONE,
30625 FPU_ARCH_VFP_V2),
30626
0198d5e6 30627 /* Maverick. */
996b5569
TP
30628 ARM_CPU_OPT ("ep9312", "ARM920T",
30629 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
30630 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
30631
da4339ed 30632 /* Marvell processors. */
996b5569
TP
30633 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
30634 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30635 FPU_ARCH_VFP_V3D16),
30636 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
30637 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30638 FPU_ARCH_NEON_VFP_V4),
da4339ed 30639
996b5569
TP
30640 /* APM X-Gene family. */
30641 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
30642 ARM_ARCH_NONE,
30643 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30644 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
30645 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30646 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30647
30648 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 30649};
f3bad469 30650#undef ARM_CPU_OPT
7ed4c4c5 30651
34ef62f4
AV
30652struct arm_ext_table
30653{
30654 const char * name;
30655 size_t name_len;
30656 const arm_feature_set merge;
30657 const arm_feature_set clear;
30658};
30659
c19d1205 30660struct arm_arch_option_table
7ed4c4c5 30661{
34ef62f4
AV
30662 const char * name;
30663 size_t name_len;
30664 const arm_feature_set value;
30665 const arm_feature_set default_fpu;
30666 const struct arm_ext_table * ext_table;
30667};
30668
30669/* Used to add support for +E and +noE extension. */
30670#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
30671/* Used to add support for a +E extension. */
30672#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
30673/* Used to add support for a +noE extension. */
30674#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
30675
30676#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
30677 ~0 & ~FPU_ENDIAN_PURE)
30678
30679static const struct arm_ext_table armv5te_ext_table[] =
30680{
30681 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
30682 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30683};
30684
30685static const struct arm_ext_table armv7_ext_table[] =
30686{
30687 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30688 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30689};
30690
30691static const struct arm_ext_table armv7ve_ext_table[] =
30692{
30693 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
30694 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
30695 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30696 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30697 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30698 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
30699 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30700
30701 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
30702 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30703
30704 /* Aliases for +simd. */
30705 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30706
30707 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30708 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30709 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30710
30711 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30712};
30713
30714static const struct arm_ext_table armv7a_ext_table[] =
30715{
30716 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30717 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30718 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30719 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30720 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30721 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
30722 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30723
30724 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
30725 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30726
30727 /* Aliases for +simd. */
30728 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30729 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30730
30731 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30732 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30733
30734 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
30735 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
30736 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30737};
30738
30739static const struct arm_ext_table armv7r_ext_table[] =
30740{
30741 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
30742 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
30743 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30744 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30745 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
30746 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30747 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
30748 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
30749 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30750};
30751
30752static const struct arm_ext_table armv7em_ext_table[] =
30753{
30754 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
30755 /* Alias for +fp, used to be known as fpv4-sp-d16. */
30756 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
30757 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
30758 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30759 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
30760 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30761};
30762
30763static const struct arm_ext_table armv8a_ext_table[] =
30764{
30765 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30766 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30767 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30768 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30769
30770 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30771 should use the +simd option to turn on FP. */
30772 ARM_REMOVE ("fp", ALL_FP),
30773 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30774 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30775 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30776};
30777
30778
30779static const struct arm_ext_table armv81a_ext_table[] =
30780{
30781 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30782 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30783 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30784
30785 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30786 should use the +simd option to turn on FP. */
30787 ARM_REMOVE ("fp", ALL_FP),
30788 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30789 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30790 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30791};
30792
30793static const struct arm_ext_table armv82a_ext_table[] =
30794{
30795 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30796 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
30797 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
30798 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30799 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30800 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30801
30802 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30803 should use the +simd option to turn on FP. */
30804 ARM_REMOVE ("fp", ALL_FP),
30805 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30806 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30807 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30808};
30809
30810static const struct arm_ext_table armv84a_ext_table[] =
30811{
30812 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30813 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30814 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30815 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30816
30817 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30818 should use the +simd option to turn on FP. */
30819 ARM_REMOVE ("fp", ALL_FP),
30820 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30821 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30822 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30823};
30824
30825static const struct arm_ext_table armv85a_ext_table[] =
30826{
30827 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30828 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30829 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30830 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30831
30832 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30833 should use the +simd option to turn on FP. */
30834 ARM_REMOVE ("fp", ALL_FP),
30835 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30836};
30837
30838static const struct arm_ext_table armv8m_main_ext_table[] =
30839{
30840 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30841 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30842 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
30843 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30844 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30845};
30846
e0991585
AV
30847static const struct arm_ext_table armv8_1m_main_ext_table[] =
30848{
30849 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30850 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30851 ARM_EXT ("fp",
30852 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30853 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
30854 ALL_FP),
30855 ARM_ADD ("fp.dp",
30856 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30857 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
a7ad558c
AV
30858 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
30859 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
30860 ARM_ADD ("mve.fp",
30861 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30862 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
30863 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
e0991585
AV
30864 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30865};
30866
34ef62f4
AV
30867static const struct arm_ext_table armv8r_ext_table[] =
30868{
30869 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30870 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30871 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30872 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30873 ARM_REMOVE ("fp", ALL_FP),
30874 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
30875 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 30876};
7ed4c4c5 30877
c19d1205
ZW
30878/* This list should, at a minimum, contain all the architecture names
30879 recognized by GCC. */
34ef62f4
AV
30880#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
30881#define ARM_ARCH_OPT2(N, V, DF, ext) \
30882 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 30883
e74cfd16 30884static const struct arm_arch_option_table arm_archs[] =
c19d1205 30885{
497d849d
TP
30886 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
30887 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
30888 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
30889 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
30890 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
30891 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
30892 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
30893 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
30894 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
30895 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
30896 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
30897 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
30898 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
30899 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
30900 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
30901 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
30902 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
30903 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30904 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30905 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
30906 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
30907 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
30908 kept to preserve existing behaviour. */
34ef62f4
AV
30909 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
30910 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
30911 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
30912 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
30913 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
30914 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
30915 kept to preserve existing behaviour. */
34ef62f4
AV
30916 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
30917 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
30918 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
30919 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 30920 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
30921 /* The official spelling of the ARMv7 profile variants is the dashed form.
30922 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
30923 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
30924 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
30925 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 30926 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
30927 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
30928 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 30929 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 30930 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 30931 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
30932 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
30933 armv8m_main),
e0991585
AV
30934 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
30935 armv8_1m_main),
34ef62f4
AV
30936 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
30937 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
30938 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
30939 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
30940 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
30941 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
30942 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
30943 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
30944 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
30945 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 30946 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 30947};
f3bad469 30948#undef ARM_ARCH_OPT
7ed4c4c5 30949
69133863 30950/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 30951
69133863 30952struct arm_option_extension_value_table
c19d1205 30953{
0198d5e6
TC
30954 const char * name;
30955 size_t name_len;
30956 const arm_feature_set merge_value;
30957 const arm_feature_set clear_value;
d942732e
TP
30958 /* List of architectures for which an extension is available. ARM_ARCH_NONE
30959 indicates that an extension is available for all architectures while
30960 ARM_ANY marks an empty entry. */
0198d5e6 30961 const arm_feature_set allowed_archs[2];
c19d1205 30962};
7ed4c4c5 30963
0198d5e6
TC
30964/* The following table must be in alphabetical order with a NULL last entry. */
30965
d942732e
TP
30966#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
30967#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 30968
34ef62f4
AV
30969/* DEPRECATED: Refrain from using this table to add any new extensions, instead
30970 use the context sensitive approach using arm_ext_table's. */
69133863 30971static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 30972{
823d2571
TG
30973 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30974 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 30975 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
30976 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
30977 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
30978 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
30979 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
30980 ARM_ARCH_V8_2A),
15afaa63
TP
30981 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30982 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30983 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
30984 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
30985 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
30986 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30987 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30988 ARM_ARCH_V8_2A),
01f48020
TC
30989 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30990 | ARM_EXT2_FP16_FML),
30991 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30992 | ARM_EXT2_FP16_FML),
30993 ARM_ARCH_V8_2A),
d942732e 30994 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 30995 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
30996 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
30997 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
30998 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
30999 Thumb divide instruction. Due to this having the same name as the
31000 previous entry, this will be ignored when doing command-line parsing and
31001 only considered by build attribute selection code. */
31002 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31003 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31004 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 31005 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 31006 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 31007 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 31008 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 31009 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
31010 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
31011 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 31012 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
31013 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31014 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
31015 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31016 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31017 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
31018 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
31019 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 31020 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
31021 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31022 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31023 ARM_ARCH_V8A),
4d1464f2
MW
31024 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
31025 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 31026 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
31027 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
31028 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 31029 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
31030 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31031 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31032 ARM_ARCH_V8A),
d942732e 31033 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 31034 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
31035 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
31036 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
31037 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
31038 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
31039 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
31040 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
31041 | ARM_EXT_DIV),
31042 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
31043 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31044 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
31045 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
31046 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 31047};
f3bad469 31048#undef ARM_EXT_OPT
69133863
MGD
31049
31050/* ISA floating-point and Advanced SIMD extensions. */
31051struct arm_option_fpu_value_table
31052{
0198d5e6
TC
31053 const char * name;
31054 const arm_feature_set value;
c19d1205 31055};
7ed4c4c5 31056
c19d1205
ZW
31057/* This list should, at a minimum, contain all the fpu names
31058 recognized by GCC. */
69133863 31059static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
31060{
31061 {"softfpa", FPU_NONE},
31062 {"fpe", FPU_ARCH_FPE},
31063 {"fpe2", FPU_ARCH_FPE},
31064 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
31065 {"fpa", FPU_ARCH_FPA},
31066 {"fpa10", FPU_ARCH_FPA},
31067 {"fpa11", FPU_ARCH_FPA},
31068 {"arm7500fe", FPU_ARCH_FPA},
31069 {"softvfp", FPU_ARCH_VFP},
31070 {"softvfp+vfp", FPU_ARCH_VFP_V2},
31071 {"vfp", FPU_ARCH_VFP_V2},
31072 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 31073 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
31074 {"vfp10", FPU_ARCH_VFP_V2},
31075 {"vfp10-r0", FPU_ARCH_VFP_V1},
31076 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
31077 {"vfpv2", FPU_ARCH_VFP_V2},
31078 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 31079 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 31080 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
31081 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
31082 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
31083 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
31084 {"arm1020t", FPU_ARCH_VFP_V1},
31085 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 31086 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
31087 {"arm1136jf-s", FPU_ARCH_VFP_V2},
31088 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 31089 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 31090 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 31091 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
31092 {"vfpv4", FPU_ARCH_VFP_V4},
31093 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 31094 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
31095 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
31096 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 31097 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
31098 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
31099 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
31100 {"crypto-neon-fp-armv8",
31101 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 31102 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
31103 {"crypto-neon-fp-armv8.1",
31104 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
31105 {NULL, ARM_ARCH_NONE}
31106};
31107
31108struct arm_option_value_table
31109{
e0471c16 31110 const char *name;
e74cfd16 31111 long value;
c19d1205 31112};
7ed4c4c5 31113
e74cfd16 31114static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
31115{
31116 {"hard", ARM_FLOAT_ABI_HARD},
31117 {"softfp", ARM_FLOAT_ABI_SOFTFP},
31118 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 31119 {NULL, 0}
c19d1205 31120};
7ed4c4c5 31121
c19d1205 31122#ifdef OBJ_ELF
3a4a14e9 31123/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 31124static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
31125{
31126 {"gnu", EF_ARM_EABI_UNKNOWN},
31127 {"4", EF_ARM_EABI_VER4},
3a4a14e9 31128 {"5", EF_ARM_EABI_VER5},
e74cfd16 31129 {NULL, 0}
c19d1205
ZW
31130};
31131#endif
7ed4c4c5 31132
c19d1205
ZW
31133struct arm_long_option_table
31134{
0198d5e6 31135 const char * option; /* Substring to match. */
e0471c16 31136 const char * help; /* Help information. */
17b9d67d 31137 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 31138 const char * deprecated; /* If non-null, print this message. */
c19d1205 31139};
7ed4c4c5 31140
c921be7d 31141static bfd_boolean
c168ce07 31142arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
31143 arm_feature_set *ext_set,
31144 const struct arm_ext_table *ext_table)
7ed4c4c5 31145{
69133863 31146 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
31147 extensions being added before being removed. We achieve this by having
31148 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 31149 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 31150 or removing it (0) and only allowing it to change in the order
69133863
MGD
31151 -1 -> 1 -> 0. */
31152 const struct arm_option_extension_value_table * opt = NULL;
d942732e 31153 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
31154 int adding_value = -1;
31155
c19d1205 31156 while (str != NULL && *str != 0)
7ed4c4c5 31157 {
82b8a785 31158 const char *ext;
f3bad469 31159 size_t len;
7ed4c4c5 31160
c19d1205
ZW
31161 if (*str != '+')
31162 {
31163 as_bad (_("invalid architectural extension"));
c921be7d 31164 return FALSE;
c19d1205 31165 }
7ed4c4c5 31166
c19d1205
ZW
31167 str++;
31168 ext = strchr (str, '+');
7ed4c4c5 31169
c19d1205 31170 if (ext != NULL)
f3bad469 31171 len = ext - str;
c19d1205 31172 else
f3bad469 31173 len = strlen (str);
7ed4c4c5 31174
f3bad469 31175 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
31176 {
31177 if (adding_value != 0)
31178 {
31179 adding_value = 0;
31180 opt = arm_extensions;
31181 }
31182
f3bad469 31183 len -= 2;
69133863
MGD
31184 str += 2;
31185 }
f3bad469 31186 else if (len > 0)
69133863
MGD
31187 {
31188 if (adding_value == -1)
31189 {
31190 adding_value = 1;
31191 opt = arm_extensions;
31192 }
31193 else if (adding_value != 1)
31194 {
31195 as_bad (_("must specify extensions to add before specifying "
31196 "those to remove"));
31197 return FALSE;
31198 }
31199 }
31200
f3bad469 31201 if (len == 0)
c19d1205
ZW
31202 {
31203 as_bad (_("missing architectural extension"));
c921be7d 31204 return FALSE;
c19d1205 31205 }
7ed4c4c5 31206
69133863
MGD
31207 gas_assert (adding_value != -1);
31208 gas_assert (opt != NULL);
31209
34ef62f4
AV
31210 if (ext_table != NULL)
31211 {
31212 const struct arm_ext_table * ext_opt = ext_table;
31213 bfd_boolean found = FALSE;
31214 for (; ext_opt->name != NULL; ext_opt++)
31215 if (ext_opt->name_len == len
31216 && strncmp (ext_opt->name, str, len) == 0)
31217 {
31218 if (adding_value)
31219 {
31220 if (ARM_FEATURE_ZERO (ext_opt->merge))
31221 /* TODO: Option not supported. When we remove the
31222 legacy table this case should error out. */
31223 continue;
31224
31225 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
31226 }
31227 else
31228 {
31229 if (ARM_FEATURE_ZERO (ext_opt->clear))
31230 /* TODO: Option not supported. When we remove the
31231 legacy table this case should error out. */
31232 continue;
31233 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
31234 }
31235 found = TRUE;
31236 break;
31237 }
31238 if (found)
31239 {
31240 str = ext;
31241 continue;
31242 }
31243 }
31244
69133863
MGD
31245 /* Scan over the options table trying to find an exact match. */
31246 for (; opt->name != NULL; opt++)
f3bad469 31247 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31248 {
d942732e
TP
31249 int i, nb_allowed_archs =
31250 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 31251 /* Check we can apply the extension to this architecture. */
d942732e
TP
31252 for (i = 0; i < nb_allowed_archs; i++)
31253 {
31254 /* Empty entry. */
31255 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
31256 continue;
c168ce07 31257 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
31258 break;
31259 }
31260 if (i == nb_allowed_archs)
69133863
MGD
31261 {
31262 as_bad (_("extension does not apply to the base architecture"));
31263 return FALSE;
31264 }
31265
31266 /* Add or remove the extension. */
31267 if (adding_value)
4d354d8b 31268 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 31269 else
4d354d8b 31270 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 31271
3d030cdb
TP
31272 /* Allowing Thumb division instructions for ARMv7 in autodetection
31273 rely on this break so that duplicate extensions (extensions
31274 with the same name as a previous extension in the list) are not
31275 considered for command-line parsing. */
c19d1205
ZW
31276 break;
31277 }
7ed4c4c5 31278
c19d1205
ZW
31279 if (opt->name == NULL)
31280 {
69133863
MGD
31281 /* Did we fail to find an extension because it wasn't specified in
31282 alphabetical order, or because it does not exist? */
31283
31284 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 31285 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
31286 break;
31287
31288 if (opt->name == NULL)
31289 as_bad (_("unknown architectural extension `%s'"), str);
31290 else
31291 as_bad (_("architectural extensions must be specified in "
31292 "alphabetical order"));
31293
c921be7d 31294 return FALSE;
c19d1205 31295 }
69133863
MGD
31296 else
31297 {
31298 /* We should skip the extension we've just matched the next time
31299 round. */
31300 opt++;
31301 }
7ed4c4c5 31302
c19d1205
ZW
31303 str = ext;
31304 };
7ed4c4c5 31305
c921be7d 31306 return TRUE;
c19d1205 31307}
7ed4c4c5 31308
5312fe52
BW
31309static bfd_boolean
31310arm_parse_fp16_opt (const char *str)
31311{
31312 if (strcasecmp (str, "ieee") == 0)
31313 fp16_format = ARM_FP16_FORMAT_IEEE;
31314 else if (strcasecmp (str, "alternative") == 0)
31315 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
31316 else
31317 {
31318 as_bad (_("unrecognised float16 format \"%s\""), str);
31319 return FALSE;
31320 }
31321
31322 return TRUE;
31323}
31324
c921be7d 31325static bfd_boolean
17b9d67d 31326arm_parse_cpu (const char *str)
7ed4c4c5 31327{
f3bad469 31328 const struct arm_cpu_option_table *opt;
82b8a785 31329 const char *ext = strchr (str, '+');
f3bad469 31330 size_t len;
7ed4c4c5 31331
c19d1205 31332 if (ext != NULL)
f3bad469 31333 len = ext - str;
7ed4c4c5 31334 else
f3bad469 31335 len = strlen (str);
7ed4c4c5 31336
f3bad469 31337 if (len == 0)
7ed4c4c5 31338 {
c19d1205 31339 as_bad (_("missing cpu name `%s'"), str);
c921be7d 31340 return FALSE;
7ed4c4c5
NC
31341 }
31342
c19d1205 31343 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 31344 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31345 {
c168ce07 31346 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
31347 if (mcpu_ext_opt == NULL)
31348 mcpu_ext_opt = XNEW (arm_feature_set);
31349 *mcpu_ext_opt = opt->ext;
e74cfd16 31350 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 31351 if (opt->canonical_name)
ef8e6722
JW
31352 {
31353 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
31354 strcpy (selected_cpu_name, opt->canonical_name);
31355 }
ee065d83
PB
31356 else
31357 {
f3bad469 31358 size_t i;
c921be7d 31359
ef8e6722
JW
31360 if (len >= sizeof selected_cpu_name)
31361 len = (sizeof selected_cpu_name) - 1;
31362
f3bad469 31363 for (i = 0; i < len; i++)
ee065d83
PB
31364 selected_cpu_name[i] = TOUPPER (opt->name[i]);
31365 selected_cpu_name[i] = 0;
31366 }
7ed4c4c5 31367
c19d1205 31368 if (ext != NULL)
34ef62f4 31369 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 31370
c921be7d 31371 return TRUE;
c19d1205 31372 }
7ed4c4c5 31373
c19d1205 31374 as_bad (_("unknown cpu `%s'"), str);
c921be7d 31375 return FALSE;
7ed4c4c5
NC
31376}
31377
c921be7d 31378static bfd_boolean
17b9d67d 31379arm_parse_arch (const char *str)
7ed4c4c5 31380{
e74cfd16 31381 const struct arm_arch_option_table *opt;
82b8a785 31382 const char *ext = strchr (str, '+');
f3bad469 31383 size_t len;
7ed4c4c5 31384
c19d1205 31385 if (ext != NULL)
f3bad469 31386 len = ext - str;
7ed4c4c5 31387 else
f3bad469 31388 len = strlen (str);
7ed4c4c5 31389
f3bad469 31390 if (len == 0)
7ed4c4c5 31391 {
c19d1205 31392 as_bad (_("missing architecture name `%s'"), str);
c921be7d 31393 return FALSE;
7ed4c4c5
NC
31394 }
31395
c19d1205 31396 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 31397 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31398 {
e74cfd16 31399 march_cpu_opt = &opt->value;
4d354d8b
TP
31400 if (march_ext_opt == NULL)
31401 march_ext_opt = XNEW (arm_feature_set);
31402 *march_ext_opt = arm_arch_none;
e74cfd16 31403 march_fpu_opt = &opt->default_fpu;
5f4273c7 31404 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 31405
c19d1205 31406 if (ext != NULL)
34ef62f4
AV
31407 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
31408 opt->ext_table);
7ed4c4c5 31409
c921be7d 31410 return TRUE;
c19d1205
ZW
31411 }
31412
31413 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 31414 return FALSE;
7ed4c4c5 31415}
eb043451 31416
c921be7d 31417static bfd_boolean
17b9d67d 31418arm_parse_fpu (const char * str)
c19d1205 31419{
69133863 31420 const struct arm_option_fpu_value_table * opt;
b99bd4ef 31421
c19d1205
ZW
31422 for (opt = arm_fpus; opt->name != NULL; opt++)
31423 if (streq (opt->name, str))
31424 {
e74cfd16 31425 mfpu_opt = &opt->value;
c921be7d 31426 return TRUE;
c19d1205 31427 }
b99bd4ef 31428
c19d1205 31429 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 31430 return FALSE;
c19d1205
ZW
31431}
31432
c921be7d 31433static bfd_boolean
17b9d67d 31434arm_parse_float_abi (const char * str)
b99bd4ef 31435{
e74cfd16 31436 const struct arm_option_value_table * opt;
b99bd4ef 31437
c19d1205
ZW
31438 for (opt = arm_float_abis; opt->name != NULL; opt++)
31439 if (streq (opt->name, str))
31440 {
31441 mfloat_abi_opt = opt->value;
c921be7d 31442 return TRUE;
c19d1205 31443 }
cc8a6dd0 31444
c19d1205 31445 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 31446 return FALSE;
c19d1205 31447}
b99bd4ef 31448
c19d1205 31449#ifdef OBJ_ELF
c921be7d 31450static bfd_boolean
17b9d67d 31451arm_parse_eabi (const char * str)
c19d1205 31452{
e74cfd16 31453 const struct arm_option_value_table *opt;
cc8a6dd0 31454
c19d1205
ZW
31455 for (opt = arm_eabis; opt->name != NULL; opt++)
31456 if (streq (opt->name, str))
31457 {
31458 meabi_flags = opt->value;
c921be7d 31459 return TRUE;
c19d1205
ZW
31460 }
31461 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 31462 return FALSE;
c19d1205
ZW
31463}
31464#endif
cc8a6dd0 31465
c921be7d 31466static bfd_boolean
17b9d67d 31467arm_parse_it_mode (const char * str)
e07e6e58 31468{
c921be7d 31469 bfd_boolean ret = TRUE;
e07e6e58
NC
31470
31471 if (streq ("arm", str))
31472 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
31473 else if (streq ("thumb", str))
31474 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
31475 else if (streq ("always", str))
31476 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
31477 else if (streq ("never", str))
31478 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
31479 else
31480 {
31481 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 31482 "arm, thumb, always, or never."), str);
c921be7d 31483 ret = FALSE;
e07e6e58
NC
31484 }
31485
31486 return ret;
31487}
31488
2e6976a8 31489static bfd_boolean
17b9d67d 31490arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
31491{
31492 codecomposer_syntax = TRUE;
31493 arm_comment_chars[0] = ';';
31494 arm_line_separator_chars[0] = 0;
31495 return TRUE;
31496}
31497
c19d1205
ZW
31498struct arm_long_option_table arm_long_opts[] =
31499{
31500 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
31501 arm_parse_cpu, NULL},
31502 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
31503 arm_parse_arch, NULL},
31504 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
31505 arm_parse_fpu, NULL},
31506 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
31507 arm_parse_float_abi, NULL},
31508#ifdef OBJ_ELF
7fac0536 31509 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
31510 arm_parse_eabi, NULL},
31511#endif
e07e6e58
NC
31512 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
31513 arm_parse_it_mode, NULL},
2e6976a8
DG
31514 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
31515 arm_ccs_mode, NULL},
5312fe52
BW
31516 {"mfp16-format=",
31517 N_("[ieee|alternative]\n\
31518 set the encoding for half precision floating point "
31519 "numbers to IEEE\n\
31520 or Arm alternative format."),
31521 arm_parse_fp16_opt, NULL },
c19d1205
ZW
31522 {NULL, NULL, 0, NULL}
31523};
cc8a6dd0 31524
c19d1205 31525int
17b9d67d 31526md_parse_option (int c, const char * arg)
c19d1205
ZW
31527{
31528 struct arm_option_table *opt;
e74cfd16 31529 const struct arm_legacy_option_table *fopt;
c19d1205 31530 struct arm_long_option_table *lopt;
b99bd4ef 31531
c19d1205 31532 switch (c)
b99bd4ef 31533 {
c19d1205
ZW
31534#ifdef OPTION_EB
31535 case OPTION_EB:
31536 target_big_endian = 1;
31537 break;
31538#endif
cc8a6dd0 31539
c19d1205
ZW
31540#ifdef OPTION_EL
31541 case OPTION_EL:
31542 target_big_endian = 0;
31543 break;
31544#endif
b99bd4ef 31545
845b51d6
PB
31546 case OPTION_FIX_V4BX:
31547 fix_v4bx = TRUE;
31548 break;
31549
18a20338
CL
31550#ifdef OBJ_ELF
31551 case OPTION_FDPIC:
31552 arm_fdpic = TRUE;
31553 break;
31554#endif /* OBJ_ELF */
31555
c19d1205
ZW
31556 case 'a':
31557 /* Listing option. Just ignore these, we don't support additional
31558 ones. */
31559 return 0;
b99bd4ef 31560
c19d1205
ZW
31561 default:
31562 for (opt = arm_opts; opt->option != NULL; opt++)
31563 {
31564 if (c == opt->option[0]
31565 && ((arg == NULL && opt->option[1] == 0)
31566 || streq (arg, opt->option + 1)))
31567 {
c19d1205 31568 /* If the option is deprecated, tell the user. */
278df34e 31569 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
31570 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31571 arg ? arg : "", _(opt->deprecated));
b99bd4ef 31572
c19d1205
ZW
31573 if (opt->var != NULL)
31574 *opt->var = opt->value;
cc8a6dd0 31575
c19d1205
ZW
31576 return 1;
31577 }
31578 }
b99bd4ef 31579
e74cfd16
PB
31580 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
31581 {
31582 if (c == fopt->option[0]
31583 && ((arg == NULL && fopt->option[1] == 0)
31584 || streq (arg, fopt->option + 1)))
31585 {
e74cfd16 31586 /* If the option is deprecated, tell the user. */
278df34e 31587 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
31588 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31589 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
31590
31591 if (fopt->var != NULL)
31592 *fopt->var = &fopt->value;
31593
31594 return 1;
31595 }
31596 }
31597
c19d1205
ZW
31598 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31599 {
31600 /* These options are expected to have an argument. */
31601 if (c == lopt->option[0]
31602 && arg != NULL
31603 && strncmp (arg, lopt->option + 1,
31604 strlen (lopt->option + 1)) == 0)
31605 {
c19d1205 31606 /* If the option is deprecated, tell the user. */
278df34e 31607 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
31608 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
31609 _(lopt->deprecated));
b99bd4ef 31610
c19d1205
ZW
31611 /* Call the sup-option parser. */
31612 return lopt->func (arg + strlen (lopt->option) - 1);
31613 }
31614 }
a737bd4d 31615
c19d1205
ZW
31616 return 0;
31617 }
a394c00f 31618
c19d1205
ZW
31619 return 1;
31620}
a394c00f 31621
c19d1205
ZW
31622void
31623md_show_usage (FILE * fp)
a394c00f 31624{
c19d1205
ZW
31625 struct arm_option_table *opt;
31626 struct arm_long_option_table *lopt;
a394c00f 31627
c19d1205 31628 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 31629
c19d1205
ZW
31630 for (opt = arm_opts; opt->option != NULL; opt++)
31631 if (opt->help != NULL)
31632 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 31633
c19d1205
ZW
31634 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31635 if (lopt->help != NULL)
31636 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 31637
c19d1205
ZW
31638#ifdef OPTION_EB
31639 fprintf (fp, _("\
31640 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
31641#endif
31642
c19d1205
ZW
31643#ifdef OPTION_EL
31644 fprintf (fp, _("\
31645 -EL assemble code for a little-endian cpu\n"));
a737bd4d 31646#endif
845b51d6
PB
31647
31648 fprintf (fp, _("\
31649 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
31650
31651#ifdef OBJ_ELF
31652 fprintf (fp, _("\
31653 --fdpic generate an FDPIC object file\n"));
31654#endif /* OBJ_ELF */
c19d1205 31655}
ee065d83 31656
ee065d83 31657#ifdef OBJ_ELF
0198d5e6 31658
62b3e311
PB
31659typedef struct
31660{
31661 int val;
31662 arm_feature_set flags;
31663} cpu_arch_ver_table;
31664
2c6b98ea
TP
31665/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
31666 chronologically for architectures, with an exception for ARMv6-M and
31667 ARMv6S-M due to legacy reasons. No new architecture should have a
31668 special case. This allows for build attribute selection results to be
31669 stable when new architectures are added. */
62b3e311
PB
31670static const cpu_arch_ver_table cpu_arch_ver[] =
31671{
031254f2
AV
31672 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
31673 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
31674 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
31675 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
31676 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
31677 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
31678 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
31679 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
31680 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
31681 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
31682 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
31683 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
31684 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
31685 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
31686 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
31687 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
31688 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
31689 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
31690 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
31691 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
31692 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
31693 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
31694 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
31695 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
31696
31697 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
31698 always selected build attributes to match those of ARMv6-M
31699 (resp. ARMv6S-M). However, due to these architectures being a strict
31700 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
31701 would be selected when fully respecting chronology of architectures.
31702 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
31703 move them before ARMv7 architectures. */
031254f2
AV
31704 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
31705 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
31706
31707 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
31708 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
31709 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
31710 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
31711 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
31712 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
31713 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
31714 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
31715 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
31716 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
31717 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
31718 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
31719 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
31720 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
31721 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
31722 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
31723 {-1, ARM_ARCH_NONE}
62b3e311
PB
31724};
31725
ee3c0378 31726/* Set an attribute if it has not already been set by the user. */
0198d5e6 31727
ee3c0378
AS
31728static void
31729aeabi_set_attribute_int (int tag, int value)
31730{
31731 if (tag < 1
31732 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31733 || !attributes_set_explicitly[tag])
31734 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
31735}
31736
31737static void
31738aeabi_set_attribute_string (int tag, const char *value)
31739{
31740 if (tag < 1
31741 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31742 || !attributes_set_explicitly[tag])
31743 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
31744}
31745
2c6b98ea
TP
31746/* Return whether features in the *NEEDED feature set are available via
31747 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 31748
2c6b98ea
TP
31749static bfd_boolean
31750have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
31751 const arm_feature_set *needed)
31752{
31753 int i, nb_allowed_archs;
31754 arm_feature_set ext_fset;
31755 const struct arm_option_extension_value_table *opt;
31756
31757 ext_fset = arm_arch_none;
31758 for (opt = arm_extensions; opt->name != NULL; opt++)
31759 {
31760 /* Extension does not provide any feature we need. */
31761 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
31762 continue;
31763
31764 nb_allowed_archs =
31765 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
31766 for (i = 0; i < nb_allowed_archs; i++)
31767 {
31768 /* Empty entry. */
31769 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
31770 break;
31771
31772 /* Extension is available, add it. */
31773 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
31774 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
31775 }
31776 }
31777
31778 /* Can we enable all features in *needed? */
31779 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
31780}
31781
31782/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
31783 a given architecture feature set *ARCH_EXT_FSET including extension feature
31784 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
31785 - if true, check for an exact match of the architecture modulo extensions;
31786 - otherwise, select build attribute value of the first superset
31787 architecture released so that results remains stable when new architectures
31788 are added.
31789 For -march/-mcpu=all the build attribute value of the most featureful
31790 architecture is returned. Tag_CPU_arch_profile result is returned in
31791 PROFILE. */
0198d5e6 31792
2c6b98ea
TP
31793static int
31794get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
31795 const arm_feature_set *ext_fset,
31796 char *profile, int exact_match)
31797{
31798 arm_feature_set arch_fset;
31799 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
31800
31801 /* Select most featureful architecture with all its extensions if building
31802 for -march=all as the feature sets used to set build attributes. */
31803 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
31804 {
31805 /* Force revisiting of decision for each new architecture. */
031254f2 31806 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
31807 *profile = 'A';
31808 return TAG_CPU_ARCH_V8;
31809 }
31810
31811 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
31812
31813 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
31814 {
31815 arm_feature_set known_arch_fset;
31816
31817 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
31818 if (exact_match)
31819 {
31820 /* Base architecture match user-specified architecture and
31821 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
31822 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
31823 {
31824 p_ver_ret = p_ver;
31825 goto found;
31826 }
31827 /* Base architecture match user-specified architecture only
31828 (eg. ARMv6-M in the same case as above). Record it in case we
31829 find a match with above condition. */
31830 else if (p_ver_ret == NULL
31831 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
31832 p_ver_ret = p_ver;
31833 }
31834 else
31835 {
31836
31837 /* Architecture has all features wanted. */
31838 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
31839 {
31840 arm_feature_set added_fset;
31841
31842 /* Compute features added by this architecture over the one
31843 recorded in p_ver_ret. */
31844 if (p_ver_ret != NULL)
31845 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
31846 p_ver_ret->flags);
31847 /* First architecture that match incl. with extensions, or the
31848 only difference in features over the recorded match is
31849 features that were optional and are now mandatory. */
31850 if (p_ver_ret == NULL
31851 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
31852 {
31853 p_ver_ret = p_ver;
31854 goto found;
31855 }
31856 }
31857 else if (p_ver_ret == NULL)
31858 {
31859 arm_feature_set needed_ext_fset;
31860
31861 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
31862
31863 /* Architecture has all features needed when using some
31864 extensions. Record it and continue searching in case there
31865 exist an architecture providing all needed features without
31866 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
31867 OS extension). */
31868 if (have_ext_for_needed_feat_p (&known_arch_fset,
31869 &needed_ext_fset))
31870 p_ver_ret = p_ver;
31871 }
31872 }
31873 }
31874
31875 if (p_ver_ret == NULL)
31876 return -1;
31877
31878found:
31879 /* Tag_CPU_arch_profile. */
31880 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
31881 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
31882 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
31883 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
31884 *profile = 'A';
31885 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
31886 *profile = 'R';
31887 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
31888 *profile = 'M';
31889 else
31890 *profile = '\0';
31891 return p_ver_ret->val;
31892}
31893
ee065d83 31894/* Set the public EABI object attributes. */
0198d5e6 31895
c168ce07 31896static void
ee065d83
PB
31897aeabi_set_public_attributes (void)
31898{
b90d5ba0 31899 char profile = '\0';
2c6b98ea 31900 int arch = -1;
90ec0d68 31901 int virt_sec = 0;
bca38921 31902 int fp16_optional = 0;
2c6b98ea
TP
31903 int skip_exact_match = 0;
31904 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 31905
54bab281
TP
31906 /* Autodetection mode, choose the architecture based the instructions
31907 actually used. */
31908 if (no_cpu_selected ())
31909 {
31910 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 31911
54bab281
TP
31912 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
31913 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 31914
54bab281
TP
31915 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
31916 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 31917
54bab281 31918 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
31919 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
31920 flags_ext = arm_arch_none;
31921 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
31922 selected_ext = flags_ext;
54bab281
TP
31923 selected_cpu = flags;
31924 }
31925 /* Otherwise, choose the architecture based on the capabilities of the
31926 requested cpu. */
31927 else
4d354d8b
TP
31928 {
31929 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
31930 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
31931 flags_ext = selected_ext;
31932 flags = selected_cpu;
31933 }
31934 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 31935
ddd7f988 31936 /* Allow the user to override the reported architecture. */
4d354d8b 31937 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 31938 {
4d354d8b 31939 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 31940 flags_ext = arm_arch_none;
7a1d4c38 31941 }
2c6b98ea 31942 else
4d354d8b 31943 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
31944
31945 /* When this function is run again after relaxation has happened there is no
31946 way to determine whether an architecture or CPU was specified by the user:
31947 - selected_cpu is set above for relaxation to work;
31948 - march_cpu_opt is not set if only -mcpu or .cpu is used;
31949 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
31950 Therefore, if not in -march=all case we first try an exact match and fall
31951 back to autodetection. */
31952 if (!skip_exact_match)
31953 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
31954 if (arch == -1)
31955 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
31956 if (arch == -1)
31957 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 31958
ee065d83
PB
31959 /* Tag_CPU_name. */
31960 if (selected_cpu_name[0])
31961 {
91d6fa6a 31962 char *q;
ee065d83 31963
91d6fa6a
NC
31964 q = selected_cpu_name;
31965 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
31966 {
31967 int i;
5f4273c7 31968
91d6fa6a
NC
31969 q += 4;
31970 for (i = 0; q[i]; i++)
31971 q[i] = TOUPPER (q[i]);
ee065d83 31972 }
91d6fa6a 31973 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 31974 }
62f3b8c8 31975
ee065d83 31976 /* Tag_CPU_arch. */
ee3c0378 31977 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 31978
62b3e311 31979 /* Tag_CPU_arch_profile. */
69239280
MGD
31980 if (profile != '\0')
31981 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 31982
15afaa63 31983 /* Tag_DSP_extension. */
4d354d8b 31984 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 31985 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 31986
2c6b98ea 31987 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 31988 /* Tag_ARM_ISA_use. */
ee3c0378 31989 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 31990 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 31991 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 31992
ee065d83 31993 /* Tag_THUMB_ISA_use. */
ee3c0378 31994 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 31995 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
31996 {
31997 int thumb_isa_use;
31998
31999 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 32000 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
32001 thumb_isa_use = 3;
32002 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
32003 thumb_isa_use = 2;
32004 else
32005 thumb_isa_use = 1;
32006 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
32007 }
62f3b8c8 32008
ee065d83 32009 /* Tag_VFP_arch. */
a715796b
TG
32010 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
32011 aeabi_set_attribute_int (Tag_VFP_arch,
32012 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32013 ? 7 : 8);
bca38921 32014 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
32015 aeabi_set_attribute_int (Tag_VFP_arch,
32016 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32017 ? 5 : 6);
32018 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
32019 {
32020 fp16_optional = 1;
32021 aeabi_set_attribute_int (Tag_VFP_arch, 3);
32022 }
ada65aa3 32023 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
32024 {
32025 aeabi_set_attribute_int (Tag_VFP_arch, 4);
32026 fp16_optional = 1;
32027 }
ee3c0378
AS
32028 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
32029 aeabi_set_attribute_int (Tag_VFP_arch, 2);
32030 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 32031 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 32032 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 32033
4547cb56
NC
32034 /* Tag_ABI_HardFP_use. */
32035 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
32036 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
32037 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
32038
ee065d83 32039 /* Tag_WMMX_arch. */
ee3c0378
AS
32040 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
32041 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
32042 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
32043 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 32044
ee3c0378 32045 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
32046 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
32047 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
32048 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
32049 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
32050 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
32051 {
32052 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
32053 {
32054 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
32055 }
32056 else
32057 {
32058 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
32059 fp16_optional = 1;
32060 }
32061 }
fa94de6b 32062
a7ad558c
AV
32063 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
32064 aeabi_set_attribute_int (Tag_MVE_arch, 2);
32065 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
32066 aeabi_set_attribute_int (Tag_MVE_arch, 1);
32067
ee3c0378 32068 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 32069 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 32070 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 32071
69239280
MGD
32072 /* Tag_DIV_use.
32073
32074 We set Tag_DIV_use to two when integer divide instructions have been used
32075 in ARM state, or when Thumb integer divide instructions have been used,
32076 but we have no architecture profile set, nor have we any ARM instructions.
32077
4ed7ed8d
TP
32078 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
32079 by the base architecture.
bca38921 32080
69239280 32081 For new architectures we will have to check these tests. */
031254f2 32082 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
32083 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32084 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
32085 aeabi_set_attribute_int (Tag_DIV_use, 0);
32086 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
32087 || (profile == '\0'
32088 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
32089 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 32090 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
32091
32092 /* Tag_MP_extension_use. */
32093 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
32094 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
32095
32096 /* Tag Virtualization_use. */
32097 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
32098 virt_sec |= 1;
32099 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
32100 virt_sec |= 2;
32101 if (virt_sec != 0)
32102 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
32103
32104 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
32105 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
32106}
32107
c168ce07
TP
32108/* Post relaxation hook. Recompute ARM attributes now that relaxation is
32109 finished and free extension feature bits which will not be used anymore. */
0198d5e6 32110
c168ce07
TP
32111void
32112arm_md_post_relax (void)
32113{
32114 aeabi_set_public_attributes ();
4d354d8b
TP
32115 XDELETE (mcpu_ext_opt);
32116 mcpu_ext_opt = NULL;
32117 XDELETE (march_ext_opt);
32118 march_ext_opt = NULL;
c168ce07
TP
32119}
32120
104d59d1 32121/* Add the default contents for the .ARM.attributes section. */
0198d5e6 32122
ee065d83
PB
32123void
32124arm_md_end (void)
32125{
ee065d83
PB
32126 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
32127 return;
32128
32129 aeabi_set_public_attributes ();
ee065d83 32130}
8463be01 32131#endif /* OBJ_ELF */
ee065d83 32132
ee065d83
PB
32133/* Parse a .cpu directive. */
32134
32135static void
32136s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
32137{
e74cfd16 32138 const struct arm_cpu_option_table *opt;
ee065d83
PB
32139 char *name;
32140 char saved_char;
32141
32142 name = input_line_pointer;
5f4273c7 32143 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32144 input_line_pointer++;
32145 saved_char = *input_line_pointer;
32146 *input_line_pointer = 0;
32147
32148 /* Skip the first "all" entry. */
32149 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
32150 if (streq (opt->name, name))
32151 {
4d354d8b
TP
32152 selected_arch = opt->value;
32153 selected_ext = opt->ext;
32154 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 32155 if (opt->canonical_name)
5f4273c7 32156 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
32157 else
32158 {
32159 int i;
32160 for (i = 0; opt->name[i]; i++)
32161 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 32162
ee065d83
PB
32163 selected_cpu_name[i] = 0;
32164 }
4d354d8b
TP
32165 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32166
ee065d83
PB
32167 *input_line_pointer = saved_char;
32168 demand_empty_rest_of_line ();
32169 return;
32170 }
32171 as_bad (_("unknown cpu `%s'"), name);
32172 *input_line_pointer = saved_char;
32173 ignore_rest_of_line ();
32174}
32175
ee065d83
PB
32176/* Parse a .arch directive. */
32177
32178static void
32179s_arm_arch (int ignored ATTRIBUTE_UNUSED)
32180{
e74cfd16 32181 const struct arm_arch_option_table *opt;
ee065d83
PB
32182 char saved_char;
32183 char *name;
32184
32185 name = input_line_pointer;
5f4273c7 32186 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32187 input_line_pointer++;
32188 saved_char = *input_line_pointer;
32189 *input_line_pointer = 0;
32190
32191 /* Skip the first "all" entry. */
32192 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32193 if (streq (opt->name, name))
32194 {
4d354d8b
TP
32195 selected_arch = opt->value;
32196 selected_ext = arm_arch_none;
32197 selected_cpu = selected_arch;
5f4273c7 32198 strcpy (selected_cpu_name, opt->name);
4d354d8b 32199 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
32200 *input_line_pointer = saved_char;
32201 demand_empty_rest_of_line ();
32202 return;
32203 }
32204
32205 as_bad (_("unknown architecture `%s'\n"), name);
32206 *input_line_pointer = saved_char;
32207 ignore_rest_of_line ();
32208}
32209
7a1d4c38
PB
32210/* Parse a .object_arch directive. */
32211
32212static void
32213s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
32214{
32215 const struct arm_arch_option_table *opt;
32216 char saved_char;
32217 char *name;
32218
32219 name = input_line_pointer;
5f4273c7 32220 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
32221 input_line_pointer++;
32222 saved_char = *input_line_pointer;
32223 *input_line_pointer = 0;
32224
32225 /* Skip the first "all" entry. */
32226 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32227 if (streq (opt->name, name))
32228 {
4d354d8b 32229 selected_object_arch = opt->value;
7a1d4c38
PB
32230 *input_line_pointer = saved_char;
32231 demand_empty_rest_of_line ();
32232 return;
32233 }
32234
32235 as_bad (_("unknown architecture `%s'\n"), name);
32236 *input_line_pointer = saved_char;
32237 ignore_rest_of_line ();
32238}
32239
69133863
MGD
32240/* Parse a .arch_extension directive. */
32241
32242static void
32243s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
32244{
32245 const struct arm_option_extension_value_table *opt;
32246 char saved_char;
32247 char *name;
32248 int adding_value = 1;
32249
32250 name = input_line_pointer;
32251 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32252 input_line_pointer++;
32253 saved_char = *input_line_pointer;
32254 *input_line_pointer = 0;
32255
32256 if (strlen (name) >= 2
32257 && strncmp (name, "no", 2) == 0)
32258 {
32259 adding_value = 0;
32260 name += 2;
32261 }
32262
32263 for (opt = arm_extensions; opt->name != NULL; opt++)
32264 if (streq (opt->name, name))
32265 {
d942732e
TP
32266 int i, nb_allowed_archs =
32267 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
32268 for (i = 0; i < nb_allowed_archs; i++)
32269 {
32270 /* Empty entry. */
4d354d8b 32271 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 32272 continue;
4d354d8b 32273 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
32274 break;
32275 }
32276
32277 if (i == nb_allowed_archs)
69133863
MGD
32278 {
32279 as_bad (_("architectural extension `%s' is not allowed for the "
32280 "current base architecture"), name);
32281 break;
32282 }
32283
32284 if (adding_value)
4d354d8b 32285 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 32286 opt->merge_value);
69133863 32287 else
4d354d8b 32288 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 32289
4d354d8b
TP
32290 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32291 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
32292 *input_line_pointer = saved_char;
32293 demand_empty_rest_of_line ();
3d030cdb
TP
32294 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
32295 on this return so that duplicate extensions (extensions with the
32296 same name as a previous extension in the list) are not considered
32297 for command-line parsing. */
69133863
MGD
32298 return;
32299 }
32300
32301 if (opt->name == NULL)
e673710a 32302 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
32303
32304 *input_line_pointer = saved_char;
32305 ignore_rest_of_line ();
32306}
32307
ee065d83
PB
32308/* Parse a .fpu directive. */
32309
32310static void
32311s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
32312{
69133863 32313 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
32314 char saved_char;
32315 char *name;
32316
32317 name = input_line_pointer;
5f4273c7 32318 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32319 input_line_pointer++;
32320 saved_char = *input_line_pointer;
32321 *input_line_pointer = 0;
5f4273c7 32322
ee065d83
PB
32323 for (opt = arm_fpus; opt->name != NULL; opt++)
32324 if (streq (opt->name, name))
32325 {
4d354d8b
TP
32326 selected_fpu = opt->value;
32327#ifndef CPU_DEFAULT
32328 if (no_cpu_selected ())
32329 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
32330 else
32331#endif
32332 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
32333 *input_line_pointer = saved_char;
32334 demand_empty_rest_of_line ();
32335 return;
32336 }
32337
32338 as_bad (_("unknown floating point format `%s'\n"), name);
32339 *input_line_pointer = saved_char;
32340 ignore_rest_of_line ();
32341}
ee065d83 32342
794ba86a 32343/* Copy symbol information. */
f31fef98 32344
794ba86a
DJ
32345void
32346arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
32347{
32348 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
32349}
e04befd0 32350
f31fef98 32351#ifdef OBJ_ELF
e04befd0
AS
32352/* Given a symbolic attribute NAME, return the proper integer value.
32353 Returns -1 if the attribute is not known. */
f31fef98 32354
e04befd0
AS
32355int
32356arm_convert_symbolic_attribute (const char *name)
32357{
f31fef98
NC
32358 static const struct
32359 {
32360 const char * name;
32361 const int tag;
32362 }
32363 attribute_table[] =
32364 {
32365 /* When you modify this table you should
32366 also modify the list in doc/c-arm.texi. */
e04befd0 32367#define T(tag) {#tag, tag}
f31fef98
NC
32368 T (Tag_CPU_raw_name),
32369 T (Tag_CPU_name),
32370 T (Tag_CPU_arch),
32371 T (Tag_CPU_arch_profile),
32372 T (Tag_ARM_ISA_use),
32373 T (Tag_THUMB_ISA_use),
75375b3e 32374 T (Tag_FP_arch),
f31fef98
NC
32375 T (Tag_VFP_arch),
32376 T (Tag_WMMX_arch),
32377 T (Tag_Advanced_SIMD_arch),
32378 T (Tag_PCS_config),
32379 T (Tag_ABI_PCS_R9_use),
32380 T (Tag_ABI_PCS_RW_data),
32381 T (Tag_ABI_PCS_RO_data),
32382 T (Tag_ABI_PCS_GOT_use),
32383 T (Tag_ABI_PCS_wchar_t),
32384 T (Tag_ABI_FP_rounding),
32385 T (Tag_ABI_FP_denormal),
32386 T (Tag_ABI_FP_exceptions),
32387 T (Tag_ABI_FP_user_exceptions),
32388 T (Tag_ABI_FP_number_model),
75375b3e 32389 T (Tag_ABI_align_needed),
f31fef98 32390 T (Tag_ABI_align8_needed),
75375b3e 32391 T (Tag_ABI_align_preserved),
f31fef98
NC
32392 T (Tag_ABI_align8_preserved),
32393 T (Tag_ABI_enum_size),
32394 T (Tag_ABI_HardFP_use),
32395 T (Tag_ABI_VFP_args),
32396 T (Tag_ABI_WMMX_args),
32397 T (Tag_ABI_optimization_goals),
32398 T (Tag_ABI_FP_optimization_goals),
32399 T (Tag_compatibility),
32400 T (Tag_CPU_unaligned_access),
75375b3e 32401 T (Tag_FP_HP_extension),
f31fef98
NC
32402 T (Tag_VFP_HP_extension),
32403 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
32404 T (Tag_MPextension_use),
32405 T (Tag_DIV_use),
f31fef98
NC
32406 T (Tag_nodefaults),
32407 T (Tag_also_compatible_with),
32408 T (Tag_conformance),
32409 T (Tag_T2EE_use),
32410 T (Tag_Virtualization_use),
15afaa63 32411 T (Tag_DSP_extension),
a7ad558c 32412 T (Tag_MVE_arch),
cd21e546 32413 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 32414#undef T
f31fef98 32415 };
e04befd0
AS
32416 unsigned int i;
32417
32418 if (name == NULL)
32419 return -1;
32420
f31fef98 32421 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 32422 if (streq (name, attribute_table[i].name))
e04befd0
AS
32423 return attribute_table[i].tag;
32424
32425 return -1;
32426}
267bf995 32427
93ef582d
NC
32428/* Apply sym value for relocations only in the case that they are for
32429 local symbols in the same segment as the fixup and you have the
32430 respective architectural feature for blx and simple switches. */
0198d5e6 32431
267bf995 32432int
93ef582d 32433arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
32434{
32435 if (fixP->fx_addsy
32436 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
32437 /* PR 17444: If the local symbol is in a different section then a reloc
32438 will always be generated for it, so applying the symbol value now
32439 will result in a double offset being stored in the relocation. */
32440 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 32441 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
32442 {
32443 switch (fixP->fx_r_type)
32444 {
32445 case BFD_RELOC_ARM_PCREL_BLX:
32446 case BFD_RELOC_THUMB_PCREL_BRANCH23:
32447 if (ARM_IS_FUNC (fixP->fx_addsy))
32448 return 1;
32449 break;
32450
32451 case BFD_RELOC_ARM_PCREL_CALL:
32452 case BFD_RELOC_THUMB_PCREL_BLX:
32453 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 32454 return 1;
267bf995
RR
32455 break;
32456
32457 default:
32458 break;
32459 }
32460
32461 }
32462 return 0;
32463}
f31fef98 32464#endif /* OBJ_ELF */
This page took 4.991415 seconds and 4 git commands to generate.