]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[binutils][arm] arm support for ARMv8.m Custom Datapath Extension
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
b3adc24a 2 Copyright (C) 1994-2020 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 34#include "opcode/arm.h"
f37164d7 35#include "cpu-arm.h"
f263249b 36
b99bd4ef
NC
37#ifdef OBJ_ELF
38#include "elf/arm.h"
a394c00f 39#include "dw2gencfi.h"
b99bd4ef
NC
40#endif
41
f0927246
NC
42#include "dwarf2dbg.h"
43
7ed4c4c5
NC
44#ifdef OBJ_ELF
45/* Must be at least the size of the largest unwind opcode (currently two). */
46#define ARM_OPCODE_CHUNK_SIZE 8
47
48/* This structure holds the unwinding state. */
49
50static struct
51{
c19d1205
ZW
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
7ed4c4c5 56 /* The segment containing the function. */
c19d1205
ZW
57 segT saved_seg;
58 subsegT saved_subseg;
7ed4c4c5
NC
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
c19d1205
ZW
61 int opcode_count;
62 int opcode_alloc;
7ed4c4c5 63 /* The number of bytes pushed to the stack. */
c19d1205 64 offsetT frame_size;
7ed4c4c5
NC
65 /* We don't add stack adjustment opcodes immediately so that we can merge
66 multiple adjustments. We can also omit the final adjustment
67 when using a frame pointer. */
c19d1205 68 offsetT pending_offset;
7ed4c4c5 69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
7ed4c4c5 73 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 74 unsigned fp_used:1;
7ed4c4c5 75 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 76 unsigned sp_restored:1;
7ed4c4c5
NC
77} unwind;
78
18a20338
CL
79/* Whether --fdpic was given. */
80static int arm_fdpic;
81
8b1ad454
NC
82#endif /* OBJ_ELF */
83
4962c51a
MS
84/* Results from operand parsing worker functions. */
85
86typedef enum
87{
88 PARSE_OPERAND_SUCCESS,
89 PARSE_OPERAND_FAIL,
90 PARSE_OPERAND_FAIL_NO_BACKTRACK
91} parse_operand_result;
92
33a392fb
PB
93enum arm_float_abi
94{
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98};
99
c19d1205 100/* Types of processor to assemble for. */
b99bd4ef 101#ifndef CPU_DEFAULT
8a59fff3 102/* The code that was here used to select a default CPU depending on compiler
fa94de6b 103 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
104 changing gas' default behaviour depending upon the build host.
105
106 If you have a target that requires a default CPU option then the you
107 should define CPU_DEFAULT here. */
b99bd4ef
NC
108#endif
109
e8f8842d
TC
110/* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112static bfd_boolean out_of_range_p (offsetT value, offsetT bits)
113 {
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
117}
118
b99bd4ef 119#ifndef FPU_DEFAULT
c820d418
MM
120# ifdef TE_LINUX
121# define FPU_DEFAULT FPU_ARCH_FPA
122# elif defined (TE_NetBSD)
123# ifdef OBJ_ELF
124# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
125# else
126 /* Legacy a.out format. */
127# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
128# endif
4e7fd91e
PB
129# elif defined (TE_VXWORKS)
130# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
131# else
132 /* For backwards compatibility, default to FPA. */
133# define FPU_DEFAULT FPU_ARCH_FPA
134# endif
135#endif /* ifndef FPU_DEFAULT */
b99bd4ef 136
c19d1205 137#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 138
4d354d8b
TP
139/* Current set of feature bits available (CPU+FPU). Different from
140 selected_cpu + selected_fpu in case of autodetection since the CPU
141 feature bits are then all set. */
e74cfd16 142static arm_feature_set cpu_variant;
4d354d8b
TP
143/* Feature bits used in each execution state. Used to set build attribute
144 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
145static arm_feature_set arm_arch_used;
146static arm_feature_set thumb_arch_used;
b99bd4ef 147
b99bd4ef 148/* Flags stored in private area of BFD structure. */
c19d1205
ZW
149static int uses_apcs_26 = FALSE;
150static int atpcs = FALSE;
b34976b6
AM
151static int support_interwork = FALSE;
152static int uses_apcs_float = FALSE;
c19d1205 153static int pic_code = FALSE;
845b51d6 154static int fix_v4bx = FALSE;
278df34e
NS
155/* Warn on using deprecated features. */
156static int warn_on_deprecated = TRUE;
24f19ccb 157static int warn_on_restrict_it = FALSE;
278df34e 158
2e6976a8
DG
159/* Understand CodeComposer Studio assembly syntax. */
160bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
161
162/* Variables that we set while parsing command-line options. Once all
163 options have been read we re-process these values to set the real
164 assembly flags. */
4d354d8b
TP
165
166/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
167 instead of -mcpu=arm1). */
168static const arm_feature_set *legacy_cpu = NULL;
169static const arm_feature_set *legacy_fpu = NULL;
170
171/* CPU, extension and FPU feature bits selected by -mcpu. */
172static const arm_feature_set *mcpu_cpu_opt = NULL;
173static arm_feature_set *mcpu_ext_opt = NULL;
174static const arm_feature_set *mcpu_fpu_opt = NULL;
175
176/* CPU, extension and FPU feature bits selected by -march. */
177static const arm_feature_set *march_cpu_opt = NULL;
178static arm_feature_set *march_ext_opt = NULL;
179static const arm_feature_set *march_fpu_opt = NULL;
180
181/* Feature bits selected by -mfpu. */
182static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
183
184/* Constants for known architecture features. */
185static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 186static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 187static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
188static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
189static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
190static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
191static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 192#ifdef OBJ_ELF
e74cfd16 193static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 194#endif
e74cfd16
PB
195static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
196
197#ifdef CPU_DEFAULT
198static const arm_feature_set cpu_default = CPU_DEFAULT;
199#endif
200
823d2571 201static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 202static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
203static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
204static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
205static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
206static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
207static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
208static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 209static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
211static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
212static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
213static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
214static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
215static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
216static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
217static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
218/* Only for compatability of hint instructions. */
219static const arm_feature_set arm_ext_v6k_v6t2 =
220 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
221static const arm_feature_set arm_ext_v6_notm =
222 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
223static const arm_feature_set arm_ext_v6_dsp =
224 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
225static const arm_feature_set arm_ext_barrier =
226 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
227static const arm_feature_set arm_ext_msr =
228 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
229static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
230static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
231static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
232static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 233#ifdef OBJ_ELF
e7d39ed3 234static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 235#endif
823d2571 236static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 237static const arm_feature_set arm_ext_m =
173205ca 238 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 239 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
240static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
241static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
242static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
243static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
244static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 245static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 246static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
247static const arm_feature_set arm_ext_v8m_main =
248 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
249static const arm_feature_set arm_ext_v8_1m_main =
250ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
251/* Instructions in ARMv8-M only found in M profile architectures. */
252static const arm_feature_set arm_ext_v8m_m_only =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
254static const arm_feature_set arm_ext_v6t2_v8m =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
256/* Instructions shared between ARMv8-A and ARMv8-M. */
257static const arm_feature_set arm_ext_atomics =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 259#ifdef OBJ_ELF
15afaa63
TP
260/* DSP instructions Tag_DSP_extension refers to. */
261static const arm_feature_set arm_ext_dsp =
262 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 263#endif
4d1464f2
MW
264static const arm_feature_set arm_ext_ras =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
266/* FP16 instructions. */
267static const arm_feature_set arm_ext_fp16 =
268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
269static const arm_feature_set arm_ext_fp16_fml =
270 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
271static const arm_feature_set arm_ext_v8_2 =
272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
273static const arm_feature_set arm_ext_v8_3 =
274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
275static const arm_feature_set arm_ext_sb =
276 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
277static const arm_feature_set arm_ext_predres =
278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
aab2c27d
MM
279static const arm_feature_set arm_ext_bf16 =
280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
616ce08e
MM
281static const arm_feature_set arm_ext_i8mm =
282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
8b301fbb
MI
283static const arm_feature_set arm_ext_crc =
284 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
4934a27c
MM
285static const arm_feature_set arm_ext_cde =
286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
287static const arm_feature_set arm_ext_cde0 =
288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
289static const arm_feature_set arm_ext_cde1 =
290 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
291static const arm_feature_set arm_ext_cde2 =
292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
293static const arm_feature_set arm_ext_cde3 =
294 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
295static const arm_feature_set arm_ext_cde4 =
296 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
297static const arm_feature_set arm_ext_cde5 =
298 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
299static const arm_feature_set arm_ext_cde6 =
300 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
301static const arm_feature_set arm_ext_cde7 =
302 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
e74cfd16
PB
303
304static const arm_feature_set arm_arch_any = ARM_ANY;
2c6b98ea 305static const arm_feature_set fpu_any = FPU_ANY;
f85d59c3 306static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
307static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
308static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
309
2d447fca 310static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 311 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 312static const arm_feature_set arm_cext_iwmmxt =
823d2571 313 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 314static const arm_feature_set arm_cext_xscale =
823d2571 315 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 316static const arm_feature_set arm_cext_maverick =
823d2571
TG
317 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
318static const arm_feature_set fpu_fpa_ext_v1 =
319 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
320static const arm_feature_set fpu_fpa_ext_v2 =
321 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 322static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
323 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
324static const arm_feature_set fpu_vfp_ext_v1 =
325 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
326static const arm_feature_set fpu_vfp_ext_v2 =
327 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
328static const arm_feature_set fpu_vfp_ext_v3xd =
329 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
330static const arm_feature_set fpu_vfp_ext_v3 =
331 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 332static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
333 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
334static const arm_feature_set fpu_neon_ext_v1 =
335 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 336static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 337 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c 338static const arm_feature_set mve_ext =
2da2eaf4 339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
a7ad558c 340static const arm_feature_set mve_fp_ext =
2da2eaf4 341 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
69c9e028 342#ifdef OBJ_ELF
823d2571
TG
343static const arm_feature_set fpu_vfp_fp16 =
344 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
345static const arm_feature_set fpu_neon_ext_fma =
346 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 347#endif
823d2571
TG
348static const arm_feature_set fpu_vfp_ext_fma =
349 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 350static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 351 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 352static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 353 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 354static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 355 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 356static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 357 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
d6b4b13e 358static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 359 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
360static const arm_feature_set fpu_neon_ext_dotprod =
361 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 362
33a392fb 363static int mfloat_abi_opt = -1;
4d354d8b
TP
364/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
365 directive. */
366static arm_feature_set selected_arch = ARM_ARCH_NONE;
367/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
368 directive. */
369static arm_feature_set selected_ext = ARM_ARCH_NONE;
370/* Feature bits selected by the last -mcpu/-march or by the combination of the
371 last .cpu/.arch directive .arch_extension directives since that
372 directive. */
e74cfd16 373static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
374/* FPU feature bits selected by the last -mfpu or .fpu directive. */
375static arm_feature_set selected_fpu = FPU_NONE;
376/* Feature bits selected by the last .object_arch directive. */
377static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 378/* Must be long enough to hold any of the names in arm_cpus. */
e20f9590 379static const struct arm_ext_table * selected_ctx_ext_table = NULL;
ef8e6722 380static char selected_cpu_name[20];
8d67f500 381
aacf0b33
KT
382extern FLONUM_TYPE generic_floating_point_number;
383
8d67f500
NC
384/* Return if no cpu was selected on command-line. */
385static bfd_boolean
386no_cpu_selected (void)
387{
823d2571 388 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
389}
390
7cc69913 391#ifdef OBJ_ELF
deeaaff8
DJ
392# ifdef EABI_DEFAULT
393static int meabi_flags = EABI_DEFAULT;
394# else
d507cf36 395static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 396# endif
e1da3f5b 397
ee3c0378
AS
398static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
399
e1da3f5b 400bfd_boolean
5f4273c7 401arm_is_eabi (void)
e1da3f5b
PB
402{
403 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
404}
7cc69913 405#endif
b99bd4ef 406
b99bd4ef 407#ifdef OBJ_ELF
c19d1205 408/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
409symbolS * GOT_symbol;
410#endif
411
b99bd4ef
NC
412/* 0: assemble for ARM,
413 1: assemble for Thumb,
414 2: assemble for Thumb even though target CPU does not support thumb
415 instructions. */
416static int thumb_mode = 0;
8dc2430f
NC
417/* A value distinct from the possible values for thumb_mode that we
418 can use to record whether thumb_mode has been copied into the
419 tc_frag_data field of a frag. */
420#define MODE_RECORDED (1 << 4)
b99bd4ef 421
e07e6e58
NC
422/* Specifies the intrinsic IT insn behavior mode. */
423enum implicit_it_mode
424{
425 IMPLICIT_IT_MODE_NEVER = 0x00,
426 IMPLICIT_IT_MODE_ARM = 0x01,
427 IMPLICIT_IT_MODE_THUMB = 0x02,
428 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
429};
430static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
431
c19d1205
ZW
432/* If unified_syntax is true, we are processing the new unified
433 ARM/Thumb syntax. Important differences from the old ARM mode:
434
435 - Immediate operands do not require a # prefix.
436 - Conditional affixes always appear at the end of the
437 instruction. (For backward compatibility, those instructions
438 that formerly had them in the middle, continue to accept them
439 there.)
440 - The IT instruction may appear, and if it does is validated
441 against subsequent conditional affixes. It does not generate
442 machine code.
443
444 Important differences from the old Thumb mode:
445
446 - Immediate operands do not require a # prefix.
447 - Most of the V6T2 instructions are only available in unified mode.
448 - The .N and .W suffixes are recognized and honored (it is an error
449 if they cannot be honored).
450 - All instructions set the flags if and only if they have an 's' affix.
451 - Conditional affixes may be used. They are validated against
452 preceding IT instructions. Unlike ARM mode, you cannot use a
453 conditional affix except in the scope of an IT instruction. */
454
455static bfd_boolean unified_syntax = FALSE;
b99bd4ef 456
bacebabc
RM
457/* An immediate operand can start with #, and ld*, st*, pld operands
458 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
459 before a [, which can appear as the first operand for pld.
460 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
461const char arm_symbol_chars[] = "#[]{}";
bacebabc 462
5287ad62
JB
463enum neon_el_type
464{
dcbf9037 465 NT_invtype,
5287ad62
JB
466 NT_untyped,
467 NT_integer,
468 NT_float,
469 NT_poly,
470 NT_signed,
aab2c27d 471 NT_bfloat,
dcbf9037 472 NT_unsigned
5287ad62
JB
473};
474
475struct neon_type_el
476{
477 enum neon_el_type type;
478 unsigned size;
479};
480
481#define NEON_MAX_TYPE_ELS 4
482
483struct neon_type
484{
485 struct neon_type_el el[NEON_MAX_TYPE_ELS];
486 unsigned elems;
487};
488
5ee91343 489enum pred_instruction_type
e07e6e58 490{
5ee91343
AV
491 OUTSIDE_PRED_INSN,
492 INSIDE_VPT_INSN,
e07e6e58
NC
493 INSIDE_IT_INSN,
494 INSIDE_IT_LAST_INSN,
495 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 496 if inside, should be the last one. */
e07e6e58 497 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 498 i.e. BKPT and NOP. */
5ee91343
AV
499 IT_INSN, /* The IT insn has been parsed. */
500 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 501 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 502 a predication code. */
4934a27c
MM
503 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
504 NEUTRAL_IT_NO_VPT_INSN, /* Instruction that can be either inside or outside
505 an IT block, but must not be in a VPT block. */
e07e6e58
NC
506};
507
ad6cec43
MGD
508/* The maximum number of operands we need. */
509#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 510#define ARM_IT_MAX_RELOCS 3
ad6cec43 511
b99bd4ef
NC
512struct arm_it
513{
c19d1205 514 const char * error;
b99bd4ef 515 unsigned long instruction;
c19d1205
ZW
516 int size;
517 int size_req;
518 int cond;
037e8744
JB
519 /* "uncond_value" is set to the value in place of the conditional field in
520 unconditional versions of the instruction, or -1 if nothing is
521 appropriate. */
522 int uncond_value;
5287ad62 523 struct neon_type vectype;
88714cb8
DG
524 /* This does not indicate an actual NEON instruction, only that
525 the mnemonic accepts neon-style type suffixes. */
526 int is_neon;
0110f2b8
PB
527 /* Set to the opcode if the instruction needs relaxation.
528 Zero if the instruction is not relaxed. */
529 unsigned long relax;
b99bd4ef
NC
530 struct
531 {
532 bfd_reloc_code_real_type type;
c19d1205
ZW
533 expressionS exp;
534 int pc_rel;
e2b0ab59 535 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 536
5ee91343 537 enum pred_instruction_type pred_insn_type;
e07e6e58 538
c19d1205
ZW
539 struct
540 {
541 unsigned reg;
ca3f61f7 542 signed int imm;
dcbf9037 543 struct neon_type_el vectype;
ca3f61f7
NC
544 unsigned present : 1; /* Operand present. */
545 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
546 unsigned immisreg : 2; /* .imm field is a second register.
547 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
548 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
549 0) not scalar,
550 1) Neon scalar,
551 2) MVE scalar. */
5287ad62 552 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 553 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
554 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
555 instructions. This allows us to disambiguate ARM <-> vector insns. */
556 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 557 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 558 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 559 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 560 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
561 unsigned hasreloc : 1; /* Operand has relocation suffix. */
562 unsigned writeback : 1; /* Operand has trailing ! */
563 unsigned preind : 1; /* Preindexed address. */
564 unsigned postind : 1; /* Postindexed address. */
565 unsigned negative : 1; /* Index register was negated. */
566 unsigned shifted : 1; /* Shift applied to operation. */
567 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 568 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
569};
570
c19d1205 571static struct arm_it inst;
b99bd4ef
NC
572
573#define NUM_FLOAT_VALS 8
574
05d2d07e 575const char * fp_const[] =
b99bd4ef
NC
576{
577 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
578};
579
b99bd4ef
NC
580LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
581
582#define FAIL (-1)
583#define SUCCESS (0)
584
585#define SUFF_S 1
586#define SUFF_D 2
587#define SUFF_E 3
588#define SUFF_P 4
589
c19d1205
ZW
590#define CP_T_X 0x00008000
591#define CP_T_Y 0x00400000
b99bd4ef 592
c19d1205
ZW
593#define CONDS_BIT 0x00100000
594#define LOAD_BIT 0x00100000
b99bd4ef
NC
595
596#define DOUBLE_LOAD_FLAG 0x00000001
597
598struct asm_cond
599{
d3ce72d0 600 const char * template_name;
c921be7d 601 unsigned long value;
b99bd4ef
NC
602};
603
c19d1205 604#define COND_ALWAYS 0xE
b99bd4ef 605
b99bd4ef
NC
606struct asm_psr
607{
d3ce72d0 608 const char * template_name;
c921be7d 609 unsigned long field;
b99bd4ef
NC
610};
611
62b3e311
PB
612struct asm_barrier_opt
613{
e797f7e0
MGD
614 const char * template_name;
615 unsigned long value;
616 const arm_feature_set arch;
62b3e311
PB
617};
618
2d2255b5 619/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
620#define SPSR_BIT (1 << 22)
621
c19d1205
ZW
622/* The individual PSR flag bits. */
623#define PSR_c (1 << 16)
624#define PSR_x (1 << 17)
625#define PSR_s (1 << 18)
626#define PSR_f (1 << 19)
b99bd4ef 627
c19d1205 628struct reloc_entry
bfae80f2 629{
0198d5e6 630 const char * name;
c921be7d 631 bfd_reloc_code_real_type reloc;
bfae80f2
RE
632};
633
5287ad62 634enum vfp_reg_pos
bfae80f2 635{
5287ad62
JB
636 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
637 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
638};
639
640enum vfp_ldstm_type
641{
642 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
643};
644
dcbf9037
JB
645/* Bits for DEFINED field in neon_typed_alias. */
646#define NTA_HASTYPE 1
647#define NTA_HASINDEX 2
648
649struct neon_typed_alias
650{
c921be7d
NC
651 unsigned char defined;
652 unsigned char index;
653 struct neon_type_el eltype;
dcbf9037
JB
654};
655
c19d1205 656/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
657 architecture extensions' registers. Each entry should have an error message
658 in reg_expected_msgs below. */
c19d1205 659enum arm_reg_type
bfae80f2 660{
c19d1205
ZW
661 REG_TYPE_RN,
662 REG_TYPE_CP,
663 REG_TYPE_CN,
664 REG_TYPE_FN,
665 REG_TYPE_VFS,
666 REG_TYPE_VFD,
5287ad62 667 REG_TYPE_NQ,
037e8744 668 REG_TYPE_VFSD,
5287ad62 669 REG_TYPE_NDQ,
dec41383 670 REG_TYPE_NSD,
037e8744 671 REG_TYPE_NSDQ,
c19d1205
ZW
672 REG_TYPE_VFC,
673 REG_TYPE_MVF,
674 REG_TYPE_MVD,
675 REG_TYPE_MVFX,
676 REG_TYPE_MVDX,
677 REG_TYPE_MVAX,
5ee91343 678 REG_TYPE_MQ,
c19d1205
ZW
679 REG_TYPE_DSPSC,
680 REG_TYPE_MMXWR,
681 REG_TYPE_MMXWC,
682 REG_TYPE_MMXWCG,
683 REG_TYPE_XSCALE,
5ee91343 684 REG_TYPE_RNB,
1b883319 685 REG_TYPE_ZR
bfae80f2
RE
686};
687
dcbf9037
JB
688/* Structure for a hash table entry for a register.
689 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
690 information which states whether a vector type or index is specified (for a
691 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
692struct reg_entry
693{
c921be7d 694 const char * name;
90ec0d68 695 unsigned int number;
c921be7d
NC
696 unsigned char type;
697 unsigned char builtin;
698 struct neon_typed_alias * neon;
6c43fab6
RE
699};
700
c19d1205 701/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 702const char * const reg_expected_msgs[] =
c19d1205 703{
5aa75429
TP
704 [REG_TYPE_RN] = N_("ARM register expected"),
705 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
706 [REG_TYPE_CN] = N_("co-processor register expected"),
707 [REG_TYPE_FN] = N_("FPA register expected"),
708 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
709 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
710 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
711 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
712 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
713 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
714 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
715 " expected"),
716 [REG_TYPE_VFC] = N_("VFP system register expected"),
717 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
718 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
719 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
720 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
721 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
722 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
723 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
724 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
725 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
726 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 727 [REG_TYPE_MQ] = N_("MVE vector register expected"),
5aa75429 728 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
729};
730
c19d1205 731/* Some well known registers that we refer to directly elsewhere. */
bd340a04 732#define REG_R12 12
c19d1205
ZW
733#define REG_SP 13
734#define REG_LR 14
735#define REG_PC 15
404ff6b5 736
b99bd4ef
NC
737/* ARM instructions take 4bytes in the object file, Thumb instructions
738 take 2: */
c19d1205 739#define INSN_SIZE 4
b99bd4ef
NC
740
741struct asm_opcode
742{
743 /* Basic string to match. */
d3ce72d0 744 const char * template_name;
c19d1205
ZW
745
746 /* Parameters to instruction. */
5be8be5d 747 unsigned int operands[8];
c19d1205
ZW
748
749 /* Conditional tag - see opcode_lookup. */
750 unsigned int tag : 4;
b99bd4ef
NC
751
752 /* Basic instruction code. */
a302e574 753 unsigned int avalue;
b99bd4ef 754
c19d1205
ZW
755 /* Thumb-format instruction code. */
756 unsigned int tvalue;
b99bd4ef 757
90e4755a 758 /* Which architecture variant provides this instruction. */
c921be7d
NC
759 const arm_feature_set * avariant;
760 const arm_feature_set * tvariant;
c19d1205
ZW
761
762 /* Function to call to encode instruction in ARM format. */
763 void (* aencode) (void);
b99bd4ef 764
c19d1205
ZW
765 /* Function to call to encode instruction in Thumb format. */
766 void (* tencode) (void);
5ee91343
AV
767
768 /* Indicates whether this instruction may be vector predicated. */
769 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
770};
771
a737bd4d
NC
772/* Defines for various bits that we will want to toggle. */
773#define INST_IMMEDIATE 0x02000000
774#define OFFSET_REG 0x02000000
c19d1205 775#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
776#define SHIFT_BY_REG 0x00000010
777#define PRE_INDEX 0x01000000
778#define INDEX_UP 0x00800000
779#define WRITE_BACK 0x00200000
780#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 781#define CPSI_MMOD 0x00020000
90e4755a 782
a737bd4d
NC
783#define LITERAL_MASK 0xf000f000
784#define OPCODE_MASK 0xfe1fffff
785#define V4_STR_BIT 0x00000020
8335d6aa 786#define VLDR_VMOV_SAME 0x0040f000
90e4755a 787
efd81785
PB
788#define T2_SUBS_PC_LR 0xf3de8f00
789
a737bd4d 790#define DATA_OP_SHIFT 21
bada4342 791#define SBIT_SHIFT 20
90e4755a 792
ef8d22e6
PB
793#define T2_OPCODE_MASK 0xfe1fffff
794#define T2_DATA_OP_SHIFT 21
bada4342 795#define T2_SBIT_SHIFT 20
ef8d22e6 796
6530b175
NC
797#define A_COND_MASK 0xf0000000
798#define A_PUSH_POP_OP_MASK 0x0fff0000
799
800/* Opcodes for pushing/poping registers to/from the stack. */
801#define A1_OPCODE_PUSH 0x092d0000
802#define A2_OPCODE_PUSH 0x052d0004
803#define A2_OPCODE_POP 0x049d0004
804
a737bd4d
NC
805/* Codes to distinguish the arithmetic instructions. */
806#define OPCODE_AND 0
807#define OPCODE_EOR 1
808#define OPCODE_SUB 2
809#define OPCODE_RSB 3
810#define OPCODE_ADD 4
811#define OPCODE_ADC 5
812#define OPCODE_SBC 6
813#define OPCODE_RSC 7
814#define OPCODE_TST 8
815#define OPCODE_TEQ 9
816#define OPCODE_CMP 10
817#define OPCODE_CMN 11
818#define OPCODE_ORR 12
819#define OPCODE_MOV 13
820#define OPCODE_BIC 14
821#define OPCODE_MVN 15
90e4755a 822
ef8d22e6
PB
823#define T2_OPCODE_AND 0
824#define T2_OPCODE_BIC 1
825#define T2_OPCODE_ORR 2
826#define T2_OPCODE_ORN 3
827#define T2_OPCODE_EOR 4
828#define T2_OPCODE_ADD 8
829#define T2_OPCODE_ADC 10
830#define T2_OPCODE_SBC 11
831#define T2_OPCODE_SUB 13
832#define T2_OPCODE_RSB 14
833
a737bd4d
NC
834#define T_OPCODE_MUL 0x4340
835#define T_OPCODE_TST 0x4200
836#define T_OPCODE_CMN 0x42c0
837#define T_OPCODE_NEG 0x4240
838#define T_OPCODE_MVN 0x43c0
90e4755a 839
a737bd4d
NC
840#define T_OPCODE_ADD_R3 0x1800
841#define T_OPCODE_SUB_R3 0x1a00
842#define T_OPCODE_ADD_HI 0x4400
843#define T_OPCODE_ADD_ST 0xb000
844#define T_OPCODE_SUB_ST 0xb080
845#define T_OPCODE_ADD_SP 0xa800
846#define T_OPCODE_ADD_PC 0xa000
847#define T_OPCODE_ADD_I8 0x3000
848#define T_OPCODE_SUB_I8 0x3800
849#define T_OPCODE_ADD_I3 0x1c00
850#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 851
a737bd4d
NC
852#define T_OPCODE_ASR_R 0x4100
853#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
854#define T_OPCODE_LSR_R 0x40c0
855#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
856#define T_OPCODE_ASR_I 0x1000
857#define T_OPCODE_LSL_I 0x0000
858#define T_OPCODE_LSR_I 0x0800
b99bd4ef 859
a737bd4d
NC
860#define T_OPCODE_MOV_I8 0x2000
861#define T_OPCODE_CMP_I8 0x2800
862#define T_OPCODE_CMP_LR 0x4280
863#define T_OPCODE_MOV_HR 0x4600
864#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 865
a737bd4d
NC
866#define T_OPCODE_LDR_PC 0x4800
867#define T_OPCODE_LDR_SP 0x9800
868#define T_OPCODE_STR_SP 0x9000
869#define T_OPCODE_LDR_IW 0x6800
870#define T_OPCODE_STR_IW 0x6000
871#define T_OPCODE_LDR_IH 0x8800
872#define T_OPCODE_STR_IH 0x8000
873#define T_OPCODE_LDR_IB 0x7800
874#define T_OPCODE_STR_IB 0x7000
875#define T_OPCODE_LDR_RW 0x5800
876#define T_OPCODE_STR_RW 0x5000
877#define T_OPCODE_LDR_RH 0x5a00
878#define T_OPCODE_STR_RH 0x5200
879#define T_OPCODE_LDR_RB 0x5c00
880#define T_OPCODE_STR_RB 0x5400
c9b604bd 881
a737bd4d
NC
882#define T_OPCODE_PUSH 0xb400
883#define T_OPCODE_POP 0xbc00
b99bd4ef 884
2fc8bdac 885#define T_OPCODE_BRANCH 0xe000
b99bd4ef 886
a737bd4d 887#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 888#define THUMB_PP_PC_LR 0x0100
c19d1205 889#define THUMB_LOAD_BIT 0x0800
53365c0d 890#define THUMB2_LOAD_BIT 0x00100000
c19d1205 891
5ee91343 892#define BAD_SYNTAX _("syntax error")
c19d1205 893#define BAD_ARGS _("bad arguments to instruction")
fdfde340 894#define BAD_SP _("r13 not allowed here")
c19d1205 895#define BAD_PC _("r15 not allowed here")
a302e574
AV
896#define BAD_ODD _("Odd register not allowed here")
897#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
898#define BAD_COND _("instruction cannot be conditional")
899#define BAD_OVERLAP _("registers may not be the same")
900#define BAD_HIREG _("lo register required")
901#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 902#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 903#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 904#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
4934a27c 905#define BAD_NO_VPT _("instruction not allowed in VPT block")
dfa9f0d5 906#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 907#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 908#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 909#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
910#define BAD_OUT_VPT \
911 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 912#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 913#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 914#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 915#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
916#define BAD_PC_ADDRESSING \
917 _("cannot use register index with PC-relative addressing")
918#define BAD_PC_WRITEBACK \
919 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
920#define BAD_RANGE _("branch out of range")
921#define BAD_FP16 _("selected processor does not support fp16 instruction")
aab2c27d 922#define BAD_BF16 _("selected processor does not support bf16 instruction")
4934a27c
MM
923#define BAD_CDE _("selected processor does not support cde instruction")
924#define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
dd5181d5 925#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 926#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
927#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
928 "block")
929#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
930 "block")
931#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
932 " operand")
933#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
934 " operand")
a302e574 935#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
936#define BAD_MVE_AUTO \
937 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
938 " use a valid -march or -mcpu option.")
939#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
940 "and source operands makes instruction UNPREDICTABLE")
35c228db 941#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 942#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 943
c921be7d
NC
944static struct hash_control * arm_ops_hsh;
945static struct hash_control * arm_cond_hsh;
5ee91343 946static struct hash_control * arm_vcond_hsh;
c921be7d
NC
947static struct hash_control * arm_shift_hsh;
948static struct hash_control * arm_psr_hsh;
949static struct hash_control * arm_v7m_psr_hsh;
950static struct hash_control * arm_reg_hsh;
951static struct hash_control * arm_reloc_hsh;
952static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 953
b99bd4ef
NC
954/* Stuff needed to resolve the label ambiguity
955 As:
956 ...
957 label: <insn>
958 may differ from:
959 ...
960 label:
5f4273c7 961 <insn> */
b99bd4ef
NC
962
963symbolS * last_label_seen;
b34976b6 964static int label_is_thumb_function_name = FALSE;
e07e6e58 965
3d0c9500
NC
966/* Literal pool structure. Held on a per-section
967 and per-sub-section basis. */
a737bd4d 968
c19d1205 969#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 970typedef struct literal_pool
b99bd4ef 971{
c921be7d
NC
972 expressionS literals [MAX_LITERAL_POOL_SIZE];
973 unsigned int next_free_entry;
974 unsigned int id;
975 symbolS * symbol;
976 segT section;
977 subsegT sub_section;
a8040cf2
NC
978#ifdef OBJ_ELF
979 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
980#endif
c921be7d 981 struct literal_pool * next;
8335d6aa 982 unsigned int alignment;
3d0c9500 983} literal_pool;
b99bd4ef 984
3d0c9500
NC
985/* Pointer to a linked list of literal pools. */
986literal_pool * list_of_pools = NULL;
e27ec89e 987
2e6976a8
DG
988typedef enum asmfunc_states
989{
990 OUTSIDE_ASMFUNC,
991 WAITING_ASMFUNC_NAME,
992 WAITING_ENDASMFUNC
993} asmfunc_states;
994
995static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
996
e07e6e58 997#ifdef OBJ_ELF
5ee91343 998# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 999#else
5ee91343 1000static struct current_pred now_pred;
e07e6e58
NC
1001#endif
1002
1003static inline int
5ee91343 1004now_pred_compatible (int cond)
e07e6e58 1005{
5ee91343 1006 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
1007}
1008
1009static inline int
1010conditional_insn (void)
1011{
1012 return inst.cond != COND_ALWAYS;
1013}
1014
5ee91343 1015static int in_pred_block (void);
e07e6e58 1016
5ee91343 1017static int handle_pred_state (void);
e07e6e58
NC
1018
1019static void force_automatic_it_block_close (void);
1020
c921be7d
NC
1021static void it_fsm_post_encode (void);
1022
5ee91343 1023#define set_pred_insn_type(type) \
e07e6e58
NC
1024 do \
1025 { \
5ee91343
AV
1026 inst.pred_insn_type = type; \
1027 if (handle_pred_state () == FAIL) \
477330fc 1028 return; \
e07e6e58
NC
1029 } \
1030 while (0)
1031
5ee91343 1032#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
1033 do \
1034 { \
5ee91343
AV
1035 inst.pred_insn_type = type; \
1036 if (handle_pred_state () == FAIL) \
477330fc 1037 return failret; \
c921be7d
NC
1038 } \
1039 while(0)
1040
5ee91343 1041#define set_pred_insn_type_last() \
e07e6e58
NC
1042 do \
1043 { \
1044 if (inst.cond == COND_ALWAYS) \
5ee91343 1045 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1046 else \
5ee91343 1047 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1048 } \
1049 while (0)
1050
e39c1607
SD
1051/* Toggle value[pos]. */
1052#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1053
c19d1205 1054/* Pure syntax. */
b99bd4ef 1055
c19d1205
ZW
1056/* This array holds the chars that always start a comment. If the
1057 pre-processor is disabled, these aren't very useful. */
2e6976a8 1058char arm_comment_chars[] = "@";
3d0c9500 1059
c19d1205
ZW
1060/* This array holds the chars that only start a comment at the beginning of
1061 a line. If the line seems to have the form '# 123 filename'
1062 .line and .file directives will appear in the pre-processed output. */
1063/* Note that input_file.c hand checks for '#' at the beginning of the
1064 first line of the input file. This is because the compiler outputs
1065 #NO_APP at the beginning of its output. */
1066/* Also note that comments like this one will always work. */
1067const char line_comment_chars[] = "#";
3d0c9500 1068
2e6976a8 1069char arm_line_separator_chars[] = ";";
b99bd4ef 1070
c19d1205
ZW
1071/* Chars that can be used to separate mant
1072 from exp in floating point numbers. */
1073const char EXP_CHARS[] = "eE";
3d0c9500 1074
c19d1205
ZW
1075/* Chars that mean this number is a floating point constant. */
1076/* As in 0f12.456 */
1077/* or 0d1.2345e12 */
b99bd4ef 1078
5312fe52 1079const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1080
c19d1205
ZW
1081/* Prefix characters that indicate the start of an immediate
1082 value. */
1083#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1084
c19d1205
ZW
1085/* Separator character handling. */
1086
1087#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1088
5312fe52
BW
1089enum fp_16bit_format
1090{
1091 ARM_FP16_FORMAT_IEEE = 0x1,
1092 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1093 ARM_FP16_FORMAT_DEFAULT = 0x3
1094};
1095
1096static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1097
1098
c19d1205
ZW
1099static inline int
1100skip_past_char (char ** str, char c)
1101{
8ab8155f
NC
1102 /* PR gas/14987: Allow for whitespace before the expected character. */
1103 skip_whitespace (*str);
427d0db6 1104
c19d1205
ZW
1105 if (**str == c)
1106 {
1107 (*str)++;
1108 return SUCCESS;
3d0c9500 1109 }
c19d1205
ZW
1110 else
1111 return FAIL;
1112}
c921be7d 1113
c19d1205 1114#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1115
c19d1205
ZW
1116/* Arithmetic expressions (possibly involving symbols). */
1117
1118/* Return TRUE if anything in the expression is a bignum. */
1119
0198d5e6 1120static bfd_boolean
c19d1205
ZW
1121walk_no_bignums (symbolS * sp)
1122{
1123 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1124 return TRUE;
c19d1205
ZW
1125
1126 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1127 {
c19d1205
ZW
1128 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1129 || (symbol_get_value_expression (sp)->X_op_symbol
1130 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1131 }
1132
0198d5e6 1133 return FALSE;
3d0c9500
NC
1134}
1135
0198d5e6 1136static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1137
1138/* Third argument to my_get_expression. */
1139#define GE_NO_PREFIX 0
1140#define GE_IMM_PREFIX 1
1141#define GE_OPT_PREFIX 2
5287ad62
JB
1142/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1143 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1144#define GE_OPT_PREFIX_BIG 3
a737bd4d 1145
b99bd4ef 1146static int
c19d1205 1147my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1148{
c19d1205 1149 char * save_in;
b99bd4ef 1150
c19d1205
ZW
1151 /* In unified syntax, all prefixes are optional. */
1152 if (unified_syntax)
5287ad62 1153 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1154 : GE_OPT_PREFIX;
b99bd4ef 1155
c19d1205 1156 switch (prefix_mode)
b99bd4ef 1157 {
c19d1205
ZW
1158 case GE_NO_PREFIX: break;
1159 case GE_IMM_PREFIX:
1160 if (!is_immediate_prefix (**str))
1161 {
1162 inst.error = _("immediate expression requires a # prefix");
1163 return FAIL;
1164 }
1165 (*str)++;
1166 break;
1167 case GE_OPT_PREFIX:
5287ad62 1168 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1169 if (is_immediate_prefix (**str))
1170 (*str)++;
1171 break;
0198d5e6
TC
1172 default:
1173 abort ();
c19d1205 1174 }
b99bd4ef 1175
c19d1205 1176 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1177
c19d1205
ZW
1178 save_in = input_line_pointer;
1179 input_line_pointer = *str;
0198d5e6 1180 in_my_get_expression = TRUE;
2ac93be7 1181 expression (ep);
0198d5e6 1182 in_my_get_expression = FALSE;
c19d1205 1183
f86adc07 1184 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1185 {
f86adc07 1186 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1187 *str = input_line_pointer;
1188 input_line_pointer = save_in;
1189 if (inst.error == NULL)
f86adc07
NS
1190 inst.error = (ep->X_op == O_absent
1191 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1192 return 1;
1193 }
b99bd4ef 1194
c19d1205
ZW
1195 /* Get rid of any bignums now, so that we don't generate an error for which
1196 we can't establish a line number later on. Big numbers are never valid
1197 in instructions, which is where this routine is always called. */
5287ad62
JB
1198 if (prefix_mode != GE_OPT_PREFIX_BIG
1199 && (ep->X_op == O_big
477330fc 1200 || (ep->X_add_symbol
5287ad62 1201 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1202 || (ep->X_op_symbol
5287ad62 1203 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1204 {
1205 inst.error = _("invalid constant");
1206 *str = input_line_pointer;
1207 input_line_pointer = save_in;
1208 return 1;
1209 }
b99bd4ef 1210
c19d1205
ZW
1211 *str = input_line_pointer;
1212 input_line_pointer = save_in;
0198d5e6 1213 return SUCCESS;
b99bd4ef
NC
1214}
1215
c19d1205
ZW
1216/* Turn a string in input_line_pointer into a floating point constant
1217 of type TYPE, and store the appropriate bytes in *LITP. The number
1218 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1219 returned, or NULL on OK.
b99bd4ef 1220
c19d1205
ZW
1221 Note that fp constants aren't represent in the normal way on the ARM.
1222 In big endian mode, things are as expected. However, in little endian
1223 mode fp constants are big-endian word-wise, and little-endian byte-wise
1224 within the words. For example, (double) 1.1 in big endian mode is
1225 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1226 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1227
c19d1205 1228 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1229
6d4af3c2 1230const char *
c19d1205
ZW
1231md_atof (int type, char * litP, int * sizeP)
1232{
1233 int prec;
1234 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1235 char *t;
1236 int i;
b99bd4ef 1237
c19d1205
ZW
1238 switch (type)
1239 {
5312fe52
BW
1240 case 'H':
1241 case 'h':
1242 prec = 1;
1243 break;
1244
27cce866
MM
1245 /* If this is a bfloat16, then parse it slightly differently, as it
1246 does not follow the IEEE specification for floating point numbers
1247 exactly. */
1248 case 'b':
1249 {
1250 FLONUM_TYPE generic_float;
1251
1252 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1253
1254 if (t)
1255 input_line_pointer = t;
1256 else
1257 return _("invalid floating point number");
1258
1259 switch (generic_float.sign)
1260 {
1261 /* Is +Inf. */
1262 case 'P':
1263 words[0] = 0x7f80;
1264 break;
1265
1266 /* Is -Inf. */
1267 case 'N':
1268 words[0] = 0xff80;
1269 break;
1270
1271 /* Is NaN. */
1272 /* bfloat16 has two types of NaN - quiet and signalling.
1273 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1274 signalling NaN's have bit[0] == 0 && fraction != 0.
1275 Chosen this specific encoding as it is the same form
1276 as used by other IEEE 754 encodings in GAS. */
1277 case 0:
1278 words[0] = 0x7fff;
1279 break;
1280
1281 default:
1282 break;
1283 }
1284
1285 *sizeP = 2;
1286
1287 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1288
1289 return NULL;
1290 }
c19d1205
ZW
1291 case 'f':
1292 case 'F':
1293 case 's':
1294 case 'S':
1295 prec = 2;
1296 break;
b99bd4ef 1297
c19d1205
ZW
1298 case 'd':
1299 case 'D':
1300 case 'r':
1301 case 'R':
1302 prec = 4;
1303 break;
b99bd4ef 1304
c19d1205
ZW
1305 case 'x':
1306 case 'X':
499ac353 1307 prec = 5;
c19d1205 1308 break;
b99bd4ef 1309
c19d1205
ZW
1310 case 'p':
1311 case 'P':
499ac353 1312 prec = 5;
c19d1205 1313 break;
a737bd4d 1314
c19d1205
ZW
1315 default:
1316 *sizeP = 0;
499ac353 1317 return _("Unrecognized or unsupported floating point constant");
c19d1205 1318 }
b99bd4ef 1319
c19d1205
ZW
1320 t = atof_ieee (input_line_pointer, type, words);
1321 if (t)
1322 input_line_pointer = t;
499ac353 1323 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1324
72c03e30
BW
1325 if (target_big_endian || prec == 1)
1326 for (i = 0; i < prec; i++)
1327 {
1328 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1329 litP += sizeof (LITTLENUM_TYPE);
1330 }
1331 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1332 for (i = prec - 1; i >= 0; i--)
1333 {
1334 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1335 litP += sizeof (LITTLENUM_TYPE);
1336 }
c19d1205 1337 else
72c03e30
BW
1338 /* For a 4 byte float the order of elements in `words' is 1 0.
1339 For an 8 byte float the order is 1 0 3 2. */
1340 for (i = 0; i < prec; i += 2)
1341 {
1342 md_number_to_chars (litP, (valueT) words[i + 1],
1343 sizeof (LITTLENUM_TYPE));
1344 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1345 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1346 litP += 2 * sizeof (LITTLENUM_TYPE);
1347 }
b99bd4ef 1348
499ac353 1349 return NULL;
c19d1205 1350}
b99bd4ef 1351
c19d1205
ZW
1352/* We handle all bad expressions here, so that we can report the faulty
1353 instruction in the error message. */
0198d5e6 1354
c19d1205 1355void
91d6fa6a 1356md_operand (expressionS * exp)
c19d1205
ZW
1357{
1358 if (in_my_get_expression)
91d6fa6a 1359 exp->X_op = O_illegal;
b99bd4ef
NC
1360}
1361
c19d1205 1362/* Immediate values. */
b99bd4ef 1363
0198d5e6 1364#ifdef OBJ_ELF
c19d1205
ZW
1365/* Generic immediate-value read function for use in directives.
1366 Accepts anything that 'expression' can fold to a constant.
1367 *val receives the number. */
0198d5e6 1368
c19d1205
ZW
1369static int
1370immediate_for_directive (int *val)
b99bd4ef 1371{
c19d1205
ZW
1372 expressionS exp;
1373 exp.X_op = O_illegal;
b99bd4ef 1374
c19d1205
ZW
1375 if (is_immediate_prefix (*input_line_pointer))
1376 {
1377 input_line_pointer++;
1378 expression (&exp);
1379 }
b99bd4ef 1380
c19d1205
ZW
1381 if (exp.X_op != O_constant)
1382 {
1383 as_bad (_("expected #constant"));
1384 ignore_rest_of_line ();
1385 return FAIL;
1386 }
1387 *val = exp.X_add_number;
1388 return SUCCESS;
b99bd4ef 1389}
c19d1205 1390#endif
b99bd4ef 1391
c19d1205 1392/* Register parsing. */
b99bd4ef 1393
c19d1205
ZW
1394/* Generic register parser. CCP points to what should be the
1395 beginning of a register name. If it is indeed a valid register
1396 name, advance CCP over it and return the reg_entry structure;
1397 otherwise return NULL. Does not issue diagnostics. */
1398
1399static struct reg_entry *
1400arm_reg_parse_multi (char **ccp)
b99bd4ef 1401{
c19d1205
ZW
1402 char *start = *ccp;
1403 char *p;
1404 struct reg_entry *reg;
b99bd4ef 1405
477330fc
RM
1406 skip_whitespace (start);
1407
c19d1205
ZW
1408#ifdef REGISTER_PREFIX
1409 if (*start != REGISTER_PREFIX)
01cfc07f 1410 return NULL;
c19d1205
ZW
1411 start++;
1412#endif
1413#ifdef OPTIONAL_REGISTER_PREFIX
1414 if (*start == OPTIONAL_REGISTER_PREFIX)
1415 start++;
1416#endif
b99bd4ef 1417
c19d1205
ZW
1418 p = start;
1419 if (!ISALPHA (*p) || !is_name_beginner (*p))
1420 return NULL;
b99bd4ef 1421
c19d1205
ZW
1422 do
1423 p++;
1424 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1425
1426 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1427
1428 if (!reg)
1429 return NULL;
1430
1431 *ccp = p;
1432 return reg;
b99bd4ef
NC
1433}
1434
1435static int
dcbf9037 1436arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1437 enum arm_reg_type type)
b99bd4ef 1438{
c19d1205
ZW
1439 /* Alternative syntaxes are accepted for a few register classes. */
1440 switch (type)
1441 {
1442 case REG_TYPE_MVF:
1443 case REG_TYPE_MVD:
1444 case REG_TYPE_MVFX:
1445 case REG_TYPE_MVDX:
1446 /* Generic coprocessor register names are allowed for these. */
79134647 1447 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1448 return reg->number;
1449 break;
69b97547 1450
c19d1205
ZW
1451 case REG_TYPE_CP:
1452 /* For backward compatibility, a bare number is valid here. */
1453 {
1454 unsigned long processor = strtoul (start, ccp, 10);
1455 if (*ccp != start && processor <= 15)
1456 return processor;
1457 }
1a0670f3 1458 /* Fall through. */
6057a28f 1459
c19d1205
ZW
1460 case REG_TYPE_MMXWC:
1461 /* WC includes WCG. ??? I'm not sure this is true for all
1462 instructions that take WC registers. */
79134647 1463 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1464 return reg->number;
6057a28f 1465 break;
c19d1205 1466
6057a28f 1467 default:
c19d1205 1468 break;
6057a28f
NC
1469 }
1470
dcbf9037
JB
1471 return FAIL;
1472}
1473
1474/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1475 return value is the register number or FAIL. */
1476
1477static int
1478arm_reg_parse (char **ccp, enum arm_reg_type type)
1479{
1480 char *start = *ccp;
1481 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1482 int ret;
1483
1484 /* Do not allow a scalar (reg+index) to parse as a register. */
1485 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1486 return FAIL;
1487
1488 if (reg && reg->type == type)
1489 return reg->number;
1490
1491 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1492 return ret;
1493
c19d1205
ZW
1494 *ccp = start;
1495 return FAIL;
1496}
69b97547 1497
dcbf9037
JB
1498/* Parse a Neon type specifier. *STR should point at the leading '.'
1499 character. Does no verification at this stage that the type fits the opcode
1500 properly. E.g.,
1501
1502 .i32.i32.s16
1503 .s32.f32
1504 .u16
1505
1506 Can all be legally parsed by this function.
1507
1508 Fills in neon_type struct pointer with parsed information, and updates STR
1509 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1510 type, FAIL if not. */
1511
1512static int
1513parse_neon_type (struct neon_type *type, char **str)
1514{
1515 char *ptr = *str;
1516
1517 if (type)
1518 type->elems = 0;
1519
1520 while (type->elems < NEON_MAX_TYPE_ELS)
1521 {
1522 enum neon_el_type thistype = NT_untyped;
1523 unsigned thissize = -1u;
1524
1525 if (*ptr != '.')
1526 break;
1527
1528 ptr++;
1529
1530 /* Just a size without an explicit type. */
1531 if (ISDIGIT (*ptr))
1532 goto parsesize;
1533
1534 switch (TOLOWER (*ptr))
1535 {
1536 case 'i': thistype = NT_integer; break;
1537 case 'f': thistype = NT_float; break;
1538 case 'p': thistype = NT_poly; break;
1539 case 's': thistype = NT_signed; break;
1540 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1541 case 'd':
1542 thistype = NT_float;
1543 thissize = 64;
1544 ptr++;
1545 goto done;
aab2c27d
MM
1546 case 'b':
1547 thistype = NT_bfloat;
1548 switch (TOLOWER (*(++ptr)))
1549 {
1550 case 'f':
1551 ptr += 1;
1552 thissize = strtoul (ptr, &ptr, 10);
1553 if (thissize != 16)
1554 {
1555 as_bad (_("bad size %d in type specifier"), thissize);
1556 return FAIL;
1557 }
1558 goto done;
1559 case '0': case '1': case '2': case '3': case '4':
1560 case '5': case '6': case '7': case '8': case '9':
1561 case ' ': case '.':
1562 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1563 return FAIL;
1564 default:
1565 break;
1566 }
1567 break;
dcbf9037
JB
1568 default:
1569 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1570 return FAIL;
1571 }
1572
1573 ptr++;
1574
1575 /* .f is an abbreviation for .f32. */
1576 if (thistype == NT_float && !ISDIGIT (*ptr))
1577 thissize = 32;
1578 else
1579 {
1580 parsesize:
1581 thissize = strtoul (ptr, &ptr, 10);
1582
1583 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1584 && thissize != 64)
1585 {
1586 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1587 return FAIL;
1588 }
1589 }
1590
037e8744 1591 done:
dcbf9037 1592 if (type)
477330fc
RM
1593 {
1594 type->el[type->elems].type = thistype;
dcbf9037
JB
1595 type->el[type->elems].size = thissize;
1596 type->elems++;
1597 }
1598 }
1599
1600 /* Empty/missing type is not a successful parse. */
1601 if (type->elems == 0)
1602 return FAIL;
1603
1604 *str = ptr;
1605
1606 return SUCCESS;
1607}
1608
1609/* Errors may be set multiple times during parsing or bit encoding
1610 (particularly in the Neon bits), but usually the earliest error which is set
1611 will be the most meaningful. Avoid overwriting it with later (cascading)
1612 errors by calling this function. */
1613
1614static void
1615first_error (const char *err)
1616{
1617 if (!inst.error)
1618 inst.error = err;
1619}
1620
1621/* Parse a single type, e.g. ".s32", leading period included. */
1622static int
1623parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1624{
1625 char *str = *ccp;
1626 struct neon_type optype;
1627
1628 if (*str == '.')
1629 {
1630 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1631 {
1632 if (optype.elems == 1)
1633 *vectype = optype.el[0];
1634 else
1635 {
1636 first_error (_("only one type should be specified for operand"));
1637 return FAIL;
1638 }
1639 }
dcbf9037 1640 else
477330fc
RM
1641 {
1642 first_error (_("vector type expected"));
1643 return FAIL;
1644 }
dcbf9037
JB
1645 }
1646 else
1647 return FAIL;
5f4273c7 1648
dcbf9037 1649 *ccp = str;
5f4273c7 1650
dcbf9037
JB
1651 return SUCCESS;
1652}
1653
1654/* Special meanings for indices (which have a range of 0-7), which will fit into
1655 a 4-bit integer. */
1656
1657#define NEON_ALL_LANES 15
1658#define NEON_INTERLEAVE_LANES 14
1659
5ee91343
AV
1660/* Record a use of the given feature. */
1661static void
1662record_feature_use (const arm_feature_set *feature)
1663{
1664 if (thumb_mode)
1665 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1666 else
1667 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1668}
1669
1670/* If the given feature available in the selected CPU, mark it as used.
1671 Returns TRUE iff feature is available. */
1672static bfd_boolean
1673mark_feature_used (const arm_feature_set *feature)
1674{
886e1c73
AV
1675
1676 /* Do not support the use of MVE only instructions when in auto-detection or
1677 -march=all. */
1678 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1679 && ARM_CPU_IS_ANY (cpu_variant))
1680 {
1681 first_error (BAD_MVE_AUTO);
1682 return FALSE;
1683 }
5ee91343
AV
1684 /* Ensure the option is valid on the current architecture. */
1685 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1686 return FALSE;
1687
1688 /* Add the appropriate architecture feature for the barrier option used.
1689 */
1690 record_feature_use (feature);
1691
1692 return TRUE;
1693}
1694
dcbf9037
JB
1695/* Parse either a register or a scalar, with an optional type. Return the
1696 register number, and optionally fill in the actual type of the register
1697 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1698 type/index information in *TYPEINFO. */
1699
1700static int
1701parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1702 enum arm_reg_type *rtype,
1703 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1704{
1705 char *str = *ccp;
1706 struct reg_entry *reg = arm_reg_parse_multi (&str);
1707 struct neon_typed_alias atype;
1708 struct neon_type_el parsetype;
1709
1710 atype.defined = 0;
1711 atype.index = -1;
1712 atype.eltype.type = NT_invtype;
1713 atype.eltype.size = -1;
1714
1715 /* Try alternate syntax for some types of register. Note these are mutually
1716 exclusive with the Neon syntax extensions. */
1717 if (reg == NULL)
1718 {
1719 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1720 if (altreg != FAIL)
477330fc 1721 *ccp = str;
dcbf9037 1722 if (typeinfo)
477330fc 1723 *typeinfo = atype;
dcbf9037
JB
1724 return altreg;
1725 }
1726
037e8744
JB
1727 /* Undo polymorphism when a set of register types may be accepted. */
1728 if ((type == REG_TYPE_NDQ
1729 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1730 || (type == REG_TYPE_VFSD
477330fc 1731 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1732 || (type == REG_TYPE_NSDQ
477330fc
RM
1733 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1734 || reg->type == REG_TYPE_NQ))
dec41383
JW
1735 || (type == REG_TYPE_NSD
1736 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1737 || (type == REG_TYPE_MMXWC
1738 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1739 type = (enum arm_reg_type) reg->type;
dcbf9037 1740
5ee91343
AV
1741 if (type == REG_TYPE_MQ)
1742 {
1743 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1744 return FAIL;
1745
1746 if (!reg || reg->type != REG_TYPE_NQ)
1747 return FAIL;
1748
1749 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1750 {
1751 first_error (_("expected MVE register [q0..q7]"));
1752 return FAIL;
1753 }
1754 type = REG_TYPE_NQ;
1755 }
1756 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1757 && (type == REG_TYPE_NQ))
1758 return FAIL;
1759
1760
dcbf9037
JB
1761 if (type != reg->type)
1762 return FAIL;
1763
1764 if (reg->neon)
1765 atype = *reg->neon;
5f4273c7 1766
dcbf9037
JB
1767 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1768 {
1769 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1770 {
1771 first_error (_("can't redefine type for operand"));
1772 return FAIL;
1773 }
dcbf9037
JB
1774 atype.defined |= NTA_HASTYPE;
1775 atype.eltype = parsetype;
1776 }
5f4273c7 1777
dcbf9037
JB
1778 if (skip_past_char (&str, '[') == SUCCESS)
1779 {
dec41383
JW
1780 if (type != REG_TYPE_VFD
1781 && !(type == REG_TYPE_VFS
57785aa2
AV
1782 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1783 && !(type == REG_TYPE_NQ
1784 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1785 {
57785aa2
AV
1786 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1787 first_error (_("only D and Q registers may be indexed"));
1788 else
1789 first_error (_("only D registers may be indexed"));
477330fc
RM
1790 return FAIL;
1791 }
5f4273c7 1792
dcbf9037 1793 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1794 {
1795 first_error (_("can't change index for operand"));
1796 return FAIL;
1797 }
dcbf9037
JB
1798
1799 atype.defined |= NTA_HASINDEX;
1800
1801 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1802 atype.index = NEON_ALL_LANES;
dcbf9037 1803 else
477330fc
RM
1804 {
1805 expressionS exp;
dcbf9037 1806
477330fc 1807 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1808
477330fc
RM
1809 if (exp.X_op != O_constant)
1810 {
1811 first_error (_("constant expression required"));
1812 return FAIL;
1813 }
dcbf9037 1814
477330fc
RM
1815 if (skip_past_char (&str, ']') == FAIL)
1816 return FAIL;
dcbf9037 1817
477330fc
RM
1818 atype.index = exp.X_add_number;
1819 }
dcbf9037 1820 }
5f4273c7 1821
dcbf9037
JB
1822 if (typeinfo)
1823 *typeinfo = atype;
5f4273c7 1824
dcbf9037
JB
1825 if (rtype)
1826 *rtype = type;
5f4273c7 1827
dcbf9037 1828 *ccp = str;
5f4273c7 1829
dcbf9037
JB
1830 return reg->number;
1831}
1832
efd6b359 1833/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1834 - If RTYPE is non-zero, return the (possibly restricted) type of the
1835 register (e.g. Neon double or quad reg when either has been requested).
1836 - If this is a Neon vector type with additional type information, fill
1837 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1838 This function will fault on encountering a scalar. */
dcbf9037
JB
1839
1840static int
1841arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1842 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1843{
1844 struct neon_typed_alias atype;
1845 char *str = *ccp;
1846 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1847
1848 if (reg == FAIL)
1849 return FAIL;
1850
0855e32b
NS
1851 /* Do not allow regname(... to parse as a register. */
1852 if (*str == '(')
1853 return FAIL;
1854
dcbf9037
JB
1855 /* Do not allow a scalar (reg+index) to parse as a register. */
1856 if ((atype.defined & NTA_HASINDEX) != 0)
1857 {
1858 first_error (_("register operand expected, but got scalar"));
1859 return FAIL;
1860 }
1861
1862 if (vectype)
1863 *vectype = atype.eltype;
1864
1865 *ccp = str;
1866
1867 return reg;
1868}
1869
1870#define NEON_SCALAR_REG(X) ((X) >> 4)
1871#define NEON_SCALAR_INDEX(X) ((X) & 15)
1872
5287ad62
JB
1873/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1874 have enough information to be able to do a good job bounds-checking. So, we
1875 just do easy checks here, and do further checks later. */
1876
1877static int
57785aa2
AV
1878parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1879 arm_reg_type reg_type)
5287ad62 1880{
dcbf9037 1881 int reg;
5287ad62 1882 char *str = *ccp;
dcbf9037 1883 struct neon_typed_alias atype;
57785aa2 1884 unsigned reg_size;
5f4273c7 1885
dec41383 1886 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1887
57785aa2
AV
1888 switch (reg_type)
1889 {
1890 case REG_TYPE_VFS:
1891 reg_size = 32;
1892 break;
1893 case REG_TYPE_VFD:
1894 reg_size = 64;
1895 break;
1896 case REG_TYPE_MQ:
1897 reg_size = 128;
1898 break;
1899 default:
1900 gas_assert (0);
1901 return FAIL;
1902 }
1903
dcbf9037 1904 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1905 return FAIL;
5f4273c7 1906
57785aa2 1907 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1908 {
dcbf9037 1909 first_error (_("scalar must have an index"));
5287ad62
JB
1910 return FAIL;
1911 }
57785aa2 1912 else if (atype.index >= reg_size / elsize)
5287ad62 1913 {
dcbf9037 1914 first_error (_("scalar index out of range"));
5287ad62
JB
1915 return FAIL;
1916 }
5f4273c7 1917
dcbf9037
JB
1918 if (type)
1919 *type = atype.eltype;
5f4273c7 1920
5287ad62 1921 *ccp = str;
5f4273c7 1922
dcbf9037 1923 return reg * 16 + atype.index;
5287ad62
JB
1924}
1925
4b5a202f
AV
1926/* Types of registers in a list. */
1927
1928enum reg_list_els
1929{
1930 REGLIST_RN,
1931 REGLIST_CLRM,
1932 REGLIST_VFP_S,
efd6b359 1933 REGLIST_VFP_S_VPR,
4b5a202f 1934 REGLIST_VFP_D,
efd6b359 1935 REGLIST_VFP_D_VPR,
4b5a202f
AV
1936 REGLIST_NEON_D
1937};
1938
c19d1205 1939/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1940
c19d1205 1941static long
4b5a202f 1942parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1943{
4b5a202f
AV
1944 char *str = *strp;
1945 long range = 0;
1946 int another_range;
1947
1948 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1949
c19d1205
ZW
1950 /* We come back here if we get ranges concatenated by '+' or '|'. */
1951 do
6057a28f 1952 {
477330fc
RM
1953 skip_whitespace (str);
1954
c19d1205 1955 another_range = 0;
a737bd4d 1956
c19d1205
ZW
1957 if (*str == '{')
1958 {
1959 int in_range = 0;
1960 int cur_reg = -1;
a737bd4d 1961
c19d1205
ZW
1962 str++;
1963 do
1964 {
1965 int reg;
4b5a202f
AV
1966 const char apsr_str[] = "apsr";
1967 int apsr_str_len = strlen (apsr_str);
6057a28f 1968
a65b5de6 1969 reg = arm_reg_parse (&str, REG_TYPE_RN);
4b5a202f 1970 if (etype == REGLIST_CLRM)
c19d1205 1971 {
4b5a202f
AV
1972 if (reg == REG_SP || reg == REG_PC)
1973 reg = FAIL;
1974 else if (reg == FAIL
1975 && !strncasecmp (str, apsr_str, apsr_str_len)
1976 && !ISALPHA (*(str + apsr_str_len)))
1977 {
1978 reg = 15;
1979 str += apsr_str_len;
1980 }
1981
1982 if (reg == FAIL)
1983 {
1984 first_error (_("r0-r12, lr or APSR expected"));
1985 return FAIL;
1986 }
1987 }
1988 else /* etype == REGLIST_RN. */
1989 {
1990 if (reg == FAIL)
1991 {
1992 first_error (_(reg_expected_msgs[REGLIST_RN]));
1993 return FAIL;
1994 }
c19d1205 1995 }
a737bd4d 1996
c19d1205
ZW
1997 if (in_range)
1998 {
1999 int i;
a737bd4d 2000
c19d1205
ZW
2001 if (reg <= cur_reg)
2002 {
dcbf9037 2003 first_error (_("bad range in register list"));
c19d1205
ZW
2004 return FAIL;
2005 }
40a18ebd 2006
c19d1205
ZW
2007 for (i = cur_reg + 1; i < reg; i++)
2008 {
2009 if (range & (1 << i))
2010 as_tsktsk
2011 (_("Warning: duplicated register (r%d) in register list"),
2012 i);
2013 else
2014 range |= 1 << i;
2015 }
2016 in_range = 0;
2017 }
a737bd4d 2018
c19d1205
ZW
2019 if (range & (1 << reg))
2020 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2021 reg);
2022 else if (reg <= cur_reg)
2023 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 2024
c19d1205
ZW
2025 range |= 1 << reg;
2026 cur_reg = reg;
2027 }
2028 while (skip_past_comma (&str) != FAIL
2029 || (in_range = 1, *str++ == '-'));
2030 str--;
a737bd4d 2031
d996d970 2032 if (skip_past_char (&str, '}') == FAIL)
c19d1205 2033 {
dcbf9037 2034 first_error (_("missing `}'"));
c19d1205
ZW
2035 return FAIL;
2036 }
2037 }
4b5a202f 2038 else if (etype == REGLIST_RN)
c19d1205 2039 {
91d6fa6a 2040 expressionS exp;
40a18ebd 2041
91d6fa6a 2042 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 2043 return FAIL;
40a18ebd 2044
91d6fa6a 2045 if (exp.X_op == O_constant)
c19d1205 2046 {
91d6fa6a
NC
2047 if (exp.X_add_number
2048 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
2049 {
2050 inst.error = _("invalid register mask");
2051 return FAIL;
2052 }
a737bd4d 2053
91d6fa6a 2054 if ((range & exp.X_add_number) != 0)
c19d1205 2055 {
91d6fa6a 2056 int regno = range & exp.X_add_number;
a737bd4d 2057
c19d1205
ZW
2058 regno &= -regno;
2059 regno = (1 << regno) - 1;
2060 as_tsktsk
2061 (_("Warning: duplicated register (r%d) in register list"),
2062 regno);
2063 }
a737bd4d 2064
91d6fa6a 2065 range |= exp.X_add_number;
c19d1205
ZW
2066 }
2067 else
2068 {
e2b0ab59 2069 if (inst.relocs[0].type != 0)
c19d1205
ZW
2070 {
2071 inst.error = _("expression too complex");
2072 return FAIL;
2073 }
a737bd4d 2074
e2b0ab59
AV
2075 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2076 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2077 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
2078 }
2079 }
a737bd4d 2080
c19d1205
ZW
2081 if (*str == '|' || *str == '+')
2082 {
2083 str++;
2084 another_range = 1;
2085 }
a737bd4d 2086 }
c19d1205 2087 while (another_range);
a737bd4d 2088
c19d1205
ZW
2089 *strp = str;
2090 return range;
a737bd4d
NC
2091}
2092
c19d1205
ZW
2093/* Parse a VFP register list. If the string is invalid return FAIL.
2094 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
2095 register. Parses registers of type ETYPE.
2096 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2097 - Q registers can be used to specify pairs of D registers
2098 - { } can be omitted from around a singleton register list
477330fc
RM
2099 FIXME: This is not implemented, as it would require backtracking in
2100 some cases, e.g.:
2101 vtbl.8 d3,d4,d5
2102 This could be done (the meaning isn't really ambiguous), but doesn't
2103 fit in well with the current parsing framework.
dcbf9037
JB
2104 - 32 D registers may be used (also true for VFPv3).
2105 FIXME: Types are ignored in these register lists, which is probably a
2106 bug. */
6057a28f 2107
c19d1205 2108static int
efd6b359
AV
2109parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2110 bfd_boolean *partial_match)
6057a28f 2111{
037e8744 2112 char *str = *ccp;
c19d1205
ZW
2113 int base_reg;
2114 int new_base;
21d799b5 2115 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2116 int max_regs = 0;
c19d1205
ZW
2117 int count = 0;
2118 int warned = 0;
2119 unsigned long mask = 0;
a737bd4d 2120 int i;
efd6b359
AV
2121 bfd_boolean vpr_seen = FALSE;
2122 bfd_boolean expect_vpr =
2123 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2124
477330fc 2125 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2126 {
2127 inst.error = _("expecting {");
2128 return FAIL;
2129 }
6057a28f 2130
5287ad62 2131 switch (etype)
c19d1205 2132 {
5287ad62 2133 case REGLIST_VFP_S:
efd6b359 2134 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2135 regtype = REG_TYPE_VFS;
2136 max_regs = 32;
5287ad62 2137 break;
5f4273c7 2138
5287ad62 2139 case REGLIST_VFP_D:
efd6b359 2140 case REGLIST_VFP_D_VPR:
5287ad62 2141 regtype = REG_TYPE_VFD;
b7fc2769 2142 break;
5f4273c7 2143
b7fc2769
JB
2144 case REGLIST_NEON_D:
2145 regtype = REG_TYPE_NDQ;
2146 break;
4b5a202f
AV
2147
2148 default:
2149 gas_assert (0);
b7fc2769
JB
2150 }
2151
efd6b359 2152 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2153 {
b1cc4aeb
PB
2154 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2155 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2156 {
2157 max_regs = 32;
2158 if (thumb_mode)
2159 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2160 fpu_vfp_ext_d32);
2161 else
2162 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2163 fpu_vfp_ext_d32);
2164 }
5287ad62 2165 else
477330fc 2166 max_regs = 16;
c19d1205 2167 }
6057a28f 2168
c19d1205 2169 base_reg = max_regs;
efd6b359 2170 *partial_match = FALSE;
a737bd4d 2171
c19d1205
ZW
2172 do
2173 {
5287ad62 2174 int setmask = 1, addregs = 1;
efd6b359
AV
2175 const char vpr_str[] = "vpr";
2176 int vpr_str_len = strlen (vpr_str);
dcbf9037 2177
037e8744 2178 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2179
efd6b359
AV
2180 if (expect_vpr)
2181 {
2182 if (new_base == FAIL
2183 && !strncasecmp (str, vpr_str, vpr_str_len)
2184 && !ISALPHA (*(str + vpr_str_len))
2185 && !vpr_seen)
2186 {
2187 vpr_seen = TRUE;
2188 str += vpr_str_len;
2189 if (count == 0)
2190 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2191 }
2192 else if (vpr_seen)
2193 {
2194 first_error (_("VPR expected last"));
2195 return FAIL;
2196 }
2197 else if (new_base == FAIL)
2198 {
2199 if (regtype == REG_TYPE_VFS)
2200 first_error (_("VFP single precision register or VPR "
2201 "expected"));
2202 else /* regtype == REG_TYPE_VFD. */
2203 first_error (_("VFP/Neon double precision register or VPR "
2204 "expected"));
2205 return FAIL;
2206 }
2207 }
2208 else if (new_base == FAIL)
a737bd4d 2209 {
dcbf9037 2210 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2211 return FAIL;
2212 }
5f4273c7 2213
efd6b359
AV
2214 *partial_match = TRUE;
2215 if (vpr_seen)
2216 continue;
2217
b7fc2769 2218 if (new_base >= max_regs)
477330fc
RM
2219 {
2220 first_error (_("register out of range in list"));
2221 return FAIL;
2222 }
5f4273c7 2223
5287ad62
JB
2224 /* Note: a value of 2 * n is returned for the register Q<n>. */
2225 if (regtype == REG_TYPE_NQ)
477330fc
RM
2226 {
2227 setmask = 3;
2228 addregs = 2;
2229 }
5287ad62 2230
c19d1205
ZW
2231 if (new_base < base_reg)
2232 base_reg = new_base;
a737bd4d 2233
5287ad62 2234 if (mask & (setmask << new_base))
c19d1205 2235 {
dcbf9037 2236 first_error (_("invalid register list"));
c19d1205 2237 return FAIL;
a737bd4d 2238 }
a737bd4d 2239
efd6b359 2240 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2241 {
2242 as_tsktsk (_("register list not in ascending order"));
2243 warned = 1;
2244 }
0bbf2aa4 2245
5287ad62
JB
2246 mask |= setmask << new_base;
2247 count += addregs;
0bbf2aa4 2248
037e8744 2249 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2250 {
2251 int high_range;
0bbf2aa4 2252
037e8744 2253 str++;
0bbf2aa4 2254
037e8744 2255 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2256 == FAIL)
c19d1205
ZW
2257 {
2258 inst.error = gettext (reg_expected_msgs[regtype]);
2259 return FAIL;
2260 }
0bbf2aa4 2261
477330fc
RM
2262 if (high_range >= max_regs)
2263 {
2264 first_error (_("register out of range in list"));
2265 return FAIL;
2266 }
b7fc2769 2267
477330fc
RM
2268 if (regtype == REG_TYPE_NQ)
2269 high_range = high_range + 1;
5287ad62 2270
c19d1205
ZW
2271 if (high_range <= new_base)
2272 {
2273 inst.error = _("register range not in ascending order");
2274 return FAIL;
2275 }
0bbf2aa4 2276
5287ad62 2277 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2278 {
5287ad62 2279 if (mask & (setmask << new_base))
0bbf2aa4 2280 {
c19d1205
ZW
2281 inst.error = _("invalid register list");
2282 return FAIL;
0bbf2aa4 2283 }
c19d1205 2284
5287ad62
JB
2285 mask |= setmask << new_base;
2286 count += addregs;
0bbf2aa4 2287 }
0bbf2aa4 2288 }
0bbf2aa4 2289 }
037e8744 2290 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2291
037e8744 2292 str++;
0bbf2aa4 2293
c19d1205 2294 /* Sanity check -- should have raised a parse error above. */
efd6b359 2295 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2296 abort ();
2297
2298 *pbase = base_reg;
2299
efd6b359
AV
2300 if (expect_vpr && !vpr_seen)
2301 {
2302 first_error (_("VPR expected last"));
2303 return FAIL;
2304 }
2305
c19d1205
ZW
2306 /* Final test -- the registers must be consecutive. */
2307 mask >>= base_reg;
2308 for (i = 0; i < count; i++)
2309 {
2310 if ((mask & (1u << i)) == 0)
2311 {
2312 inst.error = _("non-contiguous register range");
2313 return FAIL;
2314 }
2315 }
2316
037e8744
JB
2317 *ccp = str;
2318
c19d1205 2319 return count;
b99bd4ef
NC
2320}
2321
dcbf9037
JB
2322/* True if two alias types are the same. */
2323
c921be7d 2324static bfd_boolean
dcbf9037
JB
2325neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2326{
2327 if (!a && !b)
c921be7d 2328 return TRUE;
5f4273c7 2329
dcbf9037 2330 if (!a || !b)
c921be7d 2331 return FALSE;
dcbf9037
JB
2332
2333 if (a->defined != b->defined)
c921be7d 2334 return FALSE;
5f4273c7 2335
dcbf9037
JB
2336 if ((a->defined & NTA_HASTYPE) != 0
2337 && (a->eltype.type != b->eltype.type
477330fc 2338 || a->eltype.size != b->eltype.size))
c921be7d 2339 return FALSE;
dcbf9037
JB
2340
2341 if ((a->defined & NTA_HASINDEX) != 0
2342 && (a->index != b->index))
c921be7d 2343 return FALSE;
5f4273c7 2344
c921be7d 2345 return TRUE;
dcbf9037
JB
2346}
2347
5287ad62
JB
2348/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2349 The base register is put in *PBASE.
dcbf9037 2350 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2351 the return value.
2352 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2353 Bits [6:5] encode the list length (minus one).
2354 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2355
5287ad62 2356#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2357#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2358#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2359
2360static int
dcbf9037 2361parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2362 int mve,
477330fc 2363 struct neon_type_el *eltype)
5287ad62
JB
2364{
2365 char *ptr = *str;
2366 int base_reg = -1;
2367 int reg_incr = -1;
2368 int count = 0;
2369 int lane = -1;
2370 int leading_brace = 0;
2371 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2372 const char *const incr_error = mve ? _("register stride must be 1") :
2373 _("register stride must be 1 or 2");
20203fb9 2374 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2375 struct neon_typed_alias firsttype;
f85d59c3
KT
2376 firsttype.defined = 0;
2377 firsttype.eltype.type = NT_invtype;
2378 firsttype.eltype.size = -1;
2379 firsttype.index = -1;
5f4273c7 2380
5287ad62
JB
2381 if (skip_past_char (&ptr, '{') == SUCCESS)
2382 leading_brace = 1;
5f4273c7 2383
5287ad62
JB
2384 do
2385 {
dcbf9037 2386 struct neon_typed_alias atype;
35c228db
AV
2387 if (mve)
2388 rtype = REG_TYPE_MQ;
dcbf9037
JB
2389 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2390
5287ad62 2391 if (getreg == FAIL)
477330fc
RM
2392 {
2393 first_error (_(reg_expected_msgs[rtype]));
2394 return FAIL;
2395 }
5f4273c7 2396
5287ad62 2397 if (base_reg == -1)
477330fc
RM
2398 {
2399 base_reg = getreg;
2400 if (rtype == REG_TYPE_NQ)
2401 {
2402 reg_incr = 1;
2403 }
2404 firsttype = atype;
2405 }
5287ad62 2406 else if (reg_incr == -1)
477330fc
RM
2407 {
2408 reg_incr = getreg - base_reg;
2409 if (reg_incr < 1 || reg_incr > 2)
2410 {
2411 first_error (_(incr_error));
2412 return FAIL;
2413 }
2414 }
5287ad62 2415 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2416 {
2417 first_error (_(incr_error));
2418 return FAIL;
2419 }
dcbf9037 2420
c921be7d 2421 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2422 {
2423 first_error (_(type_error));
2424 return FAIL;
2425 }
5f4273c7 2426
5287ad62 2427 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2428 modes. */
5287ad62 2429 if (ptr[0] == '-')
477330fc
RM
2430 {
2431 struct neon_typed_alias htype;
2432 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2433 if (lane == -1)
2434 lane = NEON_INTERLEAVE_LANES;
2435 else if (lane != NEON_INTERLEAVE_LANES)
2436 {
2437 first_error (_(type_error));
2438 return FAIL;
2439 }
2440 if (reg_incr == -1)
2441 reg_incr = 1;
2442 else if (reg_incr != 1)
2443 {
2444 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2445 return FAIL;
2446 }
2447 ptr++;
2448 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2449 if (hireg == FAIL)
2450 {
2451 first_error (_(reg_expected_msgs[rtype]));
2452 return FAIL;
2453 }
2454 if (! neon_alias_types_same (&htype, &firsttype))
2455 {
2456 first_error (_(type_error));
2457 return FAIL;
2458 }
2459 count += hireg + dregs - getreg;
2460 continue;
2461 }
5f4273c7 2462
5287ad62
JB
2463 /* If we're using Q registers, we can't use [] or [n] syntax. */
2464 if (rtype == REG_TYPE_NQ)
477330fc
RM
2465 {
2466 count += 2;
2467 continue;
2468 }
5f4273c7 2469
dcbf9037 2470 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2471 {
2472 if (lane == -1)
2473 lane = atype.index;
2474 else if (lane != atype.index)
2475 {
2476 first_error (_(type_error));
2477 return FAIL;
2478 }
2479 }
5287ad62 2480 else if (lane == -1)
477330fc 2481 lane = NEON_INTERLEAVE_LANES;
5287ad62 2482 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2483 {
2484 first_error (_(type_error));
2485 return FAIL;
2486 }
5287ad62
JB
2487 count++;
2488 }
2489 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2490
5287ad62
JB
2491 /* No lane set by [x]. We must be interleaving structures. */
2492 if (lane == -1)
2493 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2494
5287ad62 2495 /* Sanity check. */
35c228db 2496 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2497 || (count > 1 && reg_incr == -1))
2498 {
dcbf9037 2499 first_error (_("error parsing element/structure list"));
5287ad62
JB
2500 return FAIL;
2501 }
2502
2503 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2504 {
dcbf9037 2505 first_error (_("expected }"));
5287ad62
JB
2506 return FAIL;
2507 }
5f4273c7 2508
5287ad62
JB
2509 if (reg_incr == -1)
2510 reg_incr = 1;
2511
dcbf9037
JB
2512 if (eltype)
2513 *eltype = firsttype.eltype;
2514
5287ad62
JB
2515 *pbase = base_reg;
2516 *str = ptr;
5f4273c7 2517
5287ad62
JB
2518 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2519}
2520
c19d1205
ZW
2521/* Parse an explicit relocation suffix on an expression. This is
2522 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2523 arm_reloc_hsh contains no entries, so this function can only
2524 succeed if there is no () after the word. Returns -1 on error,
2525 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2526
c19d1205
ZW
2527static int
2528parse_reloc (char **str)
b99bd4ef 2529{
c19d1205
ZW
2530 struct reloc_entry *r;
2531 char *p, *q;
b99bd4ef 2532
c19d1205
ZW
2533 if (**str != '(')
2534 return BFD_RELOC_UNUSED;
b99bd4ef 2535
c19d1205
ZW
2536 p = *str + 1;
2537 q = p;
2538
2539 while (*q && *q != ')' && *q != ',')
2540 q++;
2541 if (*q != ')')
2542 return -1;
2543
21d799b5
NC
2544 if ((r = (struct reloc_entry *)
2545 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2546 return -1;
2547
2548 *str = q + 1;
2549 return r->reloc;
b99bd4ef
NC
2550}
2551
c19d1205
ZW
2552/* Directives: register aliases. */
2553
dcbf9037 2554static struct reg_entry *
90ec0d68 2555insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2556{
d3ce72d0 2557 struct reg_entry *new_reg;
c19d1205 2558 const char *name;
b99bd4ef 2559
d3ce72d0 2560 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2561 {
d3ce72d0 2562 if (new_reg->builtin)
c19d1205 2563 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2564
c19d1205
ZW
2565 /* Only warn about a redefinition if it's not defined as the
2566 same register. */
d3ce72d0 2567 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2568 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2569
d929913e 2570 return NULL;
c19d1205 2571 }
b99bd4ef 2572
c19d1205 2573 name = xstrdup (str);
325801bd 2574 new_reg = XNEW (struct reg_entry);
b99bd4ef 2575
d3ce72d0
NC
2576 new_reg->name = name;
2577 new_reg->number = number;
2578 new_reg->type = type;
2579 new_reg->builtin = FALSE;
2580 new_reg->neon = NULL;
b99bd4ef 2581
d3ce72d0 2582 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2583 abort ();
5f4273c7 2584
d3ce72d0 2585 return new_reg;
dcbf9037
JB
2586}
2587
2588static void
2589insert_neon_reg_alias (char *str, int number, int type,
477330fc 2590 struct neon_typed_alias *atype)
dcbf9037
JB
2591{
2592 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2593
dcbf9037
JB
2594 if (!reg)
2595 {
2596 first_error (_("attempt to redefine typed alias"));
2597 return;
2598 }
5f4273c7 2599
dcbf9037
JB
2600 if (atype)
2601 {
325801bd 2602 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2603 *reg->neon = *atype;
2604 }
c19d1205 2605}
b99bd4ef 2606
c19d1205 2607/* Look for the .req directive. This is of the form:
b99bd4ef 2608
c19d1205 2609 new_register_name .req existing_register_name
b99bd4ef 2610
c19d1205 2611 If we find one, or if it looks sufficiently like one that we want to
d929913e 2612 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2613
d929913e 2614static bfd_boolean
c19d1205
ZW
2615create_register_alias (char * newname, char *p)
2616{
2617 struct reg_entry *old;
2618 char *oldname, *nbuf;
2619 size_t nlen;
b99bd4ef 2620
c19d1205
ZW
2621 /* The input scrubber ensures that whitespace after the mnemonic is
2622 collapsed to single spaces. */
2623 oldname = p;
2624 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2625 return FALSE;
b99bd4ef 2626
c19d1205
ZW
2627 oldname += 6;
2628 if (*oldname == '\0')
d929913e 2629 return FALSE;
b99bd4ef 2630
21d799b5 2631 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2632 if (!old)
b99bd4ef 2633 {
c19d1205 2634 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2635 return TRUE;
b99bd4ef
NC
2636 }
2637
c19d1205
ZW
2638 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2639 the desired alias name, and p points to its end. If not, then
2640 the desired alias name is in the global original_case_string. */
2641#ifdef TC_CASE_SENSITIVE
2642 nlen = p - newname;
2643#else
2644 newname = original_case_string;
2645 nlen = strlen (newname);
2646#endif
b99bd4ef 2647
29a2809e 2648 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2649
c19d1205
ZW
2650 /* Create aliases under the new name as stated; an all-lowercase
2651 version of the new name; and an all-uppercase version of the new
2652 name. */
d929913e
NC
2653 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2654 {
2655 for (p = nbuf; *p; p++)
2656 *p = TOUPPER (*p);
c19d1205 2657
d929913e
NC
2658 if (strncmp (nbuf, newname, nlen))
2659 {
2660 /* If this attempt to create an additional alias fails, do not bother
2661 trying to create the all-lower case alias. We will fail and issue
2662 a second, duplicate error message. This situation arises when the
2663 programmer does something like:
2664 foo .req r0
2665 Foo .req r1
2666 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2667 the artificial FOO alias because it has already been created by the
d929913e
NC
2668 first .req. */
2669 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2670 {
2671 free (nbuf);
2672 return TRUE;
2673 }
d929913e 2674 }
c19d1205 2675
d929913e
NC
2676 for (p = nbuf; *p; p++)
2677 *p = TOLOWER (*p);
c19d1205 2678
d929913e
NC
2679 if (strncmp (nbuf, newname, nlen))
2680 insert_reg_alias (nbuf, old->number, old->type);
2681 }
c19d1205 2682
e1fa0163 2683 free (nbuf);
d929913e 2684 return TRUE;
b99bd4ef
NC
2685}
2686
dcbf9037
JB
2687/* Create a Neon typed/indexed register alias using directives, e.g.:
2688 X .dn d5.s32[1]
2689 Y .qn 6.s16
2690 Z .dn d7
2691 T .dn Z[0]
2692 These typed registers can be used instead of the types specified after the
2693 Neon mnemonic, so long as all operands given have types. Types can also be
2694 specified directly, e.g.:
5f4273c7 2695 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2696
c921be7d 2697static bfd_boolean
dcbf9037
JB
2698create_neon_reg_alias (char *newname, char *p)
2699{
2700 enum arm_reg_type basetype;
2701 struct reg_entry *basereg;
2702 struct reg_entry mybasereg;
2703 struct neon_type ntype;
2704 struct neon_typed_alias typeinfo;
12d6b0b7 2705 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2706 int namelen;
5f4273c7 2707
dcbf9037
JB
2708 typeinfo.defined = 0;
2709 typeinfo.eltype.type = NT_invtype;
2710 typeinfo.eltype.size = -1;
2711 typeinfo.index = -1;
5f4273c7 2712
dcbf9037 2713 nameend = p;
5f4273c7 2714
dcbf9037
JB
2715 if (strncmp (p, " .dn ", 5) == 0)
2716 basetype = REG_TYPE_VFD;
2717 else if (strncmp (p, " .qn ", 5) == 0)
2718 basetype = REG_TYPE_NQ;
2719 else
c921be7d 2720 return FALSE;
5f4273c7 2721
dcbf9037 2722 p += 5;
5f4273c7 2723
dcbf9037 2724 if (*p == '\0')
c921be7d 2725 return FALSE;
5f4273c7 2726
dcbf9037
JB
2727 basereg = arm_reg_parse_multi (&p);
2728
2729 if (basereg && basereg->type != basetype)
2730 {
2731 as_bad (_("bad type for register"));
c921be7d 2732 return FALSE;
dcbf9037
JB
2733 }
2734
2735 if (basereg == NULL)
2736 {
2737 expressionS exp;
2738 /* Try parsing as an integer. */
2739 my_get_expression (&exp, &p, GE_NO_PREFIX);
2740 if (exp.X_op != O_constant)
477330fc
RM
2741 {
2742 as_bad (_("expression must be constant"));
2743 return FALSE;
2744 }
dcbf9037
JB
2745 basereg = &mybasereg;
2746 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2747 : exp.X_add_number;
dcbf9037
JB
2748 basereg->neon = 0;
2749 }
2750
2751 if (basereg->neon)
2752 typeinfo = *basereg->neon;
2753
2754 if (parse_neon_type (&ntype, &p) == SUCCESS)
2755 {
2756 /* We got a type. */
2757 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2758 {
2759 as_bad (_("can't redefine the type of a register alias"));
2760 return FALSE;
2761 }
5f4273c7 2762
dcbf9037
JB
2763 typeinfo.defined |= NTA_HASTYPE;
2764 if (ntype.elems != 1)
477330fc
RM
2765 {
2766 as_bad (_("you must specify a single type only"));
2767 return FALSE;
2768 }
dcbf9037
JB
2769 typeinfo.eltype = ntype.el[0];
2770 }
5f4273c7 2771
dcbf9037
JB
2772 if (skip_past_char (&p, '[') == SUCCESS)
2773 {
2774 expressionS exp;
2775 /* We got a scalar index. */
5f4273c7 2776
dcbf9037 2777 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2778 {
2779 as_bad (_("can't redefine the index of a scalar alias"));
2780 return FALSE;
2781 }
5f4273c7 2782
dcbf9037 2783 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2784
dcbf9037 2785 if (exp.X_op != O_constant)
477330fc
RM
2786 {
2787 as_bad (_("scalar index must be constant"));
2788 return FALSE;
2789 }
5f4273c7 2790
dcbf9037
JB
2791 typeinfo.defined |= NTA_HASINDEX;
2792 typeinfo.index = exp.X_add_number;
5f4273c7 2793
dcbf9037 2794 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2795 {
2796 as_bad (_("expecting ]"));
2797 return FALSE;
2798 }
dcbf9037
JB
2799 }
2800
15735687
NS
2801 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2802 the desired alias name, and p points to its end. If not, then
2803 the desired alias name is in the global original_case_string. */
2804#ifdef TC_CASE_SENSITIVE
dcbf9037 2805 namelen = nameend - newname;
15735687
NS
2806#else
2807 newname = original_case_string;
2808 namelen = strlen (newname);
2809#endif
2810
29a2809e 2811 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2812
dcbf9037 2813 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2814 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2815
dcbf9037
JB
2816 /* Insert name in all uppercase. */
2817 for (p = namebuf; *p; p++)
2818 *p = TOUPPER (*p);
5f4273c7 2819
dcbf9037
JB
2820 if (strncmp (namebuf, newname, namelen))
2821 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2822 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2823
dcbf9037
JB
2824 /* Insert name in all lowercase. */
2825 for (p = namebuf; *p; p++)
2826 *p = TOLOWER (*p);
5f4273c7 2827
dcbf9037
JB
2828 if (strncmp (namebuf, newname, namelen))
2829 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2830 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2831
e1fa0163 2832 free (namebuf);
c921be7d 2833 return TRUE;
dcbf9037
JB
2834}
2835
c19d1205
ZW
2836/* Should never be called, as .req goes between the alias and the
2837 register name, not at the beginning of the line. */
c921be7d 2838
b99bd4ef 2839static void
c19d1205 2840s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2841{
c19d1205
ZW
2842 as_bad (_("invalid syntax for .req directive"));
2843}
b99bd4ef 2844
dcbf9037
JB
2845static void
2846s_dn (int a ATTRIBUTE_UNUSED)
2847{
2848 as_bad (_("invalid syntax for .dn directive"));
2849}
2850
2851static void
2852s_qn (int a ATTRIBUTE_UNUSED)
2853{
2854 as_bad (_("invalid syntax for .qn directive"));
2855}
2856
c19d1205
ZW
2857/* The .unreq directive deletes an alias which was previously defined
2858 by .req. For example:
b99bd4ef 2859
c19d1205
ZW
2860 my_alias .req r11
2861 .unreq my_alias */
b99bd4ef
NC
2862
2863static void
c19d1205 2864s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2865{
c19d1205
ZW
2866 char * name;
2867 char saved_char;
b99bd4ef 2868
c19d1205
ZW
2869 name = input_line_pointer;
2870
2871 while (*input_line_pointer != 0
2872 && *input_line_pointer != ' '
2873 && *input_line_pointer != '\n')
2874 ++input_line_pointer;
2875
2876 saved_char = *input_line_pointer;
2877 *input_line_pointer = 0;
2878
2879 if (!*name)
2880 as_bad (_("invalid syntax for .unreq directive"));
2881 else
2882 {
21d799b5 2883 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2884 name);
c19d1205
ZW
2885
2886 if (!reg)
2887 as_bad (_("unknown register alias '%s'"), name);
2888 else if (reg->builtin)
a1727c1a 2889 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2890 name);
2891 else
2892 {
d929913e
NC
2893 char * p;
2894 char * nbuf;
2895
db0bc284 2896 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2897 free ((char *) reg->name);
477330fc
RM
2898 if (reg->neon)
2899 free (reg->neon);
c19d1205 2900 free (reg);
d929913e
NC
2901
2902 /* Also locate the all upper case and all lower case versions.
2903 Do not complain if we cannot find one or the other as it
2904 was probably deleted above. */
5f4273c7 2905
d929913e
NC
2906 nbuf = strdup (name);
2907 for (p = nbuf; *p; p++)
2908 *p = TOUPPER (*p);
21d799b5 2909 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2910 if (reg)
2911 {
db0bc284 2912 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2913 free ((char *) reg->name);
2914 if (reg->neon)
2915 free (reg->neon);
2916 free (reg);
2917 }
2918
2919 for (p = nbuf; *p; p++)
2920 *p = TOLOWER (*p);
21d799b5 2921 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2922 if (reg)
2923 {
db0bc284 2924 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2925 free ((char *) reg->name);
2926 if (reg->neon)
2927 free (reg->neon);
2928 free (reg);
2929 }
2930
2931 free (nbuf);
c19d1205
ZW
2932 }
2933 }
b99bd4ef 2934
c19d1205 2935 *input_line_pointer = saved_char;
b99bd4ef
NC
2936 demand_empty_rest_of_line ();
2937}
2938
c19d1205
ZW
2939/* Directives: Instruction set selection. */
2940
2941#ifdef OBJ_ELF
2942/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2943 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2944 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2945 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2946
cd000bff
DJ
2947/* Create a new mapping symbol for the transition to STATE. */
2948
2949static void
2950make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2951{
a737bd4d 2952 symbolS * symbolP;
c19d1205
ZW
2953 const char * symname;
2954 int type;
b99bd4ef 2955
c19d1205 2956 switch (state)
b99bd4ef 2957 {
c19d1205
ZW
2958 case MAP_DATA:
2959 symname = "$d";
2960 type = BSF_NO_FLAGS;
2961 break;
2962 case MAP_ARM:
2963 symname = "$a";
2964 type = BSF_NO_FLAGS;
2965 break;
2966 case MAP_THUMB:
2967 symname = "$t";
2968 type = BSF_NO_FLAGS;
2969 break;
c19d1205
ZW
2970 default:
2971 abort ();
2972 }
2973
cd000bff 2974 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2975 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2976
2977 switch (state)
2978 {
2979 case MAP_ARM:
2980 THUMB_SET_FUNC (symbolP, 0);
2981 ARM_SET_THUMB (symbolP, 0);
2982 ARM_SET_INTERWORK (symbolP, support_interwork);
2983 break;
2984
2985 case MAP_THUMB:
2986 THUMB_SET_FUNC (symbolP, 1);
2987 ARM_SET_THUMB (symbolP, 1);
2988 ARM_SET_INTERWORK (symbolP, support_interwork);
2989 break;
2990
2991 case MAP_DATA:
2992 default:
cd000bff
DJ
2993 break;
2994 }
2995
2996 /* Save the mapping symbols for future reference. Also check that
2997 we do not place two mapping symbols at the same offset within a
2998 frag. We'll handle overlap between frags in
2de7820f
JZ
2999 check_mapping_symbols.
3000
3001 If .fill or other data filling directive generates zero sized data,
3002 the mapping symbol for the following code will have the same value
3003 as the one generated for the data filling directive. In this case,
3004 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
3005 if (value == 0)
3006 {
2de7820f
JZ
3007 if (frag->tc_frag_data.first_map != NULL)
3008 {
3009 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3010 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3011 }
cd000bff
DJ
3012 frag->tc_frag_data.first_map = symbolP;
3013 }
3014 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
3015 {
3016 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
3017 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3018 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3019 }
cd000bff
DJ
3020 frag->tc_frag_data.last_map = symbolP;
3021}
3022
3023/* We must sometimes convert a region marked as code to data during
3024 code alignment, if an odd number of bytes have to be padded. The
3025 code mapping symbol is pushed to an aligned address. */
3026
3027static void
3028insert_data_mapping_symbol (enum mstate state,
3029 valueT value, fragS *frag, offsetT bytes)
3030{
3031 /* If there was already a mapping symbol, remove it. */
3032 if (frag->tc_frag_data.last_map != NULL
3033 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3034 {
3035 symbolS *symp = frag->tc_frag_data.last_map;
3036
3037 if (value == 0)
3038 {
3039 know (frag->tc_frag_data.first_map == symp);
3040 frag->tc_frag_data.first_map = NULL;
3041 }
3042 frag->tc_frag_data.last_map = NULL;
3043 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 3044 }
cd000bff
DJ
3045
3046 make_mapping_symbol (MAP_DATA, value, frag);
3047 make_mapping_symbol (state, value + bytes, frag);
3048}
3049
3050static void mapping_state_2 (enum mstate state, int max_chars);
3051
3052/* Set the mapping state to STATE. Only call this when about to
3053 emit some STATE bytes to the file. */
3054
4e9aaefb 3055#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
3056void
3057mapping_state (enum mstate state)
3058{
940b5ce0
DJ
3059 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3060
cd000bff
DJ
3061 if (mapstate == state)
3062 /* The mapping symbol has already been emitted.
3063 There is nothing else to do. */
3064 return;
49c62a33
NC
3065
3066 if (state == MAP_ARM || state == MAP_THUMB)
3067 /* PR gas/12931
3068 All ARM instructions require 4-byte alignment.
3069 (Almost) all Thumb instructions require 2-byte alignment.
3070
3071 When emitting instructions into any section, mark the section
3072 appropriately.
3073
3074 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3075 but themselves require 2-byte alignment; this applies to some
33eaf5de 3076 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
3077 literal pool generation or an explicit .align >=2, both of
3078 which will cause the section to me marked with sufficient
3079 alignment. Thus, we don't handle those cases here. */
3080 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3081
3082 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 3083 /* This case will be evaluated later. */
cd000bff 3084 return;
cd000bff
DJ
3085
3086 mapping_state_2 (state, 0);
cd000bff
DJ
3087}
3088
3089/* Same as mapping_state, but MAX_CHARS bytes have already been
3090 allocated. Put the mapping symbol that far back. */
3091
3092static void
3093mapping_state_2 (enum mstate state, int max_chars)
3094{
940b5ce0
DJ
3095 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3096
3097 if (!SEG_NORMAL (now_seg))
3098 return;
3099
cd000bff
DJ
3100 if (mapstate == state)
3101 /* The mapping symbol has already been emitted.
3102 There is nothing else to do. */
3103 return;
3104
4e9aaefb
SA
3105 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3106 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3107 {
3108 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3109 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3110
3111 if (add_symbol)
3112 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3113 }
3114
cd000bff
DJ
3115 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3116 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3117}
4e9aaefb 3118#undef TRANSITION
c19d1205 3119#else
d3106081
NS
3120#define mapping_state(x) ((void)0)
3121#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3122#endif
3123
3124/* Find the real, Thumb encoded start of a Thumb function. */
3125
4343666d 3126#ifdef OBJ_COFF
c19d1205
ZW
3127static symbolS *
3128find_real_start (symbolS * symbolP)
3129{
3130 char * real_start;
3131 const char * name = S_GET_NAME (symbolP);
3132 symbolS * new_target;
3133
3134 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3135#define STUB_NAME ".real_start_of"
3136
3137 if (name == NULL)
3138 abort ();
3139
37f6032b
ZW
3140 /* The compiler may generate BL instructions to local labels because
3141 it needs to perform a branch to a far away location. These labels
3142 do not have a corresponding ".real_start_of" label. We check
3143 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3144 the ".real_start_of" convention for nonlocal branches. */
3145 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3146 return symbolP;
3147
e1fa0163 3148 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3149 new_target = symbol_find (real_start);
e1fa0163 3150 free (real_start);
c19d1205
ZW
3151
3152 if (new_target == NULL)
3153 {
bd3ba5d1 3154 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3155 new_target = symbolP;
3156 }
3157
c19d1205
ZW
3158 return new_target;
3159}
4343666d 3160#endif
c19d1205
ZW
3161
3162static void
3163opcode_select (int width)
3164{
3165 switch (width)
3166 {
3167 case 16:
3168 if (! thumb_mode)
3169 {
e74cfd16 3170 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3171 as_bad (_("selected processor does not support THUMB opcodes"));
3172
3173 thumb_mode = 1;
3174 /* No need to force the alignment, since we will have been
3175 coming from ARM mode, which is word-aligned. */
3176 record_alignment (now_seg, 1);
3177 }
c19d1205
ZW
3178 break;
3179
3180 case 32:
3181 if (thumb_mode)
3182 {
e74cfd16 3183 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3184 as_bad (_("selected processor does not support ARM opcodes"));
3185
3186 thumb_mode = 0;
3187
3188 if (!need_pass_2)
3189 frag_align (2, 0, 0);
3190
3191 record_alignment (now_seg, 1);
3192 }
c19d1205
ZW
3193 break;
3194
3195 default:
3196 as_bad (_("invalid instruction size selected (%d)"), width);
3197 }
3198}
3199
3200static void
3201s_arm (int ignore ATTRIBUTE_UNUSED)
3202{
3203 opcode_select (32);
3204 demand_empty_rest_of_line ();
3205}
3206
3207static void
3208s_thumb (int ignore ATTRIBUTE_UNUSED)
3209{
3210 opcode_select (16);
3211 demand_empty_rest_of_line ();
3212}
3213
3214static void
3215s_code (int unused ATTRIBUTE_UNUSED)
3216{
3217 int temp;
3218
3219 temp = get_absolute_expression ();
3220 switch (temp)
3221 {
3222 case 16:
3223 case 32:
3224 opcode_select (temp);
3225 break;
3226
3227 default:
3228 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3229 }
3230}
3231
3232static void
3233s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3234{
3235 /* If we are not already in thumb mode go into it, EVEN if
3236 the target processor does not support thumb instructions.
3237 This is used by gcc/config/arm/lib1funcs.asm for example
3238 to compile interworking support functions even if the
3239 target processor should not support interworking. */
3240 if (! thumb_mode)
3241 {
3242 thumb_mode = 2;
3243 record_alignment (now_seg, 1);
3244 }
3245
3246 demand_empty_rest_of_line ();
3247}
3248
3249static void
3250s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3251{
3252 s_thumb (0);
3253
3254 /* The following label is the name/address of the start of a Thumb function.
3255 We need to know this for the interworking support. */
3256 label_is_thumb_function_name = TRUE;
3257}
3258
3259/* Perform a .set directive, but also mark the alias as
3260 being a thumb function. */
3261
3262static void
3263s_thumb_set (int equiv)
3264{
3265 /* XXX the following is a duplicate of the code for s_set() in read.c
3266 We cannot just call that code as we need to get at the symbol that
3267 is created. */
3268 char * name;
3269 char delim;
3270 char * end_name;
3271 symbolS * symbolP;
3272
3273 /* Especial apologies for the random logic:
3274 This just grew, and could be parsed much more simply!
3275 Dean - in haste. */
d02603dc 3276 delim = get_symbol_name (& name);
c19d1205 3277 end_name = input_line_pointer;
d02603dc 3278 (void) restore_line_pointer (delim);
c19d1205
ZW
3279
3280 if (*input_line_pointer != ',')
3281 {
3282 *end_name = 0;
3283 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3284 *end_name = delim;
3285 ignore_rest_of_line ();
3286 return;
3287 }
3288
3289 input_line_pointer++;
3290 *end_name = 0;
3291
3292 if (name[0] == '.' && name[1] == '\0')
3293 {
3294 /* XXX - this should not happen to .thumb_set. */
3295 abort ();
3296 }
3297
3298 if ((symbolP = symbol_find (name)) == NULL
3299 && (symbolP = md_undefined_symbol (name)) == NULL)
3300 {
3301#ifndef NO_LISTING
3302 /* When doing symbol listings, play games with dummy fragments living
3303 outside the normal fragment chain to record the file and line info
c19d1205 3304 for this symbol. */
b99bd4ef
NC
3305 if (listing & LISTING_SYMBOLS)
3306 {
3307 extern struct list_info_struct * listing_tail;
21d799b5 3308 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3309
3310 memset (dummy_frag, 0, sizeof (fragS));
3311 dummy_frag->fr_type = rs_fill;
3312 dummy_frag->line = listing_tail;
3313 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3314 dummy_frag->fr_symbol = symbolP;
3315 }
3316 else
3317#endif
3318 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3319
3320#ifdef OBJ_COFF
3321 /* "set" symbols are local unless otherwise specified. */
3322 SF_SET_LOCAL (symbolP);
3323#endif /* OBJ_COFF */
3324 } /* Make a new symbol. */
3325
3326 symbol_table_insert (symbolP);
3327
3328 * end_name = delim;
3329
3330 if (equiv
3331 && S_IS_DEFINED (symbolP)
3332 && S_GET_SEGMENT (symbolP) != reg_section)
3333 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3334
3335 pseudo_set (symbolP);
3336
3337 demand_empty_rest_of_line ();
3338
c19d1205 3339 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3340
3341 THUMB_SET_FUNC (symbolP, 1);
3342 ARM_SET_THUMB (symbolP, 1);
3343#if defined OBJ_ELF || defined OBJ_COFF
3344 ARM_SET_INTERWORK (symbolP, support_interwork);
3345#endif
3346}
3347
c19d1205 3348/* Directives: Mode selection. */
b99bd4ef 3349
c19d1205
ZW
3350/* .syntax [unified|divided] - choose the new unified syntax
3351 (same for Arm and Thumb encoding, modulo slight differences in what
3352 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3353static void
c19d1205 3354s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3355{
c19d1205
ZW
3356 char *name, delim;
3357
d02603dc 3358 delim = get_symbol_name (& name);
c19d1205
ZW
3359
3360 if (!strcasecmp (name, "unified"))
3361 unified_syntax = TRUE;
3362 else if (!strcasecmp (name, "divided"))
3363 unified_syntax = FALSE;
3364 else
3365 {
3366 as_bad (_("unrecognized syntax mode \"%s\""), name);
3367 return;
3368 }
d02603dc 3369 (void) restore_line_pointer (delim);
b99bd4ef
NC
3370 demand_empty_rest_of_line ();
3371}
3372
c19d1205
ZW
3373/* Directives: sectioning and alignment. */
3374
c19d1205
ZW
3375static void
3376s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3377{
c19d1205
ZW
3378 /* We don't support putting frags in the BSS segment, we fake it by
3379 marking in_bss, then looking at s_skip for clues. */
3380 subseg_set (bss_section, 0);
3381 demand_empty_rest_of_line ();
cd000bff
DJ
3382
3383#ifdef md_elf_section_change_hook
3384 md_elf_section_change_hook ();
3385#endif
c19d1205 3386}
b99bd4ef 3387
c19d1205
ZW
3388static void
3389s_even (int ignore ATTRIBUTE_UNUSED)
3390{
3391 /* Never make frag if expect extra pass. */
3392 if (!need_pass_2)
3393 frag_align (1, 0, 0);
b99bd4ef 3394
c19d1205 3395 record_alignment (now_seg, 1);
b99bd4ef 3396
c19d1205 3397 demand_empty_rest_of_line ();
b99bd4ef
NC
3398}
3399
2e6976a8
DG
3400/* Directives: CodeComposer Studio. */
3401
3402/* .ref (for CodeComposer Studio syntax only). */
3403static void
3404s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3405{
3406 if (codecomposer_syntax)
3407 ignore_rest_of_line ();
3408 else
3409 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3410}
3411
3412/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3413 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3414static void
3415asmfunc_debug (const char * name)
3416{
3417 static const char * last_name = NULL;
3418
3419 if (name != NULL)
3420 {
3421 gas_assert (last_name == NULL);
3422 last_name = name;
3423
3424 if (debug_type == DEBUG_STABS)
3425 stabs_generate_asm_func (name, name);
3426 }
3427 else
3428 {
3429 gas_assert (last_name != NULL);
3430
3431 if (debug_type == DEBUG_STABS)
3432 stabs_generate_asm_endfunc (last_name, last_name);
3433
3434 last_name = NULL;
3435 }
3436}
3437
3438static void
3439s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3440{
3441 if (codecomposer_syntax)
3442 {
3443 switch (asmfunc_state)
3444 {
3445 case OUTSIDE_ASMFUNC:
3446 asmfunc_state = WAITING_ASMFUNC_NAME;
3447 break;
3448
3449 case WAITING_ASMFUNC_NAME:
3450 as_bad (_(".asmfunc repeated."));
3451 break;
3452
3453 case WAITING_ENDASMFUNC:
3454 as_bad (_(".asmfunc without function."));
3455 break;
3456 }
3457 demand_empty_rest_of_line ();
3458 }
3459 else
3460 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3461}
3462
3463static void
3464s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3465{
3466 if (codecomposer_syntax)
3467 {
3468 switch (asmfunc_state)
3469 {
3470 case OUTSIDE_ASMFUNC:
3471 as_bad (_(".endasmfunc without a .asmfunc."));
3472 break;
3473
3474 case WAITING_ASMFUNC_NAME:
3475 as_bad (_(".endasmfunc without function."));
3476 break;
3477
3478 case WAITING_ENDASMFUNC:
3479 asmfunc_state = OUTSIDE_ASMFUNC;
3480 asmfunc_debug (NULL);
3481 break;
3482 }
3483 demand_empty_rest_of_line ();
3484 }
3485 else
3486 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3487}
3488
3489static void
3490s_ccs_def (int name)
3491{
3492 if (codecomposer_syntax)
3493 s_globl (name);
3494 else
3495 as_bad (_(".def pseudo-op only available with -mccs flag."));
3496}
3497
c19d1205 3498/* Directives: Literal pools. */
a737bd4d 3499
c19d1205
ZW
3500static literal_pool *
3501find_literal_pool (void)
a737bd4d 3502{
c19d1205 3503 literal_pool * pool;
a737bd4d 3504
c19d1205 3505 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3506 {
c19d1205
ZW
3507 if (pool->section == now_seg
3508 && pool->sub_section == now_subseg)
3509 break;
a737bd4d
NC
3510 }
3511
c19d1205 3512 return pool;
a737bd4d
NC
3513}
3514
c19d1205
ZW
3515static literal_pool *
3516find_or_make_literal_pool (void)
a737bd4d 3517{
c19d1205
ZW
3518 /* Next literal pool ID number. */
3519 static unsigned int latest_pool_num = 1;
3520 literal_pool * pool;
a737bd4d 3521
c19d1205 3522 pool = find_literal_pool ();
a737bd4d 3523
c19d1205 3524 if (pool == NULL)
a737bd4d 3525 {
c19d1205 3526 /* Create a new pool. */
325801bd 3527 pool = XNEW (literal_pool);
c19d1205
ZW
3528 if (! pool)
3529 return NULL;
a737bd4d 3530
c19d1205
ZW
3531 pool->next_free_entry = 0;
3532 pool->section = now_seg;
3533 pool->sub_section = now_subseg;
3534 pool->next = list_of_pools;
3535 pool->symbol = NULL;
8335d6aa 3536 pool->alignment = 2;
c19d1205
ZW
3537
3538 /* Add it to the list. */
3539 list_of_pools = pool;
a737bd4d 3540 }
a737bd4d 3541
c19d1205
ZW
3542 /* New pools, and emptied pools, will have a NULL symbol. */
3543 if (pool->symbol == NULL)
a737bd4d 3544 {
c19d1205
ZW
3545 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3546 (valueT) 0, &zero_address_frag);
3547 pool->id = latest_pool_num ++;
a737bd4d
NC
3548 }
3549
c19d1205
ZW
3550 /* Done. */
3551 return pool;
a737bd4d
NC
3552}
3553
c19d1205 3554/* Add the literal in the global 'inst'
5f4273c7 3555 structure to the relevant literal pool. */
b99bd4ef
NC
3556
3557static int
8335d6aa 3558add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3559{
8335d6aa
JW
3560#define PADDING_SLOT 0x1
3561#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3562 literal_pool * pool;
8335d6aa
JW
3563 unsigned int entry, pool_size = 0;
3564 bfd_boolean padding_slot_p = FALSE;
e56c722b 3565 unsigned imm1 = 0;
8335d6aa
JW
3566 unsigned imm2 = 0;
3567
3568 if (nbytes == 8)
3569 {
3570 imm1 = inst.operands[1].imm;
3571 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3572 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3573 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3574 if (target_big_endian)
3575 {
3576 imm1 = imm2;
3577 imm2 = inst.operands[1].imm;
3578 }
3579 }
b99bd4ef 3580
c19d1205
ZW
3581 pool = find_or_make_literal_pool ();
3582
3583 /* Check if this literal value is already in the pool. */
3584 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3585 {
8335d6aa
JW
3586 if (nbytes == 4)
3587 {
e2b0ab59
AV
3588 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3589 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3590 && (pool->literals[entry].X_add_number
e2b0ab59 3591 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3592 && (pool->literals[entry].X_md == nbytes)
3593 && (pool->literals[entry].X_unsigned
e2b0ab59 3594 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3595 break;
3596
e2b0ab59
AV
3597 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3598 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3599 && (pool->literals[entry].X_add_number
e2b0ab59 3600 == inst.relocs[0].exp.X_add_number)
8335d6aa 3601 && (pool->literals[entry].X_add_symbol
e2b0ab59 3602 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3603 && (pool->literals[entry].X_op_symbol
e2b0ab59 3604 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3605 && (pool->literals[entry].X_md == nbytes))
3606 break;
3607 }
3608 else if ((nbytes == 8)
3609 && !(pool_size & 0x7)
3610 && ((entry + 1) != pool->next_free_entry)
3611 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3612 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3613 && (pool->literals[entry].X_unsigned
e2b0ab59 3614 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3615 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3616 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3617 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3618 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3619 break;
3620
8335d6aa
JW
3621 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3622 if (padding_slot_p && (nbytes == 4))
c19d1205 3623 break;
8335d6aa
JW
3624
3625 pool_size += 4;
b99bd4ef
NC
3626 }
3627
c19d1205
ZW
3628 /* Do we need to create a new entry? */
3629 if (entry == pool->next_free_entry)
3630 {
3631 if (entry >= MAX_LITERAL_POOL_SIZE)
3632 {
3633 inst.error = _("literal pool overflow");
3634 return FAIL;
3635 }
3636
8335d6aa
JW
3637 if (nbytes == 8)
3638 {
3639 /* For 8-byte entries, we align to an 8-byte boundary,
3640 and split it into two 4-byte entries, because on 32-bit
3641 host, 8-byte constants are treated as big num, thus
3642 saved in "generic_bignum" which will be overwritten
3643 by later assignments.
3644
3645 We also need to make sure there is enough space for
3646 the split.
3647
3648 We also check to make sure the literal operand is a
3649 constant number. */
e2b0ab59
AV
3650 if (!(inst.relocs[0].exp.X_op == O_constant
3651 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3652 {
3653 inst.error = _("invalid type for literal pool");
3654 return FAIL;
3655 }
3656 else if (pool_size & 0x7)
3657 {
3658 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3659 {
3660 inst.error = _("literal pool overflow");
3661 return FAIL;
3662 }
3663
e2b0ab59 3664 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3665 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3666 pool->literals[entry].X_add_number = 0;
3667 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3668 pool->next_free_entry += 1;
3669 pool_size += 4;
3670 }
3671 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3672 {
3673 inst.error = _("literal pool overflow");
3674 return FAIL;
3675 }
3676
e2b0ab59 3677 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3678 pool->literals[entry].X_op = O_constant;
3679 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3680 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3681 pool->literals[entry++].X_md = 4;
e2b0ab59 3682 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3683 pool->literals[entry].X_op = O_constant;
3684 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3685 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3686 pool->literals[entry].X_md = 4;
3687 pool->alignment = 3;
3688 pool->next_free_entry += 1;
3689 }
3690 else
3691 {
e2b0ab59 3692 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3693 pool->literals[entry].X_md = 4;
3694 }
3695
a8040cf2
NC
3696#ifdef OBJ_ELF
3697 /* PR ld/12974: Record the location of the first source line to reference
3698 this entry in the literal pool. If it turns out during linking that the
3699 symbol does not exist we will be able to give an accurate line number for
3700 the (first use of the) missing reference. */
3701 if (debug_type == DEBUG_DWARF2)
3702 dwarf2_where (pool->locs + entry);
3703#endif
c19d1205
ZW
3704 pool->next_free_entry += 1;
3705 }
8335d6aa
JW
3706 else if (padding_slot_p)
3707 {
e2b0ab59 3708 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3709 pool->literals[entry].X_md = nbytes;
3710 }
b99bd4ef 3711
e2b0ab59
AV
3712 inst.relocs[0].exp.X_op = O_symbol;
3713 inst.relocs[0].exp.X_add_number = pool_size;
3714 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3715
c19d1205 3716 return SUCCESS;
b99bd4ef
NC
3717}
3718
2e6976a8 3719bfd_boolean
2e57ce7b 3720tc_start_label_without_colon (void)
2e6976a8
DG
3721{
3722 bfd_boolean ret = TRUE;
3723
3724 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3725 {
2e57ce7b 3726 const char *label = input_line_pointer;
2e6976a8
DG
3727
3728 while (!is_end_of_line[(int) label[-1]])
3729 --label;
3730
3731 if (*label == '.')
3732 {
3733 as_bad (_("Invalid label '%s'"), label);
3734 ret = FALSE;
3735 }
3736
3737 asmfunc_debug (label);
3738
3739 asmfunc_state = WAITING_ENDASMFUNC;
3740 }
3741
3742 return ret;
3743}
3744
c19d1205 3745/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3746 a later date assign it a value. That's what these functions do. */
e16bb312 3747
c19d1205
ZW
3748static void
3749symbol_locate (symbolS * symbolP,
3750 const char * name, /* It is copied, the caller can modify. */
3751 segT segment, /* Segment identifier (SEG_<something>). */
3752 valueT valu, /* Symbol value. */
3753 fragS * frag) /* Associated fragment. */
3754{
e57e6ddc 3755 size_t name_length;
c19d1205 3756 char * preserved_copy_of_name;
e16bb312 3757
c19d1205
ZW
3758 name_length = strlen (name) + 1; /* +1 for \0. */
3759 obstack_grow (&notes, name, name_length);
21d799b5 3760 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3761
c19d1205
ZW
3762#ifdef tc_canonicalize_symbol_name
3763 preserved_copy_of_name =
3764 tc_canonicalize_symbol_name (preserved_copy_of_name);
3765#endif
b99bd4ef 3766
c19d1205 3767 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3768
c19d1205
ZW
3769 S_SET_SEGMENT (symbolP, segment);
3770 S_SET_VALUE (symbolP, valu);
3771 symbol_clear_list_pointers (symbolP);
b99bd4ef 3772
c19d1205 3773 symbol_set_frag (symbolP, frag);
b99bd4ef 3774
c19d1205
ZW
3775 /* Link to end of symbol chain. */
3776 {
3777 extern int symbol_table_frozen;
b99bd4ef 3778
c19d1205
ZW
3779 if (symbol_table_frozen)
3780 abort ();
3781 }
b99bd4ef 3782
c19d1205 3783 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3784
c19d1205 3785 obj_symbol_new_hook (symbolP);
b99bd4ef 3786
c19d1205
ZW
3787#ifdef tc_symbol_new_hook
3788 tc_symbol_new_hook (symbolP);
3789#endif
3790
3791#ifdef DEBUG_SYMS
3792 verify_symbol_chain (symbol_rootP, symbol_lastP);
3793#endif /* DEBUG_SYMS */
b99bd4ef
NC
3794}
3795
c19d1205
ZW
3796static void
3797s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3798{
c19d1205
ZW
3799 unsigned int entry;
3800 literal_pool * pool;
3801 char sym_name[20];
b99bd4ef 3802
c19d1205
ZW
3803 pool = find_literal_pool ();
3804 if (pool == NULL
3805 || pool->symbol == NULL
3806 || pool->next_free_entry == 0)
3807 return;
b99bd4ef 3808
c19d1205
ZW
3809 /* Align pool as you have word accesses.
3810 Only make a frag if we have to. */
3811 if (!need_pass_2)
8335d6aa 3812 frag_align (pool->alignment, 0, 0);
b99bd4ef 3813
c19d1205 3814 record_alignment (now_seg, 2);
b99bd4ef 3815
aaca88ef 3816#ifdef OBJ_ELF
47fc6e36
WN
3817 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3818 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3819#endif
c19d1205 3820 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3821
c19d1205
ZW
3822 symbol_locate (pool->symbol, sym_name, now_seg,
3823 (valueT) frag_now_fix (), frag_now);
3824 symbol_table_insert (pool->symbol);
b99bd4ef 3825
c19d1205 3826 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3827
c19d1205
ZW
3828#if defined OBJ_COFF || defined OBJ_ELF
3829 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3830#endif
6c43fab6 3831
c19d1205 3832 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3833 {
3834#ifdef OBJ_ELF
3835 if (debug_type == DEBUG_DWARF2)
3836 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3837#endif
3838 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3839 emit_expr (&(pool->literals[entry]),
3840 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3841 }
b99bd4ef 3842
c19d1205
ZW
3843 /* Mark the pool as empty. */
3844 pool->next_free_entry = 0;
3845 pool->symbol = NULL;
b99bd4ef
NC
3846}
3847
c19d1205
ZW
3848#ifdef OBJ_ELF
3849/* Forward declarations for functions below, in the MD interface
3850 section. */
3851static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3852static valueT create_unwind_entry (int);
3853static void start_unwind_section (const segT, int);
3854static void add_unwind_opcode (valueT, int);
3855static void flush_pending_unwind (void);
b99bd4ef 3856
c19d1205 3857/* Directives: Data. */
b99bd4ef 3858
c19d1205
ZW
3859static void
3860s_arm_elf_cons (int nbytes)
3861{
3862 expressionS exp;
b99bd4ef 3863
c19d1205
ZW
3864#ifdef md_flush_pending_output
3865 md_flush_pending_output ();
3866#endif
b99bd4ef 3867
c19d1205 3868 if (is_it_end_of_statement ())
b99bd4ef 3869 {
c19d1205
ZW
3870 demand_empty_rest_of_line ();
3871 return;
b99bd4ef
NC
3872 }
3873
c19d1205
ZW
3874#ifdef md_cons_align
3875 md_cons_align (nbytes);
3876#endif
b99bd4ef 3877
c19d1205
ZW
3878 mapping_state (MAP_DATA);
3879 do
b99bd4ef 3880 {
c19d1205
ZW
3881 int reloc;
3882 char *base = input_line_pointer;
b99bd4ef 3883
c19d1205 3884 expression (& exp);
b99bd4ef 3885
c19d1205
ZW
3886 if (exp.X_op != O_symbol)
3887 emit_expr (&exp, (unsigned int) nbytes);
3888 else
3889 {
3890 char *before_reloc = input_line_pointer;
3891 reloc = parse_reloc (&input_line_pointer);
3892 if (reloc == -1)
3893 {
3894 as_bad (_("unrecognized relocation suffix"));
3895 ignore_rest_of_line ();
3896 return;
3897 }
3898 else if (reloc == BFD_RELOC_UNUSED)
3899 emit_expr (&exp, (unsigned int) nbytes);
3900 else
3901 {
21d799b5 3902 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3903 bfd_reloc_type_lookup (stdoutput,
3904 (bfd_reloc_code_real_type) reloc);
c19d1205 3905 int size = bfd_get_reloc_size (howto);
b99bd4ef 3906
2fc8bdac
ZW
3907 if (reloc == BFD_RELOC_ARM_PLT32)
3908 {
3909 as_bad (_("(plt) is only valid on branch targets"));
3910 reloc = BFD_RELOC_UNUSED;
3911 size = 0;
3912 }
3913
c19d1205 3914 if (size > nbytes)
992a06ee
AM
3915 as_bad (ngettext ("%s relocations do not fit in %d byte",
3916 "%s relocations do not fit in %d bytes",
3917 nbytes),
c19d1205
ZW
3918 howto->name, nbytes);
3919 else
3920 {
3921 /* We've parsed an expression stopping at O_symbol.
3922 But there may be more expression left now that we
3923 have parsed the relocation marker. Parse it again.
3924 XXX Surely there is a cleaner way to do this. */
3925 char *p = input_line_pointer;
3926 int offset;
325801bd 3927 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3928
c19d1205
ZW
3929 memcpy (save_buf, base, input_line_pointer - base);
3930 memmove (base + (input_line_pointer - before_reloc),
3931 base, before_reloc - base);
3932
3933 input_line_pointer = base + (input_line_pointer-before_reloc);
3934 expression (&exp);
3935 memcpy (base, save_buf, p - base);
3936
3937 offset = nbytes - size;
4b1a927e
AM
3938 p = frag_more (nbytes);
3939 memset (p, 0, nbytes);
c19d1205 3940 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3941 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3942 free (save_buf);
c19d1205
ZW
3943 }
3944 }
3945 }
b99bd4ef 3946 }
c19d1205 3947 while (*input_line_pointer++ == ',');
b99bd4ef 3948
c19d1205
ZW
3949 /* Put terminator back into stream. */
3950 input_line_pointer --;
3951 demand_empty_rest_of_line ();
b99bd4ef
NC
3952}
3953
c921be7d
NC
3954/* Emit an expression containing a 32-bit thumb instruction.
3955 Implementation based on put_thumb32_insn. */
3956
3957static void
3958emit_thumb32_expr (expressionS * exp)
3959{
3960 expressionS exp_high = *exp;
3961
3962 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3963 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3964 exp->X_add_number &= 0xffff;
3965 emit_expr (exp, (unsigned int) THUMB_SIZE);
3966}
3967
3968/* Guess the instruction size based on the opcode. */
3969
3970static int
3971thumb_insn_size (int opcode)
3972{
3973 if ((unsigned int) opcode < 0xe800u)
3974 return 2;
3975 else if ((unsigned int) opcode >= 0xe8000000u)
3976 return 4;
3977 else
3978 return 0;
3979}
3980
3981static bfd_boolean
3982emit_insn (expressionS *exp, int nbytes)
3983{
3984 int size = 0;
3985
3986 if (exp->X_op == O_constant)
3987 {
3988 size = nbytes;
3989
3990 if (size == 0)
3991 size = thumb_insn_size (exp->X_add_number);
3992
3993 if (size != 0)
3994 {
3995 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3996 {
3997 as_bad (_(".inst.n operand too big. "\
3998 "Use .inst.w instead"));
3999 size = 0;
4000 }
4001 else
4002 {
5ee91343
AV
4003 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4004 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 4005 else
5ee91343 4006 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
4007
4008 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4009 emit_thumb32_expr (exp);
4010 else
4011 emit_expr (exp, (unsigned int) size);
4012
4013 it_fsm_post_encode ();
4014 }
4015 }
4016 else
4017 as_bad (_("cannot determine Thumb instruction size. " \
4018 "Use .inst.n/.inst.w instead"));
4019 }
4020 else
4021 as_bad (_("constant expression required"));
4022
4023 return (size != 0);
4024}
4025
4026/* Like s_arm_elf_cons but do not use md_cons_align and
4027 set the mapping state to MAP_ARM/MAP_THUMB. */
4028
4029static void
4030s_arm_elf_inst (int nbytes)
4031{
4032 if (is_it_end_of_statement ())
4033 {
4034 demand_empty_rest_of_line ();
4035 return;
4036 }
4037
4038 /* Calling mapping_state () here will not change ARM/THUMB,
4039 but will ensure not to be in DATA state. */
4040
4041 if (thumb_mode)
4042 mapping_state (MAP_THUMB);
4043 else
4044 {
4045 if (nbytes != 0)
4046 {
4047 as_bad (_("width suffixes are invalid in ARM mode"));
4048 ignore_rest_of_line ();
4049 return;
4050 }
4051
4052 nbytes = 4;
4053
4054 mapping_state (MAP_ARM);
4055 }
4056
4057 do
4058 {
4059 expressionS exp;
4060
4061 expression (& exp);
4062
4063 if (! emit_insn (& exp, nbytes))
4064 {
4065 ignore_rest_of_line ();
4066 return;
4067 }
4068 }
4069 while (*input_line_pointer++ == ',');
4070
4071 /* Put terminator back into stream. */
4072 input_line_pointer --;
4073 demand_empty_rest_of_line ();
4074}
b99bd4ef 4075
c19d1205 4076/* Parse a .rel31 directive. */
b99bd4ef 4077
c19d1205
ZW
4078static void
4079s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4080{
4081 expressionS exp;
4082 char *p;
4083 valueT highbit;
b99bd4ef 4084
c19d1205
ZW
4085 highbit = 0;
4086 if (*input_line_pointer == '1')
4087 highbit = 0x80000000;
4088 else if (*input_line_pointer != '0')
4089 as_bad (_("expected 0 or 1"));
b99bd4ef 4090
c19d1205
ZW
4091 input_line_pointer++;
4092 if (*input_line_pointer != ',')
4093 as_bad (_("missing comma"));
4094 input_line_pointer++;
b99bd4ef 4095
c19d1205
ZW
4096#ifdef md_flush_pending_output
4097 md_flush_pending_output ();
4098#endif
b99bd4ef 4099
c19d1205
ZW
4100#ifdef md_cons_align
4101 md_cons_align (4);
4102#endif
b99bd4ef 4103
c19d1205 4104 mapping_state (MAP_DATA);
b99bd4ef 4105
c19d1205 4106 expression (&exp);
b99bd4ef 4107
c19d1205
ZW
4108 p = frag_more (4);
4109 md_number_to_chars (p, highbit, 4);
4110 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4111 BFD_RELOC_ARM_PREL31);
b99bd4ef 4112
c19d1205 4113 demand_empty_rest_of_line ();
b99bd4ef
NC
4114}
4115
c19d1205 4116/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4117
c19d1205 4118/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4119
c19d1205
ZW
4120static void
4121s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4122{
4123 demand_empty_rest_of_line ();
921e5f0a
PB
4124 if (unwind.proc_start)
4125 {
c921be7d 4126 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4127 return;
4128 }
4129
c19d1205
ZW
4130 /* Mark the start of the function. */
4131 unwind.proc_start = expr_build_dot ();
b99bd4ef 4132
c19d1205
ZW
4133 /* Reset the rest of the unwind info. */
4134 unwind.opcode_count = 0;
4135 unwind.table_entry = NULL;
4136 unwind.personality_routine = NULL;
4137 unwind.personality_index = -1;
4138 unwind.frame_size = 0;
4139 unwind.fp_offset = 0;
fdfde340 4140 unwind.fp_reg = REG_SP;
c19d1205
ZW
4141 unwind.fp_used = 0;
4142 unwind.sp_restored = 0;
4143}
b99bd4ef 4144
b99bd4ef 4145
c19d1205
ZW
4146/* Parse a handlerdata directive. Creates the exception handling table entry
4147 for the function. */
b99bd4ef 4148
c19d1205
ZW
4149static void
4150s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4151{
4152 demand_empty_rest_of_line ();
921e5f0a 4153 if (!unwind.proc_start)
c921be7d 4154 as_bad (MISSING_FNSTART);
921e5f0a 4155
c19d1205 4156 if (unwind.table_entry)
6decc662 4157 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4158
c19d1205
ZW
4159 create_unwind_entry (1);
4160}
a737bd4d 4161
c19d1205 4162/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4163
c19d1205
ZW
4164static void
4165s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4166{
4167 long where;
4168 char *ptr;
4169 valueT val;
940b5ce0 4170 unsigned int marked_pr_dependency;
f02232aa 4171
c19d1205 4172 demand_empty_rest_of_line ();
f02232aa 4173
921e5f0a
PB
4174 if (!unwind.proc_start)
4175 {
c921be7d 4176 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4177 return;
4178 }
4179
c19d1205
ZW
4180 /* Add eh table entry. */
4181 if (unwind.table_entry == NULL)
4182 val = create_unwind_entry (0);
4183 else
4184 val = 0;
f02232aa 4185
c19d1205
ZW
4186 /* Add index table entry. This is two words. */
4187 start_unwind_section (unwind.saved_seg, 1);
4188 frag_align (2, 0, 0);
4189 record_alignment (now_seg, 2);
b99bd4ef 4190
c19d1205 4191 ptr = frag_more (8);
5011093d 4192 memset (ptr, 0, 8);
c19d1205 4193 where = frag_now_fix () - 8;
f02232aa 4194
c19d1205
ZW
4195 /* Self relative offset of the function start. */
4196 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4197 BFD_RELOC_ARM_PREL31);
f02232aa 4198
c19d1205
ZW
4199 /* Indicate dependency on EHABI-defined personality routines to the
4200 linker, if it hasn't been done already. */
940b5ce0
DJ
4201 marked_pr_dependency
4202 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4203 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4204 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4205 {
5f4273c7
NC
4206 static const char *const name[] =
4207 {
4208 "__aeabi_unwind_cpp_pr0",
4209 "__aeabi_unwind_cpp_pr1",
4210 "__aeabi_unwind_cpp_pr2"
4211 };
c19d1205
ZW
4212 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4213 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4214 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4215 |= 1 << unwind.personality_index;
c19d1205 4216 }
f02232aa 4217
c19d1205
ZW
4218 if (val)
4219 /* Inline exception table entry. */
4220 md_number_to_chars (ptr + 4, val, 4);
4221 else
4222 /* Self relative offset of the table entry. */
4223 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4224 BFD_RELOC_ARM_PREL31);
f02232aa 4225
c19d1205
ZW
4226 /* Restore the original section. */
4227 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4228
4229 unwind.proc_start = NULL;
c19d1205 4230}
f02232aa 4231
f02232aa 4232
c19d1205 4233/* Parse an unwind_cantunwind directive. */
b99bd4ef 4234
c19d1205
ZW
4235static void
4236s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4237{
4238 demand_empty_rest_of_line ();
921e5f0a 4239 if (!unwind.proc_start)
c921be7d 4240 as_bad (MISSING_FNSTART);
921e5f0a 4241
c19d1205
ZW
4242 if (unwind.personality_routine || unwind.personality_index != -1)
4243 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4244
c19d1205
ZW
4245 unwind.personality_index = -2;
4246}
b99bd4ef 4247
b99bd4ef 4248
c19d1205 4249/* Parse a personalityindex directive. */
b99bd4ef 4250
c19d1205
ZW
4251static void
4252s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4253{
4254 expressionS exp;
b99bd4ef 4255
921e5f0a 4256 if (!unwind.proc_start)
c921be7d 4257 as_bad (MISSING_FNSTART);
921e5f0a 4258
c19d1205
ZW
4259 if (unwind.personality_routine || unwind.personality_index != -1)
4260 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4261
c19d1205 4262 expression (&exp);
b99bd4ef 4263
c19d1205
ZW
4264 if (exp.X_op != O_constant
4265 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4266 {
c19d1205
ZW
4267 as_bad (_("bad personality routine number"));
4268 ignore_rest_of_line ();
4269 return;
b99bd4ef
NC
4270 }
4271
c19d1205 4272 unwind.personality_index = exp.X_add_number;
b99bd4ef 4273
c19d1205
ZW
4274 demand_empty_rest_of_line ();
4275}
e16bb312 4276
e16bb312 4277
c19d1205 4278/* Parse a personality directive. */
e16bb312 4279
c19d1205
ZW
4280static void
4281s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4282{
4283 char *name, *p, c;
a737bd4d 4284
921e5f0a 4285 if (!unwind.proc_start)
c921be7d 4286 as_bad (MISSING_FNSTART);
921e5f0a 4287
c19d1205
ZW
4288 if (unwind.personality_routine || unwind.personality_index != -1)
4289 as_bad (_("duplicate .personality directive"));
a737bd4d 4290
d02603dc 4291 c = get_symbol_name (& name);
c19d1205 4292 p = input_line_pointer;
d02603dc
NC
4293 if (c == '"')
4294 ++ input_line_pointer;
c19d1205
ZW
4295 unwind.personality_routine = symbol_find_or_make (name);
4296 *p = c;
4297 demand_empty_rest_of_line ();
4298}
e16bb312 4299
e16bb312 4300
c19d1205 4301/* Parse a directive saving core registers. */
e16bb312 4302
c19d1205
ZW
4303static void
4304s_arm_unwind_save_core (void)
e16bb312 4305{
c19d1205
ZW
4306 valueT op;
4307 long range;
4308 int n;
e16bb312 4309
4b5a202f 4310 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4311 if (range == FAIL)
e16bb312 4312 {
c19d1205
ZW
4313 as_bad (_("expected register list"));
4314 ignore_rest_of_line ();
4315 return;
4316 }
e16bb312 4317
c19d1205 4318 demand_empty_rest_of_line ();
e16bb312 4319
c19d1205
ZW
4320 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4321 into .unwind_save {..., sp...}. We aren't bothered about the value of
4322 ip because it is clobbered by calls. */
4323 if (unwind.sp_restored && unwind.fp_reg == 12
4324 && (range & 0x3000) == 0x1000)
4325 {
4326 unwind.opcode_count--;
4327 unwind.sp_restored = 0;
4328 range = (range | 0x2000) & ~0x1000;
4329 unwind.pending_offset = 0;
4330 }
e16bb312 4331
01ae4198
DJ
4332 /* Pop r4-r15. */
4333 if (range & 0xfff0)
c19d1205 4334 {
01ae4198
DJ
4335 /* See if we can use the short opcodes. These pop a block of up to 8
4336 registers starting with r4, plus maybe r14. */
4337 for (n = 0; n < 8; n++)
4338 {
4339 /* Break at the first non-saved register. */
4340 if ((range & (1 << (n + 4))) == 0)
4341 break;
4342 }
4343 /* See if there are any other bits set. */
4344 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4345 {
4346 /* Use the long form. */
4347 op = 0x8000 | ((range >> 4) & 0xfff);
4348 add_unwind_opcode (op, 2);
4349 }
0dd132b6 4350 else
01ae4198
DJ
4351 {
4352 /* Use the short form. */
4353 if (range & 0x4000)
4354 op = 0xa8; /* Pop r14. */
4355 else
4356 op = 0xa0; /* Do not pop r14. */
4357 op |= (n - 1);
4358 add_unwind_opcode (op, 1);
4359 }
c19d1205 4360 }
0dd132b6 4361
c19d1205
ZW
4362 /* Pop r0-r3. */
4363 if (range & 0xf)
4364 {
4365 op = 0xb100 | (range & 0xf);
4366 add_unwind_opcode (op, 2);
0dd132b6
NC
4367 }
4368
c19d1205
ZW
4369 /* Record the number of bytes pushed. */
4370 for (n = 0; n < 16; n++)
4371 {
4372 if (range & (1 << n))
4373 unwind.frame_size += 4;
4374 }
0dd132b6
NC
4375}
4376
c19d1205
ZW
4377
4378/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4379
4380static void
c19d1205 4381s_arm_unwind_save_fpa (int reg)
b99bd4ef 4382{
c19d1205
ZW
4383 expressionS exp;
4384 int num_regs;
4385 valueT op;
b99bd4ef 4386
c19d1205
ZW
4387 /* Get Number of registers to transfer. */
4388 if (skip_past_comma (&input_line_pointer) != FAIL)
4389 expression (&exp);
4390 else
4391 exp.X_op = O_illegal;
b99bd4ef 4392
c19d1205 4393 if (exp.X_op != O_constant)
b99bd4ef 4394 {
c19d1205
ZW
4395 as_bad (_("expected , <constant>"));
4396 ignore_rest_of_line ();
b99bd4ef
NC
4397 return;
4398 }
4399
c19d1205
ZW
4400 num_regs = exp.X_add_number;
4401
4402 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4403 {
c19d1205
ZW
4404 as_bad (_("number of registers must be in the range [1:4]"));
4405 ignore_rest_of_line ();
b99bd4ef
NC
4406 return;
4407 }
4408
c19d1205 4409 demand_empty_rest_of_line ();
b99bd4ef 4410
c19d1205
ZW
4411 if (reg == 4)
4412 {
4413 /* Short form. */
4414 op = 0xb4 | (num_regs - 1);
4415 add_unwind_opcode (op, 1);
4416 }
b99bd4ef
NC
4417 else
4418 {
c19d1205
ZW
4419 /* Long form. */
4420 op = 0xc800 | (reg << 4) | (num_regs - 1);
4421 add_unwind_opcode (op, 2);
b99bd4ef 4422 }
c19d1205 4423 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4424}
4425
c19d1205 4426
fa073d69
MS
4427/* Parse a directive saving VFP registers for ARMv6 and above. */
4428
4429static void
4430s_arm_unwind_save_vfp_armv6 (void)
4431{
4432 int count;
4433 unsigned int start;
4434 valueT op;
4435 int num_vfpv3_regs = 0;
4436 int num_regs_below_16;
efd6b359 4437 bfd_boolean partial_match;
fa073d69 4438
efd6b359
AV
4439 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4440 &partial_match);
fa073d69
MS
4441 if (count == FAIL)
4442 {
4443 as_bad (_("expected register list"));
4444 ignore_rest_of_line ();
4445 return;
4446 }
4447
4448 demand_empty_rest_of_line ();
4449
4450 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4451 than FSTMX/FLDMX-style ones). */
4452
4453 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4454 if (start >= 16)
4455 num_vfpv3_regs = count;
4456 else if (start + count > 16)
4457 num_vfpv3_regs = start + count - 16;
4458
4459 if (num_vfpv3_regs > 0)
4460 {
4461 int start_offset = start > 16 ? start - 16 : 0;
4462 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4463 add_unwind_opcode (op, 2);
4464 }
4465
4466 /* Generate opcode for registers numbered in the range 0 .. 15. */
4467 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4468 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4469 if (num_regs_below_16 > 0)
4470 {
4471 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4472 add_unwind_opcode (op, 2);
4473 }
4474
4475 unwind.frame_size += count * 8;
4476}
4477
4478
4479/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4480
4481static void
c19d1205 4482s_arm_unwind_save_vfp (void)
b99bd4ef 4483{
c19d1205 4484 int count;
ca3f61f7 4485 unsigned int reg;
c19d1205 4486 valueT op;
efd6b359 4487 bfd_boolean partial_match;
b99bd4ef 4488
efd6b359
AV
4489 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4490 &partial_match);
c19d1205 4491 if (count == FAIL)
b99bd4ef 4492 {
c19d1205
ZW
4493 as_bad (_("expected register list"));
4494 ignore_rest_of_line ();
b99bd4ef
NC
4495 return;
4496 }
4497
c19d1205 4498 demand_empty_rest_of_line ();
b99bd4ef 4499
c19d1205 4500 if (reg == 8)
b99bd4ef 4501 {
c19d1205
ZW
4502 /* Short form. */
4503 op = 0xb8 | (count - 1);
4504 add_unwind_opcode (op, 1);
b99bd4ef 4505 }
c19d1205 4506 else
b99bd4ef 4507 {
c19d1205
ZW
4508 /* Long form. */
4509 op = 0xb300 | (reg << 4) | (count - 1);
4510 add_unwind_opcode (op, 2);
b99bd4ef 4511 }
c19d1205
ZW
4512 unwind.frame_size += count * 8 + 4;
4513}
b99bd4ef 4514
b99bd4ef 4515
c19d1205
ZW
4516/* Parse a directive saving iWMMXt data registers. */
4517
4518static void
4519s_arm_unwind_save_mmxwr (void)
4520{
4521 int reg;
4522 int hi_reg;
4523 int i;
4524 unsigned mask = 0;
4525 valueT op;
b99bd4ef 4526
c19d1205
ZW
4527 if (*input_line_pointer == '{')
4528 input_line_pointer++;
b99bd4ef 4529
c19d1205 4530 do
b99bd4ef 4531 {
dcbf9037 4532 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4533
c19d1205 4534 if (reg == FAIL)
b99bd4ef 4535 {
9b7132d3 4536 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4537 goto error;
b99bd4ef
NC
4538 }
4539
c19d1205
ZW
4540 if (mask >> reg)
4541 as_tsktsk (_("register list not in ascending order"));
4542 mask |= 1 << reg;
b99bd4ef 4543
c19d1205
ZW
4544 if (*input_line_pointer == '-')
4545 {
4546 input_line_pointer++;
dcbf9037 4547 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4548 if (hi_reg == FAIL)
4549 {
9b7132d3 4550 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4551 goto error;
4552 }
4553 else if (reg >= hi_reg)
4554 {
4555 as_bad (_("bad register range"));
4556 goto error;
4557 }
4558 for (; reg < hi_reg; reg++)
4559 mask |= 1 << reg;
4560 }
4561 }
4562 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4563
d996d970 4564 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4565
c19d1205 4566 demand_empty_rest_of_line ();
b99bd4ef 4567
708587a4 4568 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4569 the list. */
4570 flush_pending_unwind ();
b99bd4ef 4571
c19d1205 4572 for (i = 0; i < 16; i++)
b99bd4ef 4573 {
c19d1205
ZW
4574 if (mask & (1 << i))
4575 unwind.frame_size += 8;
b99bd4ef
NC
4576 }
4577
c19d1205
ZW
4578 /* Attempt to combine with a previous opcode. We do this because gcc
4579 likes to output separate unwind directives for a single block of
4580 registers. */
4581 if (unwind.opcode_count > 0)
b99bd4ef 4582 {
c19d1205
ZW
4583 i = unwind.opcodes[unwind.opcode_count - 1];
4584 if ((i & 0xf8) == 0xc0)
4585 {
4586 i &= 7;
4587 /* Only merge if the blocks are contiguous. */
4588 if (i < 6)
4589 {
4590 if ((mask & 0xfe00) == (1 << 9))
4591 {
4592 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4593 unwind.opcode_count--;
4594 }
4595 }
4596 else if (i == 6 && unwind.opcode_count >= 2)
4597 {
4598 i = unwind.opcodes[unwind.opcode_count - 2];
4599 reg = i >> 4;
4600 i &= 0xf;
b99bd4ef 4601
c19d1205
ZW
4602 op = 0xffff << (reg - 1);
4603 if (reg > 0
87a1fd79 4604 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4605 {
4606 op = (1 << (reg + i + 1)) - 1;
4607 op &= ~((1 << reg) - 1);
4608 mask |= op;
4609 unwind.opcode_count -= 2;
4610 }
4611 }
4612 }
b99bd4ef
NC
4613 }
4614
c19d1205
ZW
4615 hi_reg = 15;
4616 /* We want to generate opcodes in the order the registers have been
4617 saved, ie. descending order. */
4618 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4619 {
c19d1205
ZW
4620 /* Save registers in blocks. */
4621 if (reg < 0
4622 || !(mask & (1 << reg)))
4623 {
4624 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4625 preceding block. */
c19d1205
ZW
4626 if (reg != hi_reg)
4627 {
4628 if (reg == 9)
4629 {
4630 /* Short form. */
4631 op = 0xc0 | (hi_reg - 10);
4632 add_unwind_opcode (op, 1);
4633 }
4634 else
4635 {
4636 /* Long form. */
4637 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4638 add_unwind_opcode (op, 2);
4639 }
4640 }
4641 hi_reg = reg - 1;
4642 }
b99bd4ef
NC
4643 }
4644
c19d1205
ZW
4645 return;
4646error:
4647 ignore_rest_of_line ();
b99bd4ef
NC
4648}
4649
4650static void
c19d1205 4651s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4652{
c19d1205
ZW
4653 int reg;
4654 int hi_reg;
4655 unsigned mask = 0;
4656 valueT op;
b99bd4ef 4657
c19d1205
ZW
4658 if (*input_line_pointer == '{')
4659 input_line_pointer++;
b99bd4ef 4660
477330fc
RM
4661 skip_whitespace (input_line_pointer);
4662
c19d1205 4663 do
b99bd4ef 4664 {
dcbf9037 4665 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4666
c19d1205
ZW
4667 if (reg == FAIL)
4668 {
9b7132d3 4669 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4670 goto error;
4671 }
b99bd4ef 4672
c19d1205
ZW
4673 reg -= 8;
4674 if (mask >> reg)
4675 as_tsktsk (_("register list not in ascending order"));
4676 mask |= 1 << reg;
b99bd4ef 4677
c19d1205
ZW
4678 if (*input_line_pointer == '-')
4679 {
4680 input_line_pointer++;
dcbf9037 4681 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4682 if (hi_reg == FAIL)
4683 {
9b7132d3 4684 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4685 goto error;
4686 }
4687 else if (reg >= hi_reg)
4688 {
4689 as_bad (_("bad register range"));
4690 goto error;
4691 }
4692 for (; reg < hi_reg; reg++)
4693 mask |= 1 << reg;
4694 }
b99bd4ef 4695 }
c19d1205 4696 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4697
d996d970 4698 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4699
c19d1205
ZW
4700 demand_empty_rest_of_line ();
4701
708587a4 4702 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4703 the list. */
4704 flush_pending_unwind ();
b99bd4ef 4705
c19d1205 4706 for (reg = 0; reg < 16; reg++)
b99bd4ef 4707 {
c19d1205
ZW
4708 if (mask & (1 << reg))
4709 unwind.frame_size += 4;
b99bd4ef 4710 }
c19d1205
ZW
4711 op = 0xc700 | mask;
4712 add_unwind_opcode (op, 2);
4713 return;
4714error:
4715 ignore_rest_of_line ();
b99bd4ef
NC
4716}
4717
c19d1205 4718
fa073d69
MS
4719/* Parse an unwind_save directive.
4720 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4721
b99bd4ef 4722static void
fa073d69 4723s_arm_unwind_save (int arch_v6)
b99bd4ef 4724{
c19d1205
ZW
4725 char *peek;
4726 struct reg_entry *reg;
4727 bfd_boolean had_brace = FALSE;
b99bd4ef 4728
921e5f0a 4729 if (!unwind.proc_start)
c921be7d 4730 as_bad (MISSING_FNSTART);
921e5f0a 4731
c19d1205
ZW
4732 /* Figure out what sort of save we have. */
4733 peek = input_line_pointer;
b99bd4ef 4734
c19d1205 4735 if (*peek == '{')
b99bd4ef 4736 {
c19d1205
ZW
4737 had_brace = TRUE;
4738 peek++;
b99bd4ef
NC
4739 }
4740
c19d1205 4741 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4742
c19d1205 4743 if (!reg)
b99bd4ef 4744 {
c19d1205
ZW
4745 as_bad (_("register expected"));
4746 ignore_rest_of_line ();
b99bd4ef
NC
4747 return;
4748 }
4749
c19d1205 4750 switch (reg->type)
b99bd4ef 4751 {
c19d1205
ZW
4752 case REG_TYPE_FN:
4753 if (had_brace)
4754 {
4755 as_bad (_("FPA .unwind_save does not take a register list"));
4756 ignore_rest_of_line ();
4757 return;
4758 }
93ac2687 4759 input_line_pointer = peek;
c19d1205 4760 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4761 return;
c19d1205 4762
1f5afe1c
NC
4763 case REG_TYPE_RN:
4764 s_arm_unwind_save_core ();
4765 return;
4766
fa073d69
MS
4767 case REG_TYPE_VFD:
4768 if (arch_v6)
477330fc 4769 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4770 else
477330fc 4771 s_arm_unwind_save_vfp ();
fa073d69 4772 return;
1f5afe1c
NC
4773
4774 case REG_TYPE_MMXWR:
4775 s_arm_unwind_save_mmxwr ();
4776 return;
4777
4778 case REG_TYPE_MMXWCG:
4779 s_arm_unwind_save_mmxwcg ();
4780 return;
c19d1205
ZW
4781
4782 default:
4783 as_bad (_(".unwind_save does not support this kind of register"));
4784 ignore_rest_of_line ();
b99bd4ef 4785 }
c19d1205 4786}
b99bd4ef 4787
b99bd4ef 4788
c19d1205
ZW
4789/* Parse an unwind_movsp directive. */
4790
4791static void
4792s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4793{
4794 int reg;
4795 valueT op;
4fa3602b 4796 int offset;
c19d1205 4797
921e5f0a 4798 if (!unwind.proc_start)
c921be7d 4799 as_bad (MISSING_FNSTART);
921e5f0a 4800
dcbf9037 4801 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4802 if (reg == FAIL)
b99bd4ef 4803 {
9b7132d3 4804 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4805 ignore_rest_of_line ();
b99bd4ef
NC
4806 return;
4807 }
4fa3602b
PB
4808
4809 /* Optional constant. */
4810 if (skip_past_comma (&input_line_pointer) != FAIL)
4811 {
4812 if (immediate_for_directive (&offset) == FAIL)
4813 return;
4814 }
4815 else
4816 offset = 0;
4817
c19d1205 4818 demand_empty_rest_of_line ();
b99bd4ef 4819
c19d1205 4820 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4821 {
c19d1205 4822 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4823 return;
4824 }
4825
c19d1205
ZW
4826 if (unwind.fp_reg != REG_SP)
4827 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4828
c19d1205
ZW
4829 /* Generate opcode to restore the value. */
4830 op = 0x90 | reg;
4831 add_unwind_opcode (op, 1);
4832
4833 /* Record the information for later. */
4834 unwind.fp_reg = reg;
4fa3602b 4835 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4836 unwind.sp_restored = 1;
b05fe5cf
ZW
4837}
4838
c19d1205
ZW
4839/* Parse an unwind_pad directive. */
4840
b05fe5cf 4841static void
c19d1205 4842s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4843{
c19d1205 4844 int offset;
b05fe5cf 4845
921e5f0a 4846 if (!unwind.proc_start)
c921be7d 4847 as_bad (MISSING_FNSTART);
921e5f0a 4848
c19d1205
ZW
4849 if (immediate_for_directive (&offset) == FAIL)
4850 return;
b99bd4ef 4851
c19d1205
ZW
4852 if (offset & 3)
4853 {
4854 as_bad (_("stack increment must be multiple of 4"));
4855 ignore_rest_of_line ();
4856 return;
4857 }
b99bd4ef 4858
c19d1205
ZW
4859 /* Don't generate any opcodes, just record the details for later. */
4860 unwind.frame_size += offset;
4861 unwind.pending_offset += offset;
4862
4863 demand_empty_rest_of_line ();
4864}
4865
4866/* Parse an unwind_setfp directive. */
4867
4868static void
4869s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4870{
c19d1205
ZW
4871 int sp_reg;
4872 int fp_reg;
4873 int offset;
4874
921e5f0a 4875 if (!unwind.proc_start)
c921be7d 4876 as_bad (MISSING_FNSTART);
921e5f0a 4877
dcbf9037 4878 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4879 if (skip_past_comma (&input_line_pointer) == FAIL)
4880 sp_reg = FAIL;
4881 else
dcbf9037 4882 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4883
c19d1205
ZW
4884 if (fp_reg == FAIL || sp_reg == FAIL)
4885 {
4886 as_bad (_("expected <reg>, <reg>"));
4887 ignore_rest_of_line ();
4888 return;
4889 }
b99bd4ef 4890
c19d1205
ZW
4891 /* Optional constant. */
4892 if (skip_past_comma (&input_line_pointer) != FAIL)
4893 {
4894 if (immediate_for_directive (&offset) == FAIL)
4895 return;
4896 }
4897 else
4898 offset = 0;
a737bd4d 4899
c19d1205 4900 demand_empty_rest_of_line ();
a737bd4d 4901
fdfde340 4902 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4903 {
c19d1205
ZW
4904 as_bad (_("register must be either sp or set by a previous"
4905 "unwind_movsp directive"));
4906 return;
a737bd4d
NC
4907 }
4908
c19d1205
ZW
4909 /* Don't generate any opcodes, just record the information for later. */
4910 unwind.fp_reg = fp_reg;
4911 unwind.fp_used = 1;
fdfde340 4912 if (sp_reg == REG_SP)
c19d1205
ZW
4913 unwind.fp_offset = unwind.frame_size - offset;
4914 else
4915 unwind.fp_offset -= offset;
a737bd4d
NC
4916}
4917
c19d1205
ZW
4918/* Parse an unwind_raw directive. */
4919
4920static void
4921s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4922{
c19d1205 4923 expressionS exp;
708587a4 4924 /* This is an arbitrary limit. */
c19d1205
ZW
4925 unsigned char op[16];
4926 int count;
a737bd4d 4927
921e5f0a 4928 if (!unwind.proc_start)
c921be7d 4929 as_bad (MISSING_FNSTART);
921e5f0a 4930
c19d1205
ZW
4931 expression (&exp);
4932 if (exp.X_op == O_constant
4933 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4934 {
c19d1205
ZW
4935 unwind.frame_size += exp.X_add_number;
4936 expression (&exp);
4937 }
4938 else
4939 exp.X_op = O_illegal;
a737bd4d 4940
c19d1205
ZW
4941 if (exp.X_op != O_constant)
4942 {
4943 as_bad (_("expected <offset>, <opcode>"));
4944 ignore_rest_of_line ();
4945 return;
4946 }
a737bd4d 4947
c19d1205 4948 count = 0;
a737bd4d 4949
c19d1205
ZW
4950 /* Parse the opcode. */
4951 for (;;)
4952 {
4953 if (count >= 16)
4954 {
4955 as_bad (_("unwind opcode too long"));
4956 ignore_rest_of_line ();
a737bd4d 4957 }
c19d1205 4958 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4959 {
c19d1205
ZW
4960 as_bad (_("invalid unwind opcode"));
4961 ignore_rest_of_line ();
4962 return;
a737bd4d 4963 }
c19d1205 4964 op[count++] = exp.X_add_number;
a737bd4d 4965
c19d1205
ZW
4966 /* Parse the next byte. */
4967 if (skip_past_comma (&input_line_pointer) == FAIL)
4968 break;
a737bd4d 4969
c19d1205
ZW
4970 expression (&exp);
4971 }
b99bd4ef 4972
c19d1205
ZW
4973 /* Add the opcode bytes in reverse order. */
4974 while (count--)
4975 add_unwind_opcode (op[count], 1);
b99bd4ef 4976
c19d1205 4977 demand_empty_rest_of_line ();
b99bd4ef 4978}
ee065d83
PB
4979
4980
4981/* Parse a .eabi_attribute directive. */
4982
4983static void
4984s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4985{
0420f52b 4986 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4987
3076e594 4988 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4989 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4990}
4991
0855e32b
NS
4992/* Emit a tls fix for the symbol. */
4993
4994static void
4995s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4996{
4997 char *p;
4998 expressionS exp;
4999#ifdef md_flush_pending_output
5000 md_flush_pending_output ();
5001#endif
5002
5003#ifdef md_cons_align
5004 md_cons_align (4);
5005#endif
5006
5007 /* Since we're just labelling the code, there's no need to define a
5008 mapping symbol. */
5009 expression (&exp);
5010 p = obstack_next_free (&frchain_now->frch_obstack);
5011 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5012 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5013 : BFD_RELOC_ARM_TLS_DESCSEQ);
5014}
cdf9ccec 5015#endif /* OBJ_ELF */
0855e32b 5016
ee065d83 5017static void s_arm_arch (int);
7a1d4c38 5018static void s_arm_object_arch (int);
ee065d83
PB
5019static void s_arm_cpu (int);
5020static void s_arm_fpu (int);
69133863 5021static void s_arm_arch_extension (int);
b99bd4ef 5022
f0927246
NC
5023#ifdef TE_PE
5024
5025static void
5f4273c7 5026pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
5027{
5028 expressionS exp;
5029
5030 do
5031 {
5032 expression (&exp);
5033 if (exp.X_op == O_symbol)
5034 exp.X_op = O_secrel;
5035
5036 emit_expr (&exp, 4);
5037 }
5038 while (*input_line_pointer++ == ',');
5039
5040 input_line_pointer--;
5041 demand_empty_rest_of_line ();
5042}
5043#endif /* TE_PE */
5044
5312fe52
BW
5045int
5046arm_is_largest_exponent_ok (int precision)
5047{
5048 /* precision == 1 ensures that this will only return
5049 true for 16 bit floats. */
5050 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5051}
5052
5053static void
5054set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5055{
5056 char saved_char;
5057 char* name;
5058 enum fp_16bit_format new_format;
5059
5060 new_format = ARM_FP16_FORMAT_DEFAULT;
5061
5062 name = input_line_pointer;
5063 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5064 input_line_pointer++;
5065
5066 saved_char = *input_line_pointer;
5067 *input_line_pointer = 0;
5068
5069 if (strcasecmp (name, "ieee") == 0)
5070 new_format = ARM_FP16_FORMAT_IEEE;
5071 else if (strcasecmp (name, "alternative") == 0)
5072 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5073 else
5074 {
5075 as_bad (_("unrecognised float16 format \"%s\""), name);
5076 goto cleanup;
5077 }
5078
5079 /* Only set fp16_format if it is still the default (aka not already
5080 been set yet). */
5081 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5082 fp16_format = new_format;
5083 else
5084 {
5085 if (new_format != fp16_format)
5086 as_warn (_("float16 format cannot be set more than once, ignoring."));
5087 }
5088
5089cleanup:
5090 *input_line_pointer = saved_char;
5091 ignore_rest_of_line ();
5092}
5093
c19d1205
ZW
5094/* This table describes all the machine specific pseudo-ops the assembler
5095 has to support. The fields are:
5096 pseudo-op name without dot
5097 function to call to execute this pseudo-op
5098 Integer arg to pass to the function. */
b99bd4ef 5099
c19d1205 5100const pseudo_typeS md_pseudo_table[] =
b99bd4ef 5101{
c19d1205
ZW
5102 /* Never called because '.req' does not start a line. */
5103 { "req", s_req, 0 },
dcbf9037
JB
5104 /* Following two are likewise never called. */
5105 { "dn", s_dn, 0 },
5106 { "qn", s_qn, 0 },
c19d1205
ZW
5107 { "unreq", s_unreq, 0 },
5108 { "bss", s_bss, 0 },
db2ed2e0 5109 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5110 { "arm", s_arm, 0 },
5111 { "thumb", s_thumb, 0 },
5112 { "code", s_code, 0 },
5113 { "force_thumb", s_force_thumb, 0 },
5114 { "thumb_func", s_thumb_func, 0 },
5115 { "thumb_set", s_thumb_set, 0 },
5116 { "even", s_even, 0 },
5117 { "ltorg", s_ltorg, 0 },
5118 { "pool", s_ltorg, 0 },
5119 { "syntax", s_syntax, 0 },
8463be01
PB
5120 { "cpu", s_arm_cpu, 0 },
5121 { "arch", s_arm_arch, 0 },
7a1d4c38 5122 { "object_arch", s_arm_object_arch, 0 },
8463be01 5123 { "fpu", s_arm_fpu, 0 },
69133863 5124 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5125#ifdef OBJ_ELF
c921be7d
NC
5126 { "word", s_arm_elf_cons, 4 },
5127 { "long", s_arm_elf_cons, 4 },
5128 { "inst.n", s_arm_elf_inst, 2 },
5129 { "inst.w", s_arm_elf_inst, 4 },
5130 { "inst", s_arm_elf_inst, 0 },
5131 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5132 { "fnstart", s_arm_unwind_fnstart, 0 },
5133 { "fnend", s_arm_unwind_fnend, 0 },
5134 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5135 { "personality", s_arm_unwind_personality, 0 },
5136 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5137 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5138 { "save", s_arm_unwind_save, 0 },
fa073d69 5139 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5140 { "movsp", s_arm_unwind_movsp, 0 },
5141 { "pad", s_arm_unwind_pad, 0 },
5142 { "setfp", s_arm_unwind_setfp, 0 },
5143 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5144 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5145 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5146#else
5147 { "word", cons, 4},
f0927246
NC
5148
5149 /* These are used for dwarf. */
5150 {"2byte", cons, 2},
5151 {"4byte", cons, 4},
5152 {"8byte", cons, 8},
5153 /* These are used for dwarf2. */
68d20676 5154 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5155 { "loc", dwarf2_directive_loc, 0 },
5156 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5157#endif
5158 { "extend", float_cons, 'x' },
5159 { "ldouble", float_cons, 'x' },
5160 { "packed", float_cons, 'p' },
27cce866 5161 { "bfloat16", float_cons, 'b' },
f0927246
NC
5162#ifdef TE_PE
5163 {"secrel32", pe_directive_secrel, 0},
5164#endif
2e6976a8
DG
5165
5166 /* These are for compatibility with CodeComposer Studio. */
5167 {"ref", s_ccs_ref, 0},
5168 {"def", s_ccs_def, 0},
5169 {"asmfunc", s_ccs_asmfunc, 0},
5170 {"endasmfunc", s_ccs_endasmfunc, 0},
5171
5312fe52
BW
5172 {"float16", float_cons, 'h' },
5173 {"float16_format", set_fp16_format, 0 },
5174
c19d1205
ZW
5175 { 0, 0, 0 }
5176};
5312fe52 5177
c19d1205 5178/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5179
c19d1205
ZW
5180/* Generic immediate-value read function for use in insn parsing.
5181 STR points to the beginning of the immediate (the leading #);
5182 VAL receives the value; if the value is outside [MIN, MAX]
5183 issue an error. PREFIX_OPT is true if the immediate prefix is
5184 optional. */
b99bd4ef 5185
c19d1205
ZW
5186static int
5187parse_immediate (char **str, int *val, int min, int max,
5188 bfd_boolean prefix_opt)
5189{
5190 expressionS exp;
0198d5e6 5191
c19d1205
ZW
5192 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5193 if (exp.X_op != O_constant)
b99bd4ef 5194 {
c19d1205
ZW
5195 inst.error = _("constant expression required");
5196 return FAIL;
5197 }
b99bd4ef 5198
c19d1205
ZW
5199 if (exp.X_add_number < min || exp.X_add_number > max)
5200 {
5201 inst.error = _("immediate value out of range");
5202 return FAIL;
5203 }
b99bd4ef 5204
c19d1205
ZW
5205 *val = exp.X_add_number;
5206 return SUCCESS;
5207}
b99bd4ef 5208
5287ad62 5209/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5210 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5211 instructions. Puts the result directly in inst.operands[i]. */
5212
5213static int
8335d6aa
JW
5214parse_big_immediate (char **str, int i, expressionS *in_exp,
5215 bfd_boolean allow_symbol_p)
5287ad62
JB
5216{
5217 expressionS exp;
8335d6aa 5218 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5219 char *ptr = *str;
5220
8335d6aa 5221 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5222
8335d6aa 5223 if (exp_p->X_op == O_constant)
036dc3f7 5224 {
8335d6aa 5225 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5226 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5227 O_constant. We have to be careful not to break compilation for
5228 32-bit X_add_number, though. */
8335d6aa 5229 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5230 {
8335d6aa
JW
5231 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5232 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5233 & 0xffffffff);
036dc3f7
PB
5234 inst.operands[i].regisimm = 1;
5235 }
5236 }
8335d6aa
JW
5237 else if (exp_p->X_op == O_big
5238 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5239 {
5240 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5241
5287ad62 5242 /* Bignums have their least significant bits in
477330fc
RM
5243 generic_bignum[0]. Make sure we put 32 bits in imm and
5244 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5245 gas_assert (parts != 0);
95b75c01
NC
5246
5247 /* Make sure that the number is not too big.
5248 PR 11972: Bignums can now be sign-extended to the
5249 size of a .octa so check that the out of range bits
5250 are all zero or all one. */
8335d6aa 5251 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5252 {
5253 LITTLENUM_TYPE m = -1;
5254
5255 if (generic_bignum[parts * 2] != 0
5256 && generic_bignum[parts * 2] != m)
5257 return FAIL;
5258
8335d6aa 5259 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5260 if (generic_bignum[j] != generic_bignum[j-1])
5261 return FAIL;
5262 }
5263
5287ad62
JB
5264 inst.operands[i].imm = 0;
5265 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5266 inst.operands[i].imm |= generic_bignum[idx]
5267 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5268 inst.operands[i].reg = 0;
5269 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5270 inst.operands[i].reg |= generic_bignum[idx]
5271 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5272 inst.operands[i].regisimm = 1;
5273 }
8335d6aa 5274 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5275 return FAIL;
5f4273c7 5276
5287ad62
JB
5277 *str = ptr;
5278
5279 return SUCCESS;
5280}
5281
c19d1205
ZW
5282/* Returns the pseudo-register number of an FPA immediate constant,
5283 or FAIL if there isn't a valid constant here. */
b99bd4ef 5284
c19d1205
ZW
5285static int
5286parse_fpa_immediate (char ** str)
5287{
5288 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5289 char * save_in;
5290 expressionS exp;
5291 int i;
5292 int j;
b99bd4ef 5293
c19d1205
ZW
5294 /* First try and match exact strings, this is to guarantee
5295 that some formats will work even for cross assembly. */
b99bd4ef 5296
c19d1205
ZW
5297 for (i = 0; fp_const[i]; i++)
5298 {
5299 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5300 {
c19d1205 5301 char *start = *str;
b99bd4ef 5302
c19d1205
ZW
5303 *str += strlen (fp_const[i]);
5304 if (is_end_of_line[(unsigned char) **str])
5305 return i + 8;
5306 *str = start;
5307 }
5308 }
b99bd4ef 5309
c19d1205
ZW
5310 /* Just because we didn't get a match doesn't mean that the constant
5311 isn't valid, just that it is in a format that we don't
5312 automatically recognize. Try parsing it with the standard
5313 expression routines. */
b99bd4ef 5314
c19d1205 5315 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5316
c19d1205
ZW
5317 /* Look for a raw floating point number. */
5318 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5319 && is_end_of_line[(unsigned char) *save_in])
5320 {
5321 for (i = 0; i < NUM_FLOAT_VALS; i++)
5322 {
5323 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5324 {
c19d1205
ZW
5325 if (words[j] != fp_values[i][j])
5326 break;
b99bd4ef
NC
5327 }
5328
c19d1205 5329 if (j == MAX_LITTLENUMS)
b99bd4ef 5330 {
c19d1205
ZW
5331 *str = save_in;
5332 return i + 8;
b99bd4ef
NC
5333 }
5334 }
5335 }
b99bd4ef 5336
c19d1205
ZW
5337 /* Try and parse a more complex expression, this will probably fail
5338 unless the code uses a floating point prefix (eg "0f"). */
5339 save_in = input_line_pointer;
5340 input_line_pointer = *str;
5341 if (expression (&exp) == absolute_section
5342 && exp.X_op == O_big
5343 && exp.X_add_number < 0)
5344 {
5345 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5346 Ditto for 15. */
ba592044
AM
5347#define X_PRECISION 5
5348#define E_PRECISION 15L
5349 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5350 {
5351 for (i = 0; i < NUM_FLOAT_VALS; i++)
5352 {
5353 for (j = 0; j < MAX_LITTLENUMS; j++)
5354 {
5355 if (words[j] != fp_values[i][j])
5356 break;
5357 }
b99bd4ef 5358
c19d1205
ZW
5359 if (j == MAX_LITTLENUMS)
5360 {
5361 *str = input_line_pointer;
5362 input_line_pointer = save_in;
5363 return i + 8;
5364 }
5365 }
5366 }
b99bd4ef
NC
5367 }
5368
c19d1205
ZW
5369 *str = input_line_pointer;
5370 input_line_pointer = save_in;
5371 inst.error = _("invalid FPA immediate expression");
5372 return FAIL;
b99bd4ef
NC
5373}
5374
136da414
JB
5375/* Returns 1 if a number has "quarter-precision" float format
5376 0baBbbbbbc defgh000 00000000 00000000. */
5377
5378static int
5379is_quarter_float (unsigned imm)
5380{
5381 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5382 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5383}
5384
aacf0b33
KT
5385
5386/* Detect the presence of a floating point or integer zero constant,
5387 i.e. #0.0 or #0. */
5388
5389static bfd_boolean
5390parse_ifimm_zero (char **in)
5391{
5392 int error_code;
5393
5394 if (!is_immediate_prefix (**in))
3c6452ae
TP
5395 {
5396 /* In unified syntax, all prefixes are optional. */
5397 if (!unified_syntax)
5398 return FALSE;
5399 }
5400 else
5401 ++*in;
0900a05b
JW
5402
5403 /* Accept #0x0 as a synonym for #0. */
5404 if (strncmp (*in, "0x", 2) == 0)
5405 {
5406 int val;
5407 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5408 return FALSE;
5409 return TRUE;
5410 }
5411
aacf0b33
KT
5412 error_code = atof_generic (in, ".", EXP_CHARS,
5413 &generic_floating_point_number);
5414
5415 if (!error_code
5416 && generic_floating_point_number.sign == '+'
5417 && (generic_floating_point_number.low
5418 > generic_floating_point_number.leader))
5419 return TRUE;
5420
5421 return FALSE;
5422}
5423
136da414
JB
5424/* Parse an 8-bit "quarter-precision" floating point number of the form:
5425 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5426 The zero and minus-zero cases need special handling, since they can't be
5427 encoded in the "quarter-precision" float format, but can nonetheless be
5428 loaded as integer constants. */
136da414
JB
5429
5430static unsigned
5431parse_qfloat_immediate (char **ccp, int *immed)
5432{
5433 char *str = *ccp;
c96612cc 5434 char *fpnum;
136da414 5435 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5436 int found_fpchar = 0;
5f4273c7 5437
136da414 5438 skip_past_char (&str, '#');
5f4273c7 5439
c96612cc
JB
5440 /* We must not accidentally parse an integer as a floating-point number. Make
5441 sure that the value we parse is not an integer by checking for special
5442 characters '.' or 'e'.
5443 FIXME: This is a horrible hack, but doing better is tricky because type
5444 information isn't in a very usable state at parse time. */
5445 fpnum = str;
5446 skip_whitespace (fpnum);
5447
5448 if (strncmp (fpnum, "0x", 2) == 0)
5449 return FAIL;
5450 else
5451 {
5452 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5453 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5454 {
5455 found_fpchar = 1;
5456 break;
5457 }
c96612cc
JB
5458
5459 if (!found_fpchar)
477330fc 5460 return FAIL;
c96612cc 5461 }
5f4273c7 5462
136da414
JB
5463 if ((str = atof_ieee (str, 's', words)) != NULL)
5464 {
5465 unsigned fpword = 0;
5466 int i;
5f4273c7 5467
136da414
JB
5468 /* Our FP word must be 32 bits (single-precision FP). */
5469 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5470 {
5471 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5472 fpword |= words[i];
5473 }
5f4273c7 5474
c96612cc 5475 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5476 *immed = fpword;
136da414 5477 else
477330fc 5478 return FAIL;
136da414
JB
5479
5480 *ccp = str;
5f4273c7 5481
136da414
JB
5482 return SUCCESS;
5483 }
5f4273c7 5484
136da414
JB
5485 return FAIL;
5486}
5487
c19d1205
ZW
5488/* Shift operands. */
5489enum shift_kind
b99bd4ef 5490{
f5f10c66 5491 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5492};
b99bd4ef 5493
c19d1205
ZW
5494struct asm_shift_name
5495{
5496 const char *name;
5497 enum shift_kind kind;
5498};
b99bd4ef 5499
c19d1205
ZW
5500/* Third argument to parse_shift. */
5501enum parse_shift_mode
5502{
5503 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5504 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5505 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5506 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5507 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5508 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5509};
b99bd4ef 5510
c19d1205
ZW
5511/* Parse a <shift> specifier on an ARM data processing instruction.
5512 This has three forms:
b99bd4ef 5513
c19d1205
ZW
5514 (LSL|LSR|ASL|ASR|ROR) Rs
5515 (LSL|LSR|ASL|ASR|ROR) #imm
5516 RRX
b99bd4ef 5517
c19d1205
ZW
5518 Note that ASL is assimilated to LSL in the instruction encoding, and
5519 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5520
c19d1205
ZW
5521static int
5522parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5523{
c19d1205
ZW
5524 const struct asm_shift_name *shift_name;
5525 enum shift_kind shift;
5526 char *s = *str;
5527 char *p = s;
5528 int reg;
b99bd4ef 5529
c19d1205
ZW
5530 for (p = *str; ISALPHA (*p); p++)
5531 ;
b99bd4ef 5532
c19d1205 5533 if (p == *str)
b99bd4ef 5534 {
c19d1205
ZW
5535 inst.error = _("shift expression expected");
5536 return FAIL;
b99bd4ef
NC
5537 }
5538
21d799b5 5539 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5540 p - *str);
c19d1205
ZW
5541
5542 if (shift_name == NULL)
b99bd4ef 5543 {
c19d1205
ZW
5544 inst.error = _("shift expression expected");
5545 return FAIL;
b99bd4ef
NC
5546 }
5547
c19d1205 5548 shift = shift_name->kind;
b99bd4ef 5549
c19d1205
ZW
5550 switch (mode)
5551 {
5552 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5553 case SHIFT_IMMEDIATE:
5554 if (shift == SHIFT_UXTW)
5555 {
5556 inst.error = _("'UXTW' not allowed here");
5557 return FAIL;
5558 }
5559 break;
b99bd4ef 5560
c19d1205
ZW
5561 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5562 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5563 {
5564 inst.error = _("'LSL' or 'ASR' required");
5565 return FAIL;
5566 }
5567 break;
b99bd4ef 5568
c19d1205
ZW
5569 case SHIFT_LSL_IMMEDIATE:
5570 if (shift != SHIFT_LSL)
5571 {
5572 inst.error = _("'LSL' required");
5573 return FAIL;
5574 }
5575 break;
b99bd4ef 5576
c19d1205
ZW
5577 case SHIFT_ASR_IMMEDIATE:
5578 if (shift != SHIFT_ASR)
5579 {
5580 inst.error = _("'ASR' required");
5581 return FAIL;
5582 }
5583 break;
f5f10c66
AV
5584 case SHIFT_UXTW_IMMEDIATE:
5585 if (shift != SHIFT_UXTW)
5586 {
5587 inst.error = _("'UXTW' required");
5588 return FAIL;
5589 }
5590 break;
b99bd4ef 5591
c19d1205
ZW
5592 default: abort ();
5593 }
b99bd4ef 5594
c19d1205
ZW
5595 if (shift != SHIFT_RRX)
5596 {
5597 /* Whitespace can appear here if the next thing is a bare digit. */
5598 skip_whitespace (p);
b99bd4ef 5599
c19d1205 5600 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5601 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5602 {
5603 inst.operands[i].imm = reg;
5604 inst.operands[i].immisreg = 1;
5605 }
e2b0ab59 5606 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5607 return FAIL;
5608 }
5609 inst.operands[i].shift_kind = shift;
5610 inst.operands[i].shifted = 1;
5611 *str = p;
5612 return SUCCESS;
b99bd4ef
NC
5613}
5614
c19d1205 5615/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5616
c19d1205
ZW
5617 #<immediate>
5618 #<immediate>, <rotate>
5619 <Rm>
5620 <Rm>, <shift>
b99bd4ef 5621
c19d1205
ZW
5622 where <shift> is defined by parse_shift above, and <rotate> is a
5623 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5624 is deferred to md_apply_fix. */
b99bd4ef 5625
c19d1205
ZW
5626static int
5627parse_shifter_operand (char **str, int i)
5628{
5629 int value;
91d6fa6a 5630 expressionS exp;
b99bd4ef 5631
dcbf9037 5632 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5633 {
5634 inst.operands[i].reg = value;
5635 inst.operands[i].isreg = 1;
b99bd4ef 5636
c19d1205 5637 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5638 inst.relocs[0].exp.X_op = O_constant;
5639 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5640
c19d1205
ZW
5641 if (skip_past_comma (str) == FAIL)
5642 return SUCCESS;
b99bd4ef 5643
c19d1205
ZW
5644 /* Shift operation on register. */
5645 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5646 }
5647
e2b0ab59 5648 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5649 return FAIL;
b99bd4ef 5650
c19d1205 5651 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5652 {
c19d1205 5653 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5654 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5655 return FAIL;
b99bd4ef 5656
e2b0ab59 5657 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5658 {
5659 inst.error = _("constant expression expected");
5660 return FAIL;
5661 }
b99bd4ef 5662
91d6fa6a 5663 value = exp.X_add_number;
c19d1205
ZW
5664 if (value < 0 || value > 30 || value % 2 != 0)
5665 {
5666 inst.error = _("invalid rotation");
5667 return FAIL;
5668 }
e2b0ab59
AV
5669 if (inst.relocs[0].exp.X_add_number < 0
5670 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5671 {
5672 inst.error = _("invalid constant");
5673 return FAIL;
5674 }
09d92015 5675
a415b1cd 5676 /* Encode as specified. */
e2b0ab59 5677 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5678 return SUCCESS;
09d92015
MM
5679 }
5680
e2b0ab59
AV
5681 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5682 inst.relocs[0].pc_rel = 0;
c19d1205 5683 return SUCCESS;
09d92015
MM
5684}
5685
4962c51a
MS
5686/* Group relocation information. Each entry in the table contains the
5687 textual name of the relocation as may appear in assembler source
5688 and must end with a colon.
5689 Along with this textual name are the relocation codes to be used if
5690 the corresponding instruction is an ALU instruction (ADD or SUB only),
5691 an LDR, an LDRS, or an LDC. */
5692
5693struct group_reloc_table_entry
5694{
5695 const char *name;
5696 int alu_code;
5697 int ldr_code;
5698 int ldrs_code;
5699 int ldc_code;
5700};
5701
5702typedef enum
5703{
5704 /* Varieties of non-ALU group relocation. */
5705
5706 GROUP_LDR,
5707 GROUP_LDRS,
35c228db
AV
5708 GROUP_LDC,
5709 GROUP_MVE
4962c51a
MS
5710} group_reloc_type;
5711
5712static struct group_reloc_table_entry group_reloc_table[] =
5713 { /* Program counter relative: */
5714 { "pc_g0_nc",
5715 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5716 0, /* LDR */
5717 0, /* LDRS */
5718 0 }, /* LDC */
5719 { "pc_g0",
5720 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5721 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5722 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5723 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5724 { "pc_g1_nc",
5725 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5726 0, /* LDR */
5727 0, /* LDRS */
5728 0 }, /* LDC */
5729 { "pc_g1",
5730 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5731 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5732 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5733 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5734 { "pc_g2",
5735 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5736 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5737 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5738 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5739 /* Section base relative */
5740 { "sb_g0_nc",
5741 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5742 0, /* LDR */
5743 0, /* LDRS */
5744 0 }, /* LDC */
5745 { "sb_g0",
5746 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5747 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5748 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5749 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5750 { "sb_g1_nc",
5751 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5752 0, /* LDR */
5753 0, /* LDRS */
5754 0 }, /* LDC */
5755 { "sb_g1",
5756 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5757 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5758 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5759 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5760 { "sb_g2",
5761 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5762 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5763 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5764 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5765 /* Absolute thumb alu relocations. */
5766 { "lower0_7",
5767 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5768 0, /* LDR. */
5769 0, /* LDRS. */
5770 0 }, /* LDC. */
5771 { "lower8_15",
5772 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5773 0, /* LDR. */
5774 0, /* LDRS. */
5775 0 }, /* LDC. */
5776 { "upper0_7",
5777 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5778 0, /* LDR. */
5779 0, /* LDRS. */
5780 0 }, /* LDC. */
5781 { "upper8_15",
5782 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5783 0, /* LDR. */
5784 0, /* LDRS. */
5785 0 } }; /* LDC. */
4962c51a
MS
5786
5787/* Given the address of a pointer pointing to the textual name of a group
5788 relocation as may appear in assembler source, attempt to find its details
5789 in group_reloc_table. The pointer will be updated to the character after
5790 the trailing colon. On failure, FAIL will be returned; SUCCESS
5791 otherwise. On success, *entry will be updated to point at the relevant
5792 group_reloc_table entry. */
5793
5794static int
5795find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5796{
5797 unsigned int i;
5798 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5799 {
5800 int length = strlen (group_reloc_table[i].name);
5801
5f4273c7
NC
5802 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5803 && (*str)[length] == ':')
477330fc
RM
5804 {
5805 *out = &group_reloc_table[i];
5806 *str += (length + 1);
5807 return SUCCESS;
5808 }
4962c51a
MS
5809 }
5810
5811 return FAIL;
5812}
5813
5814/* Parse a <shifter_operand> for an ARM data processing instruction
5815 (as for parse_shifter_operand) where group relocations are allowed:
5816
5817 #<immediate>
5818 #<immediate>, <rotate>
5819 #:<group_reloc>:<expression>
5820 <Rm>
5821 <Rm>, <shift>
5822
5823 where <group_reloc> is one of the strings defined in group_reloc_table.
5824 The hashes are optional.
5825
5826 Everything else is as for parse_shifter_operand. */
5827
5828static parse_operand_result
5829parse_shifter_operand_group_reloc (char **str, int i)
5830{
5831 /* Determine if we have the sequence of characters #: or just :
5832 coming next. If we do, then we check for a group relocation.
5833 If we don't, punt the whole lot to parse_shifter_operand. */
5834
5835 if (((*str)[0] == '#' && (*str)[1] == ':')
5836 || (*str)[0] == ':')
5837 {
5838 struct group_reloc_table_entry *entry;
5839
5840 if ((*str)[0] == '#')
477330fc 5841 (*str) += 2;
4962c51a 5842 else
477330fc 5843 (*str)++;
4962c51a
MS
5844
5845 /* Try to parse a group relocation. Anything else is an error. */
5846 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5847 {
5848 inst.error = _("unknown group relocation");
5849 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5850 }
4962c51a
MS
5851
5852 /* We now have the group relocation table entry corresponding to
477330fc 5853 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5854 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5855 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5856
5857 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5858 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5859 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5860
5861 return PARSE_OPERAND_SUCCESS;
5862 }
5863 else
5864 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5865 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5866
5867 /* Never reached. */
5868}
5869
8e560766
MGD
5870/* Parse a Neon alignment expression. Information is written to
5871 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5872
8e560766
MGD
5873 align .imm = align << 8, .immisalign=1, .preind=0 */
5874static parse_operand_result
5875parse_neon_alignment (char **str, int i)
5876{
5877 char *p = *str;
5878 expressionS exp;
5879
5880 my_get_expression (&exp, &p, GE_NO_PREFIX);
5881
5882 if (exp.X_op != O_constant)
5883 {
5884 inst.error = _("alignment must be constant");
5885 return PARSE_OPERAND_FAIL;
5886 }
5887
5888 inst.operands[i].imm = exp.X_add_number << 8;
5889 inst.operands[i].immisalign = 1;
5890 /* Alignments are not pre-indexes. */
5891 inst.operands[i].preind = 0;
5892
5893 *str = p;
5894 return PARSE_OPERAND_SUCCESS;
5895}
5896
c19d1205 5897/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5898 to inst.operands[i] and/or inst.relocs[0].
09d92015 5899
c19d1205 5900 Preindexed addressing (.preind=1):
09d92015 5901
e2b0ab59 5902 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5903 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5904 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5905 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5906
c19d1205 5907 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5908
c19d1205 5909 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5910
e2b0ab59 5911 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5912 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5913 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5914 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5915
c19d1205 5916 Unindexed addressing (.preind=0, .postind=0):
09d92015 5917
c19d1205 5918 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5919
c19d1205 5920 Other:
09d92015 5921
c19d1205 5922 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5923 =immediate .isreg=0 .relocs[0].exp=immediate
5924 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5925
c19d1205 5926 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5927 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5928
4962c51a
MS
5929static parse_operand_result
5930parse_address_main (char **str, int i, int group_relocations,
477330fc 5931 group_reloc_type group_type)
09d92015 5932{
c19d1205
ZW
5933 char *p = *str;
5934 int reg;
09d92015 5935
c19d1205 5936 if (skip_past_char (&p, '[') == FAIL)
09d92015 5937 {
c19d1205
ZW
5938 if (skip_past_char (&p, '=') == FAIL)
5939 {
974da60d 5940 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5941 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5942 inst.operands[i].reg = REG_PC;
5943 inst.operands[i].isreg = 1;
5944 inst.operands[i].preind = 1;
09d92015 5945
e2b0ab59 5946 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5947 return PARSE_OPERAND_FAIL;
5948 }
e2b0ab59 5949 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5950 /*allow_symbol_p=*/TRUE))
4962c51a 5951 return PARSE_OPERAND_FAIL;
09d92015 5952
c19d1205 5953 *str = p;
4962c51a 5954 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5955 }
5956
8ab8155f
NC
5957 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5958 skip_whitespace (p);
5959
f5f10c66
AV
5960 if (group_type == GROUP_MVE)
5961 {
5962 enum arm_reg_type rtype = REG_TYPE_MQ;
5963 struct neon_type_el et;
5964 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5965 {
5966 inst.operands[i].isquad = 1;
5967 }
5968 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5969 {
5970 inst.error = BAD_ADDR_MODE;
5971 return PARSE_OPERAND_FAIL;
5972 }
5973 }
5974 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5975 {
35c228db
AV
5976 if (group_type == GROUP_MVE)
5977 inst.error = BAD_ADDR_MODE;
5978 else
5979 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5980 return PARSE_OPERAND_FAIL;
09d92015 5981 }
c19d1205
ZW
5982 inst.operands[i].reg = reg;
5983 inst.operands[i].isreg = 1;
09d92015 5984
c19d1205 5985 if (skip_past_comma (&p) == SUCCESS)
09d92015 5986 {
c19d1205 5987 inst.operands[i].preind = 1;
09d92015 5988
c19d1205
ZW
5989 if (*p == '+') p++;
5990 else if (*p == '-') p++, inst.operands[i].negative = 1;
5991
f5f10c66
AV
5992 enum arm_reg_type rtype = REG_TYPE_MQ;
5993 struct neon_type_el et;
5994 if (group_type == GROUP_MVE
5995 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5996 {
5997 inst.operands[i].immisreg = 2;
5998 inst.operands[i].imm = reg;
5999
6000 if (skip_past_comma (&p) == SUCCESS)
6001 {
6002 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6003 {
6004 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6005 inst.relocs[0].exp.X_add_number = 0;
6006 }
6007 else
6008 return PARSE_OPERAND_FAIL;
6009 }
6010 }
6011 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 6012 {
c19d1205
ZW
6013 inst.operands[i].imm = reg;
6014 inst.operands[i].immisreg = 1;
6015
6016 if (skip_past_comma (&p) == SUCCESS)
6017 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6018 return PARSE_OPERAND_FAIL;
c19d1205 6019 }
5287ad62 6020 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
6021 {
6022 /* FIXME: '@' should be used here, but it's filtered out by generic
6023 code before we get to see it here. This may be subject to
6024 change. */
6025 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6026
8e560766
MGD
6027 if (result != PARSE_OPERAND_SUCCESS)
6028 return result;
6029 }
c19d1205
ZW
6030 else
6031 {
6032 if (inst.operands[i].negative)
6033 {
6034 inst.operands[i].negative = 0;
6035 p--;
6036 }
4962c51a 6037
5f4273c7
NC
6038 if (group_relocations
6039 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
6040 {
6041 struct group_reloc_table_entry *entry;
6042
477330fc
RM
6043 /* Skip over the #: or : sequence. */
6044 if (*p == '#')
6045 p += 2;
6046 else
6047 p++;
4962c51a
MS
6048
6049 /* Try to parse a group relocation. Anything else is an
477330fc 6050 error. */
4962c51a
MS
6051 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6052 {
6053 inst.error = _("unknown group relocation");
6054 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6055 }
6056
6057 /* We now have the group relocation table entry corresponding to
6058 the name in the assembler source. Next, we parse the
477330fc 6059 expression. */
e2b0ab59 6060 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
6061 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6062
6063 /* Record the relocation type. */
477330fc
RM
6064 switch (group_type)
6065 {
6066 case GROUP_LDR:
e2b0ab59
AV
6067 inst.relocs[0].type
6068 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 6069 break;
4962c51a 6070
477330fc 6071 case GROUP_LDRS:
e2b0ab59
AV
6072 inst.relocs[0].type
6073 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 6074 break;
4962c51a 6075
477330fc 6076 case GROUP_LDC:
e2b0ab59
AV
6077 inst.relocs[0].type
6078 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 6079 break;
4962c51a 6080
477330fc
RM
6081 default:
6082 gas_assert (0);
6083 }
4962c51a 6084
e2b0ab59 6085 if (inst.relocs[0].type == 0)
4962c51a
MS
6086 {
6087 inst.error = _("this group relocation is not allowed on this instruction");
6088 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6089 }
477330fc
RM
6090 }
6091 else
26d97720
NS
6092 {
6093 char *q = p;
0198d5e6 6094
e2b0ab59 6095 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
6096 return PARSE_OPERAND_FAIL;
6097 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6098 if (inst.relocs[0].exp.X_op == O_constant
6099 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6100 {
6101 skip_whitespace (q);
6102 if (*q == '#')
6103 {
6104 q++;
6105 skip_whitespace (q);
6106 }
6107 if (*q == '-')
6108 inst.operands[i].negative = 1;
6109 }
6110 }
09d92015
MM
6111 }
6112 }
8e560766
MGD
6113 else if (skip_past_char (&p, ':') == SUCCESS)
6114 {
6115 /* FIXME: '@' should be used here, but it's filtered out by generic code
6116 before we get to see it here. This may be subject to change. */
6117 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6118
8e560766
MGD
6119 if (result != PARSE_OPERAND_SUCCESS)
6120 return result;
6121 }
09d92015 6122
c19d1205 6123 if (skip_past_char (&p, ']') == FAIL)
09d92015 6124 {
c19d1205 6125 inst.error = _("']' expected");
4962c51a 6126 return PARSE_OPERAND_FAIL;
09d92015
MM
6127 }
6128
c19d1205
ZW
6129 if (skip_past_char (&p, '!') == SUCCESS)
6130 inst.operands[i].writeback = 1;
09d92015 6131
c19d1205 6132 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6133 {
c19d1205
ZW
6134 if (skip_past_char (&p, '{') == SUCCESS)
6135 {
6136 /* [Rn], {expr} - unindexed, with option */
6137 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6138 0, 255, TRUE) == FAIL)
4962c51a 6139 return PARSE_OPERAND_FAIL;
09d92015 6140
c19d1205
ZW
6141 if (skip_past_char (&p, '}') == FAIL)
6142 {
6143 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6144 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6145 }
6146 if (inst.operands[i].preind)
6147 {
6148 inst.error = _("cannot combine index with option");
4962c51a 6149 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6150 }
6151 *str = p;
4962c51a 6152 return PARSE_OPERAND_SUCCESS;
09d92015 6153 }
c19d1205
ZW
6154 else
6155 {
6156 inst.operands[i].postind = 1;
6157 inst.operands[i].writeback = 1;
09d92015 6158
c19d1205
ZW
6159 if (inst.operands[i].preind)
6160 {
6161 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6162 return PARSE_OPERAND_FAIL;
c19d1205 6163 }
09d92015 6164
c19d1205
ZW
6165 if (*p == '+') p++;
6166 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6167
f5f10c66
AV
6168 enum arm_reg_type rtype = REG_TYPE_MQ;
6169 struct neon_type_el et;
6170 if (group_type == GROUP_MVE
6171 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6172 {
6173 inst.operands[i].immisreg = 2;
6174 inst.operands[i].imm = reg;
6175 }
6176 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6177 {
477330fc
RM
6178 /* We might be using the immediate for alignment already. If we
6179 are, OR the register number into the low-order bits. */
6180 if (inst.operands[i].immisalign)
6181 inst.operands[i].imm |= reg;
6182 else
6183 inst.operands[i].imm = reg;
c19d1205 6184 inst.operands[i].immisreg = 1;
a737bd4d 6185
c19d1205
ZW
6186 if (skip_past_comma (&p) == SUCCESS)
6187 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6188 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6189 }
6190 else
6191 {
26d97720 6192 char *q = p;
0198d5e6 6193
c19d1205
ZW
6194 if (inst.operands[i].negative)
6195 {
6196 inst.operands[i].negative = 0;
6197 p--;
6198 }
e2b0ab59 6199 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6200 return PARSE_OPERAND_FAIL;
26d97720 6201 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6202 if (inst.relocs[0].exp.X_op == O_constant
6203 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6204 {
6205 skip_whitespace (q);
6206 if (*q == '#')
6207 {
6208 q++;
6209 skip_whitespace (q);
6210 }
6211 if (*q == '-')
6212 inst.operands[i].negative = 1;
6213 }
c19d1205
ZW
6214 }
6215 }
a737bd4d
NC
6216 }
6217
c19d1205
ZW
6218 /* If at this point neither .preind nor .postind is set, we have a
6219 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6220 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6221 {
6222 inst.operands[i].preind = 1;
e2b0ab59
AV
6223 inst.relocs[0].exp.X_op = O_constant;
6224 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6225 }
6226 *str = p;
4962c51a
MS
6227 return PARSE_OPERAND_SUCCESS;
6228}
6229
6230static int
6231parse_address (char **str, int i)
6232{
21d799b5 6233 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6234 ? SUCCESS : FAIL;
4962c51a
MS
6235}
6236
6237static parse_operand_result
6238parse_address_group_reloc (char **str, int i, group_reloc_type type)
6239{
6240 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6241}
6242
b6895b4f
PB
6243/* Parse an operand for a MOVW or MOVT instruction. */
6244static int
6245parse_half (char **str)
6246{
6247 char * p;
5f4273c7 6248
b6895b4f
PB
6249 p = *str;
6250 skip_past_char (&p, '#');
5f4273c7 6251 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6252 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6253 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6254 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6255
e2b0ab59 6256 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6257 {
6258 p += 9;
5f4273c7 6259 skip_whitespace (p);
b6895b4f
PB
6260 }
6261
e2b0ab59 6262 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6263 return FAIL;
6264
e2b0ab59 6265 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6266 {
e2b0ab59 6267 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6268 {
6269 inst.error = _("constant expression expected");
6270 return FAIL;
6271 }
e2b0ab59
AV
6272 if (inst.relocs[0].exp.X_add_number < 0
6273 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6274 {
6275 inst.error = _("immediate value out of range");
6276 return FAIL;
6277 }
6278 }
6279 *str = p;
6280 return SUCCESS;
6281}
6282
c19d1205 6283/* Miscellaneous. */
a737bd4d 6284
c19d1205
ZW
6285/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6286 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6287static int
d2cd1205 6288parse_psr (char **str, bfd_boolean lhs)
09d92015 6289{
c19d1205
ZW
6290 char *p;
6291 unsigned long psr_field;
62b3e311
PB
6292 const struct asm_psr *psr;
6293 char *start;
d2cd1205 6294 bfd_boolean is_apsr = FALSE;
ac7f631b 6295 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6296
a4482bb6
NC
6297 /* PR gas/12698: If the user has specified -march=all then m_profile will
6298 be TRUE, but we want to ignore it in this case as we are building for any
6299 CPU type, including non-m variants. */
823d2571 6300 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6301 m_profile = FALSE;
6302
c19d1205
ZW
6303 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6304 feature for ease of use and backwards compatibility. */
6305 p = *str;
62b3e311 6306 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6307 {
6308 if (m_profile)
6309 goto unsupported_psr;
fa94de6b 6310
d2cd1205
JB
6311 psr_field = SPSR_BIT;
6312 }
6313 else if (strncasecmp (p, "CPSR", 4) == 0)
6314 {
6315 if (m_profile)
6316 goto unsupported_psr;
6317
6318 psr_field = 0;
6319 }
6320 else if (strncasecmp (p, "APSR", 4) == 0)
6321 {
6322 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6323 and ARMv7-R architecture CPUs. */
6324 is_apsr = TRUE;
6325 psr_field = 0;
6326 }
6327 else if (m_profile)
62b3e311
PB
6328 {
6329 start = p;
6330 do
6331 p++;
6332 while (ISALNUM (*p) || *p == '_');
6333
d2cd1205
JB
6334 if (strncasecmp (start, "iapsr", 5) == 0
6335 || strncasecmp (start, "eapsr", 5) == 0
6336 || strncasecmp (start, "xpsr", 4) == 0
6337 || strncasecmp (start, "psr", 3) == 0)
6338 p = start + strcspn (start, "rR") + 1;
6339
21d799b5 6340 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6341 p - start);
d2cd1205 6342
62b3e311
PB
6343 if (!psr)
6344 return FAIL;
09d92015 6345
d2cd1205
JB
6346 /* If APSR is being written, a bitfield may be specified. Note that
6347 APSR itself is handled above. */
6348 if (psr->field <= 3)
6349 {
6350 psr_field = psr->field;
6351 is_apsr = TRUE;
6352 goto check_suffix;
6353 }
6354
62b3e311 6355 *str = p;
d2cd1205
JB
6356 /* M-profile MSR instructions have the mask field set to "10", except
6357 *PSR variants which modify APSR, which may use a different mask (and
6358 have been handled already). Do that by setting the PSR_f field
6359 here. */
6360 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6361 }
d2cd1205
JB
6362 else
6363 goto unsupported_psr;
09d92015 6364
62b3e311 6365 p += 4;
d2cd1205 6366check_suffix:
c19d1205
ZW
6367 if (*p == '_')
6368 {
6369 /* A suffix follows. */
c19d1205
ZW
6370 p++;
6371 start = p;
a737bd4d 6372
c19d1205
ZW
6373 do
6374 p++;
6375 while (ISALNUM (*p) || *p == '_');
a737bd4d 6376
d2cd1205
JB
6377 if (is_apsr)
6378 {
6379 /* APSR uses a notation for bits, rather than fields. */
6380 unsigned int nzcvq_bits = 0;
6381 unsigned int g_bit = 0;
6382 char *bit;
fa94de6b 6383
d2cd1205
JB
6384 for (bit = start; bit != p; bit++)
6385 {
6386 switch (TOLOWER (*bit))
477330fc 6387 {
d2cd1205
JB
6388 case 'n':
6389 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6390 break;
6391
6392 case 'z':
6393 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6394 break;
6395
6396 case 'c':
6397 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6398 break;
6399
6400 case 'v':
6401 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6402 break;
fa94de6b 6403
d2cd1205
JB
6404 case 'q':
6405 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6406 break;
fa94de6b 6407
d2cd1205
JB
6408 case 'g':
6409 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6410 break;
fa94de6b 6411
d2cd1205
JB
6412 default:
6413 inst.error = _("unexpected bit specified after APSR");
6414 return FAIL;
6415 }
6416 }
fa94de6b 6417
d2cd1205
JB
6418 if (nzcvq_bits == 0x1f)
6419 psr_field |= PSR_f;
fa94de6b 6420
d2cd1205
JB
6421 if (g_bit == 0x1)
6422 {
6423 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6424 {
d2cd1205
JB
6425 inst.error = _("selected processor does not "
6426 "support DSP extension");
6427 return FAIL;
6428 }
6429
6430 psr_field |= PSR_s;
6431 }
fa94de6b 6432
d2cd1205
JB
6433 if ((nzcvq_bits & 0x20) != 0
6434 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6435 || (g_bit & 0x2) != 0)
6436 {
6437 inst.error = _("bad bitmask specified after APSR");
6438 return FAIL;
6439 }
6440 }
6441 else
477330fc 6442 {
d2cd1205 6443 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6444 p - start);
d2cd1205 6445 if (!psr)
477330fc 6446 goto error;
a737bd4d 6447
d2cd1205
JB
6448 psr_field |= psr->field;
6449 }
a737bd4d 6450 }
c19d1205 6451 else
a737bd4d 6452 {
c19d1205
ZW
6453 if (ISALNUM (*p))
6454 goto error; /* Garbage after "[CS]PSR". */
6455
d2cd1205 6456 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6457 is deprecated, but allow it anyway. */
d2cd1205
JB
6458 if (is_apsr && lhs)
6459 {
6460 psr_field |= PSR_f;
6461 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6462 "deprecated"));
6463 }
6464 else if (!m_profile)
6465 /* These bits are never right for M-profile devices: don't set them
6466 (only code paths which read/write APSR reach here). */
6467 psr_field |= (PSR_c | PSR_f);
a737bd4d 6468 }
c19d1205
ZW
6469 *str = p;
6470 return psr_field;
a737bd4d 6471
d2cd1205
JB
6472 unsupported_psr:
6473 inst.error = _("selected processor does not support requested special "
6474 "purpose register");
6475 return FAIL;
6476
c19d1205
ZW
6477 error:
6478 inst.error = _("flag for {c}psr instruction expected");
6479 return FAIL;
a737bd4d
NC
6480}
6481
32c36c3c
AV
6482static int
6483parse_sys_vldr_vstr (char **str)
6484{
6485 unsigned i;
6486 int val = FAIL;
6487 struct {
6488 const char *name;
6489 int regl;
6490 int regh;
6491 } sysregs[] = {
6492 {"FPSCR", 0x1, 0x0},
6493 {"FPSCR_nzcvqc", 0x2, 0x0},
6494 {"VPR", 0x4, 0x1},
6495 {"P0", 0x5, 0x1},
6496 {"FPCXTNS", 0x6, 0x1},
6497 {"FPCXTS", 0x7, 0x1}
6498 };
6499 char *op_end = strchr (*str, ',');
6500 size_t op_strlen = op_end - *str;
6501
6502 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6503 {
6504 if (!strncmp (*str, sysregs[i].name, op_strlen))
6505 {
6506 val = sysregs[i].regl | (sysregs[i].regh << 3);
6507 *str = op_end;
6508 break;
6509 }
6510 }
6511
6512 return val;
6513}
6514
c19d1205
ZW
6515/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6516 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6517
c19d1205
ZW
6518static int
6519parse_cps_flags (char **str)
a737bd4d 6520{
c19d1205
ZW
6521 int val = 0;
6522 int saw_a_flag = 0;
6523 char *s = *str;
a737bd4d 6524
c19d1205
ZW
6525 for (;;)
6526 switch (*s++)
6527 {
6528 case '\0': case ',':
6529 goto done;
a737bd4d 6530
c19d1205
ZW
6531 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6532 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6533 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6534
c19d1205
ZW
6535 default:
6536 inst.error = _("unrecognized CPS flag");
6537 return FAIL;
6538 }
a737bd4d 6539
c19d1205
ZW
6540 done:
6541 if (saw_a_flag == 0)
a737bd4d 6542 {
c19d1205
ZW
6543 inst.error = _("missing CPS flags");
6544 return FAIL;
a737bd4d 6545 }
a737bd4d 6546
c19d1205
ZW
6547 *str = s - 1;
6548 return val;
a737bd4d
NC
6549}
6550
c19d1205
ZW
6551/* Parse an endian specifier ("BE" or "LE", case insensitive);
6552 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6553
6554static int
c19d1205 6555parse_endian_specifier (char **str)
a737bd4d 6556{
c19d1205
ZW
6557 int little_endian;
6558 char *s = *str;
a737bd4d 6559
c19d1205
ZW
6560 if (strncasecmp (s, "BE", 2))
6561 little_endian = 0;
6562 else if (strncasecmp (s, "LE", 2))
6563 little_endian = 1;
6564 else
a737bd4d 6565 {
c19d1205 6566 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6567 return FAIL;
6568 }
6569
c19d1205 6570 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6571 {
c19d1205 6572 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6573 return FAIL;
6574 }
6575
c19d1205
ZW
6576 *str = s + 2;
6577 return little_endian;
6578}
a737bd4d 6579
c19d1205
ZW
6580/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6581 value suitable for poking into the rotate field of an sxt or sxta
6582 instruction, or FAIL on error. */
6583
6584static int
6585parse_ror (char **str)
6586{
6587 int rot;
6588 char *s = *str;
6589
6590 if (strncasecmp (s, "ROR", 3) == 0)
6591 s += 3;
6592 else
a737bd4d 6593 {
c19d1205 6594 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6595 return FAIL;
6596 }
c19d1205
ZW
6597
6598 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6599 return FAIL;
6600
6601 switch (rot)
a737bd4d 6602 {
c19d1205
ZW
6603 case 0: *str = s; return 0x0;
6604 case 8: *str = s; return 0x1;
6605 case 16: *str = s; return 0x2;
6606 case 24: *str = s; return 0x3;
6607
6608 default:
6609 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6610 return FAIL;
6611 }
c19d1205 6612}
a737bd4d 6613
c19d1205
ZW
6614/* Parse a conditional code (from conds[] below). The value returned is in the
6615 range 0 .. 14, or FAIL. */
6616static int
6617parse_cond (char **str)
6618{
c462b453 6619 char *q;
c19d1205 6620 const struct asm_cond *c;
c462b453
PB
6621 int n;
6622 /* Condition codes are always 2 characters, so matching up to
6623 3 characters is sufficient. */
6624 char cond[3];
a737bd4d 6625
c462b453
PB
6626 q = *str;
6627 n = 0;
6628 while (ISALPHA (*q) && n < 3)
6629 {
e07e6e58 6630 cond[n] = TOLOWER (*q);
c462b453
PB
6631 q++;
6632 n++;
6633 }
a737bd4d 6634
21d799b5 6635 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6636 if (!c)
a737bd4d 6637 {
c19d1205 6638 inst.error = _("condition required");
a737bd4d
NC
6639 return FAIL;
6640 }
6641
c19d1205
ZW
6642 *str = q;
6643 return c->value;
6644}
6645
62b3e311
PB
6646/* Parse an option for a barrier instruction. Returns the encoding for the
6647 option, or FAIL. */
6648static int
6649parse_barrier (char **str)
6650{
6651 char *p, *q;
6652 const struct asm_barrier_opt *o;
6653
6654 p = q = *str;
6655 while (ISALPHA (*q))
6656 q++;
6657
21d799b5 6658 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6659 q - p);
62b3e311
PB
6660 if (!o)
6661 return FAIL;
6662
e797f7e0
MGD
6663 if (!mark_feature_used (&o->arch))
6664 return FAIL;
6665
62b3e311
PB
6666 *str = q;
6667 return o->value;
6668}
6669
92e90b6e
PB
6670/* Parse the operands of a table branch instruction. Similar to a memory
6671 operand. */
6672static int
6673parse_tb (char **str)
6674{
6675 char * p = *str;
6676 int reg;
6677
6678 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6679 {
6680 inst.error = _("'[' expected");
6681 return FAIL;
6682 }
92e90b6e 6683
dcbf9037 6684 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6685 {
6686 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6687 return FAIL;
6688 }
6689 inst.operands[0].reg = reg;
6690
6691 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6692 {
6693 inst.error = _("',' expected");
6694 return FAIL;
6695 }
5f4273c7 6696
dcbf9037 6697 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6698 {
6699 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6700 return FAIL;
6701 }
6702 inst.operands[0].imm = reg;
6703
6704 if (skip_past_comma (&p) == SUCCESS)
6705 {
6706 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6707 return FAIL;
e2b0ab59 6708 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6709 {
6710 inst.error = _("invalid shift");
6711 return FAIL;
6712 }
6713 inst.operands[0].shifted = 1;
6714 }
6715
6716 if (skip_past_char (&p, ']') == FAIL)
6717 {
6718 inst.error = _("']' expected");
6719 return FAIL;
6720 }
6721 *str = p;
6722 return SUCCESS;
6723}
6724
5287ad62
JB
6725/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6726 information on the types the operands can take and how they are encoded.
037e8744
JB
6727 Up to four operands may be read; this function handles setting the
6728 ".present" field for each read operand itself.
5287ad62
JB
6729 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6730 else returns FAIL. */
6731
6732static int
6733parse_neon_mov (char **str, int *which_operand)
6734{
6735 int i = *which_operand, val;
6736 enum arm_reg_type rtype;
6737 char *ptr = *str;
dcbf9037 6738 struct neon_type_el optype;
5f4273c7 6739
57785aa2
AV
6740 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6741 {
6742 /* Cases 17 or 19. */
6743 inst.operands[i].reg = val;
6744 inst.operands[i].isvec = 1;
6745 inst.operands[i].isscalar = 2;
6746 inst.operands[i].vectype = optype;
6747 inst.operands[i++].present = 1;
6748
6749 if (skip_past_comma (&ptr) == FAIL)
6750 goto wanted_comma;
6751
6752 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6753 {
6754 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6755 inst.operands[i].reg = val;
6756 inst.operands[i].isreg = 1;
6757 inst.operands[i].present = 1;
6758 }
6759 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6760 {
6761 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6762 inst.operands[i].reg = val;
6763 inst.operands[i].isvec = 1;
6764 inst.operands[i].isscalar = 2;
6765 inst.operands[i].vectype = optype;
6766 inst.operands[i++].present = 1;
6767
6768 if (skip_past_comma (&ptr) == FAIL)
6769 goto wanted_comma;
6770
6771 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6772 goto wanted_arm;
6773
6774 inst.operands[i].reg = val;
6775 inst.operands[i].isreg = 1;
6776 inst.operands[i++].present = 1;
6777
6778 if (skip_past_comma (&ptr) == FAIL)
6779 goto wanted_comma;
6780
6781 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6782 goto wanted_arm;
6783
6784 inst.operands[i].reg = val;
6785 inst.operands[i].isreg = 1;
6786 inst.operands[i].present = 1;
6787 }
6788 else
6789 {
6790 first_error (_("expected ARM or MVE vector register"));
6791 return FAIL;
6792 }
6793 }
6794 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6795 {
6796 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6797 inst.operands[i].reg = val;
6798 inst.operands[i].isscalar = 1;
dcbf9037 6799 inst.operands[i].vectype = optype;
5287ad62
JB
6800 inst.operands[i++].present = 1;
6801
6802 if (skip_past_comma (&ptr) == FAIL)
477330fc 6803 goto wanted_comma;
5f4273c7 6804
dcbf9037 6805 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6806 goto wanted_arm;
5f4273c7 6807
5287ad62
JB
6808 inst.operands[i].reg = val;
6809 inst.operands[i].isreg = 1;
6810 inst.operands[i].present = 1;
6811 }
57785aa2
AV
6812 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6813 != FAIL)
6814 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6815 != FAIL))
5287ad62
JB
6816 {
6817 /* Cases 0, 1, 2, 3, 5 (D only). */
6818 if (skip_past_comma (&ptr) == FAIL)
477330fc 6819 goto wanted_comma;
5f4273c7 6820
5287ad62
JB
6821 inst.operands[i].reg = val;
6822 inst.operands[i].isreg = 1;
6823 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6824 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6825 inst.operands[i].isvec = 1;
dcbf9037 6826 inst.operands[i].vectype = optype;
5287ad62
JB
6827 inst.operands[i++].present = 1;
6828
dcbf9037 6829 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6830 {
6831 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6832 Case 13: VMOV <Sd>, <Rm> */
6833 inst.operands[i].reg = val;
6834 inst.operands[i].isreg = 1;
6835 inst.operands[i].present = 1;
6836
6837 if (rtype == REG_TYPE_NQ)
6838 {
6839 first_error (_("can't use Neon quad register here"));
6840 return FAIL;
6841 }
6842 else if (rtype != REG_TYPE_VFS)
6843 {
6844 i++;
6845 if (skip_past_comma (&ptr) == FAIL)
6846 goto wanted_comma;
6847 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6848 goto wanted_arm;
6849 inst.operands[i].reg = val;
6850 inst.operands[i].isreg = 1;
6851 inst.operands[i].present = 1;
6852 }
6853 }
c4a23bf8
SP
6854 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6855 &optype)) != FAIL)
6856 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6857 &optype)) != FAIL))
477330fc
RM
6858 {
6859 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6860 Case 1: VMOV<c><q> <Dd>, <Dm>
6861 Case 8: VMOV.F32 <Sd>, <Sm>
6862 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6863
6864 inst.operands[i].reg = val;
6865 inst.operands[i].isreg = 1;
6866 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6867 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6868 inst.operands[i].isvec = 1;
6869 inst.operands[i].vectype = optype;
6870 inst.operands[i].present = 1;
6871
6872 if (skip_past_comma (&ptr) == SUCCESS)
6873 {
6874 /* Case 15. */
6875 i++;
6876
6877 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6878 goto wanted_arm;
6879
6880 inst.operands[i].reg = val;
6881 inst.operands[i].isreg = 1;
6882 inst.operands[i++].present = 1;
6883
6884 if (skip_past_comma (&ptr) == FAIL)
6885 goto wanted_comma;
6886
6887 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6888 goto wanted_arm;
6889
6890 inst.operands[i].reg = val;
6891 inst.operands[i].isreg = 1;
6892 inst.operands[i].present = 1;
6893 }
6894 }
4641781c 6895 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6896 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6897 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6898 Case 10: VMOV.F32 <Sd>, #<imm>
6899 Case 11: VMOV.F64 <Dd>, #<imm> */
6900 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6901 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6902 == SUCCESS)
477330fc
RM
6903 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6904 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6905 ;
5287ad62 6906 else
477330fc
RM
6907 {
6908 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6909 return FAIL;
6910 }
5287ad62 6911 }
dcbf9037 6912 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6913 {
57785aa2 6914 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6915 inst.operands[i].reg = val;
6916 inst.operands[i].isreg = 1;
6917 inst.operands[i++].present = 1;
5f4273c7 6918
5287ad62 6919 if (skip_past_comma (&ptr) == FAIL)
477330fc 6920 goto wanted_comma;
5f4273c7 6921
57785aa2
AV
6922 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6923 {
6924 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6925 inst.operands[i].reg = val;
6926 inst.operands[i].isscalar = 2;
6927 inst.operands[i].present = 1;
6928 inst.operands[i].vectype = optype;
6929 }
6930 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6931 {
6932 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6933 inst.operands[i].reg = val;
6934 inst.operands[i].isscalar = 1;
6935 inst.operands[i].present = 1;
6936 inst.operands[i].vectype = optype;
6937 }
dcbf9037 6938 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6939 {
477330fc
RM
6940 inst.operands[i].reg = val;
6941 inst.operands[i].isreg = 1;
6942 inst.operands[i++].present = 1;
6943
6944 if (skip_past_comma (&ptr) == FAIL)
6945 goto wanted_comma;
6946
6947 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6948 != FAIL)
477330fc 6949 {
57785aa2 6950 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6951
477330fc
RM
6952 inst.operands[i].reg = val;
6953 inst.operands[i].isreg = 1;
6954 inst.operands[i].isvec = 1;
57785aa2 6955 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6956 inst.operands[i].vectype = optype;
6957 inst.operands[i].present = 1;
57785aa2
AV
6958
6959 if (rtype == REG_TYPE_VFS)
6960 {
6961 /* Case 14. */
6962 i++;
6963 if (skip_past_comma (&ptr) == FAIL)
6964 goto wanted_comma;
6965 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6966 &optype)) == FAIL)
6967 {
6968 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6969 return FAIL;
6970 }
6971 inst.operands[i].reg = val;
6972 inst.operands[i].isreg = 1;
6973 inst.operands[i].isvec = 1;
6974 inst.operands[i].issingle = 1;
6975 inst.operands[i].vectype = optype;
6976 inst.operands[i].present = 1;
6977 }
6978 }
6979 else
6980 {
6981 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6982 != FAIL)
6983 {
6984 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6985 inst.operands[i].reg = val;
6986 inst.operands[i].isvec = 1;
6987 inst.operands[i].isscalar = 2;
6988 inst.operands[i].vectype = optype;
6989 inst.operands[i++].present = 1;
6990
6991 if (skip_past_comma (&ptr) == FAIL)
6992 goto wanted_comma;
6993
6994 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6995 == FAIL)
6996 {
6997 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6998 return FAIL;
6999 }
7000 inst.operands[i].reg = val;
7001 inst.operands[i].isvec = 1;
7002 inst.operands[i].isscalar = 2;
7003 inst.operands[i].vectype = optype;
7004 inst.operands[i].present = 1;
7005 }
7006 else
7007 {
7008 first_error (_("VFP single, double or MVE vector register"
7009 " expected"));
7010 return FAIL;
7011 }
477330fc
RM
7012 }
7013 }
037e8744 7014 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
7015 != FAIL)
7016 {
7017 /* Case 13. */
7018 inst.operands[i].reg = val;
7019 inst.operands[i].isreg = 1;
7020 inst.operands[i].isvec = 1;
7021 inst.operands[i].issingle = 1;
7022 inst.operands[i].vectype = optype;
7023 inst.operands[i].present = 1;
7024 }
5287ad62
JB
7025 }
7026 else
7027 {
dcbf9037 7028 first_error (_("parse error"));
5287ad62
JB
7029 return FAIL;
7030 }
7031
7032 /* Successfully parsed the operands. Update args. */
7033 *which_operand = i;
7034 *str = ptr;
7035 return SUCCESS;
7036
5f4273c7 7037 wanted_comma:
dcbf9037 7038 first_error (_("expected comma"));
5287ad62 7039 return FAIL;
5f4273c7
NC
7040
7041 wanted_arm:
dcbf9037 7042 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 7043 return FAIL;
5287ad62
JB
7044}
7045
5be8be5d
DG
7046/* Use this macro when the operand constraints are different
7047 for ARM and THUMB (e.g. ldrd). */
7048#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7049 ((arm_operand) | ((thumb_operand) << 16))
7050
c19d1205
ZW
7051/* Matcher codes for parse_operands. */
7052enum operand_parse_code
7053{
7054 OP_stop, /* end of line */
7055
7056 OP_RR, /* ARM register */
7057 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 7058 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 7059 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 7060 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 7061 optional trailing ! */
c19d1205
ZW
7062 OP_RRw, /* ARM register, not r15, optional trailing ! */
7063 OP_RCP, /* Coprocessor number */
7064 OP_RCN, /* Coprocessor register */
7065 OP_RF, /* FPA register */
7066 OP_RVS, /* VFP single precision register */
5287ad62
JB
7067 OP_RVD, /* VFP double precision register (0..15) */
7068 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
7069 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7070 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7071 */
5287ad62 7072 OP_RNQ, /* Neon quad precision register */
5ee91343 7073 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 7074 OP_RVSD, /* VFP single or double precision register */
1b883319 7075 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 7076 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 7077 OP_RNSD, /* Neon single or double precision register */
5287ad62 7078 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 7079 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 7080 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 7081 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 7082 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
7083 OP_RVC, /* VFP control register */
7084 OP_RMF, /* Maverick F register */
7085 OP_RMD, /* Maverick D register */
7086 OP_RMFX, /* Maverick FX register */
7087 OP_RMDX, /* Maverick DX register */
7088 OP_RMAX, /* Maverick AX register */
7089 OP_RMDS, /* Maverick DSPSC register */
7090 OP_RIWR, /* iWMMXt wR register */
7091 OP_RIWC, /* iWMMXt wC register */
7092 OP_RIWG, /* iWMMXt wCG register */
7093 OP_RXA, /* XScale accumulator register */
7094
5ee91343
AV
7095 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7096 */
7097 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7098 GPR (no SP/SP) */
a302e574 7099 OP_RMQ, /* MVE vector register. */
1b883319 7100 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 7101 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 7102
60f993ce
AV
7103 /* New operands for Armv8.1-M Mainline. */
7104 OP_LR, /* ARM LR register */
a302e574
AV
7105 OP_RRe, /* ARM register, only even numbered. */
7106 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7107 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7108 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7109
c19d1205 7110 OP_REGLST, /* ARM register list */
4b5a202f 7111 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7112 OP_VRSLST, /* VFP single-precision register list */
7113 OP_VRDLST, /* VFP double-precision register list */
037e8744 7114 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7115 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7116 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7117 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7118 OP_MSTRLST2, /* MVE vector list with two elements. */
7119 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7120
5287ad62 7121 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7122 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7123 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7124 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7125 zero. */
5287ad62 7126 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7127 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7128 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7129 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7130 */
a8465a06
AV
7131 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7132 scalar, or ARM register. */
5287ad62 7133 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7134 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7135 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7136 register. */
5d281bf0 7137 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7138 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7139 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7140 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7141 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7142 OP_RNDQMQ_Ibig,
5287ad62 7143 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7144 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7145 ARM register. */
2d447fca 7146 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7147 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7148
7149 OP_I0, /* immediate zero */
c19d1205
ZW
7150 OP_I7, /* immediate value 0 .. 7 */
7151 OP_I15, /* 0 .. 15 */
7152 OP_I16, /* 1 .. 16 */
5287ad62 7153 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7154 OP_I31, /* 0 .. 31 */
7155 OP_I31w, /* 0 .. 31, optional trailing ! */
7156 OP_I32, /* 1 .. 32 */
5287ad62 7157 OP_I32z, /* 0 .. 32 */
08132bdd 7158 OP_I48_I64, /* 48 or 64 */
5287ad62 7159 OP_I63, /* 0 .. 63 */
c19d1205 7160 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7161 OP_I64, /* 1 .. 64 */
7162 OP_I64z, /* 0 .. 64 */
c19d1205 7163 OP_I255, /* 0 .. 255 */
4934a27c
MM
7164 OP_I511, /* 0 .. 511 */
7165 OP_I8191, /* 0 .. 8191 */
c19d1205
ZW
7166 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7167 OP_I7b, /* 0 .. 7 */
7168 OP_I15b, /* 0 .. 15 */
7169 OP_I31b, /* 0 .. 31 */
7170
7171 OP_SH, /* shifter operand */
4962c51a 7172 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7173 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7174 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7175 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7176 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7177 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7178 OP_EXP, /* arbitrary expression */
7179 OP_EXPi, /* same, with optional immediate prefix */
7180 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7181 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7182 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7183 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7184 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7185
7186 OP_CPSF, /* CPS flags */
7187 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7188 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7189 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7190 OP_COND, /* conditional code */
92e90b6e 7191 OP_TB, /* Table branch. */
c19d1205 7192
037e8744
JB
7193 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7194
c19d1205 7195 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7196 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7197 OP_RR_EXi, /* ARM register or expression with imm prefix */
7198 OP_RF_IF, /* FPA register or immediate */
7199 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7200 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7201
7202 /* Optional operands. */
7203 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7204 OP_oI31b, /* 0 .. 31 */
5287ad62 7205 OP_oI32b, /* 1 .. 32 */
5f1af56b 7206 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7207 OP_oIffffb, /* 0 .. 65535 */
7208 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7209
7210 OP_oRR, /* ARM register */
60f993ce 7211 OP_oLR, /* ARM LR register */
c19d1205 7212 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7213 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7214 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7215 OP_oRND, /* Optional Neon double precision register */
7216 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7217 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7218 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7219 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7220 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7221 register. */
c19d1205
ZW
7222 OP_oSHll, /* LSL immediate */
7223 OP_oSHar, /* ASR immediate */
7224 OP_oSHllar, /* LSL or ASR immediate */
7225 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7226 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7227
1b883319
AV
7228 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7229
5be8be5d
DG
7230 /* Some pre-defined mixed (ARM/THUMB) operands. */
7231 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7232 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7233 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7234
c19d1205
ZW
7235 OP_FIRST_OPTIONAL = OP_oI7b
7236};
a737bd4d 7237
c19d1205
ZW
7238/* Generic instruction operand parser. This does no encoding and no
7239 semantic validation; it merely squirrels values away in the inst
7240 structure. Returns SUCCESS or FAIL depending on whether the
7241 specified grammar matched. */
7242static int
5be8be5d 7243parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7244{
5be8be5d 7245 unsigned const int *upat = pattern;
c19d1205
ZW
7246 char *backtrack_pos = 0;
7247 const char *backtrack_error = 0;
99aad254 7248 int i, val = 0, backtrack_index = 0;
5287ad62 7249 enum arm_reg_type rtype;
4962c51a 7250 parse_operand_result result;
5be8be5d 7251 unsigned int op_parse_code;
efd6b359 7252 bfd_boolean partial_match;
c19d1205 7253
e07e6e58
NC
7254#define po_char_or_fail(chr) \
7255 do \
7256 { \
7257 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7258 goto bad_args; \
e07e6e58
NC
7259 } \
7260 while (0)
c19d1205 7261
e07e6e58
NC
7262#define po_reg_or_fail(regtype) \
7263 do \
dcbf9037 7264 { \
e07e6e58 7265 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7266 & inst.operands[i].vectype); \
e07e6e58 7267 if (val == FAIL) \
477330fc
RM
7268 { \
7269 first_error (_(reg_expected_msgs[regtype])); \
7270 goto failure; \
7271 } \
e07e6e58
NC
7272 inst.operands[i].reg = val; \
7273 inst.operands[i].isreg = 1; \
7274 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7275 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7276 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7277 || rtype == REG_TYPE_VFD \
7278 || rtype == REG_TYPE_NQ); \
1b883319 7279 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7280 } \
e07e6e58
NC
7281 while (0)
7282
7283#define po_reg_or_goto(regtype, label) \
7284 do \
7285 { \
7286 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7287 & inst.operands[i].vectype); \
7288 if (val == FAIL) \
7289 goto label; \
dcbf9037 7290 \
e07e6e58
NC
7291 inst.operands[i].reg = val; \
7292 inst.operands[i].isreg = 1; \
7293 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7294 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7295 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7296 || rtype == REG_TYPE_VFD \
e07e6e58 7297 || rtype == REG_TYPE_NQ); \
1b883319 7298 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7299 } \
7300 while (0)
7301
7302#define po_imm_or_fail(min, max, popt) \
7303 do \
7304 { \
7305 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7306 goto failure; \
7307 inst.operands[i].imm = val; \
7308 } \
7309 while (0)
7310
08132bdd
SP
7311#define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7312 do \
7313 { \
7314 expressionS exp; \
7315 my_get_expression (&exp, &str, popt); \
7316 if (exp.X_op != O_constant) \
7317 { \
7318 inst.error = _("constant expression required"); \
7319 goto failure; \
7320 } \
7321 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7322 { \
7323 inst.error = _("immediate value 48 or 64 expected"); \
7324 goto failure; \
7325 } \
7326 inst.operands[i].imm = exp.X_add_number; \
7327 } \
7328 while (0)
7329
57785aa2 7330#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7331 do \
7332 { \
57785aa2
AV
7333 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7334 reg_type); \
e07e6e58
NC
7335 if (val == FAIL) \
7336 goto label; \
7337 inst.operands[i].reg = val; \
7338 inst.operands[i].isscalar = 1; \
7339 } \
7340 while (0)
7341
7342#define po_misc_or_fail(expr) \
7343 do \
7344 { \
7345 if (expr) \
7346 goto failure; \
7347 } \
7348 while (0)
7349
7350#define po_misc_or_fail_no_backtrack(expr) \
7351 do \
7352 { \
7353 result = expr; \
7354 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7355 backtrack_pos = 0; \
7356 if (result != PARSE_OPERAND_SUCCESS) \
7357 goto failure; \
7358 } \
7359 while (0)
4962c51a 7360
52e7f43d
RE
7361#define po_barrier_or_imm(str) \
7362 do \
7363 { \
7364 val = parse_barrier (&str); \
ccb84d65
JB
7365 if (val == FAIL && ! ISALPHA (*str)) \
7366 goto immediate; \
7367 if (val == FAIL \
7368 /* ISB can only take SY as an option. */ \
7369 || ((inst.instruction & 0xf0) == 0x60 \
7370 && val != 0xf)) \
52e7f43d 7371 { \
ccb84d65
JB
7372 inst.error = _("invalid barrier type"); \
7373 backtrack_pos = 0; \
7374 goto failure; \
52e7f43d
RE
7375 } \
7376 } \
7377 while (0)
7378
c19d1205
ZW
7379 skip_whitespace (str);
7380
7381 for (i = 0; upat[i] != OP_stop; i++)
7382 {
5be8be5d
DG
7383 op_parse_code = upat[i];
7384 if (op_parse_code >= 1<<16)
7385 op_parse_code = thumb ? (op_parse_code >> 16)
7386 : (op_parse_code & ((1<<16)-1));
7387
7388 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7389 {
7390 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7391 backtrack_pos = str;
7392 backtrack_error = inst.error;
7393 backtrack_index = i;
7394 }
7395
b6702015 7396 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7397 po_char_or_fail (',');
7398
5be8be5d 7399 switch (op_parse_code)
c19d1205
ZW
7400 {
7401 /* Registers */
7402 case OP_oRRnpc:
5be8be5d 7403 case OP_oRRnpcsp:
c19d1205 7404 case OP_RRnpc:
5be8be5d 7405 case OP_RRnpcsp:
c19d1205 7406 case OP_oRR:
a302e574
AV
7407 case OP_RRe:
7408 case OP_RRo:
60f993ce
AV
7409 case OP_LR:
7410 case OP_oLR:
c19d1205
ZW
7411 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7412 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7413 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7414 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7415 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7416 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7417 case OP_oRND:
5ee91343
AV
7418 case OP_RNDMQR:
7419 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7420 break;
7421 try_rndmq:
7422 case OP_RNDMQ:
7423 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7424 break;
7425 try_rnd:
5287ad62 7426 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7427 case OP_RVC:
7428 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7429 break;
7430 /* Also accept generic coprocessor regs for unknown registers. */
7431 coproc_reg:
ba6cd17f
SD
7432 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7433 break;
7434 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7435 existing register with a value of 0, this seems like the
7436 best way to parse P0. */
7437 vpr_po:
7438 if (strncasecmp (str, "P0", 2) == 0)
7439 {
7440 str += 2;
7441 inst.operands[i].isreg = 1;
7442 inst.operands[i].reg = 13;
7443 }
7444 else
7445 goto failure;
cd2cf30b 7446 break;
c19d1205
ZW
7447 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7448 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7449 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7450 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7451 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7452 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7453 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7454 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7455 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7456 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7457 case OP_oRNQ:
5ee91343
AV
7458 case OP_RNQMQ:
7459 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7460 break;
7461 try_nq:
5287ad62 7462 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7463 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7464 case OP_RNDQMQR:
7465 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7466 break;
7467 try_rndqmq:
5ee91343
AV
7468 case OP_oRNDQMQ:
7469 case OP_RNDQMQ:
7470 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7471 break;
7472 try_rndq:
477330fc 7473 case OP_oRNDQ:
5287ad62 7474 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7475 case OP_RVSDMQ:
7476 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7477 break;
7478 try_rvsd:
477330fc 7479 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7480 case OP_RVSD_COND:
7481 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7482 break;
477330fc
RM
7483 case OP_oRNSDQ:
7484 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7485 case OP_RNSDQMQR:
7486 po_reg_or_goto (REG_TYPE_RN, try_mq);
7487 break;
7488 try_mq:
7489 case OP_oRNSDQMQ:
7490 case OP_RNSDQMQ:
7491 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7492 break;
7493 try_nsdq2:
7494 po_reg_or_fail (REG_TYPE_NSDQ);
7495 inst.error = 0;
7496 break;
35d1cfc2
AV
7497 case OP_RMQRR:
7498 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7499 break;
7500 try_rmq:
a302e574
AV
7501 case OP_RMQ:
7502 po_reg_or_fail (REG_TYPE_MQ);
7503 break;
477330fc
RM
7504 /* Neon scalar. Using an element size of 8 means that some invalid
7505 scalars are accepted here, so deal with those in later code. */
57785aa2 7506 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7507
7508 case OP_RNDQ_I0:
7509 {
7510 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7511 break;
7512 try_imm0:
7513 po_imm_or_fail (0, 0, TRUE);
7514 }
7515 break;
7516
7517 case OP_RVSD_I0:
7518 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7519 break;
7520
1b883319
AV
7521 case OP_RSVDMQ_FI0:
7522 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7523 break;
7524 try_rsvd_fi0:
aacf0b33
KT
7525 case OP_RSVD_FI0:
7526 {
7527 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7528 break;
7529 try_ifimm0:
7530 if (parse_ifimm_zero (&str))
7531 inst.operands[i].imm = 0;
7532 else
7533 {
7534 inst.error
7535 = _("only floating point zero is allowed as immediate value");
7536 goto failure;
7537 }
7538 }
7539 break;
7540
477330fc
RM
7541 case OP_RR_RNSC:
7542 {
57785aa2 7543 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7544 break;
7545 try_rr:
7546 po_reg_or_fail (REG_TYPE_RN);
7547 }
7548 break;
7549
a8465a06
AV
7550 case OP_RNSDQ_RNSC_MQ_RR:
7551 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7552 break;
7553 try_rnsdq_rnsc_mq:
886e1c73
AV
7554 case OP_RNSDQ_RNSC_MQ:
7555 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7556 break;
7557 try_rnsdq_rnsc:
477330fc
RM
7558 case OP_RNSDQ_RNSC:
7559 {
57785aa2
AV
7560 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7561 inst.error = 0;
477330fc
RM
7562 break;
7563 try_nsdq:
7564 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7565 inst.error = 0;
477330fc
RM
7566 }
7567 break;
7568
dec41383
JW
7569 case OP_RNSD_RNSC:
7570 {
57785aa2 7571 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7572 break;
7573 try_s_scalar:
57785aa2 7574 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7575 break;
7576 try_nsd:
7577 po_reg_or_fail (REG_TYPE_NSD);
7578 }
7579 break;
7580
42b16635
AV
7581 case OP_RNDQMQ_RNSC_RR:
7582 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7583 break;
7584 try_rndq_rnsc_rr:
7585 case OP_RNDQ_RNSC_RR:
7586 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7587 break;
5d281bf0
AV
7588 case OP_RNDQMQ_RNSC:
7589 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7590 break;
7591 try_rndq_rnsc:
477330fc
RM
7592 case OP_RNDQ_RNSC:
7593 {
57785aa2 7594 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7595 break;
7596 try_ndq:
7597 po_reg_or_fail (REG_TYPE_NDQ);
7598 }
7599 break;
7600
7601 case OP_RND_RNSC:
7602 {
57785aa2 7603 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7604 break;
7605 try_vfd:
7606 po_reg_or_fail (REG_TYPE_VFD);
7607 }
7608 break;
7609
7610 case OP_VMOV:
7611 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7612 not careful then bad things might happen. */
7613 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7614 break;
7615
f601a00c
AV
7616 case OP_RNDQMQ_Ibig:
7617 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7618 break;
7619 try_rndq_ibig:
477330fc
RM
7620 case OP_RNDQ_Ibig:
7621 {
7622 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7623 break;
7624 try_immbig:
7625 /* There's a possibility of getting a 64-bit immediate here, so
7626 we need special handling. */
8335d6aa
JW
7627 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7628 == FAIL)
477330fc
RM
7629 {
7630 inst.error = _("immediate value is out of range");
7631 goto failure;
7632 }
7633 }
7634 break;
7635
5150f0d8
AV
7636 case OP_RNDQMQ_I63b_RR:
7637 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7638 break;
7639 try_rndq_i63b_rr:
7640 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7641 break;
7642 try_rndq_i63b:
477330fc
RM
7643 case OP_RNDQ_I63b:
7644 {
7645 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7646 break;
7647 try_shimm:
7648 po_imm_or_fail (0, 63, TRUE);
7649 }
7650 break;
c19d1205
ZW
7651
7652 case OP_RRnpcb:
7653 po_char_or_fail ('[');
7654 po_reg_or_fail (REG_TYPE_RN);
7655 po_char_or_fail (']');
7656 break;
a737bd4d 7657
55881a11 7658 case OP_RRnpctw:
c19d1205 7659 case OP_RRw:
b6702015 7660 case OP_oRRw:
c19d1205
ZW
7661 po_reg_or_fail (REG_TYPE_RN);
7662 if (skip_past_char (&str, '!') == SUCCESS)
7663 inst.operands[i].writeback = 1;
7664 break;
7665
7666 /* Immediates */
7667 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7668 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7669 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7670 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7671 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7672 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7673 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
08132bdd 7674 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
c19d1205 7675 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7676 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7677 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7678 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 7679 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
4934a27c
MM
7680 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
7681 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
c19d1205
ZW
7682 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7683 case OP_oI7b:
7684 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7685 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7686 case OP_oI31b:
7687 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7688 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7689 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7690 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7691
7692 /* Immediate variants */
7693 case OP_oI255c:
7694 po_char_or_fail ('{');
7695 po_imm_or_fail (0, 255, TRUE);
7696 po_char_or_fail ('}');
7697 break;
7698
7699 case OP_I31w:
7700 /* The expression parser chokes on a trailing !, so we have
7701 to find it first and zap it. */
7702 {
7703 char *s = str;
7704 while (*s && *s != ',')
7705 s++;
7706 if (s[-1] == '!')
7707 {
7708 s[-1] = '\0';
7709 inst.operands[i].writeback = 1;
7710 }
7711 po_imm_or_fail (0, 31, TRUE);
7712 if (str == s - 1)
7713 str = s;
7714 }
7715 break;
7716
7717 /* Expressions */
7718 case OP_EXPi: EXPi:
e2b0ab59 7719 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7720 GE_OPT_PREFIX));
7721 break;
7722
7723 case OP_EXP:
e2b0ab59 7724 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7725 GE_NO_PREFIX));
7726 break;
7727
7728 case OP_EXPr: EXPr:
e2b0ab59 7729 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7730 GE_NO_PREFIX));
e2b0ab59 7731 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7732 {
c19d1205
ZW
7733 val = parse_reloc (&str);
7734 if (val == -1)
7735 {
7736 inst.error = _("unrecognized relocation suffix");
7737 goto failure;
7738 }
7739 else if (val != BFD_RELOC_UNUSED)
7740 {
7741 inst.operands[i].imm = val;
7742 inst.operands[i].hasreloc = 1;
7743 }
a737bd4d 7744 }
c19d1205 7745 break;
a737bd4d 7746
e2b0ab59
AV
7747 case OP_EXPs:
7748 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7749 GE_NO_PREFIX));
7750 if (inst.relocs[i].exp.X_op == O_symbol)
7751 {
7752 inst.operands[i].hasreloc = 1;
7753 }
7754 else if (inst.relocs[i].exp.X_op == O_constant)
7755 {
7756 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7757 inst.operands[i].hasreloc = 0;
7758 }
7759 break;
7760
b6895b4f
PB
7761 /* Operand for MOVW or MOVT. */
7762 case OP_HALF:
7763 po_misc_or_fail (parse_half (&str));
7764 break;
7765
e07e6e58 7766 /* Register or expression. */
c19d1205
ZW
7767 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7768 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7769
e07e6e58 7770 /* Register or immediate. */
c19d1205
ZW
7771 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7772 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7773
23d00a41
SD
7774 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7775 I32: po_imm_or_fail (1, 32, FALSE); break;
7776
c19d1205
ZW
7777 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7778 IF:
7779 if (!is_immediate_prefix (*str))
7780 goto bad_args;
7781 str++;
7782 val = parse_fpa_immediate (&str);
7783 if (val == FAIL)
7784 goto failure;
7785 /* FPA immediates are encoded as registers 8-15.
7786 parse_fpa_immediate has already applied the offset. */
7787 inst.operands[i].reg = val;
7788 inst.operands[i].isreg = 1;
7789 break;
09d92015 7790
2d447fca
JM
7791 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7792 I32z: po_imm_or_fail (0, 32, FALSE); break;
7793
e07e6e58 7794 /* Two kinds of register. */
c19d1205
ZW
7795 case OP_RIWR_RIWC:
7796 {
7797 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7798 if (!rege
7799 || (rege->type != REG_TYPE_MMXWR
7800 && rege->type != REG_TYPE_MMXWC
7801 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7802 {
7803 inst.error = _("iWMMXt data or control register expected");
7804 goto failure;
7805 }
7806 inst.operands[i].reg = rege->number;
7807 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7808 }
7809 break;
09d92015 7810
41adaa5c
JM
7811 case OP_RIWC_RIWG:
7812 {
7813 struct reg_entry *rege = arm_reg_parse_multi (&str);
7814 if (!rege
7815 || (rege->type != REG_TYPE_MMXWC
7816 && rege->type != REG_TYPE_MMXWCG))
7817 {
7818 inst.error = _("iWMMXt control register expected");
7819 goto failure;
7820 }
7821 inst.operands[i].reg = rege->number;
7822 inst.operands[i].isreg = 1;
7823 }
7824 break;
7825
c19d1205
ZW
7826 /* Misc */
7827 case OP_CPSF: val = parse_cps_flags (&str); break;
7828 case OP_ENDI: val = parse_endian_specifier (&str); break;
7829 case OP_oROR: val = parse_ror (&str); break;
1b883319 7830 try_cond:
c19d1205 7831 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7832 case OP_oBARRIER_I15:
7833 po_barrier_or_imm (str); break;
7834 immediate:
7835 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7836 goto failure;
52e7f43d 7837 break;
c19d1205 7838
fa94de6b 7839 case OP_wPSR:
d2cd1205 7840 case OP_rPSR:
90ec0d68
MGD
7841 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7842 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7843 {
7844 inst.error = _("Banked registers are not available with this "
7845 "architecture.");
7846 goto failure;
7847 }
7848 break;
d2cd1205
JB
7849 try_psr:
7850 val = parse_psr (&str, op_parse_code == OP_wPSR);
7851 break;
037e8744 7852
32c36c3c
AV
7853 case OP_VLDR:
7854 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7855 break;
7856 try_sysreg:
7857 val = parse_sys_vldr_vstr (&str);
7858 break;
7859
477330fc
RM
7860 case OP_APSR_RR:
7861 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7862 break;
7863 try_apsr:
7864 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7865 instruction). */
7866 if (strncasecmp (str, "APSR_", 5) == 0)
7867 {
7868 unsigned found = 0;
7869 str += 5;
7870 while (found < 15)
7871 switch (*str++)
7872 {
7873 case 'c': found = (found & 1) ? 16 : found | 1; break;
7874 case 'n': found = (found & 2) ? 16 : found | 2; break;
7875 case 'z': found = (found & 4) ? 16 : found | 4; break;
7876 case 'v': found = (found & 8) ? 16 : found | 8; break;
7877 default: found = 16;
7878 }
7879 if (found != 15)
7880 goto failure;
7881 inst.operands[i].isvec = 1;
f7c21dc7
NC
7882 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7883 inst.operands[i].reg = REG_PC;
477330fc
RM
7884 }
7885 else
7886 goto failure;
7887 break;
037e8744 7888
92e90b6e
PB
7889 case OP_TB:
7890 po_misc_or_fail (parse_tb (&str));
7891 break;
7892
e07e6e58 7893 /* Register lists. */
c19d1205 7894 case OP_REGLST:
4b5a202f 7895 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7896 if (*str == '^')
7897 {
5e0d7f77 7898 inst.operands[i].writeback = 1;
c19d1205
ZW
7899 str++;
7900 }
7901 break;
09d92015 7902
4b5a202f
AV
7903 case OP_CLRMLST:
7904 val = parse_reg_list (&str, REGLIST_CLRM);
7905 break;
7906
c19d1205 7907 case OP_VRSLST:
efd6b359
AV
7908 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7909 &partial_match);
c19d1205 7910 break;
09d92015 7911
c19d1205 7912 case OP_VRDLST:
efd6b359
AV
7913 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7914 &partial_match);
c19d1205 7915 break;
a737bd4d 7916
477330fc
RM
7917 case OP_VRSDLST:
7918 /* Allow Q registers too. */
7919 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7920 REGLIST_NEON_D, &partial_match);
477330fc
RM
7921 if (val == FAIL)
7922 {
7923 inst.error = NULL;
7924 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7925 REGLIST_VFP_S, &partial_match);
7926 inst.operands[i].issingle = 1;
7927 }
7928 break;
7929
7930 case OP_VRSDVLST:
7931 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7932 REGLIST_VFP_D_VPR, &partial_match);
7933 if (val == FAIL && !partial_match)
7934 {
7935 inst.error = NULL;
7936 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7937 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7938 inst.operands[i].issingle = 1;
7939 }
7940 break;
7941
7942 case OP_NRDLST:
7943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7944 REGLIST_NEON_D, &partial_match);
477330fc 7945 break;
5287ad62 7946
35c228db
AV
7947 case OP_MSTRLST4:
7948 case OP_MSTRLST2:
7949 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7950 1, &inst.operands[i].vectype);
7951 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7952 goto failure;
7953 break;
5287ad62 7954 case OP_NSTRLST:
477330fc 7955 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7956 0, &inst.operands[i].vectype);
477330fc 7957 break;
5287ad62 7958
c19d1205 7959 /* Addressing modes */
35c228db
AV
7960 case OP_ADDRMVE:
7961 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7962 break;
7963
c19d1205
ZW
7964 case OP_ADDR:
7965 po_misc_or_fail (parse_address (&str, i));
7966 break;
09d92015 7967
4962c51a
MS
7968 case OP_ADDRGLDR:
7969 po_misc_or_fail_no_backtrack (
477330fc 7970 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7971 break;
7972
7973 case OP_ADDRGLDRS:
7974 po_misc_or_fail_no_backtrack (
477330fc 7975 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7976 break;
7977
7978 case OP_ADDRGLDC:
7979 po_misc_or_fail_no_backtrack (
477330fc 7980 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7981 break;
7982
c19d1205
ZW
7983 case OP_SH:
7984 po_misc_or_fail (parse_shifter_operand (&str, i));
7985 break;
09d92015 7986
4962c51a
MS
7987 case OP_SHG:
7988 po_misc_or_fail_no_backtrack (
477330fc 7989 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7990 break;
7991
c19d1205
ZW
7992 case OP_oSHll:
7993 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7994 break;
09d92015 7995
c19d1205
ZW
7996 case OP_oSHar:
7997 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7998 break;
09d92015 7999
c19d1205
ZW
8000 case OP_oSHllar:
8001 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8002 break;
09d92015 8003
1b883319
AV
8004 case OP_RMQRZ:
8005 case OP_oRMQRZ:
8006 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8007 break;
e39c1607
SD
8008
8009 case OP_RR_ZR:
1b883319
AV
8010 try_rr_zr:
8011 po_reg_or_goto (REG_TYPE_RN, ZR);
8012 break;
8013 ZR:
8014 po_reg_or_fail (REG_TYPE_ZR);
8015 break;
8016
c19d1205 8017 default:
5be8be5d 8018 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 8019 }
09d92015 8020
c19d1205
ZW
8021 /* Various value-based sanity checks and shared operations. We
8022 do not signal immediate failures for the register constraints;
8023 this allows a syntax error to take precedence. */
5be8be5d 8024 switch (op_parse_code)
c19d1205
ZW
8025 {
8026 case OP_oRRnpc:
8027 case OP_RRnpc:
8028 case OP_RRnpcb:
8029 case OP_RRw:
b6702015 8030 case OP_oRRw:
c19d1205
ZW
8031 case OP_RRnpc_I0:
8032 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8033 inst.error = BAD_PC;
8034 break;
09d92015 8035
5be8be5d
DG
8036 case OP_oRRnpcsp:
8037 case OP_RRnpcsp:
23d00a41 8038 case OP_RRnpcsp_I32:
5be8be5d
DG
8039 if (inst.operands[i].isreg)
8040 {
8041 if (inst.operands[i].reg == REG_PC)
8042 inst.error = BAD_PC;
5c8ed6a4
JW
8043 else if (inst.operands[i].reg == REG_SP
8044 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8045 relaxed since ARMv8-A. */
8046 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8047 {
8048 gas_assert (thumb);
8049 inst.error = BAD_SP;
8050 }
5be8be5d
DG
8051 }
8052 break;
8053
55881a11 8054 case OP_RRnpctw:
fa94de6b
RM
8055 if (inst.operands[i].isreg
8056 && inst.operands[i].reg == REG_PC
55881a11
MGD
8057 && (inst.operands[i].writeback || thumb))
8058 inst.error = BAD_PC;
8059 break;
8060
1b883319 8061 case OP_RVSD_COND:
32c36c3c
AV
8062 case OP_VLDR:
8063 if (inst.operands[i].isreg)
8064 break;
8065 /* fall through. */
1b883319 8066
c19d1205
ZW
8067 case OP_CPSF:
8068 case OP_ENDI:
8069 case OP_oROR:
d2cd1205
JB
8070 case OP_wPSR:
8071 case OP_rPSR:
c19d1205 8072 case OP_COND:
52e7f43d 8073 case OP_oBARRIER_I15:
c19d1205 8074 case OP_REGLST:
4b5a202f 8075 case OP_CLRMLST:
c19d1205
ZW
8076 case OP_VRSLST:
8077 case OP_VRDLST:
477330fc 8078 case OP_VRSDLST:
efd6b359 8079 case OP_VRSDVLST:
477330fc
RM
8080 case OP_NRDLST:
8081 case OP_NSTRLST:
35c228db
AV
8082 case OP_MSTRLST2:
8083 case OP_MSTRLST4:
c19d1205
ZW
8084 if (val == FAIL)
8085 goto failure;
8086 inst.operands[i].imm = val;
8087 break;
a737bd4d 8088
60f993ce
AV
8089 case OP_LR:
8090 case OP_oLR:
8091 if (inst.operands[i].reg != REG_LR)
8092 inst.error = _("operand must be LR register");
8093 break;
8094
1b883319
AV
8095 case OP_RMQRZ:
8096 case OP_oRMQRZ:
e39c1607 8097 case OP_RR_ZR:
1b883319
AV
8098 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8099 inst.error = BAD_PC;
8100 break;
8101
a302e574
AV
8102 case OP_RRe:
8103 if (inst.operands[i].isreg
8104 && (inst.operands[i].reg & 0x00000001) != 0)
8105 inst.error = BAD_ODD;
8106 break;
8107
8108 case OP_RRo:
8109 if (inst.operands[i].isreg)
8110 {
8111 if ((inst.operands[i].reg & 0x00000001) != 1)
8112 inst.error = BAD_EVEN;
8113 else if (inst.operands[i].reg == REG_SP)
8114 as_tsktsk (MVE_BAD_SP);
8115 else if (inst.operands[i].reg == REG_PC)
8116 inst.error = BAD_PC;
8117 }
8118 break;
8119
c19d1205
ZW
8120 default:
8121 break;
8122 }
09d92015 8123
c19d1205
ZW
8124 /* If we get here, this operand was successfully parsed. */
8125 inst.operands[i].present = 1;
8126 continue;
09d92015 8127
c19d1205 8128 bad_args:
09d92015 8129 inst.error = BAD_ARGS;
c19d1205
ZW
8130
8131 failure:
8132 if (!backtrack_pos)
d252fdde
PB
8133 {
8134 /* The parse routine should already have set inst.error, but set a
5f4273c7 8135 default here just in case. */
d252fdde 8136 if (!inst.error)
5ee91343 8137 inst.error = BAD_SYNTAX;
d252fdde
PB
8138 return FAIL;
8139 }
c19d1205
ZW
8140
8141 /* Do not backtrack over a trailing optional argument that
8142 absorbed some text. We will only fail again, with the
8143 'garbage following instruction' error message, which is
8144 probably less helpful than the current one. */
8145 if (backtrack_index == i && backtrack_pos != str
8146 && upat[i+1] == OP_stop)
d252fdde
PB
8147 {
8148 if (!inst.error)
5ee91343 8149 inst.error = BAD_SYNTAX;
d252fdde
PB
8150 return FAIL;
8151 }
c19d1205
ZW
8152
8153 /* Try again, skipping the optional argument at backtrack_pos. */
8154 str = backtrack_pos;
8155 inst.error = backtrack_error;
8156 inst.operands[backtrack_index].present = 0;
8157 i = backtrack_index;
8158 backtrack_pos = 0;
09d92015 8159 }
09d92015 8160
c19d1205
ZW
8161 /* Check that we have parsed all the arguments. */
8162 if (*str != '\0' && !inst.error)
8163 inst.error = _("garbage following instruction");
09d92015 8164
c19d1205 8165 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8166}
8167
c19d1205
ZW
8168#undef po_char_or_fail
8169#undef po_reg_or_fail
8170#undef po_reg_or_goto
8171#undef po_imm_or_fail
5287ad62 8172#undef po_scalar_or_fail
52e7f43d 8173#undef po_barrier_or_imm
e07e6e58 8174
c19d1205 8175/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8176#define constraint(expr, err) \
8177 do \
c19d1205 8178 { \
e07e6e58
NC
8179 if (expr) \
8180 { \
8181 inst.error = err; \
8182 return; \
8183 } \
c19d1205 8184 } \
e07e6e58 8185 while (0)
c19d1205 8186
fdfde340
JM
8187/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8188 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8189 is the BadReg predicate in ARM's Thumb-2 documentation.
8190
8191 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8192 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8193#define reject_bad_reg(reg) \
8194 do \
8195 if (reg == REG_PC) \
8196 { \
8197 inst.error = BAD_PC; \
8198 return; \
8199 } \
8200 else if (reg == REG_SP \
8201 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8202 { \
8203 inst.error = BAD_SP; \
8204 return; \
8205 } \
fdfde340
JM
8206 while (0)
8207
94206790
MM
8208/* If REG is R13 (the stack pointer), warn that its use is
8209 deprecated. */
8210#define warn_deprecated_sp(reg) \
8211 do \
8212 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8213 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8214 while (0)
8215
c19d1205
ZW
8216/* Functions for operand encoding. ARM, then Thumb. */
8217
d840c081 8218#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8219
9db2f6b4
RL
8220/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8221
8222 The only binary encoding difference is the Coprocessor number. Coprocessor
8223 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8224 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8225 exists for Single-Precision operation. */
8226
8227static void
8228do_scalar_fp16_v82_encode (void)
8229{
5ee91343 8230 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8231 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8232 " the behaviour is UNPREDICTABLE"));
8233 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8234 _(BAD_FP16));
8235
8236 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8237 mark_feature_used (&arm_ext_fp16);
8238}
8239
c19d1205
ZW
8240/* If VAL can be encoded in the immediate field of an ARM instruction,
8241 return the encoded form. Otherwise, return FAIL. */
8242
8243static unsigned int
8244encode_arm_immediate (unsigned int val)
09d92015 8245{
c19d1205
ZW
8246 unsigned int a, i;
8247
4f1d6205
L
8248 if (val <= 0xff)
8249 return val;
8250
8251 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8252 if ((a = rotate_left (val, i)) <= 0xff)
8253 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8254
8255 return FAIL;
09d92015
MM
8256}
8257
c19d1205
ZW
8258/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8259 return the encoded form. Otherwise, return FAIL. */
8260static unsigned int
8261encode_thumb32_immediate (unsigned int val)
09d92015 8262{
c19d1205 8263 unsigned int a, i;
09d92015 8264
9c3c69f2 8265 if (val <= 0xff)
c19d1205 8266 return val;
a737bd4d 8267
9c3c69f2 8268 for (i = 1; i <= 24; i++)
09d92015 8269 {
9c3c69f2
PB
8270 a = val >> i;
8271 if ((val & ~(0xff << i)) == 0)
8272 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8273 }
a737bd4d 8274
c19d1205
ZW
8275 a = val & 0xff;
8276 if (val == ((a << 16) | a))
8277 return 0x100 | a;
8278 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8279 return 0x300 | a;
09d92015 8280
c19d1205
ZW
8281 a = val & 0xff00;
8282 if (val == ((a << 16) | a))
8283 return 0x200 | (a >> 8);
a737bd4d 8284
c19d1205 8285 return FAIL;
09d92015 8286}
5287ad62 8287/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8288
8289static void
5287ad62
JB
8290encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8291{
8292 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8293 && reg > 15)
8294 {
b1cc4aeb 8295 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8296 {
8297 if (thumb_mode)
8298 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8299 fpu_vfp_ext_d32);
8300 else
8301 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8302 fpu_vfp_ext_d32);
8303 }
5287ad62 8304 else
477330fc
RM
8305 {
8306 first_error (_("D register out of range for selected VFP version"));
8307 return;
8308 }
5287ad62
JB
8309 }
8310
c19d1205 8311 switch (pos)
09d92015 8312 {
c19d1205
ZW
8313 case VFP_REG_Sd:
8314 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8315 break;
8316
8317 case VFP_REG_Sn:
8318 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8319 break;
8320
8321 case VFP_REG_Sm:
8322 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8323 break;
8324
5287ad62
JB
8325 case VFP_REG_Dd:
8326 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8327 break;
5f4273c7 8328
5287ad62
JB
8329 case VFP_REG_Dn:
8330 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8331 break;
5f4273c7 8332
5287ad62
JB
8333 case VFP_REG_Dm:
8334 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8335 break;
8336
c19d1205
ZW
8337 default:
8338 abort ();
09d92015 8339 }
09d92015
MM
8340}
8341
c19d1205 8342/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8343 if any, is handled by md_apply_fix. */
09d92015 8344static void
c19d1205 8345encode_arm_shift (int i)
09d92015 8346{
008a97ef
RL
8347 /* register-shifted register. */
8348 if (inst.operands[i].immisreg)
8349 {
bf355b69
MR
8350 int op_index;
8351 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8352 {
5689c942
RL
8353 /* Check the operand only when it's presented. In pre-UAL syntax,
8354 if the destination register is the same as the first operand, two
8355 register form of the instruction can be used. */
bf355b69
MR
8356 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8357 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8358 as_warn (UNPRED_REG ("r15"));
8359 }
8360
8361 if (inst.operands[i].imm == REG_PC)
8362 as_warn (UNPRED_REG ("r15"));
8363 }
8364
c19d1205
ZW
8365 if (inst.operands[i].shift_kind == SHIFT_RRX)
8366 inst.instruction |= SHIFT_ROR << 5;
8367 else
09d92015 8368 {
c19d1205
ZW
8369 inst.instruction |= inst.operands[i].shift_kind << 5;
8370 if (inst.operands[i].immisreg)
8371 {
8372 inst.instruction |= SHIFT_BY_REG;
8373 inst.instruction |= inst.operands[i].imm << 8;
8374 }
8375 else
e2b0ab59 8376 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8377 }
c19d1205 8378}
09d92015 8379
c19d1205
ZW
8380static void
8381encode_arm_shifter_operand (int i)
8382{
8383 if (inst.operands[i].isreg)
09d92015 8384 {
c19d1205
ZW
8385 inst.instruction |= inst.operands[i].reg;
8386 encode_arm_shift (i);
09d92015 8387 }
c19d1205 8388 else
a415b1cd
JB
8389 {
8390 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8391 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8392 inst.instruction |= inst.operands[i].imm;
8393 }
09d92015
MM
8394}
8395
c19d1205 8396/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8397static void
c19d1205 8398encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8399{
2b2f5df9
NC
8400 /* PR 14260:
8401 Generate an error if the operand is not a register. */
8402 constraint (!inst.operands[i].isreg,
8403 _("Instruction does not support =N addresses"));
8404
c19d1205 8405 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8406
c19d1205 8407 if (inst.operands[i].preind)
09d92015 8408 {
c19d1205
ZW
8409 if (is_t)
8410 {
8411 inst.error = _("instruction does not accept preindexed addressing");
8412 return;
8413 }
8414 inst.instruction |= PRE_INDEX;
8415 if (inst.operands[i].writeback)
8416 inst.instruction |= WRITE_BACK;
09d92015 8417
c19d1205
ZW
8418 }
8419 else if (inst.operands[i].postind)
8420 {
9c2799c2 8421 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8422 if (is_t)
8423 inst.instruction |= WRITE_BACK;
8424 }
8425 else /* unindexed - only for coprocessor */
09d92015 8426 {
c19d1205 8427 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8428 return;
8429 }
8430
c19d1205
ZW
8431 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8432 && (((inst.instruction & 0x000f0000) >> 16)
8433 == ((inst.instruction & 0x0000f000) >> 12)))
8434 as_warn ((inst.instruction & LOAD_BIT)
8435 ? _("destination register same as write-back base")
8436 : _("source register same as write-back base"));
09d92015
MM
8437}
8438
c19d1205
ZW
8439/* inst.operands[i] was set up by parse_address. Encode it into an
8440 ARM-format mode 2 load or store instruction. If is_t is true,
8441 reject forms that cannot be used with a T instruction (i.e. not
8442 post-indexed). */
a737bd4d 8443static void
c19d1205 8444encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8445{
5be8be5d
DG
8446 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8447
c19d1205 8448 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8449
c19d1205 8450 if (inst.operands[i].immisreg)
09d92015 8451 {
5be8be5d
DG
8452 constraint ((inst.operands[i].imm == REG_PC
8453 || (is_pc && inst.operands[i].writeback)),
8454 BAD_PC_ADDRESSING);
c19d1205
ZW
8455 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8456 inst.instruction |= inst.operands[i].imm;
8457 if (!inst.operands[i].negative)
8458 inst.instruction |= INDEX_UP;
8459 if (inst.operands[i].shifted)
8460 {
8461 if (inst.operands[i].shift_kind == SHIFT_RRX)
8462 inst.instruction |= SHIFT_ROR << 5;
8463 else
8464 {
8465 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8466 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8467 }
8468 }
09d92015 8469 }
e2b0ab59 8470 else /* immediate offset in inst.relocs[0] */
09d92015 8471 {
e2b0ab59 8472 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8473 {
8474 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8475
8476 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8477 cannot use PC in addressing.
8478 PC cannot be used in writeback addressing, either. */
8479 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8480 BAD_PC_ADDRESSING);
23a10334 8481
dc5ec521 8482 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8483 if (warn_on_deprecated
8484 && !is_load
8485 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8486 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8487 }
8488
e2b0ab59 8489 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8490 {
8491 /* Prefer + for zero encoded value. */
8492 if (!inst.operands[i].negative)
8493 inst.instruction |= INDEX_UP;
e2b0ab59 8494 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8495 }
09d92015 8496 }
09d92015
MM
8497}
8498
c19d1205
ZW
8499/* inst.operands[i] was set up by parse_address. Encode it into an
8500 ARM-format mode 3 load or store instruction. Reject forms that
8501 cannot be used with such instructions. If is_t is true, reject
8502 forms that cannot be used with a T instruction (i.e. not
8503 post-indexed). */
8504static void
8505encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8506{
c19d1205 8507 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8508 {
c19d1205
ZW
8509 inst.error = _("instruction does not accept scaled register index");
8510 return;
09d92015 8511 }
a737bd4d 8512
c19d1205 8513 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8514
c19d1205
ZW
8515 if (inst.operands[i].immisreg)
8516 {
5be8be5d 8517 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8518 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8519 BAD_PC_ADDRESSING);
eb9f3f00
JB
8520 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8521 BAD_PC_WRITEBACK);
c19d1205
ZW
8522 inst.instruction |= inst.operands[i].imm;
8523 if (!inst.operands[i].negative)
8524 inst.instruction |= INDEX_UP;
8525 }
e2b0ab59 8526 else /* immediate offset in inst.relocs[0] */
c19d1205 8527 {
e2b0ab59 8528 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8529 && inst.operands[i].writeback),
8530 BAD_PC_WRITEBACK);
c19d1205 8531 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8532 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8533 {
8534 /* Prefer + for zero encoded value. */
8535 if (!inst.operands[i].negative)
8536 inst.instruction |= INDEX_UP;
8537
e2b0ab59 8538 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8539 }
c19d1205 8540 }
a737bd4d
NC
8541}
8542
8335d6aa
JW
8543/* Write immediate bits [7:0] to the following locations:
8544
8545 |28/24|23 19|18 16|15 4|3 0|
8546 | 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|
8547
8548 This function is used by VMOV/VMVN/VORR/VBIC. */
8549
8550static void
8551neon_write_immbits (unsigned immbits)
8552{
8553 inst.instruction |= immbits & 0xf;
8554 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8555 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8556}
8557
8558/* Invert low-order SIZE bits of XHI:XLO. */
8559
8560static void
8561neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8562{
8563 unsigned immlo = xlo ? *xlo : 0;
8564 unsigned immhi = xhi ? *xhi : 0;
8565
8566 switch (size)
8567 {
8568 case 8:
8569 immlo = (~immlo) & 0xff;
8570 break;
8571
8572 case 16:
8573 immlo = (~immlo) & 0xffff;
8574 break;
8575
8576 case 64:
8577 immhi = (~immhi) & 0xffffffff;
8578 /* fall through. */
8579
8580 case 32:
8581 immlo = (~immlo) & 0xffffffff;
8582 break;
8583
8584 default:
8585 abort ();
8586 }
8587
8588 if (xlo)
8589 *xlo = immlo;
8590
8591 if (xhi)
8592 *xhi = immhi;
8593}
8594
8595/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8596 A, B, C, D. */
09d92015 8597
c19d1205 8598static int
8335d6aa 8599neon_bits_same_in_bytes (unsigned imm)
09d92015 8600{
8335d6aa
JW
8601 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8602 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8603 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8604 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8605}
a737bd4d 8606
8335d6aa 8607/* For immediate of above form, return 0bABCD. */
09d92015 8608
8335d6aa
JW
8609static unsigned
8610neon_squash_bits (unsigned imm)
8611{
8612 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8613 | ((imm & 0x01000000) >> 21);
8614}
8615
8616/* Compress quarter-float representation to 0b...000 abcdefgh. */
8617
8618static unsigned
8619neon_qfloat_bits (unsigned imm)
8620{
8621 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8622}
8623
8624/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8625 the instruction. *OP is passed as the initial value of the op field, and
8626 may be set to a different value depending on the constant (i.e.
8627 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8628 MVN). If the immediate looks like a repeated pattern then also
8629 try smaller element sizes. */
8630
8631static int
8632neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8633 unsigned *immbits, int *op, int size,
8634 enum neon_el_type type)
8635{
8636 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8637 float. */
8638 if (type == NT_float && !float_p)
8639 return FAIL;
8640
8641 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8642 {
8335d6aa
JW
8643 if (size != 32 || *op == 1)
8644 return FAIL;
8645 *immbits = neon_qfloat_bits (immlo);
8646 return 0xf;
8647 }
8648
8649 if (size == 64)
8650 {
8651 if (neon_bits_same_in_bytes (immhi)
8652 && neon_bits_same_in_bytes (immlo))
c19d1205 8653 {
8335d6aa
JW
8654 if (*op == 1)
8655 return FAIL;
8656 *immbits = (neon_squash_bits (immhi) << 4)
8657 | neon_squash_bits (immlo);
8658 *op = 1;
8659 return 0xe;
c19d1205 8660 }
a737bd4d 8661
8335d6aa
JW
8662 if (immhi != immlo)
8663 return FAIL;
8664 }
a737bd4d 8665
8335d6aa 8666 if (size >= 32)
09d92015 8667 {
8335d6aa 8668 if (immlo == (immlo & 0x000000ff))
c19d1205 8669 {
8335d6aa
JW
8670 *immbits = immlo;
8671 return 0x0;
c19d1205 8672 }
8335d6aa 8673 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8674 {
8335d6aa
JW
8675 *immbits = immlo >> 8;
8676 return 0x2;
c19d1205 8677 }
8335d6aa
JW
8678 else if (immlo == (immlo & 0x00ff0000))
8679 {
8680 *immbits = immlo >> 16;
8681 return 0x4;
8682 }
8683 else if (immlo == (immlo & 0xff000000))
8684 {
8685 *immbits = immlo >> 24;
8686 return 0x6;
8687 }
8688 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8689 {
8690 *immbits = (immlo >> 8) & 0xff;
8691 return 0xc;
8692 }
8693 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8694 {
8695 *immbits = (immlo >> 16) & 0xff;
8696 return 0xd;
8697 }
8698
8699 if ((immlo & 0xffff) != (immlo >> 16))
8700 return FAIL;
8701 immlo &= 0xffff;
09d92015 8702 }
a737bd4d 8703
8335d6aa 8704 if (size >= 16)
4962c51a 8705 {
8335d6aa
JW
8706 if (immlo == (immlo & 0x000000ff))
8707 {
8708 *immbits = immlo;
8709 return 0x8;
8710 }
8711 else if (immlo == (immlo & 0x0000ff00))
8712 {
8713 *immbits = immlo >> 8;
8714 return 0xa;
8715 }
8716
8717 if ((immlo & 0xff) != (immlo >> 8))
8718 return FAIL;
8719 immlo &= 0xff;
4962c51a
MS
8720 }
8721
8335d6aa
JW
8722 if (immlo == (immlo & 0x000000ff))
8723 {
8724 /* Don't allow MVN with 8-bit immediate. */
8725 if (*op == 1)
8726 return FAIL;
8727 *immbits = immlo;
8728 return 0xe;
8729 }
26d97720 8730
8335d6aa 8731 return FAIL;
c19d1205 8732}
a737bd4d 8733
5fc177c8 8734#if defined BFD_HOST_64_BIT
ba592044
AM
8735/* Returns TRUE if double precision value V may be cast
8736 to single precision without loss of accuracy. */
8737
8738static bfd_boolean
5fc177c8 8739is_double_a_single (bfd_int64_t v)
ba592044 8740{
5fc177c8 8741 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8742 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8743
8744 return (exp == 0 || exp == 0x7FF
8745 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8746 && (mantissa & 0x1FFFFFFFl) == 0;
8747}
8748
3739860c 8749/* Returns a double precision value casted to single precision
ba592044
AM
8750 (ignoring the least significant bits in exponent and mantissa). */
8751
8752static int
5fc177c8 8753double_to_single (bfd_int64_t v)
ba592044
AM
8754{
8755 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8756 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8757 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8758
8759 if (exp == 0x7FF)
8760 exp = 0xFF;
8761 else
8762 {
8763 exp = exp - 1023 + 127;
8764 if (exp >= 0xFF)
8765 {
8766 /* Infinity. */
8767 exp = 0x7F;
8768 mantissa = 0;
8769 }
8770 else if (exp < 0)
8771 {
8772 /* No denormalized numbers. */
8773 exp = 0;
8774 mantissa = 0;
8775 }
8776 }
8777 mantissa >>= 29;
8778 return (sign << 31) | (exp << 23) | mantissa;
8779}
5fc177c8 8780#endif /* BFD_HOST_64_BIT */
ba592044 8781
8335d6aa
JW
8782enum lit_type
8783{
8784 CONST_THUMB,
8785 CONST_ARM,
8786 CONST_VEC
8787};
8788
ba592044
AM
8789static void do_vfp_nsyn_opcode (const char *);
8790
e2b0ab59 8791/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8792 Determine whether it can be performed with a move instruction; if
8793 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8794 return TRUE; if it can't, convert inst.instruction to a literal-pool
8795 load and return FALSE. If this is not a valid thing to do in the
8796 current context, set inst.error and return TRUE.
a737bd4d 8797
c19d1205
ZW
8798 inst.operands[i] describes the destination register. */
8799
c921be7d 8800static bfd_boolean
8335d6aa 8801move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8802{
53365c0d 8803 unsigned long tbit;
8335d6aa
JW
8804 bfd_boolean thumb_p = (t == CONST_THUMB);
8805 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8806
8807 if (thumb_p)
8808 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8809 else
8810 tbit = LOAD_BIT;
8811
8812 if ((inst.instruction & tbit) == 0)
09d92015 8813 {
c19d1205 8814 inst.error = _("invalid pseudo operation");
c921be7d 8815 return TRUE;
09d92015 8816 }
ba592044 8817
e2b0ab59
AV
8818 if (inst.relocs[0].exp.X_op != O_constant
8819 && inst.relocs[0].exp.X_op != O_symbol
8820 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8821 {
8822 inst.error = _("constant expression expected");
c921be7d 8823 return TRUE;
09d92015 8824 }
ba592044 8825
e2b0ab59
AV
8826 if (inst.relocs[0].exp.X_op == O_constant
8827 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8828 {
5fc177c8
NC
8829#if defined BFD_HOST_64_BIT
8830 bfd_int64_t v;
8831#else
ba592044 8832 offsetT v;
5fc177c8 8833#endif
e2b0ab59 8834 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8835 {
ba592044
AM
8836 LITTLENUM_TYPE w[X_PRECISION];
8837 LITTLENUM_TYPE * l;
8838
e2b0ab59 8839 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8840 {
ba592044
AM
8841 gen_to_words (w, X_PRECISION, E_PRECISION);
8842 l = w;
8843 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8844 }
ba592044
AM
8845 else
8846 l = generic_bignum;
3739860c 8847
5fc177c8
NC
8848#if defined BFD_HOST_64_BIT
8849 v =
8850 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8851 << LITTLENUM_NUMBER_OF_BITS)
8852 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8853 << LITTLENUM_NUMBER_OF_BITS)
8854 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8855 << LITTLENUM_NUMBER_OF_BITS)
8856 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8857#else
ba592044
AM
8858 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8859 | (l[0] & LITTLENUM_MASK);
5fc177c8 8860#endif
8335d6aa 8861 }
ba592044 8862 else
e2b0ab59 8863 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8864
8865 if (!inst.operands[i].issingle)
8335d6aa 8866 {
12569877 8867 if (thumb_p)
8335d6aa 8868 {
53445554
TP
8869 /* LDR should not use lead in a flag-setting instruction being
8870 chosen so we do not check whether movs can be used. */
12569877 8871
53445554 8872 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8873 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8874 && inst.operands[i].reg != 13
8875 && inst.operands[i].reg != 15)
12569877 8876 {
fc289b0a
TP
8877 /* Check if on thumb2 it can be done with a mov.w, mvn or
8878 movw instruction. */
12569877
AM
8879 unsigned int newimm;
8880 bfd_boolean isNegated;
8881
8882 newimm = encode_thumb32_immediate (v);
8883 if (newimm != (unsigned int) FAIL)
8884 isNegated = FALSE;
8885 else
8886 {
582cfe03 8887 newimm = encode_thumb32_immediate (~v);
12569877
AM
8888 if (newimm != (unsigned int) FAIL)
8889 isNegated = TRUE;
8890 }
8891
fc289b0a
TP
8892 /* The number can be loaded with a mov.w or mvn
8893 instruction. */
ff8646ee
TP
8894 if (newimm != (unsigned int) FAIL
8895 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8896 {
fc289b0a 8897 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8898 | (inst.operands[i].reg << 8));
fc289b0a 8899 /* Change to MOVN. */
582cfe03 8900 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8901 inst.instruction |= (newimm & 0x800) << 15;
8902 inst.instruction |= (newimm & 0x700) << 4;
8903 inst.instruction |= (newimm & 0x0ff);
8904 return TRUE;
8905 }
fc289b0a 8906 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8907 else if ((v & ~0xFFFF) == 0
8908 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8909 {
582cfe03 8910 int imm = v & 0xFFFF;
12569877 8911
582cfe03 8912 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8913 inst.instruction |= (inst.operands[i].reg << 8);
8914 inst.instruction |= (imm & 0xf000) << 4;
8915 inst.instruction |= (imm & 0x0800) << 15;
8916 inst.instruction |= (imm & 0x0700) << 4;
8917 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8918 /* In case this replacement is being done on Armv8-M
8919 Baseline we need to make sure to disable the
8920 instruction size check, as otherwise GAS will reject
8921 the use of this T32 instruction. */
8922 inst.size_req = 0;
12569877
AM
8923 return TRUE;
8924 }
8925 }
8335d6aa 8926 }
12569877 8927 else if (arm_p)
ba592044
AM
8928 {
8929 int value = encode_arm_immediate (v);
12569877 8930
ba592044
AM
8931 if (value != FAIL)
8932 {
8933 /* This can be done with a mov instruction. */
8934 inst.instruction &= LITERAL_MASK;
8935 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8936 inst.instruction |= value & 0xfff;
8937 return TRUE;
8938 }
8335d6aa 8939
ba592044
AM
8940 value = encode_arm_immediate (~ v);
8941 if (value != FAIL)
8942 {
8943 /* This can be done with a mvn instruction. */
8944 inst.instruction &= LITERAL_MASK;
8945 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8946 inst.instruction |= value & 0xfff;
8947 return TRUE;
8948 }
8949 }
934c2632 8950 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8951 {
ba592044
AM
8952 int op = 0;
8953 unsigned immbits = 0;
8954 unsigned immlo = inst.operands[1].imm;
8955 unsigned immhi = inst.operands[1].regisimm
8956 ? inst.operands[1].reg
e2b0ab59 8957 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8958 ? 0
8959 : ((bfd_int64_t)((int) immlo)) >> 32;
8960 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8961 &op, 64, NT_invtype);
8962
8963 if (cmode == FAIL)
8964 {
8965 neon_invert_size (&immlo, &immhi, 64);
8966 op = !op;
8967 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8968 &op, 64, NT_invtype);
8969 }
8970
8971 if (cmode != FAIL)
8972 {
8973 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8974 | (1 << 23)
8975 | (cmode << 8)
8976 | (op << 5)
8977 | (1 << 4);
8978
8979 /* Fill other bits in vmov encoding for both thumb and arm. */
8980 if (thumb_mode)
eff0bc54 8981 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8982 else
eff0bc54 8983 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8984 neon_write_immbits (immbits);
8985 return TRUE;
8986 }
8335d6aa
JW
8987 }
8988 }
8335d6aa 8989
ba592044
AM
8990 if (t == CONST_VEC)
8991 {
8992 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8993 if (inst.operands[i].issingle
8994 && is_quarter_float (inst.operands[1].imm)
8995 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8996 {
ba592044
AM
8997 inst.operands[1].imm =
8998 neon_qfloat_bits (v);
8999 do_vfp_nsyn_opcode ("fconsts");
9000 return TRUE;
8335d6aa 9001 }
5fc177c8
NC
9002
9003 /* If our host does not support a 64-bit type then we cannot perform
9004 the following optimization. This mean that there will be a
9005 discrepancy between the output produced by an assembler built for
9006 a 32-bit-only host and the output produced from a 64-bit host, but
9007 this cannot be helped. */
9008#if defined BFD_HOST_64_BIT
ba592044
AM
9009 else if (!inst.operands[1].issingle
9010 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 9011 {
ba592044
AM
9012 if (is_double_a_single (v)
9013 && is_quarter_float (double_to_single (v)))
9014 {
9015 inst.operands[1].imm =
9016 neon_qfloat_bits (double_to_single (v));
9017 do_vfp_nsyn_opcode ("fconstd");
9018 return TRUE;
9019 }
8335d6aa 9020 }
5fc177c8 9021#endif
8335d6aa
JW
9022 }
9023 }
9024
9025 if (add_to_lit_pool ((!inst.operands[i].isvec
9026 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9027 return TRUE;
9028
9029 inst.operands[1].reg = REG_PC;
9030 inst.operands[1].isreg = 1;
9031 inst.operands[1].preind = 1;
e2b0ab59
AV
9032 inst.relocs[0].pc_rel = 1;
9033 inst.relocs[0].type = (thumb_p
8335d6aa
JW
9034 ? BFD_RELOC_ARM_THUMB_OFFSET
9035 : (mode_3
9036 ? BFD_RELOC_ARM_HWLITERAL
9037 : BFD_RELOC_ARM_LITERAL));
9038 return FALSE;
9039}
9040
9041/* inst.operands[i] was set up by parse_address. Encode it into an
9042 ARM-format instruction. Reject all forms which cannot be encoded
9043 into a coprocessor load/store instruction. If wb_ok is false,
9044 reject use of writeback; if unind_ok is false, reject use of
9045 unindexed addressing. If reloc_override is not 0, use it instead
9046 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9047 (in which case it is preserved). */
9048
9049static int
9050encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9051{
9052 if (!inst.operands[i].isreg)
9053 {
99b2a2dd
NC
9054 /* PR 18256 */
9055 if (! inst.operands[0].isvec)
9056 {
9057 inst.error = _("invalid co-processor operand");
9058 return FAIL;
9059 }
8335d6aa
JW
9060 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9061 return SUCCESS;
9062 }
9063
9064 inst.instruction |= inst.operands[i].reg << 16;
9065
9066 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9067
9068 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9069 {
9070 gas_assert (!inst.operands[i].writeback);
9071 if (!unind_ok)
9072 {
9073 inst.error = _("instruction does not support unindexed addressing");
9074 return FAIL;
9075 }
9076 inst.instruction |= inst.operands[i].imm;
9077 inst.instruction |= INDEX_UP;
9078 return SUCCESS;
9079 }
9080
9081 if (inst.operands[i].preind)
9082 inst.instruction |= PRE_INDEX;
9083
9084 if (inst.operands[i].writeback)
09d92015 9085 {
8335d6aa 9086 if (inst.operands[i].reg == REG_PC)
c19d1205 9087 {
8335d6aa
JW
9088 inst.error = _("pc may not be used with write-back");
9089 return FAIL;
c19d1205 9090 }
8335d6aa 9091 if (!wb_ok)
c19d1205 9092 {
8335d6aa
JW
9093 inst.error = _("instruction does not support writeback");
9094 return FAIL;
c19d1205 9095 }
8335d6aa 9096 inst.instruction |= WRITE_BACK;
09d92015
MM
9097 }
9098
8335d6aa 9099 if (reloc_override)
e2b0ab59
AV
9100 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9101 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9102 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9103 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 9104 {
8335d6aa 9105 if (thumb_mode)
e2b0ab59 9106 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 9107 else
e2b0ab59 9108 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 9109 }
8335d6aa
JW
9110
9111 /* Prefer + for zero encoded value. */
9112 if (!inst.operands[i].negative)
9113 inst.instruction |= INDEX_UP;
9114
9115 return SUCCESS;
09d92015
MM
9116}
9117
5f4273c7 9118/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
9119 First some generics; their names are taken from the conventional
9120 bit positions for register arguments in ARM format instructions. */
09d92015 9121
a737bd4d 9122static void
c19d1205 9123do_noargs (void)
09d92015 9124{
c19d1205 9125}
a737bd4d 9126
c19d1205
ZW
9127static void
9128do_rd (void)
9129{
9130 inst.instruction |= inst.operands[0].reg << 12;
9131}
a737bd4d 9132
16a1fa25
TP
9133static void
9134do_rn (void)
9135{
9136 inst.instruction |= inst.operands[0].reg << 16;
9137}
9138
c19d1205
ZW
9139static void
9140do_rd_rm (void)
9141{
9142 inst.instruction |= inst.operands[0].reg << 12;
9143 inst.instruction |= inst.operands[1].reg;
9144}
09d92015 9145
9eb6c0f1
MGD
9146static void
9147do_rm_rn (void)
9148{
9149 inst.instruction |= inst.operands[0].reg;
9150 inst.instruction |= inst.operands[1].reg << 16;
9151}
9152
c19d1205
ZW
9153static void
9154do_rd_rn (void)
9155{
9156 inst.instruction |= inst.operands[0].reg << 12;
9157 inst.instruction |= inst.operands[1].reg << 16;
9158}
a737bd4d 9159
c19d1205
ZW
9160static void
9161do_rn_rd (void)
9162{
9163 inst.instruction |= inst.operands[0].reg << 16;
9164 inst.instruction |= inst.operands[1].reg << 12;
9165}
09d92015 9166
4ed7ed8d
TP
9167static void
9168do_tt (void)
9169{
9170 inst.instruction |= inst.operands[0].reg << 8;
9171 inst.instruction |= inst.operands[1].reg << 16;
9172}
9173
59d09be6
MGD
9174static bfd_boolean
9175check_obsolete (const arm_feature_set *feature, const char *msg)
9176{
9177 if (ARM_CPU_IS_ANY (cpu_variant))
9178 {
5c3696f8 9179 as_tsktsk ("%s", msg);
59d09be6
MGD
9180 return TRUE;
9181 }
9182 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9183 {
9184 as_bad ("%s", msg);
9185 return TRUE;
9186 }
9187
9188 return FALSE;
9189}
9190
c19d1205
ZW
9191static void
9192do_rd_rm_rn (void)
9193{
9a64e435 9194 unsigned Rn = inst.operands[2].reg;
708587a4 9195 /* Enforce restrictions on SWP instruction. */
9a64e435 9196 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9197 {
9198 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9199 _("Rn must not overlap other operands"));
9200
59d09be6
MGD
9201 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9202 */
9203 if (!check_obsolete (&arm_ext_v8,
9204 _("swp{b} use is obsoleted for ARMv8 and later"))
9205 && warn_on_deprecated
9206 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9207 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9208 }
59d09be6 9209
c19d1205
ZW
9210 inst.instruction |= inst.operands[0].reg << 12;
9211 inst.instruction |= inst.operands[1].reg;
9a64e435 9212 inst.instruction |= Rn << 16;
c19d1205 9213}
09d92015 9214
c19d1205
ZW
9215static void
9216do_rd_rn_rm (void)
9217{
9218 inst.instruction |= inst.operands[0].reg << 12;
9219 inst.instruction |= inst.operands[1].reg << 16;
9220 inst.instruction |= inst.operands[2].reg;
9221}
a737bd4d 9222
c19d1205
ZW
9223static void
9224do_rm_rd_rn (void)
9225{
5be8be5d 9226 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9227 constraint (((inst.relocs[0].exp.X_op != O_constant
9228 && inst.relocs[0].exp.X_op != O_illegal)
9229 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9230 BAD_ADDR_MODE);
c19d1205
ZW
9231 inst.instruction |= inst.operands[0].reg;
9232 inst.instruction |= inst.operands[1].reg << 12;
9233 inst.instruction |= inst.operands[2].reg << 16;
9234}
09d92015 9235
c19d1205
ZW
9236static void
9237do_imm0 (void)
9238{
9239 inst.instruction |= inst.operands[0].imm;
9240}
09d92015 9241
c19d1205
ZW
9242static void
9243do_rd_cpaddr (void)
9244{
9245 inst.instruction |= inst.operands[0].reg << 12;
9246 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9247}
a737bd4d 9248
c19d1205
ZW
9249/* ARM instructions, in alphabetical order by function name (except
9250 that wrapper functions appear immediately after the function they
9251 wrap). */
09d92015 9252
c19d1205
ZW
9253/* This is a pseudo-op of the form "adr rd, label" to be converted
9254 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9255
9256static void
c19d1205 9257do_adr (void)
09d92015 9258{
c19d1205 9259 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9260
c19d1205
ZW
9261 /* Frag hacking will turn this into a sub instruction if the offset turns
9262 out to be negative. */
e2b0ab59
AV
9263 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9264 inst.relocs[0].pc_rel = 1;
9265 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9266
fc6141f0 9267 if (support_interwork
e2b0ab59
AV
9268 && inst.relocs[0].exp.X_op == O_symbol
9269 && inst.relocs[0].exp.X_add_symbol != NULL
9270 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9271 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9272 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9273}
b99bd4ef 9274
c19d1205
ZW
9275/* This is a pseudo-op of the form "adrl rd, label" to be converted
9276 into a relative address of the form:
9277 add rd, pc, #low(label-.-8)"
9278 add rd, rd, #high(label-.-8)" */
b99bd4ef 9279
c19d1205
ZW
9280static void
9281do_adrl (void)
9282{
9283 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9284
c19d1205
ZW
9285 /* Frag hacking will turn this into a sub instruction if the offset turns
9286 out to be negative. */
e2b0ab59
AV
9287 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9288 inst.relocs[0].pc_rel = 1;
c19d1205 9289 inst.size = INSN_SIZE * 2;
e2b0ab59 9290 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9291
fc6141f0 9292 if (support_interwork
e2b0ab59
AV
9293 && inst.relocs[0].exp.X_op == O_symbol
9294 && inst.relocs[0].exp.X_add_symbol != NULL
9295 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9296 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9297 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9298}
9299
b99bd4ef 9300static void
c19d1205 9301do_arit (void)
b99bd4ef 9302{
e2b0ab59
AV
9303 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9304 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9305 THUMB1_RELOC_ONLY);
c19d1205
ZW
9306 if (!inst.operands[1].present)
9307 inst.operands[1].reg = inst.operands[0].reg;
9308 inst.instruction |= inst.operands[0].reg << 12;
9309 inst.instruction |= inst.operands[1].reg << 16;
9310 encode_arm_shifter_operand (2);
9311}
b99bd4ef 9312
62b3e311
PB
9313static void
9314do_barrier (void)
9315{
9316 if (inst.operands[0].present)
ccb84d65 9317 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9318 else
9319 inst.instruction |= 0xf;
9320}
9321
c19d1205
ZW
9322static void
9323do_bfc (void)
9324{
9325 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9326 constraint (msb > 32, _("bit-field extends past end of register"));
9327 /* The instruction encoding stores the LSB and MSB,
9328 not the LSB and width. */
9329 inst.instruction |= inst.operands[0].reg << 12;
9330 inst.instruction |= inst.operands[1].imm << 7;
9331 inst.instruction |= (msb - 1) << 16;
9332}
b99bd4ef 9333
c19d1205
ZW
9334static void
9335do_bfi (void)
9336{
9337 unsigned int msb;
b99bd4ef 9338
c19d1205
ZW
9339 /* #0 in second position is alternative syntax for bfc, which is
9340 the same instruction but with REG_PC in the Rm field. */
9341 if (!inst.operands[1].isreg)
9342 inst.operands[1].reg = REG_PC;
b99bd4ef 9343
c19d1205
ZW
9344 msb = inst.operands[2].imm + inst.operands[3].imm;
9345 constraint (msb > 32, _("bit-field extends past end of register"));
9346 /* The instruction encoding stores the LSB and MSB,
9347 not the LSB and width. */
9348 inst.instruction |= inst.operands[0].reg << 12;
9349 inst.instruction |= inst.operands[1].reg;
9350 inst.instruction |= inst.operands[2].imm << 7;
9351 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9352}
9353
b99bd4ef 9354static void
c19d1205 9355do_bfx (void)
b99bd4ef 9356{
c19d1205
ZW
9357 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9358 _("bit-field extends past end of register"));
9359 inst.instruction |= inst.operands[0].reg << 12;
9360 inst.instruction |= inst.operands[1].reg;
9361 inst.instruction |= inst.operands[2].imm << 7;
9362 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9363}
09d92015 9364
c19d1205
ZW
9365/* ARM V5 breakpoint instruction (argument parse)
9366 BKPT <16 bit unsigned immediate>
9367 Instruction is not conditional.
9368 The bit pattern given in insns[] has the COND_ALWAYS condition,
9369 and it is an error if the caller tried to override that. */
b99bd4ef 9370
c19d1205
ZW
9371static void
9372do_bkpt (void)
9373{
9374 /* Top 12 of 16 bits to bits 19:8. */
9375 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9376
c19d1205
ZW
9377 /* Bottom 4 of 16 bits to bits 3:0. */
9378 inst.instruction |= inst.operands[0].imm & 0xf;
9379}
09d92015 9380
c19d1205
ZW
9381static void
9382encode_branch (int default_reloc)
9383{
9384 if (inst.operands[0].hasreloc)
9385 {
0855e32b
NS
9386 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9387 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9388 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9389 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9390 ? BFD_RELOC_ARM_PLT32
9391 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9392 }
b99bd4ef 9393 else
e2b0ab59
AV
9394 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9395 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9396}
9397
b99bd4ef 9398static void
c19d1205 9399do_branch (void)
b99bd4ef 9400{
39b41c9c
PB
9401#ifdef OBJ_ELF
9402 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9403 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9404 else
9405#endif
9406 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9407}
9408
9409static void
9410do_bl (void)
9411{
9412#ifdef OBJ_ELF
9413 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9414 {
9415 if (inst.cond == COND_ALWAYS)
9416 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9417 else
9418 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9419 }
9420 else
9421#endif
9422 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9423}
b99bd4ef 9424
c19d1205
ZW
9425/* ARM V5 branch-link-exchange instruction (argument parse)
9426 BLX <target_addr> ie BLX(1)
9427 BLX{<condition>} <Rm> ie BLX(2)
9428 Unfortunately, there are two different opcodes for this mnemonic.
9429 So, the insns[].value is not used, and the code here zaps values
9430 into inst.instruction.
9431 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9432
c19d1205
ZW
9433static void
9434do_blx (void)
9435{
9436 if (inst.operands[0].isreg)
b99bd4ef 9437 {
c19d1205
ZW
9438 /* Arg is a register; the opcode provided by insns[] is correct.
9439 It is not illegal to do "blx pc", just useless. */
9440 if (inst.operands[0].reg == REG_PC)
9441 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9442
c19d1205
ZW
9443 inst.instruction |= inst.operands[0].reg;
9444 }
9445 else
b99bd4ef 9446 {
c19d1205 9447 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9448 conditionally, and the opcode must be adjusted.
9449 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9450 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9451 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9452 inst.instruction = 0xfa000000;
267bf995 9453 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9454 }
c19d1205
ZW
9455}
9456
9457static void
9458do_bx (void)
9459{
845b51d6
PB
9460 bfd_boolean want_reloc;
9461
c19d1205
ZW
9462 if (inst.operands[0].reg == REG_PC)
9463 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9464
c19d1205 9465 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9466 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9467 it is for ARMv4t or earlier. */
9468 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9469 if (!ARM_FEATURE_ZERO (selected_object_arch)
9470 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9471 want_reloc = TRUE;
9472
5ad34203 9473#ifdef OBJ_ELF
845b51d6 9474 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9475#endif
584206db 9476 want_reloc = FALSE;
845b51d6
PB
9477
9478 if (want_reloc)
e2b0ab59 9479 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9480}
9481
c19d1205
ZW
9482
9483/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9484
9485static void
c19d1205 9486do_bxj (void)
a737bd4d 9487{
c19d1205
ZW
9488 if (inst.operands[0].reg == REG_PC)
9489 as_tsktsk (_("use of r15 in bxj is not really useful"));
9490
9491 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9492}
9493
c19d1205
ZW
9494/* Co-processor data operation:
9495 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9496 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9497static void
9498do_cdp (void)
9499{
9500 inst.instruction |= inst.operands[0].reg << 8;
9501 inst.instruction |= inst.operands[1].imm << 20;
9502 inst.instruction |= inst.operands[2].reg << 12;
9503 inst.instruction |= inst.operands[3].reg << 16;
9504 inst.instruction |= inst.operands[4].reg;
9505 inst.instruction |= inst.operands[5].imm << 5;
9506}
a737bd4d
NC
9507
9508static void
c19d1205 9509do_cmp (void)
a737bd4d 9510{
c19d1205
ZW
9511 inst.instruction |= inst.operands[0].reg << 16;
9512 encode_arm_shifter_operand (1);
a737bd4d
NC
9513}
9514
c19d1205
ZW
9515/* Transfer between coprocessor and ARM registers.
9516 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9517 MRC2
9518 MCR{cond}
9519 MCR2
9520
9521 No special properties. */
09d92015 9522
dcbd0d71
MGD
9523struct deprecated_coproc_regs_s
9524{
9525 unsigned cp;
9526 int opc1;
9527 unsigned crn;
9528 unsigned crm;
9529 int opc2;
9530 arm_feature_set deprecated;
9531 arm_feature_set obsoleted;
9532 const char *dep_msg;
9533 const char *obs_msg;
9534};
9535
9536#define DEPR_ACCESS_V8 \
9537 N_("This coprocessor register access is deprecated in ARMv8")
9538
9539/* Table of all deprecated coprocessor registers. */
9540static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9541{
9542 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9543 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9544 DEPR_ACCESS_V8, NULL},
9545 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9546 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9547 DEPR_ACCESS_V8, NULL},
9548 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9549 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9550 DEPR_ACCESS_V8, NULL},
9551 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9552 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9553 DEPR_ACCESS_V8, NULL},
9554 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9555 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9556 DEPR_ACCESS_V8, NULL},
9557};
9558
9559#undef DEPR_ACCESS_V8
9560
9561static const size_t deprecated_coproc_reg_count =
9562 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9563
09d92015 9564static void
c19d1205 9565do_co_reg (void)
09d92015 9566{
fdfde340 9567 unsigned Rd;
dcbd0d71 9568 size_t i;
fdfde340
JM
9569
9570 Rd = inst.operands[2].reg;
9571 if (thumb_mode)
9572 {
9573 if (inst.instruction == 0xee000010
9574 || inst.instruction == 0xfe000010)
9575 /* MCR, MCR2 */
9576 reject_bad_reg (Rd);
5c8ed6a4 9577 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9578 /* MRC, MRC2 */
9579 constraint (Rd == REG_SP, BAD_SP);
9580 }
9581 else
9582 {
9583 /* MCR */
9584 if (inst.instruction == 0xe000010)
9585 constraint (Rd == REG_PC, BAD_PC);
9586 }
9587
dcbd0d71
MGD
9588 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9589 {
9590 const struct deprecated_coproc_regs_s *r =
9591 deprecated_coproc_regs + i;
9592
9593 if (inst.operands[0].reg == r->cp
9594 && inst.operands[1].imm == r->opc1
9595 && inst.operands[3].reg == r->crn
9596 && inst.operands[4].reg == r->crm
9597 && inst.operands[5].imm == r->opc2)
9598 {
b10bf8c5 9599 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9600 && warn_on_deprecated
dcbd0d71 9601 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9602 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9603 }
9604 }
fdfde340 9605
c19d1205
ZW
9606 inst.instruction |= inst.operands[0].reg << 8;
9607 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9608 inst.instruction |= Rd << 12;
c19d1205
ZW
9609 inst.instruction |= inst.operands[3].reg << 16;
9610 inst.instruction |= inst.operands[4].reg;
9611 inst.instruction |= inst.operands[5].imm << 5;
9612}
09d92015 9613
c19d1205
ZW
9614/* Transfer between coprocessor register and pair of ARM registers.
9615 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9616 MCRR2
9617 MRRC{cond}
9618 MRRC2
b99bd4ef 9619
c19d1205 9620 Two XScale instructions are special cases of these:
09d92015 9621
c19d1205
ZW
9622 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9623 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9624
5f4273c7 9625 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9626
c19d1205
ZW
9627static void
9628do_co_reg2c (void)
9629{
fdfde340
JM
9630 unsigned Rd, Rn;
9631
9632 Rd = inst.operands[2].reg;
9633 Rn = inst.operands[3].reg;
9634
9635 if (thumb_mode)
9636 {
9637 reject_bad_reg (Rd);
9638 reject_bad_reg (Rn);
9639 }
9640 else
9641 {
9642 constraint (Rd == REG_PC, BAD_PC);
9643 constraint (Rn == REG_PC, BAD_PC);
9644 }
9645
873f10f0
TC
9646 /* Only check the MRRC{2} variants. */
9647 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9648 {
9649 /* If Rd == Rn, error that the operation is
9650 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9651 constraint (Rd == Rn, BAD_OVERLAP);
9652 }
9653
c19d1205
ZW
9654 inst.instruction |= inst.operands[0].reg << 8;
9655 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9656 inst.instruction |= Rd << 12;
9657 inst.instruction |= Rn << 16;
c19d1205 9658 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9659}
9660
c19d1205
ZW
9661static void
9662do_cpsi (void)
9663{
9664 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9665 if (inst.operands[1].present)
9666 {
9667 inst.instruction |= CPSI_MMOD;
9668 inst.instruction |= inst.operands[1].imm;
9669 }
c19d1205 9670}
b99bd4ef 9671
62b3e311
PB
9672static void
9673do_dbg (void)
9674{
9675 inst.instruction |= inst.operands[0].imm;
9676}
9677
eea54501
MGD
9678static void
9679do_div (void)
9680{
9681 unsigned Rd, Rn, Rm;
9682
9683 Rd = inst.operands[0].reg;
9684 Rn = (inst.operands[1].present
9685 ? inst.operands[1].reg : Rd);
9686 Rm = inst.operands[2].reg;
9687
9688 constraint ((Rd == REG_PC), BAD_PC);
9689 constraint ((Rn == REG_PC), BAD_PC);
9690 constraint ((Rm == REG_PC), BAD_PC);
9691
9692 inst.instruction |= Rd << 16;
9693 inst.instruction |= Rn << 0;
9694 inst.instruction |= Rm << 8;
9695}
9696
b99bd4ef 9697static void
c19d1205 9698do_it (void)
b99bd4ef 9699{
c19d1205 9700 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9701 process it to do the validation as if in
9702 thumb mode, just in case the code gets
9703 assembled for thumb using the unified syntax. */
9704
c19d1205 9705 inst.size = 0;
e07e6e58
NC
9706 if (unified_syntax)
9707 {
5ee91343
AV
9708 set_pred_insn_type (IT_INSN);
9709 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9710 now_pred.cc = inst.operands[0].imm;
e07e6e58 9711 }
09d92015 9712}
b99bd4ef 9713
6530b175
NC
9714/* If there is only one register in the register list,
9715 then return its register number. Otherwise return -1. */
9716static int
9717only_one_reg_in_list (int range)
9718{
9719 int i = ffs (range) - 1;
9720 return (i > 15 || range != (1 << i)) ? -1 : i;
9721}
9722
09d92015 9723static void
6530b175 9724encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9725{
c19d1205
ZW
9726 int base_reg = inst.operands[0].reg;
9727 int range = inst.operands[1].imm;
6530b175 9728 int one_reg;
ea6ef066 9729
c19d1205
ZW
9730 inst.instruction |= base_reg << 16;
9731 inst.instruction |= range;
ea6ef066 9732
c19d1205
ZW
9733 if (inst.operands[1].writeback)
9734 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9735
c19d1205 9736 if (inst.operands[0].writeback)
ea6ef066 9737 {
c19d1205
ZW
9738 inst.instruction |= WRITE_BACK;
9739 /* Check for unpredictable uses of writeback. */
9740 if (inst.instruction & LOAD_BIT)
09d92015 9741 {
c19d1205
ZW
9742 /* Not allowed in LDM type 2. */
9743 if ((inst.instruction & LDM_TYPE_2_OR_3)
9744 && ((range & (1 << REG_PC)) == 0))
9745 as_warn (_("writeback of base register is UNPREDICTABLE"));
9746 /* Only allowed if base reg not in list for other types. */
9747 else if (range & (1 << base_reg))
9748 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9749 }
9750 else /* STM. */
9751 {
9752 /* Not allowed for type 2. */
9753 if (inst.instruction & LDM_TYPE_2_OR_3)
9754 as_warn (_("writeback of base register is UNPREDICTABLE"));
9755 /* Only allowed if base reg not in list, or first in list. */
9756 else if ((range & (1 << base_reg))
9757 && (range & ((1 << base_reg) - 1)))
9758 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9759 }
ea6ef066 9760 }
6530b175
NC
9761
9762 /* If PUSH/POP has only one register, then use the A2 encoding. */
9763 one_reg = only_one_reg_in_list (range);
9764 if (from_push_pop_mnem && one_reg >= 0)
9765 {
9766 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9767
4f588891
NC
9768 if (is_push && one_reg == 13 /* SP */)
9769 /* PR 22483: The A2 encoding cannot be used when
9770 pushing the stack pointer as this is UNPREDICTABLE. */
9771 return;
9772
6530b175
NC
9773 inst.instruction &= A_COND_MASK;
9774 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9775 inst.instruction |= one_reg << 12;
9776 }
9777}
9778
9779static void
9780do_ldmstm (void)
9781{
9782 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9783}
9784
c19d1205
ZW
9785/* ARMv5TE load-consecutive (argument parse)
9786 Mode is like LDRH.
9787
9788 LDRccD R, mode
9789 STRccD R, mode. */
9790
a737bd4d 9791static void
c19d1205 9792do_ldrd (void)
a737bd4d 9793{
c19d1205 9794 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9795 _("first transfer register must be even"));
c19d1205
ZW
9796 constraint (inst.operands[1].present
9797 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9798 _("can only transfer two consecutive registers"));
c19d1205
ZW
9799 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9800 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9801
c19d1205
ZW
9802 if (!inst.operands[1].present)
9803 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9804
c56791bb
RE
9805 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9806 register and the first register written; we have to diagnose
9807 overlap between the base and the second register written here. */
ea6ef066 9808
c56791bb
RE
9809 if (inst.operands[2].reg == inst.operands[1].reg
9810 && (inst.operands[2].writeback || inst.operands[2].postind))
9811 as_warn (_("base register written back, and overlaps "
9812 "second transfer register"));
b05fe5cf 9813
c56791bb
RE
9814 if (!(inst.instruction & V4_STR_BIT))
9815 {
c19d1205 9816 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9817 destination (even if not write-back). */
9818 if (inst.operands[2].immisreg
9819 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9820 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9821 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9822 }
c19d1205
ZW
9823 inst.instruction |= inst.operands[0].reg << 12;
9824 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9825}
9826
9827static void
c19d1205 9828do_ldrex (void)
b05fe5cf 9829{
c19d1205
ZW
9830 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9831 || inst.operands[1].postind || inst.operands[1].writeback
9832 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9833 || inst.operands[1].negative
9834 /* This can arise if the programmer has written
9835 strex rN, rM, foo
9836 or if they have mistakenly used a register name as the last
9837 operand, eg:
9838 strex rN, rM, rX
9839 It is very difficult to distinguish between these two cases
9840 because "rX" might actually be a label. ie the register
9841 name has been occluded by a symbol of the same name. So we
9842 just generate a general 'bad addressing mode' type error
9843 message and leave it up to the programmer to discover the
9844 true cause and fix their mistake. */
9845 || (inst.operands[1].reg == REG_PC),
9846 BAD_ADDR_MODE);
b05fe5cf 9847
e2b0ab59
AV
9848 constraint (inst.relocs[0].exp.X_op != O_constant
9849 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9850 _("offset must be zero in ARM encoding"));
b05fe5cf 9851
5be8be5d
DG
9852 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9853
c19d1205
ZW
9854 inst.instruction |= inst.operands[0].reg << 12;
9855 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9856 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9857}
9858
9859static void
c19d1205 9860do_ldrexd (void)
b05fe5cf 9861{
c19d1205
ZW
9862 constraint (inst.operands[0].reg % 2 != 0,
9863 _("even register required"));
9864 constraint (inst.operands[1].present
9865 && inst.operands[1].reg != inst.operands[0].reg + 1,
9866 _("can only load two consecutive registers"));
9867 /* If op 1 were present and equal to PC, this function wouldn't
9868 have been called in the first place. */
9869 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9870
c19d1205
ZW
9871 inst.instruction |= inst.operands[0].reg << 12;
9872 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9873}
9874
1be5fd2e
NC
9875/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9876 which is not a multiple of four is UNPREDICTABLE. */
9877static void
9878check_ldr_r15_aligned (void)
9879{
9880 constraint (!(inst.operands[1].immisreg)
9881 && (inst.operands[0].reg == REG_PC
9882 && inst.operands[1].reg == REG_PC
e2b0ab59 9883 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9884 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9885}
9886
b05fe5cf 9887static void
c19d1205 9888do_ldst (void)
b05fe5cf 9889{
c19d1205
ZW
9890 inst.instruction |= inst.operands[0].reg << 12;
9891 if (!inst.operands[1].isreg)
8335d6aa 9892 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9893 return;
c19d1205 9894 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9895 check_ldr_r15_aligned ();
b05fe5cf
ZW
9896}
9897
9898static void
c19d1205 9899do_ldstt (void)
b05fe5cf 9900{
c19d1205
ZW
9901 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9902 reject [Rn,...]. */
9903 if (inst.operands[1].preind)
b05fe5cf 9904 {
e2b0ab59
AV
9905 constraint (inst.relocs[0].exp.X_op != O_constant
9906 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9907 _("this instruction requires a post-indexed address"));
b05fe5cf 9908
c19d1205
ZW
9909 inst.operands[1].preind = 0;
9910 inst.operands[1].postind = 1;
9911 inst.operands[1].writeback = 1;
b05fe5cf 9912 }
c19d1205
ZW
9913 inst.instruction |= inst.operands[0].reg << 12;
9914 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9915}
b05fe5cf 9916
c19d1205 9917/* Halfword and signed-byte load/store operations. */
b05fe5cf 9918
c19d1205
ZW
9919static void
9920do_ldstv4 (void)
9921{
ff4a8d2b 9922 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9923 inst.instruction |= inst.operands[0].reg << 12;
9924 if (!inst.operands[1].isreg)
8335d6aa 9925 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9926 return;
c19d1205 9927 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9928}
9929
9930static void
c19d1205 9931do_ldsttv4 (void)
b05fe5cf 9932{
c19d1205
ZW
9933 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9934 reject [Rn,...]. */
9935 if (inst.operands[1].preind)
b05fe5cf 9936 {
e2b0ab59
AV
9937 constraint (inst.relocs[0].exp.X_op != O_constant
9938 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9939 _("this instruction requires a post-indexed address"));
b05fe5cf 9940
c19d1205
ZW
9941 inst.operands[1].preind = 0;
9942 inst.operands[1].postind = 1;
9943 inst.operands[1].writeback = 1;
b05fe5cf 9944 }
c19d1205
ZW
9945 inst.instruction |= inst.operands[0].reg << 12;
9946 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9947}
b05fe5cf 9948
c19d1205
ZW
9949/* Co-processor register load/store.
9950 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9951static void
9952do_lstc (void)
9953{
9954 inst.instruction |= inst.operands[0].reg << 8;
9955 inst.instruction |= inst.operands[1].reg << 12;
9956 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9957}
9958
b05fe5cf 9959static void
c19d1205 9960do_mlas (void)
b05fe5cf 9961{
8fb9d7b9 9962 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9963 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9964 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9965 && !(inst.instruction & 0x00400000))
8fb9d7b9 9966 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9967
c19d1205
ZW
9968 inst.instruction |= inst.operands[0].reg << 16;
9969 inst.instruction |= inst.operands[1].reg;
9970 inst.instruction |= inst.operands[2].reg << 8;
9971 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9972}
b05fe5cf 9973
c19d1205
ZW
9974static void
9975do_mov (void)
9976{
e2b0ab59
AV
9977 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9978 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9979 THUMB1_RELOC_ONLY);
c19d1205
ZW
9980 inst.instruction |= inst.operands[0].reg << 12;
9981 encode_arm_shifter_operand (1);
9982}
b05fe5cf 9983
c19d1205
ZW
9984/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9985static void
9986do_mov16 (void)
9987{
b6895b4f
PB
9988 bfd_vma imm;
9989 bfd_boolean top;
9990
9991 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9992 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9993 _(":lower16: not allowed in this instruction"));
e2b0ab59 9994 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9995 _(":upper16: not allowed in this instruction"));
c19d1205 9996 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9997 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9998 {
e2b0ab59 9999 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
10000 /* The value is in two pieces: 0:11, 16:19. */
10001 inst.instruction |= (imm & 0x00000fff);
10002 inst.instruction |= (imm & 0x0000f000) << 4;
10003 }
b05fe5cf 10004}
b99bd4ef 10005
037e8744
JB
10006static int
10007do_vfp_nsyn_mrs (void)
10008{
10009 if (inst.operands[0].isvec)
10010 {
10011 if (inst.operands[1].reg != 1)
477330fc 10012 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
10013 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10014 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10015 do_vfp_nsyn_opcode ("fmstat");
10016 }
10017 else if (inst.operands[1].isvec)
10018 do_vfp_nsyn_opcode ("fmrx");
10019 else
10020 return FAIL;
5f4273c7 10021
037e8744
JB
10022 return SUCCESS;
10023}
10024
10025static int
10026do_vfp_nsyn_msr (void)
10027{
10028 if (inst.operands[0].isvec)
10029 do_vfp_nsyn_opcode ("fmxr");
10030 else
10031 return FAIL;
10032
10033 return SUCCESS;
10034}
10035
f7c21dc7
NC
10036static void
10037do_vmrs (void)
10038{
10039 unsigned Rt = inst.operands[0].reg;
fa94de6b 10040
16d02dc9 10041 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
10042 {
10043 inst.error = BAD_SP;
10044 return;
10045 }
10046
ba6cd17f
SD
10047 switch (inst.operands[1].reg)
10048 {
10049 /* MVFR2 is only valid for Armv8-A. */
10050 case 5:
10051 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10052 _(BAD_FPU));
10053 break;
10054
10055 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10056 case 1: /* fpscr. */
10057 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10058 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10059 _(BAD_FPU));
10060 break;
10061
10062 case 14: /* fpcxt_ns. */
10063 case 15: /* fpcxt_s. */
10064 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10065 _("selected processor does not support instruction"));
10066 break;
10067
10068 case 2: /* fpscr_nzcvqc. */
10069 case 12: /* vpr. */
10070 case 13: /* p0. */
10071 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10072 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10073 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10074 _("selected processor does not support instruction"));
10075 if (inst.operands[0].reg != 2
10076 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10077 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10078 break;
10079
10080 default:
10081 break;
10082 }
40c7d507 10083
f7c21dc7 10084 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 10085 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
10086 {
10087 inst.error = BAD_PC;
10088 return;
10089 }
10090
16d02dc9
JB
10091 /* If we get through parsing the register name, we just insert the number
10092 generated into the instruction without further validation. */
10093 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
10094 inst.instruction |= (Rt << 12);
10095}
10096
10097static void
10098do_vmsr (void)
10099{
10100 unsigned Rt = inst.operands[1].reg;
fa94de6b 10101
f7c21dc7
NC
10102 if (thumb_mode)
10103 reject_bad_reg (Rt);
10104 else if (Rt == REG_PC)
10105 {
10106 inst.error = BAD_PC;
10107 return;
10108 }
10109
ba6cd17f
SD
10110 switch (inst.operands[0].reg)
10111 {
10112 /* MVFR2 is only valid for Armv8-A. */
10113 case 5:
10114 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10115 _(BAD_FPU));
10116 break;
10117
10118 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10119 case 1: /* fpcr. */
10120 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10121 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10122 _(BAD_FPU));
10123 break;
10124
10125 case 14: /* fpcxt_ns. */
10126 case 15: /* fpcxt_s. */
10127 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10128 _("selected processor does not support instruction"));
10129 break;
10130
10131 case 2: /* fpscr_nzcvqc. */
10132 case 12: /* vpr. */
10133 case 13: /* p0. */
10134 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10135 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10136 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10137 _("selected processor does not support instruction"));
10138 if (inst.operands[0].reg != 2
10139 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10140 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10141 break;
10142
10143 default:
10144 break;
10145 }
40c7d507 10146
16d02dc9
JB
10147 /* If we get through parsing the register name, we just insert the number
10148 generated into the instruction without further validation. */
10149 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10150 inst.instruction |= (Rt << 12);
10151}
10152
b99bd4ef 10153static void
c19d1205 10154do_mrs (void)
b99bd4ef 10155{
90ec0d68
MGD
10156 unsigned br;
10157
037e8744
JB
10158 if (do_vfp_nsyn_mrs () == SUCCESS)
10159 return;
10160
ff4a8d2b 10161 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10162 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10163
10164 if (inst.operands[1].isreg)
10165 {
10166 br = inst.operands[1].reg;
806ab1c0 10167 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10168 as_bad (_("bad register for mrs"));
10169 }
10170 else
10171 {
10172 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10173 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10174 != (PSR_c|PSR_f),
d2cd1205 10175 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10176 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10177 }
10178
10179 inst.instruction |= br;
c19d1205 10180}
b99bd4ef 10181
c19d1205
ZW
10182/* Two possible forms:
10183 "{C|S}PSR_<field>, Rm",
10184 "{C|S}PSR_f, #expression". */
b99bd4ef 10185
c19d1205
ZW
10186static void
10187do_msr (void)
10188{
037e8744
JB
10189 if (do_vfp_nsyn_msr () == SUCCESS)
10190 return;
10191
c19d1205
ZW
10192 inst.instruction |= inst.operands[0].imm;
10193 if (inst.operands[1].isreg)
10194 inst.instruction |= inst.operands[1].reg;
10195 else
b99bd4ef 10196 {
c19d1205 10197 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10198 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10199 inst.relocs[0].pc_rel = 0;
b99bd4ef 10200 }
b99bd4ef
NC
10201}
10202
c19d1205
ZW
10203static void
10204do_mul (void)
a737bd4d 10205{
ff4a8d2b
NC
10206 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10207
c19d1205
ZW
10208 if (!inst.operands[2].present)
10209 inst.operands[2].reg = inst.operands[0].reg;
10210 inst.instruction |= inst.operands[0].reg << 16;
10211 inst.instruction |= inst.operands[1].reg;
10212 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10213
8fb9d7b9
MS
10214 if (inst.operands[0].reg == inst.operands[1].reg
10215 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10216 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10217}
10218
c19d1205
ZW
10219/* Long Multiply Parser
10220 UMULL RdLo, RdHi, Rm, Rs
10221 SMULL RdLo, RdHi, Rm, Rs
10222 UMLAL RdLo, RdHi, Rm, Rs
10223 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10224
10225static void
c19d1205 10226do_mull (void)
b99bd4ef 10227{
c19d1205
ZW
10228 inst.instruction |= inst.operands[0].reg << 12;
10229 inst.instruction |= inst.operands[1].reg << 16;
10230 inst.instruction |= inst.operands[2].reg;
10231 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10232
682b27ad
PB
10233 /* rdhi and rdlo must be different. */
10234 if (inst.operands[0].reg == inst.operands[1].reg)
10235 as_tsktsk (_("rdhi and rdlo must be different"));
10236
10237 /* rdhi, rdlo and rm must all be different before armv6. */
10238 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10239 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10240 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10241 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10242}
b99bd4ef 10243
c19d1205
ZW
10244static void
10245do_nop (void)
10246{
e7495e45
NS
10247 if (inst.operands[0].present
10248 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10249 {
10250 /* Architectural NOP hints are CPSR sets with no bits selected. */
10251 inst.instruction &= 0xf0000000;
e7495e45
NS
10252 inst.instruction |= 0x0320f000;
10253 if (inst.operands[0].present)
10254 inst.instruction |= inst.operands[0].imm;
c19d1205 10255 }
b99bd4ef
NC
10256}
10257
c19d1205
ZW
10258/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10259 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10260 Condition defaults to COND_ALWAYS.
10261 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10262
10263static void
c19d1205 10264do_pkhbt (void)
b99bd4ef 10265{
c19d1205
ZW
10266 inst.instruction |= inst.operands[0].reg << 12;
10267 inst.instruction |= inst.operands[1].reg << 16;
10268 inst.instruction |= inst.operands[2].reg;
10269 if (inst.operands[3].present)
10270 encode_arm_shift (3);
10271}
b99bd4ef 10272
c19d1205 10273/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10274
c19d1205
ZW
10275static void
10276do_pkhtb (void)
10277{
10278 if (!inst.operands[3].present)
b99bd4ef 10279 {
c19d1205
ZW
10280 /* If the shift specifier is omitted, turn the instruction
10281 into pkhbt rd, rm, rn. */
10282 inst.instruction &= 0xfff00010;
10283 inst.instruction |= inst.operands[0].reg << 12;
10284 inst.instruction |= inst.operands[1].reg;
10285 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10286 }
10287 else
10288 {
c19d1205
ZW
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].reg << 16;
10291 inst.instruction |= inst.operands[2].reg;
10292 encode_arm_shift (3);
b99bd4ef
NC
10293 }
10294}
10295
c19d1205 10296/* ARMv5TE: Preload-Cache
60e5ef9f 10297 MP Extensions: Preload for write
c19d1205 10298
60e5ef9f 10299 PLD(W) <addr_mode>
c19d1205
ZW
10300
10301 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10302
10303static void
c19d1205 10304do_pld (void)
b99bd4ef 10305{
c19d1205
ZW
10306 constraint (!inst.operands[0].isreg,
10307 _("'[' expected after PLD mnemonic"));
10308 constraint (inst.operands[0].postind,
10309 _("post-indexed expression used in preload instruction"));
10310 constraint (inst.operands[0].writeback,
10311 _("writeback used in preload instruction"));
10312 constraint (!inst.operands[0].preind,
10313 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10314 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10315}
b99bd4ef 10316
62b3e311
PB
10317/* ARMv7: PLI <addr_mode> */
10318static void
10319do_pli (void)
10320{
10321 constraint (!inst.operands[0].isreg,
10322 _("'[' expected after PLI mnemonic"));
10323 constraint (inst.operands[0].postind,
10324 _("post-indexed expression used in preload instruction"));
10325 constraint (inst.operands[0].writeback,
10326 _("writeback used in preload instruction"));
10327 constraint (!inst.operands[0].preind,
10328 _("unindexed addressing used in preload instruction"));
10329 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10330 inst.instruction &= ~PRE_INDEX;
10331}
10332
c19d1205
ZW
10333static void
10334do_push_pop (void)
10335{
5e0d7f77
MP
10336 constraint (inst.operands[0].writeback,
10337 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10338 inst.operands[1] = inst.operands[0];
10339 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10340 inst.operands[0].isreg = 1;
10341 inst.operands[0].writeback = 1;
10342 inst.operands[0].reg = REG_SP;
6530b175 10343 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10344}
b99bd4ef 10345
c19d1205
ZW
10346/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10347 word at the specified address and the following word
10348 respectively.
10349 Unconditionally executed.
10350 Error if Rn is R15. */
b99bd4ef 10351
c19d1205
ZW
10352static void
10353do_rfe (void)
10354{
10355 inst.instruction |= inst.operands[0].reg << 16;
10356 if (inst.operands[0].writeback)
10357 inst.instruction |= WRITE_BACK;
10358}
b99bd4ef 10359
c19d1205 10360/* ARM V6 ssat (argument parse). */
b99bd4ef 10361
c19d1205
ZW
10362static void
10363do_ssat (void)
10364{
10365 inst.instruction |= inst.operands[0].reg << 12;
10366 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10367 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10368
c19d1205
ZW
10369 if (inst.operands[3].present)
10370 encode_arm_shift (3);
b99bd4ef
NC
10371}
10372
c19d1205 10373/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10374
10375static void
c19d1205 10376do_usat (void)
b99bd4ef 10377{
c19d1205
ZW
10378 inst.instruction |= inst.operands[0].reg << 12;
10379 inst.instruction |= inst.operands[1].imm << 16;
10380 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10381
c19d1205
ZW
10382 if (inst.operands[3].present)
10383 encode_arm_shift (3);
b99bd4ef
NC
10384}
10385
c19d1205 10386/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10387
10388static void
c19d1205 10389do_ssat16 (void)
09d92015 10390{
c19d1205
ZW
10391 inst.instruction |= inst.operands[0].reg << 12;
10392 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10393 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10394}
10395
c19d1205
ZW
10396static void
10397do_usat16 (void)
a737bd4d 10398{
c19d1205
ZW
10399 inst.instruction |= inst.operands[0].reg << 12;
10400 inst.instruction |= inst.operands[1].imm << 16;
10401 inst.instruction |= inst.operands[2].reg;
10402}
a737bd4d 10403
c19d1205
ZW
10404/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10405 preserving the other bits.
a737bd4d 10406
c19d1205
ZW
10407 setend <endian_specifier>, where <endian_specifier> is either
10408 BE or LE. */
a737bd4d 10409
c19d1205
ZW
10410static void
10411do_setend (void)
10412{
12e37cbc
MGD
10413 if (warn_on_deprecated
10414 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10415 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10416
c19d1205
ZW
10417 if (inst.operands[0].imm)
10418 inst.instruction |= 0x200;
a737bd4d
NC
10419}
10420
10421static void
c19d1205 10422do_shift (void)
a737bd4d 10423{
c19d1205
ZW
10424 unsigned int Rm = (inst.operands[1].present
10425 ? inst.operands[1].reg
10426 : inst.operands[0].reg);
a737bd4d 10427
c19d1205
ZW
10428 inst.instruction |= inst.operands[0].reg << 12;
10429 inst.instruction |= Rm;
10430 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10431 {
c19d1205
ZW
10432 inst.instruction |= inst.operands[2].reg << 8;
10433 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10434 /* PR 12854: Error on extraneous shifts. */
10435 constraint (inst.operands[2].shifted,
10436 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10437 }
10438 else
e2b0ab59 10439 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10440}
10441
09d92015 10442static void
3eb17e6b 10443do_smc (void)
09d92015 10444{
ba85f98c
BW
10445 unsigned int value = inst.relocs[0].exp.X_add_number;
10446 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10447
e2b0ab59
AV
10448 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10449 inst.relocs[0].pc_rel = 0;
09d92015
MM
10450}
10451
90ec0d68
MGD
10452static void
10453do_hvc (void)
10454{
e2b0ab59
AV
10455 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10456 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10457}
10458
09d92015 10459static void
c19d1205 10460do_swi (void)
09d92015 10461{
e2b0ab59
AV
10462 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10463 inst.relocs[0].pc_rel = 0;
09d92015
MM
10464}
10465
ddfded2f
MW
10466static void
10467do_setpan (void)
10468{
10469 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10470 _("selected processor does not support SETPAN instruction"));
10471
10472 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10473}
10474
10475static void
10476do_t_setpan (void)
10477{
10478 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10479 _("selected processor does not support SETPAN instruction"));
10480
10481 inst.instruction |= (inst.operands[0].imm << 3);
10482}
10483
c19d1205
ZW
10484/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10485 SMLAxy{cond} Rd,Rm,Rs,Rn
10486 SMLAWy{cond} Rd,Rm,Rs,Rn
10487 Error if any register is R15. */
e16bb312 10488
c19d1205
ZW
10489static void
10490do_smla (void)
e16bb312 10491{
c19d1205
ZW
10492 inst.instruction |= inst.operands[0].reg << 16;
10493 inst.instruction |= inst.operands[1].reg;
10494 inst.instruction |= inst.operands[2].reg << 8;
10495 inst.instruction |= inst.operands[3].reg << 12;
10496}
a737bd4d 10497
c19d1205
ZW
10498/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10499 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10500 Error if any register is R15.
10501 Warning if Rdlo == Rdhi. */
a737bd4d 10502
c19d1205
ZW
10503static void
10504do_smlal (void)
10505{
10506 inst.instruction |= inst.operands[0].reg << 12;
10507 inst.instruction |= inst.operands[1].reg << 16;
10508 inst.instruction |= inst.operands[2].reg;
10509 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10510
c19d1205
ZW
10511 if (inst.operands[0].reg == inst.operands[1].reg)
10512 as_tsktsk (_("rdhi and rdlo must be different"));
10513}
a737bd4d 10514
c19d1205
ZW
10515/* ARM V5E (El Segundo) signed-multiply (argument parse)
10516 SMULxy{cond} Rd,Rm,Rs
10517 Error if any register is R15. */
a737bd4d 10518
c19d1205
ZW
10519static void
10520do_smul (void)
10521{
10522 inst.instruction |= inst.operands[0].reg << 16;
10523 inst.instruction |= inst.operands[1].reg;
10524 inst.instruction |= inst.operands[2].reg << 8;
10525}
a737bd4d 10526
b6702015
PB
10527/* ARM V6 srs (argument parse). The variable fields in the encoding are
10528 the same for both ARM and Thumb-2. */
a737bd4d 10529
c19d1205
ZW
10530static void
10531do_srs (void)
10532{
b6702015
PB
10533 int reg;
10534
10535 if (inst.operands[0].present)
10536 {
10537 reg = inst.operands[0].reg;
fdfde340 10538 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10539 }
10540 else
fdfde340 10541 reg = REG_SP;
b6702015
PB
10542
10543 inst.instruction |= reg << 16;
10544 inst.instruction |= inst.operands[1].imm;
10545 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10546 inst.instruction |= WRITE_BACK;
10547}
a737bd4d 10548
c19d1205 10549/* ARM V6 strex (argument parse). */
a737bd4d 10550
c19d1205
ZW
10551static void
10552do_strex (void)
10553{
10554 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10555 || inst.operands[2].postind || inst.operands[2].writeback
10556 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10557 || inst.operands[2].negative
10558 /* See comment in do_ldrex(). */
10559 || (inst.operands[2].reg == REG_PC),
10560 BAD_ADDR_MODE);
a737bd4d 10561
c19d1205
ZW
10562 constraint (inst.operands[0].reg == inst.operands[1].reg
10563 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10564
e2b0ab59
AV
10565 constraint (inst.relocs[0].exp.X_op != O_constant
10566 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10567 _("offset must be zero in ARM encoding"));
a737bd4d 10568
c19d1205
ZW
10569 inst.instruction |= inst.operands[0].reg << 12;
10570 inst.instruction |= inst.operands[1].reg;
10571 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10572 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10573}
10574
877807f8
NC
10575static void
10576do_t_strexbh (void)
10577{
10578 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10579 || inst.operands[2].postind || inst.operands[2].writeback
10580 || inst.operands[2].immisreg || inst.operands[2].shifted
10581 || inst.operands[2].negative,
10582 BAD_ADDR_MODE);
10583
10584 constraint (inst.operands[0].reg == inst.operands[1].reg
10585 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10586
10587 do_rm_rd_rn ();
10588}
10589
e16bb312 10590static void
c19d1205 10591do_strexd (void)
e16bb312 10592{
c19d1205
ZW
10593 constraint (inst.operands[1].reg % 2 != 0,
10594 _("even register required"));
10595 constraint (inst.operands[2].present
10596 && inst.operands[2].reg != inst.operands[1].reg + 1,
10597 _("can only store two consecutive registers"));
10598 /* If op 2 were present and equal to PC, this function wouldn't
10599 have been called in the first place. */
10600 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10601
c19d1205
ZW
10602 constraint (inst.operands[0].reg == inst.operands[1].reg
10603 || inst.operands[0].reg == inst.operands[1].reg + 1
10604 || inst.operands[0].reg == inst.operands[3].reg,
10605 BAD_OVERLAP);
e16bb312 10606
c19d1205
ZW
10607 inst.instruction |= inst.operands[0].reg << 12;
10608 inst.instruction |= inst.operands[1].reg;
10609 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10610}
10611
9eb6c0f1
MGD
10612/* ARM V8 STRL. */
10613static void
4b8c8c02 10614do_stlex (void)
9eb6c0f1
MGD
10615{
10616 constraint (inst.operands[0].reg == inst.operands[1].reg
10617 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10618
10619 do_rd_rm_rn ();
10620}
10621
10622static void
4b8c8c02 10623do_t_stlex (void)
9eb6c0f1
MGD
10624{
10625 constraint (inst.operands[0].reg == inst.operands[1].reg
10626 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10627
10628 do_rm_rd_rn ();
10629}
10630
c19d1205
ZW
10631/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10632 extends it to 32-bits, and adds the result to a value in another
10633 register. You can specify a rotation by 0, 8, 16, or 24 bits
10634 before extracting the 16-bit value.
10635 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10636 Condition defaults to COND_ALWAYS.
10637 Error if any register uses R15. */
10638
e16bb312 10639static void
c19d1205 10640do_sxtah (void)
e16bb312 10641{
c19d1205
ZW
10642 inst.instruction |= inst.operands[0].reg << 12;
10643 inst.instruction |= inst.operands[1].reg << 16;
10644 inst.instruction |= inst.operands[2].reg;
10645 inst.instruction |= inst.operands[3].imm << 10;
10646}
e16bb312 10647
c19d1205 10648/* ARM V6 SXTH.
e16bb312 10649
c19d1205
ZW
10650 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10651 Condition defaults to COND_ALWAYS.
10652 Error if any register uses R15. */
e16bb312
NC
10653
10654static void
c19d1205 10655do_sxth (void)
e16bb312 10656{
c19d1205
ZW
10657 inst.instruction |= inst.operands[0].reg << 12;
10658 inst.instruction |= inst.operands[1].reg;
10659 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10660}
c19d1205
ZW
10661\f
10662/* VFP instructions. In a logical order: SP variant first, monad
10663 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10664
10665static void
c19d1205 10666do_vfp_sp_monadic (void)
e16bb312 10667{
57785aa2
AV
10668 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10669 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10670 _(BAD_FPU));
10671
5287ad62
JB
10672 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10673 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10674}
10675
10676static void
c19d1205 10677do_vfp_sp_dyadic (void)
e16bb312 10678{
5287ad62
JB
10679 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10680 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10681 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10682}
10683
10684static void
c19d1205 10685do_vfp_sp_compare_z (void)
e16bb312 10686{
5287ad62 10687 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10688}
10689
10690static void
c19d1205 10691do_vfp_dp_sp_cvt (void)
e16bb312 10692{
5287ad62
JB
10693 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10694 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10695}
10696
10697static void
c19d1205 10698do_vfp_sp_dp_cvt (void)
e16bb312 10699{
5287ad62
JB
10700 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10701 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10702}
10703
10704static void
c19d1205 10705do_vfp_reg_from_sp (void)
e16bb312 10706{
57785aa2
AV
10707 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10708 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10709 _(BAD_FPU));
10710
c19d1205 10711 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10712 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10713}
10714
10715static void
c19d1205 10716do_vfp_reg2_from_sp2 (void)
e16bb312 10717{
c19d1205
ZW
10718 constraint (inst.operands[2].imm != 2,
10719 _("only two consecutive VFP SP registers allowed here"));
10720 inst.instruction |= inst.operands[0].reg << 12;
10721 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10722 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10723}
10724
10725static void
c19d1205 10726do_vfp_sp_from_reg (void)
e16bb312 10727{
57785aa2
AV
10728 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10729 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10730 _(BAD_FPU));
10731
5287ad62 10732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10733 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10734}
10735
10736static void
c19d1205 10737do_vfp_sp2_from_reg2 (void)
e16bb312 10738{
c19d1205
ZW
10739 constraint (inst.operands[0].imm != 2,
10740 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10742 inst.instruction |= inst.operands[1].reg << 12;
10743 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10744}
10745
10746static void
c19d1205 10747do_vfp_sp_ldst (void)
e16bb312 10748{
5287ad62 10749 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10750 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10751}
10752
10753static void
c19d1205 10754do_vfp_dp_ldst (void)
e16bb312 10755{
5287ad62 10756 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10757 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10758}
10759
c19d1205 10760
e16bb312 10761static void
c19d1205 10762vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10763{
c19d1205
ZW
10764 if (inst.operands[0].writeback)
10765 inst.instruction |= WRITE_BACK;
10766 else
10767 constraint (ldstm_type != VFP_LDSTMIA,
10768 _("this addressing mode requires base-register writeback"));
10769 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10770 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10771 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10772}
10773
10774static void
c19d1205 10775vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10776{
c19d1205 10777 int count;
e16bb312 10778
c19d1205
ZW
10779 if (inst.operands[0].writeback)
10780 inst.instruction |= WRITE_BACK;
10781 else
10782 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10783 _("this addressing mode requires base-register writeback"));
e16bb312 10784
c19d1205 10785 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10786 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10787
c19d1205
ZW
10788 count = inst.operands[1].imm << 1;
10789 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10790 count += 1;
e16bb312 10791
c19d1205 10792 inst.instruction |= count;
e16bb312
NC
10793}
10794
10795static void
c19d1205 10796do_vfp_sp_ldstmia (void)
e16bb312 10797{
c19d1205 10798 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10799}
10800
10801static void
c19d1205 10802do_vfp_sp_ldstmdb (void)
e16bb312 10803{
c19d1205 10804 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10805}
10806
10807static void
c19d1205 10808do_vfp_dp_ldstmia (void)
e16bb312 10809{
c19d1205 10810 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10811}
10812
10813static void
c19d1205 10814do_vfp_dp_ldstmdb (void)
e16bb312 10815{
c19d1205 10816 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10817}
10818
10819static void
c19d1205 10820do_vfp_xp_ldstmia (void)
e16bb312 10821{
c19d1205
ZW
10822 vfp_dp_ldstm (VFP_LDSTMIAX);
10823}
e16bb312 10824
c19d1205
ZW
10825static void
10826do_vfp_xp_ldstmdb (void)
10827{
10828 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10829}
5287ad62
JB
10830
10831static void
10832do_vfp_dp_rd_rm (void)
10833{
57785aa2
AV
10834 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10835 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10836 _(BAD_FPU));
10837
5287ad62
JB
10838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10839 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10840}
10841
10842static void
10843do_vfp_dp_rn_rd (void)
10844{
10845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10846 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10847}
10848
10849static void
10850do_vfp_dp_rd_rn (void)
10851{
10852 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10853 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10854}
10855
10856static void
10857do_vfp_dp_rd_rn_rm (void)
10858{
57785aa2
AV
10859 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10860 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10861 _(BAD_FPU));
10862
5287ad62
JB
10863 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10864 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10865 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10866}
10867
10868static void
10869do_vfp_dp_rd (void)
10870{
10871 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10872}
10873
10874static void
10875do_vfp_dp_rm_rd_rn (void)
10876{
57785aa2
AV
10877 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10878 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10879 _(BAD_FPU));
10880
5287ad62
JB
10881 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10882 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10883 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10884}
10885
10886/* VFPv3 instructions. */
10887static void
10888do_vfp_sp_const (void)
10889{
10890 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10891 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10892 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10893}
10894
10895static void
10896do_vfp_dp_const (void)
10897{
10898 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10899 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10900 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10901}
10902
10903static void
10904vfp_conv (int srcsize)
10905{
5f1af56b
MGD
10906 int immbits = srcsize - inst.operands[1].imm;
10907
fa94de6b
RM
10908 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10909 {
5f1af56b 10910 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10911 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10912 inst.error = _("immediate value out of range, expected range [0, 16]");
10913 return;
10914 }
fa94de6b 10915 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10916 {
10917 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10918 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10919 inst.error = _("immediate value out of range, expected range [1, 32]");
10920 return;
10921 }
10922
5287ad62
JB
10923 inst.instruction |= (immbits & 1) << 5;
10924 inst.instruction |= (immbits >> 1);
10925}
10926
10927static void
10928do_vfp_sp_conv_16 (void)
10929{
10930 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10931 vfp_conv (16);
10932}
10933
10934static void
10935do_vfp_dp_conv_16 (void)
10936{
10937 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10938 vfp_conv (16);
10939}
10940
10941static void
10942do_vfp_sp_conv_32 (void)
10943{
10944 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10945 vfp_conv (32);
10946}
10947
10948static void
10949do_vfp_dp_conv_32 (void)
10950{
10951 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10952 vfp_conv (32);
10953}
c19d1205
ZW
10954\f
10955/* FPA instructions. Also in a logical order. */
e16bb312 10956
c19d1205
ZW
10957static void
10958do_fpa_cmp (void)
10959{
10960 inst.instruction |= inst.operands[0].reg << 16;
10961 inst.instruction |= inst.operands[1].reg;
10962}
b99bd4ef
NC
10963
10964static void
c19d1205 10965do_fpa_ldmstm (void)
b99bd4ef 10966{
c19d1205
ZW
10967 inst.instruction |= inst.operands[0].reg << 12;
10968 switch (inst.operands[1].imm)
10969 {
10970 case 1: inst.instruction |= CP_T_X; break;
10971 case 2: inst.instruction |= CP_T_Y; break;
10972 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10973 case 4: break;
10974 default: abort ();
10975 }
b99bd4ef 10976
c19d1205
ZW
10977 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10978 {
10979 /* The instruction specified "ea" or "fd", so we can only accept
10980 [Rn]{!}. The instruction does not really support stacking or
10981 unstacking, so we have to emulate these by setting appropriate
10982 bits and offsets. */
e2b0ab59
AV
10983 constraint (inst.relocs[0].exp.X_op != O_constant
10984 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10985 _("this instruction does not support indexing"));
b99bd4ef 10986
c19d1205 10987 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10988 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10989
c19d1205 10990 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10991 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10992
c19d1205
ZW
10993 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10994 {
10995 inst.operands[2].preind = 0;
10996 inst.operands[2].postind = 1;
10997 }
10998 }
b99bd4ef 10999
c19d1205 11000 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 11001}
c19d1205
ZW
11002\f
11003/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 11004
c19d1205
ZW
11005static void
11006do_iwmmxt_tandorc (void)
11007{
11008 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11009}
b99bd4ef 11010
c19d1205
ZW
11011static void
11012do_iwmmxt_textrc (void)
11013{
11014 inst.instruction |= inst.operands[0].reg << 12;
11015 inst.instruction |= inst.operands[1].imm;
11016}
b99bd4ef
NC
11017
11018static void
c19d1205 11019do_iwmmxt_textrm (void)
b99bd4ef 11020{
c19d1205
ZW
11021 inst.instruction |= inst.operands[0].reg << 12;
11022 inst.instruction |= inst.operands[1].reg << 16;
11023 inst.instruction |= inst.operands[2].imm;
11024}
b99bd4ef 11025
c19d1205
ZW
11026static void
11027do_iwmmxt_tinsr (void)
11028{
11029 inst.instruction |= inst.operands[0].reg << 16;
11030 inst.instruction |= inst.operands[1].reg << 12;
11031 inst.instruction |= inst.operands[2].imm;
11032}
b99bd4ef 11033
c19d1205
ZW
11034static void
11035do_iwmmxt_tmia (void)
11036{
11037 inst.instruction |= inst.operands[0].reg << 5;
11038 inst.instruction |= inst.operands[1].reg;
11039 inst.instruction |= inst.operands[2].reg << 12;
11040}
b99bd4ef 11041
c19d1205
ZW
11042static void
11043do_iwmmxt_waligni (void)
11044{
11045 inst.instruction |= inst.operands[0].reg << 12;
11046 inst.instruction |= inst.operands[1].reg << 16;
11047 inst.instruction |= inst.operands[2].reg;
11048 inst.instruction |= inst.operands[3].imm << 20;
11049}
b99bd4ef 11050
2d447fca
JM
11051static void
11052do_iwmmxt_wmerge (void)
11053{
11054 inst.instruction |= inst.operands[0].reg << 12;
11055 inst.instruction |= inst.operands[1].reg << 16;
11056 inst.instruction |= inst.operands[2].reg;
11057 inst.instruction |= inst.operands[3].imm << 21;
11058}
11059
c19d1205
ZW
11060static void
11061do_iwmmxt_wmov (void)
11062{
11063 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11064 inst.instruction |= inst.operands[0].reg << 12;
11065 inst.instruction |= inst.operands[1].reg << 16;
11066 inst.instruction |= inst.operands[1].reg;
11067}
b99bd4ef 11068
c19d1205
ZW
11069static void
11070do_iwmmxt_wldstbh (void)
11071{
8f06b2d8 11072 int reloc;
c19d1205 11073 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
11074 if (thumb_mode)
11075 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11076 else
11077 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11078 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
11079}
11080
c19d1205
ZW
11081static void
11082do_iwmmxt_wldstw (void)
11083{
11084 /* RIWR_RIWC clears .isreg for a control register. */
11085 if (!inst.operands[0].isreg)
11086 {
11087 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11088 inst.instruction |= 0xf0000000;
11089 }
b99bd4ef 11090
c19d1205
ZW
11091 inst.instruction |= inst.operands[0].reg << 12;
11092 encode_arm_cp_address (1, TRUE, TRUE, 0);
11093}
b99bd4ef
NC
11094
11095static void
c19d1205 11096do_iwmmxt_wldstd (void)
b99bd4ef 11097{
c19d1205 11098 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
11099 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11100 && inst.operands[1].immisreg)
11101 {
11102 inst.instruction &= ~0x1a000ff;
eff0bc54 11103 inst.instruction |= (0xfU << 28);
2d447fca
JM
11104 if (inst.operands[1].preind)
11105 inst.instruction |= PRE_INDEX;
11106 if (!inst.operands[1].negative)
11107 inst.instruction |= INDEX_UP;
11108 if (inst.operands[1].writeback)
11109 inst.instruction |= WRITE_BACK;
11110 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11111 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
11112 inst.instruction |= inst.operands[1].imm;
11113 }
11114 else
11115 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 11116}
b99bd4ef 11117
c19d1205
ZW
11118static void
11119do_iwmmxt_wshufh (void)
11120{
11121 inst.instruction |= inst.operands[0].reg << 12;
11122 inst.instruction |= inst.operands[1].reg << 16;
11123 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11124 inst.instruction |= (inst.operands[2].imm & 0x0f);
11125}
b99bd4ef 11126
c19d1205
ZW
11127static void
11128do_iwmmxt_wzero (void)
11129{
11130 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11131 inst.instruction |= inst.operands[0].reg;
11132 inst.instruction |= inst.operands[0].reg << 12;
11133 inst.instruction |= inst.operands[0].reg << 16;
11134}
2d447fca
JM
11135
11136static void
11137do_iwmmxt_wrwrwr_or_imm5 (void)
11138{
11139 if (inst.operands[2].isreg)
11140 do_rd_rn_rm ();
11141 else {
11142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11143 _("immediate operand requires iWMMXt2"));
11144 do_rd_rn ();
11145 if (inst.operands[2].imm == 0)
11146 {
11147 switch ((inst.instruction >> 20) & 0xf)
11148 {
11149 case 4:
11150 case 5:
11151 case 6:
5f4273c7 11152 case 7:
2d447fca
JM
11153 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11154 inst.operands[2].imm = 16;
11155 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11156 break;
11157 case 8:
11158 case 9:
11159 case 10:
11160 case 11:
11161 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11162 inst.operands[2].imm = 32;
11163 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11164 break;
11165 case 12:
11166 case 13:
11167 case 14:
11168 case 15:
11169 {
11170 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11171 unsigned long wrn;
11172 wrn = (inst.instruction >> 16) & 0xf;
11173 inst.instruction &= 0xff0fff0f;
11174 inst.instruction |= wrn;
11175 /* Bail out here; the instruction is now assembled. */
11176 return;
11177 }
11178 }
11179 }
11180 /* Map 32 -> 0, etc. */
11181 inst.operands[2].imm &= 0x1f;
eff0bc54 11182 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11183 }
11184}
c19d1205
ZW
11185\f
11186/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11187 operations first, then control, shift, and load/store. */
b99bd4ef 11188
c19d1205 11189/* Insns like "foo X,Y,Z". */
b99bd4ef 11190
c19d1205
ZW
11191static void
11192do_mav_triple (void)
11193{
11194 inst.instruction |= inst.operands[0].reg << 16;
11195 inst.instruction |= inst.operands[1].reg;
11196 inst.instruction |= inst.operands[2].reg << 12;
11197}
b99bd4ef 11198
c19d1205
ZW
11199/* Insns like "foo W,X,Y,Z".
11200 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11201
c19d1205
ZW
11202static void
11203do_mav_quad (void)
11204{
11205 inst.instruction |= inst.operands[0].reg << 5;
11206 inst.instruction |= inst.operands[1].reg << 12;
11207 inst.instruction |= inst.operands[2].reg << 16;
11208 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11209}
11210
c19d1205
ZW
11211/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11212static void
11213do_mav_dspsc (void)
a737bd4d 11214{
c19d1205
ZW
11215 inst.instruction |= inst.operands[1].reg << 12;
11216}
a737bd4d 11217
c19d1205
ZW
11218/* Maverick shift immediate instructions.
11219 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11220 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11221
c19d1205
ZW
11222static void
11223do_mav_shift (void)
11224{
11225 int imm = inst.operands[2].imm;
a737bd4d 11226
c19d1205
ZW
11227 inst.instruction |= inst.operands[0].reg << 12;
11228 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11229
c19d1205
ZW
11230 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11231 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11232 Bit 4 should be 0. */
11233 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11234
c19d1205
ZW
11235 inst.instruction |= imm;
11236}
11237\f
11238/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11239
c19d1205
ZW
11240/* Xscale multiply-accumulate (argument parse)
11241 MIAcc acc0,Rm,Rs
11242 MIAPHcc acc0,Rm,Rs
11243 MIAxycc acc0,Rm,Rs. */
a737bd4d 11244
c19d1205
ZW
11245static void
11246do_xsc_mia (void)
11247{
11248 inst.instruction |= inst.operands[1].reg;
11249 inst.instruction |= inst.operands[2].reg << 12;
11250}
a737bd4d 11251
c19d1205 11252/* Xscale move-accumulator-register (argument parse)
a737bd4d 11253
c19d1205 11254 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11255
c19d1205
ZW
11256static void
11257do_xsc_mar (void)
11258{
11259 inst.instruction |= inst.operands[1].reg << 12;
11260 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11261}
11262
c19d1205 11263/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11264
c19d1205 11265 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11266
11267static void
c19d1205 11268do_xsc_mra (void)
b99bd4ef 11269{
c19d1205
ZW
11270 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11271 inst.instruction |= inst.operands[0].reg << 12;
11272 inst.instruction |= inst.operands[1].reg << 16;
11273}
11274\f
11275/* Encoding functions relevant only to Thumb. */
b99bd4ef 11276
c19d1205
ZW
11277/* inst.operands[i] is a shifted-register operand; encode
11278 it into inst.instruction in the format used by Thumb32. */
11279
11280static void
11281encode_thumb32_shifted_operand (int i)
11282{
e2b0ab59 11283 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11284 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11285
9c3c69f2
PB
11286 constraint (inst.operands[i].immisreg,
11287 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11288 inst.instruction |= inst.operands[i].reg;
11289 if (shift == SHIFT_RRX)
11290 inst.instruction |= SHIFT_ROR << 4;
11291 else
b99bd4ef 11292 {
e2b0ab59 11293 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11294 _("expression too complex"));
11295
11296 constraint (value > 32
11297 || (value == 32 && (shift == SHIFT_LSL
11298 || shift == SHIFT_ROR)),
11299 _("shift expression is too large"));
11300
11301 if (value == 0)
11302 shift = SHIFT_LSL;
11303 else if (value == 32)
11304 value = 0;
11305
11306 inst.instruction |= shift << 4;
11307 inst.instruction |= (value & 0x1c) << 10;
11308 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11309 }
c19d1205 11310}
b99bd4ef 11311
b99bd4ef 11312
c19d1205
ZW
11313/* inst.operands[i] was set up by parse_address. Encode it into a
11314 Thumb32 format load or store instruction. Reject forms that cannot
11315 be used with such instructions. If is_t is true, reject forms that
11316 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11317 that cannot be used with a D instruction. If it is a store insn,
11318 reject PC in Rn. */
b99bd4ef 11319
c19d1205
ZW
11320static void
11321encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11322{
5be8be5d 11323 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11324
11325 constraint (!inst.operands[i].isreg,
53365c0d 11326 _("Instruction does not support =N addresses"));
b99bd4ef 11327
c19d1205
ZW
11328 inst.instruction |= inst.operands[i].reg << 16;
11329 if (inst.operands[i].immisreg)
b99bd4ef 11330 {
5be8be5d 11331 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11332 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11333 constraint (inst.operands[i].negative,
11334 _("Thumb does not support negative register indexing"));
11335 constraint (inst.operands[i].postind,
11336 _("Thumb does not support register post-indexing"));
11337 constraint (inst.operands[i].writeback,
11338 _("Thumb does not support register indexing with writeback"));
11339 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11340 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11341
f40d1643 11342 inst.instruction |= inst.operands[i].imm;
c19d1205 11343 if (inst.operands[i].shifted)
b99bd4ef 11344 {
e2b0ab59 11345 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11346 _("expression too complex"));
e2b0ab59
AV
11347 constraint (inst.relocs[0].exp.X_add_number < 0
11348 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11349 _("shift out of range"));
e2b0ab59 11350 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11351 }
e2b0ab59 11352 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11353 }
11354 else if (inst.operands[i].preind)
11355 {
5be8be5d 11356 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11357 constraint (is_t && inst.operands[i].writeback,
c19d1205 11358 _("cannot use writeback with this instruction"));
4755303e
WN
11359 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11360 BAD_PC_ADDRESSING);
c19d1205
ZW
11361
11362 if (is_d)
11363 {
11364 inst.instruction |= 0x01000000;
11365 if (inst.operands[i].writeback)
11366 inst.instruction |= 0x00200000;
b99bd4ef 11367 }
c19d1205 11368 else
b99bd4ef 11369 {
c19d1205
ZW
11370 inst.instruction |= 0x00000c00;
11371 if (inst.operands[i].writeback)
11372 inst.instruction |= 0x00000100;
b99bd4ef 11373 }
e2b0ab59 11374 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11375 }
c19d1205 11376 else if (inst.operands[i].postind)
b99bd4ef 11377 {
9c2799c2 11378 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11379 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11380 constraint (is_t, _("cannot use post-indexing with this instruction"));
11381
11382 if (is_d)
11383 inst.instruction |= 0x00200000;
11384 else
11385 inst.instruction |= 0x00000900;
e2b0ab59 11386 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11387 }
11388 else /* unindexed - only for coprocessor */
11389 inst.error = _("instruction does not accept unindexed addressing");
11390}
11391
e39c1607 11392/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11393 encodings (the latter only in post-V6T2 cores). The index is the
11394 value used in the insns table below. When there is more than one
11395 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11396 holds variant (1).
11397 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11398#define T16_32_TAB \
21d799b5
NC
11399 X(_adc, 4140, eb400000), \
11400 X(_adcs, 4140, eb500000), \
11401 X(_add, 1c00, eb000000), \
11402 X(_adds, 1c00, eb100000), \
11403 X(_addi, 0000, f1000000), \
11404 X(_addis, 0000, f1100000), \
11405 X(_add_pc,000f, f20f0000), \
11406 X(_add_sp,000d, f10d0000), \
11407 X(_adr, 000f, f20f0000), \
11408 X(_and, 4000, ea000000), \
11409 X(_ands, 4000, ea100000), \
11410 X(_asr, 1000, fa40f000), \
11411 X(_asrs, 1000, fa50f000), \
11412 X(_b, e000, f000b000), \
11413 X(_bcond, d000, f0008000), \
4389b29a 11414 X(_bf, 0000, f040e001), \
f6b2b12d 11415 X(_bfcsel,0000, f000e001), \
f1c7f421 11416 X(_bfx, 0000, f060e001), \
65d1bc05 11417 X(_bfl, 0000, f000c001), \
f1c7f421 11418 X(_bflx, 0000, f070e001), \
21d799b5
NC
11419 X(_bic, 4380, ea200000), \
11420 X(_bics, 4380, ea300000), \
e39c1607
SD
11421 X(_cinc, 0000, ea509000), \
11422 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11423 X(_cmn, 42c0, eb100f00), \
11424 X(_cmp, 2800, ebb00f00), \
e39c1607 11425 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11426 X(_cpsie, b660, f3af8400), \
11427 X(_cpsid, b670, f3af8600), \
11428 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11429 X(_csel, 0000, ea508000), \
11430 X(_cset, 0000, ea5f900f), \
11431 X(_csetm, 0000, ea5fa00f), \
11432 X(_csinc, 0000, ea509000), \
11433 X(_csinv, 0000, ea50a000), \
11434 X(_csneg, 0000, ea50b000), \
21d799b5 11435 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11436 X(_dls, 0000, f040e001), \
1f6234a3 11437 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11438 X(_eor, 4040, ea800000), \
11439 X(_eors, 4040, ea900000), \
11440 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11441 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11442 X(_ldmia, c800, e8900000), \
11443 X(_ldr, 6800, f8500000), \
11444 X(_ldrb, 7800, f8100000), \
11445 X(_ldrh, 8800, f8300000), \
11446 X(_ldrsb, 5600, f9100000), \
11447 X(_ldrsh, 5e00, f9300000), \
11448 X(_ldr_pc,4800, f85f0000), \
11449 X(_ldr_pc2,4800, f85f0000), \
11450 X(_ldr_sp,9800, f85d0000), \
60f993ce 11451 X(_le, 0000, f00fc001), \
1f6234a3 11452 X(_letp, 0000, f01fc001), \
21d799b5
NC
11453 X(_lsl, 0000, fa00f000), \
11454 X(_lsls, 0000, fa10f000), \
11455 X(_lsr, 0800, fa20f000), \
11456 X(_lsrs, 0800, fa30f000), \
11457 X(_mov, 2000, ea4f0000), \
11458 X(_movs, 2000, ea5f0000), \
11459 X(_mul, 4340, fb00f000), \
11460 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11461 X(_mvn, 43c0, ea6f0000), \
11462 X(_mvns, 43c0, ea7f0000), \
11463 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11464 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11465 X(_orr, 4300, ea400000), \
11466 X(_orrs, 4300, ea500000), \
11467 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11468 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11469 X(_rev, ba00, fa90f080), \
11470 X(_rev16, ba40, fa90f090), \
11471 X(_revsh, bac0, fa90f0b0), \
11472 X(_ror, 41c0, fa60f000), \
11473 X(_rors, 41c0, fa70f000), \
11474 X(_sbc, 4180, eb600000), \
11475 X(_sbcs, 4180, eb700000), \
11476 X(_stmia, c000, e8800000), \
11477 X(_str, 6000, f8400000), \
11478 X(_strb, 7000, f8000000), \
11479 X(_strh, 8000, f8200000), \
11480 X(_str_sp,9000, f84d0000), \
11481 X(_sub, 1e00, eba00000), \
11482 X(_subs, 1e00, ebb00000), \
11483 X(_subi, 8000, f1a00000), \
11484 X(_subis, 8000, f1b00000), \
11485 X(_sxtb, b240, fa4ff080), \
11486 X(_sxth, b200, fa0ff080), \
11487 X(_tst, 4200, ea100f00), \
11488 X(_uxtb, b2c0, fa5ff080), \
11489 X(_uxth, b280, fa1ff080), \
11490 X(_nop, bf00, f3af8000), \
11491 X(_yield, bf10, f3af8001), \
11492 X(_wfe, bf20, f3af8002), \
11493 X(_wfi, bf30, f3af8003), \
60f993ce 11494 X(_wls, 0000, f040c001), \
1f6234a3 11495 X(_wlstp, 0000, f000c001), \
53c4b28b 11496 X(_sev, bf40, f3af8004), \
74db7efb
NC
11497 X(_sevl, bf50, f3af8005), \
11498 X(_udf, de00, f7f0a000)
c19d1205
ZW
11499
11500/* To catch errors in encoding functions, the codes are all offset by
11501 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11502 as 16-bit instructions. */
21d799b5 11503#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11504enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11505#undef X
11506
11507#define X(a,b,c) 0x##b
11508static const unsigned short thumb_op16[] = { T16_32_TAB };
11509#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11510#undef X
11511
11512#define X(a,b,c) 0x##c
11513static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11514#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11515#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11516#undef X
11517#undef T16_32_TAB
11518
11519/* Thumb instruction encoders, in alphabetical order. */
11520
92e90b6e 11521/* ADDW or SUBW. */
c921be7d 11522
92e90b6e
PB
11523static void
11524do_t_add_sub_w (void)
11525{
11526 int Rd, Rn;
11527
11528 Rd = inst.operands[0].reg;
11529 Rn = inst.operands[1].reg;
11530
539d4391
NC
11531 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11532 is the SP-{plus,minus}-immediate form of the instruction. */
11533 if (Rn == REG_SP)
11534 constraint (Rd == REG_PC, BAD_PC);
11535 else
11536 reject_bad_reg (Rd);
fdfde340 11537
92e90b6e 11538 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11539 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11540}
11541
c19d1205 11542/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11543 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11544
11545static void
11546do_t_add_sub (void)
11547{
11548 int Rd, Rs, Rn;
11549
11550 Rd = inst.operands[0].reg;
11551 Rs = (inst.operands[1].present
11552 ? inst.operands[1].reg /* Rd, Rs, foo */
11553 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11554
e07e6e58 11555 if (Rd == REG_PC)
5ee91343 11556 set_pred_insn_type_last ();
e07e6e58 11557
c19d1205
ZW
11558 if (unified_syntax)
11559 {
0110f2b8
PB
11560 bfd_boolean flags;
11561 bfd_boolean narrow;
11562 int opcode;
11563
11564 flags = (inst.instruction == T_MNEM_adds
11565 || inst.instruction == T_MNEM_subs);
11566 if (flags)
5ee91343 11567 narrow = !in_pred_block ();
0110f2b8 11568 else
5ee91343 11569 narrow = in_pred_block ();
c19d1205 11570 if (!inst.operands[2].isreg)
b99bd4ef 11571 {
16805f35
PB
11572 int add;
11573
5c8ed6a4
JW
11574 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11575 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11576
16805f35
PB
11577 add = (inst.instruction == T_MNEM_add
11578 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11579 opcode = 0;
11580 if (inst.size_req != 4)
11581 {
0110f2b8 11582 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11583 appropriate. */
0110f2b8
PB
11584 if (Rd == REG_SP && Rs == REG_SP && !flags)
11585 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11586 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11587 opcode = T_MNEM_add_sp;
11588 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11589 opcode = T_MNEM_add_pc;
11590 else if (Rd <= 7 && Rs <= 7 && narrow)
11591 {
11592 if (flags)
11593 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11594 else
11595 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11596 }
11597 if (opcode)
11598 {
11599 inst.instruction = THUMB_OP16(opcode);
11600 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11601 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11602 || (inst.relocs[0].type
11603 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11604 {
11605 if (inst.size_req == 2)
e2b0ab59 11606 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11607 else
11608 inst.relax = opcode;
11609 }
0110f2b8
PB
11610 }
11611 else
11612 constraint (inst.size_req == 2, BAD_HIREG);
11613 }
11614 if (inst.size_req == 4
11615 || (inst.size_req != 2 && !opcode))
11616 {
e2b0ab59
AV
11617 constraint ((inst.relocs[0].type
11618 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11619 && (inst.relocs[0].type
11620 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11621 THUMB1_RELOC_ONLY);
efd81785
PB
11622 if (Rd == REG_PC)
11623 {
fdfde340 11624 constraint (add, BAD_PC);
efd81785
PB
11625 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11626 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11627 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11628 _("expression too complex"));
e2b0ab59
AV
11629 constraint (inst.relocs[0].exp.X_add_number < 0
11630 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11631 _("immediate value out of range"));
11632 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11633 | inst.relocs[0].exp.X_add_number;
11634 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11635 return;
11636 }
11637 else if (Rs == REG_PC)
16805f35
PB
11638 {
11639 /* Always use addw/subw. */
11640 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11641 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11642 }
11643 else
11644 {
11645 inst.instruction = THUMB_OP32 (inst.instruction);
11646 inst.instruction = (inst.instruction & 0xe1ffffff)
11647 | 0x10000000;
11648 if (flags)
e2b0ab59 11649 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11650 else
e2b0ab59 11651 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11652 }
dc4503c6
PB
11653 inst.instruction |= Rd << 8;
11654 inst.instruction |= Rs << 16;
0110f2b8 11655 }
b99bd4ef 11656 }
c19d1205
ZW
11657 else
11658 {
e2b0ab59 11659 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11660 unsigned int shift = inst.operands[2].shift_kind;
11661
c19d1205
ZW
11662 Rn = inst.operands[2].reg;
11663 /* See if we can do this with a 16-bit instruction. */
11664 if (!inst.operands[2].shifted && inst.size_req != 4)
11665 {
e27ec89e
PB
11666 if (Rd > 7 || Rs > 7 || Rn > 7)
11667 narrow = FALSE;
11668
11669 if (narrow)
c19d1205 11670 {
e27ec89e
PB
11671 inst.instruction = ((inst.instruction == T_MNEM_adds
11672 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11673 ? T_OPCODE_ADD_R3
11674 : T_OPCODE_SUB_R3);
11675 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11676 return;
11677 }
b99bd4ef 11678
7e806470 11679 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11680 {
7e806470
PB
11681 /* Thumb-1 cores (except v6-M) require at least one high
11682 register in a narrow non flag setting add. */
11683 if (Rd > 7 || Rn > 7
11684 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11685 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11686 {
7e806470
PB
11687 if (Rd == Rn)
11688 {
11689 Rn = Rs;
11690 Rs = Rd;
11691 }
c19d1205
ZW
11692 inst.instruction = T_OPCODE_ADD_HI;
11693 inst.instruction |= (Rd & 8) << 4;
11694 inst.instruction |= (Rd & 7);
11695 inst.instruction |= Rn << 3;
11696 return;
11697 }
c19d1205
ZW
11698 }
11699 }
c921be7d 11700
fdfde340 11701 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11702 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11703 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11704 constraint (Rs == REG_PC, BAD_PC);
11705 reject_bad_reg (Rn);
11706
c19d1205
ZW
11707 /* If we get here, it can't be done in 16 bits. */
11708 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11709 _("shift must be constant"));
11710 inst.instruction = THUMB_OP32 (inst.instruction);
11711 inst.instruction |= Rd << 8;
11712 inst.instruction |= Rs << 16;
5f4cb198
NC
11713 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11714 _("shift value over 3 not allowed in thumb mode"));
11715 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11716 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11717 encode_thumb32_shifted_operand (2);
11718 }
11719 }
11720 else
11721 {
11722 constraint (inst.instruction == T_MNEM_adds
11723 || inst.instruction == T_MNEM_subs,
11724 BAD_THUMB32);
b99bd4ef 11725
c19d1205 11726 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11727 {
c19d1205
ZW
11728 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11729 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11730 BAD_HIREG);
11731
11732 inst.instruction = (inst.instruction == T_MNEM_add
11733 ? 0x0000 : 0x8000);
11734 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11735 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11736 return;
11737 }
11738
c19d1205
ZW
11739 Rn = inst.operands[2].reg;
11740 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11741
c19d1205
ZW
11742 /* We now have Rd, Rs, and Rn set to registers. */
11743 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11744 {
c19d1205
ZW
11745 /* Can't do this for SUB. */
11746 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11747 inst.instruction = T_OPCODE_ADD_HI;
11748 inst.instruction |= (Rd & 8) << 4;
11749 inst.instruction |= (Rd & 7);
11750 if (Rs == Rd)
11751 inst.instruction |= Rn << 3;
11752 else if (Rn == Rd)
11753 inst.instruction |= Rs << 3;
11754 else
11755 constraint (1, _("dest must overlap one source register"));
11756 }
11757 else
11758 {
11759 inst.instruction = (inst.instruction == T_MNEM_add
11760 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11761 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11762 }
b99bd4ef 11763 }
b99bd4ef
NC
11764}
11765
c19d1205
ZW
11766static void
11767do_t_adr (void)
11768{
fdfde340
JM
11769 unsigned Rd;
11770
11771 Rd = inst.operands[0].reg;
11772 reject_bad_reg (Rd);
11773
11774 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11775 {
11776 /* Defer to section relaxation. */
11777 inst.relax = inst.instruction;
11778 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11779 inst.instruction |= Rd << 4;
0110f2b8
PB
11780 }
11781 else if (unified_syntax && inst.size_req != 2)
e9f89963 11782 {
0110f2b8 11783 /* Generate a 32-bit opcode. */
e9f89963 11784 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11785 inst.instruction |= Rd << 8;
e2b0ab59
AV
11786 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11787 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11788 }
11789 else
11790 {
0110f2b8 11791 /* Generate a 16-bit opcode. */
e9f89963 11792 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11793 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11794 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11795 inst.relocs[0].pc_rel = 1;
fdfde340 11796 inst.instruction |= Rd << 4;
e9f89963 11797 }
52a86f84 11798
e2b0ab59
AV
11799 if (inst.relocs[0].exp.X_op == O_symbol
11800 && inst.relocs[0].exp.X_add_symbol != NULL
11801 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11802 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11803 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11804}
b99bd4ef 11805
c19d1205
ZW
11806/* Arithmetic instructions for which there is just one 16-bit
11807 instruction encoding, and it allows only two low registers.
11808 For maximal compatibility with ARM syntax, we allow three register
11809 operands even when Thumb-32 instructions are not available, as long
11810 as the first two are identical. For instance, both "sbc r0,r1" and
11811 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11812static void
c19d1205 11813do_t_arit3 (void)
b99bd4ef 11814{
c19d1205 11815 int Rd, Rs, Rn;
b99bd4ef 11816
c19d1205
ZW
11817 Rd = inst.operands[0].reg;
11818 Rs = (inst.operands[1].present
11819 ? inst.operands[1].reg /* Rd, Rs, foo */
11820 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11821 Rn = inst.operands[2].reg;
b99bd4ef 11822
fdfde340
JM
11823 reject_bad_reg (Rd);
11824 reject_bad_reg (Rs);
11825 if (inst.operands[2].isreg)
11826 reject_bad_reg (Rn);
11827
c19d1205 11828 if (unified_syntax)
b99bd4ef 11829 {
c19d1205
ZW
11830 if (!inst.operands[2].isreg)
11831 {
11832 /* For an immediate, we always generate a 32-bit opcode;
11833 section relaxation will shrink it later if possible. */
11834 inst.instruction = THUMB_OP32 (inst.instruction);
11835 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11836 inst.instruction |= Rd << 8;
11837 inst.instruction |= Rs << 16;
e2b0ab59 11838 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11839 }
11840 else
11841 {
e27ec89e
PB
11842 bfd_boolean narrow;
11843
c19d1205 11844 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11845 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11846 narrow = !in_pred_block ();
e27ec89e 11847 else
5ee91343 11848 narrow = in_pred_block ();
e27ec89e
PB
11849
11850 if (Rd > 7 || Rn > 7 || Rs > 7)
11851 narrow = FALSE;
11852 if (inst.operands[2].shifted)
11853 narrow = FALSE;
11854 if (inst.size_req == 4)
11855 narrow = FALSE;
11856
11857 if (narrow
c19d1205
ZW
11858 && Rd == Rs)
11859 {
11860 inst.instruction = THUMB_OP16 (inst.instruction);
11861 inst.instruction |= Rd;
11862 inst.instruction |= Rn << 3;
11863 return;
11864 }
b99bd4ef 11865
c19d1205
ZW
11866 /* If we get here, it can't be done in 16 bits. */
11867 constraint (inst.operands[2].shifted
11868 && inst.operands[2].immisreg,
11869 _("shift must be constant"));
11870 inst.instruction = THUMB_OP32 (inst.instruction);
11871 inst.instruction |= Rd << 8;
11872 inst.instruction |= Rs << 16;
11873 encode_thumb32_shifted_operand (2);
11874 }
a737bd4d 11875 }
c19d1205 11876 else
b99bd4ef 11877 {
c19d1205
ZW
11878 /* On its face this is a lie - the instruction does set the
11879 flags. However, the only supported mnemonic in this mode
11880 says it doesn't. */
11881 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11882
c19d1205
ZW
11883 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11884 _("unshifted register required"));
11885 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11886 constraint (Rd != Rs,
11887 _("dest and source1 must be the same register"));
a737bd4d 11888
c19d1205
ZW
11889 inst.instruction = THUMB_OP16 (inst.instruction);
11890 inst.instruction |= Rd;
11891 inst.instruction |= Rn << 3;
b99bd4ef 11892 }
a737bd4d 11893}
b99bd4ef 11894
c19d1205
ZW
11895/* Similarly, but for instructions where the arithmetic operation is
11896 commutative, so we can allow either of them to be different from
11897 the destination operand in a 16-bit instruction. For instance, all
11898 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11899 accepted. */
11900static void
11901do_t_arit3c (void)
a737bd4d 11902{
c19d1205 11903 int Rd, Rs, Rn;
b99bd4ef 11904
c19d1205
ZW
11905 Rd = inst.operands[0].reg;
11906 Rs = (inst.operands[1].present
11907 ? inst.operands[1].reg /* Rd, Rs, foo */
11908 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11909 Rn = inst.operands[2].reg;
c921be7d 11910
fdfde340
JM
11911 reject_bad_reg (Rd);
11912 reject_bad_reg (Rs);
11913 if (inst.operands[2].isreg)
11914 reject_bad_reg (Rn);
a737bd4d 11915
c19d1205 11916 if (unified_syntax)
a737bd4d 11917 {
c19d1205 11918 if (!inst.operands[2].isreg)
b99bd4ef 11919 {
c19d1205
ZW
11920 /* For an immediate, we always generate a 32-bit opcode;
11921 section relaxation will shrink it later if possible. */
11922 inst.instruction = THUMB_OP32 (inst.instruction);
11923 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11924 inst.instruction |= Rd << 8;
11925 inst.instruction |= Rs << 16;
e2b0ab59 11926 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11927 }
c19d1205 11928 else
a737bd4d 11929 {
e27ec89e
PB
11930 bfd_boolean narrow;
11931
c19d1205 11932 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11933 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11934 narrow = !in_pred_block ();
e27ec89e 11935 else
5ee91343 11936 narrow = in_pred_block ();
e27ec89e
PB
11937
11938 if (Rd > 7 || Rn > 7 || Rs > 7)
11939 narrow = FALSE;
11940 if (inst.operands[2].shifted)
11941 narrow = FALSE;
11942 if (inst.size_req == 4)
11943 narrow = FALSE;
11944
11945 if (narrow)
a737bd4d 11946 {
c19d1205 11947 if (Rd == Rs)
a737bd4d 11948 {
c19d1205
ZW
11949 inst.instruction = THUMB_OP16 (inst.instruction);
11950 inst.instruction |= Rd;
11951 inst.instruction |= Rn << 3;
11952 return;
a737bd4d 11953 }
c19d1205 11954 if (Rd == Rn)
a737bd4d 11955 {
c19d1205
ZW
11956 inst.instruction = THUMB_OP16 (inst.instruction);
11957 inst.instruction |= Rd;
11958 inst.instruction |= Rs << 3;
11959 return;
a737bd4d
NC
11960 }
11961 }
c19d1205
ZW
11962
11963 /* If we get here, it can't be done in 16 bits. */
11964 constraint (inst.operands[2].shifted
11965 && inst.operands[2].immisreg,
11966 _("shift must be constant"));
11967 inst.instruction = THUMB_OP32 (inst.instruction);
11968 inst.instruction |= Rd << 8;
11969 inst.instruction |= Rs << 16;
11970 encode_thumb32_shifted_operand (2);
a737bd4d 11971 }
b99bd4ef 11972 }
c19d1205
ZW
11973 else
11974 {
11975 /* On its face this is a lie - the instruction does set the
11976 flags. However, the only supported mnemonic in this mode
11977 says it doesn't. */
11978 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11979
c19d1205
ZW
11980 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11981 _("unshifted register required"));
11982 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11983
11984 inst.instruction = THUMB_OP16 (inst.instruction);
11985 inst.instruction |= Rd;
11986
11987 if (Rd == Rs)
11988 inst.instruction |= Rn << 3;
11989 else if (Rd == Rn)
11990 inst.instruction |= Rs << 3;
11991 else
11992 constraint (1, _("dest must overlap one source register"));
11993 }
a737bd4d
NC
11994}
11995
c19d1205
ZW
11996static void
11997do_t_bfc (void)
a737bd4d 11998{
fdfde340 11999 unsigned Rd;
c19d1205
ZW
12000 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12001 constraint (msb > 32, _("bit-field extends past end of register"));
12002 /* The instruction encoding stores the LSB and MSB,
12003 not the LSB and width. */
fdfde340
JM
12004 Rd = inst.operands[0].reg;
12005 reject_bad_reg (Rd);
12006 inst.instruction |= Rd << 8;
c19d1205
ZW
12007 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12008 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12009 inst.instruction |= msb - 1;
b99bd4ef
NC
12010}
12011
c19d1205
ZW
12012static void
12013do_t_bfi (void)
b99bd4ef 12014{
fdfde340 12015 int Rd, Rn;
c19d1205 12016 unsigned int msb;
b99bd4ef 12017
fdfde340
JM
12018 Rd = inst.operands[0].reg;
12019 reject_bad_reg (Rd);
12020
c19d1205
ZW
12021 /* #0 in second position is alternative syntax for bfc, which is
12022 the same instruction but with REG_PC in the Rm field. */
12023 if (!inst.operands[1].isreg)
fdfde340
JM
12024 Rn = REG_PC;
12025 else
12026 {
12027 Rn = inst.operands[1].reg;
12028 reject_bad_reg (Rn);
12029 }
b99bd4ef 12030
c19d1205
ZW
12031 msb = inst.operands[2].imm + inst.operands[3].imm;
12032 constraint (msb > 32, _("bit-field extends past end of register"));
12033 /* The instruction encoding stores the LSB and MSB,
12034 not the LSB and width. */
fdfde340
JM
12035 inst.instruction |= Rd << 8;
12036 inst.instruction |= Rn << 16;
c19d1205
ZW
12037 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12038 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12039 inst.instruction |= msb - 1;
b99bd4ef
NC
12040}
12041
c19d1205
ZW
12042static void
12043do_t_bfx (void)
b99bd4ef 12044{
fdfde340
JM
12045 unsigned Rd, Rn;
12046
12047 Rd = inst.operands[0].reg;
12048 Rn = inst.operands[1].reg;
12049
12050 reject_bad_reg (Rd);
12051 reject_bad_reg (Rn);
12052
c19d1205
ZW
12053 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12054 _("bit-field extends past end of register"));
fdfde340
JM
12055 inst.instruction |= Rd << 8;
12056 inst.instruction |= Rn << 16;
c19d1205
ZW
12057 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12058 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12059 inst.instruction |= inst.operands[3].imm - 1;
12060}
b99bd4ef 12061
c19d1205
ZW
12062/* ARM V5 Thumb BLX (argument parse)
12063 BLX <target_addr> which is BLX(1)
12064 BLX <Rm> which is BLX(2)
12065 Unfortunately, there are two different opcodes for this mnemonic.
12066 So, the insns[].value is not used, and the code here zaps values
12067 into inst.instruction.
b99bd4ef 12068
c19d1205
ZW
12069 ??? How to take advantage of the additional two bits of displacement
12070 available in Thumb32 mode? Need new relocation? */
b99bd4ef 12071
c19d1205
ZW
12072static void
12073do_t_blx (void)
12074{
5ee91343 12075 set_pred_insn_type_last ();
e07e6e58 12076
c19d1205 12077 if (inst.operands[0].isreg)
fdfde340
JM
12078 {
12079 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12080 /* We have a register, so this is BLX(2). */
12081 inst.instruction |= inst.operands[0].reg << 3;
12082 }
b99bd4ef
NC
12083 else
12084 {
c19d1205 12085 /* No register. This must be BLX(1). */
2fc8bdac 12086 inst.instruction = 0xf000e800;
0855e32b 12087 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
12088 }
12089}
12090
c19d1205
ZW
12091static void
12092do_t_branch (void)
b99bd4ef 12093{
0110f2b8 12094 int opcode;
dfa9f0d5 12095 int cond;
2fe88214 12096 bfd_reloc_code_real_type reloc;
dfa9f0d5 12097
e07e6e58 12098 cond = inst.cond;
5ee91343 12099 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 12100
5ee91343 12101 if (in_pred_block ())
dfa9f0d5
PB
12102 {
12103 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 12104 branches. */
dfa9f0d5 12105 cond = COND_ALWAYS;
dfa9f0d5
PB
12106 }
12107 else
12108 cond = inst.cond;
12109
12110 if (cond != COND_ALWAYS)
0110f2b8
PB
12111 opcode = T_MNEM_bcond;
12112 else
12113 opcode = inst.instruction;
12114
12d6b0b7
RS
12115 if (unified_syntax
12116 && (inst.size_req == 4
10960bfb
PB
12117 || (inst.size_req != 2
12118 && (inst.operands[0].hasreloc
e2b0ab59 12119 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 12120 {
0110f2b8 12121 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 12122 if (cond == COND_ALWAYS)
9ae92b05 12123 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
12124 else
12125 {
ff8646ee
TP
12126 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12127 _("selected architecture does not support "
12128 "wide conditional branch instruction"));
12129
9c2799c2 12130 gas_assert (cond != 0xF);
dfa9f0d5 12131 inst.instruction |= cond << 22;
9ae92b05 12132 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12133 }
12134 }
b99bd4ef
NC
12135 else
12136 {
0110f2b8 12137 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12138 if (cond == COND_ALWAYS)
9ae92b05 12139 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12140 else
b99bd4ef 12141 {
dfa9f0d5 12142 inst.instruction |= cond << 8;
9ae92b05 12143 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12144 }
0110f2b8
PB
12145 /* Allow section relaxation. */
12146 if (unified_syntax && inst.size_req != 2)
12147 inst.relax = opcode;
b99bd4ef 12148 }
e2b0ab59
AV
12149 inst.relocs[0].type = reloc;
12150 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12151}
12152
8884b720 12153/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12154 between the two is the maximum immediate allowed - which is passed in
8884b720 12155 RANGE. */
b99bd4ef 12156static void
8884b720 12157do_t_bkpt_hlt1 (int range)
b99bd4ef 12158{
dfa9f0d5
PB
12159 constraint (inst.cond != COND_ALWAYS,
12160 _("instruction is always unconditional"));
c19d1205 12161 if (inst.operands[0].present)
b99bd4ef 12162 {
8884b720 12163 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12164 _("immediate value out of range"));
12165 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12166 }
8884b720 12167
5ee91343 12168 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12169}
12170
12171static void
12172do_t_hlt (void)
12173{
12174 do_t_bkpt_hlt1 (63);
12175}
12176
12177static void
12178do_t_bkpt (void)
12179{
12180 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12181}
12182
12183static void
c19d1205 12184do_t_branch23 (void)
b99bd4ef 12185{
5ee91343 12186 set_pred_insn_type_last ();
0855e32b 12187 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12188
0855e32b
NS
12189 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12190 this file. We used to simply ignore the PLT reloc type here --
12191 the branch encoding is now needed to deal with TLSCALL relocs.
12192 So if we see a PLT reloc now, put it back to how it used to be to
12193 keep the preexisting behaviour. */
e2b0ab59
AV
12194 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12195 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12196
4343666d 12197#if defined(OBJ_COFF)
c19d1205
ZW
12198 /* If the destination of the branch is a defined symbol which does not have
12199 the THUMB_FUNC attribute, then we must be calling a function which has
12200 the (interfacearm) attribute. We look for the Thumb entry point to that
12201 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12202 if ( inst.relocs[0].exp.X_op == O_symbol
12203 && inst.relocs[0].exp.X_add_symbol != NULL
12204 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12205 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12206 inst.relocs[0].exp.X_add_symbol
12207 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12208#endif
90e4755a
RE
12209}
12210
12211static void
c19d1205 12212do_t_bx (void)
90e4755a 12213{
5ee91343 12214 set_pred_insn_type_last ();
c19d1205
ZW
12215 inst.instruction |= inst.operands[0].reg << 3;
12216 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12217 should cause the alignment to be checked once it is known. This is
12218 because BX PC only works if the instruction is word aligned. */
12219}
90e4755a 12220
c19d1205
ZW
12221static void
12222do_t_bxj (void)
12223{
fdfde340 12224 int Rm;
90e4755a 12225
5ee91343 12226 set_pred_insn_type_last ();
fdfde340
JM
12227 Rm = inst.operands[0].reg;
12228 reject_bad_reg (Rm);
12229 inst.instruction |= Rm << 16;
90e4755a
RE
12230}
12231
12232static void
c19d1205 12233do_t_clz (void)
90e4755a 12234{
fdfde340
JM
12235 unsigned Rd;
12236 unsigned Rm;
12237
12238 Rd = inst.operands[0].reg;
12239 Rm = inst.operands[1].reg;
12240
12241 reject_bad_reg (Rd);
12242 reject_bad_reg (Rm);
12243
12244 inst.instruction |= Rd << 8;
12245 inst.instruction |= Rm << 16;
12246 inst.instruction |= Rm;
c19d1205 12247}
90e4755a 12248
e39c1607
SD
12249/* For the Armv8.1-M conditional instructions. */
12250static void
12251do_t_cond (void)
12252{
12253 unsigned Rd, Rn, Rm;
12254 signed int cond;
12255
12256 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12257
12258 Rd = inst.operands[0].reg;
12259 switch (inst.instruction)
12260 {
12261 case T_MNEM_csinc:
12262 case T_MNEM_csinv:
12263 case T_MNEM_csneg:
12264 case T_MNEM_csel:
12265 Rn = inst.operands[1].reg;
12266 Rm = inst.operands[2].reg;
12267 cond = inst.operands[3].imm;
12268 constraint (Rn == REG_SP, BAD_SP);
12269 constraint (Rm == REG_SP, BAD_SP);
12270 break;
12271
12272 case T_MNEM_cinc:
12273 case T_MNEM_cinv:
12274 case T_MNEM_cneg:
12275 Rn = inst.operands[1].reg;
12276 cond = inst.operands[2].imm;
12277 /* Invert the last bit to invert the cond. */
12278 cond = TOGGLE_BIT (cond, 0);
12279 constraint (Rn == REG_SP, BAD_SP);
12280 Rm = Rn;
12281 break;
12282
12283 case T_MNEM_csetm:
12284 case T_MNEM_cset:
12285 cond = inst.operands[1].imm;
12286 /* Invert the last bit to invert the cond. */
12287 cond = TOGGLE_BIT (cond, 0);
12288 Rn = REG_PC;
12289 Rm = REG_PC;
12290 break;
12291
12292 default: abort ();
12293 }
12294
12295 set_pred_insn_type (OUTSIDE_PRED_INSN);
12296 inst.instruction = THUMB_OP32 (inst.instruction);
12297 inst.instruction |= Rd << 8;
12298 inst.instruction |= Rn << 16;
12299 inst.instruction |= Rm;
12300 inst.instruction |= cond << 4;
12301}
12302
91d8b670
JG
12303static void
12304do_t_csdb (void)
12305{
5ee91343 12306 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12307}
12308
dfa9f0d5
PB
12309static void
12310do_t_cps (void)
12311{
5ee91343 12312 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12313 inst.instruction |= inst.operands[0].imm;
12314}
12315
c19d1205
ZW
12316static void
12317do_t_cpsi (void)
12318{
5ee91343 12319 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12320 if (unified_syntax
62b3e311
PB
12321 && (inst.operands[1].present || inst.size_req == 4)
12322 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12323 {
c19d1205
ZW
12324 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12325 inst.instruction = 0xf3af8000;
12326 inst.instruction |= imod << 9;
12327 inst.instruction |= inst.operands[0].imm << 5;
12328 if (inst.operands[1].present)
12329 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12330 }
c19d1205 12331 else
90e4755a 12332 {
62b3e311
PB
12333 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12334 && (inst.operands[0].imm & 4),
12335 _("selected processor does not support 'A' form "
12336 "of this instruction"));
12337 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12338 _("Thumb does not support the 2-argument "
12339 "form of this instruction"));
12340 inst.instruction |= inst.operands[0].imm;
90e4755a 12341 }
90e4755a
RE
12342}
12343
c19d1205
ZW
12344/* THUMB CPY instruction (argument parse). */
12345
90e4755a 12346static void
c19d1205 12347do_t_cpy (void)
90e4755a 12348{
c19d1205 12349 if (inst.size_req == 4)
90e4755a 12350 {
c19d1205
ZW
12351 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12352 inst.instruction |= inst.operands[0].reg << 8;
12353 inst.instruction |= inst.operands[1].reg;
90e4755a 12354 }
c19d1205 12355 else
90e4755a 12356 {
c19d1205
ZW
12357 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12358 inst.instruction |= (inst.operands[0].reg & 0x7);
12359 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12360 }
90e4755a
RE
12361}
12362
90e4755a 12363static void
25fe350b 12364do_t_cbz (void)
90e4755a 12365{
5ee91343 12366 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12367 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12368 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12369 inst.relocs[0].pc_rel = 1;
12370 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12371}
90e4755a 12372
62b3e311
PB
12373static void
12374do_t_dbg (void)
12375{
12376 inst.instruction |= inst.operands[0].imm;
12377}
12378
12379static void
12380do_t_div (void)
12381{
fdfde340
JM
12382 unsigned Rd, Rn, Rm;
12383
12384 Rd = inst.operands[0].reg;
12385 Rn = (inst.operands[1].present
12386 ? inst.operands[1].reg : Rd);
12387 Rm = inst.operands[2].reg;
12388
12389 reject_bad_reg (Rd);
12390 reject_bad_reg (Rn);
12391 reject_bad_reg (Rm);
12392
12393 inst.instruction |= Rd << 8;
12394 inst.instruction |= Rn << 16;
12395 inst.instruction |= Rm;
62b3e311
PB
12396}
12397
c19d1205
ZW
12398static void
12399do_t_hint (void)
12400{
12401 if (unified_syntax && inst.size_req == 4)
12402 inst.instruction = THUMB_OP32 (inst.instruction);
12403 else
12404 inst.instruction = THUMB_OP16 (inst.instruction);
12405}
90e4755a 12406
c19d1205
ZW
12407static void
12408do_t_it (void)
12409{
12410 unsigned int cond = inst.operands[0].imm;
e27ec89e 12411
5ee91343
AV
12412 set_pred_insn_type (IT_INSN);
12413 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12414 now_pred.cc = cond;
12415 now_pred.warn_deprecated = FALSE;
12416 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12417
12418 /* If the condition is a negative condition, invert the mask. */
c19d1205 12419 if ((cond & 0x1) == 0x0)
90e4755a 12420 {
c19d1205 12421 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12422
c19d1205 12423 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12424 {
12425 /* No conversion needed. */
5ee91343 12426 now_pred.block_length = 1;
5a01bb1d 12427 }
c19d1205 12428 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12429 {
12430 mask ^= 0x8;
5ee91343 12431 now_pred.block_length = 2;
5a01bb1d 12432 }
e27ec89e 12433 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12434 {
12435 mask ^= 0xC;
5ee91343 12436 now_pred.block_length = 3;
5a01bb1d 12437 }
c19d1205 12438 else
5a01bb1d
MGD
12439 {
12440 mask ^= 0xE;
5ee91343 12441 now_pred.block_length = 4;
5a01bb1d 12442 }
90e4755a 12443
e27ec89e
PB
12444 inst.instruction &= 0xfff0;
12445 inst.instruction |= mask;
c19d1205 12446 }
90e4755a 12447
c19d1205
ZW
12448 inst.instruction |= cond << 4;
12449}
90e4755a 12450
3c707909
PB
12451/* Helper function used for both push/pop and ldm/stm. */
12452static void
4b5a202f
AV
12453encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12454 bfd_boolean writeback)
3c707909 12455{
4b5a202f 12456 bfd_boolean load, store;
3c707909 12457
4b5a202f
AV
12458 gas_assert (base != -1 || !do_io);
12459 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12460 store = do_io && !load;
3c707909
PB
12461
12462 if (mask & (1 << 13))
12463 inst.error = _("SP not allowed in register list");
1e5b0379 12464
4b5a202f 12465 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12466 && writeback)
12467 inst.error = _("having the base register in the register list when "
12468 "using write back is UNPREDICTABLE");
12469
3c707909
PB
12470 if (load)
12471 {
e07e6e58 12472 if (mask & (1 << 15))
477330fc
RM
12473 {
12474 if (mask & (1 << 14))
12475 inst.error = _("LR and PC should not both be in register list");
12476 else
5ee91343 12477 set_pred_insn_type_last ();
477330fc 12478 }
3c707909 12479 }
4b5a202f 12480 else if (store)
3c707909
PB
12481 {
12482 if (mask & (1 << 15))
12483 inst.error = _("PC not allowed in register list");
3c707909
PB
12484 }
12485
4b5a202f 12486 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12487 {
12488 /* Single register transfers implemented as str/ldr. */
12489 if (writeback)
12490 {
12491 if (inst.instruction & (1 << 23))
12492 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12493 else
12494 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12495 }
12496 else
12497 {
12498 if (inst.instruction & (1 << 23))
12499 inst.instruction = 0x00800000; /* ia -> [base] */
12500 else
12501 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12502 }
12503
12504 inst.instruction |= 0xf8400000;
12505 if (load)
12506 inst.instruction |= 0x00100000;
12507
5f4273c7 12508 mask = ffs (mask) - 1;
3c707909
PB
12509 mask <<= 12;
12510 }
12511 else if (writeback)
12512 inst.instruction |= WRITE_BACK;
12513
12514 inst.instruction |= mask;
4b5a202f
AV
12515 if (do_io)
12516 inst.instruction |= base << 16;
3c707909
PB
12517}
12518
c19d1205
ZW
12519static void
12520do_t_ldmstm (void)
12521{
12522 /* This really doesn't seem worth it. */
e2b0ab59 12523 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12524 _("expression too complex"));
12525 constraint (inst.operands[1].writeback,
12526 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12527
c19d1205
ZW
12528 if (unified_syntax)
12529 {
3c707909
PB
12530 bfd_boolean narrow;
12531 unsigned mask;
12532
12533 narrow = FALSE;
c19d1205
ZW
12534 /* See if we can use a 16-bit instruction. */
12535 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12536 && inst.size_req != 4
3c707909 12537 && !(inst.operands[1].imm & ~0xff))
90e4755a 12538 {
3c707909 12539 mask = 1 << inst.operands[0].reg;
90e4755a 12540
eab4f823 12541 if (inst.operands[0].reg <= 7)
90e4755a 12542 {
3c707909 12543 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12544 ? inst.operands[0].writeback
12545 : (inst.operands[0].writeback
12546 == !(inst.operands[1].imm & mask)))
477330fc 12547 {
eab4f823
MGD
12548 if (inst.instruction == T_MNEM_stmia
12549 && (inst.operands[1].imm & mask)
12550 && (inst.operands[1].imm & (mask - 1)))
12551 as_warn (_("value stored for r%d is UNKNOWN"),
12552 inst.operands[0].reg);
3c707909 12553
eab4f823
MGD
12554 inst.instruction = THUMB_OP16 (inst.instruction);
12555 inst.instruction |= inst.operands[0].reg << 8;
12556 inst.instruction |= inst.operands[1].imm;
12557 narrow = TRUE;
12558 }
12559 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12560 {
12561 /* This means 1 register in reg list one of 3 situations:
12562 1. Instruction is stmia, but without writeback.
12563 2. lmdia without writeback, but with Rn not in
477330fc 12564 reglist.
eab4f823
MGD
12565 3. ldmia with writeback, but with Rn in reglist.
12566 Case 3 is UNPREDICTABLE behaviour, so we handle
12567 case 1 and 2 which can be converted into a 16-bit
12568 str or ldr. The SP cases are handled below. */
12569 unsigned long opcode;
12570 /* First, record an error for Case 3. */
12571 if (inst.operands[1].imm & mask
12572 && inst.operands[0].writeback)
fa94de6b 12573 inst.error =
eab4f823
MGD
12574 _("having the base register in the register list when "
12575 "using write back is UNPREDICTABLE");
fa94de6b
RM
12576
12577 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12578 : T_MNEM_ldr);
12579 inst.instruction = THUMB_OP16 (opcode);
12580 inst.instruction |= inst.operands[0].reg << 3;
12581 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12582 narrow = TRUE;
12583 }
90e4755a 12584 }
eab4f823 12585 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12586 {
eab4f823
MGD
12587 if (inst.operands[0].writeback)
12588 {
fa94de6b 12589 inst.instruction =
eab4f823 12590 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12591 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12592 inst.instruction |= inst.operands[1].imm;
477330fc 12593 narrow = TRUE;
eab4f823
MGD
12594 }
12595 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12596 {
fa94de6b 12597 inst.instruction =
eab4f823 12598 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12599 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12600 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12601 narrow = TRUE;
eab4f823 12602 }
90e4755a 12603 }
3c707909
PB
12604 }
12605
12606 if (!narrow)
12607 {
c19d1205
ZW
12608 if (inst.instruction < 0xffff)
12609 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12610
4b5a202f
AV
12611 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12612 inst.operands[1].imm,
12613 inst.operands[0].writeback);
90e4755a
RE
12614 }
12615 }
c19d1205 12616 else
90e4755a 12617 {
c19d1205
ZW
12618 constraint (inst.operands[0].reg > 7
12619 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12620 constraint (inst.instruction != T_MNEM_ldmia
12621 && inst.instruction != T_MNEM_stmia,
12622 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12623 if (inst.instruction == T_MNEM_stmia)
f03698e6 12624 {
c19d1205
ZW
12625 if (!inst.operands[0].writeback)
12626 as_warn (_("this instruction will write back the base register"));
12627 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12628 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12629 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12630 inst.operands[0].reg);
f03698e6 12631 }
c19d1205 12632 else
90e4755a 12633 {
c19d1205
ZW
12634 if (!inst.operands[0].writeback
12635 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12636 as_warn (_("this instruction will write back the base register"));
12637 else if (inst.operands[0].writeback
12638 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12639 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12640 }
12641
c19d1205
ZW
12642 inst.instruction = THUMB_OP16 (inst.instruction);
12643 inst.instruction |= inst.operands[0].reg << 8;
12644 inst.instruction |= inst.operands[1].imm;
12645 }
12646}
e28cd48c 12647
c19d1205
ZW
12648static void
12649do_t_ldrex (void)
12650{
12651 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12652 || inst.operands[1].postind || inst.operands[1].writeback
12653 || inst.operands[1].immisreg || inst.operands[1].shifted
12654 || inst.operands[1].negative,
01cfc07f 12655 BAD_ADDR_MODE);
e28cd48c 12656
5be8be5d
DG
12657 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12658
c19d1205
ZW
12659 inst.instruction |= inst.operands[0].reg << 12;
12660 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12661 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12662}
e28cd48c 12663
c19d1205
ZW
12664static void
12665do_t_ldrexd (void)
12666{
12667 if (!inst.operands[1].present)
1cac9012 12668 {
c19d1205
ZW
12669 constraint (inst.operands[0].reg == REG_LR,
12670 _("r14 not allowed as first register "
12671 "when second register is omitted"));
12672 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12673 }
c19d1205
ZW
12674 constraint (inst.operands[0].reg == inst.operands[1].reg,
12675 BAD_OVERLAP);
b99bd4ef 12676
c19d1205
ZW
12677 inst.instruction |= inst.operands[0].reg << 12;
12678 inst.instruction |= inst.operands[1].reg << 8;
12679 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12680}
12681
12682static void
c19d1205 12683do_t_ldst (void)
b99bd4ef 12684{
0110f2b8
PB
12685 unsigned long opcode;
12686 int Rn;
12687
e07e6e58
NC
12688 if (inst.operands[0].isreg
12689 && !inst.operands[0].preind
12690 && inst.operands[0].reg == REG_PC)
5ee91343 12691 set_pred_insn_type_last ();
e07e6e58 12692
0110f2b8 12693 opcode = inst.instruction;
c19d1205 12694 if (unified_syntax)
b99bd4ef 12695 {
53365c0d
PB
12696 if (!inst.operands[1].isreg)
12697 {
12698 if (opcode <= 0xffff)
12699 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12700 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12701 return;
12702 }
0110f2b8
PB
12703 if (inst.operands[1].isreg
12704 && !inst.operands[1].writeback
c19d1205
ZW
12705 && !inst.operands[1].shifted && !inst.operands[1].postind
12706 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12707 && opcode <= 0xffff
12708 && inst.size_req != 4)
c19d1205 12709 {
0110f2b8
PB
12710 /* Insn may have a 16-bit form. */
12711 Rn = inst.operands[1].reg;
12712 if (inst.operands[1].immisreg)
12713 {
12714 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12715 /* [Rn, Rik] */
0110f2b8
PB
12716 if (Rn <= 7 && inst.operands[1].imm <= 7)
12717 goto op16;
5be8be5d
DG
12718 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12719 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12720 }
12721 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12722 && opcode != T_MNEM_ldrsb)
12723 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12724 || (Rn == REG_SP && opcode == T_MNEM_str))
12725 {
12726 /* [Rn, #const] */
12727 if (Rn > 7)
12728 {
12729 if (Rn == REG_PC)
12730 {
e2b0ab59 12731 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12732 opcode = T_MNEM_ldr_pc2;
12733 else
12734 opcode = T_MNEM_ldr_pc;
12735 }
12736 else
12737 {
12738 if (opcode == T_MNEM_ldr)
12739 opcode = T_MNEM_ldr_sp;
12740 else
12741 opcode = T_MNEM_str_sp;
12742 }
12743 inst.instruction = inst.operands[0].reg << 8;
12744 }
12745 else
12746 {
12747 inst.instruction = inst.operands[0].reg;
12748 inst.instruction |= inst.operands[1].reg << 3;
12749 }
12750 inst.instruction |= THUMB_OP16 (opcode);
12751 if (inst.size_req == 2)
e2b0ab59 12752 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12753 else
12754 inst.relax = opcode;
12755 return;
12756 }
c19d1205 12757 }
0110f2b8 12758 /* Definitely a 32-bit variant. */
5be8be5d 12759
8d67f500
NC
12760 /* Warning for Erratum 752419. */
12761 if (opcode == T_MNEM_ldr
12762 && inst.operands[0].reg == REG_SP
12763 && inst.operands[1].writeback == 1
12764 && !inst.operands[1].immisreg)
12765 {
12766 if (no_cpu_selected ()
12767 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12768 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12769 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12770 as_warn (_("This instruction may be unpredictable "
12771 "if executed on M-profile cores "
12772 "with interrupts enabled."));
12773 }
12774
5be8be5d 12775 /* Do some validations regarding addressing modes. */
1be5fd2e 12776 if (inst.operands[1].immisreg)
5be8be5d
DG
12777 reject_bad_reg (inst.operands[1].imm);
12778
1be5fd2e
NC
12779 constraint (inst.operands[1].writeback == 1
12780 && inst.operands[0].reg == inst.operands[1].reg,
12781 BAD_OVERLAP);
12782
0110f2b8 12783 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12784 inst.instruction |= inst.operands[0].reg << 12;
12785 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12786 check_ldr_r15_aligned ();
b99bd4ef
NC
12787 return;
12788 }
12789
c19d1205
ZW
12790 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12791
12792 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12793 {
c19d1205
ZW
12794 /* Only [Rn,Rm] is acceptable. */
12795 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12796 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12797 || inst.operands[1].postind || inst.operands[1].shifted
12798 || inst.operands[1].negative,
12799 _("Thumb does not support this addressing mode"));
12800 inst.instruction = THUMB_OP16 (inst.instruction);
12801 goto op16;
b99bd4ef 12802 }
5f4273c7 12803
c19d1205
ZW
12804 inst.instruction = THUMB_OP16 (inst.instruction);
12805 if (!inst.operands[1].isreg)
8335d6aa 12806 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12807 return;
b99bd4ef 12808
c19d1205
ZW
12809 constraint (!inst.operands[1].preind
12810 || inst.operands[1].shifted
12811 || inst.operands[1].writeback,
12812 _("Thumb does not support this addressing mode"));
12813 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12814 {
c19d1205
ZW
12815 constraint (inst.instruction & 0x0600,
12816 _("byte or halfword not valid for base register"));
12817 constraint (inst.operands[1].reg == REG_PC
12818 && !(inst.instruction & THUMB_LOAD_BIT),
12819 _("r15 based store not allowed"));
12820 constraint (inst.operands[1].immisreg,
12821 _("invalid base register for register offset"));
b99bd4ef 12822
c19d1205
ZW
12823 if (inst.operands[1].reg == REG_PC)
12824 inst.instruction = T_OPCODE_LDR_PC;
12825 else if (inst.instruction & THUMB_LOAD_BIT)
12826 inst.instruction = T_OPCODE_LDR_SP;
12827 else
12828 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12829
c19d1205 12830 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12831 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12832 return;
12833 }
90e4755a 12834
c19d1205
ZW
12835 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12836 if (!inst.operands[1].immisreg)
12837 {
12838 /* Immediate offset. */
12839 inst.instruction |= inst.operands[0].reg;
12840 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12841 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12842 return;
12843 }
90e4755a 12844
c19d1205
ZW
12845 /* Register offset. */
12846 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12847 constraint (inst.operands[1].negative,
12848 _("Thumb does not support this addressing mode"));
90e4755a 12849
c19d1205
ZW
12850 op16:
12851 switch (inst.instruction)
12852 {
12853 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12854 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12855 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12856 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12857 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12858 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12859 case 0x5600 /* ldrsb */:
12860 case 0x5e00 /* ldrsh */: break;
12861 default: abort ();
12862 }
90e4755a 12863
c19d1205
ZW
12864 inst.instruction |= inst.operands[0].reg;
12865 inst.instruction |= inst.operands[1].reg << 3;
12866 inst.instruction |= inst.operands[1].imm << 6;
12867}
90e4755a 12868
c19d1205
ZW
12869static void
12870do_t_ldstd (void)
12871{
12872 if (!inst.operands[1].present)
b99bd4ef 12873 {
c19d1205
ZW
12874 inst.operands[1].reg = inst.operands[0].reg + 1;
12875 constraint (inst.operands[0].reg == REG_LR,
12876 _("r14 not allowed here"));
bd340a04 12877 constraint (inst.operands[0].reg == REG_R12,
477330fc 12878 _("r12 not allowed here"));
b99bd4ef 12879 }
bd340a04
MGD
12880
12881 if (inst.operands[2].writeback
12882 && (inst.operands[0].reg == inst.operands[2].reg
12883 || inst.operands[1].reg == inst.operands[2].reg))
12884 as_warn (_("base register written back, and overlaps "
477330fc 12885 "one of transfer registers"));
bd340a04 12886
c19d1205
ZW
12887 inst.instruction |= inst.operands[0].reg << 12;
12888 inst.instruction |= inst.operands[1].reg << 8;
12889 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12890}
12891
c19d1205
ZW
12892static void
12893do_t_ldstt (void)
12894{
12895 inst.instruction |= inst.operands[0].reg << 12;
12896 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12897}
a737bd4d 12898
b99bd4ef 12899static void
c19d1205 12900do_t_mla (void)
b99bd4ef 12901{
fdfde340 12902 unsigned Rd, Rn, Rm, Ra;
c921be7d 12903
fdfde340
JM
12904 Rd = inst.operands[0].reg;
12905 Rn = inst.operands[1].reg;
12906 Rm = inst.operands[2].reg;
12907 Ra = inst.operands[3].reg;
12908
12909 reject_bad_reg (Rd);
12910 reject_bad_reg (Rn);
12911 reject_bad_reg (Rm);
12912 reject_bad_reg (Ra);
12913
12914 inst.instruction |= Rd << 8;
12915 inst.instruction |= Rn << 16;
12916 inst.instruction |= Rm;
12917 inst.instruction |= Ra << 12;
c19d1205 12918}
b99bd4ef 12919
c19d1205
ZW
12920static void
12921do_t_mlal (void)
12922{
fdfde340
JM
12923 unsigned RdLo, RdHi, Rn, Rm;
12924
12925 RdLo = inst.operands[0].reg;
12926 RdHi = inst.operands[1].reg;
12927 Rn = inst.operands[2].reg;
12928 Rm = inst.operands[3].reg;
12929
12930 reject_bad_reg (RdLo);
12931 reject_bad_reg (RdHi);
12932 reject_bad_reg (Rn);
12933 reject_bad_reg (Rm);
12934
12935 inst.instruction |= RdLo << 12;
12936 inst.instruction |= RdHi << 8;
12937 inst.instruction |= Rn << 16;
12938 inst.instruction |= Rm;
c19d1205 12939}
b99bd4ef 12940
c19d1205
ZW
12941static void
12942do_t_mov_cmp (void)
12943{
fdfde340
JM
12944 unsigned Rn, Rm;
12945
12946 Rn = inst.operands[0].reg;
12947 Rm = inst.operands[1].reg;
12948
e07e6e58 12949 if (Rn == REG_PC)
5ee91343 12950 set_pred_insn_type_last ();
e07e6e58 12951
c19d1205 12952 if (unified_syntax)
b99bd4ef 12953 {
c19d1205
ZW
12954 int r0off = (inst.instruction == T_MNEM_mov
12955 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12956 unsigned long opcode;
3d388997
PB
12957 bfd_boolean narrow;
12958 bfd_boolean low_regs;
12959
fdfde340 12960 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12961 opcode = inst.instruction;
5ee91343 12962 if (in_pred_block ())
0110f2b8 12963 narrow = opcode != T_MNEM_movs;
3d388997 12964 else
0110f2b8 12965 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12966 if (inst.size_req == 4
12967 || inst.operands[1].shifted)
12968 narrow = FALSE;
12969
efd81785
PB
12970 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12971 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12972 && !inst.operands[1].shifted
fdfde340
JM
12973 && Rn == REG_PC
12974 && Rm == REG_LR)
efd81785
PB
12975 {
12976 inst.instruction = T2_SUBS_PC_LR;
12977 return;
12978 }
12979
fdfde340
JM
12980 if (opcode == T_MNEM_cmp)
12981 {
12982 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12983 if (narrow)
12984 {
12985 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12986 but valid. */
12987 warn_deprecated_sp (Rm);
12988 /* R15 was documented as a valid choice for Rm in ARMv6,
12989 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12990 tools reject R15, so we do too. */
12991 constraint (Rm == REG_PC, BAD_PC);
12992 }
12993 else
12994 reject_bad_reg (Rm);
fdfde340
JM
12995 }
12996 else if (opcode == T_MNEM_mov
12997 || opcode == T_MNEM_movs)
12998 {
12999 if (inst.operands[1].isreg)
13000 {
13001 if (opcode == T_MNEM_movs)
13002 {
13003 reject_bad_reg (Rn);
13004 reject_bad_reg (Rm);
13005 }
76fa04a4
MGD
13006 else if (narrow)
13007 {
13008 /* This is mov.n. */
13009 if ((Rn == REG_SP || Rn == REG_PC)
13010 && (Rm == REG_SP || Rm == REG_PC))
13011 {
5c3696f8 13012 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
13013 "deprecated when r%u is the destination "
13014 "register."), Rm, Rn);
13015 }
13016 }
13017 else
13018 {
13019 /* This is mov.w. */
13020 constraint (Rn == REG_PC, BAD_PC);
13021 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
13022 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13023 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 13024 }
fdfde340
JM
13025 }
13026 else
13027 reject_bad_reg (Rn);
13028 }
13029
c19d1205
ZW
13030 if (!inst.operands[1].isreg)
13031 {
0110f2b8 13032 /* Immediate operand. */
5ee91343 13033 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
13034 narrow = 0;
13035 if (low_regs && narrow)
13036 {
13037 inst.instruction = THUMB_OP16 (opcode);
fdfde340 13038 inst.instruction |= Rn << 8;
e2b0ab59
AV
13039 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13040 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 13041 {
a9f02af8 13042 if (inst.size_req == 2)
e2b0ab59 13043 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
13044 else
13045 inst.relax = opcode;
72d98d16 13046 }
0110f2b8
PB
13047 }
13048 else
13049 {
e2b0ab59
AV
13050 constraint ((inst.relocs[0].type
13051 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13052 && (inst.relocs[0].type
13053 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
13054 THUMB1_RELOC_ONLY);
13055
0110f2b8
PB
13056 inst.instruction = THUMB_OP32 (inst.instruction);
13057 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13058 inst.instruction |= Rn << r0off;
e2b0ab59 13059 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 13060 }
c19d1205 13061 }
728ca7c9
PB
13062 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13063 && (inst.instruction == T_MNEM_mov
13064 || inst.instruction == T_MNEM_movs))
13065 {
13066 /* Register shifts are encoded as separate shift instructions. */
13067 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13068
5ee91343 13069 if (in_pred_block ())
728ca7c9
PB
13070 narrow = !flags;
13071 else
13072 narrow = flags;
13073
13074 if (inst.size_req == 4)
13075 narrow = FALSE;
13076
13077 if (!low_regs || inst.operands[1].imm > 7)
13078 narrow = FALSE;
13079
fdfde340 13080 if (Rn != Rm)
728ca7c9
PB
13081 narrow = FALSE;
13082
13083 switch (inst.operands[1].shift_kind)
13084 {
13085 case SHIFT_LSL:
13086 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13087 break;
13088 case SHIFT_ASR:
13089 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13090 break;
13091 case SHIFT_LSR:
13092 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13093 break;
13094 case SHIFT_ROR:
13095 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13096 break;
13097 default:
5f4273c7 13098 abort ();
728ca7c9
PB
13099 }
13100
13101 inst.instruction = opcode;
13102 if (narrow)
13103 {
fdfde340 13104 inst.instruction |= Rn;
728ca7c9
PB
13105 inst.instruction |= inst.operands[1].imm << 3;
13106 }
13107 else
13108 {
13109 if (flags)
13110 inst.instruction |= CONDS_BIT;
13111
fdfde340
JM
13112 inst.instruction |= Rn << 8;
13113 inst.instruction |= Rm << 16;
728ca7c9
PB
13114 inst.instruction |= inst.operands[1].imm;
13115 }
13116 }
3d388997 13117 else if (!narrow)
c19d1205 13118 {
728ca7c9
PB
13119 /* Some mov with immediate shift have narrow variants.
13120 Register shifts are handled above. */
13121 if (low_regs && inst.operands[1].shifted
13122 && (inst.instruction == T_MNEM_mov
13123 || inst.instruction == T_MNEM_movs))
13124 {
5ee91343 13125 if (in_pred_block ())
728ca7c9
PB
13126 narrow = (inst.instruction == T_MNEM_mov);
13127 else
13128 narrow = (inst.instruction == T_MNEM_movs);
13129 }
13130
13131 if (narrow)
13132 {
13133 switch (inst.operands[1].shift_kind)
13134 {
13135 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13136 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13137 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13138 default: narrow = FALSE; break;
13139 }
13140 }
13141
13142 if (narrow)
13143 {
fdfde340
JM
13144 inst.instruction |= Rn;
13145 inst.instruction |= Rm << 3;
e2b0ab59 13146 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13147 }
13148 else
13149 {
13150 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13151 inst.instruction |= Rn << r0off;
728ca7c9
PB
13152 encode_thumb32_shifted_operand (1);
13153 }
c19d1205
ZW
13154 }
13155 else
13156 switch (inst.instruction)
13157 {
13158 case T_MNEM_mov:
837b3435 13159 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13160 results. Don't allow this. */
13161 if (low_regs)
13162 {
13163 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13164 "MOV Rd, Rs with two low registers is not "
13165 "permitted on this architecture");
fa94de6b 13166 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13167 arm_ext_v6);
13168 }
13169
c19d1205 13170 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13171 inst.instruction |= (Rn & 0x8) << 4;
13172 inst.instruction |= (Rn & 0x7);
13173 inst.instruction |= Rm << 3;
c19d1205 13174 break;
b99bd4ef 13175
c19d1205
ZW
13176 case T_MNEM_movs:
13177 /* We know we have low registers at this point.
941a8a52
MGD
13178 Generate LSLS Rd, Rs, #0. */
13179 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13180 inst.instruction |= Rn;
13181 inst.instruction |= Rm << 3;
c19d1205
ZW
13182 break;
13183
13184 case T_MNEM_cmp:
3d388997 13185 if (low_regs)
c19d1205
ZW
13186 {
13187 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13188 inst.instruction |= Rn;
13189 inst.instruction |= Rm << 3;
c19d1205
ZW
13190 }
13191 else
13192 {
13193 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13194 inst.instruction |= (Rn & 0x8) << 4;
13195 inst.instruction |= (Rn & 0x7);
13196 inst.instruction |= Rm << 3;
c19d1205
ZW
13197 }
13198 break;
13199 }
b99bd4ef
NC
13200 return;
13201 }
13202
c19d1205 13203 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13204
13205 /* PR 10443: Do not silently ignore shifted operands. */
13206 constraint (inst.operands[1].shifted,
13207 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13208
c19d1205 13209 if (inst.operands[1].isreg)
b99bd4ef 13210 {
fdfde340 13211 if (Rn < 8 && Rm < 8)
b99bd4ef 13212 {
c19d1205
ZW
13213 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13214 since a MOV instruction produces unpredictable results. */
13215 if (inst.instruction == T_OPCODE_MOV_I8)
13216 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13217 else
c19d1205 13218 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13219
fdfde340
JM
13220 inst.instruction |= Rn;
13221 inst.instruction |= Rm << 3;
b99bd4ef
NC
13222 }
13223 else
13224 {
c19d1205
ZW
13225 if (inst.instruction == T_OPCODE_MOV_I8)
13226 inst.instruction = T_OPCODE_MOV_HR;
13227 else
13228 inst.instruction = T_OPCODE_CMP_HR;
13229 do_t_cpy ();
b99bd4ef
NC
13230 }
13231 }
c19d1205 13232 else
b99bd4ef 13233 {
fdfde340 13234 constraint (Rn > 7,
c19d1205 13235 _("only lo regs allowed with immediate"));
fdfde340 13236 inst.instruction |= Rn << 8;
e2b0ab59 13237 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13238 }
13239}
b99bd4ef 13240
c19d1205
ZW
13241static void
13242do_t_mov16 (void)
13243{
fdfde340 13244 unsigned Rd;
b6895b4f
PB
13245 bfd_vma imm;
13246 bfd_boolean top;
13247
13248 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13249 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13250 {
33eaf5de 13251 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13252 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13253 }
e2b0ab59 13254 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13255 {
33eaf5de 13256 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13257 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13258 }
13259
fdfde340
JM
13260 Rd = inst.operands[0].reg;
13261 reject_bad_reg (Rd);
13262
13263 inst.instruction |= Rd << 8;
e2b0ab59 13264 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13265 {
e2b0ab59 13266 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13267 inst.instruction |= (imm & 0xf000) << 4;
13268 inst.instruction |= (imm & 0x0800) << 15;
13269 inst.instruction |= (imm & 0x0700) << 4;
13270 inst.instruction |= (imm & 0x00ff);
13271 }
c19d1205 13272}
b99bd4ef 13273
c19d1205
ZW
13274static void
13275do_t_mvn_tst (void)
13276{
fdfde340 13277 unsigned Rn, Rm;
c921be7d 13278
fdfde340
JM
13279 Rn = inst.operands[0].reg;
13280 Rm = inst.operands[1].reg;
13281
13282 if (inst.instruction == T_MNEM_cmp
13283 || inst.instruction == T_MNEM_cmn)
13284 constraint (Rn == REG_PC, BAD_PC);
13285 else
13286 reject_bad_reg (Rn);
13287 reject_bad_reg (Rm);
13288
c19d1205
ZW
13289 if (unified_syntax)
13290 {
13291 int r0off = (inst.instruction == T_MNEM_mvn
13292 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13293 bfd_boolean narrow;
13294
13295 if (inst.size_req == 4
13296 || inst.instruction > 0xffff
13297 || inst.operands[1].shifted
fdfde340 13298 || Rn > 7 || Rm > 7)
3d388997 13299 narrow = FALSE;
fe8b4cc3
KT
13300 else if (inst.instruction == T_MNEM_cmn
13301 || inst.instruction == T_MNEM_tst)
3d388997
PB
13302 narrow = TRUE;
13303 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13304 narrow = !in_pred_block ();
3d388997 13305 else
5ee91343 13306 narrow = in_pred_block ();
3d388997 13307
c19d1205 13308 if (!inst.operands[1].isreg)
b99bd4ef 13309 {
c19d1205
ZW
13310 /* For an immediate, we always generate a 32-bit opcode;
13311 section relaxation will shrink it later if possible. */
13312 if (inst.instruction < 0xffff)
13313 inst.instruction = THUMB_OP32 (inst.instruction);
13314 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13315 inst.instruction |= Rn << r0off;
e2b0ab59 13316 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13317 }
c19d1205 13318 else
b99bd4ef 13319 {
c19d1205 13320 /* See if we can do this with a 16-bit instruction. */
3d388997 13321 if (narrow)
b99bd4ef 13322 {
c19d1205 13323 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13324 inst.instruction |= Rn;
13325 inst.instruction |= Rm << 3;
b99bd4ef 13326 }
c19d1205 13327 else
b99bd4ef 13328 {
c19d1205
ZW
13329 constraint (inst.operands[1].shifted
13330 && inst.operands[1].immisreg,
13331 _("shift must be constant"));
13332 if (inst.instruction < 0xffff)
13333 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13334 inst.instruction |= Rn << r0off;
c19d1205 13335 encode_thumb32_shifted_operand (1);
b99bd4ef 13336 }
b99bd4ef
NC
13337 }
13338 }
13339 else
13340 {
c19d1205
ZW
13341 constraint (inst.instruction > 0xffff
13342 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13343 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13344 _("unshifted register required"));
fdfde340 13345 constraint (Rn > 7 || Rm > 7,
c19d1205 13346 BAD_HIREG);
b99bd4ef 13347
c19d1205 13348 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13349 inst.instruction |= Rn;
13350 inst.instruction |= Rm << 3;
b99bd4ef 13351 }
b99bd4ef
NC
13352}
13353
b05fe5cf 13354static void
c19d1205 13355do_t_mrs (void)
b05fe5cf 13356{
fdfde340 13357 unsigned Rd;
037e8744
JB
13358
13359 if (do_vfp_nsyn_mrs () == SUCCESS)
13360 return;
13361
90ec0d68
MGD
13362 Rd = inst.operands[0].reg;
13363 reject_bad_reg (Rd);
13364 inst.instruction |= Rd << 8;
13365
13366 if (inst.operands[1].isreg)
62b3e311 13367 {
90ec0d68
MGD
13368 unsigned br = inst.operands[1].reg;
13369 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13370 as_bad (_("bad register for mrs"));
13371
13372 inst.instruction |= br & (0xf << 16);
13373 inst.instruction |= (br & 0x300) >> 4;
13374 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13375 }
13376 else
13377 {
90ec0d68 13378 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13379
d2cd1205 13380 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13381 {
13382 /* PR gas/12698: The constraint is only applied for m_profile.
13383 If the user has specified -march=all, we want to ignore it as
13384 we are building for any CPU type, including non-m variants. */
823d2571
TG
13385 bfd_boolean m_profile =
13386 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13387 constraint ((flags != 0) && m_profile, _("selected processor does "
13388 "not support requested special purpose register"));
13389 }
90ec0d68 13390 else
d2cd1205
JB
13391 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13392 devices). */
13393 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13394 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13395
90ec0d68
MGD
13396 inst.instruction |= (flags & SPSR_BIT) >> 2;
13397 inst.instruction |= inst.operands[1].imm & 0xff;
13398 inst.instruction |= 0xf0000;
13399 }
c19d1205 13400}
b05fe5cf 13401
c19d1205
ZW
13402static void
13403do_t_msr (void)
13404{
62b3e311 13405 int flags;
fdfde340 13406 unsigned Rn;
62b3e311 13407
037e8744
JB
13408 if (do_vfp_nsyn_msr () == SUCCESS)
13409 return;
13410
c19d1205
ZW
13411 constraint (!inst.operands[1].isreg,
13412 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13413
13414 if (inst.operands[0].isreg)
13415 flags = (int)(inst.operands[0].reg);
13416 else
13417 flags = inst.operands[0].imm;
13418
d2cd1205 13419 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13420 {
d2cd1205
JB
13421 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13422
1a43faaf 13423 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13424 If the user has specified -march=all, we want to ignore it as
13425 we are building for any CPU type, including non-m variants. */
823d2571
TG
13426 bfd_boolean m_profile =
13427 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13428 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13429 && (bits & ~(PSR_s | PSR_f)) != 0)
13430 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13431 && bits != PSR_f)) && m_profile,
13432 _("selected processor does not support requested special "
13433 "purpose register"));
62b3e311
PB
13434 }
13435 else
d2cd1205
JB
13436 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13437 "requested special purpose register"));
c921be7d 13438
fdfde340
JM
13439 Rn = inst.operands[1].reg;
13440 reject_bad_reg (Rn);
13441
62b3e311 13442 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13443 inst.instruction |= (flags & 0xf0000) >> 8;
13444 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13445 inst.instruction |= (flags & 0xff);
fdfde340 13446 inst.instruction |= Rn << 16;
c19d1205 13447}
b05fe5cf 13448
c19d1205
ZW
13449static void
13450do_t_mul (void)
13451{
17828f45 13452 bfd_boolean narrow;
fdfde340 13453 unsigned Rd, Rn, Rm;
17828f45 13454
c19d1205
ZW
13455 if (!inst.operands[2].present)
13456 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13457
fdfde340
JM
13458 Rd = inst.operands[0].reg;
13459 Rn = inst.operands[1].reg;
13460 Rm = inst.operands[2].reg;
13461
17828f45 13462 if (unified_syntax)
b05fe5cf 13463 {
17828f45 13464 if (inst.size_req == 4
fdfde340
JM
13465 || (Rd != Rn
13466 && Rd != Rm)
13467 || Rn > 7
13468 || Rm > 7)
17828f45
JM
13469 narrow = FALSE;
13470 else if (inst.instruction == T_MNEM_muls)
5ee91343 13471 narrow = !in_pred_block ();
17828f45 13472 else
5ee91343 13473 narrow = in_pred_block ();
b05fe5cf 13474 }
c19d1205 13475 else
b05fe5cf 13476 {
17828f45 13477 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13478 constraint (Rn > 7 || Rm > 7,
c19d1205 13479 BAD_HIREG);
17828f45
JM
13480 narrow = TRUE;
13481 }
b05fe5cf 13482
17828f45
JM
13483 if (narrow)
13484 {
13485 /* 16-bit MULS/Conditional MUL. */
c19d1205 13486 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13487 inst.instruction |= Rd;
b05fe5cf 13488
fdfde340
JM
13489 if (Rd == Rn)
13490 inst.instruction |= Rm << 3;
13491 else if (Rd == Rm)
13492 inst.instruction |= Rn << 3;
c19d1205
ZW
13493 else
13494 constraint (1, _("dest must overlap one source register"));
13495 }
17828f45
JM
13496 else
13497 {
e07e6e58
NC
13498 constraint (inst.instruction != T_MNEM_mul,
13499 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13500 /* 32-bit MUL. */
13501 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13502 inst.instruction |= Rd << 8;
13503 inst.instruction |= Rn << 16;
13504 inst.instruction |= Rm << 0;
13505
13506 reject_bad_reg (Rd);
13507 reject_bad_reg (Rn);
13508 reject_bad_reg (Rm);
17828f45 13509 }
c19d1205 13510}
b05fe5cf 13511
c19d1205
ZW
13512static void
13513do_t_mull (void)
13514{
fdfde340 13515 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13516
fdfde340
JM
13517 RdLo = inst.operands[0].reg;
13518 RdHi = inst.operands[1].reg;
13519 Rn = inst.operands[2].reg;
13520 Rm = inst.operands[3].reg;
13521
13522 reject_bad_reg (RdLo);
13523 reject_bad_reg (RdHi);
13524 reject_bad_reg (Rn);
13525 reject_bad_reg (Rm);
13526
13527 inst.instruction |= RdLo << 12;
13528 inst.instruction |= RdHi << 8;
13529 inst.instruction |= Rn << 16;
13530 inst.instruction |= Rm;
13531
13532 if (RdLo == RdHi)
c19d1205
ZW
13533 as_tsktsk (_("rdhi and rdlo must be different"));
13534}
b05fe5cf 13535
c19d1205
ZW
13536static void
13537do_t_nop (void)
13538{
5ee91343 13539 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13540
c19d1205
ZW
13541 if (unified_syntax)
13542 {
13543 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13544 {
c19d1205
ZW
13545 inst.instruction = THUMB_OP32 (inst.instruction);
13546 inst.instruction |= inst.operands[0].imm;
13547 }
13548 else
13549 {
bc2d1808
NC
13550 /* PR9722: Check for Thumb2 availability before
13551 generating a thumb2 nop instruction. */
afa62d5e 13552 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13553 {
13554 inst.instruction = THUMB_OP16 (inst.instruction);
13555 inst.instruction |= inst.operands[0].imm << 4;
13556 }
13557 else
13558 inst.instruction = 0x46c0;
c19d1205
ZW
13559 }
13560 }
13561 else
13562 {
13563 constraint (inst.operands[0].present,
13564 _("Thumb does not support NOP with hints"));
13565 inst.instruction = 0x46c0;
13566 }
13567}
b05fe5cf 13568
c19d1205
ZW
13569static void
13570do_t_neg (void)
13571{
13572 if (unified_syntax)
13573 {
3d388997
PB
13574 bfd_boolean narrow;
13575
13576 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13577 narrow = !in_pred_block ();
3d388997 13578 else
5ee91343 13579 narrow = in_pred_block ();
3d388997
PB
13580 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13581 narrow = FALSE;
13582 if (inst.size_req == 4)
13583 narrow = FALSE;
13584
13585 if (!narrow)
c19d1205
ZW
13586 {
13587 inst.instruction = THUMB_OP32 (inst.instruction);
13588 inst.instruction |= inst.operands[0].reg << 8;
13589 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13590 }
13591 else
13592 {
c19d1205
ZW
13593 inst.instruction = THUMB_OP16 (inst.instruction);
13594 inst.instruction |= inst.operands[0].reg;
13595 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13596 }
13597 }
13598 else
13599 {
c19d1205
ZW
13600 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13601 BAD_HIREG);
13602 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13603
13604 inst.instruction = THUMB_OP16 (inst.instruction);
13605 inst.instruction |= inst.operands[0].reg;
13606 inst.instruction |= inst.operands[1].reg << 3;
13607 }
13608}
13609
1c444d06
JM
13610static void
13611do_t_orn (void)
13612{
13613 unsigned Rd, Rn;
13614
13615 Rd = inst.operands[0].reg;
13616 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13617
fdfde340
JM
13618 reject_bad_reg (Rd);
13619 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13620 reject_bad_reg (Rn);
13621
1c444d06
JM
13622 inst.instruction |= Rd << 8;
13623 inst.instruction |= Rn << 16;
13624
13625 if (!inst.operands[2].isreg)
13626 {
13627 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13628 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13629 }
13630 else
13631 {
13632 unsigned Rm;
13633
13634 Rm = inst.operands[2].reg;
fdfde340 13635 reject_bad_reg (Rm);
1c444d06
JM
13636
13637 constraint (inst.operands[2].shifted
13638 && inst.operands[2].immisreg,
13639 _("shift must be constant"));
13640 encode_thumb32_shifted_operand (2);
13641 }
13642}
13643
c19d1205
ZW
13644static void
13645do_t_pkhbt (void)
13646{
fdfde340
JM
13647 unsigned Rd, Rn, Rm;
13648
13649 Rd = inst.operands[0].reg;
13650 Rn = inst.operands[1].reg;
13651 Rm = inst.operands[2].reg;
13652
13653 reject_bad_reg (Rd);
13654 reject_bad_reg (Rn);
13655 reject_bad_reg (Rm);
13656
13657 inst.instruction |= Rd << 8;
13658 inst.instruction |= Rn << 16;
13659 inst.instruction |= Rm;
c19d1205
ZW
13660 if (inst.operands[3].present)
13661 {
e2b0ab59
AV
13662 unsigned int val = inst.relocs[0].exp.X_add_number;
13663 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13664 _("expression too complex"));
13665 inst.instruction |= (val & 0x1c) << 10;
13666 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13667 }
c19d1205 13668}
b05fe5cf 13669
c19d1205
ZW
13670static void
13671do_t_pkhtb (void)
13672{
13673 if (!inst.operands[3].present)
1ef52f49
NC
13674 {
13675 unsigned Rtmp;
13676
13677 inst.instruction &= ~0x00000020;
13678
13679 /* PR 10168. Swap the Rm and Rn registers. */
13680 Rtmp = inst.operands[1].reg;
13681 inst.operands[1].reg = inst.operands[2].reg;
13682 inst.operands[2].reg = Rtmp;
13683 }
c19d1205 13684 do_t_pkhbt ();
b05fe5cf
ZW
13685}
13686
c19d1205
ZW
13687static void
13688do_t_pld (void)
13689{
fdfde340
JM
13690 if (inst.operands[0].immisreg)
13691 reject_bad_reg (inst.operands[0].imm);
13692
c19d1205
ZW
13693 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13694}
b05fe5cf 13695
c19d1205
ZW
13696static void
13697do_t_push_pop (void)
b99bd4ef 13698{
e9f89963 13699 unsigned mask;
5f4273c7 13700
c19d1205
ZW
13701 constraint (inst.operands[0].writeback,
13702 _("push/pop do not support {reglist}^"));
e2b0ab59 13703 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13704 _("expression too complex"));
b99bd4ef 13705
e9f89963 13706 mask = inst.operands[0].imm;
d3bfe16e 13707 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13708 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13709 else if (inst.size_req != 4
c6025a80 13710 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13711 ? REG_LR : REG_PC)))
b99bd4ef 13712 {
c19d1205
ZW
13713 inst.instruction = THUMB_OP16 (inst.instruction);
13714 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13715 inst.instruction |= mask & 0xff;
c19d1205
ZW
13716 }
13717 else if (unified_syntax)
13718 {
3c707909 13719 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13720 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13721 }
13722 else
13723 {
13724 inst.error = _("invalid register list to push/pop instruction");
13725 return;
c19d1205 13726 }
4b5a202f
AV
13727}
13728
13729static void
13730do_t_clrm (void)
13731{
13732 if (unified_syntax)
13733 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13734 else
13735 {
13736 inst.error = _("invalid register list to push/pop instruction");
13737 return;
13738 }
c19d1205 13739}
b99bd4ef 13740
efd6b359
AV
13741static void
13742do_t_vscclrm (void)
13743{
13744 if (inst.operands[0].issingle)
13745 {
13746 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13747 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13748 inst.instruction |= inst.operands[0].imm;
13749 }
13750 else
13751 {
13752 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13753 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13754 inst.instruction |= 1 << 8;
13755 inst.instruction |= inst.operands[0].imm << 1;
13756 }
13757}
13758
c19d1205
ZW
13759static void
13760do_t_rbit (void)
13761{
fdfde340
JM
13762 unsigned Rd, Rm;
13763
13764 Rd = inst.operands[0].reg;
13765 Rm = inst.operands[1].reg;
13766
13767 reject_bad_reg (Rd);
13768 reject_bad_reg (Rm);
13769
13770 inst.instruction |= Rd << 8;
13771 inst.instruction |= Rm << 16;
13772 inst.instruction |= Rm;
c19d1205 13773}
b99bd4ef 13774
c19d1205
ZW
13775static void
13776do_t_rev (void)
13777{
fdfde340
JM
13778 unsigned Rd, Rm;
13779
13780 Rd = inst.operands[0].reg;
13781 Rm = inst.operands[1].reg;
13782
13783 reject_bad_reg (Rd);
13784 reject_bad_reg (Rm);
13785
13786 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13787 && inst.size_req != 4)
13788 {
13789 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13790 inst.instruction |= Rd;
13791 inst.instruction |= Rm << 3;
c19d1205
ZW
13792 }
13793 else if (unified_syntax)
13794 {
13795 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13796 inst.instruction |= Rd << 8;
13797 inst.instruction |= Rm << 16;
13798 inst.instruction |= Rm;
c19d1205
ZW
13799 }
13800 else
13801 inst.error = BAD_HIREG;
13802}
b99bd4ef 13803
1c444d06
JM
13804static void
13805do_t_rrx (void)
13806{
13807 unsigned Rd, Rm;
13808
13809 Rd = inst.operands[0].reg;
13810 Rm = inst.operands[1].reg;
13811
fdfde340
JM
13812 reject_bad_reg (Rd);
13813 reject_bad_reg (Rm);
c921be7d 13814
1c444d06
JM
13815 inst.instruction |= Rd << 8;
13816 inst.instruction |= Rm;
13817}
13818
c19d1205
ZW
13819static void
13820do_t_rsb (void)
13821{
fdfde340 13822 unsigned Rd, Rs;
b99bd4ef 13823
c19d1205
ZW
13824 Rd = inst.operands[0].reg;
13825 Rs = (inst.operands[1].present
13826 ? inst.operands[1].reg /* Rd, Rs, foo */
13827 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13828
fdfde340
JM
13829 reject_bad_reg (Rd);
13830 reject_bad_reg (Rs);
13831 if (inst.operands[2].isreg)
13832 reject_bad_reg (inst.operands[2].reg);
13833
c19d1205
ZW
13834 inst.instruction |= Rd << 8;
13835 inst.instruction |= Rs << 16;
13836 if (!inst.operands[2].isreg)
13837 {
026d3abb
PB
13838 bfd_boolean narrow;
13839
13840 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13841 narrow = !in_pred_block ();
026d3abb 13842 else
5ee91343 13843 narrow = in_pred_block ();
026d3abb
PB
13844
13845 if (Rd > 7 || Rs > 7)
13846 narrow = FALSE;
13847
13848 if (inst.size_req == 4 || !unified_syntax)
13849 narrow = FALSE;
13850
e2b0ab59
AV
13851 if (inst.relocs[0].exp.X_op != O_constant
13852 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13853 narrow = FALSE;
13854
13855 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13856 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13857 if (narrow)
13858 {
e2b0ab59 13859 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13860 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13861 inst.instruction |= Rs << 3;
13862 inst.instruction |= Rd;
13863 }
13864 else
13865 {
13866 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13867 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13868 }
c19d1205
ZW
13869 }
13870 else
13871 encode_thumb32_shifted_operand (2);
13872}
b99bd4ef 13873
c19d1205
ZW
13874static void
13875do_t_setend (void)
13876{
12e37cbc
MGD
13877 if (warn_on_deprecated
13878 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13879 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13880
5ee91343 13881 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13882 if (inst.operands[0].imm)
13883 inst.instruction |= 0x8;
13884}
b99bd4ef 13885
c19d1205
ZW
13886static void
13887do_t_shift (void)
13888{
13889 if (!inst.operands[1].present)
13890 inst.operands[1].reg = inst.operands[0].reg;
13891
13892 if (unified_syntax)
13893 {
3d388997
PB
13894 bfd_boolean narrow;
13895 int shift_kind;
13896
13897 switch (inst.instruction)
13898 {
13899 case T_MNEM_asr:
13900 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13901 case T_MNEM_lsl:
13902 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13903 case T_MNEM_lsr:
13904 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13905 case T_MNEM_ror:
13906 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13907 default: abort ();
13908 }
13909
13910 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13911 narrow = !in_pred_block ();
3d388997 13912 else
5ee91343 13913 narrow = in_pred_block ();
3d388997
PB
13914 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13915 narrow = FALSE;
13916 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13917 narrow = FALSE;
13918 if (inst.operands[2].isreg
13919 && (inst.operands[1].reg != inst.operands[0].reg
13920 || inst.operands[2].reg > 7))
13921 narrow = FALSE;
13922 if (inst.size_req == 4)
13923 narrow = FALSE;
13924
fdfde340
JM
13925 reject_bad_reg (inst.operands[0].reg);
13926 reject_bad_reg (inst.operands[1].reg);
c921be7d 13927
3d388997 13928 if (!narrow)
c19d1205
ZW
13929 {
13930 if (inst.operands[2].isreg)
b99bd4ef 13931 {
fdfde340 13932 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13933 inst.instruction = THUMB_OP32 (inst.instruction);
13934 inst.instruction |= inst.operands[0].reg << 8;
13935 inst.instruction |= inst.operands[1].reg << 16;
13936 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13937
13938 /* PR 12854: Error on extraneous shifts. */
13939 constraint (inst.operands[2].shifted,
13940 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13941 }
13942 else
13943 {
13944 inst.operands[1].shifted = 1;
3d388997 13945 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13946 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13947 ? T_MNEM_movs : T_MNEM_mov);
13948 inst.instruction |= inst.operands[0].reg << 8;
13949 encode_thumb32_shifted_operand (1);
13950 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13951 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13952 }
13953 }
13954 else
13955 {
c19d1205 13956 if (inst.operands[2].isreg)
b99bd4ef 13957 {
3d388997 13958 switch (shift_kind)
b99bd4ef 13959 {
3d388997
PB
13960 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13961 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13962 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13963 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13964 default: abort ();
b99bd4ef 13965 }
5f4273c7 13966
c19d1205
ZW
13967 inst.instruction |= inst.operands[0].reg;
13968 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13969
13970 /* PR 12854: Error on extraneous shifts. */
13971 constraint (inst.operands[2].shifted,
13972 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13973 }
13974 else
13975 {
3d388997 13976 switch (shift_kind)
b99bd4ef 13977 {
3d388997
PB
13978 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13979 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13980 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13981 default: abort ();
b99bd4ef 13982 }
e2b0ab59 13983 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13984 inst.instruction |= inst.operands[0].reg;
13985 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13986 }
13987 }
c19d1205
ZW
13988 }
13989 else
13990 {
13991 constraint (inst.operands[0].reg > 7
13992 || inst.operands[1].reg > 7, BAD_HIREG);
13993 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 13994
c19d1205
ZW
13995 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13996 {
13997 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13998 constraint (inst.operands[0].reg != inst.operands[1].reg,
13999 _("source1 and dest must be same register"));
b99bd4ef 14000
c19d1205
ZW
14001 switch (inst.instruction)
14002 {
14003 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14004 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14005 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14006 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14007 default: abort ();
14008 }
5f4273c7 14009
c19d1205
ZW
14010 inst.instruction |= inst.operands[0].reg;
14011 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
14012
14013 /* PR 12854: Error on extraneous shifts. */
14014 constraint (inst.operands[2].shifted,
14015 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
14016 }
14017 else
b99bd4ef 14018 {
c19d1205
ZW
14019 switch (inst.instruction)
14020 {
14021 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14022 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14023 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14024 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14025 default: abort ();
14026 }
e2b0ab59 14027 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14028 inst.instruction |= inst.operands[0].reg;
14029 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14030 }
14031 }
b99bd4ef
NC
14032}
14033
14034static void
c19d1205 14035do_t_simd (void)
b99bd4ef 14036{
fdfde340
JM
14037 unsigned Rd, Rn, Rm;
14038
14039 Rd = inst.operands[0].reg;
14040 Rn = inst.operands[1].reg;
14041 Rm = inst.operands[2].reg;
14042
14043 reject_bad_reg (Rd);
14044 reject_bad_reg (Rn);
14045 reject_bad_reg (Rm);
14046
14047 inst.instruction |= Rd << 8;
14048 inst.instruction |= Rn << 16;
14049 inst.instruction |= Rm;
c19d1205 14050}
b99bd4ef 14051
03ee1b7f
NC
14052static void
14053do_t_simd2 (void)
14054{
14055 unsigned Rd, Rn, Rm;
14056
14057 Rd = inst.operands[0].reg;
14058 Rm = inst.operands[1].reg;
14059 Rn = inst.operands[2].reg;
14060
14061 reject_bad_reg (Rd);
14062 reject_bad_reg (Rn);
14063 reject_bad_reg (Rm);
14064
14065 inst.instruction |= Rd << 8;
14066 inst.instruction |= Rn << 16;
14067 inst.instruction |= Rm;
14068}
14069
c19d1205 14070static void
3eb17e6b 14071do_t_smc (void)
c19d1205 14072{
e2b0ab59 14073 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
14074 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14075 _("SMC is not permitted on this architecture"));
e2b0ab59 14076 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14077 _("expression too complex"));
ba85f98c
BW
14078 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14079
e2b0ab59 14080 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 14081 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 14082
24382199 14083 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 14084 set_pred_insn_type_last ();
c19d1205 14085}
b99bd4ef 14086
90ec0d68
MGD
14087static void
14088do_t_hvc (void)
14089{
e2b0ab59 14090 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 14091
e2b0ab59 14092 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
14093 inst.instruction |= (value & 0x0fff);
14094 inst.instruction |= (value & 0xf000) << 4;
14095}
14096
c19d1205 14097static void
3a21c15a 14098do_t_ssat_usat (int bias)
c19d1205 14099{
fdfde340
JM
14100 unsigned Rd, Rn;
14101
14102 Rd = inst.operands[0].reg;
14103 Rn = inst.operands[2].reg;
14104
14105 reject_bad_reg (Rd);
14106 reject_bad_reg (Rn);
14107
14108 inst.instruction |= Rd << 8;
3a21c15a 14109 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 14110 inst.instruction |= Rn << 16;
b99bd4ef 14111
c19d1205 14112 if (inst.operands[3].present)
b99bd4ef 14113 {
e2b0ab59 14114 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 14115
e2b0ab59 14116 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 14117
e2b0ab59 14118 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14119 _("expression too complex"));
b99bd4ef 14120
3a21c15a 14121 if (shift_amount != 0)
6189168b 14122 {
3a21c15a
NC
14123 constraint (shift_amount > 31,
14124 _("shift expression is too large"));
14125
c19d1205 14126 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
14127 inst.instruction |= 0x00200000; /* sh bit. */
14128
14129 inst.instruction |= (shift_amount & 0x1c) << 10;
14130 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14131 }
14132 }
b99bd4ef 14133}
c921be7d 14134
3a21c15a
NC
14135static void
14136do_t_ssat (void)
14137{
14138 do_t_ssat_usat (1);
14139}
b99bd4ef 14140
0dd132b6 14141static void
c19d1205 14142do_t_ssat16 (void)
0dd132b6 14143{
fdfde340
JM
14144 unsigned Rd, Rn;
14145
14146 Rd = inst.operands[0].reg;
14147 Rn = inst.operands[2].reg;
14148
14149 reject_bad_reg (Rd);
14150 reject_bad_reg (Rn);
14151
14152 inst.instruction |= Rd << 8;
c19d1205 14153 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14154 inst.instruction |= Rn << 16;
c19d1205 14155}
0dd132b6 14156
c19d1205
ZW
14157static void
14158do_t_strex (void)
14159{
14160 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14161 || inst.operands[2].postind || inst.operands[2].writeback
14162 || inst.operands[2].immisreg || inst.operands[2].shifted
14163 || inst.operands[2].negative,
01cfc07f 14164 BAD_ADDR_MODE);
0dd132b6 14165
5be8be5d
DG
14166 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14167
c19d1205
ZW
14168 inst.instruction |= inst.operands[0].reg << 8;
14169 inst.instruction |= inst.operands[1].reg << 12;
14170 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14171 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14172}
14173
b99bd4ef 14174static void
c19d1205 14175do_t_strexd (void)
b99bd4ef 14176{
c19d1205
ZW
14177 if (!inst.operands[2].present)
14178 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14179
c19d1205
ZW
14180 constraint (inst.operands[0].reg == inst.operands[1].reg
14181 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14182 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14183 BAD_OVERLAP);
b99bd4ef 14184
c19d1205
ZW
14185 inst.instruction |= inst.operands[0].reg;
14186 inst.instruction |= inst.operands[1].reg << 12;
14187 inst.instruction |= inst.operands[2].reg << 8;
14188 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14189}
14190
14191static void
c19d1205 14192do_t_sxtah (void)
b99bd4ef 14193{
fdfde340
JM
14194 unsigned Rd, Rn, Rm;
14195
14196 Rd = inst.operands[0].reg;
14197 Rn = inst.operands[1].reg;
14198 Rm = inst.operands[2].reg;
14199
14200 reject_bad_reg (Rd);
14201 reject_bad_reg (Rn);
14202 reject_bad_reg (Rm);
14203
14204 inst.instruction |= Rd << 8;
14205 inst.instruction |= Rn << 16;
14206 inst.instruction |= Rm;
c19d1205
ZW
14207 inst.instruction |= inst.operands[3].imm << 4;
14208}
b99bd4ef 14209
c19d1205
ZW
14210static void
14211do_t_sxth (void)
14212{
fdfde340
JM
14213 unsigned Rd, Rm;
14214
14215 Rd = inst.operands[0].reg;
14216 Rm = inst.operands[1].reg;
14217
14218 reject_bad_reg (Rd);
14219 reject_bad_reg (Rm);
c921be7d
NC
14220
14221 if (inst.instruction <= 0xffff
14222 && inst.size_req != 4
fdfde340 14223 && Rd <= 7 && Rm <= 7
c19d1205 14224 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14225 {
c19d1205 14226 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14227 inst.instruction |= Rd;
14228 inst.instruction |= Rm << 3;
b99bd4ef 14229 }
c19d1205 14230 else if (unified_syntax)
b99bd4ef 14231 {
c19d1205
ZW
14232 if (inst.instruction <= 0xffff)
14233 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14234 inst.instruction |= Rd << 8;
14235 inst.instruction |= Rm;
c19d1205 14236 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14237 }
c19d1205 14238 else
b99bd4ef 14239 {
c19d1205
ZW
14240 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14241 _("Thumb encoding does not support rotation"));
14242 constraint (1, BAD_HIREG);
b99bd4ef 14243 }
c19d1205 14244}
b99bd4ef 14245
c19d1205
ZW
14246static void
14247do_t_swi (void)
14248{
e2b0ab59 14249 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14250}
b99bd4ef 14251
92e90b6e
PB
14252static void
14253do_t_tb (void)
14254{
fdfde340 14255 unsigned Rn, Rm;
92e90b6e
PB
14256 int half;
14257
14258 half = (inst.instruction & 0x10) != 0;
5ee91343 14259 set_pred_insn_type_last ();
dfa9f0d5
PB
14260 constraint (inst.operands[0].immisreg,
14261 _("instruction requires register index"));
fdfde340
JM
14262
14263 Rn = inst.operands[0].reg;
14264 Rm = inst.operands[0].imm;
c921be7d 14265
5c8ed6a4
JW
14266 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14267 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14268 reject_bad_reg (Rm);
14269
92e90b6e
PB
14270 constraint (!half && inst.operands[0].shifted,
14271 _("instruction does not allow shifted index"));
fdfde340 14272 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14273}
14274
74db7efb
NC
14275static void
14276do_t_udf (void)
14277{
14278 if (!inst.operands[0].present)
14279 inst.operands[0].imm = 0;
14280
14281 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14282 {
14283 constraint (inst.size_req == 2,
14284 _("immediate value out of range"));
14285 inst.instruction = THUMB_OP32 (inst.instruction);
14286 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14287 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14288 }
14289 else
14290 {
14291 inst.instruction = THUMB_OP16 (inst.instruction);
14292 inst.instruction |= inst.operands[0].imm;
14293 }
14294
5ee91343 14295 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14296}
14297
14298
c19d1205
ZW
14299static void
14300do_t_usat (void)
14301{
3a21c15a 14302 do_t_ssat_usat (0);
b99bd4ef
NC
14303}
14304
14305static void
c19d1205 14306do_t_usat16 (void)
b99bd4ef 14307{
fdfde340
JM
14308 unsigned Rd, Rn;
14309
14310 Rd = inst.operands[0].reg;
14311 Rn = inst.operands[2].reg;
14312
14313 reject_bad_reg (Rd);
14314 reject_bad_reg (Rn);
14315
14316 inst.instruction |= Rd << 8;
c19d1205 14317 inst.instruction |= inst.operands[1].imm;
fdfde340 14318 inst.instruction |= Rn << 16;
b99bd4ef 14319}
c19d1205 14320
e12437dc
AV
14321/* Checking the range of the branch offset (VAL) with NBITS bits
14322 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14323static int
14324v8_1_branch_value_check (int val, int nbits, int is_signed)
14325{
14326 gas_assert (nbits > 0 && nbits <= 32);
14327 if (is_signed)
14328 {
14329 int cmp = (1 << (nbits - 1));
14330 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14331 return FAIL;
14332 }
14333 else
14334 {
14335 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14336 return FAIL;
14337 }
14338 return SUCCESS;
14339}
14340
4389b29a
AV
14341/* For branches in Armv8.1-M Mainline. */
14342static void
14343do_t_branch_future (void)
14344{
14345 unsigned long insn = inst.instruction;
14346
14347 inst.instruction = THUMB_OP32 (inst.instruction);
14348 if (inst.operands[0].hasreloc == 0)
14349 {
14350 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14351 as_bad (BAD_BRANCH_OFF);
14352
14353 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14354 }
14355 else
14356 {
14357 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14358 inst.relocs[0].pc_rel = 1;
14359 }
14360
14361 switch (insn)
14362 {
14363 case T_MNEM_bf:
14364 if (inst.operands[1].hasreloc == 0)
14365 {
14366 int val = inst.operands[1].imm;
14367 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14368 as_bad (BAD_BRANCH_OFF);
14369
14370 int immA = (val & 0x0001f000) >> 12;
14371 int immB = (val & 0x00000ffc) >> 2;
14372 int immC = (val & 0x00000002) >> 1;
14373 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14374 }
14375 else
14376 {
14377 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14378 inst.relocs[1].pc_rel = 1;
14379 }
14380 break;
14381
65d1bc05
AV
14382 case T_MNEM_bfl:
14383 if (inst.operands[1].hasreloc == 0)
14384 {
14385 int val = inst.operands[1].imm;
14386 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14387 as_bad (BAD_BRANCH_OFF);
14388
14389 int immA = (val & 0x0007f000) >> 12;
14390 int immB = (val & 0x00000ffc) >> 2;
14391 int immC = (val & 0x00000002) >> 1;
14392 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14393 }
14394 else
14395 {
14396 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14397 inst.relocs[1].pc_rel = 1;
14398 }
14399 break;
14400
f6b2b12d
AV
14401 case T_MNEM_bfcsel:
14402 /* Operand 1. */
14403 if (inst.operands[1].hasreloc == 0)
14404 {
14405 int val = inst.operands[1].imm;
14406 int immA = (val & 0x00001000) >> 12;
14407 int immB = (val & 0x00000ffc) >> 2;
14408 int immC = (val & 0x00000002) >> 1;
14409 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14410 }
14411 else
14412 {
14413 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14414 inst.relocs[1].pc_rel = 1;
14415 }
14416
14417 /* Operand 2. */
14418 if (inst.operands[2].hasreloc == 0)
14419 {
14420 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14421 int val2 = inst.operands[2].imm;
14422 int val0 = inst.operands[0].imm & 0x1f;
14423 int diff = val2 - val0;
14424 if (diff == 4)
14425 inst.instruction |= 1 << 17; /* T bit. */
14426 else if (diff != 2)
14427 as_bad (_("out of range label-relative fixup value"));
14428 }
14429 else
14430 {
14431 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14432 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14433 inst.relocs[2].pc_rel = 1;
14434 }
14435
14436 /* Operand 3. */
14437 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14438 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14439 break;
14440
f1c7f421
AV
14441 case T_MNEM_bfx:
14442 case T_MNEM_bflx:
14443 inst.instruction |= inst.operands[1].reg << 16;
14444 break;
14445
4389b29a
AV
14446 default: abort ();
14447 }
14448}
14449
60f993ce
AV
14450/* Helper function for do_t_loloop to handle relocations. */
14451static void
14452v8_1_loop_reloc (int is_le)
14453{
14454 if (inst.relocs[0].exp.X_op == O_constant)
14455 {
14456 int value = inst.relocs[0].exp.X_add_number;
14457 value = (is_le) ? -value : value;
14458
14459 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14460 as_bad (BAD_BRANCH_OFF);
14461
14462 int imml, immh;
14463
14464 immh = (value & 0x00000ffc) >> 2;
14465 imml = (value & 0x00000002) >> 1;
14466
14467 inst.instruction |= (imml << 11) | (immh << 1);
14468 }
14469 else
14470 {
14471 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14472 inst.relocs[0].pc_rel = 1;
14473 }
14474}
14475
08132bdd
SP
14476/* For shifts with four operands in MVE. */
14477static void
14478do_mve_scalar_shift1 (void)
14479{
14480 unsigned int value = inst.operands[2].imm;
14481
14482 inst.instruction |= inst.operands[0].reg << 16;
14483 inst.instruction |= inst.operands[1].reg << 8;
14484
14485 /* Setting the bit for saturation. */
14486 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14487
14488 /* Assuming Rm is already checked not to be 11x1. */
14489 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14490 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14491 inst.instruction |= inst.operands[3].reg << 12;
14492}
14493
23d00a41
SD
14494/* For shifts in MVE. */
14495static void
14496do_mve_scalar_shift (void)
14497{
14498 if (!inst.operands[2].present)
14499 {
14500 inst.operands[2] = inst.operands[1];
14501 inst.operands[1].reg = 0xf;
14502 }
14503
14504 inst.instruction |= inst.operands[0].reg << 16;
14505 inst.instruction |= inst.operands[1].reg << 8;
14506
14507 if (inst.operands[2].isreg)
14508 {
14509 /* Assuming Rm is already checked not to be 11x1. */
14510 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14511 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14512 inst.instruction |= inst.operands[2].reg << 12;
14513 }
14514 else
14515 {
14516 /* Assuming imm is already checked as [1,32]. */
14517 unsigned int value = inst.operands[2].imm;
14518 inst.instruction |= (value & 0x1c) << 10;
14519 inst.instruction |= (value & 0x03) << 6;
14520 /* Change last 4 bits from 0xd to 0xf. */
14521 inst.instruction |= 0x2;
14522 }
14523}
14524
a302e574
AV
14525/* MVE instruction encoder helpers. */
14526#define M_MNEM_vabav 0xee800f01
14527#define M_MNEM_vmladav 0xeef00e00
14528#define M_MNEM_vmladava 0xeef00e20
14529#define M_MNEM_vmladavx 0xeef01e00
14530#define M_MNEM_vmladavax 0xeef01e20
14531#define M_MNEM_vmlsdav 0xeef00e01
14532#define M_MNEM_vmlsdava 0xeef00e21
14533#define M_MNEM_vmlsdavx 0xeef01e01
14534#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14535#define M_MNEM_vmullt 0xee011e00
14536#define M_MNEM_vmullb 0xee010e00
efd0b310 14537#define M_MNEM_vctp 0xf000e801
35c228db
AV
14538#define M_MNEM_vst20 0xfc801e00
14539#define M_MNEM_vst21 0xfc801e20
14540#define M_MNEM_vst40 0xfc801e01
14541#define M_MNEM_vst41 0xfc801e21
14542#define M_MNEM_vst42 0xfc801e41
14543#define M_MNEM_vst43 0xfc801e61
14544#define M_MNEM_vld20 0xfc901e00
14545#define M_MNEM_vld21 0xfc901e20
14546#define M_MNEM_vld40 0xfc901e01
14547#define M_MNEM_vld41 0xfc901e21
14548#define M_MNEM_vld42 0xfc901e41
14549#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14550#define M_MNEM_vstrb 0xec000e00
14551#define M_MNEM_vstrh 0xec000e10
14552#define M_MNEM_vstrw 0xec000e40
14553#define M_MNEM_vstrd 0xec000e50
14554#define M_MNEM_vldrb 0xec100e00
14555#define M_MNEM_vldrh 0xec100e10
14556#define M_MNEM_vldrw 0xec100e40
14557#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14558#define M_MNEM_vmovlt 0xeea01f40
14559#define M_MNEM_vmovlb 0xeea00f40
14560#define M_MNEM_vmovnt 0xfe311e81
14561#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14562#define M_MNEM_vadc 0xee300f00
14563#define M_MNEM_vadci 0xee301f00
14564#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14565#define M_MNEM_vaddlv 0xee890f00
14566#define M_MNEM_vaddlva 0xee890f20
14567#define M_MNEM_vaddv 0xeef10f00
14568#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14569#define M_MNEM_vddup 0xee011f6e
14570#define M_MNEM_vdwdup 0xee011f60
14571#define M_MNEM_vidup 0xee010f6e
14572#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14573#define M_MNEM_vmaxv 0xeee20f00
14574#define M_MNEM_vmaxav 0xeee00f00
14575#define M_MNEM_vminv 0xeee20f80
14576#define M_MNEM_vminav 0xeee00f80
93925576
AV
14577#define M_MNEM_vmlaldav 0xee800e00
14578#define M_MNEM_vmlaldava 0xee800e20
14579#define M_MNEM_vmlaldavx 0xee801e00
14580#define M_MNEM_vmlaldavax 0xee801e20
14581#define M_MNEM_vmlsldav 0xee800e01
14582#define M_MNEM_vmlsldava 0xee800e21
14583#define M_MNEM_vmlsldavx 0xee801e01
14584#define M_MNEM_vmlsldavax 0xee801e21
14585#define M_MNEM_vrmlaldavhx 0xee801f00
14586#define M_MNEM_vrmlaldavhax 0xee801f20
14587#define M_MNEM_vrmlsldavh 0xfe800e01
14588#define M_MNEM_vrmlsldavha 0xfe800e21
14589#define M_MNEM_vrmlsldavhx 0xfe801e01
14590#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14591#define M_MNEM_vqmovnt 0xee331e01
14592#define M_MNEM_vqmovnb 0xee330e01
14593#define M_MNEM_vqmovunt 0xee311e81
14594#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14595#define M_MNEM_vshrnt 0xee801fc1
14596#define M_MNEM_vshrnb 0xee800fc1
14597#define M_MNEM_vrshrnt 0xfe801fc1
14598#define M_MNEM_vqshrnt 0xee801f40
14599#define M_MNEM_vqshrnb 0xee800f40
14600#define M_MNEM_vqshrunt 0xee801fc0
14601#define M_MNEM_vqshrunb 0xee800fc0
14602#define M_MNEM_vrshrnb 0xfe800fc1
14603#define M_MNEM_vqrshrnt 0xee801f41
14604#define M_MNEM_vqrshrnb 0xee800f41
14605#define M_MNEM_vqrshrunt 0xfe801fc0
14606#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14607
aab2c27d
MM
14608/* Bfloat16 instruction encoder helpers. */
14609#define B_MNEM_vfmat 0xfc300850
14610#define B_MNEM_vfmab 0xfc300810
14611
5287ad62 14612/* Neon instruction encoder helpers. */
5f4273c7 14613
5287ad62 14614/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14615
5287ad62
JB
14616/* An "invalid" code for the following tables. */
14617#define N_INV -1u
14618
14619struct neon_tab_entry
b99bd4ef 14620{
5287ad62
JB
14621 unsigned integer;
14622 unsigned float_or_poly;
14623 unsigned scalar_or_imm;
14624};
5f4273c7 14625
5287ad62
JB
14626/* Map overloaded Neon opcodes to their respective encodings. */
14627#define NEON_ENC_TAB \
14628 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14629 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14630 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14631 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14632 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14633 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14634 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14635 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14636 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14637 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14638 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14639 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14640 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14641 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14642 /* Register variants of the following two instructions are encoded as
e07e6e58 14643 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14644 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14645 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14646 X(vfma, N_INV, 0x0000c10, N_INV), \
14647 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14648 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14649 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14650 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14651 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14652 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14653 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14654 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14655 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14656 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14657 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14658 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14659 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14660 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14661 X(vshl, 0x0000400, N_INV, 0x0800510), \
14662 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14663 X(vand, 0x0000110, N_INV, 0x0800030), \
14664 X(vbic, 0x0100110, N_INV, 0x0800030), \
14665 X(veor, 0x1000110, N_INV, N_INV), \
14666 X(vorn, 0x0300110, N_INV, 0x0800010), \
14667 X(vorr, 0x0200110, N_INV, 0x0800010), \
14668 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14669 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14670 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14671 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14672 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14673 X(vst1, 0x0000000, 0x0800000, N_INV), \
14674 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14675 X(vst2, 0x0000100, 0x0800100, N_INV), \
14676 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14677 X(vst3, 0x0000200, 0x0800200, N_INV), \
14678 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14679 X(vst4, 0x0000300, 0x0800300, N_INV), \
14680 X(vmovn, 0x1b20200, N_INV, N_INV), \
14681 X(vtrn, 0x1b20080, N_INV, N_INV), \
14682 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14683 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14684 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14685 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14686 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14687 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14688 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14689 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14690 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14691 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14692 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14693 X(vseleq, 0xe000a00, N_INV, N_INV), \
14694 X(vselvs, 0xe100a00, N_INV, N_INV), \
14695 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14696 X(vselgt, 0xe300a00, N_INV, N_INV), \
14697 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14698 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14699 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14700 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14701 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14702 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14703 X(sha3op, 0x2000c00, N_INV, N_INV), \
14704 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14705 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14706
14707enum neon_opc
14708{
14709#define X(OPC,I,F,S) N_MNEM_##OPC
14710NEON_ENC_TAB
14711#undef X
14712};
b99bd4ef 14713
5287ad62
JB
14714static const struct neon_tab_entry neon_enc_tab[] =
14715{
14716#define X(OPC,I,F,S) { (I), (F), (S) }
14717NEON_ENC_TAB
14718#undef X
14719};
b99bd4ef 14720
88714cb8
DG
14721/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14722#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14723#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14724#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14725#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14726#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14727#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14728#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14729#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14730#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14731#define NEON_ENC_SINGLE_(X) \
037e8744 14732 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14733#define NEON_ENC_DOUBLE_(X) \
037e8744 14734 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14735#define NEON_ENC_FPV8_(X) \
14736 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14737
88714cb8
DG
14738#define NEON_ENCODE(type, inst) \
14739 do \
14740 { \
14741 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14742 inst.is_neon = 1; \
14743 } \
14744 while (0)
14745
14746#define check_neon_suffixes \
14747 do \
14748 { \
14749 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14750 { \
14751 as_bad (_("invalid neon suffix for non neon instruction")); \
14752 return; \
14753 } \
14754 } \
14755 while (0)
14756
037e8744
JB
14757/* Define shapes for instruction operands. The following mnemonic characters
14758 are used in this table:
5287ad62 14759
037e8744 14760 F - VFP S<n> register
5287ad62
JB
14761 D - Neon D<n> register
14762 Q - Neon Q<n> register
14763 I - Immediate
14764 S - Scalar
14765 R - ARM register
14766 L - D<n> register list
5f4273c7 14767
037e8744
JB
14768 This table is used to generate various data:
14769 - enumerations of the form NS_DDR to be used as arguments to
14770 neon_select_shape.
14771 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14772 - a table used to drive neon_select_shape. */
b99bd4ef 14773
037e8744 14774#define NEON_SHAPE_DEF \
93925576 14775 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14776 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14777 X(4, (R, R, S, S), QUAD), \
14778 X(4, (S, S, R, R), QUAD), \
b409bdb6 14779 X(3, (Q, R, I), QUAD), \
1b883319
AV
14780 X(3, (I, Q, Q), QUAD), \
14781 X(3, (I, Q, R), QUAD), \
a302e574 14782 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14783 X(3, (D, D, D), DOUBLE), \
14784 X(3, (Q, Q, Q), QUAD), \
14785 X(3, (D, D, I), DOUBLE), \
14786 X(3, (Q, Q, I), QUAD), \
14787 X(3, (D, D, S), DOUBLE), \
14788 X(3, (Q, Q, S), QUAD), \
5ee91343 14789 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14790 X(3, (R, R, Q), QUAD), \
14791 X(2, (R, Q), QUAD), \
037e8744
JB
14792 X(2, (D, D), DOUBLE), \
14793 X(2, (Q, Q), QUAD), \
14794 X(2, (D, S), DOUBLE), \
14795 X(2, (Q, S), QUAD), \
14796 X(2, (D, R), DOUBLE), \
14797 X(2, (Q, R), QUAD), \
14798 X(2, (D, I), DOUBLE), \
14799 X(2, (Q, I), QUAD), \
14800 X(3, (D, L, D), DOUBLE), \
14801 X(2, (D, Q), MIXED), \
14802 X(2, (Q, D), MIXED), \
14803 X(3, (D, Q, I), MIXED), \
14804 X(3, (Q, D, I), MIXED), \
14805 X(3, (Q, D, D), MIXED), \
14806 X(3, (D, Q, Q), MIXED), \
14807 X(3, (Q, Q, D), MIXED), \
14808 X(3, (Q, D, S), MIXED), \
14809 X(3, (D, Q, S), MIXED), \
14810 X(4, (D, D, D, I), DOUBLE), \
14811 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14812 X(4, (D, D, S, I), DOUBLE), \
14813 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14814 X(2, (F, F), SINGLE), \
14815 X(3, (F, F, F), SINGLE), \
14816 X(2, (F, I), SINGLE), \
14817 X(2, (F, D), MIXED), \
14818 X(2, (D, F), MIXED), \
14819 X(3, (F, F, I), MIXED), \
14820 X(4, (R, R, F, F), SINGLE), \
14821 X(4, (F, F, R, R), SINGLE), \
14822 X(3, (D, R, R), DOUBLE), \
14823 X(3, (R, R, D), DOUBLE), \
14824 X(2, (S, R), SINGLE), \
14825 X(2, (R, S), SINGLE), \
14826 X(2, (F, R), SINGLE), \
d54af2d0 14827 X(2, (R, F), SINGLE), \
1f6234a3
AV
14828/* Used for MVE tail predicated loop instructions. */\
14829 X(2, (R, R), QUAD), \
d54af2d0
RL
14830/* Half float shape supported so far. */\
14831 X (2, (H, D), MIXED), \
14832 X (2, (D, H), MIXED), \
14833 X (2, (H, F), MIXED), \
14834 X (2, (F, H), MIXED), \
14835 X (2, (H, H), HALF), \
14836 X (2, (H, R), HALF), \
14837 X (2, (R, H), HALF), \
14838 X (2, (H, I), HALF), \
14839 X (3, (H, H, H), HALF), \
14840 X (3, (H, F, I), MIXED), \
dec41383
JW
14841 X (3, (F, H, I), MIXED), \
14842 X (3, (D, H, H), MIXED), \
14843 X (3, (D, H, S), MIXED)
037e8744
JB
14844
14845#define S2(A,B) NS_##A##B
14846#define S3(A,B,C) NS_##A##B##C
14847#define S4(A,B,C,D) NS_##A##B##C##D
14848
14849#define X(N, L, C) S##N L
14850
5287ad62
JB
14851enum neon_shape
14852{
037e8744
JB
14853 NEON_SHAPE_DEF,
14854 NS_NULL
5287ad62 14855};
b99bd4ef 14856
037e8744
JB
14857#undef X
14858#undef S2
14859#undef S3
14860#undef S4
14861
14862enum neon_shape_class
14863{
d54af2d0 14864 SC_HALF,
037e8744
JB
14865 SC_SINGLE,
14866 SC_DOUBLE,
14867 SC_QUAD,
14868 SC_MIXED
14869};
14870
14871#define X(N, L, C) SC_##C
14872
14873static enum neon_shape_class neon_shape_class[] =
14874{
14875 NEON_SHAPE_DEF
14876};
14877
14878#undef X
14879
14880enum neon_shape_el
14881{
d54af2d0 14882 SE_H,
037e8744
JB
14883 SE_F,
14884 SE_D,
14885 SE_Q,
14886 SE_I,
14887 SE_S,
14888 SE_R,
14889 SE_L
14890};
14891
14892/* Register widths of above. */
14893static unsigned neon_shape_el_size[] =
14894{
d54af2d0 14895 16,
037e8744
JB
14896 32,
14897 64,
14898 128,
14899 0,
14900 32,
14901 32,
14902 0
14903};
14904
14905struct neon_shape_info
14906{
14907 unsigned els;
14908 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14909};
14910
14911#define S2(A,B) { SE_##A, SE_##B }
14912#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14913#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14914
14915#define X(N, L, C) { N, S##N L }
14916
14917static struct neon_shape_info neon_shape_tab[] =
14918{
14919 NEON_SHAPE_DEF
14920};
14921
14922#undef X
14923#undef S2
14924#undef S3
14925#undef S4
14926
5287ad62
JB
14927/* Bit masks used in type checking given instructions.
14928 'N_EQK' means the type must be the same as (or based on in some way) the key
14929 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14930 set, various other bits can be set as well in order to modify the meaning of
14931 the type constraint. */
14932
14933enum neon_type_mask
14934{
8e79c3df
CM
14935 N_S8 = 0x0000001,
14936 N_S16 = 0x0000002,
14937 N_S32 = 0x0000004,
14938 N_S64 = 0x0000008,
14939 N_U8 = 0x0000010,
14940 N_U16 = 0x0000020,
14941 N_U32 = 0x0000040,
14942 N_U64 = 0x0000080,
14943 N_I8 = 0x0000100,
14944 N_I16 = 0x0000200,
14945 N_I32 = 0x0000400,
14946 N_I64 = 0x0000800,
14947 N_8 = 0x0001000,
14948 N_16 = 0x0002000,
14949 N_32 = 0x0004000,
14950 N_64 = 0x0008000,
14951 N_P8 = 0x0010000,
14952 N_P16 = 0x0020000,
14953 N_F16 = 0x0040000,
14954 N_F32 = 0x0080000,
14955 N_F64 = 0x0100000,
4f51b4bd 14956 N_P64 = 0x0200000,
aab2c27d 14957 N_BF16 = 0x0400000,
c921be7d
NC
14958 N_KEY = 0x1000000, /* Key element (main type specifier). */
14959 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14960 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14961 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14962 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14963 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14964 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14965 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14966 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14967 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14968 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 14969 N_UTYP = 0,
4f51b4bd 14970 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
14971};
14972
dcbf9037
JB
14973#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14974
5287ad62
JB
14975#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14976#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14977#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
14978#define N_S_32 (N_S8 | N_S16 | N_S32)
14979#define N_F_16_32 (N_F16 | N_F32)
14980#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 14981#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 14982#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 14983#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
14984#define N_I_MVE (N_I8 | N_I16 | N_I32)
14985#define N_F_MVE (N_F16 | N_F32)
14986#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
14987
14988/* Pass this as the first type argument to neon_check_type to ignore types
14989 altogether. */
14990#define N_IGNORE_TYPE (N_KEY | N_EQK)
14991
037e8744
JB
14992/* Select a "shape" for the current instruction (describing register types or
14993 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14994 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14995 function of operand parsing, so this function doesn't need to be called.
14996 Shapes should be listed in order of decreasing length. */
5287ad62
JB
14997
14998static enum neon_shape
037e8744 14999neon_select_shape (enum neon_shape shape, ...)
5287ad62 15000{
037e8744
JB
15001 va_list ap;
15002 enum neon_shape first_shape = shape;
5287ad62
JB
15003
15004 /* Fix missing optional operands. FIXME: we don't know at this point how
15005 many arguments we should have, so this makes the assumption that we have
15006 > 1. This is true of all current Neon opcodes, I think, but may not be
15007 true in the future. */
15008 if (!inst.operands[1].present)
15009 inst.operands[1] = inst.operands[0];
15010
037e8744 15011 va_start (ap, shape);
5f4273c7 15012
21d799b5 15013 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
15014 {
15015 unsigned j;
15016 int matches = 1;
15017
15018 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
15019 {
15020 if (!inst.operands[j].present)
15021 {
15022 matches = 0;
15023 break;
15024 }
15025
15026 switch (neon_shape_tab[shape].el[j])
15027 {
d54af2d0
RL
15028 /* If a .f16, .16, .u16, .s16 type specifier is given over
15029 a VFP single precision register operand, it's essentially
15030 means only half of the register is used.
15031
15032 If the type specifier is given after the mnemonics, the
15033 information is stored in inst.vectype. If the type specifier
15034 is given after register operand, the information is stored
15035 in inst.operands[].vectype.
15036
15037 When there is only one type specifier, and all the register
15038 operands are the same type of hardware register, the type
15039 specifier applies to all register operands.
15040
15041 If no type specifier is given, the shape is inferred from
15042 operand information.
15043
15044 for example:
15045 vadd.f16 s0, s1, s2: NS_HHH
15046 vabs.f16 s0, s1: NS_HH
15047 vmov.f16 s0, r1: NS_HR
15048 vmov.f16 r0, s1: NS_RH
15049 vcvt.f16 r0, s1: NS_RH
15050 vcvt.f16.s32 s2, s2, #29: NS_HFI
15051 vcvt.f16.s32 s2, s2: NS_HF
15052 */
15053 case SE_H:
15054 if (!(inst.operands[j].isreg
15055 && inst.operands[j].isvec
15056 && inst.operands[j].issingle
15057 && !inst.operands[j].isquad
15058 && ((inst.vectype.elems == 1
15059 && inst.vectype.el[0].size == 16)
15060 || (inst.vectype.elems > 1
15061 && inst.vectype.el[j].size == 16)
15062 || (inst.vectype.elems == 0
15063 && inst.operands[j].vectype.type != NT_invtype
15064 && inst.operands[j].vectype.size == 16))))
15065 matches = 0;
15066 break;
15067
477330fc
RM
15068 case SE_F:
15069 if (!(inst.operands[j].isreg
15070 && inst.operands[j].isvec
15071 && inst.operands[j].issingle
d54af2d0
RL
15072 && !inst.operands[j].isquad
15073 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15074 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15075 || (inst.vectype.elems == 0
15076 && (inst.operands[j].vectype.size == 32
15077 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
15078 matches = 0;
15079 break;
15080
15081 case SE_D:
15082 if (!(inst.operands[j].isreg
15083 && inst.operands[j].isvec
15084 && !inst.operands[j].isquad
15085 && !inst.operands[j].issingle))
15086 matches = 0;
15087 break;
15088
15089 case SE_R:
15090 if (!(inst.operands[j].isreg
15091 && !inst.operands[j].isvec))
15092 matches = 0;
15093 break;
15094
15095 case SE_Q:
15096 if (!(inst.operands[j].isreg
15097 && inst.operands[j].isvec
15098 && inst.operands[j].isquad
15099 && !inst.operands[j].issingle))
15100 matches = 0;
15101 break;
15102
15103 case SE_I:
15104 if (!(!inst.operands[j].isreg
15105 && !inst.operands[j].isscalar))
15106 matches = 0;
15107 break;
15108
15109 case SE_S:
15110 if (!(!inst.operands[j].isreg
15111 && inst.operands[j].isscalar))
15112 matches = 0;
15113 break;
15114
15115 case SE_L:
15116 break;
15117 }
3fde54a2
JZ
15118 if (!matches)
15119 break;
477330fc 15120 }
ad6cec43
MGD
15121 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15122 /* We've matched all the entries in the shape table, and we don't
15123 have any left over operands which have not been matched. */
477330fc 15124 break;
037e8744 15125 }
5f4273c7 15126
037e8744 15127 va_end (ap);
5287ad62 15128
037e8744
JB
15129 if (shape == NS_NULL && first_shape != NS_NULL)
15130 first_error (_("invalid instruction shape"));
5287ad62 15131
037e8744
JB
15132 return shape;
15133}
5287ad62 15134
037e8744
JB
15135/* True if SHAPE is predominantly a quadword operation (most of the time, this
15136 means the Q bit should be set). */
15137
15138static int
15139neon_quad (enum neon_shape shape)
15140{
15141 return neon_shape_class[shape] == SC_QUAD;
5287ad62 15142}
037e8744 15143
5287ad62
JB
15144static void
15145neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 15146 unsigned *g_size)
5287ad62
JB
15147{
15148 /* Allow modification to be made to types which are constrained to be
15149 based on the key element, based on bits set alongside N_EQK. */
15150 if ((typebits & N_EQK) != 0)
15151 {
15152 if ((typebits & N_HLF) != 0)
15153 *g_size /= 2;
15154 else if ((typebits & N_DBL) != 0)
15155 *g_size *= 2;
15156 if ((typebits & N_SGN) != 0)
15157 *g_type = NT_signed;
15158 else if ((typebits & N_UNS) != 0)
477330fc 15159 *g_type = NT_unsigned;
5287ad62 15160 else if ((typebits & N_INT) != 0)
477330fc 15161 *g_type = NT_integer;
5287ad62 15162 else if ((typebits & N_FLT) != 0)
477330fc 15163 *g_type = NT_float;
dcbf9037 15164 else if ((typebits & N_SIZ) != 0)
477330fc 15165 *g_type = NT_untyped;
5287ad62
JB
15166 }
15167}
5f4273c7 15168
5287ad62
JB
15169/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15170 operand type, i.e. the single type specified in a Neon instruction when it
15171 is the only one given. */
15172
15173static struct neon_type_el
15174neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15175{
15176 struct neon_type_el dest = *key;
5f4273c7 15177
9c2799c2 15178 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15179
5287ad62
JB
15180 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15181
15182 return dest;
15183}
15184
15185/* Convert Neon type and size into compact bitmask representation. */
15186
15187static enum neon_type_mask
15188type_chk_of_el_type (enum neon_el_type type, unsigned size)
15189{
15190 switch (type)
15191 {
15192 case NT_untyped:
15193 switch (size)
477330fc
RM
15194 {
15195 case 8: return N_8;
15196 case 16: return N_16;
15197 case 32: return N_32;
15198 case 64: return N_64;
15199 default: ;
15200 }
5287ad62
JB
15201 break;
15202
15203 case NT_integer:
15204 switch (size)
477330fc
RM
15205 {
15206 case 8: return N_I8;
15207 case 16: return N_I16;
15208 case 32: return N_I32;
15209 case 64: return N_I64;
15210 default: ;
15211 }
5287ad62
JB
15212 break;
15213
15214 case NT_float:
037e8744 15215 switch (size)
477330fc 15216 {
8e79c3df 15217 case 16: return N_F16;
477330fc
RM
15218 case 32: return N_F32;
15219 case 64: return N_F64;
15220 default: ;
15221 }
5287ad62
JB
15222 break;
15223
15224 case NT_poly:
15225 switch (size)
477330fc
RM
15226 {
15227 case 8: return N_P8;
15228 case 16: return N_P16;
4f51b4bd 15229 case 64: return N_P64;
477330fc
RM
15230 default: ;
15231 }
5287ad62
JB
15232 break;
15233
15234 case NT_signed:
15235 switch (size)
477330fc
RM
15236 {
15237 case 8: return N_S8;
15238 case 16: return N_S16;
15239 case 32: return N_S32;
15240 case 64: return N_S64;
15241 default: ;
15242 }
5287ad62
JB
15243 break;
15244
15245 case NT_unsigned:
15246 switch (size)
477330fc
RM
15247 {
15248 case 8: return N_U8;
15249 case 16: return N_U16;
15250 case 32: return N_U32;
15251 case 64: return N_U64;
15252 default: ;
15253 }
5287ad62
JB
15254 break;
15255
aab2c27d
MM
15256 case NT_bfloat:
15257 if (size == 16) return N_BF16;
15258 break;
15259
5287ad62
JB
15260 default: ;
15261 }
5f4273c7 15262
5287ad62
JB
15263 return N_UTYP;
15264}
15265
15266/* Convert compact Neon bitmask type representation to a type and size. Only
15267 handles the case where a single bit is set in the mask. */
15268
dcbf9037 15269static int
5287ad62 15270el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15271 enum neon_type_mask mask)
5287ad62 15272{
dcbf9037
JB
15273 if ((mask & N_EQK) != 0)
15274 return FAIL;
15275
5287ad62
JB
15276 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15277 *size = 8;
aab2c27d
MM
15278 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15279 != 0)
5287ad62 15280 *size = 16;
dcbf9037 15281 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15282 *size = 32;
4f51b4bd 15283 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15284 *size = 64;
dcbf9037
JB
15285 else
15286 return FAIL;
15287
5287ad62
JB
15288 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15289 *type = NT_signed;
dcbf9037 15290 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15291 *type = NT_unsigned;
dcbf9037 15292 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15293 *type = NT_integer;
dcbf9037 15294 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15295 *type = NT_untyped;
4f51b4bd 15296 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15297 *type = NT_poly;
d54af2d0 15298 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15299 *type = NT_float;
aab2c27d
MM
15300 else if ((mask & (N_BF16)) != 0)
15301 *type = NT_bfloat;
dcbf9037
JB
15302 else
15303 return FAIL;
5f4273c7 15304
dcbf9037 15305 return SUCCESS;
5287ad62
JB
15306}
15307
15308/* Modify a bitmask of allowed types. This is only needed for type
15309 relaxation. */
15310
15311static unsigned
15312modify_types_allowed (unsigned allowed, unsigned mods)
15313{
15314 unsigned size;
15315 enum neon_el_type type;
15316 unsigned destmask;
15317 int i;
5f4273c7 15318
5287ad62 15319 destmask = 0;
5f4273c7 15320
5287ad62
JB
15321 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15322 {
21d799b5 15323 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15324 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15325 {
15326 neon_modify_type_size (mods, &type, &size);
15327 destmask |= type_chk_of_el_type (type, size);
15328 }
5287ad62 15329 }
5f4273c7 15330
5287ad62
JB
15331 return destmask;
15332}
15333
15334/* Check type and return type classification.
15335 The manual states (paraphrase): If one datatype is given, it indicates the
15336 type given in:
15337 - the second operand, if there is one
15338 - the operand, if there is no second operand
15339 - the result, if there are no operands.
15340 This isn't quite good enough though, so we use a concept of a "key" datatype
15341 which is set on a per-instruction basis, which is the one which matters when
15342 only one data type is written.
15343 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15344 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15345
15346static struct neon_type_el
15347neon_check_type (unsigned els, enum neon_shape ns, ...)
15348{
15349 va_list ap;
15350 unsigned i, pass, key_el = 0;
15351 unsigned types[NEON_MAX_TYPE_ELS];
15352 enum neon_el_type k_type = NT_invtype;
15353 unsigned k_size = -1u;
15354 struct neon_type_el badtype = {NT_invtype, -1};
15355 unsigned key_allowed = 0;
15356
15357 /* Optional registers in Neon instructions are always (not) in operand 1.
15358 Fill in the missing operand here, if it was omitted. */
15359 if (els > 1 && !inst.operands[1].present)
15360 inst.operands[1] = inst.operands[0];
15361
15362 /* Suck up all the varargs. */
15363 va_start (ap, ns);
15364 for (i = 0; i < els; i++)
15365 {
15366 unsigned thisarg = va_arg (ap, unsigned);
15367 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15368 {
15369 va_end (ap);
15370 return badtype;
15371 }
5287ad62
JB
15372 types[i] = thisarg;
15373 if ((thisarg & N_KEY) != 0)
477330fc 15374 key_el = i;
5287ad62
JB
15375 }
15376 va_end (ap);
15377
dcbf9037
JB
15378 if (inst.vectype.elems > 0)
15379 for (i = 0; i < els; i++)
15380 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15381 {
15382 first_error (_("types specified in both the mnemonic and operands"));
15383 return badtype;
15384 }
dcbf9037 15385
5287ad62
JB
15386 /* Duplicate inst.vectype elements here as necessary.
15387 FIXME: No idea if this is exactly the same as the ARM assembler,
15388 particularly when an insn takes one register and one non-register
15389 operand. */
15390 if (inst.vectype.elems == 1 && els > 1)
15391 {
15392 unsigned j;
15393 inst.vectype.elems = els;
15394 inst.vectype.el[key_el] = inst.vectype.el[0];
15395 for (j = 0; j < els; j++)
477330fc
RM
15396 if (j != key_el)
15397 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15398 types[j]);
dcbf9037
JB
15399 }
15400 else if (inst.vectype.elems == 0 && els > 0)
15401 {
15402 unsigned j;
15403 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15404 after each operand. We allow some flexibility here; as long as the
15405 "key" operand has a type, we can infer the others. */
dcbf9037 15406 for (j = 0; j < els; j++)
477330fc
RM
15407 if (inst.operands[j].vectype.type != NT_invtype)
15408 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15409
15410 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15411 {
15412 for (j = 0; j < els; j++)
15413 if (inst.operands[j].vectype.type == NT_invtype)
15414 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15415 types[j]);
15416 }
dcbf9037 15417 else
477330fc
RM
15418 {
15419 first_error (_("operand types can't be inferred"));
15420 return badtype;
15421 }
5287ad62
JB
15422 }
15423 else if (inst.vectype.elems != els)
15424 {
dcbf9037 15425 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15426 return badtype;
15427 }
15428
15429 for (pass = 0; pass < 2; pass++)
15430 {
15431 for (i = 0; i < els; i++)
477330fc
RM
15432 {
15433 unsigned thisarg = types[i];
15434 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15435 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15436 enum neon_el_type g_type = inst.vectype.el[i].type;
15437 unsigned g_size = inst.vectype.el[i].size;
15438
15439 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15440 integer types if sign-specific variants are unavailable. */
477330fc 15441 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15442 && (types_allowed & N_SU_ALL) == 0)
15443 g_type = NT_integer;
15444
477330fc 15445 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15446 them. Some instructions only care about signs for some element
15447 sizes, so handle that properly. */
477330fc 15448 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15449 && ((g_size == 8 && (types_allowed & N_8) != 0)
15450 || (g_size == 16 && (types_allowed & N_16) != 0)
15451 || (g_size == 32 && (types_allowed & N_32) != 0)
15452 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15453 g_type = NT_untyped;
15454
477330fc
RM
15455 if (pass == 0)
15456 {
15457 if ((thisarg & N_KEY) != 0)
15458 {
15459 k_type = g_type;
15460 k_size = g_size;
15461 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15462
15463 /* Check architecture constraint on FP16 extension. */
15464 if (k_size == 16
15465 && k_type == NT_float
15466 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15467 {
15468 inst.error = _(BAD_FP16);
15469 return badtype;
15470 }
477330fc
RM
15471 }
15472 }
15473 else
15474 {
15475 if ((thisarg & N_VFP) != 0)
15476 {
15477 enum neon_shape_el regshape;
15478 unsigned regwidth, match;
99b253c5
NC
15479
15480 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15481 if (ns == NS_NULL)
15482 {
15483 first_error (_("invalid instruction shape"));
15484 return badtype;
15485 }
477330fc
RM
15486 regshape = neon_shape_tab[ns].el[i];
15487 regwidth = neon_shape_el_size[regshape];
15488
15489 /* In VFP mode, operands must match register widths. If we
15490 have a key operand, use its width, else use the width of
15491 the current operand. */
15492 if (k_size != -1u)
15493 match = k_size;
15494 else
15495 match = g_size;
15496
9db2f6b4
RL
15497 /* FP16 will use a single precision register. */
15498 if (regwidth == 32 && match == 16)
15499 {
15500 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15501 match = regwidth;
15502 else
15503 {
15504 inst.error = _(BAD_FP16);
15505 return badtype;
15506 }
15507 }
15508
477330fc
RM
15509 if (regwidth != match)
15510 {
15511 first_error (_("operand size must match register width"));
15512 return badtype;
15513 }
15514 }
15515
15516 if ((thisarg & N_EQK) == 0)
15517 {
15518 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15519
15520 if ((given_type & types_allowed) == 0)
15521 {
a302e574 15522 first_error (BAD_SIMD_TYPE);
477330fc
RM
15523 return badtype;
15524 }
15525 }
15526 else
15527 {
15528 enum neon_el_type mod_k_type = k_type;
15529 unsigned mod_k_size = k_size;
15530 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15531 if (g_type != mod_k_type || g_size != mod_k_size)
15532 {
15533 first_error (_("inconsistent types in Neon instruction"));
15534 return badtype;
15535 }
15536 }
15537 }
15538 }
5287ad62
JB
15539 }
15540
15541 return inst.vectype.el[key_el];
15542}
15543
037e8744 15544/* Neon-style VFP instruction forwarding. */
5287ad62 15545
037e8744
JB
15546/* Thumb VFP instructions have 0xE in the condition field. */
15547
15548static void
15549do_vfp_cond_or_thumb (void)
5287ad62 15550{
88714cb8
DG
15551 inst.is_neon = 1;
15552
5287ad62 15553 if (thumb_mode)
037e8744 15554 inst.instruction |= 0xe0000000;
5287ad62 15555 else
037e8744 15556 inst.instruction |= inst.cond << 28;
5287ad62
JB
15557}
15558
037e8744
JB
15559/* Look up and encode a simple mnemonic, for use as a helper function for the
15560 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15561 etc. It is assumed that operand parsing has already been done, and that the
15562 operands are in the form expected by the given opcode (this isn't necessarily
15563 the same as the form in which they were parsed, hence some massaging must
15564 take place before this function is called).
15565 Checks current arch version against that in the looked-up opcode. */
5287ad62 15566
037e8744
JB
15567static void
15568do_vfp_nsyn_opcode (const char *opname)
5287ad62 15569{
037e8744 15570 const struct asm_opcode *opcode;
5f4273c7 15571
21d799b5 15572 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 15573
037e8744
JB
15574 if (!opcode)
15575 abort ();
5287ad62 15576
037e8744 15577 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15578 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15579 _(BAD_FPU));
5287ad62 15580
88714cb8
DG
15581 inst.is_neon = 1;
15582
037e8744
JB
15583 if (thumb_mode)
15584 {
15585 inst.instruction = opcode->tvalue;
15586 opcode->tencode ();
15587 }
15588 else
15589 {
15590 inst.instruction = (inst.cond << 28) | opcode->avalue;
15591 opcode->aencode ();
15592 }
15593}
5287ad62
JB
15594
15595static void
037e8744 15596do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15597{
037e8744
JB
15598 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15599
9db2f6b4 15600 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15601 {
15602 if (is_add)
477330fc 15603 do_vfp_nsyn_opcode ("fadds");
037e8744 15604 else
477330fc 15605 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15606
15607 /* ARMv8.2 fp16 instruction. */
15608 if (rs == NS_HHH)
15609 do_scalar_fp16_v82_encode ();
037e8744
JB
15610 }
15611 else
15612 {
15613 if (is_add)
477330fc 15614 do_vfp_nsyn_opcode ("faddd");
037e8744 15615 else
477330fc 15616 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15617 }
15618}
15619
15620/* Check operand types to see if this is a VFP instruction, and if so call
15621 PFN (). */
15622
15623static int
15624try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15625{
15626 enum neon_shape rs;
15627 struct neon_type_el et;
15628
15629 switch (args)
15630 {
15631 case 2:
9db2f6b4
RL
15632 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15633 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15634 break;
5f4273c7 15635
037e8744 15636 case 3:
9db2f6b4
RL
15637 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15638 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15639 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15640 break;
15641
15642 default:
15643 abort ();
15644 }
15645
15646 if (et.type != NT_invtype)
15647 {
15648 pfn (rs);
15649 return SUCCESS;
15650 }
037e8744 15651
99b253c5 15652 inst.error = NULL;
037e8744
JB
15653 return FAIL;
15654}
15655
15656static void
15657do_vfp_nsyn_mla_mls (enum neon_shape rs)
15658{
15659 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15660
9db2f6b4 15661 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15662 {
15663 if (is_mla)
477330fc 15664 do_vfp_nsyn_opcode ("fmacs");
037e8744 15665 else
477330fc 15666 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15667
15668 /* ARMv8.2 fp16 instruction. */
15669 if (rs == NS_HHH)
15670 do_scalar_fp16_v82_encode ();
037e8744
JB
15671 }
15672 else
15673 {
15674 if (is_mla)
477330fc 15675 do_vfp_nsyn_opcode ("fmacd");
037e8744 15676 else
477330fc 15677 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15678 }
15679}
15680
62f3b8c8
PB
15681static void
15682do_vfp_nsyn_fma_fms (enum neon_shape rs)
15683{
15684 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15685
9db2f6b4 15686 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15687 {
15688 if (is_fma)
477330fc 15689 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15690 else
477330fc 15691 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15692
15693 /* ARMv8.2 fp16 instruction. */
15694 if (rs == NS_HHH)
15695 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15696 }
15697 else
15698 {
15699 if (is_fma)
477330fc 15700 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15701 else
477330fc 15702 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15703 }
15704}
15705
037e8744
JB
15706static void
15707do_vfp_nsyn_mul (enum neon_shape rs)
15708{
9db2f6b4
RL
15709 if (rs == NS_FFF || rs == NS_HHH)
15710 {
15711 do_vfp_nsyn_opcode ("fmuls");
15712
15713 /* ARMv8.2 fp16 instruction. */
15714 if (rs == NS_HHH)
15715 do_scalar_fp16_v82_encode ();
15716 }
037e8744
JB
15717 else
15718 do_vfp_nsyn_opcode ("fmuld");
15719}
15720
15721static void
15722do_vfp_nsyn_abs_neg (enum neon_shape rs)
15723{
15724 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15725 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15726
9db2f6b4 15727 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15728 {
15729 if (is_neg)
477330fc 15730 do_vfp_nsyn_opcode ("fnegs");
037e8744 15731 else
477330fc 15732 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15733
15734 /* ARMv8.2 fp16 instruction. */
15735 if (rs == NS_HH)
15736 do_scalar_fp16_v82_encode ();
037e8744
JB
15737 }
15738 else
15739 {
15740 if (is_neg)
477330fc 15741 do_vfp_nsyn_opcode ("fnegd");
037e8744 15742 else
477330fc 15743 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15744 }
15745}
15746
15747/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15748 insns belong to Neon, and are handled elsewhere. */
15749
15750static void
15751do_vfp_nsyn_ldm_stm (int is_dbmode)
15752{
15753 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15754 if (is_ldm)
15755 {
15756 if (is_dbmode)
477330fc 15757 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15758 else
477330fc 15759 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15760 }
15761 else
15762 {
15763 if (is_dbmode)
477330fc 15764 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15765 else
477330fc 15766 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15767 }
15768}
15769
037e8744
JB
15770static void
15771do_vfp_nsyn_sqrt (void)
15772{
9db2f6b4
RL
15773 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15774 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15775
9db2f6b4
RL
15776 if (rs == NS_FF || rs == NS_HH)
15777 {
15778 do_vfp_nsyn_opcode ("fsqrts");
15779
15780 /* ARMv8.2 fp16 instruction. */
15781 if (rs == NS_HH)
15782 do_scalar_fp16_v82_encode ();
15783 }
037e8744
JB
15784 else
15785 do_vfp_nsyn_opcode ("fsqrtd");
15786}
15787
15788static void
15789do_vfp_nsyn_div (void)
15790{
9db2f6b4 15791 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15792 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15793 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15794
9db2f6b4
RL
15795 if (rs == NS_FFF || rs == NS_HHH)
15796 {
15797 do_vfp_nsyn_opcode ("fdivs");
15798
15799 /* ARMv8.2 fp16 instruction. */
15800 if (rs == NS_HHH)
15801 do_scalar_fp16_v82_encode ();
15802 }
037e8744
JB
15803 else
15804 do_vfp_nsyn_opcode ("fdivd");
15805}
15806
15807static void
15808do_vfp_nsyn_nmul (void)
15809{
9db2f6b4 15810 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15811 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15812 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15813
9db2f6b4 15814 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15815 {
88714cb8 15816 NEON_ENCODE (SINGLE, inst);
037e8744 15817 do_vfp_sp_dyadic ();
9db2f6b4
RL
15818
15819 /* ARMv8.2 fp16 instruction. */
15820 if (rs == NS_HHH)
15821 do_scalar_fp16_v82_encode ();
037e8744
JB
15822 }
15823 else
15824 {
88714cb8 15825 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15826 do_vfp_dp_rd_rn_rm ();
15827 }
15828 do_vfp_cond_or_thumb ();
9db2f6b4 15829
037e8744
JB
15830}
15831
1b883319
AV
15832/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15833 (0, 1, 2, 3). */
15834
15835static unsigned
15836neon_logbits (unsigned x)
15837{
15838 return ffs (x) - 4;
15839}
15840
15841#define LOW4(R) ((R) & 0xf)
15842#define HI1(R) (((R) >> 4) & 1)
15843
15844static unsigned
15845mve_get_vcmp_vpt_cond (struct neon_type_el et)
15846{
15847 switch (et.type)
15848 {
15849 default:
15850 first_error (BAD_EL_TYPE);
15851 return 0;
15852 case NT_float:
15853 switch (inst.operands[0].imm)
15854 {
15855 default:
15856 first_error (_("invalid condition"));
15857 return 0;
15858 case 0x0:
15859 /* eq. */
15860 return 0;
15861 case 0x1:
15862 /* ne. */
15863 return 1;
15864 case 0xa:
15865 /* ge/ */
15866 return 4;
15867 case 0xb:
15868 /* lt. */
15869 return 5;
15870 case 0xc:
15871 /* gt. */
15872 return 6;
15873 case 0xd:
15874 /* le. */
15875 return 7;
15876 }
15877 case NT_integer:
15878 /* only accept eq and ne. */
15879 if (inst.operands[0].imm > 1)
15880 {
15881 first_error (_("invalid condition"));
15882 return 0;
15883 }
15884 return inst.operands[0].imm;
15885 case NT_unsigned:
15886 if (inst.operands[0].imm == 0x2)
15887 return 2;
15888 else if (inst.operands[0].imm == 0x8)
15889 return 3;
15890 else
15891 {
15892 first_error (_("invalid condition"));
15893 return 0;
15894 }
15895 case NT_signed:
15896 switch (inst.operands[0].imm)
15897 {
15898 default:
15899 first_error (_("invalid condition"));
15900 return 0;
15901 case 0xa:
15902 /* ge. */
15903 return 4;
15904 case 0xb:
15905 /* lt. */
15906 return 5;
15907 case 0xc:
15908 /* gt. */
15909 return 6;
15910 case 0xd:
15911 /* le. */
15912 return 7;
15913 }
15914 }
15915 /* Should be unreachable. */
15916 abort ();
15917}
15918
efd0b310
SP
15919/* For VCTP (create vector tail predicate) in MVE. */
15920static void
15921do_mve_vctp (void)
15922{
15923 int dt = 0;
15924 unsigned size = 0x0;
15925
15926 if (inst.cond > COND_ALWAYS)
15927 inst.pred_insn_type = INSIDE_VPT_INSN;
15928 else
15929 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15930
15931 /* This is a typical MVE instruction which has no type but have size 8, 16,
15932 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15933 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15934 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15935 dt = inst.vectype.el[0].size;
15936
15937 /* Setting this does not indicate an actual NEON instruction, but only
15938 indicates that the mnemonic accepts neon-style type suffixes. */
15939 inst.is_neon = 1;
15940
15941 switch (dt)
15942 {
15943 case 8:
15944 break;
15945 case 16:
15946 size = 0x1; break;
15947 case 32:
15948 size = 0x2; break;
15949 case 64:
15950 size = 0x3; break;
15951 default:
15952 first_error (_("Type is not allowed for this instruction"));
15953 }
15954 inst.instruction |= size << 20;
15955 inst.instruction |= inst.operands[0].reg << 16;
15956}
15957
1b883319
AV
15958static void
15959do_mve_vpt (void)
15960{
15961 /* We are dealing with a vector predicated block. */
15962 if (inst.operands[0].present)
15963 {
15964 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15965 struct neon_type_el et
15966 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15967 N_EQK);
15968
15969 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15970
15971 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15972
15973 if (et.type == NT_invtype)
15974 return;
15975
15976 if (et.type == NT_float)
15977 {
15978 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15979 BAD_FPU);
15980 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
15981 inst.instruction |= (et.size == 16) << 28;
15982 inst.instruction |= 0x3 << 20;
15983 }
15984 else
15985 {
15986 constraint (et.size != 8 && et.size != 16 && et.size != 32,
15987 BAD_EL_TYPE);
15988 inst.instruction |= 1 << 28;
15989 inst.instruction |= neon_logbits (et.size) << 20;
15990 }
15991
15992 if (inst.operands[2].isquad)
15993 {
15994 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15995 inst.instruction |= LOW4 (inst.operands[2].reg);
15996 inst.instruction |= (fcond & 0x2) >> 1;
15997 }
15998 else
15999 {
16000 if (inst.operands[2].reg == REG_SP)
16001 as_tsktsk (MVE_BAD_SP);
16002 inst.instruction |= 1 << 6;
16003 inst.instruction |= (fcond & 0x2) << 4;
16004 inst.instruction |= inst.operands[2].reg;
16005 }
16006 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16007 inst.instruction |= (fcond & 0x4) << 10;
16008 inst.instruction |= (fcond & 0x1) << 7;
16009
16010 }
16011 set_pred_insn_type (VPT_INSN);
16012 now_pred.cc = 0;
16013 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16014 | ((inst.instruction & 0xe000) >> 13);
16015 now_pred.warn_deprecated = FALSE;
16016 now_pred.type = VECTOR_PRED;
16017 inst.is_neon = 1;
16018}
16019
16020static void
16021do_mve_vcmp (void)
16022{
16023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16024 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16025 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16026 if (!inst.operands[2].present)
16027 first_error (_("MVE vector or ARM register expected"));
16028 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16029
16030 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16031 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16032 && inst.operands[1].isquad)
16033 {
16034 inst.instruction = N_MNEM_vcmp;
16035 inst.cond = 0x10;
16036 }
16037
16038 if (inst.cond > COND_ALWAYS)
16039 inst.pred_insn_type = INSIDE_VPT_INSN;
16040 else
16041 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16042
16043 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16044 struct neon_type_el et
16045 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16046 N_EQK);
16047
16048 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16049 && !inst.operands[2].iszr, BAD_PC);
16050
16051 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16052
16053 inst.instruction = 0xee010f00;
16054 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16055 inst.instruction |= (fcond & 0x4) << 10;
16056 inst.instruction |= (fcond & 0x1) << 7;
16057 if (et.type == NT_float)
16058 {
16059 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16060 BAD_FPU);
16061 inst.instruction |= (et.size == 16) << 28;
16062 inst.instruction |= 0x3 << 20;
16063 }
16064 else
16065 {
16066 inst.instruction |= 1 << 28;
16067 inst.instruction |= neon_logbits (et.size) << 20;
16068 }
16069 if (inst.operands[2].isquad)
16070 {
16071 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16072 inst.instruction |= (fcond & 0x2) >> 1;
16073 inst.instruction |= LOW4 (inst.operands[2].reg);
16074 }
16075 else
16076 {
16077 if (inst.operands[2].reg == REG_SP)
16078 as_tsktsk (MVE_BAD_SP);
16079 inst.instruction |= 1 << 6;
16080 inst.instruction |= (fcond & 0x2) << 4;
16081 inst.instruction |= inst.operands[2].reg;
16082 }
16083
16084 inst.is_neon = 1;
16085 return;
16086}
16087
935295b5
AV
16088static void
16089do_mve_vmaxa_vmina (void)
16090{
16091 if (inst.cond > COND_ALWAYS)
16092 inst.pred_insn_type = INSIDE_VPT_INSN;
16093 else
16094 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16095
16096 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16097 struct neon_type_el et
16098 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16099
16100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16101 inst.instruction |= neon_logbits (et.size) << 18;
16102 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16103 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16104 inst.instruction |= LOW4 (inst.operands[1].reg);
16105 inst.is_neon = 1;
16106}
16107
f30ee27c
AV
16108static void
16109do_mve_vfmas (void)
16110{
16111 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16112 struct neon_type_el et
16113 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16114
16115 if (inst.cond > COND_ALWAYS)
16116 inst.pred_insn_type = INSIDE_VPT_INSN;
16117 else
16118 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16119
16120 if (inst.operands[2].reg == REG_SP)
16121 as_tsktsk (MVE_BAD_SP);
16122 else if (inst.operands[2].reg == REG_PC)
16123 as_tsktsk (MVE_BAD_PC);
16124
16125 inst.instruction |= (et.size == 16) << 28;
16126 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16127 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16128 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16129 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16130 inst.instruction |= inst.operands[2].reg;
16131 inst.is_neon = 1;
16132}
16133
b409bdb6
AV
16134static void
16135do_mve_viddup (void)
16136{
16137 if (inst.cond > COND_ALWAYS)
16138 inst.pred_insn_type = INSIDE_VPT_INSN;
16139 else
16140 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16141
16142 unsigned imm = inst.relocs[0].exp.X_add_number;
16143 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16144 _("immediate must be either 1, 2, 4 or 8"));
16145
16146 enum neon_shape rs;
16147 struct neon_type_el et;
16148 unsigned Rm;
16149 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16150 {
16151 rs = neon_select_shape (NS_QRI, NS_NULL);
16152 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16153 Rm = 7;
16154 }
16155 else
16156 {
16157 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16158 if (inst.operands[2].reg == REG_SP)
16159 as_tsktsk (MVE_BAD_SP);
16160 else if (inst.operands[2].reg == REG_PC)
16161 first_error (BAD_PC);
16162
16163 rs = neon_select_shape (NS_QRRI, NS_NULL);
16164 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16165 Rm = inst.operands[2].reg >> 1;
16166 }
16167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16168 inst.instruction |= neon_logbits (et.size) << 20;
16169 inst.instruction |= inst.operands[1].reg << 16;
16170 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16171 inst.instruction |= (imm > 2) << 7;
16172 inst.instruction |= Rm << 1;
16173 inst.instruction |= (imm == 2 || imm == 8);
16174 inst.is_neon = 1;
16175}
16176
2d78f95b
AV
16177static void
16178do_mve_vmlas (void)
16179{
16180 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16181 struct neon_type_el et
16182 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16183
16184 if (inst.operands[2].reg == REG_PC)
16185 as_tsktsk (MVE_BAD_PC);
16186 else if (inst.operands[2].reg == REG_SP)
16187 as_tsktsk (MVE_BAD_SP);
16188
16189 if (inst.cond > COND_ALWAYS)
16190 inst.pred_insn_type = INSIDE_VPT_INSN;
16191 else
16192 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16193
16194 inst.instruction |= (et.type == NT_unsigned) << 28;
16195 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16196 inst.instruction |= neon_logbits (et.size) << 20;
16197 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16198 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16199 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16200 inst.instruction |= inst.operands[2].reg;
16201 inst.is_neon = 1;
16202}
16203
acca5630
AV
16204static void
16205do_mve_vshll (void)
16206{
16207 struct neon_type_el et
16208 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16209
16210 if (inst.cond > COND_ALWAYS)
16211 inst.pred_insn_type = INSIDE_VPT_INSN;
16212 else
16213 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16214
16215 int imm = inst.operands[2].imm;
16216 constraint (imm < 1 || (unsigned)imm > et.size,
16217 _("immediate value out of range"));
16218
16219 if ((unsigned)imm == et.size)
16220 {
16221 inst.instruction |= neon_logbits (et.size) << 18;
16222 inst.instruction |= 0x110001;
16223 }
16224 else
16225 {
16226 inst.instruction |= (et.size + imm) << 16;
16227 inst.instruction |= 0x800140;
16228 }
16229
16230 inst.instruction |= (et.type == NT_unsigned) << 28;
16231 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16232 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16233 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16234 inst.instruction |= LOW4 (inst.operands[1].reg);
16235 inst.is_neon = 1;
16236}
16237
16238static void
16239do_mve_vshlc (void)
16240{
16241 if (inst.cond > COND_ALWAYS)
16242 inst.pred_insn_type = INSIDE_VPT_INSN;
16243 else
16244 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16245
16246 if (inst.operands[1].reg == REG_PC)
16247 as_tsktsk (MVE_BAD_PC);
16248 else if (inst.operands[1].reg == REG_SP)
16249 as_tsktsk (MVE_BAD_SP);
16250
16251 int imm = inst.operands[2].imm;
16252 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16253
16254 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16255 inst.instruction |= (imm & 0x1f) << 16;
16256 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16257 inst.instruction |= inst.operands[1].reg;
16258 inst.is_neon = 1;
16259}
16260
4aa88b50
AV
16261static void
16262do_mve_vshrn (void)
16263{
16264 unsigned types;
16265 switch (inst.instruction)
16266 {
16267 case M_MNEM_vshrnt:
16268 case M_MNEM_vshrnb:
16269 case M_MNEM_vrshrnt:
16270 case M_MNEM_vrshrnb:
16271 types = N_I16 | N_I32;
16272 break;
16273 case M_MNEM_vqshrnt:
16274 case M_MNEM_vqshrnb:
16275 case M_MNEM_vqrshrnt:
16276 case M_MNEM_vqrshrnb:
16277 types = N_U16 | N_U32 | N_S16 | N_S32;
16278 break;
16279 case M_MNEM_vqshrunt:
16280 case M_MNEM_vqshrunb:
16281 case M_MNEM_vqrshrunt:
16282 case M_MNEM_vqrshrunb:
16283 types = N_S16 | N_S32;
16284 break;
16285 default:
16286 abort ();
16287 }
16288
16289 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16290
16291 if (inst.cond > COND_ALWAYS)
16292 inst.pred_insn_type = INSIDE_VPT_INSN;
16293 else
16294 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16295
16296 unsigned Qd = inst.operands[0].reg;
16297 unsigned Qm = inst.operands[1].reg;
16298 unsigned imm = inst.operands[2].imm;
16299 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16300 et.size == 16
16301 ? _("immediate operand expected in the range [1,8]")
16302 : _("immediate operand expected in the range [1,16]"));
16303
16304 inst.instruction |= (et.type == NT_unsigned) << 28;
16305 inst.instruction |= HI1 (Qd) << 22;
16306 inst.instruction |= (et.size - imm) << 16;
16307 inst.instruction |= LOW4 (Qd) << 12;
16308 inst.instruction |= HI1 (Qm) << 5;
16309 inst.instruction |= LOW4 (Qm);
16310 inst.is_neon = 1;
16311}
16312
1be7aba3
AV
16313static void
16314do_mve_vqmovn (void)
16315{
16316 struct neon_type_el et;
16317 if (inst.instruction == M_MNEM_vqmovnt
16318 || inst.instruction == M_MNEM_vqmovnb)
16319 et = neon_check_type (2, NS_QQ, N_EQK,
16320 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16321 else
16322 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16323
16324 if (inst.cond > COND_ALWAYS)
16325 inst.pred_insn_type = INSIDE_VPT_INSN;
16326 else
16327 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16328
16329 inst.instruction |= (et.type == NT_unsigned) << 28;
16330 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16331 inst.instruction |= (et.size == 32) << 18;
16332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16333 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16334 inst.instruction |= LOW4 (inst.operands[1].reg);
16335 inst.is_neon = 1;
16336}
16337
3063888e
AV
16338static void
16339do_mve_vpsel (void)
16340{
16341 neon_select_shape (NS_QQQ, NS_NULL);
16342
16343 if (inst.cond > COND_ALWAYS)
16344 inst.pred_insn_type = INSIDE_VPT_INSN;
16345 else
16346 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16347
16348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16349 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16350 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16351 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16352 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16353 inst.instruction |= LOW4 (inst.operands[2].reg);
16354 inst.is_neon = 1;
16355}
16356
16357static void
16358do_mve_vpnot (void)
16359{
16360 if (inst.cond > COND_ALWAYS)
16361 inst.pred_insn_type = INSIDE_VPT_INSN;
16362 else
16363 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16364}
16365
935295b5
AV
16366static void
16367do_mve_vmaxnma_vminnma (void)
16368{
16369 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16370 struct neon_type_el et
16371 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16372
16373 if (inst.cond > COND_ALWAYS)
16374 inst.pred_insn_type = INSIDE_VPT_INSN;
16375 else
16376 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16377
16378 inst.instruction |= (et.size == 16) << 28;
16379 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16380 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16381 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16382 inst.instruction |= LOW4 (inst.operands[1].reg);
16383 inst.is_neon = 1;
16384}
16385
5d281bf0
AV
16386static void
16387do_mve_vcmul (void)
16388{
16389 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16390 struct neon_type_el et
16391 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16392
16393 if (inst.cond > COND_ALWAYS)
16394 inst.pred_insn_type = INSIDE_VPT_INSN;
16395 else
16396 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16397
16398 unsigned rot = inst.relocs[0].exp.X_add_number;
16399 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16400 _("immediate out of range"));
16401
16402 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16403 || inst.operands[0].reg == inst.operands[2].reg))
16404 as_tsktsk (BAD_MVE_SRCDEST);
16405
16406 inst.instruction |= (et.size == 32) << 28;
16407 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16408 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16409 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16410 inst.instruction |= (rot > 90) << 12;
16411 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16412 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16413 inst.instruction |= LOW4 (inst.operands[2].reg);
16414 inst.instruction |= (rot == 90 || rot == 270);
16415 inst.is_neon = 1;
16416}
16417
1f6234a3
AV
16418/* To handle the Low Overhead Loop instructions
16419 in Armv8.1-M Mainline and MVE. */
16420static void
16421do_t_loloop (void)
16422{
16423 unsigned long insn = inst.instruction;
16424
16425 inst.instruction = THUMB_OP32 (inst.instruction);
16426
16427 if (insn == T_MNEM_lctp)
16428 return;
16429
16430 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16431
16432 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16433 {
16434 struct neon_type_el et
16435 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16436 inst.instruction |= neon_logbits (et.size) << 20;
16437 inst.is_neon = 1;
16438 }
16439
16440 switch (insn)
16441 {
16442 case T_MNEM_letp:
16443 constraint (!inst.operands[0].present,
16444 _("expected LR"));
16445 /* fall through. */
16446 case T_MNEM_le:
16447 /* le <label>. */
16448 if (!inst.operands[0].present)
16449 inst.instruction |= 1 << 21;
16450
16451 v8_1_loop_reloc (TRUE);
16452 break;
16453
16454 case T_MNEM_wls:
16455 case T_MNEM_wlstp:
16456 v8_1_loop_reloc (FALSE);
16457 /* fall through. */
16458 case T_MNEM_dlstp:
16459 case T_MNEM_dls:
16460 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16461
16462 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16463 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16464 else if (inst.operands[1].reg == REG_PC)
16465 as_tsktsk (MVE_BAD_PC);
16466 if (inst.operands[1].reg == REG_SP)
16467 as_tsktsk (MVE_BAD_SP);
16468
16469 inst.instruction |= (inst.operands[1].reg << 16);
16470 break;
16471
16472 default:
16473 abort ();
16474 }
16475}
16476
16477
037e8744
JB
16478static void
16479do_vfp_nsyn_cmp (void)
16480{
9db2f6b4 16481 enum neon_shape rs;
1b883319
AV
16482 if (!inst.operands[0].isreg)
16483 {
16484 do_mve_vcmp ();
16485 return;
16486 }
16487 else
16488 {
16489 constraint (inst.operands[2].present, BAD_SYNTAX);
16490 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16491 BAD_FPU);
16492 }
16493
037e8744
JB
16494 if (inst.operands[1].isreg)
16495 {
9db2f6b4
RL
16496 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16497 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16498
9db2f6b4 16499 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16500 {
16501 NEON_ENCODE (SINGLE, inst);
16502 do_vfp_sp_monadic ();
16503 }
037e8744 16504 else
477330fc
RM
16505 {
16506 NEON_ENCODE (DOUBLE, inst);
16507 do_vfp_dp_rd_rm ();
16508 }
037e8744
JB
16509 }
16510 else
16511 {
9db2f6b4
RL
16512 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16513 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16514
16515 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16516 {
16517 case N_MNEM_vcmp:
16518 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16519 break;
16520 case N_MNEM_vcmpe:
16521 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16522 break;
16523 default:
16524 abort ();
16525 }
5f4273c7 16526
9db2f6b4 16527 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16528 {
16529 NEON_ENCODE (SINGLE, inst);
16530 do_vfp_sp_compare_z ();
16531 }
037e8744 16532 else
477330fc
RM
16533 {
16534 NEON_ENCODE (DOUBLE, inst);
16535 do_vfp_dp_rd ();
16536 }
037e8744
JB
16537 }
16538 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16539
16540 /* ARMv8.2 fp16 instruction. */
16541 if (rs == NS_HI || rs == NS_HH)
16542 do_scalar_fp16_v82_encode ();
037e8744
JB
16543}
16544
16545static void
16546nsyn_insert_sp (void)
16547{
16548 inst.operands[1] = inst.operands[0];
16549 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16550 inst.operands[0].reg = REG_SP;
037e8744
JB
16551 inst.operands[0].isreg = 1;
16552 inst.operands[0].writeback = 1;
16553 inst.operands[0].present = 1;
16554}
16555
037e8744
JB
16556/* Fix up Neon data-processing instructions, ORing in the correct bits for
16557 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16558
88714cb8
DG
16559static void
16560neon_dp_fixup (struct arm_it* insn)
037e8744 16561{
88714cb8
DG
16562 unsigned int i = insn->instruction;
16563 insn->is_neon = 1;
16564
037e8744
JB
16565 if (thumb_mode)
16566 {
16567 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16568 if (i & (1 << 24))
477330fc 16569 i |= 1 << 28;
5f4273c7 16570
037e8744 16571 i &= ~(1 << 24);
5f4273c7 16572
037e8744
JB
16573 i |= 0xef000000;
16574 }
16575 else
16576 i |= 0xf2000000;
5f4273c7 16577
88714cb8 16578 insn->instruction = i;
037e8744
JB
16579}
16580
5ee91343 16581static void
7df54120 16582mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16583{
16584 if (inst.operands[2].reg == REG_SP)
16585 as_tsktsk (MVE_BAD_SP);
16586 else if (inst.operands[2].reg == REG_PC)
16587 as_tsktsk (MVE_BAD_PC);
16588
16589 if (fp)
16590 {
16591 /* vadd. */
16592 if (((unsigned)inst.instruction) == 0xd00)
16593 inst.instruction = 0xee300f40;
16594 /* vsub. */
16595 else if (((unsigned)inst.instruction) == 0x200d00)
16596 inst.instruction = 0xee301f40;
a8465a06
AV
16597 /* vmul. */
16598 else if (((unsigned)inst.instruction) == 0x1000d10)
16599 inst.instruction = 0xee310e60;
5ee91343
AV
16600
16601 /* Setting size which is 1 for F16 and 0 for F32. */
16602 inst.instruction |= (size == 16) << 28;
16603 }
16604 else
16605 {
16606 /* vadd. */
16607 if (((unsigned)inst.instruction) == 0x800)
16608 inst.instruction = 0xee010f40;
16609 /* vsub. */
16610 else if (((unsigned)inst.instruction) == 0x1000800)
16611 inst.instruction = 0xee011f40;
7df54120
AV
16612 /* vhadd. */
16613 else if (((unsigned)inst.instruction) == 0)
16614 inst.instruction = 0xee000f40;
16615 /* vhsub. */
16616 else if (((unsigned)inst.instruction) == 0x200)
16617 inst.instruction = 0xee001f40;
a8465a06
AV
16618 /* vmla. */
16619 else if (((unsigned)inst.instruction) == 0x900)
16620 inst.instruction = 0xee010e40;
16621 /* vmul. */
16622 else if (((unsigned)inst.instruction) == 0x910)
16623 inst.instruction = 0xee011e60;
16624 /* vqadd. */
16625 else if (((unsigned)inst.instruction) == 0x10)
16626 inst.instruction = 0xee000f60;
16627 /* vqsub. */
16628 else if (((unsigned)inst.instruction) == 0x210)
16629 inst.instruction = 0xee001f60;
42b16635
AV
16630 /* vqrdmlah. */
16631 else if (((unsigned)inst.instruction) == 0x3000b10)
16632 inst.instruction = 0xee000e40;
16633 /* vqdmulh. */
16634 else if (((unsigned)inst.instruction) == 0x0000b00)
16635 inst.instruction = 0xee010e60;
16636 /* vqrdmulh. */
16637 else if (((unsigned)inst.instruction) == 0x1000b00)
16638 inst.instruction = 0xfe010e60;
7df54120
AV
16639
16640 /* Set U-bit. */
16641 inst.instruction |= U << 28;
16642
5ee91343
AV
16643 /* Setting bits for size. */
16644 inst.instruction |= neon_logbits (size) << 20;
16645 }
16646 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16647 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16648 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16649 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16650 inst.instruction |= inst.operands[2].reg;
16651 inst.is_neon = 1;
16652}
16653
a302e574
AV
16654static void
16655mve_encode_rqq (unsigned bit28, unsigned size)
16656{
16657 inst.instruction |= bit28 << 28;
16658 inst.instruction |= neon_logbits (size) << 20;
16659 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16660 inst.instruction |= inst.operands[0].reg << 12;
16661 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16662 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16663 inst.instruction |= LOW4 (inst.operands[2].reg);
16664 inst.is_neon = 1;
16665}
16666
886e1c73
AV
16667static void
16668mve_encode_qqq (int ubit, int size)
16669{
16670
16671 inst.instruction |= (ubit != 0) << 28;
16672 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16673 inst.instruction |= neon_logbits (size) << 20;
16674 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16675 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16676 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16677 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16678 inst.instruction |= LOW4 (inst.operands[2].reg);
16679
16680 inst.is_neon = 1;
16681}
16682
26c1e780
AV
16683static void
16684mve_encode_rq (unsigned bit28, unsigned size)
16685{
16686 inst.instruction |= bit28 << 28;
16687 inst.instruction |= neon_logbits (size) << 18;
16688 inst.instruction |= inst.operands[0].reg << 12;
16689 inst.instruction |= LOW4 (inst.operands[1].reg);
16690 inst.is_neon = 1;
16691}
886e1c73 16692
93925576
AV
16693static void
16694mve_encode_rrqq (unsigned U, unsigned size)
16695{
16696 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16697
16698 inst.instruction |= U << 28;
16699 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16700 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16701 inst.instruction |= (size == 32) << 16;
16702 inst.instruction |= inst.operands[0].reg << 12;
16703 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16704 inst.instruction |= inst.operands[3].reg;
16705 inst.is_neon = 1;
16706}
16707
aab2c27d
MM
16708/* Helper function for neon_three_same handling the operands. */
16709static void
16710neon_three_args (int isquad)
16711{
16712 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16713 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16714 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16715 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16716 inst.instruction |= LOW4 (inst.operands[2].reg);
16717 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16718 inst.instruction |= (isquad != 0) << 6;
16719 inst.is_neon = 1;
16720}
16721
037e8744
JB
16722/* Encode insns with bit pattern:
16723
16724 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16725 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16726
037e8744
JB
16727 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16728 different meaning for some instruction. */
16729
16730static void
16731neon_three_same (int isquad, int ubit, int size)
16732{
aab2c27d 16733 neon_three_args (isquad);
037e8744
JB
16734 inst.instruction |= (ubit != 0) << 24;
16735 if (size != -1)
16736 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16737
88714cb8 16738 neon_dp_fixup (&inst);
037e8744
JB
16739}
16740
16741/* Encode instructions of the form:
16742
16743 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16744 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16745
16746 Don't write size if SIZE == -1. */
16747
16748static void
16749neon_two_same (int qbit, int ubit, int size)
16750{
16751 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16752 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16753 inst.instruction |= LOW4 (inst.operands[1].reg);
16754 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16755 inst.instruction |= (qbit != 0) << 6;
16756 inst.instruction |= (ubit != 0) << 24;
16757
16758 if (size != -1)
16759 inst.instruction |= neon_logbits (size) << 18;
16760
88714cb8 16761 neon_dp_fixup (&inst);
5287ad62
JB
16762}
16763
7df54120
AV
16764enum vfp_or_neon_is_neon_bits
16765{
16766NEON_CHECK_CC = 1,
16767NEON_CHECK_ARCH = 2,
16768NEON_CHECK_ARCH8 = 4
16769};
16770
16771/* Call this function if an instruction which may have belonged to the VFP or
16772 Neon instruction sets, but turned out to be a Neon instruction (due to the
16773 operand types involved, etc.). We have to check and/or fix-up a couple of
16774 things:
16775
16776 - Make sure the user hasn't attempted to make a Neon instruction
16777 conditional.
16778 - Alter the value in the condition code field if necessary.
16779 - Make sure that the arch supports Neon instructions.
16780
16781 Which of these operations take place depends on bits from enum
16782 vfp_or_neon_is_neon_bits.
16783
16784 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16785 current instruction's condition is COND_ALWAYS, the condition field is
16786 changed to inst.uncond_value. This is necessary because instructions shared
16787 between VFP and Neon may be conditional for the VFP variants only, and the
16788 unconditional Neon version must have, e.g., 0xF in the condition field. */
16789
16790static int
16791vfp_or_neon_is_neon (unsigned check)
16792{
16793/* Conditions are always legal in Thumb mode (IT blocks). */
16794if (!thumb_mode && (check & NEON_CHECK_CC))
16795 {
16796 if (inst.cond != COND_ALWAYS)
16797 {
16798 first_error (_(BAD_COND));
16799 return FAIL;
16800 }
16801 if (inst.uncond_value != -1)
16802 inst.instruction |= inst.uncond_value << 28;
16803 }
16804
16805
16806 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16807 || ((check & NEON_CHECK_ARCH8)
16808 && !mark_feature_used (&fpu_neon_ext_armv8)))
16809 {
16810 first_error (_(BAD_FPU));
16811 return FAIL;
16812 }
16813
16814return SUCCESS;
16815}
16816
64c350f2
AV
16817
16818/* Return TRUE if the SIMD instruction is available for the current
16819 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16820 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16821 vfp_or_neon_is_neon for the NEON specific checks. */
16822
16823static bfd_boolean
7df54120
AV
16824check_simd_pred_availability (int fp, unsigned check)
16825{
16826if (inst.cond > COND_ALWAYS)
16827 {
16828 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16829 {
16830 inst.error = BAD_FPU;
64c350f2 16831 return FALSE;
7df54120
AV
16832 }
16833 inst.pred_insn_type = INSIDE_VPT_INSN;
16834 }
16835else if (inst.cond < COND_ALWAYS)
16836 {
16837 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16838 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16839 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16840 return FALSE;
7df54120
AV
16841 }
16842else
16843 {
16844 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16845 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16846 return FALSE;
7df54120
AV
16847
16848 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16849 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16850 }
64c350f2 16851return TRUE;
7df54120
AV
16852}
16853
5287ad62
JB
16854/* Neon instruction encoders, in approximate order of appearance. */
16855
16856static void
16857do_neon_dyadic_i_su (void)
16858{
64c350f2 16859 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16860 return;
16861
16862 enum neon_shape rs;
16863 struct neon_type_el et;
16864 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16865 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16866 else
16867 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16868
16869 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16870
16871
16872 if (rs != NS_QQR)
16873 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16874 else
16875 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16876}
16877
16878static void
16879do_neon_dyadic_i64_su (void)
16880{
64c350f2 16881 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16882 return;
16883 enum neon_shape rs;
16884 struct neon_type_el et;
16885 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16886 {
16887 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16888 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16889 }
16890 else
16891 {
16892 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16893 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16894 }
16895 if (rs == NS_QQR)
16896 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16897 else
16898 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16899}
16900
16901static void
16902neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16903 unsigned immbits)
5287ad62
JB
16904{
16905 unsigned size = et.size >> 3;
16906 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16907 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16908 inst.instruction |= LOW4 (inst.operands[1].reg);
16909 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16910 inst.instruction |= (isquad != 0) << 6;
16911 inst.instruction |= immbits << 16;
16912 inst.instruction |= (size >> 3) << 7;
16913 inst.instruction |= (size & 0x7) << 19;
16914 if (write_ubit)
16915 inst.instruction |= (uval != 0) << 24;
16916
88714cb8 16917 neon_dp_fixup (&inst);
5287ad62
JB
16918}
16919
16920static void
5150f0d8 16921do_neon_shl (void)
5287ad62 16922{
64c350f2 16923 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16924 return;
16925
5287ad62
JB
16926 if (!inst.operands[2].isreg)
16927 {
5150f0d8
AV
16928 enum neon_shape rs;
16929 struct neon_type_el et;
16930 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16931 {
16932 rs = neon_select_shape (NS_QQI, NS_NULL);
16933 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16934 }
16935 else
16936 {
16937 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16938 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16939 }
cb3b1e65
JB
16940 int imm = inst.operands[2].imm;
16941
16942 constraint (imm < 0 || (unsigned)imm >= et.size,
16943 _("immediate out of range for shift"));
88714cb8 16944 NEON_ENCODE (IMMED, inst);
cb3b1e65 16945 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16946 }
16947 else
16948 {
5150f0d8
AV
16949 enum neon_shape rs;
16950 struct neon_type_el et;
16951 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16952 {
16953 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16954 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16955 }
16956 else
16957 {
16958 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16959 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16960 }
16961
16962
16963 if (rs == NS_QQR)
16964 {
16965 constraint (inst.operands[0].reg != inst.operands[1].reg,
16966 _("invalid instruction shape"));
16967 if (inst.operands[2].reg == REG_SP)
16968 as_tsktsk (MVE_BAD_SP);
16969 else if (inst.operands[2].reg == REG_PC)
16970 as_tsktsk (MVE_BAD_PC);
16971
16972 inst.instruction = 0xee311e60;
16973 inst.instruction |= (et.type == NT_unsigned) << 28;
16974 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16975 inst.instruction |= neon_logbits (et.size) << 18;
16976 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16977 inst.instruction |= inst.operands[2].reg;
16978 inst.is_neon = 1;
16979 }
16980 else
16981 {
16982 unsigned int tmp;
16983
16984 /* VSHL/VQSHL 3-register variants have syntax such as:
16985 vshl.xx Dd, Dm, Dn
16986 whereas other 3-register operations encoded by neon_three_same have
16987 syntax like:
16988 vadd.xx Dd, Dn, Dm
16989 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
16990 operands[2].reg here. */
16991 tmp = inst.operands[2].reg;
16992 inst.operands[2].reg = inst.operands[1].reg;
16993 inst.operands[1].reg = tmp;
16994 NEON_ENCODE (INTEGER, inst);
16995 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16996 }
5287ad62
JB
16997 }
16998}
16999
17000static void
5150f0d8 17001do_neon_qshl (void)
5287ad62 17002{
64c350f2 17003 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
17004 return;
17005
5287ad62
JB
17006 if (!inst.operands[2].isreg)
17007 {
5150f0d8
AV
17008 enum neon_shape rs;
17009 struct neon_type_el et;
17010 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17011 {
17012 rs = neon_select_shape (NS_QQI, NS_NULL);
17013 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17014 }
17015 else
17016 {
17017 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17018 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17019 }
cb3b1e65 17020 int imm = inst.operands[2].imm;
627907b7 17021
cb3b1e65
JB
17022 constraint (imm < 0 || (unsigned)imm >= et.size,
17023 _("immediate out of range for shift"));
88714cb8 17024 NEON_ENCODE (IMMED, inst);
cb3b1e65 17025 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
17026 }
17027 else
17028 {
5150f0d8
AV
17029 enum neon_shape rs;
17030 struct neon_type_el et;
627907b7 17031
5150f0d8
AV
17032 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17033 {
17034 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17035 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17036 }
17037 else
17038 {
17039 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17040 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17041 }
17042
17043 if (rs == NS_QQR)
17044 {
17045 constraint (inst.operands[0].reg != inst.operands[1].reg,
17046 _("invalid instruction shape"));
17047 if (inst.operands[2].reg == REG_SP)
17048 as_tsktsk (MVE_BAD_SP);
17049 else if (inst.operands[2].reg == REG_PC)
17050 as_tsktsk (MVE_BAD_PC);
17051
17052 inst.instruction = 0xee311ee0;
17053 inst.instruction |= (et.type == NT_unsigned) << 28;
17054 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17055 inst.instruction |= neon_logbits (et.size) << 18;
17056 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17057 inst.instruction |= inst.operands[2].reg;
17058 inst.is_neon = 1;
17059 }
17060 else
17061 {
17062 unsigned int tmp;
17063
17064 /* See note in do_neon_shl. */
17065 tmp = inst.operands[2].reg;
17066 inst.operands[2].reg = inst.operands[1].reg;
17067 inst.operands[1].reg = tmp;
17068 NEON_ENCODE (INTEGER, inst);
17069 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17070 }
5287ad62
JB
17071 }
17072}
17073
627907b7
JB
17074static void
17075do_neon_rshl (void)
17076{
64c350f2 17077 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
17078 return;
17079
17080 enum neon_shape rs;
17081 struct neon_type_el et;
17082 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17083 {
17084 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17085 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17086 }
17087 else
17088 {
17089 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17090 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17091 }
17092
627907b7
JB
17093 unsigned int tmp;
17094
1be7aba3
AV
17095 if (rs == NS_QQR)
17096 {
17097 if (inst.operands[2].reg == REG_PC)
17098 as_tsktsk (MVE_BAD_PC);
17099 else if (inst.operands[2].reg == REG_SP)
17100 as_tsktsk (MVE_BAD_SP);
17101
17102 constraint (inst.operands[0].reg != inst.operands[1].reg,
17103 _("invalid instruction shape"));
17104
17105 if (inst.instruction == 0x0000510)
17106 /* We are dealing with vqrshl. */
17107 inst.instruction = 0xee331ee0;
17108 else
17109 /* We are dealing with vrshl. */
17110 inst.instruction = 0xee331e60;
17111
17112 inst.instruction |= (et.type == NT_unsigned) << 28;
17113 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17114 inst.instruction |= neon_logbits (et.size) << 18;
17115 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17116 inst.instruction |= inst.operands[2].reg;
17117 inst.is_neon = 1;
17118 }
17119 else
17120 {
17121 tmp = inst.operands[2].reg;
17122 inst.operands[2].reg = inst.operands[1].reg;
17123 inst.operands[1].reg = tmp;
17124 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17125 }
627907b7
JB
17126}
17127
5287ad62
JB
17128static int
17129neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17130{
036dc3f7
PB
17131 /* Handle .I8 pseudo-instructions. */
17132 if (size == 8)
5287ad62 17133 {
5287ad62 17134 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
17135 FIXME is this the intended semantics? There doesn't seem much point in
17136 accepting .I8 if so. */
5287ad62
JB
17137 immediate |= immediate << 8;
17138 size = 16;
036dc3f7
PB
17139 }
17140
17141 if (size >= 32)
17142 {
17143 if (immediate == (immediate & 0x000000ff))
17144 {
17145 *immbits = immediate;
17146 return 0x1;
17147 }
17148 else if (immediate == (immediate & 0x0000ff00))
17149 {
17150 *immbits = immediate >> 8;
17151 return 0x3;
17152 }
17153 else if (immediate == (immediate & 0x00ff0000))
17154 {
17155 *immbits = immediate >> 16;
17156 return 0x5;
17157 }
17158 else if (immediate == (immediate & 0xff000000))
17159 {
17160 *immbits = immediate >> 24;
17161 return 0x7;
17162 }
17163 if ((immediate & 0xffff) != (immediate >> 16))
17164 goto bad_immediate;
17165 immediate &= 0xffff;
5287ad62
JB
17166 }
17167
17168 if (immediate == (immediate & 0x000000ff))
17169 {
17170 *immbits = immediate;
036dc3f7 17171 return 0x9;
5287ad62
JB
17172 }
17173 else if (immediate == (immediate & 0x0000ff00))
17174 {
17175 *immbits = immediate >> 8;
036dc3f7 17176 return 0xb;
5287ad62
JB
17177 }
17178
17179 bad_immediate:
dcbf9037 17180 first_error (_("immediate value out of range"));
5287ad62
JB
17181 return FAIL;
17182}
17183
5287ad62
JB
17184static void
17185do_neon_logic (void)
17186{
17187 if (inst.operands[2].present && inst.operands[2].isreg)
17188 {
037e8744 17189 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17190 if (rs == NS_QQQ
64c350f2
AV
17191 && !check_simd_pred_availability (FALSE,
17192 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17193 return;
17194 else if (rs != NS_QQQ
17195 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17196 first_error (BAD_FPU);
17197
5287ad62
JB
17198 neon_check_type (3, rs, N_IGNORE_TYPE);
17199 /* U bit and size field were set as part of the bitmask. */
88714cb8 17200 NEON_ENCODE (INTEGER, inst);
037e8744 17201 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17202 }
17203 else
17204 {
4316f0d2
DG
17205 const int three_ops_form = (inst.operands[2].present
17206 && !inst.operands[2].isreg);
17207 const int immoperand = (three_ops_form ? 2 : 1);
17208 enum neon_shape rs = (three_ops_form
17209 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17210 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17211 /* Because neon_select_shape makes the second operand a copy of the first
17212 if the second operand is not present. */
17213 if (rs == NS_QQI
64c350f2
AV
17214 && !check_simd_pred_availability (FALSE,
17215 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17216 return;
17217 else if (rs != NS_QQI
17218 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17219 first_error (BAD_FPU);
17220
17221 struct neon_type_el et;
17222 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17223 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17224 else
17225 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17226 | N_KEY, N_EQK);
17227
17228 if (et.type == NT_invtype)
17229 return;
21d799b5 17230 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17231 unsigned immbits;
17232 int cmode;
5f4273c7 17233
5f4273c7 17234
4316f0d2
DG
17235 if (three_ops_form)
17236 constraint (inst.operands[0].reg != inst.operands[1].reg,
17237 _("first and second operands shall be the same register"));
17238
88714cb8 17239 NEON_ENCODE (IMMED, inst);
5287ad62 17240
4316f0d2 17241 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17242 if (et.size == 64)
17243 {
17244 /* .i64 is a pseudo-op, so the immediate must be a repeating
17245 pattern. */
4316f0d2
DG
17246 if (immbits != (inst.operands[immoperand].regisimm ?
17247 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17248 {
17249 /* Set immbits to an invalid constant. */
17250 immbits = 0xdeadbeef;
17251 }
17252 }
17253
5287ad62 17254 switch (opcode)
477330fc
RM
17255 {
17256 case N_MNEM_vbic:
17257 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17258 break;
17259
17260 case N_MNEM_vorr:
17261 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17262 break;
17263
17264 case N_MNEM_vand:
17265 /* Pseudo-instruction for VBIC. */
17266 neon_invert_size (&immbits, 0, et.size);
17267 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17268 break;
17269
17270 case N_MNEM_vorn:
17271 /* Pseudo-instruction for VORR. */
17272 neon_invert_size (&immbits, 0, et.size);
17273 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17274 break;
17275
17276 default:
17277 abort ();
17278 }
5287ad62
JB
17279
17280 if (cmode == FAIL)
477330fc 17281 return;
5287ad62 17282
037e8744 17283 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17284 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17285 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17286 inst.instruction |= cmode << 8;
17287 neon_write_immbits (immbits);
5f4273c7 17288
88714cb8 17289 neon_dp_fixup (&inst);
5287ad62
JB
17290 }
17291}
17292
17293static void
17294do_neon_bitfield (void)
17295{
037e8744 17296 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17297 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17298 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17299}
17300
17301static void
dcbf9037 17302neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17303 unsigned destbits)
5287ad62 17304{
5ee91343 17305 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17306 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17307 types | N_KEY);
5287ad62
JB
17308 if (et.type == NT_float)
17309 {
88714cb8 17310 NEON_ENCODE (FLOAT, inst);
5ee91343 17311 if (rs == NS_QQR)
7df54120 17312 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17313 else
17314 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17315 }
17316 else
17317 {
88714cb8 17318 NEON_ENCODE (INTEGER, inst);
5ee91343 17319 if (rs == NS_QQR)
a8465a06 17320 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17321 else
17322 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17323 }
17324}
17325
5287ad62
JB
17326
17327static void
17328do_neon_dyadic_if_su_d (void)
17329{
17330 /* This version only allow D registers, but that constraint is enforced during
17331 operand parsing so we don't need to do anything extra here. */
dcbf9037 17332 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17333}
17334
5287ad62
JB
17335static void
17336do_neon_dyadic_if_i_d (void)
17337{
428e3f1f
PB
17338 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17339 affected if we specify unsigned args. */
17340 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17341}
17342
f5f10c66
AV
17343static void
17344do_mve_vstr_vldr_QI (int size, int elsize, int load)
17345{
17346 constraint (size < 32, BAD_ADDR_MODE);
17347 constraint (size != elsize, BAD_EL_TYPE);
17348 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17349 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17350 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17351 _("destination register and offset register may not be the"
17352 " same"));
17353
17354 int imm = inst.relocs[0].exp.X_add_number;
17355 int add = 1;
17356 if (imm < 0)
17357 {
17358 add = 0;
17359 imm = -imm;
17360 }
17361 constraint ((imm % (size / 8) != 0)
17362 || imm > (0x7f << neon_logbits (size)),
17363 (size == 32) ? _("immediate must be a multiple of 4 in the"
17364 " range of +/-[0,508]")
17365 : _("immediate must be a multiple of 8 in the"
17366 " range of +/-[0,1016]"));
17367 inst.instruction |= 0x11 << 24;
17368 inst.instruction |= add << 23;
17369 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17370 inst.instruction |= inst.operands[1].writeback << 21;
17371 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17372 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17373 inst.instruction |= 1 << 12;
17374 inst.instruction |= (size == 64) << 8;
17375 inst.instruction &= 0xffffff00;
17376 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17377 inst.instruction |= imm >> neon_logbits (size);
17378}
17379
17380static void
17381do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17382{
17383 unsigned os = inst.operands[1].imm >> 5;
e449ea97 17384 unsigned type = inst.vectype.el[0].type;
f5f10c66
AV
17385 constraint (os != 0 && size == 8,
17386 _("can not shift offsets when accessing less than half-word"));
17387 constraint (os && os != neon_logbits (size),
17388 _("shift immediate must be 1, 2 or 3 for half-word, word"
17389 " or double-word accesses respectively"));
17390 if (inst.operands[1].reg == REG_PC)
17391 as_tsktsk (MVE_BAD_PC);
17392
17393 switch (size)
17394 {
17395 case 8:
17396 constraint (elsize >= 64, BAD_EL_TYPE);
17397 break;
17398 case 16:
17399 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17400 break;
17401 case 32:
17402 case 64:
17403 constraint (elsize != size, BAD_EL_TYPE);
17404 break;
17405 default:
17406 break;
17407 }
17408 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17409 BAD_ADDR_MODE);
17410 if (load)
17411 {
17412 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17413 _("destination register and offset register may not be"
17414 " the same"));
e449ea97
SP
17415 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17416 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
f5f10c66 17417 BAD_EL_TYPE);
e449ea97 17418 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
f5f10c66
AV
17419 }
17420 else
17421 {
e449ea97 17422 constraint (type != NT_untyped, BAD_EL_TYPE);
f5f10c66
AV
17423 }
17424
17425 inst.instruction |= 1 << 23;
17426 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17427 inst.instruction |= inst.operands[1].reg << 16;
17428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17429 inst.instruction |= neon_logbits (elsize) << 7;
17430 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17431 inst.instruction |= LOW4 (inst.operands[1].imm);
17432 inst.instruction |= !!os;
17433}
17434
17435static void
17436do_mve_vstr_vldr_RI (int size, int elsize, int load)
17437{
17438 enum neon_el_type type = inst.vectype.el[0].type;
17439
17440 constraint (size >= 64, BAD_ADDR_MODE);
17441 switch (size)
17442 {
17443 case 16:
17444 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17445 break;
17446 case 32:
17447 constraint (elsize != size, BAD_EL_TYPE);
17448 break;
17449 default:
17450 break;
17451 }
17452 if (load)
17453 {
17454 constraint (elsize != size && type != NT_unsigned
17455 && type != NT_signed, BAD_EL_TYPE);
17456 }
17457 else
17458 {
17459 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17460 }
17461
17462 int imm = inst.relocs[0].exp.X_add_number;
17463 int add = 1;
17464 if (imm < 0)
17465 {
17466 add = 0;
17467 imm = -imm;
17468 }
17469
17470 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17471 {
17472 switch (size)
17473 {
17474 case 8:
17475 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17476 break;
17477 case 16:
17478 constraint (1, _("immediate must be a multiple of 2 in the"
17479 " range of +/-[0,254]"));
17480 break;
17481 case 32:
17482 constraint (1, _("immediate must be a multiple of 4 in the"
17483 " range of +/-[0,508]"));
17484 break;
17485 }
17486 }
17487
17488 if (size != elsize)
17489 {
17490 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17491 constraint (inst.operands[0].reg > 14,
17492 _("MVE vector register in the range [Q0..Q7] expected"));
17493 inst.instruction |= (load && type == NT_unsigned) << 28;
17494 inst.instruction |= (size == 16) << 19;
17495 inst.instruction |= neon_logbits (elsize) << 7;
17496 }
17497 else
17498 {
17499 if (inst.operands[1].reg == REG_PC)
17500 as_tsktsk (MVE_BAD_PC);
17501 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17502 as_tsktsk (MVE_BAD_SP);
17503 inst.instruction |= 1 << 12;
17504 inst.instruction |= neon_logbits (size) << 7;
17505 }
17506 inst.instruction |= inst.operands[1].preind << 24;
17507 inst.instruction |= add << 23;
17508 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17509 inst.instruction |= inst.operands[1].writeback << 21;
17510 inst.instruction |= inst.operands[1].reg << 16;
17511 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17512 inst.instruction &= 0xffffff80;
17513 inst.instruction |= imm >> neon_logbits (size);
17514
17515}
17516
17517static void
17518do_mve_vstr_vldr (void)
17519{
17520 unsigned size;
17521 int load = 0;
17522
17523 if (inst.cond > COND_ALWAYS)
17524 inst.pred_insn_type = INSIDE_VPT_INSN;
17525 else
17526 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17527
17528 switch (inst.instruction)
17529 {
17530 default:
17531 gas_assert (0);
17532 break;
17533 case M_MNEM_vldrb:
17534 load = 1;
17535 /* fall through. */
17536 case M_MNEM_vstrb:
17537 size = 8;
17538 break;
17539 case M_MNEM_vldrh:
17540 load = 1;
17541 /* fall through. */
17542 case M_MNEM_vstrh:
17543 size = 16;
17544 break;
17545 case M_MNEM_vldrw:
17546 load = 1;
17547 /* fall through. */
17548 case M_MNEM_vstrw:
17549 size = 32;
17550 break;
17551 case M_MNEM_vldrd:
17552 load = 1;
17553 /* fall through. */
17554 case M_MNEM_vstrd:
17555 size = 64;
17556 break;
17557 }
17558 unsigned elsize = inst.vectype.el[0].size;
17559
17560 if (inst.operands[1].isquad)
17561 {
17562 /* We are dealing with [Q, imm]{!} cases. */
17563 do_mve_vstr_vldr_QI (size, elsize, load);
17564 }
17565 else
17566 {
17567 if (inst.operands[1].immisreg == 2)
17568 {
17569 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17570 do_mve_vstr_vldr_RQ (size, elsize, load);
17571 }
17572 else if (!inst.operands[1].immisreg)
17573 {
17574 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17575 do_mve_vstr_vldr_RI (size, elsize, load);
17576 }
17577 else
17578 constraint (1, BAD_ADDR_MODE);
17579 }
17580
17581 inst.is_neon = 1;
17582}
17583
35c228db
AV
17584static void
17585do_mve_vst_vld (void)
17586{
17587 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17588 return;
17589
17590 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17591 || inst.relocs[0].exp.X_add_number != 0
17592 || inst.operands[1].immisreg != 0,
17593 BAD_ADDR_MODE);
17594 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17595 if (inst.operands[1].reg == REG_PC)
17596 as_tsktsk (MVE_BAD_PC);
17597 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17598 as_tsktsk (MVE_BAD_SP);
17599
17600
17601 /* These instructions are one of the "exceptions" mentioned in
17602 handle_pred_state. They are MVE instructions that are not VPT compatible
17603 and do not accept a VPT code, thus appending such a code is a syntax
17604 error. */
17605 if (inst.cond > COND_ALWAYS)
17606 first_error (BAD_SYNTAX);
17607 /* If we append a scalar condition code we can set this to
17608 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17609 else if (inst.cond < COND_ALWAYS)
17610 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17611 else
17612 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17613
17614 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17615 inst.instruction |= inst.operands[1].writeback << 21;
17616 inst.instruction |= inst.operands[1].reg << 16;
17617 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17618 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17619 inst.is_neon = 1;
17620}
17621
26c1e780
AV
17622static void
17623do_mve_vaddlv (void)
17624{
17625 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17626 struct neon_type_el et
17627 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17628
17629 if (et.type == NT_invtype)
17630 first_error (BAD_EL_TYPE);
17631
17632 if (inst.cond > COND_ALWAYS)
17633 inst.pred_insn_type = INSIDE_VPT_INSN;
17634 else
17635 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17636
17637 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17638
17639 inst.instruction |= (et.type == NT_unsigned) << 28;
17640 inst.instruction |= inst.operands[1].reg << 19;
17641 inst.instruction |= inst.operands[0].reg << 12;
17642 inst.instruction |= inst.operands[2].reg;
17643 inst.is_neon = 1;
17644}
17645
5287ad62 17646static void
5ee91343 17647do_neon_dyadic_if_su (void)
5287ad62 17648{
5ee91343
AV
17649 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17650 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17651 N_SUF_32 | N_KEY);
17652
935295b5
AV
17653 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17654 || inst.instruction == ((unsigned) N_MNEM_vmin))
17655 && et.type == NT_float
17656 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17657
64c350f2
AV
17658 if (!check_simd_pred_availability (et.type == NT_float,
17659 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17660 return;
17661
5ee91343
AV
17662 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17663}
17664
17665static void
17666do_neon_addsub_if_i (void)
17667{
17668 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17669 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17670 return;
17671
5ee91343
AV
17672 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17673 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17674 N_EQK, N_IF_32 | N_I64 | N_KEY);
17675
17676 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17677 /* If we are parsing Q registers and the element types match MVE, which NEON
17678 also supports, then we must check whether this is an instruction that can
17679 be used by both MVE/NEON. This distinction can be made based on whether
17680 they are predicated or not. */
17681 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17682 {
64c350f2
AV
17683 if (!check_simd_pred_availability (et.type == NT_float,
17684 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17685 return;
17686 }
17687 else
17688 {
17689 /* If they are either in a D register or are using an unsupported. */
17690 if (rs != NS_QQR
17691 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17692 return;
17693 }
17694
5287ad62
JB
17695 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17696 affected if we specify unsigned args. */
dcbf9037 17697 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17698}
17699
17700/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17701 result to be:
17702 V<op> A,B (A is operand 0, B is operand 2)
17703 to mean:
17704 V<op> A,B,A
17705 not:
17706 V<op> A,B,B
17707 so handle that case specially. */
17708
17709static void
17710neon_exchange_operands (void)
17711{
5287ad62
JB
17712 if (inst.operands[1].present)
17713 {
e1fa0163
NC
17714 void *scratch = xmalloc (sizeof (inst.operands[0]));
17715
5287ad62
JB
17716 /* Swap operands[1] and operands[2]. */
17717 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17718 inst.operands[1] = inst.operands[2];
17719 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17720 free (scratch);
5287ad62
JB
17721 }
17722 else
17723 {
17724 inst.operands[1] = inst.operands[2];
17725 inst.operands[2] = inst.operands[0];
17726 }
17727}
17728
17729static void
17730neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17731{
17732 if (inst.operands[2].isreg)
17733 {
17734 if (invert)
477330fc 17735 neon_exchange_operands ();
dcbf9037 17736 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17737 }
17738 else
17739 {
037e8744 17740 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17741 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17742 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17743
88714cb8 17744 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17745 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17746 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17747 inst.instruction |= LOW4 (inst.operands[1].reg);
17748 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17749 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17750 inst.instruction |= (et.type == NT_float) << 10;
17751 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17752
88714cb8 17753 neon_dp_fixup (&inst);
5287ad62
JB
17754 }
17755}
17756
17757static void
17758do_neon_cmp (void)
17759{
cc933301 17760 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17761}
17762
17763static void
17764do_neon_cmp_inv (void)
17765{
cc933301 17766 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17767}
17768
17769static void
17770do_neon_ceq (void)
17771{
17772 neon_compare (N_IF_32, N_IF_32, FALSE);
17773}
17774
17775/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17776 scalars, which are encoded in 5 bits, M : Rm.
17777 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17778 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17779 index in M.
17780
17781 Dot Product instructions are similar to multiply instructions except elsize
17782 should always be 32.
17783
17784 This function translates SCALAR, which is GAS's internal encoding of indexed
17785 scalar register, to raw encoding. There is also register and index range
17786 check based on ELSIZE. */
5287ad62
JB
17787
17788static unsigned
17789neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17790{
dcbf9037
JB
17791 unsigned regno = NEON_SCALAR_REG (scalar);
17792 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17793
17794 switch (elsize)
17795 {
17796 case 16:
17797 if (regno > 7 || elno > 3)
477330fc 17798 goto bad_scalar;
5287ad62 17799 return regno | (elno << 3);
5f4273c7 17800
5287ad62
JB
17801 case 32:
17802 if (regno > 15 || elno > 1)
477330fc 17803 goto bad_scalar;
5287ad62
JB
17804 return regno | (elno << 4);
17805
17806 default:
17807 bad_scalar:
dcbf9037 17808 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17809 }
17810
17811 return 0;
17812}
17813
17814/* Encode multiply / multiply-accumulate scalar instructions. */
17815
17816static void
17817neon_mul_mac (struct neon_type_el et, int ubit)
17818{
dcbf9037
JB
17819 unsigned scalar;
17820
17821 /* Give a more helpful error message if we have an invalid type. */
17822 if (et.type == NT_invtype)
17823 return;
5f4273c7 17824
dcbf9037 17825 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17826 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17827 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17828 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17829 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17830 inst.instruction |= LOW4 (scalar);
17831 inst.instruction |= HI1 (scalar) << 5;
17832 inst.instruction |= (et.type == NT_float) << 8;
17833 inst.instruction |= neon_logbits (et.size) << 20;
17834 inst.instruction |= (ubit != 0) << 24;
17835
88714cb8 17836 neon_dp_fixup (&inst);
5287ad62
JB
17837}
17838
17839static void
17840do_neon_mac_maybe_scalar (void)
17841{
037e8744
JB
17842 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17843 return;
17844
64c350f2 17845 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17846 return;
17847
5287ad62
JB
17848 if (inst.operands[2].isscalar)
17849 {
a8465a06 17850 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17851 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17852 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17853 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17854 NEON_ENCODE (SCALAR, inst);
037e8744 17855 neon_mul_mac (et, neon_quad (rs));
5287ad62 17856 }
a8465a06
AV
17857 else if (!inst.operands[2].isvec)
17858 {
17859 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17860
17861 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17862 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17863
17864 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17865 }
5287ad62 17866 else
428e3f1f 17867 {
a8465a06 17868 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17869 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17870 affected if we specify unsigned args. */
17871 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17872 }
5287ad62
JB
17873}
17874
aab2c27d
MM
17875static void
17876do_bfloat_vfma (void)
17877{
17878 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17879 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17880 enum neon_shape rs;
17881 int t_bit = 0;
17882
17883 if (inst.instruction != B_MNEM_vfmab)
17884 {
17885 t_bit = 1;
17886 inst.instruction = B_MNEM_vfmat;
17887 }
17888
17889 if (inst.operands[2].isscalar)
17890 {
17891 rs = neon_select_shape (NS_QQS, NS_NULL);
17892 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17893
17894 inst.instruction |= (1 << 25);
17895 int index = inst.operands[2].reg & 0xf;
17896 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17897 inst.operands[2].reg >>= 4;
17898 constraint (!(inst.operands[2].reg < 8),
17899 _("indexed register must be less than 8"));
17900 neon_three_args (t_bit);
17901 inst.instruction |= ((index & 1) << 3);
17902 inst.instruction |= ((index & 2) << 4);
17903 }
17904 else
17905 {
17906 rs = neon_select_shape (NS_QQQ, NS_NULL);
17907 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17908 neon_three_args (t_bit);
17909 }
17910
17911}
17912
62f3b8c8
PB
17913static void
17914do_neon_fmac (void)
17915{
d58196e0
AV
17916 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17917 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17918 return;
17919
64c350f2 17920 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17921 return;
17922
d58196e0
AV
17923 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17924 {
17925 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17926 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17927 N_EQK);
17928
17929 if (rs == NS_QQR)
17930 {
aab2c27d 17931
d58196e0
AV
17932 if (inst.operands[2].reg == REG_SP)
17933 as_tsktsk (MVE_BAD_SP);
17934 else if (inst.operands[2].reg == REG_PC)
17935 as_tsktsk (MVE_BAD_PC);
17936
17937 inst.instruction = 0xee310e40;
17938 inst.instruction |= (et.size == 16) << 28;
17939 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17940 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17941 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17942 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17943 inst.instruction |= inst.operands[2].reg;
17944 inst.is_neon = 1;
17945 return;
17946 }
17947 }
17948 else
17949 {
17950 constraint (!inst.operands[2].isvec, BAD_FPU);
17951 }
17952
62f3b8c8
PB
17953 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17954}
17955
aab2c27d
MM
17956static void
17957do_mve_vfma (void)
17958{
17959 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17960 inst.cond == COND_ALWAYS)
17961 {
17962 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17963 inst.instruction = N_MNEM_vfma;
17964 inst.pred_insn_type = INSIDE_VPT_INSN;
17965 inst.cond = 0xf;
17966 return do_neon_fmac();
17967 }
17968 else
17969 {
17970 do_bfloat_vfma();
17971 }
17972}
17973
5287ad62
JB
17974static void
17975do_neon_tst (void)
17976{
037e8744 17977 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
17978 struct neon_type_el et = neon_check_type (3, rs,
17979 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 17980 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
17981}
17982
17983/* VMUL with 3 registers allows the P8 type. The scalar version supports the
17984 same types as the MAC equivalents. The polynomial type for this instruction
17985 is encoded the same as the integer type. */
17986
17987static void
17988do_neon_mul (void)
17989{
037e8744
JB
17990 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
17991 return;
17992
64c350f2 17993 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17994 return;
17995
5287ad62 17996 if (inst.operands[2].isscalar)
a8465a06
AV
17997 {
17998 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17999 do_neon_mac_maybe_scalar ();
18000 }
5287ad62 18001 else
a8465a06
AV
18002 {
18003 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18004 {
18005 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18006 struct neon_type_el et
18007 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18008 if (et.type == NT_float)
18009 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18010 BAD_FPU);
18011
18012 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18013 }
18014 else
18015 {
18016 constraint (!inst.operands[2].isvec, BAD_FPU);
18017 neon_dyadic_misc (NT_poly,
18018 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18019 }
18020 }
5287ad62
JB
18021}
18022
18023static void
18024do_neon_qdmulh (void)
18025{
64c350f2 18026 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18027 return;
18028
5287ad62
JB
18029 if (inst.operands[2].isscalar)
18030 {
42b16635 18031 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 18032 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 18033 struct neon_type_el et = neon_check_type (3, rs,
477330fc 18034 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 18035 NEON_ENCODE (SCALAR, inst);
037e8744 18036 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
18037 }
18038 else
18039 {
42b16635
AV
18040 enum neon_shape rs;
18041 struct neon_type_el et;
18042 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18043 {
18044 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18045 et = neon_check_type (3, rs,
18046 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18047 }
18048 else
18049 {
18050 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18051 et = neon_check_type (3, rs,
18052 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18053 }
18054
88714cb8 18055 NEON_ENCODE (INTEGER, inst);
42b16635
AV
18056 if (rs == NS_QQR)
18057 mve_encode_qqr (et.size, 0, 0);
18058 else
18059 /* The U bit (rounding) comes from bit mask. */
18060 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18061 }
18062}
18063
26c1e780
AV
18064static void
18065do_mve_vaddv (void)
18066{
18067 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18068 struct neon_type_el et
18069 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18070
18071 if (et.type == NT_invtype)
18072 first_error (BAD_EL_TYPE);
18073
18074 if (inst.cond > COND_ALWAYS)
18075 inst.pred_insn_type = INSIDE_VPT_INSN;
18076 else
18077 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18078
18079 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18080
18081 mve_encode_rq (et.type == NT_unsigned, et.size);
18082}
18083
7df54120
AV
18084static void
18085do_mve_vhcadd (void)
18086{
18087 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18088 struct neon_type_el et
18089 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18090
18091 if (inst.cond > COND_ALWAYS)
18092 inst.pred_insn_type = INSIDE_VPT_INSN;
18093 else
18094 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18095
18096 unsigned rot = inst.relocs[0].exp.X_add_number;
18097 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18098
18099 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18100 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18101 "operand makes instruction UNPREDICTABLE"));
18102
18103 mve_encode_qqq (0, et.size);
18104 inst.instruction |= (rot == 270) << 12;
18105 inst.is_neon = 1;
18106}
18107
35d1cfc2
AV
18108static void
18109do_mve_vqdmull (void)
18110{
18111 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18112 struct neon_type_el et
18113 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18114
18115 if (et.size == 32
18116 && (inst.operands[0].reg == inst.operands[1].reg
18117 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18118 as_tsktsk (BAD_MVE_SRCDEST);
18119
18120 if (inst.cond > COND_ALWAYS)
18121 inst.pred_insn_type = INSIDE_VPT_INSN;
18122 else
18123 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18124
18125 if (rs == NS_QQQ)
18126 {
18127 mve_encode_qqq (et.size == 32, 64);
18128 inst.instruction |= 1;
18129 }
18130 else
18131 {
18132 mve_encode_qqr (64, et.size == 32, 0);
18133 inst.instruction |= 0x3 << 5;
18134 }
18135}
18136
c2dafc2a
AV
18137static void
18138do_mve_vadc (void)
18139{
18140 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18141 struct neon_type_el et
18142 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18143
18144 if (et.type == NT_invtype)
18145 first_error (BAD_EL_TYPE);
18146
18147 if (inst.cond > COND_ALWAYS)
18148 inst.pred_insn_type = INSIDE_VPT_INSN;
18149 else
18150 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18151
18152 mve_encode_qqq (0, 64);
18153}
18154
18155static void
18156do_mve_vbrsr (void)
18157{
18158 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18159 struct neon_type_el et
18160 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18161
18162 if (inst.cond > COND_ALWAYS)
18163 inst.pred_insn_type = INSIDE_VPT_INSN;
18164 else
18165 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18166
7df54120 18167 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
18168}
18169
18170static void
18171do_mve_vsbc (void)
18172{
18173 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18174
18175 if (inst.cond > COND_ALWAYS)
18176 inst.pred_insn_type = INSIDE_VPT_INSN;
18177 else
18178 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18179
18180 mve_encode_qqq (1, 64);
18181}
18182
2d78f95b
AV
18183static void
18184do_mve_vmulh (void)
18185{
18186 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18187 struct neon_type_el et
18188 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18189
18190 if (inst.cond > COND_ALWAYS)
18191 inst.pred_insn_type = INSIDE_VPT_INSN;
18192 else
18193 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18194
18195 mve_encode_qqq (et.type == NT_unsigned, et.size);
18196}
18197
42b16635
AV
18198static void
18199do_mve_vqdmlah (void)
18200{
18201 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18202 struct neon_type_el et
23d188c7 18203 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
18204
18205 if (inst.cond > COND_ALWAYS)
18206 inst.pred_insn_type = INSIDE_VPT_INSN;
18207 else
18208 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18209
18210 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18211}
8b8b22a4
AV
18212
18213static void
18214do_mve_vqdmladh (void)
18215{
18216 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18217 struct neon_type_el et
18218 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18219
18220 if (inst.cond > COND_ALWAYS)
18221 inst.pred_insn_type = INSIDE_VPT_INSN;
18222 else
18223 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18224
8b8b22a4
AV
18225 mve_encode_qqq (0, et.size);
18226}
18227
18228
886e1c73
AV
18229static void
18230do_mve_vmull (void)
18231{
18232
18233 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18234 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18235 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18236 && inst.cond == COND_ALWAYS
18237 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18238 {
18239 if (rs == NS_QQQ)
18240 {
18241
18242 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18243 N_SUF_32 | N_F64 | N_P8
18244 | N_P16 | N_I_MVE | N_KEY);
18245 if (((et.type == NT_poly) && et.size == 8
18246 && ARM_CPU_IS_ANY (cpu_variant))
18247 || (et.type == NT_integer) || (et.type == NT_float))
18248 goto neon_vmul;
18249 }
18250 else
18251 goto neon_vmul;
18252 }
18253
18254 constraint (rs != NS_QQQ, BAD_FPU);
18255 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18256 N_SU_32 | N_P8 | N_P16 | N_KEY);
18257
18258 /* We are dealing with MVE's vmullt. */
18259 if (et.size == 32
18260 && (inst.operands[0].reg == inst.operands[1].reg
18261 || inst.operands[0].reg == inst.operands[2].reg))
18262 as_tsktsk (BAD_MVE_SRCDEST);
18263
18264 if (inst.cond > COND_ALWAYS)
18265 inst.pred_insn_type = INSIDE_VPT_INSN;
18266 else
18267 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18268
18269 if (et.type == NT_poly)
18270 mve_encode_qqq (neon_logbits (et.size), 64);
18271 else
18272 mve_encode_qqq (et.type == NT_unsigned, et.size);
18273
18274 return;
18275
18276neon_vmul:
18277 inst.instruction = N_MNEM_vmul;
18278 inst.cond = 0xb;
18279 if (thumb_mode)
18280 inst.pred_insn_type = INSIDE_IT_INSN;
18281 do_neon_mul ();
18282}
18283
a302e574
AV
18284static void
18285do_mve_vabav (void)
18286{
18287 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18288
18289 if (rs == NS_NULL)
18290 return;
18291
18292 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18293 return;
18294
18295 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18296 | N_S16 | N_S32 | N_U8 | N_U16
18297 | N_U32);
18298
18299 if (inst.cond > COND_ALWAYS)
18300 inst.pred_insn_type = INSIDE_VPT_INSN;
18301 else
18302 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18303
18304 mve_encode_rqq (et.type == NT_unsigned, et.size);
18305}
18306
18307static void
18308do_mve_vmladav (void)
18309{
18310 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18311 struct neon_type_el et = neon_check_type (3, rs,
18312 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18313
18314 if (et.type == NT_unsigned
18315 && (inst.instruction == M_MNEM_vmladavx
18316 || inst.instruction == M_MNEM_vmladavax
18317 || inst.instruction == M_MNEM_vmlsdav
18318 || inst.instruction == M_MNEM_vmlsdava
18319 || inst.instruction == M_MNEM_vmlsdavx
18320 || inst.instruction == M_MNEM_vmlsdavax))
18321 first_error (BAD_SIMD_TYPE);
18322
18323 constraint (inst.operands[2].reg > 14,
18324 _("MVE vector register in the range [Q0..Q7] expected"));
18325
18326 if (inst.cond > COND_ALWAYS)
18327 inst.pred_insn_type = INSIDE_VPT_INSN;
18328 else
18329 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18330
18331 if (inst.instruction == M_MNEM_vmlsdav
18332 || inst.instruction == M_MNEM_vmlsdava
18333 || inst.instruction == M_MNEM_vmlsdavx
18334 || inst.instruction == M_MNEM_vmlsdavax)
18335 inst.instruction |= (et.size == 8) << 28;
18336 else
18337 inst.instruction |= (et.size == 8) << 8;
18338
18339 mve_encode_rqq (et.type == NT_unsigned, 64);
18340 inst.instruction |= (et.size == 32) << 16;
18341}
18342
93925576
AV
18343static void
18344do_mve_vmlaldav (void)
18345{
18346 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18347 struct neon_type_el et
18348 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18349 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18350
18351 if (et.type == NT_unsigned
18352 && (inst.instruction == M_MNEM_vmlsldav
18353 || inst.instruction == M_MNEM_vmlsldava
18354 || inst.instruction == M_MNEM_vmlsldavx
18355 || inst.instruction == M_MNEM_vmlsldavax))
18356 first_error (BAD_SIMD_TYPE);
18357
18358 if (inst.cond > COND_ALWAYS)
18359 inst.pred_insn_type = INSIDE_VPT_INSN;
18360 else
18361 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18362
18363 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18364}
18365
18366static void
18367do_mve_vrmlaldavh (void)
18368{
18369 struct neon_type_el et;
18370 if (inst.instruction == M_MNEM_vrmlsldavh
18371 || inst.instruction == M_MNEM_vrmlsldavha
18372 || inst.instruction == M_MNEM_vrmlsldavhx
18373 || inst.instruction == M_MNEM_vrmlsldavhax)
18374 {
18375 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18376 if (inst.operands[1].reg == REG_SP)
18377 as_tsktsk (MVE_BAD_SP);
18378 }
18379 else
18380 {
18381 if (inst.instruction == M_MNEM_vrmlaldavhx
18382 || inst.instruction == M_MNEM_vrmlaldavhax)
18383 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18384 else
18385 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18386 N_U32 | N_S32 | N_KEY);
18387 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18388 with vmax/min instructions, making the use of SP in assembly really
18389 nonsensical, so instead of issuing a warning like we do for other uses
18390 of SP for the odd register operand we error out. */
18391 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18392 }
18393
18394 /* Make sure we still check the second operand is an odd one and that PC is
18395 disallowed. This because we are parsing for any GPR operand, to be able
18396 to distinguish between giving a warning or an error for SP as described
18397 above. */
18398 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18399 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18400
18401 if (inst.cond > COND_ALWAYS)
18402 inst.pred_insn_type = INSIDE_VPT_INSN;
18403 else
18404 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18405
18406 mve_encode_rrqq (et.type == NT_unsigned, 0);
18407}
18408
18409
8cd78170
AV
18410static void
18411do_mve_vmaxnmv (void)
18412{
18413 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18414 struct neon_type_el et
18415 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18416
18417 if (inst.cond > COND_ALWAYS)
18418 inst.pred_insn_type = INSIDE_VPT_INSN;
18419 else
18420 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18421
18422 if (inst.operands[0].reg == REG_SP)
18423 as_tsktsk (MVE_BAD_SP);
18424 else if (inst.operands[0].reg == REG_PC)
18425 as_tsktsk (MVE_BAD_PC);
18426
18427 mve_encode_rq (et.size == 16, 64);
18428}
18429
13ccd4c0
AV
18430static void
18431do_mve_vmaxv (void)
18432{
18433 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18434 struct neon_type_el et;
18435
18436 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18437 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18438 else
18439 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18440
18441 if (inst.cond > COND_ALWAYS)
18442 inst.pred_insn_type = INSIDE_VPT_INSN;
18443 else
18444 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18445
18446 if (inst.operands[0].reg == REG_SP)
18447 as_tsktsk (MVE_BAD_SP);
18448 else if (inst.operands[0].reg == REG_PC)
18449 as_tsktsk (MVE_BAD_PC);
18450
18451 mve_encode_rq (et.type == NT_unsigned, et.size);
18452}
18453
18454
643afb90
MW
18455static void
18456do_neon_qrdmlah (void)
18457{
64c350f2 18458 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18459 return;
18460 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18461 {
42b16635
AV
18462 /* Check we're on the correct architecture. */
18463 if (!mark_feature_used (&fpu_neon_ext_armv8))
18464 inst.error
18465 = _("instruction form not available on this architecture.");
18466 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18467 {
18468 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18469 record_feature_use (&fpu_neon_ext_v8_1);
18470 }
18471 if (inst.operands[2].isscalar)
18472 {
18473 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18474 struct neon_type_el et = neon_check_type (3, rs,
18475 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18476 NEON_ENCODE (SCALAR, inst);
18477 neon_mul_mac (et, neon_quad (rs));
18478 }
18479 else
18480 {
18481 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18482 struct neon_type_el et = neon_check_type (3, rs,
18483 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18484 NEON_ENCODE (INTEGER, inst);
18485 /* The U bit (rounding) comes from bit mask. */
18486 neon_three_same (neon_quad (rs), 0, et.size);
18487 }
643afb90
MW
18488 }
18489 else
18490 {
42b16635
AV
18491 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18492 struct neon_type_el et
23d188c7 18493 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18494
643afb90 18495 NEON_ENCODE (INTEGER, inst);
42b16635 18496 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18497 }
18498}
18499
5287ad62
JB
18500static void
18501do_neon_fcmp_absolute (void)
18502{
037e8744 18503 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18504 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18505 N_F_16_32 | N_KEY);
5287ad62 18506 /* Size field comes from bit mask. */
cc933301 18507 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18508}
18509
18510static void
18511do_neon_fcmp_absolute_inv (void)
18512{
18513 neon_exchange_operands ();
18514 do_neon_fcmp_absolute ();
18515}
18516
18517static void
18518do_neon_step (void)
18519{
037e8744 18520 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18521 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18522 N_F_16_32 | N_KEY);
18523 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18524}
18525
18526static void
18527do_neon_abs_neg (void)
18528{
037e8744
JB
18529 enum neon_shape rs;
18530 struct neon_type_el et;
5f4273c7 18531
037e8744
JB
18532 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18533 return;
18534
037e8744 18535 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18536 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18537
64c350f2
AV
18538 if (!check_simd_pred_availability (et.type == NT_float,
18539 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18540 return;
18541
5287ad62
JB
18542 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18543 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18544 inst.instruction |= LOW4 (inst.operands[1].reg);
18545 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18546 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18547 inst.instruction |= (et.type == NT_float) << 10;
18548 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18549
88714cb8 18550 neon_dp_fixup (&inst);
5287ad62
JB
18551}
18552
18553static void
18554do_neon_sli (void)
18555{
64c350f2 18556 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18557 return;
18558
18559 enum neon_shape rs;
18560 struct neon_type_el et;
18561 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18562 {
18563 rs = neon_select_shape (NS_QQI, NS_NULL);
18564 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18565 }
18566 else
18567 {
18568 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18569 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18570 }
18571
18572
5287ad62
JB
18573 int imm = inst.operands[2].imm;
18574 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18575 _("immediate out of range for insert"));
037e8744 18576 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18577}
18578
18579static void
18580do_neon_sri (void)
18581{
64c350f2 18582 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18583 return;
18584
18585 enum neon_shape rs;
18586 struct neon_type_el et;
18587 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18588 {
18589 rs = neon_select_shape (NS_QQI, NS_NULL);
18590 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18591 }
18592 else
18593 {
18594 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18595 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18596 }
18597
5287ad62
JB
18598 int imm = inst.operands[2].imm;
18599 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18600 _("immediate out of range for insert"));
037e8744 18601 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18602}
18603
18604static void
18605do_neon_qshlu_imm (void)
18606{
64c350f2 18607 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18608 return;
18609
18610 enum neon_shape rs;
18611 struct neon_type_el et;
18612 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18613 {
18614 rs = neon_select_shape (NS_QQI, NS_NULL);
18615 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18616 }
18617 else
18618 {
18619 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18620 et = neon_check_type (2, rs, N_EQK | N_UNS,
18621 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18622 }
18623
5287ad62
JB
18624 int imm = inst.operands[2].imm;
18625 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18626 _("immediate out of range for shift"));
5287ad62
JB
18627 /* Only encodes the 'U present' variant of the instruction.
18628 In this case, signed types have OP (bit 8) set to 0.
18629 Unsigned types have OP set to 1. */
18630 inst.instruction |= (et.type == NT_unsigned) << 8;
18631 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18632 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18633}
18634
18635static void
18636do_neon_qmovn (void)
18637{
18638 struct neon_type_el et = neon_check_type (2, NS_DQ,
18639 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18640 /* Saturating move where operands can be signed or unsigned, and the
18641 destination has the same signedness. */
88714cb8 18642 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18643 if (et.type == NT_unsigned)
18644 inst.instruction |= 0xc0;
18645 else
18646 inst.instruction |= 0x80;
18647 neon_two_same (0, 1, et.size / 2);
18648}
18649
18650static void
18651do_neon_qmovun (void)
18652{
18653 struct neon_type_el et = neon_check_type (2, NS_DQ,
18654 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18655 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18656 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18657 neon_two_same (0, 1, et.size / 2);
18658}
18659
18660static void
18661do_neon_rshift_sat_narrow (void)
18662{
18663 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18664 or unsigned. If operands are unsigned, results must also be unsigned. */
18665 struct neon_type_el et = neon_check_type (2, NS_DQI,
18666 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18667 int imm = inst.operands[2].imm;
18668 /* This gets the bounds check, size encoding and immediate bits calculation
18669 right. */
18670 et.size /= 2;
5f4273c7 18671
5287ad62
JB
18672 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18673 VQMOVN.I<size> <Dd>, <Qm>. */
18674 if (imm == 0)
18675 {
18676 inst.operands[2].present = 0;
18677 inst.instruction = N_MNEM_vqmovn;
18678 do_neon_qmovn ();
18679 return;
18680 }
5f4273c7 18681
5287ad62 18682 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18683 _("immediate out of range"));
5287ad62
JB
18684 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18685}
18686
18687static void
18688do_neon_rshift_sat_narrow_u (void)
18689{
18690 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18691 or unsigned. If operands are unsigned, results must also be unsigned. */
18692 struct neon_type_el et = neon_check_type (2, NS_DQI,
18693 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18694 int imm = inst.operands[2].imm;
18695 /* This gets the bounds check, size encoding and immediate bits calculation
18696 right. */
18697 et.size /= 2;
18698
18699 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18700 VQMOVUN.I<size> <Dd>, <Qm>. */
18701 if (imm == 0)
18702 {
18703 inst.operands[2].present = 0;
18704 inst.instruction = N_MNEM_vqmovun;
18705 do_neon_qmovun ();
18706 return;
18707 }
18708
18709 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18710 _("immediate out of range"));
5287ad62
JB
18711 /* FIXME: The manual is kind of unclear about what value U should have in
18712 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18713 must be 1. */
18714 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18715}
18716
18717static void
18718do_neon_movn (void)
18719{
18720 struct neon_type_el et = neon_check_type (2, NS_DQ,
18721 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18722 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18723 neon_two_same (0, 1, et.size / 2);
18724}
18725
18726static void
18727do_neon_rshift_narrow (void)
18728{
18729 struct neon_type_el et = neon_check_type (2, NS_DQI,
18730 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18731 int imm = inst.operands[2].imm;
18732 /* This gets the bounds check, size encoding and immediate bits calculation
18733 right. */
18734 et.size /= 2;
5f4273c7 18735
5287ad62
JB
18736 /* If immediate is zero then we are a pseudo-instruction for
18737 VMOVN.I<size> <Dd>, <Qm> */
18738 if (imm == 0)
18739 {
18740 inst.operands[2].present = 0;
18741 inst.instruction = N_MNEM_vmovn;
18742 do_neon_movn ();
18743 return;
18744 }
5f4273c7 18745
5287ad62 18746 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18747 _("immediate out of range for narrowing operation"));
5287ad62
JB
18748 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18749}
18750
18751static void
18752do_neon_shll (void)
18753{
18754 /* FIXME: Type checking when lengthening. */
18755 struct neon_type_el et = neon_check_type (2, NS_QDI,
18756 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18757 unsigned imm = inst.operands[2].imm;
18758
18759 if (imm == et.size)
18760 {
18761 /* Maximum shift variant. */
88714cb8 18762 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18763 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18764 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18765 inst.instruction |= LOW4 (inst.operands[1].reg);
18766 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18767 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18768
88714cb8 18769 neon_dp_fixup (&inst);
5287ad62
JB
18770 }
18771 else
18772 {
18773 /* A more-specific type check for non-max versions. */
18774 et = neon_check_type (2, NS_QDI,
477330fc 18775 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18776 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18777 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18778 }
18779}
18780
037e8744 18781/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18782 the current instruction is. */
18783
6b9a8b67
MGD
18784#define CVT_FLAVOUR_VAR \
18785 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18786 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18787 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18788 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18789 /* Half-precision conversions. */ \
cc933301
JW
18790 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18791 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18792 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18793 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18794 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18795 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18796 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18797 Compared with single/double precision variants, only the co-processor \
18798 field is different, so the encoding flow is reused here. */ \
18799 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18800 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18801 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18802 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
aab2c27d 18803 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18804 /* VFP instructions. */ \
18805 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18806 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18807 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18808 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18809 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18810 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18811 /* VFP instructions with bitshift. */ \
18812 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18813 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18814 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18815 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18816 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18817 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18818 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18819 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18820
18821#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18822 neon_cvt_flavour_##C,
18823
18824/* The different types of conversions we can do. */
18825enum neon_cvt_flavour
18826{
18827 CVT_FLAVOUR_VAR
18828 neon_cvt_flavour_invalid,
18829 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18830};
18831
18832#undef CVT_VAR
18833
18834static enum neon_cvt_flavour
18835get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18836{
6b9a8b67
MGD
18837#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18838 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18839 if (et.type != NT_invtype) \
18840 { \
18841 inst.error = NULL; \
18842 return (neon_cvt_flavour_##C); \
5287ad62 18843 }
6b9a8b67 18844
5287ad62 18845 struct neon_type_el et;
037e8744 18846 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18847 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18848 /* The instruction versions which take an immediate take one register
18849 argument, which is extended to the width of the full register. Thus the
18850 "source" and "destination" registers must have the same width. Hack that
18851 here by making the size equal to the key (wider, in this case) operand. */
18852 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18853
6b9a8b67
MGD
18854 CVT_FLAVOUR_VAR;
18855
18856 return neon_cvt_flavour_invalid;
5287ad62
JB
18857#undef CVT_VAR
18858}
18859
7e8e6784
MGD
18860enum neon_cvt_mode
18861{
18862 neon_cvt_mode_a,
18863 neon_cvt_mode_n,
18864 neon_cvt_mode_p,
18865 neon_cvt_mode_m,
18866 neon_cvt_mode_z,
30bdf752
MGD
18867 neon_cvt_mode_x,
18868 neon_cvt_mode_r
7e8e6784
MGD
18869};
18870
037e8744
JB
18871/* Neon-syntax VFP conversions. */
18872
5287ad62 18873static void
6b9a8b67 18874do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18875{
037e8744 18876 const char *opname = 0;
5f4273c7 18877
d54af2d0
RL
18878 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18879 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18880 {
037e8744
JB
18881 /* Conversions with immediate bitshift. */
18882 const char *enc[] =
477330fc 18883 {
6b9a8b67
MGD
18884#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18885 CVT_FLAVOUR_VAR
18886 NULL
18887#undef CVT_VAR
477330fc 18888 };
037e8744 18889
6b9a8b67 18890 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18891 {
18892 opname = enc[flavour];
18893 constraint (inst.operands[0].reg != inst.operands[1].reg,
18894 _("operands 0 and 1 must be the same register"));
18895 inst.operands[1] = inst.operands[2];
18896 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18897 }
5287ad62
JB
18898 }
18899 else
18900 {
037e8744
JB
18901 /* Conversions without bitshift. */
18902 const char *enc[] =
477330fc 18903 {
6b9a8b67
MGD
18904#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18905 CVT_FLAVOUR_VAR
18906 NULL
18907#undef CVT_VAR
477330fc 18908 };
037e8744 18909
6b9a8b67 18910 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18911 opname = enc[flavour];
037e8744
JB
18912 }
18913
18914 if (opname)
18915 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18916
18917 /* ARMv8.2 fp16 VCVT instruction. */
18918 if (flavour == neon_cvt_flavour_s32_f16
18919 || flavour == neon_cvt_flavour_u32_f16
18920 || flavour == neon_cvt_flavour_f16_u32
18921 || flavour == neon_cvt_flavour_f16_s32)
18922 do_scalar_fp16_v82_encode ();
037e8744
JB
18923}
18924
18925static void
18926do_vfp_nsyn_cvtz (void)
18927{
d54af2d0 18928 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18929 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18930 const char *enc[] =
18931 {
6b9a8b67
MGD
18932#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18933 CVT_FLAVOUR_VAR
18934 NULL
18935#undef CVT_VAR
037e8744
JB
18936 };
18937
6b9a8b67 18938 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18939 do_vfp_nsyn_opcode (enc[flavour]);
18940}
f31fef98 18941
037e8744 18942static void
bacebabc 18943do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18944 enum neon_cvt_mode mode)
18945{
18946 int sz, op;
18947 int rm;
18948
a715796b
TG
18949 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18950 D register operands. */
18951 if (flavour == neon_cvt_flavour_s32_f64
18952 || flavour == neon_cvt_flavour_u32_f64)
18953 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18954 _(BAD_FPU));
18955
9db2f6b4
RL
18956 if (flavour == neon_cvt_flavour_s32_f16
18957 || flavour == neon_cvt_flavour_u32_f16)
18958 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18959 _(BAD_FP16));
18960
5ee91343 18961 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18962
18963 switch (flavour)
18964 {
18965 case neon_cvt_flavour_s32_f64:
18966 sz = 1;
827f64ff 18967 op = 1;
7e8e6784
MGD
18968 break;
18969 case neon_cvt_flavour_s32_f32:
18970 sz = 0;
18971 op = 1;
18972 break;
9db2f6b4
RL
18973 case neon_cvt_flavour_s32_f16:
18974 sz = 0;
18975 op = 1;
18976 break;
7e8e6784
MGD
18977 case neon_cvt_flavour_u32_f64:
18978 sz = 1;
18979 op = 0;
18980 break;
18981 case neon_cvt_flavour_u32_f32:
18982 sz = 0;
18983 op = 0;
18984 break;
9db2f6b4
RL
18985 case neon_cvt_flavour_u32_f16:
18986 sz = 0;
18987 op = 0;
18988 break;
7e8e6784
MGD
18989 default:
18990 first_error (_("invalid instruction shape"));
18991 return;
18992 }
18993
18994 switch (mode)
18995 {
18996 case neon_cvt_mode_a: rm = 0; break;
18997 case neon_cvt_mode_n: rm = 1; break;
18998 case neon_cvt_mode_p: rm = 2; break;
18999 case neon_cvt_mode_m: rm = 3; break;
19000 default: first_error (_("invalid rounding mode")); return;
19001 }
19002
19003 NEON_ENCODE (FPV8, inst);
19004 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19005 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19006 inst.instruction |= sz << 8;
9db2f6b4
RL
19007
19008 /* ARMv8.2 fp16 VCVT instruction. */
19009 if (flavour == neon_cvt_flavour_s32_f16
19010 ||flavour == neon_cvt_flavour_u32_f16)
19011 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
19012 inst.instruction |= op << 7;
19013 inst.instruction |= rm << 16;
19014 inst.instruction |= 0xf0000000;
19015 inst.is_neon = TRUE;
19016}
19017
19018static void
19019do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
19020{
19021 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
19022 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19023 NS_FH, NS_HF, NS_FHI, NS_HFI,
19024 NS_NULL);
6b9a8b67 19025 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 19026
cc933301
JW
19027 if (flavour == neon_cvt_flavour_invalid)
19028 return;
19029
e3e535bc 19030 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 19031 if (mode == neon_cvt_mode_z
e3e535bc 19032 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
19033 && (flavour == neon_cvt_flavour_s16_f16
19034 || flavour == neon_cvt_flavour_u16_f16
19035 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
19036 || flavour == neon_cvt_flavour_u32_f32
19037 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 19038 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
19039 && (rs == NS_FD || rs == NS_FF))
19040 {
19041 do_vfp_nsyn_cvtz ();
19042 return;
19043 }
19044
9db2f6b4
RL
19045 /* ARMv8.2 fp16 VCVT conversions. */
19046 if (mode == neon_cvt_mode_z
19047 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19048 && (flavour == neon_cvt_flavour_s32_f16
19049 || flavour == neon_cvt_flavour_u32_f16)
19050 && (rs == NS_FH))
19051 {
19052 do_vfp_nsyn_cvtz ();
19053 do_scalar_fp16_v82_encode ();
19054 return;
19055 }
19056
037e8744 19057 /* VFP rather than Neon conversions. */
6b9a8b67 19058 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 19059 {
7e8e6784
MGD
19060 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19061 do_vfp_nsyn_cvt (rs, flavour);
19062 else
19063 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19064
037e8744
JB
19065 return;
19066 }
19067
19068 switch (rs)
19069 {
037e8744 19070 case NS_QQI:
dd9634d9
AV
19071 if (mode == neon_cvt_mode_z
19072 && (flavour == neon_cvt_flavour_f16_s16
19073 || flavour == neon_cvt_flavour_f16_u16
19074 || flavour == neon_cvt_flavour_s16_f16
19075 || flavour == neon_cvt_flavour_u16_f16
19076 || flavour == neon_cvt_flavour_f32_u32
19077 || flavour == neon_cvt_flavour_f32_s32
19078 || flavour == neon_cvt_flavour_s32_f32
19079 || flavour == neon_cvt_flavour_u32_f32))
19080 {
64c350f2
AV
19081 if (!check_simd_pred_availability (TRUE,
19082 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19083 return;
19084 }
19085 else if (mode == neon_cvt_mode_n)
19086 {
19087 /* We are dealing with vcvt with the 'ne' condition. */
19088 inst.cond = 0x1;
19089 inst.instruction = N_MNEM_vcvt;
19090 do_neon_cvt_1 (neon_cvt_mode_z);
19091 return;
19092 }
19093 /* fall through. */
19094 case NS_DDI:
037e8744 19095 {
477330fc 19096 unsigned immbits;
cc933301
JW
19097 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19098 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 19099
dd9634d9
AV
19100 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19101 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19102 return;
19103
19104 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19105 {
19106 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19107 _("immediate value out of range"));
19108 switch (flavour)
19109 {
19110 case neon_cvt_flavour_f16_s16:
19111 case neon_cvt_flavour_f16_u16:
19112 case neon_cvt_flavour_s16_f16:
19113 case neon_cvt_flavour_u16_f16:
19114 constraint (inst.operands[2].imm > 16,
19115 _("immediate value out of range"));
19116 break;
19117 case neon_cvt_flavour_f32_u32:
19118 case neon_cvt_flavour_f32_s32:
19119 case neon_cvt_flavour_s32_f32:
19120 case neon_cvt_flavour_u32_f32:
19121 constraint (inst.operands[2].imm > 32,
19122 _("immediate value out of range"));
19123 break;
19124 default:
19125 inst.error = BAD_FPU;
19126 return;
19127 }
19128 }
037e8744 19129
477330fc
RM
19130 /* Fixed-point conversion with #0 immediate is encoded as an
19131 integer conversion. */
19132 if (inst.operands[2].present && inst.operands[2].imm == 0)
19133 goto int_encode;
477330fc
RM
19134 NEON_ENCODE (IMMED, inst);
19135 if (flavour != neon_cvt_flavour_invalid)
19136 inst.instruction |= enctab[flavour];
19137 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19138 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19139 inst.instruction |= LOW4 (inst.operands[1].reg);
19140 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19141 inst.instruction |= neon_quad (rs) << 6;
19142 inst.instruction |= 1 << 21;
cc933301
JW
19143 if (flavour < neon_cvt_flavour_s16_f16)
19144 {
19145 inst.instruction |= 1 << 21;
19146 immbits = 32 - inst.operands[2].imm;
19147 inst.instruction |= immbits << 16;
19148 }
19149 else
19150 {
19151 inst.instruction |= 3 << 20;
19152 immbits = 16 - inst.operands[2].imm;
19153 inst.instruction |= immbits << 16;
19154 inst.instruction &= ~(1 << 9);
19155 }
477330fc
RM
19156
19157 neon_dp_fixup (&inst);
037e8744
JB
19158 }
19159 break;
19160
037e8744 19161 case NS_QQ:
dd9634d9
AV
19162 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19163 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19164 && (flavour == neon_cvt_flavour_s16_f16
19165 || flavour == neon_cvt_flavour_u16_f16
19166 || flavour == neon_cvt_flavour_s32_f32
19167 || flavour == neon_cvt_flavour_u32_f32))
19168 {
64c350f2
AV
19169 if (!check_simd_pred_availability (TRUE,
19170 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
19171 return;
19172 }
19173 else if (mode == neon_cvt_mode_z
19174 && (flavour == neon_cvt_flavour_f16_s16
19175 || flavour == neon_cvt_flavour_f16_u16
19176 || flavour == neon_cvt_flavour_s16_f16
19177 || flavour == neon_cvt_flavour_u16_f16
19178 || flavour == neon_cvt_flavour_f32_u32
19179 || flavour == neon_cvt_flavour_f32_s32
19180 || flavour == neon_cvt_flavour_s32_f32
19181 || flavour == neon_cvt_flavour_u32_f32))
19182 {
64c350f2
AV
19183 if (!check_simd_pred_availability (TRUE,
19184 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19185 return;
19186 }
19187 /* fall through. */
19188 case NS_DD:
7e8e6784
MGD
19189 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19190 {
7e8e6784 19191
dd9634d9 19192 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
19193 if (!check_simd_pred_availability (TRUE,
19194 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
19195 return;
19196
19197 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19198 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19199 inst.instruction |= LOW4 (inst.operands[1].reg);
19200 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19201 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19202 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19203 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 19204 inst.instruction |= mode << 8;
cc933301
JW
19205 if (flavour == neon_cvt_flavour_u16_f16
19206 || flavour == neon_cvt_flavour_s16_f16)
19207 /* Mask off the original size bits and reencode them. */
19208 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19209
7e8e6784
MGD
19210 if (thumb_mode)
19211 inst.instruction |= 0xfc000000;
19212 else
19213 inst.instruction |= 0xf0000000;
19214 }
19215 else
19216 {
037e8744 19217 int_encode:
7e8e6784 19218 {
cc933301
JW
19219 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19220 0x100, 0x180, 0x0, 0x080};
037e8744 19221
7e8e6784 19222 NEON_ENCODE (INTEGER, inst);
037e8744 19223
dd9634d9
AV
19224 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19225 {
19226 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19227 return;
19228 }
037e8744 19229
7e8e6784
MGD
19230 if (flavour != neon_cvt_flavour_invalid)
19231 inst.instruction |= enctab[flavour];
037e8744 19232
7e8e6784
MGD
19233 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19234 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19235 inst.instruction |= LOW4 (inst.operands[1].reg);
19236 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19237 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19238 if (flavour >= neon_cvt_flavour_s16_f16
19239 && flavour <= neon_cvt_flavour_f16_u16)
19240 /* Half precision. */
19241 inst.instruction |= 1 << 18;
19242 else
19243 inst.instruction |= 2 << 18;
037e8744 19244
7e8e6784
MGD
19245 neon_dp_fixup (&inst);
19246 }
19247 }
19248 break;
037e8744 19249
8e79c3df
CM
19250 /* Half-precision conversions for Advanced SIMD -- neon. */
19251 case NS_QD:
19252 case NS_DQ:
bc52d49c
MM
19253 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19254 return;
8e79c3df
CM
19255
19256 if ((rs == NS_DQ)
19257 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19258 {
19259 as_bad (_("operand size must match register width"));
19260 break;
19261 }
19262
19263 if ((rs == NS_QD)
19264 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19265 {
19266 as_bad (_("operand size must match register width"));
19267 break;
19268 }
19269
19270 if (rs == NS_DQ)
aab2c27d
MM
19271 {
19272 if (flavour == neon_cvt_flavour_bf16_f32)
19273 {
19274 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19275 return;
19276 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19277 /* VCVT.bf16.f32. */
19278 inst.instruction = 0x11b60640;
19279 }
19280 else
19281 /* VCVT.f16.f32. */
19282 inst.instruction = 0x3b60600;
19283 }
8e79c3df 19284 else
aab2c27d 19285 /* VCVT.f32.f16. */
8e79c3df
CM
19286 inst.instruction = 0x3b60700;
19287
19288 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19289 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19290 inst.instruction |= LOW4 (inst.operands[1].reg);
19291 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19292 neon_dp_fixup (&inst);
8e79c3df
CM
19293 break;
19294
037e8744
JB
19295 default:
19296 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19297 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19298 do_vfp_nsyn_cvt (rs, flavour);
19299 else
19300 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19301 }
5287ad62
JB
19302}
19303
e3e535bc
NC
19304static void
19305do_neon_cvtr (void)
19306{
7e8e6784 19307 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19308}
19309
19310static void
19311do_neon_cvt (void)
19312{
7e8e6784
MGD
19313 do_neon_cvt_1 (neon_cvt_mode_z);
19314}
19315
19316static void
19317do_neon_cvta (void)
19318{
19319 do_neon_cvt_1 (neon_cvt_mode_a);
19320}
19321
19322static void
19323do_neon_cvtn (void)
19324{
19325 do_neon_cvt_1 (neon_cvt_mode_n);
19326}
19327
19328static void
19329do_neon_cvtp (void)
19330{
19331 do_neon_cvt_1 (neon_cvt_mode_p);
19332}
19333
19334static void
19335do_neon_cvtm (void)
19336{
19337 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19338}
19339
8e79c3df 19340static void
c70a8987 19341do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19342{
c70a8987
MGD
19343 if (is_double)
19344 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19345
c70a8987
MGD
19346 encode_arm_vfp_reg (inst.operands[0].reg,
19347 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19348 encode_arm_vfp_reg (inst.operands[1].reg,
19349 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19350 inst.instruction |= to ? 0x10000 : 0;
19351 inst.instruction |= t ? 0x80 : 0;
19352 inst.instruction |= is_double ? 0x100 : 0;
19353 do_vfp_cond_or_thumb ();
19354}
8e79c3df 19355
c70a8987
MGD
19356static void
19357do_neon_cvttb_1 (bfd_boolean t)
19358{
d54af2d0 19359 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19360 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19361
c70a8987
MGD
19362 if (rs == NS_NULL)
19363 return;
dd9634d9
AV
19364 else if (rs == NS_QQ || rs == NS_QQI)
19365 {
19366 int single_to_half = 0;
64c350f2 19367 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19368 return;
19369
19370 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19371
19372 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19373 && (flavour == neon_cvt_flavour_u16_f16
19374 || flavour == neon_cvt_flavour_s16_f16
19375 || flavour == neon_cvt_flavour_f16_s16
19376 || flavour == neon_cvt_flavour_f16_u16
19377 || flavour == neon_cvt_flavour_u32_f32
19378 || flavour == neon_cvt_flavour_s32_f32
19379 || flavour == neon_cvt_flavour_f32_s32
19380 || flavour == neon_cvt_flavour_f32_u32))
19381 {
19382 inst.cond = 0xf;
19383 inst.instruction = N_MNEM_vcvt;
19384 set_pred_insn_type (INSIDE_VPT_INSN);
19385 do_neon_cvt_1 (neon_cvt_mode_z);
19386 return;
19387 }
19388 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19389 single_to_half = 1;
19390 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19391 {
19392 first_error (BAD_FPU);
19393 return;
19394 }
19395
19396 inst.instruction = 0xee3f0e01;
19397 inst.instruction |= single_to_half << 28;
19398 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19399 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19400 inst.instruction |= t << 12;
19401 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19402 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19403 inst.is_neon = 1;
19404 }
c70a8987
MGD
19405 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19406 {
19407 inst.error = NULL;
19408 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19409 }
19410 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19411 {
19412 inst.error = NULL;
19413 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19414 }
19415 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19416 {
a715796b
TG
19417 /* The VCVTB and VCVTT instructions with D-register operands
19418 don't work for SP only targets. */
19419 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19420 _(BAD_FPU));
19421
c70a8987
MGD
19422 inst.error = NULL;
19423 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19424 }
19425 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19426 {
a715796b
TG
19427 /* The VCVTB and VCVTT instructions with D-register operands
19428 don't work for SP only targets. */
19429 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19430 _(BAD_FPU));
19431
c70a8987
MGD
19432 inst.error = NULL;
19433 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19434 }
aab2c27d
MM
19435 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19436 {
19437 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19438 inst.error = NULL;
19439 inst.instruction |= (1 << 8);
19440 inst.instruction &= ~(1 << 9);
19441 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19442 }
c70a8987
MGD
19443 else
19444 return;
19445}
19446
19447static void
19448do_neon_cvtb (void)
19449{
19450 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19451}
19452
19453
19454static void
19455do_neon_cvtt (void)
19456{
c70a8987 19457 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19458}
19459
5287ad62
JB
19460static void
19461neon_move_immediate (void)
19462{
037e8744
JB
19463 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19464 struct neon_type_el et = neon_check_type (2, rs,
19465 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19466 unsigned immlo, immhi = 0, immbits;
c96612cc 19467 int op, cmode, float_p;
5287ad62 19468
037e8744 19469 constraint (et.type == NT_invtype,
477330fc 19470 _("operand size must be specified for immediate VMOV"));
037e8744 19471
5287ad62
JB
19472 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19473 op = (inst.instruction & (1 << 5)) != 0;
19474
19475 immlo = inst.operands[1].imm;
19476 if (inst.operands[1].regisimm)
19477 immhi = inst.operands[1].reg;
19478
19479 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19480 _("immediate has bits set outside the operand size"));
5287ad62 19481
c96612cc
JB
19482 float_p = inst.operands[1].immisfloat;
19483
19484 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19485 et.size, et.type)) == FAIL)
5287ad62
JB
19486 {
19487 /* Invert relevant bits only. */
19488 neon_invert_size (&immlo, &immhi, et.size);
19489 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19490 with one or the other; those cases are caught by
19491 neon_cmode_for_move_imm. */
5287ad62 19492 op = !op;
c96612cc
JB
19493 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19494 &op, et.size, et.type)) == FAIL)
477330fc
RM
19495 {
19496 first_error (_("immediate out of range"));
19497 return;
19498 }
5287ad62
JB
19499 }
19500
19501 inst.instruction &= ~(1 << 5);
19502 inst.instruction |= op << 5;
19503
19504 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19505 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19506 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19507 inst.instruction |= cmode << 8;
19508
19509 neon_write_immbits (immbits);
19510}
19511
19512static void
19513do_neon_mvn (void)
19514{
64c350f2 19515 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19516 return;
19517
5287ad62
JB
19518 if (inst.operands[1].isreg)
19519 {
1a186d29
AV
19520 enum neon_shape rs;
19521 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19522 rs = neon_select_shape (NS_QQ, NS_NULL);
19523 else
19524 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19525
88714cb8 19526 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19527 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19528 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19529 inst.instruction |= LOW4 (inst.operands[1].reg);
19530 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19531 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19532 }
19533 else
19534 {
88714cb8 19535 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19536 neon_move_immediate ();
19537 }
19538
88714cb8 19539 neon_dp_fixup (&inst);
1a186d29
AV
19540
19541 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19542 {
19543 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
1a186d29 19544 }
5287ad62
JB
19545}
19546
19547/* Encode instructions of form:
19548
19549 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19550 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19551
19552static void
19553neon_mixed_length (struct neon_type_el et, unsigned size)
19554{
19555 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19556 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19557 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19558 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19559 inst.instruction |= LOW4 (inst.operands[2].reg);
19560 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19561 inst.instruction |= (et.type == NT_unsigned) << 24;
19562 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19563
88714cb8 19564 neon_dp_fixup (&inst);
5287ad62
JB
19565}
19566
19567static void
19568do_neon_dyadic_long (void)
19569{
5ee91343
AV
19570 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19571 if (rs == NS_QDD)
19572 {
19573 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19574 return;
19575
19576 NEON_ENCODE (INTEGER, inst);
19577 /* FIXME: Type checking for lengthening op. */
19578 struct neon_type_el et = neon_check_type (3, NS_QDD,
19579 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19580 neon_mixed_length (et, et.size);
19581 }
19582 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19583 && (inst.cond == 0xf || inst.cond == 0x10))
19584 {
19585 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19586 in an IT block with le/lt conditions. */
19587
19588 if (inst.cond == 0xf)
19589 inst.cond = 0xb;
19590 else if (inst.cond == 0x10)
19591 inst.cond = 0xd;
19592
19593 inst.pred_insn_type = INSIDE_IT_INSN;
19594
19595 if (inst.instruction == N_MNEM_vaddl)
19596 {
19597 inst.instruction = N_MNEM_vadd;
19598 do_neon_addsub_if_i ();
19599 }
19600 else if (inst.instruction == N_MNEM_vsubl)
19601 {
19602 inst.instruction = N_MNEM_vsub;
19603 do_neon_addsub_if_i ();
19604 }
19605 else if (inst.instruction == N_MNEM_vabdl)
19606 {
19607 inst.instruction = N_MNEM_vabd;
19608 do_neon_dyadic_if_su ();
19609 }
19610 }
19611 else
19612 first_error (BAD_FPU);
5287ad62
JB
19613}
19614
19615static void
19616do_neon_abal (void)
19617{
19618 struct neon_type_el et = neon_check_type (3, NS_QDD,
19619 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19620 neon_mixed_length (et, et.size);
19621}
19622
19623static void
19624neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19625{
19626 if (inst.operands[2].isscalar)
19627 {
dcbf9037 19628 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19629 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19630 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19631 neon_mul_mac (et, et.type == NT_unsigned);
19632 }
19633 else
19634 {
19635 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19636 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19637 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19638 neon_mixed_length (et, et.size);
19639 }
19640}
19641
19642static void
19643do_neon_mac_maybe_scalar_long (void)
19644{
19645 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19646}
19647
dec41383
JW
19648/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19649 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19650
19651static unsigned
19652neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19653{
19654 unsigned regno = NEON_SCALAR_REG (scalar);
19655 unsigned elno = NEON_SCALAR_INDEX (scalar);
19656
19657 if (quad_p)
19658 {
19659 if (regno > 7 || elno > 3)
19660 goto bad_scalar;
19661
19662 return ((regno & 0x7)
19663 | ((elno & 0x1) << 3)
19664 | (((elno >> 1) & 0x1) << 5));
19665 }
19666 else
19667 {
19668 if (regno > 15 || elno > 1)
19669 goto bad_scalar;
19670
19671 return (((regno & 0x1) << 5)
19672 | ((regno >> 1) & 0x7)
19673 | ((elno & 0x1) << 3));
19674 }
19675
19676bad_scalar:
19677 first_error (_("scalar out of range for multiply instruction"));
19678 return 0;
19679}
19680
19681static void
19682do_neon_fmac_maybe_scalar_long (int subtype)
19683{
19684 enum neon_shape rs;
19685 int high8;
19686 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19687 field (bits[21:20]) has different meaning. For scalar index variant, it's
19688 used to differentiate add and subtract, otherwise it's with fixed value
19689 0x2. */
19690 int size = -1;
19691
dec41383
JW
19692 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19693 be a scalar index register. */
19694 if (inst.operands[2].isscalar)
19695 {
19696 high8 = 0xfe000000;
19697 if (subtype)
19698 size = 16;
19699 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19700 }
19701 else
19702 {
19703 high8 = 0xfc000000;
19704 size = 32;
19705 if (subtype)
19706 inst.instruction |= (0x1 << 23);
19707 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19708 }
19709
aab2c27d
MM
19710
19711 if (inst.cond != COND_ALWAYS)
19712 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19713 "behaviour is UNPREDICTABLE"));
19714
19715 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19716 _(BAD_FP16));
19717
19718 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19719 _(BAD_FPU));
dec41383
JW
19720
19721 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19722 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19723 so we simply pass -1 as size. */
19724 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19725 neon_three_same (quad_p, 0, size);
19726
19727 /* Undo neon_dp_fixup. Redo the high eight bits. */
19728 inst.instruction &= 0x00ffffff;
19729 inst.instruction |= high8;
19730
19731#define LOW1(R) ((R) & 0x1)
19732#define HI4(R) (((R) >> 1) & 0xf)
19733 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19734 whether the instruction is in Q form and whether Vm is a scalar indexed
19735 operand. */
19736 if (inst.operands[2].isscalar)
19737 {
19738 unsigned rm
19739 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19740 inst.instruction &= 0xffffffd0;
19741 inst.instruction |= rm;
19742
19743 if (!quad_p)
19744 {
19745 /* Redo Rn as well. */
19746 inst.instruction &= 0xfff0ff7f;
19747 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19748 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19749 }
19750 }
19751 else if (!quad_p)
19752 {
19753 /* Redo Rn and Rm. */
19754 inst.instruction &= 0xfff0ff50;
19755 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19756 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19757 inst.instruction |= HI4 (inst.operands[2].reg);
19758 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19759 }
19760}
19761
19762static void
19763do_neon_vfmal (void)
19764{
19765 return do_neon_fmac_maybe_scalar_long (0);
19766}
19767
19768static void
19769do_neon_vfmsl (void)
19770{
19771 return do_neon_fmac_maybe_scalar_long (1);
19772}
19773
5287ad62
JB
19774static void
19775do_neon_dyadic_wide (void)
19776{
19777 struct neon_type_el et = neon_check_type (3, NS_QQD,
19778 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19779 neon_mixed_length (et, et.size);
19780}
19781
19782static void
19783do_neon_dyadic_narrow (void)
19784{
19785 struct neon_type_el et = neon_check_type (3, NS_QDD,
19786 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19787 /* Operand sign is unimportant, and the U bit is part of the opcode,
19788 so force the operand type to integer. */
19789 et.type = NT_integer;
5287ad62
JB
19790 neon_mixed_length (et, et.size / 2);
19791}
19792
19793static void
19794do_neon_mul_sat_scalar_long (void)
19795{
19796 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19797}
19798
19799static void
19800do_neon_vmull (void)
19801{
19802 if (inst.operands[2].isscalar)
19803 do_neon_mac_maybe_scalar_long ();
19804 else
19805 {
19806 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19807 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19808
5287ad62 19809 if (et.type == NT_poly)
477330fc 19810 NEON_ENCODE (POLY, inst);
5287ad62 19811 else
477330fc 19812 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19813
19814 /* For polynomial encoding the U bit must be zero, and the size must
19815 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19816 obviously, as 0b10). */
19817 if (et.size == 64)
19818 {
19819 /* Check we're on the correct architecture. */
19820 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19821 inst.error =
19822 _("Instruction form not available on this architecture.");
19823
19824 et.size = 32;
19825 }
19826
5287ad62
JB
19827 neon_mixed_length (et, et.size);
19828 }
19829}
19830
19831static void
19832do_neon_ext (void)
19833{
037e8744 19834 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19835 struct neon_type_el et = neon_check_type (3, rs,
19836 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19837 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19838
19839 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19840 _("shift out of range"));
5287ad62
JB
19841 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19842 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19843 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19844 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19845 inst.instruction |= LOW4 (inst.operands[2].reg);
19846 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19847 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19848 inst.instruction |= imm << 8;
5f4273c7 19849
88714cb8 19850 neon_dp_fixup (&inst);
5287ad62
JB
19851}
19852
19853static void
19854do_neon_rev (void)
19855{
64c350f2 19856 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19857 return;
19858
19859 enum neon_shape rs;
19860 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19861 rs = neon_select_shape (NS_QQ, NS_NULL);
19862 else
19863 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19864
5287ad62
JB
19865 struct neon_type_el et = neon_check_type (2, rs,
19866 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19867
5287ad62
JB
19868 unsigned op = (inst.instruction >> 7) & 3;
19869 /* N (width of reversed regions) is encoded as part of the bitmask. We
19870 extract it here to check the elements to be reversed are smaller.
19871 Otherwise we'd get a reserved instruction. */
19872 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19873
19874 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19875 && inst.operands[0].reg == inst.operands[1].reg)
19876 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19877 " operands makes instruction UNPREDICTABLE"));
19878
9c2799c2 19879 gas_assert (elsize != 0);
5287ad62 19880 constraint (et.size >= elsize,
477330fc 19881 _("elements must be smaller than reversal region"));
037e8744 19882 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19883}
19884
19885static void
19886do_neon_dup (void)
19887{
19888 if (inst.operands[1].isscalar)
19889 {
b409bdb6
AV
19890 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19891 BAD_FPU);
037e8744 19892 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19893 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19894 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19895 unsigned sizebits = et.size >> 3;
dcbf9037 19896 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19897 int logsize = neon_logbits (et.size);
dcbf9037 19898 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19899
19900 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19901 return;
037e8744 19902
88714cb8 19903 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19904 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19905 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19906 inst.instruction |= LOW4 (dm);
19907 inst.instruction |= HI1 (dm) << 5;
037e8744 19908 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19909 inst.instruction |= x << 17;
19910 inst.instruction |= sizebits << 16;
5f4273c7 19911
88714cb8 19912 neon_dp_fixup (&inst);
5287ad62
JB
19913 }
19914 else
19915 {
037e8744
JB
19916 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19917 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19918 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19919 if (rs == NS_QR)
19920 {
64c350f2 19921 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19922 return;
19923 }
19924 else
19925 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19926 BAD_FPU);
19927
19928 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19929 {
19930 if (inst.operands[1].reg == REG_SP)
19931 as_tsktsk (MVE_BAD_SP);
19932 else if (inst.operands[1].reg == REG_PC)
19933 as_tsktsk (MVE_BAD_PC);
19934 }
19935
5287ad62 19936 /* Duplicate ARM register to lanes of vector. */
88714cb8 19937 NEON_ENCODE (ARMREG, inst);
5287ad62 19938 switch (et.size)
477330fc
RM
19939 {
19940 case 8: inst.instruction |= 0x400000; break;
19941 case 16: inst.instruction |= 0x000020; break;
19942 case 32: inst.instruction |= 0x000000; break;
19943 default: break;
19944 }
5287ad62
JB
19945 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19946 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19947 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19948 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19949 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19950 variants, except for the condition field. */
037e8744 19951 do_vfp_cond_or_thumb ();
5287ad62
JB
19952 }
19953}
19954
57785aa2
AV
19955static void
19956do_mve_mov (int toQ)
19957{
19958 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19959 return;
19960 if (inst.cond > COND_ALWAYS)
19961 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19962
19963 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19964 if (toQ)
19965 {
19966 Q0 = 0;
19967 Q1 = 1;
19968 Rt = 2;
19969 Rt2 = 3;
19970 }
19971
19972 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19973 _("Index one must be [2,3] and index two must be two less than"
19974 " index one."));
19975 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
19976 _("General purpose registers may not be the same"));
19977 constraint (inst.operands[Rt].reg == REG_SP
19978 || inst.operands[Rt2].reg == REG_SP,
19979 BAD_SP);
19980 constraint (inst.operands[Rt].reg == REG_PC
19981 || inst.operands[Rt2].reg == REG_PC,
19982 BAD_PC);
19983
19984 inst.instruction = 0xec000f00;
19985 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
19986 inst.instruction |= !!toQ << 20;
19987 inst.instruction |= inst.operands[Rt2].reg << 16;
19988 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
19989 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
19990 inst.instruction |= inst.operands[Rt].reg;
19991}
19992
19993static void
19994do_mve_movn (void)
19995{
19996 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19997 return;
19998
19999 if (inst.cond > COND_ALWAYS)
20000 inst.pred_insn_type = INSIDE_VPT_INSN;
20001 else
20002 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20003
20004 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20005 | N_KEY);
20006
20007 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20008 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20009 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20010 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20011 inst.instruction |= LOW4 (inst.operands[1].reg);
20012 inst.is_neon = 1;
20013
20014}
20015
5287ad62
JB
20016/* VMOV has particularly many variations. It can be one of:
20017 0. VMOV<c><q> <Qd>, <Qm>
20018 1. VMOV<c><q> <Dd>, <Dm>
20019 (Register operations, which are VORR with Rm = Rn.)
20020 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20021 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20022 (Immediate loads.)
20023 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20024 (ARM register to scalar.)
20025 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20026 (Two ARM registers to vector.)
20027 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20028 (Scalar to ARM register.)
20029 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20030 (Vector to two ARM registers.)
037e8744
JB
20031 8. VMOV.F32 <Sd>, <Sm>
20032 9. VMOV.F64 <Dd>, <Dm>
20033 (VFP register moves.)
20034 10. VMOV.F32 <Sd>, #imm
20035 11. VMOV.F64 <Dd>, #imm
20036 (VFP float immediate load.)
20037 12. VMOV <Rd>, <Sm>
20038 (VFP single to ARM reg.)
20039 13. VMOV <Sd>, <Rm>
20040 (ARM reg to VFP single.)
20041 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20042 (Two ARM regs to two VFP singles.)
20043 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20044 (Two VFP singles to two ARM regs.)
57785aa2
AV
20045 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20046 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20047 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20048 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 20049
037e8744
JB
20050 These cases can be disambiguated using neon_select_shape, except cases 1/9
20051 and 3/11 which depend on the operand type too.
5f4273c7 20052
5287ad62 20053 All the encoded bits are hardcoded by this function.
5f4273c7 20054
b7fc2769
JB
20055 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20056 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 20057
5287ad62 20058 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 20059 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
20060
20061static void
20062do_neon_mov (void)
20063{
57785aa2
AV
20064 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20065 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20066 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20067 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20068 NS_NULL);
037e8744
JB
20069 struct neon_type_el et;
20070 const char *ldconst = 0;
5287ad62 20071
037e8744 20072 switch (rs)
5287ad62 20073 {
037e8744
JB
20074 case NS_DD: /* case 1/9. */
20075 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20076 /* It is not an error here if no type is given. */
20077 inst.error = NULL;
1c1e0fe5
SP
20078
20079 /* In MVE we interpret the following instructions as same, so ignoring
20080 the following type (float) and size (64) checks.
20081 a: VMOV<c><q> <Dd>, <Dm>
20082 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20083 if ((et.type == NT_float && et.size == 64)
20084 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc
RM
20085 {
20086 do_vfp_nsyn_opcode ("fcpyd");
20087 break;
20088 }
037e8744 20089 /* fall through. */
5287ad62 20090
037e8744
JB
20091 case NS_QQ: /* case 0/1. */
20092 {
64c350f2
AV
20093 if (!check_simd_pred_availability (FALSE,
20094 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
20095 return;
20096 /* The architecture manual I have doesn't explicitly state which
20097 value the U bit should have for register->register moves, but
20098 the equivalent VORR instruction has U = 0, so do that. */
20099 inst.instruction = 0x0200110;
20100 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20101 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20102 inst.instruction |= LOW4 (inst.operands[1].reg);
20103 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20104 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20105 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20106 inst.instruction |= neon_quad (rs) << 6;
20107
20108 neon_dp_fixup (&inst);
037e8744
JB
20109 }
20110 break;
5f4273c7 20111
037e8744
JB
20112 case NS_DI: /* case 3/11. */
20113 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20114 inst.error = NULL;
20115 if (et.type == NT_float && et.size == 64)
477330fc
RM
20116 {
20117 /* case 11 (fconstd). */
20118 ldconst = "fconstd";
20119 goto encode_fconstd;
20120 }
037e8744
JB
20121 /* fall through. */
20122
20123 case NS_QI: /* case 2/3. */
64c350f2
AV
20124 if (!check_simd_pred_availability (FALSE,
20125 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 20126 return;
037e8744
JB
20127 inst.instruction = 0x0800010;
20128 neon_move_immediate ();
88714cb8 20129 neon_dp_fixup (&inst);
5287ad62 20130 break;
5f4273c7 20131
037e8744
JB
20132 case NS_SR: /* case 4. */
20133 {
477330fc
RM
20134 unsigned bcdebits = 0;
20135 int logsize;
20136 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20137 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 20138
05ac0ffb
JB
20139 /* .<size> is optional here, defaulting to .32. */
20140 if (inst.vectype.elems == 0
20141 && inst.operands[0].vectype.type == NT_invtype
20142 && inst.operands[1].vectype.type == NT_invtype)
20143 {
20144 inst.vectype.el[0].type = NT_untyped;
20145 inst.vectype.el[0].size = 32;
20146 inst.vectype.elems = 1;
20147 }
20148
477330fc
RM
20149 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20150 logsize = neon_logbits (et.size);
20151
57785aa2
AV
20152 if (et.size != 32)
20153 {
20154 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20155 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20156 return;
20157 }
20158 else
20159 {
20160 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20161 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20162 _(BAD_FPU));
20163 }
20164
20165 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20166 {
20167 if (inst.operands[1].reg == REG_SP)
20168 as_tsktsk (MVE_BAD_SP);
20169 else if (inst.operands[1].reg == REG_PC)
20170 as_tsktsk (MVE_BAD_PC);
20171 }
20172 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20173
477330fc 20174 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
20175 constraint (x >= size / et.size, _("scalar index out of range"));
20176
477330fc
RM
20177
20178 switch (et.size)
20179 {
20180 case 8: bcdebits = 0x8; break;
20181 case 16: bcdebits = 0x1; break;
20182 case 32: bcdebits = 0x0; break;
20183 default: ;
20184 }
20185
57785aa2 20186 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20187
20188 inst.instruction = 0xe000b10;
20189 do_vfp_cond_or_thumb ();
20190 inst.instruction |= LOW4 (dn) << 16;
20191 inst.instruction |= HI1 (dn) << 7;
20192 inst.instruction |= inst.operands[1].reg << 12;
20193 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
20194 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20195 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20196 }
20197 break;
5f4273c7 20198
037e8744 20199 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
20200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20201 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20202 _(BAD_FPU));
b7fc2769 20203
037e8744
JB
20204 inst.instruction = 0xc400b10;
20205 do_vfp_cond_or_thumb ();
20206 inst.instruction |= LOW4 (inst.operands[0].reg);
20207 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20208 inst.instruction |= inst.operands[1].reg << 12;
20209 inst.instruction |= inst.operands[2].reg << 16;
20210 break;
5f4273c7 20211
037e8744
JB
20212 case NS_RS: /* case 6. */
20213 {
477330fc
RM
20214 unsigned logsize;
20215 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20216 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20217 unsigned abcdebits = 0;
037e8744 20218
05ac0ffb
JB
20219 /* .<dt> is optional here, defaulting to .32. */
20220 if (inst.vectype.elems == 0
20221 && inst.operands[0].vectype.type == NT_invtype
20222 && inst.operands[1].vectype.type == NT_invtype)
20223 {
20224 inst.vectype.el[0].type = NT_untyped;
20225 inst.vectype.el[0].size = 32;
20226 inst.vectype.elems = 1;
20227 }
20228
91d6fa6a
NC
20229 et = neon_check_type (2, NS_NULL,
20230 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
20231 logsize = neon_logbits (et.size);
20232
57785aa2
AV
20233 if (et.size != 32)
20234 {
20235 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20236 && vfp_or_neon_is_neon (NEON_CHECK_CC
20237 | NEON_CHECK_ARCH) == FAIL)
20238 return;
20239 }
20240 else
20241 {
20242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20243 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20244 _(BAD_FPU));
20245 }
20246
20247 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20248 {
20249 if (inst.operands[0].reg == REG_SP)
20250 as_tsktsk (MVE_BAD_SP);
20251 else if (inst.operands[0].reg == REG_PC)
20252 as_tsktsk (MVE_BAD_PC);
20253 }
20254
20255 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20256
477330fc 20257 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 20258 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
20259
20260 switch (et.size)
20261 {
20262 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20263 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20264 case 32: abcdebits = 0x00; break;
20265 default: ;
20266 }
20267
57785aa2 20268 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20269 inst.instruction = 0xe100b10;
20270 do_vfp_cond_or_thumb ();
20271 inst.instruction |= LOW4 (dn) << 16;
20272 inst.instruction |= HI1 (dn) << 7;
20273 inst.instruction |= inst.operands[0].reg << 12;
20274 inst.instruction |= (abcdebits & 3) << 5;
20275 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 20276 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20277 }
20278 break;
5f4273c7 20279
037e8744 20280 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
20281 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20282 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20283 _(BAD_FPU));
037e8744
JB
20284
20285 inst.instruction = 0xc500b10;
20286 do_vfp_cond_or_thumb ();
20287 inst.instruction |= inst.operands[0].reg << 12;
20288 inst.instruction |= inst.operands[1].reg << 16;
20289 inst.instruction |= LOW4 (inst.operands[2].reg);
20290 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20291 break;
5f4273c7 20292
037e8744
JB
20293 case NS_FF: /* case 8 (fcpys). */
20294 do_vfp_nsyn_opcode ("fcpys");
20295 break;
5f4273c7 20296
9db2f6b4 20297 case NS_HI:
037e8744
JB
20298 case NS_FI: /* case 10 (fconsts). */
20299 ldconst = "fconsts";
4ef4710f 20300 encode_fconstd:
58ed5c38
TC
20301 if (!inst.operands[1].immisfloat)
20302 {
4ef4710f 20303 unsigned new_imm;
58ed5c38 20304 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
20305 float imm = (float) inst.operands[1].imm;
20306 memcpy (&new_imm, &imm, sizeof (float));
20307 /* But the assembly may have been written to provide an integer
20308 bit pattern that equates to a float, so check that the
20309 conversion has worked. */
20310 if (is_quarter_float (new_imm))
20311 {
20312 if (is_quarter_float (inst.operands[1].imm))
20313 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20314
20315 inst.operands[1].imm = new_imm;
20316 inst.operands[1].immisfloat = 1;
20317 }
58ed5c38
TC
20318 }
20319
037e8744 20320 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
20321 {
20322 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20323 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20324
20325 /* ARMv8.2 fp16 vmov.f16 instruction. */
20326 if (rs == NS_HI)
20327 do_scalar_fp16_v82_encode ();
477330fc 20328 }
5287ad62 20329 else
477330fc 20330 first_error (_("immediate out of range"));
037e8744 20331 break;
5f4273c7 20332
9db2f6b4 20333 case NS_RH:
037e8744
JB
20334 case NS_RF: /* case 12 (fmrs). */
20335 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20336 /* ARMv8.2 fp16 vmov.f16 instruction. */
20337 if (rs == NS_RH)
20338 do_scalar_fp16_v82_encode ();
037e8744 20339 break;
5f4273c7 20340
9db2f6b4 20341 case NS_HR:
037e8744
JB
20342 case NS_FR: /* case 13 (fmsr). */
20343 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20344 /* ARMv8.2 fp16 vmov.f16 instruction. */
20345 if (rs == NS_HR)
20346 do_scalar_fp16_v82_encode ();
037e8744 20347 break;
5f4273c7 20348
57785aa2
AV
20349 case NS_RRSS:
20350 do_mve_mov (0);
20351 break;
20352 case NS_SSRR:
20353 do_mve_mov (1);
20354 break;
20355
037e8744
JB
20356 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20357 (one of which is a list), but we have parsed four. Do some fiddling to
20358 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20359 expect. */
20360 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20361 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20362 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20363 _(BAD_FPU));
037e8744 20364 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20365 _("VFP registers must be adjacent"));
037e8744
JB
20366 inst.operands[2].imm = 2;
20367 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20368 do_vfp_nsyn_opcode ("fmrrs");
20369 break;
5f4273c7 20370
037e8744 20371 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20372 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20373 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20374 _(BAD_FPU));
037e8744 20375 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20376 _("VFP registers must be adjacent"));
037e8744
JB
20377 inst.operands[1] = inst.operands[2];
20378 inst.operands[2] = inst.operands[3];
20379 inst.operands[0].imm = 2;
20380 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20381 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20382 break;
5f4273c7 20383
4c261dff
NC
20384 case NS_NULL:
20385 /* neon_select_shape has determined that the instruction
20386 shape is wrong and has already set the error message. */
20387 break;
20388
5287ad62
JB
20389 default:
20390 abort ();
20391 }
20392}
20393
57785aa2
AV
20394static void
20395do_mve_movl (void)
20396{
20397 if (!(inst.operands[0].present && inst.operands[0].isquad
20398 && inst.operands[1].present && inst.operands[1].isquad
20399 && !inst.operands[2].present))
20400 {
20401 inst.instruction = 0;
20402 inst.cond = 0xb;
20403 if (thumb_mode)
20404 set_pred_insn_type (INSIDE_IT_INSN);
20405 do_neon_mov ();
20406 return;
20407 }
20408
20409 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20410 return;
20411
20412 if (inst.cond != COND_ALWAYS)
20413 inst.pred_insn_type = INSIDE_VPT_INSN;
20414
20415 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20416 | N_S16 | N_U16 | N_KEY);
20417
20418 inst.instruction |= (et.type == NT_unsigned) << 28;
20419 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20420 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20421 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20422 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20423 inst.instruction |= LOW4 (inst.operands[1].reg);
20424 inst.is_neon = 1;
20425}
20426
5287ad62
JB
20427static void
20428do_neon_rshift_round_imm (void)
20429{
64c350f2 20430 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20431 return;
20432
20433 enum neon_shape rs;
20434 struct neon_type_el et;
20435
20436 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20437 {
20438 rs = neon_select_shape (NS_QQI, NS_NULL);
20439 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20440 }
20441 else
20442 {
20443 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20444 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20445 }
5287ad62
JB
20446 int imm = inst.operands[2].imm;
20447
20448 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20449 if (imm == 0)
20450 {
20451 inst.operands[2].present = 0;
20452 do_neon_mov ();
20453 return;
20454 }
20455
20456 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20457 _("immediate out of range for shift"));
037e8744 20458 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20459 et.size - imm);
5287ad62
JB
20460}
20461
9db2f6b4
RL
20462static void
20463do_neon_movhf (void)
20464{
20465 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20466 constraint (rs != NS_HH, _("invalid suffix"));
20467
7bdf778b
ASDV
20468 if (inst.cond != COND_ALWAYS)
20469 {
20470 if (thumb_mode)
20471 {
20472 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20473 " the behaviour is UNPREDICTABLE"));
20474 }
20475 else
20476 {
20477 inst.error = BAD_COND;
20478 return;
20479 }
20480 }
20481
9db2f6b4
RL
20482 do_vfp_sp_monadic ();
20483
20484 inst.is_neon = 1;
20485 inst.instruction |= 0xf0000000;
20486}
20487
5287ad62
JB
20488static void
20489do_neon_movl (void)
20490{
20491 struct neon_type_el et = neon_check_type (2, NS_QD,
20492 N_EQK | N_DBL, N_SU_32 | N_KEY);
20493 unsigned sizebits = et.size >> 3;
20494 inst.instruction |= sizebits << 19;
20495 neon_two_same (0, et.type == NT_unsigned, -1);
20496}
20497
20498static void
20499do_neon_trn (void)
20500{
037e8744 20501 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20502 struct neon_type_el et = neon_check_type (2, rs,
20503 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20504 NEON_ENCODE (INTEGER, inst);
037e8744 20505 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20506}
20507
20508static void
20509do_neon_zip_uzp (void)
20510{
037e8744 20511 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20512 struct neon_type_el et = neon_check_type (2, rs,
20513 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20514 if (rs == NS_DD && et.size == 32)
20515 {
20516 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20517 inst.instruction = N_MNEM_vtrn;
20518 do_neon_trn ();
20519 return;
20520 }
037e8744 20521 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20522}
20523
20524static void
20525do_neon_sat_abs_neg (void)
20526{
64c350f2 20527 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20528 return;
20529
20530 enum neon_shape rs;
20531 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20532 rs = neon_select_shape (NS_QQ, NS_NULL);
20533 else
20534 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20535 struct neon_type_el et = neon_check_type (2, rs,
20536 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20537 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20538}
20539
20540static void
20541do_neon_pair_long (void)
20542{
037e8744 20543 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20544 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20545 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20546 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20547 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20548}
20549
20550static void
20551do_neon_recip_est (void)
20552{
037e8744 20553 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20554 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20555 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20556 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20557 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20558}
20559
20560static void
20561do_neon_cls (void)
20562{
64c350f2 20563 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20564 return;
20565
20566 enum neon_shape rs;
20567 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20568 rs = neon_select_shape (NS_QQ, NS_NULL);
20569 else
20570 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20571
5287ad62
JB
20572 struct neon_type_el et = neon_check_type (2, rs,
20573 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20574 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20575}
20576
20577static void
20578do_neon_clz (void)
20579{
64c350f2 20580 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20581 return;
20582
20583 enum neon_shape rs;
20584 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20585 rs = neon_select_shape (NS_QQ, NS_NULL);
20586 else
20587 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20588
5287ad62
JB
20589 struct neon_type_el et = neon_check_type (2, rs,
20590 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20591 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20592}
20593
20594static void
20595do_neon_cnt (void)
20596{
037e8744 20597 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20598 struct neon_type_el et = neon_check_type (2, rs,
20599 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20600 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20601}
20602
20603static void
20604do_neon_swp (void)
20605{
037e8744
JB
20606 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20607 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20608}
20609
20610static void
20611do_neon_tbl_tbx (void)
20612{
20613 unsigned listlenbits;
dcbf9037 20614 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20615
5287ad62
JB
20616 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20617 {
dcbf9037 20618 first_error (_("bad list length for table lookup"));
5287ad62
JB
20619 return;
20620 }
5f4273c7 20621
5287ad62
JB
20622 listlenbits = inst.operands[1].imm - 1;
20623 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20624 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20625 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20626 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20627 inst.instruction |= LOW4 (inst.operands[2].reg);
20628 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20629 inst.instruction |= listlenbits << 8;
5f4273c7 20630
88714cb8 20631 neon_dp_fixup (&inst);
5287ad62
JB
20632}
20633
20634static void
20635do_neon_ldm_stm (void)
20636{
ef8f595f
MI
20637 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20638 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20639 _(BAD_FPU));
5287ad62
JB
20640 /* P, U and L bits are part of bitmask. */
20641 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20642 unsigned offsetbits = inst.operands[1].imm * 2;
20643
037e8744
JB
20644 if (inst.operands[1].issingle)
20645 {
20646 do_vfp_nsyn_ldm_stm (is_dbmode);
20647 return;
20648 }
20649
5287ad62 20650 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20651 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20652
20653 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20654 _("register list must contain at least 1 and at most 16 "
20655 "registers"));
5287ad62
JB
20656
20657 inst.instruction |= inst.operands[0].reg << 16;
20658 inst.instruction |= inst.operands[0].writeback << 21;
20659 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20660 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20661
20662 inst.instruction |= offsetbits;
5f4273c7 20663
037e8744 20664 do_vfp_cond_or_thumb ();
5287ad62
JB
20665}
20666
ef8f595f
MI
20667static void
20668do_vfp_nsyn_pop (void)
20669{
20670 nsyn_insert_sp ();
20671 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20672 return do_vfp_nsyn_opcode ("vldm");
20673 }
20674
20675 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20676 _(BAD_FPU));
20677
20678 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20679 _("register list must contain at least 1 and at most 16 "
20680 "registers"));
20681
20682 if (inst.operands[1].issingle)
20683 do_vfp_nsyn_opcode ("fldmias");
20684 else
20685 do_vfp_nsyn_opcode ("fldmiad");
20686}
20687
20688static void
20689do_vfp_nsyn_push (void)
20690{
20691 nsyn_insert_sp ();
20692 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20693 return do_vfp_nsyn_opcode ("vstmdb");
20694 }
20695
20696 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20697 _(BAD_FPU));
20698
20699 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20700 _("register list must contain at least 1 and at most 16 "
20701 "registers"));
20702
20703 if (inst.operands[1].issingle)
20704 do_vfp_nsyn_opcode ("fstmdbs");
20705 else
20706 do_vfp_nsyn_opcode ("fstmdbd");
20707}
20708
20709
5287ad62
JB
20710static void
20711do_neon_ldr_str (void)
20712{
5287ad62 20713 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20714
6844b2c2
MGD
20715 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20716 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20717 if (!is_ldr
6844b2c2 20718 && inst.operands[1].reg == REG_PC
ba86b375 20719 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20720 {
94dcf8bf 20721 if (thumb_mode)
6844b2c2 20722 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20723 else if (warn_on_deprecated)
5c3696f8 20724 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20725 }
20726
037e8744
JB
20727 if (inst.operands[0].issingle)
20728 {
cd2f129f 20729 if (is_ldr)
477330fc 20730 do_vfp_nsyn_opcode ("flds");
cd2f129f 20731 else
477330fc 20732 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20733
20734 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20735 if (inst.vectype.el[0].size == 16)
20736 do_scalar_fp16_v82_encode ();
5287ad62
JB
20737 }
20738 else
5287ad62 20739 {
cd2f129f 20740 if (is_ldr)
477330fc 20741 do_vfp_nsyn_opcode ("fldd");
5287ad62 20742 else
477330fc 20743 do_vfp_nsyn_opcode ("fstd");
5287ad62 20744 }
5287ad62
JB
20745}
20746
32c36c3c
AV
20747static void
20748do_t_vldr_vstr_sysreg (void)
20749{
20750 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20751 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20752
20753 /* Use of PC is UNPREDICTABLE. */
20754 if (inst.operands[1].reg == REG_PC)
20755 inst.error = _("Use of PC here is UNPREDICTABLE");
20756
20757 if (inst.operands[1].immisreg)
20758 inst.error = _("instruction does not accept register index");
20759
20760 if (!inst.operands[1].isreg)
20761 inst.error = _("instruction does not accept PC-relative addressing");
20762
20763 if (abs (inst.operands[1].imm) >= (1 << 7))
20764 inst.error = _("immediate value out of range");
20765
20766 inst.instruction = 0xec000f80;
20767 if (is_vldr)
20768 inst.instruction |= 1 << sysreg_vldr_bitno;
20769 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20770 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20771 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20772}
20773
20774static void
20775do_vldr_vstr (void)
20776{
20777 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20778
20779 /* VLDR/VSTR (System Register). */
20780 if (sysreg_op)
20781 {
20782 if (!mark_feature_used (&arm_ext_v8_1m_main))
20783 as_bad (_("Instruction not permitted on this architecture"));
20784
20785 do_t_vldr_vstr_sysreg ();
20786 }
20787 /* VLDR/VSTR. */
20788 else
20789 {
ef8f595f
MI
20790 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20791 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
32c36c3c
AV
20792 as_bad (_("Instruction not permitted on this architecture"));
20793 do_neon_ldr_str ();
20794 }
20795}
20796
5287ad62
JB
20797/* "interleave" version also handles non-interleaving register VLD1/VST1
20798 instructions. */
20799
20800static void
20801do_neon_ld_st_interleave (void)
20802{
037e8744 20803 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20804 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20805 unsigned alignbits = 0;
20806 unsigned idx;
20807 /* The bits in this table go:
20808 0: register stride of one (0) or two (1)
20809 1,2: register list length, minus one (1, 2, 3, 4).
20810 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20811 We use -1 for invalid entries. */
20812 const int typetable[] =
20813 {
20814 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20815 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20816 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20817 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20818 };
20819 int typebits;
20820
dcbf9037
JB
20821 if (et.type == NT_invtype)
20822 return;
20823
5287ad62
JB
20824 if (inst.operands[1].immisalign)
20825 switch (inst.operands[1].imm >> 8)
20826 {
20827 case 64: alignbits = 1; break;
20828 case 128:
477330fc 20829 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20830 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20831 goto bad_alignment;
20832 alignbits = 2;
20833 break;
5287ad62 20834 case 256:
477330fc
RM
20835 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20836 goto bad_alignment;
20837 alignbits = 3;
20838 break;
5287ad62
JB
20839 default:
20840 bad_alignment:
477330fc
RM
20841 first_error (_("bad alignment"));
20842 return;
5287ad62
JB
20843 }
20844
20845 inst.instruction |= alignbits << 4;
20846 inst.instruction |= neon_logbits (et.size) << 6;
20847
20848 /* Bits [4:6] of the immediate in a list specifier encode register stride
20849 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20850 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20851 up the right value for "type" in a table based on this value and the given
20852 list style, then stick it back. */
20853 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20854 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20855
20856 typebits = typetable[idx];
5f4273c7 20857
5287ad62 20858 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20859 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20860 BAD_EL_TYPE);
5287ad62
JB
20861
20862 inst.instruction &= ~0xf00;
20863 inst.instruction |= typebits << 8;
20864}
20865
20866/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20867 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20868 otherwise. The variable arguments are a list of pairs of legal (size, align)
20869 values, terminated with -1. */
20870
20871static int
aa8a0863 20872neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20873{
20874 va_list ap;
20875 int result = FAIL, thissize, thisalign;
5f4273c7 20876
5287ad62
JB
20877 if (!inst.operands[1].immisalign)
20878 {
aa8a0863 20879 *do_alignment = 0;
5287ad62
JB
20880 return SUCCESS;
20881 }
5f4273c7 20882
aa8a0863 20883 va_start (ap, do_alignment);
5287ad62
JB
20884
20885 do
20886 {
20887 thissize = va_arg (ap, int);
20888 if (thissize == -1)
477330fc 20889 break;
5287ad62
JB
20890 thisalign = va_arg (ap, int);
20891
20892 if (size == thissize && align == thisalign)
477330fc 20893 result = SUCCESS;
5287ad62
JB
20894 }
20895 while (result != SUCCESS);
20896
20897 va_end (ap);
20898
20899 if (result == SUCCESS)
aa8a0863 20900 *do_alignment = 1;
5287ad62 20901 else
dcbf9037 20902 first_error (_("unsupported alignment for instruction"));
5f4273c7 20903
5287ad62
JB
20904 return result;
20905}
20906
20907static void
20908do_neon_ld_st_lane (void)
20909{
037e8744 20910 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20911 int align_good, do_alignment = 0;
5287ad62
JB
20912 int logsize = neon_logbits (et.size);
20913 int align = inst.operands[1].imm >> 8;
20914 int n = (inst.instruction >> 8) & 3;
20915 int max_el = 64 / et.size;
5f4273c7 20916
dcbf9037
JB
20917 if (et.type == NT_invtype)
20918 return;
5f4273c7 20919
5287ad62 20920 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20921 _("bad list length"));
5287ad62 20922 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20923 _("scalar index out of range"));
5287ad62 20924 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20925 && et.size == 8,
20926 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20927
5287ad62
JB
20928 switch (n)
20929 {
20930 case 0: /* VLD1 / VST1. */
aa8a0863 20931 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20932 32, 32, -1);
5287ad62 20933 if (align_good == FAIL)
477330fc 20934 return;
aa8a0863 20935 if (do_alignment)
477330fc
RM
20936 {
20937 unsigned alignbits = 0;
20938 switch (et.size)
20939 {
20940 case 16: alignbits = 0x1; break;
20941 case 32: alignbits = 0x3; break;
20942 default: ;
20943 }
20944 inst.instruction |= alignbits << 4;
20945 }
5287ad62
JB
20946 break;
20947
20948 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20949 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20950 16, 32, 32, 64, -1);
5287ad62 20951 if (align_good == FAIL)
477330fc 20952 return;
aa8a0863 20953 if (do_alignment)
477330fc 20954 inst.instruction |= 1 << 4;
5287ad62
JB
20955 break;
20956
20957 case 2: /* VLD3 / VST3. */
20958 constraint (inst.operands[1].immisalign,
477330fc 20959 _("can't use alignment with this instruction"));
5287ad62
JB
20960 break;
20961
20962 case 3: /* VLD4 / VST4. */
aa8a0863 20963 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20964 16, 64, 32, 64, 32, 128, -1);
5287ad62 20965 if (align_good == FAIL)
477330fc 20966 return;
aa8a0863 20967 if (do_alignment)
477330fc
RM
20968 {
20969 unsigned alignbits = 0;
20970 switch (et.size)
20971 {
20972 case 8: alignbits = 0x1; break;
20973 case 16: alignbits = 0x1; break;
20974 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20975 default: ;
20976 }
20977 inst.instruction |= alignbits << 4;
20978 }
5287ad62
JB
20979 break;
20980
20981 default: ;
20982 }
20983
20984 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
20985 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20986 inst.instruction |= 1 << (4 + logsize);
5f4273c7 20987
5287ad62
JB
20988 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
20989 inst.instruction |= logsize << 10;
20990}
20991
20992/* Encode single n-element structure to all lanes VLD<n> instructions. */
20993
20994static void
20995do_neon_ld_dup (void)
20996{
037e8744 20997 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20998 int align_good, do_alignment = 0;
5287ad62 20999
dcbf9037
JB
21000 if (et.type == NT_invtype)
21001 return;
21002
5287ad62
JB
21003 switch ((inst.instruction >> 8) & 3)
21004 {
21005 case 0: /* VLD1. */
9c2799c2 21006 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 21007 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 21008 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 21009 if (align_good == FAIL)
477330fc 21010 return;
5287ad62 21011 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
21012 {
21013 case 1: break;
21014 case 2: inst.instruction |= 1 << 5; break;
21015 default: first_error (_("bad list length")); return;
21016 }
5287ad62
JB
21017 inst.instruction |= neon_logbits (et.size) << 6;
21018 break;
21019
21020 case 1: /* VLD2. */
21021 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
21022 &do_alignment, 8, 16, 16, 32, 32, 64,
21023 -1);
5287ad62 21024 if (align_good == FAIL)
477330fc 21025 return;
5287ad62 21026 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 21027 _("bad list length"));
5287ad62 21028 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21029 inst.instruction |= 1 << 5;
5287ad62
JB
21030 inst.instruction |= neon_logbits (et.size) << 6;
21031 break;
21032
21033 case 2: /* VLD3. */
21034 constraint (inst.operands[1].immisalign,
477330fc 21035 _("can't use alignment with this instruction"));
5287ad62 21036 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 21037 _("bad list length"));
5287ad62 21038 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21039 inst.instruction |= 1 << 5;
5287ad62
JB
21040 inst.instruction |= neon_logbits (et.size) << 6;
21041 break;
21042
21043 case 3: /* VLD4. */
21044 {
477330fc 21045 int align = inst.operands[1].imm >> 8;
aa8a0863 21046 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
21047 16, 64, 32, 64, 32, 128, -1);
21048 if (align_good == FAIL)
21049 return;
21050 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21051 _("bad list length"));
21052 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21053 inst.instruction |= 1 << 5;
21054 if (et.size == 32 && align == 128)
21055 inst.instruction |= 0x3 << 6;
21056 else
21057 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
21058 }
21059 break;
21060
21061 default: ;
21062 }
21063
aa8a0863 21064 inst.instruction |= do_alignment << 4;
5287ad62
JB
21065}
21066
21067/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21068 apart from bits [11:4]. */
21069
21070static void
21071do_neon_ldx_stx (void)
21072{
b1a769ed
DG
21073 if (inst.operands[1].isreg)
21074 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21075
5287ad62
JB
21076 switch (NEON_LANE (inst.operands[0].imm))
21077 {
21078 case NEON_INTERLEAVE_LANES:
88714cb8 21079 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
21080 do_neon_ld_st_interleave ();
21081 break;
5f4273c7 21082
5287ad62 21083 case NEON_ALL_LANES:
88714cb8 21084 NEON_ENCODE (DUP, inst);
2d51fb74
JB
21085 if (inst.instruction == N_INV)
21086 {
21087 first_error ("only loads support such operands");
21088 break;
21089 }
5287ad62
JB
21090 do_neon_ld_dup ();
21091 break;
5f4273c7 21092
5287ad62 21093 default:
88714cb8 21094 NEON_ENCODE (LANE, inst);
5287ad62
JB
21095 do_neon_ld_st_lane ();
21096 }
21097
21098 /* L bit comes from bit mask. */
21099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21101 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 21102
5287ad62
JB
21103 if (inst.operands[1].postind)
21104 {
21105 int postreg = inst.operands[1].imm & 0xf;
21106 constraint (!inst.operands[1].immisreg,
477330fc 21107 _("post-index must be a register"));
5287ad62 21108 constraint (postreg == 0xd || postreg == 0xf,
477330fc 21109 _("bad register for post-index"));
5287ad62
JB
21110 inst.instruction |= postreg;
21111 }
4f2374c7 21112 else
5287ad62 21113 {
4f2374c7 21114 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
21115 constraint (inst.relocs[0].exp.X_op != O_constant
21116 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
21117 BAD_ADDR_MODE);
21118
21119 if (inst.operands[1].writeback)
21120 {
21121 inst.instruction |= 0xd;
21122 }
21123 else
21124 inst.instruction |= 0xf;
5287ad62 21125 }
5f4273c7 21126
5287ad62
JB
21127 if (thumb_mode)
21128 inst.instruction |= 0xf9000000;
21129 else
21130 inst.instruction |= 0xf4000000;
21131}
33399f07
MGD
21132
21133/* FP v8. */
21134static void
21135do_vfp_nsyn_fpv8 (enum neon_shape rs)
21136{
a715796b
TG
21137 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21138 D register operands. */
21139 if (neon_shape_class[rs] == SC_DOUBLE)
21140 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21141 _(BAD_FPU));
21142
33399f07
MGD
21143 NEON_ENCODE (FPV8, inst);
21144
9db2f6b4
RL
21145 if (rs == NS_FFF || rs == NS_HHH)
21146 {
21147 do_vfp_sp_dyadic ();
21148
21149 /* ARMv8.2 fp16 instruction. */
21150 if (rs == NS_HHH)
21151 do_scalar_fp16_v82_encode ();
21152 }
33399f07
MGD
21153 else
21154 do_vfp_dp_rd_rn_rm ();
21155
21156 if (rs == NS_DDD)
21157 inst.instruction |= 0x100;
21158
21159 inst.instruction |= 0xf0000000;
21160}
21161
21162static void
21163do_vsel (void)
21164{
5ee91343 21165 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
21166
21167 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21168 first_error (_("invalid instruction shape"));
21169}
21170
73924fbc
MGD
21171static void
21172do_vmaxnm (void)
21173{
935295b5
AV
21174 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21175 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
21176
21177 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21178 return;
21179
64c350f2 21180 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
21181 return;
21182
cc933301 21183 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
21184}
21185
30bdf752
MGD
21186static void
21187do_vrint_1 (enum neon_cvt_mode mode)
21188{
9db2f6b4 21189 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
21190 struct neon_type_el et;
21191
21192 if (rs == NS_NULL)
21193 return;
21194
a715796b
TG
21195 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21196 D register operands. */
21197 if (neon_shape_class[rs] == SC_DOUBLE)
21198 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21199 _(BAD_FPU));
21200
9db2f6b4
RL
21201 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21202 | N_VFP);
30bdf752
MGD
21203 if (et.type != NT_invtype)
21204 {
21205 /* VFP encodings. */
21206 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21207 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 21208 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
21209
21210 NEON_ENCODE (FPV8, inst);
9db2f6b4 21211 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
21212 do_vfp_sp_monadic ();
21213 else
21214 do_vfp_dp_rd_rm ();
21215
21216 switch (mode)
21217 {
21218 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21219 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21220 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21221 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21222 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21223 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21224 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21225 default: abort ();
21226 }
21227
21228 inst.instruction |= (rs == NS_DD) << 8;
21229 do_vfp_cond_or_thumb ();
9db2f6b4
RL
21230
21231 /* ARMv8.2 fp16 vrint instruction. */
21232 if (rs == NS_HH)
21233 do_scalar_fp16_v82_encode ();
30bdf752
MGD
21234 }
21235 else
21236 {
21237 /* Neon encodings (or something broken...). */
21238 inst.error = NULL;
cc933301 21239 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
21240
21241 if (et.type == NT_invtype)
21242 return;
21243
64c350f2
AV
21244 if (!check_simd_pred_availability (TRUE,
21245 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
21246 return;
21247
a710b305
AV
21248 NEON_ENCODE (FLOAT, inst);
21249
30bdf752
MGD
21250 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21251 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21252 inst.instruction |= LOW4 (inst.operands[1].reg);
21253 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21254 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
21255 /* Mask off the original size bits and reencode them. */
21256 inst.instruction = ((inst.instruction & 0xfff3ffff)
21257 | neon_logbits (et.size) << 18);
21258
30bdf752
MGD
21259 switch (mode)
21260 {
21261 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21262 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21263 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21264 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21265 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21266 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21267 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21268 default: abort ();
21269 }
21270
21271 if (thumb_mode)
21272 inst.instruction |= 0xfc000000;
21273 else
21274 inst.instruction |= 0xf0000000;
21275 }
21276}
21277
21278static void
21279do_vrintx (void)
21280{
21281 do_vrint_1 (neon_cvt_mode_x);
21282}
21283
21284static void
21285do_vrintz (void)
21286{
21287 do_vrint_1 (neon_cvt_mode_z);
21288}
21289
21290static void
21291do_vrintr (void)
21292{
21293 do_vrint_1 (neon_cvt_mode_r);
21294}
21295
21296static void
21297do_vrinta (void)
21298{
21299 do_vrint_1 (neon_cvt_mode_a);
21300}
21301
21302static void
21303do_vrintn (void)
21304{
21305 do_vrint_1 (neon_cvt_mode_n);
21306}
21307
21308static void
21309do_vrintp (void)
21310{
21311 do_vrint_1 (neon_cvt_mode_p);
21312}
21313
21314static void
21315do_vrintm (void)
21316{
21317 do_vrint_1 (neon_cvt_mode_m);
21318}
21319
c28eeff2
SN
21320static unsigned
21321neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21322{
21323 unsigned regno = NEON_SCALAR_REG (opnd);
21324 unsigned elno = NEON_SCALAR_INDEX (opnd);
21325
21326 if (elsize == 16 && elno < 2 && regno < 16)
21327 return regno | (elno << 4);
21328 else if (elsize == 32 && elno == 0)
21329 return regno;
21330
21331 first_error (_("scalar out of range"));
21332 return 0;
21333}
21334
21335static void
21336do_vcmla (void)
21337{
5d281bf0
AV
21338 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21339 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21340 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21341 constraint (inst.relocs[0].exp.X_op != O_constant,
21342 _("expression too complex"));
21343 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21344 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21345 _("immediate out of range"));
21346 rot /= 90;
5d281bf0 21347
64c350f2
AV
21348 if (!check_simd_pred_availability (TRUE,
21349 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21350 return;
21351
c28eeff2
SN
21352 if (inst.operands[2].isscalar)
21353 {
5d281bf0
AV
21354 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21355 first_error (_("invalid instruction shape"));
c28eeff2
SN
21356 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21357 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21358 N_KEY | N_F16 | N_F32).size;
21359 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21360 inst.is_neon = 1;
21361 inst.instruction = 0xfe000800;
21362 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21363 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21364 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21365 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21366 inst.instruction |= LOW4 (m);
21367 inst.instruction |= HI1 (m) << 5;
21368 inst.instruction |= neon_quad (rs) << 6;
21369 inst.instruction |= rot << 20;
21370 inst.instruction |= (size == 32) << 23;
21371 }
21372 else
21373 {
5d281bf0
AV
21374 enum neon_shape rs;
21375 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21376 rs = neon_select_shape (NS_QQQI, NS_NULL);
21377 else
21378 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21379
c28eeff2
SN
21380 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21381 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21382 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21383 && (inst.operands[0].reg == inst.operands[1].reg
21384 || inst.operands[0].reg == inst.operands[2].reg))
21385 as_tsktsk (BAD_MVE_SRCDEST);
21386
c28eeff2
SN
21387 neon_three_same (neon_quad (rs), 0, -1);
21388 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21389 inst.instruction |= 0xfc200800;
21390 inst.instruction |= rot << 23;
21391 inst.instruction |= (size == 32) << 20;
21392 }
21393}
21394
21395static void
21396do_vcadd (void)
21397{
5d281bf0
AV
21398 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21399 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21400 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21401 constraint (inst.relocs[0].exp.X_op != O_constant,
21402 _("expression too complex"));
5d281bf0 21403
e2b0ab59 21404 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21405 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21406 enum neon_shape rs;
21407 struct neon_type_el et;
21408 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21409 {
21410 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21411 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21412 }
21413 else
21414 {
21415 rs = neon_select_shape (NS_QQQI, NS_NULL);
21416 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21417 | N_I16 | N_I32);
21418 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21419 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21420 "operand makes instruction UNPREDICTABLE"));
21421 }
21422
21423 if (et.type == NT_invtype)
21424 return;
21425
64c350f2
AV
21426 if (!check_simd_pred_availability (et.type == NT_float,
21427 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21428 return;
21429
21430 if (et.type == NT_float)
21431 {
21432 neon_three_same (neon_quad (rs), 0, -1);
21433 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21434 inst.instruction |= 0xfc800800;
21435 inst.instruction |= (rot == 270) << 24;
21436 inst.instruction |= (et.size == 32) << 20;
21437 }
21438 else
21439 {
21440 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21441 inst.instruction = 0xfe000f00;
21442 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21443 inst.instruction |= neon_logbits (et.size) << 20;
21444 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21445 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21446 inst.instruction |= (rot == 270) << 12;
21447 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21448 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21449 inst.instruction |= LOW4 (inst.operands[2].reg);
21450 inst.is_neon = 1;
21451 }
c28eeff2
SN
21452}
21453
c604a79a
JW
21454/* Dot Product instructions encoding support. */
21455
21456static void
21457do_neon_dotproduct (int unsigned_p)
21458{
21459 enum neon_shape rs;
21460 unsigned scalar_oprd2 = 0;
21461 int high8;
21462
21463 if (inst.cond != COND_ALWAYS)
21464 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21465 "is UNPREDICTABLE"));
21466
21467 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21468 _(BAD_FPU));
21469
21470 /* Dot Product instructions are in three-same D/Q register format or the third
21471 operand can be a scalar index register. */
21472 if (inst.operands[2].isscalar)
21473 {
21474 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21475 high8 = 0xfe000000;
21476 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21477 }
21478 else
21479 {
21480 high8 = 0xfc000000;
21481 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21482 }
21483
21484 if (unsigned_p)
21485 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21486 else
21487 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21488
21489 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21490 Product instruction, so we pass 0 as the "ubit" parameter. And the
21491 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21492 neon_three_same (neon_quad (rs), 0, 32);
21493
21494 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21495 different NEON three-same encoding. */
21496 inst.instruction &= 0x00ffffff;
21497 inst.instruction |= high8;
21498 /* Encode 'U' bit which indicates signedness. */
21499 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21500 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21501 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21502 the instruction encoding. */
21503 if (inst.operands[2].isscalar)
21504 {
21505 inst.instruction &= 0xffffffd0;
21506 inst.instruction |= LOW4 (scalar_oprd2);
21507 inst.instruction |= HI1 (scalar_oprd2) << 5;
21508 }
21509}
21510
21511/* Dot Product instructions for signed integer. */
21512
21513static void
21514do_neon_dotproduct_s (void)
21515{
21516 return do_neon_dotproduct (0);
21517}
21518
21519/* Dot Product instructions for unsigned integer. */
21520
21521static void
21522do_neon_dotproduct_u (void)
21523{
21524 return do_neon_dotproduct (1);
21525}
21526
616ce08e
MM
21527static void
21528do_vusdot (void)
21529{
21530 enum neon_shape rs;
21531 set_pred_insn_type (OUTSIDE_PRED_INSN);
21532 if (inst.operands[2].isscalar)
21533 {
21534 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21535 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21536
21537 inst.instruction |= (1 << 25);
21538 int index = inst.operands[2].reg & 0xf;
21539 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21540 inst.operands[2].reg >>= 4;
21541 constraint (!(inst.operands[2].reg < 16),
21542 _("indexed register must be less than 16"));
21543 neon_three_args (rs == NS_QQS);
21544 inst.instruction |= (index << 5);
21545 }
21546 else
21547 {
21548 inst.instruction |= (1 << 21);
21549 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21550 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21551 neon_three_args (rs == NS_QQQ);
21552 }
21553}
21554
21555static void
21556do_vsudot (void)
21557{
21558 enum neon_shape rs;
21559 set_pred_insn_type (OUTSIDE_PRED_INSN);
21560 if (inst.operands[2].isscalar)
21561 {
21562 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21563 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21564
21565 inst.instruction |= (1 << 25);
21566 int index = inst.operands[2].reg & 0xf;
21567 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21568 inst.operands[2].reg >>= 4;
21569 constraint (!(inst.operands[2].reg < 16),
21570 _("indexed register must be less than 16"));
21571 neon_three_args (rs == NS_QQS);
21572 inst.instruction |= (index << 5);
21573 }
21574}
21575
21576static void
21577do_vsmmla (void)
21578{
21579 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21580 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21581
21582 set_pred_insn_type (OUTSIDE_PRED_INSN);
21583
21584 neon_three_args (1);
21585
21586}
21587
21588static void
21589do_vummla (void)
21590{
21591 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21592 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21593
21594 set_pred_insn_type (OUTSIDE_PRED_INSN);
21595
21596 neon_three_args (1);
21597
21598}
21599
4934a27c
MM
21600static void
21601check_cde_operand (size_t index, int is_dual)
21602{
21603 unsigned Rx = inst.operands[index].reg;
21604 bfd_boolean isvec = inst.operands[index].isvec;
21605 if (is_dual == 0 && thumb_mode)
21606 constraint (
21607 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21608 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21609 else
21610 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21611 _("Register must be an even register between r0-r10."));
21612}
21613
21614static bfd_boolean
21615cde_coproc_enabled (unsigned coproc)
21616{
21617 switch (coproc)
21618 {
21619 case 0: return mark_feature_used (&arm_ext_cde0);
21620 case 1: return mark_feature_used (&arm_ext_cde1);
21621 case 2: return mark_feature_used (&arm_ext_cde2);
21622 case 3: return mark_feature_used (&arm_ext_cde3);
21623 case 4: return mark_feature_used (&arm_ext_cde4);
21624 case 5: return mark_feature_used (&arm_ext_cde5);
21625 case 6: return mark_feature_used (&arm_ext_cde6);
21626 case 7: return mark_feature_used (&arm_ext_cde7);
21627 default: return FALSE;
21628 }
21629}
21630
21631#define cde_coproc_pos 8
21632static void
21633cde_handle_coproc (void)
21634{
21635 unsigned coproc = inst.operands[0].reg;
21636 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21637 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21638 inst.instruction |= coproc << cde_coproc_pos;
21639}
21640#undef cde_coproc_pos
21641
21642static void
21643cxn_handle_predication (bfd_boolean is_accum)
21644{
21645 /* This function essentially checks for a suffix, not whether the instruction
21646 is inside an IT block or not.
21647 The CX* instructions should never have a conditional suffix -- this is not
21648 mentioned in the syntax. */
21649 if (conditional_insn ())
21650 inst.error = BAD_SYNTAX;
21651 /* Here we ensure that if the current element */
21652 else if (is_accum)
21653 set_pred_insn_type (NEUTRAL_IT_NO_VPT_INSN);
21654 else
21655 set_pred_insn_type (OUTSIDE_PRED_INSN);
21656}
21657
21658static void
21659do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21660{
21661
21662 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21663
21664 unsigned imm, Rd;
21665
21666 Rd = inst.operands[1].reg;
21667 check_cde_operand (1, is_dual);
21668
21669 if (is_dual == 1)
21670 {
21671 constraint (inst.operands[2].reg != Rd + 1,
21672 _("cx1d requires consecutive destination registers."));
21673 imm = inst.operands[3].imm;
21674 }
21675 else if (is_dual == 0)
21676 imm = inst.operands[2].imm;
21677 else
21678 abort ();
21679
21680 inst.instruction |= Rd << 12;
21681 inst.instruction |= (imm & 0x1F80) << 9;
21682 inst.instruction |= (imm & 0x0040) << 1;
21683 inst.instruction |= (imm & 0x003f);
21684
21685 cde_handle_coproc ();
21686 cxn_handle_predication (is_accum);
21687}
21688
21689static void
21690do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21691{
21692
21693 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21694
21695 unsigned imm, Rd, Rn;
21696
21697 Rd = inst.operands[1].reg;
21698
21699 if (is_dual == 1)
21700 {
21701 constraint (inst.operands[2].reg != Rd + 1,
21702 _("cx2d requires consecutive destination registers."));
21703 imm = inst.operands[4].imm;
21704 Rn = inst.operands[3].reg;
21705 }
21706 else if (is_dual == 0)
21707 {
21708 imm = inst.operands[3].imm;
21709 Rn = inst.operands[2].reg;
21710 }
21711 else
21712 abort ();
21713
21714 check_cde_operand (2 + is_dual, /* is_dual = */0);
21715 check_cde_operand (1, is_dual);
21716
21717 inst.instruction |= Rd << 12;
21718 inst.instruction |= Rn << 16;
21719
21720 inst.instruction |= (imm & 0x0380) << 13;
21721 inst.instruction |= (imm & 0x0040) << 1;
21722 inst.instruction |= (imm & 0x003f);
21723
21724 cde_handle_coproc ();
21725 cxn_handle_predication (is_accum);
21726}
21727
21728static void
21729do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21730{
21731
21732 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21733
21734 unsigned imm, Rd, Rn, Rm;
21735
21736 Rd = inst.operands[1].reg;
21737
21738 if (is_dual == 1)
21739 {
21740 constraint (inst.operands[2].reg != Rd + 1,
21741 _("cx3d requires consecutive destination registers."));
21742 imm = inst.operands[5].imm;
21743 Rn = inst.operands[3].reg;
21744 Rm = inst.operands[4].reg;
21745 }
21746 else if (is_dual == 0)
21747 {
21748 imm = inst.operands[4].imm;
21749 Rn = inst.operands[2].reg;
21750 Rm = inst.operands[3].reg;
21751 }
21752 else
21753 abort ();
21754
21755 check_cde_operand (1, is_dual);
21756 check_cde_operand (2 + is_dual, /* is_dual = */0);
21757 check_cde_operand (3 + is_dual, /* is_dual = */0);
21758
21759 inst.instruction |= Rd;
21760 inst.instruction |= Rn << 16;
21761 inst.instruction |= Rm << 12;
21762
21763 inst.instruction |= (imm & 0x0038) << 17;
21764 inst.instruction |= (imm & 0x0004) << 5;
21765 inst.instruction |= (imm & 0x0003) << 4;
21766
21767 cde_handle_coproc ();
21768 cxn_handle_predication (is_accum);
21769}
21770
21771static void
21772do_cx1 (void)
21773{
21774 return do_custom_instruction_1 (0, 0);
21775}
21776
21777static void
21778do_cx1a (void)
21779{
21780 return do_custom_instruction_1 (0, 1);
21781}
21782
21783static void
21784do_cx1d (void)
21785{
21786 return do_custom_instruction_1 (1, 0);
21787}
21788
21789static void
21790do_cx1da (void)
21791{
21792 return do_custom_instruction_1 (1, 1);
21793}
21794
21795static void
21796do_cx2 (void)
21797{
21798 return do_custom_instruction_2 (0, 0);
21799}
21800
21801static void
21802do_cx2a (void)
21803{
21804 return do_custom_instruction_2 (0, 1);
21805}
21806
21807static void
21808do_cx2d (void)
21809{
21810 return do_custom_instruction_2 (1, 0);
21811}
21812
21813static void
21814do_cx2da (void)
21815{
21816 return do_custom_instruction_2 (1, 1);
21817}
21818
21819static void
21820do_cx3 (void)
21821{
21822 return do_custom_instruction_3 (0, 0);
21823}
21824
21825static void
21826do_cx3a (void)
21827{
21828 return do_custom_instruction_3 (0, 1);
21829}
21830
21831static void
21832do_cx3d (void)
21833{
21834 return do_custom_instruction_3 (1, 0);
21835}
21836
21837static void
21838do_cx3da (void)
21839{
21840 return do_custom_instruction_3 (1, 1);
21841}
21842
91ff7894
MGD
21843/* Crypto v1 instructions. */
21844static void
21845do_crypto_2op_1 (unsigned elttype, int op)
21846{
5ee91343 21847 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
21848
21849 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
21850 == NT_invtype)
21851 return;
21852
21853 inst.error = NULL;
21854
21855 NEON_ENCODE (INTEGER, inst);
21856 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21857 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21858 inst.instruction |= LOW4 (inst.operands[1].reg);
21859 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21860 if (op != -1)
21861 inst.instruction |= op << 6;
21862
21863 if (thumb_mode)
21864 inst.instruction |= 0xfc000000;
21865 else
21866 inst.instruction |= 0xf0000000;
21867}
21868
48adcd8e
MGD
21869static void
21870do_crypto_3op_1 (int u, int op)
21871{
5ee91343 21872 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
21873
21874 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
21875 N_32 | N_UNT | N_KEY).type == NT_invtype)
21876 return;
21877
21878 inst.error = NULL;
21879
21880 NEON_ENCODE (INTEGER, inst);
21881 neon_three_same (1, u, 8 << op);
21882}
21883
91ff7894
MGD
21884static void
21885do_aese (void)
21886{
21887 do_crypto_2op_1 (N_8, 0);
21888}
21889
21890static void
21891do_aesd (void)
21892{
21893 do_crypto_2op_1 (N_8, 1);
21894}
21895
21896static void
21897do_aesmc (void)
21898{
21899 do_crypto_2op_1 (N_8, 2);
21900}
21901
21902static void
21903do_aesimc (void)
21904{
21905 do_crypto_2op_1 (N_8, 3);
21906}
21907
48adcd8e
MGD
21908static void
21909do_sha1c (void)
21910{
21911 do_crypto_3op_1 (0, 0);
21912}
21913
21914static void
21915do_sha1p (void)
21916{
21917 do_crypto_3op_1 (0, 1);
21918}
21919
21920static void
21921do_sha1m (void)
21922{
21923 do_crypto_3op_1 (0, 2);
21924}
21925
21926static void
21927do_sha1su0 (void)
21928{
21929 do_crypto_3op_1 (0, 3);
21930}
91ff7894 21931
48adcd8e
MGD
21932static void
21933do_sha256h (void)
21934{
21935 do_crypto_3op_1 (1, 0);
21936}
21937
21938static void
21939do_sha256h2 (void)
21940{
21941 do_crypto_3op_1 (1, 1);
21942}
21943
21944static void
21945do_sha256su1 (void)
21946{
21947 do_crypto_3op_1 (1, 2);
21948}
3c9017d2
MGD
21949
21950static void
21951do_sha1h (void)
21952{
21953 do_crypto_2op_1 (N_32, -1);
21954}
21955
21956static void
21957do_sha1su1 (void)
21958{
21959 do_crypto_2op_1 (N_32, 0);
21960}
21961
21962static void
21963do_sha256su0 (void)
21964{
21965 do_crypto_2op_1 (N_32, 1);
21966}
dd5181d5
KT
21967
21968static void
21969do_crc32_1 (unsigned int poly, unsigned int sz)
21970{
21971 unsigned int Rd = inst.operands[0].reg;
21972 unsigned int Rn = inst.operands[1].reg;
21973 unsigned int Rm = inst.operands[2].reg;
21974
5ee91343 21975 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
21976 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
21977 inst.instruction |= LOW4 (Rn) << 16;
21978 inst.instruction |= LOW4 (Rm);
21979 inst.instruction |= sz << (thumb_mode ? 4 : 21);
21980 inst.instruction |= poly << (thumb_mode ? 20 : 9);
21981
21982 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
21983 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
21984}
21985
21986static void
21987do_crc32b (void)
21988{
21989 do_crc32_1 (0, 0);
21990}
21991
21992static void
21993do_crc32h (void)
21994{
21995 do_crc32_1 (0, 1);
21996}
21997
21998static void
21999do_crc32w (void)
22000{
22001 do_crc32_1 (0, 2);
22002}
22003
22004static void
22005do_crc32cb (void)
22006{
22007 do_crc32_1 (1, 0);
22008}
22009
22010static void
22011do_crc32ch (void)
22012{
22013 do_crc32_1 (1, 1);
22014}
22015
22016static void
22017do_crc32cw (void)
22018{
22019 do_crc32_1 (1, 2);
22020}
22021
49e8a725
SN
22022static void
22023do_vjcvt (void)
22024{
22025 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22026 _(BAD_FPU));
22027 neon_check_type (2, NS_FD, N_S32, N_F64);
22028 do_vfp_sp_dp_cvt ();
22029 do_vfp_cond_or_thumb ();
22030}
22031
aab2c27d
MM
22032static void
22033do_vdot (void)
22034{
22035 enum neon_shape rs;
22036 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22037 set_pred_insn_type (OUTSIDE_PRED_INSN);
22038 if (inst.operands[2].isscalar)
22039 {
22040 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22041 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22042
22043 inst.instruction |= (1 << 25);
22044 int index = inst.operands[2].reg & 0xf;
22045 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22046 inst.operands[2].reg >>= 4;
22047 constraint (!(inst.operands[2].reg < 16),
22048 _("indexed register must be less than 16"));
22049 neon_three_args (rs == NS_QQS);
22050 inst.instruction |= (index << 5);
22051 }
22052 else
22053 {
22054 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22055 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22056 neon_three_args (rs == NS_QQQ);
22057 }
22058}
22059
22060static void
22061do_vmmla (void)
22062{
22063 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22064 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22065
22066 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22067 set_pred_insn_type (OUTSIDE_PRED_INSN);
22068
22069 neon_three_args (1);
22070}
22071
5287ad62
JB
22072\f
22073/* Overall per-instruction processing. */
22074
22075/* We need to be able to fix up arbitrary expressions in some statements.
22076 This is so that we can handle symbols that are an arbitrary distance from
22077 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22078 which returns part of an address in a form which will be valid for
22079 a data instruction. We do this by pushing the expression into a symbol
22080 in the expr_section, and creating a fix for that. */
22081
22082static void
22083fix_new_arm (fragS * frag,
22084 int where,
22085 short int size,
22086 expressionS * exp,
22087 int pc_rel,
22088 int reloc)
22089{
22090 fixS * new_fix;
22091
22092 switch (exp->X_op)
22093 {
22094 case O_constant:
6e7ce2cd
PB
22095 if (pc_rel)
22096 {
22097 /* Create an absolute valued symbol, so we have something to
477330fc
RM
22098 refer to in the object file. Unfortunately for us, gas's
22099 generic expression parsing will already have folded out
22100 any use of .set foo/.type foo %function that may have
22101 been used to set type information of the target location,
22102 that's being specified symbolically. We have to presume
22103 the user knows what they are doing. */
6e7ce2cd
PB
22104 char name[16 + 8];
22105 symbolS *symbol;
22106
22107 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22108
22109 symbol = symbol_find_or_make (name);
22110 S_SET_SEGMENT (symbol, absolute_section);
22111 symbol_set_frag (symbol, &zero_address_frag);
22112 S_SET_VALUE (symbol, exp->X_add_number);
22113 exp->X_op = O_symbol;
22114 exp->X_add_symbol = symbol;
22115 exp->X_add_number = 0;
22116 }
22117 /* FALLTHROUGH */
5287ad62
JB
22118 case O_symbol:
22119 case O_add:
22120 case O_subtract:
21d799b5 22121 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 22122 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22123 break;
22124
22125 default:
21d799b5 22126 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 22127 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22128 break;
22129 }
22130
22131 /* Mark whether the fix is to a THUMB instruction, or an ARM
22132 instruction. */
22133 new_fix->tc_fix_data = thumb_mode;
22134}
22135
22136/* Create a frg for an instruction requiring relaxation. */
22137static void
22138output_relax_insn (void)
22139{
22140 char * to;
22141 symbolS *sym;
0110f2b8
PB
22142 int offset;
22143
6e1cb1a6
PB
22144 /* The size of the instruction is unknown, so tie the debug info to the
22145 start of the instruction. */
22146 dwarf2_emit_insn (0);
6e1cb1a6 22147
e2b0ab59 22148 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
22149 {
22150 case O_symbol:
e2b0ab59
AV
22151 sym = inst.relocs[0].exp.X_add_symbol;
22152 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22153 break;
22154 case O_constant:
22155 sym = NULL;
e2b0ab59 22156 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22157 break;
22158 default:
e2b0ab59 22159 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
22160 offset = 0;
22161 break;
22162 }
22163 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22164 inst.relax, sym, offset, NULL/*offset, opcode*/);
22165 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
22166}
22167
22168/* Write a 32-bit thumb instruction to buf. */
22169static void
22170put_thumb32_insn (char * buf, unsigned long insn)
22171{
22172 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22173 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22174}
22175
b99bd4ef 22176static void
c19d1205 22177output_inst (const char * str)
b99bd4ef 22178{
c19d1205 22179 char * to = NULL;
b99bd4ef 22180
c19d1205 22181 if (inst.error)
b99bd4ef 22182 {
c19d1205 22183 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
22184 return;
22185 }
5f4273c7
NC
22186 if (inst.relax)
22187 {
22188 output_relax_insn ();
0110f2b8 22189 return;
5f4273c7 22190 }
c19d1205
ZW
22191 if (inst.size == 0)
22192 return;
b99bd4ef 22193
c19d1205 22194 to = frag_more (inst.size);
8dc2430f
NC
22195 /* PR 9814: Record the thumb mode into the current frag so that we know
22196 what type of NOP padding to use, if necessary. We override any previous
22197 setting so that if the mode has changed then the NOPS that we use will
22198 match the encoding of the last instruction in the frag. */
cd000bff 22199 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
22200
22201 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 22202 {
9c2799c2 22203 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 22204 put_thumb32_insn (to, inst.instruction);
b99bd4ef 22205 }
c19d1205 22206 else if (inst.size > INSN_SIZE)
b99bd4ef 22207 {
9c2799c2 22208 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
22209 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22210 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 22211 }
c19d1205
ZW
22212 else
22213 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 22214
e2b0ab59
AV
22215 int r;
22216 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22217 {
22218 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22219 fix_new_arm (frag_now, to - frag_now->fr_literal,
22220 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22221 inst.relocs[r].type);
22222 }
b99bd4ef 22223
c19d1205 22224 dwarf2_emit_insn (inst.size);
c19d1205 22225}
b99bd4ef 22226
e07e6e58
NC
22227static char *
22228output_it_inst (int cond, int mask, char * to)
22229{
22230 unsigned long instruction = 0xbf00;
22231
22232 mask &= 0xf;
22233 instruction |= mask;
22234 instruction |= cond << 4;
22235
22236 if (to == NULL)
22237 {
22238 to = frag_more (2);
22239#ifdef OBJ_ELF
22240 dwarf2_emit_insn (2);
22241#endif
22242 }
22243
22244 md_number_to_chars (to, instruction, 2);
22245
22246 return to;
22247}
22248
c19d1205
ZW
22249/* Tag values used in struct asm_opcode's tag field. */
22250enum opcode_tag
22251{
22252 OT_unconditional, /* Instruction cannot be conditionalized.
22253 The ARM condition field is still 0xE. */
22254 OT_unconditionalF, /* Instruction cannot be conditionalized
22255 and carries 0xF in its ARM condition field. */
22256 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
22257 OT_csuffixF, /* Some forms of the instruction take a scalar
22258 conditional suffix, others place 0xF where the
22259 condition field would be, others take a vector
22260 conditional suffix. */
c19d1205
ZW
22261 OT_cinfix3, /* Instruction takes a conditional infix,
22262 beginning at character index 3. (In
22263 unified mode, it becomes a suffix.) */
088fa78e
KH
22264 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22265 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
22266 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22267 character index 3, even in unified mode. Used for
22268 legacy instructions where suffix and infix forms
22269 may be ambiguous. */
c19d1205 22270 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 22271 suffix or an infix at character index 3. */
c19d1205
ZW
22272 OT_odd_infix_unc, /* This is the unconditional variant of an
22273 instruction that takes a conditional infix
22274 at an unusual position. In unified mode,
22275 this variant will accept a suffix. */
22276 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22277 are the conditional variants of instructions that
22278 take conditional infixes in unusual positions.
22279 The infix appears at character index
22280 (tag - OT_odd_infix_0). These are not accepted
22281 in unified mode. */
22282};
b99bd4ef 22283
c19d1205
ZW
22284/* Subroutine of md_assemble, responsible for looking up the primary
22285 opcode from the mnemonic the user wrote. STR points to the
22286 beginning of the mnemonic.
22287
22288 This is not simply a hash table lookup, because of conditional
22289 variants. Most instructions have conditional variants, which are
22290 expressed with a _conditional affix_ to the mnemonic. If we were
22291 to encode each conditional variant as a literal string in the opcode
22292 table, it would have approximately 20,000 entries.
22293
22294 Most mnemonics take this affix as a suffix, and in unified syntax,
22295 'most' is upgraded to 'all'. However, in the divided syntax, some
22296 instructions take the affix as an infix, notably the s-variants of
22297 the arithmetic instructions. Of those instructions, all but six
22298 have the infix appear after the third character of the mnemonic.
22299
22300 Accordingly, the algorithm for looking up primary opcodes given
22301 an identifier is:
22302
22303 1. Look up the identifier in the opcode table.
22304 If we find a match, go to step U.
22305
22306 2. Look up the last two characters of the identifier in the
22307 conditions table. If we find a match, look up the first N-2
22308 characters of the identifier in the opcode table. If we
22309 find a match, go to step CE.
22310
22311 3. Look up the fourth and fifth characters of the identifier in
22312 the conditions table. If we find a match, extract those
22313 characters from the identifier, and look up the remaining
22314 characters in the opcode table. If we find a match, go
22315 to step CM.
22316
22317 4. Fail.
22318
22319 U. Examine the tag field of the opcode structure, in case this is
22320 one of the six instructions with its conditional infix in an
22321 unusual place. If it is, the tag tells us where to find the
22322 infix; look it up in the conditions table and set inst.cond
22323 accordingly. Otherwise, this is an unconditional instruction.
22324 Again set inst.cond accordingly. Return the opcode structure.
22325
22326 CE. Examine the tag field to make sure this is an instruction that
22327 should receive a conditional suffix. If it is not, fail.
22328 Otherwise, set inst.cond from the suffix we already looked up,
22329 and return the opcode structure.
22330
22331 CM. Examine the tag field to make sure this is an instruction that
22332 should receive a conditional infix after the third character.
22333 If it is not, fail. Otherwise, undo the edits to the current
22334 line of input and proceed as for case CE. */
22335
22336static const struct asm_opcode *
22337opcode_lookup (char **str)
22338{
22339 char *end, *base;
22340 char *affix;
22341 const struct asm_opcode *opcode;
22342 const struct asm_cond *cond;
e3cb604e 22343 char save[2];
c19d1205
ZW
22344
22345 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 22346 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 22347 for (base = end = *str; *end != '\0'; end++)
721a8186 22348 if (*end == ' ' || *end == '.')
c19d1205 22349 break;
b99bd4ef 22350
c19d1205 22351 if (end == base)
c921be7d 22352 return NULL;
b99bd4ef 22353
5287ad62 22354 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 22355 if (end[0] == '.')
b99bd4ef 22356 {
5287ad62 22357 int offset = 2;
5f4273c7 22358
267d2029 22359 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 22360 use. */
267d2029 22361 if (unified_syntax && end[1] == 'w')
c19d1205 22362 inst.size_req = 4;
267d2029 22363 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
22364 inst.size_req = 2;
22365 else
477330fc 22366 offset = 0;
5287ad62
JB
22367
22368 inst.vectype.elems = 0;
22369
22370 *str = end + offset;
b99bd4ef 22371
5f4273c7 22372 if (end[offset] == '.')
5287ad62 22373 {
267d2029 22374 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
22375 non-unified ARM syntax mode). */
22376 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 22377 return NULL;
477330fc 22378 }
5287ad62 22379 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 22380 return NULL;
b99bd4ef 22381 }
c19d1205
ZW
22382 else
22383 *str = end;
b99bd4ef 22384
c19d1205 22385 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 22386 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22387 end - base);
c19d1205 22388 if (opcode)
b99bd4ef 22389 {
c19d1205
ZW
22390 /* step U */
22391 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 22392 {
c19d1205
ZW
22393 inst.cond = COND_ALWAYS;
22394 return opcode;
b99bd4ef 22395 }
b99bd4ef 22396
278df34e 22397 if (warn_on_deprecated && unified_syntax)
5c3696f8 22398 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 22399 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 22400 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 22401 gas_assert (cond);
b99bd4ef 22402
c19d1205
ZW
22403 inst.cond = cond->value;
22404 return opcode;
22405 }
5ee91343
AV
22406 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22407 {
22408 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22409 */
22410 if (end - base < 2)
22411 return NULL;
22412 affix = end - 1;
22413 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
22414 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22415 affix - base);
22416 /* If this opcode can not be vector predicated then don't accept it with a
22417 vector predication code. */
22418 if (opcode && !opcode->mayBeVecPred)
22419 opcode = NULL;
22420 }
22421 if (!opcode || !cond)
22422 {
22423 /* Cannot have a conditional suffix on a mnemonic of less than two
22424 characters. */
22425 if (end - base < 3)
22426 return NULL;
b99bd4ef 22427
5ee91343
AV
22428 /* Look for suffixed mnemonic. */
22429 affix = end - 2;
22430 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22431 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22432 affix - base);
22433 }
b99bd4ef 22434
c19d1205
ZW
22435 if (opcode && cond)
22436 {
22437 /* step CE */
22438 switch (opcode->tag)
22439 {
e3cb604e
PB
22440 case OT_cinfix3_legacy:
22441 /* Ignore conditional suffixes matched on infix only mnemonics. */
22442 break;
22443
c19d1205 22444 case OT_cinfix3:
088fa78e 22445 case OT_cinfix3_deprecated:
c19d1205
ZW
22446 case OT_odd_infix_unc:
22447 if (!unified_syntax)
0198d5e6 22448 return NULL;
1a0670f3 22449 /* Fall through. */
c19d1205
ZW
22450
22451 case OT_csuffix:
477330fc 22452 case OT_csuffixF:
c19d1205
ZW
22453 case OT_csuf_or_in3:
22454 inst.cond = cond->value;
22455 return opcode;
22456
22457 case OT_unconditional:
22458 case OT_unconditionalF:
dfa9f0d5 22459 if (thumb_mode)
c921be7d 22460 inst.cond = cond->value;
dfa9f0d5
PB
22461 else
22462 {
c921be7d 22463 /* Delayed diagnostic. */
dfa9f0d5
PB
22464 inst.error = BAD_COND;
22465 inst.cond = COND_ALWAYS;
22466 }
c19d1205 22467 return opcode;
b99bd4ef 22468
c19d1205 22469 default:
c921be7d 22470 return NULL;
c19d1205
ZW
22471 }
22472 }
b99bd4ef 22473
c19d1205
ZW
22474 /* Cannot have a usual-position infix on a mnemonic of less than
22475 six characters (five would be a suffix). */
22476 if (end - base < 6)
c921be7d 22477 return NULL;
b99bd4ef 22478
c19d1205
ZW
22479 /* Look for infixed mnemonic in the usual position. */
22480 affix = base + 3;
21d799b5 22481 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 22482 if (!cond)
c921be7d 22483 return NULL;
e3cb604e
PB
22484
22485 memcpy (save, affix, 2);
22486 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 22487 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22488 (end - base) - 2);
e3cb604e
PB
22489 memmove (affix + 2, affix, (end - affix) - 2);
22490 memcpy (affix, save, 2);
22491
088fa78e
KH
22492 if (opcode
22493 && (opcode->tag == OT_cinfix3
22494 || opcode->tag == OT_cinfix3_deprecated
22495 || opcode->tag == OT_csuf_or_in3
22496 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 22497 {
c921be7d 22498 /* Step CM. */
278df34e 22499 if (warn_on_deprecated && unified_syntax
088fa78e
KH
22500 && (opcode->tag == OT_cinfix3
22501 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 22502 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
22503
22504 inst.cond = cond->value;
22505 return opcode;
b99bd4ef
NC
22506 }
22507
c921be7d 22508 return NULL;
b99bd4ef
NC
22509}
22510
e07e6e58
NC
22511/* This function generates an initial IT instruction, leaving its block
22512 virtually open for the new instructions. Eventually,
5ee91343 22513 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
22514 a new instruction needs to be included in the IT block.
22515 Finally, the block is closed with close_automatic_it_block ().
22516 The block closure can be requested either from md_assemble (),
22517 a tencode (), or due to a label hook. */
22518
22519static void
22520new_automatic_it_block (int cond)
22521{
5ee91343
AV
22522 now_pred.state = AUTOMATIC_PRED_BLOCK;
22523 now_pred.mask = 0x18;
22524 now_pred.cc = cond;
22525 now_pred.block_length = 1;
cd000bff 22526 mapping_state (MAP_THUMB);
5ee91343
AV
22527 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22528 now_pred.warn_deprecated = FALSE;
22529 now_pred.insn_cond = TRUE;
e07e6e58
NC
22530}
22531
22532/* Close an automatic IT block.
22533 See comments in new_automatic_it_block (). */
22534
22535static void
22536close_automatic_it_block (void)
22537{
5ee91343
AV
22538 now_pred.mask = 0x10;
22539 now_pred.block_length = 0;
e07e6e58
NC
22540}
22541
22542/* Update the mask of the current automatically-generated IT
22543 instruction. See comments in new_automatic_it_block (). */
22544
22545static void
5ee91343 22546now_pred_add_mask (int cond)
e07e6e58
NC
22547{
22548#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22549#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 22550 | ((bitvalue) << (nbit)))
e07e6e58 22551 const int resulting_bit = (cond & 1);
c921be7d 22552
5ee91343
AV
22553 now_pred.mask &= 0xf;
22554 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22555 resulting_bit,
5ee91343
AV
22556 (5 - now_pred.block_length));
22557 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22558 1,
5ee91343
AV
22559 ((5 - now_pred.block_length) - 1));
22560 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
22561
22562#undef CLEAR_BIT
22563#undef SET_BIT_VALUE
e07e6e58
NC
22564}
22565
22566/* The IT blocks handling machinery is accessed through the these functions:
22567 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
22568 set_pred_insn_type () optional, from the tencode functions
22569 set_pred_insn_type_last () ditto
22570 in_pred_block () ditto
e07e6e58 22571 it_fsm_post_encode () from md_assemble ()
33eaf5de 22572 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
22573
22574 Rationale:
22575 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
22576 initializing the IT insn type with a generic initial value depending
22577 on the inst.condition.
e07e6e58 22578 2) During the tencode function, two things may happen:
477330fc 22579 a) The tencode function overrides the IT insn type by
5ee91343
AV
22580 calling either set_pred_insn_type (type) or
22581 set_pred_insn_type_last ().
477330fc 22582 b) The tencode function queries the IT block state by
5ee91343 22583 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 22584
5ee91343
AV
22585 Both set_pred_insn_type and in_pred_block run the internal FSM state
22586 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
22587 type may incur in an invalid state (exiting the function),
22588 and b) querying the state requires the FSM to be updated.
22589 Specifically we want to avoid creating an IT block for conditional
22590 branches, so it_fsm_pre_encode is actually a guess and we can't
22591 determine whether an IT block is required until the tencode () routine
22592 has decided what type of instruction this actually it.
5ee91343
AV
22593 Because of this, if set_pred_insn_type and in_pred_block have to be
22594 used, set_pred_insn_type has to be called first.
477330fc 22595
5ee91343
AV
22596 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22597 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
22598 When a tencode () routine encodes an instruction that can be
22599 either outside an IT block, or, in the case of being inside, has to be
5ee91343 22600 the last one, set_pred_insn_type_last () will determine the proper
477330fc 22601 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 22602 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
22603 for covering other cases.
22604
5ee91343
AV
22605 Calling handle_pred_state () may not transition the IT block state to
22606 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 22607 still queried. Instead, if the FSM determines that the state should
5ee91343 22608 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
22609 after the tencode () function: that's what it_fsm_post_encode () does.
22610
5ee91343 22611 Since in_pred_block () calls the state handling function to get an
477330fc
RM
22612 updated state, an error may occur (due to invalid insns combination).
22613 In that case, inst.error is set.
22614 Therefore, inst.error has to be checked after the execution of
22615 the tencode () routine.
e07e6e58
NC
22616
22617 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 22618 any pending state change (if any) that didn't take place in
5ee91343 22619 handle_pred_state () as explained above. */
e07e6e58
NC
22620
22621static void
22622it_fsm_pre_encode (void)
22623{
22624 if (inst.cond != COND_ALWAYS)
5ee91343 22625 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 22626 else
5ee91343 22627 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 22628
5ee91343 22629 now_pred.state_handled = 0;
e07e6e58
NC
22630}
22631
22632/* IT state FSM handling function. */
5ee91343
AV
22633/* MVE instructions and non-MVE instructions are handled differently because of
22634 the introduction of VPT blocks.
22635 Specifications say that any non-MVE instruction inside a VPT block is
22636 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22637 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 22638 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
22639 The error messages provided depending on the different combinations possible
22640 are described in the cases below:
22641 For 'most' MVE instructions:
22642 1) In an IT block, with an IT code: syntax error
22643 2) In an IT block, with a VPT code: error: must be in a VPT block
22644 3) In an IT block, with no code: warning: UNPREDICTABLE
22645 4) In a VPT block, with an IT code: syntax error
22646 5) In a VPT block, with a VPT code: OK!
22647 6) In a VPT block, with no code: error: missing code
22648 7) Outside a pred block, with an IT code: error: syntax error
22649 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22650 9) Outside a pred block, with no code: OK!
22651 For non-MVE instructions:
22652 10) In an IT block, with an IT code: OK!
22653 11) In an IT block, with a VPT code: syntax error
22654 12) In an IT block, with no code: error: missing code
22655 13) In a VPT block, with an IT code: error: should be in an IT block
22656 14) In a VPT block, with a VPT code: syntax error
22657 15) In a VPT block, with no code: UNPREDICTABLE
22658 16) Outside a pred block, with an IT code: error: should be in an IT block
22659 17) Outside a pred block, with a VPT code: syntax error
22660 18) Outside a pred block, with no code: OK!
22661 */
22662
e07e6e58
NC
22663
22664static int
5ee91343 22665handle_pred_state (void)
e07e6e58 22666{
5ee91343
AV
22667 now_pred.state_handled = 1;
22668 now_pred.insn_cond = FALSE;
e07e6e58 22669
5ee91343 22670 switch (now_pred.state)
e07e6e58 22671 {
5ee91343
AV
22672 case OUTSIDE_PRED_BLOCK:
22673 switch (inst.pred_insn_type)
e07e6e58 22674 {
35c228db 22675 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22676 case MVE_OUTSIDE_PRED_INSN:
22677 if (inst.cond < COND_ALWAYS)
22678 {
22679 /* Case 7: Outside a pred block, with an IT code: error: syntax
22680 error. */
22681 inst.error = BAD_SYNTAX;
22682 return FAIL;
22683 }
22684 /* Case 9: Outside a pred block, with no code: OK! */
22685 break;
22686 case OUTSIDE_PRED_INSN:
22687 if (inst.cond > COND_ALWAYS)
22688 {
22689 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22690 */
22691 inst.error = BAD_SYNTAX;
22692 return FAIL;
22693 }
22694 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22695 break;
22696
5ee91343
AV
22697 case INSIDE_VPT_INSN:
22698 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22699 a VPT block. */
22700 inst.error = BAD_OUT_VPT;
22701 return FAIL;
22702
e07e6e58
NC
22703 case INSIDE_IT_INSN:
22704 case INSIDE_IT_LAST_INSN:
5ee91343 22705 if (inst.cond < COND_ALWAYS)
e07e6e58 22706 {
5ee91343
AV
22707 /* Case 16: Outside a pred block, with an IT code: error: should
22708 be in an IT block. */
22709 if (thumb_mode == 0)
e07e6e58 22710 {
5ee91343
AV
22711 if (unified_syntax
22712 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22713 as_tsktsk (_("Warning: conditional outside an IT block"\
22714 " for Thumb."));
e07e6e58
NC
22715 }
22716 else
22717 {
5ee91343
AV
22718 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22719 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22720 {
22721 /* Automatically generate the IT instruction. */
22722 new_automatic_it_block (inst.cond);
22723 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22724 close_automatic_it_block ();
22725 }
22726 else
22727 {
22728 inst.error = BAD_OUT_IT;
22729 return FAIL;
22730 }
e07e6e58 22731 }
5ee91343 22732 break;
e07e6e58 22733 }
5ee91343
AV
22734 else if (inst.cond > COND_ALWAYS)
22735 {
22736 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22737 */
22738 inst.error = BAD_SYNTAX;
22739 return FAIL;
22740 }
22741 else
22742 gas_assert (0);
e07e6e58
NC
22743 case IF_INSIDE_IT_LAST_INSN:
22744 case NEUTRAL_IT_INSN:
4934a27c 22745 case NEUTRAL_IT_NO_VPT_INSN:
e07e6e58
NC
22746 break;
22747
5ee91343
AV
22748 case VPT_INSN:
22749 if (inst.cond != COND_ALWAYS)
22750 first_error (BAD_SYNTAX);
22751 now_pred.state = MANUAL_PRED_BLOCK;
22752 now_pred.block_length = 0;
22753 now_pred.type = VECTOR_PRED;
22754 now_pred.cc = 0;
22755 break;
e07e6e58 22756 case IT_INSN:
5ee91343
AV
22757 now_pred.state = MANUAL_PRED_BLOCK;
22758 now_pred.block_length = 0;
22759 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22760 break;
22761 }
22762 break;
22763
5ee91343 22764 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
22765 /* Three things may happen now:
22766 a) We should increment current it block size;
22767 b) We should close current it block (closing insn or 4 insns);
22768 c) We should close current it block and start a new one (due
22769 to incompatible conditions or
22770 4 insns-length block reached). */
22771
5ee91343 22772 switch (inst.pred_insn_type)
e07e6e58 22773 {
5ee91343
AV
22774 case INSIDE_VPT_INSN:
22775 case VPT_INSN:
35c228db 22776 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22777 case MVE_OUTSIDE_PRED_INSN:
22778 gas_assert (0);
22779 case OUTSIDE_PRED_INSN:
2b0f3761 22780 /* The closure of the block shall happen immediately,
5ee91343 22781 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
22782 force_automatic_it_block_close ();
22783 break;
22784
22785 case INSIDE_IT_INSN:
22786 case INSIDE_IT_LAST_INSN:
22787 case IF_INSIDE_IT_LAST_INSN:
5ee91343 22788 now_pred.block_length++;
e07e6e58 22789
5ee91343
AV
22790 if (now_pred.block_length > 4
22791 || !now_pred_compatible (inst.cond))
e07e6e58
NC
22792 {
22793 force_automatic_it_block_close ();
5ee91343 22794 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
22795 new_automatic_it_block (inst.cond);
22796 }
22797 else
22798 {
5ee91343
AV
22799 now_pred.insn_cond = TRUE;
22800 now_pred_add_mask (inst.cond);
e07e6e58
NC
22801 }
22802
5ee91343
AV
22803 if (now_pred.state == AUTOMATIC_PRED_BLOCK
22804 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
22805 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
22806 close_automatic_it_block ();
22807 break;
22808
4934a27c
MM
22809 case NEUTRAL_IT_NO_VPT_INSN:
22810 if (now_pred.type == VECTOR_PRED)
22811 {
22812 inst.error = BAD_NO_VPT;
22813 break;
22814 }
22815 /* Fallthrough. */
e07e6e58 22816 case NEUTRAL_IT_INSN:
5ee91343
AV
22817 now_pred.block_length++;
22818 now_pred.insn_cond = TRUE;
e07e6e58 22819
5ee91343 22820 if (now_pred.block_length > 4)
e07e6e58
NC
22821 force_automatic_it_block_close ();
22822 else
5ee91343 22823 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
22824 break;
22825
22826 case IT_INSN:
22827 close_automatic_it_block ();
5ee91343 22828 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
22829 break;
22830 }
22831 break;
22832
5ee91343 22833 case MANUAL_PRED_BLOCK:
e07e6e58 22834 {
5ee91343
AV
22835 int cond, is_last;
22836 if (now_pred.type == SCALAR_PRED)
e07e6e58 22837 {
5ee91343
AV
22838 /* Check conditional suffixes. */
22839 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
22840 now_pred.mask <<= 1;
22841 now_pred.mask &= 0x1f;
22842 is_last = (now_pred.mask == 0x10);
22843 }
22844 else
22845 {
22846 now_pred.cc ^= (now_pred.mask >> 4);
22847 cond = now_pred.cc + 0xf;
22848 now_pred.mask <<= 1;
22849 now_pred.mask &= 0x1f;
22850 is_last = now_pred.mask == 0x10;
22851 }
22852 now_pred.insn_cond = TRUE;
e07e6e58 22853
5ee91343
AV
22854 switch (inst.pred_insn_type)
22855 {
22856 case OUTSIDE_PRED_INSN:
22857 if (now_pred.type == SCALAR_PRED)
22858 {
22859 if (inst.cond == COND_ALWAYS)
22860 {
22861 /* Case 12: In an IT block, with no code: error: missing
22862 code. */
22863 inst.error = BAD_NOT_IT;
22864 return FAIL;
22865 }
22866 else if (inst.cond > COND_ALWAYS)
22867 {
22868 /* Case 11: In an IT block, with a VPT code: syntax error.
22869 */
22870 inst.error = BAD_SYNTAX;
22871 return FAIL;
22872 }
22873 else if (thumb_mode)
22874 {
22875 /* This is for some special cases where a non-MVE
22876 instruction is not allowed in an IT block, such as cbz,
22877 but are put into one with a condition code.
22878 You could argue this should be a syntax error, but we
22879 gave the 'not allowed in IT block' diagnostic in the
22880 past so we will keep doing so. */
22881 inst.error = BAD_NOT_IT;
22882 return FAIL;
22883 }
22884 break;
22885 }
22886 else
22887 {
22888 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
22889 as_tsktsk (MVE_NOT_VPT);
22890 return SUCCESS;
22891 }
22892 case MVE_OUTSIDE_PRED_INSN:
22893 if (now_pred.type == SCALAR_PRED)
22894 {
22895 if (inst.cond == COND_ALWAYS)
22896 {
22897 /* Case 3: In an IT block, with no code: warning:
22898 UNPREDICTABLE. */
22899 as_tsktsk (MVE_NOT_IT);
22900 return SUCCESS;
22901 }
22902 else if (inst.cond < COND_ALWAYS)
22903 {
22904 /* Case 1: In an IT block, with an IT code: syntax error.
22905 */
22906 inst.error = BAD_SYNTAX;
22907 return FAIL;
22908 }
22909 else
22910 gas_assert (0);
22911 }
22912 else
22913 {
22914 if (inst.cond < COND_ALWAYS)
22915 {
22916 /* Case 4: In a VPT block, with an IT code: syntax error.
22917 */
22918 inst.error = BAD_SYNTAX;
22919 return FAIL;
22920 }
22921 else if (inst.cond == COND_ALWAYS)
22922 {
22923 /* Case 6: In a VPT block, with no code: error: missing
22924 code. */
22925 inst.error = BAD_NOT_VPT;
22926 return FAIL;
22927 }
22928 else
22929 {
22930 gas_assert (0);
22931 }
22932 }
35c228db
AV
22933 case MVE_UNPREDICABLE_INSN:
22934 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
22935 return SUCCESS;
e07e6e58 22936 case INSIDE_IT_INSN:
5ee91343 22937 if (inst.cond > COND_ALWAYS)
e07e6e58 22938 {
5ee91343
AV
22939 /* Case 11: In an IT block, with a VPT code: syntax error. */
22940 /* Case 14: In a VPT block, with a VPT code: syntax error. */
22941 inst.error = BAD_SYNTAX;
22942 return FAIL;
22943 }
22944 else if (now_pred.type == SCALAR_PRED)
22945 {
22946 /* Case 10: In an IT block, with an IT code: OK! */
22947 if (cond != inst.cond)
22948 {
22949 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
22950 BAD_VPT_COND;
22951 return FAIL;
22952 }
22953 }
22954 else
22955 {
22956 /* Case 13: In a VPT block, with an IT code: error: should be
22957 in an IT block. */
22958 inst.error = BAD_OUT_IT;
e07e6e58
NC
22959 return FAIL;
22960 }
22961 break;
22962
5ee91343
AV
22963 case INSIDE_VPT_INSN:
22964 if (now_pred.type == SCALAR_PRED)
22965 {
22966 /* Case 2: In an IT block, with a VPT code: error: must be in a
22967 VPT block. */
22968 inst.error = BAD_OUT_VPT;
22969 return FAIL;
22970 }
22971 /* Case 5: In a VPT block, with a VPT code: OK! */
22972 else if (cond != inst.cond)
22973 {
22974 inst.error = BAD_VPT_COND;
22975 return FAIL;
22976 }
22977 break;
e07e6e58
NC
22978 case INSIDE_IT_LAST_INSN:
22979 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
22980 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
22981 {
22982 /* Case 4: In a VPT block, with an IT code: syntax error. */
22983 /* Case 11: In an IT block, with a VPT code: syntax error. */
22984 inst.error = BAD_SYNTAX;
22985 return FAIL;
22986 }
22987 else if (cond != inst.cond)
e07e6e58
NC
22988 {
22989 inst.error = BAD_IT_COND;
22990 return FAIL;
22991 }
22992 if (!is_last)
22993 {
22994 inst.error = BAD_BRANCH;
22995 return FAIL;
22996 }
22997 break;
22998
4934a27c
MM
22999 case NEUTRAL_IT_NO_VPT_INSN:
23000 if (now_pred.type == VECTOR_PRED)
23001 {
23002 inst.error = BAD_NO_VPT;
23003 break;
23004 }
23005 /* Fallthrough. */
e07e6e58 23006 case NEUTRAL_IT_INSN:
5ee91343
AV
23007 /* The BKPT instruction is unconditional even in a IT or VPT
23008 block. */
e07e6e58
NC
23009 break;
23010
23011 case IT_INSN:
5ee91343
AV
23012 if (now_pred.type == SCALAR_PRED)
23013 {
23014 inst.error = BAD_IT_IT;
23015 return FAIL;
23016 }
23017 /* fall through. */
23018 case VPT_INSN:
23019 if (inst.cond == COND_ALWAYS)
23020 {
23021 /* Executing a VPT/VPST instruction inside an IT block or a
23022 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23023 */
23024 if (now_pred.type == SCALAR_PRED)
23025 as_tsktsk (MVE_NOT_IT);
23026 else
23027 as_tsktsk (MVE_NOT_VPT);
23028 return SUCCESS;
23029 }
23030 else
23031 {
23032 /* VPT/VPST do not accept condition codes. */
23033 inst.error = BAD_SYNTAX;
23034 return FAIL;
23035 }
e07e6e58 23036 }
5ee91343 23037 }
e07e6e58
NC
23038 break;
23039 }
23040
23041 return SUCCESS;
23042}
23043
5a01bb1d
MGD
23044struct depr_insn_mask
23045{
23046 unsigned long pattern;
23047 unsigned long mask;
23048 const char* description;
23049};
23050
23051/* List of 16-bit instruction patterns deprecated in an IT block in
23052 ARMv8. */
23053static const struct depr_insn_mask depr_it_insns[] = {
23054 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23055 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23056 { 0xa000, 0xb800, N_("ADR") },
23057 { 0x4800, 0xf800, N_("Literal loads") },
23058 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23059 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
23060 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23061 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23062 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
23063 { 0, 0, NULL }
23064};
23065
e07e6e58
NC
23066static void
23067it_fsm_post_encode (void)
23068{
23069 int is_last;
23070
5ee91343
AV
23071 if (!now_pred.state_handled)
23072 handle_pred_state ();
e07e6e58 23073
5ee91343 23074 if (now_pred.insn_cond
24f19ccb 23075 && warn_on_restrict_it
5ee91343 23076 && !now_pred.warn_deprecated
5a01bb1d 23077 && warn_on_deprecated
df9909b8
TP
23078 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23079 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
23080 {
23081 if (inst.instruction >= 0x10000)
23082 {
5c3696f8 23083 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 23084 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 23085 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23086 }
23087 else
23088 {
23089 const struct depr_insn_mask *p = depr_it_insns;
23090
23091 while (p->mask != 0)
23092 {
23093 if ((inst.instruction & p->mask) == p->pattern)
23094 {
df9909b8
TP
23095 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23096 "instructions of the following class are "
23097 "performance deprecated in ARMv8-A and "
23098 "ARMv8-R: %s"), p->description);
5ee91343 23099 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23100 break;
23101 }
23102
23103 ++p;
23104 }
23105 }
23106
5ee91343 23107 if (now_pred.block_length > 1)
5a01bb1d 23108 {
5c3696f8 23109 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
23110 "instruction are performance deprecated in ARMv8-A and "
23111 "ARMv8-R"));
5ee91343 23112 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23113 }
23114 }
23115
5ee91343
AV
23116 is_last = (now_pred.mask == 0x10);
23117 if (is_last)
23118 {
23119 now_pred.state = OUTSIDE_PRED_BLOCK;
23120 now_pred.mask = 0;
23121 }
e07e6e58
NC
23122}
23123
23124static void
23125force_automatic_it_block_close (void)
23126{
5ee91343 23127 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
23128 {
23129 close_automatic_it_block ();
5ee91343
AV
23130 now_pred.state = OUTSIDE_PRED_BLOCK;
23131 now_pred.mask = 0;
e07e6e58
NC
23132 }
23133}
23134
23135static int
5ee91343 23136in_pred_block (void)
e07e6e58 23137{
5ee91343
AV
23138 if (!now_pred.state_handled)
23139 handle_pred_state ();
e07e6e58 23140
5ee91343 23141 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
23142}
23143
ff8646ee
TP
23144/* Whether OPCODE only has T32 encoding. Since this function is only used by
23145 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23146 here, hence the "known" in the function name. */
fc289b0a
TP
23147
23148static bfd_boolean
ff8646ee 23149known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
23150{
23151 /* Original Thumb-1 wide instruction. */
23152 if (opcode->tencode == do_t_blx
23153 || opcode->tencode == do_t_branch23
23154 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23155 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23156 return TRUE;
23157
16a1fa25
TP
23158 /* Wide-only instruction added to ARMv8-M Baseline. */
23159 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
23160 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23161 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23162 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23163 return TRUE;
23164
23165 return FALSE;
23166}
23167
23168/* Whether wide instruction variant can be used if available for a valid OPCODE
23169 in ARCH. */
23170
23171static bfd_boolean
23172t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23173{
23174 if (known_t32_only_insn (opcode))
23175 return TRUE;
23176
23177 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23178 of variant T3 of B.W is checked in do_t_branch. */
23179 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23180 && opcode->tencode == do_t_branch)
23181 return TRUE;
23182
bada4342
JW
23183 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23184 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23185 && opcode->tencode == do_t_mov_cmp
23186 /* Make sure CMP instruction is not affected. */
23187 && opcode->aencode == do_mov)
23188 return TRUE;
23189
ff8646ee
TP
23190 /* Wide instruction variants of all instructions with narrow *and* wide
23191 variants become available with ARMv6t2. Other opcodes are either
23192 narrow-only or wide-only and are thus available if OPCODE is valid. */
23193 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23194 return TRUE;
23195
23196 /* OPCODE with narrow only instruction variant or wide variant not
23197 available. */
fc289b0a
TP
23198 return FALSE;
23199}
23200
c19d1205
ZW
23201void
23202md_assemble (char *str)
b99bd4ef 23203{
c19d1205
ZW
23204 char *p = str;
23205 const struct asm_opcode * opcode;
b99bd4ef 23206
c19d1205
ZW
23207 /* Align the previous label if needed. */
23208 if (last_label_seen != NULL)
b99bd4ef 23209 {
c19d1205
ZW
23210 symbol_set_frag (last_label_seen, frag_now);
23211 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23212 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
23213 }
23214
c19d1205 23215 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
23216 int r;
23217 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23218 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 23219
c19d1205
ZW
23220 opcode = opcode_lookup (&p);
23221 if (!opcode)
b99bd4ef 23222 {
c19d1205 23223 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 23224 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 23225 if (! create_register_alias (str, p)
477330fc 23226 && ! create_neon_reg_alias (str, p))
c19d1205 23227 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 23228
b99bd4ef
NC
23229 return;
23230 }
23231
278df34e 23232 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 23233 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 23234
037e8744
JB
23235 /* The value which unconditional instructions should have in place of the
23236 condition field. */
23237 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
23238
c19d1205 23239 if (thumb_mode)
b99bd4ef 23240 {
e74cfd16 23241 arm_feature_set variant;
8f06b2d8
PB
23242
23243 variant = cpu_variant;
23244 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
23245 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23246 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 23247 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
23248 if (!opcode->tvariant
23249 || (thumb_mode == 1
23250 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 23251 {
173205ca
TP
23252 if (opcode->tencode == do_t_swi)
23253 as_bad (_("SVC is not permitted on this architecture"));
23254 else
23255 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
23256 return;
23257 }
c19d1205
ZW
23258 if (inst.cond != COND_ALWAYS && !unified_syntax
23259 && opcode->tencode != do_t_branch)
b99bd4ef 23260 {
c19d1205 23261 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
23262 return;
23263 }
23264
fc289b0a
TP
23265 /* Two things are addressed here:
23266 1) Implicit require narrow instructions on Thumb-1.
23267 This avoids relaxation accidentally introducing Thumb-2
23268 instructions.
23269 2) Reject wide instructions in non Thumb-2 cores.
23270
23271 Only instructions with narrow and wide variants need to be handled
23272 but selecting all non wide-only instructions is easier. */
23273 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 23274 && !t32_insn_ok (variant, opcode))
076d447c 23275 {
fc289b0a
TP
23276 if (inst.size_req == 0)
23277 inst.size_req = 2;
23278 else if (inst.size_req == 4)
752d5da4 23279 {
ff8646ee
TP
23280 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23281 as_bad (_("selected processor does not support 32bit wide "
23282 "variant of instruction `%s'"), str);
23283 else
23284 as_bad (_("selected processor does not support `%s' in "
23285 "Thumb-2 mode"), str);
fc289b0a 23286 return;
752d5da4 23287 }
076d447c
PB
23288 }
23289
c19d1205
ZW
23290 inst.instruction = opcode->tvalue;
23291
5be8be5d 23292 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 23293 {
5ee91343 23294 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
23295 it. */
23296 it_fsm_pre_encode ();
c19d1205 23297
477330fc 23298 opcode->tencode ();
e07e6e58 23299
477330fc
RM
23300 it_fsm_post_encode ();
23301 }
e27ec89e 23302
0110f2b8 23303 if (!(inst.error || inst.relax))
b99bd4ef 23304 {
9c2799c2 23305 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
23306 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23307 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 23308 {
c19d1205 23309 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
23310 return;
23311 }
23312 }
076d447c
PB
23313
23314 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 23315 instruction. */
9c2799c2 23316 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 23317
e74cfd16
PB
23318 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23319 *opcode->tvariant);
ee065d83 23320 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
23321 set those bits when Thumb-2 32-bit instructions are seen. The impact
23322 of relaxable instructions will be considered later after we finish all
23323 relaxation. */
ff8646ee
TP
23324 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23325 variant = arm_arch_none;
23326 else
23327 variant = cpu_variant;
23328 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
23329 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23330 arm_ext_v6t2);
cd000bff 23331
88714cb8
DG
23332 check_neon_suffixes;
23333
cd000bff 23334 if (!inst.error)
c877a2f2
NC
23335 {
23336 mapping_state (MAP_THUMB);
23337 }
c19d1205 23338 }
3e9e4fcf 23339 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 23340 {
845b51d6
PB
23341 bfd_boolean is_bx;
23342
23343 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23344 is_bx = (opcode->aencode == do_bx);
23345
c19d1205 23346 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
23347 if (!(is_bx && fix_v4bx)
23348 && !(opcode->avariant &&
23349 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 23350 {
84b52b66 23351 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 23352 return;
b99bd4ef 23353 }
c19d1205 23354 if (inst.size_req)
b99bd4ef 23355 {
c19d1205
ZW
23356 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23357 return;
b99bd4ef
NC
23358 }
23359
c19d1205
ZW
23360 inst.instruction = opcode->avalue;
23361 if (opcode->tag == OT_unconditionalF)
eff0bc54 23362 inst.instruction |= 0xFU << 28;
c19d1205
ZW
23363 else
23364 inst.instruction |= inst.cond << 28;
23365 inst.size = INSN_SIZE;
5be8be5d 23366 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
23367 {
23368 it_fsm_pre_encode ();
23369 opcode->aencode ();
23370 it_fsm_post_encode ();
23371 }
ee065d83 23372 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 23373 on a hypothetical non-thumb v5 core. */
845b51d6 23374 if (is_bx)
e74cfd16 23375 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 23376 else
e74cfd16
PB
23377 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23378 *opcode->avariant);
88714cb8
DG
23379
23380 check_neon_suffixes;
23381
cd000bff 23382 if (!inst.error)
c877a2f2
NC
23383 {
23384 mapping_state (MAP_ARM);
23385 }
b99bd4ef 23386 }
3e9e4fcf
JB
23387 else
23388 {
23389 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23390 "-- `%s'"), str);
23391 return;
23392 }
c19d1205
ZW
23393 output_inst (str);
23394}
b99bd4ef 23395
e07e6e58 23396static void
5ee91343 23397check_pred_blocks_finished (void)
e07e6e58
NC
23398{
23399#ifdef OBJ_ELF
23400 asection *sect;
23401
23402 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
23403 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23404 == MANUAL_PRED_BLOCK)
e07e6e58 23405 {
5ee91343
AV
23406 if (now_pred.type == SCALAR_PRED)
23407 as_warn (_("section '%s' finished with an open IT block."),
23408 sect->name);
23409 else
23410 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23411 sect->name);
e07e6e58
NC
23412 }
23413#else
5ee91343
AV
23414 if (now_pred.state == MANUAL_PRED_BLOCK)
23415 {
23416 if (now_pred.type == SCALAR_PRED)
23417 as_warn (_("file finished with an open IT block."));
23418 else
23419 as_warn (_("file finished with an open VPT/VPST block."));
23420 }
e07e6e58
NC
23421#endif
23422}
23423
c19d1205
ZW
23424/* Various frobbings of labels and their addresses. */
23425
23426void
23427arm_start_line_hook (void)
23428{
23429 last_label_seen = NULL;
b99bd4ef
NC
23430}
23431
c19d1205
ZW
23432void
23433arm_frob_label (symbolS * sym)
b99bd4ef 23434{
c19d1205 23435 last_label_seen = sym;
b99bd4ef 23436
c19d1205 23437 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 23438
c19d1205
ZW
23439#if defined OBJ_COFF || defined OBJ_ELF
23440 ARM_SET_INTERWORK (sym, support_interwork);
23441#endif
b99bd4ef 23442
e07e6e58
NC
23443 force_automatic_it_block_close ();
23444
5f4273c7 23445 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
23446 as Thumb functions. This is because these labels, whilst
23447 they exist inside Thumb code, are not the entry points for
23448 possible ARM->Thumb calls. Also, these labels can be used
23449 as part of a computed goto or switch statement. eg gcc
23450 can generate code that looks like this:
b99bd4ef 23451
c19d1205
ZW
23452 ldr r2, [pc, .Laaa]
23453 lsl r3, r3, #2
23454 ldr r2, [r3, r2]
23455 mov pc, r2
b99bd4ef 23456
c19d1205
ZW
23457 .Lbbb: .word .Lxxx
23458 .Lccc: .word .Lyyy
23459 ..etc...
23460 .Laaa: .word Lbbb
b99bd4ef 23461
c19d1205
ZW
23462 The first instruction loads the address of the jump table.
23463 The second instruction converts a table index into a byte offset.
23464 The third instruction gets the jump address out of the table.
23465 The fourth instruction performs the jump.
b99bd4ef 23466
c19d1205
ZW
23467 If the address stored at .Laaa is that of a symbol which has the
23468 Thumb_Func bit set, then the linker will arrange for this address
23469 to have the bottom bit set, which in turn would mean that the
23470 address computation performed by the third instruction would end
23471 up with the bottom bit set. Since the ARM is capable of unaligned
23472 word loads, the instruction would then load the incorrect address
23473 out of the jump table, and chaos would ensue. */
23474 if (label_is_thumb_function_name
23475 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
fd361982 23476 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
b99bd4ef 23477 {
c19d1205
ZW
23478 /* When the address of a Thumb function is taken the bottom
23479 bit of that address should be set. This will allow
23480 interworking between Arm and Thumb functions to work
23481 correctly. */
b99bd4ef 23482
c19d1205 23483 THUMB_SET_FUNC (sym, 1);
b99bd4ef 23484
c19d1205 23485 label_is_thumb_function_name = FALSE;
b99bd4ef 23486 }
07a53e5c 23487
07a53e5c 23488 dwarf2_emit_label (sym);
b99bd4ef
NC
23489}
23490
c921be7d 23491bfd_boolean
c19d1205 23492arm_data_in_code (void)
b99bd4ef 23493{
c19d1205 23494 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 23495 {
c19d1205
ZW
23496 *input_line_pointer = '/';
23497 input_line_pointer += 5;
23498 *input_line_pointer = 0;
c921be7d 23499 return TRUE;
b99bd4ef
NC
23500 }
23501
c921be7d 23502 return FALSE;
b99bd4ef
NC
23503}
23504
c19d1205
ZW
23505char *
23506arm_canonicalize_symbol_name (char * name)
b99bd4ef 23507{
c19d1205 23508 int len;
b99bd4ef 23509
c19d1205
ZW
23510 if (thumb_mode && (len = strlen (name)) > 5
23511 && streq (name + len - 5, "/data"))
23512 *(name + len - 5) = 0;
b99bd4ef 23513
c19d1205 23514 return name;
b99bd4ef 23515}
c19d1205
ZW
23516\f
23517/* Table of all register names defined by default. The user can
23518 define additional names with .req. Note that all register names
23519 should appear in both upper and lowercase variants. Some registers
23520 also have mixed-case names. */
b99bd4ef 23521
dcbf9037 23522#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 23523#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 23524#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
23525#define REGSET(p,t) \
23526 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23527 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23528 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23529 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
23530#define REGSETH(p,t) \
23531 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23532 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23533 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23534 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23535#define REGSET2(p,t) \
23536 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23537 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23538 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23539 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
23540#define SPLRBANK(base,bank,t) \
23541 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23542 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23543 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23544 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23545 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23546 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 23547
c19d1205 23548static const struct reg_entry reg_names[] =
7ed4c4c5 23549{
c19d1205
ZW
23550 /* ARM integer registers. */
23551 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 23552
c19d1205
ZW
23553 /* ATPCS synonyms. */
23554 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23555 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23556 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 23557
c19d1205
ZW
23558 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23559 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23560 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 23561
c19d1205
ZW
23562 /* Well-known aliases. */
23563 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23564 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23565
23566 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23567 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23568
1b883319
AV
23569 /* Defining the new Zero register from ARMv8.1-M. */
23570 REGDEF(zr,15,ZR),
23571 REGDEF(ZR,15,ZR),
23572
c19d1205
ZW
23573 /* Coprocessor numbers. */
23574 REGSET(p, CP), REGSET(P, CP),
23575
23576 /* Coprocessor register numbers. The "cr" variants are for backward
23577 compatibility. */
23578 REGSET(c, CN), REGSET(C, CN),
23579 REGSET(cr, CN), REGSET(CR, CN),
23580
90ec0d68
MGD
23581 /* ARM banked registers. */
23582 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23583 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23584 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23585 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23586 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23587 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23588 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23589
23590 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23591 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23592 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23593 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23594 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 23595 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
23596 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23597 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23598
23599 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23600 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23601 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23602 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23603 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23604 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23605 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 23606 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
23607 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23608
c19d1205
ZW
23609 /* FPA registers. */
23610 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23611 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23612
23613 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23614 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23615
23616 /* VFP SP registers. */
5287ad62
JB
23617 REGSET(s,VFS), REGSET(S,VFS),
23618 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
23619
23620 /* VFP DP Registers. */
5287ad62
JB
23621 REGSET(d,VFD), REGSET(D,VFD),
23622 /* Extra Neon DP registers. */
23623 REGSETH(d,VFD), REGSETH(D,VFD),
23624
23625 /* Neon QP registers. */
23626 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
23627
23628 /* VFP control registers. */
23629 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23630 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
23631 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23632 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23633 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23634 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 23635 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
23636 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23637 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23638 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23639 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
23640
23641 /* Maverick DSP coprocessor registers. */
23642 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23643 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23644
23645 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23646 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23647 REGDEF(dspsc,0,DSPSC),
23648
23649 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23650 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23651 REGDEF(DSPSC,0,DSPSC),
23652
23653 /* iWMMXt data registers - p0, c0-15. */
23654 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23655
23656 /* iWMMXt control registers - p1, c0-3. */
23657 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23658 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23659 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23660 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23661
23662 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23663 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23664 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23665 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23666 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23667
23668 /* XScale accumulator registers. */
23669 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23670};
23671#undef REGDEF
23672#undef REGNUM
23673#undef REGSET
7ed4c4c5 23674
c19d1205
ZW
23675/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23676 within psr_required_here. */
23677static const struct asm_psr psrs[] =
23678{
23679 /* Backward compatibility notation. Note that "all" is no longer
23680 truly all possible PSR bits. */
23681 {"all", PSR_c | PSR_f},
23682 {"flg", PSR_f},
23683 {"ctl", PSR_c},
23684
23685 /* Individual flags. */
23686 {"f", PSR_f},
23687 {"c", PSR_c},
23688 {"x", PSR_x},
23689 {"s", PSR_s},
59b42a0d 23690
c19d1205
ZW
23691 /* Combinations of flags. */
23692 {"fs", PSR_f | PSR_s},
23693 {"fx", PSR_f | PSR_x},
23694 {"fc", PSR_f | PSR_c},
23695 {"sf", PSR_s | PSR_f},
23696 {"sx", PSR_s | PSR_x},
23697 {"sc", PSR_s | PSR_c},
23698 {"xf", PSR_x | PSR_f},
23699 {"xs", PSR_x | PSR_s},
23700 {"xc", PSR_x | PSR_c},
23701 {"cf", PSR_c | PSR_f},
23702 {"cs", PSR_c | PSR_s},
23703 {"cx", PSR_c | PSR_x},
23704 {"fsx", PSR_f | PSR_s | PSR_x},
23705 {"fsc", PSR_f | PSR_s | PSR_c},
23706 {"fxs", PSR_f | PSR_x | PSR_s},
23707 {"fxc", PSR_f | PSR_x | PSR_c},
23708 {"fcs", PSR_f | PSR_c | PSR_s},
23709 {"fcx", PSR_f | PSR_c | PSR_x},
23710 {"sfx", PSR_s | PSR_f | PSR_x},
23711 {"sfc", PSR_s | PSR_f | PSR_c},
23712 {"sxf", PSR_s | PSR_x | PSR_f},
23713 {"sxc", PSR_s | PSR_x | PSR_c},
23714 {"scf", PSR_s | PSR_c | PSR_f},
23715 {"scx", PSR_s | PSR_c | PSR_x},
23716 {"xfs", PSR_x | PSR_f | PSR_s},
23717 {"xfc", PSR_x | PSR_f | PSR_c},
23718 {"xsf", PSR_x | PSR_s | PSR_f},
23719 {"xsc", PSR_x | PSR_s | PSR_c},
23720 {"xcf", PSR_x | PSR_c | PSR_f},
23721 {"xcs", PSR_x | PSR_c | PSR_s},
23722 {"cfs", PSR_c | PSR_f | PSR_s},
23723 {"cfx", PSR_c | PSR_f | PSR_x},
23724 {"csf", PSR_c | PSR_s | PSR_f},
23725 {"csx", PSR_c | PSR_s | PSR_x},
23726 {"cxf", PSR_c | PSR_x | PSR_f},
23727 {"cxs", PSR_c | PSR_x | PSR_s},
23728 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23729 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23730 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23731 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23732 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23733 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23734 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23735 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23736 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23737 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23738 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23739 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23740 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23741 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23742 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23743 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23744 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23745 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23746 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23747 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23748 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23749 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23750 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23751 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23752};
23753
62b3e311
PB
23754/* Table of V7M psr names. */
23755static const struct asm_psr v7m_psrs[] =
23756{
1a336194
TP
23757 {"apsr", 0x0 }, {"APSR", 0x0 },
23758 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23759 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23760 {"psr", 0x3 }, {"PSR", 0x3 },
23761 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23762 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23763 {"epsr", 0x6 }, {"EPSR", 0x6 },
23764 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23765 {"msp", 0x8 }, {"MSP", 0x8 },
23766 {"psp", 0x9 }, {"PSP", 0x9 },
23767 {"msplim", 0xa }, {"MSPLIM", 0xa },
23768 {"psplim", 0xb }, {"PSPLIM", 0xb },
23769 {"primask", 0x10}, {"PRIMASK", 0x10},
23770 {"basepri", 0x11}, {"BASEPRI", 0x11},
23771 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
23772 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23773 {"control", 0x14}, {"CONTROL", 0x14},
23774 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23775 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23776 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
23777 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
23778 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
23779 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
23780 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
23781 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
23782 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
23783};
23784
c19d1205
ZW
23785/* Table of all shift-in-operand names. */
23786static const struct asm_shift_name shift_names [] =
b99bd4ef 23787{
c19d1205
ZW
23788 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
23789 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
23790 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
23791 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
23792 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
23793 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
23794 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 23795};
b99bd4ef 23796
c19d1205
ZW
23797/* Table of all explicit relocation names. */
23798#ifdef OBJ_ELF
23799static struct reloc_entry reloc_names[] =
23800{
23801 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
23802 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
23803 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
23804 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
23805 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
23806 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
23807 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
23808 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
23809 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
23810 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 23811 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
23812 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
23813 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 23814 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 23815 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 23816 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 23817 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
23818 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
23819 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
23820 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
23821 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23822 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23823 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
23824 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
23825 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
23826 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
23827 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
23828};
23829#endif
b99bd4ef 23830
5ee91343 23831/* Table of all conditional affixes. */
c19d1205
ZW
23832static const struct asm_cond conds[] =
23833{
23834 {"eq", 0x0},
23835 {"ne", 0x1},
23836 {"cs", 0x2}, {"hs", 0x2},
23837 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
23838 {"mi", 0x4},
23839 {"pl", 0x5},
23840 {"vs", 0x6},
23841 {"vc", 0x7},
23842 {"hi", 0x8},
23843 {"ls", 0x9},
23844 {"ge", 0xa},
23845 {"lt", 0xb},
23846 {"gt", 0xc},
23847 {"le", 0xd},
23848 {"al", 0xe}
23849};
5ee91343
AV
23850static const struct asm_cond vconds[] =
23851{
23852 {"t", 0xf},
23853 {"e", 0x10}
23854};
bfae80f2 23855
e797f7e0 23856#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
23857 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
23858 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 23859
62b3e311
PB
23860static struct asm_barrier_opt barrier_opt_names[] =
23861{
e797f7e0
MGD
23862 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
23863 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
23864 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
23865 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
23866 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
23867 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
23868 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
23869 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
23870 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
23871 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
23872 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
23873 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
23874 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
23875 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
23876 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
23877 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
23878};
23879
e797f7e0
MGD
23880#undef UL_BARRIER
23881
c19d1205
ZW
23882/* Table of ARM-format instructions. */
23883
23884/* Macros for gluing together operand strings. N.B. In all cases
23885 other than OPS0, the trailing OP_stop comes from default
23886 zero-initialization of the unspecified elements of the array. */
23887#define OPS0() { OP_stop, }
23888#define OPS1(a) { OP_##a, }
23889#define OPS2(a,b) { OP_##a,OP_##b, }
23890#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
23891#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
23892#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
23893#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
23894
5be8be5d
DG
23895/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
23896 This is useful when mixing operands for ARM and THUMB, i.e. using the
23897 MIX_ARM_THUMB_OPERANDS macro.
23898 In order to use these macros, prefix the number of operands with _
23899 e.g. _3. */
23900#define OPS_1(a) { a, }
23901#define OPS_2(a,b) { a,b, }
23902#define OPS_3(a,b,c) { a,b,c, }
23903#define OPS_4(a,b,c,d) { a,b,c,d, }
23904#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
23905#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
23906
c19d1205
ZW
23907/* These macros abstract out the exact format of the mnemonic table and
23908 save some repeated characters. */
23909
23910/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
23911#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23912 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 23913 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23914
23915/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
23916 a T_MNEM_xyz enumerator. */
23917#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23918 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23919#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23920 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
23921
23922/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
23923 infix after the third character. */
23924#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 23925 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 23926 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 23927#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 23928 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 23929 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23930#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23931 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 23932#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23933 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23934#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23935 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 23936#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23937 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 23938
c19d1205 23939/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
23940 field is still 0xE. Many of the Thumb variants can be executed
23941 conditionally, so this is checked separately. */
c19d1205 23942#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23943 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23944 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23945
dd5181d5
KT
23946/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
23947 Used by mnemonics that have very minimal differences in the encoding for
23948 ARM and Thumb variants and can be handled in a common function. */
23949#define TUEc(mnem, op, top, nops, ops, en) \
23950 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23951 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 23952
c19d1205
ZW
23953/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
23954 condition code field. */
23955#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 23956 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23957 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23958
23959/* ARM-only variants of all the above. */
6a86118a 23960#define CE(mnem, op, nops, ops, ae) \
5ee91343 23961 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23962
23963#define C3(mnem, op, nops, ops, ae) \
5ee91343 23964 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 23965
cf3cf39d
TP
23966/* Thumb-only variants of TCE and TUE. */
23967#define ToC(mnem, top, nops, ops, te) \
23968 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23969 do_##te, 0 }
cf3cf39d
TP
23970
23971#define ToU(mnem, top, nops, ops, te) \
23972 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 23973 NULL, do_##te, 0 }
cf3cf39d 23974
4389b29a
AV
23975/* T_MNEM_xyz enumerator variants of ToC. */
23976#define toC(mnem, top, nops, ops, te) \
23977 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23978 do_##te, 0 }
4389b29a 23979
f6b2b12d
AV
23980/* T_MNEM_xyz enumerator variants of ToU. */
23981#define toU(mnem, top, nops, ops, te) \
23982 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 23983 NULL, do_##te, 0 }
f6b2b12d 23984
e3cb604e
PB
23985/* Legacy mnemonics that always have conditional infix after the third
23986 character. */
23987#define CL(mnem, op, nops, ops, ae) \
21d799b5 23988 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 23989 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 23990
8f06b2d8
PB
23991/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
23992#define cCE(mnem, op, nops, ops, ae) \
5ee91343 23993 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 23994
57785aa2
AV
23995/* mov instructions that are shared between coprocessor and MVE. */
23996#define mcCE(mnem, op, nops, ops, ae) \
23997 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
23998
e3cb604e
PB
23999/* Legacy coprocessor instructions where conditional infix and conditional
24000 suffix are ambiguous. For consistency this includes all FPA instructions,
24001 not just the potentially ambiguous ones. */
24002#define cCL(mnem, op, nops, ops, ae) \
21d799b5 24003 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24004 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
24005
24006/* Coprocessor, takes either a suffix or a position-3 infix
24007 (for an FPA corner case). */
24008#define C3E(mnem, op, nops, ops, ae) \
21d799b5 24009 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 24010 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24011
6a86118a 24012#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
24013 { m1 #m2 m3, OPS##nops ops, \
24014 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 24015 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24016
24017#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
24018 xCM_ (m1, , m2, op, nops, ops, ae), \
24019 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24020 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24021 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24022 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24023 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24024 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24025 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24026 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24027 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24028 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24029 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24030 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24031 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24032 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24033 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24034 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24035 xCM_ (m1, le, m2, op, nops, ops, ae), \
24036 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
24037
24038#define UE(mnem, op, nops, ops, ae) \
5ee91343 24039 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24040
24041#define UF(mnem, op, nops, ops, ae) \
5ee91343 24042 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24043
5287ad62
JB
24044/* Neon data-processing. ARM versions are unconditional with cond=0xf.
24045 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24046 use the same encoding function for each. */
24047#define NUF(mnem, op, nops, ops, enc) \
24048 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 24049 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24050
24051/* Neon data processing, version which indirects through neon_enc_tab for
24052 the various overloaded versions of opcodes. */
24053#define nUF(mnem, op, nops, ops, enc) \
21d799b5 24054 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 24055 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24056
24057/* Neon insn with conditional suffix for the ARM version, non-overloaded
24058 version. */
5ee91343 24059#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 24060 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 24061 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24062
037e8744 24063#define NCE(mnem, op, nops, ops, enc) \
5ee91343 24064 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24065
24066#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 24067 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 24068
5287ad62 24069/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 24070#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 24071 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 24072 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24073
037e8744 24074#define nCE(mnem, op, nops, ops, enc) \
5ee91343 24075 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24076
24077#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
24078 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24079
24080/* */
24081#define mCEF(mnem, op, nops, ops, enc) \
a302e574 24082 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
24083 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24084
24085
24086/* nCEF but for MVE predicated instructions. */
24087#define mnCEF(mnem, op, nops, ops, enc) \
24088 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24089
24090/* nCE but for MVE predicated instructions. */
24091#define mnCE(mnem, op, nops, ops, enc) \
24092 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 24093
5ee91343
AV
24094/* NUF but for potentially MVE predicated instructions. */
24095#define MNUF(mnem, op, nops, ops, enc) \
24096 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24097 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24098
24099/* nUF but for potentially MVE predicated instructions. */
24100#define mnUF(mnem, op, nops, ops, enc) \
24101 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24102 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24103
24104/* ToC but for potentially MVE predicated instructions. */
24105#define mToC(mnem, top, nops, ops, te) \
24106 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24107 do_##te, 1 }
24108
24109/* NCE but for MVE predicated instructions. */
24110#define MNCE(mnem, op, nops, ops, enc) \
24111 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24112
24113/* NCEF but for MVE predicated instructions. */
24114#define MNCEF(mnem, op, nops, ops, enc) \
24115 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
24116#define do_0 0
24117
c19d1205 24118static const struct asm_opcode insns[] =
bfae80f2 24119{
74db7efb
NC
24120#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24121#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
24122 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24123 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24124 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24125 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24126 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24127 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24128 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24129 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24130 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24131 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24132 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24133 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24134 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24135 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24136 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24137 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
24138
24139 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24140 for setting PSR flag bits. They are obsolete in V6 and do not
24141 have Thumb equivalents. */
21d799b5
NC
24142 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24143 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24144 CL("tstp", 110f000, 2, (RR, SH), cmp),
24145 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24146 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24147 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24148 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24149 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24150 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24151
24152 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 24153 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
24154 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24155 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24156
24157 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
24158 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24159 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24160 OP_RRnpc),
24161 OP_ADDRGLDR),ldst, t_ldst),
24162 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
24163
24164 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24165 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24166 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24167 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24168 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24169 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24170
21d799b5
NC
24171 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24172 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 24173
c19d1205 24174 /* Pseudo ops. */
21d799b5 24175 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 24176 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 24177 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 24178 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
24179
24180 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
24181 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24182 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24183 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24184 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24185 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24186 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24187 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24188 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24189 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24190 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24191 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24192 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 24193
16a4cf17 24194 /* These may simplify to neg. */
21d799b5
NC
24195 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24196 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 24197
173205ca
TP
24198#undef THUMB_VARIANT
24199#define THUMB_VARIANT & arm_ext_os
24200
24201 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24202 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24203
c921be7d
NC
24204#undef THUMB_VARIANT
24205#define THUMB_VARIANT & arm_ext_v6
24206
21d799b5 24207 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
24208
24209 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
24210#undef THUMB_VARIANT
24211#define THUMB_VARIANT & arm_ext_v6t2
24212
21d799b5
NC
24213 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24214 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24215 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 24216
5be8be5d
DG
24217 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24218 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24219 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24220 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 24221
21d799b5
NC
24222 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24223 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 24224
21d799b5
NC
24225 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24226 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
24227
24228 /* V1 instructions with no Thumb analogue at all. */
21d799b5 24229 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
24230 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24231
24232 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24233 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24234 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24235 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24236 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24237 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24238 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24239 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24240
c921be7d
NC
24241#undef ARM_VARIANT
24242#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24243#undef THUMB_VARIANT
24244#define THUMB_VARIANT & arm_ext_v4t
24245
21d799b5
NC
24246 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24247 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 24248
c921be7d
NC
24249#undef THUMB_VARIANT
24250#define THUMB_VARIANT & arm_ext_v6t2
24251
21d799b5 24252 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
24253 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24254
24255 /* Generic coprocessor instructions. */
21d799b5
NC
24256 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24257 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24258 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24259 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24260 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24261 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 24262 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24263
c921be7d
NC
24264#undef ARM_VARIANT
24265#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24266
21d799b5 24267 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
24268 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24269
c921be7d
NC
24270#undef ARM_VARIANT
24271#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24272#undef THUMB_VARIANT
24273#define THUMB_VARIANT & arm_ext_msr
24274
d2cd1205
JB
24275 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24276 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 24277
c921be7d
NC
24278#undef ARM_VARIANT
24279#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24280#undef THUMB_VARIANT
24281#define THUMB_VARIANT & arm_ext_v6t2
24282
21d799b5
NC
24283 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24284 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24285 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24286 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24287 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24288 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24289 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24290 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 24291
c921be7d
NC
24292#undef ARM_VARIANT
24293#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24294#undef THUMB_VARIANT
24295#define THUMB_VARIANT & arm_ext_v4t
24296
5be8be5d
DG
24297 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24298 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24299 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24300 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
24301 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24302 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 24303
c921be7d
NC
24304#undef ARM_VARIANT
24305#define ARM_VARIANT & arm_ext_v4t_5
24306
c19d1205
ZW
24307 /* ARM Architecture 4T. */
24308 /* Note: bx (and blx) are required on V5, even if the processor does
24309 not support Thumb. */
21d799b5 24310 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 24311
c921be7d
NC
24312#undef ARM_VARIANT
24313#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24314#undef THUMB_VARIANT
24315#define THUMB_VARIANT & arm_ext_v5t
24316
c19d1205
ZW
24317 /* Note: blx has 2 variants; the .value coded here is for
24318 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
24319 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24320 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 24321
c921be7d
NC
24322#undef THUMB_VARIANT
24323#define THUMB_VARIANT & arm_ext_v6t2
24324
21d799b5
NC
24325 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24326 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24327 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24328 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24329 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24330 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24331 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24332 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24333
c921be7d 24334#undef ARM_VARIANT
74db7efb
NC
24335#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24336#undef THUMB_VARIANT
24337#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 24338
21d799b5
NC
24339 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24340 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24341 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24342 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24343
21d799b5
NC
24344 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24345 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24346
21d799b5
NC
24347 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24348 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24349 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24350 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 24351
21d799b5
NC
24352 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24353 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24354 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24355 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24356
21d799b5
NC
24357 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24358 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24359
03ee1b7f
NC
24360 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24361 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24362 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24363 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 24364
c921be7d 24365#undef ARM_VARIANT
74db7efb
NC
24366#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24367#undef THUMB_VARIANT
24368#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24369
21d799b5 24370 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
24371 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24372 ldrd, t_ldstd),
24373 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24374 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 24375
21d799b5
NC
24376 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24377 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 24378
c921be7d
NC
24379#undef ARM_VARIANT
24380#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24381
21d799b5 24382 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 24383
c921be7d
NC
24384#undef ARM_VARIANT
24385#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24386#undef THUMB_VARIANT
24387#define THUMB_VARIANT & arm_ext_v6
24388
21d799b5
NC
24389 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24390 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24391 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24392 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24393 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24394 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24395 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24396 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24397 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24398 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 24399
c921be7d 24400#undef THUMB_VARIANT
ff8646ee 24401#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 24402
5be8be5d
DG
24403 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24404 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24405 strex, t_strex),
ff8646ee
TP
24406#undef THUMB_VARIANT
24407#define THUMB_VARIANT & arm_ext_v6t2
24408
21d799b5
NC
24409 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24410 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 24411
21d799b5
NC
24412 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24413 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 24414
9e3c6df6 24415/* ARM V6 not included in V7M. */
c921be7d
NC
24416#undef THUMB_VARIANT
24417#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 24418 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 24419 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
24420 UF(rfeib, 9900a00, 1, (RRw), rfe),
24421 UF(rfeda, 8100a00, 1, (RRw), rfe),
24422 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24423 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
24424 UF(rfefa, 8100a00, 1, (RRw), rfe),
24425 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24426 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 24427 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
24428 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24429 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 24430 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 24431 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 24432 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 24433 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 24434 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 24435 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 24436 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 24437
9e3c6df6
PB
24438/* ARM V6 not included in V7M (eg. integer SIMD). */
24439#undef THUMB_VARIANT
24440#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
24441 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24442 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24443 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24444 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24445 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24446 /* Old name for QASX. */
74db7efb 24447 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24448 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24449 /* Old name for QSAX. */
74db7efb 24450 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24451 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24452 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24453 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24454 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24455 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24456 /* Old name for SASX. */
74db7efb 24457 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24458 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24459 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24460 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24461 /* Old name for SHASX. */
21d799b5 24462 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24463 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24464 /* Old name for SHSAX. */
21d799b5
NC
24465 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24466 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24467 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24468 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24469 /* Old name for SSAX. */
74db7efb 24470 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24471 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24472 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24473 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24474 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24475 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24476 /* Old name for UASX. */
74db7efb 24477 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24478 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24479 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24480 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24481 /* Old name for UHASX. */
21d799b5
NC
24482 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24483 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24484 /* Old name for UHSAX. */
21d799b5
NC
24485 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24486 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24487 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24488 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24489 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24490 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24491 /* Old name for UQASX. */
21d799b5
NC
24492 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24493 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24494 /* Old name for UQSAX. */
21d799b5
NC
24495 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24496 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24497 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24498 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24499 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24500 /* Old name for USAX. */
74db7efb 24501 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24502 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24503 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24504 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24505 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24506 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24507 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24508 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24509 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24510 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24511 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24512 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24513 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24514 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24515 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24516 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24517 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24518 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24519 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24520 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24521 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24522 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24523 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24524 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24525 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24526 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24527 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24528 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24529 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
24530 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24531 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24532 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24533 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24534 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 24535
c921be7d 24536#undef ARM_VARIANT
55e8aae7 24537#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 24538#undef THUMB_VARIANT
55e8aae7 24539#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 24540
21d799b5
NC
24541 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24542 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24543 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24544 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 24545
c921be7d
NC
24546#undef THUMB_VARIANT
24547#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
24548 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24549 ldrexd, t_ldrexd),
24550 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24551 RRnpcb), strexd, t_strexd),
ebdca51a 24552
c921be7d 24553#undef THUMB_VARIANT
ff8646ee 24554#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
24555 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24556 rd_rn, rd_rn),
24557 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24558 rd_rn, rd_rn),
24559 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24560 strex, t_strexbh),
5be8be5d 24561 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24562 strex, t_strexbh),
21d799b5 24563 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 24564
c921be7d 24565#undef ARM_VARIANT
f4c65163 24566#define ARM_VARIANT & arm_ext_sec
74db7efb 24567#undef THUMB_VARIANT
f4c65163 24568#define THUMB_VARIANT & arm_ext_sec
c921be7d 24569
21d799b5 24570 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 24571
90ec0d68
MGD
24572#undef ARM_VARIANT
24573#define ARM_VARIANT & arm_ext_virt
24574#undef THUMB_VARIANT
24575#define THUMB_VARIANT & arm_ext_virt
24576
24577 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24578 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24579
ddfded2f
MW
24580#undef ARM_VARIANT
24581#define ARM_VARIANT & arm_ext_pan
24582#undef THUMB_VARIANT
24583#define THUMB_VARIANT & arm_ext_pan
24584
24585 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24586
c921be7d 24587#undef ARM_VARIANT
74db7efb 24588#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
24589#undef THUMB_VARIANT
24590#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24591
21d799b5
NC
24592 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24593 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24594 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24595 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 24596
21d799b5 24597 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 24598 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 24599
5be8be5d
DG
24600 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24601 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24602 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24603 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 24604
91d8b670
JG
24605#undef ARM_VARIANT
24606#define ARM_VARIANT & arm_ext_v3
24607#undef THUMB_VARIANT
24608#define THUMB_VARIANT & arm_ext_v6t2
24609
24610 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
24611 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24612 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
24613
24614#undef ARM_VARIANT
24615#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
24616#undef THUMB_VARIANT
24617#define THUMB_VARIANT & arm_ext_v6t2_v8m
24618 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24619 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24620
bf3eeda7 24621 /* Thumb-only instructions. */
74db7efb 24622#undef ARM_VARIANT
bf3eeda7
NS
24623#define ARM_VARIANT NULL
24624 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24625 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
24626
24627 /* ARM does not really have an IT instruction, so always allow it.
24628 The opcode is copied from Thumb in order to allow warnings in
24629 -mimplicit-it=[never | arm] modes. */
24630#undef ARM_VARIANT
24631#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
24632#undef THUMB_VARIANT
24633#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24634
21d799b5
NC
24635 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24636 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24637 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24638 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24639 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24640 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24641 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24642 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24643 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24644 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24645 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24646 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24647 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24648 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24649 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 24650 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
24651 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24652 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 24653
92e90b6e 24654 /* Thumb2 only instructions. */
c921be7d
NC
24655#undef ARM_VARIANT
24656#define ARM_VARIANT NULL
92e90b6e 24657
21d799b5
NC
24658 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24659 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24660 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24661 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24662 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24663 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 24664
eea54501
MGD
24665 /* Hardware division instructions. */
24666#undef ARM_VARIANT
24667#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
24668#undef THUMB_VARIANT
24669#define THUMB_VARIANT & arm_ext_div
24670
eea54501
MGD
24671 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24672 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 24673
7e806470 24674 /* ARM V6M/V7 instructions. */
c921be7d
NC
24675#undef ARM_VARIANT
24676#define ARM_VARIANT & arm_ext_barrier
24677#undef THUMB_VARIANT
24678#define THUMB_VARIANT & arm_ext_barrier
24679
ccb84d65
JB
24680 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24681 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24682 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24683
62b3e311 24684 /* ARM V7 instructions. */
c921be7d
NC
24685#undef ARM_VARIANT
24686#define ARM_VARIANT & arm_ext_v7
24687#undef THUMB_VARIANT
24688#define THUMB_VARIANT & arm_ext_v7
24689
21d799b5
NC
24690 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24691 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24692
74db7efb 24693#undef ARM_VARIANT
60e5ef9f 24694#define ARM_VARIANT & arm_ext_mp
74db7efb 24695#undef THUMB_VARIANT
60e5ef9f
MGD
24696#define THUMB_VARIANT & arm_ext_mp
24697
24698 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24699
53c4b28b
MGD
24700 /* AArchv8 instructions. */
24701#undef ARM_VARIANT
24702#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24703
24704/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24705#undef THUMB_VARIANT
4ed7ed8d 24706#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24707
4ed7ed8d
TP
24708 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24709 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24710 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24711 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24712 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24713 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24714 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24715 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24716 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24717 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24718 stlex, t_stlex),
4b8c8c02
RE
24719 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24720 stlex, t_stlex),
24721 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24722 stlex, t_stlex),
4ed7ed8d
TP
24723#undef THUMB_VARIANT
24724#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24725
4ed7ed8d 24726 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24727 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24728 ldrexd, t_ldrexd),
24729 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24730 strexd, t_strexd),
f7dd2fb2
TC
24731
24732/* Defined in V8 but is in undefined encoding space for earlier
24733 architectures. However earlier architectures are required to treat
24734 this instuction as a semihosting trap as well. Hence while not explicitly
24735 defined as such, it is in fact correct to define the instruction for all
24736 architectures. */
24737#undef THUMB_VARIANT
24738#define THUMB_VARIANT & arm_ext_v1
24739#undef ARM_VARIANT
24740#define ARM_VARIANT & arm_ext_v1
24741 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24742
8884b720 24743 /* ARMv8 T32 only. */
74db7efb 24744#undef ARM_VARIANT
b79f7053
MGD
24745#define ARM_VARIANT NULL
24746 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24747 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24748 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24749
33399f07
MGD
24750 /* FP for ARMv8. */
24751#undef ARM_VARIANT
a715796b 24752#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24753#undef THUMB_VARIANT
a715796b 24754#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24755
24756 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24757 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24758 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24759 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24760 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24761 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24762 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24763 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24764 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24765 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24766 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 24767
91ff7894
MGD
24768 /* Crypto v1 extensions. */
24769#undef ARM_VARIANT
24770#define ARM_VARIANT & fpu_crypto_ext_armv8
24771#undef THUMB_VARIANT
24772#define THUMB_VARIANT & fpu_crypto_ext_armv8
24773
24774 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24775 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24776 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
24777 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
24778 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
24779 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
24780 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
24781 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
24782 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
24783 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
24784 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
24785 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
24786 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
24787 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 24788
dd5181d5 24789#undef ARM_VARIANT
8b301fbb 24790#define ARM_VARIANT & arm_ext_crc
dd5181d5 24791#undef THUMB_VARIANT
8b301fbb 24792#define THUMB_VARIANT & arm_ext_crc
dd5181d5
KT
24793 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
24794 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
24795 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
24796 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
24797 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
24798 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
24799
105bde57
MW
24800 /* ARMv8.2 RAS extension. */
24801#undef ARM_VARIANT
4d1464f2 24802#define ARM_VARIANT & arm_ext_ras
105bde57 24803#undef THUMB_VARIANT
4d1464f2 24804#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
24805 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
24806
49e8a725
SN
24807#undef ARM_VARIANT
24808#define ARM_VARIANT & arm_ext_v8_3
24809#undef THUMB_VARIANT
24810#define THUMB_VARIANT & arm_ext_v8_3
24811 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
24812
c604a79a
JW
24813#undef ARM_VARIANT
24814#define ARM_VARIANT & fpu_neon_ext_dotprod
24815#undef THUMB_VARIANT
24816#define THUMB_VARIANT & fpu_neon_ext_dotprod
24817 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
24818 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
24819
c921be7d
NC
24820#undef ARM_VARIANT
24821#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
24822#undef THUMB_VARIANT
24823#define THUMB_VARIANT NULL
c921be7d 24824
21d799b5
NC
24825 cCE("wfs", e200110, 1, (RR), rd),
24826 cCE("rfs", e300110, 1, (RR), rd),
24827 cCE("wfc", e400110, 1, (RR), rd),
24828 cCE("rfc", e500110, 1, (RR), rd),
24829
24830 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
24831 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
24832 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
24833 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
24834
24835 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
24836 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
24837 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
24838 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
24839
24840 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
24841 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
24842 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
24843 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
24844 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
24845 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
24846 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
24847 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
24848 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
24849 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
24850 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
24851 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
24852
24853 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
24854 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
24855 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
24856 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
24857 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
24858 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
24859 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
24860 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
24861 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
24862 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
24863 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
24864 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
24865
24866 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
24867 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
24868 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
24869 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
24870 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
24871 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
24872 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
24873 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
24874 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
24875 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
24876 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
24877 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
24878
24879 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
24880 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
24881 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
24882 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
24883 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
24884 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
24885 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
24886 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
24887 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
24888 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
24889 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
24890 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
24891
24892 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
24893 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
24894 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
24895 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
24896 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
24897 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
24898 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
24899 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
24900 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
24901 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
24902 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
24903 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
24904
24905 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
24906 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
24907 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
24908 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
24909 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
24910 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
24911 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
24912 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
24913 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
24914 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
24915 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
24916 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
24917
24918 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
24919 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
24920 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
24921 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
24922 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
24923 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
24924 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
24925 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
24926 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
24927 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
24928 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
24929 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
24930
24931 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
24932 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
24933 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
24934 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
24935 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
24936 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
24937 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
24938 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
24939 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
24940 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
24941 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
24942 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
24943
24944 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
24945 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
24946 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
24947 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
24948 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
24949 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
24950 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
24951 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
24952 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
24953 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
24954 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
24955 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
24956
24957 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
24958 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
24959 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
24960 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
24961 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
24962 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
24963 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
24964 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
24965 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
24966 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
24967 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
24968 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
24969
24970 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
24971 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
24972 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
24973 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
24974 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
24975 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
24976 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
24977 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
24978 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
24979 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
24980 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
24981 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
24982
24983 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
24984 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
24985 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
24986 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
24987 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
24988 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
24989 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
24990 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
24991 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
24992 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
24993 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
24994 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
24995
24996 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
24997 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
24998 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
24999 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25000 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25001 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25002 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25003 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25004 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25005 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25006 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25007 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25008
25009 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25010 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25011 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25012 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25013 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25014 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25015 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25016 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25017 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25018 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25019 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25020 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25021
25022 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25023 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25024 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25025 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25026 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25027 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25028 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25029 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25030 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25031 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25032 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25033 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25034
25035 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25036 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25037 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25038 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25039 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25040 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25041 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25042 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25043 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25044 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25045 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25046 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25047
25048 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25049 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25050 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25051 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25052 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25053 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25054 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25055 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25056 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25057 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25058 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25059 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25060
25061 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25062 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25063 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25064 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25065 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25066 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25067 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25068 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25069 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25070 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25071 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25072 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25073
25074 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25075 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25076 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25077 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25078 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25079 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25080 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25081 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25082 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25083 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25084 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25085 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25086
25087 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25088 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25089 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25090 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25091 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25092 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25093 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25094 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25095 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25096 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25097 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25098 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25099
25100 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25101 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25102 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25103 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25104 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25105 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25106 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25107 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25108 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25109 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25110 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25111 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25112
25113 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25114 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25115 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25116 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25117 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25118 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25119 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25120 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25121 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25122 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25123 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25124 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25125
25126 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25127 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25128 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25129 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25130 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25131 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25132 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25133 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25134 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25135 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25136 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25137 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25138
25139 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25140 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25141 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25142 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25143 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25144 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25145 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25146 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25147 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25148 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25149 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25150 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25151
25152 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25153 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25154 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25155 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25156 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25157 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25158 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25159 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25160 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25161 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25162 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25163 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25164
25165 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25166 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25167 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25168 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25169 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25170 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25171 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25172 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25173 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25174 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25175 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25176 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25177
25178 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25179 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25180 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25181 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25182 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25183 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25184 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25185 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25186 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25187 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25188 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25189 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25190
25191 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25192 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25193 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25194 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25195 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25196 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25197 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25198 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25199 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25200 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25201 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25202 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25203
25204 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25205 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25206 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25207 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25208 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25209 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25210 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25211 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25212 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25213 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25214 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25215 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25216
25217 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25218 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25219 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25220 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25221
25222 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25223 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25224 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25225 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25226 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25227 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25228 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25229 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25230 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25231 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25232 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25233 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 25234
c19d1205
ZW
25235 /* The implementation of the FIX instruction is broken on some
25236 assemblers, in that it accepts a precision specifier as well as a
25237 rounding specifier, despite the fact that this is meaningless.
25238 To be more compatible, we accept it as well, though of course it
25239 does not set any bits. */
21d799b5
NC
25240 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25241 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25242 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25243 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25244 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25245 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25246 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25247 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25248 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25249 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25250 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25251 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25252 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 25253
c19d1205 25254 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
25255#undef ARM_VARIANT
25256#define ARM_VARIANT & fpu_fpa_ext_v2
25257
21d799b5
NC
25258 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25259 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25260 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25261 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25262 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25263 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 25264
c921be7d
NC
25265#undef ARM_VARIANT
25266#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
25267#undef THUMB_VARIANT
25268#define THUMB_VARIANT & arm_ext_v6t2
25269 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25270 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
ef8f595f
MI
25271 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25272 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25273 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25274 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
90e9955a
SP
25275
25276 /* Memory operations. */
25277 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25278 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25279 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25280 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
ba6cd17f 25281#undef THUMB_VARIANT
c921be7d 25282
c19d1205 25283 /* Moves and type conversions. */
21d799b5
NC
25284 cCE("fmstat", ef1fa10, 0, (), noargs),
25285 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25286 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25287 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25288 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25289 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25290 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25291 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25292 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
25293
25294 /* Memory operations. */
55881a11 25295 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25296 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25297 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25298 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25299 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25300 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
55881a11 25301 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25302 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25303 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25304 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25305 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25306 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 25307
c19d1205 25308 /* Monadic operations. */
21d799b5
NC
25309 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25310 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25311 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
25312
25313 /* Dyadic operations. */
21d799b5
NC
25314 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25315 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25316 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25317 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25318 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25319 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25320 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25321 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25322 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 25323
c19d1205 25324 /* Comparisons. */
21d799b5
NC
25325 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25326 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25327 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25328 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 25329
62f3b8c8
PB
25330 /* Double precision load/store are still present on single precision
25331 implementations. */
55881a11
MGD
25332 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25333 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25334 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25335 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25336 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25337 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25338 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25339 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 25340
c921be7d
NC
25341#undef ARM_VARIANT
25342#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25343
c19d1205 25344 /* Moves and type conversions. */
21d799b5
NC
25345 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25346 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25347 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25348 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25349 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25350 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25351 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25352 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25353 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25354 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25355 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25356 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 25357
c19d1205 25358 /* Monadic operations. */
21d799b5
NC
25359 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25360 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25361 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
25362
25363 /* Dyadic operations. */
21d799b5
NC
25364 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25365 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25366 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25367 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25368 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25369 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25370 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25371 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25372 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 25373
c19d1205 25374 /* Comparisons. */
21d799b5
NC
25375 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25376 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25377 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25378 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 25379
037e8744
JB
25380/* Instructions which may belong to either the Neon or VFP instruction sets.
25381 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
25382#undef ARM_VARIANT
25383#define ARM_VARIANT & fpu_vfp_ext_v1xd
ef8f595f
MI
25384#undef THUMB_VARIANT
25385#define THUMB_VARIANT & arm_ext_v6t2
25386
25387 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25388 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25389 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25390 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25391 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25392 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25393
25394 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25395 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25396
c921be7d
NC
25397#undef THUMB_VARIANT
25398#define THUMB_VARIANT & fpu_vfp_ext_v1xd
25399
037e8744
JB
25400 /* These mnemonics are unique to VFP. */
25401 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25402 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
25403 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25404 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25405 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
25406 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25407
25408 /* Mnemonics shared by Neon and VFP. */
21d799b5 25409 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 25410
dd9634d9 25411 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 25412 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
25413 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25414 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 25415
037e8744
JB
25416
25417 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
25418 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25419
32c36c3c
AV
25420#undef THUMB_VARIANT
25421/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25422 by different feature bits. Since we are setting the Thumb guard, we can
25423 require Thumb-1 which makes it a nop guard and set the right feature bit in
25424 do_vldr_vstr (). */
25425#define THUMB_VARIANT & arm_ext_v4t
25426 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25427 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25428
9db2f6b4
RL
25429#undef ARM_VARIANT
25430#define ARM_VARIANT & arm_ext_fp16
25431#undef THUMB_VARIANT
25432#define THUMB_VARIANT & arm_ext_fp16
25433 /* New instructions added from v8.2, allowing the extraction and insertion of
25434 the upper 16 bits of a 32-bit vector register. */
25435 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25436 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25437
dec41383 25438 /* New backported fma/fms instructions optional in v8.2. */
aab2c27d
MM
25439 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25440 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
dec41383 25441
c921be7d
NC
25442#undef THUMB_VARIANT
25443#define THUMB_VARIANT & fpu_neon_ext_v1
25444#undef ARM_VARIANT
25445#define ARM_VARIANT & fpu_neon_ext_v1
25446
5287ad62
JB
25447 /* Data processing with three registers of the same length. */
25448 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25449 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25450 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 25451 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 25452 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
25453 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25454 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25455 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 25456 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 25457 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 25458 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 25459 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
25460 shl should accept I8 I16 I32 I64,
25461 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25462 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25463 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 25464 /* Logic ops, types optional & ignored. */
4316f0d2 25465 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25466 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25467 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25468 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25469 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
25470 /* Bitfield ops, untyped. */
25471 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25472 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25473 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25474 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25475 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25476 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 25477 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 25478 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25479 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25480 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
25481 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25482 back to neon_dyadic_if_su. */
21d799b5
NC
25483 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25484 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25485 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25486 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25487 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25488 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25489 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25490 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 25491 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
25492 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25493 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 25494 /* As above, D registers only. */
21d799b5
NC
25495 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25496 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 25497 /* Int and float variants, signedness unimportant. */
21d799b5
NC
25498 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25499 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25500 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 25501 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
25502 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25503 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
25504 /* vtst takes sizes 8, 16, 32. */
25505 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25506 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25507 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 25508 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 25509 /* VQD{R}MULH takes S16 S32. */
21d799b5 25510 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 25511 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
25512 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25513 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25514 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25515 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
25516 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25517 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25518 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25519 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
25520 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25521 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25522 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25523 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 25524 /* ARM v8.1 extension. */
643afb90
MW
25525 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25526 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25527 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
25528
25529 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 25530 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
25531 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25532
25533 /* Data processing with two registers and a shift amount. */
25534 /* Right shifts, and variants with rounding.
25535 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25536 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
25537 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25538 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25539 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25540 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25541 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25542 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 25543 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
25544 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25545 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
25546 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25547 /* Right shift immediate, saturating & narrowing, with rounding variants.
25548 Types accepted S16 S32 S64 U16 U32 U64. */
25549 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25550 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25551 /* As above, unsigned. Types accepted S16 S32 S64. */
25552 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25553 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25554 /* Right shift narrowing. Types accepted I16 I32 I64. */
25555 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25556 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25557 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 25558 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 25559 /* CVT with optional immediate for fixed-point variant. */
21d799b5 25560 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 25561
4316f0d2 25562 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
25563
25564 /* Data processing, three registers of different lengths. */
25565 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25566 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
25567 /* If not scalar, fall back to neon_dyadic_long.
25568 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
25569 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25570 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
25571 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25572 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25573 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25574 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25575 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25576 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25577 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25578 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25579 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
25580 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25581 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25582 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
25583 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25584 S16 S32 U16 U32. */
21d799b5 25585 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
25586
25587 /* Extract. Size 8. */
3b8d421e
PB
25588 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25589 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
25590
25591 /* Two registers, miscellaneous. */
25592 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 25593 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 25594 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
25595 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25596 /* Vector replicate. Sizes 8 16 32. */
21d799b5 25597 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
25598 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25599 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25600 /* VMOVN. Types I16 I32 I64. */
21d799b5 25601 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 25602 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 25603 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 25604 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 25605 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
25606 /* VZIP / VUZP. Sizes 8 16 32. */
25607 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25608 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25609 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25610 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25611 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 25612 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
25613 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25614 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25615 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25616 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25617 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25618 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 25619 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
25620 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25621 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25622 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25623 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25624 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
25625 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25626 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
25627 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25628 /* VCNT. Size 8. */
25629 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25630 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25631 /* Two address, untyped. */
25632 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25633 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25634 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
25635 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25636 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
25637
25638 /* Table lookup. Size 8. */
25639 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25640 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25641
c921be7d
NC
25642#undef THUMB_VARIANT
25643#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25644#undef ARM_VARIANT
25645#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25646
5287ad62 25647 /* Neon element/structure load/store. */
21d799b5
NC
25648 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25649 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25650 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25651 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25652 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25653 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25654 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25655 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 25656
c921be7d 25657#undef THUMB_VARIANT
74db7efb
NC
25658#define THUMB_VARIANT & fpu_vfp_ext_v3xd
25659#undef ARM_VARIANT
25660#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
25661 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25662 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25663 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25664 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25665 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25666 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25667 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25668 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25669 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25670
74db7efb 25671#undef THUMB_VARIANT
c921be7d
NC
25672#define THUMB_VARIANT & fpu_vfp_ext_v3
25673#undef ARM_VARIANT
25674#define ARM_VARIANT & fpu_vfp_ext_v3
25675
21d799b5 25676 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 25677 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25678 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25679 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25680 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25681 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25682 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25683 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25684 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25685
74db7efb
NC
25686#undef ARM_VARIANT
25687#define ARM_VARIANT & fpu_vfp_ext_fma
25688#undef THUMB_VARIANT
25689#define THUMB_VARIANT & fpu_vfp_ext_fma
aab2c27d 25690 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
62f3b8c8
PB
25691 VFP FMA variant; NEON and VFP FMA always includes the NEON
25692 FMA instructions. */
d58196e0 25693 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
aab2c27d 25694 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
d58196e0
AV
25695 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25696
62f3b8c8
PB
25697 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25698 the v form should always be used. */
25699 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25700 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25701 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25702 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25703 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25704 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25705
5287ad62 25706#undef THUMB_VARIANT
c921be7d
NC
25707#undef ARM_VARIANT
25708#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25709
21d799b5
NC
25710 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25711 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25712 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25713 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25714 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25715 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25716 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25717 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25718
c921be7d
NC
25719#undef ARM_VARIANT
25720#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25721
21d799b5
NC
25722 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25723 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25724 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25725 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25726 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25727 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25728 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25729 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25730 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25731 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25732 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25733 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25734 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25735 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25736 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25737 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25738 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25739 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25740 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25741 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25742 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25743 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25744 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25745 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25746 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25747 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25748 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25749 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25750 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25751 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25752 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25753 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25754 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25755 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25756 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25757 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25758 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25759 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25760 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25761 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25762 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25763 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25764 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25765 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25766 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25767 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25768 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
25769 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25770 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25771 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25772 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25773 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25774 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25775 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25776 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25777 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25778 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25779 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25780 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25781 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25782 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25783 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25784 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25785 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25786 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25787 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25788 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25789 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25790 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25791 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25792 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25793 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25794 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25795 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25796 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25797 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25798 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25799 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25800 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25801 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25802 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25803 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25804 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25805 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25806 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25807 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25808 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25809 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25810 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
25811 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25812 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25813 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25814 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25815 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25816 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25817 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25818 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25819 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25820 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25821 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25822 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25823 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25824 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25825 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25826 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25827 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25828 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25829 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25830 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25831 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25832 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
25833 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25834 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25835 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25836 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25837 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25838 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25839 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25840 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25841 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25842 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25843 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25844 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25845 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25846 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25847 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25848 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25849 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25850 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25851 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25852 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25853 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25854 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25855 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25856 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25857 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25858 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25859 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25860 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25861 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25862 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25863 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25864 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
25865 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
25866 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
25867 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
25868 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
25869 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
25870 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25871 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25872 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25873 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
25874 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
25875 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
25876 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
25877 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
25878 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
25879 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25880 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25881 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25882 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25883 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 25884
c921be7d
NC
25885#undef ARM_VARIANT
25886#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
25887
21d799b5
NC
25888 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
25889 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
25890 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
25891 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
25892 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
25893 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
25894 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25895 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25896 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25897 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25898 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25899 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25900 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25901 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25902 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25903 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25904 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25905 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25906 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25907 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25908 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
25909 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25910 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25911 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25912 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25913 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25914 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25915 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25916 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25917 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25918 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25919 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25920 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25921 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25922 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25923 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25924 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25925 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25926 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25927 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25928 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25929 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25930 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25931 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25932 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25933 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25934 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25935 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25936 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25937 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25938 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25939 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25940 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25941 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25942 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25943 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25944 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 25945
c921be7d
NC
25946#undef ARM_VARIANT
25947#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
25948
21d799b5
NC
25949 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25950 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25951 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25952 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25953 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25954 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25955 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25956 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25957 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
25958 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
25959 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
25960 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
25961 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
25962 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
25963 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
25964 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
25965 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
25966 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
25967 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
25968 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
25969 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
25970 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
25971 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
25972 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
25973 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
25974 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
25975 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
25976 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
25977 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
25978 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
25979 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
25980 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
25981 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
25982 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
25983 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
25984 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
25985 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
25986 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
25987 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
25988 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
25989 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
25990 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
25991 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
25992 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
25993 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
25994 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
25995 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
25996 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
25997 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
25998 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
25999 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26000 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26001 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26002 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26003 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26004 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26005 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26006 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26007 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26008 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26009 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26010 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26011 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26012 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26013 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26014 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26015 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26016 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26017 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26018 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26019 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26020 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
26021 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26022 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
26023 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26024 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 26025
7fadb25d
SD
26026 /* ARMv8.5-A instructions. */
26027#undef ARM_VARIANT
26028#define ARM_VARIANT & arm_ext_sb
26029#undef THUMB_VARIANT
26030#define THUMB_VARIANT & arm_ext_sb
26031 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26032
dad0c3bf
SD
26033#undef ARM_VARIANT
26034#define ARM_VARIANT & arm_ext_predres
26035#undef THUMB_VARIANT
26036#define THUMB_VARIANT & arm_ext_predres
26037 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26038 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26039 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26040
16a1fa25 26041 /* ARMv8-M instructions. */
4ed7ed8d
TP
26042#undef ARM_VARIANT
26043#define ARM_VARIANT NULL
26044#undef THUMB_VARIANT
26045#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
26046 ToU("sg", e97fe97f, 0, (), noargs),
26047 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26048 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26049 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26050 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26051 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26052 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
26053
26054 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26055 instructions behave as nop if no VFP is present. */
26056#undef THUMB_VARIANT
26057#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
26058 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26059 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
26060
26061 /* Armv8.1-M Mainline instructions. */
26062#undef THUMB_VARIANT
26063#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
26064 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26065 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26066 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26067 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26068 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26069 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26070 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26071 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26072 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26073
4389b29a 26074 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 26075 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 26076 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 26077 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 26078 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
26079
26080 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26081 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26082 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 26083
efd6b359 26084 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
26085 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26086
26087#undef THUMB_VARIANT
26088#define THUMB_VARIANT & mve_ext
23d00a41
SD
26089 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26090 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26091 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
08132bdd
SP
26092 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26093 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
23d00a41
SD
26094 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26095 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26096 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26097 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26098 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26099 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26100 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26101 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26102 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26103 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
26104
26105 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26106 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26107 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26108 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26109 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26110 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26111 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26112 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26113 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26114 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26115 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26116 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26117 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26118 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26119 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26120
5ee91343
AV
26121 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26122 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26123 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26124 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26125 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26126 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26127 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26128 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26129 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26130 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26131 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26132 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26133 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26134 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26135 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26136
a302e574 26137 /* MVE and MVE FP only. */
7df54120 26138 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
efd0b310 26139 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
c2dafc2a
AV
26140 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26141 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26142 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26143 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 26144 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
26145 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26146 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26147 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26148 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26149 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26150 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26151 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26152 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26153 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26154 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26155 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26156
35c228db
AV
26157 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26158 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26159 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26160 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26161 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26162 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26163 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26164 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26165 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26166 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26167 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26168 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
26169 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26170 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26171 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26172 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26173 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26174 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26175 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26176 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 26177
57785aa2
AV
26178 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26179 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 26180 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
26181 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26182 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26183 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26184 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
26185 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26186 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26187 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26188 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
26189 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26190 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
26191 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26192 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26193 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26194 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 26195
93925576
AV
26196 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26197 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26198 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26199 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26200 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26201 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26202 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26203 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26204 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26205 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26206 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26207 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26208 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26209 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26210 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26211 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26212 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26213 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26214 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26215 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26216
2d78f95b
AV
26217 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26218 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26219 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
26220 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26221 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 26222
8b8b22a4
AV
26223 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26224 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26225 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26226 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26227 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26228 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26229 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26230 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
26231 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26232 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26233 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
26234 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26235 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
26236 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26237 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26238 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26239 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 26240
4aa88b50
AV
26241 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26242 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26243 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26244 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26245 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26246 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26247 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26248 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26249 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26250 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26251 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26252 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26253
acca5630
AV
26254 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26255 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26256 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26257
1f6234a3
AV
26258 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26259 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26260 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26261 toU("lctp", _lctp, 0, (), t_loloop),
26262
5d281bf0
AV
26263#undef THUMB_VARIANT
26264#define THUMB_VARIANT & mve_fp_ext
26265 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 26266 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
26267 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26268 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
26269 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26270 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26271 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26272 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 26273
5ee91343 26274#undef ARM_VARIANT
57785aa2 26275#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
26276#undef THUMB_VARIANT
26277#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
26278 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26279 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 26280
57785aa2
AV
26281 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26282
26283#undef ARM_VARIANT
26284#define ARM_VARIANT & fpu_vfp_ext_v1xd
26285
26286 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26287 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26288 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26289 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26290
886e1c73
AV
26291 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26292 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26293 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 26294
485dee97
AV
26295 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26296 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26297
57785aa2
AV
26298 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26299 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26300
1b883319
AV
26301 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26302 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26303
57785aa2
AV
26304#undef ARM_VARIANT
26305#define ARM_VARIANT & fpu_vfp_ext_v2
26306
26307 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26308 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26309 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26310 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26311
dd9634d9
AV
26312#undef ARM_VARIANT
26313#define ARM_VARIANT & fpu_vfp_ext_armv8xd
26314 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26315 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26316 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26317 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
26318 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26319 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
26320
26321#undef ARM_VARIANT
5ee91343 26322#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 26323 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343
AV
26324 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
26325 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
26326 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
f601a00c
AV
26327 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26328 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26329 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26330 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26331 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
26332 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26333 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 26334 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
26335 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26336 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26337 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
26338 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26339 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
26340 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26341 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
26342 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26343 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26344 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
26345 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26346 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26347 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
26348 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26349 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
26350 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26351 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26352 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26353 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26354 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26355 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26356 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
26357 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26358 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26359 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
26360
26361#undef ARM_VARIANT
26362#define ARM_VARIANT & arm_ext_v8_3
26363#undef THUMB_VARIANT
26364#define THUMB_VARIANT & arm_ext_v6t2_v8m
26365 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26366 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
aab2c27d
MM
26367
26368#undef ARM_VARIANT
26369#define ARM_VARIANT &arm_ext_bf16
26370#undef THUMB_VARIANT
26371#define THUMB_VARIANT &arm_ext_bf16
26372 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26373 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26374 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26375
26376#undef ARM_VARIANT
26377#define ARM_VARIANT &arm_ext_i8mm
26378#undef THUMB_VARIANT
26379#define THUMB_VARIANT &arm_ext_i8mm
26380 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26381 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
616ce08e 26382 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
aab2c27d
MM
26383 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26384 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
4934a27c
MM
26385
26386#undef ARM_VARIANT
26387#undef THUMB_VARIANT
26388#define THUMB_VARIANT &arm_ext_cde
26389 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26390 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26391 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26392 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26393
26394 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26395 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26396 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26397 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26398
26399 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26400 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26401 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26402 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
c19d1205
ZW
26403};
26404#undef ARM_VARIANT
26405#undef THUMB_VARIANT
26406#undef TCE
c19d1205
ZW
26407#undef TUE
26408#undef TUF
26409#undef TCC
8f06b2d8 26410#undef cCE
e3cb604e
PB
26411#undef cCL
26412#undef C3E
4389b29a 26413#undef C3
c19d1205
ZW
26414#undef CE
26415#undef CM
4389b29a 26416#undef CL
c19d1205
ZW
26417#undef UE
26418#undef UF
26419#undef UT
5287ad62
JB
26420#undef NUF
26421#undef nUF
26422#undef NCE
26423#undef nCE
c19d1205
ZW
26424#undef OPS0
26425#undef OPS1
26426#undef OPS2
26427#undef OPS3
26428#undef OPS4
26429#undef OPS5
26430#undef OPS6
26431#undef do_0
4389b29a
AV
26432#undef ToC
26433#undef toC
26434#undef ToU
f6b2b12d 26435#undef toU
c19d1205
ZW
26436\f
26437/* MD interface: bits in the object file. */
bfae80f2 26438
c19d1205
ZW
26439/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26440 for use in the a.out file, and stores them in the array pointed to by buf.
26441 This knows about the endian-ness of the target machine and does
26442 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26443 2 (short) and 4 (long) Floating numbers are put out as a series of
26444 LITTLENUMS (shorts, here at least). */
b99bd4ef 26445
c19d1205
ZW
26446void
26447md_number_to_chars (char * buf, valueT val, int n)
26448{
26449 if (target_big_endian)
26450 number_to_chars_bigendian (buf, val, n);
26451 else
26452 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
26453}
26454
c19d1205
ZW
26455static valueT
26456md_chars_to_number (char * buf, int n)
bfae80f2 26457{
c19d1205
ZW
26458 valueT result = 0;
26459 unsigned char * where = (unsigned char *) buf;
bfae80f2 26460
c19d1205 26461 if (target_big_endian)
b99bd4ef 26462 {
c19d1205
ZW
26463 while (n--)
26464 {
26465 result <<= 8;
26466 result |= (*where++ & 255);
26467 }
b99bd4ef 26468 }
c19d1205 26469 else
b99bd4ef 26470 {
c19d1205
ZW
26471 while (n--)
26472 {
26473 result <<= 8;
26474 result |= (where[n] & 255);
26475 }
bfae80f2 26476 }
b99bd4ef 26477
c19d1205 26478 return result;
bfae80f2 26479}
b99bd4ef 26480
c19d1205 26481/* MD interface: Sections. */
b99bd4ef 26482
fa94de6b
RM
26483/* Calculate the maximum variable size (i.e., excluding fr_fix)
26484 that an rs_machine_dependent frag may reach. */
26485
26486unsigned int
26487arm_frag_max_var (fragS *fragp)
26488{
26489 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26490 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26491
26492 Note that we generate relaxable instructions even for cases that don't
26493 really need it, like an immediate that's a trivial constant. So we're
26494 overestimating the instruction size for some of those cases. Rather
26495 than putting more intelligence here, it would probably be better to
26496 avoid generating a relaxation frag in the first place when it can be
26497 determined up front that a short instruction will suffice. */
26498
26499 gas_assert (fragp->fr_type == rs_machine_dependent);
26500 return INSN_SIZE;
26501}
26502
0110f2b8
PB
26503/* Estimate the size of a frag before relaxing. Assume everything fits in
26504 2 bytes. */
26505
c19d1205 26506int
0110f2b8 26507md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
26508 segT segtype ATTRIBUTE_UNUSED)
26509{
0110f2b8
PB
26510 fragp->fr_var = 2;
26511 return 2;
26512}
26513
26514/* Convert a machine dependent frag. */
26515
26516void
26517md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26518{
26519 unsigned long insn;
26520 unsigned long old_op;
26521 char *buf;
26522 expressionS exp;
26523 fixS *fixp;
26524 int reloc_type;
26525 int pc_rel;
26526 int opcode;
26527
26528 buf = fragp->fr_literal + fragp->fr_fix;
26529
26530 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
26531 if (fragp->fr_symbol)
26532 {
0110f2b8
PB
26533 exp.X_op = O_symbol;
26534 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
26535 }
26536 else
26537 {
0110f2b8 26538 exp.X_op = O_constant;
5f4273c7 26539 }
0110f2b8
PB
26540 exp.X_add_number = fragp->fr_offset;
26541 opcode = fragp->fr_subtype;
26542 switch (opcode)
26543 {
26544 case T_MNEM_ldr_pc:
26545 case T_MNEM_ldr_pc2:
26546 case T_MNEM_ldr_sp:
26547 case T_MNEM_str_sp:
26548 case T_MNEM_ldr:
26549 case T_MNEM_ldrb:
26550 case T_MNEM_ldrh:
26551 case T_MNEM_str:
26552 case T_MNEM_strb:
26553 case T_MNEM_strh:
26554 if (fragp->fr_var == 4)
26555 {
5f4273c7 26556 insn = THUMB_OP32 (opcode);
0110f2b8
PB
26557 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26558 {
26559 insn |= (old_op & 0x700) << 4;
26560 }
26561 else
26562 {
26563 insn |= (old_op & 7) << 12;
26564 insn |= (old_op & 0x38) << 13;
26565 }
26566 insn |= 0x00000c00;
26567 put_thumb32_insn (buf, insn);
26568 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26569 }
26570 else
26571 {
26572 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26573 }
26574 pc_rel = (opcode == T_MNEM_ldr_pc2);
26575 break;
26576 case T_MNEM_adr:
26577 if (fragp->fr_var == 4)
26578 {
26579 insn = THUMB_OP32 (opcode);
26580 insn |= (old_op & 0xf0) << 4;
26581 put_thumb32_insn (buf, insn);
26582 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26583 }
26584 else
26585 {
26586 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26587 exp.X_add_number -= 4;
26588 }
26589 pc_rel = 1;
26590 break;
26591 case T_MNEM_mov:
26592 case T_MNEM_movs:
26593 case T_MNEM_cmp:
26594 case T_MNEM_cmn:
26595 if (fragp->fr_var == 4)
26596 {
26597 int r0off = (opcode == T_MNEM_mov
26598 || opcode == T_MNEM_movs) ? 0 : 8;
26599 insn = THUMB_OP32 (opcode);
26600 insn = (insn & 0xe1ffffff) | 0x10000000;
26601 insn |= (old_op & 0x700) << r0off;
26602 put_thumb32_insn (buf, insn);
26603 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26604 }
26605 else
26606 {
26607 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26608 }
26609 pc_rel = 0;
26610 break;
26611 case T_MNEM_b:
26612 if (fragp->fr_var == 4)
26613 {
26614 insn = THUMB_OP32(opcode);
26615 put_thumb32_insn (buf, insn);
26616 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26617 }
26618 else
26619 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26620 pc_rel = 1;
26621 break;
26622 case T_MNEM_bcond:
26623 if (fragp->fr_var == 4)
26624 {
26625 insn = THUMB_OP32(opcode);
26626 insn |= (old_op & 0xf00) << 14;
26627 put_thumb32_insn (buf, insn);
26628 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26629 }
26630 else
26631 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26632 pc_rel = 1;
26633 break;
26634 case T_MNEM_add_sp:
26635 case T_MNEM_add_pc:
26636 case T_MNEM_inc_sp:
26637 case T_MNEM_dec_sp:
26638 if (fragp->fr_var == 4)
26639 {
26640 /* ??? Choose between add and addw. */
26641 insn = THUMB_OP32 (opcode);
26642 insn |= (old_op & 0xf0) << 4;
26643 put_thumb32_insn (buf, insn);
16805f35
PB
26644 if (opcode == T_MNEM_add_pc)
26645 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26646 else
26647 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
26648 }
26649 else
26650 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26651 pc_rel = 0;
26652 break;
26653
26654 case T_MNEM_addi:
26655 case T_MNEM_addis:
26656 case T_MNEM_subi:
26657 case T_MNEM_subis:
26658 if (fragp->fr_var == 4)
26659 {
26660 insn = THUMB_OP32 (opcode);
26661 insn |= (old_op & 0xf0) << 4;
26662 insn |= (old_op & 0xf) << 16;
26663 put_thumb32_insn (buf, insn);
16805f35
PB
26664 if (insn & (1 << 20))
26665 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26666 else
26667 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
26668 }
26669 else
26670 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26671 pc_rel = 0;
26672 break;
26673 default:
5f4273c7 26674 abort ();
0110f2b8
PB
26675 }
26676 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 26677 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
26678 fixp->fx_file = fragp->fr_file;
26679 fixp->fx_line = fragp->fr_line;
26680 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
26681
26682 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26683 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26684 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26685 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
26686}
26687
26688/* Return the size of a relaxable immediate operand instruction.
26689 SHIFT and SIZE specify the form of the allowable immediate. */
26690static int
26691relax_immediate (fragS *fragp, int size, int shift)
26692{
26693 offsetT offset;
26694 offsetT mask;
26695 offsetT low;
26696
26697 /* ??? Should be able to do better than this. */
26698 if (fragp->fr_symbol)
26699 return 4;
26700
26701 low = (1 << shift) - 1;
26702 mask = (1 << (shift + size)) - (1 << shift);
26703 offset = fragp->fr_offset;
26704 /* Force misaligned offsets to 32-bit variant. */
26705 if (offset & low)
5e77afaa 26706 return 4;
0110f2b8
PB
26707 if (offset & ~mask)
26708 return 4;
26709 return 2;
26710}
26711
5e77afaa
PB
26712/* Get the address of a symbol during relaxation. */
26713static addressT
5f4273c7 26714relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
26715{
26716 fragS *sym_frag;
26717 addressT addr;
26718 symbolS *sym;
26719
26720 sym = fragp->fr_symbol;
26721 sym_frag = symbol_get_frag (sym);
26722 know (S_GET_SEGMENT (sym) != absolute_section
26723 || sym_frag == &zero_address_frag);
26724 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26725
26726 /* If frag has yet to be reached on this pass, assume it will
26727 move by STRETCH just as we did. If this is not so, it will
26728 be because some frag between grows, and that will force
26729 another pass. */
26730
26731 if (stretch != 0
26732 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26733 {
26734 fragS *f;
26735
26736 /* Adjust stretch for any alignment frag. Note that if have
26737 been expanding the earlier code, the symbol may be
26738 defined in what appears to be an earlier frag. FIXME:
26739 This doesn't handle the fr_subtype field, which specifies
26740 a maximum number of bytes to skip when doing an
26741 alignment. */
26742 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26743 {
26744 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26745 {
26746 if (stretch < 0)
26747 stretch = - ((- stretch)
26748 & ~ ((1 << (int) f->fr_offset) - 1));
26749 else
26750 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26751 if (stretch == 0)
26752 break;
26753 }
26754 }
26755 if (f != NULL)
26756 addr += stretch;
26757 }
5e77afaa
PB
26758
26759 return addr;
26760}
26761
0110f2b8
PB
26762/* Return the size of a relaxable adr pseudo-instruction or PC-relative
26763 load. */
26764static int
5e77afaa 26765relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
26766{
26767 addressT addr;
26768 offsetT val;
26769
26770 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
26771 if (fragp->fr_symbol == NULL
26772 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
26773 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26774 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
26775 return 4;
26776
5f4273c7 26777 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
26778 addr = fragp->fr_address + fragp->fr_fix;
26779 addr = (addr + 4) & ~3;
5e77afaa 26780 /* Force misaligned targets to 32-bit variant. */
0110f2b8 26781 if (val & 3)
5e77afaa 26782 return 4;
0110f2b8
PB
26783 val -= addr;
26784 if (val < 0 || val > 1020)
26785 return 4;
26786 return 2;
26787}
26788
26789/* Return the size of a relaxable add/sub immediate instruction. */
26790static int
26791relax_addsub (fragS *fragp, asection *sec)
26792{
26793 char *buf;
26794 int op;
26795
26796 buf = fragp->fr_literal + fragp->fr_fix;
26797 op = bfd_get_16(sec->owner, buf);
26798 if ((op & 0xf) == ((op >> 4) & 0xf))
26799 return relax_immediate (fragp, 8, 0);
26800 else
26801 return relax_immediate (fragp, 3, 0);
26802}
26803
e83a675f
RE
26804/* Return TRUE iff the definition of symbol S could be pre-empted
26805 (overridden) at link or load time. */
26806static bfd_boolean
26807symbol_preemptible (symbolS *s)
26808{
26809 /* Weak symbols can always be pre-empted. */
26810 if (S_IS_WEAK (s))
26811 return TRUE;
26812
26813 /* Non-global symbols cannot be pre-empted. */
26814 if (! S_IS_EXTERNAL (s))
26815 return FALSE;
26816
26817#ifdef OBJ_ELF
26818 /* In ELF, a global symbol can be marked protected, or private. In that
26819 case it can't be pre-empted (other definitions in the same link unit
26820 would violate the ODR). */
26821 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
26822 return FALSE;
26823#endif
26824
26825 /* Other global symbols might be pre-empted. */
26826 return TRUE;
26827}
0110f2b8
PB
26828
26829/* Return the size of a relaxable branch instruction. BITS is the
26830 size of the offset field in the narrow instruction. */
26831
26832static int
5e77afaa 26833relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
26834{
26835 addressT addr;
26836 offsetT val;
26837 offsetT limit;
26838
26839 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 26840 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
26841 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26842 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
26843 return 4;
26844
267bf995 26845#ifdef OBJ_ELF
e83a675f 26846 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
26847 if (S_IS_DEFINED (fragp->fr_symbol)
26848 && ARM_IS_FUNC (fragp->fr_symbol))
26849 return 4;
e83a675f 26850#endif
0d9b4b55 26851
e83a675f 26852 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 26853 return 4;
267bf995 26854
5f4273c7 26855 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
26856 addr = fragp->fr_address + fragp->fr_fix + 4;
26857 val -= addr;
26858
26859 /* Offset is a signed value *2 */
26860 limit = 1 << bits;
26861 if (val >= limit || val < -limit)
26862 return 4;
26863 return 2;
26864}
26865
26866
26867/* Relax a machine dependent frag. This returns the amount by which
26868 the current size of the frag should change. */
26869
26870int
5e77afaa 26871arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
26872{
26873 int oldsize;
26874 int newsize;
26875
26876 oldsize = fragp->fr_var;
26877 switch (fragp->fr_subtype)
26878 {
26879 case T_MNEM_ldr_pc2:
5f4273c7 26880 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26881 break;
26882 case T_MNEM_ldr_pc:
26883 case T_MNEM_ldr_sp:
26884 case T_MNEM_str_sp:
5f4273c7 26885 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
26886 break;
26887 case T_MNEM_ldr:
26888 case T_MNEM_str:
5f4273c7 26889 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
26890 break;
26891 case T_MNEM_ldrh:
26892 case T_MNEM_strh:
5f4273c7 26893 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
26894 break;
26895 case T_MNEM_ldrb:
26896 case T_MNEM_strb:
5f4273c7 26897 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
26898 break;
26899 case T_MNEM_adr:
5f4273c7 26900 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26901 break;
26902 case T_MNEM_mov:
26903 case T_MNEM_movs:
26904 case T_MNEM_cmp:
26905 case T_MNEM_cmn:
5f4273c7 26906 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
26907 break;
26908 case T_MNEM_b:
5f4273c7 26909 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
26910 break;
26911 case T_MNEM_bcond:
5f4273c7 26912 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
26913 break;
26914 case T_MNEM_add_sp:
26915 case T_MNEM_add_pc:
26916 newsize = relax_immediate (fragp, 8, 2);
26917 break;
26918 case T_MNEM_inc_sp:
26919 case T_MNEM_dec_sp:
26920 newsize = relax_immediate (fragp, 7, 2);
26921 break;
26922 case T_MNEM_addi:
26923 case T_MNEM_addis:
26924 case T_MNEM_subi:
26925 case T_MNEM_subis:
26926 newsize = relax_addsub (fragp, sec);
26927 break;
26928 default:
5f4273c7 26929 abort ();
0110f2b8 26930 }
5e77afaa
PB
26931
26932 fragp->fr_var = newsize;
26933 /* Freeze wide instructions that are at or before the same location as
26934 in the previous pass. This avoids infinite loops.
5f4273c7
NC
26935 Don't freeze them unconditionally because targets may be artificially
26936 misaligned by the expansion of preceding frags. */
5e77afaa 26937 if (stretch <= 0 && newsize > 2)
0110f2b8 26938 {
0110f2b8 26939 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 26940 frag_wane (fragp);
0110f2b8 26941 }
5e77afaa 26942
0110f2b8 26943 return newsize - oldsize;
c19d1205 26944}
b99bd4ef 26945
c19d1205 26946/* Round up a section size to the appropriate boundary. */
b99bd4ef 26947
c19d1205
ZW
26948valueT
26949md_section_align (segT segment ATTRIBUTE_UNUSED,
26950 valueT size)
26951{
6844c0cc 26952 return size;
bfae80f2 26953}
b99bd4ef 26954
c19d1205
ZW
26955/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
26956 of an rs_align_code fragment. */
26957
26958void
26959arm_handle_align (fragS * fragP)
bfae80f2 26960{
d9235011 26961 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
26962 {
26963 { /* ARMv1 */
26964 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
26965 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
26966 },
26967 { /* ARMv6k */
26968 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
26969 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
26970 },
26971 };
d9235011 26972 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
26973 {
26974 { /* Thumb-1 */
26975 {0xc0, 0x46}, /* LE */
26976 {0x46, 0xc0}, /* BE */
26977 },
26978 { /* Thumb-2 */
26979 {0x00, 0xbf}, /* LE */
26980 {0xbf, 0x00} /* BE */
26981 }
26982 };
d9235011 26983 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
26984 { /* Wide Thumb-2 */
26985 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
26986 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
26987 };
c921be7d 26988
e7495e45 26989 unsigned bytes, fix, noop_size;
c19d1205 26990 char * p;
d9235011
TS
26991 const unsigned char * noop;
26992 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
26993#ifdef OBJ_ELF
26994 enum mstate state;
26995#endif
bfae80f2 26996
c19d1205 26997 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
26998 return;
26999
c19d1205
ZW
27000 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27001 p = fragP->fr_literal + fragP->fr_fix;
27002 fix = 0;
bfae80f2 27003
c19d1205
ZW
27004 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27005 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 27006
cd000bff 27007 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 27008
cd000bff 27009 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 27010 {
7f78eb34
JW
27011 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27012 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
27013 {
27014 narrow_noop = thumb_noop[1][target_big_endian];
27015 noop = wide_thumb_noop[target_big_endian];
27016 }
c19d1205 27017 else
e7495e45
NS
27018 noop = thumb_noop[0][target_big_endian];
27019 noop_size = 2;
cd000bff
DJ
27020#ifdef OBJ_ELF
27021 state = MAP_THUMB;
27022#endif
7ed4c4c5
NC
27023 }
27024 else
27025 {
7f78eb34
JW
27026 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27027 ? selected_cpu : arm_arch_none,
27028 arm_ext_v6k) != 0]
e7495e45
NS
27029 [target_big_endian];
27030 noop_size = 4;
cd000bff
DJ
27031#ifdef OBJ_ELF
27032 state = MAP_ARM;
27033#endif
7ed4c4c5 27034 }
c921be7d 27035
e7495e45 27036 fragP->fr_var = noop_size;
c921be7d 27037
c19d1205 27038 if (bytes & (noop_size - 1))
7ed4c4c5 27039 {
c19d1205 27040 fix = bytes & (noop_size - 1);
cd000bff
DJ
27041#ifdef OBJ_ELF
27042 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27043#endif
c19d1205
ZW
27044 memset (p, 0, fix);
27045 p += fix;
27046 bytes -= fix;
a737bd4d 27047 }
a737bd4d 27048
e7495e45
NS
27049 if (narrow_noop)
27050 {
27051 if (bytes & noop_size)
27052 {
27053 /* Insert a narrow noop. */
27054 memcpy (p, narrow_noop, noop_size);
27055 p += noop_size;
27056 bytes -= noop_size;
27057 fix += noop_size;
27058 }
27059
27060 /* Use wide noops for the remainder */
27061 noop_size = 4;
27062 }
27063
c19d1205 27064 while (bytes >= noop_size)
a737bd4d 27065 {
c19d1205
ZW
27066 memcpy (p, noop, noop_size);
27067 p += noop_size;
27068 bytes -= noop_size;
27069 fix += noop_size;
a737bd4d
NC
27070 }
27071
c19d1205 27072 fragP->fr_fix += fix;
a737bd4d
NC
27073}
27074
c19d1205
ZW
27075/* Called from md_do_align. Used to create an alignment
27076 frag in a code section. */
27077
27078void
27079arm_frag_align_code (int n, int max)
bfae80f2 27080{
c19d1205 27081 char * p;
7ed4c4c5 27082
c19d1205 27083 /* We assume that there will never be a requirement
6ec8e702 27084 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 27085 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
27086 {
27087 char err_msg[128];
27088
fa94de6b 27089 sprintf (err_msg,
477330fc
RM
27090 _("alignments greater than %d bytes not supported in .text sections."),
27091 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 27092 as_fatal ("%s", err_msg);
6ec8e702 27093 }
bfae80f2 27094
c19d1205
ZW
27095 p = frag_var (rs_align_code,
27096 MAX_MEM_FOR_RS_ALIGN_CODE,
27097 1,
27098 (relax_substateT) max,
27099 (symbolS *) NULL,
27100 (offsetT) n,
27101 (char *) NULL);
27102 *p = 0;
27103}
bfae80f2 27104
8dc2430f
NC
27105/* Perform target specific initialisation of a frag.
27106 Note - despite the name this initialisation is not done when the frag
27107 is created, but only when its type is assigned. A frag can be created
27108 and used a long time before its type is set, so beware of assuming that
33eaf5de 27109 this initialisation is performed first. */
bfae80f2 27110
cd000bff
DJ
27111#ifndef OBJ_ELF
27112void
27113arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27114{
27115 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 27116 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
27117}
27118
27119#else /* OBJ_ELF is defined. */
c19d1205 27120void
cd000bff 27121arm_init_frag (fragS * fragP, int max_chars)
c19d1205 27122{
e8d84ca1 27123 bfd_boolean frag_thumb_mode;
b968d18a 27124
8dc2430f
NC
27125 /* If the current ARM vs THUMB mode has not already
27126 been recorded into this frag then do so now. */
cd000bff 27127 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
27128 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27129
e8d84ca1
NC
27130 /* PR 21809: Do not set a mapping state for debug sections
27131 - it just confuses other tools. */
fd361982 27132 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
e8d84ca1
NC
27133 return;
27134
b968d18a 27135 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 27136
f9c1b181
RL
27137 /* Record a mapping symbol for alignment frags. We will delete this
27138 later if the alignment ends up empty. */
27139 switch (fragP->fr_type)
27140 {
27141 case rs_align:
27142 case rs_align_test:
27143 case rs_fill:
27144 mapping_state_2 (MAP_DATA, max_chars);
27145 break;
27146 case rs_align_code:
b968d18a 27147 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
27148 break;
27149 default:
27150 break;
cd000bff 27151 }
bfae80f2
RE
27152}
27153
c19d1205
ZW
27154/* When we change sections we need to issue a new mapping symbol. */
27155
27156void
27157arm_elf_change_section (void)
bfae80f2 27158{
c19d1205
ZW
27159 /* Link an unlinked unwind index table section to the .text section. */
27160 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27161 && elf_linked_to_section (now_seg) == NULL)
27162 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
27163}
27164
c19d1205
ZW
27165int
27166arm_elf_section_type (const char * str, size_t len)
e45d0630 27167{
c19d1205
ZW
27168 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27169 return SHT_ARM_EXIDX;
e45d0630 27170
c19d1205
ZW
27171 return -1;
27172}
27173\f
27174/* Code to deal with unwinding tables. */
e45d0630 27175
c19d1205 27176static void add_unwind_adjustsp (offsetT);
e45d0630 27177
5f4273c7 27178/* Generate any deferred unwind frame offset. */
e45d0630 27179
bfae80f2 27180static void
c19d1205 27181flush_pending_unwind (void)
bfae80f2 27182{
c19d1205 27183 offsetT offset;
bfae80f2 27184
c19d1205
ZW
27185 offset = unwind.pending_offset;
27186 unwind.pending_offset = 0;
27187 if (offset != 0)
27188 add_unwind_adjustsp (offset);
bfae80f2
RE
27189}
27190
c19d1205
ZW
27191/* Add an opcode to this list for this function. Two-byte opcodes should
27192 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27193 order. */
27194
bfae80f2 27195static void
c19d1205 27196add_unwind_opcode (valueT op, int length)
bfae80f2 27197{
c19d1205
ZW
27198 /* Add any deferred stack adjustment. */
27199 if (unwind.pending_offset)
27200 flush_pending_unwind ();
bfae80f2 27201
c19d1205 27202 unwind.sp_restored = 0;
bfae80f2 27203
c19d1205 27204 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 27205 {
c19d1205
ZW
27206 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27207 if (unwind.opcodes)
325801bd
TS
27208 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27209 unwind.opcode_alloc);
c19d1205 27210 else
325801bd 27211 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 27212 }
c19d1205 27213 while (length > 0)
bfae80f2 27214 {
c19d1205
ZW
27215 length--;
27216 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27217 op >>= 8;
27218 unwind.opcode_count++;
bfae80f2 27219 }
bfae80f2
RE
27220}
27221
c19d1205
ZW
27222/* Add unwind opcodes to adjust the stack pointer. */
27223
bfae80f2 27224static void
c19d1205 27225add_unwind_adjustsp (offsetT offset)
bfae80f2 27226{
c19d1205 27227 valueT op;
bfae80f2 27228
c19d1205 27229 if (offset > 0x200)
bfae80f2 27230 {
c19d1205
ZW
27231 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27232 char bytes[5];
27233 int n;
27234 valueT o;
bfae80f2 27235
c19d1205
ZW
27236 /* Long form: 0xb2, uleb128. */
27237 /* This might not fit in a word so add the individual bytes,
27238 remembering the list is built in reverse order. */
27239 o = (valueT) ((offset - 0x204) >> 2);
27240 if (o == 0)
27241 add_unwind_opcode (0, 1);
bfae80f2 27242
c19d1205
ZW
27243 /* Calculate the uleb128 encoding of the offset. */
27244 n = 0;
27245 while (o)
27246 {
27247 bytes[n] = o & 0x7f;
27248 o >>= 7;
27249 if (o)
27250 bytes[n] |= 0x80;
27251 n++;
27252 }
27253 /* Add the insn. */
27254 for (; n; n--)
27255 add_unwind_opcode (bytes[n - 1], 1);
27256 add_unwind_opcode (0xb2, 1);
27257 }
27258 else if (offset > 0x100)
bfae80f2 27259 {
c19d1205
ZW
27260 /* Two short opcodes. */
27261 add_unwind_opcode (0x3f, 1);
27262 op = (offset - 0x104) >> 2;
27263 add_unwind_opcode (op, 1);
bfae80f2 27264 }
c19d1205
ZW
27265 else if (offset > 0)
27266 {
27267 /* Short opcode. */
27268 op = (offset - 4) >> 2;
27269 add_unwind_opcode (op, 1);
27270 }
27271 else if (offset < 0)
bfae80f2 27272 {
c19d1205
ZW
27273 offset = -offset;
27274 while (offset > 0x100)
bfae80f2 27275 {
c19d1205
ZW
27276 add_unwind_opcode (0x7f, 1);
27277 offset -= 0x100;
bfae80f2 27278 }
c19d1205
ZW
27279 op = ((offset - 4) >> 2) | 0x40;
27280 add_unwind_opcode (op, 1);
bfae80f2 27281 }
bfae80f2
RE
27282}
27283
c19d1205 27284/* Finish the list of unwind opcodes for this function. */
0198d5e6 27285
c19d1205
ZW
27286static void
27287finish_unwind_opcodes (void)
bfae80f2 27288{
c19d1205 27289 valueT op;
bfae80f2 27290
c19d1205 27291 if (unwind.fp_used)
bfae80f2 27292 {
708587a4 27293 /* Adjust sp as necessary. */
c19d1205
ZW
27294 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27295 flush_pending_unwind ();
bfae80f2 27296
c19d1205
ZW
27297 /* After restoring sp from the frame pointer. */
27298 op = 0x90 | unwind.fp_reg;
27299 add_unwind_opcode (op, 1);
27300 }
27301 else
27302 flush_pending_unwind ();
bfae80f2
RE
27303}
27304
bfae80f2 27305
c19d1205
ZW
27306/* Start an exception table entry. If idx is nonzero this is an index table
27307 entry. */
bfae80f2
RE
27308
27309static void
c19d1205 27310start_unwind_section (const segT text_seg, int idx)
bfae80f2 27311{
c19d1205
ZW
27312 const char * text_name;
27313 const char * prefix;
27314 const char * prefix_once;
a8c4d40b 27315 struct elf_section_match match;
c19d1205 27316 char * sec_name;
c19d1205
ZW
27317 int type;
27318 int flags;
27319 int linkonce;
bfae80f2 27320
c19d1205 27321 if (idx)
bfae80f2 27322 {
c19d1205
ZW
27323 prefix = ELF_STRING_ARM_unwind;
27324 prefix_once = ELF_STRING_ARM_unwind_once;
27325 type = SHT_ARM_EXIDX;
bfae80f2 27326 }
c19d1205 27327 else
bfae80f2 27328 {
c19d1205
ZW
27329 prefix = ELF_STRING_ARM_unwind_info;
27330 prefix_once = ELF_STRING_ARM_unwind_info_once;
27331 type = SHT_PROGBITS;
bfae80f2
RE
27332 }
27333
c19d1205
ZW
27334 text_name = segment_name (text_seg);
27335 if (streq (text_name, ".text"))
27336 text_name = "";
27337
27338 if (strncmp (text_name, ".gnu.linkonce.t.",
27339 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 27340 {
c19d1205
ZW
27341 prefix = prefix_once;
27342 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
27343 }
27344
29a2809e 27345 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 27346
c19d1205
ZW
27347 flags = SHF_ALLOC;
27348 linkonce = 0;
a8c4d40b 27349 memset (&match, 0, sizeof (match));
bfae80f2 27350
c19d1205
ZW
27351 /* Handle COMDAT group. */
27352 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 27353 {
a8c4d40b
L
27354 match.group_name = elf_group_name (text_seg);
27355 if (match.group_name == NULL)
c19d1205 27356 {
bd3ba5d1 27357 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
27358 segment_name (text_seg));
27359 ignore_rest_of_line ();
27360 return;
27361 }
27362 flags |= SHF_GROUP;
27363 linkonce = 1;
bfae80f2
RE
27364 }
27365
a8c4d40b 27366 obj_elf_change_section (sec_name, type, flags, 0, &match,
a91e1603 27367 linkonce, 0);
bfae80f2 27368
5f4273c7 27369 /* Set the section link for index tables. */
c19d1205
ZW
27370 if (idx)
27371 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
27372}
27373
bfae80f2 27374
c19d1205
ZW
27375/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27376 personality routine data. Returns zero, or the index table value for
cad0da33 27377 an inline entry. */
c19d1205
ZW
27378
27379static valueT
27380create_unwind_entry (int have_data)
bfae80f2 27381{
c19d1205
ZW
27382 int size;
27383 addressT where;
27384 char *ptr;
27385 /* The current word of data. */
27386 valueT data;
27387 /* The number of bytes left in this word. */
27388 int n;
bfae80f2 27389
c19d1205 27390 finish_unwind_opcodes ();
bfae80f2 27391
c19d1205
ZW
27392 /* Remember the current text section. */
27393 unwind.saved_seg = now_seg;
27394 unwind.saved_subseg = now_subseg;
bfae80f2 27395
c19d1205 27396 start_unwind_section (now_seg, 0);
bfae80f2 27397
c19d1205 27398 if (unwind.personality_routine == NULL)
bfae80f2 27399 {
c19d1205
ZW
27400 if (unwind.personality_index == -2)
27401 {
27402 if (have_data)
5f4273c7 27403 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
27404 return 1; /* EXIDX_CANTUNWIND. */
27405 }
bfae80f2 27406
c19d1205
ZW
27407 /* Use a default personality routine if none is specified. */
27408 if (unwind.personality_index == -1)
27409 {
27410 if (unwind.opcode_count > 3)
27411 unwind.personality_index = 1;
27412 else
27413 unwind.personality_index = 0;
27414 }
bfae80f2 27415
c19d1205
ZW
27416 /* Space for the personality routine entry. */
27417 if (unwind.personality_index == 0)
27418 {
27419 if (unwind.opcode_count > 3)
27420 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 27421
c19d1205
ZW
27422 if (!have_data)
27423 {
27424 /* All the data is inline in the index table. */
27425 data = 0x80;
27426 n = 3;
27427 while (unwind.opcode_count > 0)
27428 {
27429 unwind.opcode_count--;
27430 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27431 n--;
27432 }
bfae80f2 27433
c19d1205
ZW
27434 /* Pad with "finish" opcodes. */
27435 while (n--)
27436 data = (data << 8) | 0xb0;
bfae80f2 27437
c19d1205
ZW
27438 return data;
27439 }
27440 size = 0;
27441 }
27442 else
27443 /* We get two opcodes "free" in the first word. */
27444 size = unwind.opcode_count - 2;
27445 }
27446 else
5011093d 27447 {
cad0da33
NC
27448 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27449 if (unwind.personality_index != -1)
27450 {
27451 as_bad (_("attempt to recreate an unwind entry"));
27452 return 1;
27453 }
5011093d
NC
27454
27455 /* An extra byte is required for the opcode count. */
27456 size = unwind.opcode_count + 1;
27457 }
bfae80f2 27458
c19d1205
ZW
27459 size = (size + 3) >> 2;
27460 if (size > 0xff)
27461 as_bad (_("too many unwind opcodes"));
bfae80f2 27462
c19d1205
ZW
27463 frag_align (2, 0, 0);
27464 record_alignment (now_seg, 2);
27465 unwind.table_entry = expr_build_dot ();
27466
27467 /* Allocate the table entry. */
27468 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
27469 /* PR 13449: Zero the table entries in case some of them are not used. */
27470 memset (ptr, 0, (size << 2) + 4);
c19d1205 27471 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 27472
c19d1205 27473 switch (unwind.personality_index)
bfae80f2 27474 {
c19d1205
ZW
27475 case -1:
27476 /* ??? Should this be a PLT generating relocation? */
27477 /* Custom personality routine. */
27478 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27479 BFD_RELOC_ARM_PREL31);
bfae80f2 27480
c19d1205
ZW
27481 where += 4;
27482 ptr += 4;
bfae80f2 27483
c19d1205 27484 /* Set the first byte to the number of additional words. */
5011093d 27485 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
27486 n = 3;
27487 break;
bfae80f2 27488
c19d1205
ZW
27489 /* ABI defined personality routines. */
27490 case 0:
27491 /* Three opcodes bytes are packed into the first word. */
27492 data = 0x80;
27493 n = 3;
27494 break;
bfae80f2 27495
c19d1205
ZW
27496 case 1:
27497 case 2:
27498 /* The size and first two opcode bytes go in the first word. */
27499 data = ((0x80 + unwind.personality_index) << 8) | size;
27500 n = 2;
27501 break;
bfae80f2 27502
c19d1205
ZW
27503 default:
27504 /* Should never happen. */
27505 abort ();
27506 }
bfae80f2 27507
c19d1205
ZW
27508 /* Pack the opcodes into words (MSB first), reversing the list at the same
27509 time. */
27510 while (unwind.opcode_count > 0)
27511 {
27512 if (n == 0)
27513 {
27514 md_number_to_chars (ptr, data, 4);
27515 ptr += 4;
27516 n = 4;
27517 data = 0;
27518 }
27519 unwind.opcode_count--;
27520 n--;
27521 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27522 }
27523
27524 /* Finish off the last word. */
27525 if (n < 4)
27526 {
27527 /* Pad with "finish" opcodes. */
27528 while (n--)
27529 data = (data << 8) | 0xb0;
27530
27531 md_number_to_chars (ptr, data, 4);
27532 }
27533
27534 if (!have_data)
27535 {
27536 /* Add an empty descriptor if there is no user-specified data. */
27537 ptr = frag_more (4);
27538 md_number_to_chars (ptr, 0, 4);
27539 }
27540
27541 return 0;
bfae80f2
RE
27542}
27543
f0927246
NC
27544
27545/* Initialize the DWARF-2 unwind information for this procedure. */
27546
27547void
27548tc_arm_frame_initial_instructions (void)
27549{
27550 cfi_add_CFA_def_cfa (REG_SP, 0);
27551}
27552#endif /* OBJ_ELF */
27553
c19d1205
ZW
27554/* Convert REGNAME to a DWARF-2 register number. */
27555
27556int
1df69f4f 27557tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 27558{
1df69f4f 27559 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
27560 if (reg != FAIL)
27561 return reg;
c19d1205 27562
1f5afe1c
NC
27563 /* PR 16694: Allow VFP registers as well. */
27564 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27565 if (reg != FAIL)
27566 return 64 + reg;
c19d1205 27567
1f5afe1c
NC
27568 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27569 if (reg != FAIL)
27570 return reg + 256;
27571
0198d5e6 27572 return FAIL;
bfae80f2
RE
27573}
27574
f0927246 27575#ifdef TE_PE
c19d1205 27576void
f0927246 27577tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 27578{
91d6fa6a 27579 expressionS exp;
bfae80f2 27580
91d6fa6a
NC
27581 exp.X_op = O_secrel;
27582 exp.X_add_symbol = symbol;
27583 exp.X_add_number = 0;
27584 emit_expr (&exp, size);
f0927246
NC
27585}
27586#endif
bfae80f2 27587
c19d1205 27588/* MD interface: Symbol and relocation handling. */
bfae80f2 27589
2fc8bdac
ZW
27590/* Return the address within the segment that a PC-relative fixup is
27591 relative to. For ARM, PC-relative fixups applied to instructions
27592 are generally relative to the location of the fixup plus 8 bytes.
27593 Thumb branches are offset by 4, and Thumb loads relative to PC
27594 require special handling. */
bfae80f2 27595
c19d1205 27596long
2fc8bdac 27597md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 27598{
2fc8bdac
ZW
27599 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27600
27601 /* If this is pc-relative and we are going to emit a relocation
27602 then we just want to put out any pipeline compensation that the linker
53baae48
NC
27603 will need. Otherwise we want to use the calculated base.
27604 For WinCE we skip the bias for externals as well, since this
27605 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 27606 if (fixP->fx_pcrel
2fc8bdac 27607 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
27608 || (arm_force_relocation (fixP)
27609#ifdef TE_WINCE
27610 && !S_IS_EXTERNAL (fixP->fx_addsy)
27611#endif
27612 )))
2fc8bdac 27613 base = 0;
bfae80f2 27614
267bf995 27615
c19d1205 27616 switch (fixP->fx_r_type)
bfae80f2 27617 {
2fc8bdac
ZW
27618 /* PC relative addressing on the Thumb is slightly odd as the
27619 bottom two bits of the PC are forced to zero for the
27620 calculation. This happens *after* application of the
27621 pipeline offset. However, Thumb adrl already adjusts for
27622 this, so we need not do it again. */
c19d1205 27623 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 27624 return base & ~3;
c19d1205
ZW
27625
27626 case BFD_RELOC_ARM_THUMB_OFFSET:
27627 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 27628 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 27629 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 27630 return (base + 4) & ~3;
c19d1205 27631
2fc8bdac 27632 /* Thumb branches are simply offset by +4. */
e12437dc 27633 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
27634 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27635 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27636 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27637 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 27638 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 27639 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 27640 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 27641 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 27642 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 27643 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 27644 return base + 4;
bfae80f2 27645
267bf995 27646 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
27647 if (fixP->fx_addsy
27648 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27649 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 27650 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
27651 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27652 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
27653 return base + 4;
27654
00adf2d4
JB
27655 /* BLX is like branches above, but forces the low two bits of PC to
27656 zero. */
486499d0
CL
27657 case BFD_RELOC_THUMB_PCREL_BLX:
27658 if (fixP->fx_addsy
27659 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27660 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27661 && THUMB_IS_FUNC (fixP->fx_addsy)
27662 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27663 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
27664 return (base + 4) & ~3;
27665
2fc8bdac
ZW
27666 /* ARM mode branches are offset by +8. However, the Windows CE
27667 loader expects the relocation not to take this into account. */
267bf995 27668 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
27669 if (fixP->fx_addsy
27670 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27671 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27672 && ARM_IS_FUNC (fixP->fx_addsy)
27673 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27674 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27675 return base + 8;
267bf995 27676
486499d0
CL
27677 case BFD_RELOC_ARM_PCREL_CALL:
27678 if (fixP->fx_addsy
27679 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27680 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27681 && THUMB_IS_FUNC (fixP->fx_addsy)
27682 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27683 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27684 return base + 8;
267bf995 27685
2fc8bdac 27686 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 27687 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 27688 case BFD_RELOC_ARM_PLT32:
c19d1205 27689#ifdef TE_WINCE
5f4273c7 27690 /* When handling fixups immediately, because we have already
477330fc 27691 discovered the value of a symbol, or the address of the frag involved
53baae48 27692 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
27693 see fixup_segment() in write.c
27694 The S_IS_EXTERNAL test handles the case of global symbols.
27695 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
27696 if (fixP->fx_pcrel
27697 && fixP->fx_addsy != NULL
27698 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27699 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27700 return base + 8;
2fc8bdac 27701 return base;
c19d1205 27702#else
2fc8bdac 27703 return base + 8;
c19d1205 27704#endif
2fc8bdac 27705
267bf995 27706
2fc8bdac
ZW
27707 /* ARM mode loads relative to PC are also offset by +8. Unlike
27708 branches, the Windows CE loader *does* expect the relocation
27709 to take this into account. */
27710 case BFD_RELOC_ARM_OFFSET_IMM:
27711 case BFD_RELOC_ARM_OFFSET_IMM8:
27712 case BFD_RELOC_ARM_HWLITERAL:
27713 case BFD_RELOC_ARM_LITERAL:
27714 case BFD_RELOC_ARM_CP_OFF_IMM:
27715 return base + 8;
27716
27717
27718 /* Other PC-relative relocations are un-offset. */
27719 default:
27720 return base;
27721 }
bfae80f2
RE
27722}
27723
8b2d793c
NC
27724static bfd_boolean flag_warn_syms = TRUE;
27725
ae8714c2
NC
27726bfd_boolean
27727arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27728{
8b2d793c
NC
27729 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27730 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27731 does mean that the resulting code might be very confusing to the reader.
27732 Also this warning can be triggered if the user omits an operand before
27733 an immediate address, eg:
27734
27735 LDR =foo
27736
27737 GAS treats this as an assignment of the value of the symbol foo to a
27738 symbol LDR, and so (without this code) it will not issue any kind of
27739 warning or error message.
27740
27741 Note - ARM instructions are case-insensitive but the strings in the hash
27742 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27743 lower case too. */
27744 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27745 {
27746 char * nbuf = strdup (name);
27747 char * p;
27748
27749 for (p = nbuf; *p; p++)
27750 *p = TOLOWER (*p);
27751 if (hash_find (arm_ops_hsh, nbuf) != NULL)
27752 {
27753 static struct hash_control * already_warned = NULL;
27754
27755 if (already_warned == NULL)
27756 already_warned = hash_new ();
27757 /* Only warn about the symbol once. To keep the code
27758 simple we let hash_insert do the lookup for us. */
3076e594 27759 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 27760 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
27761 }
27762 else
27763 free (nbuf);
27764 }
3739860c 27765
ae8714c2
NC
27766 return FALSE;
27767}
27768
27769/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
27770 Otherwise we have no need to default values of symbols. */
27771
27772symbolS *
27773md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
27774{
27775#ifdef OBJ_ELF
27776 if (name[0] == '_' && name[1] == 'G'
27777 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
27778 {
27779 if (!GOT_symbol)
27780 {
27781 if (symbol_find (name))
27782 as_bad (_("GOT already in the symbol table"));
27783
27784 GOT_symbol = symbol_new (name, undefined_section,
27785 (valueT) 0, & zero_address_frag);
27786 }
27787
27788 return GOT_symbol;
27789 }
27790#endif
27791
c921be7d 27792 return NULL;
bfae80f2
RE
27793}
27794
55cf6793 27795/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
27796 computed as two separate immediate values, added together. We
27797 already know that this value cannot be computed by just one ARM
27798 instruction. */
27799
27800static unsigned int
27801validate_immediate_twopart (unsigned int val,
27802 unsigned int * highpart)
bfae80f2 27803{
c19d1205
ZW
27804 unsigned int a;
27805 unsigned int i;
bfae80f2 27806
c19d1205
ZW
27807 for (i = 0; i < 32; i += 2)
27808 if (((a = rotate_left (val, i)) & 0xff) != 0)
27809 {
27810 if (a & 0xff00)
27811 {
27812 if (a & ~ 0xffff)
27813 continue;
27814 * highpart = (a >> 8) | ((i + 24) << 7);
27815 }
27816 else if (a & 0xff0000)
27817 {
27818 if (a & 0xff000000)
27819 continue;
27820 * highpart = (a >> 16) | ((i + 16) << 7);
27821 }
27822 else
27823 {
9c2799c2 27824 gas_assert (a & 0xff000000);
c19d1205
ZW
27825 * highpart = (a >> 24) | ((i + 8) << 7);
27826 }
bfae80f2 27827
c19d1205
ZW
27828 return (a & 0xff) | (i << 7);
27829 }
bfae80f2 27830
c19d1205 27831 return FAIL;
bfae80f2
RE
27832}
27833
c19d1205
ZW
27834static int
27835validate_offset_imm (unsigned int val, int hwse)
27836{
27837 if ((hwse && val > 255) || val > 4095)
27838 return FAIL;
27839 return val;
27840}
bfae80f2 27841
55cf6793 27842/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
27843 negative immediate constant by altering the instruction. A bit of
27844 a hack really.
27845 MOV <-> MVN
27846 AND <-> BIC
27847 ADC <-> SBC
27848 by inverting the second operand, and
27849 ADD <-> SUB
27850 CMP <-> CMN
27851 by negating the second operand. */
bfae80f2 27852
c19d1205
ZW
27853static int
27854negate_data_op (unsigned long * instruction,
27855 unsigned long value)
bfae80f2 27856{
c19d1205
ZW
27857 int op, new_inst;
27858 unsigned long negated, inverted;
bfae80f2 27859
c19d1205
ZW
27860 negated = encode_arm_immediate (-value);
27861 inverted = encode_arm_immediate (~value);
bfae80f2 27862
c19d1205
ZW
27863 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
27864 switch (op)
bfae80f2 27865 {
c19d1205
ZW
27866 /* First negates. */
27867 case OPCODE_SUB: /* ADD <-> SUB */
27868 new_inst = OPCODE_ADD;
27869 value = negated;
27870 break;
bfae80f2 27871
c19d1205
ZW
27872 case OPCODE_ADD:
27873 new_inst = OPCODE_SUB;
27874 value = negated;
27875 break;
bfae80f2 27876
c19d1205
ZW
27877 case OPCODE_CMP: /* CMP <-> CMN */
27878 new_inst = OPCODE_CMN;
27879 value = negated;
27880 break;
bfae80f2 27881
c19d1205
ZW
27882 case OPCODE_CMN:
27883 new_inst = OPCODE_CMP;
27884 value = negated;
27885 break;
bfae80f2 27886
c19d1205
ZW
27887 /* Now Inverted ops. */
27888 case OPCODE_MOV: /* MOV <-> MVN */
27889 new_inst = OPCODE_MVN;
27890 value = inverted;
27891 break;
bfae80f2 27892
c19d1205
ZW
27893 case OPCODE_MVN:
27894 new_inst = OPCODE_MOV;
27895 value = inverted;
27896 break;
bfae80f2 27897
c19d1205
ZW
27898 case OPCODE_AND: /* AND <-> BIC */
27899 new_inst = OPCODE_BIC;
27900 value = inverted;
27901 break;
bfae80f2 27902
c19d1205
ZW
27903 case OPCODE_BIC:
27904 new_inst = OPCODE_AND;
27905 value = inverted;
27906 break;
bfae80f2 27907
c19d1205
ZW
27908 case OPCODE_ADC: /* ADC <-> SBC */
27909 new_inst = OPCODE_SBC;
27910 value = inverted;
27911 break;
bfae80f2 27912
c19d1205
ZW
27913 case OPCODE_SBC:
27914 new_inst = OPCODE_ADC;
27915 value = inverted;
27916 break;
bfae80f2 27917
c19d1205
ZW
27918 /* We cannot do anything. */
27919 default:
27920 return FAIL;
b99bd4ef
NC
27921 }
27922
c19d1205
ZW
27923 if (value == (unsigned) FAIL)
27924 return FAIL;
27925
27926 *instruction &= OPCODE_MASK;
27927 *instruction |= new_inst << DATA_OP_SHIFT;
27928 return value;
b99bd4ef
NC
27929}
27930
ef8d22e6
PB
27931/* Like negate_data_op, but for Thumb-2. */
27932
27933static unsigned int
16dd5e42 27934thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
27935{
27936 int op, new_inst;
27937 int rd;
16dd5e42 27938 unsigned int negated, inverted;
ef8d22e6
PB
27939
27940 negated = encode_thumb32_immediate (-value);
27941 inverted = encode_thumb32_immediate (~value);
27942
27943 rd = (*instruction >> 8) & 0xf;
27944 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
27945 switch (op)
27946 {
27947 /* ADD <-> SUB. Includes CMP <-> CMN. */
27948 case T2_OPCODE_SUB:
27949 new_inst = T2_OPCODE_ADD;
27950 value = negated;
27951 break;
27952
27953 case T2_OPCODE_ADD:
27954 new_inst = T2_OPCODE_SUB;
27955 value = negated;
27956 break;
27957
27958 /* ORR <-> ORN. Includes MOV <-> MVN. */
27959 case T2_OPCODE_ORR:
27960 new_inst = T2_OPCODE_ORN;
27961 value = inverted;
27962 break;
27963
27964 case T2_OPCODE_ORN:
27965 new_inst = T2_OPCODE_ORR;
27966 value = inverted;
27967 break;
27968
27969 /* AND <-> BIC. TST has no inverted equivalent. */
27970 case T2_OPCODE_AND:
27971 new_inst = T2_OPCODE_BIC;
27972 if (rd == 15)
27973 value = FAIL;
27974 else
27975 value = inverted;
27976 break;
27977
27978 case T2_OPCODE_BIC:
27979 new_inst = T2_OPCODE_AND;
27980 value = inverted;
27981 break;
27982
27983 /* ADC <-> SBC */
27984 case T2_OPCODE_ADC:
27985 new_inst = T2_OPCODE_SBC;
27986 value = inverted;
27987 break;
27988
27989 case T2_OPCODE_SBC:
27990 new_inst = T2_OPCODE_ADC;
27991 value = inverted;
27992 break;
27993
27994 /* We cannot do anything. */
27995 default:
27996 return FAIL;
27997 }
27998
16dd5e42 27999 if (value == (unsigned int)FAIL)
ef8d22e6
PB
28000 return FAIL;
28001
28002 *instruction &= T2_OPCODE_MASK;
28003 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28004 return value;
28005}
28006
8f06b2d8 28007/* Read a 32-bit thumb instruction from buf. */
0198d5e6 28008
8f06b2d8
PB
28009static unsigned long
28010get_thumb32_insn (char * buf)
28011{
28012 unsigned long insn;
28013 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28014 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28015
28016 return insn;
28017}
28018
a8bc6c78
PB
28019/* We usually want to set the low bit on the address of thumb function
28020 symbols. In particular .word foo - . should have the low bit set.
28021 Generic code tries to fold the difference of two symbols to
28022 a constant. Prevent this and force a relocation when the first symbols
28023 is a thumb function. */
c921be7d
NC
28024
28025bfd_boolean
a8bc6c78
PB
28026arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28027{
28028 if (op == O_subtract
28029 && l->X_op == O_symbol
28030 && r->X_op == O_symbol
28031 && THUMB_IS_FUNC (l->X_add_symbol))
28032 {
28033 l->X_op = O_subtract;
28034 l->X_op_symbol = r->X_add_symbol;
28035 l->X_add_number -= r->X_add_number;
c921be7d 28036 return TRUE;
a8bc6c78 28037 }
c921be7d 28038
a8bc6c78 28039 /* Process as normal. */
c921be7d 28040 return FALSE;
a8bc6c78
PB
28041}
28042
4a42ebbc
RR
28043/* Encode Thumb2 unconditional branches and calls. The encoding
28044 for the 2 are identical for the immediate values. */
28045
28046static void
28047encode_thumb2_b_bl_offset (char * buf, offsetT value)
28048{
28049#define T2I1I2MASK ((1 << 13) | (1 << 11))
28050 offsetT newval;
28051 offsetT newval2;
28052 addressT S, I1, I2, lo, hi;
28053
28054 S = (value >> 24) & 0x01;
28055 I1 = (value >> 23) & 0x01;
28056 I2 = (value >> 22) & 0x01;
28057 hi = (value >> 12) & 0x3ff;
fa94de6b 28058 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
28059 newval = md_chars_to_number (buf, THUMB_SIZE);
28060 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28061 newval |= (S << 10) | hi;
28062 newval2 &= ~T2I1I2MASK;
28063 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28064 md_number_to_chars (buf, newval, THUMB_SIZE);
28065 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28066}
28067
c19d1205 28068void
55cf6793 28069md_apply_fix (fixS * fixP,
c19d1205
ZW
28070 valueT * valP,
28071 segT seg)
28072{
28073 offsetT value = * valP;
28074 offsetT newval;
28075 unsigned int newimm;
28076 unsigned long temp;
28077 int sign;
28078 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 28079
9c2799c2 28080 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 28081
c19d1205 28082 /* Note whether this will delete the relocation. */
4962c51a 28083
c19d1205
ZW
28084 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28085 fixP->fx_done = 1;
b99bd4ef 28086
adbaf948 28087 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 28088 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
28089 for emit_reloc. */
28090 value &= 0xffffffff;
28091 value ^= 0x80000000;
5f4273c7 28092 value -= 0x80000000;
adbaf948
ZW
28093
28094 *valP = value;
c19d1205 28095 fixP->fx_addnumber = value;
b99bd4ef 28096
adbaf948
ZW
28097 /* Same treatment for fixP->fx_offset. */
28098 fixP->fx_offset &= 0xffffffff;
28099 fixP->fx_offset ^= 0x80000000;
28100 fixP->fx_offset -= 0x80000000;
28101
c19d1205 28102 switch (fixP->fx_r_type)
b99bd4ef 28103 {
c19d1205
ZW
28104 case BFD_RELOC_NONE:
28105 /* This will need to go in the object file. */
28106 fixP->fx_done = 0;
28107 break;
b99bd4ef 28108
c19d1205
ZW
28109 case BFD_RELOC_ARM_IMMEDIATE:
28110 /* We claim that this fixup has been processed here,
28111 even if in fact we generate an error because we do
28112 not have a reloc for it, so tc_gen_reloc will reject it. */
28113 fixP->fx_done = 1;
b99bd4ef 28114
77db8e2e 28115 if (fixP->fx_addsy)
b99bd4ef 28116 {
77db8e2e 28117 const char *msg = 0;
b99bd4ef 28118
77db8e2e
NC
28119 if (! S_IS_DEFINED (fixP->fx_addsy))
28120 msg = _("undefined symbol %s used as an immediate value");
28121 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28122 msg = _("symbol %s is in a different section");
28123 else if (S_IS_WEAK (fixP->fx_addsy))
28124 msg = _("symbol %s is weak and may be overridden later");
28125
28126 if (msg)
28127 {
28128 as_bad_where (fixP->fx_file, fixP->fx_line,
28129 msg, S_GET_NAME (fixP->fx_addsy));
28130 break;
28131 }
42e5fcbf
AS
28132 }
28133
c19d1205
ZW
28134 temp = md_chars_to_number (buf, INSN_SIZE);
28135
5e73442d
SL
28136 /* If the offset is negative, we should use encoding A2 for ADR. */
28137 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
28138 newimm = negate_data_op (&temp, value);
28139 else
28140 {
28141 newimm = encode_arm_immediate (value);
28142
28143 /* If the instruction will fail, see if we can fix things up by
28144 changing the opcode. */
28145 if (newimm == (unsigned int) FAIL)
28146 newimm = negate_data_op (&temp, value);
bada4342
JW
28147 /* MOV accepts both ARM modified immediate (A1 encoding) and
28148 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28149 When disassembling, MOV is preferred when there is no encoding
28150 overlap. */
28151 if (newimm == (unsigned int) FAIL
28152 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28153 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28154 && !((temp >> SBIT_SHIFT) & 0x1)
28155 && value >= 0 && value <= 0xffff)
28156 {
28157 /* Clear bits[23:20] to change encoding from A1 to A2. */
28158 temp &= 0xff0fffff;
28159 /* Encoding high 4bits imm. Code below will encode the remaining
28160 low 12bits. */
28161 temp |= (value & 0x0000f000) << 4;
28162 newimm = value & 0x00000fff;
28163 }
5e73442d
SL
28164 }
28165
28166 if (newimm == (unsigned int) FAIL)
b99bd4ef 28167 {
c19d1205
ZW
28168 as_bad_where (fixP->fx_file, fixP->fx_line,
28169 _("invalid constant (%lx) after fixup"),
28170 (unsigned long) value);
28171 break;
b99bd4ef 28172 }
b99bd4ef 28173
c19d1205
ZW
28174 newimm |= (temp & 0xfffff000);
28175 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28176 break;
b99bd4ef 28177
c19d1205
ZW
28178 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28179 {
28180 unsigned int highpart = 0;
28181 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 28182
77db8e2e 28183 if (fixP->fx_addsy)
42e5fcbf 28184 {
77db8e2e 28185 const char *msg = 0;
42e5fcbf 28186
77db8e2e
NC
28187 if (! S_IS_DEFINED (fixP->fx_addsy))
28188 msg = _("undefined symbol %s used as an immediate value");
28189 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28190 msg = _("symbol %s is in a different section");
28191 else if (S_IS_WEAK (fixP->fx_addsy))
28192 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 28193
77db8e2e
NC
28194 if (msg)
28195 {
28196 as_bad_where (fixP->fx_file, fixP->fx_line,
28197 msg, S_GET_NAME (fixP->fx_addsy));
28198 break;
28199 }
28200 }
fa94de6b 28201
c19d1205
ZW
28202 newimm = encode_arm_immediate (value);
28203 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 28204
c19d1205
ZW
28205 /* If the instruction will fail, see if we can fix things up by
28206 changing the opcode. */
28207 if (newimm == (unsigned int) FAIL
28208 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28209 {
28210 /* No ? OK - try using two ADD instructions to generate
28211 the value. */
28212 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 28213
c19d1205
ZW
28214 /* Yes - then make sure that the second instruction is
28215 also an add. */
28216 if (newimm != (unsigned int) FAIL)
28217 newinsn = temp;
28218 /* Still No ? Try using a negated value. */
28219 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28220 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28221 /* Otherwise - give up. */
28222 else
28223 {
28224 as_bad_where (fixP->fx_file, fixP->fx_line,
28225 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28226 (long) value);
28227 break;
28228 }
b99bd4ef 28229
c19d1205
ZW
28230 /* Replace the first operand in the 2nd instruction (which
28231 is the PC) with the destination register. We have
28232 already added in the PC in the first instruction and we
28233 do not want to do it again. */
28234 newinsn &= ~ 0xf0000;
28235 newinsn |= ((newinsn & 0x0f000) << 4);
28236 }
b99bd4ef 28237
c19d1205
ZW
28238 newimm |= (temp & 0xfffff000);
28239 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 28240
c19d1205
ZW
28241 highpart |= (newinsn & 0xfffff000);
28242 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28243 }
28244 break;
b99bd4ef 28245
c19d1205 28246 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
28247 if (!fixP->fx_done && seg->use_rela_p)
28248 value = 0;
1a0670f3 28249 /* Fall through. */
00a97672 28250
c19d1205 28251 case BFD_RELOC_ARM_LITERAL:
26d97720 28252 sign = value > 0;
b99bd4ef 28253
c19d1205
ZW
28254 if (value < 0)
28255 value = - value;
b99bd4ef 28256
c19d1205 28257 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 28258 {
c19d1205
ZW
28259 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28260 as_bad_where (fixP->fx_file, fixP->fx_line,
28261 _("invalid literal constant: pool needs to be closer"));
28262 else
28263 as_bad_where (fixP->fx_file, fixP->fx_line,
28264 _("bad immediate value for offset (%ld)"),
28265 (long) value);
28266 break;
f03698e6
RE
28267 }
28268
c19d1205 28269 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28270 if (value == 0)
28271 newval &= 0xfffff000;
28272 else
28273 {
28274 newval &= 0xff7ff000;
28275 newval |= value | (sign ? INDEX_UP : 0);
28276 }
c19d1205
ZW
28277 md_number_to_chars (buf, newval, INSN_SIZE);
28278 break;
b99bd4ef 28279
c19d1205
ZW
28280 case BFD_RELOC_ARM_OFFSET_IMM8:
28281 case BFD_RELOC_ARM_HWLITERAL:
26d97720 28282 sign = value > 0;
b99bd4ef 28283
c19d1205
ZW
28284 if (value < 0)
28285 value = - value;
b99bd4ef 28286
c19d1205 28287 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 28288 {
c19d1205
ZW
28289 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28290 as_bad_where (fixP->fx_file, fixP->fx_line,
28291 _("invalid literal constant: pool needs to be closer"));
28292 else
427d0db6
RM
28293 as_bad_where (fixP->fx_file, fixP->fx_line,
28294 _("bad immediate value for 8-bit offset (%ld)"),
28295 (long) value);
c19d1205 28296 break;
b99bd4ef
NC
28297 }
28298
c19d1205 28299 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28300 if (value == 0)
28301 newval &= 0xfffff0f0;
28302 else
28303 {
28304 newval &= 0xff7ff0f0;
28305 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28306 }
c19d1205
ZW
28307 md_number_to_chars (buf, newval, INSN_SIZE);
28308 break;
b99bd4ef 28309
c19d1205
ZW
28310 case BFD_RELOC_ARM_T32_OFFSET_U8:
28311 if (value < 0 || value > 1020 || value % 4 != 0)
28312 as_bad_where (fixP->fx_file, fixP->fx_line,
28313 _("bad immediate value for offset (%ld)"), (long) value);
28314 value /= 4;
b99bd4ef 28315
c19d1205 28316 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
28317 newval |= value;
28318 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28319 break;
b99bd4ef 28320
c19d1205
ZW
28321 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28322 /* This is a complicated relocation used for all varieties of Thumb32
28323 load/store instruction with immediate offset:
28324
28325 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 28326 *4, optional writeback(W)
c19d1205
ZW
28327 (doubleword load/store)
28328
28329 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28330 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28331 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28332 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28333 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28334
28335 Uppercase letters indicate bits that are already encoded at
28336 this point. Lowercase letters are our problem. For the
28337 second block of instructions, the secondary opcode nybble
28338 (bits 8..11) is present, and bit 23 is zero, even if this is
28339 a PC-relative operation. */
28340 newval = md_chars_to_number (buf, THUMB_SIZE);
28341 newval <<= 16;
28342 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 28343
c19d1205 28344 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 28345 {
c19d1205
ZW
28346 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28347 if (value >= 0)
28348 newval |= (1 << 23);
28349 else
28350 value = -value;
28351 if (value % 4 != 0)
28352 {
28353 as_bad_where (fixP->fx_file, fixP->fx_line,
28354 _("offset not a multiple of 4"));
28355 break;
28356 }
28357 value /= 4;
216d22bc 28358 if (value > 0xff)
c19d1205
ZW
28359 {
28360 as_bad_where (fixP->fx_file, fixP->fx_line,
28361 _("offset out of range"));
28362 break;
28363 }
28364 newval &= ~0xff;
b99bd4ef 28365 }
c19d1205 28366 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 28367 {
c19d1205
ZW
28368 /* PC-relative, 12-bit offset. */
28369 if (value >= 0)
28370 newval |= (1 << 23);
28371 else
28372 value = -value;
216d22bc 28373 if (value > 0xfff)
c19d1205
ZW
28374 {
28375 as_bad_where (fixP->fx_file, fixP->fx_line,
28376 _("offset out of range"));
28377 break;
28378 }
28379 newval &= ~0xfff;
b99bd4ef 28380 }
c19d1205 28381 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 28382 {
c19d1205
ZW
28383 /* Writeback: 8-bit, +/- offset. */
28384 if (value >= 0)
28385 newval |= (1 << 9);
28386 else
28387 value = -value;
216d22bc 28388 if (value > 0xff)
c19d1205
ZW
28389 {
28390 as_bad_where (fixP->fx_file, fixP->fx_line,
28391 _("offset out of range"));
28392 break;
28393 }
28394 newval &= ~0xff;
b99bd4ef 28395 }
c19d1205 28396 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 28397 {
c19d1205 28398 /* T-instruction: positive 8-bit offset. */
216d22bc 28399 if (value < 0 || value > 0xff)
b99bd4ef 28400 {
c19d1205
ZW
28401 as_bad_where (fixP->fx_file, fixP->fx_line,
28402 _("offset out of range"));
28403 break;
b99bd4ef 28404 }
c19d1205
ZW
28405 newval &= ~0xff;
28406 newval |= value;
b99bd4ef
NC
28407 }
28408 else
b99bd4ef 28409 {
c19d1205
ZW
28410 /* Positive 12-bit or negative 8-bit offset. */
28411 int limit;
28412 if (value >= 0)
b99bd4ef 28413 {
c19d1205
ZW
28414 newval |= (1 << 23);
28415 limit = 0xfff;
28416 }
28417 else
28418 {
28419 value = -value;
28420 limit = 0xff;
28421 }
28422 if (value > limit)
28423 {
28424 as_bad_where (fixP->fx_file, fixP->fx_line,
28425 _("offset out of range"));
28426 break;
b99bd4ef 28427 }
c19d1205 28428 newval &= ~limit;
b99bd4ef 28429 }
b99bd4ef 28430
c19d1205
ZW
28431 newval |= value;
28432 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28433 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28434 break;
404ff6b5 28435
c19d1205
ZW
28436 case BFD_RELOC_ARM_SHIFT_IMM:
28437 newval = md_chars_to_number (buf, INSN_SIZE);
28438 if (((unsigned long) value) > 32
28439 || (value == 32
28440 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28441 {
28442 as_bad_where (fixP->fx_file, fixP->fx_line,
28443 _("shift expression is too large"));
28444 break;
28445 }
404ff6b5 28446
c19d1205
ZW
28447 if (value == 0)
28448 /* Shifts of zero must be done as lsl. */
28449 newval &= ~0x60;
28450 else if (value == 32)
28451 value = 0;
28452 newval &= 0xfffff07f;
28453 newval |= (value & 0x1f) << 7;
28454 md_number_to_chars (buf, newval, INSN_SIZE);
28455 break;
404ff6b5 28456
c19d1205 28457 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 28458 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 28459 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 28460 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
28461 /* We claim that this fixup has been processed here,
28462 even if in fact we generate an error because we do
28463 not have a reloc for it, so tc_gen_reloc will reject it. */
28464 fixP->fx_done = 1;
404ff6b5 28465
c19d1205
ZW
28466 if (fixP->fx_addsy
28467 && ! S_IS_DEFINED (fixP->fx_addsy))
28468 {
28469 as_bad_where (fixP->fx_file, fixP->fx_line,
28470 _("undefined symbol %s used as an immediate value"),
28471 S_GET_NAME (fixP->fx_addsy));
28472 break;
28473 }
404ff6b5 28474
c19d1205
ZW
28475 newval = md_chars_to_number (buf, THUMB_SIZE);
28476 newval <<= 16;
28477 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 28478
16805f35 28479 newimm = FAIL;
bada4342
JW
28480 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28481 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28482 Thumb2 modified immediate encoding (T2). */
28483 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 28484 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
28485 {
28486 newimm = encode_thumb32_immediate (value);
28487 if (newimm == (unsigned int) FAIL)
28488 newimm = thumb32_negate_data_op (&newval, value);
28489 }
bada4342 28490 if (newimm == (unsigned int) FAIL)
92e90b6e 28491 {
bada4342 28492 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 28493 {
bada4342
JW
28494 /* Turn add/sum into addw/subw. */
28495 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28496 newval = (newval & 0xfeffffff) | 0x02000000;
28497 /* No flat 12-bit imm encoding for addsw/subsw. */
28498 if ((newval & 0x00100000) == 0)
40f246e3 28499 {
bada4342
JW
28500 /* 12 bit immediate for addw/subw. */
28501 if (value < 0)
28502 {
28503 value = -value;
28504 newval ^= 0x00a00000;
28505 }
28506 if (value > 0xfff)
28507 newimm = (unsigned int) FAIL;
28508 else
28509 newimm = value;
28510 }
28511 }
28512 else
28513 {
28514 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28515 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28516 disassembling, MOV is preferred when there is no encoding
db7bf105 28517 overlap. */
bada4342 28518 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
28519 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28520 but with the Rn field [19:16] set to 1111. */
28521 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
28522 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28523 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 28524 && value >= 0 && value <= 0xffff)
bada4342
JW
28525 {
28526 /* Toggle bit[25] to change encoding from T2 to T3. */
28527 newval ^= 1 << 25;
28528 /* Clear bits[19:16]. */
28529 newval &= 0xfff0ffff;
28530 /* Encoding high 4bits imm. Code below will encode the
28531 remaining low 12bits. */
28532 newval |= (value & 0x0000f000) << 4;
28533 newimm = value & 0x00000fff;
40f246e3 28534 }
e9f89963 28535 }
92e90b6e 28536 }
cc8a6dd0 28537
c19d1205 28538 if (newimm == (unsigned int)FAIL)
3631a3c8 28539 {
c19d1205
ZW
28540 as_bad_where (fixP->fx_file, fixP->fx_line,
28541 _("invalid constant (%lx) after fixup"),
28542 (unsigned long) value);
28543 break;
3631a3c8
NC
28544 }
28545
c19d1205
ZW
28546 newval |= (newimm & 0x800) << 15;
28547 newval |= (newimm & 0x700) << 4;
28548 newval |= (newimm & 0x0ff);
cc8a6dd0 28549
c19d1205
ZW
28550 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28551 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28552 break;
a737bd4d 28553
3eb17e6b 28554 case BFD_RELOC_ARM_SMC:
ba85f98c 28555 if (((unsigned long) value) > 0xf)
c19d1205 28556 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 28557 _("invalid smc expression"));
ba85f98c 28558
2fc8bdac 28559 newval = md_chars_to_number (buf, INSN_SIZE);
ba85f98c 28560 newval |= (value & 0xf);
c19d1205
ZW
28561 md_number_to_chars (buf, newval, INSN_SIZE);
28562 break;
a737bd4d 28563
90ec0d68
MGD
28564 case BFD_RELOC_ARM_HVC:
28565 if (((unsigned long) value) > 0xffff)
28566 as_bad_where (fixP->fx_file, fixP->fx_line,
28567 _("invalid hvc expression"));
28568 newval = md_chars_to_number (buf, INSN_SIZE);
28569 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28570 md_number_to_chars (buf, newval, INSN_SIZE);
28571 break;
28572
c19d1205 28573 case BFD_RELOC_ARM_SWI:
adbaf948 28574 if (fixP->tc_fix_data != 0)
c19d1205
ZW
28575 {
28576 if (((unsigned long) value) > 0xff)
28577 as_bad_where (fixP->fx_file, fixP->fx_line,
28578 _("invalid swi expression"));
2fc8bdac 28579 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
28580 newval |= value;
28581 md_number_to_chars (buf, newval, THUMB_SIZE);
28582 }
28583 else
28584 {
28585 if (((unsigned long) value) > 0x00ffffff)
28586 as_bad_where (fixP->fx_file, fixP->fx_line,
28587 _("invalid swi expression"));
2fc8bdac 28588 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
28589 newval |= value;
28590 md_number_to_chars (buf, newval, INSN_SIZE);
28591 }
28592 break;
a737bd4d 28593
c19d1205
ZW
28594 case BFD_RELOC_ARM_MULTI:
28595 if (((unsigned long) value) > 0xffff)
28596 as_bad_where (fixP->fx_file, fixP->fx_line,
28597 _("invalid expression in load/store multiple"));
28598 newval = value | md_chars_to_number (buf, INSN_SIZE);
28599 md_number_to_chars (buf, newval, INSN_SIZE);
28600 break;
a737bd4d 28601
c19d1205 28602#ifdef OBJ_ELF
39b41c9c 28603 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
28604
28605 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28606 && fixP->fx_addsy
34e77a92 28607 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28608 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28609 && THUMB_IS_FUNC (fixP->fx_addsy))
28610 /* Flip the bl to blx. This is a simple flip
28611 bit here because we generate PCREL_CALL for
28612 unconditional bls. */
28613 {
28614 newval = md_chars_to_number (buf, INSN_SIZE);
28615 newval = newval | 0x10000000;
28616 md_number_to_chars (buf, newval, INSN_SIZE);
28617 temp = 1;
28618 fixP->fx_done = 1;
28619 }
39b41c9c
PB
28620 else
28621 temp = 3;
28622 goto arm_branch_common;
28623
28624 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
28625 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28626 && fixP->fx_addsy
34e77a92 28627 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28628 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28629 && THUMB_IS_FUNC (fixP->fx_addsy))
28630 {
28631 /* This would map to a bl<cond>, b<cond>,
28632 b<always> to a Thumb function. We
28633 need to force a relocation for this particular
28634 case. */
28635 newval = md_chars_to_number (buf, INSN_SIZE);
28636 fixP->fx_done = 0;
28637 }
1a0670f3 28638 /* Fall through. */
267bf995 28639
2fc8bdac 28640 case BFD_RELOC_ARM_PLT32:
c19d1205 28641#endif
39b41c9c
PB
28642 case BFD_RELOC_ARM_PCREL_BRANCH:
28643 temp = 3;
28644 goto arm_branch_common;
a737bd4d 28645
39b41c9c 28646 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 28647
39b41c9c 28648 temp = 1;
267bf995
RR
28649 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28650 && fixP->fx_addsy
34e77a92 28651 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28652 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28653 && ARM_IS_FUNC (fixP->fx_addsy))
28654 {
28655 /* Flip the blx to a bl and warn. */
28656 const char *name = S_GET_NAME (fixP->fx_addsy);
28657 newval = 0xeb000000;
28658 as_warn_where (fixP->fx_file, fixP->fx_line,
28659 _("blx to '%s' an ARM ISA state function changed to bl"),
28660 name);
28661 md_number_to_chars (buf, newval, INSN_SIZE);
28662 temp = 3;
28663 fixP->fx_done = 1;
28664 }
28665
28666#ifdef OBJ_ELF
28667 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 28668 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
28669#endif
28670
39b41c9c 28671 arm_branch_common:
c19d1205 28672 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
28673 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28674 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 28675 also be clear. */
39b41c9c 28676 if (value & temp)
c19d1205 28677 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
28678 _("misaligned branch destination"));
28679 if ((value & (offsetT)0xfe000000) != (offsetT)0
28680 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 28681 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28682
2fc8bdac 28683 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28684 {
2fc8bdac
ZW
28685 newval = md_chars_to_number (buf, INSN_SIZE);
28686 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
28687 /* Set the H bit on BLX instructions. */
28688 if (temp == 1)
28689 {
28690 if (value & 2)
28691 newval |= 0x01000000;
28692 else
28693 newval &= ~0x01000000;
28694 }
2fc8bdac 28695 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 28696 }
c19d1205 28697 break;
a737bd4d 28698
25fe350b
MS
28699 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28700 /* CBZ can only branch forward. */
a737bd4d 28701
738755b0 28702 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
28703 (which, strictly speaking, are prohibited) will be turned into
28704 no-ops.
738755b0
MS
28705
28706 FIXME: It may be better to remove the instruction completely and
28707 perform relaxation. */
28708 if (value == -2)
2fc8bdac
ZW
28709 {
28710 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 28711 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
28712 md_number_to_chars (buf, newval, THUMB_SIZE);
28713 }
738755b0
MS
28714 else
28715 {
28716 if (value & ~0x7e)
08f10d51 28717 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 28718
477330fc 28719 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
28720 {
28721 newval = md_chars_to_number (buf, THUMB_SIZE);
28722 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28723 md_number_to_chars (buf, newval, THUMB_SIZE);
28724 }
28725 }
c19d1205 28726 break;
a737bd4d 28727
c19d1205 28728 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
e8f8842d 28729 if (out_of_range_p (value, 8))
08f10d51 28730 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28731
2fc8bdac
ZW
28732 if (fixP->fx_done || !seg->use_rela_p)
28733 {
28734 newval = md_chars_to_number (buf, THUMB_SIZE);
28735 newval |= (value & 0x1ff) >> 1;
28736 md_number_to_chars (buf, newval, THUMB_SIZE);
28737 }
c19d1205 28738 break;
a737bd4d 28739
c19d1205 28740 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
e8f8842d 28741 if (out_of_range_p (value, 11))
08f10d51 28742 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28743
2fc8bdac
ZW
28744 if (fixP->fx_done || !seg->use_rela_p)
28745 {
28746 newval = md_chars_to_number (buf, THUMB_SIZE);
28747 newval |= (value & 0xfff) >> 1;
28748 md_number_to_chars (buf, newval, THUMB_SIZE);
28749 }
c19d1205 28750 break;
a737bd4d 28751
e8f8842d 28752 /* This relocation is misnamed, it should be BRANCH21. */
c19d1205 28753 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
28754 if (fixP->fx_addsy
28755 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28756 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28757 && ARM_IS_FUNC (fixP->fx_addsy)
28758 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28759 {
28760 /* Force a relocation for a branch 20 bits wide. */
28761 fixP->fx_done = 0;
28762 }
e8f8842d 28763 if (out_of_range_p (value, 20))
2fc8bdac
ZW
28764 as_bad_where (fixP->fx_file, fixP->fx_line,
28765 _("conditional branch out of range"));
404ff6b5 28766
2fc8bdac
ZW
28767 if (fixP->fx_done || !seg->use_rela_p)
28768 {
28769 offsetT newval2;
28770 addressT S, J1, J2, lo, hi;
404ff6b5 28771
2fc8bdac
ZW
28772 S = (value & 0x00100000) >> 20;
28773 J2 = (value & 0x00080000) >> 19;
28774 J1 = (value & 0x00040000) >> 18;
28775 hi = (value & 0x0003f000) >> 12;
28776 lo = (value & 0x00000ffe) >> 1;
6c43fab6 28777
2fc8bdac
ZW
28778 newval = md_chars_to_number (buf, THUMB_SIZE);
28779 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28780 newval |= (S << 10) | hi;
28781 newval2 |= (J1 << 13) | (J2 << 11) | lo;
28782 md_number_to_chars (buf, newval, THUMB_SIZE);
28783 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28784 }
c19d1205 28785 break;
6c43fab6 28786
c19d1205 28787 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
28788 /* If there is a blx from a thumb state function to
28789 another thumb function flip this to a bl and warn
28790 about it. */
28791
28792 if (fixP->fx_addsy
34e77a92 28793 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28794 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28795 && THUMB_IS_FUNC (fixP->fx_addsy))
28796 {
28797 const char *name = S_GET_NAME (fixP->fx_addsy);
28798 as_warn_where (fixP->fx_file, fixP->fx_line,
28799 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
28800 name);
28801 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28802 newval = newval | 0x1000;
28803 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28804 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28805 fixP->fx_done = 1;
28806 }
28807
28808
28809 goto thumb_bl_common;
28810
c19d1205 28811 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
28812 /* A bl from Thumb state ISA to an internal ARM state function
28813 is converted to a blx. */
28814 if (fixP->fx_addsy
28815 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28816 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28817 && ARM_IS_FUNC (fixP->fx_addsy)
28818 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28819 {
28820 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28821 newval = newval & ~0x1000;
28822 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28823 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
28824 fixP->fx_done = 1;
28825 }
28826
28827 thumb_bl_common:
28828
2fc8bdac
ZW
28829 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28830 /* For a BLX instruction, make sure that the relocation is rounded up
28831 to a word boundary. This follows the semantics of the instruction
28832 which specifies that bit 1 of the target address will come from bit
28833 1 of the base address. */
d406f3e4
JB
28834 value = (value + 3) & ~ 3;
28835
28836#ifdef OBJ_ELF
28837 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
28838 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28839 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28840#endif
404ff6b5 28841
e8f8842d 28842 if (out_of_range_p (value, 22))
2b2f5df9 28843 {
fc289b0a 28844 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9 28845 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
e8f8842d 28846 else if (out_of_range_p (value, 24))
2b2f5df9
NC
28847 as_bad_where (fixP->fx_file, fixP->fx_line,
28848 _("Thumb2 branch out of range"));
28849 }
4a42ebbc
RR
28850
28851 if (fixP->fx_done || !seg->use_rela_p)
28852 encode_thumb2_b_bl_offset (buf, value);
28853
c19d1205 28854 break;
404ff6b5 28855
c19d1205 28856 case BFD_RELOC_THUMB_PCREL_BRANCH25:
e8f8842d 28857 if (out_of_range_p (value, 24))
08f10d51 28858 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 28859
2fc8bdac 28860 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 28861 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 28862
2fc8bdac 28863 break;
a737bd4d 28864
2fc8bdac
ZW
28865 case BFD_RELOC_8:
28866 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 28867 *buf = value;
c19d1205 28868 break;
a737bd4d 28869
c19d1205 28870 case BFD_RELOC_16:
2fc8bdac 28871 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28872 md_number_to_chars (buf, value, 2);
c19d1205 28873 break;
a737bd4d 28874
c19d1205 28875#ifdef OBJ_ELF
0855e32b
NS
28876 case BFD_RELOC_ARM_TLS_CALL:
28877 case BFD_RELOC_ARM_THM_TLS_CALL:
28878 case BFD_RELOC_ARM_TLS_DESCSEQ:
28879 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 28880 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
28881 case BFD_RELOC_ARM_TLS_GD32:
28882 case BFD_RELOC_ARM_TLS_LE32:
28883 case BFD_RELOC_ARM_TLS_IE32:
28884 case BFD_RELOC_ARM_TLS_LDM32:
28885 case BFD_RELOC_ARM_TLS_LDO32:
28886 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 28887 break;
6c43fab6 28888
5c5a4843
CL
28889 /* Same handling as above, but with the arm_fdpic guard. */
28890 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
28891 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
28892 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
28893 if (arm_fdpic)
28894 {
28895 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28896 }
28897 else
28898 {
28899 as_bad_where (fixP->fx_file, fixP->fx_line,
28900 _("Relocation supported only in FDPIC mode"));
28901 }
28902 break;
28903
c19d1205
ZW
28904 case BFD_RELOC_ARM_GOT32:
28905 case BFD_RELOC_ARM_GOTOFF:
c19d1205 28906 break;
b43420e6
NC
28907
28908 case BFD_RELOC_ARM_GOT_PREL:
28909 if (fixP->fx_done || !seg->use_rela_p)
477330fc 28910 md_number_to_chars (buf, value, 4);
b43420e6
NC
28911 break;
28912
9a6f4e97
NS
28913 case BFD_RELOC_ARM_TARGET2:
28914 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
28915 addend here for REL targets, because it won't be written out
28916 during reloc processing later. */
9a6f4e97
NS
28917 if (fixP->fx_done || !seg->use_rela_p)
28918 md_number_to_chars (buf, fixP->fx_offset, 4);
28919 break;
188fd7ae
CL
28920
28921 /* Relocations for FDPIC. */
28922 case BFD_RELOC_ARM_GOTFUNCDESC:
28923 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
28924 case BFD_RELOC_ARM_FUNCDESC:
28925 if (arm_fdpic)
28926 {
28927 if (fixP->fx_done || !seg->use_rela_p)
28928 md_number_to_chars (buf, 0, 4);
28929 }
28930 else
28931 {
28932 as_bad_where (fixP->fx_file, fixP->fx_line,
28933 _("Relocation supported only in FDPIC mode"));
28934 }
28935 break;
c19d1205 28936#endif
6c43fab6 28937
c19d1205
ZW
28938 case BFD_RELOC_RVA:
28939 case BFD_RELOC_32:
28940 case BFD_RELOC_ARM_TARGET1:
28941 case BFD_RELOC_ARM_ROSEGREL32:
28942 case BFD_RELOC_ARM_SBREL32:
28943 case BFD_RELOC_32_PCREL:
f0927246
NC
28944#ifdef TE_PE
28945 case BFD_RELOC_32_SECREL:
28946#endif
2fc8bdac 28947 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
28948#ifdef TE_WINCE
28949 /* For WinCE we only do this for pcrel fixups. */
28950 if (fixP->fx_done || fixP->fx_pcrel)
28951#endif
28952 md_number_to_chars (buf, value, 4);
c19d1205 28953 break;
6c43fab6 28954
c19d1205
ZW
28955#ifdef OBJ_ELF
28956 case BFD_RELOC_ARM_PREL31:
2fc8bdac 28957 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
28958 {
28959 newval = md_chars_to_number (buf, 4) & 0x80000000;
28960 if ((value ^ (value >> 1)) & 0x40000000)
28961 {
28962 as_bad_where (fixP->fx_file, fixP->fx_line,
28963 _("rel31 relocation overflow"));
28964 }
28965 newval |= value & 0x7fffffff;
28966 md_number_to_chars (buf, newval, 4);
28967 }
28968 break;
c19d1205 28969#endif
a737bd4d 28970
c19d1205 28971 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 28972 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 28973 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
28974 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
28975 newval = md_chars_to_number (buf, INSN_SIZE);
28976 else
28977 newval = get_thumb32_insn (buf);
28978 if ((newval & 0x0f200f00) == 0x0d000900)
28979 {
28980 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
28981 has permitted values that are multiples of 2, in the range 0
28982 to 510. */
28983 if (value < -510 || value > 510 || (value & 1))
28984 as_bad_where (fixP->fx_file, fixP->fx_line,
28985 _("co-processor offset out of range"));
28986 }
32c36c3c
AV
28987 else if ((newval & 0xfe001f80) == 0xec000f80)
28988 {
28989 if (value < -511 || value > 512 || (value & 3))
28990 as_bad_where (fixP->fx_file, fixP->fx_line,
28991 _("co-processor offset out of range"));
28992 }
9db2f6b4 28993 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
28994 as_bad_where (fixP->fx_file, fixP->fx_line,
28995 _("co-processor offset out of range"));
28996 cp_off_common:
26d97720 28997 sign = value > 0;
c19d1205
ZW
28998 if (value < 0)
28999 value = -value;
8f06b2d8
PB
29000 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29001 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29002 newval = md_chars_to_number (buf, INSN_SIZE);
29003 else
29004 newval = get_thumb32_insn (buf);
26d97720 29005 if (value == 0)
32c36c3c
AV
29006 {
29007 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29008 newval &= 0xffffff80;
29009 else
29010 newval &= 0xffffff00;
29011 }
26d97720
NS
29012 else
29013 {
32c36c3c
AV
29014 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29015 newval &= 0xff7fff80;
29016 else
29017 newval &= 0xff7fff00;
9db2f6b4
RL
29018 if ((newval & 0x0f200f00) == 0x0d000900)
29019 {
29020 /* This is a fp16 vstr/vldr.
29021
29022 It requires the immediate offset in the instruction is shifted
29023 left by 1 to be a half-word offset.
29024
29025 Here, left shift by 1 first, and later right shift by 2
29026 should get the right offset. */
29027 value <<= 1;
29028 }
26d97720
NS
29029 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29030 }
8f06b2d8
PB
29031 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29032 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29033 md_number_to_chars (buf, newval, INSN_SIZE);
29034 else
29035 put_thumb32_insn (buf, newval);
c19d1205 29036 break;
a737bd4d 29037
c19d1205 29038 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 29039 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
29040 if (value < -255 || value > 255)
29041 as_bad_where (fixP->fx_file, fixP->fx_line,
29042 _("co-processor offset out of range"));
df7849c5 29043 value *= 4;
c19d1205 29044 goto cp_off_common;
6c43fab6 29045
c19d1205
ZW
29046 case BFD_RELOC_ARM_THUMB_OFFSET:
29047 newval = md_chars_to_number (buf, THUMB_SIZE);
29048 /* Exactly what ranges, and where the offset is inserted depends
29049 on the type of instruction, we can establish this from the
29050 top 4 bits. */
29051 switch (newval >> 12)
29052 {
29053 case 4: /* PC load. */
29054 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29055 forced to zero for these loads; md_pcrel_from has already
29056 compensated for this. */
29057 if (value & 3)
29058 as_bad_where (fixP->fx_file, fixP->fx_line,
29059 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
29060 (((unsigned long) fixP->fx_frag->fr_address
29061 + (unsigned long) fixP->fx_where) & ~3)
29062 + (unsigned long) value);
a737bd4d 29063
c19d1205
ZW
29064 if (value & ~0x3fc)
29065 as_bad_where (fixP->fx_file, fixP->fx_line,
29066 _("invalid offset, value too big (0x%08lX)"),
29067 (long) value);
a737bd4d 29068
c19d1205
ZW
29069 newval |= value >> 2;
29070 break;
a737bd4d 29071
c19d1205
ZW
29072 case 9: /* SP load/store. */
29073 if (value & ~0x3fc)
29074 as_bad_where (fixP->fx_file, fixP->fx_line,
29075 _("invalid offset, value too big (0x%08lX)"),
29076 (long) value);
29077 newval |= value >> 2;
29078 break;
6c43fab6 29079
c19d1205
ZW
29080 case 6: /* Word load/store. */
29081 if (value & ~0x7c)
29082 as_bad_where (fixP->fx_file, fixP->fx_line,
29083 _("invalid offset, value too big (0x%08lX)"),
29084 (long) value);
29085 newval |= value << 4; /* 6 - 2. */
29086 break;
a737bd4d 29087
c19d1205
ZW
29088 case 7: /* Byte load/store. */
29089 if (value & ~0x1f)
29090 as_bad_where (fixP->fx_file, fixP->fx_line,
29091 _("invalid offset, value too big (0x%08lX)"),
29092 (long) value);
29093 newval |= value << 6;
29094 break;
a737bd4d 29095
c19d1205
ZW
29096 case 8: /* Halfword load/store. */
29097 if (value & ~0x3e)
29098 as_bad_where (fixP->fx_file, fixP->fx_line,
29099 _("invalid offset, value too big (0x%08lX)"),
29100 (long) value);
29101 newval |= value << 5; /* 6 - 1. */
29102 break;
a737bd4d 29103
c19d1205
ZW
29104 default:
29105 as_bad_where (fixP->fx_file, fixP->fx_line,
29106 "Unable to process relocation for thumb opcode: %lx",
29107 (unsigned long) newval);
29108 break;
29109 }
29110 md_number_to_chars (buf, newval, THUMB_SIZE);
29111 break;
a737bd4d 29112
c19d1205
ZW
29113 case BFD_RELOC_ARM_THUMB_ADD:
29114 /* This is a complicated relocation, since we use it for all of
29115 the following immediate relocations:
a737bd4d 29116
c19d1205
ZW
29117 3bit ADD/SUB
29118 8bit ADD/SUB
29119 9bit ADD/SUB SP word-aligned
29120 10bit ADD PC/SP word-aligned
a737bd4d 29121
c19d1205
ZW
29122 The type of instruction being processed is encoded in the
29123 instruction field:
a737bd4d 29124
c19d1205
ZW
29125 0x8000 SUB
29126 0x00F0 Rd
29127 0x000F Rs
29128 */
29129 newval = md_chars_to_number (buf, THUMB_SIZE);
29130 {
29131 int rd = (newval >> 4) & 0xf;
29132 int rs = newval & 0xf;
29133 int subtract = !!(newval & 0x8000);
a737bd4d 29134
c19d1205
ZW
29135 /* Check for HI regs, only very restricted cases allowed:
29136 Adjusting SP, and using PC or SP to get an address. */
29137 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29138 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29139 as_bad_where (fixP->fx_file, fixP->fx_line,
29140 _("invalid Hi register with immediate"));
a737bd4d 29141
c19d1205
ZW
29142 /* If value is negative, choose the opposite instruction. */
29143 if (value < 0)
29144 {
29145 value = -value;
29146 subtract = !subtract;
29147 if (value < 0)
29148 as_bad_where (fixP->fx_file, fixP->fx_line,
29149 _("immediate value out of range"));
29150 }
a737bd4d 29151
c19d1205
ZW
29152 if (rd == REG_SP)
29153 {
75c11999 29154 if (value & ~0x1fc)
c19d1205
ZW
29155 as_bad_where (fixP->fx_file, fixP->fx_line,
29156 _("invalid immediate for stack address calculation"));
29157 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29158 newval |= value >> 2;
29159 }
29160 else if (rs == REG_PC || rs == REG_SP)
29161 {
c12d2c9d
NC
29162 /* PR gas/18541. If the addition is for a defined symbol
29163 within range of an ADR instruction then accept it. */
29164 if (subtract
29165 && value == 4
29166 && fixP->fx_addsy != NULL)
29167 {
29168 subtract = 0;
29169
29170 if (! S_IS_DEFINED (fixP->fx_addsy)
29171 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29172 || S_IS_WEAK (fixP->fx_addsy))
29173 {
29174 as_bad_where (fixP->fx_file, fixP->fx_line,
29175 _("address calculation needs a strongly defined nearby symbol"));
29176 }
29177 else
29178 {
29179 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29180
29181 /* Round up to the next 4-byte boundary. */
29182 if (v & 3)
29183 v = (v + 3) & ~ 3;
29184 else
29185 v += 4;
29186 v = S_GET_VALUE (fixP->fx_addsy) - v;
29187
29188 if (v & ~0x3fc)
29189 {
29190 as_bad_where (fixP->fx_file, fixP->fx_line,
29191 _("symbol too far away"));
29192 }
29193 else
29194 {
29195 fixP->fx_done = 1;
29196 value = v;
29197 }
29198 }
29199 }
29200
c19d1205
ZW
29201 if (subtract || value & ~0x3fc)
29202 as_bad_where (fixP->fx_file, fixP->fx_line,
29203 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 29204 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
29205 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29206 newval |= rd << 8;
29207 newval |= value >> 2;
29208 }
29209 else if (rs == rd)
29210 {
29211 if (value & ~0xff)
29212 as_bad_where (fixP->fx_file, fixP->fx_line,
29213 _("immediate value out of range"));
29214 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29215 newval |= (rd << 8) | value;
29216 }
29217 else
29218 {
29219 if (value & ~0x7)
29220 as_bad_where (fixP->fx_file, fixP->fx_line,
29221 _("immediate value out of range"));
29222 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29223 newval |= rd | (rs << 3) | (value << 6);
29224 }
29225 }
29226 md_number_to_chars (buf, newval, THUMB_SIZE);
29227 break;
a737bd4d 29228
c19d1205
ZW
29229 case BFD_RELOC_ARM_THUMB_IMM:
29230 newval = md_chars_to_number (buf, THUMB_SIZE);
29231 if (value < 0 || value > 255)
29232 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 29233 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
29234 (long) value);
29235 newval |= value;
29236 md_number_to_chars (buf, newval, THUMB_SIZE);
29237 break;
a737bd4d 29238
c19d1205
ZW
29239 case BFD_RELOC_ARM_THUMB_SHIFT:
29240 /* 5bit shift value (0..32). LSL cannot take 32. */
29241 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29242 temp = newval & 0xf800;
29243 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29244 as_bad_where (fixP->fx_file, fixP->fx_line,
29245 _("invalid shift value: %ld"), (long) value);
29246 /* Shifts of zero must be encoded as LSL. */
29247 if (value == 0)
29248 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29249 /* Shifts of 32 are encoded as zero. */
29250 else if (value == 32)
29251 value = 0;
29252 newval |= value << 6;
29253 md_number_to_chars (buf, newval, THUMB_SIZE);
29254 break;
a737bd4d 29255
c19d1205
ZW
29256 case BFD_RELOC_VTABLE_INHERIT:
29257 case BFD_RELOC_VTABLE_ENTRY:
29258 fixP->fx_done = 0;
29259 return;
6c43fab6 29260
b6895b4f
PB
29261 case BFD_RELOC_ARM_MOVW:
29262 case BFD_RELOC_ARM_MOVT:
29263 case BFD_RELOC_ARM_THUMB_MOVW:
29264 case BFD_RELOC_ARM_THUMB_MOVT:
29265 if (fixP->fx_done || !seg->use_rela_p)
29266 {
29267 /* REL format relocations are limited to a 16-bit addend. */
29268 if (!fixP->fx_done)
29269 {
39623e12 29270 if (value < -0x8000 || value > 0x7fff)
b6895b4f 29271 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 29272 _("offset out of range"));
b6895b4f
PB
29273 }
29274 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29275 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29276 {
29277 value >>= 16;
29278 }
29279
29280 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29281 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29282 {
29283 newval = get_thumb32_insn (buf);
29284 newval &= 0xfbf08f00;
29285 newval |= (value & 0xf000) << 4;
29286 newval |= (value & 0x0800) << 15;
29287 newval |= (value & 0x0700) << 4;
29288 newval |= (value & 0x00ff);
29289 put_thumb32_insn (buf, newval);
29290 }
29291 else
29292 {
29293 newval = md_chars_to_number (buf, 4);
29294 newval &= 0xfff0f000;
29295 newval |= value & 0x0fff;
29296 newval |= (value & 0xf000) << 4;
29297 md_number_to_chars (buf, newval, 4);
29298 }
29299 }
29300 return;
29301
72d98d16
MG
29302 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29303 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29304 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29305 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29306 gas_assert (!fixP->fx_done);
29307 {
29308 bfd_vma insn;
29309 bfd_boolean is_mov;
29310 bfd_vma encoded_addend = value;
29311
29312 /* Check that addend can be encoded in instruction. */
29313 if (!seg->use_rela_p && (value < 0 || value > 255))
29314 as_bad_where (fixP->fx_file, fixP->fx_line,
29315 _("the offset 0x%08lX is not representable"),
29316 (unsigned long) encoded_addend);
29317
29318 /* Extract the instruction. */
29319 insn = md_chars_to_number (buf, THUMB_SIZE);
29320 is_mov = (insn & 0xf800) == 0x2000;
29321
29322 /* Encode insn. */
29323 if (is_mov)
29324 {
29325 if (!seg->use_rela_p)
29326 insn |= encoded_addend;
29327 }
29328 else
29329 {
29330 int rd, rs;
29331
29332 /* Extract the instruction. */
29333 /* Encoding is the following
29334 0x8000 SUB
29335 0x00F0 Rd
29336 0x000F Rs
29337 */
29338 /* The following conditions must be true :
29339 - ADD
29340 - Rd == Rs
29341 - Rd <= 7
29342 */
29343 rd = (insn >> 4) & 0xf;
29344 rs = insn & 0xf;
29345 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29346 as_bad_where (fixP->fx_file, fixP->fx_line,
29347 _("Unable to process relocation for thumb opcode: %lx"),
29348 (unsigned long) insn);
29349
29350 /* Encode as ADD immediate8 thumb 1 code. */
29351 insn = 0x3000 | (rd << 8);
29352
29353 /* Place the encoded addend into the first 8 bits of the
29354 instruction. */
29355 if (!seg->use_rela_p)
29356 insn |= encoded_addend;
29357 }
29358
29359 /* Update the instruction. */
29360 md_number_to_chars (buf, insn, THUMB_SIZE);
29361 }
29362 break;
29363
4962c51a
MS
29364 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29365 case BFD_RELOC_ARM_ALU_PC_G0:
29366 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29367 case BFD_RELOC_ARM_ALU_PC_G1:
29368 case BFD_RELOC_ARM_ALU_PC_G2:
29369 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29370 case BFD_RELOC_ARM_ALU_SB_G0:
29371 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29372 case BFD_RELOC_ARM_ALU_SB_G1:
29373 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 29374 gas_assert (!fixP->fx_done);
4962c51a
MS
29375 if (!seg->use_rela_p)
29376 {
477330fc
RM
29377 bfd_vma insn;
29378 bfd_vma encoded_addend;
3ca4a8ec 29379 bfd_vma addend_abs = llabs (value);
477330fc
RM
29380
29381 /* Check that the absolute value of the addend can be
29382 expressed as an 8-bit constant plus a rotation. */
29383 encoded_addend = encode_arm_immediate (addend_abs);
29384 if (encoded_addend == (unsigned int) FAIL)
4962c51a 29385 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29386 _("the offset 0x%08lX is not representable"),
29387 (unsigned long) addend_abs);
29388
29389 /* Extract the instruction. */
29390 insn = md_chars_to_number (buf, INSN_SIZE);
29391
29392 /* If the addend is positive, use an ADD instruction.
29393 Otherwise use a SUB. Take care not to destroy the S bit. */
29394 insn &= 0xff1fffff;
29395 if (value < 0)
29396 insn |= 1 << 22;
29397 else
29398 insn |= 1 << 23;
29399
29400 /* Place the encoded addend into the first 12 bits of the
29401 instruction. */
29402 insn &= 0xfffff000;
29403 insn |= encoded_addend;
29404
29405 /* Update the instruction. */
29406 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
29407 }
29408 break;
29409
29410 case BFD_RELOC_ARM_LDR_PC_G0:
29411 case BFD_RELOC_ARM_LDR_PC_G1:
29412 case BFD_RELOC_ARM_LDR_PC_G2:
29413 case BFD_RELOC_ARM_LDR_SB_G0:
29414 case BFD_RELOC_ARM_LDR_SB_G1:
29415 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 29416 gas_assert (!fixP->fx_done);
4962c51a 29417 if (!seg->use_rela_p)
477330fc
RM
29418 {
29419 bfd_vma insn;
3ca4a8ec 29420 bfd_vma addend_abs = llabs (value);
4962c51a 29421
477330fc
RM
29422 /* Check that the absolute value of the addend can be
29423 encoded in 12 bits. */
29424 if (addend_abs >= 0x1000)
4962c51a 29425 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29426 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29427 (unsigned long) addend_abs);
29428
29429 /* Extract the instruction. */
29430 insn = md_chars_to_number (buf, INSN_SIZE);
29431
29432 /* If the addend is negative, clear bit 23 of the instruction.
29433 Otherwise set it. */
29434 if (value < 0)
29435 insn &= ~(1 << 23);
29436 else
29437 insn |= 1 << 23;
29438
29439 /* Place the absolute value of the addend into the first 12 bits
29440 of the instruction. */
29441 insn &= 0xfffff000;
29442 insn |= addend_abs;
29443
29444 /* Update the instruction. */
29445 md_number_to_chars (buf, insn, INSN_SIZE);
29446 }
4962c51a
MS
29447 break;
29448
29449 case BFD_RELOC_ARM_LDRS_PC_G0:
29450 case BFD_RELOC_ARM_LDRS_PC_G1:
29451 case BFD_RELOC_ARM_LDRS_PC_G2:
29452 case BFD_RELOC_ARM_LDRS_SB_G0:
29453 case BFD_RELOC_ARM_LDRS_SB_G1:
29454 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 29455 gas_assert (!fixP->fx_done);
4962c51a 29456 if (!seg->use_rela_p)
477330fc
RM
29457 {
29458 bfd_vma insn;
3ca4a8ec 29459 bfd_vma addend_abs = llabs (value);
4962c51a 29460
477330fc
RM
29461 /* Check that the absolute value of the addend can be
29462 encoded in 8 bits. */
29463 if (addend_abs >= 0x100)
4962c51a 29464 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29465 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29466 (unsigned long) addend_abs);
29467
29468 /* Extract the instruction. */
29469 insn = md_chars_to_number (buf, INSN_SIZE);
29470
29471 /* If the addend is negative, clear bit 23 of the instruction.
29472 Otherwise set it. */
29473 if (value < 0)
29474 insn &= ~(1 << 23);
29475 else
29476 insn |= 1 << 23;
29477
29478 /* Place the first four bits of the absolute value of the addend
29479 into the first 4 bits of the instruction, and the remaining
29480 four into bits 8 .. 11. */
29481 insn &= 0xfffff0f0;
29482 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29483
29484 /* Update the instruction. */
29485 md_number_to_chars (buf, insn, INSN_SIZE);
29486 }
4962c51a
MS
29487 break;
29488
29489 case BFD_RELOC_ARM_LDC_PC_G0:
29490 case BFD_RELOC_ARM_LDC_PC_G1:
29491 case BFD_RELOC_ARM_LDC_PC_G2:
29492 case BFD_RELOC_ARM_LDC_SB_G0:
29493 case BFD_RELOC_ARM_LDC_SB_G1:
29494 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 29495 gas_assert (!fixP->fx_done);
4962c51a 29496 if (!seg->use_rela_p)
477330fc
RM
29497 {
29498 bfd_vma insn;
3ca4a8ec 29499 bfd_vma addend_abs = llabs (value);
4962c51a 29500
477330fc
RM
29501 /* Check that the absolute value of the addend is a multiple of
29502 four and, when divided by four, fits in 8 bits. */
29503 if (addend_abs & 0x3)
4962c51a 29504 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29505 _("bad offset 0x%08lX (must be word-aligned)"),
29506 (unsigned long) addend_abs);
4962c51a 29507
477330fc 29508 if ((addend_abs >> 2) > 0xff)
4962c51a 29509 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29510 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29511 (unsigned long) addend_abs);
29512
29513 /* Extract the instruction. */
29514 insn = md_chars_to_number (buf, INSN_SIZE);
29515
29516 /* If the addend is negative, clear bit 23 of the instruction.
29517 Otherwise set it. */
29518 if (value < 0)
29519 insn &= ~(1 << 23);
29520 else
29521 insn |= 1 << 23;
29522
29523 /* Place the addend (divided by four) into the first eight
29524 bits of the instruction. */
29525 insn &= 0xfffffff0;
29526 insn |= addend_abs >> 2;
29527
29528 /* Update the instruction. */
29529 md_number_to_chars (buf, insn, INSN_SIZE);
29530 }
4962c51a
MS
29531 break;
29532
e12437dc
AV
29533 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29534 if (fixP->fx_addsy
29535 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29536 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29537 && ARM_IS_FUNC (fixP->fx_addsy)
29538 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29539 {
29540 /* Force a relocation for a branch 5 bits wide. */
29541 fixP->fx_done = 0;
29542 }
29543 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29544 as_bad_where (fixP->fx_file, fixP->fx_line,
29545 BAD_BRANCH_OFF);
29546
29547 if (fixP->fx_done || !seg->use_rela_p)
29548 {
29549 addressT boff = value >> 1;
29550
29551 newval = md_chars_to_number (buf, THUMB_SIZE);
29552 newval |= (boff << 7);
29553 md_number_to_chars (buf, newval, THUMB_SIZE);
29554 }
29555 break;
29556
f6b2b12d
AV
29557 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29558 if (fixP->fx_addsy
29559 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29560 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29561 && ARM_IS_FUNC (fixP->fx_addsy)
29562 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29563 {
29564 fixP->fx_done = 0;
29565 }
29566 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
29567 as_bad_where (fixP->fx_file, fixP->fx_line,
29568 _("branch out of range"));
29569
29570 if (fixP->fx_done || !seg->use_rela_p)
29571 {
29572 newval = md_chars_to_number (buf, THUMB_SIZE);
29573
29574 addressT boff = ((newval & 0x0780) >> 7) << 1;
29575 addressT diff = value - boff;
29576
29577 if (diff == 4)
29578 {
29579 newval |= 1 << 1; /* T bit. */
29580 }
29581 else if (diff != 2)
29582 {
29583 as_bad_where (fixP->fx_file, fixP->fx_line,
29584 _("out of range label-relative fixup value"));
29585 }
29586 md_number_to_chars (buf, newval, THUMB_SIZE);
29587 }
29588 break;
29589
e5d6e09e
AV
29590 case BFD_RELOC_ARM_THUMB_BF17:
29591 if (fixP->fx_addsy
29592 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29593 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29594 && ARM_IS_FUNC (fixP->fx_addsy)
29595 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29596 {
29597 /* Force a relocation for a branch 17 bits wide. */
29598 fixP->fx_done = 0;
29599 }
29600
29601 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29602 as_bad_where (fixP->fx_file, fixP->fx_line,
29603 BAD_BRANCH_OFF);
29604
29605 if (fixP->fx_done || !seg->use_rela_p)
29606 {
29607 offsetT newval2;
29608 addressT immA, immB, immC;
29609
29610 immA = (value & 0x0001f000) >> 12;
29611 immB = (value & 0x00000ffc) >> 2;
29612 immC = (value & 0x00000002) >> 1;
29613
29614 newval = md_chars_to_number (buf, THUMB_SIZE);
29615 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29616 newval |= immA;
29617 newval2 |= (immC << 11) | (immB << 1);
29618 md_number_to_chars (buf, newval, THUMB_SIZE);
29619 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29620 }
29621 break;
29622
1caf72a5
AV
29623 case BFD_RELOC_ARM_THUMB_BF19:
29624 if (fixP->fx_addsy
29625 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29626 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29627 && ARM_IS_FUNC (fixP->fx_addsy)
29628 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29629 {
29630 /* Force a relocation for a branch 19 bits wide. */
29631 fixP->fx_done = 0;
29632 }
29633
29634 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29635 as_bad_where (fixP->fx_file, fixP->fx_line,
29636 BAD_BRANCH_OFF);
29637
29638 if (fixP->fx_done || !seg->use_rela_p)
29639 {
29640 offsetT newval2;
29641 addressT immA, immB, immC;
29642
29643 immA = (value & 0x0007f000) >> 12;
29644 immB = (value & 0x00000ffc) >> 2;
29645 immC = (value & 0x00000002) >> 1;
29646
29647 newval = md_chars_to_number (buf, THUMB_SIZE);
29648 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29649 newval |= immA;
29650 newval2 |= (immC << 11) | (immB << 1);
29651 md_number_to_chars (buf, newval, THUMB_SIZE);
29652 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29653 }
29654 break;
29655
1889da70
AV
29656 case BFD_RELOC_ARM_THUMB_BF13:
29657 if (fixP->fx_addsy
29658 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29659 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29660 && ARM_IS_FUNC (fixP->fx_addsy)
29661 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29662 {
29663 /* Force a relocation for a branch 13 bits wide. */
29664 fixP->fx_done = 0;
29665 }
29666
29667 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29668 as_bad_where (fixP->fx_file, fixP->fx_line,
29669 BAD_BRANCH_OFF);
29670
29671 if (fixP->fx_done || !seg->use_rela_p)
29672 {
29673 offsetT newval2;
29674 addressT immA, immB, immC;
29675
29676 immA = (value & 0x00001000) >> 12;
29677 immB = (value & 0x00000ffc) >> 2;
29678 immC = (value & 0x00000002) >> 1;
29679
29680 newval = md_chars_to_number (buf, THUMB_SIZE);
29681 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29682 newval |= immA;
29683 newval2 |= (immC << 11) | (immB << 1);
29684 md_number_to_chars (buf, newval, THUMB_SIZE);
29685 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29686 }
29687 break;
29688
60f993ce
AV
29689 case BFD_RELOC_ARM_THUMB_LOOP12:
29690 if (fixP->fx_addsy
29691 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29692 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29693 && ARM_IS_FUNC (fixP->fx_addsy)
29694 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29695 {
29696 /* Force a relocation for a branch 12 bits wide. */
29697 fixP->fx_done = 0;
29698 }
29699
29700 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 29701 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 29702 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
29703 || ((insn & 0xffffffff) == 0xf02fc001)
29704 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
29705 value = -value;
29706
29707 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29708 as_bad_where (fixP->fx_file, fixP->fx_line,
29709 BAD_BRANCH_OFF);
29710 if (fixP->fx_done || !seg->use_rela_p)
29711 {
29712 addressT imml, immh;
29713
29714 immh = (value & 0x00000ffc) >> 2;
29715 imml = (value & 0x00000002) >> 1;
29716
29717 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29718 newval |= (imml << 11) | (immh << 1);
29719 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29720 }
29721 break;
29722
845b51d6
PB
29723 case BFD_RELOC_ARM_V4BX:
29724 /* This will need to go in the object file. */
29725 fixP->fx_done = 0;
29726 break;
29727
c19d1205
ZW
29728 case BFD_RELOC_UNUSED:
29729 default:
29730 as_bad_where (fixP->fx_file, fixP->fx_line,
29731 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29732 }
6c43fab6
RE
29733}
29734
c19d1205
ZW
29735/* Translate internal representation of relocation info to BFD target
29736 format. */
a737bd4d 29737
c19d1205 29738arelent *
00a97672 29739tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29740{
c19d1205
ZW
29741 arelent * reloc;
29742 bfd_reloc_code_real_type code;
a737bd4d 29743
325801bd 29744 reloc = XNEW (arelent);
a737bd4d 29745
325801bd 29746 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
29747 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29748 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 29749
2fc8bdac 29750 if (fixp->fx_pcrel)
00a97672
RS
29751 {
29752 if (section->use_rela_p)
29753 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29754 else
29755 fixp->fx_offset = reloc->address;
29756 }
c19d1205 29757 reloc->addend = fixp->fx_offset;
a737bd4d 29758
c19d1205 29759 switch (fixp->fx_r_type)
a737bd4d 29760 {
c19d1205
ZW
29761 case BFD_RELOC_8:
29762 if (fixp->fx_pcrel)
29763 {
29764 code = BFD_RELOC_8_PCREL;
29765 break;
29766 }
1a0670f3 29767 /* Fall through. */
a737bd4d 29768
c19d1205
ZW
29769 case BFD_RELOC_16:
29770 if (fixp->fx_pcrel)
29771 {
29772 code = BFD_RELOC_16_PCREL;
29773 break;
29774 }
1a0670f3 29775 /* Fall through. */
6c43fab6 29776
c19d1205
ZW
29777 case BFD_RELOC_32:
29778 if (fixp->fx_pcrel)
29779 {
29780 code = BFD_RELOC_32_PCREL;
29781 break;
29782 }
1a0670f3 29783 /* Fall through. */
a737bd4d 29784
b6895b4f
PB
29785 case BFD_RELOC_ARM_MOVW:
29786 if (fixp->fx_pcrel)
29787 {
29788 code = BFD_RELOC_ARM_MOVW_PCREL;
29789 break;
29790 }
1a0670f3 29791 /* Fall through. */
b6895b4f
PB
29792
29793 case BFD_RELOC_ARM_MOVT:
29794 if (fixp->fx_pcrel)
29795 {
29796 code = BFD_RELOC_ARM_MOVT_PCREL;
29797 break;
29798 }
1a0670f3 29799 /* Fall through. */
b6895b4f
PB
29800
29801 case BFD_RELOC_ARM_THUMB_MOVW:
29802 if (fixp->fx_pcrel)
29803 {
29804 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
29805 break;
29806 }
1a0670f3 29807 /* Fall through. */
b6895b4f
PB
29808
29809 case BFD_RELOC_ARM_THUMB_MOVT:
29810 if (fixp->fx_pcrel)
29811 {
29812 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
29813 break;
29814 }
1a0670f3 29815 /* Fall through. */
b6895b4f 29816
c19d1205
ZW
29817 case BFD_RELOC_NONE:
29818 case BFD_RELOC_ARM_PCREL_BRANCH:
29819 case BFD_RELOC_ARM_PCREL_BLX:
29820 case BFD_RELOC_RVA:
29821 case BFD_RELOC_THUMB_PCREL_BRANCH7:
29822 case BFD_RELOC_THUMB_PCREL_BRANCH9:
29823 case BFD_RELOC_THUMB_PCREL_BRANCH12:
29824 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29825 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29826 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
29827 case BFD_RELOC_VTABLE_ENTRY:
29828 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
29829#ifdef TE_PE
29830 case BFD_RELOC_32_SECREL:
29831#endif
c19d1205
ZW
29832 code = fixp->fx_r_type;
29833 break;
a737bd4d 29834
00adf2d4
JB
29835 case BFD_RELOC_THUMB_PCREL_BLX:
29836#ifdef OBJ_ELF
29837 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
29838 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
29839 else
29840#endif
29841 code = BFD_RELOC_THUMB_PCREL_BLX;
29842 break;
29843
c19d1205
ZW
29844 case BFD_RELOC_ARM_LITERAL:
29845 case BFD_RELOC_ARM_HWLITERAL:
29846 /* If this is called then the a literal has
29847 been referenced across a section boundary. */
29848 as_bad_where (fixp->fx_file, fixp->fx_line,
29849 _("literal referenced across section boundary"));
29850 return NULL;
a737bd4d 29851
c19d1205 29852#ifdef OBJ_ELF
0855e32b
NS
29853 case BFD_RELOC_ARM_TLS_CALL:
29854 case BFD_RELOC_ARM_THM_TLS_CALL:
29855 case BFD_RELOC_ARM_TLS_DESCSEQ:
29856 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
29857 case BFD_RELOC_ARM_GOT32:
29858 case BFD_RELOC_ARM_GOTOFF:
b43420e6 29859 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
29860 case BFD_RELOC_ARM_PLT32:
29861 case BFD_RELOC_ARM_TARGET1:
29862 case BFD_RELOC_ARM_ROSEGREL32:
29863 case BFD_RELOC_ARM_SBREL32:
29864 case BFD_RELOC_ARM_PREL31:
29865 case BFD_RELOC_ARM_TARGET2:
c19d1205 29866 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
29867 case BFD_RELOC_ARM_PCREL_CALL:
29868 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
29869 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29870 case BFD_RELOC_ARM_ALU_PC_G0:
29871 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29872 case BFD_RELOC_ARM_ALU_PC_G1:
29873 case BFD_RELOC_ARM_ALU_PC_G2:
29874 case BFD_RELOC_ARM_LDR_PC_G0:
29875 case BFD_RELOC_ARM_LDR_PC_G1:
29876 case BFD_RELOC_ARM_LDR_PC_G2:
29877 case BFD_RELOC_ARM_LDRS_PC_G0:
29878 case BFD_RELOC_ARM_LDRS_PC_G1:
29879 case BFD_RELOC_ARM_LDRS_PC_G2:
29880 case BFD_RELOC_ARM_LDC_PC_G0:
29881 case BFD_RELOC_ARM_LDC_PC_G1:
29882 case BFD_RELOC_ARM_LDC_PC_G2:
29883 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29884 case BFD_RELOC_ARM_ALU_SB_G0:
29885 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29886 case BFD_RELOC_ARM_ALU_SB_G1:
29887 case BFD_RELOC_ARM_ALU_SB_G2:
29888 case BFD_RELOC_ARM_LDR_SB_G0:
29889 case BFD_RELOC_ARM_LDR_SB_G1:
29890 case BFD_RELOC_ARM_LDR_SB_G2:
29891 case BFD_RELOC_ARM_LDRS_SB_G0:
29892 case BFD_RELOC_ARM_LDRS_SB_G1:
29893 case BFD_RELOC_ARM_LDRS_SB_G2:
29894 case BFD_RELOC_ARM_LDC_SB_G0:
29895 case BFD_RELOC_ARM_LDC_SB_G1:
29896 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 29897 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
29898 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29899 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29900 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29901 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
29902 case BFD_RELOC_ARM_GOTFUNCDESC:
29903 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29904 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 29905 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 29906 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 29907 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
29908 code = fixp->fx_r_type;
29909 break;
a737bd4d 29910
0855e32b 29911 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 29912 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 29913 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 29914 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 29915 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 29916 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 29917 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 29918 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
29919 /* BFD will include the symbol's address in the addend.
29920 But we don't want that, so subtract it out again here. */
29921 if (!S_IS_COMMON (fixp->fx_addsy))
29922 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
29923 code = fixp->fx_r_type;
29924 break;
29925#endif
a737bd4d 29926
c19d1205
ZW
29927 case BFD_RELOC_ARM_IMMEDIATE:
29928 as_bad_where (fixp->fx_file, fixp->fx_line,
29929 _("internal relocation (type: IMMEDIATE) not fixed up"));
29930 return NULL;
a737bd4d 29931
c19d1205
ZW
29932 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
29933 as_bad_where (fixp->fx_file, fixp->fx_line,
29934 _("ADRL used for a symbol not defined in the same file"));
29935 return NULL;
a737bd4d 29936
e12437dc 29937 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 29938 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 29939 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
29940 as_bad_where (fixp->fx_file, fixp->fx_line,
29941 _("%s used for a symbol not defined in the same file"),
29942 bfd_get_reloc_code_name (fixp->fx_r_type));
29943 return NULL;
29944
c19d1205 29945 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
29946 if (section->use_rela_p)
29947 {
29948 code = fixp->fx_r_type;
29949 break;
29950 }
29951
c19d1205
ZW
29952 if (fixp->fx_addsy != NULL
29953 && !S_IS_DEFINED (fixp->fx_addsy)
29954 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 29955 {
c19d1205
ZW
29956 as_bad_where (fixp->fx_file, fixp->fx_line,
29957 _("undefined local label `%s'"),
29958 S_GET_NAME (fixp->fx_addsy));
29959 return NULL;
a737bd4d
NC
29960 }
29961
c19d1205
ZW
29962 as_bad_where (fixp->fx_file, fixp->fx_line,
29963 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
29964 return NULL;
a737bd4d 29965
c19d1205
ZW
29966 default:
29967 {
e0471c16 29968 const char * type;
6c43fab6 29969
c19d1205
ZW
29970 switch (fixp->fx_r_type)
29971 {
29972 case BFD_RELOC_NONE: type = "NONE"; break;
29973 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
29974 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 29975 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
29976 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
29977 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
29978 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 29979 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 29980 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
29981 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
29982 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
29983 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
29984 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
29985 default: type = _("<unknown>"); break;
29986 }
29987 as_bad_where (fixp->fx_file, fixp->fx_line,
29988 _("cannot represent %s relocation in this object file format"),
29989 type);
29990 return NULL;
29991 }
a737bd4d 29992 }
6c43fab6 29993
c19d1205
ZW
29994#ifdef OBJ_ELF
29995 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
29996 && GOT_symbol
29997 && fixp->fx_addsy == GOT_symbol)
29998 {
29999 code = BFD_RELOC_ARM_GOTPC;
30000 reloc->addend = fixp->fx_offset = reloc->address;
30001 }
30002#endif
6c43fab6 30003
c19d1205 30004 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 30005
c19d1205
ZW
30006 if (reloc->howto == NULL)
30007 {
30008 as_bad_where (fixp->fx_file, fixp->fx_line,
30009 _("cannot represent %s relocation in this object file format"),
30010 bfd_get_reloc_code_name (code));
30011 return NULL;
30012 }
6c43fab6 30013
c19d1205
ZW
30014 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30015 vtable entry to be used in the relocation's section offset. */
30016 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30017 reloc->address = fixp->fx_offset;
6c43fab6 30018
c19d1205 30019 return reloc;
6c43fab6
RE
30020}
30021
c19d1205 30022/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 30023
c19d1205
ZW
30024void
30025cons_fix_new_arm (fragS * frag,
30026 int where,
30027 int size,
62ebcb5c
AM
30028 expressionS * exp,
30029 bfd_reloc_code_real_type reloc)
6c43fab6 30030{
c19d1205 30031 int pcrel = 0;
6c43fab6 30032
c19d1205
ZW
30033 /* Pick a reloc.
30034 FIXME: @@ Should look at CPU word size. */
30035 switch (size)
30036 {
30037 case 1:
62ebcb5c 30038 reloc = BFD_RELOC_8;
c19d1205
ZW
30039 break;
30040 case 2:
62ebcb5c 30041 reloc = BFD_RELOC_16;
c19d1205
ZW
30042 break;
30043 case 4:
30044 default:
62ebcb5c 30045 reloc = BFD_RELOC_32;
c19d1205
ZW
30046 break;
30047 case 8:
62ebcb5c 30048 reloc = BFD_RELOC_64;
c19d1205
ZW
30049 break;
30050 }
6c43fab6 30051
f0927246
NC
30052#ifdef TE_PE
30053 if (exp->X_op == O_secrel)
30054 {
30055 exp->X_op = O_symbol;
62ebcb5c 30056 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
30057 }
30058#endif
30059
62ebcb5c 30060 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 30061}
6c43fab6 30062
4343666d 30063#if defined (OBJ_COFF)
c19d1205
ZW
30064void
30065arm_validate_fix (fixS * fixP)
6c43fab6 30066{
c19d1205
ZW
30067 /* If the destination of the branch is a defined symbol which does not have
30068 the THUMB_FUNC attribute, then we must be calling a function which has
30069 the (interfacearm) attribute. We look for the Thumb entry point to that
30070 function and change the branch to refer to that function instead. */
30071 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30072 && fixP->fx_addsy != NULL
30073 && S_IS_DEFINED (fixP->fx_addsy)
30074 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 30075 {
c19d1205 30076 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 30077 }
c19d1205
ZW
30078}
30079#endif
6c43fab6 30080
267bf995 30081
c19d1205
ZW
30082int
30083arm_force_relocation (struct fix * fixp)
30084{
30085#if defined (OBJ_COFF) && defined (TE_PE)
30086 if (fixp->fx_r_type == BFD_RELOC_RVA)
30087 return 1;
30088#endif
6c43fab6 30089
267bf995
RR
30090 /* In case we have a call or a branch to a function in ARM ISA mode from
30091 a thumb function or vice-versa force the relocation. These relocations
30092 are cleared off for some cores that might have blx and simple transformations
30093 are possible. */
30094
30095#ifdef OBJ_ELF
30096 switch (fixp->fx_r_type)
30097 {
30098 case BFD_RELOC_ARM_PCREL_JUMP:
30099 case BFD_RELOC_ARM_PCREL_CALL:
30100 case BFD_RELOC_THUMB_PCREL_BLX:
30101 if (THUMB_IS_FUNC (fixp->fx_addsy))
30102 return 1;
30103 break;
30104
30105 case BFD_RELOC_ARM_PCREL_BLX:
30106 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30107 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30108 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30109 if (ARM_IS_FUNC (fixp->fx_addsy))
30110 return 1;
30111 break;
30112
30113 default:
30114 break;
30115 }
30116#endif
30117
b5884301
PB
30118 /* Resolve these relocations even if the symbol is extern or weak.
30119 Technically this is probably wrong due to symbol preemption.
30120 In practice these relocations do not have enough range to be useful
30121 at dynamic link time, and some code (e.g. in the Linux kernel)
30122 expects these references to be resolved. */
c19d1205
ZW
30123 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30124 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 30125 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 30126 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
30127 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30128 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30129 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 30130 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
30131 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30132 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
30133 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30134 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30135 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30136 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 30137 return 0;
a737bd4d 30138
4962c51a
MS
30139 /* Always leave these relocations for the linker. */
30140 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30141 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30142 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30143 return 1;
30144
f0291e4c
PB
30145 /* Always generate relocations against function symbols. */
30146 if (fixp->fx_r_type == BFD_RELOC_32
30147 && fixp->fx_addsy
30148 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30149 return 1;
30150
c19d1205 30151 return generic_force_reloc (fixp);
404ff6b5
AH
30152}
30153
0ffdc86c 30154#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
30155/* Relocations against function names must be left unadjusted,
30156 so that the linker can use this information to generate interworking
30157 stubs. The MIPS version of this function
c19d1205
ZW
30158 also prevents relocations that are mips-16 specific, but I do not
30159 know why it does this.
404ff6b5 30160
c19d1205
ZW
30161 FIXME:
30162 There is one other problem that ought to be addressed here, but
30163 which currently is not: Taking the address of a label (rather
30164 than a function) and then later jumping to that address. Such
30165 addresses also ought to have their bottom bit set (assuming that
30166 they reside in Thumb code), but at the moment they will not. */
404ff6b5 30167
c19d1205
ZW
30168bfd_boolean
30169arm_fix_adjustable (fixS * fixP)
404ff6b5 30170{
c19d1205
ZW
30171 if (fixP->fx_addsy == NULL)
30172 return 1;
404ff6b5 30173
e28387c3
PB
30174 /* Preserve relocations against symbols with function type. */
30175 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 30176 return FALSE;
e28387c3 30177
c19d1205
ZW
30178 if (THUMB_IS_FUNC (fixP->fx_addsy)
30179 && fixP->fx_subsy == NULL)
c921be7d 30180 return FALSE;
a737bd4d 30181
c19d1205
ZW
30182 /* We need the symbol name for the VTABLE entries. */
30183 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30184 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 30185 return FALSE;
404ff6b5 30186
c19d1205
ZW
30187 /* Don't allow symbols to be discarded on GOT related relocs. */
30188 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30189 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30190 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30191 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 30192 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
30193 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30194 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 30195 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 30196 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 30197 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 30198 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
30199 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30200 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30201 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30202 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30203 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 30204 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 30205 return FALSE;
a737bd4d 30206
4962c51a
MS
30207 /* Similarly for group relocations. */
30208 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30209 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30210 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 30211 return FALSE;
4962c51a 30212
79947c54
CD
30213 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30214 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30215 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30216 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30217 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30218 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30219 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30220 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30221 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 30222 return FALSE;
79947c54 30223
72d98d16
MG
30224 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30225 offsets, so keep these symbols. */
30226 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30227 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30228 return FALSE;
30229
c921be7d 30230 return TRUE;
a737bd4d 30231}
0ffdc86c
NC
30232#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30233
30234#ifdef OBJ_ELF
c19d1205
ZW
30235const char *
30236elf32_arm_target_format (void)
404ff6b5 30237{
c19d1205
ZW
30238#ifdef TE_SYMBIAN
30239 return (target_big_endian
30240 ? "elf32-bigarm-symbian"
30241 : "elf32-littlearm-symbian");
30242#elif defined (TE_VXWORKS)
30243 return (target_big_endian
30244 ? "elf32-bigarm-vxworks"
30245 : "elf32-littlearm-vxworks");
b38cadfb
NC
30246#elif defined (TE_NACL)
30247 return (target_big_endian
30248 ? "elf32-bigarm-nacl"
30249 : "elf32-littlearm-nacl");
c19d1205 30250#else
18a20338
CL
30251 if (arm_fdpic)
30252 {
30253 if (target_big_endian)
30254 return "elf32-bigarm-fdpic";
30255 else
30256 return "elf32-littlearm-fdpic";
30257 }
c19d1205 30258 else
18a20338
CL
30259 {
30260 if (target_big_endian)
30261 return "elf32-bigarm";
30262 else
30263 return "elf32-littlearm";
30264 }
c19d1205 30265#endif
404ff6b5
AH
30266}
30267
c19d1205
ZW
30268void
30269armelf_frob_symbol (symbolS * symp,
30270 int * puntp)
404ff6b5 30271{
c19d1205
ZW
30272 elf_frob_symbol (symp, puntp);
30273}
30274#endif
404ff6b5 30275
c19d1205 30276/* MD interface: Finalization. */
a737bd4d 30277
c19d1205
ZW
30278void
30279arm_cleanup (void)
30280{
30281 literal_pool * pool;
a737bd4d 30282
5ee91343
AV
30283 /* Ensure that all the predication blocks are properly closed. */
30284 check_pred_blocks_finished ();
e07e6e58 30285
c19d1205
ZW
30286 for (pool = list_of_pools; pool; pool = pool->next)
30287 {
5f4273c7 30288 /* Put it at the end of the relevant section. */
c19d1205
ZW
30289 subseg_set (pool->section, pool->sub_section);
30290#ifdef OBJ_ELF
30291 arm_elf_change_section ();
30292#endif
30293 s_ltorg (0);
30294 }
404ff6b5
AH
30295}
30296
cd000bff
DJ
30297#ifdef OBJ_ELF
30298/* Remove any excess mapping symbols generated for alignment frags in
30299 SEC. We may have created a mapping symbol before a zero byte
30300 alignment; remove it if there's a mapping symbol after the
30301 alignment. */
30302static void
30303check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30304 void *dummy ATTRIBUTE_UNUSED)
30305{
30306 segment_info_type *seginfo = seg_info (sec);
30307 fragS *fragp;
30308
30309 if (seginfo == NULL || seginfo->frchainP == NULL)
30310 return;
30311
30312 for (fragp = seginfo->frchainP->frch_root;
30313 fragp != NULL;
30314 fragp = fragp->fr_next)
30315 {
30316 symbolS *sym = fragp->tc_frag_data.last_map;
30317 fragS *next = fragp->fr_next;
30318
30319 /* Variable-sized frags have been converted to fixed size by
30320 this point. But if this was variable-sized to start with,
30321 there will be a fixed-size frag after it. So don't handle
30322 next == NULL. */
30323 if (sym == NULL || next == NULL)
30324 continue;
30325
30326 if (S_GET_VALUE (sym) < next->fr_address)
30327 /* Not at the end of this frag. */
30328 continue;
30329 know (S_GET_VALUE (sym) == next->fr_address);
30330
30331 do
30332 {
30333 if (next->tc_frag_data.first_map != NULL)
30334 {
30335 /* Next frag starts with a mapping symbol. Discard this
30336 one. */
30337 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30338 break;
30339 }
30340
30341 if (next->fr_next == NULL)
30342 {
30343 /* This mapping symbol is at the end of the section. Discard
30344 it. */
30345 know (next->fr_fix == 0 && next->fr_var == 0);
30346 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30347 break;
30348 }
30349
30350 /* As long as we have empty frags without any mapping symbols,
30351 keep looking. */
30352 /* If the next frag is non-empty and does not start with a
30353 mapping symbol, then this mapping symbol is required. */
30354 if (next->fr_address != next->fr_next->fr_address)
30355 break;
30356
30357 next = next->fr_next;
30358 }
30359 while (next != NULL);
30360 }
30361}
30362#endif
30363
c19d1205
ZW
30364/* Adjust the symbol table. This marks Thumb symbols as distinct from
30365 ARM ones. */
404ff6b5 30366
c19d1205
ZW
30367void
30368arm_adjust_symtab (void)
404ff6b5 30369{
c19d1205
ZW
30370#ifdef OBJ_COFF
30371 symbolS * sym;
404ff6b5 30372
c19d1205
ZW
30373 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30374 {
30375 if (ARM_IS_THUMB (sym))
30376 {
30377 if (THUMB_IS_FUNC (sym))
30378 {
30379 /* Mark the symbol as a Thumb function. */
30380 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30381 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30382 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 30383
c19d1205
ZW
30384 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30385 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30386 else
30387 as_bad (_("%s: unexpected function type: %d"),
30388 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30389 }
30390 else switch (S_GET_STORAGE_CLASS (sym))
30391 {
30392 case C_EXT:
30393 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30394 break;
30395 case C_STAT:
30396 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30397 break;
30398 case C_LABEL:
30399 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30400 break;
30401 default:
30402 /* Do nothing. */
30403 break;
30404 }
30405 }
a737bd4d 30406
c19d1205
ZW
30407 if (ARM_IS_INTERWORK (sym))
30408 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 30409 }
c19d1205
ZW
30410#endif
30411#ifdef OBJ_ELF
30412 symbolS * sym;
30413 char bind;
404ff6b5 30414
c19d1205 30415 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 30416 {
c19d1205
ZW
30417 if (ARM_IS_THUMB (sym))
30418 {
30419 elf_symbol_type * elf_sym;
404ff6b5 30420
c19d1205
ZW
30421 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30422 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 30423
b0796911
PB
30424 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30425 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
30426 {
30427 /* If it's a .thumb_func, declare it as so,
30428 otherwise tag label as .code 16. */
30429 if (THUMB_IS_FUNC (sym))
39d911fc
TP
30430 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30431 ST_BRANCH_TO_THUMB);
3ba67470 30432 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
30433 elf_sym->internal_elf_sym.st_info =
30434 ELF_ST_INFO (bind, STT_ARM_16BIT);
30435 }
30436 }
30437 }
cd000bff
DJ
30438
30439 /* Remove any overlapping mapping symbols generated by alignment frags. */
30440 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
30441 /* Now do generic ELF adjustments. */
30442 elf_adjust_symtab ();
c19d1205 30443#endif
404ff6b5
AH
30444}
30445
c19d1205 30446/* MD interface: Initialization. */
404ff6b5 30447
a737bd4d 30448static void
c19d1205 30449set_constant_flonums (void)
a737bd4d 30450{
c19d1205 30451 int i;
404ff6b5 30452
c19d1205
ZW
30453 for (i = 0; i < NUM_FLOAT_VALS; i++)
30454 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30455 abort ();
a737bd4d 30456}
404ff6b5 30457
3e9e4fcf
JB
30458/* Auto-select Thumb mode if it's the only available instruction set for the
30459 given architecture. */
30460
30461static void
30462autoselect_thumb_from_cpu_variant (void)
30463{
30464 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30465 opcode_select (16);
30466}
30467
c19d1205
ZW
30468void
30469md_begin (void)
a737bd4d 30470{
c19d1205
ZW
30471 unsigned mach;
30472 unsigned int i;
404ff6b5 30473
c19d1205
ZW
30474 if ( (arm_ops_hsh = hash_new ()) == NULL
30475 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 30476 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
30477 || (arm_shift_hsh = hash_new ()) == NULL
30478 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 30479 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 30480 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
30481 || (arm_reloc_hsh = hash_new ()) == NULL
30482 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
30483 as_fatal (_("virtual memory exhausted"));
30484
30485 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 30486 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 30487 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 30488 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
30489 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30490 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 30491 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 30492 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 30493 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30494 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 30495 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30496 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 30497 (void *) (v7m_psrs + i));
c19d1205 30498 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 30499 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
30500 for (i = 0;
30501 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30502 i++)
d3ce72d0 30503 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 30504 (void *) (barrier_opt_names + i));
c19d1205 30505#ifdef OBJ_ELF
3da1d841
NC
30506 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30507 {
30508 struct reloc_entry * entry = reloc_names + i;
30509
30510 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30511 /* This makes encode_branch() use the EABI versions of this relocation. */
30512 entry->reloc = BFD_RELOC_UNUSED;
30513
30514 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
30515 }
c19d1205
ZW
30516#endif
30517
30518 set_constant_flonums ();
404ff6b5 30519
c19d1205
ZW
30520 /* Set the cpu variant based on the command-line options. We prefer
30521 -mcpu= over -march= if both are set (as for GCC); and we prefer
30522 -mfpu= over any other way of setting the floating point unit.
30523 Use of legacy options with new options are faulted. */
e74cfd16 30524 if (legacy_cpu)
404ff6b5 30525 {
e74cfd16 30526 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
30527 as_bad (_("use of old and new-style options to set CPU type"));
30528
4d354d8b 30529 selected_arch = *legacy_cpu;
404ff6b5 30530 }
4d354d8b
TP
30531 else if (mcpu_cpu_opt)
30532 {
30533 selected_arch = *mcpu_cpu_opt;
30534 selected_ext = *mcpu_ext_opt;
30535 }
30536 else if (march_cpu_opt)
c168ce07 30537 {
4d354d8b
TP
30538 selected_arch = *march_cpu_opt;
30539 selected_ext = *march_ext_opt;
c168ce07 30540 }
4d354d8b 30541 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 30542
e74cfd16 30543 if (legacy_fpu)
c19d1205 30544 {
e74cfd16 30545 if (mfpu_opt)
c19d1205 30546 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 30547
4d354d8b 30548 selected_fpu = *legacy_fpu;
03b1477f 30549 }
4d354d8b
TP
30550 else if (mfpu_opt)
30551 selected_fpu = *mfpu_opt;
30552 else
03b1477f 30553 {
45eb4c1b
NS
30554#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30555 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
30556 /* Some environments specify a default FPU. If they don't, infer it
30557 from the processor. */
e74cfd16 30558 if (mcpu_fpu_opt)
4d354d8b 30559 selected_fpu = *mcpu_fpu_opt;
e7da50fa 30560 else if (march_fpu_opt)
4d354d8b 30561 selected_fpu = *march_fpu_opt;
39c2da32 30562#else
4d354d8b 30563 selected_fpu = fpu_default;
39c2da32 30564#endif
03b1477f
RE
30565 }
30566
4d354d8b 30567 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 30568 {
4d354d8b
TP
30569 if (!no_cpu_selected ())
30570 selected_fpu = fpu_default;
03b1477f 30571 else
4d354d8b 30572 selected_fpu = fpu_arch_fpa;
03b1477f
RE
30573 }
30574
ee065d83 30575#ifdef CPU_DEFAULT
4d354d8b 30576 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 30577 {
4d354d8b
TP
30578 selected_arch = cpu_default;
30579 selected_cpu = selected_arch;
ee065d83 30580 }
4d354d8b 30581 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 30582#else
4d354d8b
TP
30583 /* Autodection of feature mode: allow all features in cpu_variant but leave
30584 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30585 after all instruction have been processed and we can decide what CPU
30586 should be selected. */
30587 if (ARM_FEATURE_ZERO (selected_arch))
30588 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 30589 else
4d354d8b 30590 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 30591#endif
03b1477f 30592
3e9e4fcf
JB
30593 autoselect_thumb_from_cpu_variant ();
30594
e74cfd16 30595 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 30596
f17c130b 30597#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 30598 {
7cc69913
NC
30599 unsigned int flags = 0;
30600
30601#if defined OBJ_ELF
30602 flags = meabi_flags;
d507cf36
PB
30603
30604 switch (meabi_flags)
33a392fb 30605 {
d507cf36 30606 case EF_ARM_EABI_UNKNOWN:
7cc69913 30607#endif
d507cf36
PB
30608 /* Set the flags in the private structure. */
30609 if (uses_apcs_26) flags |= F_APCS26;
30610 if (support_interwork) flags |= F_INTERWORK;
30611 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 30612 if (pic_code) flags |= F_PIC;
e74cfd16 30613 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
30614 flags |= F_SOFT_FLOAT;
30615
d507cf36
PB
30616 switch (mfloat_abi_opt)
30617 {
30618 case ARM_FLOAT_ABI_SOFT:
30619 case ARM_FLOAT_ABI_SOFTFP:
30620 flags |= F_SOFT_FLOAT;
30621 break;
33a392fb 30622
d507cf36
PB
30623 case ARM_FLOAT_ABI_HARD:
30624 if (flags & F_SOFT_FLOAT)
30625 as_bad (_("hard-float conflicts with specified fpu"));
30626 break;
30627 }
03b1477f 30628
e74cfd16
PB
30629 /* Using pure-endian doubles (even if soft-float). */
30630 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 30631 flags |= F_VFP_FLOAT;
f17c130b 30632
fde78edd 30633#if defined OBJ_ELF
e74cfd16 30634 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 30635 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
30636 break;
30637
8cb51566 30638 case EF_ARM_EABI_VER4:
3a4a14e9 30639 case EF_ARM_EABI_VER5:
c19d1205 30640 /* No additional flags to set. */
d507cf36
PB
30641 break;
30642
30643 default:
30644 abort ();
30645 }
7cc69913 30646#endif
b99bd4ef
NC
30647 bfd_set_private_flags (stdoutput, flags);
30648
30649 /* We have run out flags in the COFF header to encode the
30650 status of ATPCS support, so instead we create a dummy,
c19d1205 30651 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
30652 if (atpcs)
30653 {
30654 asection * sec;
30655
30656 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30657
30658 if (sec != NULL)
30659 {
fd361982
AM
30660 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30661 bfd_set_section_size (sec, 0);
b99bd4ef
NC
30662 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30663 }
30664 }
7cc69913 30665 }
f17c130b 30666#endif
b99bd4ef
NC
30667
30668 /* Record the CPU type as well. */
2d447fca
JM
30669 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30670 mach = bfd_mach_arm_iWMMXt2;
30671 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 30672 mach = bfd_mach_arm_iWMMXt;
e74cfd16 30673 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 30674 mach = bfd_mach_arm_XScale;
e74cfd16 30675 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 30676 mach = bfd_mach_arm_ep9312;
e74cfd16 30677 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 30678 mach = bfd_mach_arm_5TE;
e74cfd16 30679 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 30680 {
e74cfd16 30681 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30682 mach = bfd_mach_arm_5T;
30683 else
30684 mach = bfd_mach_arm_5;
30685 }
e74cfd16 30686 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 30687 {
e74cfd16 30688 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30689 mach = bfd_mach_arm_4T;
30690 else
30691 mach = bfd_mach_arm_4;
30692 }
e74cfd16 30693 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 30694 mach = bfd_mach_arm_3M;
e74cfd16
PB
30695 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30696 mach = bfd_mach_arm_3;
30697 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30698 mach = bfd_mach_arm_2a;
30699 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30700 mach = bfd_mach_arm_2;
30701 else
30702 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
30703
30704 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30705}
30706
c19d1205 30707/* Command line processing. */
b99bd4ef 30708
c19d1205
ZW
30709/* md_parse_option
30710 Invocation line includes a switch not recognized by the base assembler.
30711 See if it's a processor-specific option.
b99bd4ef 30712
c19d1205
ZW
30713 This routine is somewhat complicated by the need for backwards
30714 compatibility (since older releases of gcc can't be changed).
30715 The new options try to make the interface as compatible as
30716 possible with GCC.
b99bd4ef 30717
c19d1205 30718 New options (supported) are:
b99bd4ef 30719
c19d1205
ZW
30720 -mcpu=<cpu name> Assemble for selected processor
30721 -march=<architecture name> Assemble for selected architecture
30722 -mfpu=<fpu architecture> Assemble for selected FPU.
30723 -EB/-mbig-endian Big-endian
30724 -EL/-mlittle-endian Little-endian
30725 -k Generate PIC code
30726 -mthumb Start in Thumb mode
30727 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30728
278df34e 30729 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30730 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30731
c19d1205 30732 For now we will also provide support for:
b99bd4ef 30733
c19d1205
ZW
30734 -mapcs-32 32-bit Program counter
30735 -mapcs-26 26-bit Program counter
30736 -macps-float Floats passed in FP registers
30737 -mapcs-reentrant Reentrant code
30738 -matpcs
30739 (sometime these will probably be replaced with -mapcs=<list of options>
30740 and -matpcs=<list of options>)
b99bd4ef 30741
c19d1205
ZW
30742 The remaining options are only supported for back-wards compatibility.
30743 Cpu variants, the arm part is optional:
30744 -m[arm]1 Currently not supported.
30745 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30746 -m[arm]3 Arm 3 processor
30747 -m[arm]6[xx], Arm 6 processors
30748 -m[arm]7[xx][t][[d]m] Arm 7 processors
30749 -m[arm]8[10] Arm 8 processors
30750 -m[arm]9[20][tdmi] Arm 9 processors
30751 -mstrongarm[110[0]] StrongARM processors
30752 -mxscale XScale processors
30753 -m[arm]v[2345[t[e]]] Arm architectures
30754 -mall All (except the ARM1)
30755 FP variants:
30756 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
30757 -mfpe-old (No float load/store multiples)
30758 -mvfpxd VFP Single precision
30759 -mvfp All VFP
30760 -mno-fpu Disable all floating point instructions
b99bd4ef 30761
c19d1205
ZW
30762 The following CPU names are recognized:
30763 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
30764 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
30765 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
30766 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
30767 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
30768 arm10t arm10e, arm1020t, arm1020e, arm10200e,
30769 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 30770
c19d1205 30771 */
b99bd4ef 30772
c19d1205 30773const char * md_shortopts = "m:k";
b99bd4ef 30774
c19d1205
ZW
30775#ifdef ARM_BI_ENDIAN
30776#define OPTION_EB (OPTION_MD_BASE + 0)
30777#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 30778#else
c19d1205
ZW
30779#if TARGET_BYTES_BIG_ENDIAN
30780#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 30781#else
c19d1205
ZW
30782#define OPTION_EL (OPTION_MD_BASE + 1)
30783#endif
b99bd4ef 30784#endif
845b51d6 30785#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 30786#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 30787
c19d1205 30788struct option md_longopts[] =
b99bd4ef 30789{
c19d1205
ZW
30790#ifdef OPTION_EB
30791 {"EB", no_argument, NULL, OPTION_EB},
30792#endif
30793#ifdef OPTION_EL
30794 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 30795#endif
845b51d6 30796 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
30797#ifdef OBJ_ELF
30798 {"fdpic", no_argument, NULL, OPTION_FDPIC},
30799#endif
c19d1205
ZW
30800 {NULL, no_argument, NULL, 0}
30801};
b99bd4ef 30802
c19d1205 30803size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 30804
c19d1205 30805struct arm_option_table
b99bd4ef 30806{
0198d5e6
TC
30807 const char * option; /* Option name to match. */
30808 const char * help; /* Help information. */
30809 int * var; /* Variable to change. */
30810 int value; /* What to change it to. */
30811 const char * deprecated; /* If non-null, print this message. */
c19d1205 30812};
b99bd4ef 30813
c19d1205
ZW
30814struct arm_option_table arm_opts[] =
30815{
30816 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
30817 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
30818 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
30819 &support_interwork, 1, NULL},
30820 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
30821 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
30822 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
30823 1, NULL},
30824 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
30825 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
30826 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
30827 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
30828 NULL},
b99bd4ef 30829
c19d1205
ZW
30830 /* These are recognized by the assembler, but have no affect on code. */
30831 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
30832 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
30833
30834 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
30835 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
30836 &warn_on_deprecated, 0, NULL},
24f19ccb
AV
30837
30838 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
30839 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
30840 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
30841
8b2d793c
NC
30842 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
30843 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
30844 {NULL, NULL, NULL, 0, NULL}
30845};
30846
30847struct arm_legacy_option_table
30848{
0198d5e6
TC
30849 const char * option; /* Option name to match. */
30850 const arm_feature_set ** var; /* Variable to change. */
30851 const arm_feature_set value; /* What to change it to. */
30852 const char * deprecated; /* If non-null, print this message. */
e74cfd16 30853};
b99bd4ef 30854
e74cfd16
PB
30855const struct arm_legacy_option_table arm_legacy_opts[] =
30856{
c19d1205
ZW
30857 /* DON'T add any new processors to this list -- we want the whole list
30858 to go away... Add them to the processors table instead. */
e74cfd16
PB
30859 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30860 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30861 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30862 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30863 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30864 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30865 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30866 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30867 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30868 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30869 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30870 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30871 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30872 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30873 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30874 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30875 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30876 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30877 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30878 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30879 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30880 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30881 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30882 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30883 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30884 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30885 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30886 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30887 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30888 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30889 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30890 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30891 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30892 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30893 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30894 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30895 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30896 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30897 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30898 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30899 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30900 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30901 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30902 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30903 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30904 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30905 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30906 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30907 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30908 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30909 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30910 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30911 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30912 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30913 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30914 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30915 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30916 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30917 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30918 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30919 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30920 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30921 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30922 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30923 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30924 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30925 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30926 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30927 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
30928 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30929 N_("use -mcpu=strongarm110")},
e74cfd16 30930 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30931 N_("use -mcpu=strongarm1100")},
e74cfd16 30932 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30933 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
30934 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
30935 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
30936 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 30937
c19d1205 30938 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
30939 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30940 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30941 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30942 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30943 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30944 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30945 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30946 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30947 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30948 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30949 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30950 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30951 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30952 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30953 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30954 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30955 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30956 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 30957
c19d1205 30958 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
30959 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
30960 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
30961 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
30962 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 30963 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 30964
e74cfd16 30965 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 30966};
7ed4c4c5 30967
c19d1205 30968struct arm_cpu_option_table
7ed4c4c5 30969{
0198d5e6
TC
30970 const char * name;
30971 size_t name_len;
30972 const arm_feature_set value;
30973 const arm_feature_set ext;
c19d1205
ZW
30974 /* For some CPUs we assume an FPU unless the user explicitly sets
30975 -mfpu=... */
0198d5e6 30976 const arm_feature_set default_fpu;
ee065d83
PB
30977 /* The canonical name of the CPU, or NULL to use NAME converted to upper
30978 case. */
0198d5e6 30979 const char * canonical_name;
c19d1205 30980};
7ed4c4c5 30981
c19d1205
ZW
30982/* This list should, at a minimum, contain all the cpu names
30983 recognized by GCC. */
996b5569 30984#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 30985
e74cfd16 30986static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 30987{
996b5569
TP
30988 ARM_CPU_OPT ("all", NULL, ARM_ANY,
30989 ARM_ARCH_NONE,
30990 FPU_ARCH_FPA),
30991 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
30992 ARM_ARCH_NONE,
30993 FPU_ARCH_FPA),
30994 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
30995 ARM_ARCH_NONE,
30996 FPU_ARCH_FPA),
30997 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
30998 ARM_ARCH_NONE,
30999 FPU_ARCH_FPA),
31000 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31001 ARM_ARCH_NONE,
31002 FPU_ARCH_FPA),
31003 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31004 ARM_ARCH_NONE,
31005 FPU_ARCH_FPA),
31006 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31007 ARM_ARCH_NONE,
31008 FPU_ARCH_FPA),
31009 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31010 ARM_ARCH_NONE,
31011 FPU_ARCH_FPA),
31012 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31013 ARM_ARCH_NONE,
31014 FPU_ARCH_FPA),
31015 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31016 ARM_ARCH_NONE,
31017 FPU_ARCH_FPA),
31018 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31019 ARM_ARCH_NONE,
31020 FPU_ARCH_FPA),
31021 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31022 ARM_ARCH_NONE,
31023 FPU_ARCH_FPA),
31024 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31025 ARM_ARCH_NONE,
31026 FPU_ARCH_FPA),
31027 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31028 ARM_ARCH_NONE,
31029 FPU_ARCH_FPA),
31030 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31031 ARM_ARCH_NONE,
31032 FPU_ARCH_FPA),
31033 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31034 ARM_ARCH_NONE,
31035 FPU_ARCH_FPA),
31036 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31037 ARM_ARCH_NONE,
31038 FPU_ARCH_FPA),
31039 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31040 ARM_ARCH_NONE,
31041 FPU_ARCH_FPA),
31042 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31043 ARM_ARCH_NONE,
31044 FPU_ARCH_FPA),
31045 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31046 ARM_ARCH_NONE,
31047 FPU_ARCH_FPA),
31048 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31049 ARM_ARCH_NONE,
31050 FPU_ARCH_FPA),
31051 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31052 ARM_ARCH_NONE,
31053 FPU_ARCH_FPA),
31054 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31055 ARM_ARCH_NONE,
31056 FPU_ARCH_FPA),
31057 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31058 ARM_ARCH_NONE,
31059 FPU_ARCH_FPA),
31060 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31061 ARM_ARCH_NONE,
31062 FPU_ARCH_FPA),
31063 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31064 ARM_ARCH_NONE,
31065 FPU_ARCH_FPA),
31066 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31067 ARM_ARCH_NONE,
31068 FPU_ARCH_FPA),
31069 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31070 ARM_ARCH_NONE,
31071 FPU_ARCH_FPA),
31072 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31073 ARM_ARCH_NONE,
31074 FPU_ARCH_FPA),
31075 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31076 ARM_ARCH_NONE,
31077 FPU_ARCH_FPA),
31078 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31079 ARM_ARCH_NONE,
31080 FPU_ARCH_FPA),
31081 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31082 ARM_ARCH_NONE,
31083 FPU_ARCH_FPA),
31084 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31085 ARM_ARCH_NONE,
31086 FPU_ARCH_FPA),
31087 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31088 ARM_ARCH_NONE,
31089 FPU_ARCH_FPA),
31090 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31091 ARM_ARCH_NONE,
31092 FPU_ARCH_FPA),
31093 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31094 ARM_ARCH_NONE,
31095 FPU_ARCH_FPA),
31096 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31097 ARM_ARCH_NONE,
31098 FPU_ARCH_FPA),
31099 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31100 ARM_ARCH_NONE,
31101 FPU_ARCH_FPA),
31102 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31103 ARM_ARCH_NONE,
31104 FPU_ARCH_FPA),
31105 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31106 ARM_ARCH_NONE,
31107 FPU_ARCH_FPA),
31108 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31109 ARM_ARCH_NONE,
31110 FPU_ARCH_FPA),
31111 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31112 ARM_ARCH_NONE,
31113 FPU_ARCH_FPA),
31114 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31115 ARM_ARCH_NONE,
31116 FPU_ARCH_FPA),
31117 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31118 ARM_ARCH_NONE,
31119 FPU_ARCH_FPA),
31120 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31121 ARM_ARCH_NONE,
31122 FPU_ARCH_FPA),
31123 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31124 ARM_ARCH_NONE,
31125 FPU_ARCH_FPA),
31126
c19d1205
ZW
31127 /* For V5 or later processors we default to using VFP; but the user
31128 should really set the FPU type explicitly. */
996b5569
TP
31129 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31130 ARM_ARCH_NONE,
31131 FPU_ARCH_VFP_V2),
31132 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31133 ARM_ARCH_NONE,
31134 FPU_ARCH_VFP_V2),
31135 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31136 ARM_ARCH_NONE,
31137 FPU_ARCH_VFP_V2),
31138 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31139 ARM_ARCH_NONE,
31140 FPU_ARCH_VFP_V2),
31141 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31142 ARM_ARCH_NONE,
31143 FPU_ARCH_VFP_V2),
31144 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31145 ARM_ARCH_NONE,
31146 FPU_ARCH_VFP_V2),
31147 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31148 ARM_ARCH_NONE,
31149 FPU_ARCH_VFP_V2),
31150 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31151 ARM_ARCH_NONE,
31152 FPU_ARCH_VFP_V2),
31153 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31154 ARM_ARCH_NONE,
31155 FPU_ARCH_VFP_V2),
31156 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31157 ARM_ARCH_NONE,
31158 FPU_ARCH_VFP_V2),
31159 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31160 ARM_ARCH_NONE,
31161 FPU_ARCH_VFP_V2),
31162 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31163 ARM_ARCH_NONE,
31164 FPU_ARCH_VFP_V2),
31165 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31166 ARM_ARCH_NONE,
31167 FPU_ARCH_VFP_V1),
31168 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31169 ARM_ARCH_NONE,
31170 FPU_ARCH_VFP_V1),
31171 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31172 ARM_ARCH_NONE,
31173 FPU_ARCH_VFP_V2),
31174 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31175 ARM_ARCH_NONE,
31176 FPU_ARCH_VFP_V2),
31177 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31178 ARM_ARCH_NONE,
31179 FPU_ARCH_VFP_V1),
31180 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31181 ARM_ARCH_NONE,
31182 FPU_ARCH_VFP_V2),
31183 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31184 ARM_ARCH_NONE,
31185 FPU_ARCH_VFP_V2),
31186 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31187 ARM_ARCH_NONE,
31188 FPU_ARCH_VFP_V2),
31189 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31190 ARM_ARCH_NONE,
31191 FPU_ARCH_VFP_V2),
31192 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31193 ARM_ARCH_NONE,
31194 FPU_ARCH_VFP_V2),
31195 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31196 ARM_ARCH_NONE,
31197 FPU_ARCH_VFP_V2),
31198 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31199 ARM_ARCH_NONE,
31200 FPU_ARCH_VFP_V2),
31201 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31202 ARM_ARCH_NONE,
31203 FPU_ARCH_VFP_V2),
31204 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31205 ARM_ARCH_NONE,
31206 FPU_ARCH_VFP_V2),
31207 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31208 ARM_ARCH_NONE,
31209 FPU_NONE),
31210 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31211 ARM_ARCH_NONE,
31212 FPU_NONE),
31213 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31214 ARM_ARCH_NONE,
31215 FPU_ARCH_VFP_V2),
31216 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31217 ARM_ARCH_NONE,
31218 FPU_ARCH_VFP_V2),
31219 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31220 ARM_ARCH_NONE,
31221 FPU_ARCH_VFP_V2),
31222 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31223 ARM_ARCH_NONE,
31224 FPU_NONE),
31225 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31226 ARM_ARCH_NONE,
31227 FPU_NONE),
31228 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31229 ARM_ARCH_NONE,
31230 FPU_ARCH_VFP_V2),
31231 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31232 ARM_ARCH_NONE,
31233 FPU_NONE),
31234 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31235 ARM_ARCH_NONE,
31236 FPU_ARCH_VFP_V2),
31237 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31238 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31239 FPU_NONE),
31240 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31241 ARM_ARCH_NONE,
31242 FPU_ARCH_NEON_VFP_V4),
31243 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31244 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31245 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31246 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31247 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31248 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31249 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31250 ARM_ARCH_NONE,
31251 FPU_ARCH_NEON_VFP_V4),
31252 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31253 ARM_ARCH_NONE,
31254 FPU_ARCH_NEON_VFP_V4),
31255 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31256 ARM_ARCH_NONE,
31257 FPU_ARCH_NEON_VFP_V4),
31258 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
8b301fbb 31259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31260 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31261 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
8b301fbb 31262 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31263 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31264 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
8b301fbb 31265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31266 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31267 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31269 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569 31270 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
8b301fbb 31271 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31272 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31273 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
8b301fbb 31274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31275 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31276 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
8b301fbb 31277 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31278 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31279 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31281 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 31282 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31283 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31284 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
0535e5d7
DZ
31285 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31287 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31288 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31289 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31290 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
31291 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31293 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
31294 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31295 ARM_ARCH_NONE,
31296 FPU_NONE),
31297 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31298 ARM_ARCH_NONE,
31299 FPU_ARCH_VFP_V3D16),
31300 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31301 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31302 FPU_NONE),
31303 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31304 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31305 FPU_ARCH_VFP_V3D16),
31306 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31307 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31308 FPU_ARCH_VFP_V3D16),
0cda1e19 31309 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
8b301fbb 31310 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
0cda1e19 31311 FPU_ARCH_NEON_VFP_ARMV8),
0535e5d7
DZ
31312 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31313 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31314 FPU_NONE),
996b5569
TP
31315 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31316 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31317 FPU_NONE),
31318 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31319 ARM_ARCH_NONE,
31320 FPU_NONE),
31321 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31322 ARM_ARCH_NONE,
31323 FPU_NONE),
31324 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31325 ARM_ARCH_NONE,
31326 FPU_NONE),
31327 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31328 ARM_ARCH_NONE,
31329 FPU_NONE),
31330 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31331 ARM_ARCH_NONE,
31332 FPU_NONE),
31333 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31334 ARM_ARCH_NONE,
31335 FPU_NONE),
31336 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31337 ARM_ARCH_NONE,
31338 FPU_NONE),
31339 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
8b301fbb 31340 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31341 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
31342 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31343 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31344 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 31345 /* ??? XSCALE is really an architecture. */
996b5569
TP
31346 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31347 ARM_ARCH_NONE,
31348 FPU_ARCH_VFP_V2),
31349
c19d1205 31350 /* ??? iwmmxt is not a processor. */
996b5569
TP
31351 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31352 ARM_ARCH_NONE,
31353 FPU_ARCH_VFP_V2),
31354 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31355 ARM_ARCH_NONE,
31356 FPU_ARCH_VFP_V2),
31357 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31358 ARM_ARCH_NONE,
31359 FPU_ARCH_VFP_V2),
31360
0198d5e6 31361 /* Maverick. */
996b5569
TP
31362 ARM_CPU_OPT ("ep9312", "ARM920T",
31363 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31364 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31365
da4339ed 31366 /* Marvell processors. */
996b5569
TP
31367 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31368 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31369 FPU_ARCH_VFP_V3D16),
31370 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31371 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31372 FPU_ARCH_NEON_VFP_V4),
da4339ed 31373
996b5569
TP
31374 /* APM X-Gene family. */
31375 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31376 ARM_ARCH_NONE,
31377 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31378 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
8b301fbb 31379 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31380 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31381
31382 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31383};
f3bad469 31384#undef ARM_CPU_OPT
7ed4c4c5 31385
34ef62f4
AV
31386struct arm_ext_table
31387{
31388 const char * name;
31389 size_t name_len;
31390 const arm_feature_set merge;
31391 const arm_feature_set clear;
31392};
31393
c19d1205 31394struct arm_arch_option_table
7ed4c4c5 31395{
34ef62f4
AV
31396 const char * name;
31397 size_t name_len;
31398 const arm_feature_set value;
31399 const arm_feature_set default_fpu;
31400 const struct arm_ext_table * ext_table;
31401};
31402
31403/* Used to add support for +E and +noE extension. */
31404#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31405/* Used to add support for a +E extension. */
31406#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31407/* Used to add support for a +noE extension. */
31408#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31409
31410#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31411 ~0 & ~FPU_ENDIAN_PURE)
31412
31413static const struct arm_ext_table armv5te_ext_table[] =
31414{
31415 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31416 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31417};
31418
31419static const struct arm_ext_table armv7_ext_table[] =
31420{
31421 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31422 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31423};
31424
31425static const struct arm_ext_table armv7ve_ext_table[] =
31426{
31427 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31428 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31429 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31430 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31431 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31432 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31433 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31434
31435 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31436 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31437
31438 /* Aliases for +simd. */
31439 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31440
31441 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31442 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31443 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31444
31445 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31446};
31447
31448static const struct arm_ext_table armv7a_ext_table[] =
31449{
31450 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31451 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31452 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31453 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31454 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31455 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31456 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31457
31458 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31459 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31460
31461 /* Aliases for +simd. */
31462 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31463 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31464
31465 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31466 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31467
31468 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31469 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31470 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31471};
31472
31473static const struct arm_ext_table armv7r_ext_table[] =
31474{
31475 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31476 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31477 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31478 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31479 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31480 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31481 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31482 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31483 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31484};
31485
31486static const struct arm_ext_table armv7em_ext_table[] =
31487{
31488 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31489 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31490 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31491 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31492 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31493 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31494 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31495};
31496
31497static const struct arm_ext_table armv8a_ext_table[] =
31498{
8b301fbb 31499 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31500 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31501 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31502 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31503
31504 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31505 should use the +simd option to turn on FP. */
31506 ARM_REMOVE ("fp", ALL_FP),
31507 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31508 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31509 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31510};
31511
31512
31513static const struct arm_ext_table armv81a_ext_table[] =
31514{
31515 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31516 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31517 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31518
31519 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31520 should use the +simd option to turn on FP. */
31521 ARM_REMOVE ("fp", ALL_FP),
31522 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31523 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31524 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31525};
31526
31527static const struct arm_ext_table armv82a_ext_table[] =
31528{
31529 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31530 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31531 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
616ce08e
MM
31532 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31533 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31534 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31535 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31536 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31537
31538 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31539 should use the +simd option to turn on FP. */
31540 ARM_REMOVE ("fp", ALL_FP),
31541 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31542 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31543 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31544};
31545
31546static const struct arm_ext_table armv84a_ext_table[] =
31547{
31548 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31549 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31550 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31551 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31552 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31553 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31554
31555 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31556 should use the +simd option to turn on FP. */
31557 ARM_REMOVE ("fp", ALL_FP),
31558 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31559 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31560 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31561};
31562
31563static const struct arm_ext_table armv85a_ext_table[] =
31564{
31565 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31566 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31567 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31568 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31569 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31570 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31571
31572 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31573 should use the +simd option to turn on FP. */
31574 ARM_REMOVE ("fp", ALL_FP),
31575 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31576};
31577
aab2c27d
MM
31578static const struct arm_ext_table armv86a_ext_table[] =
31579{
616ce08e 31580 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
aab2c27d
MM
31581 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31582};
31583
4934a27c
MM
31584#define CDE_EXTENSIONS \
31585 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31586 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31587 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31588 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31589 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31590 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31591 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31592 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31593
34ef62f4
AV
31594static const struct arm_ext_table armv8m_main_ext_table[] =
31595{
92169145
AV
31596 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31597 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
34ef62f4
AV
31598 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31599 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
4934a27c 31600 CDE_EXTENSIONS,
34ef62f4
AV
31601 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31602};
31603
92169145 31604
e0991585
AV
31605static const struct arm_ext_table armv8_1m_main_ext_table[] =
31606{
92169145
AV
31607 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31608 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
e0991585
AV
31609 ARM_EXT ("fp",
31610 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31611 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31612 ALL_FP),
31613 ARM_ADD ("fp.dp",
31614 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31615 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
92169145 31616 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
2da2eaf4 31617 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
a7ad558c 31618 ARM_ADD ("mve.fp",
92169145
AV
31619 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31620 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
2da2eaf4 31621 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
4934a27c 31622 CDE_EXTENSIONS,
e0991585
AV
31623 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31624};
31625
4934a27c
MM
31626#undef CDE_EXTENSIONS
31627
34ef62f4
AV
31628static const struct arm_ext_table armv8r_ext_table[] =
31629{
8b301fbb 31630 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31631 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31632 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31633 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31634 ARM_REMOVE ("fp", ALL_FP),
31635 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31636 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 31637};
7ed4c4c5 31638
c19d1205
ZW
31639/* This list should, at a minimum, contain all the architecture names
31640 recognized by GCC. */
34ef62f4
AV
31641#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31642#define ARM_ARCH_OPT2(N, V, DF, ext) \
31643 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 31644
e74cfd16 31645static const struct arm_arch_option_table arm_archs[] =
c19d1205 31646{
497d849d
TP
31647 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31648 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31649 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31650 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31651 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31652 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31653 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31654 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31655 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31656 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31657 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31658 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31659 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31660 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
31661 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31662 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31663 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31664 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31665 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31666 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31667 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31668 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31669 kept to preserve existing behaviour. */
34ef62f4
AV
31670 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31671 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31672 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31673 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31674 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31675 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31676 kept to preserve existing behaviour. */
34ef62f4
AV
31677 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31678 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
31679 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31680 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 31681 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
31682 /* The official spelling of the ARMv7 profile variants is the dashed form.
31683 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
31684 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31685 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31686 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31687 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
31688 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31689 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31690 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 31691 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 31692 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
31693 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31694 armv8m_main),
e0991585
AV
31695 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31696 armv8_1m_main),
34ef62f4
AV
31697 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31698 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31699 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31700 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31701 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31702 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31703 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
aab2c27d 31704 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
497d849d
TP
31705 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31706 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31707 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 31708 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31709};
f3bad469 31710#undef ARM_ARCH_OPT
7ed4c4c5 31711
69133863 31712/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 31713
69133863 31714struct arm_option_extension_value_table
c19d1205 31715{
0198d5e6
TC
31716 const char * name;
31717 size_t name_len;
31718 const arm_feature_set merge_value;
31719 const arm_feature_set clear_value;
d942732e
TP
31720 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31721 indicates that an extension is available for all architectures while
31722 ARM_ANY marks an empty entry. */
0198d5e6 31723 const arm_feature_set allowed_archs[2];
c19d1205 31724};
7ed4c4c5 31725
0198d5e6
TC
31726/* The following table must be in alphabetical order with a NULL last entry. */
31727
d942732e
TP
31728#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31729#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 31730
34ef62f4
AV
31731/* DEPRECATED: Refrain from using this table to add any new extensions, instead
31732 use the context sensitive approach using arm_ext_table's. */
69133863 31733static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 31734{
8b301fbb
MI
31735 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31736 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
823d2571 31737 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 31738 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
31739 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31740 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
31741 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31742 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31743 ARM_ARCH_V8_2A),
15afaa63
TP
31744 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31745 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31746 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
31747 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31748 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
31749 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31750 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31751 ARM_ARCH_V8_2A),
01f48020
TC
31752 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31753 | ARM_EXT2_FP16_FML),
31754 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31755 | ARM_EXT2_FP16_FML),
31756 ARM_ARCH_V8_2A),
d942732e 31757 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 31758 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
31759 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31760 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
31761 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
31762 Thumb divide instruction. Due to this having the same name as the
31763 previous entry, this will be ignored when doing command-line parsing and
31764 only considered by build attribute selection code. */
31765 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31766 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31767 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 31768 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 31769 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 31770 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 31771 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 31772 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
31773 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
31774 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 31775 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
31776 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31777 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
31778 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31779 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31780 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
31781 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
31782 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 31783 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
31784 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31785 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31786 ARM_ARCH_V8A),
4d1464f2
MW
31787 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
31788 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 31789 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
31790 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
31791 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 31792 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
31793 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31794 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31795 ARM_ARCH_V8A),
d942732e 31796 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 31797 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
31798 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
31799 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
31800 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
31801 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
31802 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
31803 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
31804 | ARM_EXT_DIV),
31805 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
31806 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31807 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
31808 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
31809 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 31810};
f3bad469 31811#undef ARM_EXT_OPT
69133863
MGD
31812
31813/* ISA floating-point and Advanced SIMD extensions. */
31814struct arm_option_fpu_value_table
31815{
0198d5e6
TC
31816 const char * name;
31817 const arm_feature_set value;
c19d1205 31818};
7ed4c4c5 31819
c19d1205
ZW
31820/* This list should, at a minimum, contain all the fpu names
31821 recognized by GCC. */
69133863 31822static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
31823{
31824 {"softfpa", FPU_NONE},
31825 {"fpe", FPU_ARCH_FPE},
31826 {"fpe2", FPU_ARCH_FPE},
31827 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
31828 {"fpa", FPU_ARCH_FPA},
31829 {"fpa10", FPU_ARCH_FPA},
31830 {"fpa11", FPU_ARCH_FPA},
31831 {"arm7500fe", FPU_ARCH_FPA},
31832 {"softvfp", FPU_ARCH_VFP},
31833 {"softvfp+vfp", FPU_ARCH_VFP_V2},
31834 {"vfp", FPU_ARCH_VFP_V2},
31835 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 31836 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
31837 {"vfp10", FPU_ARCH_VFP_V2},
31838 {"vfp10-r0", FPU_ARCH_VFP_V1},
31839 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
31840 {"vfpv2", FPU_ARCH_VFP_V2},
31841 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 31842 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 31843 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
31844 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
31845 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
31846 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
31847 {"arm1020t", FPU_ARCH_VFP_V1},
31848 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 31849 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
31850 {"arm1136jf-s", FPU_ARCH_VFP_V2},
31851 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 31852 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 31853 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 31854 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
31855 {"vfpv4", FPU_ARCH_VFP_V4},
31856 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 31857 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
31858 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
31859 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 31860 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
31861 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
31862 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
31863 {"crypto-neon-fp-armv8",
31864 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 31865 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
31866 {"crypto-neon-fp-armv8.1",
31867 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
31868 {NULL, ARM_ARCH_NONE}
31869};
31870
31871struct arm_option_value_table
31872{
e0471c16 31873 const char *name;
e74cfd16 31874 long value;
c19d1205 31875};
7ed4c4c5 31876
e74cfd16 31877static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
31878{
31879 {"hard", ARM_FLOAT_ABI_HARD},
31880 {"softfp", ARM_FLOAT_ABI_SOFTFP},
31881 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 31882 {NULL, 0}
c19d1205 31883};
7ed4c4c5 31884
c19d1205 31885#ifdef OBJ_ELF
3a4a14e9 31886/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 31887static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
31888{
31889 {"gnu", EF_ARM_EABI_UNKNOWN},
31890 {"4", EF_ARM_EABI_VER4},
3a4a14e9 31891 {"5", EF_ARM_EABI_VER5},
e74cfd16 31892 {NULL, 0}
c19d1205
ZW
31893};
31894#endif
7ed4c4c5 31895
c19d1205
ZW
31896struct arm_long_option_table
31897{
0198d5e6 31898 const char * option; /* Substring to match. */
e0471c16 31899 const char * help; /* Help information. */
17b9d67d 31900 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 31901 const char * deprecated; /* If non-null, print this message. */
c19d1205 31902};
7ed4c4c5 31903
c921be7d 31904static bfd_boolean
c168ce07 31905arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
31906 arm_feature_set *ext_set,
31907 const struct arm_ext_table *ext_table)
7ed4c4c5 31908{
69133863 31909 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
31910 extensions being added before being removed. We achieve this by having
31911 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 31912 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 31913 or removing it (0) and only allowing it to change in the order
69133863
MGD
31914 -1 -> 1 -> 0. */
31915 const struct arm_option_extension_value_table * opt = NULL;
d942732e 31916 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
31917 int adding_value = -1;
31918
c19d1205 31919 while (str != NULL && *str != 0)
7ed4c4c5 31920 {
82b8a785 31921 const char *ext;
f3bad469 31922 size_t len;
7ed4c4c5 31923
c19d1205
ZW
31924 if (*str != '+')
31925 {
31926 as_bad (_("invalid architectural extension"));
c921be7d 31927 return FALSE;
c19d1205 31928 }
7ed4c4c5 31929
c19d1205
ZW
31930 str++;
31931 ext = strchr (str, '+');
7ed4c4c5 31932
c19d1205 31933 if (ext != NULL)
f3bad469 31934 len = ext - str;
c19d1205 31935 else
f3bad469 31936 len = strlen (str);
7ed4c4c5 31937
f3bad469 31938 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
31939 {
31940 if (adding_value != 0)
31941 {
31942 adding_value = 0;
31943 opt = arm_extensions;
31944 }
31945
f3bad469 31946 len -= 2;
69133863
MGD
31947 str += 2;
31948 }
f3bad469 31949 else if (len > 0)
69133863
MGD
31950 {
31951 if (adding_value == -1)
31952 {
31953 adding_value = 1;
31954 opt = arm_extensions;
31955 }
31956 else if (adding_value != 1)
31957 {
31958 as_bad (_("must specify extensions to add before specifying "
31959 "those to remove"));
31960 return FALSE;
31961 }
31962 }
31963
f3bad469 31964 if (len == 0)
c19d1205
ZW
31965 {
31966 as_bad (_("missing architectural extension"));
c921be7d 31967 return FALSE;
c19d1205 31968 }
7ed4c4c5 31969
69133863
MGD
31970 gas_assert (adding_value != -1);
31971 gas_assert (opt != NULL);
31972
34ef62f4
AV
31973 if (ext_table != NULL)
31974 {
31975 const struct arm_ext_table * ext_opt = ext_table;
31976 bfd_boolean found = FALSE;
31977 for (; ext_opt->name != NULL; ext_opt++)
31978 if (ext_opt->name_len == len
31979 && strncmp (ext_opt->name, str, len) == 0)
31980 {
31981 if (adding_value)
31982 {
31983 if (ARM_FEATURE_ZERO (ext_opt->merge))
31984 /* TODO: Option not supported. When we remove the
31985 legacy table this case should error out. */
31986 continue;
31987
31988 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
31989 }
31990 else
31991 {
31992 if (ARM_FEATURE_ZERO (ext_opt->clear))
31993 /* TODO: Option not supported. When we remove the
31994 legacy table this case should error out. */
31995 continue;
31996 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
31997 }
31998 found = TRUE;
31999 break;
32000 }
32001 if (found)
32002 {
32003 str = ext;
32004 continue;
32005 }
32006 }
32007
69133863
MGD
32008 /* Scan over the options table trying to find an exact match. */
32009 for (; opt->name != NULL; opt++)
f3bad469 32010 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32011 {
d942732e
TP
32012 int i, nb_allowed_archs =
32013 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 32014 /* Check we can apply the extension to this architecture. */
d942732e
TP
32015 for (i = 0; i < nb_allowed_archs; i++)
32016 {
32017 /* Empty entry. */
32018 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32019 continue;
c168ce07 32020 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
32021 break;
32022 }
32023 if (i == nb_allowed_archs)
69133863
MGD
32024 {
32025 as_bad (_("extension does not apply to the base architecture"));
32026 return FALSE;
32027 }
32028
32029 /* Add or remove the extension. */
32030 if (adding_value)
4d354d8b 32031 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 32032 else
4d354d8b 32033 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 32034
3d030cdb
TP
32035 /* Allowing Thumb division instructions for ARMv7 in autodetection
32036 rely on this break so that duplicate extensions (extensions
32037 with the same name as a previous extension in the list) are not
32038 considered for command-line parsing. */
c19d1205
ZW
32039 break;
32040 }
7ed4c4c5 32041
c19d1205
ZW
32042 if (opt->name == NULL)
32043 {
69133863
MGD
32044 /* Did we fail to find an extension because it wasn't specified in
32045 alphabetical order, or because it does not exist? */
32046
32047 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 32048 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
32049 break;
32050
32051 if (opt->name == NULL)
32052 as_bad (_("unknown architectural extension `%s'"), str);
32053 else
32054 as_bad (_("architectural extensions must be specified in "
32055 "alphabetical order"));
32056
c921be7d 32057 return FALSE;
c19d1205 32058 }
69133863
MGD
32059 else
32060 {
32061 /* We should skip the extension we've just matched the next time
32062 round. */
32063 opt++;
32064 }
7ed4c4c5 32065
c19d1205
ZW
32066 str = ext;
32067 };
7ed4c4c5 32068
c921be7d 32069 return TRUE;
c19d1205 32070}
7ed4c4c5 32071
5312fe52
BW
32072static bfd_boolean
32073arm_parse_fp16_opt (const char *str)
32074{
32075 if (strcasecmp (str, "ieee") == 0)
32076 fp16_format = ARM_FP16_FORMAT_IEEE;
32077 else if (strcasecmp (str, "alternative") == 0)
32078 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32079 else
32080 {
32081 as_bad (_("unrecognised float16 format \"%s\""), str);
32082 return FALSE;
32083 }
32084
32085 return TRUE;
32086}
32087
c921be7d 32088static bfd_boolean
17b9d67d 32089arm_parse_cpu (const char *str)
7ed4c4c5 32090{
f3bad469 32091 const struct arm_cpu_option_table *opt;
82b8a785 32092 const char *ext = strchr (str, '+');
f3bad469 32093 size_t len;
7ed4c4c5 32094
c19d1205 32095 if (ext != NULL)
f3bad469 32096 len = ext - str;
7ed4c4c5 32097 else
f3bad469 32098 len = strlen (str);
7ed4c4c5 32099
f3bad469 32100 if (len == 0)
7ed4c4c5 32101 {
c19d1205 32102 as_bad (_("missing cpu name `%s'"), str);
c921be7d 32103 return FALSE;
7ed4c4c5
NC
32104 }
32105
c19d1205 32106 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 32107 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32108 {
c168ce07 32109 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
32110 if (mcpu_ext_opt == NULL)
32111 mcpu_ext_opt = XNEW (arm_feature_set);
32112 *mcpu_ext_opt = opt->ext;
e74cfd16 32113 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 32114 if (opt->canonical_name)
ef8e6722
JW
32115 {
32116 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32117 strcpy (selected_cpu_name, opt->canonical_name);
32118 }
ee065d83
PB
32119 else
32120 {
f3bad469 32121 size_t i;
c921be7d 32122
ef8e6722
JW
32123 if (len >= sizeof selected_cpu_name)
32124 len = (sizeof selected_cpu_name) - 1;
32125
f3bad469 32126 for (i = 0; i < len; i++)
ee065d83
PB
32127 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32128 selected_cpu_name[i] = 0;
32129 }
7ed4c4c5 32130
c19d1205 32131 if (ext != NULL)
34ef62f4 32132 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 32133
c921be7d 32134 return TRUE;
c19d1205 32135 }
7ed4c4c5 32136
c19d1205 32137 as_bad (_("unknown cpu `%s'"), str);
c921be7d 32138 return FALSE;
7ed4c4c5
NC
32139}
32140
c921be7d 32141static bfd_boolean
17b9d67d 32142arm_parse_arch (const char *str)
7ed4c4c5 32143{
e74cfd16 32144 const struct arm_arch_option_table *opt;
82b8a785 32145 const char *ext = strchr (str, '+');
f3bad469 32146 size_t len;
7ed4c4c5 32147
c19d1205 32148 if (ext != NULL)
f3bad469 32149 len = ext - str;
7ed4c4c5 32150 else
f3bad469 32151 len = strlen (str);
7ed4c4c5 32152
f3bad469 32153 if (len == 0)
7ed4c4c5 32154 {
c19d1205 32155 as_bad (_("missing architecture name `%s'"), str);
c921be7d 32156 return FALSE;
7ed4c4c5
NC
32157 }
32158
c19d1205 32159 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 32160 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32161 {
e74cfd16 32162 march_cpu_opt = &opt->value;
4d354d8b
TP
32163 if (march_ext_opt == NULL)
32164 march_ext_opt = XNEW (arm_feature_set);
32165 *march_ext_opt = arm_arch_none;
e74cfd16 32166 march_fpu_opt = &opt->default_fpu;
e20f9590 32167 selected_ctx_ext_table = opt->ext_table;
5f4273c7 32168 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 32169
c19d1205 32170 if (ext != NULL)
34ef62f4
AV
32171 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32172 opt->ext_table);
7ed4c4c5 32173
c921be7d 32174 return TRUE;
c19d1205
ZW
32175 }
32176
32177 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 32178 return FALSE;
7ed4c4c5 32179}
eb043451 32180
c921be7d 32181static bfd_boolean
17b9d67d 32182arm_parse_fpu (const char * str)
c19d1205 32183{
69133863 32184 const struct arm_option_fpu_value_table * opt;
b99bd4ef 32185
c19d1205
ZW
32186 for (opt = arm_fpus; opt->name != NULL; opt++)
32187 if (streq (opt->name, str))
32188 {
e74cfd16 32189 mfpu_opt = &opt->value;
c921be7d 32190 return TRUE;
c19d1205 32191 }
b99bd4ef 32192
c19d1205 32193 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 32194 return FALSE;
c19d1205
ZW
32195}
32196
c921be7d 32197static bfd_boolean
17b9d67d 32198arm_parse_float_abi (const char * str)
b99bd4ef 32199{
e74cfd16 32200 const struct arm_option_value_table * opt;
b99bd4ef 32201
c19d1205
ZW
32202 for (opt = arm_float_abis; opt->name != NULL; opt++)
32203 if (streq (opt->name, str))
32204 {
32205 mfloat_abi_opt = opt->value;
c921be7d 32206 return TRUE;
c19d1205 32207 }
cc8a6dd0 32208
c19d1205 32209 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 32210 return FALSE;
c19d1205 32211}
b99bd4ef 32212
c19d1205 32213#ifdef OBJ_ELF
c921be7d 32214static bfd_boolean
17b9d67d 32215arm_parse_eabi (const char * str)
c19d1205 32216{
e74cfd16 32217 const struct arm_option_value_table *opt;
cc8a6dd0 32218
c19d1205
ZW
32219 for (opt = arm_eabis; opt->name != NULL; opt++)
32220 if (streq (opt->name, str))
32221 {
32222 meabi_flags = opt->value;
c921be7d 32223 return TRUE;
c19d1205
ZW
32224 }
32225 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 32226 return FALSE;
c19d1205
ZW
32227}
32228#endif
cc8a6dd0 32229
c921be7d 32230static bfd_boolean
17b9d67d 32231arm_parse_it_mode (const char * str)
e07e6e58 32232{
c921be7d 32233 bfd_boolean ret = TRUE;
e07e6e58
NC
32234
32235 if (streq ("arm", str))
32236 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32237 else if (streq ("thumb", str))
32238 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32239 else if (streq ("always", str))
32240 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32241 else if (streq ("never", str))
32242 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32243 else
32244 {
32245 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 32246 "arm, thumb, always, or never."), str);
c921be7d 32247 ret = FALSE;
e07e6e58
NC
32248 }
32249
32250 return ret;
32251}
32252
2e6976a8 32253static bfd_boolean
17b9d67d 32254arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
32255{
32256 codecomposer_syntax = TRUE;
32257 arm_comment_chars[0] = ';';
32258 arm_line_separator_chars[0] = 0;
32259 return TRUE;
32260}
32261
c19d1205
ZW
32262struct arm_long_option_table arm_long_opts[] =
32263{
32264 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32265 arm_parse_cpu, NULL},
32266 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32267 arm_parse_arch, NULL},
32268 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32269 arm_parse_fpu, NULL},
32270 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32271 arm_parse_float_abi, NULL},
32272#ifdef OBJ_ELF
7fac0536 32273 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
32274 arm_parse_eabi, NULL},
32275#endif
e07e6e58
NC
32276 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32277 arm_parse_it_mode, NULL},
2e6976a8
DG
32278 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32279 arm_ccs_mode, NULL},
5312fe52
BW
32280 {"mfp16-format=",
32281 N_("[ieee|alternative]\n\
32282 set the encoding for half precision floating point "
32283 "numbers to IEEE\n\
32284 or Arm alternative format."),
32285 arm_parse_fp16_opt, NULL },
c19d1205
ZW
32286 {NULL, NULL, 0, NULL}
32287};
cc8a6dd0 32288
c19d1205 32289int
17b9d67d 32290md_parse_option (int c, const char * arg)
c19d1205
ZW
32291{
32292 struct arm_option_table *opt;
e74cfd16 32293 const struct arm_legacy_option_table *fopt;
c19d1205 32294 struct arm_long_option_table *lopt;
b99bd4ef 32295
c19d1205 32296 switch (c)
b99bd4ef 32297 {
c19d1205
ZW
32298#ifdef OPTION_EB
32299 case OPTION_EB:
32300 target_big_endian = 1;
32301 break;
32302#endif
cc8a6dd0 32303
c19d1205
ZW
32304#ifdef OPTION_EL
32305 case OPTION_EL:
32306 target_big_endian = 0;
32307 break;
32308#endif
b99bd4ef 32309
845b51d6
PB
32310 case OPTION_FIX_V4BX:
32311 fix_v4bx = TRUE;
32312 break;
32313
18a20338
CL
32314#ifdef OBJ_ELF
32315 case OPTION_FDPIC:
32316 arm_fdpic = TRUE;
32317 break;
32318#endif /* OBJ_ELF */
32319
c19d1205
ZW
32320 case 'a':
32321 /* Listing option. Just ignore these, we don't support additional
32322 ones. */
32323 return 0;
b99bd4ef 32324
c19d1205
ZW
32325 default:
32326 for (opt = arm_opts; opt->option != NULL; opt++)
32327 {
32328 if (c == opt->option[0]
32329 && ((arg == NULL && opt->option[1] == 0)
32330 || streq (arg, opt->option + 1)))
32331 {
c19d1205 32332 /* If the option is deprecated, tell the user. */
278df34e 32333 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
32334 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32335 arg ? arg : "", _(opt->deprecated));
b99bd4ef 32336
c19d1205
ZW
32337 if (opt->var != NULL)
32338 *opt->var = opt->value;
cc8a6dd0 32339
c19d1205
ZW
32340 return 1;
32341 }
32342 }
b99bd4ef 32343
e74cfd16
PB
32344 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32345 {
32346 if (c == fopt->option[0]
32347 && ((arg == NULL && fopt->option[1] == 0)
32348 || streq (arg, fopt->option + 1)))
32349 {
e74cfd16 32350 /* If the option is deprecated, tell the user. */
278df34e 32351 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
32352 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32353 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
32354
32355 if (fopt->var != NULL)
32356 *fopt->var = &fopt->value;
32357
32358 return 1;
32359 }
32360 }
32361
c19d1205
ZW
32362 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32363 {
32364 /* These options are expected to have an argument. */
32365 if (c == lopt->option[0]
32366 && arg != NULL
32367 && strncmp (arg, lopt->option + 1,
32368 strlen (lopt->option + 1)) == 0)
32369 {
c19d1205 32370 /* If the option is deprecated, tell the user. */
278df34e 32371 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
32372 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32373 _(lopt->deprecated));
b99bd4ef 32374
c19d1205
ZW
32375 /* Call the sup-option parser. */
32376 return lopt->func (arg + strlen (lopt->option) - 1);
32377 }
32378 }
a737bd4d 32379
c19d1205
ZW
32380 return 0;
32381 }
a394c00f 32382
c19d1205
ZW
32383 return 1;
32384}
a394c00f 32385
c19d1205
ZW
32386void
32387md_show_usage (FILE * fp)
a394c00f 32388{
c19d1205
ZW
32389 struct arm_option_table *opt;
32390 struct arm_long_option_table *lopt;
a394c00f 32391
c19d1205 32392 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 32393
c19d1205
ZW
32394 for (opt = arm_opts; opt->option != NULL; opt++)
32395 if (opt->help != NULL)
32396 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 32397
c19d1205
ZW
32398 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32399 if (lopt->help != NULL)
32400 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 32401
c19d1205
ZW
32402#ifdef OPTION_EB
32403 fprintf (fp, _("\
32404 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
32405#endif
32406
c19d1205
ZW
32407#ifdef OPTION_EL
32408 fprintf (fp, _("\
32409 -EL assemble code for a little-endian cpu\n"));
a737bd4d 32410#endif
845b51d6
PB
32411
32412 fprintf (fp, _("\
32413 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
32414
32415#ifdef OBJ_ELF
32416 fprintf (fp, _("\
32417 --fdpic generate an FDPIC object file\n"));
32418#endif /* OBJ_ELF */
c19d1205 32419}
ee065d83 32420
ee065d83 32421#ifdef OBJ_ELF
0198d5e6 32422
62b3e311
PB
32423typedef struct
32424{
32425 int val;
32426 arm_feature_set flags;
32427} cpu_arch_ver_table;
32428
2c6b98ea
TP
32429/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32430 chronologically for architectures, with an exception for ARMv6-M and
32431 ARMv6S-M due to legacy reasons. No new architecture should have a
32432 special case. This allows for build attribute selection results to be
32433 stable when new architectures are added. */
62b3e311
PB
32434static const cpu_arch_ver_table cpu_arch_ver[] =
32435{
031254f2
AV
32436 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32437 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32438 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32439 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32440 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32441 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32442 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32443 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32444 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32445 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32446 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32447 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32448 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32449 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32450 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32451 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32452 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32453 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32454 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32455 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32456 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32457 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32458 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32459 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
32460
32461 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32462 always selected build attributes to match those of ARMv6-M
32463 (resp. ARMv6S-M). However, due to these architectures being a strict
32464 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32465 would be selected when fully respecting chronology of architectures.
32466 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32467 move them before ARMv7 architectures. */
031254f2
AV
32468 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32469 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32470
32471 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32472 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32473 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32474 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32475 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32476 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32477 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32478 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32479 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32480 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32481 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32482 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32483 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32484 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32485 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32486 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
aab2c27d
MM
32487 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32488 {-1, ARM_ARCH_NONE}
62b3e311
PB
32489};
32490
ee3c0378 32491/* Set an attribute if it has not already been set by the user. */
0198d5e6 32492
ee3c0378
AS
32493static void
32494aeabi_set_attribute_int (int tag, int value)
32495{
32496 if (tag < 1
32497 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32498 || !attributes_set_explicitly[tag])
32499 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32500}
32501
32502static void
32503aeabi_set_attribute_string (int tag, const char *value)
32504{
32505 if (tag < 1
32506 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32507 || !attributes_set_explicitly[tag])
32508 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32509}
32510
2c6b98ea
TP
32511/* Return whether features in the *NEEDED feature set are available via
32512 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 32513
2c6b98ea
TP
32514static bfd_boolean
32515have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32516 const arm_feature_set *needed)
32517{
32518 int i, nb_allowed_archs;
32519 arm_feature_set ext_fset;
32520 const struct arm_option_extension_value_table *opt;
32521
32522 ext_fset = arm_arch_none;
32523 for (opt = arm_extensions; opt->name != NULL; opt++)
32524 {
32525 /* Extension does not provide any feature we need. */
32526 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32527 continue;
32528
32529 nb_allowed_archs =
32530 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32531 for (i = 0; i < nb_allowed_archs; i++)
32532 {
32533 /* Empty entry. */
32534 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32535 break;
32536
32537 /* Extension is available, add it. */
32538 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32539 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32540 }
32541 }
32542
32543 /* Can we enable all features in *needed? */
32544 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32545}
32546
32547/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32548 a given architecture feature set *ARCH_EXT_FSET including extension feature
32549 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32550 - if true, check for an exact match of the architecture modulo extensions;
32551 - otherwise, select build attribute value of the first superset
32552 architecture released so that results remains stable when new architectures
32553 are added.
32554 For -march/-mcpu=all the build attribute value of the most featureful
32555 architecture is returned. Tag_CPU_arch_profile result is returned in
32556 PROFILE. */
0198d5e6 32557
2c6b98ea
TP
32558static int
32559get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32560 const arm_feature_set *ext_fset,
32561 char *profile, int exact_match)
32562{
32563 arm_feature_set arch_fset;
32564 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32565
32566 /* Select most featureful architecture with all its extensions if building
32567 for -march=all as the feature sets used to set build attributes. */
32568 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32569 {
32570 /* Force revisiting of decision for each new architecture. */
031254f2 32571 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
32572 *profile = 'A';
32573 return TAG_CPU_ARCH_V8;
32574 }
32575
32576 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32577
32578 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32579 {
32580 arm_feature_set known_arch_fset;
32581
32582 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32583 if (exact_match)
32584 {
32585 /* Base architecture match user-specified architecture and
32586 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32587 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32588 {
32589 p_ver_ret = p_ver;
32590 goto found;
32591 }
32592 /* Base architecture match user-specified architecture only
32593 (eg. ARMv6-M in the same case as above). Record it in case we
32594 find a match with above condition. */
32595 else if (p_ver_ret == NULL
32596 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32597 p_ver_ret = p_ver;
32598 }
32599 else
32600 {
32601
32602 /* Architecture has all features wanted. */
32603 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32604 {
32605 arm_feature_set added_fset;
32606
32607 /* Compute features added by this architecture over the one
32608 recorded in p_ver_ret. */
32609 if (p_ver_ret != NULL)
32610 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32611 p_ver_ret->flags);
32612 /* First architecture that match incl. with extensions, or the
32613 only difference in features over the recorded match is
32614 features that were optional and are now mandatory. */
32615 if (p_ver_ret == NULL
32616 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32617 {
32618 p_ver_ret = p_ver;
32619 goto found;
32620 }
32621 }
32622 else if (p_ver_ret == NULL)
32623 {
32624 arm_feature_set needed_ext_fset;
32625
32626 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32627
32628 /* Architecture has all features needed when using some
32629 extensions. Record it and continue searching in case there
32630 exist an architecture providing all needed features without
32631 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32632 OS extension). */
32633 if (have_ext_for_needed_feat_p (&known_arch_fset,
32634 &needed_ext_fset))
32635 p_ver_ret = p_ver;
32636 }
32637 }
32638 }
32639
32640 if (p_ver_ret == NULL)
32641 return -1;
32642
32643found:
32644 /* Tag_CPU_arch_profile. */
32645 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32646 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32647 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32648 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
32649 *profile = 'A';
32650 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
32651 *profile = 'R';
32652 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32653 *profile = 'M';
32654 else
32655 *profile = '\0';
32656 return p_ver_ret->val;
32657}
32658
ee065d83 32659/* Set the public EABI object attributes. */
0198d5e6 32660
c168ce07 32661static void
ee065d83
PB
32662aeabi_set_public_attributes (void)
32663{
b90d5ba0 32664 char profile = '\0';
2c6b98ea 32665 int arch = -1;
90ec0d68 32666 int virt_sec = 0;
bca38921 32667 int fp16_optional = 0;
2c6b98ea
TP
32668 int skip_exact_match = 0;
32669 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 32670
54bab281
TP
32671 /* Autodetection mode, choose the architecture based the instructions
32672 actually used. */
32673 if (no_cpu_selected ())
32674 {
32675 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 32676
54bab281
TP
32677 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32678 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 32679
54bab281
TP
32680 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32681 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 32682
54bab281 32683 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
32684 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32685 flags_ext = arm_arch_none;
32686 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32687 selected_ext = flags_ext;
54bab281
TP
32688 selected_cpu = flags;
32689 }
32690 /* Otherwise, choose the architecture based on the capabilities of the
32691 requested cpu. */
32692 else
4d354d8b
TP
32693 {
32694 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32695 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32696 flags_ext = selected_ext;
32697 flags = selected_cpu;
32698 }
32699 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 32700
ddd7f988 32701 /* Allow the user to override the reported architecture. */
4d354d8b 32702 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 32703 {
4d354d8b 32704 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 32705 flags_ext = arm_arch_none;
7a1d4c38 32706 }
2c6b98ea 32707 else
4d354d8b 32708 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
32709
32710 /* When this function is run again after relaxation has happened there is no
32711 way to determine whether an architecture or CPU was specified by the user:
32712 - selected_cpu is set above for relaxation to work;
32713 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32714 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32715 Therefore, if not in -march=all case we first try an exact match and fall
32716 back to autodetection. */
32717 if (!skip_exact_match)
32718 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32719 if (arch == -1)
32720 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32721 if (arch == -1)
32722 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 32723
ee065d83
PB
32724 /* Tag_CPU_name. */
32725 if (selected_cpu_name[0])
32726 {
91d6fa6a 32727 char *q;
ee065d83 32728
91d6fa6a
NC
32729 q = selected_cpu_name;
32730 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
32731 {
32732 int i;
5f4273c7 32733
91d6fa6a
NC
32734 q += 4;
32735 for (i = 0; q[i]; i++)
32736 q[i] = TOUPPER (q[i]);
ee065d83 32737 }
91d6fa6a 32738 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 32739 }
62f3b8c8 32740
ee065d83 32741 /* Tag_CPU_arch. */
ee3c0378 32742 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 32743
62b3e311 32744 /* Tag_CPU_arch_profile. */
69239280
MGD
32745 if (profile != '\0')
32746 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 32747
15afaa63 32748 /* Tag_DSP_extension. */
4d354d8b 32749 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 32750 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 32751
2c6b98ea 32752 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 32753 /* Tag_ARM_ISA_use. */
ee3c0378 32754 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 32755 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 32756 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 32757
ee065d83 32758 /* Tag_THUMB_ISA_use. */
ee3c0378 32759 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 32760 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
32761 {
32762 int thumb_isa_use;
32763
32764 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 32765 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
32766 thumb_isa_use = 3;
32767 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
32768 thumb_isa_use = 2;
32769 else
32770 thumb_isa_use = 1;
32771 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
32772 }
62f3b8c8 32773
ee065d83 32774 /* Tag_VFP_arch. */
a715796b
TG
32775 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
32776 aeabi_set_attribute_int (Tag_VFP_arch,
32777 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32778 ? 7 : 8);
bca38921 32779 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
32780 aeabi_set_attribute_int (Tag_VFP_arch,
32781 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32782 ? 5 : 6);
32783 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
32784 {
32785 fp16_optional = 1;
32786 aeabi_set_attribute_int (Tag_VFP_arch, 3);
32787 }
ada65aa3 32788 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
32789 {
32790 aeabi_set_attribute_int (Tag_VFP_arch, 4);
32791 fp16_optional = 1;
32792 }
ee3c0378
AS
32793 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
32794 aeabi_set_attribute_int (Tag_VFP_arch, 2);
32795 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 32796 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 32797 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 32798
4547cb56
NC
32799 /* Tag_ABI_HardFP_use. */
32800 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
32801 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
32802 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
32803
ee065d83 32804 /* Tag_WMMX_arch. */
ee3c0378
AS
32805 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
32806 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
32807 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
32808 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 32809
ee3c0378 32810 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
32811 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
32812 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
32813 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
32814 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
32815 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
32816 {
32817 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
32818 {
32819 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
32820 }
32821 else
32822 {
32823 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
32824 fp16_optional = 1;
32825 }
32826 }
fa94de6b 32827
a7ad558c
AV
32828 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
32829 aeabi_set_attribute_int (Tag_MVE_arch, 2);
32830 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
32831 aeabi_set_attribute_int (Tag_MVE_arch, 1);
32832
ee3c0378 32833 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 32834 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 32835 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 32836
69239280
MGD
32837 /* Tag_DIV_use.
32838
32839 We set Tag_DIV_use to two when integer divide instructions have been used
32840 in ARM state, or when Thumb integer divide instructions have been used,
32841 but we have no architecture profile set, nor have we any ARM instructions.
32842
4ed7ed8d
TP
32843 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
32844 by the base architecture.
bca38921 32845
69239280 32846 For new architectures we will have to check these tests. */
031254f2 32847 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
32848 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32849 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
32850 aeabi_set_attribute_int (Tag_DIV_use, 0);
32851 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
32852 || (profile == '\0'
32853 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
32854 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 32855 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
32856
32857 /* Tag_MP_extension_use. */
32858 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
32859 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
32860
32861 /* Tag Virtualization_use. */
32862 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
32863 virt_sec |= 1;
32864 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
32865 virt_sec |= 2;
32866 if (virt_sec != 0)
32867 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
32868
32869 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
32870 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
32871}
32872
c168ce07
TP
32873/* Post relaxation hook. Recompute ARM attributes now that relaxation is
32874 finished and free extension feature bits which will not be used anymore. */
0198d5e6 32875
c168ce07
TP
32876void
32877arm_md_post_relax (void)
32878{
32879 aeabi_set_public_attributes ();
4d354d8b
TP
32880 XDELETE (mcpu_ext_opt);
32881 mcpu_ext_opt = NULL;
32882 XDELETE (march_ext_opt);
32883 march_ext_opt = NULL;
c168ce07
TP
32884}
32885
104d59d1 32886/* Add the default contents for the .ARM.attributes section. */
0198d5e6 32887
ee065d83
PB
32888void
32889arm_md_end (void)
32890{
ee065d83
PB
32891 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
32892 return;
32893
32894 aeabi_set_public_attributes ();
ee065d83 32895}
8463be01 32896#endif /* OBJ_ELF */
ee065d83 32897
ee065d83
PB
32898/* Parse a .cpu directive. */
32899
32900static void
32901s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
32902{
e74cfd16 32903 const struct arm_cpu_option_table *opt;
ee065d83
PB
32904 char *name;
32905 char saved_char;
32906
32907 name = input_line_pointer;
5f4273c7 32908 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32909 input_line_pointer++;
32910 saved_char = *input_line_pointer;
32911 *input_line_pointer = 0;
32912
32913 /* Skip the first "all" entry. */
32914 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
32915 if (streq (opt->name, name))
32916 {
4d354d8b
TP
32917 selected_arch = opt->value;
32918 selected_ext = opt->ext;
32919 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 32920 if (opt->canonical_name)
5f4273c7 32921 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
32922 else
32923 {
32924 int i;
32925 for (i = 0; opt->name[i]; i++)
32926 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 32927
ee065d83
PB
32928 selected_cpu_name[i] = 0;
32929 }
4d354d8b
TP
32930 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32931
ee065d83
PB
32932 *input_line_pointer = saved_char;
32933 demand_empty_rest_of_line ();
32934 return;
32935 }
32936 as_bad (_("unknown cpu `%s'"), name);
32937 *input_line_pointer = saved_char;
32938 ignore_rest_of_line ();
32939}
32940
ee065d83
PB
32941/* Parse a .arch directive. */
32942
32943static void
32944s_arm_arch (int ignored ATTRIBUTE_UNUSED)
32945{
e74cfd16 32946 const struct arm_arch_option_table *opt;
ee065d83
PB
32947 char saved_char;
32948 char *name;
32949
32950 name = input_line_pointer;
5f4273c7 32951 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32952 input_line_pointer++;
32953 saved_char = *input_line_pointer;
32954 *input_line_pointer = 0;
32955
32956 /* Skip the first "all" entry. */
32957 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32958 if (streq (opt->name, name))
32959 {
4d354d8b 32960 selected_arch = opt->value;
0e7aaa72 32961 selected_ctx_ext_table = opt->ext_table;
4d354d8b
TP
32962 selected_ext = arm_arch_none;
32963 selected_cpu = selected_arch;
5f4273c7 32964 strcpy (selected_cpu_name, opt->name);
4d354d8b 32965 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
32966 *input_line_pointer = saved_char;
32967 demand_empty_rest_of_line ();
32968 return;
32969 }
32970
32971 as_bad (_("unknown architecture `%s'\n"), name);
32972 *input_line_pointer = saved_char;
32973 ignore_rest_of_line ();
32974}
32975
7a1d4c38
PB
32976/* Parse a .object_arch directive. */
32977
32978static void
32979s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
32980{
32981 const struct arm_arch_option_table *opt;
32982 char saved_char;
32983 char *name;
32984
32985 name = input_line_pointer;
5f4273c7 32986 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
32987 input_line_pointer++;
32988 saved_char = *input_line_pointer;
32989 *input_line_pointer = 0;
32990
32991 /* Skip the first "all" entry. */
32992 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32993 if (streq (opt->name, name))
32994 {
4d354d8b 32995 selected_object_arch = opt->value;
7a1d4c38
PB
32996 *input_line_pointer = saved_char;
32997 demand_empty_rest_of_line ();
32998 return;
32999 }
33000
33001 as_bad (_("unknown architecture `%s'\n"), name);
33002 *input_line_pointer = saved_char;
33003 ignore_rest_of_line ();
33004}
33005
69133863
MGD
33006/* Parse a .arch_extension directive. */
33007
33008static void
33009s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33010{
33011 const struct arm_option_extension_value_table *opt;
33012 char saved_char;
33013 char *name;
33014 int adding_value = 1;
33015
33016 name = input_line_pointer;
33017 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33018 input_line_pointer++;
33019 saved_char = *input_line_pointer;
33020 *input_line_pointer = 0;
33021
33022 if (strlen (name) >= 2
33023 && strncmp (name, "no", 2) == 0)
33024 {
33025 adding_value = 0;
33026 name += 2;
33027 }
33028
e20f9590
MI
33029 /* Check the context specific extension table */
33030 if (selected_ctx_ext_table)
33031 {
33032 const struct arm_ext_table * ext_opt;
33033 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33034 {
33035 if (streq (ext_opt->name, name))
33036 {
33037 if (adding_value)
33038 {
33039 if (ARM_FEATURE_ZERO (ext_opt->merge))
33040 /* TODO: Option not supported. When we remove the
33041 legacy table this case should error out. */
33042 continue;
33043 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33044 ext_opt->merge);
33045 }
33046 else
33047 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33048
33049 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33050 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33051 *input_line_pointer = saved_char;
33052 demand_empty_rest_of_line ();
33053 return;
33054 }
33055 }
33056 }
33057
69133863
MGD
33058 for (opt = arm_extensions; opt->name != NULL; opt++)
33059 if (streq (opt->name, name))
33060 {
d942732e
TP
33061 int i, nb_allowed_archs =
33062 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33063 for (i = 0; i < nb_allowed_archs; i++)
33064 {
33065 /* Empty entry. */
4d354d8b 33066 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 33067 continue;
4d354d8b 33068 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
33069 break;
33070 }
33071
33072 if (i == nb_allowed_archs)
69133863
MGD
33073 {
33074 as_bad (_("architectural extension `%s' is not allowed for the "
33075 "current base architecture"), name);
33076 break;
33077 }
33078
33079 if (adding_value)
4d354d8b 33080 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 33081 opt->merge_value);
69133863 33082 else
4d354d8b 33083 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 33084
4d354d8b
TP
33085 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33086 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
33087 *input_line_pointer = saved_char;
33088 demand_empty_rest_of_line ();
3d030cdb
TP
33089 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33090 on this return so that duplicate extensions (extensions with the
33091 same name as a previous extension in the list) are not considered
33092 for command-line parsing. */
69133863
MGD
33093 return;
33094 }
33095
33096 if (opt->name == NULL)
e673710a 33097 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
33098
33099 *input_line_pointer = saved_char;
33100 ignore_rest_of_line ();
33101}
33102
ee065d83
PB
33103/* Parse a .fpu directive. */
33104
33105static void
33106s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33107{
69133863 33108 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
33109 char saved_char;
33110 char *name;
33111
33112 name = input_line_pointer;
5f4273c7 33113 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33114 input_line_pointer++;
33115 saved_char = *input_line_pointer;
33116 *input_line_pointer = 0;
5f4273c7 33117
ee065d83
PB
33118 for (opt = arm_fpus; opt->name != NULL; opt++)
33119 if (streq (opt->name, name))
33120 {
4d354d8b 33121 selected_fpu = opt->value;
f4399880 33122 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
4d354d8b
TP
33123#ifndef CPU_DEFAULT
33124 if (no_cpu_selected ())
33125 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33126 else
33127#endif
33128 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33129 *input_line_pointer = saved_char;
33130 demand_empty_rest_of_line ();
33131 return;
33132 }
33133
33134 as_bad (_("unknown floating point format `%s'\n"), name);
33135 *input_line_pointer = saved_char;
33136 ignore_rest_of_line ();
33137}
ee065d83 33138
794ba86a 33139/* Copy symbol information. */
f31fef98 33140
794ba86a
DJ
33141void
33142arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33143{
33144 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33145}
e04befd0 33146
f31fef98 33147#ifdef OBJ_ELF
e04befd0
AS
33148/* Given a symbolic attribute NAME, return the proper integer value.
33149 Returns -1 if the attribute is not known. */
f31fef98 33150
e04befd0
AS
33151int
33152arm_convert_symbolic_attribute (const char *name)
33153{
f31fef98
NC
33154 static const struct
33155 {
33156 const char * name;
33157 const int tag;
33158 }
33159 attribute_table[] =
33160 {
33161 /* When you modify this table you should
33162 also modify the list in doc/c-arm.texi. */
e04befd0 33163#define T(tag) {#tag, tag}
f31fef98
NC
33164 T (Tag_CPU_raw_name),
33165 T (Tag_CPU_name),
33166 T (Tag_CPU_arch),
33167 T (Tag_CPU_arch_profile),
33168 T (Tag_ARM_ISA_use),
33169 T (Tag_THUMB_ISA_use),
75375b3e 33170 T (Tag_FP_arch),
f31fef98
NC
33171 T (Tag_VFP_arch),
33172 T (Tag_WMMX_arch),
33173 T (Tag_Advanced_SIMD_arch),
33174 T (Tag_PCS_config),
33175 T (Tag_ABI_PCS_R9_use),
33176 T (Tag_ABI_PCS_RW_data),
33177 T (Tag_ABI_PCS_RO_data),
33178 T (Tag_ABI_PCS_GOT_use),
33179 T (Tag_ABI_PCS_wchar_t),
33180 T (Tag_ABI_FP_rounding),
33181 T (Tag_ABI_FP_denormal),
33182 T (Tag_ABI_FP_exceptions),
33183 T (Tag_ABI_FP_user_exceptions),
33184 T (Tag_ABI_FP_number_model),
75375b3e 33185 T (Tag_ABI_align_needed),
f31fef98 33186 T (Tag_ABI_align8_needed),
75375b3e 33187 T (Tag_ABI_align_preserved),
f31fef98
NC
33188 T (Tag_ABI_align8_preserved),
33189 T (Tag_ABI_enum_size),
33190 T (Tag_ABI_HardFP_use),
33191 T (Tag_ABI_VFP_args),
33192 T (Tag_ABI_WMMX_args),
33193 T (Tag_ABI_optimization_goals),
33194 T (Tag_ABI_FP_optimization_goals),
33195 T (Tag_compatibility),
33196 T (Tag_CPU_unaligned_access),
75375b3e 33197 T (Tag_FP_HP_extension),
f31fef98
NC
33198 T (Tag_VFP_HP_extension),
33199 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
33200 T (Tag_MPextension_use),
33201 T (Tag_DIV_use),
f31fef98
NC
33202 T (Tag_nodefaults),
33203 T (Tag_also_compatible_with),
33204 T (Tag_conformance),
33205 T (Tag_T2EE_use),
33206 T (Tag_Virtualization_use),
15afaa63 33207 T (Tag_DSP_extension),
a7ad558c 33208 T (Tag_MVE_arch),
cd21e546 33209 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 33210#undef T
f31fef98 33211 };
e04befd0
AS
33212 unsigned int i;
33213
33214 if (name == NULL)
33215 return -1;
33216
f31fef98 33217 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 33218 if (streq (name, attribute_table[i].name))
e04befd0
AS
33219 return attribute_table[i].tag;
33220
33221 return -1;
33222}
267bf995 33223
93ef582d
NC
33224/* Apply sym value for relocations only in the case that they are for
33225 local symbols in the same segment as the fixup and you have the
33226 respective architectural feature for blx and simple switches. */
0198d5e6 33227
267bf995 33228int
93ef582d 33229arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
33230{
33231 if (fixP->fx_addsy
33232 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
33233 /* PR 17444: If the local symbol is in a different section then a reloc
33234 will always be generated for it, so applying the symbol value now
33235 will result in a double offset being stored in the relocation. */
33236 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 33237 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
33238 {
33239 switch (fixP->fx_r_type)
33240 {
33241 case BFD_RELOC_ARM_PCREL_BLX:
33242 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33243 if (ARM_IS_FUNC (fixP->fx_addsy))
33244 return 1;
33245 break;
33246
33247 case BFD_RELOC_ARM_PCREL_CALL:
33248 case BFD_RELOC_THUMB_PCREL_BLX:
33249 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 33250 return 1;
267bf995
RR
33251 break;
33252
33253 default:
33254 break;
33255 }
33256
33257 }
33258 return 0;
33259}
f31fef98 33260#endif /* OBJ_ELF */