Power10 string operations
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
b3adc24a 2 Copyright (C) 1994-2020 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b 34#include "opcode/arm.h"
f37164d7 35#include "cpu-arm.h"
f263249b 36
b99bd4ef
NC
37#ifdef OBJ_ELF
38#include "elf/arm.h"
a394c00f 39#include "dw2gencfi.h"
b99bd4ef
NC
40#endif
41
f0927246
NC
42#include "dwarf2dbg.h"
43
7ed4c4c5
NC
44#ifdef OBJ_ELF
45/* Must be at least the size of the largest unwind opcode (currently two). */
46#define ARM_OPCODE_CHUNK_SIZE 8
47
48/* This structure holds the unwinding state. */
49
50static struct
51{
c19d1205
ZW
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
7ed4c4c5 56 /* The segment containing the function. */
c19d1205
ZW
57 segT saved_seg;
58 subsegT saved_subseg;
7ed4c4c5
NC
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
c19d1205
ZW
61 int opcode_count;
62 int opcode_alloc;
7ed4c4c5 63 /* The number of bytes pushed to the stack. */
c19d1205 64 offsetT frame_size;
7ed4c4c5
NC
65 /* We don't add stack adjustment opcodes immediately so that we can merge
66 multiple adjustments. We can also omit the final adjustment
67 when using a frame pointer. */
c19d1205 68 offsetT pending_offset;
7ed4c4c5 69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
7ed4c4c5 73 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 74 unsigned fp_used:1;
7ed4c4c5 75 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 76 unsigned sp_restored:1;
7ed4c4c5
NC
77} unwind;
78
18a20338
CL
79/* Whether --fdpic was given. */
80static int arm_fdpic;
81
8b1ad454
NC
82#endif /* OBJ_ELF */
83
4962c51a
MS
84/* Results from operand parsing worker functions. */
85
86typedef enum
87{
88 PARSE_OPERAND_SUCCESS,
89 PARSE_OPERAND_FAIL,
90 PARSE_OPERAND_FAIL_NO_BACKTRACK
91} parse_operand_result;
92
33a392fb
PB
93enum arm_float_abi
94{
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98};
99
c19d1205 100/* Types of processor to assemble for. */
b99bd4ef 101#ifndef CPU_DEFAULT
8a59fff3 102/* The code that was here used to select a default CPU depending on compiler
fa94de6b 103 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
104 changing gas' default behaviour depending upon the build host.
105
106 If you have a target that requires a default CPU option then the you
107 should define CPU_DEFAULT here. */
b99bd4ef
NC
108#endif
109
e8f8842d
TC
110/* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112static bfd_boolean out_of_range_p (offsetT value, offsetT bits)
113 {
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
117}
118
b99bd4ef 119#ifndef FPU_DEFAULT
c820d418
MM
120# ifdef TE_LINUX
121# define FPU_DEFAULT FPU_ARCH_FPA
122# elif defined (TE_NetBSD)
123# ifdef OBJ_ELF
124# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
125# else
126 /* Legacy a.out format. */
127# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
128# endif
4e7fd91e
PB
129# elif defined (TE_VXWORKS)
130# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
131# else
132 /* For backwards compatibility, default to FPA. */
133# define FPU_DEFAULT FPU_ARCH_FPA
134# endif
135#endif /* ifndef FPU_DEFAULT */
b99bd4ef 136
c19d1205 137#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 138
4d354d8b
TP
139/* Current set of feature bits available (CPU+FPU). Different from
140 selected_cpu + selected_fpu in case of autodetection since the CPU
141 feature bits are then all set. */
e74cfd16 142static arm_feature_set cpu_variant;
4d354d8b
TP
143/* Feature bits used in each execution state. Used to set build attribute
144 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
145static arm_feature_set arm_arch_used;
146static arm_feature_set thumb_arch_used;
b99bd4ef 147
b99bd4ef 148/* Flags stored in private area of BFD structure. */
c19d1205
ZW
149static int uses_apcs_26 = FALSE;
150static int atpcs = FALSE;
b34976b6
AM
151static int support_interwork = FALSE;
152static int uses_apcs_float = FALSE;
c19d1205 153static int pic_code = FALSE;
845b51d6 154static int fix_v4bx = FALSE;
278df34e
NS
155/* Warn on using deprecated features. */
156static int warn_on_deprecated = TRUE;
24f19ccb 157static int warn_on_restrict_it = FALSE;
278df34e 158
2e6976a8
DG
159/* Understand CodeComposer Studio assembly syntax. */
160bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
161
162/* Variables that we set while parsing command-line options. Once all
163 options have been read we re-process these values to set the real
164 assembly flags. */
4d354d8b
TP
165
166/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
167 instead of -mcpu=arm1). */
168static const arm_feature_set *legacy_cpu = NULL;
169static const arm_feature_set *legacy_fpu = NULL;
170
171/* CPU, extension and FPU feature bits selected by -mcpu. */
172static const arm_feature_set *mcpu_cpu_opt = NULL;
173static arm_feature_set *mcpu_ext_opt = NULL;
174static const arm_feature_set *mcpu_fpu_opt = NULL;
175
176/* CPU, extension and FPU feature bits selected by -march. */
177static const arm_feature_set *march_cpu_opt = NULL;
178static arm_feature_set *march_ext_opt = NULL;
179static const arm_feature_set *march_fpu_opt = NULL;
180
181/* Feature bits selected by -mfpu. */
182static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
183
184/* Constants for known architecture features. */
185static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 186static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 187static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
188static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
189static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
190static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
191static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 192#ifdef OBJ_ELF
e74cfd16 193static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 194#endif
e74cfd16
PB
195static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
196
197#ifdef CPU_DEFAULT
198static const arm_feature_set cpu_default = CPU_DEFAULT;
199#endif
200
823d2571 201static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 202static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
203static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
204static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
205static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
206static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
207static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
208static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 209static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
211static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
212static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
213static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
214static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
215static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
216static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
217static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
218/* Only for compatability of hint instructions. */
219static const arm_feature_set arm_ext_v6k_v6t2 =
220 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
221static const arm_feature_set arm_ext_v6_notm =
222 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
223static const arm_feature_set arm_ext_v6_dsp =
224 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
225static const arm_feature_set arm_ext_barrier =
226 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
227static const arm_feature_set arm_ext_msr =
228 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
229static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
230static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
231static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
232static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 233#ifdef OBJ_ELF
e7d39ed3 234static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 235#endif
823d2571 236static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 237static const arm_feature_set arm_ext_m =
173205ca 238 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 239 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
240static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
241static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
242static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
243static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
244static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 245static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 246static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
247static const arm_feature_set arm_ext_v8m_main =
248 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
249static const arm_feature_set arm_ext_v8_1m_main =
250ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
251/* Instructions in ARMv8-M only found in M profile architectures. */
252static const arm_feature_set arm_ext_v8m_m_only =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
254static const arm_feature_set arm_ext_v6t2_v8m =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
256/* Instructions shared between ARMv8-A and ARMv8-M. */
257static const arm_feature_set arm_ext_atomics =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 259#ifdef OBJ_ELF
15afaa63
TP
260/* DSP instructions Tag_DSP_extension refers to. */
261static const arm_feature_set arm_ext_dsp =
262 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 263#endif
4d1464f2
MW
264static const arm_feature_set arm_ext_ras =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
266/* FP16 instructions. */
267static const arm_feature_set arm_ext_fp16 =
268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
269static const arm_feature_set arm_ext_fp16_fml =
270 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
271static const arm_feature_set arm_ext_v8_2 =
272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
273static const arm_feature_set arm_ext_v8_3 =
274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
275static const arm_feature_set arm_ext_sb =
276 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
277static const arm_feature_set arm_ext_predres =
278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
aab2c27d
MM
279static const arm_feature_set arm_ext_bf16 =
280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
616ce08e
MM
281static const arm_feature_set arm_ext_i8mm =
282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
8b301fbb
MI
283static const arm_feature_set arm_ext_crc =
284 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
4934a27c
MM
285static const arm_feature_set arm_ext_cde =
286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
287static const arm_feature_set arm_ext_cde0 =
288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
289static const arm_feature_set arm_ext_cde1 =
290 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
291static const arm_feature_set arm_ext_cde2 =
292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
293static const arm_feature_set arm_ext_cde3 =
294 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
295static const arm_feature_set arm_ext_cde4 =
296 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
297static const arm_feature_set arm_ext_cde5 =
298 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
299static const arm_feature_set arm_ext_cde6 =
300 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
301static const arm_feature_set arm_ext_cde7 =
302 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
e74cfd16
PB
303
304static const arm_feature_set arm_arch_any = ARM_ANY;
2c6b98ea 305static const arm_feature_set fpu_any = FPU_ANY;
f85d59c3 306static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
307static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
308static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
309
2d447fca 310static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 311 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 312static const arm_feature_set arm_cext_iwmmxt =
823d2571 313 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 314static const arm_feature_set arm_cext_xscale =
823d2571 315 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 316static const arm_feature_set arm_cext_maverick =
823d2571
TG
317 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
318static const arm_feature_set fpu_fpa_ext_v1 =
319 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
320static const arm_feature_set fpu_fpa_ext_v2 =
321 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 322static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
323 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
324static const arm_feature_set fpu_vfp_ext_v1 =
325 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
326static const arm_feature_set fpu_vfp_ext_v2 =
327 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
328static const arm_feature_set fpu_vfp_ext_v3xd =
329 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
330static const arm_feature_set fpu_vfp_ext_v3 =
331 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 332static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
333 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
334static const arm_feature_set fpu_neon_ext_v1 =
335 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 336static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 337 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c 338static const arm_feature_set mve_ext =
2da2eaf4 339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
a7ad558c 340static const arm_feature_set mve_fp_ext =
2da2eaf4 341 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
5aae9ae9
MM
342/* Note: This has more than one bit set, which means using it with
343 mark_feature_used (which returns if *any* of the bits are set in the current
344 cpu variant) can give surprising results. */
345static const arm_feature_set armv8m_fp =
346 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
69c9e028 347#ifdef OBJ_ELF
823d2571
TG
348static const arm_feature_set fpu_vfp_fp16 =
349 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
350static const arm_feature_set fpu_neon_ext_fma =
351 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 352#endif
823d2571
TG
353static const arm_feature_set fpu_vfp_ext_fma =
354 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 355static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 356 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 357static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 358 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 359static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 360 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 361static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 362 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
d6b4b13e 363static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 364 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
365static const arm_feature_set fpu_neon_ext_dotprod =
366 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 367
33a392fb 368static int mfloat_abi_opt = -1;
4d354d8b
TP
369/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
370 directive. */
371static arm_feature_set selected_arch = ARM_ARCH_NONE;
372/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
373 directive. */
374static arm_feature_set selected_ext = ARM_ARCH_NONE;
375/* Feature bits selected by the last -mcpu/-march or by the combination of the
376 last .cpu/.arch directive .arch_extension directives since that
377 directive. */
e74cfd16 378static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
379/* FPU feature bits selected by the last -mfpu or .fpu directive. */
380static arm_feature_set selected_fpu = FPU_NONE;
381/* Feature bits selected by the last .object_arch directive. */
382static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 383/* Must be long enough to hold any of the names in arm_cpus. */
e20f9590 384static const struct arm_ext_table * selected_ctx_ext_table = NULL;
ef8e6722 385static char selected_cpu_name[20];
8d67f500 386
aacf0b33
KT
387extern FLONUM_TYPE generic_floating_point_number;
388
8d67f500
NC
389/* Return if no cpu was selected on command-line. */
390static bfd_boolean
391no_cpu_selected (void)
392{
823d2571 393 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
394}
395
7cc69913 396#ifdef OBJ_ELF
deeaaff8
DJ
397# ifdef EABI_DEFAULT
398static int meabi_flags = EABI_DEFAULT;
399# else
d507cf36 400static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 401# endif
e1da3f5b 402
ee3c0378
AS
403static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
404
e1da3f5b 405bfd_boolean
5f4273c7 406arm_is_eabi (void)
e1da3f5b
PB
407{
408 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
409}
7cc69913 410#endif
b99bd4ef 411
b99bd4ef 412#ifdef OBJ_ELF
c19d1205 413/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
414symbolS * GOT_symbol;
415#endif
416
b99bd4ef
NC
417/* 0: assemble for ARM,
418 1: assemble for Thumb,
419 2: assemble for Thumb even though target CPU does not support thumb
420 instructions. */
421static int thumb_mode = 0;
8dc2430f
NC
422/* A value distinct from the possible values for thumb_mode that we
423 can use to record whether thumb_mode has been copied into the
424 tc_frag_data field of a frag. */
425#define MODE_RECORDED (1 << 4)
b99bd4ef 426
e07e6e58
NC
427/* Specifies the intrinsic IT insn behavior mode. */
428enum implicit_it_mode
429{
430 IMPLICIT_IT_MODE_NEVER = 0x00,
431 IMPLICIT_IT_MODE_ARM = 0x01,
432 IMPLICIT_IT_MODE_THUMB = 0x02,
433 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
434};
435static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
436
c19d1205
ZW
437/* If unified_syntax is true, we are processing the new unified
438 ARM/Thumb syntax. Important differences from the old ARM mode:
439
440 - Immediate operands do not require a # prefix.
441 - Conditional affixes always appear at the end of the
442 instruction. (For backward compatibility, those instructions
443 that formerly had them in the middle, continue to accept them
444 there.)
445 - The IT instruction may appear, and if it does is validated
446 against subsequent conditional affixes. It does not generate
447 machine code.
448
449 Important differences from the old Thumb mode:
450
451 - Immediate operands do not require a # prefix.
452 - Most of the V6T2 instructions are only available in unified mode.
453 - The .N and .W suffixes are recognized and honored (it is an error
454 if they cannot be honored).
455 - All instructions set the flags if and only if they have an 's' affix.
456 - Conditional affixes may be used. They are validated against
457 preceding IT instructions. Unlike ARM mode, you cannot use a
458 conditional affix except in the scope of an IT instruction. */
459
460static bfd_boolean unified_syntax = FALSE;
b99bd4ef 461
bacebabc
RM
462/* An immediate operand can start with #, and ld*, st*, pld operands
463 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
464 before a [, which can appear as the first operand for pld.
465 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
466const char arm_symbol_chars[] = "#[]{}";
bacebabc 467
5287ad62
JB
468enum neon_el_type
469{
dcbf9037 470 NT_invtype,
5287ad62
JB
471 NT_untyped,
472 NT_integer,
473 NT_float,
474 NT_poly,
475 NT_signed,
aab2c27d 476 NT_bfloat,
dcbf9037 477 NT_unsigned
5287ad62
JB
478};
479
480struct neon_type_el
481{
482 enum neon_el_type type;
483 unsigned size;
484};
485
5aae9ae9 486#define NEON_MAX_TYPE_ELS 5
5287ad62
JB
487
488struct neon_type
489{
490 struct neon_type_el el[NEON_MAX_TYPE_ELS];
491 unsigned elems;
492};
493
5ee91343 494enum pred_instruction_type
e07e6e58 495{
5ee91343
AV
496 OUTSIDE_PRED_INSN,
497 INSIDE_VPT_INSN,
e07e6e58
NC
498 INSIDE_IT_INSN,
499 INSIDE_IT_LAST_INSN,
500 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 501 if inside, should be the last one. */
e07e6e58 502 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 503 i.e. BKPT and NOP. */
5ee91343
AV
504 IT_INSN, /* The IT insn has been parsed. */
505 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 506 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 507 a predication code. */
4934a27c 508 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
e07e6e58
NC
509};
510
ad6cec43
MGD
511/* The maximum number of operands we need. */
512#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 513#define ARM_IT_MAX_RELOCS 3
ad6cec43 514
b99bd4ef
NC
515struct arm_it
516{
c19d1205 517 const char * error;
b99bd4ef 518 unsigned long instruction;
c19d1205
ZW
519 int size;
520 int size_req;
521 int cond;
037e8744
JB
522 /* "uncond_value" is set to the value in place of the conditional field in
523 unconditional versions of the instruction, or -1 if nothing is
524 appropriate. */
525 int uncond_value;
5287ad62 526 struct neon_type vectype;
88714cb8
DG
527 /* This does not indicate an actual NEON instruction, only that
528 the mnemonic accepts neon-style type suffixes. */
529 int is_neon;
0110f2b8
PB
530 /* Set to the opcode if the instruction needs relaxation.
531 Zero if the instruction is not relaxed. */
532 unsigned long relax;
b99bd4ef
NC
533 struct
534 {
535 bfd_reloc_code_real_type type;
c19d1205
ZW
536 expressionS exp;
537 int pc_rel;
e2b0ab59 538 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 539
5ee91343 540 enum pred_instruction_type pred_insn_type;
e07e6e58 541
c19d1205
ZW
542 struct
543 {
544 unsigned reg;
ca3f61f7 545 signed int imm;
dcbf9037 546 struct neon_type_el vectype;
ca3f61f7
NC
547 unsigned present : 1; /* Operand present. */
548 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
549 unsigned immisreg : 2; /* .imm field is a second register.
550 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
551 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
552 0) not scalar,
553 1) Neon scalar,
554 2) MVE scalar. */
5287ad62 555 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 556 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
557 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
558 instructions. This allows us to disambiguate ARM <-> vector insns. */
559 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 560 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 561 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 562 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 563 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
564 unsigned hasreloc : 1; /* Operand has relocation suffix. */
565 unsigned writeback : 1; /* Operand has trailing ! */
566 unsigned preind : 1; /* Preindexed address. */
567 unsigned postind : 1; /* Postindexed address. */
568 unsigned negative : 1; /* Index register was negated. */
569 unsigned shifted : 1; /* Shift applied to operation. */
570 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 571 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
572};
573
c19d1205 574static struct arm_it inst;
b99bd4ef
NC
575
576#define NUM_FLOAT_VALS 8
577
05d2d07e 578const char * fp_const[] =
b99bd4ef
NC
579{
580 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
581};
582
b99bd4ef
NC
583LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
584
585#define FAIL (-1)
586#define SUCCESS (0)
587
588#define SUFF_S 1
589#define SUFF_D 2
590#define SUFF_E 3
591#define SUFF_P 4
592
c19d1205
ZW
593#define CP_T_X 0x00008000
594#define CP_T_Y 0x00400000
b99bd4ef 595
c19d1205
ZW
596#define CONDS_BIT 0x00100000
597#define LOAD_BIT 0x00100000
b99bd4ef
NC
598
599#define DOUBLE_LOAD_FLAG 0x00000001
600
601struct asm_cond
602{
d3ce72d0 603 const char * template_name;
c921be7d 604 unsigned long value;
b99bd4ef
NC
605};
606
c19d1205 607#define COND_ALWAYS 0xE
b99bd4ef 608
b99bd4ef
NC
609struct asm_psr
610{
d3ce72d0 611 const char * template_name;
c921be7d 612 unsigned long field;
b99bd4ef
NC
613};
614
62b3e311
PB
615struct asm_barrier_opt
616{
e797f7e0
MGD
617 const char * template_name;
618 unsigned long value;
619 const arm_feature_set arch;
62b3e311
PB
620};
621
2d2255b5 622/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
623#define SPSR_BIT (1 << 22)
624
c19d1205
ZW
625/* The individual PSR flag bits. */
626#define PSR_c (1 << 16)
627#define PSR_x (1 << 17)
628#define PSR_s (1 << 18)
629#define PSR_f (1 << 19)
b99bd4ef 630
c19d1205 631struct reloc_entry
bfae80f2 632{
0198d5e6 633 const char * name;
c921be7d 634 bfd_reloc_code_real_type reloc;
bfae80f2
RE
635};
636
5287ad62 637enum vfp_reg_pos
bfae80f2 638{
5287ad62
JB
639 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
640 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
641};
642
643enum vfp_ldstm_type
644{
645 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
646};
647
dcbf9037
JB
648/* Bits for DEFINED field in neon_typed_alias. */
649#define NTA_HASTYPE 1
650#define NTA_HASINDEX 2
651
652struct neon_typed_alias
653{
c921be7d
NC
654 unsigned char defined;
655 unsigned char index;
656 struct neon_type_el eltype;
dcbf9037
JB
657};
658
c19d1205 659/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
660 architecture extensions' registers. Each entry should have an error message
661 in reg_expected_msgs below. */
c19d1205 662enum arm_reg_type
bfae80f2 663{
c19d1205
ZW
664 REG_TYPE_RN,
665 REG_TYPE_CP,
666 REG_TYPE_CN,
667 REG_TYPE_FN,
668 REG_TYPE_VFS,
669 REG_TYPE_VFD,
5287ad62 670 REG_TYPE_NQ,
037e8744 671 REG_TYPE_VFSD,
5287ad62 672 REG_TYPE_NDQ,
dec41383 673 REG_TYPE_NSD,
037e8744 674 REG_TYPE_NSDQ,
c19d1205
ZW
675 REG_TYPE_VFC,
676 REG_TYPE_MVF,
677 REG_TYPE_MVD,
678 REG_TYPE_MVFX,
679 REG_TYPE_MVDX,
680 REG_TYPE_MVAX,
5ee91343 681 REG_TYPE_MQ,
c19d1205
ZW
682 REG_TYPE_DSPSC,
683 REG_TYPE_MMXWR,
684 REG_TYPE_MMXWC,
685 REG_TYPE_MMXWCG,
686 REG_TYPE_XSCALE,
5ee91343 687 REG_TYPE_RNB,
1b883319 688 REG_TYPE_ZR
bfae80f2
RE
689};
690
dcbf9037
JB
691/* Structure for a hash table entry for a register.
692 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
693 information which states whether a vector type or index is specified (for a
694 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
695struct reg_entry
696{
c921be7d 697 const char * name;
90ec0d68 698 unsigned int number;
c921be7d
NC
699 unsigned char type;
700 unsigned char builtin;
701 struct neon_typed_alias * neon;
6c43fab6
RE
702};
703
c19d1205 704/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 705const char * const reg_expected_msgs[] =
c19d1205 706{
5aa75429
TP
707 [REG_TYPE_RN] = N_("ARM register expected"),
708 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
709 [REG_TYPE_CN] = N_("co-processor register expected"),
710 [REG_TYPE_FN] = N_("FPA register expected"),
711 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
712 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
713 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
714 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
715 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
716 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
717 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
718 " expected"),
719 [REG_TYPE_VFC] = N_("VFP system register expected"),
720 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
721 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
722 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
723 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
724 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
725 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
726 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
727 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
728 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
729 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 730 [REG_TYPE_MQ] = N_("MVE vector register expected"),
da3ec71f 731 [REG_TYPE_RNB] = ""
6c43fab6
RE
732};
733
c19d1205 734/* Some well known registers that we refer to directly elsewhere. */
bd340a04 735#define REG_R12 12
c19d1205
ZW
736#define REG_SP 13
737#define REG_LR 14
738#define REG_PC 15
404ff6b5 739
b99bd4ef
NC
740/* ARM instructions take 4bytes in the object file, Thumb instructions
741 take 2: */
c19d1205 742#define INSN_SIZE 4
b99bd4ef
NC
743
744struct asm_opcode
745{
746 /* Basic string to match. */
d3ce72d0 747 const char * template_name;
c19d1205
ZW
748
749 /* Parameters to instruction. */
5be8be5d 750 unsigned int operands[8];
c19d1205
ZW
751
752 /* Conditional tag - see opcode_lookup. */
753 unsigned int tag : 4;
b99bd4ef
NC
754
755 /* Basic instruction code. */
a302e574 756 unsigned int avalue;
b99bd4ef 757
c19d1205
ZW
758 /* Thumb-format instruction code. */
759 unsigned int tvalue;
b99bd4ef 760
90e4755a 761 /* Which architecture variant provides this instruction. */
c921be7d
NC
762 const arm_feature_set * avariant;
763 const arm_feature_set * tvariant;
c19d1205
ZW
764
765 /* Function to call to encode instruction in ARM format. */
766 void (* aencode) (void);
b99bd4ef 767
c19d1205
ZW
768 /* Function to call to encode instruction in Thumb format. */
769 void (* tencode) (void);
5ee91343
AV
770
771 /* Indicates whether this instruction may be vector predicated. */
772 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
773};
774
a737bd4d
NC
775/* Defines for various bits that we will want to toggle. */
776#define INST_IMMEDIATE 0x02000000
777#define OFFSET_REG 0x02000000
c19d1205 778#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
779#define SHIFT_BY_REG 0x00000010
780#define PRE_INDEX 0x01000000
781#define INDEX_UP 0x00800000
782#define WRITE_BACK 0x00200000
783#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 784#define CPSI_MMOD 0x00020000
90e4755a 785
a737bd4d
NC
786#define LITERAL_MASK 0xf000f000
787#define OPCODE_MASK 0xfe1fffff
788#define V4_STR_BIT 0x00000020
8335d6aa 789#define VLDR_VMOV_SAME 0x0040f000
90e4755a 790
efd81785
PB
791#define T2_SUBS_PC_LR 0xf3de8f00
792
a737bd4d 793#define DATA_OP_SHIFT 21
bada4342 794#define SBIT_SHIFT 20
90e4755a 795
ef8d22e6
PB
796#define T2_OPCODE_MASK 0xfe1fffff
797#define T2_DATA_OP_SHIFT 21
bada4342 798#define T2_SBIT_SHIFT 20
ef8d22e6 799
6530b175
NC
800#define A_COND_MASK 0xf0000000
801#define A_PUSH_POP_OP_MASK 0x0fff0000
802
803/* Opcodes for pushing/poping registers to/from the stack. */
804#define A1_OPCODE_PUSH 0x092d0000
805#define A2_OPCODE_PUSH 0x052d0004
806#define A2_OPCODE_POP 0x049d0004
807
a737bd4d
NC
808/* Codes to distinguish the arithmetic instructions. */
809#define OPCODE_AND 0
810#define OPCODE_EOR 1
811#define OPCODE_SUB 2
812#define OPCODE_RSB 3
813#define OPCODE_ADD 4
814#define OPCODE_ADC 5
815#define OPCODE_SBC 6
816#define OPCODE_RSC 7
817#define OPCODE_TST 8
818#define OPCODE_TEQ 9
819#define OPCODE_CMP 10
820#define OPCODE_CMN 11
821#define OPCODE_ORR 12
822#define OPCODE_MOV 13
823#define OPCODE_BIC 14
824#define OPCODE_MVN 15
90e4755a 825
ef8d22e6
PB
826#define T2_OPCODE_AND 0
827#define T2_OPCODE_BIC 1
828#define T2_OPCODE_ORR 2
829#define T2_OPCODE_ORN 3
830#define T2_OPCODE_EOR 4
831#define T2_OPCODE_ADD 8
832#define T2_OPCODE_ADC 10
833#define T2_OPCODE_SBC 11
834#define T2_OPCODE_SUB 13
835#define T2_OPCODE_RSB 14
836
a737bd4d
NC
837#define T_OPCODE_MUL 0x4340
838#define T_OPCODE_TST 0x4200
839#define T_OPCODE_CMN 0x42c0
840#define T_OPCODE_NEG 0x4240
841#define T_OPCODE_MVN 0x43c0
90e4755a 842
a737bd4d
NC
843#define T_OPCODE_ADD_R3 0x1800
844#define T_OPCODE_SUB_R3 0x1a00
845#define T_OPCODE_ADD_HI 0x4400
846#define T_OPCODE_ADD_ST 0xb000
847#define T_OPCODE_SUB_ST 0xb080
848#define T_OPCODE_ADD_SP 0xa800
849#define T_OPCODE_ADD_PC 0xa000
850#define T_OPCODE_ADD_I8 0x3000
851#define T_OPCODE_SUB_I8 0x3800
852#define T_OPCODE_ADD_I3 0x1c00
853#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 854
a737bd4d
NC
855#define T_OPCODE_ASR_R 0x4100
856#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
857#define T_OPCODE_LSR_R 0x40c0
858#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
859#define T_OPCODE_ASR_I 0x1000
860#define T_OPCODE_LSL_I 0x0000
861#define T_OPCODE_LSR_I 0x0800
b99bd4ef 862
a737bd4d
NC
863#define T_OPCODE_MOV_I8 0x2000
864#define T_OPCODE_CMP_I8 0x2800
865#define T_OPCODE_CMP_LR 0x4280
866#define T_OPCODE_MOV_HR 0x4600
867#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 868
a737bd4d
NC
869#define T_OPCODE_LDR_PC 0x4800
870#define T_OPCODE_LDR_SP 0x9800
871#define T_OPCODE_STR_SP 0x9000
872#define T_OPCODE_LDR_IW 0x6800
873#define T_OPCODE_STR_IW 0x6000
874#define T_OPCODE_LDR_IH 0x8800
875#define T_OPCODE_STR_IH 0x8000
876#define T_OPCODE_LDR_IB 0x7800
877#define T_OPCODE_STR_IB 0x7000
878#define T_OPCODE_LDR_RW 0x5800
879#define T_OPCODE_STR_RW 0x5000
880#define T_OPCODE_LDR_RH 0x5a00
881#define T_OPCODE_STR_RH 0x5200
882#define T_OPCODE_LDR_RB 0x5c00
883#define T_OPCODE_STR_RB 0x5400
c9b604bd 884
a737bd4d
NC
885#define T_OPCODE_PUSH 0xb400
886#define T_OPCODE_POP 0xbc00
b99bd4ef 887
2fc8bdac 888#define T_OPCODE_BRANCH 0xe000
b99bd4ef 889
a737bd4d 890#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 891#define THUMB_PP_PC_LR 0x0100
c19d1205 892#define THUMB_LOAD_BIT 0x0800
53365c0d 893#define THUMB2_LOAD_BIT 0x00100000
c19d1205 894
5ee91343 895#define BAD_SYNTAX _("syntax error")
c19d1205 896#define BAD_ARGS _("bad arguments to instruction")
fdfde340 897#define BAD_SP _("r13 not allowed here")
c19d1205 898#define BAD_PC _("r15 not allowed here")
a302e574
AV
899#define BAD_ODD _("Odd register not allowed here")
900#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
901#define BAD_COND _("instruction cannot be conditional")
902#define BAD_OVERLAP _("registers may not be the same")
903#define BAD_HIREG _("lo register required")
904#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 905#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 906#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 907#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
4934a27c 908#define BAD_NO_VPT _("instruction not allowed in VPT block")
dfa9f0d5 909#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 910#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 911#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 912#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
913#define BAD_OUT_VPT \
914 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 915#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 916#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 917#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 918#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
919#define BAD_PC_ADDRESSING \
920 _("cannot use register index with PC-relative addressing")
921#define BAD_PC_WRITEBACK \
922 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
923#define BAD_RANGE _("branch out of range")
924#define BAD_FP16 _("selected processor does not support fp16 instruction")
aab2c27d 925#define BAD_BF16 _("selected processor does not support bf16 instruction")
4934a27c
MM
926#define BAD_CDE _("selected processor does not support cde instruction")
927#define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
dd5181d5 928#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 929#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
930#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
931 "block")
932#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
933 "block")
934#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
935 " operand")
936#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
937 " operand")
a302e574 938#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
939#define BAD_MVE_AUTO \
940 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
941 " use a valid -march or -mcpu option.")
942#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
943 "and source operands makes instruction UNPREDICTABLE")
35c228db 944#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 945#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 946
c921be7d
NC
947static struct hash_control * arm_ops_hsh;
948static struct hash_control * arm_cond_hsh;
5ee91343 949static struct hash_control * arm_vcond_hsh;
c921be7d
NC
950static struct hash_control * arm_shift_hsh;
951static struct hash_control * arm_psr_hsh;
952static struct hash_control * arm_v7m_psr_hsh;
953static struct hash_control * arm_reg_hsh;
954static struct hash_control * arm_reloc_hsh;
955static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 956
b99bd4ef
NC
957/* Stuff needed to resolve the label ambiguity
958 As:
959 ...
960 label: <insn>
961 may differ from:
962 ...
963 label:
5f4273c7 964 <insn> */
b99bd4ef
NC
965
966symbolS * last_label_seen;
b34976b6 967static int label_is_thumb_function_name = FALSE;
e07e6e58 968
3d0c9500
NC
969/* Literal pool structure. Held on a per-section
970 and per-sub-section basis. */
a737bd4d 971
c19d1205 972#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 973typedef struct literal_pool
b99bd4ef 974{
c921be7d
NC
975 expressionS literals [MAX_LITERAL_POOL_SIZE];
976 unsigned int next_free_entry;
977 unsigned int id;
978 symbolS * symbol;
979 segT section;
980 subsegT sub_section;
a8040cf2
NC
981#ifdef OBJ_ELF
982 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
983#endif
c921be7d 984 struct literal_pool * next;
8335d6aa 985 unsigned int alignment;
3d0c9500 986} literal_pool;
b99bd4ef 987
3d0c9500
NC
988/* Pointer to a linked list of literal pools. */
989literal_pool * list_of_pools = NULL;
e27ec89e 990
2e6976a8
DG
991typedef enum asmfunc_states
992{
993 OUTSIDE_ASMFUNC,
994 WAITING_ASMFUNC_NAME,
995 WAITING_ENDASMFUNC
996} asmfunc_states;
997
998static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
999
e07e6e58 1000#ifdef OBJ_ELF
5ee91343 1001# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 1002#else
5ee91343 1003static struct current_pred now_pred;
e07e6e58
NC
1004#endif
1005
1006static inline int
5ee91343 1007now_pred_compatible (int cond)
e07e6e58 1008{
5ee91343 1009 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
1010}
1011
1012static inline int
1013conditional_insn (void)
1014{
1015 return inst.cond != COND_ALWAYS;
1016}
1017
5ee91343 1018static int in_pred_block (void);
e07e6e58 1019
5ee91343 1020static int handle_pred_state (void);
e07e6e58
NC
1021
1022static void force_automatic_it_block_close (void);
1023
c921be7d
NC
1024static void it_fsm_post_encode (void);
1025
5ee91343 1026#define set_pred_insn_type(type) \
e07e6e58
NC
1027 do \
1028 { \
5ee91343
AV
1029 inst.pred_insn_type = type; \
1030 if (handle_pred_state () == FAIL) \
477330fc 1031 return; \
e07e6e58
NC
1032 } \
1033 while (0)
1034
5ee91343 1035#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
1036 do \
1037 { \
5ee91343
AV
1038 inst.pred_insn_type = type; \
1039 if (handle_pred_state () == FAIL) \
477330fc 1040 return failret; \
c921be7d
NC
1041 } \
1042 while(0)
1043
5ee91343 1044#define set_pred_insn_type_last() \
e07e6e58
NC
1045 do \
1046 { \
1047 if (inst.cond == COND_ALWAYS) \
5ee91343 1048 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1049 else \
5ee91343 1050 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1051 } \
1052 while (0)
1053
e39c1607
SD
1054/* Toggle value[pos]. */
1055#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1056
c19d1205 1057/* Pure syntax. */
b99bd4ef 1058
c19d1205
ZW
1059/* This array holds the chars that always start a comment. If the
1060 pre-processor is disabled, these aren't very useful. */
2e6976a8 1061char arm_comment_chars[] = "@";
3d0c9500 1062
c19d1205
ZW
1063/* This array holds the chars that only start a comment at the beginning of
1064 a line. If the line seems to have the form '# 123 filename'
1065 .line and .file directives will appear in the pre-processed output. */
1066/* Note that input_file.c hand checks for '#' at the beginning of the
1067 first line of the input file. This is because the compiler outputs
1068 #NO_APP at the beginning of its output. */
1069/* Also note that comments like this one will always work. */
1070const char line_comment_chars[] = "#";
3d0c9500 1071
2e6976a8 1072char arm_line_separator_chars[] = ";";
b99bd4ef 1073
c19d1205
ZW
1074/* Chars that can be used to separate mant
1075 from exp in floating point numbers. */
1076const char EXP_CHARS[] = "eE";
3d0c9500 1077
c19d1205
ZW
1078/* Chars that mean this number is a floating point constant. */
1079/* As in 0f12.456 */
1080/* or 0d1.2345e12 */
b99bd4ef 1081
5312fe52 1082const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1083
c19d1205
ZW
1084/* Prefix characters that indicate the start of an immediate
1085 value. */
1086#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1087
c19d1205
ZW
1088/* Separator character handling. */
1089
1090#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1091
5312fe52
BW
1092enum fp_16bit_format
1093{
1094 ARM_FP16_FORMAT_IEEE = 0x1,
1095 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1096 ARM_FP16_FORMAT_DEFAULT = 0x3
1097};
1098
1099static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1100
1101
c19d1205
ZW
1102static inline int
1103skip_past_char (char ** str, char c)
1104{
8ab8155f
NC
1105 /* PR gas/14987: Allow for whitespace before the expected character. */
1106 skip_whitespace (*str);
427d0db6 1107
c19d1205
ZW
1108 if (**str == c)
1109 {
1110 (*str)++;
1111 return SUCCESS;
3d0c9500 1112 }
c19d1205
ZW
1113 else
1114 return FAIL;
1115}
c921be7d 1116
c19d1205 1117#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1118
c19d1205
ZW
1119/* Arithmetic expressions (possibly involving symbols). */
1120
1121/* Return TRUE if anything in the expression is a bignum. */
1122
0198d5e6 1123static bfd_boolean
c19d1205
ZW
1124walk_no_bignums (symbolS * sp)
1125{
1126 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1127 return TRUE;
c19d1205
ZW
1128
1129 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1130 {
c19d1205
ZW
1131 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1132 || (symbol_get_value_expression (sp)->X_op_symbol
1133 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1134 }
1135
0198d5e6 1136 return FALSE;
3d0c9500
NC
1137}
1138
0198d5e6 1139static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1140
1141/* Third argument to my_get_expression. */
1142#define GE_NO_PREFIX 0
1143#define GE_IMM_PREFIX 1
1144#define GE_OPT_PREFIX 2
5287ad62
JB
1145/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1146 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1147#define GE_OPT_PREFIX_BIG 3
a737bd4d 1148
b99bd4ef 1149static int
c19d1205 1150my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1151{
c19d1205 1152 char * save_in;
b99bd4ef 1153
c19d1205
ZW
1154 /* In unified syntax, all prefixes are optional. */
1155 if (unified_syntax)
5287ad62 1156 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1157 : GE_OPT_PREFIX;
b99bd4ef 1158
c19d1205 1159 switch (prefix_mode)
b99bd4ef 1160 {
c19d1205
ZW
1161 case GE_NO_PREFIX: break;
1162 case GE_IMM_PREFIX:
1163 if (!is_immediate_prefix (**str))
1164 {
1165 inst.error = _("immediate expression requires a # prefix");
1166 return FAIL;
1167 }
1168 (*str)++;
1169 break;
1170 case GE_OPT_PREFIX:
5287ad62 1171 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1172 if (is_immediate_prefix (**str))
1173 (*str)++;
1174 break;
0198d5e6
TC
1175 default:
1176 abort ();
c19d1205 1177 }
b99bd4ef 1178
c19d1205 1179 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1180
c19d1205
ZW
1181 save_in = input_line_pointer;
1182 input_line_pointer = *str;
0198d5e6 1183 in_my_get_expression = TRUE;
2ac93be7 1184 expression (ep);
0198d5e6 1185 in_my_get_expression = FALSE;
c19d1205 1186
f86adc07 1187 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1188 {
f86adc07 1189 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1190 *str = input_line_pointer;
1191 input_line_pointer = save_in;
1192 if (inst.error == NULL)
f86adc07
NS
1193 inst.error = (ep->X_op == O_absent
1194 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1195 return 1;
1196 }
b99bd4ef 1197
c19d1205
ZW
1198 /* Get rid of any bignums now, so that we don't generate an error for which
1199 we can't establish a line number later on. Big numbers are never valid
1200 in instructions, which is where this routine is always called. */
5287ad62
JB
1201 if (prefix_mode != GE_OPT_PREFIX_BIG
1202 && (ep->X_op == O_big
477330fc 1203 || (ep->X_add_symbol
5287ad62 1204 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1205 || (ep->X_op_symbol
5287ad62 1206 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1207 {
1208 inst.error = _("invalid constant");
1209 *str = input_line_pointer;
1210 input_line_pointer = save_in;
1211 return 1;
1212 }
b99bd4ef 1213
c19d1205
ZW
1214 *str = input_line_pointer;
1215 input_line_pointer = save_in;
0198d5e6 1216 return SUCCESS;
b99bd4ef
NC
1217}
1218
c19d1205
ZW
1219/* Turn a string in input_line_pointer into a floating point constant
1220 of type TYPE, and store the appropriate bytes in *LITP. The number
1221 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1222 returned, or NULL on OK.
b99bd4ef 1223
c19d1205
ZW
1224 Note that fp constants aren't represent in the normal way on the ARM.
1225 In big endian mode, things are as expected. However, in little endian
1226 mode fp constants are big-endian word-wise, and little-endian byte-wise
1227 within the words. For example, (double) 1.1 in big endian mode is
1228 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1229 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1230
c19d1205 1231 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1232
6d4af3c2 1233const char *
c19d1205
ZW
1234md_atof (int type, char * litP, int * sizeP)
1235{
1236 int prec;
1237 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1238 char *t;
1239 int i;
b99bd4ef 1240
c19d1205
ZW
1241 switch (type)
1242 {
5312fe52
BW
1243 case 'H':
1244 case 'h':
1245 prec = 1;
1246 break;
1247
27cce866
MM
1248 /* If this is a bfloat16, then parse it slightly differently, as it
1249 does not follow the IEEE specification for floating point numbers
1250 exactly. */
1251 case 'b':
1252 {
1253 FLONUM_TYPE generic_float;
1254
1255 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1256
1257 if (t)
1258 input_line_pointer = t;
1259 else
1260 return _("invalid floating point number");
1261
1262 switch (generic_float.sign)
1263 {
1264 /* Is +Inf. */
1265 case 'P':
1266 words[0] = 0x7f80;
1267 break;
1268
1269 /* Is -Inf. */
1270 case 'N':
1271 words[0] = 0xff80;
1272 break;
1273
1274 /* Is NaN. */
1275 /* bfloat16 has two types of NaN - quiet and signalling.
1276 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1277 signalling NaN's have bit[0] == 0 && fraction != 0.
1278 Chosen this specific encoding as it is the same form
1279 as used by other IEEE 754 encodings in GAS. */
1280 case 0:
1281 words[0] = 0x7fff;
1282 break;
1283
1284 default:
1285 break;
1286 }
1287
1288 *sizeP = 2;
1289
1290 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1291
1292 return NULL;
1293 }
c19d1205
ZW
1294 case 'f':
1295 case 'F':
1296 case 's':
1297 case 'S':
1298 prec = 2;
1299 break;
b99bd4ef 1300
c19d1205
ZW
1301 case 'd':
1302 case 'D':
1303 case 'r':
1304 case 'R':
1305 prec = 4;
1306 break;
b99bd4ef 1307
c19d1205
ZW
1308 case 'x':
1309 case 'X':
499ac353 1310 prec = 5;
c19d1205 1311 break;
b99bd4ef 1312
c19d1205
ZW
1313 case 'p':
1314 case 'P':
499ac353 1315 prec = 5;
c19d1205 1316 break;
a737bd4d 1317
c19d1205
ZW
1318 default:
1319 *sizeP = 0;
499ac353 1320 return _("Unrecognized or unsupported floating point constant");
c19d1205 1321 }
b99bd4ef 1322
c19d1205
ZW
1323 t = atof_ieee (input_line_pointer, type, words);
1324 if (t)
1325 input_line_pointer = t;
499ac353 1326 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1327
72c03e30
BW
1328 if (target_big_endian || prec == 1)
1329 for (i = 0; i < prec; i++)
1330 {
1331 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1332 litP += sizeof (LITTLENUM_TYPE);
1333 }
1334 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1335 for (i = prec - 1; i >= 0; i--)
1336 {
1337 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1338 litP += sizeof (LITTLENUM_TYPE);
1339 }
c19d1205 1340 else
72c03e30
BW
1341 /* For a 4 byte float the order of elements in `words' is 1 0.
1342 For an 8 byte float the order is 1 0 3 2. */
1343 for (i = 0; i < prec; i += 2)
1344 {
1345 md_number_to_chars (litP, (valueT) words[i + 1],
1346 sizeof (LITTLENUM_TYPE));
1347 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1348 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1349 litP += 2 * sizeof (LITTLENUM_TYPE);
1350 }
b99bd4ef 1351
499ac353 1352 return NULL;
c19d1205 1353}
b99bd4ef 1354
c19d1205
ZW
1355/* We handle all bad expressions here, so that we can report the faulty
1356 instruction in the error message. */
0198d5e6 1357
c19d1205 1358void
91d6fa6a 1359md_operand (expressionS * exp)
c19d1205
ZW
1360{
1361 if (in_my_get_expression)
91d6fa6a 1362 exp->X_op = O_illegal;
b99bd4ef
NC
1363}
1364
c19d1205 1365/* Immediate values. */
b99bd4ef 1366
0198d5e6 1367#ifdef OBJ_ELF
c19d1205
ZW
1368/* Generic immediate-value read function for use in directives.
1369 Accepts anything that 'expression' can fold to a constant.
1370 *val receives the number. */
0198d5e6 1371
c19d1205
ZW
1372static int
1373immediate_for_directive (int *val)
b99bd4ef 1374{
c19d1205
ZW
1375 expressionS exp;
1376 exp.X_op = O_illegal;
b99bd4ef 1377
c19d1205
ZW
1378 if (is_immediate_prefix (*input_line_pointer))
1379 {
1380 input_line_pointer++;
1381 expression (&exp);
1382 }
b99bd4ef 1383
c19d1205
ZW
1384 if (exp.X_op != O_constant)
1385 {
1386 as_bad (_("expected #constant"));
1387 ignore_rest_of_line ();
1388 return FAIL;
1389 }
1390 *val = exp.X_add_number;
1391 return SUCCESS;
b99bd4ef 1392}
c19d1205 1393#endif
b99bd4ef 1394
c19d1205 1395/* Register parsing. */
b99bd4ef 1396
c19d1205
ZW
1397/* Generic register parser. CCP points to what should be the
1398 beginning of a register name. If it is indeed a valid register
1399 name, advance CCP over it and return the reg_entry structure;
1400 otherwise return NULL. Does not issue diagnostics. */
1401
1402static struct reg_entry *
1403arm_reg_parse_multi (char **ccp)
b99bd4ef 1404{
c19d1205
ZW
1405 char *start = *ccp;
1406 char *p;
1407 struct reg_entry *reg;
b99bd4ef 1408
477330fc
RM
1409 skip_whitespace (start);
1410
c19d1205
ZW
1411#ifdef REGISTER_PREFIX
1412 if (*start != REGISTER_PREFIX)
01cfc07f 1413 return NULL;
c19d1205
ZW
1414 start++;
1415#endif
1416#ifdef OPTIONAL_REGISTER_PREFIX
1417 if (*start == OPTIONAL_REGISTER_PREFIX)
1418 start++;
1419#endif
b99bd4ef 1420
c19d1205
ZW
1421 p = start;
1422 if (!ISALPHA (*p) || !is_name_beginner (*p))
1423 return NULL;
b99bd4ef 1424
c19d1205
ZW
1425 do
1426 p++;
1427 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1428
1429 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1430
1431 if (!reg)
1432 return NULL;
1433
1434 *ccp = p;
1435 return reg;
b99bd4ef
NC
1436}
1437
1438static int
dcbf9037 1439arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1440 enum arm_reg_type type)
b99bd4ef 1441{
c19d1205
ZW
1442 /* Alternative syntaxes are accepted for a few register classes. */
1443 switch (type)
1444 {
1445 case REG_TYPE_MVF:
1446 case REG_TYPE_MVD:
1447 case REG_TYPE_MVFX:
1448 case REG_TYPE_MVDX:
1449 /* Generic coprocessor register names are allowed for these. */
79134647 1450 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1451 return reg->number;
1452 break;
69b97547 1453
c19d1205
ZW
1454 case REG_TYPE_CP:
1455 /* For backward compatibility, a bare number is valid here. */
1456 {
1457 unsigned long processor = strtoul (start, ccp, 10);
1458 if (*ccp != start && processor <= 15)
1459 return processor;
1460 }
1a0670f3 1461 /* Fall through. */
6057a28f 1462
c19d1205
ZW
1463 case REG_TYPE_MMXWC:
1464 /* WC includes WCG. ??? I'm not sure this is true for all
1465 instructions that take WC registers. */
79134647 1466 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1467 return reg->number;
6057a28f 1468 break;
c19d1205 1469
6057a28f 1470 default:
c19d1205 1471 break;
6057a28f
NC
1472 }
1473
dcbf9037
JB
1474 return FAIL;
1475}
1476
1477/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1478 return value is the register number or FAIL. */
1479
1480static int
1481arm_reg_parse (char **ccp, enum arm_reg_type type)
1482{
1483 char *start = *ccp;
1484 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1485 int ret;
1486
1487 /* Do not allow a scalar (reg+index) to parse as a register. */
1488 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1489 return FAIL;
1490
1491 if (reg && reg->type == type)
1492 return reg->number;
1493
1494 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1495 return ret;
1496
c19d1205
ZW
1497 *ccp = start;
1498 return FAIL;
1499}
69b97547 1500
dcbf9037
JB
1501/* Parse a Neon type specifier. *STR should point at the leading '.'
1502 character. Does no verification at this stage that the type fits the opcode
1503 properly. E.g.,
1504
1505 .i32.i32.s16
1506 .s32.f32
1507 .u16
1508
1509 Can all be legally parsed by this function.
1510
1511 Fills in neon_type struct pointer with parsed information, and updates STR
1512 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1513 type, FAIL if not. */
1514
1515static int
1516parse_neon_type (struct neon_type *type, char **str)
1517{
1518 char *ptr = *str;
1519
1520 if (type)
1521 type->elems = 0;
1522
1523 while (type->elems < NEON_MAX_TYPE_ELS)
1524 {
1525 enum neon_el_type thistype = NT_untyped;
1526 unsigned thissize = -1u;
1527
1528 if (*ptr != '.')
1529 break;
1530
1531 ptr++;
1532
1533 /* Just a size without an explicit type. */
1534 if (ISDIGIT (*ptr))
1535 goto parsesize;
1536
1537 switch (TOLOWER (*ptr))
1538 {
1539 case 'i': thistype = NT_integer; break;
1540 case 'f': thistype = NT_float; break;
1541 case 'p': thistype = NT_poly; break;
1542 case 's': thistype = NT_signed; break;
1543 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1544 case 'd':
1545 thistype = NT_float;
1546 thissize = 64;
1547 ptr++;
1548 goto done;
aab2c27d
MM
1549 case 'b':
1550 thistype = NT_bfloat;
1551 switch (TOLOWER (*(++ptr)))
1552 {
1553 case 'f':
1554 ptr += 1;
1555 thissize = strtoul (ptr, &ptr, 10);
1556 if (thissize != 16)
1557 {
1558 as_bad (_("bad size %d in type specifier"), thissize);
1559 return FAIL;
1560 }
1561 goto done;
1562 case '0': case '1': case '2': case '3': case '4':
1563 case '5': case '6': case '7': case '8': case '9':
1564 case ' ': case '.':
1565 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1566 return FAIL;
1567 default:
1568 break;
1569 }
1570 break;
dcbf9037
JB
1571 default:
1572 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1573 return FAIL;
1574 }
1575
1576 ptr++;
1577
1578 /* .f is an abbreviation for .f32. */
1579 if (thistype == NT_float && !ISDIGIT (*ptr))
1580 thissize = 32;
1581 else
1582 {
1583 parsesize:
1584 thissize = strtoul (ptr, &ptr, 10);
1585
1586 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1587 && thissize != 64)
1588 {
1589 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1590 return FAIL;
1591 }
1592 }
1593
037e8744 1594 done:
dcbf9037 1595 if (type)
477330fc
RM
1596 {
1597 type->el[type->elems].type = thistype;
dcbf9037
JB
1598 type->el[type->elems].size = thissize;
1599 type->elems++;
1600 }
1601 }
1602
1603 /* Empty/missing type is not a successful parse. */
1604 if (type->elems == 0)
1605 return FAIL;
1606
1607 *str = ptr;
1608
1609 return SUCCESS;
1610}
1611
1612/* Errors may be set multiple times during parsing or bit encoding
1613 (particularly in the Neon bits), but usually the earliest error which is set
1614 will be the most meaningful. Avoid overwriting it with later (cascading)
1615 errors by calling this function. */
1616
1617static void
1618first_error (const char *err)
1619{
1620 if (!inst.error)
1621 inst.error = err;
1622}
1623
1624/* Parse a single type, e.g. ".s32", leading period included. */
1625static int
1626parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1627{
1628 char *str = *ccp;
1629 struct neon_type optype;
1630
1631 if (*str == '.')
1632 {
1633 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1634 {
1635 if (optype.elems == 1)
1636 *vectype = optype.el[0];
1637 else
1638 {
1639 first_error (_("only one type should be specified for operand"));
1640 return FAIL;
1641 }
1642 }
dcbf9037 1643 else
477330fc
RM
1644 {
1645 first_error (_("vector type expected"));
1646 return FAIL;
1647 }
dcbf9037
JB
1648 }
1649 else
1650 return FAIL;
5f4273c7 1651
dcbf9037 1652 *ccp = str;
5f4273c7 1653
dcbf9037
JB
1654 return SUCCESS;
1655}
1656
1657/* Special meanings for indices (which have a range of 0-7), which will fit into
1658 a 4-bit integer. */
1659
1660#define NEON_ALL_LANES 15
1661#define NEON_INTERLEAVE_LANES 14
1662
5ee91343
AV
1663/* Record a use of the given feature. */
1664static void
1665record_feature_use (const arm_feature_set *feature)
1666{
1667 if (thumb_mode)
1668 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1669 else
1670 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1671}
1672
1673/* If the given feature available in the selected CPU, mark it as used.
1674 Returns TRUE iff feature is available. */
1675static bfd_boolean
1676mark_feature_used (const arm_feature_set *feature)
1677{
886e1c73
AV
1678
1679 /* Do not support the use of MVE only instructions when in auto-detection or
1680 -march=all. */
1681 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1682 && ARM_CPU_IS_ANY (cpu_variant))
1683 {
1684 first_error (BAD_MVE_AUTO);
1685 return FALSE;
1686 }
5ee91343
AV
1687 /* Ensure the option is valid on the current architecture. */
1688 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1689 return FALSE;
1690
1691 /* Add the appropriate architecture feature for the barrier option used.
1692 */
1693 record_feature_use (feature);
1694
1695 return TRUE;
1696}
1697
dcbf9037
JB
1698/* Parse either a register or a scalar, with an optional type. Return the
1699 register number, and optionally fill in the actual type of the register
1700 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1701 type/index information in *TYPEINFO. */
1702
1703static int
1704parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1705 enum arm_reg_type *rtype,
1706 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1707{
1708 char *str = *ccp;
1709 struct reg_entry *reg = arm_reg_parse_multi (&str);
1710 struct neon_typed_alias atype;
1711 struct neon_type_el parsetype;
1712
1713 atype.defined = 0;
1714 atype.index = -1;
1715 atype.eltype.type = NT_invtype;
1716 atype.eltype.size = -1;
1717
1718 /* Try alternate syntax for some types of register. Note these are mutually
1719 exclusive with the Neon syntax extensions. */
1720 if (reg == NULL)
1721 {
1722 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1723 if (altreg != FAIL)
477330fc 1724 *ccp = str;
dcbf9037 1725 if (typeinfo)
477330fc 1726 *typeinfo = atype;
dcbf9037
JB
1727 return altreg;
1728 }
1729
037e8744
JB
1730 /* Undo polymorphism when a set of register types may be accepted. */
1731 if ((type == REG_TYPE_NDQ
1732 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1733 || (type == REG_TYPE_VFSD
477330fc 1734 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1735 || (type == REG_TYPE_NSDQ
477330fc
RM
1736 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1737 || reg->type == REG_TYPE_NQ))
dec41383
JW
1738 || (type == REG_TYPE_NSD
1739 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1740 || (type == REG_TYPE_MMXWC
1741 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1742 type = (enum arm_reg_type) reg->type;
dcbf9037 1743
5ee91343
AV
1744 if (type == REG_TYPE_MQ)
1745 {
1746 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1747 return FAIL;
1748
1749 if (!reg || reg->type != REG_TYPE_NQ)
1750 return FAIL;
1751
1752 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1753 {
1754 first_error (_("expected MVE register [q0..q7]"));
1755 return FAIL;
1756 }
1757 type = REG_TYPE_NQ;
1758 }
1759 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1760 && (type == REG_TYPE_NQ))
1761 return FAIL;
1762
1763
dcbf9037
JB
1764 if (type != reg->type)
1765 return FAIL;
1766
1767 if (reg->neon)
1768 atype = *reg->neon;
5f4273c7 1769
dcbf9037
JB
1770 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1771 {
1772 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1773 {
1774 first_error (_("can't redefine type for operand"));
1775 return FAIL;
1776 }
dcbf9037
JB
1777 atype.defined |= NTA_HASTYPE;
1778 atype.eltype = parsetype;
1779 }
5f4273c7 1780
dcbf9037
JB
1781 if (skip_past_char (&str, '[') == SUCCESS)
1782 {
dec41383
JW
1783 if (type != REG_TYPE_VFD
1784 && !(type == REG_TYPE_VFS
57785aa2
AV
1785 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1786 && !(type == REG_TYPE_NQ
1787 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1788 {
57785aa2
AV
1789 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1790 first_error (_("only D and Q registers may be indexed"));
1791 else
1792 first_error (_("only D registers may be indexed"));
477330fc
RM
1793 return FAIL;
1794 }
5f4273c7 1795
dcbf9037 1796 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1797 {
1798 first_error (_("can't change index for operand"));
1799 return FAIL;
1800 }
dcbf9037
JB
1801
1802 atype.defined |= NTA_HASINDEX;
1803
1804 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1805 atype.index = NEON_ALL_LANES;
dcbf9037 1806 else
477330fc
RM
1807 {
1808 expressionS exp;
dcbf9037 1809
477330fc 1810 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1811
477330fc
RM
1812 if (exp.X_op != O_constant)
1813 {
1814 first_error (_("constant expression required"));
1815 return FAIL;
1816 }
dcbf9037 1817
477330fc
RM
1818 if (skip_past_char (&str, ']') == FAIL)
1819 return FAIL;
dcbf9037 1820
477330fc
RM
1821 atype.index = exp.X_add_number;
1822 }
dcbf9037 1823 }
5f4273c7 1824
dcbf9037
JB
1825 if (typeinfo)
1826 *typeinfo = atype;
5f4273c7 1827
dcbf9037
JB
1828 if (rtype)
1829 *rtype = type;
5f4273c7 1830
dcbf9037 1831 *ccp = str;
5f4273c7 1832
dcbf9037
JB
1833 return reg->number;
1834}
1835
efd6b359 1836/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1837 - If RTYPE is non-zero, return the (possibly restricted) type of the
1838 register (e.g. Neon double or quad reg when either has been requested).
1839 - If this is a Neon vector type with additional type information, fill
1840 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1841 This function will fault on encountering a scalar. */
dcbf9037
JB
1842
1843static int
1844arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1845 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1846{
1847 struct neon_typed_alias atype;
1848 char *str = *ccp;
1849 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1850
1851 if (reg == FAIL)
1852 return FAIL;
1853
0855e32b
NS
1854 /* Do not allow regname(... to parse as a register. */
1855 if (*str == '(')
1856 return FAIL;
1857
dcbf9037
JB
1858 /* Do not allow a scalar (reg+index) to parse as a register. */
1859 if ((atype.defined & NTA_HASINDEX) != 0)
1860 {
1861 first_error (_("register operand expected, but got scalar"));
1862 return FAIL;
1863 }
1864
1865 if (vectype)
1866 *vectype = atype.eltype;
1867
1868 *ccp = str;
1869
1870 return reg;
1871}
1872
1873#define NEON_SCALAR_REG(X) ((X) >> 4)
1874#define NEON_SCALAR_INDEX(X) ((X) & 15)
1875
5287ad62
JB
1876/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1877 have enough information to be able to do a good job bounds-checking. So, we
1878 just do easy checks here, and do further checks later. */
1879
1880static int
57785aa2
AV
1881parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1882 arm_reg_type reg_type)
5287ad62 1883{
dcbf9037 1884 int reg;
5287ad62 1885 char *str = *ccp;
dcbf9037 1886 struct neon_typed_alias atype;
57785aa2 1887 unsigned reg_size;
5f4273c7 1888
dec41383 1889 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1890
57785aa2
AV
1891 switch (reg_type)
1892 {
1893 case REG_TYPE_VFS:
1894 reg_size = 32;
1895 break;
1896 case REG_TYPE_VFD:
1897 reg_size = 64;
1898 break;
1899 case REG_TYPE_MQ:
1900 reg_size = 128;
1901 break;
1902 default:
1903 gas_assert (0);
1904 return FAIL;
1905 }
1906
dcbf9037 1907 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1908 return FAIL;
5f4273c7 1909
57785aa2 1910 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1911 {
dcbf9037 1912 first_error (_("scalar must have an index"));
5287ad62
JB
1913 return FAIL;
1914 }
57785aa2 1915 else if (atype.index >= reg_size / elsize)
5287ad62 1916 {
dcbf9037 1917 first_error (_("scalar index out of range"));
5287ad62
JB
1918 return FAIL;
1919 }
5f4273c7 1920
dcbf9037
JB
1921 if (type)
1922 *type = atype.eltype;
5f4273c7 1923
5287ad62 1924 *ccp = str;
5f4273c7 1925
dcbf9037 1926 return reg * 16 + atype.index;
5287ad62
JB
1927}
1928
4b5a202f
AV
1929/* Types of registers in a list. */
1930
1931enum reg_list_els
1932{
1933 REGLIST_RN,
1934 REGLIST_CLRM,
1935 REGLIST_VFP_S,
efd6b359 1936 REGLIST_VFP_S_VPR,
4b5a202f 1937 REGLIST_VFP_D,
efd6b359 1938 REGLIST_VFP_D_VPR,
4b5a202f
AV
1939 REGLIST_NEON_D
1940};
1941
c19d1205 1942/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1943
c19d1205 1944static long
4b5a202f 1945parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1946{
4b5a202f
AV
1947 char *str = *strp;
1948 long range = 0;
1949 int another_range;
1950
1951 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1952
c19d1205
ZW
1953 /* We come back here if we get ranges concatenated by '+' or '|'. */
1954 do
6057a28f 1955 {
477330fc
RM
1956 skip_whitespace (str);
1957
c19d1205 1958 another_range = 0;
a737bd4d 1959
c19d1205
ZW
1960 if (*str == '{')
1961 {
1962 int in_range = 0;
1963 int cur_reg = -1;
a737bd4d 1964
c19d1205
ZW
1965 str++;
1966 do
1967 {
1968 int reg;
4b5a202f
AV
1969 const char apsr_str[] = "apsr";
1970 int apsr_str_len = strlen (apsr_str);
6057a28f 1971
a65b5de6 1972 reg = arm_reg_parse (&str, REG_TYPE_RN);
4b5a202f 1973 if (etype == REGLIST_CLRM)
c19d1205 1974 {
4b5a202f
AV
1975 if (reg == REG_SP || reg == REG_PC)
1976 reg = FAIL;
1977 else if (reg == FAIL
1978 && !strncasecmp (str, apsr_str, apsr_str_len)
1979 && !ISALPHA (*(str + apsr_str_len)))
1980 {
1981 reg = 15;
1982 str += apsr_str_len;
1983 }
1984
1985 if (reg == FAIL)
1986 {
1987 first_error (_("r0-r12, lr or APSR expected"));
1988 return FAIL;
1989 }
1990 }
1991 else /* etype == REGLIST_RN. */
1992 {
1993 if (reg == FAIL)
1994 {
1995 first_error (_(reg_expected_msgs[REGLIST_RN]));
1996 return FAIL;
1997 }
c19d1205 1998 }
a737bd4d 1999
c19d1205
ZW
2000 if (in_range)
2001 {
2002 int i;
a737bd4d 2003
c19d1205
ZW
2004 if (reg <= cur_reg)
2005 {
dcbf9037 2006 first_error (_("bad range in register list"));
c19d1205
ZW
2007 return FAIL;
2008 }
40a18ebd 2009
c19d1205
ZW
2010 for (i = cur_reg + 1; i < reg; i++)
2011 {
2012 if (range & (1 << i))
2013 as_tsktsk
2014 (_("Warning: duplicated register (r%d) in register list"),
2015 i);
2016 else
2017 range |= 1 << i;
2018 }
2019 in_range = 0;
2020 }
a737bd4d 2021
c19d1205
ZW
2022 if (range & (1 << reg))
2023 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2024 reg);
2025 else if (reg <= cur_reg)
2026 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 2027
c19d1205
ZW
2028 range |= 1 << reg;
2029 cur_reg = reg;
2030 }
2031 while (skip_past_comma (&str) != FAIL
2032 || (in_range = 1, *str++ == '-'));
2033 str--;
a737bd4d 2034
d996d970 2035 if (skip_past_char (&str, '}') == FAIL)
c19d1205 2036 {
dcbf9037 2037 first_error (_("missing `}'"));
c19d1205
ZW
2038 return FAIL;
2039 }
2040 }
4b5a202f 2041 else if (etype == REGLIST_RN)
c19d1205 2042 {
91d6fa6a 2043 expressionS exp;
40a18ebd 2044
91d6fa6a 2045 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 2046 return FAIL;
40a18ebd 2047
91d6fa6a 2048 if (exp.X_op == O_constant)
c19d1205 2049 {
91d6fa6a
NC
2050 if (exp.X_add_number
2051 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
2052 {
2053 inst.error = _("invalid register mask");
2054 return FAIL;
2055 }
a737bd4d 2056
91d6fa6a 2057 if ((range & exp.X_add_number) != 0)
c19d1205 2058 {
91d6fa6a 2059 int regno = range & exp.X_add_number;
a737bd4d 2060
c19d1205
ZW
2061 regno &= -regno;
2062 regno = (1 << regno) - 1;
2063 as_tsktsk
2064 (_("Warning: duplicated register (r%d) in register list"),
2065 regno);
2066 }
a737bd4d 2067
91d6fa6a 2068 range |= exp.X_add_number;
c19d1205
ZW
2069 }
2070 else
2071 {
e2b0ab59 2072 if (inst.relocs[0].type != 0)
c19d1205
ZW
2073 {
2074 inst.error = _("expression too complex");
2075 return FAIL;
2076 }
a737bd4d 2077
e2b0ab59
AV
2078 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2079 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2080 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
2081 }
2082 }
a737bd4d 2083
c19d1205
ZW
2084 if (*str == '|' || *str == '+')
2085 {
2086 str++;
2087 another_range = 1;
2088 }
a737bd4d 2089 }
c19d1205 2090 while (another_range);
a737bd4d 2091
c19d1205
ZW
2092 *strp = str;
2093 return range;
a737bd4d
NC
2094}
2095
c19d1205
ZW
2096/* Parse a VFP register list. If the string is invalid return FAIL.
2097 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
2098 register. Parses registers of type ETYPE.
2099 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2100 - Q registers can be used to specify pairs of D registers
2101 - { } can be omitted from around a singleton register list
477330fc
RM
2102 FIXME: This is not implemented, as it would require backtracking in
2103 some cases, e.g.:
2104 vtbl.8 d3,d4,d5
2105 This could be done (the meaning isn't really ambiguous), but doesn't
2106 fit in well with the current parsing framework.
dcbf9037
JB
2107 - 32 D registers may be used (also true for VFPv3).
2108 FIXME: Types are ignored in these register lists, which is probably a
2109 bug. */
6057a28f 2110
c19d1205 2111static int
efd6b359
AV
2112parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2113 bfd_boolean *partial_match)
6057a28f 2114{
037e8744 2115 char *str = *ccp;
c19d1205
ZW
2116 int base_reg;
2117 int new_base;
21d799b5 2118 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2119 int max_regs = 0;
c19d1205
ZW
2120 int count = 0;
2121 int warned = 0;
2122 unsigned long mask = 0;
a737bd4d 2123 int i;
efd6b359
AV
2124 bfd_boolean vpr_seen = FALSE;
2125 bfd_boolean expect_vpr =
2126 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2127
477330fc 2128 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2129 {
2130 inst.error = _("expecting {");
2131 return FAIL;
2132 }
6057a28f 2133
5287ad62 2134 switch (etype)
c19d1205 2135 {
5287ad62 2136 case REGLIST_VFP_S:
efd6b359 2137 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2138 regtype = REG_TYPE_VFS;
2139 max_regs = 32;
5287ad62 2140 break;
5f4273c7 2141
5287ad62 2142 case REGLIST_VFP_D:
efd6b359 2143 case REGLIST_VFP_D_VPR:
5287ad62 2144 regtype = REG_TYPE_VFD;
b7fc2769 2145 break;
5f4273c7 2146
b7fc2769
JB
2147 case REGLIST_NEON_D:
2148 regtype = REG_TYPE_NDQ;
2149 break;
4b5a202f
AV
2150
2151 default:
2152 gas_assert (0);
b7fc2769
JB
2153 }
2154
efd6b359 2155 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2156 {
b1cc4aeb
PB
2157 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2158 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2159 {
2160 max_regs = 32;
2161 if (thumb_mode)
2162 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2163 fpu_vfp_ext_d32);
2164 else
2165 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2166 fpu_vfp_ext_d32);
2167 }
5287ad62 2168 else
477330fc 2169 max_regs = 16;
c19d1205 2170 }
6057a28f 2171
c19d1205 2172 base_reg = max_regs;
efd6b359 2173 *partial_match = FALSE;
a737bd4d 2174
c19d1205
ZW
2175 do
2176 {
5287ad62 2177 int setmask = 1, addregs = 1;
efd6b359
AV
2178 const char vpr_str[] = "vpr";
2179 int vpr_str_len = strlen (vpr_str);
dcbf9037 2180
037e8744 2181 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2182
efd6b359
AV
2183 if (expect_vpr)
2184 {
2185 if (new_base == FAIL
2186 && !strncasecmp (str, vpr_str, vpr_str_len)
2187 && !ISALPHA (*(str + vpr_str_len))
2188 && !vpr_seen)
2189 {
2190 vpr_seen = TRUE;
2191 str += vpr_str_len;
2192 if (count == 0)
2193 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2194 }
2195 else if (vpr_seen)
2196 {
2197 first_error (_("VPR expected last"));
2198 return FAIL;
2199 }
2200 else if (new_base == FAIL)
2201 {
2202 if (regtype == REG_TYPE_VFS)
2203 first_error (_("VFP single precision register or VPR "
2204 "expected"));
2205 else /* regtype == REG_TYPE_VFD. */
2206 first_error (_("VFP/Neon double precision register or VPR "
2207 "expected"));
2208 return FAIL;
2209 }
2210 }
2211 else if (new_base == FAIL)
a737bd4d 2212 {
dcbf9037 2213 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2214 return FAIL;
2215 }
5f4273c7 2216
efd6b359
AV
2217 *partial_match = TRUE;
2218 if (vpr_seen)
2219 continue;
2220
b7fc2769 2221 if (new_base >= max_regs)
477330fc
RM
2222 {
2223 first_error (_("register out of range in list"));
2224 return FAIL;
2225 }
5f4273c7 2226
5287ad62
JB
2227 /* Note: a value of 2 * n is returned for the register Q<n>. */
2228 if (regtype == REG_TYPE_NQ)
477330fc
RM
2229 {
2230 setmask = 3;
2231 addregs = 2;
2232 }
5287ad62 2233
c19d1205
ZW
2234 if (new_base < base_reg)
2235 base_reg = new_base;
a737bd4d 2236
5287ad62 2237 if (mask & (setmask << new_base))
c19d1205 2238 {
dcbf9037 2239 first_error (_("invalid register list"));
c19d1205 2240 return FAIL;
a737bd4d 2241 }
a737bd4d 2242
efd6b359 2243 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2244 {
2245 as_tsktsk (_("register list not in ascending order"));
2246 warned = 1;
2247 }
0bbf2aa4 2248
5287ad62
JB
2249 mask |= setmask << new_base;
2250 count += addregs;
0bbf2aa4 2251
037e8744 2252 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2253 {
2254 int high_range;
0bbf2aa4 2255
037e8744 2256 str++;
0bbf2aa4 2257
037e8744 2258 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2259 == FAIL)
c19d1205
ZW
2260 {
2261 inst.error = gettext (reg_expected_msgs[regtype]);
2262 return FAIL;
2263 }
0bbf2aa4 2264
477330fc
RM
2265 if (high_range >= max_regs)
2266 {
2267 first_error (_("register out of range in list"));
2268 return FAIL;
2269 }
b7fc2769 2270
477330fc
RM
2271 if (regtype == REG_TYPE_NQ)
2272 high_range = high_range + 1;
5287ad62 2273
c19d1205
ZW
2274 if (high_range <= new_base)
2275 {
2276 inst.error = _("register range not in ascending order");
2277 return FAIL;
2278 }
0bbf2aa4 2279
5287ad62 2280 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2281 {
5287ad62 2282 if (mask & (setmask << new_base))
0bbf2aa4 2283 {
c19d1205
ZW
2284 inst.error = _("invalid register list");
2285 return FAIL;
0bbf2aa4 2286 }
c19d1205 2287
5287ad62
JB
2288 mask |= setmask << new_base;
2289 count += addregs;
0bbf2aa4 2290 }
0bbf2aa4 2291 }
0bbf2aa4 2292 }
037e8744 2293 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2294
037e8744 2295 str++;
0bbf2aa4 2296
c19d1205 2297 /* Sanity check -- should have raised a parse error above. */
efd6b359 2298 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2299 abort ();
2300
2301 *pbase = base_reg;
2302
efd6b359
AV
2303 if (expect_vpr && !vpr_seen)
2304 {
2305 first_error (_("VPR expected last"));
2306 return FAIL;
2307 }
2308
c19d1205
ZW
2309 /* Final test -- the registers must be consecutive. */
2310 mask >>= base_reg;
2311 for (i = 0; i < count; i++)
2312 {
2313 if ((mask & (1u << i)) == 0)
2314 {
2315 inst.error = _("non-contiguous register range");
2316 return FAIL;
2317 }
2318 }
2319
037e8744
JB
2320 *ccp = str;
2321
c19d1205 2322 return count;
b99bd4ef
NC
2323}
2324
dcbf9037
JB
2325/* True if two alias types are the same. */
2326
c921be7d 2327static bfd_boolean
dcbf9037
JB
2328neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2329{
2330 if (!a && !b)
c921be7d 2331 return TRUE;
5f4273c7 2332
dcbf9037 2333 if (!a || !b)
c921be7d 2334 return FALSE;
dcbf9037
JB
2335
2336 if (a->defined != b->defined)
c921be7d 2337 return FALSE;
5f4273c7 2338
dcbf9037
JB
2339 if ((a->defined & NTA_HASTYPE) != 0
2340 && (a->eltype.type != b->eltype.type
477330fc 2341 || a->eltype.size != b->eltype.size))
c921be7d 2342 return FALSE;
dcbf9037
JB
2343
2344 if ((a->defined & NTA_HASINDEX) != 0
2345 && (a->index != b->index))
c921be7d 2346 return FALSE;
5f4273c7 2347
c921be7d 2348 return TRUE;
dcbf9037
JB
2349}
2350
5287ad62
JB
2351/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2352 The base register is put in *PBASE.
dcbf9037 2353 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2354 the return value.
2355 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2356 Bits [6:5] encode the list length (minus one).
2357 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2358
5287ad62 2359#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2360#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2361#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2362
2363static int
dcbf9037 2364parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2365 int mve,
477330fc 2366 struct neon_type_el *eltype)
5287ad62
JB
2367{
2368 char *ptr = *str;
2369 int base_reg = -1;
2370 int reg_incr = -1;
2371 int count = 0;
2372 int lane = -1;
2373 int leading_brace = 0;
2374 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2375 const char *const incr_error = mve ? _("register stride must be 1") :
2376 _("register stride must be 1 or 2");
20203fb9 2377 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2378 struct neon_typed_alias firsttype;
f85d59c3
KT
2379 firsttype.defined = 0;
2380 firsttype.eltype.type = NT_invtype;
2381 firsttype.eltype.size = -1;
2382 firsttype.index = -1;
5f4273c7 2383
5287ad62
JB
2384 if (skip_past_char (&ptr, '{') == SUCCESS)
2385 leading_brace = 1;
5f4273c7 2386
5287ad62
JB
2387 do
2388 {
dcbf9037 2389 struct neon_typed_alias atype;
35c228db
AV
2390 if (mve)
2391 rtype = REG_TYPE_MQ;
dcbf9037
JB
2392 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2393
5287ad62 2394 if (getreg == FAIL)
477330fc
RM
2395 {
2396 first_error (_(reg_expected_msgs[rtype]));
2397 return FAIL;
2398 }
5f4273c7 2399
5287ad62 2400 if (base_reg == -1)
477330fc
RM
2401 {
2402 base_reg = getreg;
2403 if (rtype == REG_TYPE_NQ)
2404 {
2405 reg_incr = 1;
2406 }
2407 firsttype = atype;
2408 }
5287ad62 2409 else if (reg_incr == -1)
477330fc
RM
2410 {
2411 reg_incr = getreg - base_reg;
2412 if (reg_incr < 1 || reg_incr > 2)
2413 {
2414 first_error (_(incr_error));
2415 return FAIL;
2416 }
2417 }
5287ad62 2418 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2419 {
2420 first_error (_(incr_error));
2421 return FAIL;
2422 }
dcbf9037 2423
c921be7d 2424 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2425 {
2426 first_error (_(type_error));
2427 return FAIL;
2428 }
5f4273c7 2429
5287ad62 2430 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2431 modes. */
5287ad62 2432 if (ptr[0] == '-')
477330fc
RM
2433 {
2434 struct neon_typed_alias htype;
2435 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2436 if (lane == -1)
2437 lane = NEON_INTERLEAVE_LANES;
2438 else if (lane != NEON_INTERLEAVE_LANES)
2439 {
2440 first_error (_(type_error));
2441 return FAIL;
2442 }
2443 if (reg_incr == -1)
2444 reg_incr = 1;
2445 else if (reg_incr != 1)
2446 {
2447 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2448 return FAIL;
2449 }
2450 ptr++;
2451 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2452 if (hireg == FAIL)
2453 {
2454 first_error (_(reg_expected_msgs[rtype]));
2455 return FAIL;
2456 }
2457 if (! neon_alias_types_same (&htype, &firsttype))
2458 {
2459 first_error (_(type_error));
2460 return FAIL;
2461 }
2462 count += hireg + dregs - getreg;
2463 continue;
2464 }
5f4273c7 2465
5287ad62
JB
2466 /* If we're using Q registers, we can't use [] or [n] syntax. */
2467 if (rtype == REG_TYPE_NQ)
477330fc
RM
2468 {
2469 count += 2;
2470 continue;
2471 }
5f4273c7 2472
dcbf9037 2473 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2474 {
2475 if (lane == -1)
2476 lane = atype.index;
2477 else if (lane != atype.index)
2478 {
2479 first_error (_(type_error));
2480 return FAIL;
2481 }
2482 }
5287ad62 2483 else if (lane == -1)
477330fc 2484 lane = NEON_INTERLEAVE_LANES;
5287ad62 2485 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2486 {
2487 first_error (_(type_error));
2488 return FAIL;
2489 }
5287ad62
JB
2490 count++;
2491 }
2492 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2493
5287ad62
JB
2494 /* No lane set by [x]. We must be interleaving structures. */
2495 if (lane == -1)
2496 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2497
5287ad62 2498 /* Sanity check. */
35c228db 2499 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2500 || (count > 1 && reg_incr == -1))
2501 {
dcbf9037 2502 first_error (_("error parsing element/structure list"));
5287ad62
JB
2503 return FAIL;
2504 }
2505
2506 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2507 {
dcbf9037 2508 first_error (_("expected }"));
5287ad62
JB
2509 return FAIL;
2510 }
5f4273c7 2511
5287ad62
JB
2512 if (reg_incr == -1)
2513 reg_incr = 1;
2514
dcbf9037
JB
2515 if (eltype)
2516 *eltype = firsttype.eltype;
2517
5287ad62
JB
2518 *pbase = base_reg;
2519 *str = ptr;
5f4273c7 2520
5287ad62
JB
2521 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2522}
2523
c19d1205
ZW
2524/* Parse an explicit relocation suffix on an expression. This is
2525 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2526 arm_reloc_hsh contains no entries, so this function can only
2527 succeed if there is no () after the word. Returns -1 on error,
2528 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2529
c19d1205
ZW
2530static int
2531parse_reloc (char **str)
b99bd4ef 2532{
c19d1205
ZW
2533 struct reloc_entry *r;
2534 char *p, *q;
b99bd4ef 2535
c19d1205
ZW
2536 if (**str != '(')
2537 return BFD_RELOC_UNUSED;
b99bd4ef 2538
c19d1205
ZW
2539 p = *str + 1;
2540 q = p;
2541
2542 while (*q && *q != ')' && *q != ',')
2543 q++;
2544 if (*q != ')')
2545 return -1;
2546
21d799b5
NC
2547 if ((r = (struct reloc_entry *)
2548 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2549 return -1;
2550
2551 *str = q + 1;
2552 return r->reloc;
b99bd4ef
NC
2553}
2554
c19d1205
ZW
2555/* Directives: register aliases. */
2556
dcbf9037 2557static struct reg_entry *
90ec0d68 2558insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2559{
d3ce72d0 2560 struct reg_entry *new_reg;
c19d1205 2561 const char *name;
b99bd4ef 2562
d3ce72d0 2563 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2564 {
d3ce72d0 2565 if (new_reg->builtin)
c19d1205 2566 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2567
c19d1205
ZW
2568 /* Only warn about a redefinition if it's not defined as the
2569 same register. */
d3ce72d0 2570 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2571 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2572
d929913e 2573 return NULL;
c19d1205 2574 }
b99bd4ef 2575
c19d1205 2576 name = xstrdup (str);
325801bd 2577 new_reg = XNEW (struct reg_entry);
b99bd4ef 2578
d3ce72d0
NC
2579 new_reg->name = name;
2580 new_reg->number = number;
2581 new_reg->type = type;
2582 new_reg->builtin = FALSE;
2583 new_reg->neon = NULL;
b99bd4ef 2584
d3ce72d0 2585 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2586 abort ();
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
21d799b5 2634 old = (struct reg_entry *) 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 {
21d799b5 2886 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2887 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
db0bc284 2899 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2900 free ((char *) reg->name);
477330fc
RM
2901 if (reg->neon)
2902 free (reg->neon);
c19d1205 2903 free (reg);
d929913e
NC
2904
2905 /* Also locate the all upper case and all lower case versions.
2906 Do not complain if we cannot find one or the other as it
2907 was probably deleted above. */
5f4273c7 2908
d929913e
NC
2909 nbuf = strdup (name);
2910 for (p = nbuf; *p; p++)
2911 *p = TOUPPER (*p);
21d799b5 2912 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2913 if (reg)
2914 {
db0bc284 2915 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2916 free ((char *) reg->name);
2917 if (reg->neon)
2918 free (reg->neon);
2919 free (reg);
2920 }
2921
2922 for (p = nbuf; *p; p++)
2923 *p = TOLOWER (*p);
21d799b5 2924 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2925 if (reg)
2926 {
db0bc284 2927 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2928 free ((char *) reg->name);
2929 if (reg->neon)
2930 free (reg->neon);
2931 free (reg);
2932 }
2933
2934 free (nbuf);
c19d1205
ZW
2935 }
2936 }
b99bd4ef 2937
c19d1205 2938 *input_line_pointer = saved_char;
b99bd4ef
NC
2939 demand_empty_rest_of_line ();
2940}
2941
c19d1205
ZW
2942/* Directives: Instruction set selection. */
2943
2944#ifdef OBJ_ELF
2945/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2946 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2947 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2948 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2949
cd000bff
DJ
2950/* Create a new mapping symbol for the transition to STATE. */
2951
2952static void
2953make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2954{
a737bd4d 2955 symbolS * symbolP;
c19d1205
ZW
2956 const char * symname;
2957 int type;
b99bd4ef 2958
c19d1205 2959 switch (state)
b99bd4ef 2960 {
c19d1205
ZW
2961 case MAP_DATA:
2962 symname = "$d";
2963 type = BSF_NO_FLAGS;
2964 break;
2965 case MAP_ARM:
2966 symname = "$a";
2967 type = BSF_NO_FLAGS;
2968 break;
2969 case MAP_THUMB:
2970 symname = "$t";
2971 type = BSF_NO_FLAGS;
2972 break;
c19d1205
ZW
2973 default:
2974 abort ();
2975 }
2976
cd000bff 2977 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2978 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2979
2980 switch (state)
2981 {
2982 case MAP_ARM:
2983 THUMB_SET_FUNC (symbolP, 0);
2984 ARM_SET_THUMB (symbolP, 0);
2985 ARM_SET_INTERWORK (symbolP, support_interwork);
2986 break;
2987
2988 case MAP_THUMB:
2989 THUMB_SET_FUNC (symbolP, 1);
2990 ARM_SET_THUMB (symbolP, 1);
2991 ARM_SET_INTERWORK (symbolP, support_interwork);
2992 break;
2993
2994 case MAP_DATA:
2995 default:
cd000bff
DJ
2996 break;
2997 }
2998
2999 /* Save the mapping symbols for future reference. Also check that
3000 we do not place two mapping symbols at the same offset within a
3001 frag. We'll handle overlap between frags in
2de7820f
JZ
3002 check_mapping_symbols.
3003
3004 If .fill or other data filling directive generates zero sized data,
3005 the mapping symbol for the following code will have the same value
3006 as the one generated for the data filling directive. In this case,
3007 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
3008 if (value == 0)
3009 {
2de7820f
JZ
3010 if (frag->tc_frag_data.first_map != NULL)
3011 {
3012 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3013 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3014 }
cd000bff
DJ
3015 frag->tc_frag_data.first_map = symbolP;
3016 }
3017 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
3018 {
3019 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
3020 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3021 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3022 }
cd000bff
DJ
3023 frag->tc_frag_data.last_map = symbolP;
3024}
3025
3026/* We must sometimes convert a region marked as code to data during
3027 code alignment, if an odd number of bytes have to be padded. The
3028 code mapping symbol is pushed to an aligned address. */
3029
3030static void
3031insert_data_mapping_symbol (enum mstate state,
3032 valueT value, fragS *frag, offsetT bytes)
3033{
3034 /* If there was already a mapping symbol, remove it. */
3035 if (frag->tc_frag_data.last_map != NULL
3036 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3037 {
3038 symbolS *symp = frag->tc_frag_data.last_map;
3039
3040 if (value == 0)
3041 {
3042 know (frag->tc_frag_data.first_map == symp);
3043 frag->tc_frag_data.first_map = NULL;
3044 }
3045 frag->tc_frag_data.last_map = NULL;
3046 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 3047 }
cd000bff
DJ
3048
3049 make_mapping_symbol (MAP_DATA, value, frag);
3050 make_mapping_symbol (state, value + bytes, frag);
3051}
3052
3053static void mapping_state_2 (enum mstate state, int max_chars);
3054
3055/* Set the mapping state to STATE. Only call this when about to
3056 emit some STATE bytes to the file. */
3057
4e9aaefb 3058#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
3059void
3060mapping_state (enum mstate state)
3061{
940b5ce0
DJ
3062 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3063
cd000bff
DJ
3064 if (mapstate == state)
3065 /* The mapping symbol has already been emitted.
3066 There is nothing else to do. */
3067 return;
49c62a33
NC
3068
3069 if (state == MAP_ARM || state == MAP_THUMB)
3070 /* PR gas/12931
3071 All ARM instructions require 4-byte alignment.
3072 (Almost) all Thumb instructions require 2-byte alignment.
3073
3074 When emitting instructions into any section, mark the section
3075 appropriately.
3076
3077 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3078 but themselves require 2-byte alignment; this applies to some
33eaf5de 3079 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
3080 literal pool generation or an explicit .align >=2, both of
3081 which will cause the section to me marked with sufficient
3082 alignment. Thus, we don't handle those cases here. */
3083 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3084
3085 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 3086 /* This case will be evaluated later. */
cd000bff 3087 return;
cd000bff
DJ
3088
3089 mapping_state_2 (state, 0);
cd000bff
DJ
3090}
3091
3092/* Same as mapping_state, but MAX_CHARS bytes have already been
3093 allocated. Put the mapping symbol that far back. */
3094
3095static void
3096mapping_state_2 (enum mstate state, int max_chars)
3097{
940b5ce0
DJ
3098 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3099
3100 if (!SEG_NORMAL (now_seg))
3101 return;
3102
cd000bff
DJ
3103 if (mapstate == state)
3104 /* The mapping symbol has already been emitted.
3105 There is nothing else to do. */
3106 return;
3107
4e9aaefb
SA
3108 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3109 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3110 {
3111 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3112 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3113
3114 if (add_symbol)
3115 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3116 }
3117
cd000bff
DJ
3118 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3119 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3120}
4e9aaefb 3121#undef TRANSITION
c19d1205 3122#else
d3106081
NS
3123#define mapping_state(x) ((void)0)
3124#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3125#endif
3126
3127/* Find the real, Thumb encoded start of a Thumb function. */
3128
4343666d 3129#ifdef OBJ_COFF
c19d1205
ZW
3130static symbolS *
3131find_real_start (symbolS * symbolP)
3132{
3133 char * real_start;
3134 const char * name = S_GET_NAME (symbolP);
3135 symbolS * new_target;
3136
3137 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3138#define STUB_NAME ".real_start_of"
3139
3140 if (name == NULL)
3141 abort ();
3142
37f6032b
ZW
3143 /* The compiler may generate BL instructions to local labels because
3144 it needs to perform a branch to a far away location. These labels
3145 do not have a corresponding ".real_start_of" label. We check
3146 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3147 the ".real_start_of" convention for nonlocal branches. */
3148 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3149 return symbolP;
3150
e1fa0163 3151 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3152 new_target = symbol_find (real_start);
e1fa0163 3153 free (real_start);
c19d1205
ZW
3154
3155 if (new_target == NULL)
3156 {
bd3ba5d1 3157 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3158 new_target = symbolP;
3159 }
3160
c19d1205
ZW
3161 return new_target;
3162}
4343666d 3163#endif
c19d1205
ZW
3164
3165static void
3166opcode_select (int width)
3167{
3168 switch (width)
3169 {
3170 case 16:
3171 if (! thumb_mode)
3172 {
e74cfd16 3173 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3174 as_bad (_("selected processor does not support THUMB opcodes"));
3175
3176 thumb_mode = 1;
3177 /* No need to force the alignment, since we will have been
3178 coming from ARM mode, which is word-aligned. */
3179 record_alignment (now_seg, 1);
3180 }
c19d1205
ZW
3181 break;
3182
3183 case 32:
3184 if (thumb_mode)
3185 {
e74cfd16 3186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3187 as_bad (_("selected processor does not support ARM opcodes"));
3188
3189 thumb_mode = 0;
3190
3191 if (!need_pass_2)
3192 frag_align (2, 0, 0);
3193
3194 record_alignment (now_seg, 1);
3195 }
c19d1205
ZW
3196 break;
3197
3198 default:
3199 as_bad (_("invalid instruction size selected (%d)"), width);
3200 }
3201}
3202
3203static void
3204s_arm (int ignore ATTRIBUTE_UNUSED)
3205{
3206 opcode_select (32);
3207 demand_empty_rest_of_line ();
3208}
3209
3210static void
3211s_thumb (int ignore ATTRIBUTE_UNUSED)
3212{
3213 opcode_select (16);
3214 demand_empty_rest_of_line ();
3215}
3216
3217static void
3218s_code (int unused ATTRIBUTE_UNUSED)
3219{
3220 int temp;
3221
3222 temp = get_absolute_expression ();
3223 switch (temp)
3224 {
3225 case 16:
3226 case 32:
3227 opcode_select (temp);
3228 break;
3229
3230 default:
3231 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3232 }
3233}
3234
3235static void
3236s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3237{
3238 /* If we are not already in thumb mode go into it, EVEN if
3239 the target processor does not support thumb instructions.
3240 This is used by gcc/config/arm/lib1funcs.asm for example
3241 to compile interworking support functions even if the
3242 target processor should not support interworking. */
3243 if (! thumb_mode)
3244 {
3245 thumb_mode = 2;
3246 record_alignment (now_seg, 1);
3247 }
3248
3249 demand_empty_rest_of_line ();
3250}
3251
3252static void
3253s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3254{
3255 s_thumb (0);
3256
3257 /* The following label is the name/address of the start of a Thumb function.
3258 We need to know this for the interworking support. */
3259 label_is_thumb_function_name = TRUE;
3260}
3261
3262/* Perform a .set directive, but also mark the alias as
3263 being a thumb function. */
3264
3265static void
3266s_thumb_set (int equiv)
3267{
3268 /* XXX the following is a duplicate of the code for s_set() in read.c
3269 We cannot just call that code as we need to get at the symbol that
3270 is created. */
3271 char * name;
3272 char delim;
3273 char * end_name;
3274 symbolS * symbolP;
3275
3276 /* Especial apologies for the random logic:
3277 This just grew, and could be parsed much more simply!
3278 Dean - in haste. */
d02603dc 3279 delim = get_symbol_name (& name);
c19d1205 3280 end_name = input_line_pointer;
d02603dc 3281 (void) restore_line_pointer (delim);
c19d1205
ZW
3282
3283 if (*input_line_pointer != ',')
3284 {
3285 *end_name = 0;
3286 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3287 *end_name = delim;
3288 ignore_rest_of_line ();
3289 return;
3290 }
3291
3292 input_line_pointer++;
3293 *end_name = 0;
3294
3295 if (name[0] == '.' && name[1] == '\0')
3296 {
3297 /* XXX - this should not happen to .thumb_set. */
3298 abort ();
3299 }
3300
3301 if ((symbolP = symbol_find (name)) == NULL
3302 && (symbolP = md_undefined_symbol (name)) == NULL)
3303 {
3304#ifndef NO_LISTING
3305 /* When doing symbol listings, play games with dummy fragments living
3306 outside the normal fragment chain to record the file and line info
c19d1205 3307 for this symbol. */
b99bd4ef
NC
3308 if (listing & LISTING_SYMBOLS)
3309 {
3310 extern struct list_info_struct * listing_tail;
21d799b5 3311 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3312
3313 memset (dummy_frag, 0, sizeof (fragS));
3314 dummy_frag->fr_type = rs_fill;
3315 dummy_frag->line = listing_tail;
3316 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3317 dummy_frag->fr_symbol = symbolP;
3318 }
3319 else
3320#endif
3321 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3322
3323#ifdef OBJ_COFF
3324 /* "set" symbols are local unless otherwise specified. */
3325 SF_SET_LOCAL (symbolP);
3326#endif /* OBJ_COFF */
3327 } /* Make a new symbol. */
3328
3329 symbol_table_insert (symbolP);
3330
3331 * end_name = delim;
3332
3333 if (equiv
3334 && S_IS_DEFINED (symbolP)
3335 && S_GET_SEGMENT (symbolP) != reg_section)
3336 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3337
3338 pseudo_set (symbolP);
3339
3340 demand_empty_rest_of_line ();
3341
c19d1205 3342 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3343
3344 THUMB_SET_FUNC (symbolP, 1);
3345 ARM_SET_THUMB (symbolP, 1);
3346#if defined OBJ_ELF || defined OBJ_COFF
3347 ARM_SET_INTERWORK (symbolP, support_interwork);
3348#endif
3349}
3350
c19d1205 3351/* Directives: Mode selection. */
b99bd4ef 3352
c19d1205
ZW
3353/* .syntax [unified|divided] - choose the new unified syntax
3354 (same for Arm and Thumb encoding, modulo slight differences in what
3355 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3356static void
c19d1205 3357s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3358{
c19d1205
ZW
3359 char *name, delim;
3360
d02603dc 3361 delim = get_symbol_name (& name);
c19d1205
ZW
3362
3363 if (!strcasecmp (name, "unified"))
3364 unified_syntax = TRUE;
3365 else if (!strcasecmp (name, "divided"))
3366 unified_syntax = FALSE;
3367 else
3368 {
3369 as_bad (_("unrecognized syntax mode \"%s\""), name);
3370 return;
3371 }
d02603dc 3372 (void) restore_line_pointer (delim);
b99bd4ef
NC
3373 demand_empty_rest_of_line ();
3374}
3375
c19d1205
ZW
3376/* Directives: sectioning and alignment. */
3377
c19d1205
ZW
3378static void
3379s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3380{
c19d1205
ZW
3381 /* We don't support putting frags in the BSS segment, we fake it by
3382 marking in_bss, then looking at s_skip for clues. */
3383 subseg_set (bss_section, 0);
3384 demand_empty_rest_of_line ();
cd000bff
DJ
3385
3386#ifdef md_elf_section_change_hook
3387 md_elf_section_change_hook ();
3388#endif
c19d1205 3389}
b99bd4ef 3390
c19d1205
ZW
3391static void
3392s_even (int ignore ATTRIBUTE_UNUSED)
3393{
3394 /* Never make frag if expect extra pass. */
3395 if (!need_pass_2)
3396 frag_align (1, 0, 0);
b99bd4ef 3397
c19d1205 3398 record_alignment (now_seg, 1);
b99bd4ef 3399
c19d1205 3400 demand_empty_rest_of_line ();
b99bd4ef
NC
3401}
3402
2e6976a8
DG
3403/* Directives: CodeComposer Studio. */
3404
3405/* .ref (for CodeComposer Studio syntax only). */
3406static void
3407s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3408{
3409 if (codecomposer_syntax)
3410 ignore_rest_of_line ();
3411 else
3412 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3413}
3414
3415/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3416 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3417static void
3418asmfunc_debug (const char * name)
3419{
3420 static const char * last_name = NULL;
3421
3422 if (name != NULL)
3423 {
3424 gas_assert (last_name == NULL);
3425 last_name = name;
3426
3427 if (debug_type == DEBUG_STABS)
3428 stabs_generate_asm_func (name, name);
3429 }
3430 else
3431 {
3432 gas_assert (last_name != NULL);
3433
3434 if (debug_type == DEBUG_STABS)
3435 stabs_generate_asm_endfunc (last_name, last_name);
3436
3437 last_name = NULL;
3438 }
3439}
3440
3441static void
3442s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3443{
3444 if (codecomposer_syntax)
3445 {
3446 switch (asmfunc_state)
3447 {
3448 case OUTSIDE_ASMFUNC:
3449 asmfunc_state = WAITING_ASMFUNC_NAME;
3450 break;
3451
3452 case WAITING_ASMFUNC_NAME:
3453 as_bad (_(".asmfunc repeated."));
3454 break;
3455
3456 case WAITING_ENDASMFUNC:
3457 as_bad (_(".asmfunc without function."));
3458 break;
3459 }
3460 demand_empty_rest_of_line ();
3461 }
3462 else
3463 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3464}
3465
3466static void
3467s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3468{
3469 if (codecomposer_syntax)
3470 {
3471 switch (asmfunc_state)
3472 {
3473 case OUTSIDE_ASMFUNC:
3474 as_bad (_(".endasmfunc without a .asmfunc."));
3475 break;
3476
3477 case WAITING_ASMFUNC_NAME:
3478 as_bad (_(".endasmfunc without function."));
3479 break;
3480
3481 case WAITING_ENDASMFUNC:
3482 asmfunc_state = OUTSIDE_ASMFUNC;
3483 asmfunc_debug (NULL);
3484 break;
3485 }
3486 demand_empty_rest_of_line ();
3487 }
3488 else
3489 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3490}
3491
3492static void
3493s_ccs_def (int name)
3494{
3495 if (codecomposer_syntax)
3496 s_globl (name);
3497 else
3498 as_bad (_(".def pseudo-op only available with -mccs flag."));
3499}
3500
c19d1205 3501/* Directives: Literal pools. */
a737bd4d 3502
c19d1205
ZW
3503static literal_pool *
3504find_literal_pool (void)
a737bd4d 3505{
c19d1205 3506 literal_pool * pool;
a737bd4d 3507
c19d1205 3508 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3509 {
c19d1205
ZW
3510 if (pool->section == now_seg
3511 && pool->sub_section == now_subseg)
3512 break;
a737bd4d
NC
3513 }
3514
c19d1205 3515 return pool;
a737bd4d
NC
3516}
3517
c19d1205
ZW
3518static literal_pool *
3519find_or_make_literal_pool (void)
a737bd4d 3520{
c19d1205
ZW
3521 /* Next literal pool ID number. */
3522 static unsigned int latest_pool_num = 1;
3523 literal_pool * pool;
a737bd4d 3524
c19d1205 3525 pool = find_literal_pool ();
a737bd4d 3526
c19d1205 3527 if (pool == NULL)
a737bd4d 3528 {
c19d1205 3529 /* Create a new pool. */
325801bd 3530 pool = XNEW (literal_pool);
c19d1205
ZW
3531 if (! pool)
3532 return NULL;
a737bd4d 3533
c19d1205
ZW
3534 pool->next_free_entry = 0;
3535 pool->section = now_seg;
3536 pool->sub_section = now_subseg;
3537 pool->next = list_of_pools;
3538 pool->symbol = NULL;
8335d6aa 3539 pool->alignment = 2;
c19d1205
ZW
3540
3541 /* Add it to the list. */
3542 list_of_pools = pool;
a737bd4d 3543 }
a737bd4d 3544
c19d1205
ZW
3545 /* New pools, and emptied pools, will have a NULL symbol. */
3546 if (pool->symbol == NULL)
a737bd4d 3547 {
c19d1205
ZW
3548 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3549 (valueT) 0, &zero_address_frag);
3550 pool->id = latest_pool_num ++;
a737bd4d
NC
3551 }
3552
c19d1205
ZW
3553 /* Done. */
3554 return pool;
a737bd4d
NC
3555}
3556
c19d1205 3557/* Add the literal in the global 'inst'
5f4273c7 3558 structure to the relevant literal pool. */
b99bd4ef
NC
3559
3560static int
8335d6aa 3561add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3562{
8335d6aa
JW
3563#define PADDING_SLOT 0x1
3564#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3565 literal_pool * pool;
8335d6aa
JW
3566 unsigned int entry, pool_size = 0;
3567 bfd_boolean padding_slot_p = FALSE;
e56c722b 3568 unsigned imm1 = 0;
8335d6aa
JW
3569 unsigned imm2 = 0;
3570
3571 if (nbytes == 8)
3572 {
3573 imm1 = inst.operands[1].imm;
3574 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3575 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3576 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3577 if (target_big_endian)
3578 {
3579 imm1 = imm2;
3580 imm2 = inst.operands[1].imm;
3581 }
3582 }
b99bd4ef 3583
c19d1205
ZW
3584 pool = find_or_make_literal_pool ();
3585
3586 /* Check if this literal value is already in the pool. */
3587 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3588 {
8335d6aa
JW
3589 if (nbytes == 4)
3590 {
e2b0ab59
AV
3591 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3592 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3593 && (pool->literals[entry].X_add_number
e2b0ab59 3594 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3595 && (pool->literals[entry].X_md == nbytes)
3596 && (pool->literals[entry].X_unsigned
e2b0ab59 3597 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3598 break;
3599
e2b0ab59
AV
3600 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3601 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3602 && (pool->literals[entry].X_add_number
e2b0ab59 3603 == inst.relocs[0].exp.X_add_number)
8335d6aa 3604 && (pool->literals[entry].X_add_symbol
e2b0ab59 3605 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3606 && (pool->literals[entry].X_op_symbol
e2b0ab59 3607 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3608 && (pool->literals[entry].X_md == nbytes))
3609 break;
3610 }
3611 else if ((nbytes == 8)
3612 && !(pool_size & 0x7)
3613 && ((entry + 1) != pool->next_free_entry)
3614 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3615 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3616 && (pool->literals[entry].X_unsigned
e2b0ab59 3617 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3618 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3619 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3620 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3621 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3622 break;
3623
8335d6aa
JW
3624 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3625 if (padding_slot_p && (nbytes == 4))
c19d1205 3626 break;
8335d6aa
JW
3627
3628 pool_size += 4;
b99bd4ef
NC
3629 }
3630
c19d1205
ZW
3631 /* Do we need to create a new entry? */
3632 if (entry == pool->next_free_entry)
3633 {
3634 if (entry >= MAX_LITERAL_POOL_SIZE)
3635 {
3636 inst.error = _("literal pool overflow");
3637 return FAIL;
3638 }
3639
8335d6aa
JW
3640 if (nbytes == 8)
3641 {
3642 /* For 8-byte entries, we align to an 8-byte boundary,
3643 and split it into two 4-byte entries, because on 32-bit
3644 host, 8-byte constants are treated as big num, thus
3645 saved in "generic_bignum" which will be overwritten
3646 by later assignments.
3647
3648 We also need to make sure there is enough space for
3649 the split.
3650
3651 We also check to make sure the literal operand is a
3652 constant number. */
e2b0ab59
AV
3653 if (!(inst.relocs[0].exp.X_op == O_constant
3654 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3655 {
3656 inst.error = _("invalid type for literal pool");
3657 return FAIL;
3658 }
3659 else if (pool_size & 0x7)
3660 {
3661 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3662 {
3663 inst.error = _("literal pool overflow");
3664 return FAIL;
3665 }
3666
e2b0ab59 3667 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3668 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3669 pool->literals[entry].X_add_number = 0;
3670 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3671 pool->next_free_entry += 1;
3672 pool_size += 4;
3673 }
3674 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3675 {
3676 inst.error = _("literal pool overflow");
3677 return FAIL;
3678 }
3679
e2b0ab59 3680 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3681 pool->literals[entry].X_op = O_constant;
3682 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3683 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3684 pool->literals[entry++].X_md = 4;
e2b0ab59 3685 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3686 pool->literals[entry].X_op = O_constant;
3687 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3688 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3689 pool->literals[entry].X_md = 4;
3690 pool->alignment = 3;
3691 pool->next_free_entry += 1;
3692 }
3693 else
3694 {
e2b0ab59 3695 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3696 pool->literals[entry].X_md = 4;
3697 }
3698
a8040cf2
NC
3699#ifdef OBJ_ELF
3700 /* PR ld/12974: Record the location of the first source line to reference
3701 this entry in the literal pool. If it turns out during linking that the
3702 symbol does not exist we will be able to give an accurate line number for
3703 the (first use of the) missing reference. */
3704 if (debug_type == DEBUG_DWARF2)
3705 dwarf2_where (pool->locs + entry);
3706#endif
c19d1205
ZW
3707 pool->next_free_entry += 1;
3708 }
8335d6aa
JW
3709 else if (padding_slot_p)
3710 {
e2b0ab59 3711 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3712 pool->literals[entry].X_md = nbytes;
3713 }
b99bd4ef 3714
e2b0ab59
AV
3715 inst.relocs[0].exp.X_op = O_symbol;
3716 inst.relocs[0].exp.X_add_number = pool_size;
3717 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3718
c19d1205 3719 return SUCCESS;
b99bd4ef
NC
3720}
3721
2e6976a8 3722bfd_boolean
2e57ce7b 3723tc_start_label_without_colon (void)
2e6976a8
DG
3724{
3725 bfd_boolean ret = TRUE;
3726
3727 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3728 {
2e57ce7b 3729 const char *label = input_line_pointer;
2e6976a8
DG
3730
3731 while (!is_end_of_line[(int) label[-1]])
3732 --label;
3733
3734 if (*label == '.')
3735 {
3736 as_bad (_("Invalid label '%s'"), label);
3737 ret = FALSE;
3738 }
3739
3740 asmfunc_debug (label);
3741
3742 asmfunc_state = WAITING_ENDASMFUNC;
3743 }
3744
3745 return ret;
3746}
3747
c19d1205 3748/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3749 a later date assign it a value. That's what these functions do. */
e16bb312 3750
c19d1205
ZW
3751static void
3752symbol_locate (symbolS * symbolP,
3753 const char * name, /* It is copied, the caller can modify. */
3754 segT segment, /* Segment identifier (SEG_<something>). */
3755 valueT valu, /* Symbol value. */
3756 fragS * frag) /* Associated fragment. */
3757{
e57e6ddc 3758 size_t name_length;
c19d1205 3759 char * preserved_copy_of_name;
e16bb312 3760
c19d1205
ZW
3761 name_length = strlen (name) + 1; /* +1 for \0. */
3762 obstack_grow (&notes, name, name_length);
21d799b5 3763 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3764
c19d1205
ZW
3765#ifdef tc_canonicalize_symbol_name
3766 preserved_copy_of_name =
3767 tc_canonicalize_symbol_name (preserved_copy_of_name);
3768#endif
b99bd4ef 3769
c19d1205 3770 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3771
c19d1205
ZW
3772 S_SET_SEGMENT (symbolP, segment);
3773 S_SET_VALUE (symbolP, valu);
3774 symbol_clear_list_pointers (symbolP);
b99bd4ef 3775
c19d1205 3776 symbol_set_frag (symbolP, frag);
b99bd4ef 3777
c19d1205
ZW
3778 /* Link to end of symbol chain. */
3779 {
3780 extern int symbol_table_frozen;
b99bd4ef 3781
c19d1205
ZW
3782 if (symbol_table_frozen)
3783 abort ();
3784 }
b99bd4ef 3785
c19d1205 3786 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3787
c19d1205 3788 obj_symbol_new_hook (symbolP);
b99bd4ef 3789
c19d1205
ZW
3790#ifdef tc_symbol_new_hook
3791 tc_symbol_new_hook (symbolP);
3792#endif
3793
3794#ifdef DEBUG_SYMS
3795 verify_symbol_chain (symbol_rootP, symbol_lastP);
3796#endif /* DEBUG_SYMS */
b99bd4ef
NC
3797}
3798
c19d1205
ZW
3799static void
3800s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3801{
c19d1205
ZW
3802 unsigned int entry;
3803 literal_pool * pool;
3804 char sym_name[20];
b99bd4ef 3805
c19d1205
ZW
3806 pool = find_literal_pool ();
3807 if (pool == NULL
3808 || pool->symbol == NULL
3809 || pool->next_free_entry == 0)
3810 return;
b99bd4ef 3811
c19d1205
ZW
3812 /* Align pool as you have word accesses.
3813 Only make a frag if we have to. */
3814 if (!need_pass_2)
8335d6aa 3815 frag_align (pool->alignment, 0, 0);
b99bd4ef 3816
c19d1205 3817 record_alignment (now_seg, 2);
b99bd4ef 3818
aaca88ef 3819#ifdef OBJ_ELF
47fc6e36
WN
3820 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3821 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3822#endif
c19d1205 3823 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3824
c19d1205
ZW
3825 symbol_locate (pool->symbol, sym_name, now_seg,
3826 (valueT) frag_now_fix (), frag_now);
3827 symbol_table_insert (pool->symbol);
b99bd4ef 3828
c19d1205 3829 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3830
c19d1205
ZW
3831#if defined OBJ_COFF || defined OBJ_ELF
3832 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3833#endif
6c43fab6 3834
c19d1205 3835 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3836 {
3837#ifdef OBJ_ELF
3838 if (debug_type == DEBUG_DWARF2)
3839 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3840#endif
3841 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3842 emit_expr (&(pool->literals[entry]),
3843 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3844 }
b99bd4ef 3845
c19d1205
ZW
3846 /* Mark the pool as empty. */
3847 pool->next_free_entry = 0;
3848 pool->symbol = NULL;
b99bd4ef
NC
3849}
3850
c19d1205
ZW
3851#ifdef OBJ_ELF
3852/* Forward declarations for functions below, in the MD interface
3853 section. */
3854static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3855static valueT create_unwind_entry (int);
3856static void start_unwind_section (const segT, int);
3857static void add_unwind_opcode (valueT, int);
3858static void flush_pending_unwind (void);
b99bd4ef 3859
c19d1205 3860/* Directives: Data. */
b99bd4ef 3861
c19d1205
ZW
3862static void
3863s_arm_elf_cons (int nbytes)
3864{
3865 expressionS exp;
b99bd4ef 3866
c19d1205
ZW
3867#ifdef md_flush_pending_output
3868 md_flush_pending_output ();
3869#endif
b99bd4ef 3870
c19d1205 3871 if (is_it_end_of_statement ())
b99bd4ef 3872 {
c19d1205
ZW
3873 demand_empty_rest_of_line ();
3874 return;
b99bd4ef
NC
3875 }
3876
c19d1205
ZW
3877#ifdef md_cons_align
3878 md_cons_align (nbytes);
3879#endif
b99bd4ef 3880
c19d1205
ZW
3881 mapping_state (MAP_DATA);
3882 do
b99bd4ef 3883 {
c19d1205
ZW
3884 int reloc;
3885 char *base = input_line_pointer;
b99bd4ef 3886
c19d1205 3887 expression (& exp);
b99bd4ef 3888
c19d1205
ZW
3889 if (exp.X_op != O_symbol)
3890 emit_expr (&exp, (unsigned int) nbytes);
3891 else
3892 {
3893 char *before_reloc = input_line_pointer;
3894 reloc = parse_reloc (&input_line_pointer);
3895 if (reloc == -1)
3896 {
3897 as_bad (_("unrecognized relocation suffix"));
3898 ignore_rest_of_line ();
3899 return;
3900 }
3901 else if (reloc == BFD_RELOC_UNUSED)
3902 emit_expr (&exp, (unsigned int) nbytes);
3903 else
3904 {
21d799b5 3905 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3906 bfd_reloc_type_lookup (stdoutput,
3907 (bfd_reloc_code_real_type) reloc);
c19d1205 3908 int size = bfd_get_reloc_size (howto);
b99bd4ef 3909
2fc8bdac
ZW
3910 if (reloc == BFD_RELOC_ARM_PLT32)
3911 {
3912 as_bad (_("(plt) is only valid on branch targets"));
3913 reloc = BFD_RELOC_UNUSED;
3914 size = 0;
3915 }
3916
c19d1205 3917 if (size > nbytes)
992a06ee
AM
3918 as_bad (ngettext ("%s relocations do not fit in %d byte",
3919 "%s relocations do not fit in %d bytes",
3920 nbytes),
c19d1205
ZW
3921 howto->name, nbytes);
3922 else
3923 {
3924 /* We've parsed an expression stopping at O_symbol.
3925 But there may be more expression left now that we
3926 have parsed the relocation marker. Parse it again.
3927 XXX Surely there is a cleaner way to do this. */
3928 char *p = input_line_pointer;
3929 int offset;
325801bd 3930 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3931
c19d1205
ZW
3932 memcpy (save_buf, base, input_line_pointer - base);
3933 memmove (base + (input_line_pointer - before_reloc),
3934 base, before_reloc - base);
3935
3936 input_line_pointer = base + (input_line_pointer-before_reloc);
3937 expression (&exp);
3938 memcpy (base, save_buf, p - base);
3939
3940 offset = nbytes - size;
4b1a927e
AM
3941 p = frag_more (nbytes);
3942 memset (p, 0, nbytes);
c19d1205 3943 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3944 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3945 free (save_buf);
c19d1205
ZW
3946 }
3947 }
3948 }
b99bd4ef 3949 }
c19d1205 3950 while (*input_line_pointer++ == ',');
b99bd4ef 3951
c19d1205
ZW
3952 /* Put terminator back into stream. */
3953 input_line_pointer --;
3954 demand_empty_rest_of_line ();
b99bd4ef
NC
3955}
3956
c921be7d
NC
3957/* Emit an expression containing a 32-bit thumb instruction.
3958 Implementation based on put_thumb32_insn. */
3959
3960static void
3961emit_thumb32_expr (expressionS * exp)
3962{
3963 expressionS exp_high = *exp;
3964
3965 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3966 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3967 exp->X_add_number &= 0xffff;
3968 emit_expr (exp, (unsigned int) THUMB_SIZE);
3969}
3970
3971/* Guess the instruction size based on the opcode. */
3972
3973static int
3974thumb_insn_size (int opcode)
3975{
3976 if ((unsigned int) opcode < 0xe800u)
3977 return 2;
3978 else if ((unsigned int) opcode >= 0xe8000000u)
3979 return 4;
3980 else
3981 return 0;
3982}
3983
3984static bfd_boolean
3985emit_insn (expressionS *exp, int nbytes)
3986{
3987 int size = 0;
3988
3989 if (exp->X_op == O_constant)
3990 {
3991 size = nbytes;
3992
3993 if (size == 0)
3994 size = thumb_insn_size (exp->X_add_number);
3995
3996 if (size != 0)
3997 {
3998 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3999 {
4000 as_bad (_(".inst.n operand too big. "\
4001 "Use .inst.w instead"));
4002 size = 0;
4003 }
4004 else
4005 {
5ee91343
AV
4006 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4007 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 4008 else
5ee91343 4009 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
4010
4011 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4012 emit_thumb32_expr (exp);
4013 else
4014 emit_expr (exp, (unsigned int) size);
4015
4016 it_fsm_post_encode ();
4017 }
4018 }
4019 else
4020 as_bad (_("cannot determine Thumb instruction size. " \
4021 "Use .inst.n/.inst.w instead"));
4022 }
4023 else
4024 as_bad (_("constant expression required"));
4025
4026 return (size != 0);
4027}
4028
4029/* Like s_arm_elf_cons but do not use md_cons_align and
4030 set the mapping state to MAP_ARM/MAP_THUMB. */
4031
4032static void
4033s_arm_elf_inst (int nbytes)
4034{
4035 if (is_it_end_of_statement ())
4036 {
4037 demand_empty_rest_of_line ();
4038 return;
4039 }
4040
4041 /* Calling mapping_state () here will not change ARM/THUMB,
4042 but will ensure not to be in DATA state. */
4043
4044 if (thumb_mode)
4045 mapping_state (MAP_THUMB);
4046 else
4047 {
4048 if (nbytes != 0)
4049 {
4050 as_bad (_("width suffixes are invalid in ARM mode"));
4051 ignore_rest_of_line ();
4052 return;
4053 }
4054
4055 nbytes = 4;
4056
4057 mapping_state (MAP_ARM);
4058 }
4059
4060 do
4061 {
4062 expressionS exp;
4063
4064 expression (& exp);
4065
4066 if (! emit_insn (& exp, nbytes))
4067 {
4068 ignore_rest_of_line ();
4069 return;
4070 }
4071 }
4072 while (*input_line_pointer++ == ',');
4073
4074 /* Put terminator back into stream. */
4075 input_line_pointer --;
4076 demand_empty_rest_of_line ();
4077}
b99bd4ef 4078
c19d1205 4079/* Parse a .rel31 directive. */
b99bd4ef 4080
c19d1205
ZW
4081static void
4082s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4083{
4084 expressionS exp;
4085 char *p;
4086 valueT highbit;
b99bd4ef 4087
c19d1205
ZW
4088 highbit = 0;
4089 if (*input_line_pointer == '1')
4090 highbit = 0x80000000;
4091 else if (*input_line_pointer != '0')
4092 as_bad (_("expected 0 or 1"));
b99bd4ef 4093
c19d1205
ZW
4094 input_line_pointer++;
4095 if (*input_line_pointer != ',')
4096 as_bad (_("missing comma"));
4097 input_line_pointer++;
b99bd4ef 4098
c19d1205
ZW
4099#ifdef md_flush_pending_output
4100 md_flush_pending_output ();
4101#endif
b99bd4ef 4102
c19d1205
ZW
4103#ifdef md_cons_align
4104 md_cons_align (4);
4105#endif
b99bd4ef 4106
c19d1205 4107 mapping_state (MAP_DATA);
b99bd4ef 4108
c19d1205 4109 expression (&exp);
b99bd4ef 4110
c19d1205
ZW
4111 p = frag_more (4);
4112 md_number_to_chars (p, highbit, 4);
4113 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4114 BFD_RELOC_ARM_PREL31);
b99bd4ef 4115
c19d1205 4116 demand_empty_rest_of_line ();
b99bd4ef
NC
4117}
4118
c19d1205 4119/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4120
c19d1205 4121/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4122
c19d1205
ZW
4123static void
4124s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4125{
4126 demand_empty_rest_of_line ();
921e5f0a
PB
4127 if (unwind.proc_start)
4128 {
c921be7d 4129 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4130 return;
4131 }
4132
c19d1205
ZW
4133 /* Mark the start of the function. */
4134 unwind.proc_start = expr_build_dot ();
b99bd4ef 4135
c19d1205
ZW
4136 /* Reset the rest of the unwind info. */
4137 unwind.opcode_count = 0;
4138 unwind.table_entry = NULL;
4139 unwind.personality_routine = NULL;
4140 unwind.personality_index = -1;
4141 unwind.frame_size = 0;
4142 unwind.fp_offset = 0;
fdfde340 4143 unwind.fp_reg = REG_SP;
c19d1205
ZW
4144 unwind.fp_used = 0;
4145 unwind.sp_restored = 0;
4146}
b99bd4ef 4147
b99bd4ef 4148
c19d1205
ZW
4149/* Parse a handlerdata directive. Creates the exception handling table entry
4150 for the function. */
b99bd4ef 4151
c19d1205
ZW
4152static void
4153s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4154{
4155 demand_empty_rest_of_line ();
921e5f0a 4156 if (!unwind.proc_start)
c921be7d 4157 as_bad (MISSING_FNSTART);
921e5f0a 4158
c19d1205 4159 if (unwind.table_entry)
6decc662 4160 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4161
c19d1205
ZW
4162 create_unwind_entry (1);
4163}
a737bd4d 4164
c19d1205 4165/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4166
c19d1205
ZW
4167static void
4168s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4169{
4170 long where;
4171 char *ptr;
4172 valueT val;
940b5ce0 4173 unsigned int marked_pr_dependency;
f02232aa 4174
c19d1205 4175 demand_empty_rest_of_line ();
f02232aa 4176
921e5f0a
PB
4177 if (!unwind.proc_start)
4178 {
c921be7d 4179 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4180 return;
4181 }
4182
c19d1205
ZW
4183 /* Add eh table entry. */
4184 if (unwind.table_entry == NULL)
4185 val = create_unwind_entry (0);
4186 else
4187 val = 0;
f02232aa 4188
c19d1205
ZW
4189 /* Add index table entry. This is two words. */
4190 start_unwind_section (unwind.saved_seg, 1);
4191 frag_align (2, 0, 0);
4192 record_alignment (now_seg, 2);
b99bd4ef 4193
c19d1205 4194 ptr = frag_more (8);
5011093d 4195 memset (ptr, 0, 8);
c19d1205 4196 where = frag_now_fix () - 8;
f02232aa 4197
c19d1205
ZW
4198 /* Self relative offset of the function start. */
4199 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4200 BFD_RELOC_ARM_PREL31);
f02232aa 4201
c19d1205
ZW
4202 /* Indicate dependency on EHABI-defined personality routines to the
4203 linker, if it hasn't been done already. */
940b5ce0
DJ
4204 marked_pr_dependency
4205 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4206 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4207 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4208 {
5f4273c7
NC
4209 static const char *const name[] =
4210 {
4211 "__aeabi_unwind_cpp_pr0",
4212 "__aeabi_unwind_cpp_pr1",
4213 "__aeabi_unwind_cpp_pr2"
4214 };
c19d1205
ZW
4215 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4216 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4217 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4218 |= 1 << unwind.personality_index;
c19d1205 4219 }
f02232aa 4220
c19d1205
ZW
4221 if (val)
4222 /* Inline exception table entry. */
4223 md_number_to_chars (ptr + 4, val, 4);
4224 else
4225 /* Self relative offset of the table entry. */
4226 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4227 BFD_RELOC_ARM_PREL31);
f02232aa 4228
c19d1205
ZW
4229 /* Restore the original section. */
4230 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4231
4232 unwind.proc_start = NULL;
c19d1205 4233}
f02232aa 4234
f02232aa 4235
c19d1205 4236/* Parse an unwind_cantunwind directive. */
b99bd4ef 4237
c19d1205
ZW
4238static void
4239s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4240{
4241 demand_empty_rest_of_line ();
921e5f0a 4242 if (!unwind.proc_start)
c921be7d 4243 as_bad (MISSING_FNSTART);
921e5f0a 4244
c19d1205
ZW
4245 if (unwind.personality_routine || unwind.personality_index != -1)
4246 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4247
c19d1205
ZW
4248 unwind.personality_index = -2;
4249}
b99bd4ef 4250
b99bd4ef 4251
c19d1205 4252/* Parse a personalityindex directive. */
b99bd4ef 4253
c19d1205
ZW
4254static void
4255s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4256{
4257 expressionS exp;
b99bd4ef 4258
921e5f0a 4259 if (!unwind.proc_start)
c921be7d 4260 as_bad (MISSING_FNSTART);
921e5f0a 4261
c19d1205
ZW
4262 if (unwind.personality_routine || unwind.personality_index != -1)
4263 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4264
c19d1205 4265 expression (&exp);
b99bd4ef 4266
c19d1205
ZW
4267 if (exp.X_op != O_constant
4268 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4269 {
c19d1205
ZW
4270 as_bad (_("bad personality routine number"));
4271 ignore_rest_of_line ();
4272 return;
b99bd4ef
NC
4273 }
4274
c19d1205 4275 unwind.personality_index = exp.X_add_number;
b99bd4ef 4276
c19d1205
ZW
4277 demand_empty_rest_of_line ();
4278}
e16bb312 4279
e16bb312 4280
c19d1205 4281/* Parse a personality directive. */
e16bb312 4282
c19d1205
ZW
4283static void
4284s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4285{
4286 char *name, *p, c;
a737bd4d 4287
921e5f0a 4288 if (!unwind.proc_start)
c921be7d 4289 as_bad (MISSING_FNSTART);
921e5f0a 4290
c19d1205
ZW
4291 if (unwind.personality_routine || unwind.personality_index != -1)
4292 as_bad (_("duplicate .personality directive"));
a737bd4d 4293
d02603dc 4294 c = get_symbol_name (& name);
c19d1205 4295 p = input_line_pointer;
d02603dc
NC
4296 if (c == '"')
4297 ++ input_line_pointer;
c19d1205
ZW
4298 unwind.personality_routine = symbol_find_or_make (name);
4299 *p = c;
4300 demand_empty_rest_of_line ();
4301}
e16bb312 4302
e16bb312 4303
c19d1205 4304/* Parse a directive saving core registers. */
e16bb312 4305
c19d1205
ZW
4306static void
4307s_arm_unwind_save_core (void)
e16bb312 4308{
c19d1205
ZW
4309 valueT op;
4310 long range;
4311 int n;
e16bb312 4312
4b5a202f 4313 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4314 if (range == FAIL)
e16bb312 4315 {
c19d1205
ZW
4316 as_bad (_("expected register list"));
4317 ignore_rest_of_line ();
4318 return;
4319 }
e16bb312 4320
c19d1205 4321 demand_empty_rest_of_line ();
e16bb312 4322
c19d1205
ZW
4323 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4324 into .unwind_save {..., sp...}. We aren't bothered about the value of
4325 ip because it is clobbered by calls. */
4326 if (unwind.sp_restored && unwind.fp_reg == 12
4327 && (range & 0x3000) == 0x1000)
4328 {
4329 unwind.opcode_count--;
4330 unwind.sp_restored = 0;
4331 range = (range | 0x2000) & ~0x1000;
4332 unwind.pending_offset = 0;
4333 }
e16bb312 4334
01ae4198
DJ
4335 /* Pop r4-r15. */
4336 if (range & 0xfff0)
c19d1205 4337 {
01ae4198
DJ
4338 /* See if we can use the short opcodes. These pop a block of up to 8
4339 registers starting with r4, plus maybe r14. */
4340 for (n = 0; n < 8; n++)
4341 {
4342 /* Break at the first non-saved register. */
4343 if ((range & (1 << (n + 4))) == 0)
4344 break;
4345 }
4346 /* See if there are any other bits set. */
4347 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4348 {
4349 /* Use the long form. */
4350 op = 0x8000 | ((range >> 4) & 0xfff);
4351 add_unwind_opcode (op, 2);
4352 }
0dd132b6 4353 else
01ae4198
DJ
4354 {
4355 /* Use the short form. */
4356 if (range & 0x4000)
4357 op = 0xa8; /* Pop r14. */
4358 else
4359 op = 0xa0; /* Do not pop r14. */
4360 op |= (n - 1);
4361 add_unwind_opcode (op, 1);
4362 }
c19d1205 4363 }
0dd132b6 4364
c19d1205
ZW
4365 /* Pop r0-r3. */
4366 if (range & 0xf)
4367 {
4368 op = 0xb100 | (range & 0xf);
4369 add_unwind_opcode (op, 2);
0dd132b6
NC
4370 }
4371
c19d1205
ZW
4372 /* Record the number of bytes pushed. */
4373 for (n = 0; n < 16; n++)
4374 {
4375 if (range & (1 << n))
4376 unwind.frame_size += 4;
4377 }
0dd132b6
NC
4378}
4379
c19d1205
ZW
4380
4381/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4382
4383static void
c19d1205 4384s_arm_unwind_save_fpa (int reg)
b99bd4ef 4385{
c19d1205
ZW
4386 expressionS exp;
4387 int num_regs;
4388 valueT op;
b99bd4ef 4389
c19d1205
ZW
4390 /* Get Number of registers to transfer. */
4391 if (skip_past_comma (&input_line_pointer) != FAIL)
4392 expression (&exp);
4393 else
4394 exp.X_op = O_illegal;
b99bd4ef 4395
c19d1205 4396 if (exp.X_op != O_constant)
b99bd4ef 4397 {
c19d1205
ZW
4398 as_bad (_("expected , <constant>"));
4399 ignore_rest_of_line ();
b99bd4ef
NC
4400 return;
4401 }
4402
c19d1205
ZW
4403 num_regs = exp.X_add_number;
4404
4405 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4406 {
c19d1205
ZW
4407 as_bad (_("number of registers must be in the range [1:4]"));
4408 ignore_rest_of_line ();
b99bd4ef
NC
4409 return;
4410 }
4411
c19d1205 4412 demand_empty_rest_of_line ();
b99bd4ef 4413
c19d1205
ZW
4414 if (reg == 4)
4415 {
4416 /* Short form. */
4417 op = 0xb4 | (num_regs - 1);
4418 add_unwind_opcode (op, 1);
4419 }
b99bd4ef
NC
4420 else
4421 {
c19d1205
ZW
4422 /* Long form. */
4423 op = 0xc800 | (reg << 4) | (num_regs - 1);
4424 add_unwind_opcode (op, 2);
b99bd4ef 4425 }
c19d1205 4426 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4427}
4428
c19d1205 4429
fa073d69
MS
4430/* Parse a directive saving VFP registers for ARMv6 and above. */
4431
4432static void
4433s_arm_unwind_save_vfp_armv6 (void)
4434{
4435 int count;
4436 unsigned int start;
4437 valueT op;
4438 int num_vfpv3_regs = 0;
4439 int num_regs_below_16;
efd6b359 4440 bfd_boolean partial_match;
fa073d69 4441
efd6b359
AV
4442 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4443 &partial_match);
fa073d69
MS
4444 if (count == FAIL)
4445 {
4446 as_bad (_("expected register list"));
4447 ignore_rest_of_line ();
4448 return;
4449 }
4450
4451 demand_empty_rest_of_line ();
4452
4453 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4454 than FSTMX/FLDMX-style ones). */
4455
4456 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4457 if (start >= 16)
4458 num_vfpv3_regs = count;
4459 else if (start + count > 16)
4460 num_vfpv3_regs = start + count - 16;
4461
4462 if (num_vfpv3_regs > 0)
4463 {
4464 int start_offset = start > 16 ? start - 16 : 0;
4465 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4466 add_unwind_opcode (op, 2);
4467 }
4468
4469 /* Generate opcode for registers numbered in the range 0 .. 15. */
4470 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4471 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4472 if (num_regs_below_16 > 0)
4473 {
4474 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4475 add_unwind_opcode (op, 2);
4476 }
4477
4478 unwind.frame_size += count * 8;
4479}
4480
4481
4482/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4483
4484static void
c19d1205 4485s_arm_unwind_save_vfp (void)
b99bd4ef 4486{
c19d1205 4487 int count;
ca3f61f7 4488 unsigned int reg;
c19d1205 4489 valueT op;
efd6b359 4490 bfd_boolean partial_match;
b99bd4ef 4491
efd6b359
AV
4492 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4493 &partial_match);
c19d1205 4494 if (count == FAIL)
b99bd4ef 4495 {
c19d1205
ZW
4496 as_bad (_("expected register list"));
4497 ignore_rest_of_line ();
b99bd4ef
NC
4498 return;
4499 }
4500
c19d1205 4501 demand_empty_rest_of_line ();
b99bd4ef 4502
c19d1205 4503 if (reg == 8)
b99bd4ef 4504 {
c19d1205
ZW
4505 /* Short form. */
4506 op = 0xb8 | (count - 1);
4507 add_unwind_opcode (op, 1);
b99bd4ef 4508 }
c19d1205 4509 else
b99bd4ef 4510 {
c19d1205
ZW
4511 /* Long form. */
4512 op = 0xb300 | (reg << 4) | (count - 1);
4513 add_unwind_opcode (op, 2);
b99bd4ef 4514 }
c19d1205
ZW
4515 unwind.frame_size += count * 8 + 4;
4516}
b99bd4ef 4517
b99bd4ef 4518
c19d1205
ZW
4519/* Parse a directive saving iWMMXt data registers. */
4520
4521static void
4522s_arm_unwind_save_mmxwr (void)
4523{
4524 int reg;
4525 int hi_reg;
4526 int i;
4527 unsigned mask = 0;
4528 valueT op;
b99bd4ef 4529
c19d1205
ZW
4530 if (*input_line_pointer == '{')
4531 input_line_pointer++;
b99bd4ef 4532
c19d1205 4533 do
b99bd4ef 4534 {
dcbf9037 4535 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4536
c19d1205 4537 if (reg == FAIL)
b99bd4ef 4538 {
9b7132d3 4539 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4540 goto error;
b99bd4ef
NC
4541 }
4542
c19d1205
ZW
4543 if (mask >> reg)
4544 as_tsktsk (_("register list not in ascending order"));
4545 mask |= 1 << reg;
b99bd4ef 4546
c19d1205
ZW
4547 if (*input_line_pointer == '-')
4548 {
4549 input_line_pointer++;
dcbf9037 4550 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4551 if (hi_reg == FAIL)
4552 {
9b7132d3 4553 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4554 goto error;
4555 }
4556 else if (reg >= hi_reg)
4557 {
4558 as_bad (_("bad register range"));
4559 goto error;
4560 }
4561 for (; reg < hi_reg; reg++)
4562 mask |= 1 << reg;
4563 }
4564 }
4565 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4566
d996d970 4567 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4568
c19d1205 4569 demand_empty_rest_of_line ();
b99bd4ef 4570
708587a4 4571 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4572 the list. */
4573 flush_pending_unwind ();
b99bd4ef 4574
c19d1205 4575 for (i = 0; i < 16; i++)
b99bd4ef 4576 {
c19d1205
ZW
4577 if (mask & (1 << i))
4578 unwind.frame_size += 8;
b99bd4ef
NC
4579 }
4580
c19d1205
ZW
4581 /* Attempt to combine with a previous opcode. We do this because gcc
4582 likes to output separate unwind directives for a single block of
4583 registers. */
4584 if (unwind.opcode_count > 0)
b99bd4ef 4585 {
c19d1205
ZW
4586 i = unwind.opcodes[unwind.opcode_count - 1];
4587 if ((i & 0xf8) == 0xc0)
4588 {
4589 i &= 7;
4590 /* Only merge if the blocks are contiguous. */
4591 if (i < 6)
4592 {
4593 if ((mask & 0xfe00) == (1 << 9))
4594 {
4595 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4596 unwind.opcode_count--;
4597 }
4598 }
4599 else if (i == 6 && unwind.opcode_count >= 2)
4600 {
4601 i = unwind.opcodes[unwind.opcode_count - 2];
4602 reg = i >> 4;
4603 i &= 0xf;
b99bd4ef 4604
c19d1205
ZW
4605 op = 0xffff << (reg - 1);
4606 if (reg > 0
87a1fd79 4607 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4608 {
4609 op = (1 << (reg + i + 1)) - 1;
4610 op &= ~((1 << reg) - 1);
4611 mask |= op;
4612 unwind.opcode_count -= 2;
4613 }
4614 }
4615 }
b99bd4ef
NC
4616 }
4617
c19d1205
ZW
4618 hi_reg = 15;
4619 /* We want to generate opcodes in the order the registers have been
4620 saved, ie. descending order. */
4621 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4622 {
c19d1205
ZW
4623 /* Save registers in blocks. */
4624 if (reg < 0
4625 || !(mask & (1 << reg)))
4626 {
4627 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4628 preceding block. */
c19d1205
ZW
4629 if (reg != hi_reg)
4630 {
4631 if (reg == 9)
4632 {
4633 /* Short form. */
4634 op = 0xc0 | (hi_reg - 10);
4635 add_unwind_opcode (op, 1);
4636 }
4637 else
4638 {
4639 /* Long form. */
4640 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4641 add_unwind_opcode (op, 2);
4642 }
4643 }
4644 hi_reg = reg - 1;
4645 }
b99bd4ef
NC
4646 }
4647
c19d1205 4648 return;
dc1e8a47 4649 error:
c19d1205 4650 ignore_rest_of_line ();
b99bd4ef
NC
4651}
4652
4653static void
c19d1205 4654s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4655{
c19d1205
ZW
4656 int reg;
4657 int hi_reg;
4658 unsigned mask = 0;
4659 valueT op;
b99bd4ef 4660
c19d1205
ZW
4661 if (*input_line_pointer == '{')
4662 input_line_pointer++;
b99bd4ef 4663
477330fc
RM
4664 skip_whitespace (input_line_pointer);
4665
c19d1205 4666 do
b99bd4ef 4667 {
dcbf9037 4668 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4669
c19d1205
ZW
4670 if (reg == FAIL)
4671 {
9b7132d3 4672 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4673 goto error;
4674 }
b99bd4ef 4675
c19d1205
ZW
4676 reg -= 8;
4677 if (mask >> reg)
4678 as_tsktsk (_("register list not in ascending order"));
4679 mask |= 1 << reg;
b99bd4ef 4680
c19d1205
ZW
4681 if (*input_line_pointer == '-')
4682 {
4683 input_line_pointer++;
dcbf9037 4684 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4685 if (hi_reg == FAIL)
4686 {
9b7132d3 4687 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4688 goto error;
4689 }
4690 else if (reg >= hi_reg)
4691 {
4692 as_bad (_("bad register range"));
4693 goto error;
4694 }
4695 for (; reg < hi_reg; reg++)
4696 mask |= 1 << reg;
4697 }
b99bd4ef 4698 }
c19d1205 4699 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4700
d996d970 4701 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4702
c19d1205
ZW
4703 demand_empty_rest_of_line ();
4704
708587a4 4705 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4706 the list. */
4707 flush_pending_unwind ();
b99bd4ef 4708
c19d1205 4709 for (reg = 0; reg < 16; reg++)
b99bd4ef 4710 {
c19d1205
ZW
4711 if (mask & (1 << reg))
4712 unwind.frame_size += 4;
b99bd4ef 4713 }
c19d1205
ZW
4714 op = 0xc700 | mask;
4715 add_unwind_opcode (op, 2);
4716 return;
dc1e8a47 4717 error:
c19d1205 4718 ignore_rest_of_line ();
b99bd4ef
NC
4719}
4720
c19d1205 4721
fa073d69
MS
4722/* Parse an unwind_save directive.
4723 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4724
b99bd4ef 4725static void
fa073d69 4726s_arm_unwind_save (int arch_v6)
b99bd4ef 4727{
c19d1205
ZW
4728 char *peek;
4729 struct reg_entry *reg;
4730 bfd_boolean had_brace = FALSE;
b99bd4ef 4731
921e5f0a 4732 if (!unwind.proc_start)
c921be7d 4733 as_bad (MISSING_FNSTART);
921e5f0a 4734
c19d1205
ZW
4735 /* Figure out what sort of save we have. */
4736 peek = input_line_pointer;
b99bd4ef 4737
c19d1205 4738 if (*peek == '{')
b99bd4ef 4739 {
c19d1205
ZW
4740 had_brace = TRUE;
4741 peek++;
b99bd4ef
NC
4742 }
4743
c19d1205 4744 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4745
c19d1205 4746 if (!reg)
b99bd4ef 4747 {
c19d1205
ZW
4748 as_bad (_("register expected"));
4749 ignore_rest_of_line ();
b99bd4ef
NC
4750 return;
4751 }
4752
c19d1205 4753 switch (reg->type)
b99bd4ef 4754 {
c19d1205
ZW
4755 case REG_TYPE_FN:
4756 if (had_brace)
4757 {
4758 as_bad (_("FPA .unwind_save does not take a register list"));
4759 ignore_rest_of_line ();
4760 return;
4761 }
93ac2687 4762 input_line_pointer = peek;
c19d1205 4763 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4764 return;
c19d1205 4765
1f5afe1c
NC
4766 case REG_TYPE_RN:
4767 s_arm_unwind_save_core ();
4768 return;
4769
fa073d69
MS
4770 case REG_TYPE_VFD:
4771 if (arch_v6)
477330fc 4772 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4773 else
477330fc 4774 s_arm_unwind_save_vfp ();
fa073d69 4775 return;
1f5afe1c
NC
4776
4777 case REG_TYPE_MMXWR:
4778 s_arm_unwind_save_mmxwr ();
4779 return;
4780
4781 case REG_TYPE_MMXWCG:
4782 s_arm_unwind_save_mmxwcg ();
4783 return;
c19d1205
ZW
4784
4785 default:
4786 as_bad (_(".unwind_save does not support this kind of register"));
4787 ignore_rest_of_line ();
b99bd4ef 4788 }
c19d1205 4789}
b99bd4ef 4790
b99bd4ef 4791
c19d1205
ZW
4792/* Parse an unwind_movsp directive. */
4793
4794static void
4795s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4796{
4797 int reg;
4798 valueT op;
4fa3602b 4799 int offset;
c19d1205 4800
921e5f0a 4801 if (!unwind.proc_start)
c921be7d 4802 as_bad (MISSING_FNSTART);
921e5f0a 4803
dcbf9037 4804 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4805 if (reg == FAIL)
b99bd4ef 4806 {
9b7132d3 4807 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4808 ignore_rest_of_line ();
b99bd4ef
NC
4809 return;
4810 }
4fa3602b
PB
4811
4812 /* Optional constant. */
4813 if (skip_past_comma (&input_line_pointer) != FAIL)
4814 {
4815 if (immediate_for_directive (&offset) == FAIL)
4816 return;
4817 }
4818 else
4819 offset = 0;
4820
c19d1205 4821 demand_empty_rest_of_line ();
b99bd4ef 4822
c19d1205 4823 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4824 {
c19d1205 4825 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4826 return;
4827 }
4828
c19d1205
ZW
4829 if (unwind.fp_reg != REG_SP)
4830 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4831
c19d1205
ZW
4832 /* Generate opcode to restore the value. */
4833 op = 0x90 | reg;
4834 add_unwind_opcode (op, 1);
4835
4836 /* Record the information for later. */
4837 unwind.fp_reg = reg;
4fa3602b 4838 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4839 unwind.sp_restored = 1;
b05fe5cf
ZW
4840}
4841
c19d1205
ZW
4842/* Parse an unwind_pad directive. */
4843
b05fe5cf 4844static void
c19d1205 4845s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4846{
c19d1205 4847 int offset;
b05fe5cf 4848
921e5f0a 4849 if (!unwind.proc_start)
c921be7d 4850 as_bad (MISSING_FNSTART);
921e5f0a 4851
c19d1205
ZW
4852 if (immediate_for_directive (&offset) == FAIL)
4853 return;
b99bd4ef 4854
c19d1205
ZW
4855 if (offset & 3)
4856 {
4857 as_bad (_("stack increment must be multiple of 4"));
4858 ignore_rest_of_line ();
4859 return;
4860 }
b99bd4ef 4861
c19d1205
ZW
4862 /* Don't generate any opcodes, just record the details for later. */
4863 unwind.frame_size += offset;
4864 unwind.pending_offset += offset;
4865
4866 demand_empty_rest_of_line ();
4867}
4868
4869/* Parse an unwind_setfp directive. */
4870
4871static void
4872s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4873{
c19d1205
ZW
4874 int sp_reg;
4875 int fp_reg;
4876 int offset;
4877
921e5f0a 4878 if (!unwind.proc_start)
c921be7d 4879 as_bad (MISSING_FNSTART);
921e5f0a 4880
dcbf9037 4881 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4882 if (skip_past_comma (&input_line_pointer) == FAIL)
4883 sp_reg = FAIL;
4884 else
dcbf9037 4885 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4886
c19d1205
ZW
4887 if (fp_reg == FAIL || sp_reg == FAIL)
4888 {
4889 as_bad (_("expected <reg>, <reg>"));
4890 ignore_rest_of_line ();
4891 return;
4892 }
b99bd4ef 4893
c19d1205
ZW
4894 /* Optional constant. */
4895 if (skip_past_comma (&input_line_pointer) != FAIL)
4896 {
4897 if (immediate_for_directive (&offset) == FAIL)
4898 return;
4899 }
4900 else
4901 offset = 0;
a737bd4d 4902
c19d1205 4903 demand_empty_rest_of_line ();
a737bd4d 4904
fdfde340 4905 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4906 {
c19d1205
ZW
4907 as_bad (_("register must be either sp or set by a previous"
4908 "unwind_movsp directive"));
4909 return;
a737bd4d
NC
4910 }
4911
c19d1205
ZW
4912 /* Don't generate any opcodes, just record the information for later. */
4913 unwind.fp_reg = fp_reg;
4914 unwind.fp_used = 1;
fdfde340 4915 if (sp_reg == REG_SP)
c19d1205
ZW
4916 unwind.fp_offset = unwind.frame_size - offset;
4917 else
4918 unwind.fp_offset -= offset;
a737bd4d
NC
4919}
4920
c19d1205
ZW
4921/* Parse an unwind_raw directive. */
4922
4923static void
4924s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4925{
c19d1205 4926 expressionS exp;
708587a4 4927 /* This is an arbitrary limit. */
c19d1205
ZW
4928 unsigned char op[16];
4929 int count;
a737bd4d 4930
921e5f0a 4931 if (!unwind.proc_start)
c921be7d 4932 as_bad (MISSING_FNSTART);
921e5f0a 4933
c19d1205
ZW
4934 expression (&exp);
4935 if (exp.X_op == O_constant
4936 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4937 {
c19d1205
ZW
4938 unwind.frame_size += exp.X_add_number;
4939 expression (&exp);
4940 }
4941 else
4942 exp.X_op = O_illegal;
a737bd4d 4943
c19d1205
ZW
4944 if (exp.X_op != O_constant)
4945 {
4946 as_bad (_("expected <offset>, <opcode>"));
4947 ignore_rest_of_line ();
4948 return;
4949 }
a737bd4d 4950
c19d1205 4951 count = 0;
a737bd4d 4952
c19d1205
ZW
4953 /* Parse the opcode. */
4954 for (;;)
4955 {
4956 if (count >= 16)
4957 {
4958 as_bad (_("unwind opcode too long"));
4959 ignore_rest_of_line ();
a737bd4d 4960 }
c19d1205 4961 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4962 {
c19d1205
ZW
4963 as_bad (_("invalid unwind opcode"));
4964 ignore_rest_of_line ();
4965 return;
a737bd4d 4966 }
c19d1205 4967 op[count++] = exp.X_add_number;
a737bd4d 4968
c19d1205
ZW
4969 /* Parse the next byte. */
4970 if (skip_past_comma (&input_line_pointer) == FAIL)
4971 break;
a737bd4d 4972
c19d1205
ZW
4973 expression (&exp);
4974 }
b99bd4ef 4975
c19d1205
ZW
4976 /* Add the opcode bytes in reverse order. */
4977 while (count--)
4978 add_unwind_opcode (op[count], 1);
b99bd4ef 4979
c19d1205 4980 demand_empty_rest_of_line ();
b99bd4ef 4981}
ee065d83
PB
4982
4983
4984/* Parse a .eabi_attribute directive. */
4985
4986static void
4987s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4988{
0420f52b 4989 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4990
3076e594 4991 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4992 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4993}
4994
0855e32b
NS
4995/* Emit a tls fix for the symbol. */
4996
4997static void
4998s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4999{
5000 char *p;
5001 expressionS exp;
5002#ifdef md_flush_pending_output
5003 md_flush_pending_output ();
5004#endif
5005
5006#ifdef md_cons_align
5007 md_cons_align (4);
5008#endif
5009
5010 /* Since we're just labelling the code, there's no need to define a
5011 mapping symbol. */
5012 expression (&exp);
5013 p = obstack_next_free (&frchain_now->frch_obstack);
5014 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5015 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5016 : BFD_RELOC_ARM_TLS_DESCSEQ);
5017}
cdf9ccec 5018#endif /* OBJ_ELF */
0855e32b 5019
ee065d83 5020static void s_arm_arch (int);
7a1d4c38 5021static void s_arm_object_arch (int);
ee065d83
PB
5022static void s_arm_cpu (int);
5023static void s_arm_fpu (int);
69133863 5024static void s_arm_arch_extension (int);
b99bd4ef 5025
f0927246
NC
5026#ifdef TE_PE
5027
5028static void
5f4273c7 5029pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
5030{
5031 expressionS exp;
5032
5033 do
5034 {
5035 expression (&exp);
5036 if (exp.X_op == O_symbol)
5037 exp.X_op = O_secrel;
5038
5039 emit_expr (&exp, 4);
5040 }
5041 while (*input_line_pointer++ == ',');
5042
5043 input_line_pointer--;
5044 demand_empty_rest_of_line ();
5045}
5046#endif /* TE_PE */
5047
5312fe52
BW
5048int
5049arm_is_largest_exponent_ok (int precision)
5050{
5051 /* precision == 1 ensures that this will only return
5052 true for 16 bit floats. */
5053 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5054}
5055
5056static void
5057set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5058{
5059 char saved_char;
5060 char* name;
5061 enum fp_16bit_format new_format;
5062
5063 new_format = ARM_FP16_FORMAT_DEFAULT;
5064
5065 name = input_line_pointer;
5066 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5067 input_line_pointer++;
5068
5069 saved_char = *input_line_pointer;
5070 *input_line_pointer = 0;
5071
5072 if (strcasecmp (name, "ieee") == 0)
5073 new_format = ARM_FP16_FORMAT_IEEE;
5074 else if (strcasecmp (name, "alternative") == 0)
5075 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5076 else
5077 {
5078 as_bad (_("unrecognised float16 format \"%s\""), name);
5079 goto cleanup;
5080 }
5081
5082 /* Only set fp16_format if it is still the default (aka not already
5083 been set yet). */
5084 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5085 fp16_format = new_format;
5086 else
5087 {
5088 if (new_format != fp16_format)
5089 as_warn (_("float16 format cannot be set more than once, ignoring."));
5090 }
5091
dc1e8a47 5092 cleanup:
5312fe52
BW
5093 *input_line_pointer = saved_char;
5094 ignore_rest_of_line ();
5095}
5096
c19d1205
ZW
5097/* This table describes all the machine specific pseudo-ops the assembler
5098 has to support. The fields are:
5099 pseudo-op name without dot
5100 function to call to execute this pseudo-op
5101 Integer arg to pass to the function. */
b99bd4ef 5102
c19d1205 5103const pseudo_typeS md_pseudo_table[] =
b99bd4ef 5104{
c19d1205
ZW
5105 /* Never called because '.req' does not start a line. */
5106 { "req", s_req, 0 },
dcbf9037
JB
5107 /* Following two are likewise never called. */
5108 { "dn", s_dn, 0 },
5109 { "qn", s_qn, 0 },
c19d1205
ZW
5110 { "unreq", s_unreq, 0 },
5111 { "bss", s_bss, 0 },
db2ed2e0 5112 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5113 { "arm", s_arm, 0 },
5114 { "thumb", s_thumb, 0 },
5115 { "code", s_code, 0 },
5116 { "force_thumb", s_force_thumb, 0 },
5117 { "thumb_func", s_thumb_func, 0 },
5118 { "thumb_set", s_thumb_set, 0 },
5119 { "even", s_even, 0 },
5120 { "ltorg", s_ltorg, 0 },
5121 { "pool", s_ltorg, 0 },
5122 { "syntax", s_syntax, 0 },
8463be01
PB
5123 { "cpu", s_arm_cpu, 0 },
5124 { "arch", s_arm_arch, 0 },
7a1d4c38 5125 { "object_arch", s_arm_object_arch, 0 },
8463be01 5126 { "fpu", s_arm_fpu, 0 },
69133863 5127 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5128#ifdef OBJ_ELF
c921be7d
NC
5129 { "word", s_arm_elf_cons, 4 },
5130 { "long", s_arm_elf_cons, 4 },
5131 { "inst.n", s_arm_elf_inst, 2 },
5132 { "inst.w", s_arm_elf_inst, 4 },
5133 { "inst", s_arm_elf_inst, 0 },
5134 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5135 { "fnstart", s_arm_unwind_fnstart, 0 },
5136 { "fnend", s_arm_unwind_fnend, 0 },
5137 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5138 { "personality", s_arm_unwind_personality, 0 },
5139 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5140 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5141 { "save", s_arm_unwind_save, 0 },
fa073d69 5142 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5143 { "movsp", s_arm_unwind_movsp, 0 },
5144 { "pad", s_arm_unwind_pad, 0 },
5145 { "setfp", s_arm_unwind_setfp, 0 },
5146 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5147 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5148 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5149#else
5150 { "word", cons, 4},
f0927246
NC
5151
5152 /* These are used for dwarf. */
5153 {"2byte", cons, 2},
5154 {"4byte", cons, 4},
5155 {"8byte", cons, 8},
5156 /* These are used for dwarf2. */
68d20676 5157 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5158 { "loc", dwarf2_directive_loc, 0 },
5159 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5160#endif
5161 { "extend", float_cons, 'x' },
5162 { "ldouble", float_cons, 'x' },
5163 { "packed", float_cons, 'p' },
27cce866 5164 { "bfloat16", float_cons, 'b' },
f0927246
NC
5165#ifdef TE_PE
5166 {"secrel32", pe_directive_secrel, 0},
5167#endif
2e6976a8
DG
5168
5169 /* These are for compatibility with CodeComposer Studio. */
5170 {"ref", s_ccs_ref, 0},
5171 {"def", s_ccs_def, 0},
5172 {"asmfunc", s_ccs_asmfunc, 0},
5173 {"endasmfunc", s_ccs_endasmfunc, 0},
5174
5312fe52
BW
5175 {"float16", float_cons, 'h' },
5176 {"float16_format", set_fp16_format, 0 },
5177
c19d1205
ZW
5178 { 0, 0, 0 }
5179};
5312fe52 5180
c19d1205 5181/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5182
c19d1205
ZW
5183/* Generic immediate-value read function for use in insn parsing.
5184 STR points to the beginning of the immediate (the leading #);
5185 VAL receives the value; if the value is outside [MIN, MAX]
5186 issue an error. PREFIX_OPT is true if the immediate prefix is
5187 optional. */
b99bd4ef 5188
c19d1205
ZW
5189static int
5190parse_immediate (char **str, int *val, int min, int max,
5191 bfd_boolean prefix_opt)
5192{
5193 expressionS exp;
0198d5e6 5194
c19d1205
ZW
5195 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5196 if (exp.X_op != O_constant)
b99bd4ef 5197 {
c19d1205
ZW
5198 inst.error = _("constant expression required");
5199 return FAIL;
5200 }
b99bd4ef 5201
c19d1205
ZW
5202 if (exp.X_add_number < min || exp.X_add_number > max)
5203 {
5204 inst.error = _("immediate value out of range");
5205 return FAIL;
5206 }
b99bd4ef 5207
c19d1205
ZW
5208 *val = exp.X_add_number;
5209 return SUCCESS;
5210}
b99bd4ef 5211
5287ad62 5212/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5213 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5214 instructions. Puts the result directly in inst.operands[i]. */
5215
5216static int
8335d6aa
JW
5217parse_big_immediate (char **str, int i, expressionS *in_exp,
5218 bfd_boolean allow_symbol_p)
5287ad62
JB
5219{
5220 expressionS exp;
8335d6aa 5221 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5222 char *ptr = *str;
5223
8335d6aa 5224 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5225
8335d6aa 5226 if (exp_p->X_op == O_constant)
036dc3f7 5227 {
8335d6aa 5228 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5229 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5230 O_constant. We have to be careful not to break compilation for
5231 32-bit X_add_number, though. */
8335d6aa 5232 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5233 {
8335d6aa
JW
5234 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5235 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5236 & 0xffffffff);
036dc3f7
PB
5237 inst.operands[i].regisimm = 1;
5238 }
5239 }
8335d6aa
JW
5240 else if (exp_p->X_op == O_big
5241 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5242 {
5243 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5244
5287ad62 5245 /* Bignums have their least significant bits in
477330fc
RM
5246 generic_bignum[0]. Make sure we put 32 bits in imm and
5247 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5248 gas_assert (parts != 0);
95b75c01
NC
5249
5250 /* Make sure that the number is not too big.
5251 PR 11972: Bignums can now be sign-extended to the
5252 size of a .octa so check that the out of range bits
5253 are all zero or all one. */
8335d6aa 5254 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5255 {
5256 LITTLENUM_TYPE m = -1;
5257
5258 if (generic_bignum[parts * 2] != 0
5259 && generic_bignum[parts * 2] != m)
5260 return FAIL;
5261
8335d6aa 5262 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5263 if (generic_bignum[j] != generic_bignum[j-1])
5264 return FAIL;
5265 }
5266
5287ad62
JB
5267 inst.operands[i].imm = 0;
5268 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5269 inst.operands[i].imm |= generic_bignum[idx]
5270 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5271 inst.operands[i].reg = 0;
5272 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5273 inst.operands[i].reg |= generic_bignum[idx]
5274 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5275 inst.operands[i].regisimm = 1;
5276 }
8335d6aa 5277 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5278 return FAIL;
5f4273c7 5279
5287ad62
JB
5280 *str = ptr;
5281
5282 return SUCCESS;
5283}
5284
c19d1205
ZW
5285/* Returns the pseudo-register number of an FPA immediate constant,
5286 or FAIL if there isn't a valid constant here. */
b99bd4ef 5287
c19d1205
ZW
5288static int
5289parse_fpa_immediate (char ** str)
5290{
5291 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5292 char * save_in;
5293 expressionS exp;
5294 int i;
5295 int j;
b99bd4ef 5296
c19d1205
ZW
5297 /* First try and match exact strings, this is to guarantee
5298 that some formats will work even for cross assembly. */
b99bd4ef 5299
c19d1205
ZW
5300 for (i = 0; fp_const[i]; i++)
5301 {
5302 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5303 {
c19d1205 5304 char *start = *str;
b99bd4ef 5305
c19d1205
ZW
5306 *str += strlen (fp_const[i]);
5307 if (is_end_of_line[(unsigned char) **str])
5308 return i + 8;
5309 *str = start;
5310 }
5311 }
b99bd4ef 5312
c19d1205
ZW
5313 /* Just because we didn't get a match doesn't mean that the constant
5314 isn't valid, just that it is in a format that we don't
5315 automatically recognize. Try parsing it with the standard
5316 expression routines. */
b99bd4ef 5317
c19d1205 5318 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5319
c19d1205
ZW
5320 /* Look for a raw floating point number. */
5321 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5322 && is_end_of_line[(unsigned char) *save_in])
5323 {
5324 for (i = 0; i < NUM_FLOAT_VALS; i++)
5325 {
5326 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5327 {
c19d1205
ZW
5328 if (words[j] != fp_values[i][j])
5329 break;
b99bd4ef
NC
5330 }
5331
c19d1205 5332 if (j == MAX_LITTLENUMS)
b99bd4ef 5333 {
c19d1205
ZW
5334 *str = save_in;
5335 return i + 8;
b99bd4ef
NC
5336 }
5337 }
5338 }
b99bd4ef 5339
c19d1205
ZW
5340 /* Try and parse a more complex expression, this will probably fail
5341 unless the code uses a floating point prefix (eg "0f"). */
5342 save_in = input_line_pointer;
5343 input_line_pointer = *str;
5344 if (expression (&exp) == absolute_section
5345 && exp.X_op == O_big
5346 && exp.X_add_number < 0)
5347 {
5348 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5349 Ditto for 15. */
ba592044
AM
5350#define X_PRECISION 5
5351#define E_PRECISION 15L
5352 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5353 {
5354 for (i = 0; i < NUM_FLOAT_VALS; i++)
5355 {
5356 for (j = 0; j < MAX_LITTLENUMS; j++)
5357 {
5358 if (words[j] != fp_values[i][j])
5359 break;
5360 }
b99bd4ef 5361
c19d1205
ZW
5362 if (j == MAX_LITTLENUMS)
5363 {
5364 *str = input_line_pointer;
5365 input_line_pointer = save_in;
5366 return i + 8;
5367 }
5368 }
5369 }
b99bd4ef
NC
5370 }
5371
c19d1205
ZW
5372 *str = input_line_pointer;
5373 input_line_pointer = save_in;
5374 inst.error = _("invalid FPA immediate expression");
5375 return FAIL;
b99bd4ef
NC
5376}
5377
136da414
JB
5378/* Returns 1 if a number has "quarter-precision" float format
5379 0baBbbbbbc defgh000 00000000 00000000. */
5380
5381static int
5382is_quarter_float (unsigned imm)
5383{
5384 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5385 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5386}
5387
aacf0b33
KT
5388
5389/* Detect the presence of a floating point or integer zero constant,
5390 i.e. #0.0 or #0. */
5391
5392static bfd_boolean
5393parse_ifimm_zero (char **in)
5394{
5395 int error_code;
5396
5397 if (!is_immediate_prefix (**in))
3c6452ae
TP
5398 {
5399 /* In unified syntax, all prefixes are optional. */
5400 if (!unified_syntax)
5401 return FALSE;
5402 }
5403 else
5404 ++*in;
0900a05b
JW
5405
5406 /* Accept #0x0 as a synonym for #0. */
5407 if (strncmp (*in, "0x", 2) == 0)
5408 {
5409 int val;
5410 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5411 return FALSE;
5412 return TRUE;
5413 }
5414
aacf0b33
KT
5415 error_code = atof_generic (in, ".", EXP_CHARS,
5416 &generic_floating_point_number);
5417
5418 if (!error_code
5419 && generic_floating_point_number.sign == '+'
5420 && (generic_floating_point_number.low
5421 > generic_floating_point_number.leader))
5422 return TRUE;
5423
5424 return FALSE;
5425}
5426
136da414
JB
5427/* Parse an 8-bit "quarter-precision" floating point number of the form:
5428 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5429 The zero and minus-zero cases need special handling, since they can't be
5430 encoded in the "quarter-precision" float format, but can nonetheless be
5431 loaded as integer constants. */
136da414
JB
5432
5433static unsigned
5434parse_qfloat_immediate (char **ccp, int *immed)
5435{
5436 char *str = *ccp;
c96612cc 5437 char *fpnum;
136da414 5438 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5439 int found_fpchar = 0;
5f4273c7 5440
136da414 5441 skip_past_char (&str, '#');
5f4273c7 5442
c96612cc
JB
5443 /* We must not accidentally parse an integer as a floating-point number. Make
5444 sure that the value we parse is not an integer by checking for special
5445 characters '.' or 'e'.
5446 FIXME: This is a horrible hack, but doing better is tricky because type
5447 information isn't in a very usable state at parse time. */
5448 fpnum = str;
5449 skip_whitespace (fpnum);
5450
5451 if (strncmp (fpnum, "0x", 2) == 0)
5452 return FAIL;
5453 else
5454 {
5455 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5456 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5457 {
5458 found_fpchar = 1;
5459 break;
5460 }
c96612cc
JB
5461
5462 if (!found_fpchar)
477330fc 5463 return FAIL;
c96612cc 5464 }
5f4273c7 5465
136da414
JB
5466 if ((str = atof_ieee (str, 's', words)) != NULL)
5467 {
5468 unsigned fpword = 0;
5469 int i;
5f4273c7 5470
136da414
JB
5471 /* Our FP word must be 32 bits (single-precision FP). */
5472 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5473 {
5474 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5475 fpword |= words[i];
5476 }
5f4273c7 5477
c96612cc 5478 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5479 *immed = fpword;
136da414 5480 else
477330fc 5481 return FAIL;
136da414
JB
5482
5483 *ccp = str;
5f4273c7 5484
136da414
JB
5485 return SUCCESS;
5486 }
5f4273c7 5487
136da414
JB
5488 return FAIL;
5489}
5490
c19d1205
ZW
5491/* Shift operands. */
5492enum shift_kind
b99bd4ef 5493{
f5f10c66 5494 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5495};
b99bd4ef 5496
c19d1205
ZW
5497struct asm_shift_name
5498{
5499 const char *name;
5500 enum shift_kind kind;
5501};
b99bd4ef 5502
c19d1205
ZW
5503/* Third argument to parse_shift. */
5504enum parse_shift_mode
5505{
5506 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5507 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5508 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5509 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5510 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5511 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5512};
b99bd4ef 5513
c19d1205
ZW
5514/* Parse a <shift> specifier on an ARM data processing instruction.
5515 This has three forms:
b99bd4ef 5516
c19d1205
ZW
5517 (LSL|LSR|ASL|ASR|ROR) Rs
5518 (LSL|LSR|ASL|ASR|ROR) #imm
5519 RRX
b99bd4ef 5520
c19d1205
ZW
5521 Note that ASL is assimilated to LSL in the instruction encoding, and
5522 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5523
c19d1205
ZW
5524static int
5525parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5526{
c19d1205
ZW
5527 const struct asm_shift_name *shift_name;
5528 enum shift_kind shift;
5529 char *s = *str;
5530 char *p = s;
5531 int reg;
b99bd4ef 5532
c19d1205
ZW
5533 for (p = *str; ISALPHA (*p); p++)
5534 ;
b99bd4ef 5535
c19d1205 5536 if (p == *str)
b99bd4ef 5537 {
c19d1205
ZW
5538 inst.error = _("shift expression expected");
5539 return FAIL;
b99bd4ef
NC
5540 }
5541
21d799b5 5542 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5543 p - *str);
c19d1205
ZW
5544
5545 if (shift_name == NULL)
b99bd4ef 5546 {
c19d1205
ZW
5547 inst.error = _("shift expression expected");
5548 return FAIL;
b99bd4ef
NC
5549 }
5550
c19d1205 5551 shift = shift_name->kind;
b99bd4ef 5552
c19d1205
ZW
5553 switch (mode)
5554 {
5555 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5556 case SHIFT_IMMEDIATE:
5557 if (shift == SHIFT_UXTW)
5558 {
5559 inst.error = _("'UXTW' not allowed here");
5560 return FAIL;
5561 }
5562 break;
b99bd4ef 5563
c19d1205
ZW
5564 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5565 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5566 {
5567 inst.error = _("'LSL' or 'ASR' required");
5568 return FAIL;
5569 }
5570 break;
b99bd4ef 5571
c19d1205
ZW
5572 case SHIFT_LSL_IMMEDIATE:
5573 if (shift != SHIFT_LSL)
5574 {
5575 inst.error = _("'LSL' required");
5576 return FAIL;
5577 }
5578 break;
b99bd4ef 5579
c19d1205
ZW
5580 case SHIFT_ASR_IMMEDIATE:
5581 if (shift != SHIFT_ASR)
5582 {
5583 inst.error = _("'ASR' required");
5584 return FAIL;
5585 }
5586 break;
f5f10c66
AV
5587 case SHIFT_UXTW_IMMEDIATE:
5588 if (shift != SHIFT_UXTW)
5589 {
5590 inst.error = _("'UXTW' required");
5591 return FAIL;
5592 }
5593 break;
b99bd4ef 5594
c19d1205
ZW
5595 default: abort ();
5596 }
b99bd4ef 5597
c19d1205
ZW
5598 if (shift != SHIFT_RRX)
5599 {
5600 /* Whitespace can appear here if the next thing is a bare digit. */
5601 skip_whitespace (p);
b99bd4ef 5602
c19d1205 5603 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5604 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5605 {
5606 inst.operands[i].imm = reg;
5607 inst.operands[i].immisreg = 1;
5608 }
e2b0ab59 5609 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5610 return FAIL;
5611 }
5612 inst.operands[i].shift_kind = shift;
5613 inst.operands[i].shifted = 1;
5614 *str = p;
5615 return SUCCESS;
b99bd4ef
NC
5616}
5617
c19d1205 5618/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5619
c19d1205
ZW
5620 #<immediate>
5621 #<immediate>, <rotate>
5622 <Rm>
5623 <Rm>, <shift>
b99bd4ef 5624
c19d1205
ZW
5625 where <shift> is defined by parse_shift above, and <rotate> is a
5626 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5627 is deferred to md_apply_fix. */
b99bd4ef 5628
c19d1205
ZW
5629static int
5630parse_shifter_operand (char **str, int i)
5631{
5632 int value;
91d6fa6a 5633 expressionS exp;
b99bd4ef 5634
dcbf9037 5635 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5636 {
5637 inst.operands[i].reg = value;
5638 inst.operands[i].isreg = 1;
b99bd4ef 5639
c19d1205 5640 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5641 inst.relocs[0].exp.X_op = O_constant;
5642 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5643
c19d1205
ZW
5644 if (skip_past_comma (str) == FAIL)
5645 return SUCCESS;
b99bd4ef 5646
c19d1205
ZW
5647 /* Shift operation on register. */
5648 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5649 }
5650
e2b0ab59 5651 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5652 return FAIL;
b99bd4ef 5653
c19d1205 5654 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5655 {
c19d1205 5656 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5657 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5658 return FAIL;
b99bd4ef 5659
e2b0ab59 5660 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5661 {
5662 inst.error = _("constant expression expected");
5663 return FAIL;
5664 }
b99bd4ef 5665
91d6fa6a 5666 value = exp.X_add_number;
c19d1205
ZW
5667 if (value < 0 || value > 30 || value % 2 != 0)
5668 {
5669 inst.error = _("invalid rotation");
5670 return FAIL;
5671 }
e2b0ab59
AV
5672 if (inst.relocs[0].exp.X_add_number < 0
5673 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5674 {
5675 inst.error = _("invalid constant");
5676 return FAIL;
5677 }
09d92015 5678
a415b1cd 5679 /* Encode as specified. */
e2b0ab59 5680 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5681 return SUCCESS;
09d92015
MM
5682 }
5683
e2b0ab59
AV
5684 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5685 inst.relocs[0].pc_rel = 0;
c19d1205 5686 return SUCCESS;
09d92015
MM
5687}
5688
4962c51a
MS
5689/* Group relocation information. Each entry in the table contains the
5690 textual name of the relocation as may appear in assembler source
5691 and must end with a colon.
5692 Along with this textual name are the relocation codes to be used if
5693 the corresponding instruction is an ALU instruction (ADD or SUB only),
5694 an LDR, an LDRS, or an LDC. */
5695
5696struct group_reloc_table_entry
5697{
5698 const char *name;
5699 int alu_code;
5700 int ldr_code;
5701 int ldrs_code;
5702 int ldc_code;
5703};
5704
5705typedef enum
5706{
5707 /* Varieties of non-ALU group relocation. */
5708
5709 GROUP_LDR,
5710 GROUP_LDRS,
35c228db
AV
5711 GROUP_LDC,
5712 GROUP_MVE
4962c51a
MS
5713} group_reloc_type;
5714
5715static struct group_reloc_table_entry group_reloc_table[] =
5716 { /* Program counter relative: */
5717 { "pc_g0_nc",
5718 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5719 0, /* LDR */
5720 0, /* LDRS */
5721 0 }, /* LDC */
5722 { "pc_g0",
5723 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5724 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5725 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5726 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5727 { "pc_g1_nc",
5728 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5729 0, /* LDR */
5730 0, /* LDRS */
5731 0 }, /* LDC */
5732 { "pc_g1",
5733 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5734 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5735 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5736 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5737 { "pc_g2",
5738 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5739 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5740 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5741 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5742 /* Section base relative */
5743 { "sb_g0_nc",
5744 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5745 0, /* LDR */
5746 0, /* LDRS */
5747 0 }, /* LDC */
5748 { "sb_g0",
5749 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5750 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5751 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5752 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5753 { "sb_g1_nc",
5754 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5755 0, /* LDR */
5756 0, /* LDRS */
5757 0 }, /* LDC */
5758 { "sb_g1",
5759 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5760 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5761 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5762 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5763 { "sb_g2",
5764 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5765 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5766 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5767 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5768 /* Absolute thumb alu relocations. */
5769 { "lower0_7",
5770 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5771 0, /* LDR. */
5772 0, /* LDRS. */
5773 0 }, /* LDC. */
5774 { "lower8_15",
5775 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5776 0, /* LDR. */
5777 0, /* LDRS. */
5778 0 }, /* LDC. */
5779 { "upper0_7",
5780 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5781 0, /* LDR. */
5782 0, /* LDRS. */
5783 0 }, /* LDC. */
5784 { "upper8_15",
5785 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5786 0, /* LDR. */
5787 0, /* LDRS. */
5788 0 } }; /* LDC. */
4962c51a
MS
5789
5790/* Given the address of a pointer pointing to the textual name of a group
5791 relocation as may appear in assembler source, attempt to find its details
5792 in group_reloc_table. The pointer will be updated to the character after
5793 the trailing colon. On failure, FAIL will be returned; SUCCESS
5794 otherwise. On success, *entry will be updated to point at the relevant
5795 group_reloc_table entry. */
5796
5797static int
5798find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5799{
5800 unsigned int i;
5801 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5802 {
5803 int length = strlen (group_reloc_table[i].name);
5804
5f4273c7
NC
5805 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5806 && (*str)[length] == ':')
477330fc
RM
5807 {
5808 *out = &group_reloc_table[i];
5809 *str += (length + 1);
5810 return SUCCESS;
5811 }
4962c51a
MS
5812 }
5813
5814 return FAIL;
5815}
5816
5817/* Parse a <shifter_operand> for an ARM data processing instruction
5818 (as for parse_shifter_operand) where group relocations are allowed:
5819
5820 #<immediate>
5821 #<immediate>, <rotate>
5822 #:<group_reloc>:<expression>
5823 <Rm>
5824 <Rm>, <shift>
5825
5826 where <group_reloc> is one of the strings defined in group_reloc_table.
5827 The hashes are optional.
5828
5829 Everything else is as for parse_shifter_operand. */
5830
5831static parse_operand_result
5832parse_shifter_operand_group_reloc (char **str, int i)
5833{
5834 /* Determine if we have the sequence of characters #: or just :
5835 coming next. If we do, then we check for a group relocation.
5836 If we don't, punt the whole lot to parse_shifter_operand. */
5837
5838 if (((*str)[0] == '#' && (*str)[1] == ':')
5839 || (*str)[0] == ':')
5840 {
5841 struct group_reloc_table_entry *entry;
5842
5843 if ((*str)[0] == '#')
477330fc 5844 (*str) += 2;
4962c51a 5845 else
477330fc 5846 (*str)++;
4962c51a
MS
5847
5848 /* Try to parse a group relocation. Anything else is an error. */
5849 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5850 {
5851 inst.error = _("unknown group relocation");
5852 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5853 }
4962c51a
MS
5854
5855 /* We now have the group relocation table entry corresponding to
477330fc 5856 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5857 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5858 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5859
5860 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5861 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5862 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5863
5864 return PARSE_OPERAND_SUCCESS;
5865 }
5866 else
5867 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5868 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5869
5870 /* Never reached. */
5871}
5872
8e560766
MGD
5873/* Parse a Neon alignment expression. Information is written to
5874 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5875
8e560766
MGD
5876 align .imm = align << 8, .immisalign=1, .preind=0 */
5877static parse_operand_result
5878parse_neon_alignment (char **str, int i)
5879{
5880 char *p = *str;
5881 expressionS exp;
5882
5883 my_get_expression (&exp, &p, GE_NO_PREFIX);
5884
5885 if (exp.X_op != O_constant)
5886 {
5887 inst.error = _("alignment must be constant");
5888 return PARSE_OPERAND_FAIL;
5889 }
5890
5891 inst.operands[i].imm = exp.X_add_number << 8;
5892 inst.operands[i].immisalign = 1;
5893 /* Alignments are not pre-indexes. */
5894 inst.operands[i].preind = 0;
5895
5896 *str = p;
5897 return PARSE_OPERAND_SUCCESS;
5898}
5899
c19d1205 5900/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5901 to inst.operands[i] and/or inst.relocs[0].
09d92015 5902
c19d1205 5903 Preindexed addressing (.preind=1):
09d92015 5904
e2b0ab59 5905 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5906 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5907 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5908 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5909
c19d1205 5910 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5911
c19d1205 5912 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5913
e2b0ab59 5914 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5915 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5916 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5917 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5918
c19d1205 5919 Unindexed addressing (.preind=0, .postind=0):
09d92015 5920
c19d1205 5921 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5922
c19d1205 5923 Other:
09d92015 5924
c19d1205 5925 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5926 =immediate .isreg=0 .relocs[0].exp=immediate
5927 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5928
c19d1205 5929 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5930 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5931
4962c51a
MS
5932static parse_operand_result
5933parse_address_main (char **str, int i, int group_relocations,
477330fc 5934 group_reloc_type group_type)
09d92015 5935{
c19d1205
ZW
5936 char *p = *str;
5937 int reg;
09d92015 5938
c19d1205 5939 if (skip_past_char (&p, '[') == FAIL)
09d92015 5940 {
c19d1205
ZW
5941 if (skip_past_char (&p, '=') == FAIL)
5942 {
974da60d 5943 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5944 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5945 inst.operands[i].reg = REG_PC;
5946 inst.operands[i].isreg = 1;
5947 inst.operands[i].preind = 1;
09d92015 5948
e2b0ab59 5949 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5950 return PARSE_OPERAND_FAIL;
5951 }
e2b0ab59 5952 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5953 /*allow_symbol_p=*/TRUE))
4962c51a 5954 return PARSE_OPERAND_FAIL;
09d92015 5955
c19d1205 5956 *str = p;
4962c51a 5957 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5958 }
5959
8ab8155f
NC
5960 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5961 skip_whitespace (p);
5962
f5f10c66
AV
5963 if (group_type == GROUP_MVE)
5964 {
5965 enum arm_reg_type rtype = REG_TYPE_MQ;
5966 struct neon_type_el et;
5967 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5968 {
5969 inst.operands[i].isquad = 1;
5970 }
5971 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5972 {
5973 inst.error = BAD_ADDR_MODE;
5974 return PARSE_OPERAND_FAIL;
5975 }
5976 }
5977 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5978 {
35c228db
AV
5979 if (group_type == GROUP_MVE)
5980 inst.error = BAD_ADDR_MODE;
5981 else
5982 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5983 return PARSE_OPERAND_FAIL;
09d92015 5984 }
c19d1205
ZW
5985 inst.operands[i].reg = reg;
5986 inst.operands[i].isreg = 1;
09d92015 5987
c19d1205 5988 if (skip_past_comma (&p) == SUCCESS)
09d92015 5989 {
c19d1205 5990 inst.operands[i].preind = 1;
09d92015 5991
c19d1205
ZW
5992 if (*p == '+') p++;
5993 else if (*p == '-') p++, inst.operands[i].negative = 1;
5994
f5f10c66
AV
5995 enum arm_reg_type rtype = REG_TYPE_MQ;
5996 struct neon_type_el et;
5997 if (group_type == GROUP_MVE
5998 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5999 {
6000 inst.operands[i].immisreg = 2;
6001 inst.operands[i].imm = reg;
6002
6003 if (skip_past_comma (&p) == SUCCESS)
6004 {
6005 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6006 {
6007 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6008 inst.relocs[0].exp.X_add_number = 0;
6009 }
6010 else
6011 return PARSE_OPERAND_FAIL;
6012 }
6013 }
6014 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 6015 {
c19d1205
ZW
6016 inst.operands[i].imm = reg;
6017 inst.operands[i].immisreg = 1;
6018
6019 if (skip_past_comma (&p) == SUCCESS)
6020 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6021 return PARSE_OPERAND_FAIL;
c19d1205 6022 }
5287ad62 6023 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
6024 {
6025 /* FIXME: '@' should be used here, but it's filtered out by generic
6026 code before we get to see it here. This may be subject to
6027 change. */
6028 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6029
8e560766
MGD
6030 if (result != PARSE_OPERAND_SUCCESS)
6031 return result;
6032 }
c19d1205
ZW
6033 else
6034 {
6035 if (inst.operands[i].negative)
6036 {
6037 inst.operands[i].negative = 0;
6038 p--;
6039 }
4962c51a 6040
5f4273c7
NC
6041 if (group_relocations
6042 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
6043 {
6044 struct group_reloc_table_entry *entry;
6045
477330fc
RM
6046 /* Skip over the #: or : sequence. */
6047 if (*p == '#')
6048 p += 2;
6049 else
6050 p++;
4962c51a
MS
6051
6052 /* Try to parse a group relocation. Anything else is an
477330fc 6053 error. */
4962c51a
MS
6054 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6055 {
6056 inst.error = _("unknown group relocation");
6057 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6058 }
6059
6060 /* We now have the group relocation table entry corresponding to
6061 the name in the assembler source. Next, we parse the
477330fc 6062 expression. */
e2b0ab59 6063 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
6064 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6065
6066 /* Record the relocation type. */
477330fc
RM
6067 switch (group_type)
6068 {
6069 case GROUP_LDR:
e2b0ab59
AV
6070 inst.relocs[0].type
6071 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 6072 break;
4962c51a 6073
477330fc 6074 case GROUP_LDRS:
e2b0ab59
AV
6075 inst.relocs[0].type
6076 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 6077 break;
4962c51a 6078
477330fc 6079 case GROUP_LDC:
e2b0ab59
AV
6080 inst.relocs[0].type
6081 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 6082 break;
4962c51a 6083
477330fc
RM
6084 default:
6085 gas_assert (0);
6086 }
4962c51a 6087
e2b0ab59 6088 if (inst.relocs[0].type == 0)
4962c51a
MS
6089 {
6090 inst.error = _("this group relocation is not allowed on this instruction");
6091 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6092 }
477330fc
RM
6093 }
6094 else
26d97720
NS
6095 {
6096 char *q = p;
0198d5e6 6097
e2b0ab59 6098 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
6099 return PARSE_OPERAND_FAIL;
6100 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6101 if (inst.relocs[0].exp.X_op == O_constant
6102 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6103 {
6104 skip_whitespace (q);
6105 if (*q == '#')
6106 {
6107 q++;
6108 skip_whitespace (q);
6109 }
6110 if (*q == '-')
6111 inst.operands[i].negative = 1;
6112 }
6113 }
09d92015
MM
6114 }
6115 }
8e560766
MGD
6116 else if (skip_past_char (&p, ':') == SUCCESS)
6117 {
6118 /* FIXME: '@' should be used here, but it's filtered out by generic code
6119 before we get to see it here. This may be subject to change. */
6120 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6121
8e560766
MGD
6122 if (result != PARSE_OPERAND_SUCCESS)
6123 return result;
6124 }
09d92015 6125
c19d1205 6126 if (skip_past_char (&p, ']') == FAIL)
09d92015 6127 {
c19d1205 6128 inst.error = _("']' expected");
4962c51a 6129 return PARSE_OPERAND_FAIL;
09d92015
MM
6130 }
6131
c19d1205
ZW
6132 if (skip_past_char (&p, '!') == SUCCESS)
6133 inst.operands[i].writeback = 1;
09d92015 6134
c19d1205 6135 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6136 {
c19d1205
ZW
6137 if (skip_past_char (&p, '{') == SUCCESS)
6138 {
6139 /* [Rn], {expr} - unindexed, with option */
6140 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6141 0, 255, TRUE) == FAIL)
4962c51a 6142 return PARSE_OPERAND_FAIL;
09d92015 6143
c19d1205
ZW
6144 if (skip_past_char (&p, '}') == FAIL)
6145 {
6146 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6147 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6148 }
6149 if (inst.operands[i].preind)
6150 {
6151 inst.error = _("cannot combine index with option");
4962c51a 6152 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6153 }
6154 *str = p;
4962c51a 6155 return PARSE_OPERAND_SUCCESS;
09d92015 6156 }
c19d1205
ZW
6157 else
6158 {
6159 inst.operands[i].postind = 1;
6160 inst.operands[i].writeback = 1;
09d92015 6161
c19d1205
ZW
6162 if (inst.operands[i].preind)
6163 {
6164 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6165 return PARSE_OPERAND_FAIL;
c19d1205 6166 }
09d92015 6167
c19d1205
ZW
6168 if (*p == '+') p++;
6169 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6170
f5f10c66
AV
6171 enum arm_reg_type rtype = REG_TYPE_MQ;
6172 struct neon_type_el et;
6173 if (group_type == GROUP_MVE
6174 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6175 {
6176 inst.operands[i].immisreg = 2;
6177 inst.operands[i].imm = reg;
6178 }
6179 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6180 {
477330fc
RM
6181 /* We might be using the immediate for alignment already. If we
6182 are, OR the register number into the low-order bits. */
6183 if (inst.operands[i].immisalign)
6184 inst.operands[i].imm |= reg;
6185 else
6186 inst.operands[i].imm = reg;
c19d1205 6187 inst.operands[i].immisreg = 1;
a737bd4d 6188
c19d1205
ZW
6189 if (skip_past_comma (&p) == SUCCESS)
6190 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6191 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6192 }
6193 else
6194 {
26d97720 6195 char *q = p;
0198d5e6 6196
c19d1205
ZW
6197 if (inst.operands[i].negative)
6198 {
6199 inst.operands[i].negative = 0;
6200 p--;
6201 }
e2b0ab59 6202 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6203 return PARSE_OPERAND_FAIL;
26d97720 6204 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6205 if (inst.relocs[0].exp.X_op == O_constant
6206 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6207 {
6208 skip_whitespace (q);
6209 if (*q == '#')
6210 {
6211 q++;
6212 skip_whitespace (q);
6213 }
6214 if (*q == '-')
6215 inst.operands[i].negative = 1;
6216 }
c19d1205
ZW
6217 }
6218 }
a737bd4d
NC
6219 }
6220
c19d1205
ZW
6221 /* If at this point neither .preind nor .postind is set, we have a
6222 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6223 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6224 {
6225 inst.operands[i].preind = 1;
e2b0ab59
AV
6226 inst.relocs[0].exp.X_op = O_constant;
6227 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6228 }
6229 *str = p;
4962c51a
MS
6230 return PARSE_OPERAND_SUCCESS;
6231}
6232
6233static int
6234parse_address (char **str, int i)
6235{
21d799b5 6236 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6237 ? SUCCESS : FAIL;
4962c51a
MS
6238}
6239
6240static parse_operand_result
6241parse_address_group_reloc (char **str, int i, group_reloc_type type)
6242{
6243 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6244}
6245
b6895b4f
PB
6246/* Parse an operand for a MOVW or MOVT instruction. */
6247static int
6248parse_half (char **str)
6249{
6250 char * p;
5f4273c7 6251
b6895b4f
PB
6252 p = *str;
6253 skip_past_char (&p, '#');
5f4273c7 6254 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6255 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6256 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6257 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6258
e2b0ab59 6259 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6260 {
6261 p += 9;
5f4273c7 6262 skip_whitespace (p);
b6895b4f
PB
6263 }
6264
e2b0ab59 6265 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6266 return FAIL;
6267
e2b0ab59 6268 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6269 {
e2b0ab59 6270 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6271 {
6272 inst.error = _("constant expression expected");
6273 return FAIL;
6274 }
e2b0ab59
AV
6275 if (inst.relocs[0].exp.X_add_number < 0
6276 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6277 {
6278 inst.error = _("immediate value out of range");
6279 return FAIL;
6280 }
6281 }
6282 *str = p;
6283 return SUCCESS;
6284}
6285
c19d1205 6286/* Miscellaneous. */
a737bd4d 6287
c19d1205
ZW
6288/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6289 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6290static int
d2cd1205 6291parse_psr (char **str, bfd_boolean lhs)
09d92015 6292{
c19d1205
ZW
6293 char *p;
6294 unsigned long psr_field;
62b3e311
PB
6295 const struct asm_psr *psr;
6296 char *start;
d2cd1205 6297 bfd_boolean is_apsr = FALSE;
ac7f631b 6298 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6299
a4482bb6
NC
6300 /* PR gas/12698: If the user has specified -march=all then m_profile will
6301 be TRUE, but we want to ignore it in this case as we are building for any
6302 CPU type, including non-m variants. */
823d2571 6303 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6304 m_profile = FALSE;
6305
c19d1205
ZW
6306 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6307 feature for ease of use and backwards compatibility. */
6308 p = *str;
62b3e311 6309 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6310 {
6311 if (m_profile)
6312 goto unsupported_psr;
fa94de6b 6313
d2cd1205
JB
6314 psr_field = SPSR_BIT;
6315 }
6316 else if (strncasecmp (p, "CPSR", 4) == 0)
6317 {
6318 if (m_profile)
6319 goto unsupported_psr;
6320
6321 psr_field = 0;
6322 }
6323 else if (strncasecmp (p, "APSR", 4) == 0)
6324 {
6325 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6326 and ARMv7-R architecture CPUs. */
6327 is_apsr = TRUE;
6328 psr_field = 0;
6329 }
6330 else if (m_profile)
62b3e311
PB
6331 {
6332 start = p;
6333 do
6334 p++;
6335 while (ISALNUM (*p) || *p == '_');
6336
d2cd1205
JB
6337 if (strncasecmp (start, "iapsr", 5) == 0
6338 || strncasecmp (start, "eapsr", 5) == 0
6339 || strncasecmp (start, "xpsr", 4) == 0
6340 || strncasecmp (start, "psr", 3) == 0)
6341 p = start + strcspn (start, "rR") + 1;
6342
21d799b5 6343 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6344 p - start);
d2cd1205 6345
62b3e311
PB
6346 if (!psr)
6347 return FAIL;
09d92015 6348
d2cd1205
JB
6349 /* If APSR is being written, a bitfield may be specified. Note that
6350 APSR itself is handled above. */
6351 if (psr->field <= 3)
6352 {
6353 psr_field = psr->field;
6354 is_apsr = TRUE;
6355 goto check_suffix;
6356 }
6357
62b3e311 6358 *str = p;
d2cd1205
JB
6359 /* M-profile MSR instructions have the mask field set to "10", except
6360 *PSR variants which modify APSR, which may use a different mask (and
6361 have been handled already). Do that by setting the PSR_f field
6362 here. */
6363 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6364 }
d2cd1205
JB
6365 else
6366 goto unsupported_psr;
09d92015 6367
62b3e311 6368 p += 4;
dc1e8a47 6369 check_suffix:
c19d1205
ZW
6370 if (*p == '_')
6371 {
6372 /* A suffix follows. */
c19d1205
ZW
6373 p++;
6374 start = p;
a737bd4d 6375
c19d1205
ZW
6376 do
6377 p++;
6378 while (ISALNUM (*p) || *p == '_');
a737bd4d 6379
d2cd1205
JB
6380 if (is_apsr)
6381 {
6382 /* APSR uses a notation for bits, rather than fields. */
6383 unsigned int nzcvq_bits = 0;
6384 unsigned int g_bit = 0;
6385 char *bit;
fa94de6b 6386
d2cd1205
JB
6387 for (bit = start; bit != p; bit++)
6388 {
6389 switch (TOLOWER (*bit))
477330fc 6390 {
d2cd1205
JB
6391 case 'n':
6392 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6393 break;
6394
6395 case 'z':
6396 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6397 break;
6398
6399 case 'c':
6400 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6401 break;
6402
6403 case 'v':
6404 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6405 break;
fa94de6b 6406
d2cd1205
JB
6407 case 'q':
6408 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6409 break;
fa94de6b 6410
d2cd1205
JB
6411 case 'g':
6412 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6413 break;
fa94de6b 6414
d2cd1205
JB
6415 default:
6416 inst.error = _("unexpected bit specified after APSR");
6417 return FAIL;
6418 }
6419 }
fa94de6b 6420
d2cd1205
JB
6421 if (nzcvq_bits == 0x1f)
6422 psr_field |= PSR_f;
fa94de6b 6423
d2cd1205
JB
6424 if (g_bit == 0x1)
6425 {
6426 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6427 {
d2cd1205
JB
6428 inst.error = _("selected processor does not "
6429 "support DSP extension");
6430 return FAIL;
6431 }
6432
6433 psr_field |= PSR_s;
6434 }
fa94de6b 6435
d2cd1205
JB
6436 if ((nzcvq_bits & 0x20) != 0
6437 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6438 || (g_bit & 0x2) != 0)
6439 {
6440 inst.error = _("bad bitmask specified after APSR");
6441 return FAIL;
6442 }
6443 }
6444 else
477330fc 6445 {
d2cd1205 6446 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6447 p - start);
d2cd1205 6448 if (!psr)
477330fc 6449 goto error;
a737bd4d 6450
d2cd1205
JB
6451 psr_field |= psr->field;
6452 }
a737bd4d 6453 }
c19d1205 6454 else
a737bd4d 6455 {
c19d1205
ZW
6456 if (ISALNUM (*p))
6457 goto error; /* Garbage after "[CS]PSR". */
6458
d2cd1205 6459 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6460 is deprecated, but allow it anyway. */
d2cd1205
JB
6461 if (is_apsr && lhs)
6462 {
6463 psr_field |= PSR_f;
6464 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6465 "deprecated"));
6466 }
6467 else if (!m_profile)
6468 /* These bits are never right for M-profile devices: don't set them
6469 (only code paths which read/write APSR reach here). */
6470 psr_field |= (PSR_c | PSR_f);
a737bd4d 6471 }
c19d1205
ZW
6472 *str = p;
6473 return psr_field;
a737bd4d 6474
d2cd1205
JB
6475 unsupported_psr:
6476 inst.error = _("selected processor does not support requested special "
6477 "purpose register");
6478 return FAIL;
6479
c19d1205
ZW
6480 error:
6481 inst.error = _("flag for {c}psr instruction expected");
6482 return FAIL;
a737bd4d
NC
6483}
6484
32c36c3c
AV
6485static int
6486parse_sys_vldr_vstr (char **str)
6487{
6488 unsigned i;
6489 int val = FAIL;
6490 struct {
6491 const char *name;
6492 int regl;
6493 int regh;
6494 } sysregs[] = {
6495 {"FPSCR", 0x1, 0x0},
6496 {"FPSCR_nzcvqc", 0x2, 0x0},
6497 {"VPR", 0x4, 0x1},
6498 {"P0", 0x5, 0x1},
6499 {"FPCXTNS", 0x6, 0x1},
6500 {"FPCXTS", 0x7, 0x1}
6501 };
6502 char *op_end = strchr (*str, ',');
6503 size_t op_strlen = op_end - *str;
6504
6505 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6506 {
6507 if (!strncmp (*str, sysregs[i].name, op_strlen))
6508 {
6509 val = sysregs[i].regl | (sysregs[i].regh << 3);
6510 *str = op_end;
6511 break;
6512 }
6513 }
6514
6515 return val;
6516}
6517
c19d1205
ZW
6518/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6519 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6520
c19d1205
ZW
6521static int
6522parse_cps_flags (char **str)
a737bd4d 6523{
c19d1205
ZW
6524 int val = 0;
6525 int saw_a_flag = 0;
6526 char *s = *str;
a737bd4d 6527
c19d1205
ZW
6528 for (;;)
6529 switch (*s++)
6530 {
6531 case '\0': case ',':
6532 goto done;
a737bd4d 6533
c19d1205
ZW
6534 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6535 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6536 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6537
c19d1205
ZW
6538 default:
6539 inst.error = _("unrecognized CPS flag");
6540 return FAIL;
6541 }
a737bd4d 6542
c19d1205
ZW
6543 done:
6544 if (saw_a_flag == 0)
a737bd4d 6545 {
c19d1205
ZW
6546 inst.error = _("missing CPS flags");
6547 return FAIL;
a737bd4d 6548 }
a737bd4d 6549
c19d1205
ZW
6550 *str = s - 1;
6551 return val;
a737bd4d
NC
6552}
6553
c19d1205
ZW
6554/* Parse an endian specifier ("BE" or "LE", case insensitive);
6555 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6556
6557static int
c19d1205 6558parse_endian_specifier (char **str)
a737bd4d 6559{
c19d1205
ZW
6560 int little_endian;
6561 char *s = *str;
a737bd4d 6562
c19d1205
ZW
6563 if (strncasecmp (s, "BE", 2))
6564 little_endian = 0;
6565 else if (strncasecmp (s, "LE", 2))
6566 little_endian = 1;
6567 else
a737bd4d 6568 {
c19d1205 6569 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6570 return FAIL;
6571 }
6572
c19d1205 6573 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6574 {
c19d1205 6575 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6576 return FAIL;
6577 }
6578
c19d1205
ZW
6579 *str = s + 2;
6580 return little_endian;
6581}
a737bd4d 6582
c19d1205
ZW
6583/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6584 value suitable for poking into the rotate field of an sxt or sxta
6585 instruction, or FAIL on error. */
6586
6587static int
6588parse_ror (char **str)
6589{
6590 int rot;
6591 char *s = *str;
6592
6593 if (strncasecmp (s, "ROR", 3) == 0)
6594 s += 3;
6595 else
a737bd4d 6596 {
c19d1205 6597 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6598 return FAIL;
6599 }
c19d1205
ZW
6600
6601 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6602 return FAIL;
6603
6604 switch (rot)
a737bd4d 6605 {
c19d1205
ZW
6606 case 0: *str = s; return 0x0;
6607 case 8: *str = s; return 0x1;
6608 case 16: *str = s; return 0x2;
6609 case 24: *str = s; return 0x3;
6610
6611 default:
6612 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6613 return FAIL;
6614 }
c19d1205 6615}
a737bd4d 6616
c19d1205
ZW
6617/* Parse a conditional code (from conds[] below). The value returned is in the
6618 range 0 .. 14, or FAIL. */
6619static int
6620parse_cond (char **str)
6621{
c462b453 6622 char *q;
c19d1205 6623 const struct asm_cond *c;
c462b453
PB
6624 int n;
6625 /* Condition codes are always 2 characters, so matching up to
6626 3 characters is sufficient. */
6627 char cond[3];
a737bd4d 6628
c462b453
PB
6629 q = *str;
6630 n = 0;
6631 while (ISALPHA (*q) && n < 3)
6632 {
e07e6e58 6633 cond[n] = TOLOWER (*q);
c462b453
PB
6634 q++;
6635 n++;
6636 }
a737bd4d 6637
21d799b5 6638 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6639 if (!c)
a737bd4d 6640 {
c19d1205 6641 inst.error = _("condition required");
a737bd4d
NC
6642 return FAIL;
6643 }
6644
c19d1205
ZW
6645 *str = q;
6646 return c->value;
6647}
6648
62b3e311
PB
6649/* Parse an option for a barrier instruction. Returns the encoding for the
6650 option, or FAIL. */
6651static int
6652parse_barrier (char **str)
6653{
6654 char *p, *q;
6655 const struct asm_barrier_opt *o;
6656
6657 p = q = *str;
6658 while (ISALPHA (*q))
6659 q++;
6660
21d799b5 6661 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6662 q - p);
62b3e311
PB
6663 if (!o)
6664 return FAIL;
6665
e797f7e0
MGD
6666 if (!mark_feature_used (&o->arch))
6667 return FAIL;
6668
62b3e311
PB
6669 *str = q;
6670 return o->value;
6671}
6672
92e90b6e
PB
6673/* Parse the operands of a table branch instruction. Similar to a memory
6674 operand. */
6675static int
6676parse_tb (char **str)
6677{
6678 char * p = *str;
6679 int reg;
6680
6681 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6682 {
6683 inst.error = _("'[' expected");
6684 return FAIL;
6685 }
92e90b6e 6686
dcbf9037 6687 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6688 {
6689 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6690 return FAIL;
6691 }
6692 inst.operands[0].reg = reg;
6693
6694 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6695 {
6696 inst.error = _("',' expected");
6697 return FAIL;
6698 }
5f4273c7 6699
dcbf9037 6700 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6701 {
6702 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6703 return FAIL;
6704 }
6705 inst.operands[0].imm = reg;
6706
6707 if (skip_past_comma (&p) == SUCCESS)
6708 {
6709 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6710 return FAIL;
e2b0ab59 6711 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6712 {
6713 inst.error = _("invalid shift");
6714 return FAIL;
6715 }
6716 inst.operands[0].shifted = 1;
6717 }
6718
6719 if (skip_past_char (&p, ']') == FAIL)
6720 {
6721 inst.error = _("']' expected");
6722 return FAIL;
6723 }
6724 *str = p;
6725 return SUCCESS;
6726}
6727
5287ad62
JB
6728/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6729 information on the types the operands can take and how they are encoded.
037e8744
JB
6730 Up to four operands may be read; this function handles setting the
6731 ".present" field for each read operand itself.
5287ad62
JB
6732 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6733 else returns FAIL. */
6734
6735static int
6736parse_neon_mov (char **str, int *which_operand)
6737{
6738 int i = *which_operand, val;
6739 enum arm_reg_type rtype;
6740 char *ptr = *str;
dcbf9037 6741 struct neon_type_el optype;
5f4273c7 6742
57785aa2
AV
6743 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6744 {
6745 /* Cases 17 or 19. */
6746 inst.operands[i].reg = val;
6747 inst.operands[i].isvec = 1;
6748 inst.operands[i].isscalar = 2;
6749 inst.operands[i].vectype = optype;
6750 inst.operands[i++].present = 1;
6751
6752 if (skip_past_comma (&ptr) == FAIL)
6753 goto wanted_comma;
6754
6755 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6756 {
6757 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6758 inst.operands[i].reg = val;
6759 inst.operands[i].isreg = 1;
6760 inst.operands[i].present = 1;
6761 }
6762 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6763 {
6764 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6765 inst.operands[i].reg = val;
6766 inst.operands[i].isvec = 1;
6767 inst.operands[i].isscalar = 2;
6768 inst.operands[i].vectype = optype;
6769 inst.operands[i++].present = 1;
6770
6771 if (skip_past_comma (&ptr) == FAIL)
6772 goto wanted_comma;
6773
6774 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6775 goto wanted_arm;
6776
6777 inst.operands[i].reg = val;
6778 inst.operands[i].isreg = 1;
6779 inst.operands[i++].present = 1;
6780
6781 if (skip_past_comma (&ptr) == FAIL)
6782 goto wanted_comma;
6783
6784 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6785 goto wanted_arm;
6786
6787 inst.operands[i].reg = val;
6788 inst.operands[i].isreg = 1;
6789 inst.operands[i].present = 1;
6790 }
6791 else
6792 {
6793 first_error (_("expected ARM or MVE vector register"));
6794 return FAIL;
6795 }
6796 }
6797 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6798 {
6799 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6800 inst.operands[i].reg = val;
6801 inst.operands[i].isscalar = 1;
dcbf9037 6802 inst.operands[i].vectype = optype;
5287ad62
JB
6803 inst.operands[i++].present = 1;
6804
6805 if (skip_past_comma (&ptr) == FAIL)
477330fc 6806 goto wanted_comma;
5f4273c7 6807
dcbf9037 6808 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6809 goto wanted_arm;
5f4273c7 6810
5287ad62
JB
6811 inst.operands[i].reg = val;
6812 inst.operands[i].isreg = 1;
6813 inst.operands[i].present = 1;
6814 }
57785aa2
AV
6815 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6816 != FAIL)
6817 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6818 != FAIL))
5287ad62
JB
6819 {
6820 /* Cases 0, 1, 2, 3, 5 (D only). */
6821 if (skip_past_comma (&ptr) == FAIL)
477330fc 6822 goto wanted_comma;
5f4273c7 6823
5287ad62
JB
6824 inst.operands[i].reg = val;
6825 inst.operands[i].isreg = 1;
6826 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6827 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6828 inst.operands[i].isvec = 1;
dcbf9037 6829 inst.operands[i].vectype = optype;
5287ad62
JB
6830 inst.operands[i++].present = 1;
6831
dcbf9037 6832 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6833 {
6834 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6835 Case 13: VMOV <Sd>, <Rm> */
6836 inst.operands[i].reg = val;
6837 inst.operands[i].isreg = 1;
6838 inst.operands[i].present = 1;
6839
6840 if (rtype == REG_TYPE_NQ)
6841 {
6842 first_error (_("can't use Neon quad register here"));
6843 return FAIL;
6844 }
6845 else if (rtype != REG_TYPE_VFS)
6846 {
6847 i++;
6848 if (skip_past_comma (&ptr) == FAIL)
6849 goto wanted_comma;
6850 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6851 goto wanted_arm;
6852 inst.operands[i].reg = val;
6853 inst.operands[i].isreg = 1;
6854 inst.operands[i].present = 1;
6855 }
6856 }
c4a23bf8
SP
6857 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6858 &optype)) != FAIL)
6859 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6860 &optype)) != FAIL))
477330fc
RM
6861 {
6862 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6863 Case 1: VMOV<c><q> <Dd>, <Dm>
6864 Case 8: VMOV.F32 <Sd>, <Sm>
6865 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6866
6867 inst.operands[i].reg = val;
6868 inst.operands[i].isreg = 1;
6869 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6870 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6871 inst.operands[i].isvec = 1;
6872 inst.operands[i].vectype = optype;
6873 inst.operands[i].present = 1;
6874
6875 if (skip_past_comma (&ptr) == SUCCESS)
6876 {
6877 /* Case 15. */
6878 i++;
6879
6880 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6881 goto wanted_arm;
6882
6883 inst.operands[i].reg = val;
6884 inst.operands[i].isreg = 1;
6885 inst.operands[i++].present = 1;
6886
6887 if (skip_past_comma (&ptr) == FAIL)
6888 goto wanted_comma;
6889
6890 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6891 goto wanted_arm;
6892
6893 inst.operands[i].reg = val;
6894 inst.operands[i].isreg = 1;
6895 inst.operands[i].present = 1;
6896 }
6897 }
4641781c 6898 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6899 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6900 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6901 Case 10: VMOV.F32 <Sd>, #<imm>
6902 Case 11: VMOV.F64 <Dd>, #<imm> */
6903 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6904 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6905 == SUCCESS)
477330fc
RM
6906 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6907 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6908 ;
5287ad62 6909 else
477330fc
RM
6910 {
6911 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6912 return FAIL;
6913 }
5287ad62 6914 }
dcbf9037 6915 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6916 {
57785aa2 6917 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6918 inst.operands[i].reg = val;
6919 inst.operands[i].isreg = 1;
6920 inst.operands[i++].present = 1;
5f4273c7 6921
5287ad62 6922 if (skip_past_comma (&ptr) == FAIL)
477330fc 6923 goto wanted_comma;
5f4273c7 6924
57785aa2
AV
6925 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6926 {
6927 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6928 inst.operands[i].reg = val;
6929 inst.operands[i].isscalar = 2;
6930 inst.operands[i].present = 1;
6931 inst.operands[i].vectype = optype;
6932 }
6933 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6934 {
6935 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6936 inst.operands[i].reg = val;
6937 inst.operands[i].isscalar = 1;
6938 inst.operands[i].present = 1;
6939 inst.operands[i].vectype = optype;
6940 }
dcbf9037 6941 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6942 {
477330fc
RM
6943 inst.operands[i].reg = val;
6944 inst.operands[i].isreg = 1;
6945 inst.operands[i++].present = 1;
6946
6947 if (skip_past_comma (&ptr) == FAIL)
6948 goto wanted_comma;
6949
6950 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6951 != FAIL)
477330fc 6952 {
57785aa2 6953 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6954
477330fc
RM
6955 inst.operands[i].reg = val;
6956 inst.operands[i].isreg = 1;
6957 inst.operands[i].isvec = 1;
57785aa2 6958 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6959 inst.operands[i].vectype = optype;
6960 inst.operands[i].present = 1;
57785aa2
AV
6961
6962 if (rtype == REG_TYPE_VFS)
6963 {
6964 /* Case 14. */
6965 i++;
6966 if (skip_past_comma (&ptr) == FAIL)
6967 goto wanted_comma;
6968 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6969 &optype)) == FAIL)
6970 {
6971 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6972 return FAIL;
6973 }
6974 inst.operands[i].reg = val;
6975 inst.operands[i].isreg = 1;
6976 inst.operands[i].isvec = 1;
6977 inst.operands[i].issingle = 1;
6978 inst.operands[i].vectype = optype;
6979 inst.operands[i].present = 1;
6980 }
6981 }
6982 else
6983 {
6984 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6985 != FAIL)
6986 {
6987 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6988 inst.operands[i].reg = val;
6989 inst.operands[i].isvec = 1;
6990 inst.operands[i].isscalar = 2;
6991 inst.operands[i].vectype = optype;
6992 inst.operands[i++].present = 1;
6993
6994 if (skip_past_comma (&ptr) == FAIL)
6995 goto wanted_comma;
6996
6997 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6998 == FAIL)
6999 {
7000 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
7001 return FAIL;
7002 }
7003 inst.operands[i].reg = val;
7004 inst.operands[i].isvec = 1;
7005 inst.operands[i].isscalar = 2;
7006 inst.operands[i].vectype = optype;
7007 inst.operands[i].present = 1;
7008 }
7009 else
7010 {
7011 first_error (_("VFP single, double or MVE vector register"
7012 " expected"));
7013 return FAIL;
7014 }
477330fc
RM
7015 }
7016 }
037e8744 7017 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
7018 != FAIL)
7019 {
7020 /* Case 13. */
7021 inst.operands[i].reg = val;
7022 inst.operands[i].isreg = 1;
7023 inst.operands[i].isvec = 1;
7024 inst.operands[i].issingle = 1;
7025 inst.operands[i].vectype = optype;
7026 inst.operands[i].present = 1;
7027 }
5287ad62
JB
7028 }
7029 else
7030 {
dcbf9037 7031 first_error (_("parse error"));
5287ad62
JB
7032 return FAIL;
7033 }
7034
7035 /* Successfully parsed the operands. Update args. */
7036 *which_operand = i;
7037 *str = ptr;
7038 return SUCCESS;
7039
5f4273c7 7040 wanted_comma:
dcbf9037 7041 first_error (_("expected comma"));
5287ad62 7042 return FAIL;
5f4273c7
NC
7043
7044 wanted_arm:
dcbf9037 7045 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 7046 return FAIL;
5287ad62
JB
7047}
7048
5be8be5d
DG
7049/* Use this macro when the operand constraints are different
7050 for ARM and THUMB (e.g. ldrd). */
7051#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7052 ((arm_operand) | ((thumb_operand) << 16))
7053
c19d1205
ZW
7054/* Matcher codes for parse_operands. */
7055enum operand_parse_code
7056{
7057 OP_stop, /* end of line */
7058
7059 OP_RR, /* ARM register */
7060 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 7061 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 7062 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 7063 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 7064 optional trailing ! */
c19d1205
ZW
7065 OP_RRw, /* ARM register, not r15, optional trailing ! */
7066 OP_RCP, /* Coprocessor number */
7067 OP_RCN, /* Coprocessor register */
7068 OP_RF, /* FPA register */
7069 OP_RVS, /* VFP single precision register */
5287ad62
JB
7070 OP_RVD, /* VFP double precision register (0..15) */
7071 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
7072 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7073 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7074 */
66d1f7cc
AV
7075 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7076 */
5287ad62 7077 OP_RNQ, /* Neon quad precision register */
5ee91343 7078 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 7079 OP_RVSD, /* VFP single or double precision register */
1b883319 7080 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 7081 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 7082 OP_RNSD, /* Neon single or double precision register */
5287ad62 7083 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 7084 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 7085 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 7086 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 7087 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
7088 OP_RVC, /* VFP control register */
7089 OP_RMF, /* Maverick F register */
7090 OP_RMD, /* Maverick D register */
7091 OP_RMFX, /* Maverick FX register */
7092 OP_RMDX, /* Maverick DX register */
7093 OP_RMAX, /* Maverick AX register */
7094 OP_RMDS, /* Maverick DSPSC register */
7095 OP_RIWR, /* iWMMXt wR register */
7096 OP_RIWC, /* iWMMXt wC register */
7097 OP_RIWG, /* iWMMXt wCG register */
7098 OP_RXA, /* XScale accumulator register */
7099
5aae9ae9 7100 OP_RNSDMQ, /* Neon single, double or MVE vector register */
5ee91343
AV
7101 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7102 */
7103 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7104 GPR (no SP/SP) */
a302e574 7105 OP_RMQ, /* MVE vector register. */
1b883319 7106 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 7107 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 7108
60f993ce
AV
7109 /* New operands for Armv8.1-M Mainline. */
7110 OP_LR, /* ARM LR register */
a302e574
AV
7111 OP_RRe, /* ARM register, only even numbered. */
7112 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7113 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7114 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7115
c19d1205 7116 OP_REGLST, /* ARM register list */
4b5a202f 7117 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7118 OP_VRSLST, /* VFP single-precision register list */
7119 OP_VRDLST, /* VFP double-precision register list */
037e8744 7120 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7121 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7122 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7123 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7124 OP_MSTRLST2, /* MVE vector list with two elements. */
7125 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7126
5287ad62 7127 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7128 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7129 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7130 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7131 zero. */
5287ad62 7132 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7133 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7134 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7135 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7136 */
a8465a06
AV
7137 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7138 scalar, or ARM register. */
5287ad62 7139 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7140 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7141 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7142 register. */
5d281bf0 7143 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7144 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7145 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7146 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7147 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7148 OP_RNDQMQ_Ibig,
5287ad62 7149 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7150 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7151 ARM register. */
2d447fca 7152 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7153 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7154
7155 OP_I0, /* immediate zero */
c19d1205
ZW
7156 OP_I7, /* immediate value 0 .. 7 */
7157 OP_I15, /* 0 .. 15 */
7158 OP_I16, /* 1 .. 16 */
5287ad62 7159 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7160 OP_I31, /* 0 .. 31 */
7161 OP_I31w, /* 0 .. 31, optional trailing ! */
7162 OP_I32, /* 1 .. 32 */
5287ad62 7163 OP_I32z, /* 0 .. 32 */
08132bdd 7164 OP_I48_I64, /* 48 or 64 */
5287ad62 7165 OP_I63, /* 0 .. 63 */
c19d1205 7166 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7167 OP_I64, /* 1 .. 64 */
7168 OP_I64z, /* 0 .. 64 */
5aae9ae9 7169 OP_I127, /* 0 .. 127 */
c19d1205 7170 OP_I255, /* 0 .. 255 */
4934a27c 7171 OP_I511, /* 0 .. 511 */
5aae9ae9 7172 OP_I4095, /* 0 .. 4095 */
4934a27c 7173 OP_I8191, /* 0 .. 8191 */
c19d1205
ZW
7174 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7175 OP_I7b, /* 0 .. 7 */
7176 OP_I15b, /* 0 .. 15 */
7177 OP_I31b, /* 0 .. 31 */
7178
7179 OP_SH, /* shifter operand */
4962c51a 7180 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7181 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7182 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7183 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7184 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7185 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7186 OP_EXP, /* arbitrary expression */
7187 OP_EXPi, /* same, with optional immediate prefix */
7188 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7189 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7190 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7191 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7192 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7193
7194 OP_CPSF, /* CPS flags */
7195 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7196 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7197 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7198 OP_COND, /* conditional code */
92e90b6e 7199 OP_TB, /* Table branch. */
c19d1205 7200
037e8744
JB
7201 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7202
c19d1205 7203 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7204 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7205 OP_RR_EXi, /* ARM register or expression with imm prefix */
7206 OP_RF_IF, /* FPA register or immediate */
7207 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7208 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7209
7210 /* Optional operands. */
7211 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7212 OP_oI31b, /* 0 .. 31 */
5287ad62 7213 OP_oI32b, /* 1 .. 32 */
5f1af56b 7214 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7215 OP_oIffffb, /* 0 .. 65535 */
7216 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7217
7218 OP_oRR, /* ARM register */
60f993ce 7219 OP_oLR, /* ARM LR register */
c19d1205 7220 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7221 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7222 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7223 OP_oRND, /* Optional Neon double precision register */
7224 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7225 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7226 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7227 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7228 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7229 register. */
66d1f7cc
AV
7230 OP_oRNSDMQ, /* Optional single, double register or MVE vector
7231 register. */
c19d1205
ZW
7232 OP_oSHll, /* LSL immediate */
7233 OP_oSHar, /* ASR immediate */
7234 OP_oSHllar, /* LSL or ASR immediate */
7235 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7236 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7237
1b883319
AV
7238 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7239
5be8be5d
DG
7240 /* Some pre-defined mixed (ARM/THUMB) operands. */
7241 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7242 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7243 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7244
c19d1205
ZW
7245 OP_FIRST_OPTIONAL = OP_oI7b
7246};
a737bd4d 7247
c19d1205
ZW
7248/* Generic instruction operand parser. This does no encoding and no
7249 semantic validation; it merely squirrels values away in the inst
7250 structure. Returns SUCCESS or FAIL depending on whether the
7251 specified grammar matched. */
7252static int
5be8be5d 7253parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7254{
5be8be5d 7255 unsigned const int *upat = pattern;
c19d1205
ZW
7256 char *backtrack_pos = 0;
7257 const char *backtrack_error = 0;
99aad254 7258 int i, val = 0, backtrack_index = 0;
5287ad62 7259 enum arm_reg_type rtype;
4962c51a 7260 parse_operand_result result;
5be8be5d 7261 unsigned int op_parse_code;
efd6b359 7262 bfd_boolean partial_match;
c19d1205 7263
e07e6e58
NC
7264#define po_char_or_fail(chr) \
7265 do \
7266 { \
7267 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7268 goto bad_args; \
e07e6e58
NC
7269 } \
7270 while (0)
c19d1205 7271
e07e6e58
NC
7272#define po_reg_or_fail(regtype) \
7273 do \
dcbf9037 7274 { \
e07e6e58 7275 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7276 & inst.operands[i].vectype); \
e07e6e58 7277 if (val == FAIL) \
477330fc
RM
7278 { \
7279 first_error (_(reg_expected_msgs[regtype])); \
7280 goto failure; \
7281 } \
e07e6e58
NC
7282 inst.operands[i].reg = val; \
7283 inst.operands[i].isreg = 1; \
7284 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7285 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7286 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7287 || rtype == REG_TYPE_VFD \
7288 || rtype == REG_TYPE_NQ); \
1b883319 7289 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7290 } \
e07e6e58
NC
7291 while (0)
7292
7293#define po_reg_or_goto(regtype, label) \
7294 do \
7295 { \
7296 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7297 & inst.operands[i].vectype); \
7298 if (val == FAIL) \
7299 goto label; \
dcbf9037 7300 \
e07e6e58
NC
7301 inst.operands[i].reg = val; \
7302 inst.operands[i].isreg = 1; \
7303 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7304 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7305 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7306 || rtype == REG_TYPE_VFD \
e07e6e58 7307 || rtype == REG_TYPE_NQ); \
1b883319 7308 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7309 } \
7310 while (0)
7311
7312#define po_imm_or_fail(min, max, popt) \
7313 do \
7314 { \
7315 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7316 goto failure; \
7317 inst.operands[i].imm = val; \
7318 } \
7319 while (0)
7320
08132bdd
SP
7321#define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7322 do \
7323 { \
7324 expressionS exp; \
7325 my_get_expression (&exp, &str, popt); \
7326 if (exp.X_op != O_constant) \
7327 { \
7328 inst.error = _("constant expression required"); \
7329 goto failure; \
7330 } \
7331 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7332 { \
7333 inst.error = _("immediate value 48 or 64 expected"); \
7334 goto failure; \
7335 } \
7336 inst.operands[i].imm = exp.X_add_number; \
7337 } \
7338 while (0)
7339
57785aa2 7340#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7341 do \
7342 { \
57785aa2
AV
7343 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7344 reg_type); \
e07e6e58
NC
7345 if (val == FAIL) \
7346 goto label; \
7347 inst.operands[i].reg = val; \
7348 inst.operands[i].isscalar = 1; \
7349 } \
7350 while (0)
7351
7352#define po_misc_or_fail(expr) \
7353 do \
7354 { \
7355 if (expr) \
7356 goto failure; \
7357 } \
7358 while (0)
7359
7360#define po_misc_or_fail_no_backtrack(expr) \
7361 do \
7362 { \
7363 result = expr; \
7364 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7365 backtrack_pos = 0; \
7366 if (result != PARSE_OPERAND_SUCCESS) \
7367 goto failure; \
7368 } \
7369 while (0)
4962c51a 7370
52e7f43d
RE
7371#define po_barrier_or_imm(str) \
7372 do \
7373 { \
7374 val = parse_barrier (&str); \
ccb84d65
JB
7375 if (val == FAIL && ! ISALPHA (*str)) \
7376 goto immediate; \
7377 if (val == FAIL \
7378 /* ISB can only take SY as an option. */ \
7379 || ((inst.instruction & 0xf0) == 0x60 \
7380 && val != 0xf)) \
52e7f43d 7381 { \
ccb84d65
JB
7382 inst.error = _("invalid barrier type"); \
7383 backtrack_pos = 0; \
7384 goto failure; \
52e7f43d
RE
7385 } \
7386 } \
7387 while (0)
7388
c19d1205
ZW
7389 skip_whitespace (str);
7390
7391 for (i = 0; upat[i] != OP_stop; i++)
7392 {
5be8be5d
DG
7393 op_parse_code = upat[i];
7394 if (op_parse_code >= 1<<16)
7395 op_parse_code = thumb ? (op_parse_code >> 16)
7396 : (op_parse_code & ((1<<16)-1));
7397
7398 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7399 {
7400 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7401 backtrack_pos = str;
7402 backtrack_error = inst.error;
7403 backtrack_index = i;
7404 }
7405
b6702015 7406 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7407 po_char_or_fail (',');
7408
5be8be5d 7409 switch (op_parse_code)
c19d1205
ZW
7410 {
7411 /* Registers */
7412 case OP_oRRnpc:
5be8be5d 7413 case OP_oRRnpcsp:
c19d1205 7414 case OP_RRnpc:
5be8be5d 7415 case OP_RRnpcsp:
c19d1205 7416 case OP_oRR:
a302e574
AV
7417 case OP_RRe:
7418 case OP_RRo:
60f993ce
AV
7419 case OP_LR:
7420 case OP_oLR:
c19d1205
ZW
7421 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7422 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7423 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7424 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7425 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7426 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7427 case OP_oRND:
66d1f7cc
AV
7428 case OP_RNSDMQR:
7429 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7430 break;
7431 try_rndmqr:
5ee91343
AV
7432 case OP_RNDMQR:
7433 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7434 break;
7435 try_rndmq:
7436 case OP_RNDMQ:
7437 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7438 break;
7439 try_rnd:
5287ad62 7440 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7441 case OP_RVC:
7442 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7443 break;
7444 /* Also accept generic coprocessor regs for unknown registers. */
7445 coproc_reg:
ba6cd17f
SD
7446 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7447 break;
7448 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7449 existing register with a value of 0, this seems like the
7450 best way to parse P0. */
7451 vpr_po:
7452 if (strncasecmp (str, "P0", 2) == 0)
7453 {
7454 str += 2;
7455 inst.operands[i].isreg = 1;
7456 inst.operands[i].reg = 13;
7457 }
7458 else
7459 goto failure;
cd2cf30b 7460 break;
c19d1205
ZW
7461 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7462 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7463 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7464 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7465 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7466 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7467 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7468 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7469 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7470 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7471 case OP_oRNQ:
5ee91343
AV
7472 case OP_RNQMQ:
7473 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7474 break;
7475 try_nq:
5287ad62 7476 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7477 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7478 case OP_RNDQMQR:
7479 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7480 break;
7481 try_rndqmq:
5ee91343
AV
7482 case OP_oRNDQMQ:
7483 case OP_RNDQMQ:
7484 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7485 break;
7486 try_rndq:
477330fc 7487 case OP_oRNDQ:
5287ad62 7488 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7489 case OP_RVSDMQ:
7490 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7491 break;
7492 try_rvsd:
477330fc 7493 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7494 case OP_RVSD_COND:
7495 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7496 break;
66d1f7cc 7497 case OP_oRNSDMQ:
5aae9ae9
MM
7498 case OP_RNSDMQ:
7499 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7500 break;
7501 try_mq2:
7502 po_reg_or_fail (REG_TYPE_MQ);
7503 break;
477330fc
RM
7504 case OP_oRNSDQ:
7505 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7506 case OP_RNSDQMQR:
7507 po_reg_or_goto (REG_TYPE_RN, try_mq);
7508 break;
7509 try_mq:
7510 case OP_oRNSDQMQ:
7511 case OP_RNSDQMQ:
7512 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7513 break;
7514 try_nsdq2:
7515 po_reg_or_fail (REG_TYPE_NSDQ);
7516 inst.error = 0;
7517 break;
35d1cfc2
AV
7518 case OP_RMQRR:
7519 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7520 break;
7521 try_rmq:
a302e574
AV
7522 case OP_RMQ:
7523 po_reg_or_fail (REG_TYPE_MQ);
7524 break;
477330fc
RM
7525 /* Neon scalar. Using an element size of 8 means that some invalid
7526 scalars are accepted here, so deal with those in later code. */
57785aa2 7527 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7528
7529 case OP_RNDQ_I0:
7530 {
7531 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7532 break;
7533 try_imm0:
7534 po_imm_or_fail (0, 0, TRUE);
7535 }
7536 break;
7537
7538 case OP_RVSD_I0:
7539 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7540 break;
7541
1b883319
AV
7542 case OP_RSVDMQ_FI0:
7543 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7544 break;
7545 try_rsvd_fi0:
aacf0b33
KT
7546 case OP_RSVD_FI0:
7547 {
7548 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7549 break;
7550 try_ifimm0:
7551 if (parse_ifimm_zero (&str))
7552 inst.operands[i].imm = 0;
7553 else
7554 {
7555 inst.error
7556 = _("only floating point zero is allowed as immediate value");
7557 goto failure;
7558 }
7559 }
7560 break;
7561
477330fc
RM
7562 case OP_RR_RNSC:
7563 {
57785aa2 7564 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7565 break;
7566 try_rr:
7567 po_reg_or_fail (REG_TYPE_RN);
7568 }
7569 break;
7570
a8465a06
AV
7571 case OP_RNSDQ_RNSC_MQ_RR:
7572 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7573 break;
7574 try_rnsdq_rnsc_mq:
886e1c73
AV
7575 case OP_RNSDQ_RNSC_MQ:
7576 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7577 break;
7578 try_rnsdq_rnsc:
477330fc
RM
7579 case OP_RNSDQ_RNSC:
7580 {
57785aa2
AV
7581 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7582 inst.error = 0;
477330fc
RM
7583 break;
7584 try_nsdq:
7585 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7586 inst.error = 0;
477330fc
RM
7587 }
7588 break;
7589
dec41383
JW
7590 case OP_RNSD_RNSC:
7591 {
57785aa2 7592 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7593 break;
7594 try_s_scalar:
57785aa2 7595 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7596 break;
7597 try_nsd:
7598 po_reg_or_fail (REG_TYPE_NSD);
7599 }
7600 break;
7601
42b16635
AV
7602 case OP_RNDQMQ_RNSC_RR:
7603 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7604 break;
7605 try_rndq_rnsc_rr:
7606 case OP_RNDQ_RNSC_RR:
7607 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7608 break;
5d281bf0
AV
7609 case OP_RNDQMQ_RNSC:
7610 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7611 break;
7612 try_rndq_rnsc:
477330fc
RM
7613 case OP_RNDQ_RNSC:
7614 {
57785aa2 7615 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7616 break;
7617 try_ndq:
7618 po_reg_or_fail (REG_TYPE_NDQ);
7619 }
7620 break;
7621
7622 case OP_RND_RNSC:
7623 {
57785aa2 7624 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7625 break;
7626 try_vfd:
7627 po_reg_or_fail (REG_TYPE_VFD);
7628 }
7629 break;
7630
7631 case OP_VMOV:
7632 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7633 not careful then bad things might happen. */
7634 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7635 break;
7636
f601a00c
AV
7637 case OP_RNDQMQ_Ibig:
7638 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7639 break;
7640 try_rndq_ibig:
477330fc
RM
7641 case OP_RNDQ_Ibig:
7642 {
7643 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7644 break;
7645 try_immbig:
7646 /* There's a possibility of getting a 64-bit immediate here, so
7647 we need special handling. */
8335d6aa
JW
7648 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7649 == FAIL)
477330fc
RM
7650 {
7651 inst.error = _("immediate value is out of range");
7652 goto failure;
7653 }
7654 }
7655 break;
7656
5150f0d8
AV
7657 case OP_RNDQMQ_I63b_RR:
7658 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7659 break;
7660 try_rndq_i63b_rr:
7661 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7662 break;
7663 try_rndq_i63b:
477330fc
RM
7664 case OP_RNDQ_I63b:
7665 {
7666 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7667 break;
7668 try_shimm:
7669 po_imm_or_fail (0, 63, TRUE);
7670 }
7671 break;
c19d1205
ZW
7672
7673 case OP_RRnpcb:
7674 po_char_or_fail ('[');
7675 po_reg_or_fail (REG_TYPE_RN);
7676 po_char_or_fail (']');
7677 break;
a737bd4d 7678
55881a11 7679 case OP_RRnpctw:
c19d1205 7680 case OP_RRw:
b6702015 7681 case OP_oRRw:
c19d1205
ZW
7682 po_reg_or_fail (REG_TYPE_RN);
7683 if (skip_past_char (&str, '!') == SUCCESS)
7684 inst.operands[i].writeback = 1;
7685 break;
7686
7687 /* Immediates */
7688 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7689 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7690 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7691 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7692 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7693 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7694 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
08132bdd 7695 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
c19d1205 7696 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7697 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7698 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7699 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5aae9ae9 7700 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
c19d1205 7701 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
4934a27c 7702 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
5aae9ae9 7703 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
4934a27c 7704 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
c19d1205
ZW
7705 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7706 case OP_oI7b:
7707 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7708 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7709 case OP_oI31b:
7710 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7711 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7712 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7713 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7714
7715 /* Immediate variants */
7716 case OP_oI255c:
7717 po_char_or_fail ('{');
7718 po_imm_or_fail (0, 255, TRUE);
7719 po_char_or_fail ('}');
7720 break;
7721
7722 case OP_I31w:
7723 /* The expression parser chokes on a trailing !, so we have
7724 to find it first and zap it. */
7725 {
7726 char *s = str;
7727 while (*s && *s != ',')
7728 s++;
7729 if (s[-1] == '!')
7730 {
7731 s[-1] = '\0';
7732 inst.operands[i].writeback = 1;
7733 }
7734 po_imm_or_fail (0, 31, TRUE);
7735 if (str == s - 1)
7736 str = s;
7737 }
7738 break;
7739
7740 /* Expressions */
7741 case OP_EXPi: EXPi:
e2b0ab59 7742 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7743 GE_OPT_PREFIX));
7744 break;
7745
7746 case OP_EXP:
e2b0ab59 7747 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7748 GE_NO_PREFIX));
7749 break;
7750
7751 case OP_EXPr: EXPr:
e2b0ab59 7752 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7753 GE_NO_PREFIX));
e2b0ab59 7754 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7755 {
c19d1205
ZW
7756 val = parse_reloc (&str);
7757 if (val == -1)
7758 {
7759 inst.error = _("unrecognized relocation suffix");
7760 goto failure;
7761 }
7762 else if (val != BFD_RELOC_UNUSED)
7763 {
7764 inst.operands[i].imm = val;
7765 inst.operands[i].hasreloc = 1;
7766 }
a737bd4d 7767 }
c19d1205 7768 break;
a737bd4d 7769
e2b0ab59
AV
7770 case OP_EXPs:
7771 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7772 GE_NO_PREFIX));
7773 if (inst.relocs[i].exp.X_op == O_symbol)
7774 {
7775 inst.operands[i].hasreloc = 1;
7776 }
7777 else if (inst.relocs[i].exp.X_op == O_constant)
7778 {
7779 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7780 inst.operands[i].hasreloc = 0;
7781 }
7782 break;
7783
b6895b4f
PB
7784 /* Operand for MOVW or MOVT. */
7785 case OP_HALF:
7786 po_misc_or_fail (parse_half (&str));
7787 break;
7788
e07e6e58 7789 /* Register or expression. */
c19d1205
ZW
7790 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7791 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7792
e07e6e58 7793 /* Register or immediate. */
c19d1205
ZW
7794 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7795 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7796
23d00a41
SD
7797 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7798 I32: po_imm_or_fail (1, 32, FALSE); break;
7799
c19d1205
ZW
7800 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7801 IF:
7802 if (!is_immediate_prefix (*str))
7803 goto bad_args;
7804 str++;
7805 val = parse_fpa_immediate (&str);
7806 if (val == FAIL)
7807 goto failure;
7808 /* FPA immediates are encoded as registers 8-15.
7809 parse_fpa_immediate has already applied the offset. */
7810 inst.operands[i].reg = val;
7811 inst.operands[i].isreg = 1;
7812 break;
09d92015 7813
2d447fca
JM
7814 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7815 I32z: po_imm_or_fail (0, 32, FALSE); break;
7816
e07e6e58 7817 /* Two kinds of register. */
c19d1205
ZW
7818 case OP_RIWR_RIWC:
7819 {
7820 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7821 if (!rege
7822 || (rege->type != REG_TYPE_MMXWR
7823 && rege->type != REG_TYPE_MMXWC
7824 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7825 {
7826 inst.error = _("iWMMXt data or control register expected");
7827 goto failure;
7828 }
7829 inst.operands[i].reg = rege->number;
7830 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7831 }
7832 break;
09d92015 7833
41adaa5c
JM
7834 case OP_RIWC_RIWG:
7835 {
7836 struct reg_entry *rege = arm_reg_parse_multi (&str);
7837 if (!rege
7838 || (rege->type != REG_TYPE_MMXWC
7839 && rege->type != REG_TYPE_MMXWCG))
7840 {
7841 inst.error = _("iWMMXt control register expected");
7842 goto failure;
7843 }
7844 inst.operands[i].reg = rege->number;
7845 inst.operands[i].isreg = 1;
7846 }
7847 break;
7848
c19d1205
ZW
7849 /* Misc */
7850 case OP_CPSF: val = parse_cps_flags (&str); break;
7851 case OP_ENDI: val = parse_endian_specifier (&str); break;
7852 case OP_oROR: val = parse_ror (&str); break;
1b883319 7853 try_cond:
c19d1205 7854 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7855 case OP_oBARRIER_I15:
7856 po_barrier_or_imm (str); break;
7857 immediate:
7858 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7859 goto failure;
52e7f43d 7860 break;
c19d1205 7861
fa94de6b 7862 case OP_wPSR:
d2cd1205 7863 case OP_rPSR:
90ec0d68
MGD
7864 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7865 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7866 {
7867 inst.error = _("Banked registers are not available with this "
7868 "architecture.");
7869 goto failure;
7870 }
7871 break;
d2cd1205
JB
7872 try_psr:
7873 val = parse_psr (&str, op_parse_code == OP_wPSR);
7874 break;
037e8744 7875
32c36c3c
AV
7876 case OP_VLDR:
7877 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7878 break;
7879 try_sysreg:
7880 val = parse_sys_vldr_vstr (&str);
7881 break;
7882
477330fc
RM
7883 case OP_APSR_RR:
7884 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7885 break;
7886 try_apsr:
7887 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7888 instruction). */
7889 if (strncasecmp (str, "APSR_", 5) == 0)
7890 {
7891 unsigned found = 0;
7892 str += 5;
7893 while (found < 15)
7894 switch (*str++)
7895 {
7896 case 'c': found = (found & 1) ? 16 : found | 1; break;
7897 case 'n': found = (found & 2) ? 16 : found | 2; break;
7898 case 'z': found = (found & 4) ? 16 : found | 4; break;
7899 case 'v': found = (found & 8) ? 16 : found | 8; break;
7900 default: found = 16;
7901 }
7902 if (found != 15)
7903 goto failure;
7904 inst.operands[i].isvec = 1;
f7c21dc7
NC
7905 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7906 inst.operands[i].reg = REG_PC;
477330fc
RM
7907 }
7908 else
7909 goto failure;
7910 break;
037e8744 7911
92e90b6e
PB
7912 case OP_TB:
7913 po_misc_or_fail (parse_tb (&str));
7914 break;
7915
e07e6e58 7916 /* Register lists. */
c19d1205 7917 case OP_REGLST:
4b5a202f 7918 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7919 if (*str == '^')
7920 {
5e0d7f77 7921 inst.operands[i].writeback = 1;
c19d1205
ZW
7922 str++;
7923 }
7924 break;
09d92015 7925
4b5a202f
AV
7926 case OP_CLRMLST:
7927 val = parse_reg_list (&str, REGLIST_CLRM);
7928 break;
7929
c19d1205 7930 case OP_VRSLST:
efd6b359
AV
7931 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7932 &partial_match);
c19d1205 7933 break;
09d92015 7934
c19d1205 7935 case OP_VRDLST:
efd6b359
AV
7936 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7937 &partial_match);
c19d1205 7938 break;
a737bd4d 7939
477330fc
RM
7940 case OP_VRSDLST:
7941 /* Allow Q registers too. */
7942 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7943 REGLIST_NEON_D, &partial_match);
477330fc
RM
7944 if (val == FAIL)
7945 {
7946 inst.error = NULL;
7947 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7948 REGLIST_VFP_S, &partial_match);
7949 inst.operands[i].issingle = 1;
7950 }
7951 break;
7952
7953 case OP_VRSDVLST:
7954 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7955 REGLIST_VFP_D_VPR, &partial_match);
7956 if (val == FAIL && !partial_match)
7957 {
7958 inst.error = NULL;
7959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7960 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7961 inst.operands[i].issingle = 1;
7962 }
7963 break;
7964
7965 case OP_NRDLST:
7966 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7967 REGLIST_NEON_D, &partial_match);
477330fc 7968 break;
5287ad62 7969
35c228db
AV
7970 case OP_MSTRLST4:
7971 case OP_MSTRLST2:
7972 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7973 1, &inst.operands[i].vectype);
7974 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7975 goto failure;
7976 break;
5287ad62 7977 case OP_NSTRLST:
477330fc 7978 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7979 0, &inst.operands[i].vectype);
477330fc 7980 break;
5287ad62 7981
c19d1205 7982 /* Addressing modes */
35c228db
AV
7983 case OP_ADDRMVE:
7984 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7985 break;
7986
c19d1205
ZW
7987 case OP_ADDR:
7988 po_misc_or_fail (parse_address (&str, i));
7989 break;
09d92015 7990
4962c51a
MS
7991 case OP_ADDRGLDR:
7992 po_misc_or_fail_no_backtrack (
477330fc 7993 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7994 break;
7995
7996 case OP_ADDRGLDRS:
7997 po_misc_or_fail_no_backtrack (
477330fc 7998 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7999 break;
8000
8001 case OP_ADDRGLDC:
8002 po_misc_or_fail_no_backtrack (
477330fc 8003 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
8004 break;
8005
c19d1205
ZW
8006 case OP_SH:
8007 po_misc_or_fail (parse_shifter_operand (&str, i));
8008 break;
09d92015 8009
4962c51a
MS
8010 case OP_SHG:
8011 po_misc_or_fail_no_backtrack (
477330fc 8012 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
8013 break;
8014
c19d1205
ZW
8015 case OP_oSHll:
8016 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8017 break;
09d92015 8018
c19d1205
ZW
8019 case OP_oSHar:
8020 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8021 break;
09d92015 8022
c19d1205
ZW
8023 case OP_oSHllar:
8024 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8025 break;
09d92015 8026
1b883319
AV
8027 case OP_RMQRZ:
8028 case OP_oRMQRZ:
8029 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8030 break;
e39c1607
SD
8031
8032 case OP_RR_ZR:
1b883319
AV
8033 try_rr_zr:
8034 po_reg_or_goto (REG_TYPE_RN, ZR);
8035 break;
8036 ZR:
8037 po_reg_or_fail (REG_TYPE_ZR);
8038 break;
8039
c19d1205 8040 default:
5be8be5d 8041 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 8042 }
09d92015 8043
c19d1205
ZW
8044 /* Various value-based sanity checks and shared operations. We
8045 do not signal immediate failures for the register constraints;
8046 this allows a syntax error to take precedence. */
5be8be5d 8047 switch (op_parse_code)
c19d1205
ZW
8048 {
8049 case OP_oRRnpc:
8050 case OP_RRnpc:
8051 case OP_RRnpcb:
8052 case OP_RRw:
b6702015 8053 case OP_oRRw:
c19d1205
ZW
8054 case OP_RRnpc_I0:
8055 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8056 inst.error = BAD_PC;
8057 break;
09d92015 8058
5be8be5d
DG
8059 case OP_oRRnpcsp:
8060 case OP_RRnpcsp:
23d00a41 8061 case OP_RRnpcsp_I32:
5be8be5d
DG
8062 if (inst.operands[i].isreg)
8063 {
8064 if (inst.operands[i].reg == REG_PC)
8065 inst.error = BAD_PC;
5c8ed6a4
JW
8066 else if (inst.operands[i].reg == REG_SP
8067 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8068 relaxed since ARMv8-A. */
8069 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8070 {
8071 gas_assert (thumb);
8072 inst.error = BAD_SP;
8073 }
5be8be5d
DG
8074 }
8075 break;
8076
55881a11 8077 case OP_RRnpctw:
fa94de6b
RM
8078 if (inst.operands[i].isreg
8079 && inst.operands[i].reg == REG_PC
55881a11
MGD
8080 && (inst.operands[i].writeback || thumb))
8081 inst.error = BAD_PC;
8082 break;
8083
1b883319 8084 case OP_RVSD_COND:
32c36c3c
AV
8085 case OP_VLDR:
8086 if (inst.operands[i].isreg)
8087 break;
8088 /* fall through. */
1b883319 8089
c19d1205
ZW
8090 case OP_CPSF:
8091 case OP_ENDI:
8092 case OP_oROR:
d2cd1205
JB
8093 case OP_wPSR:
8094 case OP_rPSR:
c19d1205 8095 case OP_COND:
52e7f43d 8096 case OP_oBARRIER_I15:
c19d1205 8097 case OP_REGLST:
4b5a202f 8098 case OP_CLRMLST:
c19d1205
ZW
8099 case OP_VRSLST:
8100 case OP_VRDLST:
477330fc 8101 case OP_VRSDLST:
efd6b359 8102 case OP_VRSDVLST:
477330fc
RM
8103 case OP_NRDLST:
8104 case OP_NSTRLST:
35c228db
AV
8105 case OP_MSTRLST2:
8106 case OP_MSTRLST4:
c19d1205
ZW
8107 if (val == FAIL)
8108 goto failure;
8109 inst.operands[i].imm = val;
8110 break;
a737bd4d 8111
60f993ce
AV
8112 case OP_LR:
8113 case OP_oLR:
8114 if (inst.operands[i].reg != REG_LR)
8115 inst.error = _("operand must be LR register");
8116 break;
8117
1b883319
AV
8118 case OP_RMQRZ:
8119 case OP_oRMQRZ:
e39c1607 8120 case OP_RR_ZR:
1b883319
AV
8121 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8122 inst.error = BAD_PC;
8123 break;
8124
a302e574
AV
8125 case OP_RRe:
8126 if (inst.operands[i].isreg
8127 && (inst.operands[i].reg & 0x00000001) != 0)
8128 inst.error = BAD_ODD;
8129 break;
8130
8131 case OP_RRo:
8132 if (inst.operands[i].isreg)
8133 {
8134 if ((inst.operands[i].reg & 0x00000001) != 1)
8135 inst.error = BAD_EVEN;
8136 else if (inst.operands[i].reg == REG_SP)
8137 as_tsktsk (MVE_BAD_SP);
8138 else if (inst.operands[i].reg == REG_PC)
8139 inst.error = BAD_PC;
8140 }
8141 break;
8142
c19d1205
ZW
8143 default:
8144 break;
8145 }
09d92015 8146
c19d1205
ZW
8147 /* If we get here, this operand was successfully parsed. */
8148 inst.operands[i].present = 1;
8149 continue;
09d92015 8150
c19d1205 8151 bad_args:
09d92015 8152 inst.error = BAD_ARGS;
c19d1205
ZW
8153
8154 failure:
8155 if (!backtrack_pos)
d252fdde
PB
8156 {
8157 /* The parse routine should already have set inst.error, but set a
5f4273c7 8158 default here just in case. */
d252fdde 8159 if (!inst.error)
5ee91343 8160 inst.error = BAD_SYNTAX;
d252fdde
PB
8161 return FAIL;
8162 }
c19d1205
ZW
8163
8164 /* Do not backtrack over a trailing optional argument that
8165 absorbed some text. We will only fail again, with the
8166 'garbage following instruction' error message, which is
8167 probably less helpful than the current one. */
8168 if (backtrack_index == i && backtrack_pos != str
8169 && upat[i+1] == OP_stop)
d252fdde
PB
8170 {
8171 if (!inst.error)
5ee91343 8172 inst.error = BAD_SYNTAX;
d252fdde
PB
8173 return FAIL;
8174 }
c19d1205
ZW
8175
8176 /* Try again, skipping the optional argument at backtrack_pos. */
8177 str = backtrack_pos;
8178 inst.error = backtrack_error;
8179 inst.operands[backtrack_index].present = 0;
8180 i = backtrack_index;
8181 backtrack_pos = 0;
09d92015 8182 }
09d92015 8183
c19d1205
ZW
8184 /* Check that we have parsed all the arguments. */
8185 if (*str != '\0' && !inst.error)
8186 inst.error = _("garbage following instruction");
09d92015 8187
c19d1205 8188 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8189}
8190
c19d1205
ZW
8191#undef po_char_or_fail
8192#undef po_reg_or_fail
8193#undef po_reg_or_goto
8194#undef po_imm_or_fail
5287ad62 8195#undef po_scalar_or_fail
52e7f43d 8196#undef po_barrier_or_imm
e07e6e58 8197
c19d1205 8198/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8199#define constraint(expr, err) \
8200 do \
c19d1205 8201 { \
e07e6e58
NC
8202 if (expr) \
8203 { \
8204 inst.error = err; \
8205 return; \
8206 } \
c19d1205 8207 } \
e07e6e58 8208 while (0)
c19d1205 8209
fdfde340
JM
8210/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8211 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8212 is the BadReg predicate in ARM's Thumb-2 documentation.
8213
8214 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8215 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8216#define reject_bad_reg(reg) \
8217 do \
8218 if (reg == REG_PC) \
8219 { \
8220 inst.error = BAD_PC; \
8221 return; \
8222 } \
8223 else if (reg == REG_SP \
8224 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8225 { \
8226 inst.error = BAD_SP; \
8227 return; \
8228 } \
fdfde340
JM
8229 while (0)
8230
94206790
MM
8231/* If REG is R13 (the stack pointer), warn that its use is
8232 deprecated. */
8233#define warn_deprecated_sp(reg) \
8234 do \
8235 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8236 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8237 while (0)
8238
c19d1205
ZW
8239/* Functions for operand encoding. ARM, then Thumb. */
8240
d840c081 8241#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8242
9db2f6b4
RL
8243/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8244
8245 The only binary encoding difference is the Coprocessor number. Coprocessor
8246 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8247 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8248 exists for Single-Precision operation. */
8249
8250static void
8251do_scalar_fp16_v82_encode (void)
8252{
5ee91343 8253 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8254 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8255 " the behaviour is UNPREDICTABLE"));
8256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8257 _(BAD_FP16));
8258
8259 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8260 mark_feature_used (&arm_ext_fp16);
8261}
8262
c19d1205
ZW
8263/* If VAL can be encoded in the immediate field of an ARM instruction,
8264 return the encoded form. Otherwise, return FAIL. */
8265
8266static unsigned int
8267encode_arm_immediate (unsigned int val)
09d92015 8268{
c19d1205
ZW
8269 unsigned int a, i;
8270
4f1d6205
L
8271 if (val <= 0xff)
8272 return val;
8273
8274 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8275 if ((a = rotate_left (val, i)) <= 0xff)
8276 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8277
8278 return FAIL;
09d92015
MM
8279}
8280
c19d1205
ZW
8281/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8282 return the encoded form. Otherwise, return FAIL. */
8283static unsigned int
8284encode_thumb32_immediate (unsigned int val)
09d92015 8285{
c19d1205 8286 unsigned int a, i;
09d92015 8287
9c3c69f2 8288 if (val <= 0xff)
c19d1205 8289 return val;
a737bd4d 8290
9c3c69f2 8291 for (i = 1; i <= 24; i++)
09d92015 8292 {
9c3c69f2
PB
8293 a = val >> i;
8294 if ((val & ~(0xff << i)) == 0)
8295 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8296 }
a737bd4d 8297
c19d1205
ZW
8298 a = val & 0xff;
8299 if (val == ((a << 16) | a))
8300 return 0x100 | a;
8301 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8302 return 0x300 | a;
09d92015 8303
c19d1205
ZW
8304 a = val & 0xff00;
8305 if (val == ((a << 16) | a))
8306 return 0x200 | (a >> 8);
a737bd4d 8307
c19d1205 8308 return FAIL;
09d92015 8309}
5287ad62 8310/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8311
8312static void
5287ad62
JB
8313encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8314{
8315 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8316 && reg > 15)
8317 {
b1cc4aeb 8318 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8319 {
8320 if (thumb_mode)
8321 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8322 fpu_vfp_ext_d32);
8323 else
8324 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8325 fpu_vfp_ext_d32);
8326 }
5287ad62 8327 else
477330fc
RM
8328 {
8329 first_error (_("D register out of range for selected VFP version"));
8330 return;
8331 }
5287ad62
JB
8332 }
8333
c19d1205 8334 switch (pos)
09d92015 8335 {
c19d1205
ZW
8336 case VFP_REG_Sd:
8337 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8338 break;
8339
8340 case VFP_REG_Sn:
8341 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8342 break;
8343
8344 case VFP_REG_Sm:
8345 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8346 break;
8347
5287ad62
JB
8348 case VFP_REG_Dd:
8349 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8350 break;
5f4273c7 8351
5287ad62
JB
8352 case VFP_REG_Dn:
8353 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8354 break;
5f4273c7 8355
5287ad62
JB
8356 case VFP_REG_Dm:
8357 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8358 break;
8359
c19d1205
ZW
8360 default:
8361 abort ();
09d92015 8362 }
09d92015
MM
8363}
8364
c19d1205 8365/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8366 if any, is handled by md_apply_fix. */
09d92015 8367static void
c19d1205 8368encode_arm_shift (int i)
09d92015 8369{
008a97ef
RL
8370 /* register-shifted register. */
8371 if (inst.operands[i].immisreg)
8372 {
bf355b69
MR
8373 int op_index;
8374 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8375 {
5689c942
RL
8376 /* Check the operand only when it's presented. In pre-UAL syntax,
8377 if the destination register is the same as the first operand, two
8378 register form of the instruction can be used. */
bf355b69
MR
8379 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8380 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8381 as_warn (UNPRED_REG ("r15"));
8382 }
8383
8384 if (inst.operands[i].imm == REG_PC)
8385 as_warn (UNPRED_REG ("r15"));
8386 }
8387
c19d1205
ZW
8388 if (inst.operands[i].shift_kind == SHIFT_RRX)
8389 inst.instruction |= SHIFT_ROR << 5;
8390 else
09d92015 8391 {
c19d1205
ZW
8392 inst.instruction |= inst.operands[i].shift_kind << 5;
8393 if (inst.operands[i].immisreg)
8394 {
8395 inst.instruction |= SHIFT_BY_REG;
8396 inst.instruction |= inst.operands[i].imm << 8;
8397 }
8398 else
e2b0ab59 8399 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8400 }
c19d1205 8401}
09d92015 8402
c19d1205
ZW
8403static void
8404encode_arm_shifter_operand (int i)
8405{
8406 if (inst.operands[i].isreg)
09d92015 8407 {
c19d1205
ZW
8408 inst.instruction |= inst.operands[i].reg;
8409 encode_arm_shift (i);
09d92015 8410 }
c19d1205 8411 else
a415b1cd
JB
8412 {
8413 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8414 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8415 inst.instruction |= inst.operands[i].imm;
8416 }
09d92015
MM
8417}
8418
c19d1205 8419/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8420static void
c19d1205 8421encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8422{
2b2f5df9
NC
8423 /* PR 14260:
8424 Generate an error if the operand is not a register. */
8425 constraint (!inst.operands[i].isreg,
8426 _("Instruction does not support =N addresses"));
8427
c19d1205 8428 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8429
c19d1205 8430 if (inst.operands[i].preind)
09d92015 8431 {
c19d1205
ZW
8432 if (is_t)
8433 {
8434 inst.error = _("instruction does not accept preindexed addressing");
8435 return;
8436 }
8437 inst.instruction |= PRE_INDEX;
8438 if (inst.operands[i].writeback)
8439 inst.instruction |= WRITE_BACK;
09d92015 8440
c19d1205
ZW
8441 }
8442 else if (inst.operands[i].postind)
8443 {
9c2799c2 8444 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8445 if (is_t)
8446 inst.instruction |= WRITE_BACK;
8447 }
8448 else /* unindexed - only for coprocessor */
09d92015 8449 {
c19d1205 8450 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8451 return;
8452 }
8453
c19d1205
ZW
8454 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8455 && (((inst.instruction & 0x000f0000) >> 16)
8456 == ((inst.instruction & 0x0000f000) >> 12)))
8457 as_warn ((inst.instruction & LOAD_BIT)
8458 ? _("destination register same as write-back base")
8459 : _("source register same as write-back base"));
09d92015
MM
8460}
8461
c19d1205
ZW
8462/* inst.operands[i] was set up by parse_address. Encode it into an
8463 ARM-format mode 2 load or store instruction. If is_t is true,
8464 reject forms that cannot be used with a T instruction (i.e. not
8465 post-indexed). */
a737bd4d 8466static void
c19d1205 8467encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8468{
5be8be5d
DG
8469 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8470
c19d1205 8471 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8472
c19d1205 8473 if (inst.operands[i].immisreg)
09d92015 8474 {
5be8be5d
DG
8475 constraint ((inst.operands[i].imm == REG_PC
8476 || (is_pc && inst.operands[i].writeback)),
8477 BAD_PC_ADDRESSING);
c19d1205
ZW
8478 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8479 inst.instruction |= inst.operands[i].imm;
8480 if (!inst.operands[i].negative)
8481 inst.instruction |= INDEX_UP;
8482 if (inst.operands[i].shifted)
8483 {
8484 if (inst.operands[i].shift_kind == SHIFT_RRX)
8485 inst.instruction |= SHIFT_ROR << 5;
8486 else
8487 {
8488 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8489 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8490 }
8491 }
09d92015 8492 }
e2b0ab59 8493 else /* immediate offset in inst.relocs[0] */
09d92015 8494 {
e2b0ab59 8495 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8496 {
8497 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8498
8499 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8500 cannot use PC in addressing.
8501 PC cannot be used in writeback addressing, either. */
8502 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8503 BAD_PC_ADDRESSING);
23a10334 8504
dc5ec521 8505 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8506 if (warn_on_deprecated
8507 && !is_load
8508 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8509 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8510 }
8511
e2b0ab59 8512 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8513 {
8514 /* Prefer + for zero encoded value. */
8515 if (!inst.operands[i].negative)
8516 inst.instruction |= INDEX_UP;
e2b0ab59 8517 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8518 }
09d92015 8519 }
09d92015
MM
8520}
8521
c19d1205
ZW
8522/* inst.operands[i] was set up by parse_address. Encode it into an
8523 ARM-format mode 3 load or store instruction. Reject forms that
8524 cannot be used with such instructions. If is_t is true, reject
8525 forms that cannot be used with a T instruction (i.e. not
8526 post-indexed). */
8527static void
8528encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8529{
c19d1205 8530 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8531 {
c19d1205
ZW
8532 inst.error = _("instruction does not accept scaled register index");
8533 return;
09d92015 8534 }
a737bd4d 8535
c19d1205 8536 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8537
c19d1205
ZW
8538 if (inst.operands[i].immisreg)
8539 {
5be8be5d 8540 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8541 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8542 BAD_PC_ADDRESSING);
eb9f3f00
JB
8543 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8544 BAD_PC_WRITEBACK);
c19d1205
ZW
8545 inst.instruction |= inst.operands[i].imm;
8546 if (!inst.operands[i].negative)
8547 inst.instruction |= INDEX_UP;
8548 }
e2b0ab59 8549 else /* immediate offset in inst.relocs[0] */
c19d1205 8550 {
e2b0ab59 8551 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8552 && inst.operands[i].writeback),
8553 BAD_PC_WRITEBACK);
c19d1205 8554 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8555 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8556 {
8557 /* Prefer + for zero encoded value. */
8558 if (!inst.operands[i].negative)
8559 inst.instruction |= INDEX_UP;
8560
e2b0ab59 8561 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8562 }
c19d1205 8563 }
a737bd4d
NC
8564}
8565
8335d6aa
JW
8566/* Write immediate bits [7:0] to the following locations:
8567
8568 |28/24|23 19|18 16|15 4|3 0|
8569 | 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|
8570
8571 This function is used by VMOV/VMVN/VORR/VBIC. */
8572
8573static void
8574neon_write_immbits (unsigned immbits)
8575{
8576 inst.instruction |= immbits & 0xf;
8577 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8578 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8579}
8580
8581/* Invert low-order SIZE bits of XHI:XLO. */
8582
8583static void
8584neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8585{
8586 unsigned immlo = xlo ? *xlo : 0;
8587 unsigned immhi = xhi ? *xhi : 0;
8588
8589 switch (size)
8590 {
8591 case 8:
8592 immlo = (~immlo) & 0xff;
8593 break;
8594
8595 case 16:
8596 immlo = (~immlo) & 0xffff;
8597 break;
8598
8599 case 64:
8600 immhi = (~immhi) & 0xffffffff;
8601 /* fall through. */
8602
8603 case 32:
8604 immlo = (~immlo) & 0xffffffff;
8605 break;
8606
8607 default:
8608 abort ();
8609 }
8610
8611 if (xlo)
8612 *xlo = immlo;
8613
8614 if (xhi)
8615 *xhi = immhi;
8616}
8617
8618/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8619 A, B, C, D. */
09d92015 8620
c19d1205 8621static int
8335d6aa 8622neon_bits_same_in_bytes (unsigned imm)
09d92015 8623{
8335d6aa
JW
8624 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8625 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8626 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8627 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8628}
a737bd4d 8629
8335d6aa 8630/* For immediate of above form, return 0bABCD. */
09d92015 8631
8335d6aa
JW
8632static unsigned
8633neon_squash_bits (unsigned imm)
8634{
8635 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8636 | ((imm & 0x01000000) >> 21);
8637}
8638
8639/* Compress quarter-float representation to 0b...000 abcdefgh. */
8640
8641static unsigned
8642neon_qfloat_bits (unsigned imm)
8643{
8644 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8645}
8646
8647/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8648 the instruction. *OP is passed as the initial value of the op field, and
8649 may be set to a different value depending on the constant (i.e.
8650 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8651 MVN). If the immediate looks like a repeated pattern then also
8652 try smaller element sizes. */
8653
8654static int
8655neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8656 unsigned *immbits, int *op, int size,
8657 enum neon_el_type type)
8658{
8659 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8660 float. */
8661 if (type == NT_float && !float_p)
8662 return FAIL;
8663
8664 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8665 {
8335d6aa
JW
8666 if (size != 32 || *op == 1)
8667 return FAIL;
8668 *immbits = neon_qfloat_bits (immlo);
8669 return 0xf;
8670 }
8671
8672 if (size == 64)
8673 {
8674 if (neon_bits_same_in_bytes (immhi)
8675 && neon_bits_same_in_bytes (immlo))
c19d1205 8676 {
8335d6aa
JW
8677 if (*op == 1)
8678 return FAIL;
8679 *immbits = (neon_squash_bits (immhi) << 4)
8680 | neon_squash_bits (immlo);
8681 *op = 1;
8682 return 0xe;
c19d1205 8683 }
a737bd4d 8684
8335d6aa
JW
8685 if (immhi != immlo)
8686 return FAIL;
8687 }
a737bd4d 8688
8335d6aa 8689 if (size >= 32)
09d92015 8690 {
8335d6aa 8691 if (immlo == (immlo & 0x000000ff))
c19d1205 8692 {
8335d6aa
JW
8693 *immbits = immlo;
8694 return 0x0;
c19d1205 8695 }
8335d6aa 8696 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8697 {
8335d6aa
JW
8698 *immbits = immlo >> 8;
8699 return 0x2;
c19d1205 8700 }
8335d6aa
JW
8701 else if (immlo == (immlo & 0x00ff0000))
8702 {
8703 *immbits = immlo >> 16;
8704 return 0x4;
8705 }
8706 else if (immlo == (immlo & 0xff000000))
8707 {
8708 *immbits = immlo >> 24;
8709 return 0x6;
8710 }
8711 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8712 {
8713 *immbits = (immlo >> 8) & 0xff;
8714 return 0xc;
8715 }
8716 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8717 {
8718 *immbits = (immlo >> 16) & 0xff;
8719 return 0xd;
8720 }
8721
8722 if ((immlo & 0xffff) != (immlo >> 16))
8723 return FAIL;
8724 immlo &= 0xffff;
09d92015 8725 }
a737bd4d 8726
8335d6aa 8727 if (size >= 16)
4962c51a 8728 {
8335d6aa
JW
8729 if (immlo == (immlo & 0x000000ff))
8730 {
8731 *immbits = immlo;
8732 return 0x8;
8733 }
8734 else if (immlo == (immlo & 0x0000ff00))
8735 {
8736 *immbits = immlo >> 8;
8737 return 0xa;
8738 }
8739
8740 if ((immlo & 0xff) != (immlo >> 8))
8741 return FAIL;
8742 immlo &= 0xff;
4962c51a
MS
8743 }
8744
8335d6aa
JW
8745 if (immlo == (immlo & 0x000000ff))
8746 {
8747 /* Don't allow MVN with 8-bit immediate. */
8748 if (*op == 1)
8749 return FAIL;
8750 *immbits = immlo;
8751 return 0xe;
8752 }
26d97720 8753
8335d6aa 8754 return FAIL;
c19d1205 8755}
a737bd4d 8756
5fc177c8 8757#if defined BFD_HOST_64_BIT
ba592044
AM
8758/* Returns TRUE if double precision value V may be cast
8759 to single precision without loss of accuracy. */
8760
8761static bfd_boolean
5fc177c8 8762is_double_a_single (bfd_int64_t v)
ba592044 8763{
5fc177c8 8764 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8765 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8766
8767 return (exp == 0 || exp == 0x7FF
8768 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8769 && (mantissa & 0x1FFFFFFFl) == 0;
8770}
8771
3739860c 8772/* Returns a double precision value casted to single precision
ba592044
AM
8773 (ignoring the least significant bits in exponent and mantissa). */
8774
8775static int
5fc177c8 8776double_to_single (bfd_int64_t v)
ba592044
AM
8777{
8778 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8779 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8780 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8781
8782 if (exp == 0x7FF)
8783 exp = 0xFF;
8784 else
8785 {
8786 exp = exp - 1023 + 127;
8787 if (exp >= 0xFF)
8788 {
8789 /* Infinity. */
8790 exp = 0x7F;
8791 mantissa = 0;
8792 }
8793 else if (exp < 0)
8794 {
8795 /* No denormalized numbers. */
8796 exp = 0;
8797 mantissa = 0;
8798 }
8799 }
8800 mantissa >>= 29;
8801 return (sign << 31) | (exp << 23) | mantissa;
8802}
5fc177c8 8803#endif /* BFD_HOST_64_BIT */
ba592044 8804
8335d6aa
JW
8805enum lit_type
8806{
8807 CONST_THUMB,
8808 CONST_ARM,
8809 CONST_VEC
8810};
8811
ba592044
AM
8812static void do_vfp_nsyn_opcode (const char *);
8813
e2b0ab59 8814/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8815 Determine whether it can be performed with a move instruction; if
8816 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8817 return TRUE; if it can't, convert inst.instruction to a literal-pool
8818 load and return FALSE. If this is not a valid thing to do in the
8819 current context, set inst.error and return TRUE.
a737bd4d 8820
c19d1205
ZW
8821 inst.operands[i] describes the destination register. */
8822
c921be7d 8823static bfd_boolean
8335d6aa 8824move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8825{
53365c0d 8826 unsigned long tbit;
8335d6aa
JW
8827 bfd_boolean thumb_p = (t == CONST_THUMB);
8828 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8829
8830 if (thumb_p)
8831 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8832 else
8833 tbit = LOAD_BIT;
8834
8835 if ((inst.instruction & tbit) == 0)
09d92015 8836 {
c19d1205 8837 inst.error = _("invalid pseudo operation");
c921be7d 8838 return TRUE;
09d92015 8839 }
ba592044 8840
e2b0ab59
AV
8841 if (inst.relocs[0].exp.X_op != O_constant
8842 && inst.relocs[0].exp.X_op != O_symbol
8843 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8844 {
8845 inst.error = _("constant expression expected");
c921be7d 8846 return TRUE;
09d92015 8847 }
ba592044 8848
e2b0ab59
AV
8849 if (inst.relocs[0].exp.X_op == O_constant
8850 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8851 {
5fc177c8
NC
8852#if defined BFD_HOST_64_BIT
8853 bfd_int64_t v;
8854#else
ba592044 8855 offsetT v;
5fc177c8 8856#endif
e2b0ab59 8857 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8858 {
ba592044
AM
8859 LITTLENUM_TYPE w[X_PRECISION];
8860 LITTLENUM_TYPE * l;
8861
e2b0ab59 8862 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8863 {
ba592044
AM
8864 gen_to_words (w, X_PRECISION, E_PRECISION);
8865 l = w;
8866 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8867 }
ba592044
AM
8868 else
8869 l = generic_bignum;
3739860c 8870
5fc177c8
NC
8871#if defined BFD_HOST_64_BIT
8872 v =
8873 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8874 << LITTLENUM_NUMBER_OF_BITS)
8875 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8876 << LITTLENUM_NUMBER_OF_BITS)
8877 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8878 << LITTLENUM_NUMBER_OF_BITS)
8879 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8880#else
ba592044
AM
8881 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8882 | (l[0] & LITTLENUM_MASK);
5fc177c8 8883#endif
8335d6aa 8884 }
ba592044 8885 else
e2b0ab59 8886 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8887
8888 if (!inst.operands[i].issingle)
8335d6aa 8889 {
12569877 8890 if (thumb_p)
8335d6aa 8891 {
53445554
TP
8892 /* LDR should not use lead in a flag-setting instruction being
8893 chosen so we do not check whether movs can be used. */
12569877 8894
53445554 8895 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8896 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8897 && inst.operands[i].reg != 13
8898 && inst.operands[i].reg != 15)
12569877 8899 {
fc289b0a
TP
8900 /* Check if on thumb2 it can be done with a mov.w, mvn or
8901 movw instruction. */
12569877
AM
8902 unsigned int newimm;
8903 bfd_boolean isNegated;
8904
8905 newimm = encode_thumb32_immediate (v);
8906 if (newimm != (unsigned int) FAIL)
8907 isNegated = FALSE;
8908 else
8909 {
582cfe03 8910 newimm = encode_thumb32_immediate (~v);
12569877
AM
8911 if (newimm != (unsigned int) FAIL)
8912 isNegated = TRUE;
8913 }
8914
fc289b0a
TP
8915 /* The number can be loaded with a mov.w or mvn
8916 instruction. */
ff8646ee
TP
8917 if (newimm != (unsigned int) FAIL
8918 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8919 {
fc289b0a 8920 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8921 | (inst.operands[i].reg << 8));
fc289b0a 8922 /* Change to MOVN. */
582cfe03 8923 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8924 inst.instruction |= (newimm & 0x800) << 15;
8925 inst.instruction |= (newimm & 0x700) << 4;
8926 inst.instruction |= (newimm & 0x0ff);
8927 return TRUE;
8928 }
fc289b0a 8929 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8930 else if ((v & ~0xFFFF) == 0
8931 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8932 {
582cfe03 8933 int imm = v & 0xFFFF;
12569877 8934
582cfe03 8935 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8936 inst.instruction |= (inst.operands[i].reg << 8);
8937 inst.instruction |= (imm & 0xf000) << 4;
8938 inst.instruction |= (imm & 0x0800) << 15;
8939 inst.instruction |= (imm & 0x0700) << 4;
8940 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8941 /* In case this replacement is being done on Armv8-M
8942 Baseline we need to make sure to disable the
8943 instruction size check, as otherwise GAS will reject
8944 the use of this T32 instruction. */
8945 inst.size_req = 0;
12569877
AM
8946 return TRUE;
8947 }
8948 }
8335d6aa 8949 }
12569877 8950 else if (arm_p)
ba592044
AM
8951 {
8952 int value = encode_arm_immediate (v);
12569877 8953
ba592044
AM
8954 if (value != FAIL)
8955 {
8956 /* This can be done with a mov instruction. */
8957 inst.instruction &= LITERAL_MASK;
8958 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8959 inst.instruction |= value & 0xfff;
8960 return TRUE;
8961 }
8335d6aa 8962
ba592044
AM
8963 value = encode_arm_immediate (~ v);
8964 if (value != FAIL)
8965 {
8966 /* This can be done with a mvn instruction. */
8967 inst.instruction &= LITERAL_MASK;
8968 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8969 inst.instruction |= value & 0xfff;
8970 return TRUE;
8971 }
8972 }
934c2632 8973 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8974 {
ba592044
AM
8975 int op = 0;
8976 unsigned immbits = 0;
8977 unsigned immlo = inst.operands[1].imm;
8978 unsigned immhi = inst.operands[1].regisimm
8979 ? inst.operands[1].reg
e2b0ab59 8980 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8981 ? 0
8982 : ((bfd_int64_t)((int) immlo)) >> 32;
8983 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8984 &op, 64, NT_invtype);
8985
8986 if (cmode == FAIL)
8987 {
8988 neon_invert_size (&immlo, &immhi, 64);
8989 op = !op;
8990 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8991 &op, 64, NT_invtype);
8992 }
8993
8994 if (cmode != FAIL)
8995 {
8996 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8997 | (1 << 23)
8998 | (cmode << 8)
8999 | (op << 5)
9000 | (1 << 4);
9001
9002 /* Fill other bits in vmov encoding for both thumb and arm. */
9003 if (thumb_mode)
eff0bc54 9004 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 9005 else
eff0bc54 9006 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
9007 neon_write_immbits (immbits);
9008 return TRUE;
9009 }
8335d6aa
JW
9010 }
9011 }
8335d6aa 9012
ba592044
AM
9013 if (t == CONST_VEC)
9014 {
9015 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9016 if (inst.operands[i].issingle
9017 && is_quarter_float (inst.operands[1].imm)
9018 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 9019 {
ba592044
AM
9020 inst.operands[1].imm =
9021 neon_qfloat_bits (v);
9022 do_vfp_nsyn_opcode ("fconsts");
9023 return TRUE;
8335d6aa 9024 }
5fc177c8
NC
9025
9026 /* If our host does not support a 64-bit type then we cannot perform
9027 the following optimization. This mean that there will be a
9028 discrepancy between the output produced by an assembler built for
9029 a 32-bit-only host and the output produced from a 64-bit host, but
9030 this cannot be helped. */
9031#if defined BFD_HOST_64_BIT
ba592044
AM
9032 else if (!inst.operands[1].issingle
9033 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 9034 {
ba592044
AM
9035 if (is_double_a_single (v)
9036 && is_quarter_float (double_to_single (v)))
9037 {
9038 inst.operands[1].imm =
9039 neon_qfloat_bits (double_to_single (v));
9040 do_vfp_nsyn_opcode ("fconstd");
9041 return TRUE;
9042 }
8335d6aa 9043 }
5fc177c8 9044#endif
8335d6aa
JW
9045 }
9046 }
9047
9048 if (add_to_lit_pool ((!inst.operands[i].isvec
9049 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9050 return TRUE;
9051
9052 inst.operands[1].reg = REG_PC;
9053 inst.operands[1].isreg = 1;
9054 inst.operands[1].preind = 1;
e2b0ab59
AV
9055 inst.relocs[0].pc_rel = 1;
9056 inst.relocs[0].type = (thumb_p
8335d6aa
JW
9057 ? BFD_RELOC_ARM_THUMB_OFFSET
9058 : (mode_3
9059 ? BFD_RELOC_ARM_HWLITERAL
9060 : BFD_RELOC_ARM_LITERAL));
9061 return FALSE;
9062}
9063
9064/* inst.operands[i] was set up by parse_address. Encode it into an
9065 ARM-format instruction. Reject all forms which cannot be encoded
9066 into a coprocessor load/store instruction. If wb_ok is false,
9067 reject use of writeback; if unind_ok is false, reject use of
9068 unindexed addressing. If reloc_override is not 0, use it instead
9069 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9070 (in which case it is preserved). */
9071
9072static int
9073encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9074{
9075 if (!inst.operands[i].isreg)
9076 {
99b2a2dd
NC
9077 /* PR 18256 */
9078 if (! inst.operands[0].isvec)
9079 {
9080 inst.error = _("invalid co-processor operand");
9081 return FAIL;
9082 }
8335d6aa
JW
9083 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9084 return SUCCESS;
9085 }
9086
9087 inst.instruction |= inst.operands[i].reg << 16;
9088
9089 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9090
9091 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9092 {
9093 gas_assert (!inst.operands[i].writeback);
9094 if (!unind_ok)
9095 {
9096 inst.error = _("instruction does not support unindexed addressing");
9097 return FAIL;
9098 }
9099 inst.instruction |= inst.operands[i].imm;
9100 inst.instruction |= INDEX_UP;
9101 return SUCCESS;
9102 }
9103
9104 if (inst.operands[i].preind)
9105 inst.instruction |= PRE_INDEX;
9106
9107 if (inst.operands[i].writeback)
09d92015 9108 {
8335d6aa 9109 if (inst.operands[i].reg == REG_PC)
c19d1205 9110 {
8335d6aa
JW
9111 inst.error = _("pc may not be used with write-back");
9112 return FAIL;
c19d1205 9113 }
8335d6aa 9114 if (!wb_ok)
c19d1205 9115 {
8335d6aa
JW
9116 inst.error = _("instruction does not support writeback");
9117 return FAIL;
c19d1205 9118 }
8335d6aa 9119 inst.instruction |= WRITE_BACK;
09d92015
MM
9120 }
9121
8335d6aa 9122 if (reloc_override)
e2b0ab59
AV
9123 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9124 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9125 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9126 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 9127 {
8335d6aa 9128 if (thumb_mode)
e2b0ab59 9129 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 9130 else
e2b0ab59 9131 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 9132 }
8335d6aa
JW
9133
9134 /* Prefer + for zero encoded value. */
9135 if (!inst.operands[i].negative)
9136 inst.instruction |= INDEX_UP;
9137
9138 return SUCCESS;
09d92015
MM
9139}
9140
5f4273c7 9141/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
9142 First some generics; their names are taken from the conventional
9143 bit positions for register arguments in ARM format instructions. */
09d92015 9144
a737bd4d 9145static void
c19d1205 9146do_noargs (void)
09d92015 9147{
c19d1205 9148}
a737bd4d 9149
c19d1205
ZW
9150static void
9151do_rd (void)
9152{
9153 inst.instruction |= inst.operands[0].reg << 12;
9154}
a737bd4d 9155
16a1fa25
TP
9156static void
9157do_rn (void)
9158{
9159 inst.instruction |= inst.operands[0].reg << 16;
9160}
9161
c19d1205
ZW
9162static void
9163do_rd_rm (void)
9164{
9165 inst.instruction |= inst.operands[0].reg << 12;
9166 inst.instruction |= inst.operands[1].reg;
9167}
09d92015 9168
9eb6c0f1
MGD
9169static void
9170do_rm_rn (void)
9171{
9172 inst.instruction |= inst.operands[0].reg;
9173 inst.instruction |= inst.operands[1].reg << 16;
9174}
9175
c19d1205
ZW
9176static void
9177do_rd_rn (void)
9178{
9179 inst.instruction |= inst.operands[0].reg << 12;
9180 inst.instruction |= inst.operands[1].reg << 16;
9181}
a737bd4d 9182
c19d1205
ZW
9183static void
9184do_rn_rd (void)
9185{
9186 inst.instruction |= inst.operands[0].reg << 16;
9187 inst.instruction |= inst.operands[1].reg << 12;
9188}
09d92015 9189
4ed7ed8d
TP
9190static void
9191do_tt (void)
9192{
9193 inst.instruction |= inst.operands[0].reg << 8;
9194 inst.instruction |= inst.operands[1].reg << 16;
9195}
9196
59d09be6
MGD
9197static bfd_boolean
9198check_obsolete (const arm_feature_set *feature, const char *msg)
9199{
9200 if (ARM_CPU_IS_ANY (cpu_variant))
9201 {
5c3696f8 9202 as_tsktsk ("%s", msg);
59d09be6
MGD
9203 return TRUE;
9204 }
9205 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9206 {
9207 as_bad ("%s", msg);
9208 return TRUE;
9209 }
9210
9211 return FALSE;
9212}
9213
c19d1205
ZW
9214static void
9215do_rd_rm_rn (void)
9216{
9a64e435 9217 unsigned Rn = inst.operands[2].reg;
708587a4 9218 /* Enforce restrictions on SWP instruction. */
9a64e435 9219 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9220 {
9221 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9222 _("Rn must not overlap other operands"));
9223
59d09be6
MGD
9224 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9225 */
9226 if (!check_obsolete (&arm_ext_v8,
9227 _("swp{b} use is obsoleted for ARMv8 and later"))
9228 && warn_on_deprecated
9229 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9230 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9231 }
59d09be6 9232
c19d1205
ZW
9233 inst.instruction |= inst.operands[0].reg << 12;
9234 inst.instruction |= inst.operands[1].reg;
9a64e435 9235 inst.instruction |= Rn << 16;
c19d1205 9236}
09d92015 9237
c19d1205
ZW
9238static void
9239do_rd_rn_rm (void)
9240{
9241 inst.instruction |= inst.operands[0].reg << 12;
9242 inst.instruction |= inst.operands[1].reg << 16;
9243 inst.instruction |= inst.operands[2].reg;
9244}
a737bd4d 9245
c19d1205
ZW
9246static void
9247do_rm_rd_rn (void)
9248{
5be8be5d 9249 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9250 constraint (((inst.relocs[0].exp.X_op != O_constant
9251 && inst.relocs[0].exp.X_op != O_illegal)
9252 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9253 BAD_ADDR_MODE);
c19d1205
ZW
9254 inst.instruction |= inst.operands[0].reg;
9255 inst.instruction |= inst.operands[1].reg << 12;
9256 inst.instruction |= inst.operands[2].reg << 16;
9257}
09d92015 9258
c19d1205
ZW
9259static void
9260do_imm0 (void)
9261{
9262 inst.instruction |= inst.operands[0].imm;
9263}
09d92015 9264
c19d1205
ZW
9265static void
9266do_rd_cpaddr (void)
9267{
9268 inst.instruction |= inst.operands[0].reg << 12;
9269 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9270}
a737bd4d 9271
c19d1205
ZW
9272/* ARM instructions, in alphabetical order by function name (except
9273 that wrapper functions appear immediately after the function they
9274 wrap). */
09d92015 9275
c19d1205
ZW
9276/* This is a pseudo-op of the form "adr rd, label" to be converted
9277 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9278
9279static void
c19d1205 9280do_adr (void)
09d92015 9281{
c19d1205 9282 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9283
c19d1205
ZW
9284 /* Frag hacking will turn this into a sub instruction if the offset turns
9285 out to be negative. */
e2b0ab59
AV
9286 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9287 inst.relocs[0].pc_rel = 1;
9288 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9289
fc6141f0 9290 if (support_interwork
e2b0ab59
AV
9291 && inst.relocs[0].exp.X_op == O_symbol
9292 && inst.relocs[0].exp.X_add_symbol != NULL
9293 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9294 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9295 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9296}
b99bd4ef 9297
c19d1205
ZW
9298/* This is a pseudo-op of the form "adrl rd, label" to be converted
9299 into a relative address of the form:
9300 add rd, pc, #low(label-.-8)"
9301 add rd, rd, #high(label-.-8)" */
b99bd4ef 9302
c19d1205
ZW
9303static void
9304do_adrl (void)
9305{
9306 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9307
c19d1205
ZW
9308 /* Frag hacking will turn this into a sub instruction if the offset turns
9309 out to be negative. */
e2b0ab59
AV
9310 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9311 inst.relocs[0].pc_rel = 1;
c19d1205 9312 inst.size = INSN_SIZE * 2;
e2b0ab59 9313 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9314
fc6141f0 9315 if (support_interwork
e2b0ab59
AV
9316 && inst.relocs[0].exp.X_op == O_symbol
9317 && inst.relocs[0].exp.X_add_symbol != NULL
9318 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9319 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9320 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9321}
9322
b99bd4ef 9323static void
c19d1205 9324do_arit (void)
b99bd4ef 9325{
e2b0ab59
AV
9326 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9327 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9328 THUMB1_RELOC_ONLY);
c19d1205
ZW
9329 if (!inst.operands[1].present)
9330 inst.operands[1].reg = inst.operands[0].reg;
9331 inst.instruction |= inst.operands[0].reg << 12;
9332 inst.instruction |= inst.operands[1].reg << 16;
9333 encode_arm_shifter_operand (2);
9334}
b99bd4ef 9335
62b3e311
PB
9336static void
9337do_barrier (void)
9338{
9339 if (inst.operands[0].present)
ccb84d65 9340 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9341 else
9342 inst.instruction |= 0xf;
9343}
9344
c19d1205
ZW
9345static void
9346do_bfc (void)
9347{
9348 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9349 constraint (msb > 32, _("bit-field extends past end of register"));
9350 /* The instruction encoding stores the LSB and MSB,
9351 not the LSB and width. */
9352 inst.instruction |= inst.operands[0].reg << 12;
9353 inst.instruction |= inst.operands[1].imm << 7;
9354 inst.instruction |= (msb - 1) << 16;
9355}
b99bd4ef 9356
c19d1205
ZW
9357static void
9358do_bfi (void)
9359{
9360 unsigned int msb;
b99bd4ef 9361
c19d1205
ZW
9362 /* #0 in second position is alternative syntax for bfc, which is
9363 the same instruction but with REG_PC in the Rm field. */
9364 if (!inst.operands[1].isreg)
9365 inst.operands[1].reg = REG_PC;
b99bd4ef 9366
c19d1205
ZW
9367 msb = inst.operands[2].imm + inst.operands[3].imm;
9368 constraint (msb > 32, _("bit-field extends past end of register"));
9369 /* The instruction encoding stores the LSB and MSB,
9370 not the LSB and width. */
9371 inst.instruction |= inst.operands[0].reg << 12;
9372 inst.instruction |= inst.operands[1].reg;
9373 inst.instruction |= inst.operands[2].imm << 7;
9374 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9375}
9376
b99bd4ef 9377static void
c19d1205 9378do_bfx (void)
b99bd4ef 9379{
c19d1205
ZW
9380 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9381 _("bit-field extends past end of register"));
9382 inst.instruction |= inst.operands[0].reg << 12;
9383 inst.instruction |= inst.operands[1].reg;
9384 inst.instruction |= inst.operands[2].imm << 7;
9385 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9386}
09d92015 9387
c19d1205
ZW
9388/* ARM V5 breakpoint instruction (argument parse)
9389 BKPT <16 bit unsigned immediate>
9390 Instruction is not conditional.
9391 The bit pattern given in insns[] has the COND_ALWAYS condition,
9392 and it is an error if the caller tried to override that. */
b99bd4ef 9393
c19d1205
ZW
9394static void
9395do_bkpt (void)
9396{
9397 /* Top 12 of 16 bits to bits 19:8. */
9398 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9399
c19d1205
ZW
9400 /* Bottom 4 of 16 bits to bits 3:0. */
9401 inst.instruction |= inst.operands[0].imm & 0xf;
9402}
09d92015 9403
c19d1205
ZW
9404static void
9405encode_branch (int default_reloc)
9406{
9407 if (inst.operands[0].hasreloc)
9408 {
0855e32b
NS
9409 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9410 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9411 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9412 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9413 ? BFD_RELOC_ARM_PLT32
9414 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9415 }
b99bd4ef 9416 else
e2b0ab59
AV
9417 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9418 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9419}
9420
b99bd4ef 9421static void
c19d1205 9422do_branch (void)
b99bd4ef 9423{
39b41c9c
PB
9424#ifdef OBJ_ELF
9425 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9426 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9427 else
9428#endif
9429 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9430}
9431
9432static void
9433do_bl (void)
9434{
9435#ifdef OBJ_ELF
9436 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9437 {
9438 if (inst.cond == COND_ALWAYS)
9439 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9440 else
9441 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9442 }
9443 else
9444#endif
9445 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9446}
b99bd4ef 9447
c19d1205
ZW
9448/* ARM V5 branch-link-exchange instruction (argument parse)
9449 BLX <target_addr> ie BLX(1)
9450 BLX{<condition>} <Rm> ie BLX(2)
9451 Unfortunately, there are two different opcodes for this mnemonic.
9452 So, the insns[].value is not used, and the code here zaps values
9453 into inst.instruction.
9454 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9455
c19d1205
ZW
9456static void
9457do_blx (void)
9458{
9459 if (inst.operands[0].isreg)
b99bd4ef 9460 {
c19d1205
ZW
9461 /* Arg is a register; the opcode provided by insns[] is correct.
9462 It is not illegal to do "blx pc", just useless. */
9463 if (inst.operands[0].reg == REG_PC)
9464 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9465
c19d1205
ZW
9466 inst.instruction |= inst.operands[0].reg;
9467 }
9468 else
b99bd4ef 9469 {
c19d1205 9470 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9471 conditionally, and the opcode must be adjusted.
9472 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9473 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9474 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9475 inst.instruction = 0xfa000000;
267bf995 9476 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9477 }
c19d1205
ZW
9478}
9479
9480static void
9481do_bx (void)
9482{
845b51d6
PB
9483 bfd_boolean want_reloc;
9484
c19d1205
ZW
9485 if (inst.operands[0].reg == REG_PC)
9486 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9487
c19d1205 9488 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9489 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9490 it is for ARMv4t or earlier. */
9491 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9492 if (!ARM_FEATURE_ZERO (selected_object_arch)
9493 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9494 want_reloc = TRUE;
9495
5ad34203 9496#ifdef OBJ_ELF
845b51d6 9497 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9498#endif
584206db 9499 want_reloc = FALSE;
845b51d6
PB
9500
9501 if (want_reloc)
e2b0ab59 9502 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9503}
9504
c19d1205
ZW
9505
9506/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9507
9508static void
c19d1205 9509do_bxj (void)
a737bd4d 9510{
c19d1205
ZW
9511 if (inst.operands[0].reg == REG_PC)
9512 as_tsktsk (_("use of r15 in bxj is not really useful"));
9513
9514 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9515}
9516
c19d1205
ZW
9517/* Co-processor data operation:
9518 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9519 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9520static void
9521do_cdp (void)
9522{
9523 inst.instruction |= inst.operands[0].reg << 8;
9524 inst.instruction |= inst.operands[1].imm << 20;
9525 inst.instruction |= inst.operands[2].reg << 12;
9526 inst.instruction |= inst.operands[3].reg << 16;
9527 inst.instruction |= inst.operands[4].reg;
9528 inst.instruction |= inst.operands[5].imm << 5;
9529}
a737bd4d
NC
9530
9531static void
c19d1205 9532do_cmp (void)
a737bd4d 9533{
c19d1205
ZW
9534 inst.instruction |= inst.operands[0].reg << 16;
9535 encode_arm_shifter_operand (1);
a737bd4d
NC
9536}
9537
c19d1205
ZW
9538/* Transfer between coprocessor and ARM registers.
9539 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9540 MRC2
9541 MCR{cond}
9542 MCR2
9543
9544 No special properties. */
09d92015 9545
dcbd0d71
MGD
9546struct deprecated_coproc_regs_s
9547{
9548 unsigned cp;
9549 int opc1;
9550 unsigned crn;
9551 unsigned crm;
9552 int opc2;
9553 arm_feature_set deprecated;
9554 arm_feature_set obsoleted;
9555 const char *dep_msg;
9556 const char *obs_msg;
9557};
9558
9559#define DEPR_ACCESS_V8 \
9560 N_("This coprocessor register access is deprecated in ARMv8")
9561
9562/* Table of all deprecated coprocessor registers. */
9563static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9564{
9565 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9566 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9567 DEPR_ACCESS_V8, NULL},
9568 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9569 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9570 DEPR_ACCESS_V8, NULL},
9571 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9572 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9573 DEPR_ACCESS_V8, NULL},
9574 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9575 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9576 DEPR_ACCESS_V8, NULL},
9577 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9578 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9579 DEPR_ACCESS_V8, NULL},
9580};
9581
9582#undef DEPR_ACCESS_V8
9583
9584static const size_t deprecated_coproc_reg_count =
9585 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9586
09d92015 9587static void
c19d1205 9588do_co_reg (void)
09d92015 9589{
fdfde340 9590 unsigned Rd;
dcbd0d71 9591 size_t i;
fdfde340
JM
9592
9593 Rd = inst.operands[2].reg;
9594 if (thumb_mode)
9595 {
9596 if (inst.instruction == 0xee000010
9597 || inst.instruction == 0xfe000010)
9598 /* MCR, MCR2 */
9599 reject_bad_reg (Rd);
5c8ed6a4 9600 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9601 /* MRC, MRC2 */
9602 constraint (Rd == REG_SP, BAD_SP);
9603 }
9604 else
9605 {
9606 /* MCR */
9607 if (inst.instruction == 0xe000010)
9608 constraint (Rd == REG_PC, BAD_PC);
9609 }
9610
dcbd0d71
MGD
9611 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9612 {
9613 const struct deprecated_coproc_regs_s *r =
9614 deprecated_coproc_regs + i;
9615
9616 if (inst.operands[0].reg == r->cp
9617 && inst.operands[1].imm == r->opc1
9618 && inst.operands[3].reg == r->crn
9619 && inst.operands[4].reg == r->crm
9620 && inst.operands[5].imm == r->opc2)
9621 {
b10bf8c5 9622 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9623 && warn_on_deprecated
dcbd0d71 9624 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9625 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9626 }
9627 }
fdfde340 9628
c19d1205
ZW
9629 inst.instruction |= inst.operands[0].reg << 8;
9630 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9631 inst.instruction |= Rd << 12;
c19d1205
ZW
9632 inst.instruction |= inst.operands[3].reg << 16;
9633 inst.instruction |= inst.operands[4].reg;
9634 inst.instruction |= inst.operands[5].imm << 5;
9635}
09d92015 9636
c19d1205
ZW
9637/* Transfer between coprocessor register and pair of ARM registers.
9638 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9639 MCRR2
9640 MRRC{cond}
9641 MRRC2
b99bd4ef 9642
c19d1205 9643 Two XScale instructions are special cases of these:
09d92015 9644
c19d1205
ZW
9645 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9646 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9647
5f4273c7 9648 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9649
c19d1205
ZW
9650static void
9651do_co_reg2c (void)
9652{
fdfde340
JM
9653 unsigned Rd, Rn;
9654
9655 Rd = inst.operands[2].reg;
9656 Rn = inst.operands[3].reg;
9657
9658 if (thumb_mode)
9659 {
9660 reject_bad_reg (Rd);
9661 reject_bad_reg (Rn);
9662 }
9663 else
9664 {
9665 constraint (Rd == REG_PC, BAD_PC);
9666 constraint (Rn == REG_PC, BAD_PC);
9667 }
9668
873f10f0
TC
9669 /* Only check the MRRC{2} variants. */
9670 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9671 {
9672 /* If Rd == Rn, error that the operation is
9673 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9674 constraint (Rd == Rn, BAD_OVERLAP);
9675 }
9676
c19d1205
ZW
9677 inst.instruction |= inst.operands[0].reg << 8;
9678 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9679 inst.instruction |= Rd << 12;
9680 inst.instruction |= Rn << 16;
c19d1205 9681 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9682}
9683
c19d1205
ZW
9684static void
9685do_cpsi (void)
9686{
9687 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9688 if (inst.operands[1].present)
9689 {
9690 inst.instruction |= CPSI_MMOD;
9691 inst.instruction |= inst.operands[1].imm;
9692 }
c19d1205 9693}
b99bd4ef 9694
62b3e311
PB
9695static void
9696do_dbg (void)
9697{
9698 inst.instruction |= inst.operands[0].imm;
9699}
9700
eea54501
MGD
9701static void
9702do_div (void)
9703{
9704 unsigned Rd, Rn, Rm;
9705
9706 Rd = inst.operands[0].reg;
9707 Rn = (inst.operands[1].present
9708 ? inst.operands[1].reg : Rd);
9709 Rm = inst.operands[2].reg;
9710
9711 constraint ((Rd == REG_PC), BAD_PC);
9712 constraint ((Rn == REG_PC), BAD_PC);
9713 constraint ((Rm == REG_PC), BAD_PC);
9714
9715 inst.instruction |= Rd << 16;
9716 inst.instruction |= Rn << 0;
9717 inst.instruction |= Rm << 8;
9718}
9719
b99bd4ef 9720static void
c19d1205 9721do_it (void)
b99bd4ef 9722{
c19d1205 9723 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9724 process it to do the validation as if in
9725 thumb mode, just in case the code gets
9726 assembled for thumb using the unified syntax. */
9727
c19d1205 9728 inst.size = 0;
e07e6e58
NC
9729 if (unified_syntax)
9730 {
5ee91343
AV
9731 set_pred_insn_type (IT_INSN);
9732 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9733 now_pred.cc = inst.operands[0].imm;
e07e6e58 9734 }
09d92015 9735}
b99bd4ef 9736
6530b175
NC
9737/* If there is only one register in the register list,
9738 then return its register number. Otherwise return -1. */
9739static int
9740only_one_reg_in_list (int range)
9741{
9742 int i = ffs (range) - 1;
9743 return (i > 15 || range != (1 << i)) ? -1 : i;
9744}
9745
09d92015 9746static void
6530b175 9747encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9748{
c19d1205
ZW
9749 int base_reg = inst.operands[0].reg;
9750 int range = inst.operands[1].imm;
6530b175 9751 int one_reg;
ea6ef066 9752
c19d1205
ZW
9753 inst.instruction |= base_reg << 16;
9754 inst.instruction |= range;
ea6ef066 9755
c19d1205
ZW
9756 if (inst.operands[1].writeback)
9757 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9758
c19d1205 9759 if (inst.operands[0].writeback)
ea6ef066 9760 {
c19d1205
ZW
9761 inst.instruction |= WRITE_BACK;
9762 /* Check for unpredictable uses of writeback. */
9763 if (inst.instruction & LOAD_BIT)
09d92015 9764 {
c19d1205
ZW
9765 /* Not allowed in LDM type 2. */
9766 if ((inst.instruction & LDM_TYPE_2_OR_3)
9767 && ((range & (1 << REG_PC)) == 0))
9768 as_warn (_("writeback of base register is UNPREDICTABLE"));
9769 /* Only allowed if base reg not in list for other types. */
9770 else if (range & (1 << base_reg))
9771 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9772 }
9773 else /* STM. */
9774 {
9775 /* Not allowed for type 2. */
9776 if (inst.instruction & LDM_TYPE_2_OR_3)
9777 as_warn (_("writeback of base register is UNPREDICTABLE"));
9778 /* Only allowed if base reg not in list, or first in list. */
9779 else if ((range & (1 << base_reg))
9780 && (range & ((1 << base_reg) - 1)))
9781 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9782 }
ea6ef066 9783 }
6530b175
NC
9784
9785 /* If PUSH/POP has only one register, then use the A2 encoding. */
9786 one_reg = only_one_reg_in_list (range);
9787 if (from_push_pop_mnem && one_reg >= 0)
9788 {
9789 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9790
4f588891
NC
9791 if (is_push && one_reg == 13 /* SP */)
9792 /* PR 22483: The A2 encoding cannot be used when
9793 pushing the stack pointer as this is UNPREDICTABLE. */
9794 return;
9795
6530b175
NC
9796 inst.instruction &= A_COND_MASK;
9797 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9798 inst.instruction |= one_reg << 12;
9799 }
9800}
9801
9802static void
9803do_ldmstm (void)
9804{
9805 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9806}
9807
c19d1205
ZW
9808/* ARMv5TE load-consecutive (argument parse)
9809 Mode is like LDRH.
9810
9811 LDRccD R, mode
9812 STRccD R, mode. */
9813
a737bd4d 9814static void
c19d1205 9815do_ldrd (void)
a737bd4d 9816{
c19d1205 9817 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9818 _("first transfer register must be even"));
c19d1205
ZW
9819 constraint (inst.operands[1].present
9820 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9821 _("can only transfer two consecutive registers"));
c19d1205
ZW
9822 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9823 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9824
c19d1205
ZW
9825 if (!inst.operands[1].present)
9826 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9827
c56791bb
RE
9828 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9829 register and the first register written; we have to diagnose
9830 overlap between the base and the second register written here. */
ea6ef066 9831
c56791bb
RE
9832 if (inst.operands[2].reg == inst.operands[1].reg
9833 && (inst.operands[2].writeback || inst.operands[2].postind))
9834 as_warn (_("base register written back, and overlaps "
9835 "second transfer register"));
b05fe5cf 9836
c56791bb
RE
9837 if (!(inst.instruction & V4_STR_BIT))
9838 {
c19d1205 9839 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9840 destination (even if not write-back). */
9841 if (inst.operands[2].immisreg
9842 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9843 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9844 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9845 }
c19d1205
ZW
9846 inst.instruction |= inst.operands[0].reg << 12;
9847 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9848}
9849
9850static void
c19d1205 9851do_ldrex (void)
b05fe5cf 9852{
c19d1205
ZW
9853 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9854 || inst.operands[1].postind || inst.operands[1].writeback
9855 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9856 || inst.operands[1].negative
9857 /* This can arise if the programmer has written
9858 strex rN, rM, foo
9859 or if they have mistakenly used a register name as the last
9860 operand, eg:
9861 strex rN, rM, rX
9862 It is very difficult to distinguish between these two cases
9863 because "rX" might actually be a label. ie the register
9864 name has been occluded by a symbol of the same name. So we
9865 just generate a general 'bad addressing mode' type error
9866 message and leave it up to the programmer to discover the
9867 true cause and fix their mistake. */
9868 || (inst.operands[1].reg == REG_PC),
9869 BAD_ADDR_MODE);
b05fe5cf 9870
e2b0ab59
AV
9871 constraint (inst.relocs[0].exp.X_op != O_constant
9872 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9873 _("offset must be zero in ARM encoding"));
b05fe5cf 9874
5be8be5d
DG
9875 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9876
c19d1205
ZW
9877 inst.instruction |= inst.operands[0].reg << 12;
9878 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9879 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9880}
9881
9882static void
c19d1205 9883do_ldrexd (void)
b05fe5cf 9884{
c19d1205
ZW
9885 constraint (inst.operands[0].reg % 2 != 0,
9886 _("even register required"));
9887 constraint (inst.operands[1].present
9888 && inst.operands[1].reg != inst.operands[0].reg + 1,
9889 _("can only load two consecutive registers"));
9890 /* If op 1 were present and equal to PC, this function wouldn't
9891 have been called in the first place. */
9892 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9893
c19d1205
ZW
9894 inst.instruction |= inst.operands[0].reg << 12;
9895 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9896}
9897
1be5fd2e
NC
9898/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9899 which is not a multiple of four is UNPREDICTABLE. */
9900static void
9901check_ldr_r15_aligned (void)
9902{
9903 constraint (!(inst.operands[1].immisreg)
9904 && (inst.operands[0].reg == REG_PC
9905 && inst.operands[1].reg == REG_PC
e2b0ab59 9906 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9907 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9908}
9909
b05fe5cf 9910static void
c19d1205 9911do_ldst (void)
b05fe5cf 9912{
c19d1205
ZW
9913 inst.instruction |= inst.operands[0].reg << 12;
9914 if (!inst.operands[1].isreg)
8335d6aa 9915 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9916 return;
c19d1205 9917 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9918 check_ldr_r15_aligned ();
b05fe5cf
ZW
9919}
9920
9921static void
c19d1205 9922do_ldstt (void)
b05fe5cf 9923{
c19d1205
ZW
9924 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9925 reject [Rn,...]. */
9926 if (inst.operands[1].preind)
b05fe5cf 9927 {
e2b0ab59
AV
9928 constraint (inst.relocs[0].exp.X_op != O_constant
9929 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9930 _("this instruction requires a post-indexed address"));
b05fe5cf 9931
c19d1205
ZW
9932 inst.operands[1].preind = 0;
9933 inst.operands[1].postind = 1;
9934 inst.operands[1].writeback = 1;
b05fe5cf 9935 }
c19d1205
ZW
9936 inst.instruction |= inst.operands[0].reg << 12;
9937 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9938}
b05fe5cf 9939
c19d1205 9940/* Halfword and signed-byte load/store operations. */
b05fe5cf 9941
c19d1205
ZW
9942static void
9943do_ldstv4 (void)
9944{
ff4a8d2b 9945 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9946 inst.instruction |= inst.operands[0].reg << 12;
9947 if (!inst.operands[1].isreg)
8335d6aa 9948 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9949 return;
c19d1205 9950 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9951}
9952
9953static void
c19d1205 9954do_ldsttv4 (void)
b05fe5cf 9955{
c19d1205
ZW
9956 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9957 reject [Rn,...]. */
9958 if (inst.operands[1].preind)
b05fe5cf 9959 {
e2b0ab59
AV
9960 constraint (inst.relocs[0].exp.X_op != O_constant
9961 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9962 _("this instruction requires a post-indexed address"));
b05fe5cf 9963
c19d1205
ZW
9964 inst.operands[1].preind = 0;
9965 inst.operands[1].postind = 1;
9966 inst.operands[1].writeback = 1;
b05fe5cf 9967 }
c19d1205
ZW
9968 inst.instruction |= inst.operands[0].reg << 12;
9969 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9970}
b05fe5cf 9971
c19d1205
ZW
9972/* Co-processor register load/store.
9973 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9974static void
9975do_lstc (void)
9976{
9977 inst.instruction |= inst.operands[0].reg << 8;
9978 inst.instruction |= inst.operands[1].reg << 12;
9979 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9980}
9981
b05fe5cf 9982static void
c19d1205 9983do_mlas (void)
b05fe5cf 9984{
8fb9d7b9 9985 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9986 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9987 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9988 && !(inst.instruction & 0x00400000))
8fb9d7b9 9989 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9990
c19d1205
ZW
9991 inst.instruction |= inst.operands[0].reg << 16;
9992 inst.instruction |= inst.operands[1].reg;
9993 inst.instruction |= inst.operands[2].reg << 8;
9994 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9995}
b05fe5cf 9996
c19d1205
ZW
9997static void
9998do_mov (void)
9999{
e2b0ab59
AV
10000 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10001 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 10002 THUMB1_RELOC_ONLY);
c19d1205
ZW
10003 inst.instruction |= inst.operands[0].reg << 12;
10004 encode_arm_shifter_operand (1);
10005}
b05fe5cf 10006
c19d1205
ZW
10007/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10008static void
10009do_mov16 (void)
10010{
b6895b4f
PB
10011 bfd_vma imm;
10012 bfd_boolean top;
10013
10014 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 10015 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 10016 _(":lower16: not allowed in this instruction"));
e2b0ab59 10017 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 10018 _(":upper16: not allowed in this instruction"));
c19d1205 10019 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 10020 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 10021 {
e2b0ab59 10022 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
10023 /* The value is in two pieces: 0:11, 16:19. */
10024 inst.instruction |= (imm & 0x00000fff);
10025 inst.instruction |= (imm & 0x0000f000) << 4;
10026 }
b05fe5cf 10027}
b99bd4ef 10028
037e8744
JB
10029static int
10030do_vfp_nsyn_mrs (void)
10031{
10032 if (inst.operands[0].isvec)
10033 {
10034 if (inst.operands[1].reg != 1)
477330fc 10035 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
10036 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10037 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10038 do_vfp_nsyn_opcode ("fmstat");
10039 }
10040 else if (inst.operands[1].isvec)
10041 do_vfp_nsyn_opcode ("fmrx");
10042 else
10043 return FAIL;
5f4273c7 10044
037e8744
JB
10045 return SUCCESS;
10046}
10047
10048static int
10049do_vfp_nsyn_msr (void)
10050{
10051 if (inst.operands[0].isvec)
10052 do_vfp_nsyn_opcode ("fmxr");
10053 else
10054 return FAIL;
10055
10056 return SUCCESS;
10057}
10058
f7c21dc7
NC
10059static void
10060do_vmrs (void)
10061{
10062 unsigned Rt = inst.operands[0].reg;
fa94de6b 10063
16d02dc9 10064 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
10065 {
10066 inst.error = BAD_SP;
10067 return;
10068 }
10069
ba6cd17f
SD
10070 switch (inst.operands[1].reg)
10071 {
10072 /* MVFR2 is only valid for Armv8-A. */
10073 case 5:
10074 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10075 _(BAD_FPU));
10076 break;
10077
10078 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10079 case 1: /* fpscr. */
10080 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10081 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10082 _(BAD_FPU));
10083 break;
10084
10085 case 14: /* fpcxt_ns. */
10086 case 15: /* fpcxt_s. */
10087 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10088 _("selected processor does not support instruction"));
10089 break;
10090
10091 case 2: /* fpscr_nzcvqc. */
10092 case 12: /* vpr. */
10093 case 13: /* p0. */
10094 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10095 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10096 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10097 _("selected processor does not support instruction"));
10098 if (inst.operands[0].reg != 2
10099 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10100 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10101 break;
10102
10103 default:
10104 break;
10105 }
40c7d507 10106
f7c21dc7 10107 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 10108 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
10109 {
10110 inst.error = BAD_PC;
10111 return;
10112 }
10113
16d02dc9
JB
10114 /* If we get through parsing the register name, we just insert the number
10115 generated into the instruction without further validation. */
10116 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
10117 inst.instruction |= (Rt << 12);
10118}
10119
10120static void
10121do_vmsr (void)
10122{
10123 unsigned Rt = inst.operands[1].reg;
fa94de6b 10124
f7c21dc7
NC
10125 if (thumb_mode)
10126 reject_bad_reg (Rt);
10127 else if (Rt == REG_PC)
10128 {
10129 inst.error = BAD_PC;
10130 return;
10131 }
10132
ba6cd17f
SD
10133 switch (inst.operands[0].reg)
10134 {
10135 /* MVFR2 is only valid for Armv8-A. */
10136 case 5:
10137 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10138 _(BAD_FPU));
10139 break;
10140
10141 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10142 case 1: /* fpcr. */
10143 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10144 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10145 _(BAD_FPU));
10146 break;
10147
10148 case 14: /* fpcxt_ns. */
10149 case 15: /* fpcxt_s. */
10150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10151 _("selected processor does not support instruction"));
10152 break;
10153
10154 case 2: /* fpscr_nzcvqc. */
10155 case 12: /* vpr. */
10156 case 13: /* p0. */
10157 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10158 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10159 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10160 _("selected processor does not support instruction"));
10161 if (inst.operands[0].reg != 2
10162 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10163 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10164 break;
10165
10166 default:
10167 break;
10168 }
40c7d507 10169
16d02dc9
JB
10170 /* If we get through parsing the register name, we just insert the number
10171 generated into the instruction without further validation. */
10172 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10173 inst.instruction |= (Rt << 12);
10174}
10175
b99bd4ef 10176static void
c19d1205 10177do_mrs (void)
b99bd4ef 10178{
90ec0d68
MGD
10179 unsigned br;
10180
037e8744
JB
10181 if (do_vfp_nsyn_mrs () == SUCCESS)
10182 return;
10183
ff4a8d2b 10184 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10185 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10186
10187 if (inst.operands[1].isreg)
10188 {
10189 br = inst.operands[1].reg;
806ab1c0 10190 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10191 as_bad (_("bad register for mrs"));
10192 }
10193 else
10194 {
10195 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10196 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10197 != (PSR_c|PSR_f),
d2cd1205 10198 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10199 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10200 }
10201
10202 inst.instruction |= br;
c19d1205 10203}
b99bd4ef 10204
c19d1205
ZW
10205/* Two possible forms:
10206 "{C|S}PSR_<field>, Rm",
10207 "{C|S}PSR_f, #expression". */
b99bd4ef 10208
c19d1205
ZW
10209static void
10210do_msr (void)
10211{
037e8744
JB
10212 if (do_vfp_nsyn_msr () == SUCCESS)
10213 return;
10214
c19d1205
ZW
10215 inst.instruction |= inst.operands[0].imm;
10216 if (inst.operands[1].isreg)
10217 inst.instruction |= inst.operands[1].reg;
10218 else
b99bd4ef 10219 {
c19d1205 10220 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10221 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10222 inst.relocs[0].pc_rel = 0;
b99bd4ef 10223 }
b99bd4ef
NC
10224}
10225
c19d1205
ZW
10226static void
10227do_mul (void)
a737bd4d 10228{
ff4a8d2b
NC
10229 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10230
c19d1205
ZW
10231 if (!inst.operands[2].present)
10232 inst.operands[2].reg = inst.operands[0].reg;
10233 inst.instruction |= inst.operands[0].reg << 16;
10234 inst.instruction |= inst.operands[1].reg;
10235 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10236
8fb9d7b9
MS
10237 if (inst.operands[0].reg == inst.operands[1].reg
10238 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10239 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10240}
10241
c19d1205
ZW
10242/* Long Multiply Parser
10243 UMULL RdLo, RdHi, Rm, Rs
10244 SMULL RdLo, RdHi, Rm, Rs
10245 UMLAL RdLo, RdHi, Rm, Rs
10246 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10247
10248static void
c19d1205 10249do_mull (void)
b99bd4ef 10250{
c19d1205
ZW
10251 inst.instruction |= inst.operands[0].reg << 12;
10252 inst.instruction |= inst.operands[1].reg << 16;
10253 inst.instruction |= inst.operands[2].reg;
10254 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10255
682b27ad
PB
10256 /* rdhi and rdlo must be different. */
10257 if (inst.operands[0].reg == inst.operands[1].reg)
10258 as_tsktsk (_("rdhi and rdlo must be different"));
10259
10260 /* rdhi, rdlo and rm must all be different before armv6. */
10261 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10262 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10263 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10264 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10265}
b99bd4ef 10266
c19d1205
ZW
10267static void
10268do_nop (void)
10269{
e7495e45
NS
10270 if (inst.operands[0].present
10271 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10272 {
10273 /* Architectural NOP hints are CPSR sets with no bits selected. */
10274 inst.instruction &= 0xf0000000;
e7495e45
NS
10275 inst.instruction |= 0x0320f000;
10276 if (inst.operands[0].present)
10277 inst.instruction |= inst.operands[0].imm;
c19d1205 10278 }
b99bd4ef
NC
10279}
10280
c19d1205
ZW
10281/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10282 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10283 Condition defaults to COND_ALWAYS.
10284 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10285
10286static void
c19d1205 10287do_pkhbt (void)
b99bd4ef 10288{
c19d1205
ZW
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].reg << 16;
10291 inst.instruction |= inst.operands[2].reg;
10292 if (inst.operands[3].present)
10293 encode_arm_shift (3);
10294}
b99bd4ef 10295
c19d1205 10296/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10297
c19d1205
ZW
10298static void
10299do_pkhtb (void)
10300{
10301 if (!inst.operands[3].present)
b99bd4ef 10302 {
c19d1205
ZW
10303 /* If the shift specifier is omitted, turn the instruction
10304 into pkhbt rd, rm, rn. */
10305 inst.instruction &= 0xfff00010;
10306 inst.instruction |= inst.operands[0].reg << 12;
10307 inst.instruction |= inst.operands[1].reg;
10308 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10309 }
10310 else
10311 {
c19d1205
ZW
10312 inst.instruction |= inst.operands[0].reg << 12;
10313 inst.instruction |= inst.operands[1].reg << 16;
10314 inst.instruction |= inst.operands[2].reg;
10315 encode_arm_shift (3);
b99bd4ef
NC
10316 }
10317}
10318
c19d1205 10319/* ARMv5TE: Preload-Cache
60e5ef9f 10320 MP Extensions: Preload for write
c19d1205 10321
60e5ef9f 10322 PLD(W) <addr_mode>
c19d1205
ZW
10323
10324 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10325
10326static void
c19d1205 10327do_pld (void)
b99bd4ef 10328{
c19d1205
ZW
10329 constraint (!inst.operands[0].isreg,
10330 _("'[' expected after PLD mnemonic"));
10331 constraint (inst.operands[0].postind,
10332 _("post-indexed expression used in preload instruction"));
10333 constraint (inst.operands[0].writeback,
10334 _("writeback used in preload instruction"));
10335 constraint (!inst.operands[0].preind,
10336 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10337 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10338}
b99bd4ef 10339
62b3e311
PB
10340/* ARMv7: PLI <addr_mode> */
10341static void
10342do_pli (void)
10343{
10344 constraint (!inst.operands[0].isreg,
10345 _("'[' expected after PLI mnemonic"));
10346 constraint (inst.operands[0].postind,
10347 _("post-indexed expression used in preload instruction"));
10348 constraint (inst.operands[0].writeback,
10349 _("writeback used in preload instruction"));
10350 constraint (!inst.operands[0].preind,
10351 _("unindexed addressing used in preload instruction"));
10352 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10353 inst.instruction &= ~PRE_INDEX;
10354}
10355
c19d1205
ZW
10356static void
10357do_push_pop (void)
10358{
5e0d7f77
MP
10359 constraint (inst.operands[0].writeback,
10360 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10361 inst.operands[1] = inst.operands[0];
10362 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10363 inst.operands[0].isreg = 1;
10364 inst.operands[0].writeback = 1;
10365 inst.operands[0].reg = REG_SP;
6530b175 10366 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10367}
b99bd4ef 10368
c19d1205
ZW
10369/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10370 word at the specified address and the following word
10371 respectively.
10372 Unconditionally executed.
10373 Error if Rn is R15. */
b99bd4ef 10374
c19d1205
ZW
10375static void
10376do_rfe (void)
10377{
10378 inst.instruction |= inst.operands[0].reg << 16;
10379 if (inst.operands[0].writeback)
10380 inst.instruction |= WRITE_BACK;
10381}
b99bd4ef 10382
c19d1205 10383/* ARM V6 ssat (argument parse). */
b99bd4ef 10384
c19d1205
ZW
10385static void
10386do_ssat (void)
10387{
10388 inst.instruction |= inst.operands[0].reg << 12;
10389 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10390 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10391
c19d1205
ZW
10392 if (inst.operands[3].present)
10393 encode_arm_shift (3);
b99bd4ef
NC
10394}
10395
c19d1205 10396/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10397
10398static void
c19d1205 10399do_usat (void)
b99bd4ef 10400{
c19d1205
ZW
10401 inst.instruction |= inst.operands[0].reg << 12;
10402 inst.instruction |= inst.operands[1].imm << 16;
10403 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10404
c19d1205
ZW
10405 if (inst.operands[3].present)
10406 encode_arm_shift (3);
b99bd4ef
NC
10407}
10408
c19d1205 10409/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10410
10411static void
c19d1205 10412do_ssat16 (void)
09d92015 10413{
c19d1205
ZW
10414 inst.instruction |= inst.operands[0].reg << 12;
10415 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10416 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10417}
10418
c19d1205
ZW
10419static void
10420do_usat16 (void)
a737bd4d 10421{
c19d1205
ZW
10422 inst.instruction |= inst.operands[0].reg << 12;
10423 inst.instruction |= inst.operands[1].imm << 16;
10424 inst.instruction |= inst.operands[2].reg;
10425}
a737bd4d 10426
c19d1205
ZW
10427/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10428 preserving the other bits.
a737bd4d 10429
c19d1205
ZW
10430 setend <endian_specifier>, where <endian_specifier> is either
10431 BE or LE. */
a737bd4d 10432
c19d1205
ZW
10433static void
10434do_setend (void)
10435{
12e37cbc
MGD
10436 if (warn_on_deprecated
10437 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10438 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10439
c19d1205
ZW
10440 if (inst.operands[0].imm)
10441 inst.instruction |= 0x200;
a737bd4d
NC
10442}
10443
10444static void
c19d1205 10445do_shift (void)
a737bd4d 10446{
c19d1205
ZW
10447 unsigned int Rm = (inst.operands[1].present
10448 ? inst.operands[1].reg
10449 : inst.operands[0].reg);
a737bd4d 10450
c19d1205
ZW
10451 inst.instruction |= inst.operands[0].reg << 12;
10452 inst.instruction |= Rm;
10453 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10454 {
c19d1205
ZW
10455 inst.instruction |= inst.operands[2].reg << 8;
10456 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10457 /* PR 12854: Error on extraneous shifts. */
10458 constraint (inst.operands[2].shifted,
10459 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10460 }
10461 else
e2b0ab59 10462 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10463}
10464
09d92015 10465static void
3eb17e6b 10466do_smc (void)
09d92015 10467{
ba85f98c
BW
10468 unsigned int value = inst.relocs[0].exp.X_add_number;
10469 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10470
e2b0ab59
AV
10471 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10472 inst.relocs[0].pc_rel = 0;
09d92015
MM
10473}
10474
90ec0d68
MGD
10475static void
10476do_hvc (void)
10477{
e2b0ab59
AV
10478 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10479 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10480}
10481
09d92015 10482static void
c19d1205 10483do_swi (void)
09d92015 10484{
e2b0ab59
AV
10485 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10486 inst.relocs[0].pc_rel = 0;
09d92015
MM
10487}
10488
ddfded2f
MW
10489static void
10490do_setpan (void)
10491{
10492 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10493 _("selected processor does not support SETPAN instruction"));
10494
10495 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10496}
10497
10498static void
10499do_t_setpan (void)
10500{
10501 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10502 _("selected processor does not support SETPAN instruction"));
10503
10504 inst.instruction |= (inst.operands[0].imm << 3);
10505}
10506
c19d1205
ZW
10507/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10508 SMLAxy{cond} Rd,Rm,Rs,Rn
10509 SMLAWy{cond} Rd,Rm,Rs,Rn
10510 Error if any register is R15. */
e16bb312 10511
c19d1205
ZW
10512static void
10513do_smla (void)
e16bb312 10514{
c19d1205
ZW
10515 inst.instruction |= inst.operands[0].reg << 16;
10516 inst.instruction |= inst.operands[1].reg;
10517 inst.instruction |= inst.operands[2].reg << 8;
10518 inst.instruction |= inst.operands[3].reg << 12;
10519}
a737bd4d 10520
c19d1205
ZW
10521/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10522 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10523 Error if any register is R15.
10524 Warning if Rdlo == Rdhi. */
a737bd4d 10525
c19d1205
ZW
10526static void
10527do_smlal (void)
10528{
10529 inst.instruction |= inst.operands[0].reg << 12;
10530 inst.instruction |= inst.operands[1].reg << 16;
10531 inst.instruction |= inst.operands[2].reg;
10532 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10533
c19d1205
ZW
10534 if (inst.operands[0].reg == inst.operands[1].reg)
10535 as_tsktsk (_("rdhi and rdlo must be different"));
10536}
a737bd4d 10537
c19d1205
ZW
10538/* ARM V5E (El Segundo) signed-multiply (argument parse)
10539 SMULxy{cond} Rd,Rm,Rs
10540 Error if any register is R15. */
a737bd4d 10541
c19d1205
ZW
10542static void
10543do_smul (void)
10544{
10545 inst.instruction |= inst.operands[0].reg << 16;
10546 inst.instruction |= inst.operands[1].reg;
10547 inst.instruction |= inst.operands[2].reg << 8;
10548}
a737bd4d 10549
b6702015
PB
10550/* ARM V6 srs (argument parse). The variable fields in the encoding are
10551 the same for both ARM and Thumb-2. */
a737bd4d 10552
c19d1205
ZW
10553static void
10554do_srs (void)
10555{
b6702015
PB
10556 int reg;
10557
10558 if (inst.operands[0].present)
10559 {
10560 reg = inst.operands[0].reg;
fdfde340 10561 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10562 }
10563 else
fdfde340 10564 reg = REG_SP;
b6702015
PB
10565
10566 inst.instruction |= reg << 16;
10567 inst.instruction |= inst.operands[1].imm;
10568 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10569 inst.instruction |= WRITE_BACK;
10570}
a737bd4d 10571
c19d1205 10572/* ARM V6 strex (argument parse). */
a737bd4d 10573
c19d1205
ZW
10574static void
10575do_strex (void)
10576{
10577 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10578 || inst.operands[2].postind || inst.operands[2].writeback
10579 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10580 || inst.operands[2].negative
10581 /* See comment in do_ldrex(). */
10582 || (inst.operands[2].reg == REG_PC),
10583 BAD_ADDR_MODE);
a737bd4d 10584
c19d1205
ZW
10585 constraint (inst.operands[0].reg == inst.operands[1].reg
10586 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10587
e2b0ab59
AV
10588 constraint (inst.relocs[0].exp.X_op != O_constant
10589 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10590 _("offset must be zero in ARM encoding"));
a737bd4d 10591
c19d1205
ZW
10592 inst.instruction |= inst.operands[0].reg << 12;
10593 inst.instruction |= inst.operands[1].reg;
10594 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10595 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10596}
10597
877807f8
NC
10598static void
10599do_t_strexbh (void)
10600{
10601 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10602 || inst.operands[2].postind || inst.operands[2].writeback
10603 || inst.operands[2].immisreg || inst.operands[2].shifted
10604 || inst.operands[2].negative,
10605 BAD_ADDR_MODE);
10606
10607 constraint (inst.operands[0].reg == inst.operands[1].reg
10608 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10609
10610 do_rm_rd_rn ();
10611}
10612
e16bb312 10613static void
c19d1205 10614do_strexd (void)
e16bb312 10615{
c19d1205
ZW
10616 constraint (inst.operands[1].reg % 2 != 0,
10617 _("even register required"));
10618 constraint (inst.operands[2].present
10619 && inst.operands[2].reg != inst.operands[1].reg + 1,
10620 _("can only store two consecutive registers"));
10621 /* If op 2 were present and equal to PC, this function wouldn't
10622 have been called in the first place. */
10623 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10624
c19d1205
ZW
10625 constraint (inst.operands[0].reg == inst.operands[1].reg
10626 || inst.operands[0].reg == inst.operands[1].reg + 1
10627 || inst.operands[0].reg == inst.operands[3].reg,
10628 BAD_OVERLAP);
e16bb312 10629
c19d1205
ZW
10630 inst.instruction |= inst.operands[0].reg << 12;
10631 inst.instruction |= inst.operands[1].reg;
10632 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10633}
10634
9eb6c0f1
MGD
10635/* ARM V8 STRL. */
10636static void
4b8c8c02 10637do_stlex (void)
9eb6c0f1
MGD
10638{
10639 constraint (inst.operands[0].reg == inst.operands[1].reg
10640 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10641
10642 do_rd_rm_rn ();
10643}
10644
10645static void
4b8c8c02 10646do_t_stlex (void)
9eb6c0f1
MGD
10647{
10648 constraint (inst.operands[0].reg == inst.operands[1].reg
10649 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10650
10651 do_rm_rd_rn ();
10652}
10653
c19d1205
ZW
10654/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10655 extends it to 32-bits, and adds the result to a value in another
10656 register. You can specify a rotation by 0, 8, 16, or 24 bits
10657 before extracting the 16-bit value.
10658 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10659 Condition defaults to COND_ALWAYS.
10660 Error if any register uses R15. */
10661
e16bb312 10662static void
c19d1205 10663do_sxtah (void)
e16bb312 10664{
c19d1205
ZW
10665 inst.instruction |= inst.operands[0].reg << 12;
10666 inst.instruction |= inst.operands[1].reg << 16;
10667 inst.instruction |= inst.operands[2].reg;
10668 inst.instruction |= inst.operands[3].imm << 10;
10669}
e16bb312 10670
c19d1205 10671/* ARM V6 SXTH.
e16bb312 10672
c19d1205
ZW
10673 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10674 Condition defaults to COND_ALWAYS.
10675 Error if any register uses R15. */
e16bb312
NC
10676
10677static void
c19d1205 10678do_sxth (void)
e16bb312 10679{
c19d1205
ZW
10680 inst.instruction |= inst.operands[0].reg << 12;
10681 inst.instruction |= inst.operands[1].reg;
10682 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10683}
c19d1205
ZW
10684\f
10685/* VFP instructions. In a logical order: SP variant first, monad
10686 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10687
10688static void
c19d1205 10689do_vfp_sp_monadic (void)
e16bb312 10690{
57785aa2
AV
10691 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10692 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10693 _(BAD_FPU));
10694
5287ad62
JB
10695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10696 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10697}
10698
10699static void
c19d1205 10700do_vfp_sp_dyadic (void)
e16bb312 10701{
5287ad62
JB
10702 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10703 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10704 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10705}
10706
10707static void
c19d1205 10708do_vfp_sp_compare_z (void)
e16bb312 10709{
5287ad62 10710 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10711}
10712
10713static void
c19d1205 10714do_vfp_dp_sp_cvt (void)
e16bb312 10715{
5287ad62
JB
10716 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10717 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10718}
10719
10720static void
c19d1205 10721do_vfp_sp_dp_cvt (void)
e16bb312 10722{
5287ad62
JB
10723 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10724 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10725}
10726
10727static void
c19d1205 10728do_vfp_reg_from_sp (void)
e16bb312 10729{
57785aa2
AV
10730 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10731 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10732 _(BAD_FPU));
10733
c19d1205 10734 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10736}
10737
10738static void
c19d1205 10739do_vfp_reg2_from_sp2 (void)
e16bb312 10740{
c19d1205
ZW
10741 constraint (inst.operands[2].imm != 2,
10742 _("only two consecutive VFP SP registers allowed here"));
10743 inst.instruction |= inst.operands[0].reg << 12;
10744 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10745 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10746}
10747
10748static void
c19d1205 10749do_vfp_sp_from_reg (void)
e16bb312 10750{
57785aa2
AV
10751 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10752 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10753 _(BAD_FPU));
10754
5287ad62 10755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10756 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10757}
10758
10759static void
c19d1205 10760do_vfp_sp2_from_reg2 (void)
e16bb312 10761{
c19d1205
ZW
10762 constraint (inst.operands[0].imm != 2,
10763 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10765 inst.instruction |= inst.operands[1].reg << 12;
10766 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10767}
10768
10769static void
c19d1205 10770do_vfp_sp_ldst (void)
e16bb312 10771{
5287ad62 10772 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10773 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10774}
10775
10776static void
c19d1205 10777do_vfp_dp_ldst (void)
e16bb312 10778{
5287ad62 10779 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10780 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10781}
10782
c19d1205 10783
e16bb312 10784static void
c19d1205 10785vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10786{
c19d1205
ZW
10787 if (inst.operands[0].writeback)
10788 inst.instruction |= WRITE_BACK;
10789 else
10790 constraint (ldstm_type != VFP_LDSTMIA,
10791 _("this addressing mode requires base-register writeback"));
10792 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10793 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10794 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10795}
10796
10797static void
c19d1205 10798vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10799{
c19d1205 10800 int count;
e16bb312 10801
c19d1205
ZW
10802 if (inst.operands[0].writeback)
10803 inst.instruction |= WRITE_BACK;
10804 else
10805 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10806 _("this addressing mode requires base-register writeback"));
e16bb312 10807
c19d1205 10808 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10809 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10810
c19d1205
ZW
10811 count = inst.operands[1].imm << 1;
10812 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10813 count += 1;
e16bb312 10814
c19d1205 10815 inst.instruction |= count;
e16bb312
NC
10816}
10817
10818static void
c19d1205 10819do_vfp_sp_ldstmia (void)
e16bb312 10820{
c19d1205 10821 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10822}
10823
10824static void
c19d1205 10825do_vfp_sp_ldstmdb (void)
e16bb312 10826{
c19d1205 10827 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10828}
10829
10830static void
c19d1205 10831do_vfp_dp_ldstmia (void)
e16bb312 10832{
c19d1205 10833 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10834}
10835
10836static void
c19d1205 10837do_vfp_dp_ldstmdb (void)
e16bb312 10838{
c19d1205 10839 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10840}
10841
10842static void
c19d1205 10843do_vfp_xp_ldstmia (void)
e16bb312 10844{
c19d1205
ZW
10845 vfp_dp_ldstm (VFP_LDSTMIAX);
10846}
e16bb312 10847
c19d1205
ZW
10848static void
10849do_vfp_xp_ldstmdb (void)
10850{
10851 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10852}
5287ad62
JB
10853
10854static void
10855do_vfp_dp_rd_rm (void)
10856{
57785aa2
AV
10857 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10858 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10859 _(BAD_FPU));
10860
5287ad62
JB
10861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10863}
10864
10865static void
10866do_vfp_dp_rn_rd (void)
10867{
10868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10870}
10871
10872static void
10873do_vfp_dp_rd_rn (void)
10874{
10875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10877}
10878
10879static void
10880do_vfp_dp_rd_rn_rm (void)
10881{
57785aa2
AV
10882 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10883 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10884 _(BAD_FPU));
10885
5287ad62
JB
10886 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10887 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10888 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10889}
10890
10891static void
10892do_vfp_dp_rd (void)
10893{
10894 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10895}
10896
10897static void
10898do_vfp_dp_rm_rd_rn (void)
10899{
57785aa2
AV
10900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10901 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10902 _(BAD_FPU));
10903
5287ad62
JB
10904 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10905 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10906 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10907}
10908
10909/* VFPv3 instructions. */
10910static void
10911do_vfp_sp_const (void)
10912{
10913 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10914 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10915 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10916}
10917
10918static void
10919do_vfp_dp_const (void)
10920{
10921 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10922 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10923 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10924}
10925
10926static void
10927vfp_conv (int srcsize)
10928{
5f1af56b
MGD
10929 int immbits = srcsize - inst.operands[1].imm;
10930
fa94de6b
RM
10931 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10932 {
5f1af56b 10933 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10934 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10935 inst.error = _("immediate value out of range, expected range [0, 16]");
10936 return;
10937 }
fa94de6b 10938 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10939 {
10940 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10941 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10942 inst.error = _("immediate value out of range, expected range [1, 32]");
10943 return;
10944 }
10945
5287ad62
JB
10946 inst.instruction |= (immbits & 1) << 5;
10947 inst.instruction |= (immbits >> 1);
10948}
10949
10950static void
10951do_vfp_sp_conv_16 (void)
10952{
10953 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10954 vfp_conv (16);
10955}
10956
10957static void
10958do_vfp_dp_conv_16 (void)
10959{
10960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10961 vfp_conv (16);
10962}
10963
10964static void
10965do_vfp_sp_conv_32 (void)
10966{
10967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10968 vfp_conv (32);
10969}
10970
10971static void
10972do_vfp_dp_conv_32 (void)
10973{
10974 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10975 vfp_conv (32);
10976}
c19d1205
ZW
10977\f
10978/* FPA instructions. Also in a logical order. */
e16bb312 10979
c19d1205
ZW
10980static void
10981do_fpa_cmp (void)
10982{
10983 inst.instruction |= inst.operands[0].reg << 16;
10984 inst.instruction |= inst.operands[1].reg;
10985}
b99bd4ef
NC
10986
10987static void
c19d1205 10988do_fpa_ldmstm (void)
b99bd4ef 10989{
c19d1205
ZW
10990 inst.instruction |= inst.operands[0].reg << 12;
10991 switch (inst.operands[1].imm)
10992 {
10993 case 1: inst.instruction |= CP_T_X; break;
10994 case 2: inst.instruction |= CP_T_Y; break;
10995 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10996 case 4: break;
10997 default: abort ();
10998 }
b99bd4ef 10999
c19d1205
ZW
11000 if (inst.instruction & (PRE_INDEX | INDEX_UP))
11001 {
11002 /* The instruction specified "ea" or "fd", so we can only accept
11003 [Rn]{!}. The instruction does not really support stacking or
11004 unstacking, so we have to emulate these by setting appropriate
11005 bits and offsets. */
e2b0ab59
AV
11006 constraint (inst.relocs[0].exp.X_op != O_constant
11007 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 11008 _("this instruction does not support indexing"));
b99bd4ef 11009
c19d1205 11010 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 11011 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 11012
c19d1205 11013 if (!(inst.instruction & INDEX_UP))
e2b0ab59 11014 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 11015
c19d1205
ZW
11016 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11017 {
11018 inst.operands[2].preind = 0;
11019 inst.operands[2].postind = 1;
11020 }
11021 }
b99bd4ef 11022
c19d1205 11023 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 11024}
c19d1205
ZW
11025\f
11026/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 11027
c19d1205
ZW
11028static void
11029do_iwmmxt_tandorc (void)
11030{
11031 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11032}
b99bd4ef 11033
c19d1205
ZW
11034static void
11035do_iwmmxt_textrc (void)
11036{
11037 inst.instruction |= inst.operands[0].reg << 12;
11038 inst.instruction |= inst.operands[1].imm;
11039}
b99bd4ef
NC
11040
11041static void
c19d1205 11042do_iwmmxt_textrm (void)
b99bd4ef 11043{
c19d1205
ZW
11044 inst.instruction |= inst.operands[0].reg << 12;
11045 inst.instruction |= inst.operands[1].reg << 16;
11046 inst.instruction |= inst.operands[2].imm;
11047}
b99bd4ef 11048
c19d1205
ZW
11049static void
11050do_iwmmxt_tinsr (void)
11051{
11052 inst.instruction |= inst.operands[0].reg << 16;
11053 inst.instruction |= inst.operands[1].reg << 12;
11054 inst.instruction |= inst.operands[2].imm;
11055}
b99bd4ef 11056
c19d1205
ZW
11057static void
11058do_iwmmxt_tmia (void)
11059{
11060 inst.instruction |= inst.operands[0].reg << 5;
11061 inst.instruction |= inst.operands[1].reg;
11062 inst.instruction |= inst.operands[2].reg << 12;
11063}
b99bd4ef 11064
c19d1205
ZW
11065static void
11066do_iwmmxt_waligni (void)
11067{
11068 inst.instruction |= inst.operands[0].reg << 12;
11069 inst.instruction |= inst.operands[1].reg << 16;
11070 inst.instruction |= inst.operands[2].reg;
11071 inst.instruction |= inst.operands[3].imm << 20;
11072}
b99bd4ef 11073
2d447fca
JM
11074static void
11075do_iwmmxt_wmerge (void)
11076{
11077 inst.instruction |= inst.operands[0].reg << 12;
11078 inst.instruction |= inst.operands[1].reg << 16;
11079 inst.instruction |= inst.operands[2].reg;
11080 inst.instruction |= inst.operands[3].imm << 21;
11081}
11082
c19d1205
ZW
11083static void
11084do_iwmmxt_wmov (void)
11085{
11086 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11087 inst.instruction |= inst.operands[0].reg << 12;
11088 inst.instruction |= inst.operands[1].reg << 16;
11089 inst.instruction |= inst.operands[1].reg;
11090}
b99bd4ef 11091
c19d1205
ZW
11092static void
11093do_iwmmxt_wldstbh (void)
11094{
8f06b2d8 11095 int reloc;
c19d1205 11096 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
11097 if (thumb_mode)
11098 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11099 else
11100 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11101 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
11102}
11103
c19d1205
ZW
11104static void
11105do_iwmmxt_wldstw (void)
11106{
11107 /* RIWR_RIWC clears .isreg for a control register. */
11108 if (!inst.operands[0].isreg)
11109 {
11110 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11111 inst.instruction |= 0xf0000000;
11112 }
b99bd4ef 11113
c19d1205
ZW
11114 inst.instruction |= inst.operands[0].reg << 12;
11115 encode_arm_cp_address (1, TRUE, TRUE, 0);
11116}
b99bd4ef
NC
11117
11118static void
c19d1205 11119do_iwmmxt_wldstd (void)
b99bd4ef 11120{
c19d1205 11121 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
11122 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11123 && inst.operands[1].immisreg)
11124 {
11125 inst.instruction &= ~0x1a000ff;
eff0bc54 11126 inst.instruction |= (0xfU << 28);
2d447fca
JM
11127 if (inst.operands[1].preind)
11128 inst.instruction |= PRE_INDEX;
11129 if (!inst.operands[1].negative)
11130 inst.instruction |= INDEX_UP;
11131 if (inst.operands[1].writeback)
11132 inst.instruction |= WRITE_BACK;
11133 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11134 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
11135 inst.instruction |= inst.operands[1].imm;
11136 }
11137 else
11138 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 11139}
b99bd4ef 11140
c19d1205
ZW
11141static void
11142do_iwmmxt_wshufh (void)
11143{
11144 inst.instruction |= inst.operands[0].reg << 12;
11145 inst.instruction |= inst.operands[1].reg << 16;
11146 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11147 inst.instruction |= (inst.operands[2].imm & 0x0f);
11148}
b99bd4ef 11149
c19d1205
ZW
11150static void
11151do_iwmmxt_wzero (void)
11152{
11153 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11154 inst.instruction |= inst.operands[0].reg;
11155 inst.instruction |= inst.operands[0].reg << 12;
11156 inst.instruction |= inst.operands[0].reg << 16;
11157}
2d447fca
JM
11158
11159static void
11160do_iwmmxt_wrwrwr_or_imm5 (void)
11161{
11162 if (inst.operands[2].isreg)
11163 do_rd_rn_rm ();
11164 else {
11165 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11166 _("immediate operand requires iWMMXt2"));
11167 do_rd_rn ();
11168 if (inst.operands[2].imm == 0)
11169 {
11170 switch ((inst.instruction >> 20) & 0xf)
11171 {
11172 case 4:
11173 case 5:
11174 case 6:
5f4273c7 11175 case 7:
2d447fca
JM
11176 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11177 inst.operands[2].imm = 16;
11178 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11179 break;
11180 case 8:
11181 case 9:
11182 case 10:
11183 case 11:
11184 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11185 inst.operands[2].imm = 32;
11186 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11187 break;
11188 case 12:
11189 case 13:
11190 case 14:
11191 case 15:
11192 {
11193 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11194 unsigned long wrn;
11195 wrn = (inst.instruction >> 16) & 0xf;
11196 inst.instruction &= 0xff0fff0f;
11197 inst.instruction |= wrn;
11198 /* Bail out here; the instruction is now assembled. */
11199 return;
11200 }
11201 }
11202 }
11203 /* Map 32 -> 0, etc. */
11204 inst.operands[2].imm &= 0x1f;
eff0bc54 11205 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11206 }
11207}
c19d1205
ZW
11208\f
11209/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11210 operations first, then control, shift, and load/store. */
b99bd4ef 11211
c19d1205 11212/* Insns like "foo X,Y,Z". */
b99bd4ef 11213
c19d1205
ZW
11214static void
11215do_mav_triple (void)
11216{
11217 inst.instruction |= inst.operands[0].reg << 16;
11218 inst.instruction |= inst.operands[1].reg;
11219 inst.instruction |= inst.operands[2].reg << 12;
11220}
b99bd4ef 11221
c19d1205
ZW
11222/* Insns like "foo W,X,Y,Z".
11223 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11224
c19d1205
ZW
11225static void
11226do_mav_quad (void)
11227{
11228 inst.instruction |= inst.operands[0].reg << 5;
11229 inst.instruction |= inst.operands[1].reg << 12;
11230 inst.instruction |= inst.operands[2].reg << 16;
11231 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11232}
11233
c19d1205
ZW
11234/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11235static void
11236do_mav_dspsc (void)
a737bd4d 11237{
c19d1205
ZW
11238 inst.instruction |= inst.operands[1].reg << 12;
11239}
a737bd4d 11240
c19d1205
ZW
11241/* Maverick shift immediate instructions.
11242 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11243 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11244
c19d1205
ZW
11245static void
11246do_mav_shift (void)
11247{
11248 int imm = inst.operands[2].imm;
a737bd4d 11249
c19d1205
ZW
11250 inst.instruction |= inst.operands[0].reg << 12;
11251 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11252
c19d1205
ZW
11253 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11254 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11255 Bit 4 should be 0. */
11256 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11257
c19d1205
ZW
11258 inst.instruction |= imm;
11259}
11260\f
11261/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11262
c19d1205
ZW
11263/* Xscale multiply-accumulate (argument parse)
11264 MIAcc acc0,Rm,Rs
11265 MIAPHcc acc0,Rm,Rs
11266 MIAxycc acc0,Rm,Rs. */
a737bd4d 11267
c19d1205
ZW
11268static void
11269do_xsc_mia (void)
11270{
11271 inst.instruction |= inst.operands[1].reg;
11272 inst.instruction |= inst.operands[2].reg << 12;
11273}
a737bd4d 11274
c19d1205 11275/* Xscale move-accumulator-register (argument parse)
a737bd4d 11276
c19d1205 11277 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11278
c19d1205
ZW
11279static void
11280do_xsc_mar (void)
11281{
11282 inst.instruction |= inst.operands[1].reg << 12;
11283 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11284}
11285
c19d1205 11286/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11287
c19d1205 11288 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11289
11290static void
c19d1205 11291do_xsc_mra (void)
b99bd4ef 11292{
c19d1205
ZW
11293 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11294 inst.instruction |= inst.operands[0].reg << 12;
11295 inst.instruction |= inst.operands[1].reg << 16;
11296}
11297\f
11298/* Encoding functions relevant only to Thumb. */
b99bd4ef 11299
c19d1205
ZW
11300/* inst.operands[i] is a shifted-register operand; encode
11301 it into inst.instruction in the format used by Thumb32. */
11302
11303static void
11304encode_thumb32_shifted_operand (int i)
11305{
e2b0ab59 11306 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11307 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11308
9c3c69f2
PB
11309 constraint (inst.operands[i].immisreg,
11310 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11311 inst.instruction |= inst.operands[i].reg;
11312 if (shift == SHIFT_RRX)
11313 inst.instruction |= SHIFT_ROR << 4;
11314 else
b99bd4ef 11315 {
e2b0ab59 11316 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11317 _("expression too complex"));
11318
11319 constraint (value > 32
11320 || (value == 32 && (shift == SHIFT_LSL
11321 || shift == SHIFT_ROR)),
11322 _("shift expression is too large"));
11323
11324 if (value == 0)
11325 shift = SHIFT_LSL;
11326 else if (value == 32)
11327 value = 0;
11328
11329 inst.instruction |= shift << 4;
11330 inst.instruction |= (value & 0x1c) << 10;
11331 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11332 }
c19d1205 11333}
b99bd4ef 11334
b99bd4ef 11335
c19d1205
ZW
11336/* inst.operands[i] was set up by parse_address. Encode it into a
11337 Thumb32 format load or store instruction. Reject forms that cannot
11338 be used with such instructions. If is_t is true, reject forms that
11339 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11340 that cannot be used with a D instruction. If it is a store insn,
11341 reject PC in Rn. */
b99bd4ef 11342
c19d1205
ZW
11343static void
11344encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11345{
5be8be5d 11346 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11347
11348 constraint (!inst.operands[i].isreg,
53365c0d 11349 _("Instruction does not support =N addresses"));
b99bd4ef 11350
c19d1205
ZW
11351 inst.instruction |= inst.operands[i].reg << 16;
11352 if (inst.operands[i].immisreg)
b99bd4ef 11353 {
5be8be5d 11354 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11355 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11356 constraint (inst.operands[i].negative,
11357 _("Thumb does not support negative register indexing"));
11358 constraint (inst.operands[i].postind,
11359 _("Thumb does not support register post-indexing"));
11360 constraint (inst.operands[i].writeback,
11361 _("Thumb does not support register indexing with writeback"));
11362 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11363 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11364
f40d1643 11365 inst.instruction |= inst.operands[i].imm;
c19d1205 11366 if (inst.operands[i].shifted)
b99bd4ef 11367 {
e2b0ab59 11368 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11369 _("expression too complex"));
e2b0ab59
AV
11370 constraint (inst.relocs[0].exp.X_add_number < 0
11371 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11372 _("shift out of range"));
e2b0ab59 11373 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11374 }
e2b0ab59 11375 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11376 }
11377 else if (inst.operands[i].preind)
11378 {
5be8be5d 11379 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11380 constraint (is_t && inst.operands[i].writeback,
c19d1205 11381 _("cannot use writeback with this instruction"));
4755303e
WN
11382 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11383 BAD_PC_ADDRESSING);
c19d1205
ZW
11384
11385 if (is_d)
11386 {
11387 inst.instruction |= 0x01000000;
11388 if (inst.operands[i].writeback)
11389 inst.instruction |= 0x00200000;
b99bd4ef 11390 }
c19d1205 11391 else
b99bd4ef 11392 {
c19d1205
ZW
11393 inst.instruction |= 0x00000c00;
11394 if (inst.operands[i].writeback)
11395 inst.instruction |= 0x00000100;
b99bd4ef 11396 }
e2b0ab59 11397 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11398 }
c19d1205 11399 else if (inst.operands[i].postind)
b99bd4ef 11400 {
9c2799c2 11401 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11402 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11403 constraint (is_t, _("cannot use post-indexing with this instruction"));
11404
11405 if (is_d)
11406 inst.instruction |= 0x00200000;
11407 else
11408 inst.instruction |= 0x00000900;
e2b0ab59 11409 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11410 }
11411 else /* unindexed - only for coprocessor */
11412 inst.error = _("instruction does not accept unindexed addressing");
11413}
11414
e39c1607 11415/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11416 encodings (the latter only in post-V6T2 cores). The index is the
11417 value used in the insns table below. When there is more than one
11418 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11419 holds variant (1).
11420 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11421#define T16_32_TAB \
21d799b5
NC
11422 X(_adc, 4140, eb400000), \
11423 X(_adcs, 4140, eb500000), \
11424 X(_add, 1c00, eb000000), \
11425 X(_adds, 1c00, eb100000), \
11426 X(_addi, 0000, f1000000), \
11427 X(_addis, 0000, f1100000), \
11428 X(_add_pc,000f, f20f0000), \
11429 X(_add_sp,000d, f10d0000), \
11430 X(_adr, 000f, f20f0000), \
11431 X(_and, 4000, ea000000), \
11432 X(_ands, 4000, ea100000), \
11433 X(_asr, 1000, fa40f000), \
11434 X(_asrs, 1000, fa50f000), \
11435 X(_b, e000, f000b000), \
11436 X(_bcond, d000, f0008000), \
4389b29a 11437 X(_bf, 0000, f040e001), \
f6b2b12d 11438 X(_bfcsel,0000, f000e001), \
f1c7f421 11439 X(_bfx, 0000, f060e001), \
65d1bc05 11440 X(_bfl, 0000, f000c001), \
f1c7f421 11441 X(_bflx, 0000, f070e001), \
21d799b5
NC
11442 X(_bic, 4380, ea200000), \
11443 X(_bics, 4380, ea300000), \
e39c1607
SD
11444 X(_cinc, 0000, ea509000), \
11445 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11446 X(_cmn, 42c0, eb100f00), \
11447 X(_cmp, 2800, ebb00f00), \
e39c1607 11448 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11449 X(_cpsie, b660, f3af8400), \
11450 X(_cpsid, b670, f3af8600), \
11451 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11452 X(_csel, 0000, ea508000), \
11453 X(_cset, 0000, ea5f900f), \
11454 X(_csetm, 0000, ea5fa00f), \
11455 X(_csinc, 0000, ea509000), \
11456 X(_csinv, 0000, ea50a000), \
11457 X(_csneg, 0000, ea50b000), \
21d799b5 11458 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11459 X(_dls, 0000, f040e001), \
1f6234a3 11460 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11461 X(_eor, 4040, ea800000), \
11462 X(_eors, 4040, ea900000), \
11463 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11464 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11465 X(_ldmia, c800, e8900000), \
11466 X(_ldr, 6800, f8500000), \
11467 X(_ldrb, 7800, f8100000), \
11468 X(_ldrh, 8800, f8300000), \
11469 X(_ldrsb, 5600, f9100000), \
11470 X(_ldrsh, 5e00, f9300000), \
11471 X(_ldr_pc,4800, f85f0000), \
11472 X(_ldr_pc2,4800, f85f0000), \
11473 X(_ldr_sp,9800, f85d0000), \
60f993ce 11474 X(_le, 0000, f00fc001), \
1f6234a3 11475 X(_letp, 0000, f01fc001), \
21d799b5
NC
11476 X(_lsl, 0000, fa00f000), \
11477 X(_lsls, 0000, fa10f000), \
11478 X(_lsr, 0800, fa20f000), \
11479 X(_lsrs, 0800, fa30f000), \
11480 X(_mov, 2000, ea4f0000), \
11481 X(_movs, 2000, ea5f0000), \
11482 X(_mul, 4340, fb00f000), \
11483 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11484 X(_mvn, 43c0, ea6f0000), \
11485 X(_mvns, 43c0, ea7f0000), \
11486 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11487 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11488 X(_orr, 4300, ea400000), \
11489 X(_orrs, 4300, ea500000), \
11490 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11491 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11492 X(_rev, ba00, fa90f080), \
11493 X(_rev16, ba40, fa90f090), \
11494 X(_revsh, bac0, fa90f0b0), \
11495 X(_ror, 41c0, fa60f000), \
11496 X(_rors, 41c0, fa70f000), \
11497 X(_sbc, 4180, eb600000), \
11498 X(_sbcs, 4180, eb700000), \
11499 X(_stmia, c000, e8800000), \
11500 X(_str, 6000, f8400000), \
11501 X(_strb, 7000, f8000000), \
11502 X(_strh, 8000, f8200000), \
11503 X(_str_sp,9000, f84d0000), \
11504 X(_sub, 1e00, eba00000), \
11505 X(_subs, 1e00, ebb00000), \
11506 X(_subi, 8000, f1a00000), \
11507 X(_subis, 8000, f1b00000), \
11508 X(_sxtb, b240, fa4ff080), \
11509 X(_sxth, b200, fa0ff080), \
11510 X(_tst, 4200, ea100f00), \
11511 X(_uxtb, b2c0, fa5ff080), \
11512 X(_uxth, b280, fa1ff080), \
11513 X(_nop, bf00, f3af8000), \
11514 X(_yield, bf10, f3af8001), \
11515 X(_wfe, bf20, f3af8002), \
11516 X(_wfi, bf30, f3af8003), \
60f993ce 11517 X(_wls, 0000, f040c001), \
1f6234a3 11518 X(_wlstp, 0000, f000c001), \
53c4b28b 11519 X(_sev, bf40, f3af8004), \
74db7efb
NC
11520 X(_sevl, bf50, f3af8005), \
11521 X(_udf, de00, f7f0a000)
c19d1205
ZW
11522
11523/* To catch errors in encoding functions, the codes are all offset by
11524 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11525 as 16-bit instructions. */
21d799b5 11526#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11527enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11528#undef X
11529
11530#define X(a,b,c) 0x##b
11531static const unsigned short thumb_op16[] = { T16_32_TAB };
11532#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11533#undef X
11534
11535#define X(a,b,c) 0x##c
11536static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11537#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11538#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11539#undef X
11540#undef T16_32_TAB
11541
11542/* Thumb instruction encoders, in alphabetical order. */
11543
92e90b6e 11544/* ADDW or SUBW. */
c921be7d 11545
92e90b6e
PB
11546static void
11547do_t_add_sub_w (void)
11548{
11549 int Rd, Rn;
11550
11551 Rd = inst.operands[0].reg;
11552 Rn = inst.operands[1].reg;
11553
539d4391
NC
11554 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11555 is the SP-{plus,minus}-immediate form of the instruction. */
11556 if (Rn == REG_SP)
11557 constraint (Rd == REG_PC, BAD_PC);
11558 else
11559 reject_bad_reg (Rd);
fdfde340 11560
92e90b6e 11561 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11562 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11563}
11564
c19d1205 11565/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11566 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11567
11568static void
11569do_t_add_sub (void)
11570{
11571 int Rd, Rs, Rn;
11572
11573 Rd = inst.operands[0].reg;
11574 Rs = (inst.operands[1].present
11575 ? inst.operands[1].reg /* Rd, Rs, foo */
11576 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11577
e07e6e58 11578 if (Rd == REG_PC)
5ee91343 11579 set_pred_insn_type_last ();
e07e6e58 11580
c19d1205
ZW
11581 if (unified_syntax)
11582 {
0110f2b8
PB
11583 bfd_boolean flags;
11584 bfd_boolean narrow;
11585 int opcode;
11586
11587 flags = (inst.instruction == T_MNEM_adds
11588 || inst.instruction == T_MNEM_subs);
11589 if (flags)
5ee91343 11590 narrow = !in_pred_block ();
0110f2b8 11591 else
5ee91343 11592 narrow = in_pred_block ();
c19d1205 11593 if (!inst.operands[2].isreg)
b99bd4ef 11594 {
16805f35
PB
11595 int add;
11596
5c8ed6a4
JW
11597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11598 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11599
16805f35
PB
11600 add = (inst.instruction == T_MNEM_add
11601 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11602 opcode = 0;
11603 if (inst.size_req != 4)
11604 {
0110f2b8 11605 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11606 appropriate. */
0110f2b8
PB
11607 if (Rd == REG_SP && Rs == REG_SP && !flags)
11608 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11609 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11610 opcode = T_MNEM_add_sp;
11611 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11612 opcode = T_MNEM_add_pc;
11613 else if (Rd <= 7 && Rs <= 7 && narrow)
11614 {
11615 if (flags)
11616 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11617 else
11618 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11619 }
11620 if (opcode)
11621 {
11622 inst.instruction = THUMB_OP16(opcode);
11623 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11624 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11625 || (inst.relocs[0].type
11626 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11627 {
11628 if (inst.size_req == 2)
e2b0ab59 11629 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11630 else
11631 inst.relax = opcode;
11632 }
0110f2b8
PB
11633 }
11634 else
11635 constraint (inst.size_req == 2, BAD_HIREG);
11636 }
11637 if (inst.size_req == 4
11638 || (inst.size_req != 2 && !opcode))
11639 {
e2b0ab59
AV
11640 constraint ((inst.relocs[0].type
11641 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11642 && (inst.relocs[0].type
11643 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11644 THUMB1_RELOC_ONLY);
efd81785
PB
11645 if (Rd == REG_PC)
11646 {
fdfde340 11647 constraint (add, BAD_PC);
efd81785
PB
11648 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11649 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11650 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11651 _("expression too complex"));
e2b0ab59
AV
11652 constraint (inst.relocs[0].exp.X_add_number < 0
11653 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11654 _("immediate value out of range"));
11655 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11656 | inst.relocs[0].exp.X_add_number;
11657 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11658 return;
11659 }
11660 else if (Rs == REG_PC)
16805f35
PB
11661 {
11662 /* Always use addw/subw. */
11663 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11664 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11665 }
11666 else
11667 {
11668 inst.instruction = THUMB_OP32 (inst.instruction);
11669 inst.instruction = (inst.instruction & 0xe1ffffff)
11670 | 0x10000000;
11671 if (flags)
e2b0ab59 11672 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11673 else
e2b0ab59 11674 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11675 }
dc4503c6
PB
11676 inst.instruction |= Rd << 8;
11677 inst.instruction |= Rs << 16;
0110f2b8 11678 }
b99bd4ef 11679 }
c19d1205
ZW
11680 else
11681 {
e2b0ab59 11682 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11683 unsigned int shift = inst.operands[2].shift_kind;
11684
c19d1205
ZW
11685 Rn = inst.operands[2].reg;
11686 /* See if we can do this with a 16-bit instruction. */
11687 if (!inst.operands[2].shifted && inst.size_req != 4)
11688 {
e27ec89e
PB
11689 if (Rd > 7 || Rs > 7 || Rn > 7)
11690 narrow = FALSE;
11691
11692 if (narrow)
c19d1205 11693 {
e27ec89e
PB
11694 inst.instruction = ((inst.instruction == T_MNEM_adds
11695 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11696 ? T_OPCODE_ADD_R3
11697 : T_OPCODE_SUB_R3);
11698 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11699 return;
11700 }
b99bd4ef 11701
7e806470 11702 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11703 {
7e806470
PB
11704 /* Thumb-1 cores (except v6-M) require at least one high
11705 register in a narrow non flag setting add. */
11706 if (Rd > 7 || Rn > 7
11707 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11708 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11709 {
7e806470
PB
11710 if (Rd == Rn)
11711 {
11712 Rn = Rs;
11713 Rs = Rd;
11714 }
c19d1205
ZW
11715 inst.instruction = T_OPCODE_ADD_HI;
11716 inst.instruction |= (Rd & 8) << 4;
11717 inst.instruction |= (Rd & 7);
11718 inst.instruction |= Rn << 3;
11719 return;
11720 }
c19d1205
ZW
11721 }
11722 }
c921be7d 11723
fdfde340 11724 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11725 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11726 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11727 constraint (Rs == REG_PC, BAD_PC);
11728 reject_bad_reg (Rn);
11729
c19d1205
ZW
11730 /* If we get here, it can't be done in 16 bits. */
11731 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11732 _("shift must be constant"));
11733 inst.instruction = THUMB_OP32 (inst.instruction);
11734 inst.instruction |= Rd << 8;
11735 inst.instruction |= Rs << 16;
5f4cb198
NC
11736 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11737 _("shift value over 3 not allowed in thumb mode"));
11738 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11739 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11740 encode_thumb32_shifted_operand (2);
11741 }
11742 }
11743 else
11744 {
11745 constraint (inst.instruction == T_MNEM_adds
11746 || inst.instruction == T_MNEM_subs,
11747 BAD_THUMB32);
b99bd4ef 11748
c19d1205 11749 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11750 {
c19d1205
ZW
11751 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11752 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11753 BAD_HIREG);
11754
11755 inst.instruction = (inst.instruction == T_MNEM_add
11756 ? 0x0000 : 0x8000);
11757 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11758 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11759 return;
11760 }
11761
c19d1205
ZW
11762 Rn = inst.operands[2].reg;
11763 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11764
c19d1205
ZW
11765 /* We now have Rd, Rs, and Rn set to registers. */
11766 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11767 {
c19d1205
ZW
11768 /* Can't do this for SUB. */
11769 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11770 inst.instruction = T_OPCODE_ADD_HI;
11771 inst.instruction |= (Rd & 8) << 4;
11772 inst.instruction |= (Rd & 7);
11773 if (Rs == Rd)
11774 inst.instruction |= Rn << 3;
11775 else if (Rn == Rd)
11776 inst.instruction |= Rs << 3;
11777 else
11778 constraint (1, _("dest must overlap one source register"));
11779 }
11780 else
11781 {
11782 inst.instruction = (inst.instruction == T_MNEM_add
11783 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11784 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11785 }
b99bd4ef 11786 }
b99bd4ef
NC
11787}
11788
c19d1205
ZW
11789static void
11790do_t_adr (void)
11791{
fdfde340
JM
11792 unsigned Rd;
11793
11794 Rd = inst.operands[0].reg;
11795 reject_bad_reg (Rd);
11796
11797 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11798 {
11799 /* Defer to section relaxation. */
11800 inst.relax = inst.instruction;
11801 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11802 inst.instruction |= Rd << 4;
0110f2b8
PB
11803 }
11804 else if (unified_syntax && inst.size_req != 2)
e9f89963 11805 {
0110f2b8 11806 /* Generate a 32-bit opcode. */
e9f89963 11807 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11808 inst.instruction |= Rd << 8;
e2b0ab59
AV
11809 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11810 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11811 }
11812 else
11813 {
0110f2b8 11814 /* Generate a 16-bit opcode. */
e9f89963 11815 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11816 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11817 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11818 inst.relocs[0].pc_rel = 1;
fdfde340 11819 inst.instruction |= Rd << 4;
e9f89963 11820 }
52a86f84 11821
e2b0ab59
AV
11822 if (inst.relocs[0].exp.X_op == O_symbol
11823 && inst.relocs[0].exp.X_add_symbol != NULL
11824 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11825 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11826 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11827}
b99bd4ef 11828
c19d1205
ZW
11829/* Arithmetic instructions for which there is just one 16-bit
11830 instruction encoding, and it allows only two low registers.
11831 For maximal compatibility with ARM syntax, we allow three register
11832 operands even when Thumb-32 instructions are not available, as long
11833 as the first two are identical. For instance, both "sbc r0,r1" and
11834 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11835static void
c19d1205 11836do_t_arit3 (void)
b99bd4ef 11837{
c19d1205 11838 int Rd, Rs, Rn;
b99bd4ef 11839
c19d1205
ZW
11840 Rd = inst.operands[0].reg;
11841 Rs = (inst.operands[1].present
11842 ? inst.operands[1].reg /* Rd, Rs, foo */
11843 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11844 Rn = inst.operands[2].reg;
b99bd4ef 11845
fdfde340
JM
11846 reject_bad_reg (Rd);
11847 reject_bad_reg (Rs);
11848 if (inst.operands[2].isreg)
11849 reject_bad_reg (Rn);
11850
c19d1205 11851 if (unified_syntax)
b99bd4ef 11852 {
c19d1205
ZW
11853 if (!inst.operands[2].isreg)
11854 {
11855 /* For an immediate, we always generate a 32-bit opcode;
11856 section relaxation will shrink it later if possible. */
11857 inst.instruction = THUMB_OP32 (inst.instruction);
11858 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11859 inst.instruction |= Rd << 8;
11860 inst.instruction |= Rs << 16;
e2b0ab59 11861 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11862 }
11863 else
11864 {
e27ec89e
PB
11865 bfd_boolean narrow;
11866
c19d1205 11867 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11868 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11869 narrow = !in_pred_block ();
e27ec89e 11870 else
5ee91343 11871 narrow = in_pred_block ();
e27ec89e
PB
11872
11873 if (Rd > 7 || Rn > 7 || Rs > 7)
11874 narrow = FALSE;
11875 if (inst.operands[2].shifted)
11876 narrow = FALSE;
11877 if (inst.size_req == 4)
11878 narrow = FALSE;
11879
11880 if (narrow
c19d1205
ZW
11881 && Rd == Rs)
11882 {
11883 inst.instruction = THUMB_OP16 (inst.instruction);
11884 inst.instruction |= Rd;
11885 inst.instruction |= Rn << 3;
11886 return;
11887 }
b99bd4ef 11888
c19d1205
ZW
11889 /* If we get here, it can't be done in 16 bits. */
11890 constraint (inst.operands[2].shifted
11891 && inst.operands[2].immisreg,
11892 _("shift must be constant"));
11893 inst.instruction = THUMB_OP32 (inst.instruction);
11894 inst.instruction |= Rd << 8;
11895 inst.instruction |= Rs << 16;
11896 encode_thumb32_shifted_operand (2);
11897 }
a737bd4d 11898 }
c19d1205 11899 else
b99bd4ef 11900 {
c19d1205
ZW
11901 /* On its face this is a lie - the instruction does set the
11902 flags. However, the only supported mnemonic in this mode
11903 says it doesn't. */
11904 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11905
c19d1205
ZW
11906 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11907 _("unshifted register required"));
11908 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11909 constraint (Rd != Rs,
11910 _("dest and source1 must be the same register"));
a737bd4d 11911
c19d1205
ZW
11912 inst.instruction = THUMB_OP16 (inst.instruction);
11913 inst.instruction |= Rd;
11914 inst.instruction |= Rn << 3;
b99bd4ef 11915 }
a737bd4d 11916}
b99bd4ef 11917
c19d1205
ZW
11918/* Similarly, but for instructions where the arithmetic operation is
11919 commutative, so we can allow either of them to be different from
11920 the destination operand in a 16-bit instruction. For instance, all
11921 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11922 accepted. */
11923static void
11924do_t_arit3c (void)
a737bd4d 11925{
c19d1205 11926 int Rd, Rs, Rn;
b99bd4ef 11927
c19d1205
ZW
11928 Rd = inst.operands[0].reg;
11929 Rs = (inst.operands[1].present
11930 ? inst.operands[1].reg /* Rd, Rs, foo */
11931 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11932 Rn = inst.operands[2].reg;
c921be7d 11933
fdfde340
JM
11934 reject_bad_reg (Rd);
11935 reject_bad_reg (Rs);
11936 if (inst.operands[2].isreg)
11937 reject_bad_reg (Rn);
a737bd4d 11938
c19d1205 11939 if (unified_syntax)
a737bd4d 11940 {
c19d1205 11941 if (!inst.operands[2].isreg)
b99bd4ef 11942 {
c19d1205
ZW
11943 /* For an immediate, we always generate a 32-bit opcode;
11944 section relaxation will shrink it later if possible. */
11945 inst.instruction = THUMB_OP32 (inst.instruction);
11946 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11947 inst.instruction |= Rd << 8;
11948 inst.instruction |= Rs << 16;
e2b0ab59 11949 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11950 }
c19d1205 11951 else
a737bd4d 11952 {
e27ec89e
PB
11953 bfd_boolean narrow;
11954
c19d1205 11955 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11956 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11957 narrow = !in_pred_block ();
e27ec89e 11958 else
5ee91343 11959 narrow = in_pred_block ();
e27ec89e
PB
11960
11961 if (Rd > 7 || Rn > 7 || Rs > 7)
11962 narrow = FALSE;
11963 if (inst.operands[2].shifted)
11964 narrow = FALSE;
11965 if (inst.size_req == 4)
11966 narrow = FALSE;
11967
11968 if (narrow)
a737bd4d 11969 {
c19d1205 11970 if (Rd == Rs)
a737bd4d 11971 {
c19d1205
ZW
11972 inst.instruction = THUMB_OP16 (inst.instruction);
11973 inst.instruction |= Rd;
11974 inst.instruction |= Rn << 3;
11975 return;
a737bd4d 11976 }
c19d1205 11977 if (Rd == Rn)
a737bd4d 11978 {
c19d1205
ZW
11979 inst.instruction = THUMB_OP16 (inst.instruction);
11980 inst.instruction |= Rd;
11981 inst.instruction |= Rs << 3;
11982 return;
a737bd4d
NC
11983 }
11984 }
c19d1205
ZW
11985
11986 /* If we get here, it can't be done in 16 bits. */
11987 constraint (inst.operands[2].shifted
11988 && inst.operands[2].immisreg,
11989 _("shift must be constant"));
11990 inst.instruction = THUMB_OP32 (inst.instruction);
11991 inst.instruction |= Rd << 8;
11992 inst.instruction |= Rs << 16;
11993 encode_thumb32_shifted_operand (2);
a737bd4d 11994 }
b99bd4ef 11995 }
c19d1205
ZW
11996 else
11997 {
11998 /* On its face this is a lie - the instruction does set the
11999 flags. However, the only supported mnemonic in this mode
12000 says it doesn't. */
12001 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 12002
c19d1205
ZW
12003 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
12004 _("unshifted register required"));
12005 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
12006
12007 inst.instruction = THUMB_OP16 (inst.instruction);
12008 inst.instruction |= Rd;
12009
12010 if (Rd == Rs)
12011 inst.instruction |= Rn << 3;
12012 else if (Rd == Rn)
12013 inst.instruction |= Rs << 3;
12014 else
12015 constraint (1, _("dest must overlap one source register"));
12016 }
a737bd4d
NC
12017}
12018
c19d1205
ZW
12019static void
12020do_t_bfc (void)
a737bd4d 12021{
fdfde340 12022 unsigned Rd;
c19d1205
ZW
12023 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12024 constraint (msb > 32, _("bit-field extends past end of register"));
12025 /* The instruction encoding stores the LSB and MSB,
12026 not the LSB and width. */
fdfde340
JM
12027 Rd = inst.operands[0].reg;
12028 reject_bad_reg (Rd);
12029 inst.instruction |= Rd << 8;
c19d1205
ZW
12030 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12031 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12032 inst.instruction |= msb - 1;
b99bd4ef
NC
12033}
12034
c19d1205
ZW
12035static void
12036do_t_bfi (void)
b99bd4ef 12037{
fdfde340 12038 int Rd, Rn;
c19d1205 12039 unsigned int msb;
b99bd4ef 12040
fdfde340
JM
12041 Rd = inst.operands[0].reg;
12042 reject_bad_reg (Rd);
12043
c19d1205
ZW
12044 /* #0 in second position is alternative syntax for bfc, which is
12045 the same instruction but with REG_PC in the Rm field. */
12046 if (!inst.operands[1].isreg)
fdfde340
JM
12047 Rn = REG_PC;
12048 else
12049 {
12050 Rn = inst.operands[1].reg;
12051 reject_bad_reg (Rn);
12052 }
b99bd4ef 12053
c19d1205
ZW
12054 msb = inst.operands[2].imm + inst.operands[3].imm;
12055 constraint (msb > 32, _("bit-field extends past end of register"));
12056 /* The instruction encoding stores the LSB and MSB,
12057 not the LSB and width. */
fdfde340
JM
12058 inst.instruction |= Rd << 8;
12059 inst.instruction |= Rn << 16;
c19d1205
ZW
12060 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12061 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12062 inst.instruction |= msb - 1;
b99bd4ef
NC
12063}
12064
c19d1205
ZW
12065static void
12066do_t_bfx (void)
b99bd4ef 12067{
fdfde340
JM
12068 unsigned Rd, Rn;
12069
12070 Rd = inst.operands[0].reg;
12071 Rn = inst.operands[1].reg;
12072
12073 reject_bad_reg (Rd);
12074 reject_bad_reg (Rn);
12075
c19d1205
ZW
12076 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12077 _("bit-field extends past end of register"));
fdfde340
JM
12078 inst.instruction |= Rd << 8;
12079 inst.instruction |= Rn << 16;
c19d1205
ZW
12080 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12081 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12082 inst.instruction |= inst.operands[3].imm - 1;
12083}
b99bd4ef 12084
c19d1205
ZW
12085/* ARM V5 Thumb BLX (argument parse)
12086 BLX <target_addr> which is BLX(1)
12087 BLX <Rm> which is BLX(2)
12088 Unfortunately, there are two different opcodes for this mnemonic.
12089 So, the insns[].value is not used, and the code here zaps values
12090 into inst.instruction.
b99bd4ef 12091
c19d1205
ZW
12092 ??? How to take advantage of the additional two bits of displacement
12093 available in Thumb32 mode? Need new relocation? */
b99bd4ef 12094
c19d1205
ZW
12095static void
12096do_t_blx (void)
12097{
5ee91343 12098 set_pred_insn_type_last ();
e07e6e58 12099
c19d1205 12100 if (inst.operands[0].isreg)
fdfde340
JM
12101 {
12102 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12103 /* We have a register, so this is BLX(2). */
12104 inst.instruction |= inst.operands[0].reg << 3;
12105 }
b99bd4ef
NC
12106 else
12107 {
c19d1205 12108 /* No register. This must be BLX(1). */
2fc8bdac 12109 inst.instruction = 0xf000e800;
0855e32b 12110 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
12111 }
12112}
12113
c19d1205
ZW
12114static void
12115do_t_branch (void)
b99bd4ef 12116{
0110f2b8 12117 int opcode;
dfa9f0d5 12118 int cond;
2fe88214 12119 bfd_reloc_code_real_type reloc;
dfa9f0d5 12120
e07e6e58 12121 cond = inst.cond;
5ee91343 12122 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 12123
5ee91343 12124 if (in_pred_block ())
dfa9f0d5
PB
12125 {
12126 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 12127 branches. */
dfa9f0d5 12128 cond = COND_ALWAYS;
dfa9f0d5
PB
12129 }
12130 else
12131 cond = inst.cond;
12132
12133 if (cond != COND_ALWAYS)
0110f2b8
PB
12134 opcode = T_MNEM_bcond;
12135 else
12136 opcode = inst.instruction;
12137
12d6b0b7
RS
12138 if (unified_syntax
12139 && (inst.size_req == 4
10960bfb
PB
12140 || (inst.size_req != 2
12141 && (inst.operands[0].hasreloc
e2b0ab59 12142 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 12143 {
0110f2b8 12144 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 12145 if (cond == COND_ALWAYS)
9ae92b05 12146 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
12147 else
12148 {
ff8646ee
TP
12149 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12150 _("selected architecture does not support "
12151 "wide conditional branch instruction"));
12152
9c2799c2 12153 gas_assert (cond != 0xF);
dfa9f0d5 12154 inst.instruction |= cond << 22;
9ae92b05 12155 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12156 }
12157 }
b99bd4ef
NC
12158 else
12159 {
0110f2b8 12160 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12161 if (cond == COND_ALWAYS)
9ae92b05 12162 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12163 else
b99bd4ef 12164 {
dfa9f0d5 12165 inst.instruction |= cond << 8;
9ae92b05 12166 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12167 }
0110f2b8
PB
12168 /* Allow section relaxation. */
12169 if (unified_syntax && inst.size_req != 2)
12170 inst.relax = opcode;
b99bd4ef 12171 }
e2b0ab59
AV
12172 inst.relocs[0].type = reloc;
12173 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12174}
12175
8884b720 12176/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12177 between the two is the maximum immediate allowed - which is passed in
8884b720 12178 RANGE. */
b99bd4ef 12179static void
8884b720 12180do_t_bkpt_hlt1 (int range)
b99bd4ef 12181{
dfa9f0d5
PB
12182 constraint (inst.cond != COND_ALWAYS,
12183 _("instruction is always unconditional"));
c19d1205 12184 if (inst.operands[0].present)
b99bd4ef 12185 {
8884b720 12186 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12187 _("immediate value out of range"));
12188 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12189 }
8884b720 12190
5ee91343 12191 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12192}
12193
12194static void
12195do_t_hlt (void)
12196{
12197 do_t_bkpt_hlt1 (63);
12198}
12199
12200static void
12201do_t_bkpt (void)
12202{
12203 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12204}
12205
12206static void
c19d1205 12207do_t_branch23 (void)
b99bd4ef 12208{
5ee91343 12209 set_pred_insn_type_last ();
0855e32b 12210 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12211
0855e32b
NS
12212 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12213 this file. We used to simply ignore the PLT reloc type here --
12214 the branch encoding is now needed to deal with TLSCALL relocs.
12215 So if we see a PLT reloc now, put it back to how it used to be to
12216 keep the preexisting behaviour. */
e2b0ab59
AV
12217 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12218 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12219
4343666d 12220#if defined(OBJ_COFF)
c19d1205
ZW
12221 /* If the destination of the branch is a defined symbol which does not have
12222 the THUMB_FUNC attribute, then we must be calling a function which has
12223 the (interfacearm) attribute. We look for the Thumb entry point to that
12224 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12225 if ( inst.relocs[0].exp.X_op == O_symbol
12226 && inst.relocs[0].exp.X_add_symbol != NULL
12227 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12228 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12229 inst.relocs[0].exp.X_add_symbol
12230 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12231#endif
90e4755a
RE
12232}
12233
12234static void
c19d1205 12235do_t_bx (void)
90e4755a 12236{
5ee91343 12237 set_pred_insn_type_last ();
c19d1205
ZW
12238 inst.instruction |= inst.operands[0].reg << 3;
12239 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12240 should cause the alignment to be checked once it is known. This is
12241 because BX PC only works if the instruction is word aligned. */
12242}
90e4755a 12243
c19d1205
ZW
12244static void
12245do_t_bxj (void)
12246{
fdfde340 12247 int Rm;
90e4755a 12248
5ee91343 12249 set_pred_insn_type_last ();
fdfde340
JM
12250 Rm = inst.operands[0].reg;
12251 reject_bad_reg (Rm);
12252 inst.instruction |= Rm << 16;
90e4755a
RE
12253}
12254
12255static void
c19d1205 12256do_t_clz (void)
90e4755a 12257{
fdfde340
JM
12258 unsigned Rd;
12259 unsigned Rm;
12260
12261 Rd = inst.operands[0].reg;
12262 Rm = inst.operands[1].reg;
12263
12264 reject_bad_reg (Rd);
12265 reject_bad_reg (Rm);
12266
12267 inst.instruction |= Rd << 8;
12268 inst.instruction |= Rm << 16;
12269 inst.instruction |= Rm;
c19d1205 12270}
90e4755a 12271
e39c1607
SD
12272/* For the Armv8.1-M conditional instructions. */
12273static void
12274do_t_cond (void)
12275{
12276 unsigned Rd, Rn, Rm;
12277 signed int cond;
12278
12279 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12280
12281 Rd = inst.operands[0].reg;
12282 switch (inst.instruction)
12283 {
12284 case T_MNEM_csinc:
12285 case T_MNEM_csinv:
12286 case T_MNEM_csneg:
12287 case T_MNEM_csel:
12288 Rn = inst.operands[1].reg;
12289 Rm = inst.operands[2].reg;
12290 cond = inst.operands[3].imm;
12291 constraint (Rn == REG_SP, BAD_SP);
12292 constraint (Rm == REG_SP, BAD_SP);
12293 break;
12294
12295 case T_MNEM_cinc:
12296 case T_MNEM_cinv:
12297 case T_MNEM_cneg:
12298 Rn = inst.operands[1].reg;
12299 cond = inst.operands[2].imm;
12300 /* Invert the last bit to invert the cond. */
12301 cond = TOGGLE_BIT (cond, 0);
12302 constraint (Rn == REG_SP, BAD_SP);
12303 Rm = Rn;
12304 break;
12305
12306 case T_MNEM_csetm:
12307 case T_MNEM_cset:
12308 cond = inst.operands[1].imm;
12309 /* Invert the last bit to invert the cond. */
12310 cond = TOGGLE_BIT (cond, 0);
12311 Rn = REG_PC;
12312 Rm = REG_PC;
12313 break;
12314
12315 default: abort ();
12316 }
12317
12318 set_pred_insn_type (OUTSIDE_PRED_INSN);
12319 inst.instruction = THUMB_OP32 (inst.instruction);
12320 inst.instruction |= Rd << 8;
12321 inst.instruction |= Rn << 16;
12322 inst.instruction |= Rm;
12323 inst.instruction |= cond << 4;
12324}
12325
91d8b670
JG
12326static void
12327do_t_csdb (void)
12328{
5ee91343 12329 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12330}
12331
dfa9f0d5
PB
12332static void
12333do_t_cps (void)
12334{
5ee91343 12335 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12336 inst.instruction |= inst.operands[0].imm;
12337}
12338
c19d1205
ZW
12339static void
12340do_t_cpsi (void)
12341{
5ee91343 12342 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12343 if (unified_syntax
62b3e311
PB
12344 && (inst.operands[1].present || inst.size_req == 4)
12345 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12346 {
c19d1205
ZW
12347 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12348 inst.instruction = 0xf3af8000;
12349 inst.instruction |= imod << 9;
12350 inst.instruction |= inst.operands[0].imm << 5;
12351 if (inst.operands[1].present)
12352 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12353 }
c19d1205 12354 else
90e4755a 12355 {
62b3e311
PB
12356 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12357 && (inst.operands[0].imm & 4),
12358 _("selected processor does not support 'A' form "
12359 "of this instruction"));
12360 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12361 _("Thumb does not support the 2-argument "
12362 "form of this instruction"));
12363 inst.instruction |= inst.operands[0].imm;
90e4755a 12364 }
90e4755a
RE
12365}
12366
c19d1205
ZW
12367/* THUMB CPY instruction (argument parse). */
12368
90e4755a 12369static void
c19d1205 12370do_t_cpy (void)
90e4755a 12371{
c19d1205 12372 if (inst.size_req == 4)
90e4755a 12373 {
c19d1205
ZW
12374 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12375 inst.instruction |= inst.operands[0].reg << 8;
12376 inst.instruction |= inst.operands[1].reg;
90e4755a 12377 }
c19d1205 12378 else
90e4755a 12379 {
c19d1205
ZW
12380 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12381 inst.instruction |= (inst.operands[0].reg & 0x7);
12382 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12383 }
90e4755a
RE
12384}
12385
90e4755a 12386static void
25fe350b 12387do_t_cbz (void)
90e4755a 12388{
5ee91343 12389 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12390 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12391 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12392 inst.relocs[0].pc_rel = 1;
12393 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12394}
90e4755a 12395
62b3e311
PB
12396static void
12397do_t_dbg (void)
12398{
12399 inst.instruction |= inst.operands[0].imm;
12400}
12401
12402static void
12403do_t_div (void)
12404{
fdfde340
JM
12405 unsigned Rd, Rn, Rm;
12406
12407 Rd = inst.operands[0].reg;
12408 Rn = (inst.operands[1].present
12409 ? inst.operands[1].reg : Rd);
12410 Rm = inst.operands[2].reg;
12411
12412 reject_bad_reg (Rd);
12413 reject_bad_reg (Rn);
12414 reject_bad_reg (Rm);
12415
12416 inst.instruction |= Rd << 8;
12417 inst.instruction |= Rn << 16;
12418 inst.instruction |= Rm;
62b3e311
PB
12419}
12420
c19d1205
ZW
12421static void
12422do_t_hint (void)
12423{
12424 if (unified_syntax && inst.size_req == 4)
12425 inst.instruction = THUMB_OP32 (inst.instruction);
12426 else
12427 inst.instruction = THUMB_OP16 (inst.instruction);
12428}
90e4755a 12429
c19d1205
ZW
12430static void
12431do_t_it (void)
12432{
12433 unsigned int cond = inst.operands[0].imm;
e27ec89e 12434
5ee91343
AV
12435 set_pred_insn_type (IT_INSN);
12436 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12437 now_pred.cc = cond;
12438 now_pred.warn_deprecated = FALSE;
12439 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12440
12441 /* If the condition is a negative condition, invert the mask. */
c19d1205 12442 if ((cond & 0x1) == 0x0)
90e4755a 12443 {
c19d1205 12444 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12445
c19d1205 12446 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12447 {
12448 /* No conversion needed. */
5ee91343 12449 now_pred.block_length = 1;
5a01bb1d 12450 }
c19d1205 12451 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12452 {
12453 mask ^= 0x8;
5ee91343 12454 now_pred.block_length = 2;
5a01bb1d 12455 }
e27ec89e 12456 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12457 {
12458 mask ^= 0xC;
5ee91343 12459 now_pred.block_length = 3;
5a01bb1d 12460 }
c19d1205 12461 else
5a01bb1d
MGD
12462 {
12463 mask ^= 0xE;
5ee91343 12464 now_pred.block_length = 4;
5a01bb1d 12465 }
90e4755a 12466
e27ec89e
PB
12467 inst.instruction &= 0xfff0;
12468 inst.instruction |= mask;
c19d1205 12469 }
90e4755a 12470
c19d1205
ZW
12471 inst.instruction |= cond << 4;
12472}
90e4755a 12473
3c707909
PB
12474/* Helper function used for both push/pop and ldm/stm. */
12475static void
4b5a202f
AV
12476encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12477 bfd_boolean writeback)
3c707909 12478{
4b5a202f 12479 bfd_boolean load, store;
3c707909 12480
4b5a202f
AV
12481 gas_assert (base != -1 || !do_io);
12482 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12483 store = do_io && !load;
3c707909
PB
12484
12485 if (mask & (1 << 13))
12486 inst.error = _("SP not allowed in register list");
1e5b0379 12487
4b5a202f 12488 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12489 && writeback)
12490 inst.error = _("having the base register in the register list when "
12491 "using write back is UNPREDICTABLE");
12492
3c707909
PB
12493 if (load)
12494 {
e07e6e58 12495 if (mask & (1 << 15))
477330fc
RM
12496 {
12497 if (mask & (1 << 14))
12498 inst.error = _("LR and PC should not both be in register list");
12499 else
5ee91343 12500 set_pred_insn_type_last ();
477330fc 12501 }
3c707909 12502 }
4b5a202f 12503 else if (store)
3c707909
PB
12504 {
12505 if (mask & (1 << 15))
12506 inst.error = _("PC not allowed in register list");
3c707909
PB
12507 }
12508
4b5a202f 12509 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12510 {
12511 /* Single register transfers implemented as str/ldr. */
12512 if (writeback)
12513 {
12514 if (inst.instruction & (1 << 23))
12515 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12516 else
12517 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12518 }
12519 else
12520 {
12521 if (inst.instruction & (1 << 23))
12522 inst.instruction = 0x00800000; /* ia -> [base] */
12523 else
12524 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12525 }
12526
12527 inst.instruction |= 0xf8400000;
12528 if (load)
12529 inst.instruction |= 0x00100000;
12530
5f4273c7 12531 mask = ffs (mask) - 1;
3c707909
PB
12532 mask <<= 12;
12533 }
12534 else if (writeback)
12535 inst.instruction |= WRITE_BACK;
12536
12537 inst.instruction |= mask;
4b5a202f
AV
12538 if (do_io)
12539 inst.instruction |= base << 16;
3c707909
PB
12540}
12541
c19d1205
ZW
12542static void
12543do_t_ldmstm (void)
12544{
12545 /* This really doesn't seem worth it. */
e2b0ab59 12546 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12547 _("expression too complex"));
12548 constraint (inst.operands[1].writeback,
12549 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12550
c19d1205
ZW
12551 if (unified_syntax)
12552 {
3c707909
PB
12553 bfd_boolean narrow;
12554 unsigned mask;
12555
12556 narrow = FALSE;
c19d1205
ZW
12557 /* See if we can use a 16-bit instruction. */
12558 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12559 && inst.size_req != 4
3c707909 12560 && !(inst.operands[1].imm & ~0xff))
90e4755a 12561 {
3c707909 12562 mask = 1 << inst.operands[0].reg;
90e4755a 12563
eab4f823 12564 if (inst.operands[0].reg <= 7)
90e4755a 12565 {
3c707909 12566 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12567 ? inst.operands[0].writeback
12568 : (inst.operands[0].writeback
12569 == !(inst.operands[1].imm & mask)))
477330fc 12570 {
eab4f823
MGD
12571 if (inst.instruction == T_MNEM_stmia
12572 && (inst.operands[1].imm & mask)
12573 && (inst.operands[1].imm & (mask - 1)))
12574 as_warn (_("value stored for r%d is UNKNOWN"),
12575 inst.operands[0].reg);
3c707909 12576
eab4f823
MGD
12577 inst.instruction = THUMB_OP16 (inst.instruction);
12578 inst.instruction |= inst.operands[0].reg << 8;
12579 inst.instruction |= inst.operands[1].imm;
12580 narrow = TRUE;
12581 }
12582 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12583 {
12584 /* This means 1 register in reg list one of 3 situations:
12585 1. Instruction is stmia, but without writeback.
12586 2. lmdia without writeback, but with Rn not in
477330fc 12587 reglist.
eab4f823
MGD
12588 3. ldmia with writeback, but with Rn in reglist.
12589 Case 3 is UNPREDICTABLE behaviour, so we handle
12590 case 1 and 2 which can be converted into a 16-bit
12591 str or ldr. The SP cases are handled below. */
12592 unsigned long opcode;
12593 /* First, record an error for Case 3. */
12594 if (inst.operands[1].imm & mask
12595 && inst.operands[0].writeback)
fa94de6b 12596 inst.error =
eab4f823
MGD
12597 _("having the base register in the register list when "
12598 "using write back is UNPREDICTABLE");
fa94de6b
RM
12599
12600 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12601 : T_MNEM_ldr);
12602 inst.instruction = THUMB_OP16 (opcode);
12603 inst.instruction |= inst.operands[0].reg << 3;
12604 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12605 narrow = TRUE;
12606 }
90e4755a 12607 }
eab4f823 12608 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12609 {
eab4f823
MGD
12610 if (inst.operands[0].writeback)
12611 {
fa94de6b 12612 inst.instruction =
eab4f823 12613 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12614 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12615 inst.instruction |= inst.operands[1].imm;
477330fc 12616 narrow = TRUE;
eab4f823
MGD
12617 }
12618 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12619 {
fa94de6b 12620 inst.instruction =
eab4f823 12621 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12622 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12623 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12624 narrow = TRUE;
eab4f823 12625 }
90e4755a 12626 }
3c707909
PB
12627 }
12628
12629 if (!narrow)
12630 {
c19d1205
ZW
12631 if (inst.instruction < 0xffff)
12632 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12633
4b5a202f
AV
12634 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12635 inst.operands[1].imm,
12636 inst.operands[0].writeback);
90e4755a
RE
12637 }
12638 }
c19d1205 12639 else
90e4755a 12640 {
c19d1205
ZW
12641 constraint (inst.operands[0].reg > 7
12642 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12643 constraint (inst.instruction != T_MNEM_ldmia
12644 && inst.instruction != T_MNEM_stmia,
12645 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12646 if (inst.instruction == T_MNEM_stmia)
f03698e6 12647 {
c19d1205
ZW
12648 if (!inst.operands[0].writeback)
12649 as_warn (_("this instruction will write back the base register"));
12650 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12651 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12652 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12653 inst.operands[0].reg);
f03698e6 12654 }
c19d1205 12655 else
90e4755a 12656 {
c19d1205
ZW
12657 if (!inst.operands[0].writeback
12658 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12659 as_warn (_("this instruction will write back the base register"));
12660 else if (inst.operands[0].writeback
12661 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12662 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12663 }
12664
c19d1205
ZW
12665 inst.instruction = THUMB_OP16 (inst.instruction);
12666 inst.instruction |= inst.operands[0].reg << 8;
12667 inst.instruction |= inst.operands[1].imm;
12668 }
12669}
e28cd48c 12670
c19d1205
ZW
12671static void
12672do_t_ldrex (void)
12673{
12674 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12675 || inst.operands[1].postind || inst.operands[1].writeback
12676 || inst.operands[1].immisreg || inst.operands[1].shifted
12677 || inst.operands[1].negative,
01cfc07f 12678 BAD_ADDR_MODE);
e28cd48c 12679
5be8be5d
DG
12680 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12681
c19d1205
ZW
12682 inst.instruction |= inst.operands[0].reg << 12;
12683 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12684 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12685}
e28cd48c 12686
c19d1205
ZW
12687static void
12688do_t_ldrexd (void)
12689{
12690 if (!inst.operands[1].present)
1cac9012 12691 {
c19d1205
ZW
12692 constraint (inst.operands[0].reg == REG_LR,
12693 _("r14 not allowed as first register "
12694 "when second register is omitted"));
12695 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12696 }
c19d1205
ZW
12697 constraint (inst.operands[0].reg == inst.operands[1].reg,
12698 BAD_OVERLAP);
b99bd4ef 12699
c19d1205
ZW
12700 inst.instruction |= inst.operands[0].reg << 12;
12701 inst.instruction |= inst.operands[1].reg << 8;
12702 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12703}
12704
12705static void
c19d1205 12706do_t_ldst (void)
b99bd4ef 12707{
0110f2b8
PB
12708 unsigned long opcode;
12709 int Rn;
12710
e07e6e58
NC
12711 if (inst.operands[0].isreg
12712 && !inst.operands[0].preind
12713 && inst.operands[0].reg == REG_PC)
5ee91343 12714 set_pred_insn_type_last ();
e07e6e58 12715
0110f2b8 12716 opcode = inst.instruction;
c19d1205 12717 if (unified_syntax)
b99bd4ef 12718 {
53365c0d
PB
12719 if (!inst.operands[1].isreg)
12720 {
12721 if (opcode <= 0xffff)
12722 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12723 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12724 return;
12725 }
0110f2b8
PB
12726 if (inst.operands[1].isreg
12727 && !inst.operands[1].writeback
c19d1205
ZW
12728 && !inst.operands[1].shifted && !inst.operands[1].postind
12729 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12730 && opcode <= 0xffff
12731 && inst.size_req != 4)
c19d1205 12732 {
0110f2b8
PB
12733 /* Insn may have a 16-bit form. */
12734 Rn = inst.operands[1].reg;
12735 if (inst.operands[1].immisreg)
12736 {
12737 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12738 /* [Rn, Rik] */
0110f2b8
PB
12739 if (Rn <= 7 && inst.operands[1].imm <= 7)
12740 goto op16;
5be8be5d
DG
12741 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12742 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12743 }
12744 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12745 && opcode != T_MNEM_ldrsb)
12746 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12747 || (Rn == REG_SP && opcode == T_MNEM_str))
12748 {
12749 /* [Rn, #const] */
12750 if (Rn > 7)
12751 {
12752 if (Rn == REG_PC)
12753 {
e2b0ab59 12754 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12755 opcode = T_MNEM_ldr_pc2;
12756 else
12757 opcode = T_MNEM_ldr_pc;
12758 }
12759 else
12760 {
12761 if (opcode == T_MNEM_ldr)
12762 opcode = T_MNEM_ldr_sp;
12763 else
12764 opcode = T_MNEM_str_sp;
12765 }
12766 inst.instruction = inst.operands[0].reg << 8;
12767 }
12768 else
12769 {
12770 inst.instruction = inst.operands[0].reg;
12771 inst.instruction |= inst.operands[1].reg << 3;
12772 }
12773 inst.instruction |= THUMB_OP16 (opcode);
12774 if (inst.size_req == 2)
e2b0ab59 12775 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12776 else
12777 inst.relax = opcode;
12778 return;
12779 }
c19d1205 12780 }
0110f2b8 12781 /* Definitely a 32-bit variant. */
5be8be5d 12782
8d67f500
NC
12783 /* Warning for Erratum 752419. */
12784 if (opcode == T_MNEM_ldr
12785 && inst.operands[0].reg == REG_SP
12786 && inst.operands[1].writeback == 1
12787 && !inst.operands[1].immisreg)
12788 {
12789 if (no_cpu_selected ()
12790 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12791 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12792 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12793 as_warn (_("This instruction may be unpredictable "
12794 "if executed on M-profile cores "
12795 "with interrupts enabled."));
12796 }
12797
5be8be5d 12798 /* Do some validations regarding addressing modes. */
1be5fd2e 12799 if (inst.operands[1].immisreg)
5be8be5d
DG
12800 reject_bad_reg (inst.operands[1].imm);
12801
1be5fd2e
NC
12802 constraint (inst.operands[1].writeback == 1
12803 && inst.operands[0].reg == inst.operands[1].reg,
12804 BAD_OVERLAP);
12805
0110f2b8 12806 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12807 inst.instruction |= inst.operands[0].reg << 12;
12808 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12809 check_ldr_r15_aligned ();
b99bd4ef
NC
12810 return;
12811 }
12812
c19d1205
ZW
12813 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12814
12815 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12816 {
c19d1205
ZW
12817 /* Only [Rn,Rm] is acceptable. */
12818 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12819 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12820 || inst.operands[1].postind || inst.operands[1].shifted
12821 || inst.operands[1].negative,
12822 _("Thumb does not support this addressing mode"));
12823 inst.instruction = THUMB_OP16 (inst.instruction);
12824 goto op16;
b99bd4ef 12825 }
5f4273c7 12826
c19d1205
ZW
12827 inst.instruction = THUMB_OP16 (inst.instruction);
12828 if (!inst.operands[1].isreg)
8335d6aa 12829 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12830 return;
b99bd4ef 12831
c19d1205
ZW
12832 constraint (!inst.operands[1].preind
12833 || inst.operands[1].shifted
12834 || inst.operands[1].writeback,
12835 _("Thumb does not support this addressing mode"));
12836 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12837 {
c19d1205
ZW
12838 constraint (inst.instruction & 0x0600,
12839 _("byte or halfword not valid for base register"));
12840 constraint (inst.operands[1].reg == REG_PC
12841 && !(inst.instruction & THUMB_LOAD_BIT),
12842 _("r15 based store not allowed"));
12843 constraint (inst.operands[1].immisreg,
12844 _("invalid base register for register offset"));
b99bd4ef 12845
c19d1205
ZW
12846 if (inst.operands[1].reg == REG_PC)
12847 inst.instruction = T_OPCODE_LDR_PC;
12848 else if (inst.instruction & THUMB_LOAD_BIT)
12849 inst.instruction = T_OPCODE_LDR_SP;
12850 else
12851 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12852
c19d1205 12853 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12854 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12855 return;
12856 }
90e4755a 12857
c19d1205
ZW
12858 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12859 if (!inst.operands[1].immisreg)
12860 {
12861 /* Immediate offset. */
12862 inst.instruction |= inst.operands[0].reg;
12863 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12864 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12865 return;
12866 }
90e4755a 12867
c19d1205
ZW
12868 /* Register offset. */
12869 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12870 constraint (inst.operands[1].negative,
12871 _("Thumb does not support this addressing mode"));
90e4755a 12872
c19d1205
ZW
12873 op16:
12874 switch (inst.instruction)
12875 {
12876 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12877 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12878 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12879 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12880 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12881 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12882 case 0x5600 /* ldrsb */:
12883 case 0x5e00 /* ldrsh */: break;
12884 default: abort ();
12885 }
90e4755a 12886
c19d1205
ZW
12887 inst.instruction |= inst.operands[0].reg;
12888 inst.instruction |= inst.operands[1].reg << 3;
12889 inst.instruction |= inst.operands[1].imm << 6;
12890}
90e4755a 12891
c19d1205
ZW
12892static void
12893do_t_ldstd (void)
12894{
12895 if (!inst.operands[1].present)
b99bd4ef 12896 {
c19d1205
ZW
12897 inst.operands[1].reg = inst.operands[0].reg + 1;
12898 constraint (inst.operands[0].reg == REG_LR,
12899 _("r14 not allowed here"));
bd340a04 12900 constraint (inst.operands[0].reg == REG_R12,
477330fc 12901 _("r12 not allowed here"));
b99bd4ef 12902 }
bd340a04
MGD
12903
12904 if (inst.operands[2].writeback
12905 && (inst.operands[0].reg == inst.operands[2].reg
12906 || inst.operands[1].reg == inst.operands[2].reg))
12907 as_warn (_("base register written back, and overlaps "
477330fc 12908 "one of transfer registers"));
bd340a04 12909
c19d1205
ZW
12910 inst.instruction |= inst.operands[0].reg << 12;
12911 inst.instruction |= inst.operands[1].reg << 8;
12912 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12913}
12914
c19d1205
ZW
12915static void
12916do_t_ldstt (void)
12917{
12918 inst.instruction |= inst.operands[0].reg << 12;
12919 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12920}
a737bd4d 12921
b99bd4ef 12922static void
c19d1205 12923do_t_mla (void)
b99bd4ef 12924{
fdfde340 12925 unsigned Rd, Rn, Rm, Ra;
c921be7d 12926
fdfde340
JM
12927 Rd = inst.operands[0].reg;
12928 Rn = inst.operands[1].reg;
12929 Rm = inst.operands[2].reg;
12930 Ra = inst.operands[3].reg;
12931
12932 reject_bad_reg (Rd);
12933 reject_bad_reg (Rn);
12934 reject_bad_reg (Rm);
12935 reject_bad_reg (Ra);
12936
12937 inst.instruction |= Rd << 8;
12938 inst.instruction |= Rn << 16;
12939 inst.instruction |= Rm;
12940 inst.instruction |= Ra << 12;
c19d1205 12941}
b99bd4ef 12942
c19d1205
ZW
12943static void
12944do_t_mlal (void)
12945{
fdfde340
JM
12946 unsigned RdLo, RdHi, Rn, Rm;
12947
12948 RdLo = inst.operands[0].reg;
12949 RdHi = inst.operands[1].reg;
12950 Rn = inst.operands[2].reg;
12951 Rm = inst.operands[3].reg;
12952
12953 reject_bad_reg (RdLo);
12954 reject_bad_reg (RdHi);
12955 reject_bad_reg (Rn);
12956 reject_bad_reg (Rm);
12957
12958 inst.instruction |= RdLo << 12;
12959 inst.instruction |= RdHi << 8;
12960 inst.instruction |= Rn << 16;
12961 inst.instruction |= Rm;
c19d1205 12962}
b99bd4ef 12963
c19d1205
ZW
12964static void
12965do_t_mov_cmp (void)
12966{
fdfde340
JM
12967 unsigned Rn, Rm;
12968
12969 Rn = inst.operands[0].reg;
12970 Rm = inst.operands[1].reg;
12971
e07e6e58 12972 if (Rn == REG_PC)
5ee91343 12973 set_pred_insn_type_last ();
e07e6e58 12974
c19d1205 12975 if (unified_syntax)
b99bd4ef 12976 {
c19d1205
ZW
12977 int r0off = (inst.instruction == T_MNEM_mov
12978 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12979 unsigned long opcode;
3d388997
PB
12980 bfd_boolean narrow;
12981 bfd_boolean low_regs;
12982
fdfde340 12983 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12984 opcode = inst.instruction;
5ee91343 12985 if (in_pred_block ())
0110f2b8 12986 narrow = opcode != T_MNEM_movs;
3d388997 12987 else
0110f2b8 12988 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12989 if (inst.size_req == 4
12990 || inst.operands[1].shifted)
12991 narrow = FALSE;
12992
efd81785
PB
12993 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12994 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12995 && !inst.operands[1].shifted
fdfde340
JM
12996 && Rn == REG_PC
12997 && Rm == REG_LR)
efd81785
PB
12998 {
12999 inst.instruction = T2_SUBS_PC_LR;
13000 return;
13001 }
13002
fdfde340
JM
13003 if (opcode == T_MNEM_cmp)
13004 {
13005 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
13006 if (narrow)
13007 {
13008 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13009 but valid. */
13010 warn_deprecated_sp (Rm);
13011 /* R15 was documented as a valid choice for Rm in ARMv6,
13012 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13013 tools reject R15, so we do too. */
13014 constraint (Rm == REG_PC, BAD_PC);
13015 }
13016 else
13017 reject_bad_reg (Rm);
fdfde340
JM
13018 }
13019 else if (opcode == T_MNEM_mov
13020 || opcode == T_MNEM_movs)
13021 {
13022 if (inst.operands[1].isreg)
13023 {
13024 if (opcode == T_MNEM_movs)
13025 {
13026 reject_bad_reg (Rn);
13027 reject_bad_reg (Rm);
13028 }
76fa04a4
MGD
13029 else if (narrow)
13030 {
13031 /* This is mov.n. */
13032 if ((Rn == REG_SP || Rn == REG_PC)
13033 && (Rm == REG_SP || Rm == REG_PC))
13034 {
5c3696f8 13035 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
13036 "deprecated when r%u is the destination "
13037 "register."), Rm, Rn);
13038 }
13039 }
13040 else
13041 {
13042 /* This is mov.w. */
13043 constraint (Rn == REG_PC, BAD_PC);
13044 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
13045 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13046 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 13047 }
fdfde340
JM
13048 }
13049 else
13050 reject_bad_reg (Rn);
13051 }
13052
c19d1205
ZW
13053 if (!inst.operands[1].isreg)
13054 {
0110f2b8 13055 /* Immediate operand. */
5ee91343 13056 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
13057 narrow = 0;
13058 if (low_regs && narrow)
13059 {
13060 inst.instruction = THUMB_OP16 (opcode);
fdfde340 13061 inst.instruction |= Rn << 8;
e2b0ab59
AV
13062 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13063 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 13064 {
a9f02af8 13065 if (inst.size_req == 2)
e2b0ab59 13066 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
13067 else
13068 inst.relax = opcode;
72d98d16 13069 }
0110f2b8
PB
13070 }
13071 else
13072 {
e2b0ab59
AV
13073 constraint ((inst.relocs[0].type
13074 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13075 && (inst.relocs[0].type
13076 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
13077 THUMB1_RELOC_ONLY);
13078
0110f2b8
PB
13079 inst.instruction = THUMB_OP32 (inst.instruction);
13080 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13081 inst.instruction |= Rn << r0off;
e2b0ab59 13082 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 13083 }
c19d1205 13084 }
728ca7c9
PB
13085 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13086 && (inst.instruction == T_MNEM_mov
13087 || inst.instruction == T_MNEM_movs))
13088 {
13089 /* Register shifts are encoded as separate shift instructions. */
13090 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13091
5ee91343 13092 if (in_pred_block ())
728ca7c9
PB
13093 narrow = !flags;
13094 else
13095 narrow = flags;
13096
13097 if (inst.size_req == 4)
13098 narrow = FALSE;
13099
13100 if (!low_regs || inst.operands[1].imm > 7)
13101 narrow = FALSE;
13102
fdfde340 13103 if (Rn != Rm)
728ca7c9
PB
13104 narrow = FALSE;
13105
13106 switch (inst.operands[1].shift_kind)
13107 {
13108 case SHIFT_LSL:
13109 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13110 break;
13111 case SHIFT_ASR:
13112 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13113 break;
13114 case SHIFT_LSR:
13115 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13116 break;
13117 case SHIFT_ROR:
13118 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13119 break;
13120 default:
5f4273c7 13121 abort ();
728ca7c9
PB
13122 }
13123
13124 inst.instruction = opcode;
13125 if (narrow)
13126 {
fdfde340 13127 inst.instruction |= Rn;
728ca7c9
PB
13128 inst.instruction |= inst.operands[1].imm << 3;
13129 }
13130 else
13131 {
13132 if (flags)
13133 inst.instruction |= CONDS_BIT;
13134
fdfde340
JM
13135 inst.instruction |= Rn << 8;
13136 inst.instruction |= Rm << 16;
728ca7c9
PB
13137 inst.instruction |= inst.operands[1].imm;
13138 }
13139 }
3d388997 13140 else if (!narrow)
c19d1205 13141 {
728ca7c9
PB
13142 /* Some mov with immediate shift have narrow variants.
13143 Register shifts are handled above. */
13144 if (low_regs && inst.operands[1].shifted
13145 && (inst.instruction == T_MNEM_mov
13146 || inst.instruction == T_MNEM_movs))
13147 {
5ee91343 13148 if (in_pred_block ())
728ca7c9
PB
13149 narrow = (inst.instruction == T_MNEM_mov);
13150 else
13151 narrow = (inst.instruction == T_MNEM_movs);
13152 }
13153
13154 if (narrow)
13155 {
13156 switch (inst.operands[1].shift_kind)
13157 {
13158 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13159 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13160 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13161 default: narrow = FALSE; break;
13162 }
13163 }
13164
13165 if (narrow)
13166 {
fdfde340
JM
13167 inst.instruction |= Rn;
13168 inst.instruction |= Rm << 3;
e2b0ab59 13169 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13170 }
13171 else
13172 {
13173 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13174 inst.instruction |= Rn << r0off;
728ca7c9
PB
13175 encode_thumb32_shifted_operand (1);
13176 }
c19d1205
ZW
13177 }
13178 else
13179 switch (inst.instruction)
13180 {
13181 case T_MNEM_mov:
837b3435 13182 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13183 results. Don't allow this. */
13184 if (low_regs)
13185 {
13186 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13187 "MOV Rd, Rs with two low registers is not "
13188 "permitted on this architecture");
fa94de6b 13189 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13190 arm_ext_v6);
13191 }
13192
c19d1205 13193 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13194 inst.instruction |= (Rn & 0x8) << 4;
13195 inst.instruction |= (Rn & 0x7);
13196 inst.instruction |= Rm << 3;
c19d1205 13197 break;
b99bd4ef 13198
c19d1205
ZW
13199 case T_MNEM_movs:
13200 /* We know we have low registers at this point.
941a8a52
MGD
13201 Generate LSLS Rd, Rs, #0. */
13202 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13203 inst.instruction |= Rn;
13204 inst.instruction |= Rm << 3;
c19d1205
ZW
13205 break;
13206
13207 case T_MNEM_cmp:
3d388997 13208 if (low_regs)
c19d1205
ZW
13209 {
13210 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13211 inst.instruction |= Rn;
13212 inst.instruction |= Rm << 3;
c19d1205
ZW
13213 }
13214 else
13215 {
13216 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13217 inst.instruction |= (Rn & 0x8) << 4;
13218 inst.instruction |= (Rn & 0x7);
13219 inst.instruction |= Rm << 3;
c19d1205
ZW
13220 }
13221 break;
13222 }
b99bd4ef
NC
13223 return;
13224 }
13225
c19d1205 13226 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13227
13228 /* PR 10443: Do not silently ignore shifted operands. */
13229 constraint (inst.operands[1].shifted,
13230 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13231
c19d1205 13232 if (inst.operands[1].isreg)
b99bd4ef 13233 {
fdfde340 13234 if (Rn < 8 && Rm < 8)
b99bd4ef 13235 {
c19d1205
ZW
13236 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13237 since a MOV instruction produces unpredictable results. */
13238 if (inst.instruction == T_OPCODE_MOV_I8)
13239 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13240 else
c19d1205 13241 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13242
fdfde340
JM
13243 inst.instruction |= Rn;
13244 inst.instruction |= Rm << 3;
b99bd4ef
NC
13245 }
13246 else
13247 {
c19d1205
ZW
13248 if (inst.instruction == T_OPCODE_MOV_I8)
13249 inst.instruction = T_OPCODE_MOV_HR;
13250 else
13251 inst.instruction = T_OPCODE_CMP_HR;
13252 do_t_cpy ();
b99bd4ef
NC
13253 }
13254 }
c19d1205 13255 else
b99bd4ef 13256 {
fdfde340 13257 constraint (Rn > 7,
c19d1205 13258 _("only lo regs allowed with immediate"));
fdfde340 13259 inst.instruction |= Rn << 8;
e2b0ab59 13260 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13261 }
13262}
b99bd4ef 13263
c19d1205
ZW
13264static void
13265do_t_mov16 (void)
13266{
fdfde340 13267 unsigned Rd;
b6895b4f
PB
13268 bfd_vma imm;
13269 bfd_boolean top;
13270
13271 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13272 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13273 {
33eaf5de 13274 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13275 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13276 }
e2b0ab59 13277 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13278 {
33eaf5de 13279 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13280 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13281 }
13282
fdfde340
JM
13283 Rd = inst.operands[0].reg;
13284 reject_bad_reg (Rd);
13285
13286 inst.instruction |= Rd << 8;
e2b0ab59 13287 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13288 {
e2b0ab59 13289 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13290 inst.instruction |= (imm & 0xf000) << 4;
13291 inst.instruction |= (imm & 0x0800) << 15;
13292 inst.instruction |= (imm & 0x0700) << 4;
13293 inst.instruction |= (imm & 0x00ff);
13294 }
c19d1205 13295}
b99bd4ef 13296
c19d1205
ZW
13297static void
13298do_t_mvn_tst (void)
13299{
fdfde340 13300 unsigned Rn, Rm;
c921be7d 13301
fdfde340
JM
13302 Rn = inst.operands[0].reg;
13303 Rm = inst.operands[1].reg;
13304
13305 if (inst.instruction == T_MNEM_cmp
13306 || inst.instruction == T_MNEM_cmn)
13307 constraint (Rn == REG_PC, BAD_PC);
13308 else
13309 reject_bad_reg (Rn);
13310 reject_bad_reg (Rm);
13311
c19d1205
ZW
13312 if (unified_syntax)
13313 {
13314 int r0off = (inst.instruction == T_MNEM_mvn
13315 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13316 bfd_boolean narrow;
13317
13318 if (inst.size_req == 4
13319 || inst.instruction > 0xffff
13320 || inst.operands[1].shifted
fdfde340 13321 || Rn > 7 || Rm > 7)
3d388997 13322 narrow = FALSE;
fe8b4cc3
KT
13323 else if (inst.instruction == T_MNEM_cmn
13324 || inst.instruction == T_MNEM_tst)
3d388997
PB
13325 narrow = TRUE;
13326 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13327 narrow = !in_pred_block ();
3d388997 13328 else
5ee91343 13329 narrow = in_pred_block ();
3d388997 13330
c19d1205 13331 if (!inst.operands[1].isreg)
b99bd4ef 13332 {
c19d1205
ZW
13333 /* For an immediate, we always generate a 32-bit opcode;
13334 section relaxation will shrink it later if possible. */
13335 if (inst.instruction < 0xffff)
13336 inst.instruction = THUMB_OP32 (inst.instruction);
13337 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13338 inst.instruction |= Rn << r0off;
e2b0ab59 13339 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13340 }
c19d1205 13341 else
b99bd4ef 13342 {
c19d1205 13343 /* See if we can do this with a 16-bit instruction. */
3d388997 13344 if (narrow)
b99bd4ef 13345 {
c19d1205 13346 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13347 inst.instruction |= Rn;
13348 inst.instruction |= Rm << 3;
b99bd4ef 13349 }
c19d1205 13350 else
b99bd4ef 13351 {
c19d1205
ZW
13352 constraint (inst.operands[1].shifted
13353 && inst.operands[1].immisreg,
13354 _("shift must be constant"));
13355 if (inst.instruction < 0xffff)
13356 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13357 inst.instruction |= Rn << r0off;
c19d1205 13358 encode_thumb32_shifted_operand (1);
b99bd4ef 13359 }
b99bd4ef
NC
13360 }
13361 }
13362 else
13363 {
c19d1205
ZW
13364 constraint (inst.instruction > 0xffff
13365 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13366 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13367 _("unshifted register required"));
fdfde340 13368 constraint (Rn > 7 || Rm > 7,
c19d1205 13369 BAD_HIREG);
b99bd4ef 13370
c19d1205 13371 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13372 inst.instruction |= Rn;
13373 inst.instruction |= Rm << 3;
b99bd4ef 13374 }
b99bd4ef
NC
13375}
13376
b05fe5cf 13377static void
c19d1205 13378do_t_mrs (void)
b05fe5cf 13379{
fdfde340 13380 unsigned Rd;
037e8744
JB
13381
13382 if (do_vfp_nsyn_mrs () == SUCCESS)
13383 return;
13384
90ec0d68
MGD
13385 Rd = inst.operands[0].reg;
13386 reject_bad_reg (Rd);
13387 inst.instruction |= Rd << 8;
13388
13389 if (inst.operands[1].isreg)
62b3e311 13390 {
90ec0d68
MGD
13391 unsigned br = inst.operands[1].reg;
13392 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13393 as_bad (_("bad register for mrs"));
13394
13395 inst.instruction |= br & (0xf << 16);
13396 inst.instruction |= (br & 0x300) >> 4;
13397 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13398 }
13399 else
13400 {
90ec0d68 13401 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13402
d2cd1205 13403 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13404 {
13405 /* PR gas/12698: The constraint is only applied for m_profile.
13406 If the user has specified -march=all, we want to ignore it as
13407 we are building for any CPU type, including non-m variants. */
823d2571
TG
13408 bfd_boolean m_profile =
13409 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13410 constraint ((flags != 0) && m_profile, _("selected processor does "
13411 "not support requested special purpose register"));
13412 }
90ec0d68 13413 else
d2cd1205
JB
13414 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13415 devices). */
13416 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13417 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13418
90ec0d68
MGD
13419 inst.instruction |= (flags & SPSR_BIT) >> 2;
13420 inst.instruction |= inst.operands[1].imm & 0xff;
13421 inst.instruction |= 0xf0000;
13422 }
c19d1205 13423}
b05fe5cf 13424
c19d1205
ZW
13425static void
13426do_t_msr (void)
13427{
62b3e311 13428 int flags;
fdfde340 13429 unsigned Rn;
62b3e311 13430
037e8744
JB
13431 if (do_vfp_nsyn_msr () == SUCCESS)
13432 return;
13433
c19d1205
ZW
13434 constraint (!inst.operands[1].isreg,
13435 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13436
13437 if (inst.operands[0].isreg)
13438 flags = (int)(inst.operands[0].reg);
13439 else
13440 flags = inst.operands[0].imm;
13441
d2cd1205 13442 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13443 {
d2cd1205
JB
13444 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13445
1a43faaf 13446 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13447 If the user has specified -march=all, we want to ignore it as
13448 we are building for any CPU type, including non-m variants. */
823d2571
TG
13449 bfd_boolean m_profile =
13450 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13451 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13452 && (bits & ~(PSR_s | PSR_f)) != 0)
13453 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13454 && bits != PSR_f)) && m_profile,
13455 _("selected processor does not support requested special "
13456 "purpose register"));
62b3e311
PB
13457 }
13458 else
d2cd1205
JB
13459 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13460 "requested special purpose register"));
c921be7d 13461
fdfde340
JM
13462 Rn = inst.operands[1].reg;
13463 reject_bad_reg (Rn);
13464
62b3e311 13465 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13466 inst.instruction |= (flags & 0xf0000) >> 8;
13467 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13468 inst.instruction |= (flags & 0xff);
fdfde340 13469 inst.instruction |= Rn << 16;
c19d1205 13470}
b05fe5cf 13471
c19d1205
ZW
13472static void
13473do_t_mul (void)
13474{
17828f45 13475 bfd_boolean narrow;
fdfde340 13476 unsigned Rd, Rn, Rm;
17828f45 13477
c19d1205
ZW
13478 if (!inst.operands[2].present)
13479 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13480
fdfde340
JM
13481 Rd = inst.operands[0].reg;
13482 Rn = inst.operands[1].reg;
13483 Rm = inst.operands[2].reg;
13484
17828f45 13485 if (unified_syntax)
b05fe5cf 13486 {
17828f45 13487 if (inst.size_req == 4
fdfde340
JM
13488 || (Rd != Rn
13489 && Rd != Rm)
13490 || Rn > 7
13491 || Rm > 7)
17828f45
JM
13492 narrow = FALSE;
13493 else if (inst.instruction == T_MNEM_muls)
5ee91343 13494 narrow = !in_pred_block ();
17828f45 13495 else
5ee91343 13496 narrow = in_pred_block ();
b05fe5cf 13497 }
c19d1205 13498 else
b05fe5cf 13499 {
17828f45 13500 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13501 constraint (Rn > 7 || Rm > 7,
c19d1205 13502 BAD_HIREG);
17828f45
JM
13503 narrow = TRUE;
13504 }
b05fe5cf 13505
17828f45
JM
13506 if (narrow)
13507 {
13508 /* 16-bit MULS/Conditional MUL. */
c19d1205 13509 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13510 inst.instruction |= Rd;
b05fe5cf 13511
fdfde340
JM
13512 if (Rd == Rn)
13513 inst.instruction |= Rm << 3;
13514 else if (Rd == Rm)
13515 inst.instruction |= Rn << 3;
c19d1205
ZW
13516 else
13517 constraint (1, _("dest must overlap one source register"));
13518 }
17828f45
JM
13519 else
13520 {
e07e6e58
NC
13521 constraint (inst.instruction != T_MNEM_mul,
13522 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13523 /* 32-bit MUL. */
13524 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13525 inst.instruction |= Rd << 8;
13526 inst.instruction |= Rn << 16;
13527 inst.instruction |= Rm << 0;
13528
13529 reject_bad_reg (Rd);
13530 reject_bad_reg (Rn);
13531 reject_bad_reg (Rm);
17828f45 13532 }
c19d1205 13533}
b05fe5cf 13534
c19d1205
ZW
13535static void
13536do_t_mull (void)
13537{
fdfde340 13538 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13539
fdfde340
JM
13540 RdLo = inst.operands[0].reg;
13541 RdHi = inst.operands[1].reg;
13542 Rn = inst.operands[2].reg;
13543 Rm = inst.operands[3].reg;
13544
13545 reject_bad_reg (RdLo);
13546 reject_bad_reg (RdHi);
13547 reject_bad_reg (Rn);
13548 reject_bad_reg (Rm);
13549
13550 inst.instruction |= RdLo << 12;
13551 inst.instruction |= RdHi << 8;
13552 inst.instruction |= Rn << 16;
13553 inst.instruction |= Rm;
13554
13555 if (RdLo == RdHi)
c19d1205
ZW
13556 as_tsktsk (_("rdhi and rdlo must be different"));
13557}
b05fe5cf 13558
c19d1205
ZW
13559static void
13560do_t_nop (void)
13561{
5ee91343 13562 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13563
c19d1205
ZW
13564 if (unified_syntax)
13565 {
13566 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13567 {
c19d1205
ZW
13568 inst.instruction = THUMB_OP32 (inst.instruction);
13569 inst.instruction |= inst.operands[0].imm;
13570 }
13571 else
13572 {
bc2d1808
NC
13573 /* PR9722: Check for Thumb2 availability before
13574 generating a thumb2 nop instruction. */
afa62d5e 13575 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13576 {
13577 inst.instruction = THUMB_OP16 (inst.instruction);
13578 inst.instruction |= inst.operands[0].imm << 4;
13579 }
13580 else
13581 inst.instruction = 0x46c0;
c19d1205
ZW
13582 }
13583 }
13584 else
13585 {
13586 constraint (inst.operands[0].present,
13587 _("Thumb does not support NOP with hints"));
13588 inst.instruction = 0x46c0;
13589 }
13590}
b05fe5cf 13591
c19d1205
ZW
13592static void
13593do_t_neg (void)
13594{
13595 if (unified_syntax)
13596 {
3d388997
PB
13597 bfd_boolean narrow;
13598
13599 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13600 narrow = !in_pred_block ();
3d388997 13601 else
5ee91343 13602 narrow = in_pred_block ();
3d388997
PB
13603 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13604 narrow = FALSE;
13605 if (inst.size_req == 4)
13606 narrow = FALSE;
13607
13608 if (!narrow)
c19d1205
ZW
13609 {
13610 inst.instruction = THUMB_OP32 (inst.instruction);
13611 inst.instruction |= inst.operands[0].reg << 8;
13612 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13613 }
13614 else
13615 {
c19d1205
ZW
13616 inst.instruction = THUMB_OP16 (inst.instruction);
13617 inst.instruction |= inst.operands[0].reg;
13618 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13619 }
13620 }
13621 else
13622 {
c19d1205
ZW
13623 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13624 BAD_HIREG);
13625 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13626
13627 inst.instruction = THUMB_OP16 (inst.instruction);
13628 inst.instruction |= inst.operands[0].reg;
13629 inst.instruction |= inst.operands[1].reg << 3;
13630 }
13631}
13632
1c444d06
JM
13633static void
13634do_t_orn (void)
13635{
13636 unsigned Rd, Rn;
13637
13638 Rd = inst.operands[0].reg;
13639 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13640
fdfde340
JM
13641 reject_bad_reg (Rd);
13642 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13643 reject_bad_reg (Rn);
13644
1c444d06
JM
13645 inst.instruction |= Rd << 8;
13646 inst.instruction |= Rn << 16;
13647
13648 if (!inst.operands[2].isreg)
13649 {
13650 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13651 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13652 }
13653 else
13654 {
13655 unsigned Rm;
13656
13657 Rm = inst.operands[2].reg;
fdfde340 13658 reject_bad_reg (Rm);
1c444d06
JM
13659
13660 constraint (inst.operands[2].shifted
13661 && inst.operands[2].immisreg,
13662 _("shift must be constant"));
13663 encode_thumb32_shifted_operand (2);
13664 }
13665}
13666
c19d1205
ZW
13667static void
13668do_t_pkhbt (void)
13669{
fdfde340
JM
13670 unsigned Rd, Rn, Rm;
13671
13672 Rd = inst.operands[0].reg;
13673 Rn = inst.operands[1].reg;
13674 Rm = inst.operands[2].reg;
13675
13676 reject_bad_reg (Rd);
13677 reject_bad_reg (Rn);
13678 reject_bad_reg (Rm);
13679
13680 inst.instruction |= Rd << 8;
13681 inst.instruction |= Rn << 16;
13682 inst.instruction |= Rm;
c19d1205
ZW
13683 if (inst.operands[3].present)
13684 {
e2b0ab59
AV
13685 unsigned int val = inst.relocs[0].exp.X_add_number;
13686 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13687 _("expression too complex"));
13688 inst.instruction |= (val & 0x1c) << 10;
13689 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13690 }
c19d1205 13691}
b05fe5cf 13692
c19d1205
ZW
13693static void
13694do_t_pkhtb (void)
13695{
13696 if (!inst.operands[3].present)
1ef52f49
NC
13697 {
13698 unsigned Rtmp;
13699
13700 inst.instruction &= ~0x00000020;
13701
13702 /* PR 10168. Swap the Rm and Rn registers. */
13703 Rtmp = inst.operands[1].reg;
13704 inst.operands[1].reg = inst.operands[2].reg;
13705 inst.operands[2].reg = Rtmp;
13706 }
c19d1205 13707 do_t_pkhbt ();
b05fe5cf
ZW
13708}
13709
c19d1205
ZW
13710static void
13711do_t_pld (void)
13712{
fdfde340
JM
13713 if (inst.operands[0].immisreg)
13714 reject_bad_reg (inst.operands[0].imm);
13715
c19d1205
ZW
13716 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13717}
b05fe5cf 13718
c19d1205
ZW
13719static void
13720do_t_push_pop (void)
b99bd4ef 13721{
e9f89963 13722 unsigned mask;
5f4273c7 13723
c19d1205
ZW
13724 constraint (inst.operands[0].writeback,
13725 _("push/pop do not support {reglist}^"));
e2b0ab59 13726 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13727 _("expression too complex"));
b99bd4ef 13728
e9f89963 13729 mask = inst.operands[0].imm;
d3bfe16e 13730 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13731 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13732 else if (inst.size_req != 4
c6025a80 13733 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13734 ? REG_LR : REG_PC)))
b99bd4ef 13735 {
c19d1205
ZW
13736 inst.instruction = THUMB_OP16 (inst.instruction);
13737 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13738 inst.instruction |= mask & 0xff;
c19d1205
ZW
13739 }
13740 else if (unified_syntax)
13741 {
3c707909 13742 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13743 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13744 }
13745 else
13746 {
13747 inst.error = _("invalid register list to push/pop instruction");
13748 return;
c19d1205 13749 }
4b5a202f
AV
13750}
13751
13752static void
13753do_t_clrm (void)
13754{
13755 if (unified_syntax)
13756 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13757 else
13758 {
13759 inst.error = _("invalid register list to push/pop instruction");
13760 return;
13761 }
c19d1205 13762}
b99bd4ef 13763
efd6b359
AV
13764static void
13765do_t_vscclrm (void)
13766{
13767 if (inst.operands[0].issingle)
13768 {
13769 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13770 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13771 inst.instruction |= inst.operands[0].imm;
13772 }
13773 else
13774 {
13775 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13776 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13777 inst.instruction |= 1 << 8;
13778 inst.instruction |= inst.operands[0].imm << 1;
13779 }
13780}
13781
c19d1205
ZW
13782static void
13783do_t_rbit (void)
13784{
fdfde340
JM
13785 unsigned Rd, Rm;
13786
13787 Rd = inst.operands[0].reg;
13788 Rm = inst.operands[1].reg;
13789
13790 reject_bad_reg (Rd);
13791 reject_bad_reg (Rm);
13792
13793 inst.instruction |= Rd << 8;
13794 inst.instruction |= Rm << 16;
13795 inst.instruction |= Rm;
c19d1205 13796}
b99bd4ef 13797
c19d1205
ZW
13798static void
13799do_t_rev (void)
13800{
fdfde340
JM
13801 unsigned Rd, Rm;
13802
13803 Rd = inst.operands[0].reg;
13804 Rm = inst.operands[1].reg;
13805
13806 reject_bad_reg (Rd);
13807 reject_bad_reg (Rm);
13808
13809 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13810 && inst.size_req != 4)
13811 {
13812 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13813 inst.instruction |= Rd;
13814 inst.instruction |= Rm << 3;
c19d1205
ZW
13815 }
13816 else if (unified_syntax)
13817 {
13818 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13819 inst.instruction |= Rd << 8;
13820 inst.instruction |= Rm << 16;
13821 inst.instruction |= Rm;
c19d1205
ZW
13822 }
13823 else
13824 inst.error = BAD_HIREG;
13825}
b99bd4ef 13826
1c444d06
JM
13827static void
13828do_t_rrx (void)
13829{
13830 unsigned Rd, Rm;
13831
13832 Rd = inst.operands[0].reg;
13833 Rm = inst.operands[1].reg;
13834
fdfde340
JM
13835 reject_bad_reg (Rd);
13836 reject_bad_reg (Rm);
c921be7d 13837
1c444d06
JM
13838 inst.instruction |= Rd << 8;
13839 inst.instruction |= Rm;
13840}
13841
c19d1205
ZW
13842static void
13843do_t_rsb (void)
13844{
fdfde340 13845 unsigned Rd, Rs;
b99bd4ef 13846
c19d1205
ZW
13847 Rd = inst.operands[0].reg;
13848 Rs = (inst.operands[1].present
13849 ? inst.operands[1].reg /* Rd, Rs, foo */
13850 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13851
fdfde340
JM
13852 reject_bad_reg (Rd);
13853 reject_bad_reg (Rs);
13854 if (inst.operands[2].isreg)
13855 reject_bad_reg (inst.operands[2].reg);
13856
c19d1205
ZW
13857 inst.instruction |= Rd << 8;
13858 inst.instruction |= Rs << 16;
13859 if (!inst.operands[2].isreg)
13860 {
026d3abb
PB
13861 bfd_boolean narrow;
13862
13863 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13864 narrow = !in_pred_block ();
026d3abb 13865 else
5ee91343 13866 narrow = in_pred_block ();
026d3abb
PB
13867
13868 if (Rd > 7 || Rs > 7)
13869 narrow = FALSE;
13870
13871 if (inst.size_req == 4 || !unified_syntax)
13872 narrow = FALSE;
13873
e2b0ab59
AV
13874 if (inst.relocs[0].exp.X_op != O_constant
13875 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13876 narrow = FALSE;
13877
13878 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13879 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13880 if (narrow)
13881 {
e2b0ab59 13882 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13883 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13884 inst.instruction |= Rs << 3;
13885 inst.instruction |= Rd;
13886 }
13887 else
13888 {
13889 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13890 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13891 }
c19d1205
ZW
13892 }
13893 else
13894 encode_thumb32_shifted_operand (2);
13895}
b99bd4ef 13896
c19d1205
ZW
13897static void
13898do_t_setend (void)
13899{
12e37cbc
MGD
13900 if (warn_on_deprecated
13901 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13902 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13903
5ee91343 13904 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13905 if (inst.operands[0].imm)
13906 inst.instruction |= 0x8;
13907}
b99bd4ef 13908
c19d1205
ZW
13909static void
13910do_t_shift (void)
13911{
13912 if (!inst.operands[1].present)
13913 inst.operands[1].reg = inst.operands[0].reg;
13914
13915 if (unified_syntax)
13916 {
3d388997
PB
13917 bfd_boolean narrow;
13918 int shift_kind;
13919
13920 switch (inst.instruction)
13921 {
13922 case T_MNEM_asr:
13923 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13924 case T_MNEM_lsl:
13925 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13926 case T_MNEM_lsr:
13927 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13928 case T_MNEM_ror:
13929 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13930 default: abort ();
13931 }
13932
13933 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13934 narrow = !in_pred_block ();
3d388997 13935 else
5ee91343 13936 narrow = in_pred_block ();
3d388997
PB
13937 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13938 narrow = FALSE;
13939 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13940 narrow = FALSE;
13941 if (inst.operands[2].isreg
13942 && (inst.operands[1].reg != inst.operands[0].reg
13943 || inst.operands[2].reg > 7))
13944 narrow = FALSE;
13945 if (inst.size_req == 4)
13946 narrow = FALSE;
13947
fdfde340
JM
13948 reject_bad_reg (inst.operands[0].reg);
13949 reject_bad_reg (inst.operands[1].reg);
c921be7d 13950
3d388997 13951 if (!narrow)
c19d1205
ZW
13952 {
13953 if (inst.operands[2].isreg)
b99bd4ef 13954 {
fdfde340 13955 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13956 inst.instruction = THUMB_OP32 (inst.instruction);
13957 inst.instruction |= inst.operands[0].reg << 8;
13958 inst.instruction |= inst.operands[1].reg << 16;
13959 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13960
13961 /* PR 12854: Error on extraneous shifts. */
13962 constraint (inst.operands[2].shifted,
13963 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13964 }
13965 else
13966 {
13967 inst.operands[1].shifted = 1;
3d388997 13968 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13969 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13970 ? T_MNEM_movs : T_MNEM_mov);
13971 inst.instruction |= inst.operands[0].reg << 8;
13972 encode_thumb32_shifted_operand (1);
13973 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13974 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13975 }
13976 }
13977 else
13978 {
c19d1205 13979 if (inst.operands[2].isreg)
b99bd4ef 13980 {
3d388997 13981 switch (shift_kind)
b99bd4ef 13982 {
3d388997
PB
13983 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13984 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13985 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13986 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13987 default: abort ();
b99bd4ef 13988 }
5f4273c7 13989
c19d1205
ZW
13990 inst.instruction |= inst.operands[0].reg;
13991 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13992
13993 /* PR 12854: Error on extraneous shifts. */
13994 constraint (inst.operands[2].shifted,
13995 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13996 }
13997 else
13998 {
3d388997 13999 switch (shift_kind)
b99bd4ef 14000 {
3d388997
PB
14001 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
14002 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
14003 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 14004 default: abort ();
b99bd4ef 14005 }
e2b0ab59 14006 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14007 inst.instruction |= inst.operands[0].reg;
14008 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14009 }
14010 }
c19d1205
ZW
14011 }
14012 else
14013 {
14014 constraint (inst.operands[0].reg > 7
14015 || inst.operands[1].reg > 7, BAD_HIREG);
14016 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 14017
c19d1205
ZW
14018 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14019 {
14020 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14021 constraint (inst.operands[0].reg != inst.operands[1].reg,
14022 _("source1 and dest must be same register"));
b99bd4ef 14023
c19d1205
ZW
14024 switch (inst.instruction)
14025 {
14026 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14027 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14028 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14029 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14030 default: abort ();
14031 }
5f4273c7 14032
c19d1205
ZW
14033 inst.instruction |= inst.operands[0].reg;
14034 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
14035
14036 /* PR 12854: Error on extraneous shifts. */
14037 constraint (inst.operands[2].shifted,
14038 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
14039 }
14040 else
b99bd4ef 14041 {
c19d1205
ZW
14042 switch (inst.instruction)
14043 {
14044 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14045 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14046 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14047 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14048 default: abort ();
14049 }
e2b0ab59 14050 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14051 inst.instruction |= inst.operands[0].reg;
14052 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14053 }
14054 }
b99bd4ef
NC
14055}
14056
14057static void
c19d1205 14058do_t_simd (void)
b99bd4ef 14059{
fdfde340
JM
14060 unsigned Rd, Rn, Rm;
14061
14062 Rd = inst.operands[0].reg;
14063 Rn = inst.operands[1].reg;
14064 Rm = inst.operands[2].reg;
14065
14066 reject_bad_reg (Rd);
14067 reject_bad_reg (Rn);
14068 reject_bad_reg (Rm);
14069
14070 inst.instruction |= Rd << 8;
14071 inst.instruction |= Rn << 16;
14072 inst.instruction |= Rm;
c19d1205 14073}
b99bd4ef 14074
03ee1b7f
NC
14075static void
14076do_t_simd2 (void)
14077{
14078 unsigned Rd, Rn, Rm;
14079
14080 Rd = inst.operands[0].reg;
14081 Rm = inst.operands[1].reg;
14082 Rn = inst.operands[2].reg;
14083
14084 reject_bad_reg (Rd);
14085 reject_bad_reg (Rn);
14086 reject_bad_reg (Rm);
14087
14088 inst.instruction |= Rd << 8;
14089 inst.instruction |= Rn << 16;
14090 inst.instruction |= Rm;
14091}
14092
c19d1205 14093static void
3eb17e6b 14094do_t_smc (void)
c19d1205 14095{
e2b0ab59 14096 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
14097 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14098 _("SMC is not permitted on this architecture"));
e2b0ab59 14099 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14100 _("expression too complex"));
ba85f98c
BW
14101 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14102
e2b0ab59 14103 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 14104 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 14105
24382199 14106 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 14107 set_pred_insn_type_last ();
c19d1205 14108}
b99bd4ef 14109
90ec0d68
MGD
14110static void
14111do_t_hvc (void)
14112{
e2b0ab59 14113 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 14114
e2b0ab59 14115 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
14116 inst.instruction |= (value & 0x0fff);
14117 inst.instruction |= (value & 0xf000) << 4;
14118}
14119
c19d1205 14120static void
3a21c15a 14121do_t_ssat_usat (int bias)
c19d1205 14122{
fdfde340
JM
14123 unsigned Rd, Rn;
14124
14125 Rd = inst.operands[0].reg;
14126 Rn = inst.operands[2].reg;
14127
14128 reject_bad_reg (Rd);
14129 reject_bad_reg (Rn);
14130
14131 inst.instruction |= Rd << 8;
3a21c15a 14132 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 14133 inst.instruction |= Rn << 16;
b99bd4ef 14134
c19d1205 14135 if (inst.operands[3].present)
b99bd4ef 14136 {
e2b0ab59 14137 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 14138
e2b0ab59 14139 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 14140
e2b0ab59 14141 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14142 _("expression too complex"));
b99bd4ef 14143
3a21c15a 14144 if (shift_amount != 0)
6189168b 14145 {
3a21c15a
NC
14146 constraint (shift_amount > 31,
14147 _("shift expression is too large"));
14148
c19d1205 14149 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
14150 inst.instruction |= 0x00200000; /* sh bit. */
14151
14152 inst.instruction |= (shift_amount & 0x1c) << 10;
14153 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14154 }
14155 }
b99bd4ef 14156}
c921be7d 14157
3a21c15a
NC
14158static void
14159do_t_ssat (void)
14160{
14161 do_t_ssat_usat (1);
14162}
b99bd4ef 14163
0dd132b6 14164static void
c19d1205 14165do_t_ssat16 (void)
0dd132b6 14166{
fdfde340
JM
14167 unsigned Rd, Rn;
14168
14169 Rd = inst.operands[0].reg;
14170 Rn = inst.operands[2].reg;
14171
14172 reject_bad_reg (Rd);
14173 reject_bad_reg (Rn);
14174
14175 inst.instruction |= Rd << 8;
c19d1205 14176 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14177 inst.instruction |= Rn << 16;
c19d1205 14178}
0dd132b6 14179
c19d1205
ZW
14180static void
14181do_t_strex (void)
14182{
14183 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14184 || inst.operands[2].postind || inst.operands[2].writeback
14185 || inst.operands[2].immisreg || inst.operands[2].shifted
14186 || inst.operands[2].negative,
01cfc07f 14187 BAD_ADDR_MODE);
0dd132b6 14188
5be8be5d
DG
14189 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14190
c19d1205
ZW
14191 inst.instruction |= inst.operands[0].reg << 8;
14192 inst.instruction |= inst.operands[1].reg << 12;
14193 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14194 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14195}
14196
b99bd4ef 14197static void
c19d1205 14198do_t_strexd (void)
b99bd4ef 14199{
c19d1205
ZW
14200 if (!inst.operands[2].present)
14201 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14202
c19d1205
ZW
14203 constraint (inst.operands[0].reg == inst.operands[1].reg
14204 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14205 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14206 BAD_OVERLAP);
b99bd4ef 14207
c19d1205
ZW
14208 inst.instruction |= inst.operands[0].reg;
14209 inst.instruction |= inst.operands[1].reg << 12;
14210 inst.instruction |= inst.operands[2].reg << 8;
14211 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14212}
14213
14214static void
c19d1205 14215do_t_sxtah (void)
b99bd4ef 14216{
fdfde340
JM
14217 unsigned Rd, Rn, Rm;
14218
14219 Rd = inst.operands[0].reg;
14220 Rn = inst.operands[1].reg;
14221 Rm = inst.operands[2].reg;
14222
14223 reject_bad_reg (Rd);
14224 reject_bad_reg (Rn);
14225 reject_bad_reg (Rm);
14226
14227 inst.instruction |= Rd << 8;
14228 inst.instruction |= Rn << 16;
14229 inst.instruction |= Rm;
c19d1205
ZW
14230 inst.instruction |= inst.operands[3].imm << 4;
14231}
b99bd4ef 14232
c19d1205
ZW
14233static void
14234do_t_sxth (void)
14235{
fdfde340
JM
14236 unsigned Rd, Rm;
14237
14238 Rd = inst.operands[0].reg;
14239 Rm = inst.operands[1].reg;
14240
14241 reject_bad_reg (Rd);
14242 reject_bad_reg (Rm);
c921be7d
NC
14243
14244 if (inst.instruction <= 0xffff
14245 && inst.size_req != 4
fdfde340 14246 && Rd <= 7 && Rm <= 7
c19d1205 14247 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14248 {
c19d1205 14249 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14250 inst.instruction |= Rd;
14251 inst.instruction |= Rm << 3;
b99bd4ef 14252 }
c19d1205 14253 else if (unified_syntax)
b99bd4ef 14254 {
c19d1205
ZW
14255 if (inst.instruction <= 0xffff)
14256 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14257 inst.instruction |= Rd << 8;
14258 inst.instruction |= Rm;
c19d1205 14259 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14260 }
c19d1205 14261 else
b99bd4ef 14262 {
c19d1205
ZW
14263 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14264 _("Thumb encoding does not support rotation"));
14265 constraint (1, BAD_HIREG);
b99bd4ef 14266 }
c19d1205 14267}
b99bd4ef 14268
c19d1205
ZW
14269static void
14270do_t_swi (void)
14271{
e2b0ab59 14272 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14273}
b99bd4ef 14274
92e90b6e
PB
14275static void
14276do_t_tb (void)
14277{
fdfde340 14278 unsigned Rn, Rm;
92e90b6e
PB
14279 int half;
14280
14281 half = (inst.instruction & 0x10) != 0;
5ee91343 14282 set_pred_insn_type_last ();
dfa9f0d5
PB
14283 constraint (inst.operands[0].immisreg,
14284 _("instruction requires register index"));
fdfde340
JM
14285
14286 Rn = inst.operands[0].reg;
14287 Rm = inst.operands[0].imm;
c921be7d 14288
5c8ed6a4
JW
14289 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14290 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14291 reject_bad_reg (Rm);
14292
92e90b6e
PB
14293 constraint (!half && inst.operands[0].shifted,
14294 _("instruction does not allow shifted index"));
fdfde340 14295 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14296}
14297
74db7efb
NC
14298static void
14299do_t_udf (void)
14300{
14301 if (!inst.operands[0].present)
14302 inst.operands[0].imm = 0;
14303
14304 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14305 {
14306 constraint (inst.size_req == 2,
14307 _("immediate value out of range"));
14308 inst.instruction = THUMB_OP32 (inst.instruction);
14309 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14310 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14311 }
14312 else
14313 {
14314 inst.instruction = THUMB_OP16 (inst.instruction);
14315 inst.instruction |= inst.operands[0].imm;
14316 }
14317
5ee91343 14318 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14319}
14320
14321
c19d1205
ZW
14322static void
14323do_t_usat (void)
14324{
3a21c15a 14325 do_t_ssat_usat (0);
b99bd4ef
NC
14326}
14327
14328static void
c19d1205 14329do_t_usat16 (void)
b99bd4ef 14330{
fdfde340
JM
14331 unsigned Rd, Rn;
14332
14333 Rd = inst.operands[0].reg;
14334 Rn = inst.operands[2].reg;
14335
14336 reject_bad_reg (Rd);
14337 reject_bad_reg (Rn);
14338
14339 inst.instruction |= Rd << 8;
c19d1205 14340 inst.instruction |= inst.operands[1].imm;
fdfde340 14341 inst.instruction |= Rn << 16;
b99bd4ef 14342}
c19d1205 14343
e12437dc
AV
14344/* Checking the range of the branch offset (VAL) with NBITS bits
14345 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14346static int
14347v8_1_branch_value_check (int val, int nbits, int is_signed)
14348{
14349 gas_assert (nbits > 0 && nbits <= 32);
14350 if (is_signed)
14351 {
14352 int cmp = (1 << (nbits - 1));
14353 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14354 return FAIL;
14355 }
14356 else
14357 {
14358 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14359 return FAIL;
14360 }
14361 return SUCCESS;
14362}
14363
4389b29a
AV
14364/* For branches in Armv8.1-M Mainline. */
14365static void
14366do_t_branch_future (void)
14367{
14368 unsigned long insn = inst.instruction;
14369
14370 inst.instruction = THUMB_OP32 (inst.instruction);
14371 if (inst.operands[0].hasreloc == 0)
14372 {
14373 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14374 as_bad (BAD_BRANCH_OFF);
14375
14376 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14377 }
14378 else
14379 {
14380 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14381 inst.relocs[0].pc_rel = 1;
14382 }
14383
14384 switch (insn)
14385 {
14386 case T_MNEM_bf:
14387 if (inst.operands[1].hasreloc == 0)
14388 {
14389 int val = inst.operands[1].imm;
14390 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14391 as_bad (BAD_BRANCH_OFF);
14392
14393 int immA = (val & 0x0001f000) >> 12;
14394 int immB = (val & 0x00000ffc) >> 2;
14395 int immC = (val & 0x00000002) >> 1;
14396 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14397 }
14398 else
14399 {
14400 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14401 inst.relocs[1].pc_rel = 1;
14402 }
14403 break;
14404
65d1bc05
AV
14405 case T_MNEM_bfl:
14406 if (inst.operands[1].hasreloc == 0)
14407 {
14408 int val = inst.operands[1].imm;
14409 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14410 as_bad (BAD_BRANCH_OFF);
14411
14412 int immA = (val & 0x0007f000) >> 12;
14413 int immB = (val & 0x00000ffc) >> 2;
14414 int immC = (val & 0x00000002) >> 1;
14415 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14416 }
14417 else
14418 {
14419 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14420 inst.relocs[1].pc_rel = 1;
14421 }
14422 break;
14423
f6b2b12d
AV
14424 case T_MNEM_bfcsel:
14425 /* Operand 1. */
14426 if (inst.operands[1].hasreloc == 0)
14427 {
14428 int val = inst.operands[1].imm;
14429 int immA = (val & 0x00001000) >> 12;
14430 int immB = (val & 0x00000ffc) >> 2;
14431 int immC = (val & 0x00000002) >> 1;
14432 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14433 }
14434 else
14435 {
14436 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14437 inst.relocs[1].pc_rel = 1;
14438 }
14439
14440 /* Operand 2. */
14441 if (inst.operands[2].hasreloc == 0)
14442 {
14443 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14444 int val2 = inst.operands[2].imm;
14445 int val0 = inst.operands[0].imm & 0x1f;
14446 int diff = val2 - val0;
14447 if (diff == 4)
14448 inst.instruction |= 1 << 17; /* T bit. */
14449 else if (diff != 2)
14450 as_bad (_("out of range label-relative fixup value"));
14451 }
14452 else
14453 {
14454 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14455 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14456 inst.relocs[2].pc_rel = 1;
14457 }
14458
14459 /* Operand 3. */
14460 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14461 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14462 break;
14463
f1c7f421
AV
14464 case T_MNEM_bfx:
14465 case T_MNEM_bflx:
14466 inst.instruction |= inst.operands[1].reg << 16;
14467 break;
14468
4389b29a
AV
14469 default: abort ();
14470 }
14471}
14472
60f993ce
AV
14473/* Helper function for do_t_loloop to handle relocations. */
14474static void
14475v8_1_loop_reloc (int is_le)
14476{
14477 if (inst.relocs[0].exp.X_op == O_constant)
14478 {
14479 int value = inst.relocs[0].exp.X_add_number;
14480 value = (is_le) ? -value : value;
14481
14482 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14483 as_bad (BAD_BRANCH_OFF);
14484
14485 int imml, immh;
14486
14487 immh = (value & 0x00000ffc) >> 2;
14488 imml = (value & 0x00000002) >> 1;
14489
14490 inst.instruction |= (imml << 11) | (immh << 1);
14491 }
14492 else
14493 {
14494 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14495 inst.relocs[0].pc_rel = 1;
14496 }
14497}
14498
08132bdd
SP
14499/* For shifts with four operands in MVE. */
14500static void
14501do_mve_scalar_shift1 (void)
14502{
14503 unsigned int value = inst.operands[2].imm;
14504
14505 inst.instruction |= inst.operands[0].reg << 16;
14506 inst.instruction |= inst.operands[1].reg << 8;
14507
14508 /* Setting the bit for saturation. */
14509 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14510
14511 /* Assuming Rm is already checked not to be 11x1. */
14512 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14513 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14514 inst.instruction |= inst.operands[3].reg << 12;
14515}
14516
23d00a41
SD
14517/* For shifts in MVE. */
14518static void
14519do_mve_scalar_shift (void)
14520{
14521 if (!inst.operands[2].present)
14522 {
14523 inst.operands[2] = inst.operands[1];
14524 inst.operands[1].reg = 0xf;
14525 }
14526
14527 inst.instruction |= inst.operands[0].reg << 16;
14528 inst.instruction |= inst.operands[1].reg << 8;
14529
14530 if (inst.operands[2].isreg)
14531 {
14532 /* Assuming Rm is already checked not to be 11x1. */
14533 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14534 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14535 inst.instruction |= inst.operands[2].reg << 12;
14536 }
14537 else
14538 {
14539 /* Assuming imm is already checked as [1,32]. */
14540 unsigned int value = inst.operands[2].imm;
14541 inst.instruction |= (value & 0x1c) << 10;
14542 inst.instruction |= (value & 0x03) << 6;
14543 /* Change last 4 bits from 0xd to 0xf. */
14544 inst.instruction |= 0x2;
14545 }
14546}
14547
a302e574
AV
14548/* MVE instruction encoder helpers. */
14549#define M_MNEM_vabav 0xee800f01
14550#define M_MNEM_vmladav 0xeef00e00
14551#define M_MNEM_vmladava 0xeef00e20
14552#define M_MNEM_vmladavx 0xeef01e00
14553#define M_MNEM_vmladavax 0xeef01e20
14554#define M_MNEM_vmlsdav 0xeef00e01
14555#define M_MNEM_vmlsdava 0xeef00e21
14556#define M_MNEM_vmlsdavx 0xeef01e01
14557#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14558#define M_MNEM_vmullt 0xee011e00
14559#define M_MNEM_vmullb 0xee010e00
efd0b310 14560#define M_MNEM_vctp 0xf000e801
35c228db
AV
14561#define M_MNEM_vst20 0xfc801e00
14562#define M_MNEM_vst21 0xfc801e20
14563#define M_MNEM_vst40 0xfc801e01
14564#define M_MNEM_vst41 0xfc801e21
14565#define M_MNEM_vst42 0xfc801e41
14566#define M_MNEM_vst43 0xfc801e61
14567#define M_MNEM_vld20 0xfc901e00
14568#define M_MNEM_vld21 0xfc901e20
14569#define M_MNEM_vld40 0xfc901e01
14570#define M_MNEM_vld41 0xfc901e21
14571#define M_MNEM_vld42 0xfc901e41
14572#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14573#define M_MNEM_vstrb 0xec000e00
14574#define M_MNEM_vstrh 0xec000e10
14575#define M_MNEM_vstrw 0xec000e40
14576#define M_MNEM_vstrd 0xec000e50
14577#define M_MNEM_vldrb 0xec100e00
14578#define M_MNEM_vldrh 0xec100e10
14579#define M_MNEM_vldrw 0xec100e40
14580#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14581#define M_MNEM_vmovlt 0xeea01f40
14582#define M_MNEM_vmovlb 0xeea00f40
14583#define M_MNEM_vmovnt 0xfe311e81
14584#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14585#define M_MNEM_vadc 0xee300f00
14586#define M_MNEM_vadci 0xee301f00
14587#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14588#define M_MNEM_vaddlv 0xee890f00
14589#define M_MNEM_vaddlva 0xee890f20
14590#define M_MNEM_vaddv 0xeef10f00
14591#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14592#define M_MNEM_vddup 0xee011f6e
14593#define M_MNEM_vdwdup 0xee011f60
14594#define M_MNEM_vidup 0xee010f6e
14595#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14596#define M_MNEM_vmaxv 0xeee20f00
14597#define M_MNEM_vmaxav 0xeee00f00
14598#define M_MNEM_vminv 0xeee20f80
14599#define M_MNEM_vminav 0xeee00f80
93925576
AV
14600#define M_MNEM_vmlaldav 0xee800e00
14601#define M_MNEM_vmlaldava 0xee800e20
14602#define M_MNEM_vmlaldavx 0xee801e00
14603#define M_MNEM_vmlaldavax 0xee801e20
14604#define M_MNEM_vmlsldav 0xee800e01
14605#define M_MNEM_vmlsldava 0xee800e21
14606#define M_MNEM_vmlsldavx 0xee801e01
14607#define M_MNEM_vmlsldavax 0xee801e21
14608#define M_MNEM_vrmlaldavhx 0xee801f00
14609#define M_MNEM_vrmlaldavhax 0xee801f20
14610#define M_MNEM_vrmlsldavh 0xfe800e01
14611#define M_MNEM_vrmlsldavha 0xfe800e21
14612#define M_MNEM_vrmlsldavhx 0xfe801e01
14613#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14614#define M_MNEM_vqmovnt 0xee331e01
14615#define M_MNEM_vqmovnb 0xee330e01
14616#define M_MNEM_vqmovunt 0xee311e81
14617#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14618#define M_MNEM_vshrnt 0xee801fc1
14619#define M_MNEM_vshrnb 0xee800fc1
14620#define M_MNEM_vrshrnt 0xfe801fc1
14621#define M_MNEM_vqshrnt 0xee801f40
14622#define M_MNEM_vqshrnb 0xee800f40
14623#define M_MNEM_vqshrunt 0xee801fc0
14624#define M_MNEM_vqshrunb 0xee800fc0
14625#define M_MNEM_vrshrnb 0xfe800fc1
14626#define M_MNEM_vqrshrnt 0xee801f41
14627#define M_MNEM_vqrshrnb 0xee800f41
14628#define M_MNEM_vqrshrunt 0xfe801fc0
14629#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14630
aab2c27d
MM
14631/* Bfloat16 instruction encoder helpers. */
14632#define B_MNEM_vfmat 0xfc300850
14633#define B_MNEM_vfmab 0xfc300810
14634
5287ad62 14635/* Neon instruction encoder helpers. */
5f4273c7 14636
5287ad62 14637/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14638
5287ad62
JB
14639/* An "invalid" code for the following tables. */
14640#define N_INV -1u
14641
14642struct neon_tab_entry
b99bd4ef 14643{
5287ad62
JB
14644 unsigned integer;
14645 unsigned float_or_poly;
14646 unsigned scalar_or_imm;
14647};
5f4273c7 14648
5287ad62
JB
14649/* Map overloaded Neon opcodes to their respective encodings. */
14650#define NEON_ENC_TAB \
14651 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14652 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14653 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14654 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14655 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14656 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14657 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14658 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14659 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14660 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14661 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14662 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14663 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14664 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14665 /* Register variants of the following two instructions are encoded as
e07e6e58 14666 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14667 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14668 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14669 X(vfma, N_INV, 0x0000c10, N_INV), \
14670 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14671 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14672 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14673 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14674 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14675 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14676 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14677 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14678 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14679 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14680 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14681 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14682 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14683 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14684 X(vshl, 0x0000400, N_INV, 0x0800510), \
14685 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14686 X(vand, 0x0000110, N_INV, 0x0800030), \
14687 X(vbic, 0x0100110, N_INV, 0x0800030), \
14688 X(veor, 0x1000110, N_INV, N_INV), \
14689 X(vorn, 0x0300110, N_INV, 0x0800010), \
14690 X(vorr, 0x0200110, N_INV, 0x0800010), \
14691 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14692 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14693 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14694 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14695 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14696 X(vst1, 0x0000000, 0x0800000, N_INV), \
14697 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14698 X(vst2, 0x0000100, 0x0800100, N_INV), \
14699 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14700 X(vst3, 0x0000200, 0x0800200, N_INV), \
14701 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14702 X(vst4, 0x0000300, 0x0800300, N_INV), \
14703 X(vmovn, 0x1b20200, N_INV, N_INV), \
14704 X(vtrn, 0x1b20080, N_INV, N_INV), \
14705 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14706 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14707 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14708 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14709 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14710 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14711 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14712 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14713 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14714 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14715 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14716 X(vseleq, 0xe000a00, N_INV, N_INV), \
14717 X(vselvs, 0xe100a00, N_INV, N_INV), \
14718 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14719 X(vselgt, 0xe300a00, N_INV, N_INV), \
14720 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14721 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14722 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14723 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14724 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14725 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14726 X(sha3op, 0x2000c00, N_INV, N_INV), \
14727 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14728 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14729
14730enum neon_opc
14731{
14732#define X(OPC,I,F,S) N_MNEM_##OPC
14733NEON_ENC_TAB
14734#undef X
14735};
b99bd4ef 14736
5287ad62
JB
14737static const struct neon_tab_entry neon_enc_tab[] =
14738{
14739#define X(OPC,I,F,S) { (I), (F), (S) }
14740NEON_ENC_TAB
14741#undef X
14742};
b99bd4ef 14743
88714cb8
DG
14744/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14745#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14746#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14747#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14748#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14749#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14750#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14751#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14752#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14753#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14754#define NEON_ENC_SINGLE_(X) \
037e8744 14755 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14756#define NEON_ENC_DOUBLE_(X) \
037e8744 14757 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14758#define NEON_ENC_FPV8_(X) \
14759 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14760
88714cb8
DG
14761#define NEON_ENCODE(type, inst) \
14762 do \
14763 { \
14764 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14765 inst.is_neon = 1; \
14766 } \
14767 while (0)
14768
14769#define check_neon_suffixes \
14770 do \
14771 { \
14772 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14773 { \
14774 as_bad (_("invalid neon suffix for non neon instruction")); \
14775 return; \
14776 } \
14777 } \
14778 while (0)
14779
037e8744
JB
14780/* Define shapes for instruction operands. The following mnemonic characters
14781 are used in this table:
5287ad62 14782
037e8744 14783 F - VFP S<n> register
5287ad62
JB
14784 D - Neon D<n> register
14785 Q - Neon Q<n> register
14786 I - Immediate
14787 S - Scalar
14788 R - ARM register
14789 L - D<n> register list
5f4273c7 14790
037e8744
JB
14791 This table is used to generate various data:
14792 - enumerations of the form NS_DDR to be used as arguments to
14793 neon_select_shape.
14794 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14795 - a table used to drive neon_select_shape. */
b99bd4ef 14796
037e8744 14797#define NEON_SHAPE_DEF \
93925576 14798 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14799 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14800 X(4, (R, R, S, S), QUAD), \
14801 X(4, (S, S, R, R), QUAD), \
b409bdb6 14802 X(3, (Q, R, I), QUAD), \
1b883319
AV
14803 X(3, (I, Q, Q), QUAD), \
14804 X(3, (I, Q, R), QUAD), \
a302e574 14805 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14806 X(3, (D, D, D), DOUBLE), \
14807 X(3, (Q, Q, Q), QUAD), \
14808 X(3, (D, D, I), DOUBLE), \
14809 X(3, (Q, Q, I), QUAD), \
14810 X(3, (D, D, S), DOUBLE), \
14811 X(3, (Q, Q, S), QUAD), \
5ee91343 14812 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14813 X(3, (R, R, Q), QUAD), \
14814 X(2, (R, Q), QUAD), \
037e8744
JB
14815 X(2, (D, D), DOUBLE), \
14816 X(2, (Q, Q), QUAD), \
14817 X(2, (D, S), DOUBLE), \
14818 X(2, (Q, S), QUAD), \
14819 X(2, (D, R), DOUBLE), \
14820 X(2, (Q, R), QUAD), \
14821 X(2, (D, I), DOUBLE), \
14822 X(2, (Q, I), QUAD), \
5aae9ae9
MM
14823 X(3, (P, F, I), SINGLE), \
14824 X(3, (P, D, I), DOUBLE), \
14825 X(3, (P, Q, I), QUAD), \
14826 X(4, (P, F, F, I), SINGLE), \
14827 X(4, (P, D, D, I), DOUBLE), \
14828 X(4, (P, Q, Q, I), QUAD), \
14829 X(5, (P, F, F, F, I), SINGLE), \
14830 X(5, (P, D, D, D, I), DOUBLE), \
14831 X(5, (P, Q, Q, Q, I), QUAD), \
037e8744
JB
14832 X(3, (D, L, D), DOUBLE), \
14833 X(2, (D, Q), MIXED), \
14834 X(2, (Q, D), MIXED), \
14835 X(3, (D, Q, I), MIXED), \
14836 X(3, (Q, D, I), MIXED), \
14837 X(3, (Q, D, D), MIXED), \
14838 X(3, (D, Q, Q), MIXED), \
14839 X(3, (Q, Q, D), MIXED), \
14840 X(3, (Q, D, S), MIXED), \
14841 X(3, (D, Q, S), MIXED), \
14842 X(4, (D, D, D, I), DOUBLE), \
14843 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14844 X(4, (D, D, S, I), DOUBLE), \
14845 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14846 X(2, (F, F), SINGLE), \
14847 X(3, (F, F, F), SINGLE), \
14848 X(2, (F, I), SINGLE), \
14849 X(2, (F, D), MIXED), \
14850 X(2, (D, F), MIXED), \
14851 X(3, (F, F, I), MIXED), \
14852 X(4, (R, R, F, F), SINGLE), \
14853 X(4, (F, F, R, R), SINGLE), \
14854 X(3, (D, R, R), DOUBLE), \
14855 X(3, (R, R, D), DOUBLE), \
14856 X(2, (S, R), SINGLE), \
14857 X(2, (R, S), SINGLE), \
14858 X(2, (F, R), SINGLE), \
d54af2d0 14859 X(2, (R, F), SINGLE), \
1f6234a3
AV
14860/* Used for MVE tail predicated loop instructions. */\
14861 X(2, (R, R), QUAD), \
d54af2d0
RL
14862/* Half float shape supported so far. */\
14863 X (2, (H, D), MIXED), \
14864 X (2, (D, H), MIXED), \
14865 X (2, (H, F), MIXED), \
14866 X (2, (F, H), MIXED), \
14867 X (2, (H, H), HALF), \
14868 X (2, (H, R), HALF), \
14869 X (2, (R, H), HALF), \
14870 X (2, (H, I), HALF), \
14871 X (3, (H, H, H), HALF), \
14872 X (3, (H, F, I), MIXED), \
dec41383
JW
14873 X (3, (F, H, I), MIXED), \
14874 X (3, (D, H, H), MIXED), \
14875 X (3, (D, H, S), MIXED)
037e8744
JB
14876
14877#define S2(A,B) NS_##A##B
14878#define S3(A,B,C) NS_##A##B##C
14879#define S4(A,B,C,D) NS_##A##B##C##D
5aae9ae9 14880#define S5(A,B,C,D,E) NS_##A##B##C##D##E
037e8744
JB
14881
14882#define X(N, L, C) S##N L
14883
5287ad62
JB
14884enum neon_shape
14885{
037e8744
JB
14886 NEON_SHAPE_DEF,
14887 NS_NULL
5287ad62 14888};
b99bd4ef 14889
037e8744
JB
14890#undef X
14891#undef S2
14892#undef S3
14893#undef S4
5aae9ae9 14894#undef S5
037e8744
JB
14895
14896enum neon_shape_class
14897{
d54af2d0 14898 SC_HALF,
037e8744
JB
14899 SC_SINGLE,
14900 SC_DOUBLE,
14901 SC_QUAD,
14902 SC_MIXED
14903};
14904
14905#define X(N, L, C) SC_##C
14906
14907static enum neon_shape_class neon_shape_class[] =
14908{
14909 NEON_SHAPE_DEF
14910};
14911
14912#undef X
14913
14914enum neon_shape_el
14915{
d54af2d0 14916 SE_H,
037e8744
JB
14917 SE_F,
14918 SE_D,
14919 SE_Q,
14920 SE_I,
14921 SE_S,
14922 SE_R,
5aae9ae9
MM
14923 SE_L,
14924 SE_P
037e8744
JB
14925};
14926
14927/* Register widths of above. */
14928static unsigned neon_shape_el_size[] =
14929{
d54af2d0 14930 16,
037e8744
JB
14931 32,
14932 64,
14933 128,
14934 0,
14935 32,
14936 32,
5aae9ae9 14937 0,
037e8744
JB
14938 0
14939};
14940
14941struct neon_shape_info
14942{
14943 unsigned els;
14944 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14945};
14946
14947#define S2(A,B) { SE_##A, SE_##B }
14948#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14949#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
5aae9ae9 14950#define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
037e8744
JB
14951
14952#define X(N, L, C) { N, S##N L }
14953
14954static struct neon_shape_info neon_shape_tab[] =
14955{
14956 NEON_SHAPE_DEF
14957};
14958
14959#undef X
14960#undef S2
14961#undef S3
14962#undef S4
5aae9ae9 14963#undef S5
037e8744 14964
5287ad62
JB
14965/* Bit masks used in type checking given instructions.
14966 'N_EQK' means the type must be the same as (or based on in some way) the key
14967 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14968 set, various other bits can be set as well in order to modify the meaning of
14969 the type constraint. */
14970
14971enum neon_type_mask
14972{
8e79c3df
CM
14973 N_S8 = 0x0000001,
14974 N_S16 = 0x0000002,
14975 N_S32 = 0x0000004,
14976 N_S64 = 0x0000008,
14977 N_U8 = 0x0000010,
14978 N_U16 = 0x0000020,
14979 N_U32 = 0x0000040,
14980 N_U64 = 0x0000080,
14981 N_I8 = 0x0000100,
14982 N_I16 = 0x0000200,
14983 N_I32 = 0x0000400,
14984 N_I64 = 0x0000800,
14985 N_8 = 0x0001000,
14986 N_16 = 0x0002000,
14987 N_32 = 0x0004000,
14988 N_64 = 0x0008000,
14989 N_P8 = 0x0010000,
14990 N_P16 = 0x0020000,
14991 N_F16 = 0x0040000,
14992 N_F32 = 0x0080000,
14993 N_F64 = 0x0100000,
4f51b4bd 14994 N_P64 = 0x0200000,
aab2c27d 14995 N_BF16 = 0x0400000,
c921be7d
NC
14996 N_KEY = 0x1000000, /* Key element (main type specifier). */
14997 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14998 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14999 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
15000 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
15001 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
15002 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
15003 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
15004 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
15005 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
15006 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 15007 N_UTYP = 0,
4f51b4bd 15008 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
15009};
15010
dcbf9037
JB
15011#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15012
5287ad62
JB
15013#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15014#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15015#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
15016#define N_S_32 (N_S8 | N_S16 | N_S32)
15017#define N_F_16_32 (N_F16 | N_F32)
15018#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 15019#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 15020#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 15021#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
15022#define N_I_MVE (N_I8 | N_I16 | N_I32)
15023#define N_F_MVE (N_F16 | N_F32)
15024#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
15025
15026/* Pass this as the first type argument to neon_check_type to ignore types
15027 altogether. */
15028#define N_IGNORE_TYPE (N_KEY | N_EQK)
15029
037e8744
JB
15030/* Select a "shape" for the current instruction (describing register types or
15031 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15032 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15033 function of operand parsing, so this function doesn't need to be called.
15034 Shapes should be listed in order of decreasing length. */
5287ad62
JB
15035
15036static enum neon_shape
037e8744 15037neon_select_shape (enum neon_shape shape, ...)
5287ad62 15038{
037e8744
JB
15039 va_list ap;
15040 enum neon_shape first_shape = shape;
5287ad62
JB
15041
15042 /* Fix missing optional operands. FIXME: we don't know at this point how
15043 many arguments we should have, so this makes the assumption that we have
15044 > 1. This is true of all current Neon opcodes, I think, but may not be
15045 true in the future. */
15046 if (!inst.operands[1].present)
15047 inst.operands[1] = inst.operands[0];
15048
037e8744 15049 va_start (ap, shape);
5f4273c7 15050
21d799b5 15051 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
15052 {
15053 unsigned j;
15054 int matches = 1;
15055
15056 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
15057 {
15058 if (!inst.operands[j].present)
15059 {
15060 matches = 0;
15061 break;
15062 }
15063
15064 switch (neon_shape_tab[shape].el[j])
15065 {
d54af2d0
RL
15066 /* If a .f16, .16, .u16, .s16 type specifier is given over
15067 a VFP single precision register operand, it's essentially
15068 means only half of the register is used.
15069
15070 If the type specifier is given after the mnemonics, the
15071 information is stored in inst.vectype. If the type specifier
15072 is given after register operand, the information is stored
15073 in inst.operands[].vectype.
15074
15075 When there is only one type specifier, and all the register
15076 operands are the same type of hardware register, the type
15077 specifier applies to all register operands.
15078
15079 If no type specifier is given, the shape is inferred from
15080 operand information.
15081
15082 for example:
15083 vadd.f16 s0, s1, s2: NS_HHH
15084 vabs.f16 s0, s1: NS_HH
15085 vmov.f16 s0, r1: NS_HR
15086 vmov.f16 r0, s1: NS_RH
15087 vcvt.f16 r0, s1: NS_RH
15088 vcvt.f16.s32 s2, s2, #29: NS_HFI
15089 vcvt.f16.s32 s2, s2: NS_HF
15090 */
15091 case SE_H:
15092 if (!(inst.operands[j].isreg
15093 && inst.operands[j].isvec
15094 && inst.operands[j].issingle
15095 && !inst.operands[j].isquad
15096 && ((inst.vectype.elems == 1
15097 && inst.vectype.el[0].size == 16)
15098 || (inst.vectype.elems > 1
15099 && inst.vectype.el[j].size == 16)
15100 || (inst.vectype.elems == 0
15101 && inst.operands[j].vectype.type != NT_invtype
15102 && inst.operands[j].vectype.size == 16))))
15103 matches = 0;
15104 break;
15105
477330fc
RM
15106 case SE_F:
15107 if (!(inst.operands[j].isreg
15108 && inst.operands[j].isvec
15109 && inst.operands[j].issingle
d54af2d0
RL
15110 && !inst.operands[j].isquad
15111 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15112 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15113 || (inst.vectype.elems == 0
15114 && (inst.operands[j].vectype.size == 32
15115 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
15116 matches = 0;
15117 break;
15118
15119 case SE_D:
15120 if (!(inst.operands[j].isreg
15121 && inst.operands[j].isvec
15122 && !inst.operands[j].isquad
15123 && !inst.operands[j].issingle))
15124 matches = 0;
15125 break;
15126
15127 case SE_R:
15128 if (!(inst.operands[j].isreg
15129 && !inst.operands[j].isvec))
15130 matches = 0;
15131 break;
15132
15133 case SE_Q:
15134 if (!(inst.operands[j].isreg
15135 && inst.operands[j].isvec
15136 && inst.operands[j].isquad
15137 && !inst.operands[j].issingle))
15138 matches = 0;
15139 break;
15140
15141 case SE_I:
15142 if (!(!inst.operands[j].isreg
15143 && !inst.operands[j].isscalar))
15144 matches = 0;
15145 break;
15146
15147 case SE_S:
15148 if (!(!inst.operands[j].isreg
15149 && inst.operands[j].isscalar))
15150 matches = 0;
15151 break;
15152
5aae9ae9 15153 case SE_P:
477330fc
RM
15154 case SE_L:
15155 break;
15156 }
3fde54a2
JZ
15157 if (!matches)
15158 break;
477330fc 15159 }
ad6cec43
MGD
15160 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15161 /* We've matched all the entries in the shape table, and we don't
15162 have any left over operands which have not been matched. */
477330fc 15163 break;
037e8744 15164 }
5f4273c7 15165
037e8744 15166 va_end (ap);
5287ad62 15167
037e8744
JB
15168 if (shape == NS_NULL && first_shape != NS_NULL)
15169 first_error (_("invalid instruction shape"));
5287ad62 15170
037e8744
JB
15171 return shape;
15172}
5287ad62 15173
037e8744
JB
15174/* True if SHAPE is predominantly a quadword operation (most of the time, this
15175 means the Q bit should be set). */
15176
15177static int
15178neon_quad (enum neon_shape shape)
15179{
15180 return neon_shape_class[shape] == SC_QUAD;
5287ad62 15181}
037e8744 15182
5287ad62
JB
15183static void
15184neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 15185 unsigned *g_size)
5287ad62
JB
15186{
15187 /* Allow modification to be made to types which are constrained to be
15188 based on the key element, based on bits set alongside N_EQK. */
15189 if ((typebits & N_EQK) != 0)
15190 {
15191 if ((typebits & N_HLF) != 0)
15192 *g_size /= 2;
15193 else if ((typebits & N_DBL) != 0)
15194 *g_size *= 2;
15195 if ((typebits & N_SGN) != 0)
15196 *g_type = NT_signed;
15197 else if ((typebits & N_UNS) != 0)
477330fc 15198 *g_type = NT_unsigned;
5287ad62 15199 else if ((typebits & N_INT) != 0)
477330fc 15200 *g_type = NT_integer;
5287ad62 15201 else if ((typebits & N_FLT) != 0)
477330fc 15202 *g_type = NT_float;
dcbf9037 15203 else if ((typebits & N_SIZ) != 0)
477330fc 15204 *g_type = NT_untyped;
5287ad62
JB
15205 }
15206}
5f4273c7 15207
5287ad62
JB
15208/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15209 operand type, i.e. the single type specified in a Neon instruction when it
15210 is the only one given. */
15211
15212static struct neon_type_el
15213neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15214{
15215 struct neon_type_el dest = *key;
5f4273c7 15216
9c2799c2 15217 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15218
5287ad62
JB
15219 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15220
15221 return dest;
15222}
15223
15224/* Convert Neon type and size into compact bitmask representation. */
15225
15226static enum neon_type_mask
15227type_chk_of_el_type (enum neon_el_type type, unsigned size)
15228{
15229 switch (type)
15230 {
15231 case NT_untyped:
15232 switch (size)
477330fc
RM
15233 {
15234 case 8: return N_8;
15235 case 16: return N_16;
15236 case 32: return N_32;
15237 case 64: return N_64;
15238 default: ;
15239 }
5287ad62
JB
15240 break;
15241
15242 case NT_integer:
15243 switch (size)
477330fc
RM
15244 {
15245 case 8: return N_I8;
15246 case 16: return N_I16;
15247 case 32: return N_I32;
15248 case 64: return N_I64;
15249 default: ;
15250 }
5287ad62
JB
15251 break;
15252
15253 case NT_float:
037e8744 15254 switch (size)
477330fc 15255 {
8e79c3df 15256 case 16: return N_F16;
477330fc
RM
15257 case 32: return N_F32;
15258 case 64: return N_F64;
15259 default: ;
15260 }
5287ad62
JB
15261 break;
15262
15263 case NT_poly:
15264 switch (size)
477330fc
RM
15265 {
15266 case 8: return N_P8;
15267 case 16: return N_P16;
4f51b4bd 15268 case 64: return N_P64;
477330fc
RM
15269 default: ;
15270 }
5287ad62
JB
15271 break;
15272
15273 case NT_signed:
15274 switch (size)
477330fc
RM
15275 {
15276 case 8: return N_S8;
15277 case 16: return N_S16;
15278 case 32: return N_S32;
15279 case 64: return N_S64;
15280 default: ;
15281 }
5287ad62
JB
15282 break;
15283
15284 case NT_unsigned:
15285 switch (size)
477330fc
RM
15286 {
15287 case 8: return N_U8;
15288 case 16: return N_U16;
15289 case 32: return N_U32;
15290 case 64: return N_U64;
15291 default: ;
15292 }
5287ad62
JB
15293 break;
15294
aab2c27d
MM
15295 case NT_bfloat:
15296 if (size == 16) return N_BF16;
15297 break;
15298
5287ad62
JB
15299 default: ;
15300 }
5f4273c7 15301
5287ad62
JB
15302 return N_UTYP;
15303}
15304
15305/* Convert compact Neon bitmask type representation to a type and size. Only
15306 handles the case where a single bit is set in the mask. */
15307
dcbf9037 15308static int
5287ad62 15309el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15310 enum neon_type_mask mask)
5287ad62 15311{
dcbf9037
JB
15312 if ((mask & N_EQK) != 0)
15313 return FAIL;
15314
5287ad62
JB
15315 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15316 *size = 8;
aab2c27d
MM
15317 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15318 != 0)
5287ad62 15319 *size = 16;
dcbf9037 15320 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15321 *size = 32;
4f51b4bd 15322 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15323 *size = 64;
dcbf9037
JB
15324 else
15325 return FAIL;
15326
5287ad62
JB
15327 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15328 *type = NT_signed;
dcbf9037 15329 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15330 *type = NT_unsigned;
dcbf9037 15331 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15332 *type = NT_integer;
dcbf9037 15333 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15334 *type = NT_untyped;
4f51b4bd 15335 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15336 *type = NT_poly;
d54af2d0 15337 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15338 *type = NT_float;
aab2c27d
MM
15339 else if ((mask & (N_BF16)) != 0)
15340 *type = NT_bfloat;
dcbf9037
JB
15341 else
15342 return FAIL;
5f4273c7 15343
dcbf9037 15344 return SUCCESS;
5287ad62
JB
15345}
15346
15347/* Modify a bitmask of allowed types. This is only needed for type
15348 relaxation. */
15349
15350static unsigned
15351modify_types_allowed (unsigned allowed, unsigned mods)
15352{
15353 unsigned size;
15354 enum neon_el_type type;
15355 unsigned destmask;
15356 int i;
5f4273c7 15357
5287ad62 15358 destmask = 0;
5f4273c7 15359
5287ad62
JB
15360 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15361 {
21d799b5 15362 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15363 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15364 {
15365 neon_modify_type_size (mods, &type, &size);
15366 destmask |= type_chk_of_el_type (type, size);
15367 }
5287ad62 15368 }
5f4273c7 15369
5287ad62
JB
15370 return destmask;
15371}
15372
15373/* Check type and return type classification.
15374 The manual states (paraphrase): If one datatype is given, it indicates the
15375 type given in:
15376 - the second operand, if there is one
15377 - the operand, if there is no second operand
15378 - the result, if there are no operands.
15379 This isn't quite good enough though, so we use a concept of a "key" datatype
15380 which is set on a per-instruction basis, which is the one which matters when
15381 only one data type is written.
15382 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15383 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15384
15385static struct neon_type_el
15386neon_check_type (unsigned els, enum neon_shape ns, ...)
15387{
15388 va_list ap;
15389 unsigned i, pass, key_el = 0;
15390 unsigned types[NEON_MAX_TYPE_ELS];
15391 enum neon_el_type k_type = NT_invtype;
15392 unsigned k_size = -1u;
15393 struct neon_type_el badtype = {NT_invtype, -1};
15394 unsigned key_allowed = 0;
15395
15396 /* Optional registers in Neon instructions are always (not) in operand 1.
15397 Fill in the missing operand here, if it was omitted. */
15398 if (els > 1 && !inst.operands[1].present)
15399 inst.operands[1] = inst.operands[0];
15400
15401 /* Suck up all the varargs. */
15402 va_start (ap, ns);
15403 for (i = 0; i < els; i++)
15404 {
15405 unsigned thisarg = va_arg (ap, unsigned);
15406 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15407 {
15408 va_end (ap);
15409 return badtype;
15410 }
5287ad62
JB
15411 types[i] = thisarg;
15412 if ((thisarg & N_KEY) != 0)
477330fc 15413 key_el = i;
5287ad62
JB
15414 }
15415 va_end (ap);
15416
dcbf9037
JB
15417 if (inst.vectype.elems > 0)
15418 for (i = 0; i < els; i++)
15419 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15420 {
15421 first_error (_("types specified in both the mnemonic and operands"));
15422 return badtype;
15423 }
dcbf9037 15424
5287ad62
JB
15425 /* Duplicate inst.vectype elements here as necessary.
15426 FIXME: No idea if this is exactly the same as the ARM assembler,
15427 particularly when an insn takes one register and one non-register
15428 operand. */
15429 if (inst.vectype.elems == 1 && els > 1)
15430 {
15431 unsigned j;
15432 inst.vectype.elems = els;
15433 inst.vectype.el[key_el] = inst.vectype.el[0];
15434 for (j = 0; j < els; j++)
477330fc
RM
15435 if (j != key_el)
15436 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15437 types[j]);
dcbf9037
JB
15438 }
15439 else if (inst.vectype.elems == 0 && els > 0)
15440 {
15441 unsigned j;
15442 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15443 after each operand. We allow some flexibility here; as long as the
15444 "key" operand has a type, we can infer the others. */
dcbf9037 15445 for (j = 0; j < els; j++)
477330fc
RM
15446 if (inst.operands[j].vectype.type != NT_invtype)
15447 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15448
15449 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15450 {
15451 for (j = 0; j < els; j++)
15452 if (inst.operands[j].vectype.type == NT_invtype)
15453 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15454 types[j]);
15455 }
dcbf9037 15456 else
477330fc
RM
15457 {
15458 first_error (_("operand types can't be inferred"));
15459 return badtype;
15460 }
5287ad62
JB
15461 }
15462 else if (inst.vectype.elems != els)
15463 {
dcbf9037 15464 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15465 return badtype;
15466 }
15467
15468 for (pass = 0; pass < 2; pass++)
15469 {
15470 for (i = 0; i < els; i++)
477330fc
RM
15471 {
15472 unsigned thisarg = types[i];
15473 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15474 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15475 enum neon_el_type g_type = inst.vectype.el[i].type;
15476 unsigned g_size = inst.vectype.el[i].size;
15477
15478 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15479 integer types if sign-specific variants are unavailable. */
477330fc 15480 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15481 && (types_allowed & N_SU_ALL) == 0)
15482 g_type = NT_integer;
15483
477330fc 15484 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15485 them. Some instructions only care about signs for some element
15486 sizes, so handle that properly. */
477330fc 15487 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15488 && ((g_size == 8 && (types_allowed & N_8) != 0)
15489 || (g_size == 16 && (types_allowed & N_16) != 0)
15490 || (g_size == 32 && (types_allowed & N_32) != 0)
15491 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15492 g_type = NT_untyped;
15493
477330fc
RM
15494 if (pass == 0)
15495 {
15496 if ((thisarg & N_KEY) != 0)
15497 {
15498 k_type = g_type;
15499 k_size = g_size;
15500 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15501
15502 /* Check architecture constraint on FP16 extension. */
15503 if (k_size == 16
15504 && k_type == NT_float
15505 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15506 {
15507 inst.error = _(BAD_FP16);
15508 return badtype;
15509 }
477330fc
RM
15510 }
15511 }
15512 else
15513 {
15514 if ((thisarg & N_VFP) != 0)
15515 {
15516 enum neon_shape_el regshape;
15517 unsigned regwidth, match;
99b253c5
NC
15518
15519 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15520 if (ns == NS_NULL)
15521 {
15522 first_error (_("invalid instruction shape"));
15523 return badtype;
15524 }
477330fc
RM
15525 regshape = neon_shape_tab[ns].el[i];
15526 regwidth = neon_shape_el_size[regshape];
15527
15528 /* In VFP mode, operands must match register widths. If we
15529 have a key operand, use its width, else use the width of
15530 the current operand. */
15531 if (k_size != -1u)
15532 match = k_size;
15533 else
15534 match = g_size;
15535
9db2f6b4
RL
15536 /* FP16 will use a single precision register. */
15537 if (regwidth == 32 && match == 16)
15538 {
15539 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15540 match = regwidth;
15541 else
15542 {
15543 inst.error = _(BAD_FP16);
15544 return badtype;
15545 }
15546 }
15547
477330fc
RM
15548 if (regwidth != match)
15549 {
15550 first_error (_("operand size must match register width"));
15551 return badtype;
15552 }
15553 }
15554
15555 if ((thisarg & N_EQK) == 0)
15556 {
15557 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15558
15559 if ((given_type & types_allowed) == 0)
15560 {
a302e574 15561 first_error (BAD_SIMD_TYPE);
477330fc
RM
15562 return badtype;
15563 }
15564 }
15565 else
15566 {
15567 enum neon_el_type mod_k_type = k_type;
15568 unsigned mod_k_size = k_size;
15569 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15570 if (g_type != mod_k_type || g_size != mod_k_size)
15571 {
15572 first_error (_("inconsistent types in Neon instruction"));
15573 return badtype;
15574 }
15575 }
15576 }
15577 }
5287ad62
JB
15578 }
15579
15580 return inst.vectype.el[key_el];
15581}
15582
037e8744 15583/* Neon-style VFP instruction forwarding. */
5287ad62 15584
037e8744
JB
15585/* Thumb VFP instructions have 0xE in the condition field. */
15586
15587static void
15588do_vfp_cond_or_thumb (void)
5287ad62 15589{
88714cb8
DG
15590 inst.is_neon = 1;
15591
5287ad62 15592 if (thumb_mode)
037e8744 15593 inst.instruction |= 0xe0000000;
5287ad62 15594 else
037e8744 15595 inst.instruction |= inst.cond << 28;
5287ad62
JB
15596}
15597
037e8744
JB
15598/* Look up and encode a simple mnemonic, for use as a helper function for the
15599 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15600 etc. It is assumed that operand parsing has already been done, and that the
15601 operands are in the form expected by the given opcode (this isn't necessarily
15602 the same as the form in which they were parsed, hence some massaging must
15603 take place before this function is called).
15604 Checks current arch version against that in the looked-up opcode. */
5287ad62 15605
037e8744
JB
15606static void
15607do_vfp_nsyn_opcode (const char *opname)
5287ad62 15608{
037e8744 15609 const struct asm_opcode *opcode;
5f4273c7 15610
21d799b5 15611 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 15612
037e8744
JB
15613 if (!opcode)
15614 abort ();
5287ad62 15615
037e8744 15616 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15617 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15618 _(BAD_FPU));
5287ad62 15619
88714cb8
DG
15620 inst.is_neon = 1;
15621
037e8744
JB
15622 if (thumb_mode)
15623 {
15624 inst.instruction = opcode->tvalue;
15625 opcode->tencode ();
15626 }
15627 else
15628 {
15629 inst.instruction = (inst.cond << 28) | opcode->avalue;
15630 opcode->aencode ();
15631 }
15632}
5287ad62
JB
15633
15634static void
037e8744 15635do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15636{
037e8744
JB
15637 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15638
9db2f6b4 15639 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15640 {
15641 if (is_add)
477330fc 15642 do_vfp_nsyn_opcode ("fadds");
037e8744 15643 else
477330fc 15644 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15645
15646 /* ARMv8.2 fp16 instruction. */
15647 if (rs == NS_HHH)
15648 do_scalar_fp16_v82_encode ();
037e8744
JB
15649 }
15650 else
15651 {
15652 if (is_add)
477330fc 15653 do_vfp_nsyn_opcode ("faddd");
037e8744 15654 else
477330fc 15655 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15656 }
15657}
15658
15659/* Check operand types to see if this is a VFP instruction, and if so call
15660 PFN (). */
15661
15662static int
15663try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15664{
15665 enum neon_shape rs;
15666 struct neon_type_el et;
15667
15668 switch (args)
15669 {
15670 case 2:
9db2f6b4
RL
15671 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15672 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15673 break;
5f4273c7 15674
037e8744 15675 case 3:
9db2f6b4
RL
15676 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15677 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15678 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15679 break;
15680
15681 default:
15682 abort ();
15683 }
15684
15685 if (et.type != NT_invtype)
15686 {
15687 pfn (rs);
15688 return SUCCESS;
15689 }
037e8744 15690
99b253c5 15691 inst.error = NULL;
037e8744
JB
15692 return FAIL;
15693}
15694
15695static void
15696do_vfp_nsyn_mla_mls (enum neon_shape rs)
15697{
15698 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15699
9db2f6b4 15700 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15701 {
15702 if (is_mla)
477330fc 15703 do_vfp_nsyn_opcode ("fmacs");
037e8744 15704 else
477330fc 15705 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15706
15707 /* ARMv8.2 fp16 instruction. */
15708 if (rs == NS_HHH)
15709 do_scalar_fp16_v82_encode ();
037e8744
JB
15710 }
15711 else
15712 {
15713 if (is_mla)
477330fc 15714 do_vfp_nsyn_opcode ("fmacd");
037e8744 15715 else
477330fc 15716 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15717 }
15718}
15719
62f3b8c8
PB
15720static void
15721do_vfp_nsyn_fma_fms (enum neon_shape rs)
15722{
15723 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15724
9db2f6b4 15725 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15726 {
15727 if (is_fma)
477330fc 15728 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15729 else
477330fc 15730 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15731
15732 /* ARMv8.2 fp16 instruction. */
15733 if (rs == NS_HHH)
15734 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15735 }
15736 else
15737 {
15738 if (is_fma)
477330fc 15739 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15740 else
477330fc 15741 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15742 }
15743}
15744
037e8744
JB
15745static void
15746do_vfp_nsyn_mul (enum neon_shape rs)
15747{
9db2f6b4
RL
15748 if (rs == NS_FFF || rs == NS_HHH)
15749 {
15750 do_vfp_nsyn_opcode ("fmuls");
15751
15752 /* ARMv8.2 fp16 instruction. */
15753 if (rs == NS_HHH)
15754 do_scalar_fp16_v82_encode ();
15755 }
037e8744
JB
15756 else
15757 do_vfp_nsyn_opcode ("fmuld");
15758}
15759
15760static void
15761do_vfp_nsyn_abs_neg (enum neon_shape rs)
15762{
15763 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15764 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15765
9db2f6b4 15766 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15767 {
15768 if (is_neg)
477330fc 15769 do_vfp_nsyn_opcode ("fnegs");
037e8744 15770 else
477330fc 15771 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15772
15773 /* ARMv8.2 fp16 instruction. */
15774 if (rs == NS_HH)
15775 do_scalar_fp16_v82_encode ();
037e8744
JB
15776 }
15777 else
15778 {
15779 if (is_neg)
477330fc 15780 do_vfp_nsyn_opcode ("fnegd");
037e8744 15781 else
477330fc 15782 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15783 }
15784}
15785
15786/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15787 insns belong to Neon, and are handled elsewhere. */
15788
15789static void
15790do_vfp_nsyn_ldm_stm (int is_dbmode)
15791{
15792 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15793 if (is_ldm)
15794 {
15795 if (is_dbmode)
477330fc 15796 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15797 else
477330fc 15798 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15799 }
15800 else
15801 {
15802 if (is_dbmode)
477330fc 15803 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15804 else
477330fc 15805 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15806 }
15807}
15808
037e8744
JB
15809static void
15810do_vfp_nsyn_sqrt (void)
15811{
9db2f6b4
RL
15812 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15813 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15814
9db2f6b4
RL
15815 if (rs == NS_FF || rs == NS_HH)
15816 {
15817 do_vfp_nsyn_opcode ("fsqrts");
15818
15819 /* ARMv8.2 fp16 instruction. */
15820 if (rs == NS_HH)
15821 do_scalar_fp16_v82_encode ();
15822 }
037e8744
JB
15823 else
15824 do_vfp_nsyn_opcode ("fsqrtd");
15825}
15826
15827static void
15828do_vfp_nsyn_div (void)
15829{
9db2f6b4 15830 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15831 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15832 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15833
9db2f6b4
RL
15834 if (rs == NS_FFF || rs == NS_HHH)
15835 {
15836 do_vfp_nsyn_opcode ("fdivs");
15837
15838 /* ARMv8.2 fp16 instruction. */
15839 if (rs == NS_HHH)
15840 do_scalar_fp16_v82_encode ();
15841 }
037e8744
JB
15842 else
15843 do_vfp_nsyn_opcode ("fdivd");
15844}
15845
15846static void
15847do_vfp_nsyn_nmul (void)
15848{
9db2f6b4 15849 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15850 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15851 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15852
9db2f6b4 15853 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15854 {
88714cb8 15855 NEON_ENCODE (SINGLE, inst);
037e8744 15856 do_vfp_sp_dyadic ();
9db2f6b4
RL
15857
15858 /* ARMv8.2 fp16 instruction. */
15859 if (rs == NS_HHH)
15860 do_scalar_fp16_v82_encode ();
037e8744
JB
15861 }
15862 else
15863 {
88714cb8 15864 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15865 do_vfp_dp_rd_rn_rm ();
15866 }
15867 do_vfp_cond_or_thumb ();
9db2f6b4 15868
037e8744
JB
15869}
15870
1b883319
AV
15871/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15872 (0, 1, 2, 3). */
15873
15874static unsigned
15875neon_logbits (unsigned x)
15876{
15877 return ffs (x) - 4;
15878}
15879
15880#define LOW4(R) ((R) & 0xf)
15881#define HI1(R) (((R) >> 4) & 1)
5aae9ae9
MM
15882#define LOW1(R) ((R) & 0x1)
15883#define HI4(R) (((R) >> 1) & 0xf)
1b883319
AV
15884
15885static unsigned
15886mve_get_vcmp_vpt_cond (struct neon_type_el et)
15887{
15888 switch (et.type)
15889 {
15890 default:
15891 first_error (BAD_EL_TYPE);
15892 return 0;
15893 case NT_float:
15894 switch (inst.operands[0].imm)
15895 {
15896 default:
15897 first_error (_("invalid condition"));
15898 return 0;
15899 case 0x0:
15900 /* eq. */
15901 return 0;
15902 case 0x1:
15903 /* ne. */
15904 return 1;
15905 case 0xa:
15906 /* ge/ */
15907 return 4;
15908 case 0xb:
15909 /* lt. */
15910 return 5;
15911 case 0xc:
15912 /* gt. */
15913 return 6;
15914 case 0xd:
15915 /* le. */
15916 return 7;
15917 }
15918 case NT_integer:
15919 /* only accept eq and ne. */
15920 if (inst.operands[0].imm > 1)
15921 {
15922 first_error (_("invalid condition"));
15923 return 0;
15924 }
15925 return inst.operands[0].imm;
15926 case NT_unsigned:
15927 if (inst.operands[0].imm == 0x2)
15928 return 2;
15929 else if (inst.operands[0].imm == 0x8)
15930 return 3;
15931 else
15932 {
15933 first_error (_("invalid condition"));
15934 return 0;
15935 }
15936 case NT_signed:
15937 switch (inst.operands[0].imm)
15938 {
15939 default:
15940 first_error (_("invalid condition"));
15941 return 0;
15942 case 0xa:
15943 /* ge. */
15944 return 4;
15945 case 0xb:
15946 /* lt. */
15947 return 5;
15948 case 0xc:
15949 /* gt. */
15950 return 6;
15951 case 0xd:
15952 /* le. */
15953 return 7;
15954 }
15955 }
15956 /* Should be unreachable. */
15957 abort ();
15958}
15959
efd0b310
SP
15960/* For VCTP (create vector tail predicate) in MVE. */
15961static void
15962do_mve_vctp (void)
15963{
15964 int dt = 0;
15965 unsigned size = 0x0;
15966
15967 if (inst.cond > COND_ALWAYS)
15968 inst.pred_insn_type = INSIDE_VPT_INSN;
15969 else
15970 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15971
15972 /* This is a typical MVE instruction which has no type but have size 8, 16,
15973 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15974 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15975 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15976 dt = inst.vectype.el[0].size;
15977
15978 /* Setting this does not indicate an actual NEON instruction, but only
15979 indicates that the mnemonic accepts neon-style type suffixes. */
15980 inst.is_neon = 1;
15981
15982 switch (dt)
15983 {
15984 case 8:
15985 break;
15986 case 16:
15987 size = 0x1; break;
15988 case 32:
15989 size = 0x2; break;
15990 case 64:
15991 size = 0x3; break;
15992 default:
15993 first_error (_("Type is not allowed for this instruction"));
15994 }
15995 inst.instruction |= size << 20;
15996 inst.instruction |= inst.operands[0].reg << 16;
15997}
15998
1b883319
AV
15999static void
16000do_mve_vpt (void)
16001{
16002 /* We are dealing with a vector predicated block. */
16003 if (inst.operands[0].present)
16004 {
16005 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16006 struct neon_type_el et
16007 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16008 N_EQK);
16009
16010 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16011
16012 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16013
16014 if (et.type == NT_invtype)
16015 return;
16016
16017 if (et.type == NT_float)
16018 {
16019 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16020 BAD_FPU);
16021 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16022 inst.instruction |= (et.size == 16) << 28;
16023 inst.instruction |= 0x3 << 20;
16024 }
16025 else
16026 {
16027 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16028 BAD_EL_TYPE);
16029 inst.instruction |= 1 << 28;
16030 inst.instruction |= neon_logbits (et.size) << 20;
16031 }
16032
16033 if (inst.operands[2].isquad)
16034 {
16035 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16036 inst.instruction |= LOW4 (inst.operands[2].reg);
16037 inst.instruction |= (fcond & 0x2) >> 1;
16038 }
16039 else
16040 {
16041 if (inst.operands[2].reg == REG_SP)
16042 as_tsktsk (MVE_BAD_SP);
16043 inst.instruction |= 1 << 6;
16044 inst.instruction |= (fcond & 0x2) << 4;
16045 inst.instruction |= inst.operands[2].reg;
16046 }
16047 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16048 inst.instruction |= (fcond & 0x4) << 10;
16049 inst.instruction |= (fcond & 0x1) << 7;
16050
16051 }
16052 set_pred_insn_type (VPT_INSN);
16053 now_pred.cc = 0;
16054 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16055 | ((inst.instruction & 0xe000) >> 13);
16056 now_pred.warn_deprecated = FALSE;
16057 now_pred.type = VECTOR_PRED;
16058 inst.is_neon = 1;
16059}
16060
16061static void
16062do_mve_vcmp (void)
16063{
16064 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16065 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16066 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16067 if (!inst.operands[2].present)
16068 first_error (_("MVE vector or ARM register expected"));
16069 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16070
16071 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16072 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16073 && inst.operands[1].isquad)
16074 {
16075 inst.instruction = N_MNEM_vcmp;
16076 inst.cond = 0x10;
16077 }
16078
16079 if (inst.cond > COND_ALWAYS)
16080 inst.pred_insn_type = INSIDE_VPT_INSN;
16081 else
16082 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16083
16084 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16085 struct neon_type_el et
16086 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16087 N_EQK);
16088
16089 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16090 && !inst.operands[2].iszr, BAD_PC);
16091
16092 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16093
16094 inst.instruction = 0xee010f00;
16095 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16096 inst.instruction |= (fcond & 0x4) << 10;
16097 inst.instruction |= (fcond & 0x1) << 7;
16098 if (et.type == NT_float)
16099 {
16100 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16101 BAD_FPU);
16102 inst.instruction |= (et.size == 16) << 28;
16103 inst.instruction |= 0x3 << 20;
16104 }
16105 else
16106 {
16107 inst.instruction |= 1 << 28;
16108 inst.instruction |= neon_logbits (et.size) << 20;
16109 }
16110 if (inst.operands[2].isquad)
16111 {
16112 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16113 inst.instruction |= (fcond & 0x2) >> 1;
16114 inst.instruction |= LOW4 (inst.operands[2].reg);
16115 }
16116 else
16117 {
16118 if (inst.operands[2].reg == REG_SP)
16119 as_tsktsk (MVE_BAD_SP);
16120 inst.instruction |= 1 << 6;
16121 inst.instruction |= (fcond & 0x2) << 4;
16122 inst.instruction |= inst.operands[2].reg;
16123 }
16124
16125 inst.is_neon = 1;
16126 return;
16127}
16128
935295b5
AV
16129static void
16130do_mve_vmaxa_vmina (void)
16131{
16132 if (inst.cond > COND_ALWAYS)
16133 inst.pred_insn_type = INSIDE_VPT_INSN;
16134 else
16135 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16136
16137 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16138 struct neon_type_el et
16139 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16140
16141 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16142 inst.instruction |= neon_logbits (et.size) << 18;
16143 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16144 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16145 inst.instruction |= LOW4 (inst.operands[1].reg);
16146 inst.is_neon = 1;
16147}
16148
f30ee27c
AV
16149static void
16150do_mve_vfmas (void)
16151{
16152 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16153 struct neon_type_el et
16154 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16155
16156 if (inst.cond > COND_ALWAYS)
16157 inst.pred_insn_type = INSIDE_VPT_INSN;
16158 else
16159 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16160
16161 if (inst.operands[2].reg == REG_SP)
16162 as_tsktsk (MVE_BAD_SP);
16163 else if (inst.operands[2].reg == REG_PC)
16164 as_tsktsk (MVE_BAD_PC);
16165
16166 inst.instruction |= (et.size == 16) << 28;
16167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16168 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16169 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16170 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16171 inst.instruction |= inst.operands[2].reg;
16172 inst.is_neon = 1;
16173}
16174
b409bdb6
AV
16175static void
16176do_mve_viddup (void)
16177{
16178 if (inst.cond > COND_ALWAYS)
16179 inst.pred_insn_type = INSIDE_VPT_INSN;
16180 else
16181 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16182
16183 unsigned imm = inst.relocs[0].exp.X_add_number;
16184 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16185 _("immediate must be either 1, 2, 4 or 8"));
16186
16187 enum neon_shape rs;
16188 struct neon_type_el et;
16189 unsigned Rm;
16190 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16191 {
16192 rs = neon_select_shape (NS_QRI, NS_NULL);
16193 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16194 Rm = 7;
16195 }
16196 else
16197 {
16198 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16199 if (inst.operands[2].reg == REG_SP)
16200 as_tsktsk (MVE_BAD_SP);
16201 else if (inst.operands[2].reg == REG_PC)
16202 first_error (BAD_PC);
16203
16204 rs = neon_select_shape (NS_QRRI, NS_NULL);
16205 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16206 Rm = inst.operands[2].reg >> 1;
16207 }
16208 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16209 inst.instruction |= neon_logbits (et.size) << 20;
16210 inst.instruction |= inst.operands[1].reg << 16;
16211 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16212 inst.instruction |= (imm > 2) << 7;
16213 inst.instruction |= Rm << 1;
16214 inst.instruction |= (imm == 2 || imm == 8);
16215 inst.is_neon = 1;
16216}
16217
2d78f95b
AV
16218static void
16219do_mve_vmlas (void)
16220{
16221 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16222 struct neon_type_el et
16223 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16224
16225 if (inst.operands[2].reg == REG_PC)
16226 as_tsktsk (MVE_BAD_PC);
16227 else if (inst.operands[2].reg == REG_SP)
16228 as_tsktsk (MVE_BAD_SP);
16229
16230 if (inst.cond > COND_ALWAYS)
16231 inst.pred_insn_type = INSIDE_VPT_INSN;
16232 else
16233 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16234
16235 inst.instruction |= (et.type == NT_unsigned) << 28;
16236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16237 inst.instruction |= neon_logbits (et.size) << 20;
16238 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16239 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16240 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16241 inst.instruction |= inst.operands[2].reg;
16242 inst.is_neon = 1;
16243}
16244
acca5630
AV
16245static void
16246do_mve_vshll (void)
16247{
16248 struct neon_type_el et
16249 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16250
16251 if (inst.cond > COND_ALWAYS)
16252 inst.pred_insn_type = INSIDE_VPT_INSN;
16253 else
16254 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16255
16256 int imm = inst.operands[2].imm;
16257 constraint (imm < 1 || (unsigned)imm > et.size,
16258 _("immediate value out of range"));
16259
16260 if ((unsigned)imm == et.size)
16261 {
16262 inst.instruction |= neon_logbits (et.size) << 18;
16263 inst.instruction |= 0x110001;
16264 }
16265 else
16266 {
16267 inst.instruction |= (et.size + imm) << 16;
16268 inst.instruction |= 0x800140;
16269 }
16270
16271 inst.instruction |= (et.type == NT_unsigned) << 28;
16272 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16273 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16274 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16275 inst.instruction |= LOW4 (inst.operands[1].reg);
16276 inst.is_neon = 1;
16277}
16278
16279static void
16280do_mve_vshlc (void)
16281{
16282 if (inst.cond > COND_ALWAYS)
16283 inst.pred_insn_type = INSIDE_VPT_INSN;
16284 else
16285 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16286
16287 if (inst.operands[1].reg == REG_PC)
16288 as_tsktsk (MVE_BAD_PC);
16289 else if (inst.operands[1].reg == REG_SP)
16290 as_tsktsk (MVE_BAD_SP);
16291
16292 int imm = inst.operands[2].imm;
16293 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16294
16295 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16296 inst.instruction |= (imm & 0x1f) << 16;
16297 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16298 inst.instruction |= inst.operands[1].reg;
16299 inst.is_neon = 1;
16300}
16301
4aa88b50
AV
16302static void
16303do_mve_vshrn (void)
16304{
16305 unsigned types;
16306 switch (inst.instruction)
16307 {
16308 case M_MNEM_vshrnt:
16309 case M_MNEM_vshrnb:
16310 case M_MNEM_vrshrnt:
16311 case M_MNEM_vrshrnb:
16312 types = N_I16 | N_I32;
16313 break;
16314 case M_MNEM_vqshrnt:
16315 case M_MNEM_vqshrnb:
16316 case M_MNEM_vqrshrnt:
16317 case M_MNEM_vqrshrnb:
16318 types = N_U16 | N_U32 | N_S16 | N_S32;
16319 break;
16320 case M_MNEM_vqshrunt:
16321 case M_MNEM_vqshrunb:
16322 case M_MNEM_vqrshrunt:
16323 case M_MNEM_vqrshrunb:
16324 types = N_S16 | N_S32;
16325 break;
16326 default:
16327 abort ();
16328 }
16329
16330 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16331
16332 if (inst.cond > COND_ALWAYS)
16333 inst.pred_insn_type = INSIDE_VPT_INSN;
16334 else
16335 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16336
16337 unsigned Qd = inst.operands[0].reg;
16338 unsigned Qm = inst.operands[1].reg;
16339 unsigned imm = inst.operands[2].imm;
16340 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16341 et.size == 16
16342 ? _("immediate operand expected in the range [1,8]")
16343 : _("immediate operand expected in the range [1,16]"));
16344
16345 inst.instruction |= (et.type == NT_unsigned) << 28;
16346 inst.instruction |= HI1 (Qd) << 22;
16347 inst.instruction |= (et.size - imm) << 16;
16348 inst.instruction |= LOW4 (Qd) << 12;
16349 inst.instruction |= HI1 (Qm) << 5;
16350 inst.instruction |= LOW4 (Qm);
16351 inst.is_neon = 1;
16352}
16353
1be7aba3
AV
16354static void
16355do_mve_vqmovn (void)
16356{
16357 struct neon_type_el et;
16358 if (inst.instruction == M_MNEM_vqmovnt
16359 || inst.instruction == M_MNEM_vqmovnb)
16360 et = neon_check_type (2, NS_QQ, N_EQK,
16361 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16362 else
16363 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16364
16365 if (inst.cond > COND_ALWAYS)
16366 inst.pred_insn_type = INSIDE_VPT_INSN;
16367 else
16368 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16369
16370 inst.instruction |= (et.type == NT_unsigned) << 28;
16371 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16372 inst.instruction |= (et.size == 32) << 18;
16373 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16374 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16375 inst.instruction |= LOW4 (inst.operands[1].reg);
16376 inst.is_neon = 1;
16377}
16378
3063888e
AV
16379static void
16380do_mve_vpsel (void)
16381{
16382 neon_select_shape (NS_QQQ, NS_NULL);
16383
16384 if (inst.cond > COND_ALWAYS)
16385 inst.pred_insn_type = INSIDE_VPT_INSN;
16386 else
16387 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16388
16389 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16390 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16391 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16392 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16393 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16394 inst.instruction |= LOW4 (inst.operands[2].reg);
16395 inst.is_neon = 1;
16396}
16397
16398static void
16399do_mve_vpnot (void)
16400{
16401 if (inst.cond > COND_ALWAYS)
16402 inst.pred_insn_type = INSIDE_VPT_INSN;
16403 else
16404 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16405}
16406
935295b5
AV
16407static void
16408do_mve_vmaxnma_vminnma (void)
16409{
16410 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16411 struct neon_type_el et
16412 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16413
16414 if (inst.cond > COND_ALWAYS)
16415 inst.pred_insn_type = INSIDE_VPT_INSN;
16416 else
16417 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16418
16419 inst.instruction |= (et.size == 16) << 28;
16420 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16421 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16422 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16423 inst.instruction |= LOW4 (inst.operands[1].reg);
16424 inst.is_neon = 1;
16425}
16426
5d281bf0
AV
16427static void
16428do_mve_vcmul (void)
16429{
16430 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16431 struct neon_type_el et
16432 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16433
16434 if (inst.cond > COND_ALWAYS)
16435 inst.pred_insn_type = INSIDE_VPT_INSN;
16436 else
16437 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16438
16439 unsigned rot = inst.relocs[0].exp.X_add_number;
16440 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16441 _("immediate out of range"));
16442
16443 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16444 || inst.operands[0].reg == inst.operands[2].reg))
16445 as_tsktsk (BAD_MVE_SRCDEST);
16446
16447 inst.instruction |= (et.size == 32) << 28;
16448 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16449 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16450 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16451 inst.instruction |= (rot > 90) << 12;
16452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16453 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16454 inst.instruction |= LOW4 (inst.operands[2].reg);
16455 inst.instruction |= (rot == 90 || rot == 270);
16456 inst.is_neon = 1;
16457}
16458
1f6234a3
AV
16459/* To handle the Low Overhead Loop instructions
16460 in Armv8.1-M Mainline and MVE. */
16461static void
16462do_t_loloop (void)
16463{
16464 unsigned long insn = inst.instruction;
16465
16466 inst.instruction = THUMB_OP32 (inst.instruction);
16467
16468 if (insn == T_MNEM_lctp)
16469 return;
16470
16471 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16472
16473 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16474 {
16475 struct neon_type_el et
16476 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16477 inst.instruction |= neon_logbits (et.size) << 20;
16478 inst.is_neon = 1;
16479 }
16480
16481 switch (insn)
16482 {
16483 case T_MNEM_letp:
16484 constraint (!inst.operands[0].present,
16485 _("expected LR"));
16486 /* fall through. */
16487 case T_MNEM_le:
16488 /* le <label>. */
16489 if (!inst.operands[0].present)
16490 inst.instruction |= 1 << 21;
16491
16492 v8_1_loop_reloc (TRUE);
16493 break;
16494
16495 case T_MNEM_wls:
16496 case T_MNEM_wlstp:
16497 v8_1_loop_reloc (FALSE);
16498 /* fall through. */
16499 case T_MNEM_dlstp:
16500 case T_MNEM_dls:
16501 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16502
16503 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16504 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16505 else if (inst.operands[1].reg == REG_PC)
16506 as_tsktsk (MVE_BAD_PC);
16507 if (inst.operands[1].reg == REG_SP)
16508 as_tsktsk (MVE_BAD_SP);
16509
16510 inst.instruction |= (inst.operands[1].reg << 16);
16511 break;
16512
16513 default:
16514 abort ();
16515 }
16516}
16517
16518
037e8744
JB
16519static void
16520do_vfp_nsyn_cmp (void)
16521{
9db2f6b4 16522 enum neon_shape rs;
1b883319
AV
16523 if (!inst.operands[0].isreg)
16524 {
16525 do_mve_vcmp ();
16526 return;
16527 }
16528 else
16529 {
16530 constraint (inst.operands[2].present, BAD_SYNTAX);
16531 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16532 BAD_FPU);
16533 }
16534
037e8744
JB
16535 if (inst.operands[1].isreg)
16536 {
9db2f6b4
RL
16537 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16538 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16539
9db2f6b4 16540 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16541 {
16542 NEON_ENCODE (SINGLE, inst);
16543 do_vfp_sp_monadic ();
16544 }
037e8744 16545 else
477330fc
RM
16546 {
16547 NEON_ENCODE (DOUBLE, inst);
16548 do_vfp_dp_rd_rm ();
16549 }
037e8744
JB
16550 }
16551 else
16552 {
9db2f6b4
RL
16553 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16554 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16555
16556 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16557 {
16558 case N_MNEM_vcmp:
16559 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16560 break;
16561 case N_MNEM_vcmpe:
16562 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16563 break;
16564 default:
16565 abort ();
16566 }
5f4273c7 16567
9db2f6b4 16568 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16569 {
16570 NEON_ENCODE (SINGLE, inst);
16571 do_vfp_sp_compare_z ();
16572 }
037e8744 16573 else
477330fc
RM
16574 {
16575 NEON_ENCODE (DOUBLE, inst);
16576 do_vfp_dp_rd ();
16577 }
037e8744
JB
16578 }
16579 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16580
16581 /* ARMv8.2 fp16 instruction. */
16582 if (rs == NS_HI || rs == NS_HH)
16583 do_scalar_fp16_v82_encode ();
037e8744
JB
16584}
16585
16586static void
16587nsyn_insert_sp (void)
16588{
16589 inst.operands[1] = inst.operands[0];
16590 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16591 inst.operands[0].reg = REG_SP;
037e8744
JB
16592 inst.operands[0].isreg = 1;
16593 inst.operands[0].writeback = 1;
16594 inst.operands[0].present = 1;
16595}
16596
037e8744
JB
16597/* Fix up Neon data-processing instructions, ORing in the correct bits for
16598 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16599
88714cb8
DG
16600static void
16601neon_dp_fixup (struct arm_it* insn)
037e8744 16602{
88714cb8
DG
16603 unsigned int i = insn->instruction;
16604 insn->is_neon = 1;
16605
037e8744
JB
16606 if (thumb_mode)
16607 {
16608 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16609 if (i & (1 << 24))
477330fc 16610 i |= 1 << 28;
5f4273c7 16611
037e8744 16612 i &= ~(1 << 24);
5f4273c7 16613
037e8744
JB
16614 i |= 0xef000000;
16615 }
16616 else
16617 i |= 0xf2000000;
5f4273c7 16618
88714cb8 16619 insn->instruction = i;
037e8744
JB
16620}
16621
5ee91343 16622static void
7df54120 16623mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16624{
16625 if (inst.operands[2].reg == REG_SP)
16626 as_tsktsk (MVE_BAD_SP);
16627 else if (inst.operands[2].reg == REG_PC)
16628 as_tsktsk (MVE_BAD_PC);
16629
16630 if (fp)
16631 {
16632 /* vadd. */
16633 if (((unsigned)inst.instruction) == 0xd00)
16634 inst.instruction = 0xee300f40;
16635 /* vsub. */
16636 else if (((unsigned)inst.instruction) == 0x200d00)
16637 inst.instruction = 0xee301f40;
a8465a06
AV
16638 /* vmul. */
16639 else if (((unsigned)inst.instruction) == 0x1000d10)
16640 inst.instruction = 0xee310e60;
5ee91343
AV
16641
16642 /* Setting size which is 1 for F16 and 0 for F32. */
16643 inst.instruction |= (size == 16) << 28;
16644 }
16645 else
16646 {
16647 /* vadd. */
16648 if (((unsigned)inst.instruction) == 0x800)
16649 inst.instruction = 0xee010f40;
16650 /* vsub. */
16651 else if (((unsigned)inst.instruction) == 0x1000800)
16652 inst.instruction = 0xee011f40;
7df54120
AV
16653 /* vhadd. */
16654 else if (((unsigned)inst.instruction) == 0)
16655 inst.instruction = 0xee000f40;
16656 /* vhsub. */
16657 else if (((unsigned)inst.instruction) == 0x200)
16658 inst.instruction = 0xee001f40;
a8465a06
AV
16659 /* vmla. */
16660 else if (((unsigned)inst.instruction) == 0x900)
16661 inst.instruction = 0xee010e40;
16662 /* vmul. */
16663 else if (((unsigned)inst.instruction) == 0x910)
16664 inst.instruction = 0xee011e60;
16665 /* vqadd. */
16666 else if (((unsigned)inst.instruction) == 0x10)
16667 inst.instruction = 0xee000f60;
16668 /* vqsub. */
16669 else if (((unsigned)inst.instruction) == 0x210)
16670 inst.instruction = 0xee001f60;
42b16635
AV
16671 /* vqrdmlah. */
16672 else if (((unsigned)inst.instruction) == 0x3000b10)
16673 inst.instruction = 0xee000e40;
16674 /* vqdmulh. */
16675 else if (((unsigned)inst.instruction) == 0x0000b00)
16676 inst.instruction = 0xee010e60;
16677 /* vqrdmulh. */
16678 else if (((unsigned)inst.instruction) == 0x1000b00)
16679 inst.instruction = 0xfe010e60;
7df54120
AV
16680
16681 /* Set U-bit. */
16682 inst.instruction |= U << 28;
16683
5ee91343
AV
16684 /* Setting bits for size. */
16685 inst.instruction |= neon_logbits (size) << 20;
16686 }
16687 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16688 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16689 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16690 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16691 inst.instruction |= inst.operands[2].reg;
16692 inst.is_neon = 1;
16693}
16694
a302e574
AV
16695static void
16696mve_encode_rqq (unsigned bit28, unsigned size)
16697{
16698 inst.instruction |= bit28 << 28;
16699 inst.instruction |= neon_logbits (size) << 20;
16700 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16701 inst.instruction |= inst.operands[0].reg << 12;
16702 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16703 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16704 inst.instruction |= LOW4 (inst.operands[2].reg);
16705 inst.is_neon = 1;
16706}
16707
886e1c73
AV
16708static void
16709mve_encode_qqq (int ubit, int size)
16710{
16711
16712 inst.instruction |= (ubit != 0) << 28;
16713 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16714 inst.instruction |= neon_logbits (size) << 20;
16715 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16716 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16717 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16718 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16719 inst.instruction |= LOW4 (inst.operands[2].reg);
16720
16721 inst.is_neon = 1;
16722}
16723
26c1e780
AV
16724static void
16725mve_encode_rq (unsigned bit28, unsigned size)
16726{
16727 inst.instruction |= bit28 << 28;
16728 inst.instruction |= neon_logbits (size) << 18;
16729 inst.instruction |= inst.operands[0].reg << 12;
16730 inst.instruction |= LOW4 (inst.operands[1].reg);
16731 inst.is_neon = 1;
16732}
886e1c73 16733
93925576
AV
16734static void
16735mve_encode_rrqq (unsigned U, unsigned size)
16736{
16737 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16738
16739 inst.instruction |= U << 28;
16740 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16741 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16742 inst.instruction |= (size == 32) << 16;
16743 inst.instruction |= inst.operands[0].reg << 12;
16744 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16745 inst.instruction |= inst.operands[3].reg;
16746 inst.is_neon = 1;
16747}
16748
aab2c27d
MM
16749/* Helper function for neon_three_same handling the operands. */
16750static void
16751neon_three_args (int isquad)
16752{
16753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16755 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16756 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16757 inst.instruction |= LOW4 (inst.operands[2].reg);
16758 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16759 inst.instruction |= (isquad != 0) << 6;
16760 inst.is_neon = 1;
16761}
16762
037e8744
JB
16763/* Encode insns with bit pattern:
16764
16765 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16766 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16767
037e8744
JB
16768 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16769 different meaning for some instruction. */
16770
16771static void
16772neon_three_same (int isquad, int ubit, int size)
16773{
aab2c27d 16774 neon_three_args (isquad);
037e8744
JB
16775 inst.instruction |= (ubit != 0) << 24;
16776 if (size != -1)
16777 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16778
88714cb8 16779 neon_dp_fixup (&inst);
037e8744
JB
16780}
16781
16782/* Encode instructions of the form:
16783
16784 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16785 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16786
16787 Don't write size if SIZE == -1. */
16788
16789static void
16790neon_two_same (int qbit, int ubit, int size)
16791{
16792 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16793 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16794 inst.instruction |= LOW4 (inst.operands[1].reg);
16795 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16796 inst.instruction |= (qbit != 0) << 6;
16797 inst.instruction |= (ubit != 0) << 24;
16798
16799 if (size != -1)
16800 inst.instruction |= neon_logbits (size) << 18;
16801
88714cb8 16802 neon_dp_fixup (&inst);
5287ad62
JB
16803}
16804
7df54120
AV
16805enum vfp_or_neon_is_neon_bits
16806{
16807NEON_CHECK_CC = 1,
16808NEON_CHECK_ARCH = 2,
16809NEON_CHECK_ARCH8 = 4
16810};
16811
16812/* Call this function if an instruction which may have belonged to the VFP or
16813 Neon instruction sets, but turned out to be a Neon instruction (due to the
16814 operand types involved, etc.). We have to check and/or fix-up a couple of
16815 things:
16816
16817 - Make sure the user hasn't attempted to make a Neon instruction
16818 conditional.
16819 - Alter the value in the condition code field if necessary.
16820 - Make sure that the arch supports Neon instructions.
16821
16822 Which of these operations take place depends on bits from enum
16823 vfp_or_neon_is_neon_bits.
16824
16825 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16826 current instruction's condition is COND_ALWAYS, the condition field is
16827 changed to inst.uncond_value. This is necessary because instructions shared
16828 between VFP and Neon may be conditional for the VFP variants only, and the
16829 unconditional Neon version must have, e.g., 0xF in the condition field. */
16830
16831static int
16832vfp_or_neon_is_neon (unsigned check)
16833{
16834/* Conditions are always legal in Thumb mode (IT blocks). */
16835if (!thumb_mode && (check & NEON_CHECK_CC))
16836 {
16837 if (inst.cond != COND_ALWAYS)
16838 {
16839 first_error (_(BAD_COND));
16840 return FAIL;
16841 }
16842 if (inst.uncond_value != -1)
16843 inst.instruction |= inst.uncond_value << 28;
16844 }
16845
16846
16847 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16848 || ((check & NEON_CHECK_ARCH8)
16849 && !mark_feature_used (&fpu_neon_ext_armv8)))
16850 {
16851 first_error (_(BAD_FPU));
16852 return FAIL;
16853 }
16854
16855return SUCCESS;
16856}
16857
64c350f2
AV
16858
16859/* Return TRUE if the SIMD instruction is available for the current
16860 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16861 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16862 vfp_or_neon_is_neon for the NEON specific checks. */
16863
16864static bfd_boolean
7df54120
AV
16865check_simd_pred_availability (int fp, unsigned check)
16866{
16867if (inst.cond > COND_ALWAYS)
16868 {
16869 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16870 {
16871 inst.error = BAD_FPU;
64c350f2 16872 return FALSE;
7df54120
AV
16873 }
16874 inst.pred_insn_type = INSIDE_VPT_INSN;
16875 }
16876else if (inst.cond < COND_ALWAYS)
16877 {
16878 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16879 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16880 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16881 return FALSE;
7df54120
AV
16882 }
16883else
16884 {
16885 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16886 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16887 return FALSE;
7df54120
AV
16888
16889 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16890 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16891 }
64c350f2 16892return TRUE;
7df54120
AV
16893}
16894
5287ad62
JB
16895/* Neon instruction encoders, in approximate order of appearance. */
16896
16897static void
16898do_neon_dyadic_i_su (void)
16899{
64c350f2 16900 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16901 return;
16902
16903 enum neon_shape rs;
16904 struct neon_type_el et;
16905 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16906 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16907 else
16908 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16909
16910 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16911
16912
16913 if (rs != NS_QQR)
16914 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16915 else
16916 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16917}
16918
16919static void
16920do_neon_dyadic_i64_su (void)
16921{
64c350f2 16922 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16923 return;
16924 enum neon_shape rs;
16925 struct neon_type_el et;
16926 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16927 {
16928 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16929 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16930 }
16931 else
16932 {
16933 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16934 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16935 }
16936 if (rs == NS_QQR)
16937 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16938 else
16939 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16940}
16941
16942static void
16943neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16944 unsigned immbits)
5287ad62
JB
16945{
16946 unsigned size = et.size >> 3;
16947 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16948 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16949 inst.instruction |= LOW4 (inst.operands[1].reg);
16950 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16951 inst.instruction |= (isquad != 0) << 6;
16952 inst.instruction |= immbits << 16;
16953 inst.instruction |= (size >> 3) << 7;
16954 inst.instruction |= (size & 0x7) << 19;
16955 if (write_ubit)
16956 inst.instruction |= (uval != 0) << 24;
16957
88714cb8 16958 neon_dp_fixup (&inst);
5287ad62
JB
16959}
16960
16961static void
5150f0d8 16962do_neon_shl (void)
5287ad62 16963{
64c350f2 16964 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16965 return;
16966
5287ad62
JB
16967 if (!inst.operands[2].isreg)
16968 {
5150f0d8
AV
16969 enum neon_shape rs;
16970 struct neon_type_el et;
16971 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16972 {
16973 rs = neon_select_shape (NS_QQI, NS_NULL);
16974 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16975 }
16976 else
16977 {
16978 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16979 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16980 }
cb3b1e65
JB
16981 int imm = inst.operands[2].imm;
16982
16983 constraint (imm < 0 || (unsigned)imm >= et.size,
16984 _("immediate out of range for shift"));
88714cb8 16985 NEON_ENCODE (IMMED, inst);
cb3b1e65 16986 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16987 }
16988 else
16989 {
5150f0d8
AV
16990 enum neon_shape rs;
16991 struct neon_type_el et;
16992 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16993 {
16994 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16995 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16996 }
16997 else
16998 {
16999 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17000 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17001 }
17002
17003
17004 if (rs == NS_QQR)
17005 {
17006 constraint (inst.operands[0].reg != inst.operands[1].reg,
17007 _("invalid instruction shape"));
17008 if (inst.operands[2].reg == REG_SP)
17009 as_tsktsk (MVE_BAD_SP);
17010 else if (inst.operands[2].reg == REG_PC)
17011 as_tsktsk (MVE_BAD_PC);
17012
17013 inst.instruction = 0xee311e60;
17014 inst.instruction |= (et.type == NT_unsigned) << 28;
17015 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17016 inst.instruction |= neon_logbits (et.size) << 18;
17017 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17018 inst.instruction |= inst.operands[2].reg;
17019 inst.is_neon = 1;
17020 }
17021 else
17022 {
17023 unsigned int tmp;
17024
17025 /* VSHL/VQSHL 3-register variants have syntax such as:
17026 vshl.xx Dd, Dm, Dn
17027 whereas other 3-register operations encoded by neon_three_same have
17028 syntax like:
17029 vadd.xx Dd, Dn, Dm
17030 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17031 operands[2].reg here. */
17032 tmp = inst.operands[2].reg;
17033 inst.operands[2].reg = inst.operands[1].reg;
17034 inst.operands[1].reg = tmp;
17035 NEON_ENCODE (INTEGER, inst);
17036 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17037 }
5287ad62
JB
17038 }
17039}
17040
17041static void
5150f0d8 17042do_neon_qshl (void)
5287ad62 17043{
64c350f2 17044 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
17045 return;
17046
5287ad62
JB
17047 if (!inst.operands[2].isreg)
17048 {
5150f0d8
AV
17049 enum neon_shape rs;
17050 struct neon_type_el et;
17051 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17052 {
17053 rs = neon_select_shape (NS_QQI, NS_NULL);
17054 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17055 }
17056 else
17057 {
17058 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17059 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17060 }
cb3b1e65 17061 int imm = inst.operands[2].imm;
627907b7 17062
cb3b1e65
JB
17063 constraint (imm < 0 || (unsigned)imm >= et.size,
17064 _("immediate out of range for shift"));
88714cb8 17065 NEON_ENCODE (IMMED, inst);
cb3b1e65 17066 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
17067 }
17068 else
17069 {
5150f0d8
AV
17070 enum neon_shape rs;
17071 struct neon_type_el et;
627907b7 17072
5150f0d8
AV
17073 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17074 {
17075 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17076 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17077 }
17078 else
17079 {
17080 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17081 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17082 }
17083
17084 if (rs == NS_QQR)
17085 {
17086 constraint (inst.operands[0].reg != inst.operands[1].reg,
17087 _("invalid instruction shape"));
17088 if (inst.operands[2].reg == REG_SP)
17089 as_tsktsk (MVE_BAD_SP);
17090 else if (inst.operands[2].reg == REG_PC)
17091 as_tsktsk (MVE_BAD_PC);
17092
17093 inst.instruction = 0xee311ee0;
17094 inst.instruction |= (et.type == NT_unsigned) << 28;
17095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17096 inst.instruction |= neon_logbits (et.size) << 18;
17097 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17098 inst.instruction |= inst.operands[2].reg;
17099 inst.is_neon = 1;
17100 }
17101 else
17102 {
17103 unsigned int tmp;
17104
17105 /* See note in do_neon_shl. */
17106 tmp = inst.operands[2].reg;
17107 inst.operands[2].reg = inst.operands[1].reg;
17108 inst.operands[1].reg = tmp;
17109 NEON_ENCODE (INTEGER, inst);
17110 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17111 }
5287ad62
JB
17112 }
17113}
17114
627907b7
JB
17115static void
17116do_neon_rshl (void)
17117{
64c350f2 17118 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
17119 return;
17120
17121 enum neon_shape rs;
17122 struct neon_type_el et;
17123 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17124 {
17125 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17126 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17127 }
17128 else
17129 {
17130 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17131 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17132 }
17133
627907b7
JB
17134 unsigned int tmp;
17135
1be7aba3
AV
17136 if (rs == NS_QQR)
17137 {
17138 if (inst.operands[2].reg == REG_PC)
17139 as_tsktsk (MVE_BAD_PC);
17140 else if (inst.operands[2].reg == REG_SP)
17141 as_tsktsk (MVE_BAD_SP);
17142
17143 constraint (inst.operands[0].reg != inst.operands[1].reg,
17144 _("invalid instruction shape"));
17145
17146 if (inst.instruction == 0x0000510)
17147 /* We are dealing with vqrshl. */
17148 inst.instruction = 0xee331ee0;
17149 else
17150 /* We are dealing with vrshl. */
17151 inst.instruction = 0xee331e60;
17152
17153 inst.instruction |= (et.type == NT_unsigned) << 28;
17154 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17155 inst.instruction |= neon_logbits (et.size) << 18;
17156 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17157 inst.instruction |= inst.operands[2].reg;
17158 inst.is_neon = 1;
17159 }
17160 else
17161 {
17162 tmp = inst.operands[2].reg;
17163 inst.operands[2].reg = inst.operands[1].reg;
17164 inst.operands[1].reg = tmp;
17165 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17166 }
627907b7
JB
17167}
17168
5287ad62
JB
17169static int
17170neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17171{
036dc3f7
PB
17172 /* Handle .I8 pseudo-instructions. */
17173 if (size == 8)
5287ad62 17174 {
5287ad62 17175 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
17176 FIXME is this the intended semantics? There doesn't seem much point in
17177 accepting .I8 if so. */
5287ad62
JB
17178 immediate |= immediate << 8;
17179 size = 16;
036dc3f7
PB
17180 }
17181
17182 if (size >= 32)
17183 {
17184 if (immediate == (immediate & 0x000000ff))
17185 {
17186 *immbits = immediate;
17187 return 0x1;
17188 }
17189 else if (immediate == (immediate & 0x0000ff00))
17190 {
17191 *immbits = immediate >> 8;
17192 return 0x3;
17193 }
17194 else if (immediate == (immediate & 0x00ff0000))
17195 {
17196 *immbits = immediate >> 16;
17197 return 0x5;
17198 }
17199 else if (immediate == (immediate & 0xff000000))
17200 {
17201 *immbits = immediate >> 24;
17202 return 0x7;
17203 }
17204 if ((immediate & 0xffff) != (immediate >> 16))
17205 goto bad_immediate;
17206 immediate &= 0xffff;
5287ad62
JB
17207 }
17208
17209 if (immediate == (immediate & 0x000000ff))
17210 {
17211 *immbits = immediate;
036dc3f7 17212 return 0x9;
5287ad62
JB
17213 }
17214 else if (immediate == (immediate & 0x0000ff00))
17215 {
17216 *immbits = immediate >> 8;
036dc3f7 17217 return 0xb;
5287ad62
JB
17218 }
17219
17220 bad_immediate:
dcbf9037 17221 first_error (_("immediate value out of range"));
5287ad62
JB
17222 return FAIL;
17223}
17224
5287ad62
JB
17225static void
17226do_neon_logic (void)
17227{
17228 if (inst.operands[2].present && inst.operands[2].isreg)
17229 {
037e8744 17230 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17231 if (rs == NS_QQQ
64c350f2
AV
17232 && !check_simd_pred_availability (FALSE,
17233 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17234 return;
17235 else if (rs != NS_QQQ
17236 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17237 first_error (BAD_FPU);
17238
5287ad62
JB
17239 neon_check_type (3, rs, N_IGNORE_TYPE);
17240 /* U bit and size field were set as part of the bitmask. */
88714cb8 17241 NEON_ENCODE (INTEGER, inst);
037e8744 17242 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17243 }
17244 else
17245 {
4316f0d2
DG
17246 const int three_ops_form = (inst.operands[2].present
17247 && !inst.operands[2].isreg);
17248 const int immoperand = (three_ops_form ? 2 : 1);
17249 enum neon_shape rs = (three_ops_form
17250 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17251 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17252 /* Because neon_select_shape makes the second operand a copy of the first
17253 if the second operand is not present. */
17254 if (rs == NS_QQI
64c350f2
AV
17255 && !check_simd_pred_availability (FALSE,
17256 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17257 return;
17258 else if (rs != NS_QQI
17259 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17260 first_error (BAD_FPU);
17261
17262 struct neon_type_el et;
17263 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17264 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17265 else
17266 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17267 | N_KEY, N_EQK);
17268
17269 if (et.type == NT_invtype)
17270 return;
21d799b5 17271 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17272 unsigned immbits;
17273 int cmode;
5f4273c7 17274
5f4273c7 17275
4316f0d2
DG
17276 if (three_ops_form)
17277 constraint (inst.operands[0].reg != inst.operands[1].reg,
17278 _("first and second operands shall be the same register"));
17279
88714cb8 17280 NEON_ENCODE (IMMED, inst);
5287ad62 17281
4316f0d2 17282 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17283 if (et.size == 64)
17284 {
17285 /* .i64 is a pseudo-op, so the immediate must be a repeating
17286 pattern. */
4316f0d2
DG
17287 if (immbits != (inst.operands[immoperand].regisimm ?
17288 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17289 {
17290 /* Set immbits to an invalid constant. */
17291 immbits = 0xdeadbeef;
17292 }
17293 }
17294
5287ad62 17295 switch (opcode)
477330fc
RM
17296 {
17297 case N_MNEM_vbic:
17298 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17299 break;
17300
17301 case N_MNEM_vorr:
17302 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17303 break;
17304
17305 case N_MNEM_vand:
17306 /* Pseudo-instruction for VBIC. */
17307 neon_invert_size (&immbits, 0, et.size);
17308 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17309 break;
17310
17311 case N_MNEM_vorn:
17312 /* Pseudo-instruction for VORR. */
17313 neon_invert_size (&immbits, 0, et.size);
17314 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17315 break;
17316
17317 default:
17318 abort ();
17319 }
5287ad62
JB
17320
17321 if (cmode == FAIL)
477330fc 17322 return;
5287ad62 17323
037e8744 17324 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17325 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17327 inst.instruction |= cmode << 8;
17328 neon_write_immbits (immbits);
5f4273c7 17329
88714cb8 17330 neon_dp_fixup (&inst);
5287ad62
JB
17331 }
17332}
17333
17334static void
17335do_neon_bitfield (void)
17336{
037e8744 17337 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17338 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17339 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17340}
17341
17342static void
dcbf9037 17343neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17344 unsigned destbits)
5287ad62 17345{
5ee91343 17346 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17347 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17348 types | N_KEY);
5287ad62
JB
17349 if (et.type == NT_float)
17350 {
88714cb8 17351 NEON_ENCODE (FLOAT, inst);
5ee91343 17352 if (rs == NS_QQR)
7df54120 17353 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17354 else
17355 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17356 }
17357 else
17358 {
88714cb8 17359 NEON_ENCODE (INTEGER, inst);
5ee91343 17360 if (rs == NS_QQR)
a8465a06 17361 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17362 else
17363 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17364 }
17365}
17366
5287ad62
JB
17367
17368static void
17369do_neon_dyadic_if_su_d (void)
17370{
17371 /* This version only allow D registers, but that constraint is enforced during
17372 operand parsing so we don't need to do anything extra here. */
dcbf9037 17373 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17374}
17375
5287ad62
JB
17376static void
17377do_neon_dyadic_if_i_d (void)
17378{
428e3f1f
PB
17379 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17380 affected if we specify unsigned args. */
17381 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17382}
17383
f5f10c66
AV
17384static void
17385do_mve_vstr_vldr_QI (int size, int elsize, int load)
17386{
17387 constraint (size < 32, BAD_ADDR_MODE);
17388 constraint (size != elsize, BAD_EL_TYPE);
17389 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17390 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17391 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17392 _("destination register and offset register may not be the"
17393 " same"));
17394
17395 int imm = inst.relocs[0].exp.X_add_number;
17396 int add = 1;
17397 if (imm < 0)
17398 {
17399 add = 0;
17400 imm = -imm;
17401 }
17402 constraint ((imm % (size / 8) != 0)
17403 || imm > (0x7f << neon_logbits (size)),
17404 (size == 32) ? _("immediate must be a multiple of 4 in the"
17405 " range of +/-[0,508]")
17406 : _("immediate must be a multiple of 8 in the"
17407 " range of +/-[0,1016]"));
17408 inst.instruction |= 0x11 << 24;
17409 inst.instruction |= add << 23;
17410 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17411 inst.instruction |= inst.operands[1].writeback << 21;
17412 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17413 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17414 inst.instruction |= 1 << 12;
17415 inst.instruction |= (size == 64) << 8;
17416 inst.instruction &= 0xffffff00;
17417 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17418 inst.instruction |= imm >> neon_logbits (size);
17419}
17420
17421static void
17422do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17423{
17424 unsigned os = inst.operands[1].imm >> 5;
e449ea97 17425 unsigned type = inst.vectype.el[0].type;
f5f10c66
AV
17426 constraint (os != 0 && size == 8,
17427 _("can not shift offsets when accessing less than half-word"));
17428 constraint (os && os != neon_logbits (size),
17429 _("shift immediate must be 1, 2 or 3 for half-word, word"
17430 " or double-word accesses respectively"));
17431 if (inst.operands[1].reg == REG_PC)
17432 as_tsktsk (MVE_BAD_PC);
17433
17434 switch (size)
17435 {
17436 case 8:
17437 constraint (elsize >= 64, BAD_EL_TYPE);
17438 break;
17439 case 16:
17440 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17441 break;
17442 case 32:
17443 case 64:
17444 constraint (elsize != size, BAD_EL_TYPE);
17445 break;
17446 default:
17447 break;
17448 }
17449 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17450 BAD_ADDR_MODE);
17451 if (load)
17452 {
17453 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17454 _("destination register and offset register may not be"
17455 " the same"));
e449ea97
SP
17456 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17457 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
f5f10c66 17458 BAD_EL_TYPE);
e449ea97 17459 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
f5f10c66
AV
17460 }
17461 else
17462 {
e449ea97 17463 constraint (type != NT_untyped, BAD_EL_TYPE);
f5f10c66
AV
17464 }
17465
17466 inst.instruction |= 1 << 23;
17467 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17468 inst.instruction |= inst.operands[1].reg << 16;
17469 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17470 inst.instruction |= neon_logbits (elsize) << 7;
17471 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17472 inst.instruction |= LOW4 (inst.operands[1].imm);
17473 inst.instruction |= !!os;
17474}
17475
17476static void
17477do_mve_vstr_vldr_RI (int size, int elsize, int load)
17478{
17479 enum neon_el_type type = inst.vectype.el[0].type;
17480
17481 constraint (size >= 64, BAD_ADDR_MODE);
17482 switch (size)
17483 {
17484 case 16:
17485 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17486 break;
17487 case 32:
17488 constraint (elsize != size, BAD_EL_TYPE);
17489 break;
17490 default:
17491 break;
17492 }
17493 if (load)
17494 {
17495 constraint (elsize != size && type != NT_unsigned
17496 && type != NT_signed, BAD_EL_TYPE);
17497 }
17498 else
17499 {
17500 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17501 }
17502
17503 int imm = inst.relocs[0].exp.X_add_number;
17504 int add = 1;
17505 if (imm < 0)
17506 {
17507 add = 0;
17508 imm = -imm;
17509 }
17510
17511 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17512 {
17513 switch (size)
17514 {
17515 case 8:
17516 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17517 break;
17518 case 16:
17519 constraint (1, _("immediate must be a multiple of 2 in the"
17520 " range of +/-[0,254]"));
17521 break;
17522 case 32:
17523 constraint (1, _("immediate must be a multiple of 4 in the"
17524 " range of +/-[0,508]"));
17525 break;
17526 }
17527 }
17528
17529 if (size != elsize)
17530 {
17531 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17532 constraint (inst.operands[0].reg > 14,
17533 _("MVE vector register in the range [Q0..Q7] expected"));
17534 inst.instruction |= (load && type == NT_unsigned) << 28;
17535 inst.instruction |= (size == 16) << 19;
17536 inst.instruction |= neon_logbits (elsize) << 7;
17537 }
17538 else
17539 {
17540 if (inst.operands[1].reg == REG_PC)
17541 as_tsktsk (MVE_BAD_PC);
17542 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17543 as_tsktsk (MVE_BAD_SP);
17544 inst.instruction |= 1 << 12;
17545 inst.instruction |= neon_logbits (size) << 7;
17546 }
17547 inst.instruction |= inst.operands[1].preind << 24;
17548 inst.instruction |= add << 23;
17549 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17550 inst.instruction |= inst.operands[1].writeback << 21;
17551 inst.instruction |= inst.operands[1].reg << 16;
17552 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17553 inst.instruction &= 0xffffff80;
17554 inst.instruction |= imm >> neon_logbits (size);
17555
17556}
17557
17558static void
17559do_mve_vstr_vldr (void)
17560{
17561 unsigned size;
17562 int load = 0;
17563
17564 if (inst.cond > COND_ALWAYS)
17565 inst.pred_insn_type = INSIDE_VPT_INSN;
17566 else
17567 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17568
17569 switch (inst.instruction)
17570 {
17571 default:
17572 gas_assert (0);
17573 break;
17574 case M_MNEM_vldrb:
17575 load = 1;
17576 /* fall through. */
17577 case M_MNEM_vstrb:
17578 size = 8;
17579 break;
17580 case M_MNEM_vldrh:
17581 load = 1;
17582 /* fall through. */
17583 case M_MNEM_vstrh:
17584 size = 16;
17585 break;
17586 case M_MNEM_vldrw:
17587 load = 1;
17588 /* fall through. */
17589 case M_MNEM_vstrw:
17590 size = 32;
17591 break;
17592 case M_MNEM_vldrd:
17593 load = 1;
17594 /* fall through. */
17595 case M_MNEM_vstrd:
17596 size = 64;
17597 break;
17598 }
17599 unsigned elsize = inst.vectype.el[0].size;
17600
17601 if (inst.operands[1].isquad)
17602 {
17603 /* We are dealing with [Q, imm]{!} cases. */
17604 do_mve_vstr_vldr_QI (size, elsize, load);
17605 }
17606 else
17607 {
17608 if (inst.operands[1].immisreg == 2)
17609 {
17610 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17611 do_mve_vstr_vldr_RQ (size, elsize, load);
17612 }
17613 else if (!inst.operands[1].immisreg)
17614 {
17615 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17616 do_mve_vstr_vldr_RI (size, elsize, load);
17617 }
17618 else
17619 constraint (1, BAD_ADDR_MODE);
17620 }
17621
17622 inst.is_neon = 1;
17623}
17624
35c228db
AV
17625static void
17626do_mve_vst_vld (void)
17627{
17628 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17629 return;
17630
17631 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17632 || inst.relocs[0].exp.X_add_number != 0
17633 || inst.operands[1].immisreg != 0,
17634 BAD_ADDR_MODE);
17635 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17636 if (inst.operands[1].reg == REG_PC)
17637 as_tsktsk (MVE_BAD_PC);
17638 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17639 as_tsktsk (MVE_BAD_SP);
17640
17641
17642 /* These instructions are one of the "exceptions" mentioned in
17643 handle_pred_state. They are MVE instructions that are not VPT compatible
17644 and do not accept a VPT code, thus appending such a code is a syntax
17645 error. */
17646 if (inst.cond > COND_ALWAYS)
17647 first_error (BAD_SYNTAX);
17648 /* If we append a scalar condition code we can set this to
17649 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17650 else if (inst.cond < COND_ALWAYS)
17651 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17652 else
17653 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17654
17655 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17656 inst.instruction |= inst.operands[1].writeback << 21;
17657 inst.instruction |= inst.operands[1].reg << 16;
17658 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17659 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17660 inst.is_neon = 1;
17661}
17662
26c1e780
AV
17663static void
17664do_mve_vaddlv (void)
17665{
17666 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17667 struct neon_type_el et
17668 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17669
17670 if (et.type == NT_invtype)
17671 first_error (BAD_EL_TYPE);
17672
17673 if (inst.cond > COND_ALWAYS)
17674 inst.pred_insn_type = INSIDE_VPT_INSN;
17675 else
17676 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17677
17678 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17679
17680 inst.instruction |= (et.type == NT_unsigned) << 28;
17681 inst.instruction |= inst.operands[1].reg << 19;
17682 inst.instruction |= inst.operands[0].reg << 12;
17683 inst.instruction |= inst.operands[2].reg;
17684 inst.is_neon = 1;
17685}
17686
5287ad62 17687static void
5ee91343 17688do_neon_dyadic_if_su (void)
5287ad62 17689{
5ee91343
AV
17690 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17691 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17692 N_SUF_32 | N_KEY);
17693
935295b5
AV
17694 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17695 || inst.instruction == ((unsigned) N_MNEM_vmin))
17696 && et.type == NT_float
17697 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17698
64c350f2
AV
17699 if (!check_simd_pred_availability (et.type == NT_float,
17700 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17701 return;
17702
5ee91343
AV
17703 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17704}
17705
17706static void
17707do_neon_addsub_if_i (void)
17708{
17709 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17710 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17711 return;
17712
5ee91343
AV
17713 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17714 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17715 N_EQK, N_IF_32 | N_I64 | N_KEY);
17716
17717 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17718 /* If we are parsing Q registers and the element types match MVE, which NEON
17719 also supports, then we must check whether this is an instruction that can
17720 be used by both MVE/NEON. This distinction can be made based on whether
17721 they are predicated or not. */
17722 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17723 {
64c350f2
AV
17724 if (!check_simd_pred_availability (et.type == NT_float,
17725 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17726 return;
17727 }
17728 else
17729 {
17730 /* If they are either in a D register or are using an unsupported. */
17731 if (rs != NS_QQR
17732 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17733 return;
17734 }
17735
5287ad62
JB
17736 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17737 affected if we specify unsigned args. */
dcbf9037 17738 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17739}
17740
17741/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17742 result to be:
17743 V<op> A,B (A is operand 0, B is operand 2)
17744 to mean:
17745 V<op> A,B,A
17746 not:
17747 V<op> A,B,B
17748 so handle that case specially. */
17749
17750static void
17751neon_exchange_operands (void)
17752{
5287ad62
JB
17753 if (inst.operands[1].present)
17754 {
e1fa0163
NC
17755 void *scratch = xmalloc (sizeof (inst.operands[0]));
17756
5287ad62
JB
17757 /* Swap operands[1] and operands[2]. */
17758 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17759 inst.operands[1] = inst.operands[2];
17760 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17761 free (scratch);
5287ad62
JB
17762 }
17763 else
17764 {
17765 inst.operands[1] = inst.operands[2];
17766 inst.operands[2] = inst.operands[0];
17767 }
17768}
17769
17770static void
17771neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17772{
17773 if (inst.operands[2].isreg)
17774 {
17775 if (invert)
477330fc 17776 neon_exchange_operands ();
dcbf9037 17777 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17778 }
17779 else
17780 {
037e8744 17781 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17782 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17783 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17784
88714cb8 17785 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17786 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17787 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17788 inst.instruction |= LOW4 (inst.operands[1].reg);
17789 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17790 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17791 inst.instruction |= (et.type == NT_float) << 10;
17792 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17793
88714cb8 17794 neon_dp_fixup (&inst);
5287ad62
JB
17795 }
17796}
17797
17798static void
17799do_neon_cmp (void)
17800{
cc933301 17801 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17802}
17803
17804static void
17805do_neon_cmp_inv (void)
17806{
cc933301 17807 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17808}
17809
17810static void
17811do_neon_ceq (void)
17812{
17813 neon_compare (N_IF_32, N_IF_32, FALSE);
17814}
17815
17816/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17817 scalars, which are encoded in 5 bits, M : Rm.
17818 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17819 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17820 index in M.
17821
17822 Dot Product instructions are similar to multiply instructions except elsize
17823 should always be 32.
17824
17825 This function translates SCALAR, which is GAS's internal encoding of indexed
17826 scalar register, to raw encoding. There is also register and index range
17827 check based on ELSIZE. */
5287ad62
JB
17828
17829static unsigned
17830neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17831{
dcbf9037
JB
17832 unsigned regno = NEON_SCALAR_REG (scalar);
17833 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17834
17835 switch (elsize)
17836 {
17837 case 16:
17838 if (regno > 7 || elno > 3)
477330fc 17839 goto bad_scalar;
5287ad62 17840 return regno | (elno << 3);
5f4273c7 17841
5287ad62
JB
17842 case 32:
17843 if (regno > 15 || elno > 1)
477330fc 17844 goto bad_scalar;
5287ad62
JB
17845 return regno | (elno << 4);
17846
17847 default:
17848 bad_scalar:
dcbf9037 17849 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17850 }
17851
17852 return 0;
17853}
17854
17855/* Encode multiply / multiply-accumulate scalar instructions. */
17856
17857static void
17858neon_mul_mac (struct neon_type_el et, int ubit)
17859{
dcbf9037
JB
17860 unsigned scalar;
17861
17862 /* Give a more helpful error message if we have an invalid type. */
17863 if (et.type == NT_invtype)
17864 return;
5f4273c7 17865
dcbf9037 17866 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17867 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17868 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17869 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17870 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17871 inst.instruction |= LOW4 (scalar);
17872 inst.instruction |= HI1 (scalar) << 5;
17873 inst.instruction |= (et.type == NT_float) << 8;
17874 inst.instruction |= neon_logbits (et.size) << 20;
17875 inst.instruction |= (ubit != 0) << 24;
17876
88714cb8 17877 neon_dp_fixup (&inst);
5287ad62
JB
17878}
17879
17880static void
17881do_neon_mac_maybe_scalar (void)
17882{
037e8744
JB
17883 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17884 return;
17885
64c350f2 17886 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17887 return;
17888
5287ad62
JB
17889 if (inst.operands[2].isscalar)
17890 {
a8465a06 17891 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17892 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17893 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17894 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17895 NEON_ENCODE (SCALAR, inst);
037e8744 17896 neon_mul_mac (et, neon_quad (rs));
5287ad62 17897 }
a8465a06
AV
17898 else if (!inst.operands[2].isvec)
17899 {
17900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17901
17902 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17903 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17904
17905 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17906 }
5287ad62 17907 else
428e3f1f 17908 {
a8465a06 17909 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17910 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17911 affected if we specify unsigned args. */
17912 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17913 }
5287ad62
JB
17914}
17915
aab2c27d
MM
17916static void
17917do_bfloat_vfma (void)
17918{
17919 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17920 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17921 enum neon_shape rs;
17922 int t_bit = 0;
17923
17924 if (inst.instruction != B_MNEM_vfmab)
17925 {
17926 t_bit = 1;
17927 inst.instruction = B_MNEM_vfmat;
17928 }
17929
17930 if (inst.operands[2].isscalar)
17931 {
17932 rs = neon_select_shape (NS_QQS, NS_NULL);
17933 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17934
17935 inst.instruction |= (1 << 25);
17936 int index = inst.operands[2].reg & 0xf;
17937 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17938 inst.operands[2].reg >>= 4;
17939 constraint (!(inst.operands[2].reg < 8),
17940 _("indexed register must be less than 8"));
17941 neon_three_args (t_bit);
17942 inst.instruction |= ((index & 1) << 3);
17943 inst.instruction |= ((index & 2) << 4);
17944 }
17945 else
17946 {
17947 rs = neon_select_shape (NS_QQQ, NS_NULL);
17948 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17949 neon_three_args (t_bit);
17950 }
17951
17952}
17953
62f3b8c8
PB
17954static void
17955do_neon_fmac (void)
17956{
d58196e0
AV
17957 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17958 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17959 return;
17960
64c350f2 17961 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17962 return;
17963
d58196e0
AV
17964 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17965 {
17966 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17967 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17968 N_EQK);
17969
17970 if (rs == NS_QQR)
17971 {
aab2c27d 17972
d58196e0
AV
17973 if (inst.operands[2].reg == REG_SP)
17974 as_tsktsk (MVE_BAD_SP);
17975 else if (inst.operands[2].reg == REG_PC)
17976 as_tsktsk (MVE_BAD_PC);
17977
17978 inst.instruction = 0xee310e40;
17979 inst.instruction |= (et.size == 16) << 28;
17980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17981 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17982 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17983 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17984 inst.instruction |= inst.operands[2].reg;
17985 inst.is_neon = 1;
17986 return;
17987 }
17988 }
17989 else
17990 {
17991 constraint (!inst.operands[2].isvec, BAD_FPU);
17992 }
17993
62f3b8c8
PB
17994 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17995}
17996
aab2c27d
MM
17997static void
17998do_mve_vfma (void)
17999{
18000 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
18001 inst.cond == COND_ALWAYS)
18002 {
18003 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18004 inst.instruction = N_MNEM_vfma;
18005 inst.pred_insn_type = INSIDE_VPT_INSN;
18006 inst.cond = 0xf;
18007 return do_neon_fmac();
18008 }
18009 else
18010 {
18011 do_bfloat_vfma();
18012 }
18013}
18014
5287ad62
JB
18015static void
18016do_neon_tst (void)
18017{
037e8744 18018 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
18019 struct neon_type_el et = neon_check_type (3, rs,
18020 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 18021 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18022}
18023
18024/* VMUL with 3 registers allows the P8 type. The scalar version supports the
18025 same types as the MAC equivalents. The polynomial type for this instruction
18026 is encoded the same as the integer type. */
18027
18028static void
18029do_neon_mul (void)
18030{
037e8744
JB
18031 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18032 return;
18033
64c350f2 18034 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
18035 return;
18036
5287ad62 18037 if (inst.operands[2].isscalar)
a8465a06
AV
18038 {
18039 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18040 do_neon_mac_maybe_scalar ();
18041 }
5287ad62 18042 else
a8465a06
AV
18043 {
18044 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18045 {
18046 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18047 struct neon_type_el et
18048 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18049 if (et.type == NT_float)
18050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18051 BAD_FPU);
18052
18053 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18054 }
18055 else
18056 {
18057 constraint (!inst.operands[2].isvec, BAD_FPU);
18058 neon_dyadic_misc (NT_poly,
18059 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18060 }
18061 }
5287ad62
JB
18062}
18063
18064static void
18065do_neon_qdmulh (void)
18066{
64c350f2 18067 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18068 return;
18069
5287ad62
JB
18070 if (inst.operands[2].isscalar)
18071 {
42b16635 18072 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 18073 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 18074 struct neon_type_el et = neon_check_type (3, rs,
477330fc 18075 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 18076 NEON_ENCODE (SCALAR, inst);
037e8744 18077 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
18078 }
18079 else
18080 {
42b16635
AV
18081 enum neon_shape rs;
18082 struct neon_type_el et;
18083 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18084 {
18085 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18086 et = neon_check_type (3, rs,
18087 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18088 }
18089 else
18090 {
18091 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18092 et = neon_check_type (3, rs,
18093 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18094 }
18095
88714cb8 18096 NEON_ENCODE (INTEGER, inst);
42b16635
AV
18097 if (rs == NS_QQR)
18098 mve_encode_qqr (et.size, 0, 0);
18099 else
18100 /* The U bit (rounding) comes from bit mask. */
18101 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18102 }
18103}
18104
26c1e780
AV
18105static void
18106do_mve_vaddv (void)
18107{
18108 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18109 struct neon_type_el et
18110 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18111
18112 if (et.type == NT_invtype)
18113 first_error (BAD_EL_TYPE);
18114
18115 if (inst.cond > COND_ALWAYS)
18116 inst.pred_insn_type = INSIDE_VPT_INSN;
18117 else
18118 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18119
18120 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18121
18122 mve_encode_rq (et.type == NT_unsigned, et.size);
18123}
18124
7df54120
AV
18125static void
18126do_mve_vhcadd (void)
18127{
18128 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18129 struct neon_type_el et
18130 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18131
18132 if (inst.cond > COND_ALWAYS)
18133 inst.pred_insn_type = INSIDE_VPT_INSN;
18134 else
18135 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18136
18137 unsigned rot = inst.relocs[0].exp.X_add_number;
18138 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18139
18140 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18141 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18142 "operand makes instruction UNPREDICTABLE"));
18143
18144 mve_encode_qqq (0, et.size);
18145 inst.instruction |= (rot == 270) << 12;
18146 inst.is_neon = 1;
18147}
18148
35d1cfc2
AV
18149static void
18150do_mve_vqdmull (void)
18151{
18152 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18153 struct neon_type_el et
18154 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18155
18156 if (et.size == 32
18157 && (inst.operands[0].reg == inst.operands[1].reg
18158 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18159 as_tsktsk (BAD_MVE_SRCDEST);
18160
18161 if (inst.cond > COND_ALWAYS)
18162 inst.pred_insn_type = INSIDE_VPT_INSN;
18163 else
18164 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18165
18166 if (rs == NS_QQQ)
18167 {
18168 mve_encode_qqq (et.size == 32, 64);
18169 inst.instruction |= 1;
18170 }
18171 else
18172 {
18173 mve_encode_qqr (64, et.size == 32, 0);
18174 inst.instruction |= 0x3 << 5;
18175 }
18176}
18177
c2dafc2a
AV
18178static void
18179do_mve_vadc (void)
18180{
18181 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18182 struct neon_type_el et
18183 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18184
18185 if (et.type == NT_invtype)
18186 first_error (BAD_EL_TYPE);
18187
18188 if (inst.cond > COND_ALWAYS)
18189 inst.pred_insn_type = INSIDE_VPT_INSN;
18190 else
18191 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18192
18193 mve_encode_qqq (0, 64);
18194}
18195
18196static void
18197do_mve_vbrsr (void)
18198{
18199 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18200 struct neon_type_el et
18201 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18202
18203 if (inst.cond > COND_ALWAYS)
18204 inst.pred_insn_type = INSIDE_VPT_INSN;
18205 else
18206 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18207
7df54120 18208 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
18209}
18210
18211static void
18212do_mve_vsbc (void)
18213{
18214 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18215
18216 if (inst.cond > COND_ALWAYS)
18217 inst.pred_insn_type = INSIDE_VPT_INSN;
18218 else
18219 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18220
18221 mve_encode_qqq (1, 64);
18222}
18223
2d78f95b
AV
18224static void
18225do_mve_vmulh (void)
18226{
18227 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18228 struct neon_type_el et
18229 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18230
18231 if (inst.cond > COND_ALWAYS)
18232 inst.pred_insn_type = INSIDE_VPT_INSN;
18233 else
18234 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18235
18236 mve_encode_qqq (et.type == NT_unsigned, et.size);
18237}
18238
42b16635
AV
18239static void
18240do_mve_vqdmlah (void)
18241{
18242 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18243 struct neon_type_el et
23d188c7 18244 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
18245
18246 if (inst.cond > COND_ALWAYS)
18247 inst.pred_insn_type = INSIDE_VPT_INSN;
18248 else
18249 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18250
18251 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18252}
8b8b22a4
AV
18253
18254static void
18255do_mve_vqdmladh (void)
18256{
18257 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18258 struct neon_type_el et
18259 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18260
18261 if (inst.cond > COND_ALWAYS)
18262 inst.pred_insn_type = INSIDE_VPT_INSN;
18263 else
18264 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18265
8b8b22a4
AV
18266 mve_encode_qqq (0, et.size);
18267}
18268
18269
886e1c73
AV
18270static void
18271do_mve_vmull (void)
18272{
18273
18274 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18275 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
fe05f369 18276 if (inst.cond == COND_ALWAYS
886e1c73
AV
18277 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18278 {
fe05f369 18279
886e1c73
AV
18280 if (rs == NS_QQQ)
18281 {
fe05f369 18282 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
886e1c73
AV
18283 goto neon_vmul;
18284 }
18285 else
18286 goto neon_vmul;
18287 }
18288
18289 constraint (rs != NS_QQQ, BAD_FPU);
18290 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18291 N_SU_32 | N_P8 | N_P16 | N_KEY);
18292
18293 /* We are dealing with MVE's vmullt. */
18294 if (et.size == 32
18295 && (inst.operands[0].reg == inst.operands[1].reg
18296 || inst.operands[0].reg == inst.operands[2].reg))
18297 as_tsktsk (BAD_MVE_SRCDEST);
18298
18299 if (inst.cond > COND_ALWAYS)
18300 inst.pred_insn_type = INSIDE_VPT_INSN;
18301 else
18302 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18303
18304 if (et.type == NT_poly)
18305 mve_encode_qqq (neon_logbits (et.size), 64);
18306 else
18307 mve_encode_qqq (et.type == NT_unsigned, et.size);
18308
18309 return;
18310
dc1e8a47 18311 neon_vmul:
886e1c73
AV
18312 inst.instruction = N_MNEM_vmul;
18313 inst.cond = 0xb;
18314 if (thumb_mode)
18315 inst.pred_insn_type = INSIDE_IT_INSN;
18316 do_neon_mul ();
18317}
18318
a302e574
AV
18319static void
18320do_mve_vabav (void)
18321{
18322 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18323
18324 if (rs == NS_NULL)
18325 return;
18326
18327 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18328 return;
18329
18330 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18331 | N_S16 | N_S32 | N_U8 | N_U16
18332 | N_U32);
18333
18334 if (inst.cond > COND_ALWAYS)
18335 inst.pred_insn_type = INSIDE_VPT_INSN;
18336 else
18337 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18338
18339 mve_encode_rqq (et.type == NT_unsigned, et.size);
18340}
18341
18342static void
18343do_mve_vmladav (void)
18344{
18345 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18346 struct neon_type_el et = neon_check_type (3, rs,
18347 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18348
18349 if (et.type == NT_unsigned
18350 && (inst.instruction == M_MNEM_vmladavx
18351 || inst.instruction == M_MNEM_vmladavax
18352 || inst.instruction == M_MNEM_vmlsdav
18353 || inst.instruction == M_MNEM_vmlsdava
18354 || inst.instruction == M_MNEM_vmlsdavx
18355 || inst.instruction == M_MNEM_vmlsdavax))
18356 first_error (BAD_SIMD_TYPE);
18357
18358 constraint (inst.operands[2].reg > 14,
18359 _("MVE vector register in the range [Q0..Q7] expected"));
18360
18361 if (inst.cond > COND_ALWAYS)
18362 inst.pred_insn_type = INSIDE_VPT_INSN;
18363 else
18364 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18365
18366 if (inst.instruction == M_MNEM_vmlsdav
18367 || inst.instruction == M_MNEM_vmlsdava
18368 || inst.instruction == M_MNEM_vmlsdavx
18369 || inst.instruction == M_MNEM_vmlsdavax)
18370 inst.instruction |= (et.size == 8) << 28;
18371 else
18372 inst.instruction |= (et.size == 8) << 8;
18373
18374 mve_encode_rqq (et.type == NT_unsigned, 64);
18375 inst.instruction |= (et.size == 32) << 16;
18376}
18377
93925576
AV
18378static void
18379do_mve_vmlaldav (void)
18380{
18381 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18382 struct neon_type_el et
18383 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18384 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18385
18386 if (et.type == NT_unsigned
18387 && (inst.instruction == M_MNEM_vmlsldav
18388 || inst.instruction == M_MNEM_vmlsldava
18389 || inst.instruction == M_MNEM_vmlsldavx
18390 || inst.instruction == M_MNEM_vmlsldavax))
18391 first_error (BAD_SIMD_TYPE);
18392
18393 if (inst.cond > COND_ALWAYS)
18394 inst.pred_insn_type = INSIDE_VPT_INSN;
18395 else
18396 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18397
18398 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18399}
18400
18401static void
18402do_mve_vrmlaldavh (void)
18403{
18404 struct neon_type_el et;
18405 if (inst.instruction == M_MNEM_vrmlsldavh
18406 || inst.instruction == M_MNEM_vrmlsldavha
18407 || inst.instruction == M_MNEM_vrmlsldavhx
18408 || inst.instruction == M_MNEM_vrmlsldavhax)
18409 {
18410 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18411 if (inst.operands[1].reg == REG_SP)
18412 as_tsktsk (MVE_BAD_SP);
18413 }
18414 else
18415 {
18416 if (inst.instruction == M_MNEM_vrmlaldavhx
18417 || inst.instruction == M_MNEM_vrmlaldavhax)
18418 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18419 else
18420 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18421 N_U32 | N_S32 | N_KEY);
18422 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18423 with vmax/min instructions, making the use of SP in assembly really
18424 nonsensical, so instead of issuing a warning like we do for other uses
18425 of SP for the odd register operand we error out. */
18426 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18427 }
18428
18429 /* Make sure we still check the second operand is an odd one and that PC is
18430 disallowed. This because we are parsing for any GPR operand, to be able
18431 to distinguish between giving a warning or an error for SP as described
18432 above. */
18433 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18434 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18435
18436 if (inst.cond > COND_ALWAYS)
18437 inst.pred_insn_type = INSIDE_VPT_INSN;
18438 else
18439 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18440
18441 mve_encode_rrqq (et.type == NT_unsigned, 0);
18442}
18443
18444
8cd78170
AV
18445static void
18446do_mve_vmaxnmv (void)
18447{
18448 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18449 struct neon_type_el et
18450 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18451
18452 if (inst.cond > COND_ALWAYS)
18453 inst.pred_insn_type = INSIDE_VPT_INSN;
18454 else
18455 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18456
18457 if (inst.operands[0].reg == REG_SP)
18458 as_tsktsk (MVE_BAD_SP);
18459 else if (inst.operands[0].reg == REG_PC)
18460 as_tsktsk (MVE_BAD_PC);
18461
18462 mve_encode_rq (et.size == 16, 64);
18463}
18464
13ccd4c0
AV
18465static void
18466do_mve_vmaxv (void)
18467{
18468 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18469 struct neon_type_el et;
18470
18471 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18472 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18473 else
18474 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18475
18476 if (inst.cond > COND_ALWAYS)
18477 inst.pred_insn_type = INSIDE_VPT_INSN;
18478 else
18479 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18480
18481 if (inst.operands[0].reg == REG_SP)
18482 as_tsktsk (MVE_BAD_SP);
18483 else if (inst.operands[0].reg == REG_PC)
18484 as_tsktsk (MVE_BAD_PC);
18485
18486 mve_encode_rq (et.type == NT_unsigned, et.size);
18487}
18488
18489
643afb90
MW
18490static void
18491do_neon_qrdmlah (void)
18492{
64c350f2 18493 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18494 return;
18495 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18496 {
42b16635
AV
18497 /* Check we're on the correct architecture. */
18498 if (!mark_feature_used (&fpu_neon_ext_armv8))
18499 inst.error
18500 = _("instruction form not available on this architecture.");
18501 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18502 {
18503 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18504 record_feature_use (&fpu_neon_ext_v8_1);
18505 }
18506 if (inst.operands[2].isscalar)
18507 {
18508 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18509 struct neon_type_el et = neon_check_type (3, rs,
18510 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18511 NEON_ENCODE (SCALAR, inst);
18512 neon_mul_mac (et, neon_quad (rs));
18513 }
18514 else
18515 {
18516 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18517 struct neon_type_el et = neon_check_type (3, rs,
18518 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18519 NEON_ENCODE (INTEGER, inst);
18520 /* The U bit (rounding) comes from bit mask. */
18521 neon_three_same (neon_quad (rs), 0, et.size);
18522 }
643afb90
MW
18523 }
18524 else
18525 {
42b16635
AV
18526 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18527 struct neon_type_el et
23d188c7 18528 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18529
643afb90 18530 NEON_ENCODE (INTEGER, inst);
42b16635 18531 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18532 }
18533}
18534
5287ad62
JB
18535static void
18536do_neon_fcmp_absolute (void)
18537{
037e8744 18538 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18539 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18540 N_F_16_32 | N_KEY);
5287ad62 18541 /* Size field comes from bit mask. */
cc933301 18542 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18543}
18544
18545static void
18546do_neon_fcmp_absolute_inv (void)
18547{
18548 neon_exchange_operands ();
18549 do_neon_fcmp_absolute ();
18550}
18551
18552static void
18553do_neon_step (void)
18554{
037e8744 18555 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18556 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18557 N_F_16_32 | N_KEY);
18558 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18559}
18560
18561static void
18562do_neon_abs_neg (void)
18563{
037e8744
JB
18564 enum neon_shape rs;
18565 struct neon_type_el et;
5f4273c7 18566
037e8744
JB
18567 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18568 return;
18569
037e8744 18570 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18571 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18572
64c350f2
AV
18573 if (!check_simd_pred_availability (et.type == NT_float,
18574 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18575 return;
18576
5287ad62
JB
18577 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18578 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18579 inst.instruction |= LOW4 (inst.operands[1].reg);
18580 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18581 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18582 inst.instruction |= (et.type == NT_float) << 10;
18583 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18584
88714cb8 18585 neon_dp_fixup (&inst);
5287ad62
JB
18586}
18587
18588static void
18589do_neon_sli (void)
18590{
64c350f2 18591 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18592 return;
18593
18594 enum neon_shape rs;
18595 struct neon_type_el et;
18596 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18597 {
18598 rs = neon_select_shape (NS_QQI, NS_NULL);
18599 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18600 }
18601 else
18602 {
18603 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18604 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18605 }
18606
18607
5287ad62
JB
18608 int imm = inst.operands[2].imm;
18609 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18610 _("immediate out of range for insert"));
037e8744 18611 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18612}
18613
18614static void
18615do_neon_sri (void)
18616{
64c350f2 18617 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18618 return;
18619
18620 enum neon_shape rs;
18621 struct neon_type_el et;
18622 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18623 {
18624 rs = neon_select_shape (NS_QQI, NS_NULL);
18625 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18626 }
18627 else
18628 {
18629 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18630 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18631 }
18632
5287ad62
JB
18633 int imm = inst.operands[2].imm;
18634 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18635 _("immediate out of range for insert"));
037e8744 18636 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18637}
18638
18639static void
18640do_neon_qshlu_imm (void)
18641{
64c350f2 18642 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18643 return;
18644
18645 enum neon_shape rs;
18646 struct neon_type_el et;
18647 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18648 {
18649 rs = neon_select_shape (NS_QQI, NS_NULL);
18650 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18651 }
18652 else
18653 {
18654 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18655 et = neon_check_type (2, rs, N_EQK | N_UNS,
18656 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18657 }
18658
5287ad62
JB
18659 int imm = inst.operands[2].imm;
18660 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18661 _("immediate out of range for shift"));
5287ad62
JB
18662 /* Only encodes the 'U present' variant of the instruction.
18663 In this case, signed types have OP (bit 8) set to 0.
18664 Unsigned types have OP set to 1. */
18665 inst.instruction |= (et.type == NT_unsigned) << 8;
18666 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18667 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18668}
18669
18670static void
18671do_neon_qmovn (void)
18672{
18673 struct neon_type_el et = neon_check_type (2, NS_DQ,
18674 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18675 /* Saturating move where operands can be signed or unsigned, and the
18676 destination has the same signedness. */
88714cb8 18677 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18678 if (et.type == NT_unsigned)
18679 inst.instruction |= 0xc0;
18680 else
18681 inst.instruction |= 0x80;
18682 neon_two_same (0, 1, et.size / 2);
18683}
18684
18685static void
18686do_neon_qmovun (void)
18687{
18688 struct neon_type_el et = neon_check_type (2, NS_DQ,
18689 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18690 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18691 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18692 neon_two_same (0, 1, et.size / 2);
18693}
18694
18695static void
18696do_neon_rshift_sat_narrow (void)
18697{
18698 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18699 or unsigned. If operands are unsigned, results must also be unsigned. */
18700 struct neon_type_el et = neon_check_type (2, NS_DQI,
18701 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18702 int imm = inst.operands[2].imm;
18703 /* This gets the bounds check, size encoding and immediate bits calculation
18704 right. */
18705 et.size /= 2;
5f4273c7 18706
5287ad62
JB
18707 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18708 VQMOVN.I<size> <Dd>, <Qm>. */
18709 if (imm == 0)
18710 {
18711 inst.operands[2].present = 0;
18712 inst.instruction = N_MNEM_vqmovn;
18713 do_neon_qmovn ();
18714 return;
18715 }
5f4273c7 18716
5287ad62 18717 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18718 _("immediate out of range"));
5287ad62
JB
18719 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18720}
18721
18722static void
18723do_neon_rshift_sat_narrow_u (void)
18724{
18725 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18726 or unsigned. If operands are unsigned, results must also be unsigned. */
18727 struct neon_type_el et = neon_check_type (2, NS_DQI,
18728 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18729 int imm = inst.operands[2].imm;
18730 /* This gets the bounds check, size encoding and immediate bits calculation
18731 right. */
18732 et.size /= 2;
18733
18734 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18735 VQMOVUN.I<size> <Dd>, <Qm>. */
18736 if (imm == 0)
18737 {
18738 inst.operands[2].present = 0;
18739 inst.instruction = N_MNEM_vqmovun;
18740 do_neon_qmovun ();
18741 return;
18742 }
18743
18744 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18745 _("immediate out of range"));
5287ad62
JB
18746 /* FIXME: The manual is kind of unclear about what value U should have in
18747 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18748 must be 1. */
18749 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18750}
18751
18752static void
18753do_neon_movn (void)
18754{
18755 struct neon_type_el et = neon_check_type (2, NS_DQ,
18756 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18757 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18758 neon_two_same (0, 1, et.size / 2);
18759}
18760
18761static void
18762do_neon_rshift_narrow (void)
18763{
18764 struct neon_type_el et = neon_check_type (2, NS_DQI,
18765 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18766 int imm = inst.operands[2].imm;
18767 /* This gets the bounds check, size encoding and immediate bits calculation
18768 right. */
18769 et.size /= 2;
5f4273c7 18770
5287ad62
JB
18771 /* If immediate is zero then we are a pseudo-instruction for
18772 VMOVN.I<size> <Dd>, <Qm> */
18773 if (imm == 0)
18774 {
18775 inst.operands[2].present = 0;
18776 inst.instruction = N_MNEM_vmovn;
18777 do_neon_movn ();
18778 return;
18779 }
5f4273c7 18780
5287ad62 18781 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18782 _("immediate out of range for narrowing operation"));
5287ad62
JB
18783 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18784}
18785
18786static void
18787do_neon_shll (void)
18788{
18789 /* FIXME: Type checking when lengthening. */
18790 struct neon_type_el et = neon_check_type (2, NS_QDI,
18791 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18792 unsigned imm = inst.operands[2].imm;
18793
18794 if (imm == et.size)
18795 {
18796 /* Maximum shift variant. */
88714cb8 18797 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18798 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18799 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18800 inst.instruction |= LOW4 (inst.operands[1].reg);
18801 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18802 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18803
88714cb8 18804 neon_dp_fixup (&inst);
5287ad62
JB
18805 }
18806 else
18807 {
18808 /* A more-specific type check for non-max versions. */
18809 et = neon_check_type (2, NS_QDI,
477330fc 18810 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18811 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18812 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18813 }
18814}
18815
037e8744 18816/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18817 the current instruction is. */
18818
6b9a8b67
MGD
18819#define CVT_FLAVOUR_VAR \
18820 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18821 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18822 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18823 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18824 /* Half-precision conversions. */ \
cc933301
JW
18825 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18826 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18827 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18828 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18829 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18830 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18831 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18832 Compared with single/double precision variants, only the co-processor \
18833 field is different, so the encoding flow is reused here. */ \
18834 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18835 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18836 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18837 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
aab2c27d 18838 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18839 /* VFP instructions. */ \
18840 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18841 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18842 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18843 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18844 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18845 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18846 /* VFP instructions with bitshift. */ \
18847 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18848 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18849 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18850 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18851 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18852 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18853 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18854 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18855
18856#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18857 neon_cvt_flavour_##C,
18858
18859/* The different types of conversions we can do. */
18860enum neon_cvt_flavour
18861{
18862 CVT_FLAVOUR_VAR
18863 neon_cvt_flavour_invalid,
18864 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18865};
18866
18867#undef CVT_VAR
18868
18869static enum neon_cvt_flavour
18870get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18871{
6b9a8b67
MGD
18872#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18873 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18874 if (et.type != NT_invtype) \
18875 { \
18876 inst.error = NULL; \
18877 return (neon_cvt_flavour_##C); \
5287ad62 18878 }
6b9a8b67 18879
5287ad62 18880 struct neon_type_el et;
037e8744 18881 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18882 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18883 /* The instruction versions which take an immediate take one register
18884 argument, which is extended to the width of the full register. Thus the
18885 "source" and "destination" registers must have the same width. Hack that
18886 here by making the size equal to the key (wider, in this case) operand. */
18887 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18888
6b9a8b67
MGD
18889 CVT_FLAVOUR_VAR;
18890
18891 return neon_cvt_flavour_invalid;
5287ad62
JB
18892#undef CVT_VAR
18893}
18894
7e8e6784
MGD
18895enum neon_cvt_mode
18896{
18897 neon_cvt_mode_a,
18898 neon_cvt_mode_n,
18899 neon_cvt_mode_p,
18900 neon_cvt_mode_m,
18901 neon_cvt_mode_z,
30bdf752
MGD
18902 neon_cvt_mode_x,
18903 neon_cvt_mode_r
7e8e6784
MGD
18904};
18905
037e8744
JB
18906/* Neon-syntax VFP conversions. */
18907
5287ad62 18908static void
6b9a8b67 18909do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18910{
037e8744 18911 const char *opname = 0;
5f4273c7 18912
d54af2d0
RL
18913 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18914 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18915 {
037e8744
JB
18916 /* Conversions with immediate bitshift. */
18917 const char *enc[] =
477330fc 18918 {
6b9a8b67
MGD
18919#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18920 CVT_FLAVOUR_VAR
18921 NULL
18922#undef CVT_VAR
477330fc 18923 };
037e8744 18924
6b9a8b67 18925 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18926 {
18927 opname = enc[flavour];
18928 constraint (inst.operands[0].reg != inst.operands[1].reg,
18929 _("operands 0 and 1 must be the same register"));
18930 inst.operands[1] = inst.operands[2];
18931 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18932 }
5287ad62
JB
18933 }
18934 else
18935 {
037e8744
JB
18936 /* Conversions without bitshift. */
18937 const char *enc[] =
477330fc 18938 {
6b9a8b67
MGD
18939#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18940 CVT_FLAVOUR_VAR
18941 NULL
18942#undef CVT_VAR
477330fc 18943 };
037e8744 18944
6b9a8b67 18945 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18946 opname = enc[flavour];
037e8744
JB
18947 }
18948
18949 if (opname)
18950 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18951
18952 /* ARMv8.2 fp16 VCVT instruction. */
18953 if (flavour == neon_cvt_flavour_s32_f16
18954 || flavour == neon_cvt_flavour_u32_f16
18955 || flavour == neon_cvt_flavour_f16_u32
18956 || flavour == neon_cvt_flavour_f16_s32)
18957 do_scalar_fp16_v82_encode ();
037e8744
JB
18958}
18959
18960static void
18961do_vfp_nsyn_cvtz (void)
18962{
d54af2d0 18963 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18964 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18965 const char *enc[] =
18966 {
6b9a8b67
MGD
18967#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18968 CVT_FLAVOUR_VAR
18969 NULL
18970#undef CVT_VAR
037e8744
JB
18971 };
18972
6b9a8b67 18973 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18974 do_vfp_nsyn_opcode (enc[flavour]);
18975}
f31fef98 18976
037e8744 18977static void
bacebabc 18978do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18979 enum neon_cvt_mode mode)
18980{
18981 int sz, op;
18982 int rm;
18983
a715796b
TG
18984 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18985 D register operands. */
18986 if (flavour == neon_cvt_flavour_s32_f64
18987 || flavour == neon_cvt_flavour_u32_f64)
18988 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18989 _(BAD_FPU));
18990
9db2f6b4
RL
18991 if (flavour == neon_cvt_flavour_s32_f16
18992 || flavour == neon_cvt_flavour_u32_f16)
18993 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18994 _(BAD_FP16));
18995
5ee91343 18996 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18997
18998 switch (flavour)
18999 {
19000 case neon_cvt_flavour_s32_f64:
19001 sz = 1;
827f64ff 19002 op = 1;
7e8e6784
MGD
19003 break;
19004 case neon_cvt_flavour_s32_f32:
19005 sz = 0;
19006 op = 1;
19007 break;
9db2f6b4
RL
19008 case neon_cvt_flavour_s32_f16:
19009 sz = 0;
19010 op = 1;
19011 break;
7e8e6784
MGD
19012 case neon_cvt_flavour_u32_f64:
19013 sz = 1;
19014 op = 0;
19015 break;
19016 case neon_cvt_flavour_u32_f32:
19017 sz = 0;
19018 op = 0;
19019 break;
9db2f6b4
RL
19020 case neon_cvt_flavour_u32_f16:
19021 sz = 0;
19022 op = 0;
19023 break;
7e8e6784
MGD
19024 default:
19025 first_error (_("invalid instruction shape"));
19026 return;
19027 }
19028
19029 switch (mode)
19030 {
19031 case neon_cvt_mode_a: rm = 0; break;
19032 case neon_cvt_mode_n: rm = 1; break;
19033 case neon_cvt_mode_p: rm = 2; break;
19034 case neon_cvt_mode_m: rm = 3; break;
19035 default: first_error (_("invalid rounding mode")); return;
19036 }
19037
19038 NEON_ENCODE (FPV8, inst);
19039 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19040 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19041 inst.instruction |= sz << 8;
9db2f6b4
RL
19042
19043 /* ARMv8.2 fp16 VCVT instruction. */
19044 if (flavour == neon_cvt_flavour_s32_f16
19045 ||flavour == neon_cvt_flavour_u32_f16)
19046 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
19047 inst.instruction |= op << 7;
19048 inst.instruction |= rm << 16;
19049 inst.instruction |= 0xf0000000;
19050 inst.is_neon = TRUE;
19051}
19052
19053static void
19054do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
19055{
19056 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
19057 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19058 NS_FH, NS_HF, NS_FHI, NS_HFI,
19059 NS_NULL);
6b9a8b67 19060 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 19061
cc933301
JW
19062 if (flavour == neon_cvt_flavour_invalid)
19063 return;
19064
e3e535bc 19065 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 19066 if (mode == neon_cvt_mode_z
e3e535bc 19067 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
19068 && (flavour == neon_cvt_flavour_s16_f16
19069 || flavour == neon_cvt_flavour_u16_f16
19070 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
19071 || flavour == neon_cvt_flavour_u32_f32
19072 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 19073 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
19074 && (rs == NS_FD || rs == NS_FF))
19075 {
19076 do_vfp_nsyn_cvtz ();
19077 return;
19078 }
19079
9db2f6b4
RL
19080 /* ARMv8.2 fp16 VCVT conversions. */
19081 if (mode == neon_cvt_mode_z
19082 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19083 && (flavour == neon_cvt_flavour_s32_f16
19084 || flavour == neon_cvt_flavour_u32_f16)
19085 && (rs == NS_FH))
19086 {
19087 do_vfp_nsyn_cvtz ();
19088 do_scalar_fp16_v82_encode ();
19089 return;
19090 }
19091
037e8744 19092 /* VFP rather than Neon conversions. */
6b9a8b67 19093 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 19094 {
7e8e6784
MGD
19095 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19096 do_vfp_nsyn_cvt (rs, flavour);
19097 else
19098 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19099
037e8744
JB
19100 return;
19101 }
19102
19103 switch (rs)
19104 {
037e8744 19105 case NS_QQI:
dd9634d9
AV
19106 if (mode == neon_cvt_mode_z
19107 && (flavour == neon_cvt_flavour_f16_s16
19108 || flavour == neon_cvt_flavour_f16_u16
19109 || flavour == neon_cvt_flavour_s16_f16
19110 || flavour == neon_cvt_flavour_u16_f16
19111 || flavour == neon_cvt_flavour_f32_u32
19112 || flavour == neon_cvt_flavour_f32_s32
19113 || flavour == neon_cvt_flavour_s32_f32
19114 || flavour == neon_cvt_flavour_u32_f32))
19115 {
64c350f2
AV
19116 if (!check_simd_pred_availability (TRUE,
19117 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19118 return;
19119 }
19120 else if (mode == neon_cvt_mode_n)
19121 {
19122 /* We are dealing with vcvt with the 'ne' condition. */
19123 inst.cond = 0x1;
19124 inst.instruction = N_MNEM_vcvt;
19125 do_neon_cvt_1 (neon_cvt_mode_z);
19126 return;
19127 }
19128 /* fall through. */
19129 case NS_DDI:
037e8744 19130 {
477330fc 19131 unsigned immbits;
cc933301
JW
19132 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19133 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 19134
dd9634d9
AV
19135 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19136 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19137 return;
19138
19139 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19140 {
19141 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19142 _("immediate value out of range"));
19143 switch (flavour)
19144 {
19145 case neon_cvt_flavour_f16_s16:
19146 case neon_cvt_flavour_f16_u16:
19147 case neon_cvt_flavour_s16_f16:
19148 case neon_cvt_flavour_u16_f16:
19149 constraint (inst.operands[2].imm > 16,
19150 _("immediate value out of range"));
19151 break;
19152 case neon_cvt_flavour_f32_u32:
19153 case neon_cvt_flavour_f32_s32:
19154 case neon_cvt_flavour_s32_f32:
19155 case neon_cvt_flavour_u32_f32:
19156 constraint (inst.operands[2].imm > 32,
19157 _("immediate value out of range"));
19158 break;
19159 default:
19160 inst.error = BAD_FPU;
19161 return;
19162 }
19163 }
037e8744 19164
477330fc
RM
19165 /* Fixed-point conversion with #0 immediate is encoded as an
19166 integer conversion. */
19167 if (inst.operands[2].present && inst.operands[2].imm == 0)
19168 goto int_encode;
477330fc
RM
19169 NEON_ENCODE (IMMED, inst);
19170 if (flavour != neon_cvt_flavour_invalid)
19171 inst.instruction |= enctab[flavour];
19172 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19173 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19174 inst.instruction |= LOW4 (inst.operands[1].reg);
19175 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19176 inst.instruction |= neon_quad (rs) << 6;
19177 inst.instruction |= 1 << 21;
cc933301
JW
19178 if (flavour < neon_cvt_flavour_s16_f16)
19179 {
19180 inst.instruction |= 1 << 21;
19181 immbits = 32 - inst.operands[2].imm;
19182 inst.instruction |= immbits << 16;
19183 }
19184 else
19185 {
19186 inst.instruction |= 3 << 20;
19187 immbits = 16 - inst.operands[2].imm;
19188 inst.instruction |= immbits << 16;
19189 inst.instruction &= ~(1 << 9);
19190 }
477330fc
RM
19191
19192 neon_dp_fixup (&inst);
037e8744
JB
19193 }
19194 break;
19195
037e8744 19196 case NS_QQ:
dd9634d9
AV
19197 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19198 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19199 && (flavour == neon_cvt_flavour_s16_f16
19200 || flavour == neon_cvt_flavour_u16_f16
19201 || flavour == neon_cvt_flavour_s32_f32
19202 || flavour == neon_cvt_flavour_u32_f32))
19203 {
64c350f2
AV
19204 if (!check_simd_pred_availability (TRUE,
19205 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
19206 return;
19207 }
19208 else if (mode == neon_cvt_mode_z
19209 && (flavour == neon_cvt_flavour_f16_s16
19210 || flavour == neon_cvt_flavour_f16_u16
19211 || flavour == neon_cvt_flavour_s16_f16
19212 || flavour == neon_cvt_flavour_u16_f16
19213 || flavour == neon_cvt_flavour_f32_u32
19214 || flavour == neon_cvt_flavour_f32_s32
19215 || flavour == neon_cvt_flavour_s32_f32
19216 || flavour == neon_cvt_flavour_u32_f32))
19217 {
64c350f2
AV
19218 if (!check_simd_pred_availability (TRUE,
19219 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19220 return;
19221 }
19222 /* fall through. */
19223 case NS_DD:
7e8e6784
MGD
19224 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19225 {
7e8e6784 19226
dd9634d9 19227 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
19228 if (!check_simd_pred_availability (TRUE,
19229 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
19230 return;
19231
19232 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19233 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19234 inst.instruction |= LOW4 (inst.operands[1].reg);
19235 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19236 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19237 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19238 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 19239 inst.instruction |= mode << 8;
cc933301
JW
19240 if (flavour == neon_cvt_flavour_u16_f16
19241 || flavour == neon_cvt_flavour_s16_f16)
19242 /* Mask off the original size bits and reencode them. */
19243 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19244
7e8e6784
MGD
19245 if (thumb_mode)
19246 inst.instruction |= 0xfc000000;
19247 else
19248 inst.instruction |= 0xf0000000;
19249 }
19250 else
19251 {
037e8744 19252 int_encode:
7e8e6784 19253 {
cc933301
JW
19254 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19255 0x100, 0x180, 0x0, 0x080};
037e8744 19256
7e8e6784 19257 NEON_ENCODE (INTEGER, inst);
037e8744 19258
dd9634d9
AV
19259 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19260 {
19261 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19262 return;
19263 }
037e8744 19264
7e8e6784
MGD
19265 if (flavour != neon_cvt_flavour_invalid)
19266 inst.instruction |= enctab[flavour];
037e8744 19267
7e8e6784
MGD
19268 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19269 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19270 inst.instruction |= LOW4 (inst.operands[1].reg);
19271 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19272 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19273 if (flavour >= neon_cvt_flavour_s16_f16
19274 && flavour <= neon_cvt_flavour_f16_u16)
19275 /* Half precision. */
19276 inst.instruction |= 1 << 18;
19277 else
19278 inst.instruction |= 2 << 18;
037e8744 19279
7e8e6784
MGD
19280 neon_dp_fixup (&inst);
19281 }
19282 }
19283 break;
037e8744 19284
8e79c3df
CM
19285 /* Half-precision conversions for Advanced SIMD -- neon. */
19286 case NS_QD:
19287 case NS_DQ:
bc52d49c
MM
19288 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19289 return;
8e79c3df
CM
19290
19291 if ((rs == NS_DQ)
19292 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19293 {
19294 as_bad (_("operand size must match register width"));
19295 break;
19296 }
19297
19298 if ((rs == NS_QD)
19299 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19300 {
19301 as_bad (_("operand size must match register width"));
19302 break;
19303 }
19304
19305 if (rs == NS_DQ)
aab2c27d
MM
19306 {
19307 if (flavour == neon_cvt_flavour_bf16_f32)
19308 {
19309 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19310 return;
19311 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19312 /* VCVT.bf16.f32. */
19313 inst.instruction = 0x11b60640;
19314 }
19315 else
19316 /* VCVT.f16.f32. */
19317 inst.instruction = 0x3b60600;
19318 }
8e79c3df 19319 else
aab2c27d 19320 /* VCVT.f32.f16. */
8e79c3df
CM
19321 inst.instruction = 0x3b60700;
19322
19323 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19324 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19325 inst.instruction |= LOW4 (inst.operands[1].reg);
19326 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19327 neon_dp_fixup (&inst);
8e79c3df
CM
19328 break;
19329
037e8744
JB
19330 default:
19331 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19332 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19333 do_vfp_nsyn_cvt (rs, flavour);
19334 else
19335 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19336 }
5287ad62
JB
19337}
19338
e3e535bc
NC
19339static void
19340do_neon_cvtr (void)
19341{
7e8e6784 19342 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19343}
19344
19345static void
19346do_neon_cvt (void)
19347{
7e8e6784
MGD
19348 do_neon_cvt_1 (neon_cvt_mode_z);
19349}
19350
19351static void
19352do_neon_cvta (void)
19353{
19354 do_neon_cvt_1 (neon_cvt_mode_a);
19355}
19356
19357static void
19358do_neon_cvtn (void)
19359{
19360 do_neon_cvt_1 (neon_cvt_mode_n);
19361}
19362
19363static void
19364do_neon_cvtp (void)
19365{
19366 do_neon_cvt_1 (neon_cvt_mode_p);
19367}
19368
19369static void
19370do_neon_cvtm (void)
19371{
19372 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19373}
19374
8e79c3df 19375static void
c70a8987 19376do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19377{
c70a8987
MGD
19378 if (is_double)
19379 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19380
c70a8987
MGD
19381 encode_arm_vfp_reg (inst.operands[0].reg,
19382 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19383 encode_arm_vfp_reg (inst.operands[1].reg,
19384 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19385 inst.instruction |= to ? 0x10000 : 0;
19386 inst.instruction |= t ? 0x80 : 0;
19387 inst.instruction |= is_double ? 0x100 : 0;
19388 do_vfp_cond_or_thumb ();
19389}
8e79c3df 19390
c70a8987
MGD
19391static void
19392do_neon_cvttb_1 (bfd_boolean t)
19393{
d54af2d0 19394 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19395 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19396
c70a8987
MGD
19397 if (rs == NS_NULL)
19398 return;
dd9634d9
AV
19399 else if (rs == NS_QQ || rs == NS_QQI)
19400 {
19401 int single_to_half = 0;
64c350f2 19402 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19403 return;
19404
19405 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19406
19407 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19408 && (flavour == neon_cvt_flavour_u16_f16
19409 || flavour == neon_cvt_flavour_s16_f16
19410 || flavour == neon_cvt_flavour_f16_s16
19411 || flavour == neon_cvt_flavour_f16_u16
19412 || flavour == neon_cvt_flavour_u32_f32
19413 || flavour == neon_cvt_flavour_s32_f32
19414 || flavour == neon_cvt_flavour_f32_s32
19415 || flavour == neon_cvt_flavour_f32_u32))
19416 {
19417 inst.cond = 0xf;
19418 inst.instruction = N_MNEM_vcvt;
19419 set_pred_insn_type (INSIDE_VPT_INSN);
19420 do_neon_cvt_1 (neon_cvt_mode_z);
19421 return;
19422 }
19423 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19424 single_to_half = 1;
19425 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19426 {
19427 first_error (BAD_FPU);
19428 return;
19429 }
19430
19431 inst.instruction = 0xee3f0e01;
19432 inst.instruction |= single_to_half << 28;
19433 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19434 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19435 inst.instruction |= t << 12;
19436 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19437 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19438 inst.is_neon = 1;
19439 }
c70a8987
MGD
19440 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19441 {
19442 inst.error = NULL;
19443 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19444 }
19445 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19446 {
19447 inst.error = NULL;
19448 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19449 }
19450 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19451 {
a715796b
TG
19452 /* The VCVTB and VCVTT instructions with D-register operands
19453 don't work for SP only targets. */
19454 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19455 _(BAD_FPU));
19456
c70a8987
MGD
19457 inst.error = NULL;
19458 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19459 }
19460 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19461 {
a715796b
TG
19462 /* The VCVTB and VCVTT instructions with D-register operands
19463 don't work for SP only targets. */
19464 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19465 _(BAD_FPU));
19466
c70a8987
MGD
19467 inst.error = NULL;
19468 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19469 }
aab2c27d
MM
19470 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19471 {
19472 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19473 inst.error = NULL;
19474 inst.instruction |= (1 << 8);
19475 inst.instruction &= ~(1 << 9);
19476 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19477 }
c70a8987
MGD
19478 else
19479 return;
19480}
19481
19482static void
19483do_neon_cvtb (void)
19484{
19485 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19486}
19487
19488
19489static void
19490do_neon_cvtt (void)
19491{
c70a8987 19492 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19493}
19494
5287ad62
JB
19495static void
19496neon_move_immediate (void)
19497{
037e8744
JB
19498 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19499 struct neon_type_el et = neon_check_type (2, rs,
19500 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19501 unsigned immlo, immhi = 0, immbits;
c96612cc 19502 int op, cmode, float_p;
5287ad62 19503
037e8744 19504 constraint (et.type == NT_invtype,
477330fc 19505 _("operand size must be specified for immediate VMOV"));
037e8744 19506
5287ad62
JB
19507 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19508 op = (inst.instruction & (1 << 5)) != 0;
19509
19510 immlo = inst.operands[1].imm;
19511 if (inst.operands[1].regisimm)
19512 immhi = inst.operands[1].reg;
19513
19514 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19515 _("immediate has bits set outside the operand size"));
5287ad62 19516
c96612cc
JB
19517 float_p = inst.operands[1].immisfloat;
19518
19519 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19520 et.size, et.type)) == FAIL)
5287ad62
JB
19521 {
19522 /* Invert relevant bits only. */
19523 neon_invert_size (&immlo, &immhi, et.size);
19524 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19525 with one or the other; those cases are caught by
19526 neon_cmode_for_move_imm. */
5287ad62 19527 op = !op;
c96612cc
JB
19528 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19529 &op, et.size, et.type)) == FAIL)
477330fc
RM
19530 {
19531 first_error (_("immediate out of range"));
19532 return;
19533 }
5287ad62
JB
19534 }
19535
19536 inst.instruction &= ~(1 << 5);
19537 inst.instruction |= op << 5;
19538
19539 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19540 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19541 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19542 inst.instruction |= cmode << 8;
19543
19544 neon_write_immbits (immbits);
19545}
19546
19547static void
19548do_neon_mvn (void)
19549{
64c350f2 19550 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19551 return;
19552
5287ad62
JB
19553 if (inst.operands[1].isreg)
19554 {
1a186d29
AV
19555 enum neon_shape rs;
19556 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19557 rs = neon_select_shape (NS_QQ, NS_NULL);
19558 else
19559 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 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
JB
20639 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20640 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20641}
20642
20643static void
20644do_neon_tbl_tbx (void)
20645{
20646 unsigned listlenbits;
dcbf9037 20647 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20648
5287ad62
JB
20649 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20650 {
dcbf9037 20651 first_error (_("bad list length for table lookup"));
5287ad62
JB
20652 return;
20653 }
5f4273c7 20654
5287ad62
JB
20655 listlenbits = inst.operands[1].imm - 1;
20656 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20657 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20658 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20659 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20660 inst.instruction |= LOW4 (inst.operands[2].reg);
20661 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20662 inst.instruction |= listlenbits << 8;
5f4273c7 20663
88714cb8 20664 neon_dp_fixup (&inst);
5287ad62
JB
20665}
20666
20667static void
20668do_neon_ldm_stm (void)
20669{
ef8f595f
MI
20670 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20671 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20672 _(BAD_FPU));
5287ad62
JB
20673 /* P, U and L bits are part of bitmask. */
20674 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20675 unsigned offsetbits = inst.operands[1].imm * 2;
20676
037e8744
JB
20677 if (inst.operands[1].issingle)
20678 {
20679 do_vfp_nsyn_ldm_stm (is_dbmode);
20680 return;
20681 }
20682
5287ad62 20683 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20684 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20685
20686 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20687 _("register list must contain at least 1 and at most 16 "
20688 "registers"));
5287ad62
JB
20689
20690 inst.instruction |= inst.operands[0].reg << 16;
20691 inst.instruction |= inst.operands[0].writeback << 21;
20692 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20693 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20694
20695 inst.instruction |= offsetbits;
5f4273c7 20696
037e8744 20697 do_vfp_cond_or_thumb ();
5287ad62
JB
20698}
20699
ef8f595f
MI
20700static void
20701do_vfp_nsyn_pop (void)
20702{
20703 nsyn_insert_sp ();
20704 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20705 return do_vfp_nsyn_opcode ("vldm");
20706 }
20707
20708 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20709 _(BAD_FPU));
20710
20711 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20712 _("register list must contain at least 1 and at most 16 "
20713 "registers"));
20714
20715 if (inst.operands[1].issingle)
20716 do_vfp_nsyn_opcode ("fldmias");
20717 else
20718 do_vfp_nsyn_opcode ("fldmiad");
20719}
20720
20721static void
20722do_vfp_nsyn_push (void)
20723{
20724 nsyn_insert_sp ();
20725 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20726 return do_vfp_nsyn_opcode ("vstmdb");
20727 }
20728
20729 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20730 _(BAD_FPU));
20731
20732 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20733 _("register list must contain at least 1 and at most 16 "
20734 "registers"));
20735
20736 if (inst.operands[1].issingle)
20737 do_vfp_nsyn_opcode ("fstmdbs");
20738 else
20739 do_vfp_nsyn_opcode ("fstmdbd");
20740}
20741
20742
5287ad62
JB
20743static void
20744do_neon_ldr_str (void)
20745{
5287ad62 20746 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20747
6844b2c2
MGD
20748 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20749 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20750 if (!is_ldr
6844b2c2 20751 && inst.operands[1].reg == REG_PC
ba86b375 20752 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20753 {
94dcf8bf 20754 if (thumb_mode)
6844b2c2 20755 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20756 else if (warn_on_deprecated)
5c3696f8 20757 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20758 }
20759
037e8744
JB
20760 if (inst.operands[0].issingle)
20761 {
cd2f129f 20762 if (is_ldr)
477330fc 20763 do_vfp_nsyn_opcode ("flds");
cd2f129f 20764 else
477330fc 20765 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20766
20767 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20768 if (inst.vectype.el[0].size == 16)
20769 do_scalar_fp16_v82_encode ();
5287ad62
JB
20770 }
20771 else
5287ad62 20772 {
cd2f129f 20773 if (is_ldr)
477330fc 20774 do_vfp_nsyn_opcode ("fldd");
5287ad62 20775 else
477330fc 20776 do_vfp_nsyn_opcode ("fstd");
5287ad62 20777 }
5287ad62
JB
20778}
20779
32c36c3c
AV
20780static void
20781do_t_vldr_vstr_sysreg (void)
20782{
20783 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20784 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20785
20786 /* Use of PC is UNPREDICTABLE. */
20787 if (inst.operands[1].reg == REG_PC)
20788 inst.error = _("Use of PC here is UNPREDICTABLE");
20789
20790 if (inst.operands[1].immisreg)
20791 inst.error = _("instruction does not accept register index");
20792
20793 if (!inst.operands[1].isreg)
20794 inst.error = _("instruction does not accept PC-relative addressing");
20795
20796 if (abs (inst.operands[1].imm) >= (1 << 7))
20797 inst.error = _("immediate value out of range");
20798
20799 inst.instruction = 0xec000f80;
20800 if (is_vldr)
20801 inst.instruction |= 1 << sysreg_vldr_bitno;
20802 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20803 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20804 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20805}
20806
20807static void
20808do_vldr_vstr (void)
20809{
20810 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20811
20812 /* VLDR/VSTR (System Register). */
20813 if (sysreg_op)
20814 {
20815 if (!mark_feature_used (&arm_ext_v8_1m_main))
20816 as_bad (_("Instruction not permitted on this architecture"));
20817
20818 do_t_vldr_vstr_sysreg ();
20819 }
20820 /* VLDR/VSTR. */
20821 else
20822 {
ef8f595f
MI
20823 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20824 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
32c36c3c
AV
20825 as_bad (_("Instruction not permitted on this architecture"));
20826 do_neon_ldr_str ();
20827 }
20828}
20829
5287ad62
JB
20830/* "interleave" version also handles non-interleaving register VLD1/VST1
20831 instructions. */
20832
20833static void
20834do_neon_ld_st_interleave (void)
20835{
037e8744 20836 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20837 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20838 unsigned alignbits = 0;
20839 unsigned idx;
20840 /* The bits in this table go:
20841 0: register stride of one (0) or two (1)
20842 1,2: register list length, minus one (1, 2, 3, 4).
20843 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20844 We use -1 for invalid entries. */
20845 const int typetable[] =
20846 {
20847 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20848 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20849 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20850 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20851 };
20852 int typebits;
20853
dcbf9037
JB
20854 if (et.type == NT_invtype)
20855 return;
20856
5287ad62
JB
20857 if (inst.operands[1].immisalign)
20858 switch (inst.operands[1].imm >> 8)
20859 {
20860 case 64: alignbits = 1; break;
20861 case 128:
477330fc 20862 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20863 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20864 goto bad_alignment;
20865 alignbits = 2;
20866 break;
5287ad62 20867 case 256:
477330fc
RM
20868 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20869 goto bad_alignment;
20870 alignbits = 3;
20871 break;
5287ad62
JB
20872 default:
20873 bad_alignment:
477330fc
RM
20874 first_error (_("bad alignment"));
20875 return;
5287ad62
JB
20876 }
20877
20878 inst.instruction |= alignbits << 4;
20879 inst.instruction |= neon_logbits (et.size) << 6;
20880
20881 /* Bits [4:6] of the immediate in a list specifier encode register stride
20882 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20883 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20884 up the right value for "type" in a table based on this value and the given
20885 list style, then stick it back. */
20886 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20887 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20888
20889 typebits = typetable[idx];
5f4273c7 20890
5287ad62 20891 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20892 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20893 BAD_EL_TYPE);
5287ad62
JB
20894
20895 inst.instruction &= ~0xf00;
20896 inst.instruction |= typebits << 8;
20897}
20898
20899/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20900 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20901 otherwise. The variable arguments are a list of pairs of legal (size, align)
20902 values, terminated with -1. */
20903
20904static int
aa8a0863 20905neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20906{
20907 va_list ap;
20908 int result = FAIL, thissize, thisalign;
5f4273c7 20909
5287ad62
JB
20910 if (!inst.operands[1].immisalign)
20911 {
aa8a0863 20912 *do_alignment = 0;
5287ad62
JB
20913 return SUCCESS;
20914 }
5f4273c7 20915
aa8a0863 20916 va_start (ap, do_alignment);
5287ad62
JB
20917
20918 do
20919 {
20920 thissize = va_arg (ap, int);
20921 if (thissize == -1)
477330fc 20922 break;
5287ad62
JB
20923 thisalign = va_arg (ap, int);
20924
20925 if (size == thissize && align == thisalign)
477330fc 20926 result = SUCCESS;
5287ad62
JB
20927 }
20928 while (result != SUCCESS);
20929
20930 va_end (ap);
20931
20932 if (result == SUCCESS)
aa8a0863 20933 *do_alignment = 1;
5287ad62 20934 else
dcbf9037 20935 first_error (_("unsupported alignment for instruction"));
5f4273c7 20936
5287ad62
JB
20937 return result;
20938}
20939
20940static void
20941do_neon_ld_st_lane (void)
20942{
037e8744 20943 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20944 int align_good, do_alignment = 0;
5287ad62
JB
20945 int logsize = neon_logbits (et.size);
20946 int align = inst.operands[1].imm >> 8;
20947 int n = (inst.instruction >> 8) & 3;
20948 int max_el = 64 / et.size;
5f4273c7 20949
dcbf9037
JB
20950 if (et.type == NT_invtype)
20951 return;
5f4273c7 20952
5287ad62 20953 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20954 _("bad list length"));
5287ad62 20955 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20956 _("scalar index out of range"));
5287ad62 20957 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20958 && et.size == 8,
20959 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20960
5287ad62
JB
20961 switch (n)
20962 {
20963 case 0: /* VLD1 / VST1. */
aa8a0863 20964 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20965 32, 32, -1);
5287ad62 20966 if (align_good == FAIL)
477330fc 20967 return;
aa8a0863 20968 if (do_alignment)
477330fc
RM
20969 {
20970 unsigned alignbits = 0;
20971 switch (et.size)
20972 {
20973 case 16: alignbits = 0x1; break;
20974 case 32: alignbits = 0x3; break;
20975 default: ;
20976 }
20977 inst.instruction |= alignbits << 4;
20978 }
5287ad62
JB
20979 break;
20980
20981 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20982 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20983 16, 32, 32, 64, -1);
5287ad62 20984 if (align_good == FAIL)
477330fc 20985 return;
aa8a0863 20986 if (do_alignment)
477330fc 20987 inst.instruction |= 1 << 4;
5287ad62
JB
20988 break;
20989
20990 case 2: /* VLD3 / VST3. */
20991 constraint (inst.operands[1].immisalign,
477330fc 20992 _("can't use alignment with this instruction"));
5287ad62
JB
20993 break;
20994
20995 case 3: /* VLD4 / VST4. */
aa8a0863 20996 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20997 16, 64, 32, 64, 32, 128, -1);
5287ad62 20998 if (align_good == FAIL)
477330fc 20999 return;
aa8a0863 21000 if (do_alignment)
477330fc
RM
21001 {
21002 unsigned alignbits = 0;
21003 switch (et.size)
21004 {
21005 case 8: alignbits = 0x1; break;
21006 case 16: alignbits = 0x1; break;
21007 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21008 default: ;
21009 }
21010 inst.instruction |= alignbits << 4;
21011 }
5287ad62
JB
21012 break;
21013
21014 default: ;
21015 }
21016
21017 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21018 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21019 inst.instruction |= 1 << (4 + logsize);
5f4273c7 21020
5287ad62
JB
21021 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21022 inst.instruction |= logsize << 10;
21023}
21024
21025/* Encode single n-element structure to all lanes VLD<n> instructions. */
21026
21027static void
21028do_neon_ld_dup (void)
21029{
037e8744 21030 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 21031 int align_good, do_alignment = 0;
5287ad62 21032
dcbf9037
JB
21033 if (et.type == NT_invtype)
21034 return;
21035
5287ad62
JB
21036 switch ((inst.instruction >> 8) & 3)
21037 {
21038 case 0: /* VLD1. */
9c2799c2 21039 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 21040 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 21041 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 21042 if (align_good == FAIL)
477330fc 21043 return;
5287ad62 21044 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
21045 {
21046 case 1: break;
21047 case 2: inst.instruction |= 1 << 5; break;
21048 default: first_error (_("bad list length")); return;
21049 }
5287ad62
JB
21050 inst.instruction |= neon_logbits (et.size) << 6;
21051 break;
21052
21053 case 1: /* VLD2. */
21054 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
21055 &do_alignment, 8, 16, 16, 32, 32, 64,
21056 -1);
5287ad62 21057 if (align_good == FAIL)
477330fc 21058 return;
5287ad62 21059 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 21060 _("bad list length"));
5287ad62 21061 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21062 inst.instruction |= 1 << 5;
5287ad62
JB
21063 inst.instruction |= neon_logbits (et.size) << 6;
21064 break;
21065
21066 case 2: /* VLD3. */
21067 constraint (inst.operands[1].immisalign,
477330fc 21068 _("can't use alignment with this instruction"));
5287ad62 21069 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 21070 _("bad list length"));
5287ad62 21071 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21072 inst.instruction |= 1 << 5;
5287ad62
JB
21073 inst.instruction |= neon_logbits (et.size) << 6;
21074 break;
21075
21076 case 3: /* VLD4. */
21077 {
477330fc 21078 int align = inst.operands[1].imm >> 8;
aa8a0863 21079 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
21080 16, 64, 32, 64, 32, 128, -1);
21081 if (align_good == FAIL)
21082 return;
21083 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21084 _("bad list length"));
21085 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21086 inst.instruction |= 1 << 5;
21087 if (et.size == 32 && align == 128)
21088 inst.instruction |= 0x3 << 6;
21089 else
21090 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
21091 }
21092 break;
21093
21094 default: ;
21095 }
21096
aa8a0863 21097 inst.instruction |= do_alignment << 4;
5287ad62
JB
21098}
21099
21100/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21101 apart from bits [11:4]. */
21102
21103static void
21104do_neon_ldx_stx (void)
21105{
b1a769ed
DG
21106 if (inst.operands[1].isreg)
21107 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21108
5287ad62
JB
21109 switch (NEON_LANE (inst.operands[0].imm))
21110 {
21111 case NEON_INTERLEAVE_LANES:
88714cb8 21112 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
21113 do_neon_ld_st_interleave ();
21114 break;
5f4273c7 21115
5287ad62 21116 case NEON_ALL_LANES:
88714cb8 21117 NEON_ENCODE (DUP, inst);
2d51fb74
JB
21118 if (inst.instruction == N_INV)
21119 {
21120 first_error ("only loads support such operands");
21121 break;
21122 }
5287ad62
JB
21123 do_neon_ld_dup ();
21124 break;
5f4273c7 21125
5287ad62 21126 default:
88714cb8 21127 NEON_ENCODE (LANE, inst);
5287ad62
JB
21128 do_neon_ld_st_lane ();
21129 }
21130
21131 /* L bit comes from bit mask. */
21132 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21133 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21134 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 21135
5287ad62
JB
21136 if (inst.operands[1].postind)
21137 {
21138 int postreg = inst.operands[1].imm & 0xf;
21139 constraint (!inst.operands[1].immisreg,
477330fc 21140 _("post-index must be a register"));
5287ad62 21141 constraint (postreg == 0xd || postreg == 0xf,
477330fc 21142 _("bad register for post-index"));
5287ad62
JB
21143 inst.instruction |= postreg;
21144 }
4f2374c7 21145 else
5287ad62 21146 {
4f2374c7 21147 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
21148 constraint (inst.relocs[0].exp.X_op != O_constant
21149 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
21150 BAD_ADDR_MODE);
21151
21152 if (inst.operands[1].writeback)
21153 {
21154 inst.instruction |= 0xd;
21155 }
21156 else
21157 inst.instruction |= 0xf;
5287ad62 21158 }
5f4273c7 21159
5287ad62
JB
21160 if (thumb_mode)
21161 inst.instruction |= 0xf9000000;
21162 else
21163 inst.instruction |= 0xf4000000;
21164}
33399f07
MGD
21165
21166/* FP v8. */
21167static void
21168do_vfp_nsyn_fpv8 (enum neon_shape rs)
21169{
a715796b
TG
21170 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21171 D register operands. */
21172 if (neon_shape_class[rs] == SC_DOUBLE)
21173 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21174 _(BAD_FPU));
21175
33399f07
MGD
21176 NEON_ENCODE (FPV8, inst);
21177
9db2f6b4
RL
21178 if (rs == NS_FFF || rs == NS_HHH)
21179 {
21180 do_vfp_sp_dyadic ();
21181
21182 /* ARMv8.2 fp16 instruction. */
21183 if (rs == NS_HHH)
21184 do_scalar_fp16_v82_encode ();
21185 }
33399f07
MGD
21186 else
21187 do_vfp_dp_rd_rn_rm ();
21188
21189 if (rs == NS_DDD)
21190 inst.instruction |= 0x100;
21191
21192 inst.instruction |= 0xf0000000;
21193}
21194
21195static void
21196do_vsel (void)
21197{
5ee91343 21198 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
21199
21200 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21201 first_error (_("invalid instruction shape"));
21202}
21203
73924fbc
MGD
21204static void
21205do_vmaxnm (void)
21206{
935295b5
AV
21207 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21208 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
21209
21210 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21211 return;
21212
64c350f2 21213 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
21214 return;
21215
cc933301 21216 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
21217}
21218
30bdf752
MGD
21219static void
21220do_vrint_1 (enum neon_cvt_mode mode)
21221{
9db2f6b4 21222 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
21223 struct neon_type_el et;
21224
21225 if (rs == NS_NULL)
21226 return;
21227
a715796b
TG
21228 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21229 D register operands. */
21230 if (neon_shape_class[rs] == SC_DOUBLE)
21231 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21232 _(BAD_FPU));
21233
9db2f6b4
RL
21234 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21235 | N_VFP);
30bdf752
MGD
21236 if (et.type != NT_invtype)
21237 {
21238 /* VFP encodings. */
21239 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21240 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 21241 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
21242
21243 NEON_ENCODE (FPV8, inst);
9db2f6b4 21244 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
21245 do_vfp_sp_monadic ();
21246 else
21247 do_vfp_dp_rd_rm ();
21248
21249 switch (mode)
21250 {
21251 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21252 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21253 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21254 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21255 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21256 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21257 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21258 default: abort ();
21259 }
21260
21261 inst.instruction |= (rs == NS_DD) << 8;
21262 do_vfp_cond_or_thumb ();
9db2f6b4
RL
21263
21264 /* ARMv8.2 fp16 vrint instruction. */
21265 if (rs == NS_HH)
21266 do_scalar_fp16_v82_encode ();
30bdf752
MGD
21267 }
21268 else
21269 {
21270 /* Neon encodings (or something broken...). */
21271 inst.error = NULL;
cc933301 21272 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
21273
21274 if (et.type == NT_invtype)
21275 return;
21276
64c350f2
AV
21277 if (!check_simd_pred_availability (TRUE,
21278 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
21279 return;
21280
a710b305
AV
21281 NEON_ENCODE (FLOAT, inst);
21282
30bdf752
MGD
21283 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21284 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21285 inst.instruction |= LOW4 (inst.operands[1].reg);
21286 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21287 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
21288 /* Mask off the original size bits and reencode them. */
21289 inst.instruction = ((inst.instruction & 0xfff3ffff)
21290 | neon_logbits (et.size) << 18);
21291
30bdf752
MGD
21292 switch (mode)
21293 {
21294 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21295 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21296 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21297 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21298 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21299 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21300 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21301 default: abort ();
21302 }
21303
21304 if (thumb_mode)
21305 inst.instruction |= 0xfc000000;
21306 else
21307 inst.instruction |= 0xf0000000;
21308 }
21309}
21310
21311static void
21312do_vrintx (void)
21313{
21314 do_vrint_1 (neon_cvt_mode_x);
21315}
21316
21317static void
21318do_vrintz (void)
21319{
21320 do_vrint_1 (neon_cvt_mode_z);
21321}
21322
21323static void
21324do_vrintr (void)
21325{
21326 do_vrint_1 (neon_cvt_mode_r);
21327}
21328
21329static void
21330do_vrinta (void)
21331{
21332 do_vrint_1 (neon_cvt_mode_a);
21333}
21334
21335static void
21336do_vrintn (void)
21337{
21338 do_vrint_1 (neon_cvt_mode_n);
21339}
21340
21341static void
21342do_vrintp (void)
21343{
21344 do_vrint_1 (neon_cvt_mode_p);
21345}
21346
21347static void
21348do_vrintm (void)
21349{
21350 do_vrint_1 (neon_cvt_mode_m);
21351}
21352
c28eeff2
SN
21353static unsigned
21354neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21355{
21356 unsigned regno = NEON_SCALAR_REG (opnd);
21357 unsigned elno = NEON_SCALAR_INDEX (opnd);
21358
21359 if (elsize == 16 && elno < 2 && regno < 16)
21360 return regno | (elno << 4);
21361 else if (elsize == 32 && elno == 0)
21362 return regno;
21363
21364 first_error (_("scalar out of range"));
21365 return 0;
21366}
21367
21368static void
21369do_vcmla (void)
21370{
5d281bf0
AV
21371 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21372 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21373 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21374 constraint (inst.relocs[0].exp.X_op != O_constant,
21375 _("expression too complex"));
21376 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21377 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21378 _("immediate out of range"));
21379 rot /= 90;
5d281bf0 21380
64c350f2
AV
21381 if (!check_simd_pred_availability (TRUE,
21382 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21383 return;
21384
c28eeff2
SN
21385 if (inst.operands[2].isscalar)
21386 {
5d281bf0
AV
21387 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21388 first_error (_("invalid instruction shape"));
c28eeff2
SN
21389 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21390 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21391 N_KEY | N_F16 | N_F32).size;
21392 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21393 inst.is_neon = 1;
21394 inst.instruction = 0xfe000800;
21395 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21396 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21397 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21398 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21399 inst.instruction |= LOW4 (m);
21400 inst.instruction |= HI1 (m) << 5;
21401 inst.instruction |= neon_quad (rs) << 6;
21402 inst.instruction |= rot << 20;
21403 inst.instruction |= (size == 32) << 23;
21404 }
21405 else
21406 {
5d281bf0
AV
21407 enum neon_shape rs;
21408 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21409 rs = neon_select_shape (NS_QQQI, NS_NULL);
21410 else
21411 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21412
c28eeff2
SN
21413 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21414 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21415 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21416 && (inst.operands[0].reg == inst.operands[1].reg
21417 || inst.operands[0].reg == inst.operands[2].reg))
21418 as_tsktsk (BAD_MVE_SRCDEST);
21419
c28eeff2
SN
21420 neon_three_same (neon_quad (rs), 0, -1);
21421 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21422 inst.instruction |= 0xfc200800;
21423 inst.instruction |= rot << 23;
21424 inst.instruction |= (size == 32) << 20;
21425 }
21426}
21427
21428static void
21429do_vcadd (void)
21430{
5d281bf0
AV
21431 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21432 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21433 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21434 constraint (inst.relocs[0].exp.X_op != O_constant,
21435 _("expression too complex"));
5d281bf0 21436
e2b0ab59 21437 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21438 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21439 enum neon_shape rs;
21440 struct neon_type_el et;
21441 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21442 {
21443 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21444 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21445 }
21446 else
21447 {
21448 rs = neon_select_shape (NS_QQQI, NS_NULL);
21449 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21450 | N_I16 | N_I32);
21451 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21452 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21453 "operand makes instruction UNPREDICTABLE"));
21454 }
21455
21456 if (et.type == NT_invtype)
21457 return;
21458
64c350f2
AV
21459 if (!check_simd_pred_availability (et.type == NT_float,
21460 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21461 return;
21462
21463 if (et.type == NT_float)
21464 {
21465 neon_three_same (neon_quad (rs), 0, -1);
21466 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21467 inst.instruction |= 0xfc800800;
21468 inst.instruction |= (rot == 270) << 24;
21469 inst.instruction |= (et.size == 32) << 20;
21470 }
21471 else
21472 {
21473 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21474 inst.instruction = 0xfe000f00;
21475 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21476 inst.instruction |= neon_logbits (et.size) << 20;
21477 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21478 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21479 inst.instruction |= (rot == 270) << 12;
21480 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21481 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21482 inst.instruction |= LOW4 (inst.operands[2].reg);
21483 inst.is_neon = 1;
21484 }
c28eeff2
SN
21485}
21486
c604a79a
JW
21487/* Dot Product instructions encoding support. */
21488
21489static void
21490do_neon_dotproduct (int unsigned_p)
21491{
21492 enum neon_shape rs;
21493 unsigned scalar_oprd2 = 0;
21494 int high8;
21495
21496 if (inst.cond != COND_ALWAYS)
21497 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21498 "is UNPREDICTABLE"));
21499
21500 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21501 _(BAD_FPU));
21502
21503 /* Dot Product instructions are in three-same D/Q register format or the third
21504 operand can be a scalar index register. */
21505 if (inst.operands[2].isscalar)
21506 {
21507 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21508 high8 = 0xfe000000;
21509 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21510 }
21511 else
21512 {
21513 high8 = 0xfc000000;
21514 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21515 }
21516
21517 if (unsigned_p)
21518 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21519 else
21520 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21521
21522 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21523 Product instruction, so we pass 0 as the "ubit" parameter. And the
21524 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21525 neon_three_same (neon_quad (rs), 0, 32);
21526
21527 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21528 different NEON three-same encoding. */
21529 inst.instruction &= 0x00ffffff;
21530 inst.instruction |= high8;
21531 /* Encode 'U' bit which indicates signedness. */
21532 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21533 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21534 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21535 the instruction encoding. */
21536 if (inst.operands[2].isscalar)
21537 {
21538 inst.instruction &= 0xffffffd0;
21539 inst.instruction |= LOW4 (scalar_oprd2);
21540 inst.instruction |= HI1 (scalar_oprd2) << 5;
21541 }
21542}
21543
21544/* Dot Product instructions for signed integer. */
21545
21546static void
21547do_neon_dotproduct_s (void)
21548{
21549 return do_neon_dotproduct (0);
21550}
21551
21552/* Dot Product instructions for unsigned integer. */
21553
21554static void
21555do_neon_dotproduct_u (void)
21556{
21557 return do_neon_dotproduct (1);
21558}
21559
616ce08e
MM
21560static void
21561do_vusdot (void)
21562{
21563 enum neon_shape rs;
21564 set_pred_insn_type (OUTSIDE_PRED_INSN);
21565 if (inst.operands[2].isscalar)
21566 {
21567 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21568 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21569
21570 inst.instruction |= (1 << 25);
21571 int index = inst.operands[2].reg & 0xf;
21572 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21573 inst.operands[2].reg >>= 4;
21574 constraint (!(inst.operands[2].reg < 16),
21575 _("indexed register must be less than 16"));
21576 neon_three_args (rs == NS_QQS);
21577 inst.instruction |= (index << 5);
21578 }
21579 else
21580 {
21581 inst.instruction |= (1 << 21);
21582 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21583 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21584 neon_three_args (rs == NS_QQQ);
21585 }
21586}
21587
21588static void
21589do_vsudot (void)
21590{
21591 enum neon_shape rs;
21592 set_pred_insn_type (OUTSIDE_PRED_INSN);
21593 if (inst.operands[2].isscalar)
21594 {
21595 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21596 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21597
21598 inst.instruction |= (1 << 25);
21599 int index = inst.operands[2].reg & 0xf;
21600 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21601 inst.operands[2].reg >>= 4;
21602 constraint (!(inst.operands[2].reg < 16),
21603 _("indexed register must be less than 16"));
21604 neon_three_args (rs == NS_QQS);
21605 inst.instruction |= (index << 5);
21606 }
21607}
21608
21609static void
21610do_vsmmla (void)
21611{
21612 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21613 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21614
21615 set_pred_insn_type (OUTSIDE_PRED_INSN);
21616
21617 neon_three_args (1);
21618
21619}
21620
21621static void
21622do_vummla (void)
21623{
21624 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21625 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21626
21627 set_pred_insn_type (OUTSIDE_PRED_INSN);
21628
21629 neon_three_args (1);
21630
21631}
21632
4934a27c
MM
21633static void
21634check_cde_operand (size_t index, int is_dual)
21635{
21636 unsigned Rx = inst.operands[index].reg;
21637 bfd_boolean isvec = inst.operands[index].isvec;
21638 if (is_dual == 0 && thumb_mode)
21639 constraint (
21640 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21641 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21642 else
21643 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21644 _("Register must be an even register between r0-r10."));
21645}
21646
21647static bfd_boolean
21648cde_coproc_enabled (unsigned coproc)
21649{
21650 switch (coproc)
21651 {
21652 case 0: return mark_feature_used (&arm_ext_cde0);
21653 case 1: return mark_feature_used (&arm_ext_cde1);
21654 case 2: return mark_feature_used (&arm_ext_cde2);
21655 case 3: return mark_feature_used (&arm_ext_cde3);
21656 case 4: return mark_feature_used (&arm_ext_cde4);
21657 case 5: return mark_feature_used (&arm_ext_cde5);
21658 case 6: return mark_feature_used (&arm_ext_cde6);
21659 case 7: return mark_feature_used (&arm_ext_cde7);
21660 default: return FALSE;
21661 }
21662}
21663
21664#define cde_coproc_pos 8
21665static void
21666cde_handle_coproc (void)
21667{
21668 unsigned coproc = inst.operands[0].reg;
21669 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21670 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21671 inst.instruction |= coproc << cde_coproc_pos;
21672}
21673#undef cde_coproc_pos
21674
21675static void
21676cxn_handle_predication (bfd_boolean is_accum)
21677{
cceb53b8
MM
21678 if (is_accum && conditional_insn ())
21679 set_pred_insn_type (INSIDE_IT_INSN);
21680 else if (conditional_insn ())
21681 /* conditional_insn essentially checks for a suffix, not whether the
21682 instruction is inside an IT block or not.
21683 The non-accumulator versions should not have suffixes. */
4934a27c 21684 inst.error = BAD_SYNTAX;
4934a27c
MM
21685 else
21686 set_pred_insn_type (OUTSIDE_PRED_INSN);
21687}
21688
21689static void
21690do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21691{
21692
21693 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21694
21695 unsigned imm, Rd;
21696
21697 Rd = inst.operands[1].reg;
21698 check_cde_operand (1, is_dual);
21699
21700 if (is_dual == 1)
21701 {
21702 constraint (inst.operands[2].reg != Rd + 1,
21703 _("cx1d requires consecutive destination registers."));
21704 imm = inst.operands[3].imm;
21705 }
21706 else if (is_dual == 0)
21707 imm = inst.operands[2].imm;
21708 else
21709 abort ();
21710
21711 inst.instruction |= Rd << 12;
21712 inst.instruction |= (imm & 0x1F80) << 9;
21713 inst.instruction |= (imm & 0x0040) << 1;
21714 inst.instruction |= (imm & 0x003f);
21715
21716 cde_handle_coproc ();
21717 cxn_handle_predication (is_accum);
21718}
21719
21720static void
21721do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21722{
21723
21724 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21725
21726 unsigned imm, Rd, Rn;
21727
21728 Rd = inst.operands[1].reg;
21729
21730 if (is_dual == 1)
21731 {
21732 constraint (inst.operands[2].reg != Rd + 1,
21733 _("cx2d requires consecutive destination registers."));
21734 imm = inst.operands[4].imm;
21735 Rn = inst.operands[3].reg;
21736 }
21737 else if (is_dual == 0)
21738 {
21739 imm = inst.operands[3].imm;
21740 Rn = inst.operands[2].reg;
21741 }
21742 else
21743 abort ();
21744
21745 check_cde_operand (2 + is_dual, /* is_dual = */0);
21746 check_cde_operand (1, is_dual);
21747
21748 inst.instruction |= Rd << 12;
21749 inst.instruction |= Rn << 16;
21750
21751 inst.instruction |= (imm & 0x0380) << 13;
21752 inst.instruction |= (imm & 0x0040) << 1;
21753 inst.instruction |= (imm & 0x003f);
21754
21755 cde_handle_coproc ();
21756 cxn_handle_predication (is_accum);
21757}
21758
21759static void
21760do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21761{
21762
21763 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21764
21765 unsigned imm, Rd, Rn, Rm;
21766
21767 Rd = inst.operands[1].reg;
21768
21769 if (is_dual == 1)
21770 {
21771 constraint (inst.operands[2].reg != Rd + 1,
21772 _("cx3d requires consecutive destination registers."));
21773 imm = inst.operands[5].imm;
21774 Rn = inst.operands[3].reg;
21775 Rm = inst.operands[4].reg;
21776 }
21777 else if (is_dual == 0)
21778 {
21779 imm = inst.operands[4].imm;
21780 Rn = inst.operands[2].reg;
21781 Rm = inst.operands[3].reg;
21782 }
21783 else
21784 abort ();
21785
21786 check_cde_operand (1, is_dual);
21787 check_cde_operand (2 + is_dual, /* is_dual = */0);
21788 check_cde_operand (3 + is_dual, /* is_dual = */0);
21789
21790 inst.instruction |= Rd;
21791 inst.instruction |= Rn << 16;
21792 inst.instruction |= Rm << 12;
21793
21794 inst.instruction |= (imm & 0x0038) << 17;
21795 inst.instruction |= (imm & 0x0004) << 5;
21796 inst.instruction |= (imm & 0x0003) << 4;
21797
21798 cde_handle_coproc ();
21799 cxn_handle_predication (is_accum);
21800}
21801
21802static void
21803do_cx1 (void)
21804{
21805 return do_custom_instruction_1 (0, 0);
21806}
21807
21808static void
21809do_cx1a (void)
21810{
21811 return do_custom_instruction_1 (0, 1);
21812}
21813
21814static void
21815do_cx1d (void)
21816{
21817 return do_custom_instruction_1 (1, 0);
21818}
21819
21820static void
21821do_cx1da (void)
21822{
21823 return do_custom_instruction_1 (1, 1);
21824}
21825
21826static void
21827do_cx2 (void)
21828{
21829 return do_custom_instruction_2 (0, 0);
21830}
21831
21832static void
21833do_cx2a (void)
21834{
21835 return do_custom_instruction_2 (0, 1);
21836}
21837
21838static void
21839do_cx2d (void)
21840{
21841 return do_custom_instruction_2 (1, 0);
21842}
21843
21844static void
21845do_cx2da (void)
21846{
21847 return do_custom_instruction_2 (1, 1);
21848}
21849
21850static void
21851do_cx3 (void)
21852{
21853 return do_custom_instruction_3 (0, 0);
21854}
21855
21856static void
21857do_cx3a (void)
21858{
21859 return do_custom_instruction_3 (0, 1);
21860}
21861
21862static void
21863do_cx3d (void)
21864{
21865 return do_custom_instruction_3 (1, 0);
21866}
21867
21868static void
21869do_cx3da (void)
21870{
21871 return do_custom_instruction_3 (1, 1);
21872}
21873
5aae9ae9
MM
21874static void
21875vcx_assign_vec_d (unsigned regnum)
21876{
21877 inst.instruction |= HI4 (regnum) << 12;
21878 inst.instruction |= LOW1 (regnum) << 22;
21879}
21880
21881static void
21882vcx_assign_vec_m (unsigned regnum)
21883{
21884 inst.instruction |= HI4 (regnum);
21885 inst.instruction |= LOW1 (regnum) << 5;
21886}
21887
21888static void
21889vcx_assign_vec_n (unsigned regnum)
21890{
21891 inst.instruction |= HI4 (regnum) << 16;
21892 inst.instruction |= LOW1 (regnum) << 7;
21893}
21894
21895enum vcx_reg_type {
21896 q_reg,
21897 d_reg,
21898 s_reg
21899};
21900
21901static enum vcx_reg_type
21902vcx_get_reg_type (enum neon_shape ns)
21903{
21904 gas_assert (ns == NS_PQI
21905 || ns == NS_PDI
21906 || ns == NS_PFI
21907 || ns == NS_PQQI
21908 || ns == NS_PDDI
21909 || ns == NS_PFFI
21910 || ns == NS_PQQQI
21911 || ns == NS_PDDDI
21912 || ns == NS_PFFFI);
21913 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21914 return q_reg;
21915 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21916 return d_reg;
21917 return s_reg;
21918}
21919
21920#define vcx_size_pos 24
21921#define vcx_vec_pos 6
21922static unsigned
21923vcx_handle_shape (enum vcx_reg_type reg_type)
21924{
21925 unsigned mult = 2;
21926 if (reg_type == q_reg)
21927 inst.instruction |= 1 << vcx_vec_pos;
21928 else if (reg_type == d_reg)
21929 inst.instruction |= 1 << vcx_size_pos;
21930 else
21931 mult = 1;
21932 /* NOTE:
21933 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21934 bits (or equivalent for N and M registers).
21935 Similarly the D registers are encoded as N in D:Vd bits.
21936 While the S registers are encoded as N in the Vd:D bits.
21937
21938 Taking into account the maximum values of these registers we can see a
21939 nicer pattern for calculation:
21940 Q -> 7, D -> 15, S -> 31
21941
21942 If we say that everything is encoded in the Vd:D bits, then we can say
21943 that Q is encoded as 4*N, and D is encoded as 2*N.
21944 This way the bits will end up the same, and calculation is simpler.
21945 (calculation is now:
21946 1. Multiply by a number determined by the register letter.
21947 2. Encode resulting number in Vd:D bits.)
21948
21949 This is made a little more complicated by automatic handling of 'Q'
21950 registers elsewhere, which means the register number is already 2*N where
21951 N is the number the user wrote after the register letter.
21952 */
21953 return mult;
21954}
21955#undef vcx_vec_pos
21956#undef vcx_size_pos
21957
21958static void
21959vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21960{
21961 if (reg_type == q_reg)
21962 {
21963 gas_assert (R % 2 == 0);
21964 constraint (R >= 16, _("'q' register must be in range 0-7"));
21965 }
21966 else if (reg_type == d_reg)
21967 constraint (R >= 16, _("'d' register must be in range 0-15"));
21968 else
21969 constraint (R >= 32, _("'s' register must be in range 0-31"));
21970}
21971
21972static void (*vcx_assign_vec[3]) (unsigned) = {
21973 vcx_assign_vec_d,
21974 vcx_assign_vec_m,
21975 vcx_assign_vec_n
21976};
21977
21978static void
21979vcx_handle_register_arguments (unsigned num_registers,
21980 enum vcx_reg_type reg_type)
21981{
1ed818b4 21982 unsigned R, i;
5aae9ae9 21983 unsigned reg_mult = vcx_handle_shape (reg_type);
1ed818b4 21984 for (i = 0; i < num_registers; i++)
5aae9ae9
MM
21985 {
21986 R = inst.operands[i+1].reg;
21987 vcx_ensure_register_in_range (R, reg_type);
21988 if (num_registers == 3 && i > 0)
21989 {
21990 if (i == 2)
21991 vcx_assign_vec[1] (R * reg_mult);
21992 else
21993 vcx_assign_vec[2] (R * reg_mult);
21994 continue;
21995 }
21996 vcx_assign_vec[i](R * reg_mult);
21997 }
21998}
21999
22000static void
22001vcx_handle_insn_block (enum vcx_reg_type reg_type)
22002{
22003 if (reg_type == q_reg)
22004 if (inst.cond > COND_ALWAYS)
22005 inst.pred_insn_type = INSIDE_VPT_INSN;
22006 else
22007 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22008 else if (inst.cond == COND_ALWAYS)
22009 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22010 else
22011 inst.error = BAD_NOT_IT;
22012}
22013
22014static void
22015vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22016{
22017 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22018 cde_handle_coproc ();
22019 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22020 vcx_handle_register_arguments (num_args, reg_type);
22021 vcx_handle_insn_block (reg_type);
22022 if (reg_type == q_reg)
22023 constraint (!mark_feature_used (&mve_ext),
22024 _("vcx instructions with Q registers require MVE"));
22025 else
22026 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22027 && mark_feature_used (&armv8m_fp))
22028 && !mark_feature_used (&mve_ext),
22029 _("vcx instructions with S or D registers require either MVE"
22030 " or Armv8-M floating point etension."));
22031}
22032
22033static void
22034do_vcx1 (void)
22035{
22036 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22037 vcx_handle_common_checks (1, rs);
22038
22039 unsigned imm = inst.operands[2].imm;
22040 inst.instruction |= (imm & 0x03f);
22041 inst.instruction |= (imm & 0x040) << 1;
22042 inst.instruction |= (imm & 0x780) << 9;
22043 if (rs != NS_PQI)
22044 constraint (imm >= 2048,
22045 _("vcx1 with S or D registers takes immediate within 0-2047"));
22046 inst.instruction |= (imm & 0x800) << 13;
22047}
22048
22049static void
22050do_vcx2 (void)
22051{
22052 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22053 vcx_handle_common_checks (2, rs);
22054
22055 unsigned imm = inst.operands[3].imm;
22056 inst.instruction |= (imm & 0x01) << 4;
22057 inst.instruction |= (imm & 0x02) << 6;
22058 inst.instruction |= (imm & 0x3c) << 14;
22059 if (rs != NS_PQQI)
22060 constraint (imm >= 64,
22061 _("vcx2 with S or D registers takes immediate within 0-63"));
22062 inst.instruction |= (imm & 0x40) << 18;
22063}
22064
22065static void
22066do_vcx3 (void)
22067{
22068 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22069 vcx_handle_common_checks (3, rs);
22070
22071 unsigned imm = inst.operands[4].imm;
22072 inst.instruction |= (imm & 0x1) << 4;
22073 inst.instruction |= (imm & 0x6) << 19;
22074 if (rs != NS_PQQQI)
22075 constraint (imm >= 8,
22076 _("vcx2 with S or D registers takes immediate within 0-7"));
22077 inst.instruction |= (imm & 0x8) << 21;
22078}
22079
91ff7894
MGD
22080/* Crypto v1 instructions. */
22081static void
22082do_crypto_2op_1 (unsigned elttype, int op)
22083{
5ee91343 22084 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
22085
22086 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22087 == NT_invtype)
22088 return;
22089
22090 inst.error = NULL;
22091
22092 NEON_ENCODE (INTEGER, inst);
22093 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22094 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22095 inst.instruction |= LOW4 (inst.operands[1].reg);
22096 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22097 if (op != -1)
22098 inst.instruction |= op << 6;
22099
22100 if (thumb_mode)
22101 inst.instruction |= 0xfc000000;
22102 else
22103 inst.instruction |= 0xf0000000;
22104}
22105
48adcd8e
MGD
22106static void
22107do_crypto_3op_1 (int u, int op)
22108{
5ee91343 22109 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
22110
22111 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22112 N_32 | N_UNT | N_KEY).type == NT_invtype)
22113 return;
22114
22115 inst.error = NULL;
22116
22117 NEON_ENCODE (INTEGER, inst);
22118 neon_three_same (1, u, 8 << op);
22119}
22120
91ff7894
MGD
22121static void
22122do_aese (void)
22123{
22124 do_crypto_2op_1 (N_8, 0);
22125}
22126
22127static void
22128do_aesd (void)
22129{
22130 do_crypto_2op_1 (N_8, 1);
22131}
22132
22133static void
22134do_aesmc (void)
22135{
22136 do_crypto_2op_1 (N_8, 2);
22137}
22138
22139static void
22140do_aesimc (void)
22141{
22142 do_crypto_2op_1 (N_8, 3);
22143}
22144
48adcd8e
MGD
22145static void
22146do_sha1c (void)
22147{
22148 do_crypto_3op_1 (0, 0);
22149}
22150
22151static void
22152do_sha1p (void)
22153{
22154 do_crypto_3op_1 (0, 1);
22155}
22156
22157static void
22158do_sha1m (void)
22159{
22160 do_crypto_3op_1 (0, 2);
22161}
22162
22163static void
22164do_sha1su0 (void)
22165{
22166 do_crypto_3op_1 (0, 3);
22167}
91ff7894 22168
48adcd8e
MGD
22169static void
22170do_sha256h (void)
22171{
22172 do_crypto_3op_1 (1, 0);
22173}
22174
22175static void
22176do_sha256h2 (void)
22177{
22178 do_crypto_3op_1 (1, 1);
22179}
22180
22181static void
22182do_sha256su1 (void)
22183{
22184 do_crypto_3op_1 (1, 2);
22185}
3c9017d2
MGD
22186
22187static void
22188do_sha1h (void)
22189{
22190 do_crypto_2op_1 (N_32, -1);
22191}
22192
22193static void
22194do_sha1su1 (void)
22195{
22196 do_crypto_2op_1 (N_32, 0);
22197}
22198
22199static void
22200do_sha256su0 (void)
22201{
22202 do_crypto_2op_1 (N_32, 1);
22203}
dd5181d5
KT
22204
22205static void
22206do_crc32_1 (unsigned int poly, unsigned int sz)
22207{
22208 unsigned int Rd = inst.operands[0].reg;
22209 unsigned int Rn = inst.operands[1].reg;
22210 unsigned int Rm = inst.operands[2].reg;
22211
5ee91343 22212 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
22213 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22214 inst.instruction |= LOW4 (Rn) << 16;
22215 inst.instruction |= LOW4 (Rm);
22216 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22217 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22218
22219 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22220 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
22221}
22222
22223static void
22224do_crc32b (void)
22225{
22226 do_crc32_1 (0, 0);
22227}
22228
22229static void
22230do_crc32h (void)
22231{
22232 do_crc32_1 (0, 1);
22233}
22234
22235static void
22236do_crc32w (void)
22237{
22238 do_crc32_1 (0, 2);
22239}
22240
22241static void
22242do_crc32cb (void)
22243{
22244 do_crc32_1 (1, 0);
22245}
22246
22247static void
22248do_crc32ch (void)
22249{
22250 do_crc32_1 (1, 1);
22251}
22252
22253static void
22254do_crc32cw (void)
22255{
22256 do_crc32_1 (1, 2);
22257}
22258
49e8a725
SN
22259static void
22260do_vjcvt (void)
22261{
22262 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22263 _(BAD_FPU));
22264 neon_check_type (2, NS_FD, N_S32, N_F64);
22265 do_vfp_sp_dp_cvt ();
22266 do_vfp_cond_or_thumb ();
22267}
22268
aab2c27d
MM
22269static void
22270do_vdot (void)
22271{
22272 enum neon_shape rs;
22273 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22274 set_pred_insn_type (OUTSIDE_PRED_INSN);
22275 if (inst.operands[2].isscalar)
22276 {
22277 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22278 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22279
22280 inst.instruction |= (1 << 25);
22281 int index = inst.operands[2].reg & 0xf;
22282 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22283 inst.operands[2].reg >>= 4;
22284 constraint (!(inst.operands[2].reg < 16),
22285 _("indexed register must be less than 16"));
22286 neon_three_args (rs == NS_QQS);
22287 inst.instruction |= (index << 5);
22288 }
22289 else
22290 {
22291 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22292 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22293 neon_three_args (rs == NS_QQQ);
22294 }
22295}
22296
22297static void
22298do_vmmla (void)
22299{
22300 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22301 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22302
22303 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22304 set_pred_insn_type (OUTSIDE_PRED_INSN);
22305
22306 neon_three_args (1);
22307}
22308
5287ad62
JB
22309\f
22310/* Overall per-instruction processing. */
22311
22312/* We need to be able to fix up arbitrary expressions in some statements.
22313 This is so that we can handle symbols that are an arbitrary distance from
22314 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22315 which returns part of an address in a form which will be valid for
22316 a data instruction. We do this by pushing the expression into a symbol
22317 in the expr_section, and creating a fix for that. */
22318
22319static void
22320fix_new_arm (fragS * frag,
22321 int where,
22322 short int size,
22323 expressionS * exp,
22324 int pc_rel,
22325 int reloc)
22326{
22327 fixS * new_fix;
22328
22329 switch (exp->X_op)
22330 {
22331 case O_constant:
6e7ce2cd
PB
22332 if (pc_rel)
22333 {
22334 /* Create an absolute valued symbol, so we have something to
477330fc
RM
22335 refer to in the object file. Unfortunately for us, gas's
22336 generic expression parsing will already have folded out
22337 any use of .set foo/.type foo %function that may have
22338 been used to set type information of the target location,
22339 that's being specified symbolically. We have to presume
22340 the user knows what they are doing. */
6e7ce2cd
PB
22341 char name[16 + 8];
22342 symbolS *symbol;
22343
22344 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22345
22346 symbol = symbol_find_or_make (name);
22347 S_SET_SEGMENT (symbol, absolute_section);
22348 symbol_set_frag (symbol, &zero_address_frag);
22349 S_SET_VALUE (symbol, exp->X_add_number);
22350 exp->X_op = O_symbol;
22351 exp->X_add_symbol = symbol;
22352 exp->X_add_number = 0;
22353 }
22354 /* FALLTHROUGH */
5287ad62
JB
22355 case O_symbol:
22356 case O_add:
22357 case O_subtract:
21d799b5 22358 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 22359 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22360 break;
22361
22362 default:
21d799b5 22363 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 22364 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22365 break;
22366 }
22367
22368 /* Mark whether the fix is to a THUMB instruction, or an ARM
22369 instruction. */
22370 new_fix->tc_fix_data = thumb_mode;
22371}
22372
22373/* Create a frg for an instruction requiring relaxation. */
22374static void
22375output_relax_insn (void)
22376{
22377 char * to;
22378 symbolS *sym;
0110f2b8
PB
22379 int offset;
22380
6e1cb1a6
PB
22381 /* The size of the instruction is unknown, so tie the debug info to the
22382 start of the instruction. */
22383 dwarf2_emit_insn (0);
6e1cb1a6 22384
e2b0ab59 22385 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
22386 {
22387 case O_symbol:
e2b0ab59
AV
22388 sym = inst.relocs[0].exp.X_add_symbol;
22389 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22390 break;
22391 case O_constant:
22392 sym = NULL;
e2b0ab59 22393 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22394 break;
22395 default:
e2b0ab59 22396 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
22397 offset = 0;
22398 break;
22399 }
22400 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22401 inst.relax, sym, offset, NULL/*offset, opcode*/);
22402 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
22403}
22404
22405/* Write a 32-bit thumb instruction to buf. */
22406static void
22407put_thumb32_insn (char * buf, unsigned long insn)
22408{
22409 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22410 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22411}
22412
b99bd4ef 22413static void
c19d1205 22414output_inst (const char * str)
b99bd4ef 22415{
c19d1205 22416 char * to = NULL;
b99bd4ef 22417
c19d1205 22418 if (inst.error)
b99bd4ef 22419 {
c19d1205 22420 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
22421 return;
22422 }
5f4273c7
NC
22423 if (inst.relax)
22424 {
22425 output_relax_insn ();
0110f2b8 22426 return;
5f4273c7 22427 }
c19d1205
ZW
22428 if (inst.size == 0)
22429 return;
b99bd4ef 22430
c19d1205 22431 to = frag_more (inst.size);
8dc2430f
NC
22432 /* PR 9814: Record the thumb mode into the current frag so that we know
22433 what type of NOP padding to use, if necessary. We override any previous
22434 setting so that if the mode has changed then the NOPS that we use will
22435 match the encoding of the last instruction in the frag. */
cd000bff 22436 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
22437
22438 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 22439 {
9c2799c2 22440 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 22441 put_thumb32_insn (to, inst.instruction);
b99bd4ef 22442 }
c19d1205 22443 else if (inst.size > INSN_SIZE)
b99bd4ef 22444 {
9c2799c2 22445 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
22446 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22447 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 22448 }
c19d1205
ZW
22449 else
22450 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 22451
e2b0ab59
AV
22452 int r;
22453 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22454 {
22455 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22456 fix_new_arm (frag_now, to - frag_now->fr_literal,
22457 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22458 inst.relocs[r].type);
22459 }
b99bd4ef 22460
c19d1205 22461 dwarf2_emit_insn (inst.size);
c19d1205 22462}
b99bd4ef 22463
e07e6e58
NC
22464static char *
22465output_it_inst (int cond, int mask, char * to)
22466{
22467 unsigned long instruction = 0xbf00;
22468
22469 mask &= 0xf;
22470 instruction |= mask;
22471 instruction |= cond << 4;
22472
22473 if (to == NULL)
22474 {
22475 to = frag_more (2);
22476#ifdef OBJ_ELF
22477 dwarf2_emit_insn (2);
22478#endif
22479 }
22480
22481 md_number_to_chars (to, instruction, 2);
22482
22483 return to;
22484}
22485
c19d1205
ZW
22486/* Tag values used in struct asm_opcode's tag field. */
22487enum opcode_tag
22488{
22489 OT_unconditional, /* Instruction cannot be conditionalized.
22490 The ARM condition field is still 0xE. */
22491 OT_unconditionalF, /* Instruction cannot be conditionalized
22492 and carries 0xF in its ARM condition field. */
22493 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
22494 OT_csuffixF, /* Some forms of the instruction take a scalar
22495 conditional suffix, others place 0xF where the
22496 condition field would be, others take a vector
22497 conditional suffix. */
c19d1205
ZW
22498 OT_cinfix3, /* Instruction takes a conditional infix,
22499 beginning at character index 3. (In
22500 unified mode, it becomes a suffix.) */
088fa78e
KH
22501 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22502 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
22503 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22504 character index 3, even in unified mode. Used for
22505 legacy instructions where suffix and infix forms
22506 may be ambiguous. */
c19d1205 22507 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 22508 suffix or an infix at character index 3. */
c19d1205
ZW
22509 OT_odd_infix_unc, /* This is the unconditional variant of an
22510 instruction that takes a conditional infix
22511 at an unusual position. In unified mode,
22512 this variant will accept a suffix. */
22513 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22514 are the conditional variants of instructions that
22515 take conditional infixes in unusual positions.
22516 The infix appears at character index
22517 (tag - OT_odd_infix_0). These are not accepted
22518 in unified mode. */
22519};
b99bd4ef 22520
c19d1205
ZW
22521/* Subroutine of md_assemble, responsible for looking up the primary
22522 opcode from the mnemonic the user wrote. STR points to the
22523 beginning of the mnemonic.
22524
22525 This is not simply a hash table lookup, because of conditional
22526 variants. Most instructions have conditional variants, which are
22527 expressed with a _conditional affix_ to the mnemonic. If we were
22528 to encode each conditional variant as a literal string in the opcode
22529 table, it would have approximately 20,000 entries.
22530
22531 Most mnemonics take this affix as a suffix, and in unified syntax,
22532 'most' is upgraded to 'all'. However, in the divided syntax, some
22533 instructions take the affix as an infix, notably the s-variants of
22534 the arithmetic instructions. Of those instructions, all but six
22535 have the infix appear after the third character of the mnemonic.
22536
22537 Accordingly, the algorithm for looking up primary opcodes given
22538 an identifier is:
22539
22540 1. Look up the identifier in the opcode table.
22541 If we find a match, go to step U.
22542
22543 2. Look up the last two characters of the identifier in the
22544 conditions table. If we find a match, look up the first N-2
22545 characters of the identifier in the opcode table. If we
22546 find a match, go to step CE.
22547
22548 3. Look up the fourth and fifth characters of the identifier in
22549 the conditions table. If we find a match, extract those
22550 characters from the identifier, and look up the remaining
22551 characters in the opcode table. If we find a match, go
22552 to step CM.
22553
22554 4. Fail.
22555
22556 U. Examine the tag field of the opcode structure, in case this is
22557 one of the six instructions with its conditional infix in an
22558 unusual place. If it is, the tag tells us where to find the
22559 infix; look it up in the conditions table and set inst.cond
22560 accordingly. Otherwise, this is an unconditional instruction.
22561 Again set inst.cond accordingly. Return the opcode structure.
22562
22563 CE. Examine the tag field to make sure this is an instruction that
22564 should receive a conditional suffix. If it is not, fail.
22565 Otherwise, set inst.cond from the suffix we already looked up,
22566 and return the opcode structure.
22567
22568 CM. Examine the tag field to make sure this is an instruction that
22569 should receive a conditional infix after the third character.
22570 If it is not, fail. Otherwise, undo the edits to the current
22571 line of input and proceed as for case CE. */
22572
22573static const struct asm_opcode *
22574opcode_lookup (char **str)
22575{
22576 char *end, *base;
22577 char *affix;
22578 const struct asm_opcode *opcode;
22579 const struct asm_cond *cond;
e3cb604e 22580 char save[2];
c19d1205
ZW
22581
22582 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 22583 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 22584 for (base = end = *str; *end != '\0'; end++)
721a8186 22585 if (*end == ' ' || *end == '.')
c19d1205 22586 break;
b99bd4ef 22587
c19d1205 22588 if (end == base)
c921be7d 22589 return NULL;
b99bd4ef 22590
5287ad62 22591 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 22592 if (end[0] == '.')
b99bd4ef 22593 {
5287ad62 22594 int offset = 2;
5f4273c7 22595
267d2029 22596 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 22597 use. */
267d2029 22598 if (unified_syntax && end[1] == 'w')
c19d1205 22599 inst.size_req = 4;
267d2029 22600 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
22601 inst.size_req = 2;
22602 else
477330fc 22603 offset = 0;
5287ad62
JB
22604
22605 inst.vectype.elems = 0;
22606
22607 *str = end + offset;
b99bd4ef 22608
5f4273c7 22609 if (end[offset] == '.')
5287ad62 22610 {
267d2029 22611 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
22612 non-unified ARM syntax mode). */
22613 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 22614 return NULL;
477330fc 22615 }
5287ad62 22616 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 22617 return NULL;
b99bd4ef 22618 }
c19d1205
ZW
22619 else
22620 *str = end;
b99bd4ef 22621
c19d1205 22622 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 22623 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22624 end - base);
c19d1205 22625 if (opcode)
b99bd4ef 22626 {
c19d1205
ZW
22627 /* step U */
22628 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 22629 {
c19d1205
ZW
22630 inst.cond = COND_ALWAYS;
22631 return opcode;
b99bd4ef 22632 }
b99bd4ef 22633
278df34e 22634 if (warn_on_deprecated && unified_syntax)
5c3696f8 22635 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 22636 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 22637 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 22638 gas_assert (cond);
b99bd4ef 22639
c19d1205
ZW
22640 inst.cond = cond->value;
22641 return opcode;
22642 }
5ee91343
AV
22643 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22644 {
22645 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22646 */
22647 if (end - base < 2)
22648 return NULL;
22649 affix = end - 1;
22650 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
22651 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22652 affix - base);
22653 /* If this opcode can not be vector predicated then don't accept it with a
22654 vector predication code. */
22655 if (opcode && !opcode->mayBeVecPred)
22656 opcode = NULL;
22657 }
22658 if (!opcode || !cond)
22659 {
22660 /* Cannot have a conditional suffix on a mnemonic of less than two
22661 characters. */
22662 if (end - base < 3)
22663 return NULL;
b99bd4ef 22664
5ee91343
AV
22665 /* Look for suffixed mnemonic. */
22666 affix = end - 2;
22667 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22668 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22669 affix - base);
22670 }
b99bd4ef 22671
c19d1205
ZW
22672 if (opcode && cond)
22673 {
22674 /* step CE */
22675 switch (opcode->tag)
22676 {
e3cb604e
PB
22677 case OT_cinfix3_legacy:
22678 /* Ignore conditional suffixes matched on infix only mnemonics. */
22679 break;
22680
c19d1205 22681 case OT_cinfix3:
088fa78e 22682 case OT_cinfix3_deprecated:
c19d1205
ZW
22683 case OT_odd_infix_unc:
22684 if (!unified_syntax)
0198d5e6 22685 return NULL;
1a0670f3 22686 /* Fall through. */
c19d1205
ZW
22687
22688 case OT_csuffix:
477330fc 22689 case OT_csuffixF:
c19d1205
ZW
22690 case OT_csuf_or_in3:
22691 inst.cond = cond->value;
22692 return opcode;
22693
22694 case OT_unconditional:
22695 case OT_unconditionalF:
dfa9f0d5 22696 if (thumb_mode)
c921be7d 22697 inst.cond = cond->value;
dfa9f0d5
PB
22698 else
22699 {
c921be7d 22700 /* Delayed diagnostic. */
dfa9f0d5
PB
22701 inst.error = BAD_COND;
22702 inst.cond = COND_ALWAYS;
22703 }
c19d1205 22704 return opcode;
b99bd4ef 22705
c19d1205 22706 default:
c921be7d 22707 return NULL;
c19d1205
ZW
22708 }
22709 }
b99bd4ef 22710
c19d1205
ZW
22711 /* Cannot have a usual-position infix on a mnemonic of less than
22712 six characters (five would be a suffix). */
22713 if (end - base < 6)
c921be7d 22714 return NULL;
b99bd4ef 22715
c19d1205
ZW
22716 /* Look for infixed mnemonic in the usual position. */
22717 affix = base + 3;
21d799b5 22718 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 22719 if (!cond)
c921be7d 22720 return NULL;
e3cb604e
PB
22721
22722 memcpy (save, affix, 2);
22723 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 22724 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 22725 (end - base) - 2);
e3cb604e
PB
22726 memmove (affix + 2, affix, (end - affix) - 2);
22727 memcpy (affix, save, 2);
22728
088fa78e
KH
22729 if (opcode
22730 && (opcode->tag == OT_cinfix3
22731 || opcode->tag == OT_cinfix3_deprecated
22732 || opcode->tag == OT_csuf_or_in3
22733 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 22734 {
c921be7d 22735 /* Step CM. */
278df34e 22736 if (warn_on_deprecated && unified_syntax
088fa78e
KH
22737 && (opcode->tag == OT_cinfix3
22738 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 22739 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
22740
22741 inst.cond = cond->value;
22742 return opcode;
b99bd4ef
NC
22743 }
22744
c921be7d 22745 return NULL;
b99bd4ef
NC
22746}
22747
e07e6e58
NC
22748/* This function generates an initial IT instruction, leaving its block
22749 virtually open for the new instructions. Eventually,
5ee91343 22750 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
22751 a new instruction needs to be included in the IT block.
22752 Finally, the block is closed with close_automatic_it_block ().
22753 The block closure can be requested either from md_assemble (),
22754 a tencode (), or due to a label hook. */
22755
22756static void
22757new_automatic_it_block (int cond)
22758{
5ee91343
AV
22759 now_pred.state = AUTOMATIC_PRED_BLOCK;
22760 now_pred.mask = 0x18;
22761 now_pred.cc = cond;
22762 now_pred.block_length = 1;
cd000bff 22763 mapping_state (MAP_THUMB);
5ee91343
AV
22764 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22765 now_pred.warn_deprecated = FALSE;
22766 now_pred.insn_cond = TRUE;
e07e6e58
NC
22767}
22768
22769/* Close an automatic IT block.
22770 See comments in new_automatic_it_block (). */
22771
22772static void
22773close_automatic_it_block (void)
22774{
5ee91343
AV
22775 now_pred.mask = 0x10;
22776 now_pred.block_length = 0;
e07e6e58
NC
22777}
22778
22779/* Update the mask of the current automatically-generated IT
22780 instruction. See comments in new_automatic_it_block (). */
22781
22782static void
5ee91343 22783now_pred_add_mask (int cond)
e07e6e58
NC
22784{
22785#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22786#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 22787 | ((bitvalue) << (nbit)))
e07e6e58 22788 const int resulting_bit = (cond & 1);
c921be7d 22789
5ee91343
AV
22790 now_pred.mask &= 0xf;
22791 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22792 resulting_bit,
5ee91343
AV
22793 (5 - now_pred.block_length));
22794 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22795 1,
5ee91343
AV
22796 ((5 - now_pred.block_length) - 1));
22797 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
22798
22799#undef CLEAR_BIT
22800#undef SET_BIT_VALUE
e07e6e58
NC
22801}
22802
22803/* The IT blocks handling machinery is accessed through the these functions:
22804 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
22805 set_pred_insn_type () optional, from the tencode functions
22806 set_pred_insn_type_last () ditto
22807 in_pred_block () ditto
e07e6e58 22808 it_fsm_post_encode () from md_assemble ()
33eaf5de 22809 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
22810
22811 Rationale:
22812 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
22813 initializing the IT insn type with a generic initial value depending
22814 on the inst.condition.
e07e6e58 22815 2) During the tencode function, two things may happen:
477330fc 22816 a) The tencode function overrides the IT insn type by
5ee91343
AV
22817 calling either set_pred_insn_type (type) or
22818 set_pred_insn_type_last ().
477330fc 22819 b) The tencode function queries the IT block state by
5ee91343 22820 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 22821
5ee91343
AV
22822 Both set_pred_insn_type and in_pred_block run the internal FSM state
22823 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
22824 type may incur in an invalid state (exiting the function),
22825 and b) querying the state requires the FSM to be updated.
22826 Specifically we want to avoid creating an IT block for conditional
22827 branches, so it_fsm_pre_encode is actually a guess and we can't
22828 determine whether an IT block is required until the tencode () routine
22829 has decided what type of instruction this actually it.
5ee91343
AV
22830 Because of this, if set_pred_insn_type and in_pred_block have to be
22831 used, set_pred_insn_type has to be called first.
477330fc 22832
5ee91343
AV
22833 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22834 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
22835 When a tencode () routine encodes an instruction that can be
22836 either outside an IT block, or, in the case of being inside, has to be
5ee91343 22837 the last one, set_pred_insn_type_last () will determine the proper
477330fc 22838 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 22839 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
22840 for covering other cases.
22841
5ee91343
AV
22842 Calling handle_pred_state () may not transition the IT block state to
22843 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 22844 still queried. Instead, if the FSM determines that the state should
5ee91343 22845 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
22846 after the tencode () function: that's what it_fsm_post_encode () does.
22847
5ee91343 22848 Since in_pred_block () calls the state handling function to get an
477330fc
RM
22849 updated state, an error may occur (due to invalid insns combination).
22850 In that case, inst.error is set.
22851 Therefore, inst.error has to be checked after the execution of
22852 the tencode () routine.
e07e6e58
NC
22853
22854 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 22855 any pending state change (if any) that didn't take place in
5ee91343 22856 handle_pred_state () as explained above. */
e07e6e58
NC
22857
22858static void
22859it_fsm_pre_encode (void)
22860{
22861 if (inst.cond != COND_ALWAYS)
5ee91343 22862 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 22863 else
5ee91343 22864 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 22865
5ee91343 22866 now_pred.state_handled = 0;
e07e6e58
NC
22867}
22868
22869/* IT state FSM handling function. */
5ee91343
AV
22870/* MVE instructions and non-MVE instructions are handled differently because of
22871 the introduction of VPT blocks.
22872 Specifications say that any non-MVE instruction inside a VPT block is
22873 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22874 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 22875 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
22876 The error messages provided depending on the different combinations possible
22877 are described in the cases below:
22878 For 'most' MVE instructions:
22879 1) In an IT block, with an IT code: syntax error
22880 2) In an IT block, with a VPT code: error: must be in a VPT block
22881 3) In an IT block, with no code: warning: UNPREDICTABLE
22882 4) In a VPT block, with an IT code: syntax error
22883 5) In a VPT block, with a VPT code: OK!
22884 6) In a VPT block, with no code: error: missing code
22885 7) Outside a pred block, with an IT code: error: syntax error
22886 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22887 9) Outside a pred block, with no code: OK!
22888 For non-MVE instructions:
22889 10) In an IT block, with an IT code: OK!
22890 11) In an IT block, with a VPT code: syntax error
22891 12) In an IT block, with no code: error: missing code
22892 13) In a VPT block, with an IT code: error: should be in an IT block
22893 14) In a VPT block, with a VPT code: syntax error
22894 15) In a VPT block, with no code: UNPREDICTABLE
22895 16) Outside a pred block, with an IT code: error: should be in an IT block
22896 17) Outside a pred block, with a VPT code: syntax error
22897 18) Outside a pred block, with no code: OK!
22898 */
22899
e07e6e58
NC
22900
22901static int
5ee91343 22902handle_pred_state (void)
e07e6e58 22903{
5ee91343
AV
22904 now_pred.state_handled = 1;
22905 now_pred.insn_cond = FALSE;
e07e6e58 22906
5ee91343 22907 switch (now_pred.state)
e07e6e58 22908 {
5ee91343
AV
22909 case OUTSIDE_PRED_BLOCK:
22910 switch (inst.pred_insn_type)
e07e6e58 22911 {
35c228db 22912 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22913 case MVE_OUTSIDE_PRED_INSN:
22914 if (inst.cond < COND_ALWAYS)
22915 {
22916 /* Case 7: Outside a pred block, with an IT code: error: syntax
22917 error. */
22918 inst.error = BAD_SYNTAX;
22919 return FAIL;
22920 }
22921 /* Case 9: Outside a pred block, with no code: OK! */
22922 break;
22923 case OUTSIDE_PRED_INSN:
22924 if (inst.cond > COND_ALWAYS)
22925 {
22926 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22927 */
22928 inst.error = BAD_SYNTAX;
22929 return FAIL;
22930 }
22931 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22932 break;
22933
5ee91343
AV
22934 case INSIDE_VPT_INSN:
22935 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22936 a VPT block. */
22937 inst.error = BAD_OUT_VPT;
22938 return FAIL;
22939
e07e6e58
NC
22940 case INSIDE_IT_INSN:
22941 case INSIDE_IT_LAST_INSN:
5ee91343 22942 if (inst.cond < COND_ALWAYS)
e07e6e58 22943 {
5ee91343
AV
22944 /* Case 16: Outside a pred block, with an IT code: error: should
22945 be in an IT block. */
22946 if (thumb_mode == 0)
e07e6e58 22947 {
5ee91343
AV
22948 if (unified_syntax
22949 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22950 as_tsktsk (_("Warning: conditional outside an IT block"\
22951 " for Thumb."));
e07e6e58
NC
22952 }
22953 else
22954 {
5ee91343
AV
22955 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22956 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22957 {
22958 /* Automatically generate the IT instruction. */
22959 new_automatic_it_block (inst.cond);
22960 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22961 close_automatic_it_block ();
22962 }
22963 else
22964 {
22965 inst.error = BAD_OUT_IT;
22966 return FAIL;
22967 }
e07e6e58 22968 }
5ee91343 22969 break;
e07e6e58 22970 }
5ee91343
AV
22971 else if (inst.cond > COND_ALWAYS)
22972 {
22973 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22974 */
22975 inst.error = BAD_SYNTAX;
22976 return FAIL;
22977 }
22978 else
22979 gas_assert (0);
e07e6e58
NC
22980 case IF_INSIDE_IT_LAST_INSN:
22981 case NEUTRAL_IT_INSN:
22982 break;
22983
5ee91343
AV
22984 case VPT_INSN:
22985 if (inst.cond != COND_ALWAYS)
22986 first_error (BAD_SYNTAX);
22987 now_pred.state = MANUAL_PRED_BLOCK;
22988 now_pred.block_length = 0;
22989 now_pred.type = VECTOR_PRED;
22990 now_pred.cc = 0;
22991 break;
e07e6e58 22992 case IT_INSN:
5ee91343
AV
22993 now_pred.state = MANUAL_PRED_BLOCK;
22994 now_pred.block_length = 0;
22995 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22996 break;
22997 }
22998 break;
22999
5ee91343 23000 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
23001 /* Three things may happen now:
23002 a) We should increment current it block size;
23003 b) We should close current it block (closing insn or 4 insns);
23004 c) We should close current it block and start a new one (due
23005 to incompatible conditions or
23006 4 insns-length block reached). */
23007
5ee91343 23008 switch (inst.pred_insn_type)
e07e6e58 23009 {
5ee91343
AV
23010 case INSIDE_VPT_INSN:
23011 case VPT_INSN:
35c228db 23012 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
23013 case MVE_OUTSIDE_PRED_INSN:
23014 gas_assert (0);
23015 case OUTSIDE_PRED_INSN:
2b0f3761 23016 /* The closure of the block shall happen immediately,
5ee91343 23017 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
23018 force_automatic_it_block_close ();
23019 break;
23020
23021 case INSIDE_IT_INSN:
23022 case INSIDE_IT_LAST_INSN:
23023 case IF_INSIDE_IT_LAST_INSN:
5ee91343 23024 now_pred.block_length++;
e07e6e58 23025
5ee91343
AV
23026 if (now_pred.block_length > 4
23027 || !now_pred_compatible (inst.cond))
e07e6e58
NC
23028 {
23029 force_automatic_it_block_close ();
5ee91343 23030 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
23031 new_automatic_it_block (inst.cond);
23032 }
23033 else
23034 {
5ee91343
AV
23035 now_pred.insn_cond = TRUE;
23036 now_pred_add_mask (inst.cond);
e07e6e58
NC
23037 }
23038
5ee91343
AV
23039 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23040 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23041 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
23042 close_automatic_it_block ();
23043 break;
23044
4934a27c 23045 /* Fallthrough. */
e07e6e58 23046 case NEUTRAL_IT_INSN:
5ee91343
AV
23047 now_pred.block_length++;
23048 now_pred.insn_cond = TRUE;
e07e6e58 23049
5ee91343 23050 if (now_pred.block_length > 4)
e07e6e58
NC
23051 force_automatic_it_block_close ();
23052 else
5ee91343 23053 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
23054 break;
23055
23056 case IT_INSN:
23057 close_automatic_it_block ();
5ee91343 23058 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
23059 break;
23060 }
23061 break;
23062
5ee91343 23063 case MANUAL_PRED_BLOCK:
e07e6e58 23064 {
5ee91343
AV
23065 int cond, is_last;
23066 if (now_pred.type == SCALAR_PRED)
e07e6e58 23067 {
5ee91343
AV
23068 /* Check conditional suffixes. */
23069 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23070 now_pred.mask <<= 1;
23071 now_pred.mask &= 0x1f;
23072 is_last = (now_pred.mask == 0x10);
23073 }
23074 else
23075 {
23076 now_pred.cc ^= (now_pred.mask >> 4);
23077 cond = now_pred.cc + 0xf;
23078 now_pred.mask <<= 1;
23079 now_pred.mask &= 0x1f;
23080 is_last = now_pred.mask == 0x10;
23081 }
23082 now_pred.insn_cond = TRUE;
e07e6e58 23083
5ee91343
AV
23084 switch (inst.pred_insn_type)
23085 {
23086 case OUTSIDE_PRED_INSN:
23087 if (now_pred.type == SCALAR_PRED)
23088 {
23089 if (inst.cond == COND_ALWAYS)
23090 {
23091 /* Case 12: In an IT block, with no code: error: missing
23092 code. */
23093 inst.error = BAD_NOT_IT;
23094 return FAIL;
23095 }
23096 else if (inst.cond > COND_ALWAYS)
23097 {
23098 /* Case 11: In an IT block, with a VPT code: syntax error.
23099 */
23100 inst.error = BAD_SYNTAX;
23101 return FAIL;
23102 }
23103 else if (thumb_mode)
23104 {
23105 /* This is for some special cases where a non-MVE
23106 instruction is not allowed in an IT block, such as cbz,
23107 but are put into one with a condition code.
23108 You could argue this should be a syntax error, but we
23109 gave the 'not allowed in IT block' diagnostic in the
23110 past so we will keep doing so. */
23111 inst.error = BAD_NOT_IT;
23112 return FAIL;
23113 }
23114 break;
23115 }
23116 else
23117 {
23118 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23119 as_tsktsk (MVE_NOT_VPT);
23120 return SUCCESS;
23121 }
23122 case MVE_OUTSIDE_PRED_INSN:
23123 if (now_pred.type == SCALAR_PRED)
23124 {
23125 if (inst.cond == COND_ALWAYS)
23126 {
23127 /* Case 3: In an IT block, with no code: warning:
23128 UNPREDICTABLE. */
23129 as_tsktsk (MVE_NOT_IT);
23130 return SUCCESS;
23131 }
23132 else if (inst.cond < COND_ALWAYS)
23133 {
23134 /* Case 1: In an IT block, with an IT code: syntax error.
23135 */
23136 inst.error = BAD_SYNTAX;
23137 return FAIL;
23138 }
23139 else
23140 gas_assert (0);
23141 }
23142 else
23143 {
23144 if (inst.cond < COND_ALWAYS)
23145 {
23146 /* Case 4: In a VPT block, with an IT code: syntax error.
23147 */
23148 inst.error = BAD_SYNTAX;
23149 return FAIL;
23150 }
23151 else if (inst.cond == COND_ALWAYS)
23152 {
23153 /* Case 6: In a VPT block, with no code: error: missing
23154 code. */
23155 inst.error = BAD_NOT_VPT;
23156 return FAIL;
23157 }
23158 else
23159 {
23160 gas_assert (0);
23161 }
23162 }
35c228db
AV
23163 case MVE_UNPREDICABLE_INSN:
23164 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23165 return SUCCESS;
e07e6e58 23166 case INSIDE_IT_INSN:
5ee91343 23167 if (inst.cond > COND_ALWAYS)
e07e6e58 23168 {
5ee91343
AV
23169 /* Case 11: In an IT block, with a VPT code: syntax error. */
23170 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23171 inst.error = BAD_SYNTAX;
23172 return FAIL;
23173 }
23174 else if (now_pred.type == SCALAR_PRED)
23175 {
23176 /* Case 10: In an IT block, with an IT code: OK! */
23177 if (cond != inst.cond)
23178 {
23179 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23180 BAD_VPT_COND;
23181 return FAIL;
23182 }
23183 }
23184 else
23185 {
23186 /* Case 13: In a VPT block, with an IT code: error: should be
23187 in an IT block. */
23188 inst.error = BAD_OUT_IT;
e07e6e58
NC
23189 return FAIL;
23190 }
23191 break;
23192
5ee91343
AV
23193 case INSIDE_VPT_INSN:
23194 if (now_pred.type == SCALAR_PRED)
23195 {
23196 /* Case 2: In an IT block, with a VPT code: error: must be in a
23197 VPT block. */
23198 inst.error = BAD_OUT_VPT;
23199 return FAIL;
23200 }
23201 /* Case 5: In a VPT block, with a VPT code: OK! */
23202 else if (cond != inst.cond)
23203 {
23204 inst.error = BAD_VPT_COND;
23205 return FAIL;
23206 }
23207 break;
e07e6e58
NC
23208 case INSIDE_IT_LAST_INSN:
23209 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
23210 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23211 {
23212 /* Case 4: In a VPT block, with an IT code: syntax error. */
23213 /* Case 11: In an IT block, with a VPT code: syntax error. */
23214 inst.error = BAD_SYNTAX;
23215 return FAIL;
23216 }
23217 else if (cond != inst.cond)
e07e6e58
NC
23218 {
23219 inst.error = BAD_IT_COND;
23220 return FAIL;
23221 }
23222 if (!is_last)
23223 {
23224 inst.error = BAD_BRANCH;
23225 return FAIL;
23226 }
23227 break;
23228
23229 case NEUTRAL_IT_INSN:
5ee91343
AV
23230 /* The BKPT instruction is unconditional even in a IT or VPT
23231 block. */
e07e6e58
NC
23232 break;
23233
23234 case IT_INSN:
5ee91343
AV
23235 if (now_pred.type == SCALAR_PRED)
23236 {
23237 inst.error = BAD_IT_IT;
23238 return FAIL;
23239 }
23240 /* fall through. */
23241 case VPT_INSN:
23242 if (inst.cond == COND_ALWAYS)
23243 {
23244 /* Executing a VPT/VPST instruction inside an IT block or a
23245 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23246 */
23247 if (now_pred.type == SCALAR_PRED)
23248 as_tsktsk (MVE_NOT_IT);
23249 else
23250 as_tsktsk (MVE_NOT_VPT);
23251 return SUCCESS;
23252 }
23253 else
23254 {
23255 /* VPT/VPST do not accept condition codes. */
23256 inst.error = BAD_SYNTAX;
23257 return FAIL;
23258 }
e07e6e58 23259 }
5ee91343 23260 }
e07e6e58
NC
23261 break;
23262 }
23263
23264 return SUCCESS;
23265}
23266
5a01bb1d
MGD
23267struct depr_insn_mask
23268{
23269 unsigned long pattern;
23270 unsigned long mask;
23271 const char* description;
23272};
23273
23274/* List of 16-bit instruction patterns deprecated in an IT block in
23275 ARMv8. */
23276static const struct depr_insn_mask depr_it_insns[] = {
23277 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23278 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23279 { 0xa000, 0xb800, N_("ADR") },
23280 { 0x4800, 0xf800, N_("Literal loads") },
23281 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23282 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
23283 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23284 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23285 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
23286 { 0, 0, NULL }
23287};
23288
e07e6e58
NC
23289static void
23290it_fsm_post_encode (void)
23291{
23292 int is_last;
23293
5ee91343
AV
23294 if (!now_pred.state_handled)
23295 handle_pred_state ();
e07e6e58 23296
5ee91343 23297 if (now_pred.insn_cond
24f19ccb 23298 && warn_on_restrict_it
5ee91343 23299 && !now_pred.warn_deprecated
5a01bb1d 23300 && warn_on_deprecated
df9909b8
TP
23301 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23302 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
23303 {
23304 if (inst.instruction >= 0x10000)
23305 {
5c3696f8 23306 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 23307 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 23308 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23309 }
23310 else
23311 {
23312 const struct depr_insn_mask *p = depr_it_insns;
23313
23314 while (p->mask != 0)
23315 {
23316 if ((inst.instruction & p->mask) == p->pattern)
23317 {
df9909b8
TP
23318 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23319 "instructions of the following class are "
23320 "performance deprecated in ARMv8-A and "
23321 "ARMv8-R: %s"), p->description);
5ee91343 23322 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23323 break;
23324 }
23325
23326 ++p;
23327 }
23328 }
23329
5ee91343 23330 if (now_pred.block_length > 1)
5a01bb1d 23331 {
5c3696f8 23332 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
23333 "instruction are performance deprecated in ARMv8-A and "
23334 "ARMv8-R"));
5ee91343 23335 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23336 }
23337 }
23338
5ee91343
AV
23339 is_last = (now_pred.mask == 0x10);
23340 if (is_last)
23341 {
23342 now_pred.state = OUTSIDE_PRED_BLOCK;
23343 now_pred.mask = 0;
23344 }
e07e6e58
NC
23345}
23346
23347static void
23348force_automatic_it_block_close (void)
23349{
5ee91343 23350 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
23351 {
23352 close_automatic_it_block ();
5ee91343
AV
23353 now_pred.state = OUTSIDE_PRED_BLOCK;
23354 now_pred.mask = 0;
e07e6e58
NC
23355 }
23356}
23357
23358static int
5ee91343 23359in_pred_block (void)
e07e6e58 23360{
5ee91343
AV
23361 if (!now_pred.state_handled)
23362 handle_pred_state ();
e07e6e58 23363
5ee91343 23364 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
23365}
23366
ff8646ee
TP
23367/* Whether OPCODE only has T32 encoding. Since this function is only used by
23368 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23369 here, hence the "known" in the function name. */
fc289b0a
TP
23370
23371static bfd_boolean
ff8646ee 23372known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
23373{
23374 /* Original Thumb-1 wide instruction. */
23375 if (opcode->tencode == do_t_blx
23376 || opcode->tencode == do_t_branch23
23377 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23378 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23379 return TRUE;
23380
16a1fa25
TP
23381 /* Wide-only instruction added to ARMv8-M Baseline. */
23382 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
23383 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23384 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23385 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23386 return TRUE;
23387
23388 return FALSE;
23389}
23390
23391/* Whether wide instruction variant can be used if available for a valid OPCODE
23392 in ARCH. */
23393
23394static bfd_boolean
23395t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23396{
23397 if (known_t32_only_insn (opcode))
23398 return TRUE;
23399
23400 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23401 of variant T3 of B.W is checked in do_t_branch. */
23402 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23403 && opcode->tencode == do_t_branch)
23404 return TRUE;
23405
bada4342
JW
23406 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23407 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23408 && opcode->tencode == do_t_mov_cmp
23409 /* Make sure CMP instruction is not affected. */
23410 && opcode->aencode == do_mov)
23411 return TRUE;
23412
ff8646ee
TP
23413 /* Wide instruction variants of all instructions with narrow *and* wide
23414 variants become available with ARMv6t2. Other opcodes are either
23415 narrow-only or wide-only and are thus available if OPCODE is valid. */
23416 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23417 return TRUE;
23418
23419 /* OPCODE with narrow only instruction variant or wide variant not
23420 available. */
fc289b0a
TP
23421 return FALSE;
23422}
23423
c19d1205
ZW
23424void
23425md_assemble (char *str)
b99bd4ef 23426{
c19d1205
ZW
23427 char *p = str;
23428 const struct asm_opcode * opcode;
b99bd4ef 23429
c19d1205
ZW
23430 /* Align the previous label if needed. */
23431 if (last_label_seen != NULL)
b99bd4ef 23432 {
c19d1205
ZW
23433 symbol_set_frag (last_label_seen, frag_now);
23434 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23435 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
23436 }
23437
c19d1205 23438 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
23439 int r;
23440 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23441 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 23442
c19d1205
ZW
23443 opcode = opcode_lookup (&p);
23444 if (!opcode)
b99bd4ef 23445 {
c19d1205 23446 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 23447 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 23448 if (! create_register_alias (str, p)
477330fc 23449 && ! create_neon_reg_alias (str, p))
c19d1205 23450 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 23451
b99bd4ef
NC
23452 return;
23453 }
23454
278df34e 23455 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 23456 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 23457
037e8744
JB
23458 /* The value which unconditional instructions should have in place of the
23459 condition field. */
23460 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
23461
c19d1205 23462 if (thumb_mode)
b99bd4ef 23463 {
e74cfd16 23464 arm_feature_set variant;
8f06b2d8
PB
23465
23466 variant = cpu_variant;
23467 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
23468 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23469 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 23470 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
23471 if (!opcode->tvariant
23472 || (thumb_mode == 1
23473 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 23474 {
173205ca
TP
23475 if (opcode->tencode == do_t_swi)
23476 as_bad (_("SVC is not permitted on this architecture"));
23477 else
23478 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
23479 return;
23480 }
c19d1205
ZW
23481 if (inst.cond != COND_ALWAYS && !unified_syntax
23482 && opcode->tencode != do_t_branch)
b99bd4ef 23483 {
c19d1205 23484 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
23485 return;
23486 }
23487
fc289b0a
TP
23488 /* Two things are addressed here:
23489 1) Implicit require narrow instructions on Thumb-1.
23490 This avoids relaxation accidentally introducing Thumb-2
23491 instructions.
23492 2) Reject wide instructions in non Thumb-2 cores.
23493
23494 Only instructions with narrow and wide variants need to be handled
23495 but selecting all non wide-only instructions is easier. */
23496 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 23497 && !t32_insn_ok (variant, opcode))
076d447c 23498 {
fc289b0a
TP
23499 if (inst.size_req == 0)
23500 inst.size_req = 2;
23501 else if (inst.size_req == 4)
752d5da4 23502 {
ff8646ee
TP
23503 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23504 as_bad (_("selected processor does not support 32bit wide "
23505 "variant of instruction `%s'"), str);
23506 else
23507 as_bad (_("selected processor does not support `%s' in "
23508 "Thumb-2 mode"), str);
fc289b0a 23509 return;
752d5da4 23510 }
076d447c
PB
23511 }
23512
c19d1205
ZW
23513 inst.instruction = opcode->tvalue;
23514
5be8be5d 23515 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 23516 {
5ee91343 23517 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
23518 it. */
23519 it_fsm_pre_encode ();
c19d1205 23520
477330fc 23521 opcode->tencode ();
e07e6e58 23522
477330fc
RM
23523 it_fsm_post_encode ();
23524 }
e27ec89e 23525
0110f2b8 23526 if (!(inst.error || inst.relax))
b99bd4ef 23527 {
9c2799c2 23528 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
23529 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23530 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 23531 {
c19d1205 23532 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
23533 return;
23534 }
23535 }
076d447c
PB
23536
23537 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 23538 instruction. */
9c2799c2 23539 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 23540
e74cfd16
PB
23541 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23542 *opcode->tvariant);
ee065d83 23543 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
23544 set those bits when Thumb-2 32-bit instructions are seen. The impact
23545 of relaxable instructions will be considered later after we finish all
23546 relaxation. */
ff8646ee
TP
23547 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23548 variant = arm_arch_none;
23549 else
23550 variant = cpu_variant;
23551 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
23552 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23553 arm_ext_v6t2);
cd000bff 23554
88714cb8
DG
23555 check_neon_suffixes;
23556
cd000bff 23557 if (!inst.error)
c877a2f2
NC
23558 {
23559 mapping_state (MAP_THUMB);
23560 }
c19d1205 23561 }
3e9e4fcf 23562 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 23563 {
845b51d6
PB
23564 bfd_boolean is_bx;
23565
23566 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23567 is_bx = (opcode->aencode == do_bx);
23568
c19d1205 23569 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
23570 if (!(is_bx && fix_v4bx)
23571 && !(opcode->avariant &&
23572 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 23573 {
84b52b66 23574 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 23575 return;
b99bd4ef 23576 }
c19d1205 23577 if (inst.size_req)
b99bd4ef 23578 {
c19d1205
ZW
23579 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23580 return;
b99bd4ef
NC
23581 }
23582
c19d1205
ZW
23583 inst.instruction = opcode->avalue;
23584 if (opcode->tag == OT_unconditionalF)
eff0bc54 23585 inst.instruction |= 0xFU << 28;
c19d1205
ZW
23586 else
23587 inst.instruction |= inst.cond << 28;
23588 inst.size = INSN_SIZE;
5be8be5d 23589 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
23590 {
23591 it_fsm_pre_encode ();
23592 opcode->aencode ();
23593 it_fsm_post_encode ();
23594 }
ee065d83 23595 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 23596 on a hypothetical non-thumb v5 core. */
845b51d6 23597 if (is_bx)
e74cfd16 23598 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 23599 else
e74cfd16
PB
23600 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23601 *opcode->avariant);
88714cb8
DG
23602
23603 check_neon_suffixes;
23604
cd000bff 23605 if (!inst.error)
c877a2f2
NC
23606 {
23607 mapping_state (MAP_ARM);
23608 }
b99bd4ef 23609 }
3e9e4fcf
JB
23610 else
23611 {
23612 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23613 "-- `%s'"), str);
23614 return;
23615 }
c19d1205
ZW
23616 output_inst (str);
23617}
b99bd4ef 23618
e07e6e58 23619static void
5ee91343 23620check_pred_blocks_finished (void)
e07e6e58
NC
23621{
23622#ifdef OBJ_ELF
23623 asection *sect;
23624
23625 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
23626 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23627 == MANUAL_PRED_BLOCK)
e07e6e58 23628 {
5ee91343
AV
23629 if (now_pred.type == SCALAR_PRED)
23630 as_warn (_("section '%s' finished with an open IT block."),
23631 sect->name);
23632 else
23633 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23634 sect->name);
e07e6e58
NC
23635 }
23636#else
5ee91343
AV
23637 if (now_pred.state == MANUAL_PRED_BLOCK)
23638 {
23639 if (now_pred.type == SCALAR_PRED)
23640 as_warn (_("file finished with an open IT block."));
23641 else
23642 as_warn (_("file finished with an open VPT/VPST block."));
23643 }
e07e6e58
NC
23644#endif
23645}
23646
c19d1205
ZW
23647/* Various frobbings of labels and their addresses. */
23648
23649void
23650arm_start_line_hook (void)
23651{
23652 last_label_seen = NULL;
b99bd4ef
NC
23653}
23654
c19d1205
ZW
23655void
23656arm_frob_label (symbolS * sym)
b99bd4ef 23657{
c19d1205 23658 last_label_seen = sym;
b99bd4ef 23659
c19d1205 23660 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 23661
c19d1205
ZW
23662#if defined OBJ_COFF || defined OBJ_ELF
23663 ARM_SET_INTERWORK (sym, support_interwork);
23664#endif
b99bd4ef 23665
e07e6e58
NC
23666 force_automatic_it_block_close ();
23667
5f4273c7 23668 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
23669 as Thumb functions. This is because these labels, whilst
23670 they exist inside Thumb code, are not the entry points for
23671 possible ARM->Thumb calls. Also, these labels can be used
23672 as part of a computed goto or switch statement. eg gcc
23673 can generate code that looks like this:
b99bd4ef 23674
c19d1205
ZW
23675 ldr r2, [pc, .Laaa]
23676 lsl r3, r3, #2
23677 ldr r2, [r3, r2]
23678 mov pc, r2
b99bd4ef 23679
c19d1205
ZW
23680 .Lbbb: .word .Lxxx
23681 .Lccc: .word .Lyyy
23682 ..etc...
23683 .Laaa: .word Lbbb
b99bd4ef 23684
c19d1205
ZW
23685 The first instruction loads the address of the jump table.
23686 The second instruction converts a table index into a byte offset.
23687 The third instruction gets the jump address out of the table.
23688 The fourth instruction performs the jump.
b99bd4ef 23689
c19d1205
ZW
23690 If the address stored at .Laaa is that of a symbol which has the
23691 Thumb_Func bit set, then the linker will arrange for this address
23692 to have the bottom bit set, which in turn would mean that the
23693 address computation performed by the third instruction would end
23694 up with the bottom bit set. Since the ARM is capable of unaligned
23695 word loads, the instruction would then load the incorrect address
23696 out of the jump table, and chaos would ensue. */
23697 if (label_is_thumb_function_name
23698 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
fd361982 23699 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
b99bd4ef 23700 {
c19d1205
ZW
23701 /* When the address of a Thumb function is taken the bottom
23702 bit of that address should be set. This will allow
23703 interworking between Arm and Thumb functions to work
23704 correctly. */
b99bd4ef 23705
c19d1205 23706 THUMB_SET_FUNC (sym, 1);
b99bd4ef 23707
c19d1205 23708 label_is_thumb_function_name = FALSE;
b99bd4ef 23709 }
07a53e5c 23710
07a53e5c 23711 dwarf2_emit_label (sym);
b99bd4ef
NC
23712}
23713
c921be7d 23714bfd_boolean
c19d1205 23715arm_data_in_code (void)
b99bd4ef 23716{
c19d1205 23717 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 23718 {
c19d1205
ZW
23719 *input_line_pointer = '/';
23720 input_line_pointer += 5;
23721 *input_line_pointer = 0;
c921be7d 23722 return TRUE;
b99bd4ef
NC
23723 }
23724
c921be7d 23725 return FALSE;
b99bd4ef
NC
23726}
23727
c19d1205
ZW
23728char *
23729arm_canonicalize_symbol_name (char * name)
b99bd4ef 23730{
c19d1205 23731 int len;
b99bd4ef 23732
c19d1205
ZW
23733 if (thumb_mode && (len = strlen (name)) > 5
23734 && streq (name + len - 5, "/data"))
23735 *(name + len - 5) = 0;
b99bd4ef 23736
c19d1205 23737 return name;
b99bd4ef 23738}
c19d1205
ZW
23739\f
23740/* Table of all register names defined by default. The user can
23741 define additional names with .req. Note that all register names
23742 should appear in both upper and lowercase variants. Some registers
23743 also have mixed-case names. */
b99bd4ef 23744
dcbf9037 23745#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 23746#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 23747#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
23748#define REGSET(p,t) \
23749 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23750 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23751 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23752 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
23753#define REGSETH(p,t) \
23754 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23755 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23756 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23757 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23758#define REGSET2(p,t) \
23759 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23760 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23761 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23762 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
23763#define SPLRBANK(base,bank,t) \
23764 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23765 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23766 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23767 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23768 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23769 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 23770
c19d1205 23771static const struct reg_entry reg_names[] =
7ed4c4c5 23772{
c19d1205
ZW
23773 /* ARM integer registers. */
23774 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 23775
c19d1205
ZW
23776 /* ATPCS synonyms. */
23777 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23778 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23779 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 23780
c19d1205
ZW
23781 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23782 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23783 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 23784
c19d1205
ZW
23785 /* Well-known aliases. */
23786 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23787 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23788
23789 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23790 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23791
1b883319
AV
23792 /* Defining the new Zero register from ARMv8.1-M. */
23793 REGDEF(zr,15,ZR),
23794 REGDEF(ZR,15,ZR),
23795
c19d1205
ZW
23796 /* Coprocessor numbers. */
23797 REGSET(p, CP), REGSET(P, CP),
23798
23799 /* Coprocessor register numbers. The "cr" variants are for backward
23800 compatibility. */
23801 REGSET(c, CN), REGSET(C, CN),
23802 REGSET(cr, CN), REGSET(CR, CN),
23803
90ec0d68
MGD
23804 /* ARM banked registers. */
23805 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23806 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23807 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23808 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23809 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23810 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23811 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23812
23813 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23814 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23815 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23816 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23817 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 23818 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
23819 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23820 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23821
23822 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23823 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23824 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23825 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23826 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23827 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23828 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 23829 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
23830 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23831
c19d1205
ZW
23832 /* FPA registers. */
23833 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23834 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23835
23836 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23837 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23838
23839 /* VFP SP registers. */
5287ad62
JB
23840 REGSET(s,VFS), REGSET(S,VFS),
23841 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
23842
23843 /* VFP DP Registers. */
5287ad62
JB
23844 REGSET(d,VFD), REGSET(D,VFD),
23845 /* Extra Neon DP registers. */
23846 REGSETH(d,VFD), REGSETH(D,VFD),
23847
23848 /* Neon QP registers. */
23849 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
23850
23851 /* VFP control registers. */
23852 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23853 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
23854 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23855 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23856 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23857 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 23858 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
23859 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23860 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23861 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23862 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
23863
23864 /* Maverick DSP coprocessor registers. */
23865 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23866 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23867
23868 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23869 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23870 REGDEF(dspsc,0,DSPSC),
23871
23872 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23873 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23874 REGDEF(DSPSC,0,DSPSC),
23875
23876 /* iWMMXt data registers - p0, c0-15. */
23877 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23878
23879 /* iWMMXt control registers - p1, c0-3. */
23880 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23881 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23882 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23883 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23884
23885 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23886 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23887 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23888 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23889 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23890
23891 /* XScale accumulator registers. */
23892 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23893};
23894#undef REGDEF
23895#undef REGNUM
23896#undef REGSET
7ed4c4c5 23897
c19d1205
ZW
23898/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23899 within psr_required_here. */
23900static const struct asm_psr psrs[] =
23901{
23902 /* Backward compatibility notation. Note that "all" is no longer
23903 truly all possible PSR bits. */
23904 {"all", PSR_c | PSR_f},
23905 {"flg", PSR_f},
23906 {"ctl", PSR_c},
23907
23908 /* Individual flags. */
23909 {"f", PSR_f},
23910 {"c", PSR_c},
23911 {"x", PSR_x},
23912 {"s", PSR_s},
59b42a0d 23913
c19d1205
ZW
23914 /* Combinations of flags. */
23915 {"fs", PSR_f | PSR_s},
23916 {"fx", PSR_f | PSR_x},
23917 {"fc", PSR_f | PSR_c},
23918 {"sf", PSR_s | PSR_f},
23919 {"sx", PSR_s | PSR_x},
23920 {"sc", PSR_s | PSR_c},
23921 {"xf", PSR_x | PSR_f},
23922 {"xs", PSR_x | PSR_s},
23923 {"xc", PSR_x | PSR_c},
23924 {"cf", PSR_c | PSR_f},
23925 {"cs", PSR_c | PSR_s},
23926 {"cx", PSR_c | PSR_x},
23927 {"fsx", PSR_f | PSR_s | PSR_x},
23928 {"fsc", PSR_f | PSR_s | PSR_c},
23929 {"fxs", PSR_f | PSR_x | PSR_s},
23930 {"fxc", PSR_f | PSR_x | PSR_c},
23931 {"fcs", PSR_f | PSR_c | PSR_s},
23932 {"fcx", PSR_f | PSR_c | PSR_x},
23933 {"sfx", PSR_s | PSR_f | PSR_x},
23934 {"sfc", PSR_s | PSR_f | PSR_c},
23935 {"sxf", PSR_s | PSR_x | PSR_f},
23936 {"sxc", PSR_s | PSR_x | PSR_c},
23937 {"scf", PSR_s | PSR_c | PSR_f},
23938 {"scx", PSR_s | PSR_c | PSR_x},
23939 {"xfs", PSR_x | PSR_f | PSR_s},
23940 {"xfc", PSR_x | PSR_f | PSR_c},
23941 {"xsf", PSR_x | PSR_s | PSR_f},
23942 {"xsc", PSR_x | PSR_s | PSR_c},
23943 {"xcf", PSR_x | PSR_c | PSR_f},
23944 {"xcs", PSR_x | PSR_c | PSR_s},
23945 {"cfs", PSR_c | PSR_f | PSR_s},
23946 {"cfx", PSR_c | PSR_f | PSR_x},
23947 {"csf", PSR_c | PSR_s | PSR_f},
23948 {"csx", PSR_c | PSR_s | PSR_x},
23949 {"cxf", PSR_c | PSR_x | PSR_f},
23950 {"cxs", PSR_c | PSR_x | PSR_s},
23951 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23952 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23953 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23954 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23955 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23956 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23957 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23958 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23959 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23960 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23961 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23962 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23963 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23964 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23965 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23966 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23967 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23968 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23969 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23970 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23971 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23972 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23973 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23974 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23975};
23976
62b3e311
PB
23977/* Table of V7M psr names. */
23978static const struct asm_psr v7m_psrs[] =
23979{
1a336194
TP
23980 {"apsr", 0x0 }, {"APSR", 0x0 },
23981 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23982 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23983 {"psr", 0x3 }, {"PSR", 0x3 },
23984 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23985 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23986 {"epsr", 0x6 }, {"EPSR", 0x6 },
23987 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23988 {"msp", 0x8 }, {"MSP", 0x8 },
23989 {"psp", 0x9 }, {"PSP", 0x9 },
23990 {"msplim", 0xa }, {"MSPLIM", 0xa },
23991 {"psplim", 0xb }, {"PSPLIM", 0xb },
23992 {"primask", 0x10}, {"PRIMASK", 0x10},
23993 {"basepri", 0x11}, {"BASEPRI", 0x11},
23994 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
23995 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23996 {"control", 0x14}, {"CONTROL", 0x14},
23997 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23998 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23999 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24000 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24001 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24002 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24003 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24004 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24005 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
24006};
24007
c19d1205
ZW
24008/* Table of all shift-in-operand names. */
24009static const struct asm_shift_name shift_names [] =
b99bd4ef 24010{
c19d1205
ZW
24011 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24012 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24013 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24014 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24015 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
24016 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24017 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 24018};
b99bd4ef 24019
c19d1205
ZW
24020/* Table of all explicit relocation names. */
24021#ifdef OBJ_ELF
24022static struct reloc_entry reloc_names[] =
24023{
24024 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24025 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24026 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24027 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24028 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24029 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24030 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24031 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24032 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24033 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 24034 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
24035 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24036 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 24037 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 24038 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 24039 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 24040 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
24041 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24042 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24043 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24044 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24045 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24046 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
24047 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24048 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24049 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24050 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
24051};
24052#endif
b99bd4ef 24053
5ee91343 24054/* Table of all conditional affixes. */
c19d1205
ZW
24055static const struct asm_cond conds[] =
24056{
24057 {"eq", 0x0},
24058 {"ne", 0x1},
24059 {"cs", 0x2}, {"hs", 0x2},
24060 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24061 {"mi", 0x4},
24062 {"pl", 0x5},
24063 {"vs", 0x6},
24064 {"vc", 0x7},
24065 {"hi", 0x8},
24066 {"ls", 0x9},
24067 {"ge", 0xa},
24068 {"lt", 0xb},
24069 {"gt", 0xc},
24070 {"le", 0xd},
24071 {"al", 0xe}
24072};
5ee91343
AV
24073static const struct asm_cond vconds[] =
24074{
24075 {"t", 0xf},
24076 {"e", 0x10}
24077};
bfae80f2 24078
e797f7e0 24079#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
24080 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24081 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 24082
62b3e311
PB
24083static struct asm_barrier_opt barrier_opt_names[] =
24084{
e797f7e0
MGD
24085 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24086 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24087 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24088 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24089 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24090 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24091 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24092 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24093 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24094 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24095 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24096 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24097 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24098 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24099 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24100 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
24101};
24102
e797f7e0
MGD
24103#undef UL_BARRIER
24104
c19d1205
ZW
24105/* Table of ARM-format instructions. */
24106
24107/* Macros for gluing together operand strings. N.B. In all cases
24108 other than OPS0, the trailing OP_stop comes from default
24109 zero-initialization of the unspecified elements of the array. */
24110#define OPS0() { OP_stop, }
24111#define OPS1(a) { OP_##a, }
24112#define OPS2(a,b) { OP_##a,OP_##b, }
24113#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24114#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24115#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24116#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24117
5be8be5d
DG
24118/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24119 This is useful when mixing operands for ARM and THUMB, i.e. using the
24120 MIX_ARM_THUMB_OPERANDS macro.
24121 In order to use these macros, prefix the number of operands with _
24122 e.g. _3. */
24123#define OPS_1(a) { a, }
24124#define OPS_2(a,b) { a,b, }
24125#define OPS_3(a,b,c) { a,b,c, }
24126#define OPS_4(a,b,c,d) { a,b,c,d, }
24127#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24128#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24129
c19d1205
ZW
24130/* These macros abstract out the exact format of the mnemonic table and
24131 save some repeated characters. */
24132
24133/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24134#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24135 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 24136 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24137
24138/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24139 a T_MNEM_xyz enumerator. */
24140#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24141 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24142#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24143 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
24144
24145/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24146 infix after the third character. */
24147#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 24148 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 24149 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 24150#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 24151 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 24152 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24153#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24154 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 24155#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24156 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24157#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24158 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 24159#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24160 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 24161
c19d1205 24162/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
24163 field is still 0xE. Many of the Thumb variants can be executed
24164 conditionally, so this is checked separately. */
c19d1205 24165#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24166 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24167 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24168
dd5181d5
KT
24169/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24170 Used by mnemonics that have very minimal differences in the encoding for
24171 ARM and Thumb variants and can be handled in a common function. */
24172#define TUEc(mnem, op, top, nops, ops, en) \
24173 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24174 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 24175
c19d1205
ZW
24176/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24177 condition code field. */
24178#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 24179 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24180 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24181
24182/* ARM-only variants of all the above. */
6a86118a 24183#define CE(mnem, op, nops, ops, ae) \
5ee91343 24184 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24185
24186#define C3(mnem, op, nops, ops, ae) \
5ee91343 24187 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24188
cf3cf39d
TP
24189/* Thumb-only variants of TCE and TUE. */
24190#define ToC(mnem, top, nops, ops, te) \
24191 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24192 do_##te, 0 }
cf3cf39d
TP
24193
24194#define ToU(mnem, top, nops, ops, te) \
24195 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 24196 NULL, do_##te, 0 }
cf3cf39d 24197
4389b29a
AV
24198/* T_MNEM_xyz enumerator variants of ToC. */
24199#define toC(mnem, top, nops, ops, te) \
24200 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24201 do_##te, 0 }
4389b29a 24202
f6b2b12d
AV
24203/* T_MNEM_xyz enumerator variants of ToU. */
24204#define toU(mnem, top, nops, ops, te) \
24205 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 24206 NULL, do_##te, 0 }
f6b2b12d 24207
e3cb604e
PB
24208/* Legacy mnemonics that always have conditional infix after the third
24209 character. */
24210#define CL(mnem, op, nops, ops, ae) \
21d799b5 24211 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24212 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 24213
8f06b2d8
PB
24214/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24215#define cCE(mnem, op, nops, ops, ae) \
5ee91343 24216 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24217
57785aa2
AV
24218/* mov instructions that are shared between coprocessor and MVE. */
24219#define mcCE(mnem, op, nops, ops, ae) \
24220 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24221
e3cb604e
PB
24222/* Legacy coprocessor instructions where conditional infix and conditional
24223 suffix are ambiguous. For consistency this includes all FPA instructions,
24224 not just the potentially ambiguous ones. */
24225#define cCL(mnem, op, nops, ops, ae) \
21d799b5 24226 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24227 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
24228
24229/* Coprocessor, takes either a suffix or a position-3 infix
24230 (for an FPA corner case). */
24231#define C3E(mnem, op, nops, ops, ae) \
21d799b5 24232 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 24233 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24234
6a86118a 24235#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
24236 { m1 #m2 m3, OPS##nops ops, \
24237 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 24238 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24239
24240#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
24241 xCM_ (m1, , m2, op, nops, ops, ae), \
24242 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24243 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24244 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24245 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24246 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24247 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24248 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24249 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24250 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24251 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24252 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24253 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24254 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24255 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24256 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24257 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24258 xCM_ (m1, le, m2, op, nops, ops, ae), \
24259 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
24260
24261#define UE(mnem, op, nops, ops, ae) \
5ee91343 24262 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24263
24264#define UF(mnem, op, nops, ops, ae) \
5ee91343 24265 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24266
5287ad62
JB
24267/* Neon data-processing. ARM versions are unconditional with cond=0xf.
24268 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24269 use the same encoding function for each. */
24270#define NUF(mnem, op, nops, ops, enc) \
24271 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 24272 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24273
24274/* Neon data processing, version which indirects through neon_enc_tab for
24275 the various overloaded versions of opcodes. */
24276#define nUF(mnem, op, nops, ops, enc) \
21d799b5 24277 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 24278 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24279
24280/* Neon insn with conditional suffix for the ARM version, non-overloaded
24281 version. */
5ee91343 24282#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 24283 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 24284 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24285
037e8744 24286#define NCE(mnem, op, nops, ops, enc) \
5ee91343 24287 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24288
24289#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 24290 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 24291
5287ad62 24292/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 24293#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 24294 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 24295 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24296
037e8744 24297#define nCE(mnem, op, nops, ops, enc) \
5ee91343 24298 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24299
24300#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
24301 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24302
24303/* */
24304#define mCEF(mnem, op, nops, ops, enc) \
a302e574 24305 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
24306 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24307
24308
24309/* nCEF but for MVE predicated instructions. */
24310#define mnCEF(mnem, op, nops, ops, enc) \
24311 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24312
24313/* nCE but for MVE predicated instructions. */
24314#define mnCE(mnem, op, nops, ops, enc) \
24315 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 24316
5ee91343
AV
24317/* NUF but for potentially MVE predicated instructions. */
24318#define MNUF(mnem, op, nops, ops, enc) \
24319 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24320 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24321
24322/* nUF but for potentially MVE predicated instructions. */
24323#define mnUF(mnem, op, nops, ops, enc) \
24324 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24325 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24326
24327/* ToC but for potentially MVE predicated instructions. */
24328#define mToC(mnem, top, nops, ops, te) \
24329 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24330 do_##te, 1 }
24331
24332/* NCE but for MVE predicated instructions. */
24333#define MNCE(mnem, op, nops, ops, enc) \
24334 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24335
24336/* NCEF but for MVE predicated instructions. */
24337#define MNCEF(mnem, op, nops, ops, enc) \
24338 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
24339#define do_0 0
24340
c19d1205 24341static const struct asm_opcode insns[] =
bfae80f2 24342{
74db7efb
NC
24343#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24344#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
24345 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24346 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24347 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24348 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24349 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24350 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24351 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24352 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24353 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24354 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24355 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24356 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24357 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24358 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24359 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24360 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
24361
24362 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24363 for setting PSR flag bits. They are obsolete in V6 and do not
24364 have Thumb equivalents. */
21d799b5
NC
24365 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24366 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24367 CL("tstp", 110f000, 2, (RR, SH), cmp),
24368 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24369 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24370 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24371 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24372 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24373 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24374
24375 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 24376 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
24377 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24378 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24379
24380 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
24381 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24382 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24383 OP_RRnpc),
24384 OP_ADDRGLDR),ldst, t_ldst),
24385 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
24386
24387 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24388 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24389 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24390 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24391 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24392 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24393
21d799b5
NC
24394 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24395 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 24396
c19d1205 24397 /* Pseudo ops. */
21d799b5 24398 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 24399 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 24400 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 24401 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
24402
24403 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
24404 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24405 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24406 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24407 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24408 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24409 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24410 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24411 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24412 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24413 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24414 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24415 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 24416
16a4cf17 24417 /* These may simplify to neg. */
21d799b5
NC
24418 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24419 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 24420
173205ca
TP
24421#undef THUMB_VARIANT
24422#define THUMB_VARIANT & arm_ext_os
24423
24424 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24425 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24426
c921be7d
NC
24427#undef THUMB_VARIANT
24428#define THUMB_VARIANT & arm_ext_v6
24429
21d799b5 24430 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
24431
24432 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
24433#undef THUMB_VARIANT
24434#define THUMB_VARIANT & arm_ext_v6t2
24435
21d799b5
NC
24436 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24437 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24438 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 24439
5be8be5d
DG
24440 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24441 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24442 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24443 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 24444
21d799b5
NC
24445 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24446 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 24447
21d799b5
NC
24448 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24449 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
24450
24451 /* V1 instructions with no Thumb analogue at all. */
21d799b5 24452 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
24453 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24454
24455 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24456 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24457 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24458 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24459 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24460 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24461 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24462 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24463
c921be7d
NC
24464#undef ARM_VARIANT
24465#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24466#undef THUMB_VARIANT
24467#define THUMB_VARIANT & arm_ext_v4t
24468
21d799b5
NC
24469 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24470 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 24471
c921be7d
NC
24472#undef THUMB_VARIANT
24473#define THUMB_VARIANT & arm_ext_v6t2
24474
21d799b5 24475 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
24476 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24477
24478 /* Generic coprocessor instructions. */
21d799b5
NC
24479 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24480 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24481 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24482 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24483 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24484 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 24485 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24486
c921be7d
NC
24487#undef ARM_VARIANT
24488#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24489
21d799b5 24490 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
24491 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24492
c921be7d
NC
24493#undef ARM_VARIANT
24494#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24495#undef THUMB_VARIANT
24496#define THUMB_VARIANT & arm_ext_msr
24497
d2cd1205
JB
24498 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24499 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 24500
c921be7d
NC
24501#undef ARM_VARIANT
24502#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24503#undef THUMB_VARIANT
24504#define THUMB_VARIANT & arm_ext_v6t2
24505
21d799b5
NC
24506 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24507 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24508 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24509 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24510 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24511 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24512 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24513 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 24514
c921be7d
NC
24515#undef ARM_VARIANT
24516#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24517#undef THUMB_VARIANT
24518#define THUMB_VARIANT & arm_ext_v4t
24519
5be8be5d
DG
24520 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24521 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24522 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24523 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
24524 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24525 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 24526
c921be7d
NC
24527#undef ARM_VARIANT
24528#define ARM_VARIANT & arm_ext_v4t_5
24529
c19d1205
ZW
24530 /* ARM Architecture 4T. */
24531 /* Note: bx (and blx) are required on V5, even if the processor does
24532 not support Thumb. */
21d799b5 24533 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 24534
c921be7d
NC
24535#undef ARM_VARIANT
24536#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24537#undef THUMB_VARIANT
24538#define THUMB_VARIANT & arm_ext_v5t
24539
c19d1205
ZW
24540 /* Note: blx has 2 variants; the .value coded here is for
24541 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
24542 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24543 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 24544
c921be7d
NC
24545#undef THUMB_VARIANT
24546#define THUMB_VARIANT & arm_ext_v6t2
24547
21d799b5
NC
24548 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24549 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24550 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24551 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24552 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24553 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24554 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24555 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24556
c921be7d 24557#undef ARM_VARIANT
74db7efb
NC
24558#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24559#undef THUMB_VARIANT
24560#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 24561
21d799b5
NC
24562 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24563 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24564 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24565 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24566
21d799b5
NC
24567 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24568 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24569
21d799b5
NC
24570 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24571 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24572 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24573 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 24574
21d799b5
NC
24575 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24576 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24577 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24578 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24579
21d799b5
NC
24580 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24581 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24582
03ee1b7f
NC
24583 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24584 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24585 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24586 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 24587
c921be7d 24588#undef ARM_VARIANT
74db7efb
NC
24589#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24590#undef THUMB_VARIANT
24591#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24592
21d799b5 24593 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
24594 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24595 ldrd, t_ldstd),
24596 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24597 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 24598
21d799b5
NC
24599 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24600 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 24601
c921be7d
NC
24602#undef ARM_VARIANT
24603#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24604
21d799b5 24605 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 24606
c921be7d
NC
24607#undef ARM_VARIANT
24608#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24609#undef THUMB_VARIANT
24610#define THUMB_VARIANT & arm_ext_v6
24611
21d799b5
NC
24612 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24613 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24614 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24615 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24616 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24617 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24618 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24619 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24620 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24621 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 24622
c921be7d 24623#undef THUMB_VARIANT
ff8646ee 24624#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 24625
5be8be5d
DG
24626 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24627 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24628 strex, t_strex),
ff8646ee
TP
24629#undef THUMB_VARIANT
24630#define THUMB_VARIANT & arm_ext_v6t2
24631
21d799b5
NC
24632 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24633 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 24634
21d799b5
NC
24635 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24636 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 24637
9e3c6df6 24638/* ARM V6 not included in V7M. */
c921be7d
NC
24639#undef THUMB_VARIANT
24640#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 24641 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 24642 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
24643 UF(rfeib, 9900a00, 1, (RRw), rfe),
24644 UF(rfeda, 8100a00, 1, (RRw), rfe),
24645 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24646 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
24647 UF(rfefa, 8100a00, 1, (RRw), rfe),
24648 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24649 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 24650 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
24651 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24652 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 24653 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 24654 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 24655 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 24656 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 24657 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 24658 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 24659 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 24660
9e3c6df6
PB
24661/* ARM V6 not included in V7M (eg. integer SIMD). */
24662#undef THUMB_VARIANT
24663#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
24664 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24665 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24666 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24667 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24668 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24669 /* Old name for QASX. */
74db7efb 24670 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24671 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24672 /* Old name for QSAX. */
74db7efb 24673 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24674 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24675 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24676 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24677 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24678 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24679 /* Old name for SASX. */
74db7efb 24680 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24681 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24682 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24683 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24684 /* Old name for SHASX. */
21d799b5 24685 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24686 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24687 /* Old name for SHSAX. */
21d799b5
NC
24688 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24689 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24690 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24691 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24692 /* Old name for SSAX. */
74db7efb 24693 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24694 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24695 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24696 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24697 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24698 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24699 /* Old name for UASX. */
74db7efb 24700 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24701 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24703 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24704 /* Old name for UHASX. */
21d799b5
NC
24705 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24706 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24707 /* Old name for UHSAX. */
21d799b5
NC
24708 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24709 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24712 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24713 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24714 /* Old name for UQASX. */
21d799b5
NC
24715 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24716 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24717 /* Old name for UQSAX. */
21d799b5
NC
24718 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24719 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24720 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24721 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24722 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24723 /* Old name for USAX. */
74db7efb 24724 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24725 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24726 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24727 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24728 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24729 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24730 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24731 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24732 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24733 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24734 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24735 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24736 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24737 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24738 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24739 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24740 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24741 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24742 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24743 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24744 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24745 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24746 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24747 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24748 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24749 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24750 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24751 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24752 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
24753 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24754 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24755 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24756 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24757 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 24758
c921be7d 24759#undef ARM_VARIANT
55e8aae7 24760#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 24761#undef THUMB_VARIANT
55e8aae7 24762#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 24763
21d799b5
NC
24764 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24765 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24766 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24767 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 24768
c921be7d
NC
24769#undef THUMB_VARIANT
24770#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
24771 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24772 ldrexd, t_ldrexd),
24773 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24774 RRnpcb), strexd, t_strexd),
ebdca51a 24775
c921be7d 24776#undef THUMB_VARIANT
ff8646ee 24777#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
24778 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24779 rd_rn, rd_rn),
24780 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24781 rd_rn, rd_rn),
24782 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24783 strex, t_strexbh),
5be8be5d 24784 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24785 strex, t_strexbh),
21d799b5 24786 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 24787
c921be7d 24788#undef ARM_VARIANT
f4c65163 24789#define ARM_VARIANT & arm_ext_sec
74db7efb 24790#undef THUMB_VARIANT
f4c65163 24791#define THUMB_VARIANT & arm_ext_sec
c921be7d 24792
21d799b5 24793 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 24794
90ec0d68
MGD
24795#undef ARM_VARIANT
24796#define ARM_VARIANT & arm_ext_virt
24797#undef THUMB_VARIANT
24798#define THUMB_VARIANT & arm_ext_virt
24799
24800 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24801 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24802
ddfded2f
MW
24803#undef ARM_VARIANT
24804#define ARM_VARIANT & arm_ext_pan
24805#undef THUMB_VARIANT
24806#define THUMB_VARIANT & arm_ext_pan
24807
24808 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24809
c921be7d 24810#undef ARM_VARIANT
74db7efb 24811#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
24812#undef THUMB_VARIANT
24813#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24814
21d799b5
NC
24815 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24816 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24817 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24818 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 24819
21d799b5 24820 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 24821 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 24822
5be8be5d
DG
24823 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24824 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24825 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24826 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 24827
91d8b670
JG
24828#undef ARM_VARIANT
24829#define ARM_VARIANT & arm_ext_v3
24830#undef THUMB_VARIANT
24831#define THUMB_VARIANT & arm_ext_v6t2
24832
24833 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
24834 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24835 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
24836
24837#undef ARM_VARIANT
24838#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
24839#undef THUMB_VARIANT
24840#define THUMB_VARIANT & arm_ext_v6t2_v8m
24841 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24842 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24843
bf3eeda7 24844 /* Thumb-only instructions. */
74db7efb 24845#undef ARM_VARIANT
bf3eeda7
NS
24846#define ARM_VARIANT NULL
24847 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24848 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
24849
24850 /* ARM does not really have an IT instruction, so always allow it.
24851 The opcode is copied from Thumb in order to allow warnings in
24852 -mimplicit-it=[never | arm] modes. */
24853#undef ARM_VARIANT
24854#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
24855#undef THUMB_VARIANT
24856#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24857
21d799b5
NC
24858 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24859 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24860 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24861 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24862 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24863 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24864 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24865 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24866 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24867 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24868 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24869 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24870 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24871 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24872 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 24873 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
24874 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24875 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 24876
92e90b6e 24877 /* Thumb2 only instructions. */
c921be7d
NC
24878#undef ARM_VARIANT
24879#define ARM_VARIANT NULL
92e90b6e 24880
21d799b5
NC
24881 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24882 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24883 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24884 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24885 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24886 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 24887
eea54501
MGD
24888 /* Hardware division instructions. */
24889#undef ARM_VARIANT
24890#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
24891#undef THUMB_VARIANT
24892#define THUMB_VARIANT & arm_ext_div
24893
eea54501
MGD
24894 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24895 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 24896
7e806470 24897 /* ARM V6M/V7 instructions. */
c921be7d
NC
24898#undef ARM_VARIANT
24899#define ARM_VARIANT & arm_ext_barrier
24900#undef THUMB_VARIANT
24901#define THUMB_VARIANT & arm_ext_barrier
24902
ccb84d65
JB
24903 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24904 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24905 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24906
62b3e311 24907 /* ARM V7 instructions. */
c921be7d
NC
24908#undef ARM_VARIANT
24909#define ARM_VARIANT & arm_ext_v7
24910#undef THUMB_VARIANT
24911#define THUMB_VARIANT & arm_ext_v7
24912
21d799b5
NC
24913 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24914 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24915
74db7efb 24916#undef ARM_VARIANT
60e5ef9f 24917#define ARM_VARIANT & arm_ext_mp
74db7efb 24918#undef THUMB_VARIANT
60e5ef9f
MGD
24919#define THUMB_VARIANT & arm_ext_mp
24920
24921 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24922
53c4b28b
MGD
24923 /* AArchv8 instructions. */
24924#undef ARM_VARIANT
24925#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24926
24927/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24928#undef THUMB_VARIANT
4ed7ed8d 24929#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24930
4ed7ed8d
TP
24931 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24932 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24933 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24934 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24935 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24936 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24937 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24938 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24939 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24940 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24941 stlex, t_stlex),
4b8c8c02
RE
24942 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24943 stlex, t_stlex),
24944 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24945 stlex, t_stlex),
4ed7ed8d
TP
24946#undef THUMB_VARIANT
24947#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24948
4ed7ed8d 24949 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24950 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24951 ldrexd, t_ldrexd),
24952 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24953 strexd, t_strexd),
f7dd2fb2
TC
24954
24955/* Defined in V8 but is in undefined encoding space for earlier
24956 architectures. However earlier architectures are required to treat
24957 this instuction as a semihosting trap as well. Hence while not explicitly
24958 defined as such, it is in fact correct to define the instruction for all
24959 architectures. */
24960#undef THUMB_VARIANT
24961#define THUMB_VARIANT & arm_ext_v1
24962#undef ARM_VARIANT
24963#define ARM_VARIANT & arm_ext_v1
24964 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24965
8884b720 24966 /* ARMv8 T32 only. */
74db7efb 24967#undef ARM_VARIANT
b79f7053
MGD
24968#define ARM_VARIANT NULL
24969 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24970 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24971 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24972
33399f07
MGD
24973 /* FP for ARMv8. */
24974#undef ARM_VARIANT
a715796b 24975#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24976#undef THUMB_VARIANT
a715796b 24977#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24978
24979 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24980 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24981 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24982 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24983 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24984 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24985 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24986 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24987 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24988 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24989 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 24990
91ff7894
MGD
24991 /* Crypto v1 extensions. */
24992#undef ARM_VARIANT
24993#define ARM_VARIANT & fpu_crypto_ext_armv8
24994#undef THUMB_VARIANT
24995#define THUMB_VARIANT & fpu_crypto_ext_armv8
24996
24997 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24998 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24999 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25000 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
25001 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25002 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25003 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25004 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25005 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25006 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25007 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
25008 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25009 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25010 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 25011
dd5181d5 25012#undef ARM_VARIANT
8b301fbb 25013#define ARM_VARIANT & arm_ext_crc
dd5181d5 25014#undef THUMB_VARIANT
8b301fbb 25015#define THUMB_VARIANT & arm_ext_crc
dd5181d5
KT
25016 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25017 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25018 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25019 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25020 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25021 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25022
105bde57
MW
25023 /* ARMv8.2 RAS extension. */
25024#undef ARM_VARIANT
4d1464f2 25025#define ARM_VARIANT & arm_ext_ras
105bde57 25026#undef THUMB_VARIANT
4d1464f2 25027#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
25028 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25029
49e8a725
SN
25030#undef ARM_VARIANT
25031#define ARM_VARIANT & arm_ext_v8_3
25032#undef THUMB_VARIANT
25033#define THUMB_VARIANT & arm_ext_v8_3
25034 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25035
c604a79a
JW
25036#undef ARM_VARIANT
25037#define ARM_VARIANT & fpu_neon_ext_dotprod
25038#undef THUMB_VARIANT
25039#define THUMB_VARIANT & fpu_neon_ext_dotprod
25040 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25041 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25042
c921be7d
NC
25043#undef ARM_VARIANT
25044#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
25045#undef THUMB_VARIANT
25046#define THUMB_VARIANT NULL
c921be7d 25047
21d799b5
NC
25048 cCE("wfs", e200110, 1, (RR), rd),
25049 cCE("rfs", e300110, 1, (RR), rd),
25050 cCE("wfc", e400110, 1, (RR), rd),
25051 cCE("rfc", e500110, 1, (RR), rd),
25052
25053 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25054 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25055 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25056 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25057
25058 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25059 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25060 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25061 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25062
25063 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25064 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25065 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25066 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25067 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25068 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25069 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25070 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25071 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25072 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25073 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25074 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25075
25076 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25077 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25078 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25079 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25080 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25081 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25082 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25083 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25084 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25085 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25086 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25087 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25088
25089 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25090 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25091 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25092 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25093 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25094 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25095 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25096 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25097 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25098 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25099 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25100 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25101
25102 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25103 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25104 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25105 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25106 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25107 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25108 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25109 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25110 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25111 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25112 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25113 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25114
25115 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25116 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25117 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25118 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25119 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25120 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25121 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25122 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25123 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25124 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25125 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25126 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25127
25128 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25129 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25130 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25131 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25132 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25133 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25134 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25135 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25136 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25137 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25138 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25139 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25140
25141 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25142 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25143 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25144 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25145 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25146 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25147 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25148 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25149 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25150 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25151 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25152 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25153
25154 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25155 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25156 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25157 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25158 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25159 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25160 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25161 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25162 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25163 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25164 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25165 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25166
25167 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25168 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25169 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25170 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25171 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25172 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25173 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25174 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25175 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25176 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25177 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25178 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25179
25180 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25181 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25182 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25183 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25184 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25185 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25186 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25187 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25188 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25189 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25190 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25191 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25192
25193 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25194 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25195 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25196 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25197 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25198 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25199 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25200 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25201 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25202 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25203 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25204 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25205
25206 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25207 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25208 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25209 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25210 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25211 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25212 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25213 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25214 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25215 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25216 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25217 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25218
25219 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25220 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25221 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25222 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25223 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25224 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25225 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25226 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25227 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25228 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25229 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25230 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25231
25232 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25233 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25234 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25235 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25236 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25237 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25238 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25239 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25240 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25241 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25242 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25243 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25244
25245 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25246 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25247 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25248 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25249 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25250 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25251 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25252 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25253 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25254 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25255 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25256 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25257
25258 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25259 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25260 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25261 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25262 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25263 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25264 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25265 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25266 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25267 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25268 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25269 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25270
25271 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25272 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25273 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25274 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25275 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25276 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25277 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25278 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25279 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25280 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25281 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25282 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25283
25284 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25285 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25286 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25287 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25288 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25289 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25290 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25291 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25295 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25296
25297 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25298 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25299 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25302 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25303 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25304 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25309
25310 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25311 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25312 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25316 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25317 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25322
25323 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25324 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25325 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25329 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25330 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25335
25336 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25337 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25338 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25342 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25343 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25348
25349 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25350 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25351 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25355 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25356 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25361
25362 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25363 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25364 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25368 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25369 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25374
25375 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25376 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25377 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25381 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25382 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25387
25388 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25389 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25390 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25394 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25395 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25400
25401 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25402 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25403 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25407 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25408 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25413
25414 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25415 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25416 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25420 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25421 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25426
25427 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25428 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25429 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25433 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25434 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25439
25440 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25441 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25442 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25443 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25444
25445 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25446 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25447 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25448 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25449 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25450 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25451 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25452 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25453 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25454 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25455 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25456 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 25457
c19d1205
ZW
25458 /* The implementation of the FIX instruction is broken on some
25459 assemblers, in that it accepts a precision specifier as well as a
25460 rounding specifier, despite the fact that this is meaningless.
25461 To be more compatible, we accept it as well, though of course it
25462 does not set any bits. */
21d799b5
NC
25463 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25464 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25465 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25466 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25467 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25468 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25469 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25470 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25471 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25472 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25473 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25474 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25475 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 25476
c19d1205 25477 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
25478#undef ARM_VARIANT
25479#define ARM_VARIANT & fpu_fpa_ext_v2
25480
21d799b5
NC
25481 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25482 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25483 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25484 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25485 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25486 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 25487
c921be7d
NC
25488#undef ARM_VARIANT
25489#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
25490#undef THUMB_VARIANT
25491#define THUMB_VARIANT & arm_ext_v6t2
25492 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25493 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
ef8f595f
MI
25494 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25495 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25496 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25497 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
90e9955a
SP
25498
25499 /* Memory operations. */
25500 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25501 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25502 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25503 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
ba6cd17f 25504#undef THUMB_VARIANT
c921be7d 25505
c19d1205 25506 /* Moves and type conversions. */
21d799b5
NC
25507 cCE("fmstat", ef1fa10, 0, (), noargs),
25508 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25509 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25510 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25511 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25512 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25513 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25514 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25515 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
25516
25517 /* Memory operations. */
55881a11 25518 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25519 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25520 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25521 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25522 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25523 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
55881a11 25524 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25525 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25526 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25527 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25528 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25529 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 25530
c19d1205 25531 /* Monadic operations. */
21d799b5
NC
25532 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25533 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25534 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
25535
25536 /* Dyadic operations. */
21d799b5
NC
25537 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25538 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25539 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25540 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25541 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25542 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25543 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25544 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25545 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 25546
c19d1205 25547 /* Comparisons. */
21d799b5
NC
25548 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25549 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25550 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25551 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 25552
62f3b8c8
PB
25553 /* Double precision load/store are still present on single precision
25554 implementations. */
55881a11
MGD
25555 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25556 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25557 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25558 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25559 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25560 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25561 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25562 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 25563
c921be7d
NC
25564#undef ARM_VARIANT
25565#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25566
c19d1205 25567 /* Moves and type conversions. */
21d799b5
NC
25568 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25569 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25570 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25571 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25572 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25573 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25574 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25575 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25576 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25577 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25578 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25579 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 25580
c19d1205 25581 /* Monadic operations. */
21d799b5
NC
25582 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25583 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25584 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
25585
25586 /* Dyadic operations. */
21d799b5
NC
25587 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25588 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25589 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25590 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25591 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25592 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25593 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25594 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25595 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 25596
c19d1205 25597 /* Comparisons. */
21d799b5
NC
25598 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25599 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25600 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25601 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 25602
037e8744
JB
25603/* Instructions which may belong to either the Neon or VFP instruction sets.
25604 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
25605#undef ARM_VARIANT
25606#define ARM_VARIANT & fpu_vfp_ext_v1xd
ef8f595f
MI
25607#undef THUMB_VARIANT
25608#define THUMB_VARIANT & arm_ext_v6t2
25609
25610 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25611 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25612 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25613 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25614 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25615 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25616
25617 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25618 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25619
c921be7d
NC
25620#undef THUMB_VARIANT
25621#define THUMB_VARIANT & fpu_vfp_ext_v1xd
25622
037e8744
JB
25623 /* These mnemonics are unique to VFP. */
25624 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25625 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
25626 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25627 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25628 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
25629 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25630
25631 /* Mnemonics shared by Neon and VFP. */
21d799b5 25632 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 25633
dd9634d9 25634 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 25635 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
25636 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25637 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 25638
037e8744
JB
25639
25640 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
25641 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25642
32c36c3c
AV
25643#undef THUMB_VARIANT
25644/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25645 by different feature bits. Since we are setting the Thumb guard, we can
25646 require Thumb-1 which makes it a nop guard and set the right feature bit in
25647 do_vldr_vstr (). */
25648#define THUMB_VARIANT & arm_ext_v4t
25649 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25650 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25651
9db2f6b4
RL
25652#undef ARM_VARIANT
25653#define ARM_VARIANT & arm_ext_fp16
25654#undef THUMB_VARIANT
25655#define THUMB_VARIANT & arm_ext_fp16
25656 /* New instructions added from v8.2, allowing the extraction and insertion of
25657 the upper 16 bits of a 32-bit vector register. */
25658 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25659 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25660
dec41383 25661 /* New backported fma/fms instructions optional in v8.2. */
aab2c27d
MM
25662 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25663 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
dec41383 25664
c921be7d
NC
25665#undef THUMB_VARIANT
25666#define THUMB_VARIANT & fpu_neon_ext_v1
25667#undef ARM_VARIANT
25668#define ARM_VARIANT & fpu_neon_ext_v1
25669
5287ad62
JB
25670 /* Data processing with three registers of the same length. */
25671 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25672 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25673 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 25674 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 25675 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
25676 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25677 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25678 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 25679 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 25680 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 25681 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 25682 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
25683 shl should accept I8 I16 I32 I64,
25684 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25685 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25686 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 25687 /* Logic ops, types optional & ignored. */
4316f0d2 25688 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25689 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25690 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25691 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25692 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
25693 /* Bitfield ops, untyped. */
25694 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25695 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25696 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25697 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25698 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25699 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 25700 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 25701 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25702 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25703 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
25704 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25705 back to neon_dyadic_if_su. */
21d799b5
NC
25706 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25707 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25708 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25709 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25710 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25711 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25712 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25713 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 25714 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
25715 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25716 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 25717 /* As above, D registers only. */
21d799b5
NC
25718 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25719 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 25720 /* Int and float variants, signedness unimportant. */
21d799b5
NC
25721 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25722 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25723 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 25724 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
25725 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25726 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
25727 /* vtst takes sizes 8, 16, 32. */
25728 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25729 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25730 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 25731 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 25732 /* VQD{R}MULH takes S16 S32. */
21d799b5 25733 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 25734 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
25735 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25736 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25737 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25738 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
25739 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25740 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25741 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25742 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
25743 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25744 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25745 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25746 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 25747 /* ARM v8.1 extension. */
643afb90
MW
25748 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25749 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25750 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
25751
25752 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 25753 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
25754 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25755
25756 /* Data processing with two registers and a shift amount. */
25757 /* Right shifts, and variants with rounding.
25758 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25759 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
25760 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25761 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25762 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25763 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25764 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25765 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 25766 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
25767 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25768 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
25769 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25770 /* Right shift immediate, saturating & narrowing, with rounding variants.
25771 Types accepted S16 S32 S64 U16 U32 U64. */
25772 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25773 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25774 /* As above, unsigned. Types accepted S16 S32 S64. */
25775 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25776 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25777 /* Right shift narrowing. Types accepted I16 I32 I64. */
25778 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25779 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25780 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 25781 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 25782 /* CVT with optional immediate for fixed-point variant. */
21d799b5 25783 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 25784
4316f0d2 25785 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
25786
25787 /* Data processing, three registers of different lengths. */
25788 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25789 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
25790 /* If not scalar, fall back to neon_dyadic_long.
25791 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
25792 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25793 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
25794 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25795 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25796 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25797 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25798 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25799 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25800 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25801 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25802 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
25803 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25804 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25805 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
25806 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25807 S16 S32 U16 U32. */
21d799b5 25808 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
25809
25810 /* Extract. Size 8. */
3b8d421e
PB
25811 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25812 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
25813
25814 /* Two registers, miscellaneous. */
25815 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 25816 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 25817 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
25818 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25819 /* Vector replicate. Sizes 8 16 32. */
21d799b5 25820 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
25821 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25822 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25823 /* VMOVN. Types I16 I32 I64. */
21d799b5 25824 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 25825 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 25826 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 25827 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 25828 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
25829 /* VZIP / VUZP. Sizes 8 16 32. */
25830 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25831 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25832 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25833 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25834 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 25835 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
25836 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25837 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25838 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25839 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25840 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25841 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 25842 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
25843 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25844 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25845 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25846 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25847 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
25848 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25849 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
25850 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25851 /* VCNT. Size 8. */
25852 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25853 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25854 /* Two address, untyped. */
25855 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25856 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25857 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
25858 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25859 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
25860
25861 /* Table lookup. Size 8. */
25862 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25863 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25864
c921be7d
NC
25865#undef THUMB_VARIANT
25866#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25867#undef ARM_VARIANT
25868#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25869
5287ad62 25870 /* Neon element/structure load/store. */
21d799b5
NC
25871 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25872 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25873 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25874 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25875 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25876 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25877 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25878 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 25879
c921be7d 25880#undef THUMB_VARIANT
74db7efb
NC
25881#define THUMB_VARIANT & fpu_vfp_ext_v3xd
25882#undef ARM_VARIANT
25883#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
25884 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25885 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25886 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25887 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25888 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25889 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25890 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25891 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25892 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25893
74db7efb 25894#undef THUMB_VARIANT
c921be7d
NC
25895#define THUMB_VARIANT & fpu_vfp_ext_v3
25896#undef ARM_VARIANT
25897#define ARM_VARIANT & fpu_vfp_ext_v3
25898
21d799b5 25899 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 25900 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25901 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25902 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25903 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25904 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25905 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25906 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25907 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25908
74db7efb
NC
25909#undef ARM_VARIANT
25910#define ARM_VARIANT & fpu_vfp_ext_fma
25911#undef THUMB_VARIANT
25912#define THUMB_VARIANT & fpu_vfp_ext_fma
aab2c27d 25913 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
62f3b8c8
PB
25914 VFP FMA variant; NEON and VFP FMA always includes the NEON
25915 FMA instructions. */
d58196e0 25916 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
aab2c27d 25917 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
d58196e0
AV
25918 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25919
62f3b8c8
PB
25920 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25921 the v form should always be used. */
25922 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25923 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25924 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25925 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25926 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25927 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25928
5287ad62 25929#undef THUMB_VARIANT
c921be7d
NC
25930#undef ARM_VARIANT
25931#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25932
21d799b5
NC
25933 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25934 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25935 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25936 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25937 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25938 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25939 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25940 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25941
c921be7d
NC
25942#undef ARM_VARIANT
25943#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25944
21d799b5
NC
25945 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25946 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25947 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25948 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25949 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25950 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25951 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25952 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25953 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25954 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25955 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25956 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25957 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25958 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25959 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25960 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25961 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25962 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25963 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25964 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25965 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25966 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25967 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25968 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25969 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25970 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25971 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25972 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25973 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25974 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25975 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25976 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25977 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25978 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25979 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25980 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25981 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25982 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25983 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25984 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25985 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25986 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25987 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25988 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25989 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25990 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25991 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
25992 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25993 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25994 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25995 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25996 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25997 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25998 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25999 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26000 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26001 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26002 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26004 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26005 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26007 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26008 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26011 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26012 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26013 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26014 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26015 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26016 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26020 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26025 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26026 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26027 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26028 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26029 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26030 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26034 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26039 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26045 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26046 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26047 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26048 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26049 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26050 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26051 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26054 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26056 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26057 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26058 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26059 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26060 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26061 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26062 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26063 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26064 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26065 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26066 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26067 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26068 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26069 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26070 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26071 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26072 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26073 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26074 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26075 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26076 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26077 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26078 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26079 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26080 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26081 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26082 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26083 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26084 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26085 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26086 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26087 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26088 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26089 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26090 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26091 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26092 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26093 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26094 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26095 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26096 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26097 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26098 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26099 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26100 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26101 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26102 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26103 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26104 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26105 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26106 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 26107
c921be7d
NC
26108#undef ARM_VARIANT
26109#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26110
21d799b5
NC
26111 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26112 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26113 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26114 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26115 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26116 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26117 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26118 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26119 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26120 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26121 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26122 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26123 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26124 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26125 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26126 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26127 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26128 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26129 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26130 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26131 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26132 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26133 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26134 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26135 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26136 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26144 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26147 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 26168
c921be7d
NC
26169#undef ARM_VARIANT
26170#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26171
21d799b5
NC
26172 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26173 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26174 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26175 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26176 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26177 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26178 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26179 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26180 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26181 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26182 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26183 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26184 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26185 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
26186 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26187 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26188 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26189 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26190 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26191 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26192 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26193 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26194 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26195 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
26196 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26197 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26198 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26199 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
26200 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26201 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
26202 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26203 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26204 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26205 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
26206 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26207 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26208 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26209 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26210 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26211 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
26212 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26213 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
26214 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26215 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
26216 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26217 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26218 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26219 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26220 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26221 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26222 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26223 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26224 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26225 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26226 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26227 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26228 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26229 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26230 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26231 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26232 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26233 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26234 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26235 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26236 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26237 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26238 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26239 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26240 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26241 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26242 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26243 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
26244 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26245 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
26246 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26247 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 26248
7fadb25d
SD
26249 /* ARMv8.5-A instructions. */
26250#undef ARM_VARIANT
26251#define ARM_VARIANT & arm_ext_sb
26252#undef THUMB_VARIANT
26253#define THUMB_VARIANT & arm_ext_sb
26254 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26255
dad0c3bf
SD
26256#undef ARM_VARIANT
26257#define ARM_VARIANT & arm_ext_predres
26258#undef THUMB_VARIANT
26259#define THUMB_VARIANT & arm_ext_predres
26260 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26261 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26262 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26263
16a1fa25 26264 /* ARMv8-M instructions. */
4ed7ed8d
TP
26265#undef ARM_VARIANT
26266#define ARM_VARIANT NULL
26267#undef THUMB_VARIANT
26268#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
26269 ToU("sg", e97fe97f, 0, (), noargs),
26270 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26271 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26272 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26273 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26274 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26275 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
26276
26277 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26278 instructions behave as nop if no VFP is present. */
26279#undef THUMB_VARIANT
26280#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
26281 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26282 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
26283
26284 /* Armv8.1-M Mainline instructions. */
26285#undef THUMB_VARIANT
26286#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
26287 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26288 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26289 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26290 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26291 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26292 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26293 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26294 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26295 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26296
4389b29a 26297 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 26298 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 26299 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 26300 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 26301 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
26302
26303 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26304 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26305 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 26306
efd6b359 26307 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
26308 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26309
26310#undef THUMB_VARIANT
26311#define THUMB_VARIANT & mve_ext
23d00a41
SD
26312 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26313 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26314 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
08132bdd
SP
26315 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26316 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
23d00a41
SD
26317 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26318 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26319 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26320 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26321 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26322 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26323 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26324 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26325 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26326 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
26327
26328 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26329 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26330 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26331 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26332 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26333 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26334 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26335 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26336 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26337 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26338 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26339 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26340 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26341 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26342 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26343
5ee91343
AV
26344 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26345 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26346 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26347 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26348 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26349 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26350 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26351 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26352 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26353 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26354 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26355 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26356 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26357 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26358 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26359
a302e574 26360 /* MVE and MVE FP only. */
7df54120 26361 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
efd0b310 26362 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
c2dafc2a
AV
26363 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26364 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26365 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26366 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 26367 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
26368 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26369 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26370 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26371 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26372 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26373 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26374 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26375 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26376 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26377 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26378 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26379
35c228db
AV
26380 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26381 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26382 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26383 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26384 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26385 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26386 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26387 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26388 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26389 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26390 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26391 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
26392 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26393 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26394 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26395 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26396 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26397 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26398 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26399 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 26400
57785aa2
AV
26401 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26402 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 26403 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
26404 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26405 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26406 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26407 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
26408 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26409 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26410 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26411 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
26412 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26413 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
26414 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26415 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26416 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26417 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 26418
93925576
AV
26419 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26420 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26421 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26422 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26423 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26424 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26425 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26426 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26427 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26428 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26429 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26430 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26431 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26432 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26433 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26434 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26435 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26436 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26437 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26438 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26439
2d78f95b
AV
26440 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26441 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26442 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
26443 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26444 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 26445
8b8b22a4
AV
26446 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26447 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26448 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26449 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26450 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26451 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26452 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26453 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
26454 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26455 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26456 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
26457 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26458 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
26459 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26460 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26461 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26462 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 26463
4aa88b50
AV
26464 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26465 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26466 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26467 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26468 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26469 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26470 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26471 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26472 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26473 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26474 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26475 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26476
acca5630
AV
26477 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26478 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26479 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26480
1f6234a3
AV
26481 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26482 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26483 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26484 toU("lctp", _lctp, 0, (), t_loloop),
26485
5d281bf0
AV
26486#undef THUMB_VARIANT
26487#define THUMB_VARIANT & mve_fp_ext
26488 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 26489 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
26490 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26491 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
26492 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26493 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26494 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26495 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 26496
5ee91343 26497#undef ARM_VARIANT
57785aa2 26498#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
26499#undef THUMB_VARIANT
26500#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
26501 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26502 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 26503
57785aa2
AV
26504 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26505
26506#undef ARM_VARIANT
26507#define ARM_VARIANT & fpu_vfp_ext_v1xd
26508
26509 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26510 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26511 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26512 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26513
886e1c73
AV
26514 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26515 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26516 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 26517
485dee97
AV
26518 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26519 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26520
57785aa2
AV
26521 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26522 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26523
1b883319
AV
26524 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26525 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26526
57785aa2
AV
26527#undef ARM_VARIANT
26528#define ARM_VARIANT & fpu_vfp_ext_v2
26529
26530 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26531 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26532 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26533 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26534
dd9634d9
AV
26535#undef ARM_VARIANT
26536#define ARM_VARIANT & fpu_vfp_ext_armv8xd
26537 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26538 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26539 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26540 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
26541 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26542 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
26543
26544#undef ARM_VARIANT
5ee91343 26545#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 26546 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343 26547 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
66d1f7cc
AV
26548 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26549 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
f601a00c
AV
26550 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26551 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26552 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26553 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26554 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
26555 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26556 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 26557 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
26558 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26559 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26560 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
26561 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26562 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
26563 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26564 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
26565 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26566 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26567 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
26568 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26569 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26570 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
26571 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26572 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
26573 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26574 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26575 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26576 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26577 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26578 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26579 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
26580 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26581 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26582 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
26583
26584#undef ARM_VARIANT
26585#define ARM_VARIANT & arm_ext_v8_3
26586#undef THUMB_VARIANT
26587#define THUMB_VARIANT & arm_ext_v6t2_v8m
26588 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26589 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
aab2c27d
MM
26590
26591#undef ARM_VARIANT
26592#define ARM_VARIANT &arm_ext_bf16
26593#undef THUMB_VARIANT
26594#define THUMB_VARIANT &arm_ext_bf16
26595 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26596 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26597 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26598
26599#undef ARM_VARIANT
26600#define ARM_VARIANT &arm_ext_i8mm
26601#undef THUMB_VARIANT
26602#define THUMB_VARIANT &arm_ext_i8mm
26603 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26604 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
616ce08e 26605 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
aab2c27d
MM
26606 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26607 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
4934a27c
MM
26608
26609#undef ARM_VARIANT
26610#undef THUMB_VARIANT
26611#define THUMB_VARIANT &arm_ext_cde
26612 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26613 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26614 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26615 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26616
26617 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26618 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26619 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26620 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26621
26622 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26623 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26624 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26625 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
5aae9ae9
MM
26626
26627 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26628 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26629
26630 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26631 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26632
26633 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26634 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
c19d1205 26635};
5aae9ae9 26636
c19d1205
ZW
26637#undef ARM_VARIANT
26638#undef THUMB_VARIANT
26639#undef TCE
c19d1205
ZW
26640#undef TUE
26641#undef TUF
26642#undef TCC
8f06b2d8 26643#undef cCE
e3cb604e
PB
26644#undef cCL
26645#undef C3E
4389b29a 26646#undef C3
c19d1205
ZW
26647#undef CE
26648#undef CM
4389b29a 26649#undef CL
c19d1205
ZW
26650#undef UE
26651#undef UF
26652#undef UT
5287ad62
JB
26653#undef NUF
26654#undef nUF
26655#undef NCE
26656#undef nCE
c19d1205
ZW
26657#undef OPS0
26658#undef OPS1
26659#undef OPS2
26660#undef OPS3
26661#undef OPS4
26662#undef OPS5
26663#undef OPS6
26664#undef do_0
4389b29a
AV
26665#undef ToC
26666#undef toC
26667#undef ToU
f6b2b12d 26668#undef toU
c19d1205
ZW
26669\f
26670/* MD interface: bits in the object file. */
bfae80f2 26671
c19d1205
ZW
26672/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26673 for use in the a.out file, and stores them in the array pointed to by buf.
26674 This knows about the endian-ness of the target machine and does
26675 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26676 2 (short) and 4 (long) Floating numbers are put out as a series of
26677 LITTLENUMS (shorts, here at least). */
b99bd4ef 26678
c19d1205
ZW
26679void
26680md_number_to_chars (char * buf, valueT val, int n)
26681{
26682 if (target_big_endian)
26683 number_to_chars_bigendian (buf, val, n);
26684 else
26685 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
26686}
26687
c19d1205
ZW
26688static valueT
26689md_chars_to_number (char * buf, int n)
bfae80f2 26690{
c19d1205
ZW
26691 valueT result = 0;
26692 unsigned char * where = (unsigned char *) buf;
bfae80f2 26693
c19d1205 26694 if (target_big_endian)
b99bd4ef 26695 {
c19d1205
ZW
26696 while (n--)
26697 {
26698 result <<= 8;
26699 result |= (*where++ & 255);
26700 }
b99bd4ef 26701 }
c19d1205 26702 else
b99bd4ef 26703 {
c19d1205
ZW
26704 while (n--)
26705 {
26706 result <<= 8;
26707 result |= (where[n] & 255);
26708 }
bfae80f2 26709 }
b99bd4ef 26710
c19d1205 26711 return result;
bfae80f2 26712}
b99bd4ef 26713
c19d1205 26714/* MD interface: Sections. */
b99bd4ef 26715
fa94de6b
RM
26716/* Calculate the maximum variable size (i.e., excluding fr_fix)
26717 that an rs_machine_dependent frag may reach. */
26718
26719unsigned int
26720arm_frag_max_var (fragS *fragp)
26721{
26722 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26723 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26724
26725 Note that we generate relaxable instructions even for cases that don't
26726 really need it, like an immediate that's a trivial constant. So we're
26727 overestimating the instruction size for some of those cases. Rather
26728 than putting more intelligence here, it would probably be better to
26729 avoid generating a relaxation frag in the first place when it can be
26730 determined up front that a short instruction will suffice. */
26731
26732 gas_assert (fragp->fr_type == rs_machine_dependent);
26733 return INSN_SIZE;
26734}
26735
0110f2b8
PB
26736/* Estimate the size of a frag before relaxing. Assume everything fits in
26737 2 bytes. */
26738
c19d1205 26739int
0110f2b8 26740md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
26741 segT segtype ATTRIBUTE_UNUSED)
26742{
0110f2b8
PB
26743 fragp->fr_var = 2;
26744 return 2;
26745}
26746
26747/* Convert a machine dependent frag. */
26748
26749void
26750md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26751{
26752 unsigned long insn;
26753 unsigned long old_op;
26754 char *buf;
26755 expressionS exp;
26756 fixS *fixp;
26757 int reloc_type;
26758 int pc_rel;
26759 int opcode;
26760
26761 buf = fragp->fr_literal + fragp->fr_fix;
26762
26763 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
26764 if (fragp->fr_symbol)
26765 {
0110f2b8
PB
26766 exp.X_op = O_symbol;
26767 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
26768 }
26769 else
26770 {
0110f2b8 26771 exp.X_op = O_constant;
5f4273c7 26772 }
0110f2b8
PB
26773 exp.X_add_number = fragp->fr_offset;
26774 opcode = fragp->fr_subtype;
26775 switch (opcode)
26776 {
26777 case T_MNEM_ldr_pc:
26778 case T_MNEM_ldr_pc2:
26779 case T_MNEM_ldr_sp:
26780 case T_MNEM_str_sp:
26781 case T_MNEM_ldr:
26782 case T_MNEM_ldrb:
26783 case T_MNEM_ldrh:
26784 case T_MNEM_str:
26785 case T_MNEM_strb:
26786 case T_MNEM_strh:
26787 if (fragp->fr_var == 4)
26788 {
5f4273c7 26789 insn = THUMB_OP32 (opcode);
0110f2b8
PB
26790 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26791 {
26792 insn |= (old_op & 0x700) << 4;
26793 }
26794 else
26795 {
26796 insn |= (old_op & 7) << 12;
26797 insn |= (old_op & 0x38) << 13;
26798 }
26799 insn |= 0x00000c00;
26800 put_thumb32_insn (buf, insn);
26801 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26802 }
26803 else
26804 {
26805 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26806 }
26807 pc_rel = (opcode == T_MNEM_ldr_pc2);
26808 break;
26809 case T_MNEM_adr:
26810 if (fragp->fr_var == 4)
26811 {
26812 insn = THUMB_OP32 (opcode);
26813 insn |= (old_op & 0xf0) << 4;
26814 put_thumb32_insn (buf, insn);
26815 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26816 }
26817 else
26818 {
26819 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26820 exp.X_add_number -= 4;
26821 }
26822 pc_rel = 1;
26823 break;
26824 case T_MNEM_mov:
26825 case T_MNEM_movs:
26826 case T_MNEM_cmp:
26827 case T_MNEM_cmn:
26828 if (fragp->fr_var == 4)
26829 {
26830 int r0off = (opcode == T_MNEM_mov
26831 || opcode == T_MNEM_movs) ? 0 : 8;
26832 insn = THUMB_OP32 (opcode);
26833 insn = (insn & 0xe1ffffff) | 0x10000000;
26834 insn |= (old_op & 0x700) << r0off;
26835 put_thumb32_insn (buf, insn);
26836 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26837 }
26838 else
26839 {
26840 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26841 }
26842 pc_rel = 0;
26843 break;
26844 case T_MNEM_b:
26845 if (fragp->fr_var == 4)
26846 {
26847 insn = THUMB_OP32(opcode);
26848 put_thumb32_insn (buf, insn);
26849 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26850 }
26851 else
26852 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26853 pc_rel = 1;
26854 break;
26855 case T_MNEM_bcond:
26856 if (fragp->fr_var == 4)
26857 {
26858 insn = THUMB_OP32(opcode);
26859 insn |= (old_op & 0xf00) << 14;
26860 put_thumb32_insn (buf, insn);
26861 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26862 }
26863 else
26864 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26865 pc_rel = 1;
26866 break;
26867 case T_MNEM_add_sp:
26868 case T_MNEM_add_pc:
26869 case T_MNEM_inc_sp:
26870 case T_MNEM_dec_sp:
26871 if (fragp->fr_var == 4)
26872 {
26873 /* ??? Choose between add and addw. */
26874 insn = THUMB_OP32 (opcode);
26875 insn |= (old_op & 0xf0) << 4;
26876 put_thumb32_insn (buf, insn);
16805f35
PB
26877 if (opcode == T_MNEM_add_pc)
26878 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26879 else
26880 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
26881 }
26882 else
26883 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26884 pc_rel = 0;
26885 break;
26886
26887 case T_MNEM_addi:
26888 case T_MNEM_addis:
26889 case T_MNEM_subi:
26890 case T_MNEM_subis:
26891 if (fragp->fr_var == 4)
26892 {
26893 insn = THUMB_OP32 (opcode);
26894 insn |= (old_op & 0xf0) << 4;
26895 insn |= (old_op & 0xf) << 16;
26896 put_thumb32_insn (buf, insn);
16805f35
PB
26897 if (insn & (1 << 20))
26898 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26899 else
26900 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
26901 }
26902 else
26903 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26904 pc_rel = 0;
26905 break;
26906 default:
5f4273c7 26907 abort ();
0110f2b8
PB
26908 }
26909 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 26910 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
26911 fixp->fx_file = fragp->fr_file;
26912 fixp->fx_line = fragp->fr_line;
26913 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
26914
26915 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26916 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26917 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26918 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
26919}
26920
26921/* Return the size of a relaxable immediate operand instruction.
26922 SHIFT and SIZE specify the form of the allowable immediate. */
26923static int
26924relax_immediate (fragS *fragp, int size, int shift)
26925{
26926 offsetT offset;
26927 offsetT mask;
26928 offsetT low;
26929
26930 /* ??? Should be able to do better than this. */
26931 if (fragp->fr_symbol)
26932 return 4;
26933
26934 low = (1 << shift) - 1;
26935 mask = (1 << (shift + size)) - (1 << shift);
26936 offset = fragp->fr_offset;
26937 /* Force misaligned offsets to 32-bit variant. */
26938 if (offset & low)
5e77afaa 26939 return 4;
0110f2b8
PB
26940 if (offset & ~mask)
26941 return 4;
26942 return 2;
26943}
26944
5e77afaa
PB
26945/* Get the address of a symbol during relaxation. */
26946static addressT
5f4273c7 26947relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
26948{
26949 fragS *sym_frag;
26950 addressT addr;
26951 symbolS *sym;
26952
26953 sym = fragp->fr_symbol;
26954 sym_frag = symbol_get_frag (sym);
26955 know (S_GET_SEGMENT (sym) != absolute_section
26956 || sym_frag == &zero_address_frag);
26957 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26958
26959 /* If frag has yet to be reached on this pass, assume it will
26960 move by STRETCH just as we did. If this is not so, it will
26961 be because some frag between grows, and that will force
26962 another pass. */
26963
26964 if (stretch != 0
26965 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26966 {
26967 fragS *f;
26968
26969 /* Adjust stretch for any alignment frag. Note that if have
26970 been expanding the earlier code, the symbol may be
26971 defined in what appears to be an earlier frag. FIXME:
26972 This doesn't handle the fr_subtype field, which specifies
26973 a maximum number of bytes to skip when doing an
26974 alignment. */
26975 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26976 {
26977 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26978 {
26979 if (stretch < 0)
26980 stretch = - ((- stretch)
26981 & ~ ((1 << (int) f->fr_offset) - 1));
26982 else
26983 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26984 if (stretch == 0)
26985 break;
26986 }
26987 }
26988 if (f != NULL)
26989 addr += stretch;
26990 }
5e77afaa
PB
26991
26992 return addr;
26993}
26994
0110f2b8
PB
26995/* Return the size of a relaxable adr pseudo-instruction or PC-relative
26996 load. */
26997static int
5e77afaa 26998relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
26999{
27000 addressT addr;
27001 offsetT val;
27002
27003 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
27004 if (fragp->fr_symbol == NULL
27005 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27006 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27007 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27008 return 4;
27009
5f4273c7 27010 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27011 addr = fragp->fr_address + fragp->fr_fix;
27012 addr = (addr + 4) & ~3;
5e77afaa 27013 /* Force misaligned targets to 32-bit variant. */
0110f2b8 27014 if (val & 3)
5e77afaa 27015 return 4;
0110f2b8
PB
27016 val -= addr;
27017 if (val < 0 || val > 1020)
27018 return 4;
27019 return 2;
27020}
27021
27022/* Return the size of a relaxable add/sub immediate instruction. */
27023static int
27024relax_addsub (fragS *fragp, asection *sec)
27025{
27026 char *buf;
27027 int op;
27028
27029 buf = fragp->fr_literal + fragp->fr_fix;
27030 op = bfd_get_16(sec->owner, buf);
27031 if ((op & 0xf) == ((op >> 4) & 0xf))
27032 return relax_immediate (fragp, 8, 0);
27033 else
27034 return relax_immediate (fragp, 3, 0);
27035}
27036
e83a675f
RE
27037/* Return TRUE iff the definition of symbol S could be pre-empted
27038 (overridden) at link or load time. */
27039static bfd_boolean
27040symbol_preemptible (symbolS *s)
27041{
27042 /* Weak symbols can always be pre-empted. */
27043 if (S_IS_WEAK (s))
27044 return TRUE;
27045
27046 /* Non-global symbols cannot be pre-empted. */
27047 if (! S_IS_EXTERNAL (s))
27048 return FALSE;
27049
27050#ifdef OBJ_ELF
27051 /* In ELF, a global symbol can be marked protected, or private. In that
27052 case it can't be pre-empted (other definitions in the same link unit
27053 would violate the ODR). */
27054 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27055 return FALSE;
27056#endif
27057
27058 /* Other global symbols might be pre-empted. */
27059 return TRUE;
27060}
0110f2b8
PB
27061
27062/* Return the size of a relaxable branch instruction. BITS is the
27063 size of the offset field in the narrow instruction. */
27064
27065static int
5e77afaa 27066relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
27067{
27068 addressT addr;
27069 offsetT val;
27070 offsetT limit;
27071
27072 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 27073 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27074 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27075 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27076 return 4;
27077
267bf995 27078#ifdef OBJ_ELF
e83a675f 27079 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
27080 if (S_IS_DEFINED (fragp->fr_symbol)
27081 && ARM_IS_FUNC (fragp->fr_symbol))
27082 return 4;
e83a675f 27083#endif
0d9b4b55 27084
e83a675f 27085 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 27086 return 4;
267bf995 27087
5f4273c7 27088 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27089 addr = fragp->fr_address + fragp->fr_fix + 4;
27090 val -= addr;
27091
27092 /* Offset is a signed value *2 */
27093 limit = 1 << bits;
27094 if (val >= limit || val < -limit)
27095 return 4;
27096 return 2;
27097}
27098
27099
27100/* Relax a machine dependent frag. This returns the amount by which
27101 the current size of the frag should change. */
27102
27103int
5e77afaa 27104arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
27105{
27106 int oldsize;
27107 int newsize;
27108
27109 oldsize = fragp->fr_var;
27110 switch (fragp->fr_subtype)
27111 {
27112 case T_MNEM_ldr_pc2:
5f4273c7 27113 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27114 break;
27115 case T_MNEM_ldr_pc:
27116 case T_MNEM_ldr_sp:
27117 case T_MNEM_str_sp:
5f4273c7 27118 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
27119 break;
27120 case T_MNEM_ldr:
27121 case T_MNEM_str:
5f4273c7 27122 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
27123 break;
27124 case T_MNEM_ldrh:
27125 case T_MNEM_strh:
5f4273c7 27126 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
27127 break;
27128 case T_MNEM_ldrb:
27129 case T_MNEM_strb:
5f4273c7 27130 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
27131 break;
27132 case T_MNEM_adr:
5f4273c7 27133 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27134 break;
27135 case T_MNEM_mov:
27136 case T_MNEM_movs:
27137 case T_MNEM_cmp:
27138 case T_MNEM_cmn:
5f4273c7 27139 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
27140 break;
27141 case T_MNEM_b:
5f4273c7 27142 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
27143 break;
27144 case T_MNEM_bcond:
5f4273c7 27145 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
27146 break;
27147 case T_MNEM_add_sp:
27148 case T_MNEM_add_pc:
27149 newsize = relax_immediate (fragp, 8, 2);
27150 break;
27151 case T_MNEM_inc_sp:
27152 case T_MNEM_dec_sp:
27153 newsize = relax_immediate (fragp, 7, 2);
27154 break;
27155 case T_MNEM_addi:
27156 case T_MNEM_addis:
27157 case T_MNEM_subi:
27158 case T_MNEM_subis:
27159 newsize = relax_addsub (fragp, sec);
27160 break;
27161 default:
5f4273c7 27162 abort ();
0110f2b8 27163 }
5e77afaa
PB
27164
27165 fragp->fr_var = newsize;
27166 /* Freeze wide instructions that are at or before the same location as
27167 in the previous pass. This avoids infinite loops.
5f4273c7
NC
27168 Don't freeze them unconditionally because targets may be artificially
27169 misaligned by the expansion of preceding frags. */
5e77afaa 27170 if (stretch <= 0 && newsize > 2)
0110f2b8 27171 {
0110f2b8 27172 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 27173 frag_wane (fragp);
0110f2b8 27174 }
5e77afaa 27175
0110f2b8 27176 return newsize - oldsize;
c19d1205 27177}
b99bd4ef 27178
c19d1205 27179/* Round up a section size to the appropriate boundary. */
b99bd4ef 27180
c19d1205
ZW
27181valueT
27182md_section_align (segT segment ATTRIBUTE_UNUSED,
27183 valueT size)
27184{
6844c0cc 27185 return size;
bfae80f2 27186}
b99bd4ef 27187
c19d1205
ZW
27188/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27189 of an rs_align_code fragment. */
27190
27191void
27192arm_handle_align (fragS * fragP)
bfae80f2 27193{
d9235011 27194 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
27195 {
27196 { /* ARMv1 */
27197 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27198 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27199 },
27200 { /* ARMv6k */
27201 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27202 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27203 },
27204 };
d9235011 27205 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
27206 {
27207 { /* Thumb-1 */
27208 {0xc0, 0x46}, /* LE */
27209 {0x46, 0xc0}, /* BE */
27210 },
27211 { /* Thumb-2 */
27212 {0x00, 0xbf}, /* LE */
27213 {0xbf, 0x00} /* BE */
27214 }
27215 };
d9235011 27216 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
27217 { /* Wide Thumb-2 */
27218 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27219 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27220 };
c921be7d 27221
e7495e45 27222 unsigned bytes, fix, noop_size;
c19d1205 27223 char * p;
d9235011
TS
27224 const unsigned char * noop;
27225 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
27226#ifdef OBJ_ELF
27227 enum mstate state;
27228#endif
bfae80f2 27229
c19d1205 27230 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
27231 return;
27232
c19d1205
ZW
27233 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27234 p = fragP->fr_literal + fragP->fr_fix;
27235 fix = 0;
bfae80f2 27236
c19d1205
ZW
27237 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27238 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 27239
cd000bff 27240 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 27241
cd000bff 27242 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 27243 {
7f78eb34
JW
27244 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27245 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
27246 {
27247 narrow_noop = thumb_noop[1][target_big_endian];
27248 noop = wide_thumb_noop[target_big_endian];
27249 }
c19d1205 27250 else
e7495e45
NS
27251 noop = thumb_noop[0][target_big_endian];
27252 noop_size = 2;
cd000bff
DJ
27253#ifdef OBJ_ELF
27254 state = MAP_THUMB;
27255#endif
7ed4c4c5
NC
27256 }
27257 else
27258 {
7f78eb34
JW
27259 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27260 ? selected_cpu : arm_arch_none,
27261 arm_ext_v6k) != 0]
e7495e45
NS
27262 [target_big_endian];
27263 noop_size = 4;
cd000bff
DJ
27264#ifdef OBJ_ELF
27265 state = MAP_ARM;
27266#endif
7ed4c4c5 27267 }
c921be7d 27268
e7495e45 27269 fragP->fr_var = noop_size;
c921be7d 27270
c19d1205 27271 if (bytes & (noop_size - 1))
7ed4c4c5 27272 {
c19d1205 27273 fix = bytes & (noop_size - 1);
cd000bff
DJ
27274#ifdef OBJ_ELF
27275 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27276#endif
c19d1205
ZW
27277 memset (p, 0, fix);
27278 p += fix;
27279 bytes -= fix;
a737bd4d 27280 }
a737bd4d 27281
e7495e45
NS
27282 if (narrow_noop)
27283 {
27284 if (bytes & noop_size)
27285 {
27286 /* Insert a narrow noop. */
27287 memcpy (p, narrow_noop, noop_size);
27288 p += noop_size;
27289 bytes -= noop_size;
27290 fix += noop_size;
27291 }
27292
27293 /* Use wide noops for the remainder */
27294 noop_size = 4;
27295 }
27296
c19d1205 27297 while (bytes >= noop_size)
a737bd4d 27298 {
c19d1205
ZW
27299 memcpy (p, noop, noop_size);
27300 p += noop_size;
27301 bytes -= noop_size;
27302 fix += noop_size;
a737bd4d
NC
27303 }
27304
c19d1205 27305 fragP->fr_fix += fix;
a737bd4d
NC
27306}
27307
c19d1205
ZW
27308/* Called from md_do_align. Used to create an alignment
27309 frag in a code section. */
27310
27311void
27312arm_frag_align_code (int n, int max)
bfae80f2 27313{
c19d1205 27314 char * p;
7ed4c4c5 27315
c19d1205 27316 /* We assume that there will never be a requirement
6ec8e702 27317 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 27318 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
27319 {
27320 char err_msg[128];
27321
fa94de6b 27322 sprintf (err_msg,
477330fc
RM
27323 _("alignments greater than %d bytes not supported in .text sections."),
27324 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 27325 as_fatal ("%s", err_msg);
6ec8e702 27326 }
bfae80f2 27327
c19d1205
ZW
27328 p = frag_var (rs_align_code,
27329 MAX_MEM_FOR_RS_ALIGN_CODE,
27330 1,
27331 (relax_substateT) max,
27332 (symbolS *) NULL,
27333 (offsetT) n,
27334 (char *) NULL);
27335 *p = 0;
27336}
bfae80f2 27337
8dc2430f
NC
27338/* Perform target specific initialisation of a frag.
27339 Note - despite the name this initialisation is not done when the frag
27340 is created, but only when its type is assigned. A frag can be created
27341 and used a long time before its type is set, so beware of assuming that
33eaf5de 27342 this initialisation is performed first. */
bfae80f2 27343
cd000bff
DJ
27344#ifndef OBJ_ELF
27345void
27346arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27347{
27348 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 27349 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
27350}
27351
27352#else /* OBJ_ELF is defined. */
c19d1205 27353void
cd000bff 27354arm_init_frag (fragS * fragP, int max_chars)
c19d1205 27355{
e8d84ca1 27356 bfd_boolean frag_thumb_mode;
b968d18a 27357
8dc2430f
NC
27358 /* If the current ARM vs THUMB mode has not already
27359 been recorded into this frag then do so now. */
cd000bff 27360 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
27361 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27362
e8d84ca1
NC
27363 /* PR 21809: Do not set a mapping state for debug sections
27364 - it just confuses other tools. */
fd361982 27365 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
e8d84ca1
NC
27366 return;
27367
b968d18a 27368 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 27369
f9c1b181
RL
27370 /* Record a mapping symbol for alignment frags. We will delete this
27371 later if the alignment ends up empty. */
27372 switch (fragP->fr_type)
27373 {
27374 case rs_align:
27375 case rs_align_test:
27376 case rs_fill:
27377 mapping_state_2 (MAP_DATA, max_chars);
27378 break;
27379 case rs_align_code:
b968d18a 27380 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
27381 break;
27382 default:
27383 break;
cd000bff 27384 }
bfae80f2
RE
27385}
27386
c19d1205
ZW
27387/* When we change sections we need to issue a new mapping symbol. */
27388
27389void
27390arm_elf_change_section (void)
bfae80f2 27391{
c19d1205
ZW
27392 /* Link an unlinked unwind index table section to the .text section. */
27393 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27394 && elf_linked_to_section (now_seg) == NULL)
27395 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
27396}
27397
c19d1205
ZW
27398int
27399arm_elf_section_type (const char * str, size_t len)
e45d0630 27400{
c19d1205
ZW
27401 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27402 return SHT_ARM_EXIDX;
e45d0630 27403
c19d1205
ZW
27404 return -1;
27405}
27406\f
27407/* Code to deal with unwinding tables. */
e45d0630 27408
c19d1205 27409static void add_unwind_adjustsp (offsetT);
e45d0630 27410
5f4273c7 27411/* Generate any deferred unwind frame offset. */
e45d0630 27412
bfae80f2 27413static void
c19d1205 27414flush_pending_unwind (void)
bfae80f2 27415{
c19d1205 27416 offsetT offset;
bfae80f2 27417
c19d1205
ZW
27418 offset = unwind.pending_offset;
27419 unwind.pending_offset = 0;
27420 if (offset != 0)
27421 add_unwind_adjustsp (offset);
bfae80f2
RE
27422}
27423
c19d1205
ZW
27424/* Add an opcode to this list for this function. Two-byte opcodes should
27425 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27426 order. */
27427
bfae80f2 27428static void
c19d1205 27429add_unwind_opcode (valueT op, int length)
bfae80f2 27430{
c19d1205
ZW
27431 /* Add any deferred stack adjustment. */
27432 if (unwind.pending_offset)
27433 flush_pending_unwind ();
bfae80f2 27434
c19d1205 27435 unwind.sp_restored = 0;
bfae80f2 27436
c19d1205 27437 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 27438 {
c19d1205
ZW
27439 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27440 if (unwind.opcodes)
325801bd
TS
27441 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27442 unwind.opcode_alloc);
c19d1205 27443 else
325801bd 27444 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 27445 }
c19d1205 27446 while (length > 0)
bfae80f2 27447 {
c19d1205
ZW
27448 length--;
27449 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27450 op >>= 8;
27451 unwind.opcode_count++;
bfae80f2 27452 }
bfae80f2
RE
27453}
27454
c19d1205
ZW
27455/* Add unwind opcodes to adjust the stack pointer. */
27456
bfae80f2 27457static void
c19d1205 27458add_unwind_adjustsp (offsetT offset)
bfae80f2 27459{
c19d1205 27460 valueT op;
bfae80f2 27461
c19d1205 27462 if (offset > 0x200)
bfae80f2 27463 {
c19d1205
ZW
27464 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27465 char bytes[5];
27466 int n;
27467 valueT o;
bfae80f2 27468
c19d1205
ZW
27469 /* Long form: 0xb2, uleb128. */
27470 /* This might not fit in a word so add the individual bytes,
27471 remembering the list is built in reverse order. */
27472 o = (valueT) ((offset - 0x204) >> 2);
27473 if (o == 0)
27474 add_unwind_opcode (0, 1);
bfae80f2 27475
c19d1205
ZW
27476 /* Calculate the uleb128 encoding of the offset. */
27477 n = 0;
27478 while (o)
27479 {
27480 bytes[n] = o & 0x7f;
27481 o >>= 7;
27482 if (o)
27483 bytes[n] |= 0x80;
27484 n++;
27485 }
27486 /* Add the insn. */
27487 for (; n; n--)
27488 add_unwind_opcode (bytes[n - 1], 1);
27489 add_unwind_opcode (0xb2, 1);
27490 }
27491 else if (offset > 0x100)
bfae80f2 27492 {
c19d1205
ZW
27493 /* Two short opcodes. */
27494 add_unwind_opcode (0x3f, 1);
27495 op = (offset - 0x104) >> 2;
27496 add_unwind_opcode (op, 1);
bfae80f2 27497 }
c19d1205
ZW
27498 else if (offset > 0)
27499 {
27500 /* Short opcode. */
27501 op = (offset - 4) >> 2;
27502 add_unwind_opcode (op, 1);
27503 }
27504 else if (offset < 0)
bfae80f2 27505 {
c19d1205
ZW
27506 offset = -offset;
27507 while (offset > 0x100)
bfae80f2 27508 {
c19d1205
ZW
27509 add_unwind_opcode (0x7f, 1);
27510 offset -= 0x100;
bfae80f2 27511 }
c19d1205
ZW
27512 op = ((offset - 4) >> 2) | 0x40;
27513 add_unwind_opcode (op, 1);
bfae80f2 27514 }
bfae80f2
RE
27515}
27516
c19d1205 27517/* Finish the list of unwind opcodes for this function. */
0198d5e6 27518
c19d1205
ZW
27519static void
27520finish_unwind_opcodes (void)
bfae80f2 27521{
c19d1205 27522 valueT op;
bfae80f2 27523
c19d1205 27524 if (unwind.fp_used)
bfae80f2 27525 {
708587a4 27526 /* Adjust sp as necessary. */
c19d1205
ZW
27527 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27528 flush_pending_unwind ();
bfae80f2 27529
c19d1205
ZW
27530 /* After restoring sp from the frame pointer. */
27531 op = 0x90 | unwind.fp_reg;
27532 add_unwind_opcode (op, 1);
27533 }
27534 else
27535 flush_pending_unwind ();
bfae80f2
RE
27536}
27537
bfae80f2 27538
c19d1205
ZW
27539/* Start an exception table entry. If idx is nonzero this is an index table
27540 entry. */
bfae80f2
RE
27541
27542static void
c19d1205 27543start_unwind_section (const segT text_seg, int idx)
bfae80f2 27544{
c19d1205
ZW
27545 const char * text_name;
27546 const char * prefix;
27547 const char * prefix_once;
a8c4d40b 27548 struct elf_section_match match;
c19d1205 27549 char * sec_name;
c19d1205
ZW
27550 int type;
27551 int flags;
27552 int linkonce;
bfae80f2 27553
c19d1205 27554 if (idx)
bfae80f2 27555 {
c19d1205
ZW
27556 prefix = ELF_STRING_ARM_unwind;
27557 prefix_once = ELF_STRING_ARM_unwind_once;
27558 type = SHT_ARM_EXIDX;
bfae80f2 27559 }
c19d1205 27560 else
bfae80f2 27561 {
c19d1205
ZW
27562 prefix = ELF_STRING_ARM_unwind_info;
27563 prefix_once = ELF_STRING_ARM_unwind_info_once;
27564 type = SHT_PROGBITS;
bfae80f2
RE
27565 }
27566
c19d1205
ZW
27567 text_name = segment_name (text_seg);
27568 if (streq (text_name, ".text"))
27569 text_name = "";
27570
27571 if (strncmp (text_name, ".gnu.linkonce.t.",
27572 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 27573 {
c19d1205
ZW
27574 prefix = prefix_once;
27575 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
27576 }
27577
29a2809e 27578 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 27579
c19d1205
ZW
27580 flags = SHF_ALLOC;
27581 linkonce = 0;
a8c4d40b 27582 memset (&match, 0, sizeof (match));
bfae80f2 27583
c19d1205
ZW
27584 /* Handle COMDAT group. */
27585 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 27586 {
a8c4d40b
L
27587 match.group_name = elf_group_name (text_seg);
27588 if (match.group_name == NULL)
c19d1205 27589 {
bd3ba5d1 27590 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
27591 segment_name (text_seg));
27592 ignore_rest_of_line ();
27593 return;
27594 }
27595 flags |= SHF_GROUP;
27596 linkonce = 1;
bfae80f2
RE
27597 }
27598
a8c4d40b 27599 obj_elf_change_section (sec_name, type, flags, 0, &match,
a91e1603 27600 linkonce, 0);
bfae80f2 27601
5f4273c7 27602 /* Set the section link for index tables. */
c19d1205
ZW
27603 if (idx)
27604 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
27605}
27606
bfae80f2 27607
c19d1205
ZW
27608/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27609 personality routine data. Returns zero, or the index table value for
cad0da33 27610 an inline entry. */
c19d1205
ZW
27611
27612static valueT
27613create_unwind_entry (int have_data)
bfae80f2 27614{
c19d1205
ZW
27615 int size;
27616 addressT where;
27617 char *ptr;
27618 /* The current word of data. */
27619 valueT data;
27620 /* The number of bytes left in this word. */
27621 int n;
bfae80f2 27622
c19d1205 27623 finish_unwind_opcodes ();
bfae80f2 27624
c19d1205
ZW
27625 /* Remember the current text section. */
27626 unwind.saved_seg = now_seg;
27627 unwind.saved_subseg = now_subseg;
bfae80f2 27628
c19d1205 27629 start_unwind_section (now_seg, 0);
bfae80f2 27630
c19d1205 27631 if (unwind.personality_routine == NULL)
bfae80f2 27632 {
c19d1205
ZW
27633 if (unwind.personality_index == -2)
27634 {
27635 if (have_data)
5f4273c7 27636 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
27637 return 1; /* EXIDX_CANTUNWIND. */
27638 }
bfae80f2 27639
c19d1205
ZW
27640 /* Use a default personality routine if none is specified. */
27641 if (unwind.personality_index == -1)
27642 {
27643 if (unwind.opcode_count > 3)
27644 unwind.personality_index = 1;
27645 else
27646 unwind.personality_index = 0;
27647 }
bfae80f2 27648
c19d1205
ZW
27649 /* Space for the personality routine entry. */
27650 if (unwind.personality_index == 0)
27651 {
27652 if (unwind.opcode_count > 3)
27653 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 27654
c19d1205
ZW
27655 if (!have_data)
27656 {
27657 /* All the data is inline in the index table. */
27658 data = 0x80;
27659 n = 3;
27660 while (unwind.opcode_count > 0)
27661 {
27662 unwind.opcode_count--;
27663 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27664 n--;
27665 }
bfae80f2 27666
c19d1205
ZW
27667 /* Pad with "finish" opcodes. */
27668 while (n--)
27669 data = (data << 8) | 0xb0;
bfae80f2 27670
c19d1205
ZW
27671 return data;
27672 }
27673 size = 0;
27674 }
27675 else
27676 /* We get two opcodes "free" in the first word. */
27677 size = unwind.opcode_count - 2;
27678 }
27679 else
5011093d 27680 {
cad0da33
NC
27681 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27682 if (unwind.personality_index != -1)
27683 {
27684 as_bad (_("attempt to recreate an unwind entry"));
27685 return 1;
27686 }
5011093d
NC
27687
27688 /* An extra byte is required for the opcode count. */
27689 size = unwind.opcode_count + 1;
27690 }
bfae80f2 27691
c19d1205
ZW
27692 size = (size + 3) >> 2;
27693 if (size > 0xff)
27694 as_bad (_("too many unwind opcodes"));
bfae80f2 27695
c19d1205
ZW
27696 frag_align (2, 0, 0);
27697 record_alignment (now_seg, 2);
27698 unwind.table_entry = expr_build_dot ();
27699
27700 /* Allocate the table entry. */
27701 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
27702 /* PR 13449: Zero the table entries in case some of them are not used. */
27703 memset (ptr, 0, (size << 2) + 4);
c19d1205 27704 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 27705
c19d1205 27706 switch (unwind.personality_index)
bfae80f2 27707 {
c19d1205
ZW
27708 case -1:
27709 /* ??? Should this be a PLT generating relocation? */
27710 /* Custom personality routine. */
27711 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27712 BFD_RELOC_ARM_PREL31);
bfae80f2 27713
c19d1205
ZW
27714 where += 4;
27715 ptr += 4;
bfae80f2 27716
c19d1205 27717 /* Set the first byte to the number of additional words. */
5011093d 27718 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
27719 n = 3;
27720 break;
bfae80f2 27721
c19d1205
ZW
27722 /* ABI defined personality routines. */
27723 case 0:
27724 /* Three opcodes bytes are packed into the first word. */
27725 data = 0x80;
27726 n = 3;
27727 break;
bfae80f2 27728
c19d1205
ZW
27729 case 1:
27730 case 2:
27731 /* The size and first two opcode bytes go in the first word. */
27732 data = ((0x80 + unwind.personality_index) << 8) | size;
27733 n = 2;
27734 break;
bfae80f2 27735
c19d1205
ZW
27736 default:
27737 /* Should never happen. */
27738 abort ();
27739 }
bfae80f2 27740
c19d1205
ZW
27741 /* Pack the opcodes into words (MSB first), reversing the list at the same
27742 time. */
27743 while (unwind.opcode_count > 0)
27744 {
27745 if (n == 0)
27746 {
27747 md_number_to_chars (ptr, data, 4);
27748 ptr += 4;
27749 n = 4;
27750 data = 0;
27751 }
27752 unwind.opcode_count--;
27753 n--;
27754 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27755 }
27756
27757 /* Finish off the last word. */
27758 if (n < 4)
27759 {
27760 /* Pad with "finish" opcodes. */
27761 while (n--)
27762 data = (data << 8) | 0xb0;
27763
27764 md_number_to_chars (ptr, data, 4);
27765 }
27766
27767 if (!have_data)
27768 {
27769 /* Add an empty descriptor if there is no user-specified data. */
27770 ptr = frag_more (4);
27771 md_number_to_chars (ptr, 0, 4);
27772 }
27773
27774 return 0;
bfae80f2
RE
27775}
27776
f0927246
NC
27777
27778/* Initialize the DWARF-2 unwind information for this procedure. */
27779
27780void
27781tc_arm_frame_initial_instructions (void)
27782{
27783 cfi_add_CFA_def_cfa (REG_SP, 0);
27784}
27785#endif /* OBJ_ELF */
27786
c19d1205
ZW
27787/* Convert REGNAME to a DWARF-2 register number. */
27788
27789int
1df69f4f 27790tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 27791{
1df69f4f 27792 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
27793 if (reg != FAIL)
27794 return reg;
c19d1205 27795
1f5afe1c
NC
27796 /* PR 16694: Allow VFP registers as well. */
27797 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27798 if (reg != FAIL)
27799 return 64 + reg;
c19d1205 27800
1f5afe1c
NC
27801 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27802 if (reg != FAIL)
27803 return reg + 256;
27804
0198d5e6 27805 return FAIL;
bfae80f2
RE
27806}
27807
f0927246 27808#ifdef TE_PE
c19d1205 27809void
f0927246 27810tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 27811{
91d6fa6a 27812 expressionS exp;
bfae80f2 27813
91d6fa6a
NC
27814 exp.X_op = O_secrel;
27815 exp.X_add_symbol = symbol;
27816 exp.X_add_number = 0;
27817 emit_expr (&exp, size);
f0927246
NC
27818}
27819#endif
bfae80f2 27820
c19d1205 27821/* MD interface: Symbol and relocation handling. */
bfae80f2 27822
2fc8bdac
ZW
27823/* Return the address within the segment that a PC-relative fixup is
27824 relative to. For ARM, PC-relative fixups applied to instructions
27825 are generally relative to the location of the fixup plus 8 bytes.
27826 Thumb branches are offset by 4, and Thumb loads relative to PC
27827 require special handling. */
bfae80f2 27828
c19d1205 27829long
2fc8bdac 27830md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 27831{
2fc8bdac
ZW
27832 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27833
27834 /* If this is pc-relative and we are going to emit a relocation
27835 then we just want to put out any pipeline compensation that the linker
53baae48
NC
27836 will need. Otherwise we want to use the calculated base.
27837 For WinCE we skip the bias for externals as well, since this
27838 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 27839 if (fixP->fx_pcrel
2fc8bdac 27840 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
27841 || (arm_force_relocation (fixP)
27842#ifdef TE_WINCE
27843 && !S_IS_EXTERNAL (fixP->fx_addsy)
27844#endif
27845 )))
2fc8bdac 27846 base = 0;
bfae80f2 27847
267bf995 27848
c19d1205 27849 switch (fixP->fx_r_type)
bfae80f2 27850 {
2fc8bdac
ZW
27851 /* PC relative addressing on the Thumb is slightly odd as the
27852 bottom two bits of the PC are forced to zero for the
27853 calculation. This happens *after* application of the
27854 pipeline offset. However, Thumb adrl already adjusts for
27855 this, so we need not do it again. */
c19d1205 27856 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 27857 return base & ~3;
c19d1205
ZW
27858
27859 case BFD_RELOC_ARM_THUMB_OFFSET:
27860 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 27861 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 27862 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 27863 return (base + 4) & ~3;
c19d1205 27864
2fc8bdac 27865 /* Thumb branches are simply offset by +4. */
e12437dc 27866 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
27867 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27868 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27869 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27870 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 27871 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 27872 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 27873 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 27874 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 27875 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 27876 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 27877 return base + 4;
bfae80f2 27878
267bf995 27879 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
27880 if (fixP->fx_addsy
27881 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27882 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 27883 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
27884 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27885 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
27886 return base + 4;
27887
00adf2d4
JB
27888 /* BLX is like branches above, but forces the low two bits of PC to
27889 zero. */
486499d0
CL
27890 case BFD_RELOC_THUMB_PCREL_BLX:
27891 if (fixP->fx_addsy
27892 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27893 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27894 && THUMB_IS_FUNC (fixP->fx_addsy)
27895 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27896 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
27897 return (base + 4) & ~3;
27898
2fc8bdac
ZW
27899 /* ARM mode branches are offset by +8. However, the Windows CE
27900 loader expects the relocation not to take this into account. */
267bf995 27901 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
27902 if (fixP->fx_addsy
27903 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27904 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27905 && ARM_IS_FUNC (fixP->fx_addsy)
27906 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27907 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27908 return base + 8;
267bf995 27909
486499d0
CL
27910 case BFD_RELOC_ARM_PCREL_CALL:
27911 if (fixP->fx_addsy
27912 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27913 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27914 && THUMB_IS_FUNC (fixP->fx_addsy)
27915 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27916 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27917 return base + 8;
267bf995 27918
2fc8bdac 27919 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 27920 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 27921 case BFD_RELOC_ARM_PLT32:
c19d1205 27922#ifdef TE_WINCE
5f4273c7 27923 /* When handling fixups immediately, because we have already
477330fc 27924 discovered the value of a symbol, or the address of the frag involved
53baae48 27925 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
27926 see fixup_segment() in write.c
27927 The S_IS_EXTERNAL test handles the case of global symbols.
27928 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
27929 if (fixP->fx_pcrel
27930 && fixP->fx_addsy != NULL
27931 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27932 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27933 return base + 8;
2fc8bdac 27934 return base;
c19d1205 27935#else
2fc8bdac 27936 return base + 8;
c19d1205 27937#endif
2fc8bdac 27938
267bf995 27939
2fc8bdac
ZW
27940 /* ARM mode loads relative to PC are also offset by +8. Unlike
27941 branches, the Windows CE loader *does* expect the relocation
27942 to take this into account. */
27943 case BFD_RELOC_ARM_OFFSET_IMM:
27944 case BFD_RELOC_ARM_OFFSET_IMM8:
27945 case BFD_RELOC_ARM_HWLITERAL:
27946 case BFD_RELOC_ARM_LITERAL:
27947 case BFD_RELOC_ARM_CP_OFF_IMM:
27948 return base + 8;
27949
27950
27951 /* Other PC-relative relocations are un-offset. */
27952 default:
27953 return base;
27954 }
bfae80f2
RE
27955}
27956
8b2d793c
NC
27957static bfd_boolean flag_warn_syms = TRUE;
27958
ae8714c2
NC
27959bfd_boolean
27960arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27961{
8b2d793c
NC
27962 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27963 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27964 does mean that the resulting code might be very confusing to the reader.
27965 Also this warning can be triggered if the user omits an operand before
27966 an immediate address, eg:
27967
27968 LDR =foo
27969
27970 GAS treats this as an assignment of the value of the symbol foo to a
27971 symbol LDR, and so (without this code) it will not issue any kind of
27972 warning or error message.
27973
27974 Note - ARM instructions are case-insensitive but the strings in the hash
27975 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27976 lower case too. */
27977 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27978 {
27979 char * nbuf = strdup (name);
27980 char * p;
27981
27982 for (p = nbuf; *p; p++)
27983 *p = TOLOWER (*p);
27984 if (hash_find (arm_ops_hsh, nbuf) != NULL)
27985 {
27986 static struct hash_control * already_warned = NULL;
27987
27988 if (already_warned == NULL)
27989 already_warned = hash_new ();
27990 /* Only warn about the symbol once. To keep the code
27991 simple we let hash_insert do the lookup for us. */
3076e594 27992 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 27993 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
27994 }
27995 else
27996 free (nbuf);
27997 }
3739860c 27998
ae8714c2
NC
27999 return FALSE;
28000}
28001
28002/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28003 Otherwise we have no need to default values of symbols. */
28004
28005symbolS *
28006md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28007{
28008#ifdef OBJ_ELF
28009 if (name[0] == '_' && name[1] == 'G'
28010 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28011 {
28012 if (!GOT_symbol)
28013 {
28014 if (symbol_find (name))
28015 as_bad (_("GOT already in the symbol table"));
28016
28017 GOT_symbol = symbol_new (name, undefined_section,
28018 (valueT) 0, & zero_address_frag);
28019 }
28020
28021 return GOT_symbol;
28022 }
28023#endif
28024
c921be7d 28025 return NULL;
bfae80f2
RE
28026}
28027
55cf6793 28028/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
28029 computed as two separate immediate values, added together. We
28030 already know that this value cannot be computed by just one ARM
28031 instruction. */
28032
28033static unsigned int
28034validate_immediate_twopart (unsigned int val,
28035 unsigned int * highpart)
bfae80f2 28036{
c19d1205
ZW
28037 unsigned int a;
28038 unsigned int i;
bfae80f2 28039
c19d1205
ZW
28040 for (i = 0; i < 32; i += 2)
28041 if (((a = rotate_left (val, i)) & 0xff) != 0)
28042 {
28043 if (a & 0xff00)
28044 {
28045 if (a & ~ 0xffff)
28046 continue;
28047 * highpart = (a >> 8) | ((i + 24) << 7);
28048 }
28049 else if (a & 0xff0000)
28050 {
28051 if (a & 0xff000000)
28052 continue;
28053 * highpart = (a >> 16) | ((i + 16) << 7);
28054 }
28055 else
28056 {
9c2799c2 28057 gas_assert (a & 0xff000000);
c19d1205
ZW
28058 * highpart = (a >> 24) | ((i + 8) << 7);
28059 }
bfae80f2 28060
c19d1205
ZW
28061 return (a & 0xff) | (i << 7);
28062 }
bfae80f2 28063
c19d1205 28064 return FAIL;
bfae80f2
RE
28065}
28066
c19d1205
ZW
28067static int
28068validate_offset_imm (unsigned int val, int hwse)
28069{
28070 if ((hwse && val > 255) || val > 4095)
28071 return FAIL;
28072 return val;
28073}
bfae80f2 28074
55cf6793 28075/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
28076 negative immediate constant by altering the instruction. A bit of
28077 a hack really.
28078 MOV <-> MVN
28079 AND <-> BIC
28080 ADC <-> SBC
28081 by inverting the second operand, and
28082 ADD <-> SUB
28083 CMP <-> CMN
28084 by negating the second operand. */
bfae80f2 28085
c19d1205
ZW
28086static int
28087negate_data_op (unsigned long * instruction,
28088 unsigned long value)
bfae80f2 28089{
c19d1205
ZW
28090 int op, new_inst;
28091 unsigned long negated, inverted;
bfae80f2 28092
c19d1205
ZW
28093 negated = encode_arm_immediate (-value);
28094 inverted = encode_arm_immediate (~value);
bfae80f2 28095
c19d1205
ZW
28096 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28097 switch (op)
bfae80f2 28098 {
c19d1205
ZW
28099 /* First negates. */
28100 case OPCODE_SUB: /* ADD <-> SUB */
28101 new_inst = OPCODE_ADD;
28102 value = negated;
28103 break;
bfae80f2 28104
c19d1205
ZW
28105 case OPCODE_ADD:
28106 new_inst = OPCODE_SUB;
28107 value = negated;
28108 break;
bfae80f2 28109
c19d1205
ZW
28110 case OPCODE_CMP: /* CMP <-> CMN */
28111 new_inst = OPCODE_CMN;
28112 value = negated;
28113 break;
bfae80f2 28114
c19d1205
ZW
28115 case OPCODE_CMN:
28116 new_inst = OPCODE_CMP;
28117 value = negated;
28118 break;
bfae80f2 28119
c19d1205
ZW
28120 /* Now Inverted ops. */
28121 case OPCODE_MOV: /* MOV <-> MVN */
28122 new_inst = OPCODE_MVN;
28123 value = inverted;
28124 break;
bfae80f2 28125
c19d1205
ZW
28126 case OPCODE_MVN:
28127 new_inst = OPCODE_MOV;
28128 value = inverted;
28129 break;
bfae80f2 28130
c19d1205
ZW
28131 case OPCODE_AND: /* AND <-> BIC */
28132 new_inst = OPCODE_BIC;
28133 value = inverted;
28134 break;
bfae80f2 28135
c19d1205
ZW
28136 case OPCODE_BIC:
28137 new_inst = OPCODE_AND;
28138 value = inverted;
28139 break;
bfae80f2 28140
c19d1205
ZW
28141 case OPCODE_ADC: /* ADC <-> SBC */
28142 new_inst = OPCODE_SBC;
28143 value = inverted;
28144 break;
bfae80f2 28145
c19d1205
ZW
28146 case OPCODE_SBC:
28147 new_inst = OPCODE_ADC;
28148 value = inverted;
28149 break;
bfae80f2 28150
c19d1205
ZW
28151 /* We cannot do anything. */
28152 default:
28153 return FAIL;
b99bd4ef
NC
28154 }
28155
c19d1205
ZW
28156 if (value == (unsigned) FAIL)
28157 return FAIL;
28158
28159 *instruction &= OPCODE_MASK;
28160 *instruction |= new_inst << DATA_OP_SHIFT;
28161 return value;
b99bd4ef
NC
28162}
28163
ef8d22e6
PB
28164/* Like negate_data_op, but for Thumb-2. */
28165
28166static unsigned int
16dd5e42 28167thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
28168{
28169 int op, new_inst;
28170 int rd;
16dd5e42 28171 unsigned int negated, inverted;
ef8d22e6
PB
28172
28173 negated = encode_thumb32_immediate (-value);
28174 inverted = encode_thumb32_immediate (~value);
28175
28176 rd = (*instruction >> 8) & 0xf;
28177 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28178 switch (op)
28179 {
28180 /* ADD <-> SUB. Includes CMP <-> CMN. */
28181 case T2_OPCODE_SUB:
28182 new_inst = T2_OPCODE_ADD;
28183 value = negated;
28184 break;
28185
28186 case T2_OPCODE_ADD:
28187 new_inst = T2_OPCODE_SUB;
28188 value = negated;
28189 break;
28190
28191 /* ORR <-> ORN. Includes MOV <-> MVN. */
28192 case T2_OPCODE_ORR:
28193 new_inst = T2_OPCODE_ORN;
28194 value = inverted;
28195 break;
28196
28197 case T2_OPCODE_ORN:
28198 new_inst = T2_OPCODE_ORR;
28199 value = inverted;
28200 break;
28201
28202 /* AND <-> BIC. TST has no inverted equivalent. */
28203 case T2_OPCODE_AND:
28204 new_inst = T2_OPCODE_BIC;
28205 if (rd == 15)
28206 value = FAIL;
28207 else
28208 value = inverted;
28209 break;
28210
28211 case T2_OPCODE_BIC:
28212 new_inst = T2_OPCODE_AND;
28213 value = inverted;
28214 break;
28215
28216 /* ADC <-> SBC */
28217 case T2_OPCODE_ADC:
28218 new_inst = T2_OPCODE_SBC;
28219 value = inverted;
28220 break;
28221
28222 case T2_OPCODE_SBC:
28223 new_inst = T2_OPCODE_ADC;
28224 value = inverted;
28225 break;
28226
28227 /* We cannot do anything. */
28228 default:
28229 return FAIL;
28230 }
28231
16dd5e42 28232 if (value == (unsigned int)FAIL)
ef8d22e6
PB
28233 return FAIL;
28234
28235 *instruction &= T2_OPCODE_MASK;
28236 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28237 return value;
28238}
28239
8f06b2d8 28240/* Read a 32-bit thumb instruction from buf. */
0198d5e6 28241
8f06b2d8
PB
28242static unsigned long
28243get_thumb32_insn (char * buf)
28244{
28245 unsigned long insn;
28246 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28247 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28248
28249 return insn;
28250}
28251
a8bc6c78
PB
28252/* We usually want to set the low bit on the address of thumb function
28253 symbols. In particular .word foo - . should have the low bit set.
28254 Generic code tries to fold the difference of two symbols to
28255 a constant. Prevent this and force a relocation when the first symbols
28256 is a thumb function. */
c921be7d
NC
28257
28258bfd_boolean
a8bc6c78
PB
28259arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28260{
28261 if (op == O_subtract
28262 && l->X_op == O_symbol
28263 && r->X_op == O_symbol
28264 && THUMB_IS_FUNC (l->X_add_symbol))
28265 {
28266 l->X_op = O_subtract;
28267 l->X_op_symbol = r->X_add_symbol;
28268 l->X_add_number -= r->X_add_number;
c921be7d 28269 return TRUE;
a8bc6c78 28270 }
c921be7d 28271
a8bc6c78 28272 /* Process as normal. */
c921be7d 28273 return FALSE;
a8bc6c78
PB
28274}
28275
4a42ebbc
RR
28276/* Encode Thumb2 unconditional branches and calls. The encoding
28277 for the 2 are identical for the immediate values. */
28278
28279static void
28280encode_thumb2_b_bl_offset (char * buf, offsetT value)
28281{
28282#define T2I1I2MASK ((1 << 13) | (1 << 11))
28283 offsetT newval;
28284 offsetT newval2;
28285 addressT S, I1, I2, lo, hi;
28286
28287 S = (value >> 24) & 0x01;
28288 I1 = (value >> 23) & 0x01;
28289 I2 = (value >> 22) & 0x01;
28290 hi = (value >> 12) & 0x3ff;
fa94de6b 28291 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
28292 newval = md_chars_to_number (buf, THUMB_SIZE);
28293 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28294 newval |= (S << 10) | hi;
28295 newval2 &= ~T2I1I2MASK;
28296 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28297 md_number_to_chars (buf, newval, THUMB_SIZE);
28298 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28299}
28300
c19d1205 28301void
55cf6793 28302md_apply_fix (fixS * fixP,
c19d1205
ZW
28303 valueT * valP,
28304 segT seg)
28305{
28306 offsetT value = * valP;
28307 offsetT newval;
28308 unsigned int newimm;
28309 unsigned long temp;
28310 int sign;
28311 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 28312
9c2799c2 28313 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 28314
c19d1205 28315 /* Note whether this will delete the relocation. */
4962c51a 28316
c19d1205
ZW
28317 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28318 fixP->fx_done = 1;
b99bd4ef 28319
adbaf948 28320 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 28321 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
28322 for emit_reloc. */
28323 value &= 0xffffffff;
28324 value ^= 0x80000000;
5f4273c7 28325 value -= 0x80000000;
adbaf948
ZW
28326
28327 *valP = value;
c19d1205 28328 fixP->fx_addnumber = value;
b99bd4ef 28329
adbaf948
ZW
28330 /* Same treatment for fixP->fx_offset. */
28331 fixP->fx_offset &= 0xffffffff;
28332 fixP->fx_offset ^= 0x80000000;
28333 fixP->fx_offset -= 0x80000000;
28334
c19d1205 28335 switch (fixP->fx_r_type)
b99bd4ef 28336 {
c19d1205
ZW
28337 case BFD_RELOC_NONE:
28338 /* This will need to go in the object file. */
28339 fixP->fx_done = 0;
28340 break;
b99bd4ef 28341
c19d1205
ZW
28342 case BFD_RELOC_ARM_IMMEDIATE:
28343 /* We claim that this fixup has been processed here,
28344 even if in fact we generate an error because we do
28345 not have a reloc for it, so tc_gen_reloc will reject it. */
28346 fixP->fx_done = 1;
b99bd4ef 28347
77db8e2e 28348 if (fixP->fx_addsy)
b99bd4ef 28349 {
77db8e2e 28350 const char *msg = 0;
b99bd4ef 28351
77db8e2e
NC
28352 if (! S_IS_DEFINED (fixP->fx_addsy))
28353 msg = _("undefined symbol %s used as an immediate value");
28354 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28355 msg = _("symbol %s is in a different section");
28356 else if (S_IS_WEAK (fixP->fx_addsy))
28357 msg = _("symbol %s is weak and may be overridden later");
28358
28359 if (msg)
28360 {
28361 as_bad_where (fixP->fx_file, fixP->fx_line,
28362 msg, S_GET_NAME (fixP->fx_addsy));
28363 break;
28364 }
42e5fcbf
AS
28365 }
28366
c19d1205
ZW
28367 temp = md_chars_to_number (buf, INSN_SIZE);
28368
5e73442d
SL
28369 /* If the offset is negative, we should use encoding A2 for ADR. */
28370 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
28371 newimm = negate_data_op (&temp, value);
28372 else
28373 {
28374 newimm = encode_arm_immediate (value);
28375
28376 /* If the instruction will fail, see if we can fix things up by
28377 changing the opcode. */
28378 if (newimm == (unsigned int) FAIL)
28379 newimm = negate_data_op (&temp, value);
bada4342
JW
28380 /* MOV accepts both ARM modified immediate (A1 encoding) and
28381 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28382 When disassembling, MOV is preferred when there is no encoding
28383 overlap. */
28384 if (newimm == (unsigned int) FAIL
28385 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28386 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28387 && !((temp >> SBIT_SHIFT) & 0x1)
28388 && value >= 0 && value <= 0xffff)
28389 {
28390 /* Clear bits[23:20] to change encoding from A1 to A2. */
28391 temp &= 0xff0fffff;
28392 /* Encoding high 4bits imm. Code below will encode the remaining
28393 low 12bits. */
28394 temp |= (value & 0x0000f000) << 4;
28395 newimm = value & 0x00000fff;
28396 }
5e73442d
SL
28397 }
28398
28399 if (newimm == (unsigned int) FAIL)
b99bd4ef 28400 {
c19d1205
ZW
28401 as_bad_where (fixP->fx_file, fixP->fx_line,
28402 _("invalid constant (%lx) after fixup"),
28403 (unsigned long) value);
28404 break;
b99bd4ef 28405 }
b99bd4ef 28406
c19d1205
ZW
28407 newimm |= (temp & 0xfffff000);
28408 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28409 break;
b99bd4ef 28410
c19d1205
ZW
28411 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28412 {
28413 unsigned int highpart = 0;
28414 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 28415
77db8e2e 28416 if (fixP->fx_addsy)
42e5fcbf 28417 {
77db8e2e 28418 const char *msg = 0;
42e5fcbf 28419
77db8e2e
NC
28420 if (! S_IS_DEFINED (fixP->fx_addsy))
28421 msg = _("undefined symbol %s used as an immediate value");
28422 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28423 msg = _("symbol %s is in a different section");
28424 else if (S_IS_WEAK (fixP->fx_addsy))
28425 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 28426
77db8e2e
NC
28427 if (msg)
28428 {
28429 as_bad_where (fixP->fx_file, fixP->fx_line,
28430 msg, S_GET_NAME (fixP->fx_addsy));
28431 break;
28432 }
28433 }
fa94de6b 28434
c19d1205
ZW
28435 newimm = encode_arm_immediate (value);
28436 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 28437
c19d1205
ZW
28438 /* If the instruction will fail, see if we can fix things up by
28439 changing the opcode. */
28440 if (newimm == (unsigned int) FAIL
28441 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28442 {
28443 /* No ? OK - try using two ADD instructions to generate
28444 the value. */
28445 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 28446
c19d1205
ZW
28447 /* Yes - then make sure that the second instruction is
28448 also an add. */
28449 if (newimm != (unsigned int) FAIL)
28450 newinsn = temp;
28451 /* Still No ? Try using a negated value. */
28452 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28453 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28454 /* Otherwise - give up. */
28455 else
28456 {
28457 as_bad_where (fixP->fx_file, fixP->fx_line,
28458 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28459 (long) value);
28460 break;
28461 }
b99bd4ef 28462
c19d1205
ZW
28463 /* Replace the first operand in the 2nd instruction (which
28464 is the PC) with the destination register. We have
28465 already added in the PC in the first instruction and we
28466 do not want to do it again. */
28467 newinsn &= ~ 0xf0000;
28468 newinsn |= ((newinsn & 0x0f000) << 4);
28469 }
b99bd4ef 28470
c19d1205
ZW
28471 newimm |= (temp & 0xfffff000);
28472 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 28473
c19d1205
ZW
28474 highpart |= (newinsn & 0xfffff000);
28475 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28476 }
28477 break;
b99bd4ef 28478
c19d1205 28479 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
28480 if (!fixP->fx_done && seg->use_rela_p)
28481 value = 0;
1a0670f3 28482 /* Fall through. */
00a97672 28483
c19d1205 28484 case BFD_RELOC_ARM_LITERAL:
26d97720 28485 sign = value > 0;
b99bd4ef 28486
c19d1205
ZW
28487 if (value < 0)
28488 value = - value;
b99bd4ef 28489
c19d1205 28490 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 28491 {
c19d1205
ZW
28492 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28493 as_bad_where (fixP->fx_file, fixP->fx_line,
28494 _("invalid literal constant: pool needs to be closer"));
28495 else
28496 as_bad_where (fixP->fx_file, fixP->fx_line,
28497 _("bad immediate value for offset (%ld)"),
28498 (long) value);
28499 break;
f03698e6
RE
28500 }
28501
c19d1205 28502 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28503 if (value == 0)
28504 newval &= 0xfffff000;
28505 else
28506 {
28507 newval &= 0xff7ff000;
28508 newval |= value | (sign ? INDEX_UP : 0);
28509 }
c19d1205
ZW
28510 md_number_to_chars (buf, newval, INSN_SIZE);
28511 break;
b99bd4ef 28512
c19d1205
ZW
28513 case BFD_RELOC_ARM_OFFSET_IMM8:
28514 case BFD_RELOC_ARM_HWLITERAL:
26d97720 28515 sign = value > 0;
b99bd4ef 28516
c19d1205
ZW
28517 if (value < 0)
28518 value = - value;
b99bd4ef 28519
c19d1205 28520 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 28521 {
c19d1205
ZW
28522 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28523 as_bad_where (fixP->fx_file, fixP->fx_line,
28524 _("invalid literal constant: pool needs to be closer"));
28525 else
427d0db6
RM
28526 as_bad_where (fixP->fx_file, fixP->fx_line,
28527 _("bad immediate value for 8-bit offset (%ld)"),
28528 (long) value);
c19d1205 28529 break;
b99bd4ef
NC
28530 }
28531
c19d1205 28532 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28533 if (value == 0)
28534 newval &= 0xfffff0f0;
28535 else
28536 {
28537 newval &= 0xff7ff0f0;
28538 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28539 }
c19d1205
ZW
28540 md_number_to_chars (buf, newval, INSN_SIZE);
28541 break;
b99bd4ef 28542
c19d1205
ZW
28543 case BFD_RELOC_ARM_T32_OFFSET_U8:
28544 if (value < 0 || value > 1020 || value % 4 != 0)
28545 as_bad_where (fixP->fx_file, fixP->fx_line,
28546 _("bad immediate value for offset (%ld)"), (long) value);
28547 value /= 4;
b99bd4ef 28548
c19d1205 28549 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
28550 newval |= value;
28551 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28552 break;
b99bd4ef 28553
c19d1205
ZW
28554 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28555 /* This is a complicated relocation used for all varieties of Thumb32
28556 load/store instruction with immediate offset:
28557
28558 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 28559 *4, optional writeback(W)
c19d1205
ZW
28560 (doubleword load/store)
28561
28562 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28563 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28564 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28565 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28566 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28567
28568 Uppercase letters indicate bits that are already encoded at
28569 this point. Lowercase letters are our problem. For the
28570 second block of instructions, the secondary opcode nybble
28571 (bits 8..11) is present, and bit 23 is zero, even if this is
28572 a PC-relative operation. */
28573 newval = md_chars_to_number (buf, THUMB_SIZE);
28574 newval <<= 16;
28575 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 28576
c19d1205 28577 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 28578 {
c19d1205
ZW
28579 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28580 if (value >= 0)
28581 newval |= (1 << 23);
28582 else
28583 value = -value;
28584 if (value % 4 != 0)
28585 {
28586 as_bad_where (fixP->fx_file, fixP->fx_line,
28587 _("offset not a multiple of 4"));
28588 break;
28589 }
28590 value /= 4;
216d22bc 28591 if (value > 0xff)
c19d1205
ZW
28592 {
28593 as_bad_where (fixP->fx_file, fixP->fx_line,
28594 _("offset out of range"));
28595 break;
28596 }
28597 newval &= ~0xff;
b99bd4ef 28598 }
c19d1205 28599 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 28600 {
c19d1205
ZW
28601 /* PC-relative, 12-bit offset. */
28602 if (value >= 0)
28603 newval |= (1 << 23);
28604 else
28605 value = -value;
216d22bc 28606 if (value > 0xfff)
c19d1205
ZW
28607 {
28608 as_bad_where (fixP->fx_file, fixP->fx_line,
28609 _("offset out of range"));
28610 break;
28611 }
28612 newval &= ~0xfff;
b99bd4ef 28613 }
c19d1205 28614 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 28615 {
c19d1205
ZW
28616 /* Writeback: 8-bit, +/- offset. */
28617 if (value >= 0)
28618 newval |= (1 << 9);
28619 else
28620 value = -value;
216d22bc 28621 if (value > 0xff)
c19d1205
ZW
28622 {
28623 as_bad_where (fixP->fx_file, fixP->fx_line,
28624 _("offset out of range"));
28625 break;
28626 }
28627 newval &= ~0xff;
b99bd4ef 28628 }
c19d1205 28629 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 28630 {
c19d1205 28631 /* T-instruction: positive 8-bit offset. */
216d22bc 28632 if (value < 0 || value > 0xff)
b99bd4ef 28633 {
c19d1205
ZW
28634 as_bad_where (fixP->fx_file, fixP->fx_line,
28635 _("offset out of range"));
28636 break;
b99bd4ef 28637 }
c19d1205
ZW
28638 newval &= ~0xff;
28639 newval |= value;
b99bd4ef
NC
28640 }
28641 else
b99bd4ef 28642 {
c19d1205
ZW
28643 /* Positive 12-bit or negative 8-bit offset. */
28644 int limit;
28645 if (value >= 0)
b99bd4ef 28646 {
c19d1205
ZW
28647 newval |= (1 << 23);
28648 limit = 0xfff;
28649 }
28650 else
28651 {
28652 value = -value;
28653 limit = 0xff;
28654 }
28655 if (value > limit)
28656 {
28657 as_bad_where (fixP->fx_file, fixP->fx_line,
28658 _("offset out of range"));
28659 break;
b99bd4ef 28660 }
c19d1205 28661 newval &= ~limit;
b99bd4ef 28662 }
b99bd4ef 28663
c19d1205
ZW
28664 newval |= value;
28665 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28666 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28667 break;
404ff6b5 28668
c19d1205
ZW
28669 case BFD_RELOC_ARM_SHIFT_IMM:
28670 newval = md_chars_to_number (buf, INSN_SIZE);
28671 if (((unsigned long) value) > 32
28672 || (value == 32
28673 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28674 {
28675 as_bad_where (fixP->fx_file, fixP->fx_line,
28676 _("shift expression is too large"));
28677 break;
28678 }
404ff6b5 28679
c19d1205
ZW
28680 if (value == 0)
28681 /* Shifts of zero must be done as lsl. */
28682 newval &= ~0x60;
28683 else if (value == 32)
28684 value = 0;
28685 newval &= 0xfffff07f;
28686 newval |= (value & 0x1f) << 7;
28687 md_number_to_chars (buf, newval, INSN_SIZE);
28688 break;
404ff6b5 28689
c19d1205 28690 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 28691 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 28692 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 28693 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
28694 /* We claim that this fixup has been processed here,
28695 even if in fact we generate an error because we do
28696 not have a reloc for it, so tc_gen_reloc will reject it. */
28697 fixP->fx_done = 1;
404ff6b5 28698
c19d1205
ZW
28699 if (fixP->fx_addsy
28700 && ! S_IS_DEFINED (fixP->fx_addsy))
28701 {
28702 as_bad_where (fixP->fx_file, fixP->fx_line,
28703 _("undefined symbol %s used as an immediate value"),
28704 S_GET_NAME (fixP->fx_addsy));
28705 break;
28706 }
404ff6b5 28707
c19d1205
ZW
28708 newval = md_chars_to_number (buf, THUMB_SIZE);
28709 newval <<= 16;
28710 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 28711
16805f35 28712 newimm = FAIL;
bada4342
JW
28713 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28714 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28715 Thumb2 modified immediate encoding (T2). */
28716 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 28717 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
28718 {
28719 newimm = encode_thumb32_immediate (value);
28720 if (newimm == (unsigned int) FAIL)
28721 newimm = thumb32_negate_data_op (&newval, value);
28722 }
bada4342 28723 if (newimm == (unsigned int) FAIL)
92e90b6e 28724 {
bada4342 28725 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 28726 {
bada4342
JW
28727 /* Turn add/sum into addw/subw. */
28728 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28729 newval = (newval & 0xfeffffff) | 0x02000000;
28730 /* No flat 12-bit imm encoding for addsw/subsw. */
28731 if ((newval & 0x00100000) == 0)
40f246e3 28732 {
bada4342
JW
28733 /* 12 bit immediate for addw/subw. */
28734 if (value < 0)
28735 {
28736 value = -value;
28737 newval ^= 0x00a00000;
28738 }
28739 if (value > 0xfff)
28740 newimm = (unsigned int) FAIL;
28741 else
28742 newimm = value;
28743 }
28744 }
28745 else
28746 {
28747 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28748 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28749 disassembling, MOV is preferred when there is no encoding
db7bf105 28750 overlap. */
bada4342 28751 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
28752 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28753 but with the Rn field [19:16] set to 1111. */
28754 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
28755 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28756 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 28757 && value >= 0 && value <= 0xffff)
bada4342
JW
28758 {
28759 /* Toggle bit[25] to change encoding from T2 to T3. */
28760 newval ^= 1 << 25;
28761 /* Clear bits[19:16]. */
28762 newval &= 0xfff0ffff;
28763 /* Encoding high 4bits imm. Code below will encode the
28764 remaining low 12bits. */
28765 newval |= (value & 0x0000f000) << 4;
28766 newimm = value & 0x00000fff;
40f246e3 28767 }
e9f89963 28768 }
92e90b6e 28769 }
cc8a6dd0 28770
c19d1205 28771 if (newimm == (unsigned int)FAIL)
3631a3c8 28772 {
c19d1205
ZW
28773 as_bad_where (fixP->fx_file, fixP->fx_line,
28774 _("invalid constant (%lx) after fixup"),
28775 (unsigned long) value);
28776 break;
3631a3c8
NC
28777 }
28778
c19d1205
ZW
28779 newval |= (newimm & 0x800) << 15;
28780 newval |= (newimm & 0x700) << 4;
28781 newval |= (newimm & 0x0ff);
cc8a6dd0 28782
c19d1205
ZW
28783 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28784 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28785 break;
a737bd4d 28786
3eb17e6b 28787 case BFD_RELOC_ARM_SMC:
ba85f98c 28788 if (((unsigned long) value) > 0xf)
c19d1205 28789 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 28790 _("invalid smc expression"));
ba85f98c 28791
2fc8bdac 28792 newval = md_chars_to_number (buf, INSN_SIZE);
ba85f98c 28793 newval |= (value & 0xf);
c19d1205
ZW
28794 md_number_to_chars (buf, newval, INSN_SIZE);
28795 break;
a737bd4d 28796
90ec0d68
MGD
28797 case BFD_RELOC_ARM_HVC:
28798 if (((unsigned long) value) > 0xffff)
28799 as_bad_where (fixP->fx_file, fixP->fx_line,
28800 _("invalid hvc expression"));
28801 newval = md_chars_to_number (buf, INSN_SIZE);
28802 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28803 md_number_to_chars (buf, newval, INSN_SIZE);
28804 break;
28805
c19d1205 28806 case BFD_RELOC_ARM_SWI:
adbaf948 28807 if (fixP->tc_fix_data != 0)
c19d1205
ZW
28808 {
28809 if (((unsigned long) value) > 0xff)
28810 as_bad_where (fixP->fx_file, fixP->fx_line,
28811 _("invalid swi expression"));
2fc8bdac 28812 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
28813 newval |= value;
28814 md_number_to_chars (buf, newval, THUMB_SIZE);
28815 }
28816 else
28817 {
28818 if (((unsigned long) value) > 0x00ffffff)
28819 as_bad_where (fixP->fx_file, fixP->fx_line,
28820 _("invalid swi expression"));
2fc8bdac 28821 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
28822 newval |= value;
28823 md_number_to_chars (buf, newval, INSN_SIZE);
28824 }
28825 break;
a737bd4d 28826
c19d1205
ZW
28827 case BFD_RELOC_ARM_MULTI:
28828 if (((unsigned long) value) > 0xffff)
28829 as_bad_where (fixP->fx_file, fixP->fx_line,
28830 _("invalid expression in load/store multiple"));
28831 newval = value | md_chars_to_number (buf, INSN_SIZE);
28832 md_number_to_chars (buf, newval, INSN_SIZE);
28833 break;
a737bd4d 28834
c19d1205 28835#ifdef OBJ_ELF
39b41c9c 28836 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
28837
28838 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28839 && fixP->fx_addsy
34e77a92 28840 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28841 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28842 && THUMB_IS_FUNC (fixP->fx_addsy))
28843 /* Flip the bl to blx. This is a simple flip
28844 bit here because we generate PCREL_CALL for
28845 unconditional bls. */
28846 {
28847 newval = md_chars_to_number (buf, INSN_SIZE);
28848 newval = newval | 0x10000000;
28849 md_number_to_chars (buf, newval, INSN_SIZE);
28850 temp = 1;
28851 fixP->fx_done = 1;
28852 }
39b41c9c
PB
28853 else
28854 temp = 3;
28855 goto arm_branch_common;
28856
28857 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
28858 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28859 && fixP->fx_addsy
34e77a92 28860 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28862 && THUMB_IS_FUNC (fixP->fx_addsy))
28863 {
28864 /* This would map to a bl<cond>, b<cond>,
28865 b<always> to a Thumb function. We
28866 need to force a relocation for this particular
28867 case. */
28868 newval = md_chars_to_number (buf, INSN_SIZE);
28869 fixP->fx_done = 0;
28870 }
1a0670f3 28871 /* Fall through. */
267bf995 28872
2fc8bdac 28873 case BFD_RELOC_ARM_PLT32:
c19d1205 28874#endif
39b41c9c
PB
28875 case BFD_RELOC_ARM_PCREL_BRANCH:
28876 temp = 3;
28877 goto arm_branch_common;
a737bd4d 28878
39b41c9c 28879 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 28880
39b41c9c 28881 temp = 1;
267bf995
RR
28882 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28883 && fixP->fx_addsy
34e77a92 28884 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28885 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28886 && ARM_IS_FUNC (fixP->fx_addsy))
28887 {
28888 /* Flip the blx to a bl and warn. */
28889 const char *name = S_GET_NAME (fixP->fx_addsy);
28890 newval = 0xeb000000;
28891 as_warn_where (fixP->fx_file, fixP->fx_line,
28892 _("blx to '%s' an ARM ISA state function changed to bl"),
28893 name);
28894 md_number_to_chars (buf, newval, INSN_SIZE);
28895 temp = 3;
28896 fixP->fx_done = 1;
28897 }
28898
28899#ifdef OBJ_ELF
28900 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 28901 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
28902#endif
28903
39b41c9c 28904 arm_branch_common:
c19d1205 28905 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
28906 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28907 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 28908 also be clear. */
39b41c9c 28909 if (value & temp)
c19d1205 28910 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
28911 _("misaligned branch destination"));
28912 if ((value & (offsetT)0xfe000000) != (offsetT)0
28913 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 28914 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28915
2fc8bdac 28916 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28917 {
2fc8bdac
ZW
28918 newval = md_chars_to_number (buf, INSN_SIZE);
28919 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
28920 /* Set the H bit on BLX instructions. */
28921 if (temp == 1)
28922 {
28923 if (value & 2)
28924 newval |= 0x01000000;
28925 else
28926 newval &= ~0x01000000;
28927 }
2fc8bdac 28928 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 28929 }
c19d1205 28930 break;
a737bd4d 28931
25fe350b
MS
28932 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28933 /* CBZ can only branch forward. */
a737bd4d 28934
738755b0 28935 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
28936 (which, strictly speaking, are prohibited) will be turned into
28937 no-ops.
738755b0
MS
28938
28939 FIXME: It may be better to remove the instruction completely and
28940 perform relaxation. */
28941 if (value == -2)
2fc8bdac
ZW
28942 {
28943 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 28944 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
28945 md_number_to_chars (buf, newval, THUMB_SIZE);
28946 }
738755b0
MS
28947 else
28948 {
28949 if (value & ~0x7e)
08f10d51 28950 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 28951
477330fc 28952 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
28953 {
28954 newval = md_chars_to_number (buf, THUMB_SIZE);
28955 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28956 md_number_to_chars (buf, newval, THUMB_SIZE);
28957 }
28958 }
c19d1205 28959 break;
a737bd4d 28960
c19d1205 28961 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
e8f8842d 28962 if (out_of_range_p (value, 8))
08f10d51 28963 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28964
2fc8bdac
ZW
28965 if (fixP->fx_done || !seg->use_rela_p)
28966 {
28967 newval = md_chars_to_number (buf, THUMB_SIZE);
28968 newval |= (value & 0x1ff) >> 1;
28969 md_number_to_chars (buf, newval, THUMB_SIZE);
28970 }
c19d1205 28971 break;
a737bd4d 28972
c19d1205 28973 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
e8f8842d 28974 if (out_of_range_p (value, 11))
08f10d51 28975 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28976
2fc8bdac
ZW
28977 if (fixP->fx_done || !seg->use_rela_p)
28978 {
28979 newval = md_chars_to_number (buf, THUMB_SIZE);
28980 newval |= (value & 0xfff) >> 1;
28981 md_number_to_chars (buf, newval, THUMB_SIZE);
28982 }
c19d1205 28983 break;
a737bd4d 28984
e8f8842d 28985 /* This relocation is misnamed, it should be BRANCH21. */
c19d1205 28986 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
28987 if (fixP->fx_addsy
28988 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28989 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28990 && ARM_IS_FUNC (fixP->fx_addsy)
28991 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28992 {
28993 /* Force a relocation for a branch 20 bits wide. */
28994 fixP->fx_done = 0;
28995 }
e8f8842d 28996 if (out_of_range_p (value, 20))
2fc8bdac
ZW
28997 as_bad_where (fixP->fx_file, fixP->fx_line,
28998 _("conditional branch out of range"));
404ff6b5 28999
2fc8bdac
ZW
29000 if (fixP->fx_done || !seg->use_rela_p)
29001 {
29002 offsetT newval2;
29003 addressT S, J1, J2, lo, hi;
404ff6b5 29004
2fc8bdac
ZW
29005 S = (value & 0x00100000) >> 20;
29006 J2 = (value & 0x00080000) >> 19;
29007 J1 = (value & 0x00040000) >> 18;
29008 hi = (value & 0x0003f000) >> 12;
29009 lo = (value & 0x00000ffe) >> 1;
6c43fab6 29010
2fc8bdac
ZW
29011 newval = md_chars_to_number (buf, THUMB_SIZE);
29012 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29013 newval |= (S << 10) | hi;
29014 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29015 md_number_to_chars (buf, newval, THUMB_SIZE);
29016 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29017 }
c19d1205 29018 break;
6c43fab6 29019
c19d1205 29020 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
29021 /* If there is a blx from a thumb state function to
29022 another thumb function flip this to a bl and warn
29023 about it. */
29024
29025 if (fixP->fx_addsy
34e77a92 29026 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29027 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29028 && THUMB_IS_FUNC (fixP->fx_addsy))
29029 {
29030 const char *name = S_GET_NAME (fixP->fx_addsy);
29031 as_warn_where (fixP->fx_file, fixP->fx_line,
29032 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29033 name);
29034 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29035 newval = newval | 0x1000;
29036 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29037 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29038 fixP->fx_done = 1;
29039 }
29040
29041
29042 goto thumb_bl_common;
29043
c19d1205 29044 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
29045 /* A bl from Thumb state ISA to an internal ARM state function
29046 is converted to a blx. */
29047 if (fixP->fx_addsy
29048 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 29049 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29050 && ARM_IS_FUNC (fixP->fx_addsy)
29051 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29052 {
29053 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29054 newval = newval & ~0x1000;
29055 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29056 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29057 fixP->fx_done = 1;
29058 }
29059
29060 thumb_bl_common:
29061
2fc8bdac
ZW
29062 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29063 /* For a BLX instruction, make sure that the relocation is rounded up
29064 to a word boundary. This follows the semantics of the instruction
29065 which specifies that bit 1 of the target address will come from bit
29066 1 of the base address. */
d406f3e4
JB
29067 value = (value + 3) & ~ 3;
29068
29069#ifdef OBJ_ELF
29070 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29071 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29072 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29073#endif
404ff6b5 29074
e8f8842d 29075 if (out_of_range_p (value, 22))
2b2f5df9 29076 {
fc289b0a 29077 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9 29078 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
e8f8842d 29079 else if (out_of_range_p (value, 24))
2b2f5df9
NC
29080 as_bad_where (fixP->fx_file, fixP->fx_line,
29081 _("Thumb2 branch out of range"));
29082 }
4a42ebbc
RR
29083
29084 if (fixP->fx_done || !seg->use_rela_p)
29085 encode_thumb2_b_bl_offset (buf, value);
29086
c19d1205 29087 break;
404ff6b5 29088
c19d1205 29089 case BFD_RELOC_THUMB_PCREL_BRANCH25:
e8f8842d 29090 if (out_of_range_p (value, 24))
08f10d51 29091 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 29092
2fc8bdac 29093 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 29094 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 29095
2fc8bdac 29096 break;
a737bd4d 29097
2fc8bdac
ZW
29098 case BFD_RELOC_8:
29099 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 29100 *buf = value;
c19d1205 29101 break;
a737bd4d 29102
c19d1205 29103 case BFD_RELOC_16:
2fc8bdac 29104 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 29105 md_number_to_chars (buf, value, 2);
c19d1205 29106 break;
a737bd4d 29107
c19d1205 29108#ifdef OBJ_ELF
0855e32b
NS
29109 case BFD_RELOC_ARM_TLS_CALL:
29110 case BFD_RELOC_ARM_THM_TLS_CALL:
29111 case BFD_RELOC_ARM_TLS_DESCSEQ:
29112 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 29113 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
29114 case BFD_RELOC_ARM_TLS_GD32:
29115 case BFD_RELOC_ARM_TLS_LE32:
29116 case BFD_RELOC_ARM_TLS_IE32:
29117 case BFD_RELOC_ARM_TLS_LDM32:
29118 case BFD_RELOC_ARM_TLS_LDO32:
29119 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 29120 break;
6c43fab6 29121
5c5a4843
CL
29122 /* Same handling as above, but with the arm_fdpic guard. */
29123 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29124 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29125 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29126 if (arm_fdpic)
29127 {
29128 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29129 }
29130 else
29131 {
29132 as_bad_where (fixP->fx_file, fixP->fx_line,
29133 _("Relocation supported only in FDPIC mode"));
29134 }
29135 break;
29136
c19d1205
ZW
29137 case BFD_RELOC_ARM_GOT32:
29138 case BFD_RELOC_ARM_GOTOFF:
c19d1205 29139 break;
b43420e6
NC
29140
29141 case BFD_RELOC_ARM_GOT_PREL:
29142 if (fixP->fx_done || !seg->use_rela_p)
477330fc 29143 md_number_to_chars (buf, value, 4);
b43420e6
NC
29144 break;
29145
9a6f4e97
NS
29146 case BFD_RELOC_ARM_TARGET2:
29147 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
29148 addend here for REL targets, because it won't be written out
29149 during reloc processing later. */
9a6f4e97
NS
29150 if (fixP->fx_done || !seg->use_rela_p)
29151 md_number_to_chars (buf, fixP->fx_offset, 4);
29152 break;
188fd7ae
CL
29153
29154 /* Relocations for FDPIC. */
29155 case BFD_RELOC_ARM_GOTFUNCDESC:
29156 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29157 case BFD_RELOC_ARM_FUNCDESC:
29158 if (arm_fdpic)
29159 {
29160 if (fixP->fx_done || !seg->use_rela_p)
29161 md_number_to_chars (buf, 0, 4);
29162 }
29163 else
29164 {
29165 as_bad_where (fixP->fx_file, fixP->fx_line,
29166 _("Relocation supported only in FDPIC mode"));
29167 }
29168 break;
c19d1205 29169#endif
6c43fab6 29170
c19d1205
ZW
29171 case BFD_RELOC_RVA:
29172 case BFD_RELOC_32:
29173 case BFD_RELOC_ARM_TARGET1:
29174 case BFD_RELOC_ARM_ROSEGREL32:
29175 case BFD_RELOC_ARM_SBREL32:
29176 case BFD_RELOC_32_PCREL:
f0927246
NC
29177#ifdef TE_PE
29178 case BFD_RELOC_32_SECREL:
29179#endif
2fc8bdac 29180 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
29181#ifdef TE_WINCE
29182 /* For WinCE we only do this for pcrel fixups. */
29183 if (fixP->fx_done || fixP->fx_pcrel)
29184#endif
29185 md_number_to_chars (buf, value, 4);
c19d1205 29186 break;
6c43fab6 29187
c19d1205
ZW
29188#ifdef OBJ_ELF
29189 case BFD_RELOC_ARM_PREL31:
2fc8bdac 29190 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
29191 {
29192 newval = md_chars_to_number (buf, 4) & 0x80000000;
29193 if ((value ^ (value >> 1)) & 0x40000000)
29194 {
29195 as_bad_where (fixP->fx_file, fixP->fx_line,
29196 _("rel31 relocation overflow"));
29197 }
29198 newval |= value & 0x7fffffff;
29199 md_number_to_chars (buf, newval, 4);
29200 }
29201 break;
c19d1205 29202#endif
a737bd4d 29203
c19d1205 29204 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 29205 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 29206 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
29207 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29208 newval = md_chars_to_number (buf, INSN_SIZE);
29209 else
29210 newval = get_thumb32_insn (buf);
29211 if ((newval & 0x0f200f00) == 0x0d000900)
29212 {
29213 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
29214 has permitted values that are multiples of 2, in the range 0
29215 to 510. */
29216 if (value < -510 || value > 510 || (value & 1))
29217 as_bad_where (fixP->fx_file, fixP->fx_line,
29218 _("co-processor offset out of range"));
29219 }
32c36c3c
AV
29220 else if ((newval & 0xfe001f80) == 0xec000f80)
29221 {
29222 if (value < -511 || value > 512 || (value & 3))
29223 as_bad_where (fixP->fx_file, fixP->fx_line,
29224 _("co-processor offset out of range"));
29225 }
9db2f6b4 29226 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
29227 as_bad_where (fixP->fx_file, fixP->fx_line,
29228 _("co-processor offset out of range"));
29229 cp_off_common:
26d97720 29230 sign = value > 0;
c19d1205
ZW
29231 if (value < 0)
29232 value = -value;
8f06b2d8
PB
29233 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29234 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29235 newval = md_chars_to_number (buf, INSN_SIZE);
29236 else
29237 newval = get_thumb32_insn (buf);
26d97720 29238 if (value == 0)
32c36c3c
AV
29239 {
29240 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29241 newval &= 0xffffff80;
29242 else
29243 newval &= 0xffffff00;
29244 }
26d97720
NS
29245 else
29246 {
32c36c3c
AV
29247 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29248 newval &= 0xff7fff80;
29249 else
29250 newval &= 0xff7fff00;
9db2f6b4
RL
29251 if ((newval & 0x0f200f00) == 0x0d000900)
29252 {
29253 /* This is a fp16 vstr/vldr.
29254
29255 It requires the immediate offset in the instruction is shifted
29256 left by 1 to be a half-word offset.
29257
29258 Here, left shift by 1 first, and later right shift by 2
29259 should get the right offset. */
29260 value <<= 1;
29261 }
26d97720
NS
29262 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29263 }
8f06b2d8
PB
29264 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29265 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29266 md_number_to_chars (buf, newval, INSN_SIZE);
29267 else
29268 put_thumb32_insn (buf, newval);
c19d1205 29269 break;
a737bd4d 29270
c19d1205 29271 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 29272 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
29273 if (value < -255 || value > 255)
29274 as_bad_where (fixP->fx_file, fixP->fx_line,
29275 _("co-processor offset out of range"));
df7849c5 29276 value *= 4;
c19d1205 29277 goto cp_off_common;
6c43fab6 29278
c19d1205
ZW
29279 case BFD_RELOC_ARM_THUMB_OFFSET:
29280 newval = md_chars_to_number (buf, THUMB_SIZE);
29281 /* Exactly what ranges, and where the offset is inserted depends
29282 on the type of instruction, we can establish this from the
29283 top 4 bits. */
29284 switch (newval >> 12)
29285 {
29286 case 4: /* PC load. */
29287 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29288 forced to zero for these loads; md_pcrel_from has already
29289 compensated for this. */
29290 if (value & 3)
29291 as_bad_where (fixP->fx_file, fixP->fx_line,
29292 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
29293 (((unsigned long) fixP->fx_frag->fr_address
29294 + (unsigned long) fixP->fx_where) & ~3)
29295 + (unsigned long) value);
749479c8
AO
29296 else if (get_recorded_alignment (seg) < 2)
29297 as_warn_where (fixP->fx_file, fixP->fx_line,
29298 _("section does not have enough alignment to ensure safe PC-relative loads"));
a737bd4d 29299
c19d1205
ZW
29300 if (value & ~0x3fc)
29301 as_bad_where (fixP->fx_file, fixP->fx_line,
29302 _("invalid offset, value too big (0x%08lX)"),
29303 (long) value);
a737bd4d 29304
c19d1205
ZW
29305 newval |= value >> 2;
29306 break;
a737bd4d 29307
c19d1205
ZW
29308 case 9: /* SP load/store. */
29309 if (value & ~0x3fc)
29310 as_bad_where (fixP->fx_file, fixP->fx_line,
29311 _("invalid offset, value too big (0x%08lX)"),
29312 (long) value);
29313 newval |= value >> 2;
29314 break;
6c43fab6 29315
c19d1205
ZW
29316 case 6: /* Word load/store. */
29317 if (value & ~0x7c)
29318 as_bad_where (fixP->fx_file, fixP->fx_line,
29319 _("invalid offset, value too big (0x%08lX)"),
29320 (long) value);
29321 newval |= value << 4; /* 6 - 2. */
29322 break;
a737bd4d 29323
c19d1205
ZW
29324 case 7: /* Byte load/store. */
29325 if (value & ~0x1f)
29326 as_bad_where (fixP->fx_file, fixP->fx_line,
29327 _("invalid offset, value too big (0x%08lX)"),
29328 (long) value);
29329 newval |= value << 6;
29330 break;
a737bd4d 29331
c19d1205
ZW
29332 case 8: /* Halfword load/store. */
29333 if (value & ~0x3e)
29334 as_bad_where (fixP->fx_file, fixP->fx_line,
29335 _("invalid offset, value too big (0x%08lX)"),
29336 (long) value);
29337 newval |= value << 5; /* 6 - 1. */
29338 break;
a737bd4d 29339
c19d1205
ZW
29340 default:
29341 as_bad_where (fixP->fx_file, fixP->fx_line,
29342 "Unable to process relocation for thumb opcode: %lx",
29343 (unsigned long) newval);
29344 break;
29345 }
29346 md_number_to_chars (buf, newval, THUMB_SIZE);
29347 break;
a737bd4d 29348
c19d1205
ZW
29349 case BFD_RELOC_ARM_THUMB_ADD:
29350 /* This is a complicated relocation, since we use it for all of
29351 the following immediate relocations:
a737bd4d 29352
c19d1205
ZW
29353 3bit ADD/SUB
29354 8bit ADD/SUB
29355 9bit ADD/SUB SP word-aligned
29356 10bit ADD PC/SP word-aligned
a737bd4d 29357
c19d1205
ZW
29358 The type of instruction being processed is encoded in the
29359 instruction field:
a737bd4d 29360
c19d1205
ZW
29361 0x8000 SUB
29362 0x00F0 Rd
29363 0x000F Rs
29364 */
29365 newval = md_chars_to_number (buf, THUMB_SIZE);
29366 {
29367 int rd = (newval >> 4) & 0xf;
29368 int rs = newval & 0xf;
29369 int subtract = !!(newval & 0x8000);
a737bd4d 29370
c19d1205
ZW
29371 /* Check for HI regs, only very restricted cases allowed:
29372 Adjusting SP, and using PC or SP to get an address. */
29373 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29374 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29375 as_bad_where (fixP->fx_file, fixP->fx_line,
29376 _("invalid Hi register with immediate"));
a737bd4d 29377
c19d1205
ZW
29378 /* If value is negative, choose the opposite instruction. */
29379 if (value < 0)
29380 {
29381 value = -value;
29382 subtract = !subtract;
29383 if (value < 0)
29384 as_bad_where (fixP->fx_file, fixP->fx_line,
29385 _("immediate value out of range"));
29386 }
a737bd4d 29387
c19d1205
ZW
29388 if (rd == REG_SP)
29389 {
75c11999 29390 if (value & ~0x1fc)
c19d1205
ZW
29391 as_bad_where (fixP->fx_file, fixP->fx_line,
29392 _("invalid immediate for stack address calculation"));
29393 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29394 newval |= value >> 2;
29395 }
29396 else if (rs == REG_PC || rs == REG_SP)
29397 {
c12d2c9d
NC
29398 /* PR gas/18541. If the addition is for a defined symbol
29399 within range of an ADR instruction then accept it. */
29400 if (subtract
29401 && value == 4
29402 && fixP->fx_addsy != NULL)
29403 {
29404 subtract = 0;
29405
29406 if (! S_IS_DEFINED (fixP->fx_addsy)
29407 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29408 || S_IS_WEAK (fixP->fx_addsy))
29409 {
29410 as_bad_where (fixP->fx_file, fixP->fx_line,
29411 _("address calculation needs a strongly defined nearby symbol"));
29412 }
29413 else
29414 {
29415 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29416
29417 /* Round up to the next 4-byte boundary. */
29418 if (v & 3)
29419 v = (v + 3) & ~ 3;
29420 else
29421 v += 4;
29422 v = S_GET_VALUE (fixP->fx_addsy) - v;
29423
29424 if (v & ~0x3fc)
29425 {
29426 as_bad_where (fixP->fx_file, fixP->fx_line,
29427 _("symbol too far away"));
29428 }
29429 else
29430 {
29431 fixP->fx_done = 1;
29432 value = v;
29433 }
29434 }
29435 }
29436
c19d1205
ZW
29437 if (subtract || value & ~0x3fc)
29438 as_bad_where (fixP->fx_file, fixP->fx_line,
29439 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 29440 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
29441 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29442 newval |= rd << 8;
29443 newval |= value >> 2;
29444 }
29445 else if (rs == rd)
29446 {
29447 if (value & ~0xff)
29448 as_bad_where (fixP->fx_file, fixP->fx_line,
29449 _("immediate value out of range"));
29450 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29451 newval |= (rd << 8) | value;
29452 }
29453 else
29454 {
29455 if (value & ~0x7)
29456 as_bad_where (fixP->fx_file, fixP->fx_line,
29457 _("immediate value out of range"));
29458 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29459 newval |= rd | (rs << 3) | (value << 6);
29460 }
29461 }
29462 md_number_to_chars (buf, newval, THUMB_SIZE);
29463 break;
a737bd4d 29464
c19d1205
ZW
29465 case BFD_RELOC_ARM_THUMB_IMM:
29466 newval = md_chars_to_number (buf, THUMB_SIZE);
29467 if (value < 0 || value > 255)
29468 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 29469 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
29470 (long) value);
29471 newval |= value;
29472 md_number_to_chars (buf, newval, THUMB_SIZE);
29473 break;
a737bd4d 29474
c19d1205
ZW
29475 case BFD_RELOC_ARM_THUMB_SHIFT:
29476 /* 5bit shift value (0..32). LSL cannot take 32. */
29477 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29478 temp = newval & 0xf800;
29479 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29480 as_bad_where (fixP->fx_file, fixP->fx_line,
29481 _("invalid shift value: %ld"), (long) value);
29482 /* Shifts of zero must be encoded as LSL. */
29483 if (value == 0)
29484 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29485 /* Shifts of 32 are encoded as zero. */
29486 else if (value == 32)
29487 value = 0;
29488 newval |= value << 6;
29489 md_number_to_chars (buf, newval, THUMB_SIZE);
29490 break;
a737bd4d 29491
c19d1205
ZW
29492 case BFD_RELOC_VTABLE_INHERIT:
29493 case BFD_RELOC_VTABLE_ENTRY:
29494 fixP->fx_done = 0;
29495 return;
6c43fab6 29496
b6895b4f
PB
29497 case BFD_RELOC_ARM_MOVW:
29498 case BFD_RELOC_ARM_MOVT:
29499 case BFD_RELOC_ARM_THUMB_MOVW:
29500 case BFD_RELOC_ARM_THUMB_MOVT:
29501 if (fixP->fx_done || !seg->use_rela_p)
29502 {
29503 /* REL format relocations are limited to a 16-bit addend. */
29504 if (!fixP->fx_done)
29505 {
39623e12 29506 if (value < -0x8000 || value > 0x7fff)
b6895b4f 29507 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 29508 _("offset out of range"));
b6895b4f
PB
29509 }
29510 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29511 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29512 {
29513 value >>= 16;
29514 }
29515
29516 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29517 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29518 {
29519 newval = get_thumb32_insn (buf);
29520 newval &= 0xfbf08f00;
29521 newval |= (value & 0xf000) << 4;
29522 newval |= (value & 0x0800) << 15;
29523 newval |= (value & 0x0700) << 4;
29524 newval |= (value & 0x00ff);
29525 put_thumb32_insn (buf, newval);
29526 }
29527 else
29528 {
29529 newval = md_chars_to_number (buf, 4);
29530 newval &= 0xfff0f000;
29531 newval |= value & 0x0fff;
29532 newval |= (value & 0xf000) << 4;
29533 md_number_to_chars (buf, newval, 4);
29534 }
29535 }
29536 return;
29537
72d98d16
MG
29538 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29539 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29540 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29541 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29542 gas_assert (!fixP->fx_done);
29543 {
29544 bfd_vma insn;
29545 bfd_boolean is_mov;
29546 bfd_vma encoded_addend = value;
29547
29548 /* Check that addend can be encoded in instruction. */
29549 if (!seg->use_rela_p && (value < 0 || value > 255))
29550 as_bad_where (fixP->fx_file, fixP->fx_line,
29551 _("the offset 0x%08lX is not representable"),
29552 (unsigned long) encoded_addend);
29553
29554 /* Extract the instruction. */
29555 insn = md_chars_to_number (buf, THUMB_SIZE);
29556 is_mov = (insn & 0xf800) == 0x2000;
29557
29558 /* Encode insn. */
29559 if (is_mov)
29560 {
29561 if (!seg->use_rela_p)
29562 insn |= encoded_addend;
29563 }
29564 else
29565 {
29566 int rd, rs;
29567
29568 /* Extract the instruction. */
29569 /* Encoding is the following
29570 0x8000 SUB
29571 0x00F0 Rd
29572 0x000F Rs
29573 */
29574 /* The following conditions must be true :
29575 - ADD
29576 - Rd == Rs
29577 - Rd <= 7
29578 */
29579 rd = (insn >> 4) & 0xf;
29580 rs = insn & 0xf;
29581 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29582 as_bad_where (fixP->fx_file, fixP->fx_line,
29583 _("Unable to process relocation for thumb opcode: %lx"),
29584 (unsigned long) insn);
29585
29586 /* Encode as ADD immediate8 thumb 1 code. */
29587 insn = 0x3000 | (rd << 8);
29588
29589 /* Place the encoded addend into the first 8 bits of the
29590 instruction. */
29591 if (!seg->use_rela_p)
29592 insn |= encoded_addend;
29593 }
29594
29595 /* Update the instruction. */
29596 md_number_to_chars (buf, insn, THUMB_SIZE);
29597 }
29598 break;
29599
4962c51a
MS
29600 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29601 case BFD_RELOC_ARM_ALU_PC_G0:
29602 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29603 case BFD_RELOC_ARM_ALU_PC_G1:
29604 case BFD_RELOC_ARM_ALU_PC_G2:
29605 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29606 case BFD_RELOC_ARM_ALU_SB_G0:
29607 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29608 case BFD_RELOC_ARM_ALU_SB_G1:
29609 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 29610 gas_assert (!fixP->fx_done);
4962c51a
MS
29611 if (!seg->use_rela_p)
29612 {
477330fc
RM
29613 bfd_vma insn;
29614 bfd_vma encoded_addend;
3ca4a8ec 29615 bfd_vma addend_abs = llabs (value);
477330fc
RM
29616
29617 /* Check that the absolute value of the addend can be
29618 expressed as an 8-bit constant plus a rotation. */
29619 encoded_addend = encode_arm_immediate (addend_abs);
29620 if (encoded_addend == (unsigned int) FAIL)
4962c51a 29621 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29622 _("the offset 0x%08lX is not representable"),
29623 (unsigned long) addend_abs);
29624
29625 /* Extract the instruction. */
29626 insn = md_chars_to_number (buf, INSN_SIZE);
29627
29628 /* If the addend is positive, use an ADD instruction.
29629 Otherwise use a SUB. Take care not to destroy the S bit. */
29630 insn &= 0xff1fffff;
29631 if (value < 0)
29632 insn |= 1 << 22;
29633 else
29634 insn |= 1 << 23;
29635
29636 /* Place the encoded addend into the first 12 bits of the
29637 instruction. */
29638 insn &= 0xfffff000;
29639 insn |= encoded_addend;
29640
29641 /* Update the instruction. */
29642 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
29643 }
29644 break;
29645
29646 case BFD_RELOC_ARM_LDR_PC_G0:
29647 case BFD_RELOC_ARM_LDR_PC_G1:
29648 case BFD_RELOC_ARM_LDR_PC_G2:
29649 case BFD_RELOC_ARM_LDR_SB_G0:
29650 case BFD_RELOC_ARM_LDR_SB_G1:
29651 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 29652 gas_assert (!fixP->fx_done);
4962c51a 29653 if (!seg->use_rela_p)
477330fc
RM
29654 {
29655 bfd_vma insn;
3ca4a8ec 29656 bfd_vma addend_abs = llabs (value);
4962c51a 29657
477330fc
RM
29658 /* Check that the absolute value of the addend can be
29659 encoded in 12 bits. */
29660 if (addend_abs >= 0x1000)
4962c51a 29661 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29662 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29663 (unsigned long) addend_abs);
29664
29665 /* Extract the instruction. */
29666 insn = md_chars_to_number (buf, INSN_SIZE);
29667
29668 /* If the addend is negative, clear bit 23 of the instruction.
29669 Otherwise set it. */
29670 if (value < 0)
29671 insn &= ~(1 << 23);
29672 else
29673 insn |= 1 << 23;
29674
29675 /* Place the absolute value of the addend into the first 12 bits
29676 of the instruction. */
29677 insn &= 0xfffff000;
29678 insn |= addend_abs;
29679
29680 /* Update the instruction. */
29681 md_number_to_chars (buf, insn, INSN_SIZE);
29682 }
4962c51a
MS
29683 break;
29684
29685 case BFD_RELOC_ARM_LDRS_PC_G0:
29686 case BFD_RELOC_ARM_LDRS_PC_G1:
29687 case BFD_RELOC_ARM_LDRS_PC_G2:
29688 case BFD_RELOC_ARM_LDRS_SB_G0:
29689 case BFD_RELOC_ARM_LDRS_SB_G1:
29690 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 29691 gas_assert (!fixP->fx_done);
4962c51a 29692 if (!seg->use_rela_p)
477330fc
RM
29693 {
29694 bfd_vma insn;
3ca4a8ec 29695 bfd_vma addend_abs = llabs (value);
4962c51a 29696
477330fc
RM
29697 /* Check that the absolute value of the addend can be
29698 encoded in 8 bits. */
29699 if (addend_abs >= 0x100)
4962c51a 29700 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29701 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29702 (unsigned long) addend_abs);
29703
29704 /* Extract the instruction. */
29705 insn = md_chars_to_number (buf, INSN_SIZE);
29706
29707 /* If the addend is negative, clear bit 23 of the instruction.
29708 Otherwise set it. */
29709 if (value < 0)
29710 insn &= ~(1 << 23);
29711 else
29712 insn |= 1 << 23;
29713
29714 /* Place the first four bits of the absolute value of the addend
29715 into the first 4 bits of the instruction, and the remaining
29716 four into bits 8 .. 11. */
29717 insn &= 0xfffff0f0;
29718 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29719
29720 /* Update the instruction. */
29721 md_number_to_chars (buf, insn, INSN_SIZE);
29722 }
4962c51a
MS
29723 break;
29724
29725 case BFD_RELOC_ARM_LDC_PC_G0:
29726 case BFD_RELOC_ARM_LDC_PC_G1:
29727 case BFD_RELOC_ARM_LDC_PC_G2:
29728 case BFD_RELOC_ARM_LDC_SB_G0:
29729 case BFD_RELOC_ARM_LDC_SB_G1:
29730 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 29731 gas_assert (!fixP->fx_done);
4962c51a 29732 if (!seg->use_rela_p)
477330fc
RM
29733 {
29734 bfd_vma insn;
3ca4a8ec 29735 bfd_vma addend_abs = llabs (value);
4962c51a 29736
477330fc
RM
29737 /* Check that the absolute value of the addend is a multiple of
29738 four and, when divided by four, fits in 8 bits. */
29739 if (addend_abs & 0x3)
4962c51a 29740 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29741 _("bad offset 0x%08lX (must be word-aligned)"),
29742 (unsigned long) addend_abs);
4962c51a 29743
477330fc 29744 if ((addend_abs >> 2) > 0xff)
4962c51a 29745 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29746 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29747 (unsigned long) addend_abs);
29748
29749 /* Extract the instruction. */
29750 insn = md_chars_to_number (buf, INSN_SIZE);
29751
29752 /* If the addend is negative, clear bit 23 of the instruction.
29753 Otherwise set it. */
29754 if (value < 0)
29755 insn &= ~(1 << 23);
29756 else
29757 insn |= 1 << 23;
29758
29759 /* Place the addend (divided by four) into the first eight
29760 bits of the instruction. */
29761 insn &= 0xfffffff0;
29762 insn |= addend_abs >> 2;
29763
29764 /* Update the instruction. */
29765 md_number_to_chars (buf, insn, INSN_SIZE);
29766 }
4962c51a
MS
29767 break;
29768
e12437dc
AV
29769 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29770 if (fixP->fx_addsy
29771 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29772 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29773 && ARM_IS_FUNC (fixP->fx_addsy)
29774 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29775 {
29776 /* Force a relocation for a branch 5 bits wide. */
29777 fixP->fx_done = 0;
29778 }
29779 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29780 as_bad_where (fixP->fx_file, fixP->fx_line,
29781 BAD_BRANCH_OFF);
29782
29783 if (fixP->fx_done || !seg->use_rela_p)
29784 {
29785 addressT boff = value >> 1;
29786
29787 newval = md_chars_to_number (buf, THUMB_SIZE);
29788 newval |= (boff << 7);
29789 md_number_to_chars (buf, newval, THUMB_SIZE);
29790 }
29791 break;
29792
f6b2b12d
AV
29793 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29794 if (fixP->fx_addsy
29795 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29796 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29797 && ARM_IS_FUNC (fixP->fx_addsy)
29798 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29799 {
29800 fixP->fx_done = 0;
29801 }
29802 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
29803 as_bad_where (fixP->fx_file, fixP->fx_line,
29804 _("branch out of range"));
29805
29806 if (fixP->fx_done || !seg->use_rela_p)
29807 {
29808 newval = md_chars_to_number (buf, THUMB_SIZE);
29809
29810 addressT boff = ((newval & 0x0780) >> 7) << 1;
29811 addressT diff = value - boff;
29812
29813 if (diff == 4)
29814 {
29815 newval |= 1 << 1; /* T bit. */
29816 }
29817 else if (diff != 2)
29818 {
29819 as_bad_where (fixP->fx_file, fixP->fx_line,
29820 _("out of range label-relative fixup value"));
29821 }
29822 md_number_to_chars (buf, newval, THUMB_SIZE);
29823 }
29824 break;
29825
e5d6e09e
AV
29826 case BFD_RELOC_ARM_THUMB_BF17:
29827 if (fixP->fx_addsy
29828 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29829 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29830 && ARM_IS_FUNC (fixP->fx_addsy)
29831 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29832 {
29833 /* Force a relocation for a branch 17 bits wide. */
29834 fixP->fx_done = 0;
29835 }
29836
29837 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29838 as_bad_where (fixP->fx_file, fixP->fx_line,
29839 BAD_BRANCH_OFF);
29840
29841 if (fixP->fx_done || !seg->use_rela_p)
29842 {
29843 offsetT newval2;
29844 addressT immA, immB, immC;
29845
29846 immA = (value & 0x0001f000) >> 12;
29847 immB = (value & 0x00000ffc) >> 2;
29848 immC = (value & 0x00000002) >> 1;
29849
29850 newval = md_chars_to_number (buf, THUMB_SIZE);
29851 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29852 newval |= immA;
29853 newval2 |= (immC << 11) | (immB << 1);
29854 md_number_to_chars (buf, newval, THUMB_SIZE);
29855 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29856 }
29857 break;
29858
1caf72a5
AV
29859 case BFD_RELOC_ARM_THUMB_BF19:
29860 if (fixP->fx_addsy
29861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29862 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29863 && ARM_IS_FUNC (fixP->fx_addsy)
29864 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29865 {
29866 /* Force a relocation for a branch 19 bits wide. */
29867 fixP->fx_done = 0;
29868 }
29869
29870 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29871 as_bad_where (fixP->fx_file, fixP->fx_line,
29872 BAD_BRANCH_OFF);
29873
29874 if (fixP->fx_done || !seg->use_rela_p)
29875 {
29876 offsetT newval2;
29877 addressT immA, immB, immC;
29878
29879 immA = (value & 0x0007f000) >> 12;
29880 immB = (value & 0x00000ffc) >> 2;
29881 immC = (value & 0x00000002) >> 1;
29882
29883 newval = md_chars_to_number (buf, THUMB_SIZE);
29884 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29885 newval |= immA;
29886 newval2 |= (immC << 11) | (immB << 1);
29887 md_number_to_chars (buf, newval, THUMB_SIZE);
29888 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29889 }
29890 break;
29891
1889da70
AV
29892 case BFD_RELOC_ARM_THUMB_BF13:
29893 if (fixP->fx_addsy
29894 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29895 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29896 && ARM_IS_FUNC (fixP->fx_addsy)
29897 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29898 {
29899 /* Force a relocation for a branch 13 bits wide. */
29900 fixP->fx_done = 0;
29901 }
29902
29903 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29904 as_bad_where (fixP->fx_file, fixP->fx_line,
29905 BAD_BRANCH_OFF);
29906
29907 if (fixP->fx_done || !seg->use_rela_p)
29908 {
29909 offsetT newval2;
29910 addressT immA, immB, immC;
29911
29912 immA = (value & 0x00001000) >> 12;
29913 immB = (value & 0x00000ffc) >> 2;
29914 immC = (value & 0x00000002) >> 1;
29915
29916 newval = md_chars_to_number (buf, THUMB_SIZE);
29917 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29918 newval |= immA;
29919 newval2 |= (immC << 11) | (immB << 1);
29920 md_number_to_chars (buf, newval, THUMB_SIZE);
29921 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29922 }
29923 break;
29924
60f993ce
AV
29925 case BFD_RELOC_ARM_THUMB_LOOP12:
29926 if (fixP->fx_addsy
29927 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29928 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29929 && ARM_IS_FUNC (fixP->fx_addsy)
29930 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29931 {
29932 /* Force a relocation for a branch 12 bits wide. */
29933 fixP->fx_done = 0;
29934 }
29935
29936 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 29937 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 29938 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
29939 || ((insn & 0xffffffff) == 0xf02fc001)
29940 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
29941 value = -value;
29942
29943 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29944 as_bad_where (fixP->fx_file, fixP->fx_line,
29945 BAD_BRANCH_OFF);
29946 if (fixP->fx_done || !seg->use_rela_p)
29947 {
29948 addressT imml, immh;
29949
29950 immh = (value & 0x00000ffc) >> 2;
29951 imml = (value & 0x00000002) >> 1;
29952
29953 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29954 newval |= (imml << 11) | (immh << 1);
29955 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29956 }
29957 break;
29958
845b51d6
PB
29959 case BFD_RELOC_ARM_V4BX:
29960 /* This will need to go in the object file. */
29961 fixP->fx_done = 0;
29962 break;
29963
c19d1205
ZW
29964 case BFD_RELOC_UNUSED:
29965 default:
29966 as_bad_where (fixP->fx_file, fixP->fx_line,
29967 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29968 }
6c43fab6
RE
29969}
29970
c19d1205
ZW
29971/* Translate internal representation of relocation info to BFD target
29972 format. */
a737bd4d 29973
c19d1205 29974arelent *
00a97672 29975tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29976{
c19d1205
ZW
29977 arelent * reloc;
29978 bfd_reloc_code_real_type code;
a737bd4d 29979
325801bd 29980 reloc = XNEW (arelent);
a737bd4d 29981
325801bd 29982 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
29983 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29984 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 29985
2fc8bdac 29986 if (fixp->fx_pcrel)
00a97672
RS
29987 {
29988 if (section->use_rela_p)
29989 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29990 else
29991 fixp->fx_offset = reloc->address;
29992 }
c19d1205 29993 reloc->addend = fixp->fx_offset;
a737bd4d 29994
c19d1205 29995 switch (fixp->fx_r_type)
a737bd4d 29996 {
c19d1205
ZW
29997 case BFD_RELOC_8:
29998 if (fixp->fx_pcrel)
29999 {
30000 code = BFD_RELOC_8_PCREL;
30001 break;
30002 }
1a0670f3 30003 /* Fall through. */
a737bd4d 30004
c19d1205
ZW
30005 case BFD_RELOC_16:
30006 if (fixp->fx_pcrel)
30007 {
30008 code = BFD_RELOC_16_PCREL;
30009 break;
30010 }
1a0670f3 30011 /* Fall through. */
6c43fab6 30012
c19d1205
ZW
30013 case BFD_RELOC_32:
30014 if (fixp->fx_pcrel)
30015 {
30016 code = BFD_RELOC_32_PCREL;
30017 break;
30018 }
1a0670f3 30019 /* Fall through. */
a737bd4d 30020
b6895b4f
PB
30021 case BFD_RELOC_ARM_MOVW:
30022 if (fixp->fx_pcrel)
30023 {
30024 code = BFD_RELOC_ARM_MOVW_PCREL;
30025 break;
30026 }
1a0670f3 30027 /* Fall through. */
b6895b4f
PB
30028
30029 case BFD_RELOC_ARM_MOVT:
30030 if (fixp->fx_pcrel)
30031 {
30032 code = BFD_RELOC_ARM_MOVT_PCREL;
30033 break;
30034 }
1a0670f3 30035 /* Fall through. */
b6895b4f
PB
30036
30037 case BFD_RELOC_ARM_THUMB_MOVW:
30038 if (fixp->fx_pcrel)
30039 {
30040 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30041 break;
30042 }
1a0670f3 30043 /* Fall through. */
b6895b4f
PB
30044
30045 case BFD_RELOC_ARM_THUMB_MOVT:
30046 if (fixp->fx_pcrel)
30047 {
30048 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30049 break;
30050 }
1a0670f3 30051 /* Fall through. */
b6895b4f 30052
c19d1205
ZW
30053 case BFD_RELOC_NONE:
30054 case BFD_RELOC_ARM_PCREL_BRANCH:
30055 case BFD_RELOC_ARM_PCREL_BLX:
30056 case BFD_RELOC_RVA:
30057 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30058 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30059 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30060 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30061 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30062 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
30063 case BFD_RELOC_VTABLE_ENTRY:
30064 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
30065#ifdef TE_PE
30066 case BFD_RELOC_32_SECREL:
30067#endif
c19d1205
ZW
30068 code = fixp->fx_r_type;
30069 break;
a737bd4d 30070
00adf2d4
JB
30071 case BFD_RELOC_THUMB_PCREL_BLX:
30072#ifdef OBJ_ELF
30073 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30074 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30075 else
30076#endif
30077 code = BFD_RELOC_THUMB_PCREL_BLX;
30078 break;
30079
c19d1205
ZW
30080 case BFD_RELOC_ARM_LITERAL:
30081 case BFD_RELOC_ARM_HWLITERAL:
30082 /* If this is called then the a literal has
30083 been referenced across a section boundary. */
30084 as_bad_where (fixp->fx_file, fixp->fx_line,
30085 _("literal referenced across section boundary"));
30086 return NULL;
a737bd4d 30087
c19d1205 30088#ifdef OBJ_ELF
0855e32b
NS
30089 case BFD_RELOC_ARM_TLS_CALL:
30090 case BFD_RELOC_ARM_THM_TLS_CALL:
30091 case BFD_RELOC_ARM_TLS_DESCSEQ:
30092 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
30093 case BFD_RELOC_ARM_GOT32:
30094 case BFD_RELOC_ARM_GOTOFF:
b43420e6 30095 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
30096 case BFD_RELOC_ARM_PLT32:
30097 case BFD_RELOC_ARM_TARGET1:
30098 case BFD_RELOC_ARM_ROSEGREL32:
30099 case BFD_RELOC_ARM_SBREL32:
30100 case BFD_RELOC_ARM_PREL31:
30101 case BFD_RELOC_ARM_TARGET2:
c19d1205 30102 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
30103 case BFD_RELOC_ARM_PCREL_CALL:
30104 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
30105 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30106 case BFD_RELOC_ARM_ALU_PC_G0:
30107 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30108 case BFD_RELOC_ARM_ALU_PC_G1:
30109 case BFD_RELOC_ARM_ALU_PC_G2:
30110 case BFD_RELOC_ARM_LDR_PC_G0:
30111 case BFD_RELOC_ARM_LDR_PC_G1:
30112 case BFD_RELOC_ARM_LDR_PC_G2:
30113 case BFD_RELOC_ARM_LDRS_PC_G0:
30114 case BFD_RELOC_ARM_LDRS_PC_G1:
30115 case BFD_RELOC_ARM_LDRS_PC_G2:
30116 case BFD_RELOC_ARM_LDC_PC_G0:
30117 case BFD_RELOC_ARM_LDC_PC_G1:
30118 case BFD_RELOC_ARM_LDC_PC_G2:
30119 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30120 case BFD_RELOC_ARM_ALU_SB_G0:
30121 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30122 case BFD_RELOC_ARM_ALU_SB_G1:
30123 case BFD_RELOC_ARM_ALU_SB_G2:
30124 case BFD_RELOC_ARM_LDR_SB_G0:
30125 case BFD_RELOC_ARM_LDR_SB_G1:
30126 case BFD_RELOC_ARM_LDR_SB_G2:
30127 case BFD_RELOC_ARM_LDRS_SB_G0:
30128 case BFD_RELOC_ARM_LDRS_SB_G1:
30129 case BFD_RELOC_ARM_LDRS_SB_G2:
30130 case BFD_RELOC_ARM_LDC_SB_G0:
30131 case BFD_RELOC_ARM_LDC_SB_G1:
30132 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 30133 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
30134 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30135 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30136 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30137 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
30138 case BFD_RELOC_ARM_GOTFUNCDESC:
30139 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30140 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 30141 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 30142 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 30143 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
30144 code = fixp->fx_r_type;
30145 break;
a737bd4d 30146
0855e32b 30147 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 30148 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 30149 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 30150 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 30151 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 30152 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 30153 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 30154 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
30155 /* BFD will include the symbol's address in the addend.
30156 But we don't want that, so subtract it out again here. */
30157 if (!S_IS_COMMON (fixp->fx_addsy))
30158 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30159 code = fixp->fx_r_type;
30160 break;
30161#endif
a737bd4d 30162
c19d1205
ZW
30163 case BFD_RELOC_ARM_IMMEDIATE:
30164 as_bad_where (fixp->fx_file, fixp->fx_line,
30165 _("internal relocation (type: IMMEDIATE) not fixed up"));
30166 return NULL;
a737bd4d 30167
c19d1205
ZW
30168 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30169 as_bad_where (fixp->fx_file, fixp->fx_line,
30170 _("ADRL used for a symbol not defined in the same file"));
30171 return NULL;
a737bd4d 30172
e12437dc 30173 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 30174 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 30175 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
30176 as_bad_where (fixp->fx_file, fixp->fx_line,
30177 _("%s used for a symbol not defined in the same file"),
30178 bfd_get_reloc_code_name (fixp->fx_r_type));
30179 return NULL;
30180
c19d1205 30181 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
30182 if (section->use_rela_p)
30183 {
30184 code = fixp->fx_r_type;
30185 break;
30186 }
30187
c19d1205
ZW
30188 if (fixp->fx_addsy != NULL
30189 && !S_IS_DEFINED (fixp->fx_addsy)
30190 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 30191 {
c19d1205
ZW
30192 as_bad_where (fixp->fx_file, fixp->fx_line,
30193 _("undefined local label `%s'"),
30194 S_GET_NAME (fixp->fx_addsy));
30195 return NULL;
a737bd4d
NC
30196 }
30197
c19d1205
ZW
30198 as_bad_where (fixp->fx_file, fixp->fx_line,
30199 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30200 return NULL;
a737bd4d 30201
c19d1205
ZW
30202 default:
30203 {
e0471c16 30204 const char * type;
6c43fab6 30205
c19d1205
ZW
30206 switch (fixp->fx_r_type)
30207 {
30208 case BFD_RELOC_NONE: type = "NONE"; break;
30209 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30210 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 30211 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
30212 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30213 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30214 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 30215 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 30216 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
30217 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30218 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30219 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30220 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30221 default: type = _("<unknown>"); break;
30222 }
30223 as_bad_where (fixp->fx_file, fixp->fx_line,
30224 _("cannot represent %s relocation in this object file format"),
30225 type);
30226 return NULL;
30227 }
a737bd4d 30228 }
6c43fab6 30229
c19d1205
ZW
30230#ifdef OBJ_ELF
30231 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30232 && GOT_symbol
30233 && fixp->fx_addsy == GOT_symbol)
30234 {
30235 code = BFD_RELOC_ARM_GOTPC;
30236 reloc->addend = fixp->fx_offset = reloc->address;
30237 }
30238#endif
6c43fab6 30239
c19d1205 30240 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 30241
c19d1205
ZW
30242 if (reloc->howto == NULL)
30243 {
30244 as_bad_where (fixp->fx_file, fixp->fx_line,
30245 _("cannot represent %s relocation in this object file format"),
30246 bfd_get_reloc_code_name (code));
30247 return NULL;
30248 }
6c43fab6 30249
c19d1205
ZW
30250 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30251 vtable entry to be used in the relocation's section offset. */
30252 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30253 reloc->address = fixp->fx_offset;
6c43fab6 30254
c19d1205 30255 return reloc;
6c43fab6
RE
30256}
30257
c19d1205 30258/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 30259
c19d1205
ZW
30260void
30261cons_fix_new_arm (fragS * frag,
30262 int where,
30263 int size,
62ebcb5c
AM
30264 expressionS * exp,
30265 bfd_reloc_code_real_type reloc)
6c43fab6 30266{
c19d1205 30267 int pcrel = 0;
6c43fab6 30268
c19d1205
ZW
30269 /* Pick a reloc.
30270 FIXME: @@ Should look at CPU word size. */
30271 switch (size)
30272 {
30273 case 1:
62ebcb5c 30274 reloc = BFD_RELOC_8;
c19d1205
ZW
30275 break;
30276 case 2:
62ebcb5c 30277 reloc = BFD_RELOC_16;
c19d1205
ZW
30278 break;
30279 case 4:
30280 default:
62ebcb5c 30281 reloc = BFD_RELOC_32;
c19d1205
ZW
30282 break;
30283 case 8:
62ebcb5c 30284 reloc = BFD_RELOC_64;
c19d1205
ZW
30285 break;
30286 }
6c43fab6 30287
f0927246
NC
30288#ifdef TE_PE
30289 if (exp->X_op == O_secrel)
30290 {
30291 exp->X_op = O_symbol;
62ebcb5c 30292 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
30293 }
30294#endif
30295
62ebcb5c 30296 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 30297}
6c43fab6 30298
4343666d 30299#if defined (OBJ_COFF)
c19d1205
ZW
30300void
30301arm_validate_fix (fixS * fixP)
6c43fab6 30302{
c19d1205
ZW
30303 /* If the destination of the branch is a defined symbol which does not have
30304 the THUMB_FUNC attribute, then we must be calling a function which has
30305 the (interfacearm) attribute. We look for the Thumb entry point to that
30306 function and change the branch to refer to that function instead. */
30307 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30308 && fixP->fx_addsy != NULL
30309 && S_IS_DEFINED (fixP->fx_addsy)
30310 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 30311 {
c19d1205 30312 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 30313 }
c19d1205
ZW
30314}
30315#endif
6c43fab6 30316
267bf995 30317
c19d1205
ZW
30318int
30319arm_force_relocation (struct fix * fixp)
30320{
30321#if defined (OBJ_COFF) && defined (TE_PE)
30322 if (fixp->fx_r_type == BFD_RELOC_RVA)
30323 return 1;
30324#endif
6c43fab6 30325
267bf995
RR
30326 /* In case we have a call or a branch to a function in ARM ISA mode from
30327 a thumb function or vice-versa force the relocation. These relocations
30328 are cleared off for some cores that might have blx and simple transformations
30329 are possible. */
30330
30331#ifdef OBJ_ELF
30332 switch (fixp->fx_r_type)
30333 {
30334 case BFD_RELOC_ARM_PCREL_JUMP:
30335 case BFD_RELOC_ARM_PCREL_CALL:
30336 case BFD_RELOC_THUMB_PCREL_BLX:
30337 if (THUMB_IS_FUNC (fixp->fx_addsy))
30338 return 1;
30339 break;
30340
30341 case BFD_RELOC_ARM_PCREL_BLX:
30342 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30343 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30344 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30345 if (ARM_IS_FUNC (fixp->fx_addsy))
30346 return 1;
30347 break;
30348
30349 default:
30350 break;
30351 }
30352#endif
30353
b5884301
PB
30354 /* Resolve these relocations even if the symbol is extern or weak.
30355 Technically this is probably wrong due to symbol preemption.
30356 In practice these relocations do not have enough range to be useful
30357 at dynamic link time, and some code (e.g. in the Linux kernel)
30358 expects these references to be resolved. */
c19d1205
ZW
30359 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30360 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 30361 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 30362 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
30363 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30364 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30365 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 30366 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
30367 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30368 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
30369 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30370 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30371 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30372 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 30373 return 0;
a737bd4d 30374
4962c51a
MS
30375 /* Always leave these relocations for the linker. */
30376 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30377 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30378 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30379 return 1;
30380
f0291e4c
PB
30381 /* Always generate relocations against function symbols. */
30382 if (fixp->fx_r_type == BFD_RELOC_32
30383 && fixp->fx_addsy
30384 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30385 return 1;
30386
c19d1205 30387 return generic_force_reloc (fixp);
404ff6b5
AH
30388}
30389
0ffdc86c 30390#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
30391/* Relocations against function names must be left unadjusted,
30392 so that the linker can use this information to generate interworking
30393 stubs. The MIPS version of this function
c19d1205
ZW
30394 also prevents relocations that are mips-16 specific, but I do not
30395 know why it does this.
404ff6b5 30396
c19d1205
ZW
30397 FIXME:
30398 There is one other problem that ought to be addressed here, but
30399 which currently is not: Taking the address of a label (rather
30400 than a function) and then later jumping to that address. Such
30401 addresses also ought to have their bottom bit set (assuming that
30402 they reside in Thumb code), but at the moment they will not. */
404ff6b5 30403
c19d1205
ZW
30404bfd_boolean
30405arm_fix_adjustable (fixS * fixP)
404ff6b5 30406{
c19d1205
ZW
30407 if (fixP->fx_addsy == NULL)
30408 return 1;
404ff6b5 30409
e28387c3
PB
30410 /* Preserve relocations against symbols with function type. */
30411 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 30412 return FALSE;
e28387c3 30413
c19d1205
ZW
30414 if (THUMB_IS_FUNC (fixP->fx_addsy)
30415 && fixP->fx_subsy == NULL)
c921be7d 30416 return FALSE;
a737bd4d 30417
c19d1205
ZW
30418 /* We need the symbol name for the VTABLE entries. */
30419 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30420 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 30421 return FALSE;
404ff6b5 30422
c19d1205
ZW
30423 /* Don't allow symbols to be discarded on GOT related relocs. */
30424 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30425 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30426 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30427 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 30428 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
30429 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30430 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 30431 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 30432 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 30433 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 30434 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
30435 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30436 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30437 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30438 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30439 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 30440 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 30441 return FALSE;
a737bd4d 30442
4962c51a
MS
30443 /* Similarly for group relocations. */
30444 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30445 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30446 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 30447 return FALSE;
4962c51a 30448
79947c54
CD
30449 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30450 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30451 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30452 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30453 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30454 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30455 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30456 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30457 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 30458 return FALSE;
79947c54 30459
72d98d16
MG
30460 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30461 offsets, so keep these symbols. */
30462 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30463 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30464 return FALSE;
30465
c921be7d 30466 return TRUE;
a737bd4d 30467}
0ffdc86c
NC
30468#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30469
30470#ifdef OBJ_ELF
c19d1205
ZW
30471const char *
30472elf32_arm_target_format (void)
404ff6b5 30473{
c19d1205
ZW
30474#ifdef TE_SYMBIAN
30475 return (target_big_endian
30476 ? "elf32-bigarm-symbian"
30477 : "elf32-littlearm-symbian");
30478#elif defined (TE_VXWORKS)
30479 return (target_big_endian
30480 ? "elf32-bigarm-vxworks"
30481 : "elf32-littlearm-vxworks");
b38cadfb
NC
30482#elif defined (TE_NACL)
30483 return (target_big_endian
30484 ? "elf32-bigarm-nacl"
30485 : "elf32-littlearm-nacl");
c19d1205 30486#else
18a20338
CL
30487 if (arm_fdpic)
30488 {
30489 if (target_big_endian)
30490 return "elf32-bigarm-fdpic";
30491 else
30492 return "elf32-littlearm-fdpic";
30493 }
c19d1205 30494 else
18a20338
CL
30495 {
30496 if (target_big_endian)
30497 return "elf32-bigarm";
30498 else
30499 return "elf32-littlearm";
30500 }
c19d1205 30501#endif
404ff6b5
AH
30502}
30503
c19d1205
ZW
30504void
30505armelf_frob_symbol (symbolS * symp,
30506 int * puntp)
404ff6b5 30507{
c19d1205
ZW
30508 elf_frob_symbol (symp, puntp);
30509}
30510#endif
404ff6b5 30511
c19d1205 30512/* MD interface: Finalization. */
a737bd4d 30513
c19d1205
ZW
30514void
30515arm_cleanup (void)
30516{
30517 literal_pool * pool;
a737bd4d 30518
5ee91343
AV
30519 /* Ensure that all the predication blocks are properly closed. */
30520 check_pred_blocks_finished ();
e07e6e58 30521
c19d1205
ZW
30522 for (pool = list_of_pools; pool; pool = pool->next)
30523 {
5f4273c7 30524 /* Put it at the end of the relevant section. */
c19d1205
ZW
30525 subseg_set (pool->section, pool->sub_section);
30526#ifdef OBJ_ELF
30527 arm_elf_change_section ();
30528#endif
30529 s_ltorg (0);
30530 }
404ff6b5
AH
30531}
30532
cd000bff
DJ
30533#ifdef OBJ_ELF
30534/* Remove any excess mapping symbols generated for alignment frags in
30535 SEC. We may have created a mapping symbol before a zero byte
30536 alignment; remove it if there's a mapping symbol after the
30537 alignment. */
30538static void
30539check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30540 void *dummy ATTRIBUTE_UNUSED)
30541{
30542 segment_info_type *seginfo = seg_info (sec);
30543 fragS *fragp;
30544
30545 if (seginfo == NULL || seginfo->frchainP == NULL)
30546 return;
30547
30548 for (fragp = seginfo->frchainP->frch_root;
30549 fragp != NULL;
30550 fragp = fragp->fr_next)
30551 {
30552 symbolS *sym = fragp->tc_frag_data.last_map;
30553 fragS *next = fragp->fr_next;
30554
30555 /* Variable-sized frags have been converted to fixed size by
30556 this point. But if this was variable-sized to start with,
30557 there will be a fixed-size frag after it. So don't handle
30558 next == NULL. */
30559 if (sym == NULL || next == NULL)
30560 continue;
30561
30562 if (S_GET_VALUE (sym) < next->fr_address)
30563 /* Not at the end of this frag. */
30564 continue;
30565 know (S_GET_VALUE (sym) == next->fr_address);
30566
30567 do
30568 {
30569 if (next->tc_frag_data.first_map != NULL)
30570 {
30571 /* Next frag starts with a mapping symbol. Discard this
30572 one. */
30573 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30574 break;
30575 }
30576
30577 if (next->fr_next == NULL)
30578 {
30579 /* This mapping symbol is at the end of the section. Discard
30580 it. */
30581 know (next->fr_fix == 0 && next->fr_var == 0);
30582 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30583 break;
30584 }
30585
30586 /* As long as we have empty frags without any mapping symbols,
30587 keep looking. */
30588 /* If the next frag is non-empty and does not start with a
30589 mapping symbol, then this mapping symbol is required. */
30590 if (next->fr_address != next->fr_next->fr_address)
30591 break;
30592
30593 next = next->fr_next;
30594 }
30595 while (next != NULL);
30596 }
30597}
30598#endif
30599
c19d1205
ZW
30600/* Adjust the symbol table. This marks Thumb symbols as distinct from
30601 ARM ones. */
404ff6b5 30602
c19d1205
ZW
30603void
30604arm_adjust_symtab (void)
404ff6b5 30605{
c19d1205
ZW
30606#ifdef OBJ_COFF
30607 symbolS * sym;
404ff6b5 30608
c19d1205
ZW
30609 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30610 {
30611 if (ARM_IS_THUMB (sym))
30612 {
30613 if (THUMB_IS_FUNC (sym))
30614 {
30615 /* Mark the symbol as a Thumb function. */
30616 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30617 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30618 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 30619
c19d1205
ZW
30620 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30621 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30622 else
30623 as_bad (_("%s: unexpected function type: %d"),
30624 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30625 }
30626 else switch (S_GET_STORAGE_CLASS (sym))
30627 {
30628 case C_EXT:
30629 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30630 break;
30631 case C_STAT:
30632 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30633 break;
30634 case C_LABEL:
30635 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30636 break;
30637 default:
30638 /* Do nothing. */
30639 break;
30640 }
30641 }
a737bd4d 30642
c19d1205
ZW
30643 if (ARM_IS_INTERWORK (sym))
30644 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 30645 }
c19d1205
ZW
30646#endif
30647#ifdef OBJ_ELF
30648 symbolS * sym;
30649 char bind;
404ff6b5 30650
c19d1205 30651 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 30652 {
c19d1205
ZW
30653 if (ARM_IS_THUMB (sym))
30654 {
30655 elf_symbol_type * elf_sym;
404ff6b5 30656
c19d1205
ZW
30657 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30658 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 30659
b0796911
PB
30660 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30661 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
30662 {
30663 /* If it's a .thumb_func, declare it as so,
30664 otherwise tag label as .code 16. */
30665 if (THUMB_IS_FUNC (sym))
39d911fc
TP
30666 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30667 ST_BRANCH_TO_THUMB);
3ba67470 30668 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
30669 elf_sym->internal_elf_sym.st_info =
30670 ELF_ST_INFO (bind, STT_ARM_16BIT);
30671 }
30672 }
30673 }
cd000bff
DJ
30674
30675 /* Remove any overlapping mapping symbols generated by alignment frags. */
30676 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
30677 /* Now do generic ELF adjustments. */
30678 elf_adjust_symtab ();
c19d1205 30679#endif
404ff6b5
AH
30680}
30681
c19d1205 30682/* MD interface: Initialization. */
404ff6b5 30683
a737bd4d 30684static void
c19d1205 30685set_constant_flonums (void)
a737bd4d 30686{
c19d1205 30687 int i;
404ff6b5 30688
c19d1205
ZW
30689 for (i = 0; i < NUM_FLOAT_VALS; i++)
30690 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30691 abort ();
a737bd4d 30692}
404ff6b5 30693
3e9e4fcf
JB
30694/* Auto-select Thumb mode if it's the only available instruction set for the
30695 given architecture. */
30696
30697static void
30698autoselect_thumb_from_cpu_variant (void)
30699{
30700 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30701 opcode_select (16);
30702}
30703
c19d1205
ZW
30704void
30705md_begin (void)
a737bd4d 30706{
c19d1205
ZW
30707 unsigned mach;
30708 unsigned int i;
404ff6b5 30709
c19d1205
ZW
30710 if ( (arm_ops_hsh = hash_new ()) == NULL
30711 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 30712 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
30713 || (arm_shift_hsh = hash_new ()) == NULL
30714 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 30715 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 30716 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
30717 || (arm_reloc_hsh = hash_new ()) == NULL
30718 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
30719 as_fatal (_("virtual memory exhausted"));
30720
30721 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 30722 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 30723 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 30724 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
30725 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30726 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 30727 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 30728 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 30729 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30730 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 30731 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 30732 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 30733 (void *) (v7m_psrs + i));
c19d1205 30734 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 30735 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
30736 for (i = 0;
30737 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30738 i++)
d3ce72d0 30739 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 30740 (void *) (barrier_opt_names + i));
c19d1205 30741#ifdef OBJ_ELF
3da1d841
NC
30742 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30743 {
30744 struct reloc_entry * entry = reloc_names + i;
30745
30746 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30747 /* This makes encode_branch() use the EABI versions of this relocation. */
30748 entry->reloc = BFD_RELOC_UNUSED;
30749
30750 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
30751 }
c19d1205
ZW
30752#endif
30753
30754 set_constant_flonums ();
404ff6b5 30755
c19d1205
ZW
30756 /* Set the cpu variant based on the command-line options. We prefer
30757 -mcpu= over -march= if both are set (as for GCC); and we prefer
30758 -mfpu= over any other way of setting the floating point unit.
30759 Use of legacy options with new options are faulted. */
e74cfd16 30760 if (legacy_cpu)
404ff6b5 30761 {
e74cfd16 30762 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
30763 as_bad (_("use of old and new-style options to set CPU type"));
30764
4d354d8b 30765 selected_arch = *legacy_cpu;
404ff6b5 30766 }
4d354d8b
TP
30767 else if (mcpu_cpu_opt)
30768 {
30769 selected_arch = *mcpu_cpu_opt;
30770 selected_ext = *mcpu_ext_opt;
30771 }
30772 else if (march_cpu_opt)
c168ce07 30773 {
4d354d8b
TP
30774 selected_arch = *march_cpu_opt;
30775 selected_ext = *march_ext_opt;
c168ce07 30776 }
4d354d8b 30777 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 30778
e74cfd16 30779 if (legacy_fpu)
c19d1205 30780 {
e74cfd16 30781 if (mfpu_opt)
c19d1205 30782 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 30783
4d354d8b 30784 selected_fpu = *legacy_fpu;
03b1477f 30785 }
4d354d8b
TP
30786 else if (mfpu_opt)
30787 selected_fpu = *mfpu_opt;
30788 else
03b1477f 30789 {
45eb4c1b
NS
30790#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30791 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
30792 /* Some environments specify a default FPU. If they don't, infer it
30793 from the processor. */
e74cfd16 30794 if (mcpu_fpu_opt)
4d354d8b 30795 selected_fpu = *mcpu_fpu_opt;
e7da50fa 30796 else if (march_fpu_opt)
4d354d8b 30797 selected_fpu = *march_fpu_opt;
39c2da32 30798#else
4d354d8b 30799 selected_fpu = fpu_default;
39c2da32 30800#endif
03b1477f
RE
30801 }
30802
4d354d8b 30803 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 30804 {
4d354d8b
TP
30805 if (!no_cpu_selected ())
30806 selected_fpu = fpu_default;
03b1477f 30807 else
4d354d8b 30808 selected_fpu = fpu_arch_fpa;
03b1477f
RE
30809 }
30810
ee065d83 30811#ifdef CPU_DEFAULT
4d354d8b 30812 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 30813 {
4d354d8b
TP
30814 selected_arch = cpu_default;
30815 selected_cpu = selected_arch;
ee065d83 30816 }
4d354d8b 30817 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 30818#else
4d354d8b
TP
30819 /* Autodection of feature mode: allow all features in cpu_variant but leave
30820 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30821 after all instruction have been processed and we can decide what CPU
30822 should be selected. */
30823 if (ARM_FEATURE_ZERO (selected_arch))
30824 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 30825 else
4d354d8b 30826 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 30827#endif
03b1477f 30828
3e9e4fcf
JB
30829 autoselect_thumb_from_cpu_variant ();
30830
e74cfd16 30831 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 30832
f17c130b 30833#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 30834 {
7cc69913
NC
30835 unsigned int flags = 0;
30836
30837#if defined OBJ_ELF
30838 flags = meabi_flags;
d507cf36
PB
30839
30840 switch (meabi_flags)
33a392fb 30841 {
d507cf36 30842 case EF_ARM_EABI_UNKNOWN:
7cc69913 30843#endif
d507cf36
PB
30844 /* Set the flags in the private structure. */
30845 if (uses_apcs_26) flags |= F_APCS26;
30846 if (support_interwork) flags |= F_INTERWORK;
30847 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 30848 if (pic_code) flags |= F_PIC;
e74cfd16 30849 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
30850 flags |= F_SOFT_FLOAT;
30851
d507cf36
PB
30852 switch (mfloat_abi_opt)
30853 {
30854 case ARM_FLOAT_ABI_SOFT:
30855 case ARM_FLOAT_ABI_SOFTFP:
30856 flags |= F_SOFT_FLOAT;
30857 break;
33a392fb 30858
d507cf36
PB
30859 case ARM_FLOAT_ABI_HARD:
30860 if (flags & F_SOFT_FLOAT)
30861 as_bad (_("hard-float conflicts with specified fpu"));
30862 break;
30863 }
03b1477f 30864
e74cfd16
PB
30865 /* Using pure-endian doubles (even if soft-float). */
30866 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 30867 flags |= F_VFP_FLOAT;
f17c130b 30868
fde78edd 30869#if defined OBJ_ELF
e74cfd16 30870 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 30871 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
30872 break;
30873
8cb51566 30874 case EF_ARM_EABI_VER4:
3a4a14e9 30875 case EF_ARM_EABI_VER5:
c19d1205 30876 /* No additional flags to set. */
d507cf36
PB
30877 break;
30878
30879 default:
30880 abort ();
30881 }
7cc69913 30882#endif
b99bd4ef
NC
30883 bfd_set_private_flags (stdoutput, flags);
30884
30885 /* We have run out flags in the COFF header to encode the
30886 status of ATPCS support, so instead we create a dummy,
c19d1205 30887 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
30888 if (atpcs)
30889 {
30890 asection * sec;
30891
30892 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30893
30894 if (sec != NULL)
30895 {
fd361982
AM
30896 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30897 bfd_set_section_size (sec, 0);
b99bd4ef
NC
30898 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30899 }
30900 }
7cc69913 30901 }
f17c130b 30902#endif
b99bd4ef
NC
30903
30904 /* Record the CPU type as well. */
2d447fca
JM
30905 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30906 mach = bfd_mach_arm_iWMMXt2;
30907 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 30908 mach = bfd_mach_arm_iWMMXt;
e74cfd16 30909 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 30910 mach = bfd_mach_arm_XScale;
e74cfd16 30911 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 30912 mach = bfd_mach_arm_ep9312;
e74cfd16 30913 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 30914 mach = bfd_mach_arm_5TE;
e74cfd16 30915 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 30916 {
e74cfd16 30917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30918 mach = bfd_mach_arm_5T;
30919 else
30920 mach = bfd_mach_arm_5;
30921 }
e74cfd16 30922 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 30923 {
e74cfd16 30924 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30925 mach = bfd_mach_arm_4T;
30926 else
30927 mach = bfd_mach_arm_4;
30928 }
e74cfd16 30929 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 30930 mach = bfd_mach_arm_3M;
e74cfd16
PB
30931 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30932 mach = bfd_mach_arm_3;
30933 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30934 mach = bfd_mach_arm_2a;
30935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30936 mach = bfd_mach_arm_2;
30937 else
30938 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
30939
30940 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30941}
30942
c19d1205 30943/* Command line processing. */
b99bd4ef 30944
c19d1205
ZW
30945/* md_parse_option
30946 Invocation line includes a switch not recognized by the base assembler.
30947 See if it's a processor-specific option.
b99bd4ef 30948
c19d1205
ZW
30949 This routine is somewhat complicated by the need for backwards
30950 compatibility (since older releases of gcc can't be changed).
30951 The new options try to make the interface as compatible as
30952 possible with GCC.
b99bd4ef 30953
c19d1205 30954 New options (supported) are:
b99bd4ef 30955
c19d1205
ZW
30956 -mcpu=<cpu name> Assemble for selected processor
30957 -march=<architecture name> Assemble for selected architecture
30958 -mfpu=<fpu architecture> Assemble for selected FPU.
30959 -EB/-mbig-endian Big-endian
30960 -EL/-mlittle-endian Little-endian
30961 -k Generate PIC code
30962 -mthumb Start in Thumb mode
30963 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30964
278df34e 30965 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30966 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30967
c19d1205 30968 For now we will also provide support for:
b99bd4ef 30969
c19d1205
ZW
30970 -mapcs-32 32-bit Program counter
30971 -mapcs-26 26-bit Program counter
30972 -macps-float Floats passed in FP registers
30973 -mapcs-reentrant Reentrant code
30974 -matpcs
30975 (sometime these will probably be replaced with -mapcs=<list of options>
30976 and -matpcs=<list of options>)
b99bd4ef 30977
c19d1205
ZW
30978 The remaining options are only supported for back-wards compatibility.
30979 Cpu variants, the arm part is optional:
30980 -m[arm]1 Currently not supported.
30981 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30982 -m[arm]3 Arm 3 processor
30983 -m[arm]6[xx], Arm 6 processors
30984 -m[arm]7[xx][t][[d]m] Arm 7 processors
30985 -m[arm]8[10] Arm 8 processors
30986 -m[arm]9[20][tdmi] Arm 9 processors
30987 -mstrongarm[110[0]] StrongARM processors
30988 -mxscale XScale processors
30989 -m[arm]v[2345[t[e]]] Arm architectures
30990 -mall All (except the ARM1)
30991 FP variants:
30992 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
30993 -mfpe-old (No float load/store multiples)
30994 -mvfpxd VFP Single precision
30995 -mvfp All VFP
30996 -mno-fpu Disable all floating point instructions
b99bd4ef 30997
c19d1205
ZW
30998 The following CPU names are recognized:
30999 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31000 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31001 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31002 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31003 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31004 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31005 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 31006
c19d1205 31007 */
b99bd4ef 31008
c19d1205 31009const char * md_shortopts = "m:k";
b99bd4ef 31010
c19d1205
ZW
31011#ifdef ARM_BI_ENDIAN
31012#define OPTION_EB (OPTION_MD_BASE + 0)
31013#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 31014#else
c19d1205
ZW
31015#if TARGET_BYTES_BIG_ENDIAN
31016#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 31017#else
c19d1205
ZW
31018#define OPTION_EL (OPTION_MD_BASE + 1)
31019#endif
b99bd4ef 31020#endif
845b51d6 31021#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 31022#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 31023
c19d1205 31024struct option md_longopts[] =
b99bd4ef 31025{
c19d1205
ZW
31026#ifdef OPTION_EB
31027 {"EB", no_argument, NULL, OPTION_EB},
31028#endif
31029#ifdef OPTION_EL
31030 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 31031#endif
845b51d6 31032 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
31033#ifdef OBJ_ELF
31034 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31035#endif
c19d1205
ZW
31036 {NULL, no_argument, NULL, 0}
31037};
b99bd4ef 31038
c19d1205 31039size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 31040
c19d1205 31041struct arm_option_table
b99bd4ef 31042{
0198d5e6
TC
31043 const char * option; /* Option name to match. */
31044 const char * help; /* Help information. */
31045 int * var; /* Variable to change. */
31046 int value; /* What to change it to. */
31047 const char * deprecated; /* If non-null, print this message. */
c19d1205 31048};
b99bd4ef 31049
c19d1205
ZW
31050struct arm_option_table arm_opts[] =
31051{
31052 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31053 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31054 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31055 &support_interwork, 1, NULL},
31056 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31057 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31058 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31059 1, NULL},
31060 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31061 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31062 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31063 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31064 NULL},
b99bd4ef 31065
c19d1205
ZW
31066 /* These are recognized by the assembler, but have no affect on code. */
31067 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31068 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
31069
31070 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31071 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31072 &warn_on_deprecated, 0, NULL},
24f19ccb
AV
31073
31074 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31075 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31076 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31077
8b2d793c
NC
31078 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31079 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
31080 {NULL, NULL, NULL, 0, NULL}
31081};
31082
31083struct arm_legacy_option_table
31084{
0198d5e6
TC
31085 const char * option; /* Option name to match. */
31086 const arm_feature_set ** var; /* Variable to change. */
31087 const arm_feature_set value; /* What to change it to. */
31088 const char * deprecated; /* If non-null, print this message. */
e74cfd16 31089};
b99bd4ef 31090
e74cfd16
PB
31091const struct arm_legacy_option_table arm_legacy_opts[] =
31092{
c19d1205
ZW
31093 /* DON'T add any new processors to this list -- we want the whole list
31094 to go away... Add them to the processors table instead. */
e74cfd16
PB
31095 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31096 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31097 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31098 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31099 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31100 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31101 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31102 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31103 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31104 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31105 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31106 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31107 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31108 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31109 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31110 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31111 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31112 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31113 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31114 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31115 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31116 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31117 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31118 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31119 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31120 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31121 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31122 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31123 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31124 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31125 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31126 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31127 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31128 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31129 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31130 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31131 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31132 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31133 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31134 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31135 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31136 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31137 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31138 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31139 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31140 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31141 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31142 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31143 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31144 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31145 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31146 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31147 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31148 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31149 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31150 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31151 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31152 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31153 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31154 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31155 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31156 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31157 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31158 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31159 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31160 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31161 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31162 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31163 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31164 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31165 N_("use -mcpu=strongarm110")},
e74cfd16 31166 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31167 N_("use -mcpu=strongarm1100")},
e74cfd16 31168 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31169 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
31170 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31171 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31172 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 31173
c19d1205 31174 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
31175 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31176 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31177 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31178 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31179 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31180 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31181 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31182 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31183 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31184 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31185 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31186 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31187 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31188 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31189 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31190 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31191 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31192 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 31193
c19d1205 31194 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
31195 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31196 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31197 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31198 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 31199 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 31200
e74cfd16 31201 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 31202};
7ed4c4c5 31203
c19d1205 31204struct arm_cpu_option_table
7ed4c4c5 31205{
0198d5e6
TC
31206 const char * name;
31207 size_t name_len;
31208 const arm_feature_set value;
31209 const arm_feature_set ext;
c19d1205
ZW
31210 /* For some CPUs we assume an FPU unless the user explicitly sets
31211 -mfpu=... */
0198d5e6 31212 const arm_feature_set default_fpu;
ee065d83
PB
31213 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31214 case. */
0198d5e6 31215 const char * canonical_name;
c19d1205 31216};
7ed4c4c5 31217
c19d1205
ZW
31218/* This list should, at a minimum, contain all the cpu names
31219 recognized by GCC. */
996b5569 31220#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 31221
e74cfd16 31222static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 31223{
996b5569
TP
31224 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31225 ARM_ARCH_NONE,
31226 FPU_ARCH_FPA),
31227 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31228 ARM_ARCH_NONE,
31229 FPU_ARCH_FPA),
31230 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31231 ARM_ARCH_NONE,
31232 FPU_ARCH_FPA),
31233 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31234 ARM_ARCH_NONE,
31235 FPU_ARCH_FPA),
31236 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31237 ARM_ARCH_NONE,
31238 FPU_ARCH_FPA),
31239 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31240 ARM_ARCH_NONE,
31241 FPU_ARCH_FPA),
31242 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31243 ARM_ARCH_NONE,
31244 FPU_ARCH_FPA),
31245 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31246 ARM_ARCH_NONE,
31247 FPU_ARCH_FPA),
31248 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31249 ARM_ARCH_NONE,
31250 FPU_ARCH_FPA),
31251 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31252 ARM_ARCH_NONE,
31253 FPU_ARCH_FPA),
31254 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31255 ARM_ARCH_NONE,
31256 FPU_ARCH_FPA),
31257 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31258 ARM_ARCH_NONE,
31259 FPU_ARCH_FPA),
31260 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31261 ARM_ARCH_NONE,
31262 FPU_ARCH_FPA),
31263 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31264 ARM_ARCH_NONE,
31265 FPU_ARCH_FPA),
31266 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31267 ARM_ARCH_NONE,
31268 FPU_ARCH_FPA),
31269 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31270 ARM_ARCH_NONE,
31271 FPU_ARCH_FPA),
31272 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31273 ARM_ARCH_NONE,
31274 FPU_ARCH_FPA),
31275 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31276 ARM_ARCH_NONE,
31277 FPU_ARCH_FPA),
31278 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31279 ARM_ARCH_NONE,
31280 FPU_ARCH_FPA),
31281 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31282 ARM_ARCH_NONE,
31283 FPU_ARCH_FPA),
31284 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31285 ARM_ARCH_NONE,
31286 FPU_ARCH_FPA),
31287 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31288 ARM_ARCH_NONE,
31289 FPU_ARCH_FPA),
31290 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31291 ARM_ARCH_NONE,
31292 FPU_ARCH_FPA),
31293 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31294 ARM_ARCH_NONE,
31295 FPU_ARCH_FPA),
31296 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31297 ARM_ARCH_NONE,
31298 FPU_ARCH_FPA),
31299 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31300 ARM_ARCH_NONE,
31301 FPU_ARCH_FPA),
31302 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31303 ARM_ARCH_NONE,
31304 FPU_ARCH_FPA),
31305 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31306 ARM_ARCH_NONE,
31307 FPU_ARCH_FPA),
31308 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31309 ARM_ARCH_NONE,
31310 FPU_ARCH_FPA),
31311 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31312 ARM_ARCH_NONE,
31313 FPU_ARCH_FPA),
31314 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31315 ARM_ARCH_NONE,
31316 FPU_ARCH_FPA),
31317 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31318 ARM_ARCH_NONE,
31319 FPU_ARCH_FPA),
31320 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31321 ARM_ARCH_NONE,
31322 FPU_ARCH_FPA),
31323 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31324 ARM_ARCH_NONE,
31325 FPU_ARCH_FPA),
31326 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31327 ARM_ARCH_NONE,
31328 FPU_ARCH_FPA),
31329 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31330 ARM_ARCH_NONE,
31331 FPU_ARCH_FPA),
31332 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31333 ARM_ARCH_NONE,
31334 FPU_ARCH_FPA),
31335 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31336 ARM_ARCH_NONE,
31337 FPU_ARCH_FPA),
31338 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31339 ARM_ARCH_NONE,
31340 FPU_ARCH_FPA),
31341 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31342 ARM_ARCH_NONE,
31343 FPU_ARCH_FPA),
31344 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31345 ARM_ARCH_NONE,
31346 FPU_ARCH_FPA),
31347 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31348 ARM_ARCH_NONE,
31349 FPU_ARCH_FPA),
31350 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31351 ARM_ARCH_NONE,
31352 FPU_ARCH_FPA),
31353 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31354 ARM_ARCH_NONE,
31355 FPU_ARCH_FPA),
31356 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31357 ARM_ARCH_NONE,
31358 FPU_ARCH_FPA),
31359 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31360 ARM_ARCH_NONE,
31361 FPU_ARCH_FPA),
31362
c19d1205
ZW
31363 /* For V5 or later processors we default to using VFP; but the user
31364 should really set the FPU type explicitly. */
996b5569
TP
31365 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31366 ARM_ARCH_NONE,
31367 FPU_ARCH_VFP_V2),
31368 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31369 ARM_ARCH_NONE,
31370 FPU_ARCH_VFP_V2),
31371 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31372 ARM_ARCH_NONE,
31373 FPU_ARCH_VFP_V2),
31374 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31375 ARM_ARCH_NONE,
31376 FPU_ARCH_VFP_V2),
31377 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31378 ARM_ARCH_NONE,
31379 FPU_ARCH_VFP_V2),
31380 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31381 ARM_ARCH_NONE,
31382 FPU_ARCH_VFP_V2),
31383 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31384 ARM_ARCH_NONE,
31385 FPU_ARCH_VFP_V2),
31386 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31387 ARM_ARCH_NONE,
31388 FPU_ARCH_VFP_V2),
31389 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31390 ARM_ARCH_NONE,
31391 FPU_ARCH_VFP_V2),
31392 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31393 ARM_ARCH_NONE,
31394 FPU_ARCH_VFP_V2),
31395 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31396 ARM_ARCH_NONE,
31397 FPU_ARCH_VFP_V2),
31398 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31399 ARM_ARCH_NONE,
31400 FPU_ARCH_VFP_V2),
31401 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31402 ARM_ARCH_NONE,
31403 FPU_ARCH_VFP_V1),
31404 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31405 ARM_ARCH_NONE,
31406 FPU_ARCH_VFP_V1),
31407 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31408 ARM_ARCH_NONE,
31409 FPU_ARCH_VFP_V2),
31410 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31411 ARM_ARCH_NONE,
31412 FPU_ARCH_VFP_V2),
31413 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31414 ARM_ARCH_NONE,
31415 FPU_ARCH_VFP_V1),
31416 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31417 ARM_ARCH_NONE,
31418 FPU_ARCH_VFP_V2),
31419 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31420 ARM_ARCH_NONE,
31421 FPU_ARCH_VFP_V2),
31422 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31423 ARM_ARCH_NONE,
31424 FPU_ARCH_VFP_V2),
31425 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31426 ARM_ARCH_NONE,
31427 FPU_ARCH_VFP_V2),
31428 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31429 ARM_ARCH_NONE,
31430 FPU_ARCH_VFP_V2),
31431 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31432 ARM_ARCH_NONE,
31433 FPU_ARCH_VFP_V2),
31434 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31435 ARM_ARCH_NONE,
31436 FPU_ARCH_VFP_V2),
31437 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31438 ARM_ARCH_NONE,
31439 FPU_ARCH_VFP_V2),
31440 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31441 ARM_ARCH_NONE,
31442 FPU_ARCH_VFP_V2),
31443 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31444 ARM_ARCH_NONE,
31445 FPU_NONE),
31446 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31447 ARM_ARCH_NONE,
31448 FPU_NONE),
31449 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31450 ARM_ARCH_NONE,
31451 FPU_ARCH_VFP_V2),
31452 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31453 ARM_ARCH_NONE,
31454 FPU_ARCH_VFP_V2),
31455 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31456 ARM_ARCH_NONE,
31457 FPU_ARCH_VFP_V2),
31458 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31459 ARM_ARCH_NONE,
31460 FPU_NONE),
31461 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31462 ARM_ARCH_NONE,
31463 FPU_NONE),
31464 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31465 ARM_ARCH_NONE,
31466 FPU_ARCH_VFP_V2),
31467 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31468 ARM_ARCH_NONE,
31469 FPU_NONE),
31470 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31471 ARM_ARCH_NONE,
31472 FPU_ARCH_VFP_V2),
31473 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31474 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31475 FPU_NONE),
31476 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31477 ARM_ARCH_NONE,
31478 FPU_ARCH_NEON_VFP_V4),
31479 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31480 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31481 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31482 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31483 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31484 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31485 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31486 ARM_ARCH_NONE,
31487 FPU_ARCH_NEON_VFP_V4),
31488 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31489 ARM_ARCH_NONE,
31490 FPU_ARCH_NEON_VFP_V4),
31491 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31492 ARM_ARCH_NONE,
31493 FPU_ARCH_NEON_VFP_V4),
31494 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
8b301fbb 31495 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31496 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31497 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
8b301fbb 31498 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31499 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31500 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
8b301fbb 31501 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31502 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31503 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31504 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31505 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569 31506 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
8b301fbb 31507 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31508 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31509 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
8b301fbb 31510 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31511 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31512 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
8b301fbb 31513 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31514 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31515 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31516 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31517 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 31518 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31519 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31520 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
0535e5d7
DZ
31521 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31522 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31523 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31524 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31525 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31526 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
31527 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31528 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31529 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
31530 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31531 ARM_ARCH_NONE,
31532 FPU_NONE),
31533 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31534 ARM_ARCH_NONE,
31535 FPU_ARCH_VFP_V3D16),
31536 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31537 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31538 FPU_NONE),
31539 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31540 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31541 FPU_ARCH_VFP_V3D16),
31542 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31543 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31544 FPU_ARCH_VFP_V3D16),
0cda1e19 31545 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
8b301fbb 31546 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
0cda1e19 31547 FPU_ARCH_NEON_VFP_ARMV8),
0535e5d7
DZ
31548 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31549 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31550 FPU_NONE),
996b5569
TP
31551 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31552 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31553 FPU_NONE),
31554 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31555 ARM_ARCH_NONE,
31556 FPU_NONE),
31557 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31558 ARM_ARCH_NONE,
31559 FPU_NONE),
31560 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31561 ARM_ARCH_NONE,
31562 FPU_NONE),
31563 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31564 ARM_ARCH_NONE,
31565 FPU_NONE),
31566 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31567 ARM_ARCH_NONE,
31568 FPU_NONE),
31569 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31570 ARM_ARCH_NONE,
31571 FPU_NONE),
31572 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31573 ARM_ARCH_NONE,
31574 FPU_NONE),
31575 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
8b301fbb 31576 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31577 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
31578 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31579 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31580 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 31581 /* ??? XSCALE is really an architecture. */
996b5569
TP
31582 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31583 ARM_ARCH_NONE,
31584 FPU_ARCH_VFP_V2),
31585
c19d1205 31586 /* ??? iwmmxt is not a processor. */
996b5569
TP
31587 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31588 ARM_ARCH_NONE,
31589 FPU_ARCH_VFP_V2),
31590 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31591 ARM_ARCH_NONE,
31592 FPU_ARCH_VFP_V2),
31593 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31594 ARM_ARCH_NONE,
31595 FPU_ARCH_VFP_V2),
31596
0198d5e6 31597 /* Maverick. */
996b5569
TP
31598 ARM_CPU_OPT ("ep9312", "ARM920T",
31599 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31600 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31601
da4339ed 31602 /* Marvell processors. */
996b5569
TP
31603 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31604 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31605 FPU_ARCH_VFP_V3D16),
31606 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31607 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31608 FPU_ARCH_NEON_VFP_V4),
da4339ed 31609
996b5569
TP
31610 /* APM X-Gene family. */
31611 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31612 ARM_ARCH_NONE,
31613 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31614 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
8b301fbb 31615 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31616 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31617
31618 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31619};
f3bad469 31620#undef ARM_CPU_OPT
7ed4c4c5 31621
34ef62f4
AV
31622struct arm_ext_table
31623{
31624 const char * name;
31625 size_t name_len;
31626 const arm_feature_set merge;
31627 const arm_feature_set clear;
31628};
31629
c19d1205 31630struct arm_arch_option_table
7ed4c4c5 31631{
34ef62f4
AV
31632 const char * name;
31633 size_t name_len;
31634 const arm_feature_set value;
31635 const arm_feature_set default_fpu;
31636 const struct arm_ext_table * ext_table;
31637};
31638
31639/* Used to add support for +E and +noE extension. */
31640#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31641/* Used to add support for a +E extension. */
31642#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31643/* Used to add support for a +noE extension. */
31644#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31645
31646#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31647 ~0 & ~FPU_ENDIAN_PURE)
31648
31649static const struct arm_ext_table armv5te_ext_table[] =
31650{
31651 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31652 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31653};
31654
31655static const struct arm_ext_table armv7_ext_table[] =
31656{
31657 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31658 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31659};
31660
31661static const struct arm_ext_table armv7ve_ext_table[] =
31662{
31663 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31664 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31665 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31666 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31667 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31668 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31669 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31670
31671 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31672 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31673
31674 /* Aliases for +simd. */
31675 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31676
31677 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31678 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31679 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31680
31681 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31682};
31683
31684static const struct arm_ext_table armv7a_ext_table[] =
31685{
31686 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31687 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31688 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31689 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31690 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31691 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31692 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31693
31694 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31695 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31696
31697 /* Aliases for +simd. */
31698 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31699 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31700
31701 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31702 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31703
31704 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31705 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31706 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31707};
31708
31709static const struct arm_ext_table armv7r_ext_table[] =
31710{
31711 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31712 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31713 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31714 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31715 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31716 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31717 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31718 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31719 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31720};
31721
31722static const struct arm_ext_table armv7em_ext_table[] =
31723{
31724 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31725 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31726 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31727 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31728 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31729 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31730 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31731};
31732
31733static const struct arm_ext_table armv8a_ext_table[] =
31734{
8b301fbb 31735 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31736 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31737 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31738 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31739
31740 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31741 should use the +simd option to turn on FP. */
31742 ARM_REMOVE ("fp", ALL_FP),
31743 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31744 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31745 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31746};
31747
31748
31749static const struct arm_ext_table armv81a_ext_table[] =
31750{
31751 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31752 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31753 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31754
31755 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31756 should use the +simd option to turn on FP. */
31757 ARM_REMOVE ("fp", ALL_FP),
31758 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31759 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31760 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31761};
31762
31763static const struct arm_ext_table armv82a_ext_table[] =
31764{
31765 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31766 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31767 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
616ce08e
MM
31768 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31769 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31770 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31771 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31772 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31773
31774 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31775 should use the +simd option to turn on FP. */
31776 ARM_REMOVE ("fp", ALL_FP),
31777 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31778 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31779 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31780};
31781
31782static const struct arm_ext_table armv84a_ext_table[] =
31783{
31784 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31785 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31786 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31787 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31788 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31789 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31790
31791 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31792 should use the +simd option to turn on FP. */
31793 ARM_REMOVE ("fp", ALL_FP),
31794 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31795 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31796 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31797};
31798
31799static const struct arm_ext_table armv85a_ext_table[] =
31800{
31801 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31802 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31803 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31804 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31805 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31806 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31807
31808 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31809 should use the +simd option to turn on FP. */
31810 ARM_REMOVE ("fp", ALL_FP),
31811 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31812};
31813
aab2c27d
MM
31814static const struct arm_ext_table armv86a_ext_table[] =
31815{
616ce08e 31816 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
aab2c27d
MM
31817 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31818};
31819
4934a27c
MM
31820#define CDE_EXTENSIONS \
31821 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31822 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31823 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31824 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31825 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31826 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31827 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31828 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31829
34ef62f4
AV
31830static const struct arm_ext_table armv8m_main_ext_table[] =
31831{
92169145
AV
31832 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31833 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
34ef62f4
AV
31834 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31835 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
4934a27c 31836 CDE_EXTENSIONS,
34ef62f4
AV
31837 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31838};
31839
92169145 31840
e0991585
AV
31841static const struct arm_ext_table armv8_1m_main_ext_table[] =
31842{
92169145
AV
31843 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31844 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
e0991585
AV
31845 ARM_EXT ("fp",
31846 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31847 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31848 ALL_FP),
31849 ARM_ADD ("fp.dp",
31850 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31851 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
92169145 31852 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
2da2eaf4 31853 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
a7ad558c 31854 ARM_ADD ("mve.fp",
92169145
AV
31855 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31856 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
2da2eaf4 31857 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
4934a27c 31858 CDE_EXTENSIONS,
e0991585
AV
31859 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31860};
31861
4934a27c
MM
31862#undef CDE_EXTENSIONS
31863
34ef62f4
AV
31864static const struct arm_ext_table armv8r_ext_table[] =
31865{
8b301fbb 31866 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31867 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31868 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31869 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31870 ARM_REMOVE ("fp", ALL_FP),
31871 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31872 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 31873};
7ed4c4c5 31874
c19d1205
ZW
31875/* This list should, at a minimum, contain all the architecture names
31876 recognized by GCC. */
34ef62f4
AV
31877#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31878#define ARM_ARCH_OPT2(N, V, DF, ext) \
31879 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 31880
e74cfd16 31881static const struct arm_arch_option_table arm_archs[] =
c19d1205 31882{
497d849d
TP
31883 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31884 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31885 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31886 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31887 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31888 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31889 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31890 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31891 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31892 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31893 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31894 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31895 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31896 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
31897 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31898 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31899 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31900 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31901 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31902 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31903 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31904 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31905 kept to preserve existing behaviour. */
34ef62f4
AV
31906 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31907 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31908 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31909 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31910 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31911 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31912 kept to preserve existing behaviour. */
34ef62f4
AV
31913 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31914 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
31915 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31916 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 31917 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
31918 /* The official spelling of the ARMv7 profile variants is the dashed form.
31919 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
31920 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31921 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31922 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31923 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
31924 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31925 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31926 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 31927 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 31928 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
31929 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31930 armv8m_main),
e0991585
AV
31931 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31932 armv8_1m_main),
34ef62f4
AV
31933 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31934 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31935 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31936 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31937 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31938 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31939 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
aab2c27d 31940 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
497d849d
TP
31941 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31942 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31943 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 31944 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31945};
f3bad469 31946#undef ARM_ARCH_OPT
7ed4c4c5 31947
69133863 31948/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 31949
69133863 31950struct arm_option_extension_value_table
c19d1205 31951{
0198d5e6
TC
31952 const char * name;
31953 size_t name_len;
31954 const arm_feature_set merge_value;
31955 const arm_feature_set clear_value;
d942732e
TP
31956 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31957 indicates that an extension is available for all architectures while
31958 ARM_ANY marks an empty entry. */
0198d5e6 31959 const arm_feature_set allowed_archs[2];
c19d1205 31960};
7ed4c4c5 31961
0198d5e6
TC
31962/* The following table must be in alphabetical order with a NULL last entry. */
31963
d942732e
TP
31964#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31965#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 31966
34ef62f4
AV
31967/* DEPRECATED: Refrain from using this table to add any new extensions, instead
31968 use the context sensitive approach using arm_ext_table's. */
69133863 31969static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 31970{
8b301fbb
MI
31971 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31972 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
823d2571 31973 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 31974 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
31975 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31976 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
31977 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31978 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31979 ARM_ARCH_V8_2A),
15afaa63
TP
31980 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31981 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31982 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
31983 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31984 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
31985 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31986 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31987 ARM_ARCH_V8_2A),
01f48020
TC
31988 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31989 | ARM_EXT2_FP16_FML),
31990 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31991 | ARM_EXT2_FP16_FML),
31992 ARM_ARCH_V8_2A),
d942732e 31993 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 31994 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
31995 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31996 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
31997 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
31998 Thumb divide instruction. Due to this having the same name as the
31999 previous entry, this will be ignored when doing command-line parsing and
32000 only considered by build attribute selection code. */
32001 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32002 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32003 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 32004 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 32005 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 32006 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 32007 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 32008 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
32009 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32010 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 32011 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
32012 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32013 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
32014 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32015 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32016 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
32017 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32018 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 32019 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
32020 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32021 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32022 ARM_ARCH_V8A),
4d1464f2
MW
32023 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32024 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 32025 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
32026 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32027 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 32028 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
32029 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32030 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32031 ARM_ARCH_V8A),
d942732e 32032 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 32033 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
32034 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32035 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
32036 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32037 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32038 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
32039 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32040 | ARM_EXT_DIV),
32041 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32042 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32043 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
32044 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32045 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 32046};
f3bad469 32047#undef ARM_EXT_OPT
69133863
MGD
32048
32049/* ISA floating-point and Advanced SIMD extensions. */
32050struct arm_option_fpu_value_table
32051{
0198d5e6
TC
32052 const char * name;
32053 const arm_feature_set value;
c19d1205 32054};
7ed4c4c5 32055
c19d1205
ZW
32056/* This list should, at a minimum, contain all the fpu names
32057 recognized by GCC. */
69133863 32058static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
32059{
32060 {"softfpa", FPU_NONE},
32061 {"fpe", FPU_ARCH_FPE},
32062 {"fpe2", FPU_ARCH_FPE},
32063 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32064 {"fpa", FPU_ARCH_FPA},
32065 {"fpa10", FPU_ARCH_FPA},
32066 {"fpa11", FPU_ARCH_FPA},
32067 {"arm7500fe", FPU_ARCH_FPA},
32068 {"softvfp", FPU_ARCH_VFP},
32069 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32070 {"vfp", FPU_ARCH_VFP_V2},
32071 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 32072 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
32073 {"vfp10", FPU_ARCH_VFP_V2},
32074 {"vfp10-r0", FPU_ARCH_VFP_V1},
32075 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
32076 {"vfpv2", FPU_ARCH_VFP_V2},
32077 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 32078 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 32079 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
32080 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32081 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32082 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
32083 {"arm1020t", FPU_ARCH_VFP_V1},
32084 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 32085 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
32086 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32087 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 32088 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 32089 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 32090 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
32091 {"vfpv4", FPU_ARCH_VFP_V4},
32092 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 32093 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
32094 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32095 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 32096 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
32097 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32098 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32099 {"crypto-neon-fp-armv8",
32100 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 32101 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
32102 {"crypto-neon-fp-armv8.1",
32103 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
32104 {NULL, ARM_ARCH_NONE}
32105};
32106
32107struct arm_option_value_table
32108{
e0471c16 32109 const char *name;
e74cfd16 32110 long value;
c19d1205 32111};
7ed4c4c5 32112
e74cfd16 32113static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
32114{
32115 {"hard", ARM_FLOAT_ABI_HARD},
32116 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32117 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 32118 {NULL, 0}
c19d1205 32119};
7ed4c4c5 32120
c19d1205 32121#ifdef OBJ_ELF
3a4a14e9 32122/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 32123static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
32124{
32125 {"gnu", EF_ARM_EABI_UNKNOWN},
32126 {"4", EF_ARM_EABI_VER4},
3a4a14e9 32127 {"5", EF_ARM_EABI_VER5},
e74cfd16 32128 {NULL, 0}
c19d1205
ZW
32129};
32130#endif
7ed4c4c5 32131
c19d1205
ZW
32132struct arm_long_option_table
32133{
0198d5e6 32134 const char * option; /* Substring to match. */
e0471c16 32135 const char * help; /* Help information. */
17b9d67d 32136 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 32137 const char * deprecated; /* If non-null, print this message. */
c19d1205 32138};
7ed4c4c5 32139
c921be7d 32140static bfd_boolean
c168ce07 32141arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
32142 arm_feature_set *ext_set,
32143 const struct arm_ext_table *ext_table)
7ed4c4c5 32144{
69133863 32145 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
32146 extensions being added before being removed. We achieve this by having
32147 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 32148 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 32149 or removing it (0) and only allowing it to change in the order
69133863
MGD
32150 -1 -> 1 -> 0. */
32151 const struct arm_option_extension_value_table * opt = NULL;
d942732e 32152 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
32153 int adding_value = -1;
32154
c19d1205 32155 while (str != NULL && *str != 0)
7ed4c4c5 32156 {
82b8a785 32157 const char *ext;
f3bad469 32158 size_t len;
7ed4c4c5 32159
c19d1205
ZW
32160 if (*str != '+')
32161 {
32162 as_bad (_("invalid architectural extension"));
c921be7d 32163 return FALSE;
c19d1205 32164 }
7ed4c4c5 32165
c19d1205
ZW
32166 str++;
32167 ext = strchr (str, '+');
7ed4c4c5 32168
c19d1205 32169 if (ext != NULL)
f3bad469 32170 len = ext - str;
c19d1205 32171 else
f3bad469 32172 len = strlen (str);
7ed4c4c5 32173
f3bad469 32174 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
32175 {
32176 if (adding_value != 0)
32177 {
32178 adding_value = 0;
32179 opt = arm_extensions;
32180 }
32181
f3bad469 32182 len -= 2;
69133863
MGD
32183 str += 2;
32184 }
f3bad469 32185 else if (len > 0)
69133863
MGD
32186 {
32187 if (adding_value == -1)
32188 {
32189 adding_value = 1;
32190 opt = arm_extensions;
32191 }
32192 else if (adding_value != 1)
32193 {
32194 as_bad (_("must specify extensions to add before specifying "
32195 "those to remove"));
32196 return FALSE;
32197 }
32198 }
32199
f3bad469 32200 if (len == 0)
c19d1205
ZW
32201 {
32202 as_bad (_("missing architectural extension"));
c921be7d 32203 return FALSE;
c19d1205 32204 }
7ed4c4c5 32205
69133863
MGD
32206 gas_assert (adding_value != -1);
32207 gas_assert (opt != NULL);
32208
34ef62f4
AV
32209 if (ext_table != NULL)
32210 {
32211 const struct arm_ext_table * ext_opt = ext_table;
32212 bfd_boolean found = FALSE;
32213 for (; ext_opt->name != NULL; ext_opt++)
32214 if (ext_opt->name_len == len
32215 && strncmp (ext_opt->name, str, len) == 0)
32216 {
32217 if (adding_value)
32218 {
32219 if (ARM_FEATURE_ZERO (ext_opt->merge))
32220 /* TODO: Option not supported. When we remove the
32221 legacy table this case should error out. */
32222 continue;
32223
32224 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32225 }
32226 else
32227 {
32228 if (ARM_FEATURE_ZERO (ext_opt->clear))
32229 /* TODO: Option not supported. When we remove the
32230 legacy table this case should error out. */
32231 continue;
32232 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32233 }
32234 found = TRUE;
32235 break;
32236 }
32237 if (found)
32238 {
32239 str = ext;
32240 continue;
32241 }
32242 }
32243
69133863
MGD
32244 /* Scan over the options table trying to find an exact match. */
32245 for (; opt->name != NULL; opt++)
f3bad469 32246 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32247 {
d942732e
TP
32248 int i, nb_allowed_archs =
32249 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 32250 /* Check we can apply the extension to this architecture. */
d942732e
TP
32251 for (i = 0; i < nb_allowed_archs; i++)
32252 {
32253 /* Empty entry. */
32254 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32255 continue;
c168ce07 32256 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
32257 break;
32258 }
32259 if (i == nb_allowed_archs)
69133863
MGD
32260 {
32261 as_bad (_("extension does not apply to the base architecture"));
32262 return FALSE;
32263 }
32264
32265 /* Add or remove the extension. */
32266 if (adding_value)
4d354d8b 32267 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 32268 else
4d354d8b 32269 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 32270
3d030cdb
TP
32271 /* Allowing Thumb division instructions for ARMv7 in autodetection
32272 rely on this break so that duplicate extensions (extensions
32273 with the same name as a previous extension in the list) are not
32274 considered for command-line parsing. */
c19d1205
ZW
32275 break;
32276 }
7ed4c4c5 32277
c19d1205
ZW
32278 if (opt->name == NULL)
32279 {
69133863
MGD
32280 /* Did we fail to find an extension because it wasn't specified in
32281 alphabetical order, or because it does not exist? */
32282
32283 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 32284 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
32285 break;
32286
32287 if (opt->name == NULL)
32288 as_bad (_("unknown architectural extension `%s'"), str);
32289 else
32290 as_bad (_("architectural extensions must be specified in "
32291 "alphabetical order"));
32292
c921be7d 32293 return FALSE;
c19d1205 32294 }
69133863
MGD
32295 else
32296 {
32297 /* We should skip the extension we've just matched the next time
32298 round. */
32299 opt++;
32300 }
7ed4c4c5 32301
c19d1205
ZW
32302 str = ext;
32303 };
7ed4c4c5 32304
c921be7d 32305 return TRUE;
c19d1205 32306}
7ed4c4c5 32307
5312fe52
BW
32308static bfd_boolean
32309arm_parse_fp16_opt (const char *str)
32310{
32311 if (strcasecmp (str, "ieee") == 0)
32312 fp16_format = ARM_FP16_FORMAT_IEEE;
32313 else if (strcasecmp (str, "alternative") == 0)
32314 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32315 else
32316 {
32317 as_bad (_("unrecognised float16 format \"%s\""), str);
32318 return FALSE;
32319 }
32320
32321 return TRUE;
32322}
32323
c921be7d 32324static bfd_boolean
17b9d67d 32325arm_parse_cpu (const char *str)
7ed4c4c5 32326{
f3bad469 32327 const struct arm_cpu_option_table *opt;
82b8a785 32328 const char *ext = strchr (str, '+');
f3bad469 32329 size_t len;
7ed4c4c5 32330
c19d1205 32331 if (ext != NULL)
f3bad469 32332 len = ext - str;
7ed4c4c5 32333 else
f3bad469 32334 len = strlen (str);
7ed4c4c5 32335
f3bad469 32336 if (len == 0)
7ed4c4c5 32337 {
c19d1205 32338 as_bad (_("missing cpu name `%s'"), str);
c921be7d 32339 return FALSE;
7ed4c4c5
NC
32340 }
32341
c19d1205 32342 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 32343 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32344 {
c168ce07 32345 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
32346 if (mcpu_ext_opt == NULL)
32347 mcpu_ext_opt = XNEW (arm_feature_set);
32348 *mcpu_ext_opt = opt->ext;
e74cfd16 32349 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 32350 if (opt->canonical_name)
ef8e6722
JW
32351 {
32352 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32353 strcpy (selected_cpu_name, opt->canonical_name);
32354 }
ee065d83
PB
32355 else
32356 {
f3bad469 32357 size_t i;
c921be7d 32358
ef8e6722
JW
32359 if (len >= sizeof selected_cpu_name)
32360 len = (sizeof selected_cpu_name) - 1;
32361
f3bad469 32362 for (i = 0; i < len; i++)
ee065d83
PB
32363 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32364 selected_cpu_name[i] = 0;
32365 }
7ed4c4c5 32366
c19d1205 32367 if (ext != NULL)
34ef62f4 32368 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 32369
c921be7d 32370 return TRUE;
c19d1205 32371 }
7ed4c4c5 32372
c19d1205 32373 as_bad (_("unknown cpu `%s'"), str);
c921be7d 32374 return FALSE;
7ed4c4c5
NC
32375}
32376
c921be7d 32377static bfd_boolean
17b9d67d 32378arm_parse_arch (const char *str)
7ed4c4c5 32379{
e74cfd16 32380 const struct arm_arch_option_table *opt;
82b8a785 32381 const char *ext = strchr (str, '+');
f3bad469 32382 size_t len;
7ed4c4c5 32383
c19d1205 32384 if (ext != NULL)
f3bad469 32385 len = ext - str;
7ed4c4c5 32386 else
f3bad469 32387 len = strlen (str);
7ed4c4c5 32388
f3bad469 32389 if (len == 0)
7ed4c4c5 32390 {
c19d1205 32391 as_bad (_("missing architecture name `%s'"), str);
c921be7d 32392 return FALSE;
7ed4c4c5
NC
32393 }
32394
c19d1205 32395 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 32396 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32397 {
e74cfd16 32398 march_cpu_opt = &opt->value;
4d354d8b
TP
32399 if (march_ext_opt == NULL)
32400 march_ext_opt = XNEW (arm_feature_set);
32401 *march_ext_opt = arm_arch_none;
e74cfd16 32402 march_fpu_opt = &opt->default_fpu;
e20f9590 32403 selected_ctx_ext_table = opt->ext_table;
5f4273c7 32404 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 32405
c19d1205 32406 if (ext != NULL)
34ef62f4
AV
32407 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32408 opt->ext_table);
7ed4c4c5 32409
c921be7d 32410 return TRUE;
c19d1205
ZW
32411 }
32412
32413 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 32414 return FALSE;
7ed4c4c5 32415}
eb043451 32416
c921be7d 32417static bfd_boolean
17b9d67d 32418arm_parse_fpu (const char * str)
c19d1205 32419{
69133863 32420 const struct arm_option_fpu_value_table * opt;
b99bd4ef 32421
c19d1205
ZW
32422 for (opt = arm_fpus; opt->name != NULL; opt++)
32423 if (streq (opt->name, str))
32424 {
e74cfd16 32425 mfpu_opt = &opt->value;
c921be7d 32426 return TRUE;
c19d1205 32427 }
b99bd4ef 32428
c19d1205 32429 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 32430 return FALSE;
c19d1205
ZW
32431}
32432
c921be7d 32433static bfd_boolean
17b9d67d 32434arm_parse_float_abi (const char * str)
b99bd4ef 32435{
e74cfd16 32436 const struct arm_option_value_table * opt;
b99bd4ef 32437
c19d1205
ZW
32438 for (opt = arm_float_abis; opt->name != NULL; opt++)
32439 if (streq (opt->name, str))
32440 {
32441 mfloat_abi_opt = opt->value;
c921be7d 32442 return TRUE;
c19d1205 32443 }
cc8a6dd0 32444
c19d1205 32445 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 32446 return FALSE;
c19d1205 32447}
b99bd4ef 32448
c19d1205 32449#ifdef OBJ_ELF
c921be7d 32450static bfd_boolean
17b9d67d 32451arm_parse_eabi (const char * str)
c19d1205 32452{
e74cfd16 32453 const struct arm_option_value_table *opt;
cc8a6dd0 32454
c19d1205
ZW
32455 for (opt = arm_eabis; opt->name != NULL; opt++)
32456 if (streq (opt->name, str))
32457 {
32458 meabi_flags = opt->value;
c921be7d 32459 return TRUE;
c19d1205
ZW
32460 }
32461 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 32462 return FALSE;
c19d1205
ZW
32463}
32464#endif
cc8a6dd0 32465
c921be7d 32466static bfd_boolean
17b9d67d 32467arm_parse_it_mode (const char * str)
e07e6e58 32468{
c921be7d 32469 bfd_boolean ret = TRUE;
e07e6e58
NC
32470
32471 if (streq ("arm", str))
32472 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32473 else if (streq ("thumb", str))
32474 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32475 else if (streq ("always", str))
32476 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32477 else if (streq ("never", str))
32478 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32479 else
32480 {
32481 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 32482 "arm, thumb, always, or never."), str);
c921be7d 32483 ret = FALSE;
e07e6e58
NC
32484 }
32485
32486 return ret;
32487}
32488
2e6976a8 32489static bfd_boolean
17b9d67d 32490arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
32491{
32492 codecomposer_syntax = TRUE;
32493 arm_comment_chars[0] = ';';
32494 arm_line_separator_chars[0] = 0;
32495 return TRUE;
32496}
32497
c19d1205
ZW
32498struct arm_long_option_table arm_long_opts[] =
32499{
32500 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32501 arm_parse_cpu, NULL},
32502 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32503 arm_parse_arch, NULL},
32504 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32505 arm_parse_fpu, NULL},
32506 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32507 arm_parse_float_abi, NULL},
32508#ifdef OBJ_ELF
7fac0536 32509 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
32510 arm_parse_eabi, NULL},
32511#endif
e07e6e58
NC
32512 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32513 arm_parse_it_mode, NULL},
2e6976a8
DG
32514 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32515 arm_ccs_mode, NULL},
5312fe52
BW
32516 {"mfp16-format=",
32517 N_("[ieee|alternative]\n\
32518 set the encoding for half precision floating point "
32519 "numbers to IEEE\n\
32520 or Arm alternative format."),
32521 arm_parse_fp16_opt, NULL },
c19d1205
ZW
32522 {NULL, NULL, 0, NULL}
32523};
cc8a6dd0 32524
c19d1205 32525int
17b9d67d 32526md_parse_option (int c, const char * arg)
c19d1205
ZW
32527{
32528 struct arm_option_table *opt;
e74cfd16 32529 const struct arm_legacy_option_table *fopt;
c19d1205 32530 struct arm_long_option_table *lopt;
b99bd4ef 32531
c19d1205 32532 switch (c)
b99bd4ef 32533 {
c19d1205
ZW
32534#ifdef OPTION_EB
32535 case OPTION_EB:
32536 target_big_endian = 1;
32537 break;
32538#endif
cc8a6dd0 32539
c19d1205
ZW
32540#ifdef OPTION_EL
32541 case OPTION_EL:
32542 target_big_endian = 0;
32543 break;
32544#endif
b99bd4ef 32545
845b51d6
PB
32546 case OPTION_FIX_V4BX:
32547 fix_v4bx = TRUE;
32548 break;
32549
18a20338
CL
32550#ifdef OBJ_ELF
32551 case OPTION_FDPIC:
32552 arm_fdpic = TRUE;
32553 break;
32554#endif /* OBJ_ELF */
32555
c19d1205
ZW
32556 case 'a':
32557 /* Listing option. Just ignore these, we don't support additional
32558 ones. */
32559 return 0;
b99bd4ef 32560
c19d1205
ZW
32561 default:
32562 for (opt = arm_opts; opt->option != NULL; opt++)
32563 {
32564 if (c == opt->option[0]
32565 && ((arg == NULL && opt->option[1] == 0)
32566 || streq (arg, opt->option + 1)))
32567 {
c19d1205 32568 /* If the option is deprecated, tell the user. */
278df34e 32569 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
32570 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32571 arg ? arg : "", _(opt->deprecated));
b99bd4ef 32572
c19d1205
ZW
32573 if (opt->var != NULL)
32574 *opt->var = opt->value;
cc8a6dd0 32575
c19d1205
ZW
32576 return 1;
32577 }
32578 }
b99bd4ef 32579
e74cfd16
PB
32580 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32581 {
32582 if (c == fopt->option[0]
32583 && ((arg == NULL && fopt->option[1] == 0)
32584 || streq (arg, fopt->option + 1)))
32585 {
e74cfd16 32586 /* If the option is deprecated, tell the user. */
278df34e 32587 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
32588 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32589 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
32590
32591 if (fopt->var != NULL)
32592 *fopt->var = &fopt->value;
32593
32594 return 1;
32595 }
32596 }
32597
c19d1205
ZW
32598 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32599 {
32600 /* These options are expected to have an argument. */
32601 if (c == lopt->option[0]
32602 && arg != NULL
32603 && strncmp (arg, lopt->option + 1,
32604 strlen (lopt->option + 1)) == 0)
32605 {
c19d1205 32606 /* If the option is deprecated, tell the user. */
278df34e 32607 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
32608 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32609 _(lopt->deprecated));
b99bd4ef 32610
c19d1205
ZW
32611 /* Call the sup-option parser. */
32612 return lopt->func (arg + strlen (lopt->option) - 1);
32613 }
32614 }
a737bd4d 32615
c19d1205
ZW
32616 return 0;
32617 }
a394c00f 32618
c19d1205
ZW
32619 return 1;
32620}
a394c00f 32621
c19d1205
ZW
32622void
32623md_show_usage (FILE * fp)
a394c00f 32624{
c19d1205
ZW
32625 struct arm_option_table *opt;
32626 struct arm_long_option_table *lopt;
a394c00f 32627
c19d1205 32628 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 32629
c19d1205
ZW
32630 for (opt = arm_opts; opt->option != NULL; opt++)
32631 if (opt->help != NULL)
32632 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 32633
c19d1205
ZW
32634 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32635 if (lopt->help != NULL)
32636 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 32637
c19d1205
ZW
32638#ifdef OPTION_EB
32639 fprintf (fp, _("\
32640 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
32641#endif
32642
c19d1205
ZW
32643#ifdef OPTION_EL
32644 fprintf (fp, _("\
32645 -EL assemble code for a little-endian cpu\n"));
a737bd4d 32646#endif
845b51d6
PB
32647
32648 fprintf (fp, _("\
32649 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
32650
32651#ifdef OBJ_ELF
32652 fprintf (fp, _("\
32653 --fdpic generate an FDPIC object file\n"));
32654#endif /* OBJ_ELF */
c19d1205 32655}
ee065d83 32656
ee065d83 32657#ifdef OBJ_ELF
0198d5e6 32658
62b3e311
PB
32659typedef struct
32660{
32661 int val;
32662 arm_feature_set flags;
32663} cpu_arch_ver_table;
32664
2c6b98ea
TP
32665/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32666 chronologically for architectures, with an exception for ARMv6-M and
32667 ARMv6S-M due to legacy reasons. No new architecture should have a
32668 special case. This allows for build attribute selection results to be
32669 stable when new architectures are added. */
62b3e311
PB
32670static const cpu_arch_ver_table cpu_arch_ver[] =
32671{
031254f2
AV
32672 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32673 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32674 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32675 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32676 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32677 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32678 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32679 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32680 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32681 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32682 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32683 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32684 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32685 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32686 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32687 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32688 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32689 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32690 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32691 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32692 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32693 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32694 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32695 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
32696
32697 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32698 always selected build attributes to match those of ARMv6-M
32699 (resp. ARMv6S-M). However, due to these architectures being a strict
32700 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32701 would be selected when fully respecting chronology of architectures.
32702 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32703 move them before ARMv7 architectures. */
031254f2
AV
32704 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32705 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32706
32707 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32708 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32709 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32710 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32711 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32712 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32713 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32714 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32715 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32716 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32717 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32718 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32719 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32720 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32721 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32722 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
aab2c27d
MM
32723 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32724 {-1, ARM_ARCH_NONE}
62b3e311
PB
32725};
32726
ee3c0378 32727/* Set an attribute if it has not already been set by the user. */
0198d5e6 32728
ee3c0378
AS
32729static void
32730aeabi_set_attribute_int (int tag, int value)
32731{
32732 if (tag < 1
32733 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32734 || !attributes_set_explicitly[tag])
32735 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32736}
32737
32738static void
32739aeabi_set_attribute_string (int tag, const char *value)
32740{
32741 if (tag < 1
32742 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32743 || !attributes_set_explicitly[tag])
32744 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32745}
32746
2c6b98ea
TP
32747/* Return whether features in the *NEEDED feature set are available via
32748 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 32749
2c6b98ea
TP
32750static bfd_boolean
32751have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32752 const arm_feature_set *needed)
32753{
32754 int i, nb_allowed_archs;
32755 arm_feature_set ext_fset;
32756 const struct arm_option_extension_value_table *opt;
32757
32758 ext_fset = arm_arch_none;
32759 for (opt = arm_extensions; opt->name != NULL; opt++)
32760 {
32761 /* Extension does not provide any feature we need. */
32762 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32763 continue;
32764
32765 nb_allowed_archs =
32766 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32767 for (i = 0; i < nb_allowed_archs; i++)
32768 {
32769 /* Empty entry. */
32770 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32771 break;
32772
32773 /* Extension is available, add it. */
32774 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32775 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32776 }
32777 }
32778
32779 /* Can we enable all features in *needed? */
32780 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32781}
32782
32783/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32784 a given architecture feature set *ARCH_EXT_FSET including extension feature
32785 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32786 - if true, check for an exact match of the architecture modulo extensions;
32787 - otherwise, select build attribute value of the first superset
32788 architecture released so that results remains stable when new architectures
32789 are added.
32790 For -march/-mcpu=all the build attribute value of the most featureful
32791 architecture is returned. Tag_CPU_arch_profile result is returned in
32792 PROFILE. */
0198d5e6 32793
2c6b98ea
TP
32794static int
32795get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32796 const arm_feature_set *ext_fset,
32797 char *profile, int exact_match)
32798{
32799 arm_feature_set arch_fset;
32800 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32801
32802 /* Select most featureful architecture with all its extensions if building
32803 for -march=all as the feature sets used to set build attributes. */
32804 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32805 {
32806 /* Force revisiting of decision for each new architecture. */
031254f2 32807 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
32808 *profile = 'A';
32809 return TAG_CPU_ARCH_V8;
32810 }
32811
32812 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32813
32814 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32815 {
32816 arm_feature_set known_arch_fset;
32817
32818 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32819 if (exact_match)
32820 {
32821 /* Base architecture match user-specified architecture and
32822 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32823 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32824 {
32825 p_ver_ret = p_ver;
32826 goto found;
32827 }
32828 /* Base architecture match user-specified architecture only
32829 (eg. ARMv6-M in the same case as above). Record it in case we
32830 find a match with above condition. */
32831 else if (p_ver_ret == NULL
32832 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32833 p_ver_ret = p_ver;
32834 }
32835 else
32836 {
32837
32838 /* Architecture has all features wanted. */
32839 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32840 {
32841 arm_feature_set added_fset;
32842
32843 /* Compute features added by this architecture over the one
32844 recorded in p_ver_ret. */
32845 if (p_ver_ret != NULL)
32846 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32847 p_ver_ret->flags);
32848 /* First architecture that match incl. with extensions, or the
32849 only difference in features over the recorded match is
32850 features that were optional and are now mandatory. */
32851 if (p_ver_ret == NULL
32852 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32853 {
32854 p_ver_ret = p_ver;
32855 goto found;
32856 }
32857 }
32858 else if (p_ver_ret == NULL)
32859 {
32860 arm_feature_set needed_ext_fset;
32861
32862 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32863
32864 /* Architecture has all features needed when using some
32865 extensions. Record it and continue searching in case there
32866 exist an architecture providing all needed features without
32867 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32868 OS extension). */
32869 if (have_ext_for_needed_feat_p (&known_arch_fset,
32870 &needed_ext_fset))
32871 p_ver_ret = p_ver;
32872 }
32873 }
32874 }
32875
32876 if (p_ver_ret == NULL)
32877 return -1;
32878
dc1e8a47 32879 found:
2c6b98ea
TP
32880 /* Tag_CPU_arch_profile. */
32881 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32882 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32883 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32884 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
32885 *profile = 'A';
32886 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
32887 *profile = 'R';
32888 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32889 *profile = 'M';
32890 else
32891 *profile = '\0';
32892 return p_ver_ret->val;
32893}
32894
ee065d83 32895/* Set the public EABI object attributes. */
0198d5e6 32896
c168ce07 32897static void
ee065d83
PB
32898aeabi_set_public_attributes (void)
32899{
b90d5ba0 32900 char profile = '\0';
2c6b98ea 32901 int arch = -1;
90ec0d68 32902 int virt_sec = 0;
bca38921 32903 int fp16_optional = 0;
2c6b98ea
TP
32904 int skip_exact_match = 0;
32905 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 32906
54bab281
TP
32907 /* Autodetection mode, choose the architecture based the instructions
32908 actually used. */
32909 if (no_cpu_selected ())
32910 {
32911 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 32912
54bab281
TP
32913 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32914 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 32915
54bab281
TP
32916 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32917 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 32918
54bab281 32919 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
32920 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32921 flags_ext = arm_arch_none;
32922 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32923 selected_ext = flags_ext;
54bab281
TP
32924 selected_cpu = flags;
32925 }
32926 /* Otherwise, choose the architecture based on the capabilities of the
32927 requested cpu. */
32928 else
4d354d8b
TP
32929 {
32930 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32931 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32932 flags_ext = selected_ext;
32933 flags = selected_cpu;
32934 }
32935 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 32936
ddd7f988 32937 /* Allow the user to override the reported architecture. */
4d354d8b 32938 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 32939 {
4d354d8b 32940 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 32941 flags_ext = arm_arch_none;
7a1d4c38 32942 }
2c6b98ea 32943 else
4d354d8b 32944 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
32945
32946 /* When this function is run again after relaxation has happened there is no
32947 way to determine whether an architecture or CPU was specified by the user:
32948 - selected_cpu is set above for relaxation to work;
32949 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32950 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32951 Therefore, if not in -march=all case we first try an exact match and fall
32952 back to autodetection. */
32953 if (!skip_exact_match)
32954 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32955 if (arch == -1)
32956 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32957 if (arch == -1)
32958 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 32959
ee065d83
PB
32960 /* Tag_CPU_name. */
32961 if (selected_cpu_name[0])
32962 {
91d6fa6a 32963 char *q;
ee065d83 32964
91d6fa6a
NC
32965 q = selected_cpu_name;
32966 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
32967 {
32968 int i;
5f4273c7 32969
91d6fa6a
NC
32970 q += 4;
32971 for (i = 0; q[i]; i++)
32972 q[i] = TOUPPER (q[i]);
ee065d83 32973 }
91d6fa6a 32974 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 32975 }
62f3b8c8 32976
ee065d83 32977 /* Tag_CPU_arch. */
ee3c0378 32978 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 32979
62b3e311 32980 /* Tag_CPU_arch_profile. */
69239280
MGD
32981 if (profile != '\0')
32982 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 32983
15afaa63 32984 /* Tag_DSP_extension. */
4d354d8b 32985 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 32986 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 32987
2c6b98ea 32988 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 32989 /* Tag_ARM_ISA_use. */
ee3c0378 32990 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 32991 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 32992 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 32993
ee065d83 32994 /* Tag_THUMB_ISA_use. */
ee3c0378 32995 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 32996 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
32997 {
32998 int thumb_isa_use;
32999
33000 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 33001 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
33002 thumb_isa_use = 3;
33003 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33004 thumb_isa_use = 2;
33005 else
33006 thumb_isa_use = 1;
33007 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33008 }
62f3b8c8 33009
ee065d83 33010 /* Tag_VFP_arch. */
a715796b
TG
33011 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33012 aeabi_set_attribute_int (Tag_VFP_arch,
33013 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33014 ? 7 : 8);
bca38921 33015 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
33016 aeabi_set_attribute_int (Tag_VFP_arch,
33017 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33018 ? 5 : 6);
33019 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
33020 {
33021 fp16_optional = 1;
33022 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33023 }
ada65aa3 33024 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
33025 {
33026 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33027 fp16_optional = 1;
33028 }
ee3c0378
AS
33029 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33030 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33031 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 33032 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 33033 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 33034
4547cb56
NC
33035 /* Tag_ABI_HardFP_use. */
33036 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33037 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33038 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33039
ee065d83 33040 /* Tag_WMMX_arch. */
ee3c0378
AS
33041 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33042 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33043 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33044 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 33045
ee3c0378 33046 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
33047 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33048 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33049 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
33050 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33051 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33052 {
33053 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33054 {
33055 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33056 }
33057 else
33058 {
33059 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33060 fp16_optional = 1;
33061 }
33062 }
fa94de6b 33063
a7ad558c
AV
33064 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33065 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33066 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33067 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33068
ee3c0378 33069 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 33070 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 33071 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 33072
69239280
MGD
33073 /* Tag_DIV_use.
33074
33075 We set Tag_DIV_use to two when integer divide instructions have been used
33076 in ARM state, or when Thumb integer divide instructions have been used,
33077 but we have no architecture profile set, nor have we any ARM instructions.
33078
4ed7ed8d
TP
33079 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33080 by the base architecture.
bca38921 33081
69239280 33082 For new architectures we will have to check these tests. */
031254f2 33083 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
33084 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33085 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
33086 aeabi_set_attribute_int (Tag_DIV_use, 0);
33087 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33088 || (profile == '\0'
33089 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33090 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 33091 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
33092
33093 /* Tag_MP_extension_use. */
33094 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33095 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
33096
33097 /* Tag Virtualization_use. */
33098 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
33099 virt_sec |= 1;
33100 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33101 virt_sec |= 2;
33102 if (virt_sec != 0)
33103 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
33104
33105 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33106 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
33107}
33108
c168ce07
TP
33109/* Post relaxation hook. Recompute ARM attributes now that relaxation is
33110 finished and free extension feature bits which will not be used anymore. */
0198d5e6 33111
c168ce07
TP
33112void
33113arm_md_post_relax (void)
33114{
33115 aeabi_set_public_attributes ();
4d354d8b
TP
33116 XDELETE (mcpu_ext_opt);
33117 mcpu_ext_opt = NULL;
33118 XDELETE (march_ext_opt);
33119 march_ext_opt = NULL;
c168ce07
TP
33120}
33121
104d59d1 33122/* Add the default contents for the .ARM.attributes section. */
0198d5e6 33123
ee065d83
PB
33124void
33125arm_md_end (void)
33126{
ee065d83
PB
33127 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33128 return;
33129
33130 aeabi_set_public_attributes ();
ee065d83 33131}
8463be01 33132#endif /* OBJ_ELF */
ee065d83 33133
ee065d83
PB
33134/* Parse a .cpu directive. */
33135
33136static void
33137s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33138{
e74cfd16 33139 const struct arm_cpu_option_table *opt;
ee065d83
PB
33140 char *name;
33141 char saved_char;
33142
33143 name = input_line_pointer;
5f4273c7 33144 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33145 input_line_pointer++;
33146 saved_char = *input_line_pointer;
33147 *input_line_pointer = 0;
33148
33149 /* Skip the first "all" entry. */
33150 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33151 if (streq (opt->name, name))
33152 {
4d354d8b
TP
33153 selected_arch = opt->value;
33154 selected_ext = opt->ext;
33155 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 33156 if (opt->canonical_name)
5f4273c7 33157 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
33158 else
33159 {
33160 int i;
33161 for (i = 0; opt->name[i]; i++)
33162 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 33163
ee065d83
PB
33164 selected_cpu_name[i] = 0;
33165 }
4d354d8b
TP
33166 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33167
ee065d83
PB
33168 *input_line_pointer = saved_char;
33169 demand_empty_rest_of_line ();
33170 return;
33171 }
33172 as_bad (_("unknown cpu `%s'"), name);
33173 *input_line_pointer = saved_char;
33174 ignore_rest_of_line ();
33175}
33176
ee065d83
PB
33177/* Parse a .arch directive. */
33178
33179static void
33180s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33181{
e74cfd16 33182 const struct arm_arch_option_table *opt;
ee065d83
PB
33183 char saved_char;
33184 char *name;
33185
33186 name = input_line_pointer;
5f4273c7 33187 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33188 input_line_pointer++;
33189 saved_char = *input_line_pointer;
33190 *input_line_pointer = 0;
33191
33192 /* Skip the first "all" entry. */
33193 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33194 if (streq (opt->name, name))
33195 {
4d354d8b 33196 selected_arch = opt->value;
0e7aaa72 33197 selected_ctx_ext_table = opt->ext_table;
4d354d8b
TP
33198 selected_ext = arm_arch_none;
33199 selected_cpu = selected_arch;
5f4273c7 33200 strcpy (selected_cpu_name, opt->name);
4d354d8b 33201 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33202 *input_line_pointer = saved_char;
33203 demand_empty_rest_of_line ();
33204 return;
33205 }
33206
33207 as_bad (_("unknown architecture `%s'\n"), name);
33208 *input_line_pointer = saved_char;
33209 ignore_rest_of_line ();
33210}
33211
7a1d4c38
PB
33212/* Parse a .object_arch directive. */
33213
33214static void
33215s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33216{
33217 const struct arm_arch_option_table *opt;
33218 char saved_char;
33219 char *name;
33220
33221 name = input_line_pointer;
5f4273c7 33222 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
33223 input_line_pointer++;
33224 saved_char = *input_line_pointer;
33225 *input_line_pointer = 0;
33226
33227 /* Skip the first "all" entry. */
33228 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33229 if (streq (opt->name, name))
33230 {
4d354d8b 33231 selected_object_arch = opt->value;
7a1d4c38
PB
33232 *input_line_pointer = saved_char;
33233 demand_empty_rest_of_line ();
33234 return;
33235 }
33236
33237 as_bad (_("unknown architecture `%s'\n"), name);
33238 *input_line_pointer = saved_char;
33239 ignore_rest_of_line ();
33240}
33241
69133863
MGD
33242/* Parse a .arch_extension directive. */
33243
33244static void
33245s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33246{
33247 const struct arm_option_extension_value_table *opt;
33248 char saved_char;
33249 char *name;
33250 int adding_value = 1;
33251
33252 name = input_line_pointer;
33253 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33254 input_line_pointer++;
33255 saved_char = *input_line_pointer;
33256 *input_line_pointer = 0;
33257
33258 if (strlen (name) >= 2
33259 && strncmp (name, "no", 2) == 0)
33260 {
33261 adding_value = 0;
33262 name += 2;
33263 }
33264
e20f9590
MI
33265 /* Check the context specific extension table */
33266 if (selected_ctx_ext_table)
33267 {
33268 const struct arm_ext_table * ext_opt;
33269 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33270 {
33271 if (streq (ext_opt->name, name))
33272 {
33273 if (adding_value)
33274 {
33275 if (ARM_FEATURE_ZERO (ext_opt->merge))
33276 /* TODO: Option not supported. When we remove the
33277 legacy table this case should error out. */
33278 continue;
33279 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33280 ext_opt->merge);
33281 }
33282 else
33283 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33284
33285 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33286 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33287 *input_line_pointer = saved_char;
33288 demand_empty_rest_of_line ();
33289 return;
33290 }
33291 }
33292 }
33293
69133863
MGD
33294 for (opt = arm_extensions; opt->name != NULL; opt++)
33295 if (streq (opt->name, name))
33296 {
d942732e
TP
33297 int i, nb_allowed_archs =
33298 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33299 for (i = 0; i < nb_allowed_archs; i++)
33300 {
33301 /* Empty entry. */
4d354d8b 33302 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 33303 continue;
4d354d8b 33304 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
33305 break;
33306 }
33307
33308 if (i == nb_allowed_archs)
69133863
MGD
33309 {
33310 as_bad (_("architectural extension `%s' is not allowed for the "
33311 "current base architecture"), name);
33312 break;
33313 }
33314
33315 if (adding_value)
4d354d8b 33316 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 33317 opt->merge_value);
69133863 33318 else
4d354d8b 33319 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 33320
4d354d8b
TP
33321 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33322 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
33323 *input_line_pointer = saved_char;
33324 demand_empty_rest_of_line ();
3d030cdb
TP
33325 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33326 on this return so that duplicate extensions (extensions with the
33327 same name as a previous extension in the list) are not considered
33328 for command-line parsing. */
69133863
MGD
33329 return;
33330 }
33331
33332 if (opt->name == NULL)
e673710a 33333 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
33334
33335 *input_line_pointer = saved_char;
33336 ignore_rest_of_line ();
33337}
33338
ee065d83
PB
33339/* Parse a .fpu directive. */
33340
33341static void
33342s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33343{
69133863 33344 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
33345 char saved_char;
33346 char *name;
33347
33348 name = input_line_pointer;
5f4273c7 33349 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33350 input_line_pointer++;
33351 saved_char = *input_line_pointer;
33352 *input_line_pointer = 0;
5f4273c7 33353
ee065d83
PB
33354 for (opt = arm_fpus; opt->name != NULL; opt++)
33355 if (streq (opt->name, name))
33356 {
4d354d8b 33357 selected_fpu = opt->value;
f4399880 33358 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
4d354d8b
TP
33359#ifndef CPU_DEFAULT
33360 if (no_cpu_selected ())
33361 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33362 else
33363#endif
33364 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33365 *input_line_pointer = saved_char;
33366 demand_empty_rest_of_line ();
33367 return;
33368 }
33369
33370 as_bad (_("unknown floating point format `%s'\n"), name);
33371 *input_line_pointer = saved_char;
33372 ignore_rest_of_line ();
33373}
ee065d83 33374
794ba86a 33375/* Copy symbol information. */
f31fef98 33376
794ba86a
DJ
33377void
33378arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33379{
33380 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33381}
e04befd0 33382
f31fef98 33383#ifdef OBJ_ELF
e04befd0
AS
33384/* Given a symbolic attribute NAME, return the proper integer value.
33385 Returns -1 if the attribute is not known. */
f31fef98 33386
e04befd0
AS
33387int
33388arm_convert_symbolic_attribute (const char *name)
33389{
f31fef98
NC
33390 static const struct
33391 {
33392 const char * name;
33393 const int tag;
33394 }
33395 attribute_table[] =
33396 {
33397 /* When you modify this table you should
33398 also modify the list in doc/c-arm.texi. */
e04befd0 33399#define T(tag) {#tag, tag}
f31fef98
NC
33400 T (Tag_CPU_raw_name),
33401 T (Tag_CPU_name),
33402 T (Tag_CPU_arch),
33403 T (Tag_CPU_arch_profile),
33404 T (Tag_ARM_ISA_use),
33405 T (Tag_THUMB_ISA_use),
75375b3e 33406 T (Tag_FP_arch),
f31fef98
NC
33407 T (Tag_VFP_arch),
33408 T (Tag_WMMX_arch),
33409 T (Tag_Advanced_SIMD_arch),
33410 T (Tag_PCS_config),
33411 T (Tag_ABI_PCS_R9_use),
33412 T (Tag_ABI_PCS_RW_data),
33413 T (Tag_ABI_PCS_RO_data),
33414 T (Tag_ABI_PCS_GOT_use),
33415 T (Tag_ABI_PCS_wchar_t),
33416 T (Tag_ABI_FP_rounding),
33417 T (Tag_ABI_FP_denormal),
33418 T (Tag_ABI_FP_exceptions),
33419 T (Tag_ABI_FP_user_exceptions),
33420 T (Tag_ABI_FP_number_model),
75375b3e 33421 T (Tag_ABI_align_needed),
f31fef98 33422 T (Tag_ABI_align8_needed),
75375b3e 33423 T (Tag_ABI_align_preserved),
f31fef98
NC
33424 T (Tag_ABI_align8_preserved),
33425 T (Tag_ABI_enum_size),
33426 T (Tag_ABI_HardFP_use),
33427 T (Tag_ABI_VFP_args),
33428 T (Tag_ABI_WMMX_args),
33429 T (Tag_ABI_optimization_goals),
33430 T (Tag_ABI_FP_optimization_goals),
33431 T (Tag_compatibility),
33432 T (Tag_CPU_unaligned_access),
75375b3e 33433 T (Tag_FP_HP_extension),
f31fef98
NC
33434 T (Tag_VFP_HP_extension),
33435 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
33436 T (Tag_MPextension_use),
33437 T (Tag_DIV_use),
f31fef98
NC
33438 T (Tag_nodefaults),
33439 T (Tag_also_compatible_with),
33440 T (Tag_conformance),
33441 T (Tag_T2EE_use),
33442 T (Tag_Virtualization_use),
15afaa63 33443 T (Tag_DSP_extension),
a7ad558c 33444 T (Tag_MVE_arch),
cd21e546 33445 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 33446#undef T
f31fef98 33447 };
e04befd0
AS
33448 unsigned int i;
33449
33450 if (name == NULL)
33451 return -1;
33452
f31fef98 33453 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 33454 if (streq (name, attribute_table[i].name))
e04befd0
AS
33455 return attribute_table[i].tag;
33456
33457 return -1;
33458}
267bf995 33459
93ef582d
NC
33460/* Apply sym value for relocations only in the case that they are for
33461 local symbols in the same segment as the fixup and you have the
33462 respective architectural feature for blx and simple switches. */
0198d5e6 33463
267bf995 33464int
93ef582d 33465arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
33466{
33467 if (fixP->fx_addsy
33468 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
33469 /* PR 17444: If the local symbol is in a different section then a reloc
33470 will always be generated for it, so applying the symbol value now
33471 will result in a double offset being stored in the relocation. */
33472 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 33473 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
33474 {
33475 switch (fixP->fx_r_type)
33476 {
33477 case BFD_RELOC_ARM_PCREL_BLX:
33478 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33479 if (ARM_IS_FUNC (fixP->fx_addsy))
33480 return 1;
33481 break;
33482
33483 case BFD_RELOC_ARM_PCREL_CALL:
33484 case BFD_RELOC_THUMB_PCREL_BLX:
33485 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 33486 return 1;
267bf995
RR
33487 break;
33488
33489 default:
33490 break;
33491 }
33492
33493 }
33494 return 0;
33495}
f31fef98 33496#endif /* OBJ_ELF */
This page took 6.612871 seconds and 4 git commands to generate.