]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[gdb/testsuite] Fix UNRESOLVED in gdb.server/server-kill-python.exp
[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);
5aae9ae9
MM
342/* Note: This has more than one bit set, which means using it with
343 mark_feature_used (which returns if *any* of the bits are set in the current
344 cpu variant) can give surprising results. */
345static const arm_feature_set armv8m_fp =
346 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
69c9e028 347#ifdef OBJ_ELF
823d2571
TG
348static const arm_feature_set fpu_vfp_fp16 =
349 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
350static const arm_feature_set fpu_neon_ext_fma =
351 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 352#endif
823d2571
TG
353static const arm_feature_set fpu_vfp_ext_fma =
354 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 355static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 356 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 357static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 358 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 359static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 360 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 361static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 362 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
d6b4b13e 363static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 364 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
365static const arm_feature_set fpu_neon_ext_dotprod =
366 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 367
33a392fb 368static int mfloat_abi_opt = -1;
4d354d8b
TP
369/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
370 directive. */
371static arm_feature_set selected_arch = ARM_ARCH_NONE;
372/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
373 directive. */
374static arm_feature_set selected_ext = ARM_ARCH_NONE;
375/* Feature bits selected by the last -mcpu/-march or by the combination of the
376 last .cpu/.arch directive .arch_extension directives since that
377 directive. */
e74cfd16 378static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
379/* FPU feature bits selected by the last -mfpu or .fpu directive. */
380static arm_feature_set selected_fpu = FPU_NONE;
381/* Feature bits selected by the last .object_arch directive. */
382static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 383/* Must be long enough to hold any of the names in arm_cpus. */
e20f9590 384static const struct arm_ext_table * selected_ctx_ext_table = NULL;
ef8e6722 385static char selected_cpu_name[20];
8d67f500 386
aacf0b33
KT
387extern FLONUM_TYPE generic_floating_point_number;
388
8d67f500
NC
389/* Return if no cpu was selected on command-line. */
390static bfd_boolean
391no_cpu_selected (void)
392{
823d2571 393 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
394}
395
7cc69913 396#ifdef OBJ_ELF
deeaaff8
DJ
397# ifdef EABI_DEFAULT
398static int meabi_flags = EABI_DEFAULT;
399# else
d507cf36 400static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 401# endif
e1da3f5b 402
ee3c0378
AS
403static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
404
e1da3f5b 405bfd_boolean
5f4273c7 406arm_is_eabi (void)
e1da3f5b
PB
407{
408 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
409}
7cc69913 410#endif
b99bd4ef 411
b99bd4ef 412#ifdef OBJ_ELF
c19d1205 413/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
414symbolS * GOT_symbol;
415#endif
416
b99bd4ef
NC
417/* 0: assemble for ARM,
418 1: assemble for Thumb,
419 2: assemble for Thumb even though target CPU does not support thumb
420 instructions. */
421static int thumb_mode = 0;
8dc2430f
NC
422/* A value distinct from the possible values for thumb_mode that we
423 can use to record whether thumb_mode has been copied into the
424 tc_frag_data field of a frag. */
425#define MODE_RECORDED (1 << 4)
b99bd4ef 426
e07e6e58
NC
427/* Specifies the intrinsic IT insn behavior mode. */
428enum implicit_it_mode
429{
430 IMPLICIT_IT_MODE_NEVER = 0x00,
431 IMPLICIT_IT_MODE_ARM = 0x01,
432 IMPLICIT_IT_MODE_THUMB = 0x02,
433 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
434};
435static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
436
c19d1205
ZW
437/* If unified_syntax is true, we are processing the new unified
438 ARM/Thumb syntax. Important differences from the old ARM mode:
439
440 - Immediate operands do not require a # prefix.
441 - Conditional affixes always appear at the end of the
442 instruction. (For backward compatibility, those instructions
443 that formerly had them in the middle, continue to accept them
444 there.)
445 - The IT instruction may appear, and if it does is validated
446 against subsequent conditional affixes. It does not generate
447 machine code.
448
449 Important differences from the old Thumb mode:
450
451 - Immediate operands do not require a # prefix.
452 - Most of the V6T2 instructions are only available in unified mode.
453 - The .N and .W suffixes are recognized and honored (it is an error
454 if they cannot be honored).
455 - All instructions set the flags if and only if they have an 's' affix.
456 - Conditional affixes may be used. They are validated against
457 preceding IT instructions. Unlike ARM mode, you cannot use a
458 conditional affix except in the scope of an IT instruction. */
459
460static bfd_boolean unified_syntax = FALSE;
b99bd4ef 461
bacebabc
RM
462/* An immediate operand can start with #, and ld*, st*, pld operands
463 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
464 before a [, which can appear as the first operand for pld.
465 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
466const char arm_symbol_chars[] = "#[]{}";
bacebabc 467
5287ad62
JB
468enum neon_el_type
469{
dcbf9037 470 NT_invtype,
5287ad62
JB
471 NT_untyped,
472 NT_integer,
473 NT_float,
474 NT_poly,
475 NT_signed,
aab2c27d 476 NT_bfloat,
dcbf9037 477 NT_unsigned
5287ad62
JB
478};
479
480struct neon_type_el
481{
482 enum neon_el_type type;
483 unsigned size;
484};
485
5aae9ae9 486#define NEON_MAX_TYPE_ELS 5
5287ad62
JB
487
488struct neon_type
489{
490 struct neon_type_el el[NEON_MAX_TYPE_ELS];
491 unsigned elems;
492};
493
5ee91343 494enum pred_instruction_type
e07e6e58 495{
5ee91343
AV
496 OUTSIDE_PRED_INSN,
497 INSIDE_VPT_INSN,
e07e6e58
NC
498 INSIDE_IT_INSN,
499 INSIDE_IT_LAST_INSN,
500 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 501 if inside, should be the last one. */
e07e6e58 502 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 503 i.e. BKPT and NOP. */
5ee91343
AV
504 IT_INSN, /* The IT insn has been parsed. */
505 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 506 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 507 a predication code. */
4934a27c
MM
508 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
509 NEUTRAL_IT_NO_VPT_INSN, /* Instruction that can be either inside or outside
510 an IT block, but must not be in a VPT block. */
e07e6e58
NC
511};
512
ad6cec43
MGD
513/* The maximum number of operands we need. */
514#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 515#define ARM_IT_MAX_RELOCS 3
ad6cec43 516
b99bd4ef
NC
517struct arm_it
518{
c19d1205 519 const char * error;
b99bd4ef 520 unsigned long instruction;
c19d1205
ZW
521 int size;
522 int size_req;
523 int cond;
037e8744
JB
524 /* "uncond_value" is set to the value in place of the conditional field in
525 unconditional versions of the instruction, or -1 if nothing is
526 appropriate. */
527 int uncond_value;
5287ad62 528 struct neon_type vectype;
88714cb8
DG
529 /* This does not indicate an actual NEON instruction, only that
530 the mnemonic accepts neon-style type suffixes. */
531 int is_neon;
0110f2b8
PB
532 /* Set to the opcode if the instruction needs relaxation.
533 Zero if the instruction is not relaxed. */
534 unsigned long relax;
b99bd4ef
NC
535 struct
536 {
537 bfd_reloc_code_real_type type;
c19d1205
ZW
538 expressionS exp;
539 int pc_rel;
e2b0ab59 540 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 541
5ee91343 542 enum pred_instruction_type pred_insn_type;
e07e6e58 543
c19d1205
ZW
544 struct
545 {
546 unsigned reg;
ca3f61f7 547 signed int imm;
dcbf9037 548 struct neon_type_el vectype;
ca3f61f7
NC
549 unsigned present : 1; /* Operand present. */
550 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
551 unsigned immisreg : 2; /* .imm field is a second register.
552 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
553 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
554 0) not scalar,
555 1) Neon scalar,
556 2) MVE scalar. */
5287ad62 557 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 558 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
559 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
560 instructions. This allows us to disambiguate ARM <-> vector insns. */
561 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 562 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 563 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 564 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 565 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
566 unsigned hasreloc : 1; /* Operand has relocation suffix. */
567 unsigned writeback : 1; /* Operand has trailing ! */
568 unsigned preind : 1; /* Preindexed address. */
569 unsigned postind : 1; /* Postindexed address. */
570 unsigned negative : 1; /* Index register was negated. */
571 unsigned shifted : 1; /* Shift applied to operation. */
572 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 573 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
574};
575
c19d1205 576static struct arm_it inst;
b99bd4ef
NC
577
578#define NUM_FLOAT_VALS 8
579
05d2d07e 580const char * fp_const[] =
b99bd4ef
NC
581{
582 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
583};
584
b99bd4ef
NC
585LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
586
587#define FAIL (-1)
588#define SUCCESS (0)
589
590#define SUFF_S 1
591#define SUFF_D 2
592#define SUFF_E 3
593#define SUFF_P 4
594
c19d1205
ZW
595#define CP_T_X 0x00008000
596#define CP_T_Y 0x00400000
b99bd4ef 597
c19d1205
ZW
598#define CONDS_BIT 0x00100000
599#define LOAD_BIT 0x00100000
b99bd4ef
NC
600
601#define DOUBLE_LOAD_FLAG 0x00000001
602
603struct asm_cond
604{
d3ce72d0 605 const char * template_name;
c921be7d 606 unsigned long value;
b99bd4ef
NC
607};
608
c19d1205 609#define COND_ALWAYS 0xE
b99bd4ef 610
b99bd4ef
NC
611struct asm_psr
612{
d3ce72d0 613 const char * template_name;
c921be7d 614 unsigned long field;
b99bd4ef
NC
615};
616
62b3e311
PB
617struct asm_barrier_opt
618{
e797f7e0
MGD
619 const char * template_name;
620 unsigned long value;
621 const arm_feature_set arch;
62b3e311
PB
622};
623
2d2255b5 624/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
625#define SPSR_BIT (1 << 22)
626
c19d1205
ZW
627/* The individual PSR flag bits. */
628#define PSR_c (1 << 16)
629#define PSR_x (1 << 17)
630#define PSR_s (1 << 18)
631#define PSR_f (1 << 19)
b99bd4ef 632
c19d1205 633struct reloc_entry
bfae80f2 634{
0198d5e6 635 const char * name;
c921be7d 636 bfd_reloc_code_real_type reloc;
bfae80f2
RE
637};
638
5287ad62 639enum vfp_reg_pos
bfae80f2 640{
5287ad62
JB
641 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
642 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
643};
644
645enum vfp_ldstm_type
646{
647 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
648};
649
dcbf9037
JB
650/* Bits for DEFINED field in neon_typed_alias. */
651#define NTA_HASTYPE 1
652#define NTA_HASINDEX 2
653
654struct neon_typed_alias
655{
c921be7d
NC
656 unsigned char defined;
657 unsigned char index;
658 struct neon_type_el eltype;
dcbf9037
JB
659};
660
c19d1205 661/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
662 architecture extensions' registers. Each entry should have an error message
663 in reg_expected_msgs below. */
c19d1205 664enum arm_reg_type
bfae80f2 665{
c19d1205
ZW
666 REG_TYPE_RN,
667 REG_TYPE_CP,
668 REG_TYPE_CN,
669 REG_TYPE_FN,
670 REG_TYPE_VFS,
671 REG_TYPE_VFD,
5287ad62 672 REG_TYPE_NQ,
037e8744 673 REG_TYPE_VFSD,
5287ad62 674 REG_TYPE_NDQ,
dec41383 675 REG_TYPE_NSD,
037e8744 676 REG_TYPE_NSDQ,
c19d1205
ZW
677 REG_TYPE_VFC,
678 REG_TYPE_MVF,
679 REG_TYPE_MVD,
680 REG_TYPE_MVFX,
681 REG_TYPE_MVDX,
682 REG_TYPE_MVAX,
5ee91343 683 REG_TYPE_MQ,
c19d1205
ZW
684 REG_TYPE_DSPSC,
685 REG_TYPE_MMXWR,
686 REG_TYPE_MMXWC,
687 REG_TYPE_MMXWCG,
688 REG_TYPE_XSCALE,
5ee91343 689 REG_TYPE_RNB,
1b883319 690 REG_TYPE_ZR
bfae80f2
RE
691};
692
dcbf9037
JB
693/* Structure for a hash table entry for a register.
694 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
695 information which states whether a vector type or index is specified (for a
696 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
697struct reg_entry
698{
c921be7d 699 const char * name;
90ec0d68 700 unsigned int number;
c921be7d
NC
701 unsigned char type;
702 unsigned char builtin;
703 struct neon_typed_alias * neon;
6c43fab6
RE
704};
705
c19d1205 706/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 707const char * const reg_expected_msgs[] =
c19d1205 708{
5aa75429
TP
709 [REG_TYPE_RN] = N_("ARM register expected"),
710 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
711 [REG_TYPE_CN] = N_("co-processor register expected"),
712 [REG_TYPE_FN] = N_("FPA register expected"),
713 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
714 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
715 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
716 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
717 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
718 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
719 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
720 " expected"),
721 [REG_TYPE_VFC] = N_("VFP system register expected"),
722 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
723 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
724 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
725 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
726 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
727 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
728 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
729 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
730 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
731 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 732 [REG_TYPE_MQ] = N_("MVE vector register expected"),
5aa75429 733 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
734};
735
c19d1205 736/* Some well known registers that we refer to directly elsewhere. */
bd340a04 737#define REG_R12 12
c19d1205
ZW
738#define REG_SP 13
739#define REG_LR 14
740#define REG_PC 15
404ff6b5 741
b99bd4ef
NC
742/* ARM instructions take 4bytes in the object file, Thumb instructions
743 take 2: */
c19d1205 744#define INSN_SIZE 4
b99bd4ef
NC
745
746struct asm_opcode
747{
748 /* Basic string to match. */
d3ce72d0 749 const char * template_name;
c19d1205
ZW
750
751 /* Parameters to instruction. */
5be8be5d 752 unsigned int operands[8];
c19d1205
ZW
753
754 /* Conditional tag - see opcode_lookup. */
755 unsigned int tag : 4;
b99bd4ef
NC
756
757 /* Basic instruction code. */
a302e574 758 unsigned int avalue;
b99bd4ef 759
c19d1205
ZW
760 /* Thumb-format instruction code. */
761 unsigned int tvalue;
b99bd4ef 762
90e4755a 763 /* Which architecture variant provides this instruction. */
c921be7d
NC
764 const arm_feature_set * avariant;
765 const arm_feature_set * tvariant;
c19d1205
ZW
766
767 /* Function to call to encode instruction in ARM format. */
768 void (* aencode) (void);
b99bd4ef 769
c19d1205
ZW
770 /* Function to call to encode instruction in Thumb format. */
771 void (* tencode) (void);
5ee91343
AV
772
773 /* Indicates whether this instruction may be vector predicated. */
774 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
775};
776
a737bd4d
NC
777/* Defines for various bits that we will want to toggle. */
778#define INST_IMMEDIATE 0x02000000
779#define OFFSET_REG 0x02000000
c19d1205 780#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
781#define SHIFT_BY_REG 0x00000010
782#define PRE_INDEX 0x01000000
783#define INDEX_UP 0x00800000
784#define WRITE_BACK 0x00200000
785#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 786#define CPSI_MMOD 0x00020000
90e4755a 787
a737bd4d
NC
788#define LITERAL_MASK 0xf000f000
789#define OPCODE_MASK 0xfe1fffff
790#define V4_STR_BIT 0x00000020
8335d6aa 791#define VLDR_VMOV_SAME 0x0040f000
90e4755a 792
efd81785
PB
793#define T2_SUBS_PC_LR 0xf3de8f00
794
a737bd4d 795#define DATA_OP_SHIFT 21
bada4342 796#define SBIT_SHIFT 20
90e4755a 797
ef8d22e6
PB
798#define T2_OPCODE_MASK 0xfe1fffff
799#define T2_DATA_OP_SHIFT 21
bada4342 800#define T2_SBIT_SHIFT 20
ef8d22e6 801
6530b175
NC
802#define A_COND_MASK 0xf0000000
803#define A_PUSH_POP_OP_MASK 0x0fff0000
804
805/* Opcodes for pushing/poping registers to/from the stack. */
806#define A1_OPCODE_PUSH 0x092d0000
807#define A2_OPCODE_PUSH 0x052d0004
808#define A2_OPCODE_POP 0x049d0004
809
a737bd4d
NC
810/* Codes to distinguish the arithmetic instructions. */
811#define OPCODE_AND 0
812#define OPCODE_EOR 1
813#define OPCODE_SUB 2
814#define OPCODE_RSB 3
815#define OPCODE_ADD 4
816#define OPCODE_ADC 5
817#define OPCODE_SBC 6
818#define OPCODE_RSC 7
819#define OPCODE_TST 8
820#define OPCODE_TEQ 9
821#define OPCODE_CMP 10
822#define OPCODE_CMN 11
823#define OPCODE_ORR 12
824#define OPCODE_MOV 13
825#define OPCODE_BIC 14
826#define OPCODE_MVN 15
90e4755a 827
ef8d22e6
PB
828#define T2_OPCODE_AND 0
829#define T2_OPCODE_BIC 1
830#define T2_OPCODE_ORR 2
831#define T2_OPCODE_ORN 3
832#define T2_OPCODE_EOR 4
833#define T2_OPCODE_ADD 8
834#define T2_OPCODE_ADC 10
835#define T2_OPCODE_SBC 11
836#define T2_OPCODE_SUB 13
837#define T2_OPCODE_RSB 14
838
a737bd4d
NC
839#define T_OPCODE_MUL 0x4340
840#define T_OPCODE_TST 0x4200
841#define T_OPCODE_CMN 0x42c0
842#define T_OPCODE_NEG 0x4240
843#define T_OPCODE_MVN 0x43c0
90e4755a 844
a737bd4d
NC
845#define T_OPCODE_ADD_R3 0x1800
846#define T_OPCODE_SUB_R3 0x1a00
847#define T_OPCODE_ADD_HI 0x4400
848#define T_OPCODE_ADD_ST 0xb000
849#define T_OPCODE_SUB_ST 0xb080
850#define T_OPCODE_ADD_SP 0xa800
851#define T_OPCODE_ADD_PC 0xa000
852#define T_OPCODE_ADD_I8 0x3000
853#define T_OPCODE_SUB_I8 0x3800
854#define T_OPCODE_ADD_I3 0x1c00
855#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 856
a737bd4d
NC
857#define T_OPCODE_ASR_R 0x4100
858#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
859#define T_OPCODE_LSR_R 0x40c0
860#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
861#define T_OPCODE_ASR_I 0x1000
862#define T_OPCODE_LSL_I 0x0000
863#define T_OPCODE_LSR_I 0x0800
b99bd4ef 864
a737bd4d
NC
865#define T_OPCODE_MOV_I8 0x2000
866#define T_OPCODE_CMP_I8 0x2800
867#define T_OPCODE_CMP_LR 0x4280
868#define T_OPCODE_MOV_HR 0x4600
869#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 870
a737bd4d
NC
871#define T_OPCODE_LDR_PC 0x4800
872#define T_OPCODE_LDR_SP 0x9800
873#define T_OPCODE_STR_SP 0x9000
874#define T_OPCODE_LDR_IW 0x6800
875#define T_OPCODE_STR_IW 0x6000
876#define T_OPCODE_LDR_IH 0x8800
877#define T_OPCODE_STR_IH 0x8000
878#define T_OPCODE_LDR_IB 0x7800
879#define T_OPCODE_STR_IB 0x7000
880#define T_OPCODE_LDR_RW 0x5800
881#define T_OPCODE_STR_RW 0x5000
882#define T_OPCODE_LDR_RH 0x5a00
883#define T_OPCODE_STR_RH 0x5200
884#define T_OPCODE_LDR_RB 0x5c00
885#define T_OPCODE_STR_RB 0x5400
c9b604bd 886
a737bd4d
NC
887#define T_OPCODE_PUSH 0xb400
888#define T_OPCODE_POP 0xbc00
b99bd4ef 889
2fc8bdac 890#define T_OPCODE_BRANCH 0xe000
b99bd4ef 891
a737bd4d 892#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 893#define THUMB_PP_PC_LR 0x0100
c19d1205 894#define THUMB_LOAD_BIT 0x0800
53365c0d 895#define THUMB2_LOAD_BIT 0x00100000
c19d1205 896
5ee91343 897#define BAD_SYNTAX _("syntax error")
c19d1205 898#define BAD_ARGS _("bad arguments to instruction")
fdfde340 899#define BAD_SP _("r13 not allowed here")
c19d1205 900#define BAD_PC _("r15 not allowed here")
a302e574
AV
901#define BAD_ODD _("Odd register not allowed here")
902#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
903#define BAD_COND _("instruction cannot be conditional")
904#define BAD_OVERLAP _("registers may not be the same")
905#define BAD_HIREG _("lo register required")
906#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 907#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 908#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 909#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
4934a27c 910#define BAD_NO_VPT _("instruction not allowed in VPT block")
dfa9f0d5 911#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 912#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 913#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 914#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
915#define BAD_OUT_VPT \
916 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 917#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 918#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 919#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 920#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
921#define BAD_PC_ADDRESSING \
922 _("cannot use register index with PC-relative addressing")
923#define BAD_PC_WRITEBACK \
924 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
925#define BAD_RANGE _("branch out of range")
926#define BAD_FP16 _("selected processor does not support fp16 instruction")
aab2c27d 927#define BAD_BF16 _("selected processor does not support bf16 instruction")
4934a27c
MM
928#define BAD_CDE _("selected processor does not support cde instruction")
929#define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
dd5181d5 930#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 931#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
932#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
933 "block")
934#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
935 "block")
936#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
937 " operand")
938#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
939 " operand")
a302e574 940#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
941#define BAD_MVE_AUTO \
942 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
943 " use a valid -march or -mcpu option.")
944#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
945 "and source operands makes instruction UNPREDICTABLE")
35c228db 946#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 947#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 948
c921be7d
NC
949static struct hash_control * arm_ops_hsh;
950static struct hash_control * arm_cond_hsh;
5ee91343 951static struct hash_control * arm_vcond_hsh;
c921be7d
NC
952static struct hash_control * arm_shift_hsh;
953static struct hash_control * arm_psr_hsh;
954static struct hash_control * arm_v7m_psr_hsh;
955static struct hash_control * arm_reg_hsh;
956static struct hash_control * arm_reloc_hsh;
957static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 958
b99bd4ef
NC
959/* Stuff needed to resolve the label ambiguity
960 As:
961 ...
962 label: <insn>
963 may differ from:
964 ...
965 label:
5f4273c7 966 <insn> */
b99bd4ef
NC
967
968symbolS * last_label_seen;
b34976b6 969static int label_is_thumb_function_name = FALSE;
e07e6e58 970
3d0c9500
NC
971/* Literal pool structure. Held on a per-section
972 and per-sub-section basis. */
a737bd4d 973
c19d1205 974#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 975typedef struct literal_pool
b99bd4ef 976{
c921be7d
NC
977 expressionS literals [MAX_LITERAL_POOL_SIZE];
978 unsigned int next_free_entry;
979 unsigned int id;
980 symbolS * symbol;
981 segT section;
982 subsegT sub_section;
a8040cf2
NC
983#ifdef OBJ_ELF
984 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
985#endif
c921be7d 986 struct literal_pool * next;
8335d6aa 987 unsigned int alignment;
3d0c9500 988} literal_pool;
b99bd4ef 989
3d0c9500
NC
990/* Pointer to a linked list of literal pools. */
991literal_pool * list_of_pools = NULL;
e27ec89e 992
2e6976a8
DG
993typedef enum asmfunc_states
994{
995 OUTSIDE_ASMFUNC,
996 WAITING_ASMFUNC_NAME,
997 WAITING_ENDASMFUNC
998} asmfunc_states;
999
1000static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
1001
e07e6e58 1002#ifdef OBJ_ELF
5ee91343 1003# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 1004#else
5ee91343 1005static struct current_pred now_pred;
e07e6e58
NC
1006#endif
1007
1008static inline int
5ee91343 1009now_pred_compatible (int cond)
e07e6e58 1010{
5ee91343 1011 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
1012}
1013
1014static inline int
1015conditional_insn (void)
1016{
1017 return inst.cond != COND_ALWAYS;
1018}
1019
5ee91343 1020static int in_pred_block (void);
e07e6e58 1021
5ee91343 1022static int handle_pred_state (void);
e07e6e58
NC
1023
1024static void force_automatic_it_block_close (void);
1025
c921be7d
NC
1026static void it_fsm_post_encode (void);
1027
5ee91343 1028#define set_pred_insn_type(type) \
e07e6e58
NC
1029 do \
1030 { \
5ee91343
AV
1031 inst.pred_insn_type = type; \
1032 if (handle_pred_state () == FAIL) \
477330fc 1033 return; \
e07e6e58
NC
1034 } \
1035 while (0)
1036
5ee91343 1037#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
1038 do \
1039 { \
5ee91343
AV
1040 inst.pred_insn_type = type; \
1041 if (handle_pred_state () == FAIL) \
477330fc 1042 return failret; \
c921be7d
NC
1043 } \
1044 while(0)
1045
5ee91343 1046#define set_pred_insn_type_last() \
e07e6e58
NC
1047 do \
1048 { \
1049 if (inst.cond == COND_ALWAYS) \
5ee91343 1050 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1051 else \
5ee91343 1052 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1053 } \
1054 while (0)
1055
e39c1607
SD
1056/* Toggle value[pos]. */
1057#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1058
c19d1205 1059/* Pure syntax. */
b99bd4ef 1060
c19d1205
ZW
1061/* This array holds the chars that always start a comment. If the
1062 pre-processor is disabled, these aren't very useful. */
2e6976a8 1063char arm_comment_chars[] = "@";
3d0c9500 1064
c19d1205
ZW
1065/* This array holds the chars that only start a comment at the beginning of
1066 a line. If the line seems to have the form '# 123 filename'
1067 .line and .file directives will appear in the pre-processed output. */
1068/* Note that input_file.c hand checks for '#' at the beginning of the
1069 first line of the input file. This is because the compiler outputs
1070 #NO_APP at the beginning of its output. */
1071/* Also note that comments like this one will always work. */
1072const char line_comment_chars[] = "#";
3d0c9500 1073
2e6976a8 1074char arm_line_separator_chars[] = ";";
b99bd4ef 1075
c19d1205
ZW
1076/* Chars that can be used to separate mant
1077 from exp in floating point numbers. */
1078const char EXP_CHARS[] = "eE";
3d0c9500 1079
c19d1205
ZW
1080/* Chars that mean this number is a floating point constant. */
1081/* As in 0f12.456 */
1082/* or 0d1.2345e12 */
b99bd4ef 1083
5312fe52 1084const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1085
c19d1205
ZW
1086/* Prefix characters that indicate the start of an immediate
1087 value. */
1088#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1089
c19d1205
ZW
1090/* Separator character handling. */
1091
1092#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1093
5312fe52
BW
1094enum fp_16bit_format
1095{
1096 ARM_FP16_FORMAT_IEEE = 0x1,
1097 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1098 ARM_FP16_FORMAT_DEFAULT = 0x3
1099};
1100
1101static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1102
1103
c19d1205
ZW
1104static inline int
1105skip_past_char (char ** str, char c)
1106{
8ab8155f
NC
1107 /* PR gas/14987: Allow for whitespace before the expected character. */
1108 skip_whitespace (*str);
427d0db6 1109
c19d1205
ZW
1110 if (**str == c)
1111 {
1112 (*str)++;
1113 return SUCCESS;
3d0c9500 1114 }
c19d1205
ZW
1115 else
1116 return FAIL;
1117}
c921be7d 1118
c19d1205 1119#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1120
c19d1205
ZW
1121/* Arithmetic expressions (possibly involving symbols). */
1122
1123/* Return TRUE if anything in the expression is a bignum. */
1124
0198d5e6 1125static bfd_boolean
c19d1205
ZW
1126walk_no_bignums (symbolS * sp)
1127{
1128 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1129 return TRUE;
c19d1205
ZW
1130
1131 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1132 {
c19d1205
ZW
1133 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1134 || (symbol_get_value_expression (sp)->X_op_symbol
1135 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1136 }
1137
0198d5e6 1138 return FALSE;
3d0c9500
NC
1139}
1140
0198d5e6 1141static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1142
1143/* Third argument to my_get_expression. */
1144#define GE_NO_PREFIX 0
1145#define GE_IMM_PREFIX 1
1146#define GE_OPT_PREFIX 2
5287ad62
JB
1147/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1148 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1149#define GE_OPT_PREFIX_BIG 3
a737bd4d 1150
b99bd4ef 1151static int
c19d1205 1152my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1153{
c19d1205 1154 char * save_in;
b99bd4ef 1155
c19d1205
ZW
1156 /* In unified syntax, all prefixes are optional. */
1157 if (unified_syntax)
5287ad62 1158 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1159 : GE_OPT_PREFIX;
b99bd4ef 1160
c19d1205 1161 switch (prefix_mode)
b99bd4ef 1162 {
c19d1205
ZW
1163 case GE_NO_PREFIX: break;
1164 case GE_IMM_PREFIX:
1165 if (!is_immediate_prefix (**str))
1166 {
1167 inst.error = _("immediate expression requires a # prefix");
1168 return FAIL;
1169 }
1170 (*str)++;
1171 break;
1172 case GE_OPT_PREFIX:
5287ad62 1173 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1174 if (is_immediate_prefix (**str))
1175 (*str)++;
1176 break;
0198d5e6
TC
1177 default:
1178 abort ();
c19d1205 1179 }
b99bd4ef 1180
c19d1205 1181 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1182
c19d1205
ZW
1183 save_in = input_line_pointer;
1184 input_line_pointer = *str;
0198d5e6 1185 in_my_get_expression = TRUE;
2ac93be7 1186 expression (ep);
0198d5e6 1187 in_my_get_expression = FALSE;
c19d1205 1188
f86adc07 1189 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1190 {
f86adc07 1191 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1192 *str = input_line_pointer;
1193 input_line_pointer = save_in;
1194 if (inst.error == NULL)
f86adc07
NS
1195 inst.error = (ep->X_op == O_absent
1196 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1197 return 1;
1198 }
b99bd4ef 1199
c19d1205
ZW
1200 /* Get rid of any bignums now, so that we don't generate an error for which
1201 we can't establish a line number later on. Big numbers are never valid
1202 in instructions, which is where this routine is always called. */
5287ad62
JB
1203 if (prefix_mode != GE_OPT_PREFIX_BIG
1204 && (ep->X_op == O_big
477330fc 1205 || (ep->X_add_symbol
5287ad62 1206 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1207 || (ep->X_op_symbol
5287ad62 1208 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1209 {
1210 inst.error = _("invalid constant");
1211 *str = input_line_pointer;
1212 input_line_pointer = save_in;
1213 return 1;
1214 }
b99bd4ef 1215
c19d1205
ZW
1216 *str = input_line_pointer;
1217 input_line_pointer = save_in;
0198d5e6 1218 return SUCCESS;
b99bd4ef
NC
1219}
1220
c19d1205
ZW
1221/* Turn a string in input_line_pointer into a floating point constant
1222 of type TYPE, and store the appropriate bytes in *LITP. The number
1223 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1224 returned, or NULL on OK.
b99bd4ef 1225
c19d1205
ZW
1226 Note that fp constants aren't represent in the normal way on the ARM.
1227 In big endian mode, things are as expected. However, in little endian
1228 mode fp constants are big-endian word-wise, and little-endian byte-wise
1229 within the words. For example, (double) 1.1 in big endian mode is
1230 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1231 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1232
c19d1205 1233 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1234
6d4af3c2 1235const char *
c19d1205
ZW
1236md_atof (int type, char * litP, int * sizeP)
1237{
1238 int prec;
1239 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1240 char *t;
1241 int i;
b99bd4ef 1242
c19d1205
ZW
1243 switch (type)
1244 {
5312fe52
BW
1245 case 'H':
1246 case 'h':
1247 prec = 1;
1248 break;
1249
27cce866
MM
1250 /* If this is a bfloat16, then parse it slightly differently, as it
1251 does not follow the IEEE specification for floating point numbers
1252 exactly. */
1253 case 'b':
1254 {
1255 FLONUM_TYPE generic_float;
1256
1257 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1258
1259 if (t)
1260 input_line_pointer = t;
1261 else
1262 return _("invalid floating point number");
1263
1264 switch (generic_float.sign)
1265 {
1266 /* Is +Inf. */
1267 case 'P':
1268 words[0] = 0x7f80;
1269 break;
1270
1271 /* Is -Inf. */
1272 case 'N':
1273 words[0] = 0xff80;
1274 break;
1275
1276 /* Is NaN. */
1277 /* bfloat16 has two types of NaN - quiet and signalling.
1278 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1279 signalling NaN's have bit[0] == 0 && fraction != 0.
1280 Chosen this specific encoding as it is the same form
1281 as used by other IEEE 754 encodings in GAS. */
1282 case 0:
1283 words[0] = 0x7fff;
1284 break;
1285
1286 default:
1287 break;
1288 }
1289
1290 *sizeP = 2;
1291
1292 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1293
1294 return NULL;
1295 }
c19d1205
ZW
1296 case 'f':
1297 case 'F':
1298 case 's':
1299 case 'S':
1300 prec = 2;
1301 break;
b99bd4ef 1302
c19d1205
ZW
1303 case 'd':
1304 case 'D':
1305 case 'r':
1306 case 'R':
1307 prec = 4;
1308 break;
b99bd4ef 1309
c19d1205
ZW
1310 case 'x':
1311 case 'X':
499ac353 1312 prec = 5;
c19d1205 1313 break;
b99bd4ef 1314
c19d1205
ZW
1315 case 'p':
1316 case 'P':
499ac353 1317 prec = 5;
c19d1205 1318 break;
a737bd4d 1319
c19d1205
ZW
1320 default:
1321 *sizeP = 0;
499ac353 1322 return _("Unrecognized or unsupported floating point constant");
c19d1205 1323 }
b99bd4ef 1324
c19d1205
ZW
1325 t = atof_ieee (input_line_pointer, type, words);
1326 if (t)
1327 input_line_pointer = t;
499ac353 1328 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1329
72c03e30
BW
1330 if (target_big_endian || prec == 1)
1331 for (i = 0; i < prec; i++)
1332 {
1333 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1334 litP += sizeof (LITTLENUM_TYPE);
1335 }
1336 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1337 for (i = prec - 1; i >= 0; i--)
1338 {
1339 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1340 litP += sizeof (LITTLENUM_TYPE);
1341 }
c19d1205 1342 else
72c03e30
BW
1343 /* For a 4 byte float the order of elements in `words' is 1 0.
1344 For an 8 byte float the order is 1 0 3 2. */
1345 for (i = 0; i < prec; i += 2)
1346 {
1347 md_number_to_chars (litP, (valueT) words[i + 1],
1348 sizeof (LITTLENUM_TYPE));
1349 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1350 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1351 litP += 2 * sizeof (LITTLENUM_TYPE);
1352 }
b99bd4ef 1353
499ac353 1354 return NULL;
c19d1205 1355}
b99bd4ef 1356
c19d1205
ZW
1357/* We handle all bad expressions here, so that we can report the faulty
1358 instruction in the error message. */
0198d5e6 1359
c19d1205 1360void
91d6fa6a 1361md_operand (expressionS * exp)
c19d1205
ZW
1362{
1363 if (in_my_get_expression)
91d6fa6a 1364 exp->X_op = O_illegal;
b99bd4ef
NC
1365}
1366
c19d1205 1367/* Immediate values. */
b99bd4ef 1368
0198d5e6 1369#ifdef OBJ_ELF
c19d1205
ZW
1370/* Generic immediate-value read function for use in directives.
1371 Accepts anything that 'expression' can fold to a constant.
1372 *val receives the number. */
0198d5e6 1373
c19d1205
ZW
1374static int
1375immediate_for_directive (int *val)
b99bd4ef 1376{
c19d1205
ZW
1377 expressionS exp;
1378 exp.X_op = O_illegal;
b99bd4ef 1379
c19d1205
ZW
1380 if (is_immediate_prefix (*input_line_pointer))
1381 {
1382 input_line_pointer++;
1383 expression (&exp);
1384 }
b99bd4ef 1385
c19d1205
ZW
1386 if (exp.X_op != O_constant)
1387 {
1388 as_bad (_("expected #constant"));
1389 ignore_rest_of_line ();
1390 return FAIL;
1391 }
1392 *val = exp.X_add_number;
1393 return SUCCESS;
b99bd4ef 1394}
c19d1205 1395#endif
b99bd4ef 1396
c19d1205 1397/* Register parsing. */
b99bd4ef 1398
c19d1205
ZW
1399/* Generic register parser. CCP points to what should be the
1400 beginning of a register name. If it is indeed a valid register
1401 name, advance CCP over it and return the reg_entry structure;
1402 otherwise return NULL. Does not issue diagnostics. */
1403
1404static struct reg_entry *
1405arm_reg_parse_multi (char **ccp)
b99bd4ef 1406{
c19d1205
ZW
1407 char *start = *ccp;
1408 char *p;
1409 struct reg_entry *reg;
b99bd4ef 1410
477330fc
RM
1411 skip_whitespace (start);
1412
c19d1205
ZW
1413#ifdef REGISTER_PREFIX
1414 if (*start != REGISTER_PREFIX)
01cfc07f 1415 return NULL;
c19d1205
ZW
1416 start++;
1417#endif
1418#ifdef OPTIONAL_REGISTER_PREFIX
1419 if (*start == OPTIONAL_REGISTER_PREFIX)
1420 start++;
1421#endif
b99bd4ef 1422
c19d1205
ZW
1423 p = start;
1424 if (!ISALPHA (*p) || !is_name_beginner (*p))
1425 return NULL;
b99bd4ef 1426
c19d1205
ZW
1427 do
1428 p++;
1429 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1430
1431 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1432
1433 if (!reg)
1434 return NULL;
1435
1436 *ccp = p;
1437 return reg;
b99bd4ef
NC
1438}
1439
1440static int
dcbf9037 1441arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1442 enum arm_reg_type type)
b99bd4ef 1443{
c19d1205
ZW
1444 /* Alternative syntaxes are accepted for a few register classes. */
1445 switch (type)
1446 {
1447 case REG_TYPE_MVF:
1448 case REG_TYPE_MVD:
1449 case REG_TYPE_MVFX:
1450 case REG_TYPE_MVDX:
1451 /* Generic coprocessor register names are allowed for these. */
79134647 1452 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1453 return reg->number;
1454 break;
69b97547 1455
c19d1205
ZW
1456 case REG_TYPE_CP:
1457 /* For backward compatibility, a bare number is valid here. */
1458 {
1459 unsigned long processor = strtoul (start, ccp, 10);
1460 if (*ccp != start && processor <= 15)
1461 return processor;
1462 }
1a0670f3 1463 /* Fall through. */
6057a28f 1464
c19d1205
ZW
1465 case REG_TYPE_MMXWC:
1466 /* WC includes WCG. ??? I'm not sure this is true for all
1467 instructions that take WC registers. */
79134647 1468 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1469 return reg->number;
6057a28f 1470 break;
c19d1205 1471
6057a28f 1472 default:
c19d1205 1473 break;
6057a28f
NC
1474 }
1475
dcbf9037
JB
1476 return FAIL;
1477}
1478
1479/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1480 return value is the register number or FAIL. */
1481
1482static int
1483arm_reg_parse (char **ccp, enum arm_reg_type type)
1484{
1485 char *start = *ccp;
1486 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1487 int ret;
1488
1489 /* Do not allow a scalar (reg+index) to parse as a register. */
1490 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1491 return FAIL;
1492
1493 if (reg && reg->type == type)
1494 return reg->number;
1495
1496 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1497 return ret;
1498
c19d1205
ZW
1499 *ccp = start;
1500 return FAIL;
1501}
69b97547 1502
dcbf9037
JB
1503/* Parse a Neon type specifier. *STR should point at the leading '.'
1504 character. Does no verification at this stage that the type fits the opcode
1505 properly. E.g.,
1506
1507 .i32.i32.s16
1508 .s32.f32
1509 .u16
1510
1511 Can all be legally parsed by this function.
1512
1513 Fills in neon_type struct pointer with parsed information, and updates STR
1514 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1515 type, FAIL if not. */
1516
1517static int
1518parse_neon_type (struct neon_type *type, char **str)
1519{
1520 char *ptr = *str;
1521
1522 if (type)
1523 type->elems = 0;
1524
1525 while (type->elems < NEON_MAX_TYPE_ELS)
1526 {
1527 enum neon_el_type thistype = NT_untyped;
1528 unsigned thissize = -1u;
1529
1530 if (*ptr != '.')
1531 break;
1532
1533 ptr++;
1534
1535 /* Just a size without an explicit type. */
1536 if (ISDIGIT (*ptr))
1537 goto parsesize;
1538
1539 switch (TOLOWER (*ptr))
1540 {
1541 case 'i': thistype = NT_integer; break;
1542 case 'f': thistype = NT_float; break;
1543 case 'p': thistype = NT_poly; break;
1544 case 's': thistype = NT_signed; break;
1545 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1546 case 'd':
1547 thistype = NT_float;
1548 thissize = 64;
1549 ptr++;
1550 goto done;
aab2c27d
MM
1551 case 'b':
1552 thistype = NT_bfloat;
1553 switch (TOLOWER (*(++ptr)))
1554 {
1555 case 'f':
1556 ptr += 1;
1557 thissize = strtoul (ptr, &ptr, 10);
1558 if (thissize != 16)
1559 {
1560 as_bad (_("bad size %d in type specifier"), thissize);
1561 return FAIL;
1562 }
1563 goto done;
1564 case '0': case '1': case '2': case '3': case '4':
1565 case '5': case '6': case '7': case '8': case '9':
1566 case ' ': case '.':
1567 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1568 return FAIL;
1569 default:
1570 break;
1571 }
1572 break;
dcbf9037
JB
1573 default:
1574 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1575 return FAIL;
1576 }
1577
1578 ptr++;
1579
1580 /* .f is an abbreviation for .f32. */
1581 if (thistype == NT_float && !ISDIGIT (*ptr))
1582 thissize = 32;
1583 else
1584 {
1585 parsesize:
1586 thissize = strtoul (ptr, &ptr, 10);
1587
1588 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1589 && thissize != 64)
1590 {
1591 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1592 return FAIL;
1593 }
1594 }
1595
037e8744 1596 done:
dcbf9037 1597 if (type)
477330fc
RM
1598 {
1599 type->el[type->elems].type = thistype;
dcbf9037
JB
1600 type->el[type->elems].size = thissize;
1601 type->elems++;
1602 }
1603 }
1604
1605 /* Empty/missing type is not a successful parse. */
1606 if (type->elems == 0)
1607 return FAIL;
1608
1609 *str = ptr;
1610
1611 return SUCCESS;
1612}
1613
1614/* Errors may be set multiple times during parsing or bit encoding
1615 (particularly in the Neon bits), but usually the earliest error which is set
1616 will be the most meaningful. Avoid overwriting it with later (cascading)
1617 errors by calling this function. */
1618
1619static void
1620first_error (const char *err)
1621{
1622 if (!inst.error)
1623 inst.error = err;
1624}
1625
1626/* Parse a single type, e.g. ".s32", leading period included. */
1627static int
1628parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1629{
1630 char *str = *ccp;
1631 struct neon_type optype;
1632
1633 if (*str == '.')
1634 {
1635 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1636 {
1637 if (optype.elems == 1)
1638 *vectype = optype.el[0];
1639 else
1640 {
1641 first_error (_("only one type should be specified for operand"));
1642 return FAIL;
1643 }
1644 }
dcbf9037 1645 else
477330fc
RM
1646 {
1647 first_error (_("vector type expected"));
1648 return FAIL;
1649 }
dcbf9037
JB
1650 }
1651 else
1652 return FAIL;
5f4273c7 1653
dcbf9037 1654 *ccp = str;
5f4273c7 1655
dcbf9037
JB
1656 return SUCCESS;
1657}
1658
1659/* Special meanings for indices (which have a range of 0-7), which will fit into
1660 a 4-bit integer. */
1661
1662#define NEON_ALL_LANES 15
1663#define NEON_INTERLEAVE_LANES 14
1664
5ee91343
AV
1665/* Record a use of the given feature. */
1666static void
1667record_feature_use (const arm_feature_set *feature)
1668{
1669 if (thumb_mode)
1670 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1671 else
1672 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1673}
1674
1675/* If the given feature available in the selected CPU, mark it as used.
1676 Returns TRUE iff feature is available. */
1677static bfd_boolean
1678mark_feature_used (const arm_feature_set *feature)
1679{
886e1c73
AV
1680
1681 /* Do not support the use of MVE only instructions when in auto-detection or
1682 -march=all. */
1683 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1684 && ARM_CPU_IS_ANY (cpu_variant))
1685 {
1686 first_error (BAD_MVE_AUTO);
1687 return FALSE;
1688 }
5ee91343
AV
1689 /* Ensure the option is valid on the current architecture. */
1690 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1691 return FALSE;
1692
1693 /* Add the appropriate architecture feature for the barrier option used.
1694 */
1695 record_feature_use (feature);
1696
1697 return TRUE;
1698}
1699
dcbf9037
JB
1700/* Parse either a register or a scalar, with an optional type. Return the
1701 register number, and optionally fill in the actual type of the register
1702 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1703 type/index information in *TYPEINFO. */
1704
1705static int
1706parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1707 enum arm_reg_type *rtype,
1708 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1709{
1710 char *str = *ccp;
1711 struct reg_entry *reg = arm_reg_parse_multi (&str);
1712 struct neon_typed_alias atype;
1713 struct neon_type_el parsetype;
1714
1715 atype.defined = 0;
1716 atype.index = -1;
1717 atype.eltype.type = NT_invtype;
1718 atype.eltype.size = -1;
1719
1720 /* Try alternate syntax for some types of register. Note these are mutually
1721 exclusive with the Neon syntax extensions. */
1722 if (reg == NULL)
1723 {
1724 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1725 if (altreg != FAIL)
477330fc 1726 *ccp = str;
dcbf9037 1727 if (typeinfo)
477330fc 1728 *typeinfo = atype;
dcbf9037
JB
1729 return altreg;
1730 }
1731
037e8744
JB
1732 /* Undo polymorphism when a set of register types may be accepted. */
1733 if ((type == REG_TYPE_NDQ
1734 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1735 || (type == REG_TYPE_VFSD
477330fc 1736 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1737 || (type == REG_TYPE_NSDQ
477330fc
RM
1738 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1739 || reg->type == REG_TYPE_NQ))
dec41383
JW
1740 || (type == REG_TYPE_NSD
1741 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1742 || (type == REG_TYPE_MMXWC
1743 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1744 type = (enum arm_reg_type) reg->type;
dcbf9037 1745
5ee91343
AV
1746 if (type == REG_TYPE_MQ)
1747 {
1748 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1749 return FAIL;
1750
1751 if (!reg || reg->type != REG_TYPE_NQ)
1752 return FAIL;
1753
1754 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1755 {
1756 first_error (_("expected MVE register [q0..q7]"));
1757 return FAIL;
1758 }
1759 type = REG_TYPE_NQ;
1760 }
1761 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1762 && (type == REG_TYPE_NQ))
1763 return FAIL;
1764
1765
dcbf9037
JB
1766 if (type != reg->type)
1767 return FAIL;
1768
1769 if (reg->neon)
1770 atype = *reg->neon;
5f4273c7 1771
dcbf9037
JB
1772 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1773 {
1774 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1775 {
1776 first_error (_("can't redefine type for operand"));
1777 return FAIL;
1778 }
dcbf9037
JB
1779 atype.defined |= NTA_HASTYPE;
1780 atype.eltype = parsetype;
1781 }
5f4273c7 1782
dcbf9037
JB
1783 if (skip_past_char (&str, '[') == SUCCESS)
1784 {
dec41383
JW
1785 if (type != REG_TYPE_VFD
1786 && !(type == REG_TYPE_VFS
57785aa2
AV
1787 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1788 && !(type == REG_TYPE_NQ
1789 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1790 {
57785aa2
AV
1791 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1792 first_error (_("only D and Q registers may be indexed"));
1793 else
1794 first_error (_("only D registers may be indexed"));
477330fc
RM
1795 return FAIL;
1796 }
5f4273c7 1797
dcbf9037 1798 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1799 {
1800 first_error (_("can't change index for operand"));
1801 return FAIL;
1802 }
dcbf9037
JB
1803
1804 atype.defined |= NTA_HASINDEX;
1805
1806 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1807 atype.index = NEON_ALL_LANES;
dcbf9037 1808 else
477330fc
RM
1809 {
1810 expressionS exp;
dcbf9037 1811
477330fc 1812 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1813
477330fc
RM
1814 if (exp.X_op != O_constant)
1815 {
1816 first_error (_("constant expression required"));
1817 return FAIL;
1818 }
dcbf9037 1819
477330fc
RM
1820 if (skip_past_char (&str, ']') == FAIL)
1821 return FAIL;
dcbf9037 1822
477330fc
RM
1823 atype.index = exp.X_add_number;
1824 }
dcbf9037 1825 }
5f4273c7 1826
dcbf9037
JB
1827 if (typeinfo)
1828 *typeinfo = atype;
5f4273c7 1829
dcbf9037
JB
1830 if (rtype)
1831 *rtype = type;
5f4273c7 1832
dcbf9037 1833 *ccp = str;
5f4273c7 1834
dcbf9037
JB
1835 return reg->number;
1836}
1837
efd6b359 1838/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1839 - If RTYPE is non-zero, return the (possibly restricted) type of the
1840 register (e.g. Neon double or quad reg when either has been requested).
1841 - If this is a Neon vector type with additional type information, fill
1842 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1843 This function will fault on encountering a scalar. */
dcbf9037
JB
1844
1845static int
1846arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1847 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1848{
1849 struct neon_typed_alias atype;
1850 char *str = *ccp;
1851 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1852
1853 if (reg == FAIL)
1854 return FAIL;
1855
0855e32b
NS
1856 /* Do not allow regname(... to parse as a register. */
1857 if (*str == '(')
1858 return FAIL;
1859
dcbf9037
JB
1860 /* Do not allow a scalar (reg+index) to parse as a register. */
1861 if ((atype.defined & NTA_HASINDEX) != 0)
1862 {
1863 first_error (_("register operand expected, but got scalar"));
1864 return FAIL;
1865 }
1866
1867 if (vectype)
1868 *vectype = atype.eltype;
1869
1870 *ccp = str;
1871
1872 return reg;
1873}
1874
1875#define NEON_SCALAR_REG(X) ((X) >> 4)
1876#define NEON_SCALAR_INDEX(X) ((X) & 15)
1877
5287ad62
JB
1878/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1879 have enough information to be able to do a good job bounds-checking. So, we
1880 just do easy checks here, and do further checks later. */
1881
1882static int
57785aa2
AV
1883parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1884 arm_reg_type reg_type)
5287ad62 1885{
dcbf9037 1886 int reg;
5287ad62 1887 char *str = *ccp;
dcbf9037 1888 struct neon_typed_alias atype;
57785aa2 1889 unsigned reg_size;
5f4273c7 1890
dec41383 1891 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1892
57785aa2
AV
1893 switch (reg_type)
1894 {
1895 case REG_TYPE_VFS:
1896 reg_size = 32;
1897 break;
1898 case REG_TYPE_VFD:
1899 reg_size = 64;
1900 break;
1901 case REG_TYPE_MQ:
1902 reg_size = 128;
1903 break;
1904 default:
1905 gas_assert (0);
1906 return FAIL;
1907 }
1908
dcbf9037 1909 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1910 return FAIL;
5f4273c7 1911
57785aa2 1912 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1913 {
dcbf9037 1914 first_error (_("scalar must have an index"));
5287ad62
JB
1915 return FAIL;
1916 }
57785aa2 1917 else if (atype.index >= reg_size / elsize)
5287ad62 1918 {
dcbf9037 1919 first_error (_("scalar index out of range"));
5287ad62
JB
1920 return FAIL;
1921 }
5f4273c7 1922
dcbf9037
JB
1923 if (type)
1924 *type = atype.eltype;
5f4273c7 1925
5287ad62 1926 *ccp = str;
5f4273c7 1927
dcbf9037 1928 return reg * 16 + atype.index;
5287ad62
JB
1929}
1930
4b5a202f
AV
1931/* Types of registers in a list. */
1932
1933enum reg_list_els
1934{
1935 REGLIST_RN,
1936 REGLIST_CLRM,
1937 REGLIST_VFP_S,
efd6b359 1938 REGLIST_VFP_S_VPR,
4b5a202f 1939 REGLIST_VFP_D,
efd6b359 1940 REGLIST_VFP_D_VPR,
4b5a202f
AV
1941 REGLIST_NEON_D
1942};
1943
c19d1205 1944/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1945
c19d1205 1946static long
4b5a202f 1947parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1948{
4b5a202f
AV
1949 char *str = *strp;
1950 long range = 0;
1951 int another_range;
1952
1953 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1954
c19d1205
ZW
1955 /* We come back here if we get ranges concatenated by '+' or '|'. */
1956 do
6057a28f 1957 {
477330fc
RM
1958 skip_whitespace (str);
1959
c19d1205 1960 another_range = 0;
a737bd4d 1961
c19d1205
ZW
1962 if (*str == '{')
1963 {
1964 int in_range = 0;
1965 int cur_reg = -1;
a737bd4d 1966
c19d1205
ZW
1967 str++;
1968 do
1969 {
1970 int reg;
4b5a202f
AV
1971 const char apsr_str[] = "apsr";
1972 int apsr_str_len = strlen (apsr_str);
6057a28f 1973
a65b5de6 1974 reg = arm_reg_parse (&str, REG_TYPE_RN);
4b5a202f 1975 if (etype == REGLIST_CLRM)
c19d1205 1976 {
4b5a202f
AV
1977 if (reg == REG_SP || reg == REG_PC)
1978 reg = FAIL;
1979 else if (reg == FAIL
1980 && !strncasecmp (str, apsr_str, apsr_str_len)
1981 && !ISALPHA (*(str + apsr_str_len)))
1982 {
1983 reg = 15;
1984 str += apsr_str_len;
1985 }
1986
1987 if (reg == FAIL)
1988 {
1989 first_error (_("r0-r12, lr or APSR expected"));
1990 return FAIL;
1991 }
1992 }
1993 else /* etype == REGLIST_RN. */
1994 {
1995 if (reg == FAIL)
1996 {
1997 first_error (_(reg_expected_msgs[REGLIST_RN]));
1998 return FAIL;
1999 }
c19d1205 2000 }
a737bd4d 2001
c19d1205
ZW
2002 if (in_range)
2003 {
2004 int i;
a737bd4d 2005
c19d1205
ZW
2006 if (reg <= cur_reg)
2007 {
dcbf9037 2008 first_error (_("bad range in register list"));
c19d1205
ZW
2009 return FAIL;
2010 }
40a18ebd 2011
c19d1205
ZW
2012 for (i = cur_reg + 1; i < reg; i++)
2013 {
2014 if (range & (1 << i))
2015 as_tsktsk
2016 (_("Warning: duplicated register (r%d) in register list"),
2017 i);
2018 else
2019 range |= 1 << i;
2020 }
2021 in_range = 0;
2022 }
a737bd4d 2023
c19d1205
ZW
2024 if (range & (1 << reg))
2025 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2026 reg);
2027 else if (reg <= cur_reg)
2028 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 2029
c19d1205
ZW
2030 range |= 1 << reg;
2031 cur_reg = reg;
2032 }
2033 while (skip_past_comma (&str) != FAIL
2034 || (in_range = 1, *str++ == '-'));
2035 str--;
a737bd4d 2036
d996d970 2037 if (skip_past_char (&str, '}') == FAIL)
c19d1205 2038 {
dcbf9037 2039 first_error (_("missing `}'"));
c19d1205
ZW
2040 return FAIL;
2041 }
2042 }
4b5a202f 2043 else if (etype == REGLIST_RN)
c19d1205 2044 {
91d6fa6a 2045 expressionS exp;
40a18ebd 2046
91d6fa6a 2047 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 2048 return FAIL;
40a18ebd 2049
91d6fa6a 2050 if (exp.X_op == O_constant)
c19d1205 2051 {
91d6fa6a
NC
2052 if (exp.X_add_number
2053 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
2054 {
2055 inst.error = _("invalid register mask");
2056 return FAIL;
2057 }
a737bd4d 2058
91d6fa6a 2059 if ((range & exp.X_add_number) != 0)
c19d1205 2060 {
91d6fa6a 2061 int regno = range & exp.X_add_number;
a737bd4d 2062
c19d1205
ZW
2063 regno &= -regno;
2064 regno = (1 << regno) - 1;
2065 as_tsktsk
2066 (_("Warning: duplicated register (r%d) in register list"),
2067 regno);
2068 }
a737bd4d 2069
91d6fa6a 2070 range |= exp.X_add_number;
c19d1205
ZW
2071 }
2072 else
2073 {
e2b0ab59 2074 if (inst.relocs[0].type != 0)
c19d1205
ZW
2075 {
2076 inst.error = _("expression too complex");
2077 return FAIL;
2078 }
a737bd4d 2079
e2b0ab59
AV
2080 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2081 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2082 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
2083 }
2084 }
a737bd4d 2085
c19d1205
ZW
2086 if (*str == '|' || *str == '+')
2087 {
2088 str++;
2089 another_range = 1;
2090 }
a737bd4d 2091 }
c19d1205 2092 while (another_range);
a737bd4d 2093
c19d1205
ZW
2094 *strp = str;
2095 return range;
a737bd4d
NC
2096}
2097
c19d1205
ZW
2098/* Parse a VFP register list. If the string is invalid return FAIL.
2099 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
2100 register. Parses registers of type ETYPE.
2101 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2102 - Q registers can be used to specify pairs of D registers
2103 - { } can be omitted from around a singleton register list
477330fc
RM
2104 FIXME: This is not implemented, as it would require backtracking in
2105 some cases, e.g.:
2106 vtbl.8 d3,d4,d5
2107 This could be done (the meaning isn't really ambiguous), but doesn't
2108 fit in well with the current parsing framework.
dcbf9037
JB
2109 - 32 D registers may be used (also true for VFPv3).
2110 FIXME: Types are ignored in these register lists, which is probably a
2111 bug. */
6057a28f 2112
c19d1205 2113static int
efd6b359
AV
2114parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2115 bfd_boolean *partial_match)
6057a28f 2116{
037e8744 2117 char *str = *ccp;
c19d1205
ZW
2118 int base_reg;
2119 int new_base;
21d799b5 2120 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2121 int max_regs = 0;
c19d1205
ZW
2122 int count = 0;
2123 int warned = 0;
2124 unsigned long mask = 0;
a737bd4d 2125 int i;
efd6b359
AV
2126 bfd_boolean vpr_seen = FALSE;
2127 bfd_boolean expect_vpr =
2128 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2129
477330fc 2130 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2131 {
2132 inst.error = _("expecting {");
2133 return FAIL;
2134 }
6057a28f 2135
5287ad62 2136 switch (etype)
c19d1205 2137 {
5287ad62 2138 case REGLIST_VFP_S:
efd6b359 2139 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2140 regtype = REG_TYPE_VFS;
2141 max_regs = 32;
5287ad62 2142 break;
5f4273c7 2143
5287ad62 2144 case REGLIST_VFP_D:
efd6b359 2145 case REGLIST_VFP_D_VPR:
5287ad62 2146 regtype = REG_TYPE_VFD;
b7fc2769 2147 break;
5f4273c7 2148
b7fc2769
JB
2149 case REGLIST_NEON_D:
2150 regtype = REG_TYPE_NDQ;
2151 break;
4b5a202f
AV
2152
2153 default:
2154 gas_assert (0);
b7fc2769
JB
2155 }
2156
efd6b359 2157 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2158 {
b1cc4aeb
PB
2159 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2160 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2161 {
2162 max_regs = 32;
2163 if (thumb_mode)
2164 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2165 fpu_vfp_ext_d32);
2166 else
2167 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2168 fpu_vfp_ext_d32);
2169 }
5287ad62 2170 else
477330fc 2171 max_regs = 16;
c19d1205 2172 }
6057a28f 2173
c19d1205 2174 base_reg = max_regs;
efd6b359 2175 *partial_match = FALSE;
a737bd4d 2176
c19d1205
ZW
2177 do
2178 {
5287ad62 2179 int setmask = 1, addregs = 1;
efd6b359
AV
2180 const char vpr_str[] = "vpr";
2181 int vpr_str_len = strlen (vpr_str);
dcbf9037 2182
037e8744 2183 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2184
efd6b359
AV
2185 if (expect_vpr)
2186 {
2187 if (new_base == FAIL
2188 && !strncasecmp (str, vpr_str, vpr_str_len)
2189 && !ISALPHA (*(str + vpr_str_len))
2190 && !vpr_seen)
2191 {
2192 vpr_seen = TRUE;
2193 str += vpr_str_len;
2194 if (count == 0)
2195 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2196 }
2197 else if (vpr_seen)
2198 {
2199 first_error (_("VPR expected last"));
2200 return FAIL;
2201 }
2202 else if (new_base == FAIL)
2203 {
2204 if (regtype == REG_TYPE_VFS)
2205 first_error (_("VFP single precision register or VPR "
2206 "expected"));
2207 else /* regtype == REG_TYPE_VFD. */
2208 first_error (_("VFP/Neon double precision register or VPR "
2209 "expected"));
2210 return FAIL;
2211 }
2212 }
2213 else if (new_base == FAIL)
a737bd4d 2214 {
dcbf9037 2215 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2216 return FAIL;
2217 }
5f4273c7 2218
efd6b359
AV
2219 *partial_match = TRUE;
2220 if (vpr_seen)
2221 continue;
2222
b7fc2769 2223 if (new_base >= max_regs)
477330fc
RM
2224 {
2225 first_error (_("register out of range in list"));
2226 return FAIL;
2227 }
5f4273c7 2228
5287ad62
JB
2229 /* Note: a value of 2 * n is returned for the register Q<n>. */
2230 if (regtype == REG_TYPE_NQ)
477330fc
RM
2231 {
2232 setmask = 3;
2233 addregs = 2;
2234 }
5287ad62 2235
c19d1205
ZW
2236 if (new_base < base_reg)
2237 base_reg = new_base;
a737bd4d 2238
5287ad62 2239 if (mask & (setmask << new_base))
c19d1205 2240 {
dcbf9037 2241 first_error (_("invalid register list"));
c19d1205 2242 return FAIL;
a737bd4d 2243 }
a737bd4d 2244
efd6b359 2245 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2246 {
2247 as_tsktsk (_("register list not in ascending order"));
2248 warned = 1;
2249 }
0bbf2aa4 2250
5287ad62
JB
2251 mask |= setmask << new_base;
2252 count += addregs;
0bbf2aa4 2253
037e8744 2254 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2255 {
2256 int high_range;
0bbf2aa4 2257
037e8744 2258 str++;
0bbf2aa4 2259
037e8744 2260 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2261 == FAIL)
c19d1205
ZW
2262 {
2263 inst.error = gettext (reg_expected_msgs[regtype]);
2264 return FAIL;
2265 }
0bbf2aa4 2266
477330fc
RM
2267 if (high_range >= max_regs)
2268 {
2269 first_error (_("register out of range in list"));
2270 return FAIL;
2271 }
b7fc2769 2272
477330fc
RM
2273 if (regtype == REG_TYPE_NQ)
2274 high_range = high_range + 1;
5287ad62 2275
c19d1205
ZW
2276 if (high_range <= new_base)
2277 {
2278 inst.error = _("register range not in ascending order");
2279 return FAIL;
2280 }
0bbf2aa4 2281
5287ad62 2282 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2283 {
5287ad62 2284 if (mask & (setmask << new_base))
0bbf2aa4 2285 {
c19d1205
ZW
2286 inst.error = _("invalid register list");
2287 return FAIL;
0bbf2aa4 2288 }
c19d1205 2289
5287ad62
JB
2290 mask |= setmask << new_base;
2291 count += addregs;
0bbf2aa4 2292 }
0bbf2aa4 2293 }
0bbf2aa4 2294 }
037e8744 2295 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2296
037e8744 2297 str++;
0bbf2aa4 2298
c19d1205 2299 /* Sanity check -- should have raised a parse error above. */
efd6b359 2300 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2301 abort ();
2302
2303 *pbase = base_reg;
2304
efd6b359
AV
2305 if (expect_vpr && !vpr_seen)
2306 {
2307 first_error (_("VPR expected last"));
2308 return FAIL;
2309 }
2310
c19d1205
ZW
2311 /* Final test -- the registers must be consecutive. */
2312 mask >>= base_reg;
2313 for (i = 0; i < count; i++)
2314 {
2315 if ((mask & (1u << i)) == 0)
2316 {
2317 inst.error = _("non-contiguous register range");
2318 return FAIL;
2319 }
2320 }
2321
037e8744
JB
2322 *ccp = str;
2323
c19d1205 2324 return count;
b99bd4ef
NC
2325}
2326
dcbf9037
JB
2327/* True if two alias types are the same. */
2328
c921be7d 2329static bfd_boolean
dcbf9037
JB
2330neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2331{
2332 if (!a && !b)
c921be7d 2333 return TRUE;
5f4273c7 2334
dcbf9037 2335 if (!a || !b)
c921be7d 2336 return FALSE;
dcbf9037
JB
2337
2338 if (a->defined != b->defined)
c921be7d 2339 return FALSE;
5f4273c7 2340
dcbf9037
JB
2341 if ((a->defined & NTA_HASTYPE) != 0
2342 && (a->eltype.type != b->eltype.type
477330fc 2343 || a->eltype.size != b->eltype.size))
c921be7d 2344 return FALSE;
dcbf9037
JB
2345
2346 if ((a->defined & NTA_HASINDEX) != 0
2347 && (a->index != b->index))
c921be7d 2348 return FALSE;
5f4273c7 2349
c921be7d 2350 return TRUE;
dcbf9037
JB
2351}
2352
5287ad62
JB
2353/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2354 The base register is put in *PBASE.
dcbf9037 2355 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2356 the return value.
2357 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2358 Bits [6:5] encode the list length (minus one).
2359 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2360
5287ad62 2361#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2362#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2363#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2364
2365static int
dcbf9037 2366parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2367 int mve,
477330fc 2368 struct neon_type_el *eltype)
5287ad62
JB
2369{
2370 char *ptr = *str;
2371 int base_reg = -1;
2372 int reg_incr = -1;
2373 int count = 0;
2374 int lane = -1;
2375 int leading_brace = 0;
2376 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2377 const char *const incr_error = mve ? _("register stride must be 1") :
2378 _("register stride must be 1 or 2");
20203fb9 2379 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2380 struct neon_typed_alias firsttype;
f85d59c3
KT
2381 firsttype.defined = 0;
2382 firsttype.eltype.type = NT_invtype;
2383 firsttype.eltype.size = -1;
2384 firsttype.index = -1;
5f4273c7 2385
5287ad62
JB
2386 if (skip_past_char (&ptr, '{') == SUCCESS)
2387 leading_brace = 1;
5f4273c7 2388
5287ad62
JB
2389 do
2390 {
dcbf9037 2391 struct neon_typed_alias atype;
35c228db
AV
2392 if (mve)
2393 rtype = REG_TYPE_MQ;
dcbf9037
JB
2394 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2395
5287ad62 2396 if (getreg == FAIL)
477330fc
RM
2397 {
2398 first_error (_(reg_expected_msgs[rtype]));
2399 return FAIL;
2400 }
5f4273c7 2401
5287ad62 2402 if (base_reg == -1)
477330fc
RM
2403 {
2404 base_reg = getreg;
2405 if (rtype == REG_TYPE_NQ)
2406 {
2407 reg_incr = 1;
2408 }
2409 firsttype = atype;
2410 }
5287ad62 2411 else if (reg_incr == -1)
477330fc
RM
2412 {
2413 reg_incr = getreg - base_reg;
2414 if (reg_incr < 1 || reg_incr > 2)
2415 {
2416 first_error (_(incr_error));
2417 return FAIL;
2418 }
2419 }
5287ad62 2420 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2421 {
2422 first_error (_(incr_error));
2423 return FAIL;
2424 }
dcbf9037 2425
c921be7d 2426 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2427 {
2428 first_error (_(type_error));
2429 return FAIL;
2430 }
5f4273c7 2431
5287ad62 2432 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2433 modes. */
5287ad62 2434 if (ptr[0] == '-')
477330fc
RM
2435 {
2436 struct neon_typed_alias htype;
2437 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2438 if (lane == -1)
2439 lane = NEON_INTERLEAVE_LANES;
2440 else if (lane != NEON_INTERLEAVE_LANES)
2441 {
2442 first_error (_(type_error));
2443 return FAIL;
2444 }
2445 if (reg_incr == -1)
2446 reg_incr = 1;
2447 else if (reg_incr != 1)
2448 {
2449 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2450 return FAIL;
2451 }
2452 ptr++;
2453 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2454 if (hireg == FAIL)
2455 {
2456 first_error (_(reg_expected_msgs[rtype]));
2457 return FAIL;
2458 }
2459 if (! neon_alias_types_same (&htype, &firsttype))
2460 {
2461 first_error (_(type_error));
2462 return FAIL;
2463 }
2464 count += hireg + dregs - getreg;
2465 continue;
2466 }
5f4273c7 2467
5287ad62
JB
2468 /* If we're using Q registers, we can't use [] or [n] syntax. */
2469 if (rtype == REG_TYPE_NQ)
477330fc
RM
2470 {
2471 count += 2;
2472 continue;
2473 }
5f4273c7 2474
dcbf9037 2475 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2476 {
2477 if (lane == -1)
2478 lane = atype.index;
2479 else if (lane != atype.index)
2480 {
2481 first_error (_(type_error));
2482 return FAIL;
2483 }
2484 }
5287ad62 2485 else if (lane == -1)
477330fc 2486 lane = NEON_INTERLEAVE_LANES;
5287ad62 2487 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2488 {
2489 first_error (_(type_error));
2490 return FAIL;
2491 }
5287ad62
JB
2492 count++;
2493 }
2494 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2495
5287ad62
JB
2496 /* No lane set by [x]. We must be interleaving structures. */
2497 if (lane == -1)
2498 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2499
5287ad62 2500 /* Sanity check. */
35c228db 2501 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2502 || (count > 1 && reg_incr == -1))
2503 {
dcbf9037 2504 first_error (_("error parsing element/structure list"));
5287ad62
JB
2505 return FAIL;
2506 }
2507
2508 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2509 {
dcbf9037 2510 first_error (_("expected }"));
5287ad62
JB
2511 return FAIL;
2512 }
5f4273c7 2513
5287ad62
JB
2514 if (reg_incr == -1)
2515 reg_incr = 1;
2516
dcbf9037
JB
2517 if (eltype)
2518 *eltype = firsttype.eltype;
2519
5287ad62
JB
2520 *pbase = base_reg;
2521 *str = ptr;
5f4273c7 2522
5287ad62
JB
2523 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2524}
2525
c19d1205
ZW
2526/* Parse an explicit relocation suffix on an expression. This is
2527 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2528 arm_reloc_hsh contains no entries, so this function can only
2529 succeed if there is no () after the word. Returns -1 on error,
2530 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2531
c19d1205
ZW
2532static int
2533parse_reloc (char **str)
b99bd4ef 2534{
c19d1205
ZW
2535 struct reloc_entry *r;
2536 char *p, *q;
b99bd4ef 2537
c19d1205
ZW
2538 if (**str != '(')
2539 return BFD_RELOC_UNUSED;
b99bd4ef 2540
c19d1205
ZW
2541 p = *str + 1;
2542 q = p;
2543
2544 while (*q && *q != ')' && *q != ',')
2545 q++;
2546 if (*q != ')')
2547 return -1;
2548
21d799b5
NC
2549 if ((r = (struct reloc_entry *)
2550 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2551 return -1;
2552
2553 *str = q + 1;
2554 return r->reloc;
b99bd4ef
NC
2555}
2556
c19d1205
ZW
2557/* Directives: register aliases. */
2558
dcbf9037 2559static struct reg_entry *
90ec0d68 2560insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2561{
d3ce72d0 2562 struct reg_entry *new_reg;
c19d1205 2563 const char *name;
b99bd4ef 2564
d3ce72d0 2565 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2566 {
d3ce72d0 2567 if (new_reg->builtin)
c19d1205 2568 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2569
c19d1205
ZW
2570 /* Only warn about a redefinition if it's not defined as the
2571 same register. */
d3ce72d0 2572 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2573 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2574
d929913e 2575 return NULL;
c19d1205 2576 }
b99bd4ef 2577
c19d1205 2578 name = xstrdup (str);
325801bd 2579 new_reg = XNEW (struct reg_entry);
b99bd4ef 2580
d3ce72d0
NC
2581 new_reg->name = name;
2582 new_reg->number = number;
2583 new_reg->type = type;
2584 new_reg->builtin = FALSE;
2585 new_reg->neon = NULL;
b99bd4ef 2586
d3ce72d0 2587 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2588 abort ();
5f4273c7 2589
d3ce72d0 2590 return new_reg;
dcbf9037
JB
2591}
2592
2593static void
2594insert_neon_reg_alias (char *str, int number, int type,
477330fc 2595 struct neon_typed_alias *atype)
dcbf9037
JB
2596{
2597 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2598
dcbf9037
JB
2599 if (!reg)
2600 {
2601 first_error (_("attempt to redefine typed alias"));
2602 return;
2603 }
5f4273c7 2604
dcbf9037
JB
2605 if (atype)
2606 {
325801bd 2607 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2608 *reg->neon = *atype;
2609 }
c19d1205 2610}
b99bd4ef 2611
c19d1205 2612/* Look for the .req directive. This is of the form:
b99bd4ef 2613
c19d1205 2614 new_register_name .req existing_register_name
b99bd4ef 2615
c19d1205 2616 If we find one, or if it looks sufficiently like one that we want to
d929913e 2617 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2618
d929913e 2619static bfd_boolean
c19d1205
ZW
2620create_register_alias (char * newname, char *p)
2621{
2622 struct reg_entry *old;
2623 char *oldname, *nbuf;
2624 size_t nlen;
b99bd4ef 2625
c19d1205
ZW
2626 /* The input scrubber ensures that whitespace after the mnemonic is
2627 collapsed to single spaces. */
2628 oldname = p;
2629 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2630 return FALSE;
b99bd4ef 2631
c19d1205
ZW
2632 oldname += 6;
2633 if (*oldname == '\0')
d929913e 2634 return FALSE;
b99bd4ef 2635
21d799b5 2636 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2637 if (!old)
b99bd4ef 2638 {
c19d1205 2639 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2640 return TRUE;
b99bd4ef
NC
2641 }
2642
c19d1205
ZW
2643 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2644 the desired alias name, and p points to its end. If not, then
2645 the desired alias name is in the global original_case_string. */
2646#ifdef TC_CASE_SENSITIVE
2647 nlen = p - newname;
2648#else
2649 newname = original_case_string;
2650 nlen = strlen (newname);
2651#endif
b99bd4ef 2652
29a2809e 2653 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2654
c19d1205
ZW
2655 /* Create aliases under the new name as stated; an all-lowercase
2656 version of the new name; and an all-uppercase version of the new
2657 name. */
d929913e
NC
2658 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2659 {
2660 for (p = nbuf; *p; p++)
2661 *p = TOUPPER (*p);
c19d1205 2662
d929913e
NC
2663 if (strncmp (nbuf, newname, nlen))
2664 {
2665 /* If this attempt to create an additional alias fails, do not bother
2666 trying to create the all-lower case alias. We will fail and issue
2667 a second, duplicate error message. This situation arises when the
2668 programmer does something like:
2669 foo .req r0
2670 Foo .req r1
2671 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2672 the artificial FOO alias because it has already been created by the
d929913e
NC
2673 first .req. */
2674 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2675 {
2676 free (nbuf);
2677 return TRUE;
2678 }
d929913e 2679 }
c19d1205 2680
d929913e
NC
2681 for (p = nbuf; *p; p++)
2682 *p = TOLOWER (*p);
c19d1205 2683
d929913e
NC
2684 if (strncmp (nbuf, newname, nlen))
2685 insert_reg_alias (nbuf, old->number, old->type);
2686 }
c19d1205 2687
e1fa0163 2688 free (nbuf);
d929913e 2689 return TRUE;
b99bd4ef
NC
2690}
2691
dcbf9037
JB
2692/* Create a Neon typed/indexed register alias using directives, e.g.:
2693 X .dn d5.s32[1]
2694 Y .qn 6.s16
2695 Z .dn d7
2696 T .dn Z[0]
2697 These typed registers can be used instead of the types specified after the
2698 Neon mnemonic, so long as all operands given have types. Types can also be
2699 specified directly, e.g.:
5f4273c7 2700 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2701
c921be7d 2702static bfd_boolean
dcbf9037
JB
2703create_neon_reg_alias (char *newname, char *p)
2704{
2705 enum arm_reg_type basetype;
2706 struct reg_entry *basereg;
2707 struct reg_entry mybasereg;
2708 struct neon_type ntype;
2709 struct neon_typed_alias typeinfo;
12d6b0b7 2710 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2711 int namelen;
5f4273c7 2712
dcbf9037
JB
2713 typeinfo.defined = 0;
2714 typeinfo.eltype.type = NT_invtype;
2715 typeinfo.eltype.size = -1;
2716 typeinfo.index = -1;
5f4273c7 2717
dcbf9037 2718 nameend = p;
5f4273c7 2719
dcbf9037
JB
2720 if (strncmp (p, " .dn ", 5) == 0)
2721 basetype = REG_TYPE_VFD;
2722 else if (strncmp (p, " .qn ", 5) == 0)
2723 basetype = REG_TYPE_NQ;
2724 else
c921be7d 2725 return FALSE;
5f4273c7 2726
dcbf9037 2727 p += 5;
5f4273c7 2728
dcbf9037 2729 if (*p == '\0')
c921be7d 2730 return FALSE;
5f4273c7 2731
dcbf9037
JB
2732 basereg = arm_reg_parse_multi (&p);
2733
2734 if (basereg && basereg->type != basetype)
2735 {
2736 as_bad (_("bad type for register"));
c921be7d 2737 return FALSE;
dcbf9037
JB
2738 }
2739
2740 if (basereg == NULL)
2741 {
2742 expressionS exp;
2743 /* Try parsing as an integer. */
2744 my_get_expression (&exp, &p, GE_NO_PREFIX);
2745 if (exp.X_op != O_constant)
477330fc
RM
2746 {
2747 as_bad (_("expression must be constant"));
2748 return FALSE;
2749 }
dcbf9037
JB
2750 basereg = &mybasereg;
2751 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2752 : exp.X_add_number;
dcbf9037
JB
2753 basereg->neon = 0;
2754 }
2755
2756 if (basereg->neon)
2757 typeinfo = *basereg->neon;
2758
2759 if (parse_neon_type (&ntype, &p) == SUCCESS)
2760 {
2761 /* We got a type. */
2762 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2763 {
2764 as_bad (_("can't redefine the type of a register alias"));
2765 return FALSE;
2766 }
5f4273c7 2767
dcbf9037
JB
2768 typeinfo.defined |= NTA_HASTYPE;
2769 if (ntype.elems != 1)
477330fc
RM
2770 {
2771 as_bad (_("you must specify a single type only"));
2772 return FALSE;
2773 }
dcbf9037
JB
2774 typeinfo.eltype = ntype.el[0];
2775 }
5f4273c7 2776
dcbf9037
JB
2777 if (skip_past_char (&p, '[') == SUCCESS)
2778 {
2779 expressionS exp;
2780 /* We got a scalar index. */
5f4273c7 2781
dcbf9037 2782 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2783 {
2784 as_bad (_("can't redefine the index of a scalar alias"));
2785 return FALSE;
2786 }
5f4273c7 2787
dcbf9037 2788 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2789
dcbf9037 2790 if (exp.X_op != O_constant)
477330fc
RM
2791 {
2792 as_bad (_("scalar index must be constant"));
2793 return FALSE;
2794 }
5f4273c7 2795
dcbf9037
JB
2796 typeinfo.defined |= NTA_HASINDEX;
2797 typeinfo.index = exp.X_add_number;
5f4273c7 2798
dcbf9037 2799 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2800 {
2801 as_bad (_("expecting ]"));
2802 return FALSE;
2803 }
dcbf9037
JB
2804 }
2805
15735687
NS
2806 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2807 the desired alias name, and p points to its end. If not, then
2808 the desired alias name is in the global original_case_string. */
2809#ifdef TC_CASE_SENSITIVE
dcbf9037 2810 namelen = nameend - newname;
15735687
NS
2811#else
2812 newname = original_case_string;
2813 namelen = strlen (newname);
2814#endif
2815
29a2809e 2816 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2817
dcbf9037 2818 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2819 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2820
dcbf9037
JB
2821 /* Insert name in all uppercase. */
2822 for (p = namebuf; *p; p++)
2823 *p = TOUPPER (*p);
5f4273c7 2824
dcbf9037
JB
2825 if (strncmp (namebuf, newname, namelen))
2826 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2827 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2828
dcbf9037
JB
2829 /* Insert name in all lowercase. */
2830 for (p = namebuf; *p; p++)
2831 *p = TOLOWER (*p);
5f4273c7 2832
dcbf9037
JB
2833 if (strncmp (namebuf, newname, namelen))
2834 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2835 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2836
e1fa0163 2837 free (namebuf);
c921be7d 2838 return TRUE;
dcbf9037
JB
2839}
2840
c19d1205
ZW
2841/* Should never be called, as .req goes between the alias and the
2842 register name, not at the beginning of the line. */
c921be7d 2843
b99bd4ef 2844static void
c19d1205 2845s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2846{
c19d1205
ZW
2847 as_bad (_("invalid syntax for .req directive"));
2848}
b99bd4ef 2849
dcbf9037
JB
2850static void
2851s_dn (int a ATTRIBUTE_UNUSED)
2852{
2853 as_bad (_("invalid syntax for .dn directive"));
2854}
2855
2856static void
2857s_qn (int a ATTRIBUTE_UNUSED)
2858{
2859 as_bad (_("invalid syntax for .qn directive"));
2860}
2861
c19d1205
ZW
2862/* The .unreq directive deletes an alias which was previously defined
2863 by .req. For example:
b99bd4ef 2864
c19d1205
ZW
2865 my_alias .req r11
2866 .unreq my_alias */
b99bd4ef
NC
2867
2868static void
c19d1205 2869s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2870{
c19d1205
ZW
2871 char * name;
2872 char saved_char;
b99bd4ef 2873
c19d1205
ZW
2874 name = input_line_pointer;
2875
2876 while (*input_line_pointer != 0
2877 && *input_line_pointer != ' '
2878 && *input_line_pointer != '\n')
2879 ++input_line_pointer;
2880
2881 saved_char = *input_line_pointer;
2882 *input_line_pointer = 0;
2883
2884 if (!*name)
2885 as_bad (_("invalid syntax for .unreq directive"));
2886 else
2887 {
21d799b5 2888 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2889 name);
c19d1205
ZW
2890
2891 if (!reg)
2892 as_bad (_("unknown register alias '%s'"), name);
2893 else if (reg->builtin)
a1727c1a 2894 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2895 name);
2896 else
2897 {
d929913e
NC
2898 char * p;
2899 char * nbuf;
2900
db0bc284 2901 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2902 free ((char *) reg->name);
477330fc
RM
2903 if (reg->neon)
2904 free (reg->neon);
c19d1205 2905 free (reg);
d929913e
NC
2906
2907 /* Also locate the all upper case and all lower case versions.
2908 Do not complain if we cannot find one or the other as it
2909 was probably deleted above. */
5f4273c7 2910
d929913e
NC
2911 nbuf = strdup (name);
2912 for (p = nbuf; *p; p++)
2913 *p = TOUPPER (*p);
21d799b5 2914 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2915 if (reg)
2916 {
db0bc284 2917 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2918 free ((char *) reg->name);
2919 if (reg->neon)
2920 free (reg->neon);
2921 free (reg);
2922 }
2923
2924 for (p = nbuf; *p; p++)
2925 *p = TOLOWER (*p);
21d799b5 2926 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2927 if (reg)
2928 {
db0bc284 2929 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2930 free ((char *) reg->name);
2931 if (reg->neon)
2932 free (reg->neon);
2933 free (reg);
2934 }
2935
2936 free (nbuf);
c19d1205
ZW
2937 }
2938 }
b99bd4ef 2939
c19d1205 2940 *input_line_pointer = saved_char;
b99bd4ef
NC
2941 demand_empty_rest_of_line ();
2942}
2943
c19d1205
ZW
2944/* Directives: Instruction set selection. */
2945
2946#ifdef OBJ_ELF
2947/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2948 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2949 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2950 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2951
cd000bff
DJ
2952/* Create a new mapping symbol for the transition to STATE. */
2953
2954static void
2955make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2956{
a737bd4d 2957 symbolS * symbolP;
c19d1205
ZW
2958 const char * symname;
2959 int type;
b99bd4ef 2960
c19d1205 2961 switch (state)
b99bd4ef 2962 {
c19d1205
ZW
2963 case MAP_DATA:
2964 symname = "$d";
2965 type = BSF_NO_FLAGS;
2966 break;
2967 case MAP_ARM:
2968 symname = "$a";
2969 type = BSF_NO_FLAGS;
2970 break;
2971 case MAP_THUMB:
2972 symname = "$t";
2973 type = BSF_NO_FLAGS;
2974 break;
c19d1205
ZW
2975 default:
2976 abort ();
2977 }
2978
cd000bff 2979 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2980 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2981
2982 switch (state)
2983 {
2984 case MAP_ARM:
2985 THUMB_SET_FUNC (symbolP, 0);
2986 ARM_SET_THUMB (symbolP, 0);
2987 ARM_SET_INTERWORK (symbolP, support_interwork);
2988 break;
2989
2990 case MAP_THUMB:
2991 THUMB_SET_FUNC (symbolP, 1);
2992 ARM_SET_THUMB (symbolP, 1);
2993 ARM_SET_INTERWORK (symbolP, support_interwork);
2994 break;
2995
2996 case MAP_DATA:
2997 default:
cd000bff
DJ
2998 break;
2999 }
3000
3001 /* Save the mapping symbols for future reference. Also check that
3002 we do not place two mapping symbols at the same offset within a
3003 frag. We'll handle overlap between frags in
2de7820f
JZ
3004 check_mapping_symbols.
3005
3006 If .fill or other data filling directive generates zero sized data,
3007 the mapping symbol for the following code will have the same value
3008 as the one generated for the data filling directive. In this case,
3009 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
3010 if (value == 0)
3011 {
2de7820f
JZ
3012 if (frag->tc_frag_data.first_map != NULL)
3013 {
3014 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3015 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3016 }
cd000bff
DJ
3017 frag->tc_frag_data.first_map = symbolP;
3018 }
3019 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
3020 {
3021 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
3022 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3023 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3024 }
cd000bff
DJ
3025 frag->tc_frag_data.last_map = symbolP;
3026}
3027
3028/* We must sometimes convert a region marked as code to data during
3029 code alignment, if an odd number of bytes have to be padded. The
3030 code mapping symbol is pushed to an aligned address. */
3031
3032static void
3033insert_data_mapping_symbol (enum mstate state,
3034 valueT value, fragS *frag, offsetT bytes)
3035{
3036 /* If there was already a mapping symbol, remove it. */
3037 if (frag->tc_frag_data.last_map != NULL
3038 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3039 {
3040 symbolS *symp = frag->tc_frag_data.last_map;
3041
3042 if (value == 0)
3043 {
3044 know (frag->tc_frag_data.first_map == symp);
3045 frag->tc_frag_data.first_map = NULL;
3046 }
3047 frag->tc_frag_data.last_map = NULL;
3048 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 3049 }
cd000bff
DJ
3050
3051 make_mapping_symbol (MAP_DATA, value, frag);
3052 make_mapping_symbol (state, value + bytes, frag);
3053}
3054
3055static void mapping_state_2 (enum mstate state, int max_chars);
3056
3057/* Set the mapping state to STATE. Only call this when about to
3058 emit some STATE bytes to the file. */
3059
4e9aaefb 3060#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
3061void
3062mapping_state (enum mstate state)
3063{
940b5ce0
DJ
3064 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3065
cd000bff
DJ
3066 if (mapstate == state)
3067 /* The mapping symbol has already been emitted.
3068 There is nothing else to do. */
3069 return;
49c62a33
NC
3070
3071 if (state == MAP_ARM || state == MAP_THUMB)
3072 /* PR gas/12931
3073 All ARM instructions require 4-byte alignment.
3074 (Almost) all Thumb instructions require 2-byte alignment.
3075
3076 When emitting instructions into any section, mark the section
3077 appropriately.
3078
3079 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3080 but themselves require 2-byte alignment; this applies to some
33eaf5de 3081 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
3082 literal pool generation or an explicit .align >=2, both of
3083 which will cause the section to me marked with sufficient
3084 alignment. Thus, we don't handle those cases here. */
3085 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3086
3087 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 3088 /* This case will be evaluated later. */
cd000bff 3089 return;
cd000bff
DJ
3090
3091 mapping_state_2 (state, 0);
cd000bff
DJ
3092}
3093
3094/* Same as mapping_state, but MAX_CHARS bytes have already been
3095 allocated. Put the mapping symbol that far back. */
3096
3097static void
3098mapping_state_2 (enum mstate state, int max_chars)
3099{
940b5ce0
DJ
3100 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3101
3102 if (!SEG_NORMAL (now_seg))
3103 return;
3104
cd000bff
DJ
3105 if (mapstate == state)
3106 /* The mapping symbol has already been emitted.
3107 There is nothing else to do. */
3108 return;
3109
4e9aaefb
SA
3110 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3111 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3112 {
3113 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3114 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3115
3116 if (add_symbol)
3117 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3118 }
3119
cd000bff
DJ
3120 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3121 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3122}
4e9aaefb 3123#undef TRANSITION
c19d1205 3124#else
d3106081
NS
3125#define mapping_state(x) ((void)0)
3126#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3127#endif
3128
3129/* Find the real, Thumb encoded start of a Thumb function. */
3130
4343666d 3131#ifdef OBJ_COFF
c19d1205
ZW
3132static symbolS *
3133find_real_start (symbolS * symbolP)
3134{
3135 char * real_start;
3136 const char * name = S_GET_NAME (symbolP);
3137 symbolS * new_target;
3138
3139 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3140#define STUB_NAME ".real_start_of"
3141
3142 if (name == NULL)
3143 abort ();
3144
37f6032b
ZW
3145 /* The compiler may generate BL instructions to local labels because
3146 it needs to perform a branch to a far away location. These labels
3147 do not have a corresponding ".real_start_of" label. We check
3148 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3149 the ".real_start_of" convention for nonlocal branches. */
3150 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3151 return symbolP;
3152
e1fa0163 3153 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3154 new_target = symbol_find (real_start);
e1fa0163 3155 free (real_start);
c19d1205
ZW
3156
3157 if (new_target == NULL)
3158 {
bd3ba5d1 3159 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3160 new_target = symbolP;
3161 }
3162
c19d1205
ZW
3163 return new_target;
3164}
4343666d 3165#endif
c19d1205
ZW
3166
3167static void
3168opcode_select (int width)
3169{
3170 switch (width)
3171 {
3172 case 16:
3173 if (! thumb_mode)
3174 {
e74cfd16 3175 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3176 as_bad (_("selected processor does not support THUMB opcodes"));
3177
3178 thumb_mode = 1;
3179 /* No need to force the alignment, since we will have been
3180 coming from ARM mode, which is word-aligned. */
3181 record_alignment (now_seg, 1);
3182 }
c19d1205
ZW
3183 break;
3184
3185 case 32:
3186 if (thumb_mode)
3187 {
e74cfd16 3188 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3189 as_bad (_("selected processor does not support ARM opcodes"));
3190
3191 thumb_mode = 0;
3192
3193 if (!need_pass_2)
3194 frag_align (2, 0, 0);
3195
3196 record_alignment (now_seg, 1);
3197 }
c19d1205
ZW
3198 break;
3199
3200 default:
3201 as_bad (_("invalid instruction size selected (%d)"), width);
3202 }
3203}
3204
3205static void
3206s_arm (int ignore ATTRIBUTE_UNUSED)
3207{
3208 opcode_select (32);
3209 demand_empty_rest_of_line ();
3210}
3211
3212static void
3213s_thumb (int ignore ATTRIBUTE_UNUSED)
3214{
3215 opcode_select (16);
3216 demand_empty_rest_of_line ();
3217}
3218
3219static void
3220s_code (int unused ATTRIBUTE_UNUSED)
3221{
3222 int temp;
3223
3224 temp = get_absolute_expression ();
3225 switch (temp)
3226 {
3227 case 16:
3228 case 32:
3229 opcode_select (temp);
3230 break;
3231
3232 default:
3233 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3234 }
3235}
3236
3237static void
3238s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3239{
3240 /* If we are not already in thumb mode go into it, EVEN if
3241 the target processor does not support thumb instructions.
3242 This is used by gcc/config/arm/lib1funcs.asm for example
3243 to compile interworking support functions even if the
3244 target processor should not support interworking. */
3245 if (! thumb_mode)
3246 {
3247 thumb_mode = 2;
3248 record_alignment (now_seg, 1);
3249 }
3250
3251 demand_empty_rest_of_line ();
3252}
3253
3254static void
3255s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3256{
3257 s_thumb (0);
3258
3259 /* The following label is the name/address of the start of a Thumb function.
3260 We need to know this for the interworking support. */
3261 label_is_thumb_function_name = TRUE;
3262}
3263
3264/* Perform a .set directive, but also mark the alias as
3265 being a thumb function. */
3266
3267static void
3268s_thumb_set (int equiv)
3269{
3270 /* XXX the following is a duplicate of the code for s_set() in read.c
3271 We cannot just call that code as we need to get at the symbol that
3272 is created. */
3273 char * name;
3274 char delim;
3275 char * end_name;
3276 symbolS * symbolP;
3277
3278 /* Especial apologies for the random logic:
3279 This just grew, and could be parsed much more simply!
3280 Dean - in haste. */
d02603dc 3281 delim = get_symbol_name (& name);
c19d1205 3282 end_name = input_line_pointer;
d02603dc 3283 (void) restore_line_pointer (delim);
c19d1205
ZW
3284
3285 if (*input_line_pointer != ',')
3286 {
3287 *end_name = 0;
3288 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3289 *end_name = delim;
3290 ignore_rest_of_line ();
3291 return;
3292 }
3293
3294 input_line_pointer++;
3295 *end_name = 0;
3296
3297 if (name[0] == '.' && name[1] == '\0')
3298 {
3299 /* XXX - this should not happen to .thumb_set. */
3300 abort ();
3301 }
3302
3303 if ((symbolP = symbol_find (name)) == NULL
3304 && (symbolP = md_undefined_symbol (name)) == NULL)
3305 {
3306#ifndef NO_LISTING
3307 /* When doing symbol listings, play games with dummy fragments living
3308 outside the normal fragment chain to record the file and line info
c19d1205 3309 for this symbol. */
b99bd4ef
NC
3310 if (listing & LISTING_SYMBOLS)
3311 {
3312 extern struct list_info_struct * listing_tail;
21d799b5 3313 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3314
3315 memset (dummy_frag, 0, sizeof (fragS));
3316 dummy_frag->fr_type = rs_fill;
3317 dummy_frag->line = listing_tail;
3318 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3319 dummy_frag->fr_symbol = symbolP;
3320 }
3321 else
3322#endif
3323 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3324
3325#ifdef OBJ_COFF
3326 /* "set" symbols are local unless otherwise specified. */
3327 SF_SET_LOCAL (symbolP);
3328#endif /* OBJ_COFF */
3329 } /* Make a new symbol. */
3330
3331 symbol_table_insert (symbolP);
3332
3333 * end_name = delim;
3334
3335 if (equiv
3336 && S_IS_DEFINED (symbolP)
3337 && S_GET_SEGMENT (symbolP) != reg_section)
3338 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3339
3340 pseudo_set (symbolP);
3341
3342 demand_empty_rest_of_line ();
3343
c19d1205 3344 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3345
3346 THUMB_SET_FUNC (symbolP, 1);
3347 ARM_SET_THUMB (symbolP, 1);
3348#if defined OBJ_ELF || defined OBJ_COFF
3349 ARM_SET_INTERWORK (symbolP, support_interwork);
3350#endif
3351}
3352
c19d1205 3353/* Directives: Mode selection. */
b99bd4ef 3354
c19d1205
ZW
3355/* .syntax [unified|divided] - choose the new unified syntax
3356 (same for Arm and Thumb encoding, modulo slight differences in what
3357 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3358static void
c19d1205 3359s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3360{
c19d1205
ZW
3361 char *name, delim;
3362
d02603dc 3363 delim = get_symbol_name (& name);
c19d1205
ZW
3364
3365 if (!strcasecmp (name, "unified"))
3366 unified_syntax = TRUE;
3367 else if (!strcasecmp (name, "divided"))
3368 unified_syntax = FALSE;
3369 else
3370 {
3371 as_bad (_("unrecognized syntax mode \"%s\""), name);
3372 return;
3373 }
d02603dc 3374 (void) restore_line_pointer (delim);
b99bd4ef
NC
3375 demand_empty_rest_of_line ();
3376}
3377
c19d1205
ZW
3378/* Directives: sectioning and alignment. */
3379
c19d1205
ZW
3380static void
3381s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3382{
c19d1205
ZW
3383 /* We don't support putting frags in the BSS segment, we fake it by
3384 marking in_bss, then looking at s_skip for clues. */
3385 subseg_set (bss_section, 0);
3386 demand_empty_rest_of_line ();
cd000bff
DJ
3387
3388#ifdef md_elf_section_change_hook
3389 md_elf_section_change_hook ();
3390#endif
c19d1205 3391}
b99bd4ef 3392
c19d1205
ZW
3393static void
3394s_even (int ignore ATTRIBUTE_UNUSED)
3395{
3396 /* Never make frag if expect extra pass. */
3397 if (!need_pass_2)
3398 frag_align (1, 0, 0);
b99bd4ef 3399
c19d1205 3400 record_alignment (now_seg, 1);
b99bd4ef 3401
c19d1205 3402 demand_empty_rest_of_line ();
b99bd4ef
NC
3403}
3404
2e6976a8
DG
3405/* Directives: CodeComposer Studio. */
3406
3407/* .ref (for CodeComposer Studio syntax only). */
3408static void
3409s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3410{
3411 if (codecomposer_syntax)
3412 ignore_rest_of_line ();
3413 else
3414 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3415}
3416
3417/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3418 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3419static void
3420asmfunc_debug (const char * name)
3421{
3422 static const char * last_name = NULL;
3423
3424 if (name != NULL)
3425 {
3426 gas_assert (last_name == NULL);
3427 last_name = name;
3428
3429 if (debug_type == DEBUG_STABS)
3430 stabs_generate_asm_func (name, name);
3431 }
3432 else
3433 {
3434 gas_assert (last_name != NULL);
3435
3436 if (debug_type == DEBUG_STABS)
3437 stabs_generate_asm_endfunc (last_name, last_name);
3438
3439 last_name = NULL;
3440 }
3441}
3442
3443static void
3444s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3445{
3446 if (codecomposer_syntax)
3447 {
3448 switch (asmfunc_state)
3449 {
3450 case OUTSIDE_ASMFUNC:
3451 asmfunc_state = WAITING_ASMFUNC_NAME;
3452 break;
3453
3454 case WAITING_ASMFUNC_NAME:
3455 as_bad (_(".asmfunc repeated."));
3456 break;
3457
3458 case WAITING_ENDASMFUNC:
3459 as_bad (_(".asmfunc without function."));
3460 break;
3461 }
3462 demand_empty_rest_of_line ();
3463 }
3464 else
3465 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3466}
3467
3468static void
3469s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3470{
3471 if (codecomposer_syntax)
3472 {
3473 switch (asmfunc_state)
3474 {
3475 case OUTSIDE_ASMFUNC:
3476 as_bad (_(".endasmfunc without a .asmfunc."));
3477 break;
3478
3479 case WAITING_ASMFUNC_NAME:
3480 as_bad (_(".endasmfunc without function."));
3481 break;
3482
3483 case WAITING_ENDASMFUNC:
3484 asmfunc_state = OUTSIDE_ASMFUNC;
3485 asmfunc_debug (NULL);
3486 break;
3487 }
3488 demand_empty_rest_of_line ();
3489 }
3490 else
3491 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3492}
3493
3494static void
3495s_ccs_def (int name)
3496{
3497 if (codecomposer_syntax)
3498 s_globl (name);
3499 else
3500 as_bad (_(".def pseudo-op only available with -mccs flag."));
3501}
3502
c19d1205 3503/* Directives: Literal pools. */
a737bd4d 3504
c19d1205
ZW
3505static literal_pool *
3506find_literal_pool (void)
a737bd4d 3507{
c19d1205 3508 literal_pool * pool;
a737bd4d 3509
c19d1205 3510 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3511 {
c19d1205
ZW
3512 if (pool->section == now_seg
3513 && pool->sub_section == now_subseg)
3514 break;
a737bd4d
NC
3515 }
3516
c19d1205 3517 return pool;
a737bd4d
NC
3518}
3519
c19d1205
ZW
3520static literal_pool *
3521find_or_make_literal_pool (void)
a737bd4d 3522{
c19d1205
ZW
3523 /* Next literal pool ID number. */
3524 static unsigned int latest_pool_num = 1;
3525 literal_pool * pool;
a737bd4d 3526
c19d1205 3527 pool = find_literal_pool ();
a737bd4d 3528
c19d1205 3529 if (pool == NULL)
a737bd4d 3530 {
c19d1205 3531 /* Create a new pool. */
325801bd 3532 pool = XNEW (literal_pool);
c19d1205
ZW
3533 if (! pool)
3534 return NULL;
a737bd4d 3535
c19d1205
ZW
3536 pool->next_free_entry = 0;
3537 pool->section = now_seg;
3538 pool->sub_section = now_subseg;
3539 pool->next = list_of_pools;
3540 pool->symbol = NULL;
8335d6aa 3541 pool->alignment = 2;
c19d1205
ZW
3542
3543 /* Add it to the list. */
3544 list_of_pools = pool;
a737bd4d 3545 }
a737bd4d 3546
c19d1205
ZW
3547 /* New pools, and emptied pools, will have a NULL symbol. */
3548 if (pool->symbol == NULL)
a737bd4d 3549 {
c19d1205
ZW
3550 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3551 (valueT) 0, &zero_address_frag);
3552 pool->id = latest_pool_num ++;
a737bd4d
NC
3553 }
3554
c19d1205
ZW
3555 /* Done. */
3556 return pool;
a737bd4d
NC
3557}
3558
c19d1205 3559/* Add the literal in the global 'inst'
5f4273c7 3560 structure to the relevant literal pool. */
b99bd4ef
NC
3561
3562static int
8335d6aa 3563add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3564{
8335d6aa
JW
3565#define PADDING_SLOT 0x1
3566#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3567 literal_pool * pool;
8335d6aa
JW
3568 unsigned int entry, pool_size = 0;
3569 bfd_boolean padding_slot_p = FALSE;
e56c722b 3570 unsigned imm1 = 0;
8335d6aa
JW
3571 unsigned imm2 = 0;
3572
3573 if (nbytes == 8)
3574 {
3575 imm1 = inst.operands[1].imm;
3576 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3577 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3578 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3579 if (target_big_endian)
3580 {
3581 imm1 = imm2;
3582 imm2 = inst.operands[1].imm;
3583 }
3584 }
b99bd4ef 3585
c19d1205
ZW
3586 pool = find_or_make_literal_pool ();
3587
3588 /* Check if this literal value is already in the pool. */
3589 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3590 {
8335d6aa
JW
3591 if (nbytes == 4)
3592 {
e2b0ab59
AV
3593 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3594 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3595 && (pool->literals[entry].X_add_number
e2b0ab59 3596 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3597 && (pool->literals[entry].X_md == nbytes)
3598 && (pool->literals[entry].X_unsigned
e2b0ab59 3599 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3600 break;
3601
e2b0ab59
AV
3602 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3603 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3604 && (pool->literals[entry].X_add_number
e2b0ab59 3605 == inst.relocs[0].exp.X_add_number)
8335d6aa 3606 && (pool->literals[entry].X_add_symbol
e2b0ab59 3607 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3608 && (pool->literals[entry].X_op_symbol
e2b0ab59 3609 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3610 && (pool->literals[entry].X_md == nbytes))
3611 break;
3612 }
3613 else if ((nbytes == 8)
3614 && !(pool_size & 0x7)
3615 && ((entry + 1) != pool->next_free_entry)
3616 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3617 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3618 && (pool->literals[entry].X_unsigned
e2b0ab59 3619 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3620 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3621 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3622 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3623 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3624 break;
3625
8335d6aa
JW
3626 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3627 if (padding_slot_p && (nbytes == 4))
c19d1205 3628 break;
8335d6aa
JW
3629
3630 pool_size += 4;
b99bd4ef
NC
3631 }
3632
c19d1205
ZW
3633 /* Do we need to create a new entry? */
3634 if (entry == pool->next_free_entry)
3635 {
3636 if (entry >= MAX_LITERAL_POOL_SIZE)
3637 {
3638 inst.error = _("literal pool overflow");
3639 return FAIL;
3640 }
3641
8335d6aa
JW
3642 if (nbytes == 8)
3643 {
3644 /* For 8-byte entries, we align to an 8-byte boundary,
3645 and split it into two 4-byte entries, because on 32-bit
3646 host, 8-byte constants are treated as big num, thus
3647 saved in "generic_bignum" which will be overwritten
3648 by later assignments.
3649
3650 We also need to make sure there is enough space for
3651 the split.
3652
3653 We also check to make sure the literal operand is a
3654 constant number. */
e2b0ab59
AV
3655 if (!(inst.relocs[0].exp.X_op == O_constant
3656 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3657 {
3658 inst.error = _("invalid type for literal pool");
3659 return FAIL;
3660 }
3661 else if (pool_size & 0x7)
3662 {
3663 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3664 {
3665 inst.error = _("literal pool overflow");
3666 return FAIL;
3667 }
3668
e2b0ab59 3669 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3670 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3671 pool->literals[entry].X_add_number = 0;
3672 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3673 pool->next_free_entry += 1;
3674 pool_size += 4;
3675 }
3676 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3677 {
3678 inst.error = _("literal pool overflow");
3679 return FAIL;
3680 }
3681
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 = imm1;
e2b0ab59 3685 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3686 pool->literals[entry++].X_md = 4;
e2b0ab59 3687 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3688 pool->literals[entry].X_op = O_constant;
3689 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3690 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3691 pool->literals[entry].X_md = 4;
3692 pool->alignment = 3;
3693 pool->next_free_entry += 1;
3694 }
3695 else
3696 {
e2b0ab59 3697 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3698 pool->literals[entry].X_md = 4;
3699 }
3700
a8040cf2
NC
3701#ifdef OBJ_ELF
3702 /* PR ld/12974: Record the location of the first source line to reference
3703 this entry in the literal pool. If it turns out during linking that the
3704 symbol does not exist we will be able to give an accurate line number for
3705 the (first use of the) missing reference. */
3706 if (debug_type == DEBUG_DWARF2)
3707 dwarf2_where (pool->locs + entry);
3708#endif
c19d1205
ZW
3709 pool->next_free_entry += 1;
3710 }
8335d6aa
JW
3711 else if (padding_slot_p)
3712 {
e2b0ab59 3713 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3714 pool->literals[entry].X_md = nbytes;
3715 }
b99bd4ef 3716
e2b0ab59
AV
3717 inst.relocs[0].exp.X_op = O_symbol;
3718 inst.relocs[0].exp.X_add_number = pool_size;
3719 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3720
c19d1205 3721 return SUCCESS;
b99bd4ef
NC
3722}
3723
2e6976a8 3724bfd_boolean
2e57ce7b 3725tc_start_label_without_colon (void)
2e6976a8
DG
3726{
3727 bfd_boolean ret = TRUE;
3728
3729 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3730 {
2e57ce7b 3731 const char *label = input_line_pointer;
2e6976a8
DG
3732
3733 while (!is_end_of_line[(int) label[-1]])
3734 --label;
3735
3736 if (*label == '.')
3737 {
3738 as_bad (_("Invalid label '%s'"), label);
3739 ret = FALSE;
3740 }
3741
3742 asmfunc_debug (label);
3743
3744 asmfunc_state = WAITING_ENDASMFUNC;
3745 }
3746
3747 return ret;
3748}
3749
c19d1205 3750/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3751 a later date assign it a value. That's what these functions do. */
e16bb312 3752
c19d1205
ZW
3753static void
3754symbol_locate (symbolS * symbolP,
3755 const char * name, /* It is copied, the caller can modify. */
3756 segT segment, /* Segment identifier (SEG_<something>). */
3757 valueT valu, /* Symbol value. */
3758 fragS * frag) /* Associated fragment. */
3759{
e57e6ddc 3760 size_t name_length;
c19d1205 3761 char * preserved_copy_of_name;
e16bb312 3762
c19d1205
ZW
3763 name_length = strlen (name) + 1; /* +1 for \0. */
3764 obstack_grow (&notes, name, name_length);
21d799b5 3765 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3766
c19d1205
ZW
3767#ifdef tc_canonicalize_symbol_name
3768 preserved_copy_of_name =
3769 tc_canonicalize_symbol_name (preserved_copy_of_name);
3770#endif
b99bd4ef 3771
c19d1205 3772 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3773
c19d1205
ZW
3774 S_SET_SEGMENT (symbolP, segment);
3775 S_SET_VALUE (symbolP, valu);
3776 symbol_clear_list_pointers (symbolP);
b99bd4ef 3777
c19d1205 3778 symbol_set_frag (symbolP, frag);
b99bd4ef 3779
c19d1205
ZW
3780 /* Link to end of symbol chain. */
3781 {
3782 extern int symbol_table_frozen;
b99bd4ef 3783
c19d1205
ZW
3784 if (symbol_table_frozen)
3785 abort ();
3786 }
b99bd4ef 3787
c19d1205 3788 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3789
c19d1205 3790 obj_symbol_new_hook (symbolP);
b99bd4ef 3791
c19d1205
ZW
3792#ifdef tc_symbol_new_hook
3793 tc_symbol_new_hook (symbolP);
3794#endif
3795
3796#ifdef DEBUG_SYMS
3797 verify_symbol_chain (symbol_rootP, symbol_lastP);
3798#endif /* DEBUG_SYMS */
b99bd4ef
NC
3799}
3800
c19d1205
ZW
3801static void
3802s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3803{
c19d1205
ZW
3804 unsigned int entry;
3805 literal_pool * pool;
3806 char sym_name[20];
b99bd4ef 3807
c19d1205
ZW
3808 pool = find_literal_pool ();
3809 if (pool == NULL
3810 || pool->symbol == NULL
3811 || pool->next_free_entry == 0)
3812 return;
b99bd4ef 3813
c19d1205
ZW
3814 /* Align pool as you have word accesses.
3815 Only make a frag if we have to. */
3816 if (!need_pass_2)
8335d6aa 3817 frag_align (pool->alignment, 0, 0);
b99bd4ef 3818
c19d1205 3819 record_alignment (now_seg, 2);
b99bd4ef 3820
aaca88ef 3821#ifdef OBJ_ELF
47fc6e36
WN
3822 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3823 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3824#endif
c19d1205 3825 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3826
c19d1205
ZW
3827 symbol_locate (pool->symbol, sym_name, now_seg,
3828 (valueT) frag_now_fix (), frag_now);
3829 symbol_table_insert (pool->symbol);
b99bd4ef 3830
c19d1205 3831 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3832
c19d1205
ZW
3833#if defined OBJ_COFF || defined OBJ_ELF
3834 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3835#endif
6c43fab6 3836
c19d1205 3837 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3838 {
3839#ifdef OBJ_ELF
3840 if (debug_type == DEBUG_DWARF2)
3841 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3842#endif
3843 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3844 emit_expr (&(pool->literals[entry]),
3845 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3846 }
b99bd4ef 3847
c19d1205
ZW
3848 /* Mark the pool as empty. */
3849 pool->next_free_entry = 0;
3850 pool->symbol = NULL;
b99bd4ef
NC
3851}
3852
c19d1205
ZW
3853#ifdef OBJ_ELF
3854/* Forward declarations for functions below, in the MD interface
3855 section. */
3856static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3857static valueT create_unwind_entry (int);
3858static void start_unwind_section (const segT, int);
3859static void add_unwind_opcode (valueT, int);
3860static void flush_pending_unwind (void);
b99bd4ef 3861
c19d1205 3862/* Directives: Data. */
b99bd4ef 3863
c19d1205
ZW
3864static void
3865s_arm_elf_cons (int nbytes)
3866{
3867 expressionS exp;
b99bd4ef 3868
c19d1205
ZW
3869#ifdef md_flush_pending_output
3870 md_flush_pending_output ();
3871#endif
b99bd4ef 3872
c19d1205 3873 if (is_it_end_of_statement ())
b99bd4ef 3874 {
c19d1205
ZW
3875 demand_empty_rest_of_line ();
3876 return;
b99bd4ef
NC
3877 }
3878
c19d1205
ZW
3879#ifdef md_cons_align
3880 md_cons_align (nbytes);
3881#endif
b99bd4ef 3882
c19d1205
ZW
3883 mapping_state (MAP_DATA);
3884 do
b99bd4ef 3885 {
c19d1205
ZW
3886 int reloc;
3887 char *base = input_line_pointer;
b99bd4ef 3888
c19d1205 3889 expression (& exp);
b99bd4ef 3890
c19d1205
ZW
3891 if (exp.X_op != O_symbol)
3892 emit_expr (&exp, (unsigned int) nbytes);
3893 else
3894 {
3895 char *before_reloc = input_line_pointer;
3896 reloc = parse_reloc (&input_line_pointer);
3897 if (reloc == -1)
3898 {
3899 as_bad (_("unrecognized relocation suffix"));
3900 ignore_rest_of_line ();
3901 return;
3902 }
3903 else if (reloc == BFD_RELOC_UNUSED)
3904 emit_expr (&exp, (unsigned int) nbytes);
3905 else
3906 {
21d799b5 3907 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3908 bfd_reloc_type_lookup (stdoutput,
3909 (bfd_reloc_code_real_type) reloc);
c19d1205 3910 int size = bfd_get_reloc_size (howto);
b99bd4ef 3911
2fc8bdac
ZW
3912 if (reloc == BFD_RELOC_ARM_PLT32)
3913 {
3914 as_bad (_("(plt) is only valid on branch targets"));
3915 reloc = BFD_RELOC_UNUSED;
3916 size = 0;
3917 }
3918
c19d1205 3919 if (size > nbytes)
992a06ee
AM
3920 as_bad (ngettext ("%s relocations do not fit in %d byte",
3921 "%s relocations do not fit in %d bytes",
3922 nbytes),
c19d1205
ZW
3923 howto->name, nbytes);
3924 else
3925 {
3926 /* We've parsed an expression stopping at O_symbol.
3927 But there may be more expression left now that we
3928 have parsed the relocation marker. Parse it again.
3929 XXX Surely there is a cleaner way to do this. */
3930 char *p = input_line_pointer;
3931 int offset;
325801bd 3932 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3933
c19d1205
ZW
3934 memcpy (save_buf, base, input_line_pointer - base);
3935 memmove (base + (input_line_pointer - before_reloc),
3936 base, before_reloc - base);
3937
3938 input_line_pointer = base + (input_line_pointer-before_reloc);
3939 expression (&exp);
3940 memcpy (base, save_buf, p - base);
3941
3942 offset = nbytes - size;
4b1a927e
AM
3943 p = frag_more (nbytes);
3944 memset (p, 0, nbytes);
c19d1205 3945 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3946 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3947 free (save_buf);
c19d1205
ZW
3948 }
3949 }
3950 }
b99bd4ef 3951 }
c19d1205 3952 while (*input_line_pointer++ == ',');
b99bd4ef 3953
c19d1205
ZW
3954 /* Put terminator back into stream. */
3955 input_line_pointer --;
3956 demand_empty_rest_of_line ();
b99bd4ef
NC
3957}
3958
c921be7d
NC
3959/* Emit an expression containing a 32-bit thumb instruction.
3960 Implementation based on put_thumb32_insn. */
3961
3962static void
3963emit_thumb32_expr (expressionS * exp)
3964{
3965 expressionS exp_high = *exp;
3966
3967 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3968 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3969 exp->X_add_number &= 0xffff;
3970 emit_expr (exp, (unsigned int) THUMB_SIZE);
3971}
3972
3973/* Guess the instruction size based on the opcode. */
3974
3975static int
3976thumb_insn_size (int opcode)
3977{
3978 if ((unsigned int) opcode < 0xe800u)
3979 return 2;
3980 else if ((unsigned int) opcode >= 0xe8000000u)
3981 return 4;
3982 else
3983 return 0;
3984}
3985
3986static bfd_boolean
3987emit_insn (expressionS *exp, int nbytes)
3988{
3989 int size = 0;
3990
3991 if (exp->X_op == O_constant)
3992 {
3993 size = nbytes;
3994
3995 if (size == 0)
3996 size = thumb_insn_size (exp->X_add_number);
3997
3998 if (size != 0)
3999 {
4000 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
4001 {
4002 as_bad (_(".inst.n operand too big. "\
4003 "Use .inst.w instead"));
4004 size = 0;
4005 }
4006 else
4007 {
5ee91343
AV
4008 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4009 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 4010 else
5ee91343 4011 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
4012
4013 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4014 emit_thumb32_expr (exp);
4015 else
4016 emit_expr (exp, (unsigned int) size);
4017
4018 it_fsm_post_encode ();
4019 }
4020 }
4021 else
4022 as_bad (_("cannot determine Thumb instruction size. " \
4023 "Use .inst.n/.inst.w instead"));
4024 }
4025 else
4026 as_bad (_("constant expression required"));
4027
4028 return (size != 0);
4029}
4030
4031/* Like s_arm_elf_cons but do not use md_cons_align and
4032 set the mapping state to MAP_ARM/MAP_THUMB. */
4033
4034static void
4035s_arm_elf_inst (int nbytes)
4036{
4037 if (is_it_end_of_statement ())
4038 {
4039 demand_empty_rest_of_line ();
4040 return;
4041 }
4042
4043 /* Calling mapping_state () here will not change ARM/THUMB,
4044 but will ensure not to be in DATA state. */
4045
4046 if (thumb_mode)
4047 mapping_state (MAP_THUMB);
4048 else
4049 {
4050 if (nbytes != 0)
4051 {
4052 as_bad (_("width suffixes are invalid in ARM mode"));
4053 ignore_rest_of_line ();
4054 return;
4055 }
4056
4057 nbytes = 4;
4058
4059 mapping_state (MAP_ARM);
4060 }
4061
4062 do
4063 {
4064 expressionS exp;
4065
4066 expression (& exp);
4067
4068 if (! emit_insn (& exp, nbytes))
4069 {
4070 ignore_rest_of_line ();
4071 return;
4072 }
4073 }
4074 while (*input_line_pointer++ == ',');
4075
4076 /* Put terminator back into stream. */
4077 input_line_pointer --;
4078 demand_empty_rest_of_line ();
4079}
b99bd4ef 4080
c19d1205 4081/* Parse a .rel31 directive. */
b99bd4ef 4082
c19d1205
ZW
4083static void
4084s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4085{
4086 expressionS exp;
4087 char *p;
4088 valueT highbit;
b99bd4ef 4089
c19d1205
ZW
4090 highbit = 0;
4091 if (*input_line_pointer == '1')
4092 highbit = 0x80000000;
4093 else if (*input_line_pointer != '0')
4094 as_bad (_("expected 0 or 1"));
b99bd4ef 4095
c19d1205
ZW
4096 input_line_pointer++;
4097 if (*input_line_pointer != ',')
4098 as_bad (_("missing comma"));
4099 input_line_pointer++;
b99bd4ef 4100
c19d1205
ZW
4101#ifdef md_flush_pending_output
4102 md_flush_pending_output ();
4103#endif
b99bd4ef 4104
c19d1205
ZW
4105#ifdef md_cons_align
4106 md_cons_align (4);
4107#endif
b99bd4ef 4108
c19d1205 4109 mapping_state (MAP_DATA);
b99bd4ef 4110
c19d1205 4111 expression (&exp);
b99bd4ef 4112
c19d1205
ZW
4113 p = frag_more (4);
4114 md_number_to_chars (p, highbit, 4);
4115 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4116 BFD_RELOC_ARM_PREL31);
b99bd4ef 4117
c19d1205 4118 demand_empty_rest_of_line ();
b99bd4ef
NC
4119}
4120
c19d1205 4121/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4122
c19d1205 4123/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4124
c19d1205
ZW
4125static void
4126s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4127{
4128 demand_empty_rest_of_line ();
921e5f0a
PB
4129 if (unwind.proc_start)
4130 {
c921be7d 4131 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4132 return;
4133 }
4134
c19d1205
ZW
4135 /* Mark the start of the function. */
4136 unwind.proc_start = expr_build_dot ();
b99bd4ef 4137
c19d1205
ZW
4138 /* Reset the rest of the unwind info. */
4139 unwind.opcode_count = 0;
4140 unwind.table_entry = NULL;
4141 unwind.personality_routine = NULL;
4142 unwind.personality_index = -1;
4143 unwind.frame_size = 0;
4144 unwind.fp_offset = 0;
fdfde340 4145 unwind.fp_reg = REG_SP;
c19d1205
ZW
4146 unwind.fp_used = 0;
4147 unwind.sp_restored = 0;
4148}
b99bd4ef 4149
b99bd4ef 4150
c19d1205
ZW
4151/* Parse a handlerdata directive. Creates the exception handling table entry
4152 for the function. */
b99bd4ef 4153
c19d1205
ZW
4154static void
4155s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4156{
4157 demand_empty_rest_of_line ();
921e5f0a 4158 if (!unwind.proc_start)
c921be7d 4159 as_bad (MISSING_FNSTART);
921e5f0a 4160
c19d1205 4161 if (unwind.table_entry)
6decc662 4162 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4163
c19d1205
ZW
4164 create_unwind_entry (1);
4165}
a737bd4d 4166
c19d1205 4167/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4168
c19d1205
ZW
4169static void
4170s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4171{
4172 long where;
4173 char *ptr;
4174 valueT val;
940b5ce0 4175 unsigned int marked_pr_dependency;
f02232aa 4176
c19d1205 4177 demand_empty_rest_of_line ();
f02232aa 4178
921e5f0a
PB
4179 if (!unwind.proc_start)
4180 {
c921be7d 4181 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4182 return;
4183 }
4184
c19d1205
ZW
4185 /* Add eh table entry. */
4186 if (unwind.table_entry == NULL)
4187 val = create_unwind_entry (0);
4188 else
4189 val = 0;
f02232aa 4190
c19d1205
ZW
4191 /* Add index table entry. This is two words. */
4192 start_unwind_section (unwind.saved_seg, 1);
4193 frag_align (2, 0, 0);
4194 record_alignment (now_seg, 2);
b99bd4ef 4195
c19d1205 4196 ptr = frag_more (8);
5011093d 4197 memset (ptr, 0, 8);
c19d1205 4198 where = frag_now_fix () - 8;
f02232aa 4199
c19d1205
ZW
4200 /* Self relative offset of the function start. */
4201 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4202 BFD_RELOC_ARM_PREL31);
f02232aa 4203
c19d1205
ZW
4204 /* Indicate dependency on EHABI-defined personality routines to the
4205 linker, if it hasn't been done already. */
940b5ce0
DJ
4206 marked_pr_dependency
4207 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4208 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4209 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4210 {
5f4273c7
NC
4211 static const char *const name[] =
4212 {
4213 "__aeabi_unwind_cpp_pr0",
4214 "__aeabi_unwind_cpp_pr1",
4215 "__aeabi_unwind_cpp_pr2"
4216 };
c19d1205
ZW
4217 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4218 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4219 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4220 |= 1 << unwind.personality_index;
c19d1205 4221 }
f02232aa 4222
c19d1205
ZW
4223 if (val)
4224 /* Inline exception table entry. */
4225 md_number_to_chars (ptr + 4, val, 4);
4226 else
4227 /* Self relative offset of the table entry. */
4228 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4229 BFD_RELOC_ARM_PREL31);
f02232aa 4230
c19d1205
ZW
4231 /* Restore the original section. */
4232 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4233
4234 unwind.proc_start = NULL;
c19d1205 4235}
f02232aa 4236
f02232aa 4237
c19d1205 4238/* Parse an unwind_cantunwind directive. */
b99bd4ef 4239
c19d1205
ZW
4240static void
4241s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4242{
4243 demand_empty_rest_of_line ();
921e5f0a 4244 if (!unwind.proc_start)
c921be7d 4245 as_bad (MISSING_FNSTART);
921e5f0a 4246
c19d1205
ZW
4247 if (unwind.personality_routine || unwind.personality_index != -1)
4248 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4249
c19d1205
ZW
4250 unwind.personality_index = -2;
4251}
b99bd4ef 4252
b99bd4ef 4253
c19d1205 4254/* Parse a personalityindex directive. */
b99bd4ef 4255
c19d1205
ZW
4256static void
4257s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4258{
4259 expressionS exp;
b99bd4ef 4260
921e5f0a 4261 if (!unwind.proc_start)
c921be7d 4262 as_bad (MISSING_FNSTART);
921e5f0a 4263
c19d1205
ZW
4264 if (unwind.personality_routine || unwind.personality_index != -1)
4265 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4266
c19d1205 4267 expression (&exp);
b99bd4ef 4268
c19d1205
ZW
4269 if (exp.X_op != O_constant
4270 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4271 {
c19d1205
ZW
4272 as_bad (_("bad personality routine number"));
4273 ignore_rest_of_line ();
4274 return;
b99bd4ef
NC
4275 }
4276
c19d1205 4277 unwind.personality_index = exp.X_add_number;
b99bd4ef 4278
c19d1205
ZW
4279 demand_empty_rest_of_line ();
4280}
e16bb312 4281
e16bb312 4282
c19d1205 4283/* Parse a personality directive. */
e16bb312 4284
c19d1205
ZW
4285static void
4286s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4287{
4288 char *name, *p, c;
a737bd4d 4289
921e5f0a 4290 if (!unwind.proc_start)
c921be7d 4291 as_bad (MISSING_FNSTART);
921e5f0a 4292
c19d1205
ZW
4293 if (unwind.personality_routine || unwind.personality_index != -1)
4294 as_bad (_("duplicate .personality directive"));
a737bd4d 4295
d02603dc 4296 c = get_symbol_name (& name);
c19d1205 4297 p = input_line_pointer;
d02603dc
NC
4298 if (c == '"')
4299 ++ input_line_pointer;
c19d1205
ZW
4300 unwind.personality_routine = symbol_find_or_make (name);
4301 *p = c;
4302 demand_empty_rest_of_line ();
4303}
e16bb312 4304
e16bb312 4305
c19d1205 4306/* Parse a directive saving core registers. */
e16bb312 4307
c19d1205
ZW
4308static void
4309s_arm_unwind_save_core (void)
e16bb312 4310{
c19d1205
ZW
4311 valueT op;
4312 long range;
4313 int n;
e16bb312 4314
4b5a202f 4315 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4316 if (range == FAIL)
e16bb312 4317 {
c19d1205
ZW
4318 as_bad (_("expected register list"));
4319 ignore_rest_of_line ();
4320 return;
4321 }
e16bb312 4322
c19d1205 4323 demand_empty_rest_of_line ();
e16bb312 4324
c19d1205
ZW
4325 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4326 into .unwind_save {..., sp...}. We aren't bothered about the value of
4327 ip because it is clobbered by calls. */
4328 if (unwind.sp_restored && unwind.fp_reg == 12
4329 && (range & 0x3000) == 0x1000)
4330 {
4331 unwind.opcode_count--;
4332 unwind.sp_restored = 0;
4333 range = (range | 0x2000) & ~0x1000;
4334 unwind.pending_offset = 0;
4335 }
e16bb312 4336
01ae4198
DJ
4337 /* Pop r4-r15. */
4338 if (range & 0xfff0)
c19d1205 4339 {
01ae4198
DJ
4340 /* See if we can use the short opcodes. These pop a block of up to 8
4341 registers starting with r4, plus maybe r14. */
4342 for (n = 0; n < 8; n++)
4343 {
4344 /* Break at the first non-saved register. */
4345 if ((range & (1 << (n + 4))) == 0)
4346 break;
4347 }
4348 /* See if there are any other bits set. */
4349 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4350 {
4351 /* Use the long form. */
4352 op = 0x8000 | ((range >> 4) & 0xfff);
4353 add_unwind_opcode (op, 2);
4354 }
0dd132b6 4355 else
01ae4198
DJ
4356 {
4357 /* Use the short form. */
4358 if (range & 0x4000)
4359 op = 0xa8; /* Pop r14. */
4360 else
4361 op = 0xa0; /* Do not pop r14. */
4362 op |= (n - 1);
4363 add_unwind_opcode (op, 1);
4364 }
c19d1205 4365 }
0dd132b6 4366
c19d1205
ZW
4367 /* Pop r0-r3. */
4368 if (range & 0xf)
4369 {
4370 op = 0xb100 | (range & 0xf);
4371 add_unwind_opcode (op, 2);
0dd132b6
NC
4372 }
4373
c19d1205
ZW
4374 /* Record the number of bytes pushed. */
4375 for (n = 0; n < 16; n++)
4376 {
4377 if (range & (1 << n))
4378 unwind.frame_size += 4;
4379 }
0dd132b6
NC
4380}
4381
c19d1205
ZW
4382
4383/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4384
4385static void
c19d1205 4386s_arm_unwind_save_fpa (int reg)
b99bd4ef 4387{
c19d1205
ZW
4388 expressionS exp;
4389 int num_regs;
4390 valueT op;
b99bd4ef 4391
c19d1205
ZW
4392 /* Get Number of registers to transfer. */
4393 if (skip_past_comma (&input_line_pointer) != FAIL)
4394 expression (&exp);
4395 else
4396 exp.X_op = O_illegal;
b99bd4ef 4397
c19d1205 4398 if (exp.X_op != O_constant)
b99bd4ef 4399 {
c19d1205
ZW
4400 as_bad (_("expected , <constant>"));
4401 ignore_rest_of_line ();
b99bd4ef
NC
4402 return;
4403 }
4404
c19d1205
ZW
4405 num_regs = exp.X_add_number;
4406
4407 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4408 {
c19d1205
ZW
4409 as_bad (_("number of registers must be in the range [1:4]"));
4410 ignore_rest_of_line ();
b99bd4ef
NC
4411 return;
4412 }
4413
c19d1205 4414 demand_empty_rest_of_line ();
b99bd4ef 4415
c19d1205
ZW
4416 if (reg == 4)
4417 {
4418 /* Short form. */
4419 op = 0xb4 | (num_regs - 1);
4420 add_unwind_opcode (op, 1);
4421 }
b99bd4ef
NC
4422 else
4423 {
c19d1205
ZW
4424 /* Long form. */
4425 op = 0xc800 | (reg << 4) | (num_regs - 1);
4426 add_unwind_opcode (op, 2);
b99bd4ef 4427 }
c19d1205 4428 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4429}
4430
c19d1205 4431
fa073d69
MS
4432/* Parse a directive saving VFP registers for ARMv6 and above. */
4433
4434static void
4435s_arm_unwind_save_vfp_armv6 (void)
4436{
4437 int count;
4438 unsigned int start;
4439 valueT op;
4440 int num_vfpv3_regs = 0;
4441 int num_regs_below_16;
efd6b359 4442 bfd_boolean partial_match;
fa073d69 4443
efd6b359
AV
4444 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4445 &partial_match);
fa073d69
MS
4446 if (count == FAIL)
4447 {
4448 as_bad (_("expected register list"));
4449 ignore_rest_of_line ();
4450 return;
4451 }
4452
4453 demand_empty_rest_of_line ();
4454
4455 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4456 than FSTMX/FLDMX-style ones). */
4457
4458 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4459 if (start >= 16)
4460 num_vfpv3_regs = count;
4461 else if (start + count > 16)
4462 num_vfpv3_regs = start + count - 16;
4463
4464 if (num_vfpv3_regs > 0)
4465 {
4466 int start_offset = start > 16 ? start - 16 : 0;
4467 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4468 add_unwind_opcode (op, 2);
4469 }
4470
4471 /* Generate opcode for registers numbered in the range 0 .. 15. */
4472 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4473 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4474 if (num_regs_below_16 > 0)
4475 {
4476 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4477 add_unwind_opcode (op, 2);
4478 }
4479
4480 unwind.frame_size += count * 8;
4481}
4482
4483
4484/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4485
4486static void
c19d1205 4487s_arm_unwind_save_vfp (void)
b99bd4ef 4488{
c19d1205 4489 int count;
ca3f61f7 4490 unsigned int reg;
c19d1205 4491 valueT op;
efd6b359 4492 bfd_boolean partial_match;
b99bd4ef 4493
efd6b359
AV
4494 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4495 &partial_match);
c19d1205 4496 if (count == FAIL)
b99bd4ef 4497 {
c19d1205
ZW
4498 as_bad (_("expected register list"));
4499 ignore_rest_of_line ();
b99bd4ef
NC
4500 return;
4501 }
4502
c19d1205 4503 demand_empty_rest_of_line ();
b99bd4ef 4504
c19d1205 4505 if (reg == 8)
b99bd4ef 4506 {
c19d1205
ZW
4507 /* Short form. */
4508 op = 0xb8 | (count - 1);
4509 add_unwind_opcode (op, 1);
b99bd4ef 4510 }
c19d1205 4511 else
b99bd4ef 4512 {
c19d1205
ZW
4513 /* Long form. */
4514 op = 0xb300 | (reg << 4) | (count - 1);
4515 add_unwind_opcode (op, 2);
b99bd4ef 4516 }
c19d1205
ZW
4517 unwind.frame_size += count * 8 + 4;
4518}
b99bd4ef 4519
b99bd4ef 4520
c19d1205
ZW
4521/* Parse a directive saving iWMMXt data registers. */
4522
4523static void
4524s_arm_unwind_save_mmxwr (void)
4525{
4526 int reg;
4527 int hi_reg;
4528 int i;
4529 unsigned mask = 0;
4530 valueT op;
b99bd4ef 4531
c19d1205
ZW
4532 if (*input_line_pointer == '{')
4533 input_line_pointer++;
b99bd4ef 4534
c19d1205 4535 do
b99bd4ef 4536 {
dcbf9037 4537 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4538
c19d1205 4539 if (reg == FAIL)
b99bd4ef 4540 {
9b7132d3 4541 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4542 goto error;
b99bd4ef
NC
4543 }
4544
c19d1205
ZW
4545 if (mask >> reg)
4546 as_tsktsk (_("register list not in ascending order"));
4547 mask |= 1 << reg;
b99bd4ef 4548
c19d1205
ZW
4549 if (*input_line_pointer == '-')
4550 {
4551 input_line_pointer++;
dcbf9037 4552 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4553 if (hi_reg == FAIL)
4554 {
9b7132d3 4555 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4556 goto error;
4557 }
4558 else if (reg >= hi_reg)
4559 {
4560 as_bad (_("bad register range"));
4561 goto error;
4562 }
4563 for (; reg < hi_reg; reg++)
4564 mask |= 1 << reg;
4565 }
4566 }
4567 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4568
d996d970 4569 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4570
c19d1205 4571 demand_empty_rest_of_line ();
b99bd4ef 4572
708587a4 4573 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4574 the list. */
4575 flush_pending_unwind ();
b99bd4ef 4576
c19d1205 4577 for (i = 0; i < 16; i++)
b99bd4ef 4578 {
c19d1205
ZW
4579 if (mask & (1 << i))
4580 unwind.frame_size += 8;
b99bd4ef
NC
4581 }
4582
c19d1205
ZW
4583 /* Attempt to combine with a previous opcode. We do this because gcc
4584 likes to output separate unwind directives for a single block of
4585 registers. */
4586 if (unwind.opcode_count > 0)
b99bd4ef 4587 {
c19d1205
ZW
4588 i = unwind.opcodes[unwind.opcode_count - 1];
4589 if ((i & 0xf8) == 0xc0)
4590 {
4591 i &= 7;
4592 /* Only merge if the blocks are contiguous. */
4593 if (i < 6)
4594 {
4595 if ((mask & 0xfe00) == (1 << 9))
4596 {
4597 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4598 unwind.opcode_count--;
4599 }
4600 }
4601 else if (i == 6 && unwind.opcode_count >= 2)
4602 {
4603 i = unwind.opcodes[unwind.opcode_count - 2];
4604 reg = i >> 4;
4605 i &= 0xf;
b99bd4ef 4606
c19d1205
ZW
4607 op = 0xffff << (reg - 1);
4608 if (reg > 0
87a1fd79 4609 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4610 {
4611 op = (1 << (reg + i + 1)) - 1;
4612 op &= ~((1 << reg) - 1);
4613 mask |= op;
4614 unwind.opcode_count -= 2;
4615 }
4616 }
4617 }
b99bd4ef
NC
4618 }
4619
c19d1205
ZW
4620 hi_reg = 15;
4621 /* We want to generate opcodes in the order the registers have been
4622 saved, ie. descending order. */
4623 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4624 {
c19d1205
ZW
4625 /* Save registers in blocks. */
4626 if (reg < 0
4627 || !(mask & (1 << reg)))
4628 {
4629 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4630 preceding block. */
c19d1205
ZW
4631 if (reg != hi_reg)
4632 {
4633 if (reg == 9)
4634 {
4635 /* Short form. */
4636 op = 0xc0 | (hi_reg - 10);
4637 add_unwind_opcode (op, 1);
4638 }
4639 else
4640 {
4641 /* Long form. */
4642 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4643 add_unwind_opcode (op, 2);
4644 }
4645 }
4646 hi_reg = reg - 1;
4647 }
b99bd4ef
NC
4648 }
4649
c19d1205
ZW
4650 return;
4651error:
4652 ignore_rest_of_line ();
b99bd4ef
NC
4653}
4654
4655static void
c19d1205 4656s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4657{
c19d1205
ZW
4658 int reg;
4659 int hi_reg;
4660 unsigned mask = 0;
4661 valueT op;
b99bd4ef 4662
c19d1205
ZW
4663 if (*input_line_pointer == '{')
4664 input_line_pointer++;
b99bd4ef 4665
477330fc
RM
4666 skip_whitespace (input_line_pointer);
4667
c19d1205 4668 do
b99bd4ef 4669 {
dcbf9037 4670 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4671
c19d1205
ZW
4672 if (reg == FAIL)
4673 {
9b7132d3 4674 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4675 goto error;
4676 }
b99bd4ef 4677
c19d1205
ZW
4678 reg -= 8;
4679 if (mask >> reg)
4680 as_tsktsk (_("register list not in ascending order"));
4681 mask |= 1 << reg;
b99bd4ef 4682
c19d1205
ZW
4683 if (*input_line_pointer == '-')
4684 {
4685 input_line_pointer++;
dcbf9037 4686 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4687 if (hi_reg == FAIL)
4688 {
9b7132d3 4689 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4690 goto error;
4691 }
4692 else if (reg >= hi_reg)
4693 {
4694 as_bad (_("bad register range"));
4695 goto error;
4696 }
4697 for (; reg < hi_reg; reg++)
4698 mask |= 1 << reg;
4699 }
b99bd4ef 4700 }
c19d1205 4701 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4702
d996d970 4703 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4704
c19d1205
ZW
4705 demand_empty_rest_of_line ();
4706
708587a4 4707 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4708 the list. */
4709 flush_pending_unwind ();
b99bd4ef 4710
c19d1205 4711 for (reg = 0; reg < 16; reg++)
b99bd4ef 4712 {
c19d1205
ZW
4713 if (mask & (1 << reg))
4714 unwind.frame_size += 4;
b99bd4ef 4715 }
c19d1205
ZW
4716 op = 0xc700 | mask;
4717 add_unwind_opcode (op, 2);
4718 return;
4719error:
4720 ignore_rest_of_line ();
b99bd4ef
NC
4721}
4722
c19d1205 4723
fa073d69
MS
4724/* Parse an unwind_save directive.
4725 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4726
b99bd4ef 4727static void
fa073d69 4728s_arm_unwind_save (int arch_v6)
b99bd4ef 4729{
c19d1205
ZW
4730 char *peek;
4731 struct reg_entry *reg;
4732 bfd_boolean had_brace = FALSE;
b99bd4ef 4733
921e5f0a 4734 if (!unwind.proc_start)
c921be7d 4735 as_bad (MISSING_FNSTART);
921e5f0a 4736
c19d1205
ZW
4737 /* Figure out what sort of save we have. */
4738 peek = input_line_pointer;
b99bd4ef 4739
c19d1205 4740 if (*peek == '{')
b99bd4ef 4741 {
c19d1205
ZW
4742 had_brace = TRUE;
4743 peek++;
b99bd4ef
NC
4744 }
4745
c19d1205 4746 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4747
c19d1205 4748 if (!reg)
b99bd4ef 4749 {
c19d1205
ZW
4750 as_bad (_("register expected"));
4751 ignore_rest_of_line ();
b99bd4ef
NC
4752 return;
4753 }
4754
c19d1205 4755 switch (reg->type)
b99bd4ef 4756 {
c19d1205
ZW
4757 case REG_TYPE_FN:
4758 if (had_brace)
4759 {
4760 as_bad (_("FPA .unwind_save does not take a register list"));
4761 ignore_rest_of_line ();
4762 return;
4763 }
93ac2687 4764 input_line_pointer = peek;
c19d1205 4765 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4766 return;
c19d1205 4767
1f5afe1c
NC
4768 case REG_TYPE_RN:
4769 s_arm_unwind_save_core ();
4770 return;
4771
fa073d69
MS
4772 case REG_TYPE_VFD:
4773 if (arch_v6)
477330fc 4774 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4775 else
477330fc 4776 s_arm_unwind_save_vfp ();
fa073d69 4777 return;
1f5afe1c
NC
4778
4779 case REG_TYPE_MMXWR:
4780 s_arm_unwind_save_mmxwr ();
4781 return;
4782
4783 case REG_TYPE_MMXWCG:
4784 s_arm_unwind_save_mmxwcg ();
4785 return;
c19d1205
ZW
4786
4787 default:
4788 as_bad (_(".unwind_save does not support this kind of register"));
4789 ignore_rest_of_line ();
b99bd4ef 4790 }
c19d1205 4791}
b99bd4ef 4792
b99bd4ef 4793
c19d1205
ZW
4794/* Parse an unwind_movsp directive. */
4795
4796static void
4797s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4798{
4799 int reg;
4800 valueT op;
4fa3602b 4801 int offset;
c19d1205 4802
921e5f0a 4803 if (!unwind.proc_start)
c921be7d 4804 as_bad (MISSING_FNSTART);
921e5f0a 4805
dcbf9037 4806 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4807 if (reg == FAIL)
b99bd4ef 4808 {
9b7132d3 4809 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4810 ignore_rest_of_line ();
b99bd4ef
NC
4811 return;
4812 }
4fa3602b
PB
4813
4814 /* Optional constant. */
4815 if (skip_past_comma (&input_line_pointer) != FAIL)
4816 {
4817 if (immediate_for_directive (&offset) == FAIL)
4818 return;
4819 }
4820 else
4821 offset = 0;
4822
c19d1205 4823 demand_empty_rest_of_line ();
b99bd4ef 4824
c19d1205 4825 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4826 {
c19d1205 4827 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4828 return;
4829 }
4830
c19d1205
ZW
4831 if (unwind.fp_reg != REG_SP)
4832 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4833
c19d1205
ZW
4834 /* Generate opcode to restore the value. */
4835 op = 0x90 | reg;
4836 add_unwind_opcode (op, 1);
4837
4838 /* Record the information for later. */
4839 unwind.fp_reg = reg;
4fa3602b 4840 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4841 unwind.sp_restored = 1;
b05fe5cf
ZW
4842}
4843
c19d1205
ZW
4844/* Parse an unwind_pad directive. */
4845
b05fe5cf 4846static void
c19d1205 4847s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4848{
c19d1205 4849 int offset;
b05fe5cf 4850
921e5f0a 4851 if (!unwind.proc_start)
c921be7d 4852 as_bad (MISSING_FNSTART);
921e5f0a 4853
c19d1205
ZW
4854 if (immediate_for_directive (&offset) == FAIL)
4855 return;
b99bd4ef 4856
c19d1205
ZW
4857 if (offset & 3)
4858 {
4859 as_bad (_("stack increment must be multiple of 4"));
4860 ignore_rest_of_line ();
4861 return;
4862 }
b99bd4ef 4863
c19d1205
ZW
4864 /* Don't generate any opcodes, just record the details for later. */
4865 unwind.frame_size += offset;
4866 unwind.pending_offset += offset;
4867
4868 demand_empty_rest_of_line ();
4869}
4870
4871/* Parse an unwind_setfp directive. */
4872
4873static void
4874s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4875{
c19d1205
ZW
4876 int sp_reg;
4877 int fp_reg;
4878 int offset;
4879
921e5f0a 4880 if (!unwind.proc_start)
c921be7d 4881 as_bad (MISSING_FNSTART);
921e5f0a 4882
dcbf9037 4883 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4884 if (skip_past_comma (&input_line_pointer) == FAIL)
4885 sp_reg = FAIL;
4886 else
dcbf9037 4887 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4888
c19d1205
ZW
4889 if (fp_reg == FAIL || sp_reg == FAIL)
4890 {
4891 as_bad (_("expected <reg>, <reg>"));
4892 ignore_rest_of_line ();
4893 return;
4894 }
b99bd4ef 4895
c19d1205
ZW
4896 /* Optional constant. */
4897 if (skip_past_comma (&input_line_pointer) != FAIL)
4898 {
4899 if (immediate_for_directive (&offset) == FAIL)
4900 return;
4901 }
4902 else
4903 offset = 0;
a737bd4d 4904
c19d1205 4905 demand_empty_rest_of_line ();
a737bd4d 4906
fdfde340 4907 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4908 {
c19d1205
ZW
4909 as_bad (_("register must be either sp or set by a previous"
4910 "unwind_movsp directive"));
4911 return;
a737bd4d
NC
4912 }
4913
c19d1205
ZW
4914 /* Don't generate any opcodes, just record the information for later. */
4915 unwind.fp_reg = fp_reg;
4916 unwind.fp_used = 1;
fdfde340 4917 if (sp_reg == REG_SP)
c19d1205
ZW
4918 unwind.fp_offset = unwind.frame_size - offset;
4919 else
4920 unwind.fp_offset -= offset;
a737bd4d
NC
4921}
4922
c19d1205
ZW
4923/* Parse an unwind_raw directive. */
4924
4925static void
4926s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4927{
c19d1205 4928 expressionS exp;
708587a4 4929 /* This is an arbitrary limit. */
c19d1205
ZW
4930 unsigned char op[16];
4931 int count;
a737bd4d 4932
921e5f0a 4933 if (!unwind.proc_start)
c921be7d 4934 as_bad (MISSING_FNSTART);
921e5f0a 4935
c19d1205
ZW
4936 expression (&exp);
4937 if (exp.X_op == O_constant
4938 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4939 {
c19d1205
ZW
4940 unwind.frame_size += exp.X_add_number;
4941 expression (&exp);
4942 }
4943 else
4944 exp.X_op = O_illegal;
a737bd4d 4945
c19d1205
ZW
4946 if (exp.X_op != O_constant)
4947 {
4948 as_bad (_("expected <offset>, <opcode>"));
4949 ignore_rest_of_line ();
4950 return;
4951 }
a737bd4d 4952
c19d1205 4953 count = 0;
a737bd4d 4954
c19d1205
ZW
4955 /* Parse the opcode. */
4956 for (;;)
4957 {
4958 if (count >= 16)
4959 {
4960 as_bad (_("unwind opcode too long"));
4961 ignore_rest_of_line ();
a737bd4d 4962 }
c19d1205 4963 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4964 {
c19d1205
ZW
4965 as_bad (_("invalid unwind opcode"));
4966 ignore_rest_of_line ();
4967 return;
a737bd4d 4968 }
c19d1205 4969 op[count++] = exp.X_add_number;
a737bd4d 4970
c19d1205
ZW
4971 /* Parse the next byte. */
4972 if (skip_past_comma (&input_line_pointer) == FAIL)
4973 break;
a737bd4d 4974
c19d1205
ZW
4975 expression (&exp);
4976 }
b99bd4ef 4977
c19d1205
ZW
4978 /* Add the opcode bytes in reverse order. */
4979 while (count--)
4980 add_unwind_opcode (op[count], 1);
b99bd4ef 4981
c19d1205 4982 demand_empty_rest_of_line ();
b99bd4ef 4983}
ee065d83
PB
4984
4985
4986/* Parse a .eabi_attribute directive. */
4987
4988static void
4989s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4990{
0420f52b 4991 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4992
3076e594 4993 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4994 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4995}
4996
0855e32b
NS
4997/* Emit a tls fix for the symbol. */
4998
4999static void
5000s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
5001{
5002 char *p;
5003 expressionS exp;
5004#ifdef md_flush_pending_output
5005 md_flush_pending_output ();
5006#endif
5007
5008#ifdef md_cons_align
5009 md_cons_align (4);
5010#endif
5011
5012 /* Since we're just labelling the code, there's no need to define a
5013 mapping symbol. */
5014 expression (&exp);
5015 p = obstack_next_free (&frchain_now->frch_obstack);
5016 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5017 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5018 : BFD_RELOC_ARM_TLS_DESCSEQ);
5019}
cdf9ccec 5020#endif /* OBJ_ELF */
0855e32b 5021
ee065d83 5022static void s_arm_arch (int);
7a1d4c38 5023static void s_arm_object_arch (int);
ee065d83
PB
5024static void s_arm_cpu (int);
5025static void s_arm_fpu (int);
69133863 5026static void s_arm_arch_extension (int);
b99bd4ef 5027
f0927246
NC
5028#ifdef TE_PE
5029
5030static void
5f4273c7 5031pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
5032{
5033 expressionS exp;
5034
5035 do
5036 {
5037 expression (&exp);
5038 if (exp.X_op == O_symbol)
5039 exp.X_op = O_secrel;
5040
5041 emit_expr (&exp, 4);
5042 }
5043 while (*input_line_pointer++ == ',');
5044
5045 input_line_pointer--;
5046 demand_empty_rest_of_line ();
5047}
5048#endif /* TE_PE */
5049
5312fe52
BW
5050int
5051arm_is_largest_exponent_ok (int precision)
5052{
5053 /* precision == 1 ensures that this will only return
5054 true for 16 bit floats. */
5055 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5056}
5057
5058static void
5059set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5060{
5061 char saved_char;
5062 char* name;
5063 enum fp_16bit_format new_format;
5064
5065 new_format = ARM_FP16_FORMAT_DEFAULT;
5066
5067 name = input_line_pointer;
5068 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5069 input_line_pointer++;
5070
5071 saved_char = *input_line_pointer;
5072 *input_line_pointer = 0;
5073
5074 if (strcasecmp (name, "ieee") == 0)
5075 new_format = ARM_FP16_FORMAT_IEEE;
5076 else if (strcasecmp (name, "alternative") == 0)
5077 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5078 else
5079 {
5080 as_bad (_("unrecognised float16 format \"%s\""), name);
5081 goto cleanup;
5082 }
5083
5084 /* Only set fp16_format if it is still the default (aka not already
5085 been set yet). */
5086 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5087 fp16_format = new_format;
5088 else
5089 {
5090 if (new_format != fp16_format)
5091 as_warn (_("float16 format cannot be set more than once, ignoring."));
5092 }
5093
5094cleanup:
5095 *input_line_pointer = saved_char;
5096 ignore_rest_of_line ();
5097}
5098
c19d1205
ZW
5099/* This table describes all the machine specific pseudo-ops the assembler
5100 has to support. The fields are:
5101 pseudo-op name without dot
5102 function to call to execute this pseudo-op
5103 Integer arg to pass to the function. */
b99bd4ef 5104
c19d1205 5105const pseudo_typeS md_pseudo_table[] =
b99bd4ef 5106{
c19d1205
ZW
5107 /* Never called because '.req' does not start a line. */
5108 { "req", s_req, 0 },
dcbf9037
JB
5109 /* Following two are likewise never called. */
5110 { "dn", s_dn, 0 },
5111 { "qn", s_qn, 0 },
c19d1205
ZW
5112 { "unreq", s_unreq, 0 },
5113 { "bss", s_bss, 0 },
db2ed2e0 5114 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5115 { "arm", s_arm, 0 },
5116 { "thumb", s_thumb, 0 },
5117 { "code", s_code, 0 },
5118 { "force_thumb", s_force_thumb, 0 },
5119 { "thumb_func", s_thumb_func, 0 },
5120 { "thumb_set", s_thumb_set, 0 },
5121 { "even", s_even, 0 },
5122 { "ltorg", s_ltorg, 0 },
5123 { "pool", s_ltorg, 0 },
5124 { "syntax", s_syntax, 0 },
8463be01
PB
5125 { "cpu", s_arm_cpu, 0 },
5126 { "arch", s_arm_arch, 0 },
7a1d4c38 5127 { "object_arch", s_arm_object_arch, 0 },
8463be01 5128 { "fpu", s_arm_fpu, 0 },
69133863 5129 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5130#ifdef OBJ_ELF
c921be7d
NC
5131 { "word", s_arm_elf_cons, 4 },
5132 { "long", s_arm_elf_cons, 4 },
5133 { "inst.n", s_arm_elf_inst, 2 },
5134 { "inst.w", s_arm_elf_inst, 4 },
5135 { "inst", s_arm_elf_inst, 0 },
5136 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5137 { "fnstart", s_arm_unwind_fnstart, 0 },
5138 { "fnend", s_arm_unwind_fnend, 0 },
5139 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5140 { "personality", s_arm_unwind_personality, 0 },
5141 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5142 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5143 { "save", s_arm_unwind_save, 0 },
fa073d69 5144 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5145 { "movsp", s_arm_unwind_movsp, 0 },
5146 { "pad", s_arm_unwind_pad, 0 },
5147 { "setfp", s_arm_unwind_setfp, 0 },
5148 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5149 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5150 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5151#else
5152 { "word", cons, 4},
f0927246
NC
5153
5154 /* These are used for dwarf. */
5155 {"2byte", cons, 2},
5156 {"4byte", cons, 4},
5157 {"8byte", cons, 8},
5158 /* These are used for dwarf2. */
68d20676 5159 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5160 { "loc", dwarf2_directive_loc, 0 },
5161 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5162#endif
5163 { "extend", float_cons, 'x' },
5164 { "ldouble", float_cons, 'x' },
5165 { "packed", float_cons, 'p' },
27cce866 5166 { "bfloat16", float_cons, 'b' },
f0927246
NC
5167#ifdef TE_PE
5168 {"secrel32", pe_directive_secrel, 0},
5169#endif
2e6976a8
DG
5170
5171 /* These are for compatibility with CodeComposer Studio. */
5172 {"ref", s_ccs_ref, 0},
5173 {"def", s_ccs_def, 0},
5174 {"asmfunc", s_ccs_asmfunc, 0},
5175 {"endasmfunc", s_ccs_endasmfunc, 0},
5176
5312fe52
BW
5177 {"float16", float_cons, 'h' },
5178 {"float16_format", set_fp16_format, 0 },
5179
c19d1205
ZW
5180 { 0, 0, 0 }
5181};
5312fe52 5182
c19d1205 5183/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5184
c19d1205
ZW
5185/* Generic immediate-value read function for use in insn parsing.
5186 STR points to the beginning of the immediate (the leading #);
5187 VAL receives the value; if the value is outside [MIN, MAX]
5188 issue an error. PREFIX_OPT is true if the immediate prefix is
5189 optional. */
b99bd4ef 5190
c19d1205
ZW
5191static int
5192parse_immediate (char **str, int *val, int min, int max,
5193 bfd_boolean prefix_opt)
5194{
5195 expressionS exp;
0198d5e6 5196
c19d1205
ZW
5197 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5198 if (exp.X_op != O_constant)
b99bd4ef 5199 {
c19d1205
ZW
5200 inst.error = _("constant expression required");
5201 return FAIL;
5202 }
b99bd4ef 5203
c19d1205
ZW
5204 if (exp.X_add_number < min || exp.X_add_number > max)
5205 {
5206 inst.error = _("immediate value out of range");
5207 return FAIL;
5208 }
b99bd4ef 5209
c19d1205
ZW
5210 *val = exp.X_add_number;
5211 return SUCCESS;
5212}
b99bd4ef 5213
5287ad62 5214/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5215 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5216 instructions. Puts the result directly in inst.operands[i]. */
5217
5218static int
8335d6aa
JW
5219parse_big_immediate (char **str, int i, expressionS *in_exp,
5220 bfd_boolean allow_symbol_p)
5287ad62
JB
5221{
5222 expressionS exp;
8335d6aa 5223 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5224 char *ptr = *str;
5225
8335d6aa 5226 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5227
8335d6aa 5228 if (exp_p->X_op == O_constant)
036dc3f7 5229 {
8335d6aa 5230 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5231 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5232 O_constant. We have to be careful not to break compilation for
5233 32-bit X_add_number, though. */
8335d6aa 5234 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5235 {
8335d6aa
JW
5236 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5237 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5238 & 0xffffffff);
036dc3f7
PB
5239 inst.operands[i].regisimm = 1;
5240 }
5241 }
8335d6aa
JW
5242 else if (exp_p->X_op == O_big
5243 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5244 {
5245 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5246
5287ad62 5247 /* Bignums have their least significant bits in
477330fc
RM
5248 generic_bignum[0]. Make sure we put 32 bits in imm and
5249 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5250 gas_assert (parts != 0);
95b75c01
NC
5251
5252 /* Make sure that the number is not too big.
5253 PR 11972: Bignums can now be sign-extended to the
5254 size of a .octa so check that the out of range bits
5255 are all zero or all one. */
8335d6aa 5256 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5257 {
5258 LITTLENUM_TYPE m = -1;
5259
5260 if (generic_bignum[parts * 2] != 0
5261 && generic_bignum[parts * 2] != m)
5262 return FAIL;
5263
8335d6aa 5264 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5265 if (generic_bignum[j] != generic_bignum[j-1])
5266 return FAIL;
5267 }
5268
5287ad62
JB
5269 inst.operands[i].imm = 0;
5270 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5271 inst.operands[i].imm |= generic_bignum[idx]
5272 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5273 inst.operands[i].reg = 0;
5274 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5275 inst.operands[i].reg |= generic_bignum[idx]
5276 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5277 inst.operands[i].regisimm = 1;
5278 }
8335d6aa 5279 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5280 return FAIL;
5f4273c7 5281
5287ad62
JB
5282 *str = ptr;
5283
5284 return SUCCESS;
5285}
5286
c19d1205
ZW
5287/* Returns the pseudo-register number of an FPA immediate constant,
5288 or FAIL if there isn't a valid constant here. */
b99bd4ef 5289
c19d1205
ZW
5290static int
5291parse_fpa_immediate (char ** str)
5292{
5293 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5294 char * save_in;
5295 expressionS exp;
5296 int i;
5297 int j;
b99bd4ef 5298
c19d1205
ZW
5299 /* First try and match exact strings, this is to guarantee
5300 that some formats will work even for cross assembly. */
b99bd4ef 5301
c19d1205
ZW
5302 for (i = 0; fp_const[i]; i++)
5303 {
5304 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5305 {
c19d1205 5306 char *start = *str;
b99bd4ef 5307
c19d1205
ZW
5308 *str += strlen (fp_const[i]);
5309 if (is_end_of_line[(unsigned char) **str])
5310 return i + 8;
5311 *str = start;
5312 }
5313 }
b99bd4ef 5314
c19d1205
ZW
5315 /* Just because we didn't get a match doesn't mean that the constant
5316 isn't valid, just that it is in a format that we don't
5317 automatically recognize. Try parsing it with the standard
5318 expression routines. */
b99bd4ef 5319
c19d1205 5320 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5321
c19d1205
ZW
5322 /* Look for a raw floating point number. */
5323 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5324 && is_end_of_line[(unsigned char) *save_in])
5325 {
5326 for (i = 0; i < NUM_FLOAT_VALS; i++)
5327 {
5328 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5329 {
c19d1205
ZW
5330 if (words[j] != fp_values[i][j])
5331 break;
b99bd4ef
NC
5332 }
5333
c19d1205 5334 if (j == MAX_LITTLENUMS)
b99bd4ef 5335 {
c19d1205
ZW
5336 *str = save_in;
5337 return i + 8;
b99bd4ef
NC
5338 }
5339 }
5340 }
b99bd4ef 5341
c19d1205
ZW
5342 /* Try and parse a more complex expression, this will probably fail
5343 unless the code uses a floating point prefix (eg "0f"). */
5344 save_in = input_line_pointer;
5345 input_line_pointer = *str;
5346 if (expression (&exp) == absolute_section
5347 && exp.X_op == O_big
5348 && exp.X_add_number < 0)
5349 {
5350 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5351 Ditto for 15. */
ba592044
AM
5352#define X_PRECISION 5
5353#define E_PRECISION 15L
5354 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5355 {
5356 for (i = 0; i < NUM_FLOAT_VALS; i++)
5357 {
5358 for (j = 0; j < MAX_LITTLENUMS; j++)
5359 {
5360 if (words[j] != fp_values[i][j])
5361 break;
5362 }
b99bd4ef 5363
c19d1205
ZW
5364 if (j == MAX_LITTLENUMS)
5365 {
5366 *str = input_line_pointer;
5367 input_line_pointer = save_in;
5368 return i + 8;
5369 }
5370 }
5371 }
b99bd4ef
NC
5372 }
5373
c19d1205
ZW
5374 *str = input_line_pointer;
5375 input_line_pointer = save_in;
5376 inst.error = _("invalid FPA immediate expression");
5377 return FAIL;
b99bd4ef
NC
5378}
5379
136da414
JB
5380/* Returns 1 if a number has "quarter-precision" float format
5381 0baBbbbbbc defgh000 00000000 00000000. */
5382
5383static int
5384is_quarter_float (unsigned imm)
5385{
5386 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5387 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5388}
5389
aacf0b33
KT
5390
5391/* Detect the presence of a floating point or integer zero constant,
5392 i.e. #0.0 or #0. */
5393
5394static bfd_boolean
5395parse_ifimm_zero (char **in)
5396{
5397 int error_code;
5398
5399 if (!is_immediate_prefix (**in))
3c6452ae
TP
5400 {
5401 /* In unified syntax, all prefixes are optional. */
5402 if (!unified_syntax)
5403 return FALSE;
5404 }
5405 else
5406 ++*in;
0900a05b
JW
5407
5408 /* Accept #0x0 as a synonym for #0. */
5409 if (strncmp (*in, "0x", 2) == 0)
5410 {
5411 int val;
5412 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5413 return FALSE;
5414 return TRUE;
5415 }
5416
aacf0b33
KT
5417 error_code = atof_generic (in, ".", EXP_CHARS,
5418 &generic_floating_point_number);
5419
5420 if (!error_code
5421 && generic_floating_point_number.sign == '+'
5422 && (generic_floating_point_number.low
5423 > generic_floating_point_number.leader))
5424 return TRUE;
5425
5426 return FALSE;
5427}
5428
136da414
JB
5429/* Parse an 8-bit "quarter-precision" floating point number of the form:
5430 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5431 The zero and minus-zero cases need special handling, since they can't be
5432 encoded in the "quarter-precision" float format, but can nonetheless be
5433 loaded as integer constants. */
136da414
JB
5434
5435static unsigned
5436parse_qfloat_immediate (char **ccp, int *immed)
5437{
5438 char *str = *ccp;
c96612cc 5439 char *fpnum;
136da414 5440 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5441 int found_fpchar = 0;
5f4273c7 5442
136da414 5443 skip_past_char (&str, '#');
5f4273c7 5444
c96612cc
JB
5445 /* We must not accidentally parse an integer as a floating-point number. Make
5446 sure that the value we parse is not an integer by checking for special
5447 characters '.' or 'e'.
5448 FIXME: This is a horrible hack, but doing better is tricky because type
5449 information isn't in a very usable state at parse time. */
5450 fpnum = str;
5451 skip_whitespace (fpnum);
5452
5453 if (strncmp (fpnum, "0x", 2) == 0)
5454 return FAIL;
5455 else
5456 {
5457 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5458 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5459 {
5460 found_fpchar = 1;
5461 break;
5462 }
c96612cc
JB
5463
5464 if (!found_fpchar)
477330fc 5465 return FAIL;
c96612cc 5466 }
5f4273c7 5467
136da414
JB
5468 if ((str = atof_ieee (str, 's', words)) != NULL)
5469 {
5470 unsigned fpword = 0;
5471 int i;
5f4273c7 5472
136da414
JB
5473 /* Our FP word must be 32 bits (single-precision FP). */
5474 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5475 {
5476 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5477 fpword |= words[i];
5478 }
5f4273c7 5479
c96612cc 5480 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5481 *immed = fpword;
136da414 5482 else
477330fc 5483 return FAIL;
136da414
JB
5484
5485 *ccp = str;
5f4273c7 5486
136da414
JB
5487 return SUCCESS;
5488 }
5f4273c7 5489
136da414
JB
5490 return FAIL;
5491}
5492
c19d1205
ZW
5493/* Shift operands. */
5494enum shift_kind
b99bd4ef 5495{
f5f10c66 5496 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5497};
b99bd4ef 5498
c19d1205
ZW
5499struct asm_shift_name
5500{
5501 const char *name;
5502 enum shift_kind kind;
5503};
b99bd4ef 5504
c19d1205
ZW
5505/* Third argument to parse_shift. */
5506enum parse_shift_mode
5507{
5508 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5509 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5510 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5511 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5512 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5513 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5514};
b99bd4ef 5515
c19d1205
ZW
5516/* Parse a <shift> specifier on an ARM data processing instruction.
5517 This has three forms:
b99bd4ef 5518
c19d1205
ZW
5519 (LSL|LSR|ASL|ASR|ROR) Rs
5520 (LSL|LSR|ASL|ASR|ROR) #imm
5521 RRX
b99bd4ef 5522
c19d1205
ZW
5523 Note that ASL is assimilated to LSL in the instruction encoding, and
5524 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5525
c19d1205
ZW
5526static int
5527parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5528{
c19d1205
ZW
5529 const struct asm_shift_name *shift_name;
5530 enum shift_kind shift;
5531 char *s = *str;
5532 char *p = s;
5533 int reg;
b99bd4ef 5534
c19d1205
ZW
5535 for (p = *str; ISALPHA (*p); p++)
5536 ;
b99bd4ef 5537
c19d1205 5538 if (p == *str)
b99bd4ef 5539 {
c19d1205
ZW
5540 inst.error = _("shift expression expected");
5541 return FAIL;
b99bd4ef
NC
5542 }
5543
21d799b5 5544 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5545 p - *str);
c19d1205
ZW
5546
5547 if (shift_name == NULL)
b99bd4ef 5548 {
c19d1205
ZW
5549 inst.error = _("shift expression expected");
5550 return FAIL;
b99bd4ef
NC
5551 }
5552
c19d1205 5553 shift = shift_name->kind;
b99bd4ef 5554
c19d1205
ZW
5555 switch (mode)
5556 {
5557 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5558 case SHIFT_IMMEDIATE:
5559 if (shift == SHIFT_UXTW)
5560 {
5561 inst.error = _("'UXTW' not allowed here");
5562 return FAIL;
5563 }
5564 break;
b99bd4ef 5565
c19d1205
ZW
5566 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5567 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5568 {
5569 inst.error = _("'LSL' or 'ASR' required");
5570 return FAIL;
5571 }
5572 break;
b99bd4ef 5573
c19d1205
ZW
5574 case SHIFT_LSL_IMMEDIATE:
5575 if (shift != SHIFT_LSL)
5576 {
5577 inst.error = _("'LSL' required");
5578 return FAIL;
5579 }
5580 break;
b99bd4ef 5581
c19d1205
ZW
5582 case SHIFT_ASR_IMMEDIATE:
5583 if (shift != SHIFT_ASR)
5584 {
5585 inst.error = _("'ASR' required");
5586 return FAIL;
5587 }
5588 break;
f5f10c66
AV
5589 case SHIFT_UXTW_IMMEDIATE:
5590 if (shift != SHIFT_UXTW)
5591 {
5592 inst.error = _("'UXTW' required");
5593 return FAIL;
5594 }
5595 break;
b99bd4ef 5596
c19d1205
ZW
5597 default: abort ();
5598 }
b99bd4ef 5599
c19d1205
ZW
5600 if (shift != SHIFT_RRX)
5601 {
5602 /* Whitespace can appear here if the next thing is a bare digit. */
5603 skip_whitespace (p);
b99bd4ef 5604
c19d1205 5605 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5606 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5607 {
5608 inst.operands[i].imm = reg;
5609 inst.operands[i].immisreg = 1;
5610 }
e2b0ab59 5611 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5612 return FAIL;
5613 }
5614 inst.operands[i].shift_kind = shift;
5615 inst.operands[i].shifted = 1;
5616 *str = p;
5617 return SUCCESS;
b99bd4ef
NC
5618}
5619
c19d1205 5620/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5621
c19d1205
ZW
5622 #<immediate>
5623 #<immediate>, <rotate>
5624 <Rm>
5625 <Rm>, <shift>
b99bd4ef 5626
c19d1205
ZW
5627 where <shift> is defined by parse_shift above, and <rotate> is a
5628 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5629 is deferred to md_apply_fix. */
b99bd4ef 5630
c19d1205
ZW
5631static int
5632parse_shifter_operand (char **str, int i)
5633{
5634 int value;
91d6fa6a 5635 expressionS exp;
b99bd4ef 5636
dcbf9037 5637 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5638 {
5639 inst.operands[i].reg = value;
5640 inst.operands[i].isreg = 1;
b99bd4ef 5641
c19d1205 5642 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5643 inst.relocs[0].exp.X_op = O_constant;
5644 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5645
c19d1205
ZW
5646 if (skip_past_comma (str) == FAIL)
5647 return SUCCESS;
b99bd4ef 5648
c19d1205
ZW
5649 /* Shift operation on register. */
5650 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5651 }
5652
e2b0ab59 5653 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5654 return FAIL;
b99bd4ef 5655
c19d1205 5656 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5657 {
c19d1205 5658 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5659 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5660 return FAIL;
b99bd4ef 5661
e2b0ab59 5662 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5663 {
5664 inst.error = _("constant expression expected");
5665 return FAIL;
5666 }
b99bd4ef 5667
91d6fa6a 5668 value = exp.X_add_number;
c19d1205
ZW
5669 if (value < 0 || value > 30 || value % 2 != 0)
5670 {
5671 inst.error = _("invalid rotation");
5672 return FAIL;
5673 }
e2b0ab59
AV
5674 if (inst.relocs[0].exp.X_add_number < 0
5675 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5676 {
5677 inst.error = _("invalid constant");
5678 return FAIL;
5679 }
09d92015 5680
a415b1cd 5681 /* Encode as specified. */
e2b0ab59 5682 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5683 return SUCCESS;
09d92015
MM
5684 }
5685
e2b0ab59
AV
5686 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5687 inst.relocs[0].pc_rel = 0;
c19d1205 5688 return SUCCESS;
09d92015
MM
5689}
5690
4962c51a
MS
5691/* Group relocation information. Each entry in the table contains the
5692 textual name of the relocation as may appear in assembler source
5693 and must end with a colon.
5694 Along with this textual name are the relocation codes to be used if
5695 the corresponding instruction is an ALU instruction (ADD or SUB only),
5696 an LDR, an LDRS, or an LDC. */
5697
5698struct group_reloc_table_entry
5699{
5700 const char *name;
5701 int alu_code;
5702 int ldr_code;
5703 int ldrs_code;
5704 int ldc_code;
5705};
5706
5707typedef enum
5708{
5709 /* Varieties of non-ALU group relocation. */
5710
5711 GROUP_LDR,
5712 GROUP_LDRS,
35c228db
AV
5713 GROUP_LDC,
5714 GROUP_MVE
4962c51a
MS
5715} group_reloc_type;
5716
5717static struct group_reloc_table_entry group_reloc_table[] =
5718 { /* Program counter relative: */
5719 { "pc_g0_nc",
5720 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5721 0, /* LDR */
5722 0, /* LDRS */
5723 0 }, /* LDC */
5724 { "pc_g0",
5725 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5726 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5727 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5728 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5729 { "pc_g1_nc",
5730 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5731 0, /* LDR */
5732 0, /* LDRS */
5733 0 }, /* LDC */
5734 { "pc_g1",
5735 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5736 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5737 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5738 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5739 { "pc_g2",
5740 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5741 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5742 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5743 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5744 /* Section base relative */
5745 { "sb_g0_nc",
5746 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5747 0, /* LDR */
5748 0, /* LDRS */
5749 0 }, /* LDC */
5750 { "sb_g0",
5751 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5752 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5753 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5754 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5755 { "sb_g1_nc",
5756 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5757 0, /* LDR */
5758 0, /* LDRS */
5759 0 }, /* LDC */
5760 { "sb_g1",
5761 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5762 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5763 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5764 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5765 { "sb_g2",
5766 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5767 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5768 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5769 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5770 /* Absolute thumb alu relocations. */
5771 { "lower0_7",
5772 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5773 0, /* LDR. */
5774 0, /* LDRS. */
5775 0 }, /* LDC. */
5776 { "lower8_15",
5777 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5778 0, /* LDR. */
5779 0, /* LDRS. */
5780 0 }, /* LDC. */
5781 { "upper0_7",
5782 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5783 0, /* LDR. */
5784 0, /* LDRS. */
5785 0 }, /* LDC. */
5786 { "upper8_15",
5787 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5788 0, /* LDR. */
5789 0, /* LDRS. */
5790 0 } }; /* LDC. */
4962c51a
MS
5791
5792/* Given the address of a pointer pointing to the textual name of a group
5793 relocation as may appear in assembler source, attempt to find its details
5794 in group_reloc_table. The pointer will be updated to the character after
5795 the trailing colon. On failure, FAIL will be returned; SUCCESS
5796 otherwise. On success, *entry will be updated to point at the relevant
5797 group_reloc_table entry. */
5798
5799static int
5800find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5801{
5802 unsigned int i;
5803 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5804 {
5805 int length = strlen (group_reloc_table[i].name);
5806
5f4273c7
NC
5807 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5808 && (*str)[length] == ':')
477330fc
RM
5809 {
5810 *out = &group_reloc_table[i];
5811 *str += (length + 1);
5812 return SUCCESS;
5813 }
4962c51a
MS
5814 }
5815
5816 return FAIL;
5817}
5818
5819/* Parse a <shifter_operand> for an ARM data processing instruction
5820 (as for parse_shifter_operand) where group relocations are allowed:
5821
5822 #<immediate>
5823 #<immediate>, <rotate>
5824 #:<group_reloc>:<expression>
5825 <Rm>
5826 <Rm>, <shift>
5827
5828 where <group_reloc> is one of the strings defined in group_reloc_table.
5829 The hashes are optional.
5830
5831 Everything else is as for parse_shifter_operand. */
5832
5833static parse_operand_result
5834parse_shifter_operand_group_reloc (char **str, int i)
5835{
5836 /* Determine if we have the sequence of characters #: or just :
5837 coming next. If we do, then we check for a group relocation.
5838 If we don't, punt the whole lot to parse_shifter_operand. */
5839
5840 if (((*str)[0] == '#' && (*str)[1] == ':')
5841 || (*str)[0] == ':')
5842 {
5843 struct group_reloc_table_entry *entry;
5844
5845 if ((*str)[0] == '#')
477330fc 5846 (*str) += 2;
4962c51a 5847 else
477330fc 5848 (*str)++;
4962c51a
MS
5849
5850 /* Try to parse a group relocation. Anything else is an error. */
5851 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5852 {
5853 inst.error = _("unknown group relocation");
5854 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5855 }
4962c51a
MS
5856
5857 /* We now have the group relocation table entry corresponding to
477330fc 5858 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5859 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5860 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5861
5862 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5863 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5864 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5865
5866 return PARSE_OPERAND_SUCCESS;
5867 }
5868 else
5869 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5870 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5871
5872 /* Never reached. */
5873}
5874
8e560766
MGD
5875/* Parse a Neon alignment expression. Information is written to
5876 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5877
8e560766
MGD
5878 align .imm = align << 8, .immisalign=1, .preind=0 */
5879static parse_operand_result
5880parse_neon_alignment (char **str, int i)
5881{
5882 char *p = *str;
5883 expressionS exp;
5884
5885 my_get_expression (&exp, &p, GE_NO_PREFIX);
5886
5887 if (exp.X_op != O_constant)
5888 {
5889 inst.error = _("alignment must be constant");
5890 return PARSE_OPERAND_FAIL;
5891 }
5892
5893 inst.operands[i].imm = exp.X_add_number << 8;
5894 inst.operands[i].immisalign = 1;
5895 /* Alignments are not pre-indexes. */
5896 inst.operands[i].preind = 0;
5897
5898 *str = p;
5899 return PARSE_OPERAND_SUCCESS;
5900}
5901
c19d1205 5902/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5903 to inst.operands[i] and/or inst.relocs[0].
09d92015 5904
c19d1205 5905 Preindexed addressing (.preind=1):
09d92015 5906
e2b0ab59 5907 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5908 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5909 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5910 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5911
c19d1205 5912 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5913
c19d1205 5914 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5915
e2b0ab59 5916 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5917 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5918 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5919 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5920
c19d1205 5921 Unindexed addressing (.preind=0, .postind=0):
09d92015 5922
c19d1205 5923 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5924
c19d1205 5925 Other:
09d92015 5926
c19d1205 5927 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5928 =immediate .isreg=0 .relocs[0].exp=immediate
5929 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5930
c19d1205 5931 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5932 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5933
4962c51a
MS
5934static parse_operand_result
5935parse_address_main (char **str, int i, int group_relocations,
477330fc 5936 group_reloc_type group_type)
09d92015 5937{
c19d1205
ZW
5938 char *p = *str;
5939 int reg;
09d92015 5940
c19d1205 5941 if (skip_past_char (&p, '[') == FAIL)
09d92015 5942 {
c19d1205
ZW
5943 if (skip_past_char (&p, '=') == FAIL)
5944 {
974da60d 5945 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5946 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5947 inst.operands[i].reg = REG_PC;
5948 inst.operands[i].isreg = 1;
5949 inst.operands[i].preind = 1;
09d92015 5950
e2b0ab59 5951 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5952 return PARSE_OPERAND_FAIL;
5953 }
e2b0ab59 5954 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5955 /*allow_symbol_p=*/TRUE))
4962c51a 5956 return PARSE_OPERAND_FAIL;
09d92015 5957
c19d1205 5958 *str = p;
4962c51a 5959 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5960 }
5961
8ab8155f
NC
5962 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5963 skip_whitespace (p);
5964
f5f10c66
AV
5965 if (group_type == GROUP_MVE)
5966 {
5967 enum arm_reg_type rtype = REG_TYPE_MQ;
5968 struct neon_type_el et;
5969 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5970 {
5971 inst.operands[i].isquad = 1;
5972 }
5973 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5974 {
5975 inst.error = BAD_ADDR_MODE;
5976 return PARSE_OPERAND_FAIL;
5977 }
5978 }
5979 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5980 {
35c228db
AV
5981 if (group_type == GROUP_MVE)
5982 inst.error = BAD_ADDR_MODE;
5983 else
5984 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5985 return PARSE_OPERAND_FAIL;
09d92015 5986 }
c19d1205
ZW
5987 inst.operands[i].reg = reg;
5988 inst.operands[i].isreg = 1;
09d92015 5989
c19d1205 5990 if (skip_past_comma (&p) == SUCCESS)
09d92015 5991 {
c19d1205 5992 inst.operands[i].preind = 1;
09d92015 5993
c19d1205
ZW
5994 if (*p == '+') p++;
5995 else if (*p == '-') p++, inst.operands[i].negative = 1;
5996
f5f10c66
AV
5997 enum arm_reg_type rtype = REG_TYPE_MQ;
5998 struct neon_type_el et;
5999 if (group_type == GROUP_MVE
6000 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6001 {
6002 inst.operands[i].immisreg = 2;
6003 inst.operands[i].imm = reg;
6004
6005 if (skip_past_comma (&p) == SUCCESS)
6006 {
6007 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6008 {
6009 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6010 inst.relocs[0].exp.X_add_number = 0;
6011 }
6012 else
6013 return PARSE_OPERAND_FAIL;
6014 }
6015 }
6016 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 6017 {
c19d1205
ZW
6018 inst.operands[i].imm = reg;
6019 inst.operands[i].immisreg = 1;
6020
6021 if (skip_past_comma (&p) == SUCCESS)
6022 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6023 return PARSE_OPERAND_FAIL;
c19d1205 6024 }
5287ad62 6025 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
6026 {
6027 /* FIXME: '@' should be used here, but it's filtered out by generic
6028 code before we get to see it here. This may be subject to
6029 change. */
6030 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6031
8e560766
MGD
6032 if (result != PARSE_OPERAND_SUCCESS)
6033 return result;
6034 }
c19d1205
ZW
6035 else
6036 {
6037 if (inst.operands[i].negative)
6038 {
6039 inst.operands[i].negative = 0;
6040 p--;
6041 }
4962c51a 6042
5f4273c7
NC
6043 if (group_relocations
6044 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
6045 {
6046 struct group_reloc_table_entry *entry;
6047
477330fc
RM
6048 /* Skip over the #: or : sequence. */
6049 if (*p == '#')
6050 p += 2;
6051 else
6052 p++;
4962c51a
MS
6053
6054 /* Try to parse a group relocation. Anything else is an
477330fc 6055 error. */
4962c51a
MS
6056 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6057 {
6058 inst.error = _("unknown group relocation");
6059 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6060 }
6061
6062 /* We now have the group relocation table entry corresponding to
6063 the name in the assembler source. Next, we parse the
477330fc 6064 expression. */
e2b0ab59 6065 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
6066 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6067
6068 /* Record the relocation type. */
477330fc
RM
6069 switch (group_type)
6070 {
6071 case GROUP_LDR:
e2b0ab59
AV
6072 inst.relocs[0].type
6073 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 6074 break;
4962c51a 6075
477330fc 6076 case GROUP_LDRS:
e2b0ab59
AV
6077 inst.relocs[0].type
6078 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 6079 break;
4962c51a 6080
477330fc 6081 case GROUP_LDC:
e2b0ab59
AV
6082 inst.relocs[0].type
6083 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 6084 break;
4962c51a 6085
477330fc
RM
6086 default:
6087 gas_assert (0);
6088 }
4962c51a 6089
e2b0ab59 6090 if (inst.relocs[0].type == 0)
4962c51a
MS
6091 {
6092 inst.error = _("this group relocation is not allowed on this instruction");
6093 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6094 }
477330fc
RM
6095 }
6096 else
26d97720
NS
6097 {
6098 char *q = p;
0198d5e6 6099
e2b0ab59 6100 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
6101 return PARSE_OPERAND_FAIL;
6102 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6103 if (inst.relocs[0].exp.X_op == O_constant
6104 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6105 {
6106 skip_whitespace (q);
6107 if (*q == '#')
6108 {
6109 q++;
6110 skip_whitespace (q);
6111 }
6112 if (*q == '-')
6113 inst.operands[i].negative = 1;
6114 }
6115 }
09d92015
MM
6116 }
6117 }
8e560766
MGD
6118 else if (skip_past_char (&p, ':') == SUCCESS)
6119 {
6120 /* FIXME: '@' should be used here, but it's filtered out by generic code
6121 before we get to see it here. This may be subject to change. */
6122 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6123
8e560766
MGD
6124 if (result != PARSE_OPERAND_SUCCESS)
6125 return result;
6126 }
09d92015 6127
c19d1205 6128 if (skip_past_char (&p, ']') == FAIL)
09d92015 6129 {
c19d1205 6130 inst.error = _("']' expected");
4962c51a 6131 return PARSE_OPERAND_FAIL;
09d92015
MM
6132 }
6133
c19d1205
ZW
6134 if (skip_past_char (&p, '!') == SUCCESS)
6135 inst.operands[i].writeback = 1;
09d92015 6136
c19d1205 6137 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6138 {
c19d1205
ZW
6139 if (skip_past_char (&p, '{') == SUCCESS)
6140 {
6141 /* [Rn], {expr} - unindexed, with option */
6142 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6143 0, 255, TRUE) == FAIL)
4962c51a 6144 return PARSE_OPERAND_FAIL;
09d92015 6145
c19d1205
ZW
6146 if (skip_past_char (&p, '}') == FAIL)
6147 {
6148 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6149 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6150 }
6151 if (inst.operands[i].preind)
6152 {
6153 inst.error = _("cannot combine index with option");
4962c51a 6154 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6155 }
6156 *str = p;
4962c51a 6157 return PARSE_OPERAND_SUCCESS;
09d92015 6158 }
c19d1205
ZW
6159 else
6160 {
6161 inst.operands[i].postind = 1;
6162 inst.operands[i].writeback = 1;
09d92015 6163
c19d1205
ZW
6164 if (inst.operands[i].preind)
6165 {
6166 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6167 return PARSE_OPERAND_FAIL;
c19d1205 6168 }
09d92015 6169
c19d1205
ZW
6170 if (*p == '+') p++;
6171 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6172
f5f10c66
AV
6173 enum arm_reg_type rtype = REG_TYPE_MQ;
6174 struct neon_type_el et;
6175 if (group_type == GROUP_MVE
6176 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6177 {
6178 inst.operands[i].immisreg = 2;
6179 inst.operands[i].imm = reg;
6180 }
6181 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6182 {
477330fc
RM
6183 /* We might be using the immediate for alignment already. If we
6184 are, OR the register number into the low-order bits. */
6185 if (inst.operands[i].immisalign)
6186 inst.operands[i].imm |= reg;
6187 else
6188 inst.operands[i].imm = reg;
c19d1205 6189 inst.operands[i].immisreg = 1;
a737bd4d 6190
c19d1205
ZW
6191 if (skip_past_comma (&p) == SUCCESS)
6192 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6193 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6194 }
6195 else
6196 {
26d97720 6197 char *q = p;
0198d5e6 6198
c19d1205
ZW
6199 if (inst.operands[i].negative)
6200 {
6201 inst.operands[i].negative = 0;
6202 p--;
6203 }
e2b0ab59 6204 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6205 return PARSE_OPERAND_FAIL;
26d97720 6206 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6207 if (inst.relocs[0].exp.X_op == O_constant
6208 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6209 {
6210 skip_whitespace (q);
6211 if (*q == '#')
6212 {
6213 q++;
6214 skip_whitespace (q);
6215 }
6216 if (*q == '-')
6217 inst.operands[i].negative = 1;
6218 }
c19d1205
ZW
6219 }
6220 }
a737bd4d
NC
6221 }
6222
c19d1205
ZW
6223 /* If at this point neither .preind nor .postind is set, we have a
6224 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6225 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6226 {
6227 inst.operands[i].preind = 1;
e2b0ab59
AV
6228 inst.relocs[0].exp.X_op = O_constant;
6229 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6230 }
6231 *str = p;
4962c51a
MS
6232 return PARSE_OPERAND_SUCCESS;
6233}
6234
6235static int
6236parse_address (char **str, int i)
6237{
21d799b5 6238 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6239 ? SUCCESS : FAIL;
4962c51a
MS
6240}
6241
6242static parse_operand_result
6243parse_address_group_reloc (char **str, int i, group_reloc_type type)
6244{
6245 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6246}
6247
b6895b4f
PB
6248/* Parse an operand for a MOVW or MOVT instruction. */
6249static int
6250parse_half (char **str)
6251{
6252 char * p;
5f4273c7 6253
b6895b4f
PB
6254 p = *str;
6255 skip_past_char (&p, '#');
5f4273c7 6256 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6257 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6258 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6259 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6260
e2b0ab59 6261 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6262 {
6263 p += 9;
5f4273c7 6264 skip_whitespace (p);
b6895b4f
PB
6265 }
6266
e2b0ab59 6267 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6268 return FAIL;
6269
e2b0ab59 6270 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6271 {
e2b0ab59 6272 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6273 {
6274 inst.error = _("constant expression expected");
6275 return FAIL;
6276 }
e2b0ab59
AV
6277 if (inst.relocs[0].exp.X_add_number < 0
6278 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6279 {
6280 inst.error = _("immediate value out of range");
6281 return FAIL;
6282 }
6283 }
6284 *str = p;
6285 return SUCCESS;
6286}
6287
c19d1205 6288/* Miscellaneous. */
a737bd4d 6289
c19d1205
ZW
6290/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6291 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6292static int
d2cd1205 6293parse_psr (char **str, bfd_boolean lhs)
09d92015 6294{
c19d1205
ZW
6295 char *p;
6296 unsigned long psr_field;
62b3e311
PB
6297 const struct asm_psr *psr;
6298 char *start;
d2cd1205 6299 bfd_boolean is_apsr = FALSE;
ac7f631b 6300 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6301
a4482bb6
NC
6302 /* PR gas/12698: If the user has specified -march=all then m_profile will
6303 be TRUE, but we want to ignore it in this case as we are building for any
6304 CPU type, including non-m variants. */
823d2571 6305 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6306 m_profile = FALSE;
6307
c19d1205
ZW
6308 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6309 feature for ease of use and backwards compatibility. */
6310 p = *str;
62b3e311 6311 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6312 {
6313 if (m_profile)
6314 goto unsupported_psr;
fa94de6b 6315
d2cd1205
JB
6316 psr_field = SPSR_BIT;
6317 }
6318 else if (strncasecmp (p, "CPSR", 4) == 0)
6319 {
6320 if (m_profile)
6321 goto unsupported_psr;
6322
6323 psr_field = 0;
6324 }
6325 else if (strncasecmp (p, "APSR", 4) == 0)
6326 {
6327 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6328 and ARMv7-R architecture CPUs. */
6329 is_apsr = TRUE;
6330 psr_field = 0;
6331 }
6332 else if (m_profile)
62b3e311
PB
6333 {
6334 start = p;
6335 do
6336 p++;
6337 while (ISALNUM (*p) || *p == '_');
6338
d2cd1205
JB
6339 if (strncasecmp (start, "iapsr", 5) == 0
6340 || strncasecmp (start, "eapsr", 5) == 0
6341 || strncasecmp (start, "xpsr", 4) == 0
6342 || strncasecmp (start, "psr", 3) == 0)
6343 p = start + strcspn (start, "rR") + 1;
6344
21d799b5 6345 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6346 p - start);
d2cd1205 6347
62b3e311
PB
6348 if (!psr)
6349 return FAIL;
09d92015 6350
d2cd1205
JB
6351 /* If APSR is being written, a bitfield may be specified. Note that
6352 APSR itself is handled above. */
6353 if (psr->field <= 3)
6354 {
6355 psr_field = psr->field;
6356 is_apsr = TRUE;
6357 goto check_suffix;
6358 }
6359
62b3e311 6360 *str = p;
d2cd1205
JB
6361 /* M-profile MSR instructions have the mask field set to "10", except
6362 *PSR variants which modify APSR, which may use a different mask (and
6363 have been handled already). Do that by setting the PSR_f field
6364 here. */
6365 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6366 }
d2cd1205
JB
6367 else
6368 goto unsupported_psr;
09d92015 6369
62b3e311 6370 p += 4;
d2cd1205 6371check_suffix:
c19d1205
ZW
6372 if (*p == '_')
6373 {
6374 /* A suffix follows. */
c19d1205
ZW
6375 p++;
6376 start = p;
a737bd4d 6377
c19d1205
ZW
6378 do
6379 p++;
6380 while (ISALNUM (*p) || *p == '_');
a737bd4d 6381
d2cd1205
JB
6382 if (is_apsr)
6383 {
6384 /* APSR uses a notation for bits, rather than fields. */
6385 unsigned int nzcvq_bits = 0;
6386 unsigned int g_bit = 0;
6387 char *bit;
fa94de6b 6388
d2cd1205
JB
6389 for (bit = start; bit != p; bit++)
6390 {
6391 switch (TOLOWER (*bit))
477330fc 6392 {
d2cd1205
JB
6393 case 'n':
6394 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6395 break;
6396
6397 case 'z':
6398 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6399 break;
6400
6401 case 'c':
6402 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6403 break;
6404
6405 case 'v':
6406 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6407 break;
fa94de6b 6408
d2cd1205
JB
6409 case 'q':
6410 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6411 break;
fa94de6b 6412
d2cd1205
JB
6413 case 'g':
6414 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6415 break;
fa94de6b 6416
d2cd1205
JB
6417 default:
6418 inst.error = _("unexpected bit specified after APSR");
6419 return FAIL;
6420 }
6421 }
fa94de6b 6422
d2cd1205
JB
6423 if (nzcvq_bits == 0x1f)
6424 psr_field |= PSR_f;
fa94de6b 6425
d2cd1205
JB
6426 if (g_bit == 0x1)
6427 {
6428 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6429 {
d2cd1205
JB
6430 inst.error = _("selected processor does not "
6431 "support DSP extension");
6432 return FAIL;
6433 }
6434
6435 psr_field |= PSR_s;
6436 }
fa94de6b 6437
d2cd1205
JB
6438 if ((nzcvq_bits & 0x20) != 0
6439 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6440 || (g_bit & 0x2) != 0)
6441 {
6442 inst.error = _("bad bitmask specified after APSR");
6443 return FAIL;
6444 }
6445 }
6446 else
477330fc 6447 {
d2cd1205 6448 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6449 p - start);
d2cd1205 6450 if (!psr)
477330fc 6451 goto error;
a737bd4d 6452
d2cd1205
JB
6453 psr_field |= psr->field;
6454 }
a737bd4d 6455 }
c19d1205 6456 else
a737bd4d 6457 {
c19d1205
ZW
6458 if (ISALNUM (*p))
6459 goto error; /* Garbage after "[CS]PSR". */
6460
d2cd1205 6461 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6462 is deprecated, but allow it anyway. */
d2cd1205
JB
6463 if (is_apsr && lhs)
6464 {
6465 psr_field |= PSR_f;
6466 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6467 "deprecated"));
6468 }
6469 else if (!m_profile)
6470 /* These bits are never right for M-profile devices: don't set them
6471 (only code paths which read/write APSR reach here). */
6472 psr_field |= (PSR_c | PSR_f);
a737bd4d 6473 }
c19d1205
ZW
6474 *str = p;
6475 return psr_field;
a737bd4d 6476
d2cd1205
JB
6477 unsupported_psr:
6478 inst.error = _("selected processor does not support requested special "
6479 "purpose register");
6480 return FAIL;
6481
c19d1205
ZW
6482 error:
6483 inst.error = _("flag for {c}psr instruction expected");
6484 return FAIL;
a737bd4d
NC
6485}
6486
32c36c3c
AV
6487static int
6488parse_sys_vldr_vstr (char **str)
6489{
6490 unsigned i;
6491 int val = FAIL;
6492 struct {
6493 const char *name;
6494 int regl;
6495 int regh;
6496 } sysregs[] = {
6497 {"FPSCR", 0x1, 0x0},
6498 {"FPSCR_nzcvqc", 0x2, 0x0},
6499 {"VPR", 0x4, 0x1},
6500 {"P0", 0x5, 0x1},
6501 {"FPCXTNS", 0x6, 0x1},
6502 {"FPCXTS", 0x7, 0x1}
6503 };
6504 char *op_end = strchr (*str, ',');
6505 size_t op_strlen = op_end - *str;
6506
6507 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6508 {
6509 if (!strncmp (*str, sysregs[i].name, op_strlen))
6510 {
6511 val = sysregs[i].regl | (sysregs[i].regh << 3);
6512 *str = op_end;
6513 break;
6514 }
6515 }
6516
6517 return val;
6518}
6519
c19d1205
ZW
6520/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6521 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6522
c19d1205
ZW
6523static int
6524parse_cps_flags (char **str)
a737bd4d 6525{
c19d1205
ZW
6526 int val = 0;
6527 int saw_a_flag = 0;
6528 char *s = *str;
a737bd4d 6529
c19d1205
ZW
6530 for (;;)
6531 switch (*s++)
6532 {
6533 case '\0': case ',':
6534 goto done;
a737bd4d 6535
c19d1205
ZW
6536 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6537 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6538 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6539
c19d1205
ZW
6540 default:
6541 inst.error = _("unrecognized CPS flag");
6542 return FAIL;
6543 }
a737bd4d 6544
c19d1205
ZW
6545 done:
6546 if (saw_a_flag == 0)
a737bd4d 6547 {
c19d1205
ZW
6548 inst.error = _("missing CPS flags");
6549 return FAIL;
a737bd4d 6550 }
a737bd4d 6551
c19d1205
ZW
6552 *str = s - 1;
6553 return val;
a737bd4d
NC
6554}
6555
c19d1205
ZW
6556/* Parse an endian specifier ("BE" or "LE", case insensitive);
6557 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6558
6559static int
c19d1205 6560parse_endian_specifier (char **str)
a737bd4d 6561{
c19d1205
ZW
6562 int little_endian;
6563 char *s = *str;
a737bd4d 6564
c19d1205
ZW
6565 if (strncasecmp (s, "BE", 2))
6566 little_endian = 0;
6567 else if (strncasecmp (s, "LE", 2))
6568 little_endian = 1;
6569 else
a737bd4d 6570 {
c19d1205 6571 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6572 return FAIL;
6573 }
6574
c19d1205 6575 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6576 {
c19d1205 6577 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6578 return FAIL;
6579 }
6580
c19d1205
ZW
6581 *str = s + 2;
6582 return little_endian;
6583}
a737bd4d 6584
c19d1205
ZW
6585/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6586 value suitable for poking into the rotate field of an sxt or sxta
6587 instruction, or FAIL on error. */
6588
6589static int
6590parse_ror (char **str)
6591{
6592 int rot;
6593 char *s = *str;
6594
6595 if (strncasecmp (s, "ROR", 3) == 0)
6596 s += 3;
6597 else
a737bd4d 6598 {
c19d1205 6599 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6600 return FAIL;
6601 }
c19d1205
ZW
6602
6603 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6604 return FAIL;
6605
6606 switch (rot)
a737bd4d 6607 {
c19d1205
ZW
6608 case 0: *str = s; return 0x0;
6609 case 8: *str = s; return 0x1;
6610 case 16: *str = s; return 0x2;
6611 case 24: *str = s; return 0x3;
6612
6613 default:
6614 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6615 return FAIL;
6616 }
c19d1205 6617}
a737bd4d 6618
c19d1205
ZW
6619/* Parse a conditional code (from conds[] below). The value returned is in the
6620 range 0 .. 14, or FAIL. */
6621static int
6622parse_cond (char **str)
6623{
c462b453 6624 char *q;
c19d1205 6625 const struct asm_cond *c;
c462b453
PB
6626 int n;
6627 /* Condition codes are always 2 characters, so matching up to
6628 3 characters is sufficient. */
6629 char cond[3];
a737bd4d 6630
c462b453
PB
6631 q = *str;
6632 n = 0;
6633 while (ISALPHA (*q) && n < 3)
6634 {
e07e6e58 6635 cond[n] = TOLOWER (*q);
c462b453
PB
6636 q++;
6637 n++;
6638 }
a737bd4d 6639
21d799b5 6640 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6641 if (!c)
a737bd4d 6642 {
c19d1205 6643 inst.error = _("condition required");
a737bd4d
NC
6644 return FAIL;
6645 }
6646
c19d1205
ZW
6647 *str = q;
6648 return c->value;
6649}
6650
62b3e311
PB
6651/* Parse an option for a barrier instruction. Returns the encoding for the
6652 option, or FAIL. */
6653static int
6654parse_barrier (char **str)
6655{
6656 char *p, *q;
6657 const struct asm_barrier_opt *o;
6658
6659 p = q = *str;
6660 while (ISALPHA (*q))
6661 q++;
6662
21d799b5 6663 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6664 q - p);
62b3e311
PB
6665 if (!o)
6666 return FAIL;
6667
e797f7e0
MGD
6668 if (!mark_feature_used (&o->arch))
6669 return FAIL;
6670
62b3e311
PB
6671 *str = q;
6672 return o->value;
6673}
6674
92e90b6e
PB
6675/* Parse the operands of a table branch instruction. Similar to a memory
6676 operand. */
6677static int
6678parse_tb (char **str)
6679{
6680 char * p = *str;
6681 int reg;
6682
6683 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6684 {
6685 inst.error = _("'[' expected");
6686 return FAIL;
6687 }
92e90b6e 6688
dcbf9037 6689 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6690 {
6691 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6692 return FAIL;
6693 }
6694 inst.operands[0].reg = reg;
6695
6696 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6697 {
6698 inst.error = _("',' expected");
6699 return FAIL;
6700 }
5f4273c7 6701
dcbf9037 6702 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6703 {
6704 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6705 return FAIL;
6706 }
6707 inst.operands[0].imm = reg;
6708
6709 if (skip_past_comma (&p) == SUCCESS)
6710 {
6711 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6712 return FAIL;
e2b0ab59 6713 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6714 {
6715 inst.error = _("invalid shift");
6716 return FAIL;
6717 }
6718 inst.operands[0].shifted = 1;
6719 }
6720
6721 if (skip_past_char (&p, ']') == FAIL)
6722 {
6723 inst.error = _("']' expected");
6724 return FAIL;
6725 }
6726 *str = p;
6727 return SUCCESS;
6728}
6729
5287ad62
JB
6730/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6731 information on the types the operands can take and how they are encoded.
037e8744
JB
6732 Up to four operands may be read; this function handles setting the
6733 ".present" field for each read operand itself.
5287ad62
JB
6734 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6735 else returns FAIL. */
6736
6737static int
6738parse_neon_mov (char **str, int *which_operand)
6739{
6740 int i = *which_operand, val;
6741 enum arm_reg_type rtype;
6742 char *ptr = *str;
dcbf9037 6743 struct neon_type_el optype;
5f4273c7 6744
57785aa2
AV
6745 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6746 {
6747 /* Cases 17 or 19. */
6748 inst.operands[i].reg = val;
6749 inst.operands[i].isvec = 1;
6750 inst.operands[i].isscalar = 2;
6751 inst.operands[i].vectype = optype;
6752 inst.operands[i++].present = 1;
6753
6754 if (skip_past_comma (&ptr) == FAIL)
6755 goto wanted_comma;
6756
6757 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6758 {
6759 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6760 inst.operands[i].reg = val;
6761 inst.operands[i].isreg = 1;
6762 inst.operands[i].present = 1;
6763 }
6764 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6765 {
6766 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6767 inst.operands[i].reg = val;
6768 inst.operands[i].isvec = 1;
6769 inst.operands[i].isscalar = 2;
6770 inst.operands[i].vectype = optype;
6771 inst.operands[i++].present = 1;
6772
6773 if (skip_past_comma (&ptr) == FAIL)
6774 goto wanted_comma;
6775
6776 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6777 goto wanted_arm;
6778
6779 inst.operands[i].reg = val;
6780 inst.operands[i].isreg = 1;
6781 inst.operands[i++].present = 1;
6782
6783 if (skip_past_comma (&ptr) == FAIL)
6784 goto wanted_comma;
6785
6786 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6787 goto wanted_arm;
6788
6789 inst.operands[i].reg = val;
6790 inst.operands[i].isreg = 1;
6791 inst.operands[i].present = 1;
6792 }
6793 else
6794 {
6795 first_error (_("expected ARM or MVE vector register"));
6796 return FAIL;
6797 }
6798 }
6799 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6800 {
6801 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6802 inst.operands[i].reg = val;
6803 inst.operands[i].isscalar = 1;
dcbf9037 6804 inst.operands[i].vectype = optype;
5287ad62
JB
6805 inst.operands[i++].present = 1;
6806
6807 if (skip_past_comma (&ptr) == FAIL)
477330fc 6808 goto wanted_comma;
5f4273c7 6809
dcbf9037 6810 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6811 goto wanted_arm;
5f4273c7 6812
5287ad62
JB
6813 inst.operands[i].reg = val;
6814 inst.operands[i].isreg = 1;
6815 inst.operands[i].present = 1;
6816 }
57785aa2
AV
6817 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6818 != FAIL)
6819 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6820 != FAIL))
5287ad62
JB
6821 {
6822 /* Cases 0, 1, 2, 3, 5 (D only). */
6823 if (skip_past_comma (&ptr) == FAIL)
477330fc 6824 goto wanted_comma;
5f4273c7 6825
5287ad62
JB
6826 inst.operands[i].reg = val;
6827 inst.operands[i].isreg = 1;
6828 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6829 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6830 inst.operands[i].isvec = 1;
dcbf9037 6831 inst.operands[i].vectype = optype;
5287ad62
JB
6832 inst.operands[i++].present = 1;
6833
dcbf9037 6834 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6835 {
6836 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6837 Case 13: VMOV <Sd>, <Rm> */
6838 inst.operands[i].reg = val;
6839 inst.operands[i].isreg = 1;
6840 inst.operands[i].present = 1;
6841
6842 if (rtype == REG_TYPE_NQ)
6843 {
6844 first_error (_("can't use Neon quad register here"));
6845 return FAIL;
6846 }
6847 else if (rtype != REG_TYPE_VFS)
6848 {
6849 i++;
6850 if (skip_past_comma (&ptr) == FAIL)
6851 goto wanted_comma;
6852 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6853 goto wanted_arm;
6854 inst.operands[i].reg = val;
6855 inst.operands[i].isreg = 1;
6856 inst.operands[i].present = 1;
6857 }
6858 }
c4a23bf8
SP
6859 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6860 &optype)) != FAIL)
6861 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6862 &optype)) != FAIL))
477330fc
RM
6863 {
6864 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6865 Case 1: VMOV<c><q> <Dd>, <Dm>
6866 Case 8: VMOV.F32 <Sd>, <Sm>
6867 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6868
6869 inst.operands[i].reg = val;
6870 inst.operands[i].isreg = 1;
6871 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6872 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6873 inst.operands[i].isvec = 1;
6874 inst.operands[i].vectype = optype;
6875 inst.operands[i].present = 1;
6876
6877 if (skip_past_comma (&ptr) == SUCCESS)
6878 {
6879 /* Case 15. */
6880 i++;
6881
6882 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6883 goto wanted_arm;
6884
6885 inst.operands[i].reg = val;
6886 inst.operands[i].isreg = 1;
6887 inst.operands[i++].present = 1;
6888
6889 if (skip_past_comma (&ptr) == FAIL)
6890 goto wanted_comma;
6891
6892 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6893 goto wanted_arm;
6894
6895 inst.operands[i].reg = val;
6896 inst.operands[i].isreg = 1;
6897 inst.operands[i].present = 1;
6898 }
6899 }
4641781c 6900 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6901 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6902 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6903 Case 10: VMOV.F32 <Sd>, #<imm>
6904 Case 11: VMOV.F64 <Dd>, #<imm> */
6905 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6906 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6907 == SUCCESS)
477330fc
RM
6908 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6909 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6910 ;
5287ad62 6911 else
477330fc
RM
6912 {
6913 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6914 return FAIL;
6915 }
5287ad62 6916 }
dcbf9037 6917 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6918 {
57785aa2 6919 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6920 inst.operands[i].reg = val;
6921 inst.operands[i].isreg = 1;
6922 inst.operands[i++].present = 1;
5f4273c7 6923
5287ad62 6924 if (skip_past_comma (&ptr) == FAIL)
477330fc 6925 goto wanted_comma;
5f4273c7 6926
57785aa2
AV
6927 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6928 {
6929 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6930 inst.operands[i].reg = val;
6931 inst.operands[i].isscalar = 2;
6932 inst.operands[i].present = 1;
6933 inst.operands[i].vectype = optype;
6934 }
6935 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6936 {
6937 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6938 inst.operands[i].reg = val;
6939 inst.operands[i].isscalar = 1;
6940 inst.operands[i].present = 1;
6941 inst.operands[i].vectype = optype;
6942 }
dcbf9037 6943 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6944 {
477330fc
RM
6945 inst.operands[i].reg = val;
6946 inst.operands[i].isreg = 1;
6947 inst.operands[i++].present = 1;
6948
6949 if (skip_past_comma (&ptr) == FAIL)
6950 goto wanted_comma;
6951
6952 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6953 != FAIL)
477330fc 6954 {
57785aa2 6955 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6956
477330fc
RM
6957 inst.operands[i].reg = val;
6958 inst.operands[i].isreg = 1;
6959 inst.operands[i].isvec = 1;
57785aa2 6960 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6961 inst.operands[i].vectype = optype;
6962 inst.operands[i].present = 1;
57785aa2
AV
6963
6964 if (rtype == REG_TYPE_VFS)
6965 {
6966 /* Case 14. */
6967 i++;
6968 if (skip_past_comma (&ptr) == FAIL)
6969 goto wanted_comma;
6970 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6971 &optype)) == FAIL)
6972 {
6973 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6974 return FAIL;
6975 }
6976 inst.operands[i].reg = val;
6977 inst.operands[i].isreg = 1;
6978 inst.operands[i].isvec = 1;
6979 inst.operands[i].issingle = 1;
6980 inst.operands[i].vectype = optype;
6981 inst.operands[i].present = 1;
6982 }
6983 }
6984 else
6985 {
6986 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6987 != FAIL)
6988 {
6989 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6990 inst.operands[i].reg = val;
6991 inst.operands[i].isvec = 1;
6992 inst.operands[i].isscalar = 2;
6993 inst.operands[i].vectype = optype;
6994 inst.operands[i++].present = 1;
6995
6996 if (skip_past_comma (&ptr) == FAIL)
6997 goto wanted_comma;
6998
6999 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
7000 == FAIL)
7001 {
7002 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
7003 return FAIL;
7004 }
7005 inst.operands[i].reg = val;
7006 inst.operands[i].isvec = 1;
7007 inst.operands[i].isscalar = 2;
7008 inst.operands[i].vectype = optype;
7009 inst.operands[i].present = 1;
7010 }
7011 else
7012 {
7013 first_error (_("VFP single, double or MVE vector register"
7014 " expected"));
7015 return FAIL;
7016 }
477330fc
RM
7017 }
7018 }
037e8744 7019 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
7020 != FAIL)
7021 {
7022 /* Case 13. */
7023 inst.operands[i].reg = val;
7024 inst.operands[i].isreg = 1;
7025 inst.operands[i].isvec = 1;
7026 inst.operands[i].issingle = 1;
7027 inst.operands[i].vectype = optype;
7028 inst.operands[i].present = 1;
7029 }
5287ad62
JB
7030 }
7031 else
7032 {
dcbf9037 7033 first_error (_("parse error"));
5287ad62
JB
7034 return FAIL;
7035 }
7036
7037 /* Successfully parsed the operands. Update args. */
7038 *which_operand = i;
7039 *str = ptr;
7040 return SUCCESS;
7041
5f4273c7 7042 wanted_comma:
dcbf9037 7043 first_error (_("expected comma"));
5287ad62 7044 return FAIL;
5f4273c7
NC
7045
7046 wanted_arm:
dcbf9037 7047 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 7048 return FAIL;
5287ad62
JB
7049}
7050
5be8be5d
DG
7051/* Use this macro when the operand constraints are different
7052 for ARM and THUMB (e.g. ldrd). */
7053#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7054 ((arm_operand) | ((thumb_operand) << 16))
7055
c19d1205
ZW
7056/* Matcher codes for parse_operands. */
7057enum operand_parse_code
7058{
7059 OP_stop, /* end of line */
7060
7061 OP_RR, /* ARM register */
7062 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 7063 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 7064 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 7065 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 7066 optional trailing ! */
c19d1205
ZW
7067 OP_RRw, /* ARM register, not r15, optional trailing ! */
7068 OP_RCP, /* Coprocessor number */
7069 OP_RCN, /* Coprocessor register */
7070 OP_RF, /* FPA register */
7071 OP_RVS, /* VFP single precision register */
5287ad62
JB
7072 OP_RVD, /* VFP double precision register (0..15) */
7073 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
7074 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7075 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7076 */
5287ad62 7077 OP_RNQ, /* Neon quad precision register */
5ee91343 7078 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 7079 OP_RVSD, /* VFP single or double precision register */
1b883319 7080 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 7081 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 7082 OP_RNSD, /* Neon single or double precision register */
5287ad62 7083 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 7084 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 7085 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 7086 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 7087 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
7088 OP_RVC, /* VFP control register */
7089 OP_RMF, /* Maverick F register */
7090 OP_RMD, /* Maverick D register */
7091 OP_RMFX, /* Maverick FX register */
7092 OP_RMDX, /* Maverick DX register */
7093 OP_RMAX, /* Maverick AX register */
7094 OP_RMDS, /* Maverick DSPSC register */
7095 OP_RIWR, /* iWMMXt wR register */
7096 OP_RIWC, /* iWMMXt wC register */
7097 OP_RIWG, /* iWMMXt wCG register */
7098 OP_RXA, /* XScale accumulator register */
7099
5aae9ae9 7100 OP_RNSDMQ, /* Neon single, double or MVE vector register */
5ee91343
AV
7101 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7102 */
7103 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7104 GPR (no SP/SP) */
a302e574 7105 OP_RMQ, /* MVE vector register. */
1b883319 7106 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 7107 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 7108
60f993ce
AV
7109 /* New operands for Armv8.1-M Mainline. */
7110 OP_LR, /* ARM LR register */
a302e574
AV
7111 OP_RRe, /* ARM register, only even numbered. */
7112 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7113 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7114 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7115
c19d1205 7116 OP_REGLST, /* ARM register list */
4b5a202f 7117 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7118 OP_VRSLST, /* VFP single-precision register list */
7119 OP_VRDLST, /* VFP double-precision register list */
037e8744 7120 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7121 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7122 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7123 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7124 OP_MSTRLST2, /* MVE vector list with two elements. */
7125 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7126
5287ad62 7127 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7128 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7129 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7130 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7131 zero. */
5287ad62 7132 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7133 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7134 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7135 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7136 */
a8465a06
AV
7137 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7138 scalar, or ARM register. */
5287ad62 7139 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7140 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7141 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7142 register. */
5d281bf0 7143 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7144 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7145 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7146 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7147 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7148 OP_RNDQMQ_Ibig,
5287ad62 7149 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7150 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7151 ARM register. */
2d447fca 7152 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7153 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7154
7155 OP_I0, /* immediate zero */
c19d1205
ZW
7156 OP_I7, /* immediate value 0 .. 7 */
7157 OP_I15, /* 0 .. 15 */
7158 OP_I16, /* 1 .. 16 */
5287ad62 7159 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7160 OP_I31, /* 0 .. 31 */
7161 OP_I31w, /* 0 .. 31, optional trailing ! */
7162 OP_I32, /* 1 .. 32 */
5287ad62 7163 OP_I32z, /* 0 .. 32 */
08132bdd 7164 OP_I48_I64, /* 48 or 64 */
5287ad62 7165 OP_I63, /* 0 .. 63 */
c19d1205 7166 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7167 OP_I64, /* 1 .. 64 */
7168 OP_I64z, /* 0 .. 64 */
5aae9ae9 7169 OP_I127, /* 0 .. 127 */
c19d1205 7170 OP_I255, /* 0 .. 255 */
4934a27c 7171 OP_I511, /* 0 .. 511 */
5aae9ae9 7172 OP_I4095, /* 0 .. 4095 */
4934a27c 7173 OP_I8191, /* 0 .. 8191 */
c19d1205
ZW
7174 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7175 OP_I7b, /* 0 .. 7 */
7176 OP_I15b, /* 0 .. 15 */
7177 OP_I31b, /* 0 .. 31 */
7178
7179 OP_SH, /* shifter operand */
4962c51a 7180 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7181 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7182 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7183 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7184 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7185 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7186 OP_EXP, /* arbitrary expression */
7187 OP_EXPi, /* same, with optional immediate prefix */
7188 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7189 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7190 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7191 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7192 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7193
7194 OP_CPSF, /* CPS flags */
7195 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7196 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7197 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7198 OP_COND, /* conditional code */
92e90b6e 7199 OP_TB, /* Table branch. */
c19d1205 7200
037e8744
JB
7201 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7202
c19d1205 7203 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7204 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7205 OP_RR_EXi, /* ARM register or expression with imm prefix */
7206 OP_RF_IF, /* FPA register or immediate */
7207 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7208 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7209
7210 /* Optional operands. */
7211 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7212 OP_oI31b, /* 0 .. 31 */
5287ad62 7213 OP_oI32b, /* 1 .. 32 */
5f1af56b 7214 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7215 OP_oIffffb, /* 0 .. 65535 */
7216 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7217
7218 OP_oRR, /* ARM register */
60f993ce 7219 OP_oLR, /* ARM LR register */
c19d1205 7220 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7221 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7222 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7223 OP_oRND, /* Optional Neon double precision register */
7224 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7225 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7226 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7227 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7228 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7229 register. */
c19d1205
ZW
7230 OP_oSHll, /* LSL immediate */
7231 OP_oSHar, /* ASR immediate */
7232 OP_oSHllar, /* LSL or ASR immediate */
7233 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7234 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7235
1b883319
AV
7236 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7237
5be8be5d
DG
7238 /* Some pre-defined mixed (ARM/THUMB) operands. */
7239 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7240 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7241 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7242
c19d1205
ZW
7243 OP_FIRST_OPTIONAL = OP_oI7b
7244};
a737bd4d 7245
c19d1205
ZW
7246/* Generic instruction operand parser. This does no encoding and no
7247 semantic validation; it merely squirrels values away in the inst
7248 structure. Returns SUCCESS or FAIL depending on whether the
7249 specified grammar matched. */
7250static int
5be8be5d 7251parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7252{
5be8be5d 7253 unsigned const int *upat = pattern;
c19d1205
ZW
7254 char *backtrack_pos = 0;
7255 const char *backtrack_error = 0;
99aad254 7256 int i, val = 0, backtrack_index = 0;
5287ad62 7257 enum arm_reg_type rtype;
4962c51a 7258 parse_operand_result result;
5be8be5d 7259 unsigned int op_parse_code;
efd6b359 7260 bfd_boolean partial_match;
c19d1205 7261
e07e6e58
NC
7262#define po_char_or_fail(chr) \
7263 do \
7264 { \
7265 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7266 goto bad_args; \
e07e6e58
NC
7267 } \
7268 while (0)
c19d1205 7269
e07e6e58
NC
7270#define po_reg_or_fail(regtype) \
7271 do \
dcbf9037 7272 { \
e07e6e58 7273 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7274 & inst.operands[i].vectype); \
e07e6e58 7275 if (val == FAIL) \
477330fc
RM
7276 { \
7277 first_error (_(reg_expected_msgs[regtype])); \
7278 goto failure; \
7279 } \
e07e6e58
NC
7280 inst.operands[i].reg = val; \
7281 inst.operands[i].isreg = 1; \
7282 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7283 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7284 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7285 || rtype == REG_TYPE_VFD \
7286 || rtype == REG_TYPE_NQ); \
1b883319 7287 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7288 } \
e07e6e58
NC
7289 while (0)
7290
7291#define po_reg_or_goto(regtype, label) \
7292 do \
7293 { \
7294 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7295 & inst.operands[i].vectype); \
7296 if (val == FAIL) \
7297 goto label; \
dcbf9037 7298 \
e07e6e58
NC
7299 inst.operands[i].reg = val; \
7300 inst.operands[i].isreg = 1; \
7301 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7302 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7303 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7304 || rtype == REG_TYPE_VFD \
e07e6e58 7305 || rtype == REG_TYPE_NQ); \
1b883319 7306 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7307 } \
7308 while (0)
7309
7310#define po_imm_or_fail(min, max, popt) \
7311 do \
7312 { \
7313 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7314 goto failure; \
7315 inst.operands[i].imm = val; \
7316 } \
7317 while (0)
7318
08132bdd
SP
7319#define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7320 do \
7321 { \
7322 expressionS exp; \
7323 my_get_expression (&exp, &str, popt); \
7324 if (exp.X_op != O_constant) \
7325 { \
7326 inst.error = _("constant expression required"); \
7327 goto failure; \
7328 } \
7329 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7330 { \
7331 inst.error = _("immediate value 48 or 64 expected"); \
7332 goto failure; \
7333 } \
7334 inst.operands[i].imm = exp.X_add_number; \
7335 } \
7336 while (0)
7337
57785aa2 7338#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7339 do \
7340 { \
57785aa2
AV
7341 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7342 reg_type); \
e07e6e58
NC
7343 if (val == FAIL) \
7344 goto label; \
7345 inst.operands[i].reg = val; \
7346 inst.operands[i].isscalar = 1; \
7347 } \
7348 while (0)
7349
7350#define po_misc_or_fail(expr) \
7351 do \
7352 { \
7353 if (expr) \
7354 goto failure; \
7355 } \
7356 while (0)
7357
7358#define po_misc_or_fail_no_backtrack(expr) \
7359 do \
7360 { \
7361 result = expr; \
7362 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7363 backtrack_pos = 0; \
7364 if (result != PARSE_OPERAND_SUCCESS) \
7365 goto failure; \
7366 } \
7367 while (0)
4962c51a 7368
52e7f43d
RE
7369#define po_barrier_or_imm(str) \
7370 do \
7371 { \
7372 val = parse_barrier (&str); \
ccb84d65
JB
7373 if (val == FAIL && ! ISALPHA (*str)) \
7374 goto immediate; \
7375 if (val == FAIL \
7376 /* ISB can only take SY as an option. */ \
7377 || ((inst.instruction & 0xf0) == 0x60 \
7378 && val != 0xf)) \
52e7f43d 7379 { \
ccb84d65
JB
7380 inst.error = _("invalid barrier type"); \
7381 backtrack_pos = 0; \
7382 goto failure; \
52e7f43d
RE
7383 } \
7384 } \
7385 while (0)
7386
c19d1205
ZW
7387 skip_whitespace (str);
7388
7389 for (i = 0; upat[i] != OP_stop; i++)
7390 {
5be8be5d
DG
7391 op_parse_code = upat[i];
7392 if (op_parse_code >= 1<<16)
7393 op_parse_code = thumb ? (op_parse_code >> 16)
7394 : (op_parse_code & ((1<<16)-1));
7395
7396 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7397 {
7398 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7399 backtrack_pos = str;
7400 backtrack_error = inst.error;
7401 backtrack_index = i;
7402 }
7403
b6702015 7404 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7405 po_char_or_fail (',');
7406
5be8be5d 7407 switch (op_parse_code)
c19d1205
ZW
7408 {
7409 /* Registers */
7410 case OP_oRRnpc:
5be8be5d 7411 case OP_oRRnpcsp:
c19d1205 7412 case OP_RRnpc:
5be8be5d 7413 case OP_RRnpcsp:
c19d1205 7414 case OP_oRR:
a302e574
AV
7415 case OP_RRe:
7416 case OP_RRo:
60f993ce
AV
7417 case OP_LR:
7418 case OP_oLR:
c19d1205
ZW
7419 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7420 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7421 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7422 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7423 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7424 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7425 case OP_oRND:
5ee91343
AV
7426 case OP_RNDMQR:
7427 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7428 break;
7429 try_rndmq:
7430 case OP_RNDMQ:
7431 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7432 break;
7433 try_rnd:
5287ad62 7434 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7435 case OP_RVC:
7436 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7437 break;
7438 /* Also accept generic coprocessor regs for unknown registers. */
7439 coproc_reg:
ba6cd17f
SD
7440 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7441 break;
7442 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7443 existing register with a value of 0, this seems like the
7444 best way to parse P0. */
7445 vpr_po:
7446 if (strncasecmp (str, "P0", 2) == 0)
7447 {
7448 str += 2;
7449 inst.operands[i].isreg = 1;
7450 inst.operands[i].reg = 13;
7451 }
7452 else
7453 goto failure;
cd2cf30b 7454 break;
c19d1205
ZW
7455 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7456 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7457 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7458 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7459 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7460 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7461 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7462 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7463 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7464 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7465 case OP_oRNQ:
5ee91343
AV
7466 case OP_RNQMQ:
7467 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7468 break;
7469 try_nq:
5287ad62 7470 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7471 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7472 case OP_RNDQMQR:
7473 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7474 break;
7475 try_rndqmq:
5ee91343
AV
7476 case OP_oRNDQMQ:
7477 case OP_RNDQMQ:
7478 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7479 break;
7480 try_rndq:
477330fc 7481 case OP_oRNDQ:
5287ad62 7482 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7483 case OP_RVSDMQ:
7484 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7485 break;
7486 try_rvsd:
477330fc 7487 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7488 case OP_RVSD_COND:
7489 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7490 break;
5aae9ae9
MM
7491 case OP_RNSDMQ:
7492 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7493 break;
7494 try_mq2:
7495 po_reg_or_fail (REG_TYPE_MQ);
7496 break;
477330fc
RM
7497 case OP_oRNSDQ:
7498 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7499 case OP_RNSDQMQR:
7500 po_reg_or_goto (REG_TYPE_RN, try_mq);
7501 break;
7502 try_mq:
7503 case OP_oRNSDQMQ:
7504 case OP_RNSDQMQ:
7505 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7506 break;
7507 try_nsdq2:
7508 po_reg_or_fail (REG_TYPE_NSDQ);
7509 inst.error = 0;
7510 break;
35d1cfc2
AV
7511 case OP_RMQRR:
7512 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7513 break;
7514 try_rmq:
a302e574
AV
7515 case OP_RMQ:
7516 po_reg_or_fail (REG_TYPE_MQ);
7517 break;
477330fc
RM
7518 /* Neon scalar. Using an element size of 8 means that some invalid
7519 scalars are accepted here, so deal with those in later code. */
57785aa2 7520 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7521
7522 case OP_RNDQ_I0:
7523 {
7524 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7525 break;
7526 try_imm0:
7527 po_imm_or_fail (0, 0, TRUE);
7528 }
7529 break;
7530
7531 case OP_RVSD_I0:
7532 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7533 break;
7534
1b883319
AV
7535 case OP_RSVDMQ_FI0:
7536 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7537 break;
7538 try_rsvd_fi0:
aacf0b33
KT
7539 case OP_RSVD_FI0:
7540 {
7541 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7542 break;
7543 try_ifimm0:
7544 if (parse_ifimm_zero (&str))
7545 inst.operands[i].imm = 0;
7546 else
7547 {
7548 inst.error
7549 = _("only floating point zero is allowed as immediate value");
7550 goto failure;
7551 }
7552 }
7553 break;
7554
477330fc
RM
7555 case OP_RR_RNSC:
7556 {
57785aa2 7557 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7558 break;
7559 try_rr:
7560 po_reg_or_fail (REG_TYPE_RN);
7561 }
7562 break;
7563
a8465a06
AV
7564 case OP_RNSDQ_RNSC_MQ_RR:
7565 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7566 break;
7567 try_rnsdq_rnsc_mq:
886e1c73
AV
7568 case OP_RNSDQ_RNSC_MQ:
7569 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7570 break;
7571 try_rnsdq_rnsc:
477330fc
RM
7572 case OP_RNSDQ_RNSC:
7573 {
57785aa2
AV
7574 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7575 inst.error = 0;
477330fc
RM
7576 break;
7577 try_nsdq:
7578 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7579 inst.error = 0;
477330fc
RM
7580 }
7581 break;
7582
dec41383
JW
7583 case OP_RNSD_RNSC:
7584 {
57785aa2 7585 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7586 break;
7587 try_s_scalar:
57785aa2 7588 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7589 break;
7590 try_nsd:
7591 po_reg_or_fail (REG_TYPE_NSD);
7592 }
7593 break;
7594
42b16635
AV
7595 case OP_RNDQMQ_RNSC_RR:
7596 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7597 break;
7598 try_rndq_rnsc_rr:
7599 case OP_RNDQ_RNSC_RR:
7600 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7601 break;
5d281bf0
AV
7602 case OP_RNDQMQ_RNSC:
7603 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7604 break;
7605 try_rndq_rnsc:
477330fc
RM
7606 case OP_RNDQ_RNSC:
7607 {
57785aa2 7608 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7609 break;
7610 try_ndq:
7611 po_reg_or_fail (REG_TYPE_NDQ);
7612 }
7613 break;
7614
7615 case OP_RND_RNSC:
7616 {
57785aa2 7617 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7618 break;
7619 try_vfd:
7620 po_reg_or_fail (REG_TYPE_VFD);
7621 }
7622 break;
7623
7624 case OP_VMOV:
7625 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7626 not careful then bad things might happen. */
7627 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7628 break;
7629
f601a00c
AV
7630 case OP_RNDQMQ_Ibig:
7631 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7632 break;
7633 try_rndq_ibig:
477330fc
RM
7634 case OP_RNDQ_Ibig:
7635 {
7636 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7637 break;
7638 try_immbig:
7639 /* There's a possibility of getting a 64-bit immediate here, so
7640 we need special handling. */
8335d6aa
JW
7641 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7642 == FAIL)
477330fc
RM
7643 {
7644 inst.error = _("immediate value is out of range");
7645 goto failure;
7646 }
7647 }
7648 break;
7649
5150f0d8
AV
7650 case OP_RNDQMQ_I63b_RR:
7651 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7652 break;
7653 try_rndq_i63b_rr:
7654 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7655 break;
7656 try_rndq_i63b:
477330fc
RM
7657 case OP_RNDQ_I63b:
7658 {
7659 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7660 break;
7661 try_shimm:
7662 po_imm_or_fail (0, 63, TRUE);
7663 }
7664 break;
c19d1205
ZW
7665
7666 case OP_RRnpcb:
7667 po_char_or_fail ('[');
7668 po_reg_or_fail (REG_TYPE_RN);
7669 po_char_or_fail (']');
7670 break;
a737bd4d 7671
55881a11 7672 case OP_RRnpctw:
c19d1205 7673 case OP_RRw:
b6702015 7674 case OP_oRRw:
c19d1205
ZW
7675 po_reg_or_fail (REG_TYPE_RN);
7676 if (skip_past_char (&str, '!') == SUCCESS)
7677 inst.operands[i].writeback = 1;
7678 break;
7679
7680 /* Immediates */
7681 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7682 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7683 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7684 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7685 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7686 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7687 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
08132bdd 7688 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
c19d1205 7689 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7690 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7691 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7692 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5aae9ae9 7693 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
c19d1205 7694 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
4934a27c 7695 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
5aae9ae9 7696 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
4934a27c 7697 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
c19d1205
ZW
7698 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7699 case OP_oI7b:
7700 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7701 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7702 case OP_oI31b:
7703 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7704 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7705 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7706 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7707
7708 /* Immediate variants */
7709 case OP_oI255c:
7710 po_char_or_fail ('{');
7711 po_imm_or_fail (0, 255, TRUE);
7712 po_char_or_fail ('}');
7713 break;
7714
7715 case OP_I31w:
7716 /* The expression parser chokes on a trailing !, so we have
7717 to find it first and zap it. */
7718 {
7719 char *s = str;
7720 while (*s && *s != ',')
7721 s++;
7722 if (s[-1] == '!')
7723 {
7724 s[-1] = '\0';
7725 inst.operands[i].writeback = 1;
7726 }
7727 po_imm_or_fail (0, 31, TRUE);
7728 if (str == s - 1)
7729 str = s;
7730 }
7731 break;
7732
7733 /* Expressions */
7734 case OP_EXPi: EXPi:
e2b0ab59 7735 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7736 GE_OPT_PREFIX));
7737 break;
7738
7739 case OP_EXP:
e2b0ab59 7740 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7741 GE_NO_PREFIX));
7742 break;
7743
7744 case OP_EXPr: EXPr:
e2b0ab59 7745 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7746 GE_NO_PREFIX));
e2b0ab59 7747 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7748 {
c19d1205
ZW
7749 val = parse_reloc (&str);
7750 if (val == -1)
7751 {
7752 inst.error = _("unrecognized relocation suffix");
7753 goto failure;
7754 }
7755 else if (val != BFD_RELOC_UNUSED)
7756 {
7757 inst.operands[i].imm = val;
7758 inst.operands[i].hasreloc = 1;
7759 }
a737bd4d 7760 }
c19d1205 7761 break;
a737bd4d 7762
e2b0ab59
AV
7763 case OP_EXPs:
7764 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7765 GE_NO_PREFIX));
7766 if (inst.relocs[i].exp.X_op == O_symbol)
7767 {
7768 inst.operands[i].hasreloc = 1;
7769 }
7770 else if (inst.relocs[i].exp.X_op == O_constant)
7771 {
7772 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7773 inst.operands[i].hasreloc = 0;
7774 }
7775 break;
7776
b6895b4f
PB
7777 /* Operand for MOVW or MOVT. */
7778 case OP_HALF:
7779 po_misc_or_fail (parse_half (&str));
7780 break;
7781
e07e6e58 7782 /* Register or expression. */
c19d1205
ZW
7783 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7784 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7785
e07e6e58 7786 /* Register or immediate. */
c19d1205
ZW
7787 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7788 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7789
23d00a41
SD
7790 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7791 I32: po_imm_or_fail (1, 32, FALSE); break;
7792
c19d1205
ZW
7793 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7794 IF:
7795 if (!is_immediate_prefix (*str))
7796 goto bad_args;
7797 str++;
7798 val = parse_fpa_immediate (&str);
7799 if (val == FAIL)
7800 goto failure;
7801 /* FPA immediates are encoded as registers 8-15.
7802 parse_fpa_immediate has already applied the offset. */
7803 inst.operands[i].reg = val;
7804 inst.operands[i].isreg = 1;
7805 break;
09d92015 7806
2d447fca
JM
7807 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7808 I32z: po_imm_or_fail (0, 32, FALSE); break;
7809
e07e6e58 7810 /* Two kinds of register. */
c19d1205
ZW
7811 case OP_RIWR_RIWC:
7812 {
7813 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7814 if (!rege
7815 || (rege->type != REG_TYPE_MMXWR
7816 && rege->type != REG_TYPE_MMXWC
7817 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7818 {
7819 inst.error = _("iWMMXt data or control register expected");
7820 goto failure;
7821 }
7822 inst.operands[i].reg = rege->number;
7823 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7824 }
7825 break;
09d92015 7826
41adaa5c
JM
7827 case OP_RIWC_RIWG:
7828 {
7829 struct reg_entry *rege = arm_reg_parse_multi (&str);
7830 if (!rege
7831 || (rege->type != REG_TYPE_MMXWC
7832 && rege->type != REG_TYPE_MMXWCG))
7833 {
7834 inst.error = _("iWMMXt control register expected");
7835 goto failure;
7836 }
7837 inst.operands[i].reg = rege->number;
7838 inst.operands[i].isreg = 1;
7839 }
7840 break;
7841
c19d1205
ZW
7842 /* Misc */
7843 case OP_CPSF: val = parse_cps_flags (&str); break;
7844 case OP_ENDI: val = parse_endian_specifier (&str); break;
7845 case OP_oROR: val = parse_ror (&str); break;
1b883319 7846 try_cond:
c19d1205 7847 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7848 case OP_oBARRIER_I15:
7849 po_barrier_or_imm (str); break;
7850 immediate:
7851 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7852 goto failure;
52e7f43d 7853 break;
c19d1205 7854
fa94de6b 7855 case OP_wPSR:
d2cd1205 7856 case OP_rPSR:
90ec0d68
MGD
7857 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7858 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7859 {
7860 inst.error = _("Banked registers are not available with this "
7861 "architecture.");
7862 goto failure;
7863 }
7864 break;
d2cd1205
JB
7865 try_psr:
7866 val = parse_psr (&str, op_parse_code == OP_wPSR);
7867 break;
037e8744 7868
32c36c3c
AV
7869 case OP_VLDR:
7870 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7871 break;
7872 try_sysreg:
7873 val = parse_sys_vldr_vstr (&str);
7874 break;
7875
477330fc
RM
7876 case OP_APSR_RR:
7877 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7878 break;
7879 try_apsr:
7880 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7881 instruction). */
7882 if (strncasecmp (str, "APSR_", 5) == 0)
7883 {
7884 unsigned found = 0;
7885 str += 5;
7886 while (found < 15)
7887 switch (*str++)
7888 {
7889 case 'c': found = (found & 1) ? 16 : found | 1; break;
7890 case 'n': found = (found & 2) ? 16 : found | 2; break;
7891 case 'z': found = (found & 4) ? 16 : found | 4; break;
7892 case 'v': found = (found & 8) ? 16 : found | 8; break;
7893 default: found = 16;
7894 }
7895 if (found != 15)
7896 goto failure;
7897 inst.operands[i].isvec = 1;
f7c21dc7
NC
7898 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7899 inst.operands[i].reg = REG_PC;
477330fc
RM
7900 }
7901 else
7902 goto failure;
7903 break;
037e8744 7904
92e90b6e
PB
7905 case OP_TB:
7906 po_misc_or_fail (parse_tb (&str));
7907 break;
7908
e07e6e58 7909 /* Register lists. */
c19d1205 7910 case OP_REGLST:
4b5a202f 7911 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7912 if (*str == '^')
7913 {
5e0d7f77 7914 inst.operands[i].writeback = 1;
c19d1205
ZW
7915 str++;
7916 }
7917 break;
09d92015 7918
4b5a202f
AV
7919 case OP_CLRMLST:
7920 val = parse_reg_list (&str, REGLIST_CLRM);
7921 break;
7922
c19d1205 7923 case OP_VRSLST:
efd6b359
AV
7924 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7925 &partial_match);
c19d1205 7926 break;
09d92015 7927
c19d1205 7928 case OP_VRDLST:
efd6b359
AV
7929 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7930 &partial_match);
c19d1205 7931 break;
a737bd4d 7932
477330fc
RM
7933 case OP_VRSDLST:
7934 /* Allow Q registers too. */
7935 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7936 REGLIST_NEON_D, &partial_match);
477330fc
RM
7937 if (val == FAIL)
7938 {
7939 inst.error = NULL;
7940 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7941 REGLIST_VFP_S, &partial_match);
7942 inst.operands[i].issingle = 1;
7943 }
7944 break;
7945
7946 case OP_VRSDVLST:
7947 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7948 REGLIST_VFP_D_VPR, &partial_match);
7949 if (val == FAIL && !partial_match)
7950 {
7951 inst.error = NULL;
7952 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7953 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7954 inst.operands[i].issingle = 1;
7955 }
7956 break;
7957
7958 case OP_NRDLST:
7959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7960 REGLIST_NEON_D, &partial_match);
477330fc 7961 break;
5287ad62 7962
35c228db
AV
7963 case OP_MSTRLST4:
7964 case OP_MSTRLST2:
7965 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7966 1, &inst.operands[i].vectype);
7967 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7968 goto failure;
7969 break;
5287ad62 7970 case OP_NSTRLST:
477330fc 7971 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7972 0, &inst.operands[i].vectype);
477330fc 7973 break;
5287ad62 7974
c19d1205 7975 /* Addressing modes */
35c228db
AV
7976 case OP_ADDRMVE:
7977 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7978 break;
7979
c19d1205
ZW
7980 case OP_ADDR:
7981 po_misc_or_fail (parse_address (&str, i));
7982 break;
09d92015 7983
4962c51a
MS
7984 case OP_ADDRGLDR:
7985 po_misc_or_fail_no_backtrack (
477330fc 7986 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7987 break;
7988
7989 case OP_ADDRGLDRS:
7990 po_misc_or_fail_no_backtrack (
477330fc 7991 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7992 break;
7993
7994 case OP_ADDRGLDC:
7995 po_misc_or_fail_no_backtrack (
477330fc 7996 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7997 break;
7998
c19d1205
ZW
7999 case OP_SH:
8000 po_misc_or_fail (parse_shifter_operand (&str, i));
8001 break;
09d92015 8002
4962c51a
MS
8003 case OP_SHG:
8004 po_misc_or_fail_no_backtrack (
477330fc 8005 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
8006 break;
8007
c19d1205
ZW
8008 case OP_oSHll:
8009 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8010 break;
09d92015 8011
c19d1205
ZW
8012 case OP_oSHar:
8013 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8014 break;
09d92015 8015
c19d1205
ZW
8016 case OP_oSHllar:
8017 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8018 break;
09d92015 8019
1b883319
AV
8020 case OP_RMQRZ:
8021 case OP_oRMQRZ:
8022 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8023 break;
e39c1607
SD
8024
8025 case OP_RR_ZR:
1b883319
AV
8026 try_rr_zr:
8027 po_reg_or_goto (REG_TYPE_RN, ZR);
8028 break;
8029 ZR:
8030 po_reg_or_fail (REG_TYPE_ZR);
8031 break;
8032
c19d1205 8033 default:
5be8be5d 8034 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 8035 }
09d92015 8036
c19d1205
ZW
8037 /* Various value-based sanity checks and shared operations. We
8038 do not signal immediate failures for the register constraints;
8039 this allows a syntax error to take precedence. */
5be8be5d 8040 switch (op_parse_code)
c19d1205
ZW
8041 {
8042 case OP_oRRnpc:
8043 case OP_RRnpc:
8044 case OP_RRnpcb:
8045 case OP_RRw:
b6702015 8046 case OP_oRRw:
c19d1205
ZW
8047 case OP_RRnpc_I0:
8048 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8049 inst.error = BAD_PC;
8050 break;
09d92015 8051
5be8be5d
DG
8052 case OP_oRRnpcsp:
8053 case OP_RRnpcsp:
23d00a41 8054 case OP_RRnpcsp_I32:
5be8be5d
DG
8055 if (inst.operands[i].isreg)
8056 {
8057 if (inst.operands[i].reg == REG_PC)
8058 inst.error = BAD_PC;
5c8ed6a4
JW
8059 else if (inst.operands[i].reg == REG_SP
8060 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8061 relaxed since ARMv8-A. */
8062 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8063 {
8064 gas_assert (thumb);
8065 inst.error = BAD_SP;
8066 }
5be8be5d
DG
8067 }
8068 break;
8069
55881a11 8070 case OP_RRnpctw:
fa94de6b
RM
8071 if (inst.operands[i].isreg
8072 && inst.operands[i].reg == REG_PC
55881a11
MGD
8073 && (inst.operands[i].writeback || thumb))
8074 inst.error = BAD_PC;
8075 break;
8076
1b883319 8077 case OP_RVSD_COND:
32c36c3c
AV
8078 case OP_VLDR:
8079 if (inst.operands[i].isreg)
8080 break;
8081 /* fall through. */
1b883319 8082
c19d1205
ZW
8083 case OP_CPSF:
8084 case OP_ENDI:
8085 case OP_oROR:
d2cd1205
JB
8086 case OP_wPSR:
8087 case OP_rPSR:
c19d1205 8088 case OP_COND:
52e7f43d 8089 case OP_oBARRIER_I15:
c19d1205 8090 case OP_REGLST:
4b5a202f 8091 case OP_CLRMLST:
c19d1205
ZW
8092 case OP_VRSLST:
8093 case OP_VRDLST:
477330fc 8094 case OP_VRSDLST:
efd6b359 8095 case OP_VRSDVLST:
477330fc
RM
8096 case OP_NRDLST:
8097 case OP_NSTRLST:
35c228db
AV
8098 case OP_MSTRLST2:
8099 case OP_MSTRLST4:
c19d1205
ZW
8100 if (val == FAIL)
8101 goto failure;
8102 inst.operands[i].imm = val;
8103 break;
a737bd4d 8104
60f993ce
AV
8105 case OP_LR:
8106 case OP_oLR:
8107 if (inst.operands[i].reg != REG_LR)
8108 inst.error = _("operand must be LR register");
8109 break;
8110
1b883319
AV
8111 case OP_RMQRZ:
8112 case OP_oRMQRZ:
e39c1607 8113 case OP_RR_ZR:
1b883319
AV
8114 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8115 inst.error = BAD_PC;
8116 break;
8117
a302e574
AV
8118 case OP_RRe:
8119 if (inst.operands[i].isreg
8120 && (inst.operands[i].reg & 0x00000001) != 0)
8121 inst.error = BAD_ODD;
8122 break;
8123
8124 case OP_RRo:
8125 if (inst.operands[i].isreg)
8126 {
8127 if ((inst.operands[i].reg & 0x00000001) != 1)
8128 inst.error = BAD_EVEN;
8129 else if (inst.operands[i].reg == REG_SP)
8130 as_tsktsk (MVE_BAD_SP);
8131 else if (inst.operands[i].reg == REG_PC)
8132 inst.error = BAD_PC;
8133 }
8134 break;
8135
c19d1205
ZW
8136 default:
8137 break;
8138 }
09d92015 8139
c19d1205
ZW
8140 /* If we get here, this operand was successfully parsed. */
8141 inst.operands[i].present = 1;
8142 continue;
09d92015 8143
c19d1205 8144 bad_args:
09d92015 8145 inst.error = BAD_ARGS;
c19d1205
ZW
8146
8147 failure:
8148 if (!backtrack_pos)
d252fdde
PB
8149 {
8150 /* The parse routine should already have set inst.error, but set a
5f4273c7 8151 default here just in case. */
d252fdde 8152 if (!inst.error)
5ee91343 8153 inst.error = BAD_SYNTAX;
d252fdde
PB
8154 return FAIL;
8155 }
c19d1205
ZW
8156
8157 /* Do not backtrack over a trailing optional argument that
8158 absorbed some text. We will only fail again, with the
8159 'garbage following instruction' error message, which is
8160 probably less helpful than the current one. */
8161 if (backtrack_index == i && backtrack_pos != str
8162 && upat[i+1] == OP_stop)
d252fdde
PB
8163 {
8164 if (!inst.error)
5ee91343 8165 inst.error = BAD_SYNTAX;
d252fdde
PB
8166 return FAIL;
8167 }
c19d1205
ZW
8168
8169 /* Try again, skipping the optional argument at backtrack_pos. */
8170 str = backtrack_pos;
8171 inst.error = backtrack_error;
8172 inst.operands[backtrack_index].present = 0;
8173 i = backtrack_index;
8174 backtrack_pos = 0;
09d92015 8175 }
09d92015 8176
c19d1205
ZW
8177 /* Check that we have parsed all the arguments. */
8178 if (*str != '\0' && !inst.error)
8179 inst.error = _("garbage following instruction");
09d92015 8180
c19d1205 8181 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8182}
8183
c19d1205
ZW
8184#undef po_char_or_fail
8185#undef po_reg_or_fail
8186#undef po_reg_or_goto
8187#undef po_imm_or_fail
5287ad62 8188#undef po_scalar_or_fail
52e7f43d 8189#undef po_barrier_or_imm
e07e6e58 8190
c19d1205 8191/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8192#define constraint(expr, err) \
8193 do \
c19d1205 8194 { \
e07e6e58
NC
8195 if (expr) \
8196 { \
8197 inst.error = err; \
8198 return; \
8199 } \
c19d1205 8200 } \
e07e6e58 8201 while (0)
c19d1205 8202
fdfde340
JM
8203/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8204 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8205 is the BadReg predicate in ARM's Thumb-2 documentation.
8206
8207 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8208 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8209#define reject_bad_reg(reg) \
8210 do \
8211 if (reg == REG_PC) \
8212 { \
8213 inst.error = BAD_PC; \
8214 return; \
8215 } \
8216 else if (reg == REG_SP \
8217 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8218 { \
8219 inst.error = BAD_SP; \
8220 return; \
8221 } \
fdfde340
JM
8222 while (0)
8223
94206790
MM
8224/* If REG is R13 (the stack pointer), warn that its use is
8225 deprecated. */
8226#define warn_deprecated_sp(reg) \
8227 do \
8228 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8229 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8230 while (0)
8231
c19d1205
ZW
8232/* Functions for operand encoding. ARM, then Thumb. */
8233
d840c081 8234#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8235
9db2f6b4
RL
8236/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8237
8238 The only binary encoding difference is the Coprocessor number. Coprocessor
8239 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8240 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8241 exists for Single-Precision operation. */
8242
8243static void
8244do_scalar_fp16_v82_encode (void)
8245{
5ee91343 8246 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8247 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8248 " the behaviour is UNPREDICTABLE"));
8249 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8250 _(BAD_FP16));
8251
8252 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8253 mark_feature_used (&arm_ext_fp16);
8254}
8255
c19d1205
ZW
8256/* If VAL can be encoded in the immediate field of an ARM instruction,
8257 return the encoded form. Otherwise, return FAIL. */
8258
8259static unsigned int
8260encode_arm_immediate (unsigned int val)
09d92015 8261{
c19d1205
ZW
8262 unsigned int a, i;
8263
4f1d6205
L
8264 if (val <= 0xff)
8265 return val;
8266
8267 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8268 if ((a = rotate_left (val, i)) <= 0xff)
8269 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8270
8271 return FAIL;
09d92015
MM
8272}
8273
c19d1205
ZW
8274/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8275 return the encoded form. Otherwise, return FAIL. */
8276static unsigned int
8277encode_thumb32_immediate (unsigned int val)
09d92015 8278{
c19d1205 8279 unsigned int a, i;
09d92015 8280
9c3c69f2 8281 if (val <= 0xff)
c19d1205 8282 return val;
a737bd4d 8283
9c3c69f2 8284 for (i = 1; i <= 24; i++)
09d92015 8285 {
9c3c69f2
PB
8286 a = val >> i;
8287 if ((val & ~(0xff << i)) == 0)
8288 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8289 }
a737bd4d 8290
c19d1205
ZW
8291 a = val & 0xff;
8292 if (val == ((a << 16) | a))
8293 return 0x100 | a;
8294 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8295 return 0x300 | a;
09d92015 8296
c19d1205
ZW
8297 a = val & 0xff00;
8298 if (val == ((a << 16) | a))
8299 return 0x200 | (a >> 8);
a737bd4d 8300
c19d1205 8301 return FAIL;
09d92015 8302}
5287ad62 8303/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8304
8305static void
5287ad62
JB
8306encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8307{
8308 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8309 && reg > 15)
8310 {
b1cc4aeb 8311 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8312 {
8313 if (thumb_mode)
8314 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8315 fpu_vfp_ext_d32);
8316 else
8317 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8318 fpu_vfp_ext_d32);
8319 }
5287ad62 8320 else
477330fc
RM
8321 {
8322 first_error (_("D register out of range for selected VFP version"));
8323 return;
8324 }
5287ad62
JB
8325 }
8326
c19d1205 8327 switch (pos)
09d92015 8328 {
c19d1205
ZW
8329 case VFP_REG_Sd:
8330 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8331 break;
8332
8333 case VFP_REG_Sn:
8334 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8335 break;
8336
8337 case VFP_REG_Sm:
8338 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8339 break;
8340
5287ad62
JB
8341 case VFP_REG_Dd:
8342 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8343 break;
5f4273c7 8344
5287ad62
JB
8345 case VFP_REG_Dn:
8346 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8347 break;
5f4273c7 8348
5287ad62
JB
8349 case VFP_REG_Dm:
8350 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8351 break;
8352
c19d1205
ZW
8353 default:
8354 abort ();
09d92015 8355 }
09d92015
MM
8356}
8357
c19d1205 8358/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8359 if any, is handled by md_apply_fix. */
09d92015 8360static void
c19d1205 8361encode_arm_shift (int i)
09d92015 8362{
008a97ef
RL
8363 /* register-shifted register. */
8364 if (inst.operands[i].immisreg)
8365 {
bf355b69
MR
8366 int op_index;
8367 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8368 {
5689c942
RL
8369 /* Check the operand only when it's presented. In pre-UAL syntax,
8370 if the destination register is the same as the first operand, two
8371 register form of the instruction can be used. */
bf355b69
MR
8372 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8373 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8374 as_warn (UNPRED_REG ("r15"));
8375 }
8376
8377 if (inst.operands[i].imm == REG_PC)
8378 as_warn (UNPRED_REG ("r15"));
8379 }
8380
c19d1205
ZW
8381 if (inst.operands[i].shift_kind == SHIFT_RRX)
8382 inst.instruction |= SHIFT_ROR << 5;
8383 else
09d92015 8384 {
c19d1205
ZW
8385 inst.instruction |= inst.operands[i].shift_kind << 5;
8386 if (inst.operands[i].immisreg)
8387 {
8388 inst.instruction |= SHIFT_BY_REG;
8389 inst.instruction |= inst.operands[i].imm << 8;
8390 }
8391 else
e2b0ab59 8392 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8393 }
c19d1205 8394}
09d92015 8395
c19d1205
ZW
8396static void
8397encode_arm_shifter_operand (int i)
8398{
8399 if (inst.operands[i].isreg)
09d92015 8400 {
c19d1205
ZW
8401 inst.instruction |= inst.operands[i].reg;
8402 encode_arm_shift (i);
09d92015 8403 }
c19d1205 8404 else
a415b1cd
JB
8405 {
8406 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8407 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8408 inst.instruction |= inst.operands[i].imm;
8409 }
09d92015
MM
8410}
8411
c19d1205 8412/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8413static void
c19d1205 8414encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8415{
2b2f5df9
NC
8416 /* PR 14260:
8417 Generate an error if the operand is not a register. */
8418 constraint (!inst.operands[i].isreg,
8419 _("Instruction does not support =N addresses"));
8420
c19d1205 8421 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8422
c19d1205 8423 if (inst.operands[i].preind)
09d92015 8424 {
c19d1205
ZW
8425 if (is_t)
8426 {
8427 inst.error = _("instruction does not accept preindexed addressing");
8428 return;
8429 }
8430 inst.instruction |= PRE_INDEX;
8431 if (inst.operands[i].writeback)
8432 inst.instruction |= WRITE_BACK;
09d92015 8433
c19d1205
ZW
8434 }
8435 else if (inst.operands[i].postind)
8436 {
9c2799c2 8437 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8438 if (is_t)
8439 inst.instruction |= WRITE_BACK;
8440 }
8441 else /* unindexed - only for coprocessor */
09d92015 8442 {
c19d1205 8443 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8444 return;
8445 }
8446
c19d1205
ZW
8447 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8448 && (((inst.instruction & 0x000f0000) >> 16)
8449 == ((inst.instruction & 0x0000f000) >> 12)))
8450 as_warn ((inst.instruction & LOAD_BIT)
8451 ? _("destination register same as write-back base")
8452 : _("source register same as write-back base"));
09d92015
MM
8453}
8454
c19d1205
ZW
8455/* inst.operands[i] was set up by parse_address. Encode it into an
8456 ARM-format mode 2 load or store instruction. If is_t is true,
8457 reject forms that cannot be used with a T instruction (i.e. not
8458 post-indexed). */
a737bd4d 8459static void
c19d1205 8460encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8461{
5be8be5d
DG
8462 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8463
c19d1205 8464 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8465
c19d1205 8466 if (inst.operands[i].immisreg)
09d92015 8467 {
5be8be5d
DG
8468 constraint ((inst.operands[i].imm == REG_PC
8469 || (is_pc && inst.operands[i].writeback)),
8470 BAD_PC_ADDRESSING);
c19d1205
ZW
8471 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8472 inst.instruction |= inst.operands[i].imm;
8473 if (!inst.operands[i].negative)
8474 inst.instruction |= INDEX_UP;
8475 if (inst.operands[i].shifted)
8476 {
8477 if (inst.operands[i].shift_kind == SHIFT_RRX)
8478 inst.instruction |= SHIFT_ROR << 5;
8479 else
8480 {
8481 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8482 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8483 }
8484 }
09d92015 8485 }
e2b0ab59 8486 else /* immediate offset in inst.relocs[0] */
09d92015 8487 {
e2b0ab59 8488 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8489 {
8490 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8491
8492 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8493 cannot use PC in addressing.
8494 PC cannot be used in writeback addressing, either. */
8495 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8496 BAD_PC_ADDRESSING);
23a10334 8497
dc5ec521 8498 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8499 if (warn_on_deprecated
8500 && !is_load
8501 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8502 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8503 }
8504
e2b0ab59 8505 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8506 {
8507 /* Prefer + for zero encoded value. */
8508 if (!inst.operands[i].negative)
8509 inst.instruction |= INDEX_UP;
e2b0ab59 8510 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8511 }
09d92015 8512 }
09d92015
MM
8513}
8514
c19d1205
ZW
8515/* inst.operands[i] was set up by parse_address. Encode it into an
8516 ARM-format mode 3 load or store instruction. Reject forms that
8517 cannot be used with such instructions. If is_t is true, reject
8518 forms that cannot be used with a T instruction (i.e. not
8519 post-indexed). */
8520static void
8521encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8522{
c19d1205 8523 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8524 {
c19d1205
ZW
8525 inst.error = _("instruction does not accept scaled register index");
8526 return;
09d92015 8527 }
a737bd4d 8528
c19d1205 8529 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8530
c19d1205
ZW
8531 if (inst.operands[i].immisreg)
8532 {
5be8be5d 8533 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8534 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8535 BAD_PC_ADDRESSING);
eb9f3f00
JB
8536 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8537 BAD_PC_WRITEBACK);
c19d1205
ZW
8538 inst.instruction |= inst.operands[i].imm;
8539 if (!inst.operands[i].negative)
8540 inst.instruction |= INDEX_UP;
8541 }
e2b0ab59 8542 else /* immediate offset in inst.relocs[0] */
c19d1205 8543 {
e2b0ab59 8544 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8545 && inst.operands[i].writeback),
8546 BAD_PC_WRITEBACK);
c19d1205 8547 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8548 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8549 {
8550 /* Prefer + for zero encoded value. */
8551 if (!inst.operands[i].negative)
8552 inst.instruction |= INDEX_UP;
8553
e2b0ab59 8554 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8555 }
c19d1205 8556 }
a737bd4d
NC
8557}
8558
8335d6aa
JW
8559/* Write immediate bits [7:0] to the following locations:
8560
8561 |28/24|23 19|18 16|15 4|3 0|
8562 | 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|
8563
8564 This function is used by VMOV/VMVN/VORR/VBIC. */
8565
8566static void
8567neon_write_immbits (unsigned immbits)
8568{
8569 inst.instruction |= immbits & 0xf;
8570 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8571 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8572}
8573
8574/* Invert low-order SIZE bits of XHI:XLO. */
8575
8576static void
8577neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8578{
8579 unsigned immlo = xlo ? *xlo : 0;
8580 unsigned immhi = xhi ? *xhi : 0;
8581
8582 switch (size)
8583 {
8584 case 8:
8585 immlo = (~immlo) & 0xff;
8586 break;
8587
8588 case 16:
8589 immlo = (~immlo) & 0xffff;
8590 break;
8591
8592 case 64:
8593 immhi = (~immhi) & 0xffffffff;
8594 /* fall through. */
8595
8596 case 32:
8597 immlo = (~immlo) & 0xffffffff;
8598 break;
8599
8600 default:
8601 abort ();
8602 }
8603
8604 if (xlo)
8605 *xlo = immlo;
8606
8607 if (xhi)
8608 *xhi = immhi;
8609}
8610
8611/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8612 A, B, C, D. */
09d92015 8613
c19d1205 8614static int
8335d6aa 8615neon_bits_same_in_bytes (unsigned imm)
09d92015 8616{
8335d6aa
JW
8617 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8618 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8619 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8620 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8621}
a737bd4d 8622
8335d6aa 8623/* For immediate of above form, return 0bABCD. */
09d92015 8624
8335d6aa
JW
8625static unsigned
8626neon_squash_bits (unsigned imm)
8627{
8628 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8629 | ((imm & 0x01000000) >> 21);
8630}
8631
8632/* Compress quarter-float representation to 0b...000 abcdefgh. */
8633
8634static unsigned
8635neon_qfloat_bits (unsigned imm)
8636{
8637 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8638}
8639
8640/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8641 the instruction. *OP is passed as the initial value of the op field, and
8642 may be set to a different value depending on the constant (i.e.
8643 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8644 MVN). If the immediate looks like a repeated pattern then also
8645 try smaller element sizes. */
8646
8647static int
8648neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8649 unsigned *immbits, int *op, int size,
8650 enum neon_el_type type)
8651{
8652 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8653 float. */
8654 if (type == NT_float && !float_p)
8655 return FAIL;
8656
8657 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8658 {
8335d6aa
JW
8659 if (size != 32 || *op == 1)
8660 return FAIL;
8661 *immbits = neon_qfloat_bits (immlo);
8662 return 0xf;
8663 }
8664
8665 if (size == 64)
8666 {
8667 if (neon_bits_same_in_bytes (immhi)
8668 && neon_bits_same_in_bytes (immlo))
c19d1205 8669 {
8335d6aa
JW
8670 if (*op == 1)
8671 return FAIL;
8672 *immbits = (neon_squash_bits (immhi) << 4)
8673 | neon_squash_bits (immlo);
8674 *op = 1;
8675 return 0xe;
c19d1205 8676 }
a737bd4d 8677
8335d6aa
JW
8678 if (immhi != immlo)
8679 return FAIL;
8680 }
a737bd4d 8681
8335d6aa 8682 if (size >= 32)
09d92015 8683 {
8335d6aa 8684 if (immlo == (immlo & 0x000000ff))
c19d1205 8685 {
8335d6aa
JW
8686 *immbits = immlo;
8687 return 0x0;
c19d1205 8688 }
8335d6aa 8689 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8690 {
8335d6aa
JW
8691 *immbits = immlo >> 8;
8692 return 0x2;
c19d1205 8693 }
8335d6aa
JW
8694 else if (immlo == (immlo & 0x00ff0000))
8695 {
8696 *immbits = immlo >> 16;
8697 return 0x4;
8698 }
8699 else if (immlo == (immlo & 0xff000000))
8700 {
8701 *immbits = immlo >> 24;
8702 return 0x6;
8703 }
8704 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8705 {
8706 *immbits = (immlo >> 8) & 0xff;
8707 return 0xc;
8708 }
8709 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8710 {
8711 *immbits = (immlo >> 16) & 0xff;
8712 return 0xd;
8713 }
8714
8715 if ((immlo & 0xffff) != (immlo >> 16))
8716 return FAIL;
8717 immlo &= 0xffff;
09d92015 8718 }
a737bd4d 8719
8335d6aa 8720 if (size >= 16)
4962c51a 8721 {
8335d6aa
JW
8722 if (immlo == (immlo & 0x000000ff))
8723 {
8724 *immbits = immlo;
8725 return 0x8;
8726 }
8727 else if (immlo == (immlo & 0x0000ff00))
8728 {
8729 *immbits = immlo >> 8;
8730 return 0xa;
8731 }
8732
8733 if ((immlo & 0xff) != (immlo >> 8))
8734 return FAIL;
8735 immlo &= 0xff;
4962c51a
MS
8736 }
8737
8335d6aa
JW
8738 if (immlo == (immlo & 0x000000ff))
8739 {
8740 /* Don't allow MVN with 8-bit immediate. */
8741 if (*op == 1)
8742 return FAIL;
8743 *immbits = immlo;
8744 return 0xe;
8745 }
26d97720 8746
8335d6aa 8747 return FAIL;
c19d1205 8748}
a737bd4d 8749
5fc177c8 8750#if defined BFD_HOST_64_BIT
ba592044
AM
8751/* Returns TRUE if double precision value V may be cast
8752 to single precision without loss of accuracy. */
8753
8754static bfd_boolean
5fc177c8 8755is_double_a_single (bfd_int64_t v)
ba592044 8756{
5fc177c8 8757 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8758 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8759
8760 return (exp == 0 || exp == 0x7FF
8761 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8762 && (mantissa & 0x1FFFFFFFl) == 0;
8763}
8764
3739860c 8765/* Returns a double precision value casted to single precision
ba592044
AM
8766 (ignoring the least significant bits in exponent and mantissa). */
8767
8768static int
5fc177c8 8769double_to_single (bfd_int64_t v)
ba592044
AM
8770{
8771 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8772 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8773 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8774
8775 if (exp == 0x7FF)
8776 exp = 0xFF;
8777 else
8778 {
8779 exp = exp - 1023 + 127;
8780 if (exp >= 0xFF)
8781 {
8782 /* Infinity. */
8783 exp = 0x7F;
8784 mantissa = 0;
8785 }
8786 else if (exp < 0)
8787 {
8788 /* No denormalized numbers. */
8789 exp = 0;
8790 mantissa = 0;
8791 }
8792 }
8793 mantissa >>= 29;
8794 return (sign << 31) | (exp << 23) | mantissa;
8795}
5fc177c8 8796#endif /* BFD_HOST_64_BIT */
ba592044 8797
8335d6aa
JW
8798enum lit_type
8799{
8800 CONST_THUMB,
8801 CONST_ARM,
8802 CONST_VEC
8803};
8804
ba592044
AM
8805static void do_vfp_nsyn_opcode (const char *);
8806
e2b0ab59 8807/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8808 Determine whether it can be performed with a move instruction; if
8809 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8810 return TRUE; if it can't, convert inst.instruction to a literal-pool
8811 load and return FALSE. If this is not a valid thing to do in the
8812 current context, set inst.error and return TRUE.
a737bd4d 8813
c19d1205
ZW
8814 inst.operands[i] describes the destination register. */
8815
c921be7d 8816static bfd_boolean
8335d6aa 8817move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8818{
53365c0d 8819 unsigned long tbit;
8335d6aa
JW
8820 bfd_boolean thumb_p = (t == CONST_THUMB);
8821 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8822
8823 if (thumb_p)
8824 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8825 else
8826 tbit = LOAD_BIT;
8827
8828 if ((inst.instruction & tbit) == 0)
09d92015 8829 {
c19d1205 8830 inst.error = _("invalid pseudo operation");
c921be7d 8831 return TRUE;
09d92015 8832 }
ba592044 8833
e2b0ab59
AV
8834 if (inst.relocs[0].exp.X_op != O_constant
8835 && inst.relocs[0].exp.X_op != O_symbol
8836 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8837 {
8838 inst.error = _("constant expression expected");
c921be7d 8839 return TRUE;
09d92015 8840 }
ba592044 8841
e2b0ab59
AV
8842 if (inst.relocs[0].exp.X_op == O_constant
8843 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8844 {
5fc177c8
NC
8845#if defined BFD_HOST_64_BIT
8846 bfd_int64_t v;
8847#else
ba592044 8848 offsetT v;
5fc177c8 8849#endif
e2b0ab59 8850 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8851 {
ba592044
AM
8852 LITTLENUM_TYPE w[X_PRECISION];
8853 LITTLENUM_TYPE * l;
8854
e2b0ab59 8855 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8856 {
ba592044
AM
8857 gen_to_words (w, X_PRECISION, E_PRECISION);
8858 l = w;
8859 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8860 }
ba592044
AM
8861 else
8862 l = generic_bignum;
3739860c 8863
5fc177c8
NC
8864#if defined BFD_HOST_64_BIT
8865 v =
8866 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8867 << LITTLENUM_NUMBER_OF_BITS)
8868 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8869 << LITTLENUM_NUMBER_OF_BITS)
8870 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8871 << LITTLENUM_NUMBER_OF_BITS)
8872 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8873#else
ba592044
AM
8874 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8875 | (l[0] & LITTLENUM_MASK);
5fc177c8 8876#endif
8335d6aa 8877 }
ba592044 8878 else
e2b0ab59 8879 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8880
8881 if (!inst.operands[i].issingle)
8335d6aa 8882 {
12569877 8883 if (thumb_p)
8335d6aa 8884 {
53445554
TP
8885 /* LDR should not use lead in a flag-setting instruction being
8886 chosen so we do not check whether movs can be used. */
12569877 8887
53445554 8888 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8889 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8890 && inst.operands[i].reg != 13
8891 && inst.operands[i].reg != 15)
12569877 8892 {
fc289b0a
TP
8893 /* Check if on thumb2 it can be done with a mov.w, mvn or
8894 movw instruction. */
12569877
AM
8895 unsigned int newimm;
8896 bfd_boolean isNegated;
8897
8898 newimm = encode_thumb32_immediate (v);
8899 if (newimm != (unsigned int) FAIL)
8900 isNegated = FALSE;
8901 else
8902 {
582cfe03 8903 newimm = encode_thumb32_immediate (~v);
12569877
AM
8904 if (newimm != (unsigned int) FAIL)
8905 isNegated = TRUE;
8906 }
8907
fc289b0a
TP
8908 /* The number can be loaded with a mov.w or mvn
8909 instruction. */
ff8646ee
TP
8910 if (newimm != (unsigned int) FAIL
8911 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8912 {
fc289b0a 8913 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8914 | (inst.operands[i].reg << 8));
fc289b0a 8915 /* Change to MOVN. */
582cfe03 8916 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8917 inst.instruction |= (newimm & 0x800) << 15;
8918 inst.instruction |= (newimm & 0x700) << 4;
8919 inst.instruction |= (newimm & 0x0ff);
8920 return TRUE;
8921 }
fc289b0a 8922 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8923 else if ((v & ~0xFFFF) == 0
8924 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8925 {
582cfe03 8926 int imm = v & 0xFFFF;
12569877 8927
582cfe03 8928 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8929 inst.instruction |= (inst.operands[i].reg << 8);
8930 inst.instruction |= (imm & 0xf000) << 4;
8931 inst.instruction |= (imm & 0x0800) << 15;
8932 inst.instruction |= (imm & 0x0700) << 4;
8933 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8934 /* In case this replacement is being done on Armv8-M
8935 Baseline we need to make sure to disable the
8936 instruction size check, as otherwise GAS will reject
8937 the use of this T32 instruction. */
8938 inst.size_req = 0;
12569877
AM
8939 return TRUE;
8940 }
8941 }
8335d6aa 8942 }
12569877 8943 else if (arm_p)
ba592044
AM
8944 {
8945 int value = encode_arm_immediate (v);
12569877 8946
ba592044
AM
8947 if (value != FAIL)
8948 {
8949 /* This can be done with a mov instruction. */
8950 inst.instruction &= LITERAL_MASK;
8951 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8952 inst.instruction |= value & 0xfff;
8953 return TRUE;
8954 }
8335d6aa 8955
ba592044
AM
8956 value = encode_arm_immediate (~ v);
8957 if (value != FAIL)
8958 {
8959 /* This can be done with a mvn instruction. */
8960 inst.instruction &= LITERAL_MASK;
8961 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8962 inst.instruction |= value & 0xfff;
8963 return TRUE;
8964 }
8965 }
934c2632 8966 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8967 {
ba592044
AM
8968 int op = 0;
8969 unsigned immbits = 0;
8970 unsigned immlo = inst.operands[1].imm;
8971 unsigned immhi = inst.operands[1].regisimm
8972 ? inst.operands[1].reg
e2b0ab59 8973 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8974 ? 0
8975 : ((bfd_int64_t)((int) immlo)) >> 32;
8976 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8977 &op, 64, NT_invtype);
8978
8979 if (cmode == FAIL)
8980 {
8981 neon_invert_size (&immlo, &immhi, 64);
8982 op = !op;
8983 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8984 &op, 64, NT_invtype);
8985 }
8986
8987 if (cmode != FAIL)
8988 {
8989 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8990 | (1 << 23)
8991 | (cmode << 8)
8992 | (op << 5)
8993 | (1 << 4);
8994
8995 /* Fill other bits in vmov encoding for both thumb and arm. */
8996 if (thumb_mode)
eff0bc54 8997 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8998 else
eff0bc54 8999 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
9000 neon_write_immbits (immbits);
9001 return TRUE;
9002 }
8335d6aa
JW
9003 }
9004 }
8335d6aa 9005
ba592044
AM
9006 if (t == CONST_VEC)
9007 {
9008 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9009 if (inst.operands[i].issingle
9010 && is_quarter_float (inst.operands[1].imm)
9011 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 9012 {
ba592044
AM
9013 inst.operands[1].imm =
9014 neon_qfloat_bits (v);
9015 do_vfp_nsyn_opcode ("fconsts");
9016 return TRUE;
8335d6aa 9017 }
5fc177c8
NC
9018
9019 /* If our host does not support a 64-bit type then we cannot perform
9020 the following optimization. This mean that there will be a
9021 discrepancy between the output produced by an assembler built for
9022 a 32-bit-only host and the output produced from a 64-bit host, but
9023 this cannot be helped. */
9024#if defined BFD_HOST_64_BIT
ba592044
AM
9025 else if (!inst.operands[1].issingle
9026 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 9027 {
ba592044
AM
9028 if (is_double_a_single (v)
9029 && is_quarter_float (double_to_single (v)))
9030 {
9031 inst.operands[1].imm =
9032 neon_qfloat_bits (double_to_single (v));
9033 do_vfp_nsyn_opcode ("fconstd");
9034 return TRUE;
9035 }
8335d6aa 9036 }
5fc177c8 9037#endif
8335d6aa
JW
9038 }
9039 }
9040
9041 if (add_to_lit_pool ((!inst.operands[i].isvec
9042 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9043 return TRUE;
9044
9045 inst.operands[1].reg = REG_PC;
9046 inst.operands[1].isreg = 1;
9047 inst.operands[1].preind = 1;
e2b0ab59
AV
9048 inst.relocs[0].pc_rel = 1;
9049 inst.relocs[0].type = (thumb_p
8335d6aa
JW
9050 ? BFD_RELOC_ARM_THUMB_OFFSET
9051 : (mode_3
9052 ? BFD_RELOC_ARM_HWLITERAL
9053 : BFD_RELOC_ARM_LITERAL));
9054 return FALSE;
9055}
9056
9057/* inst.operands[i] was set up by parse_address. Encode it into an
9058 ARM-format instruction. Reject all forms which cannot be encoded
9059 into a coprocessor load/store instruction. If wb_ok is false,
9060 reject use of writeback; if unind_ok is false, reject use of
9061 unindexed addressing. If reloc_override is not 0, use it instead
9062 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9063 (in which case it is preserved). */
9064
9065static int
9066encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9067{
9068 if (!inst.operands[i].isreg)
9069 {
99b2a2dd
NC
9070 /* PR 18256 */
9071 if (! inst.operands[0].isvec)
9072 {
9073 inst.error = _("invalid co-processor operand");
9074 return FAIL;
9075 }
8335d6aa
JW
9076 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9077 return SUCCESS;
9078 }
9079
9080 inst.instruction |= inst.operands[i].reg << 16;
9081
9082 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9083
9084 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9085 {
9086 gas_assert (!inst.operands[i].writeback);
9087 if (!unind_ok)
9088 {
9089 inst.error = _("instruction does not support unindexed addressing");
9090 return FAIL;
9091 }
9092 inst.instruction |= inst.operands[i].imm;
9093 inst.instruction |= INDEX_UP;
9094 return SUCCESS;
9095 }
9096
9097 if (inst.operands[i].preind)
9098 inst.instruction |= PRE_INDEX;
9099
9100 if (inst.operands[i].writeback)
09d92015 9101 {
8335d6aa 9102 if (inst.operands[i].reg == REG_PC)
c19d1205 9103 {
8335d6aa
JW
9104 inst.error = _("pc may not be used with write-back");
9105 return FAIL;
c19d1205 9106 }
8335d6aa 9107 if (!wb_ok)
c19d1205 9108 {
8335d6aa
JW
9109 inst.error = _("instruction does not support writeback");
9110 return FAIL;
c19d1205 9111 }
8335d6aa 9112 inst.instruction |= WRITE_BACK;
09d92015
MM
9113 }
9114
8335d6aa 9115 if (reloc_override)
e2b0ab59
AV
9116 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9117 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9118 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9119 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 9120 {
8335d6aa 9121 if (thumb_mode)
e2b0ab59 9122 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 9123 else
e2b0ab59 9124 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 9125 }
8335d6aa
JW
9126
9127 /* Prefer + for zero encoded value. */
9128 if (!inst.operands[i].negative)
9129 inst.instruction |= INDEX_UP;
9130
9131 return SUCCESS;
09d92015
MM
9132}
9133
5f4273c7 9134/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
9135 First some generics; their names are taken from the conventional
9136 bit positions for register arguments in ARM format instructions. */
09d92015 9137
a737bd4d 9138static void
c19d1205 9139do_noargs (void)
09d92015 9140{
c19d1205 9141}
a737bd4d 9142
c19d1205
ZW
9143static void
9144do_rd (void)
9145{
9146 inst.instruction |= inst.operands[0].reg << 12;
9147}
a737bd4d 9148
16a1fa25
TP
9149static void
9150do_rn (void)
9151{
9152 inst.instruction |= inst.operands[0].reg << 16;
9153}
9154
c19d1205
ZW
9155static void
9156do_rd_rm (void)
9157{
9158 inst.instruction |= inst.operands[0].reg << 12;
9159 inst.instruction |= inst.operands[1].reg;
9160}
09d92015 9161
9eb6c0f1
MGD
9162static void
9163do_rm_rn (void)
9164{
9165 inst.instruction |= inst.operands[0].reg;
9166 inst.instruction |= inst.operands[1].reg << 16;
9167}
9168
c19d1205
ZW
9169static void
9170do_rd_rn (void)
9171{
9172 inst.instruction |= inst.operands[0].reg << 12;
9173 inst.instruction |= inst.operands[1].reg << 16;
9174}
a737bd4d 9175
c19d1205
ZW
9176static void
9177do_rn_rd (void)
9178{
9179 inst.instruction |= inst.operands[0].reg << 16;
9180 inst.instruction |= inst.operands[1].reg << 12;
9181}
09d92015 9182
4ed7ed8d
TP
9183static void
9184do_tt (void)
9185{
9186 inst.instruction |= inst.operands[0].reg << 8;
9187 inst.instruction |= inst.operands[1].reg << 16;
9188}
9189
59d09be6
MGD
9190static bfd_boolean
9191check_obsolete (const arm_feature_set *feature, const char *msg)
9192{
9193 if (ARM_CPU_IS_ANY (cpu_variant))
9194 {
5c3696f8 9195 as_tsktsk ("%s", msg);
59d09be6
MGD
9196 return TRUE;
9197 }
9198 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9199 {
9200 as_bad ("%s", msg);
9201 return TRUE;
9202 }
9203
9204 return FALSE;
9205}
9206
c19d1205
ZW
9207static void
9208do_rd_rm_rn (void)
9209{
9a64e435 9210 unsigned Rn = inst.operands[2].reg;
708587a4 9211 /* Enforce restrictions on SWP instruction. */
9a64e435 9212 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9213 {
9214 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9215 _("Rn must not overlap other operands"));
9216
59d09be6
MGD
9217 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9218 */
9219 if (!check_obsolete (&arm_ext_v8,
9220 _("swp{b} use is obsoleted for ARMv8 and later"))
9221 && warn_on_deprecated
9222 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9223 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9224 }
59d09be6 9225
c19d1205
ZW
9226 inst.instruction |= inst.operands[0].reg << 12;
9227 inst.instruction |= inst.operands[1].reg;
9a64e435 9228 inst.instruction |= Rn << 16;
c19d1205 9229}
09d92015 9230
c19d1205
ZW
9231static void
9232do_rd_rn_rm (void)
9233{
9234 inst.instruction |= inst.operands[0].reg << 12;
9235 inst.instruction |= inst.operands[1].reg << 16;
9236 inst.instruction |= inst.operands[2].reg;
9237}
a737bd4d 9238
c19d1205
ZW
9239static void
9240do_rm_rd_rn (void)
9241{
5be8be5d 9242 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9243 constraint (((inst.relocs[0].exp.X_op != O_constant
9244 && inst.relocs[0].exp.X_op != O_illegal)
9245 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9246 BAD_ADDR_MODE);
c19d1205
ZW
9247 inst.instruction |= inst.operands[0].reg;
9248 inst.instruction |= inst.operands[1].reg << 12;
9249 inst.instruction |= inst.operands[2].reg << 16;
9250}
09d92015 9251
c19d1205
ZW
9252static void
9253do_imm0 (void)
9254{
9255 inst.instruction |= inst.operands[0].imm;
9256}
09d92015 9257
c19d1205
ZW
9258static void
9259do_rd_cpaddr (void)
9260{
9261 inst.instruction |= inst.operands[0].reg << 12;
9262 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9263}
a737bd4d 9264
c19d1205
ZW
9265/* ARM instructions, in alphabetical order by function name (except
9266 that wrapper functions appear immediately after the function they
9267 wrap). */
09d92015 9268
c19d1205
ZW
9269/* This is a pseudo-op of the form "adr rd, label" to be converted
9270 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9271
9272static void
c19d1205 9273do_adr (void)
09d92015 9274{
c19d1205 9275 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9276
c19d1205
ZW
9277 /* Frag hacking will turn this into a sub instruction if the offset turns
9278 out to be negative. */
e2b0ab59
AV
9279 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9280 inst.relocs[0].pc_rel = 1;
9281 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9282
fc6141f0 9283 if (support_interwork
e2b0ab59
AV
9284 && inst.relocs[0].exp.X_op == O_symbol
9285 && inst.relocs[0].exp.X_add_symbol != NULL
9286 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9287 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9288 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9289}
b99bd4ef 9290
c19d1205
ZW
9291/* This is a pseudo-op of the form "adrl rd, label" to be converted
9292 into a relative address of the form:
9293 add rd, pc, #low(label-.-8)"
9294 add rd, rd, #high(label-.-8)" */
b99bd4ef 9295
c19d1205
ZW
9296static void
9297do_adrl (void)
9298{
9299 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9300
c19d1205
ZW
9301 /* Frag hacking will turn this into a sub instruction if the offset turns
9302 out to be negative. */
e2b0ab59
AV
9303 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9304 inst.relocs[0].pc_rel = 1;
c19d1205 9305 inst.size = INSN_SIZE * 2;
e2b0ab59 9306 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9307
fc6141f0 9308 if (support_interwork
e2b0ab59
AV
9309 && inst.relocs[0].exp.X_op == O_symbol
9310 && inst.relocs[0].exp.X_add_symbol != NULL
9311 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9312 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9313 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9314}
9315
b99bd4ef 9316static void
c19d1205 9317do_arit (void)
b99bd4ef 9318{
e2b0ab59
AV
9319 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9320 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9321 THUMB1_RELOC_ONLY);
c19d1205
ZW
9322 if (!inst.operands[1].present)
9323 inst.operands[1].reg = inst.operands[0].reg;
9324 inst.instruction |= inst.operands[0].reg << 12;
9325 inst.instruction |= inst.operands[1].reg << 16;
9326 encode_arm_shifter_operand (2);
9327}
b99bd4ef 9328
62b3e311
PB
9329static void
9330do_barrier (void)
9331{
9332 if (inst.operands[0].present)
ccb84d65 9333 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9334 else
9335 inst.instruction |= 0xf;
9336}
9337
c19d1205
ZW
9338static void
9339do_bfc (void)
9340{
9341 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9342 constraint (msb > 32, _("bit-field extends past end of register"));
9343 /* The instruction encoding stores the LSB and MSB,
9344 not the LSB and width. */
9345 inst.instruction |= inst.operands[0].reg << 12;
9346 inst.instruction |= inst.operands[1].imm << 7;
9347 inst.instruction |= (msb - 1) << 16;
9348}
b99bd4ef 9349
c19d1205
ZW
9350static void
9351do_bfi (void)
9352{
9353 unsigned int msb;
b99bd4ef 9354
c19d1205
ZW
9355 /* #0 in second position is alternative syntax for bfc, which is
9356 the same instruction but with REG_PC in the Rm field. */
9357 if (!inst.operands[1].isreg)
9358 inst.operands[1].reg = REG_PC;
b99bd4ef 9359
c19d1205
ZW
9360 msb = inst.operands[2].imm + inst.operands[3].imm;
9361 constraint (msb > 32, _("bit-field extends past end of register"));
9362 /* The instruction encoding stores the LSB and MSB,
9363 not the LSB and width. */
9364 inst.instruction |= inst.operands[0].reg << 12;
9365 inst.instruction |= inst.operands[1].reg;
9366 inst.instruction |= inst.operands[2].imm << 7;
9367 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9368}
9369
b99bd4ef 9370static void
c19d1205 9371do_bfx (void)
b99bd4ef 9372{
c19d1205
ZW
9373 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9374 _("bit-field extends past end of register"));
9375 inst.instruction |= inst.operands[0].reg << 12;
9376 inst.instruction |= inst.operands[1].reg;
9377 inst.instruction |= inst.operands[2].imm << 7;
9378 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9379}
09d92015 9380
c19d1205
ZW
9381/* ARM V5 breakpoint instruction (argument parse)
9382 BKPT <16 bit unsigned immediate>
9383 Instruction is not conditional.
9384 The bit pattern given in insns[] has the COND_ALWAYS condition,
9385 and it is an error if the caller tried to override that. */
b99bd4ef 9386
c19d1205
ZW
9387static void
9388do_bkpt (void)
9389{
9390 /* Top 12 of 16 bits to bits 19:8. */
9391 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9392
c19d1205
ZW
9393 /* Bottom 4 of 16 bits to bits 3:0. */
9394 inst.instruction |= inst.operands[0].imm & 0xf;
9395}
09d92015 9396
c19d1205
ZW
9397static void
9398encode_branch (int default_reloc)
9399{
9400 if (inst.operands[0].hasreloc)
9401 {
0855e32b
NS
9402 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9403 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9404 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9405 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9406 ? BFD_RELOC_ARM_PLT32
9407 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9408 }
b99bd4ef 9409 else
e2b0ab59
AV
9410 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9411 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9412}
9413
b99bd4ef 9414static void
c19d1205 9415do_branch (void)
b99bd4ef 9416{
39b41c9c
PB
9417#ifdef OBJ_ELF
9418 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9419 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9420 else
9421#endif
9422 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9423}
9424
9425static void
9426do_bl (void)
9427{
9428#ifdef OBJ_ELF
9429 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9430 {
9431 if (inst.cond == COND_ALWAYS)
9432 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9433 else
9434 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9435 }
9436 else
9437#endif
9438 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9439}
b99bd4ef 9440
c19d1205
ZW
9441/* ARM V5 branch-link-exchange instruction (argument parse)
9442 BLX <target_addr> ie BLX(1)
9443 BLX{<condition>} <Rm> ie BLX(2)
9444 Unfortunately, there are two different opcodes for this mnemonic.
9445 So, the insns[].value is not used, and the code here zaps values
9446 into inst.instruction.
9447 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9448
c19d1205
ZW
9449static void
9450do_blx (void)
9451{
9452 if (inst.operands[0].isreg)
b99bd4ef 9453 {
c19d1205
ZW
9454 /* Arg is a register; the opcode provided by insns[] is correct.
9455 It is not illegal to do "blx pc", just useless. */
9456 if (inst.operands[0].reg == REG_PC)
9457 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9458
c19d1205
ZW
9459 inst.instruction |= inst.operands[0].reg;
9460 }
9461 else
b99bd4ef 9462 {
c19d1205 9463 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9464 conditionally, and the opcode must be adjusted.
9465 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9466 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9467 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9468 inst.instruction = 0xfa000000;
267bf995 9469 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9470 }
c19d1205
ZW
9471}
9472
9473static void
9474do_bx (void)
9475{
845b51d6
PB
9476 bfd_boolean want_reloc;
9477
c19d1205
ZW
9478 if (inst.operands[0].reg == REG_PC)
9479 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9480
c19d1205 9481 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9482 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9483 it is for ARMv4t or earlier. */
9484 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9485 if (!ARM_FEATURE_ZERO (selected_object_arch)
9486 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9487 want_reloc = TRUE;
9488
5ad34203 9489#ifdef OBJ_ELF
845b51d6 9490 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9491#endif
584206db 9492 want_reloc = FALSE;
845b51d6
PB
9493
9494 if (want_reloc)
e2b0ab59 9495 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9496}
9497
c19d1205
ZW
9498
9499/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9500
9501static void
c19d1205 9502do_bxj (void)
a737bd4d 9503{
c19d1205
ZW
9504 if (inst.operands[0].reg == REG_PC)
9505 as_tsktsk (_("use of r15 in bxj is not really useful"));
9506
9507 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9508}
9509
c19d1205
ZW
9510/* Co-processor data operation:
9511 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9512 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9513static void
9514do_cdp (void)
9515{
9516 inst.instruction |= inst.operands[0].reg << 8;
9517 inst.instruction |= inst.operands[1].imm << 20;
9518 inst.instruction |= inst.operands[2].reg << 12;
9519 inst.instruction |= inst.operands[3].reg << 16;
9520 inst.instruction |= inst.operands[4].reg;
9521 inst.instruction |= inst.operands[5].imm << 5;
9522}
a737bd4d
NC
9523
9524static void
c19d1205 9525do_cmp (void)
a737bd4d 9526{
c19d1205
ZW
9527 inst.instruction |= inst.operands[0].reg << 16;
9528 encode_arm_shifter_operand (1);
a737bd4d
NC
9529}
9530
c19d1205
ZW
9531/* Transfer between coprocessor and ARM registers.
9532 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9533 MRC2
9534 MCR{cond}
9535 MCR2
9536
9537 No special properties. */
09d92015 9538
dcbd0d71
MGD
9539struct deprecated_coproc_regs_s
9540{
9541 unsigned cp;
9542 int opc1;
9543 unsigned crn;
9544 unsigned crm;
9545 int opc2;
9546 arm_feature_set deprecated;
9547 arm_feature_set obsoleted;
9548 const char *dep_msg;
9549 const char *obs_msg;
9550};
9551
9552#define DEPR_ACCESS_V8 \
9553 N_("This coprocessor register access is deprecated in ARMv8")
9554
9555/* Table of all deprecated coprocessor registers. */
9556static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9557{
9558 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9559 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9560 DEPR_ACCESS_V8, NULL},
9561 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9562 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9563 DEPR_ACCESS_V8, NULL},
9564 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9565 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9566 DEPR_ACCESS_V8, NULL},
9567 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9568 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9569 DEPR_ACCESS_V8, NULL},
9570 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9571 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9572 DEPR_ACCESS_V8, NULL},
9573};
9574
9575#undef DEPR_ACCESS_V8
9576
9577static const size_t deprecated_coproc_reg_count =
9578 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9579
09d92015 9580static void
c19d1205 9581do_co_reg (void)
09d92015 9582{
fdfde340 9583 unsigned Rd;
dcbd0d71 9584 size_t i;
fdfde340
JM
9585
9586 Rd = inst.operands[2].reg;
9587 if (thumb_mode)
9588 {
9589 if (inst.instruction == 0xee000010
9590 || inst.instruction == 0xfe000010)
9591 /* MCR, MCR2 */
9592 reject_bad_reg (Rd);
5c8ed6a4 9593 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9594 /* MRC, MRC2 */
9595 constraint (Rd == REG_SP, BAD_SP);
9596 }
9597 else
9598 {
9599 /* MCR */
9600 if (inst.instruction == 0xe000010)
9601 constraint (Rd == REG_PC, BAD_PC);
9602 }
9603
dcbd0d71
MGD
9604 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9605 {
9606 const struct deprecated_coproc_regs_s *r =
9607 deprecated_coproc_regs + i;
9608
9609 if (inst.operands[0].reg == r->cp
9610 && inst.operands[1].imm == r->opc1
9611 && inst.operands[3].reg == r->crn
9612 && inst.operands[4].reg == r->crm
9613 && inst.operands[5].imm == r->opc2)
9614 {
b10bf8c5 9615 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9616 && warn_on_deprecated
dcbd0d71 9617 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9618 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9619 }
9620 }
fdfde340 9621
c19d1205
ZW
9622 inst.instruction |= inst.operands[0].reg << 8;
9623 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9624 inst.instruction |= Rd << 12;
c19d1205
ZW
9625 inst.instruction |= inst.operands[3].reg << 16;
9626 inst.instruction |= inst.operands[4].reg;
9627 inst.instruction |= inst.operands[5].imm << 5;
9628}
09d92015 9629
c19d1205
ZW
9630/* Transfer between coprocessor register and pair of ARM registers.
9631 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9632 MCRR2
9633 MRRC{cond}
9634 MRRC2
b99bd4ef 9635
c19d1205 9636 Two XScale instructions are special cases of these:
09d92015 9637
c19d1205
ZW
9638 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9639 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9640
5f4273c7 9641 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9642
c19d1205
ZW
9643static void
9644do_co_reg2c (void)
9645{
fdfde340
JM
9646 unsigned Rd, Rn;
9647
9648 Rd = inst.operands[2].reg;
9649 Rn = inst.operands[3].reg;
9650
9651 if (thumb_mode)
9652 {
9653 reject_bad_reg (Rd);
9654 reject_bad_reg (Rn);
9655 }
9656 else
9657 {
9658 constraint (Rd == REG_PC, BAD_PC);
9659 constraint (Rn == REG_PC, BAD_PC);
9660 }
9661
873f10f0
TC
9662 /* Only check the MRRC{2} variants. */
9663 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9664 {
9665 /* If Rd == Rn, error that the operation is
9666 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9667 constraint (Rd == Rn, BAD_OVERLAP);
9668 }
9669
c19d1205
ZW
9670 inst.instruction |= inst.operands[0].reg << 8;
9671 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9672 inst.instruction |= Rd << 12;
9673 inst.instruction |= Rn << 16;
c19d1205 9674 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9675}
9676
c19d1205
ZW
9677static void
9678do_cpsi (void)
9679{
9680 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9681 if (inst.operands[1].present)
9682 {
9683 inst.instruction |= CPSI_MMOD;
9684 inst.instruction |= inst.operands[1].imm;
9685 }
c19d1205 9686}
b99bd4ef 9687
62b3e311
PB
9688static void
9689do_dbg (void)
9690{
9691 inst.instruction |= inst.operands[0].imm;
9692}
9693
eea54501
MGD
9694static void
9695do_div (void)
9696{
9697 unsigned Rd, Rn, Rm;
9698
9699 Rd = inst.operands[0].reg;
9700 Rn = (inst.operands[1].present
9701 ? inst.operands[1].reg : Rd);
9702 Rm = inst.operands[2].reg;
9703
9704 constraint ((Rd == REG_PC), BAD_PC);
9705 constraint ((Rn == REG_PC), BAD_PC);
9706 constraint ((Rm == REG_PC), BAD_PC);
9707
9708 inst.instruction |= Rd << 16;
9709 inst.instruction |= Rn << 0;
9710 inst.instruction |= Rm << 8;
9711}
9712
b99bd4ef 9713static void
c19d1205 9714do_it (void)
b99bd4ef 9715{
c19d1205 9716 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9717 process it to do the validation as if in
9718 thumb mode, just in case the code gets
9719 assembled for thumb using the unified syntax. */
9720
c19d1205 9721 inst.size = 0;
e07e6e58
NC
9722 if (unified_syntax)
9723 {
5ee91343
AV
9724 set_pred_insn_type (IT_INSN);
9725 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9726 now_pred.cc = inst.operands[0].imm;
e07e6e58 9727 }
09d92015 9728}
b99bd4ef 9729
6530b175
NC
9730/* If there is only one register in the register list,
9731 then return its register number. Otherwise return -1. */
9732static int
9733only_one_reg_in_list (int range)
9734{
9735 int i = ffs (range) - 1;
9736 return (i > 15 || range != (1 << i)) ? -1 : i;
9737}
9738
09d92015 9739static void
6530b175 9740encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9741{
c19d1205
ZW
9742 int base_reg = inst.operands[0].reg;
9743 int range = inst.operands[1].imm;
6530b175 9744 int one_reg;
ea6ef066 9745
c19d1205
ZW
9746 inst.instruction |= base_reg << 16;
9747 inst.instruction |= range;
ea6ef066 9748
c19d1205
ZW
9749 if (inst.operands[1].writeback)
9750 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9751
c19d1205 9752 if (inst.operands[0].writeback)
ea6ef066 9753 {
c19d1205
ZW
9754 inst.instruction |= WRITE_BACK;
9755 /* Check for unpredictable uses of writeback. */
9756 if (inst.instruction & LOAD_BIT)
09d92015 9757 {
c19d1205
ZW
9758 /* Not allowed in LDM type 2. */
9759 if ((inst.instruction & LDM_TYPE_2_OR_3)
9760 && ((range & (1 << REG_PC)) == 0))
9761 as_warn (_("writeback of base register is UNPREDICTABLE"));
9762 /* Only allowed if base reg not in list for other types. */
9763 else if (range & (1 << base_reg))
9764 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9765 }
9766 else /* STM. */
9767 {
9768 /* Not allowed for type 2. */
9769 if (inst.instruction & LDM_TYPE_2_OR_3)
9770 as_warn (_("writeback of base register is UNPREDICTABLE"));
9771 /* Only allowed if base reg not in list, or first in list. */
9772 else if ((range & (1 << base_reg))
9773 && (range & ((1 << base_reg) - 1)))
9774 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9775 }
ea6ef066 9776 }
6530b175
NC
9777
9778 /* If PUSH/POP has only one register, then use the A2 encoding. */
9779 one_reg = only_one_reg_in_list (range);
9780 if (from_push_pop_mnem && one_reg >= 0)
9781 {
9782 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9783
4f588891
NC
9784 if (is_push && one_reg == 13 /* SP */)
9785 /* PR 22483: The A2 encoding cannot be used when
9786 pushing the stack pointer as this is UNPREDICTABLE. */
9787 return;
9788
6530b175
NC
9789 inst.instruction &= A_COND_MASK;
9790 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9791 inst.instruction |= one_reg << 12;
9792 }
9793}
9794
9795static void
9796do_ldmstm (void)
9797{
9798 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9799}
9800
c19d1205
ZW
9801/* ARMv5TE load-consecutive (argument parse)
9802 Mode is like LDRH.
9803
9804 LDRccD R, mode
9805 STRccD R, mode. */
9806
a737bd4d 9807static void
c19d1205 9808do_ldrd (void)
a737bd4d 9809{
c19d1205 9810 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9811 _("first transfer register must be even"));
c19d1205
ZW
9812 constraint (inst.operands[1].present
9813 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9814 _("can only transfer two consecutive registers"));
c19d1205
ZW
9815 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9816 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9817
c19d1205
ZW
9818 if (!inst.operands[1].present)
9819 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9820
c56791bb
RE
9821 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9822 register and the first register written; we have to diagnose
9823 overlap between the base and the second register written here. */
ea6ef066 9824
c56791bb
RE
9825 if (inst.operands[2].reg == inst.operands[1].reg
9826 && (inst.operands[2].writeback || inst.operands[2].postind))
9827 as_warn (_("base register written back, and overlaps "
9828 "second transfer register"));
b05fe5cf 9829
c56791bb
RE
9830 if (!(inst.instruction & V4_STR_BIT))
9831 {
c19d1205 9832 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9833 destination (even if not write-back). */
9834 if (inst.operands[2].immisreg
9835 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9836 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9837 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9838 }
c19d1205
ZW
9839 inst.instruction |= inst.operands[0].reg << 12;
9840 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9841}
9842
9843static void
c19d1205 9844do_ldrex (void)
b05fe5cf 9845{
c19d1205
ZW
9846 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9847 || inst.operands[1].postind || inst.operands[1].writeback
9848 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9849 || inst.operands[1].negative
9850 /* This can arise if the programmer has written
9851 strex rN, rM, foo
9852 or if they have mistakenly used a register name as the last
9853 operand, eg:
9854 strex rN, rM, rX
9855 It is very difficult to distinguish between these two cases
9856 because "rX" might actually be a label. ie the register
9857 name has been occluded by a symbol of the same name. So we
9858 just generate a general 'bad addressing mode' type error
9859 message and leave it up to the programmer to discover the
9860 true cause and fix their mistake. */
9861 || (inst.operands[1].reg == REG_PC),
9862 BAD_ADDR_MODE);
b05fe5cf 9863
e2b0ab59
AV
9864 constraint (inst.relocs[0].exp.X_op != O_constant
9865 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9866 _("offset must be zero in ARM encoding"));
b05fe5cf 9867
5be8be5d
DG
9868 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9869
c19d1205
ZW
9870 inst.instruction |= inst.operands[0].reg << 12;
9871 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9872 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9873}
9874
9875static void
c19d1205 9876do_ldrexd (void)
b05fe5cf 9877{
c19d1205
ZW
9878 constraint (inst.operands[0].reg % 2 != 0,
9879 _("even register required"));
9880 constraint (inst.operands[1].present
9881 && inst.operands[1].reg != inst.operands[0].reg + 1,
9882 _("can only load two consecutive registers"));
9883 /* If op 1 were present and equal to PC, this function wouldn't
9884 have been called in the first place. */
9885 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9886
c19d1205
ZW
9887 inst.instruction |= inst.operands[0].reg << 12;
9888 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9889}
9890
1be5fd2e
NC
9891/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9892 which is not a multiple of four is UNPREDICTABLE. */
9893static void
9894check_ldr_r15_aligned (void)
9895{
9896 constraint (!(inst.operands[1].immisreg)
9897 && (inst.operands[0].reg == REG_PC
9898 && inst.operands[1].reg == REG_PC
e2b0ab59 9899 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9900 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9901}
9902
b05fe5cf 9903static void
c19d1205 9904do_ldst (void)
b05fe5cf 9905{
c19d1205
ZW
9906 inst.instruction |= inst.operands[0].reg << 12;
9907 if (!inst.operands[1].isreg)
8335d6aa 9908 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9909 return;
c19d1205 9910 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9911 check_ldr_r15_aligned ();
b05fe5cf
ZW
9912}
9913
9914static void
c19d1205 9915do_ldstt (void)
b05fe5cf 9916{
c19d1205
ZW
9917 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9918 reject [Rn,...]. */
9919 if (inst.operands[1].preind)
b05fe5cf 9920 {
e2b0ab59
AV
9921 constraint (inst.relocs[0].exp.X_op != O_constant
9922 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9923 _("this instruction requires a post-indexed address"));
b05fe5cf 9924
c19d1205
ZW
9925 inst.operands[1].preind = 0;
9926 inst.operands[1].postind = 1;
9927 inst.operands[1].writeback = 1;
b05fe5cf 9928 }
c19d1205
ZW
9929 inst.instruction |= inst.operands[0].reg << 12;
9930 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9931}
b05fe5cf 9932
c19d1205 9933/* Halfword and signed-byte load/store operations. */
b05fe5cf 9934
c19d1205
ZW
9935static void
9936do_ldstv4 (void)
9937{
ff4a8d2b 9938 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9939 inst.instruction |= inst.operands[0].reg << 12;
9940 if (!inst.operands[1].isreg)
8335d6aa 9941 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9942 return;
c19d1205 9943 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9944}
9945
9946static void
c19d1205 9947do_ldsttv4 (void)
b05fe5cf 9948{
c19d1205
ZW
9949 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9950 reject [Rn,...]. */
9951 if (inst.operands[1].preind)
b05fe5cf 9952 {
e2b0ab59
AV
9953 constraint (inst.relocs[0].exp.X_op != O_constant
9954 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9955 _("this instruction requires a post-indexed address"));
b05fe5cf 9956
c19d1205
ZW
9957 inst.operands[1].preind = 0;
9958 inst.operands[1].postind = 1;
9959 inst.operands[1].writeback = 1;
b05fe5cf 9960 }
c19d1205
ZW
9961 inst.instruction |= inst.operands[0].reg << 12;
9962 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9963}
b05fe5cf 9964
c19d1205
ZW
9965/* Co-processor register load/store.
9966 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9967static void
9968do_lstc (void)
9969{
9970 inst.instruction |= inst.operands[0].reg << 8;
9971 inst.instruction |= inst.operands[1].reg << 12;
9972 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9973}
9974
b05fe5cf 9975static void
c19d1205 9976do_mlas (void)
b05fe5cf 9977{
8fb9d7b9 9978 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9979 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9980 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9981 && !(inst.instruction & 0x00400000))
8fb9d7b9 9982 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9983
c19d1205
ZW
9984 inst.instruction |= inst.operands[0].reg << 16;
9985 inst.instruction |= inst.operands[1].reg;
9986 inst.instruction |= inst.operands[2].reg << 8;
9987 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9988}
b05fe5cf 9989
c19d1205
ZW
9990static void
9991do_mov (void)
9992{
e2b0ab59
AV
9993 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9994 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9995 THUMB1_RELOC_ONLY);
c19d1205
ZW
9996 inst.instruction |= inst.operands[0].reg << 12;
9997 encode_arm_shifter_operand (1);
9998}
b05fe5cf 9999
c19d1205
ZW
10000/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10001static void
10002do_mov16 (void)
10003{
b6895b4f
PB
10004 bfd_vma imm;
10005 bfd_boolean top;
10006
10007 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 10008 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 10009 _(":lower16: not allowed in this instruction"));
e2b0ab59 10010 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 10011 _(":upper16: not allowed in this instruction"));
c19d1205 10012 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 10013 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 10014 {
e2b0ab59 10015 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
10016 /* The value is in two pieces: 0:11, 16:19. */
10017 inst.instruction |= (imm & 0x00000fff);
10018 inst.instruction |= (imm & 0x0000f000) << 4;
10019 }
b05fe5cf 10020}
b99bd4ef 10021
037e8744
JB
10022static int
10023do_vfp_nsyn_mrs (void)
10024{
10025 if (inst.operands[0].isvec)
10026 {
10027 if (inst.operands[1].reg != 1)
477330fc 10028 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
10029 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10030 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10031 do_vfp_nsyn_opcode ("fmstat");
10032 }
10033 else if (inst.operands[1].isvec)
10034 do_vfp_nsyn_opcode ("fmrx");
10035 else
10036 return FAIL;
5f4273c7 10037
037e8744
JB
10038 return SUCCESS;
10039}
10040
10041static int
10042do_vfp_nsyn_msr (void)
10043{
10044 if (inst.operands[0].isvec)
10045 do_vfp_nsyn_opcode ("fmxr");
10046 else
10047 return FAIL;
10048
10049 return SUCCESS;
10050}
10051
f7c21dc7
NC
10052static void
10053do_vmrs (void)
10054{
10055 unsigned Rt = inst.operands[0].reg;
fa94de6b 10056
16d02dc9 10057 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
10058 {
10059 inst.error = BAD_SP;
10060 return;
10061 }
10062
ba6cd17f
SD
10063 switch (inst.operands[1].reg)
10064 {
10065 /* MVFR2 is only valid for Armv8-A. */
10066 case 5:
10067 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10068 _(BAD_FPU));
10069 break;
10070
10071 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10072 case 1: /* fpscr. */
10073 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10074 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10075 _(BAD_FPU));
10076 break;
10077
10078 case 14: /* fpcxt_ns. */
10079 case 15: /* fpcxt_s. */
10080 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10081 _("selected processor does not support instruction"));
10082 break;
10083
10084 case 2: /* fpscr_nzcvqc. */
10085 case 12: /* vpr. */
10086 case 13: /* p0. */
10087 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10088 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10089 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10090 _("selected processor does not support instruction"));
10091 if (inst.operands[0].reg != 2
10092 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10093 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10094 break;
10095
10096 default:
10097 break;
10098 }
40c7d507 10099
f7c21dc7 10100 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 10101 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
10102 {
10103 inst.error = BAD_PC;
10104 return;
10105 }
10106
16d02dc9
JB
10107 /* If we get through parsing the register name, we just insert the number
10108 generated into the instruction without further validation. */
10109 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
10110 inst.instruction |= (Rt << 12);
10111}
10112
10113static void
10114do_vmsr (void)
10115{
10116 unsigned Rt = inst.operands[1].reg;
fa94de6b 10117
f7c21dc7
NC
10118 if (thumb_mode)
10119 reject_bad_reg (Rt);
10120 else if (Rt == REG_PC)
10121 {
10122 inst.error = BAD_PC;
10123 return;
10124 }
10125
ba6cd17f
SD
10126 switch (inst.operands[0].reg)
10127 {
10128 /* MVFR2 is only valid for Armv8-A. */
10129 case 5:
10130 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10131 _(BAD_FPU));
10132 break;
10133
10134 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10135 case 1: /* fpcr. */
10136 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10137 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10138 _(BAD_FPU));
10139 break;
10140
10141 case 14: /* fpcxt_ns. */
10142 case 15: /* fpcxt_s. */
10143 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10144 _("selected processor does not support instruction"));
10145 break;
10146
10147 case 2: /* fpscr_nzcvqc. */
10148 case 12: /* vpr. */
10149 case 13: /* p0. */
10150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10151 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10152 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10153 _("selected processor does not support instruction"));
10154 if (inst.operands[0].reg != 2
10155 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10156 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10157 break;
10158
10159 default:
10160 break;
10161 }
40c7d507 10162
16d02dc9
JB
10163 /* If we get through parsing the register name, we just insert the number
10164 generated into the instruction without further validation. */
10165 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10166 inst.instruction |= (Rt << 12);
10167}
10168
b99bd4ef 10169static void
c19d1205 10170do_mrs (void)
b99bd4ef 10171{
90ec0d68
MGD
10172 unsigned br;
10173
037e8744
JB
10174 if (do_vfp_nsyn_mrs () == SUCCESS)
10175 return;
10176
ff4a8d2b 10177 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10178 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10179
10180 if (inst.operands[1].isreg)
10181 {
10182 br = inst.operands[1].reg;
806ab1c0 10183 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10184 as_bad (_("bad register for mrs"));
10185 }
10186 else
10187 {
10188 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10189 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10190 != (PSR_c|PSR_f),
d2cd1205 10191 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10192 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10193 }
10194
10195 inst.instruction |= br;
c19d1205 10196}
b99bd4ef 10197
c19d1205
ZW
10198/* Two possible forms:
10199 "{C|S}PSR_<field>, Rm",
10200 "{C|S}PSR_f, #expression". */
b99bd4ef 10201
c19d1205
ZW
10202static void
10203do_msr (void)
10204{
037e8744
JB
10205 if (do_vfp_nsyn_msr () == SUCCESS)
10206 return;
10207
c19d1205
ZW
10208 inst.instruction |= inst.operands[0].imm;
10209 if (inst.operands[1].isreg)
10210 inst.instruction |= inst.operands[1].reg;
10211 else
b99bd4ef 10212 {
c19d1205 10213 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10214 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10215 inst.relocs[0].pc_rel = 0;
b99bd4ef 10216 }
b99bd4ef
NC
10217}
10218
c19d1205
ZW
10219static void
10220do_mul (void)
a737bd4d 10221{
ff4a8d2b
NC
10222 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10223
c19d1205
ZW
10224 if (!inst.operands[2].present)
10225 inst.operands[2].reg = inst.operands[0].reg;
10226 inst.instruction |= inst.operands[0].reg << 16;
10227 inst.instruction |= inst.operands[1].reg;
10228 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10229
8fb9d7b9
MS
10230 if (inst.operands[0].reg == inst.operands[1].reg
10231 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10232 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10233}
10234
c19d1205
ZW
10235/* Long Multiply Parser
10236 UMULL RdLo, RdHi, Rm, Rs
10237 SMULL RdLo, RdHi, Rm, Rs
10238 UMLAL RdLo, RdHi, Rm, Rs
10239 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10240
10241static void
c19d1205 10242do_mull (void)
b99bd4ef 10243{
c19d1205
ZW
10244 inst.instruction |= inst.operands[0].reg << 12;
10245 inst.instruction |= inst.operands[1].reg << 16;
10246 inst.instruction |= inst.operands[2].reg;
10247 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10248
682b27ad
PB
10249 /* rdhi and rdlo must be different. */
10250 if (inst.operands[0].reg == inst.operands[1].reg)
10251 as_tsktsk (_("rdhi and rdlo must be different"));
10252
10253 /* rdhi, rdlo and rm must all be different before armv6. */
10254 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10255 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10256 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10257 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10258}
b99bd4ef 10259
c19d1205
ZW
10260static void
10261do_nop (void)
10262{
e7495e45
NS
10263 if (inst.operands[0].present
10264 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10265 {
10266 /* Architectural NOP hints are CPSR sets with no bits selected. */
10267 inst.instruction &= 0xf0000000;
e7495e45
NS
10268 inst.instruction |= 0x0320f000;
10269 if (inst.operands[0].present)
10270 inst.instruction |= inst.operands[0].imm;
c19d1205 10271 }
b99bd4ef
NC
10272}
10273
c19d1205
ZW
10274/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10275 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10276 Condition defaults to COND_ALWAYS.
10277 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10278
10279static void
c19d1205 10280do_pkhbt (void)
b99bd4ef 10281{
c19d1205
ZW
10282 inst.instruction |= inst.operands[0].reg << 12;
10283 inst.instruction |= inst.operands[1].reg << 16;
10284 inst.instruction |= inst.operands[2].reg;
10285 if (inst.operands[3].present)
10286 encode_arm_shift (3);
10287}
b99bd4ef 10288
c19d1205 10289/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10290
c19d1205
ZW
10291static void
10292do_pkhtb (void)
10293{
10294 if (!inst.operands[3].present)
b99bd4ef 10295 {
c19d1205
ZW
10296 /* If the shift specifier is omitted, turn the instruction
10297 into pkhbt rd, rm, rn. */
10298 inst.instruction &= 0xfff00010;
10299 inst.instruction |= inst.operands[0].reg << 12;
10300 inst.instruction |= inst.operands[1].reg;
10301 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10302 }
10303 else
10304 {
c19d1205
ZW
10305 inst.instruction |= inst.operands[0].reg << 12;
10306 inst.instruction |= inst.operands[1].reg << 16;
10307 inst.instruction |= inst.operands[2].reg;
10308 encode_arm_shift (3);
b99bd4ef
NC
10309 }
10310}
10311
c19d1205 10312/* ARMv5TE: Preload-Cache
60e5ef9f 10313 MP Extensions: Preload for write
c19d1205 10314
60e5ef9f 10315 PLD(W) <addr_mode>
c19d1205
ZW
10316
10317 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10318
10319static void
c19d1205 10320do_pld (void)
b99bd4ef 10321{
c19d1205
ZW
10322 constraint (!inst.operands[0].isreg,
10323 _("'[' expected after PLD mnemonic"));
10324 constraint (inst.operands[0].postind,
10325 _("post-indexed expression used in preload instruction"));
10326 constraint (inst.operands[0].writeback,
10327 _("writeback used in preload instruction"));
10328 constraint (!inst.operands[0].preind,
10329 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10330 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10331}
b99bd4ef 10332
62b3e311
PB
10333/* ARMv7: PLI <addr_mode> */
10334static void
10335do_pli (void)
10336{
10337 constraint (!inst.operands[0].isreg,
10338 _("'[' expected after PLI mnemonic"));
10339 constraint (inst.operands[0].postind,
10340 _("post-indexed expression used in preload instruction"));
10341 constraint (inst.operands[0].writeback,
10342 _("writeback used in preload instruction"));
10343 constraint (!inst.operands[0].preind,
10344 _("unindexed addressing used in preload instruction"));
10345 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10346 inst.instruction &= ~PRE_INDEX;
10347}
10348
c19d1205
ZW
10349static void
10350do_push_pop (void)
10351{
5e0d7f77
MP
10352 constraint (inst.operands[0].writeback,
10353 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10354 inst.operands[1] = inst.operands[0];
10355 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10356 inst.operands[0].isreg = 1;
10357 inst.operands[0].writeback = 1;
10358 inst.operands[0].reg = REG_SP;
6530b175 10359 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10360}
b99bd4ef 10361
c19d1205
ZW
10362/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10363 word at the specified address and the following word
10364 respectively.
10365 Unconditionally executed.
10366 Error if Rn is R15. */
b99bd4ef 10367
c19d1205
ZW
10368static void
10369do_rfe (void)
10370{
10371 inst.instruction |= inst.operands[0].reg << 16;
10372 if (inst.operands[0].writeback)
10373 inst.instruction |= WRITE_BACK;
10374}
b99bd4ef 10375
c19d1205 10376/* ARM V6 ssat (argument parse). */
b99bd4ef 10377
c19d1205
ZW
10378static void
10379do_ssat (void)
10380{
10381 inst.instruction |= inst.operands[0].reg << 12;
10382 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10383 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10384
c19d1205
ZW
10385 if (inst.operands[3].present)
10386 encode_arm_shift (3);
b99bd4ef
NC
10387}
10388
c19d1205 10389/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10390
10391static void
c19d1205 10392do_usat (void)
b99bd4ef 10393{
c19d1205
ZW
10394 inst.instruction |= inst.operands[0].reg << 12;
10395 inst.instruction |= inst.operands[1].imm << 16;
10396 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10397
c19d1205
ZW
10398 if (inst.operands[3].present)
10399 encode_arm_shift (3);
b99bd4ef
NC
10400}
10401
c19d1205 10402/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10403
10404static void
c19d1205 10405do_ssat16 (void)
09d92015 10406{
c19d1205
ZW
10407 inst.instruction |= inst.operands[0].reg << 12;
10408 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10409 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10410}
10411
c19d1205
ZW
10412static void
10413do_usat16 (void)
a737bd4d 10414{
c19d1205
ZW
10415 inst.instruction |= inst.operands[0].reg << 12;
10416 inst.instruction |= inst.operands[1].imm << 16;
10417 inst.instruction |= inst.operands[2].reg;
10418}
a737bd4d 10419
c19d1205
ZW
10420/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10421 preserving the other bits.
a737bd4d 10422
c19d1205
ZW
10423 setend <endian_specifier>, where <endian_specifier> is either
10424 BE or LE. */
a737bd4d 10425
c19d1205
ZW
10426static void
10427do_setend (void)
10428{
12e37cbc
MGD
10429 if (warn_on_deprecated
10430 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10431 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10432
c19d1205
ZW
10433 if (inst.operands[0].imm)
10434 inst.instruction |= 0x200;
a737bd4d
NC
10435}
10436
10437static void
c19d1205 10438do_shift (void)
a737bd4d 10439{
c19d1205
ZW
10440 unsigned int Rm = (inst.operands[1].present
10441 ? inst.operands[1].reg
10442 : inst.operands[0].reg);
a737bd4d 10443
c19d1205
ZW
10444 inst.instruction |= inst.operands[0].reg << 12;
10445 inst.instruction |= Rm;
10446 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10447 {
c19d1205
ZW
10448 inst.instruction |= inst.operands[2].reg << 8;
10449 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10450 /* PR 12854: Error on extraneous shifts. */
10451 constraint (inst.operands[2].shifted,
10452 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10453 }
10454 else
e2b0ab59 10455 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10456}
10457
09d92015 10458static void
3eb17e6b 10459do_smc (void)
09d92015 10460{
ba85f98c
BW
10461 unsigned int value = inst.relocs[0].exp.X_add_number;
10462 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10463
e2b0ab59
AV
10464 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10465 inst.relocs[0].pc_rel = 0;
09d92015
MM
10466}
10467
90ec0d68
MGD
10468static void
10469do_hvc (void)
10470{
e2b0ab59
AV
10471 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10472 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10473}
10474
09d92015 10475static void
c19d1205 10476do_swi (void)
09d92015 10477{
e2b0ab59
AV
10478 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10479 inst.relocs[0].pc_rel = 0;
09d92015
MM
10480}
10481
ddfded2f
MW
10482static void
10483do_setpan (void)
10484{
10485 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10486 _("selected processor does not support SETPAN instruction"));
10487
10488 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10489}
10490
10491static void
10492do_t_setpan (void)
10493{
10494 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10495 _("selected processor does not support SETPAN instruction"));
10496
10497 inst.instruction |= (inst.operands[0].imm << 3);
10498}
10499
c19d1205
ZW
10500/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10501 SMLAxy{cond} Rd,Rm,Rs,Rn
10502 SMLAWy{cond} Rd,Rm,Rs,Rn
10503 Error if any register is R15. */
e16bb312 10504
c19d1205
ZW
10505static void
10506do_smla (void)
e16bb312 10507{
c19d1205
ZW
10508 inst.instruction |= inst.operands[0].reg << 16;
10509 inst.instruction |= inst.operands[1].reg;
10510 inst.instruction |= inst.operands[2].reg << 8;
10511 inst.instruction |= inst.operands[3].reg << 12;
10512}
a737bd4d 10513
c19d1205
ZW
10514/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10515 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10516 Error if any register is R15.
10517 Warning if Rdlo == Rdhi. */
a737bd4d 10518
c19d1205
ZW
10519static void
10520do_smlal (void)
10521{
10522 inst.instruction |= inst.operands[0].reg << 12;
10523 inst.instruction |= inst.operands[1].reg << 16;
10524 inst.instruction |= inst.operands[2].reg;
10525 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10526
c19d1205
ZW
10527 if (inst.operands[0].reg == inst.operands[1].reg)
10528 as_tsktsk (_("rdhi and rdlo must be different"));
10529}
a737bd4d 10530
c19d1205
ZW
10531/* ARM V5E (El Segundo) signed-multiply (argument parse)
10532 SMULxy{cond} Rd,Rm,Rs
10533 Error if any register is R15. */
a737bd4d 10534
c19d1205
ZW
10535static void
10536do_smul (void)
10537{
10538 inst.instruction |= inst.operands[0].reg << 16;
10539 inst.instruction |= inst.operands[1].reg;
10540 inst.instruction |= inst.operands[2].reg << 8;
10541}
a737bd4d 10542
b6702015
PB
10543/* ARM V6 srs (argument parse). The variable fields in the encoding are
10544 the same for both ARM and Thumb-2. */
a737bd4d 10545
c19d1205
ZW
10546static void
10547do_srs (void)
10548{
b6702015
PB
10549 int reg;
10550
10551 if (inst.operands[0].present)
10552 {
10553 reg = inst.operands[0].reg;
fdfde340 10554 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10555 }
10556 else
fdfde340 10557 reg = REG_SP;
b6702015
PB
10558
10559 inst.instruction |= reg << 16;
10560 inst.instruction |= inst.operands[1].imm;
10561 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10562 inst.instruction |= WRITE_BACK;
10563}
a737bd4d 10564
c19d1205 10565/* ARM V6 strex (argument parse). */
a737bd4d 10566
c19d1205
ZW
10567static void
10568do_strex (void)
10569{
10570 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10571 || inst.operands[2].postind || inst.operands[2].writeback
10572 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10573 || inst.operands[2].negative
10574 /* See comment in do_ldrex(). */
10575 || (inst.operands[2].reg == REG_PC),
10576 BAD_ADDR_MODE);
a737bd4d 10577
c19d1205
ZW
10578 constraint (inst.operands[0].reg == inst.operands[1].reg
10579 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10580
e2b0ab59
AV
10581 constraint (inst.relocs[0].exp.X_op != O_constant
10582 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10583 _("offset must be zero in ARM encoding"));
a737bd4d 10584
c19d1205
ZW
10585 inst.instruction |= inst.operands[0].reg << 12;
10586 inst.instruction |= inst.operands[1].reg;
10587 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10588 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10589}
10590
877807f8
NC
10591static void
10592do_t_strexbh (void)
10593{
10594 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10595 || inst.operands[2].postind || inst.operands[2].writeback
10596 || inst.operands[2].immisreg || inst.operands[2].shifted
10597 || inst.operands[2].negative,
10598 BAD_ADDR_MODE);
10599
10600 constraint (inst.operands[0].reg == inst.operands[1].reg
10601 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10602
10603 do_rm_rd_rn ();
10604}
10605
e16bb312 10606static void
c19d1205 10607do_strexd (void)
e16bb312 10608{
c19d1205
ZW
10609 constraint (inst.operands[1].reg % 2 != 0,
10610 _("even register required"));
10611 constraint (inst.operands[2].present
10612 && inst.operands[2].reg != inst.operands[1].reg + 1,
10613 _("can only store two consecutive registers"));
10614 /* If op 2 were present and equal to PC, this function wouldn't
10615 have been called in the first place. */
10616 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10617
c19d1205
ZW
10618 constraint (inst.operands[0].reg == inst.operands[1].reg
10619 || inst.operands[0].reg == inst.operands[1].reg + 1
10620 || inst.operands[0].reg == inst.operands[3].reg,
10621 BAD_OVERLAP);
e16bb312 10622
c19d1205
ZW
10623 inst.instruction |= inst.operands[0].reg << 12;
10624 inst.instruction |= inst.operands[1].reg;
10625 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10626}
10627
9eb6c0f1
MGD
10628/* ARM V8 STRL. */
10629static void
4b8c8c02 10630do_stlex (void)
9eb6c0f1
MGD
10631{
10632 constraint (inst.operands[0].reg == inst.operands[1].reg
10633 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10634
10635 do_rd_rm_rn ();
10636}
10637
10638static void
4b8c8c02 10639do_t_stlex (void)
9eb6c0f1
MGD
10640{
10641 constraint (inst.operands[0].reg == inst.operands[1].reg
10642 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10643
10644 do_rm_rd_rn ();
10645}
10646
c19d1205
ZW
10647/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10648 extends it to 32-bits, and adds the result to a value in another
10649 register. You can specify a rotation by 0, 8, 16, or 24 bits
10650 before extracting the 16-bit value.
10651 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10652 Condition defaults to COND_ALWAYS.
10653 Error if any register uses R15. */
10654
e16bb312 10655static void
c19d1205 10656do_sxtah (void)
e16bb312 10657{
c19d1205
ZW
10658 inst.instruction |= inst.operands[0].reg << 12;
10659 inst.instruction |= inst.operands[1].reg << 16;
10660 inst.instruction |= inst.operands[2].reg;
10661 inst.instruction |= inst.operands[3].imm << 10;
10662}
e16bb312 10663
c19d1205 10664/* ARM V6 SXTH.
e16bb312 10665
c19d1205
ZW
10666 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10667 Condition defaults to COND_ALWAYS.
10668 Error if any register uses R15. */
e16bb312
NC
10669
10670static void
c19d1205 10671do_sxth (void)
e16bb312 10672{
c19d1205
ZW
10673 inst.instruction |= inst.operands[0].reg << 12;
10674 inst.instruction |= inst.operands[1].reg;
10675 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10676}
c19d1205
ZW
10677\f
10678/* VFP instructions. In a logical order: SP variant first, monad
10679 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10680
10681static void
c19d1205 10682do_vfp_sp_monadic (void)
e16bb312 10683{
57785aa2
AV
10684 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10685 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10686 _(BAD_FPU));
10687
5287ad62
JB
10688 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10689 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10690}
10691
10692static void
c19d1205 10693do_vfp_sp_dyadic (void)
e16bb312 10694{
5287ad62
JB
10695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10696 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10697 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10698}
10699
10700static void
c19d1205 10701do_vfp_sp_compare_z (void)
e16bb312 10702{
5287ad62 10703 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10704}
10705
10706static void
c19d1205 10707do_vfp_dp_sp_cvt (void)
e16bb312 10708{
5287ad62
JB
10709 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10710 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10711}
10712
10713static void
c19d1205 10714do_vfp_sp_dp_cvt (void)
e16bb312 10715{
5287ad62
JB
10716 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10717 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10718}
10719
10720static void
c19d1205 10721do_vfp_reg_from_sp (void)
e16bb312 10722{
57785aa2
AV
10723 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10724 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10725 _(BAD_FPU));
10726
c19d1205 10727 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10728 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10729}
10730
10731static void
c19d1205 10732do_vfp_reg2_from_sp2 (void)
e16bb312 10733{
c19d1205
ZW
10734 constraint (inst.operands[2].imm != 2,
10735 _("only two consecutive VFP SP registers allowed here"));
10736 inst.instruction |= inst.operands[0].reg << 12;
10737 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10738 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10739}
10740
10741static void
c19d1205 10742do_vfp_sp_from_reg (void)
e16bb312 10743{
57785aa2
AV
10744 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10745 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10746 _(BAD_FPU));
10747
5287ad62 10748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10749 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10750}
10751
10752static void
c19d1205 10753do_vfp_sp2_from_reg2 (void)
e16bb312 10754{
c19d1205
ZW
10755 constraint (inst.operands[0].imm != 2,
10756 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10758 inst.instruction |= inst.operands[1].reg << 12;
10759 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10760}
10761
10762static void
c19d1205 10763do_vfp_sp_ldst (void)
e16bb312 10764{
5287ad62 10765 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10766 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10767}
10768
10769static void
c19d1205 10770do_vfp_dp_ldst (void)
e16bb312 10771{
5287ad62 10772 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10773 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10774}
10775
c19d1205 10776
e16bb312 10777static void
c19d1205 10778vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10779{
c19d1205
ZW
10780 if (inst.operands[0].writeback)
10781 inst.instruction |= WRITE_BACK;
10782 else
10783 constraint (ldstm_type != VFP_LDSTMIA,
10784 _("this addressing mode requires base-register writeback"));
10785 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10786 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10787 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10788}
10789
10790static void
c19d1205 10791vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10792{
c19d1205 10793 int count;
e16bb312 10794
c19d1205
ZW
10795 if (inst.operands[0].writeback)
10796 inst.instruction |= WRITE_BACK;
10797 else
10798 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10799 _("this addressing mode requires base-register writeback"));
e16bb312 10800
c19d1205 10801 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10802 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10803
c19d1205
ZW
10804 count = inst.operands[1].imm << 1;
10805 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10806 count += 1;
e16bb312 10807
c19d1205 10808 inst.instruction |= count;
e16bb312
NC
10809}
10810
10811static void
c19d1205 10812do_vfp_sp_ldstmia (void)
e16bb312 10813{
c19d1205 10814 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10815}
10816
10817static void
c19d1205 10818do_vfp_sp_ldstmdb (void)
e16bb312 10819{
c19d1205 10820 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10821}
10822
10823static void
c19d1205 10824do_vfp_dp_ldstmia (void)
e16bb312 10825{
c19d1205 10826 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10827}
10828
10829static void
c19d1205 10830do_vfp_dp_ldstmdb (void)
e16bb312 10831{
c19d1205 10832 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10833}
10834
10835static void
c19d1205 10836do_vfp_xp_ldstmia (void)
e16bb312 10837{
c19d1205
ZW
10838 vfp_dp_ldstm (VFP_LDSTMIAX);
10839}
e16bb312 10840
c19d1205
ZW
10841static void
10842do_vfp_xp_ldstmdb (void)
10843{
10844 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10845}
5287ad62
JB
10846
10847static void
10848do_vfp_dp_rd_rm (void)
10849{
57785aa2
AV
10850 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10851 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10852 _(BAD_FPU));
10853
5287ad62
JB
10854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10855 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10856}
10857
10858static void
10859do_vfp_dp_rn_rd (void)
10860{
10861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10863}
10864
10865static void
10866do_vfp_dp_rd_rn (void)
10867{
10868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10870}
10871
10872static void
10873do_vfp_dp_rd_rn_rm (void)
10874{
57785aa2
AV
10875 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10876 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10877 _(BAD_FPU));
10878
5287ad62
JB
10879 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10880 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10881 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10882}
10883
10884static void
10885do_vfp_dp_rd (void)
10886{
10887 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10888}
10889
10890static void
10891do_vfp_dp_rm_rd_rn (void)
10892{
57785aa2
AV
10893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10894 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10895 _(BAD_FPU));
10896
5287ad62
JB
10897 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10898 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10899 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10900}
10901
10902/* VFPv3 instructions. */
10903static void
10904do_vfp_sp_const (void)
10905{
10906 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10907 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10908 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10909}
10910
10911static void
10912do_vfp_dp_const (void)
10913{
10914 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10915 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10916 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10917}
10918
10919static void
10920vfp_conv (int srcsize)
10921{
5f1af56b
MGD
10922 int immbits = srcsize - inst.operands[1].imm;
10923
fa94de6b
RM
10924 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10925 {
5f1af56b 10926 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10927 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10928 inst.error = _("immediate value out of range, expected range [0, 16]");
10929 return;
10930 }
fa94de6b 10931 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10932 {
10933 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10934 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10935 inst.error = _("immediate value out of range, expected range [1, 32]");
10936 return;
10937 }
10938
5287ad62
JB
10939 inst.instruction |= (immbits & 1) << 5;
10940 inst.instruction |= (immbits >> 1);
10941}
10942
10943static void
10944do_vfp_sp_conv_16 (void)
10945{
10946 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10947 vfp_conv (16);
10948}
10949
10950static void
10951do_vfp_dp_conv_16 (void)
10952{
10953 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10954 vfp_conv (16);
10955}
10956
10957static void
10958do_vfp_sp_conv_32 (void)
10959{
10960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10961 vfp_conv (32);
10962}
10963
10964static void
10965do_vfp_dp_conv_32 (void)
10966{
10967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10968 vfp_conv (32);
10969}
c19d1205
ZW
10970\f
10971/* FPA instructions. Also in a logical order. */
e16bb312 10972
c19d1205
ZW
10973static void
10974do_fpa_cmp (void)
10975{
10976 inst.instruction |= inst.operands[0].reg << 16;
10977 inst.instruction |= inst.operands[1].reg;
10978}
b99bd4ef
NC
10979
10980static void
c19d1205 10981do_fpa_ldmstm (void)
b99bd4ef 10982{
c19d1205
ZW
10983 inst.instruction |= inst.operands[0].reg << 12;
10984 switch (inst.operands[1].imm)
10985 {
10986 case 1: inst.instruction |= CP_T_X; break;
10987 case 2: inst.instruction |= CP_T_Y; break;
10988 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10989 case 4: break;
10990 default: abort ();
10991 }
b99bd4ef 10992
c19d1205
ZW
10993 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10994 {
10995 /* The instruction specified "ea" or "fd", so we can only accept
10996 [Rn]{!}. The instruction does not really support stacking or
10997 unstacking, so we have to emulate these by setting appropriate
10998 bits and offsets. */
e2b0ab59
AV
10999 constraint (inst.relocs[0].exp.X_op != O_constant
11000 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 11001 _("this instruction does not support indexing"));
b99bd4ef 11002
c19d1205 11003 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 11004 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 11005
c19d1205 11006 if (!(inst.instruction & INDEX_UP))
e2b0ab59 11007 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 11008
c19d1205
ZW
11009 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11010 {
11011 inst.operands[2].preind = 0;
11012 inst.operands[2].postind = 1;
11013 }
11014 }
b99bd4ef 11015
c19d1205 11016 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 11017}
c19d1205
ZW
11018\f
11019/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 11020
c19d1205
ZW
11021static void
11022do_iwmmxt_tandorc (void)
11023{
11024 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11025}
b99bd4ef 11026
c19d1205
ZW
11027static void
11028do_iwmmxt_textrc (void)
11029{
11030 inst.instruction |= inst.operands[0].reg << 12;
11031 inst.instruction |= inst.operands[1].imm;
11032}
b99bd4ef
NC
11033
11034static void
c19d1205 11035do_iwmmxt_textrm (void)
b99bd4ef 11036{
c19d1205
ZW
11037 inst.instruction |= inst.operands[0].reg << 12;
11038 inst.instruction |= inst.operands[1].reg << 16;
11039 inst.instruction |= inst.operands[2].imm;
11040}
b99bd4ef 11041
c19d1205
ZW
11042static void
11043do_iwmmxt_tinsr (void)
11044{
11045 inst.instruction |= inst.operands[0].reg << 16;
11046 inst.instruction |= inst.operands[1].reg << 12;
11047 inst.instruction |= inst.operands[2].imm;
11048}
b99bd4ef 11049
c19d1205
ZW
11050static void
11051do_iwmmxt_tmia (void)
11052{
11053 inst.instruction |= inst.operands[0].reg << 5;
11054 inst.instruction |= inst.operands[1].reg;
11055 inst.instruction |= inst.operands[2].reg << 12;
11056}
b99bd4ef 11057
c19d1205
ZW
11058static void
11059do_iwmmxt_waligni (void)
11060{
11061 inst.instruction |= inst.operands[0].reg << 12;
11062 inst.instruction |= inst.operands[1].reg << 16;
11063 inst.instruction |= inst.operands[2].reg;
11064 inst.instruction |= inst.operands[3].imm << 20;
11065}
b99bd4ef 11066
2d447fca
JM
11067static void
11068do_iwmmxt_wmerge (void)
11069{
11070 inst.instruction |= inst.operands[0].reg << 12;
11071 inst.instruction |= inst.operands[1].reg << 16;
11072 inst.instruction |= inst.operands[2].reg;
11073 inst.instruction |= inst.operands[3].imm << 21;
11074}
11075
c19d1205
ZW
11076static void
11077do_iwmmxt_wmov (void)
11078{
11079 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11080 inst.instruction |= inst.operands[0].reg << 12;
11081 inst.instruction |= inst.operands[1].reg << 16;
11082 inst.instruction |= inst.operands[1].reg;
11083}
b99bd4ef 11084
c19d1205
ZW
11085static void
11086do_iwmmxt_wldstbh (void)
11087{
8f06b2d8 11088 int reloc;
c19d1205 11089 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
11090 if (thumb_mode)
11091 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11092 else
11093 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11094 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
11095}
11096
c19d1205
ZW
11097static void
11098do_iwmmxt_wldstw (void)
11099{
11100 /* RIWR_RIWC clears .isreg for a control register. */
11101 if (!inst.operands[0].isreg)
11102 {
11103 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11104 inst.instruction |= 0xf0000000;
11105 }
b99bd4ef 11106
c19d1205
ZW
11107 inst.instruction |= inst.operands[0].reg << 12;
11108 encode_arm_cp_address (1, TRUE, TRUE, 0);
11109}
b99bd4ef
NC
11110
11111static void
c19d1205 11112do_iwmmxt_wldstd (void)
b99bd4ef 11113{
c19d1205 11114 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
11115 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11116 && inst.operands[1].immisreg)
11117 {
11118 inst.instruction &= ~0x1a000ff;
eff0bc54 11119 inst.instruction |= (0xfU << 28);
2d447fca
JM
11120 if (inst.operands[1].preind)
11121 inst.instruction |= PRE_INDEX;
11122 if (!inst.operands[1].negative)
11123 inst.instruction |= INDEX_UP;
11124 if (inst.operands[1].writeback)
11125 inst.instruction |= WRITE_BACK;
11126 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11127 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
11128 inst.instruction |= inst.operands[1].imm;
11129 }
11130 else
11131 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 11132}
b99bd4ef 11133
c19d1205
ZW
11134static void
11135do_iwmmxt_wshufh (void)
11136{
11137 inst.instruction |= inst.operands[0].reg << 12;
11138 inst.instruction |= inst.operands[1].reg << 16;
11139 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11140 inst.instruction |= (inst.operands[2].imm & 0x0f);
11141}
b99bd4ef 11142
c19d1205
ZW
11143static void
11144do_iwmmxt_wzero (void)
11145{
11146 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11147 inst.instruction |= inst.operands[0].reg;
11148 inst.instruction |= inst.operands[0].reg << 12;
11149 inst.instruction |= inst.operands[0].reg << 16;
11150}
2d447fca
JM
11151
11152static void
11153do_iwmmxt_wrwrwr_or_imm5 (void)
11154{
11155 if (inst.operands[2].isreg)
11156 do_rd_rn_rm ();
11157 else {
11158 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11159 _("immediate operand requires iWMMXt2"));
11160 do_rd_rn ();
11161 if (inst.operands[2].imm == 0)
11162 {
11163 switch ((inst.instruction >> 20) & 0xf)
11164 {
11165 case 4:
11166 case 5:
11167 case 6:
5f4273c7 11168 case 7:
2d447fca
JM
11169 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11170 inst.operands[2].imm = 16;
11171 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11172 break;
11173 case 8:
11174 case 9:
11175 case 10:
11176 case 11:
11177 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11178 inst.operands[2].imm = 32;
11179 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11180 break;
11181 case 12:
11182 case 13:
11183 case 14:
11184 case 15:
11185 {
11186 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11187 unsigned long wrn;
11188 wrn = (inst.instruction >> 16) & 0xf;
11189 inst.instruction &= 0xff0fff0f;
11190 inst.instruction |= wrn;
11191 /* Bail out here; the instruction is now assembled. */
11192 return;
11193 }
11194 }
11195 }
11196 /* Map 32 -> 0, etc. */
11197 inst.operands[2].imm &= 0x1f;
eff0bc54 11198 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11199 }
11200}
c19d1205
ZW
11201\f
11202/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11203 operations first, then control, shift, and load/store. */
b99bd4ef 11204
c19d1205 11205/* Insns like "foo X,Y,Z". */
b99bd4ef 11206
c19d1205
ZW
11207static void
11208do_mav_triple (void)
11209{
11210 inst.instruction |= inst.operands[0].reg << 16;
11211 inst.instruction |= inst.operands[1].reg;
11212 inst.instruction |= inst.operands[2].reg << 12;
11213}
b99bd4ef 11214
c19d1205
ZW
11215/* Insns like "foo W,X,Y,Z".
11216 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11217
c19d1205
ZW
11218static void
11219do_mav_quad (void)
11220{
11221 inst.instruction |= inst.operands[0].reg << 5;
11222 inst.instruction |= inst.operands[1].reg << 12;
11223 inst.instruction |= inst.operands[2].reg << 16;
11224 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11225}
11226
c19d1205
ZW
11227/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11228static void
11229do_mav_dspsc (void)
a737bd4d 11230{
c19d1205
ZW
11231 inst.instruction |= inst.operands[1].reg << 12;
11232}
a737bd4d 11233
c19d1205
ZW
11234/* Maverick shift immediate instructions.
11235 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11236 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11237
c19d1205
ZW
11238static void
11239do_mav_shift (void)
11240{
11241 int imm = inst.operands[2].imm;
a737bd4d 11242
c19d1205
ZW
11243 inst.instruction |= inst.operands[0].reg << 12;
11244 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11245
c19d1205
ZW
11246 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11247 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11248 Bit 4 should be 0. */
11249 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11250
c19d1205
ZW
11251 inst.instruction |= imm;
11252}
11253\f
11254/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11255
c19d1205
ZW
11256/* Xscale multiply-accumulate (argument parse)
11257 MIAcc acc0,Rm,Rs
11258 MIAPHcc acc0,Rm,Rs
11259 MIAxycc acc0,Rm,Rs. */
a737bd4d 11260
c19d1205
ZW
11261static void
11262do_xsc_mia (void)
11263{
11264 inst.instruction |= inst.operands[1].reg;
11265 inst.instruction |= inst.operands[2].reg << 12;
11266}
a737bd4d 11267
c19d1205 11268/* Xscale move-accumulator-register (argument parse)
a737bd4d 11269
c19d1205 11270 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11271
c19d1205
ZW
11272static void
11273do_xsc_mar (void)
11274{
11275 inst.instruction |= inst.operands[1].reg << 12;
11276 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11277}
11278
c19d1205 11279/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11280
c19d1205 11281 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11282
11283static void
c19d1205 11284do_xsc_mra (void)
b99bd4ef 11285{
c19d1205
ZW
11286 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11287 inst.instruction |= inst.operands[0].reg << 12;
11288 inst.instruction |= inst.operands[1].reg << 16;
11289}
11290\f
11291/* Encoding functions relevant only to Thumb. */
b99bd4ef 11292
c19d1205
ZW
11293/* inst.operands[i] is a shifted-register operand; encode
11294 it into inst.instruction in the format used by Thumb32. */
11295
11296static void
11297encode_thumb32_shifted_operand (int i)
11298{
e2b0ab59 11299 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11300 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11301
9c3c69f2
PB
11302 constraint (inst.operands[i].immisreg,
11303 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11304 inst.instruction |= inst.operands[i].reg;
11305 if (shift == SHIFT_RRX)
11306 inst.instruction |= SHIFT_ROR << 4;
11307 else
b99bd4ef 11308 {
e2b0ab59 11309 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11310 _("expression too complex"));
11311
11312 constraint (value > 32
11313 || (value == 32 && (shift == SHIFT_LSL
11314 || shift == SHIFT_ROR)),
11315 _("shift expression is too large"));
11316
11317 if (value == 0)
11318 shift = SHIFT_LSL;
11319 else if (value == 32)
11320 value = 0;
11321
11322 inst.instruction |= shift << 4;
11323 inst.instruction |= (value & 0x1c) << 10;
11324 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11325 }
c19d1205 11326}
b99bd4ef 11327
b99bd4ef 11328
c19d1205
ZW
11329/* inst.operands[i] was set up by parse_address. Encode it into a
11330 Thumb32 format load or store instruction. Reject forms that cannot
11331 be used with such instructions. If is_t is true, reject forms that
11332 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11333 that cannot be used with a D instruction. If it is a store insn,
11334 reject PC in Rn. */
b99bd4ef 11335
c19d1205
ZW
11336static void
11337encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11338{
5be8be5d 11339 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11340
11341 constraint (!inst.operands[i].isreg,
53365c0d 11342 _("Instruction does not support =N addresses"));
b99bd4ef 11343
c19d1205
ZW
11344 inst.instruction |= inst.operands[i].reg << 16;
11345 if (inst.operands[i].immisreg)
b99bd4ef 11346 {
5be8be5d 11347 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11348 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11349 constraint (inst.operands[i].negative,
11350 _("Thumb does not support negative register indexing"));
11351 constraint (inst.operands[i].postind,
11352 _("Thumb does not support register post-indexing"));
11353 constraint (inst.operands[i].writeback,
11354 _("Thumb does not support register indexing with writeback"));
11355 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11356 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11357
f40d1643 11358 inst.instruction |= inst.operands[i].imm;
c19d1205 11359 if (inst.operands[i].shifted)
b99bd4ef 11360 {
e2b0ab59 11361 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11362 _("expression too complex"));
e2b0ab59
AV
11363 constraint (inst.relocs[0].exp.X_add_number < 0
11364 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11365 _("shift out of range"));
e2b0ab59 11366 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11367 }
e2b0ab59 11368 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11369 }
11370 else if (inst.operands[i].preind)
11371 {
5be8be5d 11372 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11373 constraint (is_t && inst.operands[i].writeback,
c19d1205 11374 _("cannot use writeback with this instruction"));
4755303e
WN
11375 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11376 BAD_PC_ADDRESSING);
c19d1205
ZW
11377
11378 if (is_d)
11379 {
11380 inst.instruction |= 0x01000000;
11381 if (inst.operands[i].writeback)
11382 inst.instruction |= 0x00200000;
b99bd4ef 11383 }
c19d1205 11384 else
b99bd4ef 11385 {
c19d1205
ZW
11386 inst.instruction |= 0x00000c00;
11387 if (inst.operands[i].writeback)
11388 inst.instruction |= 0x00000100;
b99bd4ef 11389 }
e2b0ab59 11390 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11391 }
c19d1205 11392 else if (inst.operands[i].postind)
b99bd4ef 11393 {
9c2799c2 11394 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11395 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11396 constraint (is_t, _("cannot use post-indexing with this instruction"));
11397
11398 if (is_d)
11399 inst.instruction |= 0x00200000;
11400 else
11401 inst.instruction |= 0x00000900;
e2b0ab59 11402 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11403 }
11404 else /* unindexed - only for coprocessor */
11405 inst.error = _("instruction does not accept unindexed addressing");
11406}
11407
e39c1607 11408/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11409 encodings (the latter only in post-V6T2 cores). The index is the
11410 value used in the insns table below. When there is more than one
11411 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11412 holds variant (1).
11413 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11414#define T16_32_TAB \
21d799b5
NC
11415 X(_adc, 4140, eb400000), \
11416 X(_adcs, 4140, eb500000), \
11417 X(_add, 1c00, eb000000), \
11418 X(_adds, 1c00, eb100000), \
11419 X(_addi, 0000, f1000000), \
11420 X(_addis, 0000, f1100000), \
11421 X(_add_pc,000f, f20f0000), \
11422 X(_add_sp,000d, f10d0000), \
11423 X(_adr, 000f, f20f0000), \
11424 X(_and, 4000, ea000000), \
11425 X(_ands, 4000, ea100000), \
11426 X(_asr, 1000, fa40f000), \
11427 X(_asrs, 1000, fa50f000), \
11428 X(_b, e000, f000b000), \
11429 X(_bcond, d000, f0008000), \
4389b29a 11430 X(_bf, 0000, f040e001), \
f6b2b12d 11431 X(_bfcsel,0000, f000e001), \
f1c7f421 11432 X(_bfx, 0000, f060e001), \
65d1bc05 11433 X(_bfl, 0000, f000c001), \
f1c7f421 11434 X(_bflx, 0000, f070e001), \
21d799b5
NC
11435 X(_bic, 4380, ea200000), \
11436 X(_bics, 4380, ea300000), \
e39c1607
SD
11437 X(_cinc, 0000, ea509000), \
11438 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11439 X(_cmn, 42c0, eb100f00), \
11440 X(_cmp, 2800, ebb00f00), \
e39c1607 11441 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11442 X(_cpsie, b660, f3af8400), \
11443 X(_cpsid, b670, f3af8600), \
11444 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11445 X(_csel, 0000, ea508000), \
11446 X(_cset, 0000, ea5f900f), \
11447 X(_csetm, 0000, ea5fa00f), \
11448 X(_csinc, 0000, ea509000), \
11449 X(_csinv, 0000, ea50a000), \
11450 X(_csneg, 0000, ea50b000), \
21d799b5 11451 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11452 X(_dls, 0000, f040e001), \
1f6234a3 11453 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11454 X(_eor, 4040, ea800000), \
11455 X(_eors, 4040, ea900000), \
11456 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11457 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11458 X(_ldmia, c800, e8900000), \
11459 X(_ldr, 6800, f8500000), \
11460 X(_ldrb, 7800, f8100000), \
11461 X(_ldrh, 8800, f8300000), \
11462 X(_ldrsb, 5600, f9100000), \
11463 X(_ldrsh, 5e00, f9300000), \
11464 X(_ldr_pc,4800, f85f0000), \
11465 X(_ldr_pc2,4800, f85f0000), \
11466 X(_ldr_sp,9800, f85d0000), \
60f993ce 11467 X(_le, 0000, f00fc001), \
1f6234a3 11468 X(_letp, 0000, f01fc001), \
21d799b5
NC
11469 X(_lsl, 0000, fa00f000), \
11470 X(_lsls, 0000, fa10f000), \
11471 X(_lsr, 0800, fa20f000), \
11472 X(_lsrs, 0800, fa30f000), \
11473 X(_mov, 2000, ea4f0000), \
11474 X(_movs, 2000, ea5f0000), \
11475 X(_mul, 4340, fb00f000), \
11476 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11477 X(_mvn, 43c0, ea6f0000), \
11478 X(_mvns, 43c0, ea7f0000), \
11479 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11480 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11481 X(_orr, 4300, ea400000), \
11482 X(_orrs, 4300, ea500000), \
11483 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11484 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11485 X(_rev, ba00, fa90f080), \
11486 X(_rev16, ba40, fa90f090), \
11487 X(_revsh, bac0, fa90f0b0), \
11488 X(_ror, 41c0, fa60f000), \
11489 X(_rors, 41c0, fa70f000), \
11490 X(_sbc, 4180, eb600000), \
11491 X(_sbcs, 4180, eb700000), \
11492 X(_stmia, c000, e8800000), \
11493 X(_str, 6000, f8400000), \
11494 X(_strb, 7000, f8000000), \
11495 X(_strh, 8000, f8200000), \
11496 X(_str_sp,9000, f84d0000), \
11497 X(_sub, 1e00, eba00000), \
11498 X(_subs, 1e00, ebb00000), \
11499 X(_subi, 8000, f1a00000), \
11500 X(_subis, 8000, f1b00000), \
11501 X(_sxtb, b240, fa4ff080), \
11502 X(_sxth, b200, fa0ff080), \
11503 X(_tst, 4200, ea100f00), \
11504 X(_uxtb, b2c0, fa5ff080), \
11505 X(_uxth, b280, fa1ff080), \
11506 X(_nop, bf00, f3af8000), \
11507 X(_yield, bf10, f3af8001), \
11508 X(_wfe, bf20, f3af8002), \
11509 X(_wfi, bf30, f3af8003), \
60f993ce 11510 X(_wls, 0000, f040c001), \
1f6234a3 11511 X(_wlstp, 0000, f000c001), \
53c4b28b 11512 X(_sev, bf40, f3af8004), \
74db7efb
NC
11513 X(_sevl, bf50, f3af8005), \
11514 X(_udf, de00, f7f0a000)
c19d1205
ZW
11515
11516/* To catch errors in encoding functions, the codes are all offset by
11517 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11518 as 16-bit instructions. */
21d799b5 11519#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11520enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11521#undef X
11522
11523#define X(a,b,c) 0x##b
11524static const unsigned short thumb_op16[] = { T16_32_TAB };
11525#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11526#undef X
11527
11528#define X(a,b,c) 0x##c
11529static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11530#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11531#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11532#undef X
11533#undef T16_32_TAB
11534
11535/* Thumb instruction encoders, in alphabetical order. */
11536
92e90b6e 11537/* ADDW or SUBW. */
c921be7d 11538
92e90b6e
PB
11539static void
11540do_t_add_sub_w (void)
11541{
11542 int Rd, Rn;
11543
11544 Rd = inst.operands[0].reg;
11545 Rn = inst.operands[1].reg;
11546
539d4391
NC
11547 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11548 is the SP-{plus,minus}-immediate form of the instruction. */
11549 if (Rn == REG_SP)
11550 constraint (Rd == REG_PC, BAD_PC);
11551 else
11552 reject_bad_reg (Rd);
fdfde340 11553
92e90b6e 11554 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11555 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11556}
11557
c19d1205 11558/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11559 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11560
11561static void
11562do_t_add_sub (void)
11563{
11564 int Rd, Rs, Rn;
11565
11566 Rd = inst.operands[0].reg;
11567 Rs = (inst.operands[1].present
11568 ? inst.operands[1].reg /* Rd, Rs, foo */
11569 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11570
e07e6e58 11571 if (Rd == REG_PC)
5ee91343 11572 set_pred_insn_type_last ();
e07e6e58 11573
c19d1205
ZW
11574 if (unified_syntax)
11575 {
0110f2b8
PB
11576 bfd_boolean flags;
11577 bfd_boolean narrow;
11578 int opcode;
11579
11580 flags = (inst.instruction == T_MNEM_adds
11581 || inst.instruction == T_MNEM_subs);
11582 if (flags)
5ee91343 11583 narrow = !in_pred_block ();
0110f2b8 11584 else
5ee91343 11585 narrow = in_pred_block ();
c19d1205 11586 if (!inst.operands[2].isreg)
b99bd4ef 11587 {
16805f35
PB
11588 int add;
11589
5c8ed6a4
JW
11590 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11591 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11592
16805f35
PB
11593 add = (inst.instruction == T_MNEM_add
11594 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11595 opcode = 0;
11596 if (inst.size_req != 4)
11597 {
0110f2b8 11598 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11599 appropriate. */
0110f2b8
PB
11600 if (Rd == REG_SP && Rs == REG_SP && !flags)
11601 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11602 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11603 opcode = T_MNEM_add_sp;
11604 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11605 opcode = T_MNEM_add_pc;
11606 else if (Rd <= 7 && Rs <= 7 && narrow)
11607 {
11608 if (flags)
11609 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11610 else
11611 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11612 }
11613 if (opcode)
11614 {
11615 inst.instruction = THUMB_OP16(opcode);
11616 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11617 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11618 || (inst.relocs[0].type
11619 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11620 {
11621 if (inst.size_req == 2)
e2b0ab59 11622 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11623 else
11624 inst.relax = opcode;
11625 }
0110f2b8
PB
11626 }
11627 else
11628 constraint (inst.size_req == 2, BAD_HIREG);
11629 }
11630 if (inst.size_req == 4
11631 || (inst.size_req != 2 && !opcode))
11632 {
e2b0ab59
AV
11633 constraint ((inst.relocs[0].type
11634 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11635 && (inst.relocs[0].type
11636 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11637 THUMB1_RELOC_ONLY);
efd81785
PB
11638 if (Rd == REG_PC)
11639 {
fdfde340 11640 constraint (add, BAD_PC);
efd81785
PB
11641 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11642 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11643 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11644 _("expression too complex"));
e2b0ab59
AV
11645 constraint (inst.relocs[0].exp.X_add_number < 0
11646 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11647 _("immediate value out of range"));
11648 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11649 | inst.relocs[0].exp.X_add_number;
11650 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11651 return;
11652 }
11653 else if (Rs == REG_PC)
16805f35
PB
11654 {
11655 /* Always use addw/subw. */
11656 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11657 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11658 }
11659 else
11660 {
11661 inst.instruction = THUMB_OP32 (inst.instruction);
11662 inst.instruction = (inst.instruction & 0xe1ffffff)
11663 | 0x10000000;
11664 if (flags)
e2b0ab59 11665 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11666 else
e2b0ab59 11667 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11668 }
dc4503c6
PB
11669 inst.instruction |= Rd << 8;
11670 inst.instruction |= Rs << 16;
0110f2b8 11671 }
b99bd4ef 11672 }
c19d1205
ZW
11673 else
11674 {
e2b0ab59 11675 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11676 unsigned int shift = inst.operands[2].shift_kind;
11677
c19d1205
ZW
11678 Rn = inst.operands[2].reg;
11679 /* See if we can do this with a 16-bit instruction. */
11680 if (!inst.operands[2].shifted && inst.size_req != 4)
11681 {
e27ec89e
PB
11682 if (Rd > 7 || Rs > 7 || Rn > 7)
11683 narrow = FALSE;
11684
11685 if (narrow)
c19d1205 11686 {
e27ec89e
PB
11687 inst.instruction = ((inst.instruction == T_MNEM_adds
11688 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11689 ? T_OPCODE_ADD_R3
11690 : T_OPCODE_SUB_R3);
11691 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11692 return;
11693 }
b99bd4ef 11694
7e806470 11695 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11696 {
7e806470
PB
11697 /* Thumb-1 cores (except v6-M) require at least one high
11698 register in a narrow non flag setting add. */
11699 if (Rd > 7 || Rn > 7
11700 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11701 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11702 {
7e806470
PB
11703 if (Rd == Rn)
11704 {
11705 Rn = Rs;
11706 Rs = Rd;
11707 }
c19d1205
ZW
11708 inst.instruction = T_OPCODE_ADD_HI;
11709 inst.instruction |= (Rd & 8) << 4;
11710 inst.instruction |= (Rd & 7);
11711 inst.instruction |= Rn << 3;
11712 return;
11713 }
c19d1205
ZW
11714 }
11715 }
c921be7d 11716
fdfde340 11717 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11718 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11719 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11720 constraint (Rs == REG_PC, BAD_PC);
11721 reject_bad_reg (Rn);
11722
c19d1205
ZW
11723 /* If we get here, it can't be done in 16 bits. */
11724 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11725 _("shift must be constant"));
11726 inst.instruction = THUMB_OP32 (inst.instruction);
11727 inst.instruction |= Rd << 8;
11728 inst.instruction |= Rs << 16;
5f4cb198
NC
11729 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11730 _("shift value over 3 not allowed in thumb mode"));
11731 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11732 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11733 encode_thumb32_shifted_operand (2);
11734 }
11735 }
11736 else
11737 {
11738 constraint (inst.instruction == T_MNEM_adds
11739 || inst.instruction == T_MNEM_subs,
11740 BAD_THUMB32);
b99bd4ef 11741
c19d1205 11742 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11743 {
c19d1205
ZW
11744 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11745 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11746 BAD_HIREG);
11747
11748 inst.instruction = (inst.instruction == T_MNEM_add
11749 ? 0x0000 : 0x8000);
11750 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11751 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11752 return;
11753 }
11754
c19d1205
ZW
11755 Rn = inst.operands[2].reg;
11756 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11757
c19d1205
ZW
11758 /* We now have Rd, Rs, and Rn set to registers. */
11759 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11760 {
c19d1205
ZW
11761 /* Can't do this for SUB. */
11762 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11763 inst.instruction = T_OPCODE_ADD_HI;
11764 inst.instruction |= (Rd & 8) << 4;
11765 inst.instruction |= (Rd & 7);
11766 if (Rs == Rd)
11767 inst.instruction |= Rn << 3;
11768 else if (Rn == Rd)
11769 inst.instruction |= Rs << 3;
11770 else
11771 constraint (1, _("dest must overlap one source register"));
11772 }
11773 else
11774 {
11775 inst.instruction = (inst.instruction == T_MNEM_add
11776 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11777 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11778 }
b99bd4ef 11779 }
b99bd4ef
NC
11780}
11781
c19d1205
ZW
11782static void
11783do_t_adr (void)
11784{
fdfde340
JM
11785 unsigned Rd;
11786
11787 Rd = inst.operands[0].reg;
11788 reject_bad_reg (Rd);
11789
11790 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11791 {
11792 /* Defer to section relaxation. */
11793 inst.relax = inst.instruction;
11794 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11795 inst.instruction |= Rd << 4;
0110f2b8
PB
11796 }
11797 else if (unified_syntax && inst.size_req != 2)
e9f89963 11798 {
0110f2b8 11799 /* Generate a 32-bit opcode. */
e9f89963 11800 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11801 inst.instruction |= Rd << 8;
e2b0ab59
AV
11802 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11803 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11804 }
11805 else
11806 {
0110f2b8 11807 /* Generate a 16-bit opcode. */
e9f89963 11808 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11809 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11810 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11811 inst.relocs[0].pc_rel = 1;
fdfde340 11812 inst.instruction |= Rd << 4;
e9f89963 11813 }
52a86f84 11814
e2b0ab59
AV
11815 if (inst.relocs[0].exp.X_op == O_symbol
11816 && inst.relocs[0].exp.X_add_symbol != NULL
11817 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11818 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11819 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11820}
b99bd4ef 11821
c19d1205
ZW
11822/* Arithmetic instructions for which there is just one 16-bit
11823 instruction encoding, and it allows only two low registers.
11824 For maximal compatibility with ARM syntax, we allow three register
11825 operands even when Thumb-32 instructions are not available, as long
11826 as the first two are identical. For instance, both "sbc r0,r1" and
11827 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11828static void
c19d1205 11829do_t_arit3 (void)
b99bd4ef 11830{
c19d1205 11831 int Rd, Rs, Rn;
b99bd4ef 11832
c19d1205
ZW
11833 Rd = inst.operands[0].reg;
11834 Rs = (inst.operands[1].present
11835 ? inst.operands[1].reg /* Rd, Rs, foo */
11836 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11837 Rn = inst.operands[2].reg;
b99bd4ef 11838
fdfde340
JM
11839 reject_bad_reg (Rd);
11840 reject_bad_reg (Rs);
11841 if (inst.operands[2].isreg)
11842 reject_bad_reg (Rn);
11843
c19d1205 11844 if (unified_syntax)
b99bd4ef 11845 {
c19d1205
ZW
11846 if (!inst.operands[2].isreg)
11847 {
11848 /* For an immediate, we always generate a 32-bit opcode;
11849 section relaxation will shrink it later if possible. */
11850 inst.instruction = THUMB_OP32 (inst.instruction);
11851 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11852 inst.instruction |= Rd << 8;
11853 inst.instruction |= Rs << 16;
e2b0ab59 11854 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11855 }
11856 else
11857 {
e27ec89e
PB
11858 bfd_boolean narrow;
11859
c19d1205 11860 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11861 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11862 narrow = !in_pred_block ();
e27ec89e 11863 else
5ee91343 11864 narrow = in_pred_block ();
e27ec89e
PB
11865
11866 if (Rd > 7 || Rn > 7 || Rs > 7)
11867 narrow = FALSE;
11868 if (inst.operands[2].shifted)
11869 narrow = FALSE;
11870 if (inst.size_req == 4)
11871 narrow = FALSE;
11872
11873 if (narrow
c19d1205
ZW
11874 && Rd == Rs)
11875 {
11876 inst.instruction = THUMB_OP16 (inst.instruction);
11877 inst.instruction |= Rd;
11878 inst.instruction |= Rn << 3;
11879 return;
11880 }
b99bd4ef 11881
c19d1205
ZW
11882 /* If we get here, it can't be done in 16 bits. */
11883 constraint (inst.operands[2].shifted
11884 && inst.operands[2].immisreg,
11885 _("shift must be constant"));
11886 inst.instruction = THUMB_OP32 (inst.instruction);
11887 inst.instruction |= Rd << 8;
11888 inst.instruction |= Rs << 16;
11889 encode_thumb32_shifted_operand (2);
11890 }
a737bd4d 11891 }
c19d1205 11892 else
b99bd4ef 11893 {
c19d1205
ZW
11894 /* On its face this is a lie - the instruction does set the
11895 flags. However, the only supported mnemonic in this mode
11896 says it doesn't. */
11897 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11898
c19d1205
ZW
11899 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11900 _("unshifted register required"));
11901 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11902 constraint (Rd != Rs,
11903 _("dest and source1 must be the same register"));
a737bd4d 11904
c19d1205
ZW
11905 inst.instruction = THUMB_OP16 (inst.instruction);
11906 inst.instruction |= Rd;
11907 inst.instruction |= Rn << 3;
b99bd4ef 11908 }
a737bd4d 11909}
b99bd4ef 11910
c19d1205
ZW
11911/* Similarly, but for instructions where the arithmetic operation is
11912 commutative, so we can allow either of them to be different from
11913 the destination operand in a 16-bit instruction. For instance, all
11914 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11915 accepted. */
11916static void
11917do_t_arit3c (void)
a737bd4d 11918{
c19d1205 11919 int Rd, Rs, Rn;
b99bd4ef 11920
c19d1205
ZW
11921 Rd = inst.operands[0].reg;
11922 Rs = (inst.operands[1].present
11923 ? inst.operands[1].reg /* Rd, Rs, foo */
11924 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11925 Rn = inst.operands[2].reg;
c921be7d 11926
fdfde340
JM
11927 reject_bad_reg (Rd);
11928 reject_bad_reg (Rs);
11929 if (inst.operands[2].isreg)
11930 reject_bad_reg (Rn);
a737bd4d 11931
c19d1205 11932 if (unified_syntax)
a737bd4d 11933 {
c19d1205 11934 if (!inst.operands[2].isreg)
b99bd4ef 11935 {
c19d1205
ZW
11936 /* For an immediate, we always generate a 32-bit opcode;
11937 section relaxation will shrink it later if possible. */
11938 inst.instruction = THUMB_OP32 (inst.instruction);
11939 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11940 inst.instruction |= Rd << 8;
11941 inst.instruction |= Rs << 16;
e2b0ab59 11942 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11943 }
c19d1205 11944 else
a737bd4d 11945 {
e27ec89e
PB
11946 bfd_boolean narrow;
11947
c19d1205 11948 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11949 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11950 narrow = !in_pred_block ();
e27ec89e 11951 else
5ee91343 11952 narrow = in_pred_block ();
e27ec89e
PB
11953
11954 if (Rd > 7 || Rn > 7 || Rs > 7)
11955 narrow = FALSE;
11956 if (inst.operands[2].shifted)
11957 narrow = FALSE;
11958 if (inst.size_req == 4)
11959 narrow = FALSE;
11960
11961 if (narrow)
a737bd4d 11962 {
c19d1205 11963 if (Rd == Rs)
a737bd4d 11964 {
c19d1205
ZW
11965 inst.instruction = THUMB_OP16 (inst.instruction);
11966 inst.instruction |= Rd;
11967 inst.instruction |= Rn << 3;
11968 return;
a737bd4d 11969 }
c19d1205 11970 if (Rd == Rn)
a737bd4d 11971 {
c19d1205
ZW
11972 inst.instruction = THUMB_OP16 (inst.instruction);
11973 inst.instruction |= Rd;
11974 inst.instruction |= Rs << 3;
11975 return;
a737bd4d
NC
11976 }
11977 }
c19d1205
ZW
11978
11979 /* If we get here, it can't be done in 16 bits. */
11980 constraint (inst.operands[2].shifted
11981 && inst.operands[2].immisreg,
11982 _("shift must be constant"));
11983 inst.instruction = THUMB_OP32 (inst.instruction);
11984 inst.instruction |= Rd << 8;
11985 inst.instruction |= Rs << 16;
11986 encode_thumb32_shifted_operand (2);
a737bd4d 11987 }
b99bd4ef 11988 }
c19d1205
ZW
11989 else
11990 {
11991 /* On its face this is a lie - the instruction does set the
11992 flags. However, the only supported mnemonic in this mode
11993 says it doesn't. */
11994 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11995
c19d1205
ZW
11996 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11997 _("unshifted register required"));
11998 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11999
12000 inst.instruction = THUMB_OP16 (inst.instruction);
12001 inst.instruction |= Rd;
12002
12003 if (Rd == Rs)
12004 inst.instruction |= Rn << 3;
12005 else if (Rd == Rn)
12006 inst.instruction |= Rs << 3;
12007 else
12008 constraint (1, _("dest must overlap one source register"));
12009 }
a737bd4d
NC
12010}
12011
c19d1205
ZW
12012static void
12013do_t_bfc (void)
a737bd4d 12014{
fdfde340 12015 unsigned Rd;
c19d1205
ZW
12016 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12017 constraint (msb > 32, _("bit-field extends past end of register"));
12018 /* The instruction encoding stores the LSB and MSB,
12019 not the LSB and width. */
fdfde340
JM
12020 Rd = inst.operands[0].reg;
12021 reject_bad_reg (Rd);
12022 inst.instruction |= Rd << 8;
c19d1205
ZW
12023 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12024 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12025 inst.instruction |= msb - 1;
b99bd4ef
NC
12026}
12027
c19d1205
ZW
12028static void
12029do_t_bfi (void)
b99bd4ef 12030{
fdfde340 12031 int Rd, Rn;
c19d1205 12032 unsigned int msb;
b99bd4ef 12033
fdfde340
JM
12034 Rd = inst.operands[0].reg;
12035 reject_bad_reg (Rd);
12036
c19d1205
ZW
12037 /* #0 in second position is alternative syntax for bfc, which is
12038 the same instruction but with REG_PC in the Rm field. */
12039 if (!inst.operands[1].isreg)
fdfde340
JM
12040 Rn = REG_PC;
12041 else
12042 {
12043 Rn = inst.operands[1].reg;
12044 reject_bad_reg (Rn);
12045 }
b99bd4ef 12046
c19d1205
ZW
12047 msb = inst.operands[2].imm + inst.operands[3].imm;
12048 constraint (msb > 32, _("bit-field extends past end of register"));
12049 /* The instruction encoding stores the LSB and MSB,
12050 not the LSB and width. */
fdfde340
JM
12051 inst.instruction |= Rd << 8;
12052 inst.instruction |= Rn << 16;
c19d1205
ZW
12053 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12054 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12055 inst.instruction |= msb - 1;
b99bd4ef
NC
12056}
12057
c19d1205
ZW
12058static void
12059do_t_bfx (void)
b99bd4ef 12060{
fdfde340
JM
12061 unsigned Rd, Rn;
12062
12063 Rd = inst.operands[0].reg;
12064 Rn = inst.operands[1].reg;
12065
12066 reject_bad_reg (Rd);
12067 reject_bad_reg (Rn);
12068
c19d1205
ZW
12069 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12070 _("bit-field extends past end of register"));
fdfde340
JM
12071 inst.instruction |= Rd << 8;
12072 inst.instruction |= Rn << 16;
c19d1205
ZW
12073 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12074 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12075 inst.instruction |= inst.operands[3].imm - 1;
12076}
b99bd4ef 12077
c19d1205
ZW
12078/* ARM V5 Thumb BLX (argument parse)
12079 BLX <target_addr> which is BLX(1)
12080 BLX <Rm> which is BLX(2)
12081 Unfortunately, there are two different opcodes for this mnemonic.
12082 So, the insns[].value is not used, and the code here zaps values
12083 into inst.instruction.
b99bd4ef 12084
c19d1205
ZW
12085 ??? How to take advantage of the additional two bits of displacement
12086 available in Thumb32 mode? Need new relocation? */
b99bd4ef 12087
c19d1205
ZW
12088static void
12089do_t_blx (void)
12090{
5ee91343 12091 set_pred_insn_type_last ();
e07e6e58 12092
c19d1205 12093 if (inst.operands[0].isreg)
fdfde340
JM
12094 {
12095 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12096 /* We have a register, so this is BLX(2). */
12097 inst.instruction |= inst.operands[0].reg << 3;
12098 }
b99bd4ef
NC
12099 else
12100 {
c19d1205 12101 /* No register. This must be BLX(1). */
2fc8bdac 12102 inst.instruction = 0xf000e800;
0855e32b 12103 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
12104 }
12105}
12106
c19d1205
ZW
12107static void
12108do_t_branch (void)
b99bd4ef 12109{
0110f2b8 12110 int opcode;
dfa9f0d5 12111 int cond;
2fe88214 12112 bfd_reloc_code_real_type reloc;
dfa9f0d5 12113
e07e6e58 12114 cond = inst.cond;
5ee91343 12115 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 12116
5ee91343 12117 if (in_pred_block ())
dfa9f0d5
PB
12118 {
12119 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 12120 branches. */
dfa9f0d5 12121 cond = COND_ALWAYS;
dfa9f0d5
PB
12122 }
12123 else
12124 cond = inst.cond;
12125
12126 if (cond != COND_ALWAYS)
0110f2b8
PB
12127 opcode = T_MNEM_bcond;
12128 else
12129 opcode = inst.instruction;
12130
12d6b0b7
RS
12131 if (unified_syntax
12132 && (inst.size_req == 4
10960bfb
PB
12133 || (inst.size_req != 2
12134 && (inst.operands[0].hasreloc
e2b0ab59 12135 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 12136 {
0110f2b8 12137 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 12138 if (cond == COND_ALWAYS)
9ae92b05 12139 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
12140 else
12141 {
ff8646ee
TP
12142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12143 _("selected architecture does not support "
12144 "wide conditional branch instruction"));
12145
9c2799c2 12146 gas_assert (cond != 0xF);
dfa9f0d5 12147 inst.instruction |= cond << 22;
9ae92b05 12148 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12149 }
12150 }
b99bd4ef
NC
12151 else
12152 {
0110f2b8 12153 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12154 if (cond == COND_ALWAYS)
9ae92b05 12155 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12156 else
b99bd4ef 12157 {
dfa9f0d5 12158 inst.instruction |= cond << 8;
9ae92b05 12159 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12160 }
0110f2b8
PB
12161 /* Allow section relaxation. */
12162 if (unified_syntax && inst.size_req != 2)
12163 inst.relax = opcode;
b99bd4ef 12164 }
e2b0ab59
AV
12165 inst.relocs[0].type = reloc;
12166 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12167}
12168
8884b720 12169/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12170 between the two is the maximum immediate allowed - which is passed in
8884b720 12171 RANGE. */
b99bd4ef 12172static void
8884b720 12173do_t_bkpt_hlt1 (int range)
b99bd4ef 12174{
dfa9f0d5
PB
12175 constraint (inst.cond != COND_ALWAYS,
12176 _("instruction is always unconditional"));
c19d1205 12177 if (inst.operands[0].present)
b99bd4ef 12178 {
8884b720 12179 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12180 _("immediate value out of range"));
12181 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12182 }
8884b720 12183
5ee91343 12184 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12185}
12186
12187static void
12188do_t_hlt (void)
12189{
12190 do_t_bkpt_hlt1 (63);
12191}
12192
12193static void
12194do_t_bkpt (void)
12195{
12196 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12197}
12198
12199static void
c19d1205 12200do_t_branch23 (void)
b99bd4ef 12201{
5ee91343 12202 set_pred_insn_type_last ();
0855e32b 12203 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12204
0855e32b
NS
12205 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12206 this file. We used to simply ignore the PLT reloc type here --
12207 the branch encoding is now needed to deal with TLSCALL relocs.
12208 So if we see a PLT reloc now, put it back to how it used to be to
12209 keep the preexisting behaviour. */
e2b0ab59
AV
12210 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12211 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12212
4343666d 12213#if defined(OBJ_COFF)
c19d1205
ZW
12214 /* If the destination of the branch is a defined symbol which does not have
12215 the THUMB_FUNC attribute, then we must be calling a function which has
12216 the (interfacearm) attribute. We look for the Thumb entry point to that
12217 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12218 if ( inst.relocs[0].exp.X_op == O_symbol
12219 && inst.relocs[0].exp.X_add_symbol != NULL
12220 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12221 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12222 inst.relocs[0].exp.X_add_symbol
12223 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12224#endif
90e4755a
RE
12225}
12226
12227static void
c19d1205 12228do_t_bx (void)
90e4755a 12229{
5ee91343 12230 set_pred_insn_type_last ();
c19d1205
ZW
12231 inst.instruction |= inst.operands[0].reg << 3;
12232 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12233 should cause the alignment to be checked once it is known. This is
12234 because BX PC only works if the instruction is word aligned. */
12235}
90e4755a 12236
c19d1205
ZW
12237static void
12238do_t_bxj (void)
12239{
fdfde340 12240 int Rm;
90e4755a 12241
5ee91343 12242 set_pred_insn_type_last ();
fdfde340
JM
12243 Rm = inst.operands[0].reg;
12244 reject_bad_reg (Rm);
12245 inst.instruction |= Rm << 16;
90e4755a
RE
12246}
12247
12248static void
c19d1205 12249do_t_clz (void)
90e4755a 12250{
fdfde340
JM
12251 unsigned Rd;
12252 unsigned Rm;
12253
12254 Rd = inst.operands[0].reg;
12255 Rm = inst.operands[1].reg;
12256
12257 reject_bad_reg (Rd);
12258 reject_bad_reg (Rm);
12259
12260 inst.instruction |= Rd << 8;
12261 inst.instruction |= Rm << 16;
12262 inst.instruction |= Rm;
c19d1205 12263}
90e4755a 12264
e39c1607
SD
12265/* For the Armv8.1-M conditional instructions. */
12266static void
12267do_t_cond (void)
12268{
12269 unsigned Rd, Rn, Rm;
12270 signed int cond;
12271
12272 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12273
12274 Rd = inst.operands[0].reg;
12275 switch (inst.instruction)
12276 {
12277 case T_MNEM_csinc:
12278 case T_MNEM_csinv:
12279 case T_MNEM_csneg:
12280 case T_MNEM_csel:
12281 Rn = inst.operands[1].reg;
12282 Rm = inst.operands[2].reg;
12283 cond = inst.operands[3].imm;
12284 constraint (Rn == REG_SP, BAD_SP);
12285 constraint (Rm == REG_SP, BAD_SP);
12286 break;
12287
12288 case T_MNEM_cinc:
12289 case T_MNEM_cinv:
12290 case T_MNEM_cneg:
12291 Rn = inst.operands[1].reg;
12292 cond = inst.operands[2].imm;
12293 /* Invert the last bit to invert the cond. */
12294 cond = TOGGLE_BIT (cond, 0);
12295 constraint (Rn == REG_SP, BAD_SP);
12296 Rm = Rn;
12297 break;
12298
12299 case T_MNEM_csetm:
12300 case T_MNEM_cset:
12301 cond = inst.operands[1].imm;
12302 /* Invert the last bit to invert the cond. */
12303 cond = TOGGLE_BIT (cond, 0);
12304 Rn = REG_PC;
12305 Rm = REG_PC;
12306 break;
12307
12308 default: abort ();
12309 }
12310
12311 set_pred_insn_type (OUTSIDE_PRED_INSN);
12312 inst.instruction = THUMB_OP32 (inst.instruction);
12313 inst.instruction |= Rd << 8;
12314 inst.instruction |= Rn << 16;
12315 inst.instruction |= Rm;
12316 inst.instruction |= cond << 4;
12317}
12318
91d8b670
JG
12319static void
12320do_t_csdb (void)
12321{
5ee91343 12322 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12323}
12324
dfa9f0d5
PB
12325static void
12326do_t_cps (void)
12327{
5ee91343 12328 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12329 inst.instruction |= inst.operands[0].imm;
12330}
12331
c19d1205
ZW
12332static void
12333do_t_cpsi (void)
12334{
5ee91343 12335 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12336 if (unified_syntax
62b3e311
PB
12337 && (inst.operands[1].present || inst.size_req == 4)
12338 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12339 {
c19d1205
ZW
12340 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12341 inst.instruction = 0xf3af8000;
12342 inst.instruction |= imod << 9;
12343 inst.instruction |= inst.operands[0].imm << 5;
12344 if (inst.operands[1].present)
12345 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12346 }
c19d1205 12347 else
90e4755a 12348 {
62b3e311
PB
12349 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12350 && (inst.operands[0].imm & 4),
12351 _("selected processor does not support 'A' form "
12352 "of this instruction"));
12353 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12354 _("Thumb does not support the 2-argument "
12355 "form of this instruction"));
12356 inst.instruction |= inst.operands[0].imm;
90e4755a 12357 }
90e4755a
RE
12358}
12359
c19d1205
ZW
12360/* THUMB CPY instruction (argument parse). */
12361
90e4755a 12362static void
c19d1205 12363do_t_cpy (void)
90e4755a 12364{
c19d1205 12365 if (inst.size_req == 4)
90e4755a 12366 {
c19d1205
ZW
12367 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12368 inst.instruction |= inst.operands[0].reg << 8;
12369 inst.instruction |= inst.operands[1].reg;
90e4755a 12370 }
c19d1205 12371 else
90e4755a 12372 {
c19d1205
ZW
12373 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12374 inst.instruction |= (inst.operands[0].reg & 0x7);
12375 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12376 }
90e4755a
RE
12377}
12378
90e4755a 12379static void
25fe350b 12380do_t_cbz (void)
90e4755a 12381{
5ee91343 12382 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12383 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12384 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12385 inst.relocs[0].pc_rel = 1;
12386 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12387}
90e4755a 12388
62b3e311
PB
12389static void
12390do_t_dbg (void)
12391{
12392 inst.instruction |= inst.operands[0].imm;
12393}
12394
12395static void
12396do_t_div (void)
12397{
fdfde340
JM
12398 unsigned Rd, Rn, Rm;
12399
12400 Rd = inst.operands[0].reg;
12401 Rn = (inst.operands[1].present
12402 ? inst.operands[1].reg : Rd);
12403 Rm = inst.operands[2].reg;
12404
12405 reject_bad_reg (Rd);
12406 reject_bad_reg (Rn);
12407 reject_bad_reg (Rm);
12408
12409 inst.instruction |= Rd << 8;
12410 inst.instruction |= Rn << 16;
12411 inst.instruction |= Rm;
62b3e311
PB
12412}
12413
c19d1205
ZW
12414static void
12415do_t_hint (void)
12416{
12417 if (unified_syntax && inst.size_req == 4)
12418 inst.instruction = THUMB_OP32 (inst.instruction);
12419 else
12420 inst.instruction = THUMB_OP16 (inst.instruction);
12421}
90e4755a 12422
c19d1205
ZW
12423static void
12424do_t_it (void)
12425{
12426 unsigned int cond = inst.operands[0].imm;
e27ec89e 12427
5ee91343
AV
12428 set_pred_insn_type (IT_INSN);
12429 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12430 now_pred.cc = cond;
12431 now_pred.warn_deprecated = FALSE;
12432 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12433
12434 /* If the condition is a negative condition, invert the mask. */
c19d1205 12435 if ((cond & 0x1) == 0x0)
90e4755a 12436 {
c19d1205 12437 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12438
c19d1205 12439 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12440 {
12441 /* No conversion needed. */
5ee91343 12442 now_pred.block_length = 1;
5a01bb1d 12443 }
c19d1205 12444 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12445 {
12446 mask ^= 0x8;
5ee91343 12447 now_pred.block_length = 2;
5a01bb1d 12448 }
e27ec89e 12449 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12450 {
12451 mask ^= 0xC;
5ee91343 12452 now_pred.block_length = 3;
5a01bb1d 12453 }
c19d1205 12454 else
5a01bb1d
MGD
12455 {
12456 mask ^= 0xE;
5ee91343 12457 now_pred.block_length = 4;
5a01bb1d 12458 }
90e4755a 12459
e27ec89e
PB
12460 inst.instruction &= 0xfff0;
12461 inst.instruction |= mask;
c19d1205 12462 }
90e4755a 12463
c19d1205
ZW
12464 inst.instruction |= cond << 4;
12465}
90e4755a 12466
3c707909
PB
12467/* Helper function used for both push/pop and ldm/stm. */
12468static void
4b5a202f
AV
12469encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12470 bfd_boolean writeback)
3c707909 12471{
4b5a202f 12472 bfd_boolean load, store;
3c707909 12473
4b5a202f
AV
12474 gas_assert (base != -1 || !do_io);
12475 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12476 store = do_io && !load;
3c707909
PB
12477
12478 if (mask & (1 << 13))
12479 inst.error = _("SP not allowed in register list");
1e5b0379 12480
4b5a202f 12481 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12482 && writeback)
12483 inst.error = _("having the base register in the register list when "
12484 "using write back is UNPREDICTABLE");
12485
3c707909
PB
12486 if (load)
12487 {
e07e6e58 12488 if (mask & (1 << 15))
477330fc
RM
12489 {
12490 if (mask & (1 << 14))
12491 inst.error = _("LR and PC should not both be in register list");
12492 else
5ee91343 12493 set_pred_insn_type_last ();
477330fc 12494 }
3c707909 12495 }
4b5a202f 12496 else if (store)
3c707909
PB
12497 {
12498 if (mask & (1 << 15))
12499 inst.error = _("PC not allowed in register list");
3c707909
PB
12500 }
12501
4b5a202f 12502 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12503 {
12504 /* Single register transfers implemented as str/ldr. */
12505 if (writeback)
12506 {
12507 if (inst.instruction & (1 << 23))
12508 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12509 else
12510 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12511 }
12512 else
12513 {
12514 if (inst.instruction & (1 << 23))
12515 inst.instruction = 0x00800000; /* ia -> [base] */
12516 else
12517 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12518 }
12519
12520 inst.instruction |= 0xf8400000;
12521 if (load)
12522 inst.instruction |= 0x00100000;
12523
5f4273c7 12524 mask = ffs (mask) - 1;
3c707909
PB
12525 mask <<= 12;
12526 }
12527 else if (writeback)
12528 inst.instruction |= WRITE_BACK;
12529
12530 inst.instruction |= mask;
4b5a202f
AV
12531 if (do_io)
12532 inst.instruction |= base << 16;
3c707909
PB
12533}
12534
c19d1205
ZW
12535static void
12536do_t_ldmstm (void)
12537{
12538 /* This really doesn't seem worth it. */
e2b0ab59 12539 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12540 _("expression too complex"));
12541 constraint (inst.operands[1].writeback,
12542 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12543
c19d1205
ZW
12544 if (unified_syntax)
12545 {
3c707909
PB
12546 bfd_boolean narrow;
12547 unsigned mask;
12548
12549 narrow = FALSE;
c19d1205
ZW
12550 /* See if we can use a 16-bit instruction. */
12551 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12552 && inst.size_req != 4
3c707909 12553 && !(inst.operands[1].imm & ~0xff))
90e4755a 12554 {
3c707909 12555 mask = 1 << inst.operands[0].reg;
90e4755a 12556
eab4f823 12557 if (inst.operands[0].reg <= 7)
90e4755a 12558 {
3c707909 12559 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12560 ? inst.operands[0].writeback
12561 : (inst.operands[0].writeback
12562 == !(inst.operands[1].imm & mask)))
477330fc 12563 {
eab4f823
MGD
12564 if (inst.instruction == T_MNEM_stmia
12565 && (inst.operands[1].imm & mask)
12566 && (inst.operands[1].imm & (mask - 1)))
12567 as_warn (_("value stored for r%d is UNKNOWN"),
12568 inst.operands[0].reg);
3c707909 12569
eab4f823
MGD
12570 inst.instruction = THUMB_OP16 (inst.instruction);
12571 inst.instruction |= inst.operands[0].reg << 8;
12572 inst.instruction |= inst.operands[1].imm;
12573 narrow = TRUE;
12574 }
12575 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12576 {
12577 /* This means 1 register in reg list one of 3 situations:
12578 1. Instruction is stmia, but without writeback.
12579 2. lmdia without writeback, but with Rn not in
477330fc 12580 reglist.
eab4f823
MGD
12581 3. ldmia with writeback, but with Rn in reglist.
12582 Case 3 is UNPREDICTABLE behaviour, so we handle
12583 case 1 and 2 which can be converted into a 16-bit
12584 str or ldr. The SP cases are handled below. */
12585 unsigned long opcode;
12586 /* First, record an error for Case 3. */
12587 if (inst.operands[1].imm & mask
12588 && inst.operands[0].writeback)
fa94de6b 12589 inst.error =
eab4f823
MGD
12590 _("having the base register in the register list when "
12591 "using write back is UNPREDICTABLE");
fa94de6b
RM
12592
12593 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12594 : T_MNEM_ldr);
12595 inst.instruction = THUMB_OP16 (opcode);
12596 inst.instruction |= inst.operands[0].reg << 3;
12597 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12598 narrow = TRUE;
12599 }
90e4755a 12600 }
eab4f823 12601 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12602 {
eab4f823
MGD
12603 if (inst.operands[0].writeback)
12604 {
fa94de6b 12605 inst.instruction =
eab4f823 12606 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12607 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12608 inst.instruction |= inst.operands[1].imm;
477330fc 12609 narrow = TRUE;
eab4f823
MGD
12610 }
12611 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12612 {
fa94de6b 12613 inst.instruction =
eab4f823 12614 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12615 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12616 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12617 narrow = TRUE;
eab4f823 12618 }
90e4755a 12619 }
3c707909
PB
12620 }
12621
12622 if (!narrow)
12623 {
c19d1205
ZW
12624 if (inst.instruction < 0xffff)
12625 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12626
4b5a202f
AV
12627 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12628 inst.operands[1].imm,
12629 inst.operands[0].writeback);
90e4755a
RE
12630 }
12631 }
c19d1205 12632 else
90e4755a 12633 {
c19d1205
ZW
12634 constraint (inst.operands[0].reg > 7
12635 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12636 constraint (inst.instruction != T_MNEM_ldmia
12637 && inst.instruction != T_MNEM_stmia,
12638 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12639 if (inst.instruction == T_MNEM_stmia)
f03698e6 12640 {
c19d1205
ZW
12641 if (!inst.operands[0].writeback)
12642 as_warn (_("this instruction will write back the base register"));
12643 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12644 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12645 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12646 inst.operands[0].reg);
f03698e6 12647 }
c19d1205 12648 else
90e4755a 12649 {
c19d1205
ZW
12650 if (!inst.operands[0].writeback
12651 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12652 as_warn (_("this instruction will write back the base register"));
12653 else if (inst.operands[0].writeback
12654 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12655 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12656 }
12657
c19d1205
ZW
12658 inst.instruction = THUMB_OP16 (inst.instruction);
12659 inst.instruction |= inst.operands[0].reg << 8;
12660 inst.instruction |= inst.operands[1].imm;
12661 }
12662}
e28cd48c 12663
c19d1205
ZW
12664static void
12665do_t_ldrex (void)
12666{
12667 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12668 || inst.operands[1].postind || inst.operands[1].writeback
12669 || inst.operands[1].immisreg || inst.operands[1].shifted
12670 || inst.operands[1].negative,
01cfc07f 12671 BAD_ADDR_MODE);
e28cd48c 12672
5be8be5d
DG
12673 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12674
c19d1205
ZW
12675 inst.instruction |= inst.operands[0].reg << 12;
12676 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12677 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12678}
e28cd48c 12679
c19d1205
ZW
12680static void
12681do_t_ldrexd (void)
12682{
12683 if (!inst.operands[1].present)
1cac9012 12684 {
c19d1205
ZW
12685 constraint (inst.operands[0].reg == REG_LR,
12686 _("r14 not allowed as first register "
12687 "when second register is omitted"));
12688 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12689 }
c19d1205
ZW
12690 constraint (inst.operands[0].reg == inst.operands[1].reg,
12691 BAD_OVERLAP);
b99bd4ef 12692
c19d1205
ZW
12693 inst.instruction |= inst.operands[0].reg << 12;
12694 inst.instruction |= inst.operands[1].reg << 8;
12695 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12696}
12697
12698static void
c19d1205 12699do_t_ldst (void)
b99bd4ef 12700{
0110f2b8
PB
12701 unsigned long opcode;
12702 int Rn;
12703
e07e6e58
NC
12704 if (inst.operands[0].isreg
12705 && !inst.operands[0].preind
12706 && inst.operands[0].reg == REG_PC)
5ee91343 12707 set_pred_insn_type_last ();
e07e6e58 12708
0110f2b8 12709 opcode = inst.instruction;
c19d1205 12710 if (unified_syntax)
b99bd4ef 12711 {
53365c0d
PB
12712 if (!inst.operands[1].isreg)
12713 {
12714 if (opcode <= 0xffff)
12715 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12716 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12717 return;
12718 }
0110f2b8
PB
12719 if (inst.operands[1].isreg
12720 && !inst.operands[1].writeback
c19d1205
ZW
12721 && !inst.operands[1].shifted && !inst.operands[1].postind
12722 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12723 && opcode <= 0xffff
12724 && inst.size_req != 4)
c19d1205 12725 {
0110f2b8
PB
12726 /* Insn may have a 16-bit form. */
12727 Rn = inst.operands[1].reg;
12728 if (inst.operands[1].immisreg)
12729 {
12730 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12731 /* [Rn, Rik] */
0110f2b8
PB
12732 if (Rn <= 7 && inst.operands[1].imm <= 7)
12733 goto op16;
5be8be5d
DG
12734 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12735 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12736 }
12737 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12738 && opcode != T_MNEM_ldrsb)
12739 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12740 || (Rn == REG_SP && opcode == T_MNEM_str))
12741 {
12742 /* [Rn, #const] */
12743 if (Rn > 7)
12744 {
12745 if (Rn == REG_PC)
12746 {
e2b0ab59 12747 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12748 opcode = T_MNEM_ldr_pc2;
12749 else
12750 opcode = T_MNEM_ldr_pc;
12751 }
12752 else
12753 {
12754 if (opcode == T_MNEM_ldr)
12755 opcode = T_MNEM_ldr_sp;
12756 else
12757 opcode = T_MNEM_str_sp;
12758 }
12759 inst.instruction = inst.operands[0].reg << 8;
12760 }
12761 else
12762 {
12763 inst.instruction = inst.operands[0].reg;
12764 inst.instruction |= inst.operands[1].reg << 3;
12765 }
12766 inst.instruction |= THUMB_OP16 (opcode);
12767 if (inst.size_req == 2)
e2b0ab59 12768 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12769 else
12770 inst.relax = opcode;
12771 return;
12772 }
c19d1205 12773 }
0110f2b8 12774 /* Definitely a 32-bit variant. */
5be8be5d 12775
8d67f500
NC
12776 /* Warning for Erratum 752419. */
12777 if (opcode == T_MNEM_ldr
12778 && inst.operands[0].reg == REG_SP
12779 && inst.operands[1].writeback == 1
12780 && !inst.operands[1].immisreg)
12781 {
12782 if (no_cpu_selected ()
12783 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12784 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12785 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12786 as_warn (_("This instruction may be unpredictable "
12787 "if executed on M-profile cores "
12788 "with interrupts enabled."));
12789 }
12790
5be8be5d 12791 /* Do some validations regarding addressing modes. */
1be5fd2e 12792 if (inst.operands[1].immisreg)
5be8be5d
DG
12793 reject_bad_reg (inst.operands[1].imm);
12794
1be5fd2e
NC
12795 constraint (inst.operands[1].writeback == 1
12796 && inst.operands[0].reg == inst.operands[1].reg,
12797 BAD_OVERLAP);
12798
0110f2b8 12799 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12800 inst.instruction |= inst.operands[0].reg << 12;
12801 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12802 check_ldr_r15_aligned ();
b99bd4ef
NC
12803 return;
12804 }
12805
c19d1205
ZW
12806 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12807
12808 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12809 {
c19d1205
ZW
12810 /* Only [Rn,Rm] is acceptable. */
12811 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12812 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12813 || inst.operands[1].postind || inst.operands[1].shifted
12814 || inst.operands[1].negative,
12815 _("Thumb does not support this addressing mode"));
12816 inst.instruction = THUMB_OP16 (inst.instruction);
12817 goto op16;
b99bd4ef 12818 }
5f4273c7 12819
c19d1205
ZW
12820 inst.instruction = THUMB_OP16 (inst.instruction);
12821 if (!inst.operands[1].isreg)
8335d6aa 12822 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12823 return;
b99bd4ef 12824
c19d1205
ZW
12825 constraint (!inst.operands[1].preind
12826 || inst.operands[1].shifted
12827 || inst.operands[1].writeback,
12828 _("Thumb does not support this addressing mode"));
12829 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12830 {
c19d1205
ZW
12831 constraint (inst.instruction & 0x0600,
12832 _("byte or halfword not valid for base register"));
12833 constraint (inst.operands[1].reg == REG_PC
12834 && !(inst.instruction & THUMB_LOAD_BIT),
12835 _("r15 based store not allowed"));
12836 constraint (inst.operands[1].immisreg,
12837 _("invalid base register for register offset"));
b99bd4ef 12838
c19d1205
ZW
12839 if (inst.operands[1].reg == REG_PC)
12840 inst.instruction = T_OPCODE_LDR_PC;
12841 else if (inst.instruction & THUMB_LOAD_BIT)
12842 inst.instruction = T_OPCODE_LDR_SP;
12843 else
12844 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12845
c19d1205 12846 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12847 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12848 return;
12849 }
90e4755a 12850
c19d1205
ZW
12851 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12852 if (!inst.operands[1].immisreg)
12853 {
12854 /* Immediate offset. */
12855 inst.instruction |= inst.operands[0].reg;
12856 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12857 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12858 return;
12859 }
90e4755a 12860
c19d1205
ZW
12861 /* Register offset. */
12862 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12863 constraint (inst.operands[1].negative,
12864 _("Thumb does not support this addressing mode"));
90e4755a 12865
c19d1205
ZW
12866 op16:
12867 switch (inst.instruction)
12868 {
12869 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12870 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12871 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12872 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12873 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12874 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12875 case 0x5600 /* ldrsb */:
12876 case 0x5e00 /* ldrsh */: break;
12877 default: abort ();
12878 }
90e4755a 12879
c19d1205
ZW
12880 inst.instruction |= inst.operands[0].reg;
12881 inst.instruction |= inst.operands[1].reg << 3;
12882 inst.instruction |= inst.operands[1].imm << 6;
12883}
90e4755a 12884
c19d1205
ZW
12885static void
12886do_t_ldstd (void)
12887{
12888 if (!inst.operands[1].present)
b99bd4ef 12889 {
c19d1205
ZW
12890 inst.operands[1].reg = inst.operands[0].reg + 1;
12891 constraint (inst.operands[0].reg == REG_LR,
12892 _("r14 not allowed here"));
bd340a04 12893 constraint (inst.operands[0].reg == REG_R12,
477330fc 12894 _("r12 not allowed here"));
b99bd4ef 12895 }
bd340a04
MGD
12896
12897 if (inst.operands[2].writeback
12898 && (inst.operands[0].reg == inst.operands[2].reg
12899 || inst.operands[1].reg == inst.operands[2].reg))
12900 as_warn (_("base register written back, and overlaps "
477330fc 12901 "one of transfer registers"));
bd340a04 12902
c19d1205
ZW
12903 inst.instruction |= inst.operands[0].reg << 12;
12904 inst.instruction |= inst.operands[1].reg << 8;
12905 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12906}
12907
c19d1205
ZW
12908static void
12909do_t_ldstt (void)
12910{
12911 inst.instruction |= inst.operands[0].reg << 12;
12912 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12913}
a737bd4d 12914
b99bd4ef 12915static void
c19d1205 12916do_t_mla (void)
b99bd4ef 12917{
fdfde340 12918 unsigned Rd, Rn, Rm, Ra;
c921be7d 12919
fdfde340
JM
12920 Rd = inst.operands[0].reg;
12921 Rn = inst.operands[1].reg;
12922 Rm = inst.operands[2].reg;
12923 Ra = inst.operands[3].reg;
12924
12925 reject_bad_reg (Rd);
12926 reject_bad_reg (Rn);
12927 reject_bad_reg (Rm);
12928 reject_bad_reg (Ra);
12929
12930 inst.instruction |= Rd << 8;
12931 inst.instruction |= Rn << 16;
12932 inst.instruction |= Rm;
12933 inst.instruction |= Ra << 12;
c19d1205 12934}
b99bd4ef 12935
c19d1205
ZW
12936static void
12937do_t_mlal (void)
12938{
fdfde340
JM
12939 unsigned RdLo, RdHi, Rn, Rm;
12940
12941 RdLo = inst.operands[0].reg;
12942 RdHi = inst.operands[1].reg;
12943 Rn = inst.operands[2].reg;
12944 Rm = inst.operands[3].reg;
12945
12946 reject_bad_reg (RdLo);
12947 reject_bad_reg (RdHi);
12948 reject_bad_reg (Rn);
12949 reject_bad_reg (Rm);
12950
12951 inst.instruction |= RdLo << 12;
12952 inst.instruction |= RdHi << 8;
12953 inst.instruction |= Rn << 16;
12954 inst.instruction |= Rm;
c19d1205 12955}
b99bd4ef 12956
c19d1205
ZW
12957static void
12958do_t_mov_cmp (void)
12959{
fdfde340
JM
12960 unsigned Rn, Rm;
12961
12962 Rn = inst.operands[0].reg;
12963 Rm = inst.operands[1].reg;
12964
e07e6e58 12965 if (Rn == REG_PC)
5ee91343 12966 set_pred_insn_type_last ();
e07e6e58 12967
c19d1205 12968 if (unified_syntax)
b99bd4ef 12969 {
c19d1205
ZW
12970 int r0off = (inst.instruction == T_MNEM_mov
12971 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12972 unsigned long opcode;
3d388997
PB
12973 bfd_boolean narrow;
12974 bfd_boolean low_regs;
12975
fdfde340 12976 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12977 opcode = inst.instruction;
5ee91343 12978 if (in_pred_block ())
0110f2b8 12979 narrow = opcode != T_MNEM_movs;
3d388997 12980 else
0110f2b8 12981 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12982 if (inst.size_req == 4
12983 || inst.operands[1].shifted)
12984 narrow = FALSE;
12985
efd81785
PB
12986 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12987 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12988 && !inst.operands[1].shifted
fdfde340
JM
12989 && Rn == REG_PC
12990 && Rm == REG_LR)
efd81785
PB
12991 {
12992 inst.instruction = T2_SUBS_PC_LR;
12993 return;
12994 }
12995
fdfde340
JM
12996 if (opcode == T_MNEM_cmp)
12997 {
12998 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12999 if (narrow)
13000 {
13001 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13002 but valid. */
13003 warn_deprecated_sp (Rm);
13004 /* R15 was documented as a valid choice for Rm in ARMv6,
13005 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13006 tools reject R15, so we do too. */
13007 constraint (Rm == REG_PC, BAD_PC);
13008 }
13009 else
13010 reject_bad_reg (Rm);
fdfde340
JM
13011 }
13012 else if (opcode == T_MNEM_mov
13013 || opcode == T_MNEM_movs)
13014 {
13015 if (inst.operands[1].isreg)
13016 {
13017 if (opcode == T_MNEM_movs)
13018 {
13019 reject_bad_reg (Rn);
13020 reject_bad_reg (Rm);
13021 }
76fa04a4
MGD
13022 else if (narrow)
13023 {
13024 /* This is mov.n. */
13025 if ((Rn == REG_SP || Rn == REG_PC)
13026 && (Rm == REG_SP || Rm == REG_PC))
13027 {
5c3696f8 13028 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
13029 "deprecated when r%u is the destination "
13030 "register."), Rm, Rn);
13031 }
13032 }
13033 else
13034 {
13035 /* This is mov.w. */
13036 constraint (Rn == REG_PC, BAD_PC);
13037 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
13038 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13039 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 13040 }
fdfde340
JM
13041 }
13042 else
13043 reject_bad_reg (Rn);
13044 }
13045
c19d1205
ZW
13046 if (!inst.operands[1].isreg)
13047 {
0110f2b8 13048 /* Immediate operand. */
5ee91343 13049 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
13050 narrow = 0;
13051 if (low_regs && narrow)
13052 {
13053 inst.instruction = THUMB_OP16 (opcode);
fdfde340 13054 inst.instruction |= Rn << 8;
e2b0ab59
AV
13055 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13056 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 13057 {
a9f02af8 13058 if (inst.size_req == 2)
e2b0ab59 13059 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
13060 else
13061 inst.relax = opcode;
72d98d16 13062 }
0110f2b8
PB
13063 }
13064 else
13065 {
e2b0ab59
AV
13066 constraint ((inst.relocs[0].type
13067 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13068 && (inst.relocs[0].type
13069 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
13070 THUMB1_RELOC_ONLY);
13071
0110f2b8
PB
13072 inst.instruction = THUMB_OP32 (inst.instruction);
13073 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13074 inst.instruction |= Rn << r0off;
e2b0ab59 13075 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 13076 }
c19d1205 13077 }
728ca7c9
PB
13078 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13079 && (inst.instruction == T_MNEM_mov
13080 || inst.instruction == T_MNEM_movs))
13081 {
13082 /* Register shifts are encoded as separate shift instructions. */
13083 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13084
5ee91343 13085 if (in_pred_block ())
728ca7c9
PB
13086 narrow = !flags;
13087 else
13088 narrow = flags;
13089
13090 if (inst.size_req == 4)
13091 narrow = FALSE;
13092
13093 if (!low_regs || inst.operands[1].imm > 7)
13094 narrow = FALSE;
13095
fdfde340 13096 if (Rn != Rm)
728ca7c9
PB
13097 narrow = FALSE;
13098
13099 switch (inst.operands[1].shift_kind)
13100 {
13101 case SHIFT_LSL:
13102 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13103 break;
13104 case SHIFT_ASR:
13105 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13106 break;
13107 case SHIFT_LSR:
13108 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13109 break;
13110 case SHIFT_ROR:
13111 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13112 break;
13113 default:
5f4273c7 13114 abort ();
728ca7c9
PB
13115 }
13116
13117 inst.instruction = opcode;
13118 if (narrow)
13119 {
fdfde340 13120 inst.instruction |= Rn;
728ca7c9
PB
13121 inst.instruction |= inst.operands[1].imm << 3;
13122 }
13123 else
13124 {
13125 if (flags)
13126 inst.instruction |= CONDS_BIT;
13127
fdfde340
JM
13128 inst.instruction |= Rn << 8;
13129 inst.instruction |= Rm << 16;
728ca7c9
PB
13130 inst.instruction |= inst.operands[1].imm;
13131 }
13132 }
3d388997 13133 else if (!narrow)
c19d1205 13134 {
728ca7c9
PB
13135 /* Some mov with immediate shift have narrow variants.
13136 Register shifts are handled above. */
13137 if (low_regs && inst.operands[1].shifted
13138 && (inst.instruction == T_MNEM_mov
13139 || inst.instruction == T_MNEM_movs))
13140 {
5ee91343 13141 if (in_pred_block ())
728ca7c9
PB
13142 narrow = (inst.instruction == T_MNEM_mov);
13143 else
13144 narrow = (inst.instruction == T_MNEM_movs);
13145 }
13146
13147 if (narrow)
13148 {
13149 switch (inst.operands[1].shift_kind)
13150 {
13151 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13152 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13153 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13154 default: narrow = FALSE; break;
13155 }
13156 }
13157
13158 if (narrow)
13159 {
fdfde340
JM
13160 inst.instruction |= Rn;
13161 inst.instruction |= Rm << 3;
e2b0ab59 13162 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13163 }
13164 else
13165 {
13166 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13167 inst.instruction |= Rn << r0off;
728ca7c9
PB
13168 encode_thumb32_shifted_operand (1);
13169 }
c19d1205
ZW
13170 }
13171 else
13172 switch (inst.instruction)
13173 {
13174 case T_MNEM_mov:
837b3435 13175 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13176 results. Don't allow this. */
13177 if (low_regs)
13178 {
13179 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13180 "MOV Rd, Rs with two low registers is not "
13181 "permitted on this architecture");
fa94de6b 13182 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13183 arm_ext_v6);
13184 }
13185
c19d1205 13186 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13187 inst.instruction |= (Rn & 0x8) << 4;
13188 inst.instruction |= (Rn & 0x7);
13189 inst.instruction |= Rm << 3;
c19d1205 13190 break;
b99bd4ef 13191
c19d1205
ZW
13192 case T_MNEM_movs:
13193 /* We know we have low registers at this point.
941a8a52
MGD
13194 Generate LSLS Rd, Rs, #0. */
13195 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13196 inst.instruction |= Rn;
13197 inst.instruction |= Rm << 3;
c19d1205
ZW
13198 break;
13199
13200 case T_MNEM_cmp:
3d388997 13201 if (low_regs)
c19d1205
ZW
13202 {
13203 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13204 inst.instruction |= Rn;
13205 inst.instruction |= Rm << 3;
c19d1205
ZW
13206 }
13207 else
13208 {
13209 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13210 inst.instruction |= (Rn & 0x8) << 4;
13211 inst.instruction |= (Rn & 0x7);
13212 inst.instruction |= Rm << 3;
c19d1205
ZW
13213 }
13214 break;
13215 }
b99bd4ef
NC
13216 return;
13217 }
13218
c19d1205 13219 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13220
13221 /* PR 10443: Do not silently ignore shifted operands. */
13222 constraint (inst.operands[1].shifted,
13223 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13224
c19d1205 13225 if (inst.operands[1].isreg)
b99bd4ef 13226 {
fdfde340 13227 if (Rn < 8 && Rm < 8)
b99bd4ef 13228 {
c19d1205
ZW
13229 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13230 since a MOV instruction produces unpredictable results. */
13231 if (inst.instruction == T_OPCODE_MOV_I8)
13232 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13233 else
c19d1205 13234 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13235
fdfde340
JM
13236 inst.instruction |= Rn;
13237 inst.instruction |= Rm << 3;
b99bd4ef
NC
13238 }
13239 else
13240 {
c19d1205
ZW
13241 if (inst.instruction == T_OPCODE_MOV_I8)
13242 inst.instruction = T_OPCODE_MOV_HR;
13243 else
13244 inst.instruction = T_OPCODE_CMP_HR;
13245 do_t_cpy ();
b99bd4ef
NC
13246 }
13247 }
c19d1205 13248 else
b99bd4ef 13249 {
fdfde340 13250 constraint (Rn > 7,
c19d1205 13251 _("only lo regs allowed with immediate"));
fdfde340 13252 inst.instruction |= Rn << 8;
e2b0ab59 13253 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13254 }
13255}
b99bd4ef 13256
c19d1205
ZW
13257static void
13258do_t_mov16 (void)
13259{
fdfde340 13260 unsigned Rd;
b6895b4f
PB
13261 bfd_vma imm;
13262 bfd_boolean top;
13263
13264 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13265 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13266 {
33eaf5de 13267 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13268 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13269 }
e2b0ab59 13270 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13271 {
33eaf5de 13272 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13273 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13274 }
13275
fdfde340
JM
13276 Rd = inst.operands[0].reg;
13277 reject_bad_reg (Rd);
13278
13279 inst.instruction |= Rd << 8;
e2b0ab59 13280 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13281 {
e2b0ab59 13282 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13283 inst.instruction |= (imm & 0xf000) << 4;
13284 inst.instruction |= (imm & 0x0800) << 15;
13285 inst.instruction |= (imm & 0x0700) << 4;
13286 inst.instruction |= (imm & 0x00ff);
13287 }
c19d1205 13288}
b99bd4ef 13289
c19d1205
ZW
13290static void
13291do_t_mvn_tst (void)
13292{
fdfde340 13293 unsigned Rn, Rm;
c921be7d 13294
fdfde340
JM
13295 Rn = inst.operands[0].reg;
13296 Rm = inst.operands[1].reg;
13297
13298 if (inst.instruction == T_MNEM_cmp
13299 || inst.instruction == T_MNEM_cmn)
13300 constraint (Rn == REG_PC, BAD_PC);
13301 else
13302 reject_bad_reg (Rn);
13303 reject_bad_reg (Rm);
13304
c19d1205
ZW
13305 if (unified_syntax)
13306 {
13307 int r0off = (inst.instruction == T_MNEM_mvn
13308 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13309 bfd_boolean narrow;
13310
13311 if (inst.size_req == 4
13312 || inst.instruction > 0xffff
13313 || inst.operands[1].shifted
fdfde340 13314 || Rn > 7 || Rm > 7)
3d388997 13315 narrow = FALSE;
fe8b4cc3
KT
13316 else if (inst.instruction == T_MNEM_cmn
13317 || inst.instruction == T_MNEM_tst)
3d388997
PB
13318 narrow = TRUE;
13319 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13320 narrow = !in_pred_block ();
3d388997 13321 else
5ee91343 13322 narrow = in_pred_block ();
3d388997 13323
c19d1205 13324 if (!inst.operands[1].isreg)
b99bd4ef 13325 {
c19d1205
ZW
13326 /* For an immediate, we always generate a 32-bit opcode;
13327 section relaxation will shrink it later if possible. */
13328 if (inst.instruction < 0xffff)
13329 inst.instruction = THUMB_OP32 (inst.instruction);
13330 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13331 inst.instruction |= Rn << r0off;
e2b0ab59 13332 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13333 }
c19d1205 13334 else
b99bd4ef 13335 {
c19d1205 13336 /* See if we can do this with a 16-bit instruction. */
3d388997 13337 if (narrow)
b99bd4ef 13338 {
c19d1205 13339 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13340 inst.instruction |= Rn;
13341 inst.instruction |= Rm << 3;
b99bd4ef 13342 }
c19d1205 13343 else
b99bd4ef 13344 {
c19d1205
ZW
13345 constraint (inst.operands[1].shifted
13346 && inst.operands[1].immisreg,
13347 _("shift must be constant"));
13348 if (inst.instruction < 0xffff)
13349 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13350 inst.instruction |= Rn << r0off;
c19d1205 13351 encode_thumb32_shifted_operand (1);
b99bd4ef 13352 }
b99bd4ef
NC
13353 }
13354 }
13355 else
13356 {
c19d1205
ZW
13357 constraint (inst.instruction > 0xffff
13358 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13359 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13360 _("unshifted register required"));
fdfde340 13361 constraint (Rn > 7 || Rm > 7,
c19d1205 13362 BAD_HIREG);
b99bd4ef 13363
c19d1205 13364 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13365 inst.instruction |= Rn;
13366 inst.instruction |= Rm << 3;
b99bd4ef 13367 }
b99bd4ef
NC
13368}
13369
b05fe5cf 13370static void
c19d1205 13371do_t_mrs (void)
b05fe5cf 13372{
fdfde340 13373 unsigned Rd;
037e8744
JB
13374
13375 if (do_vfp_nsyn_mrs () == SUCCESS)
13376 return;
13377
90ec0d68
MGD
13378 Rd = inst.operands[0].reg;
13379 reject_bad_reg (Rd);
13380 inst.instruction |= Rd << 8;
13381
13382 if (inst.operands[1].isreg)
62b3e311 13383 {
90ec0d68
MGD
13384 unsigned br = inst.operands[1].reg;
13385 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13386 as_bad (_("bad register for mrs"));
13387
13388 inst.instruction |= br & (0xf << 16);
13389 inst.instruction |= (br & 0x300) >> 4;
13390 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13391 }
13392 else
13393 {
90ec0d68 13394 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13395
d2cd1205 13396 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13397 {
13398 /* PR gas/12698: The constraint is only applied for m_profile.
13399 If the user has specified -march=all, we want to ignore it as
13400 we are building for any CPU type, including non-m variants. */
823d2571
TG
13401 bfd_boolean m_profile =
13402 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13403 constraint ((flags != 0) && m_profile, _("selected processor does "
13404 "not support requested special purpose register"));
13405 }
90ec0d68 13406 else
d2cd1205
JB
13407 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13408 devices). */
13409 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13410 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13411
90ec0d68
MGD
13412 inst.instruction |= (flags & SPSR_BIT) >> 2;
13413 inst.instruction |= inst.operands[1].imm & 0xff;
13414 inst.instruction |= 0xf0000;
13415 }
c19d1205 13416}
b05fe5cf 13417
c19d1205
ZW
13418static void
13419do_t_msr (void)
13420{
62b3e311 13421 int flags;
fdfde340 13422 unsigned Rn;
62b3e311 13423
037e8744
JB
13424 if (do_vfp_nsyn_msr () == SUCCESS)
13425 return;
13426
c19d1205
ZW
13427 constraint (!inst.operands[1].isreg,
13428 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13429
13430 if (inst.operands[0].isreg)
13431 flags = (int)(inst.operands[0].reg);
13432 else
13433 flags = inst.operands[0].imm;
13434
d2cd1205 13435 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13436 {
d2cd1205
JB
13437 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13438
1a43faaf 13439 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13440 If the user has specified -march=all, we want to ignore it as
13441 we are building for any CPU type, including non-m variants. */
823d2571
TG
13442 bfd_boolean m_profile =
13443 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13444 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13445 && (bits & ~(PSR_s | PSR_f)) != 0)
13446 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13447 && bits != PSR_f)) && m_profile,
13448 _("selected processor does not support requested special "
13449 "purpose register"));
62b3e311
PB
13450 }
13451 else
d2cd1205
JB
13452 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13453 "requested special purpose register"));
c921be7d 13454
fdfde340
JM
13455 Rn = inst.operands[1].reg;
13456 reject_bad_reg (Rn);
13457
62b3e311 13458 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13459 inst.instruction |= (flags & 0xf0000) >> 8;
13460 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13461 inst.instruction |= (flags & 0xff);
fdfde340 13462 inst.instruction |= Rn << 16;
c19d1205 13463}
b05fe5cf 13464
c19d1205
ZW
13465static void
13466do_t_mul (void)
13467{
17828f45 13468 bfd_boolean narrow;
fdfde340 13469 unsigned Rd, Rn, Rm;
17828f45 13470
c19d1205
ZW
13471 if (!inst.operands[2].present)
13472 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13473
fdfde340
JM
13474 Rd = inst.operands[0].reg;
13475 Rn = inst.operands[1].reg;
13476 Rm = inst.operands[2].reg;
13477
17828f45 13478 if (unified_syntax)
b05fe5cf 13479 {
17828f45 13480 if (inst.size_req == 4
fdfde340
JM
13481 || (Rd != Rn
13482 && Rd != Rm)
13483 || Rn > 7
13484 || Rm > 7)
17828f45
JM
13485 narrow = FALSE;
13486 else if (inst.instruction == T_MNEM_muls)
5ee91343 13487 narrow = !in_pred_block ();
17828f45 13488 else
5ee91343 13489 narrow = in_pred_block ();
b05fe5cf 13490 }
c19d1205 13491 else
b05fe5cf 13492 {
17828f45 13493 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13494 constraint (Rn > 7 || Rm > 7,
c19d1205 13495 BAD_HIREG);
17828f45
JM
13496 narrow = TRUE;
13497 }
b05fe5cf 13498
17828f45
JM
13499 if (narrow)
13500 {
13501 /* 16-bit MULS/Conditional MUL. */
c19d1205 13502 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13503 inst.instruction |= Rd;
b05fe5cf 13504
fdfde340
JM
13505 if (Rd == Rn)
13506 inst.instruction |= Rm << 3;
13507 else if (Rd == Rm)
13508 inst.instruction |= Rn << 3;
c19d1205
ZW
13509 else
13510 constraint (1, _("dest must overlap one source register"));
13511 }
17828f45
JM
13512 else
13513 {
e07e6e58
NC
13514 constraint (inst.instruction != T_MNEM_mul,
13515 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13516 /* 32-bit MUL. */
13517 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13518 inst.instruction |= Rd << 8;
13519 inst.instruction |= Rn << 16;
13520 inst.instruction |= Rm << 0;
13521
13522 reject_bad_reg (Rd);
13523 reject_bad_reg (Rn);
13524 reject_bad_reg (Rm);
17828f45 13525 }
c19d1205 13526}
b05fe5cf 13527
c19d1205
ZW
13528static void
13529do_t_mull (void)
13530{
fdfde340 13531 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13532
fdfde340
JM
13533 RdLo = inst.operands[0].reg;
13534 RdHi = inst.operands[1].reg;
13535 Rn = inst.operands[2].reg;
13536 Rm = inst.operands[3].reg;
13537
13538 reject_bad_reg (RdLo);
13539 reject_bad_reg (RdHi);
13540 reject_bad_reg (Rn);
13541 reject_bad_reg (Rm);
13542
13543 inst.instruction |= RdLo << 12;
13544 inst.instruction |= RdHi << 8;
13545 inst.instruction |= Rn << 16;
13546 inst.instruction |= Rm;
13547
13548 if (RdLo == RdHi)
c19d1205
ZW
13549 as_tsktsk (_("rdhi and rdlo must be different"));
13550}
b05fe5cf 13551
c19d1205
ZW
13552static void
13553do_t_nop (void)
13554{
5ee91343 13555 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13556
c19d1205
ZW
13557 if (unified_syntax)
13558 {
13559 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13560 {
c19d1205
ZW
13561 inst.instruction = THUMB_OP32 (inst.instruction);
13562 inst.instruction |= inst.operands[0].imm;
13563 }
13564 else
13565 {
bc2d1808
NC
13566 /* PR9722: Check for Thumb2 availability before
13567 generating a thumb2 nop instruction. */
afa62d5e 13568 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13569 {
13570 inst.instruction = THUMB_OP16 (inst.instruction);
13571 inst.instruction |= inst.operands[0].imm << 4;
13572 }
13573 else
13574 inst.instruction = 0x46c0;
c19d1205
ZW
13575 }
13576 }
13577 else
13578 {
13579 constraint (inst.operands[0].present,
13580 _("Thumb does not support NOP with hints"));
13581 inst.instruction = 0x46c0;
13582 }
13583}
b05fe5cf 13584
c19d1205
ZW
13585static void
13586do_t_neg (void)
13587{
13588 if (unified_syntax)
13589 {
3d388997
PB
13590 bfd_boolean narrow;
13591
13592 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13593 narrow = !in_pred_block ();
3d388997 13594 else
5ee91343 13595 narrow = in_pred_block ();
3d388997
PB
13596 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13597 narrow = FALSE;
13598 if (inst.size_req == 4)
13599 narrow = FALSE;
13600
13601 if (!narrow)
c19d1205
ZW
13602 {
13603 inst.instruction = THUMB_OP32 (inst.instruction);
13604 inst.instruction |= inst.operands[0].reg << 8;
13605 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13606 }
13607 else
13608 {
c19d1205
ZW
13609 inst.instruction = THUMB_OP16 (inst.instruction);
13610 inst.instruction |= inst.operands[0].reg;
13611 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13612 }
13613 }
13614 else
13615 {
c19d1205
ZW
13616 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13617 BAD_HIREG);
13618 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13619
13620 inst.instruction = THUMB_OP16 (inst.instruction);
13621 inst.instruction |= inst.operands[0].reg;
13622 inst.instruction |= inst.operands[1].reg << 3;
13623 }
13624}
13625
1c444d06
JM
13626static void
13627do_t_orn (void)
13628{
13629 unsigned Rd, Rn;
13630
13631 Rd = inst.operands[0].reg;
13632 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13633
fdfde340
JM
13634 reject_bad_reg (Rd);
13635 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13636 reject_bad_reg (Rn);
13637
1c444d06
JM
13638 inst.instruction |= Rd << 8;
13639 inst.instruction |= Rn << 16;
13640
13641 if (!inst.operands[2].isreg)
13642 {
13643 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13644 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13645 }
13646 else
13647 {
13648 unsigned Rm;
13649
13650 Rm = inst.operands[2].reg;
fdfde340 13651 reject_bad_reg (Rm);
1c444d06
JM
13652
13653 constraint (inst.operands[2].shifted
13654 && inst.operands[2].immisreg,
13655 _("shift must be constant"));
13656 encode_thumb32_shifted_operand (2);
13657 }
13658}
13659
c19d1205
ZW
13660static void
13661do_t_pkhbt (void)
13662{
fdfde340
JM
13663 unsigned Rd, Rn, Rm;
13664
13665 Rd = inst.operands[0].reg;
13666 Rn = inst.operands[1].reg;
13667 Rm = inst.operands[2].reg;
13668
13669 reject_bad_reg (Rd);
13670 reject_bad_reg (Rn);
13671 reject_bad_reg (Rm);
13672
13673 inst.instruction |= Rd << 8;
13674 inst.instruction |= Rn << 16;
13675 inst.instruction |= Rm;
c19d1205
ZW
13676 if (inst.operands[3].present)
13677 {
e2b0ab59
AV
13678 unsigned int val = inst.relocs[0].exp.X_add_number;
13679 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13680 _("expression too complex"));
13681 inst.instruction |= (val & 0x1c) << 10;
13682 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13683 }
c19d1205 13684}
b05fe5cf 13685
c19d1205
ZW
13686static void
13687do_t_pkhtb (void)
13688{
13689 if (!inst.operands[3].present)
1ef52f49
NC
13690 {
13691 unsigned Rtmp;
13692
13693 inst.instruction &= ~0x00000020;
13694
13695 /* PR 10168. Swap the Rm and Rn registers. */
13696 Rtmp = inst.operands[1].reg;
13697 inst.operands[1].reg = inst.operands[2].reg;
13698 inst.operands[2].reg = Rtmp;
13699 }
c19d1205 13700 do_t_pkhbt ();
b05fe5cf
ZW
13701}
13702
c19d1205
ZW
13703static void
13704do_t_pld (void)
13705{
fdfde340
JM
13706 if (inst.operands[0].immisreg)
13707 reject_bad_reg (inst.operands[0].imm);
13708
c19d1205
ZW
13709 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13710}
b05fe5cf 13711
c19d1205
ZW
13712static void
13713do_t_push_pop (void)
b99bd4ef 13714{
e9f89963 13715 unsigned mask;
5f4273c7 13716
c19d1205
ZW
13717 constraint (inst.operands[0].writeback,
13718 _("push/pop do not support {reglist}^"));
e2b0ab59 13719 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13720 _("expression too complex"));
b99bd4ef 13721
e9f89963 13722 mask = inst.operands[0].imm;
d3bfe16e 13723 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13724 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13725 else if (inst.size_req != 4
c6025a80 13726 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13727 ? REG_LR : REG_PC)))
b99bd4ef 13728 {
c19d1205
ZW
13729 inst.instruction = THUMB_OP16 (inst.instruction);
13730 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13731 inst.instruction |= mask & 0xff;
c19d1205
ZW
13732 }
13733 else if (unified_syntax)
13734 {
3c707909 13735 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13736 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13737 }
13738 else
13739 {
13740 inst.error = _("invalid register list to push/pop instruction");
13741 return;
c19d1205 13742 }
4b5a202f
AV
13743}
13744
13745static void
13746do_t_clrm (void)
13747{
13748 if (unified_syntax)
13749 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13750 else
13751 {
13752 inst.error = _("invalid register list to push/pop instruction");
13753 return;
13754 }
c19d1205 13755}
b99bd4ef 13756
efd6b359
AV
13757static void
13758do_t_vscclrm (void)
13759{
13760 if (inst.operands[0].issingle)
13761 {
13762 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13763 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13764 inst.instruction |= inst.operands[0].imm;
13765 }
13766 else
13767 {
13768 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13769 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13770 inst.instruction |= 1 << 8;
13771 inst.instruction |= inst.operands[0].imm << 1;
13772 }
13773}
13774
c19d1205
ZW
13775static void
13776do_t_rbit (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 inst.instruction |= Rd << 8;
13787 inst.instruction |= Rm << 16;
13788 inst.instruction |= Rm;
c19d1205 13789}
b99bd4ef 13790
c19d1205
ZW
13791static void
13792do_t_rev (void)
13793{
fdfde340
JM
13794 unsigned Rd, Rm;
13795
13796 Rd = inst.operands[0].reg;
13797 Rm = inst.operands[1].reg;
13798
13799 reject_bad_reg (Rd);
13800 reject_bad_reg (Rm);
13801
13802 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13803 && inst.size_req != 4)
13804 {
13805 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13806 inst.instruction |= Rd;
13807 inst.instruction |= Rm << 3;
c19d1205
ZW
13808 }
13809 else if (unified_syntax)
13810 {
13811 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13812 inst.instruction |= Rd << 8;
13813 inst.instruction |= Rm << 16;
13814 inst.instruction |= Rm;
c19d1205
ZW
13815 }
13816 else
13817 inst.error = BAD_HIREG;
13818}
b99bd4ef 13819
1c444d06
JM
13820static void
13821do_t_rrx (void)
13822{
13823 unsigned Rd, Rm;
13824
13825 Rd = inst.operands[0].reg;
13826 Rm = inst.operands[1].reg;
13827
fdfde340
JM
13828 reject_bad_reg (Rd);
13829 reject_bad_reg (Rm);
c921be7d 13830
1c444d06
JM
13831 inst.instruction |= Rd << 8;
13832 inst.instruction |= Rm;
13833}
13834
c19d1205
ZW
13835static void
13836do_t_rsb (void)
13837{
fdfde340 13838 unsigned Rd, Rs;
b99bd4ef 13839
c19d1205
ZW
13840 Rd = inst.operands[0].reg;
13841 Rs = (inst.operands[1].present
13842 ? inst.operands[1].reg /* Rd, Rs, foo */
13843 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13844
fdfde340
JM
13845 reject_bad_reg (Rd);
13846 reject_bad_reg (Rs);
13847 if (inst.operands[2].isreg)
13848 reject_bad_reg (inst.operands[2].reg);
13849
c19d1205
ZW
13850 inst.instruction |= Rd << 8;
13851 inst.instruction |= Rs << 16;
13852 if (!inst.operands[2].isreg)
13853 {
026d3abb
PB
13854 bfd_boolean narrow;
13855
13856 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13857 narrow = !in_pred_block ();
026d3abb 13858 else
5ee91343 13859 narrow = in_pred_block ();
026d3abb
PB
13860
13861 if (Rd > 7 || Rs > 7)
13862 narrow = FALSE;
13863
13864 if (inst.size_req == 4 || !unified_syntax)
13865 narrow = FALSE;
13866
e2b0ab59
AV
13867 if (inst.relocs[0].exp.X_op != O_constant
13868 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13869 narrow = FALSE;
13870
13871 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13872 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13873 if (narrow)
13874 {
e2b0ab59 13875 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13876 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13877 inst.instruction |= Rs << 3;
13878 inst.instruction |= Rd;
13879 }
13880 else
13881 {
13882 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13883 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13884 }
c19d1205
ZW
13885 }
13886 else
13887 encode_thumb32_shifted_operand (2);
13888}
b99bd4ef 13889
c19d1205
ZW
13890static void
13891do_t_setend (void)
13892{
12e37cbc
MGD
13893 if (warn_on_deprecated
13894 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13895 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13896
5ee91343 13897 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13898 if (inst.operands[0].imm)
13899 inst.instruction |= 0x8;
13900}
b99bd4ef 13901
c19d1205
ZW
13902static void
13903do_t_shift (void)
13904{
13905 if (!inst.operands[1].present)
13906 inst.operands[1].reg = inst.operands[0].reg;
13907
13908 if (unified_syntax)
13909 {
3d388997
PB
13910 bfd_boolean narrow;
13911 int shift_kind;
13912
13913 switch (inst.instruction)
13914 {
13915 case T_MNEM_asr:
13916 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13917 case T_MNEM_lsl:
13918 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13919 case T_MNEM_lsr:
13920 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13921 case T_MNEM_ror:
13922 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13923 default: abort ();
13924 }
13925
13926 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13927 narrow = !in_pred_block ();
3d388997 13928 else
5ee91343 13929 narrow = in_pred_block ();
3d388997
PB
13930 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13931 narrow = FALSE;
13932 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13933 narrow = FALSE;
13934 if (inst.operands[2].isreg
13935 && (inst.operands[1].reg != inst.operands[0].reg
13936 || inst.operands[2].reg > 7))
13937 narrow = FALSE;
13938 if (inst.size_req == 4)
13939 narrow = FALSE;
13940
fdfde340
JM
13941 reject_bad_reg (inst.operands[0].reg);
13942 reject_bad_reg (inst.operands[1].reg);
c921be7d 13943
3d388997 13944 if (!narrow)
c19d1205
ZW
13945 {
13946 if (inst.operands[2].isreg)
b99bd4ef 13947 {
fdfde340 13948 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13949 inst.instruction = THUMB_OP32 (inst.instruction);
13950 inst.instruction |= inst.operands[0].reg << 8;
13951 inst.instruction |= inst.operands[1].reg << 16;
13952 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13953
13954 /* PR 12854: Error on extraneous shifts. */
13955 constraint (inst.operands[2].shifted,
13956 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13957 }
13958 else
13959 {
13960 inst.operands[1].shifted = 1;
3d388997 13961 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13962 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13963 ? T_MNEM_movs : T_MNEM_mov);
13964 inst.instruction |= inst.operands[0].reg << 8;
13965 encode_thumb32_shifted_operand (1);
13966 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13967 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13968 }
13969 }
13970 else
13971 {
c19d1205 13972 if (inst.operands[2].isreg)
b99bd4ef 13973 {
3d388997 13974 switch (shift_kind)
b99bd4ef 13975 {
3d388997
PB
13976 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13977 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13978 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13979 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13980 default: abort ();
b99bd4ef 13981 }
5f4273c7 13982
c19d1205
ZW
13983 inst.instruction |= inst.operands[0].reg;
13984 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13985
13986 /* PR 12854: Error on extraneous shifts. */
13987 constraint (inst.operands[2].shifted,
13988 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13989 }
13990 else
13991 {
3d388997 13992 switch (shift_kind)
b99bd4ef 13993 {
3d388997
PB
13994 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13995 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13996 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13997 default: abort ();
b99bd4ef 13998 }
e2b0ab59 13999 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14000 inst.instruction |= inst.operands[0].reg;
14001 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14002 }
14003 }
c19d1205
ZW
14004 }
14005 else
14006 {
14007 constraint (inst.operands[0].reg > 7
14008 || inst.operands[1].reg > 7, BAD_HIREG);
14009 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 14010
c19d1205
ZW
14011 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14012 {
14013 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14014 constraint (inst.operands[0].reg != inst.operands[1].reg,
14015 _("source1 and dest must be same register"));
b99bd4ef 14016
c19d1205
ZW
14017 switch (inst.instruction)
14018 {
14019 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14020 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14021 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14022 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14023 default: abort ();
14024 }
5f4273c7 14025
c19d1205
ZW
14026 inst.instruction |= inst.operands[0].reg;
14027 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
14028
14029 /* PR 12854: Error on extraneous shifts. */
14030 constraint (inst.operands[2].shifted,
14031 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
14032 }
14033 else
b99bd4ef 14034 {
c19d1205
ZW
14035 switch (inst.instruction)
14036 {
14037 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14038 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14039 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14040 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14041 default: abort ();
14042 }
e2b0ab59 14043 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14044 inst.instruction |= inst.operands[0].reg;
14045 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14046 }
14047 }
b99bd4ef
NC
14048}
14049
14050static void
c19d1205 14051do_t_simd (void)
b99bd4ef 14052{
fdfde340
JM
14053 unsigned Rd, Rn, Rm;
14054
14055 Rd = inst.operands[0].reg;
14056 Rn = inst.operands[1].reg;
14057 Rm = inst.operands[2].reg;
14058
14059 reject_bad_reg (Rd);
14060 reject_bad_reg (Rn);
14061 reject_bad_reg (Rm);
14062
14063 inst.instruction |= Rd << 8;
14064 inst.instruction |= Rn << 16;
14065 inst.instruction |= Rm;
c19d1205 14066}
b99bd4ef 14067
03ee1b7f
NC
14068static void
14069do_t_simd2 (void)
14070{
14071 unsigned Rd, Rn, Rm;
14072
14073 Rd = inst.operands[0].reg;
14074 Rm = inst.operands[1].reg;
14075 Rn = inst.operands[2].reg;
14076
14077 reject_bad_reg (Rd);
14078 reject_bad_reg (Rn);
14079 reject_bad_reg (Rm);
14080
14081 inst.instruction |= Rd << 8;
14082 inst.instruction |= Rn << 16;
14083 inst.instruction |= Rm;
14084}
14085
c19d1205 14086static void
3eb17e6b 14087do_t_smc (void)
c19d1205 14088{
e2b0ab59 14089 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
14090 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14091 _("SMC is not permitted on this architecture"));
e2b0ab59 14092 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14093 _("expression too complex"));
ba85f98c
BW
14094 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14095
e2b0ab59 14096 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 14097 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 14098
24382199 14099 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 14100 set_pred_insn_type_last ();
c19d1205 14101}
b99bd4ef 14102
90ec0d68
MGD
14103static void
14104do_t_hvc (void)
14105{
e2b0ab59 14106 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 14107
e2b0ab59 14108 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
14109 inst.instruction |= (value & 0x0fff);
14110 inst.instruction |= (value & 0xf000) << 4;
14111}
14112
c19d1205 14113static void
3a21c15a 14114do_t_ssat_usat (int bias)
c19d1205 14115{
fdfde340
JM
14116 unsigned Rd, Rn;
14117
14118 Rd = inst.operands[0].reg;
14119 Rn = inst.operands[2].reg;
14120
14121 reject_bad_reg (Rd);
14122 reject_bad_reg (Rn);
14123
14124 inst.instruction |= Rd << 8;
3a21c15a 14125 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 14126 inst.instruction |= Rn << 16;
b99bd4ef 14127
c19d1205 14128 if (inst.operands[3].present)
b99bd4ef 14129 {
e2b0ab59 14130 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 14131
e2b0ab59 14132 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 14133
e2b0ab59 14134 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14135 _("expression too complex"));
b99bd4ef 14136
3a21c15a 14137 if (shift_amount != 0)
6189168b 14138 {
3a21c15a
NC
14139 constraint (shift_amount > 31,
14140 _("shift expression is too large"));
14141
c19d1205 14142 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
14143 inst.instruction |= 0x00200000; /* sh bit. */
14144
14145 inst.instruction |= (shift_amount & 0x1c) << 10;
14146 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14147 }
14148 }
b99bd4ef 14149}
c921be7d 14150
3a21c15a
NC
14151static void
14152do_t_ssat (void)
14153{
14154 do_t_ssat_usat (1);
14155}
b99bd4ef 14156
0dd132b6 14157static void
c19d1205 14158do_t_ssat16 (void)
0dd132b6 14159{
fdfde340
JM
14160 unsigned Rd, Rn;
14161
14162 Rd = inst.operands[0].reg;
14163 Rn = inst.operands[2].reg;
14164
14165 reject_bad_reg (Rd);
14166 reject_bad_reg (Rn);
14167
14168 inst.instruction |= Rd << 8;
c19d1205 14169 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14170 inst.instruction |= Rn << 16;
c19d1205 14171}
0dd132b6 14172
c19d1205
ZW
14173static void
14174do_t_strex (void)
14175{
14176 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14177 || inst.operands[2].postind || inst.operands[2].writeback
14178 || inst.operands[2].immisreg || inst.operands[2].shifted
14179 || inst.operands[2].negative,
01cfc07f 14180 BAD_ADDR_MODE);
0dd132b6 14181
5be8be5d
DG
14182 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14183
c19d1205
ZW
14184 inst.instruction |= inst.operands[0].reg << 8;
14185 inst.instruction |= inst.operands[1].reg << 12;
14186 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14187 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14188}
14189
b99bd4ef 14190static void
c19d1205 14191do_t_strexd (void)
b99bd4ef 14192{
c19d1205
ZW
14193 if (!inst.operands[2].present)
14194 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14195
c19d1205
ZW
14196 constraint (inst.operands[0].reg == inst.operands[1].reg
14197 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14198 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14199 BAD_OVERLAP);
b99bd4ef 14200
c19d1205
ZW
14201 inst.instruction |= inst.operands[0].reg;
14202 inst.instruction |= inst.operands[1].reg << 12;
14203 inst.instruction |= inst.operands[2].reg << 8;
14204 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14205}
14206
14207static void
c19d1205 14208do_t_sxtah (void)
b99bd4ef 14209{
fdfde340
JM
14210 unsigned Rd, Rn, Rm;
14211
14212 Rd = inst.operands[0].reg;
14213 Rn = inst.operands[1].reg;
14214 Rm = inst.operands[2].reg;
14215
14216 reject_bad_reg (Rd);
14217 reject_bad_reg (Rn);
14218 reject_bad_reg (Rm);
14219
14220 inst.instruction |= Rd << 8;
14221 inst.instruction |= Rn << 16;
14222 inst.instruction |= Rm;
c19d1205
ZW
14223 inst.instruction |= inst.operands[3].imm << 4;
14224}
b99bd4ef 14225
c19d1205
ZW
14226static void
14227do_t_sxth (void)
14228{
fdfde340
JM
14229 unsigned Rd, Rm;
14230
14231 Rd = inst.operands[0].reg;
14232 Rm = inst.operands[1].reg;
14233
14234 reject_bad_reg (Rd);
14235 reject_bad_reg (Rm);
c921be7d
NC
14236
14237 if (inst.instruction <= 0xffff
14238 && inst.size_req != 4
fdfde340 14239 && Rd <= 7 && Rm <= 7
c19d1205 14240 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14241 {
c19d1205 14242 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14243 inst.instruction |= Rd;
14244 inst.instruction |= Rm << 3;
b99bd4ef 14245 }
c19d1205 14246 else if (unified_syntax)
b99bd4ef 14247 {
c19d1205
ZW
14248 if (inst.instruction <= 0xffff)
14249 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14250 inst.instruction |= Rd << 8;
14251 inst.instruction |= Rm;
c19d1205 14252 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14253 }
c19d1205 14254 else
b99bd4ef 14255 {
c19d1205
ZW
14256 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14257 _("Thumb encoding does not support rotation"));
14258 constraint (1, BAD_HIREG);
b99bd4ef 14259 }
c19d1205 14260}
b99bd4ef 14261
c19d1205
ZW
14262static void
14263do_t_swi (void)
14264{
e2b0ab59 14265 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14266}
b99bd4ef 14267
92e90b6e
PB
14268static void
14269do_t_tb (void)
14270{
fdfde340 14271 unsigned Rn, Rm;
92e90b6e
PB
14272 int half;
14273
14274 half = (inst.instruction & 0x10) != 0;
5ee91343 14275 set_pred_insn_type_last ();
dfa9f0d5
PB
14276 constraint (inst.operands[0].immisreg,
14277 _("instruction requires register index"));
fdfde340
JM
14278
14279 Rn = inst.operands[0].reg;
14280 Rm = inst.operands[0].imm;
c921be7d 14281
5c8ed6a4
JW
14282 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14283 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14284 reject_bad_reg (Rm);
14285
92e90b6e
PB
14286 constraint (!half && inst.operands[0].shifted,
14287 _("instruction does not allow shifted index"));
fdfde340 14288 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14289}
14290
74db7efb
NC
14291static void
14292do_t_udf (void)
14293{
14294 if (!inst.operands[0].present)
14295 inst.operands[0].imm = 0;
14296
14297 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14298 {
14299 constraint (inst.size_req == 2,
14300 _("immediate value out of range"));
14301 inst.instruction = THUMB_OP32 (inst.instruction);
14302 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14303 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14304 }
14305 else
14306 {
14307 inst.instruction = THUMB_OP16 (inst.instruction);
14308 inst.instruction |= inst.operands[0].imm;
14309 }
14310
5ee91343 14311 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14312}
14313
14314
c19d1205
ZW
14315static void
14316do_t_usat (void)
14317{
3a21c15a 14318 do_t_ssat_usat (0);
b99bd4ef
NC
14319}
14320
14321static void
c19d1205 14322do_t_usat16 (void)
b99bd4ef 14323{
fdfde340
JM
14324 unsigned Rd, Rn;
14325
14326 Rd = inst.operands[0].reg;
14327 Rn = inst.operands[2].reg;
14328
14329 reject_bad_reg (Rd);
14330 reject_bad_reg (Rn);
14331
14332 inst.instruction |= Rd << 8;
c19d1205 14333 inst.instruction |= inst.operands[1].imm;
fdfde340 14334 inst.instruction |= Rn << 16;
b99bd4ef 14335}
c19d1205 14336
e12437dc
AV
14337/* Checking the range of the branch offset (VAL) with NBITS bits
14338 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14339static int
14340v8_1_branch_value_check (int val, int nbits, int is_signed)
14341{
14342 gas_assert (nbits > 0 && nbits <= 32);
14343 if (is_signed)
14344 {
14345 int cmp = (1 << (nbits - 1));
14346 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14347 return FAIL;
14348 }
14349 else
14350 {
14351 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14352 return FAIL;
14353 }
14354 return SUCCESS;
14355}
14356
4389b29a
AV
14357/* For branches in Armv8.1-M Mainline. */
14358static void
14359do_t_branch_future (void)
14360{
14361 unsigned long insn = inst.instruction;
14362
14363 inst.instruction = THUMB_OP32 (inst.instruction);
14364 if (inst.operands[0].hasreloc == 0)
14365 {
14366 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14367 as_bad (BAD_BRANCH_OFF);
14368
14369 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14370 }
14371 else
14372 {
14373 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14374 inst.relocs[0].pc_rel = 1;
14375 }
14376
14377 switch (insn)
14378 {
14379 case T_MNEM_bf:
14380 if (inst.operands[1].hasreloc == 0)
14381 {
14382 int val = inst.operands[1].imm;
14383 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14384 as_bad (BAD_BRANCH_OFF);
14385
14386 int immA = (val & 0x0001f000) >> 12;
14387 int immB = (val & 0x00000ffc) >> 2;
14388 int immC = (val & 0x00000002) >> 1;
14389 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14390 }
14391 else
14392 {
14393 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14394 inst.relocs[1].pc_rel = 1;
14395 }
14396 break;
14397
65d1bc05
AV
14398 case T_MNEM_bfl:
14399 if (inst.operands[1].hasreloc == 0)
14400 {
14401 int val = inst.operands[1].imm;
14402 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14403 as_bad (BAD_BRANCH_OFF);
14404
14405 int immA = (val & 0x0007f000) >> 12;
14406 int immB = (val & 0x00000ffc) >> 2;
14407 int immC = (val & 0x00000002) >> 1;
14408 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14409 }
14410 else
14411 {
14412 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14413 inst.relocs[1].pc_rel = 1;
14414 }
14415 break;
14416
f6b2b12d
AV
14417 case T_MNEM_bfcsel:
14418 /* Operand 1. */
14419 if (inst.operands[1].hasreloc == 0)
14420 {
14421 int val = inst.operands[1].imm;
14422 int immA = (val & 0x00001000) >> 12;
14423 int immB = (val & 0x00000ffc) >> 2;
14424 int immC = (val & 0x00000002) >> 1;
14425 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14426 }
14427 else
14428 {
14429 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14430 inst.relocs[1].pc_rel = 1;
14431 }
14432
14433 /* Operand 2. */
14434 if (inst.operands[2].hasreloc == 0)
14435 {
14436 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14437 int val2 = inst.operands[2].imm;
14438 int val0 = inst.operands[0].imm & 0x1f;
14439 int diff = val2 - val0;
14440 if (diff == 4)
14441 inst.instruction |= 1 << 17; /* T bit. */
14442 else if (diff != 2)
14443 as_bad (_("out of range label-relative fixup value"));
14444 }
14445 else
14446 {
14447 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14448 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14449 inst.relocs[2].pc_rel = 1;
14450 }
14451
14452 /* Operand 3. */
14453 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14454 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14455 break;
14456
f1c7f421
AV
14457 case T_MNEM_bfx:
14458 case T_MNEM_bflx:
14459 inst.instruction |= inst.operands[1].reg << 16;
14460 break;
14461
4389b29a
AV
14462 default: abort ();
14463 }
14464}
14465
60f993ce
AV
14466/* Helper function for do_t_loloop to handle relocations. */
14467static void
14468v8_1_loop_reloc (int is_le)
14469{
14470 if (inst.relocs[0].exp.X_op == O_constant)
14471 {
14472 int value = inst.relocs[0].exp.X_add_number;
14473 value = (is_le) ? -value : value;
14474
14475 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14476 as_bad (BAD_BRANCH_OFF);
14477
14478 int imml, immh;
14479
14480 immh = (value & 0x00000ffc) >> 2;
14481 imml = (value & 0x00000002) >> 1;
14482
14483 inst.instruction |= (imml << 11) | (immh << 1);
14484 }
14485 else
14486 {
14487 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14488 inst.relocs[0].pc_rel = 1;
14489 }
14490}
14491
08132bdd
SP
14492/* For shifts with four operands in MVE. */
14493static void
14494do_mve_scalar_shift1 (void)
14495{
14496 unsigned int value = inst.operands[2].imm;
14497
14498 inst.instruction |= inst.operands[0].reg << 16;
14499 inst.instruction |= inst.operands[1].reg << 8;
14500
14501 /* Setting the bit for saturation. */
14502 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14503
14504 /* Assuming Rm is already checked not to be 11x1. */
14505 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14506 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14507 inst.instruction |= inst.operands[3].reg << 12;
14508}
14509
23d00a41
SD
14510/* For shifts in MVE. */
14511static void
14512do_mve_scalar_shift (void)
14513{
14514 if (!inst.operands[2].present)
14515 {
14516 inst.operands[2] = inst.operands[1];
14517 inst.operands[1].reg = 0xf;
14518 }
14519
14520 inst.instruction |= inst.operands[0].reg << 16;
14521 inst.instruction |= inst.operands[1].reg << 8;
14522
14523 if (inst.operands[2].isreg)
14524 {
14525 /* Assuming Rm is already checked not to be 11x1. */
14526 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14527 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14528 inst.instruction |= inst.operands[2].reg << 12;
14529 }
14530 else
14531 {
14532 /* Assuming imm is already checked as [1,32]. */
14533 unsigned int value = inst.operands[2].imm;
14534 inst.instruction |= (value & 0x1c) << 10;
14535 inst.instruction |= (value & 0x03) << 6;
14536 /* Change last 4 bits from 0xd to 0xf. */
14537 inst.instruction |= 0x2;
14538 }
14539}
14540
a302e574
AV
14541/* MVE instruction encoder helpers. */
14542#define M_MNEM_vabav 0xee800f01
14543#define M_MNEM_vmladav 0xeef00e00
14544#define M_MNEM_vmladava 0xeef00e20
14545#define M_MNEM_vmladavx 0xeef01e00
14546#define M_MNEM_vmladavax 0xeef01e20
14547#define M_MNEM_vmlsdav 0xeef00e01
14548#define M_MNEM_vmlsdava 0xeef00e21
14549#define M_MNEM_vmlsdavx 0xeef01e01
14550#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14551#define M_MNEM_vmullt 0xee011e00
14552#define M_MNEM_vmullb 0xee010e00
efd0b310 14553#define M_MNEM_vctp 0xf000e801
35c228db
AV
14554#define M_MNEM_vst20 0xfc801e00
14555#define M_MNEM_vst21 0xfc801e20
14556#define M_MNEM_vst40 0xfc801e01
14557#define M_MNEM_vst41 0xfc801e21
14558#define M_MNEM_vst42 0xfc801e41
14559#define M_MNEM_vst43 0xfc801e61
14560#define M_MNEM_vld20 0xfc901e00
14561#define M_MNEM_vld21 0xfc901e20
14562#define M_MNEM_vld40 0xfc901e01
14563#define M_MNEM_vld41 0xfc901e21
14564#define M_MNEM_vld42 0xfc901e41
14565#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14566#define M_MNEM_vstrb 0xec000e00
14567#define M_MNEM_vstrh 0xec000e10
14568#define M_MNEM_vstrw 0xec000e40
14569#define M_MNEM_vstrd 0xec000e50
14570#define M_MNEM_vldrb 0xec100e00
14571#define M_MNEM_vldrh 0xec100e10
14572#define M_MNEM_vldrw 0xec100e40
14573#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14574#define M_MNEM_vmovlt 0xeea01f40
14575#define M_MNEM_vmovlb 0xeea00f40
14576#define M_MNEM_vmovnt 0xfe311e81
14577#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14578#define M_MNEM_vadc 0xee300f00
14579#define M_MNEM_vadci 0xee301f00
14580#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14581#define M_MNEM_vaddlv 0xee890f00
14582#define M_MNEM_vaddlva 0xee890f20
14583#define M_MNEM_vaddv 0xeef10f00
14584#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14585#define M_MNEM_vddup 0xee011f6e
14586#define M_MNEM_vdwdup 0xee011f60
14587#define M_MNEM_vidup 0xee010f6e
14588#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14589#define M_MNEM_vmaxv 0xeee20f00
14590#define M_MNEM_vmaxav 0xeee00f00
14591#define M_MNEM_vminv 0xeee20f80
14592#define M_MNEM_vminav 0xeee00f80
93925576
AV
14593#define M_MNEM_vmlaldav 0xee800e00
14594#define M_MNEM_vmlaldava 0xee800e20
14595#define M_MNEM_vmlaldavx 0xee801e00
14596#define M_MNEM_vmlaldavax 0xee801e20
14597#define M_MNEM_vmlsldav 0xee800e01
14598#define M_MNEM_vmlsldava 0xee800e21
14599#define M_MNEM_vmlsldavx 0xee801e01
14600#define M_MNEM_vmlsldavax 0xee801e21
14601#define M_MNEM_vrmlaldavhx 0xee801f00
14602#define M_MNEM_vrmlaldavhax 0xee801f20
14603#define M_MNEM_vrmlsldavh 0xfe800e01
14604#define M_MNEM_vrmlsldavha 0xfe800e21
14605#define M_MNEM_vrmlsldavhx 0xfe801e01
14606#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14607#define M_MNEM_vqmovnt 0xee331e01
14608#define M_MNEM_vqmovnb 0xee330e01
14609#define M_MNEM_vqmovunt 0xee311e81
14610#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14611#define M_MNEM_vshrnt 0xee801fc1
14612#define M_MNEM_vshrnb 0xee800fc1
14613#define M_MNEM_vrshrnt 0xfe801fc1
14614#define M_MNEM_vqshrnt 0xee801f40
14615#define M_MNEM_vqshrnb 0xee800f40
14616#define M_MNEM_vqshrunt 0xee801fc0
14617#define M_MNEM_vqshrunb 0xee800fc0
14618#define M_MNEM_vrshrnb 0xfe800fc1
14619#define M_MNEM_vqrshrnt 0xee801f41
14620#define M_MNEM_vqrshrnb 0xee800f41
14621#define M_MNEM_vqrshrunt 0xfe801fc0
14622#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14623
aab2c27d
MM
14624/* Bfloat16 instruction encoder helpers. */
14625#define B_MNEM_vfmat 0xfc300850
14626#define B_MNEM_vfmab 0xfc300810
14627
5287ad62 14628/* Neon instruction encoder helpers. */
5f4273c7 14629
5287ad62 14630/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14631
5287ad62
JB
14632/* An "invalid" code for the following tables. */
14633#define N_INV -1u
14634
14635struct neon_tab_entry
b99bd4ef 14636{
5287ad62
JB
14637 unsigned integer;
14638 unsigned float_or_poly;
14639 unsigned scalar_or_imm;
14640};
5f4273c7 14641
5287ad62
JB
14642/* Map overloaded Neon opcodes to their respective encodings. */
14643#define NEON_ENC_TAB \
14644 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14645 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14646 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14647 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14648 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14649 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14650 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14651 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14652 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14653 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14654 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14655 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14656 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14657 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14658 /* Register variants of the following two instructions are encoded as
e07e6e58 14659 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14660 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14661 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14662 X(vfma, N_INV, 0x0000c10, N_INV), \
14663 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14664 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14665 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14666 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14667 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14668 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14669 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14670 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14671 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14672 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14673 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14674 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14675 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14676 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14677 X(vshl, 0x0000400, N_INV, 0x0800510), \
14678 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14679 X(vand, 0x0000110, N_INV, 0x0800030), \
14680 X(vbic, 0x0100110, N_INV, 0x0800030), \
14681 X(veor, 0x1000110, N_INV, N_INV), \
14682 X(vorn, 0x0300110, N_INV, 0x0800010), \
14683 X(vorr, 0x0200110, N_INV, 0x0800010), \
14684 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14685 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14686 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14687 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14688 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14689 X(vst1, 0x0000000, 0x0800000, N_INV), \
14690 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14691 X(vst2, 0x0000100, 0x0800100, N_INV), \
14692 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14693 X(vst3, 0x0000200, 0x0800200, N_INV), \
14694 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14695 X(vst4, 0x0000300, 0x0800300, N_INV), \
14696 X(vmovn, 0x1b20200, N_INV, N_INV), \
14697 X(vtrn, 0x1b20080, N_INV, N_INV), \
14698 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14699 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14700 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14701 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14702 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14703 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14704 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14705 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14706 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14707 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14708 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14709 X(vseleq, 0xe000a00, N_INV, N_INV), \
14710 X(vselvs, 0xe100a00, N_INV, N_INV), \
14711 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14712 X(vselgt, 0xe300a00, N_INV, N_INV), \
14713 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14714 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14715 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14716 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14717 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14718 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14719 X(sha3op, 0x2000c00, N_INV, N_INV), \
14720 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14721 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14722
14723enum neon_opc
14724{
14725#define X(OPC,I,F,S) N_MNEM_##OPC
14726NEON_ENC_TAB
14727#undef X
14728};
b99bd4ef 14729
5287ad62
JB
14730static const struct neon_tab_entry neon_enc_tab[] =
14731{
14732#define X(OPC,I,F,S) { (I), (F), (S) }
14733NEON_ENC_TAB
14734#undef X
14735};
b99bd4ef 14736
88714cb8
DG
14737/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14738#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14739#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14740#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14741#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14742#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14743#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14744#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14745#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14746#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14747#define NEON_ENC_SINGLE_(X) \
037e8744 14748 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14749#define NEON_ENC_DOUBLE_(X) \
037e8744 14750 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14751#define NEON_ENC_FPV8_(X) \
14752 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14753
88714cb8
DG
14754#define NEON_ENCODE(type, inst) \
14755 do \
14756 { \
14757 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14758 inst.is_neon = 1; \
14759 } \
14760 while (0)
14761
14762#define check_neon_suffixes \
14763 do \
14764 { \
14765 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14766 { \
14767 as_bad (_("invalid neon suffix for non neon instruction")); \
14768 return; \
14769 } \
14770 } \
14771 while (0)
14772
037e8744
JB
14773/* Define shapes for instruction operands. The following mnemonic characters
14774 are used in this table:
5287ad62 14775
037e8744 14776 F - VFP S<n> register
5287ad62
JB
14777 D - Neon D<n> register
14778 Q - Neon Q<n> register
14779 I - Immediate
14780 S - Scalar
14781 R - ARM register
14782 L - D<n> register list
5f4273c7 14783
037e8744
JB
14784 This table is used to generate various data:
14785 - enumerations of the form NS_DDR to be used as arguments to
14786 neon_select_shape.
14787 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14788 - a table used to drive neon_select_shape. */
b99bd4ef 14789
037e8744 14790#define NEON_SHAPE_DEF \
93925576 14791 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14792 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14793 X(4, (R, R, S, S), QUAD), \
14794 X(4, (S, S, R, R), QUAD), \
b409bdb6 14795 X(3, (Q, R, I), QUAD), \
1b883319
AV
14796 X(3, (I, Q, Q), QUAD), \
14797 X(3, (I, Q, R), QUAD), \
a302e574 14798 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14799 X(3, (D, D, D), DOUBLE), \
14800 X(3, (Q, Q, Q), QUAD), \
14801 X(3, (D, D, I), DOUBLE), \
14802 X(3, (Q, Q, I), QUAD), \
14803 X(3, (D, D, S), DOUBLE), \
14804 X(3, (Q, Q, S), QUAD), \
5ee91343 14805 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14806 X(3, (R, R, Q), QUAD), \
14807 X(2, (R, Q), QUAD), \
037e8744
JB
14808 X(2, (D, D), DOUBLE), \
14809 X(2, (Q, Q), QUAD), \
14810 X(2, (D, S), DOUBLE), \
14811 X(2, (Q, S), QUAD), \
14812 X(2, (D, R), DOUBLE), \
14813 X(2, (Q, R), QUAD), \
14814 X(2, (D, I), DOUBLE), \
14815 X(2, (Q, I), QUAD), \
5aae9ae9
MM
14816 X(3, (P, F, I), SINGLE), \
14817 X(3, (P, D, I), DOUBLE), \
14818 X(3, (P, Q, I), QUAD), \
14819 X(4, (P, F, F, I), SINGLE), \
14820 X(4, (P, D, D, I), DOUBLE), \
14821 X(4, (P, Q, Q, I), QUAD), \
14822 X(5, (P, F, F, F, I), SINGLE), \
14823 X(5, (P, D, D, D, I), DOUBLE), \
14824 X(5, (P, Q, Q, Q, I), QUAD), \
037e8744
JB
14825 X(3, (D, L, D), DOUBLE), \
14826 X(2, (D, Q), MIXED), \
14827 X(2, (Q, D), MIXED), \
14828 X(3, (D, Q, I), MIXED), \
14829 X(3, (Q, D, I), MIXED), \
14830 X(3, (Q, D, D), MIXED), \
14831 X(3, (D, Q, Q), MIXED), \
14832 X(3, (Q, Q, D), MIXED), \
14833 X(3, (Q, D, S), MIXED), \
14834 X(3, (D, Q, S), MIXED), \
14835 X(4, (D, D, D, I), DOUBLE), \
14836 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14837 X(4, (D, D, S, I), DOUBLE), \
14838 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14839 X(2, (F, F), SINGLE), \
14840 X(3, (F, F, F), SINGLE), \
14841 X(2, (F, I), SINGLE), \
14842 X(2, (F, D), MIXED), \
14843 X(2, (D, F), MIXED), \
14844 X(3, (F, F, I), MIXED), \
14845 X(4, (R, R, F, F), SINGLE), \
14846 X(4, (F, F, R, R), SINGLE), \
14847 X(3, (D, R, R), DOUBLE), \
14848 X(3, (R, R, D), DOUBLE), \
14849 X(2, (S, R), SINGLE), \
14850 X(2, (R, S), SINGLE), \
14851 X(2, (F, R), SINGLE), \
d54af2d0 14852 X(2, (R, F), SINGLE), \
1f6234a3
AV
14853/* Used for MVE tail predicated loop instructions. */\
14854 X(2, (R, R), QUAD), \
d54af2d0
RL
14855/* Half float shape supported so far. */\
14856 X (2, (H, D), MIXED), \
14857 X (2, (D, H), MIXED), \
14858 X (2, (H, F), MIXED), \
14859 X (2, (F, H), MIXED), \
14860 X (2, (H, H), HALF), \
14861 X (2, (H, R), HALF), \
14862 X (2, (R, H), HALF), \
14863 X (2, (H, I), HALF), \
14864 X (3, (H, H, H), HALF), \
14865 X (3, (H, F, I), MIXED), \
dec41383
JW
14866 X (3, (F, H, I), MIXED), \
14867 X (3, (D, H, H), MIXED), \
14868 X (3, (D, H, S), MIXED)
037e8744
JB
14869
14870#define S2(A,B) NS_##A##B
14871#define S3(A,B,C) NS_##A##B##C
14872#define S4(A,B,C,D) NS_##A##B##C##D
5aae9ae9 14873#define S5(A,B,C,D,E) NS_##A##B##C##D##E
037e8744
JB
14874
14875#define X(N, L, C) S##N L
14876
5287ad62
JB
14877enum neon_shape
14878{
037e8744
JB
14879 NEON_SHAPE_DEF,
14880 NS_NULL
5287ad62 14881};
b99bd4ef 14882
037e8744
JB
14883#undef X
14884#undef S2
14885#undef S3
14886#undef S4
5aae9ae9 14887#undef S5
037e8744
JB
14888
14889enum neon_shape_class
14890{
d54af2d0 14891 SC_HALF,
037e8744
JB
14892 SC_SINGLE,
14893 SC_DOUBLE,
14894 SC_QUAD,
14895 SC_MIXED
14896};
14897
14898#define X(N, L, C) SC_##C
14899
14900static enum neon_shape_class neon_shape_class[] =
14901{
14902 NEON_SHAPE_DEF
14903};
14904
14905#undef X
14906
14907enum neon_shape_el
14908{
d54af2d0 14909 SE_H,
037e8744
JB
14910 SE_F,
14911 SE_D,
14912 SE_Q,
14913 SE_I,
14914 SE_S,
14915 SE_R,
5aae9ae9
MM
14916 SE_L,
14917 SE_P
037e8744
JB
14918};
14919
14920/* Register widths of above. */
14921static unsigned neon_shape_el_size[] =
14922{
d54af2d0 14923 16,
037e8744
JB
14924 32,
14925 64,
14926 128,
14927 0,
14928 32,
14929 32,
5aae9ae9 14930 0,
037e8744
JB
14931 0
14932};
14933
14934struct neon_shape_info
14935{
14936 unsigned els;
14937 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14938};
14939
14940#define S2(A,B) { SE_##A, SE_##B }
14941#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14942#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
5aae9ae9 14943#define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
037e8744
JB
14944
14945#define X(N, L, C) { N, S##N L }
14946
14947static struct neon_shape_info neon_shape_tab[] =
14948{
14949 NEON_SHAPE_DEF
14950};
14951
14952#undef X
14953#undef S2
14954#undef S3
14955#undef S4
5aae9ae9 14956#undef S5
037e8744 14957
5287ad62
JB
14958/* Bit masks used in type checking given instructions.
14959 'N_EQK' means the type must be the same as (or based on in some way) the key
14960 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14961 set, various other bits can be set as well in order to modify the meaning of
14962 the type constraint. */
14963
14964enum neon_type_mask
14965{
8e79c3df
CM
14966 N_S8 = 0x0000001,
14967 N_S16 = 0x0000002,
14968 N_S32 = 0x0000004,
14969 N_S64 = 0x0000008,
14970 N_U8 = 0x0000010,
14971 N_U16 = 0x0000020,
14972 N_U32 = 0x0000040,
14973 N_U64 = 0x0000080,
14974 N_I8 = 0x0000100,
14975 N_I16 = 0x0000200,
14976 N_I32 = 0x0000400,
14977 N_I64 = 0x0000800,
14978 N_8 = 0x0001000,
14979 N_16 = 0x0002000,
14980 N_32 = 0x0004000,
14981 N_64 = 0x0008000,
14982 N_P8 = 0x0010000,
14983 N_P16 = 0x0020000,
14984 N_F16 = 0x0040000,
14985 N_F32 = 0x0080000,
14986 N_F64 = 0x0100000,
4f51b4bd 14987 N_P64 = 0x0200000,
aab2c27d 14988 N_BF16 = 0x0400000,
c921be7d
NC
14989 N_KEY = 0x1000000, /* Key element (main type specifier). */
14990 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14991 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14992 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14993 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14994 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14995 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14996 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14997 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14998 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14999 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 15000 N_UTYP = 0,
4f51b4bd 15001 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
15002};
15003
dcbf9037
JB
15004#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15005
5287ad62
JB
15006#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15007#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15008#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
15009#define N_S_32 (N_S8 | N_S16 | N_S32)
15010#define N_F_16_32 (N_F16 | N_F32)
15011#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 15012#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 15013#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 15014#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
15015#define N_I_MVE (N_I8 | N_I16 | N_I32)
15016#define N_F_MVE (N_F16 | N_F32)
15017#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
15018
15019/* Pass this as the first type argument to neon_check_type to ignore types
15020 altogether. */
15021#define N_IGNORE_TYPE (N_KEY | N_EQK)
15022
037e8744
JB
15023/* Select a "shape" for the current instruction (describing register types or
15024 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15025 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15026 function of operand parsing, so this function doesn't need to be called.
15027 Shapes should be listed in order of decreasing length. */
5287ad62
JB
15028
15029static enum neon_shape
037e8744 15030neon_select_shape (enum neon_shape shape, ...)
5287ad62 15031{
037e8744
JB
15032 va_list ap;
15033 enum neon_shape first_shape = shape;
5287ad62
JB
15034
15035 /* Fix missing optional operands. FIXME: we don't know at this point how
15036 many arguments we should have, so this makes the assumption that we have
15037 > 1. This is true of all current Neon opcodes, I think, but may not be
15038 true in the future. */
15039 if (!inst.operands[1].present)
15040 inst.operands[1] = inst.operands[0];
15041
037e8744 15042 va_start (ap, shape);
5f4273c7 15043
21d799b5 15044 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
15045 {
15046 unsigned j;
15047 int matches = 1;
15048
15049 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
15050 {
15051 if (!inst.operands[j].present)
15052 {
15053 matches = 0;
15054 break;
15055 }
15056
15057 switch (neon_shape_tab[shape].el[j])
15058 {
d54af2d0
RL
15059 /* If a .f16, .16, .u16, .s16 type specifier is given over
15060 a VFP single precision register operand, it's essentially
15061 means only half of the register is used.
15062
15063 If the type specifier is given after the mnemonics, the
15064 information is stored in inst.vectype. If the type specifier
15065 is given after register operand, the information is stored
15066 in inst.operands[].vectype.
15067
15068 When there is only one type specifier, and all the register
15069 operands are the same type of hardware register, the type
15070 specifier applies to all register operands.
15071
15072 If no type specifier is given, the shape is inferred from
15073 operand information.
15074
15075 for example:
15076 vadd.f16 s0, s1, s2: NS_HHH
15077 vabs.f16 s0, s1: NS_HH
15078 vmov.f16 s0, r1: NS_HR
15079 vmov.f16 r0, s1: NS_RH
15080 vcvt.f16 r0, s1: NS_RH
15081 vcvt.f16.s32 s2, s2, #29: NS_HFI
15082 vcvt.f16.s32 s2, s2: NS_HF
15083 */
15084 case SE_H:
15085 if (!(inst.operands[j].isreg
15086 && inst.operands[j].isvec
15087 && inst.operands[j].issingle
15088 && !inst.operands[j].isquad
15089 && ((inst.vectype.elems == 1
15090 && inst.vectype.el[0].size == 16)
15091 || (inst.vectype.elems > 1
15092 && inst.vectype.el[j].size == 16)
15093 || (inst.vectype.elems == 0
15094 && inst.operands[j].vectype.type != NT_invtype
15095 && inst.operands[j].vectype.size == 16))))
15096 matches = 0;
15097 break;
15098
477330fc
RM
15099 case SE_F:
15100 if (!(inst.operands[j].isreg
15101 && inst.operands[j].isvec
15102 && inst.operands[j].issingle
d54af2d0
RL
15103 && !inst.operands[j].isquad
15104 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15105 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15106 || (inst.vectype.elems == 0
15107 && (inst.operands[j].vectype.size == 32
15108 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
15109 matches = 0;
15110 break;
15111
15112 case SE_D:
15113 if (!(inst.operands[j].isreg
15114 && inst.operands[j].isvec
15115 && !inst.operands[j].isquad
15116 && !inst.operands[j].issingle))
15117 matches = 0;
15118 break;
15119
15120 case SE_R:
15121 if (!(inst.operands[j].isreg
15122 && !inst.operands[j].isvec))
15123 matches = 0;
15124 break;
15125
15126 case SE_Q:
15127 if (!(inst.operands[j].isreg
15128 && inst.operands[j].isvec
15129 && inst.operands[j].isquad
15130 && !inst.operands[j].issingle))
15131 matches = 0;
15132 break;
15133
15134 case SE_I:
15135 if (!(!inst.operands[j].isreg
15136 && !inst.operands[j].isscalar))
15137 matches = 0;
15138 break;
15139
15140 case SE_S:
15141 if (!(!inst.operands[j].isreg
15142 && inst.operands[j].isscalar))
15143 matches = 0;
15144 break;
15145
5aae9ae9 15146 case SE_P:
477330fc
RM
15147 case SE_L:
15148 break;
15149 }
3fde54a2
JZ
15150 if (!matches)
15151 break;
477330fc 15152 }
ad6cec43
MGD
15153 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15154 /* We've matched all the entries in the shape table, and we don't
15155 have any left over operands which have not been matched. */
477330fc 15156 break;
037e8744 15157 }
5f4273c7 15158
037e8744 15159 va_end (ap);
5287ad62 15160
037e8744
JB
15161 if (shape == NS_NULL && first_shape != NS_NULL)
15162 first_error (_("invalid instruction shape"));
5287ad62 15163
037e8744
JB
15164 return shape;
15165}
5287ad62 15166
037e8744
JB
15167/* True if SHAPE is predominantly a quadword operation (most of the time, this
15168 means the Q bit should be set). */
15169
15170static int
15171neon_quad (enum neon_shape shape)
15172{
15173 return neon_shape_class[shape] == SC_QUAD;
5287ad62 15174}
037e8744 15175
5287ad62
JB
15176static void
15177neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 15178 unsigned *g_size)
5287ad62
JB
15179{
15180 /* Allow modification to be made to types which are constrained to be
15181 based on the key element, based on bits set alongside N_EQK. */
15182 if ((typebits & N_EQK) != 0)
15183 {
15184 if ((typebits & N_HLF) != 0)
15185 *g_size /= 2;
15186 else if ((typebits & N_DBL) != 0)
15187 *g_size *= 2;
15188 if ((typebits & N_SGN) != 0)
15189 *g_type = NT_signed;
15190 else if ((typebits & N_UNS) != 0)
477330fc 15191 *g_type = NT_unsigned;
5287ad62 15192 else if ((typebits & N_INT) != 0)
477330fc 15193 *g_type = NT_integer;
5287ad62 15194 else if ((typebits & N_FLT) != 0)
477330fc 15195 *g_type = NT_float;
dcbf9037 15196 else if ((typebits & N_SIZ) != 0)
477330fc 15197 *g_type = NT_untyped;
5287ad62
JB
15198 }
15199}
5f4273c7 15200
5287ad62
JB
15201/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15202 operand type, i.e. the single type specified in a Neon instruction when it
15203 is the only one given. */
15204
15205static struct neon_type_el
15206neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15207{
15208 struct neon_type_el dest = *key;
5f4273c7 15209
9c2799c2 15210 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15211
5287ad62
JB
15212 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15213
15214 return dest;
15215}
15216
15217/* Convert Neon type and size into compact bitmask representation. */
15218
15219static enum neon_type_mask
15220type_chk_of_el_type (enum neon_el_type type, unsigned size)
15221{
15222 switch (type)
15223 {
15224 case NT_untyped:
15225 switch (size)
477330fc
RM
15226 {
15227 case 8: return N_8;
15228 case 16: return N_16;
15229 case 32: return N_32;
15230 case 64: return N_64;
15231 default: ;
15232 }
5287ad62
JB
15233 break;
15234
15235 case NT_integer:
15236 switch (size)
477330fc
RM
15237 {
15238 case 8: return N_I8;
15239 case 16: return N_I16;
15240 case 32: return N_I32;
15241 case 64: return N_I64;
15242 default: ;
15243 }
5287ad62
JB
15244 break;
15245
15246 case NT_float:
037e8744 15247 switch (size)
477330fc 15248 {
8e79c3df 15249 case 16: return N_F16;
477330fc
RM
15250 case 32: return N_F32;
15251 case 64: return N_F64;
15252 default: ;
15253 }
5287ad62
JB
15254 break;
15255
15256 case NT_poly:
15257 switch (size)
477330fc
RM
15258 {
15259 case 8: return N_P8;
15260 case 16: return N_P16;
4f51b4bd 15261 case 64: return N_P64;
477330fc
RM
15262 default: ;
15263 }
5287ad62
JB
15264 break;
15265
15266 case NT_signed:
15267 switch (size)
477330fc
RM
15268 {
15269 case 8: return N_S8;
15270 case 16: return N_S16;
15271 case 32: return N_S32;
15272 case 64: return N_S64;
15273 default: ;
15274 }
5287ad62
JB
15275 break;
15276
15277 case NT_unsigned:
15278 switch (size)
477330fc
RM
15279 {
15280 case 8: return N_U8;
15281 case 16: return N_U16;
15282 case 32: return N_U32;
15283 case 64: return N_U64;
15284 default: ;
15285 }
5287ad62
JB
15286 break;
15287
aab2c27d
MM
15288 case NT_bfloat:
15289 if (size == 16) return N_BF16;
15290 break;
15291
5287ad62
JB
15292 default: ;
15293 }
5f4273c7 15294
5287ad62
JB
15295 return N_UTYP;
15296}
15297
15298/* Convert compact Neon bitmask type representation to a type and size. Only
15299 handles the case where a single bit is set in the mask. */
15300
dcbf9037 15301static int
5287ad62 15302el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15303 enum neon_type_mask mask)
5287ad62 15304{
dcbf9037
JB
15305 if ((mask & N_EQK) != 0)
15306 return FAIL;
15307
5287ad62
JB
15308 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15309 *size = 8;
aab2c27d
MM
15310 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15311 != 0)
5287ad62 15312 *size = 16;
dcbf9037 15313 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15314 *size = 32;
4f51b4bd 15315 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15316 *size = 64;
dcbf9037
JB
15317 else
15318 return FAIL;
15319
5287ad62
JB
15320 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15321 *type = NT_signed;
dcbf9037 15322 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15323 *type = NT_unsigned;
dcbf9037 15324 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15325 *type = NT_integer;
dcbf9037 15326 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15327 *type = NT_untyped;
4f51b4bd 15328 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15329 *type = NT_poly;
d54af2d0 15330 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15331 *type = NT_float;
aab2c27d
MM
15332 else if ((mask & (N_BF16)) != 0)
15333 *type = NT_bfloat;
dcbf9037
JB
15334 else
15335 return FAIL;
5f4273c7 15336
dcbf9037 15337 return SUCCESS;
5287ad62
JB
15338}
15339
15340/* Modify a bitmask of allowed types. This is only needed for type
15341 relaxation. */
15342
15343static unsigned
15344modify_types_allowed (unsigned allowed, unsigned mods)
15345{
15346 unsigned size;
15347 enum neon_el_type type;
15348 unsigned destmask;
15349 int i;
5f4273c7 15350
5287ad62 15351 destmask = 0;
5f4273c7 15352
5287ad62
JB
15353 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15354 {
21d799b5 15355 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15356 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15357 {
15358 neon_modify_type_size (mods, &type, &size);
15359 destmask |= type_chk_of_el_type (type, size);
15360 }
5287ad62 15361 }
5f4273c7 15362
5287ad62
JB
15363 return destmask;
15364}
15365
15366/* Check type and return type classification.
15367 The manual states (paraphrase): If one datatype is given, it indicates the
15368 type given in:
15369 - the second operand, if there is one
15370 - the operand, if there is no second operand
15371 - the result, if there are no operands.
15372 This isn't quite good enough though, so we use a concept of a "key" datatype
15373 which is set on a per-instruction basis, which is the one which matters when
15374 only one data type is written.
15375 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15376 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15377
15378static struct neon_type_el
15379neon_check_type (unsigned els, enum neon_shape ns, ...)
15380{
15381 va_list ap;
15382 unsigned i, pass, key_el = 0;
15383 unsigned types[NEON_MAX_TYPE_ELS];
15384 enum neon_el_type k_type = NT_invtype;
15385 unsigned k_size = -1u;
15386 struct neon_type_el badtype = {NT_invtype, -1};
15387 unsigned key_allowed = 0;
15388
15389 /* Optional registers in Neon instructions are always (not) in operand 1.
15390 Fill in the missing operand here, if it was omitted. */
15391 if (els > 1 && !inst.operands[1].present)
15392 inst.operands[1] = inst.operands[0];
15393
15394 /* Suck up all the varargs. */
15395 va_start (ap, ns);
15396 for (i = 0; i < els; i++)
15397 {
15398 unsigned thisarg = va_arg (ap, unsigned);
15399 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15400 {
15401 va_end (ap);
15402 return badtype;
15403 }
5287ad62
JB
15404 types[i] = thisarg;
15405 if ((thisarg & N_KEY) != 0)
477330fc 15406 key_el = i;
5287ad62
JB
15407 }
15408 va_end (ap);
15409
dcbf9037
JB
15410 if (inst.vectype.elems > 0)
15411 for (i = 0; i < els; i++)
15412 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15413 {
15414 first_error (_("types specified in both the mnemonic and operands"));
15415 return badtype;
15416 }
dcbf9037 15417
5287ad62
JB
15418 /* Duplicate inst.vectype elements here as necessary.
15419 FIXME: No idea if this is exactly the same as the ARM assembler,
15420 particularly when an insn takes one register and one non-register
15421 operand. */
15422 if (inst.vectype.elems == 1 && els > 1)
15423 {
15424 unsigned j;
15425 inst.vectype.elems = els;
15426 inst.vectype.el[key_el] = inst.vectype.el[0];
15427 for (j = 0; j < els; j++)
477330fc
RM
15428 if (j != key_el)
15429 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15430 types[j]);
dcbf9037
JB
15431 }
15432 else if (inst.vectype.elems == 0 && els > 0)
15433 {
15434 unsigned j;
15435 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15436 after each operand. We allow some flexibility here; as long as the
15437 "key" operand has a type, we can infer the others. */
dcbf9037 15438 for (j = 0; j < els; j++)
477330fc
RM
15439 if (inst.operands[j].vectype.type != NT_invtype)
15440 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15441
15442 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15443 {
15444 for (j = 0; j < els; j++)
15445 if (inst.operands[j].vectype.type == NT_invtype)
15446 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15447 types[j]);
15448 }
dcbf9037 15449 else
477330fc
RM
15450 {
15451 first_error (_("operand types can't be inferred"));
15452 return badtype;
15453 }
5287ad62
JB
15454 }
15455 else if (inst.vectype.elems != els)
15456 {
dcbf9037 15457 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15458 return badtype;
15459 }
15460
15461 for (pass = 0; pass < 2; pass++)
15462 {
15463 for (i = 0; i < els; i++)
477330fc
RM
15464 {
15465 unsigned thisarg = types[i];
15466 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15467 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15468 enum neon_el_type g_type = inst.vectype.el[i].type;
15469 unsigned g_size = inst.vectype.el[i].size;
15470
15471 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15472 integer types if sign-specific variants are unavailable. */
477330fc 15473 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15474 && (types_allowed & N_SU_ALL) == 0)
15475 g_type = NT_integer;
15476
477330fc 15477 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15478 them. Some instructions only care about signs for some element
15479 sizes, so handle that properly. */
477330fc 15480 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15481 && ((g_size == 8 && (types_allowed & N_8) != 0)
15482 || (g_size == 16 && (types_allowed & N_16) != 0)
15483 || (g_size == 32 && (types_allowed & N_32) != 0)
15484 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15485 g_type = NT_untyped;
15486
477330fc
RM
15487 if (pass == 0)
15488 {
15489 if ((thisarg & N_KEY) != 0)
15490 {
15491 k_type = g_type;
15492 k_size = g_size;
15493 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15494
15495 /* Check architecture constraint on FP16 extension. */
15496 if (k_size == 16
15497 && k_type == NT_float
15498 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15499 {
15500 inst.error = _(BAD_FP16);
15501 return badtype;
15502 }
477330fc
RM
15503 }
15504 }
15505 else
15506 {
15507 if ((thisarg & N_VFP) != 0)
15508 {
15509 enum neon_shape_el regshape;
15510 unsigned regwidth, match;
99b253c5
NC
15511
15512 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15513 if (ns == NS_NULL)
15514 {
15515 first_error (_("invalid instruction shape"));
15516 return badtype;
15517 }
477330fc
RM
15518 regshape = neon_shape_tab[ns].el[i];
15519 regwidth = neon_shape_el_size[regshape];
15520
15521 /* In VFP mode, operands must match register widths. If we
15522 have a key operand, use its width, else use the width of
15523 the current operand. */
15524 if (k_size != -1u)
15525 match = k_size;
15526 else
15527 match = g_size;
15528
9db2f6b4
RL
15529 /* FP16 will use a single precision register. */
15530 if (regwidth == 32 && match == 16)
15531 {
15532 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15533 match = regwidth;
15534 else
15535 {
15536 inst.error = _(BAD_FP16);
15537 return badtype;
15538 }
15539 }
15540
477330fc
RM
15541 if (regwidth != match)
15542 {
15543 first_error (_("operand size must match register width"));
15544 return badtype;
15545 }
15546 }
15547
15548 if ((thisarg & N_EQK) == 0)
15549 {
15550 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15551
15552 if ((given_type & types_allowed) == 0)
15553 {
a302e574 15554 first_error (BAD_SIMD_TYPE);
477330fc
RM
15555 return badtype;
15556 }
15557 }
15558 else
15559 {
15560 enum neon_el_type mod_k_type = k_type;
15561 unsigned mod_k_size = k_size;
15562 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15563 if (g_type != mod_k_type || g_size != mod_k_size)
15564 {
15565 first_error (_("inconsistent types in Neon instruction"));
15566 return badtype;
15567 }
15568 }
15569 }
15570 }
5287ad62
JB
15571 }
15572
15573 return inst.vectype.el[key_el];
15574}
15575
037e8744 15576/* Neon-style VFP instruction forwarding. */
5287ad62 15577
037e8744
JB
15578/* Thumb VFP instructions have 0xE in the condition field. */
15579
15580static void
15581do_vfp_cond_or_thumb (void)
5287ad62 15582{
88714cb8
DG
15583 inst.is_neon = 1;
15584
5287ad62 15585 if (thumb_mode)
037e8744 15586 inst.instruction |= 0xe0000000;
5287ad62 15587 else
037e8744 15588 inst.instruction |= inst.cond << 28;
5287ad62
JB
15589}
15590
037e8744
JB
15591/* Look up and encode a simple mnemonic, for use as a helper function for the
15592 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15593 etc. It is assumed that operand parsing has already been done, and that the
15594 operands are in the form expected by the given opcode (this isn't necessarily
15595 the same as the form in which they were parsed, hence some massaging must
15596 take place before this function is called).
15597 Checks current arch version against that in the looked-up opcode. */
5287ad62 15598
037e8744
JB
15599static void
15600do_vfp_nsyn_opcode (const char *opname)
5287ad62 15601{
037e8744 15602 const struct asm_opcode *opcode;
5f4273c7 15603
21d799b5 15604 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 15605
037e8744
JB
15606 if (!opcode)
15607 abort ();
5287ad62 15608
037e8744 15609 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15610 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15611 _(BAD_FPU));
5287ad62 15612
88714cb8
DG
15613 inst.is_neon = 1;
15614
037e8744
JB
15615 if (thumb_mode)
15616 {
15617 inst.instruction = opcode->tvalue;
15618 opcode->tencode ();
15619 }
15620 else
15621 {
15622 inst.instruction = (inst.cond << 28) | opcode->avalue;
15623 opcode->aencode ();
15624 }
15625}
5287ad62
JB
15626
15627static void
037e8744 15628do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15629{
037e8744
JB
15630 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15631
9db2f6b4 15632 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15633 {
15634 if (is_add)
477330fc 15635 do_vfp_nsyn_opcode ("fadds");
037e8744 15636 else
477330fc 15637 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15638
15639 /* ARMv8.2 fp16 instruction. */
15640 if (rs == NS_HHH)
15641 do_scalar_fp16_v82_encode ();
037e8744
JB
15642 }
15643 else
15644 {
15645 if (is_add)
477330fc 15646 do_vfp_nsyn_opcode ("faddd");
037e8744 15647 else
477330fc 15648 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15649 }
15650}
15651
15652/* Check operand types to see if this is a VFP instruction, and if so call
15653 PFN (). */
15654
15655static int
15656try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15657{
15658 enum neon_shape rs;
15659 struct neon_type_el et;
15660
15661 switch (args)
15662 {
15663 case 2:
9db2f6b4
RL
15664 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15665 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15666 break;
5f4273c7 15667
037e8744 15668 case 3:
9db2f6b4
RL
15669 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15670 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15671 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15672 break;
15673
15674 default:
15675 abort ();
15676 }
15677
15678 if (et.type != NT_invtype)
15679 {
15680 pfn (rs);
15681 return SUCCESS;
15682 }
037e8744 15683
99b253c5 15684 inst.error = NULL;
037e8744
JB
15685 return FAIL;
15686}
15687
15688static void
15689do_vfp_nsyn_mla_mls (enum neon_shape rs)
15690{
15691 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15692
9db2f6b4 15693 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15694 {
15695 if (is_mla)
477330fc 15696 do_vfp_nsyn_opcode ("fmacs");
037e8744 15697 else
477330fc 15698 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15699
15700 /* ARMv8.2 fp16 instruction. */
15701 if (rs == NS_HHH)
15702 do_scalar_fp16_v82_encode ();
037e8744
JB
15703 }
15704 else
15705 {
15706 if (is_mla)
477330fc 15707 do_vfp_nsyn_opcode ("fmacd");
037e8744 15708 else
477330fc 15709 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15710 }
15711}
15712
62f3b8c8
PB
15713static void
15714do_vfp_nsyn_fma_fms (enum neon_shape rs)
15715{
15716 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15717
9db2f6b4 15718 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15719 {
15720 if (is_fma)
477330fc 15721 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15722 else
477330fc 15723 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15724
15725 /* ARMv8.2 fp16 instruction. */
15726 if (rs == NS_HHH)
15727 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15728 }
15729 else
15730 {
15731 if (is_fma)
477330fc 15732 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15733 else
477330fc 15734 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15735 }
15736}
15737
037e8744
JB
15738static void
15739do_vfp_nsyn_mul (enum neon_shape rs)
15740{
9db2f6b4
RL
15741 if (rs == NS_FFF || rs == NS_HHH)
15742 {
15743 do_vfp_nsyn_opcode ("fmuls");
15744
15745 /* ARMv8.2 fp16 instruction. */
15746 if (rs == NS_HHH)
15747 do_scalar_fp16_v82_encode ();
15748 }
037e8744
JB
15749 else
15750 do_vfp_nsyn_opcode ("fmuld");
15751}
15752
15753static void
15754do_vfp_nsyn_abs_neg (enum neon_shape rs)
15755{
15756 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15757 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15758
9db2f6b4 15759 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15760 {
15761 if (is_neg)
477330fc 15762 do_vfp_nsyn_opcode ("fnegs");
037e8744 15763 else
477330fc 15764 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15765
15766 /* ARMv8.2 fp16 instruction. */
15767 if (rs == NS_HH)
15768 do_scalar_fp16_v82_encode ();
037e8744
JB
15769 }
15770 else
15771 {
15772 if (is_neg)
477330fc 15773 do_vfp_nsyn_opcode ("fnegd");
037e8744 15774 else
477330fc 15775 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15776 }
15777}
15778
15779/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15780 insns belong to Neon, and are handled elsewhere. */
15781
15782static void
15783do_vfp_nsyn_ldm_stm (int is_dbmode)
15784{
15785 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15786 if (is_ldm)
15787 {
15788 if (is_dbmode)
477330fc 15789 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15790 else
477330fc 15791 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15792 }
15793 else
15794 {
15795 if (is_dbmode)
477330fc 15796 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15797 else
477330fc 15798 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15799 }
15800}
15801
037e8744
JB
15802static void
15803do_vfp_nsyn_sqrt (void)
15804{
9db2f6b4
RL
15805 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15806 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15807
9db2f6b4
RL
15808 if (rs == NS_FF || rs == NS_HH)
15809 {
15810 do_vfp_nsyn_opcode ("fsqrts");
15811
15812 /* ARMv8.2 fp16 instruction. */
15813 if (rs == NS_HH)
15814 do_scalar_fp16_v82_encode ();
15815 }
037e8744
JB
15816 else
15817 do_vfp_nsyn_opcode ("fsqrtd");
15818}
15819
15820static void
15821do_vfp_nsyn_div (void)
15822{
9db2f6b4 15823 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15824 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15825 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15826
9db2f6b4
RL
15827 if (rs == NS_FFF || rs == NS_HHH)
15828 {
15829 do_vfp_nsyn_opcode ("fdivs");
15830
15831 /* ARMv8.2 fp16 instruction. */
15832 if (rs == NS_HHH)
15833 do_scalar_fp16_v82_encode ();
15834 }
037e8744
JB
15835 else
15836 do_vfp_nsyn_opcode ("fdivd");
15837}
15838
15839static void
15840do_vfp_nsyn_nmul (void)
15841{
9db2f6b4 15842 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15843 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15844 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15845
9db2f6b4 15846 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15847 {
88714cb8 15848 NEON_ENCODE (SINGLE, inst);
037e8744 15849 do_vfp_sp_dyadic ();
9db2f6b4
RL
15850
15851 /* ARMv8.2 fp16 instruction. */
15852 if (rs == NS_HHH)
15853 do_scalar_fp16_v82_encode ();
037e8744
JB
15854 }
15855 else
15856 {
88714cb8 15857 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15858 do_vfp_dp_rd_rn_rm ();
15859 }
15860 do_vfp_cond_or_thumb ();
9db2f6b4 15861
037e8744
JB
15862}
15863
1b883319
AV
15864/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15865 (0, 1, 2, 3). */
15866
15867static unsigned
15868neon_logbits (unsigned x)
15869{
15870 return ffs (x) - 4;
15871}
15872
15873#define LOW4(R) ((R) & 0xf)
15874#define HI1(R) (((R) >> 4) & 1)
5aae9ae9
MM
15875#define LOW1(R) ((R) & 0x1)
15876#define HI4(R) (((R) >> 1) & 0xf)
1b883319
AV
15877
15878static unsigned
15879mve_get_vcmp_vpt_cond (struct neon_type_el et)
15880{
15881 switch (et.type)
15882 {
15883 default:
15884 first_error (BAD_EL_TYPE);
15885 return 0;
15886 case NT_float:
15887 switch (inst.operands[0].imm)
15888 {
15889 default:
15890 first_error (_("invalid condition"));
15891 return 0;
15892 case 0x0:
15893 /* eq. */
15894 return 0;
15895 case 0x1:
15896 /* ne. */
15897 return 1;
15898 case 0xa:
15899 /* ge/ */
15900 return 4;
15901 case 0xb:
15902 /* lt. */
15903 return 5;
15904 case 0xc:
15905 /* gt. */
15906 return 6;
15907 case 0xd:
15908 /* le. */
15909 return 7;
15910 }
15911 case NT_integer:
15912 /* only accept eq and ne. */
15913 if (inst.operands[0].imm > 1)
15914 {
15915 first_error (_("invalid condition"));
15916 return 0;
15917 }
15918 return inst.operands[0].imm;
15919 case NT_unsigned:
15920 if (inst.operands[0].imm == 0x2)
15921 return 2;
15922 else if (inst.operands[0].imm == 0x8)
15923 return 3;
15924 else
15925 {
15926 first_error (_("invalid condition"));
15927 return 0;
15928 }
15929 case NT_signed:
15930 switch (inst.operands[0].imm)
15931 {
15932 default:
15933 first_error (_("invalid condition"));
15934 return 0;
15935 case 0xa:
15936 /* ge. */
15937 return 4;
15938 case 0xb:
15939 /* lt. */
15940 return 5;
15941 case 0xc:
15942 /* gt. */
15943 return 6;
15944 case 0xd:
15945 /* le. */
15946 return 7;
15947 }
15948 }
15949 /* Should be unreachable. */
15950 abort ();
15951}
15952
efd0b310
SP
15953/* For VCTP (create vector tail predicate) in MVE. */
15954static void
15955do_mve_vctp (void)
15956{
15957 int dt = 0;
15958 unsigned size = 0x0;
15959
15960 if (inst.cond > COND_ALWAYS)
15961 inst.pred_insn_type = INSIDE_VPT_INSN;
15962 else
15963 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15964
15965 /* This is a typical MVE instruction which has no type but have size 8, 16,
15966 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15967 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15968 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15969 dt = inst.vectype.el[0].size;
15970
15971 /* Setting this does not indicate an actual NEON instruction, but only
15972 indicates that the mnemonic accepts neon-style type suffixes. */
15973 inst.is_neon = 1;
15974
15975 switch (dt)
15976 {
15977 case 8:
15978 break;
15979 case 16:
15980 size = 0x1; break;
15981 case 32:
15982 size = 0x2; break;
15983 case 64:
15984 size = 0x3; break;
15985 default:
15986 first_error (_("Type is not allowed for this instruction"));
15987 }
15988 inst.instruction |= size << 20;
15989 inst.instruction |= inst.operands[0].reg << 16;
15990}
15991
1b883319
AV
15992static void
15993do_mve_vpt (void)
15994{
15995 /* We are dealing with a vector predicated block. */
15996 if (inst.operands[0].present)
15997 {
15998 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15999 struct neon_type_el et
16000 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16001 N_EQK);
16002
16003 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16004
16005 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16006
16007 if (et.type == NT_invtype)
16008 return;
16009
16010 if (et.type == NT_float)
16011 {
16012 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16013 BAD_FPU);
16014 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16015 inst.instruction |= (et.size == 16) << 28;
16016 inst.instruction |= 0x3 << 20;
16017 }
16018 else
16019 {
16020 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16021 BAD_EL_TYPE);
16022 inst.instruction |= 1 << 28;
16023 inst.instruction |= neon_logbits (et.size) << 20;
16024 }
16025
16026 if (inst.operands[2].isquad)
16027 {
16028 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16029 inst.instruction |= LOW4 (inst.operands[2].reg);
16030 inst.instruction |= (fcond & 0x2) >> 1;
16031 }
16032 else
16033 {
16034 if (inst.operands[2].reg == REG_SP)
16035 as_tsktsk (MVE_BAD_SP);
16036 inst.instruction |= 1 << 6;
16037 inst.instruction |= (fcond & 0x2) << 4;
16038 inst.instruction |= inst.operands[2].reg;
16039 }
16040 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16041 inst.instruction |= (fcond & 0x4) << 10;
16042 inst.instruction |= (fcond & 0x1) << 7;
16043
16044 }
16045 set_pred_insn_type (VPT_INSN);
16046 now_pred.cc = 0;
16047 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16048 | ((inst.instruction & 0xe000) >> 13);
16049 now_pred.warn_deprecated = FALSE;
16050 now_pred.type = VECTOR_PRED;
16051 inst.is_neon = 1;
16052}
16053
16054static void
16055do_mve_vcmp (void)
16056{
16057 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16058 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16059 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16060 if (!inst.operands[2].present)
16061 first_error (_("MVE vector or ARM register expected"));
16062 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16063
16064 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16065 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16066 && inst.operands[1].isquad)
16067 {
16068 inst.instruction = N_MNEM_vcmp;
16069 inst.cond = 0x10;
16070 }
16071
16072 if (inst.cond > COND_ALWAYS)
16073 inst.pred_insn_type = INSIDE_VPT_INSN;
16074 else
16075 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16076
16077 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16078 struct neon_type_el et
16079 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16080 N_EQK);
16081
16082 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16083 && !inst.operands[2].iszr, BAD_PC);
16084
16085 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16086
16087 inst.instruction = 0xee010f00;
16088 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16089 inst.instruction |= (fcond & 0x4) << 10;
16090 inst.instruction |= (fcond & 0x1) << 7;
16091 if (et.type == NT_float)
16092 {
16093 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16094 BAD_FPU);
16095 inst.instruction |= (et.size == 16) << 28;
16096 inst.instruction |= 0x3 << 20;
16097 }
16098 else
16099 {
16100 inst.instruction |= 1 << 28;
16101 inst.instruction |= neon_logbits (et.size) << 20;
16102 }
16103 if (inst.operands[2].isquad)
16104 {
16105 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16106 inst.instruction |= (fcond & 0x2) >> 1;
16107 inst.instruction |= LOW4 (inst.operands[2].reg);
16108 }
16109 else
16110 {
16111 if (inst.operands[2].reg == REG_SP)
16112 as_tsktsk (MVE_BAD_SP);
16113 inst.instruction |= 1 << 6;
16114 inst.instruction |= (fcond & 0x2) << 4;
16115 inst.instruction |= inst.operands[2].reg;
16116 }
16117
16118 inst.is_neon = 1;
16119 return;
16120}
16121
935295b5
AV
16122static void
16123do_mve_vmaxa_vmina (void)
16124{
16125 if (inst.cond > COND_ALWAYS)
16126 inst.pred_insn_type = INSIDE_VPT_INSN;
16127 else
16128 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16129
16130 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16131 struct neon_type_el et
16132 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16133
16134 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16135 inst.instruction |= neon_logbits (et.size) << 18;
16136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16137 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16138 inst.instruction |= LOW4 (inst.operands[1].reg);
16139 inst.is_neon = 1;
16140}
16141
f30ee27c
AV
16142static void
16143do_mve_vfmas (void)
16144{
16145 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16146 struct neon_type_el et
16147 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16148
16149 if (inst.cond > COND_ALWAYS)
16150 inst.pred_insn_type = INSIDE_VPT_INSN;
16151 else
16152 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16153
16154 if (inst.operands[2].reg == REG_SP)
16155 as_tsktsk (MVE_BAD_SP);
16156 else if (inst.operands[2].reg == REG_PC)
16157 as_tsktsk (MVE_BAD_PC);
16158
16159 inst.instruction |= (et.size == 16) << 28;
16160 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16161 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16162 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16163 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16164 inst.instruction |= inst.operands[2].reg;
16165 inst.is_neon = 1;
16166}
16167
b409bdb6
AV
16168static void
16169do_mve_viddup (void)
16170{
16171 if (inst.cond > COND_ALWAYS)
16172 inst.pred_insn_type = INSIDE_VPT_INSN;
16173 else
16174 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16175
16176 unsigned imm = inst.relocs[0].exp.X_add_number;
16177 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16178 _("immediate must be either 1, 2, 4 or 8"));
16179
16180 enum neon_shape rs;
16181 struct neon_type_el et;
16182 unsigned Rm;
16183 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16184 {
16185 rs = neon_select_shape (NS_QRI, NS_NULL);
16186 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16187 Rm = 7;
16188 }
16189 else
16190 {
16191 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16192 if (inst.operands[2].reg == REG_SP)
16193 as_tsktsk (MVE_BAD_SP);
16194 else if (inst.operands[2].reg == REG_PC)
16195 first_error (BAD_PC);
16196
16197 rs = neon_select_shape (NS_QRRI, NS_NULL);
16198 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16199 Rm = inst.operands[2].reg >> 1;
16200 }
16201 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16202 inst.instruction |= neon_logbits (et.size) << 20;
16203 inst.instruction |= inst.operands[1].reg << 16;
16204 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16205 inst.instruction |= (imm > 2) << 7;
16206 inst.instruction |= Rm << 1;
16207 inst.instruction |= (imm == 2 || imm == 8);
16208 inst.is_neon = 1;
16209}
16210
2d78f95b
AV
16211static void
16212do_mve_vmlas (void)
16213{
16214 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16215 struct neon_type_el et
16216 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16217
16218 if (inst.operands[2].reg == REG_PC)
16219 as_tsktsk (MVE_BAD_PC);
16220 else if (inst.operands[2].reg == REG_SP)
16221 as_tsktsk (MVE_BAD_SP);
16222
16223 if (inst.cond > COND_ALWAYS)
16224 inst.pred_insn_type = INSIDE_VPT_INSN;
16225 else
16226 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16227
16228 inst.instruction |= (et.type == NT_unsigned) << 28;
16229 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16230 inst.instruction |= neon_logbits (et.size) << 20;
16231 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16232 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16233 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16234 inst.instruction |= inst.operands[2].reg;
16235 inst.is_neon = 1;
16236}
16237
acca5630
AV
16238static void
16239do_mve_vshll (void)
16240{
16241 struct neon_type_el et
16242 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16243
16244 if (inst.cond > COND_ALWAYS)
16245 inst.pred_insn_type = INSIDE_VPT_INSN;
16246 else
16247 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16248
16249 int imm = inst.operands[2].imm;
16250 constraint (imm < 1 || (unsigned)imm > et.size,
16251 _("immediate value out of range"));
16252
16253 if ((unsigned)imm == et.size)
16254 {
16255 inst.instruction |= neon_logbits (et.size) << 18;
16256 inst.instruction |= 0x110001;
16257 }
16258 else
16259 {
16260 inst.instruction |= (et.size + imm) << 16;
16261 inst.instruction |= 0x800140;
16262 }
16263
16264 inst.instruction |= (et.type == NT_unsigned) << 28;
16265 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16266 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16267 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16268 inst.instruction |= LOW4 (inst.operands[1].reg);
16269 inst.is_neon = 1;
16270}
16271
16272static void
16273do_mve_vshlc (void)
16274{
16275 if (inst.cond > COND_ALWAYS)
16276 inst.pred_insn_type = INSIDE_VPT_INSN;
16277 else
16278 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16279
16280 if (inst.operands[1].reg == REG_PC)
16281 as_tsktsk (MVE_BAD_PC);
16282 else if (inst.operands[1].reg == REG_SP)
16283 as_tsktsk (MVE_BAD_SP);
16284
16285 int imm = inst.operands[2].imm;
16286 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16287
16288 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16289 inst.instruction |= (imm & 0x1f) << 16;
16290 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16291 inst.instruction |= inst.operands[1].reg;
16292 inst.is_neon = 1;
16293}
16294
4aa88b50
AV
16295static void
16296do_mve_vshrn (void)
16297{
16298 unsigned types;
16299 switch (inst.instruction)
16300 {
16301 case M_MNEM_vshrnt:
16302 case M_MNEM_vshrnb:
16303 case M_MNEM_vrshrnt:
16304 case M_MNEM_vrshrnb:
16305 types = N_I16 | N_I32;
16306 break;
16307 case M_MNEM_vqshrnt:
16308 case M_MNEM_vqshrnb:
16309 case M_MNEM_vqrshrnt:
16310 case M_MNEM_vqrshrnb:
16311 types = N_U16 | N_U32 | N_S16 | N_S32;
16312 break;
16313 case M_MNEM_vqshrunt:
16314 case M_MNEM_vqshrunb:
16315 case M_MNEM_vqrshrunt:
16316 case M_MNEM_vqrshrunb:
16317 types = N_S16 | N_S32;
16318 break;
16319 default:
16320 abort ();
16321 }
16322
16323 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16324
16325 if (inst.cond > COND_ALWAYS)
16326 inst.pred_insn_type = INSIDE_VPT_INSN;
16327 else
16328 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16329
16330 unsigned Qd = inst.operands[0].reg;
16331 unsigned Qm = inst.operands[1].reg;
16332 unsigned imm = inst.operands[2].imm;
16333 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16334 et.size == 16
16335 ? _("immediate operand expected in the range [1,8]")
16336 : _("immediate operand expected in the range [1,16]"));
16337
16338 inst.instruction |= (et.type == NT_unsigned) << 28;
16339 inst.instruction |= HI1 (Qd) << 22;
16340 inst.instruction |= (et.size - imm) << 16;
16341 inst.instruction |= LOW4 (Qd) << 12;
16342 inst.instruction |= HI1 (Qm) << 5;
16343 inst.instruction |= LOW4 (Qm);
16344 inst.is_neon = 1;
16345}
16346
1be7aba3
AV
16347static void
16348do_mve_vqmovn (void)
16349{
16350 struct neon_type_el et;
16351 if (inst.instruction == M_MNEM_vqmovnt
16352 || inst.instruction == M_MNEM_vqmovnb)
16353 et = neon_check_type (2, NS_QQ, N_EQK,
16354 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16355 else
16356 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16357
16358 if (inst.cond > COND_ALWAYS)
16359 inst.pred_insn_type = INSIDE_VPT_INSN;
16360 else
16361 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16362
16363 inst.instruction |= (et.type == NT_unsigned) << 28;
16364 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16365 inst.instruction |= (et.size == 32) << 18;
16366 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16367 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16368 inst.instruction |= LOW4 (inst.operands[1].reg);
16369 inst.is_neon = 1;
16370}
16371
3063888e
AV
16372static void
16373do_mve_vpsel (void)
16374{
16375 neon_select_shape (NS_QQQ, NS_NULL);
16376
16377 if (inst.cond > COND_ALWAYS)
16378 inst.pred_insn_type = INSIDE_VPT_INSN;
16379 else
16380 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16381
16382 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16383 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16384 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16385 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16386 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16387 inst.instruction |= LOW4 (inst.operands[2].reg);
16388 inst.is_neon = 1;
16389}
16390
16391static void
16392do_mve_vpnot (void)
16393{
16394 if (inst.cond > COND_ALWAYS)
16395 inst.pred_insn_type = INSIDE_VPT_INSN;
16396 else
16397 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16398}
16399
935295b5
AV
16400static void
16401do_mve_vmaxnma_vminnma (void)
16402{
16403 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16404 struct neon_type_el et
16405 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16406
16407 if (inst.cond > COND_ALWAYS)
16408 inst.pred_insn_type = INSIDE_VPT_INSN;
16409 else
16410 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16411
16412 inst.instruction |= (et.size == 16) << 28;
16413 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16414 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16415 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16416 inst.instruction |= LOW4 (inst.operands[1].reg);
16417 inst.is_neon = 1;
16418}
16419
5d281bf0
AV
16420static void
16421do_mve_vcmul (void)
16422{
16423 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16424 struct neon_type_el et
16425 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16426
16427 if (inst.cond > COND_ALWAYS)
16428 inst.pred_insn_type = INSIDE_VPT_INSN;
16429 else
16430 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16431
16432 unsigned rot = inst.relocs[0].exp.X_add_number;
16433 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16434 _("immediate out of range"));
16435
16436 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16437 || inst.operands[0].reg == inst.operands[2].reg))
16438 as_tsktsk (BAD_MVE_SRCDEST);
16439
16440 inst.instruction |= (et.size == 32) << 28;
16441 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16442 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16443 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16444 inst.instruction |= (rot > 90) << 12;
16445 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16446 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16447 inst.instruction |= LOW4 (inst.operands[2].reg);
16448 inst.instruction |= (rot == 90 || rot == 270);
16449 inst.is_neon = 1;
16450}
16451
1f6234a3
AV
16452/* To handle the Low Overhead Loop instructions
16453 in Armv8.1-M Mainline and MVE. */
16454static void
16455do_t_loloop (void)
16456{
16457 unsigned long insn = inst.instruction;
16458
16459 inst.instruction = THUMB_OP32 (inst.instruction);
16460
16461 if (insn == T_MNEM_lctp)
16462 return;
16463
16464 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16465
16466 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16467 {
16468 struct neon_type_el et
16469 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16470 inst.instruction |= neon_logbits (et.size) << 20;
16471 inst.is_neon = 1;
16472 }
16473
16474 switch (insn)
16475 {
16476 case T_MNEM_letp:
16477 constraint (!inst.operands[0].present,
16478 _("expected LR"));
16479 /* fall through. */
16480 case T_MNEM_le:
16481 /* le <label>. */
16482 if (!inst.operands[0].present)
16483 inst.instruction |= 1 << 21;
16484
16485 v8_1_loop_reloc (TRUE);
16486 break;
16487
16488 case T_MNEM_wls:
16489 case T_MNEM_wlstp:
16490 v8_1_loop_reloc (FALSE);
16491 /* fall through. */
16492 case T_MNEM_dlstp:
16493 case T_MNEM_dls:
16494 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16495
16496 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16497 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16498 else if (inst.operands[1].reg == REG_PC)
16499 as_tsktsk (MVE_BAD_PC);
16500 if (inst.operands[1].reg == REG_SP)
16501 as_tsktsk (MVE_BAD_SP);
16502
16503 inst.instruction |= (inst.operands[1].reg << 16);
16504 break;
16505
16506 default:
16507 abort ();
16508 }
16509}
16510
16511
037e8744
JB
16512static void
16513do_vfp_nsyn_cmp (void)
16514{
9db2f6b4 16515 enum neon_shape rs;
1b883319
AV
16516 if (!inst.operands[0].isreg)
16517 {
16518 do_mve_vcmp ();
16519 return;
16520 }
16521 else
16522 {
16523 constraint (inst.operands[2].present, BAD_SYNTAX);
16524 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16525 BAD_FPU);
16526 }
16527
037e8744
JB
16528 if (inst.operands[1].isreg)
16529 {
9db2f6b4
RL
16530 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16531 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16532
9db2f6b4 16533 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16534 {
16535 NEON_ENCODE (SINGLE, inst);
16536 do_vfp_sp_monadic ();
16537 }
037e8744 16538 else
477330fc
RM
16539 {
16540 NEON_ENCODE (DOUBLE, inst);
16541 do_vfp_dp_rd_rm ();
16542 }
037e8744
JB
16543 }
16544 else
16545 {
9db2f6b4
RL
16546 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16547 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16548
16549 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16550 {
16551 case N_MNEM_vcmp:
16552 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16553 break;
16554 case N_MNEM_vcmpe:
16555 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16556 break;
16557 default:
16558 abort ();
16559 }
5f4273c7 16560
9db2f6b4 16561 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16562 {
16563 NEON_ENCODE (SINGLE, inst);
16564 do_vfp_sp_compare_z ();
16565 }
037e8744 16566 else
477330fc
RM
16567 {
16568 NEON_ENCODE (DOUBLE, inst);
16569 do_vfp_dp_rd ();
16570 }
037e8744
JB
16571 }
16572 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16573
16574 /* ARMv8.2 fp16 instruction. */
16575 if (rs == NS_HI || rs == NS_HH)
16576 do_scalar_fp16_v82_encode ();
037e8744
JB
16577}
16578
16579static void
16580nsyn_insert_sp (void)
16581{
16582 inst.operands[1] = inst.operands[0];
16583 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16584 inst.operands[0].reg = REG_SP;
037e8744
JB
16585 inst.operands[0].isreg = 1;
16586 inst.operands[0].writeback = 1;
16587 inst.operands[0].present = 1;
16588}
16589
037e8744
JB
16590/* Fix up Neon data-processing instructions, ORing in the correct bits for
16591 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16592
88714cb8
DG
16593static void
16594neon_dp_fixup (struct arm_it* insn)
037e8744 16595{
88714cb8
DG
16596 unsigned int i = insn->instruction;
16597 insn->is_neon = 1;
16598
037e8744
JB
16599 if (thumb_mode)
16600 {
16601 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16602 if (i & (1 << 24))
477330fc 16603 i |= 1 << 28;
5f4273c7 16604
037e8744 16605 i &= ~(1 << 24);
5f4273c7 16606
037e8744
JB
16607 i |= 0xef000000;
16608 }
16609 else
16610 i |= 0xf2000000;
5f4273c7 16611
88714cb8 16612 insn->instruction = i;
037e8744
JB
16613}
16614
5ee91343 16615static void
7df54120 16616mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16617{
16618 if (inst.operands[2].reg == REG_SP)
16619 as_tsktsk (MVE_BAD_SP);
16620 else if (inst.operands[2].reg == REG_PC)
16621 as_tsktsk (MVE_BAD_PC);
16622
16623 if (fp)
16624 {
16625 /* vadd. */
16626 if (((unsigned)inst.instruction) == 0xd00)
16627 inst.instruction = 0xee300f40;
16628 /* vsub. */
16629 else if (((unsigned)inst.instruction) == 0x200d00)
16630 inst.instruction = 0xee301f40;
a8465a06
AV
16631 /* vmul. */
16632 else if (((unsigned)inst.instruction) == 0x1000d10)
16633 inst.instruction = 0xee310e60;
5ee91343
AV
16634
16635 /* Setting size which is 1 for F16 and 0 for F32. */
16636 inst.instruction |= (size == 16) << 28;
16637 }
16638 else
16639 {
16640 /* vadd. */
16641 if (((unsigned)inst.instruction) == 0x800)
16642 inst.instruction = 0xee010f40;
16643 /* vsub. */
16644 else if (((unsigned)inst.instruction) == 0x1000800)
16645 inst.instruction = 0xee011f40;
7df54120
AV
16646 /* vhadd. */
16647 else if (((unsigned)inst.instruction) == 0)
16648 inst.instruction = 0xee000f40;
16649 /* vhsub. */
16650 else if (((unsigned)inst.instruction) == 0x200)
16651 inst.instruction = 0xee001f40;
a8465a06
AV
16652 /* vmla. */
16653 else if (((unsigned)inst.instruction) == 0x900)
16654 inst.instruction = 0xee010e40;
16655 /* vmul. */
16656 else if (((unsigned)inst.instruction) == 0x910)
16657 inst.instruction = 0xee011e60;
16658 /* vqadd. */
16659 else if (((unsigned)inst.instruction) == 0x10)
16660 inst.instruction = 0xee000f60;
16661 /* vqsub. */
16662 else if (((unsigned)inst.instruction) == 0x210)
16663 inst.instruction = 0xee001f60;
42b16635
AV
16664 /* vqrdmlah. */
16665 else if (((unsigned)inst.instruction) == 0x3000b10)
16666 inst.instruction = 0xee000e40;
16667 /* vqdmulh. */
16668 else if (((unsigned)inst.instruction) == 0x0000b00)
16669 inst.instruction = 0xee010e60;
16670 /* vqrdmulh. */
16671 else if (((unsigned)inst.instruction) == 0x1000b00)
16672 inst.instruction = 0xfe010e60;
7df54120
AV
16673
16674 /* Set U-bit. */
16675 inst.instruction |= U << 28;
16676
5ee91343
AV
16677 /* Setting bits for size. */
16678 inst.instruction |= neon_logbits (size) << 20;
16679 }
16680 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16681 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16682 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16683 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16684 inst.instruction |= inst.operands[2].reg;
16685 inst.is_neon = 1;
16686}
16687
a302e574
AV
16688static void
16689mve_encode_rqq (unsigned bit28, unsigned size)
16690{
16691 inst.instruction |= bit28 << 28;
16692 inst.instruction |= neon_logbits (size) << 20;
16693 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16694 inst.instruction |= inst.operands[0].reg << 12;
16695 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16696 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16697 inst.instruction |= LOW4 (inst.operands[2].reg);
16698 inst.is_neon = 1;
16699}
16700
886e1c73
AV
16701static void
16702mve_encode_qqq (int ubit, int size)
16703{
16704
16705 inst.instruction |= (ubit != 0) << 28;
16706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16707 inst.instruction |= neon_logbits (size) << 20;
16708 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16709 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16710 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16711 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16712 inst.instruction |= LOW4 (inst.operands[2].reg);
16713
16714 inst.is_neon = 1;
16715}
16716
26c1e780
AV
16717static void
16718mve_encode_rq (unsigned bit28, unsigned size)
16719{
16720 inst.instruction |= bit28 << 28;
16721 inst.instruction |= neon_logbits (size) << 18;
16722 inst.instruction |= inst.operands[0].reg << 12;
16723 inst.instruction |= LOW4 (inst.operands[1].reg);
16724 inst.is_neon = 1;
16725}
886e1c73 16726
93925576
AV
16727static void
16728mve_encode_rrqq (unsigned U, unsigned size)
16729{
16730 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16731
16732 inst.instruction |= U << 28;
16733 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16734 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16735 inst.instruction |= (size == 32) << 16;
16736 inst.instruction |= inst.operands[0].reg << 12;
16737 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16738 inst.instruction |= inst.operands[3].reg;
16739 inst.is_neon = 1;
16740}
16741
aab2c27d
MM
16742/* Helper function for neon_three_same handling the operands. */
16743static void
16744neon_three_args (int isquad)
16745{
16746 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16747 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16748 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16749 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16750 inst.instruction |= LOW4 (inst.operands[2].reg);
16751 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16752 inst.instruction |= (isquad != 0) << 6;
16753 inst.is_neon = 1;
16754}
16755
037e8744
JB
16756/* Encode insns with bit pattern:
16757
16758 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16759 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16760
037e8744
JB
16761 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16762 different meaning for some instruction. */
16763
16764static void
16765neon_three_same (int isquad, int ubit, int size)
16766{
aab2c27d 16767 neon_three_args (isquad);
037e8744
JB
16768 inst.instruction |= (ubit != 0) << 24;
16769 if (size != -1)
16770 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16771
88714cb8 16772 neon_dp_fixup (&inst);
037e8744
JB
16773}
16774
16775/* Encode instructions of the form:
16776
16777 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16778 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16779
16780 Don't write size if SIZE == -1. */
16781
16782static void
16783neon_two_same (int qbit, int ubit, int size)
16784{
16785 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16786 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16787 inst.instruction |= LOW4 (inst.operands[1].reg);
16788 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16789 inst.instruction |= (qbit != 0) << 6;
16790 inst.instruction |= (ubit != 0) << 24;
16791
16792 if (size != -1)
16793 inst.instruction |= neon_logbits (size) << 18;
16794
88714cb8 16795 neon_dp_fixup (&inst);
5287ad62
JB
16796}
16797
7df54120
AV
16798enum vfp_or_neon_is_neon_bits
16799{
16800NEON_CHECK_CC = 1,
16801NEON_CHECK_ARCH = 2,
16802NEON_CHECK_ARCH8 = 4
16803};
16804
16805/* Call this function if an instruction which may have belonged to the VFP or
16806 Neon instruction sets, but turned out to be a Neon instruction (due to the
16807 operand types involved, etc.). We have to check and/or fix-up a couple of
16808 things:
16809
16810 - Make sure the user hasn't attempted to make a Neon instruction
16811 conditional.
16812 - Alter the value in the condition code field if necessary.
16813 - Make sure that the arch supports Neon instructions.
16814
16815 Which of these operations take place depends on bits from enum
16816 vfp_or_neon_is_neon_bits.
16817
16818 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16819 current instruction's condition is COND_ALWAYS, the condition field is
16820 changed to inst.uncond_value. This is necessary because instructions shared
16821 between VFP and Neon may be conditional for the VFP variants only, and the
16822 unconditional Neon version must have, e.g., 0xF in the condition field. */
16823
16824static int
16825vfp_or_neon_is_neon (unsigned check)
16826{
16827/* Conditions are always legal in Thumb mode (IT blocks). */
16828if (!thumb_mode && (check & NEON_CHECK_CC))
16829 {
16830 if (inst.cond != COND_ALWAYS)
16831 {
16832 first_error (_(BAD_COND));
16833 return FAIL;
16834 }
16835 if (inst.uncond_value != -1)
16836 inst.instruction |= inst.uncond_value << 28;
16837 }
16838
16839
16840 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16841 || ((check & NEON_CHECK_ARCH8)
16842 && !mark_feature_used (&fpu_neon_ext_armv8)))
16843 {
16844 first_error (_(BAD_FPU));
16845 return FAIL;
16846 }
16847
16848return SUCCESS;
16849}
16850
64c350f2
AV
16851
16852/* Return TRUE if the SIMD instruction is available for the current
16853 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16854 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16855 vfp_or_neon_is_neon for the NEON specific checks. */
16856
16857static bfd_boolean
7df54120
AV
16858check_simd_pred_availability (int fp, unsigned check)
16859{
16860if (inst.cond > COND_ALWAYS)
16861 {
16862 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16863 {
16864 inst.error = BAD_FPU;
64c350f2 16865 return FALSE;
7df54120
AV
16866 }
16867 inst.pred_insn_type = INSIDE_VPT_INSN;
16868 }
16869else if (inst.cond < COND_ALWAYS)
16870 {
16871 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16872 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16873 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16874 return FALSE;
7df54120
AV
16875 }
16876else
16877 {
16878 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16879 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16880 return FALSE;
7df54120
AV
16881
16882 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16883 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16884 }
64c350f2 16885return TRUE;
7df54120
AV
16886}
16887
5287ad62
JB
16888/* Neon instruction encoders, in approximate order of appearance. */
16889
16890static void
16891do_neon_dyadic_i_su (void)
16892{
64c350f2 16893 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16894 return;
16895
16896 enum neon_shape rs;
16897 struct neon_type_el et;
16898 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16899 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16900 else
16901 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16902
16903 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16904
16905
16906 if (rs != NS_QQR)
16907 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16908 else
16909 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16910}
16911
16912static void
16913do_neon_dyadic_i64_su (void)
16914{
64c350f2 16915 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16916 return;
16917 enum neon_shape rs;
16918 struct neon_type_el et;
16919 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16920 {
16921 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16922 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16923 }
16924 else
16925 {
16926 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16927 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16928 }
16929 if (rs == NS_QQR)
16930 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16931 else
16932 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16933}
16934
16935static void
16936neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16937 unsigned immbits)
5287ad62
JB
16938{
16939 unsigned size = et.size >> 3;
16940 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16941 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16942 inst.instruction |= LOW4 (inst.operands[1].reg);
16943 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16944 inst.instruction |= (isquad != 0) << 6;
16945 inst.instruction |= immbits << 16;
16946 inst.instruction |= (size >> 3) << 7;
16947 inst.instruction |= (size & 0x7) << 19;
16948 if (write_ubit)
16949 inst.instruction |= (uval != 0) << 24;
16950
88714cb8 16951 neon_dp_fixup (&inst);
5287ad62
JB
16952}
16953
16954static void
5150f0d8 16955do_neon_shl (void)
5287ad62 16956{
64c350f2 16957 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16958 return;
16959
5287ad62
JB
16960 if (!inst.operands[2].isreg)
16961 {
5150f0d8
AV
16962 enum neon_shape rs;
16963 struct neon_type_el et;
16964 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16965 {
16966 rs = neon_select_shape (NS_QQI, NS_NULL);
16967 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16968 }
16969 else
16970 {
16971 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16972 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16973 }
cb3b1e65
JB
16974 int imm = inst.operands[2].imm;
16975
16976 constraint (imm < 0 || (unsigned)imm >= et.size,
16977 _("immediate out of range for shift"));
88714cb8 16978 NEON_ENCODE (IMMED, inst);
cb3b1e65 16979 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16980 }
16981 else
16982 {
5150f0d8
AV
16983 enum neon_shape rs;
16984 struct neon_type_el et;
16985 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16986 {
16987 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16988 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16989 }
16990 else
16991 {
16992 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16993 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16994 }
16995
16996
16997 if (rs == NS_QQR)
16998 {
16999 constraint (inst.operands[0].reg != inst.operands[1].reg,
17000 _("invalid instruction shape"));
17001 if (inst.operands[2].reg == REG_SP)
17002 as_tsktsk (MVE_BAD_SP);
17003 else if (inst.operands[2].reg == REG_PC)
17004 as_tsktsk (MVE_BAD_PC);
17005
17006 inst.instruction = 0xee311e60;
17007 inst.instruction |= (et.type == NT_unsigned) << 28;
17008 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17009 inst.instruction |= neon_logbits (et.size) << 18;
17010 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17011 inst.instruction |= inst.operands[2].reg;
17012 inst.is_neon = 1;
17013 }
17014 else
17015 {
17016 unsigned int tmp;
17017
17018 /* VSHL/VQSHL 3-register variants have syntax such as:
17019 vshl.xx Dd, Dm, Dn
17020 whereas other 3-register operations encoded by neon_three_same have
17021 syntax like:
17022 vadd.xx Dd, Dn, Dm
17023 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17024 operands[2].reg here. */
17025 tmp = inst.operands[2].reg;
17026 inst.operands[2].reg = inst.operands[1].reg;
17027 inst.operands[1].reg = tmp;
17028 NEON_ENCODE (INTEGER, inst);
17029 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17030 }
5287ad62
JB
17031 }
17032}
17033
17034static void
5150f0d8 17035do_neon_qshl (void)
5287ad62 17036{
64c350f2 17037 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
17038 return;
17039
5287ad62
JB
17040 if (!inst.operands[2].isreg)
17041 {
5150f0d8
AV
17042 enum neon_shape rs;
17043 struct neon_type_el et;
17044 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17045 {
17046 rs = neon_select_shape (NS_QQI, NS_NULL);
17047 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17048 }
17049 else
17050 {
17051 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17052 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17053 }
cb3b1e65 17054 int imm = inst.operands[2].imm;
627907b7 17055
cb3b1e65
JB
17056 constraint (imm < 0 || (unsigned)imm >= et.size,
17057 _("immediate out of range for shift"));
88714cb8 17058 NEON_ENCODE (IMMED, inst);
cb3b1e65 17059 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
17060 }
17061 else
17062 {
5150f0d8
AV
17063 enum neon_shape rs;
17064 struct neon_type_el et;
627907b7 17065
5150f0d8
AV
17066 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17067 {
17068 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17069 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17070 }
17071 else
17072 {
17073 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17074 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17075 }
17076
17077 if (rs == NS_QQR)
17078 {
17079 constraint (inst.operands[0].reg != inst.operands[1].reg,
17080 _("invalid instruction shape"));
17081 if (inst.operands[2].reg == REG_SP)
17082 as_tsktsk (MVE_BAD_SP);
17083 else if (inst.operands[2].reg == REG_PC)
17084 as_tsktsk (MVE_BAD_PC);
17085
17086 inst.instruction = 0xee311ee0;
17087 inst.instruction |= (et.type == NT_unsigned) << 28;
17088 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17089 inst.instruction |= neon_logbits (et.size) << 18;
17090 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17091 inst.instruction |= inst.operands[2].reg;
17092 inst.is_neon = 1;
17093 }
17094 else
17095 {
17096 unsigned int tmp;
17097
17098 /* See note in do_neon_shl. */
17099 tmp = inst.operands[2].reg;
17100 inst.operands[2].reg = inst.operands[1].reg;
17101 inst.operands[1].reg = tmp;
17102 NEON_ENCODE (INTEGER, inst);
17103 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17104 }
5287ad62
JB
17105 }
17106}
17107
627907b7
JB
17108static void
17109do_neon_rshl (void)
17110{
64c350f2 17111 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
17112 return;
17113
17114 enum neon_shape rs;
17115 struct neon_type_el et;
17116 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17117 {
17118 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17119 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17120 }
17121 else
17122 {
17123 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17124 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17125 }
17126
627907b7
JB
17127 unsigned int tmp;
17128
1be7aba3
AV
17129 if (rs == NS_QQR)
17130 {
17131 if (inst.operands[2].reg == REG_PC)
17132 as_tsktsk (MVE_BAD_PC);
17133 else if (inst.operands[2].reg == REG_SP)
17134 as_tsktsk (MVE_BAD_SP);
17135
17136 constraint (inst.operands[0].reg != inst.operands[1].reg,
17137 _("invalid instruction shape"));
17138
17139 if (inst.instruction == 0x0000510)
17140 /* We are dealing with vqrshl. */
17141 inst.instruction = 0xee331ee0;
17142 else
17143 /* We are dealing with vrshl. */
17144 inst.instruction = 0xee331e60;
17145
17146 inst.instruction |= (et.type == NT_unsigned) << 28;
17147 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17148 inst.instruction |= neon_logbits (et.size) << 18;
17149 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17150 inst.instruction |= inst.operands[2].reg;
17151 inst.is_neon = 1;
17152 }
17153 else
17154 {
17155 tmp = inst.operands[2].reg;
17156 inst.operands[2].reg = inst.operands[1].reg;
17157 inst.operands[1].reg = tmp;
17158 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17159 }
627907b7
JB
17160}
17161
5287ad62
JB
17162static int
17163neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17164{
036dc3f7
PB
17165 /* Handle .I8 pseudo-instructions. */
17166 if (size == 8)
5287ad62 17167 {
5287ad62 17168 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
17169 FIXME is this the intended semantics? There doesn't seem much point in
17170 accepting .I8 if so. */
5287ad62
JB
17171 immediate |= immediate << 8;
17172 size = 16;
036dc3f7
PB
17173 }
17174
17175 if (size >= 32)
17176 {
17177 if (immediate == (immediate & 0x000000ff))
17178 {
17179 *immbits = immediate;
17180 return 0x1;
17181 }
17182 else if (immediate == (immediate & 0x0000ff00))
17183 {
17184 *immbits = immediate >> 8;
17185 return 0x3;
17186 }
17187 else if (immediate == (immediate & 0x00ff0000))
17188 {
17189 *immbits = immediate >> 16;
17190 return 0x5;
17191 }
17192 else if (immediate == (immediate & 0xff000000))
17193 {
17194 *immbits = immediate >> 24;
17195 return 0x7;
17196 }
17197 if ((immediate & 0xffff) != (immediate >> 16))
17198 goto bad_immediate;
17199 immediate &= 0xffff;
5287ad62
JB
17200 }
17201
17202 if (immediate == (immediate & 0x000000ff))
17203 {
17204 *immbits = immediate;
036dc3f7 17205 return 0x9;
5287ad62
JB
17206 }
17207 else if (immediate == (immediate & 0x0000ff00))
17208 {
17209 *immbits = immediate >> 8;
036dc3f7 17210 return 0xb;
5287ad62
JB
17211 }
17212
17213 bad_immediate:
dcbf9037 17214 first_error (_("immediate value out of range"));
5287ad62
JB
17215 return FAIL;
17216}
17217
5287ad62
JB
17218static void
17219do_neon_logic (void)
17220{
17221 if (inst.operands[2].present && inst.operands[2].isreg)
17222 {
037e8744 17223 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17224 if (rs == NS_QQQ
64c350f2
AV
17225 && !check_simd_pred_availability (FALSE,
17226 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17227 return;
17228 else if (rs != NS_QQQ
17229 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17230 first_error (BAD_FPU);
17231
5287ad62
JB
17232 neon_check_type (3, rs, N_IGNORE_TYPE);
17233 /* U bit and size field were set as part of the bitmask. */
88714cb8 17234 NEON_ENCODE (INTEGER, inst);
037e8744 17235 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17236 }
17237 else
17238 {
4316f0d2
DG
17239 const int three_ops_form = (inst.operands[2].present
17240 && !inst.operands[2].isreg);
17241 const int immoperand = (three_ops_form ? 2 : 1);
17242 enum neon_shape rs = (three_ops_form
17243 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17244 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17245 /* Because neon_select_shape makes the second operand a copy of the first
17246 if the second operand is not present. */
17247 if (rs == NS_QQI
64c350f2
AV
17248 && !check_simd_pred_availability (FALSE,
17249 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17250 return;
17251 else if (rs != NS_QQI
17252 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17253 first_error (BAD_FPU);
17254
17255 struct neon_type_el et;
17256 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17257 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17258 else
17259 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17260 | N_KEY, N_EQK);
17261
17262 if (et.type == NT_invtype)
17263 return;
21d799b5 17264 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17265 unsigned immbits;
17266 int cmode;
5f4273c7 17267
5f4273c7 17268
4316f0d2
DG
17269 if (three_ops_form)
17270 constraint (inst.operands[0].reg != inst.operands[1].reg,
17271 _("first and second operands shall be the same register"));
17272
88714cb8 17273 NEON_ENCODE (IMMED, inst);
5287ad62 17274
4316f0d2 17275 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17276 if (et.size == 64)
17277 {
17278 /* .i64 is a pseudo-op, so the immediate must be a repeating
17279 pattern. */
4316f0d2
DG
17280 if (immbits != (inst.operands[immoperand].regisimm ?
17281 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17282 {
17283 /* Set immbits to an invalid constant. */
17284 immbits = 0xdeadbeef;
17285 }
17286 }
17287
5287ad62 17288 switch (opcode)
477330fc
RM
17289 {
17290 case N_MNEM_vbic:
17291 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17292 break;
17293
17294 case N_MNEM_vorr:
17295 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17296 break;
17297
17298 case N_MNEM_vand:
17299 /* Pseudo-instruction for VBIC. */
17300 neon_invert_size (&immbits, 0, et.size);
17301 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17302 break;
17303
17304 case N_MNEM_vorn:
17305 /* Pseudo-instruction for VORR. */
17306 neon_invert_size (&immbits, 0, et.size);
17307 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17308 break;
17309
17310 default:
17311 abort ();
17312 }
5287ad62
JB
17313
17314 if (cmode == FAIL)
477330fc 17315 return;
5287ad62 17316
037e8744 17317 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17318 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17319 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17320 inst.instruction |= cmode << 8;
17321 neon_write_immbits (immbits);
5f4273c7 17322
88714cb8 17323 neon_dp_fixup (&inst);
5287ad62
JB
17324 }
17325}
17326
17327static void
17328do_neon_bitfield (void)
17329{
037e8744 17330 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17331 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17332 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17333}
17334
17335static void
dcbf9037 17336neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17337 unsigned destbits)
5287ad62 17338{
5ee91343 17339 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17340 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17341 types | N_KEY);
5287ad62
JB
17342 if (et.type == NT_float)
17343 {
88714cb8 17344 NEON_ENCODE (FLOAT, inst);
5ee91343 17345 if (rs == NS_QQR)
7df54120 17346 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17347 else
17348 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17349 }
17350 else
17351 {
88714cb8 17352 NEON_ENCODE (INTEGER, inst);
5ee91343 17353 if (rs == NS_QQR)
a8465a06 17354 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17355 else
17356 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17357 }
17358}
17359
5287ad62
JB
17360
17361static void
17362do_neon_dyadic_if_su_d (void)
17363{
17364 /* This version only allow D registers, but that constraint is enforced during
17365 operand parsing so we don't need to do anything extra here. */
dcbf9037 17366 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17367}
17368
5287ad62
JB
17369static void
17370do_neon_dyadic_if_i_d (void)
17371{
428e3f1f
PB
17372 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17373 affected if we specify unsigned args. */
17374 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17375}
17376
f5f10c66
AV
17377static void
17378do_mve_vstr_vldr_QI (int size, int elsize, int load)
17379{
17380 constraint (size < 32, BAD_ADDR_MODE);
17381 constraint (size != elsize, BAD_EL_TYPE);
17382 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17383 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17384 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17385 _("destination register and offset register may not be the"
17386 " same"));
17387
17388 int imm = inst.relocs[0].exp.X_add_number;
17389 int add = 1;
17390 if (imm < 0)
17391 {
17392 add = 0;
17393 imm = -imm;
17394 }
17395 constraint ((imm % (size / 8) != 0)
17396 || imm > (0x7f << neon_logbits (size)),
17397 (size == 32) ? _("immediate must be a multiple of 4 in the"
17398 " range of +/-[0,508]")
17399 : _("immediate must be a multiple of 8 in the"
17400 " range of +/-[0,1016]"));
17401 inst.instruction |= 0x11 << 24;
17402 inst.instruction |= add << 23;
17403 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17404 inst.instruction |= inst.operands[1].writeback << 21;
17405 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17406 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17407 inst.instruction |= 1 << 12;
17408 inst.instruction |= (size == 64) << 8;
17409 inst.instruction &= 0xffffff00;
17410 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17411 inst.instruction |= imm >> neon_logbits (size);
17412}
17413
17414static void
17415do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17416{
17417 unsigned os = inst.operands[1].imm >> 5;
e449ea97 17418 unsigned type = inst.vectype.el[0].type;
f5f10c66
AV
17419 constraint (os != 0 && size == 8,
17420 _("can not shift offsets when accessing less than half-word"));
17421 constraint (os && os != neon_logbits (size),
17422 _("shift immediate must be 1, 2 or 3 for half-word, word"
17423 " or double-word accesses respectively"));
17424 if (inst.operands[1].reg == REG_PC)
17425 as_tsktsk (MVE_BAD_PC);
17426
17427 switch (size)
17428 {
17429 case 8:
17430 constraint (elsize >= 64, BAD_EL_TYPE);
17431 break;
17432 case 16:
17433 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17434 break;
17435 case 32:
17436 case 64:
17437 constraint (elsize != size, BAD_EL_TYPE);
17438 break;
17439 default:
17440 break;
17441 }
17442 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17443 BAD_ADDR_MODE);
17444 if (load)
17445 {
17446 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17447 _("destination register and offset register may not be"
17448 " the same"));
e449ea97
SP
17449 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17450 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
f5f10c66 17451 BAD_EL_TYPE);
e449ea97 17452 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
f5f10c66
AV
17453 }
17454 else
17455 {
e449ea97 17456 constraint (type != NT_untyped, BAD_EL_TYPE);
f5f10c66
AV
17457 }
17458
17459 inst.instruction |= 1 << 23;
17460 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17461 inst.instruction |= inst.operands[1].reg << 16;
17462 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17463 inst.instruction |= neon_logbits (elsize) << 7;
17464 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17465 inst.instruction |= LOW4 (inst.operands[1].imm);
17466 inst.instruction |= !!os;
17467}
17468
17469static void
17470do_mve_vstr_vldr_RI (int size, int elsize, int load)
17471{
17472 enum neon_el_type type = inst.vectype.el[0].type;
17473
17474 constraint (size >= 64, BAD_ADDR_MODE);
17475 switch (size)
17476 {
17477 case 16:
17478 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17479 break;
17480 case 32:
17481 constraint (elsize != size, BAD_EL_TYPE);
17482 break;
17483 default:
17484 break;
17485 }
17486 if (load)
17487 {
17488 constraint (elsize != size && type != NT_unsigned
17489 && type != NT_signed, BAD_EL_TYPE);
17490 }
17491 else
17492 {
17493 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17494 }
17495
17496 int imm = inst.relocs[0].exp.X_add_number;
17497 int add = 1;
17498 if (imm < 0)
17499 {
17500 add = 0;
17501 imm = -imm;
17502 }
17503
17504 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17505 {
17506 switch (size)
17507 {
17508 case 8:
17509 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17510 break;
17511 case 16:
17512 constraint (1, _("immediate must be a multiple of 2 in the"
17513 " range of +/-[0,254]"));
17514 break;
17515 case 32:
17516 constraint (1, _("immediate must be a multiple of 4 in the"
17517 " range of +/-[0,508]"));
17518 break;
17519 }
17520 }
17521
17522 if (size != elsize)
17523 {
17524 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17525 constraint (inst.operands[0].reg > 14,
17526 _("MVE vector register in the range [Q0..Q7] expected"));
17527 inst.instruction |= (load && type == NT_unsigned) << 28;
17528 inst.instruction |= (size == 16) << 19;
17529 inst.instruction |= neon_logbits (elsize) << 7;
17530 }
17531 else
17532 {
17533 if (inst.operands[1].reg == REG_PC)
17534 as_tsktsk (MVE_BAD_PC);
17535 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17536 as_tsktsk (MVE_BAD_SP);
17537 inst.instruction |= 1 << 12;
17538 inst.instruction |= neon_logbits (size) << 7;
17539 }
17540 inst.instruction |= inst.operands[1].preind << 24;
17541 inst.instruction |= add << 23;
17542 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17543 inst.instruction |= inst.operands[1].writeback << 21;
17544 inst.instruction |= inst.operands[1].reg << 16;
17545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17546 inst.instruction &= 0xffffff80;
17547 inst.instruction |= imm >> neon_logbits (size);
17548
17549}
17550
17551static void
17552do_mve_vstr_vldr (void)
17553{
17554 unsigned size;
17555 int load = 0;
17556
17557 if (inst.cond > COND_ALWAYS)
17558 inst.pred_insn_type = INSIDE_VPT_INSN;
17559 else
17560 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17561
17562 switch (inst.instruction)
17563 {
17564 default:
17565 gas_assert (0);
17566 break;
17567 case M_MNEM_vldrb:
17568 load = 1;
17569 /* fall through. */
17570 case M_MNEM_vstrb:
17571 size = 8;
17572 break;
17573 case M_MNEM_vldrh:
17574 load = 1;
17575 /* fall through. */
17576 case M_MNEM_vstrh:
17577 size = 16;
17578 break;
17579 case M_MNEM_vldrw:
17580 load = 1;
17581 /* fall through. */
17582 case M_MNEM_vstrw:
17583 size = 32;
17584 break;
17585 case M_MNEM_vldrd:
17586 load = 1;
17587 /* fall through. */
17588 case M_MNEM_vstrd:
17589 size = 64;
17590 break;
17591 }
17592 unsigned elsize = inst.vectype.el[0].size;
17593
17594 if (inst.operands[1].isquad)
17595 {
17596 /* We are dealing with [Q, imm]{!} cases. */
17597 do_mve_vstr_vldr_QI (size, elsize, load);
17598 }
17599 else
17600 {
17601 if (inst.operands[1].immisreg == 2)
17602 {
17603 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17604 do_mve_vstr_vldr_RQ (size, elsize, load);
17605 }
17606 else if (!inst.operands[1].immisreg)
17607 {
17608 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17609 do_mve_vstr_vldr_RI (size, elsize, load);
17610 }
17611 else
17612 constraint (1, BAD_ADDR_MODE);
17613 }
17614
17615 inst.is_neon = 1;
17616}
17617
35c228db
AV
17618static void
17619do_mve_vst_vld (void)
17620{
17621 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17622 return;
17623
17624 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17625 || inst.relocs[0].exp.X_add_number != 0
17626 || inst.operands[1].immisreg != 0,
17627 BAD_ADDR_MODE);
17628 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17629 if (inst.operands[1].reg == REG_PC)
17630 as_tsktsk (MVE_BAD_PC);
17631 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17632 as_tsktsk (MVE_BAD_SP);
17633
17634
17635 /* These instructions are one of the "exceptions" mentioned in
17636 handle_pred_state. They are MVE instructions that are not VPT compatible
17637 and do not accept a VPT code, thus appending such a code is a syntax
17638 error. */
17639 if (inst.cond > COND_ALWAYS)
17640 first_error (BAD_SYNTAX);
17641 /* If we append a scalar condition code we can set this to
17642 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17643 else if (inst.cond < COND_ALWAYS)
17644 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17645 else
17646 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17647
17648 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17649 inst.instruction |= inst.operands[1].writeback << 21;
17650 inst.instruction |= inst.operands[1].reg << 16;
17651 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17652 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17653 inst.is_neon = 1;
17654}
17655
26c1e780
AV
17656static void
17657do_mve_vaddlv (void)
17658{
17659 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17660 struct neon_type_el et
17661 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17662
17663 if (et.type == NT_invtype)
17664 first_error (BAD_EL_TYPE);
17665
17666 if (inst.cond > COND_ALWAYS)
17667 inst.pred_insn_type = INSIDE_VPT_INSN;
17668 else
17669 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17670
17671 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17672
17673 inst.instruction |= (et.type == NT_unsigned) << 28;
17674 inst.instruction |= inst.operands[1].reg << 19;
17675 inst.instruction |= inst.operands[0].reg << 12;
17676 inst.instruction |= inst.operands[2].reg;
17677 inst.is_neon = 1;
17678}
17679
5287ad62 17680static void
5ee91343 17681do_neon_dyadic_if_su (void)
5287ad62 17682{
5ee91343
AV
17683 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17684 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17685 N_SUF_32 | N_KEY);
17686
935295b5
AV
17687 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17688 || inst.instruction == ((unsigned) N_MNEM_vmin))
17689 && et.type == NT_float
17690 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17691
64c350f2
AV
17692 if (!check_simd_pred_availability (et.type == NT_float,
17693 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17694 return;
17695
5ee91343
AV
17696 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17697}
17698
17699static void
17700do_neon_addsub_if_i (void)
17701{
17702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17703 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17704 return;
17705
5ee91343
AV
17706 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17707 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17708 N_EQK, N_IF_32 | N_I64 | N_KEY);
17709
17710 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17711 /* If we are parsing Q registers and the element types match MVE, which NEON
17712 also supports, then we must check whether this is an instruction that can
17713 be used by both MVE/NEON. This distinction can be made based on whether
17714 they are predicated or not. */
17715 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17716 {
64c350f2
AV
17717 if (!check_simd_pred_availability (et.type == NT_float,
17718 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17719 return;
17720 }
17721 else
17722 {
17723 /* If they are either in a D register or are using an unsupported. */
17724 if (rs != NS_QQR
17725 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17726 return;
17727 }
17728
5287ad62
JB
17729 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17730 affected if we specify unsigned args. */
dcbf9037 17731 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17732}
17733
17734/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17735 result to be:
17736 V<op> A,B (A is operand 0, B is operand 2)
17737 to mean:
17738 V<op> A,B,A
17739 not:
17740 V<op> A,B,B
17741 so handle that case specially. */
17742
17743static void
17744neon_exchange_operands (void)
17745{
5287ad62
JB
17746 if (inst.operands[1].present)
17747 {
e1fa0163
NC
17748 void *scratch = xmalloc (sizeof (inst.operands[0]));
17749
5287ad62
JB
17750 /* Swap operands[1] and operands[2]. */
17751 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17752 inst.operands[1] = inst.operands[2];
17753 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17754 free (scratch);
5287ad62
JB
17755 }
17756 else
17757 {
17758 inst.operands[1] = inst.operands[2];
17759 inst.operands[2] = inst.operands[0];
17760 }
17761}
17762
17763static void
17764neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17765{
17766 if (inst.operands[2].isreg)
17767 {
17768 if (invert)
477330fc 17769 neon_exchange_operands ();
dcbf9037 17770 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17771 }
17772 else
17773 {
037e8744 17774 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17775 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17776 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17777
88714cb8 17778 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17779 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17780 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17781 inst.instruction |= LOW4 (inst.operands[1].reg);
17782 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17783 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17784 inst.instruction |= (et.type == NT_float) << 10;
17785 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17786
88714cb8 17787 neon_dp_fixup (&inst);
5287ad62
JB
17788 }
17789}
17790
17791static void
17792do_neon_cmp (void)
17793{
cc933301 17794 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17795}
17796
17797static void
17798do_neon_cmp_inv (void)
17799{
cc933301 17800 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17801}
17802
17803static void
17804do_neon_ceq (void)
17805{
17806 neon_compare (N_IF_32, N_IF_32, FALSE);
17807}
17808
17809/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17810 scalars, which are encoded in 5 bits, M : Rm.
17811 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17812 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17813 index in M.
17814
17815 Dot Product instructions are similar to multiply instructions except elsize
17816 should always be 32.
17817
17818 This function translates SCALAR, which is GAS's internal encoding of indexed
17819 scalar register, to raw encoding. There is also register and index range
17820 check based on ELSIZE. */
5287ad62
JB
17821
17822static unsigned
17823neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17824{
dcbf9037
JB
17825 unsigned regno = NEON_SCALAR_REG (scalar);
17826 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17827
17828 switch (elsize)
17829 {
17830 case 16:
17831 if (regno > 7 || elno > 3)
477330fc 17832 goto bad_scalar;
5287ad62 17833 return regno | (elno << 3);
5f4273c7 17834
5287ad62
JB
17835 case 32:
17836 if (regno > 15 || elno > 1)
477330fc 17837 goto bad_scalar;
5287ad62
JB
17838 return regno | (elno << 4);
17839
17840 default:
17841 bad_scalar:
dcbf9037 17842 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17843 }
17844
17845 return 0;
17846}
17847
17848/* Encode multiply / multiply-accumulate scalar instructions. */
17849
17850static void
17851neon_mul_mac (struct neon_type_el et, int ubit)
17852{
dcbf9037
JB
17853 unsigned scalar;
17854
17855 /* Give a more helpful error message if we have an invalid type. */
17856 if (et.type == NT_invtype)
17857 return;
5f4273c7 17858
dcbf9037 17859 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17860 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17861 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17862 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17863 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17864 inst.instruction |= LOW4 (scalar);
17865 inst.instruction |= HI1 (scalar) << 5;
17866 inst.instruction |= (et.type == NT_float) << 8;
17867 inst.instruction |= neon_logbits (et.size) << 20;
17868 inst.instruction |= (ubit != 0) << 24;
17869
88714cb8 17870 neon_dp_fixup (&inst);
5287ad62
JB
17871}
17872
17873static void
17874do_neon_mac_maybe_scalar (void)
17875{
037e8744
JB
17876 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17877 return;
17878
64c350f2 17879 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17880 return;
17881
5287ad62
JB
17882 if (inst.operands[2].isscalar)
17883 {
a8465a06 17884 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17885 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17886 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17887 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17888 NEON_ENCODE (SCALAR, inst);
037e8744 17889 neon_mul_mac (et, neon_quad (rs));
5287ad62 17890 }
a8465a06
AV
17891 else if (!inst.operands[2].isvec)
17892 {
17893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17894
17895 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17896 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17897
17898 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17899 }
5287ad62 17900 else
428e3f1f 17901 {
a8465a06 17902 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17903 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17904 affected if we specify unsigned args. */
17905 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17906 }
5287ad62
JB
17907}
17908
aab2c27d
MM
17909static void
17910do_bfloat_vfma (void)
17911{
17912 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17913 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17914 enum neon_shape rs;
17915 int t_bit = 0;
17916
17917 if (inst.instruction != B_MNEM_vfmab)
17918 {
17919 t_bit = 1;
17920 inst.instruction = B_MNEM_vfmat;
17921 }
17922
17923 if (inst.operands[2].isscalar)
17924 {
17925 rs = neon_select_shape (NS_QQS, NS_NULL);
17926 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17927
17928 inst.instruction |= (1 << 25);
17929 int index = inst.operands[2].reg & 0xf;
17930 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17931 inst.operands[2].reg >>= 4;
17932 constraint (!(inst.operands[2].reg < 8),
17933 _("indexed register must be less than 8"));
17934 neon_three_args (t_bit);
17935 inst.instruction |= ((index & 1) << 3);
17936 inst.instruction |= ((index & 2) << 4);
17937 }
17938 else
17939 {
17940 rs = neon_select_shape (NS_QQQ, NS_NULL);
17941 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17942 neon_three_args (t_bit);
17943 }
17944
17945}
17946
62f3b8c8
PB
17947static void
17948do_neon_fmac (void)
17949{
d58196e0
AV
17950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17951 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17952 return;
17953
64c350f2 17954 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17955 return;
17956
d58196e0
AV
17957 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17958 {
17959 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17960 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17961 N_EQK);
17962
17963 if (rs == NS_QQR)
17964 {
aab2c27d 17965
d58196e0
AV
17966 if (inst.operands[2].reg == REG_SP)
17967 as_tsktsk (MVE_BAD_SP);
17968 else if (inst.operands[2].reg == REG_PC)
17969 as_tsktsk (MVE_BAD_PC);
17970
17971 inst.instruction = 0xee310e40;
17972 inst.instruction |= (et.size == 16) << 28;
17973 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17974 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17975 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17976 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17977 inst.instruction |= inst.operands[2].reg;
17978 inst.is_neon = 1;
17979 return;
17980 }
17981 }
17982 else
17983 {
17984 constraint (!inst.operands[2].isvec, BAD_FPU);
17985 }
17986
62f3b8c8
PB
17987 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17988}
17989
aab2c27d
MM
17990static void
17991do_mve_vfma (void)
17992{
17993 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17994 inst.cond == COND_ALWAYS)
17995 {
17996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17997 inst.instruction = N_MNEM_vfma;
17998 inst.pred_insn_type = INSIDE_VPT_INSN;
17999 inst.cond = 0xf;
18000 return do_neon_fmac();
18001 }
18002 else
18003 {
18004 do_bfloat_vfma();
18005 }
18006}
18007
5287ad62
JB
18008static void
18009do_neon_tst (void)
18010{
037e8744 18011 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
18012 struct neon_type_el et = neon_check_type (3, rs,
18013 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 18014 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18015}
18016
18017/* VMUL with 3 registers allows the P8 type. The scalar version supports the
18018 same types as the MAC equivalents. The polynomial type for this instruction
18019 is encoded the same as the integer type. */
18020
18021static void
18022do_neon_mul (void)
18023{
037e8744
JB
18024 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18025 return;
18026
64c350f2 18027 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
18028 return;
18029
5287ad62 18030 if (inst.operands[2].isscalar)
a8465a06
AV
18031 {
18032 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18033 do_neon_mac_maybe_scalar ();
18034 }
5287ad62 18035 else
a8465a06
AV
18036 {
18037 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18038 {
18039 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18040 struct neon_type_el et
18041 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18042 if (et.type == NT_float)
18043 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18044 BAD_FPU);
18045
18046 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18047 }
18048 else
18049 {
18050 constraint (!inst.operands[2].isvec, BAD_FPU);
18051 neon_dyadic_misc (NT_poly,
18052 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18053 }
18054 }
5287ad62
JB
18055}
18056
18057static void
18058do_neon_qdmulh (void)
18059{
64c350f2 18060 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18061 return;
18062
5287ad62
JB
18063 if (inst.operands[2].isscalar)
18064 {
42b16635 18065 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 18066 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 18067 struct neon_type_el et = neon_check_type (3, rs,
477330fc 18068 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 18069 NEON_ENCODE (SCALAR, inst);
037e8744 18070 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
18071 }
18072 else
18073 {
42b16635
AV
18074 enum neon_shape rs;
18075 struct neon_type_el et;
18076 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18077 {
18078 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18079 et = neon_check_type (3, rs,
18080 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18081 }
18082 else
18083 {
18084 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18085 et = neon_check_type (3, rs,
18086 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18087 }
18088
88714cb8 18089 NEON_ENCODE (INTEGER, inst);
42b16635
AV
18090 if (rs == NS_QQR)
18091 mve_encode_qqr (et.size, 0, 0);
18092 else
18093 /* The U bit (rounding) comes from bit mask. */
18094 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18095 }
18096}
18097
26c1e780
AV
18098static void
18099do_mve_vaddv (void)
18100{
18101 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18102 struct neon_type_el et
18103 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18104
18105 if (et.type == NT_invtype)
18106 first_error (BAD_EL_TYPE);
18107
18108 if (inst.cond > COND_ALWAYS)
18109 inst.pred_insn_type = INSIDE_VPT_INSN;
18110 else
18111 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18112
18113 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18114
18115 mve_encode_rq (et.type == NT_unsigned, et.size);
18116}
18117
7df54120
AV
18118static void
18119do_mve_vhcadd (void)
18120{
18121 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18122 struct neon_type_el et
18123 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18124
18125 if (inst.cond > COND_ALWAYS)
18126 inst.pred_insn_type = INSIDE_VPT_INSN;
18127 else
18128 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18129
18130 unsigned rot = inst.relocs[0].exp.X_add_number;
18131 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18132
18133 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18134 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18135 "operand makes instruction UNPREDICTABLE"));
18136
18137 mve_encode_qqq (0, et.size);
18138 inst.instruction |= (rot == 270) << 12;
18139 inst.is_neon = 1;
18140}
18141
35d1cfc2
AV
18142static void
18143do_mve_vqdmull (void)
18144{
18145 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18146 struct neon_type_el et
18147 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18148
18149 if (et.size == 32
18150 && (inst.operands[0].reg == inst.operands[1].reg
18151 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18152 as_tsktsk (BAD_MVE_SRCDEST);
18153
18154 if (inst.cond > COND_ALWAYS)
18155 inst.pred_insn_type = INSIDE_VPT_INSN;
18156 else
18157 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18158
18159 if (rs == NS_QQQ)
18160 {
18161 mve_encode_qqq (et.size == 32, 64);
18162 inst.instruction |= 1;
18163 }
18164 else
18165 {
18166 mve_encode_qqr (64, et.size == 32, 0);
18167 inst.instruction |= 0x3 << 5;
18168 }
18169}
18170
c2dafc2a
AV
18171static void
18172do_mve_vadc (void)
18173{
18174 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18175 struct neon_type_el et
18176 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18177
18178 if (et.type == NT_invtype)
18179 first_error (BAD_EL_TYPE);
18180
18181 if (inst.cond > COND_ALWAYS)
18182 inst.pred_insn_type = INSIDE_VPT_INSN;
18183 else
18184 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18185
18186 mve_encode_qqq (0, 64);
18187}
18188
18189static void
18190do_mve_vbrsr (void)
18191{
18192 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18193 struct neon_type_el et
18194 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18195
18196 if (inst.cond > COND_ALWAYS)
18197 inst.pred_insn_type = INSIDE_VPT_INSN;
18198 else
18199 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18200
7df54120 18201 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
18202}
18203
18204static void
18205do_mve_vsbc (void)
18206{
18207 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18208
18209 if (inst.cond > COND_ALWAYS)
18210 inst.pred_insn_type = INSIDE_VPT_INSN;
18211 else
18212 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18213
18214 mve_encode_qqq (1, 64);
18215}
18216
2d78f95b
AV
18217static void
18218do_mve_vmulh (void)
18219{
18220 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18221 struct neon_type_el et
18222 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18223
18224 if (inst.cond > COND_ALWAYS)
18225 inst.pred_insn_type = INSIDE_VPT_INSN;
18226 else
18227 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18228
18229 mve_encode_qqq (et.type == NT_unsigned, et.size);
18230}
18231
42b16635
AV
18232static void
18233do_mve_vqdmlah (void)
18234{
18235 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18236 struct neon_type_el et
23d188c7 18237 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
18238
18239 if (inst.cond > COND_ALWAYS)
18240 inst.pred_insn_type = INSIDE_VPT_INSN;
18241 else
18242 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18243
18244 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18245}
8b8b22a4
AV
18246
18247static void
18248do_mve_vqdmladh (void)
18249{
18250 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18251 struct neon_type_el et
18252 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18253
18254 if (inst.cond > COND_ALWAYS)
18255 inst.pred_insn_type = INSIDE_VPT_INSN;
18256 else
18257 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18258
8b8b22a4
AV
18259 mve_encode_qqq (0, et.size);
18260}
18261
18262
886e1c73
AV
18263static void
18264do_mve_vmull (void)
18265{
18266
18267 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18268 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18269 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18270 && inst.cond == COND_ALWAYS
18271 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18272 {
18273 if (rs == NS_QQQ)
18274 {
18275
18276 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18277 N_SUF_32 | N_F64 | N_P8
18278 | N_P16 | N_I_MVE | N_KEY);
18279 if (((et.type == NT_poly) && et.size == 8
18280 && ARM_CPU_IS_ANY (cpu_variant))
18281 || (et.type == NT_integer) || (et.type == NT_float))
18282 goto neon_vmul;
18283 }
18284 else
18285 goto neon_vmul;
18286 }
18287
18288 constraint (rs != NS_QQQ, BAD_FPU);
18289 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18290 N_SU_32 | N_P8 | N_P16 | N_KEY);
18291
18292 /* We are dealing with MVE's vmullt. */
18293 if (et.size == 32
18294 && (inst.operands[0].reg == inst.operands[1].reg
18295 || inst.operands[0].reg == inst.operands[2].reg))
18296 as_tsktsk (BAD_MVE_SRCDEST);
18297
18298 if (inst.cond > COND_ALWAYS)
18299 inst.pred_insn_type = INSIDE_VPT_INSN;
18300 else
18301 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18302
18303 if (et.type == NT_poly)
18304 mve_encode_qqq (neon_logbits (et.size), 64);
18305 else
18306 mve_encode_qqq (et.type == NT_unsigned, et.size);
18307
18308 return;
18309
18310neon_vmul:
18311 inst.instruction = N_MNEM_vmul;
18312 inst.cond = 0xb;
18313 if (thumb_mode)
18314 inst.pred_insn_type = INSIDE_IT_INSN;
18315 do_neon_mul ();
18316}
18317
a302e574
AV
18318static void
18319do_mve_vabav (void)
18320{
18321 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18322
18323 if (rs == NS_NULL)
18324 return;
18325
18326 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18327 return;
18328
18329 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18330 | N_S16 | N_S32 | N_U8 | N_U16
18331 | N_U32);
18332
18333 if (inst.cond > COND_ALWAYS)
18334 inst.pred_insn_type = INSIDE_VPT_INSN;
18335 else
18336 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18337
18338 mve_encode_rqq (et.type == NT_unsigned, et.size);
18339}
18340
18341static void
18342do_mve_vmladav (void)
18343{
18344 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18345 struct neon_type_el et = neon_check_type (3, rs,
18346 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18347
18348 if (et.type == NT_unsigned
18349 && (inst.instruction == M_MNEM_vmladavx
18350 || inst.instruction == M_MNEM_vmladavax
18351 || inst.instruction == M_MNEM_vmlsdav
18352 || inst.instruction == M_MNEM_vmlsdava
18353 || inst.instruction == M_MNEM_vmlsdavx
18354 || inst.instruction == M_MNEM_vmlsdavax))
18355 first_error (BAD_SIMD_TYPE);
18356
18357 constraint (inst.operands[2].reg > 14,
18358 _("MVE vector register in the range [Q0..Q7] expected"));
18359
18360 if (inst.cond > COND_ALWAYS)
18361 inst.pred_insn_type = INSIDE_VPT_INSN;
18362 else
18363 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18364
18365 if (inst.instruction == M_MNEM_vmlsdav
18366 || inst.instruction == M_MNEM_vmlsdava
18367 || inst.instruction == M_MNEM_vmlsdavx
18368 || inst.instruction == M_MNEM_vmlsdavax)
18369 inst.instruction |= (et.size == 8) << 28;
18370 else
18371 inst.instruction |= (et.size == 8) << 8;
18372
18373 mve_encode_rqq (et.type == NT_unsigned, 64);
18374 inst.instruction |= (et.size == 32) << 16;
18375}
18376
93925576
AV
18377static void
18378do_mve_vmlaldav (void)
18379{
18380 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18381 struct neon_type_el et
18382 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18383 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18384
18385 if (et.type == NT_unsigned
18386 && (inst.instruction == M_MNEM_vmlsldav
18387 || inst.instruction == M_MNEM_vmlsldava
18388 || inst.instruction == M_MNEM_vmlsldavx
18389 || inst.instruction == M_MNEM_vmlsldavax))
18390 first_error (BAD_SIMD_TYPE);
18391
18392 if (inst.cond > COND_ALWAYS)
18393 inst.pred_insn_type = INSIDE_VPT_INSN;
18394 else
18395 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18396
18397 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18398}
18399
18400static void
18401do_mve_vrmlaldavh (void)
18402{
18403 struct neon_type_el et;
18404 if (inst.instruction == M_MNEM_vrmlsldavh
18405 || inst.instruction == M_MNEM_vrmlsldavha
18406 || inst.instruction == M_MNEM_vrmlsldavhx
18407 || inst.instruction == M_MNEM_vrmlsldavhax)
18408 {
18409 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18410 if (inst.operands[1].reg == REG_SP)
18411 as_tsktsk (MVE_BAD_SP);
18412 }
18413 else
18414 {
18415 if (inst.instruction == M_MNEM_vrmlaldavhx
18416 || inst.instruction == M_MNEM_vrmlaldavhax)
18417 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18418 else
18419 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18420 N_U32 | N_S32 | N_KEY);
18421 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18422 with vmax/min instructions, making the use of SP in assembly really
18423 nonsensical, so instead of issuing a warning like we do for other uses
18424 of SP for the odd register operand we error out. */
18425 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18426 }
18427
18428 /* Make sure we still check the second operand is an odd one and that PC is
18429 disallowed. This because we are parsing for any GPR operand, to be able
18430 to distinguish between giving a warning or an error for SP as described
18431 above. */
18432 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18433 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18434
18435 if (inst.cond > COND_ALWAYS)
18436 inst.pred_insn_type = INSIDE_VPT_INSN;
18437 else
18438 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18439
18440 mve_encode_rrqq (et.type == NT_unsigned, 0);
18441}
18442
18443
8cd78170
AV
18444static void
18445do_mve_vmaxnmv (void)
18446{
18447 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18448 struct neon_type_el et
18449 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18450
18451 if (inst.cond > COND_ALWAYS)
18452 inst.pred_insn_type = INSIDE_VPT_INSN;
18453 else
18454 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18455
18456 if (inst.operands[0].reg == REG_SP)
18457 as_tsktsk (MVE_BAD_SP);
18458 else if (inst.operands[0].reg == REG_PC)
18459 as_tsktsk (MVE_BAD_PC);
18460
18461 mve_encode_rq (et.size == 16, 64);
18462}
18463
13ccd4c0
AV
18464static void
18465do_mve_vmaxv (void)
18466{
18467 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18468 struct neon_type_el et;
18469
18470 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18471 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18472 else
18473 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18474
18475 if (inst.cond > COND_ALWAYS)
18476 inst.pred_insn_type = INSIDE_VPT_INSN;
18477 else
18478 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18479
18480 if (inst.operands[0].reg == REG_SP)
18481 as_tsktsk (MVE_BAD_SP);
18482 else if (inst.operands[0].reg == REG_PC)
18483 as_tsktsk (MVE_BAD_PC);
18484
18485 mve_encode_rq (et.type == NT_unsigned, et.size);
18486}
18487
18488
643afb90
MW
18489static void
18490do_neon_qrdmlah (void)
18491{
64c350f2 18492 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18493 return;
18494 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18495 {
42b16635
AV
18496 /* Check we're on the correct architecture. */
18497 if (!mark_feature_used (&fpu_neon_ext_armv8))
18498 inst.error
18499 = _("instruction form not available on this architecture.");
18500 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18501 {
18502 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18503 record_feature_use (&fpu_neon_ext_v8_1);
18504 }
18505 if (inst.operands[2].isscalar)
18506 {
18507 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18508 struct neon_type_el et = neon_check_type (3, rs,
18509 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18510 NEON_ENCODE (SCALAR, inst);
18511 neon_mul_mac (et, neon_quad (rs));
18512 }
18513 else
18514 {
18515 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18516 struct neon_type_el et = neon_check_type (3, rs,
18517 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18518 NEON_ENCODE (INTEGER, inst);
18519 /* The U bit (rounding) comes from bit mask. */
18520 neon_three_same (neon_quad (rs), 0, et.size);
18521 }
643afb90
MW
18522 }
18523 else
18524 {
42b16635
AV
18525 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18526 struct neon_type_el et
23d188c7 18527 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18528
643afb90 18529 NEON_ENCODE (INTEGER, inst);
42b16635 18530 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18531 }
18532}
18533
5287ad62
JB
18534static void
18535do_neon_fcmp_absolute (void)
18536{
037e8744 18537 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18538 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18539 N_F_16_32 | N_KEY);
5287ad62 18540 /* Size field comes from bit mask. */
cc933301 18541 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18542}
18543
18544static void
18545do_neon_fcmp_absolute_inv (void)
18546{
18547 neon_exchange_operands ();
18548 do_neon_fcmp_absolute ();
18549}
18550
18551static void
18552do_neon_step (void)
18553{
037e8744 18554 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18555 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18556 N_F_16_32 | N_KEY);
18557 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18558}
18559
18560static void
18561do_neon_abs_neg (void)
18562{
037e8744
JB
18563 enum neon_shape rs;
18564 struct neon_type_el et;
5f4273c7 18565
037e8744
JB
18566 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18567 return;
18568
037e8744 18569 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18570 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18571
64c350f2
AV
18572 if (!check_simd_pred_availability (et.type == NT_float,
18573 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18574 return;
18575
5287ad62
JB
18576 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18577 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18578 inst.instruction |= LOW4 (inst.operands[1].reg);
18579 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18580 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18581 inst.instruction |= (et.type == NT_float) << 10;
18582 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18583
88714cb8 18584 neon_dp_fixup (&inst);
5287ad62
JB
18585}
18586
18587static void
18588do_neon_sli (void)
18589{
64c350f2 18590 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18591 return;
18592
18593 enum neon_shape rs;
18594 struct neon_type_el et;
18595 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18596 {
18597 rs = neon_select_shape (NS_QQI, NS_NULL);
18598 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18599 }
18600 else
18601 {
18602 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18603 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18604 }
18605
18606
5287ad62
JB
18607 int imm = inst.operands[2].imm;
18608 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18609 _("immediate out of range for insert"));
037e8744 18610 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18611}
18612
18613static void
18614do_neon_sri (void)
18615{
64c350f2 18616 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18617 return;
18618
18619 enum neon_shape rs;
18620 struct neon_type_el et;
18621 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18622 {
18623 rs = neon_select_shape (NS_QQI, NS_NULL);
18624 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18625 }
18626 else
18627 {
18628 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18629 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18630 }
18631
5287ad62
JB
18632 int imm = inst.operands[2].imm;
18633 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18634 _("immediate out of range for insert"));
037e8744 18635 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18636}
18637
18638static void
18639do_neon_qshlu_imm (void)
18640{
64c350f2 18641 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18642 return;
18643
18644 enum neon_shape rs;
18645 struct neon_type_el et;
18646 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18647 {
18648 rs = neon_select_shape (NS_QQI, NS_NULL);
18649 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18650 }
18651 else
18652 {
18653 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18654 et = neon_check_type (2, rs, N_EQK | N_UNS,
18655 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18656 }
18657
5287ad62
JB
18658 int imm = inst.operands[2].imm;
18659 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18660 _("immediate out of range for shift"));
5287ad62
JB
18661 /* Only encodes the 'U present' variant of the instruction.
18662 In this case, signed types have OP (bit 8) set to 0.
18663 Unsigned types have OP set to 1. */
18664 inst.instruction |= (et.type == NT_unsigned) << 8;
18665 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18666 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18667}
18668
18669static void
18670do_neon_qmovn (void)
18671{
18672 struct neon_type_el et = neon_check_type (2, NS_DQ,
18673 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18674 /* Saturating move where operands can be signed or unsigned, and the
18675 destination has the same signedness. */
88714cb8 18676 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18677 if (et.type == NT_unsigned)
18678 inst.instruction |= 0xc0;
18679 else
18680 inst.instruction |= 0x80;
18681 neon_two_same (0, 1, et.size / 2);
18682}
18683
18684static void
18685do_neon_qmovun (void)
18686{
18687 struct neon_type_el et = neon_check_type (2, NS_DQ,
18688 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18689 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18690 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18691 neon_two_same (0, 1, et.size / 2);
18692}
18693
18694static void
18695do_neon_rshift_sat_narrow (void)
18696{
18697 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18698 or unsigned. If operands are unsigned, results must also be unsigned. */
18699 struct neon_type_el et = neon_check_type (2, NS_DQI,
18700 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18701 int imm = inst.operands[2].imm;
18702 /* This gets the bounds check, size encoding and immediate bits calculation
18703 right. */
18704 et.size /= 2;
5f4273c7 18705
5287ad62
JB
18706 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18707 VQMOVN.I<size> <Dd>, <Qm>. */
18708 if (imm == 0)
18709 {
18710 inst.operands[2].present = 0;
18711 inst.instruction = N_MNEM_vqmovn;
18712 do_neon_qmovn ();
18713 return;
18714 }
5f4273c7 18715
5287ad62 18716 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18717 _("immediate out of range"));
5287ad62
JB
18718 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18719}
18720
18721static void
18722do_neon_rshift_sat_narrow_u (void)
18723{
18724 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18725 or unsigned. If operands are unsigned, results must also be unsigned. */
18726 struct neon_type_el et = neon_check_type (2, NS_DQI,
18727 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18728 int imm = inst.operands[2].imm;
18729 /* This gets the bounds check, size encoding and immediate bits calculation
18730 right. */
18731 et.size /= 2;
18732
18733 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18734 VQMOVUN.I<size> <Dd>, <Qm>. */
18735 if (imm == 0)
18736 {
18737 inst.operands[2].present = 0;
18738 inst.instruction = N_MNEM_vqmovun;
18739 do_neon_qmovun ();
18740 return;
18741 }
18742
18743 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18744 _("immediate out of range"));
5287ad62
JB
18745 /* FIXME: The manual is kind of unclear about what value U should have in
18746 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18747 must be 1. */
18748 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18749}
18750
18751static void
18752do_neon_movn (void)
18753{
18754 struct neon_type_el et = neon_check_type (2, NS_DQ,
18755 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18756 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18757 neon_two_same (0, 1, et.size / 2);
18758}
18759
18760static void
18761do_neon_rshift_narrow (void)
18762{
18763 struct neon_type_el et = neon_check_type (2, NS_DQI,
18764 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18765 int imm = inst.operands[2].imm;
18766 /* This gets the bounds check, size encoding and immediate bits calculation
18767 right. */
18768 et.size /= 2;
5f4273c7 18769
5287ad62
JB
18770 /* If immediate is zero then we are a pseudo-instruction for
18771 VMOVN.I<size> <Dd>, <Qm> */
18772 if (imm == 0)
18773 {
18774 inst.operands[2].present = 0;
18775 inst.instruction = N_MNEM_vmovn;
18776 do_neon_movn ();
18777 return;
18778 }
5f4273c7 18779
5287ad62 18780 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18781 _("immediate out of range for narrowing operation"));
5287ad62
JB
18782 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18783}
18784
18785static void
18786do_neon_shll (void)
18787{
18788 /* FIXME: Type checking when lengthening. */
18789 struct neon_type_el et = neon_check_type (2, NS_QDI,
18790 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18791 unsigned imm = inst.operands[2].imm;
18792
18793 if (imm == et.size)
18794 {
18795 /* Maximum shift variant. */
88714cb8 18796 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18797 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18798 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18799 inst.instruction |= LOW4 (inst.operands[1].reg);
18800 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18801 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18802
88714cb8 18803 neon_dp_fixup (&inst);
5287ad62
JB
18804 }
18805 else
18806 {
18807 /* A more-specific type check for non-max versions. */
18808 et = neon_check_type (2, NS_QDI,
477330fc 18809 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18810 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18811 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18812 }
18813}
18814
037e8744 18815/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18816 the current instruction is. */
18817
6b9a8b67
MGD
18818#define CVT_FLAVOUR_VAR \
18819 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18820 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18821 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18822 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18823 /* Half-precision conversions. */ \
cc933301
JW
18824 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18825 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18826 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18827 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18828 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18829 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18830 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18831 Compared with single/double precision variants, only the co-processor \
18832 field is different, so the encoding flow is reused here. */ \
18833 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18834 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18835 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18836 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
aab2c27d 18837 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18838 /* VFP instructions. */ \
18839 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18840 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18841 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18842 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18843 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18844 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18845 /* VFP instructions with bitshift. */ \
18846 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18847 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18848 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18849 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18850 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18851 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18852 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18853 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18854
18855#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18856 neon_cvt_flavour_##C,
18857
18858/* The different types of conversions we can do. */
18859enum neon_cvt_flavour
18860{
18861 CVT_FLAVOUR_VAR
18862 neon_cvt_flavour_invalid,
18863 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18864};
18865
18866#undef CVT_VAR
18867
18868static enum neon_cvt_flavour
18869get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18870{
6b9a8b67
MGD
18871#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18872 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18873 if (et.type != NT_invtype) \
18874 { \
18875 inst.error = NULL; \
18876 return (neon_cvt_flavour_##C); \
5287ad62 18877 }
6b9a8b67 18878
5287ad62 18879 struct neon_type_el et;
037e8744 18880 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18881 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18882 /* The instruction versions which take an immediate take one register
18883 argument, which is extended to the width of the full register. Thus the
18884 "source" and "destination" registers must have the same width. Hack that
18885 here by making the size equal to the key (wider, in this case) operand. */
18886 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18887
6b9a8b67
MGD
18888 CVT_FLAVOUR_VAR;
18889
18890 return neon_cvt_flavour_invalid;
5287ad62
JB
18891#undef CVT_VAR
18892}
18893
7e8e6784
MGD
18894enum neon_cvt_mode
18895{
18896 neon_cvt_mode_a,
18897 neon_cvt_mode_n,
18898 neon_cvt_mode_p,
18899 neon_cvt_mode_m,
18900 neon_cvt_mode_z,
30bdf752
MGD
18901 neon_cvt_mode_x,
18902 neon_cvt_mode_r
7e8e6784
MGD
18903};
18904
037e8744
JB
18905/* Neon-syntax VFP conversions. */
18906
5287ad62 18907static void
6b9a8b67 18908do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18909{
037e8744 18910 const char *opname = 0;
5f4273c7 18911
d54af2d0
RL
18912 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18913 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18914 {
037e8744
JB
18915 /* Conversions with immediate bitshift. */
18916 const char *enc[] =
477330fc 18917 {
6b9a8b67
MGD
18918#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18919 CVT_FLAVOUR_VAR
18920 NULL
18921#undef CVT_VAR
477330fc 18922 };
037e8744 18923
6b9a8b67 18924 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18925 {
18926 opname = enc[flavour];
18927 constraint (inst.operands[0].reg != inst.operands[1].reg,
18928 _("operands 0 and 1 must be the same register"));
18929 inst.operands[1] = inst.operands[2];
18930 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18931 }
5287ad62
JB
18932 }
18933 else
18934 {
037e8744
JB
18935 /* Conversions without bitshift. */
18936 const char *enc[] =
477330fc 18937 {
6b9a8b67
MGD
18938#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18939 CVT_FLAVOUR_VAR
18940 NULL
18941#undef CVT_VAR
477330fc 18942 };
037e8744 18943
6b9a8b67 18944 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18945 opname = enc[flavour];
037e8744
JB
18946 }
18947
18948 if (opname)
18949 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18950
18951 /* ARMv8.2 fp16 VCVT instruction. */
18952 if (flavour == neon_cvt_flavour_s32_f16
18953 || flavour == neon_cvt_flavour_u32_f16
18954 || flavour == neon_cvt_flavour_f16_u32
18955 || flavour == neon_cvt_flavour_f16_s32)
18956 do_scalar_fp16_v82_encode ();
037e8744
JB
18957}
18958
18959static void
18960do_vfp_nsyn_cvtz (void)
18961{
d54af2d0 18962 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18963 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18964 const char *enc[] =
18965 {
6b9a8b67
MGD
18966#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18967 CVT_FLAVOUR_VAR
18968 NULL
18969#undef CVT_VAR
037e8744
JB
18970 };
18971
6b9a8b67 18972 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18973 do_vfp_nsyn_opcode (enc[flavour]);
18974}
f31fef98 18975
037e8744 18976static void
bacebabc 18977do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18978 enum neon_cvt_mode mode)
18979{
18980 int sz, op;
18981 int rm;
18982
a715796b
TG
18983 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18984 D register operands. */
18985 if (flavour == neon_cvt_flavour_s32_f64
18986 || flavour == neon_cvt_flavour_u32_f64)
18987 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18988 _(BAD_FPU));
18989
9db2f6b4
RL
18990 if (flavour == neon_cvt_flavour_s32_f16
18991 || flavour == neon_cvt_flavour_u32_f16)
18992 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18993 _(BAD_FP16));
18994
5ee91343 18995 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18996
18997 switch (flavour)
18998 {
18999 case neon_cvt_flavour_s32_f64:
19000 sz = 1;
827f64ff 19001 op = 1;
7e8e6784
MGD
19002 break;
19003 case neon_cvt_flavour_s32_f32:
19004 sz = 0;
19005 op = 1;
19006 break;
9db2f6b4
RL
19007 case neon_cvt_flavour_s32_f16:
19008 sz = 0;
19009 op = 1;
19010 break;
7e8e6784
MGD
19011 case neon_cvt_flavour_u32_f64:
19012 sz = 1;
19013 op = 0;
19014 break;
19015 case neon_cvt_flavour_u32_f32:
19016 sz = 0;
19017 op = 0;
19018 break;
9db2f6b4
RL
19019 case neon_cvt_flavour_u32_f16:
19020 sz = 0;
19021 op = 0;
19022 break;
7e8e6784
MGD
19023 default:
19024 first_error (_("invalid instruction shape"));
19025 return;
19026 }
19027
19028 switch (mode)
19029 {
19030 case neon_cvt_mode_a: rm = 0; break;
19031 case neon_cvt_mode_n: rm = 1; break;
19032 case neon_cvt_mode_p: rm = 2; break;
19033 case neon_cvt_mode_m: rm = 3; break;
19034 default: first_error (_("invalid rounding mode")); return;
19035 }
19036
19037 NEON_ENCODE (FPV8, inst);
19038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19039 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19040 inst.instruction |= sz << 8;
9db2f6b4
RL
19041
19042 /* ARMv8.2 fp16 VCVT instruction. */
19043 if (flavour == neon_cvt_flavour_s32_f16
19044 ||flavour == neon_cvt_flavour_u32_f16)
19045 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
19046 inst.instruction |= op << 7;
19047 inst.instruction |= rm << 16;
19048 inst.instruction |= 0xf0000000;
19049 inst.is_neon = TRUE;
19050}
19051
19052static void
19053do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
19054{
19055 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
19056 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19057 NS_FH, NS_HF, NS_FHI, NS_HFI,
19058 NS_NULL);
6b9a8b67 19059 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 19060
cc933301
JW
19061 if (flavour == neon_cvt_flavour_invalid)
19062 return;
19063
e3e535bc 19064 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 19065 if (mode == neon_cvt_mode_z
e3e535bc 19066 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
19067 && (flavour == neon_cvt_flavour_s16_f16
19068 || flavour == neon_cvt_flavour_u16_f16
19069 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
19070 || flavour == neon_cvt_flavour_u32_f32
19071 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 19072 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
19073 && (rs == NS_FD || rs == NS_FF))
19074 {
19075 do_vfp_nsyn_cvtz ();
19076 return;
19077 }
19078
9db2f6b4
RL
19079 /* ARMv8.2 fp16 VCVT conversions. */
19080 if (mode == neon_cvt_mode_z
19081 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19082 && (flavour == neon_cvt_flavour_s32_f16
19083 || flavour == neon_cvt_flavour_u32_f16)
19084 && (rs == NS_FH))
19085 {
19086 do_vfp_nsyn_cvtz ();
19087 do_scalar_fp16_v82_encode ();
19088 return;
19089 }
19090
037e8744 19091 /* VFP rather than Neon conversions. */
6b9a8b67 19092 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 19093 {
7e8e6784
MGD
19094 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19095 do_vfp_nsyn_cvt (rs, flavour);
19096 else
19097 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19098
037e8744
JB
19099 return;
19100 }
19101
19102 switch (rs)
19103 {
037e8744 19104 case NS_QQI:
dd9634d9
AV
19105 if (mode == neon_cvt_mode_z
19106 && (flavour == neon_cvt_flavour_f16_s16
19107 || flavour == neon_cvt_flavour_f16_u16
19108 || flavour == neon_cvt_flavour_s16_f16
19109 || flavour == neon_cvt_flavour_u16_f16
19110 || flavour == neon_cvt_flavour_f32_u32
19111 || flavour == neon_cvt_flavour_f32_s32
19112 || flavour == neon_cvt_flavour_s32_f32
19113 || flavour == neon_cvt_flavour_u32_f32))
19114 {
64c350f2
AV
19115 if (!check_simd_pred_availability (TRUE,
19116 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19117 return;
19118 }
19119 else if (mode == neon_cvt_mode_n)
19120 {
19121 /* We are dealing with vcvt with the 'ne' condition. */
19122 inst.cond = 0x1;
19123 inst.instruction = N_MNEM_vcvt;
19124 do_neon_cvt_1 (neon_cvt_mode_z);
19125 return;
19126 }
19127 /* fall through. */
19128 case NS_DDI:
037e8744 19129 {
477330fc 19130 unsigned immbits;
cc933301
JW
19131 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19132 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 19133
dd9634d9
AV
19134 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19135 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19136 return;
19137
19138 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19139 {
19140 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19141 _("immediate value out of range"));
19142 switch (flavour)
19143 {
19144 case neon_cvt_flavour_f16_s16:
19145 case neon_cvt_flavour_f16_u16:
19146 case neon_cvt_flavour_s16_f16:
19147 case neon_cvt_flavour_u16_f16:
19148 constraint (inst.operands[2].imm > 16,
19149 _("immediate value out of range"));
19150 break;
19151 case neon_cvt_flavour_f32_u32:
19152 case neon_cvt_flavour_f32_s32:
19153 case neon_cvt_flavour_s32_f32:
19154 case neon_cvt_flavour_u32_f32:
19155 constraint (inst.operands[2].imm > 32,
19156 _("immediate value out of range"));
19157 break;
19158 default:
19159 inst.error = BAD_FPU;
19160 return;
19161 }
19162 }
037e8744 19163
477330fc
RM
19164 /* Fixed-point conversion with #0 immediate is encoded as an
19165 integer conversion. */
19166 if (inst.operands[2].present && inst.operands[2].imm == 0)
19167 goto int_encode;
477330fc
RM
19168 NEON_ENCODE (IMMED, inst);
19169 if (flavour != neon_cvt_flavour_invalid)
19170 inst.instruction |= enctab[flavour];
19171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19173 inst.instruction |= LOW4 (inst.operands[1].reg);
19174 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19175 inst.instruction |= neon_quad (rs) << 6;
19176 inst.instruction |= 1 << 21;
cc933301
JW
19177 if (flavour < neon_cvt_flavour_s16_f16)
19178 {
19179 inst.instruction |= 1 << 21;
19180 immbits = 32 - inst.operands[2].imm;
19181 inst.instruction |= immbits << 16;
19182 }
19183 else
19184 {
19185 inst.instruction |= 3 << 20;
19186 immbits = 16 - inst.operands[2].imm;
19187 inst.instruction |= immbits << 16;
19188 inst.instruction &= ~(1 << 9);
19189 }
477330fc
RM
19190
19191 neon_dp_fixup (&inst);
037e8744
JB
19192 }
19193 break;
19194
037e8744 19195 case NS_QQ:
dd9634d9
AV
19196 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19197 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19198 && (flavour == neon_cvt_flavour_s16_f16
19199 || flavour == neon_cvt_flavour_u16_f16
19200 || flavour == neon_cvt_flavour_s32_f32
19201 || flavour == neon_cvt_flavour_u32_f32))
19202 {
64c350f2
AV
19203 if (!check_simd_pred_availability (TRUE,
19204 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
19205 return;
19206 }
19207 else if (mode == neon_cvt_mode_z
19208 && (flavour == neon_cvt_flavour_f16_s16
19209 || flavour == neon_cvt_flavour_f16_u16
19210 || flavour == neon_cvt_flavour_s16_f16
19211 || flavour == neon_cvt_flavour_u16_f16
19212 || flavour == neon_cvt_flavour_f32_u32
19213 || flavour == neon_cvt_flavour_f32_s32
19214 || flavour == neon_cvt_flavour_s32_f32
19215 || flavour == neon_cvt_flavour_u32_f32))
19216 {
64c350f2
AV
19217 if (!check_simd_pred_availability (TRUE,
19218 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19219 return;
19220 }
19221 /* fall through. */
19222 case NS_DD:
7e8e6784
MGD
19223 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19224 {
7e8e6784 19225
dd9634d9 19226 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
19227 if (!check_simd_pred_availability (TRUE,
19228 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
19229 return;
19230
19231 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19232 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19233 inst.instruction |= LOW4 (inst.operands[1].reg);
19234 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19235 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19236 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19237 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 19238 inst.instruction |= mode << 8;
cc933301
JW
19239 if (flavour == neon_cvt_flavour_u16_f16
19240 || flavour == neon_cvt_flavour_s16_f16)
19241 /* Mask off the original size bits and reencode them. */
19242 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19243
7e8e6784
MGD
19244 if (thumb_mode)
19245 inst.instruction |= 0xfc000000;
19246 else
19247 inst.instruction |= 0xf0000000;
19248 }
19249 else
19250 {
037e8744 19251 int_encode:
7e8e6784 19252 {
cc933301
JW
19253 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19254 0x100, 0x180, 0x0, 0x080};
037e8744 19255
7e8e6784 19256 NEON_ENCODE (INTEGER, inst);
037e8744 19257
dd9634d9
AV
19258 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19259 {
19260 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19261 return;
19262 }
037e8744 19263
7e8e6784
MGD
19264 if (flavour != neon_cvt_flavour_invalid)
19265 inst.instruction |= enctab[flavour];
037e8744 19266
7e8e6784
MGD
19267 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19268 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19269 inst.instruction |= LOW4 (inst.operands[1].reg);
19270 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19271 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19272 if (flavour >= neon_cvt_flavour_s16_f16
19273 && flavour <= neon_cvt_flavour_f16_u16)
19274 /* Half precision. */
19275 inst.instruction |= 1 << 18;
19276 else
19277 inst.instruction |= 2 << 18;
037e8744 19278
7e8e6784
MGD
19279 neon_dp_fixup (&inst);
19280 }
19281 }
19282 break;
037e8744 19283
8e79c3df
CM
19284 /* Half-precision conversions for Advanced SIMD -- neon. */
19285 case NS_QD:
19286 case NS_DQ:
bc52d49c
MM
19287 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19288 return;
8e79c3df
CM
19289
19290 if ((rs == NS_DQ)
19291 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19292 {
19293 as_bad (_("operand size must match register width"));
19294 break;
19295 }
19296
19297 if ((rs == NS_QD)
19298 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19299 {
19300 as_bad (_("operand size must match register width"));
19301 break;
19302 }
19303
19304 if (rs == NS_DQ)
aab2c27d
MM
19305 {
19306 if (flavour == neon_cvt_flavour_bf16_f32)
19307 {
19308 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19309 return;
19310 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19311 /* VCVT.bf16.f32. */
19312 inst.instruction = 0x11b60640;
19313 }
19314 else
19315 /* VCVT.f16.f32. */
19316 inst.instruction = 0x3b60600;
19317 }
8e79c3df 19318 else
aab2c27d 19319 /* VCVT.f32.f16. */
8e79c3df
CM
19320 inst.instruction = 0x3b60700;
19321
19322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19324 inst.instruction |= LOW4 (inst.operands[1].reg);
19325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19326 neon_dp_fixup (&inst);
8e79c3df
CM
19327 break;
19328
037e8744
JB
19329 default:
19330 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19331 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19332 do_vfp_nsyn_cvt (rs, flavour);
19333 else
19334 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19335 }
5287ad62
JB
19336}
19337
e3e535bc
NC
19338static void
19339do_neon_cvtr (void)
19340{
7e8e6784 19341 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19342}
19343
19344static void
19345do_neon_cvt (void)
19346{
7e8e6784
MGD
19347 do_neon_cvt_1 (neon_cvt_mode_z);
19348}
19349
19350static void
19351do_neon_cvta (void)
19352{
19353 do_neon_cvt_1 (neon_cvt_mode_a);
19354}
19355
19356static void
19357do_neon_cvtn (void)
19358{
19359 do_neon_cvt_1 (neon_cvt_mode_n);
19360}
19361
19362static void
19363do_neon_cvtp (void)
19364{
19365 do_neon_cvt_1 (neon_cvt_mode_p);
19366}
19367
19368static void
19369do_neon_cvtm (void)
19370{
19371 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19372}
19373
8e79c3df 19374static void
c70a8987 19375do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19376{
c70a8987
MGD
19377 if (is_double)
19378 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19379
c70a8987
MGD
19380 encode_arm_vfp_reg (inst.operands[0].reg,
19381 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19382 encode_arm_vfp_reg (inst.operands[1].reg,
19383 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19384 inst.instruction |= to ? 0x10000 : 0;
19385 inst.instruction |= t ? 0x80 : 0;
19386 inst.instruction |= is_double ? 0x100 : 0;
19387 do_vfp_cond_or_thumb ();
19388}
8e79c3df 19389
c70a8987
MGD
19390static void
19391do_neon_cvttb_1 (bfd_boolean t)
19392{
d54af2d0 19393 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19394 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19395
c70a8987
MGD
19396 if (rs == NS_NULL)
19397 return;
dd9634d9
AV
19398 else if (rs == NS_QQ || rs == NS_QQI)
19399 {
19400 int single_to_half = 0;
64c350f2 19401 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19402 return;
19403
19404 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19405
19406 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19407 && (flavour == neon_cvt_flavour_u16_f16
19408 || flavour == neon_cvt_flavour_s16_f16
19409 || flavour == neon_cvt_flavour_f16_s16
19410 || flavour == neon_cvt_flavour_f16_u16
19411 || flavour == neon_cvt_flavour_u32_f32
19412 || flavour == neon_cvt_flavour_s32_f32
19413 || flavour == neon_cvt_flavour_f32_s32
19414 || flavour == neon_cvt_flavour_f32_u32))
19415 {
19416 inst.cond = 0xf;
19417 inst.instruction = N_MNEM_vcvt;
19418 set_pred_insn_type (INSIDE_VPT_INSN);
19419 do_neon_cvt_1 (neon_cvt_mode_z);
19420 return;
19421 }
19422 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19423 single_to_half = 1;
19424 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19425 {
19426 first_error (BAD_FPU);
19427 return;
19428 }
19429
19430 inst.instruction = 0xee3f0e01;
19431 inst.instruction |= single_to_half << 28;
19432 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19433 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19434 inst.instruction |= t << 12;
19435 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19436 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19437 inst.is_neon = 1;
19438 }
c70a8987
MGD
19439 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19440 {
19441 inst.error = NULL;
19442 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19443 }
19444 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19445 {
19446 inst.error = NULL;
19447 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19448 }
19449 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19450 {
a715796b
TG
19451 /* The VCVTB and VCVTT instructions with D-register operands
19452 don't work for SP only targets. */
19453 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19454 _(BAD_FPU));
19455
c70a8987
MGD
19456 inst.error = NULL;
19457 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19458 }
19459 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19460 {
a715796b
TG
19461 /* The VCVTB and VCVTT instructions with D-register operands
19462 don't work for SP only targets. */
19463 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19464 _(BAD_FPU));
19465
c70a8987
MGD
19466 inst.error = NULL;
19467 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19468 }
aab2c27d
MM
19469 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19470 {
19471 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19472 inst.error = NULL;
19473 inst.instruction |= (1 << 8);
19474 inst.instruction &= ~(1 << 9);
19475 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19476 }
c70a8987
MGD
19477 else
19478 return;
19479}
19480
19481static void
19482do_neon_cvtb (void)
19483{
19484 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19485}
19486
19487
19488static void
19489do_neon_cvtt (void)
19490{
c70a8987 19491 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19492}
19493
5287ad62
JB
19494static void
19495neon_move_immediate (void)
19496{
037e8744
JB
19497 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19498 struct neon_type_el et = neon_check_type (2, rs,
19499 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19500 unsigned immlo, immhi = 0, immbits;
c96612cc 19501 int op, cmode, float_p;
5287ad62 19502
037e8744 19503 constraint (et.type == NT_invtype,
477330fc 19504 _("operand size must be specified for immediate VMOV"));
037e8744 19505
5287ad62
JB
19506 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19507 op = (inst.instruction & (1 << 5)) != 0;
19508
19509 immlo = inst.operands[1].imm;
19510 if (inst.operands[1].regisimm)
19511 immhi = inst.operands[1].reg;
19512
19513 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19514 _("immediate has bits set outside the operand size"));
5287ad62 19515
c96612cc
JB
19516 float_p = inst.operands[1].immisfloat;
19517
19518 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19519 et.size, et.type)) == FAIL)
5287ad62
JB
19520 {
19521 /* Invert relevant bits only. */
19522 neon_invert_size (&immlo, &immhi, et.size);
19523 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19524 with one or the other; those cases are caught by
19525 neon_cmode_for_move_imm. */
5287ad62 19526 op = !op;
c96612cc
JB
19527 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19528 &op, et.size, et.type)) == FAIL)
477330fc
RM
19529 {
19530 first_error (_("immediate out of range"));
19531 return;
19532 }
5287ad62
JB
19533 }
19534
19535 inst.instruction &= ~(1 << 5);
19536 inst.instruction |= op << 5;
19537
19538 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19539 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19540 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19541 inst.instruction |= cmode << 8;
19542
19543 neon_write_immbits (immbits);
19544}
19545
19546static void
19547do_neon_mvn (void)
19548{
64c350f2 19549 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19550 return;
19551
5287ad62
JB
19552 if (inst.operands[1].isreg)
19553 {
1a186d29
AV
19554 enum neon_shape rs;
19555 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19556 rs = neon_select_shape (NS_QQ, NS_NULL);
19557 else
19558 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19559
88714cb8 19560 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19561 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19562 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19563 inst.instruction |= LOW4 (inst.operands[1].reg);
19564 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19565 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19566 }
19567 else
19568 {
88714cb8 19569 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19570 neon_move_immediate ();
19571 }
19572
88714cb8 19573 neon_dp_fixup (&inst);
1a186d29
AV
19574
19575 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19576 {
19577 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
1a186d29 19578 }
5287ad62
JB
19579}
19580
19581/* Encode instructions of form:
19582
19583 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19584 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19585
19586static void
19587neon_mixed_length (struct neon_type_el et, unsigned size)
19588{
19589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19591 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19592 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19593 inst.instruction |= LOW4 (inst.operands[2].reg);
19594 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19595 inst.instruction |= (et.type == NT_unsigned) << 24;
19596 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19597
88714cb8 19598 neon_dp_fixup (&inst);
5287ad62
JB
19599}
19600
19601static void
19602do_neon_dyadic_long (void)
19603{
5ee91343
AV
19604 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19605 if (rs == NS_QDD)
19606 {
19607 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19608 return;
19609
19610 NEON_ENCODE (INTEGER, inst);
19611 /* FIXME: Type checking for lengthening op. */
19612 struct neon_type_el et = neon_check_type (3, NS_QDD,
19613 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19614 neon_mixed_length (et, et.size);
19615 }
19616 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19617 && (inst.cond == 0xf || inst.cond == 0x10))
19618 {
19619 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19620 in an IT block with le/lt conditions. */
19621
19622 if (inst.cond == 0xf)
19623 inst.cond = 0xb;
19624 else if (inst.cond == 0x10)
19625 inst.cond = 0xd;
19626
19627 inst.pred_insn_type = INSIDE_IT_INSN;
19628
19629 if (inst.instruction == N_MNEM_vaddl)
19630 {
19631 inst.instruction = N_MNEM_vadd;
19632 do_neon_addsub_if_i ();
19633 }
19634 else if (inst.instruction == N_MNEM_vsubl)
19635 {
19636 inst.instruction = N_MNEM_vsub;
19637 do_neon_addsub_if_i ();
19638 }
19639 else if (inst.instruction == N_MNEM_vabdl)
19640 {
19641 inst.instruction = N_MNEM_vabd;
19642 do_neon_dyadic_if_su ();
19643 }
19644 }
19645 else
19646 first_error (BAD_FPU);
5287ad62
JB
19647}
19648
19649static void
19650do_neon_abal (void)
19651{
19652 struct neon_type_el et = neon_check_type (3, NS_QDD,
19653 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19654 neon_mixed_length (et, et.size);
19655}
19656
19657static void
19658neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19659{
19660 if (inst.operands[2].isscalar)
19661 {
dcbf9037 19662 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19663 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19664 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19665 neon_mul_mac (et, et.type == NT_unsigned);
19666 }
19667 else
19668 {
19669 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19670 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19671 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19672 neon_mixed_length (et, et.size);
19673 }
19674}
19675
19676static void
19677do_neon_mac_maybe_scalar_long (void)
19678{
19679 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19680}
19681
dec41383
JW
19682/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19683 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19684
19685static unsigned
19686neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19687{
19688 unsigned regno = NEON_SCALAR_REG (scalar);
19689 unsigned elno = NEON_SCALAR_INDEX (scalar);
19690
19691 if (quad_p)
19692 {
19693 if (regno > 7 || elno > 3)
19694 goto bad_scalar;
19695
19696 return ((regno & 0x7)
19697 | ((elno & 0x1) << 3)
19698 | (((elno >> 1) & 0x1) << 5));
19699 }
19700 else
19701 {
19702 if (regno > 15 || elno > 1)
19703 goto bad_scalar;
19704
19705 return (((regno & 0x1) << 5)
19706 | ((regno >> 1) & 0x7)
19707 | ((elno & 0x1) << 3));
19708 }
19709
19710bad_scalar:
19711 first_error (_("scalar out of range for multiply instruction"));
19712 return 0;
19713}
19714
19715static void
19716do_neon_fmac_maybe_scalar_long (int subtype)
19717{
19718 enum neon_shape rs;
19719 int high8;
19720 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19721 field (bits[21:20]) has different meaning. For scalar index variant, it's
19722 used to differentiate add and subtract, otherwise it's with fixed value
19723 0x2. */
19724 int size = -1;
19725
dec41383
JW
19726 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19727 be a scalar index register. */
19728 if (inst.operands[2].isscalar)
19729 {
19730 high8 = 0xfe000000;
19731 if (subtype)
19732 size = 16;
19733 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19734 }
19735 else
19736 {
19737 high8 = 0xfc000000;
19738 size = 32;
19739 if (subtype)
19740 inst.instruction |= (0x1 << 23);
19741 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19742 }
19743
aab2c27d
MM
19744
19745 if (inst.cond != COND_ALWAYS)
19746 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19747 "behaviour is UNPREDICTABLE"));
19748
19749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19750 _(BAD_FP16));
19751
19752 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19753 _(BAD_FPU));
dec41383
JW
19754
19755 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19756 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19757 so we simply pass -1 as size. */
19758 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19759 neon_three_same (quad_p, 0, size);
19760
19761 /* Undo neon_dp_fixup. Redo the high eight bits. */
19762 inst.instruction &= 0x00ffffff;
19763 inst.instruction |= high8;
19764
dec41383
JW
19765 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19766 whether the instruction is in Q form and whether Vm is a scalar indexed
19767 operand. */
19768 if (inst.operands[2].isscalar)
19769 {
19770 unsigned rm
19771 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19772 inst.instruction &= 0xffffffd0;
19773 inst.instruction |= rm;
19774
19775 if (!quad_p)
19776 {
19777 /* Redo Rn as well. */
19778 inst.instruction &= 0xfff0ff7f;
19779 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19780 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19781 }
19782 }
19783 else if (!quad_p)
19784 {
19785 /* Redo Rn and Rm. */
19786 inst.instruction &= 0xfff0ff50;
19787 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19788 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19789 inst.instruction |= HI4 (inst.operands[2].reg);
19790 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19791 }
19792}
19793
19794static void
19795do_neon_vfmal (void)
19796{
19797 return do_neon_fmac_maybe_scalar_long (0);
19798}
19799
19800static void
19801do_neon_vfmsl (void)
19802{
19803 return do_neon_fmac_maybe_scalar_long (1);
19804}
19805
5287ad62
JB
19806static void
19807do_neon_dyadic_wide (void)
19808{
19809 struct neon_type_el et = neon_check_type (3, NS_QQD,
19810 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19811 neon_mixed_length (et, et.size);
19812}
19813
19814static void
19815do_neon_dyadic_narrow (void)
19816{
19817 struct neon_type_el et = neon_check_type (3, NS_QDD,
19818 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19819 /* Operand sign is unimportant, and the U bit is part of the opcode,
19820 so force the operand type to integer. */
19821 et.type = NT_integer;
5287ad62
JB
19822 neon_mixed_length (et, et.size / 2);
19823}
19824
19825static void
19826do_neon_mul_sat_scalar_long (void)
19827{
19828 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19829}
19830
19831static void
19832do_neon_vmull (void)
19833{
19834 if (inst.operands[2].isscalar)
19835 do_neon_mac_maybe_scalar_long ();
19836 else
19837 {
19838 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19839 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19840
5287ad62 19841 if (et.type == NT_poly)
477330fc 19842 NEON_ENCODE (POLY, inst);
5287ad62 19843 else
477330fc 19844 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19845
19846 /* For polynomial encoding the U bit must be zero, and the size must
19847 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19848 obviously, as 0b10). */
19849 if (et.size == 64)
19850 {
19851 /* Check we're on the correct architecture. */
19852 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19853 inst.error =
19854 _("Instruction form not available on this architecture.");
19855
19856 et.size = 32;
19857 }
19858
5287ad62
JB
19859 neon_mixed_length (et, et.size);
19860 }
19861}
19862
19863static void
19864do_neon_ext (void)
19865{
037e8744 19866 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19867 struct neon_type_el et = neon_check_type (3, rs,
19868 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19869 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19870
19871 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19872 _("shift out of range"));
5287ad62
JB
19873 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19874 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19875 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19876 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19877 inst.instruction |= LOW4 (inst.operands[2].reg);
19878 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19879 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19880 inst.instruction |= imm << 8;
5f4273c7 19881
88714cb8 19882 neon_dp_fixup (&inst);
5287ad62
JB
19883}
19884
19885static void
19886do_neon_rev (void)
19887{
64c350f2 19888 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19889 return;
19890
19891 enum neon_shape rs;
19892 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19893 rs = neon_select_shape (NS_QQ, NS_NULL);
19894 else
19895 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19896
5287ad62
JB
19897 struct neon_type_el et = neon_check_type (2, rs,
19898 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19899
5287ad62
JB
19900 unsigned op = (inst.instruction >> 7) & 3;
19901 /* N (width of reversed regions) is encoded as part of the bitmask. We
19902 extract it here to check the elements to be reversed are smaller.
19903 Otherwise we'd get a reserved instruction. */
19904 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19905
19906 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19907 && inst.operands[0].reg == inst.operands[1].reg)
19908 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19909 " operands makes instruction UNPREDICTABLE"));
19910
9c2799c2 19911 gas_assert (elsize != 0);
5287ad62 19912 constraint (et.size >= elsize,
477330fc 19913 _("elements must be smaller than reversal region"));
037e8744 19914 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19915}
19916
19917static void
19918do_neon_dup (void)
19919{
19920 if (inst.operands[1].isscalar)
19921 {
b409bdb6
AV
19922 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19923 BAD_FPU);
037e8744 19924 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19925 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19926 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19927 unsigned sizebits = et.size >> 3;
dcbf9037 19928 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19929 int logsize = neon_logbits (et.size);
dcbf9037 19930 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19931
19932 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19933 return;
037e8744 19934
88714cb8 19935 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19936 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19938 inst.instruction |= LOW4 (dm);
19939 inst.instruction |= HI1 (dm) << 5;
037e8744 19940 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19941 inst.instruction |= x << 17;
19942 inst.instruction |= sizebits << 16;
5f4273c7 19943
88714cb8 19944 neon_dp_fixup (&inst);
5287ad62
JB
19945 }
19946 else
19947 {
037e8744
JB
19948 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19949 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19950 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19951 if (rs == NS_QR)
19952 {
64c350f2 19953 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19954 return;
19955 }
19956 else
19957 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19958 BAD_FPU);
19959
19960 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19961 {
19962 if (inst.operands[1].reg == REG_SP)
19963 as_tsktsk (MVE_BAD_SP);
19964 else if (inst.operands[1].reg == REG_PC)
19965 as_tsktsk (MVE_BAD_PC);
19966 }
19967
5287ad62 19968 /* Duplicate ARM register to lanes of vector. */
88714cb8 19969 NEON_ENCODE (ARMREG, inst);
5287ad62 19970 switch (et.size)
477330fc
RM
19971 {
19972 case 8: inst.instruction |= 0x400000; break;
19973 case 16: inst.instruction |= 0x000020; break;
19974 case 32: inst.instruction |= 0x000000; break;
19975 default: break;
19976 }
5287ad62
JB
19977 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19978 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19979 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19980 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19981 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19982 variants, except for the condition field. */
037e8744 19983 do_vfp_cond_or_thumb ();
5287ad62
JB
19984 }
19985}
19986
57785aa2
AV
19987static void
19988do_mve_mov (int toQ)
19989{
19990 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19991 return;
19992 if (inst.cond > COND_ALWAYS)
19993 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19994
19995 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19996 if (toQ)
19997 {
19998 Q0 = 0;
19999 Q1 = 1;
20000 Rt = 2;
20001 Rt2 = 3;
20002 }
20003
20004 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
20005 _("Index one must be [2,3] and index two must be two less than"
20006 " index one."));
20007 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
20008 _("General purpose registers may not be the same"));
20009 constraint (inst.operands[Rt].reg == REG_SP
20010 || inst.operands[Rt2].reg == REG_SP,
20011 BAD_SP);
20012 constraint (inst.operands[Rt].reg == REG_PC
20013 || inst.operands[Rt2].reg == REG_PC,
20014 BAD_PC);
20015
20016 inst.instruction = 0xec000f00;
20017 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20018 inst.instruction |= !!toQ << 20;
20019 inst.instruction |= inst.operands[Rt2].reg << 16;
20020 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20021 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20022 inst.instruction |= inst.operands[Rt].reg;
20023}
20024
20025static void
20026do_mve_movn (void)
20027{
20028 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20029 return;
20030
20031 if (inst.cond > COND_ALWAYS)
20032 inst.pred_insn_type = INSIDE_VPT_INSN;
20033 else
20034 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20035
20036 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20037 | N_KEY);
20038
20039 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20040 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20042 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20043 inst.instruction |= LOW4 (inst.operands[1].reg);
20044 inst.is_neon = 1;
20045
20046}
20047
5287ad62
JB
20048/* VMOV has particularly many variations. It can be one of:
20049 0. VMOV<c><q> <Qd>, <Qm>
20050 1. VMOV<c><q> <Dd>, <Dm>
20051 (Register operations, which are VORR with Rm = Rn.)
20052 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20053 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20054 (Immediate loads.)
20055 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20056 (ARM register to scalar.)
20057 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20058 (Two ARM registers to vector.)
20059 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20060 (Scalar to ARM register.)
20061 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20062 (Vector to two ARM registers.)
037e8744
JB
20063 8. VMOV.F32 <Sd>, <Sm>
20064 9. VMOV.F64 <Dd>, <Dm>
20065 (VFP register moves.)
20066 10. VMOV.F32 <Sd>, #imm
20067 11. VMOV.F64 <Dd>, #imm
20068 (VFP float immediate load.)
20069 12. VMOV <Rd>, <Sm>
20070 (VFP single to ARM reg.)
20071 13. VMOV <Sd>, <Rm>
20072 (ARM reg to VFP single.)
20073 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20074 (Two ARM regs to two VFP singles.)
20075 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20076 (Two VFP singles to two ARM regs.)
57785aa2
AV
20077 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20078 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20079 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20080 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 20081
037e8744
JB
20082 These cases can be disambiguated using neon_select_shape, except cases 1/9
20083 and 3/11 which depend on the operand type too.
5f4273c7 20084
5287ad62 20085 All the encoded bits are hardcoded by this function.
5f4273c7 20086
b7fc2769
JB
20087 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20088 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 20089
5287ad62 20090 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 20091 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
20092
20093static void
20094do_neon_mov (void)
20095{
57785aa2
AV
20096 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20097 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20098 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20099 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20100 NS_NULL);
037e8744
JB
20101 struct neon_type_el et;
20102 const char *ldconst = 0;
5287ad62 20103
037e8744 20104 switch (rs)
5287ad62 20105 {
037e8744
JB
20106 case NS_DD: /* case 1/9. */
20107 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20108 /* It is not an error here if no type is given. */
20109 inst.error = NULL;
1c1e0fe5
SP
20110
20111 /* In MVE we interpret the following instructions as same, so ignoring
20112 the following type (float) and size (64) checks.
20113 a: VMOV<c><q> <Dd>, <Dm>
20114 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20115 if ((et.type == NT_float && et.size == 64)
20116 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc
RM
20117 {
20118 do_vfp_nsyn_opcode ("fcpyd");
20119 break;
20120 }
037e8744 20121 /* fall through. */
5287ad62 20122
037e8744
JB
20123 case NS_QQ: /* case 0/1. */
20124 {
64c350f2
AV
20125 if (!check_simd_pred_availability (FALSE,
20126 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
20127 return;
20128 /* The architecture manual I have doesn't explicitly state which
20129 value the U bit should have for register->register moves, but
20130 the equivalent VORR instruction has U = 0, so do that. */
20131 inst.instruction = 0x0200110;
20132 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20133 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20134 inst.instruction |= LOW4 (inst.operands[1].reg);
20135 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20136 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20137 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20138 inst.instruction |= neon_quad (rs) << 6;
20139
20140 neon_dp_fixup (&inst);
037e8744
JB
20141 }
20142 break;
5f4273c7 20143
037e8744
JB
20144 case NS_DI: /* case 3/11. */
20145 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20146 inst.error = NULL;
20147 if (et.type == NT_float && et.size == 64)
477330fc
RM
20148 {
20149 /* case 11 (fconstd). */
20150 ldconst = "fconstd";
20151 goto encode_fconstd;
20152 }
037e8744
JB
20153 /* fall through. */
20154
20155 case NS_QI: /* case 2/3. */
64c350f2
AV
20156 if (!check_simd_pred_availability (FALSE,
20157 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 20158 return;
037e8744
JB
20159 inst.instruction = 0x0800010;
20160 neon_move_immediate ();
88714cb8 20161 neon_dp_fixup (&inst);
5287ad62 20162 break;
5f4273c7 20163
037e8744
JB
20164 case NS_SR: /* case 4. */
20165 {
477330fc
RM
20166 unsigned bcdebits = 0;
20167 int logsize;
20168 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20169 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 20170
05ac0ffb
JB
20171 /* .<size> is optional here, defaulting to .32. */
20172 if (inst.vectype.elems == 0
20173 && inst.operands[0].vectype.type == NT_invtype
20174 && inst.operands[1].vectype.type == NT_invtype)
20175 {
20176 inst.vectype.el[0].type = NT_untyped;
20177 inst.vectype.el[0].size = 32;
20178 inst.vectype.elems = 1;
20179 }
20180
477330fc
RM
20181 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20182 logsize = neon_logbits (et.size);
20183
57785aa2
AV
20184 if (et.size != 32)
20185 {
20186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20187 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20188 return;
20189 }
20190 else
20191 {
20192 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20193 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20194 _(BAD_FPU));
20195 }
20196
20197 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20198 {
20199 if (inst.operands[1].reg == REG_SP)
20200 as_tsktsk (MVE_BAD_SP);
20201 else if (inst.operands[1].reg == REG_PC)
20202 as_tsktsk (MVE_BAD_PC);
20203 }
20204 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20205
477330fc 20206 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
20207 constraint (x >= size / et.size, _("scalar index out of range"));
20208
477330fc
RM
20209
20210 switch (et.size)
20211 {
20212 case 8: bcdebits = 0x8; break;
20213 case 16: bcdebits = 0x1; break;
20214 case 32: bcdebits = 0x0; break;
20215 default: ;
20216 }
20217
57785aa2 20218 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20219
20220 inst.instruction = 0xe000b10;
20221 do_vfp_cond_or_thumb ();
20222 inst.instruction |= LOW4 (dn) << 16;
20223 inst.instruction |= HI1 (dn) << 7;
20224 inst.instruction |= inst.operands[1].reg << 12;
20225 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
20226 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20227 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20228 }
20229 break;
5f4273c7 20230
037e8744 20231 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
20232 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20233 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20234 _(BAD_FPU));
b7fc2769 20235
037e8744
JB
20236 inst.instruction = 0xc400b10;
20237 do_vfp_cond_or_thumb ();
20238 inst.instruction |= LOW4 (inst.operands[0].reg);
20239 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20240 inst.instruction |= inst.operands[1].reg << 12;
20241 inst.instruction |= inst.operands[2].reg << 16;
20242 break;
5f4273c7 20243
037e8744
JB
20244 case NS_RS: /* case 6. */
20245 {
477330fc
RM
20246 unsigned logsize;
20247 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20248 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20249 unsigned abcdebits = 0;
037e8744 20250
05ac0ffb
JB
20251 /* .<dt> is optional here, defaulting to .32. */
20252 if (inst.vectype.elems == 0
20253 && inst.operands[0].vectype.type == NT_invtype
20254 && inst.operands[1].vectype.type == NT_invtype)
20255 {
20256 inst.vectype.el[0].type = NT_untyped;
20257 inst.vectype.el[0].size = 32;
20258 inst.vectype.elems = 1;
20259 }
20260
91d6fa6a
NC
20261 et = neon_check_type (2, NS_NULL,
20262 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
20263 logsize = neon_logbits (et.size);
20264
57785aa2
AV
20265 if (et.size != 32)
20266 {
20267 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20268 && vfp_or_neon_is_neon (NEON_CHECK_CC
20269 | NEON_CHECK_ARCH) == FAIL)
20270 return;
20271 }
20272 else
20273 {
20274 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20275 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20276 _(BAD_FPU));
20277 }
20278
20279 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20280 {
20281 if (inst.operands[0].reg == REG_SP)
20282 as_tsktsk (MVE_BAD_SP);
20283 else if (inst.operands[0].reg == REG_PC)
20284 as_tsktsk (MVE_BAD_PC);
20285 }
20286
20287 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20288
477330fc 20289 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 20290 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
20291
20292 switch (et.size)
20293 {
20294 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20295 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20296 case 32: abcdebits = 0x00; break;
20297 default: ;
20298 }
20299
57785aa2 20300 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20301 inst.instruction = 0xe100b10;
20302 do_vfp_cond_or_thumb ();
20303 inst.instruction |= LOW4 (dn) << 16;
20304 inst.instruction |= HI1 (dn) << 7;
20305 inst.instruction |= inst.operands[0].reg << 12;
20306 inst.instruction |= (abcdebits & 3) << 5;
20307 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 20308 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20309 }
20310 break;
5f4273c7 20311
037e8744 20312 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
20313 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20314 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20315 _(BAD_FPU));
037e8744
JB
20316
20317 inst.instruction = 0xc500b10;
20318 do_vfp_cond_or_thumb ();
20319 inst.instruction |= inst.operands[0].reg << 12;
20320 inst.instruction |= inst.operands[1].reg << 16;
20321 inst.instruction |= LOW4 (inst.operands[2].reg);
20322 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20323 break;
5f4273c7 20324
037e8744
JB
20325 case NS_FF: /* case 8 (fcpys). */
20326 do_vfp_nsyn_opcode ("fcpys");
20327 break;
5f4273c7 20328
9db2f6b4 20329 case NS_HI:
037e8744
JB
20330 case NS_FI: /* case 10 (fconsts). */
20331 ldconst = "fconsts";
4ef4710f 20332 encode_fconstd:
58ed5c38
TC
20333 if (!inst.operands[1].immisfloat)
20334 {
4ef4710f 20335 unsigned new_imm;
58ed5c38 20336 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
20337 float imm = (float) inst.operands[1].imm;
20338 memcpy (&new_imm, &imm, sizeof (float));
20339 /* But the assembly may have been written to provide an integer
20340 bit pattern that equates to a float, so check that the
20341 conversion has worked. */
20342 if (is_quarter_float (new_imm))
20343 {
20344 if (is_quarter_float (inst.operands[1].imm))
20345 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20346
20347 inst.operands[1].imm = new_imm;
20348 inst.operands[1].immisfloat = 1;
20349 }
58ed5c38
TC
20350 }
20351
037e8744 20352 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
20353 {
20354 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20355 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20356
20357 /* ARMv8.2 fp16 vmov.f16 instruction. */
20358 if (rs == NS_HI)
20359 do_scalar_fp16_v82_encode ();
477330fc 20360 }
5287ad62 20361 else
477330fc 20362 first_error (_("immediate out of range"));
037e8744 20363 break;
5f4273c7 20364
9db2f6b4 20365 case NS_RH:
037e8744
JB
20366 case NS_RF: /* case 12 (fmrs). */
20367 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20368 /* ARMv8.2 fp16 vmov.f16 instruction. */
20369 if (rs == NS_RH)
20370 do_scalar_fp16_v82_encode ();
037e8744 20371 break;
5f4273c7 20372
9db2f6b4 20373 case NS_HR:
037e8744
JB
20374 case NS_FR: /* case 13 (fmsr). */
20375 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20376 /* ARMv8.2 fp16 vmov.f16 instruction. */
20377 if (rs == NS_HR)
20378 do_scalar_fp16_v82_encode ();
037e8744 20379 break;
5f4273c7 20380
57785aa2
AV
20381 case NS_RRSS:
20382 do_mve_mov (0);
20383 break;
20384 case NS_SSRR:
20385 do_mve_mov (1);
20386 break;
20387
037e8744
JB
20388 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20389 (one of which is a list), but we have parsed four. Do some fiddling to
20390 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20391 expect. */
20392 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20394 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20395 _(BAD_FPU));
037e8744 20396 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20397 _("VFP registers must be adjacent"));
037e8744
JB
20398 inst.operands[2].imm = 2;
20399 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20400 do_vfp_nsyn_opcode ("fmrrs");
20401 break;
5f4273c7 20402
037e8744 20403 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20404 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20405 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20406 _(BAD_FPU));
037e8744 20407 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20408 _("VFP registers must be adjacent"));
037e8744
JB
20409 inst.operands[1] = inst.operands[2];
20410 inst.operands[2] = inst.operands[3];
20411 inst.operands[0].imm = 2;
20412 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20413 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20414 break;
5f4273c7 20415
4c261dff
NC
20416 case NS_NULL:
20417 /* neon_select_shape has determined that the instruction
20418 shape is wrong and has already set the error message. */
20419 break;
20420
5287ad62
JB
20421 default:
20422 abort ();
20423 }
20424}
20425
57785aa2
AV
20426static void
20427do_mve_movl (void)
20428{
20429 if (!(inst.operands[0].present && inst.operands[0].isquad
20430 && inst.operands[1].present && inst.operands[1].isquad
20431 && !inst.operands[2].present))
20432 {
20433 inst.instruction = 0;
20434 inst.cond = 0xb;
20435 if (thumb_mode)
20436 set_pred_insn_type (INSIDE_IT_INSN);
20437 do_neon_mov ();
20438 return;
20439 }
20440
20441 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20442 return;
20443
20444 if (inst.cond != COND_ALWAYS)
20445 inst.pred_insn_type = INSIDE_VPT_INSN;
20446
20447 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20448 | N_S16 | N_U16 | N_KEY);
20449
20450 inst.instruction |= (et.type == NT_unsigned) << 28;
20451 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20452 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20453 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20454 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20455 inst.instruction |= LOW4 (inst.operands[1].reg);
20456 inst.is_neon = 1;
20457}
20458
5287ad62
JB
20459static void
20460do_neon_rshift_round_imm (void)
20461{
64c350f2 20462 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20463 return;
20464
20465 enum neon_shape rs;
20466 struct neon_type_el et;
20467
20468 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20469 {
20470 rs = neon_select_shape (NS_QQI, NS_NULL);
20471 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20472 }
20473 else
20474 {
20475 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20476 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20477 }
5287ad62
JB
20478 int imm = inst.operands[2].imm;
20479
20480 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20481 if (imm == 0)
20482 {
20483 inst.operands[2].present = 0;
20484 do_neon_mov ();
20485 return;
20486 }
20487
20488 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20489 _("immediate out of range for shift"));
037e8744 20490 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20491 et.size - imm);
5287ad62
JB
20492}
20493
9db2f6b4
RL
20494static void
20495do_neon_movhf (void)
20496{
20497 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20498 constraint (rs != NS_HH, _("invalid suffix"));
20499
7bdf778b
ASDV
20500 if (inst.cond != COND_ALWAYS)
20501 {
20502 if (thumb_mode)
20503 {
20504 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20505 " the behaviour is UNPREDICTABLE"));
20506 }
20507 else
20508 {
20509 inst.error = BAD_COND;
20510 return;
20511 }
20512 }
20513
9db2f6b4
RL
20514 do_vfp_sp_monadic ();
20515
20516 inst.is_neon = 1;
20517 inst.instruction |= 0xf0000000;
20518}
20519
5287ad62
JB
20520static void
20521do_neon_movl (void)
20522{
20523 struct neon_type_el et = neon_check_type (2, NS_QD,
20524 N_EQK | N_DBL, N_SU_32 | N_KEY);
20525 unsigned sizebits = et.size >> 3;
20526 inst.instruction |= sizebits << 19;
20527 neon_two_same (0, et.type == NT_unsigned, -1);
20528}
20529
20530static void
20531do_neon_trn (void)
20532{
037e8744 20533 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20534 struct neon_type_el et = neon_check_type (2, rs,
20535 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20536 NEON_ENCODE (INTEGER, inst);
037e8744 20537 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20538}
20539
20540static void
20541do_neon_zip_uzp (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,
20545 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20546 if (rs == NS_DD && et.size == 32)
20547 {
20548 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20549 inst.instruction = N_MNEM_vtrn;
20550 do_neon_trn ();
20551 return;
20552 }
037e8744 20553 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20554}
20555
20556static void
20557do_neon_sat_abs_neg (void)
20558{
64c350f2 20559 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20560 return;
20561
20562 enum neon_shape rs;
20563 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20564 rs = neon_select_shape (NS_QQ, NS_NULL);
20565 else
20566 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20567 struct neon_type_el et = neon_check_type (2, rs,
20568 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20569 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20570}
20571
20572static void
20573do_neon_pair_long (void)
20574{
037e8744 20575 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20576 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20577 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20578 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20579 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20580}
20581
20582static void
20583do_neon_recip_est (void)
20584{
037e8744 20585 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20586 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20587 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20588 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20589 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20590}
20591
20592static void
20593do_neon_cls (void)
20594{
64c350f2 20595 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20596 return;
20597
20598 enum neon_shape rs;
20599 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20600 rs = neon_select_shape (NS_QQ, NS_NULL);
20601 else
20602 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20603
5287ad62
JB
20604 struct neon_type_el et = neon_check_type (2, rs,
20605 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20606 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20607}
20608
20609static void
20610do_neon_clz (void)
20611{
64c350f2 20612 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20613 return;
20614
20615 enum neon_shape rs;
20616 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20617 rs = neon_select_shape (NS_QQ, NS_NULL);
20618 else
20619 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20620
5287ad62
JB
20621 struct neon_type_el et = neon_check_type (2, rs,
20622 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20623 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20624}
20625
20626static void
20627do_neon_cnt (void)
20628{
037e8744 20629 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20630 struct neon_type_el et = neon_check_type (2, rs,
20631 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20632 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20633}
20634
20635static void
20636do_neon_swp (void)
20637{
037e8744
JB
20638 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20639 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20640}
20641
20642static void
20643do_neon_tbl_tbx (void)
20644{
20645 unsigned listlenbits;
dcbf9037 20646 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20647
5287ad62
JB
20648 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20649 {
dcbf9037 20650 first_error (_("bad list length for table lookup"));
5287ad62
JB
20651 return;
20652 }
5f4273c7 20653
5287ad62
JB
20654 listlenbits = inst.operands[1].imm - 1;
20655 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20656 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20657 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20658 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20659 inst.instruction |= LOW4 (inst.operands[2].reg);
20660 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20661 inst.instruction |= listlenbits << 8;
5f4273c7 20662
88714cb8 20663 neon_dp_fixup (&inst);
5287ad62
JB
20664}
20665
20666static void
20667do_neon_ldm_stm (void)
20668{
ef8f595f
MI
20669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20670 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20671 _(BAD_FPU));
5287ad62
JB
20672 /* P, U and L bits are part of bitmask. */
20673 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20674 unsigned offsetbits = inst.operands[1].imm * 2;
20675
037e8744
JB
20676 if (inst.operands[1].issingle)
20677 {
20678 do_vfp_nsyn_ldm_stm (is_dbmode);
20679 return;
20680 }
20681
5287ad62 20682 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20683 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20684
20685 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20686 _("register list must contain at least 1 and at most 16 "
20687 "registers"));
5287ad62
JB
20688
20689 inst.instruction |= inst.operands[0].reg << 16;
20690 inst.instruction |= inst.operands[0].writeback << 21;
20691 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20692 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20693
20694 inst.instruction |= offsetbits;
5f4273c7 20695
037e8744 20696 do_vfp_cond_or_thumb ();
5287ad62
JB
20697}
20698
ef8f595f
MI
20699static void
20700do_vfp_nsyn_pop (void)
20701{
20702 nsyn_insert_sp ();
20703 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20704 return do_vfp_nsyn_opcode ("vldm");
20705 }
20706
20707 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20708 _(BAD_FPU));
20709
20710 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20711 _("register list must contain at least 1 and at most 16 "
20712 "registers"));
20713
20714 if (inst.operands[1].issingle)
20715 do_vfp_nsyn_opcode ("fldmias");
20716 else
20717 do_vfp_nsyn_opcode ("fldmiad");
20718}
20719
20720static void
20721do_vfp_nsyn_push (void)
20722{
20723 nsyn_insert_sp ();
20724 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20725 return do_vfp_nsyn_opcode ("vstmdb");
20726 }
20727
20728 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20729 _(BAD_FPU));
20730
20731 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20732 _("register list must contain at least 1 and at most 16 "
20733 "registers"));
20734
20735 if (inst.operands[1].issingle)
20736 do_vfp_nsyn_opcode ("fstmdbs");
20737 else
20738 do_vfp_nsyn_opcode ("fstmdbd");
20739}
20740
20741
5287ad62
JB
20742static void
20743do_neon_ldr_str (void)
20744{
5287ad62 20745 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20746
6844b2c2
MGD
20747 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20748 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20749 if (!is_ldr
6844b2c2 20750 && inst.operands[1].reg == REG_PC
ba86b375 20751 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20752 {
94dcf8bf 20753 if (thumb_mode)
6844b2c2 20754 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20755 else if (warn_on_deprecated)
5c3696f8 20756 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20757 }
20758
037e8744
JB
20759 if (inst.operands[0].issingle)
20760 {
cd2f129f 20761 if (is_ldr)
477330fc 20762 do_vfp_nsyn_opcode ("flds");
cd2f129f 20763 else
477330fc 20764 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20765
20766 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20767 if (inst.vectype.el[0].size == 16)
20768 do_scalar_fp16_v82_encode ();
5287ad62
JB
20769 }
20770 else
5287ad62 20771 {
cd2f129f 20772 if (is_ldr)
477330fc 20773 do_vfp_nsyn_opcode ("fldd");
5287ad62 20774 else
477330fc 20775 do_vfp_nsyn_opcode ("fstd");
5287ad62 20776 }
5287ad62
JB
20777}
20778
32c36c3c
AV
20779static void
20780do_t_vldr_vstr_sysreg (void)
20781{
20782 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20783 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20784
20785 /* Use of PC is UNPREDICTABLE. */
20786 if (inst.operands[1].reg == REG_PC)
20787 inst.error = _("Use of PC here is UNPREDICTABLE");
20788
20789 if (inst.operands[1].immisreg)
20790 inst.error = _("instruction does not accept register index");
20791
20792 if (!inst.operands[1].isreg)
20793 inst.error = _("instruction does not accept PC-relative addressing");
20794
20795 if (abs (inst.operands[1].imm) >= (1 << 7))
20796 inst.error = _("immediate value out of range");
20797
20798 inst.instruction = 0xec000f80;
20799 if (is_vldr)
20800 inst.instruction |= 1 << sysreg_vldr_bitno;
20801 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20802 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20803 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20804}
20805
20806static void
20807do_vldr_vstr (void)
20808{
20809 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20810
20811 /* VLDR/VSTR (System Register). */
20812 if (sysreg_op)
20813 {
20814 if (!mark_feature_used (&arm_ext_v8_1m_main))
20815 as_bad (_("Instruction not permitted on this architecture"));
20816
20817 do_t_vldr_vstr_sysreg ();
20818 }
20819 /* VLDR/VSTR. */
20820 else
20821 {
ef8f595f
MI
20822 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20823 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
32c36c3c
AV
20824 as_bad (_("Instruction not permitted on this architecture"));
20825 do_neon_ldr_str ();
20826 }
20827}
20828
5287ad62
JB
20829/* "interleave" version also handles non-interleaving register VLD1/VST1
20830 instructions. */
20831
20832static void
20833do_neon_ld_st_interleave (void)
20834{
037e8744 20835 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20836 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20837 unsigned alignbits = 0;
20838 unsigned idx;
20839 /* The bits in this table go:
20840 0: register stride of one (0) or two (1)
20841 1,2: register list length, minus one (1, 2, 3, 4).
20842 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20843 We use -1 for invalid entries. */
20844 const int typetable[] =
20845 {
20846 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20847 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20848 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20849 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20850 };
20851 int typebits;
20852
dcbf9037
JB
20853 if (et.type == NT_invtype)
20854 return;
20855
5287ad62
JB
20856 if (inst.operands[1].immisalign)
20857 switch (inst.operands[1].imm >> 8)
20858 {
20859 case 64: alignbits = 1; break;
20860 case 128:
477330fc 20861 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20862 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20863 goto bad_alignment;
20864 alignbits = 2;
20865 break;
5287ad62 20866 case 256:
477330fc
RM
20867 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20868 goto bad_alignment;
20869 alignbits = 3;
20870 break;
5287ad62
JB
20871 default:
20872 bad_alignment:
477330fc
RM
20873 first_error (_("bad alignment"));
20874 return;
5287ad62
JB
20875 }
20876
20877 inst.instruction |= alignbits << 4;
20878 inst.instruction |= neon_logbits (et.size) << 6;
20879
20880 /* Bits [4:6] of the immediate in a list specifier encode register stride
20881 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20882 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20883 up the right value for "type" in a table based on this value and the given
20884 list style, then stick it back. */
20885 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20886 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20887
20888 typebits = typetable[idx];
5f4273c7 20889
5287ad62 20890 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20891 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20892 BAD_EL_TYPE);
5287ad62
JB
20893
20894 inst.instruction &= ~0xf00;
20895 inst.instruction |= typebits << 8;
20896}
20897
20898/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20899 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20900 otherwise. The variable arguments are a list of pairs of legal (size, align)
20901 values, terminated with -1. */
20902
20903static int
aa8a0863 20904neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20905{
20906 va_list ap;
20907 int result = FAIL, thissize, thisalign;
5f4273c7 20908
5287ad62
JB
20909 if (!inst.operands[1].immisalign)
20910 {
aa8a0863 20911 *do_alignment = 0;
5287ad62
JB
20912 return SUCCESS;
20913 }
5f4273c7 20914
aa8a0863 20915 va_start (ap, do_alignment);
5287ad62
JB
20916
20917 do
20918 {
20919 thissize = va_arg (ap, int);
20920 if (thissize == -1)
477330fc 20921 break;
5287ad62
JB
20922 thisalign = va_arg (ap, int);
20923
20924 if (size == thissize && align == thisalign)
477330fc 20925 result = SUCCESS;
5287ad62
JB
20926 }
20927 while (result != SUCCESS);
20928
20929 va_end (ap);
20930
20931 if (result == SUCCESS)
aa8a0863 20932 *do_alignment = 1;
5287ad62 20933 else
dcbf9037 20934 first_error (_("unsupported alignment for instruction"));
5f4273c7 20935
5287ad62
JB
20936 return result;
20937}
20938
20939static void
20940do_neon_ld_st_lane (void)
20941{
037e8744 20942 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20943 int align_good, do_alignment = 0;
5287ad62
JB
20944 int logsize = neon_logbits (et.size);
20945 int align = inst.operands[1].imm >> 8;
20946 int n = (inst.instruction >> 8) & 3;
20947 int max_el = 64 / et.size;
5f4273c7 20948
dcbf9037
JB
20949 if (et.type == NT_invtype)
20950 return;
5f4273c7 20951
5287ad62 20952 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20953 _("bad list length"));
5287ad62 20954 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20955 _("scalar index out of range"));
5287ad62 20956 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20957 && et.size == 8,
20958 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20959
5287ad62
JB
20960 switch (n)
20961 {
20962 case 0: /* VLD1 / VST1. */
aa8a0863 20963 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20964 32, 32, -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 16: alignbits = 0x1; break;
20973 case 32: alignbits = 0x3; break;
20974 default: ;
20975 }
20976 inst.instruction |= alignbits << 4;
20977 }
5287ad62
JB
20978 break;
20979
20980 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20981 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20982 16, 32, 32, 64, -1);
5287ad62 20983 if (align_good == FAIL)
477330fc 20984 return;
aa8a0863 20985 if (do_alignment)
477330fc 20986 inst.instruction |= 1 << 4;
5287ad62
JB
20987 break;
20988
20989 case 2: /* VLD3 / VST3. */
20990 constraint (inst.operands[1].immisalign,
477330fc 20991 _("can't use alignment with this instruction"));
5287ad62
JB
20992 break;
20993
20994 case 3: /* VLD4 / VST4. */
aa8a0863 20995 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20996 16, 64, 32, 64, 32, 128, -1);
5287ad62 20997 if (align_good == FAIL)
477330fc 20998 return;
aa8a0863 20999 if (do_alignment)
477330fc
RM
21000 {
21001 unsigned alignbits = 0;
21002 switch (et.size)
21003 {
21004 case 8: alignbits = 0x1; break;
21005 case 16: alignbits = 0x1; break;
21006 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21007 default: ;
21008 }
21009 inst.instruction |= alignbits << 4;
21010 }
5287ad62
JB
21011 break;
21012
21013 default: ;
21014 }
21015
21016 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21017 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21018 inst.instruction |= 1 << (4 + logsize);
5f4273c7 21019
5287ad62
JB
21020 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21021 inst.instruction |= logsize << 10;
21022}
21023
21024/* Encode single n-element structure to all lanes VLD<n> instructions. */
21025
21026static void
21027do_neon_ld_dup (void)
21028{
037e8744 21029 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 21030 int align_good, do_alignment = 0;
5287ad62 21031
dcbf9037
JB
21032 if (et.type == NT_invtype)
21033 return;
21034
5287ad62
JB
21035 switch ((inst.instruction >> 8) & 3)
21036 {
21037 case 0: /* VLD1. */
9c2799c2 21038 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 21039 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 21040 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 21041 if (align_good == FAIL)
477330fc 21042 return;
5287ad62 21043 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
21044 {
21045 case 1: break;
21046 case 2: inst.instruction |= 1 << 5; break;
21047 default: first_error (_("bad list length")); return;
21048 }
5287ad62
JB
21049 inst.instruction |= neon_logbits (et.size) << 6;
21050 break;
21051
21052 case 1: /* VLD2. */
21053 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
21054 &do_alignment, 8, 16, 16, 32, 32, 64,
21055 -1);
5287ad62 21056 if (align_good == FAIL)
477330fc 21057 return;
5287ad62 21058 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 21059 _("bad list length"));
5287ad62 21060 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21061 inst.instruction |= 1 << 5;
5287ad62
JB
21062 inst.instruction |= neon_logbits (et.size) << 6;
21063 break;
21064
21065 case 2: /* VLD3. */
21066 constraint (inst.operands[1].immisalign,
477330fc 21067 _("can't use alignment with this instruction"));
5287ad62 21068 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 21069 _("bad list length"));
5287ad62 21070 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21071 inst.instruction |= 1 << 5;
5287ad62
JB
21072 inst.instruction |= neon_logbits (et.size) << 6;
21073 break;
21074
21075 case 3: /* VLD4. */
21076 {
477330fc 21077 int align = inst.operands[1].imm >> 8;
aa8a0863 21078 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
21079 16, 64, 32, 64, 32, 128, -1);
21080 if (align_good == FAIL)
21081 return;
21082 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21083 _("bad list length"));
21084 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21085 inst.instruction |= 1 << 5;
21086 if (et.size == 32 && align == 128)
21087 inst.instruction |= 0x3 << 6;
21088 else
21089 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
21090 }
21091 break;
21092
21093 default: ;
21094 }
21095
aa8a0863 21096 inst.instruction |= do_alignment << 4;
5287ad62
JB
21097}
21098
21099/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21100 apart from bits [11:4]. */
21101
21102static void
21103do_neon_ldx_stx (void)
21104{
b1a769ed
DG
21105 if (inst.operands[1].isreg)
21106 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21107
5287ad62
JB
21108 switch (NEON_LANE (inst.operands[0].imm))
21109 {
21110 case NEON_INTERLEAVE_LANES:
88714cb8 21111 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
21112 do_neon_ld_st_interleave ();
21113 break;
5f4273c7 21114
5287ad62 21115 case NEON_ALL_LANES:
88714cb8 21116 NEON_ENCODE (DUP, inst);
2d51fb74
JB
21117 if (inst.instruction == N_INV)
21118 {
21119 first_error ("only loads support such operands");
21120 break;
21121 }
5287ad62
JB
21122 do_neon_ld_dup ();
21123 break;
5f4273c7 21124
5287ad62 21125 default:
88714cb8 21126 NEON_ENCODE (LANE, inst);
5287ad62
JB
21127 do_neon_ld_st_lane ();
21128 }
21129
21130 /* L bit comes from bit mask. */
21131 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21133 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 21134
5287ad62
JB
21135 if (inst.operands[1].postind)
21136 {
21137 int postreg = inst.operands[1].imm & 0xf;
21138 constraint (!inst.operands[1].immisreg,
477330fc 21139 _("post-index must be a register"));
5287ad62 21140 constraint (postreg == 0xd || postreg == 0xf,
477330fc 21141 _("bad register for post-index"));
5287ad62
JB
21142 inst.instruction |= postreg;
21143 }
4f2374c7 21144 else
5287ad62 21145 {
4f2374c7 21146 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
21147 constraint (inst.relocs[0].exp.X_op != O_constant
21148 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
21149 BAD_ADDR_MODE);
21150
21151 if (inst.operands[1].writeback)
21152 {
21153 inst.instruction |= 0xd;
21154 }
21155 else
21156 inst.instruction |= 0xf;
5287ad62 21157 }
5f4273c7 21158
5287ad62
JB
21159 if (thumb_mode)
21160 inst.instruction |= 0xf9000000;
21161 else
21162 inst.instruction |= 0xf4000000;
21163}
33399f07
MGD
21164
21165/* FP v8. */
21166static void
21167do_vfp_nsyn_fpv8 (enum neon_shape rs)
21168{
a715796b
TG
21169 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21170 D register operands. */
21171 if (neon_shape_class[rs] == SC_DOUBLE)
21172 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21173 _(BAD_FPU));
21174
33399f07
MGD
21175 NEON_ENCODE (FPV8, inst);
21176
9db2f6b4
RL
21177 if (rs == NS_FFF || rs == NS_HHH)
21178 {
21179 do_vfp_sp_dyadic ();
21180
21181 /* ARMv8.2 fp16 instruction. */
21182 if (rs == NS_HHH)
21183 do_scalar_fp16_v82_encode ();
21184 }
33399f07
MGD
21185 else
21186 do_vfp_dp_rd_rn_rm ();
21187
21188 if (rs == NS_DDD)
21189 inst.instruction |= 0x100;
21190
21191 inst.instruction |= 0xf0000000;
21192}
21193
21194static void
21195do_vsel (void)
21196{
5ee91343 21197 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
21198
21199 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21200 first_error (_("invalid instruction shape"));
21201}
21202
73924fbc
MGD
21203static void
21204do_vmaxnm (void)
21205{
935295b5
AV
21206 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21207 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
21208
21209 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21210 return;
21211
64c350f2 21212 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
21213 return;
21214
cc933301 21215 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
21216}
21217
30bdf752
MGD
21218static void
21219do_vrint_1 (enum neon_cvt_mode mode)
21220{
9db2f6b4 21221 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
21222 struct neon_type_el et;
21223
21224 if (rs == NS_NULL)
21225 return;
21226
a715796b
TG
21227 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21228 D register operands. */
21229 if (neon_shape_class[rs] == SC_DOUBLE)
21230 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21231 _(BAD_FPU));
21232
9db2f6b4
RL
21233 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21234 | N_VFP);
30bdf752
MGD
21235 if (et.type != NT_invtype)
21236 {
21237 /* VFP encodings. */
21238 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21239 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 21240 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
21241
21242 NEON_ENCODE (FPV8, inst);
9db2f6b4 21243 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
21244 do_vfp_sp_monadic ();
21245 else
21246 do_vfp_dp_rd_rm ();
21247
21248 switch (mode)
21249 {
21250 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21251 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21252 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21253 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21254 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21255 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21256 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21257 default: abort ();
21258 }
21259
21260 inst.instruction |= (rs == NS_DD) << 8;
21261 do_vfp_cond_or_thumb ();
9db2f6b4
RL
21262
21263 /* ARMv8.2 fp16 vrint instruction. */
21264 if (rs == NS_HH)
21265 do_scalar_fp16_v82_encode ();
30bdf752
MGD
21266 }
21267 else
21268 {
21269 /* Neon encodings (or something broken...). */
21270 inst.error = NULL;
cc933301 21271 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
21272
21273 if (et.type == NT_invtype)
21274 return;
21275
64c350f2
AV
21276 if (!check_simd_pred_availability (TRUE,
21277 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
21278 return;
21279
a710b305
AV
21280 NEON_ENCODE (FLOAT, inst);
21281
30bdf752
MGD
21282 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21283 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21284 inst.instruction |= LOW4 (inst.operands[1].reg);
21285 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21286 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
21287 /* Mask off the original size bits and reencode them. */
21288 inst.instruction = ((inst.instruction & 0xfff3ffff)
21289 | neon_logbits (et.size) << 18);
21290
30bdf752
MGD
21291 switch (mode)
21292 {
21293 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21294 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21295 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21296 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21297 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21298 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21299 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21300 default: abort ();
21301 }
21302
21303 if (thumb_mode)
21304 inst.instruction |= 0xfc000000;
21305 else
21306 inst.instruction |= 0xf0000000;
21307 }
21308}
21309
21310static void
21311do_vrintx (void)
21312{
21313 do_vrint_1 (neon_cvt_mode_x);
21314}
21315
21316static void
21317do_vrintz (void)
21318{
21319 do_vrint_1 (neon_cvt_mode_z);
21320}
21321
21322static void
21323do_vrintr (void)
21324{
21325 do_vrint_1 (neon_cvt_mode_r);
21326}
21327
21328static void
21329do_vrinta (void)
21330{
21331 do_vrint_1 (neon_cvt_mode_a);
21332}
21333
21334static void
21335do_vrintn (void)
21336{
21337 do_vrint_1 (neon_cvt_mode_n);
21338}
21339
21340static void
21341do_vrintp (void)
21342{
21343 do_vrint_1 (neon_cvt_mode_p);
21344}
21345
21346static void
21347do_vrintm (void)
21348{
21349 do_vrint_1 (neon_cvt_mode_m);
21350}
21351
c28eeff2
SN
21352static unsigned
21353neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21354{
21355 unsigned regno = NEON_SCALAR_REG (opnd);
21356 unsigned elno = NEON_SCALAR_INDEX (opnd);
21357
21358 if (elsize == 16 && elno < 2 && regno < 16)
21359 return regno | (elno << 4);
21360 else if (elsize == 32 && elno == 0)
21361 return regno;
21362
21363 first_error (_("scalar out of range"));
21364 return 0;
21365}
21366
21367static void
21368do_vcmla (void)
21369{
5d281bf0
AV
21370 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21371 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21372 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21373 constraint (inst.relocs[0].exp.X_op != O_constant,
21374 _("expression too complex"));
21375 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21376 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21377 _("immediate out of range"));
21378 rot /= 90;
5d281bf0 21379
64c350f2
AV
21380 if (!check_simd_pred_availability (TRUE,
21381 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21382 return;
21383
c28eeff2
SN
21384 if (inst.operands[2].isscalar)
21385 {
5d281bf0
AV
21386 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21387 first_error (_("invalid instruction shape"));
c28eeff2
SN
21388 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21389 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21390 N_KEY | N_F16 | N_F32).size;
21391 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21392 inst.is_neon = 1;
21393 inst.instruction = 0xfe000800;
21394 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21395 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21396 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21397 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21398 inst.instruction |= LOW4 (m);
21399 inst.instruction |= HI1 (m) << 5;
21400 inst.instruction |= neon_quad (rs) << 6;
21401 inst.instruction |= rot << 20;
21402 inst.instruction |= (size == 32) << 23;
21403 }
21404 else
21405 {
5d281bf0
AV
21406 enum neon_shape rs;
21407 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21408 rs = neon_select_shape (NS_QQQI, NS_NULL);
21409 else
21410 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21411
c28eeff2
SN
21412 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21413 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21414 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21415 && (inst.operands[0].reg == inst.operands[1].reg
21416 || inst.operands[0].reg == inst.operands[2].reg))
21417 as_tsktsk (BAD_MVE_SRCDEST);
21418
c28eeff2
SN
21419 neon_three_same (neon_quad (rs), 0, -1);
21420 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21421 inst.instruction |= 0xfc200800;
21422 inst.instruction |= rot << 23;
21423 inst.instruction |= (size == 32) << 20;
21424 }
21425}
21426
21427static void
21428do_vcadd (void)
21429{
5d281bf0
AV
21430 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21431 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21432 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21433 constraint (inst.relocs[0].exp.X_op != O_constant,
21434 _("expression too complex"));
5d281bf0 21435
e2b0ab59 21436 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21437 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21438 enum neon_shape rs;
21439 struct neon_type_el et;
21440 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21441 {
21442 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21443 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21444 }
21445 else
21446 {
21447 rs = neon_select_shape (NS_QQQI, NS_NULL);
21448 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21449 | N_I16 | N_I32);
21450 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21451 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21452 "operand makes instruction UNPREDICTABLE"));
21453 }
21454
21455 if (et.type == NT_invtype)
21456 return;
21457
64c350f2
AV
21458 if (!check_simd_pred_availability (et.type == NT_float,
21459 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21460 return;
21461
21462 if (et.type == NT_float)
21463 {
21464 neon_three_same (neon_quad (rs), 0, -1);
21465 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21466 inst.instruction |= 0xfc800800;
21467 inst.instruction |= (rot == 270) << 24;
21468 inst.instruction |= (et.size == 32) << 20;
21469 }
21470 else
21471 {
21472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21473 inst.instruction = 0xfe000f00;
21474 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21475 inst.instruction |= neon_logbits (et.size) << 20;
21476 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21477 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21478 inst.instruction |= (rot == 270) << 12;
21479 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21480 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21481 inst.instruction |= LOW4 (inst.operands[2].reg);
21482 inst.is_neon = 1;
21483 }
c28eeff2
SN
21484}
21485
c604a79a
JW
21486/* Dot Product instructions encoding support. */
21487
21488static void
21489do_neon_dotproduct (int unsigned_p)
21490{
21491 enum neon_shape rs;
21492 unsigned scalar_oprd2 = 0;
21493 int high8;
21494
21495 if (inst.cond != COND_ALWAYS)
21496 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21497 "is UNPREDICTABLE"));
21498
21499 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21500 _(BAD_FPU));
21501
21502 /* Dot Product instructions are in three-same D/Q register format or the third
21503 operand can be a scalar index register. */
21504 if (inst.operands[2].isscalar)
21505 {
21506 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21507 high8 = 0xfe000000;
21508 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21509 }
21510 else
21511 {
21512 high8 = 0xfc000000;
21513 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21514 }
21515
21516 if (unsigned_p)
21517 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21518 else
21519 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21520
21521 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21522 Product instruction, so we pass 0 as the "ubit" parameter. And the
21523 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21524 neon_three_same (neon_quad (rs), 0, 32);
21525
21526 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21527 different NEON three-same encoding. */
21528 inst.instruction &= 0x00ffffff;
21529 inst.instruction |= high8;
21530 /* Encode 'U' bit which indicates signedness. */
21531 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21532 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21533 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21534 the instruction encoding. */
21535 if (inst.operands[2].isscalar)
21536 {
21537 inst.instruction &= 0xffffffd0;
21538 inst.instruction |= LOW4 (scalar_oprd2);
21539 inst.instruction |= HI1 (scalar_oprd2) << 5;
21540 }
21541}
21542
21543/* Dot Product instructions for signed integer. */
21544
21545static void
21546do_neon_dotproduct_s (void)
21547{
21548 return do_neon_dotproduct (0);
21549}
21550
21551/* Dot Product instructions for unsigned integer. */
21552
21553static void
21554do_neon_dotproduct_u (void)
21555{
21556 return do_neon_dotproduct (1);
21557}
21558
616ce08e
MM
21559static void
21560do_vusdot (void)
21561{
21562 enum neon_shape rs;
21563 set_pred_insn_type (OUTSIDE_PRED_INSN);
21564 if (inst.operands[2].isscalar)
21565 {
21566 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21567 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21568
21569 inst.instruction |= (1 << 25);
21570 int index = inst.operands[2].reg & 0xf;
21571 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21572 inst.operands[2].reg >>= 4;
21573 constraint (!(inst.operands[2].reg < 16),
21574 _("indexed register must be less than 16"));
21575 neon_three_args (rs == NS_QQS);
21576 inst.instruction |= (index << 5);
21577 }
21578 else
21579 {
21580 inst.instruction |= (1 << 21);
21581 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21582 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21583 neon_three_args (rs == NS_QQQ);
21584 }
21585}
21586
21587static void
21588do_vsudot (void)
21589{
21590 enum neon_shape rs;
21591 set_pred_insn_type (OUTSIDE_PRED_INSN);
21592 if (inst.operands[2].isscalar)
21593 {
21594 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21595 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21596
21597 inst.instruction |= (1 << 25);
21598 int index = inst.operands[2].reg & 0xf;
21599 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21600 inst.operands[2].reg >>= 4;
21601 constraint (!(inst.operands[2].reg < 16),
21602 _("indexed register must be less than 16"));
21603 neon_three_args (rs == NS_QQS);
21604 inst.instruction |= (index << 5);
21605 }
21606}
21607
21608static void
21609do_vsmmla (void)
21610{
21611 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21612 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21613
21614 set_pred_insn_type (OUTSIDE_PRED_INSN);
21615
21616 neon_three_args (1);
21617
21618}
21619
21620static void
21621do_vummla (void)
21622{
21623 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21624 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21625
21626 set_pred_insn_type (OUTSIDE_PRED_INSN);
21627
21628 neon_three_args (1);
21629
21630}
21631
4934a27c
MM
21632static void
21633check_cde_operand (size_t index, int is_dual)
21634{
21635 unsigned Rx = inst.operands[index].reg;
21636 bfd_boolean isvec = inst.operands[index].isvec;
21637 if (is_dual == 0 && thumb_mode)
21638 constraint (
21639 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21640 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21641 else
21642 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21643 _("Register must be an even register between r0-r10."));
21644}
21645
21646static bfd_boolean
21647cde_coproc_enabled (unsigned coproc)
21648{
21649 switch (coproc)
21650 {
21651 case 0: return mark_feature_used (&arm_ext_cde0);
21652 case 1: return mark_feature_used (&arm_ext_cde1);
21653 case 2: return mark_feature_used (&arm_ext_cde2);
21654 case 3: return mark_feature_used (&arm_ext_cde3);
21655 case 4: return mark_feature_used (&arm_ext_cde4);
21656 case 5: return mark_feature_used (&arm_ext_cde5);
21657 case 6: return mark_feature_used (&arm_ext_cde6);
21658 case 7: return mark_feature_used (&arm_ext_cde7);
21659 default: return FALSE;
21660 }
21661}
21662
21663#define cde_coproc_pos 8
21664static void
21665cde_handle_coproc (void)
21666{
21667 unsigned coproc = inst.operands[0].reg;
21668 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21669 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21670 inst.instruction |= coproc << cde_coproc_pos;
21671}
21672#undef cde_coproc_pos
21673
21674static void
21675cxn_handle_predication (bfd_boolean is_accum)
21676{
21677 /* This function essentially checks for a suffix, not whether the instruction
21678 is inside an IT block or not.
21679 The CX* instructions should never have a conditional suffix -- this is not
21680 mentioned in the syntax. */
21681 if (conditional_insn ())
21682 inst.error = BAD_SYNTAX;
21683 /* Here we ensure that if the current element */
21684 else if (is_accum)
21685 set_pred_insn_type (NEUTRAL_IT_NO_VPT_INSN);
21686 else
21687 set_pred_insn_type (OUTSIDE_PRED_INSN);
21688}
21689
21690static void
21691do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21692{
21693
21694 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21695
21696 unsigned imm, Rd;
21697
21698 Rd = inst.operands[1].reg;
21699 check_cde_operand (1, is_dual);
21700
21701 if (is_dual == 1)
21702 {
21703 constraint (inst.operands[2].reg != Rd + 1,
21704 _("cx1d requires consecutive destination registers."));
21705 imm = inst.operands[3].imm;
21706 }
21707 else if (is_dual == 0)
21708 imm = inst.operands[2].imm;
21709 else
21710 abort ();
21711
21712 inst.instruction |= Rd << 12;
21713 inst.instruction |= (imm & 0x1F80) << 9;
21714 inst.instruction |= (imm & 0x0040) << 1;
21715 inst.instruction |= (imm & 0x003f);
21716
21717 cde_handle_coproc ();
21718 cxn_handle_predication (is_accum);
21719}
21720
21721static void
21722do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21723{
21724
21725 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21726
21727 unsigned imm, Rd, Rn;
21728
21729 Rd = inst.operands[1].reg;
21730
21731 if (is_dual == 1)
21732 {
21733 constraint (inst.operands[2].reg != Rd + 1,
21734 _("cx2d requires consecutive destination registers."));
21735 imm = inst.operands[4].imm;
21736 Rn = inst.operands[3].reg;
21737 }
21738 else if (is_dual == 0)
21739 {
21740 imm = inst.operands[3].imm;
21741 Rn = inst.operands[2].reg;
21742 }
21743 else
21744 abort ();
21745
21746 check_cde_operand (2 + is_dual, /* is_dual = */0);
21747 check_cde_operand (1, is_dual);
21748
21749 inst.instruction |= Rd << 12;
21750 inst.instruction |= Rn << 16;
21751
21752 inst.instruction |= (imm & 0x0380) << 13;
21753 inst.instruction |= (imm & 0x0040) << 1;
21754 inst.instruction |= (imm & 0x003f);
21755
21756 cde_handle_coproc ();
21757 cxn_handle_predication (is_accum);
21758}
21759
21760static void
21761do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21762{
21763
21764 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21765
21766 unsigned imm, Rd, Rn, Rm;
21767
21768 Rd = inst.operands[1].reg;
21769
21770 if (is_dual == 1)
21771 {
21772 constraint (inst.operands[2].reg != Rd + 1,
21773 _("cx3d requires consecutive destination registers."));
21774 imm = inst.operands[5].imm;
21775 Rn = inst.operands[3].reg;
21776 Rm = inst.operands[4].reg;
21777 }
21778 else if (is_dual == 0)
21779 {
21780 imm = inst.operands[4].imm;
21781 Rn = inst.operands[2].reg;
21782 Rm = inst.operands[3].reg;
21783 }
21784 else
21785 abort ();
21786
21787 check_cde_operand (1, is_dual);
21788 check_cde_operand (2 + is_dual, /* is_dual = */0);
21789 check_cde_operand (3 + is_dual, /* is_dual = */0);
21790
21791 inst.instruction |= Rd;
21792 inst.instruction |= Rn << 16;
21793 inst.instruction |= Rm << 12;
21794
21795 inst.instruction |= (imm & 0x0038) << 17;
21796 inst.instruction |= (imm & 0x0004) << 5;
21797 inst.instruction |= (imm & 0x0003) << 4;
21798
21799 cde_handle_coproc ();
21800 cxn_handle_predication (is_accum);
21801}
21802
21803static void
21804do_cx1 (void)
21805{
21806 return do_custom_instruction_1 (0, 0);
21807}
21808
21809static void
21810do_cx1a (void)
21811{
21812 return do_custom_instruction_1 (0, 1);
21813}
21814
21815static void
21816do_cx1d (void)
21817{
21818 return do_custom_instruction_1 (1, 0);
21819}
21820
21821static void
21822do_cx1da (void)
21823{
21824 return do_custom_instruction_1 (1, 1);
21825}
21826
21827static void
21828do_cx2 (void)
21829{
21830 return do_custom_instruction_2 (0, 0);
21831}
21832
21833static void
21834do_cx2a (void)
21835{
21836 return do_custom_instruction_2 (0, 1);
21837}
21838
21839static void
21840do_cx2d (void)
21841{
21842 return do_custom_instruction_2 (1, 0);
21843}
21844
21845static void
21846do_cx2da (void)
21847{
21848 return do_custom_instruction_2 (1, 1);
21849}
21850
21851static void
21852do_cx3 (void)
21853{
21854 return do_custom_instruction_3 (0, 0);
21855}
21856
21857static void
21858do_cx3a (void)
21859{
21860 return do_custom_instruction_3 (0, 1);
21861}
21862
21863static void
21864do_cx3d (void)
21865{
21866 return do_custom_instruction_3 (1, 0);
21867}
21868
21869static void
21870do_cx3da (void)
21871{
21872 return do_custom_instruction_3 (1, 1);
21873}
21874
5aae9ae9
MM
21875static void
21876vcx_assign_vec_d (unsigned regnum)
21877{
21878 inst.instruction |= HI4 (regnum) << 12;
21879 inst.instruction |= LOW1 (regnum) << 22;
21880}
21881
21882static void
21883vcx_assign_vec_m (unsigned regnum)
21884{
21885 inst.instruction |= HI4 (regnum);
21886 inst.instruction |= LOW1 (regnum) << 5;
21887}
21888
21889static void
21890vcx_assign_vec_n (unsigned regnum)
21891{
21892 inst.instruction |= HI4 (regnum) << 16;
21893 inst.instruction |= LOW1 (regnum) << 7;
21894}
21895
21896enum vcx_reg_type {
21897 q_reg,
21898 d_reg,
21899 s_reg
21900};
21901
21902static enum vcx_reg_type
21903vcx_get_reg_type (enum neon_shape ns)
21904{
21905 gas_assert (ns == NS_PQI
21906 || ns == NS_PDI
21907 || ns == NS_PFI
21908 || ns == NS_PQQI
21909 || ns == NS_PDDI
21910 || ns == NS_PFFI
21911 || ns == NS_PQQQI
21912 || ns == NS_PDDDI
21913 || ns == NS_PFFFI);
21914 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21915 return q_reg;
21916 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21917 return d_reg;
21918 return s_reg;
21919}
21920
21921#define vcx_size_pos 24
21922#define vcx_vec_pos 6
21923static unsigned
21924vcx_handle_shape (enum vcx_reg_type reg_type)
21925{
21926 unsigned mult = 2;
21927 if (reg_type == q_reg)
21928 inst.instruction |= 1 << vcx_vec_pos;
21929 else if (reg_type == d_reg)
21930 inst.instruction |= 1 << vcx_size_pos;
21931 else
21932 mult = 1;
21933 /* NOTE:
21934 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21935 bits (or equivalent for N and M registers).
21936 Similarly the D registers are encoded as N in D:Vd bits.
21937 While the S registers are encoded as N in the Vd:D bits.
21938
21939 Taking into account the maximum values of these registers we can see a
21940 nicer pattern for calculation:
21941 Q -> 7, D -> 15, S -> 31
21942
21943 If we say that everything is encoded in the Vd:D bits, then we can say
21944 that Q is encoded as 4*N, and D is encoded as 2*N.
21945 This way the bits will end up the same, and calculation is simpler.
21946 (calculation is now:
21947 1. Multiply by a number determined by the register letter.
21948 2. Encode resulting number in Vd:D bits.)
21949
21950 This is made a little more complicated by automatic handling of 'Q'
21951 registers elsewhere, which means the register number is already 2*N where
21952 N is the number the user wrote after the register letter.
21953 */
21954 return mult;
21955}
21956#undef vcx_vec_pos
21957#undef vcx_size_pos
21958
21959static void
21960vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21961{
21962 if (reg_type == q_reg)
21963 {
21964 gas_assert (R % 2 == 0);
21965 constraint (R >= 16, _("'q' register must be in range 0-7"));
21966 }
21967 else if (reg_type == d_reg)
21968 constraint (R >= 16, _("'d' register must be in range 0-15"));
21969 else
21970 constraint (R >= 32, _("'s' register must be in range 0-31"));
21971}
21972
21973static void (*vcx_assign_vec[3]) (unsigned) = {
21974 vcx_assign_vec_d,
21975 vcx_assign_vec_m,
21976 vcx_assign_vec_n
21977};
21978
21979static void
21980vcx_handle_register_arguments (unsigned num_registers,
21981 enum vcx_reg_type reg_type)
21982{
21983 unsigned R;
21984 unsigned reg_mult = vcx_handle_shape (reg_type);
21985 for (unsigned i = 0; i < num_registers; i++)
21986 {
21987 R = inst.operands[i+1].reg;
21988 vcx_ensure_register_in_range (R, reg_type);
21989 if (num_registers == 3 && i > 0)
21990 {
21991 if (i == 2)
21992 vcx_assign_vec[1] (R * reg_mult);
21993 else
21994 vcx_assign_vec[2] (R * reg_mult);
21995 continue;
21996 }
21997 vcx_assign_vec[i](R * reg_mult);
21998 }
21999}
22000
22001static void
22002vcx_handle_insn_block (enum vcx_reg_type reg_type)
22003{
22004 if (reg_type == q_reg)
22005 if (inst.cond > COND_ALWAYS)
22006 inst.pred_insn_type = INSIDE_VPT_INSN;
22007 else
22008 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22009 else if (inst.cond == COND_ALWAYS)
22010 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22011 else
22012 inst.error = BAD_NOT_IT;
22013}
22014
22015static void
22016vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22017{
22018 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22019 cde_handle_coproc ();
22020 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22021 vcx_handle_register_arguments (num_args, reg_type);
22022 vcx_handle_insn_block (reg_type);
22023 if (reg_type == q_reg)
22024 constraint (!mark_feature_used (&mve_ext),
22025 _("vcx instructions with Q registers require MVE"));
22026 else
22027 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22028 && mark_feature_used (&armv8m_fp))
22029 && !mark_feature_used (&mve_ext),
22030 _("vcx instructions with S or D registers require either MVE"
22031 " or Armv8-M floating point etension."));
22032}
22033
22034static void
22035do_vcx1 (void)
22036{
22037 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22038 vcx_handle_common_checks (1, rs);
22039
22040 unsigned imm = inst.operands[2].imm;
22041 inst.instruction |= (imm & 0x03f);
22042 inst.instruction |= (imm & 0x040) << 1;
22043 inst.instruction |= (imm & 0x780) << 9;
22044 if (rs != NS_PQI)
22045 constraint (imm >= 2048,
22046 _("vcx1 with S or D registers takes immediate within 0-2047"));
22047 inst.instruction |= (imm & 0x800) << 13;
22048}
22049
22050static void
22051do_vcx2 (void)
22052{
22053 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22054 vcx_handle_common_checks (2, rs);
22055
22056 unsigned imm = inst.operands[3].imm;
22057 inst.instruction |= (imm & 0x01) << 4;
22058 inst.instruction |= (imm & 0x02) << 6;
22059 inst.instruction |= (imm & 0x3c) << 14;
22060 if (rs != NS_PQQI)
22061 constraint (imm >= 64,
22062 _("vcx2 with S or D registers takes immediate within 0-63"));
22063 inst.instruction |= (imm & 0x40) << 18;
22064}
22065
22066static void
22067do_vcx3 (void)
22068{
22069 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22070 vcx_handle_common_checks (3, rs);
22071
22072 unsigned imm = inst.operands[4].imm;
22073 inst.instruction |= (imm & 0x1) << 4;
22074 inst.instruction |= (imm & 0x6) << 19;
22075 if (rs != NS_PQQQI)
22076 constraint (imm >= 8,
22077 _("vcx2 with S or D registers takes immediate within 0-7"));
22078 inst.instruction |= (imm & 0x8) << 21;
22079}
22080
91ff7894
MGD
22081/* Crypto v1 instructions. */
22082static void
22083do_crypto_2op_1 (unsigned elttype, int op)
22084{
5ee91343 22085 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
22086
22087 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22088 == NT_invtype)
22089 return;
22090
22091 inst.error = NULL;
22092
22093 NEON_ENCODE (INTEGER, inst);
22094 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22096 inst.instruction |= LOW4 (inst.operands[1].reg);
22097 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22098 if (op != -1)
22099 inst.instruction |= op << 6;
22100
22101 if (thumb_mode)
22102 inst.instruction |= 0xfc000000;
22103 else
22104 inst.instruction |= 0xf0000000;
22105}
22106
48adcd8e
MGD
22107static void
22108do_crypto_3op_1 (int u, int op)
22109{
5ee91343 22110 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
22111
22112 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22113 N_32 | N_UNT | N_KEY).type == NT_invtype)
22114 return;
22115
22116 inst.error = NULL;
22117
22118 NEON_ENCODE (INTEGER, inst);
22119 neon_three_same (1, u, 8 << op);
22120}
22121
91ff7894
MGD
22122static void
22123do_aese (void)
22124{
22125 do_crypto_2op_1 (N_8, 0);
22126}
22127
22128static void
22129do_aesd (void)
22130{
22131 do_crypto_2op_1 (N_8, 1);
22132}
22133
22134static void
22135do_aesmc (void)
22136{
22137 do_crypto_2op_1 (N_8, 2);
22138}
22139
22140static void
22141do_aesimc (void)
22142{
22143 do_crypto_2op_1 (N_8, 3);
22144}
22145
48adcd8e
MGD
22146static void
22147do_sha1c (void)
22148{
22149 do_crypto_3op_1 (0, 0);
22150}
22151
22152static void
22153do_sha1p (void)
22154{
22155 do_crypto_3op_1 (0, 1);
22156}
22157
22158static void
22159do_sha1m (void)
22160{
22161 do_crypto_3op_1 (0, 2);
22162}
22163
22164static void
22165do_sha1su0 (void)
22166{
22167 do_crypto_3op_1 (0, 3);
22168}
91ff7894 22169
48adcd8e
MGD
22170static void
22171do_sha256h (void)
22172{
22173 do_crypto_3op_1 (1, 0);
22174}
22175
22176static void
22177do_sha256h2 (void)
22178{
22179 do_crypto_3op_1 (1, 1);
22180}
22181
22182static void
22183do_sha256su1 (void)
22184{
22185 do_crypto_3op_1 (1, 2);
22186}
3c9017d2
MGD
22187
22188static void
22189do_sha1h (void)
22190{
22191 do_crypto_2op_1 (N_32, -1);
22192}
22193
22194static void
22195do_sha1su1 (void)
22196{
22197 do_crypto_2op_1 (N_32, 0);
22198}
22199
22200static void
22201do_sha256su0 (void)
22202{
22203 do_crypto_2op_1 (N_32, 1);
22204}
dd5181d5
KT
22205
22206static void
22207do_crc32_1 (unsigned int poly, unsigned int sz)
22208{
22209 unsigned int Rd = inst.operands[0].reg;
22210 unsigned int Rn = inst.operands[1].reg;
22211 unsigned int Rm = inst.operands[2].reg;
22212
5ee91343 22213 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
22214 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22215 inst.instruction |= LOW4 (Rn) << 16;
22216 inst.instruction |= LOW4 (Rm);
22217 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22218 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22219
22220 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22221 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
22222}
22223
22224static void
22225do_crc32b (void)
22226{
22227 do_crc32_1 (0, 0);
22228}
22229
22230static void
22231do_crc32h (void)
22232{
22233 do_crc32_1 (0, 1);
22234}
22235
22236static void
22237do_crc32w (void)
22238{
22239 do_crc32_1 (0, 2);
22240}
22241
22242static void
22243do_crc32cb (void)
22244{
22245 do_crc32_1 (1, 0);
22246}
22247
22248static void
22249do_crc32ch (void)
22250{
22251 do_crc32_1 (1, 1);
22252}
22253
22254static void
22255do_crc32cw (void)
22256{
22257 do_crc32_1 (1, 2);
22258}
22259
49e8a725
SN
22260static void
22261do_vjcvt (void)
22262{
22263 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22264 _(BAD_FPU));
22265 neon_check_type (2, NS_FD, N_S32, N_F64);
22266 do_vfp_sp_dp_cvt ();
22267 do_vfp_cond_or_thumb ();
22268}
22269
aab2c27d
MM
22270static void
22271do_vdot (void)
22272{
22273 enum neon_shape rs;
22274 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22275 set_pred_insn_type (OUTSIDE_PRED_INSN);
22276 if (inst.operands[2].isscalar)
22277 {
22278 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22279 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22280
22281 inst.instruction |= (1 << 25);
22282 int index = inst.operands[2].reg & 0xf;
22283 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22284 inst.operands[2].reg >>= 4;
22285 constraint (!(inst.operands[2].reg < 16),
22286 _("indexed register must be less than 16"));
22287 neon_three_args (rs == NS_QQS);
22288 inst.instruction |= (index << 5);
22289 }
22290 else
22291 {
22292 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22293 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22294 neon_three_args (rs == NS_QQQ);
22295 }
22296}
22297
22298static void
22299do_vmmla (void)
22300{
22301 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22302 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22303
22304 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22305 set_pred_insn_type (OUTSIDE_PRED_INSN);
22306
22307 neon_three_args (1);
22308}
22309
5287ad62
JB
22310\f
22311/* Overall per-instruction processing. */
22312
22313/* We need to be able to fix up arbitrary expressions in some statements.
22314 This is so that we can handle symbols that are an arbitrary distance from
22315 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22316 which returns part of an address in a form which will be valid for
22317 a data instruction. We do this by pushing the expression into a symbol
22318 in the expr_section, and creating a fix for that. */
22319
22320static void
22321fix_new_arm (fragS * frag,
22322 int where,
22323 short int size,
22324 expressionS * exp,
22325 int pc_rel,
22326 int reloc)
22327{
22328 fixS * new_fix;
22329
22330 switch (exp->X_op)
22331 {
22332 case O_constant:
6e7ce2cd
PB
22333 if (pc_rel)
22334 {
22335 /* Create an absolute valued symbol, so we have something to
477330fc
RM
22336 refer to in the object file. Unfortunately for us, gas's
22337 generic expression parsing will already have folded out
22338 any use of .set foo/.type foo %function that may have
22339 been used to set type information of the target location,
22340 that's being specified symbolically. We have to presume
22341 the user knows what they are doing. */
6e7ce2cd
PB
22342 char name[16 + 8];
22343 symbolS *symbol;
22344
22345 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22346
22347 symbol = symbol_find_or_make (name);
22348 S_SET_SEGMENT (symbol, absolute_section);
22349 symbol_set_frag (symbol, &zero_address_frag);
22350 S_SET_VALUE (symbol, exp->X_add_number);
22351 exp->X_op = O_symbol;
22352 exp->X_add_symbol = symbol;
22353 exp->X_add_number = 0;
22354 }
22355 /* FALLTHROUGH */
5287ad62
JB
22356 case O_symbol:
22357 case O_add:
22358 case O_subtract:
21d799b5 22359 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 22360 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22361 break;
22362
22363 default:
21d799b5 22364 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 22365 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22366 break;
22367 }
22368
22369 /* Mark whether the fix is to a THUMB instruction, or an ARM
22370 instruction. */
22371 new_fix->tc_fix_data = thumb_mode;
22372}
22373
22374/* Create a frg for an instruction requiring relaxation. */
22375static void
22376output_relax_insn (void)
22377{
22378 char * to;
22379 symbolS *sym;
0110f2b8
PB
22380 int offset;
22381
6e1cb1a6
PB
22382 /* The size of the instruction is unknown, so tie the debug info to the
22383 start of the instruction. */
22384 dwarf2_emit_insn (0);
6e1cb1a6 22385
e2b0ab59 22386 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
22387 {
22388 case O_symbol:
e2b0ab59
AV
22389 sym = inst.relocs[0].exp.X_add_symbol;
22390 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22391 break;
22392 case O_constant:
22393 sym = NULL;
e2b0ab59 22394 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22395 break;
22396 default:
e2b0ab59 22397 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
22398 offset = 0;
22399 break;
22400 }
22401 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22402 inst.relax, sym, offset, NULL/*offset, opcode*/);
22403 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
22404}
22405
22406/* Write a 32-bit thumb instruction to buf. */
22407static void
22408put_thumb32_insn (char * buf, unsigned long insn)
22409{
22410 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22411 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22412}
22413
b99bd4ef 22414static void
c19d1205 22415output_inst (const char * str)
b99bd4ef 22416{
c19d1205 22417 char * to = NULL;
b99bd4ef 22418
c19d1205 22419 if (inst.error)
b99bd4ef 22420 {
c19d1205 22421 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
22422 return;
22423 }
5f4273c7
NC
22424 if (inst.relax)
22425 {
22426 output_relax_insn ();
0110f2b8 22427 return;
5f4273c7 22428 }
c19d1205
ZW
22429 if (inst.size == 0)
22430 return;
b99bd4ef 22431
c19d1205 22432 to = frag_more (inst.size);
8dc2430f
NC
22433 /* PR 9814: Record the thumb mode into the current frag so that we know
22434 what type of NOP padding to use, if necessary. We override any previous
22435 setting so that if the mode has changed then the NOPS that we use will
22436 match the encoding of the last instruction in the frag. */
cd000bff 22437 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
22438
22439 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 22440 {
9c2799c2 22441 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 22442 put_thumb32_insn (to, inst.instruction);
b99bd4ef 22443 }
c19d1205 22444 else if (inst.size > INSN_SIZE)
b99bd4ef 22445 {
9c2799c2 22446 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
22447 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22448 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 22449 }
c19d1205
ZW
22450 else
22451 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 22452
e2b0ab59
AV
22453 int r;
22454 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22455 {
22456 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22457 fix_new_arm (frag_now, to - frag_now->fr_literal,
22458 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22459 inst.relocs[r].type);
22460 }
b99bd4ef 22461
c19d1205 22462 dwarf2_emit_insn (inst.size);
c19d1205 22463}
b99bd4ef 22464
e07e6e58
NC
22465static char *
22466output_it_inst (int cond, int mask, char * to)
22467{
22468 unsigned long instruction = 0xbf00;
22469
22470 mask &= 0xf;
22471 instruction |= mask;
22472 instruction |= cond << 4;
22473
22474 if (to == NULL)
22475 {
22476 to = frag_more (2);
22477#ifdef OBJ_ELF
22478 dwarf2_emit_insn (2);
22479#endif
22480 }
22481
22482 md_number_to_chars (to, instruction, 2);
22483
22484 return to;
22485}
22486
c19d1205
ZW
22487/* Tag values used in struct asm_opcode's tag field. */
22488enum opcode_tag
22489{
22490 OT_unconditional, /* Instruction cannot be conditionalized.
22491 The ARM condition field is still 0xE. */
22492 OT_unconditionalF, /* Instruction cannot be conditionalized
22493 and carries 0xF in its ARM condition field. */
22494 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
22495 OT_csuffixF, /* Some forms of the instruction take a scalar
22496 conditional suffix, others place 0xF where the
22497 condition field would be, others take a vector
22498 conditional suffix. */
c19d1205
ZW
22499 OT_cinfix3, /* Instruction takes a conditional infix,
22500 beginning at character index 3. (In
22501 unified mode, it becomes a suffix.) */
088fa78e
KH
22502 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22503 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
22504 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22505 character index 3, even in unified mode. Used for
22506 legacy instructions where suffix and infix forms
22507 may be ambiguous. */
c19d1205 22508 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 22509 suffix or an infix at character index 3. */
c19d1205
ZW
22510 OT_odd_infix_unc, /* This is the unconditional variant of an
22511 instruction that takes a conditional infix
22512 at an unusual position. In unified mode,
22513 this variant will accept a suffix. */
22514 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22515 are the conditional variants of instructions that
22516 take conditional infixes in unusual positions.
22517 The infix appears at character index
22518 (tag - OT_odd_infix_0). These are not accepted
22519 in unified mode. */
22520};
b99bd4ef 22521
c19d1205
ZW
22522/* Subroutine of md_assemble, responsible for looking up the primary
22523 opcode from the mnemonic the user wrote. STR points to the
22524 beginning of the mnemonic.
22525
22526 This is not simply a hash table lookup, because of conditional
22527 variants. Most instructions have conditional variants, which are
22528 expressed with a _conditional affix_ to the mnemonic. If we were
22529 to encode each conditional variant as a literal string in the opcode
22530 table, it would have approximately 20,000 entries.
22531
22532 Most mnemonics take this affix as a suffix, and in unified syntax,
22533 'most' is upgraded to 'all'. However, in the divided syntax, some
22534 instructions take the affix as an infix, notably the s-variants of
22535 the arithmetic instructions. Of those instructions, all but six
22536 have the infix appear after the third character of the mnemonic.
22537
22538 Accordingly, the algorithm for looking up primary opcodes given
22539 an identifier is:
22540
22541 1. Look up the identifier in the opcode table.
22542 If we find a match, go to step U.
22543
22544 2. Look up the last two characters of the identifier in the
22545 conditions table. If we find a match, look up the first N-2
22546 characters of the identifier in the opcode table. If we
22547 find a match, go to step CE.
22548
22549 3. Look up the fourth and fifth characters of the identifier in
22550 the conditions table. If we find a match, extract those
22551 characters from the identifier, and look up the remaining
22552 characters in the opcode table. If we find a match, go
22553 to step CM.
22554
22555 4. Fail.
22556
22557 U. Examine the tag field of the opcode structure, in case this is
22558 one of the six instructions with its conditional infix in an
22559 unusual place. If it is, the tag tells us where to find the
22560 infix; look it up in the conditions table and set inst.cond
22561 accordingly. Otherwise, this is an unconditional instruction.
22562 Again set inst.cond accordingly. Return the opcode structure.
22563
22564 CE. Examine the tag field to make sure this is an instruction that
22565 should receive a conditional suffix. If it is not, fail.
22566 Otherwise, set inst.cond from the suffix we already looked up,
22567 and return the opcode structure.
22568
22569 CM. Examine the tag field to make sure this is an instruction that
22570 should receive a conditional infix after the third character.
22571 If it is not, fail. Otherwise, undo the edits to the current
22572 line of input and proceed as for case CE. */
22573
22574static const struct asm_opcode *
22575opcode_lookup (char **str)
22576{
22577 char *end, *base;
22578 char *affix;
22579 const struct asm_opcode *opcode;
22580 const struct asm_cond *cond;
e3cb604e 22581 char save[2];
c19d1205
ZW
22582
22583 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 22584 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 22585 for (base = end = *str; *end != '\0'; end++)
721a8186 22586 if (*end == ' ' || *end == '.')
c19d1205 22587 break;
b99bd4ef 22588
c19d1205 22589 if (end == base)
c921be7d 22590 return NULL;
b99bd4ef 22591
5287ad62 22592 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 22593 if (end[0] == '.')
b99bd4ef 22594 {
5287ad62 22595 int offset = 2;
5f4273c7 22596
267d2029 22597 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 22598 use. */
267d2029 22599 if (unified_syntax && end[1] == 'w')
c19d1205 22600 inst.size_req = 4;
267d2029 22601 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
22602 inst.size_req = 2;
22603 else
477330fc 22604 offset = 0;
5287ad62
JB
22605
22606 inst.vectype.elems = 0;
22607
22608 *str = end + offset;
b99bd4ef 22609
5f4273c7 22610 if (end[offset] == '.')
5287ad62 22611 {
267d2029 22612 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
22613 non-unified ARM syntax mode). */
22614 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 22615 return NULL;
477330fc 22616 }
5287ad62 22617 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 22618 return NULL;
b99bd4ef 22619 }
c19d1205
ZW
22620 else
22621 *str = end;
b99bd4ef 22622
c19d1205 22623 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 22624 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22625 end - base);
c19d1205 22626 if (opcode)
b99bd4ef 22627 {
c19d1205
ZW
22628 /* step U */
22629 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 22630 {
c19d1205
ZW
22631 inst.cond = COND_ALWAYS;
22632 return opcode;
b99bd4ef 22633 }
b99bd4ef 22634
278df34e 22635 if (warn_on_deprecated && unified_syntax)
5c3696f8 22636 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 22637 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 22638 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 22639 gas_assert (cond);
b99bd4ef 22640
c19d1205
ZW
22641 inst.cond = cond->value;
22642 return opcode;
22643 }
5ee91343
AV
22644 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22645 {
22646 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22647 */
22648 if (end - base < 2)
22649 return NULL;
22650 affix = end - 1;
22651 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
22652 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22653 affix - base);
22654 /* If this opcode can not be vector predicated then don't accept it with a
22655 vector predication code. */
22656 if (opcode && !opcode->mayBeVecPred)
22657 opcode = NULL;
22658 }
22659 if (!opcode || !cond)
22660 {
22661 /* Cannot have a conditional suffix on a mnemonic of less than two
22662 characters. */
22663 if (end - base < 3)
22664 return NULL;
b99bd4ef 22665
5ee91343
AV
22666 /* Look for suffixed mnemonic. */
22667 affix = end - 2;
22668 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22669 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22670 affix - base);
22671 }
b99bd4ef 22672
c19d1205
ZW
22673 if (opcode && cond)
22674 {
22675 /* step CE */
22676 switch (opcode->tag)
22677 {
e3cb604e
PB
22678 case OT_cinfix3_legacy:
22679 /* Ignore conditional suffixes matched on infix only mnemonics. */
22680 break;
22681
c19d1205 22682 case OT_cinfix3:
088fa78e 22683 case OT_cinfix3_deprecated:
c19d1205
ZW
22684 case OT_odd_infix_unc:
22685 if (!unified_syntax)
0198d5e6 22686 return NULL;
1a0670f3 22687 /* Fall through. */
c19d1205
ZW
22688
22689 case OT_csuffix:
477330fc 22690 case OT_csuffixF:
c19d1205
ZW
22691 case OT_csuf_or_in3:
22692 inst.cond = cond->value;
22693 return opcode;
22694
22695 case OT_unconditional:
22696 case OT_unconditionalF:
dfa9f0d5 22697 if (thumb_mode)
c921be7d 22698 inst.cond = cond->value;
dfa9f0d5
PB
22699 else
22700 {
c921be7d 22701 /* Delayed diagnostic. */
dfa9f0d5
PB
22702 inst.error = BAD_COND;
22703 inst.cond = COND_ALWAYS;
22704 }
c19d1205 22705 return opcode;
b99bd4ef 22706
c19d1205 22707 default:
c921be7d 22708 return NULL;
c19d1205
ZW
22709 }
22710 }
b99bd4ef 22711
c19d1205
ZW
22712 /* Cannot have a usual-position infix on a mnemonic of less than
22713 six characters (five would be a suffix). */
22714 if (end - base < 6)
c921be7d 22715 return NULL;
b99bd4ef 22716
c19d1205
ZW
22717 /* Look for infixed mnemonic in the usual position. */
22718 affix = base + 3;
21d799b5 22719 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 22720 if (!cond)
c921be7d 22721 return NULL;
e3cb604e
PB
22722
22723 memcpy (save, affix, 2);
22724 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 22725 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22726 (end - base) - 2);
e3cb604e
PB
22727 memmove (affix + 2, affix, (end - affix) - 2);
22728 memcpy (affix, save, 2);
22729
088fa78e
KH
22730 if (opcode
22731 && (opcode->tag == OT_cinfix3
22732 || opcode->tag == OT_cinfix3_deprecated
22733 || opcode->tag == OT_csuf_or_in3
22734 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 22735 {
c921be7d 22736 /* Step CM. */
278df34e 22737 if (warn_on_deprecated && unified_syntax
088fa78e
KH
22738 && (opcode->tag == OT_cinfix3
22739 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 22740 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
22741
22742 inst.cond = cond->value;
22743 return opcode;
b99bd4ef
NC
22744 }
22745
c921be7d 22746 return NULL;
b99bd4ef
NC
22747}
22748
e07e6e58
NC
22749/* This function generates an initial IT instruction, leaving its block
22750 virtually open for the new instructions. Eventually,
5ee91343 22751 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
22752 a new instruction needs to be included in the IT block.
22753 Finally, the block is closed with close_automatic_it_block ().
22754 The block closure can be requested either from md_assemble (),
22755 a tencode (), or due to a label hook. */
22756
22757static void
22758new_automatic_it_block (int cond)
22759{
5ee91343
AV
22760 now_pred.state = AUTOMATIC_PRED_BLOCK;
22761 now_pred.mask = 0x18;
22762 now_pred.cc = cond;
22763 now_pred.block_length = 1;
cd000bff 22764 mapping_state (MAP_THUMB);
5ee91343
AV
22765 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22766 now_pred.warn_deprecated = FALSE;
22767 now_pred.insn_cond = TRUE;
e07e6e58
NC
22768}
22769
22770/* Close an automatic IT block.
22771 See comments in new_automatic_it_block (). */
22772
22773static void
22774close_automatic_it_block (void)
22775{
5ee91343
AV
22776 now_pred.mask = 0x10;
22777 now_pred.block_length = 0;
e07e6e58
NC
22778}
22779
22780/* Update the mask of the current automatically-generated IT
22781 instruction. See comments in new_automatic_it_block (). */
22782
22783static void
5ee91343 22784now_pred_add_mask (int cond)
e07e6e58
NC
22785{
22786#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22787#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 22788 | ((bitvalue) << (nbit)))
e07e6e58 22789 const int resulting_bit = (cond & 1);
c921be7d 22790
5ee91343
AV
22791 now_pred.mask &= 0xf;
22792 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22793 resulting_bit,
5ee91343
AV
22794 (5 - now_pred.block_length));
22795 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22796 1,
5ee91343
AV
22797 ((5 - now_pred.block_length) - 1));
22798 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
22799
22800#undef CLEAR_BIT
22801#undef SET_BIT_VALUE
e07e6e58
NC
22802}
22803
22804/* The IT blocks handling machinery is accessed through the these functions:
22805 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
22806 set_pred_insn_type () optional, from the tencode functions
22807 set_pred_insn_type_last () ditto
22808 in_pred_block () ditto
e07e6e58 22809 it_fsm_post_encode () from md_assemble ()
33eaf5de 22810 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
22811
22812 Rationale:
22813 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
22814 initializing the IT insn type with a generic initial value depending
22815 on the inst.condition.
e07e6e58 22816 2) During the tencode function, two things may happen:
477330fc 22817 a) The tencode function overrides the IT insn type by
5ee91343
AV
22818 calling either set_pred_insn_type (type) or
22819 set_pred_insn_type_last ().
477330fc 22820 b) The tencode function queries the IT block state by
5ee91343 22821 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 22822
5ee91343
AV
22823 Both set_pred_insn_type and in_pred_block run the internal FSM state
22824 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
22825 type may incur in an invalid state (exiting the function),
22826 and b) querying the state requires the FSM to be updated.
22827 Specifically we want to avoid creating an IT block for conditional
22828 branches, so it_fsm_pre_encode is actually a guess and we can't
22829 determine whether an IT block is required until the tencode () routine
22830 has decided what type of instruction this actually it.
5ee91343
AV
22831 Because of this, if set_pred_insn_type and in_pred_block have to be
22832 used, set_pred_insn_type has to be called first.
477330fc 22833
5ee91343
AV
22834 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22835 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
22836 When a tencode () routine encodes an instruction that can be
22837 either outside an IT block, or, in the case of being inside, has to be
5ee91343 22838 the last one, set_pred_insn_type_last () will determine the proper
477330fc 22839 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 22840 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
22841 for covering other cases.
22842
5ee91343
AV
22843 Calling handle_pred_state () may not transition the IT block state to
22844 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 22845 still queried. Instead, if the FSM determines that the state should
5ee91343 22846 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
22847 after the tencode () function: that's what it_fsm_post_encode () does.
22848
5ee91343 22849 Since in_pred_block () calls the state handling function to get an
477330fc
RM
22850 updated state, an error may occur (due to invalid insns combination).
22851 In that case, inst.error is set.
22852 Therefore, inst.error has to be checked after the execution of
22853 the tencode () routine.
e07e6e58
NC
22854
22855 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 22856 any pending state change (if any) that didn't take place in
5ee91343 22857 handle_pred_state () as explained above. */
e07e6e58
NC
22858
22859static void
22860it_fsm_pre_encode (void)
22861{
22862 if (inst.cond != COND_ALWAYS)
5ee91343 22863 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 22864 else
5ee91343 22865 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 22866
5ee91343 22867 now_pred.state_handled = 0;
e07e6e58
NC
22868}
22869
22870/* IT state FSM handling function. */
5ee91343
AV
22871/* MVE instructions and non-MVE instructions are handled differently because of
22872 the introduction of VPT blocks.
22873 Specifications say that any non-MVE instruction inside a VPT block is
22874 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22875 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 22876 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
22877 The error messages provided depending on the different combinations possible
22878 are described in the cases below:
22879 For 'most' MVE instructions:
22880 1) In an IT block, with an IT code: syntax error
22881 2) In an IT block, with a VPT code: error: must be in a VPT block
22882 3) In an IT block, with no code: warning: UNPREDICTABLE
22883 4) In a VPT block, with an IT code: syntax error
22884 5) In a VPT block, with a VPT code: OK!
22885 6) In a VPT block, with no code: error: missing code
22886 7) Outside a pred block, with an IT code: error: syntax error
22887 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22888 9) Outside a pred block, with no code: OK!
22889 For non-MVE instructions:
22890 10) In an IT block, with an IT code: OK!
22891 11) In an IT block, with a VPT code: syntax error
22892 12) In an IT block, with no code: error: missing code
22893 13) In a VPT block, with an IT code: error: should be in an IT block
22894 14) In a VPT block, with a VPT code: syntax error
22895 15) In a VPT block, with no code: UNPREDICTABLE
22896 16) Outside a pred block, with an IT code: error: should be in an IT block
22897 17) Outside a pred block, with a VPT code: syntax error
22898 18) Outside a pred block, with no code: OK!
22899 */
22900
e07e6e58
NC
22901
22902static int
5ee91343 22903handle_pred_state (void)
e07e6e58 22904{
5ee91343
AV
22905 now_pred.state_handled = 1;
22906 now_pred.insn_cond = FALSE;
e07e6e58 22907
5ee91343 22908 switch (now_pred.state)
e07e6e58 22909 {
5ee91343
AV
22910 case OUTSIDE_PRED_BLOCK:
22911 switch (inst.pred_insn_type)
e07e6e58 22912 {
35c228db 22913 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22914 case MVE_OUTSIDE_PRED_INSN:
22915 if (inst.cond < COND_ALWAYS)
22916 {
22917 /* Case 7: Outside a pred block, with an IT code: error: syntax
22918 error. */
22919 inst.error = BAD_SYNTAX;
22920 return FAIL;
22921 }
22922 /* Case 9: Outside a pred block, with no code: OK! */
22923 break;
22924 case OUTSIDE_PRED_INSN:
22925 if (inst.cond > COND_ALWAYS)
22926 {
22927 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22928 */
22929 inst.error = BAD_SYNTAX;
22930 return FAIL;
22931 }
22932 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22933 break;
22934
5ee91343
AV
22935 case INSIDE_VPT_INSN:
22936 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22937 a VPT block. */
22938 inst.error = BAD_OUT_VPT;
22939 return FAIL;
22940
e07e6e58
NC
22941 case INSIDE_IT_INSN:
22942 case INSIDE_IT_LAST_INSN:
5ee91343 22943 if (inst.cond < COND_ALWAYS)
e07e6e58 22944 {
5ee91343
AV
22945 /* Case 16: Outside a pred block, with an IT code: error: should
22946 be in an IT block. */
22947 if (thumb_mode == 0)
e07e6e58 22948 {
5ee91343
AV
22949 if (unified_syntax
22950 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22951 as_tsktsk (_("Warning: conditional outside an IT block"\
22952 " for Thumb."));
e07e6e58
NC
22953 }
22954 else
22955 {
5ee91343
AV
22956 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22957 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22958 {
22959 /* Automatically generate the IT instruction. */
22960 new_automatic_it_block (inst.cond);
22961 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22962 close_automatic_it_block ();
22963 }
22964 else
22965 {
22966 inst.error = BAD_OUT_IT;
22967 return FAIL;
22968 }
e07e6e58 22969 }
5ee91343 22970 break;
e07e6e58 22971 }
5ee91343
AV
22972 else if (inst.cond > COND_ALWAYS)
22973 {
22974 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22975 */
22976 inst.error = BAD_SYNTAX;
22977 return FAIL;
22978 }
22979 else
22980 gas_assert (0);
e07e6e58
NC
22981 case IF_INSIDE_IT_LAST_INSN:
22982 case NEUTRAL_IT_INSN:
4934a27c 22983 case NEUTRAL_IT_NO_VPT_INSN:
e07e6e58
NC
22984 break;
22985
5ee91343
AV
22986 case VPT_INSN:
22987 if (inst.cond != COND_ALWAYS)
22988 first_error (BAD_SYNTAX);
22989 now_pred.state = MANUAL_PRED_BLOCK;
22990 now_pred.block_length = 0;
22991 now_pred.type = VECTOR_PRED;
22992 now_pred.cc = 0;
22993 break;
e07e6e58 22994 case IT_INSN:
5ee91343
AV
22995 now_pred.state = MANUAL_PRED_BLOCK;
22996 now_pred.block_length = 0;
22997 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22998 break;
22999 }
23000 break;
23001
5ee91343 23002 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
23003 /* Three things may happen now:
23004 a) We should increment current it block size;
23005 b) We should close current it block (closing insn or 4 insns);
23006 c) We should close current it block and start a new one (due
23007 to incompatible conditions or
23008 4 insns-length block reached). */
23009
5ee91343 23010 switch (inst.pred_insn_type)
e07e6e58 23011 {
5ee91343
AV
23012 case INSIDE_VPT_INSN:
23013 case VPT_INSN:
35c228db 23014 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
23015 case MVE_OUTSIDE_PRED_INSN:
23016 gas_assert (0);
23017 case OUTSIDE_PRED_INSN:
2b0f3761 23018 /* The closure of the block shall happen immediately,
5ee91343 23019 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
23020 force_automatic_it_block_close ();
23021 break;
23022
23023 case INSIDE_IT_INSN:
23024 case INSIDE_IT_LAST_INSN:
23025 case IF_INSIDE_IT_LAST_INSN:
5ee91343 23026 now_pred.block_length++;
e07e6e58 23027
5ee91343
AV
23028 if (now_pred.block_length > 4
23029 || !now_pred_compatible (inst.cond))
e07e6e58
NC
23030 {
23031 force_automatic_it_block_close ();
5ee91343 23032 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
23033 new_automatic_it_block (inst.cond);
23034 }
23035 else
23036 {
5ee91343
AV
23037 now_pred.insn_cond = TRUE;
23038 now_pred_add_mask (inst.cond);
e07e6e58
NC
23039 }
23040
5ee91343
AV
23041 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23042 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23043 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
23044 close_automatic_it_block ();
23045 break;
23046
4934a27c
MM
23047 case NEUTRAL_IT_NO_VPT_INSN:
23048 if (now_pred.type == VECTOR_PRED)
23049 {
23050 inst.error = BAD_NO_VPT;
23051 break;
23052 }
23053 /* Fallthrough. */
e07e6e58 23054 case NEUTRAL_IT_INSN:
5ee91343
AV
23055 now_pred.block_length++;
23056 now_pred.insn_cond = TRUE;
e07e6e58 23057
5ee91343 23058 if (now_pred.block_length > 4)
e07e6e58
NC
23059 force_automatic_it_block_close ();
23060 else
5ee91343 23061 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
23062 break;
23063
23064 case IT_INSN:
23065 close_automatic_it_block ();
5ee91343 23066 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
23067 break;
23068 }
23069 break;
23070
5ee91343 23071 case MANUAL_PRED_BLOCK:
e07e6e58 23072 {
5ee91343
AV
23073 int cond, is_last;
23074 if (now_pred.type == SCALAR_PRED)
e07e6e58 23075 {
5ee91343
AV
23076 /* Check conditional suffixes. */
23077 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23078 now_pred.mask <<= 1;
23079 now_pred.mask &= 0x1f;
23080 is_last = (now_pred.mask == 0x10);
23081 }
23082 else
23083 {
23084 now_pred.cc ^= (now_pred.mask >> 4);
23085 cond = now_pred.cc + 0xf;
23086 now_pred.mask <<= 1;
23087 now_pred.mask &= 0x1f;
23088 is_last = now_pred.mask == 0x10;
23089 }
23090 now_pred.insn_cond = TRUE;
e07e6e58 23091
5ee91343
AV
23092 switch (inst.pred_insn_type)
23093 {
23094 case OUTSIDE_PRED_INSN:
23095 if (now_pred.type == SCALAR_PRED)
23096 {
23097 if (inst.cond == COND_ALWAYS)
23098 {
23099 /* Case 12: In an IT block, with no code: error: missing
23100 code. */
23101 inst.error = BAD_NOT_IT;
23102 return FAIL;
23103 }
23104 else if (inst.cond > COND_ALWAYS)
23105 {
23106 /* Case 11: In an IT block, with a VPT code: syntax error.
23107 */
23108 inst.error = BAD_SYNTAX;
23109 return FAIL;
23110 }
23111 else if (thumb_mode)
23112 {
23113 /* This is for some special cases where a non-MVE
23114 instruction is not allowed in an IT block, such as cbz,
23115 but are put into one with a condition code.
23116 You could argue this should be a syntax error, but we
23117 gave the 'not allowed in IT block' diagnostic in the
23118 past so we will keep doing so. */
23119 inst.error = BAD_NOT_IT;
23120 return FAIL;
23121 }
23122 break;
23123 }
23124 else
23125 {
23126 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23127 as_tsktsk (MVE_NOT_VPT);
23128 return SUCCESS;
23129 }
23130 case MVE_OUTSIDE_PRED_INSN:
23131 if (now_pred.type == SCALAR_PRED)
23132 {
23133 if (inst.cond == COND_ALWAYS)
23134 {
23135 /* Case 3: In an IT block, with no code: warning:
23136 UNPREDICTABLE. */
23137 as_tsktsk (MVE_NOT_IT);
23138 return SUCCESS;
23139 }
23140 else if (inst.cond < COND_ALWAYS)
23141 {
23142 /* Case 1: In an IT block, with an IT code: syntax error.
23143 */
23144 inst.error = BAD_SYNTAX;
23145 return FAIL;
23146 }
23147 else
23148 gas_assert (0);
23149 }
23150 else
23151 {
23152 if (inst.cond < COND_ALWAYS)
23153 {
23154 /* Case 4: In a VPT block, with an IT code: syntax error.
23155 */
23156 inst.error = BAD_SYNTAX;
23157 return FAIL;
23158 }
23159 else if (inst.cond == COND_ALWAYS)
23160 {
23161 /* Case 6: In a VPT block, with no code: error: missing
23162 code. */
23163 inst.error = BAD_NOT_VPT;
23164 return FAIL;
23165 }
23166 else
23167 {
23168 gas_assert (0);
23169 }
23170 }
35c228db
AV
23171 case MVE_UNPREDICABLE_INSN:
23172 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23173 return SUCCESS;
e07e6e58 23174 case INSIDE_IT_INSN:
5ee91343 23175 if (inst.cond > COND_ALWAYS)
e07e6e58 23176 {
5ee91343
AV
23177 /* Case 11: In an IT block, with a VPT code: syntax error. */
23178 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23179 inst.error = BAD_SYNTAX;
23180 return FAIL;
23181 }
23182 else if (now_pred.type == SCALAR_PRED)
23183 {
23184 /* Case 10: In an IT block, with an IT code: OK! */
23185 if (cond != inst.cond)
23186 {
23187 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23188 BAD_VPT_COND;
23189 return FAIL;
23190 }
23191 }
23192 else
23193 {
23194 /* Case 13: In a VPT block, with an IT code: error: should be
23195 in an IT block. */
23196 inst.error = BAD_OUT_IT;
e07e6e58
NC
23197 return FAIL;
23198 }
23199 break;
23200
5ee91343
AV
23201 case INSIDE_VPT_INSN:
23202 if (now_pred.type == SCALAR_PRED)
23203 {
23204 /* Case 2: In an IT block, with a VPT code: error: must be in a
23205 VPT block. */
23206 inst.error = BAD_OUT_VPT;
23207 return FAIL;
23208 }
23209 /* Case 5: In a VPT block, with a VPT code: OK! */
23210 else if (cond != inst.cond)
23211 {
23212 inst.error = BAD_VPT_COND;
23213 return FAIL;
23214 }
23215 break;
e07e6e58
NC
23216 case INSIDE_IT_LAST_INSN:
23217 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
23218 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23219 {
23220 /* Case 4: In a VPT block, with an IT code: syntax error. */
23221 /* Case 11: In an IT block, with a VPT code: syntax error. */
23222 inst.error = BAD_SYNTAX;
23223 return FAIL;
23224 }
23225 else if (cond != inst.cond)
e07e6e58
NC
23226 {
23227 inst.error = BAD_IT_COND;
23228 return FAIL;
23229 }
23230 if (!is_last)
23231 {
23232 inst.error = BAD_BRANCH;
23233 return FAIL;
23234 }
23235 break;
23236
4934a27c
MM
23237 case NEUTRAL_IT_NO_VPT_INSN:
23238 if (now_pred.type == VECTOR_PRED)
23239 {
23240 inst.error = BAD_NO_VPT;
23241 break;
23242 }
23243 /* Fallthrough. */
e07e6e58 23244 case NEUTRAL_IT_INSN:
5ee91343
AV
23245 /* The BKPT instruction is unconditional even in a IT or VPT
23246 block. */
e07e6e58
NC
23247 break;
23248
23249 case IT_INSN:
5ee91343
AV
23250 if (now_pred.type == SCALAR_PRED)
23251 {
23252 inst.error = BAD_IT_IT;
23253 return FAIL;
23254 }
23255 /* fall through. */
23256 case VPT_INSN:
23257 if (inst.cond == COND_ALWAYS)
23258 {
23259 /* Executing a VPT/VPST instruction inside an IT block or a
23260 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23261 */
23262 if (now_pred.type == SCALAR_PRED)
23263 as_tsktsk (MVE_NOT_IT);
23264 else
23265 as_tsktsk (MVE_NOT_VPT);
23266 return SUCCESS;
23267 }
23268 else
23269 {
23270 /* VPT/VPST do not accept condition codes. */
23271 inst.error = BAD_SYNTAX;
23272 return FAIL;
23273 }
e07e6e58 23274 }
5ee91343 23275 }
e07e6e58
NC
23276 break;
23277 }
23278
23279 return SUCCESS;
23280}
23281
5a01bb1d
MGD
23282struct depr_insn_mask
23283{
23284 unsigned long pattern;
23285 unsigned long mask;
23286 const char* description;
23287};
23288
23289/* List of 16-bit instruction patterns deprecated in an IT block in
23290 ARMv8. */
23291static const struct depr_insn_mask depr_it_insns[] = {
23292 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23293 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23294 { 0xa000, 0xb800, N_("ADR") },
23295 { 0x4800, 0xf800, N_("Literal loads") },
23296 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23297 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
23298 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23299 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23300 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
23301 { 0, 0, NULL }
23302};
23303
e07e6e58
NC
23304static void
23305it_fsm_post_encode (void)
23306{
23307 int is_last;
23308
5ee91343
AV
23309 if (!now_pred.state_handled)
23310 handle_pred_state ();
e07e6e58 23311
5ee91343 23312 if (now_pred.insn_cond
24f19ccb 23313 && warn_on_restrict_it
5ee91343 23314 && !now_pred.warn_deprecated
5a01bb1d 23315 && warn_on_deprecated
df9909b8
TP
23316 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23317 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
23318 {
23319 if (inst.instruction >= 0x10000)
23320 {
5c3696f8 23321 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 23322 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 23323 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23324 }
23325 else
23326 {
23327 const struct depr_insn_mask *p = depr_it_insns;
23328
23329 while (p->mask != 0)
23330 {
23331 if ((inst.instruction & p->mask) == p->pattern)
23332 {
df9909b8
TP
23333 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23334 "instructions of the following class are "
23335 "performance deprecated in ARMv8-A and "
23336 "ARMv8-R: %s"), p->description);
5ee91343 23337 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23338 break;
23339 }
23340
23341 ++p;
23342 }
23343 }
23344
5ee91343 23345 if (now_pred.block_length > 1)
5a01bb1d 23346 {
5c3696f8 23347 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
23348 "instruction are performance deprecated in ARMv8-A and "
23349 "ARMv8-R"));
5ee91343 23350 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23351 }
23352 }
23353
5ee91343
AV
23354 is_last = (now_pred.mask == 0x10);
23355 if (is_last)
23356 {
23357 now_pred.state = OUTSIDE_PRED_BLOCK;
23358 now_pred.mask = 0;
23359 }
e07e6e58
NC
23360}
23361
23362static void
23363force_automatic_it_block_close (void)
23364{
5ee91343 23365 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
23366 {
23367 close_automatic_it_block ();
5ee91343
AV
23368 now_pred.state = OUTSIDE_PRED_BLOCK;
23369 now_pred.mask = 0;
e07e6e58
NC
23370 }
23371}
23372
23373static int
5ee91343 23374in_pred_block (void)
e07e6e58 23375{
5ee91343
AV
23376 if (!now_pred.state_handled)
23377 handle_pred_state ();
e07e6e58 23378
5ee91343 23379 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
23380}
23381
ff8646ee
TP
23382/* Whether OPCODE only has T32 encoding. Since this function is only used by
23383 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23384 here, hence the "known" in the function name. */
fc289b0a
TP
23385
23386static bfd_boolean
ff8646ee 23387known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
23388{
23389 /* Original Thumb-1 wide instruction. */
23390 if (opcode->tencode == do_t_blx
23391 || opcode->tencode == do_t_branch23
23392 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23393 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23394 return TRUE;
23395
16a1fa25
TP
23396 /* Wide-only instruction added to ARMv8-M Baseline. */
23397 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
23398 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23399 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23400 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23401 return TRUE;
23402
23403 return FALSE;
23404}
23405
23406/* Whether wide instruction variant can be used if available for a valid OPCODE
23407 in ARCH. */
23408
23409static bfd_boolean
23410t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23411{
23412 if (known_t32_only_insn (opcode))
23413 return TRUE;
23414
23415 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23416 of variant T3 of B.W is checked in do_t_branch. */
23417 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23418 && opcode->tencode == do_t_branch)
23419 return TRUE;
23420
bada4342
JW
23421 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23422 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23423 && opcode->tencode == do_t_mov_cmp
23424 /* Make sure CMP instruction is not affected. */
23425 && opcode->aencode == do_mov)
23426 return TRUE;
23427
ff8646ee
TP
23428 /* Wide instruction variants of all instructions with narrow *and* wide
23429 variants become available with ARMv6t2. Other opcodes are either
23430 narrow-only or wide-only and are thus available if OPCODE is valid. */
23431 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23432 return TRUE;
23433
23434 /* OPCODE with narrow only instruction variant or wide variant not
23435 available. */
fc289b0a
TP
23436 return FALSE;
23437}
23438
c19d1205
ZW
23439void
23440md_assemble (char *str)
b99bd4ef 23441{
c19d1205
ZW
23442 char *p = str;
23443 const struct asm_opcode * opcode;
b99bd4ef 23444
c19d1205
ZW
23445 /* Align the previous label if needed. */
23446 if (last_label_seen != NULL)
b99bd4ef 23447 {
c19d1205
ZW
23448 symbol_set_frag (last_label_seen, frag_now);
23449 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23450 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
23451 }
23452
c19d1205 23453 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
23454 int r;
23455 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23456 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 23457
c19d1205
ZW
23458 opcode = opcode_lookup (&p);
23459 if (!opcode)
b99bd4ef 23460 {
c19d1205 23461 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 23462 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 23463 if (! create_register_alias (str, p)
477330fc 23464 && ! create_neon_reg_alias (str, p))
c19d1205 23465 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 23466
b99bd4ef
NC
23467 return;
23468 }
23469
278df34e 23470 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 23471 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 23472
037e8744
JB
23473 /* The value which unconditional instructions should have in place of the
23474 condition field. */
23475 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
23476
c19d1205 23477 if (thumb_mode)
b99bd4ef 23478 {
e74cfd16 23479 arm_feature_set variant;
8f06b2d8
PB
23480
23481 variant = cpu_variant;
23482 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
23483 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23484 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 23485 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
23486 if (!opcode->tvariant
23487 || (thumb_mode == 1
23488 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 23489 {
173205ca
TP
23490 if (opcode->tencode == do_t_swi)
23491 as_bad (_("SVC is not permitted on this architecture"));
23492 else
23493 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
23494 return;
23495 }
c19d1205
ZW
23496 if (inst.cond != COND_ALWAYS && !unified_syntax
23497 && opcode->tencode != do_t_branch)
b99bd4ef 23498 {
c19d1205 23499 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
23500 return;
23501 }
23502
fc289b0a
TP
23503 /* Two things are addressed here:
23504 1) Implicit require narrow instructions on Thumb-1.
23505 This avoids relaxation accidentally introducing Thumb-2
23506 instructions.
23507 2) Reject wide instructions in non Thumb-2 cores.
23508
23509 Only instructions with narrow and wide variants need to be handled
23510 but selecting all non wide-only instructions is easier. */
23511 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 23512 && !t32_insn_ok (variant, opcode))
076d447c 23513 {
fc289b0a
TP
23514 if (inst.size_req == 0)
23515 inst.size_req = 2;
23516 else if (inst.size_req == 4)
752d5da4 23517 {
ff8646ee
TP
23518 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23519 as_bad (_("selected processor does not support 32bit wide "
23520 "variant of instruction `%s'"), str);
23521 else
23522 as_bad (_("selected processor does not support `%s' in "
23523 "Thumb-2 mode"), str);
fc289b0a 23524 return;
752d5da4 23525 }
076d447c
PB
23526 }
23527
c19d1205
ZW
23528 inst.instruction = opcode->tvalue;
23529
5be8be5d 23530 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 23531 {
5ee91343 23532 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
23533 it. */
23534 it_fsm_pre_encode ();
c19d1205 23535
477330fc 23536 opcode->tencode ();
e07e6e58 23537
477330fc
RM
23538 it_fsm_post_encode ();
23539 }
e27ec89e 23540
0110f2b8 23541 if (!(inst.error || inst.relax))
b99bd4ef 23542 {
9c2799c2 23543 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
23544 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23545 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 23546 {
c19d1205 23547 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
23548 return;
23549 }
23550 }
076d447c
PB
23551
23552 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 23553 instruction. */
9c2799c2 23554 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 23555
e74cfd16
PB
23556 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23557 *opcode->tvariant);
ee065d83 23558 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
23559 set those bits when Thumb-2 32-bit instructions are seen. The impact
23560 of relaxable instructions will be considered later after we finish all
23561 relaxation. */
ff8646ee
TP
23562 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23563 variant = arm_arch_none;
23564 else
23565 variant = cpu_variant;
23566 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
23567 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23568 arm_ext_v6t2);
cd000bff 23569
88714cb8
DG
23570 check_neon_suffixes;
23571
cd000bff 23572 if (!inst.error)
c877a2f2
NC
23573 {
23574 mapping_state (MAP_THUMB);
23575 }
c19d1205 23576 }
3e9e4fcf 23577 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 23578 {
845b51d6
PB
23579 bfd_boolean is_bx;
23580
23581 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23582 is_bx = (opcode->aencode == do_bx);
23583
c19d1205 23584 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
23585 if (!(is_bx && fix_v4bx)
23586 && !(opcode->avariant &&
23587 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 23588 {
84b52b66 23589 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 23590 return;
b99bd4ef 23591 }
c19d1205 23592 if (inst.size_req)
b99bd4ef 23593 {
c19d1205
ZW
23594 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23595 return;
b99bd4ef
NC
23596 }
23597
c19d1205
ZW
23598 inst.instruction = opcode->avalue;
23599 if (opcode->tag == OT_unconditionalF)
eff0bc54 23600 inst.instruction |= 0xFU << 28;
c19d1205
ZW
23601 else
23602 inst.instruction |= inst.cond << 28;
23603 inst.size = INSN_SIZE;
5be8be5d 23604 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
23605 {
23606 it_fsm_pre_encode ();
23607 opcode->aencode ();
23608 it_fsm_post_encode ();
23609 }
ee065d83 23610 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 23611 on a hypothetical non-thumb v5 core. */
845b51d6 23612 if (is_bx)
e74cfd16 23613 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 23614 else
e74cfd16
PB
23615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23616 *opcode->avariant);
88714cb8
DG
23617
23618 check_neon_suffixes;
23619
cd000bff 23620 if (!inst.error)
c877a2f2
NC
23621 {
23622 mapping_state (MAP_ARM);
23623 }
b99bd4ef 23624 }
3e9e4fcf
JB
23625 else
23626 {
23627 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23628 "-- `%s'"), str);
23629 return;
23630 }
c19d1205
ZW
23631 output_inst (str);
23632}
b99bd4ef 23633
e07e6e58 23634static void
5ee91343 23635check_pred_blocks_finished (void)
e07e6e58
NC
23636{
23637#ifdef OBJ_ELF
23638 asection *sect;
23639
23640 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
23641 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23642 == MANUAL_PRED_BLOCK)
e07e6e58 23643 {
5ee91343
AV
23644 if (now_pred.type == SCALAR_PRED)
23645 as_warn (_("section '%s' finished with an open IT block."),
23646 sect->name);
23647 else
23648 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23649 sect->name);
e07e6e58
NC
23650 }
23651#else
5ee91343
AV
23652 if (now_pred.state == MANUAL_PRED_BLOCK)
23653 {
23654 if (now_pred.type == SCALAR_PRED)
23655 as_warn (_("file finished with an open IT block."));
23656 else
23657 as_warn (_("file finished with an open VPT/VPST block."));
23658 }
e07e6e58
NC
23659#endif
23660}
23661
c19d1205
ZW
23662/* Various frobbings of labels and their addresses. */
23663
23664void
23665arm_start_line_hook (void)
23666{
23667 last_label_seen = NULL;
b99bd4ef
NC
23668}
23669
c19d1205
ZW
23670void
23671arm_frob_label (symbolS * sym)
b99bd4ef 23672{
c19d1205 23673 last_label_seen = sym;
b99bd4ef 23674
c19d1205 23675 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 23676
c19d1205
ZW
23677#if defined OBJ_COFF || defined OBJ_ELF
23678 ARM_SET_INTERWORK (sym, support_interwork);
23679#endif
b99bd4ef 23680
e07e6e58
NC
23681 force_automatic_it_block_close ();
23682
5f4273c7 23683 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
23684 as Thumb functions. This is because these labels, whilst
23685 they exist inside Thumb code, are not the entry points for
23686 possible ARM->Thumb calls. Also, these labels can be used
23687 as part of a computed goto or switch statement. eg gcc
23688 can generate code that looks like this:
b99bd4ef 23689
c19d1205
ZW
23690 ldr r2, [pc, .Laaa]
23691 lsl r3, r3, #2
23692 ldr r2, [r3, r2]
23693 mov pc, r2
b99bd4ef 23694
c19d1205
ZW
23695 .Lbbb: .word .Lxxx
23696 .Lccc: .word .Lyyy
23697 ..etc...
23698 .Laaa: .word Lbbb
b99bd4ef 23699
c19d1205
ZW
23700 The first instruction loads the address of the jump table.
23701 The second instruction converts a table index into a byte offset.
23702 The third instruction gets the jump address out of the table.
23703 The fourth instruction performs the jump.
b99bd4ef 23704
c19d1205
ZW
23705 If the address stored at .Laaa is that of a symbol which has the
23706 Thumb_Func bit set, then the linker will arrange for this address
23707 to have the bottom bit set, which in turn would mean that the
23708 address computation performed by the third instruction would end
23709 up with the bottom bit set. Since the ARM is capable of unaligned
23710 word loads, the instruction would then load the incorrect address
23711 out of the jump table, and chaos would ensue. */
23712 if (label_is_thumb_function_name
23713 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
fd361982 23714 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
b99bd4ef 23715 {
c19d1205
ZW
23716 /* When the address of a Thumb function is taken the bottom
23717 bit of that address should be set. This will allow
23718 interworking between Arm and Thumb functions to work
23719 correctly. */
b99bd4ef 23720
c19d1205 23721 THUMB_SET_FUNC (sym, 1);
b99bd4ef 23722
c19d1205 23723 label_is_thumb_function_name = FALSE;
b99bd4ef 23724 }
07a53e5c 23725
07a53e5c 23726 dwarf2_emit_label (sym);
b99bd4ef
NC
23727}
23728
c921be7d 23729bfd_boolean
c19d1205 23730arm_data_in_code (void)
b99bd4ef 23731{
c19d1205 23732 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 23733 {
c19d1205
ZW
23734 *input_line_pointer = '/';
23735 input_line_pointer += 5;
23736 *input_line_pointer = 0;
c921be7d 23737 return TRUE;
b99bd4ef
NC
23738 }
23739
c921be7d 23740 return FALSE;
b99bd4ef
NC
23741}
23742
c19d1205
ZW
23743char *
23744arm_canonicalize_symbol_name (char * name)
b99bd4ef 23745{
c19d1205 23746 int len;
b99bd4ef 23747
c19d1205
ZW
23748 if (thumb_mode && (len = strlen (name)) > 5
23749 && streq (name + len - 5, "/data"))
23750 *(name + len - 5) = 0;
b99bd4ef 23751
c19d1205 23752 return name;
b99bd4ef 23753}
c19d1205
ZW
23754\f
23755/* Table of all register names defined by default. The user can
23756 define additional names with .req. Note that all register names
23757 should appear in both upper and lowercase variants. Some registers
23758 also have mixed-case names. */
b99bd4ef 23759
dcbf9037 23760#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 23761#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 23762#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
23763#define REGSET(p,t) \
23764 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23765 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23766 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23767 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
23768#define REGSETH(p,t) \
23769 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23770 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23771 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23772 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23773#define REGSET2(p,t) \
23774 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23775 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23776 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23777 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
23778#define SPLRBANK(base,bank,t) \
23779 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23780 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23781 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23782 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23783 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23784 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 23785
c19d1205 23786static const struct reg_entry reg_names[] =
7ed4c4c5 23787{
c19d1205
ZW
23788 /* ARM integer registers. */
23789 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 23790
c19d1205
ZW
23791 /* ATPCS synonyms. */
23792 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23793 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23794 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 23795
c19d1205
ZW
23796 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23797 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23798 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 23799
c19d1205
ZW
23800 /* Well-known aliases. */
23801 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23802 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23803
23804 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23805 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23806
1b883319
AV
23807 /* Defining the new Zero register from ARMv8.1-M. */
23808 REGDEF(zr,15,ZR),
23809 REGDEF(ZR,15,ZR),
23810
c19d1205
ZW
23811 /* Coprocessor numbers. */
23812 REGSET(p, CP), REGSET(P, CP),
23813
23814 /* Coprocessor register numbers. The "cr" variants are for backward
23815 compatibility. */
23816 REGSET(c, CN), REGSET(C, CN),
23817 REGSET(cr, CN), REGSET(CR, CN),
23818
90ec0d68
MGD
23819 /* ARM banked registers. */
23820 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23821 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23822 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23823 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23824 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23825 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23826 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23827
23828 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23829 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23830 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23831 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23832 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 23833 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
23834 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23835 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23836
23837 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23838 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23839 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23840 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23841 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23842 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23843 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 23844 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
23845 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23846
c19d1205
ZW
23847 /* FPA registers. */
23848 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23849 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23850
23851 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23852 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23853
23854 /* VFP SP registers. */
5287ad62
JB
23855 REGSET(s,VFS), REGSET(S,VFS),
23856 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
23857
23858 /* VFP DP Registers. */
5287ad62
JB
23859 REGSET(d,VFD), REGSET(D,VFD),
23860 /* Extra Neon DP registers. */
23861 REGSETH(d,VFD), REGSETH(D,VFD),
23862
23863 /* Neon QP registers. */
23864 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
23865
23866 /* VFP control registers. */
23867 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23868 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
23869 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23870 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23871 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23872 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 23873 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
23874 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23875 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23876 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23877 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
23878
23879 /* Maverick DSP coprocessor registers. */
23880 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23881 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23882
23883 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23884 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23885 REGDEF(dspsc,0,DSPSC),
23886
23887 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23888 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23889 REGDEF(DSPSC,0,DSPSC),
23890
23891 /* iWMMXt data registers - p0, c0-15. */
23892 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23893
23894 /* iWMMXt control registers - p1, c0-3. */
23895 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23896 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23897 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23898 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23899
23900 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23901 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23902 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23903 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23904 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23905
23906 /* XScale accumulator registers. */
23907 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23908};
23909#undef REGDEF
23910#undef REGNUM
23911#undef REGSET
7ed4c4c5 23912
c19d1205
ZW
23913/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23914 within psr_required_here. */
23915static const struct asm_psr psrs[] =
23916{
23917 /* Backward compatibility notation. Note that "all" is no longer
23918 truly all possible PSR bits. */
23919 {"all", PSR_c | PSR_f},
23920 {"flg", PSR_f},
23921 {"ctl", PSR_c},
23922
23923 /* Individual flags. */
23924 {"f", PSR_f},
23925 {"c", PSR_c},
23926 {"x", PSR_x},
23927 {"s", PSR_s},
59b42a0d 23928
c19d1205
ZW
23929 /* Combinations of flags. */
23930 {"fs", PSR_f | PSR_s},
23931 {"fx", PSR_f | PSR_x},
23932 {"fc", PSR_f | PSR_c},
23933 {"sf", PSR_s | PSR_f},
23934 {"sx", PSR_s | PSR_x},
23935 {"sc", PSR_s | PSR_c},
23936 {"xf", PSR_x | PSR_f},
23937 {"xs", PSR_x | PSR_s},
23938 {"xc", PSR_x | PSR_c},
23939 {"cf", PSR_c | PSR_f},
23940 {"cs", PSR_c | PSR_s},
23941 {"cx", PSR_c | PSR_x},
23942 {"fsx", PSR_f | PSR_s | PSR_x},
23943 {"fsc", PSR_f | PSR_s | PSR_c},
23944 {"fxs", PSR_f | PSR_x | PSR_s},
23945 {"fxc", PSR_f | PSR_x | PSR_c},
23946 {"fcs", PSR_f | PSR_c | PSR_s},
23947 {"fcx", PSR_f | PSR_c | PSR_x},
23948 {"sfx", PSR_s | PSR_f | PSR_x},
23949 {"sfc", PSR_s | PSR_f | PSR_c},
23950 {"sxf", PSR_s | PSR_x | PSR_f},
23951 {"sxc", PSR_s | PSR_x | PSR_c},
23952 {"scf", PSR_s | PSR_c | PSR_f},
23953 {"scx", PSR_s | PSR_c | PSR_x},
23954 {"xfs", PSR_x | PSR_f | PSR_s},
23955 {"xfc", PSR_x | PSR_f | PSR_c},
23956 {"xsf", PSR_x | PSR_s | PSR_f},
23957 {"xsc", PSR_x | PSR_s | PSR_c},
23958 {"xcf", PSR_x | PSR_c | PSR_f},
23959 {"xcs", PSR_x | PSR_c | PSR_s},
23960 {"cfs", PSR_c | PSR_f | PSR_s},
23961 {"cfx", PSR_c | PSR_f | PSR_x},
23962 {"csf", PSR_c | PSR_s | PSR_f},
23963 {"csx", PSR_c | PSR_s | PSR_x},
23964 {"cxf", PSR_c | PSR_x | PSR_f},
23965 {"cxs", PSR_c | PSR_x | PSR_s},
23966 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23967 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23968 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23969 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23970 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23971 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23972 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23973 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23974 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23975 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23976 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23977 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23978 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23979 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23980 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23981 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23982 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23983 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23984 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23985 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23986 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23987 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23988 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23989 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23990};
23991
62b3e311
PB
23992/* Table of V7M psr names. */
23993static const struct asm_psr v7m_psrs[] =
23994{
1a336194
TP
23995 {"apsr", 0x0 }, {"APSR", 0x0 },
23996 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23997 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23998 {"psr", 0x3 }, {"PSR", 0x3 },
23999 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
24000 {"ipsr", 0x5 }, {"IPSR", 0x5 },
24001 {"epsr", 0x6 }, {"EPSR", 0x6 },
24002 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
24003 {"msp", 0x8 }, {"MSP", 0x8 },
24004 {"psp", 0x9 }, {"PSP", 0x9 },
24005 {"msplim", 0xa }, {"MSPLIM", 0xa },
24006 {"psplim", 0xb }, {"PSPLIM", 0xb },
24007 {"primask", 0x10}, {"PRIMASK", 0x10},
24008 {"basepri", 0x11}, {"BASEPRI", 0x11},
24009 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
24010 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24011 {"control", 0x14}, {"CONTROL", 0x14},
24012 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24013 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24014 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24015 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24016 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24017 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24018 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24019 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24020 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
24021};
24022
c19d1205
ZW
24023/* Table of all shift-in-operand names. */
24024static const struct asm_shift_name shift_names [] =
b99bd4ef 24025{
c19d1205
ZW
24026 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24027 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24028 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24029 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24030 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
24031 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24032 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 24033};
b99bd4ef 24034
c19d1205
ZW
24035/* Table of all explicit relocation names. */
24036#ifdef OBJ_ELF
24037static struct reloc_entry reloc_names[] =
24038{
24039 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24040 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24041 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24042 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24043 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24044 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24045 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24046 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24047 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24048 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 24049 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
24050 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24051 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 24052 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 24053 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 24054 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 24055 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
24056 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24057 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24058 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24059 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24060 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24061 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
24062 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24063 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24064 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24065 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
24066};
24067#endif
b99bd4ef 24068
5ee91343 24069/* Table of all conditional affixes. */
c19d1205
ZW
24070static const struct asm_cond conds[] =
24071{
24072 {"eq", 0x0},
24073 {"ne", 0x1},
24074 {"cs", 0x2}, {"hs", 0x2},
24075 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24076 {"mi", 0x4},
24077 {"pl", 0x5},
24078 {"vs", 0x6},
24079 {"vc", 0x7},
24080 {"hi", 0x8},
24081 {"ls", 0x9},
24082 {"ge", 0xa},
24083 {"lt", 0xb},
24084 {"gt", 0xc},
24085 {"le", 0xd},
24086 {"al", 0xe}
24087};
5ee91343
AV
24088static const struct asm_cond vconds[] =
24089{
24090 {"t", 0xf},
24091 {"e", 0x10}
24092};
bfae80f2 24093
e797f7e0 24094#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
24095 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24096 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 24097
62b3e311
PB
24098static struct asm_barrier_opt barrier_opt_names[] =
24099{
e797f7e0
MGD
24100 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24101 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24102 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24103 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24104 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24105 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24106 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24107 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24108 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24109 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24110 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24111 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24112 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24113 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24114 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24115 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
24116};
24117
e797f7e0
MGD
24118#undef UL_BARRIER
24119
c19d1205
ZW
24120/* Table of ARM-format instructions. */
24121
24122/* Macros for gluing together operand strings. N.B. In all cases
24123 other than OPS0, the trailing OP_stop comes from default
24124 zero-initialization of the unspecified elements of the array. */
24125#define OPS0() { OP_stop, }
24126#define OPS1(a) { OP_##a, }
24127#define OPS2(a,b) { OP_##a,OP_##b, }
24128#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24129#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24130#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24131#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24132
5be8be5d
DG
24133/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24134 This is useful when mixing operands for ARM and THUMB, i.e. using the
24135 MIX_ARM_THUMB_OPERANDS macro.
24136 In order to use these macros, prefix the number of operands with _
24137 e.g. _3. */
24138#define OPS_1(a) { a, }
24139#define OPS_2(a,b) { a,b, }
24140#define OPS_3(a,b,c) { a,b,c, }
24141#define OPS_4(a,b,c,d) { a,b,c,d, }
24142#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24143#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24144
c19d1205
ZW
24145/* These macros abstract out the exact format of the mnemonic table and
24146 save some repeated characters. */
24147
24148/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24149#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24150 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 24151 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24152
24153/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24154 a T_MNEM_xyz enumerator. */
24155#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24156 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24157#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24158 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
24159
24160/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24161 infix after the third character. */
24162#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 24163 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 24164 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 24165#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 24166 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 24167 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24168#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24169 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 24170#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24171 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24172#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24173 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 24174#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24175 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 24176
c19d1205 24177/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
24178 field is still 0xE. Many of the Thumb variants can be executed
24179 conditionally, so this is checked separately. */
c19d1205 24180#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24181 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24182 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24183
dd5181d5
KT
24184/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24185 Used by mnemonics that have very minimal differences in the encoding for
24186 ARM and Thumb variants and can be handled in a common function. */
24187#define TUEc(mnem, op, top, nops, ops, en) \
24188 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24189 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 24190
c19d1205
ZW
24191/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24192 condition code field. */
24193#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 24194 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24195 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24196
24197/* ARM-only variants of all the above. */
6a86118a 24198#define CE(mnem, op, nops, ops, ae) \
5ee91343 24199 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24200
24201#define C3(mnem, op, nops, ops, ae) \
5ee91343 24202 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24203
cf3cf39d
TP
24204/* Thumb-only variants of TCE and TUE. */
24205#define ToC(mnem, top, nops, ops, te) \
24206 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24207 do_##te, 0 }
cf3cf39d
TP
24208
24209#define ToU(mnem, top, nops, ops, te) \
24210 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 24211 NULL, do_##te, 0 }
cf3cf39d 24212
4389b29a
AV
24213/* T_MNEM_xyz enumerator variants of ToC. */
24214#define toC(mnem, top, nops, ops, te) \
24215 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24216 do_##te, 0 }
4389b29a 24217
f6b2b12d
AV
24218/* T_MNEM_xyz enumerator variants of ToU. */
24219#define toU(mnem, top, nops, ops, te) \
24220 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 24221 NULL, do_##te, 0 }
f6b2b12d 24222
e3cb604e
PB
24223/* Legacy mnemonics that always have conditional infix after the third
24224 character. */
24225#define CL(mnem, op, nops, ops, ae) \
21d799b5 24226 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24227 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 24228
8f06b2d8
PB
24229/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24230#define cCE(mnem, op, nops, ops, ae) \
5ee91343 24231 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24232
57785aa2
AV
24233/* mov instructions that are shared between coprocessor and MVE. */
24234#define mcCE(mnem, op, nops, ops, ae) \
24235 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24236
e3cb604e
PB
24237/* Legacy coprocessor instructions where conditional infix and conditional
24238 suffix are ambiguous. For consistency this includes all FPA instructions,
24239 not just the potentially ambiguous ones. */
24240#define cCL(mnem, op, nops, ops, ae) \
21d799b5 24241 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24242 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
24243
24244/* Coprocessor, takes either a suffix or a position-3 infix
24245 (for an FPA corner case). */
24246#define C3E(mnem, op, nops, ops, ae) \
21d799b5 24247 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 24248 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24249
6a86118a 24250#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
24251 { m1 #m2 m3, OPS##nops ops, \
24252 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 24253 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24254
24255#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
24256 xCM_ (m1, , m2, op, nops, ops, ae), \
24257 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24258 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24259 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24260 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24261 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24262 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24263 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24264 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24265 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24266 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24267 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24268 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24269 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24270 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24271 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24272 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24273 xCM_ (m1, le, m2, op, nops, ops, ae), \
24274 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
24275
24276#define UE(mnem, op, nops, ops, ae) \
5ee91343 24277 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24278
24279#define UF(mnem, op, nops, ops, ae) \
5ee91343 24280 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24281
5287ad62
JB
24282/* Neon data-processing. ARM versions are unconditional with cond=0xf.
24283 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24284 use the same encoding function for each. */
24285#define NUF(mnem, op, nops, ops, enc) \
24286 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 24287 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24288
24289/* Neon data processing, version which indirects through neon_enc_tab for
24290 the various overloaded versions of opcodes. */
24291#define nUF(mnem, op, nops, ops, enc) \
21d799b5 24292 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 24293 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24294
24295/* Neon insn with conditional suffix for the ARM version, non-overloaded
24296 version. */
5ee91343 24297#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 24298 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 24299 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24300
037e8744 24301#define NCE(mnem, op, nops, ops, enc) \
5ee91343 24302 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24303
24304#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 24305 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 24306
5287ad62 24307/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 24308#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 24309 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 24310 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24311
037e8744 24312#define nCE(mnem, op, nops, ops, enc) \
5ee91343 24313 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24314
24315#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
24316 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24317
24318/* */
24319#define mCEF(mnem, op, nops, ops, enc) \
a302e574 24320 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
24321 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24322
24323
24324/* nCEF but for MVE predicated instructions. */
24325#define mnCEF(mnem, op, nops, ops, enc) \
24326 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24327
24328/* nCE but for MVE predicated instructions. */
24329#define mnCE(mnem, op, nops, ops, enc) \
24330 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 24331
5ee91343
AV
24332/* NUF but for potentially MVE predicated instructions. */
24333#define MNUF(mnem, op, nops, ops, enc) \
24334 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24335 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24336
24337/* nUF but for potentially MVE predicated instructions. */
24338#define mnUF(mnem, op, nops, ops, enc) \
24339 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24340 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24341
24342/* ToC but for potentially MVE predicated instructions. */
24343#define mToC(mnem, top, nops, ops, te) \
24344 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24345 do_##te, 1 }
24346
24347/* NCE but for MVE predicated instructions. */
24348#define MNCE(mnem, op, nops, ops, enc) \
24349 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24350
24351/* NCEF but for MVE predicated instructions. */
24352#define MNCEF(mnem, op, nops, ops, enc) \
24353 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
24354#define do_0 0
24355
c19d1205 24356static const struct asm_opcode insns[] =
bfae80f2 24357{
74db7efb
NC
24358#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24359#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
24360 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24361 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24362 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24363 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24364 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24365 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24366 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24367 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24368 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24369 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24370 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24371 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24372 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24373 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24374 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24375 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
24376
24377 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24378 for setting PSR flag bits. They are obsolete in V6 and do not
24379 have Thumb equivalents. */
21d799b5
NC
24380 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24381 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24382 CL("tstp", 110f000, 2, (RR, SH), cmp),
24383 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24384 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24385 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24386 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24387 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24388 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24389
24390 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 24391 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
24392 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24393 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24394
24395 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
24396 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24397 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24398 OP_RRnpc),
24399 OP_ADDRGLDR),ldst, t_ldst),
24400 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
24401
24402 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24403 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24404 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24405 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24406 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24407 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24408
21d799b5
NC
24409 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24410 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 24411
c19d1205 24412 /* Pseudo ops. */
21d799b5 24413 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 24414 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 24415 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 24416 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
24417
24418 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
24419 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24420 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24421 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24422 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24423 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24424 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24425 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24426 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24427 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24428 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24429 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24430 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 24431
16a4cf17 24432 /* These may simplify to neg. */
21d799b5
NC
24433 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24434 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 24435
173205ca
TP
24436#undef THUMB_VARIANT
24437#define THUMB_VARIANT & arm_ext_os
24438
24439 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24440 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24441
c921be7d
NC
24442#undef THUMB_VARIANT
24443#define THUMB_VARIANT & arm_ext_v6
24444
21d799b5 24445 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
24446
24447 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
24448#undef THUMB_VARIANT
24449#define THUMB_VARIANT & arm_ext_v6t2
24450
21d799b5
NC
24451 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24452 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24453 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 24454
5be8be5d
DG
24455 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24456 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24457 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24458 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 24459
21d799b5
NC
24460 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24461 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 24462
21d799b5
NC
24463 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24464 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
24465
24466 /* V1 instructions with no Thumb analogue at all. */
21d799b5 24467 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
24468 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24469
24470 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24471 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24472 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24473 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24474 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24475 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24476 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24477 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24478
c921be7d
NC
24479#undef ARM_VARIANT
24480#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24481#undef THUMB_VARIANT
24482#define THUMB_VARIANT & arm_ext_v4t
24483
21d799b5
NC
24484 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24485 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 24486
c921be7d
NC
24487#undef THUMB_VARIANT
24488#define THUMB_VARIANT & arm_ext_v6t2
24489
21d799b5 24490 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
24491 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24492
24493 /* Generic coprocessor instructions. */
21d799b5
NC
24494 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24495 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24496 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24497 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24498 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24499 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 24500 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24501
c921be7d
NC
24502#undef ARM_VARIANT
24503#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24504
21d799b5 24505 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
24506 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24507
c921be7d
NC
24508#undef ARM_VARIANT
24509#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24510#undef THUMB_VARIANT
24511#define THUMB_VARIANT & arm_ext_msr
24512
d2cd1205
JB
24513 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24514 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 24515
c921be7d
NC
24516#undef ARM_VARIANT
24517#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24518#undef THUMB_VARIANT
24519#define THUMB_VARIANT & arm_ext_v6t2
24520
21d799b5
NC
24521 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24522 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24523 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24524 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24525 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24526 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24527 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24528 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 24529
c921be7d
NC
24530#undef ARM_VARIANT
24531#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24532#undef THUMB_VARIANT
24533#define THUMB_VARIANT & arm_ext_v4t
24534
5be8be5d
DG
24535 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24536 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24537 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24538 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
24539 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24540 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 24541
c921be7d
NC
24542#undef ARM_VARIANT
24543#define ARM_VARIANT & arm_ext_v4t_5
24544
c19d1205
ZW
24545 /* ARM Architecture 4T. */
24546 /* Note: bx (and blx) are required on V5, even if the processor does
24547 not support Thumb. */
21d799b5 24548 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 24549
c921be7d
NC
24550#undef ARM_VARIANT
24551#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24552#undef THUMB_VARIANT
24553#define THUMB_VARIANT & arm_ext_v5t
24554
c19d1205
ZW
24555 /* Note: blx has 2 variants; the .value coded here is for
24556 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
24557 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24558 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 24559
c921be7d
NC
24560#undef THUMB_VARIANT
24561#define THUMB_VARIANT & arm_ext_v6t2
24562
21d799b5
NC
24563 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24564 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24565 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24566 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24567 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24568 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24569 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24570 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24571
c921be7d 24572#undef ARM_VARIANT
74db7efb
NC
24573#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24574#undef THUMB_VARIANT
24575#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 24576
21d799b5
NC
24577 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24578 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24579 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24580 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24581
21d799b5
NC
24582 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24583 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24584
21d799b5
NC
24585 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24586 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24587 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24588 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 24589
21d799b5
NC
24590 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24591 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24592 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24593 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24594
21d799b5
NC
24595 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24596 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24597
03ee1b7f
NC
24598 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24599 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24600 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24601 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 24602
c921be7d 24603#undef ARM_VARIANT
74db7efb
NC
24604#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24605#undef THUMB_VARIANT
24606#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24607
21d799b5 24608 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
24609 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24610 ldrd, t_ldstd),
24611 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24612 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 24613
21d799b5
NC
24614 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24615 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 24616
c921be7d
NC
24617#undef ARM_VARIANT
24618#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24619
21d799b5 24620 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 24621
c921be7d
NC
24622#undef ARM_VARIANT
24623#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24624#undef THUMB_VARIANT
24625#define THUMB_VARIANT & arm_ext_v6
24626
21d799b5
NC
24627 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24628 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24629 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24630 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24631 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24632 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24633 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24634 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24635 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24636 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 24637
c921be7d 24638#undef THUMB_VARIANT
ff8646ee 24639#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 24640
5be8be5d
DG
24641 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24642 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24643 strex, t_strex),
ff8646ee
TP
24644#undef THUMB_VARIANT
24645#define THUMB_VARIANT & arm_ext_v6t2
24646
21d799b5
NC
24647 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24648 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 24649
21d799b5
NC
24650 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24651 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 24652
9e3c6df6 24653/* ARM V6 not included in V7M. */
c921be7d
NC
24654#undef THUMB_VARIANT
24655#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 24656 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 24657 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
24658 UF(rfeib, 9900a00, 1, (RRw), rfe),
24659 UF(rfeda, 8100a00, 1, (RRw), rfe),
24660 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24661 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
24662 UF(rfefa, 8100a00, 1, (RRw), rfe),
24663 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24664 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 24665 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
24666 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24667 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 24668 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 24669 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 24670 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 24671 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 24672 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 24673 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 24674 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 24675
9e3c6df6
PB
24676/* ARM V6 not included in V7M (eg. integer SIMD). */
24677#undef THUMB_VARIANT
24678#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
24679 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24680 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24681 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24682 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24683 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24684 /* Old name for QASX. */
74db7efb 24685 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24686 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24687 /* Old name for QSAX. */
74db7efb 24688 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24689 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24690 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24691 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24692 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24693 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24694 /* Old name for SASX. */
74db7efb 24695 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24696 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24697 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24698 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24699 /* Old name for SHASX. */
21d799b5 24700 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24701 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24702 /* Old name for SHSAX. */
21d799b5
NC
24703 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24704 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24705 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24706 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24707 /* Old name for SSAX. */
74db7efb 24708 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24709 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24712 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24713 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24714 /* Old name for UASX. */
74db7efb 24715 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24716 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24717 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24718 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24719 /* Old name for UHASX. */
21d799b5
NC
24720 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24721 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24722 /* Old name for UHSAX. */
21d799b5
NC
24723 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24724 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24726 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24727 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24728 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24729 /* Old name for UQASX. */
21d799b5
NC
24730 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24731 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24732 /* Old name for UQSAX. */
21d799b5
NC
24733 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24734 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24735 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24736 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24737 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24738 /* Old name for USAX. */
74db7efb 24739 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24740 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24741 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24742 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24743 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24744 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24745 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24746 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24747 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24748 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24749 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24750 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24751 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24752 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24753 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24754 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24755 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24756 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24757 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24758 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24759 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24760 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24761 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24762 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24763 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24764 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24765 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24766 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24767 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
24768 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24769 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24770 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24771 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24772 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 24773
c921be7d 24774#undef ARM_VARIANT
55e8aae7 24775#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 24776#undef THUMB_VARIANT
55e8aae7 24777#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 24778
21d799b5
NC
24779 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24780 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24781 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24782 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 24783
c921be7d
NC
24784#undef THUMB_VARIANT
24785#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
24786 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24787 ldrexd, t_ldrexd),
24788 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24789 RRnpcb), strexd, t_strexd),
ebdca51a 24790
c921be7d 24791#undef THUMB_VARIANT
ff8646ee 24792#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
24793 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24794 rd_rn, rd_rn),
24795 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24796 rd_rn, rd_rn),
24797 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24798 strex, t_strexbh),
5be8be5d 24799 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24800 strex, t_strexbh),
21d799b5 24801 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 24802
c921be7d 24803#undef ARM_VARIANT
f4c65163 24804#define ARM_VARIANT & arm_ext_sec
74db7efb 24805#undef THUMB_VARIANT
f4c65163 24806#define THUMB_VARIANT & arm_ext_sec
c921be7d 24807
21d799b5 24808 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 24809
90ec0d68
MGD
24810#undef ARM_VARIANT
24811#define ARM_VARIANT & arm_ext_virt
24812#undef THUMB_VARIANT
24813#define THUMB_VARIANT & arm_ext_virt
24814
24815 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24816 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24817
ddfded2f
MW
24818#undef ARM_VARIANT
24819#define ARM_VARIANT & arm_ext_pan
24820#undef THUMB_VARIANT
24821#define THUMB_VARIANT & arm_ext_pan
24822
24823 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24824
c921be7d 24825#undef ARM_VARIANT
74db7efb 24826#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
24827#undef THUMB_VARIANT
24828#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24829
21d799b5
NC
24830 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24831 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24832 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24833 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 24834
21d799b5 24835 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 24836 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 24837
5be8be5d
DG
24838 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24839 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24840 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24841 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 24842
91d8b670
JG
24843#undef ARM_VARIANT
24844#define ARM_VARIANT & arm_ext_v3
24845#undef THUMB_VARIANT
24846#define THUMB_VARIANT & arm_ext_v6t2
24847
24848 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
24849 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24850 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
24851
24852#undef ARM_VARIANT
24853#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
24854#undef THUMB_VARIANT
24855#define THUMB_VARIANT & arm_ext_v6t2_v8m
24856 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24857 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24858
bf3eeda7 24859 /* Thumb-only instructions. */
74db7efb 24860#undef ARM_VARIANT
bf3eeda7
NS
24861#define ARM_VARIANT NULL
24862 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24863 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
24864
24865 /* ARM does not really have an IT instruction, so always allow it.
24866 The opcode is copied from Thumb in order to allow warnings in
24867 -mimplicit-it=[never | arm] modes. */
24868#undef ARM_VARIANT
24869#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
24870#undef THUMB_VARIANT
24871#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24872
21d799b5
NC
24873 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24874 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24875 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24876 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24877 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24878 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24879 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24880 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24881 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24882 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24883 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24884 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24885 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24886 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24887 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 24888 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
24889 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24890 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 24891
92e90b6e 24892 /* Thumb2 only instructions. */
c921be7d
NC
24893#undef ARM_VARIANT
24894#define ARM_VARIANT NULL
92e90b6e 24895
21d799b5
NC
24896 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24897 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24898 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24899 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24900 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24901 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 24902
eea54501
MGD
24903 /* Hardware division instructions. */
24904#undef ARM_VARIANT
24905#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
24906#undef THUMB_VARIANT
24907#define THUMB_VARIANT & arm_ext_div
24908
eea54501
MGD
24909 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24910 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 24911
7e806470 24912 /* ARM V6M/V7 instructions. */
c921be7d
NC
24913#undef ARM_VARIANT
24914#define ARM_VARIANT & arm_ext_barrier
24915#undef THUMB_VARIANT
24916#define THUMB_VARIANT & arm_ext_barrier
24917
ccb84d65
JB
24918 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24919 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24920 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24921
62b3e311 24922 /* ARM V7 instructions. */
c921be7d
NC
24923#undef ARM_VARIANT
24924#define ARM_VARIANT & arm_ext_v7
24925#undef THUMB_VARIANT
24926#define THUMB_VARIANT & arm_ext_v7
24927
21d799b5
NC
24928 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24929 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24930
74db7efb 24931#undef ARM_VARIANT
60e5ef9f 24932#define ARM_VARIANT & arm_ext_mp
74db7efb 24933#undef THUMB_VARIANT
60e5ef9f
MGD
24934#define THUMB_VARIANT & arm_ext_mp
24935
24936 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24937
53c4b28b
MGD
24938 /* AArchv8 instructions. */
24939#undef ARM_VARIANT
24940#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24941
24942/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24943#undef THUMB_VARIANT
4ed7ed8d 24944#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24945
4ed7ed8d
TP
24946 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24947 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24948 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24949 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24950 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24951 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24952 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24953 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24954 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24955 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24956 stlex, t_stlex),
4b8c8c02
RE
24957 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24958 stlex, t_stlex),
24959 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24960 stlex, t_stlex),
4ed7ed8d
TP
24961#undef THUMB_VARIANT
24962#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24963
4ed7ed8d 24964 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24965 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24966 ldrexd, t_ldrexd),
24967 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24968 strexd, t_strexd),
f7dd2fb2
TC
24969
24970/* Defined in V8 but is in undefined encoding space for earlier
24971 architectures. However earlier architectures are required to treat
24972 this instuction as a semihosting trap as well. Hence while not explicitly
24973 defined as such, it is in fact correct to define the instruction for all
24974 architectures. */
24975#undef THUMB_VARIANT
24976#define THUMB_VARIANT & arm_ext_v1
24977#undef ARM_VARIANT
24978#define ARM_VARIANT & arm_ext_v1
24979 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24980
8884b720 24981 /* ARMv8 T32 only. */
74db7efb 24982#undef ARM_VARIANT
b79f7053
MGD
24983#define ARM_VARIANT NULL
24984 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24985 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24986 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24987
33399f07
MGD
24988 /* FP for ARMv8. */
24989#undef ARM_VARIANT
a715796b 24990#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24991#undef THUMB_VARIANT
a715796b 24992#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24993
24994 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24995 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24996 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24997 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24998 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24999 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
25000 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
25001 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
25002 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
25003 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
25004 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 25005
91ff7894
MGD
25006 /* Crypto v1 extensions. */
25007#undef ARM_VARIANT
25008#define ARM_VARIANT & fpu_crypto_ext_armv8
25009#undef THUMB_VARIANT
25010#define THUMB_VARIANT & fpu_crypto_ext_armv8
25011
25012 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25013 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25014 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25015 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
25016 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25017 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25018 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25019 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25020 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25021 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25022 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
25023 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25024 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25025 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 25026
dd5181d5 25027#undef ARM_VARIANT
8b301fbb 25028#define ARM_VARIANT & arm_ext_crc
dd5181d5 25029#undef THUMB_VARIANT
8b301fbb 25030#define THUMB_VARIANT & arm_ext_crc
dd5181d5
KT
25031 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25032 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25033 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25034 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25035 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25036 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25037
105bde57
MW
25038 /* ARMv8.2 RAS extension. */
25039#undef ARM_VARIANT
4d1464f2 25040#define ARM_VARIANT & arm_ext_ras
105bde57 25041#undef THUMB_VARIANT
4d1464f2 25042#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
25043 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25044
49e8a725
SN
25045#undef ARM_VARIANT
25046#define ARM_VARIANT & arm_ext_v8_3
25047#undef THUMB_VARIANT
25048#define THUMB_VARIANT & arm_ext_v8_3
25049 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25050
c604a79a
JW
25051#undef ARM_VARIANT
25052#define ARM_VARIANT & fpu_neon_ext_dotprod
25053#undef THUMB_VARIANT
25054#define THUMB_VARIANT & fpu_neon_ext_dotprod
25055 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25056 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25057
c921be7d
NC
25058#undef ARM_VARIANT
25059#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
25060#undef THUMB_VARIANT
25061#define THUMB_VARIANT NULL
c921be7d 25062
21d799b5
NC
25063 cCE("wfs", e200110, 1, (RR), rd),
25064 cCE("rfs", e300110, 1, (RR), rd),
25065 cCE("wfc", e400110, 1, (RR), rd),
25066 cCE("rfc", e500110, 1, (RR), rd),
25067
25068 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25069 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25070 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25071 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25072
25073 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25074 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25075 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25076 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25077
25078 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25079 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25080 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25081 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25082 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25083 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25084 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25085 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25086 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25087 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25088 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25089 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25090
25091 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25092 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25093 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25094 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25095 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25096 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25097 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25098 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25099 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25100 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25101 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25102 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25103
25104 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25105 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25106 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25107 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25108 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25109 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25110 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25111 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25112 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25113 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25114 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25115 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25116
25117 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25118 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25119 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25120 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25121 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25122 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25123 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25124 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25125 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25126 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25127 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25128 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25129
25130 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25131 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25132 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25133 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25134 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25135 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25136 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25137 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25138 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25139 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25140 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25141 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25142
25143 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25144 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25145 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25146 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25147 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25148 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25149 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25150 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25151 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25152 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25153 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25154 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25155
25156 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25157 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25158 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25159 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25160 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25161 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25162 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25163 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25164 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25165 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25166 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25167 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25168
25169 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25170 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25171 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25172 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25173 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25174 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25175 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25176 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25177 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25178 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25179 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25180 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25181
25182 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25183 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25184 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25185 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25186 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25187 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25188 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25189 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25190 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25191 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25192 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25193 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25194
25195 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25196 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25197 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25198 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25199 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25200 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25201 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25202 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25203 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25204 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25205 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25206 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25207
25208 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25209 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25210 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25211 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25212 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25213 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25214 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25215 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25216 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25217 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25218 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25219 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25220
25221 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25222 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25223 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25224 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25225 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25226 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25227 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25228 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25229 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25230 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25231 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25232 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25233
25234 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25235 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25236 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25237 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25238 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25239 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25240 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25241 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25242 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25243 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25244 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25245 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25246
25247 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25248 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25249 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25250 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25251 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25252 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25253 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25254 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25255 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25256 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25257 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25258 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25259
25260 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25261 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25262 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25263 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25264 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25265 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25266 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25267 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25268 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25269 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25270 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25271 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25272
25273 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25274 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25275 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25276 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25277 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25278 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25279 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25280 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25281 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25282 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25283 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25284 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25285
25286 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25287 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25288 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25289 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25290 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25291 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25295 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25296 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25297 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25298
25299 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25302 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25303 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25304 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25309 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25311
25312 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25316 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25317 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25322 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25324
25325 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25329 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25330 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25335 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25337
25338 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25342 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25343 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25348 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25350
25351 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25355 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25356 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25361 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25363
25364 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25368 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25369 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25374 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25376
25377 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25381 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25382 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25387 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25389
25390 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25394 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25395 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25400 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25402
25403 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25407 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25408 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25413 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25415
25416 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25420 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25421 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25426 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25428
25429 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25433 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25434 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25439 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25441
25442 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25445 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25446 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25447 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25448 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25449 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25450 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25451 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25452 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25453 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25454
25455 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25456 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25457 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25458 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25459
25460 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25461 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25462 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25463 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25464 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25465 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25466 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25467 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25468 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25469 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25470 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25471 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 25472
c19d1205
ZW
25473 /* The implementation of the FIX instruction is broken on some
25474 assemblers, in that it accepts a precision specifier as well as a
25475 rounding specifier, despite the fact that this is meaningless.
25476 To be more compatible, we accept it as well, though of course it
25477 does not set any bits. */
21d799b5
NC
25478 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25479 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25480 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25481 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25482 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25483 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25484 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25485 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25486 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25487 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25488 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25489 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25490 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 25491
c19d1205 25492 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
25493#undef ARM_VARIANT
25494#define ARM_VARIANT & fpu_fpa_ext_v2
25495
21d799b5
NC
25496 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25497 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25498 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25499 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25500 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25501 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 25502
c921be7d
NC
25503#undef ARM_VARIANT
25504#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
25505#undef THUMB_VARIANT
25506#define THUMB_VARIANT & arm_ext_v6t2
25507 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25508 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
ef8f595f
MI
25509 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25510 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25511 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25512 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
90e9955a
SP
25513
25514 /* Memory operations. */
25515 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25516 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25517 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25518 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
ba6cd17f 25519#undef THUMB_VARIANT
c921be7d 25520
c19d1205 25521 /* Moves and type conversions. */
21d799b5
NC
25522 cCE("fmstat", ef1fa10, 0, (), noargs),
25523 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25524 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25525 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25526 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25527 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25528 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25529 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25530 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
25531
25532 /* Memory operations. */
55881a11 25533 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25534 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25535 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25536 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25537 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25538 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
55881a11 25539 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25540 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25541 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25542 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25543 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25544 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 25545
c19d1205 25546 /* Monadic operations. */
21d799b5
NC
25547 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25548 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25549 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
25550
25551 /* Dyadic operations. */
21d799b5
NC
25552 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25553 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25554 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25555 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25556 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25557 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25558 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25559 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25560 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 25561
c19d1205 25562 /* Comparisons. */
21d799b5
NC
25563 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25564 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25565 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25566 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 25567
62f3b8c8
PB
25568 /* Double precision load/store are still present on single precision
25569 implementations. */
55881a11
MGD
25570 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25571 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25572 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25573 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25574 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25575 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25576 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25577 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 25578
c921be7d
NC
25579#undef ARM_VARIANT
25580#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25581
c19d1205 25582 /* Moves and type conversions. */
21d799b5
NC
25583 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25584 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25585 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25586 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25587 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25588 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25589 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25590 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25591 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25592 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25593 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25594 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 25595
c19d1205 25596 /* Monadic operations. */
21d799b5
NC
25597 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25598 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25599 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
25600
25601 /* Dyadic operations. */
21d799b5
NC
25602 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25603 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25604 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25605 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25606 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25607 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25608 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25609 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25610 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 25611
c19d1205 25612 /* Comparisons. */
21d799b5
NC
25613 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25614 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25615 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25616 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 25617
037e8744
JB
25618/* Instructions which may belong to either the Neon or VFP instruction sets.
25619 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
25620#undef ARM_VARIANT
25621#define ARM_VARIANT & fpu_vfp_ext_v1xd
ef8f595f
MI
25622#undef THUMB_VARIANT
25623#define THUMB_VARIANT & arm_ext_v6t2
25624
25625 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25626 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25627 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25628 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25629 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25630 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25631
25632 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25633 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25634
c921be7d
NC
25635#undef THUMB_VARIANT
25636#define THUMB_VARIANT & fpu_vfp_ext_v1xd
25637
037e8744
JB
25638 /* These mnemonics are unique to VFP. */
25639 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25640 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
25641 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25642 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25643 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
25644 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25645
25646 /* Mnemonics shared by Neon and VFP. */
21d799b5 25647 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 25648
dd9634d9 25649 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 25650 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
25651 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25652 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 25653
037e8744
JB
25654
25655 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
25656 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25657
32c36c3c
AV
25658#undef THUMB_VARIANT
25659/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25660 by different feature bits. Since we are setting the Thumb guard, we can
25661 require Thumb-1 which makes it a nop guard and set the right feature bit in
25662 do_vldr_vstr (). */
25663#define THUMB_VARIANT & arm_ext_v4t
25664 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25665 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25666
9db2f6b4
RL
25667#undef ARM_VARIANT
25668#define ARM_VARIANT & arm_ext_fp16
25669#undef THUMB_VARIANT
25670#define THUMB_VARIANT & arm_ext_fp16
25671 /* New instructions added from v8.2, allowing the extraction and insertion of
25672 the upper 16 bits of a 32-bit vector register. */
25673 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25674 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25675
dec41383 25676 /* New backported fma/fms instructions optional in v8.2. */
aab2c27d
MM
25677 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25678 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
dec41383 25679
c921be7d
NC
25680#undef THUMB_VARIANT
25681#define THUMB_VARIANT & fpu_neon_ext_v1
25682#undef ARM_VARIANT
25683#define ARM_VARIANT & fpu_neon_ext_v1
25684
5287ad62
JB
25685 /* Data processing with three registers of the same length. */
25686 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25687 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25688 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 25689 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 25690 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
25691 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25692 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25693 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 25694 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 25695 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 25696 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 25697 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
25698 shl should accept I8 I16 I32 I64,
25699 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25700 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25701 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 25702 /* Logic ops, types optional & ignored. */
4316f0d2 25703 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25704 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25705 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25706 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25707 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
25708 /* Bitfield ops, untyped. */
25709 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25710 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25711 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25712 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25713 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25714 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 25715 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 25716 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25717 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25718 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
25719 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25720 back to neon_dyadic_if_su. */
21d799b5
NC
25721 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25722 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25723 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25724 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25725 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25726 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25727 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25728 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 25729 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
25730 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25731 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 25732 /* As above, D registers only. */
21d799b5
NC
25733 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25734 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 25735 /* Int and float variants, signedness unimportant. */
21d799b5
NC
25736 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25737 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25738 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 25739 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
25740 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25741 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
25742 /* vtst takes sizes 8, 16, 32. */
25743 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25744 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25745 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 25746 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 25747 /* VQD{R}MULH takes S16 S32. */
21d799b5 25748 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 25749 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
25750 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25751 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25752 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25753 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
25754 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25755 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25756 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25757 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
25758 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25759 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25760 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25761 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 25762 /* ARM v8.1 extension. */
643afb90
MW
25763 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25764 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25765 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
25766
25767 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 25768 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
25769 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25770
25771 /* Data processing with two registers and a shift amount. */
25772 /* Right shifts, and variants with rounding.
25773 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25774 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
25775 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25776 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25777 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25778 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25779 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25780 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 25781 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
25782 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25783 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
25784 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25785 /* Right shift immediate, saturating & narrowing, with rounding variants.
25786 Types accepted S16 S32 S64 U16 U32 U64. */
25787 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25788 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25789 /* As above, unsigned. Types accepted S16 S32 S64. */
25790 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25791 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25792 /* Right shift narrowing. Types accepted I16 I32 I64. */
25793 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25794 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25795 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 25796 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 25797 /* CVT with optional immediate for fixed-point variant. */
21d799b5 25798 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 25799
4316f0d2 25800 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
25801
25802 /* Data processing, three registers of different lengths. */
25803 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25804 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
25805 /* If not scalar, fall back to neon_dyadic_long.
25806 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
25807 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25808 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
25809 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25810 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25811 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25812 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25813 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25814 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25815 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25816 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25817 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
25818 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25819 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25820 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
25821 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25822 S16 S32 U16 U32. */
21d799b5 25823 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
25824
25825 /* Extract. Size 8. */
3b8d421e
PB
25826 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25827 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
25828
25829 /* Two registers, miscellaneous. */
25830 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 25831 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 25832 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
25833 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25834 /* Vector replicate. Sizes 8 16 32. */
21d799b5 25835 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
25836 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25837 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25838 /* VMOVN. Types I16 I32 I64. */
21d799b5 25839 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 25840 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 25841 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 25842 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 25843 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
25844 /* VZIP / VUZP. Sizes 8 16 32. */
25845 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25846 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25847 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25848 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25849 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 25850 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
25851 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25852 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25853 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25854 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25855 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25856 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 25857 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
25858 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25859 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25860 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25861 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25862 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
25863 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25864 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
25865 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25866 /* VCNT. Size 8. */
25867 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25868 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25869 /* Two address, untyped. */
25870 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25871 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25872 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
25873 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25874 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
25875
25876 /* Table lookup. Size 8. */
25877 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25878 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25879
c921be7d
NC
25880#undef THUMB_VARIANT
25881#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25882#undef ARM_VARIANT
25883#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25884
5287ad62 25885 /* Neon element/structure load/store. */
21d799b5
NC
25886 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25887 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25888 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25889 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25890 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25891 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25892 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25893 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 25894
c921be7d 25895#undef THUMB_VARIANT
74db7efb
NC
25896#define THUMB_VARIANT & fpu_vfp_ext_v3xd
25897#undef ARM_VARIANT
25898#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
25899 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25900 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25901 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25902 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25903 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25904 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25905 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25906 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25907 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25908
74db7efb 25909#undef THUMB_VARIANT
c921be7d
NC
25910#define THUMB_VARIANT & fpu_vfp_ext_v3
25911#undef ARM_VARIANT
25912#define ARM_VARIANT & fpu_vfp_ext_v3
25913
21d799b5 25914 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 25915 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25916 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25917 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25918 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25919 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25920 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25921 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25922 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25923
74db7efb
NC
25924#undef ARM_VARIANT
25925#define ARM_VARIANT & fpu_vfp_ext_fma
25926#undef THUMB_VARIANT
25927#define THUMB_VARIANT & fpu_vfp_ext_fma
aab2c27d 25928 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
62f3b8c8
PB
25929 VFP FMA variant; NEON and VFP FMA always includes the NEON
25930 FMA instructions. */
d58196e0 25931 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
aab2c27d 25932 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
d58196e0
AV
25933 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25934
62f3b8c8
PB
25935 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25936 the v form should always be used. */
25937 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25938 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25939 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25940 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25941 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25942 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25943
5287ad62 25944#undef THUMB_VARIANT
c921be7d
NC
25945#undef ARM_VARIANT
25946#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25947
21d799b5
NC
25948 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25949 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25950 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25951 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25952 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25953 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25954 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25955 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25956
c921be7d
NC
25957#undef ARM_VARIANT
25958#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25959
21d799b5
NC
25960 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25961 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25962 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25963 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25964 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25965 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25966 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25967 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25968 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25969 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25970 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25971 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25972 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25973 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25974 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25975 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25976 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25977 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25978 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25979 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25980 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25981 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25982 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25983 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25984 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25985 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25986 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25987 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25988 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25989 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25990 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25991 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25992 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25993 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25994 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25995 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25996 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25997 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25998 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25999 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26000 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26001 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26002 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26004 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26005 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
26007 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26008 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26011 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26012 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26013 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26014 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26015 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26016 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26020 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26025 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26026 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26027 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26028 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26029 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26030 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26034 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26046 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26047 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26048 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26049 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26051 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26054 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26056 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26057 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26058 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26059 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26060 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26061 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26062 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26063 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26064 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26065 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26066 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26067 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26068 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26069 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26070 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26071 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26072 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26073 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26074 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26075 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26076 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26077 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26078 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26079 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26080 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26081 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26082 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26083 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26084 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26085 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26086 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26087 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26088 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26089 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26090 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26091 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26092 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26093 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26094 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26095 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26096 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26097 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26098 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26099 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26100 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26101 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26102 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26103 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26104 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26105 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26106 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26107 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26108 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26109 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26110 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26111 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26112 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26113 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26114 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26115 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26116 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26117 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26118 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26119 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26120 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26121 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 26122
c921be7d
NC
26123#undef ARM_VARIANT
26124#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26125
21d799b5
NC
26126 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26127 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26128 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26129 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26130 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26131 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26132 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26133 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26134 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26135 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26136 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26144 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26147 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26175 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26176 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26177 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26178 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26179 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26180 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26181 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26182 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 26183
c921be7d
NC
26184#undef ARM_VARIANT
26185#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26186
21d799b5
NC
26187 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26188 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26189 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26190 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26191 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26192 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26193 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26194 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26195 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26196 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26197 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26198 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26199 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26200 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
26201 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26202 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26203 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26204 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26205 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26206 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26207 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26208 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26209 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26210 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
26211 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26212 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26213 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26214 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
26215 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26216 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
26217 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26218 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26219 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26220 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
26221 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26222 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26223 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26224 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26225 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26226 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
26227 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26228 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
26229 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26230 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
26231 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26232 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26233 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26234 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26235 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26236 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26237 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26238 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26239 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26240 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26241 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26242 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26243 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26244 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26245 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26246 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26247 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26248 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26249 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26250 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26251 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26252 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26253 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26254 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26255 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26256 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26257 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26258 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
26259 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26260 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
26261 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26262 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 26263
7fadb25d
SD
26264 /* ARMv8.5-A instructions. */
26265#undef ARM_VARIANT
26266#define ARM_VARIANT & arm_ext_sb
26267#undef THUMB_VARIANT
26268#define THUMB_VARIANT & arm_ext_sb
26269 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26270
dad0c3bf
SD
26271#undef ARM_VARIANT
26272#define ARM_VARIANT & arm_ext_predres
26273#undef THUMB_VARIANT
26274#define THUMB_VARIANT & arm_ext_predres
26275 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26276 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26277 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26278
16a1fa25 26279 /* ARMv8-M instructions. */
4ed7ed8d
TP
26280#undef ARM_VARIANT
26281#define ARM_VARIANT NULL
26282#undef THUMB_VARIANT
26283#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
26284 ToU("sg", e97fe97f, 0, (), noargs),
26285 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26286 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26287 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26288 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26289 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26290 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
26291
26292 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26293 instructions behave as nop if no VFP is present. */
26294#undef THUMB_VARIANT
26295#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
26296 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26297 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
26298
26299 /* Armv8.1-M Mainline instructions. */
26300#undef THUMB_VARIANT
26301#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
26302 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26303 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26304 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26305 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26306 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26307 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26308 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26309 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26310 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26311
4389b29a 26312 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 26313 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 26314 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 26315 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 26316 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
26317
26318 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26319 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26320 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 26321
efd6b359 26322 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
26323 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26324
26325#undef THUMB_VARIANT
26326#define THUMB_VARIANT & mve_ext
23d00a41
SD
26327 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26328 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26329 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
08132bdd
SP
26330 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26331 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
23d00a41
SD
26332 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26333 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26334 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26335 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26336 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26337 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26338 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26339 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26340 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26341 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
26342
26343 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26344 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26345 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26346 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26347 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26348 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26349 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26350 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26351 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26352 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26353 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26354 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26355 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26356 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26357 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26358
5ee91343
AV
26359 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26360 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26361 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26362 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26363 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26364 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26365 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26366 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26367 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26368 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26369 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26370 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26371 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26372 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26373 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26374
a302e574 26375 /* MVE and MVE FP only. */
7df54120 26376 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
efd0b310 26377 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
c2dafc2a
AV
26378 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26379 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26380 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26381 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 26382 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
26383 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26384 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26385 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26386 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26387 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26388 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26389 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26390 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26391 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26392 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26393 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26394
35c228db
AV
26395 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26396 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26397 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26398 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26399 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26400 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26401 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26402 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26403 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26404 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26405 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26406 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
26407 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26408 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26409 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26410 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26411 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26412 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26413 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26414 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 26415
57785aa2
AV
26416 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26417 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 26418 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
26419 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26420 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26421 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26422 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
26423 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26424 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26425 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26426 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
26427 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26428 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
26429 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26430 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26431 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26432 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 26433
93925576
AV
26434 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26435 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26436 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26437 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26438 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26439 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26440 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26441 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26442 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26443 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26444 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26445 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26446 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26447 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26448 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26449 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26450 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26451 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26452 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26453 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26454
2d78f95b
AV
26455 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26456 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26457 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
26458 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26459 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 26460
8b8b22a4
AV
26461 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26462 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26463 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26464 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26465 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26466 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26467 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26468 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
26469 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26470 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26471 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
26472 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26473 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
26474 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26475 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26476 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26477 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 26478
4aa88b50
AV
26479 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26480 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26481 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26482 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26483 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26484 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26485 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26486 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26487 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26488 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26489 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26490 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26491
acca5630
AV
26492 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26493 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26494 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26495
1f6234a3
AV
26496 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26497 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26498 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26499 toU("lctp", _lctp, 0, (), t_loloop),
26500
5d281bf0
AV
26501#undef THUMB_VARIANT
26502#define THUMB_VARIANT & mve_fp_ext
26503 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 26504 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
26505 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26506 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
26507 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26508 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26509 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26510 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 26511
5ee91343 26512#undef ARM_VARIANT
57785aa2 26513#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
26514#undef THUMB_VARIANT
26515#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
26516 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26517 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 26518
57785aa2
AV
26519 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26520
26521#undef ARM_VARIANT
26522#define ARM_VARIANT & fpu_vfp_ext_v1xd
26523
26524 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26525 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26526 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26527 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26528
886e1c73
AV
26529 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26530 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26531 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 26532
485dee97
AV
26533 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26534 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26535
57785aa2
AV
26536 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26537 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26538
1b883319
AV
26539 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26540 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26541
57785aa2
AV
26542#undef ARM_VARIANT
26543#define ARM_VARIANT & fpu_vfp_ext_v2
26544
26545 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26546 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26547 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26548 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26549
dd9634d9
AV
26550#undef ARM_VARIANT
26551#define ARM_VARIANT & fpu_vfp_ext_armv8xd
26552 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26553 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26554 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26555 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
26556 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26557 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
26558
26559#undef ARM_VARIANT
5ee91343 26560#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 26561 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343
AV
26562 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
26563 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
26564 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
f601a00c
AV
26565 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26566 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26567 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26568 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26569 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
26570 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26571 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 26572 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
26573 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26574 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26575 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
26576 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26577 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
26578 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26579 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
26580 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26581 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26582 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
26583 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26584 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26585 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
26586 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26587 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
26588 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26589 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26590 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26591 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26592 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26593 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26594 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
26595 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26596 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26597 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
26598
26599#undef ARM_VARIANT
26600#define ARM_VARIANT & arm_ext_v8_3
26601#undef THUMB_VARIANT
26602#define THUMB_VARIANT & arm_ext_v6t2_v8m
26603 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26604 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
aab2c27d
MM
26605
26606#undef ARM_VARIANT
26607#define ARM_VARIANT &arm_ext_bf16
26608#undef THUMB_VARIANT
26609#define THUMB_VARIANT &arm_ext_bf16
26610 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26611 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26612 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26613
26614#undef ARM_VARIANT
26615#define ARM_VARIANT &arm_ext_i8mm
26616#undef THUMB_VARIANT
26617#define THUMB_VARIANT &arm_ext_i8mm
26618 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26619 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
616ce08e 26620 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
aab2c27d
MM
26621 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26622 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
4934a27c
MM
26623
26624#undef ARM_VARIANT
26625#undef THUMB_VARIANT
26626#define THUMB_VARIANT &arm_ext_cde
26627 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26628 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26629 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26630 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26631
26632 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26633 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26634 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26635 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26636
26637 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26638 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26639 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26640 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
5aae9ae9
MM
26641
26642 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26643 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26644
26645 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26646 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26647
26648 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26649 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
c19d1205 26650};
5aae9ae9 26651
c19d1205
ZW
26652#undef ARM_VARIANT
26653#undef THUMB_VARIANT
26654#undef TCE
c19d1205
ZW
26655#undef TUE
26656#undef TUF
26657#undef TCC
8f06b2d8 26658#undef cCE
e3cb604e
PB
26659#undef cCL
26660#undef C3E
4389b29a 26661#undef C3
c19d1205
ZW
26662#undef CE
26663#undef CM
4389b29a 26664#undef CL
c19d1205
ZW
26665#undef UE
26666#undef UF
26667#undef UT
5287ad62
JB
26668#undef NUF
26669#undef nUF
26670#undef NCE
26671#undef nCE
c19d1205
ZW
26672#undef OPS0
26673#undef OPS1
26674#undef OPS2
26675#undef OPS3
26676#undef OPS4
26677#undef OPS5
26678#undef OPS6
26679#undef do_0
4389b29a
AV
26680#undef ToC
26681#undef toC
26682#undef ToU
f6b2b12d 26683#undef toU
c19d1205
ZW
26684\f
26685/* MD interface: bits in the object file. */
bfae80f2 26686
c19d1205
ZW
26687/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26688 for use in the a.out file, and stores them in the array pointed to by buf.
26689 This knows about the endian-ness of the target machine and does
26690 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26691 2 (short) and 4 (long) Floating numbers are put out as a series of
26692 LITTLENUMS (shorts, here at least). */
b99bd4ef 26693
c19d1205
ZW
26694void
26695md_number_to_chars (char * buf, valueT val, int n)
26696{
26697 if (target_big_endian)
26698 number_to_chars_bigendian (buf, val, n);
26699 else
26700 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
26701}
26702
c19d1205
ZW
26703static valueT
26704md_chars_to_number (char * buf, int n)
bfae80f2 26705{
c19d1205
ZW
26706 valueT result = 0;
26707 unsigned char * where = (unsigned char *) buf;
bfae80f2 26708
c19d1205 26709 if (target_big_endian)
b99bd4ef 26710 {
c19d1205
ZW
26711 while (n--)
26712 {
26713 result <<= 8;
26714 result |= (*where++ & 255);
26715 }
b99bd4ef 26716 }
c19d1205 26717 else
b99bd4ef 26718 {
c19d1205
ZW
26719 while (n--)
26720 {
26721 result <<= 8;
26722 result |= (where[n] & 255);
26723 }
bfae80f2 26724 }
b99bd4ef 26725
c19d1205 26726 return result;
bfae80f2 26727}
b99bd4ef 26728
c19d1205 26729/* MD interface: Sections. */
b99bd4ef 26730
fa94de6b
RM
26731/* Calculate the maximum variable size (i.e., excluding fr_fix)
26732 that an rs_machine_dependent frag may reach. */
26733
26734unsigned int
26735arm_frag_max_var (fragS *fragp)
26736{
26737 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26738 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26739
26740 Note that we generate relaxable instructions even for cases that don't
26741 really need it, like an immediate that's a trivial constant. So we're
26742 overestimating the instruction size for some of those cases. Rather
26743 than putting more intelligence here, it would probably be better to
26744 avoid generating a relaxation frag in the first place when it can be
26745 determined up front that a short instruction will suffice. */
26746
26747 gas_assert (fragp->fr_type == rs_machine_dependent);
26748 return INSN_SIZE;
26749}
26750
0110f2b8
PB
26751/* Estimate the size of a frag before relaxing. Assume everything fits in
26752 2 bytes. */
26753
c19d1205 26754int
0110f2b8 26755md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
26756 segT segtype ATTRIBUTE_UNUSED)
26757{
0110f2b8
PB
26758 fragp->fr_var = 2;
26759 return 2;
26760}
26761
26762/* Convert a machine dependent frag. */
26763
26764void
26765md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26766{
26767 unsigned long insn;
26768 unsigned long old_op;
26769 char *buf;
26770 expressionS exp;
26771 fixS *fixp;
26772 int reloc_type;
26773 int pc_rel;
26774 int opcode;
26775
26776 buf = fragp->fr_literal + fragp->fr_fix;
26777
26778 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
26779 if (fragp->fr_symbol)
26780 {
0110f2b8
PB
26781 exp.X_op = O_symbol;
26782 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
26783 }
26784 else
26785 {
0110f2b8 26786 exp.X_op = O_constant;
5f4273c7 26787 }
0110f2b8
PB
26788 exp.X_add_number = fragp->fr_offset;
26789 opcode = fragp->fr_subtype;
26790 switch (opcode)
26791 {
26792 case T_MNEM_ldr_pc:
26793 case T_MNEM_ldr_pc2:
26794 case T_MNEM_ldr_sp:
26795 case T_MNEM_str_sp:
26796 case T_MNEM_ldr:
26797 case T_MNEM_ldrb:
26798 case T_MNEM_ldrh:
26799 case T_MNEM_str:
26800 case T_MNEM_strb:
26801 case T_MNEM_strh:
26802 if (fragp->fr_var == 4)
26803 {
5f4273c7 26804 insn = THUMB_OP32 (opcode);
0110f2b8
PB
26805 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26806 {
26807 insn |= (old_op & 0x700) << 4;
26808 }
26809 else
26810 {
26811 insn |= (old_op & 7) << 12;
26812 insn |= (old_op & 0x38) << 13;
26813 }
26814 insn |= 0x00000c00;
26815 put_thumb32_insn (buf, insn);
26816 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26817 }
26818 else
26819 {
26820 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26821 }
26822 pc_rel = (opcode == T_MNEM_ldr_pc2);
26823 break;
26824 case T_MNEM_adr:
26825 if (fragp->fr_var == 4)
26826 {
26827 insn = THUMB_OP32 (opcode);
26828 insn |= (old_op & 0xf0) << 4;
26829 put_thumb32_insn (buf, insn);
26830 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26831 }
26832 else
26833 {
26834 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26835 exp.X_add_number -= 4;
26836 }
26837 pc_rel = 1;
26838 break;
26839 case T_MNEM_mov:
26840 case T_MNEM_movs:
26841 case T_MNEM_cmp:
26842 case T_MNEM_cmn:
26843 if (fragp->fr_var == 4)
26844 {
26845 int r0off = (opcode == T_MNEM_mov
26846 || opcode == T_MNEM_movs) ? 0 : 8;
26847 insn = THUMB_OP32 (opcode);
26848 insn = (insn & 0xe1ffffff) | 0x10000000;
26849 insn |= (old_op & 0x700) << r0off;
26850 put_thumb32_insn (buf, insn);
26851 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26852 }
26853 else
26854 {
26855 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26856 }
26857 pc_rel = 0;
26858 break;
26859 case T_MNEM_b:
26860 if (fragp->fr_var == 4)
26861 {
26862 insn = THUMB_OP32(opcode);
26863 put_thumb32_insn (buf, insn);
26864 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26865 }
26866 else
26867 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26868 pc_rel = 1;
26869 break;
26870 case T_MNEM_bcond:
26871 if (fragp->fr_var == 4)
26872 {
26873 insn = THUMB_OP32(opcode);
26874 insn |= (old_op & 0xf00) << 14;
26875 put_thumb32_insn (buf, insn);
26876 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26877 }
26878 else
26879 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26880 pc_rel = 1;
26881 break;
26882 case T_MNEM_add_sp:
26883 case T_MNEM_add_pc:
26884 case T_MNEM_inc_sp:
26885 case T_MNEM_dec_sp:
26886 if (fragp->fr_var == 4)
26887 {
26888 /* ??? Choose between add and addw. */
26889 insn = THUMB_OP32 (opcode);
26890 insn |= (old_op & 0xf0) << 4;
26891 put_thumb32_insn (buf, insn);
16805f35
PB
26892 if (opcode == T_MNEM_add_pc)
26893 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26894 else
26895 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
26896 }
26897 else
26898 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26899 pc_rel = 0;
26900 break;
26901
26902 case T_MNEM_addi:
26903 case T_MNEM_addis:
26904 case T_MNEM_subi:
26905 case T_MNEM_subis:
26906 if (fragp->fr_var == 4)
26907 {
26908 insn = THUMB_OP32 (opcode);
26909 insn |= (old_op & 0xf0) << 4;
26910 insn |= (old_op & 0xf) << 16;
26911 put_thumb32_insn (buf, insn);
16805f35
PB
26912 if (insn & (1 << 20))
26913 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26914 else
26915 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
26916 }
26917 else
26918 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26919 pc_rel = 0;
26920 break;
26921 default:
5f4273c7 26922 abort ();
0110f2b8
PB
26923 }
26924 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 26925 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
26926 fixp->fx_file = fragp->fr_file;
26927 fixp->fx_line = fragp->fr_line;
26928 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
26929
26930 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26931 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26932 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26933 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
26934}
26935
26936/* Return the size of a relaxable immediate operand instruction.
26937 SHIFT and SIZE specify the form of the allowable immediate. */
26938static int
26939relax_immediate (fragS *fragp, int size, int shift)
26940{
26941 offsetT offset;
26942 offsetT mask;
26943 offsetT low;
26944
26945 /* ??? Should be able to do better than this. */
26946 if (fragp->fr_symbol)
26947 return 4;
26948
26949 low = (1 << shift) - 1;
26950 mask = (1 << (shift + size)) - (1 << shift);
26951 offset = fragp->fr_offset;
26952 /* Force misaligned offsets to 32-bit variant. */
26953 if (offset & low)
5e77afaa 26954 return 4;
0110f2b8
PB
26955 if (offset & ~mask)
26956 return 4;
26957 return 2;
26958}
26959
5e77afaa
PB
26960/* Get the address of a symbol during relaxation. */
26961static addressT
5f4273c7 26962relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
26963{
26964 fragS *sym_frag;
26965 addressT addr;
26966 symbolS *sym;
26967
26968 sym = fragp->fr_symbol;
26969 sym_frag = symbol_get_frag (sym);
26970 know (S_GET_SEGMENT (sym) != absolute_section
26971 || sym_frag == &zero_address_frag);
26972 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26973
26974 /* If frag has yet to be reached on this pass, assume it will
26975 move by STRETCH just as we did. If this is not so, it will
26976 be because some frag between grows, and that will force
26977 another pass. */
26978
26979 if (stretch != 0
26980 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26981 {
26982 fragS *f;
26983
26984 /* Adjust stretch for any alignment frag. Note that if have
26985 been expanding the earlier code, the symbol may be
26986 defined in what appears to be an earlier frag. FIXME:
26987 This doesn't handle the fr_subtype field, which specifies
26988 a maximum number of bytes to skip when doing an
26989 alignment. */
26990 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26991 {
26992 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26993 {
26994 if (stretch < 0)
26995 stretch = - ((- stretch)
26996 & ~ ((1 << (int) f->fr_offset) - 1));
26997 else
26998 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26999 if (stretch == 0)
27000 break;
27001 }
27002 }
27003 if (f != NULL)
27004 addr += stretch;
27005 }
5e77afaa
PB
27006
27007 return addr;
27008}
27009
0110f2b8
PB
27010/* Return the size of a relaxable adr pseudo-instruction or PC-relative
27011 load. */
27012static int
5e77afaa 27013relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
27014{
27015 addressT addr;
27016 offsetT val;
27017
27018 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
27019 if (fragp->fr_symbol == NULL
27020 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27021 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27022 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27023 return 4;
27024
5f4273c7 27025 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27026 addr = fragp->fr_address + fragp->fr_fix;
27027 addr = (addr + 4) & ~3;
5e77afaa 27028 /* Force misaligned targets to 32-bit variant. */
0110f2b8 27029 if (val & 3)
5e77afaa 27030 return 4;
0110f2b8
PB
27031 val -= addr;
27032 if (val < 0 || val > 1020)
27033 return 4;
27034 return 2;
27035}
27036
27037/* Return the size of a relaxable add/sub immediate instruction. */
27038static int
27039relax_addsub (fragS *fragp, asection *sec)
27040{
27041 char *buf;
27042 int op;
27043
27044 buf = fragp->fr_literal + fragp->fr_fix;
27045 op = bfd_get_16(sec->owner, buf);
27046 if ((op & 0xf) == ((op >> 4) & 0xf))
27047 return relax_immediate (fragp, 8, 0);
27048 else
27049 return relax_immediate (fragp, 3, 0);
27050}
27051
e83a675f
RE
27052/* Return TRUE iff the definition of symbol S could be pre-empted
27053 (overridden) at link or load time. */
27054static bfd_boolean
27055symbol_preemptible (symbolS *s)
27056{
27057 /* Weak symbols can always be pre-empted. */
27058 if (S_IS_WEAK (s))
27059 return TRUE;
27060
27061 /* Non-global symbols cannot be pre-empted. */
27062 if (! S_IS_EXTERNAL (s))
27063 return FALSE;
27064
27065#ifdef OBJ_ELF
27066 /* In ELF, a global symbol can be marked protected, or private. In that
27067 case it can't be pre-empted (other definitions in the same link unit
27068 would violate the ODR). */
27069 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27070 return FALSE;
27071#endif
27072
27073 /* Other global symbols might be pre-empted. */
27074 return TRUE;
27075}
0110f2b8
PB
27076
27077/* Return the size of a relaxable branch instruction. BITS is the
27078 size of the offset field in the narrow instruction. */
27079
27080static int
5e77afaa 27081relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
27082{
27083 addressT addr;
27084 offsetT val;
27085 offsetT limit;
27086
27087 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 27088 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27089 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27090 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27091 return 4;
27092
267bf995 27093#ifdef OBJ_ELF
e83a675f 27094 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
27095 if (S_IS_DEFINED (fragp->fr_symbol)
27096 && ARM_IS_FUNC (fragp->fr_symbol))
27097 return 4;
e83a675f 27098#endif
0d9b4b55 27099
e83a675f 27100 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 27101 return 4;
267bf995 27102
5f4273c7 27103 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27104 addr = fragp->fr_address + fragp->fr_fix + 4;
27105 val -= addr;
27106
27107 /* Offset is a signed value *2 */
27108 limit = 1 << bits;
27109 if (val >= limit || val < -limit)
27110 return 4;
27111 return 2;
27112}
27113
27114
27115/* Relax a machine dependent frag. This returns the amount by which
27116 the current size of the frag should change. */
27117
27118int
5e77afaa 27119arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
27120{
27121 int oldsize;
27122 int newsize;
27123
27124 oldsize = fragp->fr_var;
27125 switch (fragp->fr_subtype)
27126 {
27127 case T_MNEM_ldr_pc2:
5f4273c7 27128 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27129 break;
27130 case T_MNEM_ldr_pc:
27131 case T_MNEM_ldr_sp:
27132 case T_MNEM_str_sp:
5f4273c7 27133 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
27134 break;
27135 case T_MNEM_ldr:
27136 case T_MNEM_str:
5f4273c7 27137 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
27138 break;
27139 case T_MNEM_ldrh:
27140 case T_MNEM_strh:
5f4273c7 27141 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
27142 break;
27143 case T_MNEM_ldrb:
27144 case T_MNEM_strb:
5f4273c7 27145 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
27146 break;
27147 case T_MNEM_adr:
5f4273c7 27148 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27149 break;
27150 case T_MNEM_mov:
27151 case T_MNEM_movs:
27152 case T_MNEM_cmp:
27153 case T_MNEM_cmn:
5f4273c7 27154 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
27155 break;
27156 case T_MNEM_b:
5f4273c7 27157 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
27158 break;
27159 case T_MNEM_bcond:
5f4273c7 27160 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
27161 break;
27162 case T_MNEM_add_sp:
27163 case T_MNEM_add_pc:
27164 newsize = relax_immediate (fragp, 8, 2);
27165 break;
27166 case T_MNEM_inc_sp:
27167 case T_MNEM_dec_sp:
27168 newsize = relax_immediate (fragp, 7, 2);
27169 break;
27170 case T_MNEM_addi:
27171 case T_MNEM_addis:
27172 case T_MNEM_subi:
27173 case T_MNEM_subis:
27174 newsize = relax_addsub (fragp, sec);
27175 break;
27176 default:
5f4273c7 27177 abort ();
0110f2b8 27178 }
5e77afaa
PB
27179
27180 fragp->fr_var = newsize;
27181 /* Freeze wide instructions that are at or before the same location as
27182 in the previous pass. This avoids infinite loops.
5f4273c7
NC
27183 Don't freeze them unconditionally because targets may be artificially
27184 misaligned by the expansion of preceding frags. */
5e77afaa 27185 if (stretch <= 0 && newsize > 2)
0110f2b8 27186 {
0110f2b8 27187 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 27188 frag_wane (fragp);
0110f2b8 27189 }
5e77afaa 27190
0110f2b8 27191 return newsize - oldsize;
c19d1205 27192}
b99bd4ef 27193
c19d1205 27194/* Round up a section size to the appropriate boundary. */
b99bd4ef 27195
c19d1205
ZW
27196valueT
27197md_section_align (segT segment ATTRIBUTE_UNUSED,
27198 valueT size)
27199{
6844c0cc 27200 return size;
bfae80f2 27201}
b99bd4ef 27202
c19d1205
ZW
27203/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27204 of an rs_align_code fragment. */
27205
27206void
27207arm_handle_align (fragS * fragP)
bfae80f2 27208{
d9235011 27209 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
27210 {
27211 { /* ARMv1 */
27212 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27213 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27214 },
27215 { /* ARMv6k */
27216 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27217 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27218 },
27219 };
d9235011 27220 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
27221 {
27222 { /* Thumb-1 */
27223 {0xc0, 0x46}, /* LE */
27224 {0x46, 0xc0}, /* BE */
27225 },
27226 { /* Thumb-2 */
27227 {0x00, 0xbf}, /* LE */
27228 {0xbf, 0x00} /* BE */
27229 }
27230 };
d9235011 27231 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
27232 { /* Wide Thumb-2 */
27233 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27234 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27235 };
c921be7d 27236
e7495e45 27237 unsigned bytes, fix, noop_size;
c19d1205 27238 char * p;
d9235011
TS
27239 const unsigned char * noop;
27240 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
27241#ifdef OBJ_ELF
27242 enum mstate state;
27243#endif
bfae80f2 27244
c19d1205 27245 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
27246 return;
27247
c19d1205
ZW
27248 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27249 p = fragP->fr_literal + fragP->fr_fix;
27250 fix = 0;
bfae80f2 27251
c19d1205
ZW
27252 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27253 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 27254
cd000bff 27255 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 27256
cd000bff 27257 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 27258 {
7f78eb34
JW
27259 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27260 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
27261 {
27262 narrow_noop = thumb_noop[1][target_big_endian];
27263 noop = wide_thumb_noop[target_big_endian];
27264 }
c19d1205 27265 else
e7495e45
NS
27266 noop = thumb_noop[0][target_big_endian];
27267 noop_size = 2;
cd000bff
DJ
27268#ifdef OBJ_ELF
27269 state = MAP_THUMB;
27270#endif
7ed4c4c5
NC
27271 }
27272 else
27273 {
7f78eb34
JW
27274 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27275 ? selected_cpu : arm_arch_none,
27276 arm_ext_v6k) != 0]
e7495e45
NS
27277 [target_big_endian];
27278 noop_size = 4;
cd000bff
DJ
27279#ifdef OBJ_ELF
27280 state = MAP_ARM;
27281#endif
7ed4c4c5 27282 }
c921be7d 27283
e7495e45 27284 fragP->fr_var = noop_size;
c921be7d 27285
c19d1205 27286 if (bytes & (noop_size - 1))
7ed4c4c5 27287 {
c19d1205 27288 fix = bytes & (noop_size - 1);
cd000bff
DJ
27289#ifdef OBJ_ELF
27290 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27291#endif
c19d1205
ZW
27292 memset (p, 0, fix);
27293 p += fix;
27294 bytes -= fix;
a737bd4d 27295 }
a737bd4d 27296
e7495e45
NS
27297 if (narrow_noop)
27298 {
27299 if (bytes & noop_size)
27300 {
27301 /* Insert a narrow noop. */
27302 memcpy (p, narrow_noop, noop_size);
27303 p += noop_size;
27304 bytes -= noop_size;
27305 fix += noop_size;
27306 }
27307
27308 /* Use wide noops for the remainder */
27309 noop_size = 4;
27310 }
27311
c19d1205 27312 while (bytes >= noop_size)
a737bd4d 27313 {
c19d1205
ZW
27314 memcpy (p, noop, noop_size);
27315 p += noop_size;
27316 bytes -= noop_size;
27317 fix += noop_size;
a737bd4d
NC
27318 }
27319
c19d1205 27320 fragP->fr_fix += fix;
a737bd4d
NC
27321}
27322
c19d1205
ZW
27323/* Called from md_do_align. Used to create an alignment
27324 frag in a code section. */
27325
27326void
27327arm_frag_align_code (int n, int max)
bfae80f2 27328{
c19d1205 27329 char * p;
7ed4c4c5 27330
c19d1205 27331 /* We assume that there will never be a requirement
6ec8e702 27332 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 27333 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
27334 {
27335 char err_msg[128];
27336
fa94de6b 27337 sprintf (err_msg,
477330fc
RM
27338 _("alignments greater than %d bytes not supported in .text sections."),
27339 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 27340 as_fatal ("%s", err_msg);
6ec8e702 27341 }
bfae80f2 27342
c19d1205
ZW
27343 p = frag_var (rs_align_code,
27344 MAX_MEM_FOR_RS_ALIGN_CODE,
27345 1,
27346 (relax_substateT) max,
27347 (symbolS *) NULL,
27348 (offsetT) n,
27349 (char *) NULL);
27350 *p = 0;
27351}
bfae80f2 27352
8dc2430f
NC
27353/* Perform target specific initialisation of a frag.
27354 Note - despite the name this initialisation is not done when the frag
27355 is created, but only when its type is assigned. A frag can be created
27356 and used a long time before its type is set, so beware of assuming that
33eaf5de 27357 this initialisation is performed first. */
bfae80f2 27358
cd000bff
DJ
27359#ifndef OBJ_ELF
27360void
27361arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27362{
27363 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 27364 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
27365}
27366
27367#else /* OBJ_ELF is defined. */
c19d1205 27368void
cd000bff 27369arm_init_frag (fragS * fragP, int max_chars)
c19d1205 27370{
e8d84ca1 27371 bfd_boolean frag_thumb_mode;
b968d18a 27372
8dc2430f
NC
27373 /* If the current ARM vs THUMB mode has not already
27374 been recorded into this frag then do so now. */
cd000bff 27375 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
27376 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27377
e8d84ca1
NC
27378 /* PR 21809: Do not set a mapping state for debug sections
27379 - it just confuses other tools. */
fd361982 27380 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
e8d84ca1
NC
27381 return;
27382
b968d18a 27383 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 27384
f9c1b181
RL
27385 /* Record a mapping symbol for alignment frags. We will delete this
27386 later if the alignment ends up empty. */
27387 switch (fragP->fr_type)
27388 {
27389 case rs_align:
27390 case rs_align_test:
27391 case rs_fill:
27392 mapping_state_2 (MAP_DATA, max_chars);
27393 break;
27394 case rs_align_code:
b968d18a 27395 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
27396 break;
27397 default:
27398 break;
cd000bff 27399 }
bfae80f2
RE
27400}
27401
c19d1205
ZW
27402/* When we change sections we need to issue a new mapping symbol. */
27403
27404void
27405arm_elf_change_section (void)
bfae80f2 27406{
c19d1205
ZW
27407 /* Link an unlinked unwind index table section to the .text section. */
27408 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27409 && elf_linked_to_section (now_seg) == NULL)
27410 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
27411}
27412
c19d1205
ZW
27413int
27414arm_elf_section_type (const char * str, size_t len)
e45d0630 27415{
c19d1205
ZW
27416 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27417 return SHT_ARM_EXIDX;
e45d0630 27418
c19d1205
ZW
27419 return -1;
27420}
27421\f
27422/* Code to deal with unwinding tables. */
e45d0630 27423
c19d1205 27424static void add_unwind_adjustsp (offsetT);
e45d0630 27425
5f4273c7 27426/* Generate any deferred unwind frame offset. */
e45d0630 27427
bfae80f2 27428static void
c19d1205 27429flush_pending_unwind (void)
bfae80f2 27430{
c19d1205 27431 offsetT offset;
bfae80f2 27432
c19d1205
ZW
27433 offset = unwind.pending_offset;
27434 unwind.pending_offset = 0;
27435 if (offset != 0)
27436 add_unwind_adjustsp (offset);
bfae80f2
RE
27437}
27438
c19d1205
ZW
27439/* Add an opcode to this list for this function. Two-byte opcodes should
27440 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27441 order. */
27442
bfae80f2 27443static void
c19d1205 27444add_unwind_opcode (valueT op, int length)
bfae80f2 27445{
c19d1205
ZW
27446 /* Add any deferred stack adjustment. */
27447 if (unwind.pending_offset)
27448 flush_pending_unwind ();
bfae80f2 27449
c19d1205 27450 unwind.sp_restored = 0;
bfae80f2 27451
c19d1205 27452 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 27453 {
c19d1205
ZW
27454 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27455 if (unwind.opcodes)
325801bd
TS
27456 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27457 unwind.opcode_alloc);
c19d1205 27458 else
325801bd 27459 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 27460 }
c19d1205 27461 while (length > 0)
bfae80f2 27462 {
c19d1205
ZW
27463 length--;
27464 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27465 op >>= 8;
27466 unwind.opcode_count++;
bfae80f2 27467 }
bfae80f2
RE
27468}
27469
c19d1205
ZW
27470/* Add unwind opcodes to adjust the stack pointer. */
27471
bfae80f2 27472static void
c19d1205 27473add_unwind_adjustsp (offsetT offset)
bfae80f2 27474{
c19d1205 27475 valueT op;
bfae80f2 27476
c19d1205 27477 if (offset > 0x200)
bfae80f2 27478 {
c19d1205
ZW
27479 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27480 char bytes[5];
27481 int n;
27482 valueT o;
bfae80f2 27483
c19d1205
ZW
27484 /* Long form: 0xb2, uleb128. */
27485 /* This might not fit in a word so add the individual bytes,
27486 remembering the list is built in reverse order. */
27487 o = (valueT) ((offset - 0x204) >> 2);
27488 if (o == 0)
27489 add_unwind_opcode (0, 1);
bfae80f2 27490
c19d1205
ZW
27491 /* Calculate the uleb128 encoding of the offset. */
27492 n = 0;
27493 while (o)
27494 {
27495 bytes[n] = o & 0x7f;
27496 o >>= 7;
27497 if (o)
27498 bytes[n] |= 0x80;
27499 n++;
27500 }
27501 /* Add the insn. */
27502 for (; n; n--)
27503 add_unwind_opcode (bytes[n - 1], 1);
27504 add_unwind_opcode (0xb2, 1);
27505 }
27506 else if (offset > 0x100)
bfae80f2 27507 {
c19d1205
ZW
27508 /* Two short opcodes. */
27509 add_unwind_opcode (0x3f, 1);
27510 op = (offset - 0x104) >> 2;
27511 add_unwind_opcode (op, 1);
bfae80f2 27512 }
c19d1205
ZW
27513 else if (offset > 0)
27514 {
27515 /* Short opcode. */
27516 op = (offset - 4) >> 2;
27517 add_unwind_opcode (op, 1);
27518 }
27519 else if (offset < 0)
bfae80f2 27520 {
c19d1205
ZW
27521 offset = -offset;
27522 while (offset > 0x100)
bfae80f2 27523 {
c19d1205
ZW
27524 add_unwind_opcode (0x7f, 1);
27525 offset -= 0x100;
bfae80f2 27526 }
c19d1205
ZW
27527 op = ((offset - 4) >> 2) | 0x40;
27528 add_unwind_opcode (op, 1);
bfae80f2 27529 }
bfae80f2
RE
27530}
27531
c19d1205 27532/* Finish the list of unwind opcodes for this function. */
0198d5e6 27533
c19d1205
ZW
27534static void
27535finish_unwind_opcodes (void)
bfae80f2 27536{
c19d1205 27537 valueT op;
bfae80f2 27538
c19d1205 27539 if (unwind.fp_used)
bfae80f2 27540 {
708587a4 27541 /* Adjust sp as necessary. */
c19d1205
ZW
27542 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27543 flush_pending_unwind ();
bfae80f2 27544
c19d1205
ZW
27545 /* After restoring sp from the frame pointer. */
27546 op = 0x90 | unwind.fp_reg;
27547 add_unwind_opcode (op, 1);
27548 }
27549 else
27550 flush_pending_unwind ();
bfae80f2
RE
27551}
27552
bfae80f2 27553
c19d1205
ZW
27554/* Start an exception table entry. If idx is nonzero this is an index table
27555 entry. */
bfae80f2
RE
27556
27557static void
c19d1205 27558start_unwind_section (const segT text_seg, int idx)
bfae80f2 27559{
c19d1205
ZW
27560 const char * text_name;
27561 const char * prefix;
27562 const char * prefix_once;
a8c4d40b 27563 struct elf_section_match match;
c19d1205 27564 char * sec_name;
c19d1205
ZW
27565 int type;
27566 int flags;
27567 int linkonce;
bfae80f2 27568
c19d1205 27569 if (idx)
bfae80f2 27570 {
c19d1205
ZW
27571 prefix = ELF_STRING_ARM_unwind;
27572 prefix_once = ELF_STRING_ARM_unwind_once;
27573 type = SHT_ARM_EXIDX;
bfae80f2 27574 }
c19d1205 27575 else
bfae80f2 27576 {
c19d1205
ZW
27577 prefix = ELF_STRING_ARM_unwind_info;
27578 prefix_once = ELF_STRING_ARM_unwind_info_once;
27579 type = SHT_PROGBITS;
bfae80f2
RE
27580 }
27581
c19d1205
ZW
27582 text_name = segment_name (text_seg);
27583 if (streq (text_name, ".text"))
27584 text_name = "";
27585
27586 if (strncmp (text_name, ".gnu.linkonce.t.",
27587 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 27588 {
c19d1205
ZW
27589 prefix = prefix_once;
27590 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
27591 }
27592
29a2809e 27593 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 27594
c19d1205
ZW
27595 flags = SHF_ALLOC;
27596 linkonce = 0;
a8c4d40b 27597 memset (&match, 0, sizeof (match));
bfae80f2 27598
c19d1205
ZW
27599 /* Handle COMDAT group. */
27600 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 27601 {
a8c4d40b
L
27602 match.group_name = elf_group_name (text_seg);
27603 if (match.group_name == NULL)
c19d1205 27604 {
bd3ba5d1 27605 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
27606 segment_name (text_seg));
27607 ignore_rest_of_line ();
27608 return;
27609 }
27610 flags |= SHF_GROUP;
27611 linkonce = 1;
bfae80f2
RE
27612 }
27613
a8c4d40b 27614 obj_elf_change_section (sec_name, type, flags, 0, &match,
a91e1603 27615 linkonce, 0);
bfae80f2 27616
5f4273c7 27617 /* Set the section link for index tables. */
c19d1205
ZW
27618 if (idx)
27619 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
27620}
27621
bfae80f2 27622
c19d1205
ZW
27623/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27624 personality routine data. Returns zero, or the index table value for
cad0da33 27625 an inline entry. */
c19d1205
ZW
27626
27627static valueT
27628create_unwind_entry (int have_data)
bfae80f2 27629{
c19d1205
ZW
27630 int size;
27631 addressT where;
27632 char *ptr;
27633 /* The current word of data. */
27634 valueT data;
27635 /* The number of bytes left in this word. */
27636 int n;
bfae80f2 27637
c19d1205 27638 finish_unwind_opcodes ();
bfae80f2 27639
c19d1205
ZW
27640 /* Remember the current text section. */
27641 unwind.saved_seg = now_seg;
27642 unwind.saved_subseg = now_subseg;
bfae80f2 27643
c19d1205 27644 start_unwind_section (now_seg, 0);
bfae80f2 27645
c19d1205 27646 if (unwind.personality_routine == NULL)
bfae80f2 27647 {
c19d1205
ZW
27648 if (unwind.personality_index == -2)
27649 {
27650 if (have_data)
5f4273c7 27651 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
27652 return 1; /* EXIDX_CANTUNWIND. */
27653 }
bfae80f2 27654
c19d1205
ZW
27655 /* Use a default personality routine if none is specified. */
27656 if (unwind.personality_index == -1)
27657 {
27658 if (unwind.opcode_count > 3)
27659 unwind.personality_index = 1;
27660 else
27661 unwind.personality_index = 0;
27662 }
bfae80f2 27663
c19d1205
ZW
27664 /* Space for the personality routine entry. */
27665 if (unwind.personality_index == 0)
27666 {
27667 if (unwind.opcode_count > 3)
27668 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 27669
c19d1205
ZW
27670 if (!have_data)
27671 {
27672 /* All the data is inline in the index table. */
27673 data = 0x80;
27674 n = 3;
27675 while (unwind.opcode_count > 0)
27676 {
27677 unwind.opcode_count--;
27678 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27679 n--;
27680 }
bfae80f2 27681
c19d1205
ZW
27682 /* Pad with "finish" opcodes. */
27683 while (n--)
27684 data = (data << 8) | 0xb0;
bfae80f2 27685
c19d1205
ZW
27686 return data;
27687 }
27688 size = 0;
27689 }
27690 else
27691 /* We get two opcodes "free" in the first word. */
27692 size = unwind.opcode_count - 2;
27693 }
27694 else
5011093d 27695 {
cad0da33
NC
27696 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27697 if (unwind.personality_index != -1)
27698 {
27699 as_bad (_("attempt to recreate an unwind entry"));
27700 return 1;
27701 }
5011093d
NC
27702
27703 /* An extra byte is required for the opcode count. */
27704 size = unwind.opcode_count + 1;
27705 }
bfae80f2 27706
c19d1205
ZW
27707 size = (size + 3) >> 2;
27708 if (size > 0xff)
27709 as_bad (_("too many unwind opcodes"));
bfae80f2 27710
c19d1205
ZW
27711 frag_align (2, 0, 0);
27712 record_alignment (now_seg, 2);
27713 unwind.table_entry = expr_build_dot ();
27714
27715 /* Allocate the table entry. */
27716 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
27717 /* PR 13449: Zero the table entries in case some of them are not used. */
27718 memset (ptr, 0, (size << 2) + 4);
c19d1205 27719 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 27720
c19d1205 27721 switch (unwind.personality_index)
bfae80f2 27722 {
c19d1205
ZW
27723 case -1:
27724 /* ??? Should this be a PLT generating relocation? */
27725 /* Custom personality routine. */
27726 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27727 BFD_RELOC_ARM_PREL31);
bfae80f2 27728
c19d1205
ZW
27729 where += 4;
27730 ptr += 4;
bfae80f2 27731
c19d1205 27732 /* Set the first byte to the number of additional words. */
5011093d 27733 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
27734 n = 3;
27735 break;
bfae80f2 27736
c19d1205
ZW
27737 /* ABI defined personality routines. */
27738 case 0:
27739 /* Three opcodes bytes are packed into the first word. */
27740 data = 0x80;
27741 n = 3;
27742 break;
bfae80f2 27743
c19d1205
ZW
27744 case 1:
27745 case 2:
27746 /* The size and first two opcode bytes go in the first word. */
27747 data = ((0x80 + unwind.personality_index) << 8) | size;
27748 n = 2;
27749 break;
bfae80f2 27750
c19d1205
ZW
27751 default:
27752 /* Should never happen. */
27753 abort ();
27754 }
bfae80f2 27755
c19d1205
ZW
27756 /* Pack the opcodes into words (MSB first), reversing the list at the same
27757 time. */
27758 while (unwind.opcode_count > 0)
27759 {
27760 if (n == 0)
27761 {
27762 md_number_to_chars (ptr, data, 4);
27763 ptr += 4;
27764 n = 4;
27765 data = 0;
27766 }
27767 unwind.opcode_count--;
27768 n--;
27769 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27770 }
27771
27772 /* Finish off the last word. */
27773 if (n < 4)
27774 {
27775 /* Pad with "finish" opcodes. */
27776 while (n--)
27777 data = (data << 8) | 0xb0;
27778
27779 md_number_to_chars (ptr, data, 4);
27780 }
27781
27782 if (!have_data)
27783 {
27784 /* Add an empty descriptor if there is no user-specified data. */
27785 ptr = frag_more (4);
27786 md_number_to_chars (ptr, 0, 4);
27787 }
27788
27789 return 0;
bfae80f2
RE
27790}
27791
f0927246
NC
27792
27793/* Initialize the DWARF-2 unwind information for this procedure. */
27794
27795void
27796tc_arm_frame_initial_instructions (void)
27797{
27798 cfi_add_CFA_def_cfa (REG_SP, 0);
27799}
27800#endif /* OBJ_ELF */
27801
c19d1205
ZW
27802/* Convert REGNAME to a DWARF-2 register number. */
27803
27804int
1df69f4f 27805tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 27806{
1df69f4f 27807 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
27808 if (reg != FAIL)
27809 return reg;
c19d1205 27810
1f5afe1c
NC
27811 /* PR 16694: Allow VFP registers as well. */
27812 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27813 if (reg != FAIL)
27814 return 64 + reg;
c19d1205 27815
1f5afe1c
NC
27816 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27817 if (reg != FAIL)
27818 return reg + 256;
27819
0198d5e6 27820 return FAIL;
bfae80f2
RE
27821}
27822
f0927246 27823#ifdef TE_PE
c19d1205 27824void
f0927246 27825tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 27826{
91d6fa6a 27827 expressionS exp;
bfae80f2 27828
91d6fa6a
NC
27829 exp.X_op = O_secrel;
27830 exp.X_add_symbol = symbol;
27831 exp.X_add_number = 0;
27832 emit_expr (&exp, size);
f0927246
NC
27833}
27834#endif
bfae80f2 27835
c19d1205 27836/* MD interface: Symbol and relocation handling. */
bfae80f2 27837
2fc8bdac
ZW
27838/* Return the address within the segment that a PC-relative fixup is
27839 relative to. For ARM, PC-relative fixups applied to instructions
27840 are generally relative to the location of the fixup plus 8 bytes.
27841 Thumb branches are offset by 4, and Thumb loads relative to PC
27842 require special handling. */
bfae80f2 27843
c19d1205 27844long
2fc8bdac 27845md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 27846{
2fc8bdac
ZW
27847 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27848
27849 /* If this is pc-relative and we are going to emit a relocation
27850 then we just want to put out any pipeline compensation that the linker
53baae48
NC
27851 will need. Otherwise we want to use the calculated base.
27852 For WinCE we skip the bias for externals as well, since this
27853 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 27854 if (fixP->fx_pcrel
2fc8bdac 27855 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
27856 || (arm_force_relocation (fixP)
27857#ifdef TE_WINCE
27858 && !S_IS_EXTERNAL (fixP->fx_addsy)
27859#endif
27860 )))
2fc8bdac 27861 base = 0;
bfae80f2 27862
267bf995 27863
c19d1205 27864 switch (fixP->fx_r_type)
bfae80f2 27865 {
2fc8bdac
ZW
27866 /* PC relative addressing on the Thumb is slightly odd as the
27867 bottom two bits of the PC are forced to zero for the
27868 calculation. This happens *after* application of the
27869 pipeline offset. However, Thumb adrl already adjusts for
27870 this, so we need not do it again. */
c19d1205 27871 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 27872 return base & ~3;
c19d1205
ZW
27873
27874 case BFD_RELOC_ARM_THUMB_OFFSET:
27875 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 27876 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 27877 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 27878 return (base + 4) & ~3;
c19d1205 27879
2fc8bdac 27880 /* Thumb branches are simply offset by +4. */
e12437dc 27881 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
27882 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27883 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27884 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27885 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 27886 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 27887 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 27888 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 27889 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 27890 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 27891 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 27892 return base + 4;
bfae80f2 27893
267bf995 27894 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
27895 if (fixP->fx_addsy
27896 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27897 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 27898 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
27899 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27900 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
27901 return base + 4;
27902
00adf2d4
JB
27903 /* BLX is like branches above, but forces the low two bits of PC to
27904 zero. */
486499d0
CL
27905 case BFD_RELOC_THUMB_PCREL_BLX:
27906 if (fixP->fx_addsy
27907 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27908 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27909 && THUMB_IS_FUNC (fixP->fx_addsy)
27910 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27911 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
27912 return (base + 4) & ~3;
27913
2fc8bdac
ZW
27914 /* ARM mode branches are offset by +8. However, the Windows CE
27915 loader expects the relocation not to take this into account. */
267bf995 27916 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
27917 if (fixP->fx_addsy
27918 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27919 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27920 && ARM_IS_FUNC (fixP->fx_addsy)
27921 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27922 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27923 return base + 8;
267bf995 27924
486499d0
CL
27925 case BFD_RELOC_ARM_PCREL_CALL:
27926 if (fixP->fx_addsy
27927 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27928 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27929 && THUMB_IS_FUNC (fixP->fx_addsy)
27930 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27931 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27932 return base + 8;
267bf995 27933
2fc8bdac 27934 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 27935 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 27936 case BFD_RELOC_ARM_PLT32:
c19d1205 27937#ifdef TE_WINCE
5f4273c7 27938 /* When handling fixups immediately, because we have already
477330fc 27939 discovered the value of a symbol, or the address of the frag involved
53baae48 27940 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
27941 see fixup_segment() in write.c
27942 The S_IS_EXTERNAL test handles the case of global symbols.
27943 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
27944 if (fixP->fx_pcrel
27945 && fixP->fx_addsy != NULL
27946 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27947 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27948 return base + 8;
2fc8bdac 27949 return base;
c19d1205 27950#else
2fc8bdac 27951 return base + 8;
c19d1205 27952#endif
2fc8bdac 27953
267bf995 27954
2fc8bdac
ZW
27955 /* ARM mode loads relative to PC are also offset by +8. Unlike
27956 branches, the Windows CE loader *does* expect the relocation
27957 to take this into account. */
27958 case BFD_RELOC_ARM_OFFSET_IMM:
27959 case BFD_RELOC_ARM_OFFSET_IMM8:
27960 case BFD_RELOC_ARM_HWLITERAL:
27961 case BFD_RELOC_ARM_LITERAL:
27962 case BFD_RELOC_ARM_CP_OFF_IMM:
27963 return base + 8;
27964
27965
27966 /* Other PC-relative relocations are un-offset. */
27967 default:
27968 return base;
27969 }
bfae80f2
RE
27970}
27971
8b2d793c
NC
27972static bfd_boolean flag_warn_syms = TRUE;
27973
ae8714c2
NC
27974bfd_boolean
27975arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27976{
8b2d793c
NC
27977 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27978 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27979 does mean that the resulting code might be very confusing to the reader.
27980 Also this warning can be triggered if the user omits an operand before
27981 an immediate address, eg:
27982
27983 LDR =foo
27984
27985 GAS treats this as an assignment of the value of the symbol foo to a
27986 symbol LDR, and so (without this code) it will not issue any kind of
27987 warning or error message.
27988
27989 Note - ARM instructions are case-insensitive but the strings in the hash
27990 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27991 lower case too. */
27992 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27993 {
27994 char * nbuf = strdup (name);
27995 char * p;
27996
27997 for (p = nbuf; *p; p++)
27998 *p = TOLOWER (*p);
27999 if (hash_find (arm_ops_hsh, nbuf) != NULL)
28000 {
28001 static struct hash_control * already_warned = NULL;
28002
28003 if (already_warned == NULL)
28004 already_warned = hash_new ();
28005 /* Only warn about the symbol once. To keep the code
28006 simple we let hash_insert do the lookup for us. */
3076e594 28007 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 28008 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
28009 }
28010 else
28011 free (nbuf);
28012 }
3739860c 28013
ae8714c2
NC
28014 return FALSE;
28015}
28016
28017/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28018 Otherwise we have no need to default values of symbols. */
28019
28020symbolS *
28021md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28022{
28023#ifdef OBJ_ELF
28024 if (name[0] == '_' && name[1] == 'G'
28025 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28026 {
28027 if (!GOT_symbol)
28028 {
28029 if (symbol_find (name))
28030 as_bad (_("GOT already in the symbol table"));
28031
28032 GOT_symbol = symbol_new (name, undefined_section,
28033 (valueT) 0, & zero_address_frag);
28034 }
28035
28036 return GOT_symbol;
28037 }
28038#endif
28039
c921be7d 28040 return NULL;
bfae80f2
RE
28041}
28042
55cf6793 28043/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
28044 computed as two separate immediate values, added together. We
28045 already know that this value cannot be computed by just one ARM
28046 instruction. */
28047
28048static unsigned int
28049validate_immediate_twopart (unsigned int val,
28050 unsigned int * highpart)
bfae80f2 28051{
c19d1205
ZW
28052 unsigned int a;
28053 unsigned int i;
bfae80f2 28054
c19d1205
ZW
28055 for (i = 0; i < 32; i += 2)
28056 if (((a = rotate_left (val, i)) & 0xff) != 0)
28057 {
28058 if (a & 0xff00)
28059 {
28060 if (a & ~ 0xffff)
28061 continue;
28062 * highpart = (a >> 8) | ((i + 24) << 7);
28063 }
28064 else if (a & 0xff0000)
28065 {
28066 if (a & 0xff000000)
28067 continue;
28068 * highpart = (a >> 16) | ((i + 16) << 7);
28069 }
28070 else
28071 {
9c2799c2 28072 gas_assert (a & 0xff000000);
c19d1205
ZW
28073 * highpart = (a >> 24) | ((i + 8) << 7);
28074 }
bfae80f2 28075
c19d1205
ZW
28076 return (a & 0xff) | (i << 7);
28077 }
bfae80f2 28078
c19d1205 28079 return FAIL;
bfae80f2
RE
28080}
28081
c19d1205
ZW
28082static int
28083validate_offset_imm (unsigned int val, int hwse)
28084{
28085 if ((hwse && val > 255) || val > 4095)
28086 return FAIL;
28087 return val;
28088}
bfae80f2 28089
55cf6793 28090/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
28091 negative immediate constant by altering the instruction. A bit of
28092 a hack really.
28093 MOV <-> MVN
28094 AND <-> BIC
28095 ADC <-> SBC
28096 by inverting the second operand, and
28097 ADD <-> SUB
28098 CMP <-> CMN
28099 by negating the second operand. */
bfae80f2 28100
c19d1205
ZW
28101static int
28102negate_data_op (unsigned long * instruction,
28103 unsigned long value)
bfae80f2 28104{
c19d1205
ZW
28105 int op, new_inst;
28106 unsigned long negated, inverted;
bfae80f2 28107
c19d1205
ZW
28108 negated = encode_arm_immediate (-value);
28109 inverted = encode_arm_immediate (~value);
bfae80f2 28110
c19d1205
ZW
28111 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28112 switch (op)
bfae80f2 28113 {
c19d1205
ZW
28114 /* First negates. */
28115 case OPCODE_SUB: /* ADD <-> SUB */
28116 new_inst = OPCODE_ADD;
28117 value = negated;
28118 break;
bfae80f2 28119
c19d1205
ZW
28120 case OPCODE_ADD:
28121 new_inst = OPCODE_SUB;
28122 value = negated;
28123 break;
bfae80f2 28124
c19d1205
ZW
28125 case OPCODE_CMP: /* CMP <-> CMN */
28126 new_inst = OPCODE_CMN;
28127 value = negated;
28128 break;
bfae80f2 28129
c19d1205
ZW
28130 case OPCODE_CMN:
28131 new_inst = OPCODE_CMP;
28132 value = negated;
28133 break;
bfae80f2 28134
c19d1205
ZW
28135 /* Now Inverted ops. */
28136 case OPCODE_MOV: /* MOV <-> MVN */
28137 new_inst = OPCODE_MVN;
28138 value = inverted;
28139 break;
bfae80f2 28140
c19d1205
ZW
28141 case OPCODE_MVN:
28142 new_inst = OPCODE_MOV;
28143 value = inverted;
28144 break;
bfae80f2 28145
c19d1205
ZW
28146 case OPCODE_AND: /* AND <-> BIC */
28147 new_inst = OPCODE_BIC;
28148 value = inverted;
28149 break;
bfae80f2 28150
c19d1205
ZW
28151 case OPCODE_BIC:
28152 new_inst = OPCODE_AND;
28153 value = inverted;
28154 break;
bfae80f2 28155
c19d1205
ZW
28156 case OPCODE_ADC: /* ADC <-> SBC */
28157 new_inst = OPCODE_SBC;
28158 value = inverted;
28159 break;
bfae80f2 28160
c19d1205
ZW
28161 case OPCODE_SBC:
28162 new_inst = OPCODE_ADC;
28163 value = inverted;
28164 break;
bfae80f2 28165
c19d1205
ZW
28166 /* We cannot do anything. */
28167 default:
28168 return FAIL;
b99bd4ef
NC
28169 }
28170
c19d1205
ZW
28171 if (value == (unsigned) FAIL)
28172 return FAIL;
28173
28174 *instruction &= OPCODE_MASK;
28175 *instruction |= new_inst << DATA_OP_SHIFT;
28176 return value;
b99bd4ef
NC
28177}
28178
ef8d22e6
PB
28179/* Like negate_data_op, but for Thumb-2. */
28180
28181static unsigned int
16dd5e42 28182thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
28183{
28184 int op, new_inst;
28185 int rd;
16dd5e42 28186 unsigned int negated, inverted;
ef8d22e6
PB
28187
28188 negated = encode_thumb32_immediate (-value);
28189 inverted = encode_thumb32_immediate (~value);
28190
28191 rd = (*instruction >> 8) & 0xf;
28192 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28193 switch (op)
28194 {
28195 /* ADD <-> SUB. Includes CMP <-> CMN. */
28196 case T2_OPCODE_SUB:
28197 new_inst = T2_OPCODE_ADD;
28198 value = negated;
28199 break;
28200
28201 case T2_OPCODE_ADD:
28202 new_inst = T2_OPCODE_SUB;
28203 value = negated;
28204 break;
28205
28206 /* ORR <-> ORN. Includes MOV <-> MVN. */
28207 case T2_OPCODE_ORR:
28208 new_inst = T2_OPCODE_ORN;
28209 value = inverted;
28210 break;
28211
28212 case T2_OPCODE_ORN:
28213 new_inst = T2_OPCODE_ORR;
28214 value = inverted;
28215 break;
28216
28217 /* AND <-> BIC. TST has no inverted equivalent. */
28218 case T2_OPCODE_AND:
28219 new_inst = T2_OPCODE_BIC;
28220 if (rd == 15)
28221 value = FAIL;
28222 else
28223 value = inverted;
28224 break;
28225
28226 case T2_OPCODE_BIC:
28227 new_inst = T2_OPCODE_AND;
28228 value = inverted;
28229 break;
28230
28231 /* ADC <-> SBC */
28232 case T2_OPCODE_ADC:
28233 new_inst = T2_OPCODE_SBC;
28234 value = inverted;
28235 break;
28236
28237 case T2_OPCODE_SBC:
28238 new_inst = T2_OPCODE_ADC;
28239 value = inverted;
28240 break;
28241
28242 /* We cannot do anything. */
28243 default:
28244 return FAIL;
28245 }
28246
16dd5e42 28247 if (value == (unsigned int)FAIL)
ef8d22e6
PB
28248 return FAIL;
28249
28250 *instruction &= T2_OPCODE_MASK;
28251 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28252 return value;
28253}
28254
8f06b2d8 28255/* Read a 32-bit thumb instruction from buf. */
0198d5e6 28256
8f06b2d8
PB
28257static unsigned long
28258get_thumb32_insn (char * buf)
28259{
28260 unsigned long insn;
28261 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28262 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28263
28264 return insn;
28265}
28266
a8bc6c78
PB
28267/* We usually want to set the low bit on the address of thumb function
28268 symbols. In particular .word foo - . should have the low bit set.
28269 Generic code tries to fold the difference of two symbols to
28270 a constant. Prevent this and force a relocation when the first symbols
28271 is a thumb function. */
c921be7d
NC
28272
28273bfd_boolean
a8bc6c78
PB
28274arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28275{
28276 if (op == O_subtract
28277 && l->X_op == O_symbol
28278 && r->X_op == O_symbol
28279 && THUMB_IS_FUNC (l->X_add_symbol))
28280 {
28281 l->X_op = O_subtract;
28282 l->X_op_symbol = r->X_add_symbol;
28283 l->X_add_number -= r->X_add_number;
c921be7d 28284 return TRUE;
a8bc6c78 28285 }
c921be7d 28286
a8bc6c78 28287 /* Process as normal. */
c921be7d 28288 return FALSE;
a8bc6c78
PB
28289}
28290
4a42ebbc
RR
28291/* Encode Thumb2 unconditional branches and calls. The encoding
28292 for the 2 are identical for the immediate values. */
28293
28294static void
28295encode_thumb2_b_bl_offset (char * buf, offsetT value)
28296{
28297#define T2I1I2MASK ((1 << 13) | (1 << 11))
28298 offsetT newval;
28299 offsetT newval2;
28300 addressT S, I1, I2, lo, hi;
28301
28302 S = (value >> 24) & 0x01;
28303 I1 = (value >> 23) & 0x01;
28304 I2 = (value >> 22) & 0x01;
28305 hi = (value >> 12) & 0x3ff;
fa94de6b 28306 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
28307 newval = md_chars_to_number (buf, THUMB_SIZE);
28308 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28309 newval |= (S << 10) | hi;
28310 newval2 &= ~T2I1I2MASK;
28311 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28312 md_number_to_chars (buf, newval, THUMB_SIZE);
28313 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28314}
28315
c19d1205 28316void
55cf6793 28317md_apply_fix (fixS * fixP,
c19d1205
ZW
28318 valueT * valP,
28319 segT seg)
28320{
28321 offsetT value = * valP;
28322 offsetT newval;
28323 unsigned int newimm;
28324 unsigned long temp;
28325 int sign;
28326 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 28327
9c2799c2 28328 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 28329
c19d1205 28330 /* Note whether this will delete the relocation. */
4962c51a 28331
c19d1205
ZW
28332 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28333 fixP->fx_done = 1;
b99bd4ef 28334
adbaf948 28335 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 28336 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
28337 for emit_reloc. */
28338 value &= 0xffffffff;
28339 value ^= 0x80000000;
5f4273c7 28340 value -= 0x80000000;
adbaf948
ZW
28341
28342 *valP = value;
c19d1205 28343 fixP->fx_addnumber = value;
b99bd4ef 28344
adbaf948
ZW
28345 /* Same treatment for fixP->fx_offset. */
28346 fixP->fx_offset &= 0xffffffff;
28347 fixP->fx_offset ^= 0x80000000;
28348 fixP->fx_offset -= 0x80000000;
28349
c19d1205 28350 switch (fixP->fx_r_type)
b99bd4ef 28351 {
c19d1205
ZW
28352 case BFD_RELOC_NONE:
28353 /* This will need to go in the object file. */
28354 fixP->fx_done = 0;
28355 break;
b99bd4ef 28356
c19d1205
ZW
28357 case BFD_RELOC_ARM_IMMEDIATE:
28358 /* We claim that this fixup has been processed here,
28359 even if in fact we generate an error because we do
28360 not have a reloc for it, so tc_gen_reloc will reject it. */
28361 fixP->fx_done = 1;
b99bd4ef 28362
77db8e2e 28363 if (fixP->fx_addsy)
b99bd4ef 28364 {
77db8e2e 28365 const char *msg = 0;
b99bd4ef 28366
77db8e2e
NC
28367 if (! S_IS_DEFINED (fixP->fx_addsy))
28368 msg = _("undefined symbol %s used as an immediate value");
28369 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28370 msg = _("symbol %s is in a different section");
28371 else if (S_IS_WEAK (fixP->fx_addsy))
28372 msg = _("symbol %s is weak and may be overridden later");
28373
28374 if (msg)
28375 {
28376 as_bad_where (fixP->fx_file, fixP->fx_line,
28377 msg, S_GET_NAME (fixP->fx_addsy));
28378 break;
28379 }
42e5fcbf
AS
28380 }
28381
c19d1205
ZW
28382 temp = md_chars_to_number (buf, INSN_SIZE);
28383
5e73442d
SL
28384 /* If the offset is negative, we should use encoding A2 for ADR. */
28385 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
28386 newimm = negate_data_op (&temp, value);
28387 else
28388 {
28389 newimm = encode_arm_immediate (value);
28390
28391 /* If the instruction will fail, see if we can fix things up by
28392 changing the opcode. */
28393 if (newimm == (unsigned int) FAIL)
28394 newimm = negate_data_op (&temp, value);
bada4342
JW
28395 /* MOV accepts both ARM modified immediate (A1 encoding) and
28396 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28397 When disassembling, MOV is preferred when there is no encoding
28398 overlap. */
28399 if (newimm == (unsigned int) FAIL
28400 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28401 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28402 && !((temp >> SBIT_SHIFT) & 0x1)
28403 && value >= 0 && value <= 0xffff)
28404 {
28405 /* Clear bits[23:20] to change encoding from A1 to A2. */
28406 temp &= 0xff0fffff;
28407 /* Encoding high 4bits imm. Code below will encode the remaining
28408 low 12bits. */
28409 temp |= (value & 0x0000f000) << 4;
28410 newimm = value & 0x00000fff;
28411 }
5e73442d
SL
28412 }
28413
28414 if (newimm == (unsigned int) FAIL)
b99bd4ef 28415 {
c19d1205
ZW
28416 as_bad_where (fixP->fx_file, fixP->fx_line,
28417 _("invalid constant (%lx) after fixup"),
28418 (unsigned long) value);
28419 break;
b99bd4ef 28420 }
b99bd4ef 28421
c19d1205
ZW
28422 newimm |= (temp & 0xfffff000);
28423 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28424 break;
b99bd4ef 28425
c19d1205
ZW
28426 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28427 {
28428 unsigned int highpart = 0;
28429 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 28430
77db8e2e 28431 if (fixP->fx_addsy)
42e5fcbf 28432 {
77db8e2e 28433 const char *msg = 0;
42e5fcbf 28434
77db8e2e
NC
28435 if (! S_IS_DEFINED (fixP->fx_addsy))
28436 msg = _("undefined symbol %s used as an immediate value");
28437 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28438 msg = _("symbol %s is in a different section");
28439 else if (S_IS_WEAK (fixP->fx_addsy))
28440 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 28441
77db8e2e
NC
28442 if (msg)
28443 {
28444 as_bad_where (fixP->fx_file, fixP->fx_line,
28445 msg, S_GET_NAME (fixP->fx_addsy));
28446 break;
28447 }
28448 }
fa94de6b 28449
c19d1205
ZW
28450 newimm = encode_arm_immediate (value);
28451 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 28452
c19d1205
ZW
28453 /* If the instruction will fail, see if we can fix things up by
28454 changing the opcode. */
28455 if (newimm == (unsigned int) FAIL
28456 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28457 {
28458 /* No ? OK - try using two ADD instructions to generate
28459 the value. */
28460 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 28461
c19d1205
ZW
28462 /* Yes - then make sure that the second instruction is
28463 also an add. */
28464 if (newimm != (unsigned int) FAIL)
28465 newinsn = temp;
28466 /* Still No ? Try using a negated value. */
28467 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28468 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28469 /* Otherwise - give up. */
28470 else
28471 {
28472 as_bad_where (fixP->fx_file, fixP->fx_line,
28473 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28474 (long) value);
28475 break;
28476 }
b99bd4ef 28477
c19d1205
ZW
28478 /* Replace the first operand in the 2nd instruction (which
28479 is the PC) with the destination register. We have
28480 already added in the PC in the first instruction and we
28481 do not want to do it again. */
28482 newinsn &= ~ 0xf0000;
28483 newinsn |= ((newinsn & 0x0f000) << 4);
28484 }
b99bd4ef 28485
c19d1205
ZW
28486 newimm |= (temp & 0xfffff000);
28487 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 28488
c19d1205
ZW
28489 highpart |= (newinsn & 0xfffff000);
28490 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28491 }
28492 break;
b99bd4ef 28493
c19d1205 28494 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
28495 if (!fixP->fx_done && seg->use_rela_p)
28496 value = 0;
1a0670f3 28497 /* Fall through. */
00a97672 28498
c19d1205 28499 case BFD_RELOC_ARM_LITERAL:
26d97720 28500 sign = value > 0;
b99bd4ef 28501
c19d1205
ZW
28502 if (value < 0)
28503 value = - value;
b99bd4ef 28504
c19d1205 28505 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 28506 {
c19d1205
ZW
28507 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28508 as_bad_where (fixP->fx_file, fixP->fx_line,
28509 _("invalid literal constant: pool needs to be closer"));
28510 else
28511 as_bad_where (fixP->fx_file, fixP->fx_line,
28512 _("bad immediate value for offset (%ld)"),
28513 (long) value);
28514 break;
f03698e6
RE
28515 }
28516
c19d1205 28517 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28518 if (value == 0)
28519 newval &= 0xfffff000;
28520 else
28521 {
28522 newval &= 0xff7ff000;
28523 newval |= value | (sign ? INDEX_UP : 0);
28524 }
c19d1205
ZW
28525 md_number_to_chars (buf, newval, INSN_SIZE);
28526 break;
b99bd4ef 28527
c19d1205
ZW
28528 case BFD_RELOC_ARM_OFFSET_IMM8:
28529 case BFD_RELOC_ARM_HWLITERAL:
26d97720 28530 sign = value > 0;
b99bd4ef 28531
c19d1205
ZW
28532 if (value < 0)
28533 value = - value;
b99bd4ef 28534
c19d1205 28535 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 28536 {
c19d1205
ZW
28537 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28538 as_bad_where (fixP->fx_file, fixP->fx_line,
28539 _("invalid literal constant: pool needs to be closer"));
28540 else
427d0db6
RM
28541 as_bad_where (fixP->fx_file, fixP->fx_line,
28542 _("bad immediate value for 8-bit offset (%ld)"),
28543 (long) value);
c19d1205 28544 break;
b99bd4ef
NC
28545 }
28546
c19d1205 28547 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28548 if (value == 0)
28549 newval &= 0xfffff0f0;
28550 else
28551 {
28552 newval &= 0xff7ff0f0;
28553 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28554 }
c19d1205
ZW
28555 md_number_to_chars (buf, newval, INSN_SIZE);
28556 break;
b99bd4ef 28557
c19d1205
ZW
28558 case BFD_RELOC_ARM_T32_OFFSET_U8:
28559 if (value < 0 || value > 1020 || value % 4 != 0)
28560 as_bad_where (fixP->fx_file, fixP->fx_line,
28561 _("bad immediate value for offset (%ld)"), (long) value);
28562 value /= 4;
b99bd4ef 28563
c19d1205 28564 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
28565 newval |= value;
28566 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28567 break;
b99bd4ef 28568
c19d1205
ZW
28569 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28570 /* This is a complicated relocation used for all varieties of Thumb32
28571 load/store instruction with immediate offset:
28572
28573 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 28574 *4, optional writeback(W)
c19d1205
ZW
28575 (doubleword load/store)
28576
28577 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28578 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28579 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28580 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28581 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28582
28583 Uppercase letters indicate bits that are already encoded at
28584 this point. Lowercase letters are our problem. For the
28585 second block of instructions, the secondary opcode nybble
28586 (bits 8..11) is present, and bit 23 is zero, even if this is
28587 a PC-relative operation. */
28588 newval = md_chars_to_number (buf, THUMB_SIZE);
28589 newval <<= 16;
28590 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 28591
c19d1205 28592 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 28593 {
c19d1205
ZW
28594 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28595 if (value >= 0)
28596 newval |= (1 << 23);
28597 else
28598 value = -value;
28599 if (value % 4 != 0)
28600 {
28601 as_bad_where (fixP->fx_file, fixP->fx_line,
28602 _("offset not a multiple of 4"));
28603 break;
28604 }
28605 value /= 4;
216d22bc 28606 if (value > 0xff)
c19d1205
ZW
28607 {
28608 as_bad_where (fixP->fx_file, fixP->fx_line,
28609 _("offset out of range"));
28610 break;
28611 }
28612 newval &= ~0xff;
b99bd4ef 28613 }
c19d1205 28614 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 28615 {
c19d1205
ZW
28616 /* PC-relative, 12-bit offset. */
28617 if (value >= 0)
28618 newval |= (1 << 23);
28619 else
28620 value = -value;
216d22bc 28621 if (value > 0xfff)
c19d1205
ZW
28622 {
28623 as_bad_where (fixP->fx_file, fixP->fx_line,
28624 _("offset out of range"));
28625 break;
28626 }
28627 newval &= ~0xfff;
b99bd4ef 28628 }
c19d1205 28629 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 28630 {
c19d1205
ZW
28631 /* Writeback: 8-bit, +/- offset. */
28632 if (value >= 0)
28633 newval |= (1 << 9);
28634 else
28635 value = -value;
216d22bc 28636 if (value > 0xff)
c19d1205
ZW
28637 {
28638 as_bad_where (fixP->fx_file, fixP->fx_line,
28639 _("offset out of range"));
28640 break;
28641 }
28642 newval &= ~0xff;
b99bd4ef 28643 }
c19d1205 28644 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 28645 {
c19d1205 28646 /* T-instruction: positive 8-bit offset. */
216d22bc 28647 if (value < 0 || value > 0xff)
b99bd4ef 28648 {
c19d1205
ZW
28649 as_bad_where (fixP->fx_file, fixP->fx_line,
28650 _("offset out of range"));
28651 break;
b99bd4ef 28652 }
c19d1205
ZW
28653 newval &= ~0xff;
28654 newval |= value;
b99bd4ef
NC
28655 }
28656 else
b99bd4ef 28657 {
c19d1205
ZW
28658 /* Positive 12-bit or negative 8-bit offset. */
28659 int limit;
28660 if (value >= 0)
b99bd4ef 28661 {
c19d1205
ZW
28662 newval |= (1 << 23);
28663 limit = 0xfff;
28664 }
28665 else
28666 {
28667 value = -value;
28668 limit = 0xff;
28669 }
28670 if (value > limit)
28671 {
28672 as_bad_where (fixP->fx_file, fixP->fx_line,
28673 _("offset out of range"));
28674 break;
b99bd4ef 28675 }
c19d1205 28676 newval &= ~limit;
b99bd4ef 28677 }
b99bd4ef 28678
c19d1205
ZW
28679 newval |= value;
28680 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28681 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28682 break;
404ff6b5 28683
c19d1205
ZW
28684 case BFD_RELOC_ARM_SHIFT_IMM:
28685 newval = md_chars_to_number (buf, INSN_SIZE);
28686 if (((unsigned long) value) > 32
28687 || (value == 32
28688 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28689 {
28690 as_bad_where (fixP->fx_file, fixP->fx_line,
28691 _("shift expression is too large"));
28692 break;
28693 }
404ff6b5 28694
c19d1205
ZW
28695 if (value == 0)
28696 /* Shifts of zero must be done as lsl. */
28697 newval &= ~0x60;
28698 else if (value == 32)
28699 value = 0;
28700 newval &= 0xfffff07f;
28701 newval |= (value & 0x1f) << 7;
28702 md_number_to_chars (buf, newval, INSN_SIZE);
28703 break;
404ff6b5 28704
c19d1205 28705 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 28706 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 28707 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 28708 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
28709 /* We claim that this fixup has been processed here,
28710 even if in fact we generate an error because we do
28711 not have a reloc for it, so tc_gen_reloc will reject it. */
28712 fixP->fx_done = 1;
404ff6b5 28713
c19d1205
ZW
28714 if (fixP->fx_addsy
28715 && ! S_IS_DEFINED (fixP->fx_addsy))
28716 {
28717 as_bad_where (fixP->fx_file, fixP->fx_line,
28718 _("undefined symbol %s used as an immediate value"),
28719 S_GET_NAME (fixP->fx_addsy));
28720 break;
28721 }
404ff6b5 28722
c19d1205
ZW
28723 newval = md_chars_to_number (buf, THUMB_SIZE);
28724 newval <<= 16;
28725 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 28726
16805f35 28727 newimm = FAIL;
bada4342
JW
28728 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28729 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28730 Thumb2 modified immediate encoding (T2). */
28731 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 28732 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
28733 {
28734 newimm = encode_thumb32_immediate (value);
28735 if (newimm == (unsigned int) FAIL)
28736 newimm = thumb32_negate_data_op (&newval, value);
28737 }
bada4342 28738 if (newimm == (unsigned int) FAIL)
92e90b6e 28739 {
bada4342 28740 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 28741 {
bada4342
JW
28742 /* Turn add/sum into addw/subw. */
28743 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28744 newval = (newval & 0xfeffffff) | 0x02000000;
28745 /* No flat 12-bit imm encoding for addsw/subsw. */
28746 if ((newval & 0x00100000) == 0)
40f246e3 28747 {
bada4342
JW
28748 /* 12 bit immediate for addw/subw. */
28749 if (value < 0)
28750 {
28751 value = -value;
28752 newval ^= 0x00a00000;
28753 }
28754 if (value > 0xfff)
28755 newimm = (unsigned int) FAIL;
28756 else
28757 newimm = value;
28758 }
28759 }
28760 else
28761 {
28762 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28763 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28764 disassembling, MOV is preferred when there is no encoding
db7bf105 28765 overlap. */
bada4342 28766 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
28767 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28768 but with the Rn field [19:16] set to 1111. */
28769 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
28770 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28771 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 28772 && value >= 0 && value <= 0xffff)
bada4342
JW
28773 {
28774 /* Toggle bit[25] to change encoding from T2 to T3. */
28775 newval ^= 1 << 25;
28776 /* Clear bits[19:16]. */
28777 newval &= 0xfff0ffff;
28778 /* Encoding high 4bits imm. Code below will encode the
28779 remaining low 12bits. */
28780 newval |= (value & 0x0000f000) << 4;
28781 newimm = value & 0x00000fff;
40f246e3 28782 }
e9f89963 28783 }
92e90b6e 28784 }
cc8a6dd0 28785
c19d1205 28786 if (newimm == (unsigned int)FAIL)
3631a3c8 28787 {
c19d1205
ZW
28788 as_bad_where (fixP->fx_file, fixP->fx_line,
28789 _("invalid constant (%lx) after fixup"),
28790 (unsigned long) value);
28791 break;
3631a3c8
NC
28792 }
28793
c19d1205
ZW
28794 newval |= (newimm & 0x800) << 15;
28795 newval |= (newimm & 0x700) << 4;
28796 newval |= (newimm & 0x0ff);
cc8a6dd0 28797
c19d1205
ZW
28798 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28799 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28800 break;
a737bd4d 28801
3eb17e6b 28802 case BFD_RELOC_ARM_SMC:
ba85f98c 28803 if (((unsigned long) value) > 0xf)
c19d1205 28804 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 28805 _("invalid smc expression"));
ba85f98c 28806
2fc8bdac 28807 newval = md_chars_to_number (buf, INSN_SIZE);
ba85f98c 28808 newval |= (value & 0xf);
c19d1205
ZW
28809 md_number_to_chars (buf, newval, INSN_SIZE);
28810 break;
a737bd4d 28811
90ec0d68
MGD
28812 case BFD_RELOC_ARM_HVC:
28813 if (((unsigned long) value) > 0xffff)
28814 as_bad_where (fixP->fx_file, fixP->fx_line,
28815 _("invalid hvc expression"));
28816 newval = md_chars_to_number (buf, INSN_SIZE);
28817 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28818 md_number_to_chars (buf, newval, INSN_SIZE);
28819 break;
28820
c19d1205 28821 case BFD_RELOC_ARM_SWI:
adbaf948 28822 if (fixP->tc_fix_data != 0)
c19d1205
ZW
28823 {
28824 if (((unsigned long) value) > 0xff)
28825 as_bad_where (fixP->fx_file, fixP->fx_line,
28826 _("invalid swi expression"));
2fc8bdac 28827 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
28828 newval |= value;
28829 md_number_to_chars (buf, newval, THUMB_SIZE);
28830 }
28831 else
28832 {
28833 if (((unsigned long) value) > 0x00ffffff)
28834 as_bad_where (fixP->fx_file, fixP->fx_line,
28835 _("invalid swi expression"));
2fc8bdac 28836 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
28837 newval |= value;
28838 md_number_to_chars (buf, newval, INSN_SIZE);
28839 }
28840 break;
a737bd4d 28841
c19d1205
ZW
28842 case BFD_RELOC_ARM_MULTI:
28843 if (((unsigned long) value) > 0xffff)
28844 as_bad_where (fixP->fx_file, fixP->fx_line,
28845 _("invalid expression in load/store multiple"));
28846 newval = value | md_chars_to_number (buf, INSN_SIZE);
28847 md_number_to_chars (buf, newval, INSN_SIZE);
28848 break;
a737bd4d 28849
c19d1205 28850#ifdef OBJ_ELF
39b41c9c 28851 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
28852
28853 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28854 && fixP->fx_addsy
34e77a92 28855 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28857 && THUMB_IS_FUNC (fixP->fx_addsy))
28858 /* Flip the bl to blx. This is a simple flip
28859 bit here because we generate PCREL_CALL for
28860 unconditional bls. */
28861 {
28862 newval = md_chars_to_number (buf, INSN_SIZE);
28863 newval = newval | 0x10000000;
28864 md_number_to_chars (buf, newval, INSN_SIZE);
28865 temp = 1;
28866 fixP->fx_done = 1;
28867 }
39b41c9c
PB
28868 else
28869 temp = 3;
28870 goto arm_branch_common;
28871
28872 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
28873 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28874 && fixP->fx_addsy
34e77a92 28875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28877 && THUMB_IS_FUNC (fixP->fx_addsy))
28878 {
28879 /* This would map to a bl<cond>, b<cond>,
28880 b<always> to a Thumb function. We
28881 need to force a relocation for this particular
28882 case. */
28883 newval = md_chars_to_number (buf, INSN_SIZE);
28884 fixP->fx_done = 0;
28885 }
1a0670f3 28886 /* Fall through. */
267bf995 28887
2fc8bdac 28888 case BFD_RELOC_ARM_PLT32:
c19d1205 28889#endif
39b41c9c
PB
28890 case BFD_RELOC_ARM_PCREL_BRANCH:
28891 temp = 3;
28892 goto arm_branch_common;
a737bd4d 28893
39b41c9c 28894 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 28895
39b41c9c 28896 temp = 1;
267bf995
RR
28897 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28898 && fixP->fx_addsy
34e77a92 28899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28901 && ARM_IS_FUNC (fixP->fx_addsy))
28902 {
28903 /* Flip the blx to a bl and warn. */
28904 const char *name = S_GET_NAME (fixP->fx_addsy);
28905 newval = 0xeb000000;
28906 as_warn_where (fixP->fx_file, fixP->fx_line,
28907 _("blx to '%s' an ARM ISA state function changed to bl"),
28908 name);
28909 md_number_to_chars (buf, newval, INSN_SIZE);
28910 temp = 3;
28911 fixP->fx_done = 1;
28912 }
28913
28914#ifdef OBJ_ELF
28915 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 28916 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
28917#endif
28918
39b41c9c 28919 arm_branch_common:
c19d1205 28920 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
28921 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28922 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 28923 also be clear. */
39b41c9c 28924 if (value & temp)
c19d1205 28925 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
28926 _("misaligned branch destination"));
28927 if ((value & (offsetT)0xfe000000) != (offsetT)0
28928 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 28929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28930
2fc8bdac 28931 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28932 {
2fc8bdac
ZW
28933 newval = md_chars_to_number (buf, INSN_SIZE);
28934 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
28935 /* Set the H bit on BLX instructions. */
28936 if (temp == 1)
28937 {
28938 if (value & 2)
28939 newval |= 0x01000000;
28940 else
28941 newval &= ~0x01000000;
28942 }
2fc8bdac 28943 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 28944 }
c19d1205 28945 break;
a737bd4d 28946
25fe350b
MS
28947 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28948 /* CBZ can only branch forward. */
a737bd4d 28949
738755b0 28950 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
28951 (which, strictly speaking, are prohibited) will be turned into
28952 no-ops.
738755b0
MS
28953
28954 FIXME: It may be better to remove the instruction completely and
28955 perform relaxation. */
28956 if (value == -2)
2fc8bdac
ZW
28957 {
28958 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 28959 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
28960 md_number_to_chars (buf, newval, THUMB_SIZE);
28961 }
738755b0
MS
28962 else
28963 {
28964 if (value & ~0x7e)
08f10d51 28965 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 28966
477330fc 28967 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
28968 {
28969 newval = md_chars_to_number (buf, THUMB_SIZE);
28970 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28971 md_number_to_chars (buf, newval, THUMB_SIZE);
28972 }
28973 }
c19d1205 28974 break;
a737bd4d 28975
c19d1205 28976 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
e8f8842d 28977 if (out_of_range_p (value, 8))
08f10d51 28978 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28979
2fc8bdac
ZW
28980 if (fixP->fx_done || !seg->use_rela_p)
28981 {
28982 newval = md_chars_to_number (buf, THUMB_SIZE);
28983 newval |= (value & 0x1ff) >> 1;
28984 md_number_to_chars (buf, newval, THUMB_SIZE);
28985 }
c19d1205 28986 break;
a737bd4d 28987
c19d1205 28988 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
e8f8842d 28989 if (out_of_range_p (value, 11))
08f10d51 28990 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28991
2fc8bdac
ZW
28992 if (fixP->fx_done || !seg->use_rela_p)
28993 {
28994 newval = md_chars_to_number (buf, THUMB_SIZE);
28995 newval |= (value & 0xfff) >> 1;
28996 md_number_to_chars (buf, newval, THUMB_SIZE);
28997 }
c19d1205 28998 break;
a737bd4d 28999
e8f8842d 29000 /* This relocation is misnamed, it should be BRANCH21. */
c19d1205 29001 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
29002 if (fixP->fx_addsy
29003 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 29004 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29005 && ARM_IS_FUNC (fixP->fx_addsy)
29006 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29007 {
29008 /* Force a relocation for a branch 20 bits wide. */
29009 fixP->fx_done = 0;
29010 }
e8f8842d 29011 if (out_of_range_p (value, 20))
2fc8bdac
ZW
29012 as_bad_where (fixP->fx_file, fixP->fx_line,
29013 _("conditional branch out of range"));
404ff6b5 29014
2fc8bdac
ZW
29015 if (fixP->fx_done || !seg->use_rela_p)
29016 {
29017 offsetT newval2;
29018 addressT S, J1, J2, lo, hi;
404ff6b5 29019
2fc8bdac
ZW
29020 S = (value & 0x00100000) >> 20;
29021 J2 = (value & 0x00080000) >> 19;
29022 J1 = (value & 0x00040000) >> 18;
29023 hi = (value & 0x0003f000) >> 12;
29024 lo = (value & 0x00000ffe) >> 1;
6c43fab6 29025
2fc8bdac
ZW
29026 newval = md_chars_to_number (buf, THUMB_SIZE);
29027 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29028 newval |= (S << 10) | hi;
29029 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29030 md_number_to_chars (buf, newval, THUMB_SIZE);
29031 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29032 }
c19d1205 29033 break;
6c43fab6 29034
c19d1205 29035 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
29036 /* If there is a blx from a thumb state function to
29037 another thumb function flip this to a bl and warn
29038 about it. */
29039
29040 if (fixP->fx_addsy
34e77a92 29041 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29043 && THUMB_IS_FUNC (fixP->fx_addsy))
29044 {
29045 const char *name = S_GET_NAME (fixP->fx_addsy);
29046 as_warn_where (fixP->fx_file, fixP->fx_line,
29047 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29048 name);
29049 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29050 newval = newval | 0x1000;
29051 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29052 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29053 fixP->fx_done = 1;
29054 }
29055
29056
29057 goto thumb_bl_common;
29058
c19d1205 29059 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
29060 /* A bl from Thumb state ISA to an internal ARM state function
29061 is converted to a blx. */
29062 if (fixP->fx_addsy
29063 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 29064 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29065 && ARM_IS_FUNC (fixP->fx_addsy)
29066 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29067 {
29068 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29069 newval = newval & ~0x1000;
29070 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29071 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29072 fixP->fx_done = 1;
29073 }
29074
29075 thumb_bl_common:
29076
2fc8bdac
ZW
29077 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29078 /* For a BLX instruction, make sure that the relocation is rounded up
29079 to a word boundary. This follows the semantics of the instruction
29080 which specifies that bit 1 of the target address will come from bit
29081 1 of the base address. */
d406f3e4
JB
29082 value = (value + 3) & ~ 3;
29083
29084#ifdef OBJ_ELF
29085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29086 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29087 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29088#endif
404ff6b5 29089
e8f8842d 29090 if (out_of_range_p (value, 22))
2b2f5df9 29091 {
fc289b0a 29092 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9 29093 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
e8f8842d 29094 else if (out_of_range_p (value, 24))
2b2f5df9
NC
29095 as_bad_where (fixP->fx_file, fixP->fx_line,
29096 _("Thumb2 branch out of range"));
29097 }
4a42ebbc
RR
29098
29099 if (fixP->fx_done || !seg->use_rela_p)
29100 encode_thumb2_b_bl_offset (buf, value);
29101
c19d1205 29102 break;
404ff6b5 29103
c19d1205 29104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
e8f8842d 29105 if (out_of_range_p (value, 24))
08f10d51 29106 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 29107
2fc8bdac 29108 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 29109 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 29110
2fc8bdac 29111 break;
a737bd4d 29112
2fc8bdac
ZW
29113 case BFD_RELOC_8:
29114 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 29115 *buf = value;
c19d1205 29116 break;
a737bd4d 29117
c19d1205 29118 case BFD_RELOC_16:
2fc8bdac 29119 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 29120 md_number_to_chars (buf, value, 2);
c19d1205 29121 break;
a737bd4d 29122
c19d1205 29123#ifdef OBJ_ELF
0855e32b
NS
29124 case BFD_RELOC_ARM_TLS_CALL:
29125 case BFD_RELOC_ARM_THM_TLS_CALL:
29126 case BFD_RELOC_ARM_TLS_DESCSEQ:
29127 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 29128 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
29129 case BFD_RELOC_ARM_TLS_GD32:
29130 case BFD_RELOC_ARM_TLS_LE32:
29131 case BFD_RELOC_ARM_TLS_IE32:
29132 case BFD_RELOC_ARM_TLS_LDM32:
29133 case BFD_RELOC_ARM_TLS_LDO32:
29134 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 29135 break;
6c43fab6 29136
5c5a4843
CL
29137 /* Same handling as above, but with the arm_fdpic guard. */
29138 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29139 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29140 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29141 if (arm_fdpic)
29142 {
29143 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29144 }
29145 else
29146 {
29147 as_bad_where (fixP->fx_file, fixP->fx_line,
29148 _("Relocation supported only in FDPIC mode"));
29149 }
29150 break;
29151
c19d1205
ZW
29152 case BFD_RELOC_ARM_GOT32:
29153 case BFD_RELOC_ARM_GOTOFF:
c19d1205 29154 break;
b43420e6
NC
29155
29156 case BFD_RELOC_ARM_GOT_PREL:
29157 if (fixP->fx_done || !seg->use_rela_p)
477330fc 29158 md_number_to_chars (buf, value, 4);
b43420e6
NC
29159 break;
29160
9a6f4e97
NS
29161 case BFD_RELOC_ARM_TARGET2:
29162 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
29163 addend here for REL targets, because it won't be written out
29164 during reloc processing later. */
9a6f4e97
NS
29165 if (fixP->fx_done || !seg->use_rela_p)
29166 md_number_to_chars (buf, fixP->fx_offset, 4);
29167 break;
188fd7ae
CL
29168
29169 /* Relocations for FDPIC. */
29170 case BFD_RELOC_ARM_GOTFUNCDESC:
29171 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29172 case BFD_RELOC_ARM_FUNCDESC:
29173 if (arm_fdpic)
29174 {
29175 if (fixP->fx_done || !seg->use_rela_p)
29176 md_number_to_chars (buf, 0, 4);
29177 }
29178 else
29179 {
29180 as_bad_where (fixP->fx_file, fixP->fx_line,
29181 _("Relocation supported only in FDPIC mode"));
29182 }
29183 break;
c19d1205 29184#endif
6c43fab6 29185
c19d1205
ZW
29186 case BFD_RELOC_RVA:
29187 case BFD_RELOC_32:
29188 case BFD_RELOC_ARM_TARGET1:
29189 case BFD_RELOC_ARM_ROSEGREL32:
29190 case BFD_RELOC_ARM_SBREL32:
29191 case BFD_RELOC_32_PCREL:
f0927246
NC
29192#ifdef TE_PE
29193 case BFD_RELOC_32_SECREL:
29194#endif
2fc8bdac 29195 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
29196#ifdef TE_WINCE
29197 /* For WinCE we only do this for pcrel fixups. */
29198 if (fixP->fx_done || fixP->fx_pcrel)
29199#endif
29200 md_number_to_chars (buf, value, 4);
c19d1205 29201 break;
6c43fab6 29202
c19d1205
ZW
29203#ifdef OBJ_ELF
29204 case BFD_RELOC_ARM_PREL31:
2fc8bdac 29205 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
29206 {
29207 newval = md_chars_to_number (buf, 4) & 0x80000000;
29208 if ((value ^ (value >> 1)) & 0x40000000)
29209 {
29210 as_bad_where (fixP->fx_file, fixP->fx_line,
29211 _("rel31 relocation overflow"));
29212 }
29213 newval |= value & 0x7fffffff;
29214 md_number_to_chars (buf, newval, 4);
29215 }
29216 break;
c19d1205 29217#endif
a737bd4d 29218
c19d1205 29219 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 29220 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 29221 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
29222 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29223 newval = md_chars_to_number (buf, INSN_SIZE);
29224 else
29225 newval = get_thumb32_insn (buf);
29226 if ((newval & 0x0f200f00) == 0x0d000900)
29227 {
29228 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
29229 has permitted values that are multiples of 2, in the range 0
29230 to 510. */
29231 if (value < -510 || value > 510 || (value & 1))
29232 as_bad_where (fixP->fx_file, fixP->fx_line,
29233 _("co-processor offset out of range"));
29234 }
32c36c3c
AV
29235 else if ((newval & 0xfe001f80) == 0xec000f80)
29236 {
29237 if (value < -511 || value > 512 || (value & 3))
29238 as_bad_where (fixP->fx_file, fixP->fx_line,
29239 _("co-processor offset out of range"));
29240 }
9db2f6b4 29241 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
29242 as_bad_where (fixP->fx_file, fixP->fx_line,
29243 _("co-processor offset out of range"));
29244 cp_off_common:
26d97720 29245 sign = value > 0;
c19d1205
ZW
29246 if (value < 0)
29247 value = -value;
8f06b2d8
PB
29248 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29249 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29250 newval = md_chars_to_number (buf, INSN_SIZE);
29251 else
29252 newval = get_thumb32_insn (buf);
26d97720 29253 if (value == 0)
32c36c3c
AV
29254 {
29255 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29256 newval &= 0xffffff80;
29257 else
29258 newval &= 0xffffff00;
29259 }
26d97720
NS
29260 else
29261 {
32c36c3c
AV
29262 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29263 newval &= 0xff7fff80;
29264 else
29265 newval &= 0xff7fff00;
9db2f6b4
RL
29266 if ((newval & 0x0f200f00) == 0x0d000900)
29267 {
29268 /* This is a fp16 vstr/vldr.
29269
29270 It requires the immediate offset in the instruction is shifted
29271 left by 1 to be a half-word offset.
29272
29273 Here, left shift by 1 first, and later right shift by 2
29274 should get the right offset. */
29275 value <<= 1;
29276 }
26d97720
NS
29277 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29278 }
8f06b2d8
PB
29279 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29280 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29281 md_number_to_chars (buf, newval, INSN_SIZE);
29282 else
29283 put_thumb32_insn (buf, newval);
c19d1205 29284 break;
a737bd4d 29285
c19d1205 29286 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 29287 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
29288 if (value < -255 || value > 255)
29289 as_bad_where (fixP->fx_file, fixP->fx_line,
29290 _("co-processor offset out of range"));
df7849c5 29291 value *= 4;
c19d1205 29292 goto cp_off_common;
6c43fab6 29293
c19d1205
ZW
29294 case BFD_RELOC_ARM_THUMB_OFFSET:
29295 newval = md_chars_to_number (buf, THUMB_SIZE);
29296 /* Exactly what ranges, and where the offset is inserted depends
29297 on the type of instruction, we can establish this from the
29298 top 4 bits. */
29299 switch (newval >> 12)
29300 {
29301 case 4: /* PC load. */
29302 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29303 forced to zero for these loads; md_pcrel_from has already
29304 compensated for this. */
29305 if (value & 3)
29306 as_bad_where (fixP->fx_file, fixP->fx_line,
29307 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
29308 (((unsigned long) fixP->fx_frag->fr_address
29309 + (unsigned long) fixP->fx_where) & ~3)
29310 + (unsigned long) value);
a737bd4d 29311
c19d1205
ZW
29312 if (value & ~0x3fc)
29313 as_bad_where (fixP->fx_file, fixP->fx_line,
29314 _("invalid offset, value too big (0x%08lX)"),
29315 (long) value);
a737bd4d 29316
c19d1205
ZW
29317 newval |= value >> 2;
29318 break;
a737bd4d 29319
c19d1205
ZW
29320 case 9: /* SP load/store. */
29321 if (value & ~0x3fc)
29322 as_bad_where (fixP->fx_file, fixP->fx_line,
29323 _("invalid offset, value too big (0x%08lX)"),
29324 (long) value);
29325 newval |= value >> 2;
29326 break;
6c43fab6 29327
c19d1205
ZW
29328 case 6: /* Word load/store. */
29329 if (value & ~0x7c)
29330 as_bad_where (fixP->fx_file, fixP->fx_line,
29331 _("invalid offset, value too big (0x%08lX)"),
29332 (long) value);
29333 newval |= value << 4; /* 6 - 2. */
29334 break;
a737bd4d 29335
c19d1205
ZW
29336 case 7: /* Byte load/store. */
29337 if (value & ~0x1f)
29338 as_bad_where (fixP->fx_file, fixP->fx_line,
29339 _("invalid offset, value too big (0x%08lX)"),
29340 (long) value);
29341 newval |= value << 6;
29342 break;
a737bd4d 29343
c19d1205
ZW
29344 case 8: /* Halfword load/store. */
29345 if (value & ~0x3e)
29346 as_bad_where (fixP->fx_file, fixP->fx_line,
29347 _("invalid offset, value too big (0x%08lX)"),
29348 (long) value);
29349 newval |= value << 5; /* 6 - 1. */
29350 break;
a737bd4d 29351
c19d1205
ZW
29352 default:
29353 as_bad_where (fixP->fx_file, fixP->fx_line,
29354 "Unable to process relocation for thumb opcode: %lx",
29355 (unsigned long) newval);
29356 break;
29357 }
29358 md_number_to_chars (buf, newval, THUMB_SIZE);
29359 break;
a737bd4d 29360
c19d1205
ZW
29361 case BFD_RELOC_ARM_THUMB_ADD:
29362 /* This is a complicated relocation, since we use it for all of
29363 the following immediate relocations:
a737bd4d 29364
c19d1205
ZW
29365 3bit ADD/SUB
29366 8bit ADD/SUB
29367 9bit ADD/SUB SP word-aligned
29368 10bit ADD PC/SP word-aligned
a737bd4d 29369
c19d1205
ZW
29370 The type of instruction being processed is encoded in the
29371 instruction field:
a737bd4d 29372
c19d1205
ZW
29373 0x8000 SUB
29374 0x00F0 Rd
29375 0x000F Rs
29376 */
29377 newval = md_chars_to_number (buf, THUMB_SIZE);
29378 {
29379 int rd = (newval >> 4) & 0xf;
29380 int rs = newval & 0xf;
29381 int subtract = !!(newval & 0x8000);
a737bd4d 29382
c19d1205
ZW
29383 /* Check for HI regs, only very restricted cases allowed:
29384 Adjusting SP, and using PC or SP to get an address. */
29385 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29386 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29387 as_bad_where (fixP->fx_file, fixP->fx_line,
29388 _("invalid Hi register with immediate"));
a737bd4d 29389
c19d1205
ZW
29390 /* If value is negative, choose the opposite instruction. */
29391 if (value < 0)
29392 {
29393 value = -value;
29394 subtract = !subtract;
29395 if (value < 0)
29396 as_bad_where (fixP->fx_file, fixP->fx_line,
29397 _("immediate value out of range"));
29398 }
a737bd4d 29399
c19d1205
ZW
29400 if (rd == REG_SP)
29401 {
75c11999 29402 if (value & ~0x1fc)
c19d1205
ZW
29403 as_bad_where (fixP->fx_file, fixP->fx_line,
29404 _("invalid immediate for stack address calculation"));
29405 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29406 newval |= value >> 2;
29407 }
29408 else if (rs == REG_PC || rs == REG_SP)
29409 {
c12d2c9d
NC
29410 /* PR gas/18541. If the addition is for a defined symbol
29411 within range of an ADR instruction then accept it. */
29412 if (subtract
29413 && value == 4
29414 && fixP->fx_addsy != NULL)
29415 {
29416 subtract = 0;
29417
29418 if (! S_IS_DEFINED (fixP->fx_addsy)
29419 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29420 || S_IS_WEAK (fixP->fx_addsy))
29421 {
29422 as_bad_where (fixP->fx_file, fixP->fx_line,
29423 _("address calculation needs a strongly defined nearby symbol"));
29424 }
29425 else
29426 {
29427 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29428
29429 /* Round up to the next 4-byte boundary. */
29430 if (v & 3)
29431 v = (v + 3) & ~ 3;
29432 else
29433 v += 4;
29434 v = S_GET_VALUE (fixP->fx_addsy) - v;
29435
29436 if (v & ~0x3fc)
29437 {
29438 as_bad_where (fixP->fx_file, fixP->fx_line,
29439 _("symbol too far away"));
29440 }
29441 else
29442 {
29443 fixP->fx_done = 1;
29444 value = v;
29445 }
29446 }
29447 }
29448
c19d1205
ZW
29449 if (subtract || value & ~0x3fc)
29450 as_bad_where (fixP->fx_file, fixP->fx_line,
29451 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 29452 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
29453 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29454 newval |= rd << 8;
29455 newval |= value >> 2;
29456 }
29457 else if (rs == rd)
29458 {
29459 if (value & ~0xff)
29460 as_bad_where (fixP->fx_file, fixP->fx_line,
29461 _("immediate value out of range"));
29462 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29463 newval |= (rd << 8) | value;
29464 }
29465 else
29466 {
29467 if (value & ~0x7)
29468 as_bad_where (fixP->fx_file, fixP->fx_line,
29469 _("immediate value out of range"));
29470 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29471 newval |= rd | (rs << 3) | (value << 6);
29472 }
29473 }
29474 md_number_to_chars (buf, newval, THUMB_SIZE);
29475 break;
a737bd4d 29476
c19d1205
ZW
29477 case BFD_RELOC_ARM_THUMB_IMM:
29478 newval = md_chars_to_number (buf, THUMB_SIZE);
29479 if (value < 0 || value > 255)
29480 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 29481 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
29482 (long) value);
29483 newval |= value;
29484 md_number_to_chars (buf, newval, THUMB_SIZE);
29485 break;
a737bd4d 29486
c19d1205
ZW
29487 case BFD_RELOC_ARM_THUMB_SHIFT:
29488 /* 5bit shift value (0..32). LSL cannot take 32. */
29489 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29490 temp = newval & 0xf800;
29491 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29492 as_bad_where (fixP->fx_file, fixP->fx_line,
29493 _("invalid shift value: %ld"), (long) value);
29494 /* Shifts of zero must be encoded as LSL. */
29495 if (value == 0)
29496 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29497 /* Shifts of 32 are encoded as zero. */
29498 else if (value == 32)
29499 value = 0;
29500 newval |= value << 6;
29501 md_number_to_chars (buf, newval, THUMB_SIZE);
29502 break;
a737bd4d 29503
c19d1205
ZW
29504 case BFD_RELOC_VTABLE_INHERIT:
29505 case BFD_RELOC_VTABLE_ENTRY:
29506 fixP->fx_done = 0;
29507 return;
6c43fab6 29508
b6895b4f
PB
29509 case BFD_RELOC_ARM_MOVW:
29510 case BFD_RELOC_ARM_MOVT:
29511 case BFD_RELOC_ARM_THUMB_MOVW:
29512 case BFD_RELOC_ARM_THUMB_MOVT:
29513 if (fixP->fx_done || !seg->use_rela_p)
29514 {
29515 /* REL format relocations are limited to a 16-bit addend. */
29516 if (!fixP->fx_done)
29517 {
39623e12 29518 if (value < -0x8000 || value > 0x7fff)
b6895b4f 29519 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 29520 _("offset out of range"));
b6895b4f
PB
29521 }
29522 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29523 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29524 {
29525 value >>= 16;
29526 }
29527
29528 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29529 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29530 {
29531 newval = get_thumb32_insn (buf);
29532 newval &= 0xfbf08f00;
29533 newval |= (value & 0xf000) << 4;
29534 newval |= (value & 0x0800) << 15;
29535 newval |= (value & 0x0700) << 4;
29536 newval |= (value & 0x00ff);
29537 put_thumb32_insn (buf, newval);
29538 }
29539 else
29540 {
29541 newval = md_chars_to_number (buf, 4);
29542 newval &= 0xfff0f000;
29543 newval |= value & 0x0fff;
29544 newval |= (value & 0xf000) << 4;
29545 md_number_to_chars (buf, newval, 4);
29546 }
29547 }
29548 return;
29549
72d98d16
MG
29550 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29551 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29552 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29554 gas_assert (!fixP->fx_done);
29555 {
29556 bfd_vma insn;
29557 bfd_boolean is_mov;
29558 bfd_vma encoded_addend = value;
29559
29560 /* Check that addend can be encoded in instruction. */
29561 if (!seg->use_rela_p && (value < 0 || value > 255))
29562 as_bad_where (fixP->fx_file, fixP->fx_line,
29563 _("the offset 0x%08lX is not representable"),
29564 (unsigned long) encoded_addend);
29565
29566 /* Extract the instruction. */
29567 insn = md_chars_to_number (buf, THUMB_SIZE);
29568 is_mov = (insn & 0xf800) == 0x2000;
29569
29570 /* Encode insn. */
29571 if (is_mov)
29572 {
29573 if (!seg->use_rela_p)
29574 insn |= encoded_addend;
29575 }
29576 else
29577 {
29578 int rd, rs;
29579
29580 /* Extract the instruction. */
29581 /* Encoding is the following
29582 0x8000 SUB
29583 0x00F0 Rd
29584 0x000F Rs
29585 */
29586 /* The following conditions must be true :
29587 - ADD
29588 - Rd == Rs
29589 - Rd <= 7
29590 */
29591 rd = (insn >> 4) & 0xf;
29592 rs = insn & 0xf;
29593 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29594 as_bad_where (fixP->fx_file, fixP->fx_line,
29595 _("Unable to process relocation for thumb opcode: %lx"),
29596 (unsigned long) insn);
29597
29598 /* Encode as ADD immediate8 thumb 1 code. */
29599 insn = 0x3000 | (rd << 8);
29600
29601 /* Place the encoded addend into the first 8 bits of the
29602 instruction. */
29603 if (!seg->use_rela_p)
29604 insn |= encoded_addend;
29605 }
29606
29607 /* Update the instruction. */
29608 md_number_to_chars (buf, insn, THUMB_SIZE);
29609 }
29610 break;
29611
4962c51a
MS
29612 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29613 case BFD_RELOC_ARM_ALU_PC_G0:
29614 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29615 case BFD_RELOC_ARM_ALU_PC_G1:
29616 case BFD_RELOC_ARM_ALU_PC_G2:
29617 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29618 case BFD_RELOC_ARM_ALU_SB_G0:
29619 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29620 case BFD_RELOC_ARM_ALU_SB_G1:
29621 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 29622 gas_assert (!fixP->fx_done);
4962c51a
MS
29623 if (!seg->use_rela_p)
29624 {
477330fc
RM
29625 bfd_vma insn;
29626 bfd_vma encoded_addend;
3ca4a8ec 29627 bfd_vma addend_abs = llabs (value);
477330fc
RM
29628
29629 /* Check that the absolute value of the addend can be
29630 expressed as an 8-bit constant plus a rotation. */
29631 encoded_addend = encode_arm_immediate (addend_abs);
29632 if (encoded_addend == (unsigned int) FAIL)
4962c51a 29633 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29634 _("the offset 0x%08lX is not representable"),
29635 (unsigned long) addend_abs);
29636
29637 /* Extract the instruction. */
29638 insn = md_chars_to_number (buf, INSN_SIZE);
29639
29640 /* If the addend is positive, use an ADD instruction.
29641 Otherwise use a SUB. Take care not to destroy the S bit. */
29642 insn &= 0xff1fffff;
29643 if (value < 0)
29644 insn |= 1 << 22;
29645 else
29646 insn |= 1 << 23;
29647
29648 /* Place the encoded addend into the first 12 bits of the
29649 instruction. */
29650 insn &= 0xfffff000;
29651 insn |= encoded_addend;
29652
29653 /* Update the instruction. */
29654 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
29655 }
29656 break;
29657
29658 case BFD_RELOC_ARM_LDR_PC_G0:
29659 case BFD_RELOC_ARM_LDR_PC_G1:
29660 case BFD_RELOC_ARM_LDR_PC_G2:
29661 case BFD_RELOC_ARM_LDR_SB_G0:
29662 case BFD_RELOC_ARM_LDR_SB_G1:
29663 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 29664 gas_assert (!fixP->fx_done);
4962c51a 29665 if (!seg->use_rela_p)
477330fc
RM
29666 {
29667 bfd_vma insn;
3ca4a8ec 29668 bfd_vma addend_abs = llabs (value);
4962c51a 29669
477330fc
RM
29670 /* Check that the absolute value of the addend can be
29671 encoded in 12 bits. */
29672 if (addend_abs >= 0x1000)
4962c51a 29673 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29674 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29675 (unsigned long) addend_abs);
29676
29677 /* Extract the instruction. */
29678 insn = md_chars_to_number (buf, INSN_SIZE);
29679
29680 /* If the addend is negative, clear bit 23 of the instruction.
29681 Otherwise set it. */
29682 if (value < 0)
29683 insn &= ~(1 << 23);
29684 else
29685 insn |= 1 << 23;
29686
29687 /* Place the absolute value of the addend into the first 12 bits
29688 of the instruction. */
29689 insn &= 0xfffff000;
29690 insn |= addend_abs;
29691
29692 /* Update the instruction. */
29693 md_number_to_chars (buf, insn, INSN_SIZE);
29694 }
4962c51a
MS
29695 break;
29696
29697 case BFD_RELOC_ARM_LDRS_PC_G0:
29698 case BFD_RELOC_ARM_LDRS_PC_G1:
29699 case BFD_RELOC_ARM_LDRS_PC_G2:
29700 case BFD_RELOC_ARM_LDRS_SB_G0:
29701 case BFD_RELOC_ARM_LDRS_SB_G1:
29702 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 29703 gas_assert (!fixP->fx_done);
4962c51a 29704 if (!seg->use_rela_p)
477330fc
RM
29705 {
29706 bfd_vma insn;
3ca4a8ec 29707 bfd_vma addend_abs = llabs (value);
4962c51a 29708
477330fc
RM
29709 /* Check that the absolute value of the addend can be
29710 encoded in 8 bits. */
29711 if (addend_abs >= 0x100)
4962c51a 29712 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29713 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29714 (unsigned long) addend_abs);
29715
29716 /* Extract the instruction. */
29717 insn = md_chars_to_number (buf, INSN_SIZE);
29718
29719 /* If the addend is negative, clear bit 23 of the instruction.
29720 Otherwise set it. */
29721 if (value < 0)
29722 insn &= ~(1 << 23);
29723 else
29724 insn |= 1 << 23;
29725
29726 /* Place the first four bits of the absolute value of the addend
29727 into the first 4 bits of the instruction, and the remaining
29728 four into bits 8 .. 11. */
29729 insn &= 0xfffff0f0;
29730 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29731
29732 /* Update the instruction. */
29733 md_number_to_chars (buf, insn, INSN_SIZE);
29734 }
4962c51a
MS
29735 break;
29736
29737 case BFD_RELOC_ARM_LDC_PC_G0:
29738 case BFD_RELOC_ARM_LDC_PC_G1:
29739 case BFD_RELOC_ARM_LDC_PC_G2:
29740 case BFD_RELOC_ARM_LDC_SB_G0:
29741 case BFD_RELOC_ARM_LDC_SB_G1:
29742 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 29743 gas_assert (!fixP->fx_done);
4962c51a 29744 if (!seg->use_rela_p)
477330fc
RM
29745 {
29746 bfd_vma insn;
3ca4a8ec 29747 bfd_vma addend_abs = llabs (value);
4962c51a 29748
477330fc
RM
29749 /* Check that the absolute value of the addend is a multiple of
29750 four and, when divided by four, fits in 8 bits. */
29751 if (addend_abs & 0x3)
4962c51a 29752 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29753 _("bad offset 0x%08lX (must be word-aligned)"),
29754 (unsigned long) addend_abs);
4962c51a 29755
477330fc 29756 if ((addend_abs >> 2) > 0xff)
4962c51a 29757 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29758 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29759 (unsigned long) addend_abs);
29760
29761 /* Extract the instruction. */
29762 insn = md_chars_to_number (buf, INSN_SIZE);
29763
29764 /* If the addend is negative, clear bit 23 of the instruction.
29765 Otherwise set it. */
29766 if (value < 0)
29767 insn &= ~(1 << 23);
29768 else
29769 insn |= 1 << 23;
29770
29771 /* Place the addend (divided by four) into the first eight
29772 bits of the instruction. */
29773 insn &= 0xfffffff0;
29774 insn |= addend_abs >> 2;
29775
29776 /* Update the instruction. */
29777 md_number_to_chars (buf, insn, INSN_SIZE);
29778 }
4962c51a
MS
29779 break;
29780
e12437dc
AV
29781 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29782 if (fixP->fx_addsy
29783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29784 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29785 && ARM_IS_FUNC (fixP->fx_addsy)
29786 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29787 {
29788 /* Force a relocation for a branch 5 bits wide. */
29789 fixP->fx_done = 0;
29790 }
29791 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29792 as_bad_where (fixP->fx_file, fixP->fx_line,
29793 BAD_BRANCH_OFF);
29794
29795 if (fixP->fx_done || !seg->use_rela_p)
29796 {
29797 addressT boff = value >> 1;
29798
29799 newval = md_chars_to_number (buf, THUMB_SIZE);
29800 newval |= (boff << 7);
29801 md_number_to_chars (buf, newval, THUMB_SIZE);
29802 }
29803 break;
29804
f6b2b12d
AV
29805 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29806 if (fixP->fx_addsy
29807 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29809 && ARM_IS_FUNC (fixP->fx_addsy)
29810 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29811 {
29812 fixP->fx_done = 0;
29813 }
29814 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
29815 as_bad_where (fixP->fx_file, fixP->fx_line,
29816 _("branch out of range"));
29817
29818 if (fixP->fx_done || !seg->use_rela_p)
29819 {
29820 newval = md_chars_to_number (buf, THUMB_SIZE);
29821
29822 addressT boff = ((newval & 0x0780) >> 7) << 1;
29823 addressT diff = value - boff;
29824
29825 if (diff == 4)
29826 {
29827 newval |= 1 << 1; /* T bit. */
29828 }
29829 else if (diff != 2)
29830 {
29831 as_bad_where (fixP->fx_file, fixP->fx_line,
29832 _("out of range label-relative fixup value"));
29833 }
29834 md_number_to_chars (buf, newval, THUMB_SIZE);
29835 }
29836 break;
29837
e5d6e09e
AV
29838 case BFD_RELOC_ARM_THUMB_BF17:
29839 if (fixP->fx_addsy
29840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29841 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29842 && ARM_IS_FUNC (fixP->fx_addsy)
29843 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29844 {
29845 /* Force a relocation for a branch 17 bits wide. */
29846 fixP->fx_done = 0;
29847 }
29848
29849 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29850 as_bad_where (fixP->fx_file, fixP->fx_line,
29851 BAD_BRANCH_OFF);
29852
29853 if (fixP->fx_done || !seg->use_rela_p)
29854 {
29855 offsetT newval2;
29856 addressT immA, immB, immC;
29857
29858 immA = (value & 0x0001f000) >> 12;
29859 immB = (value & 0x00000ffc) >> 2;
29860 immC = (value & 0x00000002) >> 1;
29861
29862 newval = md_chars_to_number (buf, THUMB_SIZE);
29863 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29864 newval |= immA;
29865 newval2 |= (immC << 11) | (immB << 1);
29866 md_number_to_chars (buf, newval, THUMB_SIZE);
29867 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29868 }
29869 break;
29870
1caf72a5
AV
29871 case BFD_RELOC_ARM_THUMB_BF19:
29872 if (fixP->fx_addsy
29873 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29874 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29875 && ARM_IS_FUNC (fixP->fx_addsy)
29876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29877 {
29878 /* Force a relocation for a branch 19 bits wide. */
29879 fixP->fx_done = 0;
29880 }
29881
29882 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29883 as_bad_where (fixP->fx_file, fixP->fx_line,
29884 BAD_BRANCH_OFF);
29885
29886 if (fixP->fx_done || !seg->use_rela_p)
29887 {
29888 offsetT newval2;
29889 addressT immA, immB, immC;
29890
29891 immA = (value & 0x0007f000) >> 12;
29892 immB = (value & 0x00000ffc) >> 2;
29893 immC = (value & 0x00000002) >> 1;
29894
29895 newval = md_chars_to_number (buf, THUMB_SIZE);
29896 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29897 newval |= immA;
29898 newval2 |= (immC << 11) | (immB << 1);
29899 md_number_to_chars (buf, newval, THUMB_SIZE);
29900 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29901 }
29902 break;
29903
1889da70
AV
29904 case BFD_RELOC_ARM_THUMB_BF13:
29905 if (fixP->fx_addsy
29906 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29907 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29908 && ARM_IS_FUNC (fixP->fx_addsy)
29909 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29910 {
29911 /* Force a relocation for a branch 13 bits wide. */
29912 fixP->fx_done = 0;
29913 }
29914
29915 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29916 as_bad_where (fixP->fx_file, fixP->fx_line,
29917 BAD_BRANCH_OFF);
29918
29919 if (fixP->fx_done || !seg->use_rela_p)
29920 {
29921 offsetT newval2;
29922 addressT immA, immB, immC;
29923
29924 immA = (value & 0x00001000) >> 12;
29925 immB = (value & 0x00000ffc) >> 2;
29926 immC = (value & 0x00000002) >> 1;
29927
29928 newval = md_chars_to_number (buf, THUMB_SIZE);
29929 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29930 newval |= immA;
29931 newval2 |= (immC << 11) | (immB << 1);
29932 md_number_to_chars (buf, newval, THUMB_SIZE);
29933 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29934 }
29935 break;
29936
60f993ce
AV
29937 case BFD_RELOC_ARM_THUMB_LOOP12:
29938 if (fixP->fx_addsy
29939 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29940 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29941 && ARM_IS_FUNC (fixP->fx_addsy)
29942 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29943 {
29944 /* Force a relocation for a branch 12 bits wide. */
29945 fixP->fx_done = 0;
29946 }
29947
29948 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 29949 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 29950 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
29951 || ((insn & 0xffffffff) == 0xf02fc001)
29952 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
29953 value = -value;
29954
29955 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29956 as_bad_where (fixP->fx_file, fixP->fx_line,
29957 BAD_BRANCH_OFF);
29958 if (fixP->fx_done || !seg->use_rela_p)
29959 {
29960 addressT imml, immh;
29961
29962 immh = (value & 0x00000ffc) >> 2;
29963 imml = (value & 0x00000002) >> 1;
29964
29965 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29966 newval |= (imml << 11) | (immh << 1);
29967 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29968 }
29969 break;
29970
845b51d6
PB
29971 case BFD_RELOC_ARM_V4BX:
29972 /* This will need to go in the object file. */
29973 fixP->fx_done = 0;
29974 break;
29975
c19d1205
ZW
29976 case BFD_RELOC_UNUSED:
29977 default:
29978 as_bad_where (fixP->fx_file, fixP->fx_line,
29979 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29980 }
6c43fab6
RE
29981}
29982
c19d1205
ZW
29983/* Translate internal representation of relocation info to BFD target
29984 format. */
a737bd4d 29985
c19d1205 29986arelent *
00a97672 29987tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29988{
c19d1205
ZW
29989 arelent * reloc;
29990 bfd_reloc_code_real_type code;
a737bd4d 29991
325801bd 29992 reloc = XNEW (arelent);
a737bd4d 29993
325801bd 29994 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
29995 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29996 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 29997
2fc8bdac 29998 if (fixp->fx_pcrel)
00a97672
RS
29999 {
30000 if (section->use_rela_p)
30001 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
30002 else
30003 fixp->fx_offset = reloc->address;
30004 }
c19d1205 30005 reloc->addend = fixp->fx_offset;
a737bd4d 30006
c19d1205 30007 switch (fixp->fx_r_type)
a737bd4d 30008 {
c19d1205
ZW
30009 case BFD_RELOC_8:
30010 if (fixp->fx_pcrel)
30011 {
30012 code = BFD_RELOC_8_PCREL;
30013 break;
30014 }
1a0670f3 30015 /* Fall through. */
a737bd4d 30016
c19d1205
ZW
30017 case BFD_RELOC_16:
30018 if (fixp->fx_pcrel)
30019 {
30020 code = BFD_RELOC_16_PCREL;
30021 break;
30022 }
1a0670f3 30023 /* Fall through. */
6c43fab6 30024
c19d1205
ZW
30025 case BFD_RELOC_32:
30026 if (fixp->fx_pcrel)
30027 {
30028 code = BFD_RELOC_32_PCREL;
30029 break;
30030 }
1a0670f3 30031 /* Fall through. */
a737bd4d 30032
b6895b4f
PB
30033 case BFD_RELOC_ARM_MOVW:
30034 if (fixp->fx_pcrel)
30035 {
30036 code = BFD_RELOC_ARM_MOVW_PCREL;
30037 break;
30038 }
1a0670f3 30039 /* Fall through. */
b6895b4f
PB
30040
30041 case BFD_RELOC_ARM_MOVT:
30042 if (fixp->fx_pcrel)
30043 {
30044 code = BFD_RELOC_ARM_MOVT_PCREL;
30045 break;
30046 }
1a0670f3 30047 /* Fall through. */
b6895b4f
PB
30048
30049 case BFD_RELOC_ARM_THUMB_MOVW:
30050 if (fixp->fx_pcrel)
30051 {
30052 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30053 break;
30054 }
1a0670f3 30055 /* Fall through. */
b6895b4f
PB
30056
30057 case BFD_RELOC_ARM_THUMB_MOVT:
30058 if (fixp->fx_pcrel)
30059 {
30060 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30061 break;
30062 }
1a0670f3 30063 /* Fall through. */
b6895b4f 30064
c19d1205
ZW
30065 case BFD_RELOC_NONE:
30066 case BFD_RELOC_ARM_PCREL_BRANCH:
30067 case BFD_RELOC_ARM_PCREL_BLX:
30068 case BFD_RELOC_RVA:
30069 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30070 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30071 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30072 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30073 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30074 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
30075 case BFD_RELOC_VTABLE_ENTRY:
30076 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
30077#ifdef TE_PE
30078 case BFD_RELOC_32_SECREL:
30079#endif
c19d1205
ZW
30080 code = fixp->fx_r_type;
30081 break;
a737bd4d 30082
00adf2d4
JB
30083 case BFD_RELOC_THUMB_PCREL_BLX:
30084#ifdef OBJ_ELF
30085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30086 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30087 else
30088#endif
30089 code = BFD_RELOC_THUMB_PCREL_BLX;
30090 break;
30091
c19d1205
ZW
30092 case BFD_RELOC_ARM_LITERAL:
30093 case BFD_RELOC_ARM_HWLITERAL:
30094 /* If this is called then the a literal has
30095 been referenced across a section boundary. */
30096 as_bad_where (fixp->fx_file, fixp->fx_line,
30097 _("literal referenced across section boundary"));
30098 return NULL;
a737bd4d 30099
c19d1205 30100#ifdef OBJ_ELF
0855e32b
NS
30101 case BFD_RELOC_ARM_TLS_CALL:
30102 case BFD_RELOC_ARM_THM_TLS_CALL:
30103 case BFD_RELOC_ARM_TLS_DESCSEQ:
30104 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
30105 case BFD_RELOC_ARM_GOT32:
30106 case BFD_RELOC_ARM_GOTOFF:
b43420e6 30107 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
30108 case BFD_RELOC_ARM_PLT32:
30109 case BFD_RELOC_ARM_TARGET1:
30110 case BFD_RELOC_ARM_ROSEGREL32:
30111 case BFD_RELOC_ARM_SBREL32:
30112 case BFD_RELOC_ARM_PREL31:
30113 case BFD_RELOC_ARM_TARGET2:
c19d1205 30114 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
30115 case BFD_RELOC_ARM_PCREL_CALL:
30116 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
30117 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30118 case BFD_RELOC_ARM_ALU_PC_G0:
30119 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30120 case BFD_RELOC_ARM_ALU_PC_G1:
30121 case BFD_RELOC_ARM_ALU_PC_G2:
30122 case BFD_RELOC_ARM_LDR_PC_G0:
30123 case BFD_RELOC_ARM_LDR_PC_G1:
30124 case BFD_RELOC_ARM_LDR_PC_G2:
30125 case BFD_RELOC_ARM_LDRS_PC_G0:
30126 case BFD_RELOC_ARM_LDRS_PC_G1:
30127 case BFD_RELOC_ARM_LDRS_PC_G2:
30128 case BFD_RELOC_ARM_LDC_PC_G0:
30129 case BFD_RELOC_ARM_LDC_PC_G1:
30130 case BFD_RELOC_ARM_LDC_PC_G2:
30131 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30132 case BFD_RELOC_ARM_ALU_SB_G0:
30133 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30134 case BFD_RELOC_ARM_ALU_SB_G1:
30135 case BFD_RELOC_ARM_ALU_SB_G2:
30136 case BFD_RELOC_ARM_LDR_SB_G0:
30137 case BFD_RELOC_ARM_LDR_SB_G1:
30138 case BFD_RELOC_ARM_LDR_SB_G2:
30139 case BFD_RELOC_ARM_LDRS_SB_G0:
30140 case BFD_RELOC_ARM_LDRS_SB_G1:
30141 case BFD_RELOC_ARM_LDRS_SB_G2:
30142 case BFD_RELOC_ARM_LDC_SB_G0:
30143 case BFD_RELOC_ARM_LDC_SB_G1:
30144 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 30145 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
30146 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30147 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30148 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30149 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
30150 case BFD_RELOC_ARM_GOTFUNCDESC:
30151 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30152 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 30153 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 30154 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 30155 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
30156 code = fixp->fx_r_type;
30157 break;
a737bd4d 30158
0855e32b 30159 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 30160 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 30161 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 30162 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 30163 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 30164 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 30165 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 30166 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
30167 /* BFD will include the symbol's address in the addend.
30168 But we don't want that, so subtract it out again here. */
30169 if (!S_IS_COMMON (fixp->fx_addsy))
30170 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30171 code = fixp->fx_r_type;
30172 break;
30173#endif
a737bd4d 30174
c19d1205
ZW
30175 case BFD_RELOC_ARM_IMMEDIATE:
30176 as_bad_where (fixp->fx_file, fixp->fx_line,
30177 _("internal relocation (type: IMMEDIATE) not fixed up"));
30178 return NULL;
a737bd4d 30179
c19d1205
ZW
30180 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30181 as_bad_where (fixp->fx_file, fixp->fx_line,
30182 _("ADRL used for a symbol not defined in the same file"));
30183 return NULL;
a737bd4d 30184
e12437dc 30185 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 30186 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 30187 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
30188 as_bad_where (fixp->fx_file, fixp->fx_line,
30189 _("%s used for a symbol not defined in the same file"),
30190 bfd_get_reloc_code_name (fixp->fx_r_type));
30191 return NULL;
30192
c19d1205 30193 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
30194 if (section->use_rela_p)
30195 {
30196 code = fixp->fx_r_type;
30197 break;
30198 }
30199
c19d1205
ZW
30200 if (fixp->fx_addsy != NULL
30201 && !S_IS_DEFINED (fixp->fx_addsy)
30202 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 30203 {
c19d1205
ZW
30204 as_bad_where (fixp->fx_file, fixp->fx_line,
30205 _("undefined local label `%s'"),
30206 S_GET_NAME (fixp->fx_addsy));
30207 return NULL;
a737bd4d
NC
30208 }
30209
c19d1205
ZW
30210 as_bad_where (fixp->fx_file, fixp->fx_line,
30211 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30212 return NULL;
a737bd4d 30213
c19d1205
ZW
30214 default:
30215 {
e0471c16 30216 const char * type;
6c43fab6 30217
c19d1205
ZW
30218 switch (fixp->fx_r_type)
30219 {
30220 case BFD_RELOC_NONE: type = "NONE"; break;
30221 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30222 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 30223 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
30224 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30225 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30226 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 30227 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 30228 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
30229 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30230 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30231 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30232 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30233 default: type = _("<unknown>"); break;
30234 }
30235 as_bad_where (fixp->fx_file, fixp->fx_line,
30236 _("cannot represent %s relocation in this object file format"),
30237 type);
30238 return NULL;
30239 }
a737bd4d 30240 }
6c43fab6 30241
c19d1205
ZW
30242#ifdef OBJ_ELF
30243 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30244 && GOT_symbol
30245 && fixp->fx_addsy == GOT_symbol)
30246 {
30247 code = BFD_RELOC_ARM_GOTPC;
30248 reloc->addend = fixp->fx_offset = reloc->address;
30249 }
30250#endif
6c43fab6 30251
c19d1205 30252 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 30253
c19d1205
ZW
30254 if (reloc->howto == NULL)
30255 {
30256 as_bad_where (fixp->fx_file, fixp->fx_line,
30257 _("cannot represent %s relocation in this object file format"),
30258 bfd_get_reloc_code_name (code));
30259 return NULL;
30260 }
6c43fab6 30261
c19d1205
ZW
30262 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30263 vtable entry to be used in the relocation's section offset. */
30264 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30265 reloc->address = fixp->fx_offset;
6c43fab6 30266
c19d1205 30267 return reloc;
6c43fab6
RE
30268}
30269
c19d1205 30270/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 30271
c19d1205
ZW
30272void
30273cons_fix_new_arm (fragS * frag,
30274 int where,
30275 int size,
62ebcb5c
AM
30276 expressionS * exp,
30277 bfd_reloc_code_real_type reloc)
6c43fab6 30278{
c19d1205 30279 int pcrel = 0;
6c43fab6 30280
c19d1205
ZW
30281 /* Pick a reloc.
30282 FIXME: @@ Should look at CPU word size. */
30283 switch (size)
30284 {
30285 case 1:
62ebcb5c 30286 reloc = BFD_RELOC_8;
c19d1205
ZW
30287 break;
30288 case 2:
62ebcb5c 30289 reloc = BFD_RELOC_16;
c19d1205
ZW
30290 break;
30291 case 4:
30292 default:
62ebcb5c 30293 reloc = BFD_RELOC_32;
c19d1205
ZW
30294 break;
30295 case 8:
62ebcb5c 30296 reloc = BFD_RELOC_64;
c19d1205
ZW
30297 break;
30298 }
6c43fab6 30299
f0927246
NC
30300#ifdef TE_PE
30301 if (exp->X_op == O_secrel)
30302 {
30303 exp->X_op = O_symbol;
62ebcb5c 30304 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
30305 }
30306#endif
30307
62ebcb5c 30308 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 30309}
6c43fab6 30310
4343666d 30311#if defined (OBJ_COFF)
c19d1205
ZW
30312void
30313arm_validate_fix (fixS * fixP)
6c43fab6 30314{
c19d1205
ZW
30315 /* If the destination of the branch is a defined symbol which does not have
30316 the THUMB_FUNC attribute, then we must be calling a function which has
30317 the (interfacearm) attribute. We look for the Thumb entry point to that
30318 function and change the branch to refer to that function instead. */
30319 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30320 && fixP->fx_addsy != NULL
30321 && S_IS_DEFINED (fixP->fx_addsy)
30322 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 30323 {
c19d1205 30324 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 30325 }
c19d1205
ZW
30326}
30327#endif
6c43fab6 30328
267bf995 30329
c19d1205
ZW
30330int
30331arm_force_relocation (struct fix * fixp)
30332{
30333#if defined (OBJ_COFF) && defined (TE_PE)
30334 if (fixp->fx_r_type == BFD_RELOC_RVA)
30335 return 1;
30336#endif
6c43fab6 30337
267bf995
RR
30338 /* In case we have a call or a branch to a function in ARM ISA mode from
30339 a thumb function or vice-versa force the relocation. These relocations
30340 are cleared off for some cores that might have blx and simple transformations
30341 are possible. */
30342
30343#ifdef OBJ_ELF
30344 switch (fixp->fx_r_type)
30345 {
30346 case BFD_RELOC_ARM_PCREL_JUMP:
30347 case BFD_RELOC_ARM_PCREL_CALL:
30348 case BFD_RELOC_THUMB_PCREL_BLX:
30349 if (THUMB_IS_FUNC (fixp->fx_addsy))
30350 return 1;
30351 break;
30352
30353 case BFD_RELOC_ARM_PCREL_BLX:
30354 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30355 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30356 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30357 if (ARM_IS_FUNC (fixp->fx_addsy))
30358 return 1;
30359 break;
30360
30361 default:
30362 break;
30363 }
30364#endif
30365
b5884301
PB
30366 /* Resolve these relocations even if the symbol is extern or weak.
30367 Technically this is probably wrong due to symbol preemption.
30368 In practice these relocations do not have enough range to be useful
30369 at dynamic link time, and some code (e.g. in the Linux kernel)
30370 expects these references to be resolved. */
c19d1205
ZW
30371 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30372 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 30373 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 30374 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
30375 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30376 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30377 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 30378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
30379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
30381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30384 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 30385 return 0;
a737bd4d 30386
4962c51a
MS
30387 /* Always leave these relocations for the linker. */
30388 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30389 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30390 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30391 return 1;
30392
f0291e4c
PB
30393 /* Always generate relocations against function symbols. */
30394 if (fixp->fx_r_type == BFD_RELOC_32
30395 && fixp->fx_addsy
30396 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30397 return 1;
30398
c19d1205 30399 return generic_force_reloc (fixp);
404ff6b5
AH
30400}
30401
0ffdc86c 30402#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
30403/* Relocations against function names must be left unadjusted,
30404 so that the linker can use this information to generate interworking
30405 stubs. The MIPS version of this function
c19d1205
ZW
30406 also prevents relocations that are mips-16 specific, but I do not
30407 know why it does this.
404ff6b5 30408
c19d1205
ZW
30409 FIXME:
30410 There is one other problem that ought to be addressed here, but
30411 which currently is not: Taking the address of a label (rather
30412 than a function) and then later jumping to that address. Such
30413 addresses also ought to have their bottom bit set (assuming that
30414 they reside in Thumb code), but at the moment they will not. */
404ff6b5 30415
c19d1205
ZW
30416bfd_boolean
30417arm_fix_adjustable (fixS * fixP)
404ff6b5 30418{
c19d1205
ZW
30419 if (fixP->fx_addsy == NULL)
30420 return 1;
404ff6b5 30421
e28387c3
PB
30422 /* Preserve relocations against symbols with function type. */
30423 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 30424 return FALSE;
e28387c3 30425
c19d1205
ZW
30426 if (THUMB_IS_FUNC (fixP->fx_addsy)
30427 && fixP->fx_subsy == NULL)
c921be7d 30428 return FALSE;
a737bd4d 30429
c19d1205
ZW
30430 /* We need the symbol name for the VTABLE entries. */
30431 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30432 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 30433 return FALSE;
404ff6b5 30434
c19d1205
ZW
30435 /* Don't allow symbols to be discarded on GOT related relocs. */
30436 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30437 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30438 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 30440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
30441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 30443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 30444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 30445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 30446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
30447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30448 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30449 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30450 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30451 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 30452 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 30453 return FALSE;
a737bd4d 30454
4962c51a
MS
30455 /* Similarly for group relocations. */
30456 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30457 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30458 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 30459 return FALSE;
4962c51a 30460
79947c54
CD
30461 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30462 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30463 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30464 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30465 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30466 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30467 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30468 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30469 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 30470 return FALSE;
79947c54 30471
72d98d16
MG
30472 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30473 offsets, so keep these symbols. */
30474 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30475 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30476 return FALSE;
30477
c921be7d 30478 return TRUE;
a737bd4d 30479}
0ffdc86c
NC
30480#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30481
30482#ifdef OBJ_ELF
c19d1205
ZW
30483const char *
30484elf32_arm_target_format (void)
404ff6b5 30485{
c19d1205
ZW
30486#ifdef TE_SYMBIAN
30487 return (target_big_endian
30488 ? "elf32-bigarm-symbian"
30489 : "elf32-littlearm-symbian");
30490#elif defined (TE_VXWORKS)
30491 return (target_big_endian
30492 ? "elf32-bigarm-vxworks"
30493 : "elf32-littlearm-vxworks");
b38cadfb
NC
30494#elif defined (TE_NACL)
30495 return (target_big_endian
30496 ? "elf32-bigarm-nacl"
30497 : "elf32-littlearm-nacl");
c19d1205 30498#else
18a20338
CL
30499 if (arm_fdpic)
30500 {
30501 if (target_big_endian)
30502 return "elf32-bigarm-fdpic";
30503 else
30504 return "elf32-littlearm-fdpic";
30505 }
c19d1205 30506 else
18a20338
CL
30507 {
30508 if (target_big_endian)
30509 return "elf32-bigarm";
30510 else
30511 return "elf32-littlearm";
30512 }
c19d1205 30513#endif
404ff6b5
AH
30514}
30515
c19d1205
ZW
30516void
30517armelf_frob_symbol (symbolS * symp,
30518 int * puntp)
404ff6b5 30519{
c19d1205
ZW
30520 elf_frob_symbol (symp, puntp);
30521}
30522#endif
404ff6b5 30523
c19d1205 30524/* MD interface: Finalization. */
a737bd4d 30525
c19d1205
ZW
30526void
30527arm_cleanup (void)
30528{
30529 literal_pool * pool;
a737bd4d 30530
5ee91343
AV
30531 /* Ensure that all the predication blocks are properly closed. */
30532 check_pred_blocks_finished ();
e07e6e58 30533
c19d1205
ZW
30534 for (pool = list_of_pools; pool; pool = pool->next)
30535 {
5f4273c7 30536 /* Put it at the end of the relevant section. */
c19d1205
ZW
30537 subseg_set (pool->section, pool->sub_section);
30538#ifdef OBJ_ELF
30539 arm_elf_change_section ();
30540#endif
30541 s_ltorg (0);
30542 }
404ff6b5
AH
30543}
30544
cd000bff
DJ
30545#ifdef OBJ_ELF
30546/* Remove any excess mapping symbols generated for alignment frags in
30547 SEC. We may have created a mapping symbol before a zero byte
30548 alignment; remove it if there's a mapping symbol after the
30549 alignment. */
30550static void
30551check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30552 void *dummy ATTRIBUTE_UNUSED)
30553{
30554 segment_info_type *seginfo = seg_info (sec);
30555 fragS *fragp;
30556
30557 if (seginfo == NULL || seginfo->frchainP == NULL)
30558 return;
30559
30560 for (fragp = seginfo->frchainP->frch_root;
30561 fragp != NULL;
30562 fragp = fragp->fr_next)
30563 {
30564 symbolS *sym = fragp->tc_frag_data.last_map;
30565 fragS *next = fragp->fr_next;
30566
30567 /* Variable-sized frags have been converted to fixed size by
30568 this point. But if this was variable-sized to start with,
30569 there will be a fixed-size frag after it. So don't handle
30570 next == NULL. */
30571 if (sym == NULL || next == NULL)
30572 continue;
30573
30574 if (S_GET_VALUE (sym) < next->fr_address)
30575 /* Not at the end of this frag. */
30576 continue;
30577 know (S_GET_VALUE (sym) == next->fr_address);
30578
30579 do
30580 {
30581 if (next->tc_frag_data.first_map != NULL)
30582 {
30583 /* Next frag starts with a mapping symbol. Discard this
30584 one. */
30585 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30586 break;
30587 }
30588
30589 if (next->fr_next == NULL)
30590 {
30591 /* This mapping symbol is at the end of the section. Discard
30592 it. */
30593 know (next->fr_fix == 0 && next->fr_var == 0);
30594 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30595 break;
30596 }
30597
30598 /* As long as we have empty frags without any mapping symbols,
30599 keep looking. */
30600 /* If the next frag is non-empty and does not start with a
30601 mapping symbol, then this mapping symbol is required. */
30602 if (next->fr_address != next->fr_next->fr_address)
30603 break;
30604
30605 next = next->fr_next;
30606 }
30607 while (next != NULL);
30608 }
30609}
30610#endif
30611
c19d1205
ZW
30612/* Adjust the symbol table. This marks Thumb symbols as distinct from
30613 ARM ones. */
404ff6b5 30614
c19d1205
ZW
30615void
30616arm_adjust_symtab (void)
404ff6b5 30617{
c19d1205
ZW
30618#ifdef OBJ_COFF
30619 symbolS * sym;
404ff6b5 30620
c19d1205
ZW
30621 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30622 {
30623 if (ARM_IS_THUMB (sym))
30624 {
30625 if (THUMB_IS_FUNC (sym))
30626 {
30627 /* Mark the symbol as a Thumb function. */
30628 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30629 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30630 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 30631
c19d1205
ZW
30632 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30633 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30634 else
30635 as_bad (_("%s: unexpected function type: %d"),
30636 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30637 }
30638 else switch (S_GET_STORAGE_CLASS (sym))
30639 {
30640 case C_EXT:
30641 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30642 break;
30643 case C_STAT:
30644 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30645 break;
30646 case C_LABEL:
30647 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30648 break;
30649 default:
30650 /* Do nothing. */
30651 break;
30652 }
30653 }
a737bd4d 30654
c19d1205
ZW
30655 if (ARM_IS_INTERWORK (sym))
30656 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 30657 }
c19d1205
ZW
30658#endif
30659#ifdef OBJ_ELF
30660 symbolS * sym;
30661 char bind;
404ff6b5 30662
c19d1205 30663 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 30664 {
c19d1205
ZW
30665 if (ARM_IS_THUMB (sym))
30666 {
30667 elf_symbol_type * elf_sym;
404ff6b5 30668
c19d1205
ZW
30669 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30670 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 30671
b0796911
PB
30672 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30673 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
30674 {
30675 /* If it's a .thumb_func, declare it as so,
30676 otherwise tag label as .code 16. */
30677 if (THUMB_IS_FUNC (sym))
39d911fc
TP
30678 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30679 ST_BRANCH_TO_THUMB);
3ba67470 30680 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
30681 elf_sym->internal_elf_sym.st_info =
30682 ELF_ST_INFO (bind, STT_ARM_16BIT);
30683 }
30684 }
30685 }
cd000bff
DJ
30686
30687 /* Remove any overlapping mapping symbols generated by alignment frags. */
30688 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
30689 /* Now do generic ELF adjustments. */
30690 elf_adjust_symtab ();
c19d1205 30691#endif
404ff6b5
AH
30692}
30693
c19d1205 30694/* MD interface: Initialization. */
404ff6b5 30695
a737bd4d 30696static void
c19d1205 30697set_constant_flonums (void)
a737bd4d 30698{
c19d1205 30699 int i;
404ff6b5 30700
c19d1205
ZW
30701 for (i = 0; i < NUM_FLOAT_VALS; i++)
30702 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30703 abort ();
a737bd4d 30704}
404ff6b5 30705
3e9e4fcf
JB
30706/* Auto-select Thumb mode if it's the only available instruction set for the
30707 given architecture. */
30708
30709static void
30710autoselect_thumb_from_cpu_variant (void)
30711{
30712 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30713 opcode_select (16);
30714}
30715
c19d1205
ZW
30716void
30717md_begin (void)
a737bd4d 30718{
c19d1205
ZW
30719 unsigned mach;
30720 unsigned int i;
404ff6b5 30721
c19d1205
ZW
30722 if ( (arm_ops_hsh = hash_new ()) == NULL
30723 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 30724 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
30725 || (arm_shift_hsh = hash_new ()) == NULL
30726 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 30727 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 30728 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
30729 || (arm_reloc_hsh = hash_new ()) == NULL
30730 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
30731 as_fatal (_("virtual memory exhausted"));
30732
30733 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 30734 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 30735 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 30736 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
30737 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30738 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 30739 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 30740 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 30741 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30742 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 30743 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30744 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 30745 (void *) (v7m_psrs + i));
c19d1205 30746 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 30747 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
30748 for (i = 0;
30749 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30750 i++)
d3ce72d0 30751 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 30752 (void *) (barrier_opt_names + i));
c19d1205 30753#ifdef OBJ_ELF
3da1d841
NC
30754 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30755 {
30756 struct reloc_entry * entry = reloc_names + i;
30757
30758 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30759 /* This makes encode_branch() use the EABI versions of this relocation. */
30760 entry->reloc = BFD_RELOC_UNUSED;
30761
30762 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
30763 }
c19d1205
ZW
30764#endif
30765
30766 set_constant_flonums ();
404ff6b5 30767
c19d1205
ZW
30768 /* Set the cpu variant based on the command-line options. We prefer
30769 -mcpu= over -march= if both are set (as for GCC); and we prefer
30770 -mfpu= over any other way of setting the floating point unit.
30771 Use of legacy options with new options are faulted. */
e74cfd16 30772 if (legacy_cpu)
404ff6b5 30773 {
e74cfd16 30774 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
30775 as_bad (_("use of old and new-style options to set CPU type"));
30776
4d354d8b 30777 selected_arch = *legacy_cpu;
404ff6b5 30778 }
4d354d8b
TP
30779 else if (mcpu_cpu_opt)
30780 {
30781 selected_arch = *mcpu_cpu_opt;
30782 selected_ext = *mcpu_ext_opt;
30783 }
30784 else if (march_cpu_opt)
c168ce07 30785 {
4d354d8b
TP
30786 selected_arch = *march_cpu_opt;
30787 selected_ext = *march_ext_opt;
c168ce07 30788 }
4d354d8b 30789 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 30790
e74cfd16 30791 if (legacy_fpu)
c19d1205 30792 {
e74cfd16 30793 if (mfpu_opt)
c19d1205 30794 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 30795
4d354d8b 30796 selected_fpu = *legacy_fpu;
03b1477f 30797 }
4d354d8b
TP
30798 else if (mfpu_opt)
30799 selected_fpu = *mfpu_opt;
30800 else
03b1477f 30801 {
45eb4c1b
NS
30802#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30803 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
30804 /* Some environments specify a default FPU. If they don't, infer it
30805 from the processor. */
e74cfd16 30806 if (mcpu_fpu_opt)
4d354d8b 30807 selected_fpu = *mcpu_fpu_opt;
e7da50fa 30808 else if (march_fpu_opt)
4d354d8b 30809 selected_fpu = *march_fpu_opt;
39c2da32 30810#else
4d354d8b 30811 selected_fpu = fpu_default;
39c2da32 30812#endif
03b1477f
RE
30813 }
30814
4d354d8b 30815 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 30816 {
4d354d8b
TP
30817 if (!no_cpu_selected ())
30818 selected_fpu = fpu_default;
03b1477f 30819 else
4d354d8b 30820 selected_fpu = fpu_arch_fpa;
03b1477f
RE
30821 }
30822
ee065d83 30823#ifdef CPU_DEFAULT
4d354d8b 30824 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 30825 {
4d354d8b
TP
30826 selected_arch = cpu_default;
30827 selected_cpu = selected_arch;
ee065d83 30828 }
4d354d8b 30829 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 30830#else
4d354d8b
TP
30831 /* Autodection of feature mode: allow all features in cpu_variant but leave
30832 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30833 after all instruction have been processed and we can decide what CPU
30834 should be selected. */
30835 if (ARM_FEATURE_ZERO (selected_arch))
30836 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 30837 else
4d354d8b 30838 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 30839#endif
03b1477f 30840
3e9e4fcf
JB
30841 autoselect_thumb_from_cpu_variant ();
30842
e74cfd16 30843 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 30844
f17c130b 30845#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 30846 {
7cc69913
NC
30847 unsigned int flags = 0;
30848
30849#if defined OBJ_ELF
30850 flags = meabi_flags;
d507cf36
PB
30851
30852 switch (meabi_flags)
33a392fb 30853 {
d507cf36 30854 case EF_ARM_EABI_UNKNOWN:
7cc69913 30855#endif
d507cf36
PB
30856 /* Set the flags in the private structure. */
30857 if (uses_apcs_26) flags |= F_APCS26;
30858 if (support_interwork) flags |= F_INTERWORK;
30859 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 30860 if (pic_code) flags |= F_PIC;
e74cfd16 30861 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
30862 flags |= F_SOFT_FLOAT;
30863
d507cf36
PB
30864 switch (mfloat_abi_opt)
30865 {
30866 case ARM_FLOAT_ABI_SOFT:
30867 case ARM_FLOAT_ABI_SOFTFP:
30868 flags |= F_SOFT_FLOAT;
30869 break;
33a392fb 30870
d507cf36
PB
30871 case ARM_FLOAT_ABI_HARD:
30872 if (flags & F_SOFT_FLOAT)
30873 as_bad (_("hard-float conflicts with specified fpu"));
30874 break;
30875 }
03b1477f 30876
e74cfd16
PB
30877 /* Using pure-endian doubles (even if soft-float). */
30878 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 30879 flags |= F_VFP_FLOAT;
f17c130b 30880
fde78edd 30881#if defined OBJ_ELF
e74cfd16 30882 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 30883 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
30884 break;
30885
8cb51566 30886 case EF_ARM_EABI_VER4:
3a4a14e9 30887 case EF_ARM_EABI_VER5:
c19d1205 30888 /* No additional flags to set. */
d507cf36
PB
30889 break;
30890
30891 default:
30892 abort ();
30893 }
7cc69913 30894#endif
b99bd4ef
NC
30895 bfd_set_private_flags (stdoutput, flags);
30896
30897 /* We have run out flags in the COFF header to encode the
30898 status of ATPCS support, so instead we create a dummy,
c19d1205 30899 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
30900 if (atpcs)
30901 {
30902 asection * sec;
30903
30904 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30905
30906 if (sec != NULL)
30907 {
fd361982
AM
30908 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30909 bfd_set_section_size (sec, 0);
b99bd4ef
NC
30910 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30911 }
30912 }
7cc69913 30913 }
f17c130b 30914#endif
b99bd4ef
NC
30915
30916 /* Record the CPU type as well. */
2d447fca
JM
30917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30918 mach = bfd_mach_arm_iWMMXt2;
30919 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 30920 mach = bfd_mach_arm_iWMMXt;
e74cfd16 30921 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 30922 mach = bfd_mach_arm_XScale;
e74cfd16 30923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 30924 mach = bfd_mach_arm_ep9312;
e74cfd16 30925 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 30926 mach = bfd_mach_arm_5TE;
e74cfd16 30927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 30928 {
e74cfd16 30929 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30930 mach = bfd_mach_arm_5T;
30931 else
30932 mach = bfd_mach_arm_5;
30933 }
e74cfd16 30934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 30935 {
e74cfd16 30936 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30937 mach = bfd_mach_arm_4T;
30938 else
30939 mach = bfd_mach_arm_4;
30940 }
e74cfd16 30941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 30942 mach = bfd_mach_arm_3M;
e74cfd16
PB
30943 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30944 mach = bfd_mach_arm_3;
30945 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30946 mach = bfd_mach_arm_2a;
30947 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30948 mach = bfd_mach_arm_2;
30949 else
30950 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
30951
30952 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30953}
30954
c19d1205 30955/* Command line processing. */
b99bd4ef 30956
c19d1205
ZW
30957/* md_parse_option
30958 Invocation line includes a switch not recognized by the base assembler.
30959 See if it's a processor-specific option.
b99bd4ef 30960
c19d1205
ZW
30961 This routine is somewhat complicated by the need for backwards
30962 compatibility (since older releases of gcc can't be changed).
30963 The new options try to make the interface as compatible as
30964 possible with GCC.
b99bd4ef 30965
c19d1205 30966 New options (supported) are:
b99bd4ef 30967
c19d1205
ZW
30968 -mcpu=<cpu name> Assemble for selected processor
30969 -march=<architecture name> Assemble for selected architecture
30970 -mfpu=<fpu architecture> Assemble for selected FPU.
30971 -EB/-mbig-endian Big-endian
30972 -EL/-mlittle-endian Little-endian
30973 -k Generate PIC code
30974 -mthumb Start in Thumb mode
30975 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30976
278df34e 30977 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30978 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30979
c19d1205 30980 For now we will also provide support for:
b99bd4ef 30981
c19d1205
ZW
30982 -mapcs-32 32-bit Program counter
30983 -mapcs-26 26-bit Program counter
30984 -macps-float Floats passed in FP registers
30985 -mapcs-reentrant Reentrant code
30986 -matpcs
30987 (sometime these will probably be replaced with -mapcs=<list of options>
30988 and -matpcs=<list of options>)
b99bd4ef 30989
c19d1205
ZW
30990 The remaining options are only supported for back-wards compatibility.
30991 Cpu variants, the arm part is optional:
30992 -m[arm]1 Currently not supported.
30993 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30994 -m[arm]3 Arm 3 processor
30995 -m[arm]6[xx], Arm 6 processors
30996 -m[arm]7[xx][t][[d]m] Arm 7 processors
30997 -m[arm]8[10] Arm 8 processors
30998 -m[arm]9[20][tdmi] Arm 9 processors
30999 -mstrongarm[110[0]] StrongARM processors
31000 -mxscale XScale processors
31001 -m[arm]v[2345[t[e]]] Arm architectures
31002 -mall All (except the ARM1)
31003 FP variants:
31004 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
31005 -mfpe-old (No float load/store multiples)
31006 -mvfpxd VFP Single precision
31007 -mvfp All VFP
31008 -mno-fpu Disable all floating point instructions
b99bd4ef 31009
c19d1205
ZW
31010 The following CPU names are recognized:
31011 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31012 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31013 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31014 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31015 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31016 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31017 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 31018
c19d1205 31019 */
b99bd4ef 31020
c19d1205 31021const char * md_shortopts = "m:k";
b99bd4ef 31022
c19d1205
ZW
31023#ifdef ARM_BI_ENDIAN
31024#define OPTION_EB (OPTION_MD_BASE + 0)
31025#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 31026#else
c19d1205
ZW
31027#if TARGET_BYTES_BIG_ENDIAN
31028#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 31029#else
c19d1205
ZW
31030#define OPTION_EL (OPTION_MD_BASE + 1)
31031#endif
b99bd4ef 31032#endif
845b51d6 31033#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 31034#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 31035
c19d1205 31036struct option md_longopts[] =
b99bd4ef 31037{
c19d1205
ZW
31038#ifdef OPTION_EB
31039 {"EB", no_argument, NULL, OPTION_EB},
31040#endif
31041#ifdef OPTION_EL
31042 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 31043#endif
845b51d6 31044 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
31045#ifdef OBJ_ELF
31046 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31047#endif
c19d1205
ZW
31048 {NULL, no_argument, NULL, 0}
31049};
b99bd4ef 31050
c19d1205 31051size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 31052
c19d1205 31053struct arm_option_table
b99bd4ef 31054{
0198d5e6
TC
31055 const char * option; /* Option name to match. */
31056 const char * help; /* Help information. */
31057 int * var; /* Variable to change. */
31058 int value; /* What to change it to. */
31059 const char * deprecated; /* If non-null, print this message. */
c19d1205 31060};
b99bd4ef 31061
c19d1205
ZW
31062struct arm_option_table arm_opts[] =
31063{
31064 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31065 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31066 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31067 &support_interwork, 1, NULL},
31068 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31069 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31070 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31071 1, NULL},
31072 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31073 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31074 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31075 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31076 NULL},
b99bd4ef 31077
c19d1205
ZW
31078 /* These are recognized by the assembler, but have no affect on code. */
31079 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31080 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
31081
31082 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31083 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31084 &warn_on_deprecated, 0, NULL},
24f19ccb
AV
31085
31086 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31087 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31088 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31089
8b2d793c
NC
31090 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31091 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
31092 {NULL, NULL, NULL, 0, NULL}
31093};
31094
31095struct arm_legacy_option_table
31096{
0198d5e6
TC
31097 const char * option; /* Option name to match. */
31098 const arm_feature_set ** var; /* Variable to change. */
31099 const arm_feature_set value; /* What to change it to. */
31100 const char * deprecated; /* If non-null, print this message. */
e74cfd16 31101};
b99bd4ef 31102
e74cfd16
PB
31103const struct arm_legacy_option_table arm_legacy_opts[] =
31104{
c19d1205
ZW
31105 /* DON'T add any new processors to this list -- we want the whole list
31106 to go away... Add them to the processors table instead. */
e74cfd16
PB
31107 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31108 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31109 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31110 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31111 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31112 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31113 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31114 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31115 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31116 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31117 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31118 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31119 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31120 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31121 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31122 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31123 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31124 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31125 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31126 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31127 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31128 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31129 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31130 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31131 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31132 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31133 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31134 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31135 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31136 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31137 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31138 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31139 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31140 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31141 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31142 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31143 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31144 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31145 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31146 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31147 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31148 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31149 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31150 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31151 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31152 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31153 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31154 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31155 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31156 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31157 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31158 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31159 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31160 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31161 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31162 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31163 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31164 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31165 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31166 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31167 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31168 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31169 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31170 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31171 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31172 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31173 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31174 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31175 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31176 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31177 N_("use -mcpu=strongarm110")},
e74cfd16 31178 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31179 N_("use -mcpu=strongarm1100")},
e74cfd16 31180 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31181 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
31182 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31183 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31184 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 31185
c19d1205 31186 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
31187 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31188 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31189 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31190 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31191 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31192 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31193 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31194 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31195 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31196 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31197 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31198 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31199 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31200 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31201 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31202 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31203 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31204 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 31205
c19d1205 31206 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
31207 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31208 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31209 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31210 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 31211 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 31212
e74cfd16 31213 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 31214};
7ed4c4c5 31215
c19d1205 31216struct arm_cpu_option_table
7ed4c4c5 31217{
0198d5e6
TC
31218 const char * name;
31219 size_t name_len;
31220 const arm_feature_set value;
31221 const arm_feature_set ext;
c19d1205
ZW
31222 /* For some CPUs we assume an FPU unless the user explicitly sets
31223 -mfpu=... */
0198d5e6 31224 const arm_feature_set default_fpu;
ee065d83
PB
31225 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31226 case. */
0198d5e6 31227 const char * canonical_name;
c19d1205 31228};
7ed4c4c5 31229
c19d1205
ZW
31230/* This list should, at a minimum, contain all the cpu names
31231 recognized by GCC. */
996b5569 31232#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 31233
e74cfd16 31234static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 31235{
996b5569
TP
31236 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31237 ARM_ARCH_NONE,
31238 FPU_ARCH_FPA),
31239 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31240 ARM_ARCH_NONE,
31241 FPU_ARCH_FPA),
31242 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31243 ARM_ARCH_NONE,
31244 FPU_ARCH_FPA),
31245 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31246 ARM_ARCH_NONE,
31247 FPU_ARCH_FPA),
31248 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31249 ARM_ARCH_NONE,
31250 FPU_ARCH_FPA),
31251 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31252 ARM_ARCH_NONE,
31253 FPU_ARCH_FPA),
31254 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31255 ARM_ARCH_NONE,
31256 FPU_ARCH_FPA),
31257 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31258 ARM_ARCH_NONE,
31259 FPU_ARCH_FPA),
31260 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31261 ARM_ARCH_NONE,
31262 FPU_ARCH_FPA),
31263 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31264 ARM_ARCH_NONE,
31265 FPU_ARCH_FPA),
31266 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31267 ARM_ARCH_NONE,
31268 FPU_ARCH_FPA),
31269 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31270 ARM_ARCH_NONE,
31271 FPU_ARCH_FPA),
31272 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31273 ARM_ARCH_NONE,
31274 FPU_ARCH_FPA),
31275 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31276 ARM_ARCH_NONE,
31277 FPU_ARCH_FPA),
31278 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31279 ARM_ARCH_NONE,
31280 FPU_ARCH_FPA),
31281 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31282 ARM_ARCH_NONE,
31283 FPU_ARCH_FPA),
31284 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31285 ARM_ARCH_NONE,
31286 FPU_ARCH_FPA),
31287 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31288 ARM_ARCH_NONE,
31289 FPU_ARCH_FPA),
31290 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31291 ARM_ARCH_NONE,
31292 FPU_ARCH_FPA),
31293 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31294 ARM_ARCH_NONE,
31295 FPU_ARCH_FPA),
31296 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31297 ARM_ARCH_NONE,
31298 FPU_ARCH_FPA),
31299 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31300 ARM_ARCH_NONE,
31301 FPU_ARCH_FPA),
31302 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31303 ARM_ARCH_NONE,
31304 FPU_ARCH_FPA),
31305 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31306 ARM_ARCH_NONE,
31307 FPU_ARCH_FPA),
31308 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31309 ARM_ARCH_NONE,
31310 FPU_ARCH_FPA),
31311 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31312 ARM_ARCH_NONE,
31313 FPU_ARCH_FPA),
31314 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31315 ARM_ARCH_NONE,
31316 FPU_ARCH_FPA),
31317 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31318 ARM_ARCH_NONE,
31319 FPU_ARCH_FPA),
31320 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31321 ARM_ARCH_NONE,
31322 FPU_ARCH_FPA),
31323 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31324 ARM_ARCH_NONE,
31325 FPU_ARCH_FPA),
31326 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31327 ARM_ARCH_NONE,
31328 FPU_ARCH_FPA),
31329 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31330 ARM_ARCH_NONE,
31331 FPU_ARCH_FPA),
31332 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31333 ARM_ARCH_NONE,
31334 FPU_ARCH_FPA),
31335 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31336 ARM_ARCH_NONE,
31337 FPU_ARCH_FPA),
31338 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31339 ARM_ARCH_NONE,
31340 FPU_ARCH_FPA),
31341 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31342 ARM_ARCH_NONE,
31343 FPU_ARCH_FPA),
31344 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31345 ARM_ARCH_NONE,
31346 FPU_ARCH_FPA),
31347 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31348 ARM_ARCH_NONE,
31349 FPU_ARCH_FPA),
31350 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31351 ARM_ARCH_NONE,
31352 FPU_ARCH_FPA),
31353 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31354 ARM_ARCH_NONE,
31355 FPU_ARCH_FPA),
31356 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31357 ARM_ARCH_NONE,
31358 FPU_ARCH_FPA),
31359 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31360 ARM_ARCH_NONE,
31361 FPU_ARCH_FPA),
31362 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31363 ARM_ARCH_NONE,
31364 FPU_ARCH_FPA),
31365 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31366 ARM_ARCH_NONE,
31367 FPU_ARCH_FPA),
31368 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31369 ARM_ARCH_NONE,
31370 FPU_ARCH_FPA),
31371 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31372 ARM_ARCH_NONE,
31373 FPU_ARCH_FPA),
31374
c19d1205
ZW
31375 /* For V5 or later processors we default to using VFP; but the user
31376 should really set the FPU type explicitly. */
996b5569
TP
31377 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31378 ARM_ARCH_NONE,
31379 FPU_ARCH_VFP_V2),
31380 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31381 ARM_ARCH_NONE,
31382 FPU_ARCH_VFP_V2),
31383 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31384 ARM_ARCH_NONE,
31385 FPU_ARCH_VFP_V2),
31386 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31387 ARM_ARCH_NONE,
31388 FPU_ARCH_VFP_V2),
31389 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31390 ARM_ARCH_NONE,
31391 FPU_ARCH_VFP_V2),
31392 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31393 ARM_ARCH_NONE,
31394 FPU_ARCH_VFP_V2),
31395 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31396 ARM_ARCH_NONE,
31397 FPU_ARCH_VFP_V2),
31398 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31399 ARM_ARCH_NONE,
31400 FPU_ARCH_VFP_V2),
31401 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31402 ARM_ARCH_NONE,
31403 FPU_ARCH_VFP_V2),
31404 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31405 ARM_ARCH_NONE,
31406 FPU_ARCH_VFP_V2),
31407 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31408 ARM_ARCH_NONE,
31409 FPU_ARCH_VFP_V2),
31410 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31411 ARM_ARCH_NONE,
31412 FPU_ARCH_VFP_V2),
31413 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31414 ARM_ARCH_NONE,
31415 FPU_ARCH_VFP_V1),
31416 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31417 ARM_ARCH_NONE,
31418 FPU_ARCH_VFP_V1),
31419 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31420 ARM_ARCH_NONE,
31421 FPU_ARCH_VFP_V2),
31422 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31423 ARM_ARCH_NONE,
31424 FPU_ARCH_VFP_V2),
31425 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31426 ARM_ARCH_NONE,
31427 FPU_ARCH_VFP_V1),
31428 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31429 ARM_ARCH_NONE,
31430 FPU_ARCH_VFP_V2),
31431 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31432 ARM_ARCH_NONE,
31433 FPU_ARCH_VFP_V2),
31434 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31435 ARM_ARCH_NONE,
31436 FPU_ARCH_VFP_V2),
31437 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31438 ARM_ARCH_NONE,
31439 FPU_ARCH_VFP_V2),
31440 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31441 ARM_ARCH_NONE,
31442 FPU_ARCH_VFP_V2),
31443 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31444 ARM_ARCH_NONE,
31445 FPU_ARCH_VFP_V2),
31446 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31447 ARM_ARCH_NONE,
31448 FPU_ARCH_VFP_V2),
31449 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31450 ARM_ARCH_NONE,
31451 FPU_ARCH_VFP_V2),
31452 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31453 ARM_ARCH_NONE,
31454 FPU_ARCH_VFP_V2),
31455 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31456 ARM_ARCH_NONE,
31457 FPU_NONE),
31458 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31459 ARM_ARCH_NONE,
31460 FPU_NONE),
31461 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31462 ARM_ARCH_NONE,
31463 FPU_ARCH_VFP_V2),
31464 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31465 ARM_ARCH_NONE,
31466 FPU_ARCH_VFP_V2),
31467 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31468 ARM_ARCH_NONE,
31469 FPU_ARCH_VFP_V2),
31470 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31471 ARM_ARCH_NONE,
31472 FPU_NONE),
31473 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31474 ARM_ARCH_NONE,
31475 FPU_NONE),
31476 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31477 ARM_ARCH_NONE,
31478 FPU_ARCH_VFP_V2),
31479 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31480 ARM_ARCH_NONE,
31481 FPU_NONE),
31482 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31483 ARM_ARCH_NONE,
31484 FPU_ARCH_VFP_V2),
31485 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31486 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31487 FPU_NONE),
31488 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31489 ARM_ARCH_NONE,
31490 FPU_ARCH_NEON_VFP_V4),
31491 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31492 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31493 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31494 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31495 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31496 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31497 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31498 ARM_ARCH_NONE,
31499 FPU_ARCH_NEON_VFP_V4),
31500 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31501 ARM_ARCH_NONE,
31502 FPU_ARCH_NEON_VFP_V4),
31503 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31504 ARM_ARCH_NONE,
31505 FPU_ARCH_NEON_VFP_V4),
31506 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
8b301fbb 31507 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31508 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31509 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
8b301fbb 31510 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31511 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31512 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
8b301fbb 31513 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31514 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31515 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31516 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31517 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569 31518 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
8b301fbb 31519 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31520 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31521 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
8b301fbb 31522 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31523 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31524 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
8b301fbb 31525 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31526 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31527 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31528 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31529 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 31530 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31531 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31532 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
0535e5d7
DZ
31533 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31534 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31536 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31537 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31538 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
31539 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31540 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31541 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
31542 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31543 ARM_ARCH_NONE,
31544 FPU_NONE),
31545 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31546 ARM_ARCH_NONE,
31547 FPU_ARCH_VFP_V3D16),
31548 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31549 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31550 FPU_NONE),
31551 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31552 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31553 FPU_ARCH_VFP_V3D16),
31554 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31555 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31556 FPU_ARCH_VFP_V3D16),
0cda1e19 31557 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
8b301fbb 31558 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
0cda1e19 31559 FPU_ARCH_NEON_VFP_ARMV8),
0535e5d7
DZ
31560 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31561 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31562 FPU_NONE),
996b5569
TP
31563 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31564 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31565 FPU_NONE),
31566 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31567 ARM_ARCH_NONE,
31568 FPU_NONE),
31569 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31570 ARM_ARCH_NONE,
31571 FPU_NONE),
31572 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31573 ARM_ARCH_NONE,
31574 FPU_NONE),
31575 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31576 ARM_ARCH_NONE,
31577 FPU_NONE),
31578 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31579 ARM_ARCH_NONE,
31580 FPU_NONE),
31581 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31582 ARM_ARCH_NONE,
31583 FPU_NONE),
31584 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31585 ARM_ARCH_NONE,
31586 FPU_NONE),
31587 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
8b301fbb 31588 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31589 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
31590 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31591 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31592 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 31593 /* ??? XSCALE is really an architecture. */
996b5569
TP
31594 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31595 ARM_ARCH_NONE,
31596 FPU_ARCH_VFP_V2),
31597
c19d1205 31598 /* ??? iwmmxt is not a processor. */
996b5569
TP
31599 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31600 ARM_ARCH_NONE,
31601 FPU_ARCH_VFP_V2),
31602 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31603 ARM_ARCH_NONE,
31604 FPU_ARCH_VFP_V2),
31605 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31606 ARM_ARCH_NONE,
31607 FPU_ARCH_VFP_V2),
31608
0198d5e6 31609 /* Maverick. */
996b5569
TP
31610 ARM_CPU_OPT ("ep9312", "ARM920T",
31611 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31612 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31613
da4339ed 31614 /* Marvell processors. */
996b5569
TP
31615 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31616 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31617 FPU_ARCH_VFP_V3D16),
31618 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31619 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31620 FPU_ARCH_NEON_VFP_V4),
da4339ed 31621
996b5569
TP
31622 /* APM X-Gene family. */
31623 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31624 ARM_ARCH_NONE,
31625 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31626 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
8b301fbb 31627 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31628 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31629
31630 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31631};
f3bad469 31632#undef ARM_CPU_OPT
7ed4c4c5 31633
34ef62f4
AV
31634struct arm_ext_table
31635{
31636 const char * name;
31637 size_t name_len;
31638 const arm_feature_set merge;
31639 const arm_feature_set clear;
31640};
31641
c19d1205 31642struct arm_arch_option_table
7ed4c4c5 31643{
34ef62f4
AV
31644 const char * name;
31645 size_t name_len;
31646 const arm_feature_set value;
31647 const arm_feature_set default_fpu;
31648 const struct arm_ext_table * ext_table;
31649};
31650
31651/* Used to add support for +E and +noE extension. */
31652#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31653/* Used to add support for a +E extension. */
31654#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31655/* Used to add support for a +noE extension. */
31656#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31657
31658#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31659 ~0 & ~FPU_ENDIAN_PURE)
31660
31661static const struct arm_ext_table armv5te_ext_table[] =
31662{
31663 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31664 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31665};
31666
31667static const struct arm_ext_table armv7_ext_table[] =
31668{
31669 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31670 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31671};
31672
31673static const struct arm_ext_table armv7ve_ext_table[] =
31674{
31675 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31676 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31677 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31678 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31679 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31680 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31681 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31682
31683 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31684 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31685
31686 /* Aliases for +simd. */
31687 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31688
31689 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31690 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31691 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31692
31693 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31694};
31695
31696static const struct arm_ext_table armv7a_ext_table[] =
31697{
31698 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31699 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31700 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31701 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31702 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31703 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31704 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31705
31706 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31707 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31708
31709 /* Aliases for +simd. */
31710 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31711 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31712
31713 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31714 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31715
31716 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31717 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31718 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31719};
31720
31721static const struct arm_ext_table armv7r_ext_table[] =
31722{
31723 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31724 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31725 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31726 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31727 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31728 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31729 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31730 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31731 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31732};
31733
31734static const struct arm_ext_table armv7em_ext_table[] =
31735{
31736 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31737 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31738 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31739 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31740 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31741 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31742 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31743};
31744
31745static const struct arm_ext_table armv8a_ext_table[] =
31746{
8b301fbb 31747 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31748 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31749 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31750 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31751
31752 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31753 should use the +simd option to turn on FP. */
31754 ARM_REMOVE ("fp", ALL_FP),
31755 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31756 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31757 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31758};
31759
31760
31761static const struct arm_ext_table armv81a_ext_table[] =
31762{
31763 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31764 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31765 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31766
31767 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31768 should use the +simd option to turn on FP. */
31769 ARM_REMOVE ("fp", ALL_FP),
31770 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31771 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31772 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31773};
31774
31775static const struct arm_ext_table armv82a_ext_table[] =
31776{
31777 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31778 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31779 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
616ce08e
MM
31780 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31781 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31782 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31783 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31784 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31785
31786 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31787 should use the +simd option to turn on FP. */
31788 ARM_REMOVE ("fp", ALL_FP),
31789 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31790 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31791 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31792};
31793
31794static const struct arm_ext_table armv84a_ext_table[] =
31795{
31796 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31797 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31798 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31799 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31800 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31801 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31802
31803 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31804 should use the +simd option to turn on FP. */
31805 ARM_REMOVE ("fp", ALL_FP),
31806 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31807 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31808 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31809};
31810
31811static const struct arm_ext_table armv85a_ext_table[] =
31812{
31813 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31814 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31815 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31816 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31817 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31818 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31819
31820 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31821 should use the +simd option to turn on FP. */
31822 ARM_REMOVE ("fp", ALL_FP),
31823 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31824};
31825
aab2c27d
MM
31826static const struct arm_ext_table armv86a_ext_table[] =
31827{
616ce08e 31828 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
aab2c27d
MM
31829 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31830};
31831
4934a27c
MM
31832#define CDE_EXTENSIONS \
31833 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31834 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31835 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31836 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31837 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31838 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31839 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31840 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31841
34ef62f4
AV
31842static const struct arm_ext_table armv8m_main_ext_table[] =
31843{
92169145
AV
31844 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31845 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
34ef62f4
AV
31846 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31847 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
4934a27c 31848 CDE_EXTENSIONS,
34ef62f4
AV
31849 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31850};
31851
92169145 31852
e0991585
AV
31853static const struct arm_ext_table armv8_1m_main_ext_table[] =
31854{
92169145
AV
31855 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31856 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
e0991585
AV
31857 ARM_EXT ("fp",
31858 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31859 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31860 ALL_FP),
31861 ARM_ADD ("fp.dp",
31862 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31863 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
92169145 31864 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
2da2eaf4 31865 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
a7ad558c 31866 ARM_ADD ("mve.fp",
92169145
AV
31867 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31868 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
2da2eaf4 31869 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
4934a27c 31870 CDE_EXTENSIONS,
e0991585
AV
31871 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31872};
31873
4934a27c
MM
31874#undef CDE_EXTENSIONS
31875
34ef62f4
AV
31876static const struct arm_ext_table armv8r_ext_table[] =
31877{
8b301fbb 31878 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31879 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31880 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31881 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31882 ARM_REMOVE ("fp", ALL_FP),
31883 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31884 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 31885};
7ed4c4c5 31886
c19d1205
ZW
31887/* This list should, at a minimum, contain all the architecture names
31888 recognized by GCC. */
34ef62f4
AV
31889#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31890#define ARM_ARCH_OPT2(N, V, DF, ext) \
31891 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 31892
e74cfd16 31893static const struct arm_arch_option_table arm_archs[] =
c19d1205 31894{
497d849d
TP
31895 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31896 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31897 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31898 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31899 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31900 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31901 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31902 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31903 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31904 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31905 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31906 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31907 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31908 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
31909 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31910 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31911 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31912 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31913 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31914 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31915 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31916 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31917 kept to preserve existing behaviour. */
34ef62f4
AV
31918 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31919 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31920 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31921 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31922 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31923 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31924 kept to preserve existing behaviour. */
34ef62f4
AV
31925 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31926 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
31927 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31928 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 31929 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
31930 /* The official spelling of the ARMv7 profile variants is the dashed form.
31931 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
31932 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31933 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31934 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31935 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
31936 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31937 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31938 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 31939 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 31940 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
31941 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31942 armv8m_main),
e0991585
AV
31943 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31944 armv8_1m_main),
34ef62f4
AV
31945 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31946 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31947 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31948 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31949 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31950 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31951 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
aab2c27d 31952 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
497d849d
TP
31953 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31954 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31955 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 31956 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31957};
f3bad469 31958#undef ARM_ARCH_OPT
7ed4c4c5 31959
69133863 31960/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 31961
69133863 31962struct arm_option_extension_value_table
c19d1205 31963{
0198d5e6
TC
31964 const char * name;
31965 size_t name_len;
31966 const arm_feature_set merge_value;
31967 const arm_feature_set clear_value;
d942732e
TP
31968 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31969 indicates that an extension is available for all architectures while
31970 ARM_ANY marks an empty entry. */
0198d5e6 31971 const arm_feature_set allowed_archs[2];
c19d1205 31972};
7ed4c4c5 31973
0198d5e6
TC
31974/* The following table must be in alphabetical order with a NULL last entry. */
31975
d942732e
TP
31976#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31977#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 31978
34ef62f4
AV
31979/* DEPRECATED: Refrain from using this table to add any new extensions, instead
31980 use the context sensitive approach using arm_ext_table's. */
69133863 31981static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 31982{
8b301fbb
MI
31983 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31984 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
823d2571 31985 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 31986 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
31987 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31988 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
31989 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31990 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31991 ARM_ARCH_V8_2A),
15afaa63
TP
31992 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31993 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31994 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
31995 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31996 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
31997 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31998 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31999 ARM_ARCH_V8_2A),
01f48020
TC
32000 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32001 | ARM_EXT2_FP16_FML),
32002 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32003 | ARM_EXT2_FP16_FML),
32004 ARM_ARCH_V8_2A),
d942732e 32005 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 32006 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
32007 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32008 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
32009 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32010 Thumb divide instruction. Due to this having the same name as the
32011 previous entry, this will be ignored when doing command-line parsing and
32012 only considered by build attribute selection code. */
32013 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32014 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32015 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 32016 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 32017 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 32018 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 32019 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 32020 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
32021 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32022 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 32023 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
32024 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32025 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
32026 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32027 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32028 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
32029 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32030 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 32031 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
32032 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32033 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32034 ARM_ARCH_V8A),
4d1464f2
MW
32035 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32036 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 32037 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
32038 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32039 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 32040 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
32041 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32042 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32043 ARM_ARCH_V8A),
d942732e 32044 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 32045 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
32046 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32047 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
32048 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32049 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32050 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
32051 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32052 | ARM_EXT_DIV),
32053 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32054 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32055 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
32056 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32057 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 32058};
f3bad469 32059#undef ARM_EXT_OPT
69133863
MGD
32060
32061/* ISA floating-point and Advanced SIMD extensions. */
32062struct arm_option_fpu_value_table
32063{
0198d5e6
TC
32064 const char * name;
32065 const arm_feature_set value;
c19d1205 32066};
7ed4c4c5 32067
c19d1205
ZW
32068/* This list should, at a minimum, contain all the fpu names
32069 recognized by GCC. */
69133863 32070static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
32071{
32072 {"softfpa", FPU_NONE},
32073 {"fpe", FPU_ARCH_FPE},
32074 {"fpe2", FPU_ARCH_FPE},
32075 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32076 {"fpa", FPU_ARCH_FPA},
32077 {"fpa10", FPU_ARCH_FPA},
32078 {"fpa11", FPU_ARCH_FPA},
32079 {"arm7500fe", FPU_ARCH_FPA},
32080 {"softvfp", FPU_ARCH_VFP},
32081 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32082 {"vfp", FPU_ARCH_VFP_V2},
32083 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 32084 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
32085 {"vfp10", FPU_ARCH_VFP_V2},
32086 {"vfp10-r0", FPU_ARCH_VFP_V1},
32087 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
32088 {"vfpv2", FPU_ARCH_VFP_V2},
32089 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 32090 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 32091 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
32092 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32093 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32094 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
32095 {"arm1020t", FPU_ARCH_VFP_V1},
32096 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 32097 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
32098 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32099 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 32100 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 32101 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 32102 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
32103 {"vfpv4", FPU_ARCH_VFP_V4},
32104 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 32105 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
32106 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32107 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 32108 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
32109 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32110 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32111 {"crypto-neon-fp-armv8",
32112 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 32113 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
32114 {"crypto-neon-fp-armv8.1",
32115 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
32116 {NULL, ARM_ARCH_NONE}
32117};
32118
32119struct arm_option_value_table
32120{
e0471c16 32121 const char *name;
e74cfd16 32122 long value;
c19d1205 32123};
7ed4c4c5 32124
e74cfd16 32125static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
32126{
32127 {"hard", ARM_FLOAT_ABI_HARD},
32128 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32129 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 32130 {NULL, 0}
c19d1205 32131};
7ed4c4c5 32132
c19d1205 32133#ifdef OBJ_ELF
3a4a14e9 32134/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 32135static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
32136{
32137 {"gnu", EF_ARM_EABI_UNKNOWN},
32138 {"4", EF_ARM_EABI_VER4},
3a4a14e9 32139 {"5", EF_ARM_EABI_VER5},
e74cfd16 32140 {NULL, 0}
c19d1205
ZW
32141};
32142#endif
7ed4c4c5 32143
c19d1205
ZW
32144struct arm_long_option_table
32145{
0198d5e6 32146 const char * option; /* Substring to match. */
e0471c16 32147 const char * help; /* Help information. */
17b9d67d 32148 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 32149 const char * deprecated; /* If non-null, print this message. */
c19d1205 32150};
7ed4c4c5 32151
c921be7d 32152static bfd_boolean
c168ce07 32153arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
32154 arm_feature_set *ext_set,
32155 const struct arm_ext_table *ext_table)
7ed4c4c5 32156{
69133863 32157 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
32158 extensions being added before being removed. We achieve this by having
32159 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 32160 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 32161 or removing it (0) and only allowing it to change in the order
69133863
MGD
32162 -1 -> 1 -> 0. */
32163 const struct arm_option_extension_value_table * opt = NULL;
d942732e 32164 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
32165 int adding_value = -1;
32166
c19d1205 32167 while (str != NULL && *str != 0)
7ed4c4c5 32168 {
82b8a785 32169 const char *ext;
f3bad469 32170 size_t len;
7ed4c4c5 32171
c19d1205
ZW
32172 if (*str != '+')
32173 {
32174 as_bad (_("invalid architectural extension"));
c921be7d 32175 return FALSE;
c19d1205 32176 }
7ed4c4c5 32177
c19d1205
ZW
32178 str++;
32179 ext = strchr (str, '+');
7ed4c4c5 32180
c19d1205 32181 if (ext != NULL)
f3bad469 32182 len = ext - str;
c19d1205 32183 else
f3bad469 32184 len = strlen (str);
7ed4c4c5 32185
f3bad469 32186 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
32187 {
32188 if (adding_value != 0)
32189 {
32190 adding_value = 0;
32191 opt = arm_extensions;
32192 }
32193
f3bad469 32194 len -= 2;
69133863
MGD
32195 str += 2;
32196 }
f3bad469 32197 else if (len > 0)
69133863
MGD
32198 {
32199 if (adding_value == -1)
32200 {
32201 adding_value = 1;
32202 opt = arm_extensions;
32203 }
32204 else if (adding_value != 1)
32205 {
32206 as_bad (_("must specify extensions to add before specifying "
32207 "those to remove"));
32208 return FALSE;
32209 }
32210 }
32211
f3bad469 32212 if (len == 0)
c19d1205
ZW
32213 {
32214 as_bad (_("missing architectural extension"));
c921be7d 32215 return FALSE;
c19d1205 32216 }
7ed4c4c5 32217
69133863
MGD
32218 gas_assert (adding_value != -1);
32219 gas_assert (opt != NULL);
32220
34ef62f4
AV
32221 if (ext_table != NULL)
32222 {
32223 const struct arm_ext_table * ext_opt = ext_table;
32224 bfd_boolean found = FALSE;
32225 for (; ext_opt->name != NULL; ext_opt++)
32226 if (ext_opt->name_len == len
32227 && strncmp (ext_opt->name, str, len) == 0)
32228 {
32229 if (adding_value)
32230 {
32231 if (ARM_FEATURE_ZERO (ext_opt->merge))
32232 /* TODO: Option not supported. When we remove the
32233 legacy table this case should error out. */
32234 continue;
32235
32236 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32237 }
32238 else
32239 {
32240 if (ARM_FEATURE_ZERO (ext_opt->clear))
32241 /* TODO: Option not supported. When we remove the
32242 legacy table this case should error out. */
32243 continue;
32244 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32245 }
32246 found = TRUE;
32247 break;
32248 }
32249 if (found)
32250 {
32251 str = ext;
32252 continue;
32253 }
32254 }
32255
69133863
MGD
32256 /* Scan over the options table trying to find an exact match. */
32257 for (; opt->name != NULL; opt++)
f3bad469 32258 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32259 {
d942732e
TP
32260 int i, nb_allowed_archs =
32261 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 32262 /* Check we can apply the extension to this architecture. */
d942732e
TP
32263 for (i = 0; i < nb_allowed_archs; i++)
32264 {
32265 /* Empty entry. */
32266 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32267 continue;
c168ce07 32268 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
32269 break;
32270 }
32271 if (i == nb_allowed_archs)
69133863
MGD
32272 {
32273 as_bad (_("extension does not apply to the base architecture"));
32274 return FALSE;
32275 }
32276
32277 /* Add or remove the extension. */
32278 if (adding_value)
4d354d8b 32279 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 32280 else
4d354d8b 32281 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 32282
3d030cdb
TP
32283 /* Allowing Thumb division instructions for ARMv7 in autodetection
32284 rely on this break so that duplicate extensions (extensions
32285 with the same name as a previous extension in the list) are not
32286 considered for command-line parsing. */
c19d1205
ZW
32287 break;
32288 }
7ed4c4c5 32289
c19d1205
ZW
32290 if (opt->name == NULL)
32291 {
69133863
MGD
32292 /* Did we fail to find an extension because it wasn't specified in
32293 alphabetical order, or because it does not exist? */
32294
32295 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 32296 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
32297 break;
32298
32299 if (opt->name == NULL)
32300 as_bad (_("unknown architectural extension `%s'"), str);
32301 else
32302 as_bad (_("architectural extensions must be specified in "
32303 "alphabetical order"));
32304
c921be7d 32305 return FALSE;
c19d1205 32306 }
69133863
MGD
32307 else
32308 {
32309 /* We should skip the extension we've just matched the next time
32310 round. */
32311 opt++;
32312 }
7ed4c4c5 32313
c19d1205
ZW
32314 str = ext;
32315 };
7ed4c4c5 32316
c921be7d 32317 return TRUE;
c19d1205 32318}
7ed4c4c5 32319
5312fe52
BW
32320static bfd_boolean
32321arm_parse_fp16_opt (const char *str)
32322{
32323 if (strcasecmp (str, "ieee") == 0)
32324 fp16_format = ARM_FP16_FORMAT_IEEE;
32325 else if (strcasecmp (str, "alternative") == 0)
32326 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32327 else
32328 {
32329 as_bad (_("unrecognised float16 format \"%s\""), str);
32330 return FALSE;
32331 }
32332
32333 return TRUE;
32334}
32335
c921be7d 32336static bfd_boolean
17b9d67d 32337arm_parse_cpu (const char *str)
7ed4c4c5 32338{
f3bad469 32339 const struct arm_cpu_option_table *opt;
82b8a785 32340 const char *ext = strchr (str, '+');
f3bad469 32341 size_t len;
7ed4c4c5 32342
c19d1205 32343 if (ext != NULL)
f3bad469 32344 len = ext - str;
7ed4c4c5 32345 else
f3bad469 32346 len = strlen (str);
7ed4c4c5 32347
f3bad469 32348 if (len == 0)
7ed4c4c5 32349 {
c19d1205 32350 as_bad (_("missing cpu name `%s'"), str);
c921be7d 32351 return FALSE;
7ed4c4c5
NC
32352 }
32353
c19d1205 32354 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 32355 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32356 {
c168ce07 32357 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
32358 if (mcpu_ext_opt == NULL)
32359 mcpu_ext_opt = XNEW (arm_feature_set);
32360 *mcpu_ext_opt = opt->ext;
e74cfd16 32361 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 32362 if (opt->canonical_name)
ef8e6722
JW
32363 {
32364 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32365 strcpy (selected_cpu_name, opt->canonical_name);
32366 }
ee065d83
PB
32367 else
32368 {
f3bad469 32369 size_t i;
c921be7d 32370
ef8e6722
JW
32371 if (len >= sizeof selected_cpu_name)
32372 len = (sizeof selected_cpu_name) - 1;
32373
f3bad469 32374 for (i = 0; i < len; i++)
ee065d83
PB
32375 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32376 selected_cpu_name[i] = 0;
32377 }
7ed4c4c5 32378
c19d1205 32379 if (ext != NULL)
34ef62f4 32380 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 32381
c921be7d 32382 return TRUE;
c19d1205 32383 }
7ed4c4c5 32384
c19d1205 32385 as_bad (_("unknown cpu `%s'"), str);
c921be7d 32386 return FALSE;
7ed4c4c5
NC
32387}
32388
c921be7d 32389static bfd_boolean
17b9d67d 32390arm_parse_arch (const char *str)
7ed4c4c5 32391{
e74cfd16 32392 const struct arm_arch_option_table *opt;
82b8a785 32393 const char *ext = strchr (str, '+');
f3bad469 32394 size_t len;
7ed4c4c5 32395
c19d1205 32396 if (ext != NULL)
f3bad469 32397 len = ext - str;
7ed4c4c5 32398 else
f3bad469 32399 len = strlen (str);
7ed4c4c5 32400
f3bad469 32401 if (len == 0)
7ed4c4c5 32402 {
c19d1205 32403 as_bad (_("missing architecture name `%s'"), str);
c921be7d 32404 return FALSE;
7ed4c4c5
NC
32405 }
32406
c19d1205 32407 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 32408 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32409 {
e74cfd16 32410 march_cpu_opt = &opt->value;
4d354d8b
TP
32411 if (march_ext_opt == NULL)
32412 march_ext_opt = XNEW (arm_feature_set);
32413 *march_ext_opt = arm_arch_none;
e74cfd16 32414 march_fpu_opt = &opt->default_fpu;
e20f9590 32415 selected_ctx_ext_table = opt->ext_table;
5f4273c7 32416 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 32417
c19d1205 32418 if (ext != NULL)
34ef62f4
AV
32419 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32420 opt->ext_table);
7ed4c4c5 32421
c921be7d 32422 return TRUE;
c19d1205
ZW
32423 }
32424
32425 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 32426 return FALSE;
7ed4c4c5 32427}
eb043451 32428
c921be7d 32429static bfd_boolean
17b9d67d 32430arm_parse_fpu (const char * str)
c19d1205 32431{
69133863 32432 const struct arm_option_fpu_value_table * opt;
b99bd4ef 32433
c19d1205
ZW
32434 for (opt = arm_fpus; opt->name != NULL; opt++)
32435 if (streq (opt->name, str))
32436 {
e74cfd16 32437 mfpu_opt = &opt->value;
c921be7d 32438 return TRUE;
c19d1205 32439 }
b99bd4ef 32440
c19d1205 32441 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 32442 return FALSE;
c19d1205
ZW
32443}
32444
c921be7d 32445static bfd_boolean
17b9d67d 32446arm_parse_float_abi (const char * str)
b99bd4ef 32447{
e74cfd16 32448 const struct arm_option_value_table * opt;
b99bd4ef 32449
c19d1205
ZW
32450 for (opt = arm_float_abis; opt->name != NULL; opt++)
32451 if (streq (opt->name, str))
32452 {
32453 mfloat_abi_opt = opt->value;
c921be7d 32454 return TRUE;
c19d1205 32455 }
cc8a6dd0 32456
c19d1205 32457 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 32458 return FALSE;
c19d1205 32459}
b99bd4ef 32460
c19d1205 32461#ifdef OBJ_ELF
c921be7d 32462static bfd_boolean
17b9d67d 32463arm_parse_eabi (const char * str)
c19d1205 32464{
e74cfd16 32465 const struct arm_option_value_table *opt;
cc8a6dd0 32466
c19d1205
ZW
32467 for (opt = arm_eabis; opt->name != NULL; opt++)
32468 if (streq (opt->name, str))
32469 {
32470 meabi_flags = opt->value;
c921be7d 32471 return TRUE;
c19d1205
ZW
32472 }
32473 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 32474 return FALSE;
c19d1205
ZW
32475}
32476#endif
cc8a6dd0 32477
c921be7d 32478static bfd_boolean
17b9d67d 32479arm_parse_it_mode (const char * str)
e07e6e58 32480{
c921be7d 32481 bfd_boolean ret = TRUE;
e07e6e58
NC
32482
32483 if (streq ("arm", str))
32484 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32485 else if (streq ("thumb", str))
32486 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32487 else if (streq ("always", str))
32488 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32489 else if (streq ("never", str))
32490 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32491 else
32492 {
32493 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 32494 "arm, thumb, always, or never."), str);
c921be7d 32495 ret = FALSE;
e07e6e58
NC
32496 }
32497
32498 return ret;
32499}
32500
2e6976a8 32501static bfd_boolean
17b9d67d 32502arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
32503{
32504 codecomposer_syntax = TRUE;
32505 arm_comment_chars[0] = ';';
32506 arm_line_separator_chars[0] = 0;
32507 return TRUE;
32508}
32509
c19d1205
ZW
32510struct arm_long_option_table arm_long_opts[] =
32511{
32512 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32513 arm_parse_cpu, NULL},
32514 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32515 arm_parse_arch, NULL},
32516 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32517 arm_parse_fpu, NULL},
32518 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32519 arm_parse_float_abi, NULL},
32520#ifdef OBJ_ELF
7fac0536 32521 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
32522 arm_parse_eabi, NULL},
32523#endif
e07e6e58
NC
32524 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32525 arm_parse_it_mode, NULL},
2e6976a8
DG
32526 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32527 arm_ccs_mode, NULL},
5312fe52
BW
32528 {"mfp16-format=",
32529 N_("[ieee|alternative]\n\
32530 set the encoding for half precision floating point "
32531 "numbers to IEEE\n\
32532 or Arm alternative format."),
32533 arm_parse_fp16_opt, NULL },
c19d1205
ZW
32534 {NULL, NULL, 0, NULL}
32535};
cc8a6dd0 32536
c19d1205 32537int
17b9d67d 32538md_parse_option (int c, const char * arg)
c19d1205
ZW
32539{
32540 struct arm_option_table *opt;
e74cfd16 32541 const struct arm_legacy_option_table *fopt;
c19d1205 32542 struct arm_long_option_table *lopt;
b99bd4ef 32543
c19d1205 32544 switch (c)
b99bd4ef 32545 {
c19d1205
ZW
32546#ifdef OPTION_EB
32547 case OPTION_EB:
32548 target_big_endian = 1;
32549 break;
32550#endif
cc8a6dd0 32551
c19d1205
ZW
32552#ifdef OPTION_EL
32553 case OPTION_EL:
32554 target_big_endian = 0;
32555 break;
32556#endif
b99bd4ef 32557
845b51d6
PB
32558 case OPTION_FIX_V4BX:
32559 fix_v4bx = TRUE;
32560 break;
32561
18a20338
CL
32562#ifdef OBJ_ELF
32563 case OPTION_FDPIC:
32564 arm_fdpic = TRUE;
32565 break;
32566#endif /* OBJ_ELF */
32567
c19d1205
ZW
32568 case 'a':
32569 /* Listing option. Just ignore these, we don't support additional
32570 ones. */
32571 return 0;
b99bd4ef 32572
c19d1205
ZW
32573 default:
32574 for (opt = arm_opts; opt->option != NULL; opt++)
32575 {
32576 if (c == opt->option[0]
32577 && ((arg == NULL && opt->option[1] == 0)
32578 || streq (arg, opt->option + 1)))
32579 {
c19d1205 32580 /* If the option is deprecated, tell the user. */
278df34e 32581 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
32582 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32583 arg ? arg : "", _(opt->deprecated));
b99bd4ef 32584
c19d1205
ZW
32585 if (opt->var != NULL)
32586 *opt->var = opt->value;
cc8a6dd0 32587
c19d1205
ZW
32588 return 1;
32589 }
32590 }
b99bd4ef 32591
e74cfd16
PB
32592 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32593 {
32594 if (c == fopt->option[0]
32595 && ((arg == NULL && fopt->option[1] == 0)
32596 || streq (arg, fopt->option + 1)))
32597 {
e74cfd16 32598 /* If the option is deprecated, tell the user. */
278df34e 32599 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
32600 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32601 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
32602
32603 if (fopt->var != NULL)
32604 *fopt->var = &fopt->value;
32605
32606 return 1;
32607 }
32608 }
32609
c19d1205
ZW
32610 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32611 {
32612 /* These options are expected to have an argument. */
32613 if (c == lopt->option[0]
32614 && arg != NULL
32615 && strncmp (arg, lopt->option + 1,
32616 strlen (lopt->option + 1)) == 0)
32617 {
c19d1205 32618 /* If the option is deprecated, tell the user. */
278df34e 32619 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
32620 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32621 _(lopt->deprecated));
b99bd4ef 32622
c19d1205
ZW
32623 /* Call the sup-option parser. */
32624 return lopt->func (arg + strlen (lopt->option) - 1);
32625 }
32626 }
a737bd4d 32627
c19d1205
ZW
32628 return 0;
32629 }
a394c00f 32630
c19d1205
ZW
32631 return 1;
32632}
a394c00f 32633
c19d1205
ZW
32634void
32635md_show_usage (FILE * fp)
a394c00f 32636{
c19d1205
ZW
32637 struct arm_option_table *opt;
32638 struct arm_long_option_table *lopt;
a394c00f 32639
c19d1205 32640 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 32641
c19d1205
ZW
32642 for (opt = arm_opts; opt->option != NULL; opt++)
32643 if (opt->help != NULL)
32644 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 32645
c19d1205
ZW
32646 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32647 if (lopt->help != NULL)
32648 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 32649
c19d1205
ZW
32650#ifdef OPTION_EB
32651 fprintf (fp, _("\
32652 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
32653#endif
32654
c19d1205
ZW
32655#ifdef OPTION_EL
32656 fprintf (fp, _("\
32657 -EL assemble code for a little-endian cpu\n"));
a737bd4d 32658#endif
845b51d6
PB
32659
32660 fprintf (fp, _("\
32661 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
32662
32663#ifdef OBJ_ELF
32664 fprintf (fp, _("\
32665 --fdpic generate an FDPIC object file\n"));
32666#endif /* OBJ_ELF */
c19d1205 32667}
ee065d83 32668
ee065d83 32669#ifdef OBJ_ELF
0198d5e6 32670
62b3e311
PB
32671typedef struct
32672{
32673 int val;
32674 arm_feature_set flags;
32675} cpu_arch_ver_table;
32676
2c6b98ea
TP
32677/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32678 chronologically for architectures, with an exception for ARMv6-M and
32679 ARMv6S-M due to legacy reasons. No new architecture should have a
32680 special case. This allows for build attribute selection results to be
32681 stable when new architectures are added. */
62b3e311
PB
32682static const cpu_arch_ver_table cpu_arch_ver[] =
32683{
031254f2
AV
32684 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32685 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32686 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32687 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32688 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32689 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32690 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32691 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32692 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32693 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32694 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32695 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32696 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32697 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32698 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32699 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32700 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32701 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32702 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32703 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32704 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32705 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32706 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32707 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
32708
32709 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32710 always selected build attributes to match those of ARMv6-M
32711 (resp. ARMv6S-M). However, due to these architectures being a strict
32712 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32713 would be selected when fully respecting chronology of architectures.
32714 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32715 move them before ARMv7 architectures. */
031254f2
AV
32716 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32717 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32718
32719 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32720 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32721 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32722 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32723 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32724 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32725 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32726 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32727 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32728 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32729 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32730 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32731 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32732 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32733 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32734 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
aab2c27d
MM
32735 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32736 {-1, ARM_ARCH_NONE}
62b3e311
PB
32737};
32738
ee3c0378 32739/* Set an attribute if it has not already been set by the user. */
0198d5e6 32740
ee3c0378
AS
32741static void
32742aeabi_set_attribute_int (int tag, int value)
32743{
32744 if (tag < 1
32745 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32746 || !attributes_set_explicitly[tag])
32747 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32748}
32749
32750static void
32751aeabi_set_attribute_string (int tag, const char *value)
32752{
32753 if (tag < 1
32754 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32755 || !attributes_set_explicitly[tag])
32756 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32757}
32758
2c6b98ea
TP
32759/* Return whether features in the *NEEDED feature set are available via
32760 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 32761
2c6b98ea
TP
32762static bfd_boolean
32763have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32764 const arm_feature_set *needed)
32765{
32766 int i, nb_allowed_archs;
32767 arm_feature_set ext_fset;
32768 const struct arm_option_extension_value_table *opt;
32769
32770 ext_fset = arm_arch_none;
32771 for (opt = arm_extensions; opt->name != NULL; opt++)
32772 {
32773 /* Extension does not provide any feature we need. */
32774 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32775 continue;
32776
32777 nb_allowed_archs =
32778 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32779 for (i = 0; i < nb_allowed_archs; i++)
32780 {
32781 /* Empty entry. */
32782 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32783 break;
32784
32785 /* Extension is available, add it. */
32786 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32787 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32788 }
32789 }
32790
32791 /* Can we enable all features in *needed? */
32792 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32793}
32794
32795/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32796 a given architecture feature set *ARCH_EXT_FSET including extension feature
32797 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32798 - if true, check for an exact match of the architecture modulo extensions;
32799 - otherwise, select build attribute value of the first superset
32800 architecture released so that results remains stable when new architectures
32801 are added.
32802 For -march/-mcpu=all the build attribute value of the most featureful
32803 architecture is returned. Tag_CPU_arch_profile result is returned in
32804 PROFILE. */
0198d5e6 32805
2c6b98ea
TP
32806static int
32807get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32808 const arm_feature_set *ext_fset,
32809 char *profile, int exact_match)
32810{
32811 arm_feature_set arch_fset;
32812 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32813
32814 /* Select most featureful architecture with all its extensions if building
32815 for -march=all as the feature sets used to set build attributes. */
32816 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32817 {
32818 /* Force revisiting of decision for each new architecture. */
031254f2 32819 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
32820 *profile = 'A';
32821 return TAG_CPU_ARCH_V8;
32822 }
32823
32824 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32825
32826 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32827 {
32828 arm_feature_set known_arch_fset;
32829
32830 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32831 if (exact_match)
32832 {
32833 /* Base architecture match user-specified architecture and
32834 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32835 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32836 {
32837 p_ver_ret = p_ver;
32838 goto found;
32839 }
32840 /* Base architecture match user-specified architecture only
32841 (eg. ARMv6-M in the same case as above). Record it in case we
32842 find a match with above condition. */
32843 else if (p_ver_ret == NULL
32844 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32845 p_ver_ret = p_ver;
32846 }
32847 else
32848 {
32849
32850 /* Architecture has all features wanted. */
32851 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32852 {
32853 arm_feature_set added_fset;
32854
32855 /* Compute features added by this architecture over the one
32856 recorded in p_ver_ret. */
32857 if (p_ver_ret != NULL)
32858 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32859 p_ver_ret->flags);
32860 /* First architecture that match incl. with extensions, or the
32861 only difference in features over the recorded match is
32862 features that were optional and are now mandatory. */
32863 if (p_ver_ret == NULL
32864 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32865 {
32866 p_ver_ret = p_ver;
32867 goto found;
32868 }
32869 }
32870 else if (p_ver_ret == NULL)
32871 {
32872 arm_feature_set needed_ext_fset;
32873
32874 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32875
32876 /* Architecture has all features needed when using some
32877 extensions. Record it and continue searching in case there
32878 exist an architecture providing all needed features without
32879 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32880 OS extension). */
32881 if (have_ext_for_needed_feat_p (&known_arch_fset,
32882 &needed_ext_fset))
32883 p_ver_ret = p_ver;
32884 }
32885 }
32886 }
32887
32888 if (p_ver_ret == NULL)
32889 return -1;
32890
32891found:
32892 /* Tag_CPU_arch_profile. */
32893 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32894 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32895 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32896 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
32897 *profile = 'A';
32898 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
32899 *profile = 'R';
32900 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32901 *profile = 'M';
32902 else
32903 *profile = '\0';
32904 return p_ver_ret->val;
32905}
32906
ee065d83 32907/* Set the public EABI object attributes. */
0198d5e6 32908
c168ce07 32909static void
ee065d83
PB
32910aeabi_set_public_attributes (void)
32911{
b90d5ba0 32912 char profile = '\0';
2c6b98ea 32913 int arch = -1;
90ec0d68 32914 int virt_sec = 0;
bca38921 32915 int fp16_optional = 0;
2c6b98ea
TP
32916 int skip_exact_match = 0;
32917 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 32918
54bab281
TP
32919 /* Autodetection mode, choose the architecture based the instructions
32920 actually used. */
32921 if (no_cpu_selected ())
32922 {
32923 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 32924
54bab281
TP
32925 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32926 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 32927
54bab281
TP
32928 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32929 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 32930
54bab281 32931 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
32932 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32933 flags_ext = arm_arch_none;
32934 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32935 selected_ext = flags_ext;
54bab281
TP
32936 selected_cpu = flags;
32937 }
32938 /* Otherwise, choose the architecture based on the capabilities of the
32939 requested cpu. */
32940 else
4d354d8b
TP
32941 {
32942 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32943 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32944 flags_ext = selected_ext;
32945 flags = selected_cpu;
32946 }
32947 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 32948
ddd7f988 32949 /* Allow the user to override the reported architecture. */
4d354d8b 32950 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 32951 {
4d354d8b 32952 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 32953 flags_ext = arm_arch_none;
7a1d4c38 32954 }
2c6b98ea 32955 else
4d354d8b 32956 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
32957
32958 /* When this function is run again after relaxation has happened there is no
32959 way to determine whether an architecture or CPU was specified by the user:
32960 - selected_cpu is set above for relaxation to work;
32961 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32962 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32963 Therefore, if not in -march=all case we first try an exact match and fall
32964 back to autodetection. */
32965 if (!skip_exact_match)
32966 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32967 if (arch == -1)
32968 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32969 if (arch == -1)
32970 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 32971
ee065d83
PB
32972 /* Tag_CPU_name. */
32973 if (selected_cpu_name[0])
32974 {
91d6fa6a 32975 char *q;
ee065d83 32976
91d6fa6a
NC
32977 q = selected_cpu_name;
32978 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
32979 {
32980 int i;
5f4273c7 32981
91d6fa6a
NC
32982 q += 4;
32983 for (i = 0; q[i]; i++)
32984 q[i] = TOUPPER (q[i]);
ee065d83 32985 }
91d6fa6a 32986 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 32987 }
62f3b8c8 32988
ee065d83 32989 /* Tag_CPU_arch. */
ee3c0378 32990 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 32991
62b3e311 32992 /* Tag_CPU_arch_profile. */
69239280
MGD
32993 if (profile != '\0')
32994 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 32995
15afaa63 32996 /* Tag_DSP_extension. */
4d354d8b 32997 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 32998 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 32999
2c6b98ea 33000 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 33001 /* Tag_ARM_ISA_use. */
ee3c0378 33002 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 33003 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 33004 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 33005
ee065d83 33006 /* Tag_THUMB_ISA_use. */
ee3c0378 33007 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 33008 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
33009 {
33010 int thumb_isa_use;
33011
33012 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 33013 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
33014 thumb_isa_use = 3;
33015 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33016 thumb_isa_use = 2;
33017 else
33018 thumb_isa_use = 1;
33019 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33020 }
62f3b8c8 33021
ee065d83 33022 /* Tag_VFP_arch. */
a715796b
TG
33023 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33024 aeabi_set_attribute_int (Tag_VFP_arch,
33025 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33026 ? 7 : 8);
bca38921 33027 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
33028 aeabi_set_attribute_int (Tag_VFP_arch,
33029 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33030 ? 5 : 6);
33031 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
33032 {
33033 fp16_optional = 1;
33034 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33035 }
ada65aa3 33036 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
33037 {
33038 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33039 fp16_optional = 1;
33040 }
ee3c0378
AS
33041 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33042 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33043 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 33044 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 33045 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 33046
4547cb56
NC
33047 /* Tag_ABI_HardFP_use. */
33048 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33049 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33050 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33051
ee065d83 33052 /* Tag_WMMX_arch. */
ee3c0378
AS
33053 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33054 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33055 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33056 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 33057
ee3c0378 33058 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
33059 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33060 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33061 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
33062 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33063 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33064 {
33065 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33066 {
33067 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33068 }
33069 else
33070 {
33071 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33072 fp16_optional = 1;
33073 }
33074 }
fa94de6b 33075
a7ad558c
AV
33076 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33077 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33078 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33079 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33080
ee3c0378 33081 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 33082 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 33083 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 33084
69239280
MGD
33085 /* Tag_DIV_use.
33086
33087 We set Tag_DIV_use to two when integer divide instructions have been used
33088 in ARM state, or when Thumb integer divide instructions have been used,
33089 but we have no architecture profile set, nor have we any ARM instructions.
33090
4ed7ed8d
TP
33091 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33092 by the base architecture.
bca38921 33093
69239280 33094 For new architectures we will have to check these tests. */
031254f2 33095 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
33096 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33097 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
33098 aeabi_set_attribute_int (Tag_DIV_use, 0);
33099 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33100 || (profile == '\0'
33101 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33102 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 33103 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
33104
33105 /* Tag_MP_extension_use. */
33106 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33107 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
33108
33109 /* Tag Virtualization_use. */
33110 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
33111 virt_sec |= 1;
33112 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33113 virt_sec |= 2;
33114 if (virt_sec != 0)
33115 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
33116
33117 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33118 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
33119}
33120
c168ce07
TP
33121/* Post relaxation hook. Recompute ARM attributes now that relaxation is
33122 finished and free extension feature bits which will not be used anymore. */
0198d5e6 33123
c168ce07
TP
33124void
33125arm_md_post_relax (void)
33126{
33127 aeabi_set_public_attributes ();
4d354d8b
TP
33128 XDELETE (mcpu_ext_opt);
33129 mcpu_ext_opt = NULL;
33130 XDELETE (march_ext_opt);
33131 march_ext_opt = NULL;
c168ce07
TP
33132}
33133
104d59d1 33134/* Add the default contents for the .ARM.attributes section. */
0198d5e6 33135
ee065d83
PB
33136void
33137arm_md_end (void)
33138{
ee065d83
PB
33139 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33140 return;
33141
33142 aeabi_set_public_attributes ();
ee065d83 33143}
8463be01 33144#endif /* OBJ_ELF */
ee065d83 33145
ee065d83
PB
33146/* Parse a .cpu directive. */
33147
33148static void
33149s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33150{
e74cfd16 33151 const struct arm_cpu_option_table *opt;
ee065d83
PB
33152 char *name;
33153 char saved_char;
33154
33155 name = input_line_pointer;
5f4273c7 33156 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33157 input_line_pointer++;
33158 saved_char = *input_line_pointer;
33159 *input_line_pointer = 0;
33160
33161 /* Skip the first "all" entry. */
33162 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33163 if (streq (opt->name, name))
33164 {
4d354d8b
TP
33165 selected_arch = opt->value;
33166 selected_ext = opt->ext;
33167 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 33168 if (opt->canonical_name)
5f4273c7 33169 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
33170 else
33171 {
33172 int i;
33173 for (i = 0; opt->name[i]; i++)
33174 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 33175
ee065d83
PB
33176 selected_cpu_name[i] = 0;
33177 }
4d354d8b
TP
33178 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33179
ee065d83
PB
33180 *input_line_pointer = saved_char;
33181 demand_empty_rest_of_line ();
33182 return;
33183 }
33184 as_bad (_("unknown cpu `%s'"), name);
33185 *input_line_pointer = saved_char;
33186 ignore_rest_of_line ();
33187}
33188
ee065d83
PB
33189/* Parse a .arch directive. */
33190
33191static void
33192s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33193{
e74cfd16 33194 const struct arm_arch_option_table *opt;
ee065d83
PB
33195 char saved_char;
33196 char *name;
33197
33198 name = input_line_pointer;
5f4273c7 33199 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33200 input_line_pointer++;
33201 saved_char = *input_line_pointer;
33202 *input_line_pointer = 0;
33203
33204 /* Skip the first "all" entry. */
33205 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33206 if (streq (opt->name, name))
33207 {
4d354d8b 33208 selected_arch = opt->value;
0e7aaa72 33209 selected_ctx_ext_table = opt->ext_table;
4d354d8b
TP
33210 selected_ext = arm_arch_none;
33211 selected_cpu = selected_arch;
5f4273c7 33212 strcpy (selected_cpu_name, opt->name);
4d354d8b 33213 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33214 *input_line_pointer = saved_char;
33215 demand_empty_rest_of_line ();
33216 return;
33217 }
33218
33219 as_bad (_("unknown architecture `%s'\n"), name);
33220 *input_line_pointer = saved_char;
33221 ignore_rest_of_line ();
33222}
33223
7a1d4c38
PB
33224/* Parse a .object_arch directive. */
33225
33226static void
33227s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33228{
33229 const struct arm_arch_option_table *opt;
33230 char saved_char;
33231 char *name;
33232
33233 name = input_line_pointer;
5f4273c7 33234 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
33235 input_line_pointer++;
33236 saved_char = *input_line_pointer;
33237 *input_line_pointer = 0;
33238
33239 /* Skip the first "all" entry. */
33240 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33241 if (streq (opt->name, name))
33242 {
4d354d8b 33243 selected_object_arch = opt->value;
7a1d4c38
PB
33244 *input_line_pointer = saved_char;
33245 demand_empty_rest_of_line ();
33246 return;
33247 }
33248
33249 as_bad (_("unknown architecture `%s'\n"), name);
33250 *input_line_pointer = saved_char;
33251 ignore_rest_of_line ();
33252}
33253
69133863
MGD
33254/* Parse a .arch_extension directive. */
33255
33256static void
33257s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33258{
33259 const struct arm_option_extension_value_table *opt;
33260 char saved_char;
33261 char *name;
33262 int adding_value = 1;
33263
33264 name = input_line_pointer;
33265 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33266 input_line_pointer++;
33267 saved_char = *input_line_pointer;
33268 *input_line_pointer = 0;
33269
33270 if (strlen (name) >= 2
33271 && strncmp (name, "no", 2) == 0)
33272 {
33273 adding_value = 0;
33274 name += 2;
33275 }
33276
e20f9590
MI
33277 /* Check the context specific extension table */
33278 if (selected_ctx_ext_table)
33279 {
33280 const struct arm_ext_table * ext_opt;
33281 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33282 {
33283 if (streq (ext_opt->name, name))
33284 {
33285 if (adding_value)
33286 {
33287 if (ARM_FEATURE_ZERO (ext_opt->merge))
33288 /* TODO: Option not supported. When we remove the
33289 legacy table this case should error out. */
33290 continue;
33291 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33292 ext_opt->merge);
33293 }
33294 else
33295 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33296
33297 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33298 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33299 *input_line_pointer = saved_char;
33300 demand_empty_rest_of_line ();
33301 return;
33302 }
33303 }
33304 }
33305
69133863
MGD
33306 for (opt = arm_extensions; opt->name != NULL; opt++)
33307 if (streq (opt->name, name))
33308 {
d942732e
TP
33309 int i, nb_allowed_archs =
33310 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33311 for (i = 0; i < nb_allowed_archs; i++)
33312 {
33313 /* Empty entry. */
4d354d8b 33314 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 33315 continue;
4d354d8b 33316 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
33317 break;
33318 }
33319
33320 if (i == nb_allowed_archs)
69133863
MGD
33321 {
33322 as_bad (_("architectural extension `%s' is not allowed for the "
33323 "current base architecture"), name);
33324 break;
33325 }
33326
33327 if (adding_value)
4d354d8b 33328 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 33329 opt->merge_value);
69133863 33330 else
4d354d8b 33331 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 33332
4d354d8b
TP
33333 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33334 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
33335 *input_line_pointer = saved_char;
33336 demand_empty_rest_of_line ();
3d030cdb
TP
33337 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33338 on this return so that duplicate extensions (extensions with the
33339 same name as a previous extension in the list) are not considered
33340 for command-line parsing. */
69133863
MGD
33341 return;
33342 }
33343
33344 if (opt->name == NULL)
e673710a 33345 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
33346
33347 *input_line_pointer = saved_char;
33348 ignore_rest_of_line ();
33349}
33350
ee065d83
PB
33351/* Parse a .fpu directive. */
33352
33353static void
33354s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33355{
69133863 33356 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
33357 char saved_char;
33358 char *name;
33359
33360 name = input_line_pointer;
5f4273c7 33361 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33362 input_line_pointer++;
33363 saved_char = *input_line_pointer;
33364 *input_line_pointer = 0;
5f4273c7 33365
ee065d83
PB
33366 for (opt = arm_fpus; opt->name != NULL; opt++)
33367 if (streq (opt->name, name))
33368 {
4d354d8b 33369 selected_fpu = opt->value;
f4399880 33370 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
4d354d8b
TP
33371#ifndef CPU_DEFAULT
33372 if (no_cpu_selected ())
33373 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33374 else
33375#endif
33376 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33377 *input_line_pointer = saved_char;
33378 demand_empty_rest_of_line ();
33379 return;
33380 }
33381
33382 as_bad (_("unknown floating point format `%s'\n"), name);
33383 *input_line_pointer = saved_char;
33384 ignore_rest_of_line ();
33385}
ee065d83 33386
794ba86a 33387/* Copy symbol information. */
f31fef98 33388
794ba86a
DJ
33389void
33390arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33391{
33392 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33393}
e04befd0 33394
f31fef98 33395#ifdef OBJ_ELF
e04befd0
AS
33396/* Given a symbolic attribute NAME, return the proper integer value.
33397 Returns -1 if the attribute is not known. */
f31fef98 33398
e04befd0
AS
33399int
33400arm_convert_symbolic_attribute (const char *name)
33401{
f31fef98
NC
33402 static const struct
33403 {
33404 const char * name;
33405 const int tag;
33406 }
33407 attribute_table[] =
33408 {
33409 /* When you modify this table you should
33410 also modify the list in doc/c-arm.texi. */
e04befd0 33411#define T(tag) {#tag, tag}
f31fef98
NC
33412 T (Tag_CPU_raw_name),
33413 T (Tag_CPU_name),
33414 T (Tag_CPU_arch),
33415 T (Tag_CPU_arch_profile),
33416 T (Tag_ARM_ISA_use),
33417 T (Tag_THUMB_ISA_use),
75375b3e 33418 T (Tag_FP_arch),
f31fef98
NC
33419 T (Tag_VFP_arch),
33420 T (Tag_WMMX_arch),
33421 T (Tag_Advanced_SIMD_arch),
33422 T (Tag_PCS_config),
33423 T (Tag_ABI_PCS_R9_use),
33424 T (Tag_ABI_PCS_RW_data),
33425 T (Tag_ABI_PCS_RO_data),
33426 T (Tag_ABI_PCS_GOT_use),
33427 T (Tag_ABI_PCS_wchar_t),
33428 T (Tag_ABI_FP_rounding),
33429 T (Tag_ABI_FP_denormal),
33430 T (Tag_ABI_FP_exceptions),
33431 T (Tag_ABI_FP_user_exceptions),
33432 T (Tag_ABI_FP_number_model),
75375b3e 33433 T (Tag_ABI_align_needed),
f31fef98 33434 T (Tag_ABI_align8_needed),
75375b3e 33435 T (Tag_ABI_align_preserved),
f31fef98
NC
33436 T (Tag_ABI_align8_preserved),
33437 T (Tag_ABI_enum_size),
33438 T (Tag_ABI_HardFP_use),
33439 T (Tag_ABI_VFP_args),
33440 T (Tag_ABI_WMMX_args),
33441 T (Tag_ABI_optimization_goals),
33442 T (Tag_ABI_FP_optimization_goals),
33443 T (Tag_compatibility),
33444 T (Tag_CPU_unaligned_access),
75375b3e 33445 T (Tag_FP_HP_extension),
f31fef98
NC
33446 T (Tag_VFP_HP_extension),
33447 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
33448 T (Tag_MPextension_use),
33449 T (Tag_DIV_use),
f31fef98
NC
33450 T (Tag_nodefaults),
33451 T (Tag_also_compatible_with),
33452 T (Tag_conformance),
33453 T (Tag_T2EE_use),
33454 T (Tag_Virtualization_use),
15afaa63 33455 T (Tag_DSP_extension),
a7ad558c 33456 T (Tag_MVE_arch),
cd21e546 33457 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 33458#undef T
f31fef98 33459 };
e04befd0
AS
33460 unsigned int i;
33461
33462 if (name == NULL)
33463 return -1;
33464
f31fef98 33465 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 33466 if (streq (name, attribute_table[i].name))
e04befd0
AS
33467 return attribute_table[i].tag;
33468
33469 return -1;
33470}
267bf995 33471
93ef582d
NC
33472/* Apply sym value for relocations only in the case that they are for
33473 local symbols in the same segment as the fixup and you have the
33474 respective architectural feature for blx and simple switches. */
0198d5e6 33475
267bf995 33476int
93ef582d 33477arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
33478{
33479 if (fixP->fx_addsy
33480 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
33481 /* PR 17444: If the local symbol is in a different section then a reloc
33482 will always be generated for it, so applying the symbol value now
33483 will result in a double offset being stored in the relocation. */
33484 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 33485 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
33486 {
33487 switch (fixP->fx_r_type)
33488 {
33489 case BFD_RELOC_ARM_PCREL_BLX:
33490 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33491 if (ARM_IS_FUNC (fixP->fx_addsy))
33492 return 1;
33493 break;
33494
33495 case BFD_RELOC_ARM_PCREL_CALL:
33496 case BFD_RELOC_THUMB_PCREL_BLX:
33497 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 33498 return 1;
267bf995
RR
33499 break;
33500
33501 default:
33502 break;
33503 }
33504
33505 }
33506 return 0;
33507}
f31fef98 33508#endif /* OBJ_ELF */