]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
aarch64: Neoverse V1 tweaks
[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);
164446e0 233static const arm_feature_set arm_ext_v8r = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8R);
69c9e028 234#ifdef OBJ_ELF
e7d39ed3 235static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 236#endif
823d2571 237static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 238static const arm_feature_set arm_ext_m =
173205ca 239 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 240 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
241static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
242static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
243static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
244static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
245static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 246static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 247static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
248static const arm_feature_set arm_ext_v8m_main =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
250static const arm_feature_set arm_ext_v8_1m_main =
251ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
252/* Instructions in ARMv8-M only found in M profile architectures. */
253static const arm_feature_set arm_ext_v8m_m_only =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
255static const arm_feature_set arm_ext_v6t2_v8m =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
257/* Instructions shared between ARMv8-A and ARMv8-M. */
258static const arm_feature_set arm_ext_atomics =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 260#ifdef OBJ_ELF
15afaa63
TP
261/* DSP instructions Tag_DSP_extension refers to. */
262static const arm_feature_set arm_ext_dsp =
263 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 264#endif
4d1464f2
MW
265static const arm_feature_set arm_ext_ras =
266 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
267/* FP16 instructions. */
268static const arm_feature_set arm_ext_fp16 =
269 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
270static const arm_feature_set arm_ext_fp16_fml =
271 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
272static const arm_feature_set arm_ext_v8_2 =
273 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
274static const arm_feature_set arm_ext_v8_3 =
275 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
276static const arm_feature_set arm_ext_sb =
277 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
278static const arm_feature_set arm_ext_predres =
279 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
aab2c27d
MM
280static const arm_feature_set arm_ext_bf16 =
281 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
616ce08e
MM
282static const arm_feature_set arm_ext_i8mm =
283 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
8b301fbb
MI
284static const arm_feature_set arm_ext_crc =
285 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
4934a27c
MM
286static const arm_feature_set arm_ext_cde =
287 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
288static const arm_feature_set arm_ext_cde0 =
289 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
290static const arm_feature_set arm_ext_cde1 =
291 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
292static const arm_feature_set arm_ext_cde2 =
293 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
294static const arm_feature_set arm_ext_cde3 =
295 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
296static const arm_feature_set arm_ext_cde4 =
297 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
298static const arm_feature_set arm_ext_cde5 =
299 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
300static const arm_feature_set arm_ext_cde6 =
301 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
302static const arm_feature_set arm_ext_cde7 =
303 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
e74cfd16
PB
304
305static const arm_feature_set arm_arch_any = ARM_ANY;
2c6b98ea 306static const arm_feature_set fpu_any = FPU_ANY;
f85d59c3 307static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
308static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
309static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
310
2d447fca 311static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 312 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 313static const arm_feature_set arm_cext_iwmmxt =
823d2571 314 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 315static const arm_feature_set arm_cext_xscale =
823d2571 316 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 317static const arm_feature_set arm_cext_maverick =
823d2571
TG
318 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
319static const arm_feature_set fpu_fpa_ext_v1 =
320 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
321static const arm_feature_set fpu_fpa_ext_v2 =
322 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 323static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
324 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
325static const arm_feature_set fpu_vfp_ext_v1 =
326 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
327static const arm_feature_set fpu_vfp_ext_v2 =
328 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
329static const arm_feature_set fpu_vfp_ext_v3xd =
330 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
331static const arm_feature_set fpu_vfp_ext_v3 =
332 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 333static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
334 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
335static const arm_feature_set fpu_neon_ext_v1 =
336 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 337static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 338 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c 339static const arm_feature_set mve_ext =
2da2eaf4 340 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
a7ad558c 341static const arm_feature_set mve_fp_ext =
2da2eaf4 342 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
5aae9ae9
MM
343/* Note: This has more than one bit set, which means using it with
344 mark_feature_used (which returns if *any* of the bits are set in the current
345 cpu variant) can give surprising results. */
346static const arm_feature_set armv8m_fp =
347 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
69c9e028 348#ifdef OBJ_ELF
823d2571
TG
349static const arm_feature_set fpu_vfp_fp16 =
350 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
351static const arm_feature_set fpu_neon_ext_fma =
352 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 353#endif
823d2571
TG
354static const arm_feature_set fpu_vfp_ext_fma =
355 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 356static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 357 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 358static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 359 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 360static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 361 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 362static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 363 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
d6b4b13e 364static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 365 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
366static const arm_feature_set fpu_neon_ext_dotprod =
367 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 368
33a392fb 369static int mfloat_abi_opt = -1;
4d354d8b
TP
370/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
371 directive. */
372static arm_feature_set selected_arch = ARM_ARCH_NONE;
373/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
374 directive. */
375static arm_feature_set selected_ext = ARM_ARCH_NONE;
376/* Feature bits selected by the last -mcpu/-march or by the combination of the
377 last .cpu/.arch directive .arch_extension directives since that
378 directive. */
e74cfd16 379static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
380/* FPU feature bits selected by the last -mfpu or .fpu directive. */
381static arm_feature_set selected_fpu = FPU_NONE;
382/* Feature bits selected by the last .object_arch directive. */
383static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 384/* Must be long enough to hold any of the names in arm_cpus. */
e20f9590 385static const struct arm_ext_table * selected_ctx_ext_table = NULL;
ef8e6722 386static char selected_cpu_name[20];
8d67f500 387
aacf0b33
KT
388extern FLONUM_TYPE generic_floating_point_number;
389
8d67f500
NC
390/* Return if no cpu was selected on command-line. */
391static bfd_boolean
392no_cpu_selected (void)
393{
823d2571 394 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
395}
396
7cc69913 397#ifdef OBJ_ELF
deeaaff8
DJ
398# ifdef EABI_DEFAULT
399static int meabi_flags = EABI_DEFAULT;
400# else
d507cf36 401static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 402# endif
e1da3f5b 403
ee3c0378
AS
404static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
405
e1da3f5b 406bfd_boolean
5f4273c7 407arm_is_eabi (void)
e1da3f5b
PB
408{
409 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
410}
7cc69913 411#endif
b99bd4ef 412
b99bd4ef 413#ifdef OBJ_ELF
c19d1205 414/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
415symbolS * GOT_symbol;
416#endif
417
b99bd4ef
NC
418/* 0: assemble for ARM,
419 1: assemble for Thumb,
420 2: assemble for Thumb even though target CPU does not support thumb
421 instructions. */
422static int thumb_mode = 0;
8dc2430f
NC
423/* A value distinct from the possible values for thumb_mode that we
424 can use to record whether thumb_mode has been copied into the
425 tc_frag_data field of a frag. */
426#define MODE_RECORDED (1 << 4)
b99bd4ef 427
e07e6e58
NC
428/* Specifies the intrinsic IT insn behavior mode. */
429enum implicit_it_mode
430{
431 IMPLICIT_IT_MODE_NEVER = 0x00,
432 IMPLICIT_IT_MODE_ARM = 0x01,
433 IMPLICIT_IT_MODE_THUMB = 0x02,
434 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
435};
436static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
437
c19d1205
ZW
438/* If unified_syntax is true, we are processing the new unified
439 ARM/Thumb syntax. Important differences from the old ARM mode:
440
441 - Immediate operands do not require a # prefix.
442 - Conditional affixes always appear at the end of the
443 instruction. (For backward compatibility, those instructions
444 that formerly had them in the middle, continue to accept them
445 there.)
446 - The IT instruction may appear, and if it does is validated
447 against subsequent conditional affixes. It does not generate
448 machine code.
449
450 Important differences from the old Thumb mode:
451
452 - Immediate operands do not require a # prefix.
453 - Most of the V6T2 instructions are only available in unified mode.
454 - The .N and .W suffixes are recognized and honored (it is an error
455 if they cannot be honored).
456 - All instructions set the flags if and only if they have an 's' affix.
457 - Conditional affixes may be used. They are validated against
458 preceding IT instructions. Unlike ARM mode, you cannot use a
459 conditional affix except in the scope of an IT instruction. */
460
461static bfd_boolean unified_syntax = FALSE;
b99bd4ef 462
bacebabc
RM
463/* An immediate operand can start with #, and ld*, st*, pld operands
464 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
465 before a [, which can appear as the first operand for pld.
466 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
467const char arm_symbol_chars[] = "#[]{}";
bacebabc 468
5287ad62
JB
469enum neon_el_type
470{
dcbf9037 471 NT_invtype,
5287ad62
JB
472 NT_untyped,
473 NT_integer,
474 NT_float,
475 NT_poly,
476 NT_signed,
aab2c27d 477 NT_bfloat,
dcbf9037 478 NT_unsigned
5287ad62
JB
479};
480
481struct neon_type_el
482{
483 enum neon_el_type type;
484 unsigned size;
485};
486
5aae9ae9 487#define NEON_MAX_TYPE_ELS 5
5287ad62
JB
488
489struct neon_type
490{
491 struct neon_type_el el[NEON_MAX_TYPE_ELS];
492 unsigned elems;
493};
494
5ee91343 495enum pred_instruction_type
e07e6e58 496{
5ee91343
AV
497 OUTSIDE_PRED_INSN,
498 INSIDE_VPT_INSN,
e07e6e58
NC
499 INSIDE_IT_INSN,
500 INSIDE_IT_LAST_INSN,
501 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 502 if inside, should be the last one. */
e07e6e58 503 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 504 i.e. BKPT and NOP. */
5ee91343
AV
505 IT_INSN, /* The IT insn has been parsed. */
506 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 507 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 508 a predication code. */
4934a27c 509 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
e07e6e58
NC
510};
511
ad6cec43
MGD
512/* The maximum number of operands we need. */
513#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 514#define ARM_IT_MAX_RELOCS 3
ad6cec43 515
b99bd4ef
NC
516struct arm_it
517{
c19d1205 518 const char * error;
b99bd4ef 519 unsigned long instruction;
7af67752
AM
520 unsigned int size;
521 unsigned int size_req;
522 unsigned int cond;
037e8744 523 /* "uncond_value" is set to the value in place of the conditional field in
7af67752 524 unconditional versions of the instruction, or -1u if nothing is
037e8744 525 appropriate. */
7af67752 526 unsigned int uncond_value;
5287ad62 527 struct neon_type vectype;
88714cb8
DG
528 /* This does not indicate an actual NEON instruction, only that
529 the mnemonic accepts neon-style type suffixes. */
530 int is_neon;
0110f2b8
PB
531 /* Set to the opcode if the instruction needs relaxation.
532 Zero if the instruction is not relaxed. */
533 unsigned long relax;
b99bd4ef
NC
534 struct
535 {
536 bfd_reloc_code_real_type type;
c19d1205
ZW
537 expressionS exp;
538 int pc_rel;
e2b0ab59 539 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 540
5ee91343 541 enum pred_instruction_type pred_insn_type;
e07e6e58 542
c19d1205
ZW
543 struct
544 {
545 unsigned reg;
ca3f61f7 546 signed int imm;
dcbf9037 547 struct neon_type_el vectype;
ca3f61f7
NC
548 unsigned present : 1; /* Operand present. */
549 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
550 unsigned immisreg : 2; /* .imm field is a second register.
551 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
552 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
553 0) not scalar,
554 1) Neon scalar,
555 2) MVE scalar. */
5287ad62 556 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 557 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
558 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
559 instructions. This allows us to disambiguate ARM <-> vector insns. */
560 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 561 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 562 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 563 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 564 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
565 unsigned hasreloc : 1; /* Operand has relocation suffix. */
566 unsigned writeback : 1; /* Operand has trailing ! */
567 unsigned preind : 1; /* Preindexed address. */
568 unsigned postind : 1; /* Postindexed address. */
569 unsigned negative : 1; /* Index register was negated. */
570 unsigned shifted : 1; /* Shift applied to operation. */
571 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 572 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
573};
574
c19d1205 575static struct arm_it inst;
b99bd4ef
NC
576
577#define NUM_FLOAT_VALS 8
578
05d2d07e 579const char * fp_const[] =
b99bd4ef
NC
580{
581 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
582};
583
b99bd4ef
NC
584LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
585
586#define FAIL (-1)
587#define SUCCESS (0)
588
589#define SUFF_S 1
590#define SUFF_D 2
591#define SUFF_E 3
592#define SUFF_P 4
593
c19d1205
ZW
594#define CP_T_X 0x00008000
595#define CP_T_Y 0x00400000
b99bd4ef 596
c19d1205
ZW
597#define CONDS_BIT 0x00100000
598#define LOAD_BIT 0x00100000
b99bd4ef
NC
599
600#define DOUBLE_LOAD_FLAG 0x00000001
601
602struct asm_cond
603{
d3ce72d0 604 const char * template_name;
c921be7d 605 unsigned long value;
b99bd4ef
NC
606};
607
c19d1205 608#define COND_ALWAYS 0xE
b99bd4ef 609
b99bd4ef
NC
610struct asm_psr
611{
d3ce72d0 612 const char * template_name;
c921be7d 613 unsigned long field;
b99bd4ef
NC
614};
615
62b3e311
PB
616struct asm_barrier_opt
617{
e797f7e0
MGD
618 const char * template_name;
619 unsigned long value;
620 const arm_feature_set arch;
62b3e311
PB
621};
622
2d2255b5 623/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
624#define SPSR_BIT (1 << 22)
625
c19d1205
ZW
626/* The individual PSR flag bits. */
627#define PSR_c (1 << 16)
628#define PSR_x (1 << 17)
629#define PSR_s (1 << 18)
630#define PSR_f (1 << 19)
b99bd4ef 631
c19d1205 632struct reloc_entry
bfae80f2 633{
0198d5e6 634 const char * name;
c921be7d 635 bfd_reloc_code_real_type reloc;
bfae80f2
RE
636};
637
5287ad62 638enum vfp_reg_pos
bfae80f2 639{
5287ad62
JB
640 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
641 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
642};
643
644enum vfp_ldstm_type
645{
646 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
647};
648
dcbf9037
JB
649/* Bits for DEFINED field in neon_typed_alias. */
650#define NTA_HASTYPE 1
651#define NTA_HASINDEX 2
652
653struct neon_typed_alias
654{
c921be7d
NC
655 unsigned char defined;
656 unsigned char index;
657 struct neon_type_el eltype;
dcbf9037
JB
658};
659
c19d1205 660/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
661 architecture extensions' registers. Each entry should have an error message
662 in reg_expected_msgs below. */
c19d1205 663enum arm_reg_type
bfae80f2 664{
c19d1205
ZW
665 REG_TYPE_RN,
666 REG_TYPE_CP,
667 REG_TYPE_CN,
668 REG_TYPE_FN,
669 REG_TYPE_VFS,
670 REG_TYPE_VFD,
5287ad62 671 REG_TYPE_NQ,
037e8744 672 REG_TYPE_VFSD,
5287ad62 673 REG_TYPE_NDQ,
dec41383 674 REG_TYPE_NSD,
037e8744 675 REG_TYPE_NSDQ,
c19d1205
ZW
676 REG_TYPE_VFC,
677 REG_TYPE_MVF,
678 REG_TYPE_MVD,
679 REG_TYPE_MVFX,
680 REG_TYPE_MVDX,
681 REG_TYPE_MVAX,
5ee91343 682 REG_TYPE_MQ,
c19d1205
ZW
683 REG_TYPE_DSPSC,
684 REG_TYPE_MMXWR,
685 REG_TYPE_MMXWC,
686 REG_TYPE_MMXWCG,
687 REG_TYPE_XSCALE,
5ee91343 688 REG_TYPE_RNB,
1b883319 689 REG_TYPE_ZR
bfae80f2
RE
690};
691
dcbf9037
JB
692/* Structure for a hash table entry for a register.
693 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
694 information which states whether a vector type or index is specified (for a
695 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
696struct reg_entry
697{
c921be7d 698 const char * name;
90ec0d68 699 unsigned int number;
c921be7d
NC
700 unsigned char type;
701 unsigned char builtin;
702 struct neon_typed_alias * neon;
6c43fab6
RE
703};
704
c19d1205 705/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 706const char * const reg_expected_msgs[] =
c19d1205 707{
5aa75429
TP
708 [REG_TYPE_RN] = N_("ARM register expected"),
709 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
710 [REG_TYPE_CN] = N_("co-processor register expected"),
711 [REG_TYPE_FN] = N_("FPA register expected"),
712 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
713 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
714 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
715 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
716 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
717 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
718 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
719 " expected"),
720 [REG_TYPE_VFC] = N_("VFP system register expected"),
721 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
722 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
723 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
724 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
725 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
726 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
727 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
728 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
729 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
730 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 731 [REG_TYPE_MQ] = N_("MVE vector register expected"),
da3ec71f 732 [REG_TYPE_RNB] = ""
6c43fab6
RE
733};
734
c19d1205 735/* Some well known registers that we refer to directly elsewhere. */
bd340a04 736#define REG_R12 12
c19d1205
ZW
737#define REG_SP 13
738#define REG_LR 14
739#define REG_PC 15
404ff6b5 740
b99bd4ef
NC
741/* ARM instructions take 4bytes in the object file, Thumb instructions
742 take 2: */
c19d1205 743#define INSN_SIZE 4
b99bd4ef
NC
744
745struct asm_opcode
746{
747 /* Basic string to match. */
d3ce72d0 748 const char * template_name;
c19d1205
ZW
749
750 /* Parameters to instruction. */
5be8be5d 751 unsigned int operands[8];
c19d1205
ZW
752
753 /* Conditional tag - see opcode_lookup. */
754 unsigned int tag : 4;
b99bd4ef
NC
755
756 /* Basic instruction code. */
a302e574 757 unsigned int avalue;
b99bd4ef 758
c19d1205
ZW
759 /* Thumb-format instruction code. */
760 unsigned int tvalue;
b99bd4ef 761
90e4755a 762 /* Which architecture variant provides this instruction. */
c921be7d
NC
763 const arm_feature_set * avariant;
764 const arm_feature_set * tvariant;
c19d1205
ZW
765
766 /* Function to call to encode instruction in ARM format. */
767 void (* aencode) (void);
b99bd4ef 768
c19d1205
ZW
769 /* Function to call to encode instruction in Thumb format. */
770 void (* tencode) (void);
5ee91343
AV
771
772 /* Indicates whether this instruction may be vector predicated. */
773 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
774};
775
a737bd4d
NC
776/* Defines for various bits that we will want to toggle. */
777#define INST_IMMEDIATE 0x02000000
778#define OFFSET_REG 0x02000000
c19d1205 779#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
780#define SHIFT_BY_REG 0x00000010
781#define PRE_INDEX 0x01000000
782#define INDEX_UP 0x00800000
783#define WRITE_BACK 0x00200000
784#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 785#define CPSI_MMOD 0x00020000
90e4755a 786
a737bd4d
NC
787#define LITERAL_MASK 0xf000f000
788#define OPCODE_MASK 0xfe1fffff
789#define V4_STR_BIT 0x00000020
8335d6aa 790#define VLDR_VMOV_SAME 0x0040f000
90e4755a 791
efd81785
PB
792#define T2_SUBS_PC_LR 0xf3de8f00
793
a737bd4d 794#define DATA_OP_SHIFT 21
bada4342 795#define SBIT_SHIFT 20
90e4755a 796
ef8d22e6
PB
797#define T2_OPCODE_MASK 0xfe1fffff
798#define T2_DATA_OP_SHIFT 21
bada4342 799#define T2_SBIT_SHIFT 20
ef8d22e6 800
6530b175
NC
801#define A_COND_MASK 0xf0000000
802#define A_PUSH_POP_OP_MASK 0x0fff0000
803
804/* Opcodes for pushing/poping registers to/from the stack. */
805#define A1_OPCODE_PUSH 0x092d0000
806#define A2_OPCODE_PUSH 0x052d0004
807#define A2_OPCODE_POP 0x049d0004
808
a737bd4d
NC
809/* Codes to distinguish the arithmetic instructions. */
810#define OPCODE_AND 0
811#define OPCODE_EOR 1
812#define OPCODE_SUB 2
813#define OPCODE_RSB 3
814#define OPCODE_ADD 4
815#define OPCODE_ADC 5
816#define OPCODE_SBC 6
817#define OPCODE_RSC 7
818#define OPCODE_TST 8
819#define OPCODE_TEQ 9
820#define OPCODE_CMP 10
821#define OPCODE_CMN 11
822#define OPCODE_ORR 12
823#define OPCODE_MOV 13
824#define OPCODE_BIC 14
825#define OPCODE_MVN 15
90e4755a 826
ef8d22e6
PB
827#define T2_OPCODE_AND 0
828#define T2_OPCODE_BIC 1
829#define T2_OPCODE_ORR 2
830#define T2_OPCODE_ORN 3
831#define T2_OPCODE_EOR 4
832#define T2_OPCODE_ADD 8
833#define T2_OPCODE_ADC 10
834#define T2_OPCODE_SBC 11
835#define T2_OPCODE_SUB 13
836#define T2_OPCODE_RSB 14
837
a737bd4d
NC
838#define T_OPCODE_MUL 0x4340
839#define T_OPCODE_TST 0x4200
840#define T_OPCODE_CMN 0x42c0
841#define T_OPCODE_NEG 0x4240
842#define T_OPCODE_MVN 0x43c0
90e4755a 843
a737bd4d
NC
844#define T_OPCODE_ADD_R3 0x1800
845#define T_OPCODE_SUB_R3 0x1a00
846#define T_OPCODE_ADD_HI 0x4400
847#define T_OPCODE_ADD_ST 0xb000
848#define T_OPCODE_SUB_ST 0xb080
849#define T_OPCODE_ADD_SP 0xa800
850#define T_OPCODE_ADD_PC 0xa000
851#define T_OPCODE_ADD_I8 0x3000
852#define T_OPCODE_SUB_I8 0x3800
853#define T_OPCODE_ADD_I3 0x1c00
854#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 855
a737bd4d
NC
856#define T_OPCODE_ASR_R 0x4100
857#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
858#define T_OPCODE_LSR_R 0x40c0
859#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
860#define T_OPCODE_ASR_I 0x1000
861#define T_OPCODE_LSL_I 0x0000
862#define T_OPCODE_LSR_I 0x0800
b99bd4ef 863
a737bd4d
NC
864#define T_OPCODE_MOV_I8 0x2000
865#define T_OPCODE_CMP_I8 0x2800
866#define T_OPCODE_CMP_LR 0x4280
867#define T_OPCODE_MOV_HR 0x4600
868#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 869
a737bd4d
NC
870#define T_OPCODE_LDR_PC 0x4800
871#define T_OPCODE_LDR_SP 0x9800
872#define T_OPCODE_STR_SP 0x9000
873#define T_OPCODE_LDR_IW 0x6800
874#define T_OPCODE_STR_IW 0x6000
875#define T_OPCODE_LDR_IH 0x8800
876#define T_OPCODE_STR_IH 0x8000
877#define T_OPCODE_LDR_IB 0x7800
878#define T_OPCODE_STR_IB 0x7000
879#define T_OPCODE_LDR_RW 0x5800
880#define T_OPCODE_STR_RW 0x5000
881#define T_OPCODE_LDR_RH 0x5a00
882#define T_OPCODE_STR_RH 0x5200
883#define T_OPCODE_LDR_RB 0x5c00
884#define T_OPCODE_STR_RB 0x5400
c9b604bd 885
a737bd4d
NC
886#define T_OPCODE_PUSH 0xb400
887#define T_OPCODE_POP 0xbc00
b99bd4ef 888
2fc8bdac 889#define T_OPCODE_BRANCH 0xe000
b99bd4ef 890
a737bd4d 891#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 892#define THUMB_PP_PC_LR 0x0100
c19d1205 893#define THUMB_LOAD_BIT 0x0800
53365c0d 894#define THUMB2_LOAD_BIT 0x00100000
c19d1205 895
5ee91343 896#define BAD_SYNTAX _("syntax error")
c19d1205 897#define BAD_ARGS _("bad arguments to instruction")
fdfde340 898#define BAD_SP _("r13 not allowed here")
c19d1205 899#define BAD_PC _("r15 not allowed here")
a302e574
AV
900#define BAD_ODD _("Odd register not allowed here")
901#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
902#define BAD_COND _("instruction cannot be conditional")
903#define BAD_OVERLAP _("registers may not be the same")
904#define BAD_HIREG _("lo register required")
905#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 906#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 907#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 908#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
4934a27c 909#define BAD_NO_VPT _("instruction not allowed in VPT block")
dfa9f0d5 910#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 911#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 912#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 913#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
914#define BAD_OUT_VPT \
915 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 916#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 917#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 918#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 919#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
920#define BAD_PC_ADDRESSING \
921 _("cannot use register index with PC-relative addressing")
922#define BAD_PC_WRITEBACK \
923 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
924#define BAD_RANGE _("branch out of range")
925#define BAD_FP16 _("selected processor does not support fp16 instruction")
aab2c27d 926#define BAD_BF16 _("selected processor does not support bf16 instruction")
4934a27c
MM
927#define BAD_CDE _("selected processor does not support cde instruction")
928#define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
dd5181d5 929#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 930#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
931#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
932 "block")
933#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
934 "block")
935#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
936 " operand")
937#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
938 " operand")
a302e574 939#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
940#define BAD_MVE_AUTO \
941 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
942 " use a valid -march or -mcpu option.")
943#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
944 "and source operands makes instruction UNPREDICTABLE")
35c228db 945#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 946#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 947
629310ab
ML
948static htab_t arm_ops_hsh;
949static htab_t arm_cond_hsh;
950static htab_t arm_vcond_hsh;
951static htab_t arm_shift_hsh;
952static htab_t arm_psr_hsh;
953static htab_t arm_v7m_psr_hsh;
954static htab_t arm_reg_hsh;
955static htab_t arm_reloc_hsh;
956static htab_t arm_barrier_opt_hsh;
b99bd4ef 957
b99bd4ef
NC
958/* Stuff needed to resolve the label ambiguity
959 As:
960 ...
961 label: <insn>
962 may differ from:
963 ...
964 label:
5f4273c7 965 <insn> */
b99bd4ef
NC
966
967symbolS * last_label_seen;
b34976b6 968static int label_is_thumb_function_name = FALSE;
e07e6e58 969
3d0c9500
NC
970/* Literal pool structure. Held on a per-section
971 and per-sub-section basis. */
a737bd4d 972
c19d1205 973#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 974typedef struct literal_pool
b99bd4ef 975{
c921be7d
NC
976 expressionS literals [MAX_LITERAL_POOL_SIZE];
977 unsigned int next_free_entry;
978 unsigned int id;
979 symbolS * symbol;
980 segT section;
981 subsegT sub_section;
a8040cf2
NC
982#ifdef OBJ_ELF
983 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
984#endif
c921be7d 985 struct literal_pool * next;
8335d6aa 986 unsigned int alignment;
3d0c9500 987} literal_pool;
b99bd4ef 988
3d0c9500
NC
989/* Pointer to a linked list of literal pools. */
990literal_pool * list_of_pools = NULL;
e27ec89e 991
2e6976a8
DG
992typedef enum asmfunc_states
993{
994 OUTSIDE_ASMFUNC,
995 WAITING_ASMFUNC_NAME,
996 WAITING_ENDASMFUNC
997} asmfunc_states;
998
999static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
1000
e07e6e58 1001#ifdef OBJ_ELF
5ee91343 1002# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 1003#else
5ee91343 1004static struct current_pred now_pred;
e07e6e58
NC
1005#endif
1006
1007static inline int
5ee91343 1008now_pred_compatible (int cond)
e07e6e58 1009{
5ee91343 1010 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
1011}
1012
1013static inline int
1014conditional_insn (void)
1015{
1016 return inst.cond != COND_ALWAYS;
1017}
1018
5ee91343 1019static int in_pred_block (void);
e07e6e58 1020
5ee91343 1021static int handle_pred_state (void);
e07e6e58
NC
1022
1023static void force_automatic_it_block_close (void);
1024
c921be7d
NC
1025static void it_fsm_post_encode (void);
1026
5ee91343 1027#define set_pred_insn_type(type) \
e07e6e58
NC
1028 do \
1029 { \
5ee91343
AV
1030 inst.pred_insn_type = type; \
1031 if (handle_pred_state () == FAIL) \
477330fc 1032 return; \
e07e6e58
NC
1033 } \
1034 while (0)
1035
5ee91343 1036#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
1037 do \
1038 { \
5ee91343
AV
1039 inst.pred_insn_type = type; \
1040 if (handle_pred_state () == FAIL) \
477330fc 1041 return failret; \
c921be7d
NC
1042 } \
1043 while(0)
1044
5ee91343 1045#define set_pred_insn_type_last() \
e07e6e58
NC
1046 do \
1047 { \
1048 if (inst.cond == COND_ALWAYS) \
5ee91343 1049 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1050 else \
5ee91343 1051 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1052 } \
1053 while (0)
1054
e39c1607
SD
1055/* Toggle value[pos]. */
1056#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1057
c19d1205 1058/* Pure syntax. */
b99bd4ef 1059
c19d1205
ZW
1060/* This array holds the chars that always start a comment. If the
1061 pre-processor is disabled, these aren't very useful. */
2e6976a8 1062char arm_comment_chars[] = "@";
3d0c9500 1063
c19d1205
ZW
1064/* This array holds the chars that only start a comment at the beginning of
1065 a line. If the line seems to have the form '# 123 filename'
1066 .line and .file directives will appear in the pre-processed output. */
1067/* Note that input_file.c hand checks for '#' at the beginning of the
1068 first line of the input file. This is because the compiler outputs
1069 #NO_APP at the beginning of its output. */
1070/* Also note that comments like this one will always work. */
1071const char line_comment_chars[] = "#";
3d0c9500 1072
2e6976a8 1073char arm_line_separator_chars[] = ";";
b99bd4ef 1074
c19d1205
ZW
1075/* Chars that can be used to separate mant
1076 from exp in floating point numbers. */
1077const char EXP_CHARS[] = "eE";
3d0c9500 1078
c19d1205
ZW
1079/* Chars that mean this number is a floating point constant. */
1080/* As in 0f12.456 */
1081/* or 0d1.2345e12 */
b99bd4ef 1082
5312fe52 1083const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1084
c19d1205
ZW
1085/* Prefix characters that indicate the start of an immediate
1086 value. */
1087#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1088
c19d1205
ZW
1089/* Separator character handling. */
1090
1091#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1092
5312fe52
BW
1093enum fp_16bit_format
1094{
1095 ARM_FP16_FORMAT_IEEE = 0x1,
1096 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1097 ARM_FP16_FORMAT_DEFAULT = 0x3
1098};
1099
1100static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1101
1102
c19d1205
ZW
1103static inline int
1104skip_past_char (char ** str, char c)
1105{
8ab8155f
NC
1106 /* PR gas/14987: Allow for whitespace before the expected character. */
1107 skip_whitespace (*str);
427d0db6 1108
c19d1205
ZW
1109 if (**str == c)
1110 {
1111 (*str)++;
1112 return SUCCESS;
3d0c9500 1113 }
c19d1205
ZW
1114 else
1115 return FAIL;
1116}
c921be7d 1117
c19d1205 1118#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1119
c19d1205
ZW
1120/* Arithmetic expressions (possibly involving symbols). */
1121
1122/* Return TRUE if anything in the expression is a bignum. */
1123
0198d5e6 1124static bfd_boolean
c19d1205
ZW
1125walk_no_bignums (symbolS * sp)
1126{
1127 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1128 return TRUE;
c19d1205
ZW
1129
1130 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1131 {
c19d1205
ZW
1132 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1133 || (symbol_get_value_expression (sp)->X_op_symbol
1134 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1135 }
1136
0198d5e6 1137 return FALSE;
3d0c9500
NC
1138}
1139
0198d5e6 1140static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1141
1142/* Third argument to my_get_expression. */
1143#define GE_NO_PREFIX 0
1144#define GE_IMM_PREFIX 1
1145#define GE_OPT_PREFIX 2
5287ad62
JB
1146/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1147 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1148#define GE_OPT_PREFIX_BIG 3
a737bd4d 1149
b99bd4ef 1150static int
c19d1205 1151my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1152{
c19d1205 1153 char * save_in;
b99bd4ef 1154
c19d1205
ZW
1155 /* In unified syntax, all prefixes are optional. */
1156 if (unified_syntax)
5287ad62 1157 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1158 : GE_OPT_PREFIX;
b99bd4ef 1159
c19d1205 1160 switch (prefix_mode)
b99bd4ef 1161 {
c19d1205
ZW
1162 case GE_NO_PREFIX: break;
1163 case GE_IMM_PREFIX:
1164 if (!is_immediate_prefix (**str))
1165 {
1166 inst.error = _("immediate expression requires a # prefix");
1167 return FAIL;
1168 }
1169 (*str)++;
1170 break;
1171 case GE_OPT_PREFIX:
5287ad62 1172 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1173 if (is_immediate_prefix (**str))
1174 (*str)++;
1175 break;
0198d5e6
TC
1176 default:
1177 abort ();
c19d1205 1178 }
b99bd4ef 1179
c19d1205 1180 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1181
c19d1205
ZW
1182 save_in = input_line_pointer;
1183 input_line_pointer = *str;
0198d5e6 1184 in_my_get_expression = TRUE;
2ac93be7 1185 expression (ep);
0198d5e6 1186 in_my_get_expression = FALSE;
c19d1205 1187
f86adc07 1188 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1189 {
f86adc07 1190 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1191 *str = input_line_pointer;
1192 input_line_pointer = save_in;
1193 if (inst.error == NULL)
f86adc07
NS
1194 inst.error = (ep->X_op == O_absent
1195 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1196 return 1;
1197 }
b99bd4ef 1198
c19d1205
ZW
1199 /* Get rid of any bignums now, so that we don't generate an error for which
1200 we can't establish a line number later on. Big numbers are never valid
1201 in instructions, which is where this routine is always called. */
5287ad62
JB
1202 if (prefix_mode != GE_OPT_PREFIX_BIG
1203 && (ep->X_op == O_big
477330fc 1204 || (ep->X_add_symbol
5287ad62 1205 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1206 || (ep->X_op_symbol
5287ad62 1207 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1208 {
1209 inst.error = _("invalid constant");
1210 *str = input_line_pointer;
1211 input_line_pointer = save_in;
1212 return 1;
1213 }
b99bd4ef 1214
c19d1205
ZW
1215 *str = input_line_pointer;
1216 input_line_pointer = save_in;
0198d5e6 1217 return SUCCESS;
b99bd4ef
NC
1218}
1219
c19d1205
ZW
1220/* Turn a string in input_line_pointer into a floating point constant
1221 of type TYPE, and store the appropriate bytes in *LITP. The number
1222 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1223 returned, or NULL on OK.
b99bd4ef 1224
c19d1205
ZW
1225 Note that fp constants aren't represent in the normal way on the ARM.
1226 In big endian mode, things are as expected. However, in little endian
1227 mode fp constants are big-endian word-wise, and little-endian byte-wise
1228 within the words. For example, (double) 1.1 in big endian mode is
1229 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1230 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1231
c19d1205 1232 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1233
6d4af3c2 1234const char *
c19d1205
ZW
1235md_atof (int type, char * litP, int * sizeP)
1236{
1237 int prec;
1238 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1239 char *t;
1240 int i;
b99bd4ef 1241
c19d1205
ZW
1242 switch (type)
1243 {
5312fe52
BW
1244 case 'H':
1245 case 'h':
1246 prec = 1;
1247 break;
1248
27cce866
MM
1249 /* If this is a bfloat16, then parse it slightly differently, as it
1250 does not follow the IEEE specification for floating point numbers
1251 exactly. */
1252 case 'b':
1253 {
1254 FLONUM_TYPE generic_float;
1255
1256 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1257
1258 if (t)
1259 input_line_pointer = t;
1260 else
1261 return _("invalid floating point number");
1262
1263 switch (generic_float.sign)
1264 {
1265 /* Is +Inf. */
1266 case 'P':
1267 words[0] = 0x7f80;
1268 break;
1269
1270 /* Is -Inf. */
1271 case 'N':
1272 words[0] = 0xff80;
1273 break;
1274
1275 /* Is NaN. */
1276 /* bfloat16 has two types of NaN - quiet and signalling.
1277 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1278 signalling NaN's have bit[0] == 0 && fraction != 0.
1279 Chosen this specific encoding as it is the same form
1280 as used by other IEEE 754 encodings in GAS. */
1281 case 0:
1282 words[0] = 0x7fff;
1283 break;
1284
1285 default:
1286 break;
1287 }
1288
1289 *sizeP = 2;
1290
1291 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1292
1293 return NULL;
1294 }
c19d1205
ZW
1295 case 'f':
1296 case 'F':
1297 case 's':
1298 case 'S':
1299 prec = 2;
1300 break;
b99bd4ef 1301
c19d1205
ZW
1302 case 'd':
1303 case 'D':
1304 case 'r':
1305 case 'R':
1306 prec = 4;
1307 break;
b99bd4ef 1308
c19d1205
ZW
1309 case 'x':
1310 case 'X':
499ac353 1311 prec = 5;
c19d1205 1312 break;
b99bd4ef 1313
c19d1205
ZW
1314 case 'p':
1315 case 'P':
499ac353 1316 prec = 5;
c19d1205 1317 break;
a737bd4d 1318
c19d1205
ZW
1319 default:
1320 *sizeP = 0;
499ac353 1321 return _("Unrecognized or unsupported floating point constant");
c19d1205 1322 }
b99bd4ef 1323
c19d1205
ZW
1324 t = atof_ieee (input_line_pointer, type, words);
1325 if (t)
1326 input_line_pointer = t;
499ac353 1327 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1328
72c03e30
BW
1329 if (target_big_endian || prec == 1)
1330 for (i = 0; i < prec; i++)
1331 {
1332 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1333 litP += sizeof (LITTLENUM_TYPE);
1334 }
1335 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1336 for (i = prec - 1; i >= 0; i--)
1337 {
1338 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1339 litP += sizeof (LITTLENUM_TYPE);
1340 }
c19d1205 1341 else
72c03e30
BW
1342 /* For a 4 byte float the order of elements in `words' is 1 0.
1343 For an 8 byte float the order is 1 0 3 2. */
1344 for (i = 0; i < prec; i += 2)
1345 {
1346 md_number_to_chars (litP, (valueT) words[i + 1],
1347 sizeof (LITTLENUM_TYPE));
1348 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1349 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1350 litP += 2 * sizeof (LITTLENUM_TYPE);
1351 }
b99bd4ef 1352
499ac353 1353 return NULL;
c19d1205 1354}
b99bd4ef 1355
c19d1205
ZW
1356/* We handle all bad expressions here, so that we can report the faulty
1357 instruction in the error message. */
0198d5e6 1358
c19d1205 1359void
91d6fa6a 1360md_operand (expressionS * exp)
c19d1205
ZW
1361{
1362 if (in_my_get_expression)
91d6fa6a 1363 exp->X_op = O_illegal;
b99bd4ef
NC
1364}
1365
c19d1205 1366/* Immediate values. */
b99bd4ef 1367
0198d5e6 1368#ifdef OBJ_ELF
c19d1205
ZW
1369/* Generic immediate-value read function for use in directives.
1370 Accepts anything that 'expression' can fold to a constant.
1371 *val receives the number. */
0198d5e6 1372
c19d1205
ZW
1373static int
1374immediate_for_directive (int *val)
b99bd4ef 1375{
c19d1205
ZW
1376 expressionS exp;
1377 exp.X_op = O_illegal;
b99bd4ef 1378
c19d1205
ZW
1379 if (is_immediate_prefix (*input_line_pointer))
1380 {
1381 input_line_pointer++;
1382 expression (&exp);
1383 }
b99bd4ef 1384
c19d1205
ZW
1385 if (exp.X_op != O_constant)
1386 {
1387 as_bad (_("expected #constant"));
1388 ignore_rest_of_line ();
1389 return FAIL;
1390 }
1391 *val = exp.X_add_number;
1392 return SUCCESS;
b99bd4ef 1393}
c19d1205 1394#endif
b99bd4ef 1395
c19d1205 1396/* Register parsing. */
b99bd4ef 1397
c19d1205
ZW
1398/* Generic register parser. CCP points to what should be the
1399 beginning of a register name. If it is indeed a valid register
1400 name, advance CCP over it and return the reg_entry structure;
1401 otherwise return NULL. Does not issue diagnostics. */
1402
1403static struct reg_entry *
1404arm_reg_parse_multi (char **ccp)
b99bd4ef 1405{
c19d1205
ZW
1406 char *start = *ccp;
1407 char *p;
1408 struct reg_entry *reg;
b99bd4ef 1409
477330fc
RM
1410 skip_whitespace (start);
1411
c19d1205
ZW
1412#ifdef REGISTER_PREFIX
1413 if (*start != REGISTER_PREFIX)
01cfc07f 1414 return NULL;
c19d1205
ZW
1415 start++;
1416#endif
1417#ifdef OPTIONAL_REGISTER_PREFIX
1418 if (*start == OPTIONAL_REGISTER_PREFIX)
1419 start++;
1420#endif
b99bd4ef 1421
c19d1205
ZW
1422 p = start;
1423 if (!ISALPHA (*p) || !is_name_beginner (*p))
1424 return NULL;
b99bd4ef 1425
c19d1205
ZW
1426 do
1427 p++;
1428 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1429
629310ab 1430 reg = (struct reg_entry *) str_hash_find_n (arm_reg_hsh, start, p - start);
c19d1205
ZW
1431
1432 if (!reg)
1433 return NULL;
1434
1435 *ccp = p;
1436 return reg;
b99bd4ef
NC
1437}
1438
1439static int
dcbf9037 1440arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1441 enum arm_reg_type type)
b99bd4ef 1442{
c19d1205
ZW
1443 /* Alternative syntaxes are accepted for a few register classes. */
1444 switch (type)
1445 {
1446 case REG_TYPE_MVF:
1447 case REG_TYPE_MVD:
1448 case REG_TYPE_MVFX:
1449 case REG_TYPE_MVDX:
1450 /* Generic coprocessor register names are allowed for these. */
79134647 1451 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1452 return reg->number;
1453 break;
69b97547 1454
c19d1205
ZW
1455 case REG_TYPE_CP:
1456 /* For backward compatibility, a bare number is valid here. */
1457 {
1458 unsigned long processor = strtoul (start, ccp, 10);
1459 if (*ccp != start && processor <= 15)
1460 return processor;
1461 }
1a0670f3 1462 /* Fall through. */
6057a28f 1463
c19d1205
ZW
1464 case REG_TYPE_MMXWC:
1465 /* WC includes WCG. ??? I'm not sure this is true for all
1466 instructions that take WC registers. */
79134647 1467 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1468 return reg->number;
6057a28f 1469 break;
c19d1205 1470
6057a28f 1471 default:
c19d1205 1472 break;
6057a28f
NC
1473 }
1474
dcbf9037
JB
1475 return FAIL;
1476}
1477
1478/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1479 return value is the register number or FAIL. */
1480
1481static int
1482arm_reg_parse (char **ccp, enum arm_reg_type type)
1483{
1484 char *start = *ccp;
1485 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1486 int ret;
1487
1488 /* Do not allow a scalar (reg+index) to parse as a register. */
1489 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1490 return FAIL;
1491
1492 if (reg && reg->type == type)
1493 return reg->number;
1494
1495 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1496 return ret;
1497
c19d1205
ZW
1498 *ccp = start;
1499 return FAIL;
1500}
69b97547 1501
dcbf9037
JB
1502/* Parse a Neon type specifier. *STR should point at the leading '.'
1503 character. Does no verification at this stage that the type fits the opcode
1504 properly. E.g.,
1505
1506 .i32.i32.s16
1507 .s32.f32
1508 .u16
1509
1510 Can all be legally parsed by this function.
1511
1512 Fills in neon_type struct pointer with parsed information, and updates STR
1513 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1514 type, FAIL if not. */
1515
1516static int
1517parse_neon_type (struct neon_type *type, char **str)
1518{
1519 char *ptr = *str;
1520
1521 if (type)
1522 type->elems = 0;
1523
1524 while (type->elems < NEON_MAX_TYPE_ELS)
1525 {
1526 enum neon_el_type thistype = NT_untyped;
1527 unsigned thissize = -1u;
1528
1529 if (*ptr != '.')
1530 break;
1531
1532 ptr++;
1533
1534 /* Just a size without an explicit type. */
1535 if (ISDIGIT (*ptr))
1536 goto parsesize;
1537
1538 switch (TOLOWER (*ptr))
1539 {
1540 case 'i': thistype = NT_integer; break;
1541 case 'f': thistype = NT_float; break;
1542 case 'p': thistype = NT_poly; break;
1543 case 's': thistype = NT_signed; break;
1544 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1545 case 'd':
1546 thistype = NT_float;
1547 thissize = 64;
1548 ptr++;
1549 goto done;
aab2c27d
MM
1550 case 'b':
1551 thistype = NT_bfloat;
1552 switch (TOLOWER (*(++ptr)))
1553 {
1554 case 'f':
1555 ptr += 1;
1556 thissize = strtoul (ptr, &ptr, 10);
1557 if (thissize != 16)
1558 {
1559 as_bad (_("bad size %d in type specifier"), thissize);
1560 return FAIL;
1561 }
1562 goto done;
1563 case '0': case '1': case '2': case '3': case '4':
1564 case '5': case '6': case '7': case '8': case '9':
1565 case ' ': case '.':
1566 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1567 return FAIL;
1568 default:
1569 break;
1570 }
1571 break;
dcbf9037
JB
1572 default:
1573 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1574 return FAIL;
1575 }
1576
1577 ptr++;
1578
1579 /* .f is an abbreviation for .f32. */
1580 if (thistype == NT_float && !ISDIGIT (*ptr))
1581 thissize = 32;
1582 else
1583 {
1584 parsesize:
1585 thissize = strtoul (ptr, &ptr, 10);
1586
1587 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1588 && thissize != 64)
1589 {
1590 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1591 return FAIL;
1592 }
1593 }
1594
037e8744 1595 done:
dcbf9037 1596 if (type)
477330fc
RM
1597 {
1598 type->el[type->elems].type = thistype;
dcbf9037
JB
1599 type->el[type->elems].size = thissize;
1600 type->elems++;
1601 }
1602 }
1603
1604 /* Empty/missing type is not a successful parse. */
1605 if (type->elems == 0)
1606 return FAIL;
1607
1608 *str = ptr;
1609
1610 return SUCCESS;
1611}
1612
1613/* Errors may be set multiple times during parsing or bit encoding
1614 (particularly in the Neon bits), but usually the earliest error which is set
1615 will be the most meaningful. Avoid overwriting it with later (cascading)
1616 errors by calling this function. */
1617
1618static void
1619first_error (const char *err)
1620{
1621 if (!inst.error)
1622 inst.error = err;
1623}
1624
1625/* Parse a single type, e.g. ".s32", leading period included. */
1626static int
1627parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1628{
1629 char *str = *ccp;
1630 struct neon_type optype;
1631
1632 if (*str == '.')
1633 {
1634 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1635 {
1636 if (optype.elems == 1)
1637 *vectype = optype.el[0];
1638 else
1639 {
1640 first_error (_("only one type should be specified for operand"));
1641 return FAIL;
1642 }
1643 }
dcbf9037 1644 else
477330fc
RM
1645 {
1646 first_error (_("vector type expected"));
1647 return FAIL;
1648 }
dcbf9037
JB
1649 }
1650 else
1651 return FAIL;
5f4273c7 1652
dcbf9037 1653 *ccp = str;
5f4273c7 1654
dcbf9037
JB
1655 return SUCCESS;
1656}
1657
1658/* Special meanings for indices (which have a range of 0-7), which will fit into
1659 a 4-bit integer. */
1660
1661#define NEON_ALL_LANES 15
1662#define NEON_INTERLEAVE_LANES 14
1663
5ee91343
AV
1664/* Record a use of the given feature. */
1665static void
1666record_feature_use (const arm_feature_set *feature)
1667{
1668 if (thumb_mode)
1669 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1670 else
1671 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1672}
1673
1674/* If the given feature available in the selected CPU, mark it as used.
1675 Returns TRUE iff feature is available. */
1676static bfd_boolean
1677mark_feature_used (const arm_feature_set *feature)
1678{
886e1c73
AV
1679
1680 /* Do not support the use of MVE only instructions when in auto-detection or
1681 -march=all. */
1682 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1683 && ARM_CPU_IS_ANY (cpu_variant))
1684 {
1685 first_error (BAD_MVE_AUTO);
1686 return FALSE;
1687 }
5ee91343
AV
1688 /* Ensure the option is valid on the current architecture. */
1689 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1690 return FALSE;
1691
1692 /* Add the appropriate architecture feature for the barrier option used.
1693 */
1694 record_feature_use (feature);
1695
1696 return TRUE;
1697}
1698
dcbf9037
JB
1699/* Parse either a register or a scalar, with an optional type. Return the
1700 register number, and optionally fill in the actual type of the register
1701 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1702 type/index information in *TYPEINFO. */
1703
1704static int
1705parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1706 enum arm_reg_type *rtype,
1707 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1708{
1709 char *str = *ccp;
1710 struct reg_entry *reg = arm_reg_parse_multi (&str);
1711 struct neon_typed_alias atype;
1712 struct neon_type_el parsetype;
1713
1714 atype.defined = 0;
1715 atype.index = -1;
1716 atype.eltype.type = NT_invtype;
1717 atype.eltype.size = -1;
1718
1719 /* Try alternate syntax for some types of register. Note these are mutually
1720 exclusive with the Neon syntax extensions. */
1721 if (reg == NULL)
1722 {
1723 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1724 if (altreg != FAIL)
477330fc 1725 *ccp = str;
dcbf9037 1726 if (typeinfo)
477330fc 1727 *typeinfo = atype;
dcbf9037
JB
1728 return altreg;
1729 }
1730
037e8744
JB
1731 /* Undo polymorphism when a set of register types may be accepted. */
1732 if ((type == REG_TYPE_NDQ
1733 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1734 || (type == REG_TYPE_VFSD
477330fc 1735 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1736 || (type == REG_TYPE_NSDQ
477330fc
RM
1737 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1738 || reg->type == REG_TYPE_NQ))
dec41383
JW
1739 || (type == REG_TYPE_NSD
1740 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1741 || (type == REG_TYPE_MMXWC
1742 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1743 type = (enum arm_reg_type) reg->type;
dcbf9037 1744
5ee91343
AV
1745 if (type == REG_TYPE_MQ)
1746 {
1747 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1748 return FAIL;
1749
1750 if (!reg || reg->type != REG_TYPE_NQ)
1751 return FAIL;
1752
1753 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1754 {
1755 first_error (_("expected MVE register [q0..q7]"));
1756 return FAIL;
1757 }
1758 type = REG_TYPE_NQ;
1759 }
1760 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1761 && (type == REG_TYPE_NQ))
1762 return FAIL;
1763
1764
dcbf9037
JB
1765 if (type != reg->type)
1766 return FAIL;
1767
1768 if (reg->neon)
1769 atype = *reg->neon;
5f4273c7 1770
dcbf9037
JB
1771 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1772 {
1773 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1774 {
1775 first_error (_("can't redefine type for operand"));
1776 return FAIL;
1777 }
dcbf9037
JB
1778 atype.defined |= NTA_HASTYPE;
1779 atype.eltype = parsetype;
1780 }
5f4273c7 1781
dcbf9037
JB
1782 if (skip_past_char (&str, '[') == SUCCESS)
1783 {
dec41383
JW
1784 if (type != REG_TYPE_VFD
1785 && !(type == REG_TYPE_VFS
57785aa2
AV
1786 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1787 && !(type == REG_TYPE_NQ
1788 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1789 {
57785aa2
AV
1790 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1791 first_error (_("only D and Q registers may be indexed"));
1792 else
1793 first_error (_("only D registers may be indexed"));
477330fc
RM
1794 return FAIL;
1795 }
5f4273c7 1796
dcbf9037 1797 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1798 {
1799 first_error (_("can't change index for operand"));
1800 return FAIL;
1801 }
dcbf9037
JB
1802
1803 atype.defined |= NTA_HASINDEX;
1804
1805 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1806 atype.index = NEON_ALL_LANES;
dcbf9037 1807 else
477330fc
RM
1808 {
1809 expressionS exp;
dcbf9037 1810
477330fc 1811 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1812
477330fc
RM
1813 if (exp.X_op != O_constant)
1814 {
1815 first_error (_("constant expression required"));
1816 return FAIL;
1817 }
dcbf9037 1818
477330fc
RM
1819 if (skip_past_char (&str, ']') == FAIL)
1820 return FAIL;
dcbf9037 1821
477330fc
RM
1822 atype.index = exp.X_add_number;
1823 }
dcbf9037 1824 }
5f4273c7 1825
dcbf9037
JB
1826 if (typeinfo)
1827 *typeinfo = atype;
5f4273c7 1828
dcbf9037
JB
1829 if (rtype)
1830 *rtype = type;
5f4273c7 1831
dcbf9037 1832 *ccp = str;
5f4273c7 1833
dcbf9037
JB
1834 return reg->number;
1835}
1836
efd6b359 1837/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1838 - If RTYPE is non-zero, return the (possibly restricted) type of the
1839 register (e.g. Neon double or quad reg when either has been requested).
1840 - If this is a Neon vector type with additional type information, fill
1841 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1842 This function will fault on encountering a scalar. */
dcbf9037
JB
1843
1844static int
1845arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1846 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1847{
1848 struct neon_typed_alias atype;
1849 char *str = *ccp;
1850 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1851
1852 if (reg == FAIL)
1853 return FAIL;
1854
0855e32b
NS
1855 /* Do not allow regname(... to parse as a register. */
1856 if (*str == '(')
1857 return FAIL;
1858
dcbf9037
JB
1859 /* Do not allow a scalar (reg+index) to parse as a register. */
1860 if ((atype.defined & NTA_HASINDEX) != 0)
1861 {
1862 first_error (_("register operand expected, but got scalar"));
1863 return FAIL;
1864 }
1865
1866 if (vectype)
1867 *vectype = atype.eltype;
1868
1869 *ccp = str;
1870
1871 return reg;
1872}
1873
1874#define NEON_SCALAR_REG(X) ((X) >> 4)
1875#define NEON_SCALAR_INDEX(X) ((X) & 15)
1876
5287ad62
JB
1877/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1878 have enough information to be able to do a good job bounds-checking. So, we
1879 just do easy checks here, and do further checks later. */
1880
1881static int
57785aa2
AV
1882parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1883 arm_reg_type reg_type)
5287ad62 1884{
dcbf9037 1885 int reg;
5287ad62 1886 char *str = *ccp;
dcbf9037 1887 struct neon_typed_alias atype;
57785aa2 1888 unsigned reg_size;
5f4273c7 1889
dec41383 1890 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1891
57785aa2
AV
1892 switch (reg_type)
1893 {
1894 case REG_TYPE_VFS:
1895 reg_size = 32;
1896 break;
1897 case REG_TYPE_VFD:
1898 reg_size = 64;
1899 break;
1900 case REG_TYPE_MQ:
1901 reg_size = 128;
1902 break;
1903 default:
1904 gas_assert (0);
1905 return FAIL;
1906 }
1907
dcbf9037 1908 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1909 return FAIL;
5f4273c7 1910
57785aa2 1911 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1912 {
dcbf9037 1913 first_error (_("scalar must have an index"));
5287ad62
JB
1914 return FAIL;
1915 }
57785aa2 1916 else if (atype.index >= reg_size / elsize)
5287ad62 1917 {
dcbf9037 1918 first_error (_("scalar index out of range"));
5287ad62
JB
1919 return FAIL;
1920 }
5f4273c7 1921
dcbf9037
JB
1922 if (type)
1923 *type = atype.eltype;
5f4273c7 1924
5287ad62 1925 *ccp = str;
5f4273c7 1926
dcbf9037 1927 return reg * 16 + atype.index;
5287ad62
JB
1928}
1929
4b5a202f
AV
1930/* Types of registers in a list. */
1931
1932enum reg_list_els
1933{
1934 REGLIST_RN,
1935 REGLIST_CLRM,
1936 REGLIST_VFP_S,
efd6b359 1937 REGLIST_VFP_S_VPR,
4b5a202f 1938 REGLIST_VFP_D,
efd6b359 1939 REGLIST_VFP_D_VPR,
4b5a202f
AV
1940 REGLIST_NEON_D
1941};
1942
c19d1205 1943/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1944
c19d1205 1945static long
4b5a202f 1946parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1947{
4b5a202f
AV
1948 char *str = *strp;
1949 long range = 0;
1950 int another_range;
1951
1952 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1953
c19d1205
ZW
1954 /* We come back here if we get ranges concatenated by '+' or '|'. */
1955 do
6057a28f 1956 {
477330fc
RM
1957 skip_whitespace (str);
1958
c19d1205 1959 another_range = 0;
a737bd4d 1960
c19d1205
ZW
1961 if (*str == '{')
1962 {
1963 int in_range = 0;
1964 int cur_reg = -1;
a737bd4d 1965
c19d1205
ZW
1966 str++;
1967 do
1968 {
1969 int reg;
4b5a202f
AV
1970 const char apsr_str[] = "apsr";
1971 int apsr_str_len = strlen (apsr_str);
6057a28f 1972
a65b5de6 1973 reg = arm_reg_parse (&str, REG_TYPE_RN);
4b5a202f 1974 if (etype == REGLIST_CLRM)
c19d1205 1975 {
4b5a202f
AV
1976 if (reg == REG_SP || reg == REG_PC)
1977 reg = FAIL;
1978 else if (reg == FAIL
1979 && !strncasecmp (str, apsr_str, apsr_str_len)
1980 && !ISALPHA (*(str + apsr_str_len)))
1981 {
1982 reg = 15;
1983 str += apsr_str_len;
1984 }
1985
1986 if (reg == FAIL)
1987 {
1988 first_error (_("r0-r12, lr or APSR expected"));
1989 return FAIL;
1990 }
1991 }
1992 else /* etype == REGLIST_RN. */
1993 {
1994 if (reg == FAIL)
1995 {
1996 first_error (_(reg_expected_msgs[REGLIST_RN]));
1997 return FAIL;
1998 }
c19d1205 1999 }
a737bd4d 2000
c19d1205
ZW
2001 if (in_range)
2002 {
2003 int i;
a737bd4d 2004
c19d1205
ZW
2005 if (reg <= cur_reg)
2006 {
dcbf9037 2007 first_error (_("bad range in register list"));
c19d1205
ZW
2008 return FAIL;
2009 }
40a18ebd 2010
c19d1205
ZW
2011 for (i = cur_reg + 1; i < reg; i++)
2012 {
2013 if (range & (1 << i))
2014 as_tsktsk
2015 (_("Warning: duplicated register (r%d) in register list"),
2016 i);
2017 else
2018 range |= 1 << i;
2019 }
2020 in_range = 0;
2021 }
a737bd4d 2022
c19d1205
ZW
2023 if (range & (1 << reg))
2024 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2025 reg);
2026 else if (reg <= cur_reg)
2027 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 2028
c19d1205
ZW
2029 range |= 1 << reg;
2030 cur_reg = reg;
2031 }
2032 while (skip_past_comma (&str) != FAIL
2033 || (in_range = 1, *str++ == '-'));
2034 str--;
a737bd4d 2035
d996d970 2036 if (skip_past_char (&str, '}') == FAIL)
c19d1205 2037 {
dcbf9037 2038 first_error (_("missing `}'"));
c19d1205
ZW
2039 return FAIL;
2040 }
2041 }
4b5a202f 2042 else if (etype == REGLIST_RN)
c19d1205 2043 {
91d6fa6a 2044 expressionS exp;
40a18ebd 2045
91d6fa6a 2046 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 2047 return FAIL;
40a18ebd 2048
91d6fa6a 2049 if (exp.X_op == O_constant)
c19d1205 2050 {
91d6fa6a
NC
2051 if (exp.X_add_number
2052 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
2053 {
2054 inst.error = _("invalid register mask");
2055 return FAIL;
2056 }
a737bd4d 2057
91d6fa6a 2058 if ((range & exp.X_add_number) != 0)
c19d1205 2059 {
91d6fa6a 2060 int regno = range & exp.X_add_number;
a737bd4d 2061
c19d1205
ZW
2062 regno &= -regno;
2063 regno = (1 << regno) - 1;
2064 as_tsktsk
2065 (_("Warning: duplicated register (r%d) in register list"),
2066 regno);
2067 }
a737bd4d 2068
91d6fa6a 2069 range |= exp.X_add_number;
c19d1205
ZW
2070 }
2071 else
2072 {
e2b0ab59 2073 if (inst.relocs[0].type != 0)
c19d1205
ZW
2074 {
2075 inst.error = _("expression too complex");
2076 return FAIL;
2077 }
a737bd4d 2078
e2b0ab59
AV
2079 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2080 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2081 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
2082 }
2083 }
a737bd4d 2084
c19d1205
ZW
2085 if (*str == '|' || *str == '+')
2086 {
2087 str++;
2088 another_range = 1;
2089 }
a737bd4d 2090 }
c19d1205 2091 while (another_range);
a737bd4d 2092
c19d1205
ZW
2093 *strp = str;
2094 return range;
a737bd4d
NC
2095}
2096
c19d1205
ZW
2097/* Parse a VFP register list. If the string is invalid return FAIL.
2098 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
2099 register. Parses registers of type ETYPE.
2100 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2101 - Q registers can be used to specify pairs of D registers
2102 - { } can be omitted from around a singleton register list
477330fc
RM
2103 FIXME: This is not implemented, as it would require backtracking in
2104 some cases, e.g.:
2105 vtbl.8 d3,d4,d5
2106 This could be done (the meaning isn't really ambiguous), but doesn't
2107 fit in well with the current parsing framework.
dcbf9037
JB
2108 - 32 D registers may be used (also true for VFPv3).
2109 FIXME: Types are ignored in these register lists, which is probably a
2110 bug. */
6057a28f 2111
c19d1205 2112static int
efd6b359
AV
2113parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2114 bfd_boolean *partial_match)
6057a28f 2115{
037e8744 2116 char *str = *ccp;
c19d1205
ZW
2117 int base_reg;
2118 int new_base;
21d799b5 2119 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2120 int max_regs = 0;
c19d1205
ZW
2121 int count = 0;
2122 int warned = 0;
2123 unsigned long mask = 0;
a737bd4d 2124 int i;
efd6b359
AV
2125 bfd_boolean vpr_seen = FALSE;
2126 bfd_boolean expect_vpr =
2127 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2128
477330fc 2129 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2130 {
2131 inst.error = _("expecting {");
2132 return FAIL;
2133 }
6057a28f 2134
5287ad62 2135 switch (etype)
c19d1205 2136 {
5287ad62 2137 case REGLIST_VFP_S:
efd6b359 2138 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2139 regtype = REG_TYPE_VFS;
2140 max_regs = 32;
5287ad62 2141 break;
5f4273c7 2142
5287ad62 2143 case REGLIST_VFP_D:
efd6b359 2144 case REGLIST_VFP_D_VPR:
5287ad62 2145 regtype = REG_TYPE_VFD;
b7fc2769 2146 break;
5f4273c7 2147
b7fc2769
JB
2148 case REGLIST_NEON_D:
2149 regtype = REG_TYPE_NDQ;
2150 break;
4b5a202f
AV
2151
2152 default:
2153 gas_assert (0);
b7fc2769
JB
2154 }
2155
efd6b359 2156 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2157 {
b1cc4aeb
PB
2158 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2159 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2160 {
2161 max_regs = 32;
2162 if (thumb_mode)
2163 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2164 fpu_vfp_ext_d32);
2165 else
2166 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2167 fpu_vfp_ext_d32);
2168 }
5287ad62 2169 else
477330fc 2170 max_regs = 16;
c19d1205 2171 }
6057a28f 2172
c19d1205 2173 base_reg = max_regs;
efd6b359 2174 *partial_match = FALSE;
a737bd4d 2175
c19d1205
ZW
2176 do
2177 {
7af67752 2178 unsigned int setmask = 1, addregs = 1;
efd6b359 2179 const char vpr_str[] = "vpr";
7af67752 2180 size_t vpr_str_len = strlen (vpr_str);
dcbf9037 2181
037e8744 2182 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2183
efd6b359
AV
2184 if (expect_vpr)
2185 {
2186 if (new_base == FAIL
2187 && !strncasecmp (str, vpr_str, vpr_str_len)
2188 && !ISALPHA (*(str + vpr_str_len))
2189 && !vpr_seen)
2190 {
2191 vpr_seen = TRUE;
2192 str += vpr_str_len;
2193 if (count == 0)
2194 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2195 }
2196 else if (vpr_seen)
2197 {
2198 first_error (_("VPR expected last"));
2199 return FAIL;
2200 }
2201 else if (new_base == FAIL)
2202 {
2203 if (regtype == REG_TYPE_VFS)
2204 first_error (_("VFP single precision register or VPR "
2205 "expected"));
2206 else /* regtype == REG_TYPE_VFD. */
2207 first_error (_("VFP/Neon double precision register or VPR "
2208 "expected"));
2209 return FAIL;
2210 }
2211 }
2212 else if (new_base == FAIL)
a737bd4d 2213 {
dcbf9037 2214 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2215 return FAIL;
2216 }
5f4273c7 2217
efd6b359
AV
2218 *partial_match = TRUE;
2219 if (vpr_seen)
2220 continue;
2221
b7fc2769 2222 if (new_base >= max_regs)
477330fc
RM
2223 {
2224 first_error (_("register out of range in list"));
2225 return FAIL;
2226 }
5f4273c7 2227
5287ad62
JB
2228 /* Note: a value of 2 * n is returned for the register Q<n>. */
2229 if (regtype == REG_TYPE_NQ)
477330fc
RM
2230 {
2231 setmask = 3;
2232 addregs = 2;
2233 }
5287ad62 2234
c19d1205
ZW
2235 if (new_base < base_reg)
2236 base_reg = new_base;
a737bd4d 2237
5287ad62 2238 if (mask & (setmask << new_base))
c19d1205 2239 {
dcbf9037 2240 first_error (_("invalid register list"));
c19d1205 2241 return FAIL;
a737bd4d 2242 }
a737bd4d 2243
efd6b359 2244 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2245 {
2246 as_tsktsk (_("register list not in ascending order"));
2247 warned = 1;
2248 }
0bbf2aa4 2249
5287ad62
JB
2250 mask |= setmask << new_base;
2251 count += addregs;
0bbf2aa4 2252
037e8744 2253 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2254 {
2255 int high_range;
0bbf2aa4 2256
037e8744 2257 str++;
0bbf2aa4 2258
037e8744 2259 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2260 == FAIL)
c19d1205
ZW
2261 {
2262 inst.error = gettext (reg_expected_msgs[regtype]);
2263 return FAIL;
2264 }
0bbf2aa4 2265
477330fc
RM
2266 if (high_range >= max_regs)
2267 {
2268 first_error (_("register out of range in list"));
2269 return FAIL;
2270 }
b7fc2769 2271
477330fc
RM
2272 if (regtype == REG_TYPE_NQ)
2273 high_range = high_range + 1;
5287ad62 2274
c19d1205
ZW
2275 if (high_range <= new_base)
2276 {
2277 inst.error = _("register range not in ascending order");
2278 return FAIL;
2279 }
0bbf2aa4 2280
5287ad62 2281 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2282 {
5287ad62 2283 if (mask & (setmask << new_base))
0bbf2aa4 2284 {
c19d1205
ZW
2285 inst.error = _("invalid register list");
2286 return FAIL;
0bbf2aa4 2287 }
c19d1205 2288
5287ad62
JB
2289 mask |= setmask << new_base;
2290 count += addregs;
0bbf2aa4 2291 }
0bbf2aa4 2292 }
0bbf2aa4 2293 }
037e8744 2294 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2295
037e8744 2296 str++;
0bbf2aa4 2297
c19d1205 2298 /* Sanity check -- should have raised a parse error above. */
efd6b359 2299 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2300 abort ();
2301
2302 *pbase = base_reg;
2303
efd6b359
AV
2304 if (expect_vpr && !vpr_seen)
2305 {
2306 first_error (_("VPR expected last"));
2307 return FAIL;
2308 }
2309
c19d1205
ZW
2310 /* Final test -- the registers must be consecutive. */
2311 mask >>= base_reg;
2312 for (i = 0; i < count; i++)
2313 {
2314 if ((mask & (1u << i)) == 0)
2315 {
2316 inst.error = _("non-contiguous register range");
2317 return FAIL;
2318 }
2319 }
2320
037e8744
JB
2321 *ccp = str;
2322
c19d1205 2323 return count;
b99bd4ef
NC
2324}
2325
dcbf9037
JB
2326/* True if two alias types are the same. */
2327
c921be7d 2328static bfd_boolean
dcbf9037
JB
2329neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2330{
2331 if (!a && !b)
c921be7d 2332 return TRUE;
5f4273c7 2333
dcbf9037 2334 if (!a || !b)
c921be7d 2335 return FALSE;
dcbf9037
JB
2336
2337 if (a->defined != b->defined)
c921be7d 2338 return FALSE;
5f4273c7 2339
dcbf9037
JB
2340 if ((a->defined & NTA_HASTYPE) != 0
2341 && (a->eltype.type != b->eltype.type
477330fc 2342 || a->eltype.size != b->eltype.size))
c921be7d 2343 return FALSE;
dcbf9037
JB
2344
2345 if ((a->defined & NTA_HASINDEX) != 0
2346 && (a->index != b->index))
c921be7d 2347 return FALSE;
5f4273c7 2348
c921be7d 2349 return TRUE;
dcbf9037
JB
2350}
2351
5287ad62
JB
2352/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2353 The base register is put in *PBASE.
dcbf9037 2354 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2355 the return value.
2356 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2357 Bits [6:5] encode the list length (minus one).
2358 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2359
5287ad62 2360#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2361#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2362#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2363
2364static int
dcbf9037 2365parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2366 int mve,
477330fc 2367 struct neon_type_el *eltype)
5287ad62
JB
2368{
2369 char *ptr = *str;
2370 int base_reg = -1;
2371 int reg_incr = -1;
2372 int count = 0;
2373 int lane = -1;
2374 int leading_brace = 0;
2375 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2376 const char *const incr_error = mve ? _("register stride must be 1") :
2377 _("register stride must be 1 or 2");
20203fb9 2378 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2379 struct neon_typed_alias firsttype;
f85d59c3
KT
2380 firsttype.defined = 0;
2381 firsttype.eltype.type = NT_invtype;
2382 firsttype.eltype.size = -1;
2383 firsttype.index = -1;
5f4273c7 2384
5287ad62
JB
2385 if (skip_past_char (&ptr, '{') == SUCCESS)
2386 leading_brace = 1;
5f4273c7 2387
5287ad62
JB
2388 do
2389 {
dcbf9037 2390 struct neon_typed_alias atype;
35c228db
AV
2391 if (mve)
2392 rtype = REG_TYPE_MQ;
dcbf9037
JB
2393 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2394
5287ad62 2395 if (getreg == FAIL)
477330fc
RM
2396 {
2397 first_error (_(reg_expected_msgs[rtype]));
2398 return FAIL;
2399 }
5f4273c7 2400
5287ad62 2401 if (base_reg == -1)
477330fc
RM
2402 {
2403 base_reg = getreg;
2404 if (rtype == REG_TYPE_NQ)
2405 {
2406 reg_incr = 1;
2407 }
2408 firsttype = atype;
2409 }
5287ad62 2410 else if (reg_incr == -1)
477330fc
RM
2411 {
2412 reg_incr = getreg - base_reg;
2413 if (reg_incr < 1 || reg_incr > 2)
2414 {
2415 first_error (_(incr_error));
2416 return FAIL;
2417 }
2418 }
5287ad62 2419 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2420 {
2421 first_error (_(incr_error));
2422 return FAIL;
2423 }
dcbf9037 2424
c921be7d 2425 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2426 {
2427 first_error (_(type_error));
2428 return FAIL;
2429 }
5f4273c7 2430
5287ad62 2431 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2432 modes. */
5287ad62 2433 if (ptr[0] == '-')
477330fc
RM
2434 {
2435 struct neon_typed_alias htype;
2436 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2437 if (lane == -1)
2438 lane = NEON_INTERLEAVE_LANES;
2439 else if (lane != NEON_INTERLEAVE_LANES)
2440 {
2441 first_error (_(type_error));
2442 return FAIL;
2443 }
2444 if (reg_incr == -1)
2445 reg_incr = 1;
2446 else if (reg_incr != 1)
2447 {
2448 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2449 return FAIL;
2450 }
2451 ptr++;
2452 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2453 if (hireg == FAIL)
2454 {
2455 first_error (_(reg_expected_msgs[rtype]));
2456 return FAIL;
2457 }
2458 if (! neon_alias_types_same (&htype, &firsttype))
2459 {
2460 first_error (_(type_error));
2461 return FAIL;
2462 }
2463 count += hireg + dregs - getreg;
2464 continue;
2465 }
5f4273c7 2466
5287ad62
JB
2467 /* If we're using Q registers, we can't use [] or [n] syntax. */
2468 if (rtype == REG_TYPE_NQ)
477330fc
RM
2469 {
2470 count += 2;
2471 continue;
2472 }
5f4273c7 2473
dcbf9037 2474 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2475 {
2476 if (lane == -1)
2477 lane = atype.index;
2478 else if (lane != atype.index)
2479 {
2480 first_error (_(type_error));
2481 return FAIL;
2482 }
2483 }
5287ad62 2484 else if (lane == -1)
477330fc 2485 lane = NEON_INTERLEAVE_LANES;
5287ad62 2486 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2487 {
2488 first_error (_(type_error));
2489 return FAIL;
2490 }
5287ad62
JB
2491 count++;
2492 }
2493 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2494
5287ad62
JB
2495 /* No lane set by [x]. We must be interleaving structures. */
2496 if (lane == -1)
2497 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2498
5287ad62 2499 /* Sanity check. */
35c228db 2500 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2501 || (count > 1 && reg_incr == -1))
2502 {
dcbf9037 2503 first_error (_("error parsing element/structure list"));
5287ad62
JB
2504 return FAIL;
2505 }
2506
2507 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2508 {
dcbf9037 2509 first_error (_("expected }"));
5287ad62
JB
2510 return FAIL;
2511 }
5f4273c7 2512
5287ad62
JB
2513 if (reg_incr == -1)
2514 reg_incr = 1;
2515
dcbf9037
JB
2516 if (eltype)
2517 *eltype = firsttype.eltype;
2518
5287ad62
JB
2519 *pbase = base_reg;
2520 *str = ptr;
5f4273c7 2521
5287ad62
JB
2522 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2523}
2524
c19d1205
ZW
2525/* Parse an explicit relocation suffix on an expression. This is
2526 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2527 arm_reloc_hsh contains no entries, so this function can only
2528 succeed if there is no () after the word. Returns -1 on error,
2529 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2530
c19d1205
ZW
2531static int
2532parse_reloc (char **str)
b99bd4ef 2533{
c19d1205
ZW
2534 struct reloc_entry *r;
2535 char *p, *q;
b99bd4ef 2536
c19d1205
ZW
2537 if (**str != '(')
2538 return BFD_RELOC_UNUSED;
b99bd4ef 2539
c19d1205
ZW
2540 p = *str + 1;
2541 q = p;
2542
2543 while (*q && *q != ')' && *q != ',')
2544 q++;
2545 if (*q != ')')
2546 return -1;
2547
21d799b5 2548 if ((r = (struct reloc_entry *)
629310ab 2549 str_hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2550 return -1;
2551
2552 *str = q + 1;
2553 return r->reloc;
b99bd4ef
NC
2554}
2555
c19d1205
ZW
2556/* Directives: register aliases. */
2557
dcbf9037 2558static struct reg_entry *
90ec0d68 2559insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2560{
d3ce72d0 2561 struct reg_entry *new_reg;
c19d1205 2562 const char *name;
b99bd4ef 2563
629310ab 2564 if ((new_reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2565 {
d3ce72d0 2566 if (new_reg->builtin)
c19d1205 2567 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2568
c19d1205
ZW
2569 /* Only warn about a redefinition if it's not defined as the
2570 same register. */
d3ce72d0 2571 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2572 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2573
d929913e 2574 return NULL;
c19d1205 2575 }
b99bd4ef 2576
c19d1205 2577 name = xstrdup (str);
325801bd 2578 new_reg = XNEW (struct reg_entry);
b99bd4ef 2579
d3ce72d0
NC
2580 new_reg->name = name;
2581 new_reg->number = number;
2582 new_reg->type = type;
2583 new_reg->builtin = FALSE;
2584 new_reg->neon = NULL;
b99bd4ef 2585
fe0e921f 2586 str_hash_insert (arm_reg_hsh, name, new_reg, 0);
5f4273c7 2587
d3ce72d0 2588 return new_reg;
dcbf9037
JB
2589}
2590
2591static void
2592insert_neon_reg_alias (char *str, int number, int type,
477330fc 2593 struct neon_typed_alias *atype)
dcbf9037
JB
2594{
2595 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2596
dcbf9037
JB
2597 if (!reg)
2598 {
2599 first_error (_("attempt to redefine typed alias"));
2600 return;
2601 }
5f4273c7 2602
dcbf9037
JB
2603 if (atype)
2604 {
325801bd 2605 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2606 *reg->neon = *atype;
2607 }
c19d1205 2608}
b99bd4ef 2609
c19d1205 2610/* Look for the .req directive. This is of the form:
b99bd4ef 2611
c19d1205 2612 new_register_name .req existing_register_name
b99bd4ef 2613
c19d1205 2614 If we find one, or if it looks sufficiently like one that we want to
d929913e 2615 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2616
d929913e 2617static bfd_boolean
c19d1205
ZW
2618create_register_alias (char * newname, char *p)
2619{
2620 struct reg_entry *old;
2621 char *oldname, *nbuf;
2622 size_t nlen;
b99bd4ef 2623
c19d1205
ZW
2624 /* The input scrubber ensures that whitespace after the mnemonic is
2625 collapsed to single spaces. */
2626 oldname = p;
2627 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2628 return FALSE;
b99bd4ef 2629
c19d1205
ZW
2630 oldname += 6;
2631 if (*oldname == '\0')
d929913e 2632 return FALSE;
b99bd4ef 2633
629310ab 2634 old = (struct reg_entry *) str_hash_find (arm_reg_hsh, oldname);
c19d1205 2635 if (!old)
b99bd4ef 2636 {
c19d1205 2637 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2638 return TRUE;
b99bd4ef
NC
2639 }
2640
c19d1205
ZW
2641 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2642 the desired alias name, and p points to its end. If not, then
2643 the desired alias name is in the global original_case_string. */
2644#ifdef TC_CASE_SENSITIVE
2645 nlen = p - newname;
2646#else
2647 newname = original_case_string;
2648 nlen = strlen (newname);
2649#endif
b99bd4ef 2650
29a2809e 2651 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2652
c19d1205
ZW
2653 /* Create aliases under the new name as stated; an all-lowercase
2654 version of the new name; and an all-uppercase version of the new
2655 name. */
d929913e
NC
2656 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2657 {
2658 for (p = nbuf; *p; p++)
2659 *p = TOUPPER (*p);
c19d1205 2660
d929913e
NC
2661 if (strncmp (nbuf, newname, nlen))
2662 {
2663 /* If this attempt to create an additional alias fails, do not bother
2664 trying to create the all-lower case alias. We will fail and issue
2665 a second, duplicate error message. This situation arises when the
2666 programmer does something like:
2667 foo .req r0
2668 Foo .req r1
2669 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2670 the artificial FOO alias because it has already been created by the
d929913e
NC
2671 first .req. */
2672 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2673 {
2674 free (nbuf);
2675 return TRUE;
2676 }
d929913e 2677 }
c19d1205 2678
d929913e
NC
2679 for (p = nbuf; *p; p++)
2680 *p = TOLOWER (*p);
c19d1205 2681
d929913e
NC
2682 if (strncmp (nbuf, newname, nlen))
2683 insert_reg_alias (nbuf, old->number, old->type);
2684 }
c19d1205 2685
e1fa0163 2686 free (nbuf);
d929913e 2687 return TRUE;
b99bd4ef
NC
2688}
2689
dcbf9037
JB
2690/* Create a Neon typed/indexed register alias using directives, e.g.:
2691 X .dn d5.s32[1]
2692 Y .qn 6.s16
2693 Z .dn d7
2694 T .dn Z[0]
2695 These typed registers can be used instead of the types specified after the
2696 Neon mnemonic, so long as all operands given have types. Types can also be
2697 specified directly, e.g.:
5f4273c7 2698 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2699
c921be7d 2700static bfd_boolean
dcbf9037
JB
2701create_neon_reg_alias (char *newname, char *p)
2702{
2703 enum arm_reg_type basetype;
2704 struct reg_entry *basereg;
2705 struct reg_entry mybasereg;
2706 struct neon_type ntype;
2707 struct neon_typed_alias typeinfo;
12d6b0b7 2708 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2709 int namelen;
5f4273c7 2710
dcbf9037
JB
2711 typeinfo.defined = 0;
2712 typeinfo.eltype.type = NT_invtype;
2713 typeinfo.eltype.size = -1;
2714 typeinfo.index = -1;
5f4273c7 2715
dcbf9037 2716 nameend = p;
5f4273c7 2717
dcbf9037
JB
2718 if (strncmp (p, " .dn ", 5) == 0)
2719 basetype = REG_TYPE_VFD;
2720 else if (strncmp (p, " .qn ", 5) == 0)
2721 basetype = REG_TYPE_NQ;
2722 else
c921be7d 2723 return FALSE;
5f4273c7 2724
dcbf9037 2725 p += 5;
5f4273c7 2726
dcbf9037 2727 if (*p == '\0')
c921be7d 2728 return FALSE;
5f4273c7 2729
dcbf9037
JB
2730 basereg = arm_reg_parse_multi (&p);
2731
2732 if (basereg && basereg->type != basetype)
2733 {
2734 as_bad (_("bad type for register"));
c921be7d 2735 return FALSE;
dcbf9037
JB
2736 }
2737
2738 if (basereg == NULL)
2739 {
2740 expressionS exp;
2741 /* Try parsing as an integer. */
2742 my_get_expression (&exp, &p, GE_NO_PREFIX);
2743 if (exp.X_op != O_constant)
477330fc
RM
2744 {
2745 as_bad (_("expression must be constant"));
2746 return FALSE;
2747 }
dcbf9037
JB
2748 basereg = &mybasereg;
2749 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2750 : exp.X_add_number;
dcbf9037
JB
2751 basereg->neon = 0;
2752 }
2753
2754 if (basereg->neon)
2755 typeinfo = *basereg->neon;
2756
2757 if (parse_neon_type (&ntype, &p) == SUCCESS)
2758 {
2759 /* We got a type. */
2760 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2761 {
2762 as_bad (_("can't redefine the type of a register alias"));
2763 return FALSE;
2764 }
5f4273c7 2765
dcbf9037
JB
2766 typeinfo.defined |= NTA_HASTYPE;
2767 if (ntype.elems != 1)
477330fc
RM
2768 {
2769 as_bad (_("you must specify a single type only"));
2770 return FALSE;
2771 }
dcbf9037
JB
2772 typeinfo.eltype = ntype.el[0];
2773 }
5f4273c7 2774
dcbf9037
JB
2775 if (skip_past_char (&p, '[') == SUCCESS)
2776 {
2777 expressionS exp;
2778 /* We got a scalar index. */
5f4273c7 2779
dcbf9037 2780 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2781 {
2782 as_bad (_("can't redefine the index of a scalar alias"));
2783 return FALSE;
2784 }
5f4273c7 2785
dcbf9037 2786 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2787
dcbf9037 2788 if (exp.X_op != O_constant)
477330fc
RM
2789 {
2790 as_bad (_("scalar index must be constant"));
2791 return FALSE;
2792 }
5f4273c7 2793
dcbf9037
JB
2794 typeinfo.defined |= NTA_HASINDEX;
2795 typeinfo.index = exp.X_add_number;
5f4273c7 2796
dcbf9037 2797 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2798 {
2799 as_bad (_("expecting ]"));
2800 return FALSE;
2801 }
dcbf9037
JB
2802 }
2803
15735687
NS
2804 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2805 the desired alias name, and p points to its end. If not, then
2806 the desired alias name is in the global original_case_string. */
2807#ifdef TC_CASE_SENSITIVE
dcbf9037 2808 namelen = nameend - newname;
15735687
NS
2809#else
2810 newname = original_case_string;
2811 namelen = strlen (newname);
2812#endif
2813
29a2809e 2814 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2815
dcbf9037 2816 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2817 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2818
dcbf9037
JB
2819 /* Insert name in all uppercase. */
2820 for (p = namebuf; *p; p++)
2821 *p = TOUPPER (*p);
5f4273c7 2822
dcbf9037
JB
2823 if (strncmp (namebuf, newname, namelen))
2824 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2825 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2826
dcbf9037
JB
2827 /* Insert name in all lowercase. */
2828 for (p = namebuf; *p; p++)
2829 *p = TOLOWER (*p);
5f4273c7 2830
dcbf9037
JB
2831 if (strncmp (namebuf, newname, namelen))
2832 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2833 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2834
e1fa0163 2835 free (namebuf);
c921be7d 2836 return TRUE;
dcbf9037
JB
2837}
2838
c19d1205
ZW
2839/* Should never be called, as .req goes between the alias and the
2840 register name, not at the beginning of the line. */
c921be7d 2841
b99bd4ef 2842static void
c19d1205 2843s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2844{
c19d1205
ZW
2845 as_bad (_("invalid syntax for .req directive"));
2846}
b99bd4ef 2847
dcbf9037
JB
2848static void
2849s_dn (int a ATTRIBUTE_UNUSED)
2850{
2851 as_bad (_("invalid syntax for .dn directive"));
2852}
2853
2854static void
2855s_qn (int a ATTRIBUTE_UNUSED)
2856{
2857 as_bad (_("invalid syntax for .qn directive"));
2858}
2859
c19d1205
ZW
2860/* The .unreq directive deletes an alias which was previously defined
2861 by .req. For example:
b99bd4ef 2862
c19d1205
ZW
2863 my_alias .req r11
2864 .unreq my_alias */
b99bd4ef
NC
2865
2866static void
c19d1205 2867s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2868{
c19d1205
ZW
2869 char * name;
2870 char saved_char;
b99bd4ef 2871
c19d1205
ZW
2872 name = input_line_pointer;
2873
2874 while (*input_line_pointer != 0
2875 && *input_line_pointer != ' '
2876 && *input_line_pointer != '\n')
2877 ++input_line_pointer;
2878
2879 saved_char = *input_line_pointer;
2880 *input_line_pointer = 0;
2881
2882 if (!*name)
2883 as_bad (_("invalid syntax for .unreq directive"));
2884 else
2885 {
fe0e921f
AM
2886 struct reg_entry *reg
2887 = (struct reg_entry *) str_hash_find (arm_reg_hsh, name);
c19d1205
ZW
2888
2889 if (!reg)
2890 as_bad (_("unknown register alias '%s'"), name);
2891 else if (reg->builtin)
a1727c1a 2892 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2893 name);
2894 else
2895 {
d929913e
NC
2896 char * p;
2897 char * nbuf;
2898
629310ab 2899 str_hash_delete (arm_reg_hsh, name);
c19d1205 2900 free ((char *) reg->name);
9fbb53c7 2901 free (reg->neon);
c19d1205 2902 free (reg);
d929913e
NC
2903
2904 /* Also locate the all upper case and all lower case versions.
2905 Do not complain if we cannot find one or the other as it
2906 was probably deleted above. */
5f4273c7 2907
d929913e
NC
2908 nbuf = strdup (name);
2909 for (p = nbuf; *p; p++)
2910 *p = TOUPPER (*p);
629310ab 2911 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2912 if (reg)
2913 {
629310ab 2914 str_hash_delete (arm_reg_hsh, nbuf);
d929913e 2915 free ((char *) reg->name);
9fbb53c7 2916 free (reg->neon);
d929913e
NC
2917 free (reg);
2918 }
2919
2920 for (p = nbuf; *p; p++)
2921 *p = TOLOWER (*p);
629310ab 2922 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2923 if (reg)
2924 {
629310ab 2925 str_hash_delete (arm_reg_hsh, nbuf);
d929913e 2926 free ((char *) reg->name);
9fbb53c7 2927 free (reg->neon);
d929913e
NC
2928 free (reg);
2929 }
2930
2931 free (nbuf);
c19d1205
ZW
2932 }
2933 }
b99bd4ef 2934
c19d1205 2935 *input_line_pointer = saved_char;
b99bd4ef
NC
2936 demand_empty_rest_of_line ();
2937}
2938
c19d1205
ZW
2939/* Directives: Instruction set selection. */
2940
2941#ifdef OBJ_ELF
2942/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2943 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2944 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2945 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2946
cd000bff
DJ
2947/* Create a new mapping symbol for the transition to STATE. */
2948
2949static void
2950make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2951{
a737bd4d 2952 symbolS * symbolP;
c19d1205
ZW
2953 const char * symname;
2954 int type;
b99bd4ef 2955
c19d1205 2956 switch (state)
b99bd4ef 2957 {
c19d1205
ZW
2958 case MAP_DATA:
2959 symname = "$d";
2960 type = BSF_NO_FLAGS;
2961 break;
2962 case MAP_ARM:
2963 symname = "$a";
2964 type = BSF_NO_FLAGS;
2965 break;
2966 case MAP_THUMB:
2967 symname = "$t";
2968 type = BSF_NO_FLAGS;
2969 break;
c19d1205
ZW
2970 default:
2971 abort ();
2972 }
2973
e01e1cee 2974 symbolP = symbol_new (symname, now_seg, frag, value);
c19d1205
ZW
2975 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2976
2977 switch (state)
2978 {
2979 case MAP_ARM:
2980 THUMB_SET_FUNC (symbolP, 0);
2981 ARM_SET_THUMB (symbolP, 0);
2982 ARM_SET_INTERWORK (symbolP, support_interwork);
2983 break;
2984
2985 case MAP_THUMB:
2986 THUMB_SET_FUNC (symbolP, 1);
2987 ARM_SET_THUMB (symbolP, 1);
2988 ARM_SET_INTERWORK (symbolP, support_interwork);
2989 break;
2990
2991 case MAP_DATA:
2992 default:
cd000bff
DJ
2993 break;
2994 }
2995
2996 /* Save the mapping symbols for future reference. Also check that
2997 we do not place two mapping symbols at the same offset within a
2998 frag. We'll handle overlap between frags in
2de7820f
JZ
2999 check_mapping_symbols.
3000
3001 If .fill or other data filling directive generates zero sized data,
3002 the mapping symbol for the following code will have the same value
3003 as the one generated for the data filling directive. In this case,
3004 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
3005 if (value == 0)
3006 {
2de7820f
JZ
3007 if (frag->tc_frag_data.first_map != NULL)
3008 {
3009 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3010 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3011 }
cd000bff
DJ
3012 frag->tc_frag_data.first_map = symbolP;
3013 }
3014 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
3015 {
3016 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
3017 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3018 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3019 }
cd000bff
DJ
3020 frag->tc_frag_data.last_map = symbolP;
3021}
3022
3023/* We must sometimes convert a region marked as code to data during
3024 code alignment, if an odd number of bytes have to be padded. The
3025 code mapping symbol is pushed to an aligned address. */
3026
3027static void
3028insert_data_mapping_symbol (enum mstate state,
3029 valueT value, fragS *frag, offsetT bytes)
3030{
3031 /* If there was already a mapping symbol, remove it. */
3032 if (frag->tc_frag_data.last_map != NULL
3033 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3034 {
3035 symbolS *symp = frag->tc_frag_data.last_map;
3036
3037 if (value == 0)
3038 {
3039 know (frag->tc_frag_data.first_map == symp);
3040 frag->tc_frag_data.first_map = NULL;
3041 }
3042 frag->tc_frag_data.last_map = NULL;
3043 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 3044 }
cd000bff
DJ
3045
3046 make_mapping_symbol (MAP_DATA, value, frag);
3047 make_mapping_symbol (state, value + bytes, frag);
3048}
3049
3050static void mapping_state_2 (enum mstate state, int max_chars);
3051
3052/* Set the mapping state to STATE. Only call this when about to
3053 emit some STATE bytes to the file. */
3054
4e9aaefb 3055#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
3056void
3057mapping_state (enum mstate state)
3058{
940b5ce0
DJ
3059 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3060
cd000bff
DJ
3061 if (mapstate == state)
3062 /* The mapping symbol has already been emitted.
3063 There is nothing else to do. */
3064 return;
49c62a33
NC
3065
3066 if (state == MAP_ARM || state == MAP_THUMB)
3067 /* PR gas/12931
3068 All ARM instructions require 4-byte alignment.
3069 (Almost) all Thumb instructions require 2-byte alignment.
3070
3071 When emitting instructions into any section, mark the section
3072 appropriately.
3073
3074 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3075 but themselves require 2-byte alignment; this applies to some
33eaf5de 3076 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
3077 literal pool generation or an explicit .align >=2, both of
3078 which will cause the section to me marked with sufficient
3079 alignment. Thus, we don't handle those cases here. */
3080 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3081
3082 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 3083 /* This case will be evaluated later. */
cd000bff 3084 return;
cd000bff
DJ
3085
3086 mapping_state_2 (state, 0);
cd000bff
DJ
3087}
3088
3089/* Same as mapping_state, but MAX_CHARS bytes have already been
3090 allocated. Put the mapping symbol that far back. */
3091
3092static void
3093mapping_state_2 (enum mstate state, int max_chars)
3094{
940b5ce0
DJ
3095 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3096
3097 if (!SEG_NORMAL (now_seg))
3098 return;
3099
cd000bff
DJ
3100 if (mapstate == state)
3101 /* The mapping symbol has already been emitted.
3102 There is nothing else to do. */
3103 return;
3104
4e9aaefb
SA
3105 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3106 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3107 {
3108 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3109 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3110
3111 if (add_symbol)
3112 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3113 }
3114
cd000bff
DJ
3115 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3116 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3117}
4e9aaefb 3118#undef TRANSITION
c19d1205 3119#else
d3106081
NS
3120#define mapping_state(x) ((void)0)
3121#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3122#endif
3123
3124/* Find the real, Thumb encoded start of a Thumb function. */
3125
4343666d 3126#ifdef OBJ_COFF
c19d1205
ZW
3127static symbolS *
3128find_real_start (symbolS * symbolP)
3129{
3130 char * real_start;
3131 const char * name = S_GET_NAME (symbolP);
3132 symbolS * new_target;
3133
3134 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3135#define STUB_NAME ".real_start_of"
3136
3137 if (name == NULL)
3138 abort ();
3139
37f6032b
ZW
3140 /* The compiler may generate BL instructions to local labels because
3141 it needs to perform a branch to a far away location. These labels
3142 do not have a corresponding ".real_start_of" label. We check
3143 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3144 the ".real_start_of" convention for nonlocal branches. */
3145 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3146 return symbolP;
3147
e1fa0163 3148 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3149 new_target = symbol_find (real_start);
e1fa0163 3150 free (real_start);
c19d1205
ZW
3151
3152 if (new_target == NULL)
3153 {
bd3ba5d1 3154 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3155 new_target = symbolP;
3156 }
3157
c19d1205
ZW
3158 return new_target;
3159}
4343666d 3160#endif
c19d1205
ZW
3161
3162static void
3163opcode_select (int width)
3164{
3165 switch (width)
3166 {
3167 case 16:
3168 if (! thumb_mode)
3169 {
e74cfd16 3170 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3171 as_bad (_("selected processor does not support THUMB opcodes"));
3172
3173 thumb_mode = 1;
3174 /* No need to force the alignment, since we will have been
3175 coming from ARM mode, which is word-aligned. */
3176 record_alignment (now_seg, 1);
3177 }
c19d1205
ZW
3178 break;
3179
3180 case 32:
3181 if (thumb_mode)
3182 {
e74cfd16 3183 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3184 as_bad (_("selected processor does not support ARM opcodes"));
3185
3186 thumb_mode = 0;
3187
3188 if (!need_pass_2)
3189 frag_align (2, 0, 0);
3190
3191 record_alignment (now_seg, 1);
3192 }
c19d1205
ZW
3193 break;
3194
3195 default:
3196 as_bad (_("invalid instruction size selected (%d)"), width);
3197 }
3198}
3199
3200static void
3201s_arm (int ignore ATTRIBUTE_UNUSED)
3202{
3203 opcode_select (32);
3204 demand_empty_rest_of_line ();
3205}
3206
3207static void
3208s_thumb (int ignore ATTRIBUTE_UNUSED)
3209{
3210 opcode_select (16);
3211 demand_empty_rest_of_line ();
3212}
3213
3214static void
3215s_code (int unused ATTRIBUTE_UNUSED)
3216{
3217 int temp;
3218
3219 temp = get_absolute_expression ();
3220 switch (temp)
3221 {
3222 case 16:
3223 case 32:
3224 opcode_select (temp);
3225 break;
3226
3227 default:
3228 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3229 }
3230}
3231
3232static void
3233s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3234{
3235 /* If we are not already in thumb mode go into it, EVEN if
3236 the target processor does not support thumb instructions.
3237 This is used by gcc/config/arm/lib1funcs.asm for example
3238 to compile interworking support functions even if the
3239 target processor should not support interworking. */
3240 if (! thumb_mode)
3241 {
3242 thumb_mode = 2;
3243 record_alignment (now_seg, 1);
3244 }
3245
3246 demand_empty_rest_of_line ();
3247}
3248
3249static void
3250s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3251{
3252 s_thumb (0);
3253
3254 /* The following label is the name/address of the start of a Thumb function.
3255 We need to know this for the interworking support. */
3256 label_is_thumb_function_name = TRUE;
3257}
3258
3259/* Perform a .set directive, but also mark the alias as
3260 being a thumb function. */
3261
3262static void
3263s_thumb_set (int equiv)
3264{
3265 /* XXX the following is a duplicate of the code for s_set() in read.c
3266 We cannot just call that code as we need to get at the symbol that
3267 is created. */
3268 char * name;
3269 char delim;
3270 char * end_name;
3271 symbolS * symbolP;
3272
3273 /* Especial apologies for the random logic:
3274 This just grew, and could be parsed much more simply!
3275 Dean - in haste. */
d02603dc 3276 delim = get_symbol_name (& name);
c19d1205 3277 end_name = input_line_pointer;
d02603dc 3278 (void) restore_line_pointer (delim);
c19d1205
ZW
3279
3280 if (*input_line_pointer != ',')
3281 {
3282 *end_name = 0;
3283 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3284 *end_name = delim;
3285 ignore_rest_of_line ();
3286 return;
3287 }
3288
3289 input_line_pointer++;
3290 *end_name = 0;
3291
3292 if (name[0] == '.' && name[1] == '\0')
3293 {
3294 /* XXX - this should not happen to .thumb_set. */
3295 abort ();
3296 }
3297
3298 if ((symbolP = symbol_find (name)) == NULL
3299 && (symbolP = md_undefined_symbol (name)) == NULL)
3300 {
3301#ifndef NO_LISTING
3302 /* When doing symbol listings, play games with dummy fragments living
3303 outside the normal fragment chain to record the file and line info
c19d1205 3304 for this symbol. */
b99bd4ef
NC
3305 if (listing & LISTING_SYMBOLS)
3306 {
3307 extern struct list_info_struct * listing_tail;
21d799b5 3308 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3309
3310 memset (dummy_frag, 0, sizeof (fragS));
3311 dummy_frag->fr_type = rs_fill;
3312 dummy_frag->line = listing_tail;
e01e1cee 3313 symbolP = symbol_new (name, undefined_section, dummy_frag, 0);
b99bd4ef
NC
3314 dummy_frag->fr_symbol = symbolP;
3315 }
3316 else
3317#endif
e01e1cee 3318 symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0);
b99bd4ef
NC
3319
3320#ifdef OBJ_COFF
3321 /* "set" symbols are local unless otherwise specified. */
3322 SF_SET_LOCAL (symbolP);
3323#endif /* OBJ_COFF */
3324 } /* Make a new symbol. */
3325
3326 symbol_table_insert (symbolP);
3327
3328 * end_name = delim;
3329
3330 if (equiv
3331 && S_IS_DEFINED (symbolP)
3332 && S_GET_SEGMENT (symbolP) != reg_section)
3333 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3334
3335 pseudo_set (symbolP);
3336
3337 demand_empty_rest_of_line ();
3338
c19d1205 3339 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3340
3341 THUMB_SET_FUNC (symbolP, 1);
3342 ARM_SET_THUMB (symbolP, 1);
3343#if defined OBJ_ELF || defined OBJ_COFF
3344 ARM_SET_INTERWORK (symbolP, support_interwork);
3345#endif
3346}
3347
c19d1205 3348/* Directives: Mode selection. */
b99bd4ef 3349
c19d1205
ZW
3350/* .syntax [unified|divided] - choose the new unified syntax
3351 (same for Arm and Thumb encoding, modulo slight differences in what
3352 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3353static void
c19d1205 3354s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3355{
c19d1205
ZW
3356 char *name, delim;
3357
d02603dc 3358 delim = get_symbol_name (& name);
c19d1205
ZW
3359
3360 if (!strcasecmp (name, "unified"))
3361 unified_syntax = TRUE;
3362 else if (!strcasecmp (name, "divided"))
3363 unified_syntax = FALSE;
3364 else
3365 {
3366 as_bad (_("unrecognized syntax mode \"%s\""), name);
3367 return;
3368 }
d02603dc 3369 (void) restore_line_pointer (delim);
b99bd4ef
NC
3370 demand_empty_rest_of_line ();
3371}
3372
c19d1205
ZW
3373/* Directives: sectioning and alignment. */
3374
c19d1205
ZW
3375static void
3376s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3377{
c19d1205
ZW
3378 /* We don't support putting frags in the BSS segment, we fake it by
3379 marking in_bss, then looking at s_skip for clues. */
3380 subseg_set (bss_section, 0);
3381 demand_empty_rest_of_line ();
cd000bff
DJ
3382
3383#ifdef md_elf_section_change_hook
3384 md_elf_section_change_hook ();
3385#endif
c19d1205 3386}
b99bd4ef 3387
c19d1205
ZW
3388static void
3389s_even (int ignore ATTRIBUTE_UNUSED)
3390{
3391 /* Never make frag if expect extra pass. */
3392 if (!need_pass_2)
3393 frag_align (1, 0, 0);
b99bd4ef 3394
c19d1205 3395 record_alignment (now_seg, 1);
b99bd4ef 3396
c19d1205 3397 demand_empty_rest_of_line ();
b99bd4ef
NC
3398}
3399
2e6976a8
DG
3400/* Directives: CodeComposer Studio. */
3401
3402/* .ref (for CodeComposer Studio syntax only). */
3403static void
3404s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3405{
3406 if (codecomposer_syntax)
3407 ignore_rest_of_line ();
3408 else
3409 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3410}
3411
3412/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3413 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3414static void
3415asmfunc_debug (const char * name)
3416{
3417 static const char * last_name = NULL;
3418
3419 if (name != NULL)
3420 {
3421 gas_assert (last_name == NULL);
3422 last_name = name;
3423
3424 if (debug_type == DEBUG_STABS)
3425 stabs_generate_asm_func (name, name);
3426 }
3427 else
3428 {
3429 gas_assert (last_name != NULL);
3430
3431 if (debug_type == DEBUG_STABS)
3432 stabs_generate_asm_endfunc (last_name, last_name);
3433
3434 last_name = NULL;
3435 }
3436}
3437
3438static void
3439s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3440{
3441 if (codecomposer_syntax)
3442 {
3443 switch (asmfunc_state)
3444 {
3445 case OUTSIDE_ASMFUNC:
3446 asmfunc_state = WAITING_ASMFUNC_NAME;
3447 break;
3448
3449 case WAITING_ASMFUNC_NAME:
3450 as_bad (_(".asmfunc repeated."));
3451 break;
3452
3453 case WAITING_ENDASMFUNC:
3454 as_bad (_(".asmfunc without function."));
3455 break;
3456 }
3457 demand_empty_rest_of_line ();
3458 }
3459 else
3460 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3461}
3462
3463static void
3464s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3465{
3466 if (codecomposer_syntax)
3467 {
3468 switch (asmfunc_state)
3469 {
3470 case OUTSIDE_ASMFUNC:
3471 as_bad (_(".endasmfunc without a .asmfunc."));
3472 break;
3473
3474 case WAITING_ASMFUNC_NAME:
3475 as_bad (_(".endasmfunc without function."));
3476 break;
3477
3478 case WAITING_ENDASMFUNC:
3479 asmfunc_state = OUTSIDE_ASMFUNC;
3480 asmfunc_debug (NULL);
3481 break;
3482 }
3483 demand_empty_rest_of_line ();
3484 }
3485 else
3486 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3487}
3488
3489static void
3490s_ccs_def (int name)
3491{
3492 if (codecomposer_syntax)
3493 s_globl (name);
3494 else
3495 as_bad (_(".def pseudo-op only available with -mccs flag."));
3496}
3497
c19d1205 3498/* Directives: Literal pools. */
a737bd4d 3499
c19d1205
ZW
3500static literal_pool *
3501find_literal_pool (void)
a737bd4d 3502{
c19d1205 3503 literal_pool * pool;
a737bd4d 3504
c19d1205 3505 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3506 {
c19d1205
ZW
3507 if (pool->section == now_seg
3508 && pool->sub_section == now_subseg)
3509 break;
a737bd4d
NC
3510 }
3511
c19d1205 3512 return pool;
a737bd4d
NC
3513}
3514
c19d1205
ZW
3515static literal_pool *
3516find_or_make_literal_pool (void)
a737bd4d 3517{
c19d1205
ZW
3518 /* Next literal pool ID number. */
3519 static unsigned int latest_pool_num = 1;
3520 literal_pool * pool;
a737bd4d 3521
c19d1205 3522 pool = find_literal_pool ();
a737bd4d 3523
c19d1205 3524 if (pool == NULL)
a737bd4d 3525 {
c19d1205 3526 /* Create a new pool. */
325801bd 3527 pool = XNEW (literal_pool);
c19d1205
ZW
3528 if (! pool)
3529 return NULL;
a737bd4d 3530
c19d1205
ZW
3531 pool->next_free_entry = 0;
3532 pool->section = now_seg;
3533 pool->sub_section = now_subseg;
3534 pool->next = list_of_pools;
3535 pool->symbol = NULL;
8335d6aa 3536 pool->alignment = 2;
c19d1205
ZW
3537
3538 /* Add it to the list. */
3539 list_of_pools = pool;
a737bd4d 3540 }
a737bd4d 3541
c19d1205
ZW
3542 /* New pools, and emptied pools, will have a NULL symbol. */
3543 if (pool->symbol == NULL)
a737bd4d 3544 {
c19d1205 3545 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
e01e1cee 3546 &zero_address_frag, 0);
c19d1205 3547 pool->id = latest_pool_num ++;
a737bd4d
NC
3548 }
3549
c19d1205
ZW
3550 /* Done. */
3551 return pool;
a737bd4d
NC
3552}
3553
c19d1205 3554/* Add the literal in the global 'inst'
5f4273c7 3555 structure to the relevant literal pool. */
b99bd4ef
NC
3556
3557static int
8335d6aa 3558add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3559{
8335d6aa
JW
3560#define PADDING_SLOT 0x1
3561#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3562 literal_pool * pool;
8335d6aa
JW
3563 unsigned int entry, pool_size = 0;
3564 bfd_boolean padding_slot_p = FALSE;
e56c722b 3565 unsigned imm1 = 0;
8335d6aa
JW
3566 unsigned imm2 = 0;
3567
3568 if (nbytes == 8)
3569 {
3570 imm1 = inst.operands[1].imm;
3571 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3572 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3573 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3574 if (target_big_endian)
3575 {
3576 imm1 = imm2;
3577 imm2 = inst.operands[1].imm;
3578 }
3579 }
b99bd4ef 3580
c19d1205
ZW
3581 pool = find_or_make_literal_pool ();
3582
3583 /* Check if this literal value is already in the pool. */
3584 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3585 {
8335d6aa
JW
3586 if (nbytes == 4)
3587 {
e2b0ab59
AV
3588 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3589 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3590 && (pool->literals[entry].X_add_number
e2b0ab59 3591 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3592 && (pool->literals[entry].X_md == nbytes)
3593 && (pool->literals[entry].X_unsigned
e2b0ab59 3594 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3595 break;
3596
e2b0ab59
AV
3597 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3598 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3599 && (pool->literals[entry].X_add_number
e2b0ab59 3600 == inst.relocs[0].exp.X_add_number)
8335d6aa 3601 && (pool->literals[entry].X_add_symbol
e2b0ab59 3602 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3603 && (pool->literals[entry].X_op_symbol
e2b0ab59 3604 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3605 && (pool->literals[entry].X_md == nbytes))
3606 break;
3607 }
3608 else if ((nbytes == 8)
3609 && !(pool_size & 0x7)
3610 && ((entry + 1) != pool->next_free_entry)
3611 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3612 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3613 && (pool->literals[entry].X_unsigned
e2b0ab59 3614 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3615 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3616 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3617 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3618 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3619 break;
3620
8335d6aa
JW
3621 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3622 if (padding_slot_p && (nbytes == 4))
c19d1205 3623 break;
8335d6aa
JW
3624
3625 pool_size += 4;
b99bd4ef
NC
3626 }
3627
c19d1205
ZW
3628 /* Do we need to create a new entry? */
3629 if (entry == pool->next_free_entry)
3630 {
3631 if (entry >= MAX_LITERAL_POOL_SIZE)
3632 {
3633 inst.error = _("literal pool overflow");
3634 return FAIL;
3635 }
3636
8335d6aa
JW
3637 if (nbytes == 8)
3638 {
3639 /* For 8-byte entries, we align to an 8-byte boundary,
3640 and split it into two 4-byte entries, because on 32-bit
3641 host, 8-byte constants are treated as big num, thus
3642 saved in "generic_bignum" which will be overwritten
3643 by later assignments.
3644
3645 We also need to make sure there is enough space for
3646 the split.
3647
3648 We also check to make sure the literal operand is a
3649 constant number. */
e2b0ab59
AV
3650 if (!(inst.relocs[0].exp.X_op == O_constant
3651 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3652 {
3653 inst.error = _("invalid type for literal pool");
3654 return FAIL;
3655 }
3656 else if (pool_size & 0x7)
3657 {
3658 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3659 {
3660 inst.error = _("literal pool overflow");
3661 return FAIL;
3662 }
3663
e2b0ab59 3664 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3665 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3666 pool->literals[entry].X_add_number = 0;
3667 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3668 pool->next_free_entry += 1;
3669 pool_size += 4;
3670 }
3671 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3672 {
3673 inst.error = _("literal pool overflow");
3674 return FAIL;
3675 }
3676
e2b0ab59 3677 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3678 pool->literals[entry].X_op = O_constant;
3679 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3680 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3681 pool->literals[entry++].X_md = 4;
e2b0ab59 3682 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3683 pool->literals[entry].X_op = O_constant;
3684 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3685 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3686 pool->literals[entry].X_md = 4;
3687 pool->alignment = 3;
3688 pool->next_free_entry += 1;
3689 }
3690 else
3691 {
e2b0ab59 3692 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3693 pool->literals[entry].X_md = 4;
3694 }
3695
a8040cf2
NC
3696#ifdef OBJ_ELF
3697 /* PR ld/12974: Record the location of the first source line to reference
3698 this entry in the literal pool. If it turns out during linking that the
3699 symbol does not exist we will be able to give an accurate line number for
3700 the (first use of the) missing reference. */
3701 if (debug_type == DEBUG_DWARF2)
3702 dwarf2_where (pool->locs + entry);
3703#endif
c19d1205
ZW
3704 pool->next_free_entry += 1;
3705 }
8335d6aa
JW
3706 else if (padding_slot_p)
3707 {
e2b0ab59 3708 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3709 pool->literals[entry].X_md = nbytes;
3710 }
b99bd4ef 3711
e2b0ab59
AV
3712 inst.relocs[0].exp.X_op = O_symbol;
3713 inst.relocs[0].exp.X_add_number = pool_size;
3714 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3715
c19d1205 3716 return SUCCESS;
b99bd4ef
NC
3717}
3718
2e6976a8 3719bfd_boolean
2e57ce7b 3720tc_start_label_without_colon (void)
2e6976a8
DG
3721{
3722 bfd_boolean ret = TRUE;
3723
3724 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3725 {
2e57ce7b 3726 const char *label = input_line_pointer;
2e6976a8
DG
3727
3728 while (!is_end_of_line[(int) label[-1]])
3729 --label;
3730
3731 if (*label == '.')
3732 {
3733 as_bad (_("Invalid label '%s'"), label);
3734 ret = FALSE;
3735 }
3736
3737 asmfunc_debug (label);
3738
3739 asmfunc_state = WAITING_ENDASMFUNC;
3740 }
3741
3742 return ret;
3743}
3744
c19d1205 3745/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3746 a later date assign it a value. That's what these functions do. */
e16bb312 3747
c19d1205
ZW
3748static void
3749symbol_locate (symbolS * symbolP,
3750 const char * name, /* It is copied, the caller can modify. */
3751 segT segment, /* Segment identifier (SEG_<something>). */
3752 valueT valu, /* Symbol value. */
3753 fragS * frag) /* Associated fragment. */
3754{
e57e6ddc 3755 size_t name_length;
c19d1205 3756 char * preserved_copy_of_name;
e16bb312 3757
c19d1205
ZW
3758 name_length = strlen (name) + 1; /* +1 for \0. */
3759 obstack_grow (&notes, name, name_length);
21d799b5 3760 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3761
c19d1205
ZW
3762#ifdef tc_canonicalize_symbol_name
3763 preserved_copy_of_name =
3764 tc_canonicalize_symbol_name (preserved_copy_of_name);
3765#endif
b99bd4ef 3766
c19d1205 3767 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3768
c19d1205
ZW
3769 S_SET_SEGMENT (symbolP, segment);
3770 S_SET_VALUE (symbolP, valu);
3771 symbol_clear_list_pointers (symbolP);
b99bd4ef 3772
c19d1205 3773 symbol_set_frag (symbolP, frag);
b99bd4ef 3774
c19d1205
ZW
3775 /* Link to end of symbol chain. */
3776 {
3777 extern int symbol_table_frozen;
b99bd4ef 3778
c19d1205
ZW
3779 if (symbol_table_frozen)
3780 abort ();
3781 }
b99bd4ef 3782
c19d1205 3783 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3784
c19d1205 3785 obj_symbol_new_hook (symbolP);
b99bd4ef 3786
c19d1205
ZW
3787#ifdef tc_symbol_new_hook
3788 tc_symbol_new_hook (symbolP);
3789#endif
3790
3791#ifdef DEBUG_SYMS
3792 verify_symbol_chain (symbol_rootP, symbol_lastP);
3793#endif /* DEBUG_SYMS */
b99bd4ef
NC
3794}
3795
c19d1205
ZW
3796static void
3797s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3798{
c19d1205
ZW
3799 unsigned int entry;
3800 literal_pool * pool;
3801 char sym_name[20];
b99bd4ef 3802
c19d1205
ZW
3803 pool = find_literal_pool ();
3804 if (pool == NULL
3805 || pool->symbol == NULL
3806 || pool->next_free_entry == 0)
3807 return;
b99bd4ef 3808
c19d1205
ZW
3809 /* Align pool as you have word accesses.
3810 Only make a frag if we have to. */
3811 if (!need_pass_2)
8335d6aa 3812 frag_align (pool->alignment, 0, 0);
b99bd4ef 3813
c19d1205 3814 record_alignment (now_seg, 2);
b99bd4ef 3815
aaca88ef 3816#ifdef OBJ_ELF
47fc6e36
WN
3817 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3818 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3819#endif
c19d1205 3820 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3821
c19d1205
ZW
3822 symbol_locate (pool->symbol, sym_name, now_seg,
3823 (valueT) frag_now_fix (), frag_now);
3824 symbol_table_insert (pool->symbol);
b99bd4ef 3825
c19d1205 3826 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3827
c19d1205
ZW
3828#if defined OBJ_COFF || defined OBJ_ELF
3829 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3830#endif
6c43fab6 3831
c19d1205 3832 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3833 {
3834#ifdef OBJ_ELF
3835 if (debug_type == DEBUG_DWARF2)
3836 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3837#endif
3838 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3839 emit_expr (&(pool->literals[entry]),
3840 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3841 }
b99bd4ef 3842
c19d1205
ZW
3843 /* Mark the pool as empty. */
3844 pool->next_free_entry = 0;
3845 pool->symbol = NULL;
b99bd4ef
NC
3846}
3847
c19d1205
ZW
3848#ifdef OBJ_ELF
3849/* Forward declarations for functions below, in the MD interface
3850 section. */
3851static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3852static valueT create_unwind_entry (int);
3853static void start_unwind_section (const segT, int);
3854static void add_unwind_opcode (valueT, int);
3855static void flush_pending_unwind (void);
b99bd4ef 3856
c19d1205 3857/* Directives: Data. */
b99bd4ef 3858
c19d1205
ZW
3859static void
3860s_arm_elf_cons (int nbytes)
3861{
3862 expressionS exp;
b99bd4ef 3863
c19d1205
ZW
3864#ifdef md_flush_pending_output
3865 md_flush_pending_output ();
3866#endif
b99bd4ef 3867
c19d1205 3868 if (is_it_end_of_statement ())
b99bd4ef 3869 {
c19d1205
ZW
3870 demand_empty_rest_of_line ();
3871 return;
b99bd4ef
NC
3872 }
3873
c19d1205
ZW
3874#ifdef md_cons_align
3875 md_cons_align (nbytes);
3876#endif
b99bd4ef 3877
c19d1205
ZW
3878 mapping_state (MAP_DATA);
3879 do
b99bd4ef 3880 {
c19d1205
ZW
3881 int reloc;
3882 char *base = input_line_pointer;
b99bd4ef 3883
c19d1205 3884 expression (& exp);
b99bd4ef 3885
c19d1205
ZW
3886 if (exp.X_op != O_symbol)
3887 emit_expr (&exp, (unsigned int) nbytes);
3888 else
3889 {
3890 char *before_reloc = input_line_pointer;
3891 reloc = parse_reloc (&input_line_pointer);
3892 if (reloc == -1)
3893 {
3894 as_bad (_("unrecognized relocation suffix"));
3895 ignore_rest_of_line ();
3896 return;
3897 }
3898 else if (reloc == BFD_RELOC_UNUSED)
3899 emit_expr (&exp, (unsigned int) nbytes);
3900 else
3901 {
21d799b5 3902 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3903 bfd_reloc_type_lookup (stdoutput,
3904 (bfd_reloc_code_real_type) reloc);
c19d1205 3905 int size = bfd_get_reloc_size (howto);
b99bd4ef 3906
2fc8bdac
ZW
3907 if (reloc == BFD_RELOC_ARM_PLT32)
3908 {
3909 as_bad (_("(plt) is only valid on branch targets"));
3910 reloc = BFD_RELOC_UNUSED;
3911 size = 0;
3912 }
3913
c19d1205 3914 if (size > nbytes)
992a06ee
AM
3915 as_bad (ngettext ("%s relocations do not fit in %d byte",
3916 "%s relocations do not fit in %d bytes",
3917 nbytes),
c19d1205
ZW
3918 howto->name, nbytes);
3919 else
3920 {
3921 /* We've parsed an expression stopping at O_symbol.
3922 But there may be more expression left now that we
3923 have parsed the relocation marker. Parse it again.
3924 XXX Surely there is a cleaner way to do this. */
3925 char *p = input_line_pointer;
3926 int offset;
325801bd 3927 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3928
c19d1205
ZW
3929 memcpy (save_buf, base, input_line_pointer - base);
3930 memmove (base + (input_line_pointer - before_reloc),
3931 base, before_reloc - base);
3932
3933 input_line_pointer = base + (input_line_pointer-before_reloc);
3934 expression (&exp);
3935 memcpy (base, save_buf, p - base);
3936
3937 offset = nbytes - size;
4b1a927e
AM
3938 p = frag_more (nbytes);
3939 memset (p, 0, nbytes);
c19d1205 3940 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3941 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3942 free (save_buf);
c19d1205
ZW
3943 }
3944 }
3945 }
b99bd4ef 3946 }
c19d1205 3947 while (*input_line_pointer++ == ',');
b99bd4ef 3948
c19d1205
ZW
3949 /* Put terminator back into stream. */
3950 input_line_pointer --;
3951 demand_empty_rest_of_line ();
b99bd4ef
NC
3952}
3953
c921be7d
NC
3954/* Emit an expression containing a 32-bit thumb instruction.
3955 Implementation based on put_thumb32_insn. */
3956
3957static void
3958emit_thumb32_expr (expressionS * exp)
3959{
3960 expressionS exp_high = *exp;
3961
3962 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3963 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3964 exp->X_add_number &= 0xffff;
3965 emit_expr (exp, (unsigned int) THUMB_SIZE);
3966}
3967
3968/* Guess the instruction size based on the opcode. */
3969
3970static int
3971thumb_insn_size (int opcode)
3972{
3973 if ((unsigned int) opcode < 0xe800u)
3974 return 2;
3975 else if ((unsigned int) opcode >= 0xe8000000u)
3976 return 4;
3977 else
3978 return 0;
3979}
3980
3981static bfd_boolean
3982emit_insn (expressionS *exp, int nbytes)
3983{
3984 int size = 0;
3985
3986 if (exp->X_op == O_constant)
3987 {
3988 size = nbytes;
3989
3990 if (size == 0)
3991 size = thumb_insn_size (exp->X_add_number);
3992
3993 if (size != 0)
3994 {
3995 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3996 {
3997 as_bad (_(".inst.n operand too big. "\
3998 "Use .inst.w instead"));
3999 size = 0;
4000 }
4001 else
4002 {
5ee91343
AV
4003 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4004 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 4005 else
5ee91343 4006 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
4007
4008 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4009 emit_thumb32_expr (exp);
4010 else
4011 emit_expr (exp, (unsigned int) size);
4012
4013 it_fsm_post_encode ();
4014 }
4015 }
4016 else
4017 as_bad (_("cannot determine Thumb instruction size. " \
4018 "Use .inst.n/.inst.w instead"));
4019 }
4020 else
4021 as_bad (_("constant expression required"));
4022
4023 return (size != 0);
4024}
4025
4026/* Like s_arm_elf_cons but do not use md_cons_align and
4027 set the mapping state to MAP_ARM/MAP_THUMB. */
4028
4029static void
4030s_arm_elf_inst (int nbytes)
4031{
4032 if (is_it_end_of_statement ())
4033 {
4034 demand_empty_rest_of_line ();
4035 return;
4036 }
4037
4038 /* Calling mapping_state () here will not change ARM/THUMB,
4039 but will ensure not to be in DATA state. */
4040
4041 if (thumb_mode)
4042 mapping_state (MAP_THUMB);
4043 else
4044 {
4045 if (nbytes != 0)
4046 {
4047 as_bad (_("width suffixes are invalid in ARM mode"));
4048 ignore_rest_of_line ();
4049 return;
4050 }
4051
4052 nbytes = 4;
4053
4054 mapping_state (MAP_ARM);
4055 }
4056
4057 do
4058 {
4059 expressionS exp;
4060
4061 expression (& exp);
4062
4063 if (! emit_insn (& exp, nbytes))
4064 {
4065 ignore_rest_of_line ();
4066 return;
4067 }
4068 }
4069 while (*input_line_pointer++ == ',');
4070
4071 /* Put terminator back into stream. */
4072 input_line_pointer --;
4073 demand_empty_rest_of_line ();
4074}
b99bd4ef 4075
c19d1205 4076/* Parse a .rel31 directive. */
b99bd4ef 4077
c19d1205
ZW
4078static void
4079s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4080{
4081 expressionS exp;
4082 char *p;
4083 valueT highbit;
b99bd4ef 4084
c19d1205
ZW
4085 highbit = 0;
4086 if (*input_line_pointer == '1')
4087 highbit = 0x80000000;
4088 else if (*input_line_pointer != '0')
4089 as_bad (_("expected 0 or 1"));
b99bd4ef 4090
c19d1205
ZW
4091 input_line_pointer++;
4092 if (*input_line_pointer != ',')
4093 as_bad (_("missing comma"));
4094 input_line_pointer++;
b99bd4ef 4095
c19d1205
ZW
4096#ifdef md_flush_pending_output
4097 md_flush_pending_output ();
4098#endif
b99bd4ef 4099
c19d1205
ZW
4100#ifdef md_cons_align
4101 md_cons_align (4);
4102#endif
b99bd4ef 4103
c19d1205 4104 mapping_state (MAP_DATA);
b99bd4ef 4105
c19d1205 4106 expression (&exp);
b99bd4ef 4107
c19d1205
ZW
4108 p = frag_more (4);
4109 md_number_to_chars (p, highbit, 4);
4110 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4111 BFD_RELOC_ARM_PREL31);
b99bd4ef 4112
c19d1205 4113 demand_empty_rest_of_line ();
b99bd4ef
NC
4114}
4115
c19d1205 4116/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4117
c19d1205 4118/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4119
c19d1205
ZW
4120static void
4121s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4122{
4123 demand_empty_rest_of_line ();
921e5f0a
PB
4124 if (unwind.proc_start)
4125 {
c921be7d 4126 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4127 return;
4128 }
4129
c19d1205
ZW
4130 /* Mark the start of the function. */
4131 unwind.proc_start = expr_build_dot ();
b99bd4ef 4132
c19d1205
ZW
4133 /* Reset the rest of the unwind info. */
4134 unwind.opcode_count = 0;
4135 unwind.table_entry = NULL;
4136 unwind.personality_routine = NULL;
4137 unwind.personality_index = -1;
4138 unwind.frame_size = 0;
4139 unwind.fp_offset = 0;
fdfde340 4140 unwind.fp_reg = REG_SP;
c19d1205
ZW
4141 unwind.fp_used = 0;
4142 unwind.sp_restored = 0;
4143}
b99bd4ef 4144
b99bd4ef 4145
c19d1205
ZW
4146/* Parse a handlerdata directive. Creates the exception handling table entry
4147 for the function. */
b99bd4ef 4148
c19d1205
ZW
4149static void
4150s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4151{
4152 demand_empty_rest_of_line ();
921e5f0a 4153 if (!unwind.proc_start)
c921be7d 4154 as_bad (MISSING_FNSTART);
921e5f0a 4155
c19d1205 4156 if (unwind.table_entry)
6decc662 4157 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4158
c19d1205
ZW
4159 create_unwind_entry (1);
4160}
a737bd4d 4161
c19d1205 4162/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4163
c19d1205
ZW
4164static void
4165s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4166{
4167 long where;
4168 char *ptr;
4169 valueT val;
940b5ce0 4170 unsigned int marked_pr_dependency;
f02232aa 4171
c19d1205 4172 demand_empty_rest_of_line ();
f02232aa 4173
921e5f0a
PB
4174 if (!unwind.proc_start)
4175 {
c921be7d 4176 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4177 return;
4178 }
4179
c19d1205
ZW
4180 /* Add eh table entry. */
4181 if (unwind.table_entry == NULL)
4182 val = create_unwind_entry (0);
4183 else
4184 val = 0;
f02232aa 4185
c19d1205
ZW
4186 /* Add index table entry. This is two words. */
4187 start_unwind_section (unwind.saved_seg, 1);
4188 frag_align (2, 0, 0);
4189 record_alignment (now_seg, 2);
b99bd4ef 4190
c19d1205 4191 ptr = frag_more (8);
5011093d 4192 memset (ptr, 0, 8);
c19d1205 4193 where = frag_now_fix () - 8;
f02232aa 4194
c19d1205
ZW
4195 /* Self relative offset of the function start. */
4196 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4197 BFD_RELOC_ARM_PREL31);
f02232aa 4198
c19d1205
ZW
4199 /* Indicate dependency on EHABI-defined personality routines to the
4200 linker, if it hasn't been done already. */
940b5ce0
DJ
4201 marked_pr_dependency
4202 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4203 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4204 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4205 {
5f4273c7
NC
4206 static const char *const name[] =
4207 {
4208 "__aeabi_unwind_cpp_pr0",
4209 "__aeabi_unwind_cpp_pr1",
4210 "__aeabi_unwind_cpp_pr2"
4211 };
c19d1205
ZW
4212 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4213 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4214 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4215 |= 1 << unwind.personality_index;
c19d1205 4216 }
f02232aa 4217
c19d1205
ZW
4218 if (val)
4219 /* Inline exception table entry. */
4220 md_number_to_chars (ptr + 4, val, 4);
4221 else
4222 /* Self relative offset of the table entry. */
4223 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4224 BFD_RELOC_ARM_PREL31);
f02232aa 4225
c19d1205
ZW
4226 /* Restore the original section. */
4227 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4228
4229 unwind.proc_start = NULL;
c19d1205 4230}
f02232aa 4231
f02232aa 4232
c19d1205 4233/* Parse an unwind_cantunwind directive. */
b99bd4ef 4234
c19d1205
ZW
4235static void
4236s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4237{
4238 demand_empty_rest_of_line ();
921e5f0a 4239 if (!unwind.proc_start)
c921be7d 4240 as_bad (MISSING_FNSTART);
921e5f0a 4241
c19d1205
ZW
4242 if (unwind.personality_routine || unwind.personality_index != -1)
4243 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4244
c19d1205
ZW
4245 unwind.personality_index = -2;
4246}
b99bd4ef 4247
b99bd4ef 4248
c19d1205 4249/* Parse a personalityindex directive. */
b99bd4ef 4250
c19d1205
ZW
4251static void
4252s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4253{
4254 expressionS exp;
b99bd4ef 4255
921e5f0a 4256 if (!unwind.proc_start)
c921be7d 4257 as_bad (MISSING_FNSTART);
921e5f0a 4258
c19d1205
ZW
4259 if (unwind.personality_routine || unwind.personality_index != -1)
4260 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4261
c19d1205 4262 expression (&exp);
b99bd4ef 4263
c19d1205
ZW
4264 if (exp.X_op != O_constant
4265 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4266 {
c19d1205
ZW
4267 as_bad (_("bad personality routine number"));
4268 ignore_rest_of_line ();
4269 return;
b99bd4ef
NC
4270 }
4271
c19d1205 4272 unwind.personality_index = exp.X_add_number;
b99bd4ef 4273
c19d1205
ZW
4274 demand_empty_rest_of_line ();
4275}
e16bb312 4276
e16bb312 4277
c19d1205 4278/* Parse a personality directive. */
e16bb312 4279
c19d1205
ZW
4280static void
4281s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4282{
4283 char *name, *p, c;
a737bd4d 4284
921e5f0a 4285 if (!unwind.proc_start)
c921be7d 4286 as_bad (MISSING_FNSTART);
921e5f0a 4287
c19d1205
ZW
4288 if (unwind.personality_routine || unwind.personality_index != -1)
4289 as_bad (_("duplicate .personality directive"));
a737bd4d 4290
d02603dc 4291 c = get_symbol_name (& name);
c19d1205 4292 p = input_line_pointer;
d02603dc
NC
4293 if (c == '"')
4294 ++ input_line_pointer;
c19d1205
ZW
4295 unwind.personality_routine = symbol_find_or_make (name);
4296 *p = c;
4297 demand_empty_rest_of_line ();
4298}
e16bb312 4299
e16bb312 4300
c19d1205 4301/* Parse a directive saving core registers. */
e16bb312 4302
c19d1205
ZW
4303static void
4304s_arm_unwind_save_core (void)
e16bb312 4305{
c19d1205
ZW
4306 valueT op;
4307 long range;
4308 int n;
e16bb312 4309
4b5a202f 4310 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4311 if (range == FAIL)
e16bb312 4312 {
c19d1205
ZW
4313 as_bad (_("expected register list"));
4314 ignore_rest_of_line ();
4315 return;
4316 }
e16bb312 4317
c19d1205 4318 demand_empty_rest_of_line ();
e16bb312 4319
c19d1205
ZW
4320 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4321 into .unwind_save {..., sp...}. We aren't bothered about the value of
4322 ip because it is clobbered by calls. */
4323 if (unwind.sp_restored && unwind.fp_reg == 12
4324 && (range & 0x3000) == 0x1000)
4325 {
4326 unwind.opcode_count--;
4327 unwind.sp_restored = 0;
4328 range = (range | 0x2000) & ~0x1000;
4329 unwind.pending_offset = 0;
4330 }
e16bb312 4331
01ae4198
DJ
4332 /* Pop r4-r15. */
4333 if (range & 0xfff0)
c19d1205 4334 {
01ae4198
DJ
4335 /* See if we can use the short opcodes. These pop a block of up to 8
4336 registers starting with r4, plus maybe r14. */
4337 for (n = 0; n < 8; n++)
4338 {
4339 /* Break at the first non-saved register. */
4340 if ((range & (1 << (n + 4))) == 0)
4341 break;
4342 }
4343 /* See if there are any other bits set. */
4344 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4345 {
4346 /* Use the long form. */
4347 op = 0x8000 | ((range >> 4) & 0xfff);
4348 add_unwind_opcode (op, 2);
4349 }
0dd132b6 4350 else
01ae4198
DJ
4351 {
4352 /* Use the short form. */
4353 if (range & 0x4000)
4354 op = 0xa8; /* Pop r14. */
4355 else
4356 op = 0xa0; /* Do not pop r14. */
4357 op |= (n - 1);
4358 add_unwind_opcode (op, 1);
4359 }
c19d1205 4360 }
0dd132b6 4361
c19d1205
ZW
4362 /* Pop r0-r3. */
4363 if (range & 0xf)
4364 {
4365 op = 0xb100 | (range & 0xf);
4366 add_unwind_opcode (op, 2);
0dd132b6
NC
4367 }
4368
c19d1205
ZW
4369 /* Record the number of bytes pushed. */
4370 for (n = 0; n < 16; n++)
4371 {
4372 if (range & (1 << n))
4373 unwind.frame_size += 4;
4374 }
0dd132b6
NC
4375}
4376
c19d1205
ZW
4377
4378/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4379
4380static void
c19d1205 4381s_arm_unwind_save_fpa (int reg)
b99bd4ef 4382{
c19d1205
ZW
4383 expressionS exp;
4384 int num_regs;
4385 valueT op;
b99bd4ef 4386
c19d1205
ZW
4387 /* Get Number of registers to transfer. */
4388 if (skip_past_comma (&input_line_pointer) != FAIL)
4389 expression (&exp);
4390 else
4391 exp.X_op = O_illegal;
b99bd4ef 4392
c19d1205 4393 if (exp.X_op != O_constant)
b99bd4ef 4394 {
c19d1205
ZW
4395 as_bad (_("expected , <constant>"));
4396 ignore_rest_of_line ();
b99bd4ef
NC
4397 return;
4398 }
4399
c19d1205
ZW
4400 num_regs = exp.X_add_number;
4401
4402 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4403 {
c19d1205
ZW
4404 as_bad (_("number of registers must be in the range [1:4]"));
4405 ignore_rest_of_line ();
b99bd4ef
NC
4406 return;
4407 }
4408
c19d1205 4409 demand_empty_rest_of_line ();
b99bd4ef 4410
c19d1205
ZW
4411 if (reg == 4)
4412 {
4413 /* Short form. */
4414 op = 0xb4 | (num_regs - 1);
4415 add_unwind_opcode (op, 1);
4416 }
b99bd4ef
NC
4417 else
4418 {
c19d1205
ZW
4419 /* Long form. */
4420 op = 0xc800 | (reg << 4) | (num_regs - 1);
4421 add_unwind_opcode (op, 2);
b99bd4ef 4422 }
c19d1205 4423 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4424}
4425
c19d1205 4426
fa073d69
MS
4427/* Parse a directive saving VFP registers for ARMv6 and above. */
4428
4429static void
4430s_arm_unwind_save_vfp_armv6 (void)
4431{
4432 int count;
4433 unsigned int start;
4434 valueT op;
4435 int num_vfpv3_regs = 0;
4436 int num_regs_below_16;
efd6b359 4437 bfd_boolean partial_match;
fa073d69 4438
efd6b359
AV
4439 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4440 &partial_match);
fa073d69
MS
4441 if (count == FAIL)
4442 {
4443 as_bad (_("expected register list"));
4444 ignore_rest_of_line ();
4445 return;
4446 }
4447
4448 demand_empty_rest_of_line ();
4449
4450 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4451 than FSTMX/FLDMX-style ones). */
4452
4453 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4454 if (start >= 16)
4455 num_vfpv3_regs = count;
4456 else if (start + count > 16)
4457 num_vfpv3_regs = start + count - 16;
4458
4459 if (num_vfpv3_regs > 0)
4460 {
4461 int start_offset = start > 16 ? start - 16 : 0;
4462 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4463 add_unwind_opcode (op, 2);
4464 }
4465
4466 /* Generate opcode for registers numbered in the range 0 .. 15. */
4467 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4468 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4469 if (num_regs_below_16 > 0)
4470 {
4471 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4472 add_unwind_opcode (op, 2);
4473 }
4474
4475 unwind.frame_size += count * 8;
4476}
4477
4478
4479/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4480
4481static void
c19d1205 4482s_arm_unwind_save_vfp (void)
b99bd4ef 4483{
c19d1205 4484 int count;
ca3f61f7 4485 unsigned int reg;
c19d1205 4486 valueT op;
efd6b359 4487 bfd_boolean partial_match;
b99bd4ef 4488
efd6b359
AV
4489 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4490 &partial_match);
c19d1205 4491 if (count == FAIL)
b99bd4ef 4492 {
c19d1205
ZW
4493 as_bad (_("expected register list"));
4494 ignore_rest_of_line ();
b99bd4ef
NC
4495 return;
4496 }
4497
c19d1205 4498 demand_empty_rest_of_line ();
b99bd4ef 4499
c19d1205 4500 if (reg == 8)
b99bd4ef 4501 {
c19d1205
ZW
4502 /* Short form. */
4503 op = 0xb8 | (count - 1);
4504 add_unwind_opcode (op, 1);
b99bd4ef 4505 }
c19d1205 4506 else
b99bd4ef 4507 {
c19d1205
ZW
4508 /* Long form. */
4509 op = 0xb300 | (reg << 4) | (count - 1);
4510 add_unwind_opcode (op, 2);
b99bd4ef 4511 }
c19d1205
ZW
4512 unwind.frame_size += count * 8 + 4;
4513}
b99bd4ef 4514
b99bd4ef 4515
c19d1205
ZW
4516/* Parse a directive saving iWMMXt data registers. */
4517
4518static void
4519s_arm_unwind_save_mmxwr (void)
4520{
4521 int reg;
4522 int hi_reg;
4523 int i;
4524 unsigned mask = 0;
4525 valueT op;
b99bd4ef 4526
c19d1205
ZW
4527 if (*input_line_pointer == '{')
4528 input_line_pointer++;
b99bd4ef 4529
c19d1205 4530 do
b99bd4ef 4531 {
dcbf9037 4532 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4533
c19d1205 4534 if (reg == FAIL)
b99bd4ef 4535 {
9b7132d3 4536 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4537 goto error;
b99bd4ef
NC
4538 }
4539
c19d1205
ZW
4540 if (mask >> reg)
4541 as_tsktsk (_("register list not in ascending order"));
4542 mask |= 1 << reg;
b99bd4ef 4543
c19d1205
ZW
4544 if (*input_line_pointer == '-')
4545 {
4546 input_line_pointer++;
dcbf9037 4547 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4548 if (hi_reg == FAIL)
4549 {
9b7132d3 4550 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4551 goto error;
4552 }
4553 else if (reg >= hi_reg)
4554 {
4555 as_bad (_("bad register range"));
4556 goto error;
4557 }
4558 for (; reg < hi_reg; reg++)
4559 mask |= 1 << reg;
4560 }
4561 }
4562 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4563
d996d970 4564 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4565
c19d1205 4566 demand_empty_rest_of_line ();
b99bd4ef 4567
708587a4 4568 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4569 the list. */
4570 flush_pending_unwind ();
b99bd4ef 4571
c19d1205 4572 for (i = 0; i < 16; i++)
b99bd4ef 4573 {
c19d1205
ZW
4574 if (mask & (1 << i))
4575 unwind.frame_size += 8;
b99bd4ef
NC
4576 }
4577
c19d1205
ZW
4578 /* Attempt to combine with a previous opcode. We do this because gcc
4579 likes to output separate unwind directives for a single block of
4580 registers. */
4581 if (unwind.opcode_count > 0)
b99bd4ef 4582 {
c19d1205
ZW
4583 i = unwind.opcodes[unwind.opcode_count - 1];
4584 if ((i & 0xf8) == 0xc0)
4585 {
4586 i &= 7;
4587 /* Only merge if the blocks are contiguous. */
4588 if (i < 6)
4589 {
4590 if ((mask & 0xfe00) == (1 << 9))
4591 {
4592 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4593 unwind.opcode_count--;
4594 }
4595 }
4596 else if (i == 6 && unwind.opcode_count >= 2)
4597 {
4598 i = unwind.opcodes[unwind.opcode_count - 2];
4599 reg = i >> 4;
4600 i &= 0xf;
b99bd4ef 4601
c19d1205
ZW
4602 op = 0xffff << (reg - 1);
4603 if (reg > 0
87a1fd79 4604 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4605 {
4606 op = (1 << (reg + i + 1)) - 1;
4607 op &= ~((1 << reg) - 1);
4608 mask |= op;
4609 unwind.opcode_count -= 2;
4610 }
4611 }
4612 }
b99bd4ef
NC
4613 }
4614
c19d1205
ZW
4615 hi_reg = 15;
4616 /* We want to generate opcodes in the order the registers have been
4617 saved, ie. descending order. */
4618 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4619 {
c19d1205
ZW
4620 /* Save registers in blocks. */
4621 if (reg < 0
4622 || !(mask & (1 << reg)))
4623 {
4624 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4625 preceding block. */
c19d1205
ZW
4626 if (reg != hi_reg)
4627 {
4628 if (reg == 9)
4629 {
4630 /* Short form. */
4631 op = 0xc0 | (hi_reg - 10);
4632 add_unwind_opcode (op, 1);
4633 }
4634 else
4635 {
4636 /* Long form. */
4637 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4638 add_unwind_opcode (op, 2);
4639 }
4640 }
4641 hi_reg = reg - 1;
4642 }
b99bd4ef
NC
4643 }
4644
c19d1205 4645 return;
dc1e8a47 4646 error:
c19d1205 4647 ignore_rest_of_line ();
b99bd4ef
NC
4648}
4649
4650static void
c19d1205 4651s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4652{
c19d1205
ZW
4653 int reg;
4654 int hi_reg;
4655 unsigned mask = 0;
4656 valueT op;
b99bd4ef 4657
c19d1205
ZW
4658 if (*input_line_pointer == '{')
4659 input_line_pointer++;
b99bd4ef 4660
477330fc
RM
4661 skip_whitespace (input_line_pointer);
4662
c19d1205 4663 do
b99bd4ef 4664 {
dcbf9037 4665 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4666
c19d1205
ZW
4667 if (reg == FAIL)
4668 {
9b7132d3 4669 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4670 goto error;
4671 }
b99bd4ef 4672
c19d1205
ZW
4673 reg -= 8;
4674 if (mask >> reg)
4675 as_tsktsk (_("register list not in ascending order"));
4676 mask |= 1 << reg;
b99bd4ef 4677
c19d1205
ZW
4678 if (*input_line_pointer == '-')
4679 {
4680 input_line_pointer++;
dcbf9037 4681 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4682 if (hi_reg == FAIL)
4683 {
9b7132d3 4684 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4685 goto error;
4686 }
4687 else if (reg >= hi_reg)
4688 {
4689 as_bad (_("bad register range"));
4690 goto error;
4691 }
4692 for (; reg < hi_reg; reg++)
4693 mask |= 1 << reg;
4694 }
b99bd4ef 4695 }
c19d1205 4696 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4697
d996d970 4698 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4699
c19d1205
ZW
4700 demand_empty_rest_of_line ();
4701
708587a4 4702 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4703 the list. */
4704 flush_pending_unwind ();
b99bd4ef 4705
c19d1205 4706 for (reg = 0; reg < 16; reg++)
b99bd4ef 4707 {
c19d1205
ZW
4708 if (mask & (1 << reg))
4709 unwind.frame_size += 4;
b99bd4ef 4710 }
c19d1205
ZW
4711 op = 0xc700 | mask;
4712 add_unwind_opcode (op, 2);
4713 return;
dc1e8a47 4714 error:
c19d1205 4715 ignore_rest_of_line ();
b99bd4ef
NC
4716}
4717
c19d1205 4718
fa073d69
MS
4719/* Parse an unwind_save directive.
4720 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4721
b99bd4ef 4722static void
fa073d69 4723s_arm_unwind_save (int arch_v6)
b99bd4ef 4724{
c19d1205
ZW
4725 char *peek;
4726 struct reg_entry *reg;
4727 bfd_boolean had_brace = FALSE;
b99bd4ef 4728
921e5f0a 4729 if (!unwind.proc_start)
c921be7d 4730 as_bad (MISSING_FNSTART);
921e5f0a 4731
c19d1205
ZW
4732 /* Figure out what sort of save we have. */
4733 peek = input_line_pointer;
b99bd4ef 4734
c19d1205 4735 if (*peek == '{')
b99bd4ef 4736 {
c19d1205
ZW
4737 had_brace = TRUE;
4738 peek++;
b99bd4ef
NC
4739 }
4740
c19d1205 4741 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4742
c19d1205 4743 if (!reg)
b99bd4ef 4744 {
c19d1205
ZW
4745 as_bad (_("register expected"));
4746 ignore_rest_of_line ();
b99bd4ef
NC
4747 return;
4748 }
4749
c19d1205 4750 switch (reg->type)
b99bd4ef 4751 {
c19d1205
ZW
4752 case REG_TYPE_FN:
4753 if (had_brace)
4754 {
4755 as_bad (_("FPA .unwind_save does not take a register list"));
4756 ignore_rest_of_line ();
4757 return;
4758 }
93ac2687 4759 input_line_pointer = peek;
c19d1205 4760 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4761 return;
c19d1205 4762
1f5afe1c
NC
4763 case REG_TYPE_RN:
4764 s_arm_unwind_save_core ();
4765 return;
4766
fa073d69
MS
4767 case REG_TYPE_VFD:
4768 if (arch_v6)
477330fc 4769 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4770 else
477330fc 4771 s_arm_unwind_save_vfp ();
fa073d69 4772 return;
1f5afe1c
NC
4773
4774 case REG_TYPE_MMXWR:
4775 s_arm_unwind_save_mmxwr ();
4776 return;
4777
4778 case REG_TYPE_MMXWCG:
4779 s_arm_unwind_save_mmxwcg ();
4780 return;
c19d1205
ZW
4781
4782 default:
4783 as_bad (_(".unwind_save does not support this kind of register"));
4784 ignore_rest_of_line ();
b99bd4ef 4785 }
c19d1205 4786}
b99bd4ef 4787
b99bd4ef 4788
c19d1205
ZW
4789/* Parse an unwind_movsp directive. */
4790
4791static void
4792s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4793{
4794 int reg;
4795 valueT op;
4fa3602b 4796 int offset;
c19d1205 4797
921e5f0a 4798 if (!unwind.proc_start)
c921be7d 4799 as_bad (MISSING_FNSTART);
921e5f0a 4800
dcbf9037 4801 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4802 if (reg == FAIL)
b99bd4ef 4803 {
9b7132d3 4804 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4805 ignore_rest_of_line ();
b99bd4ef
NC
4806 return;
4807 }
4fa3602b
PB
4808
4809 /* Optional constant. */
4810 if (skip_past_comma (&input_line_pointer) != FAIL)
4811 {
4812 if (immediate_for_directive (&offset) == FAIL)
4813 return;
4814 }
4815 else
4816 offset = 0;
4817
c19d1205 4818 demand_empty_rest_of_line ();
b99bd4ef 4819
c19d1205 4820 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4821 {
c19d1205 4822 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4823 return;
4824 }
4825
c19d1205
ZW
4826 if (unwind.fp_reg != REG_SP)
4827 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4828
c19d1205
ZW
4829 /* Generate opcode to restore the value. */
4830 op = 0x90 | reg;
4831 add_unwind_opcode (op, 1);
4832
4833 /* Record the information for later. */
4834 unwind.fp_reg = reg;
4fa3602b 4835 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4836 unwind.sp_restored = 1;
b05fe5cf
ZW
4837}
4838
c19d1205
ZW
4839/* Parse an unwind_pad directive. */
4840
b05fe5cf 4841static void
c19d1205 4842s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4843{
c19d1205 4844 int offset;
b05fe5cf 4845
921e5f0a 4846 if (!unwind.proc_start)
c921be7d 4847 as_bad (MISSING_FNSTART);
921e5f0a 4848
c19d1205
ZW
4849 if (immediate_for_directive (&offset) == FAIL)
4850 return;
b99bd4ef 4851
c19d1205
ZW
4852 if (offset & 3)
4853 {
4854 as_bad (_("stack increment must be multiple of 4"));
4855 ignore_rest_of_line ();
4856 return;
4857 }
b99bd4ef 4858
c19d1205
ZW
4859 /* Don't generate any opcodes, just record the details for later. */
4860 unwind.frame_size += offset;
4861 unwind.pending_offset += offset;
4862
4863 demand_empty_rest_of_line ();
4864}
4865
4866/* Parse an unwind_setfp directive. */
4867
4868static void
4869s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4870{
c19d1205
ZW
4871 int sp_reg;
4872 int fp_reg;
4873 int offset;
4874
921e5f0a 4875 if (!unwind.proc_start)
c921be7d 4876 as_bad (MISSING_FNSTART);
921e5f0a 4877
dcbf9037 4878 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4879 if (skip_past_comma (&input_line_pointer) == FAIL)
4880 sp_reg = FAIL;
4881 else
dcbf9037 4882 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4883
c19d1205
ZW
4884 if (fp_reg == FAIL || sp_reg == FAIL)
4885 {
4886 as_bad (_("expected <reg>, <reg>"));
4887 ignore_rest_of_line ();
4888 return;
4889 }
b99bd4ef 4890
c19d1205
ZW
4891 /* Optional constant. */
4892 if (skip_past_comma (&input_line_pointer) != FAIL)
4893 {
4894 if (immediate_for_directive (&offset) == FAIL)
4895 return;
4896 }
4897 else
4898 offset = 0;
a737bd4d 4899
c19d1205 4900 demand_empty_rest_of_line ();
a737bd4d 4901
fdfde340 4902 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4903 {
c19d1205
ZW
4904 as_bad (_("register must be either sp or set by a previous"
4905 "unwind_movsp directive"));
4906 return;
a737bd4d
NC
4907 }
4908
c19d1205
ZW
4909 /* Don't generate any opcodes, just record the information for later. */
4910 unwind.fp_reg = fp_reg;
4911 unwind.fp_used = 1;
fdfde340 4912 if (sp_reg == REG_SP)
c19d1205
ZW
4913 unwind.fp_offset = unwind.frame_size - offset;
4914 else
4915 unwind.fp_offset -= offset;
a737bd4d
NC
4916}
4917
c19d1205
ZW
4918/* Parse an unwind_raw directive. */
4919
4920static void
4921s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4922{
c19d1205 4923 expressionS exp;
708587a4 4924 /* This is an arbitrary limit. */
c19d1205
ZW
4925 unsigned char op[16];
4926 int count;
a737bd4d 4927
921e5f0a 4928 if (!unwind.proc_start)
c921be7d 4929 as_bad (MISSING_FNSTART);
921e5f0a 4930
c19d1205
ZW
4931 expression (&exp);
4932 if (exp.X_op == O_constant
4933 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4934 {
c19d1205
ZW
4935 unwind.frame_size += exp.X_add_number;
4936 expression (&exp);
4937 }
4938 else
4939 exp.X_op = O_illegal;
a737bd4d 4940
c19d1205
ZW
4941 if (exp.X_op != O_constant)
4942 {
4943 as_bad (_("expected <offset>, <opcode>"));
4944 ignore_rest_of_line ();
4945 return;
4946 }
a737bd4d 4947
c19d1205 4948 count = 0;
a737bd4d 4949
c19d1205
ZW
4950 /* Parse the opcode. */
4951 for (;;)
4952 {
4953 if (count >= 16)
4954 {
4955 as_bad (_("unwind opcode too long"));
4956 ignore_rest_of_line ();
a737bd4d 4957 }
c19d1205 4958 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4959 {
c19d1205
ZW
4960 as_bad (_("invalid unwind opcode"));
4961 ignore_rest_of_line ();
4962 return;
a737bd4d 4963 }
c19d1205 4964 op[count++] = exp.X_add_number;
a737bd4d 4965
c19d1205
ZW
4966 /* Parse the next byte. */
4967 if (skip_past_comma (&input_line_pointer) == FAIL)
4968 break;
a737bd4d 4969
c19d1205
ZW
4970 expression (&exp);
4971 }
b99bd4ef 4972
c19d1205
ZW
4973 /* Add the opcode bytes in reverse order. */
4974 while (count--)
4975 add_unwind_opcode (op[count], 1);
b99bd4ef 4976
c19d1205 4977 demand_empty_rest_of_line ();
b99bd4ef 4978}
ee065d83
PB
4979
4980
4981/* Parse a .eabi_attribute directive. */
4982
4983static void
4984s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4985{
0420f52b 4986 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4987
3076e594 4988 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4989 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4990}
4991
0855e32b
NS
4992/* Emit a tls fix for the symbol. */
4993
4994static void
4995s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4996{
4997 char *p;
4998 expressionS exp;
4999#ifdef md_flush_pending_output
5000 md_flush_pending_output ();
5001#endif
5002
5003#ifdef md_cons_align
5004 md_cons_align (4);
5005#endif
5006
5007 /* Since we're just labelling the code, there's no need to define a
5008 mapping symbol. */
5009 expression (&exp);
5010 p = obstack_next_free (&frchain_now->frch_obstack);
5011 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5012 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5013 : BFD_RELOC_ARM_TLS_DESCSEQ);
5014}
cdf9ccec 5015#endif /* OBJ_ELF */
0855e32b 5016
ee065d83 5017static void s_arm_arch (int);
7a1d4c38 5018static void s_arm_object_arch (int);
ee065d83
PB
5019static void s_arm_cpu (int);
5020static void s_arm_fpu (int);
69133863 5021static void s_arm_arch_extension (int);
b99bd4ef 5022
f0927246
NC
5023#ifdef TE_PE
5024
5025static void
5f4273c7 5026pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
5027{
5028 expressionS exp;
5029
5030 do
5031 {
5032 expression (&exp);
5033 if (exp.X_op == O_symbol)
5034 exp.X_op = O_secrel;
5035
5036 emit_expr (&exp, 4);
5037 }
5038 while (*input_line_pointer++ == ',');
5039
5040 input_line_pointer--;
5041 demand_empty_rest_of_line ();
5042}
5043#endif /* TE_PE */
5044
5312fe52
BW
5045int
5046arm_is_largest_exponent_ok (int precision)
5047{
5048 /* precision == 1 ensures that this will only return
5049 true for 16 bit floats. */
5050 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5051}
5052
5053static void
5054set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5055{
5056 char saved_char;
5057 char* name;
5058 enum fp_16bit_format new_format;
5059
5060 new_format = ARM_FP16_FORMAT_DEFAULT;
5061
5062 name = input_line_pointer;
5063 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5064 input_line_pointer++;
5065
5066 saved_char = *input_line_pointer;
5067 *input_line_pointer = 0;
5068
5069 if (strcasecmp (name, "ieee") == 0)
5070 new_format = ARM_FP16_FORMAT_IEEE;
5071 else if (strcasecmp (name, "alternative") == 0)
5072 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5073 else
5074 {
5075 as_bad (_("unrecognised float16 format \"%s\""), name);
5076 goto cleanup;
5077 }
5078
5079 /* Only set fp16_format if it is still the default (aka not already
5080 been set yet). */
5081 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5082 fp16_format = new_format;
5083 else
5084 {
5085 if (new_format != fp16_format)
5086 as_warn (_("float16 format cannot be set more than once, ignoring."));
5087 }
5088
dc1e8a47 5089 cleanup:
5312fe52
BW
5090 *input_line_pointer = saved_char;
5091 ignore_rest_of_line ();
5092}
5093
c19d1205
ZW
5094/* This table describes all the machine specific pseudo-ops the assembler
5095 has to support. The fields are:
5096 pseudo-op name without dot
5097 function to call to execute this pseudo-op
5098 Integer arg to pass to the function. */
b99bd4ef 5099
c19d1205 5100const pseudo_typeS md_pseudo_table[] =
b99bd4ef 5101{
c19d1205
ZW
5102 /* Never called because '.req' does not start a line. */
5103 { "req", s_req, 0 },
dcbf9037
JB
5104 /* Following two are likewise never called. */
5105 { "dn", s_dn, 0 },
5106 { "qn", s_qn, 0 },
c19d1205
ZW
5107 { "unreq", s_unreq, 0 },
5108 { "bss", s_bss, 0 },
db2ed2e0 5109 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5110 { "arm", s_arm, 0 },
5111 { "thumb", s_thumb, 0 },
5112 { "code", s_code, 0 },
5113 { "force_thumb", s_force_thumb, 0 },
5114 { "thumb_func", s_thumb_func, 0 },
5115 { "thumb_set", s_thumb_set, 0 },
5116 { "even", s_even, 0 },
5117 { "ltorg", s_ltorg, 0 },
5118 { "pool", s_ltorg, 0 },
5119 { "syntax", s_syntax, 0 },
8463be01
PB
5120 { "cpu", s_arm_cpu, 0 },
5121 { "arch", s_arm_arch, 0 },
7a1d4c38 5122 { "object_arch", s_arm_object_arch, 0 },
8463be01 5123 { "fpu", s_arm_fpu, 0 },
69133863 5124 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5125#ifdef OBJ_ELF
c921be7d
NC
5126 { "word", s_arm_elf_cons, 4 },
5127 { "long", s_arm_elf_cons, 4 },
5128 { "inst.n", s_arm_elf_inst, 2 },
5129 { "inst.w", s_arm_elf_inst, 4 },
5130 { "inst", s_arm_elf_inst, 0 },
5131 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5132 { "fnstart", s_arm_unwind_fnstart, 0 },
5133 { "fnend", s_arm_unwind_fnend, 0 },
5134 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5135 { "personality", s_arm_unwind_personality, 0 },
5136 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5137 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5138 { "save", s_arm_unwind_save, 0 },
fa073d69 5139 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5140 { "movsp", s_arm_unwind_movsp, 0 },
5141 { "pad", s_arm_unwind_pad, 0 },
5142 { "setfp", s_arm_unwind_setfp, 0 },
5143 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5144 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5145 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5146#else
5147 { "word", cons, 4},
f0927246
NC
5148
5149 /* These are used for dwarf. */
5150 {"2byte", cons, 2},
5151 {"4byte", cons, 4},
5152 {"8byte", cons, 8},
5153 /* These are used for dwarf2. */
68d20676 5154 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5155 { "loc", dwarf2_directive_loc, 0 },
5156 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5157#endif
5158 { "extend", float_cons, 'x' },
5159 { "ldouble", float_cons, 'x' },
5160 { "packed", float_cons, 'p' },
27cce866 5161 { "bfloat16", float_cons, 'b' },
f0927246
NC
5162#ifdef TE_PE
5163 {"secrel32", pe_directive_secrel, 0},
5164#endif
2e6976a8
DG
5165
5166 /* These are for compatibility with CodeComposer Studio. */
5167 {"ref", s_ccs_ref, 0},
5168 {"def", s_ccs_def, 0},
5169 {"asmfunc", s_ccs_asmfunc, 0},
5170 {"endasmfunc", s_ccs_endasmfunc, 0},
5171
5312fe52
BW
5172 {"float16", float_cons, 'h' },
5173 {"float16_format", set_fp16_format, 0 },
5174
c19d1205
ZW
5175 { 0, 0, 0 }
5176};
5312fe52 5177
c19d1205 5178/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5179
c19d1205
ZW
5180/* Generic immediate-value read function for use in insn parsing.
5181 STR points to the beginning of the immediate (the leading #);
5182 VAL receives the value; if the value is outside [MIN, MAX]
5183 issue an error. PREFIX_OPT is true if the immediate prefix is
5184 optional. */
b99bd4ef 5185
c19d1205
ZW
5186static int
5187parse_immediate (char **str, int *val, int min, int max,
5188 bfd_boolean prefix_opt)
5189{
5190 expressionS exp;
0198d5e6 5191
c19d1205
ZW
5192 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5193 if (exp.X_op != O_constant)
b99bd4ef 5194 {
c19d1205
ZW
5195 inst.error = _("constant expression required");
5196 return FAIL;
5197 }
b99bd4ef 5198
c19d1205
ZW
5199 if (exp.X_add_number < min || exp.X_add_number > max)
5200 {
5201 inst.error = _("immediate value out of range");
5202 return FAIL;
5203 }
b99bd4ef 5204
c19d1205
ZW
5205 *val = exp.X_add_number;
5206 return SUCCESS;
5207}
b99bd4ef 5208
5287ad62 5209/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5210 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5211 instructions. Puts the result directly in inst.operands[i]. */
5212
5213static int
8335d6aa
JW
5214parse_big_immediate (char **str, int i, expressionS *in_exp,
5215 bfd_boolean allow_symbol_p)
5287ad62
JB
5216{
5217 expressionS exp;
8335d6aa 5218 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5219 char *ptr = *str;
5220
8335d6aa 5221 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5222
8335d6aa 5223 if (exp_p->X_op == O_constant)
036dc3f7 5224 {
8335d6aa 5225 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5226 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5227 O_constant. We have to be careful not to break compilation for
5228 32-bit X_add_number, though. */
8335d6aa 5229 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5230 {
8335d6aa
JW
5231 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5232 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5233 & 0xffffffff);
036dc3f7
PB
5234 inst.operands[i].regisimm = 1;
5235 }
5236 }
8335d6aa
JW
5237 else if (exp_p->X_op == O_big
5238 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5239 {
5240 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5241
5287ad62 5242 /* Bignums have their least significant bits in
477330fc
RM
5243 generic_bignum[0]. Make sure we put 32 bits in imm and
5244 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5245 gas_assert (parts != 0);
95b75c01
NC
5246
5247 /* Make sure that the number is not too big.
5248 PR 11972: Bignums can now be sign-extended to the
5249 size of a .octa so check that the out of range bits
5250 are all zero or all one. */
8335d6aa 5251 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5252 {
5253 LITTLENUM_TYPE m = -1;
5254
5255 if (generic_bignum[parts * 2] != 0
5256 && generic_bignum[parts * 2] != m)
5257 return FAIL;
5258
8335d6aa 5259 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5260 if (generic_bignum[j] != generic_bignum[j-1])
5261 return FAIL;
5262 }
5263
5287ad62
JB
5264 inst.operands[i].imm = 0;
5265 for (j = 0; j < parts; j++, idx++)
7af67752
AM
5266 inst.operands[i].imm |= ((unsigned) generic_bignum[idx]
5267 << (LITTLENUM_NUMBER_OF_BITS * j));
5287ad62
JB
5268 inst.operands[i].reg = 0;
5269 for (j = 0; j < parts; j++, idx++)
7af67752
AM
5270 inst.operands[i].reg |= ((unsigned) generic_bignum[idx]
5271 << (LITTLENUM_NUMBER_OF_BITS * j));
5287ad62
JB
5272 inst.operands[i].regisimm = 1;
5273 }
8335d6aa 5274 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5275 return FAIL;
5f4273c7 5276
5287ad62
JB
5277 *str = ptr;
5278
5279 return SUCCESS;
5280}
5281
c19d1205
ZW
5282/* Returns the pseudo-register number of an FPA immediate constant,
5283 or FAIL if there isn't a valid constant here. */
b99bd4ef 5284
c19d1205
ZW
5285static int
5286parse_fpa_immediate (char ** str)
5287{
5288 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5289 char * save_in;
5290 expressionS exp;
5291 int i;
5292 int j;
b99bd4ef 5293
c19d1205
ZW
5294 /* First try and match exact strings, this is to guarantee
5295 that some formats will work even for cross assembly. */
b99bd4ef 5296
c19d1205
ZW
5297 for (i = 0; fp_const[i]; i++)
5298 {
5299 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5300 {
c19d1205 5301 char *start = *str;
b99bd4ef 5302
c19d1205
ZW
5303 *str += strlen (fp_const[i]);
5304 if (is_end_of_line[(unsigned char) **str])
5305 return i + 8;
5306 *str = start;
5307 }
5308 }
b99bd4ef 5309
c19d1205
ZW
5310 /* Just because we didn't get a match doesn't mean that the constant
5311 isn't valid, just that it is in a format that we don't
5312 automatically recognize. Try parsing it with the standard
5313 expression routines. */
b99bd4ef 5314
c19d1205 5315 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5316
c19d1205
ZW
5317 /* Look for a raw floating point number. */
5318 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5319 && is_end_of_line[(unsigned char) *save_in])
5320 {
5321 for (i = 0; i < NUM_FLOAT_VALS; i++)
5322 {
5323 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5324 {
c19d1205
ZW
5325 if (words[j] != fp_values[i][j])
5326 break;
b99bd4ef
NC
5327 }
5328
c19d1205 5329 if (j == MAX_LITTLENUMS)
b99bd4ef 5330 {
c19d1205
ZW
5331 *str = save_in;
5332 return i + 8;
b99bd4ef
NC
5333 }
5334 }
5335 }
b99bd4ef 5336
c19d1205
ZW
5337 /* Try and parse a more complex expression, this will probably fail
5338 unless the code uses a floating point prefix (eg "0f"). */
5339 save_in = input_line_pointer;
5340 input_line_pointer = *str;
5341 if (expression (&exp) == absolute_section
5342 && exp.X_op == O_big
5343 && exp.X_add_number < 0)
5344 {
5345 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5346 Ditto for 15. */
ba592044
AM
5347#define X_PRECISION 5
5348#define E_PRECISION 15L
5349 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5350 {
5351 for (i = 0; i < NUM_FLOAT_VALS; i++)
5352 {
5353 for (j = 0; j < MAX_LITTLENUMS; j++)
5354 {
5355 if (words[j] != fp_values[i][j])
5356 break;
5357 }
b99bd4ef 5358
c19d1205
ZW
5359 if (j == MAX_LITTLENUMS)
5360 {
5361 *str = input_line_pointer;
5362 input_line_pointer = save_in;
5363 return i + 8;
5364 }
5365 }
5366 }
b99bd4ef
NC
5367 }
5368
c19d1205
ZW
5369 *str = input_line_pointer;
5370 input_line_pointer = save_in;
5371 inst.error = _("invalid FPA immediate expression");
5372 return FAIL;
b99bd4ef
NC
5373}
5374
136da414
JB
5375/* Returns 1 if a number has "quarter-precision" float format
5376 0baBbbbbbc defgh000 00000000 00000000. */
5377
5378static int
5379is_quarter_float (unsigned imm)
5380{
5381 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5382 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5383}
5384
aacf0b33
KT
5385
5386/* Detect the presence of a floating point or integer zero constant,
5387 i.e. #0.0 or #0. */
5388
5389static bfd_boolean
5390parse_ifimm_zero (char **in)
5391{
5392 int error_code;
5393
5394 if (!is_immediate_prefix (**in))
3c6452ae
TP
5395 {
5396 /* In unified syntax, all prefixes are optional. */
5397 if (!unified_syntax)
5398 return FALSE;
5399 }
5400 else
5401 ++*in;
0900a05b
JW
5402
5403 /* Accept #0x0 as a synonym for #0. */
5404 if (strncmp (*in, "0x", 2) == 0)
5405 {
5406 int val;
5407 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5408 return FALSE;
5409 return TRUE;
5410 }
5411
aacf0b33
KT
5412 error_code = atof_generic (in, ".", EXP_CHARS,
5413 &generic_floating_point_number);
5414
5415 if (!error_code
5416 && generic_floating_point_number.sign == '+'
5417 && (generic_floating_point_number.low
5418 > generic_floating_point_number.leader))
5419 return TRUE;
5420
5421 return FALSE;
5422}
5423
136da414
JB
5424/* Parse an 8-bit "quarter-precision" floating point number of the form:
5425 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5426 The zero and minus-zero cases need special handling, since they can't be
5427 encoded in the "quarter-precision" float format, but can nonetheless be
5428 loaded as integer constants. */
136da414
JB
5429
5430static unsigned
5431parse_qfloat_immediate (char **ccp, int *immed)
5432{
5433 char *str = *ccp;
c96612cc 5434 char *fpnum;
136da414 5435 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5436 int found_fpchar = 0;
5f4273c7 5437
136da414 5438 skip_past_char (&str, '#');
5f4273c7 5439
c96612cc
JB
5440 /* We must not accidentally parse an integer as a floating-point number. Make
5441 sure that the value we parse is not an integer by checking for special
5442 characters '.' or 'e'.
5443 FIXME: This is a horrible hack, but doing better is tricky because type
5444 information isn't in a very usable state at parse time. */
5445 fpnum = str;
5446 skip_whitespace (fpnum);
5447
5448 if (strncmp (fpnum, "0x", 2) == 0)
5449 return FAIL;
5450 else
5451 {
5452 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5453 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5454 {
5455 found_fpchar = 1;
5456 break;
5457 }
c96612cc
JB
5458
5459 if (!found_fpchar)
477330fc 5460 return FAIL;
c96612cc 5461 }
5f4273c7 5462
136da414
JB
5463 if ((str = atof_ieee (str, 's', words)) != NULL)
5464 {
5465 unsigned fpword = 0;
5466 int i;
5f4273c7 5467
136da414
JB
5468 /* Our FP word must be 32 bits (single-precision FP). */
5469 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5470 {
5471 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5472 fpword |= words[i];
5473 }
5f4273c7 5474
c96612cc 5475 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5476 *immed = fpword;
136da414 5477 else
477330fc 5478 return FAIL;
136da414
JB
5479
5480 *ccp = str;
5f4273c7 5481
136da414
JB
5482 return SUCCESS;
5483 }
5f4273c7 5484
136da414
JB
5485 return FAIL;
5486}
5487
c19d1205
ZW
5488/* Shift operands. */
5489enum shift_kind
b99bd4ef 5490{
f5f10c66 5491 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5492};
b99bd4ef 5493
c19d1205
ZW
5494struct asm_shift_name
5495{
5496 const char *name;
5497 enum shift_kind kind;
5498};
b99bd4ef 5499
c19d1205
ZW
5500/* Third argument to parse_shift. */
5501enum parse_shift_mode
5502{
5503 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5504 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5505 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5506 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5507 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5508 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5509};
b99bd4ef 5510
c19d1205
ZW
5511/* Parse a <shift> specifier on an ARM data processing instruction.
5512 This has three forms:
b99bd4ef 5513
c19d1205
ZW
5514 (LSL|LSR|ASL|ASR|ROR) Rs
5515 (LSL|LSR|ASL|ASR|ROR) #imm
5516 RRX
b99bd4ef 5517
c19d1205
ZW
5518 Note that ASL is assimilated to LSL in the instruction encoding, and
5519 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5520
c19d1205
ZW
5521static int
5522parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5523{
c19d1205
ZW
5524 const struct asm_shift_name *shift_name;
5525 enum shift_kind shift;
5526 char *s = *str;
5527 char *p = s;
5528 int reg;
b99bd4ef 5529
c19d1205
ZW
5530 for (p = *str; ISALPHA (*p); p++)
5531 ;
b99bd4ef 5532
c19d1205 5533 if (p == *str)
b99bd4ef 5534 {
c19d1205
ZW
5535 inst.error = _("shift expression expected");
5536 return FAIL;
b99bd4ef
NC
5537 }
5538
fe0e921f
AM
5539 shift_name
5540 = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str,
5541 p - *str);
c19d1205
ZW
5542
5543 if (shift_name == NULL)
b99bd4ef 5544 {
c19d1205
ZW
5545 inst.error = _("shift expression expected");
5546 return FAIL;
b99bd4ef
NC
5547 }
5548
c19d1205 5549 shift = shift_name->kind;
b99bd4ef 5550
c19d1205
ZW
5551 switch (mode)
5552 {
5553 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5554 case SHIFT_IMMEDIATE:
5555 if (shift == SHIFT_UXTW)
5556 {
5557 inst.error = _("'UXTW' not allowed here");
5558 return FAIL;
5559 }
5560 break;
b99bd4ef 5561
c19d1205
ZW
5562 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5563 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5564 {
5565 inst.error = _("'LSL' or 'ASR' required");
5566 return FAIL;
5567 }
5568 break;
b99bd4ef 5569
c19d1205
ZW
5570 case SHIFT_LSL_IMMEDIATE:
5571 if (shift != SHIFT_LSL)
5572 {
5573 inst.error = _("'LSL' required");
5574 return FAIL;
5575 }
5576 break;
b99bd4ef 5577
c19d1205
ZW
5578 case SHIFT_ASR_IMMEDIATE:
5579 if (shift != SHIFT_ASR)
5580 {
5581 inst.error = _("'ASR' required");
5582 return FAIL;
5583 }
5584 break;
f5f10c66
AV
5585 case SHIFT_UXTW_IMMEDIATE:
5586 if (shift != SHIFT_UXTW)
5587 {
5588 inst.error = _("'UXTW' required");
5589 return FAIL;
5590 }
5591 break;
b99bd4ef 5592
c19d1205
ZW
5593 default: abort ();
5594 }
b99bd4ef 5595
c19d1205
ZW
5596 if (shift != SHIFT_RRX)
5597 {
5598 /* Whitespace can appear here if the next thing is a bare digit. */
5599 skip_whitespace (p);
b99bd4ef 5600
c19d1205 5601 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5602 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5603 {
5604 inst.operands[i].imm = reg;
5605 inst.operands[i].immisreg = 1;
5606 }
e2b0ab59 5607 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5608 return FAIL;
5609 }
5610 inst.operands[i].shift_kind = shift;
5611 inst.operands[i].shifted = 1;
5612 *str = p;
5613 return SUCCESS;
b99bd4ef
NC
5614}
5615
c19d1205 5616/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5617
c19d1205
ZW
5618 #<immediate>
5619 #<immediate>, <rotate>
5620 <Rm>
5621 <Rm>, <shift>
b99bd4ef 5622
c19d1205
ZW
5623 where <shift> is defined by parse_shift above, and <rotate> is a
5624 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5625 is deferred to md_apply_fix. */
b99bd4ef 5626
c19d1205
ZW
5627static int
5628parse_shifter_operand (char **str, int i)
5629{
5630 int value;
91d6fa6a 5631 expressionS exp;
b99bd4ef 5632
dcbf9037 5633 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5634 {
5635 inst.operands[i].reg = value;
5636 inst.operands[i].isreg = 1;
b99bd4ef 5637
c19d1205 5638 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5639 inst.relocs[0].exp.X_op = O_constant;
5640 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5641
c19d1205
ZW
5642 if (skip_past_comma (str) == FAIL)
5643 return SUCCESS;
b99bd4ef 5644
c19d1205
ZW
5645 /* Shift operation on register. */
5646 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5647 }
5648
e2b0ab59 5649 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5650 return FAIL;
b99bd4ef 5651
c19d1205 5652 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5653 {
c19d1205 5654 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5655 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5656 return FAIL;
b99bd4ef 5657
e2b0ab59 5658 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5659 {
5660 inst.error = _("constant expression expected");
5661 return FAIL;
5662 }
b99bd4ef 5663
91d6fa6a 5664 value = exp.X_add_number;
c19d1205
ZW
5665 if (value < 0 || value > 30 || value % 2 != 0)
5666 {
5667 inst.error = _("invalid rotation");
5668 return FAIL;
5669 }
e2b0ab59
AV
5670 if (inst.relocs[0].exp.X_add_number < 0
5671 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5672 {
5673 inst.error = _("invalid constant");
5674 return FAIL;
5675 }
09d92015 5676
a415b1cd 5677 /* Encode as specified. */
e2b0ab59 5678 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5679 return SUCCESS;
09d92015
MM
5680 }
5681
e2b0ab59
AV
5682 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5683 inst.relocs[0].pc_rel = 0;
c19d1205 5684 return SUCCESS;
09d92015
MM
5685}
5686
4962c51a
MS
5687/* Group relocation information. Each entry in the table contains the
5688 textual name of the relocation as may appear in assembler source
5689 and must end with a colon.
5690 Along with this textual name are the relocation codes to be used if
5691 the corresponding instruction is an ALU instruction (ADD or SUB only),
5692 an LDR, an LDRS, or an LDC. */
5693
5694struct group_reloc_table_entry
5695{
5696 const char *name;
5697 int alu_code;
5698 int ldr_code;
5699 int ldrs_code;
5700 int ldc_code;
5701};
5702
5703typedef enum
5704{
5705 /* Varieties of non-ALU group relocation. */
5706
5707 GROUP_LDR,
5708 GROUP_LDRS,
35c228db
AV
5709 GROUP_LDC,
5710 GROUP_MVE
4962c51a
MS
5711} group_reloc_type;
5712
5713static struct group_reloc_table_entry group_reloc_table[] =
5714 { /* Program counter relative: */
5715 { "pc_g0_nc",
5716 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5717 0, /* LDR */
5718 0, /* LDRS */
5719 0 }, /* LDC */
5720 { "pc_g0",
5721 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5722 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5723 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5724 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5725 { "pc_g1_nc",
5726 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5727 0, /* LDR */
5728 0, /* LDRS */
5729 0 }, /* LDC */
5730 { "pc_g1",
5731 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5732 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5733 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5734 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5735 { "pc_g2",
5736 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5737 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5738 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5739 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5740 /* Section base relative */
5741 { "sb_g0_nc",
5742 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5743 0, /* LDR */
5744 0, /* LDRS */
5745 0 }, /* LDC */
5746 { "sb_g0",
5747 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5748 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5749 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5750 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5751 { "sb_g1_nc",
5752 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5753 0, /* LDR */
5754 0, /* LDRS */
5755 0 }, /* LDC */
5756 { "sb_g1",
5757 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5758 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5759 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5760 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5761 { "sb_g2",
5762 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5763 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5764 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5765 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5766 /* Absolute thumb alu relocations. */
5767 { "lower0_7",
5768 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5769 0, /* LDR. */
5770 0, /* LDRS. */
5771 0 }, /* LDC. */
5772 { "lower8_15",
5773 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5774 0, /* LDR. */
5775 0, /* LDRS. */
5776 0 }, /* LDC. */
5777 { "upper0_7",
5778 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5779 0, /* LDR. */
5780 0, /* LDRS. */
5781 0 }, /* LDC. */
5782 { "upper8_15",
5783 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5784 0, /* LDR. */
5785 0, /* LDRS. */
5786 0 } }; /* LDC. */
4962c51a
MS
5787
5788/* Given the address of a pointer pointing to the textual name of a group
5789 relocation as may appear in assembler source, attempt to find its details
5790 in group_reloc_table. The pointer will be updated to the character after
5791 the trailing colon. On failure, FAIL will be returned; SUCCESS
5792 otherwise. On success, *entry will be updated to point at the relevant
5793 group_reloc_table entry. */
5794
5795static int
5796find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5797{
5798 unsigned int i;
5799 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5800 {
5801 int length = strlen (group_reloc_table[i].name);
5802
5f4273c7
NC
5803 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5804 && (*str)[length] == ':')
477330fc
RM
5805 {
5806 *out = &group_reloc_table[i];
5807 *str += (length + 1);
5808 return SUCCESS;
5809 }
4962c51a
MS
5810 }
5811
5812 return FAIL;
5813}
5814
5815/* Parse a <shifter_operand> for an ARM data processing instruction
5816 (as for parse_shifter_operand) where group relocations are allowed:
5817
5818 #<immediate>
5819 #<immediate>, <rotate>
5820 #:<group_reloc>:<expression>
5821 <Rm>
5822 <Rm>, <shift>
5823
5824 where <group_reloc> is one of the strings defined in group_reloc_table.
5825 The hashes are optional.
5826
5827 Everything else is as for parse_shifter_operand. */
5828
5829static parse_operand_result
5830parse_shifter_operand_group_reloc (char **str, int i)
5831{
5832 /* Determine if we have the sequence of characters #: or just :
5833 coming next. If we do, then we check for a group relocation.
5834 If we don't, punt the whole lot to parse_shifter_operand. */
5835
5836 if (((*str)[0] == '#' && (*str)[1] == ':')
5837 || (*str)[0] == ':')
5838 {
5839 struct group_reloc_table_entry *entry;
5840
5841 if ((*str)[0] == '#')
477330fc 5842 (*str) += 2;
4962c51a 5843 else
477330fc 5844 (*str)++;
4962c51a
MS
5845
5846 /* Try to parse a group relocation. Anything else is an error. */
5847 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5848 {
5849 inst.error = _("unknown group relocation");
5850 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5851 }
4962c51a
MS
5852
5853 /* We now have the group relocation table entry corresponding to
477330fc 5854 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5855 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5856 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5857
5858 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5859 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5860 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5861
5862 return PARSE_OPERAND_SUCCESS;
5863 }
5864 else
5865 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5866 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5867
5868 /* Never reached. */
5869}
5870
8e560766
MGD
5871/* Parse a Neon alignment expression. Information is written to
5872 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5873
8e560766
MGD
5874 align .imm = align << 8, .immisalign=1, .preind=0 */
5875static parse_operand_result
5876parse_neon_alignment (char **str, int i)
5877{
5878 char *p = *str;
5879 expressionS exp;
5880
5881 my_get_expression (&exp, &p, GE_NO_PREFIX);
5882
5883 if (exp.X_op != O_constant)
5884 {
5885 inst.error = _("alignment must be constant");
5886 return PARSE_OPERAND_FAIL;
5887 }
5888
5889 inst.operands[i].imm = exp.X_add_number << 8;
5890 inst.operands[i].immisalign = 1;
5891 /* Alignments are not pre-indexes. */
5892 inst.operands[i].preind = 0;
5893
5894 *str = p;
5895 return PARSE_OPERAND_SUCCESS;
5896}
5897
c19d1205 5898/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5899 to inst.operands[i] and/or inst.relocs[0].
09d92015 5900
c19d1205 5901 Preindexed addressing (.preind=1):
09d92015 5902
e2b0ab59 5903 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5904 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5905 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5906 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5907
c19d1205 5908 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5909
c19d1205 5910 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5911
e2b0ab59 5912 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5913 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5914 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5915 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5916
c19d1205 5917 Unindexed addressing (.preind=0, .postind=0):
09d92015 5918
c19d1205 5919 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5920
c19d1205 5921 Other:
09d92015 5922
c19d1205 5923 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5924 =immediate .isreg=0 .relocs[0].exp=immediate
5925 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5926
c19d1205 5927 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5928 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5929
4962c51a
MS
5930static parse_operand_result
5931parse_address_main (char **str, int i, int group_relocations,
477330fc 5932 group_reloc_type group_type)
09d92015 5933{
c19d1205
ZW
5934 char *p = *str;
5935 int reg;
09d92015 5936
c19d1205 5937 if (skip_past_char (&p, '[') == FAIL)
09d92015 5938 {
c19d1205
ZW
5939 if (skip_past_char (&p, '=') == FAIL)
5940 {
974da60d 5941 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5942 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5943 inst.operands[i].reg = REG_PC;
5944 inst.operands[i].isreg = 1;
5945 inst.operands[i].preind = 1;
09d92015 5946
e2b0ab59 5947 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5948 return PARSE_OPERAND_FAIL;
5949 }
e2b0ab59 5950 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5951 /*allow_symbol_p=*/TRUE))
4962c51a 5952 return PARSE_OPERAND_FAIL;
09d92015 5953
c19d1205 5954 *str = p;
4962c51a 5955 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5956 }
5957
8ab8155f
NC
5958 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5959 skip_whitespace (p);
5960
f5f10c66
AV
5961 if (group_type == GROUP_MVE)
5962 {
5963 enum arm_reg_type rtype = REG_TYPE_MQ;
5964 struct neon_type_el et;
5965 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5966 {
5967 inst.operands[i].isquad = 1;
5968 }
5969 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5970 {
5971 inst.error = BAD_ADDR_MODE;
5972 return PARSE_OPERAND_FAIL;
5973 }
5974 }
5975 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5976 {
35c228db
AV
5977 if (group_type == GROUP_MVE)
5978 inst.error = BAD_ADDR_MODE;
5979 else
5980 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5981 return PARSE_OPERAND_FAIL;
09d92015 5982 }
c19d1205
ZW
5983 inst.operands[i].reg = reg;
5984 inst.operands[i].isreg = 1;
09d92015 5985
c19d1205 5986 if (skip_past_comma (&p) == SUCCESS)
09d92015 5987 {
c19d1205 5988 inst.operands[i].preind = 1;
09d92015 5989
c19d1205
ZW
5990 if (*p == '+') p++;
5991 else if (*p == '-') p++, inst.operands[i].negative = 1;
5992
f5f10c66
AV
5993 enum arm_reg_type rtype = REG_TYPE_MQ;
5994 struct neon_type_el et;
5995 if (group_type == GROUP_MVE
5996 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5997 {
5998 inst.operands[i].immisreg = 2;
5999 inst.operands[i].imm = reg;
6000
6001 if (skip_past_comma (&p) == SUCCESS)
6002 {
6003 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6004 {
6005 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6006 inst.relocs[0].exp.X_add_number = 0;
6007 }
6008 else
6009 return PARSE_OPERAND_FAIL;
6010 }
6011 }
6012 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 6013 {
c19d1205
ZW
6014 inst.operands[i].imm = reg;
6015 inst.operands[i].immisreg = 1;
6016
6017 if (skip_past_comma (&p) == SUCCESS)
6018 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6019 return PARSE_OPERAND_FAIL;
c19d1205 6020 }
5287ad62 6021 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
6022 {
6023 /* FIXME: '@' should be used here, but it's filtered out by generic
6024 code before we get to see it here. This may be subject to
6025 change. */
6026 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6027
8e560766
MGD
6028 if (result != PARSE_OPERAND_SUCCESS)
6029 return result;
6030 }
c19d1205
ZW
6031 else
6032 {
6033 if (inst.operands[i].negative)
6034 {
6035 inst.operands[i].negative = 0;
6036 p--;
6037 }
4962c51a 6038
5f4273c7
NC
6039 if (group_relocations
6040 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
6041 {
6042 struct group_reloc_table_entry *entry;
6043
477330fc
RM
6044 /* Skip over the #: or : sequence. */
6045 if (*p == '#')
6046 p += 2;
6047 else
6048 p++;
4962c51a
MS
6049
6050 /* Try to parse a group relocation. Anything else is an
477330fc 6051 error. */
4962c51a
MS
6052 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6053 {
6054 inst.error = _("unknown group relocation");
6055 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6056 }
6057
6058 /* We now have the group relocation table entry corresponding to
6059 the name in the assembler source. Next, we parse the
477330fc 6060 expression. */
e2b0ab59 6061 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
6062 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6063
6064 /* Record the relocation type. */
477330fc
RM
6065 switch (group_type)
6066 {
6067 case GROUP_LDR:
e2b0ab59
AV
6068 inst.relocs[0].type
6069 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 6070 break;
4962c51a 6071
477330fc 6072 case GROUP_LDRS:
e2b0ab59
AV
6073 inst.relocs[0].type
6074 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 6075 break;
4962c51a 6076
477330fc 6077 case GROUP_LDC:
e2b0ab59
AV
6078 inst.relocs[0].type
6079 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 6080 break;
4962c51a 6081
477330fc
RM
6082 default:
6083 gas_assert (0);
6084 }
4962c51a 6085
e2b0ab59 6086 if (inst.relocs[0].type == 0)
4962c51a
MS
6087 {
6088 inst.error = _("this group relocation is not allowed on this instruction");
6089 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6090 }
477330fc
RM
6091 }
6092 else
26d97720
NS
6093 {
6094 char *q = p;
0198d5e6 6095
e2b0ab59 6096 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
6097 return PARSE_OPERAND_FAIL;
6098 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6099 if (inst.relocs[0].exp.X_op == O_constant
6100 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6101 {
6102 skip_whitespace (q);
6103 if (*q == '#')
6104 {
6105 q++;
6106 skip_whitespace (q);
6107 }
6108 if (*q == '-')
6109 inst.operands[i].negative = 1;
6110 }
6111 }
09d92015
MM
6112 }
6113 }
8e560766
MGD
6114 else if (skip_past_char (&p, ':') == SUCCESS)
6115 {
6116 /* FIXME: '@' should be used here, but it's filtered out by generic code
6117 before we get to see it here. This may be subject to change. */
6118 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6119
8e560766
MGD
6120 if (result != PARSE_OPERAND_SUCCESS)
6121 return result;
6122 }
09d92015 6123
c19d1205 6124 if (skip_past_char (&p, ']') == FAIL)
09d92015 6125 {
c19d1205 6126 inst.error = _("']' expected");
4962c51a 6127 return PARSE_OPERAND_FAIL;
09d92015
MM
6128 }
6129
c19d1205
ZW
6130 if (skip_past_char (&p, '!') == SUCCESS)
6131 inst.operands[i].writeback = 1;
09d92015 6132
c19d1205 6133 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6134 {
c19d1205
ZW
6135 if (skip_past_char (&p, '{') == SUCCESS)
6136 {
6137 /* [Rn], {expr} - unindexed, with option */
6138 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6139 0, 255, TRUE) == FAIL)
4962c51a 6140 return PARSE_OPERAND_FAIL;
09d92015 6141
c19d1205
ZW
6142 if (skip_past_char (&p, '}') == FAIL)
6143 {
6144 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6145 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6146 }
6147 if (inst.operands[i].preind)
6148 {
6149 inst.error = _("cannot combine index with option");
4962c51a 6150 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6151 }
6152 *str = p;
4962c51a 6153 return PARSE_OPERAND_SUCCESS;
09d92015 6154 }
c19d1205
ZW
6155 else
6156 {
6157 inst.operands[i].postind = 1;
6158 inst.operands[i].writeback = 1;
09d92015 6159
c19d1205
ZW
6160 if (inst.operands[i].preind)
6161 {
6162 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6163 return PARSE_OPERAND_FAIL;
c19d1205 6164 }
09d92015 6165
c19d1205
ZW
6166 if (*p == '+') p++;
6167 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6168
f5f10c66
AV
6169 enum arm_reg_type rtype = REG_TYPE_MQ;
6170 struct neon_type_el et;
6171 if (group_type == GROUP_MVE
6172 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6173 {
6174 inst.operands[i].immisreg = 2;
6175 inst.operands[i].imm = reg;
6176 }
6177 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6178 {
477330fc
RM
6179 /* We might be using the immediate for alignment already. If we
6180 are, OR the register number into the low-order bits. */
6181 if (inst.operands[i].immisalign)
6182 inst.operands[i].imm |= reg;
6183 else
6184 inst.operands[i].imm = reg;
c19d1205 6185 inst.operands[i].immisreg = 1;
a737bd4d 6186
c19d1205
ZW
6187 if (skip_past_comma (&p) == SUCCESS)
6188 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6189 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6190 }
6191 else
6192 {
26d97720 6193 char *q = p;
0198d5e6 6194
c19d1205
ZW
6195 if (inst.operands[i].negative)
6196 {
6197 inst.operands[i].negative = 0;
6198 p--;
6199 }
e2b0ab59 6200 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6201 return PARSE_OPERAND_FAIL;
26d97720 6202 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6203 if (inst.relocs[0].exp.X_op == O_constant
6204 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6205 {
6206 skip_whitespace (q);
6207 if (*q == '#')
6208 {
6209 q++;
6210 skip_whitespace (q);
6211 }
6212 if (*q == '-')
6213 inst.operands[i].negative = 1;
6214 }
c19d1205
ZW
6215 }
6216 }
a737bd4d
NC
6217 }
6218
c19d1205
ZW
6219 /* If at this point neither .preind nor .postind is set, we have a
6220 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6221 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6222 {
6223 inst.operands[i].preind = 1;
e2b0ab59
AV
6224 inst.relocs[0].exp.X_op = O_constant;
6225 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6226 }
6227 *str = p;
4962c51a
MS
6228 return PARSE_OPERAND_SUCCESS;
6229}
6230
6231static int
6232parse_address (char **str, int i)
6233{
21d799b5 6234 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6235 ? SUCCESS : FAIL;
4962c51a
MS
6236}
6237
6238static parse_operand_result
6239parse_address_group_reloc (char **str, int i, group_reloc_type type)
6240{
6241 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6242}
6243
b6895b4f
PB
6244/* Parse an operand for a MOVW or MOVT instruction. */
6245static int
6246parse_half (char **str)
6247{
6248 char * p;
5f4273c7 6249
b6895b4f
PB
6250 p = *str;
6251 skip_past_char (&p, '#');
5f4273c7 6252 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6253 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6254 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6255 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6256
e2b0ab59 6257 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6258 {
6259 p += 9;
5f4273c7 6260 skip_whitespace (p);
b6895b4f
PB
6261 }
6262
e2b0ab59 6263 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6264 return FAIL;
6265
e2b0ab59 6266 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6267 {
e2b0ab59 6268 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6269 {
6270 inst.error = _("constant expression expected");
6271 return FAIL;
6272 }
e2b0ab59
AV
6273 if (inst.relocs[0].exp.X_add_number < 0
6274 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6275 {
6276 inst.error = _("immediate value out of range");
6277 return FAIL;
6278 }
6279 }
6280 *str = p;
6281 return SUCCESS;
6282}
6283
c19d1205 6284/* Miscellaneous. */
a737bd4d 6285
c19d1205
ZW
6286/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6287 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6288static int
d2cd1205 6289parse_psr (char **str, bfd_boolean lhs)
09d92015 6290{
c19d1205
ZW
6291 char *p;
6292 unsigned long psr_field;
62b3e311
PB
6293 const struct asm_psr *psr;
6294 char *start;
d2cd1205 6295 bfd_boolean is_apsr = FALSE;
ac7f631b 6296 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6297
a4482bb6
NC
6298 /* PR gas/12698: If the user has specified -march=all then m_profile will
6299 be TRUE, but we want to ignore it in this case as we are building for any
6300 CPU type, including non-m variants. */
823d2571 6301 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6302 m_profile = FALSE;
6303
c19d1205
ZW
6304 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6305 feature for ease of use and backwards compatibility. */
6306 p = *str;
62b3e311 6307 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6308 {
6309 if (m_profile)
6310 goto unsupported_psr;
fa94de6b 6311
d2cd1205
JB
6312 psr_field = SPSR_BIT;
6313 }
6314 else if (strncasecmp (p, "CPSR", 4) == 0)
6315 {
6316 if (m_profile)
6317 goto unsupported_psr;
6318
6319 psr_field = 0;
6320 }
6321 else if (strncasecmp (p, "APSR", 4) == 0)
6322 {
6323 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6324 and ARMv7-R architecture CPUs. */
6325 is_apsr = TRUE;
6326 psr_field = 0;
6327 }
6328 else if (m_profile)
62b3e311
PB
6329 {
6330 start = p;
6331 do
6332 p++;
6333 while (ISALNUM (*p) || *p == '_');
6334
d2cd1205
JB
6335 if (strncasecmp (start, "iapsr", 5) == 0
6336 || strncasecmp (start, "eapsr", 5) == 0
6337 || strncasecmp (start, "xpsr", 4) == 0
6338 || strncasecmp (start, "psr", 3) == 0)
6339 p = start + strcspn (start, "rR") + 1;
6340
629310ab 6341 psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start,
fe0e921f 6342 p - start);
d2cd1205 6343
62b3e311
PB
6344 if (!psr)
6345 return FAIL;
09d92015 6346
d2cd1205
JB
6347 /* If APSR is being written, a bitfield may be specified. Note that
6348 APSR itself is handled above. */
6349 if (psr->field <= 3)
6350 {
6351 psr_field = psr->field;
6352 is_apsr = TRUE;
6353 goto check_suffix;
6354 }
6355
62b3e311 6356 *str = p;
d2cd1205
JB
6357 /* M-profile MSR instructions have the mask field set to "10", except
6358 *PSR variants which modify APSR, which may use a different mask (and
6359 have been handled already). Do that by setting the PSR_f field
6360 here. */
6361 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6362 }
d2cd1205
JB
6363 else
6364 goto unsupported_psr;
09d92015 6365
62b3e311 6366 p += 4;
dc1e8a47 6367 check_suffix:
c19d1205
ZW
6368 if (*p == '_')
6369 {
6370 /* A suffix follows. */
c19d1205
ZW
6371 p++;
6372 start = p;
a737bd4d 6373
c19d1205
ZW
6374 do
6375 p++;
6376 while (ISALNUM (*p) || *p == '_');
a737bd4d 6377
d2cd1205
JB
6378 if (is_apsr)
6379 {
6380 /* APSR uses a notation for bits, rather than fields. */
6381 unsigned int nzcvq_bits = 0;
6382 unsigned int g_bit = 0;
6383 char *bit;
fa94de6b 6384
d2cd1205
JB
6385 for (bit = start; bit != p; bit++)
6386 {
6387 switch (TOLOWER (*bit))
477330fc 6388 {
d2cd1205
JB
6389 case 'n':
6390 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6391 break;
6392
6393 case 'z':
6394 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6395 break;
6396
6397 case 'c':
6398 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6399 break;
6400
6401 case 'v':
6402 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6403 break;
fa94de6b 6404
d2cd1205
JB
6405 case 'q':
6406 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6407 break;
fa94de6b 6408
d2cd1205
JB
6409 case 'g':
6410 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6411 break;
fa94de6b 6412
d2cd1205
JB
6413 default:
6414 inst.error = _("unexpected bit specified after APSR");
6415 return FAIL;
6416 }
6417 }
fa94de6b 6418
d2cd1205
JB
6419 if (nzcvq_bits == 0x1f)
6420 psr_field |= PSR_f;
fa94de6b 6421
d2cd1205
JB
6422 if (g_bit == 0x1)
6423 {
6424 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6425 {
d2cd1205
JB
6426 inst.error = _("selected processor does not "
6427 "support DSP extension");
6428 return FAIL;
6429 }
6430
6431 psr_field |= PSR_s;
6432 }
fa94de6b 6433
d2cd1205
JB
6434 if ((nzcvq_bits & 0x20) != 0
6435 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6436 || (g_bit & 0x2) != 0)
6437 {
6438 inst.error = _("bad bitmask specified after APSR");
6439 return FAIL;
6440 }
6441 }
6442 else
477330fc 6443 {
629310ab 6444 psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start,
fe0e921f 6445 p - start);
d2cd1205 6446 if (!psr)
477330fc 6447 goto error;
a737bd4d 6448
d2cd1205
JB
6449 psr_field |= psr->field;
6450 }
a737bd4d 6451 }
c19d1205 6452 else
a737bd4d 6453 {
c19d1205
ZW
6454 if (ISALNUM (*p))
6455 goto error; /* Garbage after "[CS]PSR". */
6456
d2cd1205 6457 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6458 is deprecated, but allow it anyway. */
d2cd1205
JB
6459 if (is_apsr && lhs)
6460 {
6461 psr_field |= PSR_f;
6462 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6463 "deprecated"));
6464 }
6465 else if (!m_profile)
6466 /* These bits are never right for M-profile devices: don't set them
6467 (only code paths which read/write APSR reach here). */
6468 psr_field |= (PSR_c | PSR_f);
a737bd4d 6469 }
c19d1205
ZW
6470 *str = p;
6471 return psr_field;
a737bd4d 6472
d2cd1205
JB
6473 unsupported_psr:
6474 inst.error = _("selected processor does not support requested special "
6475 "purpose register");
6476 return FAIL;
6477
c19d1205
ZW
6478 error:
6479 inst.error = _("flag for {c}psr instruction expected");
6480 return FAIL;
a737bd4d
NC
6481}
6482
32c36c3c
AV
6483static int
6484parse_sys_vldr_vstr (char **str)
6485{
6486 unsigned i;
6487 int val = FAIL;
6488 struct {
6489 const char *name;
6490 int regl;
6491 int regh;
6492 } sysregs[] = {
6493 {"FPSCR", 0x1, 0x0},
6494 {"FPSCR_nzcvqc", 0x2, 0x0},
6495 {"VPR", 0x4, 0x1},
6496 {"P0", 0x5, 0x1},
6497 {"FPCXTNS", 0x6, 0x1},
6498 {"FPCXTS", 0x7, 0x1}
6499 };
6500 char *op_end = strchr (*str, ',');
6501 size_t op_strlen = op_end - *str;
6502
6503 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6504 {
6505 if (!strncmp (*str, sysregs[i].name, op_strlen))
6506 {
6507 val = sysregs[i].regl | (sysregs[i].regh << 3);
6508 *str = op_end;
6509 break;
6510 }
6511 }
6512
6513 return val;
6514}
6515
c19d1205
ZW
6516/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6517 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6518
c19d1205
ZW
6519static int
6520parse_cps_flags (char **str)
a737bd4d 6521{
c19d1205
ZW
6522 int val = 0;
6523 int saw_a_flag = 0;
6524 char *s = *str;
a737bd4d 6525
c19d1205
ZW
6526 for (;;)
6527 switch (*s++)
6528 {
6529 case '\0': case ',':
6530 goto done;
a737bd4d 6531
c19d1205
ZW
6532 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6533 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6534 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6535
c19d1205
ZW
6536 default:
6537 inst.error = _("unrecognized CPS flag");
6538 return FAIL;
6539 }
a737bd4d 6540
c19d1205
ZW
6541 done:
6542 if (saw_a_flag == 0)
a737bd4d 6543 {
c19d1205
ZW
6544 inst.error = _("missing CPS flags");
6545 return FAIL;
a737bd4d 6546 }
a737bd4d 6547
c19d1205
ZW
6548 *str = s - 1;
6549 return val;
a737bd4d
NC
6550}
6551
c19d1205
ZW
6552/* Parse an endian specifier ("BE" or "LE", case insensitive);
6553 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6554
6555static int
c19d1205 6556parse_endian_specifier (char **str)
a737bd4d 6557{
c19d1205
ZW
6558 int little_endian;
6559 char *s = *str;
a737bd4d 6560
c19d1205
ZW
6561 if (strncasecmp (s, "BE", 2))
6562 little_endian = 0;
6563 else if (strncasecmp (s, "LE", 2))
6564 little_endian = 1;
6565 else
a737bd4d 6566 {
c19d1205 6567 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6568 return FAIL;
6569 }
6570
c19d1205 6571 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6572 {
c19d1205 6573 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6574 return FAIL;
6575 }
6576
c19d1205
ZW
6577 *str = s + 2;
6578 return little_endian;
6579}
a737bd4d 6580
c19d1205
ZW
6581/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6582 value suitable for poking into the rotate field of an sxt or sxta
6583 instruction, or FAIL on error. */
6584
6585static int
6586parse_ror (char **str)
6587{
6588 int rot;
6589 char *s = *str;
6590
6591 if (strncasecmp (s, "ROR", 3) == 0)
6592 s += 3;
6593 else
a737bd4d 6594 {
c19d1205 6595 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6596 return FAIL;
6597 }
c19d1205
ZW
6598
6599 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6600 return FAIL;
6601
6602 switch (rot)
a737bd4d 6603 {
c19d1205
ZW
6604 case 0: *str = s; return 0x0;
6605 case 8: *str = s; return 0x1;
6606 case 16: *str = s; return 0x2;
6607 case 24: *str = s; return 0x3;
6608
6609 default:
6610 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6611 return FAIL;
6612 }
c19d1205 6613}
a737bd4d 6614
c19d1205
ZW
6615/* Parse a conditional code (from conds[] below). The value returned is in the
6616 range 0 .. 14, or FAIL. */
6617static int
6618parse_cond (char **str)
6619{
c462b453 6620 char *q;
c19d1205 6621 const struct asm_cond *c;
c462b453
PB
6622 int n;
6623 /* Condition codes are always 2 characters, so matching up to
6624 3 characters is sufficient. */
6625 char cond[3];
a737bd4d 6626
c462b453
PB
6627 q = *str;
6628 n = 0;
6629 while (ISALPHA (*q) && n < 3)
6630 {
e07e6e58 6631 cond[n] = TOLOWER (*q);
c462b453
PB
6632 q++;
6633 n++;
6634 }
a737bd4d 6635
629310ab 6636 c = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6637 if (!c)
a737bd4d 6638 {
c19d1205 6639 inst.error = _("condition required");
a737bd4d
NC
6640 return FAIL;
6641 }
6642
c19d1205
ZW
6643 *str = q;
6644 return c->value;
6645}
6646
62b3e311
PB
6647/* Parse an option for a barrier instruction. Returns the encoding for the
6648 option, or FAIL. */
6649static int
6650parse_barrier (char **str)
6651{
6652 char *p, *q;
6653 const struct asm_barrier_opt *o;
6654
6655 p = q = *str;
6656 while (ISALPHA (*q))
6657 q++;
6658
629310ab 6659 o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p,
fe0e921f 6660 q - p);
62b3e311
PB
6661 if (!o)
6662 return FAIL;
6663
e797f7e0
MGD
6664 if (!mark_feature_used (&o->arch))
6665 return FAIL;
6666
62b3e311
PB
6667 *str = q;
6668 return o->value;
6669}
6670
92e90b6e
PB
6671/* Parse the operands of a table branch instruction. Similar to a memory
6672 operand. */
6673static int
6674parse_tb (char **str)
6675{
6676 char * p = *str;
6677 int reg;
6678
6679 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6680 {
6681 inst.error = _("'[' expected");
6682 return FAIL;
6683 }
92e90b6e 6684
dcbf9037 6685 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6686 {
6687 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6688 return FAIL;
6689 }
6690 inst.operands[0].reg = reg;
6691
6692 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6693 {
6694 inst.error = _("',' expected");
6695 return FAIL;
6696 }
5f4273c7 6697
dcbf9037 6698 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6699 {
6700 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6701 return FAIL;
6702 }
6703 inst.operands[0].imm = reg;
6704
6705 if (skip_past_comma (&p) == SUCCESS)
6706 {
6707 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6708 return FAIL;
e2b0ab59 6709 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6710 {
6711 inst.error = _("invalid shift");
6712 return FAIL;
6713 }
6714 inst.operands[0].shifted = 1;
6715 }
6716
6717 if (skip_past_char (&p, ']') == FAIL)
6718 {
6719 inst.error = _("']' expected");
6720 return FAIL;
6721 }
6722 *str = p;
6723 return SUCCESS;
6724}
6725
5287ad62
JB
6726/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6727 information on the types the operands can take and how they are encoded.
037e8744
JB
6728 Up to four operands may be read; this function handles setting the
6729 ".present" field for each read operand itself.
5287ad62
JB
6730 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6731 else returns FAIL. */
6732
6733static int
6734parse_neon_mov (char **str, int *which_operand)
6735{
6736 int i = *which_operand, val;
6737 enum arm_reg_type rtype;
6738 char *ptr = *str;
dcbf9037 6739 struct neon_type_el optype;
5f4273c7 6740
57785aa2
AV
6741 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6742 {
6743 /* Cases 17 or 19. */
6744 inst.operands[i].reg = val;
6745 inst.operands[i].isvec = 1;
6746 inst.operands[i].isscalar = 2;
6747 inst.operands[i].vectype = optype;
6748 inst.operands[i++].present = 1;
6749
6750 if (skip_past_comma (&ptr) == FAIL)
6751 goto wanted_comma;
6752
6753 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6754 {
6755 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6756 inst.operands[i].reg = val;
6757 inst.operands[i].isreg = 1;
6758 inst.operands[i].present = 1;
6759 }
6760 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6761 {
6762 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6763 inst.operands[i].reg = val;
6764 inst.operands[i].isvec = 1;
6765 inst.operands[i].isscalar = 2;
6766 inst.operands[i].vectype = optype;
6767 inst.operands[i++].present = 1;
6768
6769 if (skip_past_comma (&ptr) == FAIL)
6770 goto wanted_comma;
6771
6772 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6773 goto wanted_arm;
6774
6775 inst.operands[i].reg = val;
6776 inst.operands[i].isreg = 1;
6777 inst.operands[i++].present = 1;
6778
6779 if (skip_past_comma (&ptr) == FAIL)
6780 goto wanted_comma;
6781
6782 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6783 goto wanted_arm;
6784
6785 inst.operands[i].reg = val;
6786 inst.operands[i].isreg = 1;
6787 inst.operands[i].present = 1;
6788 }
6789 else
6790 {
6791 first_error (_("expected ARM or MVE vector register"));
6792 return FAIL;
6793 }
6794 }
6795 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6796 {
6797 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6798 inst.operands[i].reg = val;
6799 inst.operands[i].isscalar = 1;
dcbf9037 6800 inst.operands[i].vectype = optype;
5287ad62
JB
6801 inst.operands[i++].present = 1;
6802
6803 if (skip_past_comma (&ptr) == FAIL)
477330fc 6804 goto wanted_comma;
5f4273c7 6805
dcbf9037 6806 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6807 goto wanted_arm;
5f4273c7 6808
5287ad62
JB
6809 inst.operands[i].reg = val;
6810 inst.operands[i].isreg = 1;
6811 inst.operands[i].present = 1;
6812 }
57785aa2
AV
6813 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6814 != FAIL)
6815 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6816 != FAIL))
5287ad62
JB
6817 {
6818 /* Cases 0, 1, 2, 3, 5 (D only). */
6819 if (skip_past_comma (&ptr) == FAIL)
477330fc 6820 goto wanted_comma;
5f4273c7 6821
5287ad62
JB
6822 inst.operands[i].reg = val;
6823 inst.operands[i].isreg = 1;
6824 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6825 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6826 inst.operands[i].isvec = 1;
dcbf9037 6827 inst.operands[i].vectype = optype;
5287ad62
JB
6828 inst.operands[i++].present = 1;
6829
dcbf9037 6830 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6831 {
6832 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6833 Case 13: VMOV <Sd>, <Rm> */
6834 inst.operands[i].reg = val;
6835 inst.operands[i].isreg = 1;
6836 inst.operands[i].present = 1;
6837
6838 if (rtype == REG_TYPE_NQ)
6839 {
6840 first_error (_("can't use Neon quad register here"));
6841 return FAIL;
6842 }
6843 else if (rtype != REG_TYPE_VFS)
6844 {
6845 i++;
6846 if (skip_past_comma (&ptr) == FAIL)
6847 goto wanted_comma;
6848 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6849 goto wanted_arm;
6850 inst.operands[i].reg = val;
6851 inst.operands[i].isreg = 1;
6852 inst.operands[i].present = 1;
6853 }
6854 }
c4a23bf8
SP
6855 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6856 &optype)) != FAIL)
6857 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6858 &optype)) != FAIL))
477330fc
RM
6859 {
6860 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6861 Case 1: VMOV<c><q> <Dd>, <Dm>
6862 Case 8: VMOV.F32 <Sd>, <Sm>
6863 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6864
6865 inst.operands[i].reg = val;
6866 inst.operands[i].isreg = 1;
6867 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6868 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6869 inst.operands[i].isvec = 1;
6870 inst.operands[i].vectype = optype;
6871 inst.operands[i].present = 1;
6872
6873 if (skip_past_comma (&ptr) == SUCCESS)
6874 {
6875 /* Case 15. */
6876 i++;
6877
6878 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6879 goto wanted_arm;
6880
6881 inst.operands[i].reg = val;
6882 inst.operands[i].isreg = 1;
6883 inst.operands[i++].present = 1;
6884
6885 if (skip_past_comma (&ptr) == FAIL)
6886 goto wanted_comma;
6887
6888 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6889 goto wanted_arm;
6890
6891 inst.operands[i].reg = val;
6892 inst.operands[i].isreg = 1;
6893 inst.operands[i].present = 1;
6894 }
6895 }
4641781c 6896 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6897 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6898 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6899 Case 10: VMOV.F32 <Sd>, #<imm>
6900 Case 11: VMOV.F64 <Dd>, #<imm> */
6901 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6902 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6903 == SUCCESS)
477330fc
RM
6904 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6905 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6906 ;
5287ad62 6907 else
477330fc
RM
6908 {
6909 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6910 return FAIL;
6911 }
5287ad62 6912 }
dcbf9037 6913 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6914 {
57785aa2 6915 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6916 inst.operands[i].reg = val;
6917 inst.operands[i].isreg = 1;
6918 inst.operands[i++].present = 1;
5f4273c7 6919
5287ad62 6920 if (skip_past_comma (&ptr) == FAIL)
477330fc 6921 goto wanted_comma;
5f4273c7 6922
57785aa2
AV
6923 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6924 {
6925 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6926 inst.operands[i].reg = val;
6927 inst.operands[i].isscalar = 2;
6928 inst.operands[i].present = 1;
6929 inst.operands[i].vectype = optype;
6930 }
6931 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6932 {
6933 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6934 inst.operands[i].reg = val;
6935 inst.operands[i].isscalar = 1;
6936 inst.operands[i].present = 1;
6937 inst.operands[i].vectype = optype;
6938 }
dcbf9037 6939 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6940 {
477330fc
RM
6941 inst.operands[i].reg = val;
6942 inst.operands[i].isreg = 1;
6943 inst.operands[i++].present = 1;
6944
6945 if (skip_past_comma (&ptr) == FAIL)
6946 goto wanted_comma;
6947
6948 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6949 != FAIL)
477330fc 6950 {
57785aa2 6951 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6952
477330fc
RM
6953 inst.operands[i].reg = val;
6954 inst.operands[i].isreg = 1;
6955 inst.operands[i].isvec = 1;
57785aa2 6956 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6957 inst.operands[i].vectype = optype;
6958 inst.operands[i].present = 1;
57785aa2
AV
6959
6960 if (rtype == REG_TYPE_VFS)
6961 {
6962 /* Case 14. */
6963 i++;
6964 if (skip_past_comma (&ptr) == FAIL)
6965 goto wanted_comma;
6966 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6967 &optype)) == FAIL)
6968 {
6969 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6970 return FAIL;
6971 }
6972 inst.operands[i].reg = val;
6973 inst.operands[i].isreg = 1;
6974 inst.operands[i].isvec = 1;
6975 inst.operands[i].issingle = 1;
6976 inst.operands[i].vectype = optype;
6977 inst.operands[i].present = 1;
6978 }
6979 }
6980 else
6981 {
6982 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6983 != FAIL)
6984 {
6985 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6986 inst.operands[i].reg = val;
6987 inst.operands[i].isvec = 1;
6988 inst.operands[i].isscalar = 2;
6989 inst.operands[i].vectype = optype;
6990 inst.operands[i++].present = 1;
6991
6992 if (skip_past_comma (&ptr) == FAIL)
6993 goto wanted_comma;
6994
6995 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6996 == FAIL)
6997 {
6998 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6999 return FAIL;
7000 }
7001 inst.operands[i].reg = val;
7002 inst.operands[i].isvec = 1;
7003 inst.operands[i].isscalar = 2;
7004 inst.operands[i].vectype = optype;
7005 inst.operands[i].present = 1;
7006 }
7007 else
7008 {
7009 first_error (_("VFP single, double or MVE vector register"
7010 " expected"));
7011 return FAIL;
7012 }
477330fc
RM
7013 }
7014 }
037e8744 7015 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
7016 != FAIL)
7017 {
7018 /* Case 13. */
7019 inst.operands[i].reg = val;
7020 inst.operands[i].isreg = 1;
7021 inst.operands[i].isvec = 1;
7022 inst.operands[i].issingle = 1;
7023 inst.operands[i].vectype = optype;
7024 inst.operands[i].present = 1;
7025 }
5287ad62
JB
7026 }
7027 else
7028 {
dcbf9037 7029 first_error (_("parse error"));
5287ad62
JB
7030 return FAIL;
7031 }
7032
7033 /* Successfully parsed the operands. Update args. */
7034 *which_operand = i;
7035 *str = ptr;
7036 return SUCCESS;
7037
5f4273c7 7038 wanted_comma:
dcbf9037 7039 first_error (_("expected comma"));
5287ad62 7040 return FAIL;
5f4273c7
NC
7041
7042 wanted_arm:
dcbf9037 7043 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 7044 return FAIL;
5287ad62
JB
7045}
7046
5be8be5d
DG
7047/* Use this macro when the operand constraints are different
7048 for ARM and THUMB (e.g. ldrd). */
7049#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7050 ((arm_operand) | ((thumb_operand) << 16))
7051
c19d1205
ZW
7052/* Matcher codes for parse_operands. */
7053enum operand_parse_code
7054{
7055 OP_stop, /* end of line */
7056
7057 OP_RR, /* ARM register */
7058 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 7059 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 7060 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 7061 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 7062 optional trailing ! */
c19d1205
ZW
7063 OP_RRw, /* ARM register, not r15, optional trailing ! */
7064 OP_RCP, /* Coprocessor number */
7065 OP_RCN, /* Coprocessor register */
7066 OP_RF, /* FPA register */
7067 OP_RVS, /* VFP single precision register */
5287ad62
JB
7068 OP_RVD, /* VFP double precision register (0..15) */
7069 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
7070 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7071 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7072 */
66d1f7cc
AV
7073 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7074 */
5287ad62 7075 OP_RNQ, /* Neon quad precision register */
5ee91343 7076 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 7077 OP_RVSD, /* VFP single or double precision register */
1b883319 7078 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 7079 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 7080 OP_RNSD, /* Neon single or double precision register */
5287ad62 7081 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 7082 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 7083 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 7084 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 7085 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
7086 OP_RVC, /* VFP control register */
7087 OP_RMF, /* Maverick F register */
7088 OP_RMD, /* Maverick D register */
7089 OP_RMFX, /* Maverick FX register */
7090 OP_RMDX, /* Maverick DX register */
7091 OP_RMAX, /* Maverick AX register */
7092 OP_RMDS, /* Maverick DSPSC register */
7093 OP_RIWR, /* iWMMXt wR register */
7094 OP_RIWC, /* iWMMXt wC register */
7095 OP_RIWG, /* iWMMXt wCG register */
7096 OP_RXA, /* XScale accumulator register */
7097
5aae9ae9 7098 OP_RNSDMQ, /* Neon single, double or MVE vector register */
5ee91343
AV
7099 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7100 */
7101 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7102 GPR (no SP/SP) */
a302e574 7103 OP_RMQ, /* MVE vector register. */
1b883319 7104 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 7105 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 7106
60f993ce
AV
7107 /* New operands for Armv8.1-M Mainline. */
7108 OP_LR, /* ARM LR register */
a302e574
AV
7109 OP_RRe, /* ARM register, only even numbered. */
7110 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7111 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7112 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7113
c19d1205 7114 OP_REGLST, /* ARM register list */
4b5a202f 7115 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7116 OP_VRSLST, /* VFP single-precision register list */
7117 OP_VRDLST, /* VFP double-precision register list */
037e8744 7118 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7119 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7120 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7121 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7122 OP_MSTRLST2, /* MVE vector list with two elements. */
7123 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7124
5287ad62 7125 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7126 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7127 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7128 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7129 zero. */
5287ad62 7130 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7131 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7132 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7133 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7134 */
a8465a06
AV
7135 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7136 scalar, or ARM register. */
5287ad62 7137 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7138 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7139 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7140 register. */
5d281bf0 7141 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7142 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7143 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7144 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7145 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7146 OP_RNDQMQ_Ibig,
5287ad62 7147 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7148 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7149 ARM register. */
2d447fca 7150 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7151 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7152
7153 OP_I0, /* immediate zero */
c19d1205
ZW
7154 OP_I7, /* immediate value 0 .. 7 */
7155 OP_I15, /* 0 .. 15 */
7156 OP_I16, /* 1 .. 16 */
5287ad62 7157 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7158 OP_I31, /* 0 .. 31 */
7159 OP_I31w, /* 0 .. 31, optional trailing ! */
7160 OP_I32, /* 1 .. 32 */
5287ad62 7161 OP_I32z, /* 0 .. 32 */
08132bdd 7162 OP_I48_I64, /* 48 or 64 */
5287ad62 7163 OP_I63, /* 0 .. 63 */
c19d1205 7164 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7165 OP_I64, /* 1 .. 64 */
7166 OP_I64z, /* 0 .. 64 */
5aae9ae9 7167 OP_I127, /* 0 .. 127 */
c19d1205 7168 OP_I255, /* 0 .. 255 */
4934a27c 7169 OP_I511, /* 0 .. 511 */
5aae9ae9 7170 OP_I4095, /* 0 .. 4095 */
4934a27c 7171 OP_I8191, /* 0 .. 8191 */
c19d1205
ZW
7172 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7173 OP_I7b, /* 0 .. 7 */
7174 OP_I15b, /* 0 .. 15 */
7175 OP_I31b, /* 0 .. 31 */
7176
7177 OP_SH, /* shifter operand */
4962c51a 7178 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7179 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7180 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7181 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7182 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7183 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7184 OP_EXP, /* arbitrary expression */
7185 OP_EXPi, /* same, with optional immediate prefix */
7186 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7187 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7188 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7189 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7190 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7191
7192 OP_CPSF, /* CPS flags */
7193 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7194 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7195 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7196 OP_COND, /* conditional code */
92e90b6e 7197 OP_TB, /* Table branch. */
c19d1205 7198
037e8744
JB
7199 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7200
c19d1205 7201 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7202 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7203 OP_RR_EXi, /* ARM register or expression with imm prefix */
7204 OP_RF_IF, /* FPA register or immediate */
7205 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7206 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7207
7208 /* Optional operands. */
7209 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7210 OP_oI31b, /* 0 .. 31 */
5287ad62 7211 OP_oI32b, /* 1 .. 32 */
5f1af56b 7212 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7213 OP_oIffffb, /* 0 .. 65535 */
7214 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7215
7216 OP_oRR, /* ARM register */
60f993ce 7217 OP_oLR, /* ARM LR register */
c19d1205 7218 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7219 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7220 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7221 OP_oRND, /* Optional Neon double precision register */
7222 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7223 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7224 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7225 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7226 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7227 register. */
66d1f7cc
AV
7228 OP_oRNSDMQ, /* Optional single, double 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:
66d1f7cc
AV
7426 case OP_RNSDMQR:
7427 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7428 break;
7429 try_rndmqr:
5ee91343
AV
7430 case OP_RNDMQR:
7431 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7432 break;
7433 try_rndmq:
7434 case OP_RNDMQ:
7435 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7436 break;
7437 try_rnd:
5287ad62 7438 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7439 case OP_RVC:
7440 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7441 break;
7442 /* Also accept generic coprocessor regs for unknown registers. */
7443 coproc_reg:
ba6cd17f
SD
7444 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7445 break;
7446 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7447 existing register with a value of 0, this seems like the
7448 best way to parse P0. */
7449 vpr_po:
7450 if (strncasecmp (str, "P0", 2) == 0)
7451 {
7452 str += 2;
7453 inst.operands[i].isreg = 1;
7454 inst.operands[i].reg = 13;
7455 }
7456 else
7457 goto failure;
cd2cf30b 7458 break;
c19d1205
ZW
7459 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7460 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7461 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7462 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7463 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7464 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7465 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7466 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7467 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7468 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7469 case OP_oRNQ:
5ee91343
AV
7470 case OP_RNQMQ:
7471 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7472 break;
7473 try_nq:
5287ad62 7474 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7475 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7476 case OP_RNDQMQR:
7477 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7478 break;
7479 try_rndqmq:
5ee91343
AV
7480 case OP_oRNDQMQ:
7481 case OP_RNDQMQ:
7482 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7483 break;
7484 try_rndq:
477330fc 7485 case OP_oRNDQ:
5287ad62 7486 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7487 case OP_RVSDMQ:
7488 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7489 break;
7490 try_rvsd:
477330fc 7491 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7492 case OP_RVSD_COND:
7493 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7494 break;
66d1f7cc 7495 case OP_oRNSDMQ:
5aae9ae9
MM
7496 case OP_RNSDMQ:
7497 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7498 break;
7499 try_mq2:
7500 po_reg_or_fail (REG_TYPE_MQ);
7501 break;
477330fc
RM
7502 case OP_oRNSDQ:
7503 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7504 case OP_RNSDQMQR:
7505 po_reg_or_goto (REG_TYPE_RN, try_mq);
7506 break;
7507 try_mq:
7508 case OP_oRNSDQMQ:
7509 case OP_RNSDQMQ:
7510 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7511 break;
7512 try_nsdq2:
7513 po_reg_or_fail (REG_TYPE_NSDQ);
7514 inst.error = 0;
7515 break;
35d1cfc2
AV
7516 case OP_RMQRR:
7517 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7518 break;
7519 try_rmq:
a302e574
AV
7520 case OP_RMQ:
7521 po_reg_or_fail (REG_TYPE_MQ);
7522 break;
477330fc
RM
7523 /* Neon scalar. Using an element size of 8 means that some invalid
7524 scalars are accepted here, so deal with those in later code. */
57785aa2 7525 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7526
7527 case OP_RNDQ_I0:
7528 {
7529 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7530 break;
7531 try_imm0:
7532 po_imm_or_fail (0, 0, TRUE);
7533 }
7534 break;
7535
7536 case OP_RVSD_I0:
7537 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7538 break;
7539
1b883319
AV
7540 case OP_RSVDMQ_FI0:
7541 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7542 break;
7543 try_rsvd_fi0:
aacf0b33
KT
7544 case OP_RSVD_FI0:
7545 {
7546 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7547 break;
7548 try_ifimm0:
7549 if (parse_ifimm_zero (&str))
7550 inst.operands[i].imm = 0;
7551 else
7552 {
7553 inst.error
7554 = _("only floating point zero is allowed as immediate value");
7555 goto failure;
7556 }
7557 }
7558 break;
7559
477330fc
RM
7560 case OP_RR_RNSC:
7561 {
57785aa2 7562 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7563 break;
7564 try_rr:
7565 po_reg_or_fail (REG_TYPE_RN);
7566 }
7567 break;
7568
a8465a06
AV
7569 case OP_RNSDQ_RNSC_MQ_RR:
7570 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7571 break;
7572 try_rnsdq_rnsc_mq:
886e1c73
AV
7573 case OP_RNSDQ_RNSC_MQ:
7574 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7575 break;
7576 try_rnsdq_rnsc:
477330fc
RM
7577 case OP_RNSDQ_RNSC:
7578 {
57785aa2
AV
7579 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7580 inst.error = 0;
477330fc
RM
7581 break;
7582 try_nsdq:
7583 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7584 inst.error = 0;
477330fc
RM
7585 }
7586 break;
7587
dec41383
JW
7588 case OP_RNSD_RNSC:
7589 {
57785aa2 7590 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7591 break;
7592 try_s_scalar:
57785aa2 7593 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7594 break;
7595 try_nsd:
7596 po_reg_or_fail (REG_TYPE_NSD);
7597 }
7598 break;
7599
42b16635
AV
7600 case OP_RNDQMQ_RNSC_RR:
7601 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7602 break;
7603 try_rndq_rnsc_rr:
7604 case OP_RNDQ_RNSC_RR:
7605 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7606 break;
5d281bf0
AV
7607 case OP_RNDQMQ_RNSC:
7608 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7609 break;
7610 try_rndq_rnsc:
477330fc
RM
7611 case OP_RNDQ_RNSC:
7612 {
57785aa2 7613 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7614 break;
7615 try_ndq:
7616 po_reg_or_fail (REG_TYPE_NDQ);
7617 }
7618 break;
7619
7620 case OP_RND_RNSC:
7621 {
57785aa2 7622 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7623 break;
7624 try_vfd:
7625 po_reg_or_fail (REG_TYPE_VFD);
7626 }
7627 break;
7628
7629 case OP_VMOV:
7630 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7631 not careful then bad things might happen. */
7632 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7633 break;
7634
f601a00c
AV
7635 case OP_RNDQMQ_Ibig:
7636 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7637 break;
7638 try_rndq_ibig:
477330fc
RM
7639 case OP_RNDQ_Ibig:
7640 {
7641 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7642 break;
7643 try_immbig:
7644 /* There's a possibility of getting a 64-bit immediate here, so
7645 we need special handling. */
8335d6aa
JW
7646 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7647 == FAIL)
477330fc
RM
7648 {
7649 inst.error = _("immediate value is out of range");
7650 goto failure;
7651 }
7652 }
7653 break;
7654
5150f0d8
AV
7655 case OP_RNDQMQ_I63b_RR:
7656 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7657 break;
7658 try_rndq_i63b_rr:
7659 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7660 break;
7661 try_rndq_i63b:
477330fc
RM
7662 case OP_RNDQ_I63b:
7663 {
7664 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7665 break;
7666 try_shimm:
7667 po_imm_or_fail (0, 63, TRUE);
7668 }
7669 break;
c19d1205
ZW
7670
7671 case OP_RRnpcb:
7672 po_char_or_fail ('[');
7673 po_reg_or_fail (REG_TYPE_RN);
7674 po_char_or_fail (']');
7675 break;
a737bd4d 7676
55881a11 7677 case OP_RRnpctw:
c19d1205 7678 case OP_RRw:
b6702015 7679 case OP_oRRw:
c19d1205
ZW
7680 po_reg_or_fail (REG_TYPE_RN);
7681 if (skip_past_char (&str, '!') == SUCCESS)
7682 inst.operands[i].writeback = 1;
7683 break;
7684
7685 /* Immediates */
7686 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7687 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7688 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7689 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7690 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7691 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7692 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
08132bdd 7693 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
c19d1205 7694 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7695 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7696 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7697 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5aae9ae9 7698 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
c19d1205 7699 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
4934a27c 7700 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
5aae9ae9 7701 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
4934a27c 7702 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
c19d1205
ZW
7703 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7704 case OP_oI7b:
7705 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7706 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7707 case OP_oI31b:
7708 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7709 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7710 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7711 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7712
7713 /* Immediate variants */
7714 case OP_oI255c:
7715 po_char_or_fail ('{');
7716 po_imm_or_fail (0, 255, TRUE);
7717 po_char_or_fail ('}');
7718 break;
7719
7720 case OP_I31w:
7721 /* The expression parser chokes on a trailing !, so we have
7722 to find it first and zap it. */
7723 {
7724 char *s = str;
7725 while (*s && *s != ',')
7726 s++;
7727 if (s[-1] == '!')
7728 {
7729 s[-1] = '\0';
7730 inst.operands[i].writeback = 1;
7731 }
7732 po_imm_or_fail (0, 31, TRUE);
7733 if (str == s - 1)
7734 str = s;
7735 }
7736 break;
7737
7738 /* Expressions */
7739 case OP_EXPi: EXPi:
e2b0ab59 7740 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7741 GE_OPT_PREFIX));
7742 break;
7743
7744 case OP_EXP:
e2b0ab59 7745 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7746 GE_NO_PREFIX));
7747 break;
7748
7749 case OP_EXPr: EXPr:
e2b0ab59 7750 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7751 GE_NO_PREFIX));
e2b0ab59 7752 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7753 {
c19d1205
ZW
7754 val = parse_reloc (&str);
7755 if (val == -1)
7756 {
7757 inst.error = _("unrecognized relocation suffix");
7758 goto failure;
7759 }
7760 else if (val != BFD_RELOC_UNUSED)
7761 {
7762 inst.operands[i].imm = val;
7763 inst.operands[i].hasreloc = 1;
7764 }
a737bd4d 7765 }
c19d1205 7766 break;
a737bd4d 7767
e2b0ab59
AV
7768 case OP_EXPs:
7769 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7770 GE_NO_PREFIX));
7771 if (inst.relocs[i].exp.X_op == O_symbol)
7772 {
7773 inst.operands[i].hasreloc = 1;
7774 }
7775 else if (inst.relocs[i].exp.X_op == O_constant)
7776 {
7777 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7778 inst.operands[i].hasreloc = 0;
7779 }
7780 break;
7781
b6895b4f
PB
7782 /* Operand for MOVW or MOVT. */
7783 case OP_HALF:
7784 po_misc_or_fail (parse_half (&str));
7785 break;
7786
e07e6e58 7787 /* Register or expression. */
c19d1205
ZW
7788 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7789 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7790
e07e6e58 7791 /* Register or immediate. */
c19d1205
ZW
7792 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7793 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7794
23d00a41
SD
7795 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7796 I32: po_imm_or_fail (1, 32, FALSE); break;
7797
c19d1205
ZW
7798 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7799 IF:
7800 if (!is_immediate_prefix (*str))
7801 goto bad_args;
7802 str++;
7803 val = parse_fpa_immediate (&str);
7804 if (val == FAIL)
7805 goto failure;
7806 /* FPA immediates are encoded as registers 8-15.
7807 parse_fpa_immediate has already applied the offset. */
7808 inst.operands[i].reg = val;
7809 inst.operands[i].isreg = 1;
7810 break;
09d92015 7811
2d447fca
JM
7812 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7813 I32z: po_imm_or_fail (0, 32, FALSE); break;
7814
e07e6e58 7815 /* Two kinds of register. */
c19d1205
ZW
7816 case OP_RIWR_RIWC:
7817 {
7818 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7819 if (!rege
7820 || (rege->type != REG_TYPE_MMXWR
7821 && rege->type != REG_TYPE_MMXWC
7822 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7823 {
7824 inst.error = _("iWMMXt data or control register expected");
7825 goto failure;
7826 }
7827 inst.operands[i].reg = rege->number;
7828 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7829 }
7830 break;
09d92015 7831
41adaa5c
JM
7832 case OP_RIWC_RIWG:
7833 {
7834 struct reg_entry *rege = arm_reg_parse_multi (&str);
7835 if (!rege
7836 || (rege->type != REG_TYPE_MMXWC
7837 && rege->type != REG_TYPE_MMXWCG))
7838 {
7839 inst.error = _("iWMMXt control register expected");
7840 goto failure;
7841 }
7842 inst.operands[i].reg = rege->number;
7843 inst.operands[i].isreg = 1;
7844 }
7845 break;
7846
c19d1205
ZW
7847 /* Misc */
7848 case OP_CPSF: val = parse_cps_flags (&str); break;
7849 case OP_ENDI: val = parse_endian_specifier (&str); break;
7850 case OP_oROR: val = parse_ror (&str); break;
1b883319 7851 try_cond:
c19d1205 7852 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7853 case OP_oBARRIER_I15:
7854 po_barrier_or_imm (str); break;
7855 immediate:
7856 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7857 goto failure;
52e7f43d 7858 break;
c19d1205 7859
fa94de6b 7860 case OP_wPSR:
d2cd1205 7861 case OP_rPSR:
90ec0d68
MGD
7862 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7863 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7864 {
7865 inst.error = _("Banked registers are not available with this "
7866 "architecture.");
7867 goto failure;
7868 }
7869 break;
d2cd1205
JB
7870 try_psr:
7871 val = parse_psr (&str, op_parse_code == OP_wPSR);
7872 break;
037e8744 7873
32c36c3c
AV
7874 case OP_VLDR:
7875 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7876 break;
7877 try_sysreg:
7878 val = parse_sys_vldr_vstr (&str);
7879 break;
7880
477330fc
RM
7881 case OP_APSR_RR:
7882 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7883 break;
7884 try_apsr:
7885 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7886 instruction). */
7887 if (strncasecmp (str, "APSR_", 5) == 0)
7888 {
7889 unsigned found = 0;
7890 str += 5;
7891 while (found < 15)
7892 switch (*str++)
7893 {
7894 case 'c': found = (found & 1) ? 16 : found | 1; break;
7895 case 'n': found = (found & 2) ? 16 : found | 2; break;
7896 case 'z': found = (found & 4) ? 16 : found | 4; break;
7897 case 'v': found = (found & 8) ? 16 : found | 8; break;
7898 default: found = 16;
7899 }
7900 if (found != 15)
7901 goto failure;
7902 inst.operands[i].isvec = 1;
f7c21dc7
NC
7903 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7904 inst.operands[i].reg = REG_PC;
477330fc
RM
7905 }
7906 else
7907 goto failure;
7908 break;
037e8744 7909
92e90b6e
PB
7910 case OP_TB:
7911 po_misc_or_fail (parse_tb (&str));
7912 break;
7913
e07e6e58 7914 /* Register lists. */
c19d1205 7915 case OP_REGLST:
4b5a202f 7916 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7917 if (*str == '^')
7918 {
5e0d7f77 7919 inst.operands[i].writeback = 1;
c19d1205
ZW
7920 str++;
7921 }
7922 break;
09d92015 7923
4b5a202f
AV
7924 case OP_CLRMLST:
7925 val = parse_reg_list (&str, REGLIST_CLRM);
7926 break;
7927
c19d1205 7928 case OP_VRSLST:
efd6b359
AV
7929 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7930 &partial_match);
c19d1205 7931 break;
09d92015 7932
c19d1205 7933 case OP_VRDLST:
efd6b359
AV
7934 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7935 &partial_match);
c19d1205 7936 break;
a737bd4d 7937
477330fc
RM
7938 case OP_VRSDLST:
7939 /* Allow Q registers too. */
7940 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7941 REGLIST_NEON_D, &partial_match);
477330fc
RM
7942 if (val == FAIL)
7943 {
7944 inst.error = NULL;
7945 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7946 REGLIST_VFP_S, &partial_match);
7947 inst.operands[i].issingle = 1;
7948 }
7949 break;
7950
7951 case OP_VRSDVLST:
7952 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7953 REGLIST_VFP_D_VPR, &partial_match);
7954 if (val == FAIL && !partial_match)
7955 {
7956 inst.error = NULL;
7957 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7958 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7959 inst.operands[i].issingle = 1;
7960 }
7961 break;
7962
7963 case OP_NRDLST:
7964 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7965 REGLIST_NEON_D, &partial_match);
477330fc 7966 break;
5287ad62 7967
35c228db
AV
7968 case OP_MSTRLST4:
7969 case OP_MSTRLST2:
7970 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7971 1, &inst.operands[i].vectype);
7972 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7973 goto failure;
7974 break;
5287ad62 7975 case OP_NSTRLST:
477330fc 7976 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7977 0, &inst.operands[i].vectype);
477330fc 7978 break;
5287ad62 7979
c19d1205 7980 /* Addressing modes */
35c228db
AV
7981 case OP_ADDRMVE:
7982 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7983 break;
7984
c19d1205
ZW
7985 case OP_ADDR:
7986 po_misc_or_fail (parse_address (&str, i));
7987 break;
09d92015 7988
4962c51a
MS
7989 case OP_ADDRGLDR:
7990 po_misc_or_fail_no_backtrack (
477330fc 7991 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7992 break;
7993
7994 case OP_ADDRGLDRS:
7995 po_misc_or_fail_no_backtrack (
477330fc 7996 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7997 break;
7998
7999 case OP_ADDRGLDC:
8000 po_misc_or_fail_no_backtrack (
477330fc 8001 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
8002 break;
8003
c19d1205
ZW
8004 case OP_SH:
8005 po_misc_or_fail (parse_shifter_operand (&str, i));
8006 break;
09d92015 8007
4962c51a
MS
8008 case OP_SHG:
8009 po_misc_or_fail_no_backtrack (
477330fc 8010 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
8011 break;
8012
c19d1205
ZW
8013 case OP_oSHll:
8014 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8015 break;
09d92015 8016
c19d1205
ZW
8017 case OP_oSHar:
8018 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8019 break;
09d92015 8020
c19d1205
ZW
8021 case OP_oSHllar:
8022 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8023 break;
09d92015 8024
1b883319
AV
8025 case OP_RMQRZ:
8026 case OP_oRMQRZ:
8027 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8028 break;
e39c1607
SD
8029
8030 case OP_RR_ZR:
1b883319
AV
8031 try_rr_zr:
8032 po_reg_or_goto (REG_TYPE_RN, ZR);
8033 break;
8034 ZR:
8035 po_reg_or_fail (REG_TYPE_ZR);
8036 break;
8037
c19d1205 8038 default:
5be8be5d 8039 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 8040 }
09d92015 8041
c19d1205
ZW
8042 /* Various value-based sanity checks and shared operations. We
8043 do not signal immediate failures for the register constraints;
8044 this allows a syntax error to take precedence. */
5be8be5d 8045 switch (op_parse_code)
c19d1205
ZW
8046 {
8047 case OP_oRRnpc:
8048 case OP_RRnpc:
8049 case OP_RRnpcb:
8050 case OP_RRw:
b6702015 8051 case OP_oRRw:
c19d1205
ZW
8052 case OP_RRnpc_I0:
8053 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8054 inst.error = BAD_PC;
8055 break;
09d92015 8056
5be8be5d
DG
8057 case OP_oRRnpcsp:
8058 case OP_RRnpcsp:
23d00a41 8059 case OP_RRnpcsp_I32:
5be8be5d
DG
8060 if (inst.operands[i].isreg)
8061 {
8062 if (inst.operands[i].reg == REG_PC)
8063 inst.error = BAD_PC;
5c8ed6a4
JW
8064 else if (inst.operands[i].reg == REG_SP
8065 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8066 relaxed since ARMv8-A. */
8067 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8068 {
8069 gas_assert (thumb);
8070 inst.error = BAD_SP;
8071 }
5be8be5d
DG
8072 }
8073 break;
8074
55881a11 8075 case OP_RRnpctw:
fa94de6b
RM
8076 if (inst.operands[i].isreg
8077 && inst.operands[i].reg == REG_PC
55881a11
MGD
8078 && (inst.operands[i].writeback || thumb))
8079 inst.error = BAD_PC;
8080 break;
8081
1b883319 8082 case OP_RVSD_COND:
32c36c3c
AV
8083 case OP_VLDR:
8084 if (inst.operands[i].isreg)
8085 break;
8086 /* fall through. */
1b883319 8087
c19d1205
ZW
8088 case OP_CPSF:
8089 case OP_ENDI:
8090 case OP_oROR:
d2cd1205
JB
8091 case OP_wPSR:
8092 case OP_rPSR:
c19d1205 8093 case OP_COND:
52e7f43d 8094 case OP_oBARRIER_I15:
c19d1205 8095 case OP_REGLST:
4b5a202f 8096 case OP_CLRMLST:
c19d1205
ZW
8097 case OP_VRSLST:
8098 case OP_VRDLST:
477330fc 8099 case OP_VRSDLST:
efd6b359 8100 case OP_VRSDVLST:
477330fc
RM
8101 case OP_NRDLST:
8102 case OP_NSTRLST:
35c228db
AV
8103 case OP_MSTRLST2:
8104 case OP_MSTRLST4:
c19d1205
ZW
8105 if (val == FAIL)
8106 goto failure;
8107 inst.operands[i].imm = val;
8108 break;
a737bd4d 8109
60f993ce
AV
8110 case OP_LR:
8111 case OP_oLR:
8112 if (inst.operands[i].reg != REG_LR)
8113 inst.error = _("operand must be LR register");
8114 break;
8115
1b883319
AV
8116 case OP_RMQRZ:
8117 case OP_oRMQRZ:
e39c1607 8118 case OP_RR_ZR:
1b883319
AV
8119 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8120 inst.error = BAD_PC;
8121 break;
8122
a302e574
AV
8123 case OP_RRe:
8124 if (inst.operands[i].isreg
8125 && (inst.operands[i].reg & 0x00000001) != 0)
8126 inst.error = BAD_ODD;
8127 break;
8128
8129 case OP_RRo:
8130 if (inst.operands[i].isreg)
8131 {
8132 if ((inst.operands[i].reg & 0x00000001) != 1)
8133 inst.error = BAD_EVEN;
8134 else if (inst.operands[i].reg == REG_SP)
8135 as_tsktsk (MVE_BAD_SP);
8136 else if (inst.operands[i].reg == REG_PC)
8137 inst.error = BAD_PC;
8138 }
8139 break;
8140
c19d1205
ZW
8141 default:
8142 break;
8143 }
09d92015 8144
c19d1205
ZW
8145 /* If we get here, this operand was successfully parsed. */
8146 inst.operands[i].present = 1;
8147 continue;
09d92015 8148
c19d1205 8149 bad_args:
09d92015 8150 inst.error = BAD_ARGS;
c19d1205
ZW
8151
8152 failure:
8153 if (!backtrack_pos)
d252fdde
PB
8154 {
8155 /* The parse routine should already have set inst.error, but set a
5f4273c7 8156 default here just in case. */
d252fdde 8157 if (!inst.error)
5ee91343 8158 inst.error = BAD_SYNTAX;
d252fdde
PB
8159 return FAIL;
8160 }
c19d1205
ZW
8161
8162 /* Do not backtrack over a trailing optional argument that
8163 absorbed some text. We will only fail again, with the
8164 'garbage following instruction' error message, which is
8165 probably less helpful than the current one. */
8166 if (backtrack_index == i && backtrack_pos != str
8167 && upat[i+1] == OP_stop)
d252fdde
PB
8168 {
8169 if (!inst.error)
5ee91343 8170 inst.error = BAD_SYNTAX;
d252fdde
PB
8171 return FAIL;
8172 }
c19d1205
ZW
8173
8174 /* Try again, skipping the optional argument at backtrack_pos. */
8175 str = backtrack_pos;
8176 inst.error = backtrack_error;
8177 inst.operands[backtrack_index].present = 0;
8178 i = backtrack_index;
8179 backtrack_pos = 0;
09d92015 8180 }
09d92015 8181
c19d1205
ZW
8182 /* Check that we have parsed all the arguments. */
8183 if (*str != '\0' && !inst.error)
8184 inst.error = _("garbage following instruction");
09d92015 8185
c19d1205 8186 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8187}
8188
c19d1205
ZW
8189#undef po_char_or_fail
8190#undef po_reg_or_fail
8191#undef po_reg_or_goto
8192#undef po_imm_or_fail
5287ad62 8193#undef po_scalar_or_fail
52e7f43d 8194#undef po_barrier_or_imm
e07e6e58 8195
c19d1205 8196/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8197#define constraint(expr, err) \
8198 do \
c19d1205 8199 { \
e07e6e58
NC
8200 if (expr) \
8201 { \
8202 inst.error = err; \
8203 return; \
8204 } \
c19d1205 8205 } \
e07e6e58 8206 while (0)
c19d1205 8207
fdfde340
JM
8208/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8209 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8210 is the BadReg predicate in ARM's Thumb-2 documentation.
8211
8212 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8213 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8214#define reject_bad_reg(reg) \
8215 do \
8216 if (reg == REG_PC) \
8217 { \
8218 inst.error = BAD_PC; \
8219 return; \
8220 } \
8221 else if (reg == REG_SP \
8222 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8223 { \
8224 inst.error = BAD_SP; \
8225 return; \
8226 } \
fdfde340
JM
8227 while (0)
8228
94206790
MM
8229/* If REG is R13 (the stack pointer), warn that its use is
8230 deprecated. */
8231#define warn_deprecated_sp(reg) \
8232 do \
8233 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8234 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8235 while (0)
8236
c19d1205
ZW
8237/* Functions for operand encoding. ARM, then Thumb. */
8238
d840c081 8239#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8240
9db2f6b4
RL
8241/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8242
8243 The only binary encoding difference is the Coprocessor number. Coprocessor
8244 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8245 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8246 exists for Single-Precision operation. */
8247
8248static void
8249do_scalar_fp16_v82_encode (void)
8250{
5ee91343 8251 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8252 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8253 " the behaviour is UNPREDICTABLE"));
8254 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8255 _(BAD_FP16));
8256
8257 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8258 mark_feature_used (&arm_ext_fp16);
8259}
8260
c19d1205
ZW
8261/* If VAL can be encoded in the immediate field of an ARM instruction,
8262 return the encoded form. Otherwise, return FAIL. */
8263
8264static unsigned int
8265encode_arm_immediate (unsigned int val)
09d92015 8266{
c19d1205
ZW
8267 unsigned int a, i;
8268
4f1d6205
L
8269 if (val <= 0xff)
8270 return val;
8271
8272 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8273 if ((a = rotate_left (val, i)) <= 0xff)
8274 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8275
8276 return FAIL;
09d92015
MM
8277}
8278
c19d1205
ZW
8279/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8280 return the encoded form. Otherwise, return FAIL. */
8281static unsigned int
8282encode_thumb32_immediate (unsigned int val)
09d92015 8283{
c19d1205 8284 unsigned int a, i;
09d92015 8285
9c3c69f2 8286 if (val <= 0xff)
c19d1205 8287 return val;
a737bd4d 8288
9c3c69f2 8289 for (i = 1; i <= 24; i++)
09d92015 8290 {
9c3c69f2 8291 a = val >> i;
7af67752 8292 if ((val & ~(0xffU << i)) == 0)
9c3c69f2 8293 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8294 }
a737bd4d 8295
c19d1205
ZW
8296 a = val & 0xff;
8297 if (val == ((a << 16) | a))
8298 return 0x100 | a;
8299 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8300 return 0x300 | a;
09d92015 8301
c19d1205
ZW
8302 a = val & 0xff00;
8303 if (val == ((a << 16) | a))
8304 return 0x200 | (a >> 8);
a737bd4d 8305
c19d1205 8306 return FAIL;
09d92015 8307}
5287ad62 8308/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8309
8310static void
5287ad62
JB
8311encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8312{
8313 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8314 && reg > 15)
8315 {
b1cc4aeb 8316 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8317 {
8318 if (thumb_mode)
8319 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8320 fpu_vfp_ext_d32);
8321 else
8322 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8323 fpu_vfp_ext_d32);
8324 }
5287ad62 8325 else
477330fc
RM
8326 {
8327 first_error (_("D register out of range for selected VFP version"));
8328 return;
8329 }
5287ad62
JB
8330 }
8331
c19d1205 8332 switch (pos)
09d92015 8333 {
c19d1205
ZW
8334 case VFP_REG_Sd:
8335 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8336 break;
8337
8338 case VFP_REG_Sn:
8339 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8340 break;
8341
8342 case VFP_REG_Sm:
8343 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8344 break;
8345
5287ad62
JB
8346 case VFP_REG_Dd:
8347 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8348 break;
5f4273c7 8349
5287ad62
JB
8350 case VFP_REG_Dn:
8351 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8352 break;
5f4273c7 8353
5287ad62
JB
8354 case VFP_REG_Dm:
8355 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8356 break;
8357
c19d1205
ZW
8358 default:
8359 abort ();
09d92015 8360 }
09d92015
MM
8361}
8362
c19d1205 8363/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8364 if any, is handled by md_apply_fix. */
09d92015 8365static void
c19d1205 8366encode_arm_shift (int i)
09d92015 8367{
008a97ef
RL
8368 /* register-shifted register. */
8369 if (inst.operands[i].immisreg)
8370 {
bf355b69
MR
8371 int op_index;
8372 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8373 {
5689c942
RL
8374 /* Check the operand only when it's presented. In pre-UAL syntax,
8375 if the destination register is the same as the first operand, two
8376 register form of the instruction can be used. */
bf355b69
MR
8377 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8378 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8379 as_warn (UNPRED_REG ("r15"));
8380 }
8381
8382 if (inst.operands[i].imm == REG_PC)
8383 as_warn (UNPRED_REG ("r15"));
8384 }
8385
c19d1205
ZW
8386 if (inst.operands[i].shift_kind == SHIFT_RRX)
8387 inst.instruction |= SHIFT_ROR << 5;
8388 else
09d92015 8389 {
c19d1205
ZW
8390 inst.instruction |= inst.operands[i].shift_kind << 5;
8391 if (inst.operands[i].immisreg)
8392 {
8393 inst.instruction |= SHIFT_BY_REG;
8394 inst.instruction |= inst.operands[i].imm << 8;
8395 }
8396 else
e2b0ab59 8397 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8398 }
c19d1205 8399}
09d92015 8400
c19d1205
ZW
8401static void
8402encode_arm_shifter_operand (int i)
8403{
8404 if (inst.operands[i].isreg)
09d92015 8405 {
c19d1205
ZW
8406 inst.instruction |= inst.operands[i].reg;
8407 encode_arm_shift (i);
09d92015 8408 }
c19d1205 8409 else
a415b1cd
JB
8410 {
8411 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8412 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8413 inst.instruction |= inst.operands[i].imm;
8414 }
09d92015
MM
8415}
8416
c19d1205 8417/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8418static void
c19d1205 8419encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8420{
2b2f5df9
NC
8421 /* PR 14260:
8422 Generate an error if the operand is not a register. */
8423 constraint (!inst.operands[i].isreg,
8424 _("Instruction does not support =N addresses"));
8425
c19d1205 8426 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8427
c19d1205 8428 if (inst.operands[i].preind)
09d92015 8429 {
c19d1205
ZW
8430 if (is_t)
8431 {
8432 inst.error = _("instruction does not accept preindexed addressing");
8433 return;
8434 }
8435 inst.instruction |= PRE_INDEX;
8436 if (inst.operands[i].writeback)
8437 inst.instruction |= WRITE_BACK;
09d92015 8438
c19d1205
ZW
8439 }
8440 else if (inst.operands[i].postind)
8441 {
9c2799c2 8442 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8443 if (is_t)
8444 inst.instruction |= WRITE_BACK;
8445 }
8446 else /* unindexed - only for coprocessor */
09d92015 8447 {
c19d1205 8448 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8449 return;
8450 }
8451
c19d1205
ZW
8452 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8453 && (((inst.instruction & 0x000f0000) >> 16)
8454 == ((inst.instruction & 0x0000f000) >> 12)))
8455 as_warn ((inst.instruction & LOAD_BIT)
8456 ? _("destination register same as write-back base")
8457 : _("source register same as write-back base"));
09d92015
MM
8458}
8459
c19d1205
ZW
8460/* inst.operands[i] was set up by parse_address. Encode it into an
8461 ARM-format mode 2 load or store instruction. If is_t is true,
8462 reject forms that cannot be used with a T instruction (i.e. not
8463 post-indexed). */
a737bd4d 8464static void
c19d1205 8465encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8466{
5be8be5d
DG
8467 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8468
c19d1205 8469 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8470
c19d1205 8471 if (inst.operands[i].immisreg)
09d92015 8472 {
5be8be5d
DG
8473 constraint ((inst.operands[i].imm == REG_PC
8474 || (is_pc && inst.operands[i].writeback)),
8475 BAD_PC_ADDRESSING);
c19d1205
ZW
8476 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8477 inst.instruction |= inst.operands[i].imm;
8478 if (!inst.operands[i].negative)
8479 inst.instruction |= INDEX_UP;
8480 if (inst.operands[i].shifted)
8481 {
8482 if (inst.operands[i].shift_kind == SHIFT_RRX)
8483 inst.instruction |= SHIFT_ROR << 5;
8484 else
8485 {
8486 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8487 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8488 }
8489 }
09d92015 8490 }
e2b0ab59 8491 else /* immediate offset in inst.relocs[0] */
09d92015 8492 {
e2b0ab59 8493 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8494 {
8495 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8496
8497 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8498 cannot use PC in addressing.
8499 PC cannot be used in writeback addressing, either. */
8500 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8501 BAD_PC_ADDRESSING);
23a10334 8502
dc5ec521 8503 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8504 if (warn_on_deprecated
8505 && !is_load
8506 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8507 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8508 }
8509
e2b0ab59 8510 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8511 {
8512 /* Prefer + for zero encoded value. */
8513 if (!inst.operands[i].negative)
8514 inst.instruction |= INDEX_UP;
e2b0ab59 8515 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8516 }
09d92015 8517 }
09d92015
MM
8518}
8519
c19d1205
ZW
8520/* inst.operands[i] was set up by parse_address. Encode it into an
8521 ARM-format mode 3 load or store instruction. Reject forms that
8522 cannot be used with such instructions. If is_t is true, reject
8523 forms that cannot be used with a T instruction (i.e. not
8524 post-indexed). */
8525static void
8526encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8527{
c19d1205 8528 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8529 {
c19d1205
ZW
8530 inst.error = _("instruction does not accept scaled register index");
8531 return;
09d92015 8532 }
a737bd4d 8533
c19d1205 8534 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8535
c19d1205
ZW
8536 if (inst.operands[i].immisreg)
8537 {
5be8be5d 8538 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8539 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8540 BAD_PC_ADDRESSING);
eb9f3f00
JB
8541 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8542 BAD_PC_WRITEBACK);
c19d1205
ZW
8543 inst.instruction |= inst.operands[i].imm;
8544 if (!inst.operands[i].negative)
8545 inst.instruction |= INDEX_UP;
8546 }
e2b0ab59 8547 else /* immediate offset in inst.relocs[0] */
c19d1205 8548 {
e2b0ab59 8549 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8550 && inst.operands[i].writeback),
8551 BAD_PC_WRITEBACK);
c19d1205 8552 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8553 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8554 {
8555 /* Prefer + for zero encoded value. */
8556 if (!inst.operands[i].negative)
8557 inst.instruction |= INDEX_UP;
8558
e2b0ab59 8559 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8560 }
c19d1205 8561 }
a737bd4d
NC
8562}
8563
8335d6aa
JW
8564/* Write immediate bits [7:0] to the following locations:
8565
8566 |28/24|23 19|18 16|15 4|3 0|
8567 | 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|
8568
8569 This function is used by VMOV/VMVN/VORR/VBIC. */
8570
8571static void
8572neon_write_immbits (unsigned immbits)
8573{
8574 inst.instruction |= immbits & 0xf;
8575 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8576 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8577}
8578
8579/* Invert low-order SIZE bits of XHI:XLO. */
8580
8581static void
8582neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8583{
8584 unsigned immlo = xlo ? *xlo : 0;
8585 unsigned immhi = xhi ? *xhi : 0;
8586
8587 switch (size)
8588 {
8589 case 8:
8590 immlo = (~immlo) & 0xff;
8591 break;
8592
8593 case 16:
8594 immlo = (~immlo) & 0xffff;
8595 break;
8596
8597 case 64:
8598 immhi = (~immhi) & 0xffffffff;
8599 /* fall through. */
8600
8601 case 32:
8602 immlo = (~immlo) & 0xffffffff;
8603 break;
8604
8605 default:
8606 abort ();
8607 }
8608
8609 if (xlo)
8610 *xlo = immlo;
8611
8612 if (xhi)
8613 *xhi = immhi;
8614}
8615
8616/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8617 A, B, C, D. */
09d92015 8618
c19d1205 8619static int
8335d6aa 8620neon_bits_same_in_bytes (unsigned imm)
09d92015 8621{
8335d6aa
JW
8622 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8623 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8624 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8625 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8626}
a737bd4d 8627
8335d6aa 8628/* For immediate of above form, return 0bABCD. */
09d92015 8629
8335d6aa
JW
8630static unsigned
8631neon_squash_bits (unsigned imm)
8632{
8633 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8634 | ((imm & 0x01000000) >> 21);
8635}
8636
8637/* Compress quarter-float representation to 0b...000 abcdefgh. */
8638
8639static unsigned
8640neon_qfloat_bits (unsigned imm)
8641{
8642 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8643}
8644
8645/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8646 the instruction. *OP is passed as the initial value of the op field, and
8647 may be set to a different value depending on the constant (i.e.
8648 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8649 MVN). If the immediate looks like a repeated pattern then also
8650 try smaller element sizes. */
8651
8652static int
8653neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8654 unsigned *immbits, int *op, int size,
8655 enum neon_el_type type)
8656{
8657 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8658 float. */
8659 if (type == NT_float && !float_p)
8660 return FAIL;
8661
8662 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8663 {
8335d6aa
JW
8664 if (size != 32 || *op == 1)
8665 return FAIL;
8666 *immbits = neon_qfloat_bits (immlo);
8667 return 0xf;
8668 }
8669
8670 if (size == 64)
8671 {
8672 if (neon_bits_same_in_bytes (immhi)
8673 && neon_bits_same_in_bytes (immlo))
c19d1205 8674 {
8335d6aa
JW
8675 if (*op == 1)
8676 return FAIL;
8677 *immbits = (neon_squash_bits (immhi) << 4)
8678 | neon_squash_bits (immlo);
8679 *op = 1;
8680 return 0xe;
c19d1205 8681 }
a737bd4d 8682
8335d6aa
JW
8683 if (immhi != immlo)
8684 return FAIL;
8685 }
a737bd4d 8686
8335d6aa 8687 if (size >= 32)
09d92015 8688 {
8335d6aa 8689 if (immlo == (immlo & 0x000000ff))
c19d1205 8690 {
8335d6aa
JW
8691 *immbits = immlo;
8692 return 0x0;
c19d1205 8693 }
8335d6aa 8694 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8695 {
8335d6aa
JW
8696 *immbits = immlo >> 8;
8697 return 0x2;
c19d1205 8698 }
8335d6aa
JW
8699 else if (immlo == (immlo & 0x00ff0000))
8700 {
8701 *immbits = immlo >> 16;
8702 return 0x4;
8703 }
8704 else if (immlo == (immlo & 0xff000000))
8705 {
8706 *immbits = immlo >> 24;
8707 return 0x6;
8708 }
8709 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8710 {
8711 *immbits = (immlo >> 8) & 0xff;
8712 return 0xc;
8713 }
8714 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8715 {
8716 *immbits = (immlo >> 16) & 0xff;
8717 return 0xd;
8718 }
8719
8720 if ((immlo & 0xffff) != (immlo >> 16))
8721 return FAIL;
8722 immlo &= 0xffff;
09d92015 8723 }
a737bd4d 8724
8335d6aa 8725 if (size >= 16)
4962c51a 8726 {
8335d6aa
JW
8727 if (immlo == (immlo & 0x000000ff))
8728 {
8729 *immbits = immlo;
8730 return 0x8;
8731 }
8732 else if (immlo == (immlo & 0x0000ff00))
8733 {
8734 *immbits = immlo >> 8;
8735 return 0xa;
8736 }
8737
8738 if ((immlo & 0xff) != (immlo >> 8))
8739 return FAIL;
8740 immlo &= 0xff;
4962c51a
MS
8741 }
8742
8335d6aa
JW
8743 if (immlo == (immlo & 0x000000ff))
8744 {
8745 /* Don't allow MVN with 8-bit immediate. */
8746 if (*op == 1)
8747 return FAIL;
8748 *immbits = immlo;
8749 return 0xe;
8750 }
26d97720 8751
8335d6aa 8752 return FAIL;
c19d1205 8753}
a737bd4d 8754
5fc177c8 8755#if defined BFD_HOST_64_BIT
ba592044
AM
8756/* Returns TRUE if double precision value V may be cast
8757 to single precision without loss of accuracy. */
8758
8759static bfd_boolean
7e30b1eb 8760is_double_a_single (bfd_uint64_t v)
ba592044 8761{
7e30b1eb
AM
8762 int exp = (v >> 52) & 0x7FF;
8763 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
ba592044 8764
7e30b1eb
AM
8765 return ((exp == 0 || exp == 0x7FF
8766 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8767 && (mantissa & 0x1FFFFFFFL) == 0);
ba592044
AM
8768}
8769
3739860c 8770/* Returns a double precision value casted to single precision
ba592044
AM
8771 (ignoring the least significant bits in exponent and mantissa). */
8772
8773static int
7e30b1eb 8774double_to_single (bfd_uint64_t v)
ba592044 8775{
7af67752
AM
8776 unsigned int sign = (v >> 63) & 1;
8777 int exp = (v >> 52) & 0x7FF;
7e30b1eb 8778 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
ba592044
AM
8779
8780 if (exp == 0x7FF)
8781 exp = 0xFF;
8782 else
8783 {
8784 exp = exp - 1023 + 127;
8785 if (exp >= 0xFF)
8786 {
8787 /* Infinity. */
8788 exp = 0x7F;
8789 mantissa = 0;
8790 }
8791 else if (exp < 0)
8792 {
8793 /* No denormalized numbers. */
8794 exp = 0;
8795 mantissa = 0;
8796 }
8797 }
8798 mantissa >>= 29;
8799 return (sign << 31) | (exp << 23) | mantissa;
8800}
5fc177c8 8801#endif /* BFD_HOST_64_BIT */
ba592044 8802
8335d6aa
JW
8803enum lit_type
8804{
8805 CONST_THUMB,
8806 CONST_ARM,
8807 CONST_VEC
8808};
8809
ba592044
AM
8810static void do_vfp_nsyn_opcode (const char *);
8811
e2b0ab59 8812/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8813 Determine whether it can be performed with a move instruction; if
8814 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8815 return TRUE; if it can't, convert inst.instruction to a literal-pool
8816 load and return FALSE. If this is not a valid thing to do in the
8817 current context, set inst.error and return TRUE.
a737bd4d 8818
c19d1205
ZW
8819 inst.operands[i] describes the destination register. */
8820
c921be7d 8821static bfd_boolean
8335d6aa 8822move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8823{
53365c0d 8824 unsigned long tbit;
8335d6aa
JW
8825 bfd_boolean thumb_p = (t == CONST_THUMB);
8826 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8827
8828 if (thumb_p)
8829 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8830 else
8831 tbit = LOAD_BIT;
8832
8833 if ((inst.instruction & tbit) == 0)
09d92015 8834 {
c19d1205 8835 inst.error = _("invalid pseudo operation");
c921be7d 8836 return TRUE;
09d92015 8837 }
ba592044 8838
e2b0ab59
AV
8839 if (inst.relocs[0].exp.X_op != O_constant
8840 && inst.relocs[0].exp.X_op != O_symbol
8841 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8842 {
8843 inst.error = _("constant expression expected");
c921be7d 8844 return TRUE;
09d92015 8845 }
ba592044 8846
e2b0ab59
AV
8847 if (inst.relocs[0].exp.X_op == O_constant
8848 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8849 {
5fc177c8 8850#if defined BFD_HOST_64_BIT
7e30b1eb 8851 bfd_uint64_t v;
5fc177c8 8852#else
7e30b1eb 8853 valueT v;
5fc177c8 8854#endif
e2b0ab59 8855 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8856 {
ba592044
AM
8857 LITTLENUM_TYPE w[X_PRECISION];
8858 LITTLENUM_TYPE * l;
8859
e2b0ab59 8860 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8861 {
ba592044
AM
8862 gen_to_words (w, X_PRECISION, E_PRECISION);
8863 l = w;
8864 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8865 }
ba592044
AM
8866 else
8867 l = generic_bignum;
3739860c 8868
5fc177c8 8869#if defined BFD_HOST_64_BIT
7e30b1eb
AM
8870 v = l[3] & LITTLENUM_MASK;
8871 v <<= LITTLENUM_NUMBER_OF_BITS;
8872 v |= l[2] & LITTLENUM_MASK;
8873 v <<= LITTLENUM_NUMBER_OF_BITS;
8874 v |= l[1] & LITTLENUM_MASK;
8875 v <<= LITTLENUM_NUMBER_OF_BITS;
8876 v |= l[0] & LITTLENUM_MASK;
5fc177c8 8877#else
7e30b1eb
AM
8878 v = l[1] & LITTLENUM_MASK;
8879 v <<= LITTLENUM_NUMBER_OF_BITS;
8880 v |= l[0] & LITTLENUM_MASK;
5fc177c8 8881#endif
8335d6aa 8882 }
ba592044 8883 else
e2b0ab59 8884 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8885
8886 if (!inst.operands[i].issingle)
8335d6aa 8887 {
12569877 8888 if (thumb_p)
8335d6aa 8889 {
53445554
TP
8890 /* LDR should not use lead in a flag-setting instruction being
8891 chosen so we do not check whether movs can be used. */
12569877 8892
53445554 8893 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8894 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8895 && inst.operands[i].reg != 13
8896 && inst.operands[i].reg != 15)
12569877 8897 {
fc289b0a
TP
8898 /* Check if on thumb2 it can be done with a mov.w, mvn or
8899 movw instruction. */
12569877 8900 unsigned int newimm;
f3da8a96 8901 bfd_boolean isNegated = FALSE;
12569877
AM
8902
8903 newimm = encode_thumb32_immediate (v);
f3da8a96 8904 if (newimm == (unsigned int) FAIL)
12569877 8905 {
582cfe03 8906 newimm = encode_thumb32_immediate (~v);
f3da8a96 8907 isNegated = TRUE;
12569877
AM
8908 }
8909
fc289b0a
TP
8910 /* The number can be loaded with a mov.w or mvn
8911 instruction. */
ff8646ee
TP
8912 if (newimm != (unsigned int) FAIL
8913 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8914 {
fc289b0a 8915 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8916 | (inst.operands[i].reg << 8));
fc289b0a 8917 /* Change to MOVN. */
582cfe03 8918 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8919 inst.instruction |= (newimm & 0x800) << 15;
8920 inst.instruction |= (newimm & 0x700) << 4;
8921 inst.instruction |= (newimm & 0x0ff);
8922 return TRUE;
8923 }
fc289b0a 8924 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8925 else if ((v & ~0xFFFF) == 0
8926 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8927 {
582cfe03 8928 int imm = v & 0xFFFF;
12569877 8929
582cfe03 8930 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8931 inst.instruction |= (inst.operands[i].reg << 8);
8932 inst.instruction |= (imm & 0xf000) << 4;
8933 inst.instruction |= (imm & 0x0800) << 15;
8934 inst.instruction |= (imm & 0x0700) << 4;
8935 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8936 /* In case this replacement is being done on Armv8-M
8937 Baseline we need to make sure to disable the
8938 instruction size check, as otherwise GAS will reject
8939 the use of this T32 instruction. */
8940 inst.size_req = 0;
12569877
AM
8941 return TRUE;
8942 }
8943 }
8335d6aa 8944 }
12569877 8945 else if (arm_p)
ba592044
AM
8946 {
8947 int value = encode_arm_immediate (v);
12569877 8948
ba592044
AM
8949 if (value != FAIL)
8950 {
8951 /* This can be done with a mov instruction. */
8952 inst.instruction &= LITERAL_MASK;
8953 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8954 inst.instruction |= value & 0xfff;
8955 return TRUE;
8956 }
8335d6aa 8957
ba592044
AM
8958 value = encode_arm_immediate (~ v);
8959 if (value != FAIL)
8960 {
8961 /* This can be done with a mvn instruction. */
8962 inst.instruction &= LITERAL_MASK;
8963 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8964 inst.instruction |= value & 0xfff;
8965 return TRUE;
8966 }
8967 }
934c2632 8968 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8969 {
ba592044
AM
8970 int op = 0;
8971 unsigned immbits = 0;
8972 unsigned immlo = inst.operands[1].imm;
8973 unsigned immhi = inst.operands[1].regisimm
8974 ? inst.operands[1].reg
e2b0ab59 8975 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8976 ? 0
8977 : ((bfd_int64_t)((int) immlo)) >> 32;
8978 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8979 &op, 64, NT_invtype);
8980
8981 if (cmode == FAIL)
8982 {
8983 neon_invert_size (&immlo, &immhi, 64);
8984 op = !op;
8985 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8986 &op, 64, NT_invtype);
8987 }
8988
8989 if (cmode != FAIL)
8990 {
8991 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8992 | (1 << 23)
8993 | (cmode << 8)
8994 | (op << 5)
8995 | (1 << 4);
8996
8997 /* Fill other bits in vmov encoding for both thumb and arm. */
8998 if (thumb_mode)
eff0bc54 8999 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 9000 else
eff0bc54 9001 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
9002 neon_write_immbits (immbits);
9003 return TRUE;
9004 }
8335d6aa
JW
9005 }
9006 }
8335d6aa 9007
ba592044
AM
9008 if (t == CONST_VEC)
9009 {
9010 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9011 if (inst.operands[i].issingle
9012 && is_quarter_float (inst.operands[1].imm)
9013 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 9014 {
ba592044
AM
9015 inst.operands[1].imm =
9016 neon_qfloat_bits (v);
9017 do_vfp_nsyn_opcode ("fconsts");
9018 return TRUE;
8335d6aa 9019 }
5fc177c8
NC
9020
9021 /* If our host does not support a 64-bit type then we cannot perform
9022 the following optimization. This mean that there will be a
9023 discrepancy between the output produced by an assembler built for
9024 a 32-bit-only host and the output produced from a 64-bit host, but
9025 this cannot be helped. */
9026#if defined BFD_HOST_64_BIT
ba592044
AM
9027 else if (!inst.operands[1].issingle
9028 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 9029 {
ba592044
AM
9030 if (is_double_a_single (v)
9031 && is_quarter_float (double_to_single (v)))
9032 {
9033 inst.operands[1].imm =
9034 neon_qfloat_bits (double_to_single (v));
9035 do_vfp_nsyn_opcode ("fconstd");
9036 return TRUE;
9037 }
8335d6aa 9038 }
5fc177c8 9039#endif
8335d6aa
JW
9040 }
9041 }
9042
9043 if (add_to_lit_pool ((!inst.operands[i].isvec
9044 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9045 return TRUE;
9046
9047 inst.operands[1].reg = REG_PC;
9048 inst.operands[1].isreg = 1;
9049 inst.operands[1].preind = 1;
e2b0ab59
AV
9050 inst.relocs[0].pc_rel = 1;
9051 inst.relocs[0].type = (thumb_p
8335d6aa
JW
9052 ? BFD_RELOC_ARM_THUMB_OFFSET
9053 : (mode_3
9054 ? BFD_RELOC_ARM_HWLITERAL
9055 : BFD_RELOC_ARM_LITERAL));
9056 return FALSE;
9057}
9058
9059/* inst.operands[i] was set up by parse_address. Encode it into an
9060 ARM-format instruction. Reject all forms which cannot be encoded
9061 into a coprocessor load/store instruction. If wb_ok is false,
9062 reject use of writeback; if unind_ok is false, reject use of
9063 unindexed addressing. If reloc_override is not 0, use it instead
9064 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9065 (in which case it is preserved). */
9066
9067static int
9068encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9069{
9070 if (!inst.operands[i].isreg)
9071 {
99b2a2dd
NC
9072 /* PR 18256 */
9073 if (! inst.operands[0].isvec)
9074 {
9075 inst.error = _("invalid co-processor operand");
9076 return FAIL;
9077 }
8335d6aa
JW
9078 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9079 return SUCCESS;
9080 }
9081
9082 inst.instruction |= inst.operands[i].reg << 16;
9083
9084 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9085
9086 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9087 {
9088 gas_assert (!inst.operands[i].writeback);
9089 if (!unind_ok)
9090 {
9091 inst.error = _("instruction does not support unindexed addressing");
9092 return FAIL;
9093 }
9094 inst.instruction |= inst.operands[i].imm;
9095 inst.instruction |= INDEX_UP;
9096 return SUCCESS;
9097 }
9098
9099 if (inst.operands[i].preind)
9100 inst.instruction |= PRE_INDEX;
9101
9102 if (inst.operands[i].writeback)
09d92015 9103 {
8335d6aa 9104 if (inst.operands[i].reg == REG_PC)
c19d1205 9105 {
8335d6aa
JW
9106 inst.error = _("pc may not be used with write-back");
9107 return FAIL;
c19d1205 9108 }
8335d6aa 9109 if (!wb_ok)
c19d1205 9110 {
8335d6aa
JW
9111 inst.error = _("instruction does not support writeback");
9112 return FAIL;
c19d1205 9113 }
8335d6aa 9114 inst.instruction |= WRITE_BACK;
09d92015
MM
9115 }
9116
8335d6aa 9117 if (reloc_override)
e2b0ab59
AV
9118 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9119 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9120 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9121 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 9122 {
8335d6aa 9123 if (thumb_mode)
e2b0ab59 9124 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 9125 else
e2b0ab59 9126 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 9127 }
8335d6aa
JW
9128
9129 /* Prefer + for zero encoded value. */
9130 if (!inst.operands[i].negative)
9131 inst.instruction |= INDEX_UP;
9132
9133 return SUCCESS;
09d92015
MM
9134}
9135
5f4273c7 9136/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
9137 First some generics; their names are taken from the conventional
9138 bit positions for register arguments in ARM format instructions. */
09d92015 9139
a737bd4d 9140static void
c19d1205 9141do_noargs (void)
09d92015 9142{
c19d1205 9143}
a737bd4d 9144
c19d1205
ZW
9145static void
9146do_rd (void)
9147{
9148 inst.instruction |= inst.operands[0].reg << 12;
9149}
a737bd4d 9150
16a1fa25
TP
9151static void
9152do_rn (void)
9153{
9154 inst.instruction |= inst.operands[0].reg << 16;
9155}
9156
c19d1205
ZW
9157static void
9158do_rd_rm (void)
9159{
9160 inst.instruction |= inst.operands[0].reg << 12;
9161 inst.instruction |= inst.operands[1].reg;
9162}
09d92015 9163
9eb6c0f1
MGD
9164static void
9165do_rm_rn (void)
9166{
9167 inst.instruction |= inst.operands[0].reg;
9168 inst.instruction |= inst.operands[1].reg << 16;
9169}
9170
c19d1205
ZW
9171static void
9172do_rd_rn (void)
9173{
9174 inst.instruction |= inst.operands[0].reg << 12;
9175 inst.instruction |= inst.operands[1].reg << 16;
9176}
a737bd4d 9177
c19d1205
ZW
9178static void
9179do_rn_rd (void)
9180{
9181 inst.instruction |= inst.operands[0].reg << 16;
9182 inst.instruction |= inst.operands[1].reg << 12;
9183}
09d92015 9184
4ed7ed8d
TP
9185static void
9186do_tt (void)
9187{
9188 inst.instruction |= inst.operands[0].reg << 8;
9189 inst.instruction |= inst.operands[1].reg << 16;
9190}
9191
59d09be6
MGD
9192static bfd_boolean
9193check_obsolete (const arm_feature_set *feature, const char *msg)
9194{
9195 if (ARM_CPU_IS_ANY (cpu_variant))
9196 {
5c3696f8 9197 as_tsktsk ("%s", msg);
59d09be6
MGD
9198 return TRUE;
9199 }
9200 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9201 {
9202 as_bad ("%s", msg);
9203 return TRUE;
9204 }
9205
9206 return FALSE;
9207}
9208
c19d1205
ZW
9209static void
9210do_rd_rm_rn (void)
9211{
9a64e435 9212 unsigned Rn = inst.operands[2].reg;
708587a4 9213 /* Enforce restrictions on SWP instruction. */
9a64e435 9214 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9215 {
9216 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9217 _("Rn must not overlap other operands"));
9218
59d09be6
MGD
9219 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9220 */
9221 if (!check_obsolete (&arm_ext_v8,
9222 _("swp{b} use is obsoleted for ARMv8 and later"))
9223 && warn_on_deprecated
9224 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9225 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9226 }
59d09be6 9227
c19d1205
ZW
9228 inst.instruction |= inst.operands[0].reg << 12;
9229 inst.instruction |= inst.operands[1].reg;
9a64e435 9230 inst.instruction |= Rn << 16;
c19d1205 9231}
09d92015 9232
c19d1205
ZW
9233static void
9234do_rd_rn_rm (void)
9235{
9236 inst.instruction |= inst.operands[0].reg << 12;
9237 inst.instruction |= inst.operands[1].reg << 16;
9238 inst.instruction |= inst.operands[2].reg;
9239}
a737bd4d 9240
c19d1205
ZW
9241static void
9242do_rm_rd_rn (void)
9243{
5be8be5d 9244 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9245 constraint (((inst.relocs[0].exp.X_op != O_constant
9246 && inst.relocs[0].exp.X_op != O_illegal)
9247 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9248 BAD_ADDR_MODE);
c19d1205
ZW
9249 inst.instruction |= inst.operands[0].reg;
9250 inst.instruction |= inst.operands[1].reg << 12;
9251 inst.instruction |= inst.operands[2].reg << 16;
9252}
09d92015 9253
c19d1205
ZW
9254static void
9255do_imm0 (void)
9256{
9257 inst.instruction |= inst.operands[0].imm;
9258}
09d92015 9259
c19d1205
ZW
9260static void
9261do_rd_cpaddr (void)
9262{
9263 inst.instruction |= inst.operands[0].reg << 12;
9264 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9265}
a737bd4d 9266
c19d1205
ZW
9267/* ARM instructions, in alphabetical order by function name (except
9268 that wrapper functions appear immediately after the function they
9269 wrap). */
09d92015 9270
c19d1205
ZW
9271/* This is a pseudo-op of the form "adr rd, label" to be converted
9272 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9273
9274static void
c19d1205 9275do_adr (void)
09d92015 9276{
c19d1205 9277 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9278
c19d1205
ZW
9279 /* Frag hacking will turn this into a sub instruction if the offset turns
9280 out to be negative. */
e2b0ab59
AV
9281 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9282 inst.relocs[0].pc_rel = 1;
9283 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9284
fc6141f0 9285 if (support_interwork
e2b0ab59
AV
9286 && inst.relocs[0].exp.X_op == O_symbol
9287 && inst.relocs[0].exp.X_add_symbol != NULL
9288 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9289 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9290 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9291}
b99bd4ef 9292
c19d1205
ZW
9293/* This is a pseudo-op of the form "adrl rd, label" to be converted
9294 into a relative address of the form:
9295 add rd, pc, #low(label-.-8)"
9296 add rd, rd, #high(label-.-8)" */
b99bd4ef 9297
c19d1205
ZW
9298static void
9299do_adrl (void)
9300{
9301 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9302
c19d1205
ZW
9303 /* Frag hacking will turn this into a sub instruction if the offset turns
9304 out to be negative. */
e2b0ab59
AV
9305 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9306 inst.relocs[0].pc_rel = 1;
c19d1205 9307 inst.size = INSN_SIZE * 2;
e2b0ab59 9308 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9309
fc6141f0 9310 if (support_interwork
e2b0ab59
AV
9311 && inst.relocs[0].exp.X_op == O_symbol
9312 && inst.relocs[0].exp.X_add_symbol != NULL
9313 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9314 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9315 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9316}
9317
b99bd4ef 9318static void
c19d1205 9319do_arit (void)
b99bd4ef 9320{
e2b0ab59
AV
9321 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9322 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9323 THUMB1_RELOC_ONLY);
c19d1205
ZW
9324 if (!inst.operands[1].present)
9325 inst.operands[1].reg = inst.operands[0].reg;
9326 inst.instruction |= inst.operands[0].reg << 12;
9327 inst.instruction |= inst.operands[1].reg << 16;
9328 encode_arm_shifter_operand (2);
9329}
b99bd4ef 9330
62b3e311
PB
9331static void
9332do_barrier (void)
9333{
9334 if (inst.operands[0].present)
ccb84d65 9335 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9336 else
9337 inst.instruction |= 0xf;
9338}
9339
c19d1205
ZW
9340static void
9341do_bfc (void)
9342{
9343 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9344 constraint (msb > 32, _("bit-field extends past end of register"));
9345 /* The instruction encoding stores the LSB and MSB,
9346 not the LSB and width. */
9347 inst.instruction |= inst.operands[0].reg << 12;
9348 inst.instruction |= inst.operands[1].imm << 7;
9349 inst.instruction |= (msb - 1) << 16;
9350}
b99bd4ef 9351
c19d1205
ZW
9352static void
9353do_bfi (void)
9354{
9355 unsigned int msb;
b99bd4ef 9356
c19d1205
ZW
9357 /* #0 in second position is alternative syntax for bfc, which is
9358 the same instruction but with REG_PC in the Rm field. */
9359 if (!inst.operands[1].isreg)
9360 inst.operands[1].reg = REG_PC;
b99bd4ef 9361
c19d1205
ZW
9362 msb = inst.operands[2].imm + inst.operands[3].imm;
9363 constraint (msb > 32, _("bit-field extends past end of register"));
9364 /* The instruction encoding stores the LSB and MSB,
9365 not the LSB and width. */
9366 inst.instruction |= inst.operands[0].reg << 12;
9367 inst.instruction |= inst.operands[1].reg;
9368 inst.instruction |= inst.operands[2].imm << 7;
9369 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9370}
9371
b99bd4ef 9372static void
c19d1205 9373do_bfx (void)
b99bd4ef 9374{
c19d1205
ZW
9375 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9376 _("bit-field extends past end of register"));
9377 inst.instruction |= inst.operands[0].reg << 12;
9378 inst.instruction |= inst.operands[1].reg;
9379 inst.instruction |= inst.operands[2].imm << 7;
9380 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9381}
09d92015 9382
c19d1205
ZW
9383/* ARM V5 breakpoint instruction (argument parse)
9384 BKPT <16 bit unsigned immediate>
9385 Instruction is not conditional.
9386 The bit pattern given in insns[] has the COND_ALWAYS condition,
9387 and it is an error if the caller tried to override that. */
b99bd4ef 9388
c19d1205
ZW
9389static void
9390do_bkpt (void)
9391{
9392 /* Top 12 of 16 bits to bits 19:8. */
9393 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9394
c19d1205
ZW
9395 /* Bottom 4 of 16 bits to bits 3:0. */
9396 inst.instruction |= inst.operands[0].imm & 0xf;
9397}
09d92015 9398
c19d1205
ZW
9399static void
9400encode_branch (int default_reloc)
9401{
9402 if (inst.operands[0].hasreloc)
9403 {
0855e32b
NS
9404 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9405 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9406 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9407 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9408 ? BFD_RELOC_ARM_PLT32
9409 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9410 }
b99bd4ef 9411 else
e2b0ab59
AV
9412 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9413 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9414}
9415
b99bd4ef 9416static void
c19d1205 9417do_branch (void)
b99bd4ef 9418{
39b41c9c
PB
9419#ifdef OBJ_ELF
9420 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9421 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9422 else
9423#endif
9424 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9425}
9426
9427static void
9428do_bl (void)
9429{
9430#ifdef OBJ_ELF
9431 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9432 {
9433 if (inst.cond == COND_ALWAYS)
9434 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9435 else
9436 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9437 }
9438 else
9439#endif
9440 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9441}
b99bd4ef 9442
c19d1205
ZW
9443/* ARM V5 branch-link-exchange instruction (argument parse)
9444 BLX <target_addr> ie BLX(1)
9445 BLX{<condition>} <Rm> ie BLX(2)
9446 Unfortunately, there are two different opcodes for this mnemonic.
9447 So, the insns[].value is not used, and the code here zaps values
9448 into inst.instruction.
9449 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9450
c19d1205
ZW
9451static void
9452do_blx (void)
9453{
9454 if (inst.operands[0].isreg)
b99bd4ef 9455 {
c19d1205
ZW
9456 /* Arg is a register; the opcode provided by insns[] is correct.
9457 It is not illegal to do "blx pc", just useless. */
9458 if (inst.operands[0].reg == REG_PC)
9459 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9460
c19d1205
ZW
9461 inst.instruction |= inst.operands[0].reg;
9462 }
9463 else
b99bd4ef 9464 {
c19d1205 9465 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9466 conditionally, and the opcode must be adjusted.
9467 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9468 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9469 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9470 inst.instruction = 0xfa000000;
267bf995 9471 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9472 }
c19d1205
ZW
9473}
9474
9475static void
9476do_bx (void)
9477{
845b51d6
PB
9478 bfd_boolean want_reloc;
9479
c19d1205
ZW
9480 if (inst.operands[0].reg == REG_PC)
9481 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9482
c19d1205 9483 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9484 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9485 it is for ARMv4t or earlier. */
9486 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9487 if (!ARM_FEATURE_ZERO (selected_object_arch)
9488 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9489 want_reloc = TRUE;
9490
5ad34203 9491#ifdef OBJ_ELF
845b51d6 9492 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9493#endif
584206db 9494 want_reloc = FALSE;
845b51d6
PB
9495
9496 if (want_reloc)
e2b0ab59 9497 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9498}
9499
c19d1205
ZW
9500
9501/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9502
9503static void
c19d1205 9504do_bxj (void)
a737bd4d 9505{
c19d1205
ZW
9506 if (inst.operands[0].reg == REG_PC)
9507 as_tsktsk (_("use of r15 in bxj is not really useful"));
9508
9509 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9510}
9511
c19d1205
ZW
9512/* Co-processor data operation:
9513 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9514 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9515static void
9516do_cdp (void)
9517{
9518 inst.instruction |= inst.operands[0].reg << 8;
9519 inst.instruction |= inst.operands[1].imm << 20;
9520 inst.instruction |= inst.operands[2].reg << 12;
9521 inst.instruction |= inst.operands[3].reg << 16;
9522 inst.instruction |= inst.operands[4].reg;
9523 inst.instruction |= inst.operands[5].imm << 5;
9524}
a737bd4d
NC
9525
9526static void
c19d1205 9527do_cmp (void)
a737bd4d 9528{
c19d1205
ZW
9529 inst.instruction |= inst.operands[0].reg << 16;
9530 encode_arm_shifter_operand (1);
a737bd4d
NC
9531}
9532
c19d1205
ZW
9533/* Transfer between coprocessor and ARM registers.
9534 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9535 MRC2
9536 MCR{cond}
9537 MCR2
9538
9539 No special properties. */
09d92015 9540
dcbd0d71
MGD
9541struct deprecated_coproc_regs_s
9542{
9543 unsigned cp;
9544 int opc1;
9545 unsigned crn;
9546 unsigned crm;
9547 int opc2;
9548 arm_feature_set deprecated;
9549 arm_feature_set obsoleted;
9550 const char *dep_msg;
9551 const char *obs_msg;
9552};
9553
9554#define DEPR_ACCESS_V8 \
9555 N_("This coprocessor register access is deprecated in ARMv8")
9556
9557/* Table of all deprecated coprocessor registers. */
9558static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9559{
9560 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9561 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9562 DEPR_ACCESS_V8, NULL},
9563 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9564 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9565 DEPR_ACCESS_V8, NULL},
9566 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9567 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9568 DEPR_ACCESS_V8, NULL},
9569 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9570 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9571 DEPR_ACCESS_V8, NULL},
9572 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9573 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9574 DEPR_ACCESS_V8, NULL},
9575};
9576
9577#undef DEPR_ACCESS_V8
9578
9579static const size_t deprecated_coproc_reg_count =
9580 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9581
09d92015 9582static void
c19d1205 9583do_co_reg (void)
09d92015 9584{
fdfde340 9585 unsigned Rd;
dcbd0d71 9586 size_t i;
fdfde340
JM
9587
9588 Rd = inst.operands[2].reg;
9589 if (thumb_mode)
9590 {
9591 if (inst.instruction == 0xee000010
9592 || inst.instruction == 0xfe000010)
9593 /* MCR, MCR2 */
9594 reject_bad_reg (Rd);
5c8ed6a4 9595 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9596 /* MRC, MRC2 */
9597 constraint (Rd == REG_SP, BAD_SP);
9598 }
9599 else
9600 {
9601 /* MCR */
9602 if (inst.instruction == 0xe000010)
9603 constraint (Rd == REG_PC, BAD_PC);
9604 }
9605
dcbd0d71
MGD
9606 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9607 {
9608 const struct deprecated_coproc_regs_s *r =
9609 deprecated_coproc_regs + i;
9610
9611 if (inst.operands[0].reg == r->cp
9612 && inst.operands[1].imm == r->opc1
9613 && inst.operands[3].reg == r->crn
9614 && inst.operands[4].reg == r->crm
9615 && inst.operands[5].imm == r->opc2)
9616 {
b10bf8c5 9617 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9618 && warn_on_deprecated
dcbd0d71 9619 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9620 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9621 }
9622 }
fdfde340 9623
c19d1205
ZW
9624 inst.instruction |= inst.operands[0].reg << 8;
9625 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9626 inst.instruction |= Rd << 12;
c19d1205
ZW
9627 inst.instruction |= inst.operands[3].reg << 16;
9628 inst.instruction |= inst.operands[4].reg;
9629 inst.instruction |= inst.operands[5].imm << 5;
9630}
09d92015 9631
c19d1205
ZW
9632/* Transfer between coprocessor register and pair of ARM registers.
9633 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9634 MCRR2
9635 MRRC{cond}
9636 MRRC2
b99bd4ef 9637
c19d1205 9638 Two XScale instructions are special cases of these:
09d92015 9639
c19d1205
ZW
9640 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9641 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9642
5f4273c7 9643 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9644
c19d1205
ZW
9645static void
9646do_co_reg2c (void)
9647{
fdfde340
JM
9648 unsigned Rd, Rn;
9649
9650 Rd = inst.operands[2].reg;
9651 Rn = inst.operands[3].reg;
9652
9653 if (thumb_mode)
9654 {
9655 reject_bad_reg (Rd);
9656 reject_bad_reg (Rn);
9657 }
9658 else
9659 {
9660 constraint (Rd == REG_PC, BAD_PC);
9661 constraint (Rn == REG_PC, BAD_PC);
9662 }
9663
873f10f0
TC
9664 /* Only check the MRRC{2} variants. */
9665 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9666 {
9667 /* If Rd == Rn, error that the operation is
9668 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9669 constraint (Rd == Rn, BAD_OVERLAP);
9670 }
9671
c19d1205
ZW
9672 inst.instruction |= inst.operands[0].reg << 8;
9673 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9674 inst.instruction |= Rd << 12;
9675 inst.instruction |= Rn << 16;
c19d1205 9676 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9677}
9678
c19d1205
ZW
9679static void
9680do_cpsi (void)
9681{
9682 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9683 if (inst.operands[1].present)
9684 {
9685 inst.instruction |= CPSI_MMOD;
9686 inst.instruction |= inst.operands[1].imm;
9687 }
c19d1205 9688}
b99bd4ef 9689
62b3e311
PB
9690static void
9691do_dbg (void)
9692{
9693 inst.instruction |= inst.operands[0].imm;
9694}
9695
eea54501
MGD
9696static void
9697do_div (void)
9698{
9699 unsigned Rd, Rn, Rm;
9700
9701 Rd = inst.operands[0].reg;
9702 Rn = (inst.operands[1].present
9703 ? inst.operands[1].reg : Rd);
9704 Rm = inst.operands[2].reg;
9705
9706 constraint ((Rd == REG_PC), BAD_PC);
9707 constraint ((Rn == REG_PC), BAD_PC);
9708 constraint ((Rm == REG_PC), BAD_PC);
9709
9710 inst.instruction |= Rd << 16;
9711 inst.instruction |= Rn << 0;
9712 inst.instruction |= Rm << 8;
9713}
9714
b99bd4ef 9715static void
c19d1205 9716do_it (void)
b99bd4ef 9717{
c19d1205 9718 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9719 process it to do the validation as if in
9720 thumb mode, just in case the code gets
9721 assembled for thumb using the unified syntax. */
9722
c19d1205 9723 inst.size = 0;
e07e6e58
NC
9724 if (unified_syntax)
9725 {
5ee91343
AV
9726 set_pred_insn_type (IT_INSN);
9727 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9728 now_pred.cc = inst.operands[0].imm;
e07e6e58 9729 }
09d92015 9730}
b99bd4ef 9731
6530b175
NC
9732/* If there is only one register in the register list,
9733 then return its register number. Otherwise return -1. */
9734static int
9735only_one_reg_in_list (int range)
9736{
9737 int i = ffs (range) - 1;
9738 return (i > 15 || range != (1 << i)) ? -1 : i;
9739}
9740
09d92015 9741static void
6530b175 9742encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9743{
c19d1205
ZW
9744 int base_reg = inst.operands[0].reg;
9745 int range = inst.operands[1].imm;
6530b175 9746 int one_reg;
ea6ef066 9747
c19d1205
ZW
9748 inst.instruction |= base_reg << 16;
9749 inst.instruction |= range;
ea6ef066 9750
c19d1205
ZW
9751 if (inst.operands[1].writeback)
9752 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9753
c19d1205 9754 if (inst.operands[0].writeback)
ea6ef066 9755 {
c19d1205
ZW
9756 inst.instruction |= WRITE_BACK;
9757 /* Check for unpredictable uses of writeback. */
9758 if (inst.instruction & LOAD_BIT)
09d92015 9759 {
c19d1205
ZW
9760 /* Not allowed in LDM type 2. */
9761 if ((inst.instruction & LDM_TYPE_2_OR_3)
9762 && ((range & (1 << REG_PC)) == 0))
9763 as_warn (_("writeback of base register is UNPREDICTABLE"));
9764 /* Only allowed if base reg not in list for other types. */
9765 else if (range & (1 << base_reg))
9766 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9767 }
9768 else /* STM. */
9769 {
9770 /* Not allowed for type 2. */
9771 if (inst.instruction & LDM_TYPE_2_OR_3)
9772 as_warn (_("writeback of base register is UNPREDICTABLE"));
9773 /* Only allowed if base reg not in list, or first in list. */
9774 else if ((range & (1 << base_reg))
9775 && (range & ((1 << base_reg) - 1)))
9776 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9777 }
ea6ef066 9778 }
6530b175
NC
9779
9780 /* If PUSH/POP has only one register, then use the A2 encoding. */
9781 one_reg = only_one_reg_in_list (range);
9782 if (from_push_pop_mnem && one_reg >= 0)
9783 {
9784 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9785
4f588891
NC
9786 if (is_push && one_reg == 13 /* SP */)
9787 /* PR 22483: The A2 encoding cannot be used when
9788 pushing the stack pointer as this is UNPREDICTABLE. */
9789 return;
9790
6530b175
NC
9791 inst.instruction &= A_COND_MASK;
9792 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9793 inst.instruction |= one_reg << 12;
9794 }
9795}
9796
9797static void
9798do_ldmstm (void)
9799{
9800 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9801}
9802
c19d1205
ZW
9803/* ARMv5TE load-consecutive (argument parse)
9804 Mode is like LDRH.
9805
9806 LDRccD R, mode
9807 STRccD R, mode. */
9808
a737bd4d 9809static void
c19d1205 9810do_ldrd (void)
a737bd4d 9811{
c19d1205 9812 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9813 _("first transfer register must be even"));
c19d1205
ZW
9814 constraint (inst.operands[1].present
9815 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9816 _("can only transfer two consecutive registers"));
c19d1205
ZW
9817 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9818 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9819
c19d1205
ZW
9820 if (!inst.operands[1].present)
9821 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9822
c56791bb
RE
9823 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9824 register and the first register written; we have to diagnose
9825 overlap between the base and the second register written here. */
ea6ef066 9826
c56791bb
RE
9827 if (inst.operands[2].reg == inst.operands[1].reg
9828 && (inst.operands[2].writeback || inst.operands[2].postind))
9829 as_warn (_("base register written back, and overlaps "
9830 "second transfer register"));
b05fe5cf 9831
c56791bb
RE
9832 if (!(inst.instruction & V4_STR_BIT))
9833 {
c19d1205 9834 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9835 destination (even if not write-back). */
9836 if (inst.operands[2].immisreg
9837 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9838 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9839 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9840 }
c19d1205
ZW
9841 inst.instruction |= inst.operands[0].reg << 12;
9842 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9843}
9844
9845static void
c19d1205 9846do_ldrex (void)
b05fe5cf 9847{
c19d1205
ZW
9848 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9849 || inst.operands[1].postind || inst.operands[1].writeback
9850 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9851 || inst.operands[1].negative
9852 /* This can arise if the programmer has written
9853 strex rN, rM, foo
9854 or if they have mistakenly used a register name as the last
9855 operand, eg:
9856 strex rN, rM, rX
9857 It is very difficult to distinguish between these two cases
9858 because "rX" might actually be a label. ie the register
9859 name has been occluded by a symbol of the same name. So we
9860 just generate a general 'bad addressing mode' type error
9861 message and leave it up to the programmer to discover the
9862 true cause and fix their mistake. */
9863 || (inst.operands[1].reg == REG_PC),
9864 BAD_ADDR_MODE);
b05fe5cf 9865
e2b0ab59
AV
9866 constraint (inst.relocs[0].exp.X_op != O_constant
9867 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9868 _("offset must be zero in ARM encoding"));
b05fe5cf 9869
5be8be5d
DG
9870 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9871
c19d1205
ZW
9872 inst.instruction |= inst.operands[0].reg << 12;
9873 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9874 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9875}
9876
9877static void
c19d1205 9878do_ldrexd (void)
b05fe5cf 9879{
c19d1205
ZW
9880 constraint (inst.operands[0].reg % 2 != 0,
9881 _("even register required"));
9882 constraint (inst.operands[1].present
9883 && inst.operands[1].reg != inst.operands[0].reg + 1,
9884 _("can only load two consecutive registers"));
9885 /* If op 1 were present and equal to PC, this function wouldn't
9886 have been called in the first place. */
9887 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9888
c19d1205
ZW
9889 inst.instruction |= inst.operands[0].reg << 12;
9890 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9891}
9892
1be5fd2e
NC
9893/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9894 which is not a multiple of four is UNPREDICTABLE. */
9895static void
9896check_ldr_r15_aligned (void)
9897{
9898 constraint (!(inst.operands[1].immisreg)
9899 && (inst.operands[0].reg == REG_PC
9900 && inst.operands[1].reg == REG_PC
e2b0ab59 9901 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9902 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9903}
9904
b05fe5cf 9905static void
c19d1205 9906do_ldst (void)
b05fe5cf 9907{
c19d1205
ZW
9908 inst.instruction |= inst.operands[0].reg << 12;
9909 if (!inst.operands[1].isreg)
8335d6aa 9910 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9911 return;
c19d1205 9912 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9913 check_ldr_r15_aligned ();
b05fe5cf
ZW
9914}
9915
9916static void
c19d1205 9917do_ldstt (void)
b05fe5cf 9918{
c19d1205
ZW
9919 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9920 reject [Rn,...]. */
9921 if (inst.operands[1].preind)
b05fe5cf 9922 {
e2b0ab59
AV
9923 constraint (inst.relocs[0].exp.X_op != O_constant
9924 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9925 _("this instruction requires a post-indexed address"));
b05fe5cf 9926
c19d1205
ZW
9927 inst.operands[1].preind = 0;
9928 inst.operands[1].postind = 1;
9929 inst.operands[1].writeback = 1;
b05fe5cf 9930 }
c19d1205
ZW
9931 inst.instruction |= inst.operands[0].reg << 12;
9932 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9933}
b05fe5cf 9934
c19d1205 9935/* Halfword and signed-byte load/store operations. */
b05fe5cf 9936
c19d1205
ZW
9937static void
9938do_ldstv4 (void)
9939{
ff4a8d2b 9940 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9941 inst.instruction |= inst.operands[0].reg << 12;
9942 if (!inst.operands[1].isreg)
8335d6aa 9943 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9944 return;
c19d1205 9945 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9946}
9947
9948static void
c19d1205 9949do_ldsttv4 (void)
b05fe5cf 9950{
c19d1205
ZW
9951 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9952 reject [Rn,...]. */
9953 if (inst.operands[1].preind)
b05fe5cf 9954 {
e2b0ab59
AV
9955 constraint (inst.relocs[0].exp.X_op != O_constant
9956 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9957 _("this instruction requires a post-indexed address"));
b05fe5cf 9958
c19d1205
ZW
9959 inst.operands[1].preind = 0;
9960 inst.operands[1].postind = 1;
9961 inst.operands[1].writeback = 1;
b05fe5cf 9962 }
c19d1205
ZW
9963 inst.instruction |= inst.operands[0].reg << 12;
9964 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9965}
b05fe5cf 9966
c19d1205
ZW
9967/* Co-processor register load/store.
9968 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9969static void
9970do_lstc (void)
9971{
9972 inst.instruction |= inst.operands[0].reg << 8;
9973 inst.instruction |= inst.operands[1].reg << 12;
9974 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9975}
9976
b05fe5cf 9977static void
c19d1205 9978do_mlas (void)
b05fe5cf 9979{
8fb9d7b9 9980 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9981 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9982 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9983 && !(inst.instruction & 0x00400000))
8fb9d7b9 9984 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9985
c19d1205
ZW
9986 inst.instruction |= inst.operands[0].reg << 16;
9987 inst.instruction |= inst.operands[1].reg;
9988 inst.instruction |= inst.operands[2].reg << 8;
9989 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9990}
b05fe5cf 9991
c19d1205
ZW
9992static void
9993do_mov (void)
9994{
e2b0ab59
AV
9995 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9996 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9997 THUMB1_RELOC_ONLY);
c19d1205
ZW
9998 inst.instruction |= inst.operands[0].reg << 12;
9999 encode_arm_shifter_operand (1);
10000}
b05fe5cf 10001
c19d1205
ZW
10002/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10003static void
10004do_mov16 (void)
10005{
b6895b4f
PB
10006 bfd_vma imm;
10007 bfd_boolean top;
10008
10009 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 10010 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 10011 _(":lower16: not allowed in this instruction"));
e2b0ab59 10012 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 10013 _(":upper16: not allowed in this instruction"));
c19d1205 10014 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 10015 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 10016 {
e2b0ab59 10017 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
10018 /* The value is in two pieces: 0:11, 16:19. */
10019 inst.instruction |= (imm & 0x00000fff);
10020 inst.instruction |= (imm & 0x0000f000) << 4;
10021 }
b05fe5cf 10022}
b99bd4ef 10023
037e8744
JB
10024static int
10025do_vfp_nsyn_mrs (void)
10026{
10027 if (inst.operands[0].isvec)
10028 {
10029 if (inst.operands[1].reg != 1)
477330fc 10030 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
10031 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10032 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10033 do_vfp_nsyn_opcode ("fmstat");
10034 }
10035 else if (inst.operands[1].isvec)
10036 do_vfp_nsyn_opcode ("fmrx");
10037 else
10038 return FAIL;
5f4273c7 10039
037e8744
JB
10040 return SUCCESS;
10041}
10042
10043static int
10044do_vfp_nsyn_msr (void)
10045{
10046 if (inst.operands[0].isvec)
10047 do_vfp_nsyn_opcode ("fmxr");
10048 else
10049 return FAIL;
10050
10051 return SUCCESS;
10052}
10053
f7c21dc7
NC
10054static void
10055do_vmrs (void)
10056{
10057 unsigned Rt = inst.operands[0].reg;
fa94de6b 10058
16d02dc9 10059 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
10060 {
10061 inst.error = BAD_SP;
10062 return;
10063 }
10064
ba6cd17f
SD
10065 switch (inst.operands[1].reg)
10066 {
10067 /* MVFR2 is only valid for Armv8-A. */
10068 case 5:
10069 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10070 _(BAD_FPU));
10071 break;
10072
10073 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10074 case 1: /* fpscr. */
10075 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10076 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10077 _(BAD_FPU));
10078 break;
10079
10080 case 14: /* fpcxt_ns. */
10081 case 15: /* fpcxt_s. */
10082 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10083 _("selected processor does not support instruction"));
10084 break;
10085
10086 case 2: /* fpscr_nzcvqc. */
10087 case 12: /* vpr. */
10088 case 13: /* p0. */
10089 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10090 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10091 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10092 _("selected processor does not support instruction"));
10093 if (inst.operands[0].reg != 2
10094 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10095 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10096 break;
10097
10098 default:
10099 break;
10100 }
40c7d507 10101
f7c21dc7 10102 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 10103 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
10104 {
10105 inst.error = BAD_PC;
10106 return;
10107 }
10108
16d02dc9
JB
10109 /* If we get through parsing the register name, we just insert the number
10110 generated into the instruction without further validation. */
10111 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
10112 inst.instruction |= (Rt << 12);
10113}
10114
10115static void
10116do_vmsr (void)
10117{
10118 unsigned Rt = inst.operands[1].reg;
fa94de6b 10119
f7c21dc7
NC
10120 if (thumb_mode)
10121 reject_bad_reg (Rt);
10122 else if (Rt == REG_PC)
10123 {
10124 inst.error = BAD_PC;
10125 return;
10126 }
10127
ba6cd17f
SD
10128 switch (inst.operands[0].reg)
10129 {
10130 /* MVFR2 is only valid for Armv8-A. */
10131 case 5:
10132 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10133 _(BAD_FPU));
10134 break;
10135
10136 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10137 case 1: /* fpcr. */
10138 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10139 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10140 _(BAD_FPU));
10141 break;
10142
10143 case 14: /* fpcxt_ns. */
10144 case 15: /* fpcxt_s. */
10145 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10146 _("selected processor does not support instruction"));
10147 break;
10148
10149 case 2: /* fpscr_nzcvqc. */
10150 case 12: /* vpr. */
10151 case 13: /* p0. */
10152 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10153 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10154 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10155 _("selected processor does not support instruction"));
10156 if (inst.operands[0].reg != 2
10157 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10158 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10159 break;
10160
10161 default:
10162 break;
10163 }
40c7d507 10164
16d02dc9
JB
10165 /* If we get through parsing the register name, we just insert the number
10166 generated into the instruction without further validation. */
10167 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10168 inst.instruction |= (Rt << 12);
10169}
10170
b99bd4ef 10171static void
c19d1205 10172do_mrs (void)
b99bd4ef 10173{
90ec0d68
MGD
10174 unsigned br;
10175
037e8744
JB
10176 if (do_vfp_nsyn_mrs () == SUCCESS)
10177 return;
10178
ff4a8d2b 10179 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10180 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10181
10182 if (inst.operands[1].isreg)
10183 {
10184 br = inst.operands[1].reg;
806ab1c0 10185 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10186 as_bad (_("bad register for mrs"));
10187 }
10188 else
10189 {
10190 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10191 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10192 != (PSR_c|PSR_f),
d2cd1205 10193 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10194 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10195 }
10196
10197 inst.instruction |= br;
c19d1205 10198}
b99bd4ef 10199
c19d1205
ZW
10200/* Two possible forms:
10201 "{C|S}PSR_<field>, Rm",
10202 "{C|S}PSR_f, #expression". */
b99bd4ef 10203
c19d1205
ZW
10204static void
10205do_msr (void)
10206{
037e8744
JB
10207 if (do_vfp_nsyn_msr () == SUCCESS)
10208 return;
10209
c19d1205
ZW
10210 inst.instruction |= inst.operands[0].imm;
10211 if (inst.operands[1].isreg)
10212 inst.instruction |= inst.operands[1].reg;
10213 else
b99bd4ef 10214 {
c19d1205 10215 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10216 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10217 inst.relocs[0].pc_rel = 0;
b99bd4ef 10218 }
b99bd4ef
NC
10219}
10220
c19d1205
ZW
10221static void
10222do_mul (void)
a737bd4d 10223{
ff4a8d2b
NC
10224 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10225
c19d1205
ZW
10226 if (!inst.operands[2].present)
10227 inst.operands[2].reg = inst.operands[0].reg;
10228 inst.instruction |= inst.operands[0].reg << 16;
10229 inst.instruction |= inst.operands[1].reg;
10230 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10231
8fb9d7b9
MS
10232 if (inst.operands[0].reg == inst.operands[1].reg
10233 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10234 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10235}
10236
c19d1205
ZW
10237/* Long Multiply Parser
10238 UMULL RdLo, RdHi, Rm, Rs
10239 SMULL RdLo, RdHi, Rm, Rs
10240 UMLAL RdLo, RdHi, Rm, Rs
10241 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10242
10243static void
c19d1205 10244do_mull (void)
b99bd4ef 10245{
c19d1205
ZW
10246 inst.instruction |= inst.operands[0].reg << 12;
10247 inst.instruction |= inst.operands[1].reg << 16;
10248 inst.instruction |= inst.operands[2].reg;
10249 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10250
682b27ad
PB
10251 /* rdhi and rdlo must be different. */
10252 if (inst.operands[0].reg == inst.operands[1].reg)
10253 as_tsktsk (_("rdhi and rdlo must be different"));
10254
10255 /* rdhi, rdlo and rm must all be different before armv6. */
10256 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10257 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10258 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10259 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10260}
b99bd4ef 10261
c19d1205
ZW
10262static void
10263do_nop (void)
10264{
e7495e45
NS
10265 if (inst.operands[0].present
10266 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10267 {
10268 /* Architectural NOP hints are CPSR sets with no bits selected. */
10269 inst.instruction &= 0xf0000000;
e7495e45
NS
10270 inst.instruction |= 0x0320f000;
10271 if (inst.operands[0].present)
10272 inst.instruction |= inst.operands[0].imm;
c19d1205 10273 }
b99bd4ef
NC
10274}
10275
c19d1205
ZW
10276/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10277 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10278 Condition defaults to COND_ALWAYS.
10279 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10280
10281static void
c19d1205 10282do_pkhbt (void)
b99bd4ef 10283{
c19d1205
ZW
10284 inst.instruction |= inst.operands[0].reg << 12;
10285 inst.instruction |= inst.operands[1].reg << 16;
10286 inst.instruction |= inst.operands[2].reg;
10287 if (inst.operands[3].present)
10288 encode_arm_shift (3);
10289}
b99bd4ef 10290
c19d1205 10291/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10292
c19d1205
ZW
10293static void
10294do_pkhtb (void)
10295{
10296 if (!inst.operands[3].present)
b99bd4ef 10297 {
c19d1205
ZW
10298 /* If the shift specifier is omitted, turn the instruction
10299 into pkhbt rd, rm, rn. */
10300 inst.instruction &= 0xfff00010;
10301 inst.instruction |= inst.operands[0].reg << 12;
10302 inst.instruction |= inst.operands[1].reg;
10303 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10304 }
10305 else
10306 {
c19d1205
ZW
10307 inst.instruction |= inst.operands[0].reg << 12;
10308 inst.instruction |= inst.operands[1].reg << 16;
10309 inst.instruction |= inst.operands[2].reg;
10310 encode_arm_shift (3);
b99bd4ef
NC
10311 }
10312}
10313
c19d1205 10314/* ARMv5TE: Preload-Cache
60e5ef9f 10315 MP Extensions: Preload for write
c19d1205 10316
60e5ef9f 10317 PLD(W) <addr_mode>
c19d1205
ZW
10318
10319 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10320
10321static void
c19d1205 10322do_pld (void)
b99bd4ef 10323{
c19d1205
ZW
10324 constraint (!inst.operands[0].isreg,
10325 _("'[' expected after PLD mnemonic"));
10326 constraint (inst.operands[0].postind,
10327 _("post-indexed expression used in preload instruction"));
10328 constraint (inst.operands[0].writeback,
10329 _("writeback used in preload instruction"));
10330 constraint (!inst.operands[0].preind,
10331 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10332 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10333}
b99bd4ef 10334
62b3e311
PB
10335/* ARMv7: PLI <addr_mode> */
10336static void
10337do_pli (void)
10338{
10339 constraint (!inst.operands[0].isreg,
10340 _("'[' expected after PLI mnemonic"));
10341 constraint (inst.operands[0].postind,
10342 _("post-indexed expression used in preload instruction"));
10343 constraint (inst.operands[0].writeback,
10344 _("writeback used in preload instruction"));
10345 constraint (!inst.operands[0].preind,
10346 _("unindexed addressing used in preload instruction"));
10347 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10348 inst.instruction &= ~PRE_INDEX;
10349}
10350
c19d1205
ZW
10351static void
10352do_push_pop (void)
10353{
5e0d7f77
MP
10354 constraint (inst.operands[0].writeback,
10355 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10356 inst.operands[1] = inst.operands[0];
10357 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10358 inst.operands[0].isreg = 1;
10359 inst.operands[0].writeback = 1;
10360 inst.operands[0].reg = REG_SP;
6530b175 10361 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10362}
b99bd4ef 10363
c19d1205
ZW
10364/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10365 word at the specified address and the following word
10366 respectively.
10367 Unconditionally executed.
10368 Error if Rn is R15. */
b99bd4ef 10369
c19d1205
ZW
10370static void
10371do_rfe (void)
10372{
10373 inst.instruction |= inst.operands[0].reg << 16;
10374 if (inst.operands[0].writeback)
10375 inst.instruction |= WRITE_BACK;
10376}
b99bd4ef 10377
c19d1205 10378/* ARM V6 ssat (argument parse). */
b99bd4ef 10379
c19d1205
ZW
10380static void
10381do_ssat (void)
10382{
10383 inst.instruction |= inst.operands[0].reg << 12;
10384 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10385 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10386
c19d1205
ZW
10387 if (inst.operands[3].present)
10388 encode_arm_shift (3);
b99bd4ef
NC
10389}
10390
c19d1205 10391/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10392
10393static void
c19d1205 10394do_usat (void)
b99bd4ef 10395{
c19d1205
ZW
10396 inst.instruction |= inst.operands[0].reg << 12;
10397 inst.instruction |= inst.operands[1].imm << 16;
10398 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10399
c19d1205
ZW
10400 if (inst.operands[3].present)
10401 encode_arm_shift (3);
b99bd4ef
NC
10402}
10403
c19d1205 10404/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10405
10406static void
c19d1205 10407do_ssat16 (void)
09d92015 10408{
c19d1205
ZW
10409 inst.instruction |= inst.operands[0].reg << 12;
10410 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10411 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10412}
10413
c19d1205
ZW
10414static void
10415do_usat16 (void)
a737bd4d 10416{
c19d1205
ZW
10417 inst.instruction |= inst.operands[0].reg << 12;
10418 inst.instruction |= inst.operands[1].imm << 16;
10419 inst.instruction |= inst.operands[2].reg;
10420}
a737bd4d 10421
c19d1205
ZW
10422/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10423 preserving the other bits.
a737bd4d 10424
c19d1205
ZW
10425 setend <endian_specifier>, where <endian_specifier> is either
10426 BE or LE. */
a737bd4d 10427
c19d1205
ZW
10428static void
10429do_setend (void)
10430{
12e37cbc
MGD
10431 if (warn_on_deprecated
10432 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10433 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10434
c19d1205
ZW
10435 if (inst.operands[0].imm)
10436 inst.instruction |= 0x200;
a737bd4d
NC
10437}
10438
10439static void
c19d1205 10440do_shift (void)
a737bd4d 10441{
c19d1205
ZW
10442 unsigned int Rm = (inst.operands[1].present
10443 ? inst.operands[1].reg
10444 : inst.operands[0].reg);
a737bd4d 10445
c19d1205
ZW
10446 inst.instruction |= inst.operands[0].reg << 12;
10447 inst.instruction |= Rm;
10448 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10449 {
c19d1205
ZW
10450 inst.instruction |= inst.operands[2].reg << 8;
10451 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10452 /* PR 12854: Error on extraneous shifts. */
10453 constraint (inst.operands[2].shifted,
10454 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10455 }
10456 else
e2b0ab59 10457 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10458}
10459
09d92015 10460static void
3eb17e6b 10461do_smc (void)
09d92015 10462{
ba85f98c
BW
10463 unsigned int value = inst.relocs[0].exp.X_add_number;
10464 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10465
e2b0ab59
AV
10466 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10467 inst.relocs[0].pc_rel = 0;
09d92015
MM
10468}
10469
90ec0d68
MGD
10470static void
10471do_hvc (void)
10472{
e2b0ab59
AV
10473 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10474 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10475}
10476
09d92015 10477static void
c19d1205 10478do_swi (void)
09d92015 10479{
e2b0ab59
AV
10480 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10481 inst.relocs[0].pc_rel = 0;
09d92015
MM
10482}
10483
ddfded2f
MW
10484static void
10485do_setpan (void)
10486{
10487 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10488 _("selected processor does not support SETPAN instruction"));
10489
10490 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10491}
10492
10493static void
10494do_t_setpan (void)
10495{
10496 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10497 _("selected processor does not support SETPAN instruction"));
10498
10499 inst.instruction |= (inst.operands[0].imm << 3);
10500}
10501
c19d1205
ZW
10502/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10503 SMLAxy{cond} Rd,Rm,Rs,Rn
10504 SMLAWy{cond} Rd,Rm,Rs,Rn
10505 Error if any register is R15. */
e16bb312 10506
c19d1205
ZW
10507static void
10508do_smla (void)
e16bb312 10509{
c19d1205
ZW
10510 inst.instruction |= inst.operands[0].reg << 16;
10511 inst.instruction |= inst.operands[1].reg;
10512 inst.instruction |= inst.operands[2].reg << 8;
10513 inst.instruction |= inst.operands[3].reg << 12;
10514}
a737bd4d 10515
c19d1205
ZW
10516/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10517 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10518 Error if any register is R15.
10519 Warning if Rdlo == Rdhi. */
a737bd4d 10520
c19d1205
ZW
10521static void
10522do_smlal (void)
10523{
10524 inst.instruction |= inst.operands[0].reg << 12;
10525 inst.instruction |= inst.operands[1].reg << 16;
10526 inst.instruction |= inst.operands[2].reg;
10527 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10528
c19d1205
ZW
10529 if (inst.operands[0].reg == inst.operands[1].reg)
10530 as_tsktsk (_("rdhi and rdlo must be different"));
10531}
a737bd4d 10532
c19d1205
ZW
10533/* ARM V5E (El Segundo) signed-multiply (argument parse)
10534 SMULxy{cond} Rd,Rm,Rs
10535 Error if any register is R15. */
a737bd4d 10536
c19d1205
ZW
10537static void
10538do_smul (void)
10539{
10540 inst.instruction |= inst.operands[0].reg << 16;
10541 inst.instruction |= inst.operands[1].reg;
10542 inst.instruction |= inst.operands[2].reg << 8;
10543}
a737bd4d 10544
b6702015
PB
10545/* ARM V6 srs (argument parse). The variable fields in the encoding are
10546 the same for both ARM and Thumb-2. */
a737bd4d 10547
c19d1205
ZW
10548static void
10549do_srs (void)
10550{
b6702015
PB
10551 int reg;
10552
10553 if (inst.operands[0].present)
10554 {
10555 reg = inst.operands[0].reg;
fdfde340 10556 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10557 }
10558 else
fdfde340 10559 reg = REG_SP;
b6702015
PB
10560
10561 inst.instruction |= reg << 16;
10562 inst.instruction |= inst.operands[1].imm;
10563 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10564 inst.instruction |= WRITE_BACK;
10565}
a737bd4d 10566
c19d1205 10567/* ARM V6 strex (argument parse). */
a737bd4d 10568
c19d1205
ZW
10569static void
10570do_strex (void)
10571{
10572 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10573 || inst.operands[2].postind || inst.operands[2].writeback
10574 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10575 || inst.operands[2].negative
10576 /* See comment in do_ldrex(). */
10577 || (inst.operands[2].reg == REG_PC),
10578 BAD_ADDR_MODE);
a737bd4d 10579
c19d1205
ZW
10580 constraint (inst.operands[0].reg == inst.operands[1].reg
10581 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10582
e2b0ab59
AV
10583 constraint (inst.relocs[0].exp.X_op != O_constant
10584 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10585 _("offset must be zero in ARM encoding"));
a737bd4d 10586
c19d1205
ZW
10587 inst.instruction |= inst.operands[0].reg << 12;
10588 inst.instruction |= inst.operands[1].reg;
10589 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10590 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10591}
10592
877807f8
NC
10593static void
10594do_t_strexbh (void)
10595{
10596 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10597 || inst.operands[2].postind || inst.operands[2].writeback
10598 || inst.operands[2].immisreg || inst.operands[2].shifted
10599 || inst.operands[2].negative,
10600 BAD_ADDR_MODE);
10601
10602 constraint (inst.operands[0].reg == inst.operands[1].reg
10603 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10604
10605 do_rm_rd_rn ();
10606}
10607
e16bb312 10608static void
c19d1205 10609do_strexd (void)
e16bb312 10610{
c19d1205
ZW
10611 constraint (inst.operands[1].reg % 2 != 0,
10612 _("even register required"));
10613 constraint (inst.operands[2].present
10614 && inst.operands[2].reg != inst.operands[1].reg + 1,
10615 _("can only store two consecutive registers"));
10616 /* If op 2 were present and equal to PC, this function wouldn't
10617 have been called in the first place. */
10618 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10619
c19d1205
ZW
10620 constraint (inst.operands[0].reg == inst.operands[1].reg
10621 || inst.operands[0].reg == inst.operands[1].reg + 1
10622 || inst.operands[0].reg == inst.operands[3].reg,
10623 BAD_OVERLAP);
e16bb312 10624
c19d1205
ZW
10625 inst.instruction |= inst.operands[0].reg << 12;
10626 inst.instruction |= inst.operands[1].reg;
10627 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10628}
10629
9eb6c0f1
MGD
10630/* ARM V8 STRL. */
10631static void
4b8c8c02 10632do_stlex (void)
9eb6c0f1
MGD
10633{
10634 constraint (inst.operands[0].reg == inst.operands[1].reg
10635 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10636
10637 do_rd_rm_rn ();
10638}
10639
10640static void
4b8c8c02 10641do_t_stlex (void)
9eb6c0f1
MGD
10642{
10643 constraint (inst.operands[0].reg == inst.operands[1].reg
10644 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10645
10646 do_rm_rd_rn ();
10647}
10648
c19d1205
ZW
10649/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10650 extends it to 32-bits, and adds the result to a value in another
10651 register. You can specify a rotation by 0, 8, 16, or 24 bits
10652 before extracting the 16-bit value.
10653 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10654 Condition defaults to COND_ALWAYS.
10655 Error if any register uses R15. */
10656
e16bb312 10657static void
c19d1205 10658do_sxtah (void)
e16bb312 10659{
c19d1205
ZW
10660 inst.instruction |= inst.operands[0].reg << 12;
10661 inst.instruction |= inst.operands[1].reg << 16;
10662 inst.instruction |= inst.operands[2].reg;
10663 inst.instruction |= inst.operands[3].imm << 10;
10664}
e16bb312 10665
c19d1205 10666/* ARM V6 SXTH.
e16bb312 10667
c19d1205
ZW
10668 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10669 Condition defaults to COND_ALWAYS.
10670 Error if any register uses R15. */
e16bb312
NC
10671
10672static void
c19d1205 10673do_sxth (void)
e16bb312 10674{
c19d1205
ZW
10675 inst.instruction |= inst.operands[0].reg << 12;
10676 inst.instruction |= inst.operands[1].reg;
10677 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10678}
c19d1205
ZW
10679\f
10680/* VFP instructions. In a logical order: SP variant first, monad
10681 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10682
10683static void
c19d1205 10684do_vfp_sp_monadic (void)
e16bb312 10685{
57785aa2
AV
10686 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10687 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10688 _(BAD_FPU));
10689
5287ad62
JB
10690 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10691 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10692}
10693
10694static void
c19d1205 10695do_vfp_sp_dyadic (void)
e16bb312 10696{
5287ad62
JB
10697 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10698 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10699 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10700}
10701
10702static void
c19d1205 10703do_vfp_sp_compare_z (void)
e16bb312 10704{
5287ad62 10705 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10706}
10707
10708static void
c19d1205 10709do_vfp_dp_sp_cvt (void)
e16bb312 10710{
5287ad62
JB
10711 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10712 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10713}
10714
10715static void
c19d1205 10716do_vfp_sp_dp_cvt (void)
e16bb312 10717{
5287ad62
JB
10718 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10719 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10720}
10721
10722static void
c19d1205 10723do_vfp_reg_from_sp (void)
e16bb312 10724{
57785aa2
AV
10725 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10726 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10727 _(BAD_FPU));
10728
c19d1205 10729 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10730 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10731}
10732
10733static void
c19d1205 10734do_vfp_reg2_from_sp2 (void)
e16bb312 10735{
c19d1205
ZW
10736 constraint (inst.operands[2].imm != 2,
10737 _("only two consecutive VFP SP registers allowed here"));
10738 inst.instruction |= inst.operands[0].reg << 12;
10739 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10740 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10741}
10742
10743static void
c19d1205 10744do_vfp_sp_from_reg (void)
e16bb312 10745{
57785aa2
AV
10746 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10747 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10748 _(BAD_FPU));
10749
5287ad62 10750 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10751 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10752}
10753
10754static void
c19d1205 10755do_vfp_sp2_from_reg2 (void)
e16bb312 10756{
c19d1205
ZW
10757 constraint (inst.operands[0].imm != 2,
10758 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10759 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10760 inst.instruction |= inst.operands[1].reg << 12;
10761 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10762}
10763
10764static void
c19d1205 10765do_vfp_sp_ldst (void)
e16bb312 10766{
5287ad62 10767 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10768 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10769}
10770
10771static void
c19d1205 10772do_vfp_dp_ldst (void)
e16bb312 10773{
5287ad62 10774 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10775 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10776}
10777
c19d1205 10778
e16bb312 10779static void
c19d1205 10780vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10781{
c19d1205
ZW
10782 if (inst.operands[0].writeback)
10783 inst.instruction |= WRITE_BACK;
10784 else
10785 constraint (ldstm_type != VFP_LDSTMIA,
10786 _("this addressing mode requires base-register writeback"));
10787 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10788 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10789 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10790}
10791
10792static void
c19d1205 10793vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10794{
c19d1205 10795 int count;
e16bb312 10796
c19d1205
ZW
10797 if (inst.operands[0].writeback)
10798 inst.instruction |= WRITE_BACK;
10799 else
10800 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10801 _("this addressing mode requires base-register writeback"));
e16bb312 10802
c19d1205 10803 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10804 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10805
c19d1205
ZW
10806 count = inst.operands[1].imm << 1;
10807 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10808 count += 1;
e16bb312 10809
c19d1205 10810 inst.instruction |= count;
e16bb312
NC
10811}
10812
10813static void
c19d1205 10814do_vfp_sp_ldstmia (void)
e16bb312 10815{
c19d1205 10816 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10817}
10818
10819static void
c19d1205 10820do_vfp_sp_ldstmdb (void)
e16bb312 10821{
c19d1205 10822 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10823}
10824
10825static void
c19d1205 10826do_vfp_dp_ldstmia (void)
e16bb312 10827{
c19d1205 10828 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10829}
10830
10831static void
c19d1205 10832do_vfp_dp_ldstmdb (void)
e16bb312 10833{
c19d1205 10834 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10835}
10836
10837static void
c19d1205 10838do_vfp_xp_ldstmia (void)
e16bb312 10839{
c19d1205
ZW
10840 vfp_dp_ldstm (VFP_LDSTMIAX);
10841}
e16bb312 10842
c19d1205
ZW
10843static void
10844do_vfp_xp_ldstmdb (void)
10845{
10846 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10847}
5287ad62
JB
10848
10849static void
10850do_vfp_dp_rd_rm (void)
10851{
57785aa2
AV
10852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10853 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10854 _(BAD_FPU));
10855
5287ad62
JB
10856 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10857 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10858}
10859
10860static void
10861do_vfp_dp_rn_rd (void)
10862{
10863 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10864 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10865}
10866
10867static void
10868do_vfp_dp_rd_rn (void)
10869{
10870 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10871 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10872}
10873
10874static void
10875do_vfp_dp_rd_rn_rm (void)
10876{
57785aa2
AV
10877 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10878 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10879 _(BAD_FPU));
10880
5287ad62
JB
10881 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10882 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10883 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10884}
10885
10886static void
10887do_vfp_dp_rd (void)
10888{
10889 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10890}
10891
10892static void
10893do_vfp_dp_rm_rd_rn (void)
10894{
57785aa2
AV
10895 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10896 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10897 _(BAD_FPU));
10898
5287ad62
JB
10899 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10900 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10901 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10902}
10903
10904/* VFPv3 instructions. */
10905static void
10906do_vfp_sp_const (void)
10907{
10908 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10909 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10910 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10911}
10912
10913static void
10914do_vfp_dp_const (void)
10915{
10916 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10917 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10918 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10919}
10920
10921static void
10922vfp_conv (int srcsize)
10923{
5f1af56b
MGD
10924 int immbits = srcsize - inst.operands[1].imm;
10925
fa94de6b
RM
10926 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10927 {
5f1af56b 10928 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10929 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10930 inst.error = _("immediate value out of range, expected range [0, 16]");
10931 return;
10932 }
fa94de6b 10933 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10934 {
10935 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10936 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10937 inst.error = _("immediate value out of range, expected range [1, 32]");
10938 return;
10939 }
10940
5287ad62
JB
10941 inst.instruction |= (immbits & 1) << 5;
10942 inst.instruction |= (immbits >> 1);
10943}
10944
10945static void
10946do_vfp_sp_conv_16 (void)
10947{
10948 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10949 vfp_conv (16);
10950}
10951
10952static void
10953do_vfp_dp_conv_16 (void)
10954{
10955 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10956 vfp_conv (16);
10957}
10958
10959static void
10960do_vfp_sp_conv_32 (void)
10961{
10962 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10963 vfp_conv (32);
10964}
10965
10966static void
10967do_vfp_dp_conv_32 (void)
10968{
10969 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10970 vfp_conv (32);
10971}
c19d1205
ZW
10972\f
10973/* FPA instructions. Also in a logical order. */
e16bb312 10974
c19d1205
ZW
10975static void
10976do_fpa_cmp (void)
10977{
10978 inst.instruction |= inst.operands[0].reg << 16;
10979 inst.instruction |= inst.operands[1].reg;
10980}
b99bd4ef
NC
10981
10982static void
c19d1205 10983do_fpa_ldmstm (void)
b99bd4ef 10984{
c19d1205
ZW
10985 inst.instruction |= inst.operands[0].reg << 12;
10986 switch (inst.operands[1].imm)
10987 {
10988 case 1: inst.instruction |= CP_T_X; break;
10989 case 2: inst.instruction |= CP_T_Y; break;
10990 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10991 case 4: break;
10992 default: abort ();
10993 }
b99bd4ef 10994
c19d1205
ZW
10995 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10996 {
10997 /* The instruction specified "ea" or "fd", so we can only accept
10998 [Rn]{!}. The instruction does not really support stacking or
10999 unstacking, so we have to emulate these by setting appropriate
11000 bits and offsets. */
e2b0ab59
AV
11001 constraint (inst.relocs[0].exp.X_op != O_constant
11002 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 11003 _("this instruction does not support indexing"));
b99bd4ef 11004
c19d1205 11005 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 11006 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 11007
c19d1205 11008 if (!(inst.instruction & INDEX_UP))
e2b0ab59 11009 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 11010
c19d1205
ZW
11011 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11012 {
11013 inst.operands[2].preind = 0;
11014 inst.operands[2].postind = 1;
11015 }
11016 }
b99bd4ef 11017
c19d1205 11018 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 11019}
c19d1205
ZW
11020\f
11021/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 11022
c19d1205
ZW
11023static void
11024do_iwmmxt_tandorc (void)
11025{
11026 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11027}
b99bd4ef 11028
c19d1205
ZW
11029static void
11030do_iwmmxt_textrc (void)
11031{
11032 inst.instruction |= inst.operands[0].reg << 12;
11033 inst.instruction |= inst.operands[1].imm;
11034}
b99bd4ef
NC
11035
11036static void
c19d1205 11037do_iwmmxt_textrm (void)
b99bd4ef 11038{
c19d1205
ZW
11039 inst.instruction |= inst.operands[0].reg << 12;
11040 inst.instruction |= inst.operands[1].reg << 16;
11041 inst.instruction |= inst.operands[2].imm;
11042}
b99bd4ef 11043
c19d1205
ZW
11044static void
11045do_iwmmxt_tinsr (void)
11046{
11047 inst.instruction |= inst.operands[0].reg << 16;
11048 inst.instruction |= inst.operands[1].reg << 12;
11049 inst.instruction |= inst.operands[2].imm;
11050}
b99bd4ef 11051
c19d1205
ZW
11052static void
11053do_iwmmxt_tmia (void)
11054{
11055 inst.instruction |= inst.operands[0].reg << 5;
11056 inst.instruction |= inst.operands[1].reg;
11057 inst.instruction |= inst.operands[2].reg << 12;
11058}
b99bd4ef 11059
c19d1205
ZW
11060static void
11061do_iwmmxt_waligni (void)
11062{
11063 inst.instruction |= inst.operands[0].reg << 12;
11064 inst.instruction |= inst.operands[1].reg << 16;
11065 inst.instruction |= inst.operands[2].reg;
11066 inst.instruction |= inst.operands[3].imm << 20;
11067}
b99bd4ef 11068
2d447fca
JM
11069static void
11070do_iwmmxt_wmerge (void)
11071{
11072 inst.instruction |= inst.operands[0].reg << 12;
11073 inst.instruction |= inst.operands[1].reg << 16;
11074 inst.instruction |= inst.operands[2].reg;
11075 inst.instruction |= inst.operands[3].imm << 21;
11076}
11077
c19d1205
ZW
11078static void
11079do_iwmmxt_wmov (void)
11080{
11081 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11082 inst.instruction |= inst.operands[0].reg << 12;
11083 inst.instruction |= inst.operands[1].reg << 16;
11084 inst.instruction |= inst.operands[1].reg;
11085}
b99bd4ef 11086
c19d1205
ZW
11087static void
11088do_iwmmxt_wldstbh (void)
11089{
8f06b2d8 11090 int reloc;
c19d1205 11091 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
11092 if (thumb_mode)
11093 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11094 else
11095 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11096 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
11097}
11098
c19d1205
ZW
11099static void
11100do_iwmmxt_wldstw (void)
11101{
11102 /* RIWR_RIWC clears .isreg for a control register. */
11103 if (!inst.operands[0].isreg)
11104 {
11105 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11106 inst.instruction |= 0xf0000000;
11107 }
b99bd4ef 11108
c19d1205
ZW
11109 inst.instruction |= inst.operands[0].reg << 12;
11110 encode_arm_cp_address (1, TRUE, TRUE, 0);
11111}
b99bd4ef
NC
11112
11113static void
c19d1205 11114do_iwmmxt_wldstd (void)
b99bd4ef 11115{
c19d1205 11116 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
11117 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11118 && inst.operands[1].immisreg)
11119 {
11120 inst.instruction &= ~0x1a000ff;
eff0bc54 11121 inst.instruction |= (0xfU << 28);
2d447fca
JM
11122 if (inst.operands[1].preind)
11123 inst.instruction |= PRE_INDEX;
11124 if (!inst.operands[1].negative)
11125 inst.instruction |= INDEX_UP;
11126 if (inst.operands[1].writeback)
11127 inst.instruction |= WRITE_BACK;
11128 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11129 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
11130 inst.instruction |= inst.operands[1].imm;
11131 }
11132 else
11133 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 11134}
b99bd4ef 11135
c19d1205
ZW
11136static void
11137do_iwmmxt_wshufh (void)
11138{
11139 inst.instruction |= inst.operands[0].reg << 12;
11140 inst.instruction |= inst.operands[1].reg << 16;
11141 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11142 inst.instruction |= (inst.operands[2].imm & 0x0f);
11143}
b99bd4ef 11144
c19d1205
ZW
11145static void
11146do_iwmmxt_wzero (void)
11147{
11148 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11149 inst.instruction |= inst.operands[0].reg;
11150 inst.instruction |= inst.operands[0].reg << 12;
11151 inst.instruction |= inst.operands[0].reg << 16;
11152}
2d447fca
JM
11153
11154static void
11155do_iwmmxt_wrwrwr_or_imm5 (void)
11156{
11157 if (inst.operands[2].isreg)
11158 do_rd_rn_rm ();
11159 else {
11160 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11161 _("immediate operand requires iWMMXt2"));
11162 do_rd_rn ();
11163 if (inst.operands[2].imm == 0)
11164 {
11165 switch ((inst.instruction >> 20) & 0xf)
11166 {
11167 case 4:
11168 case 5:
11169 case 6:
5f4273c7 11170 case 7:
2d447fca
JM
11171 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11172 inst.operands[2].imm = 16;
11173 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11174 break;
11175 case 8:
11176 case 9:
11177 case 10:
11178 case 11:
11179 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11180 inst.operands[2].imm = 32;
11181 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11182 break;
11183 case 12:
11184 case 13:
11185 case 14:
11186 case 15:
11187 {
11188 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11189 unsigned long wrn;
11190 wrn = (inst.instruction >> 16) & 0xf;
11191 inst.instruction &= 0xff0fff0f;
11192 inst.instruction |= wrn;
11193 /* Bail out here; the instruction is now assembled. */
11194 return;
11195 }
11196 }
11197 }
11198 /* Map 32 -> 0, etc. */
11199 inst.operands[2].imm &= 0x1f;
eff0bc54 11200 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11201 }
11202}
c19d1205
ZW
11203\f
11204/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11205 operations first, then control, shift, and load/store. */
b99bd4ef 11206
c19d1205 11207/* Insns like "foo X,Y,Z". */
b99bd4ef 11208
c19d1205
ZW
11209static void
11210do_mav_triple (void)
11211{
11212 inst.instruction |= inst.operands[0].reg << 16;
11213 inst.instruction |= inst.operands[1].reg;
11214 inst.instruction |= inst.operands[2].reg << 12;
11215}
b99bd4ef 11216
c19d1205
ZW
11217/* Insns like "foo W,X,Y,Z".
11218 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11219
c19d1205
ZW
11220static void
11221do_mav_quad (void)
11222{
11223 inst.instruction |= inst.operands[0].reg << 5;
11224 inst.instruction |= inst.operands[1].reg << 12;
11225 inst.instruction |= inst.operands[2].reg << 16;
11226 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11227}
11228
c19d1205
ZW
11229/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11230static void
11231do_mav_dspsc (void)
a737bd4d 11232{
c19d1205
ZW
11233 inst.instruction |= inst.operands[1].reg << 12;
11234}
a737bd4d 11235
c19d1205
ZW
11236/* Maverick shift immediate instructions.
11237 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11238 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11239
c19d1205
ZW
11240static void
11241do_mav_shift (void)
11242{
11243 int imm = inst.operands[2].imm;
a737bd4d 11244
c19d1205
ZW
11245 inst.instruction |= inst.operands[0].reg << 12;
11246 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11247
c19d1205
ZW
11248 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11249 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11250 Bit 4 should be 0. */
11251 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11252
c19d1205
ZW
11253 inst.instruction |= imm;
11254}
11255\f
11256/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11257
c19d1205
ZW
11258/* Xscale multiply-accumulate (argument parse)
11259 MIAcc acc0,Rm,Rs
11260 MIAPHcc acc0,Rm,Rs
11261 MIAxycc acc0,Rm,Rs. */
a737bd4d 11262
c19d1205
ZW
11263static void
11264do_xsc_mia (void)
11265{
11266 inst.instruction |= inst.operands[1].reg;
11267 inst.instruction |= inst.operands[2].reg << 12;
11268}
a737bd4d 11269
c19d1205 11270/* Xscale move-accumulator-register (argument parse)
a737bd4d 11271
c19d1205 11272 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11273
c19d1205
ZW
11274static void
11275do_xsc_mar (void)
11276{
11277 inst.instruction |= inst.operands[1].reg << 12;
11278 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11279}
11280
c19d1205 11281/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11282
c19d1205 11283 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11284
11285static void
c19d1205 11286do_xsc_mra (void)
b99bd4ef 11287{
c19d1205
ZW
11288 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11289 inst.instruction |= inst.operands[0].reg << 12;
11290 inst.instruction |= inst.operands[1].reg << 16;
11291}
11292\f
11293/* Encoding functions relevant only to Thumb. */
b99bd4ef 11294
c19d1205
ZW
11295/* inst.operands[i] is a shifted-register operand; encode
11296 it into inst.instruction in the format used by Thumb32. */
11297
11298static void
11299encode_thumb32_shifted_operand (int i)
11300{
e2b0ab59 11301 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11302 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11303
9c3c69f2
PB
11304 constraint (inst.operands[i].immisreg,
11305 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11306 inst.instruction |= inst.operands[i].reg;
11307 if (shift == SHIFT_RRX)
11308 inst.instruction |= SHIFT_ROR << 4;
11309 else
b99bd4ef 11310 {
e2b0ab59 11311 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11312 _("expression too complex"));
11313
11314 constraint (value > 32
11315 || (value == 32 && (shift == SHIFT_LSL
11316 || shift == SHIFT_ROR)),
11317 _("shift expression is too large"));
11318
11319 if (value == 0)
11320 shift = SHIFT_LSL;
11321 else if (value == 32)
11322 value = 0;
11323
11324 inst.instruction |= shift << 4;
11325 inst.instruction |= (value & 0x1c) << 10;
11326 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11327 }
c19d1205 11328}
b99bd4ef 11329
b99bd4ef 11330
c19d1205
ZW
11331/* inst.operands[i] was set up by parse_address. Encode it into a
11332 Thumb32 format load or store instruction. Reject forms that cannot
11333 be used with such instructions. If is_t is true, reject forms that
11334 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11335 that cannot be used with a D instruction. If it is a store insn,
11336 reject PC in Rn. */
b99bd4ef 11337
c19d1205
ZW
11338static void
11339encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11340{
5be8be5d 11341 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11342
11343 constraint (!inst.operands[i].isreg,
53365c0d 11344 _("Instruction does not support =N addresses"));
b99bd4ef 11345
c19d1205
ZW
11346 inst.instruction |= inst.operands[i].reg << 16;
11347 if (inst.operands[i].immisreg)
b99bd4ef 11348 {
5be8be5d 11349 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11350 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11351 constraint (inst.operands[i].negative,
11352 _("Thumb does not support negative register indexing"));
11353 constraint (inst.operands[i].postind,
11354 _("Thumb does not support register post-indexing"));
11355 constraint (inst.operands[i].writeback,
11356 _("Thumb does not support register indexing with writeback"));
11357 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11358 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11359
f40d1643 11360 inst.instruction |= inst.operands[i].imm;
c19d1205 11361 if (inst.operands[i].shifted)
b99bd4ef 11362 {
e2b0ab59 11363 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11364 _("expression too complex"));
e2b0ab59
AV
11365 constraint (inst.relocs[0].exp.X_add_number < 0
11366 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11367 _("shift out of range"));
e2b0ab59 11368 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11369 }
e2b0ab59 11370 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11371 }
11372 else if (inst.operands[i].preind)
11373 {
5be8be5d 11374 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11375 constraint (is_t && inst.operands[i].writeback,
c19d1205 11376 _("cannot use writeback with this instruction"));
4755303e
WN
11377 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11378 BAD_PC_ADDRESSING);
c19d1205
ZW
11379
11380 if (is_d)
11381 {
11382 inst.instruction |= 0x01000000;
11383 if (inst.operands[i].writeback)
11384 inst.instruction |= 0x00200000;
b99bd4ef 11385 }
c19d1205 11386 else
b99bd4ef 11387 {
c19d1205
ZW
11388 inst.instruction |= 0x00000c00;
11389 if (inst.operands[i].writeback)
11390 inst.instruction |= 0x00000100;
b99bd4ef 11391 }
e2b0ab59 11392 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11393 }
c19d1205 11394 else if (inst.operands[i].postind)
b99bd4ef 11395 {
9c2799c2 11396 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11397 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11398 constraint (is_t, _("cannot use post-indexing with this instruction"));
11399
11400 if (is_d)
11401 inst.instruction |= 0x00200000;
11402 else
11403 inst.instruction |= 0x00000900;
e2b0ab59 11404 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11405 }
11406 else /* unindexed - only for coprocessor */
11407 inst.error = _("instruction does not accept unindexed addressing");
11408}
11409
e39c1607 11410/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11411 encodings (the latter only in post-V6T2 cores). The index is the
11412 value used in the insns table below. When there is more than one
11413 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11414 holds variant (1).
11415 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11416#define T16_32_TAB \
21d799b5
NC
11417 X(_adc, 4140, eb400000), \
11418 X(_adcs, 4140, eb500000), \
11419 X(_add, 1c00, eb000000), \
11420 X(_adds, 1c00, eb100000), \
11421 X(_addi, 0000, f1000000), \
11422 X(_addis, 0000, f1100000), \
11423 X(_add_pc,000f, f20f0000), \
11424 X(_add_sp,000d, f10d0000), \
11425 X(_adr, 000f, f20f0000), \
11426 X(_and, 4000, ea000000), \
11427 X(_ands, 4000, ea100000), \
11428 X(_asr, 1000, fa40f000), \
11429 X(_asrs, 1000, fa50f000), \
11430 X(_b, e000, f000b000), \
11431 X(_bcond, d000, f0008000), \
4389b29a 11432 X(_bf, 0000, f040e001), \
f6b2b12d 11433 X(_bfcsel,0000, f000e001), \
f1c7f421 11434 X(_bfx, 0000, f060e001), \
65d1bc05 11435 X(_bfl, 0000, f000c001), \
f1c7f421 11436 X(_bflx, 0000, f070e001), \
21d799b5
NC
11437 X(_bic, 4380, ea200000), \
11438 X(_bics, 4380, ea300000), \
e39c1607
SD
11439 X(_cinc, 0000, ea509000), \
11440 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11441 X(_cmn, 42c0, eb100f00), \
11442 X(_cmp, 2800, ebb00f00), \
e39c1607 11443 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11444 X(_cpsie, b660, f3af8400), \
11445 X(_cpsid, b670, f3af8600), \
11446 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11447 X(_csel, 0000, ea508000), \
11448 X(_cset, 0000, ea5f900f), \
11449 X(_csetm, 0000, ea5fa00f), \
11450 X(_csinc, 0000, ea509000), \
11451 X(_csinv, 0000, ea50a000), \
11452 X(_csneg, 0000, ea50b000), \
21d799b5 11453 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11454 X(_dls, 0000, f040e001), \
1f6234a3 11455 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11456 X(_eor, 4040, ea800000), \
11457 X(_eors, 4040, ea900000), \
11458 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11459 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11460 X(_ldmia, c800, e8900000), \
11461 X(_ldr, 6800, f8500000), \
11462 X(_ldrb, 7800, f8100000), \
11463 X(_ldrh, 8800, f8300000), \
11464 X(_ldrsb, 5600, f9100000), \
11465 X(_ldrsh, 5e00, f9300000), \
11466 X(_ldr_pc,4800, f85f0000), \
11467 X(_ldr_pc2,4800, f85f0000), \
11468 X(_ldr_sp,9800, f85d0000), \
60f993ce 11469 X(_le, 0000, f00fc001), \
1f6234a3 11470 X(_letp, 0000, f01fc001), \
21d799b5
NC
11471 X(_lsl, 0000, fa00f000), \
11472 X(_lsls, 0000, fa10f000), \
11473 X(_lsr, 0800, fa20f000), \
11474 X(_lsrs, 0800, fa30f000), \
11475 X(_mov, 2000, ea4f0000), \
11476 X(_movs, 2000, ea5f0000), \
11477 X(_mul, 4340, fb00f000), \
11478 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11479 X(_mvn, 43c0, ea6f0000), \
11480 X(_mvns, 43c0, ea7f0000), \
11481 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11482 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11483 X(_orr, 4300, ea400000), \
11484 X(_orrs, 4300, ea500000), \
11485 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11486 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11487 X(_rev, ba00, fa90f080), \
11488 X(_rev16, ba40, fa90f090), \
11489 X(_revsh, bac0, fa90f0b0), \
11490 X(_ror, 41c0, fa60f000), \
11491 X(_rors, 41c0, fa70f000), \
11492 X(_sbc, 4180, eb600000), \
11493 X(_sbcs, 4180, eb700000), \
11494 X(_stmia, c000, e8800000), \
11495 X(_str, 6000, f8400000), \
11496 X(_strb, 7000, f8000000), \
11497 X(_strh, 8000, f8200000), \
11498 X(_str_sp,9000, f84d0000), \
11499 X(_sub, 1e00, eba00000), \
11500 X(_subs, 1e00, ebb00000), \
11501 X(_subi, 8000, f1a00000), \
11502 X(_subis, 8000, f1b00000), \
11503 X(_sxtb, b240, fa4ff080), \
11504 X(_sxth, b200, fa0ff080), \
11505 X(_tst, 4200, ea100f00), \
11506 X(_uxtb, b2c0, fa5ff080), \
11507 X(_uxth, b280, fa1ff080), \
11508 X(_nop, bf00, f3af8000), \
11509 X(_yield, bf10, f3af8001), \
11510 X(_wfe, bf20, f3af8002), \
11511 X(_wfi, bf30, f3af8003), \
60f993ce 11512 X(_wls, 0000, f040c001), \
1f6234a3 11513 X(_wlstp, 0000, f000c001), \
53c4b28b 11514 X(_sev, bf40, f3af8004), \
74db7efb
NC
11515 X(_sevl, bf50, f3af8005), \
11516 X(_udf, de00, f7f0a000)
c19d1205
ZW
11517
11518/* To catch errors in encoding functions, the codes are all offset by
11519 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11520 as 16-bit instructions. */
21d799b5 11521#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11522enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11523#undef X
11524
11525#define X(a,b,c) 0x##b
11526static const unsigned short thumb_op16[] = { T16_32_TAB };
11527#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11528#undef X
11529
11530#define X(a,b,c) 0x##c
11531static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11532#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11533#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11534#undef X
11535#undef T16_32_TAB
11536
11537/* Thumb instruction encoders, in alphabetical order. */
11538
92e90b6e 11539/* ADDW or SUBW. */
c921be7d 11540
92e90b6e
PB
11541static void
11542do_t_add_sub_w (void)
11543{
11544 int Rd, Rn;
11545
11546 Rd = inst.operands[0].reg;
11547 Rn = inst.operands[1].reg;
11548
539d4391
NC
11549 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11550 is the SP-{plus,minus}-immediate form of the instruction. */
11551 if (Rn == REG_SP)
11552 constraint (Rd == REG_PC, BAD_PC);
11553 else
11554 reject_bad_reg (Rd);
fdfde340 11555
92e90b6e 11556 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11557 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11558}
11559
c19d1205 11560/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11561 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11562
11563static void
11564do_t_add_sub (void)
11565{
11566 int Rd, Rs, Rn;
11567
11568 Rd = inst.operands[0].reg;
11569 Rs = (inst.operands[1].present
11570 ? inst.operands[1].reg /* Rd, Rs, foo */
11571 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11572
e07e6e58 11573 if (Rd == REG_PC)
5ee91343 11574 set_pred_insn_type_last ();
e07e6e58 11575
c19d1205
ZW
11576 if (unified_syntax)
11577 {
0110f2b8
PB
11578 bfd_boolean flags;
11579 bfd_boolean narrow;
11580 int opcode;
11581
11582 flags = (inst.instruction == T_MNEM_adds
11583 || inst.instruction == T_MNEM_subs);
11584 if (flags)
5ee91343 11585 narrow = !in_pred_block ();
0110f2b8 11586 else
5ee91343 11587 narrow = in_pred_block ();
c19d1205 11588 if (!inst.operands[2].isreg)
b99bd4ef 11589 {
16805f35
PB
11590 int add;
11591
5c8ed6a4
JW
11592 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11593 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11594
16805f35
PB
11595 add = (inst.instruction == T_MNEM_add
11596 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11597 opcode = 0;
11598 if (inst.size_req != 4)
11599 {
0110f2b8 11600 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11601 appropriate. */
0110f2b8
PB
11602 if (Rd == REG_SP && Rs == REG_SP && !flags)
11603 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11604 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11605 opcode = T_MNEM_add_sp;
11606 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11607 opcode = T_MNEM_add_pc;
11608 else if (Rd <= 7 && Rs <= 7 && narrow)
11609 {
11610 if (flags)
11611 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11612 else
11613 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11614 }
11615 if (opcode)
11616 {
11617 inst.instruction = THUMB_OP16(opcode);
11618 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11619 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11620 || (inst.relocs[0].type
11621 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11622 {
11623 if (inst.size_req == 2)
e2b0ab59 11624 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11625 else
11626 inst.relax = opcode;
11627 }
0110f2b8
PB
11628 }
11629 else
11630 constraint (inst.size_req == 2, BAD_HIREG);
11631 }
11632 if (inst.size_req == 4
11633 || (inst.size_req != 2 && !opcode))
11634 {
e2b0ab59
AV
11635 constraint ((inst.relocs[0].type
11636 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11637 && (inst.relocs[0].type
11638 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11639 THUMB1_RELOC_ONLY);
efd81785
PB
11640 if (Rd == REG_PC)
11641 {
fdfde340 11642 constraint (add, BAD_PC);
efd81785
PB
11643 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11644 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11645 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11646 _("expression too complex"));
e2b0ab59
AV
11647 constraint (inst.relocs[0].exp.X_add_number < 0
11648 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11649 _("immediate value out of range"));
11650 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11651 | inst.relocs[0].exp.X_add_number;
11652 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11653 return;
11654 }
11655 else if (Rs == REG_PC)
16805f35
PB
11656 {
11657 /* Always use addw/subw. */
11658 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11659 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11660 }
11661 else
11662 {
11663 inst.instruction = THUMB_OP32 (inst.instruction);
11664 inst.instruction = (inst.instruction & 0xe1ffffff)
11665 | 0x10000000;
11666 if (flags)
e2b0ab59 11667 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11668 else
e2b0ab59 11669 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11670 }
dc4503c6
PB
11671 inst.instruction |= Rd << 8;
11672 inst.instruction |= Rs << 16;
0110f2b8 11673 }
b99bd4ef 11674 }
c19d1205
ZW
11675 else
11676 {
e2b0ab59 11677 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11678 unsigned int shift = inst.operands[2].shift_kind;
11679
c19d1205
ZW
11680 Rn = inst.operands[2].reg;
11681 /* See if we can do this with a 16-bit instruction. */
11682 if (!inst.operands[2].shifted && inst.size_req != 4)
11683 {
e27ec89e
PB
11684 if (Rd > 7 || Rs > 7 || Rn > 7)
11685 narrow = FALSE;
11686
11687 if (narrow)
c19d1205 11688 {
e27ec89e
PB
11689 inst.instruction = ((inst.instruction == T_MNEM_adds
11690 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11691 ? T_OPCODE_ADD_R3
11692 : T_OPCODE_SUB_R3);
11693 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11694 return;
11695 }
b99bd4ef 11696
7e806470 11697 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11698 {
7e806470
PB
11699 /* Thumb-1 cores (except v6-M) require at least one high
11700 register in a narrow non flag setting add. */
11701 if (Rd > 7 || Rn > 7
11702 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11703 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11704 {
7e806470
PB
11705 if (Rd == Rn)
11706 {
11707 Rn = Rs;
11708 Rs = Rd;
11709 }
c19d1205
ZW
11710 inst.instruction = T_OPCODE_ADD_HI;
11711 inst.instruction |= (Rd & 8) << 4;
11712 inst.instruction |= (Rd & 7);
11713 inst.instruction |= Rn << 3;
11714 return;
11715 }
c19d1205
ZW
11716 }
11717 }
c921be7d 11718
fdfde340 11719 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11720 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11721 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11722 constraint (Rs == REG_PC, BAD_PC);
11723 reject_bad_reg (Rn);
11724
c19d1205
ZW
11725 /* If we get here, it can't be done in 16 bits. */
11726 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11727 _("shift must be constant"));
11728 inst.instruction = THUMB_OP32 (inst.instruction);
11729 inst.instruction |= Rd << 8;
11730 inst.instruction |= Rs << 16;
5f4cb198
NC
11731 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11732 _("shift value over 3 not allowed in thumb mode"));
11733 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11734 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11735 encode_thumb32_shifted_operand (2);
11736 }
11737 }
11738 else
11739 {
11740 constraint (inst.instruction == T_MNEM_adds
11741 || inst.instruction == T_MNEM_subs,
11742 BAD_THUMB32);
b99bd4ef 11743
c19d1205 11744 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11745 {
c19d1205
ZW
11746 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11747 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11748 BAD_HIREG);
11749
11750 inst.instruction = (inst.instruction == T_MNEM_add
11751 ? 0x0000 : 0x8000);
11752 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11753 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11754 return;
11755 }
11756
c19d1205
ZW
11757 Rn = inst.operands[2].reg;
11758 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11759
c19d1205
ZW
11760 /* We now have Rd, Rs, and Rn set to registers. */
11761 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11762 {
c19d1205
ZW
11763 /* Can't do this for SUB. */
11764 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11765 inst.instruction = T_OPCODE_ADD_HI;
11766 inst.instruction |= (Rd & 8) << 4;
11767 inst.instruction |= (Rd & 7);
11768 if (Rs == Rd)
11769 inst.instruction |= Rn << 3;
11770 else if (Rn == Rd)
11771 inst.instruction |= Rs << 3;
11772 else
11773 constraint (1, _("dest must overlap one source register"));
11774 }
11775 else
11776 {
11777 inst.instruction = (inst.instruction == T_MNEM_add
11778 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11779 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11780 }
b99bd4ef 11781 }
b99bd4ef
NC
11782}
11783
c19d1205
ZW
11784static void
11785do_t_adr (void)
11786{
fdfde340
JM
11787 unsigned Rd;
11788
11789 Rd = inst.operands[0].reg;
11790 reject_bad_reg (Rd);
11791
11792 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11793 {
11794 /* Defer to section relaxation. */
11795 inst.relax = inst.instruction;
11796 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11797 inst.instruction |= Rd << 4;
0110f2b8
PB
11798 }
11799 else if (unified_syntax && inst.size_req != 2)
e9f89963 11800 {
0110f2b8 11801 /* Generate a 32-bit opcode. */
e9f89963 11802 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11803 inst.instruction |= Rd << 8;
e2b0ab59
AV
11804 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11805 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11806 }
11807 else
11808 {
0110f2b8 11809 /* Generate a 16-bit opcode. */
e9f89963 11810 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11811 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11812 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11813 inst.relocs[0].pc_rel = 1;
fdfde340 11814 inst.instruction |= Rd << 4;
e9f89963 11815 }
52a86f84 11816
e2b0ab59
AV
11817 if (inst.relocs[0].exp.X_op == O_symbol
11818 && inst.relocs[0].exp.X_add_symbol != NULL
11819 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11820 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11821 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11822}
b99bd4ef 11823
c19d1205
ZW
11824/* Arithmetic instructions for which there is just one 16-bit
11825 instruction encoding, and it allows only two low registers.
11826 For maximal compatibility with ARM syntax, we allow three register
11827 operands even when Thumb-32 instructions are not available, as long
11828 as the first two are identical. For instance, both "sbc r0,r1" and
11829 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11830static void
c19d1205 11831do_t_arit3 (void)
b99bd4ef 11832{
c19d1205 11833 int Rd, Rs, Rn;
b99bd4ef 11834
c19d1205
ZW
11835 Rd = inst.operands[0].reg;
11836 Rs = (inst.operands[1].present
11837 ? inst.operands[1].reg /* Rd, Rs, foo */
11838 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11839 Rn = inst.operands[2].reg;
b99bd4ef 11840
fdfde340
JM
11841 reject_bad_reg (Rd);
11842 reject_bad_reg (Rs);
11843 if (inst.operands[2].isreg)
11844 reject_bad_reg (Rn);
11845
c19d1205 11846 if (unified_syntax)
b99bd4ef 11847 {
c19d1205
ZW
11848 if (!inst.operands[2].isreg)
11849 {
11850 /* For an immediate, we always generate a 32-bit opcode;
11851 section relaxation will shrink it later if possible. */
11852 inst.instruction = THUMB_OP32 (inst.instruction);
11853 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11854 inst.instruction |= Rd << 8;
11855 inst.instruction |= Rs << 16;
e2b0ab59 11856 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11857 }
11858 else
11859 {
e27ec89e
PB
11860 bfd_boolean narrow;
11861
c19d1205 11862 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11863 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11864 narrow = !in_pred_block ();
e27ec89e 11865 else
5ee91343 11866 narrow = in_pred_block ();
e27ec89e
PB
11867
11868 if (Rd > 7 || Rn > 7 || Rs > 7)
11869 narrow = FALSE;
11870 if (inst.operands[2].shifted)
11871 narrow = FALSE;
11872 if (inst.size_req == 4)
11873 narrow = FALSE;
11874
11875 if (narrow
c19d1205
ZW
11876 && Rd == Rs)
11877 {
11878 inst.instruction = THUMB_OP16 (inst.instruction);
11879 inst.instruction |= Rd;
11880 inst.instruction |= Rn << 3;
11881 return;
11882 }
b99bd4ef 11883
c19d1205
ZW
11884 /* If we get here, it can't be done in 16 bits. */
11885 constraint (inst.operands[2].shifted
11886 && inst.operands[2].immisreg,
11887 _("shift must be constant"));
11888 inst.instruction = THUMB_OP32 (inst.instruction);
11889 inst.instruction |= Rd << 8;
11890 inst.instruction |= Rs << 16;
11891 encode_thumb32_shifted_operand (2);
11892 }
a737bd4d 11893 }
c19d1205 11894 else
b99bd4ef 11895 {
c19d1205
ZW
11896 /* On its face this is a lie - the instruction does set the
11897 flags. However, the only supported mnemonic in this mode
11898 says it doesn't. */
11899 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11900
c19d1205
ZW
11901 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11902 _("unshifted register required"));
11903 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11904 constraint (Rd != Rs,
11905 _("dest and source1 must be the same register"));
a737bd4d 11906
c19d1205
ZW
11907 inst.instruction = THUMB_OP16 (inst.instruction);
11908 inst.instruction |= Rd;
11909 inst.instruction |= Rn << 3;
b99bd4ef 11910 }
a737bd4d 11911}
b99bd4ef 11912
c19d1205
ZW
11913/* Similarly, but for instructions where the arithmetic operation is
11914 commutative, so we can allow either of them to be different from
11915 the destination operand in a 16-bit instruction. For instance, all
11916 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11917 accepted. */
11918static void
11919do_t_arit3c (void)
a737bd4d 11920{
c19d1205 11921 int Rd, Rs, Rn;
b99bd4ef 11922
c19d1205
ZW
11923 Rd = inst.operands[0].reg;
11924 Rs = (inst.operands[1].present
11925 ? inst.operands[1].reg /* Rd, Rs, foo */
11926 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11927 Rn = inst.operands[2].reg;
c921be7d 11928
fdfde340
JM
11929 reject_bad_reg (Rd);
11930 reject_bad_reg (Rs);
11931 if (inst.operands[2].isreg)
11932 reject_bad_reg (Rn);
a737bd4d 11933
c19d1205 11934 if (unified_syntax)
a737bd4d 11935 {
c19d1205 11936 if (!inst.operands[2].isreg)
b99bd4ef 11937 {
c19d1205
ZW
11938 /* For an immediate, we always generate a 32-bit opcode;
11939 section relaxation will shrink it later if possible. */
11940 inst.instruction = THUMB_OP32 (inst.instruction);
11941 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11942 inst.instruction |= Rd << 8;
11943 inst.instruction |= Rs << 16;
e2b0ab59 11944 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11945 }
c19d1205 11946 else
a737bd4d 11947 {
e27ec89e
PB
11948 bfd_boolean narrow;
11949
c19d1205 11950 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11951 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11952 narrow = !in_pred_block ();
e27ec89e 11953 else
5ee91343 11954 narrow = in_pred_block ();
e27ec89e
PB
11955
11956 if (Rd > 7 || Rn > 7 || Rs > 7)
11957 narrow = FALSE;
11958 if (inst.operands[2].shifted)
11959 narrow = FALSE;
11960 if (inst.size_req == 4)
11961 narrow = FALSE;
11962
11963 if (narrow)
a737bd4d 11964 {
c19d1205 11965 if (Rd == Rs)
a737bd4d 11966 {
c19d1205
ZW
11967 inst.instruction = THUMB_OP16 (inst.instruction);
11968 inst.instruction |= Rd;
11969 inst.instruction |= Rn << 3;
11970 return;
a737bd4d 11971 }
c19d1205 11972 if (Rd == Rn)
a737bd4d 11973 {
c19d1205
ZW
11974 inst.instruction = THUMB_OP16 (inst.instruction);
11975 inst.instruction |= Rd;
11976 inst.instruction |= Rs << 3;
11977 return;
a737bd4d
NC
11978 }
11979 }
c19d1205
ZW
11980
11981 /* If we get here, it can't be done in 16 bits. */
11982 constraint (inst.operands[2].shifted
11983 && inst.operands[2].immisreg,
11984 _("shift must be constant"));
11985 inst.instruction = THUMB_OP32 (inst.instruction);
11986 inst.instruction |= Rd << 8;
11987 inst.instruction |= Rs << 16;
11988 encode_thumb32_shifted_operand (2);
a737bd4d 11989 }
b99bd4ef 11990 }
c19d1205
ZW
11991 else
11992 {
11993 /* On its face this is a lie - the instruction does set the
11994 flags. However, the only supported mnemonic in this mode
11995 says it doesn't. */
11996 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11997
c19d1205
ZW
11998 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11999 _("unshifted register required"));
12000 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
12001
12002 inst.instruction = THUMB_OP16 (inst.instruction);
12003 inst.instruction |= Rd;
12004
12005 if (Rd == Rs)
12006 inst.instruction |= Rn << 3;
12007 else if (Rd == Rn)
12008 inst.instruction |= Rs << 3;
12009 else
12010 constraint (1, _("dest must overlap one source register"));
12011 }
a737bd4d
NC
12012}
12013
c19d1205
ZW
12014static void
12015do_t_bfc (void)
a737bd4d 12016{
fdfde340 12017 unsigned Rd;
c19d1205
ZW
12018 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12019 constraint (msb > 32, _("bit-field extends past end of register"));
12020 /* The instruction encoding stores the LSB and MSB,
12021 not the LSB and width. */
fdfde340
JM
12022 Rd = inst.operands[0].reg;
12023 reject_bad_reg (Rd);
12024 inst.instruction |= Rd << 8;
c19d1205
ZW
12025 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12026 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12027 inst.instruction |= msb - 1;
b99bd4ef
NC
12028}
12029
c19d1205
ZW
12030static void
12031do_t_bfi (void)
b99bd4ef 12032{
fdfde340 12033 int Rd, Rn;
c19d1205 12034 unsigned int msb;
b99bd4ef 12035
fdfde340
JM
12036 Rd = inst.operands[0].reg;
12037 reject_bad_reg (Rd);
12038
c19d1205
ZW
12039 /* #0 in second position is alternative syntax for bfc, which is
12040 the same instruction but with REG_PC in the Rm field. */
12041 if (!inst.operands[1].isreg)
fdfde340
JM
12042 Rn = REG_PC;
12043 else
12044 {
12045 Rn = inst.operands[1].reg;
12046 reject_bad_reg (Rn);
12047 }
b99bd4ef 12048
c19d1205
ZW
12049 msb = inst.operands[2].imm + inst.operands[3].imm;
12050 constraint (msb > 32, _("bit-field extends past end of register"));
12051 /* The instruction encoding stores the LSB and MSB,
12052 not the LSB and width. */
fdfde340
JM
12053 inst.instruction |= Rd << 8;
12054 inst.instruction |= Rn << 16;
c19d1205
ZW
12055 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12056 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12057 inst.instruction |= msb - 1;
b99bd4ef
NC
12058}
12059
c19d1205
ZW
12060static void
12061do_t_bfx (void)
b99bd4ef 12062{
fdfde340
JM
12063 unsigned Rd, Rn;
12064
12065 Rd = inst.operands[0].reg;
12066 Rn = inst.operands[1].reg;
12067
12068 reject_bad_reg (Rd);
12069 reject_bad_reg (Rn);
12070
c19d1205
ZW
12071 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12072 _("bit-field extends past end of register"));
fdfde340
JM
12073 inst.instruction |= Rd << 8;
12074 inst.instruction |= Rn << 16;
c19d1205
ZW
12075 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12076 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12077 inst.instruction |= inst.operands[3].imm - 1;
12078}
b99bd4ef 12079
c19d1205
ZW
12080/* ARM V5 Thumb BLX (argument parse)
12081 BLX <target_addr> which is BLX(1)
12082 BLX <Rm> which is BLX(2)
12083 Unfortunately, there are two different opcodes for this mnemonic.
12084 So, the insns[].value is not used, and the code here zaps values
12085 into inst.instruction.
b99bd4ef 12086
c19d1205
ZW
12087 ??? How to take advantage of the additional two bits of displacement
12088 available in Thumb32 mode? Need new relocation? */
b99bd4ef 12089
c19d1205
ZW
12090static void
12091do_t_blx (void)
12092{
5ee91343 12093 set_pred_insn_type_last ();
e07e6e58 12094
c19d1205 12095 if (inst.operands[0].isreg)
fdfde340
JM
12096 {
12097 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12098 /* We have a register, so this is BLX(2). */
12099 inst.instruction |= inst.operands[0].reg << 3;
12100 }
b99bd4ef
NC
12101 else
12102 {
c19d1205 12103 /* No register. This must be BLX(1). */
2fc8bdac 12104 inst.instruction = 0xf000e800;
0855e32b 12105 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
12106 }
12107}
12108
c19d1205
ZW
12109static void
12110do_t_branch (void)
b99bd4ef 12111{
0110f2b8 12112 int opcode;
dfa9f0d5 12113 int cond;
2fe88214 12114 bfd_reloc_code_real_type reloc;
dfa9f0d5 12115
e07e6e58 12116 cond = inst.cond;
5ee91343 12117 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 12118
5ee91343 12119 if (in_pred_block ())
dfa9f0d5
PB
12120 {
12121 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 12122 branches. */
dfa9f0d5 12123 cond = COND_ALWAYS;
dfa9f0d5
PB
12124 }
12125 else
12126 cond = inst.cond;
12127
12128 if (cond != COND_ALWAYS)
0110f2b8
PB
12129 opcode = T_MNEM_bcond;
12130 else
12131 opcode = inst.instruction;
12132
12d6b0b7
RS
12133 if (unified_syntax
12134 && (inst.size_req == 4
10960bfb
PB
12135 || (inst.size_req != 2
12136 && (inst.operands[0].hasreloc
e2b0ab59 12137 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 12138 {
0110f2b8 12139 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 12140 if (cond == COND_ALWAYS)
9ae92b05 12141 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
12142 else
12143 {
ff8646ee
TP
12144 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12145 _("selected architecture does not support "
12146 "wide conditional branch instruction"));
12147
9c2799c2 12148 gas_assert (cond != 0xF);
dfa9f0d5 12149 inst.instruction |= cond << 22;
9ae92b05 12150 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12151 }
12152 }
b99bd4ef
NC
12153 else
12154 {
0110f2b8 12155 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12156 if (cond == COND_ALWAYS)
9ae92b05 12157 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12158 else
b99bd4ef 12159 {
dfa9f0d5 12160 inst.instruction |= cond << 8;
9ae92b05 12161 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12162 }
0110f2b8
PB
12163 /* Allow section relaxation. */
12164 if (unified_syntax && inst.size_req != 2)
12165 inst.relax = opcode;
b99bd4ef 12166 }
e2b0ab59
AV
12167 inst.relocs[0].type = reloc;
12168 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12169}
12170
8884b720 12171/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12172 between the two is the maximum immediate allowed - which is passed in
8884b720 12173 RANGE. */
b99bd4ef 12174static void
8884b720 12175do_t_bkpt_hlt1 (int range)
b99bd4ef 12176{
dfa9f0d5
PB
12177 constraint (inst.cond != COND_ALWAYS,
12178 _("instruction is always unconditional"));
c19d1205 12179 if (inst.operands[0].present)
b99bd4ef 12180 {
8884b720 12181 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12182 _("immediate value out of range"));
12183 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12184 }
8884b720 12185
5ee91343 12186 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12187}
12188
12189static void
12190do_t_hlt (void)
12191{
12192 do_t_bkpt_hlt1 (63);
12193}
12194
12195static void
12196do_t_bkpt (void)
12197{
12198 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12199}
12200
12201static void
c19d1205 12202do_t_branch23 (void)
b99bd4ef 12203{
5ee91343 12204 set_pred_insn_type_last ();
0855e32b 12205 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12206
0855e32b
NS
12207 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12208 this file. We used to simply ignore the PLT reloc type here --
12209 the branch encoding is now needed to deal with TLSCALL relocs.
12210 So if we see a PLT reloc now, put it back to how it used to be to
12211 keep the preexisting behaviour. */
e2b0ab59
AV
12212 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12213 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12214
4343666d 12215#if defined(OBJ_COFF)
c19d1205
ZW
12216 /* If the destination of the branch is a defined symbol which does not have
12217 the THUMB_FUNC attribute, then we must be calling a function which has
12218 the (interfacearm) attribute. We look for the Thumb entry point to that
12219 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12220 if ( inst.relocs[0].exp.X_op == O_symbol
12221 && inst.relocs[0].exp.X_add_symbol != NULL
12222 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12223 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12224 inst.relocs[0].exp.X_add_symbol
12225 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12226#endif
90e4755a
RE
12227}
12228
12229static void
c19d1205 12230do_t_bx (void)
90e4755a 12231{
5ee91343 12232 set_pred_insn_type_last ();
c19d1205
ZW
12233 inst.instruction |= inst.operands[0].reg << 3;
12234 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12235 should cause the alignment to be checked once it is known. This is
12236 because BX PC only works if the instruction is word aligned. */
12237}
90e4755a 12238
c19d1205
ZW
12239static void
12240do_t_bxj (void)
12241{
fdfde340 12242 int Rm;
90e4755a 12243
5ee91343 12244 set_pred_insn_type_last ();
fdfde340
JM
12245 Rm = inst.operands[0].reg;
12246 reject_bad_reg (Rm);
12247 inst.instruction |= Rm << 16;
90e4755a
RE
12248}
12249
12250static void
c19d1205 12251do_t_clz (void)
90e4755a 12252{
fdfde340
JM
12253 unsigned Rd;
12254 unsigned Rm;
12255
12256 Rd = inst.operands[0].reg;
12257 Rm = inst.operands[1].reg;
12258
12259 reject_bad_reg (Rd);
12260 reject_bad_reg (Rm);
12261
12262 inst.instruction |= Rd << 8;
12263 inst.instruction |= Rm << 16;
12264 inst.instruction |= Rm;
c19d1205 12265}
90e4755a 12266
e39c1607
SD
12267/* For the Armv8.1-M conditional instructions. */
12268static void
12269do_t_cond (void)
12270{
12271 unsigned Rd, Rn, Rm;
12272 signed int cond;
12273
12274 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12275
12276 Rd = inst.operands[0].reg;
12277 switch (inst.instruction)
12278 {
12279 case T_MNEM_csinc:
12280 case T_MNEM_csinv:
12281 case T_MNEM_csneg:
12282 case T_MNEM_csel:
12283 Rn = inst.operands[1].reg;
12284 Rm = inst.operands[2].reg;
12285 cond = inst.operands[3].imm;
12286 constraint (Rn == REG_SP, BAD_SP);
12287 constraint (Rm == REG_SP, BAD_SP);
12288 break;
12289
12290 case T_MNEM_cinc:
12291 case T_MNEM_cinv:
12292 case T_MNEM_cneg:
12293 Rn = inst.operands[1].reg;
12294 cond = inst.operands[2].imm;
12295 /* Invert the last bit to invert the cond. */
12296 cond = TOGGLE_BIT (cond, 0);
12297 constraint (Rn == REG_SP, BAD_SP);
12298 Rm = Rn;
12299 break;
12300
12301 case T_MNEM_csetm:
12302 case T_MNEM_cset:
12303 cond = inst.operands[1].imm;
12304 /* Invert the last bit to invert the cond. */
12305 cond = TOGGLE_BIT (cond, 0);
12306 Rn = REG_PC;
12307 Rm = REG_PC;
12308 break;
12309
12310 default: abort ();
12311 }
12312
12313 set_pred_insn_type (OUTSIDE_PRED_INSN);
12314 inst.instruction = THUMB_OP32 (inst.instruction);
12315 inst.instruction |= Rd << 8;
12316 inst.instruction |= Rn << 16;
12317 inst.instruction |= Rm;
12318 inst.instruction |= cond << 4;
12319}
12320
91d8b670
JG
12321static void
12322do_t_csdb (void)
12323{
5ee91343 12324 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12325}
12326
dfa9f0d5
PB
12327static void
12328do_t_cps (void)
12329{
5ee91343 12330 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12331 inst.instruction |= inst.operands[0].imm;
12332}
12333
c19d1205
ZW
12334static void
12335do_t_cpsi (void)
12336{
5ee91343 12337 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12338 if (unified_syntax
62b3e311
PB
12339 && (inst.operands[1].present || inst.size_req == 4)
12340 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12341 {
c19d1205
ZW
12342 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12343 inst.instruction = 0xf3af8000;
12344 inst.instruction |= imod << 9;
12345 inst.instruction |= inst.operands[0].imm << 5;
12346 if (inst.operands[1].present)
12347 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12348 }
c19d1205 12349 else
90e4755a 12350 {
62b3e311
PB
12351 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12352 && (inst.operands[0].imm & 4),
12353 _("selected processor does not support 'A' form "
12354 "of this instruction"));
12355 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12356 _("Thumb does not support the 2-argument "
12357 "form of this instruction"));
12358 inst.instruction |= inst.operands[0].imm;
90e4755a 12359 }
90e4755a
RE
12360}
12361
c19d1205
ZW
12362/* THUMB CPY instruction (argument parse). */
12363
90e4755a 12364static void
c19d1205 12365do_t_cpy (void)
90e4755a 12366{
c19d1205 12367 if (inst.size_req == 4)
90e4755a 12368 {
c19d1205
ZW
12369 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12370 inst.instruction |= inst.operands[0].reg << 8;
12371 inst.instruction |= inst.operands[1].reg;
90e4755a 12372 }
c19d1205 12373 else
90e4755a 12374 {
c19d1205
ZW
12375 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12376 inst.instruction |= (inst.operands[0].reg & 0x7);
12377 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12378 }
90e4755a
RE
12379}
12380
90e4755a 12381static void
25fe350b 12382do_t_cbz (void)
90e4755a 12383{
5ee91343 12384 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12385 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12386 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12387 inst.relocs[0].pc_rel = 1;
12388 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12389}
90e4755a 12390
62b3e311
PB
12391static void
12392do_t_dbg (void)
12393{
12394 inst.instruction |= inst.operands[0].imm;
12395}
12396
12397static void
12398do_t_div (void)
12399{
fdfde340
JM
12400 unsigned Rd, Rn, Rm;
12401
12402 Rd = inst.operands[0].reg;
12403 Rn = (inst.operands[1].present
12404 ? inst.operands[1].reg : Rd);
12405 Rm = inst.operands[2].reg;
12406
12407 reject_bad_reg (Rd);
12408 reject_bad_reg (Rn);
12409 reject_bad_reg (Rm);
12410
12411 inst.instruction |= Rd << 8;
12412 inst.instruction |= Rn << 16;
12413 inst.instruction |= Rm;
62b3e311
PB
12414}
12415
c19d1205
ZW
12416static void
12417do_t_hint (void)
12418{
12419 if (unified_syntax && inst.size_req == 4)
12420 inst.instruction = THUMB_OP32 (inst.instruction);
12421 else
12422 inst.instruction = THUMB_OP16 (inst.instruction);
12423}
90e4755a 12424
c19d1205
ZW
12425static void
12426do_t_it (void)
12427{
12428 unsigned int cond = inst.operands[0].imm;
e27ec89e 12429
5ee91343
AV
12430 set_pred_insn_type (IT_INSN);
12431 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12432 now_pred.cc = cond;
12433 now_pred.warn_deprecated = FALSE;
12434 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12435
12436 /* If the condition is a negative condition, invert the mask. */
c19d1205 12437 if ((cond & 0x1) == 0x0)
90e4755a 12438 {
c19d1205 12439 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12440
c19d1205 12441 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12442 {
12443 /* No conversion needed. */
5ee91343 12444 now_pred.block_length = 1;
5a01bb1d 12445 }
c19d1205 12446 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12447 {
12448 mask ^= 0x8;
5ee91343 12449 now_pred.block_length = 2;
5a01bb1d 12450 }
e27ec89e 12451 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12452 {
12453 mask ^= 0xC;
5ee91343 12454 now_pred.block_length = 3;
5a01bb1d 12455 }
c19d1205 12456 else
5a01bb1d
MGD
12457 {
12458 mask ^= 0xE;
5ee91343 12459 now_pred.block_length = 4;
5a01bb1d 12460 }
90e4755a 12461
e27ec89e
PB
12462 inst.instruction &= 0xfff0;
12463 inst.instruction |= mask;
c19d1205 12464 }
90e4755a 12465
c19d1205
ZW
12466 inst.instruction |= cond << 4;
12467}
90e4755a 12468
3c707909
PB
12469/* Helper function used for both push/pop and ldm/stm. */
12470static void
4b5a202f
AV
12471encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12472 bfd_boolean writeback)
3c707909 12473{
4b5a202f 12474 bfd_boolean load, store;
3c707909 12475
4b5a202f
AV
12476 gas_assert (base != -1 || !do_io);
12477 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12478 store = do_io && !load;
3c707909
PB
12479
12480 if (mask & (1 << 13))
12481 inst.error = _("SP not allowed in register list");
1e5b0379 12482
4b5a202f 12483 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12484 && writeback)
12485 inst.error = _("having the base register in the register list when "
12486 "using write back is UNPREDICTABLE");
12487
3c707909
PB
12488 if (load)
12489 {
e07e6e58 12490 if (mask & (1 << 15))
477330fc
RM
12491 {
12492 if (mask & (1 << 14))
12493 inst.error = _("LR and PC should not both be in register list");
12494 else
5ee91343 12495 set_pred_insn_type_last ();
477330fc 12496 }
3c707909 12497 }
4b5a202f 12498 else if (store)
3c707909
PB
12499 {
12500 if (mask & (1 << 15))
12501 inst.error = _("PC not allowed in register list");
3c707909
PB
12502 }
12503
4b5a202f 12504 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12505 {
12506 /* Single register transfers implemented as str/ldr. */
12507 if (writeback)
12508 {
12509 if (inst.instruction & (1 << 23))
12510 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12511 else
12512 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12513 }
12514 else
12515 {
12516 if (inst.instruction & (1 << 23))
12517 inst.instruction = 0x00800000; /* ia -> [base] */
12518 else
12519 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12520 }
12521
12522 inst.instruction |= 0xf8400000;
12523 if (load)
12524 inst.instruction |= 0x00100000;
12525
5f4273c7 12526 mask = ffs (mask) - 1;
3c707909
PB
12527 mask <<= 12;
12528 }
12529 else if (writeback)
12530 inst.instruction |= WRITE_BACK;
12531
12532 inst.instruction |= mask;
4b5a202f
AV
12533 if (do_io)
12534 inst.instruction |= base << 16;
3c707909
PB
12535}
12536
c19d1205
ZW
12537static void
12538do_t_ldmstm (void)
12539{
12540 /* This really doesn't seem worth it. */
e2b0ab59 12541 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12542 _("expression too complex"));
12543 constraint (inst.operands[1].writeback,
12544 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12545
c19d1205
ZW
12546 if (unified_syntax)
12547 {
3c707909
PB
12548 bfd_boolean narrow;
12549 unsigned mask;
12550
12551 narrow = FALSE;
c19d1205
ZW
12552 /* See if we can use a 16-bit instruction. */
12553 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12554 && inst.size_req != 4
3c707909 12555 && !(inst.operands[1].imm & ~0xff))
90e4755a 12556 {
3c707909 12557 mask = 1 << inst.operands[0].reg;
90e4755a 12558
eab4f823 12559 if (inst.operands[0].reg <= 7)
90e4755a 12560 {
3c707909 12561 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12562 ? inst.operands[0].writeback
12563 : (inst.operands[0].writeback
12564 == !(inst.operands[1].imm & mask)))
477330fc 12565 {
eab4f823
MGD
12566 if (inst.instruction == T_MNEM_stmia
12567 && (inst.operands[1].imm & mask)
12568 && (inst.operands[1].imm & (mask - 1)))
12569 as_warn (_("value stored for r%d is UNKNOWN"),
12570 inst.operands[0].reg);
3c707909 12571
eab4f823
MGD
12572 inst.instruction = THUMB_OP16 (inst.instruction);
12573 inst.instruction |= inst.operands[0].reg << 8;
12574 inst.instruction |= inst.operands[1].imm;
12575 narrow = TRUE;
12576 }
12577 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12578 {
12579 /* This means 1 register in reg list one of 3 situations:
12580 1. Instruction is stmia, but without writeback.
12581 2. lmdia without writeback, but with Rn not in
477330fc 12582 reglist.
eab4f823
MGD
12583 3. ldmia with writeback, but with Rn in reglist.
12584 Case 3 is UNPREDICTABLE behaviour, so we handle
12585 case 1 and 2 which can be converted into a 16-bit
12586 str or ldr. The SP cases are handled below. */
12587 unsigned long opcode;
12588 /* First, record an error for Case 3. */
12589 if (inst.operands[1].imm & mask
12590 && inst.operands[0].writeback)
fa94de6b 12591 inst.error =
eab4f823
MGD
12592 _("having the base register in the register list when "
12593 "using write back is UNPREDICTABLE");
fa94de6b
RM
12594
12595 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12596 : T_MNEM_ldr);
12597 inst.instruction = THUMB_OP16 (opcode);
12598 inst.instruction |= inst.operands[0].reg << 3;
12599 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12600 narrow = TRUE;
12601 }
90e4755a 12602 }
eab4f823 12603 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12604 {
eab4f823
MGD
12605 if (inst.operands[0].writeback)
12606 {
fa94de6b 12607 inst.instruction =
eab4f823 12608 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12609 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12610 inst.instruction |= inst.operands[1].imm;
477330fc 12611 narrow = TRUE;
eab4f823
MGD
12612 }
12613 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12614 {
fa94de6b 12615 inst.instruction =
eab4f823 12616 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12617 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12618 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12619 narrow = TRUE;
eab4f823 12620 }
90e4755a 12621 }
3c707909
PB
12622 }
12623
12624 if (!narrow)
12625 {
c19d1205
ZW
12626 if (inst.instruction < 0xffff)
12627 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12628
4b5a202f
AV
12629 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12630 inst.operands[1].imm,
12631 inst.operands[0].writeback);
90e4755a
RE
12632 }
12633 }
c19d1205 12634 else
90e4755a 12635 {
c19d1205
ZW
12636 constraint (inst.operands[0].reg > 7
12637 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12638 constraint (inst.instruction != T_MNEM_ldmia
12639 && inst.instruction != T_MNEM_stmia,
12640 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12641 if (inst.instruction == T_MNEM_stmia)
f03698e6 12642 {
c19d1205
ZW
12643 if (!inst.operands[0].writeback)
12644 as_warn (_("this instruction will write back the base register"));
12645 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12646 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12647 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12648 inst.operands[0].reg);
f03698e6 12649 }
c19d1205 12650 else
90e4755a 12651 {
c19d1205
ZW
12652 if (!inst.operands[0].writeback
12653 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12654 as_warn (_("this instruction will write back the base register"));
12655 else if (inst.operands[0].writeback
12656 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12657 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12658 }
12659
c19d1205
ZW
12660 inst.instruction = THUMB_OP16 (inst.instruction);
12661 inst.instruction |= inst.operands[0].reg << 8;
12662 inst.instruction |= inst.operands[1].imm;
12663 }
12664}
e28cd48c 12665
c19d1205
ZW
12666static void
12667do_t_ldrex (void)
12668{
12669 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12670 || inst.operands[1].postind || inst.operands[1].writeback
12671 || inst.operands[1].immisreg || inst.operands[1].shifted
12672 || inst.operands[1].negative,
01cfc07f 12673 BAD_ADDR_MODE);
e28cd48c 12674
5be8be5d
DG
12675 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12676
c19d1205
ZW
12677 inst.instruction |= inst.operands[0].reg << 12;
12678 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12679 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12680}
e28cd48c 12681
c19d1205
ZW
12682static void
12683do_t_ldrexd (void)
12684{
12685 if (!inst.operands[1].present)
1cac9012 12686 {
c19d1205
ZW
12687 constraint (inst.operands[0].reg == REG_LR,
12688 _("r14 not allowed as first register "
12689 "when second register is omitted"));
12690 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12691 }
c19d1205
ZW
12692 constraint (inst.operands[0].reg == inst.operands[1].reg,
12693 BAD_OVERLAP);
b99bd4ef 12694
c19d1205
ZW
12695 inst.instruction |= inst.operands[0].reg << 12;
12696 inst.instruction |= inst.operands[1].reg << 8;
12697 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12698}
12699
12700static void
c19d1205 12701do_t_ldst (void)
b99bd4ef 12702{
0110f2b8
PB
12703 unsigned long opcode;
12704 int Rn;
12705
e07e6e58
NC
12706 if (inst.operands[0].isreg
12707 && !inst.operands[0].preind
12708 && inst.operands[0].reg == REG_PC)
5ee91343 12709 set_pred_insn_type_last ();
e07e6e58 12710
0110f2b8 12711 opcode = inst.instruction;
c19d1205 12712 if (unified_syntax)
b99bd4ef 12713 {
53365c0d
PB
12714 if (!inst.operands[1].isreg)
12715 {
12716 if (opcode <= 0xffff)
12717 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12718 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12719 return;
12720 }
0110f2b8
PB
12721 if (inst.operands[1].isreg
12722 && !inst.operands[1].writeback
c19d1205
ZW
12723 && !inst.operands[1].shifted && !inst.operands[1].postind
12724 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12725 && opcode <= 0xffff
12726 && inst.size_req != 4)
c19d1205 12727 {
0110f2b8
PB
12728 /* Insn may have a 16-bit form. */
12729 Rn = inst.operands[1].reg;
12730 if (inst.operands[1].immisreg)
12731 {
12732 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12733 /* [Rn, Rik] */
0110f2b8
PB
12734 if (Rn <= 7 && inst.operands[1].imm <= 7)
12735 goto op16;
5be8be5d
DG
12736 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12737 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12738 }
12739 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12740 && opcode != T_MNEM_ldrsb)
12741 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12742 || (Rn == REG_SP && opcode == T_MNEM_str))
12743 {
12744 /* [Rn, #const] */
12745 if (Rn > 7)
12746 {
12747 if (Rn == REG_PC)
12748 {
e2b0ab59 12749 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12750 opcode = T_MNEM_ldr_pc2;
12751 else
12752 opcode = T_MNEM_ldr_pc;
12753 }
12754 else
12755 {
12756 if (opcode == T_MNEM_ldr)
12757 opcode = T_MNEM_ldr_sp;
12758 else
12759 opcode = T_MNEM_str_sp;
12760 }
12761 inst.instruction = inst.operands[0].reg << 8;
12762 }
12763 else
12764 {
12765 inst.instruction = inst.operands[0].reg;
12766 inst.instruction |= inst.operands[1].reg << 3;
12767 }
12768 inst.instruction |= THUMB_OP16 (opcode);
12769 if (inst.size_req == 2)
e2b0ab59 12770 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12771 else
12772 inst.relax = opcode;
12773 return;
12774 }
c19d1205 12775 }
0110f2b8 12776 /* Definitely a 32-bit variant. */
5be8be5d 12777
8d67f500
NC
12778 /* Warning for Erratum 752419. */
12779 if (opcode == T_MNEM_ldr
12780 && inst.operands[0].reg == REG_SP
12781 && inst.operands[1].writeback == 1
12782 && !inst.operands[1].immisreg)
12783 {
12784 if (no_cpu_selected ()
12785 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12786 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12787 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12788 as_warn (_("This instruction may be unpredictable "
12789 "if executed on M-profile cores "
12790 "with interrupts enabled."));
12791 }
12792
5be8be5d 12793 /* Do some validations regarding addressing modes. */
1be5fd2e 12794 if (inst.operands[1].immisreg)
5be8be5d
DG
12795 reject_bad_reg (inst.operands[1].imm);
12796
1be5fd2e
NC
12797 constraint (inst.operands[1].writeback == 1
12798 && inst.operands[0].reg == inst.operands[1].reg,
12799 BAD_OVERLAP);
12800
0110f2b8 12801 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12802 inst.instruction |= inst.operands[0].reg << 12;
12803 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12804 check_ldr_r15_aligned ();
b99bd4ef
NC
12805 return;
12806 }
12807
c19d1205
ZW
12808 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12809
12810 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12811 {
c19d1205
ZW
12812 /* Only [Rn,Rm] is acceptable. */
12813 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12814 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12815 || inst.operands[1].postind || inst.operands[1].shifted
12816 || inst.operands[1].negative,
12817 _("Thumb does not support this addressing mode"));
12818 inst.instruction = THUMB_OP16 (inst.instruction);
12819 goto op16;
b99bd4ef 12820 }
5f4273c7 12821
c19d1205
ZW
12822 inst.instruction = THUMB_OP16 (inst.instruction);
12823 if (!inst.operands[1].isreg)
8335d6aa 12824 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12825 return;
b99bd4ef 12826
c19d1205
ZW
12827 constraint (!inst.operands[1].preind
12828 || inst.operands[1].shifted
12829 || inst.operands[1].writeback,
12830 _("Thumb does not support this addressing mode"));
12831 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12832 {
c19d1205
ZW
12833 constraint (inst.instruction & 0x0600,
12834 _("byte or halfword not valid for base register"));
12835 constraint (inst.operands[1].reg == REG_PC
12836 && !(inst.instruction & THUMB_LOAD_BIT),
12837 _("r15 based store not allowed"));
12838 constraint (inst.operands[1].immisreg,
12839 _("invalid base register for register offset"));
b99bd4ef 12840
c19d1205
ZW
12841 if (inst.operands[1].reg == REG_PC)
12842 inst.instruction = T_OPCODE_LDR_PC;
12843 else if (inst.instruction & THUMB_LOAD_BIT)
12844 inst.instruction = T_OPCODE_LDR_SP;
12845 else
12846 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12847
c19d1205 12848 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12849 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12850 return;
12851 }
90e4755a 12852
c19d1205
ZW
12853 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12854 if (!inst.operands[1].immisreg)
12855 {
12856 /* Immediate offset. */
12857 inst.instruction |= inst.operands[0].reg;
12858 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12859 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12860 return;
12861 }
90e4755a 12862
c19d1205
ZW
12863 /* Register offset. */
12864 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12865 constraint (inst.operands[1].negative,
12866 _("Thumb does not support this addressing mode"));
90e4755a 12867
c19d1205
ZW
12868 op16:
12869 switch (inst.instruction)
12870 {
12871 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12872 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12873 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12874 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12875 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12876 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12877 case 0x5600 /* ldrsb */:
12878 case 0x5e00 /* ldrsh */: break;
12879 default: abort ();
12880 }
90e4755a 12881
c19d1205
ZW
12882 inst.instruction |= inst.operands[0].reg;
12883 inst.instruction |= inst.operands[1].reg << 3;
12884 inst.instruction |= inst.operands[1].imm << 6;
12885}
90e4755a 12886
c19d1205
ZW
12887static void
12888do_t_ldstd (void)
12889{
12890 if (!inst.operands[1].present)
b99bd4ef 12891 {
c19d1205
ZW
12892 inst.operands[1].reg = inst.operands[0].reg + 1;
12893 constraint (inst.operands[0].reg == REG_LR,
12894 _("r14 not allowed here"));
bd340a04 12895 constraint (inst.operands[0].reg == REG_R12,
477330fc 12896 _("r12 not allowed here"));
b99bd4ef 12897 }
bd340a04
MGD
12898
12899 if (inst.operands[2].writeback
12900 && (inst.operands[0].reg == inst.operands[2].reg
12901 || inst.operands[1].reg == inst.operands[2].reg))
12902 as_warn (_("base register written back, and overlaps "
477330fc 12903 "one of transfer registers"));
bd340a04 12904
c19d1205
ZW
12905 inst.instruction |= inst.operands[0].reg << 12;
12906 inst.instruction |= inst.operands[1].reg << 8;
12907 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12908}
12909
c19d1205
ZW
12910static void
12911do_t_ldstt (void)
12912{
12913 inst.instruction |= inst.operands[0].reg << 12;
12914 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12915}
a737bd4d 12916
b99bd4ef 12917static void
c19d1205 12918do_t_mla (void)
b99bd4ef 12919{
fdfde340 12920 unsigned Rd, Rn, Rm, Ra;
c921be7d 12921
fdfde340
JM
12922 Rd = inst.operands[0].reg;
12923 Rn = inst.operands[1].reg;
12924 Rm = inst.operands[2].reg;
12925 Ra = inst.operands[3].reg;
12926
12927 reject_bad_reg (Rd);
12928 reject_bad_reg (Rn);
12929 reject_bad_reg (Rm);
12930 reject_bad_reg (Ra);
12931
12932 inst.instruction |= Rd << 8;
12933 inst.instruction |= Rn << 16;
12934 inst.instruction |= Rm;
12935 inst.instruction |= Ra << 12;
c19d1205 12936}
b99bd4ef 12937
c19d1205
ZW
12938static void
12939do_t_mlal (void)
12940{
fdfde340
JM
12941 unsigned RdLo, RdHi, Rn, Rm;
12942
12943 RdLo = inst.operands[0].reg;
12944 RdHi = inst.operands[1].reg;
12945 Rn = inst.operands[2].reg;
12946 Rm = inst.operands[3].reg;
12947
12948 reject_bad_reg (RdLo);
12949 reject_bad_reg (RdHi);
12950 reject_bad_reg (Rn);
12951 reject_bad_reg (Rm);
12952
12953 inst.instruction |= RdLo << 12;
12954 inst.instruction |= RdHi << 8;
12955 inst.instruction |= Rn << 16;
12956 inst.instruction |= Rm;
c19d1205 12957}
b99bd4ef 12958
c19d1205
ZW
12959static void
12960do_t_mov_cmp (void)
12961{
fdfde340
JM
12962 unsigned Rn, Rm;
12963
12964 Rn = inst.operands[0].reg;
12965 Rm = inst.operands[1].reg;
12966
e07e6e58 12967 if (Rn == REG_PC)
5ee91343 12968 set_pred_insn_type_last ();
e07e6e58 12969
c19d1205 12970 if (unified_syntax)
b99bd4ef 12971 {
c19d1205
ZW
12972 int r0off = (inst.instruction == T_MNEM_mov
12973 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12974 unsigned long opcode;
3d388997
PB
12975 bfd_boolean narrow;
12976 bfd_boolean low_regs;
12977
fdfde340 12978 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12979 opcode = inst.instruction;
5ee91343 12980 if (in_pred_block ())
0110f2b8 12981 narrow = opcode != T_MNEM_movs;
3d388997 12982 else
0110f2b8 12983 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12984 if (inst.size_req == 4
12985 || inst.operands[1].shifted)
12986 narrow = FALSE;
12987
efd81785
PB
12988 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12989 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12990 && !inst.operands[1].shifted
fdfde340
JM
12991 && Rn == REG_PC
12992 && Rm == REG_LR)
efd81785
PB
12993 {
12994 inst.instruction = T2_SUBS_PC_LR;
12995 return;
12996 }
12997
fdfde340
JM
12998 if (opcode == T_MNEM_cmp)
12999 {
13000 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
13001 if (narrow)
13002 {
13003 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13004 but valid. */
13005 warn_deprecated_sp (Rm);
13006 /* R15 was documented as a valid choice for Rm in ARMv6,
13007 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13008 tools reject R15, so we do too. */
13009 constraint (Rm == REG_PC, BAD_PC);
13010 }
13011 else
13012 reject_bad_reg (Rm);
fdfde340
JM
13013 }
13014 else if (opcode == T_MNEM_mov
13015 || opcode == T_MNEM_movs)
13016 {
13017 if (inst.operands[1].isreg)
13018 {
13019 if (opcode == T_MNEM_movs)
13020 {
13021 reject_bad_reg (Rn);
13022 reject_bad_reg (Rm);
13023 }
76fa04a4
MGD
13024 else if (narrow)
13025 {
13026 /* This is mov.n. */
13027 if ((Rn == REG_SP || Rn == REG_PC)
13028 && (Rm == REG_SP || Rm == REG_PC))
13029 {
5c3696f8 13030 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
13031 "deprecated when r%u is the destination "
13032 "register."), Rm, Rn);
13033 }
13034 }
13035 else
13036 {
13037 /* This is mov.w. */
13038 constraint (Rn == REG_PC, BAD_PC);
13039 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
13040 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13041 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 13042 }
fdfde340
JM
13043 }
13044 else
13045 reject_bad_reg (Rn);
13046 }
13047
c19d1205
ZW
13048 if (!inst.operands[1].isreg)
13049 {
0110f2b8 13050 /* Immediate operand. */
5ee91343 13051 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
13052 narrow = 0;
13053 if (low_regs && narrow)
13054 {
13055 inst.instruction = THUMB_OP16 (opcode);
fdfde340 13056 inst.instruction |= Rn << 8;
e2b0ab59
AV
13057 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13058 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 13059 {
a9f02af8 13060 if (inst.size_req == 2)
e2b0ab59 13061 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
13062 else
13063 inst.relax = opcode;
72d98d16 13064 }
0110f2b8
PB
13065 }
13066 else
13067 {
e2b0ab59
AV
13068 constraint ((inst.relocs[0].type
13069 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13070 && (inst.relocs[0].type
13071 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
13072 THUMB1_RELOC_ONLY);
13073
0110f2b8
PB
13074 inst.instruction = THUMB_OP32 (inst.instruction);
13075 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13076 inst.instruction |= Rn << r0off;
e2b0ab59 13077 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 13078 }
c19d1205 13079 }
728ca7c9
PB
13080 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13081 && (inst.instruction == T_MNEM_mov
13082 || inst.instruction == T_MNEM_movs))
13083 {
13084 /* Register shifts are encoded as separate shift instructions. */
13085 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13086
5ee91343 13087 if (in_pred_block ())
728ca7c9
PB
13088 narrow = !flags;
13089 else
13090 narrow = flags;
13091
13092 if (inst.size_req == 4)
13093 narrow = FALSE;
13094
13095 if (!low_regs || inst.operands[1].imm > 7)
13096 narrow = FALSE;
13097
fdfde340 13098 if (Rn != Rm)
728ca7c9
PB
13099 narrow = FALSE;
13100
13101 switch (inst.operands[1].shift_kind)
13102 {
13103 case SHIFT_LSL:
13104 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13105 break;
13106 case SHIFT_ASR:
13107 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13108 break;
13109 case SHIFT_LSR:
13110 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13111 break;
13112 case SHIFT_ROR:
13113 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13114 break;
13115 default:
5f4273c7 13116 abort ();
728ca7c9
PB
13117 }
13118
13119 inst.instruction = opcode;
13120 if (narrow)
13121 {
fdfde340 13122 inst.instruction |= Rn;
728ca7c9
PB
13123 inst.instruction |= inst.operands[1].imm << 3;
13124 }
13125 else
13126 {
13127 if (flags)
13128 inst.instruction |= CONDS_BIT;
13129
fdfde340
JM
13130 inst.instruction |= Rn << 8;
13131 inst.instruction |= Rm << 16;
728ca7c9
PB
13132 inst.instruction |= inst.operands[1].imm;
13133 }
13134 }
3d388997 13135 else if (!narrow)
c19d1205 13136 {
728ca7c9
PB
13137 /* Some mov with immediate shift have narrow variants.
13138 Register shifts are handled above. */
13139 if (low_regs && inst.operands[1].shifted
13140 && (inst.instruction == T_MNEM_mov
13141 || inst.instruction == T_MNEM_movs))
13142 {
5ee91343 13143 if (in_pred_block ())
728ca7c9
PB
13144 narrow = (inst.instruction == T_MNEM_mov);
13145 else
13146 narrow = (inst.instruction == T_MNEM_movs);
13147 }
13148
13149 if (narrow)
13150 {
13151 switch (inst.operands[1].shift_kind)
13152 {
13153 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13154 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13155 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13156 default: narrow = FALSE; break;
13157 }
13158 }
13159
13160 if (narrow)
13161 {
fdfde340
JM
13162 inst.instruction |= Rn;
13163 inst.instruction |= Rm << 3;
e2b0ab59 13164 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13165 }
13166 else
13167 {
13168 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13169 inst.instruction |= Rn << r0off;
728ca7c9
PB
13170 encode_thumb32_shifted_operand (1);
13171 }
c19d1205
ZW
13172 }
13173 else
13174 switch (inst.instruction)
13175 {
13176 case T_MNEM_mov:
837b3435 13177 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13178 results. Don't allow this. */
13179 if (low_regs)
13180 {
13181 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13182 "MOV Rd, Rs with two low registers is not "
13183 "permitted on this architecture");
fa94de6b 13184 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13185 arm_ext_v6);
13186 }
13187
c19d1205 13188 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13189 inst.instruction |= (Rn & 0x8) << 4;
13190 inst.instruction |= (Rn & 0x7);
13191 inst.instruction |= Rm << 3;
c19d1205 13192 break;
b99bd4ef 13193
c19d1205
ZW
13194 case T_MNEM_movs:
13195 /* We know we have low registers at this point.
941a8a52
MGD
13196 Generate LSLS Rd, Rs, #0. */
13197 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13198 inst.instruction |= Rn;
13199 inst.instruction |= Rm << 3;
c19d1205
ZW
13200 break;
13201
13202 case T_MNEM_cmp:
3d388997 13203 if (low_regs)
c19d1205
ZW
13204 {
13205 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13206 inst.instruction |= Rn;
13207 inst.instruction |= Rm << 3;
c19d1205
ZW
13208 }
13209 else
13210 {
13211 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13212 inst.instruction |= (Rn & 0x8) << 4;
13213 inst.instruction |= (Rn & 0x7);
13214 inst.instruction |= Rm << 3;
c19d1205
ZW
13215 }
13216 break;
13217 }
b99bd4ef
NC
13218 return;
13219 }
13220
c19d1205 13221 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13222
13223 /* PR 10443: Do not silently ignore shifted operands. */
13224 constraint (inst.operands[1].shifted,
13225 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13226
c19d1205 13227 if (inst.operands[1].isreg)
b99bd4ef 13228 {
fdfde340 13229 if (Rn < 8 && Rm < 8)
b99bd4ef 13230 {
c19d1205
ZW
13231 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13232 since a MOV instruction produces unpredictable results. */
13233 if (inst.instruction == T_OPCODE_MOV_I8)
13234 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13235 else
c19d1205 13236 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13237
fdfde340
JM
13238 inst.instruction |= Rn;
13239 inst.instruction |= Rm << 3;
b99bd4ef
NC
13240 }
13241 else
13242 {
c19d1205
ZW
13243 if (inst.instruction == T_OPCODE_MOV_I8)
13244 inst.instruction = T_OPCODE_MOV_HR;
13245 else
13246 inst.instruction = T_OPCODE_CMP_HR;
13247 do_t_cpy ();
b99bd4ef
NC
13248 }
13249 }
c19d1205 13250 else
b99bd4ef 13251 {
fdfde340 13252 constraint (Rn > 7,
c19d1205 13253 _("only lo regs allowed with immediate"));
fdfde340 13254 inst.instruction |= Rn << 8;
e2b0ab59 13255 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13256 }
13257}
b99bd4ef 13258
c19d1205
ZW
13259static void
13260do_t_mov16 (void)
13261{
fdfde340 13262 unsigned Rd;
b6895b4f
PB
13263 bfd_vma imm;
13264 bfd_boolean top;
13265
13266 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13267 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13268 {
33eaf5de 13269 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13270 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13271 }
e2b0ab59 13272 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13273 {
33eaf5de 13274 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13275 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13276 }
13277
fdfde340
JM
13278 Rd = inst.operands[0].reg;
13279 reject_bad_reg (Rd);
13280
13281 inst.instruction |= Rd << 8;
e2b0ab59 13282 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13283 {
e2b0ab59 13284 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13285 inst.instruction |= (imm & 0xf000) << 4;
13286 inst.instruction |= (imm & 0x0800) << 15;
13287 inst.instruction |= (imm & 0x0700) << 4;
13288 inst.instruction |= (imm & 0x00ff);
13289 }
c19d1205 13290}
b99bd4ef 13291
c19d1205
ZW
13292static void
13293do_t_mvn_tst (void)
13294{
fdfde340 13295 unsigned Rn, Rm;
c921be7d 13296
fdfde340
JM
13297 Rn = inst.operands[0].reg;
13298 Rm = inst.operands[1].reg;
13299
13300 if (inst.instruction == T_MNEM_cmp
13301 || inst.instruction == T_MNEM_cmn)
13302 constraint (Rn == REG_PC, BAD_PC);
13303 else
13304 reject_bad_reg (Rn);
13305 reject_bad_reg (Rm);
13306
c19d1205
ZW
13307 if (unified_syntax)
13308 {
13309 int r0off = (inst.instruction == T_MNEM_mvn
13310 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13311 bfd_boolean narrow;
13312
13313 if (inst.size_req == 4
13314 || inst.instruction > 0xffff
13315 || inst.operands[1].shifted
fdfde340 13316 || Rn > 7 || Rm > 7)
3d388997 13317 narrow = FALSE;
fe8b4cc3
KT
13318 else if (inst.instruction == T_MNEM_cmn
13319 || inst.instruction == T_MNEM_tst)
3d388997
PB
13320 narrow = TRUE;
13321 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13322 narrow = !in_pred_block ();
3d388997 13323 else
5ee91343 13324 narrow = in_pred_block ();
3d388997 13325
c19d1205 13326 if (!inst.operands[1].isreg)
b99bd4ef 13327 {
c19d1205
ZW
13328 /* For an immediate, we always generate a 32-bit opcode;
13329 section relaxation will shrink it later if possible. */
13330 if (inst.instruction < 0xffff)
13331 inst.instruction = THUMB_OP32 (inst.instruction);
13332 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13333 inst.instruction |= Rn << r0off;
e2b0ab59 13334 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13335 }
c19d1205 13336 else
b99bd4ef 13337 {
c19d1205 13338 /* See if we can do this with a 16-bit instruction. */
3d388997 13339 if (narrow)
b99bd4ef 13340 {
c19d1205 13341 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13342 inst.instruction |= Rn;
13343 inst.instruction |= Rm << 3;
b99bd4ef 13344 }
c19d1205 13345 else
b99bd4ef 13346 {
c19d1205
ZW
13347 constraint (inst.operands[1].shifted
13348 && inst.operands[1].immisreg,
13349 _("shift must be constant"));
13350 if (inst.instruction < 0xffff)
13351 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13352 inst.instruction |= Rn << r0off;
c19d1205 13353 encode_thumb32_shifted_operand (1);
b99bd4ef 13354 }
b99bd4ef
NC
13355 }
13356 }
13357 else
13358 {
c19d1205
ZW
13359 constraint (inst.instruction > 0xffff
13360 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13361 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13362 _("unshifted register required"));
fdfde340 13363 constraint (Rn > 7 || Rm > 7,
c19d1205 13364 BAD_HIREG);
b99bd4ef 13365
c19d1205 13366 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13367 inst.instruction |= Rn;
13368 inst.instruction |= Rm << 3;
b99bd4ef 13369 }
b99bd4ef
NC
13370}
13371
b05fe5cf 13372static void
c19d1205 13373do_t_mrs (void)
b05fe5cf 13374{
fdfde340 13375 unsigned Rd;
037e8744
JB
13376
13377 if (do_vfp_nsyn_mrs () == SUCCESS)
13378 return;
13379
90ec0d68
MGD
13380 Rd = inst.operands[0].reg;
13381 reject_bad_reg (Rd);
13382 inst.instruction |= Rd << 8;
13383
13384 if (inst.operands[1].isreg)
62b3e311 13385 {
90ec0d68
MGD
13386 unsigned br = inst.operands[1].reg;
13387 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13388 as_bad (_("bad register for mrs"));
13389
13390 inst.instruction |= br & (0xf << 16);
13391 inst.instruction |= (br & 0x300) >> 4;
13392 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13393 }
13394 else
13395 {
90ec0d68 13396 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13397
d2cd1205 13398 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13399 {
13400 /* PR gas/12698: The constraint is only applied for m_profile.
13401 If the user has specified -march=all, we want to ignore it as
13402 we are building for any CPU type, including non-m variants. */
823d2571
TG
13403 bfd_boolean m_profile =
13404 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13405 constraint ((flags != 0) && m_profile, _("selected processor does "
13406 "not support requested special purpose register"));
13407 }
90ec0d68 13408 else
d2cd1205
JB
13409 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13410 devices). */
13411 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13412 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13413
90ec0d68
MGD
13414 inst.instruction |= (flags & SPSR_BIT) >> 2;
13415 inst.instruction |= inst.operands[1].imm & 0xff;
13416 inst.instruction |= 0xf0000;
13417 }
c19d1205 13418}
b05fe5cf 13419
c19d1205
ZW
13420static void
13421do_t_msr (void)
13422{
62b3e311 13423 int flags;
fdfde340 13424 unsigned Rn;
62b3e311 13425
037e8744
JB
13426 if (do_vfp_nsyn_msr () == SUCCESS)
13427 return;
13428
c19d1205
ZW
13429 constraint (!inst.operands[1].isreg,
13430 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13431
13432 if (inst.operands[0].isreg)
13433 flags = (int)(inst.operands[0].reg);
13434 else
13435 flags = inst.operands[0].imm;
13436
d2cd1205 13437 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13438 {
d2cd1205
JB
13439 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13440
1a43faaf 13441 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13442 If the user has specified -march=all, we want to ignore it as
13443 we are building for any CPU type, including non-m variants. */
823d2571
TG
13444 bfd_boolean m_profile =
13445 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13446 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13447 && (bits & ~(PSR_s | PSR_f)) != 0)
13448 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13449 && bits != PSR_f)) && m_profile,
13450 _("selected processor does not support requested special "
13451 "purpose register"));
62b3e311
PB
13452 }
13453 else
d2cd1205
JB
13454 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13455 "requested special purpose register"));
c921be7d 13456
fdfde340
JM
13457 Rn = inst.operands[1].reg;
13458 reject_bad_reg (Rn);
13459
62b3e311 13460 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13461 inst.instruction |= (flags & 0xf0000) >> 8;
13462 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13463 inst.instruction |= (flags & 0xff);
fdfde340 13464 inst.instruction |= Rn << 16;
c19d1205 13465}
b05fe5cf 13466
c19d1205
ZW
13467static void
13468do_t_mul (void)
13469{
17828f45 13470 bfd_boolean narrow;
fdfde340 13471 unsigned Rd, Rn, Rm;
17828f45 13472
c19d1205
ZW
13473 if (!inst.operands[2].present)
13474 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13475
fdfde340
JM
13476 Rd = inst.operands[0].reg;
13477 Rn = inst.operands[1].reg;
13478 Rm = inst.operands[2].reg;
13479
17828f45 13480 if (unified_syntax)
b05fe5cf 13481 {
17828f45 13482 if (inst.size_req == 4
fdfde340
JM
13483 || (Rd != Rn
13484 && Rd != Rm)
13485 || Rn > 7
13486 || Rm > 7)
17828f45
JM
13487 narrow = FALSE;
13488 else if (inst.instruction == T_MNEM_muls)
5ee91343 13489 narrow = !in_pred_block ();
17828f45 13490 else
5ee91343 13491 narrow = in_pred_block ();
b05fe5cf 13492 }
c19d1205 13493 else
b05fe5cf 13494 {
17828f45 13495 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13496 constraint (Rn > 7 || Rm > 7,
c19d1205 13497 BAD_HIREG);
17828f45
JM
13498 narrow = TRUE;
13499 }
b05fe5cf 13500
17828f45
JM
13501 if (narrow)
13502 {
13503 /* 16-bit MULS/Conditional MUL. */
c19d1205 13504 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13505 inst.instruction |= Rd;
b05fe5cf 13506
fdfde340
JM
13507 if (Rd == Rn)
13508 inst.instruction |= Rm << 3;
13509 else if (Rd == Rm)
13510 inst.instruction |= Rn << 3;
c19d1205
ZW
13511 else
13512 constraint (1, _("dest must overlap one source register"));
13513 }
17828f45
JM
13514 else
13515 {
e07e6e58
NC
13516 constraint (inst.instruction != T_MNEM_mul,
13517 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13518 /* 32-bit MUL. */
13519 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13520 inst.instruction |= Rd << 8;
13521 inst.instruction |= Rn << 16;
13522 inst.instruction |= Rm << 0;
13523
13524 reject_bad_reg (Rd);
13525 reject_bad_reg (Rn);
13526 reject_bad_reg (Rm);
17828f45 13527 }
c19d1205 13528}
b05fe5cf 13529
c19d1205
ZW
13530static void
13531do_t_mull (void)
13532{
fdfde340 13533 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13534
fdfde340
JM
13535 RdLo = inst.operands[0].reg;
13536 RdHi = inst.operands[1].reg;
13537 Rn = inst.operands[2].reg;
13538 Rm = inst.operands[3].reg;
13539
13540 reject_bad_reg (RdLo);
13541 reject_bad_reg (RdHi);
13542 reject_bad_reg (Rn);
13543 reject_bad_reg (Rm);
13544
13545 inst.instruction |= RdLo << 12;
13546 inst.instruction |= RdHi << 8;
13547 inst.instruction |= Rn << 16;
13548 inst.instruction |= Rm;
13549
13550 if (RdLo == RdHi)
c19d1205
ZW
13551 as_tsktsk (_("rdhi and rdlo must be different"));
13552}
b05fe5cf 13553
c19d1205
ZW
13554static void
13555do_t_nop (void)
13556{
5ee91343 13557 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13558
c19d1205
ZW
13559 if (unified_syntax)
13560 {
13561 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13562 {
c19d1205
ZW
13563 inst.instruction = THUMB_OP32 (inst.instruction);
13564 inst.instruction |= inst.operands[0].imm;
13565 }
13566 else
13567 {
bc2d1808
NC
13568 /* PR9722: Check for Thumb2 availability before
13569 generating a thumb2 nop instruction. */
afa62d5e 13570 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13571 {
13572 inst.instruction = THUMB_OP16 (inst.instruction);
13573 inst.instruction |= inst.operands[0].imm << 4;
13574 }
13575 else
13576 inst.instruction = 0x46c0;
c19d1205
ZW
13577 }
13578 }
13579 else
13580 {
13581 constraint (inst.operands[0].present,
13582 _("Thumb does not support NOP with hints"));
13583 inst.instruction = 0x46c0;
13584 }
13585}
b05fe5cf 13586
c19d1205
ZW
13587static void
13588do_t_neg (void)
13589{
13590 if (unified_syntax)
13591 {
3d388997
PB
13592 bfd_boolean narrow;
13593
13594 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13595 narrow = !in_pred_block ();
3d388997 13596 else
5ee91343 13597 narrow = in_pred_block ();
3d388997
PB
13598 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13599 narrow = FALSE;
13600 if (inst.size_req == 4)
13601 narrow = FALSE;
13602
13603 if (!narrow)
c19d1205
ZW
13604 {
13605 inst.instruction = THUMB_OP32 (inst.instruction);
13606 inst.instruction |= inst.operands[0].reg << 8;
13607 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13608 }
13609 else
13610 {
c19d1205
ZW
13611 inst.instruction = THUMB_OP16 (inst.instruction);
13612 inst.instruction |= inst.operands[0].reg;
13613 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13614 }
13615 }
13616 else
13617 {
c19d1205
ZW
13618 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13619 BAD_HIREG);
13620 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13621
13622 inst.instruction = THUMB_OP16 (inst.instruction);
13623 inst.instruction |= inst.operands[0].reg;
13624 inst.instruction |= inst.operands[1].reg << 3;
13625 }
13626}
13627
1c444d06
JM
13628static void
13629do_t_orn (void)
13630{
13631 unsigned Rd, Rn;
13632
13633 Rd = inst.operands[0].reg;
13634 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13635
fdfde340
JM
13636 reject_bad_reg (Rd);
13637 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13638 reject_bad_reg (Rn);
13639
1c444d06
JM
13640 inst.instruction |= Rd << 8;
13641 inst.instruction |= Rn << 16;
13642
13643 if (!inst.operands[2].isreg)
13644 {
13645 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13646 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13647 }
13648 else
13649 {
13650 unsigned Rm;
13651
13652 Rm = inst.operands[2].reg;
fdfde340 13653 reject_bad_reg (Rm);
1c444d06
JM
13654
13655 constraint (inst.operands[2].shifted
13656 && inst.operands[2].immisreg,
13657 _("shift must be constant"));
13658 encode_thumb32_shifted_operand (2);
13659 }
13660}
13661
c19d1205
ZW
13662static void
13663do_t_pkhbt (void)
13664{
fdfde340
JM
13665 unsigned Rd, Rn, Rm;
13666
13667 Rd = inst.operands[0].reg;
13668 Rn = inst.operands[1].reg;
13669 Rm = inst.operands[2].reg;
13670
13671 reject_bad_reg (Rd);
13672 reject_bad_reg (Rn);
13673 reject_bad_reg (Rm);
13674
13675 inst.instruction |= Rd << 8;
13676 inst.instruction |= Rn << 16;
13677 inst.instruction |= Rm;
c19d1205
ZW
13678 if (inst.operands[3].present)
13679 {
e2b0ab59
AV
13680 unsigned int val = inst.relocs[0].exp.X_add_number;
13681 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13682 _("expression too complex"));
13683 inst.instruction |= (val & 0x1c) << 10;
13684 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13685 }
c19d1205 13686}
b05fe5cf 13687
c19d1205
ZW
13688static void
13689do_t_pkhtb (void)
13690{
13691 if (!inst.operands[3].present)
1ef52f49
NC
13692 {
13693 unsigned Rtmp;
13694
13695 inst.instruction &= ~0x00000020;
13696
13697 /* PR 10168. Swap the Rm and Rn registers. */
13698 Rtmp = inst.operands[1].reg;
13699 inst.operands[1].reg = inst.operands[2].reg;
13700 inst.operands[2].reg = Rtmp;
13701 }
c19d1205 13702 do_t_pkhbt ();
b05fe5cf
ZW
13703}
13704
c19d1205
ZW
13705static void
13706do_t_pld (void)
13707{
fdfde340
JM
13708 if (inst.operands[0].immisreg)
13709 reject_bad_reg (inst.operands[0].imm);
13710
c19d1205
ZW
13711 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13712}
b05fe5cf 13713
c19d1205
ZW
13714static void
13715do_t_push_pop (void)
b99bd4ef 13716{
e9f89963 13717 unsigned mask;
5f4273c7 13718
c19d1205
ZW
13719 constraint (inst.operands[0].writeback,
13720 _("push/pop do not support {reglist}^"));
e2b0ab59 13721 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13722 _("expression too complex"));
b99bd4ef 13723
e9f89963 13724 mask = inst.operands[0].imm;
d3bfe16e 13725 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13726 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13727 else if (inst.size_req != 4
c6025a80 13728 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13729 ? REG_LR : REG_PC)))
b99bd4ef 13730 {
c19d1205
ZW
13731 inst.instruction = THUMB_OP16 (inst.instruction);
13732 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13733 inst.instruction |= mask & 0xff;
c19d1205
ZW
13734 }
13735 else if (unified_syntax)
13736 {
3c707909 13737 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13738 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13739 }
13740 else
13741 {
13742 inst.error = _("invalid register list to push/pop instruction");
13743 return;
c19d1205 13744 }
4b5a202f
AV
13745}
13746
13747static void
13748do_t_clrm (void)
13749{
13750 if (unified_syntax)
13751 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13752 else
13753 {
13754 inst.error = _("invalid register list to push/pop instruction");
13755 return;
13756 }
c19d1205 13757}
b99bd4ef 13758
efd6b359
AV
13759static void
13760do_t_vscclrm (void)
13761{
13762 if (inst.operands[0].issingle)
13763 {
13764 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13765 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13766 inst.instruction |= inst.operands[0].imm;
13767 }
13768 else
13769 {
13770 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13771 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13772 inst.instruction |= 1 << 8;
13773 inst.instruction |= inst.operands[0].imm << 1;
13774 }
13775}
13776
c19d1205
ZW
13777static void
13778do_t_rbit (void)
13779{
fdfde340
JM
13780 unsigned Rd, Rm;
13781
13782 Rd = inst.operands[0].reg;
13783 Rm = inst.operands[1].reg;
13784
13785 reject_bad_reg (Rd);
13786 reject_bad_reg (Rm);
13787
13788 inst.instruction |= Rd << 8;
13789 inst.instruction |= Rm << 16;
13790 inst.instruction |= Rm;
c19d1205 13791}
b99bd4ef 13792
c19d1205
ZW
13793static void
13794do_t_rev (void)
13795{
fdfde340
JM
13796 unsigned Rd, Rm;
13797
13798 Rd = inst.operands[0].reg;
13799 Rm = inst.operands[1].reg;
13800
13801 reject_bad_reg (Rd);
13802 reject_bad_reg (Rm);
13803
13804 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13805 && inst.size_req != 4)
13806 {
13807 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13808 inst.instruction |= Rd;
13809 inst.instruction |= Rm << 3;
c19d1205
ZW
13810 }
13811 else if (unified_syntax)
13812 {
13813 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13814 inst.instruction |= Rd << 8;
13815 inst.instruction |= Rm << 16;
13816 inst.instruction |= Rm;
c19d1205
ZW
13817 }
13818 else
13819 inst.error = BAD_HIREG;
13820}
b99bd4ef 13821
1c444d06
JM
13822static void
13823do_t_rrx (void)
13824{
13825 unsigned Rd, Rm;
13826
13827 Rd = inst.operands[0].reg;
13828 Rm = inst.operands[1].reg;
13829
fdfde340
JM
13830 reject_bad_reg (Rd);
13831 reject_bad_reg (Rm);
c921be7d 13832
1c444d06
JM
13833 inst.instruction |= Rd << 8;
13834 inst.instruction |= Rm;
13835}
13836
c19d1205
ZW
13837static void
13838do_t_rsb (void)
13839{
fdfde340 13840 unsigned Rd, Rs;
b99bd4ef 13841
c19d1205
ZW
13842 Rd = inst.operands[0].reg;
13843 Rs = (inst.operands[1].present
13844 ? inst.operands[1].reg /* Rd, Rs, foo */
13845 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13846
fdfde340
JM
13847 reject_bad_reg (Rd);
13848 reject_bad_reg (Rs);
13849 if (inst.operands[2].isreg)
13850 reject_bad_reg (inst.operands[2].reg);
13851
c19d1205
ZW
13852 inst.instruction |= Rd << 8;
13853 inst.instruction |= Rs << 16;
13854 if (!inst.operands[2].isreg)
13855 {
026d3abb
PB
13856 bfd_boolean narrow;
13857
13858 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13859 narrow = !in_pred_block ();
026d3abb 13860 else
5ee91343 13861 narrow = in_pred_block ();
026d3abb
PB
13862
13863 if (Rd > 7 || Rs > 7)
13864 narrow = FALSE;
13865
13866 if (inst.size_req == 4 || !unified_syntax)
13867 narrow = FALSE;
13868
e2b0ab59
AV
13869 if (inst.relocs[0].exp.X_op != O_constant
13870 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13871 narrow = FALSE;
13872
13873 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13874 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13875 if (narrow)
13876 {
e2b0ab59 13877 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13878 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13879 inst.instruction |= Rs << 3;
13880 inst.instruction |= Rd;
13881 }
13882 else
13883 {
13884 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13885 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13886 }
c19d1205
ZW
13887 }
13888 else
13889 encode_thumb32_shifted_operand (2);
13890}
b99bd4ef 13891
c19d1205
ZW
13892static void
13893do_t_setend (void)
13894{
12e37cbc
MGD
13895 if (warn_on_deprecated
13896 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13897 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13898
5ee91343 13899 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13900 if (inst.operands[0].imm)
13901 inst.instruction |= 0x8;
13902}
b99bd4ef 13903
c19d1205
ZW
13904static void
13905do_t_shift (void)
13906{
13907 if (!inst.operands[1].present)
13908 inst.operands[1].reg = inst.operands[0].reg;
13909
13910 if (unified_syntax)
13911 {
3d388997
PB
13912 bfd_boolean narrow;
13913 int shift_kind;
13914
13915 switch (inst.instruction)
13916 {
13917 case T_MNEM_asr:
13918 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13919 case T_MNEM_lsl:
13920 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13921 case T_MNEM_lsr:
13922 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13923 case T_MNEM_ror:
13924 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13925 default: abort ();
13926 }
13927
13928 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13929 narrow = !in_pred_block ();
3d388997 13930 else
5ee91343 13931 narrow = in_pred_block ();
3d388997
PB
13932 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13933 narrow = FALSE;
13934 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13935 narrow = FALSE;
13936 if (inst.operands[2].isreg
13937 && (inst.operands[1].reg != inst.operands[0].reg
13938 || inst.operands[2].reg > 7))
13939 narrow = FALSE;
13940 if (inst.size_req == 4)
13941 narrow = FALSE;
13942
fdfde340
JM
13943 reject_bad_reg (inst.operands[0].reg);
13944 reject_bad_reg (inst.operands[1].reg);
c921be7d 13945
3d388997 13946 if (!narrow)
c19d1205
ZW
13947 {
13948 if (inst.operands[2].isreg)
b99bd4ef 13949 {
fdfde340 13950 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13951 inst.instruction = THUMB_OP32 (inst.instruction);
13952 inst.instruction |= inst.operands[0].reg << 8;
13953 inst.instruction |= inst.operands[1].reg << 16;
13954 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13955
13956 /* PR 12854: Error on extraneous shifts. */
13957 constraint (inst.operands[2].shifted,
13958 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13959 }
13960 else
13961 {
13962 inst.operands[1].shifted = 1;
3d388997 13963 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13964 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13965 ? T_MNEM_movs : T_MNEM_mov);
13966 inst.instruction |= inst.operands[0].reg << 8;
13967 encode_thumb32_shifted_operand (1);
13968 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13969 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13970 }
13971 }
13972 else
13973 {
c19d1205 13974 if (inst.operands[2].isreg)
b99bd4ef 13975 {
3d388997 13976 switch (shift_kind)
b99bd4ef 13977 {
3d388997
PB
13978 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13979 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13980 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13981 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13982 default: abort ();
b99bd4ef 13983 }
5f4273c7 13984
c19d1205
ZW
13985 inst.instruction |= inst.operands[0].reg;
13986 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13987
13988 /* PR 12854: Error on extraneous shifts. */
13989 constraint (inst.operands[2].shifted,
13990 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13991 }
13992 else
13993 {
3d388997 13994 switch (shift_kind)
b99bd4ef 13995 {
3d388997
PB
13996 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13997 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13998 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13999 default: abort ();
b99bd4ef 14000 }
e2b0ab59 14001 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14002 inst.instruction |= inst.operands[0].reg;
14003 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14004 }
14005 }
c19d1205
ZW
14006 }
14007 else
14008 {
14009 constraint (inst.operands[0].reg > 7
14010 || inst.operands[1].reg > 7, BAD_HIREG);
14011 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 14012
c19d1205
ZW
14013 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14014 {
14015 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14016 constraint (inst.operands[0].reg != inst.operands[1].reg,
14017 _("source1 and dest must be same register"));
b99bd4ef 14018
c19d1205
ZW
14019 switch (inst.instruction)
14020 {
14021 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14022 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14023 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14024 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14025 default: abort ();
14026 }
5f4273c7 14027
c19d1205
ZW
14028 inst.instruction |= inst.operands[0].reg;
14029 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
14030
14031 /* PR 12854: Error on extraneous shifts. */
14032 constraint (inst.operands[2].shifted,
14033 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
14034 }
14035 else
b99bd4ef 14036 {
c19d1205
ZW
14037 switch (inst.instruction)
14038 {
14039 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14040 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14041 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14042 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14043 default: abort ();
14044 }
e2b0ab59 14045 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14046 inst.instruction |= inst.operands[0].reg;
14047 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14048 }
14049 }
b99bd4ef
NC
14050}
14051
14052static void
c19d1205 14053do_t_simd (void)
b99bd4ef 14054{
fdfde340
JM
14055 unsigned Rd, Rn, Rm;
14056
14057 Rd = inst.operands[0].reg;
14058 Rn = inst.operands[1].reg;
14059 Rm = inst.operands[2].reg;
14060
14061 reject_bad_reg (Rd);
14062 reject_bad_reg (Rn);
14063 reject_bad_reg (Rm);
14064
14065 inst.instruction |= Rd << 8;
14066 inst.instruction |= Rn << 16;
14067 inst.instruction |= Rm;
c19d1205 14068}
b99bd4ef 14069
03ee1b7f
NC
14070static void
14071do_t_simd2 (void)
14072{
14073 unsigned Rd, Rn, Rm;
14074
14075 Rd = inst.operands[0].reg;
14076 Rm = inst.operands[1].reg;
14077 Rn = inst.operands[2].reg;
14078
14079 reject_bad_reg (Rd);
14080 reject_bad_reg (Rn);
14081 reject_bad_reg (Rm);
14082
14083 inst.instruction |= Rd << 8;
14084 inst.instruction |= Rn << 16;
14085 inst.instruction |= Rm;
14086}
14087
c19d1205 14088static void
3eb17e6b 14089do_t_smc (void)
c19d1205 14090{
e2b0ab59 14091 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
14092 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14093 _("SMC is not permitted on this architecture"));
e2b0ab59 14094 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14095 _("expression too complex"));
ba85f98c
BW
14096 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14097
e2b0ab59 14098 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 14099 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 14100
24382199 14101 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 14102 set_pred_insn_type_last ();
c19d1205 14103}
b99bd4ef 14104
90ec0d68
MGD
14105static void
14106do_t_hvc (void)
14107{
e2b0ab59 14108 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 14109
e2b0ab59 14110 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
14111 inst.instruction |= (value & 0x0fff);
14112 inst.instruction |= (value & 0xf000) << 4;
14113}
14114
c19d1205 14115static void
3a21c15a 14116do_t_ssat_usat (int bias)
c19d1205 14117{
fdfde340
JM
14118 unsigned Rd, Rn;
14119
14120 Rd = inst.operands[0].reg;
14121 Rn = inst.operands[2].reg;
14122
14123 reject_bad_reg (Rd);
14124 reject_bad_reg (Rn);
14125
14126 inst.instruction |= Rd << 8;
3a21c15a 14127 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 14128 inst.instruction |= Rn << 16;
b99bd4ef 14129
c19d1205 14130 if (inst.operands[3].present)
b99bd4ef 14131 {
e2b0ab59 14132 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 14133
e2b0ab59 14134 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 14135
e2b0ab59 14136 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14137 _("expression too complex"));
b99bd4ef 14138
3a21c15a 14139 if (shift_amount != 0)
6189168b 14140 {
3a21c15a
NC
14141 constraint (shift_amount > 31,
14142 _("shift expression is too large"));
14143
c19d1205 14144 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
14145 inst.instruction |= 0x00200000; /* sh bit. */
14146
14147 inst.instruction |= (shift_amount & 0x1c) << 10;
14148 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14149 }
14150 }
b99bd4ef 14151}
c921be7d 14152
3a21c15a
NC
14153static void
14154do_t_ssat (void)
14155{
14156 do_t_ssat_usat (1);
14157}
b99bd4ef 14158
0dd132b6 14159static void
c19d1205 14160do_t_ssat16 (void)
0dd132b6 14161{
fdfde340
JM
14162 unsigned Rd, Rn;
14163
14164 Rd = inst.operands[0].reg;
14165 Rn = inst.operands[2].reg;
14166
14167 reject_bad_reg (Rd);
14168 reject_bad_reg (Rn);
14169
14170 inst.instruction |= Rd << 8;
c19d1205 14171 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14172 inst.instruction |= Rn << 16;
c19d1205 14173}
0dd132b6 14174
c19d1205
ZW
14175static void
14176do_t_strex (void)
14177{
14178 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14179 || inst.operands[2].postind || inst.operands[2].writeback
14180 || inst.operands[2].immisreg || inst.operands[2].shifted
14181 || inst.operands[2].negative,
01cfc07f 14182 BAD_ADDR_MODE);
0dd132b6 14183
5be8be5d
DG
14184 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14185
c19d1205
ZW
14186 inst.instruction |= inst.operands[0].reg << 8;
14187 inst.instruction |= inst.operands[1].reg << 12;
14188 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14189 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14190}
14191
b99bd4ef 14192static void
c19d1205 14193do_t_strexd (void)
b99bd4ef 14194{
c19d1205
ZW
14195 if (!inst.operands[2].present)
14196 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14197
c19d1205
ZW
14198 constraint (inst.operands[0].reg == inst.operands[1].reg
14199 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14200 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14201 BAD_OVERLAP);
b99bd4ef 14202
c19d1205
ZW
14203 inst.instruction |= inst.operands[0].reg;
14204 inst.instruction |= inst.operands[1].reg << 12;
14205 inst.instruction |= inst.operands[2].reg << 8;
14206 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14207}
14208
14209static void
c19d1205 14210do_t_sxtah (void)
b99bd4ef 14211{
fdfde340
JM
14212 unsigned Rd, Rn, Rm;
14213
14214 Rd = inst.operands[0].reg;
14215 Rn = inst.operands[1].reg;
14216 Rm = inst.operands[2].reg;
14217
14218 reject_bad_reg (Rd);
14219 reject_bad_reg (Rn);
14220 reject_bad_reg (Rm);
14221
14222 inst.instruction |= Rd << 8;
14223 inst.instruction |= Rn << 16;
14224 inst.instruction |= Rm;
c19d1205
ZW
14225 inst.instruction |= inst.operands[3].imm << 4;
14226}
b99bd4ef 14227
c19d1205
ZW
14228static void
14229do_t_sxth (void)
14230{
fdfde340
JM
14231 unsigned Rd, Rm;
14232
14233 Rd = inst.operands[0].reg;
14234 Rm = inst.operands[1].reg;
14235
14236 reject_bad_reg (Rd);
14237 reject_bad_reg (Rm);
c921be7d
NC
14238
14239 if (inst.instruction <= 0xffff
14240 && inst.size_req != 4
fdfde340 14241 && Rd <= 7 && Rm <= 7
c19d1205 14242 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14243 {
c19d1205 14244 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14245 inst.instruction |= Rd;
14246 inst.instruction |= Rm << 3;
b99bd4ef 14247 }
c19d1205 14248 else if (unified_syntax)
b99bd4ef 14249 {
c19d1205
ZW
14250 if (inst.instruction <= 0xffff)
14251 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14252 inst.instruction |= Rd << 8;
14253 inst.instruction |= Rm;
c19d1205 14254 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14255 }
c19d1205 14256 else
b99bd4ef 14257 {
c19d1205
ZW
14258 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14259 _("Thumb encoding does not support rotation"));
14260 constraint (1, BAD_HIREG);
b99bd4ef 14261 }
c19d1205 14262}
b99bd4ef 14263
c19d1205
ZW
14264static void
14265do_t_swi (void)
14266{
e2b0ab59 14267 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14268}
b99bd4ef 14269
92e90b6e
PB
14270static void
14271do_t_tb (void)
14272{
fdfde340 14273 unsigned Rn, Rm;
92e90b6e
PB
14274 int half;
14275
14276 half = (inst.instruction & 0x10) != 0;
5ee91343 14277 set_pred_insn_type_last ();
dfa9f0d5
PB
14278 constraint (inst.operands[0].immisreg,
14279 _("instruction requires register index"));
fdfde340
JM
14280
14281 Rn = inst.operands[0].reg;
14282 Rm = inst.operands[0].imm;
c921be7d 14283
5c8ed6a4
JW
14284 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14285 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14286 reject_bad_reg (Rm);
14287
92e90b6e
PB
14288 constraint (!half && inst.operands[0].shifted,
14289 _("instruction does not allow shifted index"));
fdfde340 14290 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14291}
14292
74db7efb
NC
14293static void
14294do_t_udf (void)
14295{
14296 if (!inst.operands[0].present)
14297 inst.operands[0].imm = 0;
14298
14299 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14300 {
14301 constraint (inst.size_req == 2,
14302 _("immediate value out of range"));
14303 inst.instruction = THUMB_OP32 (inst.instruction);
14304 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14305 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14306 }
14307 else
14308 {
14309 inst.instruction = THUMB_OP16 (inst.instruction);
14310 inst.instruction |= inst.operands[0].imm;
14311 }
14312
5ee91343 14313 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14314}
14315
14316
c19d1205
ZW
14317static void
14318do_t_usat (void)
14319{
3a21c15a 14320 do_t_ssat_usat (0);
b99bd4ef
NC
14321}
14322
14323static void
c19d1205 14324do_t_usat16 (void)
b99bd4ef 14325{
fdfde340
JM
14326 unsigned Rd, Rn;
14327
14328 Rd = inst.operands[0].reg;
14329 Rn = inst.operands[2].reg;
14330
14331 reject_bad_reg (Rd);
14332 reject_bad_reg (Rn);
14333
14334 inst.instruction |= Rd << 8;
c19d1205 14335 inst.instruction |= inst.operands[1].imm;
fdfde340 14336 inst.instruction |= Rn << 16;
b99bd4ef 14337}
c19d1205 14338
e12437dc
AV
14339/* Checking the range of the branch offset (VAL) with NBITS bits
14340 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14341static int
14342v8_1_branch_value_check (int val, int nbits, int is_signed)
14343{
14344 gas_assert (nbits > 0 && nbits <= 32);
14345 if (is_signed)
14346 {
14347 int cmp = (1 << (nbits - 1));
14348 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14349 return FAIL;
14350 }
14351 else
14352 {
14353 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14354 return FAIL;
14355 }
14356 return SUCCESS;
14357}
14358
4389b29a
AV
14359/* For branches in Armv8.1-M Mainline. */
14360static void
14361do_t_branch_future (void)
14362{
14363 unsigned long insn = inst.instruction;
14364
14365 inst.instruction = THUMB_OP32 (inst.instruction);
14366 if (inst.operands[0].hasreloc == 0)
14367 {
14368 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14369 as_bad (BAD_BRANCH_OFF);
14370
14371 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14372 }
14373 else
14374 {
14375 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14376 inst.relocs[0].pc_rel = 1;
14377 }
14378
14379 switch (insn)
14380 {
14381 case T_MNEM_bf:
14382 if (inst.operands[1].hasreloc == 0)
14383 {
14384 int val = inst.operands[1].imm;
14385 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14386 as_bad (BAD_BRANCH_OFF);
14387
14388 int immA = (val & 0x0001f000) >> 12;
14389 int immB = (val & 0x00000ffc) >> 2;
14390 int immC = (val & 0x00000002) >> 1;
14391 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14392 }
14393 else
14394 {
14395 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14396 inst.relocs[1].pc_rel = 1;
14397 }
14398 break;
14399
65d1bc05
AV
14400 case T_MNEM_bfl:
14401 if (inst.operands[1].hasreloc == 0)
14402 {
14403 int val = inst.operands[1].imm;
14404 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14405 as_bad (BAD_BRANCH_OFF);
14406
14407 int immA = (val & 0x0007f000) >> 12;
14408 int immB = (val & 0x00000ffc) >> 2;
14409 int immC = (val & 0x00000002) >> 1;
14410 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14411 }
14412 else
14413 {
14414 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14415 inst.relocs[1].pc_rel = 1;
14416 }
14417 break;
14418
f6b2b12d
AV
14419 case T_MNEM_bfcsel:
14420 /* Operand 1. */
14421 if (inst.operands[1].hasreloc == 0)
14422 {
14423 int val = inst.operands[1].imm;
14424 int immA = (val & 0x00001000) >> 12;
14425 int immB = (val & 0x00000ffc) >> 2;
14426 int immC = (val & 0x00000002) >> 1;
14427 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14428 }
14429 else
14430 {
14431 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14432 inst.relocs[1].pc_rel = 1;
14433 }
14434
14435 /* Operand 2. */
14436 if (inst.operands[2].hasreloc == 0)
14437 {
14438 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14439 int val2 = inst.operands[2].imm;
14440 int val0 = inst.operands[0].imm & 0x1f;
14441 int diff = val2 - val0;
14442 if (diff == 4)
14443 inst.instruction |= 1 << 17; /* T bit. */
14444 else if (diff != 2)
14445 as_bad (_("out of range label-relative fixup value"));
14446 }
14447 else
14448 {
14449 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14450 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14451 inst.relocs[2].pc_rel = 1;
14452 }
14453
14454 /* Operand 3. */
14455 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14456 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14457 break;
14458
f1c7f421
AV
14459 case T_MNEM_bfx:
14460 case T_MNEM_bflx:
14461 inst.instruction |= inst.operands[1].reg << 16;
14462 break;
14463
4389b29a
AV
14464 default: abort ();
14465 }
14466}
14467
60f993ce
AV
14468/* Helper function for do_t_loloop to handle relocations. */
14469static void
14470v8_1_loop_reloc (int is_le)
14471{
14472 if (inst.relocs[0].exp.X_op == O_constant)
14473 {
14474 int value = inst.relocs[0].exp.X_add_number;
14475 value = (is_le) ? -value : value;
14476
14477 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14478 as_bad (BAD_BRANCH_OFF);
14479
14480 int imml, immh;
14481
14482 immh = (value & 0x00000ffc) >> 2;
14483 imml = (value & 0x00000002) >> 1;
14484
14485 inst.instruction |= (imml << 11) | (immh << 1);
14486 }
14487 else
14488 {
14489 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14490 inst.relocs[0].pc_rel = 1;
14491 }
14492}
14493
08132bdd
SP
14494/* For shifts with four operands in MVE. */
14495static void
14496do_mve_scalar_shift1 (void)
14497{
14498 unsigned int value = inst.operands[2].imm;
14499
14500 inst.instruction |= inst.operands[0].reg << 16;
14501 inst.instruction |= inst.operands[1].reg << 8;
14502
14503 /* Setting the bit for saturation. */
14504 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14505
14506 /* Assuming Rm is already checked not to be 11x1. */
14507 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14508 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14509 inst.instruction |= inst.operands[3].reg << 12;
14510}
14511
23d00a41
SD
14512/* For shifts in MVE. */
14513static void
14514do_mve_scalar_shift (void)
14515{
14516 if (!inst.operands[2].present)
14517 {
14518 inst.operands[2] = inst.operands[1];
14519 inst.operands[1].reg = 0xf;
14520 }
14521
14522 inst.instruction |= inst.operands[0].reg << 16;
14523 inst.instruction |= inst.operands[1].reg << 8;
14524
14525 if (inst.operands[2].isreg)
14526 {
14527 /* Assuming Rm is already checked not to be 11x1. */
14528 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14529 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14530 inst.instruction |= inst.operands[2].reg << 12;
14531 }
14532 else
14533 {
14534 /* Assuming imm is already checked as [1,32]. */
14535 unsigned int value = inst.operands[2].imm;
14536 inst.instruction |= (value & 0x1c) << 10;
14537 inst.instruction |= (value & 0x03) << 6;
14538 /* Change last 4 bits from 0xd to 0xf. */
14539 inst.instruction |= 0x2;
14540 }
14541}
14542
a302e574
AV
14543/* MVE instruction encoder helpers. */
14544#define M_MNEM_vabav 0xee800f01
14545#define M_MNEM_vmladav 0xeef00e00
14546#define M_MNEM_vmladava 0xeef00e20
14547#define M_MNEM_vmladavx 0xeef01e00
14548#define M_MNEM_vmladavax 0xeef01e20
14549#define M_MNEM_vmlsdav 0xeef00e01
14550#define M_MNEM_vmlsdava 0xeef00e21
14551#define M_MNEM_vmlsdavx 0xeef01e01
14552#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14553#define M_MNEM_vmullt 0xee011e00
14554#define M_MNEM_vmullb 0xee010e00
efd0b310 14555#define M_MNEM_vctp 0xf000e801
35c228db
AV
14556#define M_MNEM_vst20 0xfc801e00
14557#define M_MNEM_vst21 0xfc801e20
14558#define M_MNEM_vst40 0xfc801e01
14559#define M_MNEM_vst41 0xfc801e21
14560#define M_MNEM_vst42 0xfc801e41
14561#define M_MNEM_vst43 0xfc801e61
14562#define M_MNEM_vld20 0xfc901e00
14563#define M_MNEM_vld21 0xfc901e20
14564#define M_MNEM_vld40 0xfc901e01
14565#define M_MNEM_vld41 0xfc901e21
14566#define M_MNEM_vld42 0xfc901e41
14567#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14568#define M_MNEM_vstrb 0xec000e00
14569#define M_MNEM_vstrh 0xec000e10
14570#define M_MNEM_vstrw 0xec000e40
14571#define M_MNEM_vstrd 0xec000e50
14572#define M_MNEM_vldrb 0xec100e00
14573#define M_MNEM_vldrh 0xec100e10
14574#define M_MNEM_vldrw 0xec100e40
14575#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14576#define M_MNEM_vmovlt 0xeea01f40
14577#define M_MNEM_vmovlb 0xeea00f40
14578#define M_MNEM_vmovnt 0xfe311e81
14579#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14580#define M_MNEM_vadc 0xee300f00
14581#define M_MNEM_vadci 0xee301f00
14582#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14583#define M_MNEM_vaddlv 0xee890f00
14584#define M_MNEM_vaddlva 0xee890f20
14585#define M_MNEM_vaddv 0xeef10f00
14586#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14587#define M_MNEM_vddup 0xee011f6e
14588#define M_MNEM_vdwdup 0xee011f60
14589#define M_MNEM_vidup 0xee010f6e
14590#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14591#define M_MNEM_vmaxv 0xeee20f00
14592#define M_MNEM_vmaxav 0xeee00f00
14593#define M_MNEM_vminv 0xeee20f80
14594#define M_MNEM_vminav 0xeee00f80
93925576
AV
14595#define M_MNEM_vmlaldav 0xee800e00
14596#define M_MNEM_vmlaldava 0xee800e20
14597#define M_MNEM_vmlaldavx 0xee801e00
14598#define M_MNEM_vmlaldavax 0xee801e20
14599#define M_MNEM_vmlsldav 0xee800e01
14600#define M_MNEM_vmlsldava 0xee800e21
14601#define M_MNEM_vmlsldavx 0xee801e01
14602#define M_MNEM_vmlsldavax 0xee801e21
14603#define M_MNEM_vrmlaldavhx 0xee801f00
14604#define M_MNEM_vrmlaldavhax 0xee801f20
14605#define M_MNEM_vrmlsldavh 0xfe800e01
14606#define M_MNEM_vrmlsldavha 0xfe800e21
14607#define M_MNEM_vrmlsldavhx 0xfe801e01
14608#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14609#define M_MNEM_vqmovnt 0xee331e01
14610#define M_MNEM_vqmovnb 0xee330e01
14611#define M_MNEM_vqmovunt 0xee311e81
14612#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14613#define M_MNEM_vshrnt 0xee801fc1
14614#define M_MNEM_vshrnb 0xee800fc1
14615#define M_MNEM_vrshrnt 0xfe801fc1
14616#define M_MNEM_vqshrnt 0xee801f40
14617#define M_MNEM_vqshrnb 0xee800f40
14618#define M_MNEM_vqshrunt 0xee801fc0
14619#define M_MNEM_vqshrunb 0xee800fc0
14620#define M_MNEM_vrshrnb 0xfe800fc1
14621#define M_MNEM_vqrshrnt 0xee801f41
14622#define M_MNEM_vqrshrnb 0xee800f41
14623#define M_MNEM_vqrshrunt 0xfe801fc0
14624#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14625
aab2c27d
MM
14626/* Bfloat16 instruction encoder helpers. */
14627#define B_MNEM_vfmat 0xfc300850
14628#define B_MNEM_vfmab 0xfc300810
14629
5287ad62 14630/* Neon instruction encoder helpers. */
5f4273c7 14631
5287ad62 14632/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14633
5287ad62
JB
14634/* An "invalid" code for the following tables. */
14635#define N_INV -1u
14636
14637struct neon_tab_entry
b99bd4ef 14638{
5287ad62
JB
14639 unsigned integer;
14640 unsigned float_or_poly;
14641 unsigned scalar_or_imm;
14642};
5f4273c7 14643
5287ad62
JB
14644/* Map overloaded Neon opcodes to their respective encodings. */
14645#define NEON_ENC_TAB \
14646 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14647 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14648 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14649 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14650 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14651 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14652 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14653 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14654 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14655 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14656 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14657 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14658 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14659 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14660 /* Register variants of the following two instructions are encoded as
e07e6e58 14661 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14662 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14663 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14664 X(vfma, N_INV, 0x0000c10, N_INV), \
14665 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14666 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14667 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14668 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14669 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14670 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14671 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14672 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14673 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14674 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14675 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14676 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14677 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14678 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14679 X(vshl, 0x0000400, N_INV, 0x0800510), \
14680 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14681 X(vand, 0x0000110, N_INV, 0x0800030), \
14682 X(vbic, 0x0100110, N_INV, 0x0800030), \
14683 X(veor, 0x1000110, N_INV, N_INV), \
14684 X(vorn, 0x0300110, N_INV, 0x0800010), \
14685 X(vorr, 0x0200110, N_INV, 0x0800010), \
14686 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14687 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14688 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14689 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14690 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14691 X(vst1, 0x0000000, 0x0800000, N_INV), \
14692 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14693 X(vst2, 0x0000100, 0x0800100, N_INV), \
14694 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14695 X(vst3, 0x0000200, 0x0800200, N_INV), \
14696 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14697 X(vst4, 0x0000300, 0x0800300, N_INV), \
14698 X(vmovn, 0x1b20200, N_INV, N_INV), \
14699 X(vtrn, 0x1b20080, N_INV, N_INV), \
14700 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14701 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14702 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14703 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14704 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14705 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14706 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14707 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14708 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14709 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14710 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14711 X(vseleq, 0xe000a00, N_INV, N_INV), \
14712 X(vselvs, 0xe100a00, N_INV, N_INV), \
14713 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14714 X(vselgt, 0xe300a00, N_INV, N_INV), \
14715 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14716 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14717 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14718 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14719 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14720 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14721 X(sha3op, 0x2000c00, N_INV, N_INV), \
14722 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14723 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14724
14725enum neon_opc
14726{
14727#define X(OPC,I,F,S) N_MNEM_##OPC
14728NEON_ENC_TAB
14729#undef X
14730};
b99bd4ef 14731
5287ad62
JB
14732static const struct neon_tab_entry neon_enc_tab[] =
14733{
14734#define X(OPC,I,F,S) { (I), (F), (S) }
14735NEON_ENC_TAB
14736#undef X
14737};
b99bd4ef 14738
88714cb8
DG
14739/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14740#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14741#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14742#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14743#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14744#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14745#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14746#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14747#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14748#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14749#define NEON_ENC_SINGLE_(X) \
037e8744 14750 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14751#define NEON_ENC_DOUBLE_(X) \
037e8744 14752 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14753#define NEON_ENC_FPV8_(X) \
14754 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14755
88714cb8
DG
14756#define NEON_ENCODE(type, inst) \
14757 do \
14758 { \
14759 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14760 inst.is_neon = 1; \
14761 } \
14762 while (0)
14763
14764#define check_neon_suffixes \
14765 do \
14766 { \
14767 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14768 { \
14769 as_bad (_("invalid neon suffix for non neon instruction")); \
14770 return; \
14771 } \
14772 } \
14773 while (0)
14774
037e8744
JB
14775/* Define shapes for instruction operands. The following mnemonic characters
14776 are used in this table:
5287ad62 14777
037e8744 14778 F - VFP S<n> register
5287ad62
JB
14779 D - Neon D<n> register
14780 Q - Neon Q<n> register
14781 I - Immediate
14782 S - Scalar
14783 R - ARM register
14784 L - D<n> register list
5f4273c7 14785
037e8744
JB
14786 This table is used to generate various data:
14787 - enumerations of the form NS_DDR to be used as arguments to
14788 neon_select_shape.
14789 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14790 - a table used to drive neon_select_shape. */
b99bd4ef 14791
037e8744 14792#define NEON_SHAPE_DEF \
93925576 14793 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14794 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14795 X(4, (R, R, S, S), QUAD), \
14796 X(4, (S, S, R, R), QUAD), \
b409bdb6 14797 X(3, (Q, R, I), QUAD), \
1b883319
AV
14798 X(3, (I, Q, Q), QUAD), \
14799 X(3, (I, Q, R), QUAD), \
a302e574 14800 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14801 X(3, (D, D, D), DOUBLE), \
14802 X(3, (Q, Q, Q), QUAD), \
14803 X(3, (D, D, I), DOUBLE), \
14804 X(3, (Q, Q, I), QUAD), \
14805 X(3, (D, D, S), DOUBLE), \
14806 X(3, (Q, Q, S), QUAD), \
5ee91343 14807 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14808 X(3, (R, R, Q), QUAD), \
14809 X(2, (R, Q), QUAD), \
037e8744
JB
14810 X(2, (D, D), DOUBLE), \
14811 X(2, (Q, Q), QUAD), \
14812 X(2, (D, S), DOUBLE), \
14813 X(2, (Q, S), QUAD), \
14814 X(2, (D, R), DOUBLE), \
14815 X(2, (Q, R), QUAD), \
14816 X(2, (D, I), DOUBLE), \
14817 X(2, (Q, I), QUAD), \
5aae9ae9
MM
14818 X(3, (P, F, I), SINGLE), \
14819 X(3, (P, D, I), DOUBLE), \
14820 X(3, (P, Q, I), QUAD), \
14821 X(4, (P, F, F, I), SINGLE), \
14822 X(4, (P, D, D, I), DOUBLE), \
14823 X(4, (P, Q, Q, I), QUAD), \
14824 X(5, (P, F, F, F, I), SINGLE), \
14825 X(5, (P, D, D, D, I), DOUBLE), \
14826 X(5, (P, Q, Q, Q, I), QUAD), \
037e8744
JB
14827 X(3, (D, L, D), DOUBLE), \
14828 X(2, (D, Q), MIXED), \
14829 X(2, (Q, D), MIXED), \
14830 X(3, (D, Q, I), MIXED), \
14831 X(3, (Q, D, I), MIXED), \
14832 X(3, (Q, D, D), MIXED), \
14833 X(3, (D, Q, Q), MIXED), \
14834 X(3, (Q, Q, D), MIXED), \
14835 X(3, (Q, D, S), MIXED), \
14836 X(3, (D, Q, S), MIXED), \
14837 X(4, (D, D, D, I), DOUBLE), \
14838 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14839 X(4, (D, D, S, I), DOUBLE), \
14840 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14841 X(2, (F, F), SINGLE), \
14842 X(3, (F, F, F), SINGLE), \
14843 X(2, (F, I), SINGLE), \
14844 X(2, (F, D), MIXED), \
14845 X(2, (D, F), MIXED), \
14846 X(3, (F, F, I), MIXED), \
14847 X(4, (R, R, F, F), SINGLE), \
14848 X(4, (F, F, R, R), SINGLE), \
14849 X(3, (D, R, R), DOUBLE), \
14850 X(3, (R, R, D), DOUBLE), \
14851 X(2, (S, R), SINGLE), \
14852 X(2, (R, S), SINGLE), \
14853 X(2, (F, R), SINGLE), \
d54af2d0 14854 X(2, (R, F), SINGLE), \
1f6234a3
AV
14855/* Used for MVE tail predicated loop instructions. */\
14856 X(2, (R, R), QUAD), \
d54af2d0
RL
14857/* Half float shape supported so far. */\
14858 X (2, (H, D), MIXED), \
14859 X (2, (D, H), MIXED), \
14860 X (2, (H, F), MIXED), \
14861 X (2, (F, H), MIXED), \
14862 X (2, (H, H), HALF), \
14863 X (2, (H, R), HALF), \
14864 X (2, (R, H), HALF), \
14865 X (2, (H, I), HALF), \
14866 X (3, (H, H, H), HALF), \
14867 X (3, (H, F, I), MIXED), \
dec41383
JW
14868 X (3, (F, H, I), MIXED), \
14869 X (3, (D, H, H), MIXED), \
14870 X (3, (D, H, S), MIXED)
037e8744
JB
14871
14872#define S2(A,B) NS_##A##B
14873#define S3(A,B,C) NS_##A##B##C
14874#define S4(A,B,C,D) NS_##A##B##C##D
5aae9ae9 14875#define S5(A,B,C,D,E) NS_##A##B##C##D##E
037e8744
JB
14876
14877#define X(N, L, C) S##N L
14878
5287ad62
JB
14879enum neon_shape
14880{
037e8744
JB
14881 NEON_SHAPE_DEF,
14882 NS_NULL
5287ad62 14883};
b99bd4ef 14884
037e8744
JB
14885#undef X
14886#undef S2
14887#undef S3
14888#undef S4
5aae9ae9 14889#undef S5
037e8744
JB
14890
14891enum neon_shape_class
14892{
d54af2d0 14893 SC_HALF,
037e8744
JB
14894 SC_SINGLE,
14895 SC_DOUBLE,
14896 SC_QUAD,
14897 SC_MIXED
14898};
14899
14900#define X(N, L, C) SC_##C
14901
14902static enum neon_shape_class neon_shape_class[] =
14903{
14904 NEON_SHAPE_DEF
14905};
14906
14907#undef X
14908
14909enum neon_shape_el
14910{
d54af2d0 14911 SE_H,
037e8744
JB
14912 SE_F,
14913 SE_D,
14914 SE_Q,
14915 SE_I,
14916 SE_S,
14917 SE_R,
5aae9ae9
MM
14918 SE_L,
14919 SE_P
037e8744
JB
14920};
14921
14922/* Register widths of above. */
14923static unsigned neon_shape_el_size[] =
14924{
d54af2d0 14925 16,
037e8744
JB
14926 32,
14927 64,
14928 128,
14929 0,
14930 32,
14931 32,
5aae9ae9 14932 0,
037e8744
JB
14933 0
14934};
14935
14936struct neon_shape_info
14937{
14938 unsigned els;
14939 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14940};
14941
14942#define S2(A,B) { SE_##A, SE_##B }
14943#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14944#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
5aae9ae9 14945#define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
037e8744
JB
14946
14947#define X(N, L, C) { N, S##N L }
14948
14949static struct neon_shape_info neon_shape_tab[] =
14950{
14951 NEON_SHAPE_DEF
14952};
14953
14954#undef X
14955#undef S2
14956#undef S3
14957#undef S4
5aae9ae9 14958#undef S5
037e8744 14959
5287ad62
JB
14960/* Bit masks used in type checking given instructions.
14961 'N_EQK' means the type must be the same as (or based on in some way) the key
14962 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14963 set, various other bits can be set as well in order to modify the meaning of
14964 the type constraint. */
14965
14966enum neon_type_mask
14967{
8e79c3df
CM
14968 N_S8 = 0x0000001,
14969 N_S16 = 0x0000002,
14970 N_S32 = 0x0000004,
14971 N_S64 = 0x0000008,
14972 N_U8 = 0x0000010,
14973 N_U16 = 0x0000020,
14974 N_U32 = 0x0000040,
14975 N_U64 = 0x0000080,
14976 N_I8 = 0x0000100,
14977 N_I16 = 0x0000200,
14978 N_I32 = 0x0000400,
14979 N_I64 = 0x0000800,
14980 N_8 = 0x0001000,
14981 N_16 = 0x0002000,
14982 N_32 = 0x0004000,
14983 N_64 = 0x0008000,
14984 N_P8 = 0x0010000,
14985 N_P16 = 0x0020000,
14986 N_F16 = 0x0040000,
14987 N_F32 = 0x0080000,
14988 N_F64 = 0x0100000,
4f51b4bd 14989 N_P64 = 0x0200000,
aab2c27d 14990 N_BF16 = 0x0400000,
c921be7d
NC
14991 N_KEY = 0x1000000, /* Key element (main type specifier). */
14992 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14993 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14994 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14995 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14996 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14997 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14998 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14999 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
15000 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
15001 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 15002 N_UTYP = 0,
4f51b4bd 15003 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
15004};
15005
dcbf9037
JB
15006#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15007
5287ad62
JB
15008#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15009#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15010#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
15011#define N_S_32 (N_S8 | N_S16 | N_S32)
15012#define N_F_16_32 (N_F16 | N_F32)
15013#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 15014#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 15015#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 15016#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
15017#define N_I_MVE (N_I8 | N_I16 | N_I32)
15018#define N_F_MVE (N_F16 | N_F32)
15019#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
15020
15021/* Pass this as the first type argument to neon_check_type to ignore types
15022 altogether. */
15023#define N_IGNORE_TYPE (N_KEY | N_EQK)
15024
037e8744
JB
15025/* Select a "shape" for the current instruction (describing register types or
15026 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15027 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15028 function of operand parsing, so this function doesn't need to be called.
15029 Shapes should be listed in order of decreasing length. */
5287ad62
JB
15030
15031static enum neon_shape
037e8744 15032neon_select_shape (enum neon_shape shape, ...)
5287ad62 15033{
037e8744
JB
15034 va_list ap;
15035 enum neon_shape first_shape = shape;
5287ad62
JB
15036
15037 /* Fix missing optional operands. FIXME: we don't know at this point how
15038 many arguments we should have, so this makes the assumption that we have
15039 > 1. This is true of all current Neon opcodes, I think, but may not be
15040 true in the future. */
15041 if (!inst.operands[1].present)
15042 inst.operands[1] = inst.operands[0];
15043
037e8744 15044 va_start (ap, shape);
5f4273c7 15045
21d799b5 15046 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
15047 {
15048 unsigned j;
15049 int matches = 1;
15050
15051 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
15052 {
15053 if (!inst.operands[j].present)
15054 {
15055 matches = 0;
15056 break;
15057 }
15058
15059 switch (neon_shape_tab[shape].el[j])
15060 {
d54af2d0
RL
15061 /* If a .f16, .16, .u16, .s16 type specifier is given over
15062 a VFP single precision register operand, it's essentially
15063 means only half of the register is used.
15064
15065 If the type specifier is given after the mnemonics, the
15066 information is stored in inst.vectype. If the type specifier
15067 is given after register operand, the information is stored
15068 in inst.operands[].vectype.
15069
15070 When there is only one type specifier, and all the register
15071 operands are the same type of hardware register, the type
15072 specifier applies to all register operands.
15073
15074 If no type specifier is given, the shape is inferred from
15075 operand information.
15076
15077 for example:
15078 vadd.f16 s0, s1, s2: NS_HHH
15079 vabs.f16 s0, s1: NS_HH
15080 vmov.f16 s0, r1: NS_HR
15081 vmov.f16 r0, s1: NS_RH
15082 vcvt.f16 r0, s1: NS_RH
15083 vcvt.f16.s32 s2, s2, #29: NS_HFI
15084 vcvt.f16.s32 s2, s2: NS_HF
15085 */
15086 case SE_H:
15087 if (!(inst.operands[j].isreg
15088 && inst.operands[j].isvec
15089 && inst.operands[j].issingle
15090 && !inst.operands[j].isquad
15091 && ((inst.vectype.elems == 1
15092 && inst.vectype.el[0].size == 16)
15093 || (inst.vectype.elems > 1
15094 && inst.vectype.el[j].size == 16)
15095 || (inst.vectype.elems == 0
15096 && inst.operands[j].vectype.type != NT_invtype
15097 && inst.operands[j].vectype.size == 16))))
15098 matches = 0;
15099 break;
15100
477330fc
RM
15101 case SE_F:
15102 if (!(inst.operands[j].isreg
15103 && inst.operands[j].isvec
15104 && inst.operands[j].issingle
d54af2d0
RL
15105 && !inst.operands[j].isquad
15106 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15107 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15108 || (inst.vectype.elems == 0
15109 && (inst.operands[j].vectype.size == 32
15110 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
15111 matches = 0;
15112 break;
15113
15114 case SE_D:
15115 if (!(inst.operands[j].isreg
15116 && inst.operands[j].isvec
15117 && !inst.operands[j].isquad
15118 && !inst.operands[j].issingle))
15119 matches = 0;
15120 break;
15121
15122 case SE_R:
15123 if (!(inst.operands[j].isreg
15124 && !inst.operands[j].isvec))
15125 matches = 0;
15126 break;
15127
15128 case SE_Q:
15129 if (!(inst.operands[j].isreg
15130 && inst.operands[j].isvec
15131 && inst.operands[j].isquad
15132 && !inst.operands[j].issingle))
15133 matches = 0;
15134 break;
15135
15136 case SE_I:
15137 if (!(!inst.operands[j].isreg
15138 && !inst.operands[j].isscalar))
15139 matches = 0;
15140 break;
15141
15142 case SE_S:
15143 if (!(!inst.operands[j].isreg
15144 && inst.operands[j].isscalar))
15145 matches = 0;
15146 break;
15147
5aae9ae9 15148 case SE_P:
477330fc
RM
15149 case SE_L:
15150 break;
15151 }
3fde54a2
JZ
15152 if (!matches)
15153 break;
477330fc 15154 }
ad6cec43
MGD
15155 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15156 /* We've matched all the entries in the shape table, and we don't
15157 have any left over operands which have not been matched. */
477330fc 15158 break;
037e8744 15159 }
5f4273c7 15160
037e8744 15161 va_end (ap);
5287ad62 15162
037e8744
JB
15163 if (shape == NS_NULL && first_shape != NS_NULL)
15164 first_error (_("invalid instruction shape"));
5287ad62 15165
037e8744
JB
15166 return shape;
15167}
5287ad62 15168
037e8744
JB
15169/* True if SHAPE is predominantly a quadword operation (most of the time, this
15170 means the Q bit should be set). */
15171
15172static int
15173neon_quad (enum neon_shape shape)
15174{
15175 return neon_shape_class[shape] == SC_QUAD;
5287ad62 15176}
037e8744 15177
5287ad62
JB
15178static void
15179neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 15180 unsigned *g_size)
5287ad62
JB
15181{
15182 /* Allow modification to be made to types which are constrained to be
15183 based on the key element, based on bits set alongside N_EQK. */
15184 if ((typebits & N_EQK) != 0)
15185 {
15186 if ((typebits & N_HLF) != 0)
15187 *g_size /= 2;
15188 else if ((typebits & N_DBL) != 0)
15189 *g_size *= 2;
15190 if ((typebits & N_SGN) != 0)
15191 *g_type = NT_signed;
15192 else if ((typebits & N_UNS) != 0)
477330fc 15193 *g_type = NT_unsigned;
5287ad62 15194 else if ((typebits & N_INT) != 0)
477330fc 15195 *g_type = NT_integer;
5287ad62 15196 else if ((typebits & N_FLT) != 0)
477330fc 15197 *g_type = NT_float;
dcbf9037 15198 else if ((typebits & N_SIZ) != 0)
477330fc 15199 *g_type = NT_untyped;
5287ad62
JB
15200 }
15201}
5f4273c7 15202
5287ad62
JB
15203/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15204 operand type, i.e. the single type specified in a Neon instruction when it
15205 is the only one given. */
15206
15207static struct neon_type_el
15208neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15209{
15210 struct neon_type_el dest = *key;
5f4273c7 15211
9c2799c2 15212 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15213
5287ad62
JB
15214 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15215
15216 return dest;
15217}
15218
15219/* Convert Neon type and size into compact bitmask representation. */
15220
15221static enum neon_type_mask
15222type_chk_of_el_type (enum neon_el_type type, unsigned size)
15223{
15224 switch (type)
15225 {
15226 case NT_untyped:
15227 switch (size)
477330fc
RM
15228 {
15229 case 8: return N_8;
15230 case 16: return N_16;
15231 case 32: return N_32;
15232 case 64: return N_64;
15233 default: ;
15234 }
5287ad62
JB
15235 break;
15236
15237 case NT_integer:
15238 switch (size)
477330fc
RM
15239 {
15240 case 8: return N_I8;
15241 case 16: return N_I16;
15242 case 32: return N_I32;
15243 case 64: return N_I64;
15244 default: ;
15245 }
5287ad62
JB
15246 break;
15247
15248 case NT_float:
037e8744 15249 switch (size)
477330fc 15250 {
8e79c3df 15251 case 16: return N_F16;
477330fc
RM
15252 case 32: return N_F32;
15253 case 64: return N_F64;
15254 default: ;
15255 }
5287ad62
JB
15256 break;
15257
15258 case NT_poly:
15259 switch (size)
477330fc
RM
15260 {
15261 case 8: return N_P8;
15262 case 16: return N_P16;
4f51b4bd 15263 case 64: return N_P64;
477330fc
RM
15264 default: ;
15265 }
5287ad62
JB
15266 break;
15267
15268 case NT_signed:
15269 switch (size)
477330fc
RM
15270 {
15271 case 8: return N_S8;
15272 case 16: return N_S16;
15273 case 32: return N_S32;
15274 case 64: return N_S64;
15275 default: ;
15276 }
5287ad62
JB
15277 break;
15278
15279 case NT_unsigned:
15280 switch (size)
477330fc
RM
15281 {
15282 case 8: return N_U8;
15283 case 16: return N_U16;
15284 case 32: return N_U32;
15285 case 64: return N_U64;
15286 default: ;
15287 }
5287ad62
JB
15288 break;
15289
aab2c27d
MM
15290 case NT_bfloat:
15291 if (size == 16) return N_BF16;
15292 break;
15293
5287ad62
JB
15294 default: ;
15295 }
5f4273c7 15296
5287ad62
JB
15297 return N_UTYP;
15298}
15299
15300/* Convert compact Neon bitmask type representation to a type and size. Only
15301 handles the case where a single bit is set in the mask. */
15302
dcbf9037 15303static int
5287ad62 15304el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15305 enum neon_type_mask mask)
5287ad62 15306{
dcbf9037
JB
15307 if ((mask & N_EQK) != 0)
15308 return FAIL;
15309
5287ad62
JB
15310 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15311 *size = 8;
aab2c27d
MM
15312 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15313 != 0)
5287ad62 15314 *size = 16;
dcbf9037 15315 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15316 *size = 32;
4f51b4bd 15317 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15318 *size = 64;
dcbf9037
JB
15319 else
15320 return FAIL;
15321
5287ad62
JB
15322 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15323 *type = NT_signed;
dcbf9037 15324 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15325 *type = NT_unsigned;
dcbf9037 15326 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15327 *type = NT_integer;
dcbf9037 15328 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15329 *type = NT_untyped;
4f51b4bd 15330 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15331 *type = NT_poly;
d54af2d0 15332 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15333 *type = NT_float;
aab2c27d
MM
15334 else if ((mask & (N_BF16)) != 0)
15335 *type = NT_bfloat;
dcbf9037
JB
15336 else
15337 return FAIL;
5f4273c7 15338
dcbf9037 15339 return SUCCESS;
5287ad62
JB
15340}
15341
15342/* Modify a bitmask of allowed types. This is only needed for type
15343 relaxation. */
15344
15345static unsigned
15346modify_types_allowed (unsigned allowed, unsigned mods)
15347{
15348 unsigned size;
15349 enum neon_el_type type;
15350 unsigned destmask;
15351 int i;
5f4273c7 15352
5287ad62 15353 destmask = 0;
5f4273c7 15354
5287ad62
JB
15355 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15356 {
21d799b5 15357 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15358 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15359 {
15360 neon_modify_type_size (mods, &type, &size);
15361 destmask |= type_chk_of_el_type (type, size);
15362 }
5287ad62 15363 }
5f4273c7 15364
5287ad62
JB
15365 return destmask;
15366}
15367
15368/* Check type and return type classification.
15369 The manual states (paraphrase): If one datatype is given, it indicates the
15370 type given in:
15371 - the second operand, if there is one
15372 - the operand, if there is no second operand
15373 - the result, if there are no operands.
15374 This isn't quite good enough though, so we use a concept of a "key" datatype
15375 which is set on a per-instruction basis, which is the one which matters when
15376 only one data type is written.
15377 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15378 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15379
15380static struct neon_type_el
15381neon_check_type (unsigned els, enum neon_shape ns, ...)
15382{
15383 va_list ap;
15384 unsigned i, pass, key_el = 0;
15385 unsigned types[NEON_MAX_TYPE_ELS];
15386 enum neon_el_type k_type = NT_invtype;
15387 unsigned k_size = -1u;
15388 struct neon_type_el badtype = {NT_invtype, -1};
15389 unsigned key_allowed = 0;
15390
15391 /* Optional registers in Neon instructions are always (not) in operand 1.
15392 Fill in the missing operand here, if it was omitted. */
15393 if (els > 1 && !inst.operands[1].present)
15394 inst.operands[1] = inst.operands[0];
15395
15396 /* Suck up all the varargs. */
15397 va_start (ap, ns);
15398 for (i = 0; i < els; i++)
15399 {
15400 unsigned thisarg = va_arg (ap, unsigned);
15401 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15402 {
15403 va_end (ap);
15404 return badtype;
15405 }
5287ad62
JB
15406 types[i] = thisarg;
15407 if ((thisarg & N_KEY) != 0)
477330fc 15408 key_el = i;
5287ad62
JB
15409 }
15410 va_end (ap);
15411
dcbf9037
JB
15412 if (inst.vectype.elems > 0)
15413 for (i = 0; i < els; i++)
15414 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15415 {
15416 first_error (_("types specified in both the mnemonic and operands"));
15417 return badtype;
15418 }
dcbf9037 15419
5287ad62
JB
15420 /* Duplicate inst.vectype elements here as necessary.
15421 FIXME: No idea if this is exactly the same as the ARM assembler,
15422 particularly when an insn takes one register and one non-register
15423 operand. */
15424 if (inst.vectype.elems == 1 && els > 1)
15425 {
15426 unsigned j;
15427 inst.vectype.elems = els;
15428 inst.vectype.el[key_el] = inst.vectype.el[0];
15429 for (j = 0; j < els; j++)
477330fc
RM
15430 if (j != key_el)
15431 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15432 types[j]);
dcbf9037
JB
15433 }
15434 else if (inst.vectype.elems == 0 && els > 0)
15435 {
15436 unsigned j;
15437 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15438 after each operand. We allow some flexibility here; as long as the
15439 "key" operand has a type, we can infer the others. */
dcbf9037 15440 for (j = 0; j < els; j++)
477330fc
RM
15441 if (inst.operands[j].vectype.type != NT_invtype)
15442 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15443
15444 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15445 {
15446 for (j = 0; j < els; j++)
15447 if (inst.operands[j].vectype.type == NT_invtype)
15448 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15449 types[j]);
15450 }
dcbf9037 15451 else
477330fc
RM
15452 {
15453 first_error (_("operand types can't be inferred"));
15454 return badtype;
15455 }
5287ad62
JB
15456 }
15457 else if (inst.vectype.elems != els)
15458 {
dcbf9037 15459 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15460 return badtype;
15461 }
15462
15463 for (pass = 0; pass < 2; pass++)
15464 {
15465 for (i = 0; i < els; i++)
477330fc
RM
15466 {
15467 unsigned thisarg = types[i];
15468 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15469 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15470 enum neon_el_type g_type = inst.vectype.el[i].type;
15471 unsigned g_size = inst.vectype.el[i].size;
15472
15473 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15474 integer types if sign-specific variants are unavailable. */
477330fc 15475 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15476 && (types_allowed & N_SU_ALL) == 0)
15477 g_type = NT_integer;
15478
477330fc 15479 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15480 them. Some instructions only care about signs for some element
15481 sizes, so handle that properly. */
477330fc 15482 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15483 && ((g_size == 8 && (types_allowed & N_8) != 0)
15484 || (g_size == 16 && (types_allowed & N_16) != 0)
15485 || (g_size == 32 && (types_allowed & N_32) != 0)
15486 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15487 g_type = NT_untyped;
15488
477330fc
RM
15489 if (pass == 0)
15490 {
15491 if ((thisarg & N_KEY) != 0)
15492 {
15493 k_type = g_type;
15494 k_size = g_size;
15495 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15496
15497 /* Check architecture constraint on FP16 extension. */
15498 if (k_size == 16
15499 && k_type == NT_float
15500 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15501 {
15502 inst.error = _(BAD_FP16);
15503 return badtype;
15504 }
477330fc
RM
15505 }
15506 }
15507 else
15508 {
15509 if ((thisarg & N_VFP) != 0)
15510 {
15511 enum neon_shape_el regshape;
15512 unsigned regwidth, match;
99b253c5
NC
15513
15514 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15515 if (ns == NS_NULL)
15516 {
15517 first_error (_("invalid instruction shape"));
15518 return badtype;
15519 }
477330fc
RM
15520 regshape = neon_shape_tab[ns].el[i];
15521 regwidth = neon_shape_el_size[regshape];
15522
15523 /* In VFP mode, operands must match register widths. If we
15524 have a key operand, use its width, else use the width of
15525 the current operand. */
15526 if (k_size != -1u)
15527 match = k_size;
15528 else
15529 match = g_size;
15530
9db2f6b4
RL
15531 /* FP16 will use a single precision register. */
15532 if (regwidth == 32 && match == 16)
15533 {
15534 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15535 match = regwidth;
15536 else
15537 {
15538 inst.error = _(BAD_FP16);
15539 return badtype;
15540 }
15541 }
15542
477330fc
RM
15543 if (regwidth != match)
15544 {
15545 first_error (_("operand size must match register width"));
15546 return badtype;
15547 }
15548 }
15549
15550 if ((thisarg & N_EQK) == 0)
15551 {
15552 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15553
15554 if ((given_type & types_allowed) == 0)
15555 {
a302e574 15556 first_error (BAD_SIMD_TYPE);
477330fc
RM
15557 return badtype;
15558 }
15559 }
15560 else
15561 {
15562 enum neon_el_type mod_k_type = k_type;
15563 unsigned mod_k_size = k_size;
15564 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15565 if (g_type != mod_k_type || g_size != mod_k_size)
15566 {
15567 first_error (_("inconsistent types in Neon instruction"));
15568 return badtype;
15569 }
15570 }
15571 }
15572 }
5287ad62
JB
15573 }
15574
15575 return inst.vectype.el[key_el];
15576}
15577
037e8744 15578/* Neon-style VFP instruction forwarding. */
5287ad62 15579
037e8744
JB
15580/* Thumb VFP instructions have 0xE in the condition field. */
15581
15582static void
15583do_vfp_cond_or_thumb (void)
5287ad62 15584{
88714cb8
DG
15585 inst.is_neon = 1;
15586
5287ad62 15587 if (thumb_mode)
037e8744 15588 inst.instruction |= 0xe0000000;
5287ad62 15589 else
037e8744 15590 inst.instruction |= inst.cond << 28;
5287ad62
JB
15591}
15592
037e8744
JB
15593/* Look up and encode a simple mnemonic, for use as a helper function for the
15594 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15595 etc. It is assumed that operand parsing has already been done, and that the
15596 operands are in the form expected by the given opcode (this isn't necessarily
15597 the same as the form in which they were parsed, hence some massaging must
15598 take place before this function is called).
15599 Checks current arch version against that in the looked-up opcode. */
5287ad62 15600
037e8744
JB
15601static void
15602do_vfp_nsyn_opcode (const char *opname)
5287ad62 15603{
037e8744 15604 const struct asm_opcode *opcode;
5f4273c7 15605
629310ab 15606 opcode = (const struct asm_opcode *) str_hash_find (arm_ops_hsh, opname);
5287ad62 15607
037e8744
JB
15608 if (!opcode)
15609 abort ();
5287ad62 15610
037e8744 15611 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15612 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15613 _(BAD_FPU));
5287ad62 15614
88714cb8
DG
15615 inst.is_neon = 1;
15616
037e8744
JB
15617 if (thumb_mode)
15618 {
15619 inst.instruction = opcode->tvalue;
15620 opcode->tencode ();
15621 }
15622 else
15623 {
15624 inst.instruction = (inst.cond << 28) | opcode->avalue;
15625 opcode->aencode ();
15626 }
15627}
5287ad62
JB
15628
15629static void
037e8744 15630do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15631{
037e8744
JB
15632 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15633
9db2f6b4 15634 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15635 {
15636 if (is_add)
477330fc 15637 do_vfp_nsyn_opcode ("fadds");
037e8744 15638 else
477330fc 15639 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15640
15641 /* ARMv8.2 fp16 instruction. */
15642 if (rs == NS_HHH)
15643 do_scalar_fp16_v82_encode ();
037e8744
JB
15644 }
15645 else
15646 {
15647 if (is_add)
477330fc 15648 do_vfp_nsyn_opcode ("faddd");
037e8744 15649 else
477330fc 15650 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15651 }
15652}
15653
15654/* Check operand types to see if this is a VFP instruction, and if so call
15655 PFN (). */
15656
15657static int
15658try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15659{
15660 enum neon_shape rs;
15661 struct neon_type_el et;
15662
15663 switch (args)
15664 {
15665 case 2:
9db2f6b4
RL
15666 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15667 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15668 break;
5f4273c7 15669
037e8744 15670 case 3:
9db2f6b4
RL
15671 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15672 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15673 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15674 break;
15675
15676 default:
15677 abort ();
15678 }
15679
15680 if (et.type != NT_invtype)
15681 {
15682 pfn (rs);
15683 return SUCCESS;
15684 }
037e8744 15685
99b253c5 15686 inst.error = NULL;
037e8744
JB
15687 return FAIL;
15688}
15689
15690static void
15691do_vfp_nsyn_mla_mls (enum neon_shape rs)
15692{
15693 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15694
9db2f6b4 15695 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15696 {
15697 if (is_mla)
477330fc 15698 do_vfp_nsyn_opcode ("fmacs");
037e8744 15699 else
477330fc 15700 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15701
15702 /* ARMv8.2 fp16 instruction. */
15703 if (rs == NS_HHH)
15704 do_scalar_fp16_v82_encode ();
037e8744
JB
15705 }
15706 else
15707 {
15708 if (is_mla)
477330fc 15709 do_vfp_nsyn_opcode ("fmacd");
037e8744 15710 else
477330fc 15711 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15712 }
15713}
15714
62f3b8c8
PB
15715static void
15716do_vfp_nsyn_fma_fms (enum neon_shape rs)
15717{
15718 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15719
9db2f6b4 15720 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15721 {
15722 if (is_fma)
477330fc 15723 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15724 else
477330fc 15725 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15726
15727 /* ARMv8.2 fp16 instruction. */
15728 if (rs == NS_HHH)
15729 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15730 }
15731 else
15732 {
15733 if (is_fma)
477330fc 15734 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15735 else
477330fc 15736 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15737 }
15738}
15739
037e8744
JB
15740static void
15741do_vfp_nsyn_mul (enum neon_shape rs)
15742{
9db2f6b4
RL
15743 if (rs == NS_FFF || rs == NS_HHH)
15744 {
15745 do_vfp_nsyn_opcode ("fmuls");
15746
15747 /* ARMv8.2 fp16 instruction. */
15748 if (rs == NS_HHH)
15749 do_scalar_fp16_v82_encode ();
15750 }
037e8744
JB
15751 else
15752 do_vfp_nsyn_opcode ("fmuld");
15753}
15754
15755static void
15756do_vfp_nsyn_abs_neg (enum neon_shape rs)
15757{
15758 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15759 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15760
9db2f6b4 15761 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15762 {
15763 if (is_neg)
477330fc 15764 do_vfp_nsyn_opcode ("fnegs");
037e8744 15765 else
477330fc 15766 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15767
15768 /* ARMv8.2 fp16 instruction. */
15769 if (rs == NS_HH)
15770 do_scalar_fp16_v82_encode ();
037e8744
JB
15771 }
15772 else
15773 {
15774 if (is_neg)
477330fc 15775 do_vfp_nsyn_opcode ("fnegd");
037e8744 15776 else
477330fc 15777 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15778 }
15779}
15780
15781/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15782 insns belong to Neon, and are handled elsewhere. */
15783
15784static void
15785do_vfp_nsyn_ldm_stm (int is_dbmode)
15786{
15787 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15788 if (is_ldm)
15789 {
15790 if (is_dbmode)
477330fc 15791 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15792 else
477330fc 15793 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15794 }
15795 else
15796 {
15797 if (is_dbmode)
477330fc 15798 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15799 else
477330fc 15800 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15801 }
15802}
15803
037e8744
JB
15804static void
15805do_vfp_nsyn_sqrt (void)
15806{
9db2f6b4
RL
15807 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15808 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15809
9db2f6b4
RL
15810 if (rs == NS_FF || rs == NS_HH)
15811 {
15812 do_vfp_nsyn_opcode ("fsqrts");
15813
15814 /* ARMv8.2 fp16 instruction. */
15815 if (rs == NS_HH)
15816 do_scalar_fp16_v82_encode ();
15817 }
037e8744
JB
15818 else
15819 do_vfp_nsyn_opcode ("fsqrtd");
15820}
15821
15822static void
15823do_vfp_nsyn_div (void)
15824{
9db2f6b4 15825 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15826 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15827 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15828
9db2f6b4
RL
15829 if (rs == NS_FFF || rs == NS_HHH)
15830 {
15831 do_vfp_nsyn_opcode ("fdivs");
15832
15833 /* ARMv8.2 fp16 instruction. */
15834 if (rs == NS_HHH)
15835 do_scalar_fp16_v82_encode ();
15836 }
037e8744
JB
15837 else
15838 do_vfp_nsyn_opcode ("fdivd");
15839}
15840
15841static void
15842do_vfp_nsyn_nmul (void)
15843{
9db2f6b4 15844 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15845 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15846 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15847
9db2f6b4 15848 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15849 {
88714cb8 15850 NEON_ENCODE (SINGLE, inst);
037e8744 15851 do_vfp_sp_dyadic ();
9db2f6b4
RL
15852
15853 /* ARMv8.2 fp16 instruction. */
15854 if (rs == NS_HHH)
15855 do_scalar_fp16_v82_encode ();
037e8744
JB
15856 }
15857 else
15858 {
88714cb8 15859 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15860 do_vfp_dp_rd_rn_rm ();
15861 }
15862 do_vfp_cond_or_thumb ();
9db2f6b4 15863
037e8744
JB
15864}
15865
1b883319
AV
15866/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15867 (0, 1, 2, 3). */
15868
15869static unsigned
15870neon_logbits (unsigned x)
15871{
15872 return ffs (x) - 4;
15873}
15874
15875#define LOW4(R) ((R) & 0xf)
15876#define HI1(R) (((R) >> 4) & 1)
5aae9ae9
MM
15877#define LOW1(R) ((R) & 0x1)
15878#define HI4(R) (((R) >> 1) & 0xf)
1b883319
AV
15879
15880static unsigned
15881mve_get_vcmp_vpt_cond (struct neon_type_el et)
15882{
15883 switch (et.type)
15884 {
15885 default:
15886 first_error (BAD_EL_TYPE);
15887 return 0;
15888 case NT_float:
15889 switch (inst.operands[0].imm)
15890 {
15891 default:
15892 first_error (_("invalid condition"));
15893 return 0;
15894 case 0x0:
15895 /* eq. */
15896 return 0;
15897 case 0x1:
15898 /* ne. */
15899 return 1;
15900 case 0xa:
15901 /* ge/ */
15902 return 4;
15903 case 0xb:
15904 /* lt. */
15905 return 5;
15906 case 0xc:
15907 /* gt. */
15908 return 6;
15909 case 0xd:
15910 /* le. */
15911 return 7;
15912 }
15913 case NT_integer:
15914 /* only accept eq and ne. */
15915 if (inst.operands[0].imm > 1)
15916 {
15917 first_error (_("invalid condition"));
15918 return 0;
15919 }
15920 return inst.operands[0].imm;
15921 case NT_unsigned:
15922 if (inst.operands[0].imm == 0x2)
15923 return 2;
15924 else if (inst.operands[0].imm == 0x8)
15925 return 3;
15926 else
15927 {
15928 first_error (_("invalid condition"));
15929 return 0;
15930 }
15931 case NT_signed:
15932 switch (inst.operands[0].imm)
15933 {
15934 default:
15935 first_error (_("invalid condition"));
15936 return 0;
15937 case 0xa:
15938 /* ge. */
15939 return 4;
15940 case 0xb:
15941 /* lt. */
15942 return 5;
15943 case 0xc:
15944 /* gt. */
15945 return 6;
15946 case 0xd:
15947 /* le. */
15948 return 7;
15949 }
15950 }
15951 /* Should be unreachable. */
15952 abort ();
15953}
15954
efd0b310
SP
15955/* For VCTP (create vector tail predicate) in MVE. */
15956static void
15957do_mve_vctp (void)
15958{
15959 int dt = 0;
15960 unsigned size = 0x0;
15961
15962 if (inst.cond > COND_ALWAYS)
15963 inst.pred_insn_type = INSIDE_VPT_INSN;
15964 else
15965 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15966
15967 /* This is a typical MVE instruction which has no type but have size 8, 16,
15968 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15969 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15970 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15971 dt = inst.vectype.el[0].size;
15972
15973 /* Setting this does not indicate an actual NEON instruction, but only
15974 indicates that the mnemonic accepts neon-style type suffixes. */
15975 inst.is_neon = 1;
15976
15977 switch (dt)
15978 {
15979 case 8:
15980 break;
15981 case 16:
15982 size = 0x1; break;
15983 case 32:
15984 size = 0x2; break;
15985 case 64:
15986 size = 0x3; break;
15987 default:
15988 first_error (_("Type is not allowed for this instruction"));
15989 }
15990 inst.instruction |= size << 20;
15991 inst.instruction |= inst.operands[0].reg << 16;
15992}
15993
1b883319
AV
15994static void
15995do_mve_vpt (void)
15996{
15997 /* We are dealing with a vector predicated block. */
15998 if (inst.operands[0].present)
15999 {
16000 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16001 struct neon_type_el et
16002 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16003 N_EQK);
16004
16005 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16006
16007 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16008
16009 if (et.type == NT_invtype)
16010 return;
16011
16012 if (et.type == NT_float)
16013 {
16014 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16015 BAD_FPU);
16016 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16017 inst.instruction |= (et.size == 16) << 28;
16018 inst.instruction |= 0x3 << 20;
16019 }
16020 else
16021 {
16022 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16023 BAD_EL_TYPE);
16024 inst.instruction |= 1 << 28;
16025 inst.instruction |= neon_logbits (et.size) << 20;
16026 }
16027
16028 if (inst.operands[2].isquad)
16029 {
16030 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16031 inst.instruction |= LOW4 (inst.operands[2].reg);
16032 inst.instruction |= (fcond & 0x2) >> 1;
16033 }
16034 else
16035 {
16036 if (inst.operands[2].reg == REG_SP)
16037 as_tsktsk (MVE_BAD_SP);
16038 inst.instruction |= 1 << 6;
16039 inst.instruction |= (fcond & 0x2) << 4;
16040 inst.instruction |= inst.operands[2].reg;
16041 }
16042 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16043 inst.instruction |= (fcond & 0x4) << 10;
16044 inst.instruction |= (fcond & 0x1) << 7;
16045
16046 }
16047 set_pred_insn_type (VPT_INSN);
16048 now_pred.cc = 0;
16049 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16050 | ((inst.instruction & 0xe000) >> 13);
16051 now_pred.warn_deprecated = FALSE;
16052 now_pred.type = VECTOR_PRED;
16053 inst.is_neon = 1;
16054}
16055
16056static void
16057do_mve_vcmp (void)
16058{
16059 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16060 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16061 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16062 if (!inst.operands[2].present)
16063 first_error (_("MVE vector or ARM register expected"));
16064 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16065
16066 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16067 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16068 && inst.operands[1].isquad)
16069 {
16070 inst.instruction = N_MNEM_vcmp;
16071 inst.cond = 0x10;
16072 }
16073
16074 if (inst.cond > COND_ALWAYS)
16075 inst.pred_insn_type = INSIDE_VPT_INSN;
16076 else
16077 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16078
16079 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16080 struct neon_type_el et
16081 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16082 N_EQK);
16083
16084 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16085 && !inst.operands[2].iszr, BAD_PC);
16086
16087 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16088
16089 inst.instruction = 0xee010f00;
16090 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16091 inst.instruction |= (fcond & 0x4) << 10;
16092 inst.instruction |= (fcond & 0x1) << 7;
16093 if (et.type == NT_float)
16094 {
16095 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16096 BAD_FPU);
16097 inst.instruction |= (et.size == 16) << 28;
16098 inst.instruction |= 0x3 << 20;
16099 }
16100 else
16101 {
16102 inst.instruction |= 1 << 28;
16103 inst.instruction |= neon_logbits (et.size) << 20;
16104 }
16105 if (inst.operands[2].isquad)
16106 {
16107 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16108 inst.instruction |= (fcond & 0x2) >> 1;
16109 inst.instruction |= LOW4 (inst.operands[2].reg);
16110 }
16111 else
16112 {
16113 if (inst.operands[2].reg == REG_SP)
16114 as_tsktsk (MVE_BAD_SP);
16115 inst.instruction |= 1 << 6;
16116 inst.instruction |= (fcond & 0x2) << 4;
16117 inst.instruction |= inst.operands[2].reg;
16118 }
16119
16120 inst.is_neon = 1;
16121 return;
16122}
16123
935295b5
AV
16124static void
16125do_mve_vmaxa_vmina (void)
16126{
16127 if (inst.cond > COND_ALWAYS)
16128 inst.pred_insn_type = INSIDE_VPT_INSN;
16129 else
16130 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16131
16132 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16133 struct neon_type_el et
16134 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16135
16136 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16137 inst.instruction |= neon_logbits (et.size) << 18;
16138 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16139 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16140 inst.instruction |= LOW4 (inst.operands[1].reg);
16141 inst.is_neon = 1;
16142}
16143
f30ee27c
AV
16144static void
16145do_mve_vfmas (void)
16146{
16147 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16148 struct neon_type_el et
16149 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16150
16151 if (inst.cond > COND_ALWAYS)
16152 inst.pred_insn_type = INSIDE_VPT_INSN;
16153 else
16154 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16155
16156 if (inst.operands[2].reg == REG_SP)
16157 as_tsktsk (MVE_BAD_SP);
16158 else if (inst.operands[2].reg == REG_PC)
16159 as_tsktsk (MVE_BAD_PC);
16160
16161 inst.instruction |= (et.size == 16) << 28;
16162 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16163 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16164 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16165 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16166 inst.instruction |= inst.operands[2].reg;
16167 inst.is_neon = 1;
16168}
16169
b409bdb6
AV
16170static void
16171do_mve_viddup (void)
16172{
16173 if (inst.cond > COND_ALWAYS)
16174 inst.pred_insn_type = INSIDE_VPT_INSN;
16175 else
16176 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16177
16178 unsigned imm = inst.relocs[0].exp.X_add_number;
16179 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16180 _("immediate must be either 1, 2, 4 or 8"));
16181
16182 enum neon_shape rs;
16183 struct neon_type_el et;
16184 unsigned Rm;
16185 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16186 {
16187 rs = neon_select_shape (NS_QRI, NS_NULL);
16188 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16189 Rm = 7;
16190 }
16191 else
16192 {
16193 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16194 if (inst.operands[2].reg == REG_SP)
16195 as_tsktsk (MVE_BAD_SP);
16196 else if (inst.operands[2].reg == REG_PC)
16197 first_error (BAD_PC);
16198
16199 rs = neon_select_shape (NS_QRRI, NS_NULL);
16200 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16201 Rm = inst.operands[2].reg >> 1;
16202 }
16203 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16204 inst.instruction |= neon_logbits (et.size) << 20;
16205 inst.instruction |= inst.operands[1].reg << 16;
16206 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16207 inst.instruction |= (imm > 2) << 7;
16208 inst.instruction |= Rm << 1;
16209 inst.instruction |= (imm == 2 || imm == 8);
16210 inst.is_neon = 1;
16211}
16212
2d78f95b
AV
16213static void
16214do_mve_vmlas (void)
16215{
16216 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16217 struct neon_type_el et
16218 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16219
16220 if (inst.operands[2].reg == REG_PC)
16221 as_tsktsk (MVE_BAD_PC);
16222 else if (inst.operands[2].reg == REG_SP)
16223 as_tsktsk (MVE_BAD_SP);
16224
16225 if (inst.cond > COND_ALWAYS)
16226 inst.pred_insn_type = INSIDE_VPT_INSN;
16227 else
16228 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16229
16230 inst.instruction |= (et.type == NT_unsigned) << 28;
16231 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16232 inst.instruction |= neon_logbits (et.size) << 20;
16233 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16234 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16235 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16236 inst.instruction |= inst.operands[2].reg;
16237 inst.is_neon = 1;
16238}
16239
acca5630
AV
16240static void
16241do_mve_vshll (void)
16242{
16243 struct neon_type_el et
16244 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16245
16246 if (inst.cond > COND_ALWAYS)
16247 inst.pred_insn_type = INSIDE_VPT_INSN;
16248 else
16249 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16250
16251 int imm = inst.operands[2].imm;
16252 constraint (imm < 1 || (unsigned)imm > et.size,
16253 _("immediate value out of range"));
16254
16255 if ((unsigned)imm == et.size)
16256 {
16257 inst.instruction |= neon_logbits (et.size) << 18;
16258 inst.instruction |= 0x110001;
16259 }
16260 else
16261 {
16262 inst.instruction |= (et.size + imm) << 16;
16263 inst.instruction |= 0x800140;
16264 }
16265
16266 inst.instruction |= (et.type == NT_unsigned) << 28;
16267 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16268 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16269 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16270 inst.instruction |= LOW4 (inst.operands[1].reg);
16271 inst.is_neon = 1;
16272}
16273
16274static void
16275do_mve_vshlc (void)
16276{
16277 if (inst.cond > COND_ALWAYS)
16278 inst.pred_insn_type = INSIDE_VPT_INSN;
16279 else
16280 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16281
16282 if (inst.operands[1].reg == REG_PC)
16283 as_tsktsk (MVE_BAD_PC);
16284 else if (inst.operands[1].reg == REG_SP)
16285 as_tsktsk (MVE_BAD_SP);
16286
16287 int imm = inst.operands[2].imm;
16288 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16289
16290 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16291 inst.instruction |= (imm & 0x1f) << 16;
16292 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16293 inst.instruction |= inst.operands[1].reg;
16294 inst.is_neon = 1;
16295}
16296
4aa88b50
AV
16297static void
16298do_mve_vshrn (void)
16299{
16300 unsigned types;
16301 switch (inst.instruction)
16302 {
16303 case M_MNEM_vshrnt:
16304 case M_MNEM_vshrnb:
16305 case M_MNEM_vrshrnt:
16306 case M_MNEM_vrshrnb:
16307 types = N_I16 | N_I32;
16308 break;
16309 case M_MNEM_vqshrnt:
16310 case M_MNEM_vqshrnb:
16311 case M_MNEM_vqrshrnt:
16312 case M_MNEM_vqrshrnb:
16313 types = N_U16 | N_U32 | N_S16 | N_S32;
16314 break;
16315 case M_MNEM_vqshrunt:
16316 case M_MNEM_vqshrunb:
16317 case M_MNEM_vqrshrunt:
16318 case M_MNEM_vqrshrunb:
16319 types = N_S16 | N_S32;
16320 break;
16321 default:
16322 abort ();
16323 }
16324
16325 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16326
16327 if (inst.cond > COND_ALWAYS)
16328 inst.pred_insn_type = INSIDE_VPT_INSN;
16329 else
16330 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16331
16332 unsigned Qd = inst.operands[0].reg;
16333 unsigned Qm = inst.operands[1].reg;
16334 unsigned imm = inst.operands[2].imm;
16335 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16336 et.size == 16
16337 ? _("immediate operand expected in the range [1,8]")
16338 : _("immediate operand expected in the range [1,16]"));
16339
16340 inst.instruction |= (et.type == NT_unsigned) << 28;
16341 inst.instruction |= HI1 (Qd) << 22;
16342 inst.instruction |= (et.size - imm) << 16;
16343 inst.instruction |= LOW4 (Qd) << 12;
16344 inst.instruction |= HI1 (Qm) << 5;
16345 inst.instruction |= LOW4 (Qm);
16346 inst.is_neon = 1;
16347}
16348
1be7aba3
AV
16349static void
16350do_mve_vqmovn (void)
16351{
16352 struct neon_type_el et;
16353 if (inst.instruction == M_MNEM_vqmovnt
16354 || inst.instruction == M_MNEM_vqmovnb)
16355 et = neon_check_type (2, NS_QQ, N_EQK,
16356 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16357 else
16358 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16359
16360 if (inst.cond > COND_ALWAYS)
16361 inst.pred_insn_type = INSIDE_VPT_INSN;
16362 else
16363 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16364
16365 inst.instruction |= (et.type == NT_unsigned) << 28;
16366 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16367 inst.instruction |= (et.size == 32) << 18;
16368 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16369 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16370 inst.instruction |= LOW4 (inst.operands[1].reg);
16371 inst.is_neon = 1;
16372}
16373
3063888e
AV
16374static void
16375do_mve_vpsel (void)
16376{
16377 neon_select_shape (NS_QQQ, NS_NULL);
16378
16379 if (inst.cond > COND_ALWAYS)
16380 inst.pred_insn_type = INSIDE_VPT_INSN;
16381 else
16382 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16383
16384 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16385 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16386 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16387 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16388 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16389 inst.instruction |= LOW4 (inst.operands[2].reg);
16390 inst.is_neon = 1;
16391}
16392
16393static void
16394do_mve_vpnot (void)
16395{
16396 if (inst.cond > COND_ALWAYS)
16397 inst.pred_insn_type = INSIDE_VPT_INSN;
16398 else
16399 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16400}
16401
935295b5
AV
16402static void
16403do_mve_vmaxnma_vminnma (void)
16404{
16405 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16406 struct neon_type_el et
16407 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16408
16409 if (inst.cond > COND_ALWAYS)
16410 inst.pred_insn_type = INSIDE_VPT_INSN;
16411 else
16412 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16413
16414 inst.instruction |= (et.size == 16) << 28;
16415 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16416 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16417 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16418 inst.instruction |= LOW4 (inst.operands[1].reg);
16419 inst.is_neon = 1;
16420}
16421
5d281bf0
AV
16422static void
16423do_mve_vcmul (void)
16424{
16425 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16426 struct neon_type_el et
16427 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16428
16429 if (inst.cond > COND_ALWAYS)
16430 inst.pred_insn_type = INSIDE_VPT_INSN;
16431 else
16432 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16433
16434 unsigned rot = inst.relocs[0].exp.X_add_number;
16435 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16436 _("immediate out of range"));
16437
16438 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16439 || inst.operands[0].reg == inst.operands[2].reg))
16440 as_tsktsk (BAD_MVE_SRCDEST);
16441
16442 inst.instruction |= (et.size == 32) << 28;
16443 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16444 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16445 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16446 inst.instruction |= (rot > 90) << 12;
16447 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16448 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16449 inst.instruction |= LOW4 (inst.operands[2].reg);
16450 inst.instruction |= (rot == 90 || rot == 270);
16451 inst.is_neon = 1;
16452}
16453
1f6234a3
AV
16454/* To handle the Low Overhead Loop instructions
16455 in Armv8.1-M Mainline and MVE. */
16456static void
16457do_t_loloop (void)
16458{
16459 unsigned long insn = inst.instruction;
16460
16461 inst.instruction = THUMB_OP32 (inst.instruction);
16462
16463 if (insn == T_MNEM_lctp)
16464 return;
16465
16466 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16467
16468 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16469 {
16470 struct neon_type_el et
16471 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16472 inst.instruction |= neon_logbits (et.size) << 20;
16473 inst.is_neon = 1;
16474 }
16475
16476 switch (insn)
16477 {
16478 case T_MNEM_letp:
16479 constraint (!inst.operands[0].present,
16480 _("expected LR"));
16481 /* fall through. */
16482 case T_MNEM_le:
16483 /* le <label>. */
16484 if (!inst.operands[0].present)
16485 inst.instruction |= 1 << 21;
16486
16487 v8_1_loop_reloc (TRUE);
16488 break;
16489
16490 case T_MNEM_wls:
16491 case T_MNEM_wlstp:
16492 v8_1_loop_reloc (FALSE);
16493 /* fall through. */
16494 case T_MNEM_dlstp:
16495 case T_MNEM_dls:
16496 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16497
16498 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16499 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16500 else if (inst.operands[1].reg == REG_PC)
16501 as_tsktsk (MVE_BAD_PC);
16502 if (inst.operands[1].reg == REG_SP)
16503 as_tsktsk (MVE_BAD_SP);
16504
16505 inst.instruction |= (inst.operands[1].reg << 16);
16506 break;
16507
16508 default:
16509 abort ();
16510 }
16511}
16512
16513
037e8744
JB
16514static void
16515do_vfp_nsyn_cmp (void)
16516{
9db2f6b4 16517 enum neon_shape rs;
1b883319
AV
16518 if (!inst.operands[0].isreg)
16519 {
16520 do_mve_vcmp ();
16521 return;
16522 }
16523 else
16524 {
16525 constraint (inst.operands[2].present, BAD_SYNTAX);
16526 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16527 BAD_FPU);
16528 }
16529
037e8744
JB
16530 if (inst.operands[1].isreg)
16531 {
9db2f6b4
RL
16532 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16533 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16534
9db2f6b4 16535 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16536 {
16537 NEON_ENCODE (SINGLE, inst);
16538 do_vfp_sp_monadic ();
16539 }
037e8744 16540 else
477330fc
RM
16541 {
16542 NEON_ENCODE (DOUBLE, inst);
16543 do_vfp_dp_rd_rm ();
16544 }
037e8744
JB
16545 }
16546 else
16547 {
9db2f6b4
RL
16548 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16549 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16550
16551 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16552 {
16553 case N_MNEM_vcmp:
16554 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16555 break;
16556 case N_MNEM_vcmpe:
16557 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16558 break;
16559 default:
16560 abort ();
16561 }
5f4273c7 16562
9db2f6b4 16563 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16564 {
16565 NEON_ENCODE (SINGLE, inst);
16566 do_vfp_sp_compare_z ();
16567 }
037e8744 16568 else
477330fc
RM
16569 {
16570 NEON_ENCODE (DOUBLE, inst);
16571 do_vfp_dp_rd ();
16572 }
037e8744
JB
16573 }
16574 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16575
16576 /* ARMv8.2 fp16 instruction. */
16577 if (rs == NS_HI || rs == NS_HH)
16578 do_scalar_fp16_v82_encode ();
037e8744
JB
16579}
16580
16581static void
16582nsyn_insert_sp (void)
16583{
16584 inst.operands[1] = inst.operands[0];
16585 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16586 inst.operands[0].reg = REG_SP;
037e8744
JB
16587 inst.operands[0].isreg = 1;
16588 inst.operands[0].writeback = 1;
16589 inst.operands[0].present = 1;
16590}
16591
037e8744
JB
16592/* Fix up Neon data-processing instructions, ORing in the correct bits for
16593 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16594
88714cb8
DG
16595static void
16596neon_dp_fixup (struct arm_it* insn)
037e8744 16597{
88714cb8
DG
16598 unsigned int i = insn->instruction;
16599 insn->is_neon = 1;
16600
037e8744
JB
16601 if (thumb_mode)
16602 {
16603 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16604 if (i & (1 << 24))
477330fc 16605 i |= 1 << 28;
5f4273c7 16606
037e8744 16607 i &= ~(1 << 24);
5f4273c7 16608
037e8744
JB
16609 i |= 0xef000000;
16610 }
16611 else
16612 i |= 0xf2000000;
5f4273c7 16613
88714cb8 16614 insn->instruction = i;
037e8744
JB
16615}
16616
5ee91343 16617static void
7df54120 16618mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16619{
16620 if (inst.operands[2].reg == REG_SP)
16621 as_tsktsk (MVE_BAD_SP);
16622 else if (inst.operands[2].reg == REG_PC)
16623 as_tsktsk (MVE_BAD_PC);
16624
16625 if (fp)
16626 {
16627 /* vadd. */
16628 if (((unsigned)inst.instruction) == 0xd00)
16629 inst.instruction = 0xee300f40;
16630 /* vsub. */
16631 else if (((unsigned)inst.instruction) == 0x200d00)
16632 inst.instruction = 0xee301f40;
a8465a06
AV
16633 /* vmul. */
16634 else if (((unsigned)inst.instruction) == 0x1000d10)
16635 inst.instruction = 0xee310e60;
5ee91343
AV
16636
16637 /* Setting size which is 1 for F16 and 0 for F32. */
16638 inst.instruction |= (size == 16) << 28;
16639 }
16640 else
16641 {
16642 /* vadd. */
16643 if (((unsigned)inst.instruction) == 0x800)
16644 inst.instruction = 0xee010f40;
16645 /* vsub. */
16646 else if (((unsigned)inst.instruction) == 0x1000800)
16647 inst.instruction = 0xee011f40;
7df54120
AV
16648 /* vhadd. */
16649 else if (((unsigned)inst.instruction) == 0)
16650 inst.instruction = 0xee000f40;
16651 /* vhsub. */
16652 else if (((unsigned)inst.instruction) == 0x200)
16653 inst.instruction = 0xee001f40;
a8465a06
AV
16654 /* vmla. */
16655 else if (((unsigned)inst.instruction) == 0x900)
16656 inst.instruction = 0xee010e40;
16657 /* vmul. */
16658 else if (((unsigned)inst.instruction) == 0x910)
16659 inst.instruction = 0xee011e60;
16660 /* vqadd. */
16661 else if (((unsigned)inst.instruction) == 0x10)
16662 inst.instruction = 0xee000f60;
16663 /* vqsub. */
16664 else if (((unsigned)inst.instruction) == 0x210)
16665 inst.instruction = 0xee001f60;
42b16635
AV
16666 /* vqrdmlah. */
16667 else if (((unsigned)inst.instruction) == 0x3000b10)
16668 inst.instruction = 0xee000e40;
16669 /* vqdmulh. */
16670 else if (((unsigned)inst.instruction) == 0x0000b00)
16671 inst.instruction = 0xee010e60;
16672 /* vqrdmulh. */
16673 else if (((unsigned)inst.instruction) == 0x1000b00)
16674 inst.instruction = 0xfe010e60;
7df54120
AV
16675
16676 /* Set U-bit. */
16677 inst.instruction |= U << 28;
16678
5ee91343
AV
16679 /* Setting bits for size. */
16680 inst.instruction |= neon_logbits (size) << 20;
16681 }
16682 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16683 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16684 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16685 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16686 inst.instruction |= inst.operands[2].reg;
16687 inst.is_neon = 1;
16688}
16689
a302e574
AV
16690static void
16691mve_encode_rqq (unsigned bit28, unsigned size)
16692{
16693 inst.instruction |= bit28 << 28;
16694 inst.instruction |= neon_logbits (size) << 20;
16695 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16696 inst.instruction |= inst.operands[0].reg << 12;
16697 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16698 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16699 inst.instruction |= LOW4 (inst.operands[2].reg);
16700 inst.is_neon = 1;
16701}
16702
886e1c73
AV
16703static void
16704mve_encode_qqq (int ubit, int size)
16705{
16706
16707 inst.instruction |= (ubit != 0) << 28;
16708 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16709 inst.instruction |= neon_logbits (size) << 20;
16710 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16711 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16712 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16713 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16714 inst.instruction |= LOW4 (inst.operands[2].reg);
16715
16716 inst.is_neon = 1;
16717}
16718
26c1e780
AV
16719static void
16720mve_encode_rq (unsigned bit28, unsigned size)
16721{
16722 inst.instruction |= bit28 << 28;
16723 inst.instruction |= neon_logbits (size) << 18;
16724 inst.instruction |= inst.operands[0].reg << 12;
16725 inst.instruction |= LOW4 (inst.operands[1].reg);
16726 inst.is_neon = 1;
16727}
886e1c73 16728
93925576
AV
16729static void
16730mve_encode_rrqq (unsigned U, unsigned size)
16731{
16732 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16733
16734 inst.instruction |= U << 28;
16735 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16736 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16737 inst.instruction |= (size == 32) << 16;
16738 inst.instruction |= inst.operands[0].reg << 12;
16739 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16740 inst.instruction |= inst.operands[3].reg;
16741 inst.is_neon = 1;
16742}
16743
aab2c27d
MM
16744/* Helper function for neon_three_same handling the operands. */
16745static void
16746neon_three_args (int isquad)
16747{
16748 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16749 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16750 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16751 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16752 inst.instruction |= LOW4 (inst.operands[2].reg);
16753 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16754 inst.instruction |= (isquad != 0) << 6;
16755 inst.is_neon = 1;
16756}
16757
037e8744
JB
16758/* Encode insns with bit pattern:
16759
16760 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16761 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16762
037e8744
JB
16763 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16764 different meaning for some instruction. */
16765
16766static void
16767neon_three_same (int isquad, int ubit, int size)
16768{
aab2c27d 16769 neon_three_args (isquad);
037e8744
JB
16770 inst.instruction |= (ubit != 0) << 24;
16771 if (size != -1)
16772 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16773
88714cb8 16774 neon_dp_fixup (&inst);
037e8744
JB
16775}
16776
16777/* Encode instructions of the form:
16778
16779 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16780 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16781
16782 Don't write size if SIZE == -1. */
16783
16784static void
16785neon_two_same (int qbit, int ubit, int size)
16786{
16787 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16788 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16789 inst.instruction |= LOW4 (inst.operands[1].reg);
16790 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16791 inst.instruction |= (qbit != 0) << 6;
16792 inst.instruction |= (ubit != 0) << 24;
16793
16794 if (size != -1)
16795 inst.instruction |= neon_logbits (size) << 18;
16796
88714cb8 16797 neon_dp_fixup (&inst);
5287ad62
JB
16798}
16799
7df54120
AV
16800enum vfp_or_neon_is_neon_bits
16801{
16802NEON_CHECK_CC = 1,
16803NEON_CHECK_ARCH = 2,
16804NEON_CHECK_ARCH8 = 4
16805};
16806
16807/* Call this function if an instruction which may have belonged to the VFP or
16808 Neon instruction sets, but turned out to be a Neon instruction (due to the
16809 operand types involved, etc.). We have to check and/or fix-up a couple of
16810 things:
16811
16812 - Make sure the user hasn't attempted to make a Neon instruction
16813 conditional.
16814 - Alter the value in the condition code field if necessary.
16815 - Make sure that the arch supports Neon instructions.
16816
16817 Which of these operations take place depends on bits from enum
16818 vfp_or_neon_is_neon_bits.
16819
16820 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16821 current instruction's condition is COND_ALWAYS, the condition field is
16822 changed to inst.uncond_value. This is necessary because instructions shared
16823 between VFP and Neon may be conditional for the VFP variants only, and the
16824 unconditional Neon version must have, e.g., 0xF in the condition field. */
16825
16826static int
16827vfp_or_neon_is_neon (unsigned check)
16828{
16829/* Conditions are always legal in Thumb mode (IT blocks). */
16830if (!thumb_mode && (check & NEON_CHECK_CC))
16831 {
16832 if (inst.cond != COND_ALWAYS)
16833 {
16834 first_error (_(BAD_COND));
16835 return FAIL;
16836 }
7af67752 16837 if (inst.uncond_value != -1u)
7df54120
AV
16838 inst.instruction |= inst.uncond_value << 28;
16839 }
16840
16841
16842 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16843 || ((check & NEON_CHECK_ARCH8)
16844 && !mark_feature_used (&fpu_neon_ext_armv8)))
16845 {
16846 first_error (_(BAD_FPU));
16847 return FAIL;
16848 }
16849
16850return SUCCESS;
16851}
16852
64c350f2
AV
16853
16854/* Return TRUE if the SIMD instruction is available for the current
16855 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16856 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16857 vfp_or_neon_is_neon for the NEON specific checks. */
16858
16859static bfd_boolean
7df54120
AV
16860check_simd_pred_availability (int fp, unsigned check)
16861{
16862if (inst.cond > COND_ALWAYS)
16863 {
16864 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16865 {
16866 inst.error = BAD_FPU;
64c350f2 16867 return FALSE;
7df54120
AV
16868 }
16869 inst.pred_insn_type = INSIDE_VPT_INSN;
16870 }
16871else if (inst.cond < COND_ALWAYS)
16872 {
16873 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16874 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16875 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16876 return FALSE;
7df54120
AV
16877 }
16878else
16879 {
16880 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16881 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16882 return FALSE;
7df54120
AV
16883
16884 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16885 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16886 }
64c350f2 16887return TRUE;
7df54120
AV
16888}
16889
5287ad62
JB
16890/* Neon instruction encoders, in approximate order of appearance. */
16891
16892static void
16893do_neon_dyadic_i_su (void)
16894{
64c350f2 16895 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16896 return;
16897
16898 enum neon_shape rs;
16899 struct neon_type_el et;
16900 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16901 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16902 else
16903 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16904
16905 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16906
16907
16908 if (rs != NS_QQR)
16909 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16910 else
16911 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16912}
16913
16914static void
16915do_neon_dyadic_i64_su (void)
16916{
64c350f2 16917 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16918 return;
16919 enum neon_shape rs;
16920 struct neon_type_el et;
16921 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16922 {
16923 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16924 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16925 }
16926 else
16927 {
16928 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16929 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16930 }
16931 if (rs == NS_QQR)
16932 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16933 else
16934 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16935}
16936
16937static void
16938neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16939 unsigned immbits)
5287ad62
JB
16940{
16941 unsigned size = et.size >> 3;
16942 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16943 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16944 inst.instruction |= LOW4 (inst.operands[1].reg);
16945 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16946 inst.instruction |= (isquad != 0) << 6;
16947 inst.instruction |= immbits << 16;
16948 inst.instruction |= (size >> 3) << 7;
16949 inst.instruction |= (size & 0x7) << 19;
16950 if (write_ubit)
16951 inst.instruction |= (uval != 0) << 24;
16952
88714cb8 16953 neon_dp_fixup (&inst);
5287ad62
JB
16954}
16955
16956static void
5150f0d8 16957do_neon_shl (void)
5287ad62 16958{
64c350f2 16959 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16960 return;
16961
5287ad62
JB
16962 if (!inst.operands[2].isreg)
16963 {
5150f0d8
AV
16964 enum neon_shape rs;
16965 struct neon_type_el et;
16966 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16967 {
16968 rs = neon_select_shape (NS_QQI, NS_NULL);
16969 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16970 }
16971 else
16972 {
16973 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16974 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16975 }
cb3b1e65
JB
16976 int imm = inst.operands[2].imm;
16977
16978 constraint (imm < 0 || (unsigned)imm >= et.size,
16979 _("immediate out of range for shift"));
88714cb8 16980 NEON_ENCODE (IMMED, inst);
cb3b1e65 16981 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16982 }
16983 else
16984 {
5150f0d8
AV
16985 enum neon_shape rs;
16986 struct neon_type_el et;
16987 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16988 {
16989 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16990 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16991 }
16992 else
16993 {
16994 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16995 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16996 }
16997
16998
16999 if (rs == NS_QQR)
17000 {
17001 constraint (inst.operands[0].reg != inst.operands[1].reg,
17002 _("invalid instruction shape"));
17003 if (inst.operands[2].reg == REG_SP)
17004 as_tsktsk (MVE_BAD_SP);
17005 else if (inst.operands[2].reg == REG_PC)
17006 as_tsktsk (MVE_BAD_PC);
17007
17008 inst.instruction = 0xee311e60;
17009 inst.instruction |= (et.type == NT_unsigned) << 28;
17010 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17011 inst.instruction |= neon_logbits (et.size) << 18;
17012 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17013 inst.instruction |= inst.operands[2].reg;
17014 inst.is_neon = 1;
17015 }
17016 else
17017 {
17018 unsigned int tmp;
17019
17020 /* VSHL/VQSHL 3-register variants have syntax such as:
17021 vshl.xx Dd, Dm, Dn
17022 whereas other 3-register operations encoded by neon_three_same have
17023 syntax like:
17024 vadd.xx Dd, Dn, Dm
17025 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17026 operands[2].reg here. */
17027 tmp = inst.operands[2].reg;
17028 inst.operands[2].reg = inst.operands[1].reg;
17029 inst.operands[1].reg = tmp;
17030 NEON_ENCODE (INTEGER, inst);
17031 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17032 }
5287ad62
JB
17033 }
17034}
17035
17036static void
5150f0d8 17037do_neon_qshl (void)
5287ad62 17038{
64c350f2 17039 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
17040 return;
17041
5287ad62
JB
17042 if (!inst.operands[2].isreg)
17043 {
5150f0d8
AV
17044 enum neon_shape rs;
17045 struct neon_type_el et;
17046 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17047 {
17048 rs = neon_select_shape (NS_QQI, NS_NULL);
17049 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17050 }
17051 else
17052 {
17053 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17054 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17055 }
cb3b1e65 17056 int imm = inst.operands[2].imm;
627907b7 17057
cb3b1e65
JB
17058 constraint (imm < 0 || (unsigned)imm >= et.size,
17059 _("immediate out of range for shift"));
88714cb8 17060 NEON_ENCODE (IMMED, inst);
cb3b1e65 17061 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
17062 }
17063 else
17064 {
5150f0d8
AV
17065 enum neon_shape rs;
17066 struct neon_type_el et;
627907b7 17067
5150f0d8
AV
17068 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17069 {
17070 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17071 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17072 }
17073 else
17074 {
17075 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17076 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17077 }
17078
17079 if (rs == NS_QQR)
17080 {
17081 constraint (inst.operands[0].reg != inst.operands[1].reg,
17082 _("invalid instruction shape"));
17083 if (inst.operands[2].reg == REG_SP)
17084 as_tsktsk (MVE_BAD_SP);
17085 else if (inst.operands[2].reg == REG_PC)
17086 as_tsktsk (MVE_BAD_PC);
17087
17088 inst.instruction = 0xee311ee0;
17089 inst.instruction |= (et.type == NT_unsigned) << 28;
17090 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17091 inst.instruction |= neon_logbits (et.size) << 18;
17092 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17093 inst.instruction |= inst.operands[2].reg;
17094 inst.is_neon = 1;
17095 }
17096 else
17097 {
17098 unsigned int tmp;
17099
17100 /* See note in do_neon_shl. */
17101 tmp = inst.operands[2].reg;
17102 inst.operands[2].reg = inst.operands[1].reg;
17103 inst.operands[1].reg = tmp;
17104 NEON_ENCODE (INTEGER, inst);
17105 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17106 }
5287ad62
JB
17107 }
17108}
17109
627907b7
JB
17110static void
17111do_neon_rshl (void)
17112{
64c350f2 17113 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
17114 return;
17115
17116 enum neon_shape rs;
17117 struct neon_type_el et;
17118 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17119 {
17120 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17121 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17122 }
17123 else
17124 {
17125 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17126 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17127 }
17128
627907b7
JB
17129 unsigned int tmp;
17130
1be7aba3
AV
17131 if (rs == NS_QQR)
17132 {
17133 if (inst.operands[2].reg == REG_PC)
17134 as_tsktsk (MVE_BAD_PC);
17135 else if (inst.operands[2].reg == REG_SP)
17136 as_tsktsk (MVE_BAD_SP);
17137
17138 constraint (inst.operands[0].reg != inst.operands[1].reg,
17139 _("invalid instruction shape"));
17140
17141 if (inst.instruction == 0x0000510)
17142 /* We are dealing with vqrshl. */
17143 inst.instruction = 0xee331ee0;
17144 else
17145 /* We are dealing with vrshl. */
17146 inst.instruction = 0xee331e60;
17147
17148 inst.instruction |= (et.type == NT_unsigned) << 28;
17149 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17150 inst.instruction |= neon_logbits (et.size) << 18;
17151 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17152 inst.instruction |= inst.operands[2].reg;
17153 inst.is_neon = 1;
17154 }
17155 else
17156 {
17157 tmp = inst.operands[2].reg;
17158 inst.operands[2].reg = inst.operands[1].reg;
17159 inst.operands[1].reg = tmp;
17160 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17161 }
627907b7
JB
17162}
17163
5287ad62
JB
17164static int
17165neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17166{
036dc3f7
PB
17167 /* Handle .I8 pseudo-instructions. */
17168 if (size == 8)
5287ad62 17169 {
5287ad62 17170 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
17171 FIXME is this the intended semantics? There doesn't seem much point in
17172 accepting .I8 if so. */
5287ad62
JB
17173 immediate |= immediate << 8;
17174 size = 16;
036dc3f7
PB
17175 }
17176
17177 if (size >= 32)
17178 {
17179 if (immediate == (immediate & 0x000000ff))
17180 {
17181 *immbits = immediate;
17182 return 0x1;
17183 }
17184 else if (immediate == (immediate & 0x0000ff00))
17185 {
17186 *immbits = immediate >> 8;
17187 return 0x3;
17188 }
17189 else if (immediate == (immediate & 0x00ff0000))
17190 {
17191 *immbits = immediate >> 16;
17192 return 0x5;
17193 }
17194 else if (immediate == (immediate & 0xff000000))
17195 {
17196 *immbits = immediate >> 24;
17197 return 0x7;
17198 }
17199 if ((immediate & 0xffff) != (immediate >> 16))
17200 goto bad_immediate;
17201 immediate &= 0xffff;
5287ad62
JB
17202 }
17203
17204 if (immediate == (immediate & 0x000000ff))
17205 {
17206 *immbits = immediate;
036dc3f7 17207 return 0x9;
5287ad62
JB
17208 }
17209 else if (immediate == (immediate & 0x0000ff00))
17210 {
17211 *immbits = immediate >> 8;
036dc3f7 17212 return 0xb;
5287ad62
JB
17213 }
17214
17215 bad_immediate:
dcbf9037 17216 first_error (_("immediate value out of range"));
5287ad62
JB
17217 return FAIL;
17218}
17219
5287ad62
JB
17220static void
17221do_neon_logic (void)
17222{
17223 if (inst.operands[2].present && inst.operands[2].isreg)
17224 {
037e8744 17225 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17226 if (rs == NS_QQQ
64c350f2
AV
17227 && !check_simd_pred_availability (FALSE,
17228 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17229 return;
17230 else if (rs != NS_QQQ
17231 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17232 first_error (BAD_FPU);
17233
5287ad62
JB
17234 neon_check_type (3, rs, N_IGNORE_TYPE);
17235 /* U bit and size field were set as part of the bitmask. */
88714cb8 17236 NEON_ENCODE (INTEGER, inst);
037e8744 17237 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17238 }
17239 else
17240 {
4316f0d2
DG
17241 const int three_ops_form = (inst.operands[2].present
17242 && !inst.operands[2].isreg);
17243 const int immoperand = (three_ops_form ? 2 : 1);
17244 enum neon_shape rs = (three_ops_form
17245 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17246 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17247 /* Because neon_select_shape makes the second operand a copy of the first
17248 if the second operand is not present. */
17249 if (rs == NS_QQI
64c350f2
AV
17250 && !check_simd_pred_availability (FALSE,
17251 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17252 return;
17253 else if (rs != NS_QQI
17254 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17255 first_error (BAD_FPU);
17256
17257 struct neon_type_el et;
17258 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17259 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17260 else
17261 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17262 | N_KEY, N_EQK);
17263
17264 if (et.type == NT_invtype)
17265 return;
21d799b5 17266 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17267 unsigned immbits;
17268 int cmode;
5f4273c7 17269
5f4273c7 17270
4316f0d2
DG
17271 if (three_ops_form)
17272 constraint (inst.operands[0].reg != inst.operands[1].reg,
17273 _("first and second operands shall be the same register"));
17274
88714cb8 17275 NEON_ENCODE (IMMED, inst);
5287ad62 17276
4316f0d2 17277 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17278 if (et.size == 64)
17279 {
17280 /* .i64 is a pseudo-op, so the immediate must be a repeating
17281 pattern. */
4316f0d2
DG
17282 if (immbits != (inst.operands[immoperand].regisimm ?
17283 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17284 {
17285 /* Set immbits to an invalid constant. */
17286 immbits = 0xdeadbeef;
17287 }
17288 }
17289
5287ad62 17290 switch (opcode)
477330fc
RM
17291 {
17292 case N_MNEM_vbic:
17293 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17294 break;
17295
17296 case N_MNEM_vorr:
17297 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17298 break;
17299
17300 case N_MNEM_vand:
17301 /* Pseudo-instruction for VBIC. */
17302 neon_invert_size (&immbits, 0, et.size);
17303 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17304 break;
17305
17306 case N_MNEM_vorn:
17307 /* Pseudo-instruction for VORR. */
17308 neon_invert_size (&immbits, 0, et.size);
17309 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17310 break;
17311
17312 default:
17313 abort ();
17314 }
5287ad62
JB
17315
17316 if (cmode == FAIL)
477330fc 17317 return;
5287ad62 17318
037e8744 17319 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17320 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17321 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17322 inst.instruction |= cmode << 8;
17323 neon_write_immbits (immbits);
5f4273c7 17324
88714cb8 17325 neon_dp_fixup (&inst);
5287ad62
JB
17326 }
17327}
17328
17329static void
17330do_neon_bitfield (void)
17331{
037e8744 17332 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17333 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17334 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17335}
17336
17337static void
dcbf9037 17338neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17339 unsigned destbits)
5287ad62 17340{
5ee91343 17341 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17342 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17343 types | N_KEY);
5287ad62
JB
17344 if (et.type == NT_float)
17345 {
88714cb8 17346 NEON_ENCODE (FLOAT, inst);
5ee91343 17347 if (rs == NS_QQR)
7df54120 17348 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17349 else
17350 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17351 }
17352 else
17353 {
88714cb8 17354 NEON_ENCODE (INTEGER, inst);
5ee91343 17355 if (rs == NS_QQR)
a8465a06 17356 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17357 else
17358 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17359 }
17360}
17361
5287ad62
JB
17362
17363static void
17364do_neon_dyadic_if_su_d (void)
17365{
17366 /* This version only allow D registers, but that constraint is enforced during
17367 operand parsing so we don't need to do anything extra here. */
dcbf9037 17368 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17369}
17370
5287ad62
JB
17371static void
17372do_neon_dyadic_if_i_d (void)
17373{
428e3f1f
PB
17374 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17375 affected if we specify unsigned args. */
17376 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17377}
17378
f5f10c66
AV
17379static void
17380do_mve_vstr_vldr_QI (int size, int elsize, int load)
17381{
17382 constraint (size < 32, BAD_ADDR_MODE);
17383 constraint (size != elsize, BAD_EL_TYPE);
17384 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17385 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17386 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17387 _("destination register and offset register may not be the"
17388 " same"));
17389
17390 int imm = inst.relocs[0].exp.X_add_number;
17391 int add = 1;
17392 if (imm < 0)
17393 {
17394 add = 0;
17395 imm = -imm;
17396 }
17397 constraint ((imm % (size / 8) != 0)
17398 || imm > (0x7f << neon_logbits (size)),
17399 (size == 32) ? _("immediate must be a multiple of 4 in the"
17400 " range of +/-[0,508]")
17401 : _("immediate must be a multiple of 8 in the"
17402 " range of +/-[0,1016]"));
17403 inst.instruction |= 0x11 << 24;
17404 inst.instruction |= add << 23;
17405 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17406 inst.instruction |= inst.operands[1].writeback << 21;
17407 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17408 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17409 inst.instruction |= 1 << 12;
17410 inst.instruction |= (size == 64) << 8;
17411 inst.instruction &= 0xffffff00;
17412 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17413 inst.instruction |= imm >> neon_logbits (size);
17414}
17415
17416static void
17417do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17418{
17419 unsigned os = inst.operands[1].imm >> 5;
e449ea97 17420 unsigned type = inst.vectype.el[0].type;
f5f10c66
AV
17421 constraint (os != 0 && size == 8,
17422 _("can not shift offsets when accessing less than half-word"));
17423 constraint (os && os != neon_logbits (size),
17424 _("shift immediate must be 1, 2 or 3 for half-word, word"
17425 " or double-word accesses respectively"));
17426 if (inst.operands[1].reg == REG_PC)
17427 as_tsktsk (MVE_BAD_PC);
17428
17429 switch (size)
17430 {
17431 case 8:
17432 constraint (elsize >= 64, BAD_EL_TYPE);
17433 break;
17434 case 16:
17435 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17436 break;
17437 case 32:
17438 case 64:
17439 constraint (elsize != size, BAD_EL_TYPE);
17440 break;
17441 default:
17442 break;
17443 }
17444 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17445 BAD_ADDR_MODE);
17446 if (load)
17447 {
17448 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17449 _("destination register and offset register may not be"
17450 " the same"));
e449ea97
SP
17451 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17452 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
f5f10c66 17453 BAD_EL_TYPE);
e449ea97 17454 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
f5f10c66
AV
17455 }
17456 else
17457 {
e449ea97 17458 constraint (type != NT_untyped, BAD_EL_TYPE);
f5f10c66
AV
17459 }
17460
17461 inst.instruction |= 1 << 23;
17462 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17463 inst.instruction |= inst.operands[1].reg << 16;
17464 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17465 inst.instruction |= neon_logbits (elsize) << 7;
17466 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17467 inst.instruction |= LOW4 (inst.operands[1].imm);
17468 inst.instruction |= !!os;
17469}
17470
17471static void
17472do_mve_vstr_vldr_RI (int size, int elsize, int load)
17473{
17474 enum neon_el_type type = inst.vectype.el[0].type;
17475
17476 constraint (size >= 64, BAD_ADDR_MODE);
17477 switch (size)
17478 {
17479 case 16:
17480 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17481 break;
17482 case 32:
17483 constraint (elsize != size, BAD_EL_TYPE);
17484 break;
17485 default:
17486 break;
17487 }
17488 if (load)
17489 {
17490 constraint (elsize != size && type != NT_unsigned
17491 && type != NT_signed, BAD_EL_TYPE);
17492 }
17493 else
17494 {
17495 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17496 }
17497
17498 int imm = inst.relocs[0].exp.X_add_number;
17499 int add = 1;
17500 if (imm < 0)
17501 {
17502 add = 0;
17503 imm = -imm;
17504 }
17505
17506 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17507 {
17508 switch (size)
17509 {
17510 case 8:
17511 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17512 break;
17513 case 16:
17514 constraint (1, _("immediate must be a multiple of 2 in the"
17515 " range of +/-[0,254]"));
17516 break;
17517 case 32:
17518 constraint (1, _("immediate must be a multiple of 4 in the"
17519 " range of +/-[0,508]"));
17520 break;
17521 }
17522 }
17523
17524 if (size != elsize)
17525 {
17526 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17527 constraint (inst.operands[0].reg > 14,
17528 _("MVE vector register in the range [Q0..Q7] expected"));
17529 inst.instruction |= (load && type == NT_unsigned) << 28;
17530 inst.instruction |= (size == 16) << 19;
17531 inst.instruction |= neon_logbits (elsize) << 7;
17532 }
17533 else
17534 {
17535 if (inst.operands[1].reg == REG_PC)
17536 as_tsktsk (MVE_BAD_PC);
17537 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17538 as_tsktsk (MVE_BAD_SP);
17539 inst.instruction |= 1 << 12;
17540 inst.instruction |= neon_logbits (size) << 7;
17541 }
17542 inst.instruction |= inst.operands[1].preind << 24;
17543 inst.instruction |= add << 23;
17544 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17545 inst.instruction |= inst.operands[1].writeback << 21;
17546 inst.instruction |= inst.operands[1].reg << 16;
17547 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17548 inst.instruction &= 0xffffff80;
17549 inst.instruction |= imm >> neon_logbits (size);
17550
17551}
17552
17553static void
17554do_mve_vstr_vldr (void)
17555{
17556 unsigned size;
17557 int load = 0;
17558
17559 if (inst.cond > COND_ALWAYS)
17560 inst.pred_insn_type = INSIDE_VPT_INSN;
17561 else
17562 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17563
17564 switch (inst.instruction)
17565 {
17566 default:
17567 gas_assert (0);
17568 break;
17569 case M_MNEM_vldrb:
17570 load = 1;
17571 /* fall through. */
17572 case M_MNEM_vstrb:
17573 size = 8;
17574 break;
17575 case M_MNEM_vldrh:
17576 load = 1;
17577 /* fall through. */
17578 case M_MNEM_vstrh:
17579 size = 16;
17580 break;
17581 case M_MNEM_vldrw:
17582 load = 1;
17583 /* fall through. */
17584 case M_MNEM_vstrw:
17585 size = 32;
17586 break;
17587 case M_MNEM_vldrd:
17588 load = 1;
17589 /* fall through. */
17590 case M_MNEM_vstrd:
17591 size = 64;
17592 break;
17593 }
17594 unsigned elsize = inst.vectype.el[0].size;
17595
17596 if (inst.operands[1].isquad)
17597 {
17598 /* We are dealing with [Q, imm]{!} cases. */
17599 do_mve_vstr_vldr_QI (size, elsize, load);
17600 }
17601 else
17602 {
17603 if (inst.operands[1].immisreg == 2)
17604 {
17605 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17606 do_mve_vstr_vldr_RQ (size, elsize, load);
17607 }
17608 else if (!inst.operands[1].immisreg)
17609 {
17610 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17611 do_mve_vstr_vldr_RI (size, elsize, load);
17612 }
17613 else
17614 constraint (1, BAD_ADDR_MODE);
17615 }
17616
17617 inst.is_neon = 1;
17618}
17619
35c228db
AV
17620static void
17621do_mve_vst_vld (void)
17622{
17623 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17624 return;
17625
17626 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17627 || inst.relocs[0].exp.X_add_number != 0
17628 || inst.operands[1].immisreg != 0,
17629 BAD_ADDR_MODE);
17630 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17631 if (inst.operands[1].reg == REG_PC)
17632 as_tsktsk (MVE_BAD_PC);
17633 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17634 as_tsktsk (MVE_BAD_SP);
17635
17636
17637 /* These instructions are one of the "exceptions" mentioned in
17638 handle_pred_state. They are MVE instructions that are not VPT compatible
17639 and do not accept a VPT code, thus appending such a code is a syntax
17640 error. */
17641 if (inst.cond > COND_ALWAYS)
17642 first_error (BAD_SYNTAX);
17643 /* If we append a scalar condition code we can set this to
17644 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17645 else if (inst.cond < COND_ALWAYS)
17646 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17647 else
17648 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17649
17650 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17651 inst.instruction |= inst.operands[1].writeback << 21;
17652 inst.instruction |= inst.operands[1].reg << 16;
17653 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17654 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17655 inst.is_neon = 1;
17656}
17657
26c1e780
AV
17658static void
17659do_mve_vaddlv (void)
17660{
17661 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17662 struct neon_type_el et
17663 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17664
17665 if (et.type == NT_invtype)
17666 first_error (BAD_EL_TYPE);
17667
17668 if (inst.cond > COND_ALWAYS)
17669 inst.pred_insn_type = INSIDE_VPT_INSN;
17670 else
17671 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17672
17673 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17674
17675 inst.instruction |= (et.type == NT_unsigned) << 28;
17676 inst.instruction |= inst.operands[1].reg << 19;
17677 inst.instruction |= inst.operands[0].reg << 12;
17678 inst.instruction |= inst.operands[2].reg;
17679 inst.is_neon = 1;
17680}
17681
5287ad62 17682static void
5ee91343 17683do_neon_dyadic_if_su (void)
5287ad62 17684{
5ee91343
AV
17685 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17686 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17687 N_SUF_32 | N_KEY);
17688
935295b5
AV
17689 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17690 || inst.instruction == ((unsigned) N_MNEM_vmin))
17691 && et.type == NT_float
17692 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17693
64c350f2
AV
17694 if (!check_simd_pred_availability (et.type == NT_float,
17695 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17696 return;
17697
5ee91343
AV
17698 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17699}
17700
17701static void
17702do_neon_addsub_if_i (void)
17703{
17704 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17705 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17706 return;
17707
5ee91343
AV
17708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17709 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17710 N_EQK, N_IF_32 | N_I64 | N_KEY);
17711
17712 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17713 /* If we are parsing Q registers and the element types match MVE, which NEON
17714 also supports, then we must check whether this is an instruction that can
17715 be used by both MVE/NEON. This distinction can be made based on whether
17716 they are predicated or not. */
17717 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17718 {
64c350f2
AV
17719 if (!check_simd_pred_availability (et.type == NT_float,
17720 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17721 return;
17722 }
17723 else
17724 {
17725 /* If they are either in a D register or are using an unsupported. */
17726 if (rs != NS_QQR
17727 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17728 return;
17729 }
17730
5287ad62
JB
17731 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17732 affected if we specify unsigned args. */
dcbf9037 17733 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17734}
17735
17736/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17737 result to be:
17738 V<op> A,B (A is operand 0, B is operand 2)
17739 to mean:
17740 V<op> A,B,A
17741 not:
17742 V<op> A,B,B
17743 so handle that case specially. */
17744
17745static void
17746neon_exchange_operands (void)
17747{
5287ad62
JB
17748 if (inst.operands[1].present)
17749 {
e1fa0163
NC
17750 void *scratch = xmalloc (sizeof (inst.operands[0]));
17751
5287ad62
JB
17752 /* Swap operands[1] and operands[2]. */
17753 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17754 inst.operands[1] = inst.operands[2];
17755 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17756 free (scratch);
5287ad62
JB
17757 }
17758 else
17759 {
17760 inst.operands[1] = inst.operands[2];
17761 inst.operands[2] = inst.operands[0];
17762 }
17763}
17764
17765static void
17766neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17767{
17768 if (inst.operands[2].isreg)
17769 {
17770 if (invert)
477330fc 17771 neon_exchange_operands ();
dcbf9037 17772 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17773 }
17774 else
17775 {
037e8744 17776 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17777 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17778 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17779
88714cb8 17780 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17781 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17782 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17783 inst.instruction |= LOW4 (inst.operands[1].reg);
17784 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17785 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17786 inst.instruction |= (et.type == NT_float) << 10;
17787 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17788
88714cb8 17789 neon_dp_fixup (&inst);
5287ad62
JB
17790 }
17791}
17792
17793static void
17794do_neon_cmp (void)
17795{
cc933301 17796 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17797}
17798
17799static void
17800do_neon_cmp_inv (void)
17801{
cc933301 17802 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17803}
17804
17805static void
17806do_neon_ceq (void)
17807{
17808 neon_compare (N_IF_32, N_IF_32, FALSE);
17809}
17810
17811/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17812 scalars, which are encoded in 5 bits, M : Rm.
17813 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17814 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17815 index in M.
17816
17817 Dot Product instructions are similar to multiply instructions except elsize
17818 should always be 32.
17819
17820 This function translates SCALAR, which is GAS's internal encoding of indexed
17821 scalar register, to raw encoding. There is also register and index range
17822 check based on ELSIZE. */
5287ad62
JB
17823
17824static unsigned
17825neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17826{
dcbf9037
JB
17827 unsigned regno = NEON_SCALAR_REG (scalar);
17828 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17829
17830 switch (elsize)
17831 {
17832 case 16:
17833 if (regno > 7 || elno > 3)
477330fc 17834 goto bad_scalar;
5287ad62 17835 return regno | (elno << 3);
5f4273c7 17836
5287ad62
JB
17837 case 32:
17838 if (regno > 15 || elno > 1)
477330fc 17839 goto bad_scalar;
5287ad62
JB
17840 return regno | (elno << 4);
17841
17842 default:
17843 bad_scalar:
dcbf9037 17844 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17845 }
17846
17847 return 0;
17848}
17849
17850/* Encode multiply / multiply-accumulate scalar instructions. */
17851
17852static void
17853neon_mul_mac (struct neon_type_el et, int ubit)
17854{
dcbf9037
JB
17855 unsigned scalar;
17856
17857 /* Give a more helpful error message if we have an invalid type. */
17858 if (et.type == NT_invtype)
17859 return;
5f4273c7 17860
dcbf9037 17861 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17862 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17863 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17864 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17865 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17866 inst.instruction |= LOW4 (scalar);
17867 inst.instruction |= HI1 (scalar) << 5;
17868 inst.instruction |= (et.type == NT_float) << 8;
17869 inst.instruction |= neon_logbits (et.size) << 20;
17870 inst.instruction |= (ubit != 0) << 24;
17871
88714cb8 17872 neon_dp_fixup (&inst);
5287ad62
JB
17873}
17874
17875static void
17876do_neon_mac_maybe_scalar (void)
17877{
037e8744
JB
17878 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17879 return;
17880
64c350f2 17881 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17882 return;
17883
5287ad62
JB
17884 if (inst.operands[2].isscalar)
17885 {
a8465a06 17886 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17887 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17888 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17889 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17890 NEON_ENCODE (SCALAR, inst);
037e8744 17891 neon_mul_mac (et, neon_quad (rs));
5287ad62 17892 }
a8465a06
AV
17893 else if (!inst.operands[2].isvec)
17894 {
17895 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17896
17897 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17898 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17899
17900 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17901 }
5287ad62 17902 else
428e3f1f 17903 {
a8465a06 17904 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17905 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17906 affected if we specify unsigned args. */
17907 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17908 }
5287ad62
JB
17909}
17910
aab2c27d
MM
17911static void
17912do_bfloat_vfma (void)
17913{
17914 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17915 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17916 enum neon_shape rs;
17917 int t_bit = 0;
17918
17919 if (inst.instruction != B_MNEM_vfmab)
17920 {
17921 t_bit = 1;
17922 inst.instruction = B_MNEM_vfmat;
17923 }
17924
17925 if (inst.operands[2].isscalar)
17926 {
17927 rs = neon_select_shape (NS_QQS, NS_NULL);
17928 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17929
17930 inst.instruction |= (1 << 25);
17931 int index = inst.operands[2].reg & 0xf;
17932 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17933 inst.operands[2].reg >>= 4;
17934 constraint (!(inst.operands[2].reg < 8),
17935 _("indexed register must be less than 8"));
17936 neon_three_args (t_bit);
17937 inst.instruction |= ((index & 1) << 3);
17938 inst.instruction |= ((index & 2) << 4);
17939 }
17940 else
17941 {
17942 rs = neon_select_shape (NS_QQQ, NS_NULL);
17943 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17944 neon_three_args (t_bit);
17945 }
17946
17947}
17948
62f3b8c8
PB
17949static void
17950do_neon_fmac (void)
17951{
d58196e0
AV
17952 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17953 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17954 return;
17955
64c350f2 17956 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17957 return;
17958
d58196e0
AV
17959 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17960 {
17961 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17962 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17963 N_EQK);
17964
17965 if (rs == NS_QQR)
17966 {
aab2c27d 17967
d58196e0
AV
17968 if (inst.operands[2].reg == REG_SP)
17969 as_tsktsk (MVE_BAD_SP);
17970 else if (inst.operands[2].reg == REG_PC)
17971 as_tsktsk (MVE_BAD_PC);
17972
17973 inst.instruction = 0xee310e40;
17974 inst.instruction |= (et.size == 16) << 28;
17975 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17976 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17977 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17978 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17979 inst.instruction |= inst.operands[2].reg;
17980 inst.is_neon = 1;
17981 return;
17982 }
17983 }
17984 else
17985 {
17986 constraint (!inst.operands[2].isvec, BAD_FPU);
17987 }
17988
62f3b8c8
PB
17989 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17990}
17991
aab2c27d
MM
17992static void
17993do_mve_vfma (void)
17994{
17995 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17996 inst.cond == COND_ALWAYS)
17997 {
17998 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17999 inst.instruction = N_MNEM_vfma;
18000 inst.pred_insn_type = INSIDE_VPT_INSN;
18001 inst.cond = 0xf;
18002 return do_neon_fmac();
18003 }
18004 else
18005 {
18006 do_bfloat_vfma();
18007 }
18008}
18009
5287ad62
JB
18010static void
18011do_neon_tst (void)
18012{
037e8744 18013 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
18014 struct neon_type_el et = neon_check_type (3, rs,
18015 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 18016 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18017}
18018
18019/* VMUL with 3 registers allows the P8 type. The scalar version supports the
18020 same types as the MAC equivalents. The polynomial type for this instruction
18021 is encoded the same as the integer type. */
18022
18023static void
18024do_neon_mul (void)
18025{
037e8744
JB
18026 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18027 return;
18028
64c350f2 18029 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
18030 return;
18031
5287ad62 18032 if (inst.operands[2].isscalar)
a8465a06
AV
18033 {
18034 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18035 do_neon_mac_maybe_scalar ();
18036 }
5287ad62 18037 else
a8465a06
AV
18038 {
18039 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18040 {
18041 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18042 struct neon_type_el et
18043 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18044 if (et.type == NT_float)
18045 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18046 BAD_FPU);
18047
18048 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18049 }
18050 else
18051 {
18052 constraint (!inst.operands[2].isvec, BAD_FPU);
18053 neon_dyadic_misc (NT_poly,
18054 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18055 }
18056 }
5287ad62
JB
18057}
18058
18059static void
18060do_neon_qdmulh (void)
18061{
64c350f2 18062 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18063 return;
18064
5287ad62
JB
18065 if (inst.operands[2].isscalar)
18066 {
42b16635 18067 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 18068 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 18069 struct neon_type_el et = neon_check_type (3, rs,
477330fc 18070 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 18071 NEON_ENCODE (SCALAR, inst);
037e8744 18072 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
18073 }
18074 else
18075 {
42b16635
AV
18076 enum neon_shape rs;
18077 struct neon_type_el et;
18078 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18079 {
18080 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18081 et = neon_check_type (3, rs,
18082 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18083 }
18084 else
18085 {
18086 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18087 et = neon_check_type (3, rs,
18088 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18089 }
18090
88714cb8 18091 NEON_ENCODE (INTEGER, inst);
42b16635
AV
18092 if (rs == NS_QQR)
18093 mve_encode_qqr (et.size, 0, 0);
18094 else
18095 /* The U bit (rounding) comes from bit mask. */
18096 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18097 }
18098}
18099
26c1e780
AV
18100static void
18101do_mve_vaddv (void)
18102{
18103 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18104 struct neon_type_el et
18105 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18106
18107 if (et.type == NT_invtype)
18108 first_error (BAD_EL_TYPE);
18109
18110 if (inst.cond > COND_ALWAYS)
18111 inst.pred_insn_type = INSIDE_VPT_INSN;
18112 else
18113 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18114
18115 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18116
18117 mve_encode_rq (et.type == NT_unsigned, et.size);
18118}
18119
7df54120
AV
18120static void
18121do_mve_vhcadd (void)
18122{
18123 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18124 struct neon_type_el et
18125 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18126
18127 if (inst.cond > COND_ALWAYS)
18128 inst.pred_insn_type = INSIDE_VPT_INSN;
18129 else
18130 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18131
18132 unsigned rot = inst.relocs[0].exp.X_add_number;
18133 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18134
18135 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18136 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18137 "operand makes instruction UNPREDICTABLE"));
18138
18139 mve_encode_qqq (0, et.size);
18140 inst.instruction |= (rot == 270) << 12;
18141 inst.is_neon = 1;
18142}
18143
35d1cfc2
AV
18144static void
18145do_mve_vqdmull (void)
18146{
18147 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18148 struct neon_type_el et
18149 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18150
18151 if (et.size == 32
18152 && (inst.operands[0].reg == inst.operands[1].reg
18153 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18154 as_tsktsk (BAD_MVE_SRCDEST);
18155
18156 if (inst.cond > COND_ALWAYS)
18157 inst.pred_insn_type = INSIDE_VPT_INSN;
18158 else
18159 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18160
18161 if (rs == NS_QQQ)
18162 {
18163 mve_encode_qqq (et.size == 32, 64);
18164 inst.instruction |= 1;
18165 }
18166 else
18167 {
18168 mve_encode_qqr (64, et.size == 32, 0);
18169 inst.instruction |= 0x3 << 5;
18170 }
18171}
18172
c2dafc2a
AV
18173static void
18174do_mve_vadc (void)
18175{
18176 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18177 struct neon_type_el et
18178 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18179
18180 if (et.type == NT_invtype)
18181 first_error (BAD_EL_TYPE);
18182
18183 if (inst.cond > COND_ALWAYS)
18184 inst.pred_insn_type = INSIDE_VPT_INSN;
18185 else
18186 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18187
18188 mve_encode_qqq (0, 64);
18189}
18190
18191static void
18192do_mve_vbrsr (void)
18193{
18194 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18195 struct neon_type_el et
18196 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18197
18198 if (inst.cond > COND_ALWAYS)
18199 inst.pred_insn_type = INSIDE_VPT_INSN;
18200 else
18201 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18202
7df54120 18203 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
18204}
18205
18206static void
18207do_mve_vsbc (void)
18208{
18209 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18210
18211 if (inst.cond > COND_ALWAYS)
18212 inst.pred_insn_type = INSIDE_VPT_INSN;
18213 else
18214 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18215
18216 mve_encode_qqq (1, 64);
18217}
18218
2d78f95b
AV
18219static void
18220do_mve_vmulh (void)
18221{
18222 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18223 struct neon_type_el et
18224 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18225
18226 if (inst.cond > COND_ALWAYS)
18227 inst.pred_insn_type = INSIDE_VPT_INSN;
18228 else
18229 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18230
18231 mve_encode_qqq (et.type == NT_unsigned, et.size);
18232}
18233
42b16635
AV
18234static void
18235do_mve_vqdmlah (void)
18236{
18237 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18238 struct neon_type_el et
23d188c7 18239 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
18240
18241 if (inst.cond > COND_ALWAYS)
18242 inst.pred_insn_type = INSIDE_VPT_INSN;
18243 else
18244 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18245
18246 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18247}
8b8b22a4
AV
18248
18249static void
18250do_mve_vqdmladh (void)
18251{
18252 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18253 struct neon_type_el et
18254 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18255
18256 if (inst.cond > COND_ALWAYS)
18257 inst.pred_insn_type = INSIDE_VPT_INSN;
18258 else
18259 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18260
8b8b22a4
AV
18261 mve_encode_qqq (0, et.size);
18262}
18263
18264
886e1c73
AV
18265static void
18266do_mve_vmull (void)
18267{
18268
18269 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18270 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
fe05f369 18271 if (inst.cond == COND_ALWAYS
886e1c73
AV
18272 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18273 {
fe05f369 18274
886e1c73
AV
18275 if (rs == NS_QQQ)
18276 {
fe05f369 18277 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
886e1c73
AV
18278 goto neon_vmul;
18279 }
18280 else
18281 goto neon_vmul;
18282 }
18283
18284 constraint (rs != NS_QQQ, BAD_FPU);
18285 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18286 N_SU_32 | N_P8 | N_P16 | N_KEY);
18287
18288 /* We are dealing with MVE's vmullt. */
18289 if (et.size == 32
18290 && (inst.operands[0].reg == inst.operands[1].reg
18291 || inst.operands[0].reg == inst.operands[2].reg))
18292 as_tsktsk (BAD_MVE_SRCDEST);
18293
18294 if (inst.cond > COND_ALWAYS)
18295 inst.pred_insn_type = INSIDE_VPT_INSN;
18296 else
18297 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18298
18299 if (et.type == NT_poly)
18300 mve_encode_qqq (neon_logbits (et.size), 64);
18301 else
18302 mve_encode_qqq (et.type == NT_unsigned, et.size);
18303
18304 return;
18305
dc1e8a47 18306 neon_vmul:
886e1c73
AV
18307 inst.instruction = N_MNEM_vmul;
18308 inst.cond = 0xb;
18309 if (thumb_mode)
18310 inst.pred_insn_type = INSIDE_IT_INSN;
18311 do_neon_mul ();
18312}
18313
a302e574
AV
18314static void
18315do_mve_vabav (void)
18316{
18317 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18318
18319 if (rs == NS_NULL)
18320 return;
18321
18322 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18323 return;
18324
18325 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18326 | N_S16 | N_S32 | N_U8 | N_U16
18327 | N_U32);
18328
18329 if (inst.cond > COND_ALWAYS)
18330 inst.pred_insn_type = INSIDE_VPT_INSN;
18331 else
18332 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18333
18334 mve_encode_rqq (et.type == NT_unsigned, et.size);
18335}
18336
18337static void
18338do_mve_vmladav (void)
18339{
18340 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18341 struct neon_type_el et = neon_check_type (3, rs,
18342 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18343
18344 if (et.type == NT_unsigned
18345 && (inst.instruction == M_MNEM_vmladavx
18346 || inst.instruction == M_MNEM_vmladavax
18347 || inst.instruction == M_MNEM_vmlsdav
18348 || inst.instruction == M_MNEM_vmlsdava
18349 || inst.instruction == M_MNEM_vmlsdavx
18350 || inst.instruction == M_MNEM_vmlsdavax))
18351 first_error (BAD_SIMD_TYPE);
18352
18353 constraint (inst.operands[2].reg > 14,
18354 _("MVE vector register in the range [Q0..Q7] expected"));
18355
18356 if (inst.cond > COND_ALWAYS)
18357 inst.pred_insn_type = INSIDE_VPT_INSN;
18358 else
18359 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18360
18361 if (inst.instruction == M_MNEM_vmlsdav
18362 || inst.instruction == M_MNEM_vmlsdava
18363 || inst.instruction == M_MNEM_vmlsdavx
18364 || inst.instruction == M_MNEM_vmlsdavax)
18365 inst.instruction |= (et.size == 8) << 28;
18366 else
18367 inst.instruction |= (et.size == 8) << 8;
18368
18369 mve_encode_rqq (et.type == NT_unsigned, 64);
18370 inst.instruction |= (et.size == 32) << 16;
18371}
18372
93925576
AV
18373static void
18374do_mve_vmlaldav (void)
18375{
18376 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18377 struct neon_type_el et
18378 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18379 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18380
18381 if (et.type == NT_unsigned
18382 && (inst.instruction == M_MNEM_vmlsldav
18383 || inst.instruction == M_MNEM_vmlsldava
18384 || inst.instruction == M_MNEM_vmlsldavx
18385 || inst.instruction == M_MNEM_vmlsldavax))
18386 first_error (BAD_SIMD_TYPE);
18387
18388 if (inst.cond > COND_ALWAYS)
18389 inst.pred_insn_type = INSIDE_VPT_INSN;
18390 else
18391 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18392
18393 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18394}
18395
18396static void
18397do_mve_vrmlaldavh (void)
18398{
18399 struct neon_type_el et;
18400 if (inst.instruction == M_MNEM_vrmlsldavh
18401 || inst.instruction == M_MNEM_vrmlsldavha
18402 || inst.instruction == M_MNEM_vrmlsldavhx
18403 || inst.instruction == M_MNEM_vrmlsldavhax)
18404 {
18405 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18406 if (inst.operands[1].reg == REG_SP)
18407 as_tsktsk (MVE_BAD_SP);
18408 }
18409 else
18410 {
18411 if (inst.instruction == M_MNEM_vrmlaldavhx
18412 || inst.instruction == M_MNEM_vrmlaldavhax)
18413 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18414 else
18415 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18416 N_U32 | N_S32 | N_KEY);
18417 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18418 with vmax/min instructions, making the use of SP in assembly really
18419 nonsensical, so instead of issuing a warning like we do for other uses
18420 of SP for the odd register operand we error out. */
18421 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18422 }
18423
18424 /* Make sure we still check the second operand is an odd one and that PC is
18425 disallowed. This because we are parsing for any GPR operand, to be able
18426 to distinguish between giving a warning or an error for SP as described
18427 above. */
18428 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18429 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18430
18431 if (inst.cond > COND_ALWAYS)
18432 inst.pred_insn_type = INSIDE_VPT_INSN;
18433 else
18434 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18435
18436 mve_encode_rrqq (et.type == NT_unsigned, 0);
18437}
18438
18439
8cd78170
AV
18440static void
18441do_mve_vmaxnmv (void)
18442{
18443 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18444 struct neon_type_el et
18445 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18446
18447 if (inst.cond > COND_ALWAYS)
18448 inst.pred_insn_type = INSIDE_VPT_INSN;
18449 else
18450 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18451
18452 if (inst.operands[0].reg == REG_SP)
18453 as_tsktsk (MVE_BAD_SP);
18454 else if (inst.operands[0].reg == REG_PC)
18455 as_tsktsk (MVE_BAD_PC);
18456
18457 mve_encode_rq (et.size == 16, 64);
18458}
18459
13ccd4c0
AV
18460static void
18461do_mve_vmaxv (void)
18462{
18463 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18464 struct neon_type_el et;
18465
18466 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18467 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18468 else
18469 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18470
18471 if (inst.cond > COND_ALWAYS)
18472 inst.pred_insn_type = INSIDE_VPT_INSN;
18473 else
18474 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18475
18476 if (inst.operands[0].reg == REG_SP)
18477 as_tsktsk (MVE_BAD_SP);
18478 else if (inst.operands[0].reg == REG_PC)
18479 as_tsktsk (MVE_BAD_PC);
18480
18481 mve_encode_rq (et.type == NT_unsigned, et.size);
18482}
18483
18484
643afb90
MW
18485static void
18486do_neon_qrdmlah (void)
18487{
64c350f2 18488 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18489 return;
18490 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18491 {
42b16635
AV
18492 /* Check we're on the correct architecture. */
18493 if (!mark_feature_used (&fpu_neon_ext_armv8))
18494 inst.error
18495 = _("instruction form not available on this architecture.");
18496 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18497 {
18498 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18499 record_feature_use (&fpu_neon_ext_v8_1);
18500 }
18501 if (inst.operands[2].isscalar)
18502 {
18503 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18504 struct neon_type_el et = neon_check_type (3, rs,
18505 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18506 NEON_ENCODE (SCALAR, inst);
18507 neon_mul_mac (et, neon_quad (rs));
18508 }
18509 else
18510 {
18511 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18512 struct neon_type_el et = neon_check_type (3, rs,
18513 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18514 NEON_ENCODE (INTEGER, inst);
18515 /* The U bit (rounding) comes from bit mask. */
18516 neon_three_same (neon_quad (rs), 0, et.size);
18517 }
643afb90
MW
18518 }
18519 else
18520 {
42b16635
AV
18521 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18522 struct neon_type_el et
23d188c7 18523 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18524
643afb90 18525 NEON_ENCODE (INTEGER, inst);
42b16635 18526 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18527 }
18528}
18529
5287ad62
JB
18530static void
18531do_neon_fcmp_absolute (void)
18532{
037e8744 18533 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18534 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18535 N_F_16_32 | N_KEY);
5287ad62 18536 /* Size field comes from bit mask. */
cc933301 18537 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18538}
18539
18540static void
18541do_neon_fcmp_absolute_inv (void)
18542{
18543 neon_exchange_operands ();
18544 do_neon_fcmp_absolute ();
18545}
18546
18547static void
18548do_neon_step (void)
18549{
037e8744 18550 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18551 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18552 N_F_16_32 | N_KEY);
18553 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18554}
18555
18556static void
18557do_neon_abs_neg (void)
18558{
037e8744
JB
18559 enum neon_shape rs;
18560 struct neon_type_el et;
5f4273c7 18561
037e8744
JB
18562 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18563 return;
18564
037e8744 18565 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18566 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18567
64c350f2
AV
18568 if (!check_simd_pred_availability (et.type == NT_float,
18569 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18570 return;
18571
5287ad62
JB
18572 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18573 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18574 inst.instruction |= LOW4 (inst.operands[1].reg);
18575 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18576 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18577 inst.instruction |= (et.type == NT_float) << 10;
18578 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18579
88714cb8 18580 neon_dp_fixup (&inst);
5287ad62
JB
18581}
18582
18583static void
18584do_neon_sli (void)
18585{
64c350f2 18586 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18587 return;
18588
18589 enum neon_shape rs;
18590 struct neon_type_el et;
18591 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18592 {
18593 rs = neon_select_shape (NS_QQI, NS_NULL);
18594 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18595 }
18596 else
18597 {
18598 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18599 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18600 }
18601
18602
5287ad62
JB
18603 int imm = inst.operands[2].imm;
18604 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18605 _("immediate out of range for insert"));
037e8744 18606 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18607}
18608
18609static void
18610do_neon_sri (void)
18611{
64c350f2 18612 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18613 return;
18614
18615 enum neon_shape rs;
18616 struct neon_type_el et;
18617 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18618 {
18619 rs = neon_select_shape (NS_QQI, NS_NULL);
18620 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18621 }
18622 else
18623 {
18624 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18625 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18626 }
18627
5287ad62
JB
18628 int imm = inst.operands[2].imm;
18629 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18630 _("immediate out of range for insert"));
037e8744 18631 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18632}
18633
18634static void
18635do_neon_qshlu_imm (void)
18636{
64c350f2 18637 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18638 return;
18639
18640 enum neon_shape rs;
18641 struct neon_type_el et;
18642 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18643 {
18644 rs = neon_select_shape (NS_QQI, NS_NULL);
18645 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18646 }
18647 else
18648 {
18649 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18650 et = neon_check_type (2, rs, N_EQK | N_UNS,
18651 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18652 }
18653
5287ad62
JB
18654 int imm = inst.operands[2].imm;
18655 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18656 _("immediate out of range for shift"));
5287ad62
JB
18657 /* Only encodes the 'U present' variant of the instruction.
18658 In this case, signed types have OP (bit 8) set to 0.
18659 Unsigned types have OP set to 1. */
18660 inst.instruction |= (et.type == NT_unsigned) << 8;
18661 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18662 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18663}
18664
18665static void
18666do_neon_qmovn (void)
18667{
18668 struct neon_type_el et = neon_check_type (2, NS_DQ,
18669 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18670 /* Saturating move where operands can be signed or unsigned, and the
18671 destination has the same signedness. */
88714cb8 18672 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18673 if (et.type == NT_unsigned)
18674 inst.instruction |= 0xc0;
18675 else
18676 inst.instruction |= 0x80;
18677 neon_two_same (0, 1, et.size / 2);
18678}
18679
18680static void
18681do_neon_qmovun (void)
18682{
18683 struct neon_type_el et = neon_check_type (2, NS_DQ,
18684 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18685 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18686 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18687 neon_two_same (0, 1, et.size / 2);
18688}
18689
18690static void
18691do_neon_rshift_sat_narrow (void)
18692{
18693 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18694 or unsigned. If operands are unsigned, results must also be unsigned. */
18695 struct neon_type_el et = neon_check_type (2, NS_DQI,
18696 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18697 int imm = inst.operands[2].imm;
18698 /* This gets the bounds check, size encoding and immediate bits calculation
18699 right. */
18700 et.size /= 2;
5f4273c7 18701
5287ad62
JB
18702 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18703 VQMOVN.I<size> <Dd>, <Qm>. */
18704 if (imm == 0)
18705 {
18706 inst.operands[2].present = 0;
18707 inst.instruction = N_MNEM_vqmovn;
18708 do_neon_qmovn ();
18709 return;
18710 }
5f4273c7 18711
5287ad62 18712 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18713 _("immediate out of range"));
5287ad62
JB
18714 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18715}
18716
18717static void
18718do_neon_rshift_sat_narrow_u (void)
18719{
18720 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18721 or unsigned. If operands are unsigned, results must also be unsigned. */
18722 struct neon_type_el et = neon_check_type (2, NS_DQI,
18723 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18724 int imm = inst.operands[2].imm;
18725 /* This gets the bounds check, size encoding and immediate bits calculation
18726 right. */
18727 et.size /= 2;
18728
18729 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18730 VQMOVUN.I<size> <Dd>, <Qm>. */
18731 if (imm == 0)
18732 {
18733 inst.operands[2].present = 0;
18734 inst.instruction = N_MNEM_vqmovun;
18735 do_neon_qmovun ();
18736 return;
18737 }
18738
18739 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18740 _("immediate out of range"));
5287ad62
JB
18741 /* FIXME: The manual is kind of unclear about what value U should have in
18742 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18743 must be 1. */
18744 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18745}
18746
18747static void
18748do_neon_movn (void)
18749{
18750 struct neon_type_el et = neon_check_type (2, NS_DQ,
18751 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18752 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18753 neon_two_same (0, 1, et.size / 2);
18754}
18755
18756static void
18757do_neon_rshift_narrow (void)
18758{
18759 struct neon_type_el et = neon_check_type (2, NS_DQI,
18760 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18761 int imm = inst.operands[2].imm;
18762 /* This gets the bounds check, size encoding and immediate bits calculation
18763 right. */
18764 et.size /= 2;
5f4273c7 18765
5287ad62
JB
18766 /* If immediate is zero then we are a pseudo-instruction for
18767 VMOVN.I<size> <Dd>, <Qm> */
18768 if (imm == 0)
18769 {
18770 inst.operands[2].present = 0;
18771 inst.instruction = N_MNEM_vmovn;
18772 do_neon_movn ();
18773 return;
18774 }
5f4273c7 18775
5287ad62 18776 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18777 _("immediate out of range for narrowing operation"));
5287ad62
JB
18778 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18779}
18780
18781static void
18782do_neon_shll (void)
18783{
18784 /* FIXME: Type checking when lengthening. */
18785 struct neon_type_el et = neon_check_type (2, NS_QDI,
18786 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18787 unsigned imm = inst.operands[2].imm;
18788
18789 if (imm == et.size)
18790 {
18791 /* Maximum shift variant. */
88714cb8 18792 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18793 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18794 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18795 inst.instruction |= LOW4 (inst.operands[1].reg);
18796 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18797 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18798
88714cb8 18799 neon_dp_fixup (&inst);
5287ad62
JB
18800 }
18801 else
18802 {
18803 /* A more-specific type check for non-max versions. */
18804 et = neon_check_type (2, NS_QDI,
477330fc 18805 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18806 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18807 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18808 }
18809}
18810
037e8744 18811/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18812 the current instruction is. */
18813
6b9a8b67
MGD
18814#define CVT_FLAVOUR_VAR \
18815 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18816 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18817 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18818 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18819 /* Half-precision conversions. */ \
cc933301
JW
18820 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18821 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18822 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18823 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18824 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18825 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18826 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18827 Compared with single/double precision variants, only the co-processor \
18828 field is different, so the encoding flow is reused here. */ \
18829 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18830 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18831 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18832 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
aab2c27d 18833 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18834 /* VFP instructions. */ \
18835 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18836 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18837 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18838 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18839 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18840 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18841 /* VFP instructions with bitshift. */ \
18842 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18843 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18844 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18845 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18846 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18847 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18848 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18849 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18850
18851#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18852 neon_cvt_flavour_##C,
18853
18854/* The different types of conversions we can do. */
18855enum neon_cvt_flavour
18856{
18857 CVT_FLAVOUR_VAR
18858 neon_cvt_flavour_invalid,
18859 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18860};
18861
18862#undef CVT_VAR
18863
18864static enum neon_cvt_flavour
18865get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18866{
6b9a8b67
MGD
18867#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18868 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18869 if (et.type != NT_invtype) \
18870 { \
18871 inst.error = NULL; \
18872 return (neon_cvt_flavour_##C); \
5287ad62 18873 }
6b9a8b67 18874
5287ad62 18875 struct neon_type_el et;
037e8744 18876 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18877 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18878 /* The instruction versions which take an immediate take one register
18879 argument, which is extended to the width of the full register. Thus the
18880 "source" and "destination" registers must have the same width. Hack that
18881 here by making the size equal to the key (wider, in this case) operand. */
18882 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18883
6b9a8b67
MGD
18884 CVT_FLAVOUR_VAR;
18885
18886 return neon_cvt_flavour_invalid;
5287ad62
JB
18887#undef CVT_VAR
18888}
18889
7e8e6784
MGD
18890enum neon_cvt_mode
18891{
18892 neon_cvt_mode_a,
18893 neon_cvt_mode_n,
18894 neon_cvt_mode_p,
18895 neon_cvt_mode_m,
18896 neon_cvt_mode_z,
30bdf752
MGD
18897 neon_cvt_mode_x,
18898 neon_cvt_mode_r
7e8e6784
MGD
18899};
18900
037e8744
JB
18901/* Neon-syntax VFP conversions. */
18902
5287ad62 18903static void
6b9a8b67 18904do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18905{
037e8744 18906 const char *opname = 0;
5f4273c7 18907
d54af2d0
RL
18908 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18909 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18910 {
037e8744
JB
18911 /* Conversions with immediate bitshift. */
18912 const char *enc[] =
477330fc 18913 {
6b9a8b67
MGD
18914#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18915 CVT_FLAVOUR_VAR
18916 NULL
18917#undef CVT_VAR
477330fc 18918 };
037e8744 18919
6b9a8b67 18920 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18921 {
18922 opname = enc[flavour];
18923 constraint (inst.operands[0].reg != inst.operands[1].reg,
18924 _("operands 0 and 1 must be the same register"));
18925 inst.operands[1] = inst.operands[2];
18926 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18927 }
5287ad62
JB
18928 }
18929 else
18930 {
037e8744
JB
18931 /* Conversions without bitshift. */
18932 const char *enc[] =
477330fc 18933 {
6b9a8b67
MGD
18934#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18935 CVT_FLAVOUR_VAR
18936 NULL
18937#undef CVT_VAR
477330fc 18938 };
037e8744 18939
6b9a8b67 18940 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18941 opname = enc[flavour];
037e8744
JB
18942 }
18943
18944 if (opname)
18945 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18946
18947 /* ARMv8.2 fp16 VCVT instruction. */
18948 if (flavour == neon_cvt_flavour_s32_f16
18949 || flavour == neon_cvt_flavour_u32_f16
18950 || flavour == neon_cvt_flavour_f16_u32
18951 || flavour == neon_cvt_flavour_f16_s32)
18952 do_scalar_fp16_v82_encode ();
037e8744
JB
18953}
18954
18955static void
18956do_vfp_nsyn_cvtz (void)
18957{
d54af2d0 18958 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18959 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18960 const char *enc[] =
18961 {
6b9a8b67
MGD
18962#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18963 CVT_FLAVOUR_VAR
18964 NULL
18965#undef CVT_VAR
037e8744
JB
18966 };
18967
6b9a8b67 18968 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18969 do_vfp_nsyn_opcode (enc[flavour]);
18970}
f31fef98 18971
037e8744 18972static void
bacebabc 18973do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18974 enum neon_cvt_mode mode)
18975{
18976 int sz, op;
18977 int rm;
18978
a715796b
TG
18979 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18980 D register operands. */
18981 if (flavour == neon_cvt_flavour_s32_f64
18982 || flavour == neon_cvt_flavour_u32_f64)
18983 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18984 _(BAD_FPU));
18985
9db2f6b4
RL
18986 if (flavour == neon_cvt_flavour_s32_f16
18987 || flavour == neon_cvt_flavour_u32_f16)
18988 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18989 _(BAD_FP16));
18990
5ee91343 18991 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18992
18993 switch (flavour)
18994 {
18995 case neon_cvt_flavour_s32_f64:
18996 sz = 1;
827f64ff 18997 op = 1;
7e8e6784
MGD
18998 break;
18999 case neon_cvt_flavour_s32_f32:
19000 sz = 0;
19001 op = 1;
19002 break;
9db2f6b4
RL
19003 case neon_cvt_flavour_s32_f16:
19004 sz = 0;
19005 op = 1;
19006 break;
7e8e6784
MGD
19007 case neon_cvt_flavour_u32_f64:
19008 sz = 1;
19009 op = 0;
19010 break;
19011 case neon_cvt_flavour_u32_f32:
19012 sz = 0;
19013 op = 0;
19014 break;
9db2f6b4
RL
19015 case neon_cvt_flavour_u32_f16:
19016 sz = 0;
19017 op = 0;
19018 break;
7e8e6784
MGD
19019 default:
19020 first_error (_("invalid instruction shape"));
19021 return;
19022 }
19023
19024 switch (mode)
19025 {
19026 case neon_cvt_mode_a: rm = 0; break;
19027 case neon_cvt_mode_n: rm = 1; break;
19028 case neon_cvt_mode_p: rm = 2; break;
19029 case neon_cvt_mode_m: rm = 3; break;
19030 default: first_error (_("invalid rounding mode")); return;
19031 }
19032
19033 NEON_ENCODE (FPV8, inst);
19034 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19035 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19036 inst.instruction |= sz << 8;
9db2f6b4
RL
19037
19038 /* ARMv8.2 fp16 VCVT instruction. */
19039 if (flavour == neon_cvt_flavour_s32_f16
19040 ||flavour == neon_cvt_flavour_u32_f16)
19041 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
19042 inst.instruction |= op << 7;
19043 inst.instruction |= rm << 16;
19044 inst.instruction |= 0xf0000000;
19045 inst.is_neon = TRUE;
19046}
19047
19048static void
19049do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
19050{
19051 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
19052 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19053 NS_FH, NS_HF, NS_FHI, NS_HFI,
19054 NS_NULL);
6b9a8b67 19055 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 19056
cc933301
JW
19057 if (flavour == neon_cvt_flavour_invalid)
19058 return;
19059
e3e535bc 19060 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 19061 if (mode == neon_cvt_mode_z
e3e535bc 19062 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
19063 && (flavour == neon_cvt_flavour_s16_f16
19064 || flavour == neon_cvt_flavour_u16_f16
19065 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
19066 || flavour == neon_cvt_flavour_u32_f32
19067 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 19068 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
19069 && (rs == NS_FD || rs == NS_FF))
19070 {
19071 do_vfp_nsyn_cvtz ();
19072 return;
19073 }
19074
9db2f6b4
RL
19075 /* ARMv8.2 fp16 VCVT conversions. */
19076 if (mode == neon_cvt_mode_z
19077 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19078 && (flavour == neon_cvt_flavour_s32_f16
19079 || flavour == neon_cvt_flavour_u32_f16)
19080 && (rs == NS_FH))
19081 {
19082 do_vfp_nsyn_cvtz ();
19083 do_scalar_fp16_v82_encode ();
19084 return;
19085 }
19086
225f1684
JR
19087 if ((rs == NS_FD || rs == NS_QQI) && mode == neon_cvt_mode_n
19088 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19089 {
19090 /* We are dealing with vcvt with the 'ne' condition. */
19091 inst.cond = 0x1;
19092 inst.instruction = N_MNEM_vcvt;
19093 do_neon_cvt_1 (neon_cvt_mode_z);
19094 return;
19095 }
19096
037e8744 19097 /* VFP rather than Neon conversions. */
6b9a8b67 19098 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 19099 {
7e8e6784
MGD
19100 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19101 do_vfp_nsyn_cvt (rs, flavour);
19102 else
19103 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19104
037e8744
JB
19105 return;
19106 }
19107
19108 switch (rs)
19109 {
037e8744 19110 case NS_QQI:
dd9634d9
AV
19111 if (mode == neon_cvt_mode_z
19112 && (flavour == neon_cvt_flavour_f16_s16
19113 || flavour == neon_cvt_flavour_f16_u16
19114 || flavour == neon_cvt_flavour_s16_f16
19115 || flavour == neon_cvt_flavour_u16_f16
19116 || flavour == neon_cvt_flavour_f32_u32
19117 || flavour == neon_cvt_flavour_f32_s32
19118 || flavour == neon_cvt_flavour_s32_f32
19119 || flavour == neon_cvt_flavour_u32_f32))
19120 {
64c350f2
AV
19121 if (!check_simd_pred_availability (TRUE,
19122 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19123 return;
19124 }
dd9634d9
AV
19125 /* fall through. */
19126 case NS_DDI:
037e8744 19127 {
477330fc 19128 unsigned immbits;
cc933301
JW
19129 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19130 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 19131
dd9634d9
AV
19132 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19133 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19134 return;
19135
19136 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19137 {
19138 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19139 _("immediate value out of range"));
19140 switch (flavour)
19141 {
19142 case neon_cvt_flavour_f16_s16:
19143 case neon_cvt_flavour_f16_u16:
19144 case neon_cvt_flavour_s16_f16:
19145 case neon_cvt_flavour_u16_f16:
19146 constraint (inst.operands[2].imm > 16,
19147 _("immediate value out of range"));
19148 break;
19149 case neon_cvt_flavour_f32_u32:
19150 case neon_cvt_flavour_f32_s32:
19151 case neon_cvt_flavour_s32_f32:
19152 case neon_cvt_flavour_u32_f32:
19153 constraint (inst.operands[2].imm > 32,
19154 _("immediate value out of range"));
19155 break;
19156 default:
19157 inst.error = BAD_FPU;
19158 return;
19159 }
19160 }
037e8744 19161
477330fc
RM
19162 /* Fixed-point conversion with #0 immediate is encoded as an
19163 integer conversion. */
19164 if (inst.operands[2].present && inst.operands[2].imm == 0)
19165 goto int_encode;
477330fc
RM
19166 NEON_ENCODE (IMMED, inst);
19167 if (flavour != neon_cvt_flavour_invalid)
19168 inst.instruction |= enctab[flavour];
19169 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19170 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19171 inst.instruction |= LOW4 (inst.operands[1].reg);
19172 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19173 inst.instruction |= neon_quad (rs) << 6;
19174 inst.instruction |= 1 << 21;
cc933301
JW
19175 if (flavour < neon_cvt_flavour_s16_f16)
19176 {
19177 inst.instruction |= 1 << 21;
19178 immbits = 32 - inst.operands[2].imm;
19179 inst.instruction |= immbits << 16;
19180 }
19181 else
19182 {
19183 inst.instruction |= 3 << 20;
19184 immbits = 16 - inst.operands[2].imm;
19185 inst.instruction |= immbits << 16;
19186 inst.instruction &= ~(1 << 9);
19187 }
477330fc
RM
19188
19189 neon_dp_fixup (&inst);
037e8744
JB
19190 }
19191 break;
19192
037e8744 19193 case NS_QQ:
dd9634d9
AV
19194 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19195 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19196 && (flavour == neon_cvt_flavour_s16_f16
19197 || flavour == neon_cvt_flavour_u16_f16
19198 || flavour == neon_cvt_flavour_s32_f32
19199 || flavour == neon_cvt_flavour_u32_f32))
19200 {
64c350f2
AV
19201 if (!check_simd_pred_availability (TRUE,
19202 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
19203 return;
19204 }
19205 else if (mode == neon_cvt_mode_z
19206 && (flavour == neon_cvt_flavour_f16_s16
19207 || flavour == neon_cvt_flavour_f16_u16
19208 || flavour == neon_cvt_flavour_s16_f16
19209 || flavour == neon_cvt_flavour_u16_f16
19210 || flavour == neon_cvt_flavour_f32_u32
19211 || flavour == neon_cvt_flavour_f32_s32
19212 || flavour == neon_cvt_flavour_s32_f32
19213 || flavour == neon_cvt_flavour_u32_f32))
19214 {
64c350f2
AV
19215 if (!check_simd_pred_availability (TRUE,
19216 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19217 return;
19218 }
19219 /* fall through. */
19220 case NS_DD:
7e8e6784
MGD
19221 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19222 {
7e8e6784 19223
dd9634d9 19224 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
19225 if (!check_simd_pred_availability (TRUE,
19226 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
19227 return;
19228
19229 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19230 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19231 inst.instruction |= LOW4 (inst.operands[1].reg);
19232 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19233 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19234 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19235 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 19236 inst.instruction |= mode << 8;
cc933301
JW
19237 if (flavour == neon_cvt_flavour_u16_f16
19238 || flavour == neon_cvt_flavour_s16_f16)
19239 /* Mask off the original size bits and reencode them. */
19240 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19241
7e8e6784
MGD
19242 if (thumb_mode)
19243 inst.instruction |= 0xfc000000;
19244 else
19245 inst.instruction |= 0xf0000000;
19246 }
19247 else
19248 {
037e8744 19249 int_encode:
7e8e6784 19250 {
cc933301
JW
19251 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19252 0x100, 0x180, 0x0, 0x080};
037e8744 19253
7e8e6784 19254 NEON_ENCODE (INTEGER, inst);
037e8744 19255
dd9634d9
AV
19256 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19257 {
19258 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19259 return;
19260 }
037e8744 19261
7e8e6784
MGD
19262 if (flavour != neon_cvt_flavour_invalid)
19263 inst.instruction |= enctab[flavour];
037e8744 19264
7e8e6784
MGD
19265 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19266 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19267 inst.instruction |= LOW4 (inst.operands[1].reg);
19268 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19269 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19270 if (flavour >= neon_cvt_flavour_s16_f16
19271 && flavour <= neon_cvt_flavour_f16_u16)
19272 /* Half precision. */
19273 inst.instruction |= 1 << 18;
19274 else
19275 inst.instruction |= 2 << 18;
037e8744 19276
7e8e6784
MGD
19277 neon_dp_fixup (&inst);
19278 }
19279 }
19280 break;
037e8744 19281
8e79c3df
CM
19282 /* Half-precision conversions for Advanced SIMD -- neon. */
19283 case NS_QD:
19284 case NS_DQ:
bc52d49c
MM
19285 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19286 return;
8e79c3df
CM
19287
19288 if ((rs == NS_DQ)
19289 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19290 {
19291 as_bad (_("operand size must match register width"));
19292 break;
19293 }
19294
19295 if ((rs == NS_QD)
19296 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19297 {
19298 as_bad (_("operand size must match register width"));
19299 break;
19300 }
19301
19302 if (rs == NS_DQ)
aab2c27d
MM
19303 {
19304 if (flavour == neon_cvt_flavour_bf16_f32)
19305 {
19306 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19307 return;
19308 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19309 /* VCVT.bf16.f32. */
19310 inst.instruction = 0x11b60640;
19311 }
19312 else
19313 /* VCVT.f16.f32. */
19314 inst.instruction = 0x3b60600;
19315 }
8e79c3df 19316 else
aab2c27d 19317 /* VCVT.f32.f16. */
8e79c3df
CM
19318 inst.instruction = 0x3b60700;
19319
19320 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19321 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19322 inst.instruction |= LOW4 (inst.operands[1].reg);
19323 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19324 neon_dp_fixup (&inst);
8e79c3df
CM
19325 break;
19326
037e8744
JB
19327 default:
19328 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19329 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19330 do_vfp_nsyn_cvt (rs, flavour);
19331 else
19332 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19333 }
5287ad62
JB
19334}
19335
e3e535bc
NC
19336static void
19337do_neon_cvtr (void)
19338{
7e8e6784 19339 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19340}
19341
19342static void
19343do_neon_cvt (void)
19344{
7e8e6784
MGD
19345 do_neon_cvt_1 (neon_cvt_mode_z);
19346}
19347
19348static void
19349do_neon_cvta (void)
19350{
19351 do_neon_cvt_1 (neon_cvt_mode_a);
19352}
19353
19354static void
19355do_neon_cvtn (void)
19356{
19357 do_neon_cvt_1 (neon_cvt_mode_n);
19358}
19359
19360static void
19361do_neon_cvtp (void)
19362{
19363 do_neon_cvt_1 (neon_cvt_mode_p);
19364}
19365
19366static void
19367do_neon_cvtm (void)
19368{
19369 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19370}
19371
8e79c3df 19372static void
c70a8987 19373do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19374{
c70a8987
MGD
19375 if (is_double)
19376 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19377
c70a8987
MGD
19378 encode_arm_vfp_reg (inst.operands[0].reg,
19379 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19380 encode_arm_vfp_reg (inst.operands[1].reg,
19381 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19382 inst.instruction |= to ? 0x10000 : 0;
19383 inst.instruction |= t ? 0x80 : 0;
19384 inst.instruction |= is_double ? 0x100 : 0;
19385 do_vfp_cond_or_thumb ();
19386}
8e79c3df 19387
c70a8987
MGD
19388static void
19389do_neon_cvttb_1 (bfd_boolean t)
19390{
d54af2d0 19391 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19392 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19393
c70a8987
MGD
19394 if (rs == NS_NULL)
19395 return;
dd9634d9
AV
19396 else if (rs == NS_QQ || rs == NS_QQI)
19397 {
19398 int single_to_half = 0;
64c350f2 19399 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19400 return;
19401
19402 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19403
19404 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19405 && (flavour == neon_cvt_flavour_u16_f16
19406 || flavour == neon_cvt_flavour_s16_f16
19407 || flavour == neon_cvt_flavour_f16_s16
19408 || flavour == neon_cvt_flavour_f16_u16
19409 || flavour == neon_cvt_flavour_u32_f32
19410 || flavour == neon_cvt_flavour_s32_f32
19411 || flavour == neon_cvt_flavour_f32_s32
19412 || flavour == neon_cvt_flavour_f32_u32))
19413 {
19414 inst.cond = 0xf;
19415 inst.instruction = N_MNEM_vcvt;
19416 set_pred_insn_type (INSIDE_VPT_INSN);
19417 do_neon_cvt_1 (neon_cvt_mode_z);
19418 return;
19419 }
19420 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19421 single_to_half = 1;
19422 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19423 {
19424 first_error (BAD_FPU);
19425 return;
19426 }
19427
19428 inst.instruction = 0xee3f0e01;
19429 inst.instruction |= single_to_half << 28;
19430 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19431 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19432 inst.instruction |= t << 12;
19433 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19434 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19435 inst.is_neon = 1;
19436 }
c70a8987
MGD
19437 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19438 {
19439 inst.error = NULL;
19440 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19441 }
19442 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19443 {
19444 inst.error = NULL;
19445 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19446 }
19447 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19448 {
a715796b
TG
19449 /* The VCVTB and VCVTT instructions with D-register operands
19450 don't work for SP only targets. */
19451 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19452 _(BAD_FPU));
19453
c70a8987
MGD
19454 inst.error = NULL;
19455 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19456 }
19457 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19458 {
a715796b
TG
19459 /* The VCVTB and VCVTT instructions with D-register operands
19460 don't work for SP only targets. */
19461 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19462 _(BAD_FPU));
19463
c70a8987
MGD
19464 inst.error = NULL;
19465 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19466 }
aab2c27d
MM
19467 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19468 {
19469 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19470 inst.error = NULL;
19471 inst.instruction |= (1 << 8);
19472 inst.instruction &= ~(1 << 9);
19473 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19474 }
c70a8987
MGD
19475 else
19476 return;
19477}
19478
19479static void
19480do_neon_cvtb (void)
19481{
19482 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19483}
19484
19485
19486static void
19487do_neon_cvtt (void)
19488{
c70a8987 19489 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19490}
19491
5287ad62
JB
19492static void
19493neon_move_immediate (void)
19494{
037e8744
JB
19495 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19496 struct neon_type_el et = neon_check_type (2, rs,
19497 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19498 unsigned immlo, immhi = 0, immbits;
c96612cc 19499 int op, cmode, float_p;
5287ad62 19500
037e8744 19501 constraint (et.type == NT_invtype,
477330fc 19502 _("operand size must be specified for immediate VMOV"));
037e8744 19503
5287ad62
JB
19504 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19505 op = (inst.instruction & (1 << 5)) != 0;
19506
19507 immlo = inst.operands[1].imm;
19508 if (inst.operands[1].regisimm)
19509 immhi = inst.operands[1].reg;
19510
19511 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19512 _("immediate has bits set outside the operand size"));
5287ad62 19513
c96612cc
JB
19514 float_p = inst.operands[1].immisfloat;
19515
19516 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19517 et.size, et.type)) == FAIL)
5287ad62
JB
19518 {
19519 /* Invert relevant bits only. */
19520 neon_invert_size (&immlo, &immhi, et.size);
19521 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19522 with one or the other; those cases are caught by
19523 neon_cmode_for_move_imm. */
5287ad62 19524 op = !op;
c96612cc
JB
19525 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19526 &op, et.size, et.type)) == FAIL)
477330fc
RM
19527 {
19528 first_error (_("immediate out of range"));
19529 return;
19530 }
5287ad62
JB
19531 }
19532
19533 inst.instruction &= ~(1 << 5);
19534 inst.instruction |= op << 5;
19535
19536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19538 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19539 inst.instruction |= cmode << 8;
19540
19541 neon_write_immbits (immbits);
19542}
19543
19544static void
19545do_neon_mvn (void)
19546{
64c350f2 19547 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19548 return;
19549
5287ad62
JB
19550 if (inst.operands[1].isreg)
19551 {
1a186d29
AV
19552 enum neon_shape rs;
19553 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19554 rs = neon_select_shape (NS_QQ, NS_NULL);
19555 else
19556 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19557
250dd99f
AM
19558 if (rs == NS_NULL)
19559 return;
19560
88714cb8 19561 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19562 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19563 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19564 inst.instruction |= LOW4 (inst.operands[1].reg);
19565 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19566 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19567 }
19568 else
19569 {
88714cb8 19570 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19571 neon_move_immediate ();
19572 }
19573
88714cb8 19574 neon_dp_fixup (&inst);
1a186d29
AV
19575
19576 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19577 {
19578 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
1a186d29 19579 }
5287ad62
JB
19580}
19581
19582/* Encode instructions of form:
19583
19584 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19585 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19586
19587static void
19588neon_mixed_length (struct neon_type_el et, unsigned size)
19589{
19590 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19591 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19592 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19593 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19594 inst.instruction |= LOW4 (inst.operands[2].reg);
19595 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19596 inst.instruction |= (et.type == NT_unsigned) << 24;
19597 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19598
88714cb8 19599 neon_dp_fixup (&inst);
5287ad62
JB
19600}
19601
19602static void
19603do_neon_dyadic_long (void)
19604{
66d1f7cc 19605 enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL);
5ee91343
AV
19606 if (rs == NS_QDD)
19607 {
19608 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19609 return;
19610
19611 NEON_ENCODE (INTEGER, inst);
19612 /* FIXME: Type checking for lengthening op. */
19613 struct neon_type_el et = neon_check_type (3, NS_QDD,
19614 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19615 neon_mixed_length (et, et.size);
19616 }
19617 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19618 && (inst.cond == 0xf || inst.cond == 0x10))
19619 {
19620 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19621 in an IT block with le/lt conditions. */
19622
19623 if (inst.cond == 0xf)
19624 inst.cond = 0xb;
19625 else if (inst.cond == 0x10)
19626 inst.cond = 0xd;
19627
19628 inst.pred_insn_type = INSIDE_IT_INSN;
19629
19630 if (inst.instruction == N_MNEM_vaddl)
19631 {
19632 inst.instruction = N_MNEM_vadd;
19633 do_neon_addsub_if_i ();
19634 }
19635 else if (inst.instruction == N_MNEM_vsubl)
19636 {
19637 inst.instruction = N_MNEM_vsub;
19638 do_neon_addsub_if_i ();
19639 }
19640 else if (inst.instruction == N_MNEM_vabdl)
19641 {
19642 inst.instruction = N_MNEM_vabd;
19643 do_neon_dyadic_if_su ();
19644 }
19645 }
19646 else
19647 first_error (BAD_FPU);
5287ad62
JB
19648}
19649
19650static void
19651do_neon_abal (void)
19652{
19653 struct neon_type_el et = neon_check_type (3, NS_QDD,
19654 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19655 neon_mixed_length (et, et.size);
19656}
19657
19658static void
19659neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19660{
19661 if (inst.operands[2].isscalar)
19662 {
dcbf9037 19663 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19664 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19665 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19666 neon_mul_mac (et, et.type == NT_unsigned);
19667 }
19668 else
19669 {
19670 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19671 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19672 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19673 neon_mixed_length (et, et.size);
19674 }
19675}
19676
19677static void
19678do_neon_mac_maybe_scalar_long (void)
19679{
19680 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19681}
19682
dec41383
JW
19683/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19684 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19685
19686static unsigned
19687neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19688{
19689 unsigned regno = NEON_SCALAR_REG (scalar);
19690 unsigned elno = NEON_SCALAR_INDEX (scalar);
19691
19692 if (quad_p)
19693 {
19694 if (regno > 7 || elno > 3)
19695 goto bad_scalar;
19696
19697 return ((regno & 0x7)
19698 | ((elno & 0x1) << 3)
19699 | (((elno >> 1) & 0x1) << 5));
19700 }
19701 else
19702 {
19703 if (regno > 15 || elno > 1)
19704 goto bad_scalar;
19705
19706 return (((regno & 0x1) << 5)
19707 | ((regno >> 1) & 0x7)
19708 | ((elno & 0x1) << 3));
19709 }
19710
dc1e8a47 19711 bad_scalar:
dec41383
JW
19712 first_error (_("scalar out of range for multiply instruction"));
19713 return 0;
19714}
19715
19716static void
19717do_neon_fmac_maybe_scalar_long (int subtype)
19718{
19719 enum neon_shape rs;
19720 int high8;
19721 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19722 field (bits[21:20]) has different meaning. For scalar index variant, it's
19723 used to differentiate add and subtract, otherwise it's with fixed value
19724 0x2. */
19725 int size = -1;
19726
dec41383
JW
19727 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19728 be a scalar index register. */
19729 if (inst.operands[2].isscalar)
19730 {
19731 high8 = 0xfe000000;
19732 if (subtype)
19733 size = 16;
19734 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19735 }
19736 else
19737 {
19738 high8 = 0xfc000000;
19739 size = 32;
19740 if (subtype)
19741 inst.instruction |= (0x1 << 23);
19742 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19743 }
19744
aab2c27d
MM
19745
19746 if (inst.cond != COND_ALWAYS)
19747 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19748 "behaviour is UNPREDICTABLE"));
19749
19750 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19751 _(BAD_FP16));
19752
19753 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19754 _(BAD_FPU));
dec41383
JW
19755
19756 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19757 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19758 so we simply pass -1 as size. */
19759 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19760 neon_three_same (quad_p, 0, size);
19761
19762 /* Undo neon_dp_fixup. Redo the high eight bits. */
19763 inst.instruction &= 0x00ffffff;
19764 inst.instruction |= high8;
19765
dec41383
JW
19766 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19767 whether the instruction is in Q form and whether Vm is a scalar indexed
19768 operand. */
19769 if (inst.operands[2].isscalar)
19770 {
19771 unsigned rm
19772 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19773 inst.instruction &= 0xffffffd0;
19774 inst.instruction |= rm;
19775
19776 if (!quad_p)
19777 {
19778 /* Redo Rn as well. */
19779 inst.instruction &= 0xfff0ff7f;
19780 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19781 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19782 }
19783 }
19784 else if (!quad_p)
19785 {
19786 /* Redo Rn and Rm. */
19787 inst.instruction &= 0xfff0ff50;
19788 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19789 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19790 inst.instruction |= HI4 (inst.operands[2].reg);
19791 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19792 }
19793}
19794
19795static void
19796do_neon_vfmal (void)
19797{
19798 return do_neon_fmac_maybe_scalar_long (0);
19799}
19800
19801static void
19802do_neon_vfmsl (void)
19803{
19804 return do_neon_fmac_maybe_scalar_long (1);
19805}
19806
5287ad62
JB
19807static void
19808do_neon_dyadic_wide (void)
19809{
19810 struct neon_type_el et = neon_check_type (3, NS_QQD,
19811 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19812 neon_mixed_length (et, et.size);
19813}
19814
19815static void
19816do_neon_dyadic_narrow (void)
19817{
19818 struct neon_type_el et = neon_check_type (3, NS_QDD,
19819 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19820 /* Operand sign is unimportant, and the U bit is part of the opcode,
19821 so force the operand type to integer. */
19822 et.type = NT_integer;
5287ad62
JB
19823 neon_mixed_length (et, et.size / 2);
19824}
19825
19826static void
19827do_neon_mul_sat_scalar_long (void)
19828{
19829 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19830}
19831
19832static void
19833do_neon_vmull (void)
19834{
19835 if (inst.operands[2].isscalar)
19836 do_neon_mac_maybe_scalar_long ();
19837 else
19838 {
19839 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19840 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19841
5287ad62 19842 if (et.type == NT_poly)
477330fc 19843 NEON_ENCODE (POLY, inst);
5287ad62 19844 else
477330fc 19845 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19846
19847 /* For polynomial encoding the U bit must be zero, and the size must
19848 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19849 obviously, as 0b10). */
19850 if (et.size == 64)
19851 {
19852 /* Check we're on the correct architecture. */
19853 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19854 inst.error =
19855 _("Instruction form not available on this architecture.");
19856
19857 et.size = 32;
19858 }
19859
5287ad62
JB
19860 neon_mixed_length (et, et.size);
19861 }
19862}
19863
19864static void
19865do_neon_ext (void)
19866{
037e8744 19867 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19868 struct neon_type_el et = neon_check_type (3, rs,
19869 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19870 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19871
19872 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19873 _("shift out of range"));
5287ad62
JB
19874 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19875 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19876 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19877 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19878 inst.instruction |= LOW4 (inst.operands[2].reg);
19879 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19880 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19881 inst.instruction |= imm << 8;
5f4273c7 19882
88714cb8 19883 neon_dp_fixup (&inst);
5287ad62
JB
19884}
19885
19886static void
19887do_neon_rev (void)
19888{
64c350f2 19889 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19890 return;
19891
19892 enum neon_shape rs;
19893 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19894 rs = neon_select_shape (NS_QQ, NS_NULL);
19895 else
19896 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19897
5287ad62
JB
19898 struct neon_type_el et = neon_check_type (2, rs,
19899 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19900
5287ad62
JB
19901 unsigned op = (inst.instruction >> 7) & 3;
19902 /* N (width of reversed regions) is encoded as part of the bitmask. We
19903 extract it here to check the elements to be reversed are smaller.
19904 Otherwise we'd get a reserved instruction. */
19905 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19906
19907 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19908 && inst.operands[0].reg == inst.operands[1].reg)
19909 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19910 " operands makes instruction UNPREDICTABLE"));
19911
9c2799c2 19912 gas_assert (elsize != 0);
5287ad62 19913 constraint (et.size >= elsize,
477330fc 19914 _("elements must be smaller than reversal region"));
037e8744 19915 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19916}
19917
19918static void
19919do_neon_dup (void)
19920{
19921 if (inst.operands[1].isscalar)
19922 {
b409bdb6
AV
19923 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19924 BAD_FPU);
037e8744 19925 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19926 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19927 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19928 unsigned sizebits = et.size >> 3;
dcbf9037 19929 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19930 int logsize = neon_logbits (et.size);
dcbf9037 19931 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19932
19933 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19934 return;
037e8744 19935
88714cb8 19936 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19937 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19938 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19939 inst.instruction |= LOW4 (dm);
19940 inst.instruction |= HI1 (dm) << 5;
037e8744 19941 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19942 inst.instruction |= x << 17;
19943 inst.instruction |= sizebits << 16;
5f4273c7 19944
88714cb8 19945 neon_dp_fixup (&inst);
5287ad62
JB
19946 }
19947 else
19948 {
037e8744
JB
19949 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19950 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19951 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19952 if (rs == NS_QR)
19953 {
64c350f2 19954 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19955 return;
19956 }
19957 else
19958 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19959 BAD_FPU);
19960
19961 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19962 {
19963 if (inst.operands[1].reg == REG_SP)
19964 as_tsktsk (MVE_BAD_SP);
19965 else if (inst.operands[1].reg == REG_PC)
19966 as_tsktsk (MVE_BAD_PC);
19967 }
19968
5287ad62 19969 /* Duplicate ARM register to lanes of vector. */
88714cb8 19970 NEON_ENCODE (ARMREG, inst);
5287ad62 19971 switch (et.size)
477330fc
RM
19972 {
19973 case 8: inst.instruction |= 0x400000; break;
19974 case 16: inst.instruction |= 0x000020; break;
19975 case 32: inst.instruction |= 0x000000; break;
19976 default: break;
19977 }
5287ad62
JB
19978 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19979 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19980 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19981 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19982 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19983 variants, except for the condition field. */
037e8744 19984 do_vfp_cond_or_thumb ();
5287ad62
JB
19985 }
19986}
19987
57785aa2
AV
19988static void
19989do_mve_mov (int toQ)
19990{
19991 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19992 return;
19993 if (inst.cond > COND_ALWAYS)
19994 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19995
19996 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19997 if (toQ)
19998 {
19999 Q0 = 0;
20000 Q1 = 1;
20001 Rt = 2;
20002 Rt2 = 3;
20003 }
20004
20005 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
20006 _("Index one must be [2,3] and index two must be two less than"
20007 " index one."));
20008 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
20009 _("General purpose registers may not be the same"));
20010 constraint (inst.operands[Rt].reg == REG_SP
20011 || inst.operands[Rt2].reg == REG_SP,
20012 BAD_SP);
20013 constraint (inst.operands[Rt].reg == REG_PC
20014 || inst.operands[Rt2].reg == REG_PC,
20015 BAD_PC);
20016
20017 inst.instruction = 0xec000f00;
20018 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20019 inst.instruction |= !!toQ << 20;
20020 inst.instruction |= inst.operands[Rt2].reg << 16;
20021 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20022 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20023 inst.instruction |= inst.operands[Rt].reg;
20024}
20025
20026static void
20027do_mve_movn (void)
20028{
20029 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20030 return;
20031
20032 if (inst.cond > COND_ALWAYS)
20033 inst.pred_insn_type = INSIDE_VPT_INSN;
20034 else
20035 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20036
20037 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20038 | N_KEY);
20039
20040 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20041 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20042 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20043 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20044 inst.instruction |= LOW4 (inst.operands[1].reg);
20045 inst.is_neon = 1;
20046
20047}
20048
5287ad62
JB
20049/* VMOV has particularly many variations. It can be one of:
20050 0. VMOV<c><q> <Qd>, <Qm>
20051 1. VMOV<c><q> <Dd>, <Dm>
20052 (Register operations, which are VORR with Rm = Rn.)
20053 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20054 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20055 (Immediate loads.)
20056 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20057 (ARM register to scalar.)
20058 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20059 (Two ARM registers to vector.)
20060 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20061 (Scalar to ARM register.)
20062 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20063 (Vector to two ARM registers.)
037e8744
JB
20064 8. VMOV.F32 <Sd>, <Sm>
20065 9. VMOV.F64 <Dd>, <Dm>
20066 (VFP register moves.)
20067 10. VMOV.F32 <Sd>, #imm
20068 11. VMOV.F64 <Dd>, #imm
20069 (VFP float immediate load.)
20070 12. VMOV <Rd>, <Sm>
20071 (VFP single to ARM reg.)
20072 13. VMOV <Sd>, <Rm>
20073 (ARM reg to VFP single.)
20074 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20075 (Two ARM regs to two VFP singles.)
20076 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20077 (Two VFP singles to two ARM regs.)
57785aa2
AV
20078 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20079 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20080 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20081 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 20082
037e8744
JB
20083 These cases can be disambiguated using neon_select_shape, except cases 1/9
20084 and 3/11 which depend on the operand type too.
5f4273c7 20085
5287ad62 20086 All the encoded bits are hardcoded by this function.
5f4273c7 20087
b7fc2769
JB
20088 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20089 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 20090
5287ad62 20091 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 20092 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
20093
20094static void
20095do_neon_mov (void)
20096{
57785aa2
AV
20097 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20098 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20099 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20100 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20101 NS_NULL);
037e8744
JB
20102 struct neon_type_el et;
20103 const char *ldconst = 0;
5287ad62 20104
037e8744 20105 switch (rs)
5287ad62 20106 {
037e8744
JB
20107 case NS_DD: /* case 1/9. */
20108 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20109 /* It is not an error here if no type is given. */
20110 inst.error = NULL;
1c1e0fe5
SP
20111
20112 /* In MVE we interpret the following instructions as same, so ignoring
20113 the following type (float) and size (64) checks.
20114 a: VMOV<c><q> <Dd>, <Dm>
20115 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20116 if ((et.type == NT_float && et.size == 64)
20117 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc
RM
20118 {
20119 do_vfp_nsyn_opcode ("fcpyd");
20120 break;
20121 }
037e8744 20122 /* fall through. */
5287ad62 20123
037e8744
JB
20124 case NS_QQ: /* case 0/1. */
20125 {
64c350f2
AV
20126 if (!check_simd_pred_availability (FALSE,
20127 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
20128 return;
20129 /* The architecture manual I have doesn't explicitly state which
20130 value the U bit should have for register->register moves, but
20131 the equivalent VORR instruction has U = 0, so do that. */
20132 inst.instruction = 0x0200110;
20133 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20134 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20135 inst.instruction |= LOW4 (inst.operands[1].reg);
20136 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20137 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20138 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20139 inst.instruction |= neon_quad (rs) << 6;
20140
20141 neon_dp_fixup (&inst);
037e8744
JB
20142 }
20143 break;
5f4273c7 20144
037e8744
JB
20145 case NS_DI: /* case 3/11. */
20146 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20147 inst.error = NULL;
20148 if (et.type == NT_float && et.size == 64)
477330fc
RM
20149 {
20150 /* case 11 (fconstd). */
20151 ldconst = "fconstd";
20152 goto encode_fconstd;
20153 }
037e8744
JB
20154 /* fall through. */
20155
20156 case NS_QI: /* case 2/3. */
64c350f2
AV
20157 if (!check_simd_pred_availability (FALSE,
20158 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 20159 return;
037e8744
JB
20160 inst.instruction = 0x0800010;
20161 neon_move_immediate ();
88714cb8 20162 neon_dp_fixup (&inst);
5287ad62 20163 break;
5f4273c7 20164
037e8744
JB
20165 case NS_SR: /* case 4. */
20166 {
477330fc
RM
20167 unsigned bcdebits = 0;
20168 int logsize;
20169 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20170 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 20171
05ac0ffb
JB
20172 /* .<size> is optional here, defaulting to .32. */
20173 if (inst.vectype.elems == 0
20174 && inst.operands[0].vectype.type == NT_invtype
20175 && inst.operands[1].vectype.type == NT_invtype)
20176 {
20177 inst.vectype.el[0].type = NT_untyped;
20178 inst.vectype.el[0].size = 32;
20179 inst.vectype.elems = 1;
20180 }
20181
477330fc
RM
20182 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20183 logsize = neon_logbits (et.size);
20184
57785aa2
AV
20185 if (et.size != 32)
20186 {
20187 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20188 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20189 return;
20190 }
20191 else
20192 {
20193 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20194 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20195 _(BAD_FPU));
20196 }
20197
20198 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20199 {
20200 if (inst.operands[1].reg == REG_SP)
20201 as_tsktsk (MVE_BAD_SP);
20202 else if (inst.operands[1].reg == REG_PC)
20203 as_tsktsk (MVE_BAD_PC);
20204 }
20205 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20206
477330fc 20207 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
20208 constraint (x >= size / et.size, _("scalar index out of range"));
20209
477330fc
RM
20210
20211 switch (et.size)
20212 {
20213 case 8: bcdebits = 0x8; break;
20214 case 16: bcdebits = 0x1; break;
20215 case 32: bcdebits = 0x0; break;
20216 default: ;
20217 }
20218
57785aa2 20219 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20220
20221 inst.instruction = 0xe000b10;
20222 do_vfp_cond_or_thumb ();
20223 inst.instruction |= LOW4 (dn) << 16;
20224 inst.instruction |= HI1 (dn) << 7;
20225 inst.instruction |= inst.operands[1].reg << 12;
20226 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
20227 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20228 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20229 }
20230 break;
5f4273c7 20231
037e8744 20232 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
20233 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20234 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20235 _(BAD_FPU));
b7fc2769 20236
037e8744
JB
20237 inst.instruction = 0xc400b10;
20238 do_vfp_cond_or_thumb ();
20239 inst.instruction |= LOW4 (inst.operands[0].reg);
20240 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20241 inst.instruction |= inst.operands[1].reg << 12;
20242 inst.instruction |= inst.operands[2].reg << 16;
20243 break;
5f4273c7 20244
037e8744
JB
20245 case NS_RS: /* case 6. */
20246 {
477330fc
RM
20247 unsigned logsize;
20248 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20249 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20250 unsigned abcdebits = 0;
037e8744 20251
05ac0ffb
JB
20252 /* .<dt> is optional here, defaulting to .32. */
20253 if (inst.vectype.elems == 0
20254 && inst.operands[0].vectype.type == NT_invtype
20255 && inst.operands[1].vectype.type == NT_invtype)
20256 {
20257 inst.vectype.el[0].type = NT_untyped;
20258 inst.vectype.el[0].size = 32;
20259 inst.vectype.elems = 1;
20260 }
20261
91d6fa6a
NC
20262 et = neon_check_type (2, NS_NULL,
20263 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
20264 logsize = neon_logbits (et.size);
20265
57785aa2
AV
20266 if (et.size != 32)
20267 {
20268 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20269 && vfp_or_neon_is_neon (NEON_CHECK_CC
20270 | NEON_CHECK_ARCH) == FAIL)
20271 return;
20272 }
20273 else
20274 {
20275 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20276 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20277 _(BAD_FPU));
20278 }
20279
20280 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20281 {
20282 if (inst.operands[0].reg == REG_SP)
20283 as_tsktsk (MVE_BAD_SP);
20284 else if (inst.operands[0].reg == REG_PC)
20285 as_tsktsk (MVE_BAD_PC);
20286 }
20287
20288 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20289
477330fc 20290 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 20291 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
20292
20293 switch (et.size)
20294 {
20295 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20296 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20297 case 32: abcdebits = 0x00; break;
20298 default: ;
20299 }
20300
57785aa2 20301 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20302 inst.instruction = 0xe100b10;
20303 do_vfp_cond_or_thumb ();
20304 inst.instruction |= LOW4 (dn) << 16;
20305 inst.instruction |= HI1 (dn) << 7;
20306 inst.instruction |= inst.operands[0].reg << 12;
20307 inst.instruction |= (abcdebits & 3) << 5;
20308 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 20309 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20310 }
20311 break;
5f4273c7 20312
037e8744 20313 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
20314 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20315 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20316 _(BAD_FPU));
037e8744
JB
20317
20318 inst.instruction = 0xc500b10;
20319 do_vfp_cond_or_thumb ();
20320 inst.instruction |= inst.operands[0].reg << 12;
20321 inst.instruction |= inst.operands[1].reg << 16;
20322 inst.instruction |= LOW4 (inst.operands[2].reg);
20323 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20324 break;
5f4273c7 20325
037e8744
JB
20326 case NS_FF: /* case 8 (fcpys). */
20327 do_vfp_nsyn_opcode ("fcpys");
20328 break;
5f4273c7 20329
9db2f6b4 20330 case NS_HI:
037e8744
JB
20331 case NS_FI: /* case 10 (fconsts). */
20332 ldconst = "fconsts";
4ef4710f 20333 encode_fconstd:
58ed5c38
TC
20334 if (!inst.operands[1].immisfloat)
20335 {
4ef4710f 20336 unsigned new_imm;
58ed5c38 20337 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
20338 float imm = (float) inst.operands[1].imm;
20339 memcpy (&new_imm, &imm, sizeof (float));
20340 /* But the assembly may have been written to provide an integer
20341 bit pattern that equates to a float, so check that the
20342 conversion has worked. */
20343 if (is_quarter_float (new_imm))
20344 {
20345 if (is_quarter_float (inst.operands[1].imm))
20346 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20347
20348 inst.operands[1].imm = new_imm;
20349 inst.operands[1].immisfloat = 1;
20350 }
58ed5c38
TC
20351 }
20352
037e8744 20353 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
20354 {
20355 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20356 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20357
20358 /* ARMv8.2 fp16 vmov.f16 instruction. */
20359 if (rs == NS_HI)
20360 do_scalar_fp16_v82_encode ();
477330fc 20361 }
5287ad62 20362 else
477330fc 20363 first_error (_("immediate out of range"));
037e8744 20364 break;
5f4273c7 20365
9db2f6b4 20366 case NS_RH:
037e8744
JB
20367 case NS_RF: /* case 12 (fmrs). */
20368 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20369 /* ARMv8.2 fp16 vmov.f16 instruction. */
20370 if (rs == NS_RH)
20371 do_scalar_fp16_v82_encode ();
037e8744 20372 break;
5f4273c7 20373
9db2f6b4 20374 case NS_HR:
037e8744
JB
20375 case NS_FR: /* case 13 (fmsr). */
20376 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20377 /* ARMv8.2 fp16 vmov.f16 instruction. */
20378 if (rs == NS_HR)
20379 do_scalar_fp16_v82_encode ();
037e8744 20380 break;
5f4273c7 20381
57785aa2
AV
20382 case NS_RRSS:
20383 do_mve_mov (0);
20384 break;
20385 case NS_SSRR:
20386 do_mve_mov (1);
20387 break;
20388
037e8744
JB
20389 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20390 (one of which is a list), but we have parsed four. Do some fiddling to
20391 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20392 expect. */
20393 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20394 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20395 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20396 _(BAD_FPU));
037e8744 20397 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20398 _("VFP registers must be adjacent"));
037e8744
JB
20399 inst.operands[2].imm = 2;
20400 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20401 do_vfp_nsyn_opcode ("fmrrs");
20402 break;
5f4273c7 20403
037e8744 20404 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20405 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20406 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20407 _(BAD_FPU));
037e8744 20408 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20409 _("VFP registers must be adjacent"));
037e8744
JB
20410 inst.operands[1] = inst.operands[2];
20411 inst.operands[2] = inst.operands[3];
20412 inst.operands[0].imm = 2;
20413 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20414 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20415 break;
5f4273c7 20416
4c261dff
NC
20417 case NS_NULL:
20418 /* neon_select_shape has determined that the instruction
20419 shape is wrong and has already set the error message. */
20420 break;
20421
5287ad62
JB
20422 default:
20423 abort ();
20424 }
20425}
20426
57785aa2
AV
20427static void
20428do_mve_movl (void)
20429{
20430 if (!(inst.operands[0].present && inst.operands[0].isquad
20431 && inst.operands[1].present && inst.operands[1].isquad
20432 && !inst.operands[2].present))
20433 {
20434 inst.instruction = 0;
20435 inst.cond = 0xb;
20436 if (thumb_mode)
20437 set_pred_insn_type (INSIDE_IT_INSN);
20438 do_neon_mov ();
20439 return;
20440 }
20441
20442 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20443 return;
20444
20445 if (inst.cond != COND_ALWAYS)
20446 inst.pred_insn_type = INSIDE_VPT_INSN;
20447
20448 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20449 | N_S16 | N_U16 | N_KEY);
20450
20451 inst.instruction |= (et.type == NT_unsigned) << 28;
20452 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20453 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20454 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20455 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20456 inst.instruction |= LOW4 (inst.operands[1].reg);
20457 inst.is_neon = 1;
20458}
20459
5287ad62
JB
20460static void
20461do_neon_rshift_round_imm (void)
20462{
64c350f2 20463 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20464 return;
20465
20466 enum neon_shape rs;
20467 struct neon_type_el et;
20468
20469 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20470 {
20471 rs = neon_select_shape (NS_QQI, NS_NULL);
20472 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20473 }
20474 else
20475 {
20476 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20477 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20478 }
5287ad62
JB
20479 int imm = inst.operands[2].imm;
20480
20481 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20482 if (imm == 0)
20483 {
20484 inst.operands[2].present = 0;
20485 do_neon_mov ();
20486 return;
20487 }
20488
20489 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20490 _("immediate out of range for shift"));
037e8744 20491 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20492 et.size - imm);
5287ad62
JB
20493}
20494
9db2f6b4
RL
20495static void
20496do_neon_movhf (void)
20497{
20498 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20499 constraint (rs != NS_HH, _("invalid suffix"));
20500
7bdf778b
ASDV
20501 if (inst.cond != COND_ALWAYS)
20502 {
20503 if (thumb_mode)
20504 {
20505 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20506 " the behaviour is UNPREDICTABLE"));
20507 }
20508 else
20509 {
20510 inst.error = BAD_COND;
20511 return;
20512 }
20513 }
20514
9db2f6b4
RL
20515 do_vfp_sp_monadic ();
20516
20517 inst.is_neon = 1;
20518 inst.instruction |= 0xf0000000;
20519}
20520
5287ad62
JB
20521static void
20522do_neon_movl (void)
20523{
20524 struct neon_type_el et = neon_check_type (2, NS_QD,
20525 N_EQK | N_DBL, N_SU_32 | N_KEY);
20526 unsigned sizebits = et.size >> 3;
20527 inst.instruction |= sizebits << 19;
20528 neon_two_same (0, et.type == NT_unsigned, -1);
20529}
20530
20531static void
20532do_neon_trn (void)
20533{
037e8744 20534 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20535 struct neon_type_el et = neon_check_type (2, rs,
20536 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20537 NEON_ENCODE (INTEGER, inst);
037e8744 20538 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20539}
20540
20541static void
20542do_neon_zip_uzp (void)
20543{
037e8744 20544 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20545 struct neon_type_el et = neon_check_type (2, rs,
20546 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20547 if (rs == NS_DD && et.size == 32)
20548 {
20549 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20550 inst.instruction = N_MNEM_vtrn;
20551 do_neon_trn ();
20552 return;
20553 }
037e8744 20554 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20555}
20556
20557static void
20558do_neon_sat_abs_neg (void)
20559{
64c350f2 20560 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20561 return;
20562
20563 enum neon_shape rs;
20564 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20565 rs = neon_select_shape (NS_QQ, NS_NULL);
20566 else
20567 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20568 struct neon_type_el et = neon_check_type (2, rs,
20569 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20570 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20571}
20572
20573static void
20574do_neon_pair_long (void)
20575{
037e8744 20576 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20577 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20578 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20579 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20580 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20581}
20582
20583static void
20584do_neon_recip_est (void)
20585{
037e8744 20586 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20587 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20588 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20589 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20590 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20591}
20592
20593static void
20594do_neon_cls (void)
20595{
64c350f2 20596 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20597 return;
20598
20599 enum neon_shape rs;
20600 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20601 rs = neon_select_shape (NS_QQ, NS_NULL);
20602 else
20603 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20604
5287ad62
JB
20605 struct neon_type_el et = neon_check_type (2, rs,
20606 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20607 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20608}
20609
20610static void
20611do_neon_clz (void)
20612{
64c350f2 20613 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20614 return;
20615
20616 enum neon_shape rs;
20617 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20618 rs = neon_select_shape (NS_QQ, NS_NULL);
20619 else
20620 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20621
5287ad62
JB
20622 struct neon_type_el et = neon_check_type (2, rs,
20623 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20624 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20625}
20626
20627static void
20628do_neon_cnt (void)
20629{
037e8744 20630 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20631 struct neon_type_el et = neon_check_type (2, rs,
20632 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20633 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20634}
20635
20636static void
20637do_neon_swp (void)
20638{
037e8744 20639 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
250dd99f
AM
20640 if (rs == NS_NULL)
20641 return;
037e8744 20642 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20643}
20644
20645static void
20646do_neon_tbl_tbx (void)
20647{
20648 unsigned listlenbits;
dcbf9037 20649 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20650
5287ad62
JB
20651 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20652 {
dcbf9037 20653 first_error (_("bad list length for table lookup"));
5287ad62
JB
20654 return;
20655 }
5f4273c7 20656
5287ad62
JB
20657 listlenbits = inst.operands[1].imm - 1;
20658 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20659 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20660 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20661 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20662 inst.instruction |= LOW4 (inst.operands[2].reg);
20663 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20664 inst.instruction |= listlenbits << 8;
5f4273c7 20665
88714cb8 20666 neon_dp_fixup (&inst);
5287ad62
JB
20667}
20668
20669static void
20670do_neon_ldm_stm (void)
20671{
ef8f595f
MI
20672 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20673 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20674 _(BAD_FPU));
5287ad62
JB
20675 /* P, U and L bits are part of bitmask. */
20676 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20677 unsigned offsetbits = inst.operands[1].imm * 2;
20678
037e8744
JB
20679 if (inst.operands[1].issingle)
20680 {
20681 do_vfp_nsyn_ldm_stm (is_dbmode);
20682 return;
20683 }
20684
5287ad62 20685 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20686 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20687
20688 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20689 _("register list must contain at least 1 and at most 16 "
20690 "registers"));
5287ad62
JB
20691
20692 inst.instruction |= inst.operands[0].reg << 16;
20693 inst.instruction |= inst.operands[0].writeback << 21;
20694 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20695 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20696
20697 inst.instruction |= offsetbits;
5f4273c7 20698
037e8744 20699 do_vfp_cond_or_thumb ();
5287ad62
JB
20700}
20701
ef8f595f
MI
20702static void
20703do_vfp_nsyn_pop (void)
20704{
20705 nsyn_insert_sp ();
20706 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20707 return do_vfp_nsyn_opcode ("vldm");
20708 }
20709
20710 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20711 _(BAD_FPU));
20712
20713 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20714 _("register list must contain at least 1 and at most 16 "
20715 "registers"));
20716
20717 if (inst.operands[1].issingle)
20718 do_vfp_nsyn_opcode ("fldmias");
20719 else
20720 do_vfp_nsyn_opcode ("fldmiad");
20721}
20722
20723static void
20724do_vfp_nsyn_push (void)
20725{
20726 nsyn_insert_sp ();
20727 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20728 return do_vfp_nsyn_opcode ("vstmdb");
20729 }
20730
20731 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20732 _(BAD_FPU));
20733
20734 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20735 _("register list must contain at least 1 and at most 16 "
20736 "registers"));
20737
20738 if (inst.operands[1].issingle)
20739 do_vfp_nsyn_opcode ("fstmdbs");
20740 else
20741 do_vfp_nsyn_opcode ("fstmdbd");
20742}
20743
20744
5287ad62
JB
20745static void
20746do_neon_ldr_str (void)
20747{
5287ad62 20748 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20749
6844b2c2
MGD
20750 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20751 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20752 if (!is_ldr
6844b2c2 20753 && inst.operands[1].reg == REG_PC
ba86b375 20754 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20755 {
94dcf8bf 20756 if (thumb_mode)
6844b2c2 20757 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20758 else if (warn_on_deprecated)
5c3696f8 20759 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20760 }
20761
037e8744
JB
20762 if (inst.operands[0].issingle)
20763 {
cd2f129f 20764 if (is_ldr)
477330fc 20765 do_vfp_nsyn_opcode ("flds");
cd2f129f 20766 else
477330fc 20767 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20768
20769 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20770 if (inst.vectype.el[0].size == 16)
20771 do_scalar_fp16_v82_encode ();
5287ad62
JB
20772 }
20773 else
5287ad62 20774 {
cd2f129f 20775 if (is_ldr)
477330fc 20776 do_vfp_nsyn_opcode ("fldd");
5287ad62 20777 else
477330fc 20778 do_vfp_nsyn_opcode ("fstd");
5287ad62 20779 }
5287ad62
JB
20780}
20781
32c36c3c
AV
20782static void
20783do_t_vldr_vstr_sysreg (void)
20784{
20785 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20786 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20787
20788 /* Use of PC is UNPREDICTABLE. */
20789 if (inst.operands[1].reg == REG_PC)
20790 inst.error = _("Use of PC here is UNPREDICTABLE");
20791
20792 if (inst.operands[1].immisreg)
20793 inst.error = _("instruction does not accept register index");
20794
20795 if (!inst.operands[1].isreg)
20796 inst.error = _("instruction does not accept PC-relative addressing");
20797
20798 if (abs (inst.operands[1].imm) >= (1 << 7))
20799 inst.error = _("immediate value out of range");
20800
20801 inst.instruction = 0xec000f80;
20802 if (is_vldr)
20803 inst.instruction |= 1 << sysreg_vldr_bitno;
20804 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20805 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20806 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20807}
20808
20809static void
20810do_vldr_vstr (void)
20811{
20812 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20813
20814 /* VLDR/VSTR (System Register). */
20815 if (sysreg_op)
20816 {
20817 if (!mark_feature_used (&arm_ext_v8_1m_main))
20818 as_bad (_("Instruction not permitted on this architecture"));
20819
20820 do_t_vldr_vstr_sysreg ();
20821 }
20822 /* VLDR/VSTR. */
20823 else
20824 {
ef8f595f
MI
20825 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20826 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
32c36c3c
AV
20827 as_bad (_("Instruction not permitted on this architecture"));
20828 do_neon_ldr_str ();
20829 }
20830}
20831
5287ad62
JB
20832/* "interleave" version also handles non-interleaving register VLD1/VST1
20833 instructions. */
20834
20835static void
20836do_neon_ld_st_interleave (void)
20837{
037e8744 20838 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20839 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20840 unsigned alignbits = 0;
20841 unsigned idx;
20842 /* The bits in this table go:
20843 0: register stride of one (0) or two (1)
20844 1,2: register list length, minus one (1, 2, 3, 4).
20845 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20846 We use -1 for invalid entries. */
20847 const int typetable[] =
20848 {
20849 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20850 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20851 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20852 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20853 };
20854 int typebits;
20855
dcbf9037
JB
20856 if (et.type == NT_invtype)
20857 return;
20858
5287ad62
JB
20859 if (inst.operands[1].immisalign)
20860 switch (inst.operands[1].imm >> 8)
20861 {
20862 case 64: alignbits = 1; break;
20863 case 128:
477330fc 20864 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20865 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20866 goto bad_alignment;
20867 alignbits = 2;
20868 break;
5287ad62 20869 case 256:
477330fc
RM
20870 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20871 goto bad_alignment;
20872 alignbits = 3;
20873 break;
5287ad62
JB
20874 default:
20875 bad_alignment:
477330fc
RM
20876 first_error (_("bad alignment"));
20877 return;
5287ad62
JB
20878 }
20879
20880 inst.instruction |= alignbits << 4;
20881 inst.instruction |= neon_logbits (et.size) << 6;
20882
20883 /* Bits [4:6] of the immediate in a list specifier encode register stride
20884 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20885 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20886 up the right value for "type" in a table based on this value and the given
20887 list style, then stick it back. */
20888 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20889 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20890
20891 typebits = typetable[idx];
5f4273c7 20892
5287ad62 20893 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20894 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20895 BAD_EL_TYPE);
5287ad62
JB
20896
20897 inst.instruction &= ~0xf00;
20898 inst.instruction |= typebits << 8;
20899}
20900
20901/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20902 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20903 otherwise. The variable arguments are a list of pairs of legal (size, align)
20904 values, terminated with -1. */
20905
20906static int
aa8a0863 20907neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20908{
20909 va_list ap;
20910 int result = FAIL, thissize, thisalign;
5f4273c7 20911
5287ad62
JB
20912 if (!inst.operands[1].immisalign)
20913 {
aa8a0863 20914 *do_alignment = 0;
5287ad62
JB
20915 return SUCCESS;
20916 }
5f4273c7 20917
aa8a0863 20918 va_start (ap, do_alignment);
5287ad62
JB
20919
20920 do
20921 {
20922 thissize = va_arg (ap, int);
20923 if (thissize == -1)
477330fc 20924 break;
5287ad62
JB
20925 thisalign = va_arg (ap, int);
20926
20927 if (size == thissize && align == thisalign)
477330fc 20928 result = SUCCESS;
5287ad62
JB
20929 }
20930 while (result != SUCCESS);
20931
20932 va_end (ap);
20933
20934 if (result == SUCCESS)
aa8a0863 20935 *do_alignment = 1;
5287ad62 20936 else
dcbf9037 20937 first_error (_("unsupported alignment for instruction"));
5f4273c7 20938
5287ad62
JB
20939 return result;
20940}
20941
20942static void
20943do_neon_ld_st_lane (void)
20944{
037e8744 20945 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20946 int align_good, do_alignment = 0;
5287ad62
JB
20947 int logsize = neon_logbits (et.size);
20948 int align = inst.operands[1].imm >> 8;
20949 int n = (inst.instruction >> 8) & 3;
20950 int max_el = 64 / et.size;
5f4273c7 20951
dcbf9037
JB
20952 if (et.type == NT_invtype)
20953 return;
5f4273c7 20954
5287ad62 20955 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20956 _("bad list length"));
5287ad62 20957 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20958 _("scalar index out of range"));
5287ad62 20959 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20960 && et.size == 8,
20961 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20962
5287ad62
JB
20963 switch (n)
20964 {
20965 case 0: /* VLD1 / VST1. */
aa8a0863 20966 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20967 32, 32, -1);
5287ad62 20968 if (align_good == FAIL)
477330fc 20969 return;
aa8a0863 20970 if (do_alignment)
477330fc
RM
20971 {
20972 unsigned alignbits = 0;
20973 switch (et.size)
20974 {
20975 case 16: alignbits = 0x1; break;
20976 case 32: alignbits = 0x3; break;
20977 default: ;
20978 }
20979 inst.instruction |= alignbits << 4;
20980 }
5287ad62
JB
20981 break;
20982
20983 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20984 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20985 16, 32, 32, 64, -1);
5287ad62 20986 if (align_good == FAIL)
477330fc 20987 return;
aa8a0863 20988 if (do_alignment)
477330fc 20989 inst.instruction |= 1 << 4;
5287ad62
JB
20990 break;
20991
20992 case 2: /* VLD3 / VST3. */
20993 constraint (inst.operands[1].immisalign,
477330fc 20994 _("can't use alignment with this instruction"));
5287ad62
JB
20995 break;
20996
20997 case 3: /* VLD4 / VST4. */
aa8a0863 20998 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20999 16, 64, 32, 64, 32, 128, -1);
5287ad62 21000 if (align_good == FAIL)
477330fc 21001 return;
aa8a0863 21002 if (do_alignment)
477330fc
RM
21003 {
21004 unsigned alignbits = 0;
21005 switch (et.size)
21006 {
21007 case 8: alignbits = 0x1; break;
21008 case 16: alignbits = 0x1; break;
21009 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21010 default: ;
21011 }
21012 inst.instruction |= alignbits << 4;
21013 }
5287ad62
JB
21014 break;
21015
21016 default: ;
21017 }
21018
21019 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21020 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21021 inst.instruction |= 1 << (4 + logsize);
5f4273c7 21022
5287ad62
JB
21023 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21024 inst.instruction |= logsize << 10;
21025}
21026
21027/* Encode single n-element structure to all lanes VLD<n> instructions. */
21028
21029static void
21030do_neon_ld_dup (void)
21031{
037e8744 21032 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 21033 int align_good, do_alignment = 0;
5287ad62 21034
dcbf9037
JB
21035 if (et.type == NT_invtype)
21036 return;
21037
5287ad62
JB
21038 switch ((inst.instruction >> 8) & 3)
21039 {
21040 case 0: /* VLD1. */
9c2799c2 21041 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 21042 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 21043 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 21044 if (align_good == FAIL)
477330fc 21045 return;
5287ad62 21046 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
21047 {
21048 case 1: break;
21049 case 2: inst.instruction |= 1 << 5; break;
21050 default: first_error (_("bad list length")); return;
21051 }
5287ad62
JB
21052 inst.instruction |= neon_logbits (et.size) << 6;
21053 break;
21054
21055 case 1: /* VLD2. */
21056 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
21057 &do_alignment, 8, 16, 16, 32, 32, 64,
21058 -1);
5287ad62 21059 if (align_good == FAIL)
477330fc 21060 return;
5287ad62 21061 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 21062 _("bad list length"));
5287ad62 21063 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21064 inst.instruction |= 1 << 5;
5287ad62
JB
21065 inst.instruction |= neon_logbits (et.size) << 6;
21066 break;
21067
21068 case 2: /* VLD3. */
21069 constraint (inst.operands[1].immisalign,
477330fc 21070 _("can't use alignment with this instruction"));
5287ad62 21071 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 21072 _("bad list length"));
5287ad62 21073 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21074 inst.instruction |= 1 << 5;
5287ad62
JB
21075 inst.instruction |= neon_logbits (et.size) << 6;
21076 break;
21077
21078 case 3: /* VLD4. */
21079 {
477330fc 21080 int align = inst.operands[1].imm >> 8;
aa8a0863 21081 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
21082 16, 64, 32, 64, 32, 128, -1);
21083 if (align_good == FAIL)
21084 return;
21085 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21086 _("bad list length"));
21087 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21088 inst.instruction |= 1 << 5;
21089 if (et.size == 32 && align == 128)
21090 inst.instruction |= 0x3 << 6;
21091 else
21092 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
21093 }
21094 break;
21095
21096 default: ;
21097 }
21098
aa8a0863 21099 inst.instruction |= do_alignment << 4;
5287ad62
JB
21100}
21101
21102/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21103 apart from bits [11:4]. */
21104
21105static void
21106do_neon_ldx_stx (void)
21107{
b1a769ed
DG
21108 if (inst.operands[1].isreg)
21109 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21110
5287ad62
JB
21111 switch (NEON_LANE (inst.operands[0].imm))
21112 {
21113 case NEON_INTERLEAVE_LANES:
88714cb8 21114 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
21115 do_neon_ld_st_interleave ();
21116 break;
5f4273c7 21117
5287ad62 21118 case NEON_ALL_LANES:
88714cb8 21119 NEON_ENCODE (DUP, inst);
2d51fb74
JB
21120 if (inst.instruction == N_INV)
21121 {
21122 first_error ("only loads support such operands");
21123 break;
21124 }
5287ad62
JB
21125 do_neon_ld_dup ();
21126 break;
5f4273c7 21127
5287ad62 21128 default:
88714cb8 21129 NEON_ENCODE (LANE, inst);
5287ad62
JB
21130 do_neon_ld_st_lane ();
21131 }
21132
21133 /* L bit comes from bit mask. */
21134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21135 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21136 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 21137
5287ad62
JB
21138 if (inst.operands[1].postind)
21139 {
21140 int postreg = inst.operands[1].imm & 0xf;
21141 constraint (!inst.operands[1].immisreg,
477330fc 21142 _("post-index must be a register"));
5287ad62 21143 constraint (postreg == 0xd || postreg == 0xf,
477330fc 21144 _("bad register for post-index"));
5287ad62
JB
21145 inst.instruction |= postreg;
21146 }
4f2374c7 21147 else
5287ad62 21148 {
4f2374c7 21149 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
21150 constraint (inst.relocs[0].exp.X_op != O_constant
21151 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
21152 BAD_ADDR_MODE);
21153
21154 if (inst.operands[1].writeback)
21155 {
21156 inst.instruction |= 0xd;
21157 }
21158 else
21159 inst.instruction |= 0xf;
5287ad62 21160 }
5f4273c7 21161
5287ad62
JB
21162 if (thumb_mode)
21163 inst.instruction |= 0xf9000000;
21164 else
21165 inst.instruction |= 0xf4000000;
21166}
33399f07
MGD
21167
21168/* FP v8. */
21169static void
21170do_vfp_nsyn_fpv8 (enum neon_shape rs)
21171{
a715796b
TG
21172 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21173 D register operands. */
21174 if (neon_shape_class[rs] == SC_DOUBLE)
21175 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21176 _(BAD_FPU));
21177
33399f07
MGD
21178 NEON_ENCODE (FPV8, inst);
21179
9db2f6b4
RL
21180 if (rs == NS_FFF || rs == NS_HHH)
21181 {
21182 do_vfp_sp_dyadic ();
21183
21184 /* ARMv8.2 fp16 instruction. */
21185 if (rs == NS_HHH)
21186 do_scalar_fp16_v82_encode ();
21187 }
33399f07
MGD
21188 else
21189 do_vfp_dp_rd_rn_rm ();
21190
21191 if (rs == NS_DDD)
21192 inst.instruction |= 0x100;
21193
21194 inst.instruction |= 0xf0000000;
21195}
21196
21197static void
21198do_vsel (void)
21199{
5ee91343 21200 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
21201
21202 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21203 first_error (_("invalid instruction shape"));
21204}
21205
73924fbc
MGD
21206static void
21207do_vmaxnm (void)
21208{
935295b5
AV
21209 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21210 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
21211
21212 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21213 return;
21214
64c350f2 21215 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
21216 return;
21217
cc933301 21218 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
21219}
21220
30bdf752
MGD
21221static void
21222do_vrint_1 (enum neon_cvt_mode mode)
21223{
9db2f6b4 21224 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
21225 struct neon_type_el et;
21226
21227 if (rs == NS_NULL)
21228 return;
21229
a715796b
TG
21230 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21231 D register operands. */
21232 if (neon_shape_class[rs] == SC_DOUBLE)
21233 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21234 _(BAD_FPU));
21235
9db2f6b4
RL
21236 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21237 | N_VFP);
30bdf752
MGD
21238 if (et.type != NT_invtype)
21239 {
21240 /* VFP encodings. */
21241 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21242 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 21243 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
21244
21245 NEON_ENCODE (FPV8, inst);
9db2f6b4 21246 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
21247 do_vfp_sp_monadic ();
21248 else
21249 do_vfp_dp_rd_rm ();
21250
21251 switch (mode)
21252 {
21253 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21254 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21255 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21256 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21257 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21258 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21259 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21260 default: abort ();
21261 }
21262
21263 inst.instruction |= (rs == NS_DD) << 8;
21264 do_vfp_cond_or_thumb ();
9db2f6b4
RL
21265
21266 /* ARMv8.2 fp16 vrint instruction. */
21267 if (rs == NS_HH)
21268 do_scalar_fp16_v82_encode ();
30bdf752
MGD
21269 }
21270 else
21271 {
21272 /* Neon encodings (or something broken...). */
21273 inst.error = NULL;
cc933301 21274 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
21275
21276 if (et.type == NT_invtype)
21277 return;
21278
64c350f2
AV
21279 if (!check_simd_pred_availability (TRUE,
21280 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
21281 return;
21282
a710b305
AV
21283 NEON_ENCODE (FLOAT, inst);
21284
30bdf752
MGD
21285 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21286 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21287 inst.instruction |= LOW4 (inst.operands[1].reg);
21288 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21289 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
21290 /* Mask off the original size bits and reencode them. */
21291 inst.instruction = ((inst.instruction & 0xfff3ffff)
21292 | neon_logbits (et.size) << 18);
21293
30bdf752
MGD
21294 switch (mode)
21295 {
21296 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21297 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21298 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21299 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21300 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21301 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21302 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21303 default: abort ();
21304 }
21305
21306 if (thumb_mode)
21307 inst.instruction |= 0xfc000000;
21308 else
21309 inst.instruction |= 0xf0000000;
21310 }
21311}
21312
21313static void
21314do_vrintx (void)
21315{
21316 do_vrint_1 (neon_cvt_mode_x);
21317}
21318
21319static void
21320do_vrintz (void)
21321{
21322 do_vrint_1 (neon_cvt_mode_z);
21323}
21324
21325static void
21326do_vrintr (void)
21327{
21328 do_vrint_1 (neon_cvt_mode_r);
21329}
21330
21331static void
21332do_vrinta (void)
21333{
21334 do_vrint_1 (neon_cvt_mode_a);
21335}
21336
21337static void
21338do_vrintn (void)
21339{
21340 do_vrint_1 (neon_cvt_mode_n);
21341}
21342
21343static void
21344do_vrintp (void)
21345{
21346 do_vrint_1 (neon_cvt_mode_p);
21347}
21348
21349static void
21350do_vrintm (void)
21351{
21352 do_vrint_1 (neon_cvt_mode_m);
21353}
21354
c28eeff2
SN
21355static unsigned
21356neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21357{
21358 unsigned regno = NEON_SCALAR_REG (opnd);
21359 unsigned elno = NEON_SCALAR_INDEX (opnd);
21360
21361 if (elsize == 16 && elno < 2 && regno < 16)
21362 return regno | (elno << 4);
21363 else if (elsize == 32 && elno == 0)
21364 return regno;
21365
21366 first_error (_("scalar out of range"));
21367 return 0;
21368}
21369
21370static void
21371do_vcmla (void)
21372{
5d281bf0
AV
21373 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21374 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21375 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21376 constraint (inst.relocs[0].exp.X_op != O_constant,
21377 _("expression too complex"));
21378 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21379 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21380 _("immediate out of range"));
21381 rot /= 90;
5d281bf0 21382
64c350f2
AV
21383 if (!check_simd_pred_availability (TRUE,
21384 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21385 return;
21386
c28eeff2
SN
21387 if (inst.operands[2].isscalar)
21388 {
5d281bf0
AV
21389 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21390 first_error (_("invalid instruction shape"));
c28eeff2
SN
21391 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21392 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21393 N_KEY | N_F16 | N_F32).size;
21394 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21395 inst.is_neon = 1;
21396 inst.instruction = 0xfe000800;
21397 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21398 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21399 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21400 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21401 inst.instruction |= LOW4 (m);
21402 inst.instruction |= HI1 (m) << 5;
21403 inst.instruction |= neon_quad (rs) << 6;
21404 inst.instruction |= rot << 20;
21405 inst.instruction |= (size == 32) << 23;
21406 }
21407 else
21408 {
5d281bf0
AV
21409 enum neon_shape rs;
21410 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21411 rs = neon_select_shape (NS_QQQI, NS_NULL);
21412 else
21413 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21414
c28eeff2
SN
21415 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21416 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21417 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21418 && (inst.operands[0].reg == inst.operands[1].reg
21419 || inst.operands[0].reg == inst.operands[2].reg))
21420 as_tsktsk (BAD_MVE_SRCDEST);
21421
c28eeff2
SN
21422 neon_three_same (neon_quad (rs), 0, -1);
21423 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21424 inst.instruction |= 0xfc200800;
21425 inst.instruction |= rot << 23;
21426 inst.instruction |= (size == 32) << 20;
21427 }
21428}
21429
21430static void
21431do_vcadd (void)
21432{
5d281bf0
AV
21433 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21434 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21435 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21436 constraint (inst.relocs[0].exp.X_op != O_constant,
21437 _("expression too complex"));
5d281bf0 21438
e2b0ab59 21439 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21440 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21441 enum neon_shape rs;
21442 struct neon_type_el et;
21443 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21444 {
21445 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21446 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21447 }
21448 else
21449 {
21450 rs = neon_select_shape (NS_QQQI, NS_NULL);
21451 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21452 | N_I16 | N_I32);
21453 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21454 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21455 "operand makes instruction UNPREDICTABLE"));
21456 }
21457
21458 if (et.type == NT_invtype)
21459 return;
21460
64c350f2
AV
21461 if (!check_simd_pred_availability (et.type == NT_float,
21462 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21463 return;
21464
21465 if (et.type == NT_float)
21466 {
21467 neon_three_same (neon_quad (rs), 0, -1);
21468 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21469 inst.instruction |= 0xfc800800;
21470 inst.instruction |= (rot == 270) << 24;
21471 inst.instruction |= (et.size == 32) << 20;
21472 }
21473 else
21474 {
21475 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21476 inst.instruction = 0xfe000f00;
21477 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21478 inst.instruction |= neon_logbits (et.size) << 20;
21479 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21480 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21481 inst.instruction |= (rot == 270) << 12;
21482 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21483 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21484 inst.instruction |= LOW4 (inst.operands[2].reg);
21485 inst.is_neon = 1;
21486 }
c28eeff2
SN
21487}
21488
c604a79a
JW
21489/* Dot Product instructions encoding support. */
21490
21491static void
21492do_neon_dotproduct (int unsigned_p)
21493{
21494 enum neon_shape rs;
21495 unsigned scalar_oprd2 = 0;
21496 int high8;
21497
21498 if (inst.cond != COND_ALWAYS)
21499 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21500 "is UNPREDICTABLE"));
21501
21502 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21503 _(BAD_FPU));
21504
21505 /* Dot Product instructions are in three-same D/Q register format or the third
21506 operand can be a scalar index register. */
21507 if (inst.operands[2].isscalar)
21508 {
21509 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21510 high8 = 0xfe000000;
21511 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21512 }
21513 else
21514 {
21515 high8 = 0xfc000000;
21516 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21517 }
21518
21519 if (unsigned_p)
21520 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21521 else
21522 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21523
21524 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21525 Product instruction, so we pass 0 as the "ubit" parameter. And the
21526 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21527 neon_three_same (neon_quad (rs), 0, 32);
21528
21529 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21530 different NEON three-same encoding. */
21531 inst.instruction &= 0x00ffffff;
21532 inst.instruction |= high8;
21533 /* Encode 'U' bit which indicates signedness. */
21534 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21535 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21536 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21537 the instruction encoding. */
21538 if (inst.operands[2].isscalar)
21539 {
21540 inst.instruction &= 0xffffffd0;
21541 inst.instruction |= LOW4 (scalar_oprd2);
21542 inst.instruction |= HI1 (scalar_oprd2) << 5;
21543 }
21544}
21545
21546/* Dot Product instructions for signed integer. */
21547
21548static void
21549do_neon_dotproduct_s (void)
21550{
21551 return do_neon_dotproduct (0);
21552}
21553
21554/* Dot Product instructions for unsigned integer. */
21555
21556static void
21557do_neon_dotproduct_u (void)
21558{
21559 return do_neon_dotproduct (1);
21560}
21561
616ce08e
MM
21562static void
21563do_vusdot (void)
21564{
21565 enum neon_shape rs;
21566 set_pred_insn_type (OUTSIDE_PRED_INSN);
21567 if (inst.operands[2].isscalar)
21568 {
21569 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21570 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21571
21572 inst.instruction |= (1 << 25);
21573 int index = inst.operands[2].reg & 0xf;
21574 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21575 inst.operands[2].reg >>= 4;
21576 constraint (!(inst.operands[2].reg < 16),
21577 _("indexed register must be less than 16"));
21578 neon_three_args (rs == NS_QQS);
21579 inst.instruction |= (index << 5);
21580 }
21581 else
21582 {
21583 inst.instruction |= (1 << 21);
21584 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21585 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21586 neon_three_args (rs == NS_QQQ);
21587 }
21588}
21589
21590static void
21591do_vsudot (void)
21592{
21593 enum neon_shape rs;
21594 set_pred_insn_type (OUTSIDE_PRED_INSN);
21595 if (inst.operands[2].isscalar)
21596 {
21597 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21598 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21599
21600 inst.instruction |= (1 << 25);
21601 int index = inst.operands[2].reg & 0xf;
21602 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21603 inst.operands[2].reg >>= 4;
21604 constraint (!(inst.operands[2].reg < 16),
21605 _("indexed register must be less than 16"));
21606 neon_three_args (rs == NS_QQS);
21607 inst.instruction |= (index << 5);
21608 }
21609}
21610
21611static void
21612do_vsmmla (void)
21613{
21614 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21615 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21616
21617 set_pred_insn_type (OUTSIDE_PRED_INSN);
21618
21619 neon_three_args (1);
21620
21621}
21622
21623static void
21624do_vummla (void)
21625{
21626 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21627 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21628
21629 set_pred_insn_type (OUTSIDE_PRED_INSN);
21630
21631 neon_three_args (1);
21632
21633}
21634
4934a27c
MM
21635static void
21636check_cde_operand (size_t index, int is_dual)
21637{
21638 unsigned Rx = inst.operands[index].reg;
21639 bfd_boolean isvec = inst.operands[index].isvec;
21640 if (is_dual == 0 && thumb_mode)
21641 constraint (
21642 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21643 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21644 else
21645 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21646 _("Register must be an even register between r0-r10."));
21647}
21648
21649static bfd_boolean
21650cde_coproc_enabled (unsigned coproc)
21651{
21652 switch (coproc)
21653 {
21654 case 0: return mark_feature_used (&arm_ext_cde0);
21655 case 1: return mark_feature_used (&arm_ext_cde1);
21656 case 2: return mark_feature_used (&arm_ext_cde2);
21657 case 3: return mark_feature_used (&arm_ext_cde3);
21658 case 4: return mark_feature_used (&arm_ext_cde4);
21659 case 5: return mark_feature_used (&arm_ext_cde5);
21660 case 6: return mark_feature_used (&arm_ext_cde6);
21661 case 7: return mark_feature_used (&arm_ext_cde7);
21662 default: return FALSE;
21663 }
21664}
21665
21666#define cde_coproc_pos 8
21667static void
21668cde_handle_coproc (void)
21669{
21670 unsigned coproc = inst.operands[0].reg;
21671 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21672 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21673 inst.instruction |= coproc << cde_coproc_pos;
21674}
21675#undef cde_coproc_pos
21676
21677static void
21678cxn_handle_predication (bfd_boolean is_accum)
21679{
cceb53b8
MM
21680 if (is_accum && conditional_insn ())
21681 set_pred_insn_type (INSIDE_IT_INSN);
21682 else if (conditional_insn ())
21683 /* conditional_insn essentially checks for a suffix, not whether the
21684 instruction is inside an IT block or not.
21685 The non-accumulator versions should not have suffixes. */
4934a27c 21686 inst.error = BAD_SYNTAX;
4934a27c
MM
21687 else
21688 set_pred_insn_type (OUTSIDE_PRED_INSN);
21689}
21690
21691static void
21692do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21693{
21694
21695 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21696
21697 unsigned imm, Rd;
21698
21699 Rd = inst.operands[1].reg;
21700 check_cde_operand (1, is_dual);
21701
21702 if (is_dual == 1)
21703 {
21704 constraint (inst.operands[2].reg != Rd + 1,
21705 _("cx1d requires consecutive destination registers."));
21706 imm = inst.operands[3].imm;
21707 }
21708 else if (is_dual == 0)
21709 imm = inst.operands[2].imm;
21710 else
21711 abort ();
21712
21713 inst.instruction |= Rd << 12;
21714 inst.instruction |= (imm & 0x1F80) << 9;
21715 inst.instruction |= (imm & 0x0040) << 1;
21716 inst.instruction |= (imm & 0x003f);
21717
21718 cde_handle_coproc ();
21719 cxn_handle_predication (is_accum);
21720}
21721
21722static void
21723do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21724{
21725
21726 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21727
21728 unsigned imm, Rd, Rn;
21729
21730 Rd = inst.operands[1].reg;
21731
21732 if (is_dual == 1)
21733 {
21734 constraint (inst.operands[2].reg != Rd + 1,
21735 _("cx2d requires consecutive destination registers."));
21736 imm = inst.operands[4].imm;
21737 Rn = inst.operands[3].reg;
21738 }
21739 else if (is_dual == 0)
21740 {
21741 imm = inst.operands[3].imm;
21742 Rn = inst.operands[2].reg;
21743 }
21744 else
21745 abort ();
21746
21747 check_cde_operand (2 + is_dual, /* is_dual = */0);
21748 check_cde_operand (1, is_dual);
21749
21750 inst.instruction |= Rd << 12;
21751 inst.instruction |= Rn << 16;
21752
21753 inst.instruction |= (imm & 0x0380) << 13;
21754 inst.instruction |= (imm & 0x0040) << 1;
21755 inst.instruction |= (imm & 0x003f);
21756
21757 cde_handle_coproc ();
21758 cxn_handle_predication (is_accum);
21759}
21760
21761static void
21762do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21763{
21764
21765 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21766
21767 unsigned imm, Rd, Rn, Rm;
21768
21769 Rd = inst.operands[1].reg;
21770
21771 if (is_dual == 1)
21772 {
21773 constraint (inst.operands[2].reg != Rd + 1,
21774 _("cx3d requires consecutive destination registers."));
21775 imm = inst.operands[5].imm;
21776 Rn = inst.operands[3].reg;
21777 Rm = inst.operands[4].reg;
21778 }
21779 else if (is_dual == 0)
21780 {
21781 imm = inst.operands[4].imm;
21782 Rn = inst.operands[2].reg;
21783 Rm = inst.operands[3].reg;
21784 }
21785 else
21786 abort ();
21787
21788 check_cde_operand (1, is_dual);
21789 check_cde_operand (2 + is_dual, /* is_dual = */0);
21790 check_cde_operand (3 + is_dual, /* is_dual = */0);
21791
21792 inst.instruction |= Rd;
21793 inst.instruction |= Rn << 16;
21794 inst.instruction |= Rm << 12;
21795
21796 inst.instruction |= (imm & 0x0038) << 17;
21797 inst.instruction |= (imm & 0x0004) << 5;
21798 inst.instruction |= (imm & 0x0003) << 4;
21799
21800 cde_handle_coproc ();
21801 cxn_handle_predication (is_accum);
21802}
21803
21804static void
21805do_cx1 (void)
21806{
21807 return do_custom_instruction_1 (0, 0);
21808}
21809
21810static void
21811do_cx1a (void)
21812{
21813 return do_custom_instruction_1 (0, 1);
21814}
21815
21816static void
21817do_cx1d (void)
21818{
21819 return do_custom_instruction_1 (1, 0);
21820}
21821
21822static void
21823do_cx1da (void)
21824{
21825 return do_custom_instruction_1 (1, 1);
21826}
21827
21828static void
21829do_cx2 (void)
21830{
21831 return do_custom_instruction_2 (0, 0);
21832}
21833
21834static void
21835do_cx2a (void)
21836{
21837 return do_custom_instruction_2 (0, 1);
21838}
21839
21840static void
21841do_cx2d (void)
21842{
21843 return do_custom_instruction_2 (1, 0);
21844}
21845
21846static void
21847do_cx2da (void)
21848{
21849 return do_custom_instruction_2 (1, 1);
21850}
21851
21852static void
21853do_cx3 (void)
21854{
21855 return do_custom_instruction_3 (0, 0);
21856}
21857
21858static void
21859do_cx3a (void)
21860{
21861 return do_custom_instruction_3 (0, 1);
21862}
21863
21864static void
21865do_cx3d (void)
21866{
21867 return do_custom_instruction_3 (1, 0);
21868}
21869
21870static void
21871do_cx3da (void)
21872{
21873 return do_custom_instruction_3 (1, 1);
21874}
21875
5aae9ae9
MM
21876static void
21877vcx_assign_vec_d (unsigned regnum)
21878{
21879 inst.instruction |= HI4 (regnum) << 12;
21880 inst.instruction |= LOW1 (regnum) << 22;
21881}
21882
21883static void
21884vcx_assign_vec_m (unsigned regnum)
21885{
21886 inst.instruction |= HI4 (regnum);
21887 inst.instruction |= LOW1 (regnum) << 5;
21888}
21889
21890static void
21891vcx_assign_vec_n (unsigned regnum)
21892{
21893 inst.instruction |= HI4 (regnum) << 16;
21894 inst.instruction |= LOW1 (regnum) << 7;
21895}
21896
21897enum vcx_reg_type {
21898 q_reg,
21899 d_reg,
21900 s_reg
21901};
21902
21903static enum vcx_reg_type
21904vcx_get_reg_type (enum neon_shape ns)
21905{
21906 gas_assert (ns == NS_PQI
21907 || ns == NS_PDI
21908 || ns == NS_PFI
21909 || ns == NS_PQQI
21910 || ns == NS_PDDI
21911 || ns == NS_PFFI
21912 || ns == NS_PQQQI
21913 || ns == NS_PDDDI
21914 || ns == NS_PFFFI);
21915 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21916 return q_reg;
21917 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21918 return d_reg;
21919 return s_reg;
21920}
21921
21922#define vcx_size_pos 24
21923#define vcx_vec_pos 6
21924static unsigned
21925vcx_handle_shape (enum vcx_reg_type reg_type)
21926{
21927 unsigned mult = 2;
21928 if (reg_type == q_reg)
21929 inst.instruction |= 1 << vcx_vec_pos;
21930 else if (reg_type == d_reg)
21931 inst.instruction |= 1 << vcx_size_pos;
21932 else
21933 mult = 1;
21934 /* NOTE:
21935 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21936 bits (or equivalent for N and M registers).
21937 Similarly the D registers are encoded as N in D:Vd bits.
21938 While the S registers are encoded as N in the Vd:D bits.
21939
21940 Taking into account the maximum values of these registers we can see a
21941 nicer pattern for calculation:
21942 Q -> 7, D -> 15, S -> 31
21943
21944 If we say that everything is encoded in the Vd:D bits, then we can say
21945 that Q is encoded as 4*N, and D is encoded as 2*N.
21946 This way the bits will end up the same, and calculation is simpler.
21947 (calculation is now:
21948 1. Multiply by a number determined by the register letter.
21949 2. Encode resulting number in Vd:D bits.)
21950
21951 This is made a little more complicated by automatic handling of 'Q'
21952 registers elsewhere, which means the register number is already 2*N where
21953 N is the number the user wrote after the register letter.
21954 */
21955 return mult;
21956}
21957#undef vcx_vec_pos
21958#undef vcx_size_pos
21959
21960static void
21961vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21962{
21963 if (reg_type == q_reg)
21964 {
21965 gas_assert (R % 2 == 0);
21966 constraint (R >= 16, _("'q' register must be in range 0-7"));
21967 }
21968 else if (reg_type == d_reg)
21969 constraint (R >= 16, _("'d' register must be in range 0-15"));
21970 else
21971 constraint (R >= 32, _("'s' register must be in range 0-31"));
21972}
21973
21974static void (*vcx_assign_vec[3]) (unsigned) = {
21975 vcx_assign_vec_d,
21976 vcx_assign_vec_m,
21977 vcx_assign_vec_n
21978};
21979
21980static void
21981vcx_handle_register_arguments (unsigned num_registers,
21982 enum vcx_reg_type reg_type)
21983{
1ed818b4 21984 unsigned R, i;
5aae9ae9 21985 unsigned reg_mult = vcx_handle_shape (reg_type);
1ed818b4 21986 for (i = 0; i < num_registers; i++)
5aae9ae9
MM
21987 {
21988 R = inst.operands[i+1].reg;
21989 vcx_ensure_register_in_range (R, reg_type);
21990 if (num_registers == 3 && i > 0)
21991 {
21992 if (i == 2)
21993 vcx_assign_vec[1] (R * reg_mult);
21994 else
21995 vcx_assign_vec[2] (R * reg_mult);
21996 continue;
21997 }
21998 vcx_assign_vec[i](R * reg_mult);
21999 }
22000}
22001
22002static void
22003vcx_handle_insn_block (enum vcx_reg_type reg_type)
22004{
22005 if (reg_type == q_reg)
22006 if (inst.cond > COND_ALWAYS)
22007 inst.pred_insn_type = INSIDE_VPT_INSN;
22008 else
22009 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22010 else if (inst.cond == COND_ALWAYS)
22011 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22012 else
22013 inst.error = BAD_NOT_IT;
22014}
22015
22016static void
22017vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22018{
22019 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22020 cde_handle_coproc ();
22021 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22022 vcx_handle_register_arguments (num_args, reg_type);
22023 vcx_handle_insn_block (reg_type);
22024 if (reg_type == q_reg)
22025 constraint (!mark_feature_used (&mve_ext),
22026 _("vcx instructions with Q registers require MVE"));
22027 else
22028 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22029 && mark_feature_used (&armv8m_fp))
22030 && !mark_feature_used (&mve_ext),
22031 _("vcx instructions with S or D registers require either MVE"
ddc73fa9 22032 " or Armv8-M floating point extension."));
5aae9ae9
MM
22033}
22034
22035static void
22036do_vcx1 (void)
22037{
22038 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22039 vcx_handle_common_checks (1, rs);
22040
22041 unsigned imm = inst.operands[2].imm;
22042 inst.instruction |= (imm & 0x03f);
22043 inst.instruction |= (imm & 0x040) << 1;
22044 inst.instruction |= (imm & 0x780) << 9;
22045 if (rs != NS_PQI)
22046 constraint (imm >= 2048,
22047 _("vcx1 with S or D registers takes immediate within 0-2047"));
22048 inst.instruction |= (imm & 0x800) << 13;
22049}
22050
22051static void
22052do_vcx2 (void)
22053{
22054 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22055 vcx_handle_common_checks (2, rs);
22056
22057 unsigned imm = inst.operands[3].imm;
22058 inst.instruction |= (imm & 0x01) << 4;
22059 inst.instruction |= (imm & 0x02) << 6;
22060 inst.instruction |= (imm & 0x3c) << 14;
22061 if (rs != NS_PQQI)
22062 constraint (imm >= 64,
22063 _("vcx2 with S or D registers takes immediate within 0-63"));
22064 inst.instruction |= (imm & 0x40) << 18;
22065}
22066
22067static void
22068do_vcx3 (void)
22069{
22070 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22071 vcx_handle_common_checks (3, rs);
22072
22073 unsigned imm = inst.operands[4].imm;
22074 inst.instruction |= (imm & 0x1) << 4;
22075 inst.instruction |= (imm & 0x6) << 19;
22076 if (rs != NS_PQQQI)
22077 constraint (imm >= 8,
22078 _("vcx2 with S or D registers takes immediate within 0-7"));
22079 inst.instruction |= (imm & 0x8) << 21;
22080}
22081
91ff7894
MGD
22082/* Crypto v1 instructions. */
22083static void
22084do_crypto_2op_1 (unsigned elttype, int op)
22085{
5ee91343 22086 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
22087
22088 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22089 == NT_invtype)
22090 return;
22091
22092 inst.error = NULL;
22093
22094 NEON_ENCODE (INTEGER, inst);
22095 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22096 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22097 inst.instruction |= LOW4 (inst.operands[1].reg);
22098 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22099 if (op != -1)
22100 inst.instruction |= op << 6;
22101
22102 if (thumb_mode)
22103 inst.instruction |= 0xfc000000;
22104 else
22105 inst.instruction |= 0xf0000000;
22106}
22107
48adcd8e
MGD
22108static void
22109do_crypto_3op_1 (int u, int op)
22110{
5ee91343 22111 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
22112
22113 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22114 N_32 | N_UNT | N_KEY).type == NT_invtype)
22115 return;
22116
22117 inst.error = NULL;
22118
22119 NEON_ENCODE (INTEGER, inst);
22120 neon_three_same (1, u, 8 << op);
22121}
22122
91ff7894
MGD
22123static void
22124do_aese (void)
22125{
22126 do_crypto_2op_1 (N_8, 0);
22127}
22128
22129static void
22130do_aesd (void)
22131{
22132 do_crypto_2op_1 (N_8, 1);
22133}
22134
22135static void
22136do_aesmc (void)
22137{
22138 do_crypto_2op_1 (N_8, 2);
22139}
22140
22141static void
22142do_aesimc (void)
22143{
22144 do_crypto_2op_1 (N_8, 3);
22145}
22146
48adcd8e
MGD
22147static void
22148do_sha1c (void)
22149{
22150 do_crypto_3op_1 (0, 0);
22151}
22152
22153static void
22154do_sha1p (void)
22155{
22156 do_crypto_3op_1 (0, 1);
22157}
22158
22159static void
22160do_sha1m (void)
22161{
22162 do_crypto_3op_1 (0, 2);
22163}
22164
22165static void
22166do_sha1su0 (void)
22167{
22168 do_crypto_3op_1 (0, 3);
22169}
91ff7894 22170
48adcd8e
MGD
22171static void
22172do_sha256h (void)
22173{
22174 do_crypto_3op_1 (1, 0);
22175}
22176
22177static void
22178do_sha256h2 (void)
22179{
22180 do_crypto_3op_1 (1, 1);
22181}
22182
22183static void
22184do_sha256su1 (void)
22185{
22186 do_crypto_3op_1 (1, 2);
22187}
3c9017d2
MGD
22188
22189static void
22190do_sha1h (void)
22191{
22192 do_crypto_2op_1 (N_32, -1);
22193}
22194
22195static void
22196do_sha1su1 (void)
22197{
22198 do_crypto_2op_1 (N_32, 0);
22199}
22200
22201static void
22202do_sha256su0 (void)
22203{
22204 do_crypto_2op_1 (N_32, 1);
22205}
dd5181d5
KT
22206
22207static void
22208do_crc32_1 (unsigned int poly, unsigned int sz)
22209{
22210 unsigned int Rd = inst.operands[0].reg;
22211 unsigned int Rn = inst.operands[1].reg;
22212 unsigned int Rm = inst.operands[2].reg;
22213
5ee91343 22214 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
22215 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22216 inst.instruction |= LOW4 (Rn) << 16;
22217 inst.instruction |= LOW4 (Rm);
22218 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22219 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22220
22221 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22222 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
22223}
22224
22225static void
22226do_crc32b (void)
22227{
22228 do_crc32_1 (0, 0);
22229}
22230
22231static void
22232do_crc32h (void)
22233{
22234 do_crc32_1 (0, 1);
22235}
22236
22237static void
22238do_crc32w (void)
22239{
22240 do_crc32_1 (0, 2);
22241}
22242
22243static void
22244do_crc32cb (void)
22245{
22246 do_crc32_1 (1, 0);
22247}
22248
22249static void
22250do_crc32ch (void)
22251{
22252 do_crc32_1 (1, 1);
22253}
22254
22255static void
22256do_crc32cw (void)
22257{
22258 do_crc32_1 (1, 2);
22259}
22260
49e8a725
SN
22261static void
22262do_vjcvt (void)
22263{
22264 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22265 _(BAD_FPU));
22266 neon_check_type (2, NS_FD, N_S32, N_F64);
22267 do_vfp_sp_dp_cvt ();
22268 do_vfp_cond_or_thumb ();
22269}
22270
aab2c27d
MM
22271static void
22272do_vdot (void)
22273{
22274 enum neon_shape rs;
22275 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22276 set_pred_insn_type (OUTSIDE_PRED_INSN);
22277 if (inst.operands[2].isscalar)
22278 {
22279 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22280 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22281
22282 inst.instruction |= (1 << 25);
22283 int index = inst.operands[2].reg & 0xf;
22284 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22285 inst.operands[2].reg >>= 4;
22286 constraint (!(inst.operands[2].reg < 16),
22287 _("indexed register must be less than 16"));
22288 neon_three_args (rs == NS_QQS);
22289 inst.instruction |= (index << 5);
22290 }
22291 else
22292 {
22293 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22294 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22295 neon_three_args (rs == NS_QQQ);
22296 }
22297}
22298
22299static void
22300do_vmmla (void)
22301{
22302 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22303 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22304
22305 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22306 set_pred_insn_type (OUTSIDE_PRED_INSN);
22307
22308 neon_three_args (1);
22309}
22310
5287ad62
JB
22311\f
22312/* Overall per-instruction processing. */
22313
22314/* We need to be able to fix up arbitrary expressions in some statements.
22315 This is so that we can handle symbols that are an arbitrary distance from
22316 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22317 which returns part of an address in a form which will be valid for
22318 a data instruction. We do this by pushing the expression into a symbol
22319 in the expr_section, and creating a fix for that. */
22320
22321static void
22322fix_new_arm (fragS * frag,
22323 int where,
22324 short int size,
22325 expressionS * exp,
22326 int pc_rel,
22327 int reloc)
22328{
22329 fixS * new_fix;
22330
22331 switch (exp->X_op)
22332 {
22333 case O_constant:
6e7ce2cd
PB
22334 if (pc_rel)
22335 {
22336 /* Create an absolute valued symbol, so we have something to
477330fc
RM
22337 refer to in the object file. Unfortunately for us, gas's
22338 generic expression parsing will already have folded out
22339 any use of .set foo/.type foo %function that may have
22340 been used to set type information of the target location,
22341 that's being specified symbolically. We have to presume
22342 the user knows what they are doing. */
6e7ce2cd
PB
22343 char name[16 + 8];
22344 symbolS *symbol;
22345
22346 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22347
22348 symbol = symbol_find_or_make (name);
22349 S_SET_SEGMENT (symbol, absolute_section);
22350 symbol_set_frag (symbol, &zero_address_frag);
22351 S_SET_VALUE (symbol, exp->X_add_number);
22352 exp->X_op = O_symbol;
22353 exp->X_add_symbol = symbol;
22354 exp->X_add_number = 0;
22355 }
22356 /* FALLTHROUGH */
5287ad62
JB
22357 case O_symbol:
22358 case O_add:
22359 case O_subtract:
21d799b5 22360 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 22361 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22362 break;
22363
22364 default:
21d799b5 22365 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 22366 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22367 break;
22368 }
22369
22370 /* Mark whether the fix is to a THUMB instruction, or an ARM
22371 instruction. */
22372 new_fix->tc_fix_data = thumb_mode;
22373}
22374
22375/* Create a frg for an instruction requiring relaxation. */
22376static void
22377output_relax_insn (void)
22378{
22379 char * to;
22380 symbolS *sym;
0110f2b8
PB
22381 int offset;
22382
6e1cb1a6
PB
22383 /* The size of the instruction is unknown, so tie the debug info to the
22384 start of the instruction. */
22385 dwarf2_emit_insn (0);
6e1cb1a6 22386
e2b0ab59 22387 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
22388 {
22389 case O_symbol:
e2b0ab59
AV
22390 sym = inst.relocs[0].exp.X_add_symbol;
22391 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22392 break;
22393 case O_constant:
22394 sym = NULL;
e2b0ab59 22395 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22396 break;
22397 default:
e2b0ab59 22398 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
22399 offset = 0;
22400 break;
22401 }
22402 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22403 inst.relax, sym, offset, NULL/*offset, opcode*/);
22404 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
22405}
22406
22407/* Write a 32-bit thumb instruction to buf. */
22408static void
22409put_thumb32_insn (char * buf, unsigned long insn)
22410{
22411 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22412 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22413}
22414
b99bd4ef 22415static void
c19d1205 22416output_inst (const char * str)
b99bd4ef 22417{
c19d1205 22418 char * to = NULL;
b99bd4ef 22419
c19d1205 22420 if (inst.error)
b99bd4ef 22421 {
c19d1205 22422 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
22423 return;
22424 }
5f4273c7
NC
22425 if (inst.relax)
22426 {
22427 output_relax_insn ();
0110f2b8 22428 return;
5f4273c7 22429 }
c19d1205
ZW
22430 if (inst.size == 0)
22431 return;
b99bd4ef 22432
c19d1205 22433 to = frag_more (inst.size);
8dc2430f
NC
22434 /* PR 9814: Record the thumb mode into the current frag so that we know
22435 what type of NOP padding to use, if necessary. We override any previous
22436 setting so that if the mode has changed then the NOPS that we use will
22437 match the encoding of the last instruction in the frag. */
cd000bff 22438 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
22439
22440 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 22441 {
9c2799c2 22442 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 22443 put_thumb32_insn (to, inst.instruction);
b99bd4ef 22444 }
c19d1205 22445 else if (inst.size > INSN_SIZE)
b99bd4ef 22446 {
9c2799c2 22447 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
22448 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22449 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 22450 }
c19d1205
ZW
22451 else
22452 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 22453
e2b0ab59
AV
22454 int r;
22455 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22456 {
22457 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22458 fix_new_arm (frag_now, to - frag_now->fr_literal,
22459 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22460 inst.relocs[r].type);
22461 }
b99bd4ef 22462
c19d1205 22463 dwarf2_emit_insn (inst.size);
c19d1205 22464}
b99bd4ef 22465
e07e6e58
NC
22466static char *
22467output_it_inst (int cond, int mask, char * to)
22468{
22469 unsigned long instruction = 0xbf00;
22470
22471 mask &= 0xf;
22472 instruction |= mask;
22473 instruction |= cond << 4;
22474
22475 if (to == NULL)
22476 {
22477 to = frag_more (2);
22478#ifdef OBJ_ELF
22479 dwarf2_emit_insn (2);
22480#endif
22481 }
22482
22483 md_number_to_chars (to, instruction, 2);
22484
22485 return to;
22486}
22487
c19d1205
ZW
22488/* Tag values used in struct asm_opcode's tag field. */
22489enum opcode_tag
22490{
22491 OT_unconditional, /* Instruction cannot be conditionalized.
22492 The ARM condition field is still 0xE. */
22493 OT_unconditionalF, /* Instruction cannot be conditionalized
22494 and carries 0xF in its ARM condition field. */
22495 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
22496 OT_csuffixF, /* Some forms of the instruction take a scalar
22497 conditional suffix, others place 0xF where the
22498 condition field would be, others take a vector
22499 conditional suffix. */
c19d1205
ZW
22500 OT_cinfix3, /* Instruction takes a conditional infix,
22501 beginning at character index 3. (In
22502 unified mode, it becomes a suffix.) */
088fa78e
KH
22503 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22504 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
22505 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22506 character index 3, even in unified mode. Used for
22507 legacy instructions where suffix and infix forms
22508 may be ambiguous. */
c19d1205 22509 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 22510 suffix or an infix at character index 3. */
c19d1205
ZW
22511 OT_odd_infix_unc, /* This is the unconditional variant of an
22512 instruction that takes a conditional infix
22513 at an unusual position. In unified mode,
22514 this variant will accept a suffix. */
22515 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22516 are the conditional variants of instructions that
22517 take conditional infixes in unusual positions.
22518 The infix appears at character index
22519 (tag - OT_odd_infix_0). These are not accepted
22520 in unified mode. */
22521};
b99bd4ef 22522
c19d1205
ZW
22523/* Subroutine of md_assemble, responsible for looking up the primary
22524 opcode from the mnemonic the user wrote. STR points to the
22525 beginning of the mnemonic.
22526
22527 This is not simply a hash table lookup, because of conditional
22528 variants. Most instructions have conditional variants, which are
22529 expressed with a _conditional affix_ to the mnemonic. If we were
22530 to encode each conditional variant as a literal string in the opcode
22531 table, it would have approximately 20,000 entries.
22532
22533 Most mnemonics take this affix as a suffix, and in unified syntax,
22534 'most' is upgraded to 'all'. However, in the divided syntax, some
22535 instructions take the affix as an infix, notably the s-variants of
22536 the arithmetic instructions. Of those instructions, all but six
22537 have the infix appear after the third character of the mnemonic.
22538
22539 Accordingly, the algorithm for looking up primary opcodes given
22540 an identifier is:
22541
22542 1. Look up the identifier in the opcode table.
22543 If we find a match, go to step U.
22544
22545 2. Look up the last two characters of the identifier in the
22546 conditions table. If we find a match, look up the first N-2
22547 characters of the identifier in the opcode table. If we
22548 find a match, go to step CE.
22549
22550 3. Look up the fourth and fifth characters of the identifier in
22551 the conditions table. If we find a match, extract those
22552 characters from the identifier, and look up the remaining
22553 characters in the opcode table. If we find a match, go
22554 to step CM.
22555
22556 4. Fail.
22557
22558 U. Examine the tag field of the opcode structure, in case this is
22559 one of the six instructions with its conditional infix in an
22560 unusual place. If it is, the tag tells us where to find the
22561 infix; look it up in the conditions table and set inst.cond
22562 accordingly. Otherwise, this is an unconditional instruction.
22563 Again set inst.cond accordingly. Return the opcode structure.
22564
22565 CE. Examine the tag field to make sure this is an instruction that
22566 should receive a conditional suffix. If it is not, fail.
22567 Otherwise, set inst.cond from the suffix we already looked up,
22568 and return the opcode structure.
22569
22570 CM. Examine the tag field to make sure this is an instruction that
22571 should receive a conditional infix after the third character.
22572 If it is not, fail. Otherwise, undo the edits to the current
22573 line of input and proceed as for case CE. */
22574
22575static const struct asm_opcode *
22576opcode_lookup (char **str)
22577{
22578 char *end, *base;
22579 char *affix;
22580 const struct asm_opcode *opcode;
22581 const struct asm_cond *cond;
e3cb604e 22582 char save[2];
c19d1205
ZW
22583
22584 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 22585 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 22586 for (base = end = *str; *end != '\0'; end++)
721a8186 22587 if (*end == ' ' || *end == '.')
c19d1205 22588 break;
b99bd4ef 22589
c19d1205 22590 if (end == base)
c921be7d 22591 return NULL;
b99bd4ef 22592
5287ad62 22593 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 22594 if (end[0] == '.')
b99bd4ef 22595 {
5287ad62 22596 int offset = 2;
5f4273c7 22597
267d2029 22598 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 22599 use. */
267d2029 22600 if (unified_syntax && end[1] == 'w')
c19d1205 22601 inst.size_req = 4;
267d2029 22602 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
22603 inst.size_req = 2;
22604 else
477330fc 22605 offset = 0;
5287ad62
JB
22606
22607 inst.vectype.elems = 0;
22608
22609 *str = end + offset;
b99bd4ef 22610
5f4273c7 22611 if (end[offset] == '.')
5287ad62 22612 {
267d2029 22613 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
22614 non-unified ARM syntax mode). */
22615 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 22616 return NULL;
477330fc 22617 }
5287ad62 22618 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 22619 return NULL;
b99bd4ef 22620 }
c19d1205
ZW
22621 else
22622 *str = end;
b99bd4ef 22623
c19d1205 22624 /* Look for unaffixed or special-case affixed mnemonic. */
629310ab 22625 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22626 end - base);
f3da8a96 22627 cond = NULL;
c19d1205 22628 if (opcode)
b99bd4ef 22629 {
c19d1205
ZW
22630 /* step U */
22631 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 22632 {
c19d1205
ZW
22633 inst.cond = COND_ALWAYS;
22634 return opcode;
b99bd4ef 22635 }
b99bd4ef 22636
278df34e 22637 if (warn_on_deprecated && unified_syntax)
5c3696f8 22638 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 22639 affix = base + (opcode->tag - OT_odd_infix_0);
629310ab 22640 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 22641 gas_assert (cond);
b99bd4ef 22642
c19d1205
ZW
22643 inst.cond = cond->value;
22644 return opcode;
22645 }
5ee91343
AV
22646 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22647 {
22648 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22649 */
22650 if (end - base < 2)
22651 return NULL;
22652 affix = end - 1;
629310ab
ML
22653 cond = (const struct asm_cond *) str_hash_find_n (arm_vcond_hsh, affix, 1);
22654 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22655 affix - base);
5ee91343
AV
22656 /* If this opcode can not be vector predicated then don't accept it with a
22657 vector predication code. */
22658 if (opcode && !opcode->mayBeVecPred)
22659 opcode = NULL;
22660 }
22661 if (!opcode || !cond)
22662 {
22663 /* Cannot have a conditional suffix on a mnemonic of less than two
22664 characters. */
22665 if (end - base < 3)
22666 return NULL;
b99bd4ef 22667
5ee91343
AV
22668 /* Look for suffixed mnemonic. */
22669 affix = end - 2;
629310ab
ML
22670 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22671 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22672 affix - base);
5ee91343 22673 }
b99bd4ef 22674
c19d1205
ZW
22675 if (opcode && cond)
22676 {
22677 /* step CE */
22678 switch (opcode->tag)
22679 {
e3cb604e
PB
22680 case OT_cinfix3_legacy:
22681 /* Ignore conditional suffixes matched on infix only mnemonics. */
22682 break;
22683
c19d1205 22684 case OT_cinfix3:
088fa78e 22685 case OT_cinfix3_deprecated:
c19d1205
ZW
22686 case OT_odd_infix_unc:
22687 if (!unified_syntax)
0198d5e6 22688 return NULL;
1a0670f3 22689 /* Fall through. */
c19d1205
ZW
22690
22691 case OT_csuffix:
477330fc 22692 case OT_csuffixF:
c19d1205
ZW
22693 case OT_csuf_or_in3:
22694 inst.cond = cond->value;
22695 return opcode;
22696
22697 case OT_unconditional:
22698 case OT_unconditionalF:
dfa9f0d5 22699 if (thumb_mode)
c921be7d 22700 inst.cond = cond->value;
dfa9f0d5
PB
22701 else
22702 {
c921be7d 22703 /* Delayed diagnostic. */
dfa9f0d5
PB
22704 inst.error = BAD_COND;
22705 inst.cond = COND_ALWAYS;
22706 }
c19d1205 22707 return opcode;
b99bd4ef 22708
c19d1205 22709 default:
c921be7d 22710 return NULL;
c19d1205
ZW
22711 }
22712 }
b99bd4ef 22713
c19d1205
ZW
22714 /* Cannot have a usual-position infix on a mnemonic of less than
22715 six characters (five would be a suffix). */
22716 if (end - base < 6)
c921be7d 22717 return NULL;
b99bd4ef 22718
c19d1205
ZW
22719 /* Look for infixed mnemonic in the usual position. */
22720 affix = base + 3;
629310ab 22721 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 22722 if (!cond)
c921be7d 22723 return NULL;
e3cb604e
PB
22724
22725 memcpy (save, affix, 2);
22726 memmove (affix, affix + 2, (end - affix) - 2);
629310ab 22727 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22728 (end - base) - 2);
e3cb604e
PB
22729 memmove (affix + 2, affix, (end - affix) - 2);
22730 memcpy (affix, save, 2);
22731
088fa78e
KH
22732 if (opcode
22733 && (opcode->tag == OT_cinfix3
22734 || opcode->tag == OT_cinfix3_deprecated
22735 || opcode->tag == OT_csuf_or_in3
22736 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 22737 {
c921be7d 22738 /* Step CM. */
278df34e 22739 if (warn_on_deprecated && unified_syntax
088fa78e
KH
22740 && (opcode->tag == OT_cinfix3
22741 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 22742 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
22743
22744 inst.cond = cond->value;
22745 return opcode;
b99bd4ef
NC
22746 }
22747
c921be7d 22748 return NULL;
b99bd4ef
NC
22749}
22750
e07e6e58
NC
22751/* This function generates an initial IT instruction, leaving its block
22752 virtually open for the new instructions. Eventually,
5ee91343 22753 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
22754 a new instruction needs to be included in the IT block.
22755 Finally, the block is closed with close_automatic_it_block ().
22756 The block closure can be requested either from md_assemble (),
22757 a tencode (), or due to a label hook. */
22758
22759static void
22760new_automatic_it_block (int cond)
22761{
5ee91343
AV
22762 now_pred.state = AUTOMATIC_PRED_BLOCK;
22763 now_pred.mask = 0x18;
22764 now_pred.cc = cond;
22765 now_pred.block_length = 1;
cd000bff 22766 mapping_state (MAP_THUMB);
5ee91343
AV
22767 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22768 now_pred.warn_deprecated = FALSE;
22769 now_pred.insn_cond = TRUE;
e07e6e58
NC
22770}
22771
22772/* Close an automatic IT block.
22773 See comments in new_automatic_it_block (). */
22774
22775static void
22776close_automatic_it_block (void)
22777{
5ee91343
AV
22778 now_pred.mask = 0x10;
22779 now_pred.block_length = 0;
e07e6e58
NC
22780}
22781
22782/* Update the mask of the current automatically-generated IT
22783 instruction. See comments in new_automatic_it_block (). */
22784
22785static void
5ee91343 22786now_pred_add_mask (int cond)
e07e6e58
NC
22787{
22788#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22789#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 22790 | ((bitvalue) << (nbit)))
e07e6e58 22791 const int resulting_bit = (cond & 1);
c921be7d 22792
5ee91343
AV
22793 now_pred.mask &= 0xf;
22794 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22795 resulting_bit,
5ee91343
AV
22796 (5 - now_pred.block_length));
22797 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22798 1,
5ee91343
AV
22799 ((5 - now_pred.block_length) - 1));
22800 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
22801
22802#undef CLEAR_BIT
22803#undef SET_BIT_VALUE
e07e6e58
NC
22804}
22805
22806/* The IT blocks handling machinery is accessed through the these functions:
22807 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
22808 set_pred_insn_type () optional, from the tencode functions
22809 set_pred_insn_type_last () ditto
22810 in_pred_block () ditto
e07e6e58 22811 it_fsm_post_encode () from md_assemble ()
33eaf5de 22812 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
22813
22814 Rationale:
22815 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
22816 initializing the IT insn type with a generic initial value depending
22817 on the inst.condition.
e07e6e58 22818 2) During the tencode function, two things may happen:
477330fc 22819 a) The tencode function overrides the IT insn type by
5ee91343
AV
22820 calling either set_pred_insn_type (type) or
22821 set_pred_insn_type_last ().
477330fc 22822 b) The tencode function queries the IT block state by
5ee91343 22823 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 22824
5ee91343
AV
22825 Both set_pred_insn_type and in_pred_block run the internal FSM state
22826 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
22827 type may incur in an invalid state (exiting the function),
22828 and b) querying the state requires the FSM to be updated.
22829 Specifically we want to avoid creating an IT block for conditional
22830 branches, so it_fsm_pre_encode is actually a guess and we can't
22831 determine whether an IT block is required until the tencode () routine
22832 has decided what type of instruction this actually it.
5ee91343
AV
22833 Because of this, if set_pred_insn_type and in_pred_block have to be
22834 used, set_pred_insn_type has to be called first.
477330fc 22835
5ee91343
AV
22836 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22837 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
22838 When a tencode () routine encodes an instruction that can be
22839 either outside an IT block, or, in the case of being inside, has to be
5ee91343 22840 the last one, set_pred_insn_type_last () will determine the proper
477330fc 22841 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 22842 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
22843 for covering other cases.
22844
5ee91343
AV
22845 Calling handle_pred_state () may not transition the IT block state to
22846 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 22847 still queried. Instead, if the FSM determines that the state should
5ee91343 22848 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
22849 after the tencode () function: that's what it_fsm_post_encode () does.
22850
5ee91343 22851 Since in_pred_block () calls the state handling function to get an
477330fc
RM
22852 updated state, an error may occur (due to invalid insns combination).
22853 In that case, inst.error is set.
22854 Therefore, inst.error has to be checked after the execution of
22855 the tencode () routine.
e07e6e58
NC
22856
22857 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 22858 any pending state change (if any) that didn't take place in
5ee91343 22859 handle_pred_state () as explained above. */
e07e6e58
NC
22860
22861static void
22862it_fsm_pre_encode (void)
22863{
22864 if (inst.cond != COND_ALWAYS)
5ee91343 22865 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 22866 else
5ee91343 22867 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 22868
5ee91343 22869 now_pred.state_handled = 0;
e07e6e58
NC
22870}
22871
22872/* IT state FSM handling function. */
5ee91343
AV
22873/* MVE instructions and non-MVE instructions are handled differently because of
22874 the introduction of VPT blocks.
22875 Specifications say that any non-MVE instruction inside a VPT block is
22876 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22877 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 22878 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
22879 The error messages provided depending on the different combinations possible
22880 are described in the cases below:
22881 For 'most' MVE instructions:
22882 1) In an IT block, with an IT code: syntax error
22883 2) In an IT block, with a VPT code: error: must be in a VPT block
22884 3) In an IT block, with no code: warning: UNPREDICTABLE
22885 4) In a VPT block, with an IT code: syntax error
22886 5) In a VPT block, with a VPT code: OK!
22887 6) In a VPT block, with no code: error: missing code
22888 7) Outside a pred block, with an IT code: error: syntax error
22889 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22890 9) Outside a pred block, with no code: OK!
22891 For non-MVE instructions:
22892 10) In an IT block, with an IT code: OK!
22893 11) In an IT block, with a VPT code: syntax error
22894 12) In an IT block, with no code: error: missing code
22895 13) In a VPT block, with an IT code: error: should be in an IT block
22896 14) In a VPT block, with a VPT code: syntax error
22897 15) In a VPT block, with no code: UNPREDICTABLE
22898 16) Outside a pred block, with an IT code: error: should be in an IT block
22899 17) Outside a pred block, with a VPT code: syntax error
22900 18) Outside a pred block, with no code: OK!
22901 */
22902
e07e6e58
NC
22903
22904static int
5ee91343 22905handle_pred_state (void)
e07e6e58 22906{
5ee91343
AV
22907 now_pred.state_handled = 1;
22908 now_pred.insn_cond = FALSE;
e07e6e58 22909
5ee91343 22910 switch (now_pred.state)
e07e6e58 22911 {
5ee91343
AV
22912 case OUTSIDE_PRED_BLOCK:
22913 switch (inst.pred_insn_type)
e07e6e58 22914 {
35c228db 22915 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22916 case MVE_OUTSIDE_PRED_INSN:
22917 if (inst.cond < COND_ALWAYS)
22918 {
22919 /* Case 7: Outside a pred block, with an IT code: error: syntax
22920 error. */
22921 inst.error = BAD_SYNTAX;
22922 return FAIL;
22923 }
22924 /* Case 9: Outside a pred block, with no code: OK! */
22925 break;
22926 case OUTSIDE_PRED_INSN:
22927 if (inst.cond > COND_ALWAYS)
22928 {
22929 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22930 */
22931 inst.error = BAD_SYNTAX;
22932 return FAIL;
22933 }
22934 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22935 break;
22936
5ee91343
AV
22937 case INSIDE_VPT_INSN:
22938 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22939 a VPT block. */
22940 inst.error = BAD_OUT_VPT;
22941 return FAIL;
22942
e07e6e58
NC
22943 case INSIDE_IT_INSN:
22944 case INSIDE_IT_LAST_INSN:
5ee91343 22945 if (inst.cond < COND_ALWAYS)
e07e6e58 22946 {
5ee91343
AV
22947 /* Case 16: Outside a pred block, with an IT code: error: should
22948 be in an IT block. */
22949 if (thumb_mode == 0)
e07e6e58 22950 {
5ee91343
AV
22951 if (unified_syntax
22952 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22953 as_tsktsk (_("Warning: conditional outside an IT block"\
22954 " for Thumb."));
e07e6e58
NC
22955 }
22956 else
22957 {
5ee91343
AV
22958 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22959 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22960 {
22961 /* Automatically generate the IT instruction. */
22962 new_automatic_it_block (inst.cond);
22963 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22964 close_automatic_it_block ();
22965 }
22966 else
22967 {
22968 inst.error = BAD_OUT_IT;
22969 return FAIL;
22970 }
e07e6e58 22971 }
5ee91343 22972 break;
e07e6e58 22973 }
5ee91343
AV
22974 else if (inst.cond > COND_ALWAYS)
22975 {
22976 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22977 */
22978 inst.error = BAD_SYNTAX;
22979 return FAIL;
22980 }
22981 else
22982 gas_assert (0);
e07e6e58
NC
22983 case IF_INSIDE_IT_LAST_INSN:
22984 case NEUTRAL_IT_INSN:
22985 break;
22986
5ee91343
AV
22987 case VPT_INSN:
22988 if (inst.cond != COND_ALWAYS)
22989 first_error (BAD_SYNTAX);
22990 now_pred.state = MANUAL_PRED_BLOCK;
22991 now_pred.block_length = 0;
22992 now_pred.type = VECTOR_PRED;
22993 now_pred.cc = 0;
22994 break;
e07e6e58 22995 case IT_INSN:
5ee91343
AV
22996 now_pred.state = MANUAL_PRED_BLOCK;
22997 now_pred.block_length = 0;
22998 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22999 break;
23000 }
23001 break;
23002
5ee91343 23003 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
23004 /* Three things may happen now:
23005 a) We should increment current it block size;
23006 b) We should close current it block (closing insn or 4 insns);
23007 c) We should close current it block and start a new one (due
23008 to incompatible conditions or
23009 4 insns-length block reached). */
23010
5ee91343 23011 switch (inst.pred_insn_type)
e07e6e58 23012 {
5ee91343
AV
23013 case INSIDE_VPT_INSN:
23014 case VPT_INSN:
35c228db 23015 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
23016 case MVE_OUTSIDE_PRED_INSN:
23017 gas_assert (0);
23018 case OUTSIDE_PRED_INSN:
2b0f3761 23019 /* The closure of the block shall happen immediately,
5ee91343 23020 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
23021 force_automatic_it_block_close ();
23022 break;
23023
23024 case INSIDE_IT_INSN:
23025 case INSIDE_IT_LAST_INSN:
23026 case IF_INSIDE_IT_LAST_INSN:
5ee91343 23027 now_pred.block_length++;
e07e6e58 23028
5ee91343
AV
23029 if (now_pred.block_length > 4
23030 || !now_pred_compatible (inst.cond))
e07e6e58
NC
23031 {
23032 force_automatic_it_block_close ();
5ee91343 23033 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
23034 new_automatic_it_block (inst.cond);
23035 }
23036 else
23037 {
5ee91343
AV
23038 now_pred.insn_cond = TRUE;
23039 now_pred_add_mask (inst.cond);
e07e6e58
NC
23040 }
23041
5ee91343
AV
23042 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23043 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23044 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
23045 close_automatic_it_block ();
23046 break;
23047
4934a27c 23048 /* Fallthrough. */
e07e6e58 23049 case NEUTRAL_IT_INSN:
5ee91343
AV
23050 now_pred.block_length++;
23051 now_pred.insn_cond = TRUE;
e07e6e58 23052
5ee91343 23053 if (now_pred.block_length > 4)
e07e6e58
NC
23054 force_automatic_it_block_close ();
23055 else
5ee91343 23056 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
23057 break;
23058
23059 case IT_INSN:
23060 close_automatic_it_block ();
5ee91343 23061 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
23062 break;
23063 }
23064 break;
23065
5ee91343 23066 case MANUAL_PRED_BLOCK:
e07e6e58 23067 {
7af67752
AM
23068 unsigned int cond;
23069 int is_last;
5ee91343 23070 if (now_pred.type == SCALAR_PRED)
e07e6e58 23071 {
5ee91343
AV
23072 /* Check conditional suffixes. */
23073 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23074 now_pred.mask <<= 1;
23075 now_pred.mask &= 0x1f;
23076 is_last = (now_pred.mask == 0x10);
23077 }
23078 else
23079 {
23080 now_pred.cc ^= (now_pred.mask >> 4);
23081 cond = now_pred.cc + 0xf;
23082 now_pred.mask <<= 1;
23083 now_pred.mask &= 0x1f;
23084 is_last = now_pred.mask == 0x10;
23085 }
23086 now_pred.insn_cond = TRUE;
e07e6e58 23087
5ee91343
AV
23088 switch (inst.pred_insn_type)
23089 {
23090 case OUTSIDE_PRED_INSN:
23091 if (now_pred.type == SCALAR_PRED)
23092 {
23093 if (inst.cond == COND_ALWAYS)
23094 {
23095 /* Case 12: In an IT block, with no code: error: missing
23096 code. */
23097 inst.error = BAD_NOT_IT;
23098 return FAIL;
23099 }
23100 else if (inst.cond > COND_ALWAYS)
23101 {
23102 /* Case 11: In an IT block, with a VPT code: syntax error.
23103 */
23104 inst.error = BAD_SYNTAX;
23105 return FAIL;
23106 }
23107 else if (thumb_mode)
23108 {
23109 /* This is for some special cases where a non-MVE
23110 instruction is not allowed in an IT block, such as cbz,
23111 but are put into one with a condition code.
23112 You could argue this should be a syntax error, but we
23113 gave the 'not allowed in IT block' diagnostic in the
23114 past so we will keep doing so. */
23115 inst.error = BAD_NOT_IT;
23116 return FAIL;
23117 }
23118 break;
23119 }
23120 else
23121 {
23122 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23123 as_tsktsk (MVE_NOT_VPT);
23124 return SUCCESS;
23125 }
23126 case MVE_OUTSIDE_PRED_INSN:
23127 if (now_pred.type == SCALAR_PRED)
23128 {
23129 if (inst.cond == COND_ALWAYS)
23130 {
23131 /* Case 3: In an IT block, with no code: warning:
23132 UNPREDICTABLE. */
23133 as_tsktsk (MVE_NOT_IT);
23134 return SUCCESS;
23135 }
23136 else if (inst.cond < COND_ALWAYS)
23137 {
23138 /* Case 1: In an IT block, with an IT code: syntax error.
23139 */
23140 inst.error = BAD_SYNTAX;
23141 return FAIL;
23142 }
23143 else
23144 gas_assert (0);
23145 }
23146 else
23147 {
23148 if (inst.cond < COND_ALWAYS)
23149 {
23150 /* Case 4: In a VPT block, with an IT code: syntax error.
23151 */
23152 inst.error = BAD_SYNTAX;
23153 return FAIL;
23154 }
23155 else if (inst.cond == COND_ALWAYS)
23156 {
23157 /* Case 6: In a VPT block, with no code: error: missing
23158 code. */
23159 inst.error = BAD_NOT_VPT;
23160 return FAIL;
23161 }
23162 else
23163 {
23164 gas_assert (0);
23165 }
23166 }
35c228db
AV
23167 case MVE_UNPREDICABLE_INSN:
23168 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23169 return SUCCESS;
e07e6e58 23170 case INSIDE_IT_INSN:
5ee91343 23171 if (inst.cond > COND_ALWAYS)
e07e6e58 23172 {
5ee91343
AV
23173 /* Case 11: In an IT block, with a VPT code: syntax error. */
23174 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23175 inst.error = BAD_SYNTAX;
23176 return FAIL;
23177 }
23178 else if (now_pred.type == SCALAR_PRED)
23179 {
23180 /* Case 10: In an IT block, with an IT code: OK! */
23181 if (cond != inst.cond)
23182 {
23183 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23184 BAD_VPT_COND;
23185 return FAIL;
23186 }
23187 }
23188 else
23189 {
23190 /* Case 13: In a VPT block, with an IT code: error: should be
23191 in an IT block. */
23192 inst.error = BAD_OUT_IT;
e07e6e58
NC
23193 return FAIL;
23194 }
23195 break;
23196
5ee91343
AV
23197 case INSIDE_VPT_INSN:
23198 if (now_pred.type == SCALAR_PRED)
23199 {
23200 /* Case 2: In an IT block, with a VPT code: error: must be in a
23201 VPT block. */
23202 inst.error = BAD_OUT_VPT;
23203 return FAIL;
23204 }
23205 /* Case 5: In a VPT block, with a VPT code: OK! */
23206 else if (cond != inst.cond)
23207 {
23208 inst.error = BAD_VPT_COND;
23209 return FAIL;
23210 }
23211 break;
e07e6e58
NC
23212 case INSIDE_IT_LAST_INSN:
23213 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
23214 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23215 {
23216 /* Case 4: In a VPT block, with an IT code: syntax error. */
23217 /* Case 11: In an IT block, with a VPT code: syntax error. */
23218 inst.error = BAD_SYNTAX;
23219 return FAIL;
23220 }
23221 else if (cond != inst.cond)
e07e6e58
NC
23222 {
23223 inst.error = BAD_IT_COND;
23224 return FAIL;
23225 }
23226 if (!is_last)
23227 {
23228 inst.error = BAD_BRANCH;
23229 return FAIL;
23230 }
23231 break;
23232
23233 case NEUTRAL_IT_INSN:
5ee91343
AV
23234 /* The BKPT instruction is unconditional even in a IT or VPT
23235 block. */
e07e6e58
NC
23236 break;
23237
23238 case IT_INSN:
5ee91343
AV
23239 if (now_pred.type == SCALAR_PRED)
23240 {
23241 inst.error = BAD_IT_IT;
23242 return FAIL;
23243 }
23244 /* fall through. */
23245 case VPT_INSN:
23246 if (inst.cond == COND_ALWAYS)
23247 {
23248 /* Executing a VPT/VPST instruction inside an IT block or a
23249 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23250 */
23251 if (now_pred.type == SCALAR_PRED)
23252 as_tsktsk (MVE_NOT_IT);
23253 else
23254 as_tsktsk (MVE_NOT_VPT);
23255 return SUCCESS;
23256 }
23257 else
23258 {
23259 /* VPT/VPST do not accept condition codes. */
23260 inst.error = BAD_SYNTAX;
23261 return FAIL;
23262 }
e07e6e58 23263 }
5ee91343 23264 }
e07e6e58
NC
23265 break;
23266 }
23267
23268 return SUCCESS;
23269}
23270
5a01bb1d
MGD
23271struct depr_insn_mask
23272{
23273 unsigned long pattern;
23274 unsigned long mask;
23275 const char* description;
23276};
23277
23278/* List of 16-bit instruction patterns deprecated in an IT block in
23279 ARMv8. */
23280static const struct depr_insn_mask depr_it_insns[] = {
23281 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23282 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23283 { 0xa000, 0xb800, N_("ADR") },
23284 { 0x4800, 0xf800, N_("Literal loads") },
23285 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23286 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
23287 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23288 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23289 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
23290 { 0, 0, NULL }
23291};
23292
e07e6e58
NC
23293static void
23294it_fsm_post_encode (void)
23295{
23296 int is_last;
23297
5ee91343
AV
23298 if (!now_pred.state_handled)
23299 handle_pred_state ();
e07e6e58 23300
5ee91343 23301 if (now_pred.insn_cond
24f19ccb 23302 && warn_on_restrict_it
5ee91343 23303 && !now_pred.warn_deprecated
5a01bb1d 23304 && warn_on_deprecated
164446e0
AF
23305 && (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23306 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8r))
df9909b8 23307 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
23308 {
23309 if (inst.instruction >= 0x10000)
23310 {
5c3696f8 23311 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 23312 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 23313 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23314 }
23315 else
23316 {
23317 const struct depr_insn_mask *p = depr_it_insns;
23318
23319 while (p->mask != 0)
23320 {
23321 if ((inst.instruction & p->mask) == p->pattern)
23322 {
df9909b8
TP
23323 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23324 "instructions of the following class are "
23325 "performance deprecated in ARMv8-A and "
23326 "ARMv8-R: %s"), p->description);
5ee91343 23327 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23328 break;
23329 }
23330
23331 ++p;
23332 }
23333 }
23334
5ee91343 23335 if (now_pred.block_length > 1)
5a01bb1d 23336 {
5c3696f8 23337 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
23338 "instruction are performance deprecated in ARMv8-A and "
23339 "ARMv8-R"));
5ee91343 23340 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23341 }
23342 }
23343
5ee91343
AV
23344 is_last = (now_pred.mask == 0x10);
23345 if (is_last)
23346 {
23347 now_pred.state = OUTSIDE_PRED_BLOCK;
23348 now_pred.mask = 0;
23349 }
e07e6e58
NC
23350}
23351
23352static void
23353force_automatic_it_block_close (void)
23354{
5ee91343 23355 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
23356 {
23357 close_automatic_it_block ();
5ee91343
AV
23358 now_pred.state = OUTSIDE_PRED_BLOCK;
23359 now_pred.mask = 0;
e07e6e58
NC
23360 }
23361}
23362
23363static int
5ee91343 23364in_pred_block (void)
e07e6e58 23365{
5ee91343
AV
23366 if (!now_pred.state_handled)
23367 handle_pred_state ();
e07e6e58 23368
5ee91343 23369 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
23370}
23371
ff8646ee
TP
23372/* Whether OPCODE only has T32 encoding. Since this function is only used by
23373 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23374 here, hence the "known" in the function name. */
fc289b0a
TP
23375
23376static bfd_boolean
ff8646ee 23377known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
23378{
23379 /* Original Thumb-1 wide instruction. */
23380 if (opcode->tencode == do_t_blx
23381 || opcode->tencode == do_t_branch23
23382 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23383 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23384 return TRUE;
23385
16a1fa25
TP
23386 /* Wide-only instruction added to ARMv8-M Baseline. */
23387 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
23388 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23389 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23390 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23391 return TRUE;
23392
23393 return FALSE;
23394}
23395
23396/* Whether wide instruction variant can be used if available for a valid OPCODE
23397 in ARCH. */
23398
23399static bfd_boolean
23400t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23401{
23402 if (known_t32_only_insn (opcode))
23403 return TRUE;
23404
23405 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23406 of variant T3 of B.W is checked in do_t_branch. */
23407 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23408 && opcode->tencode == do_t_branch)
23409 return TRUE;
23410
bada4342
JW
23411 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23412 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23413 && opcode->tencode == do_t_mov_cmp
23414 /* Make sure CMP instruction is not affected. */
23415 && opcode->aencode == do_mov)
23416 return TRUE;
23417
ff8646ee
TP
23418 /* Wide instruction variants of all instructions with narrow *and* wide
23419 variants become available with ARMv6t2. Other opcodes are either
23420 narrow-only or wide-only and are thus available if OPCODE is valid. */
23421 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23422 return TRUE;
23423
23424 /* OPCODE with narrow only instruction variant or wide variant not
23425 available. */
fc289b0a
TP
23426 return FALSE;
23427}
23428
c19d1205
ZW
23429void
23430md_assemble (char *str)
b99bd4ef 23431{
c19d1205
ZW
23432 char *p = str;
23433 const struct asm_opcode * opcode;
b99bd4ef 23434
c19d1205
ZW
23435 /* Align the previous label if needed. */
23436 if (last_label_seen != NULL)
b99bd4ef 23437 {
c19d1205
ZW
23438 symbol_set_frag (last_label_seen, frag_now);
23439 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23440 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
23441 }
23442
c19d1205 23443 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
23444 int r;
23445 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23446 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 23447
c19d1205
ZW
23448 opcode = opcode_lookup (&p);
23449 if (!opcode)
b99bd4ef 23450 {
c19d1205 23451 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 23452 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 23453 if (! create_register_alias (str, p)
477330fc 23454 && ! create_neon_reg_alias (str, p))
c19d1205 23455 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 23456
b99bd4ef
NC
23457 return;
23458 }
23459
278df34e 23460 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 23461 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 23462
037e8744
JB
23463 /* The value which unconditional instructions should have in place of the
23464 condition field. */
7af67752 23465 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1u;
037e8744 23466
c19d1205 23467 if (thumb_mode)
b99bd4ef 23468 {
e74cfd16 23469 arm_feature_set variant;
8f06b2d8
PB
23470
23471 variant = cpu_variant;
23472 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
23473 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23474 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 23475 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
23476 if (!opcode->tvariant
23477 || (thumb_mode == 1
23478 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 23479 {
173205ca
TP
23480 if (opcode->tencode == do_t_swi)
23481 as_bad (_("SVC is not permitted on this architecture"));
23482 else
23483 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
23484 return;
23485 }
c19d1205
ZW
23486 if (inst.cond != COND_ALWAYS && !unified_syntax
23487 && opcode->tencode != do_t_branch)
b99bd4ef 23488 {
c19d1205 23489 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
23490 return;
23491 }
23492
fc289b0a
TP
23493 /* Two things are addressed here:
23494 1) Implicit require narrow instructions on Thumb-1.
23495 This avoids relaxation accidentally introducing Thumb-2
23496 instructions.
23497 2) Reject wide instructions in non Thumb-2 cores.
23498
23499 Only instructions with narrow and wide variants need to be handled
23500 but selecting all non wide-only instructions is easier. */
23501 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 23502 && !t32_insn_ok (variant, opcode))
076d447c 23503 {
fc289b0a
TP
23504 if (inst.size_req == 0)
23505 inst.size_req = 2;
23506 else if (inst.size_req == 4)
752d5da4 23507 {
ff8646ee
TP
23508 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23509 as_bad (_("selected processor does not support 32bit wide "
23510 "variant of instruction `%s'"), str);
23511 else
23512 as_bad (_("selected processor does not support `%s' in "
23513 "Thumb-2 mode"), str);
fc289b0a 23514 return;
752d5da4 23515 }
076d447c
PB
23516 }
23517
c19d1205
ZW
23518 inst.instruction = opcode->tvalue;
23519
5be8be5d 23520 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 23521 {
5ee91343 23522 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
23523 it. */
23524 it_fsm_pre_encode ();
c19d1205 23525
477330fc 23526 opcode->tencode ();
e07e6e58 23527
477330fc
RM
23528 it_fsm_post_encode ();
23529 }
e27ec89e 23530
0110f2b8 23531 if (!(inst.error || inst.relax))
b99bd4ef 23532 {
9c2799c2 23533 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
23534 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23535 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 23536 {
c19d1205 23537 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
23538 return;
23539 }
23540 }
076d447c
PB
23541
23542 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 23543 instruction. */
9c2799c2 23544 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 23545
e74cfd16
PB
23546 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23547 *opcode->tvariant);
ee065d83 23548 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
23549 set those bits when Thumb-2 32-bit instructions are seen. The impact
23550 of relaxable instructions will be considered later after we finish all
23551 relaxation. */
ff8646ee
TP
23552 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23553 variant = arm_arch_none;
23554 else
23555 variant = cpu_variant;
23556 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
23557 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23558 arm_ext_v6t2);
cd000bff 23559
88714cb8
DG
23560 check_neon_suffixes;
23561
cd000bff 23562 if (!inst.error)
c877a2f2
NC
23563 {
23564 mapping_state (MAP_THUMB);
23565 }
c19d1205 23566 }
3e9e4fcf 23567 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 23568 {
845b51d6
PB
23569 bfd_boolean is_bx;
23570
23571 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23572 is_bx = (opcode->aencode == do_bx);
23573
c19d1205 23574 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
23575 if (!(is_bx && fix_v4bx)
23576 && !(opcode->avariant &&
23577 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 23578 {
84b52b66 23579 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 23580 return;
b99bd4ef 23581 }
c19d1205 23582 if (inst.size_req)
b99bd4ef 23583 {
c19d1205
ZW
23584 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23585 return;
b99bd4ef
NC
23586 }
23587
c19d1205
ZW
23588 inst.instruction = opcode->avalue;
23589 if (opcode->tag == OT_unconditionalF)
eff0bc54 23590 inst.instruction |= 0xFU << 28;
c19d1205
ZW
23591 else
23592 inst.instruction |= inst.cond << 28;
23593 inst.size = INSN_SIZE;
5be8be5d 23594 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
23595 {
23596 it_fsm_pre_encode ();
23597 opcode->aencode ();
23598 it_fsm_post_encode ();
23599 }
ee065d83 23600 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 23601 on a hypothetical non-thumb v5 core. */
845b51d6 23602 if (is_bx)
e74cfd16 23603 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 23604 else
e74cfd16
PB
23605 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23606 *opcode->avariant);
88714cb8
DG
23607
23608 check_neon_suffixes;
23609
cd000bff 23610 if (!inst.error)
c877a2f2
NC
23611 {
23612 mapping_state (MAP_ARM);
23613 }
b99bd4ef 23614 }
3e9e4fcf
JB
23615 else
23616 {
23617 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23618 "-- `%s'"), str);
23619 return;
23620 }
c19d1205
ZW
23621 output_inst (str);
23622}
b99bd4ef 23623
e07e6e58 23624static void
5ee91343 23625check_pred_blocks_finished (void)
e07e6e58
NC
23626{
23627#ifdef OBJ_ELF
23628 asection *sect;
23629
23630 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
23631 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23632 == MANUAL_PRED_BLOCK)
e07e6e58 23633 {
5ee91343
AV
23634 if (now_pred.type == SCALAR_PRED)
23635 as_warn (_("section '%s' finished with an open IT block."),
23636 sect->name);
23637 else
23638 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23639 sect->name);
e07e6e58
NC
23640 }
23641#else
5ee91343
AV
23642 if (now_pred.state == MANUAL_PRED_BLOCK)
23643 {
23644 if (now_pred.type == SCALAR_PRED)
23645 as_warn (_("file finished with an open IT block."));
23646 else
23647 as_warn (_("file finished with an open VPT/VPST block."));
23648 }
e07e6e58
NC
23649#endif
23650}
23651
c19d1205
ZW
23652/* Various frobbings of labels and their addresses. */
23653
23654void
23655arm_start_line_hook (void)
23656{
23657 last_label_seen = NULL;
b99bd4ef
NC
23658}
23659
c19d1205
ZW
23660void
23661arm_frob_label (symbolS * sym)
b99bd4ef 23662{
c19d1205 23663 last_label_seen = sym;
b99bd4ef 23664
c19d1205 23665 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 23666
c19d1205
ZW
23667#if defined OBJ_COFF || defined OBJ_ELF
23668 ARM_SET_INTERWORK (sym, support_interwork);
23669#endif
b99bd4ef 23670
e07e6e58
NC
23671 force_automatic_it_block_close ();
23672
5f4273c7 23673 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
23674 as Thumb functions. This is because these labels, whilst
23675 they exist inside Thumb code, are not the entry points for
23676 possible ARM->Thumb calls. Also, these labels can be used
23677 as part of a computed goto or switch statement. eg gcc
23678 can generate code that looks like this:
b99bd4ef 23679
c19d1205
ZW
23680 ldr r2, [pc, .Laaa]
23681 lsl r3, r3, #2
23682 ldr r2, [r3, r2]
23683 mov pc, r2
b99bd4ef 23684
c19d1205
ZW
23685 .Lbbb: .word .Lxxx
23686 .Lccc: .word .Lyyy
23687 ..etc...
23688 .Laaa: .word Lbbb
b99bd4ef 23689
c19d1205
ZW
23690 The first instruction loads the address of the jump table.
23691 The second instruction converts a table index into a byte offset.
23692 The third instruction gets the jump address out of the table.
23693 The fourth instruction performs the jump.
b99bd4ef 23694
c19d1205
ZW
23695 If the address stored at .Laaa is that of a symbol which has the
23696 Thumb_Func bit set, then the linker will arrange for this address
23697 to have the bottom bit set, which in turn would mean that the
23698 address computation performed by the third instruction would end
23699 up with the bottom bit set. Since the ARM is capable of unaligned
23700 word loads, the instruction would then load the incorrect address
23701 out of the jump table, and chaos would ensue. */
23702 if (label_is_thumb_function_name
23703 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
fd361982 23704 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
b99bd4ef 23705 {
c19d1205
ZW
23706 /* When the address of a Thumb function is taken the bottom
23707 bit of that address should be set. This will allow
23708 interworking between Arm and Thumb functions to work
23709 correctly. */
b99bd4ef 23710
c19d1205 23711 THUMB_SET_FUNC (sym, 1);
b99bd4ef 23712
c19d1205 23713 label_is_thumb_function_name = FALSE;
b99bd4ef 23714 }
07a53e5c 23715
07a53e5c 23716 dwarf2_emit_label (sym);
b99bd4ef
NC
23717}
23718
c921be7d 23719bfd_boolean
c19d1205 23720arm_data_in_code (void)
b99bd4ef 23721{
c19d1205 23722 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 23723 {
c19d1205
ZW
23724 *input_line_pointer = '/';
23725 input_line_pointer += 5;
23726 *input_line_pointer = 0;
c921be7d 23727 return TRUE;
b99bd4ef
NC
23728 }
23729
c921be7d 23730 return FALSE;
b99bd4ef
NC
23731}
23732
c19d1205
ZW
23733char *
23734arm_canonicalize_symbol_name (char * name)
b99bd4ef 23735{
c19d1205 23736 int len;
b99bd4ef 23737
c19d1205
ZW
23738 if (thumb_mode && (len = strlen (name)) > 5
23739 && streq (name + len - 5, "/data"))
23740 *(name + len - 5) = 0;
b99bd4ef 23741
c19d1205 23742 return name;
b99bd4ef 23743}
c19d1205
ZW
23744\f
23745/* Table of all register names defined by default. The user can
23746 define additional names with .req. Note that all register names
23747 should appear in both upper and lowercase variants. Some registers
23748 also have mixed-case names. */
b99bd4ef 23749
dcbf9037 23750#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 23751#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 23752#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
23753#define REGSET(p,t) \
23754 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23755 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23756 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23757 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
23758#define REGSETH(p,t) \
23759 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23760 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23761 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23762 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23763#define REGSET2(p,t) \
23764 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23765 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23766 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23767 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
23768#define SPLRBANK(base,bank,t) \
23769 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23770 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23771 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23772 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23773 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23774 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 23775
c19d1205 23776static const struct reg_entry reg_names[] =
7ed4c4c5 23777{
c19d1205
ZW
23778 /* ARM integer registers. */
23779 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 23780
c19d1205
ZW
23781 /* ATPCS synonyms. */
23782 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23783 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23784 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 23785
c19d1205
ZW
23786 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23787 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23788 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 23789
c19d1205
ZW
23790 /* Well-known aliases. */
23791 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23792 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23793
23794 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23795 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23796
1b883319
AV
23797 /* Defining the new Zero register from ARMv8.1-M. */
23798 REGDEF(zr,15,ZR),
23799 REGDEF(ZR,15,ZR),
23800
c19d1205
ZW
23801 /* Coprocessor numbers. */
23802 REGSET(p, CP), REGSET(P, CP),
23803
23804 /* Coprocessor register numbers. The "cr" variants are for backward
23805 compatibility. */
23806 REGSET(c, CN), REGSET(C, CN),
23807 REGSET(cr, CN), REGSET(CR, CN),
23808
90ec0d68
MGD
23809 /* ARM banked registers. */
23810 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23811 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23812 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23813 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23814 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23815 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23816 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23817
23818 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23819 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23820 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23821 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23822 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 23823 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
23824 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23825 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23826
23827 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23828 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23829 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23830 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23831 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23832 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23833 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 23834 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
23835 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23836
c19d1205
ZW
23837 /* FPA registers. */
23838 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23839 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23840
23841 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23842 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23843
23844 /* VFP SP registers. */
5287ad62
JB
23845 REGSET(s,VFS), REGSET(S,VFS),
23846 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
23847
23848 /* VFP DP Registers. */
5287ad62
JB
23849 REGSET(d,VFD), REGSET(D,VFD),
23850 /* Extra Neon DP registers. */
23851 REGSETH(d,VFD), REGSETH(D,VFD),
23852
23853 /* Neon QP registers. */
23854 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
23855
23856 /* VFP control registers. */
23857 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23858 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
23859 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23860 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23861 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23862 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 23863 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
23864 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23865 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23866 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23867 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
23868
23869 /* Maverick DSP coprocessor registers. */
23870 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23871 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23872
23873 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23874 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23875 REGDEF(dspsc,0,DSPSC),
23876
23877 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23878 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23879 REGDEF(DSPSC,0,DSPSC),
23880
23881 /* iWMMXt data registers - p0, c0-15. */
23882 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23883
23884 /* iWMMXt control registers - p1, c0-3. */
23885 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23886 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23887 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23888 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23889
23890 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23891 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23892 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23893 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23894 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23895
23896 /* XScale accumulator registers. */
23897 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23898};
23899#undef REGDEF
23900#undef REGNUM
23901#undef REGSET
7ed4c4c5 23902
c19d1205
ZW
23903/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23904 within psr_required_here. */
23905static const struct asm_psr psrs[] =
23906{
23907 /* Backward compatibility notation. Note that "all" is no longer
23908 truly all possible PSR bits. */
23909 {"all", PSR_c | PSR_f},
23910 {"flg", PSR_f},
23911 {"ctl", PSR_c},
23912
23913 /* Individual flags. */
23914 {"f", PSR_f},
23915 {"c", PSR_c},
23916 {"x", PSR_x},
23917 {"s", PSR_s},
59b42a0d 23918
c19d1205
ZW
23919 /* Combinations of flags. */
23920 {"fs", PSR_f | PSR_s},
23921 {"fx", PSR_f | PSR_x},
23922 {"fc", PSR_f | PSR_c},
23923 {"sf", PSR_s | PSR_f},
23924 {"sx", PSR_s | PSR_x},
23925 {"sc", PSR_s | PSR_c},
23926 {"xf", PSR_x | PSR_f},
23927 {"xs", PSR_x | PSR_s},
23928 {"xc", PSR_x | PSR_c},
23929 {"cf", PSR_c | PSR_f},
23930 {"cs", PSR_c | PSR_s},
23931 {"cx", PSR_c | PSR_x},
23932 {"fsx", PSR_f | PSR_s | PSR_x},
23933 {"fsc", PSR_f | PSR_s | PSR_c},
23934 {"fxs", PSR_f | PSR_x | PSR_s},
23935 {"fxc", PSR_f | PSR_x | PSR_c},
23936 {"fcs", PSR_f | PSR_c | PSR_s},
23937 {"fcx", PSR_f | PSR_c | PSR_x},
23938 {"sfx", PSR_s | PSR_f | PSR_x},
23939 {"sfc", PSR_s | PSR_f | PSR_c},
23940 {"sxf", PSR_s | PSR_x | PSR_f},
23941 {"sxc", PSR_s | PSR_x | PSR_c},
23942 {"scf", PSR_s | PSR_c | PSR_f},
23943 {"scx", PSR_s | PSR_c | PSR_x},
23944 {"xfs", PSR_x | PSR_f | PSR_s},
23945 {"xfc", PSR_x | PSR_f | PSR_c},
23946 {"xsf", PSR_x | PSR_s | PSR_f},
23947 {"xsc", PSR_x | PSR_s | PSR_c},
23948 {"xcf", PSR_x | PSR_c | PSR_f},
23949 {"xcs", PSR_x | PSR_c | PSR_s},
23950 {"cfs", PSR_c | PSR_f | PSR_s},
23951 {"cfx", PSR_c | PSR_f | PSR_x},
23952 {"csf", PSR_c | PSR_s | PSR_f},
23953 {"csx", PSR_c | PSR_s | PSR_x},
23954 {"cxf", PSR_c | PSR_x | PSR_f},
23955 {"cxs", PSR_c | PSR_x | PSR_s},
23956 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23957 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23958 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23959 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23960 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23961 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23962 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23963 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23964 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23965 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23966 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23967 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23968 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23969 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23970 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23971 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23972 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23973 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23974 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23975 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23976 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23977 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23978 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23979 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23980};
23981
62b3e311
PB
23982/* Table of V7M psr names. */
23983static const struct asm_psr v7m_psrs[] =
23984{
1a336194
TP
23985 {"apsr", 0x0 }, {"APSR", 0x0 },
23986 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23987 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23988 {"psr", 0x3 }, {"PSR", 0x3 },
23989 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23990 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23991 {"epsr", 0x6 }, {"EPSR", 0x6 },
23992 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23993 {"msp", 0x8 }, {"MSP", 0x8 },
23994 {"psp", 0x9 }, {"PSP", 0x9 },
23995 {"msplim", 0xa }, {"MSPLIM", 0xa },
23996 {"psplim", 0xb }, {"PSPLIM", 0xb },
23997 {"primask", 0x10}, {"PRIMASK", 0x10},
23998 {"basepri", 0x11}, {"BASEPRI", 0x11},
23999 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
24000 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24001 {"control", 0x14}, {"CONTROL", 0x14},
24002 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24003 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24004 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24005 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24006 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24007 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24008 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24009 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24010 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
24011};
24012
c19d1205
ZW
24013/* Table of all shift-in-operand names. */
24014static const struct asm_shift_name shift_names [] =
b99bd4ef 24015{
c19d1205
ZW
24016 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24017 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24018 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24019 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24020 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
24021 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24022 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 24023};
b99bd4ef 24024
c19d1205
ZW
24025/* Table of all explicit relocation names. */
24026#ifdef OBJ_ELF
24027static struct reloc_entry reloc_names[] =
24028{
24029 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24030 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24031 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24032 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24033 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24034 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24035 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24036 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24037 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24038 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 24039 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
24040 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24041 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 24042 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 24043 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 24044 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 24045 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
24046 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24047 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24048 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24049 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24050 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24051 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
24052 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24053 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24054 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24055 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
24056};
24057#endif
b99bd4ef 24058
5ee91343 24059/* Table of all conditional affixes. */
c19d1205
ZW
24060static const struct asm_cond conds[] =
24061{
24062 {"eq", 0x0},
24063 {"ne", 0x1},
24064 {"cs", 0x2}, {"hs", 0x2},
24065 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24066 {"mi", 0x4},
24067 {"pl", 0x5},
24068 {"vs", 0x6},
24069 {"vc", 0x7},
24070 {"hi", 0x8},
24071 {"ls", 0x9},
24072 {"ge", 0xa},
24073 {"lt", 0xb},
24074 {"gt", 0xc},
24075 {"le", 0xd},
24076 {"al", 0xe}
24077};
5ee91343
AV
24078static const struct asm_cond vconds[] =
24079{
24080 {"t", 0xf},
24081 {"e", 0x10}
24082};
bfae80f2 24083
e797f7e0 24084#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
24085 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24086 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 24087
62b3e311
PB
24088static struct asm_barrier_opt barrier_opt_names[] =
24089{
e797f7e0
MGD
24090 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24091 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24092 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24093 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24094 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24095 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24096 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24097 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24098 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24099 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24100 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24101 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24102 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24103 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24104 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24105 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
24106};
24107
e797f7e0
MGD
24108#undef UL_BARRIER
24109
c19d1205
ZW
24110/* Table of ARM-format instructions. */
24111
24112/* Macros for gluing together operand strings. N.B. In all cases
24113 other than OPS0, the trailing OP_stop comes from default
24114 zero-initialization of the unspecified elements of the array. */
24115#define OPS0() { OP_stop, }
24116#define OPS1(a) { OP_##a, }
24117#define OPS2(a,b) { OP_##a,OP_##b, }
24118#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24119#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24120#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24121#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24122
5be8be5d
DG
24123/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24124 This is useful when mixing operands for ARM and THUMB, i.e. using the
24125 MIX_ARM_THUMB_OPERANDS macro.
24126 In order to use these macros, prefix the number of operands with _
24127 e.g. _3. */
24128#define OPS_1(a) { a, }
24129#define OPS_2(a,b) { a,b, }
24130#define OPS_3(a,b,c) { a,b,c, }
24131#define OPS_4(a,b,c,d) { a,b,c,d, }
24132#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24133#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24134
c19d1205
ZW
24135/* These macros abstract out the exact format of the mnemonic table and
24136 save some repeated characters. */
24137
24138/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24139#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24140 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 24141 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24142
24143/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24144 a T_MNEM_xyz enumerator. */
24145#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24146 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24147#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24148 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
24149
24150/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24151 infix after the third character. */
24152#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 24153 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 24154 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 24155#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 24156 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 24157 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24158#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24159 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 24160#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24161 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24162#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24163 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 24164#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24165 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 24166
c19d1205 24167/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
24168 field is still 0xE. Many of the Thumb variants can be executed
24169 conditionally, so this is checked separately. */
c19d1205 24170#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24171 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24172 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24173
dd5181d5
KT
24174/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24175 Used by mnemonics that have very minimal differences in the encoding for
24176 ARM and Thumb variants and can be handled in a common function. */
24177#define TUEc(mnem, op, top, nops, ops, en) \
24178 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24179 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 24180
c19d1205
ZW
24181/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24182 condition code field. */
24183#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 24184 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24185 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24186
24187/* ARM-only variants of all the above. */
6a86118a 24188#define CE(mnem, op, nops, ops, ae) \
5ee91343 24189 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24190
24191#define C3(mnem, op, nops, ops, ae) \
5ee91343 24192 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24193
cf3cf39d
TP
24194/* Thumb-only variants of TCE and TUE. */
24195#define ToC(mnem, top, nops, ops, te) \
24196 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24197 do_##te, 0 }
cf3cf39d
TP
24198
24199#define ToU(mnem, top, nops, ops, te) \
24200 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 24201 NULL, do_##te, 0 }
cf3cf39d 24202
4389b29a
AV
24203/* T_MNEM_xyz enumerator variants of ToC. */
24204#define toC(mnem, top, nops, ops, te) \
24205 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24206 do_##te, 0 }
4389b29a 24207
f6b2b12d
AV
24208/* T_MNEM_xyz enumerator variants of ToU. */
24209#define toU(mnem, top, nops, ops, te) \
24210 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 24211 NULL, do_##te, 0 }
f6b2b12d 24212
e3cb604e
PB
24213/* Legacy mnemonics that always have conditional infix after the third
24214 character. */
24215#define CL(mnem, op, nops, ops, ae) \
21d799b5 24216 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24217 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 24218
8f06b2d8
PB
24219/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24220#define cCE(mnem, op, nops, ops, ae) \
5ee91343 24221 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24222
57785aa2
AV
24223/* mov instructions that are shared between coprocessor and MVE. */
24224#define mcCE(mnem, op, nops, ops, ae) \
24225 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24226
e3cb604e
PB
24227/* Legacy coprocessor instructions where conditional infix and conditional
24228 suffix are ambiguous. For consistency this includes all FPA instructions,
24229 not just the potentially ambiguous ones. */
24230#define cCL(mnem, op, nops, ops, ae) \
21d799b5 24231 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24232 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
24233
24234/* Coprocessor, takes either a suffix or a position-3 infix
24235 (for an FPA corner case). */
24236#define C3E(mnem, op, nops, ops, ae) \
21d799b5 24237 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 24238 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24239
6a86118a 24240#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
24241 { m1 #m2 m3, OPS##nops ops, \
24242 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 24243 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24244
24245#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
24246 xCM_ (m1, , m2, op, nops, ops, ae), \
24247 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24248 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24249 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24250 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24251 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24252 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24253 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24254 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24255 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24256 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24257 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24258 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24259 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24260 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24261 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24262 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24263 xCM_ (m1, le, m2, op, nops, ops, ae), \
24264 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
24265
24266#define UE(mnem, op, nops, ops, ae) \
5ee91343 24267 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24268
24269#define UF(mnem, op, nops, ops, ae) \
5ee91343 24270 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24271
5287ad62
JB
24272/* Neon data-processing. ARM versions are unconditional with cond=0xf.
24273 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24274 use the same encoding function for each. */
24275#define NUF(mnem, op, nops, ops, enc) \
24276 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 24277 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24278
24279/* Neon data processing, version which indirects through neon_enc_tab for
24280 the various overloaded versions of opcodes. */
24281#define nUF(mnem, op, nops, ops, enc) \
21d799b5 24282 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 24283 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24284
24285/* Neon insn with conditional suffix for the ARM version, non-overloaded
24286 version. */
5ee91343 24287#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 24288 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 24289 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24290
037e8744 24291#define NCE(mnem, op, nops, ops, enc) \
5ee91343 24292 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24293
24294#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 24295 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 24296
5287ad62 24297/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 24298#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 24299 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 24300 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24301
037e8744 24302#define nCE(mnem, op, nops, ops, enc) \
5ee91343 24303 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24304
24305#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
24306 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24307
24308/* */
24309#define mCEF(mnem, op, nops, ops, enc) \
a302e574 24310 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
24311 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24312
24313
24314/* nCEF but for MVE predicated instructions. */
24315#define mnCEF(mnem, op, nops, ops, enc) \
24316 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24317
24318/* nCE but for MVE predicated instructions. */
24319#define mnCE(mnem, op, nops, ops, enc) \
24320 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 24321
5ee91343
AV
24322/* NUF but for potentially MVE predicated instructions. */
24323#define MNUF(mnem, op, nops, ops, enc) \
24324 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24325 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24326
24327/* nUF but for potentially MVE predicated instructions. */
24328#define mnUF(mnem, op, nops, ops, enc) \
24329 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24330 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24331
24332/* ToC but for potentially MVE predicated instructions. */
24333#define mToC(mnem, top, nops, ops, te) \
24334 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24335 do_##te, 1 }
24336
24337/* NCE but for MVE predicated instructions. */
24338#define MNCE(mnem, op, nops, ops, enc) \
24339 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24340
24341/* NCEF but for MVE predicated instructions. */
24342#define MNCEF(mnem, op, nops, ops, enc) \
24343 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
24344#define do_0 0
24345
c19d1205 24346static const struct asm_opcode insns[] =
bfae80f2 24347{
74db7efb
NC
24348#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24349#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
24350 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24351 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24352 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24353 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24354 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24355 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24356 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24357 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24358 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24359 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24360 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24361 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24362 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24363 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24364 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24365 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
24366
24367 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24368 for setting PSR flag bits. They are obsolete in V6 and do not
24369 have Thumb equivalents. */
21d799b5
NC
24370 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24371 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24372 CL("tstp", 110f000, 2, (RR, SH), cmp),
24373 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24374 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24375 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24376 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24377 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24378 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24379
24380 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 24381 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
24382 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24383 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24384
24385 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
24386 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24387 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24388 OP_RRnpc),
24389 OP_ADDRGLDR),ldst, t_ldst),
24390 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
24391
24392 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24393 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24394 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24395 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24396 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24397 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24398
21d799b5
NC
24399 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24400 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 24401
c19d1205 24402 /* Pseudo ops. */
21d799b5 24403 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 24404 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 24405 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 24406 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
24407
24408 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
24409 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24410 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24411 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24412 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24413 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24414 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24415 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24416 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24417 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24418 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24419 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24420 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 24421
16a4cf17 24422 /* These may simplify to neg. */
21d799b5
NC
24423 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24424 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 24425
173205ca
TP
24426#undef THUMB_VARIANT
24427#define THUMB_VARIANT & arm_ext_os
24428
24429 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24430 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24431
c921be7d
NC
24432#undef THUMB_VARIANT
24433#define THUMB_VARIANT & arm_ext_v6
24434
21d799b5 24435 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
24436
24437 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
24438#undef THUMB_VARIANT
24439#define THUMB_VARIANT & arm_ext_v6t2
24440
21d799b5
NC
24441 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24442 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24443 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 24444
5be8be5d
DG
24445 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24446 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24447 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24448 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 24449
21d799b5
NC
24450 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24451 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 24452
21d799b5
NC
24453 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24454 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
24455
24456 /* V1 instructions with no Thumb analogue at all. */
21d799b5 24457 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
24458 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24459
24460 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24461 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24462 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24463 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24464 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24465 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24466 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24467 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24468
c921be7d
NC
24469#undef ARM_VARIANT
24470#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24471#undef THUMB_VARIANT
24472#define THUMB_VARIANT & arm_ext_v4t
24473
21d799b5
NC
24474 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24475 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 24476
c921be7d
NC
24477#undef THUMB_VARIANT
24478#define THUMB_VARIANT & arm_ext_v6t2
24479
21d799b5 24480 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
24481 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24482
24483 /* Generic coprocessor instructions. */
21d799b5
NC
24484 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24485 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24486 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24487 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24488 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24489 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 24490 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24491
c921be7d
NC
24492#undef ARM_VARIANT
24493#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24494
21d799b5 24495 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
24496 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24497
c921be7d
NC
24498#undef ARM_VARIANT
24499#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24500#undef THUMB_VARIANT
24501#define THUMB_VARIANT & arm_ext_msr
24502
d2cd1205
JB
24503 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24504 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 24505
c921be7d
NC
24506#undef ARM_VARIANT
24507#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24508#undef THUMB_VARIANT
24509#define THUMB_VARIANT & arm_ext_v6t2
24510
21d799b5
NC
24511 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24512 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24513 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24514 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24515 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24516 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24517 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24518 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 24519
c921be7d
NC
24520#undef ARM_VARIANT
24521#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24522#undef THUMB_VARIANT
24523#define THUMB_VARIANT & arm_ext_v4t
24524
5be8be5d
DG
24525 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24526 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24527 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24528 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
24529 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24530 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 24531
c921be7d
NC
24532#undef ARM_VARIANT
24533#define ARM_VARIANT & arm_ext_v4t_5
24534
c19d1205
ZW
24535 /* ARM Architecture 4T. */
24536 /* Note: bx (and blx) are required on V5, even if the processor does
24537 not support Thumb. */
21d799b5 24538 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 24539
c921be7d
NC
24540#undef ARM_VARIANT
24541#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24542#undef THUMB_VARIANT
24543#define THUMB_VARIANT & arm_ext_v5t
24544
c19d1205
ZW
24545 /* Note: blx has 2 variants; the .value coded here is for
24546 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
24547 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24548 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 24549
c921be7d
NC
24550#undef THUMB_VARIANT
24551#define THUMB_VARIANT & arm_ext_v6t2
24552
21d799b5
NC
24553 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24554 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24555 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24556 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24557 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24558 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24559 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24560 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24561
c921be7d 24562#undef ARM_VARIANT
74db7efb
NC
24563#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24564#undef THUMB_VARIANT
24565#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 24566
21d799b5
NC
24567 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24568 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24569 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24570 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24571
21d799b5
NC
24572 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24573 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24574
21d799b5
NC
24575 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24576 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24577 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24578 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 24579
21d799b5
NC
24580 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24581 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24582 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24583 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24584
21d799b5
NC
24585 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24586 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24587
03ee1b7f
NC
24588 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24589 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24590 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24591 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 24592
c921be7d 24593#undef ARM_VARIANT
74db7efb
NC
24594#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24595#undef THUMB_VARIANT
24596#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24597
21d799b5 24598 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
24599 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24600 ldrd, t_ldstd),
24601 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24602 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 24603
21d799b5
NC
24604 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24605 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 24606
c921be7d
NC
24607#undef ARM_VARIANT
24608#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24609
21d799b5 24610 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 24611
c921be7d
NC
24612#undef ARM_VARIANT
24613#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24614#undef THUMB_VARIANT
24615#define THUMB_VARIANT & arm_ext_v6
24616
21d799b5
NC
24617 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24618 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24619 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24620 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24621 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24622 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24623 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24624 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24625 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24626 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 24627
c921be7d 24628#undef THUMB_VARIANT
ff8646ee 24629#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 24630
5be8be5d
DG
24631 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24632 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24633 strex, t_strex),
ff8646ee
TP
24634#undef THUMB_VARIANT
24635#define THUMB_VARIANT & arm_ext_v6t2
24636
21d799b5
NC
24637 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24638 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 24639
21d799b5
NC
24640 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24641 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 24642
9e3c6df6 24643/* ARM V6 not included in V7M. */
c921be7d
NC
24644#undef THUMB_VARIANT
24645#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 24646 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 24647 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
24648 UF(rfeib, 9900a00, 1, (RRw), rfe),
24649 UF(rfeda, 8100a00, 1, (RRw), rfe),
24650 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24651 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
24652 UF(rfefa, 8100a00, 1, (RRw), rfe),
24653 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24654 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 24655 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
24656 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24657 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 24658 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 24659 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 24660 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 24661 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 24662 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 24663 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 24664 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 24665
9e3c6df6
PB
24666/* ARM V6 not included in V7M (eg. integer SIMD). */
24667#undef THUMB_VARIANT
24668#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
24669 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24670 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24671 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24672 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24673 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24674 /* Old name for QASX. */
74db7efb 24675 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24676 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24677 /* Old name for QSAX. */
74db7efb 24678 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24679 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24680 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24681 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24682 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24683 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24684 /* Old name for SASX. */
74db7efb 24685 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24686 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24687 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24688 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24689 /* Old name for SHASX. */
21d799b5 24690 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24691 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24692 /* Old name for SHSAX. */
21d799b5
NC
24693 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24694 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24695 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24696 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24697 /* Old name for SSAX. */
74db7efb 24698 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24699 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24700 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24701 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24703 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24704 /* Old name for UASX. */
74db7efb 24705 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24706 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24707 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24708 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24709 /* Old name for UHASX. */
21d799b5
NC
24710 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24712 /* Old name for UHSAX. */
21d799b5
NC
24713 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24714 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24715 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24716 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24717 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24718 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24719 /* Old name for UQASX. */
21d799b5
NC
24720 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24721 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24722 /* Old name for UQSAX. */
21d799b5
NC
24723 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24724 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24726 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24727 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24728 /* Old name for USAX. */
74db7efb 24729 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24730 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24731 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24732 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24733 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24734 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24735 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24736 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24737 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24738 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24739 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24740 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24741 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24742 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24743 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24744 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24745 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24746 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24747 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24748 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24749 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24750 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24751 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24752 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24753 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24754 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24755 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24756 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24757 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
24758 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24759 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24760 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24761 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24762 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 24763
c921be7d 24764#undef ARM_VARIANT
55e8aae7 24765#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 24766#undef THUMB_VARIANT
55e8aae7 24767#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 24768
21d799b5
NC
24769 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24770 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24771 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24772 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 24773
c921be7d
NC
24774#undef THUMB_VARIANT
24775#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
24776 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24777 ldrexd, t_ldrexd),
24778 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24779 RRnpcb), strexd, t_strexd),
ebdca51a 24780
c921be7d 24781#undef THUMB_VARIANT
ff8646ee 24782#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
24783 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24784 rd_rn, rd_rn),
24785 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24786 rd_rn, rd_rn),
24787 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24788 strex, t_strexbh),
5be8be5d 24789 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24790 strex, t_strexbh),
21d799b5 24791 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 24792
c921be7d 24793#undef ARM_VARIANT
f4c65163 24794#define ARM_VARIANT & arm_ext_sec
74db7efb 24795#undef THUMB_VARIANT
f4c65163 24796#define THUMB_VARIANT & arm_ext_sec
c921be7d 24797
21d799b5 24798 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 24799
90ec0d68
MGD
24800#undef ARM_VARIANT
24801#define ARM_VARIANT & arm_ext_virt
24802#undef THUMB_VARIANT
24803#define THUMB_VARIANT & arm_ext_virt
24804
24805 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24806 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24807
ddfded2f
MW
24808#undef ARM_VARIANT
24809#define ARM_VARIANT & arm_ext_pan
24810#undef THUMB_VARIANT
24811#define THUMB_VARIANT & arm_ext_pan
24812
24813 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24814
c921be7d 24815#undef ARM_VARIANT
74db7efb 24816#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
24817#undef THUMB_VARIANT
24818#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24819
21d799b5
NC
24820 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24821 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24822 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24823 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 24824
21d799b5 24825 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 24826 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 24827
5be8be5d
DG
24828 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24829 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24830 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24831 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 24832
91d8b670
JG
24833#undef ARM_VARIANT
24834#define ARM_VARIANT & arm_ext_v3
24835#undef THUMB_VARIANT
24836#define THUMB_VARIANT & arm_ext_v6t2
24837
24838 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
24839 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24840 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
24841
24842#undef ARM_VARIANT
24843#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
24844#undef THUMB_VARIANT
24845#define THUMB_VARIANT & arm_ext_v6t2_v8m
24846 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24847 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24848
bf3eeda7 24849 /* Thumb-only instructions. */
74db7efb 24850#undef ARM_VARIANT
bf3eeda7
NS
24851#define ARM_VARIANT NULL
24852 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24853 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
24854
24855 /* ARM does not really have an IT instruction, so always allow it.
24856 The opcode is copied from Thumb in order to allow warnings in
24857 -mimplicit-it=[never | arm] modes. */
24858#undef ARM_VARIANT
24859#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
24860#undef THUMB_VARIANT
24861#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24862
21d799b5
NC
24863 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24864 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24865 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24866 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24867 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24868 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24869 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24870 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24871 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24872 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24873 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24874 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24875 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24876 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24877 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 24878 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
24879 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24880 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 24881
92e90b6e 24882 /* Thumb2 only instructions. */
c921be7d
NC
24883#undef ARM_VARIANT
24884#define ARM_VARIANT NULL
92e90b6e 24885
21d799b5
NC
24886 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24887 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24888 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24889 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24890 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24891 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 24892
eea54501
MGD
24893 /* Hardware division instructions. */
24894#undef ARM_VARIANT
24895#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
24896#undef THUMB_VARIANT
24897#define THUMB_VARIANT & arm_ext_div
24898
eea54501
MGD
24899 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24900 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 24901
7e806470 24902 /* ARM V6M/V7 instructions. */
c921be7d
NC
24903#undef ARM_VARIANT
24904#define ARM_VARIANT & arm_ext_barrier
24905#undef THUMB_VARIANT
24906#define THUMB_VARIANT & arm_ext_barrier
24907
ccb84d65
JB
24908 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24909 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24910 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24911
62b3e311 24912 /* ARM V7 instructions. */
c921be7d
NC
24913#undef ARM_VARIANT
24914#define ARM_VARIANT & arm_ext_v7
24915#undef THUMB_VARIANT
24916#define THUMB_VARIANT & arm_ext_v7
24917
21d799b5
NC
24918 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24919 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24920
74db7efb 24921#undef ARM_VARIANT
60e5ef9f 24922#define ARM_VARIANT & arm_ext_mp
74db7efb 24923#undef THUMB_VARIANT
60e5ef9f
MGD
24924#define THUMB_VARIANT & arm_ext_mp
24925
24926 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24927
53c4b28b
MGD
24928 /* AArchv8 instructions. */
24929#undef ARM_VARIANT
24930#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24931
24932/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24933#undef THUMB_VARIANT
4ed7ed8d 24934#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24935
4ed7ed8d
TP
24936 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24937 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24938 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24939 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24940 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24941 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24942 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24943 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24944 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24945 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24946 stlex, t_stlex),
4b8c8c02
RE
24947 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24948 stlex, t_stlex),
24949 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24950 stlex, t_stlex),
4ed7ed8d
TP
24951#undef THUMB_VARIANT
24952#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24953
4ed7ed8d 24954 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24955 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24956 ldrexd, t_ldrexd),
24957 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24958 strexd, t_strexd),
26417f19
AC
24959#undef THUMB_VARIANT
24960#define THUMB_VARIANT & arm_ext_v8r
24961#undef ARM_VARIANT
24962#define ARM_VARIANT & arm_ext_v8r
24963
24964/* ARMv8-R instructions. */
24965 TUF("dfb", 57ff04c, f3bf8f4c, 0, (), noargs, noargs),
f7dd2fb2
TC
24966
24967/* Defined in V8 but is in undefined encoding space for earlier
24968 architectures. However earlier architectures are required to treat
24969 this instuction as a semihosting trap as well. Hence while not explicitly
24970 defined as such, it is in fact correct to define the instruction for all
24971 architectures. */
24972#undef THUMB_VARIANT
24973#define THUMB_VARIANT & arm_ext_v1
24974#undef ARM_VARIANT
24975#define ARM_VARIANT & arm_ext_v1
24976 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24977
8884b720 24978 /* ARMv8 T32 only. */
74db7efb 24979#undef ARM_VARIANT
b79f7053
MGD
24980#define ARM_VARIANT NULL
24981 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24982 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24983 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24984
33399f07
MGD
24985 /* FP for ARMv8. */
24986#undef ARM_VARIANT
a715796b 24987#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24988#undef THUMB_VARIANT
a715796b 24989#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24990
24991 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24992 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24993 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24994 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24995 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24996 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24997 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24998 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24999 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
25000 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
25001 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 25002
91ff7894
MGD
25003 /* Crypto v1 extensions. */
25004#undef ARM_VARIANT
25005#define ARM_VARIANT & fpu_crypto_ext_armv8
25006#undef THUMB_VARIANT
25007#define THUMB_VARIANT & fpu_crypto_ext_armv8
25008
25009 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25010 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25011 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25012 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
25013 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25014 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25015 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25016 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25017 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25018 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25019 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
25020 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25021 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25022 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 25023
dd5181d5 25024#undef ARM_VARIANT
8b301fbb 25025#define ARM_VARIANT & arm_ext_crc
dd5181d5 25026#undef THUMB_VARIANT
8b301fbb 25027#define THUMB_VARIANT & arm_ext_crc
dd5181d5
KT
25028 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25029 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25030 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25031 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25032 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25033 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25034
105bde57
MW
25035 /* ARMv8.2 RAS extension. */
25036#undef ARM_VARIANT
4d1464f2 25037#define ARM_VARIANT & arm_ext_ras
105bde57 25038#undef THUMB_VARIANT
4d1464f2 25039#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
25040 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25041
49e8a725
SN
25042#undef ARM_VARIANT
25043#define ARM_VARIANT & arm_ext_v8_3
25044#undef THUMB_VARIANT
25045#define THUMB_VARIANT & arm_ext_v8_3
25046 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25047
c604a79a
JW
25048#undef ARM_VARIANT
25049#define ARM_VARIANT & fpu_neon_ext_dotprod
25050#undef THUMB_VARIANT
25051#define THUMB_VARIANT & fpu_neon_ext_dotprod
25052 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25053 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25054
c921be7d
NC
25055#undef ARM_VARIANT
25056#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
25057#undef THUMB_VARIANT
25058#define THUMB_VARIANT NULL
c921be7d 25059
21d799b5
NC
25060 cCE("wfs", e200110, 1, (RR), rd),
25061 cCE("rfs", e300110, 1, (RR), rd),
25062 cCE("wfc", e400110, 1, (RR), rd),
25063 cCE("rfc", e500110, 1, (RR), rd),
25064
25065 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25066 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25067 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25068 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25069
25070 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25071 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25072 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25073 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25074
25075 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25076 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25077 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25078 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25079 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25080 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25081 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25082 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25083 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25084 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25085 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25086 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25087
25088 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25089 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25090 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25091 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25092 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25093 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25094 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25095 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25096 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25097 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25098 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25099 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25100
25101 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25102 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25103 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25104 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25105 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25106 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25107 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25108 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25109 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25110 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25111 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25112 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25113
25114 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25115 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25116 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25117 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25118 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25119 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25120 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25121 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25122 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25123 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25124 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25125 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25126
25127 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25128 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25129 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25130 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25131 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25132 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25133 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25134 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25135 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25136 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25137 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25138 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25139
25140 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25141 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25142 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25143 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25144 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25145 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25146 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25147 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25148 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25149 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25150 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25151 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25152
25153 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25154 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25155 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25156 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25157 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25158 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25159 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25160 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25161 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25162 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25163 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25164 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25165
25166 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25167 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25168 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25169 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25170 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25171 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25172 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25173 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25174 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25175 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25176 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25177 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25178
25179 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25180 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25181 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25182 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25183 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25184 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25185 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25186 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25187 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25188 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25189 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25190 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25191
25192 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25193 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25194 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25195 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25196 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25197 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25198 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25199 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25200 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25201 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25202 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25203 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25204
25205 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25206 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25207 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25208 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25209 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25210 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25211 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25212 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25213 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25214 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25215 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25216 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25217
25218 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25219 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25220 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25221 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25222 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25223 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25224 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25225 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25226 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25227 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25228 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25229 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25230
25231 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25232 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25233 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25234 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25235 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25236 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25237 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25238 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25239 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25240 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25241 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25242 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25243
25244 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25245 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25246 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25247 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25248 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25249 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25250 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25251 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25252 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25253 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25254 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25255 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25256
25257 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25258 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25259 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25260 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25261 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25262 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25263 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25264 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25265 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25266 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25267 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25268 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25269
25270 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25271 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25272 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25273 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25274 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25275 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25276 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25277 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25278 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25279 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25280 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25281 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25282
25283 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25284 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25285 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25286 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25287 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25288 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25289 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25290 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25291 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25295
25296 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25297 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25298 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25299 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25302 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25303 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25304 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25308
25309 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25311 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25312 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25316 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25317 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25321
25322 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25324 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25325 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25329 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25330 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25334
25335 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25337 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25338 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25342 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25343 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25347
25348 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25350 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25351 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25355 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25356 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25360
25361 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25363 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25364 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25368 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25369 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25373
25374 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25376 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25377 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25381 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25382 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25386
25387 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25389 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25390 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25394 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25395 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25399
25400 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25402 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25403 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25407 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25408 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25412
25413 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25415 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25416 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25420 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25421 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25425
25426 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25428 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25429 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25433 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25434 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25438
25439 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25441 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25442 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25445 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25446 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25447 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25448 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25449 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25450 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25451
25452 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25453 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25454 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25455 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25456
25457 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25458 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25459 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25460 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25461 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25462 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25463 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25464 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25465 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25466 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25467 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25468 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 25469
c19d1205
ZW
25470 /* The implementation of the FIX instruction is broken on some
25471 assemblers, in that it accepts a precision specifier as well as a
25472 rounding specifier, despite the fact that this is meaningless.
25473 To be more compatible, we accept it as well, though of course it
25474 does not set any bits. */
21d799b5
NC
25475 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25476 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25477 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25478 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25479 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25480 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25481 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25482 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25483 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25484 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25485 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25486 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25487 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 25488
c19d1205 25489 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
25490#undef ARM_VARIANT
25491#define ARM_VARIANT & fpu_fpa_ext_v2
25492
21d799b5
NC
25493 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25494 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25495 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25496 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25497 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25498 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 25499
c921be7d
NC
25500#undef ARM_VARIANT
25501#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
25502#undef THUMB_VARIANT
25503#define THUMB_VARIANT & arm_ext_v6t2
25504 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25505 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
ef8f595f
MI
25506 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25507 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25508 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25509 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
90e9955a
SP
25510
25511 /* Memory operations. */
25512 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25513 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25514 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25515 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
ba6cd17f 25516#undef THUMB_VARIANT
c921be7d 25517
c19d1205 25518 /* Moves and type conversions. */
21d799b5
NC
25519 cCE("fmstat", ef1fa10, 0, (), noargs),
25520 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25521 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25522 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25523 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25524 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25525 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25526 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25527 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
25528
25529 /* Memory operations. */
55881a11 25530 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25531 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25532 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25533 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25534 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25535 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
55881a11 25536 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25537 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25538 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25539 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25540 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25541 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 25542
c19d1205 25543 /* Monadic operations. */
21d799b5
NC
25544 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25545 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25546 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
25547
25548 /* Dyadic operations. */
21d799b5
NC
25549 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25550 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25551 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25552 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25553 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25554 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25555 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25556 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25557 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 25558
c19d1205 25559 /* Comparisons. */
21d799b5
NC
25560 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25561 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25562 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25563 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 25564
62f3b8c8
PB
25565 /* Double precision load/store are still present on single precision
25566 implementations. */
55881a11
MGD
25567 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25568 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25569 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25570 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25571 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25572 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25573 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25574 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 25575
c921be7d
NC
25576#undef ARM_VARIANT
25577#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25578
c19d1205 25579 /* Moves and type conversions. */
21d799b5
NC
25580 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25581 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25582 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25583 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25584 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25585 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25586 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25587 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25588 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25589 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25590 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25591 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 25592
c19d1205 25593 /* Monadic operations. */
21d799b5
NC
25594 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25595 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25596 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
25597
25598 /* Dyadic operations. */
21d799b5
NC
25599 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25600 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25601 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25602 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25603 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25604 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25605 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25606 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25607 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 25608
c19d1205 25609 /* Comparisons. */
21d799b5
NC
25610 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25611 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25612 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25613 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 25614
037e8744
JB
25615/* Instructions which may belong to either the Neon or VFP instruction sets.
25616 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
25617#undef ARM_VARIANT
25618#define ARM_VARIANT & fpu_vfp_ext_v1xd
ef8f595f
MI
25619#undef THUMB_VARIANT
25620#define THUMB_VARIANT & arm_ext_v6t2
25621
25622 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25623 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25624 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25625 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25626 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25627 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25628
25629 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25630 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25631
c921be7d
NC
25632#undef THUMB_VARIANT
25633#define THUMB_VARIANT & fpu_vfp_ext_v1xd
25634
037e8744
JB
25635 /* These mnemonics are unique to VFP. */
25636 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25637 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
25638 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25639 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25640 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
25641 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25642
25643 /* Mnemonics shared by Neon and VFP. */
21d799b5 25644 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 25645
dd9634d9 25646 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 25647 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
25648 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25649 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 25650
037e8744
JB
25651
25652 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
25653 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25654
32c36c3c
AV
25655#undef THUMB_VARIANT
25656/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25657 by different feature bits. Since we are setting the Thumb guard, we can
25658 require Thumb-1 which makes it a nop guard and set the right feature bit in
25659 do_vldr_vstr (). */
25660#define THUMB_VARIANT & arm_ext_v4t
25661 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25662 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25663
9db2f6b4
RL
25664#undef ARM_VARIANT
25665#define ARM_VARIANT & arm_ext_fp16
25666#undef THUMB_VARIANT
25667#define THUMB_VARIANT & arm_ext_fp16
25668 /* New instructions added from v8.2, allowing the extraction and insertion of
25669 the upper 16 bits of a 32-bit vector register. */
25670 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25671 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25672
dec41383 25673 /* New backported fma/fms instructions optional in v8.2. */
aab2c27d
MM
25674 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25675 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
dec41383 25676
c921be7d
NC
25677#undef THUMB_VARIANT
25678#define THUMB_VARIANT & fpu_neon_ext_v1
25679#undef ARM_VARIANT
25680#define ARM_VARIANT & fpu_neon_ext_v1
25681
5287ad62
JB
25682 /* Data processing with three registers of the same length. */
25683 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25684 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25685 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 25686 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 25687 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
25688 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25689 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25690 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 25691 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 25692 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 25693 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 25694 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
25695 shl should accept I8 I16 I32 I64,
25696 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25697 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25698 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 25699 /* Logic ops, types optional & ignored. */
4316f0d2 25700 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25701 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25702 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25703 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25704 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
25705 /* Bitfield ops, untyped. */
25706 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25707 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25708 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25709 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25710 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25711 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 25712 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 25713 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25714 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25715 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
25716 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25717 back to neon_dyadic_if_su. */
21d799b5
NC
25718 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25719 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25720 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25721 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25722 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25723 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25724 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25725 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 25726 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
25727 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25728 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 25729 /* As above, D registers only. */
21d799b5
NC
25730 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25731 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 25732 /* Int and float variants, signedness unimportant. */
21d799b5
NC
25733 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25734 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25735 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 25736 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
25737 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25738 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
25739 /* vtst takes sizes 8, 16, 32. */
25740 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25741 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25742 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 25743 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 25744 /* VQD{R}MULH takes S16 S32. */
21d799b5 25745 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 25746 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
25747 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25748 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25749 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25750 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
25751 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25752 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25753 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25754 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
25755 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25756 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25757 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25758 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 25759 /* ARM v8.1 extension. */
643afb90
MW
25760 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25761 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25762 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
25763
25764 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 25765 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
25766 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25767
25768 /* Data processing with two registers and a shift amount. */
25769 /* Right shifts, and variants with rounding.
25770 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25771 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
25772 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25773 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25774 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25775 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25776 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25777 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 25778 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
25779 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25780 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
25781 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25782 /* Right shift immediate, saturating & narrowing, with rounding variants.
25783 Types accepted S16 S32 S64 U16 U32 U64. */
25784 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25785 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25786 /* As above, unsigned. Types accepted S16 S32 S64. */
25787 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25788 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25789 /* Right shift narrowing. Types accepted I16 I32 I64. */
25790 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25791 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25792 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 25793 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 25794 /* CVT with optional immediate for fixed-point variant. */
21d799b5 25795 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 25796
4316f0d2 25797 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
25798
25799 /* Data processing, three registers of different lengths. */
25800 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25801 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
25802 /* If not scalar, fall back to neon_dyadic_long.
25803 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
25804 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25805 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
25806 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25807 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25808 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25809 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25810 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25811 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25812 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25813 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25814 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
25815 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25816 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25817 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
25818 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25819 S16 S32 U16 U32. */
21d799b5 25820 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
25821
25822 /* Extract. Size 8. */
3b8d421e
PB
25823 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25824 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
25825
25826 /* Two registers, miscellaneous. */
25827 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 25828 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 25829 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
25830 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25831 /* Vector replicate. Sizes 8 16 32. */
21d799b5 25832 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
25833 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25834 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25835 /* VMOVN. Types I16 I32 I64. */
21d799b5 25836 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 25837 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 25838 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 25839 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 25840 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
25841 /* VZIP / VUZP. Sizes 8 16 32. */
25842 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25843 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25844 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25845 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25846 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 25847 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
25848 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25849 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25850 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25851 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25852 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25853 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 25854 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
25855 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25856 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25857 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25858 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25859 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
25860 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25861 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
25862 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25863 /* VCNT. Size 8. */
25864 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25865 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25866 /* Two address, untyped. */
25867 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25868 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25869 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
25870 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25871 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
25872
25873 /* Table lookup. Size 8. */
25874 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25875 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25876
c921be7d
NC
25877#undef THUMB_VARIANT
25878#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25879#undef ARM_VARIANT
25880#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25881
5287ad62 25882 /* Neon element/structure load/store. */
21d799b5
NC
25883 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25884 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25885 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25886 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25887 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25888 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25889 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25890 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 25891
c921be7d 25892#undef THUMB_VARIANT
74db7efb
NC
25893#define THUMB_VARIANT & fpu_vfp_ext_v3xd
25894#undef ARM_VARIANT
25895#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
25896 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25897 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25898 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25899 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25900 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25901 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25902 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25903 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25904 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25905
74db7efb 25906#undef THUMB_VARIANT
c921be7d
NC
25907#define THUMB_VARIANT & fpu_vfp_ext_v3
25908#undef ARM_VARIANT
25909#define ARM_VARIANT & fpu_vfp_ext_v3
25910
21d799b5 25911 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 25912 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25913 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25914 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25915 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25916 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25917 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25918 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25919 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25920
74db7efb
NC
25921#undef ARM_VARIANT
25922#define ARM_VARIANT & fpu_vfp_ext_fma
25923#undef THUMB_VARIANT
25924#define THUMB_VARIANT & fpu_vfp_ext_fma
aab2c27d 25925 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
62f3b8c8
PB
25926 VFP FMA variant; NEON and VFP FMA always includes the NEON
25927 FMA instructions. */
d58196e0 25928 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
aab2c27d 25929 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
d58196e0
AV
25930 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25931
62f3b8c8
PB
25932 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25933 the v form should always be used. */
25934 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25935 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25936 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25937 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25938 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25939 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25940
5287ad62 25941#undef THUMB_VARIANT
c921be7d
NC
25942#undef ARM_VARIANT
25943#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25944
21d799b5
NC
25945 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25946 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25947 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25948 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25949 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25950 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25951 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25952 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25953
c921be7d
NC
25954#undef ARM_VARIANT
25955#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25956
21d799b5
NC
25957 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25958 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25959 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25960 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25961 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25962 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25963 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25964 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25965 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25966 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25967 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25968 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25969 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25970 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25971 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25972 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25973 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25974 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25975 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25976 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25977 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25978 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25979 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25980 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25981 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25982 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25983 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25984 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25985 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25986 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25987 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25988 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25989 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25990 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25991 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25992 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25993 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25994 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25995 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25996 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25997 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25998 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25999 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26000 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26001 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26002 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
26004 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26005 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26007 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26008 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26011 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26012 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26013 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26014 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26015 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26016 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26017 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26020 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26023 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26024 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26025 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26026 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26027 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26028 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26029 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26030 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26034 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26046 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26047 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26048 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26049 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26051 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26054 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26056 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26057 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26058 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26059 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26060 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26061 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26062 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26063 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26064 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26065 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26066 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26067 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26068 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26069 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26070 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26071 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26072 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26073 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26074 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26075 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26076 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26077 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26078 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26079 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26080 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26081 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26082 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26083 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26084 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26085 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26086 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26087 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26088 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26089 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26090 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26091 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26092 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26093 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26094 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26095 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26096 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26097 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26098 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26099 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26100 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26101 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26102 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26103 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26104 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26105 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26106 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26107 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26108 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26109 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26110 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26111 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26112 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26113 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26114 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26115 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26116 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26117 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26118 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 26119
c921be7d
NC
26120#undef ARM_VARIANT
26121#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26122
21d799b5
NC
26123 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26124 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26125 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26126 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26127 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26128 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26129 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26130 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26131 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26132 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26133 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26134 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26135 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26136 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26144 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26147 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26175 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26176 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26177 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26178 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26179 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 26180
c921be7d
NC
26181#undef ARM_VARIANT
26182#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26183
21d799b5
NC
26184 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26185 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26186 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26187 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26188 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26189 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26190 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26191 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26192 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26193 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26194 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26195 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26196 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26197 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
26198 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26199 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26200 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26201 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26202 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26203 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26204 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26205 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26206 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26207 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
26208 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26209 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26210 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26211 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
26212 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26213 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
26214 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26215 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26216 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26217 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
26218 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26219 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26220 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26221 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26222 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26223 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
26224 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26225 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
26226 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26227 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
26228 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26229 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26230 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26231 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26232 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26233 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26234 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26235 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26236 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26237 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26238 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26239 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26240 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26241 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26242 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26243 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26244 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26245 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26246 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26247 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26248 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26249 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26250 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26251 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26252 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26253 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26254 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26255 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
26256 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26257 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
26258 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26259 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 26260
7fadb25d
SD
26261 /* ARMv8.5-A instructions. */
26262#undef ARM_VARIANT
26263#define ARM_VARIANT & arm_ext_sb
26264#undef THUMB_VARIANT
26265#define THUMB_VARIANT & arm_ext_sb
26266 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26267
dad0c3bf
SD
26268#undef ARM_VARIANT
26269#define ARM_VARIANT & arm_ext_predres
26270#undef THUMB_VARIANT
26271#define THUMB_VARIANT & arm_ext_predres
26272 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26273 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26274 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26275
16a1fa25 26276 /* ARMv8-M instructions. */
4ed7ed8d
TP
26277#undef ARM_VARIANT
26278#define ARM_VARIANT NULL
26279#undef THUMB_VARIANT
26280#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
26281 ToU("sg", e97fe97f, 0, (), noargs),
26282 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26283 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26284 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26285 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26286 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26287 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
26288
26289 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26290 instructions behave as nop if no VFP is present. */
26291#undef THUMB_VARIANT
26292#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
26293 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26294 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
26295
26296 /* Armv8.1-M Mainline instructions. */
26297#undef THUMB_VARIANT
26298#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
26299 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26300 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26301 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26302 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26303 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26304 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26305 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26306 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26307 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26308
4389b29a 26309 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 26310 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 26311 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 26312 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 26313 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
26314
26315 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26316 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26317 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 26318
efd6b359 26319 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
26320 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26321
26322#undef THUMB_VARIANT
26323#define THUMB_VARIANT & mve_ext
23d00a41
SD
26324 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26325 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26326 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
08132bdd
SP
26327 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26328 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
23d00a41
SD
26329 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26330 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26331 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26332 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26333 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26334 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26335 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26336 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26337 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26338 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
26339
26340 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26341 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26342 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26343 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26344 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26345 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26346 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26347 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26348 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26349 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26350 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26351 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26352 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26353 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26354 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26355
5ee91343
AV
26356 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26357 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26358 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26359 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26360 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26361 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26362 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26363 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26364 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26365 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26366 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26367 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26368 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26369 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26370 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26371
a302e574 26372 /* MVE and MVE FP only. */
7df54120 26373 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
efd0b310 26374 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
c2dafc2a
AV
26375 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26376 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26377 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26378 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 26379 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
26380 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26381 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26382 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26383 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26384 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26385 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26386 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26387 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26388 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26389 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26390 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26391
35c228db
AV
26392 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26393 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26394 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26395 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26396 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26397 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26398 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26399 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26400 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26401 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26402 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26403 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
26404 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26405 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26406 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26407 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26408 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26409 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26410 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26411 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 26412
57785aa2
AV
26413 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26414 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 26415 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
26416 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26417 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26418 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26419 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
26420 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26421 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26422 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26423 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
26424 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26425 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
26426 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26427 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26428 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26429 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 26430
93925576
AV
26431 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26432 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26433 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26434 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26435 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26436 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26437 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26438 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26439 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26440 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26441 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26442 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26443 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26444 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26445 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26446 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26447 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26448 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26449 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26450 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26451
2d78f95b
AV
26452 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26453 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26454 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
26455 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26456 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 26457
8b8b22a4
AV
26458 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26459 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26460 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26461 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26462 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26463 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26464 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26465 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
26466 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26467 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26468 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
26469 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26470 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
26471 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26472 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26473 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26474 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 26475
4aa88b50
AV
26476 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26477 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26478 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26479 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26480 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26481 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26482 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26483 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26484 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26485 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26486 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26487 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26488
acca5630
AV
26489 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26490 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26491 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26492
1f6234a3
AV
26493 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26494 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26495 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26496 toU("lctp", _lctp, 0, (), t_loloop),
26497
5d281bf0
AV
26498#undef THUMB_VARIANT
26499#define THUMB_VARIANT & mve_fp_ext
26500 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 26501 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
26502 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26503 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
26504 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26505 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26506 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26507 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 26508
5ee91343 26509#undef ARM_VARIANT
57785aa2 26510#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
26511#undef THUMB_VARIANT
26512#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
26513 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26514 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 26515
57785aa2
AV
26516 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26517
26518#undef ARM_VARIANT
26519#define ARM_VARIANT & fpu_vfp_ext_v1xd
26520
26521 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26522 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26523 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26524 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26525
886e1c73
AV
26526 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26527 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26528 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 26529
485dee97
AV
26530 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26531 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26532
57785aa2
AV
26533 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26534 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26535
1b883319
AV
26536 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26537 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26538
57785aa2
AV
26539#undef ARM_VARIANT
26540#define ARM_VARIANT & fpu_vfp_ext_v2
26541
26542 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26543 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26544 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26545 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26546
dd9634d9
AV
26547#undef ARM_VARIANT
26548#define ARM_VARIANT & fpu_vfp_ext_armv8xd
26549 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26550 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26551 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26552 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
26553 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26554 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
26555
26556#undef ARM_VARIANT
5ee91343 26557#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 26558 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343 26559 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
66d1f7cc
AV
26560 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26561 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
f601a00c
AV
26562 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26563 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26564 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26565 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26566 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
26567 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26568 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 26569 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
26570 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26571 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26572 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
26573 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26574 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
26575 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26576 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
26577 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26578 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26579 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
26580 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26581 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26582 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
26583 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26584 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
26585 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26586 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26587 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26588 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26589 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26590 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26591 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
26592 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26593 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26594 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
26595
26596#undef ARM_VARIANT
26597#define ARM_VARIANT & arm_ext_v8_3
26598#undef THUMB_VARIANT
26599#define THUMB_VARIANT & arm_ext_v6t2_v8m
26600 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26601 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
aab2c27d
MM
26602
26603#undef ARM_VARIANT
26604#define ARM_VARIANT &arm_ext_bf16
26605#undef THUMB_VARIANT
26606#define THUMB_VARIANT &arm_ext_bf16
26607 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26608 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26609 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26610
26611#undef ARM_VARIANT
26612#define ARM_VARIANT &arm_ext_i8mm
26613#undef THUMB_VARIANT
26614#define THUMB_VARIANT &arm_ext_i8mm
26615 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26616 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
616ce08e 26617 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
aab2c27d
MM
26618 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26619 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
4934a27c
MM
26620
26621#undef ARM_VARIANT
26622#undef THUMB_VARIANT
26623#define THUMB_VARIANT &arm_ext_cde
26624 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26625 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26626 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26627 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26628
26629 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26630 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26631 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26632 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26633
26634 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26635 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26636 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26637 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
5aae9ae9
MM
26638
26639 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26640 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26641
26642 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26643 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26644
26645 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26646 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
c19d1205 26647};
5aae9ae9 26648
c19d1205
ZW
26649#undef ARM_VARIANT
26650#undef THUMB_VARIANT
26651#undef TCE
c19d1205
ZW
26652#undef TUE
26653#undef TUF
26654#undef TCC
8f06b2d8 26655#undef cCE
e3cb604e
PB
26656#undef cCL
26657#undef C3E
4389b29a 26658#undef C3
c19d1205
ZW
26659#undef CE
26660#undef CM
4389b29a 26661#undef CL
c19d1205
ZW
26662#undef UE
26663#undef UF
26664#undef UT
5287ad62
JB
26665#undef NUF
26666#undef nUF
26667#undef NCE
26668#undef nCE
c19d1205
ZW
26669#undef OPS0
26670#undef OPS1
26671#undef OPS2
26672#undef OPS3
26673#undef OPS4
26674#undef OPS5
26675#undef OPS6
26676#undef do_0
4389b29a
AV
26677#undef ToC
26678#undef toC
26679#undef ToU
f6b2b12d 26680#undef toU
c19d1205
ZW
26681\f
26682/* MD interface: bits in the object file. */
bfae80f2 26683
c19d1205
ZW
26684/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26685 for use in the a.out file, and stores them in the array pointed to by buf.
26686 This knows about the endian-ness of the target machine and does
26687 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26688 2 (short) and 4 (long) Floating numbers are put out as a series of
26689 LITTLENUMS (shorts, here at least). */
b99bd4ef 26690
c19d1205
ZW
26691void
26692md_number_to_chars (char * buf, valueT val, int n)
26693{
26694 if (target_big_endian)
26695 number_to_chars_bigendian (buf, val, n);
26696 else
26697 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
26698}
26699
c19d1205
ZW
26700static valueT
26701md_chars_to_number (char * buf, int n)
bfae80f2 26702{
c19d1205
ZW
26703 valueT result = 0;
26704 unsigned char * where = (unsigned char *) buf;
bfae80f2 26705
c19d1205 26706 if (target_big_endian)
b99bd4ef 26707 {
c19d1205
ZW
26708 while (n--)
26709 {
26710 result <<= 8;
26711 result |= (*where++ & 255);
26712 }
b99bd4ef 26713 }
c19d1205 26714 else
b99bd4ef 26715 {
c19d1205
ZW
26716 while (n--)
26717 {
26718 result <<= 8;
26719 result |= (where[n] & 255);
26720 }
bfae80f2 26721 }
b99bd4ef 26722
c19d1205 26723 return result;
bfae80f2 26724}
b99bd4ef 26725
c19d1205 26726/* MD interface: Sections. */
b99bd4ef 26727
fa94de6b
RM
26728/* Calculate the maximum variable size (i.e., excluding fr_fix)
26729 that an rs_machine_dependent frag may reach. */
26730
26731unsigned int
26732arm_frag_max_var (fragS *fragp)
26733{
26734 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26735 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26736
26737 Note that we generate relaxable instructions even for cases that don't
26738 really need it, like an immediate that's a trivial constant. So we're
26739 overestimating the instruction size for some of those cases. Rather
26740 than putting more intelligence here, it would probably be better to
26741 avoid generating a relaxation frag in the first place when it can be
26742 determined up front that a short instruction will suffice. */
26743
26744 gas_assert (fragp->fr_type == rs_machine_dependent);
26745 return INSN_SIZE;
26746}
26747
0110f2b8
PB
26748/* Estimate the size of a frag before relaxing. Assume everything fits in
26749 2 bytes. */
26750
c19d1205 26751int
0110f2b8 26752md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
26753 segT segtype ATTRIBUTE_UNUSED)
26754{
0110f2b8
PB
26755 fragp->fr_var = 2;
26756 return 2;
26757}
26758
26759/* Convert a machine dependent frag. */
26760
26761void
26762md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26763{
26764 unsigned long insn;
26765 unsigned long old_op;
26766 char *buf;
26767 expressionS exp;
26768 fixS *fixp;
26769 int reloc_type;
26770 int pc_rel;
26771 int opcode;
26772
26773 buf = fragp->fr_literal + fragp->fr_fix;
26774
26775 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
26776 if (fragp->fr_symbol)
26777 {
0110f2b8
PB
26778 exp.X_op = O_symbol;
26779 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
26780 }
26781 else
26782 {
0110f2b8 26783 exp.X_op = O_constant;
5f4273c7 26784 }
0110f2b8
PB
26785 exp.X_add_number = fragp->fr_offset;
26786 opcode = fragp->fr_subtype;
26787 switch (opcode)
26788 {
26789 case T_MNEM_ldr_pc:
26790 case T_MNEM_ldr_pc2:
26791 case T_MNEM_ldr_sp:
26792 case T_MNEM_str_sp:
26793 case T_MNEM_ldr:
26794 case T_MNEM_ldrb:
26795 case T_MNEM_ldrh:
26796 case T_MNEM_str:
26797 case T_MNEM_strb:
26798 case T_MNEM_strh:
26799 if (fragp->fr_var == 4)
26800 {
5f4273c7 26801 insn = THUMB_OP32 (opcode);
0110f2b8
PB
26802 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26803 {
26804 insn |= (old_op & 0x700) << 4;
26805 }
26806 else
26807 {
26808 insn |= (old_op & 7) << 12;
26809 insn |= (old_op & 0x38) << 13;
26810 }
26811 insn |= 0x00000c00;
26812 put_thumb32_insn (buf, insn);
26813 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26814 }
26815 else
26816 {
26817 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26818 }
26819 pc_rel = (opcode == T_MNEM_ldr_pc2);
26820 break;
26821 case T_MNEM_adr:
26822 if (fragp->fr_var == 4)
26823 {
26824 insn = THUMB_OP32 (opcode);
26825 insn |= (old_op & 0xf0) << 4;
26826 put_thumb32_insn (buf, insn);
26827 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26828 }
26829 else
26830 {
26831 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26832 exp.X_add_number -= 4;
26833 }
26834 pc_rel = 1;
26835 break;
26836 case T_MNEM_mov:
26837 case T_MNEM_movs:
26838 case T_MNEM_cmp:
26839 case T_MNEM_cmn:
26840 if (fragp->fr_var == 4)
26841 {
26842 int r0off = (opcode == T_MNEM_mov
26843 || opcode == T_MNEM_movs) ? 0 : 8;
26844 insn = THUMB_OP32 (opcode);
26845 insn = (insn & 0xe1ffffff) | 0x10000000;
26846 insn |= (old_op & 0x700) << r0off;
26847 put_thumb32_insn (buf, insn);
26848 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26849 }
26850 else
26851 {
26852 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26853 }
26854 pc_rel = 0;
26855 break;
26856 case T_MNEM_b:
26857 if (fragp->fr_var == 4)
26858 {
26859 insn = THUMB_OP32(opcode);
26860 put_thumb32_insn (buf, insn);
26861 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26862 }
26863 else
26864 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26865 pc_rel = 1;
26866 break;
26867 case T_MNEM_bcond:
26868 if (fragp->fr_var == 4)
26869 {
26870 insn = THUMB_OP32(opcode);
26871 insn |= (old_op & 0xf00) << 14;
26872 put_thumb32_insn (buf, insn);
26873 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26874 }
26875 else
26876 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26877 pc_rel = 1;
26878 break;
26879 case T_MNEM_add_sp:
26880 case T_MNEM_add_pc:
26881 case T_MNEM_inc_sp:
26882 case T_MNEM_dec_sp:
26883 if (fragp->fr_var == 4)
26884 {
26885 /* ??? Choose between add and addw. */
26886 insn = THUMB_OP32 (opcode);
26887 insn |= (old_op & 0xf0) << 4;
26888 put_thumb32_insn (buf, insn);
16805f35
PB
26889 if (opcode == T_MNEM_add_pc)
26890 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26891 else
26892 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
26893 }
26894 else
26895 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26896 pc_rel = 0;
26897 break;
26898
26899 case T_MNEM_addi:
26900 case T_MNEM_addis:
26901 case T_MNEM_subi:
26902 case T_MNEM_subis:
26903 if (fragp->fr_var == 4)
26904 {
26905 insn = THUMB_OP32 (opcode);
26906 insn |= (old_op & 0xf0) << 4;
26907 insn |= (old_op & 0xf) << 16;
26908 put_thumb32_insn (buf, insn);
16805f35
PB
26909 if (insn & (1 << 20))
26910 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26911 else
26912 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
26913 }
26914 else
26915 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26916 pc_rel = 0;
26917 break;
26918 default:
5f4273c7 26919 abort ();
0110f2b8
PB
26920 }
26921 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 26922 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
26923 fixp->fx_file = fragp->fr_file;
26924 fixp->fx_line = fragp->fr_line;
26925 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
26926
26927 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26928 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26929 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26930 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
26931}
26932
26933/* Return the size of a relaxable immediate operand instruction.
26934 SHIFT and SIZE specify the form of the allowable immediate. */
26935static int
26936relax_immediate (fragS *fragp, int size, int shift)
26937{
26938 offsetT offset;
26939 offsetT mask;
26940 offsetT low;
26941
26942 /* ??? Should be able to do better than this. */
26943 if (fragp->fr_symbol)
26944 return 4;
26945
26946 low = (1 << shift) - 1;
26947 mask = (1 << (shift + size)) - (1 << shift);
26948 offset = fragp->fr_offset;
26949 /* Force misaligned offsets to 32-bit variant. */
26950 if (offset & low)
5e77afaa 26951 return 4;
0110f2b8
PB
26952 if (offset & ~mask)
26953 return 4;
26954 return 2;
26955}
26956
5e77afaa
PB
26957/* Get the address of a symbol during relaxation. */
26958static addressT
5f4273c7 26959relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
26960{
26961 fragS *sym_frag;
26962 addressT addr;
26963 symbolS *sym;
26964
26965 sym = fragp->fr_symbol;
26966 sym_frag = symbol_get_frag (sym);
26967 know (S_GET_SEGMENT (sym) != absolute_section
26968 || sym_frag == &zero_address_frag);
26969 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26970
26971 /* If frag has yet to be reached on this pass, assume it will
26972 move by STRETCH just as we did. If this is not so, it will
26973 be because some frag between grows, and that will force
26974 another pass. */
26975
26976 if (stretch != 0
26977 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26978 {
26979 fragS *f;
26980
26981 /* Adjust stretch for any alignment frag. Note that if have
26982 been expanding the earlier code, the symbol may be
26983 defined in what appears to be an earlier frag. FIXME:
26984 This doesn't handle the fr_subtype field, which specifies
26985 a maximum number of bytes to skip when doing an
26986 alignment. */
26987 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26988 {
26989 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26990 {
26991 if (stretch < 0)
26992 stretch = - ((- stretch)
26993 & ~ ((1 << (int) f->fr_offset) - 1));
26994 else
26995 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26996 if (stretch == 0)
26997 break;
26998 }
26999 }
27000 if (f != NULL)
27001 addr += stretch;
27002 }
5e77afaa
PB
27003
27004 return addr;
27005}
27006
0110f2b8
PB
27007/* Return the size of a relaxable adr pseudo-instruction or PC-relative
27008 load. */
27009static int
5e77afaa 27010relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
27011{
27012 addressT addr;
27013 offsetT val;
27014
27015 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
27016 if (fragp->fr_symbol == NULL
27017 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27018 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27019 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27020 return 4;
27021
5f4273c7 27022 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27023 addr = fragp->fr_address + fragp->fr_fix;
27024 addr = (addr + 4) & ~3;
5e77afaa 27025 /* Force misaligned targets to 32-bit variant. */
0110f2b8 27026 if (val & 3)
5e77afaa 27027 return 4;
0110f2b8
PB
27028 val -= addr;
27029 if (val < 0 || val > 1020)
27030 return 4;
27031 return 2;
27032}
27033
27034/* Return the size of a relaxable add/sub immediate instruction. */
27035static int
27036relax_addsub (fragS *fragp, asection *sec)
27037{
27038 char *buf;
27039 int op;
27040
27041 buf = fragp->fr_literal + fragp->fr_fix;
27042 op = bfd_get_16(sec->owner, buf);
27043 if ((op & 0xf) == ((op >> 4) & 0xf))
27044 return relax_immediate (fragp, 8, 0);
27045 else
27046 return relax_immediate (fragp, 3, 0);
27047}
27048
e83a675f
RE
27049/* Return TRUE iff the definition of symbol S could be pre-empted
27050 (overridden) at link or load time. */
27051static bfd_boolean
27052symbol_preemptible (symbolS *s)
27053{
27054 /* Weak symbols can always be pre-empted. */
27055 if (S_IS_WEAK (s))
27056 return TRUE;
27057
27058 /* Non-global symbols cannot be pre-empted. */
27059 if (! S_IS_EXTERNAL (s))
27060 return FALSE;
27061
27062#ifdef OBJ_ELF
27063 /* In ELF, a global symbol can be marked protected, or private. In that
27064 case it can't be pre-empted (other definitions in the same link unit
27065 would violate the ODR). */
27066 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27067 return FALSE;
27068#endif
27069
27070 /* Other global symbols might be pre-empted. */
27071 return TRUE;
27072}
0110f2b8
PB
27073
27074/* Return the size of a relaxable branch instruction. BITS is the
27075 size of the offset field in the narrow instruction. */
27076
27077static int
5e77afaa 27078relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
27079{
27080 addressT addr;
27081 offsetT val;
27082 offsetT limit;
27083
27084 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 27085 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27086 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27087 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27088 return 4;
27089
267bf995 27090#ifdef OBJ_ELF
e83a675f 27091 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
27092 if (S_IS_DEFINED (fragp->fr_symbol)
27093 && ARM_IS_FUNC (fragp->fr_symbol))
27094 return 4;
e83a675f 27095#endif
0d9b4b55 27096
e83a675f 27097 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 27098 return 4;
267bf995 27099
5f4273c7 27100 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27101 addr = fragp->fr_address + fragp->fr_fix + 4;
27102 val -= addr;
27103
27104 /* Offset is a signed value *2 */
27105 limit = 1 << bits;
27106 if (val >= limit || val < -limit)
27107 return 4;
27108 return 2;
27109}
27110
27111
27112/* Relax a machine dependent frag. This returns the amount by which
27113 the current size of the frag should change. */
27114
27115int
5e77afaa 27116arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
27117{
27118 int oldsize;
27119 int newsize;
27120
27121 oldsize = fragp->fr_var;
27122 switch (fragp->fr_subtype)
27123 {
27124 case T_MNEM_ldr_pc2:
5f4273c7 27125 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27126 break;
27127 case T_MNEM_ldr_pc:
27128 case T_MNEM_ldr_sp:
27129 case T_MNEM_str_sp:
5f4273c7 27130 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
27131 break;
27132 case T_MNEM_ldr:
27133 case T_MNEM_str:
5f4273c7 27134 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
27135 break;
27136 case T_MNEM_ldrh:
27137 case T_MNEM_strh:
5f4273c7 27138 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
27139 break;
27140 case T_MNEM_ldrb:
27141 case T_MNEM_strb:
5f4273c7 27142 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
27143 break;
27144 case T_MNEM_adr:
5f4273c7 27145 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27146 break;
27147 case T_MNEM_mov:
27148 case T_MNEM_movs:
27149 case T_MNEM_cmp:
27150 case T_MNEM_cmn:
5f4273c7 27151 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
27152 break;
27153 case T_MNEM_b:
5f4273c7 27154 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
27155 break;
27156 case T_MNEM_bcond:
5f4273c7 27157 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
27158 break;
27159 case T_MNEM_add_sp:
27160 case T_MNEM_add_pc:
27161 newsize = relax_immediate (fragp, 8, 2);
27162 break;
27163 case T_MNEM_inc_sp:
27164 case T_MNEM_dec_sp:
27165 newsize = relax_immediate (fragp, 7, 2);
27166 break;
27167 case T_MNEM_addi:
27168 case T_MNEM_addis:
27169 case T_MNEM_subi:
27170 case T_MNEM_subis:
27171 newsize = relax_addsub (fragp, sec);
27172 break;
27173 default:
5f4273c7 27174 abort ();
0110f2b8 27175 }
5e77afaa
PB
27176
27177 fragp->fr_var = newsize;
27178 /* Freeze wide instructions that are at or before the same location as
27179 in the previous pass. This avoids infinite loops.
5f4273c7
NC
27180 Don't freeze them unconditionally because targets may be artificially
27181 misaligned by the expansion of preceding frags. */
5e77afaa 27182 if (stretch <= 0 && newsize > 2)
0110f2b8 27183 {
0110f2b8 27184 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 27185 frag_wane (fragp);
0110f2b8 27186 }
5e77afaa 27187
0110f2b8 27188 return newsize - oldsize;
c19d1205 27189}
b99bd4ef 27190
c19d1205 27191/* Round up a section size to the appropriate boundary. */
b99bd4ef 27192
c19d1205
ZW
27193valueT
27194md_section_align (segT segment ATTRIBUTE_UNUSED,
27195 valueT size)
27196{
6844c0cc 27197 return size;
bfae80f2 27198}
b99bd4ef 27199
c19d1205
ZW
27200/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27201 of an rs_align_code fragment. */
27202
27203void
27204arm_handle_align (fragS * fragP)
bfae80f2 27205{
d9235011 27206 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
27207 {
27208 { /* ARMv1 */
27209 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27210 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27211 },
27212 { /* ARMv6k */
27213 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27214 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27215 },
27216 };
d9235011 27217 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
27218 {
27219 { /* Thumb-1 */
27220 {0xc0, 0x46}, /* LE */
27221 {0x46, 0xc0}, /* BE */
27222 },
27223 { /* Thumb-2 */
27224 {0x00, 0xbf}, /* LE */
27225 {0xbf, 0x00} /* BE */
27226 }
27227 };
d9235011 27228 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
27229 { /* Wide Thumb-2 */
27230 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27231 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27232 };
c921be7d 27233
e7495e45 27234 unsigned bytes, fix, noop_size;
c19d1205 27235 char * p;
d9235011
TS
27236 const unsigned char * noop;
27237 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
27238#ifdef OBJ_ELF
27239 enum mstate state;
27240#endif
bfae80f2 27241
c19d1205 27242 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
27243 return;
27244
c19d1205
ZW
27245 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27246 p = fragP->fr_literal + fragP->fr_fix;
27247 fix = 0;
bfae80f2 27248
c19d1205
ZW
27249 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27250 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 27251
cd000bff 27252 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 27253
cd000bff 27254 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 27255 {
7f78eb34
JW
27256 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27257 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
27258 {
27259 narrow_noop = thumb_noop[1][target_big_endian];
27260 noop = wide_thumb_noop[target_big_endian];
27261 }
c19d1205 27262 else
e7495e45
NS
27263 noop = thumb_noop[0][target_big_endian];
27264 noop_size = 2;
cd000bff
DJ
27265#ifdef OBJ_ELF
27266 state = MAP_THUMB;
27267#endif
7ed4c4c5
NC
27268 }
27269 else
27270 {
7f78eb34
JW
27271 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27272 ? selected_cpu : arm_arch_none,
27273 arm_ext_v6k) != 0]
e7495e45
NS
27274 [target_big_endian];
27275 noop_size = 4;
cd000bff
DJ
27276#ifdef OBJ_ELF
27277 state = MAP_ARM;
27278#endif
7ed4c4c5 27279 }
c921be7d 27280
e7495e45 27281 fragP->fr_var = noop_size;
c921be7d 27282
c19d1205 27283 if (bytes & (noop_size - 1))
7ed4c4c5 27284 {
c19d1205 27285 fix = bytes & (noop_size - 1);
cd000bff
DJ
27286#ifdef OBJ_ELF
27287 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27288#endif
c19d1205
ZW
27289 memset (p, 0, fix);
27290 p += fix;
27291 bytes -= fix;
a737bd4d 27292 }
a737bd4d 27293
e7495e45
NS
27294 if (narrow_noop)
27295 {
27296 if (bytes & noop_size)
27297 {
27298 /* Insert a narrow noop. */
27299 memcpy (p, narrow_noop, noop_size);
27300 p += noop_size;
27301 bytes -= noop_size;
27302 fix += noop_size;
27303 }
27304
27305 /* Use wide noops for the remainder */
27306 noop_size = 4;
27307 }
27308
c19d1205 27309 while (bytes >= noop_size)
a737bd4d 27310 {
c19d1205
ZW
27311 memcpy (p, noop, noop_size);
27312 p += noop_size;
27313 bytes -= noop_size;
27314 fix += noop_size;
a737bd4d
NC
27315 }
27316
c19d1205 27317 fragP->fr_fix += fix;
a737bd4d
NC
27318}
27319
c19d1205
ZW
27320/* Called from md_do_align. Used to create an alignment
27321 frag in a code section. */
27322
27323void
27324arm_frag_align_code (int n, int max)
bfae80f2 27325{
c19d1205 27326 char * p;
7ed4c4c5 27327
c19d1205 27328 /* We assume that there will never be a requirement
6ec8e702 27329 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 27330 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
27331 {
27332 char err_msg[128];
27333
fa94de6b 27334 sprintf (err_msg,
477330fc
RM
27335 _("alignments greater than %d bytes not supported in .text sections."),
27336 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 27337 as_fatal ("%s", err_msg);
6ec8e702 27338 }
bfae80f2 27339
c19d1205
ZW
27340 p = frag_var (rs_align_code,
27341 MAX_MEM_FOR_RS_ALIGN_CODE,
27342 1,
27343 (relax_substateT) max,
27344 (symbolS *) NULL,
27345 (offsetT) n,
27346 (char *) NULL);
27347 *p = 0;
27348}
bfae80f2 27349
8dc2430f
NC
27350/* Perform target specific initialisation of a frag.
27351 Note - despite the name this initialisation is not done when the frag
27352 is created, but only when its type is assigned. A frag can be created
27353 and used a long time before its type is set, so beware of assuming that
33eaf5de 27354 this initialisation is performed first. */
bfae80f2 27355
cd000bff
DJ
27356#ifndef OBJ_ELF
27357void
27358arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27359{
27360 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 27361 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
27362}
27363
27364#else /* OBJ_ELF is defined. */
c19d1205 27365void
cd000bff 27366arm_init_frag (fragS * fragP, int max_chars)
c19d1205 27367{
e8d84ca1 27368 bfd_boolean frag_thumb_mode;
b968d18a 27369
8dc2430f
NC
27370 /* If the current ARM vs THUMB mode has not already
27371 been recorded into this frag then do so now. */
cd000bff 27372 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
27373 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27374
e8d84ca1
NC
27375 /* PR 21809: Do not set a mapping state for debug sections
27376 - it just confuses other tools. */
fd361982 27377 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
e8d84ca1
NC
27378 return;
27379
b968d18a 27380 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 27381
f9c1b181
RL
27382 /* Record a mapping symbol for alignment frags. We will delete this
27383 later if the alignment ends up empty. */
27384 switch (fragP->fr_type)
27385 {
27386 case rs_align:
27387 case rs_align_test:
27388 case rs_fill:
27389 mapping_state_2 (MAP_DATA, max_chars);
27390 break;
27391 case rs_align_code:
b968d18a 27392 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
27393 break;
27394 default:
27395 break;
cd000bff 27396 }
bfae80f2
RE
27397}
27398
c19d1205
ZW
27399/* When we change sections we need to issue a new mapping symbol. */
27400
27401void
27402arm_elf_change_section (void)
bfae80f2 27403{
c19d1205
ZW
27404 /* Link an unlinked unwind index table section to the .text section. */
27405 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27406 && elf_linked_to_section (now_seg) == NULL)
27407 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
27408}
27409
c19d1205
ZW
27410int
27411arm_elf_section_type (const char * str, size_t len)
e45d0630 27412{
c19d1205
ZW
27413 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27414 return SHT_ARM_EXIDX;
e45d0630 27415
c19d1205
ZW
27416 return -1;
27417}
27418\f
27419/* Code to deal with unwinding tables. */
e45d0630 27420
c19d1205 27421static void add_unwind_adjustsp (offsetT);
e45d0630 27422
5f4273c7 27423/* Generate any deferred unwind frame offset. */
e45d0630 27424
bfae80f2 27425static void
c19d1205 27426flush_pending_unwind (void)
bfae80f2 27427{
c19d1205 27428 offsetT offset;
bfae80f2 27429
c19d1205
ZW
27430 offset = unwind.pending_offset;
27431 unwind.pending_offset = 0;
27432 if (offset != 0)
27433 add_unwind_adjustsp (offset);
bfae80f2
RE
27434}
27435
c19d1205
ZW
27436/* Add an opcode to this list for this function. Two-byte opcodes should
27437 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27438 order. */
27439
bfae80f2 27440static void
c19d1205 27441add_unwind_opcode (valueT op, int length)
bfae80f2 27442{
c19d1205
ZW
27443 /* Add any deferred stack adjustment. */
27444 if (unwind.pending_offset)
27445 flush_pending_unwind ();
bfae80f2 27446
c19d1205 27447 unwind.sp_restored = 0;
bfae80f2 27448
c19d1205 27449 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 27450 {
c19d1205
ZW
27451 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27452 if (unwind.opcodes)
325801bd
TS
27453 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27454 unwind.opcode_alloc);
c19d1205 27455 else
325801bd 27456 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 27457 }
c19d1205 27458 while (length > 0)
bfae80f2 27459 {
c19d1205
ZW
27460 length--;
27461 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27462 op >>= 8;
27463 unwind.opcode_count++;
bfae80f2 27464 }
bfae80f2
RE
27465}
27466
c19d1205
ZW
27467/* Add unwind opcodes to adjust the stack pointer. */
27468
bfae80f2 27469static void
c19d1205 27470add_unwind_adjustsp (offsetT offset)
bfae80f2 27471{
c19d1205 27472 valueT op;
bfae80f2 27473
c19d1205 27474 if (offset > 0x200)
bfae80f2 27475 {
c19d1205
ZW
27476 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27477 char bytes[5];
27478 int n;
27479 valueT o;
bfae80f2 27480
c19d1205
ZW
27481 /* Long form: 0xb2, uleb128. */
27482 /* This might not fit in a word so add the individual bytes,
27483 remembering the list is built in reverse order. */
27484 o = (valueT) ((offset - 0x204) >> 2);
27485 if (o == 0)
27486 add_unwind_opcode (0, 1);
bfae80f2 27487
c19d1205
ZW
27488 /* Calculate the uleb128 encoding of the offset. */
27489 n = 0;
27490 while (o)
27491 {
27492 bytes[n] = o & 0x7f;
27493 o >>= 7;
27494 if (o)
27495 bytes[n] |= 0x80;
27496 n++;
27497 }
27498 /* Add the insn. */
27499 for (; n; n--)
27500 add_unwind_opcode (bytes[n - 1], 1);
27501 add_unwind_opcode (0xb2, 1);
27502 }
27503 else if (offset > 0x100)
bfae80f2 27504 {
c19d1205
ZW
27505 /* Two short opcodes. */
27506 add_unwind_opcode (0x3f, 1);
27507 op = (offset - 0x104) >> 2;
27508 add_unwind_opcode (op, 1);
bfae80f2 27509 }
c19d1205
ZW
27510 else if (offset > 0)
27511 {
27512 /* Short opcode. */
27513 op = (offset - 4) >> 2;
27514 add_unwind_opcode (op, 1);
27515 }
27516 else if (offset < 0)
bfae80f2 27517 {
c19d1205
ZW
27518 offset = -offset;
27519 while (offset > 0x100)
bfae80f2 27520 {
c19d1205
ZW
27521 add_unwind_opcode (0x7f, 1);
27522 offset -= 0x100;
bfae80f2 27523 }
c19d1205
ZW
27524 op = ((offset - 4) >> 2) | 0x40;
27525 add_unwind_opcode (op, 1);
bfae80f2 27526 }
bfae80f2
RE
27527}
27528
c19d1205 27529/* Finish the list of unwind opcodes for this function. */
0198d5e6 27530
c19d1205
ZW
27531static void
27532finish_unwind_opcodes (void)
bfae80f2 27533{
c19d1205 27534 valueT op;
bfae80f2 27535
c19d1205 27536 if (unwind.fp_used)
bfae80f2 27537 {
708587a4 27538 /* Adjust sp as necessary. */
c19d1205
ZW
27539 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27540 flush_pending_unwind ();
bfae80f2 27541
c19d1205
ZW
27542 /* After restoring sp from the frame pointer. */
27543 op = 0x90 | unwind.fp_reg;
27544 add_unwind_opcode (op, 1);
27545 }
27546 else
27547 flush_pending_unwind ();
bfae80f2
RE
27548}
27549
bfae80f2 27550
c19d1205
ZW
27551/* Start an exception table entry. If idx is nonzero this is an index table
27552 entry. */
bfae80f2
RE
27553
27554static void
c19d1205 27555start_unwind_section (const segT text_seg, int idx)
bfae80f2 27556{
c19d1205
ZW
27557 const char * text_name;
27558 const char * prefix;
27559 const char * prefix_once;
a8c4d40b 27560 struct elf_section_match match;
c19d1205 27561 char * sec_name;
c19d1205
ZW
27562 int type;
27563 int flags;
27564 int linkonce;
bfae80f2 27565
c19d1205 27566 if (idx)
bfae80f2 27567 {
c19d1205
ZW
27568 prefix = ELF_STRING_ARM_unwind;
27569 prefix_once = ELF_STRING_ARM_unwind_once;
27570 type = SHT_ARM_EXIDX;
bfae80f2 27571 }
c19d1205 27572 else
bfae80f2 27573 {
c19d1205
ZW
27574 prefix = ELF_STRING_ARM_unwind_info;
27575 prefix_once = ELF_STRING_ARM_unwind_info_once;
27576 type = SHT_PROGBITS;
bfae80f2
RE
27577 }
27578
c19d1205
ZW
27579 text_name = segment_name (text_seg);
27580 if (streq (text_name, ".text"))
27581 text_name = "";
27582
27583 if (strncmp (text_name, ".gnu.linkonce.t.",
27584 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 27585 {
c19d1205
ZW
27586 prefix = prefix_once;
27587 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
27588 }
27589
29a2809e 27590 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 27591
c19d1205
ZW
27592 flags = SHF_ALLOC;
27593 linkonce = 0;
a8c4d40b 27594 memset (&match, 0, sizeof (match));
bfae80f2 27595
c19d1205
ZW
27596 /* Handle COMDAT group. */
27597 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 27598 {
a8c4d40b
L
27599 match.group_name = elf_group_name (text_seg);
27600 if (match.group_name == NULL)
c19d1205 27601 {
bd3ba5d1 27602 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
27603 segment_name (text_seg));
27604 ignore_rest_of_line ();
27605 return;
27606 }
27607 flags |= SHF_GROUP;
27608 linkonce = 1;
bfae80f2
RE
27609 }
27610
a8c4d40b 27611 obj_elf_change_section (sec_name, type, flags, 0, &match,
a91e1603 27612 linkonce, 0);
bfae80f2 27613
5f4273c7 27614 /* Set the section link for index tables. */
c19d1205
ZW
27615 if (idx)
27616 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
27617}
27618
bfae80f2 27619
c19d1205
ZW
27620/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27621 personality routine data. Returns zero, or the index table value for
cad0da33 27622 an inline entry. */
c19d1205
ZW
27623
27624static valueT
27625create_unwind_entry (int have_data)
bfae80f2 27626{
c19d1205
ZW
27627 int size;
27628 addressT where;
27629 char *ptr;
27630 /* The current word of data. */
27631 valueT data;
27632 /* The number of bytes left in this word. */
27633 int n;
bfae80f2 27634
c19d1205 27635 finish_unwind_opcodes ();
bfae80f2 27636
c19d1205
ZW
27637 /* Remember the current text section. */
27638 unwind.saved_seg = now_seg;
27639 unwind.saved_subseg = now_subseg;
bfae80f2 27640
c19d1205 27641 start_unwind_section (now_seg, 0);
bfae80f2 27642
c19d1205 27643 if (unwind.personality_routine == NULL)
bfae80f2 27644 {
c19d1205
ZW
27645 if (unwind.personality_index == -2)
27646 {
27647 if (have_data)
5f4273c7 27648 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
27649 return 1; /* EXIDX_CANTUNWIND. */
27650 }
bfae80f2 27651
c19d1205
ZW
27652 /* Use a default personality routine if none is specified. */
27653 if (unwind.personality_index == -1)
27654 {
27655 if (unwind.opcode_count > 3)
27656 unwind.personality_index = 1;
27657 else
27658 unwind.personality_index = 0;
27659 }
bfae80f2 27660
c19d1205
ZW
27661 /* Space for the personality routine entry. */
27662 if (unwind.personality_index == 0)
27663 {
27664 if (unwind.opcode_count > 3)
27665 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 27666
c19d1205
ZW
27667 if (!have_data)
27668 {
27669 /* All the data is inline in the index table. */
27670 data = 0x80;
27671 n = 3;
27672 while (unwind.opcode_count > 0)
27673 {
27674 unwind.opcode_count--;
27675 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27676 n--;
27677 }
bfae80f2 27678
c19d1205
ZW
27679 /* Pad with "finish" opcodes. */
27680 while (n--)
27681 data = (data << 8) | 0xb0;
bfae80f2 27682
c19d1205
ZW
27683 return data;
27684 }
27685 size = 0;
27686 }
27687 else
27688 /* We get two opcodes "free" in the first word. */
27689 size = unwind.opcode_count - 2;
27690 }
27691 else
5011093d 27692 {
cad0da33
NC
27693 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27694 if (unwind.personality_index != -1)
27695 {
27696 as_bad (_("attempt to recreate an unwind entry"));
27697 return 1;
27698 }
5011093d
NC
27699
27700 /* An extra byte is required for the opcode count. */
27701 size = unwind.opcode_count + 1;
27702 }
bfae80f2 27703
c19d1205
ZW
27704 size = (size + 3) >> 2;
27705 if (size > 0xff)
27706 as_bad (_("too many unwind opcodes"));
bfae80f2 27707
c19d1205
ZW
27708 frag_align (2, 0, 0);
27709 record_alignment (now_seg, 2);
27710 unwind.table_entry = expr_build_dot ();
27711
27712 /* Allocate the table entry. */
27713 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
27714 /* PR 13449: Zero the table entries in case some of them are not used. */
27715 memset (ptr, 0, (size << 2) + 4);
c19d1205 27716 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 27717
c19d1205 27718 switch (unwind.personality_index)
bfae80f2 27719 {
c19d1205
ZW
27720 case -1:
27721 /* ??? Should this be a PLT generating relocation? */
27722 /* Custom personality routine. */
27723 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27724 BFD_RELOC_ARM_PREL31);
bfae80f2 27725
c19d1205
ZW
27726 where += 4;
27727 ptr += 4;
bfae80f2 27728
c19d1205 27729 /* Set the first byte to the number of additional words. */
5011093d 27730 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
27731 n = 3;
27732 break;
bfae80f2 27733
c19d1205
ZW
27734 /* ABI defined personality routines. */
27735 case 0:
27736 /* Three opcodes bytes are packed into the first word. */
27737 data = 0x80;
27738 n = 3;
27739 break;
bfae80f2 27740
c19d1205
ZW
27741 case 1:
27742 case 2:
27743 /* The size and first two opcode bytes go in the first word. */
27744 data = ((0x80 + unwind.personality_index) << 8) | size;
27745 n = 2;
27746 break;
bfae80f2 27747
c19d1205
ZW
27748 default:
27749 /* Should never happen. */
27750 abort ();
27751 }
bfae80f2 27752
c19d1205
ZW
27753 /* Pack the opcodes into words (MSB first), reversing the list at the same
27754 time. */
27755 while (unwind.opcode_count > 0)
27756 {
27757 if (n == 0)
27758 {
27759 md_number_to_chars (ptr, data, 4);
27760 ptr += 4;
27761 n = 4;
27762 data = 0;
27763 }
27764 unwind.opcode_count--;
27765 n--;
27766 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27767 }
27768
27769 /* Finish off the last word. */
27770 if (n < 4)
27771 {
27772 /* Pad with "finish" opcodes. */
27773 while (n--)
27774 data = (data << 8) | 0xb0;
27775
27776 md_number_to_chars (ptr, data, 4);
27777 }
27778
27779 if (!have_data)
27780 {
27781 /* Add an empty descriptor if there is no user-specified data. */
27782 ptr = frag_more (4);
27783 md_number_to_chars (ptr, 0, 4);
27784 }
27785
27786 return 0;
bfae80f2
RE
27787}
27788
f0927246
NC
27789
27790/* Initialize the DWARF-2 unwind information for this procedure. */
27791
27792void
27793tc_arm_frame_initial_instructions (void)
27794{
27795 cfi_add_CFA_def_cfa (REG_SP, 0);
27796}
27797#endif /* OBJ_ELF */
27798
c19d1205
ZW
27799/* Convert REGNAME to a DWARF-2 register number. */
27800
27801int
1df69f4f 27802tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 27803{
1df69f4f 27804 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
27805 if (reg != FAIL)
27806 return reg;
c19d1205 27807
1f5afe1c
NC
27808 /* PR 16694: Allow VFP registers as well. */
27809 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27810 if (reg != FAIL)
27811 return 64 + reg;
c19d1205 27812
1f5afe1c
NC
27813 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27814 if (reg != FAIL)
27815 return reg + 256;
27816
0198d5e6 27817 return FAIL;
bfae80f2
RE
27818}
27819
f0927246 27820#ifdef TE_PE
c19d1205 27821void
f0927246 27822tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 27823{
91d6fa6a 27824 expressionS exp;
bfae80f2 27825
91d6fa6a
NC
27826 exp.X_op = O_secrel;
27827 exp.X_add_symbol = symbol;
27828 exp.X_add_number = 0;
27829 emit_expr (&exp, size);
f0927246
NC
27830}
27831#endif
bfae80f2 27832
c19d1205 27833/* MD interface: Symbol and relocation handling. */
bfae80f2 27834
2fc8bdac
ZW
27835/* Return the address within the segment that a PC-relative fixup is
27836 relative to. For ARM, PC-relative fixups applied to instructions
27837 are generally relative to the location of the fixup plus 8 bytes.
27838 Thumb branches are offset by 4, and Thumb loads relative to PC
27839 require special handling. */
bfae80f2 27840
c19d1205 27841long
2fc8bdac 27842md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 27843{
2fc8bdac
ZW
27844 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27845
27846 /* If this is pc-relative and we are going to emit a relocation
27847 then we just want to put out any pipeline compensation that the linker
53baae48
NC
27848 will need. Otherwise we want to use the calculated base.
27849 For WinCE we skip the bias for externals as well, since this
27850 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 27851 if (fixP->fx_pcrel
2fc8bdac 27852 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
27853 || (arm_force_relocation (fixP)
27854#ifdef TE_WINCE
27855 && !S_IS_EXTERNAL (fixP->fx_addsy)
27856#endif
27857 )))
2fc8bdac 27858 base = 0;
bfae80f2 27859
267bf995 27860
c19d1205 27861 switch (fixP->fx_r_type)
bfae80f2 27862 {
2fc8bdac
ZW
27863 /* PC relative addressing on the Thumb is slightly odd as the
27864 bottom two bits of the PC are forced to zero for the
27865 calculation. This happens *after* application of the
27866 pipeline offset. However, Thumb adrl already adjusts for
27867 this, so we need not do it again. */
c19d1205 27868 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 27869 return base & ~3;
c19d1205
ZW
27870
27871 case BFD_RELOC_ARM_THUMB_OFFSET:
27872 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 27873 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 27874 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 27875 return (base + 4) & ~3;
c19d1205 27876
2fc8bdac 27877 /* Thumb branches are simply offset by +4. */
e12437dc 27878 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
27879 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27880 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27881 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27882 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 27883 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 27884 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 27885 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 27886 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 27887 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 27888 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 27889 return base + 4;
bfae80f2 27890
267bf995 27891 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
27892 if (fixP->fx_addsy
27893 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27894 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 27895 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
27896 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27897 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
27898 return base + 4;
27899
00adf2d4
JB
27900 /* BLX is like branches above, but forces the low two bits of PC to
27901 zero. */
486499d0
CL
27902 case BFD_RELOC_THUMB_PCREL_BLX:
27903 if (fixP->fx_addsy
27904 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27905 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27906 && THUMB_IS_FUNC (fixP->fx_addsy)
27907 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27908 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
27909 return (base + 4) & ~3;
27910
2fc8bdac
ZW
27911 /* ARM mode branches are offset by +8. However, the Windows CE
27912 loader expects the relocation not to take this into account. */
267bf995 27913 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
27914 if (fixP->fx_addsy
27915 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27916 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27917 && ARM_IS_FUNC (fixP->fx_addsy)
27918 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27919 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27920 return base + 8;
267bf995 27921
486499d0
CL
27922 case BFD_RELOC_ARM_PCREL_CALL:
27923 if (fixP->fx_addsy
27924 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27925 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27926 && THUMB_IS_FUNC (fixP->fx_addsy)
27927 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27928 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27929 return base + 8;
267bf995 27930
2fc8bdac 27931 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 27932 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 27933 case BFD_RELOC_ARM_PLT32:
c19d1205 27934#ifdef TE_WINCE
5f4273c7 27935 /* When handling fixups immediately, because we have already
477330fc 27936 discovered the value of a symbol, or the address of the frag involved
53baae48 27937 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
27938 see fixup_segment() in write.c
27939 The S_IS_EXTERNAL test handles the case of global symbols.
27940 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
27941 if (fixP->fx_pcrel
27942 && fixP->fx_addsy != NULL
27943 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27944 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27945 return base + 8;
2fc8bdac 27946 return base;
c19d1205 27947#else
2fc8bdac 27948 return base + 8;
c19d1205 27949#endif
2fc8bdac 27950
267bf995 27951
2fc8bdac
ZW
27952 /* ARM mode loads relative to PC are also offset by +8. Unlike
27953 branches, the Windows CE loader *does* expect the relocation
27954 to take this into account. */
27955 case BFD_RELOC_ARM_OFFSET_IMM:
27956 case BFD_RELOC_ARM_OFFSET_IMM8:
27957 case BFD_RELOC_ARM_HWLITERAL:
27958 case BFD_RELOC_ARM_LITERAL:
27959 case BFD_RELOC_ARM_CP_OFF_IMM:
27960 return base + 8;
27961
27962
27963 /* Other PC-relative relocations are un-offset. */
27964 default:
27965 return base;
27966 }
bfae80f2
RE
27967}
27968
8b2d793c
NC
27969static bfd_boolean flag_warn_syms = TRUE;
27970
ae8714c2
NC
27971bfd_boolean
27972arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27973{
8b2d793c
NC
27974 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27975 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27976 does mean that the resulting code might be very confusing to the reader.
27977 Also this warning can be triggered if the user omits an operand before
27978 an immediate address, eg:
27979
27980 LDR =foo
27981
27982 GAS treats this as an assignment of the value of the symbol foo to a
27983 symbol LDR, and so (without this code) it will not issue any kind of
27984 warning or error message.
27985
27986 Note - ARM instructions are case-insensitive but the strings in the hash
27987 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27988 lower case too. */
27989 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27990 {
27991 char * nbuf = strdup (name);
27992 char * p;
27993
27994 for (p = nbuf; *p; p++)
27995 *p = TOLOWER (*p);
629310ab 27996 if (str_hash_find (arm_ops_hsh, nbuf) != NULL)
8b2d793c 27997 {
629310ab 27998 static htab_t already_warned = NULL;
8b2d793c
NC
27999
28000 if (already_warned == NULL)
629310ab 28001 already_warned = str_htab_create ();
8b2d793c 28002 /* Only warn about the symbol once. To keep the code
629310ab
ML
28003 simple we let str_hash_insert do the lookup for us. */
28004 if (str_hash_find (already_warned, nbuf) == NULL)
28005 {
28006 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
fe0e921f 28007 str_hash_insert (already_warned, nbuf, NULL, 0);
629310ab 28008 }
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,
e01e1cee 28033 &zero_address_frag, 0);
ae8714c2
NC
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
7af67752 28182thumb32_negate_data_op (valueT *instruction, unsigned int value)
ef8d22e6 28183{
7af67752
AM
28184 unsigned int op, new_inst;
28185 unsigned 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{
7af67752
AM
28321 valueT value = * valP;
28322 valueT newval;
c19d1205
ZW
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 28384 /* If the offset is negative, we should use encoding A2 for ADR. */
7af67752 28385 if ((temp & 0xfff0000) == 0x28f0000 && (offsetT) value < 0)
5e73442d
SL
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)
7af67752 28403 && value <= 0xffff)
bada4342
JW
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:
7af67752 28500 sign = (offsetT) value > 0;
b99bd4ef 28501
7af67752 28502 if ((offsetT) value < 0)
c19d1205 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:
7af67752 28530 sign = (offsetT) value > 0;
b99bd4ef 28531
7af67752 28532 if ((offsetT) value < 0)
c19d1205 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 28558 case BFD_RELOC_ARM_T32_OFFSET_U8:
7af67752 28559 if (value > 1020 || value % 4 != 0)
c19d1205
ZW
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 28594 /* Doubleword load/store: 8-bit offset, scaled by 4. */
7af67752 28595 if ((offsetT) value >= 0)
c19d1205
ZW
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 28616 /* PC-relative, 12-bit offset. */
7af67752 28617 if ((offsetT) value >= 0)
c19d1205
ZW
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 28631 /* Writeback: 8-bit, +/- offset. */
7af67752 28632 if ((offsetT) value >= 0)
c19d1205
ZW
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. */
7af67752 28647 if (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 28658 /* Positive 12-bit or negative 8-bit offset. */
7af67752
AM
28659 unsigned int limit;
28660 if ((offsetT) 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);
7af67752 28686 if (value > 32
c19d1205
ZW
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 28748 /* 12 bit immediate for addw/subw. */
7af67752 28749 if ((offsetT) value < 0)
bada4342
JW
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)
7af67752 28772 && 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:
7af67752 28803 if (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 28812 case BFD_RELOC_ARM_HVC:
7af67752 28813 if (value > 0xffff)
90ec0d68
MGD
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 28823 {
7af67752 28824 if (value > 0xff)
c19d1205
ZW
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 {
7af67752 28833 if (value > 0x00ffffff)
c19d1205
ZW
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 28842 case BFD_RELOC_ARM_MULTI:
7af67752 28843 if (value > 0xffff)
c19d1205
ZW
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 28926 _("misaligned branch destination"));
7af67752
AM
28927 if ((value & 0xfe000000) != 0
28928 && (value & 0xfe000000) != 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. */
7af67752 28956 if ((offsetT) 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
7af67752 29229 has permitted values that are multiples of 2, in the range -510
9db2f6b4 29230 to 510. */
7af67752 29231 if (value + 510 > 510 + 510 || (value & 1))
9db2f6b4
RL
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 {
7af67752 29237 if (value + 511 > 512 + 511 || (value & 3))
32c36c3c
AV
29238 as_bad_where (fixP->fx_file, fixP->fx_line,
29239 _("co-processor offset out of range"));
29240 }
7af67752 29241 else if (value + 1023 > 1023 + 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:
7af67752
AM
29245 sign = (offsetT) value > 0;
29246 if ((offsetT) value < 0)
c19d1205 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:
7af67752 29288 if (value + 255 > 255 + 255)
c19d1205
ZW
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);
749479c8
AO
29311 else if (get_recorded_alignment (seg) < 2)
29312 as_warn_where (fixP->fx_file, fixP->fx_line,
29313 _("section does not have enough alignment to ensure safe PC-relative loads"));
a737bd4d 29314
c19d1205
ZW
29315 if (value & ~0x3fc)
29316 as_bad_where (fixP->fx_file, fixP->fx_line,
29317 _("invalid offset, value too big (0x%08lX)"),
29318 (long) value);
a737bd4d 29319
c19d1205
ZW
29320 newval |= value >> 2;
29321 break;
a737bd4d 29322
c19d1205
ZW
29323 case 9: /* SP load/store. */
29324 if (value & ~0x3fc)
29325 as_bad_where (fixP->fx_file, fixP->fx_line,
29326 _("invalid offset, value too big (0x%08lX)"),
29327 (long) value);
29328 newval |= value >> 2;
29329 break;
6c43fab6 29330
c19d1205
ZW
29331 case 6: /* Word load/store. */
29332 if (value & ~0x7c)
29333 as_bad_where (fixP->fx_file, fixP->fx_line,
29334 _("invalid offset, value too big (0x%08lX)"),
29335 (long) value);
29336 newval |= value << 4; /* 6 - 2. */
29337 break;
a737bd4d 29338
c19d1205
ZW
29339 case 7: /* Byte load/store. */
29340 if (value & ~0x1f)
29341 as_bad_where (fixP->fx_file, fixP->fx_line,
29342 _("invalid offset, value too big (0x%08lX)"),
29343 (long) value);
29344 newval |= value << 6;
29345 break;
a737bd4d 29346
c19d1205
ZW
29347 case 8: /* Halfword load/store. */
29348 if (value & ~0x3e)
29349 as_bad_where (fixP->fx_file, fixP->fx_line,
29350 _("invalid offset, value too big (0x%08lX)"),
29351 (long) value);
29352 newval |= value << 5; /* 6 - 1. */
29353 break;
a737bd4d 29354
c19d1205
ZW
29355 default:
29356 as_bad_where (fixP->fx_file, fixP->fx_line,
29357 "Unable to process relocation for thumb opcode: %lx",
29358 (unsigned long) newval);
29359 break;
29360 }
29361 md_number_to_chars (buf, newval, THUMB_SIZE);
29362 break;
a737bd4d 29363
c19d1205
ZW
29364 case BFD_RELOC_ARM_THUMB_ADD:
29365 /* This is a complicated relocation, since we use it for all of
29366 the following immediate relocations:
a737bd4d 29367
c19d1205
ZW
29368 3bit ADD/SUB
29369 8bit ADD/SUB
29370 9bit ADD/SUB SP word-aligned
29371 10bit ADD PC/SP word-aligned
a737bd4d 29372
c19d1205
ZW
29373 The type of instruction being processed is encoded in the
29374 instruction field:
a737bd4d 29375
c19d1205
ZW
29376 0x8000 SUB
29377 0x00F0 Rd
29378 0x000F Rs
29379 */
29380 newval = md_chars_to_number (buf, THUMB_SIZE);
29381 {
29382 int rd = (newval >> 4) & 0xf;
29383 int rs = newval & 0xf;
29384 int subtract = !!(newval & 0x8000);
a737bd4d 29385
c19d1205
ZW
29386 /* Check for HI regs, only very restricted cases allowed:
29387 Adjusting SP, and using PC or SP to get an address. */
29388 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29389 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29390 as_bad_where (fixP->fx_file, fixP->fx_line,
29391 _("invalid Hi register with immediate"));
a737bd4d 29392
c19d1205 29393 /* If value is negative, choose the opposite instruction. */
7af67752 29394 if ((offsetT) value < 0)
c19d1205
ZW
29395 {
29396 value = -value;
29397 subtract = !subtract;
7af67752 29398 if ((offsetT) value < 0)
c19d1205
ZW
29399 as_bad_where (fixP->fx_file, fixP->fx_line,
29400 _("immediate value out of range"));
29401 }
a737bd4d 29402
c19d1205
ZW
29403 if (rd == REG_SP)
29404 {
75c11999 29405 if (value & ~0x1fc)
c19d1205
ZW
29406 as_bad_where (fixP->fx_file, fixP->fx_line,
29407 _("invalid immediate for stack address calculation"));
29408 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29409 newval |= value >> 2;
29410 }
29411 else if (rs == REG_PC || rs == REG_SP)
29412 {
c12d2c9d
NC
29413 /* PR gas/18541. If the addition is for a defined symbol
29414 within range of an ADR instruction then accept it. */
29415 if (subtract
29416 && value == 4
29417 && fixP->fx_addsy != NULL)
29418 {
29419 subtract = 0;
29420
29421 if (! S_IS_DEFINED (fixP->fx_addsy)
29422 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29423 || S_IS_WEAK (fixP->fx_addsy))
29424 {
29425 as_bad_where (fixP->fx_file, fixP->fx_line,
29426 _("address calculation needs a strongly defined nearby symbol"));
29427 }
29428 else
29429 {
29430 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29431
29432 /* Round up to the next 4-byte boundary. */
29433 if (v & 3)
29434 v = (v + 3) & ~ 3;
29435 else
29436 v += 4;
29437 v = S_GET_VALUE (fixP->fx_addsy) - v;
29438
29439 if (v & ~0x3fc)
29440 {
29441 as_bad_where (fixP->fx_file, fixP->fx_line,
29442 _("symbol too far away"));
29443 }
29444 else
29445 {
29446 fixP->fx_done = 1;
29447 value = v;
29448 }
29449 }
29450 }
29451
c19d1205
ZW
29452 if (subtract || value & ~0x3fc)
29453 as_bad_where (fixP->fx_file, fixP->fx_line,
29454 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 29455 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
29456 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29457 newval |= rd << 8;
29458 newval |= value >> 2;
29459 }
29460 else if (rs == rd)
29461 {
29462 if (value & ~0xff)
29463 as_bad_where (fixP->fx_file, fixP->fx_line,
29464 _("immediate value out of range"));
29465 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29466 newval |= (rd << 8) | value;
29467 }
29468 else
29469 {
29470 if (value & ~0x7)
29471 as_bad_where (fixP->fx_file, fixP->fx_line,
29472 _("immediate value out of range"));
29473 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29474 newval |= rd | (rs << 3) | (value << 6);
29475 }
29476 }
29477 md_number_to_chars (buf, newval, THUMB_SIZE);
29478 break;
a737bd4d 29479
c19d1205
ZW
29480 case BFD_RELOC_ARM_THUMB_IMM:
29481 newval = md_chars_to_number (buf, THUMB_SIZE);
7af67752 29482 if (value > 255)
c19d1205 29483 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 29484 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
29485 (long) value);
29486 newval |= value;
29487 md_number_to_chars (buf, newval, THUMB_SIZE);
29488 break;
a737bd4d 29489
c19d1205
ZW
29490 case BFD_RELOC_ARM_THUMB_SHIFT:
29491 /* 5bit shift value (0..32). LSL cannot take 32. */
29492 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29493 temp = newval & 0xf800;
7af67752 29494 if (value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
c19d1205
ZW
29495 as_bad_where (fixP->fx_file, fixP->fx_line,
29496 _("invalid shift value: %ld"), (long) value);
29497 /* Shifts of zero must be encoded as LSL. */
29498 if (value == 0)
29499 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29500 /* Shifts of 32 are encoded as zero. */
29501 else if (value == 32)
29502 value = 0;
29503 newval |= value << 6;
29504 md_number_to_chars (buf, newval, THUMB_SIZE);
29505 break;
a737bd4d 29506
c19d1205
ZW
29507 case BFD_RELOC_VTABLE_INHERIT:
29508 case BFD_RELOC_VTABLE_ENTRY:
29509 fixP->fx_done = 0;
29510 return;
6c43fab6 29511
b6895b4f
PB
29512 case BFD_RELOC_ARM_MOVW:
29513 case BFD_RELOC_ARM_MOVT:
29514 case BFD_RELOC_ARM_THUMB_MOVW:
29515 case BFD_RELOC_ARM_THUMB_MOVT:
29516 if (fixP->fx_done || !seg->use_rela_p)
29517 {
29518 /* REL format relocations are limited to a 16-bit addend. */
29519 if (!fixP->fx_done)
29520 {
7af67752 29521 if (value + 0x8000 > 0x7fff + 0x8000)
b6895b4f 29522 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 29523 _("offset out of range"));
b6895b4f
PB
29524 }
29525 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29526 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29527 {
29528 value >>= 16;
29529 }
29530
29531 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29532 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29533 {
29534 newval = get_thumb32_insn (buf);
29535 newval &= 0xfbf08f00;
29536 newval |= (value & 0xf000) << 4;
29537 newval |= (value & 0x0800) << 15;
29538 newval |= (value & 0x0700) << 4;
29539 newval |= (value & 0x00ff);
29540 put_thumb32_insn (buf, newval);
29541 }
29542 else
29543 {
29544 newval = md_chars_to_number (buf, 4);
29545 newval &= 0xfff0f000;
29546 newval |= value & 0x0fff;
29547 newval |= (value & 0xf000) << 4;
29548 md_number_to_chars (buf, newval, 4);
29549 }
29550 }
29551 return;
29552
72d98d16
MG
29553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29554 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29555 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29556 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29557 gas_assert (!fixP->fx_done);
29558 {
29559 bfd_vma insn;
29560 bfd_boolean is_mov;
29561 bfd_vma encoded_addend = value;
29562
29563 /* Check that addend can be encoded in instruction. */
7af67752 29564 if (!seg->use_rela_p && value > 255)
72d98d16
MG
29565 as_bad_where (fixP->fx_file, fixP->fx_line,
29566 _("the offset 0x%08lX is not representable"),
29567 (unsigned long) encoded_addend);
29568
29569 /* Extract the instruction. */
29570 insn = md_chars_to_number (buf, THUMB_SIZE);
29571 is_mov = (insn & 0xf800) == 0x2000;
29572
29573 /* Encode insn. */
29574 if (is_mov)
29575 {
29576 if (!seg->use_rela_p)
29577 insn |= encoded_addend;
29578 }
29579 else
29580 {
29581 int rd, rs;
29582
29583 /* Extract the instruction. */
29584 /* Encoding is the following
29585 0x8000 SUB
29586 0x00F0 Rd
29587 0x000F Rs
29588 */
29589 /* The following conditions must be true :
29590 - ADD
29591 - Rd == Rs
29592 - Rd <= 7
29593 */
29594 rd = (insn >> 4) & 0xf;
29595 rs = insn & 0xf;
29596 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29597 as_bad_where (fixP->fx_file, fixP->fx_line,
29598 _("Unable to process relocation for thumb opcode: %lx"),
29599 (unsigned long) insn);
29600
29601 /* Encode as ADD immediate8 thumb 1 code. */
29602 insn = 0x3000 | (rd << 8);
29603
29604 /* Place the encoded addend into the first 8 bits of the
29605 instruction. */
29606 if (!seg->use_rela_p)
29607 insn |= encoded_addend;
29608 }
29609
29610 /* Update the instruction. */
29611 md_number_to_chars (buf, insn, THUMB_SIZE);
29612 }
29613 break;
29614
4962c51a
MS
29615 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29616 case BFD_RELOC_ARM_ALU_PC_G0:
29617 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29618 case BFD_RELOC_ARM_ALU_PC_G1:
29619 case BFD_RELOC_ARM_ALU_PC_G2:
29620 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29621 case BFD_RELOC_ARM_ALU_SB_G0:
29622 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29623 case BFD_RELOC_ARM_ALU_SB_G1:
29624 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 29625 gas_assert (!fixP->fx_done);
4962c51a
MS
29626 if (!seg->use_rela_p)
29627 {
477330fc
RM
29628 bfd_vma insn;
29629 bfd_vma encoded_addend;
7af67752 29630 bfd_vma addend_abs = llabs ((offsetT) value);
477330fc
RM
29631
29632 /* Check that the absolute value of the addend can be
29633 expressed as an 8-bit constant plus a rotation. */
29634 encoded_addend = encode_arm_immediate (addend_abs);
29635 if (encoded_addend == (unsigned int) FAIL)
4962c51a 29636 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29637 _("the offset 0x%08lX is not representable"),
29638 (unsigned long) addend_abs);
29639
29640 /* Extract the instruction. */
29641 insn = md_chars_to_number (buf, INSN_SIZE);
29642
29643 /* If the addend is positive, use an ADD instruction.
29644 Otherwise use a SUB. Take care not to destroy the S bit. */
29645 insn &= 0xff1fffff;
7af67752 29646 if ((offsetT) value < 0)
477330fc
RM
29647 insn |= 1 << 22;
29648 else
29649 insn |= 1 << 23;
29650
29651 /* Place the encoded addend into the first 12 bits of the
29652 instruction. */
29653 insn &= 0xfffff000;
29654 insn |= encoded_addend;
29655
29656 /* Update the instruction. */
29657 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
29658 }
29659 break;
29660
29661 case BFD_RELOC_ARM_LDR_PC_G0:
29662 case BFD_RELOC_ARM_LDR_PC_G1:
29663 case BFD_RELOC_ARM_LDR_PC_G2:
29664 case BFD_RELOC_ARM_LDR_SB_G0:
29665 case BFD_RELOC_ARM_LDR_SB_G1:
29666 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 29667 gas_assert (!fixP->fx_done);
4962c51a 29668 if (!seg->use_rela_p)
477330fc
RM
29669 {
29670 bfd_vma insn;
7af67752 29671 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29672
477330fc
RM
29673 /* Check that the absolute value of the addend can be
29674 encoded in 12 bits. */
29675 if (addend_abs >= 0x1000)
4962c51a 29676 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29677 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29678 (unsigned long) addend_abs);
29679
29680 /* Extract the instruction. */
29681 insn = md_chars_to_number (buf, INSN_SIZE);
29682
29683 /* If the addend is negative, clear bit 23 of the instruction.
29684 Otherwise set it. */
7af67752 29685 if ((offsetT) value < 0)
477330fc
RM
29686 insn &= ~(1 << 23);
29687 else
29688 insn |= 1 << 23;
29689
29690 /* Place the absolute value of the addend into the first 12 bits
29691 of the instruction. */
29692 insn &= 0xfffff000;
29693 insn |= addend_abs;
29694
29695 /* Update the instruction. */
29696 md_number_to_chars (buf, insn, INSN_SIZE);
29697 }
4962c51a
MS
29698 break;
29699
29700 case BFD_RELOC_ARM_LDRS_PC_G0:
29701 case BFD_RELOC_ARM_LDRS_PC_G1:
29702 case BFD_RELOC_ARM_LDRS_PC_G2:
29703 case BFD_RELOC_ARM_LDRS_SB_G0:
29704 case BFD_RELOC_ARM_LDRS_SB_G1:
29705 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 29706 gas_assert (!fixP->fx_done);
4962c51a 29707 if (!seg->use_rela_p)
477330fc
RM
29708 {
29709 bfd_vma insn;
7af67752 29710 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29711
477330fc
RM
29712 /* Check that the absolute value of the addend can be
29713 encoded in 8 bits. */
29714 if (addend_abs >= 0x100)
4962c51a 29715 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29716 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29717 (unsigned long) addend_abs);
29718
29719 /* Extract the instruction. */
29720 insn = md_chars_to_number (buf, INSN_SIZE);
29721
29722 /* If the addend is negative, clear bit 23 of the instruction.
29723 Otherwise set it. */
7af67752 29724 if ((offsetT) value < 0)
477330fc
RM
29725 insn &= ~(1 << 23);
29726 else
29727 insn |= 1 << 23;
29728
29729 /* Place the first four bits of the absolute value of the addend
29730 into the first 4 bits of the instruction, and the remaining
29731 four into bits 8 .. 11. */
29732 insn &= 0xfffff0f0;
29733 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29734
29735 /* Update the instruction. */
29736 md_number_to_chars (buf, insn, INSN_SIZE);
29737 }
4962c51a
MS
29738 break;
29739
29740 case BFD_RELOC_ARM_LDC_PC_G0:
29741 case BFD_RELOC_ARM_LDC_PC_G1:
29742 case BFD_RELOC_ARM_LDC_PC_G2:
29743 case BFD_RELOC_ARM_LDC_SB_G0:
29744 case BFD_RELOC_ARM_LDC_SB_G1:
29745 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 29746 gas_assert (!fixP->fx_done);
4962c51a 29747 if (!seg->use_rela_p)
477330fc
RM
29748 {
29749 bfd_vma insn;
7af67752 29750 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29751
477330fc
RM
29752 /* Check that the absolute value of the addend is a multiple of
29753 four and, when divided by four, fits in 8 bits. */
29754 if (addend_abs & 0x3)
4962c51a 29755 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29756 _("bad offset 0x%08lX (must be word-aligned)"),
29757 (unsigned long) addend_abs);
4962c51a 29758
477330fc 29759 if ((addend_abs >> 2) > 0xff)
4962c51a 29760 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29761 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29762 (unsigned long) addend_abs);
29763
29764 /* Extract the instruction. */
29765 insn = md_chars_to_number (buf, INSN_SIZE);
29766
29767 /* If the addend is negative, clear bit 23 of the instruction.
29768 Otherwise set it. */
7af67752 29769 if ((offsetT) value < 0)
477330fc
RM
29770 insn &= ~(1 << 23);
29771 else
29772 insn |= 1 << 23;
29773
29774 /* Place the addend (divided by four) into the first eight
29775 bits of the instruction. */
29776 insn &= 0xfffffff0;
29777 insn |= addend_abs >> 2;
29778
29779 /* Update the instruction. */
29780 md_number_to_chars (buf, insn, INSN_SIZE);
29781 }
4962c51a
MS
29782 break;
29783
e12437dc
AV
29784 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29785 if (fixP->fx_addsy
29786 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29787 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29788 && ARM_IS_FUNC (fixP->fx_addsy)
29789 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29790 {
29791 /* Force a relocation for a branch 5 bits wide. */
29792 fixP->fx_done = 0;
29793 }
29794 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29795 as_bad_where (fixP->fx_file, fixP->fx_line,
29796 BAD_BRANCH_OFF);
29797
29798 if (fixP->fx_done || !seg->use_rela_p)
29799 {
29800 addressT boff = value >> 1;
29801
29802 newval = md_chars_to_number (buf, THUMB_SIZE);
29803 newval |= (boff << 7);
29804 md_number_to_chars (buf, newval, THUMB_SIZE);
29805 }
29806 break;
29807
f6b2b12d
AV
29808 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29809 if (fixP->fx_addsy
29810 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29811 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29812 && ARM_IS_FUNC (fixP->fx_addsy)
29813 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29814 {
29815 fixP->fx_done = 0;
29816 }
7af67752 29817 if ((value & ~0x7f) && ((value & ~0x3f) != (valueT) ~0x3f))
f6b2b12d
AV
29818 as_bad_where (fixP->fx_file, fixP->fx_line,
29819 _("branch out of range"));
29820
29821 if (fixP->fx_done || !seg->use_rela_p)
29822 {
29823 newval = md_chars_to_number (buf, THUMB_SIZE);
29824
29825 addressT boff = ((newval & 0x0780) >> 7) << 1;
29826 addressT diff = value - boff;
29827
29828 if (diff == 4)
29829 {
29830 newval |= 1 << 1; /* T bit. */
29831 }
29832 else if (diff != 2)
29833 {
29834 as_bad_where (fixP->fx_file, fixP->fx_line,
29835 _("out of range label-relative fixup value"));
29836 }
29837 md_number_to_chars (buf, newval, THUMB_SIZE);
29838 }
29839 break;
29840
e5d6e09e
AV
29841 case BFD_RELOC_ARM_THUMB_BF17:
29842 if (fixP->fx_addsy
29843 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29844 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29845 && ARM_IS_FUNC (fixP->fx_addsy)
29846 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29847 {
29848 /* Force a relocation for a branch 17 bits wide. */
29849 fixP->fx_done = 0;
29850 }
29851
29852 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29853 as_bad_where (fixP->fx_file, fixP->fx_line,
29854 BAD_BRANCH_OFF);
29855
29856 if (fixP->fx_done || !seg->use_rela_p)
29857 {
29858 offsetT newval2;
29859 addressT immA, immB, immC;
29860
29861 immA = (value & 0x0001f000) >> 12;
29862 immB = (value & 0x00000ffc) >> 2;
29863 immC = (value & 0x00000002) >> 1;
29864
29865 newval = md_chars_to_number (buf, THUMB_SIZE);
29866 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29867 newval |= immA;
29868 newval2 |= (immC << 11) | (immB << 1);
29869 md_number_to_chars (buf, newval, THUMB_SIZE);
29870 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29871 }
29872 break;
29873
1caf72a5
AV
29874 case BFD_RELOC_ARM_THUMB_BF19:
29875 if (fixP->fx_addsy
29876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29877 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29878 && ARM_IS_FUNC (fixP->fx_addsy)
29879 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29880 {
29881 /* Force a relocation for a branch 19 bits wide. */
29882 fixP->fx_done = 0;
29883 }
29884
29885 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29886 as_bad_where (fixP->fx_file, fixP->fx_line,
29887 BAD_BRANCH_OFF);
29888
29889 if (fixP->fx_done || !seg->use_rela_p)
29890 {
29891 offsetT newval2;
29892 addressT immA, immB, immC;
29893
29894 immA = (value & 0x0007f000) >> 12;
29895 immB = (value & 0x00000ffc) >> 2;
29896 immC = (value & 0x00000002) >> 1;
29897
29898 newval = md_chars_to_number (buf, THUMB_SIZE);
29899 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29900 newval |= immA;
29901 newval2 |= (immC << 11) | (immB << 1);
29902 md_number_to_chars (buf, newval, THUMB_SIZE);
29903 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29904 }
29905 break;
29906
1889da70
AV
29907 case BFD_RELOC_ARM_THUMB_BF13:
29908 if (fixP->fx_addsy
29909 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29910 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29911 && ARM_IS_FUNC (fixP->fx_addsy)
29912 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29913 {
29914 /* Force a relocation for a branch 13 bits wide. */
29915 fixP->fx_done = 0;
29916 }
29917
29918 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29919 as_bad_where (fixP->fx_file, fixP->fx_line,
29920 BAD_BRANCH_OFF);
29921
29922 if (fixP->fx_done || !seg->use_rela_p)
29923 {
29924 offsetT newval2;
29925 addressT immA, immB, immC;
29926
29927 immA = (value & 0x00001000) >> 12;
29928 immB = (value & 0x00000ffc) >> 2;
29929 immC = (value & 0x00000002) >> 1;
29930
29931 newval = md_chars_to_number (buf, THUMB_SIZE);
29932 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29933 newval |= immA;
29934 newval2 |= (immC << 11) | (immB << 1);
29935 md_number_to_chars (buf, newval, THUMB_SIZE);
29936 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29937 }
29938 break;
29939
60f993ce
AV
29940 case BFD_RELOC_ARM_THUMB_LOOP12:
29941 if (fixP->fx_addsy
29942 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29943 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29944 && ARM_IS_FUNC (fixP->fx_addsy)
29945 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29946 {
29947 /* Force a relocation for a branch 12 bits wide. */
29948 fixP->fx_done = 0;
29949 }
29950
29951 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 29952 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 29953 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
29954 || ((insn & 0xffffffff) == 0xf02fc001)
29955 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
29956 value = -value;
29957
29958 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29959 as_bad_where (fixP->fx_file, fixP->fx_line,
29960 BAD_BRANCH_OFF);
29961 if (fixP->fx_done || !seg->use_rela_p)
29962 {
29963 addressT imml, immh;
29964
29965 immh = (value & 0x00000ffc) >> 2;
29966 imml = (value & 0x00000002) >> 1;
29967
29968 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29969 newval |= (imml << 11) | (immh << 1);
29970 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29971 }
29972 break;
29973
845b51d6
PB
29974 case BFD_RELOC_ARM_V4BX:
29975 /* This will need to go in the object file. */
29976 fixP->fx_done = 0;
29977 break;
29978
c19d1205
ZW
29979 case BFD_RELOC_UNUSED:
29980 default:
29981 as_bad_where (fixP->fx_file, fixP->fx_line,
29982 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29983 }
6c43fab6
RE
29984}
29985
c19d1205
ZW
29986/* Translate internal representation of relocation info to BFD target
29987 format. */
a737bd4d 29988
c19d1205 29989arelent *
00a97672 29990tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29991{
c19d1205
ZW
29992 arelent * reloc;
29993 bfd_reloc_code_real_type code;
a737bd4d 29994
325801bd 29995 reloc = XNEW (arelent);
a737bd4d 29996
325801bd 29997 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
29998 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29999 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 30000
2fc8bdac 30001 if (fixp->fx_pcrel)
00a97672
RS
30002 {
30003 if (section->use_rela_p)
30004 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
30005 else
30006 fixp->fx_offset = reloc->address;
30007 }
c19d1205 30008 reloc->addend = fixp->fx_offset;
a737bd4d 30009
c19d1205 30010 switch (fixp->fx_r_type)
a737bd4d 30011 {
c19d1205
ZW
30012 case BFD_RELOC_8:
30013 if (fixp->fx_pcrel)
30014 {
30015 code = BFD_RELOC_8_PCREL;
30016 break;
30017 }
1a0670f3 30018 /* Fall through. */
a737bd4d 30019
c19d1205
ZW
30020 case BFD_RELOC_16:
30021 if (fixp->fx_pcrel)
30022 {
30023 code = BFD_RELOC_16_PCREL;
30024 break;
30025 }
1a0670f3 30026 /* Fall through. */
6c43fab6 30027
c19d1205
ZW
30028 case BFD_RELOC_32:
30029 if (fixp->fx_pcrel)
30030 {
30031 code = BFD_RELOC_32_PCREL;
30032 break;
30033 }
1a0670f3 30034 /* Fall through. */
a737bd4d 30035
b6895b4f
PB
30036 case BFD_RELOC_ARM_MOVW:
30037 if (fixp->fx_pcrel)
30038 {
30039 code = BFD_RELOC_ARM_MOVW_PCREL;
30040 break;
30041 }
1a0670f3 30042 /* Fall through. */
b6895b4f
PB
30043
30044 case BFD_RELOC_ARM_MOVT:
30045 if (fixp->fx_pcrel)
30046 {
30047 code = BFD_RELOC_ARM_MOVT_PCREL;
30048 break;
30049 }
1a0670f3 30050 /* Fall through. */
b6895b4f
PB
30051
30052 case BFD_RELOC_ARM_THUMB_MOVW:
30053 if (fixp->fx_pcrel)
30054 {
30055 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30056 break;
30057 }
1a0670f3 30058 /* Fall through. */
b6895b4f
PB
30059
30060 case BFD_RELOC_ARM_THUMB_MOVT:
30061 if (fixp->fx_pcrel)
30062 {
30063 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30064 break;
30065 }
1a0670f3 30066 /* Fall through. */
b6895b4f 30067
c19d1205
ZW
30068 case BFD_RELOC_NONE:
30069 case BFD_RELOC_ARM_PCREL_BRANCH:
30070 case BFD_RELOC_ARM_PCREL_BLX:
30071 case BFD_RELOC_RVA:
30072 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30073 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30074 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30075 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30076 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30077 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
30078 case BFD_RELOC_VTABLE_ENTRY:
30079 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
30080#ifdef TE_PE
30081 case BFD_RELOC_32_SECREL:
30082#endif
c19d1205
ZW
30083 code = fixp->fx_r_type;
30084 break;
a737bd4d 30085
00adf2d4
JB
30086 case BFD_RELOC_THUMB_PCREL_BLX:
30087#ifdef OBJ_ELF
30088 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30089 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30090 else
30091#endif
30092 code = BFD_RELOC_THUMB_PCREL_BLX;
30093 break;
30094
c19d1205
ZW
30095 case BFD_RELOC_ARM_LITERAL:
30096 case BFD_RELOC_ARM_HWLITERAL:
30097 /* If this is called then the a literal has
30098 been referenced across a section boundary. */
30099 as_bad_where (fixp->fx_file, fixp->fx_line,
30100 _("literal referenced across section boundary"));
30101 return NULL;
a737bd4d 30102
c19d1205 30103#ifdef OBJ_ELF
0855e32b
NS
30104 case BFD_RELOC_ARM_TLS_CALL:
30105 case BFD_RELOC_ARM_THM_TLS_CALL:
30106 case BFD_RELOC_ARM_TLS_DESCSEQ:
30107 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
30108 case BFD_RELOC_ARM_GOT32:
30109 case BFD_RELOC_ARM_GOTOFF:
b43420e6 30110 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
30111 case BFD_RELOC_ARM_PLT32:
30112 case BFD_RELOC_ARM_TARGET1:
30113 case BFD_RELOC_ARM_ROSEGREL32:
30114 case BFD_RELOC_ARM_SBREL32:
30115 case BFD_RELOC_ARM_PREL31:
30116 case BFD_RELOC_ARM_TARGET2:
c19d1205 30117 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
30118 case BFD_RELOC_ARM_PCREL_CALL:
30119 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
30120 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30121 case BFD_RELOC_ARM_ALU_PC_G0:
30122 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30123 case BFD_RELOC_ARM_ALU_PC_G1:
30124 case BFD_RELOC_ARM_ALU_PC_G2:
30125 case BFD_RELOC_ARM_LDR_PC_G0:
30126 case BFD_RELOC_ARM_LDR_PC_G1:
30127 case BFD_RELOC_ARM_LDR_PC_G2:
30128 case BFD_RELOC_ARM_LDRS_PC_G0:
30129 case BFD_RELOC_ARM_LDRS_PC_G1:
30130 case BFD_RELOC_ARM_LDRS_PC_G2:
30131 case BFD_RELOC_ARM_LDC_PC_G0:
30132 case BFD_RELOC_ARM_LDC_PC_G1:
30133 case BFD_RELOC_ARM_LDC_PC_G2:
30134 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30135 case BFD_RELOC_ARM_ALU_SB_G0:
30136 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30137 case BFD_RELOC_ARM_ALU_SB_G1:
30138 case BFD_RELOC_ARM_ALU_SB_G2:
30139 case BFD_RELOC_ARM_LDR_SB_G0:
30140 case BFD_RELOC_ARM_LDR_SB_G1:
30141 case BFD_RELOC_ARM_LDR_SB_G2:
30142 case BFD_RELOC_ARM_LDRS_SB_G0:
30143 case BFD_RELOC_ARM_LDRS_SB_G1:
30144 case BFD_RELOC_ARM_LDRS_SB_G2:
30145 case BFD_RELOC_ARM_LDC_SB_G0:
30146 case BFD_RELOC_ARM_LDC_SB_G1:
30147 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 30148 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
30149 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30150 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30151 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30152 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
30153 case BFD_RELOC_ARM_GOTFUNCDESC:
30154 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30155 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 30156 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 30157 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 30158 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
30159 code = fixp->fx_r_type;
30160 break;
a737bd4d 30161
0855e32b 30162 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 30163 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 30164 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 30165 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 30166 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 30167 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 30168 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 30169 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
30170 /* BFD will include the symbol's address in the addend.
30171 But we don't want that, so subtract it out again here. */
30172 if (!S_IS_COMMON (fixp->fx_addsy))
30173 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30174 code = fixp->fx_r_type;
30175 break;
30176#endif
a737bd4d 30177
c19d1205
ZW
30178 case BFD_RELOC_ARM_IMMEDIATE:
30179 as_bad_where (fixp->fx_file, fixp->fx_line,
30180 _("internal relocation (type: IMMEDIATE) not fixed up"));
30181 return NULL;
a737bd4d 30182
c19d1205
ZW
30183 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30184 as_bad_where (fixp->fx_file, fixp->fx_line,
30185 _("ADRL used for a symbol not defined in the same file"));
30186 return NULL;
a737bd4d 30187
e12437dc 30188 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 30189 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 30190 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
30191 as_bad_where (fixp->fx_file, fixp->fx_line,
30192 _("%s used for a symbol not defined in the same file"),
30193 bfd_get_reloc_code_name (fixp->fx_r_type));
30194 return NULL;
30195
c19d1205 30196 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
30197 if (section->use_rela_p)
30198 {
30199 code = fixp->fx_r_type;
30200 break;
30201 }
30202
c19d1205
ZW
30203 if (fixp->fx_addsy != NULL
30204 && !S_IS_DEFINED (fixp->fx_addsy)
30205 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 30206 {
c19d1205
ZW
30207 as_bad_where (fixp->fx_file, fixp->fx_line,
30208 _("undefined local label `%s'"),
30209 S_GET_NAME (fixp->fx_addsy));
30210 return NULL;
a737bd4d
NC
30211 }
30212
c19d1205
ZW
30213 as_bad_where (fixp->fx_file, fixp->fx_line,
30214 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30215 return NULL;
a737bd4d 30216
c19d1205
ZW
30217 default:
30218 {
e0471c16 30219 const char * type;
6c43fab6 30220
c19d1205
ZW
30221 switch (fixp->fx_r_type)
30222 {
30223 case BFD_RELOC_NONE: type = "NONE"; break;
30224 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30225 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 30226 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
30227 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30228 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30229 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 30230 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 30231 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
30232 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30233 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30234 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30235 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30236 default: type = _("<unknown>"); break;
30237 }
30238 as_bad_where (fixp->fx_file, fixp->fx_line,
30239 _("cannot represent %s relocation in this object file format"),
30240 type);
30241 return NULL;
30242 }
a737bd4d 30243 }
6c43fab6 30244
c19d1205
ZW
30245#ifdef OBJ_ELF
30246 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30247 && GOT_symbol
30248 && fixp->fx_addsy == GOT_symbol)
30249 {
30250 code = BFD_RELOC_ARM_GOTPC;
30251 reloc->addend = fixp->fx_offset = reloc->address;
30252 }
30253#endif
6c43fab6 30254
c19d1205 30255 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 30256
c19d1205
ZW
30257 if (reloc->howto == NULL)
30258 {
30259 as_bad_where (fixp->fx_file, fixp->fx_line,
30260 _("cannot represent %s relocation in this object file format"),
30261 bfd_get_reloc_code_name (code));
30262 return NULL;
30263 }
6c43fab6 30264
c19d1205
ZW
30265 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30266 vtable entry to be used in the relocation's section offset. */
30267 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30268 reloc->address = fixp->fx_offset;
6c43fab6 30269
c19d1205 30270 return reloc;
6c43fab6
RE
30271}
30272
c19d1205 30273/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 30274
c19d1205
ZW
30275void
30276cons_fix_new_arm (fragS * frag,
30277 int where,
30278 int size,
62ebcb5c
AM
30279 expressionS * exp,
30280 bfd_reloc_code_real_type reloc)
6c43fab6 30281{
c19d1205 30282 int pcrel = 0;
6c43fab6 30283
c19d1205
ZW
30284 /* Pick a reloc.
30285 FIXME: @@ Should look at CPU word size. */
30286 switch (size)
30287 {
30288 case 1:
62ebcb5c 30289 reloc = BFD_RELOC_8;
c19d1205
ZW
30290 break;
30291 case 2:
62ebcb5c 30292 reloc = BFD_RELOC_16;
c19d1205
ZW
30293 break;
30294 case 4:
30295 default:
62ebcb5c 30296 reloc = BFD_RELOC_32;
c19d1205
ZW
30297 break;
30298 case 8:
62ebcb5c 30299 reloc = BFD_RELOC_64;
c19d1205
ZW
30300 break;
30301 }
6c43fab6 30302
f0927246
NC
30303#ifdef TE_PE
30304 if (exp->X_op == O_secrel)
30305 {
30306 exp->X_op = O_symbol;
62ebcb5c 30307 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
30308 }
30309#endif
30310
62ebcb5c 30311 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 30312}
6c43fab6 30313
4343666d 30314#if defined (OBJ_COFF)
c19d1205
ZW
30315void
30316arm_validate_fix (fixS * fixP)
6c43fab6 30317{
c19d1205
ZW
30318 /* If the destination of the branch is a defined symbol which does not have
30319 the THUMB_FUNC attribute, then we must be calling a function which has
30320 the (interfacearm) attribute. We look for the Thumb entry point to that
30321 function and change the branch to refer to that function instead. */
30322 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30323 && fixP->fx_addsy != NULL
30324 && S_IS_DEFINED (fixP->fx_addsy)
30325 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 30326 {
c19d1205 30327 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 30328 }
c19d1205
ZW
30329}
30330#endif
6c43fab6 30331
267bf995 30332
c19d1205
ZW
30333int
30334arm_force_relocation (struct fix * fixp)
30335{
30336#if defined (OBJ_COFF) && defined (TE_PE)
30337 if (fixp->fx_r_type == BFD_RELOC_RVA)
30338 return 1;
30339#endif
6c43fab6 30340
267bf995
RR
30341 /* In case we have a call or a branch to a function in ARM ISA mode from
30342 a thumb function or vice-versa force the relocation. These relocations
30343 are cleared off for some cores that might have blx and simple transformations
30344 are possible. */
30345
30346#ifdef OBJ_ELF
30347 switch (fixp->fx_r_type)
30348 {
30349 case BFD_RELOC_ARM_PCREL_JUMP:
30350 case BFD_RELOC_ARM_PCREL_CALL:
30351 case BFD_RELOC_THUMB_PCREL_BLX:
30352 if (THUMB_IS_FUNC (fixp->fx_addsy))
30353 return 1;
30354 break;
30355
30356 case BFD_RELOC_ARM_PCREL_BLX:
30357 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30358 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30359 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30360 if (ARM_IS_FUNC (fixp->fx_addsy))
30361 return 1;
30362 break;
30363
30364 default:
30365 break;
30366 }
30367#endif
30368
b5884301
PB
30369 /* Resolve these relocations even if the symbol is extern or weak.
30370 Technically this is probably wrong due to symbol preemption.
30371 In practice these relocations do not have enough range to be useful
30372 at dynamic link time, and some code (e.g. in the Linux kernel)
30373 expects these references to be resolved. */
c19d1205
ZW
30374 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30375 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 30376 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 30377 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
30378 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30379 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30380 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
b59d128a 30381 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH12
16805f35 30382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
30383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30384 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
30385 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30386 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30387 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30388 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 30389 return 0;
a737bd4d 30390
4962c51a
MS
30391 /* Always leave these relocations for the linker. */
30392 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30393 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30394 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30395 return 1;
30396
f0291e4c
PB
30397 /* Always generate relocations against function symbols. */
30398 if (fixp->fx_r_type == BFD_RELOC_32
30399 && fixp->fx_addsy
30400 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30401 return 1;
30402
c19d1205 30403 return generic_force_reloc (fixp);
404ff6b5
AH
30404}
30405
0ffdc86c 30406#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
30407/* Relocations against function names must be left unadjusted,
30408 so that the linker can use this information to generate interworking
30409 stubs. The MIPS version of this function
c19d1205
ZW
30410 also prevents relocations that are mips-16 specific, but I do not
30411 know why it does this.
404ff6b5 30412
c19d1205
ZW
30413 FIXME:
30414 There is one other problem that ought to be addressed here, but
30415 which currently is not: Taking the address of a label (rather
30416 than a function) and then later jumping to that address. Such
30417 addresses also ought to have their bottom bit set (assuming that
30418 they reside in Thumb code), but at the moment they will not. */
404ff6b5 30419
c19d1205
ZW
30420bfd_boolean
30421arm_fix_adjustable (fixS * fixP)
404ff6b5 30422{
c19d1205
ZW
30423 if (fixP->fx_addsy == NULL)
30424 return 1;
404ff6b5 30425
e28387c3
PB
30426 /* Preserve relocations against symbols with function type. */
30427 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 30428 return FALSE;
e28387c3 30429
c19d1205
ZW
30430 if (THUMB_IS_FUNC (fixP->fx_addsy)
30431 && fixP->fx_subsy == NULL)
c921be7d 30432 return FALSE;
a737bd4d 30433
c19d1205
ZW
30434 /* We need the symbol name for the VTABLE entries. */
30435 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30436 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 30437 return FALSE;
404ff6b5 30438
c19d1205
ZW
30439 /* Don't allow symbols to be discarded on GOT related relocs. */
30440 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30441 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30442 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 30444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
30445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 30447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 30448 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 30449 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 30450 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
30451 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30452 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30453 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30454 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30455 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 30456 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 30457 return FALSE;
a737bd4d 30458
4962c51a
MS
30459 /* Similarly for group relocations. */
30460 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30461 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30462 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 30463 return FALSE;
4962c51a 30464
79947c54
CD
30465 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30466 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30467 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30468 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30469 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30470 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30471 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30472 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30473 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 30474 return FALSE;
79947c54 30475
72d98d16
MG
30476 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30477 offsets, so keep these symbols. */
30478 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30479 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30480 return FALSE;
30481
c921be7d 30482 return TRUE;
a737bd4d 30483}
0ffdc86c
NC
30484#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30485
30486#ifdef OBJ_ELF
c19d1205
ZW
30487const char *
30488elf32_arm_target_format (void)
404ff6b5 30489{
c19d1205
ZW
30490#ifdef TE_SYMBIAN
30491 return (target_big_endian
30492 ? "elf32-bigarm-symbian"
30493 : "elf32-littlearm-symbian");
30494#elif defined (TE_VXWORKS)
30495 return (target_big_endian
30496 ? "elf32-bigarm-vxworks"
30497 : "elf32-littlearm-vxworks");
b38cadfb
NC
30498#elif defined (TE_NACL)
30499 return (target_big_endian
30500 ? "elf32-bigarm-nacl"
30501 : "elf32-littlearm-nacl");
c19d1205 30502#else
18a20338
CL
30503 if (arm_fdpic)
30504 {
30505 if (target_big_endian)
30506 return "elf32-bigarm-fdpic";
30507 else
30508 return "elf32-littlearm-fdpic";
30509 }
c19d1205 30510 else
18a20338
CL
30511 {
30512 if (target_big_endian)
30513 return "elf32-bigarm";
30514 else
30515 return "elf32-littlearm";
30516 }
c19d1205 30517#endif
404ff6b5
AH
30518}
30519
c19d1205
ZW
30520void
30521armelf_frob_symbol (symbolS * symp,
30522 int * puntp)
404ff6b5 30523{
c19d1205
ZW
30524 elf_frob_symbol (symp, puntp);
30525}
30526#endif
404ff6b5 30527
c19d1205 30528/* MD interface: Finalization. */
a737bd4d 30529
c19d1205
ZW
30530void
30531arm_cleanup (void)
30532{
30533 literal_pool * pool;
a737bd4d 30534
5ee91343
AV
30535 /* Ensure that all the predication blocks are properly closed. */
30536 check_pred_blocks_finished ();
e07e6e58 30537
c19d1205
ZW
30538 for (pool = list_of_pools; pool; pool = pool->next)
30539 {
5f4273c7 30540 /* Put it at the end of the relevant section. */
c19d1205
ZW
30541 subseg_set (pool->section, pool->sub_section);
30542#ifdef OBJ_ELF
30543 arm_elf_change_section ();
30544#endif
30545 s_ltorg (0);
30546 }
404ff6b5
AH
30547}
30548
cd000bff
DJ
30549#ifdef OBJ_ELF
30550/* Remove any excess mapping symbols generated for alignment frags in
30551 SEC. We may have created a mapping symbol before a zero byte
30552 alignment; remove it if there's a mapping symbol after the
30553 alignment. */
30554static void
30555check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30556 void *dummy ATTRIBUTE_UNUSED)
30557{
30558 segment_info_type *seginfo = seg_info (sec);
30559 fragS *fragp;
30560
30561 if (seginfo == NULL || seginfo->frchainP == NULL)
30562 return;
30563
30564 for (fragp = seginfo->frchainP->frch_root;
30565 fragp != NULL;
30566 fragp = fragp->fr_next)
30567 {
30568 symbolS *sym = fragp->tc_frag_data.last_map;
30569 fragS *next = fragp->fr_next;
30570
30571 /* Variable-sized frags have been converted to fixed size by
30572 this point. But if this was variable-sized to start with,
30573 there will be a fixed-size frag after it. So don't handle
30574 next == NULL. */
30575 if (sym == NULL || next == NULL)
30576 continue;
30577
30578 if (S_GET_VALUE (sym) < next->fr_address)
30579 /* Not at the end of this frag. */
30580 continue;
30581 know (S_GET_VALUE (sym) == next->fr_address);
30582
30583 do
30584 {
30585 if (next->tc_frag_data.first_map != NULL)
30586 {
30587 /* Next frag starts with a mapping symbol. Discard this
30588 one. */
30589 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30590 break;
30591 }
30592
30593 if (next->fr_next == NULL)
30594 {
30595 /* This mapping symbol is at the end of the section. Discard
30596 it. */
30597 know (next->fr_fix == 0 && next->fr_var == 0);
30598 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30599 break;
30600 }
30601
30602 /* As long as we have empty frags without any mapping symbols,
30603 keep looking. */
30604 /* If the next frag is non-empty and does not start with a
30605 mapping symbol, then this mapping symbol is required. */
30606 if (next->fr_address != next->fr_next->fr_address)
30607 break;
30608
30609 next = next->fr_next;
30610 }
30611 while (next != NULL);
30612 }
30613}
30614#endif
30615
c19d1205
ZW
30616/* Adjust the symbol table. This marks Thumb symbols as distinct from
30617 ARM ones. */
404ff6b5 30618
c19d1205
ZW
30619void
30620arm_adjust_symtab (void)
404ff6b5 30621{
c19d1205
ZW
30622#ifdef OBJ_COFF
30623 symbolS * sym;
404ff6b5 30624
c19d1205
ZW
30625 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30626 {
30627 if (ARM_IS_THUMB (sym))
30628 {
30629 if (THUMB_IS_FUNC (sym))
30630 {
30631 /* Mark the symbol as a Thumb function. */
30632 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30633 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30634 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 30635
c19d1205
ZW
30636 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30637 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30638 else
30639 as_bad (_("%s: unexpected function type: %d"),
30640 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30641 }
30642 else switch (S_GET_STORAGE_CLASS (sym))
30643 {
30644 case C_EXT:
30645 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30646 break;
30647 case C_STAT:
30648 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30649 break;
30650 case C_LABEL:
30651 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30652 break;
30653 default:
30654 /* Do nothing. */
30655 break;
30656 }
30657 }
a737bd4d 30658
c19d1205
ZW
30659 if (ARM_IS_INTERWORK (sym))
30660 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 30661 }
c19d1205
ZW
30662#endif
30663#ifdef OBJ_ELF
30664 symbolS * sym;
30665 char bind;
404ff6b5 30666
c19d1205 30667 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 30668 {
c19d1205
ZW
30669 if (ARM_IS_THUMB (sym))
30670 {
30671 elf_symbol_type * elf_sym;
404ff6b5 30672
c19d1205
ZW
30673 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30674 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 30675
b0796911
PB
30676 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30677 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
30678 {
30679 /* If it's a .thumb_func, declare it as so,
30680 otherwise tag label as .code 16. */
30681 if (THUMB_IS_FUNC (sym))
39d911fc
TP
30682 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30683 ST_BRANCH_TO_THUMB);
3ba67470 30684 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
30685 elf_sym->internal_elf_sym.st_info =
30686 ELF_ST_INFO (bind, STT_ARM_16BIT);
30687 }
30688 }
30689 }
cd000bff
DJ
30690
30691 /* Remove any overlapping mapping symbols generated by alignment frags. */
30692 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
30693 /* Now do generic ELF adjustments. */
30694 elf_adjust_symtab ();
c19d1205 30695#endif
404ff6b5
AH
30696}
30697
c19d1205 30698/* MD interface: Initialization. */
404ff6b5 30699
a737bd4d 30700static void
c19d1205 30701set_constant_flonums (void)
a737bd4d 30702{
c19d1205 30703 int i;
404ff6b5 30704
c19d1205
ZW
30705 for (i = 0; i < NUM_FLOAT_VALS; i++)
30706 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30707 abort ();
a737bd4d 30708}
404ff6b5 30709
3e9e4fcf
JB
30710/* Auto-select Thumb mode if it's the only available instruction set for the
30711 given architecture. */
30712
30713static void
30714autoselect_thumb_from_cpu_variant (void)
30715{
30716 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30717 opcode_select (16);
30718}
30719
c19d1205
ZW
30720void
30721md_begin (void)
a737bd4d 30722{
c19d1205
ZW
30723 unsigned mach;
30724 unsigned int i;
404ff6b5 30725
f16c3d4f
AM
30726 arm_ops_hsh = str_htab_create ();
30727 arm_cond_hsh = str_htab_create ();
30728 arm_vcond_hsh = str_htab_create ();
30729 arm_shift_hsh = str_htab_create ();
30730 arm_psr_hsh = str_htab_create ();
30731 arm_v7m_psr_hsh = str_htab_create ();
30732 arm_reg_hsh = str_htab_create ();
30733 arm_reloc_hsh = str_htab_create ();
30734 arm_barrier_opt_hsh = str_htab_create ();
c19d1205
ZW
30735
30736 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
629310ab 30737 if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL)
fe0e921f 30738 str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0);
c19d1205 30739 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
fe0e921f 30740 str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0);
5ee91343 30741 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
fe0e921f 30742 str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0);
c19d1205 30743 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
fe0e921f 30744 str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0);
c19d1205 30745 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
fe0e921f 30746 str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0);
62b3e311 30747 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
629310ab 30748 str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
fe0e921f 30749 v7m_psrs + i, 0);
c19d1205 30750 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
fe0e921f 30751 str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0);
62b3e311
PB
30752 for (i = 0;
30753 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30754 i++)
629310ab 30755 str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
fe0e921f 30756 barrier_opt_names + i, 0);
c19d1205 30757#ifdef OBJ_ELF
3da1d841
NC
30758 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30759 {
30760 struct reloc_entry * entry = reloc_names + i;
30761
30762 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30763 /* This makes encode_branch() use the EABI versions of this relocation. */
30764 entry->reloc = BFD_RELOC_UNUSED;
30765
fe0e921f 30766 str_hash_insert (arm_reloc_hsh, entry->name, entry, 0);
3da1d841 30767 }
c19d1205
ZW
30768#endif
30769
30770 set_constant_flonums ();
404ff6b5 30771
c19d1205
ZW
30772 /* Set the cpu variant based on the command-line options. We prefer
30773 -mcpu= over -march= if both are set (as for GCC); and we prefer
30774 -mfpu= over any other way of setting the floating point unit.
30775 Use of legacy options with new options are faulted. */
e74cfd16 30776 if (legacy_cpu)
404ff6b5 30777 {
e74cfd16 30778 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
30779 as_bad (_("use of old and new-style options to set CPU type"));
30780
4d354d8b 30781 selected_arch = *legacy_cpu;
404ff6b5 30782 }
4d354d8b
TP
30783 else if (mcpu_cpu_opt)
30784 {
30785 selected_arch = *mcpu_cpu_opt;
30786 selected_ext = *mcpu_ext_opt;
30787 }
30788 else if (march_cpu_opt)
c168ce07 30789 {
4d354d8b
TP
30790 selected_arch = *march_cpu_opt;
30791 selected_ext = *march_ext_opt;
c168ce07 30792 }
4d354d8b 30793 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 30794
e74cfd16 30795 if (legacy_fpu)
c19d1205 30796 {
e74cfd16 30797 if (mfpu_opt)
c19d1205 30798 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 30799
4d354d8b 30800 selected_fpu = *legacy_fpu;
03b1477f 30801 }
4d354d8b
TP
30802 else if (mfpu_opt)
30803 selected_fpu = *mfpu_opt;
30804 else
03b1477f 30805 {
45eb4c1b
NS
30806#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30807 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
30808 /* Some environments specify a default FPU. If they don't, infer it
30809 from the processor. */
e74cfd16 30810 if (mcpu_fpu_opt)
4d354d8b 30811 selected_fpu = *mcpu_fpu_opt;
e7da50fa 30812 else if (march_fpu_opt)
4d354d8b 30813 selected_fpu = *march_fpu_opt;
39c2da32 30814#else
4d354d8b 30815 selected_fpu = fpu_default;
39c2da32 30816#endif
03b1477f
RE
30817 }
30818
4d354d8b 30819 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 30820 {
4d354d8b
TP
30821 if (!no_cpu_selected ())
30822 selected_fpu = fpu_default;
03b1477f 30823 else
4d354d8b 30824 selected_fpu = fpu_arch_fpa;
03b1477f
RE
30825 }
30826
ee065d83 30827#ifdef CPU_DEFAULT
4d354d8b 30828 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 30829 {
4d354d8b
TP
30830 selected_arch = cpu_default;
30831 selected_cpu = selected_arch;
ee065d83 30832 }
4d354d8b 30833 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 30834#else
4d354d8b
TP
30835 /* Autodection of feature mode: allow all features in cpu_variant but leave
30836 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30837 after all instruction have been processed and we can decide what CPU
30838 should be selected. */
30839 if (ARM_FEATURE_ZERO (selected_arch))
30840 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 30841 else
4d354d8b 30842 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 30843#endif
03b1477f 30844
3e9e4fcf
JB
30845 autoselect_thumb_from_cpu_variant ();
30846
e74cfd16 30847 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 30848
f17c130b 30849#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 30850 {
7cc69913
NC
30851 unsigned int flags = 0;
30852
30853#if defined OBJ_ELF
30854 flags = meabi_flags;
d507cf36
PB
30855
30856 switch (meabi_flags)
33a392fb 30857 {
d507cf36 30858 case EF_ARM_EABI_UNKNOWN:
7cc69913 30859#endif
d507cf36
PB
30860 /* Set the flags in the private structure. */
30861 if (uses_apcs_26) flags |= F_APCS26;
30862 if (support_interwork) flags |= F_INTERWORK;
30863 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 30864 if (pic_code) flags |= F_PIC;
e74cfd16 30865 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
30866 flags |= F_SOFT_FLOAT;
30867
d507cf36
PB
30868 switch (mfloat_abi_opt)
30869 {
30870 case ARM_FLOAT_ABI_SOFT:
30871 case ARM_FLOAT_ABI_SOFTFP:
30872 flags |= F_SOFT_FLOAT;
30873 break;
33a392fb 30874
d507cf36
PB
30875 case ARM_FLOAT_ABI_HARD:
30876 if (flags & F_SOFT_FLOAT)
30877 as_bad (_("hard-float conflicts with specified fpu"));
30878 break;
30879 }
03b1477f 30880
e74cfd16
PB
30881 /* Using pure-endian doubles (even if soft-float). */
30882 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 30883 flags |= F_VFP_FLOAT;
f17c130b 30884
fde78edd 30885#if defined OBJ_ELF
e74cfd16 30886 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 30887 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
30888 break;
30889
8cb51566 30890 case EF_ARM_EABI_VER4:
3a4a14e9 30891 case EF_ARM_EABI_VER5:
c19d1205 30892 /* No additional flags to set. */
d507cf36
PB
30893 break;
30894
30895 default:
30896 abort ();
30897 }
7cc69913 30898#endif
b99bd4ef
NC
30899 bfd_set_private_flags (stdoutput, flags);
30900
30901 /* We have run out flags in the COFF header to encode the
30902 status of ATPCS support, so instead we create a dummy,
c19d1205 30903 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
30904 if (atpcs)
30905 {
30906 asection * sec;
30907
30908 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30909
30910 if (sec != NULL)
30911 {
fd361982
AM
30912 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30913 bfd_set_section_size (sec, 0);
b99bd4ef
NC
30914 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30915 }
30916 }
7cc69913 30917 }
f17c130b 30918#endif
b99bd4ef
NC
30919
30920 /* Record the CPU type as well. */
2d447fca
JM
30921 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30922 mach = bfd_mach_arm_iWMMXt2;
30923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 30924 mach = bfd_mach_arm_iWMMXt;
e74cfd16 30925 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 30926 mach = bfd_mach_arm_XScale;
e74cfd16 30927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 30928 mach = bfd_mach_arm_ep9312;
e74cfd16 30929 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 30930 mach = bfd_mach_arm_5TE;
e74cfd16 30931 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 30932 {
e74cfd16 30933 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30934 mach = bfd_mach_arm_5T;
30935 else
30936 mach = bfd_mach_arm_5;
30937 }
e74cfd16 30938 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 30939 {
e74cfd16 30940 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30941 mach = bfd_mach_arm_4T;
30942 else
30943 mach = bfd_mach_arm_4;
30944 }
e74cfd16 30945 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 30946 mach = bfd_mach_arm_3M;
e74cfd16
PB
30947 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30948 mach = bfd_mach_arm_3;
30949 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30950 mach = bfd_mach_arm_2a;
30951 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30952 mach = bfd_mach_arm_2;
30953 else
30954 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
30955
30956 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30957}
30958
c19d1205 30959/* Command line processing. */
b99bd4ef 30960
c19d1205
ZW
30961/* md_parse_option
30962 Invocation line includes a switch not recognized by the base assembler.
30963 See if it's a processor-specific option.
b99bd4ef 30964
c19d1205
ZW
30965 This routine is somewhat complicated by the need for backwards
30966 compatibility (since older releases of gcc can't be changed).
30967 The new options try to make the interface as compatible as
30968 possible with GCC.
b99bd4ef 30969
c19d1205 30970 New options (supported) are:
b99bd4ef 30971
c19d1205
ZW
30972 -mcpu=<cpu name> Assemble for selected processor
30973 -march=<architecture name> Assemble for selected architecture
30974 -mfpu=<fpu architecture> Assemble for selected FPU.
30975 -EB/-mbig-endian Big-endian
30976 -EL/-mlittle-endian Little-endian
30977 -k Generate PIC code
30978 -mthumb Start in Thumb mode
30979 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30980
278df34e 30981 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30982 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30983
c19d1205 30984 For now we will also provide support for:
b99bd4ef 30985
c19d1205
ZW
30986 -mapcs-32 32-bit Program counter
30987 -mapcs-26 26-bit Program counter
30988 -macps-float Floats passed in FP registers
30989 -mapcs-reentrant Reentrant code
30990 -matpcs
30991 (sometime these will probably be replaced with -mapcs=<list of options>
30992 and -matpcs=<list of options>)
b99bd4ef 30993
c19d1205
ZW
30994 The remaining options are only supported for back-wards compatibility.
30995 Cpu variants, the arm part is optional:
30996 -m[arm]1 Currently not supported.
30997 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30998 -m[arm]3 Arm 3 processor
30999 -m[arm]6[xx], Arm 6 processors
31000 -m[arm]7[xx][t][[d]m] Arm 7 processors
31001 -m[arm]8[10] Arm 8 processors
31002 -m[arm]9[20][tdmi] Arm 9 processors
31003 -mstrongarm[110[0]] StrongARM processors
31004 -mxscale XScale processors
31005 -m[arm]v[2345[t[e]]] Arm architectures
31006 -mall All (except the ARM1)
31007 FP variants:
31008 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
31009 -mfpe-old (No float load/store multiples)
31010 -mvfpxd VFP Single precision
31011 -mvfp All VFP
31012 -mno-fpu Disable all floating point instructions
b99bd4ef 31013
c19d1205
ZW
31014 The following CPU names are recognized:
31015 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31016 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31017 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31018 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31019 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31020 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31021 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 31022
c19d1205 31023 */
b99bd4ef 31024
c19d1205 31025const char * md_shortopts = "m:k";
b99bd4ef 31026
c19d1205
ZW
31027#ifdef ARM_BI_ENDIAN
31028#define OPTION_EB (OPTION_MD_BASE + 0)
31029#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 31030#else
c19d1205
ZW
31031#if TARGET_BYTES_BIG_ENDIAN
31032#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 31033#else
c19d1205
ZW
31034#define OPTION_EL (OPTION_MD_BASE + 1)
31035#endif
b99bd4ef 31036#endif
845b51d6 31037#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 31038#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 31039
c19d1205 31040struct option md_longopts[] =
b99bd4ef 31041{
c19d1205
ZW
31042#ifdef OPTION_EB
31043 {"EB", no_argument, NULL, OPTION_EB},
31044#endif
31045#ifdef OPTION_EL
31046 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 31047#endif
845b51d6 31048 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
31049#ifdef OBJ_ELF
31050 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31051#endif
c19d1205
ZW
31052 {NULL, no_argument, NULL, 0}
31053};
b99bd4ef 31054
c19d1205 31055size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 31056
c19d1205 31057struct arm_option_table
b99bd4ef 31058{
0198d5e6
TC
31059 const char * option; /* Option name to match. */
31060 const char * help; /* Help information. */
31061 int * var; /* Variable to change. */
31062 int value; /* What to change it to. */
31063 const char * deprecated; /* If non-null, print this message. */
c19d1205 31064};
b99bd4ef 31065
c19d1205
ZW
31066struct arm_option_table arm_opts[] =
31067{
31068 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31069 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31070 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31071 &support_interwork, 1, NULL},
31072 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31073 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31074 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31075 1, NULL},
31076 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31077 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31078 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31079 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31080 NULL},
b99bd4ef 31081
c19d1205
ZW
31082 /* These are recognized by the assembler, but have no affect on code. */
31083 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31084 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
31085
31086 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31087 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31088 &warn_on_deprecated, 0, NULL},
24f19ccb
AV
31089
31090 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31091 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31092 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31093
8b2d793c
NC
31094 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31095 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
31096 {NULL, NULL, NULL, 0, NULL}
31097};
31098
31099struct arm_legacy_option_table
31100{
0198d5e6
TC
31101 const char * option; /* Option name to match. */
31102 const arm_feature_set ** var; /* Variable to change. */
31103 const arm_feature_set value; /* What to change it to. */
31104 const char * deprecated; /* If non-null, print this message. */
e74cfd16 31105};
b99bd4ef 31106
e74cfd16
PB
31107const struct arm_legacy_option_table arm_legacy_opts[] =
31108{
c19d1205
ZW
31109 /* DON'T add any new processors to this list -- we want the whole list
31110 to go away... Add them to the processors table instead. */
e74cfd16
PB
31111 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31112 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31113 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31114 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31115 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31116 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31117 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31118 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31119 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31120 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31121 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31122 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31123 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31124 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31125 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31126 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31127 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31128 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31129 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31130 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31131 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31132 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31133 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31134 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31135 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31136 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31137 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31138 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31139 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31140 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31141 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31142 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31143 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31144 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31145 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31146 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31147 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31148 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31149 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31150 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31151 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31152 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31153 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31154 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31155 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31156 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31157 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31158 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31159 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31160 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31161 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31162 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31163 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31164 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31165 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31166 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31167 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31168 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31169 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31170 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31171 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31172 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31173 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31174 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31175 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31176 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31177 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31178 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31179 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31180 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31181 N_("use -mcpu=strongarm110")},
e74cfd16 31182 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31183 N_("use -mcpu=strongarm1100")},
e74cfd16 31184 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31185 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
31186 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31187 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31188 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 31189
c19d1205 31190 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
31191 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31192 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31193 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31194 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31195 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31196 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31197 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31198 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31199 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31200 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31201 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31202 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31203 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31204 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31205 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31206 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31207 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31208 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 31209
c19d1205 31210 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
31211 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31212 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31213 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31214 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 31215 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 31216
e74cfd16 31217 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 31218};
7ed4c4c5 31219
c19d1205 31220struct arm_cpu_option_table
7ed4c4c5 31221{
0198d5e6
TC
31222 const char * name;
31223 size_t name_len;
31224 const arm_feature_set value;
31225 const arm_feature_set ext;
c19d1205
ZW
31226 /* For some CPUs we assume an FPU unless the user explicitly sets
31227 -mfpu=... */
0198d5e6 31228 const arm_feature_set default_fpu;
ee065d83
PB
31229 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31230 case. */
0198d5e6 31231 const char * canonical_name;
c19d1205 31232};
7ed4c4c5 31233
c19d1205
ZW
31234/* This list should, at a minimum, contain all the cpu names
31235 recognized by GCC. */
996b5569 31236#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 31237
e74cfd16 31238static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 31239{
996b5569
TP
31240 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31241 ARM_ARCH_NONE,
31242 FPU_ARCH_FPA),
31243 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31244 ARM_ARCH_NONE,
31245 FPU_ARCH_FPA),
31246 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31247 ARM_ARCH_NONE,
31248 FPU_ARCH_FPA),
31249 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31250 ARM_ARCH_NONE,
31251 FPU_ARCH_FPA),
31252 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31253 ARM_ARCH_NONE,
31254 FPU_ARCH_FPA),
31255 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31256 ARM_ARCH_NONE,
31257 FPU_ARCH_FPA),
31258 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31259 ARM_ARCH_NONE,
31260 FPU_ARCH_FPA),
31261 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31262 ARM_ARCH_NONE,
31263 FPU_ARCH_FPA),
31264 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31265 ARM_ARCH_NONE,
31266 FPU_ARCH_FPA),
31267 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31268 ARM_ARCH_NONE,
31269 FPU_ARCH_FPA),
31270 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31271 ARM_ARCH_NONE,
31272 FPU_ARCH_FPA),
31273 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31274 ARM_ARCH_NONE,
31275 FPU_ARCH_FPA),
31276 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31277 ARM_ARCH_NONE,
31278 FPU_ARCH_FPA),
31279 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31280 ARM_ARCH_NONE,
31281 FPU_ARCH_FPA),
31282 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31283 ARM_ARCH_NONE,
31284 FPU_ARCH_FPA),
31285 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31286 ARM_ARCH_NONE,
31287 FPU_ARCH_FPA),
31288 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31289 ARM_ARCH_NONE,
31290 FPU_ARCH_FPA),
31291 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31292 ARM_ARCH_NONE,
31293 FPU_ARCH_FPA),
31294 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31295 ARM_ARCH_NONE,
31296 FPU_ARCH_FPA),
31297 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31298 ARM_ARCH_NONE,
31299 FPU_ARCH_FPA),
31300 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31301 ARM_ARCH_NONE,
31302 FPU_ARCH_FPA),
31303 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31304 ARM_ARCH_NONE,
31305 FPU_ARCH_FPA),
31306 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31307 ARM_ARCH_NONE,
31308 FPU_ARCH_FPA),
31309 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31310 ARM_ARCH_NONE,
31311 FPU_ARCH_FPA),
31312 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31313 ARM_ARCH_NONE,
31314 FPU_ARCH_FPA),
31315 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31316 ARM_ARCH_NONE,
31317 FPU_ARCH_FPA),
31318 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31319 ARM_ARCH_NONE,
31320 FPU_ARCH_FPA),
31321 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31322 ARM_ARCH_NONE,
31323 FPU_ARCH_FPA),
31324 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31325 ARM_ARCH_NONE,
31326 FPU_ARCH_FPA),
31327 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31328 ARM_ARCH_NONE,
31329 FPU_ARCH_FPA),
31330 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31331 ARM_ARCH_NONE,
31332 FPU_ARCH_FPA),
31333 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31334 ARM_ARCH_NONE,
31335 FPU_ARCH_FPA),
31336 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31337 ARM_ARCH_NONE,
31338 FPU_ARCH_FPA),
31339 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31340 ARM_ARCH_NONE,
31341 FPU_ARCH_FPA),
31342 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31343 ARM_ARCH_NONE,
31344 FPU_ARCH_FPA),
31345 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31346 ARM_ARCH_NONE,
31347 FPU_ARCH_FPA),
31348 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31349 ARM_ARCH_NONE,
31350 FPU_ARCH_FPA),
31351 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31352 ARM_ARCH_NONE,
31353 FPU_ARCH_FPA),
31354 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31355 ARM_ARCH_NONE,
31356 FPU_ARCH_FPA),
31357 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31358 ARM_ARCH_NONE,
31359 FPU_ARCH_FPA),
31360 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31361 ARM_ARCH_NONE,
31362 FPU_ARCH_FPA),
31363 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31364 ARM_ARCH_NONE,
31365 FPU_ARCH_FPA),
31366 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31367 ARM_ARCH_NONE,
31368 FPU_ARCH_FPA),
31369 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31370 ARM_ARCH_NONE,
31371 FPU_ARCH_FPA),
31372 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31373 ARM_ARCH_NONE,
31374 FPU_ARCH_FPA),
31375 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31376 ARM_ARCH_NONE,
31377 FPU_ARCH_FPA),
31378
c19d1205
ZW
31379 /* For V5 or later processors we default to using VFP; but the user
31380 should really set the FPU type explicitly. */
996b5569
TP
31381 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31382 ARM_ARCH_NONE,
31383 FPU_ARCH_VFP_V2),
31384 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31385 ARM_ARCH_NONE,
31386 FPU_ARCH_VFP_V2),
31387 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31388 ARM_ARCH_NONE,
31389 FPU_ARCH_VFP_V2),
31390 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31391 ARM_ARCH_NONE,
31392 FPU_ARCH_VFP_V2),
31393 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31394 ARM_ARCH_NONE,
31395 FPU_ARCH_VFP_V2),
31396 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31397 ARM_ARCH_NONE,
31398 FPU_ARCH_VFP_V2),
31399 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31400 ARM_ARCH_NONE,
31401 FPU_ARCH_VFP_V2),
31402 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31403 ARM_ARCH_NONE,
31404 FPU_ARCH_VFP_V2),
31405 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31406 ARM_ARCH_NONE,
31407 FPU_ARCH_VFP_V2),
31408 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31409 ARM_ARCH_NONE,
31410 FPU_ARCH_VFP_V2),
31411 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31412 ARM_ARCH_NONE,
31413 FPU_ARCH_VFP_V2),
31414 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31415 ARM_ARCH_NONE,
31416 FPU_ARCH_VFP_V2),
31417 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31418 ARM_ARCH_NONE,
31419 FPU_ARCH_VFP_V1),
31420 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31421 ARM_ARCH_NONE,
31422 FPU_ARCH_VFP_V1),
31423 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31424 ARM_ARCH_NONE,
31425 FPU_ARCH_VFP_V2),
31426 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31427 ARM_ARCH_NONE,
31428 FPU_ARCH_VFP_V2),
31429 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31430 ARM_ARCH_NONE,
31431 FPU_ARCH_VFP_V1),
31432 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31433 ARM_ARCH_NONE,
31434 FPU_ARCH_VFP_V2),
31435 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31436 ARM_ARCH_NONE,
31437 FPU_ARCH_VFP_V2),
31438 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31439 ARM_ARCH_NONE,
31440 FPU_ARCH_VFP_V2),
31441 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31442 ARM_ARCH_NONE,
31443 FPU_ARCH_VFP_V2),
31444 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31445 ARM_ARCH_NONE,
31446 FPU_ARCH_VFP_V2),
31447 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31448 ARM_ARCH_NONE,
31449 FPU_ARCH_VFP_V2),
31450 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31451 ARM_ARCH_NONE,
31452 FPU_ARCH_VFP_V2),
31453 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31454 ARM_ARCH_NONE,
31455 FPU_ARCH_VFP_V2),
31456 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31457 ARM_ARCH_NONE,
31458 FPU_ARCH_VFP_V2),
31459 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31460 ARM_ARCH_NONE,
31461 FPU_NONE),
31462 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31463 ARM_ARCH_NONE,
31464 FPU_NONE),
31465 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31466 ARM_ARCH_NONE,
31467 FPU_ARCH_VFP_V2),
31468 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31469 ARM_ARCH_NONE,
31470 FPU_ARCH_VFP_V2),
31471 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31472 ARM_ARCH_NONE,
31473 FPU_ARCH_VFP_V2),
31474 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31475 ARM_ARCH_NONE,
31476 FPU_NONE),
31477 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31478 ARM_ARCH_NONE,
31479 FPU_NONE),
31480 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31481 ARM_ARCH_NONE,
31482 FPU_ARCH_VFP_V2),
31483 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31484 ARM_ARCH_NONE,
31485 FPU_NONE),
31486 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31487 ARM_ARCH_NONE,
31488 FPU_ARCH_VFP_V2),
31489 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31490 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31491 FPU_NONE),
31492 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31493 ARM_ARCH_NONE,
31494 FPU_ARCH_NEON_VFP_V4),
31495 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31496 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31497 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31498 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31499 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31500 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31501 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31502 ARM_ARCH_NONE,
31503 FPU_ARCH_NEON_VFP_V4),
31504 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31505 ARM_ARCH_NONE,
31506 FPU_ARCH_NEON_VFP_V4),
31507 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31508 ARM_ARCH_NONE,
31509 FPU_ARCH_NEON_VFP_V4),
31510 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
8b301fbb 31511 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31512 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31513 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
8b301fbb 31514 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31515 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31516 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
8b301fbb 31517 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31518 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31519 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31520 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31521 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569 31522 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
8b301fbb 31523 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31524 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31525 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
8b301fbb 31526 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31527 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31528 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
8b301fbb 31529 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31530 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31531 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31532 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31533 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 31534 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31535 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31536 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
0535e5d7
DZ
31537 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31538 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31539 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31540 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31541 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31542 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
31543 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31544 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31545 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
31546 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31547 ARM_ARCH_NONE,
31548 FPU_NONE),
31549 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31550 ARM_ARCH_NONE,
31551 FPU_ARCH_VFP_V3D16),
31552 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31553 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31554 FPU_NONE),
31555 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31556 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31557 FPU_ARCH_VFP_V3D16),
31558 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31559 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31560 FPU_ARCH_VFP_V3D16),
0cda1e19 31561 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
8b301fbb 31562 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
0cda1e19 31563 FPU_ARCH_NEON_VFP_ARMV8),
0535e5d7
DZ
31564 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31565 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31566 FPU_NONE),
996b5569
TP
31567 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31568 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31569 FPU_NONE),
31570 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31571 ARM_ARCH_NONE,
31572 FPU_NONE),
31573 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31574 ARM_ARCH_NONE,
31575 FPU_NONE),
31576 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31577 ARM_ARCH_NONE,
31578 FPU_NONE),
31579 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31580 ARM_ARCH_NONE,
31581 FPU_NONE),
31582 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31583 ARM_ARCH_NONE,
31584 FPU_NONE),
31585 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31586 ARM_ARCH_NONE,
31587 FPU_NONE),
31588 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31589 ARM_ARCH_NONE,
31590 FPU_NONE),
31591 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
8b301fbb 31592 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31593 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
31594 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31595 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31596 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
f3034e25
AC
31597 ARM_CPU_OPT ("neoverse-n2", "Neoverse N2", ARM_ARCH_V8_5A,
31598 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31599 | ARM_EXT2_BF16
31600 | ARM_EXT2_I8MM),
31601 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
6eee0315
AC
31602 ARM_CPU_OPT ("neoverse-v1", "Neoverse V1", ARM_ARCH_V8_4A,
31603 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16 | ARM_EXT2_I8MM),
31604 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
c19d1205 31605 /* ??? XSCALE is really an architecture. */
996b5569
TP
31606 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31607 ARM_ARCH_NONE,
31608 FPU_ARCH_VFP_V2),
31609
c19d1205 31610 /* ??? iwmmxt is not a processor. */
996b5569
TP
31611 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31612 ARM_ARCH_NONE,
31613 FPU_ARCH_VFP_V2),
31614 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31615 ARM_ARCH_NONE,
31616 FPU_ARCH_VFP_V2),
31617 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31618 ARM_ARCH_NONE,
31619 FPU_ARCH_VFP_V2),
31620
0198d5e6 31621 /* Maverick. */
996b5569
TP
31622 ARM_CPU_OPT ("ep9312", "ARM920T",
31623 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31624 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31625
da4339ed 31626 /* Marvell processors. */
996b5569
TP
31627 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31628 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31629 FPU_ARCH_VFP_V3D16),
31630 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31631 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31632 FPU_ARCH_NEON_VFP_V4),
da4339ed 31633
996b5569
TP
31634 /* APM X-Gene family. */
31635 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31636 ARM_ARCH_NONE,
31637 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31638 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
8b301fbb 31639 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31640 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31641
31642 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31643};
f3bad469 31644#undef ARM_CPU_OPT
7ed4c4c5 31645
34ef62f4
AV
31646struct arm_ext_table
31647{
31648 const char * name;
31649 size_t name_len;
31650 const arm_feature_set merge;
31651 const arm_feature_set clear;
31652};
31653
c19d1205 31654struct arm_arch_option_table
7ed4c4c5 31655{
34ef62f4
AV
31656 const char * name;
31657 size_t name_len;
31658 const arm_feature_set value;
31659 const arm_feature_set default_fpu;
31660 const struct arm_ext_table * ext_table;
31661};
31662
31663/* Used to add support for +E and +noE extension. */
31664#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31665/* Used to add support for a +E extension. */
31666#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31667/* Used to add support for a +noE extension. */
31668#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31669
31670#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31671 ~0 & ~FPU_ENDIAN_PURE)
31672
31673static const struct arm_ext_table armv5te_ext_table[] =
31674{
31675 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31676 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31677};
31678
31679static const struct arm_ext_table armv7_ext_table[] =
31680{
31681 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31682 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31683};
31684
31685static const struct arm_ext_table armv7ve_ext_table[] =
31686{
31687 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31688 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31689 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31690 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31691 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31692 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31693 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31694
31695 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31696 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31697
31698 /* Aliases for +simd. */
31699 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31700
31701 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31702 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31703 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31704
31705 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31706};
31707
31708static const struct arm_ext_table armv7a_ext_table[] =
31709{
31710 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31711 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31712 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31713 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31714 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31715 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31716 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31717
31718 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31719 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31720
31721 /* Aliases for +simd. */
31722 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31723 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31724
31725 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31726 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31727
31728 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31729 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31730 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31731};
31732
31733static const struct arm_ext_table armv7r_ext_table[] =
31734{
31735 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31736 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31737 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31738 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31739 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31740 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31741 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31742 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31743 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31744};
31745
31746static const struct arm_ext_table armv7em_ext_table[] =
31747{
31748 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31749 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31750 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31751 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31752 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31753 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31754 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31755};
31756
31757static const struct arm_ext_table armv8a_ext_table[] =
31758{
8b301fbb 31759 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31760 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31761 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31762 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31763
31764 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31765 should use the +simd option to turn on FP. */
31766 ARM_REMOVE ("fp", ALL_FP),
31767 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31768 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31769 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31770};
31771
31772
31773static const struct arm_ext_table armv81a_ext_table[] =
31774{
31775 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31776 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31777 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31778
31779 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31780 should use the +simd option to turn on FP. */
31781 ARM_REMOVE ("fp", ALL_FP),
31782 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31783 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31784 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31785};
31786
31787static const struct arm_ext_table armv82a_ext_table[] =
31788{
31789 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31790 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31791 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
616ce08e
MM
31792 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31793 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31794 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31795 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31796 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31797
31798 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31799 should use the +simd option to turn on FP. */
31800 ARM_REMOVE ("fp", ALL_FP),
31801 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31802 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31803 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31804};
31805
31806static const struct arm_ext_table armv84a_ext_table[] =
31807{
31808 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31809 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31810 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31811 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31812 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31813 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31814
31815 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31816 should use the +simd option to turn on FP. */
31817 ARM_REMOVE ("fp", ALL_FP),
31818 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31819 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31820 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31821};
31822
31823static const struct arm_ext_table armv85a_ext_table[] =
31824{
31825 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31826 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31827 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31828 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31829 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31830 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31831
31832 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31833 should use the +simd option to turn on FP. */
31834 ARM_REMOVE ("fp", ALL_FP),
31835 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31836};
31837
aab2c27d
MM
31838static const struct arm_ext_table armv86a_ext_table[] =
31839{
616ce08e 31840 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
aab2c27d
MM
31841 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31842};
31843
4934a27c
MM
31844#define CDE_EXTENSIONS \
31845 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31846 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31847 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31848 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31849 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31850 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31851 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31852 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31853
34ef62f4
AV
31854static const struct arm_ext_table armv8m_main_ext_table[] =
31855{
92169145
AV
31856 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31857 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
34ef62f4
AV
31858 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31859 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
4934a27c 31860 CDE_EXTENSIONS,
34ef62f4
AV
31861 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31862};
31863
92169145 31864
e0991585
AV
31865static const struct arm_ext_table armv8_1m_main_ext_table[] =
31866{
92169145
AV
31867 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31868 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
e0991585
AV
31869 ARM_EXT ("fp",
31870 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31871 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31872 ALL_FP),
31873 ARM_ADD ("fp.dp",
31874 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31875 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
92169145 31876 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
2da2eaf4 31877 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
a7ad558c 31878 ARM_ADD ("mve.fp",
92169145
AV
31879 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31880 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
2da2eaf4 31881 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
4934a27c 31882 CDE_EXTENSIONS,
e0991585
AV
31883 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31884};
31885
4934a27c
MM
31886#undef CDE_EXTENSIONS
31887
34ef62f4
AV
31888static const struct arm_ext_table armv8r_ext_table[] =
31889{
8b301fbb 31890 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31891 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31892 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31893 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31894 ARM_REMOVE ("fp", ALL_FP),
31895 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31896 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 31897};
7ed4c4c5 31898
c19d1205
ZW
31899/* This list should, at a minimum, contain all the architecture names
31900 recognized by GCC. */
34ef62f4
AV
31901#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31902#define ARM_ARCH_OPT2(N, V, DF, ext) \
31903 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 31904
e74cfd16 31905static const struct arm_arch_option_table arm_archs[] =
c19d1205 31906{
497d849d
TP
31907 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31908 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31909 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31910 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31911 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31912 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31913 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31914 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31915 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31916 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31917 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31918 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31919 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31920 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
31921 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31922 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31923 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31924 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31925 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31926 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31927 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31928 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31929 kept to preserve existing behaviour. */
34ef62f4
AV
31930 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31931 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31932 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31933 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31934 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31935 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31936 kept to preserve existing behaviour. */
34ef62f4
AV
31937 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31938 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
31939 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31940 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 31941 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
31942 /* The official spelling of the ARMv7 profile variants is the dashed form.
31943 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
31944 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31945 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31946 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31947 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
31948 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31949 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31950 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 31951 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 31952 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
31953 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31954 armv8m_main),
e0991585
AV
31955 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31956 armv8_1m_main),
34ef62f4
AV
31957 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31958 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31959 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31960 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31961 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31962 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31963 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
aab2c27d 31964 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
497d849d
TP
31965 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31966 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31967 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 31968 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31969};
f3bad469 31970#undef ARM_ARCH_OPT
7ed4c4c5 31971
69133863 31972/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 31973
69133863 31974struct arm_option_extension_value_table
c19d1205 31975{
0198d5e6
TC
31976 const char * name;
31977 size_t name_len;
31978 const arm_feature_set merge_value;
31979 const arm_feature_set clear_value;
d942732e
TP
31980 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31981 indicates that an extension is available for all architectures while
31982 ARM_ANY marks an empty entry. */
0198d5e6 31983 const arm_feature_set allowed_archs[2];
c19d1205 31984};
7ed4c4c5 31985
0198d5e6
TC
31986/* The following table must be in alphabetical order with a NULL last entry. */
31987
d942732e
TP
31988#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31989#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 31990
34ef62f4
AV
31991/* DEPRECATED: Refrain from using this table to add any new extensions, instead
31992 use the context sensitive approach using arm_ext_table's. */
69133863 31993static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 31994{
8b301fbb
MI
31995 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31996 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
823d2571 31997 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 31998 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
31999 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
32000 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
32001 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
32002 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
32003 ARM_ARCH_V8_2A),
15afaa63
TP
32004 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32005 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32006 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
32007 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
32008 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
32009 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32010 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32011 ARM_ARCH_V8_2A),
01f48020
TC
32012 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32013 | ARM_EXT2_FP16_FML),
32014 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32015 | ARM_EXT2_FP16_FML),
32016 ARM_ARCH_V8_2A),
d942732e 32017 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 32018 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
32019 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32020 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
32021 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32022 Thumb divide instruction. Due to this having the same name as the
32023 previous entry, this will be ignored when doing command-line parsing and
32024 only considered by build attribute selection code. */
32025 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32026 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32027 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 32028 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 32029 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 32030 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 32031 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 32032 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
32033 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32034 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 32035 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
32036 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32037 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
32038 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32039 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32040 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
32041 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32042 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 32043 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
32044 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32045 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32046 ARM_ARCH_V8A),
4d1464f2
MW
32047 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32048 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 32049 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
32050 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32051 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 32052 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
32053 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32054 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32055 ARM_ARCH_V8A),
d942732e 32056 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 32057 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
32058 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32059 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
32060 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32061 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32062 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
32063 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32064 | ARM_EXT_DIV),
32065 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32066 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32067 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
32068 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32069 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 32070};
f3bad469 32071#undef ARM_EXT_OPT
69133863
MGD
32072
32073/* ISA floating-point and Advanced SIMD extensions. */
32074struct arm_option_fpu_value_table
32075{
0198d5e6
TC
32076 const char * name;
32077 const arm_feature_set value;
c19d1205 32078};
7ed4c4c5 32079
c19d1205
ZW
32080/* This list should, at a minimum, contain all the fpu names
32081 recognized by GCC. */
69133863 32082static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
32083{
32084 {"softfpa", FPU_NONE},
32085 {"fpe", FPU_ARCH_FPE},
32086 {"fpe2", FPU_ARCH_FPE},
32087 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32088 {"fpa", FPU_ARCH_FPA},
32089 {"fpa10", FPU_ARCH_FPA},
32090 {"fpa11", FPU_ARCH_FPA},
32091 {"arm7500fe", FPU_ARCH_FPA},
32092 {"softvfp", FPU_ARCH_VFP},
32093 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32094 {"vfp", FPU_ARCH_VFP_V2},
32095 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 32096 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
32097 {"vfp10", FPU_ARCH_VFP_V2},
32098 {"vfp10-r0", FPU_ARCH_VFP_V1},
32099 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
32100 {"vfpv2", FPU_ARCH_VFP_V2},
32101 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 32102 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 32103 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
32104 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32105 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32106 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
32107 {"arm1020t", FPU_ARCH_VFP_V1},
32108 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 32109 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
32110 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32111 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 32112 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 32113 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 32114 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
32115 {"vfpv4", FPU_ARCH_VFP_V4},
32116 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 32117 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
32118 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32119 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 32120 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
32121 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32122 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32123 {"crypto-neon-fp-armv8",
32124 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 32125 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
32126 {"crypto-neon-fp-armv8.1",
32127 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
32128 {NULL, ARM_ARCH_NONE}
32129};
32130
32131struct arm_option_value_table
32132{
e0471c16 32133 const char *name;
e74cfd16 32134 long value;
c19d1205 32135};
7ed4c4c5 32136
e74cfd16 32137static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
32138{
32139 {"hard", ARM_FLOAT_ABI_HARD},
32140 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32141 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 32142 {NULL, 0}
c19d1205 32143};
7ed4c4c5 32144
c19d1205 32145#ifdef OBJ_ELF
3a4a14e9 32146/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 32147static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
32148{
32149 {"gnu", EF_ARM_EABI_UNKNOWN},
32150 {"4", EF_ARM_EABI_VER4},
3a4a14e9 32151 {"5", EF_ARM_EABI_VER5},
e74cfd16 32152 {NULL, 0}
c19d1205
ZW
32153};
32154#endif
7ed4c4c5 32155
c19d1205
ZW
32156struct arm_long_option_table
32157{
0198d5e6 32158 const char * option; /* Substring to match. */
e0471c16 32159 const char * help; /* Help information. */
17b9d67d 32160 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 32161 const char * deprecated; /* If non-null, print this message. */
c19d1205 32162};
7ed4c4c5 32163
c921be7d 32164static bfd_boolean
c168ce07 32165arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
32166 arm_feature_set *ext_set,
32167 const struct arm_ext_table *ext_table)
7ed4c4c5 32168{
69133863 32169 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
32170 extensions being added before being removed. We achieve this by having
32171 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 32172 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 32173 or removing it (0) and only allowing it to change in the order
69133863
MGD
32174 -1 -> 1 -> 0. */
32175 const struct arm_option_extension_value_table * opt = NULL;
d942732e 32176 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
32177 int adding_value = -1;
32178
c19d1205 32179 while (str != NULL && *str != 0)
7ed4c4c5 32180 {
82b8a785 32181 const char *ext;
f3bad469 32182 size_t len;
7ed4c4c5 32183
c19d1205
ZW
32184 if (*str != '+')
32185 {
32186 as_bad (_("invalid architectural extension"));
c921be7d 32187 return FALSE;
c19d1205 32188 }
7ed4c4c5 32189
c19d1205
ZW
32190 str++;
32191 ext = strchr (str, '+');
7ed4c4c5 32192
c19d1205 32193 if (ext != NULL)
f3bad469 32194 len = ext - str;
c19d1205 32195 else
f3bad469 32196 len = strlen (str);
7ed4c4c5 32197
f3bad469 32198 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
32199 {
32200 if (adding_value != 0)
32201 {
32202 adding_value = 0;
32203 opt = arm_extensions;
32204 }
32205
f3bad469 32206 len -= 2;
69133863
MGD
32207 str += 2;
32208 }
f3bad469 32209 else if (len > 0)
69133863
MGD
32210 {
32211 if (adding_value == -1)
32212 {
32213 adding_value = 1;
32214 opt = arm_extensions;
32215 }
32216 else if (adding_value != 1)
32217 {
32218 as_bad (_("must specify extensions to add before specifying "
32219 "those to remove"));
32220 return FALSE;
32221 }
32222 }
32223
f3bad469 32224 if (len == 0)
c19d1205
ZW
32225 {
32226 as_bad (_("missing architectural extension"));
c921be7d 32227 return FALSE;
c19d1205 32228 }
7ed4c4c5 32229
69133863
MGD
32230 gas_assert (adding_value != -1);
32231 gas_assert (opt != NULL);
32232
34ef62f4
AV
32233 if (ext_table != NULL)
32234 {
32235 const struct arm_ext_table * ext_opt = ext_table;
32236 bfd_boolean found = FALSE;
32237 for (; ext_opt->name != NULL; ext_opt++)
32238 if (ext_opt->name_len == len
32239 && strncmp (ext_opt->name, str, len) == 0)
32240 {
32241 if (adding_value)
32242 {
32243 if (ARM_FEATURE_ZERO (ext_opt->merge))
32244 /* TODO: Option not supported. When we remove the
32245 legacy table this case should error out. */
32246 continue;
32247
32248 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32249 }
32250 else
32251 {
32252 if (ARM_FEATURE_ZERO (ext_opt->clear))
32253 /* TODO: Option not supported. When we remove the
32254 legacy table this case should error out. */
32255 continue;
32256 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32257 }
32258 found = TRUE;
32259 break;
32260 }
32261 if (found)
32262 {
32263 str = ext;
32264 continue;
32265 }
32266 }
32267
69133863
MGD
32268 /* Scan over the options table trying to find an exact match. */
32269 for (; opt->name != NULL; opt++)
f3bad469 32270 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32271 {
d942732e
TP
32272 int i, nb_allowed_archs =
32273 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 32274 /* Check we can apply the extension to this architecture. */
d942732e
TP
32275 for (i = 0; i < nb_allowed_archs; i++)
32276 {
32277 /* Empty entry. */
32278 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32279 continue;
c168ce07 32280 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
32281 break;
32282 }
32283 if (i == nb_allowed_archs)
69133863
MGD
32284 {
32285 as_bad (_("extension does not apply to the base architecture"));
32286 return FALSE;
32287 }
32288
32289 /* Add or remove the extension. */
32290 if (adding_value)
4d354d8b 32291 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 32292 else
4d354d8b 32293 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 32294
3d030cdb
TP
32295 /* Allowing Thumb division instructions for ARMv7 in autodetection
32296 rely on this break so that duplicate extensions (extensions
32297 with the same name as a previous extension in the list) are not
32298 considered for command-line parsing. */
c19d1205
ZW
32299 break;
32300 }
7ed4c4c5 32301
c19d1205
ZW
32302 if (opt->name == NULL)
32303 {
69133863
MGD
32304 /* Did we fail to find an extension because it wasn't specified in
32305 alphabetical order, or because it does not exist? */
32306
32307 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 32308 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
32309 break;
32310
32311 if (opt->name == NULL)
32312 as_bad (_("unknown architectural extension `%s'"), str);
32313 else
32314 as_bad (_("architectural extensions must be specified in "
32315 "alphabetical order"));
32316
c921be7d 32317 return FALSE;
c19d1205 32318 }
69133863
MGD
32319 else
32320 {
32321 /* We should skip the extension we've just matched the next time
32322 round. */
32323 opt++;
32324 }
7ed4c4c5 32325
c19d1205
ZW
32326 str = ext;
32327 };
7ed4c4c5 32328
c921be7d 32329 return TRUE;
c19d1205 32330}
7ed4c4c5 32331
5312fe52
BW
32332static bfd_boolean
32333arm_parse_fp16_opt (const char *str)
32334{
32335 if (strcasecmp (str, "ieee") == 0)
32336 fp16_format = ARM_FP16_FORMAT_IEEE;
32337 else if (strcasecmp (str, "alternative") == 0)
32338 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32339 else
32340 {
32341 as_bad (_("unrecognised float16 format \"%s\""), str);
32342 return FALSE;
32343 }
32344
32345 return TRUE;
32346}
32347
c921be7d 32348static bfd_boolean
17b9d67d 32349arm_parse_cpu (const char *str)
7ed4c4c5 32350{
f3bad469 32351 const struct arm_cpu_option_table *opt;
82b8a785 32352 const char *ext = strchr (str, '+');
f3bad469 32353 size_t len;
7ed4c4c5 32354
c19d1205 32355 if (ext != NULL)
f3bad469 32356 len = ext - str;
7ed4c4c5 32357 else
f3bad469 32358 len = strlen (str);
7ed4c4c5 32359
f3bad469 32360 if (len == 0)
7ed4c4c5 32361 {
c19d1205 32362 as_bad (_("missing cpu name `%s'"), str);
c921be7d 32363 return FALSE;
7ed4c4c5
NC
32364 }
32365
c19d1205 32366 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 32367 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32368 {
c168ce07 32369 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
32370 if (mcpu_ext_opt == NULL)
32371 mcpu_ext_opt = XNEW (arm_feature_set);
32372 *mcpu_ext_opt = opt->ext;
e74cfd16 32373 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 32374 if (opt->canonical_name)
ef8e6722
JW
32375 {
32376 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32377 strcpy (selected_cpu_name, opt->canonical_name);
32378 }
ee065d83
PB
32379 else
32380 {
f3bad469 32381 size_t i;
c921be7d 32382
ef8e6722
JW
32383 if (len >= sizeof selected_cpu_name)
32384 len = (sizeof selected_cpu_name) - 1;
32385
f3bad469 32386 for (i = 0; i < len; i++)
ee065d83
PB
32387 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32388 selected_cpu_name[i] = 0;
32389 }
7ed4c4c5 32390
c19d1205 32391 if (ext != NULL)
34ef62f4 32392 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 32393
c921be7d 32394 return TRUE;
c19d1205 32395 }
7ed4c4c5 32396
c19d1205 32397 as_bad (_("unknown cpu `%s'"), str);
c921be7d 32398 return FALSE;
7ed4c4c5
NC
32399}
32400
c921be7d 32401static bfd_boolean
17b9d67d 32402arm_parse_arch (const char *str)
7ed4c4c5 32403{
e74cfd16 32404 const struct arm_arch_option_table *opt;
82b8a785 32405 const char *ext = strchr (str, '+');
f3bad469 32406 size_t len;
7ed4c4c5 32407
c19d1205 32408 if (ext != NULL)
f3bad469 32409 len = ext - str;
7ed4c4c5 32410 else
f3bad469 32411 len = strlen (str);
7ed4c4c5 32412
f3bad469 32413 if (len == 0)
7ed4c4c5 32414 {
c19d1205 32415 as_bad (_("missing architecture name `%s'"), str);
c921be7d 32416 return FALSE;
7ed4c4c5
NC
32417 }
32418
c19d1205 32419 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 32420 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32421 {
e74cfd16 32422 march_cpu_opt = &opt->value;
4d354d8b
TP
32423 if (march_ext_opt == NULL)
32424 march_ext_opt = XNEW (arm_feature_set);
32425 *march_ext_opt = arm_arch_none;
e74cfd16 32426 march_fpu_opt = &opt->default_fpu;
e20f9590 32427 selected_ctx_ext_table = opt->ext_table;
5f4273c7 32428 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 32429
c19d1205 32430 if (ext != NULL)
34ef62f4
AV
32431 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32432 opt->ext_table);
7ed4c4c5 32433
c921be7d 32434 return TRUE;
c19d1205
ZW
32435 }
32436
32437 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 32438 return FALSE;
7ed4c4c5 32439}
eb043451 32440
c921be7d 32441static bfd_boolean
17b9d67d 32442arm_parse_fpu (const char * str)
c19d1205 32443{
69133863 32444 const struct arm_option_fpu_value_table * opt;
b99bd4ef 32445
c19d1205
ZW
32446 for (opt = arm_fpus; opt->name != NULL; opt++)
32447 if (streq (opt->name, str))
32448 {
e74cfd16 32449 mfpu_opt = &opt->value;
c921be7d 32450 return TRUE;
c19d1205 32451 }
b99bd4ef 32452
c19d1205 32453 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 32454 return FALSE;
c19d1205
ZW
32455}
32456
c921be7d 32457static bfd_boolean
17b9d67d 32458arm_parse_float_abi (const char * str)
b99bd4ef 32459{
e74cfd16 32460 const struct arm_option_value_table * opt;
b99bd4ef 32461
c19d1205
ZW
32462 for (opt = arm_float_abis; opt->name != NULL; opt++)
32463 if (streq (opt->name, str))
32464 {
32465 mfloat_abi_opt = opt->value;
c921be7d 32466 return TRUE;
c19d1205 32467 }
cc8a6dd0 32468
c19d1205 32469 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 32470 return FALSE;
c19d1205 32471}
b99bd4ef 32472
c19d1205 32473#ifdef OBJ_ELF
c921be7d 32474static bfd_boolean
17b9d67d 32475arm_parse_eabi (const char * str)
c19d1205 32476{
e74cfd16 32477 const struct arm_option_value_table *opt;
cc8a6dd0 32478
c19d1205
ZW
32479 for (opt = arm_eabis; opt->name != NULL; opt++)
32480 if (streq (opt->name, str))
32481 {
32482 meabi_flags = opt->value;
c921be7d 32483 return TRUE;
c19d1205
ZW
32484 }
32485 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 32486 return FALSE;
c19d1205
ZW
32487}
32488#endif
cc8a6dd0 32489
c921be7d 32490static bfd_boolean
17b9d67d 32491arm_parse_it_mode (const char * str)
e07e6e58 32492{
c921be7d 32493 bfd_boolean ret = TRUE;
e07e6e58
NC
32494
32495 if (streq ("arm", str))
32496 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32497 else if (streq ("thumb", str))
32498 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32499 else if (streq ("always", str))
32500 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32501 else if (streq ("never", str))
32502 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32503 else
32504 {
32505 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 32506 "arm, thumb, always, or never."), str);
c921be7d 32507 ret = FALSE;
e07e6e58
NC
32508 }
32509
32510 return ret;
32511}
32512
2e6976a8 32513static bfd_boolean
17b9d67d 32514arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
32515{
32516 codecomposer_syntax = TRUE;
32517 arm_comment_chars[0] = ';';
32518 arm_line_separator_chars[0] = 0;
32519 return TRUE;
32520}
32521
c19d1205
ZW
32522struct arm_long_option_table arm_long_opts[] =
32523{
32524 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32525 arm_parse_cpu, NULL},
32526 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32527 arm_parse_arch, NULL},
32528 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32529 arm_parse_fpu, NULL},
32530 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32531 arm_parse_float_abi, NULL},
32532#ifdef OBJ_ELF
7fac0536 32533 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
32534 arm_parse_eabi, NULL},
32535#endif
e07e6e58
NC
32536 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32537 arm_parse_it_mode, NULL},
2e6976a8
DG
32538 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32539 arm_ccs_mode, NULL},
5312fe52
BW
32540 {"mfp16-format=",
32541 N_("[ieee|alternative]\n\
32542 set the encoding for half precision floating point "
32543 "numbers to IEEE\n\
32544 or Arm alternative format."),
32545 arm_parse_fp16_opt, NULL },
c19d1205
ZW
32546 {NULL, NULL, 0, NULL}
32547};
cc8a6dd0 32548
c19d1205 32549int
17b9d67d 32550md_parse_option (int c, const char * arg)
c19d1205
ZW
32551{
32552 struct arm_option_table *opt;
e74cfd16 32553 const struct arm_legacy_option_table *fopt;
c19d1205 32554 struct arm_long_option_table *lopt;
b99bd4ef 32555
c19d1205 32556 switch (c)
b99bd4ef 32557 {
c19d1205
ZW
32558#ifdef OPTION_EB
32559 case OPTION_EB:
32560 target_big_endian = 1;
32561 break;
32562#endif
cc8a6dd0 32563
c19d1205
ZW
32564#ifdef OPTION_EL
32565 case OPTION_EL:
32566 target_big_endian = 0;
32567 break;
32568#endif
b99bd4ef 32569
845b51d6
PB
32570 case OPTION_FIX_V4BX:
32571 fix_v4bx = TRUE;
32572 break;
32573
18a20338
CL
32574#ifdef OBJ_ELF
32575 case OPTION_FDPIC:
32576 arm_fdpic = TRUE;
32577 break;
32578#endif /* OBJ_ELF */
32579
c19d1205
ZW
32580 case 'a':
32581 /* Listing option. Just ignore these, we don't support additional
32582 ones. */
32583 return 0;
b99bd4ef 32584
c19d1205
ZW
32585 default:
32586 for (opt = arm_opts; opt->option != NULL; opt++)
32587 {
32588 if (c == opt->option[0]
32589 && ((arg == NULL && opt->option[1] == 0)
32590 || streq (arg, opt->option + 1)))
32591 {
c19d1205 32592 /* If the option is deprecated, tell the user. */
278df34e 32593 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
32594 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32595 arg ? arg : "", _(opt->deprecated));
b99bd4ef 32596
c19d1205
ZW
32597 if (opt->var != NULL)
32598 *opt->var = opt->value;
cc8a6dd0 32599
c19d1205
ZW
32600 return 1;
32601 }
32602 }
b99bd4ef 32603
e74cfd16
PB
32604 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32605 {
32606 if (c == fopt->option[0]
32607 && ((arg == NULL && fopt->option[1] == 0)
32608 || streq (arg, fopt->option + 1)))
32609 {
e74cfd16 32610 /* If the option is deprecated, tell the user. */
278df34e 32611 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
32612 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32613 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
32614
32615 if (fopt->var != NULL)
32616 *fopt->var = &fopt->value;
32617
32618 return 1;
32619 }
32620 }
32621
c19d1205
ZW
32622 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32623 {
32624 /* These options are expected to have an argument. */
32625 if (c == lopt->option[0]
32626 && arg != NULL
32627 && strncmp (arg, lopt->option + 1,
32628 strlen (lopt->option + 1)) == 0)
32629 {
c19d1205 32630 /* If the option is deprecated, tell the user. */
278df34e 32631 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
32632 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32633 _(lopt->deprecated));
b99bd4ef 32634
c19d1205
ZW
32635 /* Call the sup-option parser. */
32636 return lopt->func (arg + strlen (lopt->option) - 1);
32637 }
32638 }
a737bd4d 32639
c19d1205
ZW
32640 return 0;
32641 }
a394c00f 32642
c19d1205
ZW
32643 return 1;
32644}
a394c00f 32645
c19d1205
ZW
32646void
32647md_show_usage (FILE * fp)
a394c00f 32648{
c19d1205
ZW
32649 struct arm_option_table *opt;
32650 struct arm_long_option_table *lopt;
a394c00f 32651
c19d1205 32652 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 32653
c19d1205
ZW
32654 for (opt = arm_opts; opt->option != NULL; opt++)
32655 if (opt->help != NULL)
32656 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 32657
c19d1205
ZW
32658 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32659 if (lopt->help != NULL)
32660 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 32661
c19d1205
ZW
32662#ifdef OPTION_EB
32663 fprintf (fp, _("\
32664 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
32665#endif
32666
c19d1205
ZW
32667#ifdef OPTION_EL
32668 fprintf (fp, _("\
32669 -EL assemble code for a little-endian cpu\n"));
a737bd4d 32670#endif
845b51d6
PB
32671
32672 fprintf (fp, _("\
32673 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
32674
32675#ifdef OBJ_ELF
32676 fprintf (fp, _("\
32677 --fdpic generate an FDPIC object file\n"));
32678#endif /* OBJ_ELF */
c19d1205 32679}
ee065d83 32680
ee065d83 32681#ifdef OBJ_ELF
0198d5e6 32682
62b3e311
PB
32683typedef struct
32684{
32685 int val;
32686 arm_feature_set flags;
32687} cpu_arch_ver_table;
32688
2c6b98ea
TP
32689/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32690 chronologically for architectures, with an exception for ARMv6-M and
32691 ARMv6S-M due to legacy reasons. No new architecture should have a
32692 special case. This allows for build attribute selection results to be
32693 stable when new architectures are added. */
62b3e311
PB
32694static const cpu_arch_ver_table cpu_arch_ver[] =
32695{
031254f2
AV
32696 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32697 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32698 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32699 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32700 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32701 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32702 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32703 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32704 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32705 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32706 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32707 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32708 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32709 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32710 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32711 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32712 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32713 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32714 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32715 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32716 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32717 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32718 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32719 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
32720
32721 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32722 always selected build attributes to match those of ARMv6-M
32723 (resp. ARMv6S-M). However, due to these architectures being a strict
32724 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32725 would be selected when fully respecting chronology of architectures.
32726 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32727 move them before ARMv7 architectures. */
031254f2
AV
32728 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32729 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32730
32731 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32732 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32733 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32734 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32735 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32736 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32737 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32738 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32739 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32740 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32741 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32742 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32743 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32744 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32745 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32746 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
aab2c27d
MM
32747 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32748 {-1, ARM_ARCH_NONE}
62b3e311
PB
32749};
32750
ee3c0378 32751/* Set an attribute if it has not already been set by the user. */
0198d5e6 32752
ee3c0378
AS
32753static void
32754aeabi_set_attribute_int (int tag, int value)
32755{
32756 if (tag < 1
32757 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32758 || !attributes_set_explicitly[tag])
32759 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32760}
32761
32762static void
32763aeabi_set_attribute_string (int tag, const char *value)
32764{
32765 if (tag < 1
32766 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32767 || !attributes_set_explicitly[tag])
32768 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32769}
32770
2c6b98ea
TP
32771/* Return whether features in the *NEEDED feature set are available via
32772 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 32773
2c6b98ea
TP
32774static bfd_boolean
32775have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32776 const arm_feature_set *needed)
32777{
32778 int i, nb_allowed_archs;
32779 arm_feature_set ext_fset;
32780 const struct arm_option_extension_value_table *opt;
32781
32782 ext_fset = arm_arch_none;
32783 for (opt = arm_extensions; opt->name != NULL; opt++)
32784 {
32785 /* Extension does not provide any feature we need. */
32786 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32787 continue;
32788
32789 nb_allowed_archs =
32790 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32791 for (i = 0; i < nb_allowed_archs; i++)
32792 {
32793 /* Empty entry. */
32794 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32795 break;
32796
32797 /* Extension is available, add it. */
32798 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32799 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32800 }
32801 }
32802
32803 /* Can we enable all features in *needed? */
32804 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32805}
32806
32807/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32808 a given architecture feature set *ARCH_EXT_FSET including extension feature
32809 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32810 - if true, check for an exact match of the architecture modulo extensions;
32811 - otherwise, select build attribute value of the first superset
32812 architecture released so that results remains stable when new architectures
32813 are added.
32814 For -march/-mcpu=all the build attribute value of the most featureful
32815 architecture is returned. Tag_CPU_arch_profile result is returned in
32816 PROFILE. */
0198d5e6 32817
2c6b98ea
TP
32818static int
32819get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32820 const arm_feature_set *ext_fset,
32821 char *profile, int exact_match)
32822{
32823 arm_feature_set arch_fset;
32824 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32825
32826 /* Select most featureful architecture with all its extensions if building
32827 for -march=all as the feature sets used to set build attributes. */
32828 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32829 {
32830 /* Force revisiting of decision for each new architecture. */
031254f2 32831 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
32832 *profile = 'A';
32833 return TAG_CPU_ARCH_V8;
32834 }
32835
32836 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32837
32838 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32839 {
32840 arm_feature_set known_arch_fset;
32841
32842 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32843 if (exact_match)
32844 {
32845 /* Base architecture match user-specified architecture and
32846 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32847 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32848 {
32849 p_ver_ret = p_ver;
32850 goto found;
32851 }
32852 /* Base architecture match user-specified architecture only
32853 (eg. ARMv6-M in the same case as above). Record it in case we
32854 find a match with above condition. */
32855 else if (p_ver_ret == NULL
32856 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32857 p_ver_ret = p_ver;
32858 }
32859 else
32860 {
32861
32862 /* Architecture has all features wanted. */
32863 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32864 {
32865 arm_feature_set added_fset;
32866
32867 /* Compute features added by this architecture over the one
32868 recorded in p_ver_ret. */
32869 if (p_ver_ret != NULL)
32870 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32871 p_ver_ret->flags);
32872 /* First architecture that match incl. with extensions, or the
32873 only difference in features over the recorded match is
32874 features that were optional and are now mandatory. */
32875 if (p_ver_ret == NULL
32876 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32877 {
32878 p_ver_ret = p_ver;
32879 goto found;
32880 }
32881 }
32882 else if (p_ver_ret == NULL)
32883 {
32884 arm_feature_set needed_ext_fset;
32885
32886 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32887
32888 /* Architecture has all features needed when using some
32889 extensions. Record it and continue searching in case there
32890 exist an architecture providing all needed features without
32891 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32892 OS extension). */
32893 if (have_ext_for_needed_feat_p (&known_arch_fset,
32894 &needed_ext_fset))
32895 p_ver_ret = p_ver;
32896 }
32897 }
32898 }
32899
32900 if (p_ver_ret == NULL)
32901 return -1;
32902
dc1e8a47 32903 found:
2c6b98ea 32904 /* Tag_CPU_arch_profile. */
164446e0
AF
32905 if (!ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r)
32906 && (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32907 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32908 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32909 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))))
2c6b98ea 32910 *profile = 'A';
164446e0
AF
32911 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)
32912 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r))
2c6b98ea
TP
32913 *profile = 'R';
32914 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32915 *profile = 'M';
32916 else
32917 *profile = '\0';
32918 return p_ver_ret->val;
32919}
32920
ee065d83 32921/* Set the public EABI object attributes. */
0198d5e6 32922
c168ce07 32923static void
ee065d83
PB
32924aeabi_set_public_attributes (void)
32925{
b90d5ba0 32926 char profile = '\0';
2c6b98ea 32927 int arch = -1;
90ec0d68 32928 int virt_sec = 0;
bca38921 32929 int fp16_optional = 0;
2c6b98ea
TP
32930 int skip_exact_match = 0;
32931 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 32932
54bab281
TP
32933 /* Autodetection mode, choose the architecture based the instructions
32934 actually used. */
32935 if (no_cpu_selected ())
32936 {
32937 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 32938
54bab281
TP
32939 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32940 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 32941
54bab281
TP
32942 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32943 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 32944
54bab281 32945 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
32946 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32947 flags_ext = arm_arch_none;
32948 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32949 selected_ext = flags_ext;
54bab281
TP
32950 selected_cpu = flags;
32951 }
32952 /* Otherwise, choose the architecture based on the capabilities of the
32953 requested cpu. */
32954 else
4d354d8b
TP
32955 {
32956 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32957 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32958 flags_ext = selected_ext;
32959 flags = selected_cpu;
32960 }
32961 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 32962
ddd7f988 32963 /* Allow the user to override the reported architecture. */
4d354d8b 32964 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 32965 {
4d354d8b 32966 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 32967 flags_ext = arm_arch_none;
7a1d4c38 32968 }
2c6b98ea 32969 else
4d354d8b 32970 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
32971
32972 /* When this function is run again after relaxation has happened there is no
32973 way to determine whether an architecture or CPU was specified by the user:
32974 - selected_cpu is set above for relaxation to work;
32975 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32976 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32977 Therefore, if not in -march=all case we first try an exact match and fall
32978 back to autodetection. */
32979 if (!skip_exact_match)
32980 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32981 if (arch == -1)
32982 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32983 if (arch == -1)
32984 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 32985
ee065d83
PB
32986 /* Tag_CPU_name. */
32987 if (selected_cpu_name[0])
32988 {
91d6fa6a 32989 char *q;
ee065d83 32990
91d6fa6a
NC
32991 q = selected_cpu_name;
32992 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
32993 {
32994 int i;
5f4273c7 32995
91d6fa6a
NC
32996 q += 4;
32997 for (i = 0; q[i]; i++)
32998 q[i] = TOUPPER (q[i]);
ee065d83 32999 }
91d6fa6a 33000 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 33001 }
62f3b8c8 33002
ee065d83 33003 /* Tag_CPU_arch. */
ee3c0378 33004 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 33005
62b3e311 33006 /* Tag_CPU_arch_profile. */
69239280
MGD
33007 if (profile != '\0')
33008 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 33009
15afaa63 33010 /* Tag_DSP_extension. */
4d354d8b 33011 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 33012 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 33013
2c6b98ea 33014 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 33015 /* Tag_ARM_ISA_use. */
ee3c0378 33016 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 33017 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 33018 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 33019
ee065d83 33020 /* Tag_THUMB_ISA_use. */
ee3c0378 33021 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 33022 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
33023 {
33024 int thumb_isa_use;
33025
33026 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 33027 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
33028 thumb_isa_use = 3;
33029 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33030 thumb_isa_use = 2;
33031 else
33032 thumb_isa_use = 1;
33033 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33034 }
62f3b8c8 33035
ee065d83 33036 /* Tag_VFP_arch. */
a715796b
TG
33037 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33038 aeabi_set_attribute_int (Tag_VFP_arch,
33039 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33040 ? 7 : 8);
bca38921 33041 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
33042 aeabi_set_attribute_int (Tag_VFP_arch,
33043 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33044 ? 5 : 6);
33045 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
33046 {
33047 fp16_optional = 1;
33048 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33049 }
ada65aa3 33050 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
33051 {
33052 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33053 fp16_optional = 1;
33054 }
ee3c0378
AS
33055 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33056 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33057 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 33058 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 33059 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 33060
4547cb56
NC
33061 /* Tag_ABI_HardFP_use. */
33062 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33063 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33064 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33065
ee065d83 33066 /* Tag_WMMX_arch. */
ee3c0378
AS
33067 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33068 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33069 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33070 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 33071
ee3c0378 33072 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
33073 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33074 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33075 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
33076 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33077 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33078 {
33079 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33080 {
33081 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33082 }
33083 else
33084 {
33085 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33086 fp16_optional = 1;
33087 }
33088 }
fa94de6b 33089
a7ad558c
AV
33090 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33091 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33092 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33093 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33094
ee3c0378 33095 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 33096 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 33097 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 33098
69239280
MGD
33099 /* Tag_DIV_use.
33100
33101 We set Tag_DIV_use to two when integer divide instructions have been used
33102 in ARM state, or when Thumb integer divide instructions have been used,
33103 but we have no architecture profile set, nor have we any ARM instructions.
33104
4ed7ed8d
TP
33105 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33106 by the base architecture.
bca38921 33107
69239280 33108 For new architectures we will have to check these tests. */
031254f2 33109 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
33110 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33111 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
33112 aeabi_set_attribute_int (Tag_DIV_use, 0);
33113 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33114 || (profile == '\0'
33115 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33116 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 33117 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
33118
33119 /* Tag_MP_extension_use. */
33120 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33121 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
33122
33123 /* Tag Virtualization_use. */
33124 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
33125 virt_sec |= 1;
33126 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33127 virt_sec |= 2;
33128 if (virt_sec != 0)
33129 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
33130
33131 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33132 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
33133}
33134
c168ce07
TP
33135/* Post relaxation hook. Recompute ARM attributes now that relaxation is
33136 finished and free extension feature bits which will not be used anymore. */
0198d5e6 33137
c168ce07
TP
33138void
33139arm_md_post_relax (void)
33140{
33141 aeabi_set_public_attributes ();
4d354d8b
TP
33142 XDELETE (mcpu_ext_opt);
33143 mcpu_ext_opt = NULL;
33144 XDELETE (march_ext_opt);
33145 march_ext_opt = NULL;
c168ce07
TP
33146}
33147
104d59d1 33148/* Add the default contents for the .ARM.attributes section. */
0198d5e6 33149
ee065d83
PB
33150void
33151arm_md_end (void)
33152{
ee065d83
PB
33153 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33154 return;
33155
33156 aeabi_set_public_attributes ();
ee065d83 33157}
8463be01 33158#endif /* OBJ_ELF */
ee065d83 33159
ee065d83
PB
33160/* Parse a .cpu directive. */
33161
33162static void
33163s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33164{
e74cfd16 33165 const struct arm_cpu_option_table *opt;
ee065d83
PB
33166 char *name;
33167 char saved_char;
33168
33169 name = input_line_pointer;
5f4273c7 33170 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33171 input_line_pointer++;
33172 saved_char = *input_line_pointer;
33173 *input_line_pointer = 0;
33174
33175 /* Skip the first "all" entry. */
33176 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33177 if (streq (opt->name, name))
33178 {
4d354d8b
TP
33179 selected_arch = opt->value;
33180 selected_ext = opt->ext;
33181 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 33182 if (opt->canonical_name)
5f4273c7 33183 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
33184 else
33185 {
33186 int i;
33187 for (i = 0; opt->name[i]; i++)
33188 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 33189
ee065d83
PB
33190 selected_cpu_name[i] = 0;
33191 }
4d354d8b
TP
33192 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33193
ee065d83
PB
33194 *input_line_pointer = saved_char;
33195 demand_empty_rest_of_line ();
33196 return;
33197 }
33198 as_bad (_("unknown cpu `%s'"), name);
33199 *input_line_pointer = saved_char;
33200 ignore_rest_of_line ();
33201}
33202
ee065d83
PB
33203/* Parse a .arch directive. */
33204
33205static void
33206s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33207{
e74cfd16 33208 const struct arm_arch_option_table *opt;
ee065d83
PB
33209 char saved_char;
33210 char *name;
33211
33212 name = input_line_pointer;
5f4273c7 33213 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33214 input_line_pointer++;
33215 saved_char = *input_line_pointer;
33216 *input_line_pointer = 0;
33217
33218 /* Skip the first "all" entry. */
33219 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33220 if (streq (opt->name, name))
33221 {
4d354d8b 33222 selected_arch = opt->value;
0e7aaa72 33223 selected_ctx_ext_table = opt->ext_table;
4d354d8b
TP
33224 selected_ext = arm_arch_none;
33225 selected_cpu = selected_arch;
5f4273c7 33226 strcpy (selected_cpu_name, opt->name);
4d354d8b 33227 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33228 *input_line_pointer = saved_char;
33229 demand_empty_rest_of_line ();
33230 return;
33231 }
33232
33233 as_bad (_("unknown architecture `%s'\n"), name);
33234 *input_line_pointer = saved_char;
33235 ignore_rest_of_line ();
33236}
33237
7a1d4c38
PB
33238/* Parse a .object_arch directive. */
33239
33240static void
33241s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33242{
33243 const struct arm_arch_option_table *opt;
33244 char saved_char;
33245 char *name;
33246
33247 name = input_line_pointer;
5f4273c7 33248 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
33249 input_line_pointer++;
33250 saved_char = *input_line_pointer;
33251 *input_line_pointer = 0;
33252
33253 /* Skip the first "all" entry. */
33254 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33255 if (streq (opt->name, name))
33256 {
4d354d8b 33257 selected_object_arch = opt->value;
7a1d4c38
PB
33258 *input_line_pointer = saved_char;
33259 demand_empty_rest_of_line ();
33260 return;
33261 }
33262
33263 as_bad (_("unknown architecture `%s'\n"), name);
33264 *input_line_pointer = saved_char;
33265 ignore_rest_of_line ();
33266}
33267
69133863
MGD
33268/* Parse a .arch_extension directive. */
33269
33270static void
33271s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33272{
33273 const struct arm_option_extension_value_table *opt;
33274 char saved_char;
33275 char *name;
33276 int adding_value = 1;
33277
33278 name = input_line_pointer;
33279 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33280 input_line_pointer++;
33281 saved_char = *input_line_pointer;
33282 *input_line_pointer = 0;
33283
33284 if (strlen (name) >= 2
33285 && strncmp (name, "no", 2) == 0)
33286 {
33287 adding_value = 0;
33288 name += 2;
33289 }
33290
e20f9590
MI
33291 /* Check the context specific extension table */
33292 if (selected_ctx_ext_table)
33293 {
33294 const struct arm_ext_table * ext_opt;
33295 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33296 {
33297 if (streq (ext_opt->name, name))
33298 {
33299 if (adding_value)
33300 {
33301 if (ARM_FEATURE_ZERO (ext_opt->merge))
33302 /* TODO: Option not supported. When we remove the
33303 legacy table this case should error out. */
33304 continue;
33305 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33306 ext_opt->merge);
33307 }
33308 else
33309 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33310
33311 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33312 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33313 *input_line_pointer = saved_char;
33314 demand_empty_rest_of_line ();
33315 return;
33316 }
33317 }
33318 }
33319
69133863
MGD
33320 for (opt = arm_extensions; opt->name != NULL; opt++)
33321 if (streq (opt->name, name))
33322 {
d942732e
TP
33323 int i, nb_allowed_archs =
33324 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33325 for (i = 0; i < nb_allowed_archs; i++)
33326 {
33327 /* Empty entry. */
4d354d8b 33328 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 33329 continue;
4d354d8b 33330 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
33331 break;
33332 }
33333
33334 if (i == nb_allowed_archs)
69133863
MGD
33335 {
33336 as_bad (_("architectural extension `%s' is not allowed for the "
33337 "current base architecture"), name);
33338 break;
33339 }
33340
33341 if (adding_value)
4d354d8b 33342 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 33343 opt->merge_value);
69133863 33344 else
4d354d8b 33345 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 33346
4d354d8b
TP
33347 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33348 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
33349 *input_line_pointer = saved_char;
33350 demand_empty_rest_of_line ();
3d030cdb
TP
33351 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33352 on this return so that duplicate extensions (extensions with the
33353 same name as a previous extension in the list) are not considered
33354 for command-line parsing. */
69133863
MGD
33355 return;
33356 }
33357
33358 if (opt->name == NULL)
e673710a 33359 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
33360
33361 *input_line_pointer = saved_char;
33362 ignore_rest_of_line ();
33363}
33364
ee065d83
PB
33365/* Parse a .fpu directive. */
33366
33367static void
33368s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33369{
69133863 33370 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
33371 char saved_char;
33372 char *name;
33373
33374 name = input_line_pointer;
5f4273c7 33375 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33376 input_line_pointer++;
33377 saved_char = *input_line_pointer;
33378 *input_line_pointer = 0;
5f4273c7 33379
ee065d83
PB
33380 for (opt = arm_fpus; opt->name != NULL; opt++)
33381 if (streq (opt->name, name))
33382 {
4d354d8b 33383 selected_fpu = opt->value;
f4399880 33384 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
4d354d8b
TP
33385#ifndef CPU_DEFAULT
33386 if (no_cpu_selected ())
33387 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33388 else
33389#endif
33390 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33391 *input_line_pointer = saved_char;
33392 demand_empty_rest_of_line ();
33393 return;
33394 }
33395
33396 as_bad (_("unknown floating point format `%s'\n"), name);
33397 *input_line_pointer = saved_char;
33398 ignore_rest_of_line ();
33399}
ee065d83 33400
794ba86a 33401/* Copy symbol information. */
f31fef98 33402
794ba86a
DJ
33403void
33404arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33405{
33406 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33407}
e04befd0 33408
f31fef98 33409#ifdef OBJ_ELF
e04befd0
AS
33410/* Given a symbolic attribute NAME, return the proper integer value.
33411 Returns -1 if the attribute is not known. */
f31fef98 33412
e04befd0
AS
33413int
33414arm_convert_symbolic_attribute (const char *name)
33415{
f31fef98
NC
33416 static const struct
33417 {
33418 const char * name;
33419 const int tag;
33420 }
33421 attribute_table[] =
33422 {
33423 /* When you modify this table you should
33424 also modify the list in doc/c-arm.texi. */
e04befd0 33425#define T(tag) {#tag, tag}
f31fef98
NC
33426 T (Tag_CPU_raw_name),
33427 T (Tag_CPU_name),
33428 T (Tag_CPU_arch),
33429 T (Tag_CPU_arch_profile),
33430 T (Tag_ARM_ISA_use),
33431 T (Tag_THUMB_ISA_use),
75375b3e 33432 T (Tag_FP_arch),
f31fef98
NC
33433 T (Tag_VFP_arch),
33434 T (Tag_WMMX_arch),
33435 T (Tag_Advanced_SIMD_arch),
33436 T (Tag_PCS_config),
33437 T (Tag_ABI_PCS_R9_use),
33438 T (Tag_ABI_PCS_RW_data),
33439 T (Tag_ABI_PCS_RO_data),
33440 T (Tag_ABI_PCS_GOT_use),
33441 T (Tag_ABI_PCS_wchar_t),
33442 T (Tag_ABI_FP_rounding),
33443 T (Tag_ABI_FP_denormal),
33444 T (Tag_ABI_FP_exceptions),
33445 T (Tag_ABI_FP_user_exceptions),
33446 T (Tag_ABI_FP_number_model),
75375b3e 33447 T (Tag_ABI_align_needed),
f31fef98 33448 T (Tag_ABI_align8_needed),
75375b3e 33449 T (Tag_ABI_align_preserved),
f31fef98
NC
33450 T (Tag_ABI_align8_preserved),
33451 T (Tag_ABI_enum_size),
33452 T (Tag_ABI_HardFP_use),
33453 T (Tag_ABI_VFP_args),
33454 T (Tag_ABI_WMMX_args),
33455 T (Tag_ABI_optimization_goals),
33456 T (Tag_ABI_FP_optimization_goals),
33457 T (Tag_compatibility),
33458 T (Tag_CPU_unaligned_access),
75375b3e 33459 T (Tag_FP_HP_extension),
f31fef98
NC
33460 T (Tag_VFP_HP_extension),
33461 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
33462 T (Tag_MPextension_use),
33463 T (Tag_DIV_use),
f31fef98
NC
33464 T (Tag_nodefaults),
33465 T (Tag_also_compatible_with),
33466 T (Tag_conformance),
33467 T (Tag_T2EE_use),
33468 T (Tag_Virtualization_use),
15afaa63 33469 T (Tag_DSP_extension),
a7ad558c 33470 T (Tag_MVE_arch),
cd21e546 33471 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 33472#undef T
f31fef98 33473 };
e04befd0
AS
33474 unsigned int i;
33475
33476 if (name == NULL)
33477 return -1;
33478
f31fef98 33479 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 33480 if (streq (name, attribute_table[i].name))
e04befd0
AS
33481 return attribute_table[i].tag;
33482
33483 return -1;
33484}
267bf995 33485
93ef582d
NC
33486/* Apply sym value for relocations only in the case that they are for
33487 local symbols in the same segment as the fixup and you have the
33488 respective architectural feature for blx and simple switches. */
0198d5e6 33489
267bf995 33490int
93ef582d 33491arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
33492{
33493 if (fixP->fx_addsy
33494 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
33495 /* PR 17444: If the local symbol is in a different section then a reloc
33496 will always be generated for it, so applying the symbol value now
33497 will result in a double offset being stored in the relocation. */
33498 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 33499 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
33500 {
33501 switch (fixP->fx_r_type)
33502 {
33503 case BFD_RELOC_ARM_PCREL_BLX:
33504 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33505 if (ARM_IS_FUNC (fixP->fx_addsy))
33506 return 1;
33507 break;
33508
33509 case BFD_RELOC_ARM_PCREL_CALL:
33510 case BFD_RELOC_THUMB_PCREL_BLX:
33511 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 33512 return 1;
267bf995
RR
33513 break;
33514
33515 default:
33516 break;
33517 }
33518
33519 }
33520 return 0;
33521}
f31fef98 33522#endif /* OBJ_ELF */