PowerPC D-form prefixed loads and stores
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
82704155 2 Copyright (C) 1994-2019 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
18a20338
CL
78/* Whether --fdpic was given. */
79static int arm_fdpic;
80
8b1ad454
NC
81#endif /* OBJ_ELF */
82
4962c51a
MS
83/* Results from operand parsing worker functions. */
84
85typedef enum
86{
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90} parse_operand_result;
91
33a392fb
PB
92enum arm_float_abi
93{
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97};
98
c19d1205 99/* Types of processor to assemble for. */
b99bd4ef 100#ifndef CPU_DEFAULT
8a59fff3 101/* The code that was here used to select a default CPU depending on compiler
fa94de6b 102 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
b99bd4ef
NC
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
4d354d8b
TP
129/* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
e74cfd16 132static arm_feature_set cpu_variant;
4d354d8b
TP
133/* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
2e6976a8
DG
148/* Understand CodeComposer Studio assembly syntax. */
149bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
150
151/* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
4d354d8b
TP
154
155/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157static const arm_feature_set *legacy_cpu = NULL;
158static const arm_feature_set *legacy_fpu = NULL;
159
160/* CPU, extension and FPU feature bits selected by -mcpu. */
161static const arm_feature_set *mcpu_cpu_opt = NULL;
162static arm_feature_set *mcpu_ext_opt = NULL;
163static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165/* CPU, extension and FPU feature bits selected by -march. */
166static const arm_feature_set *march_cpu_opt = NULL;
167static arm_feature_set *march_ext_opt = NULL;
168static const arm_feature_set *march_fpu_opt = NULL;
169
170/* Feature bits selected by -mfpu. */
171static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
172
173/* Constants for known architecture features. */
174static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 175static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 176static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
177static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
179static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 181#ifdef OBJ_ELF
e74cfd16 182static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 183#endif
e74cfd16
PB
184static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186#ifdef CPU_DEFAULT
187static const arm_feature_set cpu_default = CPU_DEFAULT;
188#endif
189
823d2571 190static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 191static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
192static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 198static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
207/* Only for compatability of hint instructions. */
208static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
210static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 222#ifdef OBJ_ELF
e7d39ed3 223static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 224#endif
823d2571 225static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 226static const arm_feature_set arm_ext_m =
173205ca 227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
229static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 234static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 235static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
236static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
238static const arm_feature_set arm_ext_v8_1m_main =
239ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
240/* Instructions in ARMv8-M only found in M profile architectures. */
241static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
243static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
245/* Instructions shared between ARMv8-A and ARMv8-M. */
246static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 248#ifdef OBJ_ELF
15afaa63
TP
249/* DSP instructions Tag_DSP_extension refers to. */
250static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 252#endif
4d1464f2
MW
253static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
255/* FP16 instructions. */
256static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
258static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
260static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
262static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
264static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
266static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
e74cfd16
PB
268
269static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 270#ifdef OBJ_ELF
2c6b98ea 271static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 272#endif
f85d59c3 273static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
274static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
2d447fca 277static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 279static const arm_feature_set arm_cext_iwmmxt =
823d2571 280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 281static const arm_feature_set arm_cext_xscale =
823d2571 282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 283static const arm_feature_set arm_cext_maverick =
823d2571
TG
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 289static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 299static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 303static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c
AV
305static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
69c9e028 309#ifdef OBJ_ELF
823d2571
TG
310static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 314#endif
823d2571
TG
315static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 317static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 319static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 321static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 323static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 325static const arm_feature_set crc_ext_armv8 =
823d2571 326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 327static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
329static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 331
33a392fb 332static int mfloat_abi_opt = -1;
4d354d8b
TP
333/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335static arm_feature_set selected_arch = ARM_ARCH_NONE;
336/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338static arm_feature_set selected_ext = ARM_ARCH_NONE;
339/* Feature bits selected by the last -mcpu/-march or by the combination of the
340 last .cpu/.arch directive .arch_extension directives since that
341 directive. */
e74cfd16 342static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
343/* FPU feature bits selected by the last -mfpu or .fpu directive. */
344static arm_feature_set selected_fpu = FPU_NONE;
345/* Feature bits selected by the last .object_arch directive. */
346static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 347/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 348static char selected_cpu_name[20];
8d67f500 349
aacf0b33
KT
350extern FLONUM_TYPE generic_floating_point_number;
351
8d67f500
NC
352/* Return if no cpu was selected on command-line. */
353static bfd_boolean
354no_cpu_selected (void)
355{
823d2571 356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
357}
358
7cc69913 359#ifdef OBJ_ELF
deeaaff8
DJ
360# ifdef EABI_DEFAULT
361static int meabi_flags = EABI_DEFAULT;
362# else
d507cf36 363static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 364# endif
e1da3f5b 365
ee3c0378
AS
366static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
367
e1da3f5b 368bfd_boolean
5f4273c7 369arm_is_eabi (void)
e1da3f5b
PB
370{
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
372}
7cc69913 373#endif
b99bd4ef 374
b99bd4ef 375#ifdef OBJ_ELF
c19d1205 376/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
377symbolS * GOT_symbol;
378#endif
379
b99bd4ef
NC
380/* 0: assemble for ARM,
381 1: assemble for Thumb,
382 2: assemble for Thumb even though target CPU does not support thumb
383 instructions. */
384static int thumb_mode = 0;
8dc2430f
NC
385/* A value distinct from the possible values for thumb_mode that we
386 can use to record whether thumb_mode has been copied into the
387 tc_frag_data field of a frag. */
388#define MODE_RECORDED (1 << 4)
b99bd4ef 389
e07e6e58
NC
390/* Specifies the intrinsic IT insn behavior mode. */
391enum implicit_it_mode
392{
393 IMPLICIT_IT_MODE_NEVER = 0x00,
394 IMPLICIT_IT_MODE_ARM = 0x01,
395 IMPLICIT_IT_MODE_THUMB = 0x02,
396 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
397};
398static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
399
c19d1205
ZW
400/* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
402
403 - Immediate operands do not require a # prefix.
404 - Conditional affixes always appear at the end of the
405 instruction. (For backward compatibility, those instructions
406 that formerly had them in the middle, continue to accept them
407 there.)
408 - The IT instruction may appear, and if it does is validated
409 against subsequent conditional affixes. It does not generate
410 machine code.
411
412 Important differences from the old Thumb mode:
413
414 - Immediate operands do not require a # prefix.
415 - Most of the V6T2 instructions are only available in unified mode.
416 - The .N and .W suffixes are recognized and honored (it is an error
417 if they cannot be honored).
418 - All instructions set the flags if and only if they have an 's' affix.
419 - Conditional affixes may be used. They are validated against
420 preceding IT instructions. Unlike ARM mode, you cannot use a
421 conditional affix except in the scope of an IT instruction. */
422
423static bfd_boolean unified_syntax = FALSE;
b99bd4ef 424
bacebabc
RM
425/* An immediate operand can start with #, and ld*, st*, pld operands
426 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
427 before a [, which can appear as the first operand for pld.
428 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
429const char arm_symbol_chars[] = "#[]{}";
bacebabc 430
5287ad62
JB
431enum neon_el_type
432{
dcbf9037 433 NT_invtype,
5287ad62
JB
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
dcbf9037 439 NT_unsigned
5287ad62
JB
440};
441
442struct neon_type_el
443{
444 enum neon_el_type type;
445 unsigned size;
446};
447
448#define NEON_MAX_TYPE_ELS 4
449
450struct neon_type
451{
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
454};
455
5ee91343 456enum pred_instruction_type
e07e6e58 457{
5ee91343
AV
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
e07e6e58
NC
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 463 if inside, should be the last one. */
e07e6e58 464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 465 i.e. BKPT and NOP. */
5ee91343
AV
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 468 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 469 a predication code. */
35c228db 470 MVE_UNPREDICABLE_INSN /* MVE instruction that is non-predicable. */
e07e6e58
NC
471};
472
ad6cec43
MGD
473/* The maximum number of operands we need. */
474#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 475#define ARM_IT_MAX_RELOCS 3
ad6cec43 476
b99bd4ef
NC
477struct arm_it
478{
c19d1205 479 const char * error;
b99bd4ef 480 unsigned long instruction;
c19d1205
ZW
481 int size;
482 int size_req;
483 int cond;
037e8744
JB
484 /* "uncond_value" is set to the value in place of the conditional field in
485 unconditional versions of the instruction, or -1 if nothing is
486 appropriate. */
487 int uncond_value;
5287ad62 488 struct neon_type vectype;
88714cb8
DG
489 /* This does not indicate an actual NEON instruction, only that
490 the mnemonic accepts neon-style type suffixes. */
491 int is_neon;
0110f2b8
PB
492 /* Set to the opcode if the instruction needs relaxation.
493 Zero if the instruction is not relaxed. */
494 unsigned long relax;
b99bd4ef
NC
495 struct
496 {
497 bfd_reloc_code_real_type type;
c19d1205
ZW
498 expressionS exp;
499 int pc_rel;
e2b0ab59 500 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 501
5ee91343 502 enum pred_instruction_type pred_insn_type;
e07e6e58 503
c19d1205
ZW
504 struct
505 {
506 unsigned reg;
ca3f61f7 507 signed int imm;
dcbf9037 508 struct neon_type_el vectype;
ca3f61f7
NC
509 unsigned present : 1; /* Operand present. */
510 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
511 unsigned immisreg : 2; /* .imm field is a second register.
512 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
513 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
514 0) not scalar,
515 1) Neon scalar,
516 2) MVE scalar. */
5287ad62 517 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 518 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
519 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
520 instructions. This allows us to disambiguate ARM <-> vector insns. */
521 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 522 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 523 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 524 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 525 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
526 unsigned hasreloc : 1; /* Operand has relocation suffix. */
527 unsigned writeback : 1; /* Operand has trailing ! */
528 unsigned preind : 1; /* Preindexed address. */
529 unsigned postind : 1; /* Postindexed address. */
530 unsigned negative : 1; /* Index register was negated. */
531 unsigned shifted : 1; /* Shift applied to operation. */
532 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 533 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
534};
535
c19d1205 536static struct arm_it inst;
b99bd4ef
NC
537
538#define NUM_FLOAT_VALS 8
539
05d2d07e 540const char * fp_const[] =
b99bd4ef
NC
541{
542 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
543};
544
b99bd4ef
NC
545LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
546
547#define FAIL (-1)
548#define SUCCESS (0)
549
550#define SUFF_S 1
551#define SUFF_D 2
552#define SUFF_E 3
553#define SUFF_P 4
554
c19d1205
ZW
555#define CP_T_X 0x00008000
556#define CP_T_Y 0x00400000
b99bd4ef 557
c19d1205
ZW
558#define CONDS_BIT 0x00100000
559#define LOAD_BIT 0x00100000
b99bd4ef
NC
560
561#define DOUBLE_LOAD_FLAG 0x00000001
562
563struct asm_cond
564{
d3ce72d0 565 const char * template_name;
c921be7d 566 unsigned long value;
b99bd4ef
NC
567};
568
c19d1205 569#define COND_ALWAYS 0xE
b99bd4ef 570
b99bd4ef
NC
571struct asm_psr
572{
d3ce72d0 573 const char * template_name;
c921be7d 574 unsigned long field;
b99bd4ef
NC
575};
576
62b3e311
PB
577struct asm_barrier_opt
578{
e797f7e0
MGD
579 const char * template_name;
580 unsigned long value;
581 const arm_feature_set arch;
62b3e311
PB
582};
583
2d2255b5 584/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
585#define SPSR_BIT (1 << 22)
586
c19d1205
ZW
587/* The individual PSR flag bits. */
588#define PSR_c (1 << 16)
589#define PSR_x (1 << 17)
590#define PSR_s (1 << 18)
591#define PSR_f (1 << 19)
b99bd4ef 592
c19d1205 593struct reloc_entry
bfae80f2 594{
0198d5e6 595 const char * name;
c921be7d 596 bfd_reloc_code_real_type reloc;
bfae80f2
RE
597};
598
5287ad62 599enum vfp_reg_pos
bfae80f2 600{
5287ad62
JB
601 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
602 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
603};
604
605enum vfp_ldstm_type
606{
607 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
608};
609
dcbf9037
JB
610/* Bits for DEFINED field in neon_typed_alias. */
611#define NTA_HASTYPE 1
612#define NTA_HASINDEX 2
613
614struct neon_typed_alias
615{
c921be7d
NC
616 unsigned char defined;
617 unsigned char index;
618 struct neon_type_el eltype;
dcbf9037
JB
619};
620
c19d1205 621/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
622 architecture extensions' registers. Each entry should have an error message
623 in reg_expected_msgs below. */
c19d1205 624enum arm_reg_type
bfae80f2 625{
c19d1205
ZW
626 REG_TYPE_RN,
627 REG_TYPE_CP,
628 REG_TYPE_CN,
629 REG_TYPE_FN,
630 REG_TYPE_VFS,
631 REG_TYPE_VFD,
5287ad62 632 REG_TYPE_NQ,
037e8744 633 REG_TYPE_VFSD,
5287ad62 634 REG_TYPE_NDQ,
dec41383 635 REG_TYPE_NSD,
037e8744 636 REG_TYPE_NSDQ,
c19d1205
ZW
637 REG_TYPE_VFC,
638 REG_TYPE_MVF,
639 REG_TYPE_MVD,
640 REG_TYPE_MVFX,
641 REG_TYPE_MVDX,
642 REG_TYPE_MVAX,
5ee91343 643 REG_TYPE_MQ,
c19d1205
ZW
644 REG_TYPE_DSPSC,
645 REG_TYPE_MMXWR,
646 REG_TYPE_MMXWC,
647 REG_TYPE_MMXWCG,
648 REG_TYPE_XSCALE,
5ee91343 649 REG_TYPE_RNB,
1b883319 650 REG_TYPE_ZR
bfae80f2
RE
651};
652
dcbf9037
JB
653/* Structure for a hash table entry for a register.
654 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
655 information which states whether a vector type or index is specified (for a
656 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
657struct reg_entry
658{
c921be7d 659 const char * name;
90ec0d68 660 unsigned int number;
c921be7d
NC
661 unsigned char type;
662 unsigned char builtin;
663 struct neon_typed_alias * neon;
6c43fab6
RE
664};
665
c19d1205 666/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 667const char * const reg_expected_msgs[] =
c19d1205 668{
5aa75429
TP
669 [REG_TYPE_RN] = N_("ARM register expected"),
670 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
671 [REG_TYPE_CN] = N_("co-processor register expected"),
672 [REG_TYPE_FN] = N_("FPA register expected"),
673 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
674 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
675 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
676 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
677 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
678 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
679 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
680 " expected"),
681 [REG_TYPE_VFC] = N_("VFP system register expected"),
682 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
683 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
684 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
685 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
686 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
687 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
688 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
689 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
690 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
691 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 692 [REG_TYPE_MQ] = N_("MVE vector register expected"),
5aa75429 693 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
694};
695
c19d1205 696/* Some well known registers that we refer to directly elsewhere. */
bd340a04 697#define REG_R12 12
c19d1205
ZW
698#define REG_SP 13
699#define REG_LR 14
700#define REG_PC 15
404ff6b5 701
b99bd4ef
NC
702/* ARM instructions take 4bytes in the object file, Thumb instructions
703 take 2: */
c19d1205 704#define INSN_SIZE 4
b99bd4ef
NC
705
706struct asm_opcode
707{
708 /* Basic string to match. */
d3ce72d0 709 const char * template_name;
c19d1205
ZW
710
711 /* Parameters to instruction. */
5be8be5d 712 unsigned int operands[8];
c19d1205
ZW
713
714 /* Conditional tag - see opcode_lookup. */
715 unsigned int tag : 4;
b99bd4ef
NC
716
717 /* Basic instruction code. */
a302e574 718 unsigned int avalue;
b99bd4ef 719
c19d1205
ZW
720 /* Thumb-format instruction code. */
721 unsigned int tvalue;
b99bd4ef 722
90e4755a 723 /* Which architecture variant provides this instruction. */
c921be7d
NC
724 const arm_feature_set * avariant;
725 const arm_feature_set * tvariant;
c19d1205
ZW
726
727 /* Function to call to encode instruction in ARM format. */
728 void (* aencode) (void);
b99bd4ef 729
c19d1205
ZW
730 /* Function to call to encode instruction in Thumb format. */
731 void (* tencode) (void);
5ee91343
AV
732
733 /* Indicates whether this instruction may be vector predicated. */
734 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
735};
736
a737bd4d
NC
737/* Defines for various bits that we will want to toggle. */
738#define INST_IMMEDIATE 0x02000000
739#define OFFSET_REG 0x02000000
c19d1205 740#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
741#define SHIFT_BY_REG 0x00000010
742#define PRE_INDEX 0x01000000
743#define INDEX_UP 0x00800000
744#define WRITE_BACK 0x00200000
745#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 746#define CPSI_MMOD 0x00020000
90e4755a 747
a737bd4d
NC
748#define LITERAL_MASK 0xf000f000
749#define OPCODE_MASK 0xfe1fffff
750#define V4_STR_BIT 0x00000020
8335d6aa 751#define VLDR_VMOV_SAME 0x0040f000
90e4755a 752
efd81785
PB
753#define T2_SUBS_PC_LR 0xf3de8f00
754
a737bd4d 755#define DATA_OP_SHIFT 21
bada4342 756#define SBIT_SHIFT 20
90e4755a 757
ef8d22e6
PB
758#define T2_OPCODE_MASK 0xfe1fffff
759#define T2_DATA_OP_SHIFT 21
bada4342 760#define T2_SBIT_SHIFT 20
ef8d22e6 761
6530b175
NC
762#define A_COND_MASK 0xf0000000
763#define A_PUSH_POP_OP_MASK 0x0fff0000
764
765/* Opcodes for pushing/poping registers to/from the stack. */
766#define A1_OPCODE_PUSH 0x092d0000
767#define A2_OPCODE_PUSH 0x052d0004
768#define A2_OPCODE_POP 0x049d0004
769
a737bd4d
NC
770/* Codes to distinguish the arithmetic instructions. */
771#define OPCODE_AND 0
772#define OPCODE_EOR 1
773#define OPCODE_SUB 2
774#define OPCODE_RSB 3
775#define OPCODE_ADD 4
776#define OPCODE_ADC 5
777#define OPCODE_SBC 6
778#define OPCODE_RSC 7
779#define OPCODE_TST 8
780#define OPCODE_TEQ 9
781#define OPCODE_CMP 10
782#define OPCODE_CMN 11
783#define OPCODE_ORR 12
784#define OPCODE_MOV 13
785#define OPCODE_BIC 14
786#define OPCODE_MVN 15
90e4755a 787
ef8d22e6
PB
788#define T2_OPCODE_AND 0
789#define T2_OPCODE_BIC 1
790#define T2_OPCODE_ORR 2
791#define T2_OPCODE_ORN 3
792#define T2_OPCODE_EOR 4
793#define T2_OPCODE_ADD 8
794#define T2_OPCODE_ADC 10
795#define T2_OPCODE_SBC 11
796#define T2_OPCODE_SUB 13
797#define T2_OPCODE_RSB 14
798
a737bd4d
NC
799#define T_OPCODE_MUL 0x4340
800#define T_OPCODE_TST 0x4200
801#define T_OPCODE_CMN 0x42c0
802#define T_OPCODE_NEG 0x4240
803#define T_OPCODE_MVN 0x43c0
90e4755a 804
a737bd4d
NC
805#define T_OPCODE_ADD_R3 0x1800
806#define T_OPCODE_SUB_R3 0x1a00
807#define T_OPCODE_ADD_HI 0x4400
808#define T_OPCODE_ADD_ST 0xb000
809#define T_OPCODE_SUB_ST 0xb080
810#define T_OPCODE_ADD_SP 0xa800
811#define T_OPCODE_ADD_PC 0xa000
812#define T_OPCODE_ADD_I8 0x3000
813#define T_OPCODE_SUB_I8 0x3800
814#define T_OPCODE_ADD_I3 0x1c00
815#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 816
a737bd4d
NC
817#define T_OPCODE_ASR_R 0x4100
818#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
819#define T_OPCODE_LSR_R 0x40c0
820#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
821#define T_OPCODE_ASR_I 0x1000
822#define T_OPCODE_LSL_I 0x0000
823#define T_OPCODE_LSR_I 0x0800
b99bd4ef 824
a737bd4d
NC
825#define T_OPCODE_MOV_I8 0x2000
826#define T_OPCODE_CMP_I8 0x2800
827#define T_OPCODE_CMP_LR 0x4280
828#define T_OPCODE_MOV_HR 0x4600
829#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 830
a737bd4d
NC
831#define T_OPCODE_LDR_PC 0x4800
832#define T_OPCODE_LDR_SP 0x9800
833#define T_OPCODE_STR_SP 0x9000
834#define T_OPCODE_LDR_IW 0x6800
835#define T_OPCODE_STR_IW 0x6000
836#define T_OPCODE_LDR_IH 0x8800
837#define T_OPCODE_STR_IH 0x8000
838#define T_OPCODE_LDR_IB 0x7800
839#define T_OPCODE_STR_IB 0x7000
840#define T_OPCODE_LDR_RW 0x5800
841#define T_OPCODE_STR_RW 0x5000
842#define T_OPCODE_LDR_RH 0x5a00
843#define T_OPCODE_STR_RH 0x5200
844#define T_OPCODE_LDR_RB 0x5c00
845#define T_OPCODE_STR_RB 0x5400
c9b604bd 846
a737bd4d
NC
847#define T_OPCODE_PUSH 0xb400
848#define T_OPCODE_POP 0xbc00
b99bd4ef 849
2fc8bdac 850#define T_OPCODE_BRANCH 0xe000
b99bd4ef 851
a737bd4d 852#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 853#define THUMB_PP_PC_LR 0x0100
c19d1205 854#define THUMB_LOAD_BIT 0x0800
53365c0d 855#define THUMB2_LOAD_BIT 0x00100000
c19d1205 856
5ee91343 857#define BAD_SYNTAX _("syntax error")
c19d1205 858#define BAD_ARGS _("bad arguments to instruction")
fdfde340 859#define BAD_SP _("r13 not allowed here")
c19d1205 860#define BAD_PC _("r15 not allowed here")
a302e574
AV
861#define BAD_ODD _("Odd register not allowed here")
862#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
863#define BAD_COND _("instruction cannot be conditional")
864#define BAD_OVERLAP _("registers may not be the same")
865#define BAD_HIREG _("lo register required")
866#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 867#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 868#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 869#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
dfa9f0d5 870#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 871#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 872#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 873#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
874#define BAD_OUT_VPT \
875 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 876#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 877#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 878#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 879#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
880#define BAD_PC_ADDRESSING \
881 _("cannot use register index with PC-relative addressing")
882#define BAD_PC_WRITEBACK \
883 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
884#define BAD_RANGE _("branch out of range")
885#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 886#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 887#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
888#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
889 "block")
890#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
891 "block")
892#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
893 " operand")
894#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
895 " operand")
a302e574 896#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
897#define BAD_MVE_AUTO \
898 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
899 " use a valid -march or -mcpu option.")
900#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
901 "and source operands makes instruction UNPREDICTABLE")
35c228db 902#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 903#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 904
c921be7d
NC
905static struct hash_control * arm_ops_hsh;
906static struct hash_control * arm_cond_hsh;
5ee91343 907static struct hash_control * arm_vcond_hsh;
c921be7d
NC
908static struct hash_control * arm_shift_hsh;
909static struct hash_control * arm_psr_hsh;
910static struct hash_control * arm_v7m_psr_hsh;
911static struct hash_control * arm_reg_hsh;
912static struct hash_control * arm_reloc_hsh;
913static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 914
b99bd4ef
NC
915/* Stuff needed to resolve the label ambiguity
916 As:
917 ...
918 label: <insn>
919 may differ from:
920 ...
921 label:
5f4273c7 922 <insn> */
b99bd4ef
NC
923
924symbolS * last_label_seen;
b34976b6 925static int label_is_thumb_function_name = FALSE;
e07e6e58 926
3d0c9500
NC
927/* Literal pool structure. Held on a per-section
928 and per-sub-section basis. */
a737bd4d 929
c19d1205 930#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 931typedef struct literal_pool
b99bd4ef 932{
c921be7d
NC
933 expressionS literals [MAX_LITERAL_POOL_SIZE];
934 unsigned int next_free_entry;
935 unsigned int id;
936 symbolS * symbol;
937 segT section;
938 subsegT sub_section;
a8040cf2
NC
939#ifdef OBJ_ELF
940 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
941#endif
c921be7d 942 struct literal_pool * next;
8335d6aa 943 unsigned int alignment;
3d0c9500 944} literal_pool;
b99bd4ef 945
3d0c9500
NC
946/* Pointer to a linked list of literal pools. */
947literal_pool * list_of_pools = NULL;
e27ec89e 948
2e6976a8
DG
949typedef enum asmfunc_states
950{
951 OUTSIDE_ASMFUNC,
952 WAITING_ASMFUNC_NAME,
953 WAITING_ENDASMFUNC
954} asmfunc_states;
955
956static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
957
e07e6e58 958#ifdef OBJ_ELF
5ee91343 959# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 960#else
5ee91343 961static struct current_pred now_pred;
e07e6e58
NC
962#endif
963
964static inline int
5ee91343 965now_pred_compatible (int cond)
e07e6e58 966{
5ee91343 967 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
968}
969
970static inline int
971conditional_insn (void)
972{
973 return inst.cond != COND_ALWAYS;
974}
975
5ee91343 976static int in_pred_block (void);
e07e6e58 977
5ee91343 978static int handle_pred_state (void);
e07e6e58
NC
979
980static void force_automatic_it_block_close (void);
981
c921be7d
NC
982static void it_fsm_post_encode (void);
983
5ee91343 984#define set_pred_insn_type(type) \
e07e6e58
NC
985 do \
986 { \
5ee91343
AV
987 inst.pred_insn_type = type; \
988 if (handle_pred_state () == FAIL) \
477330fc 989 return; \
e07e6e58
NC
990 } \
991 while (0)
992
5ee91343 993#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
994 do \
995 { \
5ee91343
AV
996 inst.pred_insn_type = type; \
997 if (handle_pred_state () == FAIL) \
477330fc 998 return failret; \
c921be7d
NC
999 } \
1000 while(0)
1001
5ee91343 1002#define set_pred_insn_type_last() \
e07e6e58
NC
1003 do \
1004 { \
1005 if (inst.cond == COND_ALWAYS) \
5ee91343 1006 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1007 else \
5ee91343 1008 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1009 } \
1010 while (0)
1011
e39c1607
SD
1012/* Toggle value[pos]. */
1013#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1014
c19d1205 1015/* Pure syntax. */
b99bd4ef 1016
c19d1205
ZW
1017/* This array holds the chars that always start a comment. If the
1018 pre-processor is disabled, these aren't very useful. */
2e6976a8 1019char arm_comment_chars[] = "@";
3d0c9500 1020
c19d1205
ZW
1021/* This array holds the chars that only start a comment at the beginning of
1022 a line. If the line seems to have the form '# 123 filename'
1023 .line and .file directives will appear in the pre-processed output. */
1024/* Note that input_file.c hand checks for '#' at the beginning of the
1025 first line of the input file. This is because the compiler outputs
1026 #NO_APP at the beginning of its output. */
1027/* Also note that comments like this one will always work. */
1028const char line_comment_chars[] = "#";
3d0c9500 1029
2e6976a8 1030char arm_line_separator_chars[] = ";";
b99bd4ef 1031
c19d1205
ZW
1032/* Chars that can be used to separate mant
1033 from exp in floating point numbers. */
1034const char EXP_CHARS[] = "eE";
3d0c9500 1035
c19d1205
ZW
1036/* Chars that mean this number is a floating point constant. */
1037/* As in 0f12.456 */
1038/* or 0d1.2345e12 */
b99bd4ef 1039
c19d1205 1040const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 1041
c19d1205
ZW
1042/* Prefix characters that indicate the start of an immediate
1043 value. */
1044#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1045
c19d1205
ZW
1046/* Separator character handling. */
1047
1048#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1049
1050static inline int
1051skip_past_char (char ** str, char c)
1052{
8ab8155f
NC
1053 /* PR gas/14987: Allow for whitespace before the expected character. */
1054 skip_whitespace (*str);
427d0db6 1055
c19d1205
ZW
1056 if (**str == c)
1057 {
1058 (*str)++;
1059 return SUCCESS;
3d0c9500 1060 }
c19d1205
ZW
1061 else
1062 return FAIL;
1063}
c921be7d 1064
c19d1205 1065#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1066
c19d1205
ZW
1067/* Arithmetic expressions (possibly involving symbols). */
1068
1069/* Return TRUE if anything in the expression is a bignum. */
1070
0198d5e6 1071static bfd_boolean
c19d1205
ZW
1072walk_no_bignums (symbolS * sp)
1073{
1074 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1075 return TRUE;
c19d1205
ZW
1076
1077 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1078 {
c19d1205
ZW
1079 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1080 || (symbol_get_value_expression (sp)->X_op_symbol
1081 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1082 }
1083
0198d5e6 1084 return FALSE;
3d0c9500
NC
1085}
1086
0198d5e6 1087static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1088
1089/* Third argument to my_get_expression. */
1090#define GE_NO_PREFIX 0
1091#define GE_IMM_PREFIX 1
1092#define GE_OPT_PREFIX 2
5287ad62
JB
1093/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1094 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1095#define GE_OPT_PREFIX_BIG 3
a737bd4d 1096
b99bd4ef 1097static int
c19d1205 1098my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1099{
c19d1205 1100 char * save_in;
b99bd4ef 1101
c19d1205
ZW
1102 /* In unified syntax, all prefixes are optional. */
1103 if (unified_syntax)
5287ad62 1104 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1105 : GE_OPT_PREFIX;
b99bd4ef 1106
c19d1205 1107 switch (prefix_mode)
b99bd4ef 1108 {
c19d1205
ZW
1109 case GE_NO_PREFIX: break;
1110 case GE_IMM_PREFIX:
1111 if (!is_immediate_prefix (**str))
1112 {
1113 inst.error = _("immediate expression requires a # prefix");
1114 return FAIL;
1115 }
1116 (*str)++;
1117 break;
1118 case GE_OPT_PREFIX:
5287ad62 1119 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1120 if (is_immediate_prefix (**str))
1121 (*str)++;
1122 break;
0198d5e6
TC
1123 default:
1124 abort ();
c19d1205 1125 }
b99bd4ef 1126
c19d1205 1127 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1128
c19d1205
ZW
1129 save_in = input_line_pointer;
1130 input_line_pointer = *str;
0198d5e6 1131 in_my_get_expression = TRUE;
2ac93be7 1132 expression (ep);
0198d5e6 1133 in_my_get_expression = FALSE;
c19d1205 1134
f86adc07 1135 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1136 {
f86adc07 1137 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1138 *str = input_line_pointer;
1139 input_line_pointer = save_in;
1140 if (inst.error == NULL)
f86adc07
NS
1141 inst.error = (ep->X_op == O_absent
1142 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1143 return 1;
1144 }
b99bd4ef 1145
c19d1205
ZW
1146 /* Get rid of any bignums now, so that we don't generate an error for which
1147 we can't establish a line number later on. Big numbers are never valid
1148 in instructions, which is where this routine is always called. */
5287ad62
JB
1149 if (prefix_mode != GE_OPT_PREFIX_BIG
1150 && (ep->X_op == O_big
477330fc 1151 || (ep->X_add_symbol
5287ad62 1152 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1153 || (ep->X_op_symbol
5287ad62 1154 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1155 {
1156 inst.error = _("invalid constant");
1157 *str = input_line_pointer;
1158 input_line_pointer = save_in;
1159 return 1;
1160 }
b99bd4ef 1161
c19d1205
ZW
1162 *str = input_line_pointer;
1163 input_line_pointer = save_in;
0198d5e6 1164 return SUCCESS;
b99bd4ef
NC
1165}
1166
c19d1205
ZW
1167/* Turn a string in input_line_pointer into a floating point constant
1168 of type TYPE, and store the appropriate bytes in *LITP. The number
1169 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1170 returned, or NULL on OK.
b99bd4ef 1171
c19d1205
ZW
1172 Note that fp constants aren't represent in the normal way on the ARM.
1173 In big endian mode, things are as expected. However, in little endian
1174 mode fp constants are big-endian word-wise, and little-endian byte-wise
1175 within the words. For example, (double) 1.1 in big endian mode is
1176 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1177 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1178
c19d1205 1179 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1180
6d4af3c2 1181const char *
c19d1205
ZW
1182md_atof (int type, char * litP, int * sizeP)
1183{
1184 int prec;
1185 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1186 char *t;
1187 int i;
b99bd4ef 1188
c19d1205
ZW
1189 switch (type)
1190 {
1191 case 'f':
1192 case 'F':
1193 case 's':
1194 case 'S':
1195 prec = 2;
1196 break;
b99bd4ef 1197
c19d1205
ZW
1198 case 'd':
1199 case 'D':
1200 case 'r':
1201 case 'R':
1202 prec = 4;
1203 break;
b99bd4ef 1204
c19d1205
ZW
1205 case 'x':
1206 case 'X':
499ac353 1207 prec = 5;
c19d1205 1208 break;
b99bd4ef 1209
c19d1205
ZW
1210 case 'p':
1211 case 'P':
499ac353 1212 prec = 5;
c19d1205 1213 break;
a737bd4d 1214
c19d1205
ZW
1215 default:
1216 *sizeP = 0;
499ac353 1217 return _("Unrecognized or unsupported floating point constant");
c19d1205 1218 }
b99bd4ef 1219
c19d1205
ZW
1220 t = atof_ieee (input_line_pointer, type, words);
1221 if (t)
1222 input_line_pointer = t;
499ac353 1223 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1224
c19d1205
ZW
1225 if (target_big_endian)
1226 {
1227 for (i = 0; i < prec; i++)
1228 {
499ac353
NC
1229 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1230 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1231 }
1232 }
1233 else
1234 {
e74cfd16 1235 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1236 for (i = prec - 1; i >= 0; i--)
1237 {
499ac353
NC
1238 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1239 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1240 }
1241 else
1242 /* For a 4 byte float the order of elements in `words' is 1 0.
1243 For an 8 byte float the order is 1 0 3 2. */
1244 for (i = 0; i < prec; i += 2)
1245 {
499ac353
NC
1246 md_number_to_chars (litP, (valueT) words[i + 1],
1247 sizeof (LITTLENUM_TYPE));
1248 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1249 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1250 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1251 }
1252 }
b99bd4ef 1253
499ac353 1254 return NULL;
c19d1205 1255}
b99bd4ef 1256
c19d1205
ZW
1257/* We handle all bad expressions here, so that we can report the faulty
1258 instruction in the error message. */
0198d5e6 1259
c19d1205 1260void
91d6fa6a 1261md_operand (expressionS * exp)
c19d1205
ZW
1262{
1263 if (in_my_get_expression)
91d6fa6a 1264 exp->X_op = O_illegal;
b99bd4ef
NC
1265}
1266
c19d1205 1267/* Immediate values. */
b99bd4ef 1268
0198d5e6 1269#ifdef OBJ_ELF
c19d1205
ZW
1270/* Generic immediate-value read function for use in directives.
1271 Accepts anything that 'expression' can fold to a constant.
1272 *val receives the number. */
0198d5e6 1273
c19d1205
ZW
1274static int
1275immediate_for_directive (int *val)
b99bd4ef 1276{
c19d1205
ZW
1277 expressionS exp;
1278 exp.X_op = O_illegal;
b99bd4ef 1279
c19d1205
ZW
1280 if (is_immediate_prefix (*input_line_pointer))
1281 {
1282 input_line_pointer++;
1283 expression (&exp);
1284 }
b99bd4ef 1285
c19d1205
ZW
1286 if (exp.X_op != O_constant)
1287 {
1288 as_bad (_("expected #constant"));
1289 ignore_rest_of_line ();
1290 return FAIL;
1291 }
1292 *val = exp.X_add_number;
1293 return SUCCESS;
b99bd4ef 1294}
c19d1205 1295#endif
b99bd4ef 1296
c19d1205 1297/* Register parsing. */
b99bd4ef 1298
c19d1205
ZW
1299/* Generic register parser. CCP points to what should be the
1300 beginning of a register name. If it is indeed a valid register
1301 name, advance CCP over it and return the reg_entry structure;
1302 otherwise return NULL. Does not issue diagnostics. */
1303
1304static struct reg_entry *
1305arm_reg_parse_multi (char **ccp)
b99bd4ef 1306{
c19d1205
ZW
1307 char *start = *ccp;
1308 char *p;
1309 struct reg_entry *reg;
b99bd4ef 1310
477330fc
RM
1311 skip_whitespace (start);
1312
c19d1205
ZW
1313#ifdef REGISTER_PREFIX
1314 if (*start != REGISTER_PREFIX)
01cfc07f 1315 return NULL;
c19d1205
ZW
1316 start++;
1317#endif
1318#ifdef OPTIONAL_REGISTER_PREFIX
1319 if (*start == OPTIONAL_REGISTER_PREFIX)
1320 start++;
1321#endif
b99bd4ef 1322
c19d1205
ZW
1323 p = start;
1324 if (!ISALPHA (*p) || !is_name_beginner (*p))
1325 return NULL;
b99bd4ef 1326
c19d1205
ZW
1327 do
1328 p++;
1329 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1330
1331 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1332
1333 if (!reg)
1334 return NULL;
1335
1336 *ccp = p;
1337 return reg;
b99bd4ef
NC
1338}
1339
1340static int
dcbf9037 1341arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1342 enum arm_reg_type type)
b99bd4ef 1343{
c19d1205
ZW
1344 /* Alternative syntaxes are accepted for a few register classes. */
1345 switch (type)
1346 {
1347 case REG_TYPE_MVF:
1348 case REG_TYPE_MVD:
1349 case REG_TYPE_MVFX:
1350 case REG_TYPE_MVDX:
1351 /* Generic coprocessor register names are allowed for these. */
79134647 1352 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1353 return reg->number;
1354 break;
69b97547 1355
c19d1205
ZW
1356 case REG_TYPE_CP:
1357 /* For backward compatibility, a bare number is valid here. */
1358 {
1359 unsigned long processor = strtoul (start, ccp, 10);
1360 if (*ccp != start && processor <= 15)
1361 return processor;
1362 }
1a0670f3 1363 /* Fall through. */
6057a28f 1364
c19d1205
ZW
1365 case REG_TYPE_MMXWC:
1366 /* WC includes WCG. ??? I'm not sure this is true for all
1367 instructions that take WC registers. */
79134647 1368 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1369 return reg->number;
6057a28f 1370 break;
c19d1205 1371
6057a28f 1372 default:
c19d1205 1373 break;
6057a28f
NC
1374 }
1375
dcbf9037
JB
1376 return FAIL;
1377}
1378
1379/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1380 return value is the register number or FAIL. */
1381
1382static int
1383arm_reg_parse (char **ccp, enum arm_reg_type type)
1384{
1385 char *start = *ccp;
1386 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1387 int ret;
1388
1389 /* Do not allow a scalar (reg+index) to parse as a register. */
1390 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1391 return FAIL;
1392
1393 if (reg && reg->type == type)
1394 return reg->number;
1395
1396 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1397 return ret;
1398
c19d1205
ZW
1399 *ccp = start;
1400 return FAIL;
1401}
69b97547 1402
dcbf9037
JB
1403/* Parse a Neon type specifier. *STR should point at the leading '.'
1404 character. Does no verification at this stage that the type fits the opcode
1405 properly. E.g.,
1406
1407 .i32.i32.s16
1408 .s32.f32
1409 .u16
1410
1411 Can all be legally parsed by this function.
1412
1413 Fills in neon_type struct pointer with parsed information, and updates STR
1414 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1415 type, FAIL if not. */
1416
1417static int
1418parse_neon_type (struct neon_type *type, char **str)
1419{
1420 char *ptr = *str;
1421
1422 if (type)
1423 type->elems = 0;
1424
1425 while (type->elems < NEON_MAX_TYPE_ELS)
1426 {
1427 enum neon_el_type thistype = NT_untyped;
1428 unsigned thissize = -1u;
1429
1430 if (*ptr != '.')
1431 break;
1432
1433 ptr++;
1434
1435 /* Just a size without an explicit type. */
1436 if (ISDIGIT (*ptr))
1437 goto parsesize;
1438
1439 switch (TOLOWER (*ptr))
1440 {
1441 case 'i': thistype = NT_integer; break;
1442 case 'f': thistype = NT_float; break;
1443 case 'p': thistype = NT_poly; break;
1444 case 's': thistype = NT_signed; break;
1445 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1446 case 'd':
1447 thistype = NT_float;
1448 thissize = 64;
1449 ptr++;
1450 goto done;
dcbf9037
JB
1451 default:
1452 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1453 return FAIL;
1454 }
1455
1456 ptr++;
1457
1458 /* .f is an abbreviation for .f32. */
1459 if (thistype == NT_float && !ISDIGIT (*ptr))
1460 thissize = 32;
1461 else
1462 {
1463 parsesize:
1464 thissize = strtoul (ptr, &ptr, 10);
1465
1466 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1467 && thissize != 64)
1468 {
1469 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1470 return FAIL;
1471 }
1472 }
1473
037e8744 1474 done:
dcbf9037 1475 if (type)
477330fc
RM
1476 {
1477 type->el[type->elems].type = thistype;
dcbf9037
JB
1478 type->el[type->elems].size = thissize;
1479 type->elems++;
1480 }
1481 }
1482
1483 /* Empty/missing type is not a successful parse. */
1484 if (type->elems == 0)
1485 return FAIL;
1486
1487 *str = ptr;
1488
1489 return SUCCESS;
1490}
1491
1492/* Errors may be set multiple times during parsing or bit encoding
1493 (particularly in the Neon bits), but usually the earliest error which is set
1494 will be the most meaningful. Avoid overwriting it with later (cascading)
1495 errors by calling this function. */
1496
1497static void
1498first_error (const char *err)
1499{
1500 if (!inst.error)
1501 inst.error = err;
1502}
1503
1504/* Parse a single type, e.g. ".s32", leading period included. */
1505static int
1506parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1507{
1508 char *str = *ccp;
1509 struct neon_type optype;
1510
1511 if (*str == '.')
1512 {
1513 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1514 {
1515 if (optype.elems == 1)
1516 *vectype = optype.el[0];
1517 else
1518 {
1519 first_error (_("only one type should be specified for operand"));
1520 return FAIL;
1521 }
1522 }
dcbf9037 1523 else
477330fc
RM
1524 {
1525 first_error (_("vector type expected"));
1526 return FAIL;
1527 }
dcbf9037
JB
1528 }
1529 else
1530 return FAIL;
5f4273c7 1531
dcbf9037 1532 *ccp = str;
5f4273c7 1533
dcbf9037
JB
1534 return SUCCESS;
1535}
1536
1537/* Special meanings for indices (which have a range of 0-7), which will fit into
1538 a 4-bit integer. */
1539
1540#define NEON_ALL_LANES 15
1541#define NEON_INTERLEAVE_LANES 14
1542
5ee91343
AV
1543/* Record a use of the given feature. */
1544static void
1545record_feature_use (const arm_feature_set *feature)
1546{
1547 if (thumb_mode)
1548 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1549 else
1550 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1551}
1552
1553/* If the given feature available in the selected CPU, mark it as used.
1554 Returns TRUE iff feature is available. */
1555static bfd_boolean
1556mark_feature_used (const arm_feature_set *feature)
1557{
886e1c73
AV
1558
1559 /* Do not support the use of MVE only instructions when in auto-detection or
1560 -march=all. */
1561 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1562 && ARM_CPU_IS_ANY (cpu_variant))
1563 {
1564 first_error (BAD_MVE_AUTO);
1565 return FALSE;
1566 }
5ee91343
AV
1567 /* Ensure the option is valid on the current architecture. */
1568 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1569 return FALSE;
1570
1571 /* Add the appropriate architecture feature for the barrier option used.
1572 */
1573 record_feature_use (feature);
1574
1575 return TRUE;
1576}
1577
dcbf9037
JB
1578/* Parse either a register or a scalar, with an optional type. Return the
1579 register number, and optionally fill in the actual type of the register
1580 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1581 type/index information in *TYPEINFO. */
1582
1583static int
1584parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1585 enum arm_reg_type *rtype,
1586 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1587{
1588 char *str = *ccp;
1589 struct reg_entry *reg = arm_reg_parse_multi (&str);
1590 struct neon_typed_alias atype;
1591 struct neon_type_el parsetype;
1592
1593 atype.defined = 0;
1594 atype.index = -1;
1595 atype.eltype.type = NT_invtype;
1596 atype.eltype.size = -1;
1597
1598 /* Try alternate syntax for some types of register. Note these are mutually
1599 exclusive with the Neon syntax extensions. */
1600 if (reg == NULL)
1601 {
1602 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1603 if (altreg != FAIL)
477330fc 1604 *ccp = str;
dcbf9037 1605 if (typeinfo)
477330fc 1606 *typeinfo = atype;
dcbf9037
JB
1607 return altreg;
1608 }
1609
037e8744
JB
1610 /* Undo polymorphism when a set of register types may be accepted. */
1611 if ((type == REG_TYPE_NDQ
1612 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1613 || (type == REG_TYPE_VFSD
477330fc 1614 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1615 || (type == REG_TYPE_NSDQ
477330fc
RM
1616 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1617 || reg->type == REG_TYPE_NQ))
dec41383
JW
1618 || (type == REG_TYPE_NSD
1619 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1620 || (type == REG_TYPE_MMXWC
1621 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1622 type = (enum arm_reg_type) reg->type;
dcbf9037 1623
5ee91343
AV
1624 if (type == REG_TYPE_MQ)
1625 {
1626 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1627 return FAIL;
1628
1629 if (!reg || reg->type != REG_TYPE_NQ)
1630 return FAIL;
1631
1632 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1633 {
1634 first_error (_("expected MVE register [q0..q7]"));
1635 return FAIL;
1636 }
1637 type = REG_TYPE_NQ;
1638 }
1639 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1640 && (type == REG_TYPE_NQ))
1641 return FAIL;
1642
1643
dcbf9037
JB
1644 if (type != reg->type)
1645 return FAIL;
1646
1647 if (reg->neon)
1648 atype = *reg->neon;
5f4273c7 1649
dcbf9037
JB
1650 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1651 {
1652 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1653 {
1654 first_error (_("can't redefine type for operand"));
1655 return FAIL;
1656 }
dcbf9037
JB
1657 atype.defined |= NTA_HASTYPE;
1658 atype.eltype = parsetype;
1659 }
5f4273c7 1660
dcbf9037
JB
1661 if (skip_past_char (&str, '[') == SUCCESS)
1662 {
dec41383
JW
1663 if (type != REG_TYPE_VFD
1664 && !(type == REG_TYPE_VFS
57785aa2
AV
1665 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1666 && !(type == REG_TYPE_NQ
1667 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1668 {
57785aa2
AV
1669 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1670 first_error (_("only D and Q registers may be indexed"));
1671 else
1672 first_error (_("only D registers may be indexed"));
477330fc
RM
1673 return FAIL;
1674 }
5f4273c7 1675
dcbf9037 1676 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1677 {
1678 first_error (_("can't change index for operand"));
1679 return FAIL;
1680 }
dcbf9037
JB
1681
1682 atype.defined |= NTA_HASINDEX;
1683
1684 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1685 atype.index = NEON_ALL_LANES;
dcbf9037 1686 else
477330fc
RM
1687 {
1688 expressionS exp;
dcbf9037 1689
477330fc 1690 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1691
477330fc
RM
1692 if (exp.X_op != O_constant)
1693 {
1694 first_error (_("constant expression required"));
1695 return FAIL;
1696 }
dcbf9037 1697
477330fc
RM
1698 if (skip_past_char (&str, ']') == FAIL)
1699 return FAIL;
dcbf9037 1700
477330fc
RM
1701 atype.index = exp.X_add_number;
1702 }
dcbf9037 1703 }
5f4273c7 1704
dcbf9037
JB
1705 if (typeinfo)
1706 *typeinfo = atype;
5f4273c7 1707
dcbf9037
JB
1708 if (rtype)
1709 *rtype = type;
5f4273c7 1710
dcbf9037 1711 *ccp = str;
5f4273c7 1712
dcbf9037
JB
1713 return reg->number;
1714}
1715
efd6b359 1716/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1717 - If RTYPE is non-zero, return the (possibly restricted) type of the
1718 register (e.g. Neon double or quad reg when either has been requested).
1719 - If this is a Neon vector type with additional type information, fill
1720 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1721 This function will fault on encountering a scalar. */
dcbf9037
JB
1722
1723static int
1724arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1725 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1726{
1727 struct neon_typed_alias atype;
1728 char *str = *ccp;
1729 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1730
1731 if (reg == FAIL)
1732 return FAIL;
1733
0855e32b
NS
1734 /* Do not allow regname(... to parse as a register. */
1735 if (*str == '(')
1736 return FAIL;
1737
dcbf9037
JB
1738 /* Do not allow a scalar (reg+index) to parse as a register. */
1739 if ((atype.defined & NTA_HASINDEX) != 0)
1740 {
1741 first_error (_("register operand expected, but got scalar"));
1742 return FAIL;
1743 }
1744
1745 if (vectype)
1746 *vectype = atype.eltype;
1747
1748 *ccp = str;
1749
1750 return reg;
1751}
1752
1753#define NEON_SCALAR_REG(X) ((X) >> 4)
1754#define NEON_SCALAR_INDEX(X) ((X) & 15)
1755
5287ad62
JB
1756/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1757 have enough information to be able to do a good job bounds-checking. So, we
1758 just do easy checks here, and do further checks later. */
1759
1760static int
57785aa2
AV
1761parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1762 arm_reg_type reg_type)
5287ad62 1763{
dcbf9037 1764 int reg;
5287ad62 1765 char *str = *ccp;
dcbf9037 1766 struct neon_typed_alias atype;
57785aa2 1767 unsigned reg_size;
5f4273c7 1768
dec41383 1769 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1770
57785aa2
AV
1771 switch (reg_type)
1772 {
1773 case REG_TYPE_VFS:
1774 reg_size = 32;
1775 break;
1776 case REG_TYPE_VFD:
1777 reg_size = 64;
1778 break;
1779 case REG_TYPE_MQ:
1780 reg_size = 128;
1781 break;
1782 default:
1783 gas_assert (0);
1784 return FAIL;
1785 }
1786
dcbf9037 1787 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1788 return FAIL;
5f4273c7 1789
57785aa2 1790 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1791 {
dcbf9037 1792 first_error (_("scalar must have an index"));
5287ad62
JB
1793 return FAIL;
1794 }
57785aa2 1795 else if (atype.index >= reg_size / elsize)
5287ad62 1796 {
dcbf9037 1797 first_error (_("scalar index out of range"));
5287ad62
JB
1798 return FAIL;
1799 }
5f4273c7 1800
dcbf9037
JB
1801 if (type)
1802 *type = atype.eltype;
5f4273c7 1803
5287ad62 1804 *ccp = str;
5f4273c7 1805
dcbf9037 1806 return reg * 16 + atype.index;
5287ad62
JB
1807}
1808
4b5a202f
AV
1809/* Types of registers in a list. */
1810
1811enum reg_list_els
1812{
1813 REGLIST_RN,
1814 REGLIST_CLRM,
1815 REGLIST_VFP_S,
efd6b359 1816 REGLIST_VFP_S_VPR,
4b5a202f 1817 REGLIST_VFP_D,
efd6b359 1818 REGLIST_VFP_D_VPR,
4b5a202f
AV
1819 REGLIST_NEON_D
1820};
1821
c19d1205 1822/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1823
c19d1205 1824static long
4b5a202f 1825parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1826{
4b5a202f
AV
1827 char *str = *strp;
1828 long range = 0;
1829 int another_range;
1830
1831 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1832
c19d1205
ZW
1833 /* We come back here if we get ranges concatenated by '+' or '|'. */
1834 do
6057a28f 1835 {
477330fc
RM
1836 skip_whitespace (str);
1837
c19d1205 1838 another_range = 0;
a737bd4d 1839
c19d1205
ZW
1840 if (*str == '{')
1841 {
1842 int in_range = 0;
1843 int cur_reg = -1;
a737bd4d 1844
c19d1205
ZW
1845 str++;
1846 do
1847 {
1848 int reg;
4b5a202f
AV
1849 const char apsr_str[] = "apsr";
1850 int apsr_str_len = strlen (apsr_str);
6057a28f 1851
4b5a202f
AV
1852 reg = arm_reg_parse (&str, REGLIST_RN);
1853 if (etype == REGLIST_CLRM)
c19d1205 1854 {
4b5a202f
AV
1855 if (reg == REG_SP || reg == REG_PC)
1856 reg = FAIL;
1857 else if (reg == FAIL
1858 && !strncasecmp (str, apsr_str, apsr_str_len)
1859 && !ISALPHA (*(str + apsr_str_len)))
1860 {
1861 reg = 15;
1862 str += apsr_str_len;
1863 }
1864
1865 if (reg == FAIL)
1866 {
1867 first_error (_("r0-r12, lr or APSR expected"));
1868 return FAIL;
1869 }
1870 }
1871 else /* etype == REGLIST_RN. */
1872 {
1873 if (reg == FAIL)
1874 {
1875 first_error (_(reg_expected_msgs[REGLIST_RN]));
1876 return FAIL;
1877 }
c19d1205 1878 }
a737bd4d 1879
c19d1205
ZW
1880 if (in_range)
1881 {
1882 int i;
a737bd4d 1883
c19d1205
ZW
1884 if (reg <= cur_reg)
1885 {
dcbf9037 1886 first_error (_("bad range in register list"));
c19d1205
ZW
1887 return FAIL;
1888 }
40a18ebd 1889
c19d1205
ZW
1890 for (i = cur_reg + 1; i < reg; i++)
1891 {
1892 if (range & (1 << i))
1893 as_tsktsk
1894 (_("Warning: duplicated register (r%d) in register list"),
1895 i);
1896 else
1897 range |= 1 << i;
1898 }
1899 in_range = 0;
1900 }
a737bd4d 1901
c19d1205
ZW
1902 if (range & (1 << reg))
1903 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1904 reg);
1905 else if (reg <= cur_reg)
1906 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1907
c19d1205
ZW
1908 range |= 1 << reg;
1909 cur_reg = reg;
1910 }
1911 while (skip_past_comma (&str) != FAIL
1912 || (in_range = 1, *str++ == '-'));
1913 str--;
a737bd4d 1914
d996d970 1915 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1916 {
dcbf9037 1917 first_error (_("missing `}'"));
c19d1205
ZW
1918 return FAIL;
1919 }
1920 }
4b5a202f 1921 else if (etype == REGLIST_RN)
c19d1205 1922 {
91d6fa6a 1923 expressionS exp;
40a18ebd 1924
91d6fa6a 1925 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1926 return FAIL;
40a18ebd 1927
91d6fa6a 1928 if (exp.X_op == O_constant)
c19d1205 1929 {
91d6fa6a
NC
1930 if (exp.X_add_number
1931 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1932 {
1933 inst.error = _("invalid register mask");
1934 return FAIL;
1935 }
a737bd4d 1936
91d6fa6a 1937 if ((range & exp.X_add_number) != 0)
c19d1205 1938 {
91d6fa6a 1939 int regno = range & exp.X_add_number;
a737bd4d 1940
c19d1205
ZW
1941 regno &= -regno;
1942 regno = (1 << regno) - 1;
1943 as_tsktsk
1944 (_("Warning: duplicated register (r%d) in register list"),
1945 regno);
1946 }
a737bd4d 1947
91d6fa6a 1948 range |= exp.X_add_number;
c19d1205
ZW
1949 }
1950 else
1951 {
e2b0ab59 1952 if (inst.relocs[0].type != 0)
c19d1205
ZW
1953 {
1954 inst.error = _("expression too complex");
1955 return FAIL;
1956 }
a737bd4d 1957
e2b0ab59
AV
1958 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1959 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1960 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
1961 }
1962 }
a737bd4d 1963
c19d1205
ZW
1964 if (*str == '|' || *str == '+')
1965 {
1966 str++;
1967 another_range = 1;
1968 }
a737bd4d 1969 }
c19d1205 1970 while (another_range);
a737bd4d 1971
c19d1205
ZW
1972 *strp = str;
1973 return range;
a737bd4d
NC
1974}
1975
c19d1205
ZW
1976/* Parse a VFP register list. If the string is invalid return FAIL.
1977 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1978 register. Parses registers of type ETYPE.
1979 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1980 - Q registers can be used to specify pairs of D registers
1981 - { } can be omitted from around a singleton register list
477330fc
RM
1982 FIXME: This is not implemented, as it would require backtracking in
1983 some cases, e.g.:
1984 vtbl.8 d3,d4,d5
1985 This could be done (the meaning isn't really ambiguous), but doesn't
1986 fit in well with the current parsing framework.
dcbf9037
JB
1987 - 32 D registers may be used (also true for VFPv3).
1988 FIXME: Types are ignored in these register lists, which is probably a
1989 bug. */
6057a28f 1990
c19d1205 1991static int
efd6b359
AV
1992parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
1993 bfd_boolean *partial_match)
6057a28f 1994{
037e8744 1995 char *str = *ccp;
c19d1205
ZW
1996 int base_reg;
1997 int new_base;
21d799b5 1998 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1999 int max_regs = 0;
c19d1205
ZW
2000 int count = 0;
2001 int warned = 0;
2002 unsigned long mask = 0;
a737bd4d 2003 int i;
efd6b359
AV
2004 bfd_boolean vpr_seen = FALSE;
2005 bfd_boolean expect_vpr =
2006 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2007
477330fc 2008 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2009 {
2010 inst.error = _("expecting {");
2011 return FAIL;
2012 }
6057a28f 2013
5287ad62 2014 switch (etype)
c19d1205 2015 {
5287ad62 2016 case REGLIST_VFP_S:
efd6b359 2017 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2018 regtype = REG_TYPE_VFS;
2019 max_regs = 32;
5287ad62 2020 break;
5f4273c7 2021
5287ad62 2022 case REGLIST_VFP_D:
efd6b359 2023 case REGLIST_VFP_D_VPR:
5287ad62 2024 regtype = REG_TYPE_VFD;
b7fc2769 2025 break;
5f4273c7 2026
b7fc2769
JB
2027 case REGLIST_NEON_D:
2028 regtype = REG_TYPE_NDQ;
2029 break;
4b5a202f
AV
2030
2031 default:
2032 gas_assert (0);
b7fc2769
JB
2033 }
2034
efd6b359 2035 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2036 {
b1cc4aeb
PB
2037 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2038 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2039 {
2040 max_regs = 32;
2041 if (thumb_mode)
2042 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2043 fpu_vfp_ext_d32);
2044 else
2045 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2046 fpu_vfp_ext_d32);
2047 }
5287ad62 2048 else
477330fc 2049 max_regs = 16;
c19d1205 2050 }
6057a28f 2051
c19d1205 2052 base_reg = max_regs;
efd6b359 2053 *partial_match = FALSE;
a737bd4d 2054
c19d1205
ZW
2055 do
2056 {
5287ad62 2057 int setmask = 1, addregs = 1;
efd6b359
AV
2058 const char vpr_str[] = "vpr";
2059 int vpr_str_len = strlen (vpr_str);
dcbf9037 2060
037e8744 2061 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2062
efd6b359
AV
2063 if (expect_vpr)
2064 {
2065 if (new_base == FAIL
2066 && !strncasecmp (str, vpr_str, vpr_str_len)
2067 && !ISALPHA (*(str + vpr_str_len))
2068 && !vpr_seen)
2069 {
2070 vpr_seen = TRUE;
2071 str += vpr_str_len;
2072 if (count == 0)
2073 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2074 }
2075 else if (vpr_seen)
2076 {
2077 first_error (_("VPR expected last"));
2078 return FAIL;
2079 }
2080 else if (new_base == FAIL)
2081 {
2082 if (regtype == REG_TYPE_VFS)
2083 first_error (_("VFP single precision register or VPR "
2084 "expected"));
2085 else /* regtype == REG_TYPE_VFD. */
2086 first_error (_("VFP/Neon double precision register or VPR "
2087 "expected"));
2088 return FAIL;
2089 }
2090 }
2091 else if (new_base == FAIL)
a737bd4d 2092 {
dcbf9037 2093 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2094 return FAIL;
2095 }
5f4273c7 2096
efd6b359
AV
2097 *partial_match = TRUE;
2098 if (vpr_seen)
2099 continue;
2100
b7fc2769 2101 if (new_base >= max_regs)
477330fc
RM
2102 {
2103 first_error (_("register out of range in list"));
2104 return FAIL;
2105 }
5f4273c7 2106
5287ad62
JB
2107 /* Note: a value of 2 * n is returned for the register Q<n>. */
2108 if (regtype == REG_TYPE_NQ)
477330fc
RM
2109 {
2110 setmask = 3;
2111 addregs = 2;
2112 }
5287ad62 2113
c19d1205
ZW
2114 if (new_base < base_reg)
2115 base_reg = new_base;
a737bd4d 2116
5287ad62 2117 if (mask & (setmask << new_base))
c19d1205 2118 {
dcbf9037 2119 first_error (_("invalid register list"));
c19d1205 2120 return FAIL;
a737bd4d 2121 }
a737bd4d 2122
efd6b359 2123 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2124 {
2125 as_tsktsk (_("register list not in ascending order"));
2126 warned = 1;
2127 }
0bbf2aa4 2128
5287ad62
JB
2129 mask |= setmask << new_base;
2130 count += addregs;
0bbf2aa4 2131
037e8744 2132 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2133 {
2134 int high_range;
0bbf2aa4 2135
037e8744 2136 str++;
0bbf2aa4 2137
037e8744 2138 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2139 == FAIL)
c19d1205
ZW
2140 {
2141 inst.error = gettext (reg_expected_msgs[regtype]);
2142 return FAIL;
2143 }
0bbf2aa4 2144
477330fc
RM
2145 if (high_range >= max_regs)
2146 {
2147 first_error (_("register out of range in list"));
2148 return FAIL;
2149 }
b7fc2769 2150
477330fc
RM
2151 if (regtype == REG_TYPE_NQ)
2152 high_range = high_range + 1;
5287ad62 2153
c19d1205
ZW
2154 if (high_range <= new_base)
2155 {
2156 inst.error = _("register range not in ascending order");
2157 return FAIL;
2158 }
0bbf2aa4 2159
5287ad62 2160 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2161 {
5287ad62 2162 if (mask & (setmask << new_base))
0bbf2aa4 2163 {
c19d1205
ZW
2164 inst.error = _("invalid register list");
2165 return FAIL;
0bbf2aa4 2166 }
c19d1205 2167
5287ad62
JB
2168 mask |= setmask << new_base;
2169 count += addregs;
0bbf2aa4 2170 }
0bbf2aa4 2171 }
0bbf2aa4 2172 }
037e8744 2173 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2174
037e8744 2175 str++;
0bbf2aa4 2176
c19d1205 2177 /* Sanity check -- should have raised a parse error above. */
efd6b359 2178 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2179 abort ();
2180
2181 *pbase = base_reg;
2182
efd6b359
AV
2183 if (expect_vpr && !vpr_seen)
2184 {
2185 first_error (_("VPR expected last"));
2186 return FAIL;
2187 }
2188
c19d1205
ZW
2189 /* Final test -- the registers must be consecutive. */
2190 mask >>= base_reg;
2191 for (i = 0; i < count; i++)
2192 {
2193 if ((mask & (1u << i)) == 0)
2194 {
2195 inst.error = _("non-contiguous register range");
2196 return FAIL;
2197 }
2198 }
2199
037e8744
JB
2200 *ccp = str;
2201
c19d1205 2202 return count;
b99bd4ef
NC
2203}
2204
dcbf9037
JB
2205/* True if two alias types are the same. */
2206
c921be7d 2207static bfd_boolean
dcbf9037
JB
2208neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2209{
2210 if (!a && !b)
c921be7d 2211 return TRUE;
5f4273c7 2212
dcbf9037 2213 if (!a || !b)
c921be7d 2214 return FALSE;
dcbf9037
JB
2215
2216 if (a->defined != b->defined)
c921be7d 2217 return FALSE;
5f4273c7 2218
dcbf9037
JB
2219 if ((a->defined & NTA_HASTYPE) != 0
2220 && (a->eltype.type != b->eltype.type
477330fc 2221 || a->eltype.size != b->eltype.size))
c921be7d 2222 return FALSE;
dcbf9037
JB
2223
2224 if ((a->defined & NTA_HASINDEX) != 0
2225 && (a->index != b->index))
c921be7d 2226 return FALSE;
5f4273c7 2227
c921be7d 2228 return TRUE;
dcbf9037
JB
2229}
2230
5287ad62
JB
2231/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2232 The base register is put in *PBASE.
dcbf9037 2233 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2234 the return value.
2235 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2236 Bits [6:5] encode the list length (minus one).
2237 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2238
5287ad62 2239#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2240#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2241#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2242
2243static int
dcbf9037 2244parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2245 int mve,
477330fc 2246 struct neon_type_el *eltype)
5287ad62
JB
2247{
2248 char *ptr = *str;
2249 int base_reg = -1;
2250 int reg_incr = -1;
2251 int count = 0;
2252 int lane = -1;
2253 int leading_brace = 0;
2254 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2255 const char *const incr_error = mve ? _("register stride must be 1") :
2256 _("register stride must be 1 or 2");
20203fb9 2257 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2258 struct neon_typed_alias firsttype;
f85d59c3
KT
2259 firsttype.defined = 0;
2260 firsttype.eltype.type = NT_invtype;
2261 firsttype.eltype.size = -1;
2262 firsttype.index = -1;
5f4273c7 2263
5287ad62
JB
2264 if (skip_past_char (&ptr, '{') == SUCCESS)
2265 leading_brace = 1;
5f4273c7 2266
5287ad62
JB
2267 do
2268 {
dcbf9037 2269 struct neon_typed_alias atype;
35c228db
AV
2270 if (mve)
2271 rtype = REG_TYPE_MQ;
dcbf9037
JB
2272 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2273
5287ad62 2274 if (getreg == FAIL)
477330fc
RM
2275 {
2276 first_error (_(reg_expected_msgs[rtype]));
2277 return FAIL;
2278 }
5f4273c7 2279
5287ad62 2280 if (base_reg == -1)
477330fc
RM
2281 {
2282 base_reg = getreg;
2283 if (rtype == REG_TYPE_NQ)
2284 {
2285 reg_incr = 1;
2286 }
2287 firsttype = atype;
2288 }
5287ad62 2289 else if (reg_incr == -1)
477330fc
RM
2290 {
2291 reg_incr = getreg - base_reg;
2292 if (reg_incr < 1 || reg_incr > 2)
2293 {
2294 first_error (_(incr_error));
2295 return FAIL;
2296 }
2297 }
5287ad62 2298 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2299 {
2300 first_error (_(incr_error));
2301 return FAIL;
2302 }
dcbf9037 2303
c921be7d 2304 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2305 {
2306 first_error (_(type_error));
2307 return FAIL;
2308 }
5f4273c7 2309
5287ad62 2310 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2311 modes. */
5287ad62 2312 if (ptr[0] == '-')
477330fc
RM
2313 {
2314 struct neon_typed_alias htype;
2315 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2316 if (lane == -1)
2317 lane = NEON_INTERLEAVE_LANES;
2318 else if (lane != NEON_INTERLEAVE_LANES)
2319 {
2320 first_error (_(type_error));
2321 return FAIL;
2322 }
2323 if (reg_incr == -1)
2324 reg_incr = 1;
2325 else if (reg_incr != 1)
2326 {
2327 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2328 return FAIL;
2329 }
2330 ptr++;
2331 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2332 if (hireg == FAIL)
2333 {
2334 first_error (_(reg_expected_msgs[rtype]));
2335 return FAIL;
2336 }
2337 if (! neon_alias_types_same (&htype, &firsttype))
2338 {
2339 first_error (_(type_error));
2340 return FAIL;
2341 }
2342 count += hireg + dregs - getreg;
2343 continue;
2344 }
5f4273c7 2345
5287ad62
JB
2346 /* If we're using Q registers, we can't use [] or [n] syntax. */
2347 if (rtype == REG_TYPE_NQ)
477330fc
RM
2348 {
2349 count += 2;
2350 continue;
2351 }
5f4273c7 2352
dcbf9037 2353 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2354 {
2355 if (lane == -1)
2356 lane = atype.index;
2357 else if (lane != atype.index)
2358 {
2359 first_error (_(type_error));
2360 return FAIL;
2361 }
2362 }
5287ad62 2363 else if (lane == -1)
477330fc 2364 lane = NEON_INTERLEAVE_LANES;
5287ad62 2365 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2366 {
2367 first_error (_(type_error));
2368 return FAIL;
2369 }
5287ad62
JB
2370 count++;
2371 }
2372 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2373
5287ad62
JB
2374 /* No lane set by [x]. We must be interleaving structures. */
2375 if (lane == -1)
2376 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2377
5287ad62 2378 /* Sanity check. */
35c228db 2379 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2380 || (count > 1 && reg_incr == -1))
2381 {
dcbf9037 2382 first_error (_("error parsing element/structure list"));
5287ad62
JB
2383 return FAIL;
2384 }
2385
2386 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2387 {
dcbf9037 2388 first_error (_("expected }"));
5287ad62
JB
2389 return FAIL;
2390 }
5f4273c7 2391
5287ad62
JB
2392 if (reg_incr == -1)
2393 reg_incr = 1;
2394
dcbf9037
JB
2395 if (eltype)
2396 *eltype = firsttype.eltype;
2397
5287ad62
JB
2398 *pbase = base_reg;
2399 *str = ptr;
5f4273c7 2400
5287ad62
JB
2401 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2402}
2403
c19d1205
ZW
2404/* Parse an explicit relocation suffix on an expression. This is
2405 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2406 arm_reloc_hsh contains no entries, so this function can only
2407 succeed if there is no () after the word. Returns -1 on error,
2408 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2409
c19d1205
ZW
2410static int
2411parse_reloc (char **str)
b99bd4ef 2412{
c19d1205
ZW
2413 struct reloc_entry *r;
2414 char *p, *q;
b99bd4ef 2415
c19d1205
ZW
2416 if (**str != '(')
2417 return BFD_RELOC_UNUSED;
b99bd4ef 2418
c19d1205
ZW
2419 p = *str + 1;
2420 q = p;
2421
2422 while (*q && *q != ')' && *q != ',')
2423 q++;
2424 if (*q != ')')
2425 return -1;
2426
21d799b5
NC
2427 if ((r = (struct reloc_entry *)
2428 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2429 return -1;
2430
2431 *str = q + 1;
2432 return r->reloc;
b99bd4ef
NC
2433}
2434
c19d1205
ZW
2435/* Directives: register aliases. */
2436
dcbf9037 2437static struct reg_entry *
90ec0d68 2438insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2439{
d3ce72d0 2440 struct reg_entry *new_reg;
c19d1205 2441 const char *name;
b99bd4ef 2442
d3ce72d0 2443 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2444 {
d3ce72d0 2445 if (new_reg->builtin)
c19d1205 2446 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2447
c19d1205
ZW
2448 /* Only warn about a redefinition if it's not defined as the
2449 same register. */
d3ce72d0 2450 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2451 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2452
d929913e 2453 return NULL;
c19d1205 2454 }
b99bd4ef 2455
c19d1205 2456 name = xstrdup (str);
325801bd 2457 new_reg = XNEW (struct reg_entry);
b99bd4ef 2458
d3ce72d0
NC
2459 new_reg->name = name;
2460 new_reg->number = number;
2461 new_reg->type = type;
2462 new_reg->builtin = FALSE;
2463 new_reg->neon = NULL;
b99bd4ef 2464
d3ce72d0 2465 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2466 abort ();
5f4273c7 2467
d3ce72d0 2468 return new_reg;
dcbf9037
JB
2469}
2470
2471static void
2472insert_neon_reg_alias (char *str, int number, int type,
477330fc 2473 struct neon_typed_alias *atype)
dcbf9037
JB
2474{
2475 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2476
dcbf9037
JB
2477 if (!reg)
2478 {
2479 first_error (_("attempt to redefine typed alias"));
2480 return;
2481 }
5f4273c7 2482
dcbf9037
JB
2483 if (atype)
2484 {
325801bd 2485 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2486 *reg->neon = *atype;
2487 }
c19d1205 2488}
b99bd4ef 2489
c19d1205 2490/* Look for the .req directive. This is of the form:
b99bd4ef 2491
c19d1205 2492 new_register_name .req existing_register_name
b99bd4ef 2493
c19d1205 2494 If we find one, or if it looks sufficiently like one that we want to
d929913e 2495 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2496
d929913e 2497static bfd_boolean
c19d1205
ZW
2498create_register_alias (char * newname, char *p)
2499{
2500 struct reg_entry *old;
2501 char *oldname, *nbuf;
2502 size_t nlen;
b99bd4ef 2503
c19d1205
ZW
2504 /* The input scrubber ensures that whitespace after the mnemonic is
2505 collapsed to single spaces. */
2506 oldname = p;
2507 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2508 return FALSE;
b99bd4ef 2509
c19d1205
ZW
2510 oldname += 6;
2511 if (*oldname == '\0')
d929913e 2512 return FALSE;
b99bd4ef 2513
21d799b5 2514 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2515 if (!old)
b99bd4ef 2516 {
c19d1205 2517 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2518 return TRUE;
b99bd4ef
NC
2519 }
2520
c19d1205
ZW
2521 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2522 the desired alias name, and p points to its end. If not, then
2523 the desired alias name is in the global original_case_string. */
2524#ifdef TC_CASE_SENSITIVE
2525 nlen = p - newname;
2526#else
2527 newname = original_case_string;
2528 nlen = strlen (newname);
2529#endif
b99bd4ef 2530
29a2809e 2531 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2532
c19d1205
ZW
2533 /* Create aliases under the new name as stated; an all-lowercase
2534 version of the new name; and an all-uppercase version of the new
2535 name. */
d929913e
NC
2536 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2537 {
2538 for (p = nbuf; *p; p++)
2539 *p = TOUPPER (*p);
c19d1205 2540
d929913e
NC
2541 if (strncmp (nbuf, newname, nlen))
2542 {
2543 /* If this attempt to create an additional alias fails, do not bother
2544 trying to create the all-lower case alias. We will fail and issue
2545 a second, duplicate error message. This situation arises when the
2546 programmer does something like:
2547 foo .req r0
2548 Foo .req r1
2549 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2550 the artificial FOO alias because it has already been created by the
d929913e
NC
2551 first .req. */
2552 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2553 {
2554 free (nbuf);
2555 return TRUE;
2556 }
d929913e 2557 }
c19d1205 2558
d929913e
NC
2559 for (p = nbuf; *p; p++)
2560 *p = TOLOWER (*p);
c19d1205 2561
d929913e
NC
2562 if (strncmp (nbuf, newname, nlen))
2563 insert_reg_alias (nbuf, old->number, old->type);
2564 }
c19d1205 2565
e1fa0163 2566 free (nbuf);
d929913e 2567 return TRUE;
b99bd4ef
NC
2568}
2569
dcbf9037
JB
2570/* Create a Neon typed/indexed register alias using directives, e.g.:
2571 X .dn d5.s32[1]
2572 Y .qn 6.s16
2573 Z .dn d7
2574 T .dn Z[0]
2575 These typed registers can be used instead of the types specified after the
2576 Neon mnemonic, so long as all operands given have types. Types can also be
2577 specified directly, e.g.:
5f4273c7 2578 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2579
c921be7d 2580static bfd_boolean
dcbf9037
JB
2581create_neon_reg_alias (char *newname, char *p)
2582{
2583 enum arm_reg_type basetype;
2584 struct reg_entry *basereg;
2585 struct reg_entry mybasereg;
2586 struct neon_type ntype;
2587 struct neon_typed_alias typeinfo;
12d6b0b7 2588 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2589 int namelen;
5f4273c7 2590
dcbf9037
JB
2591 typeinfo.defined = 0;
2592 typeinfo.eltype.type = NT_invtype;
2593 typeinfo.eltype.size = -1;
2594 typeinfo.index = -1;
5f4273c7 2595
dcbf9037 2596 nameend = p;
5f4273c7 2597
dcbf9037
JB
2598 if (strncmp (p, " .dn ", 5) == 0)
2599 basetype = REG_TYPE_VFD;
2600 else if (strncmp (p, " .qn ", 5) == 0)
2601 basetype = REG_TYPE_NQ;
2602 else
c921be7d 2603 return FALSE;
5f4273c7 2604
dcbf9037 2605 p += 5;
5f4273c7 2606
dcbf9037 2607 if (*p == '\0')
c921be7d 2608 return FALSE;
5f4273c7 2609
dcbf9037
JB
2610 basereg = arm_reg_parse_multi (&p);
2611
2612 if (basereg && basereg->type != basetype)
2613 {
2614 as_bad (_("bad type for register"));
c921be7d 2615 return FALSE;
dcbf9037
JB
2616 }
2617
2618 if (basereg == NULL)
2619 {
2620 expressionS exp;
2621 /* Try parsing as an integer. */
2622 my_get_expression (&exp, &p, GE_NO_PREFIX);
2623 if (exp.X_op != O_constant)
477330fc
RM
2624 {
2625 as_bad (_("expression must be constant"));
2626 return FALSE;
2627 }
dcbf9037
JB
2628 basereg = &mybasereg;
2629 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2630 : exp.X_add_number;
dcbf9037
JB
2631 basereg->neon = 0;
2632 }
2633
2634 if (basereg->neon)
2635 typeinfo = *basereg->neon;
2636
2637 if (parse_neon_type (&ntype, &p) == SUCCESS)
2638 {
2639 /* We got a type. */
2640 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2641 {
2642 as_bad (_("can't redefine the type of a register alias"));
2643 return FALSE;
2644 }
5f4273c7 2645
dcbf9037
JB
2646 typeinfo.defined |= NTA_HASTYPE;
2647 if (ntype.elems != 1)
477330fc
RM
2648 {
2649 as_bad (_("you must specify a single type only"));
2650 return FALSE;
2651 }
dcbf9037
JB
2652 typeinfo.eltype = ntype.el[0];
2653 }
5f4273c7 2654
dcbf9037
JB
2655 if (skip_past_char (&p, '[') == SUCCESS)
2656 {
2657 expressionS exp;
2658 /* We got a scalar index. */
5f4273c7 2659
dcbf9037 2660 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2661 {
2662 as_bad (_("can't redefine the index of a scalar alias"));
2663 return FALSE;
2664 }
5f4273c7 2665
dcbf9037 2666 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2667
dcbf9037 2668 if (exp.X_op != O_constant)
477330fc
RM
2669 {
2670 as_bad (_("scalar index must be constant"));
2671 return FALSE;
2672 }
5f4273c7 2673
dcbf9037
JB
2674 typeinfo.defined |= NTA_HASINDEX;
2675 typeinfo.index = exp.X_add_number;
5f4273c7 2676
dcbf9037 2677 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2678 {
2679 as_bad (_("expecting ]"));
2680 return FALSE;
2681 }
dcbf9037
JB
2682 }
2683
15735687
NS
2684 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2685 the desired alias name, and p points to its end. If not, then
2686 the desired alias name is in the global original_case_string. */
2687#ifdef TC_CASE_SENSITIVE
dcbf9037 2688 namelen = nameend - newname;
15735687
NS
2689#else
2690 newname = original_case_string;
2691 namelen = strlen (newname);
2692#endif
2693
29a2809e 2694 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2695
dcbf9037 2696 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2697 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2698
dcbf9037
JB
2699 /* Insert name in all uppercase. */
2700 for (p = namebuf; *p; p++)
2701 *p = TOUPPER (*p);
5f4273c7 2702
dcbf9037
JB
2703 if (strncmp (namebuf, newname, namelen))
2704 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2705 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2706
dcbf9037
JB
2707 /* Insert name in all lowercase. */
2708 for (p = namebuf; *p; p++)
2709 *p = TOLOWER (*p);
5f4273c7 2710
dcbf9037
JB
2711 if (strncmp (namebuf, newname, namelen))
2712 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2713 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2714
e1fa0163 2715 free (namebuf);
c921be7d 2716 return TRUE;
dcbf9037
JB
2717}
2718
c19d1205
ZW
2719/* Should never be called, as .req goes between the alias and the
2720 register name, not at the beginning of the line. */
c921be7d 2721
b99bd4ef 2722static void
c19d1205 2723s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2724{
c19d1205
ZW
2725 as_bad (_("invalid syntax for .req directive"));
2726}
b99bd4ef 2727
dcbf9037
JB
2728static void
2729s_dn (int a ATTRIBUTE_UNUSED)
2730{
2731 as_bad (_("invalid syntax for .dn directive"));
2732}
2733
2734static void
2735s_qn (int a ATTRIBUTE_UNUSED)
2736{
2737 as_bad (_("invalid syntax for .qn directive"));
2738}
2739
c19d1205
ZW
2740/* The .unreq directive deletes an alias which was previously defined
2741 by .req. For example:
b99bd4ef 2742
c19d1205
ZW
2743 my_alias .req r11
2744 .unreq my_alias */
b99bd4ef
NC
2745
2746static void
c19d1205 2747s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2748{
c19d1205
ZW
2749 char * name;
2750 char saved_char;
b99bd4ef 2751
c19d1205
ZW
2752 name = input_line_pointer;
2753
2754 while (*input_line_pointer != 0
2755 && *input_line_pointer != ' '
2756 && *input_line_pointer != '\n')
2757 ++input_line_pointer;
2758
2759 saved_char = *input_line_pointer;
2760 *input_line_pointer = 0;
2761
2762 if (!*name)
2763 as_bad (_("invalid syntax for .unreq directive"));
2764 else
2765 {
21d799b5 2766 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2767 name);
c19d1205
ZW
2768
2769 if (!reg)
2770 as_bad (_("unknown register alias '%s'"), name);
2771 else if (reg->builtin)
a1727c1a 2772 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2773 name);
2774 else
2775 {
d929913e
NC
2776 char * p;
2777 char * nbuf;
2778
db0bc284 2779 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2780 free ((char *) reg->name);
477330fc
RM
2781 if (reg->neon)
2782 free (reg->neon);
c19d1205 2783 free (reg);
d929913e
NC
2784
2785 /* Also locate the all upper case and all lower case versions.
2786 Do not complain if we cannot find one or the other as it
2787 was probably deleted above. */
5f4273c7 2788
d929913e
NC
2789 nbuf = strdup (name);
2790 for (p = nbuf; *p; p++)
2791 *p = TOUPPER (*p);
21d799b5 2792 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2793 if (reg)
2794 {
db0bc284 2795 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2796 free ((char *) reg->name);
2797 if (reg->neon)
2798 free (reg->neon);
2799 free (reg);
2800 }
2801
2802 for (p = nbuf; *p; p++)
2803 *p = TOLOWER (*p);
21d799b5 2804 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2805 if (reg)
2806 {
db0bc284 2807 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2808 free ((char *) reg->name);
2809 if (reg->neon)
2810 free (reg->neon);
2811 free (reg);
2812 }
2813
2814 free (nbuf);
c19d1205
ZW
2815 }
2816 }
b99bd4ef 2817
c19d1205 2818 *input_line_pointer = saved_char;
b99bd4ef
NC
2819 demand_empty_rest_of_line ();
2820}
2821
c19d1205
ZW
2822/* Directives: Instruction set selection. */
2823
2824#ifdef OBJ_ELF
2825/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2826 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2827 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2828 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2829
cd000bff
DJ
2830/* Create a new mapping symbol for the transition to STATE. */
2831
2832static void
2833make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2834{
a737bd4d 2835 symbolS * symbolP;
c19d1205
ZW
2836 const char * symname;
2837 int type;
b99bd4ef 2838
c19d1205 2839 switch (state)
b99bd4ef 2840 {
c19d1205
ZW
2841 case MAP_DATA:
2842 symname = "$d";
2843 type = BSF_NO_FLAGS;
2844 break;
2845 case MAP_ARM:
2846 symname = "$a";
2847 type = BSF_NO_FLAGS;
2848 break;
2849 case MAP_THUMB:
2850 symname = "$t";
2851 type = BSF_NO_FLAGS;
2852 break;
c19d1205
ZW
2853 default:
2854 abort ();
2855 }
2856
cd000bff 2857 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2858 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2859
2860 switch (state)
2861 {
2862 case MAP_ARM:
2863 THUMB_SET_FUNC (symbolP, 0);
2864 ARM_SET_THUMB (symbolP, 0);
2865 ARM_SET_INTERWORK (symbolP, support_interwork);
2866 break;
2867
2868 case MAP_THUMB:
2869 THUMB_SET_FUNC (symbolP, 1);
2870 ARM_SET_THUMB (symbolP, 1);
2871 ARM_SET_INTERWORK (symbolP, support_interwork);
2872 break;
2873
2874 case MAP_DATA:
2875 default:
cd000bff
DJ
2876 break;
2877 }
2878
2879 /* Save the mapping symbols for future reference. Also check that
2880 we do not place two mapping symbols at the same offset within a
2881 frag. We'll handle overlap between frags in
2de7820f
JZ
2882 check_mapping_symbols.
2883
2884 If .fill or other data filling directive generates zero sized data,
2885 the mapping symbol for the following code will have the same value
2886 as the one generated for the data filling directive. In this case,
2887 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2888 if (value == 0)
2889 {
2de7820f
JZ
2890 if (frag->tc_frag_data.first_map != NULL)
2891 {
2892 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2893 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2894 }
cd000bff
DJ
2895 frag->tc_frag_data.first_map = symbolP;
2896 }
2897 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2898 {
2899 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2900 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2901 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2902 }
cd000bff
DJ
2903 frag->tc_frag_data.last_map = symbolP;
2904}
2905
2906/* We must sometimes convert a region marked as code to data during
2907 code alignment, if an odd number of bytes have to be padded. The
2908 code mapping symbol is pushed to an aligned address. */
2909
2910static void
2911insert_data_mapping_symbol (enum mstate state,
2912 valueT value, fragS *frag, offsetT bytes)
2913{
2914 /* If there was already a mapping symbol, remove it. */
2915 if (frag->tc_frag_data.last_map != NULL
2916 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2917 {
2918 symbolS *symp = frag->tc_frag_data.last_map;
2919
2920 if (value == 0)
2921 {
2922 know (frag->tc_frag_data.first_map == symp);
2923 frag->tc_frag_data.first_map = NULL;
2924 }
2925 frag->tc_frag_data.last_map = NULL;
2926 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2927 }
cd000bff
DJ
2928
2929 make_mapping_symbol (MAP_DATA, value, frag);
2930 make_mapping_symbol (state, value + bytes, frag);
2931}
2932
2933static void mapping_state_2 (enum mstate state, int max_chars);
2934
2935/* Set the mapping state to STATE. Only call this when about to
2936 emit some STATE bytes to the file. */
2937
4e9aaefb 2938#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2939void
2940mapping_state (enum mstate state)
2941{
940b5ce0
DJ
2942 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2943
cd000bff
DJ
2944 if (mapstate == state)
2945 /* The mapping symbol has already been emitted.
2946 There is nothing else to do. */
2947 return;
49c62a33
NC
2948
2949 if (state == MAP_ARM || state == MAP_THUMB)
2950 /* PR gas/12931
2951 All ARM instructions require 4-byte alignment.
2952 (Almost) all Thumb instructions require 2-byte alignment.
2953
2954 When emitting instructions into any section, mark the section
2955 appropriately.
2956
2957 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2958 but themselves require 2-byte alignment; this applies to some
33eaf5de 2959 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2960 literal pool generation or an explicit .align >=2, both of
2961 which will cause the section to me marked with sufficient
2962 alignment. Thus, we don't handle those cases here. */
2963 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2964
2965 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2966 /* This case will be evaluated later. */
cd000bff 2967 return;
cd000bff
DJ
2968
2969 mapping_state_2 (state, 0);
cd000bff
DJ
2970}
2971
2972/* Same as mapping_state, but MAX_CHARS bytes have already been
2973 allocated. Put the mapping symbol that far back. */
2974
2975static void
2976mapping_state_2 (enum mstate state, int max_chars)
2977{
940b5ce0
DJ
2978 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2979
2980 if (!SEG_NORMAL (now_seg))
2981 return;
2982
cd000bff
DJ
2983 if (mapstate == state)
2984 /* The mapping symbol has already been emitted.
2985 There is nothing else to do. */
2986 return;
2987
4e9aaefb
SA
2988 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2989 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2990 {
2991 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2992 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2993
2994 if (add_symbol)
2995 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2996 }
2997
cd000bff
DJ
2998 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2999 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3000}
4e9aaefb 3001#undef TRANSITION
c19d1205 3002#else
d3106081
NS
3003#define mapping_state(x) ((void)0)
3004#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3005#endif
3006
3007/* Find the real, Thumb encoded start of a Thumb function. */
3008
4343666d 3009#ifdef OBJ_COFF
c19d1205
ZW
3010static symbolS *
3011find_real_start (symbolS * symbolP)
3012{
3013 char * real_start;
3014 const char * name = S_GET_NAME (symbolP);
3015 symbolS * new_target;
3016
3017 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3018#define STUB_NAME ".real_start_of"
3019
3020 if (name == NULL)
3021 abort ();
3022
37f6032b
ZW
3023 /* The compiler may generate BL instructions to local labels because
3024 it needs to perform a branch to a far away location. These labels
3025 do not have a corresponding ".real_start_of" label. We check
3026 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3027 the ".real_start_of" convention for nonlocal branches. */
3028 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3029 return symbolP;
3030
e1fa0163 3031 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3032 new_target = symbol_find (real_start);
e1fa0163 3033 free (real_start);
c19d1205
ZW
3034
3035 if (new_target == NULL)
3036 {
bd3ba5d1 3037 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3038 new_target = symbolP;
3039 }
3040
c19d1205
ZW
3041 return new_target;
3042}
4343666d 3043#endif
c19d1205
ZW
3044
3045static void
3046opcode_select (int width)
3047{
3048 switch (width)
3049 {
3050 case 16:
3051 if (! thumb_mode)
3052 {
e74cfd16 3053 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3054 as_bad (_("selected processor does not support THUMB opcodes"));
3055
3056 thumb_mode = 1;
3057 /* No need to force the alignment, since we will have been
3058 coming from ARM mode, which is word-aligned. */
3059 record_alignment (now_seg, 1);
3060 }
c19d1205
ZW
3061 break;
3062
3063 case 32:
3064 if (thumb_mode)
3065 {
e74cfd16 3066 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3067 as_bad (_("selected processor does not support ARM opcodes"));
3068
3069 thumb_mode = 0;
3070
3071 if (!need_pass_2)
3072 frag_align (2, 0, 0);
3073
3074 record_alignment (now_seg, 1);
3075 }
c19d1205
ZW
3076 break;
3077
3078 default:
3079 as_bad (_("invalid instruction size selected (%d)"), width);
3080 }
3081}
3082
3083static void
3084s_arm (int ignore ATTRIBUTE_UNUSED)
3085{
3086 opcode_select (32);
3087 demand_empty_rest_of_line ();
3088}
3089
3090static void
3091s_thumb (int ignore ATTRIBUTE_UNUSED)
3092{
3093 opcode_select (16);
3094 demand_empty_rest_of_line ();
3095}
3096
3097static void
3098s_code (int unused ATTRIBUTE_UNUSED)
3099{
3100 int temp;
3101
3102 temp = get_absolute_expression ();
3103 switch (temp)
3104 {
3105 case 16:
3106 case 32:
3107 opcode_select (temp);
3108 break;
3109
3110 default:
3111 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3112 }
3113}
3114
3115static void
3116s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3117{
3118 /* If we are not already in thumb mode go into it, EVEN if
3119 the target processor does not support thumb instructions.
3120 This is used by gcc/config/arm/lib1funcs.asm for example
3121 to compile interworking support functions even if the
3122 target processor should not support interworking. */
3123 if (! thumb_mode)
3124 {
3125 thumb_mode = 2;
3126 record_alignment (now_seg, 1);
3127 }
3128
3129 demand_empty_rest_of_line ();
3130}
3131
3132static void
3133s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3134{
3135 s_thumb (0);
3136
3137 /* The following label is the name/address of the start of a Thumb function.
3138 We need to know this for the interworking support. */
3139 label_is_thumb_function_name = TRUE;
3140}
3141
3142/* Perform a .set directive, but also mark the alias as
3143 being a thumb function. */
3144
3145static void
3146s_thumb_set (int equiv)
3147{
3148 /* XXX the following is a duplicate of the code for s_set() in read.c
3149 We cannot just call that code as we need to get at the symbol that
3150 is created. */
3151 char * name;
3152 char delim;
3153 char * end_name;
3154 symbolS * symbolP;
3155
3156 /* Especial apologies for the random logic:
3157 This just grew, and could be parsed much more simply!
3158 Dean - in haste. */
d02603dc 3159 delim = get_symbol_name (& name);
c19d1205 3160 end_name = input_line_pointer;
d02603dc 3161 (void) restore_line_pointer (delim);
c19d1205
ZW
3162
3163 if (*input_line_pointer != ',')
3164 {
3165 *end_name = 0;
3166 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3167 *end_name = delim;
3168 ignore_rest_of_line ();
3169 return;
3170 }
3171
3172 input_line_pointer++;
3173 *end_name = 0;
3174
3175 if (name[0] == '.' && name[1] == '\0')
3176 {
3177 /* XXX - this should not happen to .thumb_set. */
3178 abort ();
3179 }
3180
3181 if ((symbolP = symbol_find (name)) == NULL
3182 && (symbolP = md_undefined_symbol (name)) == NULL)
3183 {
3184#ifndef NO_LISTING
3185 /* When doing symbol listings, play games with dummy fragments living
3186 outside the normal fragment chain to record the file and line info
c19d1205 3187 for this symbol. */
b99bd4ef
NC
3188 if (listing & LISTING_SYMBOLS)
3189 {
3190 extern struct list_info_struct * listing_tail;
21d799b5 3191 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3192
3193 memset (dummy_frag, 0, sizeof (fragS));
3194 dummy_frag->fr_type = rs_fill;
3195 dummy_frag->line = listing_tail;
3196 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3197 dummy_frag->fr_symbol = symbolP;
3198 }
3199 else
3200#endif
3201 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3202
3203#ifdef OBJ_COFF
3204 /* "set" symbols are local unless otherwise specified. */
3205 SF_SET_LOCAL (symbolP);
3206#endif /* OBJ_COFF */
3207 } /* Make a new symbol. */
3208
3209 symbol_table_insert (symbolP);
3210
3211 * end_name = delim;
3212
3213 if (equiv
3214 && S_IS_DEFINED (symbolP)
3215 && S_GET_SEGMENT (symbolP) != reg_section)
3216 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3217
3218 pseudo_set (symbolP);
3219
3220 demand_empty_rest_of_line ();
3221
c19d1205 3222 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3223
3224 THUMB_SET_FUNC (symbolP, 1);
3225 ARM_SET_THUMB (symbolP, 1);
3226#if defined OBJ_ELF || defined OBJ_COFF
3227 ARM_SET_INTERWORK (symbolP, support_interwork);
3228#endif
3229}
3230
c19d1205 3231/* Directives: Mode selection. */
b99bd4ef 3232
c19d1205
ZW
3233/* .syntax [unified|divided] - choose the new unified syntax
3234 (same for Arm and Thumb encoding, modulo slight differences in what
3235 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3236static void
c19d1205 3237s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3238{
c19d1205
ZW
3239 char *name, delim;
3240
d02603dc 3241 delim = get_symbol_name (& name);
c19d1205
ZW
3242
3243 if (!strcasecmp (name, "unified"))
3244 unified_syntax = TRUE;
3245 else if (!strcasecmp (name, "divided"))
3246 unified_syntax = FALSE;
3247 else
3248 {
3249 as_bad (_("unrecognized syntax mode \"%s\""), name);
3250 return;
3251 }
d02603dc 3252 (void) restore_line_pointer (delim);
b99bd4ef
NC
3253 demand_empty_rest_of_line ();
3254}
3255
c19d1205
ZW
3256/* Directives: sectioning and alignment. */
3257
c19d1205
ZW
3258static void
3259s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3260{
c19d1205
ZW
3261 /* We don't support putting frags in the BSS segment, we fake it by
3262 marking in_bss, then looking at s_skip for clues. */
3263 subseg_set (bss_section, 0);
3264 demand_empty_rest_of_line ();
cd000bff
DJ
3265
3266#ifdef md_elf_section_change_hook
3267 md_elf_section_change_hook ();
3268#endif
c19d1205 3269}
b99bd4ef 3270
c19d1205
ZW
3271static void
3272s_even (int ignore ATTRIBUTE_UNUSED)
3273{
3274 /* Never make frag if expect extra pass. */
3275 if (!need_pass_2)
3276 frag_align (1, 0, 0);
b99bd4ef 3277
c19d1205 3278 record_alignment (now_seg, 1);
b99bd4ef 3279
c19d1205 3280 demand_empty_rest_of_line ();
b99bd4ef
NC
3281}
3282
2e6976a8
DG
3283/* Directives: CodeComposer Studio. */
3284
3285/* .ref (for CodeComposer Studio syntax only). */
3286static void
3287s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3288{
3289 if (codecomposer_syntax)
3290 ignore_rest_of_line ();
3291 else
3292 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3293}
3294
3295/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3296 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3297static void
3298asmfunc_debug (const char * name)
3299{
3300 static const char * last_name = NULL;
3301
3302 if (name != NULL)
3303 {
3304 gas_assert (last_name == NULL);
3305 last_name = name;
3306
3307 if (debug_type == DEBUG_STABS)
3308 stabs_generate_asm_func (name, name);
3309 }
3310 else
3311 {
3312 gas_assert (last_name != NULL);
3313
3314 if (debug_type == DEBUG_STABS)
3315 stabs_generate_asm_endfunc (last_name, last_name);
3316
3317 last_name = NULL;
3318 }
3319}
3320
3321static void
3322s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3323{
3324 if (codecomposer_syntax)
3325 {
3326 switch (asmfunc_state)
3327 {
3328 case OUTSIDE_ASMFUNC:
3329 asmfunc_state = WAITING_ASMFUNC_NAME;
3330 break;
3331
3332 case WAITING_ASMFUNC_NAME:
3333 as_bad (_(".asmfunc repeated."));
3334 break;
3335
3336 case WAITING_ENDASMFUNC:
3337 as_bad (_(".asmfunc without function."));
3338 break;
3339 }
3340 demand_empty_rest_of_line ();
3341 }
3342 else
3343 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3344}
3345
3346static void
3347s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3348{
3349 if (codecomposer_syntax)
3350 {
3351 switch (asmfunc_state)
3352 {
3353 case OUTSIDE_ASMFUNC:
3354 as_bad (_(".endasmfunc without a .asmfunc."));
3355 break;
3356
3357 case WAITING_ASMFUNC_NAME:
3358 as_bad (_(".endasmfunc without function."));
3359 break;
3360
3361 case WAITING_ENDASMFUNC:
3362 asmfunc_state = OUTSIDE_ASMFUNC;
3363 asmfunc_debug (NULL);
3364 break;
3365 }
3366 demand_empty_rest_of_line ();
3367 }
3368 else
3369 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3370}
3371
3372static void
3373s_ccs_def (int name)
3374{
3375 if (codecomposer_syntax)
3376 s_globl (name);
3377 else
3378 as_bad (_(".def pseudo-op only available with -mccs flag."));
3379}
3380
c19d1205 3381/* Directives: Literal pools. */
a737bd4d 3382
c19d1205
ZW
3383static literal_pool *
3384find_literal_pool (void)
a737bd4d 3385{
c19d1205 3386 literal_pool * pool;
a737bd4d 3387
c19d1205 3388 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3389 {
c19d1205
ZW
3390 if (pool->section == now_seg
3391 && pool->sub_section == now_subseg)
3392 break;
a737bd4d
NC
3393 }
3394
c19d1205 3395 return pool;
a737bd4d
NC
3396}
3397
c19d1205
ZW
3398static literal_pool *
3399find_or_make_literal_pool (void)
a737bd4d 3400{
c19d1205
ZW
3401 /* Next literal pool ID number. */
3402 static unsigned int latest_pool_num = 1;
3403 literal_pool * pool;
a737bd4d 3404
c19d1205 3405 pool = find_literal_pool ();
a737bd4d 3406
c19d1205 3407 if (pool == NULL)
a737bd4d 3408 {
c19d1205 3409 /* Create a new pool. */
325801bd 3410 pool = XNEW (literal_pool);
c19d1205
ZW
3411 if (! pool)
3412 return NULL;
a737bd4d 3413
c19d1205
ZW
3414 pool->next_free_entry = 0;
3415 pool->section = now_seg;
3416 pool->sub_section = now_subseg;
3417 pool->next = list_of_pools;
3418 pool->symbol = NULL;
8335d6aa 3419 pool->alignment = 2;
c19d1205
ZW
3420
3421 /* Add it to the list. */
3422 list_of_pools = pool;
a737bd4d 3423 }
a737bd4d 3424
c19d1205
ZW
3425 /* New pools, and emptied pools, will have a NULL symbol. */
3426 if (pool->symbol == NULL)
a737bd4d 3427 {
c19d1205
ZW
3428 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3429 (valueT) 0, &zero_address_frag);
3430 pool->id = latest_pool_num ++;
a737bd4d
NC
3431 }
3432
c19d1205
ZW
3433 /* Done. */
3434 return pool;
a737bd4d
NC
3435}
3436
c19d1205 3437/* Add the literal in the global 'inst'
5f4273c7 3438 structure to the relevant literal pool. */
b99bd4ef
NC
3439
3440static int
8335d6aa 3441add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3442{
8335d6aa
JW
3443#define PADDING_SLOT 0x1
3444#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3445 literal_pool * pool;
8335d6aa
JW
3446 unsigned int entry, pool_size = 0;
3447 bfd_boolean padding_slot_p = FALSE;
e56c722b 3448 unsigned imm1 = 0;
8335d6aa
JW
3449 unsigned imm2 = 0;
3450
3451 if (nbytes == 8)
3452 {
3453 imm1 = inst.operands[1].imm;
3454 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3455 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3456 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3457 if (target_big_endian)
3458 {
3459 imm1 = imm2;
3460 imm2 = inst.operands[1].imm;
3461 }
3462 }
b99bd4ef 3463
c19d1205
ZW
3464 pool = find_or_make_literal_pool ();
3465
3466 /* Check if this literal value is already in the pool. */
3467 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3468 {
8335d6aa
JW
3469 if (nbytes == 4)
3470 {
e2b0ab59
AV
3471 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3472 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3473 && (pool->literals[entry].X_add_number
e2b0ab59 3474 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3475 && (pool->literals[entry].X_md == nbytes)
3476 && (pool->literals[entry].X_unsigned
e2b0ab59 3477 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3478 break;
3479
e2b0ab59
AV
3480 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3481 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3482 && (pool->literals[entry].X_add_number
e2b0ab59 3483 == inst.relocs[0].exp.X_add_number)
8335d6aa 3484 && (pool->literals[entry].X_add_symbol
e2b0ab59 3485 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3486 && (pool->literals[entry].X_op_symbol
e2b0ab59 3487 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3488 && (pool->literals[entry].X_md == nbytes))
3489 break;
3490 }
3491 else if ((nbytes == 8)
3492 && !(pool_size & 0x7)
3493 && ((entry + 1) != pool->next_free_entry)
3494 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3495 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3496 && (pool->literals[entry].X_unsigned
e2b0ab59 3497 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3498 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3499 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3500 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3501 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3502 break;
3503
8335d6aa
JW
3504 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3505 if (padding_slot_p && (nbytes == 4))
c19d1205 3506 break;
8335d6aa
JW
3507
3508 pool_size += 4;
b99bd4ef
NC
3509 }
3510
c19d1205
ZW
3511 /* Do we need to create a new entry? */
3512 if (entry == pool->next_free_entry)
3513 {
3514 if (entry >= MAX_LITERAL_POOL_SIZE)
3515 {
3516 inst.error = _("literal pool overflow");
3517 return FAIL;
3518 }
3519
8335d6aa
JW
3520 if (nbytes == 8)
3521 {
3522 /* For 8-byte entries, we align to an 8-byte boundary,
3523 and split it into two 4-byte entries, because on 32-bit
3524 host, 8-byte constants are treated as big num, thus
3525 saved in "generic_bignum" which will be overwritten
3526 by later assignments.
3527
3528 We also need to make sure there is enough space for
3529 the split.
3530
3531 We also check to make sure the literal operand is a
3532 constant number. */
e2b0ab59
AV
3533 if (!(inst.relocs[0].exp.X_op == O_constant
3534 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3535 {
3536 inst.error = _("invalid type for literal pool");
3537 return FAIL;
3538 }
3539 else if (pool_size & 0x7)
3540 {
3541 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3542 {
3543 inst.error = _("literal pool overflow");
3544 return FAIL;
3545 }
3546
e2b0ab59 3547 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3548 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3549 pool->literals[entry].X_add_number = 0;
3550 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3551 pool->next_free_entry += 1;
3552 pool_size += 4;
3553 }
3554 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3555 {
3556 inst.error = _("literal pool overflow");
3557 return FAIL;
3558 }
3559
e2b0ab59 3560 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3561 pool->literals[entry].X_op = O_constant;
3562 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3563 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3564 pool->literals[entry++].X_md = 4;
e2b0ab59 3565 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3566 pool->literals[entry].X_op = O_constant;
3567 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3568 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3569 pool->literals[entry].X_md = 4;
3570 pool->alignment = 3;
3571 pool->next_free_entry += 1;
3572 }
3573 else
3574 {
e2b0ab59 3575 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3576 pool->literals[entry].X_md = 4;
3577 }
3578
a8040cf2
NC
3579#ifdef OBJ_ELF
3580 /* PR ld/12974: Record the location of the first source line to reference
3581 this entry in the literal pool. If it turns out during linking that the
3582 symbol does not exist we will be able to give an accurate line number for
3583 the (first use of the) missing reference. */
3584 if (debug_type == DEBUG_DWARF2)
3585 dwarf2_where (pool->locs + entry);
3586#endif
c19d1205
ZW
3587 pool->next_free_entry += 1;
3588 }
8335d6aa
JW
3589 else if (padding_slot_p)
3590 {
e2b0ab59 3591 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3592 pool->literals[entry].X_md = nbytes;
3593 }
b99bd4ef 3594
e2b0ab59
AV
3595 inst.relocs[0].exp.X_op = O_symbol;
3596 inst.relocs[0].exp.X_add_number = pool_size;
3597 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3598
c19d1205 3599 return SUCCESS;
b99bd4ef
NC
3600}
3601
2e6976a8 3602bfd_boolean
2e57ce7b 3603tc_start_label_without_colon (void)
2e6976a8
DG
3604{
3605 bfd_boolean ret = TRUE;
3606
3607 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3608 {
2e57ce7b 3609 const char *label = input_line_pointer;
2e6976a8
DG
3610
3611 while (!is_end_of_line[(int) label[-1]])
3612 --label;
3613
3614 if (*label == '.')
3615 {
3616 as_bad (_("Invalid label '%s'"), label);
3617 ret = FALSE;
3618 }
3619
3620 asmfunc_debug (label);
3621
3622 asmfunc_state = WAITING_ENDASMFUNC;
3623 }
3624
3625 return ret;
3626}
3627
c19d1205 3628/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3629 a later date assign it a value. That's what these functions do. */
e16bb312 3630
c19d1205
ZW
3631static void
3632symbol_locate (symbolS * symbolP,
3633 const char * name, /* It is copied, the caller can modify. */
3634 segT segment, /* Segment identifier (SEG_<something>). */
3635 valueT valu, /* Symbol value. */
3636 fragS * frag) /* Associated fragment. */
3637{
e57e6ddc 3638 size_t name_length;
c19d1205 3639 char * preserved_copy_of_name;
e16bb312 3640
c19d1205
ZW
3641 name_length = strlen (name) + 1; /* +1 for \0. */
3642 obstack_grow (&notes, name, name_length);
21d799b5 3643 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3644
c19d1205
ZW
3645#ifdef tc_canonicalize_symbol_name
3646 preserved_copy_of_name =
3647 tc_canonicalize_symbol_name (preserved_copy_of_name);
3648#endif
b99bd4ef 3649
c19d1205 3650 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3651
c19d1205
ZW
3652 S_SET_SEGMENT (symbolP, segment);
3653 S_SET_VALUE (symbolP, valu);
3654 symbol_clear_list_pointers (symbolP);
b99bd4ef 3655
c19d1205 3656 symbol_set_frag (symbolP, frag);
b99bd4ef 3657
c19d1205
ZW
3658 /* Link to end of symbol chain. */
3659 {
3660 extern int symbol_table_frozen;
b99bd4ef 3661
c19d1205
ZW
3662 if (symbol_table_frozen)
3663 abort ();
3664 }
b99bd4ef 3665
c19d1205 3666 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3667
c19d1205 3668 obj_symbol_new_hook (symbolP);
b99bd4ef 3669
c19d1205
ZW
3670#ifdef tc_symbol_new_hook
3671 tc_symbol_new_hook (symbolP);
3672#endif
3673
3674#ifdef DEBUG_SYMS
3675 verify_symbol_chain (symbol_rootP, symbol_lastP);
3676#endif /* DEBUG_SYMS */
b99bd4ef
NC
3677}
3678
c19d1205
ZW
3679static void
3680s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3681{
c19d1205
ZW
3682 unsigned int entry;
3683 literal_pool * pool;
3684 char sym_name[20];
b99bd4ef 3685
c19d1205
ZW
3686 pool = find_literal_pool ();
3687 if (pool == NULL
3688 || pool->symbol == NULL
3689 || pool->next_free_entry == 0)
3690 return;
b99bd4ef 3691
c19d1205
ZW
3692 /* Align pool as you have word accesses.
3693 Only make a frag if we have to. */
3694 if (!need_pass_2)
8335d6aa 3695 frag_align (pool->alignment, 0, 0);
b99bd4ef 3696
c19d1205 3697 record_alignment (now_seg, 2);
b99bd4ef 3698
aaca88ef 3699#ifdef OBJ_ELF
47fc6e36
WN
3700 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3701 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3702#endif
c19d1205 3703 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3704
c19d1205
ZW
3705 symbol_locate (pool->symbol, sym_name, now_seg,
3706 (valueT) frag_now_fix (), frag_now);
3707 symbol_table_insert (pool->symbol);
b99bd4ef 3708
c19d1205 3709 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3710
c19d1205
ZW
3711#if defined OBJ_COFF || defined OBJ_ELF
3712 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3713#endif
6c43fab6 3714
c19d1205 3715 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3716 {
3717#ifdef OBJ_ELF
3718 if (debug_type == DEBUG_DWARF2)
3719 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3720#endif
3721 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3722 emit_expr (&(pool->literals[entry]),
3723 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3724 }
b99bd4ef 3725
c19d1205
ZW
3726 /* Mark the pool as empty. */
3727 pool->next_free_entry = 0;
3728 pool->symbol = NULL;
b99bd4ef
NC
3729}
3730
c19d1205
ZW
3731#ifdef OBJ_ELF
3732/* Forward declarations for functions below, in the MD interface
3733 section. */
3734static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3735static valueT create_unwind_entry (int);
3736static void start_unwind_section (const segT, int);
3737static void add_unwind_opcode (valueT, int);
3738static void flush_pending_unwind (void);
b99bd4ef 3739
c19d1205 3740/* Directives: Data. */
b99bd4ef 3741
c19d1205
ZW
3742static void
3743s_arm_elf_cons (int nbytes)
3744{
3745 expressionS exp;
b99bd4ef 3746
c19d1205
ZW
3747#ifdef md_flush_pending_output
3748 md_flush_pending_output ();
3749#endif
b99bd4ef 3750
c19d1205 3751 if (is_it_end_of_statement ())
b99bd4ef 3752 {
c19d1205
ZW
3753 demand_empty_rest_of_line ();
3754 return;
b99bd4ef
NC
3755 }
3756
c19d1205
ZW
3757#ifdef md_cons_align
3758 md_cons_align (nbytes);
3759#endif
b99bd4ef 3760
c19d1205
ZW
3761 mapping_state (MAP_DATA);
3762 do
b99bd4ef 3763 {
c19d1205
ZW
3764 int reloc;
3765 char *base = input_line_pointer;
b99bd4ef 3766
c19d1205 3767 expression (& exp);
b99bd4ef 3768
c19d1205
ZW
3769 if (exp.X_op != O_symbol)
3770 emit_expr (&exp, (unsigned int) nbytes);
3771 else
3772 {
3773 char *before_reloc = input_line_pointer;
3774 reloc = parse_reloc (&input_line_pointer);
3775 if (reloc == -1)
3776 {
3777 as_bad (_("unrecognized relocation suffix"));
3778 ignore_rest_of_line ();
3779 return;
3780 }
3781 else if (reloc == BFD_RELOC_UNUSED)
3782 emit_expr (&exp, (unsigned int) nbytes);
3783 else
3784 {
21d799b5 3785 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3786 bfd_reloc_type_lookup (stdoutput,
3787 (bfd_reloc_code_real_type) reloc);
c19d1205 3788 int size = bfd_get_reloc_size (howto);
b99bd4ef 3789
2fc8bdac
ZW
3790 if (reloc == BFD_RELOC_ARM_PLT32)
3791 {
3792 as_bad (_("(plt) is only valid on branch targets"));
3793 reloc = BFD_RELOC_UNUSED;
3794 size = 0;
3795 }
3796
c19d1205 3797 if (size > nbytes)
992a06ee
AM
3798 as_bad (ngettext ("%s relocations do not fit in %d byte",
3799 "%s relocations do not fit in %d bytes",
3800 nbytes),
c19d1205
ZW
3801 howto->name, nbytes);
3802 else
3803 {
3804 /* We've parsed an expression stopping at O_symbol.
3805 But there may be more expression left now that we
3806 have parsed the relocation marker. Parse it again.
3807 XXX Surely there is a cleaner way to do this. */
3808 char *p = input_line_pointer;
3809 int offset;
325801bd 3810 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3811
c19d1205
ZW
3812 memcpy (save_buf, base, input_line_pointer - base);
3813 memmove (base + (input_line_pointer - before_reloc),
3814 base, before_reloc - base);
3815
3816 input_line_pointer = base + (input_line_pointer-before_reloc);
3817 expression (&exp);
3818 memcpy (base, save_buf, p - base);
3819
3820 offset = nbytes - size;
4b1a927e
AM
3821 p = frag_more (nbytes);
3822 memset (p, 0, nbytes);
c19d1205 3823 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3824 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3825 free (save_buf);
c19d1205
ZW
3826 }
3827 }
3828 }
b99bd4ef 3829 }
c19d1205 3830 while (*input_line_pointer++ == ',');
b99bd4ef 3831
c19d1205
ZW
3832 /* Put terminator back into stream. */
3833 input_line_pointer --;
3834 demand_empty_rest_of_line ();
b99bd4ef
NC
3835}
3836
c921be7d
NC
3837/* Emit an expression containing a 32-bit thumb instruction.
3838 Implementation based on put_thumb32_insn. */
3839
3840static void
3841emit_thumb32_expr (expressionS * exp)
3842{
3843 expressionS exp_high = *exp;
3844
3845 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3846 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3847 exp->X_add_number &= 0xffff;
3848 emit_expr (exp, (unsigned int) THUMB_SIZE);
3849}
3850
3851/* Guess the instruction size based on the opcode. */
3852
3853static int
3854thumb_insn_size (int opcode)
3855{
3856 if ((unsigned int) opcode < 0xe800u)
3857 return 2;
3858 else if ((unsigned int) opcode >= 0xe8000000u)
3859 return 4;
3860 else
3861 return 0;
3862}
3863
3864static bfd_boolean
3865emit_insn (expressionS *exp, int nbytes)
3866{
3867 int size = 0;
3868
3869 if (exp->X_op == O_constant)
3870 {
3871 size = nbytes;
3872
3873 if (size == 0)
3874 size = thumb_insn_size (exp->X_add_number);
3875
3876 if (size != 0)
3877 {
3878 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3879 {
3880 as_bad (_(".inst.n operand too big. "\
3881 "Use .inst.w instead"));
3882 size = 0;
3883 }
3884 else
3885 {
5ee91343
AV
3886 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3887 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 3888 else
5ee91343 3889 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
3890
3891 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3892 emit_thumb32_expr (exp);
3893 else
3894 emit_expr (exp, (unsigned int) size);
3895
3896 it_fsm_post_encode ();
3897 }
3898 }
3899 else
3900 as_bad (_("cannot determine Thumb instruction size. " \
3901 "Use .inst.n/.inst.w instead"));
3902 }
3903 else
3904 as_bad (_("constant expression required"));
3905
3906 return (size != 0);
3907}
3908
3909/* Like s_arm_elf_cons but do not use md_cons_align and
3910 set the mapping state to MAP_ARM/MAP_THUMB. */
3911
3912static void
3913s_arm_elf_inst (int nbytes)
3914{
3915 if (is_it_end_of_statement ())
3916 {
3917 demand_empty_rest_of_line ();
3918 return;
3919 }
3920
3921 /* Calling mapping_state () here will not change ARM/THUMB,
3922 but will ensure not to be in DATA state. */
3923
3924 if (thumb_mode)
3925 mapping_state (MAP_THUMB);
3926 else
3927 {
3928 if (nbytes != 0)
3929 {
3930 as_bad (_("width suffixes are invalid in ARM mode"));
3931 ignore_rest_of_line ();
3932 return;
3933 }
3934
3935 nbytes = 4;
3936
3937 mapping_state (MAP_ARM);
3938 }
3939
3940 do
3941 {
3942 expressionS exp;
3943
3944 expression (& exp);
3945
3946 if (! emit_insn (& exp, nbytes))
3947 {
3948 ignore_rest_of_line ();
3949 return;
3950 }
3951 }
3952 while (*input_line_pointer++ == ',');
3953
3954 /* Put terminator back into stream. */
3955 input_line_pointer --;
3956 demand_empty_rest_of_line ();
3957}
b99bd4ef 3958
c19d1205 3959/* Parse a .rel31 directive. */
b99bd4ef 3960
c19d1205
ZW
3961static void
3962s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3963{
3964 expressionS exp;
3965 char *p;
3966 valueT highbit;
b99bd4ef 3967
c19d1205
ZW
3968 highbit = 0;
3969 if (*input_line_pointer == '1')
3970 highbit = 0x80000000;
3971 else if (*input_line_pointer != '0')
3972 as_bad (_("expected 0 or 1"));
b99bd4ef 3973
c19d1205
ZW
3974 input_line_pointer++;
3975 if (*input_line_pointer != ',')
3976 as_bad (_("missing comma"));
3977 input_line_pointer++;
b99bd4ef 3978
c19d1205
ZW
3979#ifdef md_flush_pending_output
3980 md_flush_pending_output ();
3981#endif
b99bd4ef 3982
c19d1205
ZW
3983#ifdef md_cons_align
3984 md_cons_align (4);
3985#endif
b99bd4ef 3986
c19d1205 3987 mapping_state (MAP_DATA);
b99bd4ef 3988
c19d1205 3989 expression (&exp);
b99bd4ef 3990
c19d1205
ZW
3991 p = frag_more (4);
3992 md_number_to_chars (p, highbit, 4);
3993 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3994 BFD_RELOC_ARM_PREL31);
b99bd4ef 3995
c19d1205 3996 demand_empty_rest_of_line ();
b99bd4ef
NC
3997}
3998
c19d1205 3999/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4000
c19d1205 4001/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4002
c19d1205
ZW
4003static void
4004s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4005{
4006 demand_empty_rest_of_line ();
921e5f0a
PB
4007 if (unwind.proc_start)
4008 {
c921be7d 4009 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4010 return;
4011 }
4012
c19d1205
ZW
4013 /* Mark the start of the function. */
4014 unwind.proc_start = expr_build_dot ();
b99bd4ef 4015
c19d1205
ZW
4016 /* Reset the rest of the unwind info. */
4017 unwind.opcode_count = 0;
4018 unwind.table_entry = NULL;
4019 unwind.personality_routine = NULL;
4020 unwind.personality_index = -1;
4021 unwind.frame_size = 0;
4022 unwind.fp_offset = 0;
fdfde340 4023 unwind.fp_reg = REG_SP;
c19d1205
ZW
4024 unwind.fp_used = 0;
4025 unwind.sp_restored = 0;
4026}
b99bd4ef 4027
b99bd4ef 4028
c19d1205
ZW
4029/* Parse a handlerdata directive. Creates the exception handling table entry
4030 for the function. */
b99bd4ef 4031
c19d1205
ZW
4032static void
4033s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4034{
4035 demand_empty_rest_of_line ();
921e5f0a 4036 if (!unwind.proc_start)
c921be7d 4037 as_bad (MISSING_FNSTART);
921e5f0a 4038
c19d1205 4039 if (unwind.table_entry)
6decc662 4040 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4041
c19d1205
ZW
4042 create_unwind_entry (1);
4043}
a737bd4d 4044
c19d1205 4045/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4046
c19d1205
ZW
4047static void
4048s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4049{
4050 long where;
4051 char *ptr;
4052 valueT val;
940b5ce0 4053 unsigned int marked_pr_dependency;
f02232aa 4054
c19d1205 4055 demand_empty_rest_of_line ();
f02232aa 4056
921e5f0a
PB
4057 if (!unwind.proc_start)
4058 {
c921be7d 4059 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4060 return;
4061 }
4062
c19d1205
ZW
4063 /* Add eh table entry. */
4064 if (unwind.table_entry == NULL)
4065 val = create_unwind_entry (0);
4066 else
4067 val = 0;
f02232aa 4068
c19d1205
ZW
4069 /* Add index table entry. This is two words. */
4070 start_unwind_section (unwind.saved_seg, 1);
4071 frag_align (2, 0, 0);
4072 record_alignment (now_seg, 2);
b99bd4ef 4073
c19d1205 4074 ptr = frag_more (8);
5011093d 4075 memset (ptr, 0, 8);
c19d1205 4076 where = frag_now_fix () - 8;
f02232aa 4077
c19d1205
ZW
4078 /* Self relative offset of the function start. */
4079 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4080 BFD_RELOC_ARM_PREL31);
f02232aa 4081
c19d1205
ZW
4082 /* Indicate dependency on EHABI-defined personality routines to the
4083 linker, if it hasn't been done already. */
940b5ce0
DJ
4084 marked_pr_dependency
4085 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4086 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4087 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4088 {
5f4273c7
NC
4089 static const char *const name[] =
4090 {
4091 "__aeabi_unwind_cpp_pr0",
4092 "__aeabi_unwind_cpp_pr1",
4093 "__aeabi_unwind_cpp_pr2"
4094 };
c19d1205
ZW
4095 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4096 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4097 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4098 |= 1 << unwind.personality_index;
c19d1205 4099 }
f02232aa 4100
c19d1205
ZW
4101 if (val)
4102 /* Inline exception table entry. */
4103 md_number_to_chars (ptr + 4, val, 4);
4104 else
4105 /* Self relative offset of the table entry. */
4106 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4107 BFD_RELOC_ARM_PREL31);
f02232aa 4108
c19d1205
ZW
4109 /* Restore the original section. */
4110 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4111
4112 unwind.proc_start = NULL;
c19d1205 4113}
f02232aa 4114
f02232aa 4115
c19d1205 4116/* Parse an unwind_cantunwind directive. */
b99bd4ef 4117
c19d1205
ZW
4118static void
4119s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4120{
4121 demand_empty_rest_of_line ();
921e5f0a 4122 if (!unwind.proc_start)
c921be7d 4123 as_bad (MISSING_FNSTART);
921e5f0a 4124
c19d1205
ZW
4125 if (unwind.personality_routine || unwind.personality_index != -1)
4126 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4127
c19d1205
ZW
4128 unwind.personality_index = -2;
4129}
b99bd4ef 4130
b99bd4ef 4131
c19d1205 4132/* Parse a personalityindex directive. */
b99bd4ef 4133
c19d1205
ZW
4134static void
4135s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4136{
4137 expressionS exp;
b99bd4ef 4138
921e5f0a 4139 if (!unwind.proc_start)
c921be7d 4140 as_bad (MISSING_FNSTART);
921e5f0a 4141
c19d1205
ZW
4142 if (unwind.personality_routine || unwind.personality_index != -1)
4143 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4144
c19d1205 4145 expression (&exp);
b99bd4ef 4146
c19d1205
ZW
4147 if (exp.X_op != O_constant
4148 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4149 {
c19d1205
ZW
4150 as_bad (_("bad personality routine number"));
4151 ignore_rest_of_line ();
4152 return;
b99bd4ef
NC
4153 }
4154
c19d1205 4155 unwind.personality_index = exp.X_add_number;
b99bd4ef 4156
c19d1205
ZW
4157 demand_empty_rest_of_line ();
4158}
e16bb312 4159
e16bb312 4160
c19d1205 4161/* Parse a personality directive. */
e16bb312 4162
c19d1205
ZW
4163static void
4164s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4165{
4166 char *name, *p, c;
a737bd4d 4167
921e5f0a 4168 if (!unwind.proc_start)
c921be7d 4169 as_bad (MISSING_FNSTART);
921e5f0a 4170
c19d1205
ZW
4171 if (unwind.personality_routine || unwind.personality_index != -1)
4172 as_bad (_("duplicate .personality directive"));
a737bd4d 4173
d02603dc 4174 c = get_symbol_name (& name);
c19d1205 4175 p = input_line_pointer;
d02603dc
NC
4176 if (c == '"')
4177 ++ input_line_pointer;
c19d1205
ZW
4178 unwind.personality_routine = symbol_find_or_make (name);
4179 *p = c;
4180 demand_empty_rest_of_line ();
4181}
e16bb312 4182
e16bb312 4183
c19d1205 4184/* Parse a directive saving core registers. */
e16bb312 4185
c19d1205
ZW
4186static void
4187s_arm_unwind_save_core (void)
e16bb312 4188{
c19d1205
ZW
4189 valueT op;
4190 long range;
4191 int n;
e16bb312 4192
4b5a202f 4193 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4194 if (range == FAIL)
e16bb312 4195 {
c19d1205
ZW
4196 as_bad (_("expected register list"));
4197 ignore_rest_of_line ();
4198 return;
4199 }
e16bb312 4200
c19d1205 4201 demand_empty_rest_of_line ();
e16bb312 4202
c19d1205
ZW
4203 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4204 into .unwind_save {..., sp...}. We aren't bothered about the value of
4205 ip because it is clobbered by calls. */
4206 if (unwind.sp_restored && unwind.fp_reg == 12
4207 && (range & 0x3000) == 0x1000)
4208 {
4209 unwind.opcode_count--;
4210 unwind.sp_restored = 0;
4211 range = (range | 0x2000) & ~0x1000;
4212 unwind.pending_offset = 0;
4213 }
e16bb312 4214
01ae4198
DJ
4215 /* Pop r4-r15. */
4216 if (range & 0xfff0)
c19d1205 4217 {
01ae4198
DJ
4218 /* See if we can use the short opcodes. These pop a block of up to 8
4219 registers starting with r4, plus maybe r14. */
4220 for (n = 0; n < 8; n++)
4221 {
4222 /* Break at the first non-saved register. */
4223 if ((range & (1 << (n + 4))) == 0)
4224 break;
4225 }
4226 /* See if there are any other bits set. */
4227 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4228 {
4229 /* Use the long form. */
4230 op = 0x8000 | ((range >> 4) & 0xfff);
4231 add_unwind_opcode (op, 2);
4232 }
0dd132b6 4233 else
01ae4198
DJ
4234 {
4235 /* Use the short form. */
4236 if (range & 0x4000)
4237 op = 0xa8; /* Pop r14. */
4238 else
4239 op = 0xa0; /* Do not pop r14. */
4240 op |= (n - 1);
4241 add_unwind_opcode (op, 1);
4242 }
c19d1205 4243 }
0dd132b6 4244
c19d1205
ZW
4245 /* Pop r0-r3. */
4246 if (range & 0xf)
4247 {
4248 op = 0xb100 | (range & 0xf);
4249 add_unwind_opcode (op, 2);
0dd132b6
NC
4250 }
4251
c19d1205
ZW
4252 /* Record the number of bytes pushed. */
4253 for (n = 0; n < 16; n++)
4254 {
4255 if (range & (1 << n))
4256 unwind.frame_size += 4;
4257 }
0dd132b6
NC
4258}
4259
c19d1205
ZW
4260
4261/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4262
4263static void
c19d1205 4264s_arm_unwind_save_fpa (int reg)
b99bd4ef 4265{
c19d1205
ZW
4266 expressionS exp;
4267 int num_regs;
4268 valueT op;
b99bd4ef 4269
c19d1205
ZW
4270 /* Get Number of registers to transfer. */
4271 if (skip_past_comma (&input_line_pointer) != FAIL)
4272 expression (&exp);
4273 else
4274 exp.X_op = O_illegal;
b99bd4ef 4275
c19d1205 4276 if (exp.X_op != O_constant)
b99bd4ef 4277 {
c19d1205
ZW
4278 as_bad (_("expected , <constant>"));
4279 ignore_rest_of_line ();
b99bd4ef
NC
4280 return;
4281 }
4282
c19d1205
ZW
4283 num_regs = exp.X_add_number;
4284
4285 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4286 {
c19d1205
ZW
4287 as_bad (_("number of registers must be in the range [1:4]"));
4288 ignore_rest_of_line ();
b99bd4ef
NC
4289 return;
4290 }
4291
c19d1205 4292 demand_empty_rest_of_line ();
b99bd4ef 4293
c19d1205
ZW
4294 if (reg == 4)
4295 {
4296 /* Short form. */
4297 op = 0xb4 | (num_regs - 1);
4298 add_unwind_opcode (op, 1);
4299 }
b99bd4ef
NC
4300 else
4301 {
c19d1205
ZW
4302 /* Long form. */
4303 op = 0xc800 | (reg << 4) | (num_regs - 1);
4304 add_unwind_opcode (op, 2);
b99bd4ef 4305 }
c19d1205 4306 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4307}
4308
c19d1205 4309
fa073d69
MS
4310/* Parse a directive saving VFP registers for ARMv6 and above. */
4311
4312static void
4313s_arm_unwind_save_vfp_armv6 (void)
4314{
4315 int count;
4316 unsigned int start;
4317 valueT op;
4318 int num_vfpv3_regs = 0;
4319 int num_regs_below_16;
efd6b359 4320 bfd_boolean partial_match;
fa073d69 4321
efd6b359
AV
4322 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4323 &partial_match);
fa073d69
MS
4324 if (count == FAIL)
4325 {
4326 as_bad (_("expected register list"));
4327 ignore_rest_of_line ();
4328 return;
4329 }
4330
4331 demand_empty_rest_of_line ();
4332
4333 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4334 than FSTMX/FLDMX-style ones). */
4335
4336 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4337 if (start >= 16)
4338 num_vfpv3_regs = count;
4339 else if (start + count > 16)
4340 num_vfpv3_regs = start + count - 16;
4341
4342 if (num_vfpv3_regs > 0)
4343 {
4344 int start_offset = start > 16 ? start - 16 : 0;
4345 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4346 add_unwind_opcode (op, 2);
4347 }
4348
4349 /* Generate opcode for registers numbered in the range 0 .. 15. */
4350 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4351 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4352 if (num_regs_below_16 > 0)
4353 {
4354 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4355 add_unwind_opcode (op, 2);
4356 }
4357
4358 unwind.frame_size += count * 8;
4359}
4360
4361
4362/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4363
4364static void
c19d1205 4365s_arm_unwind_save_vfp (void)
b99bd4ef 4366{
c19d1205 4367 int count;
ca3f61f7 4368 unsigned int reg;
c19d1205 4369 valueT op;
efd6b359 4370 bfd_boolean partial_match;
b99bd4ef 4371
efd6b359
AV
4372 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4373 &partial_match);
c19d1205 4374 if (count == FAIL)
b99bd4ef 4375 {
c19d1205
ZW
4376 as_bad (_("expected register list"));
4377 ignore_rest_of_line ();
b99bd4ef
NC
4378 return;
4379 }
4380
c19d1205 4381 demand_empty_rest_of_line ();
b99bd4ef 4382
c19d1205 4383 if (reg == 8)
b99bd4ef 4384 {
c19d1205
ZW
4385 /* Short form. */
4386 op = 0xb8 | (count - 1);
4387 add_unwind_opcode (op, 1);
b99bd4ef 4388 }
c19d1205 4389 else
b99bd4ef 4390 {
c19d1205
ZW
4391 /* Long form. */
4392 op = 0xb300 | (reg << 4) | (count - 1);
4393 add_unwind_opcode (op, 2);
b99bd4ef 4394 }
c19d1205
ZW
4395 unwind.frame_size += count * 8 + 4;
4396}
b99bd4ef 4397
b99bd4ef 4398
c19d1205
ZW
4399/* Parse a directive saving iWMMXt data registers. */
4400
4401static void
4402s_arm_unwind_save_mmxwr (void)
4403{
4404 int reg;
4405 int hi_reg;
4406 int i;
4407 unsigned mask = 0;
4408 valueT op;
b99bd4ef 4409
c19d1205
ZW
4410 if (*input_line_pointer == '{')
4411 input_line_pointer++;
b99bd4ef 4412
c19d1205 4413 do
b99bd4ef 4414 {
dcbf9037 4415 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4416
c19d1205 4417 if (reg == FAIL)
b99bd4ef 4418 {
9b7132d3 4419 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4420 goto error;
b99bd4ef
NC
4421 }
4422
c19d1205
ZW
4423 if (mask >> reg)
4424 as_tsktsk (_("register list not in ascending order"));
4425 mask |= 1 << reg;
b99bd4ef 4426
c19d1205
ZW
4427 if (*input_line_pointer == '-')
4428 {
4429 input_line_pointer++;
dcbf9037 4430 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4431 if (hi_reg == FAIL)
4432 {
9b7132d3 4433 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4434 goto error;
4435 }
4436 else if (reg >= hi_reg)
4437 {
4438 as_bad (_("bad register range"));
4439 goto error;
4440 }
4441 for (; reg < hi_reg; reg++)
4442 mask |= 1 << reg;
4443 }
4444 }
4445 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4446
d996d970 4447 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4448
c19d1205 4449 demand_empty_rest_of_line ();
b99bd4ef 4450
708587a4 4451 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4452 the list. */
4453 flush_pending_unwind ();
b99bd4ef 4454
c19d1205 4455 for (i = 0; i < 16; i++)
b99bd4ef 4456 {
c19d1205
ZW
4457 if (mask & (1 << i))
4458 unwind.frame_size += 8;
b99bd4ef
NC
4459 }
4460
c19d1205
ZW
4461 /* Attempt to combine with a previous opcode. We do this because gcc
4462 likes to output separate unwind directives for a single block of
4463 registers. */
4464 if (unwind.opcode_count > 0)
b99bd4ef 4465 {
c19d1205
ZW
4466 i = unwind.opcodes[unwind.opcode_count - 1];
4467 if ((i & 0xf8) == 0xc0)
4468 {
4469 i &= 7;
4470 /* Only merge if the blocks are contiguous. */
4471 if (i < 6)
4472 {
4473 if ((mask & 0xfe00) == (1 << 9))
4474 {
4475 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4476 unwind.opcode_count--;
4477 }
4478 }
4479 else if (i == 6 && unwind.opcode_count >= 2)
4480 {
4481 i = unwind.opcodes[unwind.opcode_count - 2];
4482 reg = i >> 4;
4483 i &= 0xf;
b99bd4ef 4484
c19d1205
ZW
4485 op = 0xffff << (reg - 1);
4486 if (reg > 0
87a1fd79 4487 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4488 {
4489 op = (1 << (reg + i + 1)) - 1;
4490 op &= ~((1 << reg) - 1);
4491 mask |= op;
4492 unwind.opcode_count -= 2;
4493 }
4494 }
4495 }
b99bd4ef
NC
4496 }
4497
c19d1205
ZW
4498 hi_reg = 15;
4499 /* We want to generate opcodes in the order the registers have been
4500 saved, ie. descending order. */
4501 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4502 {
c19d1205
ZW
4503 /* Save registers in blocks. */
4504 if (reg < 0
4505 || !(mask & (1 << reg)))
4506 {
4507 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4508 preceding block. */
c19d1205
ZW
4509 if (reg != hi_reg)
4510 {
4511 if (reg == 9)
4512 {
4513 /* Short form. */
4514 op = 0xc0 | (hi_reg - 10);
4515 add_unwind_opcode (op, 1);
4516 }
4517 else
4518 {
4519 /* Long form. */
4520 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4521 add_unwind_opcode (op, 2);
4522 }
4523 }
4524 hi_reg = reg - 1;
4525 }
b99bd4ef
NC
4526 }
4527
c19d1205
ZW
4528 return;
4529error:
4530 ignore_rest_of_line ();
b99bd4ef
NC
4531}
4532
4533static void
c19d1205 4534s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4535{
c19d1205
ZW
4536 int reg;
4537 int hi_reg;
4538 unsigned mask = 0;
4539 valueT op;
b99bd4ef 4540
c19d1205
ZW
4541 if (*input_line_pointer == '{')
4542 input_line_pointer++;
b99bd4ef 4543
477330fc
RM
4544 skip_whitespace (input_line_pointer);
4545
c19d1205 4546 do
b99bd4ef 4547 {
dcbf9037 4548 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4549
c19d1205
ZW
4550 if (reg == FAIL)
4551 {
9b7132d3 4552 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4553 goto error;
4554 }
b99bd4ef 4555
c19d1205
ZW
4556 reg -= 8;
4557 if (mask >> reg)
4558 as_tsktsk (_("register list not in ascending order"));
4559 mask |= 1 << reg;
b99bd4ef 4560
c19d1205
ZW
4561 if (*input_line_pointer == '-')
4562 {
4563 input_line_pointer++;
dcbf9037 4564 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4565 if (hi_reg == FAIL)
4566 {
9b7132d3 4567 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4568 goto error;
4569 }
4570 else if (reg >= hi_reg)
4571 {
4572 as_bad (_("bad register range"));
4573 goto error;
4574 }
4575 for (; reg < hi_reg; reg++)
4576 mask |= 1 << reg;
4577 }
b99bd4ef 4578 }
c19d1205 4579 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4580
d996d970 4581 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4582
c19d1205
ZW
4583 demand_empty_rest_of_line ();
4584
708587a4 4585 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4586 the list. */
4587 flush_pending_unwind ();
b99bd4ef 4588
c19d1205 4589 for (reg = 0; reg < 16; reg++)
b99bd4ef 4590 {
c19d1205
ZW
4591 if (mask & (1 << reg))
4592 unwind.frame_size += 4;
b99bd4ef 4593 }
c19d1205
ZW
4594 op = 0xc700 | mask;
4595 add_unwind_opcode (op, 2);
4596 return;
4597error:
4598 ignore_rest_of_line ();
b99bd4ef
NC
4599}
4600
c19d1205 4601
fa073d69
MS
4602/* Parse an unwind_save directive.
4603 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4604
b99bd4ef 4605static void
fa073d69 4606s_arm_unwind_save (int arch_v6)
b99bd4ef 4607{
c19d1205
ZW
4608 char *peek;
4609 struct reg_entry *reg;
4610 bfd_boolean had_brace = FALSE;
b99bd4ef 4611
921e5f0a 4612 if (!unwind.proc_start)
c921be7d 4613 as_bad (MISSING_FNSTART);
921e5f0a 4614
c19d1205
ZW
4615 /* Figure out what sort of save we have. */
4616 peek = input_line_pointer;
b99bd4ef 4617
c19d1205 4618 if (*peek == '{')
b99bd4ef 4619 {
c19d1205
ZW
4620 had_brace = TRUE;
4621 peek++;
b99bd4ef
NC
4622 }
4623
c19d1205 4624 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4625
c19d1205 4626 if (!reg)
b99bd4ef 4627 {
c19d1205
ZW
4628 as_bad (_("register expected"));
4629 ignore_rest_of_line ();
b99bd4ef
NC
4630 return;
4631 }
4632
c19d1205 4633 switch (reg->type)
b99bd4ef 4634 {
c19d1205
ZW
4635 case REG_TYPE_FN:
4636 if (had_brace)
4637 {
4638 as_bad (_("FPA .unwind_save does not take a register list"));
4639 ignore_rest_of_line ();
4640 return;
4641 }
93ac2687 4642 input_line_pointer = peek;
c19d1205 4643 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4644 return;
c19d1205 4645
1f5afe1c
NC
4646 case REG_TYPE_RN:
4647 s_arm_unwind_save_core ();
4648 return;
4649
fa073d69
MS
4650 case REG_TYPE_VFD:
4651 if (arch_v6)
477330fc 4652 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4653 else
477330fc 4654 s_arm_unwind_save_vfp ();
fa073d69 4655 return;
1f5afe1c
NC
4656
4657 case REG_TYPE_MMXWR:
4658 s_arm_unwind_save_mmxwr ();
4659 return;
4660
4661 case REG_TYPE_MMXWCG:
4662 s_arm_unwind_save_mmxwcg ();
4663 return;
c19d1205
ZW
4664
4665 default:
4666 as_bad (_(".unwind_save does not support this kind of register"));
4667 ignore_rest_of_line ();
b99bd4ef 4668 }
c19d1205 4669}
b99bd4ef 4670
b99bd4ef 4671
c19d1205
ZW
4672/* Parse an unwind_movsp directive. */
4673
4674static void
4675s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4676{
4677 int reg;
4678 valueT op;
4fa3602b 4679 int offset;
c19d1205 4680
921e5f0a 4681 if (!unwind.proc_start)
c921be7d 4682 as_bad (MISSING_FNSTART);
921e5f0a 4683
dcbf9037 4684 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4685 if (reg == FAIL)
b99bd4ef 4686 {
9b7132d3 4687 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4688 ignore_rest_of_line ();
b99bd4ef
NC
4689 return;
4690 }
4fa3602b
PB
4691
4692 /* Optional constant. */
4693 if (skip_past_comma (&input_line_pointer) != FAIL)
4694 {
4695 if (immediate_for_directive (&offset) == FAIL)
4696 return;
4697 }
4698 else
4699 offset = 0;
4700
c19d1205 4701 demand_empty_rest_of_line ();
b99bd4ef 4702
c19d1205 4703 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4704 {
c19d1205 4705 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4706 return;
4707 }
4708
c19d1205
ZW
4709 if (unwind.fp_reg != REG_SP)
4710 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4711
c19d1205
ZW
4712 /* Generate opcode to restore the value. */
4713 op = 0x90 | reg;
4714 add_unwind_opcode (op, 1);
4715
4716 /* Record the information for later. */
4717 unwind.fp_reg = reg;
4fa3602b 4718 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4719 unwind.sp_restored = 1;
b05fe5cf
ZW
4720}
4721
c19d1205
ZW
4722/* Parse an unwind_pad directive. */
4723
b05fe5cf 4724static void
c19d1205 4725s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4726{
c19d1205 4727 int offset;
b05fe5cf 4728
921e5f0a 4729 if (!unwind.proc_start)
c921be7d 4730 as_bad (MISSING_FNSTART);
921e5f0a 4731
c19d1205
ZW
4732 if (immediate_for_directive (&offset) == FAIL)
4733 return;
b99bd4ef 4734
c19d1205
ZW
4735 if (offset & 3)
4736 {
4737 as_bad (_("stack increment must be multiple of 4"));
4738 ignore_rest_of_line ();
4739 return;
4740 }
b99bd4ef 4741
c19d1205
ZW
4742 /* Don't generate any opcodes, just record the details for later. */
4743 unwind.frame_size += offset;
4744 unwind.pending_offset += offset;
4745
4746 demand_empty_rest_of_line ();
4747}
4748
4749/* Parse an unwind_setfp directive. */
4750
4751static void
4752s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4753{
c19d1205
ZW
4754 int sp_reg;
4755 int fp_reg;
4756 int offset;
4757
921e5f0a 4758 if (!unwind.proc_start)
c921be7d 4759 as_bad (MISSING_FNSTART);
921e5f0a 4760
dcbf9037 4761 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4762 if (skip_past_comma (&input_line_pointer) == FAIL)
4763 sp_reg = FAIL;
4764 else
dcbf9037 4765 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4766
c19d1205
ZW
4767 if (fp_reg == FAIL || sp_reg == FAIL)
4768 {
4769 as_bad (_("expected <reg>, <reg>"));
4770 ignore_rest_of_line ();
4771 return;
4772 }
b99bd4ef 4773
c19d1205
ZW
4774 /* Optional constant. */
4775 if (skip_past_comma (&input_line_pointer) != FAIL)
4776 {
4777 if (immediate_for_directive (&offset) == FAIL)
4778 return;
4779 }
4780 else
4781 offset = 0;
a737bd4d 4782
c19d1205 4783 demand_empty_rest_of_line ();
a737bd4d 4784
fdfde340 4785 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4786 {
c19d1205
ZW
4787 as_bad (_("register must be either sp or set by a previous"
4788 "unwind_movsp directive"));
4789 return;
a737bd4d
NC
4790 }
4791
c19d1205
ZW
4792 /* Don't generate any opcodes, just record the information for later. */
4793 unwind.fp_reg = fp_reg;
4794 unwind.fp_used = 1;
fdfde340 4795 if (sp_reg == REG_SP)
c19d1205
ZW
4796 unwind.fp_offset = unwind.frame_size - offset;
4797 else
4798 unwind.fp_offset -= offset;
a737bd4d
NC
4799}
4800
c19d1205
ZW
4801/* Parse an unwind_raw directive. */
4802
4803static void
4804s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4805{
c19d1205 4806 expressionS exp;
708587a4 4807 /* This is an arbitrary limit. */
c19d1205
ZW
4808 unsigned char op[16];
4809 int count;
a737bd4d 4810
921e5f0a 4811 if (!unwind.proc_start)
c921be7d 4812 as_bad (MISSING_FNSTART);
921e5f0a 4813
c19d1205
ZW
4814 expression (&exp);
4815 if (exp.X_op == O_constant
4816 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4817 {
c19d1205
ZW
4818 unwind.frame_size += exp.X_add_number;
4819 expression (&exp);
4820 }
4821 else
4822 exp.X_op = O_illegal;
a737bd4d 4823
c19d1205
ZW
4824 if (exp.X_op != O_constant)
4825 {
4826 as_bad (_("expected <offset>, <opcode>"));
4827 ignore_rest_of_line ();
4828 return;
4829 }
a737bd4d 4830
c19d1205 4831 count = 0;
a737bd4d 4832
c19d1205
ZW
4833 /* Parse the opcode. */
4834 for (;;)
4835 {
4836 if (count >= 16)
4837 {
4838 as_bad (_("unwind opcode too long"));
4839 ignore_rest_of_line ();
a737bd4d 4840 }
c19d1205 4841 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4842 {
c19d1205
ZW
4843 as_bad (_("invalid unwind opcode"));
4844 ignore_rest_of_line ();
4845 return;
a737bd4d 4846 }
c19d1205 4847 op[count++] = exp.X_add_number;
a737bd4d 4848
c19d1205
ZW
4849 /* Parse the next byte. */
4850 if (skip_past_comma (&input_line_pointer) == FAIL)
4851 break;
a737bd4d 4852
c19d1205
ZW
4853 expression (&exp);
4854 }
b99bd4ef 4855
c19d1205
ZW
4856 /* Add the opcode bytes in reverse order. */
4857 while (count--)
4858 add_unwind_opcode (op[count], 1);
b99bd4ef 4859
c19d1205 4860 demand_empty_rest_of_line ();
b99bd4ef 4861}
ee065d83
PB
4862
4863
4864/* Parse a .eabi_attribute directive. */
4865
4866static void
4867s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4868{
0420f52b 4869 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4870
3076e594 4871 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4872 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4873}
4874
0855e32b
NS
4875/* Emit a tls fix for the symbol. */
4876
4877static void
4878s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4879{
4880 char *p;
4881 expressionS exp;
4882#ifdef md_flush_pending_output
4883 md_flush_pending_output ();
4884#endif
4885
4886#ifdef md_cons_align
4887 md_cons_align (4);
4888#endif
4889
4890 /* Since we're just labelling the code, there's no need to define a
4891 mapping symbol. */
4892 expression (&exp);
4893 p = obstack_next_free (&frchain_now->frch_obstack);
4894 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4895 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4896 : BFD_RELOC_ARM_TLS_DESCSEQ);
4897}
cdf9ccec 4898#endif /* OBJ_ELF */
0855e32b 4899
ee065d83 4900static void s_arm_arch (int);
7a1d4c38 4901static void s_arm_object_arch (int);
ee065d83
PB
4902static void s_arm_cpu (int);
4903static void s_arm_fpu (int);
69133863 4904static void s_arm_arch_extension (int);
b99bd4ef 4905
f0927246
NC
4906#ifdef TE_PE
4907
4908static void
5f4273c7 4909pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4910{
4911 expressionS exp;
4912
4913 do
4914 {
4915 expression (&exp);
4916 if (exp.X_op == O_symbol)
4917 exp.X_op = O_secrel;
4918
4919 emit_expr (&exp, 4);
4920 }
4921 while (*input_line_pointer++ == ',');
4922
4923 input_line_pointer--;
4924 demand_empty_rest_of_line ();
4925}
4926#endif /* TE_PE */
4927
c19d1205
ZW
4928/* This table describes all the machine specific pseudo-ops the assembler
4929 has to support. The fields are:
4930 pseudo-op name without dot
4931 function to call to execute this pseudo-op
4932 Integer arg to pass to the function. */
b99bd4ef 4933
c19d1205 4934const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4935{
c19d1205
ZW
4936 /* Never called because '.req' does not start a line. */
4937 { "req", s_req, 0 },
dcbf9037
JB
4938 /* Following two are likewise never called. */
4939 { "dn", s_dn, 0 },
4940 { "qn", s_qn, 0 },
c19d1205
ZW
4941 { "unreq", s_unreq, 0 },
4942 { "bss", s_bss, 0 },
db2ed2e0 4943 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4944 { "arm", s_arm, 0 },
4945 { "thumb", s_thumb, 0 },
4946 { "code", s_code, 0 },
4947 { "force_thumb", s_force_thumb, 0 },
4948 { "thumb_func", s_thumb_func, 0 },
4949 { "thumb_set", s_thumb_set, 0 },
4950 { "even", s_even, 0 },
4951 { "ltorg", s_ltorg, 0 },
4952 { "pool", s_ltorg, 0 },
4953 { "syntax", s_syntax, 0 },
8463be01
PB
4954 { "cpu", s_arm_cpu, 0 },
4955 { "arch", s_arm_arch, 0 },
7a1d4c38 4956 { "object_arch", s_arm_object_arch, 0 },
8463be01 4957 { "fpu", s_arm_fpu, 0 },
69133863 4958 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4959#ifdef OBJ_ELF
c921be7d
NC
4960 { "word", s_arm_elf_cons, 4 },
4961 { "long", s_arm_elf_cons, 4 },
4962 { "inst.n", s_arm_elf_inst, 2 },
4963 { "inst.w", s_arm_elf_inst, 4 },
4964 { "inst", s_arm_elf_inst, 0 },
4965 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4966 { "fnstart", s_arm_unwind_fnstart, 0 },
4967 { "fnend", s_arm_unwind_fnend, 0 },
4968 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4969 { "personality", s_arm_unwind_personality, 0 },
4970 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4971 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4972 { "save", s_arm_unwind_save, 0 },
fa073d69 4973 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4974 { "movsp", s_arm_unwind_movsp, 0 },
4975 { "pad", s_arm_unwind_pad, 0 },
4976 { "setfp", s_arm_unwind_setfp, 0 },
4977 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4978 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4979 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4980#else
4981 { "word", cons, 4},
f0927246
NC
4982
4983 /* These are used for dwarf. */
4984 {"2byte", cons, 2},
4985 {"4byte", cons, 4},
4986 {"8byte", cons, 8},
4987 /* These are used for dwarf2. */
68d20676 4988 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4989 { "loc", dwarf2_directive_loc, 0 },
4990 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4991#endif
4992 { "extend", float_cons, 'x' },
4993 { "ldouble", float_cons, 'x' },
4994 { "packed", float_cons, 'p' },
f0927246
NC
4995#ifdef TE_PE
4996 {"secrel32", pe_directive_secrel, 0},
4997#endif
2e6976a8
DG
4998
4999 /* These are for compatibility with CodeComposer Studio. */
5000 {"ref", s_ccs_ref, 0},
5001 {"def", s_ccs_def, 0},
5002 {"asmfunc", s_ccs_asmfunc, 0},
5003 {"endasmfunc", s_ccs_endasmfunc, 0},
5004
c19d1205
ZW
5005 { 0, 0, 0 }
5006};
5007\f
5008/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5009
c19d1205
ZW
5010/* Generic immediate-value read function for use in insn parsing.
5011 STR points to the beginning of the immediate (the leading #);
5012 VAL receives the value; if the value is outside [MIN, MAX]
5013 issue an error. PREFIX_OPT is true if the immediate prefix is
5014 optional. */
b99bd4ef 5015
c19d1205
ZW
5016static int
5017parse_immediate (char **str, int *val, int min, int max,
5018 bfd_boolean prefix_opt)
5019{
5020 expressionS exp;
0198d5e6 5021
c19d1205
ZW
5022 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5023 if (exp.X_op != O_constant)
b99bd4ef 5024 {
c19d1205
ZW
5025 inst.error = _("constant expression required");
5026 return FAIL;
5027 }
b99bd4ef 5028
c19d1205
ZW
5029 if (exp.X_add_number < min || exp.X_add_number > max)
5030 {
5031 inst.error = _("immediate value out of range");
5032 return FAIL;
5033 }
b99bd4ef 5034
c19d1205
ZW
5035 *val = exp.X_add_number;
5036 return SUCCESS;
5037}
b99bd4ef 5038
5287ad62 5039/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5040 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5041 instructions. Puts the result directly in inst.operands[i]. */
5042
5043static int
8335d6aa
JW
5044parse_big_immediate (char **str, int i, expressionS *in_exp,
5045 bfd_boolean allow_symbol_p)
5287ad62
JB
5046{
5047 expressionS exp;
8335d6aa 5048 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5049 char *ptr = *str;
5050
8335d6aa 5051 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5052
8335d6aa 5053 if (exp_p->X_op == O_constant)
036dc3f7 5054 {
8335d6aa 5055 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5056 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5057 O_constant. We have to be careful not to break compilation for
5058 32-bit X_add_number, though. */
8335d6aa 5059 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5060 {
8335d6aa
JW
5061 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5062 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5063 & 0xffffffff);
036dc3f7
PB
5064 inst.operands[i].regisimm = 1;
5065 }
5066 }
8335d6aa
JW
5067 else if (exp_p->X_op == O_big
5068 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5069 {
5070 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5071
5287ad62 5072 /* Bignums have their least significant bits in
477330fc
RM
5073 generic_bignum[0]. Make sure we put 32 bits in imm and
5074 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5075 gas_assert (parts != 0);
95b75c01
NC
5076
5077 /* Make sure that the number is not too big.
5078 PR 11972: Bignums can now be sign-extended to the
5079 size of a .octa so check that the out of range bits
5080 are all zero or all one. */
8335d6aa 5081 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5082 {
5083 LITTLENUM_TYPE m = -1;
5084
5085 if (generic_bignum[parts * 2] != 0
5086 && generic_bignum[parts * 2] != m)
5087 return FAIL;
5088
8335d6aa 5089 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5090 if (generic_bignum[j] != generic_bignum[j-1])
5091 return FAIL;
5092 }
5093
5287ad62
JB
5094 inst.operands[i].imm = 0;
5095 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5096 inst.operands[i].imm |= generic_bignum[idx]
5097 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5098 inst.operands[i].reg = 0;
5099 for (j = 0; j < parts; j++, idx++)
477330fc
RM
5100 inst.operands[i].reg |= generic_bignum[idx]
5101 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
5102 inst.operands[i].regisimm = 1;
5103 }
8335d6aa 5104 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5105 return FAIL;
5f4273c7 5106
5287ad62
JB
5107 *str = ptr;
5108
5109 return SUCCESS;
5110}
5111
c19d1205
ZW
5112/* Returns the pseudo-register number of an FPA immediate constant,
5113 or FAIL if there isn't a valid constant here. */
b99bd4ef 5114
c19d1205
ZW
5115static int
5116parse_fpa_immediate (char ** str)
5117{
5118 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5119 char * save_in;
5120 expressionS exp;
5121 int i;
5122 int j;
b99bd4ef 5123
c19d1205
ZW
5124 /* First try and match exact strings, this is to guarantee
5125 that some formats will work even for cross assembly. */
b99bd4ef 5126
c19d1205
ZW
5127 for (i = 0; fp_const[i]; i++)
5128 {
5129 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5130 {
c19d1205 5131 char *start = *str;
b99bd4ef 5132
c19d1205
ZW
5133 *str += strlen (fp_const[i]);
5134 if (is_end_of_line[(unsigned char) **str])
5135 return i + 8;
5136 *str = start;
5137 }
5138 }
b99bd4ef 5139
c19d1205
ZW
5140 /* Just because we didn't get a match doesn't mean that the constant
5141 isn't valid, just that it is in a format that we don't
5142 automatically recognize. Try parsing it with the standard
5143 expression routines. */
b99bd4ef 5144
c19d1205 5145 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5146
c19d1205
ZW
5147 /* Look for a raw floating point number. */
5148 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5149 && is_end_of_line[(unsigned char) *save_in])
5150 {
5151 for (i = 0; i < NUM_FLOAT_VALS; i++)
5152 {
5153 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5154 {
c19d1205
ZW
5155 if (words[j] != fp_values[i][j])
5156 break;
b99bd4ef
NC
5157 }
5158
c19d1205 5159 if (j == MAX_LITTLENUMS)
b99bd4ef 5160 {
c19d1205
ZW
5161 *str = save_in;
5162 return i + 8;
b99bd4ef
NC
5163 }
5164 }
5165 }
b99bd4ef 5166
c19d1205
ZW
5167 /* Try and parse a more complex expression, this will probably fail
5168 unless the code uses a floating point prefix (eg "0f"). */
5169 save_in = input_line_pointer;
5170 input_line_pointer = *str;
5171 if (expression (&exp) == absolute_section
5172 && exp.X_op == O_big
5173 && exp.X_add_number < 0)
5174 {
5175 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5176 Ditto for 15. */
ba592044
AM
5177#define X_PRECISION 5
5178#define E_PRECISION 15L
5179 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5180 {
5181 for (i = 0; i < NUM_FLOAT_VALS; i++)
5182 {
5183 for (j = 0; j < MAX_LITTLENUMS; j++)
5184 {
5185 if (words[j] != fp_values[i][j])
5186 break;
5187 }
b99bd4ef 5188
c19d1205
ZW
5189 if (j == MAX_LITTLENUMS)
5190 {
5191 *str = input_line_pointer;
5192 input_line_pointer = save_in;
5193 return i + 8;
5194 }
5195 }
5196 }
b99bd4ef
NC
5197 }
5198
c19d1205
ZW
5199 *str = input_line_pointer;
5200 input_line_pointer = save_in;
5201 inst.error = _("invalid FPA immediate expression");
5202 return FAIL;
b99bd4ef
NC
5203}
5204
136da414
JB
5205/* Returns 1 if a number has "quarter-precision" float format
5206 0baBbbbbbc defgh000 00000000 00000000. */
5207
5208static int
5209is_quarter_float (unsigned imm)
5210{
5211 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5212 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5213}
5214
aacf0b33
KT
5215
5216/* Detect the presence of a floating point or integer zero constant,
5217 i.e. #0.0 or #0. */
5218
5219static bfd_boolean
5220parse_ifimm_zero (char **in)
5221{
5222 int error_code;
5223
5224 if (!is_immediate_prefix (**in))
3c6452ae
TP
5225 {
5226 /* In unified syntax, all prefixes are optional. */
5227 if (!unified_syntax)
5228 return FALSE;
5229 }
5230 else
5231 ++*in;
0900a05b
JW
5232
5233 /* Accept #0x0 as a synonym for #0. */
5234 if (strncmp (*in, "0x", 2) == 0)
5235 {
5236 int val;
5237 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5238 return FALSE;
5239 return TRUE;
5240 }
5241
aacf0b33
KT
5242 error_code = atof_generic (in, ".", EXP_CHARS,
5243 &generic_floating_point_number);
5244
5245 if (!error_code
5246 && generic_floating_point_number.sign == '+'
5247 && (generic_floating_point_number.low
5248 > generic_floating_point_number.leader))
5249 return TRUE;
5250
5251 return FALSE;
5252}
5253
136da414
JB
5254/* Parse an 8-bit "quarter-precision" floating point number of the form:
5255 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5256 The zero and minus-zero cases need special handling, since they can't be
5257 encoded in the "quarter-precision" float format, but can nonetheless be
5258 loaded as integer constants. */
136da414
JB
5259
5260static unsigned
5261parse_qfloat_immediate (char **ccp, int *immed)
5262{
5263 char *str = *ccp;
c96612cc 5264 char *fpnum;
136da414 5265 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5266 int found_fpchar = 0;
5f4273c7 5267
136da414 5268 skip_past_char (&str, '#');
5f4273c7 5269
c96612cc
JB
5270 /* We must not accidentally parse an integer as a floating-point number. Make
5271 sure that the value we parse is not an integer by checking for special
5272 characters '.' or 'e'.
5273 FIXME: This is a horrible hack, but doing better is tricky because type
5274 information isn't in a very usable state at parse time. */
5275 fpnum = str;
5276 skip_whitespace (fpnum);
5277
5278 if (strncmp (fpnum, "0x", 2) == 0)
5279 return FAIL;
5280 else
5281 {
5282 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5283 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5284 {
5285 found_fpchar = 1;
5286 break;
5287 }
c96612cc
JB
5288
5289 if (!found_fpchar)
477330fc 5290 return FAIL;
c96612cc 5291 }
5f4273c7 5292
136da414
JB
5293 if ((str = atof_ieee (str, 's', words)) != NULL)
5294 {
5295 unsigned fpword = 0;
5296 int i;
5f4273c7 5297
136da414
JB
5298 /* Our FP word must be 32 bits (single-precision FP). */
5299 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5300 {
5301 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5302 fpword |= words[i];
5303 }
5f4273c7 5304
c96612cc 5305 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5306 *immed = fpword;
136da414 5307 else
477330fc 5308 return FAIL;
136da414
JB
5309
5310 *ccp = str;
5f4273c7 5311
136da414
JB
5312 return SUCCESS;
5313 }
5f4273c7 5314
136da414
JB
5315 return FAIL;
5316}
5317
c19d1205
ZW
5318/* Shift operands. */
5319enum shift_kind
b99bd4ef 5320{
f5f10c66 5321 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5322};
b99bd4ef 5323
c19d1205
ZW
5324struct asm_shift_name
5325{
5326 const char *name;
5327 enum shift_kind kind;
5328};
b99bd4ef 5329
c19d1205
ZW
5330/* Third argument to parse_shift. */
5331enum parse_shift_mode
5332{
5333 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5334 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5335 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5336 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5337 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5338 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5339};
b99bd4ef 5340
c19d1205
ZW
5341/* Parse a <shift> specifier on an ARM data processing instruction.
5342 This has three forms:
b99bd4ef 5343
c19d1205
ZW
5344 (LSL|LSR|ASL|ASR|ROR) Rs
5345 (LSL|LSR|ASL|ASR|ROR) #imm
5346 RRX
b99bd4ef 5347
c19d1205
ZW
5348 Note that ASL is assimilated to LSL in the instruction encoding, and
5349 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5350
c19d1205
ZW
5351static int
5352parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5353{
c19d1205
ZW
5354 const struct asm_shift_name *shift_name;
5355 enum shift_kind shift;
5356 char *s = *str;
5357 char *p = s;
5358 int reg;
b99bd4ef 5359
c19d1205
ZW
5360 for (p = *str; ISALPHA (*p); p++)
5361 ;
b99bd4ef 5362
c19d1205 5363 if (p == *str)
b99bd4ef 5364 {
c19d1205
ZW
5365 inst.error = _("shift expression expected");
5366 return FAIL;
b99bd4ef
NC
5367 }
5368
21d799b5 5369 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5370 p - *str);
c19d1205
ZW
5371
5372 if (shift_name == NULL)
b99bd4ef 5373 {
c19d1205
ZW
5374 inst.error = _("shift expression expected");
5375 return FAIL;
b99bd4ef
NC
5376 }
5377
c19d1205 5378 shift = shift_name->kind;
b99bd4ef 5379
c19d1205
ZW
5380 switch (mode)
5381 {
5382 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5383 case SHIFT_IMMEDIATE:
5384 if (shift == SHIFT_UXTW)
5385 {
5386 inst.error = _("'UXTW' not allowed here");
5387 return FAIL;
5388 }
5389 break;
b99bd4ef 5390
c19d1205
ZW
5391 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5392 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5393 {
5394 inst.error = _("'LSL' or 'ASR' required");
5395 return FAIL;
5396 }
5397 break;
b99bd4ef 5398
c19d1205
ZW
5399 case SHIFT_LSL_IMMEDIATE:
5400 if (shift != SHIFT_LSL)
5401 {
5402 inst.error = _("'LSL' required");
5403 return FAIL;
5404 }
5405 break;
b99bd4ef 5406
c19d1205
ZW
5407 case SHIFT_ASR_IMMEDIATE:
5408 if (shift != SHIFT_ASR)
5409 {
5410 inst.error = _("'ASR' required");
5411 return FAIL;
5412 }
5413 break;
f5f10c66
AV
5414 case SHIFT_UXTW_IMMEDIATE:
5415 if (shift != SHIFT_UXTW)
5416 {
5417 inst.error = _("'UXTW' required");
5418 return FAIL;
5419 }
5420 break;
b99bd4ef 5421
c19d1205
ZW
5422 default: abort ();
5423 }
b99bd4ef 5424
c19d1205
ZW
5425 if (shift != SHIFT_RRX)
5426 {
5427 /* Whitespace can appear here if the next thing is a bare digit. */
5428 skip_whitespace (p);
b99bd4ef 5429
c19d1205 5430 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5431 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5432 {
5433 inst.operands[i].imm = reg;
5434 inst.operands[i].immisreg = 1;
5435 }
e2b0ab59 5436 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5437 return FAIL;
5438 }
5439 inst.operands[i].shift_kind = shift;
5440 inst.operands[i].shifted = 1;
5441 *str = p;
5442 return SUCCESS;
b99bd4ef
NC
5443}
5444
c19d1205 5445/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5446
c19d1205
ZW
5447 #<immediate>
5448 #<immediate>, <rotate>
5449 <Rm>
5450 <Rm>, <shift>
b99bd4ef 5451
c19d1205
ZW
5452 where <shift> is defined by parse_shift above, and <rotate> is a
5453 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5454 is deferred to md_apply_fix. */
b99bd4ef 5455
c19d1205
ZW
5456static int
5457parse_shifter_operand (char **str, int i)
5458{
5459 int value;
91d6fa6a 5460 expressionS exp;
b99bd4ef 5461
dcbf9037 5462 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5463 {
5464 inst.operands[i].reg = value;
5465 inst.operands[i].isreg = 1;
b99bd4ef 5466
c19d1205 5467 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5468 inst.relocs[0].exp.X_op = O_constant;
5469 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5470
c19d1205
ZW
5471 if (skip_past_comma (str) == FAIL)
5472 return SUCCESS;
b99bd4ef 5473
c19d1205
ZW
5474 /* Shift operation on register. */
5475 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5476 }
5477
e2b0ab59 5478 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5479 return FAIL;
b99bd4ef 5480
c19d1205 5481 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5482 {
c19d1205 5483 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5484 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5485 return FAIL;
b99bd4ef 5486
e2b0ab59 5487 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5488 {
5489 inst.error = _("constant expression expected");
5490 return FAIL;
5491 }
b99bd4ef 5492
91d6fa6a 5493 value = exp.X_add_number;
c19d1205
ZW
5494 if (value < 0 || value > 30 || value % 2 != 0)
5495 {
5496 inst.error = _("invalid rotation");
5497 return FAIL;
5498 }
e2b0ab59
AV
5499 if (inst.relocs[0].exp.X_add_number < 0
5500 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5501 {
5502 inst.error = _("invalid constant");
5503 return FAIL;
5504 }
09d92015 5505
a415b1cd 5506 /* Encode as specified. */
e2b0ab59 5507 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5508 return SUCCESS;
09d92015
MM
5509 }
5510
e2b0ab59
AV
5511 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5512 inst.relocs[0].pc_rel = 0;
c19d1205 5513 return SUCCESS;
09d92015
MM
5514}
5515
4962c51a
MS
5516/* Group relocation information. Each entry in the table contains the
5517 textual name of the relocation as may appear in assembler source
5518 and must end with a colon.
5519 Along with this textual name are the relocation codes to be used if
5520 the corresponding instruction is an ALU instruction (ADD or SUB only),
5521 an LDR, an LDRS, or an LDC. */
5522
5523struct group_reloc_table_entry
5524{
5525 const char *name;
5526 int alu_code;
5527 int ldr_code;
5528 int ldrs_code;
5529 int ldc_code;
5530};
5531
5532typedef enum
5533{
5534 /* Varieties of non-ALU group relocation. */
5535
5536 GROUP_LDR,
5537 GROUP_LDRS,
35c228db
AV
5538 GROUP_LDC,
5539 GROUP_MVE
4962c51a
MS
5540} group_reloc_type;
5541
5542static struct group_reloc_table_entry group_reloc_table[] =
5543 { /* Program counter relative: */
5544 { "pc_g0_nc",
5545 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5546 0, /* LDR */
5547 0, /* LDRS */
5548 0 }, /* LDC */
5549 { "pc_g0",
5550 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5551 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5552 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5553 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5554 { "pc_g1_nc",
5555 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5556 0, /* LDR */
5557 0, /* LDRS */
5558 0 }, /* LDC */
5559 { "pc_g1",
5560 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5561 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5562 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5563 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5564 { "pc_g2",
5565 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5566 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5567 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5568 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5569 /* Section base relative */
5570 { "sb_g0_nc",
5571 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5572 0, /* LDR */
5573 0, /* LDRS */
5574 0 }, /* LDC */
5575 { "sb_g0",
5576 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5577 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5578 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5579 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5580 { "sb_g1_nc",
5581 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5582 0, /* LDR */
5583 0, /* LDRS */
5584 0 }, /* LDC */
5585 { "sb_g1",
5586 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5587 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5588 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5589 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5590 { "sb_g2",
5591 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5592 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5593 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5594 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5595 /* Absolute thumb alu relocations. */
5596 { "lower0_7",
5597 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5598 0, /* LDR. */
5599 0, /* LDRS. */
5600 0 }, /* LDC. */
5601 { "lower8_15",
5602 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5603 0, /* LDR. */
5604 0, /* LDRS. */
5605 0 }, /* LDC. */
5606 { "upper0_7",
5607 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5608 0, /* LDR. */
5609 0, /* LDRS. */
5610 0 }, /* LDC. */
5611 { "upper8_15",
5612 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5613 0, /* LDR. */
5614 0, /* LDRS. */
5615 0 } }; /* LDC. */
4962c51a
MS
5616
5617/* Given the address of a pointer pointing to the textual name of a group
5618 relocation as may appear in assembler source, attempt to find its details
5619 in group_reloc_table. The pointer will be updated to the character after
5620 the trailing colon. On failure, FAIL will be returned; SUCCESS
5621 otherwise. On success, *entry will be updated to point at the relevant
5622 group_reloc_table entry. */
5623
5624static int
5625find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5626{
5627 unsigned int i;
5628 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5629 {
5630 int length = strlen (group_reloc_table[i].name);
5631
5f4273c7
NC
5632 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5633 && (*str)[length] == ':')
477330fc
RM
5634 {
5635 *out = &group_reloc_table[i];
5636 *str += (length + 1);
5637 return SUCCESS;
5638 }
4962c51a
MS
5639 }
5640
5641 return FAIL;
5642}
5643
5644/* Parse a <shifter_operand> for an ARM data processing instruction
5645 (as for parse_shifter_operand) where group relocations are allowed:
5646
5647 #<immediate>
5648 #<immediate>, <rotate>
5649 #:<group_reloc>:<expression>
5650 <Rm>
5651 <Rm>, <shift>
5652
5653 where <group_reloc> is one of the strings defined in group_reloc_table.
5654 The hashes are optional.
5655
5656 Everything else is as for parse_shifter_operand. */
5657
5658static parse_operand_result
5659parse_shifter_operand_group_reloc (char **str, int i)
5660{
5661 /* Determine if we have the sequence of characters #: or just :
5662 coming next. If we do, then we check for a group relocation.
5663 If we don't, punt the whole lot to parse_shifter_operand. */
5664
5665 if (((*str)[0] == '#' && (*str)[1] == ':')
5666 || (*str)[0] == ':')
5667 {
5668 struct group_reloc_table_entry *entry;
5669
5670 if ((*str)[0] == '#')
477330fc 5671 (*str) += 2;
4962c51a 5672 else
477330fc 5673 (*str)++;
4962c51a
MS
5674
5675 /* Try to parse a group relocation. Anything else is an error. */
5676 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5677 {
5678 inst.error = _("unknown group relocation");
5679 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5680 }
4962c51a
MS
5681
5682 /* We now have the group relocation table entry corresponding to
477330fc 5683 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5684 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5685 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5686
5687 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5688 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5689 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5690
5691 return PARSE_OPERAND_SUCCESS;
5692 }
5693 else
5694 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5695 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5696
5697 /* Never reached. */
5698}
5699
8e560766
MGD
5700/* Parse a Neon alignment expression. Information is written to
5701 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5702
8e560766
MGD
5703 align .imm = align << 8, .immisalign=1, .preind=0 */
5704static parse_operand_result
5705parse_neon_alignment (char **str, int i)
5706{
5707 char *p = *str;
5708 expressionS exp;
5709
5710 my_get_expression (&exp, &p, GE_NO_PREFIX);
5711
5712 if (exp.X_op != O_constant)
5713 {
5714 inst.error = _("alignment must be constant");
5715 return PARSE_OPERAND_FAIL;
5716 }
5717
5718 inst.operands[i].imm = exp.X_add_number << 8;
5719 inst.operands[i].immisalign = 1;
5720 /* Alignments are not pre-indexes. */
5721 inst.operands[i].preind = 0;
5722
5723 *str = p;
5724 return PARSE_OPERAND_SUCCESS;
5725}
5726
c19d1205 5727/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5728 to inst.operands[i] and/or inst.relocs[0].
09d92015 5729
c19d1205 5730 Preindexed addressing (.preind=1):
09d92015 5731
e2b0ab59 5732 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5733 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5734 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5735 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5736
c19d1205 5737 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5738
c19d1205 5739 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5740
e2b0ab59 5741 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5742 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5743 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5744 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5745
c19d1205 5746 Unindexed addressing (.preind=0, .postind=0):
09d92015 5747
c19d1205 5748 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5749
c19d1205 5750 Other:
09d92015 5751
c19d1205 5752 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5753 =immediate .isreg=0 .relocs[0].exp=immediate
5754 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5755
c19d1205 5756 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5757 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5758
4962c51a
MS
5759static parse_operand_result
5760parse_address_main (char **str, int i, int group_relocations,
477330fc 5761 group_reloc_type group_type)
09d92015 5762{
c19d1205
ZW
5763 char *p = *str;
5764 int reg;
09d92015 5765
c19d1205 5766 if (skip_past_char (&p, '[') == FAIL)
09d92015 5767 {
c19d1205
ZW
5768 if (skip_past_char (&p, '=') == FAIL)
5769 {
974da60d 5770 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5771 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5772 inst.operands[i].reg = REG_PC;
5773 inst.operands[i].isreg = 1;
5774 inst.operands[i].preind = 1;
09d92015 5775
e2b0ab59 5776 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5777 return PARSE_OPERAND_FAIL;
5778 }
e2b0ab59 5779 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5780 /*allow_symbol_p=*/TRUE))
4962c51a 5781 return PARSE_OPERAND_FAIL;
09d92015 5782
c19d1205 5783 *str = p;
4962c51a 5784 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5785 }
5786
8ab8155f
NC
5787 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5788 skip_whitespace (p);
5789
f5f10c66
AV
5790 if (group_type == GROUP_MVE)
5791 {
5792 enum arm_reg_type rtype = REG_TYPE_MQ;
5793 struct neon_type_el et;
5794 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5795 {
5796 inst.operands[i].isquad = 1;
5797 }
5798 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5799 {
5800 inst.error = BAD_ADDR_MODE;
5801 return PARSE_OPERAND_FAIL;
5802 }
5803 }
5804 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5805 {
35c228db
AV
5806 if (group_type == GROUP_MVE)
5807 inst.error = BAD_ADDR_MODE;
5808 else
5809 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5810 return PARSE_OPERAND_FAIL;
09d92015 5811 }
c19d1205
ZW
5812 inst.operands[i].reg = reg;
5813 inst.operands[i].isreg = 1;
09d92015 5814
c19d1205 5815 if (skip_past_comma (&p) == SUCCESS)
09d92015 5816 {
c19d1205 5817 inst.operands[i].preind = 1;
09d92015 5818
c19d1205
ZW
5819 if (*p == '+') p++;
5820 else if (*p == '-') p++, inst.operands[i].negative = 1;
5821
f5f10c66
AV
5822 enum arm_reg_type rtype = REG_TYPE_MQ;
5823 struct neon_type_el et;
5824 if (group_type == GROUP_MVE
5825 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5826 {
5827 inst.operands[i].immisreg = 2;
5828 inst.operands[i].imm = reg;
5829
5830 if (skip_past_comma (&p) == SUCCESS)
5831 {
5832 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
5833 {
5834 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
5835 inst.relocs[0].exp.X_add_number = 0;
5836 }
5837 else
5838 return PARSE_OPERAND_FAIL;
5839 }
5840 }
5841 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5842 {
c19d1205
ZW
5843 inst.operands[i].imm = reg;
5844 inst.operands[i].immisreg = 1;
5845
5846 if (skip_past_comma (&p) == SUCCESS)
5847 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5848 return PARSE_OPERAND_FAIL;
c19d1205 5849 }
5287ad62 5850 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5851 {
5852 /* FIXME: '@' should be used here, but it's filtered out by generic
5853 code before we get to see it here. This may be subject to
5854 change. */
5855 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5856
8e560766
MGD
5857 if (result != PARSE_OPERAND_SUCCESS)
5858 return result;
5859 }
c19d1205
ZW
5860 else
5861 {
5862 if (inst.operands[i].negative)
5863 {
5864 inst.operands[i].negative = 0;
5865 p--;
5866 }
4962c51a 5867
5f4273c7
NC
5868 if (group_relocations
5869 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5870 {
5871 struct group_reloc_table_entry *entry;
5872
477330fc
RM
5873 /* Skip over the #: or : sequence. */
5874 if (*p == '#')
5875 p += 2;
5876 else
5877 p++;
4962c51a
MS
5878
5879 /* Try to parse a group relocation. Anything else is an
477330fc 5880 error. */
4962c51a
MS
5881 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5882 {
5883 inst.error = _("unknown group relocation");
5884 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5885 }
5886
5887 /* We now have the group relocation table entry corresponding to
5888 the name in the assembler source. Next, we parse the
477330fc 5889 expression. */
e2b0ab59 5890 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
5891 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5892
5893 /* Record the relocation type. */
477330fc
RM
5894 switch (group_type)
5895 {
5896 case GROUP_LDR:
e2b0ab59
AV
5897 inst.relocs[0].type
5898 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 5899 break;
4962c51a 5900
477330fc 5901 case GROUP_LDRS:
e2b0ab59
AV
5902 inst.relocs[0].type
5903 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 5904 break;
4962c51a 5905
477330fc 5906 case GROUP_LDC:
e2b0ab59
AV
5907 inst.relocs[0].type
5908 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 5909 break;
4962c51a 5910
477330fc
RM
5911 default:
5912 gas_assert (0);
5913 }
4962c51a 5914
e2b0ab59 5915 if (inst.relocs[0].type == 0)
4962c51a
MS
5916 {
5917 inst.error = _("this group relocation is not allowed on this instruction");
5918 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5919 }
477330fc
RM
5920 }
5921 else
26d97720
NS
5922 {
5923 char *q = p;
0198d5e6 5924
e2b0ab59 5925 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
5926 return PARSE_OPERAND_FAIL;
5927 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
5928 if (inst.relocs[0].exp.X_op == O_constant
5929 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
5930 {
5931 skip_whitespace (q);
5932 if (*q == '#')
5933 {
5934 q++;
5935 skip_whitespace (q);
5936 }
5937 if (*q == '-')
5938 inst.operands[i].negative = 1;
5939 }
5940 }
09d92015
MM
5941 }
5942 }
8e560766
MGD
5943 else if (skip_past_char (&p, ':') == SUCCESS)
5944 {
5945 /* FIXME: '@' should be used here, but it's filtered out by generic code
5946 before we get to see it here. This may be subject to change. */
5947 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5948
8e560766
MGD
5949 if (result != PARSE_OPERAND_SUCCESS)
5950 return result;
5951 }
09d92015 5952
c19d1205 5953 if (skip_past_char (&p, ']') == FAIL)
09d92015 5954 {
c19d1205 5955 inst.error = _("']' expected");
4962c51a 5956 return PARSE_OPERAND_FAIL;
09d92015
MM
5957 }
5958
c19d1205
ZW
5959 if (skip_past_char (&p, '!') == SUCCESS)
5960 inst.operands[i].writeback = 1;
09d92015 5961
c19d1205 5962 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5963 {
c19d1205
ZW
5964 if (skip_past_char (&p, '{') == SUCCESS)
5965 {
5966 /* [Rn], {expr} - unindexed, with option */
5967 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5968 0, 255, TRUE) == FAIL)
4962c51a 5969 return PARSE_OPERAND_FAIL;
09d92015 5970
c19d1205
ZW
5971 if (skip_past_char (&p, '}') == FAIL)
5972 {
5973 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5974 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5975 }
5976 if (inst.operands[i].preind)
5977 {
5978 inst.error = _("cannot combine index with option");
4962c51a 5979 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5980 }
5981 *str = p;
4962c51a 5982 return PARSE_OPERAND_SUCCESS;
09d92015 5983 }
c19d1205
ZW
5984 else
5985 {
5986 inst.operands[i].postind = 1;
5987 inst.operands[i].writeback = 1;
09d92015 5988
c19d1205
ZW
5989 if (inst.operands[i].preind)
5990 {
5991 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5992 return PARSE_OPERAND_FAIL;
c19d1205 5993 }
09d92015 5994
c19d1205
ZW
5995 if (*p == '+') p++;
5996 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5997
f5f10c66
AV
5998 enum arm_reg_type rtype = REG_TYPE_MQ;
5999 struct neon_type_el et;
6000 if (group_type == GROUP_MVE
6001 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6002 {
6003 inst.operands[i].immisreg = 2;
6004 inst.operands[i].imm = reg;
6005 }
6006 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6007 {
477330fc
RM
6008 /* We might be using the immediate for alignment already. If we
6009 are, OR the register number into the low-order bits. */
6010 if (inst.operands[i].immisalign)
6011 inst.operands[i].imm |= reg;
6012 else
6013 inst.operands[i].imm = reg;
c19d1205 6014 inst.operands[i].immisreg = 1;
a737bd4d 6015
c19d1205
ZW
6016 if (skip_past_comma (&p) == SUCCESS)
6017 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6018 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6019 }
6020 else
6021 {
26d97720 6022 char *q = p;
0198d5e6 6023
c19d1205
ZW
6024 if (inst.operands[i].negative)
6025 {
6026 inst.operands[i].negative = 0;
6027 p--;
6028 }
e2b0ab59 6029 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6030 return PARSE_OPERAND_FAIL;
26d97720 6031 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6032 if (inst.relocs[0].exp.X_op == O_constant
6033 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6034 {
6035 skip_whitespace (q);
6036 if (*q == '#')
6037 {
6038 q++;
6039 skip_whitespace (q);
6040 }
6041 if (*q == '-')
6042 inst.operands[i].negative = 1;
6043 }
c19d1205
ZW
6044 }
6045 }
a737bd4d
NC
6046 }
6047
c19d1205
ZW
6048 /* If at this point neither .preind nor .postind is set, we have a
6049 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6050 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6051 {
6052 inst.operands[i].preind = 1;
e2b0ab59
AV
6053 inst.relocs[0].exp.X_op = O_constant;
6054 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6055 }
6056 *str = p;
4962c51a
MS
6057 return PARSE_OPERAND_SUCCESS;
6058}
6059
6060static int
6061parse_address (char **str, int i)
6062{
21d799b5 6063 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6064 ? SUCCESS : FAIL;
4962c51a
MS
6065}
6066
6067static parse_operand_result
6068parse_address_group_reloc (char **str, int i, group_reloc_type type)
6069{
6070 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6071}
6072
b6895b4f
PB
6073/* Parse an operand for a MOVW or MOVT instruction. */
6074static int
6075parse_half (char **str)
6076{
6077 char * p;
5f4273c7 6078
b6895b4f
PB
6079 p = *str;
6080 skip_past_char (&p, '#');
5f4273c7 6081 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6082 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6083 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6084 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6085
e2b0ab59 6086 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6087 {
6088 p += 9;
5f4273c7 6089 skip_whitespace (p);
b6895b4f
PB
6090 }
6091
e2b0ab59 6092 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6093 return FAIL;
6094
e2b0ab59 6095 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6096 {
e2b0ab59 6097 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6098 {
6099 inst.error = _("constant expression expected");
6100 return FAIL;
6101 }
e2b0ab59
AV
6102 if (inst.relocs[0].exp.X_add_number < 0
6103 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6104 {
6105 inst.error = _("immediate value out of range");
6106 return FAIL;
6107 }
6108 }
6109 *str = p;
6110 return SUCCESS;
6111}
6112
c19d1205 6113/* Miscellaneous. */
a737bd4d 6114
c19d1205
ZW
6115/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6116 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6117static int
d2cd1205 6118parse_psr (char **str, bfd_boolean lhs)
09d92015 6119{
c19d1205
ZW
6120 char *p;
6121 unsigned long psr_field;
62b3e311
PB
6122 const struct asm_psr *psr;
6123 char *start;
d2cd1205 6124 bfd_boolean is_apsr = FALSE;
ac7f631b 6125 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6126
a4482bb6
NC
6127 /* PR gas/12698: If the user has specified -march=all then m_profile will
6128 be TRUE, but we want to ignore it in this case as we are building for any
6129 CPU type, including non-m variants. */
823d2571 6130 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6131 m_profile = FALSE;
6132
c19d1205
ZW
6133 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6134 feature for ease of use and backwards compatibility. */
6135 p = *str;
62b3e311 6136 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6137 {
6138 if (m_profile)
6139 goto unsupported_psr;
fa94de6b 6140
d2cd1205
JB
6141 psr_field = SPSR_BIT;
6142 }
6143 else if (strncasecmp (p, "CPSR", 4) == 0)
6144 {
6145 if (m_profile)
6146 goto unsupported_psr;
6147
6148 psr_field = 0;
6149 }
6150 else if (strncasecmp (p, "APSR", 4) == 0)
6151 {
6152 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6153 and ARMv7-R architecture CPUs. */
6154 is_apsr = TRUE;
6155 psr_field = 0;
6156 }
6157 else if (m_profile)
62b3e311
PB
6158 {
6159 start = p;
6160 do
6161 p++;
6162 while (ISALNUM (*p) || *p == '_');
6163
d2cd1205
JB
6164 if (strncasecmp (start, "iapsr", 5) == 0
6165 || strncasecmp (start, "eapsr", 5) == 0
6166 || strncasecmp (start, "xpsr", 4) == 0
6167 || strncasecmp (start, "psr", 3) == 0)
6168 p = start + strcspn (start, "rR") + 1;
6169
21d799b5 6170 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 6171 p - start);
d2cd1205 6172
62b3e311
PB
6173 if (!psr)
6174 return FAIL;
09d92015 6175
d2cd1205
JB
6176 /* If APSR is being written, a bitfield may be specified. Note that
6177 APSR itself is handled above. */
6178 if (psr->field <= 3)
6179 {
6180 psr_field = psr->field;
6181 is_apsr = TRUE;
6182 goto check_suffix;
6183 }
6184
62b3e311 6185 *str = p;
d2cd1205
JB
6186 /* M-profile MSR instructions have the mask field set to "10", except
6187 *PSR variants which modify APSR, which may use a different mask (and
6188 have been handled already). Do that by setting the PSR_f field
6189 here. */
6190 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6191 }
d2cd1205
JB
6192 else
6193 goto unsupported_psr;
09d92015 6194
62b3e311 6195 p += 4;
d2cd1205 6196check_suffix:
c19d1205
ZW
6197 if (*p == '_')
6198 {
6199 /* A suffix follows. */
c19d1205
ZW
6200 p++;
6201 start = p;
a737bd4d 6202
c19d1205
ZW
6203 do
6204 p++;
6205 while (ISALNUM (*p) || *p == '_');
a737bd4d 6206
d2cd1205
JB
6207 if (is_apsr)
6208 {
6209 /* APSR uses a notation for bits, rather than fields. */
6210 unsigned int nzcvq_bits = 0;
6211 unsigned int g_bit = 0;
6212 char *bit;
fa94de6b 6213
d2cd1205
JB
6214 for (bit = start; bit != p; bit++)
6215 {
6216 switch (TOLOWER (*bit))
477330fc 6217 {
d2cd1205
JB
6218 case 'n':
6219 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6220 break;
6221
6222 case 'z':
6223 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6224 break;
6225
6226 case 'c':
6227 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6228 break;
6229
6230 case 'v':
6231 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6232 break;
fa94de6b 6233
d2cd1205
JB
6234 case 'q':
6235 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6236 break;
fa94de6b 6237
d2cd1205
JB
6238 case 'g':
6239 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6240 break;
fa94de6b 6241
d2cd1205
JB
6242 default:
6243 inst.error = _("unexpected bit specified after APSR");
6244 return FAIL;
6245 }
6246 }
fa94de6b 6247
d2cd1205
JB
6248 if (nzcvq_bits == 0x1f)
6249 psr_field |= PSR_f;
fa94de6b 6250
d2cd1205
JB
6251 if (g_bit == 0x1)
6252 {
6253 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6254 {
d2cd1205
JB
6255 inst.error = _("selected processor does not "
6256 "support DSP extension");
6257 return FAIL;
6258 }
6259
6260 psr_field |= PSR_s;
6261 }
fa94de6b 6262
d2cd1205
JB
6263 if ((nzcvq_bits & 0x20) != 0
6264 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6265 || (g_bit & 0x2) != 0)
6266 {
6267 inst.error = _("bad bitmask specified after APSR");
6268 return FAIL;
6269 }
6270 }
6271 else
477330fc 6272 {
d2cd1205 6273 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6274 p - start);
d2cd1205 6275 if (!psr)
477330fc 6276 goto error;
a737bd4d 6277
d2cd1205
JB
6278 psr_field |= psr->field;
6279 }
a737bd4d 6280 }
c19d1205 6281 else
a737bd4d 6282 {
c19d1205
ZW
6283 if (ISALNUM (*p))
6284 goto error; /* Garbage after "[CS]PSR". */
6285
d2cd1205 6286 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6287 is deprecated, but allow it anyway. */
d2cd1205
JB
6288 if (is_apsr && lhs)
6289 {
6290 psr_field |= PSR_f;
6291 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6292 "deprecated"));
6293 }
6294 else if (!m_profile)
6295 /* These bits are never right for M-profile devices: don't set them
6296 (only code paths which read/write APSR reach here). */
6297 psr_field |= (PSR_c | PSR_f);
a737bd4d 6298 }
c19d1205
ZW
6299 *str = p;
6300 return psr_field;
a737bd4d 6301
d2cd1205
JB
6302 unsupported_psr:
6303 inst.error = _("selected processor does not support requested special "
6304 "purpose register");
6305 return FAIL;
6306
c19d1205
ZW
6307 error:
6308 inst.error = _("flag for {c}psr instruction expected");
6309 return FAIL;
a737bd4d
NC
6310}
6311
32c36c3c
AV
6312static int
6313parse_sys_vldr_vstr (char **str)
6314{
6315 unsigned i;
6316 int val = FAIL;
6317 struct {
6318 const char *name;
6319 int regl;
6320 int regh;
6321 } sysregs[] = {
6322 {"FPSCR", 0x1, 0x0},
6323 {"FPSCR_nzcvqc", 0x2, 0x0},
6324 {"VPR", 0x4, 0x1},
6325 {"P0", 0x5, 0x1},
6326 {"FPCXTNS", 0x6, 0x1},
6327 {"FPCXTS", 0x7, 0x1}
6328 };
6329 char *op_end = strchr (*str, ',');
6330 size_t op_strlen = op_end - *str;
6331
6332 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6333 {
6334 if (!strncmp (*str, sysregs[i].name, op_strlen))
6335 {
6336 val = sysregs[i].regl | (sysregs[i].regh << 3);
6337 *str = op_end;
6338 break;
6339 }
6340 }
6341
6342 return val;
6343}
6344
c19d1205
ZW
6345/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6346 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6347
c19d1205
ZW
6348static int
6349parse_cps_flags (char **str)
a737bd4d 6350{
c19d1205
ZW
6351 int val = 0;
6352 int saw_a_flag = 0;
6353 char *s = *str;
a737bd4d 6354
c19d1205
ZW
6355 for (;;)
6356 switch (*s++)
6357 {
6358 case '\0': case ',':
6359 goto done;
a737bd4d 6360
c19d1205
ZW
6361 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6362 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6363 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6364
c19d1205
ZW
6365 default:
6366 inst.error = _("unrecognized CPS flag");
6367 return FAIL;
6368 }
a737bd4d 6369
c19d1205
ZW
6370 done:
6371 if (saw_a_flag == 0)
a737bd4d 6372 {
c19d1205
ZW
6373 inst.error = _("missing CPS flags");
6374 return FAIL;
a737bd4d 6375 }
a737bd4d 6376
c19d1205
ZW
6377 *str = s - 1;
6378 return val;
a737bd4d
NC
6379}
6380
c19d1205
ZW
6381/* Parse an endian specifier ("BE" or "LE", case insensitive);
6382 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6383
6384static int
c19d1205 6385parse_endian_specifier (char **str)
a737bd4d 6386{
c19d1205
ZW
6387 int little_endian;
6388 char *s = *str;
a737bd4d 6389
c19d1205
ZW
6390 if (strncasecmp (s, "BE", 2))
6391 little_endian = 0;
6392 else if (strncasecmp (s, "LE", 2))
6393 little_endian = 1;
6394 else
a737bd4d 6395 {
c19d1205 6396 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6397 return FAIL;
6398 }
6399
c19d1205 6400 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6401 {
c19d1205 6402 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6403 return FAIL;
6404 }
6405
c19d1205
ZW
6406 *str = s + 2;
6407 return little_endian;
6408}
a737bd4d 6409
c19d1205
ZW
6410/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6411 value suitable for poking into the rotate field of an sxt or sxta
6412 instruction, or FAIL on error. */
6413
6414static int
6415parse_ror (char **str)
6416{
6417 int rot;
6418 char *s = *str;
6419
6420 if (strncasecmp (s, "ROR", 3) == 0)
6421 s += 3;
6422 else
a737bd4d 6423 {
c19d1205 6424 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6425 return FAIL;
6426 }
c19d1205
ZW
6427
6428 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6429 return FAIL;
6430
6431 switch (rot)
a737bd4d 6432 {
c19d1205
ZW
6433 case 0: *str = s; return 0x0;
6434 case 8: *str = s; return 0x1;
6435 case 16: *str = s; return 0x2;
6436 case 24: *str = s; return 0x3;
6437
6438 default:
6439 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6440 return FAIL;
6441 }
c19d1205 6442}
a737bd4d 6443
c19d1205
ZW
6444/* Parse a conditional code (from conds[] below). The value returned is in the
6445 range 0 .. 14, or FAIL. */
6446static int
6447parse_cond (char **str)
6448{
c462b453 6449 char *q;
c19d1205 6450 const struct asm_cond *c;
c462b453
PB
6451 int n;
6452 /* Condition codes are always 2 characters, so matching up to
6453 3 characters is sufficient. */
6454 char cond[3];
a737bd4d 6455
c462b453
PB
6456 q = *str;
6457 n = 0;
6458 while (ISALPHA (*q) && n < 3)
6459 {
e07e6e58 6460 cond[n] = TOLOWER (*q);
c462b453
PB
6461 q++;
6462 n++;
6463 }
a737bd4d 6464
21d799b5 6465 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6466 if (!c)
a737bd4d 6467 {
c19d1205 6468 inst.error = _("condition required");
a737bd4d
NC
6469 return FAIL;
6470 }
6471
c19d1205
ZW
6472 *str = q;
6473 return c->value;
6474}
6475
62b3e311
PB
6476/* Parse an option for a barrier instruction. Returns the encoding for the
6477 option, or FAIL. */
6478static int
6479parse_barrier (char **str)
6480{
6481 char *p, *q;
6482 const struct asm_barrier_opt *o;
6483
6484 p = q = *str;
6485 while (ISALPHA (*q))
6486 q++;
6487
21d799b5 6488 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6489 q - p);
62b3e311
PB
6490 if (!o)
6491 return FAIL;
6492
e797f7e0
MGD
6493 if (!mark_feature_used (&o->arch))
6494 return FAIL;
6495
62b3e311
PB
6496 *str = q;
6497 return o->value;
6498}
6499
92e90b6e
PB
6500/* Parse the operands of a table branch instruction. Similar to a memory
6501 operand. */
6502static int
6503parse_tb (char **str)
6504{
6505 char * p = *str;
6506 int reg;
6507
6508 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6509 {
6510 inst.error = _("'[' expected");
6511 return FAIL;
6512 }
92e90b6e 6513
dcbf9037 6514 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6515 {
6516 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6517 return FAIL;
6518 }
6519 inst.operands[0].reg = reg;
6520
6521 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6522 {
6523 inst.error = _("',' expected");
6524 return FAIL;
6525 }
5f4273c7 6526
dcbf9037 6527 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6528 {
6529 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6530 return FAIL;
6531 }
6532 inst.operands[0].imm = reg;
6533
6534 if (skip_past_comma (&p) == SUCCESS)
6535 {
6536 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6537 return FAIL;
e2b0ab59 6538 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6539 {
6540 inst.error = _("invalid shift");
6541 return FAIL;
6542 }
6543 inst.operands[0].shifted = 1;
6544 }
6545
6546 if (skip_past_char (&p, ']') == FAIL)
6547 {
6548 inst.error = _("']' expected");
6549 return FAIL;
6550 }
6551 *str = p;
6552 return SUCCESS;
6553}
6554
5287ad62
JB
6555/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6556 information on the types the operands can take and how they are encoded.
037e8744
JB
6557 Up to four operands may be read; this function handles setting the
6558 ".present" field for each read operand itself.
5287ad62
JB
6559 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6560 else returns FAIL. */
6561
6562static int
6563parse_neon_mov (char **str, int *which_operand)
6564{
6565 int i = *which_operand, val;
6566 enum arm_reg_type rtype;
6567 char *ptr = *str;
dcbf9037 6568 struct neon_type_el optype;
5f4273c7 6569
57785aa2
AV
6570 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6571 {
6572 /* Cases 17 or 19. */
6573 inst.operands[i].reg = val;
6574 inst.operands[i].isvec = 1;
6575 inst.operands[i].isscalar = 2;
6576 inst.operands[i].vectype = optype;
6577 inst.operands[i++].present = 1;
6578
6579 if (skip_past_comma (&ptr) == FAIL)
6580 goto wanted_comma;
6581
6582 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6583 {
6584 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6585 inst.operands[i].reg = val;
6586 inst.operands[i].isreg = 1;
6587 inst.operands[i].present = 1;
6588 }
6589 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6590 {
6591 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6592 inst.operands[i].reg = val;
6593 inst.operands[i].isvec = 1;
6594 inst.operands[i].isscalar = 2;
6595 inst.operands[i].vectype = optype;
6596 inst.operands[i++].present = 1;
6597
6598 if (skip_past_comma (&ptr) == FAIL)
6599 goto wanted_comma;
6600
6601 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6602 goto wanted_arm;
6603
6604 inst.operands[i].reg = val;
6605 inst.operands[i].isreg = 1;
6606 inst.operands[i++].present = 1;
6607
6608 if (skip_past_comma (&ptr) == FAIL)
6609 goto wanted_comma;
6610
6611 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6612 goto wanted_arm;
6613
6614 inst.operands[i].reg = val;
6615 inst.operands[i].isreg = 1;
6616 inst.operands[i].present = 1;
6617 }
6618 else
6619 {
6620 first_error (_("expected ARM or MVE vector register"));
6621 return FAIL;
6622 }
6623 }
6624 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6625 {
6626 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6627 inst.operands[i].reg = val;
6628 inst.operands[i].isscalar = 1;
dcbf9037 6629 inst.operands[i].vectype = optype;
5287ad62
JB
6630 inst.operands[i++].present = 1;
6631
6632 if (skip_past_comma (&ptr) == FAIL)
477330fc 6633 goto wanted_comma;
5f4273c7 6634
dcbf9037 6635 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6636 goto wanted_arm;
5f4273c7 6637
5287ad62
JB
6638 inst.operands[i].reg = val;
6639 inst.operands[i].isreg = 1;
6640 inst.operands[i].present = 1;
6641 }
57785aa2
AV
6642 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6643 != FAIL)
6644 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6645 != FAIL))
5287ad62
JB
6646 {
6647 /* Cases 0, 1, 2, 3, 5 (D only). */
6648 if (skip_past_comma (&ptr) == FAIL)
477330fc 6649 goto wanted_comma;
5f4273c7 6650
5287ad62
JB
6651 inst.operands[i].reg = val;
6652 inst.operands[i].isreg = 1;
6653 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6654 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6655 inst.operands[i].isvec = 1;
dcbf9037 6656 inst.operands[i].vectype = optype;
5287ad62
JB
6657 inst.operands[i++].present = 1;
6658
dcbf9037 6659 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6660 {
6661 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6662 Case 13: VMOV <Sd>, <Rm> */
6663 inst.operands[i].reg = val;
6664 inst.operands[i].isreg = 1;
6665 inst.operands[i].present = 1;
6666
6667 if (rtype == REG_TYPE_NQ)
6668 {
6669 first_error (_("can't use Neon quad register here"));
6670 return FAIL;
6671 }
6672 else if (rtype != REG_TYPE_VFS)
6673 {
6674 i++;
6675 if (skip_past_comma (&ptr) == FAIL)
6676 goto wanted_comma;
6677 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6678 goto wanted_arm;
6679 inst.operands[i].reg = val;
6680 inst.operands[i].isreg = 1;
6681 inst.operands[i].present = 1;
6682 }
6683 }
037e8744 6684 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6685 &optype)) != FAIL)
6686 {
6687 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6688 Case 1: VMOV<c><q> <Dd>, <Dm>
6689 Case 8: VMOV.F32 <Sd>, <Sm>
6690 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6691
6692 inst.operands[i].reg = val;
6693 inst.operands[i].isreg = 1;
6694 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6695 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6696 inst.operands[i].isvec = 1;
6697 inst.operands[i].vectype = optype;
6698 inst.operands[i].present = 1;
6699
6700 if (skip_past_comma (&ptr) == SUCCESS)
6701 {
6702 /* Case 15. */
6703 i++;
6704
6705 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6706 goto wanted_arm;
6707
6708 inst.operands[i].reg = val;
6709 inst.operands[i].isreg = 1;
6710 inst.operands[i++].present = 1;
6711
6712 if (skip_past_comma (&ptr) == FAIL)
6713 goto wanted_comma;
6714
6715 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6716 goto wanted_arm;
6717
6718 inst.operands[i].reg = val;
6719 inst.operands[i].isreg = 1;
6720 inst.operands[i].present = 1;
6721 }
6722 }
4641781c 6723 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6724 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6725 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6726 Case 10: VMOV.F32 <Sd>, #<imm>
6727 Case 11: VMOV.F64 <Dd>, #<imm> */
6728 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6729 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6730 == SUCCESS)
477330fc
RM
6731 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6732 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6733 ;
5287ad62 6734 else
477330fc
RM
6735 {
6736 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6737 return FAIL;
6738 }
5287ad62 6739 }
dcbf9037 6740 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6741 {
57785aa2 6742 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6743 inst.operands[i].reg = val;
6744 inst.operands[i].isreg = 1;
6745 inst.operands[i++].present = 1;
5f4273c7 6746
5287ad62 6747 if (skip_past_comma (&ptr) == FAIL)
477330fc 6748 goto wanted_comma;
5f4273c7 6749
57785aa2
AV
6750 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6751 {
6752 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6753 inst.operands[i].reg = val;
6754 inst.operands[i].isscalar = 2;
6755 inst.operands[i].present = 1;
6756 inst.operands[i].vectype = optype;
6757 }
6758 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6759 {
6760 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6761 inst.operands[i].reg = val;
6762 inst.operands[i].isscalar = 1;
6763 inst.operands[i].present = 1;
6764 inst.operands[i].vectype = optype;
6765 }
dcbf9037 6766 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6767 {
477330fc
RM
6768 inst.operands[i].reg = val;
6769 inst.operands[i].isreg = 1;
6770 inst.operands[i++].present = 1;
6771
6772 if (skip_past_comma (&ptr) == FAIL)
6773 goto wanted_comma;
6774
6775 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6776 != FAIL)
477330fc 6777 {
57785aa2 6778 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6779
477330fc
RM
6780 inst.operands[i].reg = val;
6781 inst.operands[i].isreg = 1;
6782 inst.operands[i].isvec = 1;
57785aa2 6783 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6784 inst.operands[i].vectype = optype;
6785 inst.operands[i].present = 1;
57785aa2
AV
6786
6787 if (rtype == REG_TYPE_VFS)
6788 {
6789 /* Case 14. */
6790 i++;
6791 if (skip_past_comma (&ptr) == FAIL)
6792 goto wanted_comma;
6793 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6794 &optype)) == FAIL)
6795 {
6796 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6797 return FAIL;
6798 }
6799 inst.operands[i].reg = val;
6800 inst.operands[i].isreg = 1;
6801 inst.operands[i].isvec = 1;
6802 inst.operands[i].issingle = 1;
6803 inst.operands[i].vectype = optype;
6804 inst.operands[i].present = 1;
6805 }
6806 }
6807 else
6808 {
6809 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6810 != FAIL)
6811 {
6812 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6813 inst.operands[i].reg = val;
6814 inst.operands[i].isvec = 1;
6815 inst.operands[i].isscalar = 2;
6816 inst.operands[i].vectype = optype;
6817 inst.operands[i++].present = 1;
6818
6819 if (skip_past_comma (&ptr) == FAIL)
6820 goto wanted_comma;
6821
6822 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6823 == FAIL)
6824 {
6825 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6826 return FAIL;
6827 }
6828 inst.operands[i].reg = val;
6829 inst.operands[i].isvec = 1;
6830 inst.operands[i].isscalar = 2;
6831 inst.operands[i].vectype = optype;
6832 inst.operands[i].present = 1;
6833 }
6834 else
6835 {
6836 first_error (_("VFP single, double or MVE vector register"
6837 " expected"));
6838 return FAIL;
6839 }
477330fc
RM
6840 }
6841 }
037e8744 6842 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6843 != FAIL)
6844 {
6845 /* Case 13. */
6846 inst.operands[i].reg = val;
6847 inst.operands[i].isreg = 1;
6848 inst.operands[i].isvec = 1;
6849 inst.operands[i].issingle = 1;
6850 inst.operands[i].vectype = optype;
6851 inst.operands[i].present = 1;
6852 }
5287ad62
JB
6853 }
6854 else
6855 {
dcbf9037 6856 first_error (_("parse error"));
5287ad62
JB
6857 return FAIL;
6858 }
6859
6860 /* Successfully parsed the operands. Update args. */
6861 *which_operand = i;
6862 *str = ptr;
6863 return SUCCESS;
6864
5f4273c7 6865 wanted_comma:
dcbf9037 6866 first_error (_("expected comma"));
5287ad62 6867 return FAIL;
5f4273c7
NC
6868
6869 wanted_arm:
dcbf9037 6870 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6871 return FAIL;
5287ad62
JB
6872}
6873
5be8be5d
DG
6874/* Use this macro when the operand constraints are different
6875 for ARM and THUMB (e.g. ldrd). */
6876#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6877 ((arm_operand) | ((thumb_operand) << 16))
6878
c19d1205
ZW
6879/* Matcher codes for parse_operands. */
6880enum operand_parse_code
6881{
6882 OP_stop, /* end of line */
6883
6884 OP_RR, /* ARM register */
6885 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6886 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6887 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6888 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6889 optional trailing ! */
c19d1205
ZW
6890 OP_RRw, /* ARM register, not r15, optional trailing ! */
6891 OP_RCP, /* Coprocessor number */
6892 OP_RCN, /* Coprocessor register */
6893 OP_RF, /* FPA register */
6894 OP_RVS, /* VFP single precision register */
5287ad62
JB
6895 OP_RVD, /* VFP double precision register (0..15) */
6896 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
6897 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6898 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
6899 */
5287ad62 6900 OP_RNQ, /* Neon quad precision register */
5ee91343 6901 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 6902 OP_RVSD, /* VFP single or double precision register */
1b883319 6903 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 6904 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 6905 OP_RNSD, /* Neon single or double precision register */
5287ad62 6906 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 6907 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 6908 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 6909 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6910 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6911 OP_RVC, /* VFP control register */
6912 OP_RMF, /* Maverick F register */
6913 OP_RMD, /* Maverick D register */
6914 OP_RMFX, /* Maverick FX register */
6915 OP_RMDX, /* Maverick DX register */
6916 OP_RMAX, /* Maverick AX register */
6917 OP_RMDS, /* Maverick DSPSC register */
6918 OP_RIWR, /* iWMMXt wR register */
6919 OP_RIWC, /* iWMMXt wC register */
6920 OP_RIWG, /* iWMMXt wCG register */
6921 OP_RXA, /* XScale accumulator register */
6922
5ee91343
AV
6923 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
6924 */
6925 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
6926 GPR (no SP/SP) */
a302e574 6927 OP_RMQ, /* MVE vector register. */
1b883319 6928 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 6929 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 6930
60f993ce
AV
6931 /* New operands for Armv8.1-M Mainline. */
6932 OP_LR, /* ARM LR register */
a302e574
AV
6933 OP_RRe, /* ARM register, only even numbered. */
6934 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 6935 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 6936 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 6937
c19d1205 6938 OP_REGLST, /* ARM register list */
4b5a202f 6939 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
6940 OP_VRSLST, /* VFP single-precision register list */
6941 OP_VRDLST, /* VFP double-precision register list */
037e8744 6942 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6943 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6944 OP_NSTRLST, /* Neon element/structure list */
efd6b359 6945 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
6946 OP_MSTRLST2, /* MVE vector list with two elements. */
6947 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 6948
5287ad62 6949 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6950 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6951 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
6952 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
6953 zero. */
5287ad62 6954 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6955 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6956 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
6957 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
6958 */
a8465a06
AV
6959 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
6960 scalar, or ARM register. */
5287ad62 6961 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
6962 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
6963 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
6964 register. */
5d281bf0 6965 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
6966 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6967 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6968 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
6969 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
6970 OP_RNDQMQ_Ibig,
5287ad62 6971 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
6972 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
6973 ARM register. */
2d447fca 6974 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 6975 OP_VLDR, /* VLDR operand. */
5287ad62
JB
6976
6977 OP_I0, /* immediate zero */
c19d1205
ZW
6978 OP_I7, /* immediate value 0 .. 7 */
6979 OP_I15, /* 0 .. 15 */
6980 OP_I16, /* 1 .. 16 */
5287ad62 6981 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6982 OP_I31, /* 0 .. 31 */
6983 OP_I31w, /* 0 .. 31, optional trailing ! */
6984 OP_I32, /* 1 .. 32 */
5287ad62
JB
6985 OP_I32z, /* 0 .. 32 */
6986 OP_I63, /* 0 .. 63 */
c19d1205 6987 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6988 OP_I64, /* 1 .. 64 */
6989 OP_I64z, /* 0 .. 64 */
c19d1205 6990 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6991
6992 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6993 OP_I7b, /* 0 .. 7 */
6994 OP_I15b, /* 0 .. 15 */
6995 OP_I31b, /* 0 .. 31 */
6996
6997 OP_SH, /* shifter operand */
4962c51a 6998 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6999 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7000 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7001 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7002 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7003 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7004 OP_EXP, /* arbitrary expression */
7005 OP_EXPi, /* same, with optional immediate prefix */
7006 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7007 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7008 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7009 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7010 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7011
7012 OP_CPSF, /* CPS flags */
7013 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7014 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7015 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7016 OP_COND, /* conditional code */
92e90b6e 7017 OP_TB, /* Table branch. */
c19d1205 7018
037e8744
JB
7019 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7020
c19d1205 7021 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7022 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7023 OP_RR_EXi, /* ARM register or expression with imm prefix */
7024 OP_RF_IF, /* FPA register or immediate */
7025 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7026 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7027
7028 /* Optional operands. */
7029 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7030 OP_oI31b, /* 0 .. 31 */
5287ad62 7031 OP_oI32b, /* 1 .. 32 */
5f1af56b 7032 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7033 OP_oIffffb, /* 0 .. 65535 */
7034 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7035
7036 OP_oRR, /* ARM register */
60f993ce 7037 OP_oLR, /* ARM LR register */
c19d1205 7038 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7039 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7040 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7041 OP_oRND, /* Optional Neon double precision register */
7042 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7043 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7044 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7045 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7046 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7047 register. */
c19d1205
ZW
7048 OP_oSHll, /* LSL immediate */
7049 OP_oSHar, /* ASR immediate */
7050 OP_oSHllar, /* LSL or ASR immediate */
7051 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7052 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7053
1b883319
AV
7054 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7055
5be8be5d
DG
7056 /* Some pre-defined mixed (ARM/THUMB) operands. */
7057 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7058 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7059 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7060
c19d1205
ZW
7061 OP_FIRST_OPTIONAL = OP_oI7b
7062};
a737bd4d 7063
c19d1205
ZW
7064/* Generic instruction operand parser. This does no encoding and no
7065 semantic validation; it merely squirrels values away in the inst
7066 structure. Returns SUCCESS or FAIL depending on whether the
7067 specified grammar matched. */
7068static int
5be8be5d 7069parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7070{
5be8be5d 7071 unsigned const int *upat = pattern;
c19d1205
ZW
7072 char *backtrack_pos = 0;
7073 const char *backtrack_error = 0;
99aad254 7074 int i, val = 0, backtrack_index = 0;
5287ad62 7075 enum arm_reg_type rtype;
4962c51a 7076 parse_operand_result result;
5be8be5d 7077 unsigned int op_parse_code;
efd6b359 7078 bfd_boolean partial_match;
c19d1205 7079
e07e6e58
NC
7080#define po_char_or_fail(chr) \
7081 do \
7082 { \
7083 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7084 goto bad_args; \
e07e6e58
NC
7085 } \
7086 while (0)
c19d1205 7087
e07e6e58
NC
7088#define po_reg_or_fail(regtype) \
7089 do \
dcbf9037 7090 { \
e07e6e58 7091 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7092 & inst.operands[i].vectype); \
e07e6e58 7093 if (val == FAIL) \
477330fc
RM
7094 { \
7095 first_error (_(reg_expected_msgs[regtype])); \
7096 goto failure; \
7097 } \
e07e6e58
NC
7098 inst.operands[i].reg = val; \
7099 inst.operands[i].isreg = 1; \
7100 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7101 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7102 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7103 || rtype == REG_TYPE_VFD \
7104 || rtype == REG_TYPE_NQ); \
1b883319 7105 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7106 } \
e07e6e58
NC
7107 while (0)
7108
7109#define po_reg_or_goto(regtype, label) \
7110 do \
7111 { \
7112 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7113 & inst.operands[i].vectype); \
7114 if (val == FAIL) \
7115 goto label; \
dcbf9037 7116 \
e07e6e58
NC
7117 inst.operands[i].reg = val; \
7118 inst.operands[i].isreg = 1; \
7119 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7120 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7121 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7122 || rtype == REG_TYPE_VFD \
e07e6e58 7123 || rtype == REG_TYPE_NQ); \
1b883319 7124 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7125 } \
7126 while (0)
7127
7128#define po_imm_or_fail(min, max, popt) \
7129 do \
7130 { \
7131 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7132 goto failure; \
7133 inst.operands[i].imm = val; \
7134 } \
7135 while (0)
7136
57785aa2 7137#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7138 do \
7139 { \
57785aa2
AV
7140 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7141 reg_type); \
e07e6e58
NC
7142 if (val == FAIL) \
7143 goto label; \
7144 inst.operands[i].reg = val; \
7145 inst.operands[i].isscalar = 1; \
7146 } \
7147 while (0)
7148
7149#define po_misc_or_fail(expr) \
7150 do \
7151 { \
7152 if (expr) \
7153 goto failure; \
7154 } \
7155 while (0)
7156
7157#define po_misc_or_fail_no_backtrack(expr) \
7158 do \
7159 { \
7160 result = expr; \
7161 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7162 backtrack_pos = 0; \
7163 if (result != PARSE_OPERAND_SUCCESS) \
7164 goto failure; \
7165 } \
7166 while (0)
4962c51a 7167
52e7f43d
RE
7168#define po_barrier_or_imm(str) \
7169 do \
7170 { \
7171 val = parse_barrier (&str); \
ccb84d65
JB
7172 if (val == FAIL && ! ISALPHA (*str)) \
7173 goto immediate; \
7174 if (val == FAIL \
7175 /* ISB can only take SY as an option. */ \
7176 || ((inst.instruction & 0xf0) == 0x60 \
7177 && val != 0xf)) \
52e7f43d 7178 { \
ccb84d65
JB
7179 inst.error = _("invalid barrier type"); \
7180 backtrack_pos = 0; \
7181 goto failure; \
52e7f43d
RE
7182 } \
7183 } \
7184 while (0)
7185
c19d1205
ZW
7186 skip_whitespace (str);
7187
7188 for (i = 0; upat[i] != OP_stop; i++)
7189 {
5be8be5d
DG
7190 op_parse_code = upat[i];
7191 if (op_parse_code >= 1<<16)
7192 op_parse_code = thumb ? (op_parse_code >> 16)
7193 : (op_parse_code & ((1<<16)-1));
7194
7195 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7196 {
7197 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7198 backtrack_pos = str;
7199 backtrack_error = inst.error;
7200 backtrack_index = i;
7201 }
7202
b6702015 7203 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7204 po_char_or_fail (',');
7205
5be8be5d 7206 switch (op_parse_code)
c19d1205
ZW
7207 {
7208 /* Registers */
7209 case OP_oRRnpc:
5be8be5d 7210 case OP_oRRnpcsp:
c19d1205 7211 case OP_RRnpc:
5be8be5d 7212 case OP_RRnpcsp:
c19d1205 7213 case OP_oRR:
a302e574
AV
7214 case OP_RRe:
7215 case OP_RRo:
60f993ce
AV
7216 case OP_LR:
7217 case OP_oLR:
c19d1205
ZW
7218 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7219 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7220 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7221 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7222 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7223 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7224 case OP_oRND:
5ee91343
AV
7225 case OP_RNDMQR:
7226 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7227 break;
7228 try_rndmq:
7229 case OP_RNDMQ:
7230 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7231 break;
7232 try_rnd:
5287ad62 7233 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7234 case OP_RVC:
7235 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7236 break;
7237 /* Also accept generic coprocessor regs for unknown registers. */
7238 coproc_reg:
ba6cd17f
SD
7239 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7240 break;
7241 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7242 existing register with a value of 0, this seems like the
7243 best way to parse P0. */
7244 vpr_po:
7245 if (strncasecmp (str, "P0", 2) == 0)
7246 {
7247 str += 2;
7248 inst.operands[i].isreg = 1;
7249 inst.operands[i].reg = 13;
7250 }
7251 else
7252 goto failure;
cd2cf30b 7253 break;
c19d1205
ZW
7254 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7255 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7256 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7257 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7258 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7259 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7260 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7261 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7262 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7263 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7264 case OP_oRNQ:
5ee91343
AV
7265 case OP_RNQMQ:
7266 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7267 break;
7268 try_nq:
5287ad62 7269 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7270 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7271 case OP_RNDQMQR:
7272 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7273 break;
7274 try_rndqmq:
5ee91343
AV
7275 case OP_oRNDQMQ:
7276 case OP_RNDQMQ:
7277 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7278 break;
7279 try_rndq:
477330fc 7280 case OP_oRNDQ:
5287ad62 7281 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7282 case OP_RVSDMQ:
7283 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7284 break;
7285 try_rvsd:
477330fc 7286 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7287 case OP_RVSD_COND:
7288 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7289 break;
477330fc
RM
7290 case OP_oRNSDQ:
7291 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7292 case OP_RNSDQMQR:
7293 po_reg_or_goto (REG_TYPE_RN, try_mq);
7294 break;
7295 try_mq:
7296 case OP_oRNSDQMQ:
7297 case OP_RNSDQMQ:
7298 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7299 break;
7300 try_nsdq2:
7301 po_reg_or_fail (REG_TYPE_NSDQ);
7302 inst.error = 0;
7303 break;
35d1cfc2
AV
7304 case OP_RMQRR:
7305 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7306 break;
7307 try_rmq:
a302e574
AV
7308 case OP_RMQ:
7309 po_reg_or_fail (REG_TYPE_MQ);
7310 break;
477330fc
RM
7311 /* Neon scalar. Using an element size of 8 means that some invalid
7312 scalars are accepted here, so deal with those in later code. */
57785aa2 7313 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7314
7315 case OP_RNDQ_I0:
7316 {
7317 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7318 break;
7319 try_imm0:
7320 po_imm_or_fail (0, 0, TRUE);
7321 }
7322 break;
7323
7324 case OP_RVSD_I0:
7325 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7326 break;
7327
1b883319
AV
7328 case OP_RSVDMQ_FI0:
7329 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7330 break;
7331 try_rsvd_fi0:
aacf0b33
KT
7332 case OP_RSVD_FI0:
7333 {
7334 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7335 break;
7336 try_ifimm0:
7337 if (parse_ifimm_zero (&str))
7338 inst.operands[i].imm = 0;
7339 else
7340 {
7341 inst.error
7342 = _("only floating point zero is allowed as immediate value");
7343 goto failure;
7344 }
7345 }
7346 break;
7347
477330fc
RM
7348 case OP_RR_RNSC:
7349 {
57785aa2 7350 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7351 break;
7352 try_rr:
7353 po_reg_or_fail (REG_TYPE_RN);
7354 }
7355 break;
7356
a8465a06
AV
7357 case OP_RNSDQ_RNSC_MQ_RR:
7358 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7359 break;
7360 try_rnsdq_rnsc_mq:
886e1c73
AV
7361 case OP_RNSDQ_RNSC_MQ:
7362 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7363 break;
7364 try_rnsdq_rnsc:
477330fc
RM
7365 case OP_RNSDQ_RNSC:
7366 {
57785aa2
AV
7367 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7368 inst.error = 0;
477330fc
RM
7369 break;
7370 try_nsdq:
7371 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7372 inst.error = 0;
477330fc
RM
7373 }
7374 break;
7375
dec41383
JW
7376 case OP_RNSD_RNSC:
7377 {
57785aa2 7378 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7379 break;
7380 try_s_scalar:
57785aa2 7381 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7382 break;
7383 try_nsd:
7384 po_reg_or_fail (REG_TYPE_NSD);
7385 }
7386 break;
7387
42b16635
AV
7388 case OP_RNDQMQ_RNSC_RR:
7389 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7390 break;
7391 try_rndq_rnsc_rr:
7392 case OP_RNDQ_RNSC_RR:
7393 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7394 break;
5d281bf0
AV
7395 case OP_RNDQMQ_RNSC:
7396 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7397 break;
7398 try_rndq_rnsc:
477330fc
RM
7399 case OP_RNDQ_RNSC:
7400 {
57785aa2 7401 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7402 break;
7403 try_ndq:
7404 po_reg_or_fail (REG_TYPE_NDQ);
7405 }
7406 break;
7407
7408 case OP_RND_RNSC:
7409 {
57785aa2 7410 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7411 break;
7412 try_vfd:
7413 po_reg_or_fail (REG_TYPE_VFD);
7414 }
7415 break;
7416
7417 case OP_VMOV:
7418 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7419 not careful then bad things might happen. */
7420 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7421 break;
7422
f601a00c
AV
7423 case OP_RNDQMQ_Ibig:
7424 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7425 break;
7426 try_rndq_ibig:
477330fc
RM
7427 case OP_RNDQ_Ibig:
7428 {
7429 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7430 break;
7431 try_immbig:
7432 /* There's a possibility of getting a 64-bit immediate here, so
7433 we need special handling. */
8335d6aa
JW
7434 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7435 == FAIL)
477330fc
RM
7436 {
7437 inst.error = _("immediate value is out of range");
7438 goto failure;
7439 }
7440 }
7441 break;
7442
5150f0d8
AV
7443 case OP_RNDQMQ_I63b_RR:
7444 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7445 break;
7446 try_rndq_i63b_rr:
7447 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7448 break;
7449 try_rndq_i63b:
477330fc
RM
7450 case OP_RNDQ_I63b:
7451 {
7452 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7453 break;
7454 try_shimm:
7455 po_imm_or_fail (0, 63, TRUE);
7456 }
7457 break;
c19d1205
ZW
7458
7459 case OP_RRnpcb:
7460 po_char_or_fail ('[');
7461 po_reg_or_fail (REG_TYPE_RN);
7462 po_char_or_fail (']');
7463 break;
a737bd4d 7464
55881a11 7465 case OP_RRnpctw:
c19d1205 7466 case OP_RRw:
b6702015 7467 case OP_oRRw:
c19d1205
ZW
7468 po_reg_or_fail (REG_TYPE_RN);
7469 if (skip_past_char (&str, '!') == SUCCESS)
7470 inst.operands[i].writeback = 1;
7471 break;
7472
7473 /* Immediates */
7474 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7475 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7476 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7477 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7478 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7479 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7480 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 7481 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7482 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7483 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7484 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 7485 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
7486
7487 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7488 case OP_oI7b:
7489 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7490 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7491 case OP_oI31b:
7492 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7493 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7494 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7495 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7496
7497 /* Immediate variants */
7498 case OP_oI255c:
7499 po_char_or_fail ('{');
7500 po_imm_or_fail (0, 255, TRUE);
7501 po_char_or_fail ('}');
7502 break;
7503
7504 case OP_I31w:
7505 /* The expression parser chokes on a trailing !, so we have
7506 to find it first and zap it. */
7507 {
7508 char *s = str;
7509 while (*s && *s != ',')
7510 s++;
7511 if (s[-1] == '!')
7512 {
7513 s[-1] = '\0';
7514 inst.operands[i].writeback = 1;
7515 }
7516 po_imm_or_fail (0, 31, TRUE);
7517 if (str == s - 1)
7518 str = s;
7519 }
7520 break;
7521
7522 /* Expressions */
7523 case OP_EXPi: EXPi:
e2b0ab59 7524 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7525 GE_OPT_PREFIX));
7526 break;
7527
7528 case OP_EXP:
e2b0ab59 7529 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7530 GE_NO_PREFIX));
7531 break;
7532
7533 case OP_EXPr: EXPr:
e2b0ab59 7534 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7535 GE_NO_PREFIX));
e2b0ab59 7536 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7537 {
c19d1205
ZW
7538 val = parse_reloc (&str);
7539 if (val == -1)
7540 {
7541 inst.error = _("unrecognized relocation suffix");
7542 goto failure;
7543 }
7544 else if (val != BFD_RELOC_UNUSED)
7545 {
7546 inst.operands[i].imm = val;
7547 inst.operands[i].hasreloc = 1;
7548 }
a737bd4d 7549 }
c19d1205 7550 break;
a737bd4d 7551
e2b0ab59
AV
7552 case OP_EXPs:
7553 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7554 GE_NO_PREFIX));
7555 if (inst.relocs[i].exp.X_op == O_symbol)
7556 {
7557 inst.operands[i].hasreloc = 1;
7558 }
7559 else if (inst.relocs[i].exp.X_op == O_constant)
7560 {
7561 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7562 inst.operands[i].hasreloc = 0;
7563 }
7564 break;
7565
b6895b4f
PB
7566 /* Operand for MOVW or MOVT. */
7567 case OP_HALF:
7568 po_misc_or_fail (parse_half (&str));
7569 break;
7570
e07e6e58 7571 /* Register or expression. */
c19d1205
ZW
7572 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7573 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7574
e07e6e58 7575 /* Register or immediate. */
c19d1205
ZW
7576 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7577 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7578
23d00a41
SD
7579 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7580 I32: po_imm_or_fail (1, 32, FALSE); break;
7581
c19d1205
ZW
7582 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7583 IF:
7584 if (!is_immediate_prefix (*str))
7585 goto bad_args;
7586 str++;
7587 val = parse_fpa_immediate (&str);
7588 if (val == FAIL)
7589 goto failure;
7590 /* FPA immediates are encoded as registers 8-15.
7591 parse_fpa_immediate has already applied the offset. */
7592 inst.operands[i].reg = val;
7593 inst.operands[i].isreg = 1;
7594 break;
09d92015 7595
2d447fca
JM
7596 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7597 I32z: po_imm_or_fail (0, 32, FALSE); break;
7598
e07e6e58 7599 /* Two kinds of register. */
c19d1205
ZW
7600 case OP_RIWR_RIWC:
7601 {
7602 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7603 if (!rege
7604 || (rege->type != REG_TYPE_MMXWR
7605 && rege->type != REG_TYPE_MMXWC
7606 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7607 {
7608 inst.error = _("iWMMXt data or control register expected");
7609 goto failure;
7610 }
7611 inst.operands[i].reg = rege->number;
7612 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7613 }
7614 break;
09d92015 7615
41adaa5c
JM
7616 case OP_RIWC_RIWG:
7617 {
7618 struct reg_entry *rege = arm_reg_parse_multi (&str);
7619 if (!rege
7620 || (rege->type != REG_TYPE_MMXWC
7621 && rege->type != REG_TYPE_MMXWCG))
7622 {
7623 inst.error = _("iWMMXt control register expected");
7624 goto failure;
7625 }
7626 inst.operands[i].reg = rege->number;
7627 inst.operands[i].isreg = 1;
7628 }
7629 break;
7630
c19d1205
ZW
7631 /* Misc */
7632 case OP_CPSF: val = parse_cps_flags (&str); break;
7633 case OP_ENDI: val = parse_endian_specifier (&str); break;
7634 case OP_oROR: val = parse_ror (&str); break;
1b883319 7635 try_cond:
c19d1205 7636 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7637 case OP_oBARRIER_I15:
7638 po_barrier_or_imm (str); break;
7639 immediate:
7640 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7641 goto failure;
52e7f43d 7642 break;
c19d1205 7643
fa94de6b 7644 case OP_wPSR:
d2cd1205 7645 case OP_rPSR:
90ec0d68
MGD
7646 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7647 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7648 {
7649 inst.error = _("Banked registers are not available with this "
7650 "architecture.");
7651 goto failure;
7652 }
7653 break;
d2cd1205
JB
7654 try_psr:
7655 val = parse_psr (&str, op_parse_code == OP_wPSR);
7656 break;
037e8744 7657
32c36c3c
AV
7658 case OP_VLDR:
7659 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7660 break;
7661 try_sysreg:
7662 val = parse_sys_vldr_vstr (&str);
7663 break;
7664
477330fc
RM
7665 case OP_APSR_RR:
7666 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7667 break;
7668 try_apsr:
7669 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7670 instruction). */
7671 if (strncasecmp (str, "APSR_", 5) == 0)
7672 {
7673 unsigned found = 0;
7674 str += 5;
7675 while (found < 15)
7676 switch (*str++)
7677 {
7678 case 'c': found = (found & 1) ? 16 : found | 1; break;
7679 case 'n': found = (found & 2) ? 16 : found | 2; break;
7680 case 'z': found = (found & 4) ? 16 : found | 4; break;
7681 case 'v': found = (found & 8) ? 16 : found | 8; break;
7682 default: found = 16;
7683 }
7684 if (found != 15)
7685 goto failure;
7686 inst.operands[i].isvec = 1;
f7c21dc7
NC
7687 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7688 inst.operands[i].reg = REG_PC;
477330fc
RM
7689 }
7690 else
7691 goto failure;
7692 break;
037e8744 7693
92e90b6e
PB
7694 case OP_TB:
7695 po_misc_or_fail (parse_tb (&str));
7696 break;
7697
e07e6e58 7698 /* Register lists. */
c19d1205 7699 case OP_REGLST:
4b5a202f 7700 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7701 if (*str == '^')
7702 {
5e0d7f77 7703 inst.operands[i].writeback = 1;
c19d1205
ZW
7704 str++;
7705 }
7706 break;
09d92015 7707
4b5a202f
AV
7708 case OP_CLRMLST:
7709 val = parse_reg_list (&str, REGLIST_CLRM);
7710 break;
7711
c19d1205 7712 case OP_VRSLST:
efd6b359
AV
7713 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7714 &partial_match);
c19d1205 7715 break;
09d92015 7716
c19d1205 7717 case OP_VRDLST:
efd6b359
AV
7718 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7719 &partial_match);
c19d1205 7720 break;
a737bd4d 7721
477330fc
RM
7722 case OP_VRSDLST:
7723 /* Allow Q registers too. */
7724 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7725 REGLIST_NEON_D, &partial_match);
477330fc
RM
7726 if (val == FAIL)
7727 {
7728 inst.error = NULL;
7729 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7730 REGLIST_VFP_S, &partial_match);
7731 inst.operands[i].issingle = 1;
7732 }
7733 break;
7734
7735 case OP_VRSDVLST:
7736 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7737 REGLIST_VFP_D_VPR, &partial_match);
7738 if (val == FAIL && !partial_match)
7739 {
7740 inst.error = NULL;
7741 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7742 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7743 inst.operands[i].issingle = 1;
7744 }
7745 break;
7746
7747 case OP_NRDLST:
7748 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7749 REGLIST_NEON_D, &partial_match);
477330fc 7750 break;
5287ad62 7751
35c228db
AV
7752 case OP_MSTRLST4:
7753 case OP_MSTRLST2:
7754 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7755 1, &inst.operands[i].vectype);
7756 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7757 goto failure;
7758 break;
5287ad62 7759 case OP_NSTRLST:
477330fc 7760 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7761 0, &inst.operands[i].vectype);
477330fc 7762 break;
5287ad62 7763
c19d1205 7764 /* Addressing modes */
35c228db
AV
7765 case OP_ADDRMVE:
7766 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7767 break;
7768
c19d1205
ZW
7769 case OP_ADDR:
7770 po_misc_or_fail (parse_address (&str, i));
7771 break;
09d92015 7772
4962c51a
MS
7773 case OP_ADDRGLDR:
7774 po_misc_or_fail_no_backtrack (
477330fc 7775 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7776 break;
7777
7778 case OP_ADDRGLDRS:
7779 po_misc_or_fail_no_backtrack (
477330fc 7780 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7781 break;
7782
7783 case OP_ADDRGLDC:
7784 po_misc_or_fail_no_backtrack (
477330fc 7785 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7786 break;
7787
c19d1205
ZW
7788 case OP_SH:
7789 po_misc_or_fail (parse_shifter_operand (&str, i));
7790 break;
09d92015 7791
4962c51a
MS
7792 case OP_SHG:
7793 po_misc_or_fail_no_backtrack (
477330fc 7794 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7795 break;
7796
c19d1205
ZW
7797 case OP_oSHll:
7798 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7799 break;
09d92015 7800
c19d1205
ZW
7801 case OP_oSHar:
7802 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7803 break;
09d92015 7804
c19d1205
ZW
7805 case OP_oSHllar:
7806 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7807 break;
09d92015 7808
1b883319
AV
7809 case OP_RMQRZ:
7810 case OP_oRMQRZ:
7811 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
7812 break;
e39c1607
SD
7813
7814 case OP_RR_ZR:
1b883319
AV
7815 try_rr_zr:
7816 po_reg_or_goto (REG_TYPE_RN, ZR);
7817 break;
7818 ZR:
7819 po_reg_or_fail (REG_TYPE_ZR);
7820 break;
7821
c19d1205 7822 default:
5be8be5d 7823 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7824 }
09d92015 7825
c19d1205
ZW
7826 /* Various value-based sanity checks and shared operations. We
7827 do not signal immediate failures for the register constraints;
7828 this allows a syntax error to take precedence. */
5be8be5d 7829 switch (op_parse_code)
c19d1205
ZW
7830 {
7831 case OP_oRRnpc:
7832 case OP_RRnpc:
7833 case OP_RRnpcb:
7834 case OP_RRw:
b6702015 7835 case OP_oRRw:
c19d1205
ZW
7836 case OP_RRnpc_I0:
7837 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7838 inst.error = BAD_PC;
7839 break;
09d92015 7840
5be8be5d
DG
7841 case OP_oRRnpcsp:
7842 case OP_RRnpcsp:
23d00a41 7843 case OP_RRnpcsp_I32:
5be8be5d
DG
7844 if (inst.operands[i].isreg)
7845 {
7846 if (inst.operands[i].reg == REG_PC)
7847 inst.error = BAD_PC;
5c8ed6a4
JW
7848 else if (inst.operands[i].reg == REG_SP
7849 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7850 relaxed since ARMv8-A. */
7851 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7852 {
7853 gas_assert (thumb);
7854 inst.error = BAD_SP;
7855 }
5be8be5d
DG
7856 }
7857 break;
7858
55881a11 7859 case OP_RRnpctw:
fa94de6b
RM
7860 if (inst.operands[i].isreg
7861 && inst.operands[i].reg == REG_PC
55881a11
MGD
7862 && (inst.operands[i].writeback || thumb))
7863 inst.error = BAD_PC;
7864 break;
7865
1b883319 7866 case OP_RVSD_COND:
32c36c3c
AV
7867 case OP_VLDR:
7868 if (inst.operands[i].isreg)
7869 break;
7870 /* fall through. */
1b883319 7871
c19d1205
ZW
7872 case OP_CPSF:
7873 case OP_ENDI:
7874 case OP_oROR:
d2cd1205
JB
7875 case OP_wPSR:
7876 case OP_rPSR:
c19d1205 7877 case OP_COND:
52e7f43d 7878 case OP_oBARRIER_I15:
c19d1205 7879 case OP_REGLST:
4b5a202f 7880 case OP_CLRMLST:
c19d1205
ZW
7881 case OP_VRSLST:
7882 case OP_VRDLST:
477330fc 7883 case OP_VRSDLST:
efd6b359 7884 case OP_VRSDVLST:
477330fc
RM
7885 case OP_NRDLST:
7886 case OP_NSTRLST:
35c228db
AV
7887 case OP_MSTRLST2:
7888 case OP_MSTRLST4:
c19d1205
ZW
7889 if (val == FAIL)
7890 goto failure;
7891 inst.operands[i].imm = val;
7892 break;
a737bd4d 7893
60f993ce
AV
7894 case OP_LR:
7895 case OP_oLR:
7896 if (inst.operands[i].reg != REG_LR)
7897 inst.error = _("operand must be LR register");
7898 break;
7899
1b883319
AV
7900 case OP_RMQRZ:
7901 case OP_oRMQRZ:
e39c1607 7902 case OP_RR_ZR:
1b883319
AV
7903 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
7904 inst.error = BAD_PC;
7905 break;
7906
a302e574
AV
7907 case OP_RRe:
7908 if (inst.operands[i].isreg
7909 && (inst.operands[i].reg & 0x00000001) != 0)
7910 inst.error = BAD_ODD;
7911 break;
7912
7913 case OP_RRo:
7914 if (inst.operands[i].isreg)
7915 {
7916 if ((inst.operands[i].reg & 0x00000001) != 1)
7917 inst.error = BAD_EVEN;
7918 else if (inst.operands[i].reg == REG_SP)
7919 as_tsktsk (MVE_BAD_SP);
7920 else if (inst.operands[i].reg == REG_PC)
7921 inst.error = BAD_PC;
7922 }
7923 break;
7924
c19d1205
ZW
7925 default:
7926 break;
7927 }
09d92015 7928
c19d1205
ZW
7929 /* If we get here, this operand was successfully parsed. */
7930 inst.operands[i].present = 1;
7931 continue;
09d92015 7932
c19d1205 7933 bad_args:
09d92015 7934 inst.error = BAD_ARGS;
c19d1205
ZW
7935
7936 failure:
7937 if (!backtrack_pos)
d252fdde
PB
7938 {
7939 /* The parse routine should already have set inst.error, but set a
5f4273c7 7940 default here just in case. */
d252fdde 7941 if (!inst.error)
5ee91343 7942 inst.error = BAD_SYNTAX;
d252fdde
PB
7943 return FAIL;
7944 }
c19d1205
ZW
7945
7946 /* Do not backtrack over a trailing optional argument that
7947 absorbed some text. We will only fail again, with the
7948 'garbage following instruction' error message, which is
7949 probably less helpful than the current one. */
7950 if (backtrack_index == i && backtrack_pos != str
7951 && upat[i+1] == OP_stop)
d252fdde
PB
7952 {
7953 if (!inst.error)
5ee91343 7954 inst.error = BAD_SYNTAX;
d252fdde
PB
7955 return FAIL;
7956 }
c19d1205
ZW
7957
7958 /* Try again, skipping the optional argument at backtrack_pos. */
7959 str = backtrack_pos;
7960 inst.error = backtrack_error;
7961 inst.operands[backtrack_index].present = 0;
7962 i = backtrack_index;
7963 backtrack_pos = 0;
09d92015 7964 }
09d92015 7965
c19d1205
ZW
7966 /* Check that we have parsed all the arguments. */
7967 if (*str != '\0' && !inst.error)
7968 inst.error = _("garbage following instruction");
09d92015 7969
c19d1205 7970 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7971}
7972
c19d1205
ZW
7973#undef po_char_or_fail
7974#undef po_reg_or_fail
7975#undef po_reg_or_goto
7976#undef po_imm_or_fail
5287ad62 7977#undef po_scalar_or_fail
52e7f43d 7978#undef po_barrier_or_imm
e07e6e58 7979
c19d1205 7980/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7981#define constraint(expr, err) \
7982 do \
c19d1205 7983 { \
e07e6e58
NC
7984 if (expr) \
7985 { \
7986 inst.error = err; \
7987 return; \
7988 } \
c19d1205 7989 } \
e07e6e58 7990 while (0)
c19d1205 7991
fdfde340
JM
7992/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7993 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7994 is the BadReg predicate in ARM's Thumb-2 documentation.
7995
7996 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7997 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7998#define reject_bad_reg(reg) \
7999 do \
8000 if (reg == REG_PC) \
8001 { \
8002 inst.error = BAD_PC; \
8003 return; \
8004 } \
8005 else if (reg == REG_SP \
8006 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8007 { \
8008 inst.error = BAD_SP; \
8009 return; \
8010 } \
fdfde340
JM
8011 while (0)
8012
94206790
MM
8013/* If REG is R13 (the stack pointer), warn that its use is
8014 deprecated. */
8015#define warn_deprecated_sp(reg) \
8016 do \
8017 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8018 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8019 while (0)
8020
c19d1205
ZW
8021/* Functions for operand encoding. ARM, then Thumb. */
8022
d840c081 8023#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8024
9db2f6b4
RL
8025/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8026
8027 The only binary encoding difference is the Coprocessor number. Coprocessor
8028 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8029 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8030 exists for Single-Precision operation. */
8031
8032static void
8033do_scalar_fp16_v82_encode (void)
8034{
5ee91343 8035 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8036 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8037 " the behaviour is UNPREDICTABLE"));
8038 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8039 _(BAD_FP16));
8040
8041 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8042 mark_feature_used (&arm_ext_fp16);
8043}
8044
c19d1205
ZW
8045/* If VAL can be encoded in the immediate field of an ARM instruction,
8046 return the encoded form. Otherwise, return FAIL. */
8047
8048static unsigned int
8049encode_arm_immediate (unsigned int val)
09d92015 8050{
c19d1205
ZW
8051 unsigned int a, i;
8052
4f1d6205
L
8053 if (val <= 0xff)
8054 return val;
8055
8056 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8057 if ((a = rotate_left (val, i)) <= 0xff)
8058 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8059
8060 return FAIL;
09d92015
MM
8061}
8062
c19d1205
ZW
8063/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8064 return the encoded form. Otherwise, return FAIL. */
8065static unsigned int
8066encode_thumb32_immediate (unsigned int val)
09d92015 8067{
c19d1205 8068 unsigned int a, i;
09d92015 8069
9c3c69f2 8070 if (val <= 0xff)
c19d1205 8071 return val;
a737bd4d 8072
9c3c69f2 8073 for (i = 1; i <= 24; i++)
09d92015 8074 {
9c3c69f2
PB
8075 a = val >> i;
8076 if ((val & ~(0xff << i)) == 0)
8077 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8078 }
a737bd4d 8079
c19d1205
ZW
8080 a = val & 0xff;
8081 if (val == ((a << 16) | a))
8082 return 0x100 | a;
8083 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8084 return 0x300 | a;
09d92015 8085
c19d1205
ZW
8086 a = val & 0xff00;
8087 if (val == ((a << 16) | a))
8088 return 0x200 | (a >> 8);
a737bd4d 8089
c19d1205 8090 return FAIL;
09d92015 8091}
5287ad62 8092/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8093
8094static void
5287ad62
JB
8095encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8096{
8097 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8098 && reg > 15)
8099 {
b1cc4aeb 8100 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8101 {
8102 if (thumb_mode)
8103 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8104 fpu_vfp_ext_d32);
8105 else
8106 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8107 fpu_vfp_ext_d32);
8108 }
5287ad62 8109 else
477330fc
RM
8110 {
8111 first_error (_("D register out of range for selected VFP version"));
8112 return;
8113 }
5287ad62
JB
8114 }
8115
c19d1205 8116 switch (pos)
09d92015 8117 {
c19d1205
ZW
8118 case VFP_REG_Sd:
8119 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8120 break;
8121
8122 case VFP_REG_Sn:
8123 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8124 break;
8125
8126 case VFP_REG_Sm:
8127 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8128 break;
8129
5287ad62
JB
8130 case VFP_REG_Dd:
8131 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8132 break;
5f4273c7 8133
5287ad62
JB
8134 case VFP_REG_Dn:
8135 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8136 break;
5f4273c7 8137
5287ad62
JB
8138 case VFP_REG_Dm:
8139 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8140 break;
8141
c19d1205
ZW
8142 default:
8143 abort ();
09d92015 8144 }
09d92015
MM
8145}
8146
c19d1205 8147/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8148 if any, is handled by md_apply_fix. */
09d92015 8149static void
c19d1205 8150encode_arm_shift (int i)
09d92015 8151{
008a97ef
RL
8152 /* register-shifted register. */
8153 if (inst.operands[i].immisreg)
8154 {
bf355b69
MR
8155 int op_index;
8156 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8157 {
5689c942
RL
8158 /* Check the operand only when it's presented. In pre-UAL syntax,
8159 if the destination register is the same as the first operand, two
8160 register form of the instruction can be used. */
bf355b69
MR
8161 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8162 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8163 as_warn (UNPRED_REG ("r15"));
8164 }
8165
8166 if (inst.operands[i].imm == REG_PC)
8167 as_warn (UNPRED_REG ("r15"));
8168 }
8169
c19d1205
ZW
8170 if (inst.operands[i].shift_kind == SHIFT_RRX)
8171 inst.instruction |= SHIFT_ROR << 5;
8172 else
09d92015 8173 {
c19d1205
ZW
8174 inst.instruction |= inst.operands[i].shift_kind << 5;
8175 if (inst.operands[i].immisreg)
8176 {
8177 inst.instruction |= SHIFT_BY_REG;
8178 inst.instruction |= inst.operands[i].imm << 8;
8179 }
8180 else
e2b0ab59 8181 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8182 }
c19d1205 8183}
09d92015 8184
c19d1205
ZW
8185static void
8186encode_arm_shifter_operand (int i)
8187{
8188 if (inst.operands[i].isreg)
09d92015 8189 {
c19d1205
ZW
8190 inst.instruction |= inst.operands[i].reg;
8191 encode_arm_shift (i);
09d92015 8192 }
c19d1205 8193 else
a415b1cd
JB
8194 {
8195 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8196 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8197 inst.instruction |= inst.operands[i].imm;
8198 }
09d92015
MM
8199}
8200
c19d1205 8201/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8202static void
c19d1205 8203encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8204{
2b2f5df9
NC
8205 /* PR 14260:
8206 Generate an error if the operand is not a register. */
8207 constraint (!inst.operands[i].isreg,
8208 _("Instruction does not support =N addresses"));
8209
c19d1205 8210 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8211
c19d1205 8212 if (inst.operands[i].preind)
09d92015 8213 {
c19d1205
ZW
8214 if (is_t)
8215 {
8216 inst.error = _("instruction does not accept preindexed addressing");
8217 return;
8218 }
8219 inst.instruction |= PRE_INDEX;
8220 if (inst.operands[i].writeback)
8221 inst.instruction |= WRITE_BACK;
09d92015 8222
c19d1205
ZW
8223 }
8224 else if (inst.operands[i].postind)
8225 {
9c2799c2 8226 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8227 if (is_t)
8228 inst.instruction |= WRITE_BACK;
8229 }
8230 else /* unindexed - only for coprocessor */
09d92015 8231 {
c19d1205 8232 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8233 return;
8234 }
8235
c19d1205
ZW
8236 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8237 && (((inst.instruction & 0x000f0000) >> 16)
8238 == ((inst.instruction & 0x0000f000) >> 12)))
8239 as_warn ((inst.instruction & LOAD_BIT)
8240 ? _("destination register same as write-back base")
8241 : _("source register same as write-back base"));
09d92015
MM
8242}
8243
c19d1205
ZW
8244/* inst.operands[i] was set up by parse_address. Encode it into an
8245 ARM-format mode 2 load or store instruction. If is_t is true,
8246 reject forms that cannot be used with a T instruction (i.e. not
8247 post-indexed). */
a737bd4d 8248static void
c19d1205 8249encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8250{
5be8be5d
DG
8251 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8252
c19d1205 8253 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8254
c19d1205 8255 if (inst.operands[i].immisreg)
09d92015 8256 {
5be8be5d
DG
8257 constraint ((inst.operands[i].imm == REG_PC
8258 || (is_pc && inst.operands[i].writeback)),
8259 BAD_PC_ADDRESSING);
c19d1205
ZW
8260 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8261 inst.instruction |= inst.operands[i].imm;
8262 if (!inst.operands[i].negative)
8263 inst.instruction |= INDEX_UP;
8264 if (inst.operands[i].shifted)
8265 {
8266 if (inst.operands[i].shift_kind == SHIFT_RRX)
8267 inst.instruction |= SHIFT_ROR << 5;
8268 else
8269 {
8270 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8271 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8272 }
8273 }
09d92015 8274 }
e2b0ab59 8275 else /* immediate offset in inst.relocs[0] */
09d92015 8276 {
e2b0ab59 8277 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8278 {
8279 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8280
8281 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8282 cannot use PC in addressing.
8283 PC cannot be used in writeback addressing, either. */
8284 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8285 BAD_PC_ADDRESSING);
23a10334 8286
dc5ec521 8287 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8288 if (warn_on_deprecated
8289 && !is_load
8290 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8291 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8292 }
8293
e2b0ab59 8294 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8295 {
8296 /* Prefer + for zero encoded value. */
8297 if (!inst.operands[i].negative)
8298 inst.instruction |= INDEX_UP;
e2b0ab59 8299 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8300 }
09d92015 8301 }
09d92015
MM
8302}
8303
c19d1205
ZW
8304/* inst.operands[i] was set up by parse_address. Encode it into an
8305 ARM-format mode 3 load or store instruction. Reject forms that
8306 cannot be used with such instructions. If is_t is true, reject
8307 forms that cannot be used with a T instruction (i.e. not
8308 post-indexed). */
8309static void
8310encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8311{
c19d1205 8312 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8313 {
c19d1205
ZW
8314 inst.error = _("instruction does not accept scaled register index");
8315 return;
09d92015 8316 }
a737bd4d 8317
c19d1205 8318 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8319
c19d1205
ZW
8320 if (inst.operands[i].immisreg)
8321 {
5be8be5d 8322 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8323 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8324 BAD_PC_ADDRESSING);
eb9f3f00
JB
8325 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8326 BAD_PC_WRITEBACK);
c19d1205
ZW
8327 inst.instruction |= inst.operands[i].imm;
8328 if (!inst.operands[i].negative)
8329 inst.instruction |= INDEX_UP;
8330 }
e2b0ab59 8331 else /* immediate offset in inst.relocs[0] */
c19d1205 8332 {
e2b0ab59 8333 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8334 && inst.operands[i].writeback),
8335 BAD_PC_WRITEBACK);
c19d1205 8336 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8337 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8338 {
8339 /* Prefer + for zero encoded value. */
8340 if (!inst.operands[i].negative)
8341 inst.instruction |= INDEX_UP;
8342
e2b0ab59 8343 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8344 }
c19d1205 8345 }
a737bd4d
NC
8346}
8347
8335d6aa
JW
8348/* Write immediate bits [7:0] to the following locations:
8349
8350 |28/24|23 19|18 16|15 4|3 0|
8351 | 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|
8352
8353 This function is used by VMOV/VMVN/VORR/VBIC. */
8354
8355static void
8356neon_write_immbits (unsigned immbits)
8357{
8358 inst.instruction |= immbits & 0xf;
8359 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8360 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8361}
8362
8363/* Invert low-order SIZE bits of XHI:XLO. */
8364
8365static void
8366neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8367{
8368 unsigned immlo = xlo ? *xlo : 0;
8369 unsigned immhi = xhi ? *xhi : 0;
8370
8371 switch (size)
8372 {
8373 case 8:
8374 immlo = (~immlo) & 0xff;
8375 break;
8376
8377 case 16:
8378 immlo = (~immlo) & 0xffff;
8379 break;
8380
8381 case 64:
8382 immhi = (~immhi) & 0xffffffff;
8383 /* fall through. */
8384
8385 case 32:
8386 immlo = (~immlo) & 0xffffffff;
8387 break;
8388
8389 default:
8390 abort ();
8391 }
8392
8393 if (xlo)
8394 *xlo = immlo;
8395
8396 if (xhi)
8397 *xhi = immhi;
8398}
8399
8400/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8401 A, B, C, D. */
09d92015 8402
c19d1205 8403static int
8335d6aa 8404neon_bits_same_in_bytes (unsigned imm)
09d92015 8405{
8335d6aa
JW
8406 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8407 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8408 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8409 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8410}
a737bd4d 8411
8335d6aa 8412/* For immediate of above form, return 0bABCD. */
09d92015 8413
8335d6aa
JW
8414static unsigned
8415neon_squash_bits (unsigned imm)
8416{
8417 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8418 | ((imm & 0x01000000) >> 21);
8419}
8420
8421/* Compress quarter-float representation to 0b...000 abcdefgh. */
8422
8423static unsigned
8424neon_qfloat_bits (unsigned imm)
8425{
8426 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8427}
8428
8429/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8430 the instruction. *OP is passed as the initial value of the op field, and
8431 may be set to a different value depending on the constant (i.e.
8432 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8433 MVN). If the immediate looks like a repeated pattern then also
8434 try smaller element sizes. */
8435
8436static int
8437neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8438 unsigned *immbits, int *op, int size,
8439 enum neon_el_type type)
8440{
8441 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8442 float. */
8443 if (type == NT_float && !float_p)
8444 return FAIL;
8445
8446 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8447 {
8335d6aa
JW
8448 if (size != 32 || *op == 1)
8449 return FAIL;
8450 *immbits = neon_qfloat_bits (immlo);
8451 return 0xf;
8452 }
8453
8454 if (size == 64)
8455 {
8456 if (neon_bits_same_in_bytes (immhi)
8457 && neon_bits_same_in_bytes (immlo))
c19d1205 8458 {
8335d6aa
JW
8459 if (*op == 1)
8460 return FAIL;
8461 *immbits = (neon_squash_bits (immhi) << 4)
8462 | neon_squash_bits (immlo);
8463 *op = 1;
8464 return 0xe;
c19d1205 8465 }
a737bd4d 8466
8335d6aa
JW
8467 if (immhi != immlo)
8468 return FAIL;
8469 }
a737bd4d 8470
8335d6aa 8471 if (size >= 32)
09d92015 8472 {
8335d6aa 8473 if (immlo == (immlo & 0x000000ff))
c19d1205 8474 {
8335d6aa
JW
8475 *immbits = immlo;
8476 return 0x0;
c19d1205 8477 }
8335d6aa 8478 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8479 {
8335d6aa
JW
8480 *immbits = immlo >> 8;
8481 return 0x2;
c19d1205 8482 }
8335d6aa
JW
8483 else if (immlo == (immlo & 0x00ff0000))
8484 {
8485 *immbits = immlo >> 16;
8486 return 0x4;
8487 }
8488 else if (immlo == (immlo & 0xff000000))
8489 {
8490 *immbits = immlo >> 24;
8491 return 0x6;
8492 }
8493 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8494 {
8495 *immbits = (immlo >> 8) & 0xff;
8496 return 0xc;
8497 }
8498 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8499 {
8500 *immbits = (immlo >> 16) & 0xff;
8501 return 0xd;
8502 }
8503
8504 if ((immlo & 0xffff) != (immlo >> 16))
8505 return FAIL;
8506 immlo &= 0xffff;
09d92015 8507 }
a737bd4d 8508
8335d6aa 8509 if (size >= 16)
4962c51a 8510 {
8335d6aa
JW
8511 if (immlo == (immlo & 0x000000ff))
8512 {
8513 *immbits = immlo;
8514 return 0x8;
8515 }
8516 else if (immlo == (immlo & 0x0000ff00))
8517 {
8518 *immbits = immlo >> 8;
8519 return 0xa;
8520 }
8521
8522 if ((immlo & 0xff) != (immlo >> 8))
8523 return FAIL;
8524 immlo &= 0xff;
4962c51a
MS
8525 }
8526
8335d6aa
JW
8527 if (immlo == (immlo & 0x000000ff))
8528 {
8529 /* Don't allow MVN with 8-bit immediate. */
8530 if (*op == 1)
8531 return FAIL;
8532 *immbits = immlo;
8533 return 0xe;
8534 }
26d97720 8535
8335d6aa 8536 return FAIL;
c19d1205 8537}
a737bd4d 8538
5fc177c8 8539#if defined BFD_HOST_64_BIT
ba592044
AM
8540/* Returns TRUE if double precision value V may be cast
8541 to single precision without loss of accuracy. */
8542
8543static bfd_boolean
5fc177c8 8544is_double_a_single (bfd_int64_t v)
ba592044 8545{
5fc177c8 8546 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 8547 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8548
8549 return (exp == 0 || exp == 0x7FF
8550 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8551 && (mantissa & 0x1FFFFFFFl) == 0;
8552}
8553
3739860c 8554/* Returns a double precision value casted to single precision
ba592044
AM
8555 (ignoring the least significant bits in exponent and mantissa). */
8556
8557static int
5fc177c8 8558double_to_single (bfd_int64_t v)
ba592044
AM
8559{
8560 int sign = (int) ((v >> 63) & 1l);
5fc177c8 8561 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 8562 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
8563
8564 if (exp == 0x7FF)
8565 exp = 0xFF;
8566 else
8567 {
8568 exp = exp - 1023 + 127;
8569 if (exp >= 0xFF)
8570 {
8571 /* Infinity. */
8572 exp = 0x7F;
8573 mantissa = 0;
8574 }
8575 else if (exp < 0)
8576 {
8577 /* No denormalized numbers. */
8578 exp = 0;
8579 mantissa = 0;
8580 }
8581 }
8582 mantissa >>= 29;
8583 return (sign << 31) | (exp << 23) | mantissa;
8584}
5fc177c8 8585#endif /* BFD_HOST_64_BIT */
ba592044 8586
8335d6aa
JW
8587enum lit_type
8588{
8589 CONST_THUMB,
8590 CONST_ARM,
8591 CONST_VEC
8592};
8593
ba592044
AM
8594static void do_vfp_nsyn_opcode (const char *);
8595
e2b0ab59 8596/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8597 Determine whether it can be performed with a move instruction; if
8598 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8599 return TRUE; if it can't, convert inst.instruction to a literal-pool
8600 load and return FALSE. If this is not a valid thing to do in the
8601 current context, set inst.error and return TRUE.
a737bd4d 8602
c19d1205
ZW
8603 inst.operands[i] describes the destination register. */
8604
c921be7d 8605static bfd_boolean
8335d6aa 8606move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8607{
53365c0d 8608 unsigned long tbit;
8335d6aa
JW
8609 bfd_boolean thumb_p = (t == CONST_THUMB);
8610 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8611
8612 if (thumb_p)
8613 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8614 else
8615 tbit = LOAD_BIT;
8616
8617 if ((inst.instruction & tbit) == 0)
09d92015 8618 {
c19d1205 8619 inst.error = _("invalid pseudo operation");
c921be7d 8620 return TRUE;
09d92015 8621 }
ba592044 8622
e2b0ab59
AV
8623 if (inst.relocs[0].exp.X_op != O_constant
8624 && inst.relocs[0].exp.X_op != O_symbol
8625 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8626 {
8627 inst.error = _("constant expression expected");
c921be7d 8628 return TRUE;
09d92015 8629 }
ba592044 8630
e2b0ab59
AV
8631 if (inst.relocs[0].exp.X_op == O_constant
8632 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8633 {
5fc177c8
NC
8634#if defined BFD_HOST_64_BIT
8635 bfd_int64_t v;
8636#else
ba592044 8637 offsetT v;
5fc177c8 8638#endif
e2b0ab59 8639 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8640 {
ba592044
AM
8641 LITTLENUM_TYPE w[X_PRECISION];
8642 LITTLENUM_TYPE * l;
8643
e2b0ab59 8644 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8645 {
ba592044
AM
8646 gen_to_words (w, X_PRECISION, E_PRECISION);
8647 l = w;
8648 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8649 }
ba592044
AM
8650 else
8651 l = generic_bignum;
3739860c 8652
5fc177c8
NC
8653#if defined BFD_HOST_64_BIT
8654 v =
8655 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8656 << LITTLENUM_NUMBER_OF_BITS)
8657 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8658 << LITTLENUM_NUMBER_OF_BITS)
8659 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8660 << LITTLENUM_NUMBER_OF_BITS)
8661 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8662#else
ba592044
AM
8663 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8664 | (l[0] & LITTLENUM_MASK);
5fc177c8 8665#endif
8335d6aa 8666 }
ba592044 8667 else
e2b0ab59 8668 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8669
8670 if (!inst.operands[i].issingle)
8335d6aa 8671 {
12569877 8672 if (thumb_p)
8335d6aa 8673 {
53445554
TP
8674 /* LDR should not use lead in a flag-setting instruction being
8675 chosen so we do not check whether movs can be used. */
12569877 8676
53445554 8677 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8678 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8679 && inst.operands[i].reg != 13
8680 && inst.operands[i].reg != 15)
12569877 8681 {
fc289b0a
TP
8682 /* Check if on thumb2 it can be done with a mov.w, mvn or
8683 movw instruction. */
12569877
AM
8684 unsigned int newimm;
8685 bfd_boolean isNegated;
8686
8687 newimm = encode_thumb32_immediate (v);
8688 if (newimm != (unsigned int) FAIL)
8689 isNegated = FALSE;
8690 else
8691 {
582cfe03 8692 newimm = encode_thumb32_immediate (~v);
12569877
AM
8693 if (newimm != (unsigned int) FAIL)
8694 isNegated = TRUE;
8695 }
8696
fc289b0a
TP
8697 /* The number can be loaded with a mov.w or mvn
8698 instruction. */
ff8646ee
TP
8699 if (newimm != (unsigned int) FAIL
8700 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8701 {
fc289b0a 8702 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8703 | (inst.operands[i].reg << 8));
fc289b0a 8704 /* Change to MOVN. */
582cfe03 8705 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8706 inst.instruction |= (newimm & 0x800) << 15;
8707 inst.instruction |= (newimm & 0x700) << 4;
8708 inst.instruction |= (newimm & 0x0ff);
8709 return TRUE;
8710 }
fc289b0a 8711 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8712 else if ((v & ~0xFFFF) == 0
8713 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8714 {
582cfe03 8715 int imm = v & 0xFFFF;
12569877 8716
582cfe03 8717 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8718 inst.instruction |= (inst.operands[i].reg << 8);
8719 inst.instruction |= (imm & 0xf000) << 4;
8720 inst.instruction |= (imm & 0x0800) << 15;
8721 inst.instruction |= (imm & 0x0700) << 4;
8722 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8723 /* In case this replacement is being done on Armv8-M
8724 Baseline we need to make sure to disable the
8725 instruction size check, as otherwise GAS will reject
8726 the use of this T32 instruction. */
8727 inst.size_req = 0;
12569877
AM
8728 return TRUE;
8729 }
8730 }
8335d6aa 8731 }
12569877 8732 else if (arm_p)
ba592044
AM
8733 {
8734 int value = encode_arm_immediate (v);
12569877 8735
ba592044
AM
8736 if (value != FAIL)
8737 {
8738 /* This can be done with a mov instruction. */
8739 inst.instruction &= LITERAL_MASK;
8740 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8741 inst.instruction |= value & 0xfff;
8742 return TRUE;
8743 }
8335d6aa 8744
ba592044
AM
8745 value = encode_arm_immediate (~ v);
8746 if (value != FAIL)
8747 {
8748 /* This can be done with a mvn instruction. */
8749 inst.instruction &= LITERAL_MASK;
8750 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8751 inst.instruction |= value & 0xfff;
8752 return TRUE;
8753 }
8754 }
934c2632 8755 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8756 {
ba592044
AM
8757 int op = 0;
8758 unsigned immbits = 0;
8759 unsigned immlo = inst.operands[1].imm;
8760 unsigned immhi = inst.operands[1].regisimm
8761 ? inst.operands[1].reg
e2b0ab59 8762 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8763 ? 0
8764 : ((bfd_int64_t)((int) immlo)) >> 32;
8765 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8766 &op, 64, NT_invtype);
8767
8768 if (cmode == FAIL)
8769 {
8770 neon_invert_size (&immlo, &immhi, 64);
8771 op = !op;
8772 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8773 &op, 64, NT_invtype);
8774 }
8775
8776 if (cmode != FAIL)
8777 {
8778 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8779 | (1 << 23)
8780 | (cmode << 8)
8781 | (op << 5)
8782 | (1 << 4);
8783
8784 /* Fill other bits in vmov encoding for both thumb and arm. */
8785 if (thumb_mode)
eff0bc54 8786 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8787 else
eff0bc54 8788 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8789 neon_write_immbits (immbits);
8790 return TRUE;
8791 }
8335d6aa
JW
8792 }
8793 }
8335d6aa 8794
ba592044
AM
8795 if (t == CONST_VEC)
8796 {
8797 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8798 if (inst.operands[i].issingle
8799 && is_quarter_float (inst.operands[1].imm)
8800 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8801 {
ba592044
AM
8802 inst.operands[1].imm =
8803 neon_qfloat_bits (v);
8804 do_vfp_nsyn_opcode ("fconsts");
8805 return TRUE;
8335d6aa 8806 }
5fc177c8
NC
8807
8808 /* If our host does not support a 64-bit type then we cannot perform
8809 the following optimization. This mean that there will be a
8810 discrepancy between the output produced by an assembler built for
8811 a 32-bit-only host and the output produced from a 64-bit host, but
8812 this cannot be helped. */
8813#if defined BFD_HOST_64_BIT
ba592044
AM
8814 else if (!inst.operands[1].issingle
8815 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8816 {
ba592044
AM
8817 if (is_double_a_single (v)
8818 && is_quarter_float (double_to_single (v)))
8819 {
8820 inst.operands[1].imm =
8821 neon_qfloat_bits (double_to_single (v));
8822 do_vfp_nsyn_opcode ("fconstd");
8823 return TRUE;
8824 }
8335d6aa 8825 }
5fc177c8 8826#endif
8335d6aa
JW
8827 }
8828 }
8829
8830 if (add_to_lit_pool ((!inst.operands[i].isvec
8831 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8832 return TRUE;
8833
8834 inst.operands[1].reg = REG_PC;
8835 inst.operands[1].isreg = 1;
8836 inst.operands[1].preind = 1;
e2b0ab59
AV
8837 inst.relocs[0].pc_rel = 1;
8838 inst.relocs[0].type = (thumb_p
8335d6aa
JW
8839 ? BFD_RELOC_ARM_THUMB_OFFSET
8840 : (mode_3
8841 ? BFD_RELOC_ARM_HWLITERAL
8842 : BFD_RELOC_ARM_LITERAL));
8843 return FALSE;
8844}
8845
8846/* inst.operands[i] was set up by parse_address. Encode it into an
8847 ARM-format instruction. Reject all forms which cannot be encoded
8848 into a coprocessor load/store instruction. If wb_ok is false,
8849 reject use of writeback; if unind_ok is false, reject use of
8850 unindexed addressing. If reloc_override is not 0, use it instead
8851 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8852 (in which case it is preserved). */
8853
8854static int
8855encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8856{
8857 if (!inst.operands[i].isreg)
8858 {
99b2a2dd
NC
8859 /* PR 18256 */
8860 if (! inst.operands[0].isvec)
8861 {
8862 inst.error = _("invalid co-processor operand");
8863 return FAIL;
8864 }
8335d6aa
JW
8865 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8866 return SUCCESS;
8867 }
8868
8869 inst.instruction |= inst.operands[i].reg << 16;
8870
8871 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8872
8873 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8874 {
8875 gas_assert (!inst.operands[i].writeback);
8876 if (!unind_ok)
8877 {
8878 inst.error = _("instruction does not support unindexed addressing");
8879 return FAIL;
8880 }
8881 inst.instruction |= inst.operands[i].imm;
8882 inst.instruction |= INDEX_UP;
8883 return SUCCESS;
8884 }
8885
8886 if (inst.operands[i].preind)
8887 inst.instruction |= PRE_INDEX;
8888
8889 if (inst.operands[i].writeback)
09d92015 8890 {
8335d6aa 8891 if (inst.operands[i].reg == REG_PC)
c19d1205 8892 {
8335d6aa
JW
8893 inst.error = _("pc may not be used with write-back");
8894 return FAIL;
c19d1205 8895 }
8335d6aa 8896 if (!wb_ok)
c19d1205 8897 {
8335d6aa
JW
8898 inst.error = _("instruction does not support writeback");
8899 return FAIL;
c19d1205 8900 }
8335d6aa 8901 inst.instruction |= WRITE_BACK;
09d92015
MM
8902 }
8903
8335d6aa 8904 if (reloc_override)
e2b0ab59
AV
8905 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8906 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8907 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8908 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8909 {
8335d6aa 8910 if (thumb_mode)
e2b0ab59 8911 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 8912 else
e2b0ab59 8913 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8914 }
8335d6aa
JW
8915
8916 /* Prefer + for zero encoded value. */
8917 if (!inst.operands[i].negative)
8918 inst.instruction |= INDEX_UP;
8919
8920 return SUCCESS;
09d92015
MM
8921}
8922
5f4273c7 8923/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8924 First some generics; their names are taken from the conventional
8925 bit positions for register arguments in ARM format instructions. */
09d92015 8926
a737bd4d 8927static void
c19d1205 8928do_noargs (void)
09d92015 8929{
c19d1205 8930}
a737bd4d 8931
c19d1205
ZW
8932static void
8933do_rd (void)
8934{
8935 inst.instruction |= inst.operands[0].reg << 12;
8936}
a737bd4d 8937
16a1fa25
TP
8938static void
8939do_rn (void)
8940{
8941 inst.instruction |= inst.operands[0].reg << 16;
8942}
8943
c19d1205
ZW
8944static void
8945do_rd_rm (void)
8946{
8947 inst.instruction |= inst.operands[0].reg << 12;
8948 inst.instruction |= inst.operands[1].reg;
8949}
09d92015 8950
9eb6c0f1
MGD
8951static void
8952do_rm_rn (void)
8953{
8954 inst.instruction |= inst.operands[0].reg;
8955 inst.instruction |= inst.operands[1].reg << 16;
8956}
8957
c19d1205
ZW
8958static void
8959do_rd_rn (void)
8960{
8961 inst.instruction |= inst.operands[0].reg << 12;
8962 inst.instruction |= inst.operands[1].reg << 16;
8963}
a737bd4d 8964
c19d1205
ZW
8965static void
8966do_rn_rd (void)
8967{
8968 inst.instruction |= inst.operands[0].reg << 16;
8969 inst.instruction |= inst.operands[1].reg << 12;
8970}
09d92015 8971
4ed7ed8d
TP
8972static void
8973do_tt (void)
8974{
8975 inst.instruction |= inst.operands[0].reg << 8;
8976 inst.instruction |= inst.operands[1].reg << 16;
8977}
8978
59d09be6
MGD
8979static bfd_boolean
8980check_obsolete (const arm_feature_set *feature, const char *msg)
8981{
8982 if (ARM_CPU_IS_ANY (cpu_variant))
8983 {
5c3696f8 8984 as_tsktsk ("%s", msg);
59d09be6
MGD
8985 return TRUE;
8986 }
8987 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8988 {
8989 as_bad ("%s", msg);
8990 return TRUE;
8991 }
8992
8993 return FALSE;
8994}
8995
c19d1205
ZW
8996static void
8997do_rd_rm_rn (void)
8998{
9a64e435 8999 unsigned Rn = inst.operands[2].reg;
708587a4 9000 /* Enforce restrictions on SWP instruction. */
9a64e435 9001 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9002 {
9003 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9004 _("Rn must not overlap other operands"));
9005
59d09be6
MGD
9006 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9007 */
9008 if (!check_obsolete (&arm_ext_v8,
9009 _("swp{b} use is obsoleted for ARMv8 and later"))
9010 && warn_on_deprecated
9011 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9012 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9013 }
59d09be6 9014
c19d1205
ZW
9015 inst.instruction |= inst.operands[0].reg << 12;
9016 inst.instruction |= inst.operands[1].reg;
9a64e435 9017 inst.instruction |= Rn << 16;
c19d1205 9018}
09d92015 9019
c19d1205
ZW
9020static void
9021do_rd_rn_rm (void)
9022{
9023 inst.instruction |= inst.operands[0].reg << 12;
9024 inst.instruction |= inst.operands[1].reg << 16;
9025 inst.instruction |= inst.operands[2].reg;
9026}
a737bd4d 9027
c19d1205
ZW
9028static void
9029do_rm_rd_rn (void)
9030{
5be8be5d 9031 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9032 constraint (((inst.relocs[0].exp.X_op != O_constant
9033 && inst.relocs[0].exp.X_op != O_illegal)
9034 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9035 BAD_ADDR_MODE);
c19d1205
ZW
9036 inst.instruction |= inst.operands[0].reg;
9037 inst.instruction |= inst.operands[1].reg << 12;
9038 inst.instruction |= inst.operands[2].reg << 16;
9039}
09d92015 9040
c19d1205
ZW
9041static void
9042do_imm0 (void)
9043{
9044 inst.instruction |= inst.operands[0].imm;
9045}
09d92015 9046
c19d1205
ZW
9047static void
9048do_rd_cpaddr (void)
9049{
9050 inst.instruction |= inst.operands[0].reg << 12;
9051 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9052}
a737bd4d 9053
c19d1205
ZW
9054/* ARM instructions, in alphabetical order by function name (except
9055 that wrapper functions appear immediately after the function they
9056 wrap). */
09d92015 9057
c19d1205
ZW
9058/* This is a pseudo-op of the form "adr rd, label" to be converted
9059 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9060
9061static void
c19d1205 9062do_adr (void)
09d92015 9063{
c19d1205 9064 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9065
c19d1205
ZW
9066 /* Frag hacking will turn this into a sub instruction if the offset turns
9067 out to be negative. */
e2b0ab59
AV
9068 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9069 inst.relocs[0].pc_rel = 1;
9070 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9071
fc6141f0 9072 if (support_interwork
e2b0ab59
AV
9073 && inst.relocs[0].exp.X_op == O_symbol
9074 && inst.relocs[0].exp.X_add_symbol != NULL
9075 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9076 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9077 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9078}
b99bd4ef 9079
c19d1205
ZW
9080/* This is a pseudo-op of the form "adrl rd, label" to be converted
9081 into a relative address of the form:
9082 add rd, pc, #low(label-.-8)"
9083 add rd, rd, #high(label-.-8)" */
b99bd4ef 9084
c19d1205
ZW
9085static void
9086do_adrl (void)
9087{
9088 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9089
c19d1205
ZW
9090 /* Frag hacking will turn this into a sub instruction if the offset turns
9091 out to be negative. */
e2b0ab59
AV
9092 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9093 inst.relocs[0].pc_rel = 1;
c19d1205 9094 inst.size = INSN_SIZE * 2;
e2b0ab59 9095 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9096
fc6141f0 9097 if (support_interwork
e2b0ab59
AV
9098 && inst.relocs[0].exp.X_op == O_symbol
9099 && inst.relocs[0].exp.X_add_symbol != NULL
9100 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9101 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9102 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9103}
9104
b99bd4ef 9105static void
c19d1205 9106do_arit (void)
b99bd4ef 9107{
e2b0ab59
AV
9108 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9109 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9110 THUMB1_RELOC_ONLY);
c19d1205
ZW
9111 if (!inst.operands[1].present)
9112 inst.operands[1].reg = inst.operands[0].reg;
9113 inst.instruction |= inst.operands[0].reg << 12;
9114 inst.instruction |= inst.operands[1].reg << 16;
9115 encode_arm_shifter_operand (2);
9116}
b99bd4ef 9117
62b3e311
PB
9118static void
9119do_barrier (void)
9120{
9121 if (inst.operands[0].present)
ccb84d65 9122 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9123 else
9124 inst.instruction |= 0xf;
9125}
9126
c19d1205
ZW
9127static void
9128do_bfc (void)
9129{
9130 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9131 constraint (msb > 32, _("bit-field extends past end of register"));
9132 /* The instruction encoding stores the LSB and MSB,
9133 not the LSB and width. */
9134 inst.instruction |= inst.operands[0].reg << 12;
9135 inst.instruction |= inst.operands[1].imm << 7;
9136 inst.instruction |= (msb - 1) << 16;
9137}
b99bd4ef 9138
c19d1205
ZW
9139static void
9140do_bfi (void)
9141{
9142 unsigned int msb;
b99bd4ef 9143
c19d1205
ZW
9144 /* #0 in second position is alternative syntax for bfc, which is
9145 the same instruction but with REG_PC in the Rm field. */
9146 if (!inst.operands[1].isreg)
9147 inst.operands[1].reg = REG_PC;
b99bd4ef 9148
c19d1205
ZW
9149 msb = inst.operands[2].imm + inst.operands[3].imm;
9150 constraint (msb > 32, _("bit-field extends past end of register"));
9151 /* The instruction encoding stores the LSB and MSB,
9152 not the LSB and width. */
9153 inst.instruction |= inst.operands[0].reg << 12;
9154 inst.instruction |= inst.operands[1].reg;
9155 inst.instruction |= inst.operands[2].imm << 7;
9156 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9157}
9158
b99bd4ef 9159static void
c19d1205 9160do_bfx (void)
b99bd4ef 9161{
c19d1205
ZW
9162 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9163 _("bit-field extends past end of register"));
9164 inst.instruction |= inst.operands[0].reg << 12;
9165 inst.instruction |= inst.operands[1].reg;
9166 inst.instruction |= inst.operands[2].imm << 7;
9167 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9168}
09d92015 9169
c19d1205
ZW
9170/* ARM V5 breakpoint instruction (argument parse)
9171 BKPT <16 bit unsigned immediate>
9172 Instruction is not conditional.
9173 The bit pattern given in insns[] has the COND_ALWAYS condition,
9174 and it is an error if the caller tried to override that. */
b99bd4ef 9175
c19d1205
ZW
9176static void
9177do_bkpt (void)
9178{
9179 /* Top 12 of 16 bits to bits 19:8. */
9180 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9181
c19d1205
ZW
9182 /* Bottom 4 of 16 bits to bits 3:0. */
9183 inst.instruction |= inst.operands[0].imm & 0xf;
9184}
09d92015 9185
c19d1205
ZW
9186static void
9187encode_branch (int default_reloc)
9188{
9189 if (inst.operands[0].hasreloc)
9190 {
0855e32b
NS
9191 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9192 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9193 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9194 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9195 ? BFD_RELOC_ARM_PLT32
9196 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9197 }
b99bd4ef 9198 else
e2b0ab59
AV
9199 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9200 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9201}
9202
b99bd4ef 9203static void
c19d1205 9204do_branch (void)
b99bd4ef 9205{
39b41c9c
PB
9206#ifdef OBJ_ELF
9207 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9208 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9209 else
9210#endif
9211 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9212}
9213
9214static void
9215do_bl (void)
9216{
9217#ifdef OBJ_ELF
9218 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9219 {
9220 if (inst.cond == COND_ALWAYS)
9221 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9222 else
9223 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9224 }
9225 else
9226#endif
9227 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9228}
b99bd4ef 9229
c19d1205
ZW
9230/* ARM V5 branch-link-exchange instruction (argument parse)
9231 BLX <target_addr> ie BLX(1)
9232 BLX{<condition>} <Rm> ie BLX(2)
9233 Unfortunately, there are two different opcodes for this mnemonic.
9234 So, the insns[].value is not used, and the code here zaps values
9235 into inst.instruction.
9236 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9237
c19d1205
ZW
9238static void
9239do_blx (void)
9240{
9241 if (inst.operands[0].isreg)
b99bd4ef 9242 {
c19d1205
ZW
9243 /* Arg is a register; the opcode provided by insns[] is correct.
9244 It is not illegal to do "blx pc", just useless. */
9245 if (inst.operands[0].reg == REG_PC)
9246 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9247
c19d1205
ZW
9248 inst.instruction |= inst.operands[0].reg;
9249 }
9250 else
b99bd4ef 9251 {
c19d1205 9252 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9253 conditionally, and the opcode must be adjusted.
9254 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9255 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9256 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9257 inst.instruction = 0xfa000000;
267bf995 9258 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9259 }
c19d1205
ZW
9260}
9261
9262static void
9263do_bx (void)
9264{
845b51d6
PB
9265 bfd_boolean want_reloc;
9266
c19d1205
ZW
9267 if (inst.operands[0].reg == REG_PC)
9268 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9269
c19d1205 9270 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9271 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9272 it is for ARMv4t or earlier. */
9273 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9274 if (!ARM_FEATURE_ZERO (selected_object_arch)
9275 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9276 want_reloc = TRUE;
9277
5ad34203 9278#ifdef OBJ_ELF
845b51d6 9279 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9280#endif
584206db 9281 want_reloc = FALSE;
845b51d6
PB
9282
9283 if (want_reloc)
e2b0ab59 9284 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9285}
9286
c19d1205
ZW
9287
9288/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9289
9290static void
c19d1205 9291do_bxj (void)
a737bd4d 9292{
c19d1205
ZW
9293 if (inst.operands[0].reg == REG_PC)
9294 as_tsktsk (_("use of r15 in bxj is not really useful"));
9295
9296 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9297}
9298
c19d1205
ZW
9299/* Co-processor data operation:
9300 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9301 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9302static void
9303do_cdp (void)
9304{
9305 inst.instruction |= inst.operands[0].reg << 8;
9306 inst.instruction |= inst.operands[1].imm << 20;
9307 inst.instruction |= inst.operands[2].reg << 12;
9308 inst.instruction |= inst.operands[3].reg << 16;
9309 inst.instruction |= inst.operands[4].reg;
9310 inst.instruction |= inst.operands[5].imm << 5;
9311}
a737bd4d
NC
9312
9313static void
c19d1205 9314do_cmp (void)
a737bd4d 9315{
c19d1205
ZW
9316 inst.instruction |= inst.operands[0].reg << 16;
9317 encode_arm_shifter_operand (1);
a737bd4d
NC
9318}
9319
c19d1205
ZW
9320/* Transfer between coprocessor and ARM registers.
9321 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9322 MRC2
9323 MCR{cond}
9324 MCR2
9325
9326 No special properties. */
09d92015 9327
dcbd0d71
MGD
9328struct deprecated_coproc_regs_s
9329{
9330 unsigned cp;
9331 int opc1;
9332 unsigned crn;
9333 unsigned crm;
9334 int opc2;
9335 arm_feature_set deprecated;
9336 arm_feature_set obsoleted;
9337 const char *dep_msg;
9338 const char *obs_msg;
9339};
9340
9341#define DEPR_ACCESS_V8 \
9342 N_("This coprocessor register access is deprecated in ARMv8")
9343
9344/* Table of all deprecated coprocessor registers. */
9345static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9346{
9347 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9348 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9349 DEPR_ACCESS_V8, NULL},
9350 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9351 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9352 DEPR_ACCESS_V8, NULL},
9353 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9354 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9355 DEPR_ACCESS_V8, NULL},
9356 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9357 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9358 DEPR_ACCESS_V8, NULL},
9359 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9360 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9361 DEPR_ACCESS_V8, NULL},
9362};
9363
9364#undef DEPR_ACCESS_V8
9365
9366static const size_t deprecated_coproc_reg_count =
9367 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9368
09d92015 9369static void
c19d1205 9370do_co_reg (void)
09d92015 9371{
fdfde340 9372 unsigned Rd;
dcbd0d71 9373 size_t i;
fdfde340
JM
9374
9375 Rd = inst.operands[2].reg;
9376 if (thumb_mode)
9377 {
9378 if (inst.instruction == 0xee000010
9379 || inst.instruction == 0xfe000010)
9380 /* MCR, MCR2 */
9381 reject_bad_reg (Rd);
5c8ed6a4 9382 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9383 /* MRC, MRC2 */
9384 constraint (Rd == REG_SP, BAD_SP);
9385 }
9386 else
9387 {
9388 /* MCR */
9389 if (inst.instruction == 0xe000010)
9390 constraint (Rd == REG_PC, BAD_PC);
9391 }
9392
dcbd0d71
MGD
9393 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9394 {
9395 const struct deprecated_coproc_regs_s *r =
9396 deprecated_coproc_regs + i;
9397
9398 if (inst.operands[0].reg == r->cp
9399 && inst.operands[1].imm == r->opc1
9400 && inst.operands[3].reg == r->crn
9401 && inst.operands[4].reg == r->crm
9402 && inst.operands[5].imm == r->opc2)
9403 {
b10bf8c5 9404 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9405 && warn_on_deprecated
dcbd0d71 9406 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9407 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9408 }
9409 }
fdfde340 9410
c19d1205
ZW
9411 inst.instruction |= inst.operands[0].reg << 8;
9412 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9413 inst.instruction |= Rd << 12;
c19d1205
ZW
9414 inst.instruction |= inst.operands[3].reg << 16;
9415 inst.instruction |= inst.operands[4].reg;
9416 inst.instruction |= inst.operands[5].imm << 5;
9417}
09d92015 9418
c19d1205
ZW
9419/* Transfer between coprocessor register and pair of ARM registers.
9420 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9421 MCRR2
9422 MRRC{cond}
9423 MRRC2
b99bd4ef 9424
c19d1205 9425 Two XScale instructions are special cases of these:
09d92015 9426
c19d1205
ZW
9427 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9428 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9429
5f4273c7 9430 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9431
c19d1205
ZW
9432static void
9433do_co_reg2c (void)
9434{
fdfde340
JM
9435 unsigned Rd, Rn;
9436
9437 Rd = inst.operands[2].reg;
9438 Rn = inst.operands[3].reg;
9439
9440 if (thumb_mode)
9441 {
9442 reject_bad_reg (Rd);
9443 reject_bad_reg (Rn);
9444 }
9445 else
9446 {
9447 constraint (Rd == REG_PC, BAD_PC);
9448 constraint (Rn == REG_PC, BAD_PC);
9449 }
9450
873f10f0
TC
9451 /* Only check the MRRC{2} variants. */
9452 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9453 {
9454 /* If Rd == Rn, error that the operation is
9455 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9456 constraint (Rd == Rn, BAD_OVERLAP);
9457 }
9458
c19d1205
ZW
9459 inst.instruction |= inst.operands[0].reg << 8;
9460 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9461 inst.instruction |= Rd << 12;
9462 inst.instruction |= Rn << 16;
c19d1205 9463 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9464}
9465
c19d1205
ZW
9466static void
9467do_cpsi (void)
9468{
9469 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9470 if (inst.operands[1].present)
9471 {
9472 inst.instruction |= CPSI_MMOD;
9473 inst.instruction |= inst.operands[1].imm;
9474 }
c19d1205 9475}
b99bd4ef 9476
62b3e311
PB
9477static void
9478do_dbg (void)
9479{
9480 inst.instruction |= inst.operands[0].imm;
9481}
9482
eea54501
MGD
9483static void
9484do_div (void)
9485{
9486 unsigned Rd, Rn, Rm;
9487
9488 Rd = inst.operands[0].reg;
9489 Rn = (inst.operands[1].present
9490 ? inst.operands[1].reg : Rd);
9491 Rm = inst.operands[2].reg;
9492
9493 constraint ((Rd == REG_PC), BAD_PC);
9494 constraint ((Rn == REG_PC), BAD_PC);
9495 constraint ((Rm == REG_PC), BAD_PC);
9496
9497 inst.instruction |= Rd << 16;
9498 inst.instruction |= Rn << 0;
9499 inst.instruction |= Rm << 8;
9500}
9501
b99bd4ef 9502static void
c19d1205 9503do_it (void)
b99bd4ef 9504{
c19d1205 9505 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9506 process it to do the validation as if in
9507 thumb mode, just in case the code gets
9508 assembled for thumb using the unified syntax. */
9509
c19d1205 9510 inst.size = 0;
e07e6e58
NC
9511 if (unified_syntax)
9512 {
5ee91343
AV
9513 set_pred_insn_type (IT_INSN);
9514 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9515 now_pred.cc = inst.operands[0].imm;
e07e6e58 9516 }
09d92015 9517}
b99bd4ef 9518
6530b175
NC
9519/* If there is only one register in the register list,
9520 then return its register number. Otherwise return -1. */
9521static int
9522only_one_reg_in_list (int range)
9523{
9524 int i = ffs (range) - 1;
9525 return (i > 15 || range != (1 << i)) ? -1 : i;
9526}
9527
09d92015 9528static void
6530b175 9529encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9530{
c19d1205
ZW
9531 int base_reg = inst.operands[0].reg;
9532 int range = inst.operands[1].imm;
6530b175 9533 int one_reg;
ea6ef066 9534
c19d1205
ZW
9535 inst.instruction |= base_reg << 16;
9536 inst.instruction |= range;
ea6ef066 9537
c19d1205
ZW
9538 if (inst.operands[1].writeback)
9539 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9540
c19d1205 9541 if (inst.operands[0].writeback)
ea6ef066 9542 {
c19d1205
ZW
9543 inst.instruction |= WRITE_BACK;
9544 /* Check for unpredictable uses of writeback. */
9545 if (inst.instruction & LOAD_BIT)
09d92015 9546 {
c19d1205
ZW
9547 /* Not allowed in LDM type 2. */
9548 if ((inst.instruction & LDM_TYPE_2_OR_3)
9549 && ((range & (1 << REG_PC)) == 0))
9550 as_warn (_("writeback of base register is UNPREDICTABLE"));
9551 /* Only allowed if base reg not in list for other types. */
9552 else if (range & (1 << base_reg))
9553 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9554 }
9555 else /* STM. */
9556 {
9557 /* Not allowed for type 2. */
9558 if (inst.instruction & LDM_TYPE_2_OR_3)
9559 as_warn (_("writeback of base register is UNPREDICTABLE"));
9560 /* Only allowed if base reg not in list, or first in list. */
9561 else if ((range & (1 << base_reg))
9562 && (range & ((1 << base_reg) - 1)))
9563 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9564 }
ea6ef066 9565 }
6530b175
NC
9566
9567 /* If PUSH/POP has only one register, then use the A2 encoding. */
9568 one_reg = only_one_reg_in_list (range);
9569 if (from_push_pop_mnem && one_reg >= 0)
9570 {
9571 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9572
4f588891
NC
9573 if (is_push && one_reg == 13 /* SP */)
9574 /* PR 22483: The A2 encoding cannot be used when
9575 pushing the stack pointer as this is UNPREDICTABLE. */
9576 return;
9577
6530b175
NC
9578 inst.instruction &= A_COND_MASK;
9579 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9580 inst.instruction |= one_reg << 12;
9581 }
9582}
9583
9584static void
9585do_ldmstm (void)
9586{
9587 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9588}
9589
c19d1205
ZW
9590/* ARMv5TE load-consecutive (argument parse)
9591 Mode is like LDRH.
9592
9593 LDRccD R, mode
9594 STRccD R, mode. */
9595
a737bd4d 9596static void
c19d1205 9597do_ldrd (void)
a737bd4d 9598{
c19d1205 9599 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9600 _("first transfer register must be even"));
c19d1205
ZW
9601 constraint (inst.operands[1].present
9602 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9603 _("can only transfer two consecutive registers"));
c19d1205
ZW
9604 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9605 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9606
c19d1205
ZW
9607 if (!inst.operands[1].present)
9608 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9609
c56791bb
RE
9610 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9611 register and the first register written; we have to diagnose
9612 overlap between the base and the second register written here. */
ea6ef066 9613
c56791bb
RE
9614 if (inst.operands[2].reg == inst.operands[1].reg
9615 && (inst.operands[2].writeback || inst.operands[2].postind))
9616 as_warn (_("base register written back, and overlaps "
9617 "second transfer register"));
b05fe5cf 9618
c56791bb
RE
9619 if (!(inst.instruction & V4_STR_BIT))
9620 {
c19d1205 9621 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9622 destination (even if not write-back). */
9623 if (inst.operands[2].immisreg
9624 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9625 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9626 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9627 }
c19d1205
ZW
9628 inst.instruction |= inst.operands[0].reg << 12;
9629 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9630}
9631
9632static void
c19d1205 9633do_ldrex (void)
b05fe5cf 9634{
c19d1205
ZW
9635 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9636 || inst.operands[1].postind || inst.operands[1].writeback
9637 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9638 || inst.operands[1].negative
9639 /* This can arise if the programmer has written
9640 strex rN, rM, foo
9641 or if they have mistakenly used a register name as the last
9642 operand, eg:
9643 strex rN, rM, rX
9644 It is very difficult to distinguish between these two cases
9645 because "rX" might actually be a label. ie the register
9646 name has been occluded by a symbol of the same name. So we
9647 just generate a general 'bad addressing mode' type error
9648 message and leave it up to the programmer to discover the
9649 true cause and fix their mistake. */
9650 || (inst.operands[1].reg == REG_PC),
9651 BAD_ADDR_MODE);
b05fe5cf 9652
e2b0ab59
AV
9653 constraint (inst.relocs[0].exp.X_op != O_constant
9654 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9655 _("offset must be zero in ARM encoding"));
b05fe5cf 9656
5be8be5d
DG
9657 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9658
c19d1205
ZW
9659 inst.instruction |= inst.operands[0].reg << 12;
9660 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9661 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9662}
9663
9664static void
c19d1205 9665do_ldrexd (void)
b05fe5cf 9666{
c19d1205
ZW
9667 constraint (inst.operands[0].reg % 2 != 0,
9668 _("even register required"));
9669 constraint (inst.operands[1].present
9670 && inst.operands[1].reg != inst.operands[0].reg + 1,
9671 _("can only load two consecutive registers"));
9672 /* If op 1 were present and equal to PC, this function wouldn't
9673 have been called in the first place. */
9674 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9675
c19d1205
ZW
9676 inst.instruction |= inst.operands[0].reg << 12;
9677 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9678}
9679
1be5fd2e
NC
9680/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9681 which is not a multiple of four is UNPREDICTABLE. */
9682static void
9683check_ldr_r15_aligned (void)
9684{
9685 constraint (!(inst.operands[1].immisreg)
9686 && (inst.operands[0].reg == REG_PC
9687 && inst.operands[1].reg == REG_PC
e2b0ab59 9688 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9689 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9690}
9691
b05fe5cf 9692static void
c19d1205 9693do_ldst (void)
b05fe5cf 9694{
c19d1205
ZW
9695 inst.instruction |= inst.operands[0].reg << 12;
9696 if (!inst.operands[1].isreg)
8335d6aa 9697 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9698 return;
c19d1205 9699 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9700 check_ldr_r15_aligned ();
b05fe5cf
ZW
9701}
9702
9703static void
c19d1205 9704do_ldstt (void)
b05fe5cf 9705{
c19d1205
ZW
9706 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9707 reject [Rn,...]. */
9708 if (inst.operands[1].preind)
b05fe5cf 9709 {
e2b0ab59
AV
9710 constraint (inst.relocs[0].exp.X_op != O_constant
9711 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9712 _("this instruction requires a post-indexed address"));
b05fe5cf 9713
c19d1205
ZW
9714 inst.operands[1].preind = 0;
9715 inst.operands[1].postind = 1;
9716 inst.operands[1].writeback = 1;
b05fe5cf 9717 }
c19d1205
ZW
9718 inst.instruction |= inst.operands[0].reg << 12;
9719 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9720}
b05fe5cf 9721
c19d1205 9722/* Halfword and signed-byte load/store operations. */
b05fe5cf 9723
c19d1205
ZW
9724static void
9725do_ldstv4 (void)
9726{
ff4a8d2b 9727 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9728 inst.instruction |= inst.operands[0].reg << 12;
9729 if (!inst.operands[1].isreg)
8335d6aa 9730 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9731 return;
c19d1205 9732 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9733}
9734
9735static void
c19d1205 9736do_ldsttv4 (void)
b05fe5cf 9737{
c19d1205
ZW
9738 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9739 reject [Rn,...]. */
9740 if (inst.operands[1].preind)
b05fe5cf 9741 {
e2b0ab59
AV
9742 constraint (inst.relocs[0].exp.X_op != O_constant
9743 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9744 _("this instruction requires a post-indexed address"));
b05fe5cf 9745
c19d1205
ZW
9746 inst.operands[1].preind = 0;
9747 inst.operands[1].postind = 1;
9748 inst.operands[1].writeback = 1;
b05fe5cf 9749 }
c19d1205
ZW
9750 inst.instruction |= inst.operands[0].reg << 12;
9751 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9752}
b05fe5cf 9753
c19d1205
ZW
9754/* Co-processor register load/store.
9755 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9756static void
9757do_lstc (void)
9758{
9759 inst.instruction |= inst.operands[0].reg << 8;
9760 inst.instruction |= inst.operands[1].reg << 12;
9761 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9762}
9763
b05fe5cf 9764static void
c19d1205 9765do_mlas (void)
b05fe5cf 9766{
8fb9d7b9 9767 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9768 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9769 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9770 && !(inst.instruction & 0x00400000))
8fb9d7b9 9771 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9772
c19d1205
ZW
9773 inst.instruction |= inst.operands[0].reg << 16;
9774 inst.instruction |= inst.operands[1].reg;
9775 inst.instruction |= inst.operands[2].reg << 8;
9776 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9777}
b05fe5cf 9778
c19d1205
ZW
9779static void
9780do_mov (void)
9781{
e2b0ab59
AV
9782 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9783 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9784 THUMB1_RELOC_ONLY);
c19d1205
ZW
9785 inst.instruction |= inst.operands[0].reg << 12;
9786 encode_arm_shifter_operand (1);
9787}
b05fe5cf 9788
c19d1205
ZW
9789/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9790static void
9791do_mov16 (void)
9792{
b6895b4f
PB
9793 bfd_vma imm;
9794 bfd_boolean top;
9795
9796 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 9797 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 9798 _(":lower16: not allowed in this instruction"));
e2b0ab59 9799 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 9800 _(":upper16: not allowed in this instruction"));
c19d1205 9801 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 9802 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 9803 {
e2b0ab59 9804 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
9805 /* The value is in two pieces: 0:11, 16:19. */
9806 inst.instruction |= (imm & 0x00000fff);
9807 inst.instruction |= (imm & 0x0000f000) << 4;
9808 }
b05fe5cf 9809}
b99bd4ef 9810
037e8744
JB
9811static int
9812do_vfp_nsyn_mrs (void)
9813{
9814 if (inst.operands[0].isvec)
9815 {
9816 if (inst.operands[1].reg != 1)
477330fc 9817 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9818 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9819 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9820 do_vfp_nsyn_opcode ("fmstat");
9821 }
9822 else if (inst.operands[1].isvec)
9823 do_vfp_nsyn_opcode ("fmrx");
9824 else
9825 return FAIL;
5f4273c7 9826
037e8744
JB
9827 return SUCCESS;
9828}
9829
9830static int
9831do_vfp_nsyn_msr (void)
9832{
9833 if (inst.operands[0].isvec)
9834 do_vfp_nsyn_opcode ("fmxr");
9835 else
9836 return FAIL;
9837
9838 return SUCCESS;
9839}
9840
f7c21dc7
NC
9841static void
9842do_vmrs (void)
9843{
9844 unsigned Rt = inst.operands[0].reg;
fa94de6b 9845
16d02dc9 9846 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9847 {
9848 inst.error = BAD_SP;
9849 return;
9850 }
9851
ba6cd17f
SD
9852 switch (inst.operands[1].reg)
9853 {
9854 /* MVFR2 is only valid for Armv8-A. */
9855 case 5:
9856 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9857 _(BAD_FPU));
9858 break;
9859
9860 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9861 case 1: /* fpscr. */
9862 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9863 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9864 _(BAD_FPU));
9865 break;
9866
9867 case 14: /* fpcxt_ns. */
9868 case 15: /* fpcxt_s. */
9869 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
9870 _("selected processor does not support instruction"));
9871 break;
9872
9873 case 2: /* fpscr_nzcvqc. */
9874 case 12: /* vpr. */
9875 case 13: /* p0. */
9876 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
9877 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9878 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9879 _("selected processor does not support instruction"));
9880 if (inst.operands[0].reg != 2
9881 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
9882 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
9883 break;
9884
9885 default:
9886 break;
9887 }
40c7d507 9888
f7c21dc7 9889 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9890 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9891 {
9892 inst.error = BAD_PC;
9893 return;
9894 }
9895
16d02dc9
JB
9896 /* If we get through parsing the register name, we just insert the number
9897 generated into the instruction without further validation. */
9898 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9899 inst.instruction |= (Rt << 12);
9900}
9901
9902static void
9903do_vmsr (void)
9904{
9905 unsigned Rt = inst.operands[1].reg;
fa94de6b 9906
f7c21dc7
NC
9907 if (thumb_mode)
9908 reject_bad_reg (Rt);
9909 else if (Rt == REG_PC)
9910 {
9911 inst.error = BAD_PC;
9912 return;
9913 }
9914
ba6cd17f
SD
9915 switch (inst.operands[0].reg)
9916 {
9917 /* MVFR2 is only valid for Armv8-A. */
9918 case 5:
9919 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9920 _(BAD_FPU));
9921 break;
9922
9923 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9924 case 1: /* fpcr. */
9925 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9926 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9927 _(BAD_FPU));
9928 break;
9929
9930 case 14: /* fpcxt_ns. */
9931 case 15: /* fpcxt_s. */
9932 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
9933 _("selected processor does not support instruction"));
9934 break;
9935
9936 case 2: /* fpscr_nzcvqc. */
9937 case 12: /* vpr. */
9938 case 13: /* p0. */
9939 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
9940 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9941 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9942 _("selected processor does not support instruction"));
9943 if (inst.operands[0].reg != 2
9944 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
9945 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
9946 break;
9947
9948 default:
9949 break;
9950 }
40c7d507 9951
16d02dc9
JB
9952 /* If we get through parsing the register name, we just insert the number
9953 generated into the instruction without further validation. */
9954 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9955 inst.instruction |= (Rt << 12);
9956}
9957
b99bd4ef 9958static void
c19d1205 9959do_mrs (void)
b99bd4ef 9960{
90ec0d68
MGD
9961 unsigned br;
9962
037e8744
JB
9963 if (do_vfp_nsyn_mrs () == SUCCESS)
9964 return;
9965
ff4a8d2b 9966 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9967 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9968
9969 if (inst.operands[1].isreg)
9970 {
9971 br = inst.operands[1].reg;
806ab1c0 9972 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9973 as_bad (_("bad register for mrs"));
9974 }
9975 else
9976 {
9977 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9978 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9979 != (PSR_c|PSR_f),
d2cd1205 9980 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9981 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9982 }
9983
9984 inst.instruction |= br;
c19d1205 9985}
b99bd4ef 9986
c19d1205
ZW
9987/* Two possible forms:
9988 "{C|S}PSR_<field>, Rm",
9989 "{C|S}PSR_f, #expression". */
b99bd4ef 9990
c19d1205
ZW
9991static void
9992do_msr (void)
9993{
037e8744
JB
9994 if (do_vfp_nsyn_msr () == SUCCESS)
9995 return;
9996
c19d1205
ZW
9997 inst.instruction |= inst.operands[0].imm;
9998 if (inst.operands[1].isreg)
9999 inst.instruction |= inst.operands[1].reg;
10000 else
b99bd4ef 10001 {
c19d1205 10002 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10003 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10004 inst.relocs[0].pc_rel = 0;
b99bd4ef 10005 }
b99bd4ef
NC
10006}
10007
c19d1205
ZW
10008static void
10009do_mul (void)
a737bd4d 10010{
ff4a8d2b
NC
10011 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10012
c19d1205
ZW
10013 if (!inst.operands[2].present)
10014 inst.operands[2].reg = inst.operands[0].reg;
10015 inst.instruction |= inst.operands[0].reg << 16;
10016 inst.instruction |= inst.operands[1].reg;
10017 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10018
8fb9d7b9
MS
10019 if (inst.operands[0].reg == inst.operands[1].reg
10020 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10021 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10022}
10023
c19d1205
ZW
10024/* Long Multiply Parser
10025 UMULL RdLo, RdHi, Rm, Rs
10026 SMULL RdLo, RdHi, Rm, Rs
10027 UMLAL RdLo, RdHi, Rm, Rs
10028 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10029
10030static void
c19d1205 10031do_mull (void)
b99bd4ef 10032{
c19d1205
ZW
10033 inst.instruction |= inst.operands[0].reg << 12;
10034 inst.instruction |= inst.operands[1].reg << 16;
10035 inst.instruction |= inst.operands[2].reg;
10036 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10037
682b27ad
PB
10038 /* rdhi and rdlo must be different. */
10039 if (inst.operands[0].reg == inst.operands[1].reg)
10040 as_tsktsk (_("rdhi and rdlo must be different"));
10041
10042 /* rdhi, rdlo and rm must all be different before armv6. */
10043 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10044 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10045 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10046 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10047}
b99bd4ef 10048
c19d1205
ZW
10049static void
10050do_nop (void)
10051{
e7495e45
NS
10052 if (inst.operands[0].present
10053 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10054 {
10055 /* Architectural NOP hints are CPSR sets with no bits selected. */
10056 inst.instruction &= 0xf0000000;
e7495e45
NS
10057 inst.instruction |= 0x0320f000;
10058 if (inst.operands[0].present)
10059 inst.instruction |= inst.operands[0].imm;
c19d1205 10060 }
b99bd4ef
NC
10061}
10062
c19d1205
ZW
10063/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10064 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10065 Condition defaults to COND_ALWAYS.
10066 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10067
10068static void
c19d1205 10069do_pkhbt (void)
b99bd4ef 10070{
c19d1205
ZW
10071 inst.instruction |= inst.operands[0].reg << 12;
10072 inst.instruction |= inst.operands[1].reg << 16;
10073 inst.instruction |= inst.operands[2].reg;
10074 if (inst.operands[3].present)
10075 encode_arm_shift (3);
10076}
b99bd4ef 10077
c19d1205 10078/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10079
c19d1205
ZW
10080static void
10081do_pkhtb (void)
10082{
10083 if (!inst.operands[3].present)
b99bd4ef 10084 {
c19d1205
ZW
10085 /* If the shift specifier is omitted, turn the instruction
10086 into pkhbt rd, rm, rn. */
10087 inst.instruction &= 0xfff00010;
10088 inst.instruction |= inst.operands[0].reg << 12;
10089 inst.instruction |= inst.operands[1].reg;
10090 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10091 }
10092 else
10093 {
c19d1205
ZW
10094 inst.instruction |= inst.operands[0].reg << 12;
10095 inst.instruction |= inst.operands[1].reg << 16;
10096 inst.instruction |= inst.operands[2].reg;
10097 encode_arm_shift (3);
b99bd4ef
NC
10098 }
10099}
10100
c19d1205 10101/* ARMv5TE: Preload-Cache
60e5ef9f 10102 MP Extensions: Preload for write
c19d1205 10103
60e5ef9f 10104 PLD(W) <addr_mode>
c19d1205
ZW
10105
10106 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10107
10108static void
c19d1205 10109do_pld (void)
b99bd4ef 10110{
c19d1205
ZW
10111 constraint (!inst.operands[0].isreg,
10112 _("'[' expected after PLD mnemonic"));
10113 constraint (inst.operands[0].postind,
10114 _("post-indexed expression used in preload instruction"));
10115 constraint (inst.operands[0].writeback,
10116 _("writeback used in preload instruction"));
10117 constraint (!inst.operands[0].preind,
10118 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10119 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10120}
b99bd4ef 10121
62b3e311
PB
10122/* ARMv7: PLI <addr_mode> */
10123static void
10124do_pli (void)
10125{
10126 constraint (!inst.operands[0].isreg,
10127 _("'[' expected after PLI mnemonic"));
10128 constraint (inst.operands[0].postind,
10129 _("post-indexed expression used in preload instruction"));
10130 constraint (inst.operands[0].writeback,
10131 _("writeback used in preload instruction"));
10132 constraint (!inst.operands[0].preind,
10133 _("unindexed addressing used in preload instruction"));
10134 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10135 inst.instruction &= ~PRE_INDEX;
10136}
10137
c19d1205
ZW
10138static void
10139do_push_pop (void)
10140{
5e0d7f77
MP
10141 constraint (inst.operands[0].writeback,
10142 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10143 inst.operands[1] = inst.operands[0];
10144 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10145 inst.operands[0].isreg = 1;
10146 inst.operands[0].writeback = 1;
10147 inst.operands[0].reg = REG_SP;
6530b175 10148 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10149}
b99bd4ef 10150
c19d1205
ZW
10151/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10152 word at the specified address and the following word
10153 respectively.
10154 Unconditionally executed.
10155 Error if Rn is R15. */
b99bd4ef 10156
c19d1205
ZW
10157static void
10158do_rfe (void)
10159{
10160 inst.instruction |= inst.operands[0].reg << 16;
10161 if (inst.operands[0].writeback)
10162 inst.instruction |= WRITE_BACK;
10163}
b99bd4ef 10164
c19d1205 10165/* ARM V6 ssat (argument parse). */
b99bd4ef 10166
c19d1205
ZW
10167static void
10168do_ssat (void)
10169{
10170 inst.instruction |= inst.operands[0].reg << 12;
10171 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10172 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10173
c19d1205
ZW
10174 if (inst.operands[3].present)
10175 encode_arm_shift (3);
b99bd4ef
NC
10176}
10177
c19d1205 10178/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10179
10180static void
c19d1205 10181do_usat (void)
b99bd4ef 10182{
c19d1205
ZW
10183 inst.instruction |= inst.operands[0].reg << 12;
10184 inst.instruction |= inst.operands[1].imm << 16;
10185 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10186
c19d1205
ZW
10187 if (inst.operands[3].present)
10188 encode_arm_shift (3);
b99bd4ef
NC
10189}
10190
c19d1205 10191/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10192
10193static void
c19d1205 10194do_ssat16 (void)
09d92015 10195{
c19d1205
ZW
10196 inst.instruction |= inst.operands[0].reg << 12;
10197 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10198 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10199}
10200
c19d1205
ZW
10201static void
10202do_usat16 (void)
a737bd4d 10203{
c19d1205
ZW
10204 inst.instruction |= inst.operands[0].reg << 12;
10205 inst.instruction |= inst.operands[1].imm << 16;
10206 inst.instruction |= inst.operands[2].reg;
10207}
a737bd4d 10208
c19d1205
ZW
10209/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10210 preserving the other bits.
a737bd4d 10211
c19d1205
ZW
10212 setend <endian_specifier>, where <endian_specifier> is either
10213 BE or LE. */
a737bd4d 10214
c19d1205
ZW
10215static void
10216do_setend (void)
10217{
12e37cbc
MGD
10218 if (warn_on_deprecated
10219 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10220 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10221
c19d1205
ZW
10222 if (inst.operands[0].imm)
10223 inst.instruction |= 0x200;
a737bd4d
NC
10224}
10225
10226static void
c19d1205 10227do_shift (void)
a737bd4d 10228{
c19d1205
ZW
10229 unsigned int Rm = (inst.operands[1].present
10230 ? inst.operands[1].reg
10231 : inst.operands[0].reg);
a737bd4d 10232
c19d1205
ZW
10233 inst.instruction |= inst.operands[0].reg << 12;
10234 inst.instruction |= Rm;
10235 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10236 {
c19d1205
ZW
10237 inst.instruction |= inst.operands[2].reg << 8;
10238 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10239 /* PR 12854: Error on extraneous shifts. */
10240 constraint (inst.operands[2].shifted,
10241 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10242 }
10243 else
e2b0ab59 10244 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10245}
10246
09d92015 10247static void
3eb17e6b 10248do_smc (void)
09d92015 10249{
e2b0ab59
AV
10250 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10251 inst.relocs[0].pc_rel = 0;
09d92015
MM
10252}
10253
90ec0d68
MGD
10254static void
10255do_hvc (void)
10256{
e2b0ab59
AV
10257 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10258 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10259}
10260
09d92015 10261static void
c19d1205 10262do_swi (void)
09d92015 10263{
e2b0ab59
AV
10264 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10265 inst.relocs[0].pc_rel = 0;
09d92015
MM
10266}
10267
ddfded2f
MW
10268static void
10269do_setpan (void)
10270{
10271 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10272 _("selected processor does not support SETPAN instruction"));
10273
10274 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10275}
10276
10277static void
10278do_t_setpan (void)
10279{
10280 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10281 _("selected processor does not support SETPAN instruction"));
10282
10283 inst.instruction |= (inst.operands[0].imm << 3);
10284}
10285
c19d1205
ZW
10286/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10287 SMLAxy{cond} Rd,Rm,Rs,Rn
10288 SMLAWy{cond} Rd,Rm,Rs,Rn
10289 Error if any register is R15. */
e16bb312 10290
c19d1205
ZW
10291static void
10292do_smla (void)
e16bb312 10293{
c19d1205
ZW
10294 inst.instruction |= inst.operands[0].reg << 16;
10295 inst.instruction |= inst.operands[1].reg;
10296 inst.instruction |= inst.operands[2].reg << 8;
10297 inst.instruction |= inst.operands[3].reg << 12;
10298}
a737bd4d 10299
c19d1205
ZW
10300/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10301 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10302 Error if any register is R15.
10303 Warning if Rdlo == Rdhi. */
a737bd4d 10304
c19d1205
ZW
10305static void
10306do_smlal (void)
10307{
10308 inst.instruction |= inst.operands[0].reg << 12;
10309 inst.instruction |= inst.operands[1].reg << 16;
10310 inst.instruction |= inst.operands[2].reg;
10311 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10312
c19d1205
ZW
10313 if (inst.operands[0].reg == inst.operands[1].reg)
10314 as_tsktsk (_("rdhi and rdlo must be different"));
10315}
a737bd4d 10316
c19d1205
ZW
10317/* ARM V5E (El Segundo) signed-multiply (argument parse)
10318 SMULxy{cond} Rd,Rm,Rs
10319 Error if any register is R15. */
a737bd4d 10320
c19d1205
ZW
10321static void
10322do_smul (void)
10323{
10324 inst.instruction |= inst.operands[0].reg << 16;
10325 inst.instruction |= inst.operands[1].reg;
10326 inst.instruction |= inst.operands[2].reg << 8;
10327}
a737bd4d 10328
b6702015
PB
10329/* ARM V6 srs (argument parse). The variable fields in the encoding are
10330 the same for both ARM and Thumb-2. */
a737bd4d 10331
c19d1205
ZW
10332static void
10333do_srs (void)
10334{
b6702015
PB
10335 int reg;
10336
10337 if (inst.operands[0].present)
10338 {
10339 reg = inst.operands[0].reg;
fdfde340 10340 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10341 }
10342 else
fdfde340 10343 reg = REG_SP;
b6702015
PB
10344
10345 inst.instruction |= reg << 16;
10346 inst.instruction |= inst.operands[1].imm;
10347 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10348 inst.instruction |= WRITE_BACK;
10349}
a737bd4d 10350
c19d1205 10351/* ARM V6 strex (argument parse). */
a737bd4d 10352
c19d1205
ZW
10353static void
10354do_strex (void)
10355{
10356 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10357 || inst.operands[2].postind || inst.operands[2].writeback
10358 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10359 || inst.operands[2].negative
10360 /* See comment in do_ldrex(). */
10361 || (inst.operands[2].reg == REG_PC),
10362 BAD_ADDR_MODE);
a737bd4d 10363
c19d1205
ZW
10364 constraint (inst.operands[0].reg == inst.operands[1].reg
10365 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10366
e2b0ab59
AV
10367 constraint (inst.relocs[0].exp.X_op != O_constant
10368 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10369 _("offset must be zero in ARM encoding"));
a737bd4d 10370
c19d1205
ZW
10371 inst.instruction |= inst.operands[0].reg << 12;
10372 inst.instruction |= inst.operands[1].reg;
10373 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10374 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10375}
10376
877807f8
NC
10377static void
10378do_t_strexbh (void)
10379{
10380 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10381 || inst.operands[2].postind || inst.operands[2].writeback
10382 || inst.operands[2].immisreg || inst.operands[2].shifted
10383 || inst.operands[2].negative,
10384 BAD_ADDR_MODE);
10385
10386 constraint (inst.operands[0].reg == inst.operands[1].reg
10387 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10388
10389 do_rm_rd_rn ();
10390}
10391
e16bb312 10392static void
c19d1205 10393do_strexd (void)
e16bb312 10394{
c19d1205
ZW
10395 constraint (inst.operands[1].reg % 2 != 0,
10396 _("even register required"));
10397 constraint (inst.operands[2].present
10398 && inst.operands[2].reg != inst.operands[1].reg + 1,
10399 _("can only store two consecutive registers"));
10400 /* If op 2 were present and equal to PC, this function wouldn't
10401 have been called in the first place. */
10402 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10403
c19d1205
ZW
10404 constraint (inst.operands[0].reg == inst.operands[1].reg
10405 || inst.operands[0].reg == inst.operands[1].reg + 1
10406 || inst.operands[0].reg == inst.operands[3].reg,
10407 BAD_OVERLAP);
e16bb312 10408
c19d1205
ZW
10409 inst.instruction |= inst.operands[0].reg << 12;
10410 inst.instruction |= inst.operands[1].reg;
10411 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10412}
10413
9eb6c0f1
MGD
10414/* ARM V8 STRL. */
10415static void
4b8c8c02 10416do_stlex (void)
9eb6c0f1
MGD
10417{
10418 constraint (inst.operands[0].reg == inst.operands[1].reg
10419 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10420
10421 do_rd_rm_rn ();
10422}
10423
10424static void
4b8c8c02 10425do_t_stlex (void)
9eb6c0f1
MGD
10426{
10427 constraint (inst.operands[0].reg == inst.operands[1].reg
10428 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10429
10430 do_rm_rd_rn ();
10431}
10432
c19d1205
ZW
10433/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10434 extends it to 32-bits, and adds the result to a value in another
10435 register. You can specify a rotation by 0, 8, 16, or 24 bits
10436 before extracting the 16-bit value.
10437 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10438 Condition defaults to COND_ALWAYS.
10439 Error if any register uses R15. */
10440
e16bb312 10441static void
c19d1205 10442do_sxtah (void)
e16bb312 10443{
c19d1205
ZW
10444 inst.instruction |= inst.operands[0].reg << 12;
10445 inst.instruction |= inst.operands[1].reg << 16;
10446 inst.instruction |= inst.operands[2].reg;
10447 inst.instruction |= inst.operands[3].imm << 10;
10448}
e16bb312 10449
c19d1205 10450/* ARM V6 SXTH.
e16bb312 10451
c19d1205
ZW
10452 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10453 Condition defaults to COND_ALWAYS.
10454 Error if any register uses R15. */
e16bb312
NC
10455
10456static void
c19d1205 10457do_sxth (void)
e16bb312 10458{
c19d1205
ZW
10459 inst.instruction |= inst.operands[0].reg << 12;
10460 inst.instruction |= inst.operands[1].reg;
10461 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10462}
c19d1205
ZW
10463\f
10464/* VFP instructions. In a logical order: SP variant first, monad
10465 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10466
10467static void
c19d1205 10468do_vfp_sp_monadic (void)
e16bb312 10469{
57785aa2
AV
10470 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10471 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10472 _(BAD_FPU));
10473
5287ad62
JB
10474 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10475 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10476}
10477
10478static void
c19d1205 10479do_vfp_sp_dyadic (void)
e16bb312 10480{
5287ad62
JB
10481 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10482 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10483 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10484}
10485
10486static void
c19d1205 10487do_vfp_sp_compare_z (void)
e16bb312 10488{
5287ad62 10489 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10490}
10491
10492static void
c19d1205 10493do_vfp_dp_sp_cvt (void)
e16bb312 10494{
5287ad62
JB
10495 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10496 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10497}
10498
10499static void
c19d1205 10500do_vfp_sp_dp_cvt (void)
e16bb312 10501{
5287ad62
JB
10502 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10503 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10504}
10505
10506static void
c19d1205 10507do_vfp_reg_from_sp (void)
e16bb312 10508{
57785aa2
AV
10509 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10510 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10511 _(BAD_FPU));
10512
c19d1205 10513 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10514 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10515}
10516
10517static void
c19d1205 10518do_vfp_reg2_from_sp2 (void)
e16bb312 10519{
c19d1205
ZW
10520 constraint (inst.operands[2].imm != 2,
10521 _("only two consecutive VFP SP registers allowed here"));
10522 inst.instruction |= inst.operands[0].reg << 12;
10523 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10524 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10525}
10526
10527static void
c19d1205 10528do_vfp_sp_from_reg (void)
e16bb312 10529{
57785aa2
AV
10530 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10531 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10532 _(BAD_FPU));
10533
5287ad62 10534 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10535 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10536}
10537
10538static void
c19d1205 10539do_vfp_sp2_from_reg2 (void)
e16bb312 10540{
c19d1205
ZW
10541 constraint (inst.operands[0].imm != 2,
10542 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10543 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10544 inst.instruction |= inst.operands[1].reg << 12;
10545 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10546}
10547
10548static void
c19d1205 10549do_vfp_sp_ldst (void)
e16bb312 10550{
5287ad62 10551 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10552 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10553}
10554
10555static void
c19d1205 10556do_vfp_dp_ldst (void)
e16bb312 10557{
5287ad62 10558 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10559 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10560}
10561
c19d1205 10562
e16bb312 10563static void
c19d1205 10564vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10565{
c19d1205
ZW
10566 if (inst.operands[0].writeback)
10567 inst.instruction |= WRITE_BACK;
10568 else
10569 constraint (ldstm_type != VFP_LDSTMIA,
10570 _("this addressing mode requires base-register writeback"));
10571 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10572 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10573 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10574}
10575
10576static void
c19d1205 10577vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10578{
c19d1205 10579 int count;
e16bb312 10580
c19d1205
ZW
10581 if (inst.operands[0].writeback)
10582 inst.instruction |= WRITE_BACK;
10583 else
10584 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10585 _("this addressing mode requires base-register writeback"));
e16bb312 10586
c19d1205 10587 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10589
c19d1205
ZW
10590 count = inst.operands[1].imm << 1;
10591 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10592 count += 1;
e16bb312 10593
c19d1205 10594 inst.instruction |= count;
e16bb312
NC
10595}
10596
10597static void
c19d1205 10598do_vfp_sp_ldstmia (void)
e16bb312 10599{
c19d1205 10600 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10601}
10602
10603static void
c19d1205 10604do_vfp_sp_ldstmdb (void)
e16bb312 10605{
c19d1205 10606 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10607}
10608
10609static void
c19d1205 10610do_vfp_dp_ldstmia (void)
e16bb312 10611{
c19d1205 10612 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10613}
10614
10615static void
c19d1205 10616do_vfp_dp_ldstmdb (void)
e16bb312 10617{
c19d1205 10618 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10619}
10620
10621static void
c19d1205 10622do_vfp_xp_ldstmia (void)
e16bb312 10623{
c19d1205
ZW
10624 vfp_dp_ldstm (VFP_LDSTMIAX);
10625}
e16bb312 10626
c19d1205
ZW
10627static void
10628do_vfp_xp_ldstmdb (void)
10629{
10630 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10631}
5287ad62
JB
10632
10633static void
10634do_vfp_dp_rd_rm (void)
10635{
57785aa2
AV
10636 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10637 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10638 _(BAD_FPU));
10639
5287ad62
JB
10640 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10641 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10642}
10643
10644static void
10645do_vfp_dp_rn_rd (void)
10646{
10647 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10648 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10649}
10650
10651static void
10652do_vfp_dp_rd_rn (void)
10653{
10654 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10655 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10656}
10657
10658static void
10659do_vfp_dp_rd_rn_rm (void)
10660{
57785aa2
AV
10661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10662 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10663 _(BAD_FPU));
10664
5287ad62
JB
10665 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10666 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10667 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10668}
10669
10670static void
10671do_vfp_dp_rd (void)
10672{
10673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10674}
10675
10676static void
10677do_vfp_dp_rm_rd_rn (void)
10678{
57785aa2
AV
10679 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10680 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10681 _(BAD_FPU));
10682
5287ad62
JB
10683 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10684 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10685 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10686}
10687
10688/* VFPv3 instructions. */
10689static void
10690do_vfp_sp_const (void)
10691{
10692 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10693 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10694 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10695}
10696
10697static void
10698do_vfp_dp_const (void)
10699{
10700 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10701 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10702 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10703}
10704
10705static void
10706vfp_conv (int srcsize)
10707{
5f1af56b
MGD
10708 int immbits = srcsize - inst.operands[1].imm;
10709
fa94de6b
RM
10710 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10711 {
5f1af56b 10712 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10713 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10714 inst.error = _("immediate value out of range, expected range [0, 16]");
10715 return;
10716 }
fa94de6b 10717 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10718 {
10719 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10720 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10721 inst.error = _("immediate value out of range, expected range [1, 32]");
10722 return;
10723 }
10724
5287ad62
JB
10725 inst.instruction |= (immbits & 1) << 5;
10726 inst.instruction |= (immbits >> 1);
10727}
10728
10729static void
10730do_vfp_sp_conv_16 (void)
10731{
10732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10733 vfp_conv (16);
10734}
10735
10736static void
10737do_vfp_dp_conv_16 (void)
10738{
10739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10740 vfp_conv (16);
10741}
10742
10743static void
10744do_vfp_sp_conv_32 (void)
10745{
10746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10747 vfp_conv (32);
10748}
10749
10750static void
10751do_vfp_dp_conv_32 (void)
10752{
10753 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10754 vfp_conv (32);
10755}
c19d1205
ZW
10756\f
10757/* FPA instructions. Also in a logical order. */
e16bb312 10758
c19d1205
ZW
10759static void
10760do_fpa_cmp (void)
10761{
10762 inst.instruction |= inst.operands[0].reg << 16;
10763 inst.instruction |= inst.operands[1].reg;
10764}
b99bd4ef
NC
10765
10766static void
c19d1205 10767do_fpa_ldmstm (void)
b99bd4ef 10768{
c19d1205
ZW
10769 inst.instruction |= inst.operands[0].reg << 12;
10770 switch (inst.operands[1].imm)
10771 {
10772 case 1: inst.instruction |= CP_T_X; break;
10773 case 2: inst.instruction |= CP_T_Y; break;
10774 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10775 case 4: break;
10776 default: abort ();
10777 }
b99bd4ef 10778
c19d1205
ZW
10779 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10780 {
10781 /* The instruction specified "ea" or "fd", so we can only accept
10782 [Rn]{!}. The instruction does not really support stacking or
10783 unstacking, so we have to emulate these by setting appropriate
10784 bits and offsets. */
e2b0ab59
AV
10785 constraint (inst.relocs[0].exp.X_op != O_constant
10786 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10787 _("this instruction does not support indexing"));
b99bd4ef 10788
c19d1205 10789 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 10790 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10791
c19d1205 10792 if (!(inst.instruction & INDEX_UP))
e2b0ab59 10793 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 10794
c19d1205
ZW
10795 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10796 {
10797 inst.operands[2].preind = 0;
10798 inst.operands[2].postind = 1;
10799 }
10800 }
b99bd4ef 10801
c19d1205 10802 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10803}
c19d1205
ZW
10804\f
10805/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10806
c19d1205
ZW
10807static void
10808do_iwmmxt_tandorc (void)
10809{
10810 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10811}
b99bd4ef 10812
c19d1205
ZW
10813static void
10814do_iwmmxt_textrc (void)
10815{
10816 inst.instruction |= inst.operands[0].reg << 12;
10817 inst.instruction |= inst.operands[1].imm;
10818}
b99bd4ef
NC
10819
10820static void
c19d1205 10821do_iwmmxt_textrm (void)
b99bd4ef 10822{
c19d1205
ZW
10823 inst.instruction |= inst.operands[0].reg << 12;
10824 inst.instruction |= inst.operands[1].reg << 16;
10825 inst.instruction |= inst.operands[2].imm;
10826}
b99bd4ef 10827
c19d1205
ZW
10828static void
10829do_iwmmxt_tinsr (void)
10830{
10831 inst.instruction |= inst.operands[0].reg << 16;
10832 inst.instruction |= inst.operands[1].reg << 12;
10833 inst.instruction |= inst.operands[2].imm;
10834}
b99bd4ef 10835
c19d1205
ZW
10836static void
10837do_iwmmxt_tmia (void)
10838{
10839 inst.instruction |= inst.operands[0].reg << 5;
10840 inst.instruction |= inst.operands[1].reg;
10841 inst.instruction |= inst.operands[2].reg << 12;
10842}
b99bd4ef 10843
c19d1205
ZW
10844static void
10845do_iwmmxt_waligni (void)
10846{
10847 inst.instruction |= inst.operands[0].reg << 12;
10848 inst.instruction |= inst.operands[1].reg << 16;
10849 inst.instruction |= inst.operands[2].reg;
10850 inst.instruction |= inst.operands[3].imm << 20;
10851}
b99bd4ef 10852
2d447fca
JM
10853static void
10854do_iwmmxt_wmerge (void)
10855{
10856 inst.instruction |= inst.operands[0].reg << 12;
10857 inst.instruction |= inst.operands[1].reg << 16;
10858 inst.instruction |= inst.operands[2].reg;
10859 inst.instruction |= inst.operands[3].imm << 21;
10860}
10861
c19d1205
ZW
10862static void
10863do_iwmmxt_wmov (void)
10864{
10865 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10866 inst.instruction |= inst.operands[0].reg << 12;
10867 inst.instruction |= inst.operands[1].reg << 16;
10868 inst.instruction |= inst.operands[1].reg;
10869}
b99bd4ef 10870
c19d1205
ZW
10871static void
10872do_iwmmxt_wldstbh (void)
10873{
8f06b2d8 10874 int reloc;
c19d1205 10875 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10876 if (thumb_mode)
10877 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10878 else
10879 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10880 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10881}
10882
c19d1205
ZW
10883static void
10884do_iwmmxt_wldstw (void)
10885{
10886 /* RIWR_RIWC clears .isreg for a control register. */
10887 if (!inst.operands[0].isreg)
10888 {
10889 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10890 inst.instruction |= 0xf0000000;
10891 }
b99bd4ef 10892
c19d1205
ZW
10893 inst.instruction |= inst.operands[0].reg << 12;
10894 encode_arm_cp_address (1, TRUE, TRUE, 0);
10895}
b99bd4ef
NC
10896
10897static void
c19d1205 10898do_iwmmxt_wldstd (void)
b99bd4ef 10899{
c19d1205 10900 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10901 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10902 && inst.operands[1].immisreg)
10903 {
10904 inst.instruction &= ~0x1a000ff;
eff0bc54 10905 inst.instruction |= (0xfU << 28);
2d447fca
JM
10906 if (inst.operands[1].preind)
10907 inst.instruction |= PRE_INDEX;
10908 if (!inst.operands[1].negative)
10909 inst.instruction |= INDEX_UP;
10910 if (inst.operands[1].writeback)
10911 inst.instruction |= WRITE_BACK;
10912 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 10913 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
10914 inst.instruction |= inst.operands[1].imm;
10915 }
10916 else
10917 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10918}
b99bd4ef 10919
c19d1205
ZW
10920static void
10921do_iwmmxt_wshufh (void)
10922{
10923 inst.instruction |= inst.operands[0].reg << 12;
10924 inst.instruction |= inst.operands[1].reg << 16;
10925 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10926 inst.instruction |= (inst.operands[2].imm & 0x0f);
10927}
b99bd4ef 10928
c19d1205
ZW
10929static void
10930do_iwmmxt_wzero (void)
10931{
10932 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10933 inst.instruction |= inst.operands[0].reg;
10934 inst.instruction |= inst.operands[0].reg << 12;
10935 inst.instruction |= inst.operands[0].reg << 16;
10936}
2d447fca
JM
10937
10938static void
10939do_iwmmxt_wrwrwr_or_imm5 (void)
10940{
10941 if (inst.operands[2].isreg)
10942 do_rd_rn_rm ();
10943 else {
10944 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10945 _("immediate operand requires iWMMXt2"));
10946 do_rd_rn ();
10947 if (inst.operands[2].imm == 0)
10948 {
10949 switch ((inst.instruction >> 20) & 0xf)
10950 {
10951 case 4:
10952 case 5:
10953 case 6:
5f4273c7 10954 case 7:
2d447fca
JM
10955 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10956 inst.operands[2].imm = 16;
10957 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10958 break;
10959 case 8:
10960 case 9:
10961 case 10:
10962 case 11:
10963 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10964 inst.operands[2].imm = 32;
10965 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10966 break;
10967 case 12:
10968 case 13:
10969 case 14:
10970 case 15:
10971 {
10972 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10973 unsigned long wrn;
10974 wrn = (inst.instruction >> 16) & 0xf;
10975 inst.instruction &= 0xff0fff0f;
10976 inst.instruction |= wrn;
10977 /* Bail out here; the instruction is now assembled. */
10978 return;
10979 }
10980 }
10981 }
10982 /* Map 32 -> 0, etc. */
10983 inst.operands[2].imm &= 0x1f;
eff0bc54 10984 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10985 }
10986}
c19d1205
ZW
10987\f
10988/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10989 operations first, then control, shift, and load/store. */
b99bd4ef 10990
c19d1205 10991/* Insns like "foo X,Y,Z". */
b99bd4ef 10992
c19d1205
ZW
10993static void
10994do_mav_triple (void)
10995{
10996 inst.instruction |= inst.operands[0].reg << 16;
10997 inst.instruction |= inst.operands[1].reg;
10998 inst.instruction |= inst.operands[2].reg << 12;
10999}
b99bd4ef 11000
c19d1205
ZW
11001/* Insns like "foo W,X,Y,Z".
11002 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11003
c19d1205
ZW
11004static void
11005do_mav_quad (void)
11006{
11007 inst.instruction |= inst.operands[0].reg << 5;
11008 inst.instruction |= inst.operands[1].reg << 12;
11009 inst.instruction |= inst.operands[2].reg << 16;
11010 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11011}
11012
c19d1205
ZW
11013/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11014static void
11015do_mav_dspsc (void)
a737bd4d 11016{
c19d1205
ZW
11017 inst.instruction |= inst.operands[1].reg << 12;
11018}
a737bd4d 11019
c19d1205
ZW
11020/* Maverick shift immediate instructions.
11021 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11022 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11023
c19d1205
ZW
11024static void
11025do_mav_shift (void)
11026{
11027 int imm = inst.operands[2].imm;
a737bd4d 11028
c19d1205
ZW
11029 inst.instruction |= inst.operands[0].reg << 12;
11030 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11031
c19d1205
ZW
11032 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11033 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11034 Bit 4 should be 0. */
11035 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11036
c19d1205
ZW
11037 inst.instruction |= imm;
11038}
11039\f
11040/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11041
c19d1205
ZW
11042/* Xscale multiply-accumulate (argument parse)
11043 MIAcc acc0,Rm,Rs
11044 MIAPHcc acc0,Rm,Rs
11045 MIAxycc acc0,Rm,Rs. */
a737bd4d 11046
c19d1205
ZW
11047static void
11048do_xsc_mia (void)
11049{
11050 inst.instruction |= inst.operands[1].reg;
11051 inst.instruction |= inst.operands[2].reg << 12;
11052}
a737bd4d 11053
c19d1205 11054/* Xscale move-accumulator-register (argument parse)
a737bd4d 11055
c19d1205 11056 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11057
c19d1205
ZW
11058static void
11059do_xsc_mar (void)
11060{
11061 inst.instruction |= inst.operands[1].reg << 12;
11062 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11063}
11064
c19d1205 11065/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11066
c19d1205 11067 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11068
11069static void
c19d1205 11070do_xsc_mra (void)
b99bd4ef 11071{
c19d1205
ZW
11072 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11073 inst.instruction |= inst.operands[0].reg << 12;
11074 inst.instruction |= inst.operands[1].reg << 16;
11075}
11076\f
11077/* Encoding functions relevant only to Thumb. */
b99bd4ef 11078
c19d1205
ZW
11079/* inst.operands[i] is a shifted-register operand; encode
11080 it into inst.instruction in the format used by Thumb32. */
11081
11082static void
11083encode_thumb32_shifted_operand (int i)
11084{
e2b0ab59 11085 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11086 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11087
9c3c69f2
PB
11088 constraint (inst.operands[i].immisreg,
11089 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11090 inst.instruction |= inst.operands[i].reg;
11091 if (shift == SHIFT_RRX)
11092 inst.instruction |= SHIFT_ROR << 4;
11093 else
b99bd4ef 11094 {
e2b0ab59 11095 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11096 _("expression too complex"));
11097
11098 constraint (value > 32
11099 || (value == 32 && (shift == SHIFT_LSL
11100 || shift == SHIFT_ROR)),
11101 _("shift expression is too large"));
11102
11103 if (value == 0)
11104 shift = SHIFT_LSL;
11105 else if (value == 32)
11106 value = 0;
11107
11108 inst.instruction |= shift << 4;
11109 inst.instruction |= (value & 0x1c) << 10;
11110 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11111 }
c19d1205 11112}
b99bd4ef 11113
b99bd4ef 11114
c19d1205
ZW
11115/* inst.operands[i] was set up by parse_address. Encode it into a
11116 Thumb32 format load or store instruction. Reject forms that cannot
11117 be used with such instructions. If is_t is true, reject forms that
11118 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11119 that cannot be used with a D instruction. If it is a store insn,
11120 reject PC in Rn. */
b99bd4ef 11121
c19d1205
ZW
11122static void
11123encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11124{
5be8be5d 11125 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11126
11127 constraint (!inst.operands[i].isreg,
53365c0d 11128 _("Instruction does not support =N addresses"));
b99bd4ef 11129
c19d1205
ZW
11130 inst.instruction |= inst.operands[i].reg << 16;
11131 if (inst.operands[i].immisreg)
b99bd4ef 11132 {
5be8be5d 11133 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11134 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11135 constraint (inst.operands[i].negative,
11136 _("Thumb does not support negative register indexing"));
11137 constraint (inst.operands[i].postind,
11138 _("Thumb does not support register post-indexing"));
11139 constraint (inst.operands[i].writeback,
11140 _("Thumb does not support register indexing with writeback"));
11141 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11142 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11143
f40d1643 11144 inst.instruction |= inst.operands[i].imm;
c19d1205 11145 if (inst.operands[i].shifted)
b99bd4ef 11146 {
e2b0ab59 11147 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11148 _("expression too complex"));
e2b0ab59
AV
11149 constraint (inst.relocs[0].exp.X_add_number < 0
11150 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11151 _("shift out of range"));
e2b0ab59 11152 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11153 }
e2b0ab59 11154 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11155 }
11156 else if (inst.operands[i].preind)
11157 {
5be8be5d 11158 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11159 constraint (is_t && inst.operands[i].writeback,
c19d1205 11160 _("cannot use writeback with this instruction"));
4755303e
WN
11161 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11162 BAD_PC_ADDRESSING);
c19d1205
ZW
11163
11164 if (is_d)
11165 {
11166 inst.instruction |= 0x01000000;
11167 if (inst.operands[i].writeback)
11168 inst.instruction |= 0x00200000;
b99bd4ef 11169 }
c19d1205 11170 else
b99bd4ef 11171 {
c19d1205
ZW
11172 inst.instruction |= 0x00000c00;
11173 if (inst.operands[i].writeback)
11174 inst.instruction |= 0x00000100;
b99bd4ef 11175 }
e2b0ab59 11176 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11177 }
c19d1205 11178 else if (inst.operands[i].postind)
b99bd4ef 11179 {
9c2799c2 11180 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11181 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11182 constraint (is_t, _("cannot use post-indexing with this instruction"));
11183
11184 if (is_d)
11185 inst.instruction |= 0x00200000;
11186 else
11187 inst.instruction |= 0x00000900;
e2b0ab59 11188 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11189 }
11190 else /* unindexed - only for coprocessor */
11191 inst.error = _("instruction does not accept unindexed addressing");
11192}
11193
e39c1607 11194/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11195 encodings (the latter only in post-V6T2 cores). The index is the
11196 value used in the insns table below. When there is more than one
11197 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11198 holds variant (1).
11199 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11200#define T16_32_TAB \
21d799b5
NC
11201 X(_adc, 4140, eb400000), \
11202 X(_adcs, 4140, eb500000), \
11203 X(_add, 1c00, eb000000), \
11204 X(_adds, 1c00, eb100000), \
11205 X(_addi, 0000, f1000000), \
11206 X(_addis, 0000, f1100000), \
11207 X(_add_pc,000f, f20f0000), \
11208 X(_add_sp,000d, f10d0000), \
11209 X(_adr, 000f, f20f0000), \
11210 X(_and, 4000, ea000000), \
11211 X(_ands, 4000, ea100000), \
11212 X(_asr, 1000, fa40f000), \
11213 X(_asrs, 1000, fa50f000), \
11214 X(_b, e000, f000b000), \
11215 X(_bcond, d000, f0008000), \
4389b29a 11216 X(_bf, 0000, f040e001), \
f6b2b12d 11217 X(_bfcsel,0000, f000e001), \
f1c7f421 11218 X(_bfx, 0000, f060e001), \
65d1bc05 11219 X(_bfl, 0000, f000c001), \
f1c7f421 11220 X(_bflx, 0000, f070e001), \
21d799b5
NC
11221 X(_bic, 4380, ea200000), \
11222 X(_bics, 4380, ea300000), \
e39c1607
SD
11223 X(_cinc, 0000, ea509000), \
11224 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11225 X(_cmn, 42c0, eb100f00), \
11226 X(_cmp, 2800, ebb00f00), \
e39c1607 11227 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11228 X(_cpsie, b660, f3af8400), \
11229 X(_cpsid, b670, f3af8600), \
11230 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11231 X(_csel, 0000, ea508000), \
11232 X(_cset, 0000, ea5f900f), \
11233 X(_csetm, 0000, ea5fa00f), \
11234 X(_csinc, 0000, ea509000), \
11235 X(_csinv, 0000, ea50a000), \
11236 X(_csneg, 0000, ea50b000), \
21d799b5 11237 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11238 X(_dls, 0000, f040e001), \
1f6234a3 11239 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11240 X(_eor, 4040, ea800000), \
11241 X(_eors, 4040, ea900000), \
11242 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11243 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11244 X(_ldmia, c800, e8900000), \
11245 X(_ldr, 6800, f8500000), \
11246 X(_ldrb, 7800, f8100000), \
11247 X(_ldrh, 8800, f8300000), \
11248 X(_ldrsb, 5600, f9100000), \
11249 X(_ldrsh, 5e00, f9300000), \
11250 X(_ldr_pc,4800, f85f0000), \
11251 X(_ldr_pc2,4800, f85f0000), \
11252 X(_ldr_sp,9800, f85d0000), \
60f993ce 11253 X(_le, 0000, f00fc001), \
1f6234a3 11254 X(_letp, 0000, f01fc001), \
21d799b5
NC
11255 X(_lsl, 0000, fa00f000), \
11256 X(_lsls, 0000, fa10f000), \
11257 X(_lsr, 0800, fa20f000), \
11258 X(_lsrs, 0800, fa30f000), \
11259 X(_mov, 2000, ea4f0000), \
11260 X(_movs, 2000, ea5f0000), \
11261 X(_mul, 4340, fb00f000), \
11262 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11263 X(_mvn, 43c0, ea6f0000), \
11264 X(_mvns, 43c0, ea7f0000), \
11265 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11266 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11267 X(_orr, 4300, ea400000), \
11268 X(_orrs, 4300, ea500000), \
11269 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11270 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11271 X(_rev, ba00, fa90f080), \
11272 X(_rev16, ba40, fa90f090), \
11273 X(_revsh, bac0, fa90f0b0), \
11274 X(_ror, 41c0, fa60f000), \
11275 X(_rors, 41c0, fa70f000), \
11276 X(_sbc, 4180, eb600000), \
11277 X(_sbcs, 4180, eb700000), \
11278 X(_stmia, c000, e8800000), \
11279 X(_str, 6000, f8400000), \
11280 X(_strb, 7000, f8000000), \
11281 X(_strh, 8000, f8200000), \
11282 X(_str_sp,9000, f84d0000), \
11283 X(_sub, 1e00, eba00000), \
11284 X(_subs, 1e00, ebb00000), \
11285 X(_subi, 8000, f1a00000), \
11286 X(_subis, 8000, f1b00000), \
11287 X(_sxtb, b240, fa4ff080), \
11288 X(_sxth, b200, fa0ff080), \
11289 X(_tst, 4200, ea100f00), \
11290 X(_uxtb, b2c0, fa5ff080), \
11291 X(_uxth, b280, fa1ff080), \
11292 X(_nop, bf00, f3af8000), \
11293 X(_yield, bf10, f3af8001), \
11294 X(_wfe, bf20, f3af8002), \
11295 X(_wfi, bf30, f3af8003), \
60f993ce 11296 X(_wls, 0000, f040c001), \
1f6234a3 11297 X(_wlstp, 0000, f000c001), \
53c4b28b 11298 X(_sev, bf40, f3af8004), \
74db7efb
NC
11299 X(_sevl, bf50, f3af8005), \
11300 X(_udf, de00, f7f0a000)
c19d1205
ZW
11301
11302/* To catch errors in encoding functions, the codes are all offset by
11303 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11304 as 16-bit instructions. */
21d799b5 11305#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11306enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11307#undef X
11308
11309#define X(a,b,c) 0x##b
11310static const unsigned short thumb_op16[] = { T16_32_TAB };
11311#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11312#undef X
11313
11314#define X(a,b,c) 0x##c
11315static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11316#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11317#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11318#undef X
11319#undef T16_32_TAB
11320
11321/* Thumb instruction encoders, in alphabetical order. */
11322
92e90b6e 11323/* ADDW or SUBW. */
c921be7d 11324
92e90b6e
PB
11325static void
11326do_t_add_sub_w (void)
11327{
11328 int Rd, Rn;
11329
11330 Rd = inst.operands[0].reg;
11331 Rn = inst.operands[1].reg;
11332
539d4391
NC
11333 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11334 is the SP-{plus,minus}-immediate form of the instruction. */
11335 if (Rn == REG_SP)
11336 constraint (Rd == REG_PC, BAD_PC);
11337 else
11338 reject_bad_reg (Rd);
fdfde340 11339
92e90b6e 11340 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11341 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11342}
11343
c19d1205 11344/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11345 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11346
11347static void
11348do_t_add_sub (void)
11349{
11350 int Rd, Rs, Rn;
11351
11352 Rd = inst.operands[0].reg;
11353 Rs = (inst.operands[1].present
11354 ? inst.operands[1].reg /* Rd, Rs, foo */
11355 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11356
e07e6e58 11357 if (Rd == REG_PC)
5ee91343 11358 set_pred_insn_type_last ();
e07e6e58 11359
c19d1205
ZW
11360 if (unified_syntax)
11361 {
0110f2b8
PB
11362 bfd_boolean flags;
11363 bfd_boolean narrow;
11364 int opcode;
11365
11366 flags = (inst.instruction == T_MNEM_adds
11367 || inst.instruction == T_MNEM_subs);
11368 if (flags)
5ee91343 11369 narrow = !in_pred_block ();
0110f2b8 11370 else
5ee91343 11371 narrow = in_pred_block ();
c19d1205 11372 if (!inst.operands[2].isreg)
b99bd4ef 11373 {
16805f35
PB
11374 int add;
11375
5c8ed6a4
JW
11376 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11377 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11378
16805f35
PB
11379 add = (inst.instruction == T_MNEM_add
11380 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11381 opcode = 0;
11382 if (inst.size_req != 4)
11383 {
0110f2b8 11384 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11385 appropriate. */
0110f2b8
PB
11386 if (Rd == REG_SP && Rs == REG_SP && !flags)
11387 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11388 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11389 opcode = T_MNEM_add_sp;
11390 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11391 opcode = T_MNEM_add_pc;
11392 else if (Rd <= 7 && Rs <= 7 && narrow)
11393 {
11394 if (flags)
11395 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11396 else
11397 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11398 }
11399 if (opcode)
11400 {
11401 inst.instruction = THUMB_OP16(opcode);
11402 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11403 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11404 || (inst.relocs[0].type
11405 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11406 {
11407 if (inst.size_req == 2)
e2b0ab59 11408 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11409 else
11410 inst.relax = opcode;
11411 }
0110f2b8
PB
11412 }
11413 else
11414 constraint (inst.size_req == 2, BAD_HIREG);
11415 }
11416 if (inst.size_req == 4
11417 || (inst.size_req != 2 && !opcode))
11418 {
e2b0ab59
AV
11419 constraint ((inst.relocs[0].type
11420 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11421 && (inst.relocs[0].type
11422 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11423 THUMB1_RELOC_ONLY);
efd81785
PB
11424 if (Rd == REG_PC)
11425 {
fdfde340 11426 constraint (add, BAD_PC);
efd81785
PB
11427 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11428 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11429 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11430 _("expression too complex"));
e2b0ab59
AV
11431 constraint (inst.relocs[0].exp.X_add_number < 0
11432 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11433 _("immediate value out of range"));
11434 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11435 | inst.relocs[0].exp.X_add_number;
11436 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11437 return;
11438 }
11439 else if (Rs == REG_PC)
16805f35
PB
11440 {
11441 /* Always use addw/subw. */
11442 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11443 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11444 }
11445 else
11446 {
11447 inst.instruction = THUMB_OP32 (inst.instruction);
11448 inst.instruction = (inst.instruction & 0xe1ffffff)
11449 | 0x10000000;
11450 if (flags)
e2b0ab59 11451 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11452 else
e2b0ab59 11453 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11454 }
dc4503c6
PB
11455 inst.instruction |= Rd << 8;
11456 inst.instruction |= Rs << 16;
0110f2b8 11457 }
b99bd4ef 11458 }
c19d1205
ZW
11459 else
11460 {
e2b0ab59 11461 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11462 unsigned int shift = inst.operands[2].shift_kind;
11463
c19d1205
ZW
11464 Rn = inst.operands[2].reg;
11465 /* See if we can do this with a 16-bit instruction. */
11466 if (!inst.operands[2].shifted && inst.size_req != 4)
11467 {
e27ec89e
PB
11468 if (Rd > 7 || Rs > 7 || Rn > 7)
11469 narrow = FALSE;
11470
11471 if (narrow)
c19d1205 11472 {
e27ec89e
PB
11473 inst.instruction = ((inst.instruction == T_MNEM_adds
11474 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11475 ? T_OPCODE_ADD_R3
11476 : T_OPCODE_SUB_R3);
11477 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11478 return;
11479 }
b99bd4ef 11480
7e806470 11481 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11482 {
7e806470
PB
11483 /* Thumb-1 cores (except v6-M) require at least one high
11484 register in a narrow non flag setting add. */
11485 if (Rd > 7 || Rn > 7
11486 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11487 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11488 {
7e806470
PB
11489 if (Rd == Rn)
11490 {
11491 Rn = Rs;
11492 Rs = Rd;
11493 }
c19d1205
ZW
11494 inst.instruction = T_OPCODE_ADD_HI;
11495 inst.instruction |= (Rd & 8) << 4;
11496 inst.instruction |= (Rd & 7);
11497 inst.instruction |= Rn << 3;
11498 return;
11499 }
c19d1205
ZW
11500 }
11501 }
c921be7d 11502
fdfde340 11503 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11504 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11505 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11506 constraint (Rs == REG_PC, BAD_PC);
11507 reject_bad_reg (Rn);
11508
c19d1205
ZW
11509 /* If we get here, it can't be done in 16 bits. */
11510 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11511 _("shift must be constant"));
11512 inst.instruction = THUMB_OP32 (inst.instruction);
11513 inst.instruction |= Rd << 8;
11514 inst.instruction |= Rs << 16;
5f4cb198
NC
11515 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11516 _("shift value over 3 not allowed in thumb mode"));
11517 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11518 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11519 encode_thumb32_shifted_operand (2);
11520 }
11521 }
11522 else
11523 {
11524 constraint (inst.instruction == T_MNEM_adds
11525 || inst.instruction == T_MNEM_subs,
11526 BAD_THUMB32);
b99bd4ef 11527
c19d1205 11528 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11529 {
c19d1205
ZW
11530 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11531 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11532 BAD_HIREG);
11533
11534 inst.instruction = (inst.instruction == T_MNEM_add
11535 ? 0x0000 : 0x8000);
11536 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11537 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11538 return;
11539 }
11540
c19d1205
ZW
11541 Rn = inst.operands[2].reg;
11542 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11543
c19d1205
ZW
11544 /* We now have Rd, Rs, and Rn set to registers. */
11545 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11546 {
c19d1205
ZW
11547 /* Can't do this for SUB. */
11548 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11549 inst.instruction = T_OPCODE_ADD_HI;
11550 inst.instruction |= (Rd & 8) << 4;
11551 inst.instruction |= (Rd & 7);
11552 if (Rs == Rd)
11553 inst.instruction |= Rn << 3;
11554 else if (Rn == Rd)
11555 inst.instruction |= Rs << 3;
11556 else
11557 constraint (1, _("dest must overlap one source register"));
11558 }
11559 else
11560 {
11561 inst.instruction = (inst.instruction == T_MNEM_add
11562 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11563 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11564 }
b99bd4ef 11565 }
b99bd4ef
NC
11566}
11567
c19d1205
ZW
11568static void
11569do_t_adr (void)
11570{
fdfde340
JM
11571 unsigned Rd;
11572
11573 Rd = inst.operands[0].reg;
11574 reject_bad_reg (Rd);
11575
11576 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11577 {
11578 /* Defer to section relaxation. */
11579 inst.relax = inst.instruction;
11580 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11581 inst.instruction |= Rd << 4;
0110f2b8
PB
11582 }
11583 else if (unified_syntax && inst.size_req != 2)
e9f89963 11584 {
0110f2b8 11585 /* Generate a 32-bit opcode. */
e9f89963 11586 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11587 inst.instruction |= Rd << 8;
e2b0ab59
AV
11588 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11589 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11590 }
11591 else
11592 {
0110f2b8 11593 /* Generate a 16-bit opcode. */
e9f89963 11594 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11595 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11596 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11597 inst.relocs[0].pc_rel = 1;
fdfde340 11598 inst.instruction |= Rd << 4;
e9f89963 11599 }
52a86f84 11600
e2b0ab59
AV
11601 if (inst.relocs[0].exp.X_op == O_symbol
11602 && inst.relocs[0].exp.X_add_symbol != NULL
11603 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11604 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11605 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11606}
b99bd4ef 11607
c19d1205
ZW
11608/* Arithmetic instructions for which there is just one 16-bit
11609 instruction encoding, and it allows only two low registers.
11610 For maximal compatibility with ARM syntax, we allow three register
11611 operands even when Thumb-32 instructions are not available, as long
11612 as the first two are identical. For instance, both "sbc r0,r1" and
11613 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11614static void
c19d1205 11615do_t_arit3 (void)
b99bd4ef 11616{
c19d1205 11617 int Rd, Rs, Rn;
b99bd4ef 11618
c19d1205
ZW
11619 Rd = inst.operands[0].reg;
11620 Rs = (inst.operands[1].present
11621 ? inst.operands[1].reg /* Rd, Rs, foo */
11622 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11623 Rn = inst.operands[2].reg;
b99bd4ef 11624
fdfde340
JM
11625 reject_bad_reg (Rd);
11626 reject_bad_reg (Rs);
11627 if (inst.operands[2].isreg)
11628 reject_bad_reg (Rn);
11629
c19d1205 11630 if (unified_syntax)
b99bd4ef 11631 {
c19d1205
ZW
11632 if (!inst.operands[2].isreg)
11633 {
11634 /* For an immediate, we always generate a 32-bit opcode;
11635 section relaxation will shrink it later if possible. */
11636 inst.instruction = THUMB_OP32 (inst.instruction);
11637 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11638 inst.instruction |= Rd << 8;
11639 inst.instruction |= Rs << 16;
e2b0ab59 11640 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11641 }
11642 else
11643 {
e27ec89e
PB
11644 bfd_boolean narrow;
11645
c19d1205 11646 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11647 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11648 narrow = !in_pred_block ();
e27ec89e 11649 else
5ee91343 11650 narrow = in_pred_block ();
e27ec89e
PB
11651
11652 if (Rd > 7 || Rn > 7 || Rs > 7)
11653 narrow = FALSE;
11654 if (inst.operands[2].shifted)
11655 narrow = FALSE;
11656 if (inst.size_req == 4)
11657 narrow = FALSE;
11658
11659 if (narrow
c19d1205
ZW
11660 && Rd == Rs)
11661 {
11662 inst.instruction = THUMB_OP16 (inst.instruction);
11663 inst.instruction |= Rd;
11664 inst.instruction |= Rn << 3;
11665 return;
11666 }
b99bd4ef 11667
c19d1205
ZW
11668 /* If we get here, it can't be done in 16 bits. */
11669 constraint (inst.operands[2].shifted
11670 && inst.operands[2].immisreg,
11671 _("shift must be constant"));
11672 inst.instruction = THUMB_OP32 (inst.instruction);
11673 inst.instruction |= Rd << 8;
11674 inst.instruction |= Rs << 16;
11675 encode_thumb32_shifted_operand (2);
11676 }
a737bd4d 11677 }
c19d1205 11678 else
b99bd4ef 11679 {
c19d1205
ZW
11680 /* On its face this is a lie - the instruction does set the
11681 flags. However, the only supported mnemonic in this mode
11682 says it doesn't. */
11683 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11684
c19d1205
ZW
11685 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11686 _("unshifted register required"));
11687 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11688 constraint (Rd != Rs,
11689 _("dest and source1 must be the same register"));
a737bd4d 11690
c19d1205
ZW
11691 inst.instruction = THUMB_OP16 (inst.instruction);
11692 inst.instruction |= Rd;
11693 inst.instruction |= Rn << 3;
b99bd4ef 11694 }
a737bd4d 11695}
b99bd4ef 11696
c19d1205
ZW
11697/* Similarly, but for instructions where the arithmetic operation is
11698 commutative, so we can allow either of them to be different from
11699 the destination operand in a 16-bit instruction. For instance, all
11700 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11701 accepted. */
11702static void
11703do_t_arit3c (void)
a737bd4d 11704{
c19d1205 11705 int Rd, Rs, Rn;
b99bd4ef 11706
c19d1205
ZW
11707 Rd = inst.operands[0].reg;
11708 Rs = (inst.operands[1].present
11709 ? inst.operands[1].reg /* Rd, Rs, foo */
11710 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11711 Rn = inst.operands[2].reg;
c921be7d 11712
fdfde340
JM
11713 reject_bad_reg (Rd);
11714 reject_bad_reg (Rs);
11715 if (inst.operands[2].isreg)
11716 reject_bad_reg (Rn);
a737bd4d 11717
c19d1205 11718 if (unified_syntax)
a737bd4d 11719 {
c19d1205 11720 if (!inst.operands[2].isreg)
b99bd4ef 11721 {
c19d1205
ZW
11722 /* For an immediate, we always generate a 32-bit opcode;
11723 section relaxation will shrink it later if possible. */
11724 inst.instruction = THUMB_OP32 (inst.instruction);
11725 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11726 inst.instruction |= Rd << 8;
11727 inst.instruction |= Rs << 16;
e2b0ab59 11728 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11729 }
c19d1205 11730 else
a737bd4d 11731 {
e27ec89e
PB
11732 bfd_boolean narrow;
11733
c19d1205 11734 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11735 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11736 narrow = !in_pred_block ();
e27ec89e 11737 else
5ee91343 11738 narrow = in_pred_block ();
e27ec89e
PB
11739
11740 if (Rd > 7 || Rn > 7 || Rs > 7)
11741 narrow = FALSE;
11742 if (inst.operands[2].shifted)
11743 narrow = FALSE;
11744 if (inst.size_req == 4)
11745 narrow = FALSE;
11746
11747 if (narrow)
a737bd4d 11748 {
c19d1205 11749 if (Rd == Rs)
a737bd4d 11750 {
c19d1205
ZW
11751 inst.instruction = THUMB_OP16 (inst.instruction);
11752 inst.instruction |= Rd;
11753 inst.instruction |= Rn << 3;
11754 return;
a737bd4d 11755 }
c19d1205 11756 if (Rd == Rn)
a737bd4d 11757 {
c19d1205
ZW
11758 inst.instruction = THUMB_OP16 (inst.instruction);
11759 inst.instruction |= Rd;
11760 inst.instruction |= Rs << 3;
11761 return;
a737bd4d
NC
11762 }
11763 }
c19d1205
ZW
11764
11765 /* If we get here, it can't be done in 16 bits. */
11766 constraint (inst.operands[2].shifted
11767 && inst.operands[2].immisreg,
11768 _("shift must be constant"));
11769 inst.instruction = THUMB_OP32 (inst.instruction);
11770 inst.instruction |= Rd << 8;
11771 inst.instruction |= Rs << 16;
11772 encode_thumb32_shifted_operand (2);
a737bd4d 11773 }
b99bd4ef 11774 }
c19d1205
ZW
11775 else
11776 {
11777 /* On its face this is a lie - the instruction does set the
11778 flags. However, the only supported mnemonic in this mode
11779 says it doesn't. */
11780 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11781
c19d1205
ZW
11782 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11783 _("unshifted register required"));
11784 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11785
11786 inst.instruction = THUMB_OP16 (inst.instruction);
11787 inst.instruction |= Rd;
11788
11789 if (Rd == Rs)
11790 inst.instruction |= Rn << 3;
11791 else if (Rd == Rn)
11792 inst.instruction |= Rs << 3;
11793 else
11794 constraint (1, _("dest must overlap one source register"));
11795 }
a737bd4d
NC
11796}
11797
c19d1205
ZW
11798static void
11799do_t_bfc (void)
a737bd4d 11800{
fdfde340 11801 unsigned Rd;
c19d1205
ZW
11802 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11803 constraint (msb > 32, _("bit-field extends past end of register"));
11804 /* The instruction encoding stores the LSB and MSB,
11805 not the LSB and width. */
fdfde340
JM
11806 Rd = inst.operands[0].reg;
11807 reject_bad_reg (Rd);
11808 inst.instruction |= Rd << 8;
c19d1205
ZW
11809 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11810 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11811 inst.instruction |= msb - 1;
b99bd4ef
NC
11812}
11813
c19d1205
ZW
11814static void
11815do_t_bfi (void)
b99bd4ef 11816{
fdfde340 11817 int Rd, Rn;
c19d1205 11818 unsigned int msb;
b99bd4ef 11819
fdfde340
JM
11820 Rd = inst.operands[0].reg;
11821 reject_bad_reg (Rd);
11822
c19d1205
ZW
11823 /* #0 in second position is alternative syntax for bfc, which is
11824 the same instruction but with REG_PC in the Rm field. */
11825 if (!inst.operands[1].isreg)
fdfde340
JM
11826 Rn = REG_PC;
11827 else
11828 {
11829 Rn = inst.operands[1].reg;
11830 reject_bad_reg (Rn);
11831 }
b99bd4ef 11832
c19d1205
ZW
11833 msb = inst.operands[2].imm + inst.operands[3].imm;
11834 constraint (msb > 32, _("bit-field extends past end of register"));
11835 /* The instruction encoding stores the LSB and MSB,
11836 not the LSB and width. */
fdfde340
JM
11837 inst.instruction |= Rd << 8;
11838 inst.instruction |= Rn << 16;
c19d1205
ZW
11839 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11840 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11841 inst.instruction |= msb - 1;
b99bd4ef
NC
11842}
11843
c19d1205
ZW
11844static void
11845do_t_bfx (void)
b99bd4ef 11846{
fdfde340
JM
11847 unsigned Rd, Rn;
11848
11849 Rd = inst.operands[0].reg;
11850 Rn = inst.operands[1].reg;
11851
11852 reject_bad_reg (Rd);
11853 reject_bad_reg (Rn);
11854
c19d1205
ZW
11855 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11856 _("bit-field extends past end of register"));
fdfde340
JM
11857 inst.instruction |= Rd << 8;
11858 inst.instruction |= Rn << 16;
c19d1205
ZW
11859 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11860 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11861 inst.instruction |= inst.operands[3].imm - 1;
11862}
b99bd4ef 11863
c19d1205
ZW
11864/* ARM V5 Thumb BLX (argument parse)
11865 BLX <target_addr> which is BLX(1)
11866 BLX <Rm> which is BLX(2)
11867 Unfortunately, there are two different opcodes for this mnemonic.
11868 So, the insns[].value is not used, and the code here zaps values
11869 into inst.instruction.
b99bd4ef 11870
c19d1205
ZW
11871 ??? How to take advantage of the additional two bits of displacement
11872 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11873
c19d1205
ZW
11874static void
11875do_t_blx (void)
11876{
5ee91343 11877 set_pred_insn_type_last ();
e07e6e58 11878
c19d1205 11879 if (inst.operands[0].isreg)
fdfde340
JM
11880 {
11881 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11882 /* We have a register, so this is BLX(2). */
11883 inst.instruction |= inst.operands[0].reg << 3;
11884 }
b99bd4ef
NC
11885 else
11886 {
c19d1205 11887 /* No register. This must be BLX(1). */
2fc8bdac 11888 inst.instruction = 0xf000e800;
0855e32b 11889 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11890 }
11891}
11892
c19d1205
ZW
11893static void
11894do_t_branch (void)
b99bd4ef 11895{
0110f2b8 11896 int opcode;
dfa9f0d5 11897 int cond;
2fe88214 11898 bfd_reloc_code_real_type reloc;
dfa9f0d5 11899
e07e6e58 11900 cond = inst.cond;
5ee91343 11901 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 11902
5ee91343 11903 if (in_pred_block ())
dfa9f0d5
PB
11904 {
11905 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11906 branches. */
dfa9f0d5 11907 cond = COND_ALWAYS;
dfa9f0d5
PB
11908 }
11909 else
11910 cond = inst.cond;
11911
11912 if (cond != COND_ALWAYS)
0110f2b8
PB
11913 opcode = T_MNEM_bcond;
11914 else
11915 opcode = inst.instruction;
11916
12d6b0b7
RS
11917 if (unified_syntax
11918 && (inst.size_req == 4
10960bfb
PB
11919 || (inst.size_req != 2
11920 && (inst.operands[0].hasreloc
e2b0ab59 11921 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 11922 {
0110f2b8 11923 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11924 if (cond == COND_ALWAYS)
9ae92b05 11925 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11926 else
11927 {
ff8646ee
TP
11928 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11929 _("selected architecture does not support "
11930 "wide conditional branch instruction"));
11931
9c2799c2 11932 gas_assert (cond != 0xF);
dfa9f0d5 11933 inst.instruction |= cond << 22;
9ae92b05 11934 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11935 }
11936 }
b99bd4ef
NC
11937 else
11938 {
0110f2b8 11939 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11940 if (cond == COND_ALWAYS)
9ae92b05 11941 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11942 else
b99bd4ef 11943 {
dfa9f0d5 11944 inst.instruction |= cond << 8;
9ae92b05 11945 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11946 }
0110f2b8
PB
11947 /* Allow section relaxation. */
11948 if (unified_syntax && inst.size_req != 2)
11949 inst.relax = opcode;
b99bd4ef 11950 }
e2b0ab59
AV
11951 inst.relocs[0].type = reloc;
11952 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
11953}
11954
8884b720 11955/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11956 between the two is the maximum immediate allowed - which is passed in
8884b720 11957 RANGE. */
b99bd4ef 11958static void
8884b720 11959do_t_bkpt_hlt1 (int range)
b99bd4ef 11960{
dfa9f0d5
PB
11961 constraint (inst.cond != COND_ALWAYS,
11962 _("instruction is always unconditional"));
c19d1205 11963 if (inst.operands[0].present)
b99bd4ef 11964 {
8884b720 11965 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11966 _("immediate value out of range"));
11967 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11968 }
8884b720 11969
5ee91343 11970 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
11971}
11972
11973static void
11974do_t_hlt (void)
11975{
11976 do_t_bkpt_hlt1 (63);
11977}
11978
11979static void
11980do_t_bkpt (void)
11981{
11982 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11983}
11984
11985static void
c19d1205 11986do_t_branch23 (void)
b99bd4ef 11987{
5ee91343 11988 set_pred_insn_type_last ();
0855e32b 11989 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11990
0855e32b
NS
11991 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11992 this file. We used to simply ignore the PLT reloc type here --
11993 the branch encoding is now needed to deal with TLSCALL relocs.
11994 So if we see a PLT reloc now, put it back to how it used to be to
11995 keep the preexisting behaviour. */
e2b0ab59
AV
11996 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11997 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11998
4343666d 11999#if defined(OBJ_COFF)
c19d1205
ZW
12000 /* If the destination of the branch is a defined symbol which does not have
12001 the THUMB_FUNC attribute, then we must be calling a function which has
12002 the (interfacearm) attribute. We look for the Thumb entry point to that
12003 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12004 if ( inst.relocs[0].exp.X_op == O_symbol
12005 && inst.relocs[0].exp.X_add_symbol != NULL
12006 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12007 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12008 inst.relocs[0].exp.X_add_symbol
12009 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12010#endif
90e4755a
RE
12011}
12012
12013static void
c19d1205 12014do_t_bx (void)
90e4755a 12015{
5ee91343 12016 set_pred_insn_type_last ();
c19d1205
ZW
12017 inst.instruction |= inst.operands[0].reg << 3;
12018 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12019 should cause the alignment to be checked once it is known. This is
12020 because BX PC only works if the instruction is word aligned. */
12021}
90e4755a 12022
c19d1205
ZW
12023static void
12024do_t_bxj (void)
12025{
fdfde340 12026 int Rm;
90e4755a 12027
5ee91343 12028 set_pred_insn_type_last ();
fdfde340
JM
12029 Rm = inst.operands[0].reg;
12030 reject_bad_reg (Rm);
12031 inst.instruction |= Rm << 16;
90e4755a
RE
12032}
12033
12034static void
c19d1205 12035do_t_clz (void)
90e4755a 12036{
fdfde340
JM
12037 unsigned Rd;
12038 unsigned Rm;
12039
12040 Rd = inst.operands[0].reg;
12041 Rm = inst.operands[1].reg;
12042
12043 reject_bad_reg (Rd);
12044 reject_bad_reg (Rm);
12045
12046 inst.instruction |= Rd << 8;
12047 inst.instruction |= Rm << 16;
12048 inst.instruction |= Rm;
c19d1205 12049}
90e4755a 12050
e39c1607
SD
12051/* For the Armv8.1-M conditional instructions. */
12052static void
12053do_t_cond (void)
12054{
12055 unsigned Rd, Rn, Rm;
12056 signed int cond;
12057
12058 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12059
12060 Rd = inst.operands[0].reg;
12061 switch (inst.instruction)
12062 {
12063 case T_MNEM_csinc:
12064 case T_MNEM_csinv:
12065 case T_MNEM_csneg:
12066 case T_MNEM_csel:
12067 Rn = inst.operands[1].reg;
12068 Rm = inst.operands[2].reg;
12069 cond = inst.operands[3].imm;
12070 constraint (Rn == REG_SP, BAD_SP);
12071 constraint (Rm == REG_SP, BAD_SP);
12072 break;
12073
12074 case T_MNEM_cinc:
12075 case T_MNEM_cinv:
12076 case T_MNEM_cneg:
12077 Rn = inst.operands[1].reg;
12078 cond = inst.operands[2].imm;
12079 /* Invert the last bit to invert the cond. */
12080 cond = TOGGLE_BIT (cond, 0);
12081 constraint (Rn == REG_SP, BAD_SP);
12082 Rm = Rn;
12083 break;
12084
12085 case T_MNEM_csetm:
12086 case T_MNEM_cset:
12087 cond = inst.operands[1].imm;
12088 /* Invert the last bit to invert the cond. */
12089 cond = TOGGLE_BIT (cond, 0);
12090 Rn = REG_PC;
12091 Rm = REG_PC;
12092 break;
12093
12094 default: abort ();
12095 }
12096
12097 set_pred_insn_type (OUTSIDE_PRED_INSN);
12098 inst.instruction = THUMB_OP32 (inst.instruction);
12099 inst.instruction |= Rd << 8;
12100 inst.instruction |= Rn << 16;
12101 inst.instruction |= Rm;
12102 inst.instruction |= cond << 4;
12103}
12104
91d8b670
JG
12105static void
12106do_t_csdb (void)
12107{
5ee91343 12108 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12109}
12110
dfa9f0d5
PB
12111static void
12112do_t_cps (void)
12113{
5ee91343 12114 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12115 inst.instruction |= inst.operands[0].imm;
12116}
12117
c19d1205
ZW
12118static void
12119do_t_cpsi (void)
12120{
5ee91343 12121 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12122 if (unified_syntax
62b3e311
PB
12123 && (inst.operands[1].present || inst.size_req == 4)
12124 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12125 {
c19d1205
ZW
12126 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12127 inst.instruction = 0xf3af8000;
12128 inst.instruction |= imod << 9;
12129 inst.instruction |= inst.operands[0].imm << 5;
12130 if (inst.operands[1].present)
12131 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12132 }
c19d1205 12133 else
90e4755a 12134 {
62b3e311
PB
12135 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12136 && (inst.operands[0].imm & 4),
12137 _("selected processor does not support 'A' form "
12138 "of this instruction"));
12139 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12140 _("Thumb does not support the 2-argument "
12141 "form of this instruction"));
12142 inst.instruction |= inst.operands[0].imm;
90e4755a 12143 }
90e4755a
RE
12144}
12145
c19d1205
ZW
12146/* THUMB CPY instruction (argument parse). */
12147
90e4755a 12148static void
c19d1205 12149do_t_cpy (void)
90e4755a 12150{
c19d1205 12151 if (inst.size_req == 4)
90e4755a 12152 {
c19d1205
ZW
12153 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12154 inst.instruction |= inst.operands[0].reg << 8;
12155 inst.instruction |= inst.operands[1].reg;
90e4755a 12156 }
c19d1205 12157 else
90e4755a 12158 {
c19d1205
ZW
12159 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12160 inst.instruction |= (inst.operands[0].reg & 0x7);
12161 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12162 }
90e4755a
RE
12163}
12164
90e4755a 12165static void
25fe350b 12166do_t_cbz (void)
90e4755a 12167{
5ee91343 12168 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12169 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12170 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12171 inst.relocs[0].pc_rel = 1;
12172 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12173}
90e4755a 12174
62b3e311
PB
12175static void
12176do_t_dbg (void)
12177{
12178 inst.instruction |= inst.operands[0].imm;
12179}
12180
12181static void
12182do_t_div (void)
12183{
fdfde340
JM
12184 unsigned Rd, Rn, Rm;
12185
12186 Rd = inst.operands[0].reg;
12187 Rn = (inst.operands[1].present
12188 ? inst.operands[1].reg : Rd);
12189 Rm = inst.operands[2].reg;
12190
12191 reject_bad_reg (Rd);
12192 reject_bad_reg (Rn);
12193 reject_bad_reg (Rm);
12194
12195 inst.instruction |= Rd << 8;
12196 inst.instruction |= Rn << 16;
12197 inst.instruction |= Rm;
62b3e311
PB
12198}
12199
c19d1205
ZW
12200static void
12201do_t_hint (void)
12202{
12203 if (unified_syntax && inst.size_req == 4)
12204 inst.instruction = THUMB_OP32 (inst.instruction);
12205 else
12206 inst.instruction = THUMB_OP16 (inst.instruction);
12207}
90e4755a 12208
c19d1205
ZW
12209static void
12210do_t_it (void)
12211{
12212 unsigned int cond = inst.operands[0].imm;
e27ec89e 12213
5ee91343
AV
12214 set_pred_insn_type (IT_INSN);
12215 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12216 now_pred.cc = cond;
12217 now_pred.warn_deprecated = FALSE;
12218 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12219
12220 /* If the condition is a negative condition, invert the mask. */
c19d1205 12221 if ((cond & 0x1) == 0x0)
90e4755a 12222 {
c19d1205 12223 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12224
c19d1205 12225 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12226 {
12227 /* No conversion needed. */
5ee91343 12228 now_pred.block_length = 1;
5a01bb1d 12229 }
c19d1205 12230 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12231 {
12232 mask ^= 0x8;
5ee91343 12233 now_pred.block_length = 2;
5a01bb1d 12234 }
e27ec89e 12235 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12236 {
12237 mask ^= 0xC;
5ee91343 12238 now_pred.block_length = 3;
5a01bb1d 12239 }
c19d1205 12240 else
5a01bb1d
MGD
12241 {
12242 mask ^= 0xE;
5ee91343 12243 now_pred.block_length = 4;
5a01bb1d 12244 }
90e4755a 12245
e27ec89e
PB
12246 inst.instruction &= 0xfff0;
12247 inst.instruction |= mask;
c19d1205 12248 }
90e4755a 12249
c19d1205
ZW
12250 inst.instruction |= cond << 4;
12251}
90e4755a 12252
3c707909
PB
12253/* Helper function used for both push/pop and ldm/stm. */
12254static void
4b5a202f
AV
12255encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12256 bfd_boolean writeback)
3c707909 12257{
4b5a202f 12258 bfd_boolean load, store;
3c707909 12259
4b5a202f
AV
12260 gas_assert (base != -1 || !do_io);
12261 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12262 store = do_io && !load;
3c707909
PB
12263
12264 if (mask & (1 << 13))
12265 inst.error = _("SP not allowed in register list");
1e5b0379 12266
4b5a202f 12267 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12268 && writeback)
12269 inst.error = _("having the base register in the register list when "
12270 "using write back is UNPREDICTABLE");
12271
3c707909
PB
12272 if (load)
12273 {
e07e6e58 12274 if (mask & (1 << 15))
477330fc
RM
12275 {
12276 if (mask & (1 << 14))
12277 inst.error = _("LR and PC should not both be in register list");
12278 else
5ee91343 12279 set_pred_insn_type_last ();
477330fc 12280 }
3c707909 12281 }
4b5a202f 12282 else if (store)
3c707909
PB
12283 {
12284 if (mask & (1 << 15))
12285 inst.error = _("PC not allowed in register list");
3c707909
PB
12286 }
12287
4b5a202f 12288 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12289 {
12290 /* Single register transfers implemented as str/ldr. */
12291 if (writeback)
12292 {
12293 if (inst.instruction & (1 << 23))
12294 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12295 else
12296 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12297 }
12298 else
12299 {
12300 if (inst.instruction & (1 << 23))
12301 inst.instruction = 0x00800000; /* ia -> [base] */
12302 else
12303 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12304 }
12305
12306 inst.instruction |= 0xf8400000;
12307 if (load)
12308 inst.instruction |= 0x00100000;
12309
5f4273c7 12310 mask = ffs (mask) - 1;
3c707909
PB
12311 mask <<= 12;
12312 }
12313 else if (writeback)
12314 inst.instruction |= WRITE_BACK;
12315
12316 inst.instruction |= mask;
4b5a202f
AV
12317 if (do_io)
12318 inst.instruction |= base << 16;
3c707909
PB
12319}
12320
c19d1205
ZW
12321static void
12322do_t_ldmstm (void)
12323{
12324 /* This really doesn't seem worth it. */
e2b0ab59 12325 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12326 _("expression too complex"));
12327 constraint (inst.operands[1].writeback,
12328 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12329
c19d1205
ZW
12330 if (unified_syntax)
12331 {
3c707909
PB
12332 bfd_boolean narrow;
12333 unsigned mask;
12334
12335 narrow = FALSE;
c19d1205
ZW
12336 /* See if we can use a 16-bit instruction. */
12337 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12338 && inst.size_req != 4
3c707909 12339 && !(inst.operands[1].imm & ~0xff))
90e4755a 12340 {
3c707909 12341 mask = 1 << inst.operands[0].reg;
90e4755a 12342
eab4f823 12343 if (inst.operands[0].reg <= 7)
90e4755a 12344 {
3c707909 12345 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12346 ? inst.operands[0].writeback
12347 : (inst.operands[0].writeback
12348 == !(inst.operands[1].imm & mask)))
477330fc 12349 {
eab4f823
MGD
12350 if (inst.instruction == T_MNEM_stmia
12351 && (inst.operands[1].imm & mask)
12352 && (inst.operands[1].imm & (mask - 1)))
12353 as_warn (_("value stored for r%d is UNKNOWN"),
12354 inst.operands[0].reg);
3c707909 12355
eab4f823
MGD
12356 inst.instruction = THUMB_OP16 (inst.instruction);
12357 inst.instruction |= inst.operands[0].reg << 8;
12358 inst.instruction |= inst.operands[1].imm;
12359 narrow = TRUE;
12360 }
12361 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12362 {
12363 /* This means 1 register in reg list one of 3 situations:
12364 1. Instruction is stmia, but without writeback.
12365 2. lmdia without writeback, but with Rn not in
477330fc 12366 reglist.
eab4f823
MGD
12367 3. ldmia with writeback, but with Rn in reglist.
12368 Case 3 is UNPREDICTABLE behaviour, so we handle
12369 case 1 and 2 which can be converted into a 16-bit
12370 str or ldr. The SP cases are handled below. */
12371 unsigned long opcode;
12372 /* First, record an error for Case 3. */
12373 if (inst.operands[1].imm & mask
12374 && inst.operands[0].writeback)
fa94de6b 12375 inst.error =
eab4f823
MGD
12376 _("having the base register in the register list when "
12377 "using write back is UNPREDICTABLE");
fa94de6b
RM
12378
12379 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12380 : T_MNEM_ldr);
12381 inst.instruction = THUMB_OP16 (opcode);
12382 inst.instruction |= inst.operands[0].reg << 3;
12383 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12384 narrow = TRUE;
12385 }
90e4755a 12386 }
eab4f823 12387 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12388 {
eab4f823
MGD
12389 if (inst.operands[0].writeback)
12390 {
fa94de6b 12391 inst.instruction =
eab4f823 12392 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12393 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12394 inst.instruction |= inst.operands[1].imm;
477330fc 12395 narrow = TRUE;
eab4f823
MGD
12396 }
12397 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12398 {
fa94de6b 12399 inst.instruction =
eab4f823 12400 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12401 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12402 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12403 narrow = TRUE;
eab4f823 12404 }
90e4755a 12405 }
3c707909
PB
12406 }
12407
12408 if (!narrow)
12409 {
c19d1205
ZW
12410 if (inst.instruction < 0xffff)
12411 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12412
4b5a202f
AV
12413 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12414 inst.operands[1].imm,
12415 inst.operands[0].writeback);
90e4755a
RE
12416 }
12417 }
c19d1205 12418 else
90e4755a 12419 {
c19d1205
ZW
12420 constraint (inst.operands[0].reg > 7
12421 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12422 constraint (inst.instruction != T_MNEM_ldmia
12423 && inst.instruction != T_MNEM_stmia,
12424 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12425 if (inst.instruction == T_MNEM_stmia)
f03698e6 12426 {
c19d1205
ZW
12427 if (!inst.operands[0].writeback)
12428 as_warn (_("this instruction will write back the base register"));
12429 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12430 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12431 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12432 inst.operands[0].reg);
f03698e6 12433 }
c19d1205 12434 else
90e4755a 12435 {
c19d1205
ZW
12436 if (!inst.operands[0].writeback
12437 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12438 as_warn (_("this instruction will write back the base register"));
12439 else if (inst.operands[0].writeback
12440 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12441 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12442 }
12443
c19d1205
ZW
12444 inst.instruction = THUMB_OP16 (inst.instruction);
12445 inst.instruction |= inst.operands[0].reg << 8;
12446 inst.instruction |= inst.operands[1].imm;
12447 }
12448}
e28cd48c 12449
c19d1205
ZW
12450static void
12451do_t_ldrex (void)
12452{
12453 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12454 || inst.operands[1].postind || inst.operands[1].writeback
12455 || inst.operands[1].immisreg || inst.operands[1].shifted
12456 || inst.operands[1].negative,
01cfc07f 12457 BAD_ADDR_MODE);
e28cd48c 12458
5be8be5d
DG
12459 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12460
c19d1205
ZW
12461 inst.instruction |= inst.operands[0].reg << 12;
12462 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12463 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12464}
e28cd48c 12465
c19d1205
ZW
12466static void
12467do_t_ldrexd (void)
12468{
12469 if (!inst.operands[1].present)
1cac9012 12470 {
c19d1205
ZW
12471 constraint (inst.operands[0].reg == REG_LR,
12472 _("r14 not allowed as first register "
12473 "when second register is omitted"));
12474 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12475 }
c19d1205
ZW
12476 constraint (inst.operands[0].reg == inst.operands[1].reg,
12477 BAD_OVERLAP);
b99bd4ef 12478
c19d1205
ZW
12479 inst.instruction |= inst.operands[0].reg << 12;
12480 inst.instruction |= inst.operands[1].reg << 8;
12481 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12482}
12483
12484static void
c19d1205 12485do_t_ldst (void)
b99bd4ef 12486{
0110f2b8
PB
12487 unsigned long opcode;
12488 int Rn;
12489
e07e6e58
NC
12490 if (inst.operands[0].isreg
12491 && !inst.operands[0].preind
12492 && inst.operands[0].reg == REG_PC)
5ee91343 12493 set_pred_insn_type_last ();
e07e6e58 12494
0110f2b8 12495 opcode = inst.instruction;
c19d1205 12496 if (unified_syntax)
b99bd4ef 12497 {
53365c0d
PB
12498 if (!inst.operands[1].isreg)
12499 {
12500 if (opcode <= 0xffff)
12501 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12502 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12503 return;
12504 }
0110f2b8
PB
12505 if (inst.operands[1].isreg
12506 && !inst.operands[1].writeback
c19d1205
ZW
12507 && !inst.operands[1].shifted && !inst.operands[1].postind
12508 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12509 && opcode <= 0xffff
12510 && inst.size_req != 4)
c19d1205 12511 {
0110f2b8
PB
12512 /* Insn may have a 16-bit form. */
12513 Rn = inst.operands[1].reg;
12514 if (inst.operands[1].immisreg)
12515 {
12516 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12517 /* [Rn, Rik] */
0110f2b8
PB
12518 if (Rn <= 7 && inst.operands[1].imm <= 7)
12519 goto op16;
5be8be5d
DG
12520 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12521 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12522 }
12523 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12524 && opcode != T_MNEM_ldrsb)
12525 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12526 || (Rn == REG_SP && opcode == T_MNEM_str))
12527 {
12528 /* [Rn, #const] */
12529 if (Rn > 7)
12530 {
12531 if (Rn == REG_PC)
12532 {
e2b0ab59 12533 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12534 opcode = T_MNEM_ldr_pc2;
12535 else
12536 opcode = T_MNEM_ldr_pc;
12537 }
12538 else
12539 {
12540 if (opcode == T_MNEM_ldr)
12541 opcode = T_MNEM_ldr_sp;
12542 else
12543 opcode = T_MNEM_str_sp;
12544 }
12545 inst.instruction = inst.operands[0].reg << 8;
12546 }
12547 else
12548 {
12549 inst.instruction = inst.operands[0].reg;
12550 inst.instruction |= inst.operands[1].reg << 3;
12551 }
12552 inst.instruction |= THUMB_OP16 (opcode);
12553 if (inst.size_req == 2)
e2b0ab59 12554 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12555 else
12556 inst.relax = opcode;
12557 return;
12558 }
c19d1205 12559 }
0110f2b8 12560 /* Definitely a 32-bit variant. */
5be8be5d 12561
8d67f500
NC
12562 /* Warning for Erratum 752419. */
12563 if (opcode == T_MNEM_ldr
12564 && inst.operands[0].reg == REG_SP
12565 && inst.operands[1].writeback == 1
12566 && !inst.operands[1].immisreg)
12567 {
12568 if (no_cpu_selected ()
12569 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12570 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12571 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12572 as_warn (_("This instruction may be unpredictable "
12573 "if executed on M-profile cores "
12574 "with interrupts enabled."));
12575 }
12576
5be8be5d 12577 /* Do some validations regarding addressing modes. */
1be5fd2e 12578 if (inst.operands[1].immisreg)
5be8be5d
DG
12579 reject_bad_reg (inst.operands[1].imm);
12580
1be5fd2e
NC
12581 constraint (inst.operands[1].writeback == 1
12582 && inst.operands[0].reg == inst.operands[1].reg,
12583 BAD_OVERLAP);
12584
0110f2b8 12585 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12586 inst.instruction |= inst.operands[0].reg << 12;
12587 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12588 check_ldr_r15_aligned ();
b99bd4ef
NC
12589 return;
12590 }
12591
c19d1205
ZW
12592 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12593
12594 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12595 {
c19d1205
ZW
12596 /* Only [Rn,Rm] is acceptable. */
12597 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12598 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12599 || inst.operands[1].postind || inst.operands[1].shifted
12600 || inst.operands[1].negative,
12601 _("Thumb does not support this addressing mode"));
12602 inst.instruction = THUMB_OP16 (inst.instruction);
12603 goto op16;
b99bd4ef 12604 }
5f4273c7 12605
c19d1205
ZW
12606 inst.instruction = THUMB_OP16 (inst.instruction);
12607 if (!inst.operands[1].isreg)
8335d6aa 12608 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12609 return;
b99bd4ef 12610
c19d1205
ZW
12611 constraint (!inst.operands[1].preind
12612 || inst.operands[1].shifted
12613 || inst.operands[1].writeback,
12614 _("Thumb does not support this addressing mode"));
12615 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12616 {
c19d1205
ZW
12617 constraint (inst.instruction & 0x0600,
12618 _("byte or halfword not valid for base register"));
12619 constraint (inst.operands[1].reg == REG_PC
12620 && !(inst.instruction & THUMB_LOAD_BIT),
12621 _("r15 based store not allowed"));
12622 constraint (inst.operands[1].immisreg,
12623 _("invalid base register for register offset"));
b99bd4ef 12624
c19d1205
ZW
12625 if (inst.operands[1].reg == REG_PC)
12626 inst.instruction = T_OPCODE_LDR_PC;
12627 else if (inst.instruction & THUMB_LOAD_BIT)
12628 inst.instruction = T_OPCODE_LDR_SP;
12629 else
12630 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12631
c19d1205 12632 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12633 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12634 return;
12635 }
90e4755a 12636
c19d1205
ZW
12637 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12638 if (!inst.operands[1].immisreg)
12639 {
12640 /* Immediate offset. */
12641 inst.instruction |= inst.operands[0].reg;
12642 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12643 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12644 return;
12645 }
90e4755a 12646
c19d1205
ZW
12647 /* Register offset. */
12648 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12649 constraint (inst.operands[1].negative,
12650 _("Thumb does not support this addressing mode"));
90e4755a 12651
c19d1205
ZW
12652 op16:
12653 switch (inst.instruction)
12654 {
12655 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12656 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12657 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12658 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12659 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12660 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12661 case 0x5600 /* ldrsb */:
12662 case 0x5e00 /* ldrsh */: break;
12663 default: abort ();
12664 }
90e4755a 12665
c19d1205
ZW
12666 inst.instruction |= inst.operands[0].reg;
12667 inst.instruction |= inst.operands[1].reg << 3;
12668 inst.instruction |= inst.operands[1].imm << 6;
12669}
90e4755a 12670
c19d1205
ZW
12671static void
12672do_t_ldstd (void)
12673{
12674 if (!inst.operands[1].present)
b99bd4ef 12675 {
c19d1205
ZW
12676 inst.operands[1].reg = inst.operands[0].reg + 1;
12677 constraint (inst.operands[0].reg == REG_LR,
12678 _("r14 not allowed here"));
bd340a04 12679 constraint (inst.operands[0].reg == REG_R12,
477330fc 12680 _("r12 not allowed here"));
b99bd4ef 12681 }
bd340a04
MGD
12682
12683 if (inst.operands[2].writeback
12684 && (inst.operands[0].reg == inst.operands[2].reg
12685 || inst.operands[1].reg == inst.operands[2].reg))
12686 as_warn (_("base register written back, and overlaps "
477330fc 12687 "one of transfer registers"));
bd340a04 12688
c19d1205
ZW
12689 inst.instruction |= inst.operands[0].reg << 12;
12690 inst.instruction |= inst.operands[1].reg << 8;
12691 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12692}
12693
c19d1205
ZW
12694static void
12695do_t_ldstt (void)
12696{
12697 inst.instruction |= inst.operands[0].reg << 12;
12698 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12699}
a737bd4d 12700
b99bd4ef 12701static void
c19d1205 12702do_t_mla (void)
b99bd4ef 12703{
fdfde340 12704 unsigned Rd, Rn, Rm, Ra;
c921be7d 12705
fdfde340
JM
12706 Rd = inst.operands[0].reg;
12707 Rn = inst.operands[1].reg;
12708 Rm = inst.operands[2].reg;
12709 Ra = inst.operands[3].reg;
12710
12711 reject_bad_reg (Rd);
12712 reject_bad_reg (Rn);
12713 reject_bad_reg (Rm);
12714 reject_bad_reg (Ra);
12715
12716 inst.instruction |= Rd << 8;
12717 inst.instruction |= Rn << 16;
12718 inst.instruction |= Rm;
12719 inst.instruction |= Ra << 12;
c19d1205 12720}
b99bd4ef 12721
c19d1205
ZW
12722static void
12723do_t_mlal (void)
12724{
fdfde340
JM
12725 unsigned RdLo, RdHi, Rn, Rm;
12726
12727 RdLo = inst.operands[0].reg;
12728 RdHi = inst.operands[1].reg;
12729 Rn = inst.operands[2].reg;
12730 Rm = inst.operands[3].reg;
12731
12732 reject_bad_reg (RdLo);
12733 reject_bad_reg (RdHi);
12734 reject_bad_reg (Rn);
12735 reject_bad_reg (Rm);
12736
12737 inst.instruction |= RdLo << 12;
12738 inst.instruction |= RdHi << 8;
12739 inst.instruction |= Rn << 16;
12740 inst.instruction |= Rm;
c19d1205 12741}
b99bd4ef 12742
c19d1205
ZW
12743static void
12744do_t_mov_cmp (void)
12745{
fdfde340
JM
12746 unsigned Rn, Rm;
12747
12748 Rn = inst.operands[0].reg;
12749 Rm = inst.operands[1].reg;
12750
e07e6e58 12751 if (Rn == REG_PC)
5ee91343 12752 set_pred_insn_type_last ();
e07e6e58 12753
c19d1205 12754 if (unified_syntax)
b99bd4ef 12755 {
c19d1205
ZW
12756 int r0off = (inst.instruction == T_MNEM_mov
12757 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12758 unsigned long opcode;
3d388997
PB
12759 bfd_boolean narrow;
12760 bfd_boolean low_regs;
12761
fdfde340 12762 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12763 opcode = inst.instruction;
5ee91343 12764 if (in_pred_block ())
0110f2b8 12765 narrow = opcode != T_MNEM_movs;
3d388997 12766 else
0110f2b8 12767 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12768 if (inst.size_req == 4
12769 || inst.operands[1].shifted)
12770 narrow = FALSE;
12771
efd81785
PB
12772 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12773 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12774 && !inst.operands[1].shifted
fdfde340
JM
12775 && Rn == REG_PC
12776 && Rm == REG_LR)
efd81785
PB
12777 {
12778 inst.instruction = T2_SUBS_PC_LR;
12779 return;
12780 }
12781
fdfde340
JM
12782 if (opcode == T_MNEM_cmp)
12783 {
12784 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
12785 if (narrow)
12786 {
12787 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12788 but valid. */
12789 warn_deprecated_sp (Rm);
12790 /* R15 was documented as a valid choice for Rm in ARMv6,
12791 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12792 tools reject R15, so we do too. */
12793 constraint (Rm == REG_PC, BAD_PC);
12794 }
12795 else
12796 reject_bad_reg (Rm);
fdfde340
JM
12797 }
12798 else if (opcode == T_MNEM_mov
12799 || opcode == T_MNEM_movs)
12800 {
12801 if (inst.operands[1].isreg)
12802 {
12803 if (opcode == T_MNEM_movs)
12804 {
12805 reject_bad_reg (Rn);
12806 reject_bad_reg (Rm);
12807 }
76fa04a4
MGD
12808 else if (narrow)
12809 {
12810 /* This is mov.n. */
12811 if ((Rn == REG_SP || Rn == REG_PC)
12812 && (Rm == REG_SP || Rm == REG_PC))
12813 {
5c3696f8 12814 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12815 "deprecated when r%u is the destination "
12816 "register."), Rm, Rn);
12817 }
12818 }
12819 else
12820 {
12821 /* This is mov.w. */
12822 constraint (Rn == REG_PC, BAD_PC);
12823 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12824 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12825 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12826 }
fdfde340
JM
12827 }
12828 else
12829 reject_bad_reg (Rn);
12830 }
12831
c19d1205
ZW
12832 if (!inst.operands[1].isreg)
12833 {
0110f2b8 12834 /* Immediate operand. */
5ee91343 12835 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12836 narrow = 0;
12837 if (low_regs && narrow)
12838 {
12839 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12840 inst.instruction |= Rn << 8;
e2b0ab59
AV
12841 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12842 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12843 {
a9f02af8 12844 if (inst.size_req == 2)
e2b0ab59 12845 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12846 else
12847 inst.relax = opcode;
72d98d16 12848 }
0110f2b8
PB
12849 }
12850 else
12851 {
e2b0ab59
AV
12852 constraint ((inst.relocs[0].type
12853 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12854 && (inst.relocs[0].type
12855 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
12856 THUMB1_RELOC_ONLY);
12857
0110f2b8
PB
12858 inst.instruction = THUMB_OP32 (inst.instruction);
12859 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12860 inst.instruction |= Rn << r0off;
e2b0ab59 12861 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 12862 }
c19d1205 12863 }
728ca7c9
PB
12864 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12865 && (inst.instruction == T_MNEM_mov
12866 || inst.instruction == T_MNEM_movs))
12867 {
12868 /* Register shifts are encoded as separate shift instructions. */
12869 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12870
5ee91343 12871 if (in_pred_block ())
728ca7c9
PB
12872 narrow = !flags;
12873 else
12874 narrow = flags;
12875
12876 if (inst.size_req == 4)
12877 narrow = FALSE;
12878
12879 if (!low_regs || inst.operands[1].imm > 7)
12880 narrow = FALSE;
12881
fdfde340 12882 if (Rn != Rm)
728ca7c9
PB
12883 narrow = FALSE;
12884
12885 switch (inst.operands[1].shift_kind)
12886 {
12887 case SHIFT_LSL:
12888 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12889 break;
12890 case SHIFT_ASR:
12891 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12892 break;
12893 case SHIFT_LSR:
12894 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12895 break;
12896 case SHIFT_ROR:
12897 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12898 break;
12899 default:
5f4273c7 12900 abort ();
728ca7c9
PB
12901 }
12902
12903 inst.instruction = opcode;
12904 if (narrow)
12905 {
fdfde340 12906 inst.instruction |= Rn;
728ca7c9
PB
12907 inst.instruction |= inst.operands[1].imm << 3;
12908 }
12909 else
12910 {
12911 if (flags)
12912 inst.instruction |= CONDS_BIT;
12913
fdfde340
JM
12914 inst.instruction |= Rn << 8;
12915 inst.instruction |= Rm << 16;
728ca7c9
PB
12916 inst.instruction |= inst.operands[1].imm;
12917 }
12918 }
3d388997 12919 else if (!narrow)
c19d1205 12920 {
728ca7c9
PB
12921 /* Some mov with immediate shift have narrow variants.
12922 Register shifts are handled above. */
12923 if (low_regs && inst.operands[1].shifted
12924 && (inst.instruction == T_MNEM_mov
12925 || inst.instruction == T_MNEM_movs))
12926 {
5ee91343 12927 if (in_pred_block ())
728ca7c9
PB
12928 narrow = (inst.instruction == T_MNEM_mov);
12929 else
12930 narrow = (inst.instruction == T_MNEM_movs);
12931 }
12932
12933 if (narrow)
12934 {
12935 switch (inst.operands[1].shift_kind)
12936 {
12937 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12938 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12939 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12940 default: narrow = FALSE; break;
12941 }
12942 }
12943
12944 if (narrow)
12945 {
fdfde340
JM
12946 inst.instruction |= Rn;
12947 inst.instruction |= Rm << 3;
e2b0ab59 12948 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
12949 }
12950 else
12951 {
12952 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12953 inst.instruction |= Rn << r0off;
728ca7c9
PB
12954 encode_thumb32_shifted_operand (1);
12955 }
c19d1205
ZW
12956 }
12957 else
12958 switch (inst.instruction)
12959 {
12960 case T_MNEM_mov:
837b3435 12961 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12962 results. Don't allow this. */
12963 if (low_regs)
12964 {
12965 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12966 "MOV Rd, Rs with two low registers is not "
12967 "permitted on this architecture");
fa94de6b 12968 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12969 arm_ext_v6);
12970 }
12971
c19d1205 12972 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12973 inst.instruction |= (Rn & 0x8) << 4;
12974 inst.instruction |= (Rn & 0x7);
12975 inst.instruction |= Rm << 3;
c19d1205 12976 break;
b99bd4ef 12977
c19d1205
ZW
12978 case T_MNEM_movs:
12979 /* We know we have low registers at this point.
941a8a52
MGD
12980 Generate LSLS Rd, Rs, #0. */
12981 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12982 inst.instruction |= Rn;
12983 inst.instruction |= Rm << 3;
c19d1205
ZW
12984 break;
12985
12986 case T_MNEM_cmp:
3d388997 12987 if (low_regs)
c19d1205
ZW
12988 {
12989 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12990 inst.instruction |= Rn;
12991 inst.instruction |= Rm << 3;
c19d1205
ZW
12992 }
12993 else
12994 {
12995 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12996 inst.instruction |= (Rn & 0x8) << 4;
12997 inst.instruction |= (Rn & 0x7);
12998 inst.instruction |= Rm << 3;
c19d1205
ZW
12999 }
13000 break;
13001 }
b99bd4ef
NC
13002 return;
13003 }
13004
c19d1205 13005 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13006
13007 /* PR 10443: Do not silently ignore shifted operands. */
13008 constraint (inst.operands[1].shifted,
13009 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13010
c19d1205 13011 if (inst.operands[1].isreg)
b99bd4ef 13012 {
fdfde340 13013 if (Rn < 8 && Rm < 8)
b99bd4ef 13014 {
c19d1205
ZW
13015 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13016 since a MOV instruction produces unpredictable results. */
13017 if (inst.instruction == T_OPCODE_MOV_I8)
13018 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13019 else
c19d1205 13020 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13021
fdfde340
JM
13022 inst.instruction |= Rn;
13023 inst.instruction |= Rm << 3;
b99bd4ef
NC
13024 }
13025 else
13026 {
c19d1205
ZW
13027 if (inst.instruction == T_OPCODE_MOV_I8)
13028 inst.instruction = T_OPCODE_MOV_HR;
13029 else
13030 inst.instruction = T_OPCODE_CMP_HR;
13031 do_t_cpy ();
b99bd4ef
NC
13032 }
13033 }
c19d1205 13034 else
b99bd4ef 13035 {
fdfde340 13036 constraint (Rn > 7,
c19d1205 13037 _("only lo regs allowed with immediate"));
fdfde340 13038 inst.instruction |= Rn << 8;
e2b0ab59 13039 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13040 }
13041}
b99bd4ef 13042
c19d1205
ZW
13043static void
13044do_t_mov16 (void)
13045{
fdfde340 13046 unsigned Rd;
b6895b4f
PB
13047 bfd_vma imm;
13048 bfd_boolean top;
13049
13050 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13051 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13052 {
33eaf5de 13053 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13054 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13055 }
e2b0ab59 13056 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13057 {
33eaf5de 13058 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13059 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13060 }
13061
fdfde340
JM
13062 Rd = inst.operands[0].reg;
13063 reject_bad_reg (Rd);
13064
13065 inst.instruction |= Rd << 8;
e2b0ab59 13066 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13067 {
e2b0ab59 13068 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13069 inst.instruction |= (imm & 0xf000) << 4;
13070 inst.instruction |= (imm & 0x0800) << 15;
13071 inst.instruction |= (imm & 0x0700) << 4;
13072 inst.instruction |= (imm & 0x00ff);
13073 }
c19d1205 13074}
b99bd4ef 13075
c19d1205
ZW
13076static void
13077do_t_mvn_tst (void)
13078{
fdfde340 13079 unsigned Rn, Rm;
c921be7d 13080
fdfde340
JM
13081 Rn = inst.operands[0].reg;
13082 Rm = inst.operands[1].reg;
13083
13084 if (inst.instruction == T_MNEM_cmp
13085 || inst.instruction == T_MNEM_cmn)
13086 constraint (Rn == REG_PC, BAD_PC);
13087 else
13088 reject_bad_reg (Rn);
13089 reject_bad_reg (Rm);
13090
c19d1205
ZW
13091 if (unified_syntax)
13092 {
13093 int r0off = (inst.instruction == T_MNEM_mvn
13094 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13095 bfd_boolean narrow;
13096
13097 if (inst.size_req == 4
13098 || inst.instruction > 0xffff
13099 || inst.operands[1].shifted
fdfde340 13100 || Rn > 7 || Rm > 7)
3d388997 13101 narrow = FALSE;
fe8b4cc3
KT
13102 else if (inst.instruction == T_MNEM_cmn
13103 || inst.instruction == T_MNEM_tst)
3d388997
PB
13104 narrow = TRUE;
13105 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13106 narrow = !in_pred_block ();
3d388997 13107 else
5ee91343 13108 narrow = in_pred_block ();
3d388997 13109
c19d1205 13110 if (!inst.operands[1].isreg)
b99bd4ef 13111 {
c19d1205
ZW
13112 /* For an immediate, we always generate a 32-bit opcode;
13113 section relaxation will shrink it later if possible. */
13114 if (inst.instruction < 0xffff)
13115 inst.instruction = THUMB_OP32 (inst.instruction);
13116 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13117 inst.instruction |= Rn << r0off;
e2b0ab59 13118 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13119 }
c19d1205 13120 else
b99bd4ef 13121 {
c19d1205 13122 /* See if we can do this with a 16-bit instruction. */
3d388997 13123 if (narrow)
b99bd4ef 13124 {
c19d1205 13125 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13126 inst.instruction |= Rn;
13127 inst.instruction |= Rm << 3;
b99bd4ef 13128 }
c19d1205 13129 else
b99bd4ef 13130 {
c19d1205
ZW
13131 constraint (inst.operands[1].shifted
13132 && inst.operands[1].immisreg,
13133 _("shift must be constant"));
13134 if (inst.instruction < 0xffff)
13135 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13136 inst.instruction |= Rn << r0off;
c19d1205 13137 encode_thumb32_shifted_operand (1);
b99bd4ef 13138 }
b99bd4ef
NC
13139 }
13140 }
13141 else
13142 {
c19d1205
ZW
13143 constraint (inst.instruction > 0xffff
13144 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13145 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13146 _("unshifted register required"));
fdfde340 13147 constraint (Rn > 7 || Rm > 7,
c19d1205 13148 BAD_HIREG);
b99bd4ef 13149
c19d1205 13150 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13151 inst.instruction |= Rn;
13152 inst.instruction |= Rm << 3;
b99bd4ef 13153 }
b99bd4ef
NC
13154}
13155
b05fe5cf 13156static void
c19d1205 13157do_t_mrs (void)
b05fe5cf 13158{
fdfde340 13159 unsigned Rd;
037e8744
JB
13160
13161 if (do_vfp_nsyn_mrs () == SUCCESS)
13162 return;
13163
90ec0d68
MGD
13164 Rd = inst.operands[0].reg;
13165 reject_bad_reg (Rd);
13166 inst.instruction |= Rd << 8;
13167
13168 if (inst.operands[1].isreg)
62b3e311 13169 {
90ec0d68
MGD
13170 unsigned br = inst.operands[1].reg;
13171 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13172 as_bad (_("bad register for mrs"));
13173
13174 inst.instruction |= br & (0xf << 16);
13175 inst.instruction |= (br & 0x300) >> 4;
13176 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13177 }
13178 else
13179 {
90ec0d68 13180 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13181
d2cd1205 13182 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13183 {
13184 /* PR gas/12698: The constraint is only applied for m_profile.
13185 If the user has specified -march=all, we want to ignore it as
13186 we are building for any CPU type, including non-m variants. */
823d2571
TG
13187 bfd_boolean m_profile =
13188 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13189 constraint ((flags != 0) && m_profile, _("selected processor does "
13190 "not support requested special purpose register"));
13191 }
90ec0d68 13192 else
d2cd1205
JB
13193 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13194 devices). */
13195 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13196 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13197
90ec0d68
MGD
13198 inst.instruction |= (flags & SPSR_BIT) >> 2;
13199 inst.instruction |= inst.operands[1].imm & 0xff;
13200 inst.instruction |= 0xf0000;
13201 }
c19d1205 13202}
b05fe5cf 13203
c19d1205
ZW
13204static void
13205do_t_msr (void)
13206{
62b3e311 13207 int flags;
fdfde340 13208 unsigned Rn;
62b3e311 13209
037e8744
JB
13210 if (do_vfp_nsyn_msr () == SUCCESS)
13211 return;
13212
c19d1205
ZW
13213 constraint (!inst.operands[1].isreg,
13214 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13215
13216 if (inst.operands[0].isreg)
13217 flags = (int)(inst.operands[0].reg);
13218 else
13219 flags = inst.operands[0].imm;
13220
d2cd1205 13221 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13222 {
d2cd1205
JB
13223 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13224
1a43faaf 13225 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13226 If the user has specified -march=all, we want to ignore it as
13227 we are building for any CPU type, including non-m variants. */
823d2571
TG
13228 bfd_boolean m_profile =
13229 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13230 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13231 && (bits & ~(PSR_s | PSR_f)) != 0)
13232 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13233 && bits != PSR_f)) && m_profile,
13234 _("selected processor does not support requested special "
13235 "purpose register"));
62b3e311
PB
13236 }
13237 else
d2cd1205
JB
13238 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13239 "requested special purpose register"));
c921be7d 13240
fdfde340
JM
13241 Rn = inst.operands[1].reg;
13242 reject_bad_reg (Rn);
13243
62b3e311 13244 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13245 inst.instruction |= (flags & 0xf0000) >> 8;
13246 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13247 inst.instruction |= (flags & 0xff);
fdfde340 13248 inst.instruction |= Rn << 16;
c19d1205 13249}
b05fe5cf 13250
c19d1205
ZW
13251static void
13252do_t_mul (void)
13253{
17828f45 13254 bfd_boolean narrow;
fdfde340 13255 unsigned Rd, Rn, Rm;
17828f45 13256
c19d1205
ZW
13257 if (!inst.operands[2].present)
13258 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13259
fdfde340
JM
13260 Rd = inst.operands[0].reg;
13261 Rn = inst.operands[1].reg;
13262 Rm = inst.operands[2].reg;
13263
17828f45 13264 if (unified_syntax)
b05fe5cf 13265 {
17828f45 13266 if (inst.size_req == 4
fdfde340
JM
13267 || (Rd != Rn
13268 && Rd != Rm)
13269 || Rn > 7
13270 || Rm > 7)
17828f45
JM
13271 narrow = FALSE;
13272 else if (inst.instruction == T_MNEM_muls)
5ee91343 13273 narrow = !in_pred_block ();
17828f45 13274 else
5ee91343 13275 narrow = in_pred_block ();
b05fe5cf 13276 }
c19d1205 13277 else
b05fe5cf 13278 {
17828f45 13279 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13280 constraint (Rn > 7 || Rm > 7,
c19d1205 13281 BAD_HIREG);
17828f45
JM
13282 narrow = TRUE;
13283 }
b05fe5cf 13284
17828f45
JM
13285 if (narrow)
13286 {
13287 /* 16-bit MULS/Conditional MUL. */
c19d1205 13288 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13289 inst.instruction |= Rd;
b05fe5cf 13290
fdfde340
JM
13291 if (Rd == Rn)
13292 inst.instruction |= Rm << 3;
13293 else if (Rd == Rm)
13294 inst.instruction |= Rn << 3;
c19d1205
ZW
13295 else
13296 constraint (1, _("dest must overlap one source register"));
13297 }
17828f45
JM
13298 else
13299 {
e07e6e58
NC
13300 constraint (inst.instruction != T_MNEM_mul,
13301 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13302 /* 32-bit MUL. */
13303 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13304 inst.instruction |= Rd << 8;
13305 inst.instruction |= Rn << 16;
13306 inst.instruction |= Rm << 0;
13307
13308 reject_bad_reg (Rd);
13309 reject_bad_reg (Rn);
13310 reject_bad_reg (Rm);
17828f45 13311 }
c19d1205 13312}
b05fe5cf 13313
c19d1205
ZW
13314static void
13315do_t_mull (void)
13316{
fdfde340 13317 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13318
fdfde340
JM
13319 RdLo = inst.operands[0].reg;
13320 RdHi = inst.operands[1].reg;
13321 Rn = inst.operands[2].reg;
13322 Rm = inst.operands[3].reg;
13323
13324 reject_bad_reg (RdLo);
13325 reject_bad_reg (RdHi);
13326 reject_bad_reg (Rn);
13327 reject_bad_reg (Rm);
13328
13329 inst.instruction |= RdLo << 12;
13330 inst.instruction |= RdHi << 8;
13331 inst.instruction |= Rn << 16;
13332 inst.instruction |= Rm;
13333
13334 if (RdLo == RdHi)
c19d1205
ZW
13335 as_tsktsk (_("rdhi and rdlo must be different"));
13336}
b05fe5cf 13337
c19d1205
ZW
13338static void
13339do_t_nop (void)
13340{
5ee91343 13341 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13342
c19d1205
ZW
13343 if (unified_syntax)
13344 {
13345 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13346 {
c19d1205
ZW
13347 inst.instruction = THUMB_OP32 (inst.instruction);
13348 inst.instruction |= inst.operands[0].imm;
13349 }
13350 else
13351 {
bc2d1808
NC
13352 /* PR9722: Check for Thumb2 availability before
13353 generating a thumb2 nop instruction. */
afa62d5e 13354 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13355 {
13356 inst.instruction = THUMB_OP16 (inst.instruction);
13357 inst.instruction |= inst.operands[0].imm << 4;
13358 }
13359 else
13360 inst.instruction = 0x46c0;
c19d1205
ZW
13361 }
13362 }
13363 else
13364 {
13365 constraint (inst.operands[0].present,
13366 _("Thumb does not support NOP with hints"));
13367 inst.instruction = 0x46c0;
13368 }
13369}
b05fe5cf 13370
c19d1205
ZW
13371static void
13372do_t_neg (void)
13373{
13374 if (unified_syntax)
13375 {
3d388997
PB
13376 bfd_boolean narrow;
13377
13378 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13379 narrow = !in_pred_block ();
3d388997 13380 else
5ee91343 13381 narrow = in_pred_block ();
3d388997
PB
13382 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13383 narrow = FALSE;
13384 if (inst.size_req == 4)
13385 narrow = FALSE;
13386
13387 if (!narrow)
c19d1205
ZW
13388 {
13389 inst.instruction = THUMB_OP32 (inst.instruction);
13390 inst.instruction |= inst.operands[0].reg << 8;
13391 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13392 }
13393 else
13394 {
c19d1205
ZW
13395 inst.instruction = THUMB_OP16 (inst.instruction);
13396 inst.instruction |= inst.operands[0].reg;
13397 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13398 }
13399 }
13400 else
13401 {
c19d1205
ZW
13402 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13403 BAD_HIREG);
13404 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13405
13406 inst.instruction = THUMB_OP16 (inst.instruction);
13407 inst.instruction |= inst.operands[0].reg;
13408 inst.instruction |= inst.operands[1].reg << 3;
13409 }
13410}
13411
1c444d06
JM
13412static void
13413do_t_orn (void)
13414{
13415 unsigned Rd, Rn;
13416
13417 Rd = inst.operands[0].reg;
13418 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13419
fdfde340
JM
13420 reject_bad_reg (Rd);
13421 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13422 reject_bad_reg (Rn);
13423
1c444d06
JM
13424 inst.instruction |= Rd << 8;
13425 inst.instruction |= Rn << 16;
13426
13427 if (!inst.operands[2].isreg)
13428 {
13429 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13430 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13431 }
13432 else
13433 {
13434 unsigned Rm;
13435
13436 Rm = inst.operands[2].reg;
fdfde340 13437 reject_bad_reg (Rm);
1c444d06
JM
13438
13439 constraint (inst.operands[2].shifted
13440 && inst.operands[2].immisreg,
13441 _("shift must be constant"));
13442 encode_thumb32_shifted_operand (2);
13443 }
13444}
13445
c19d1205
ZW
13446static void
13447do_t_pkhbt (void)
13448{
fdfde340
JM
13449 unsigned Rd, Rn, Rm;
13450
13451 Rd = inst.operands[0].reg;
13452 Rn = inst.operands[1].reg;
13453 Rm = inst.operands[2].reg;
13454
13455 reject_bad_reg (Rd);
13456 reject_bad_reg (Rn);
13457 reject_bad_reg (Rm);
13458
13459 inst.instruction |= Rd << 8;
13460 inst.instruction |= Rn << 16;
13461 inst.instruction |= Rm;
c19d1205
ZW
13462 if (inst.operands[3].present)
13463 {
e2b0ab59
AV
13464 unsigned int val = inst.relocs[0].exp.X_add_number;
13465 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13466 _("expression too complex"));
13467 inst.instruction |= (val & 0x1c) << 10;
13468 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13469 }
c19d1205 13470}
b05fe5cf 13471
c19d1205
ZW
13472static void
13473do_t_pkhtb (void)
13474{
13475 if (!inst.operands[3].present)
1ef52f49
NC
13476 {
13477 unsigned Rtmp;
13478
13479 inst.instruction &= ~0x00000020;
13480
13481 /* PR 10168. Swap the Rm and Rn registers. */
13482 Rtmp = inst.operands[1].reg;
13483 inst.operands[1].reg = inst.operands[2].reg;
13484 inst.operands[2].reg = Rtmp;
13485 }
c19d1205 13486 do_t_pkhbt ();
b05fe5cf
ZW
13487}
13488
c19d1205
ZW
13489static void
13490do_t_pld (void)
13491{
fdfde340
JM
13492 if (inst.operands[0].immisreg)
13493 reject_bad_reg (inst.operands[0].imm);
13494
c19d1205
ZW
13495 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13496}
b05fe5cf 13497
c19d1205
ZW
13498static void
13499do_t_push_pop (void)
b99bd4ef 13500{
e9f89963 13501 unsigned mask;
5f4273c7 13502
c19d1205
ZW
13503 constraint (inst.operands[0].writeback,
13504 _("push/pop do not support {reglist}^"));
e2b0ab59 13505 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13506 _("expression too complex"));
b99bd4ef 13507
e9f89963 13508 mask = inst.operands[0].imm;
d3bfe16e 13509 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13510 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13511 else if (inst.size_req != 4
c6025a80 13512 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13513 ? REG_LR : REG_PC)))
b99bd4ef 13514 {
c19d1205
ZW
13515 inst.instruction = THUMB_OP16 (inst.instruction);
13516 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13517 inst.instruction |= mask & 0xff;
c19d1205
ZW
13518 }
13519 else if (unified_syntax)
13520 {
3c707909 13521 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13522 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13523 }
13524 else
13525 {
13526 inst.error = _("invalid register list to push/pop instruction");
13527 return;
c19d1205 13528 }
4b5a202f
AV
13529}
13530
13531static void
13532do_t_clrm (void)
13533{
13534 if (unified_syntax)
13535 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13536 else
13537 {
13538 inst.error = _("invalid register list to push/pop instruction");
13539 return;
13540 }
c19d1205 13541}
b99bd4ef 13542
efd6b359
AV
13543static void
13544do_t_vscclrm (void)
13545{
13546 if (inst.operands[0].issingle)
13547 {
13548 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13549 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13550 inst.instruction |= inst.operands[0].imm;
13551 }
13552 else
13553 {
13554 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13555 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13556 inst.instruction |= 1 << 8;
13557 inst.instruction |= inst.operands[0].imm << 1;
13558 }
13559}
13560
c19d1205
ZW
13561static void
13562do_t_rbit (void)
13563{
fdfde340
JM
13564 unsigned Rd, Rm;
13565
13566 Rd = inst.operands[0].reg;
13567 Rm = inst.operands[1].reg;
13568
13569 reject_bad_reg (Rd);
13570 reject_bad_reg (Rm);
13571
13572 inst.instruction |= Rd << 8;
13573 inst.instruction |= Rm << 16;
13574 inst.instruction |= Rm;
c19d1205 13575}
b99bd4ef 13576
c19d1205
ZW
13577static void
13578do_t_rev (void)
13579{
fdfde340
JM
13580 unsigned Rd, Rm;
13581
13582 Rd = inst.operands[0].reg;
13583 Rm = inst.operands[1].reg;
13584
13585 reject_bad_reg (Rd);
13586 reject_bad_reg (Rm);
13587
13588 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13589 && inst.size_req != 4)
13590 {
13591 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13592 inst.instruction |= Rd;
13593 inst.instruction |= Rm << 3;
c19d1205
ZW
13594 }
13595 else if (unified_syntax)
13596 {
13597 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13598 inst.instruction |= Rd << 8;
13599 inst.instruction |= Rm << 16;
13600 inst.instruction |= Rm;
c19d1205
ZW
13601 }
13602 else
13603 inst.error = BAD_HIREG;
13604}
b99bd4ef 13605
1c444d06
JM
13606static void
13607do_t_rrx (void)
13608{
13609 unsigned Rd, Rm;
13610
13611 Rd = inst.operands[0].reg;
13612 Rm = inst.operands[1].reg;
13613
fdfde340
JM
13614 reject_bad_reg (Rd);
13615 reject_bad_reg (Rm);
c921be7d 13616
1c444d06
JM
13617 inst.instruction |= Rd << 8;
13618 inst.instruction |= Rm;
13619}
13620
c19d1205
ZW
13621static void
13622do_t_rsb (void)
13623{
fdfde340 13624 unsigned Rd, Rs;
b99bd4ef 13625
c19d1205
ZW
13626 Rd = inst.operands[0].reg;
13627 Rs = (inst.operands[1].present
13628 ? inst.operands[1].reg /* Rd, Rs, foo */
13629 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13630
fdfde340
JM
13631 reject_bad_reg (Rd);
13632 reject_bad_reg (Rs);
13633 if (inst.operands[2].isreg)
13634 reject_bad_reg (inst.operands[2].reg);
13635
c19d1205
ZW
13636 inst.instruction |= Rd << 8;
13637 inst.instruction |= Rs << 16;
13638 if (!inst.operands[2].isreg)
13639 {
026d3abb
PB
13640 bfd_boolean narrow;
13641
13642 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13643 narrow = !in_pred_block ();
026d3abb 13644 else
5ee91343 13645 narrow = in_pred_block ();
026d3abb
PB
13646
13647 if (Rd > 7 || Rs > 7)
13648 narrow = FALSE;
13649
13650 if (inst.size_req == 4 || !unified_syntax)
13651 narrow = FALSE;
13652
e2b0ab59
AV
13653 if (inst.relocs[0].exp.X_op != O_constant
13654 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13655 narrow = FALSE;
13656
13657 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13658 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13659 if (narrow)
13660 {
e2b0ab59 13661 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13662 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13663 inst.instruction |= Rs << 3;
13664 inst.instruction |= Rd;
13665 }
13666 else
13667 {
13668 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13669 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13670 }
c19d1205
ZW
13671 }
13672 else
13673 encode_thumb32_shifted_operand (2);
13674}
b99bd4ef 13675
c19d1205
ZW
13676static void
13677do_t_setend (void)
13678{
12e37cbc
MGD
13679 if (warn_on_deprecated
13680 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13681 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13682
5ee91343 13683 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13684 if (inst.operands[0].imm)
13685 inst.instruction |= 0x8;
13686}
b99bd4ef 13687
c19d1205
ZW
13688static void
13689do_t_shift (void)
13690{
13691 if (!inst.operands[1].present)
13692 inst.operands[1].reg = inst.operands[0].reg;
13693
13694 if (unified_syntax)
13695 {
3d388997
PB
13696 bfd_boolean narrow;
13697 int shift_kind;
13698
13699 switch (inst.instruction)
13700 {
13701 case T_MNEM_asr:
13702 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13703 case T_MNEM_lsl:
13704 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13705 case T_MNEM_lsr:
13706 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13707 case T_MNEM_ror:
13708 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13709 default: abort ();
13710 }
13711
13712 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13713 narrow = !in_pred_block ();
3d388997 13714 else
5ee91343 13715 narrow = in_pred_block ();
3d388997
PB
13716 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13717 narrow = FALSE;
13718 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13719 narrow = FALSE;
13720 if (inst.operands[2].isreg
13721 && (inst.operands[1].reg != inst.operands[0].reg
13722 || inst.operands[2].reg > 7))
13723 narrow = FALSE;
13724 if (inst.size_req == 4)
13725 narrow = FALSE;
13726
fdfde340
JM
13727 reject_bad_reg (inst.operands[0].reg);
13728 reject_bad_reg (inst.operands[1].reg);
c921be7d 13729
3d388997 13730 if (!narrow)
c19d1205
ZW
13731 {
13732 if (inst.operands[2].isreg)
b99bd4ef 13733 {
fdfde340 13734 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13735 inst.instruction = THUMB_OP32 (inst.instruction);
13736 inst.instruction |= inst.operands[0].reg << 8;
13737 inst.instruction |= inst.operands[1].reg << 16;
13738 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13739
13740 /* PR 12854: Error on extraneous shifts. */
13741 constraint (inst.operands[2].shifted,
13742 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13743 }
13744 else
13745 {
13746 inst.operands[1].shifted = 1;
3d388997 13747 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13748 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13749 ? T_MNEM_movs : T_MNEM_mov);
13750 inst.instruction |= inst.operands[0].reg << 8;
13751 encode_thumb32_shifted_operand (1);
13752 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13753 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13754 }
13755 }
13756 else
13757 {
c19d1205 13758 if (inst.operands[2].isreg)
b99bd4ef 13759 {
3d388997 13760 switch (shift_kind)
b99bd4ef 13761 {
3d388997
PB
13762 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13763 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13764 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13765 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13766 default: abort ();
b99bd4ef 13767 }
5f4273c7 13768
c19d1205
ZW
13769 inst.instruction |= inst.operands[0].reg;
13770 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13771
13772 /* PR 12854: Error on extraneous shifts. */
13773 constraint (inst.operands[2].shifted,
13774 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13775 }
13776 else
13777 {
3d388997 13778 switch (shift_kind)
b99bd4ef 13779 {
3d388997
PB
13780 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13781 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13782 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 13783 default: abort ();
b99bd4ef 13784 }
e2b0ab59 13785 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13786 inst.instruction |= inst.operands[0].reg;
13787 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13788 }
13789 }
c19d1205
ZW
13790 }
13791 else
13792 {
13793 constraint (inst.operands[0].reg > 7
13794 || inst.operands[1].reg > 7, BAD_HIREG);
13795 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 13796
c19d1205
ZW
13797 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13798 {
13799 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13800 constraint (inst.operands[0].reg != inst.operands[1].reg,
13801 _("source1 and dest must be same register"));
b99bd4ef 13802
c19d1205
ZW
13803 switch (inst.instruction)
13804 {
13805 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13806 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13807 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13808 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13809 default: abort ();
13810 }
5f4273c7 13811
c19d1205
ZW
13812 inst.instruction |= inst.operands[0].reg;
13813 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13814
13815 /* PR 12854: Error on extraneous shifts. */
13816 constraint (inst.operands[2].shifted,
13817 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13818 }
13819 else
b99bd4ef 13820 {
c19d1205
ZW
13821 switch (inst.instruction)
13822 {
13823 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13824 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13825 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13826 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13827 default: abort ();
13828 }
e2b0ab59 13829 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
13830 inst.instruction |= inst.operands[0].reg;
13831 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
13832 }
13833 }
b99bd4ef
NC
13834}
13835
13836static void
c19d1205 13837do_t_simd (void)
b99bd4ef 13838{
fdfde340
JM
13839 unsigned Rd, Rn, Rm;
13840
13841 Rd = inst.operands[0].reg;
13842 Rn = inst.operands[1].reg;
13843 Rm = inst.operands[2].reg;
13844
13845 reject_bad_reg (Rd);
13846 reject_bad_reg (Rn);
13847 reject_bad_reg (Rm);
13848
13849 inst.instruction |= Rd << 8;
13850 inst.instruction |= Rn << 16;
13851 inst.instruction |= Rm;
c19d1205 13852}
b99bd4ef 13853
03ee1b7f
NC
13854static void
13855do_t_simd2 (void)
13856{
13857 unsigned Rd, Rn, Rm;
13858
13859 Rd = inst.operands[0].reg;
13860 Rm = inst.operands[1].reg;
13861 Rn = inst.operands[2].reg;
13862
13863 reject_bad_reg (Rd);
13864 reject_bad_reg (Rn);
13865 reject_bad_reg (Rm);
13866
13867 inst.instruction |= Rd << 8;
13868 inst.instruction |= Rn << 16;
13869 inst.instruction |= Rm;
13870}
13871
c19d1205 13872static void
3eb17e6b 13873do_t_smc (void)
c19d1205 13874{
e2b0ab59 13875 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
13876 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13877 _("SMC is not permitted on this architecture"));
e2b0ab59 13878 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13879 _("expression too complex"));
e2b0ab59 13880 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
13881 inst.instruction |= (value & 0xf000) >> 12;
13882 inst.instruction |= (value & 0x0ff0);
13883 inst.instruction |= (value & 0x000f) << 16;
24382199 13884 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 13885 set_pred_insn_type_last ();
c19d1205 13886}
b99bd4ef 13887
90ec0d68
MGD
13888static void
13889do_t_hvc (void)
13890{
e2b0ab59 13891 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 13892
e2b0ab59 13893 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
13894 inst.instruction |= (value & 0x0fff);
13895 inst.instruction |= (value & 0xf000) << 4;
13896}
13897
c19d1205 13898static void
3a21c15a 13899do_t_ssat_usat (int bias)
c19d1205 13900{
fdfde340
JM
13901 unsigned Rd, Rn;
13902
13903 Rd = inst.operands[0].reg;
13904 Rn = inst.operands[2].reg;
13905
13906 reject_bad_reg (Rd);
13907 reject_bad_reg (Rn);
13908
13909 inst.instruction |= Rd << 8;
3a21c15a 13910 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13911 inst.instruction |= Rn << 16;
b99bd4ef 13912
c19d1205 13913 if (inst.operands[3].present)
b99bd4ef 13914 {
e2b0ab59 13915 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 13916
e2b0ab59 13917 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 13918
e2b0ab59 13919 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 13920 _("expression too complex"));
b99bd4ef 13921
3a21c15a 13922 if (shift_amount != 0)
6189168b 13923 {
3a21c15a
NC
13924 constraint (shift_amount > 31,
13925 _("shift expression is too large"));
13926
c19d1205 13927 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13928 inst.instruction |= 0x00200000; /* sh bit. */
13929
13930 inst.instruction |= (shift_amount & 0x1c) << 10;
13931 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13932 }
13933 }
b99bd4ef 13934}
c921be7d 13935
3a21c15a
NC
13936static void
13937do_t_ssat (void)
13938{
13939 do_t_ssat_usat (1);
13940}
b99bd4ef 13941
0dd132b6 13942static void
c19d1205 13943do_t_ssat16 (void)
0dd132b6 13944{
fdfde340
JM
13945 unsigned Rd, Rn;
13946
13947 Rd = inst.operands[0].reg;
13948 Rn = inst.operands[2].reg;
13949
13950 reject_bad_reg (Rd);
13951 reject_bad_reg (Rn);
13952
13953 inst.instruction |= Rd << 8;
c19d1205 13954 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13955 inst.instruction |= Rn << 16;
c19d1205 13956}
0dd132b6 13957
c19d1205
ZW
13958static void
13959do_t_strex (void)
13960{
13961 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13962 || inst.operands[2].postind || inst.operands[2].writeback
13963 || inst.operands[2].immisreg || inst.operands[2].shifted
13964 || inst.operands[2].negative,
01cfc07f 13965 BAD_ADDR_MODE);
0dd132b6 13966
5be8be5d
DG
13967 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13968
c19d1205
ZW
13969 inst.instruction |= inst.operands[0].reg << 8;
13970 inst.instruction |= inst.operands[1].reg << 12;
13971 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 13972 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13973}
13974
b99bd4ef 13975static void
c19d1205 13976do_t_strexd (void)
b99bd4ef 13977{
c19d1205
ZW
13978 if (!inst.operands[2].present)
13979 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13980
c19d1205
ZW
13981 constraint (inst.operands[0].reg == inst.operands[1].reg
13982 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13983 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13984 BAD_OVERLAP);
b99bd4ef 13985
c19d1205
ZW
13986 inst.instruction |= inst.operands[0].reg;
13987 inst.instruction |= inst.operands[1].reg << 12;
13988 inst.instruction |= inst.operands[2].reg << 8;
13989 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13990}
13991
13992static void
c19d1205 13993do_t_sxtah (void)
b99bd4ef 13994{
fdfde340
JM
13995 unsigned Rd, Rn, Rm;
13996
13997 Rd = inst.operands[0].reg;
13998 Rn = inst.operands[1].reg;
13999 Rm = inst.operands[2].reg;
14000
14001 reject_bad_reg (Rd);
14002 reject_bad_reg (Rn);
14003 reject_bad_reg (Rm);
14004
14005 inst.instruction |= Rd << 8;
14006 inst.instruction |= Rn << 16;
14007 inst.instruction |= Rm;
c19d1205
ZW
14008 inst.instruction |= inst.operands[3].imm << 4;
14009}
b99bd4ef 14010
c19d1205
ZW
14011static void
14012do_t_sxth (void)
14013{
fdfde340
JM
14014 unsigned Rd, Rm;
14015
14016 Rd = inst.operands[0].reg;
14017 Rm = inst.operands[1].reg;
14018
14019 reject_bad_reg (Rd);
14020 reject_bad_reg (Rm);
c921be7d
NC
14021
14022 if (inst.instruction <= 0xffff
14023 && inst.size_req != 4
fdfde340 14024 && Rd <= 7 && Rm <= 7
c19d1205 14025 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14026 {
c19d1205 14027 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14028 inst.instruction |= Rd;
14029 inst.instruction |= Rm << 3;
b99bd4ef 14030 }
c19d1205 14031 else if (unified_syntax)
b99bd4ef 14032 {
c19d1205
ZW
14033 if (inst.instruction <= 0xffff)
14034 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14035 inst.instruction |= Rd << 8;
14036 inst.instruction |= Rm;
c19d1205 14037 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14038 }
c19d1205 14039 else
b99bd4ef 14040 {
c19d1205
ZW
14041 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14042 _("Thumb encoding does not support rotation"));
14043 constraint (1, BAD_HIREG);
b99bd4ef 14044 }
c19d1205 14045}
b99bd4ef 14046
c19d1205
ZW
14047static void
14048do_t_swi (void)
14049{
e2b0ab59 14050 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14051}
b99bd4ef 14052
92e90b6e
PB
14053static void
14054do_t_tb (void)
14055{
fdfde340 14056 unsigned Rn, Rm;
92e90b6e
PB
14057 int half;
14058
14059 half = (inst.instruction & 0x10) != 0;
5ee91343 14060 set_pred_insn_type_last ();
dfa9f0d5
PB
14061 constraint (inst.operands[0].immisreg,
14062 _("instruction requires register index"));
fdfde340
JM
14063
14064 Rn = inst.operands[0].reg;
14065 Rm = inst.operands[0].imm;
c921be7d 14066
5c8ed6a4
JW
14067 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14068 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14069 reject_bad_reg (Rm);
14070
92e90b6e
PB
14071 constraint (!half && inst.operands[0].shifted,
14072 _("instruction does not allow shifted index"));
fdfde340 14073 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14074}
14075
74db7efb
NC
14076static void
14077do_t_udf (void)
14078{
14079 if (!inst.operands[0].present)
14080 inst.operands[0].imm = 0;
14081
14082 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14083 {
14084 constraint (inst.size_req == 2,
14085 _("immediate value out of range"));
14086 inst.instruction = THUMB_OP32 (inst.instruction);
14087 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14088 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14089 }
14090 else
14091 {
14092 inst.instruction = THUMB_OP16 (inst.instruction);
14093 inst.instruction |= inst.operands[0].imm;
14094 }
14095
5ee91343 14096 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14097}
14098
14099
c19d1205
ZW
14100static void
14101do_t_usat (void)
14102{
3a21c15a 14103 do_t_ssat_usat (0);
b99bd4ef
NC
14104}
14105
14106static void
c19d1205 14107do_t_usat16 (void)
b99bd4ef 14108{
fdfde340
JM
14109 unsigned Rd, Rn;
14110
14111 Rd = inst.operands[0].reg;
14112 Rn = inst.operands[2].reg;
14113
14114 reject_bad_reg (Rd);
14115 reject_bad_reg (Rn);
14116
14117 inst.instruction |= Rd << 8;
c19d1205 14118 inst.instruction |= inst.operands[1].imm;
fdfde340 14119 inst.instruction |= Rn << 16;
b99bd4ef 14120}
c19d1205 14121
e12437dc
AV
14122/* Checking the range of the branch offset (VAL) with NBITS bits
14123 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14124static int
14125v8_1_branch_value_check (int val, int nbits, int is_signed)
14126{
14127 gas_assert (nbits > 0 && nbits <= 32);
14128 if (is_signed)
14129 {
14130 int cmp = (1 << (nbits - 1));
14131 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14132 return FAIL;
14133 }
14134 else
14135 {
14136 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14137 return FAIL;
14138 }
14139 return SUCCESS;
14140}
14141
4389b29a
AV
14142/* For branches in Armv8.1-M Mainline. */
14143static void
14144do_t_branch_future (void)
14145{
14146 unsigned long insn = inst.instruction;
14147
14148 inst.instruction = THUMB_OP32 (inst.instruction);
14149 if (inst.operands[0].hasreloc == 0)
14150 {
14151 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14152 as_bad (BAD_BRANCH_OFF);
14153
14154 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14155 }
14156 else
14157 {
14158 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14159 inst.relocs[0].pc_rel = 1;
14160 }
14161
14162 switch (insn)
14163 {
14164 case T_MNEM_bf:
14165 if (inst.operands[1].hasreloc == 0)
14166 {
14167 int val = inst.operands[1].imm;
14168 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14169 as_bad (BAD_BRANCH_OFF);
14170
14171 int immA = (val & 0x0001f000) >> 12;
14172 int immB = (val & 0x00000ffc) >> 2;
14173 int immC = (val & 0x00000002) >> 1;
14174 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14175 }
14176 else
14177 {
14178 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14179 inst.relocs[1].pc_rel = 1;
14180 }
14181 break;
14182
65d1bc05
AV
14183 case T_MNEM_bfl:
14184 if (inst.operands[1].hasreloc == 0)
14185 {
14186 int val = inst.operands[1].imm;
14187 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14188 as_bad (BAD_BRANCH_OFF);
14189
14190 int immA = (val & 0x0007f000) >> 12;
14191 int immB = (val & 0x00000ffc) >> 2;
14192 int immC = (val & 0x00000002) >> 1;
14193 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14194 }
14195 else
14196 {
14197 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14198 inst.relocs[1].pc_rel = 1;
14199 }
14200 break;
14201
f6b2b12d
AV
14202 case T_MNEM_bfcsel:
14203 /* Operand 1. */
14204 if (inst.operands[1].hasreloc == 0)
14205 {
14206 int val = inst.operands[1].imm;
14207 int immA = (val & 0x00001000) >> 12;
14208 int immB = (val & 0x00000ffc) >> 2;
14209 int immC = (val & 0x00000002) >> 1;
14210 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14211 }
14212 else
14213 {
14214 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14215 inst.relocs[1].pc_rel = 1;
14216 }
14217
14218 /* Operand 2. */
14219 if (inst.operands[2].hasreloc == 0)
14220 {
14221 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14222 int val2 = inst.operands[2].imm;
14223 int val0 = inst.operands[0].imm & 0x1f;
14224 int diff = val2 - val0;
14225 if (diff == 4)
14226 inst.instruction |= 1 << 17; /* T bit. */
14227 else if (diff != 2)
14228 as_bad (_("out of range label-relative fixup value"));
14229 }
14230 else
14231 {
14232 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14233 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14234 inst.relocs[2].pc_rel = 1;
14235 }
14236
14237 /* Operand 3. */
14238 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14239 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14240 break;
14241
f1c7f421
AV
14242 case T_MNEM_bfx:
14243 case T_MNEM_bflx:
14244 inst.instruction |= inst.operands[1].reg << 16;
14245 break;
14246
4389b29a
AV
14247 default: abort ();
14248 }
14249}
14250
60f993ce
AV
14251/* Helper function for do_t_loloop to handle relocations. */
14252static void
14253v8_1_loop_reloc (int is_le)
14254{
14255 if (inst.relocs[0].exp.X_op == O_constant)
14256 {
14257 int value = inst.relocs[0].exp.X_add_number;
14258 value = (is_le) ? -value : value;
14259
14260 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14261 as_bad (BAD_BRANCH_OFF);
14262
14263 int imml, immh;
14264
14265 immh = (value & 0x00000ffc) >> 2;
14266 imml = (value & 0x00000002) >> 1;
14267
14268 inst.instruction |= (imml << 11) | (immh << 1);
14269 }
14270 else
14271 {
14272 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14273 inst.relocs[0].pc_rel = 1;
14274 }
14275}
14276
23d00a41
SD
14277/* For shifts in MVE. */
14278static void
14279do_mve_scalar_shift (void)
14280{
14281 if (!inst.operands[2].present)
14282 {
14283 inst.operands[2] = inst.operands[1];
14284 inst.operands[1].reg = 0xf;
14285 }
14286
14287 inst.instruction |= inst.operands[0].reg << 16;
14288 inst.instruction |= inst.operands[1].reg << 8;
14289
14290 if (inst.operands[2].isreg)
14291 {
14292 /* Assuming Rm is already checked not to be 11x1. */
14293 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14294 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14295 inst.instruction |= inst.operands[2].reg << 12;
14296 }
14297 else
14298 {
14299 /* Assuming imm is already checked as [1,32]. */
14300 unsigned int value = inst.operands[2].imm;
14301 inst.instruction |= (value & 0x1c) << 10;
14302 inst.instruction |= (value & 0x03) << 6;
14303 /* Change last 4 bits from 0xd to 0xf. */
14304 inst.instruction |= 0x2;
14305 }
14306}
14307
a302e574
AV
14308/* MVE instruction encoder helpers. */
14309#define M_MNEM_vabav 0xee800f01
14310#define M_MNEM_vmladav 0xeef00e00
14311#define M_MNEM_vmladava 0xeef00e20
14312#define M_MNEM_vmladavx 0xeef01e00
14313#define M_MNEM_vmladavax 0xeef01e20
14314#define M_MNEM_vmlsdav 0xeef00e01
14315#define M_MNEM_vmlsdava 0xeef00e21
14316#define M_MNEM_vmlsdavx 0xeef01e01
14317#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14318#define M_MNEM_vmullt 0xee011e00
14319#define M_MNEM_vmullb 0xee010e00
35c228db
AV
14320#define M_MNEM_vst20 0xfc801e00
14321#define M_MNEM_vst21 0xfc801e20
14322#define M_MNEM_vst40 0xfc801e01
14323#define M_MNEM_vst41 0xfc801e21
14324#define M_MNEM_vst42 0xfc801e41
14325#define M_MNEM_vst43 0xfc801e61
14326#define M_MNEM_vld20 0xfc901e00
14327#define M_MNEM_vld21 0xfc901e20
14328#define M_MNEM_vld40 0xfc901e01
14329#define M_MNEM_vld41 0xfc901e21
14330#define M_MNEM_vld42 0xfc901e41
14331#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14332#define M_MNEM_vstrb 0xec000e00
14333#define M_MNEM_vstrh 0xec000e10
14334#define M_MNEM_vstrw 0xec000e40
14335#define M_MNEM_vstrd 0xec000e50
14336#define M_MNEM_vldrb 0xec100e00
14337#define M_MNEM_vldrh 0xec100e10
14338#define M_MNEM_vldrw 0xec100e40
14339#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14340#define M_MNEM_vmovlt 0xeea01f40
14341#define M_MNEM_vmovlb 0xeea00f40
14342#define M_MNEM_vmovnt 0xfe311e81
14343#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14344#define M_MNEM_vadc 0xee300f00
14345#define M_MNEM_vadci 0xee301f00
14346#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14347#define M_MNEM_vaddlv 0xee890f00
14348#define M_MNEM_vaddlva 0xee890f20
14349#define M_MNEM_vaddv 0xeef10f00
14350#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14351#define M_MNEM_vddup 0xee011f6e
14352#define M_MNEM_vdwdup 0xee011f60
14353#define M_MNEM_vidup 0xee010f6e
14354#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14355#define M_MNEM_vmaxv 0xeee20f00
14356#define M_MNEM_vmaxav 0xeee00f00
14357#define M_MNEM_vminv 0xeee20f80
14358#define M_MNEM_vminav 0xeee00f80
93925576
AV
14359#define M_MNEM_vmlaldav 0xee800e00
14360#define M_MNEM_vmlaldava 0xee800e20
14361#define M_MNEM_vmlaldavx 0xee801e00
14362#define M_MNEM_vmlaldavax 0xee801e20
14363#define M_MNEM_vmlsldav 0xee800e01
14364#define M_MNEM_vmlsldava 0xee800e21
14365#define M_MNEM_vmlsldavx 0xee801e01
14366#define M_MNEM_vmlsldavax 0xee801e21
14367#define M_MNEM_vrmlaldavhx 0xee801f00
14368#define M_MNEM_vrmlaldavhax 0xee801f20
14369#define M_MNEM_vrmlsldavh 0xfe800e01
14370#define M_MNEM_vrmlsldavha 0xfe800e21
14371#define M_MNEM_vrmlsldavhx 0xfe801e01
14372#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14373#define M_MNEM_vqmovnt 0xee331e01
14374#define M_MNEM_vqmovnb 0xee330e01
14375#define M_MNEM_vqmovunt 0xee311e81
14376#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14377#define M_MNEM_vshrnt 0xee801fc1
14378#define M_MNEM_vshrnb 0xee800fc1
14379#define M_MNEM_vrshrnt 0xfe801fc1
14380#define M_MNEM_vqshrnt 0xee801f40
14381#define M_MNEM_vqshrnb 0xee800f40
14382#define M_MNEM_vqshrunt 0xee801fc0
14383#define M_MNEM_vqshrunb 0xee800fc0
14384#define M_MNEM_vrshrnb 0xfe800fc1
14385#define M_MNEM_vqrshrnt 0xee801f41
14386#define M_MNEM_vqrshrnb 0xee800f41
14387#define M_MNEM_vqrshrunt 0xfe801fc0
14388#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14389
5287ad62 14390/* Neon instruction encoder helpers. */
5f4273c7 14391
5287ad62 14392/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14393
5287ad62
JB
14394/* An "invalid" code for the following tables. */
14395#define N_INV -1u
14396
14397struct neon_tab_entry
b99bd4ef 14398{
5287ad62
JB
14399 unsigned integer;
14400 unsigned float_or_poly;
14401 unsigned scalar_or_imm;
14402};
5f4273c7 14403
5287ad62
JB
14404/* Map overloaded Neon opcodes to their respective encodings. */
14405#define NEON_ENC_TAB \
14406 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14407 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14408 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14409 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14410 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14411 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14412 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14413 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14414 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14415 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14416 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14417 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14418 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14419 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14420 /* Register variants of the following two instructions are encoded as
e07e6e58 14421 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14422 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14423 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14424 X(vfma, N_INV, 0x0000c10, N_INV), \
14425 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14426 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14427 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14428 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14429 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14430 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14431 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14432 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14433 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14434 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14435 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14436 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14437 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14438 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14439 X(vshl, 0x0000400, N_INV, 0x0800510), \
14440 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14441 X(vand, 0x0000110, N_INV, 0x0800030), \
14442 X(vbic, 0x0100110, N_INV, 0x0800030), \
14443 X(veor, 0x1000110, N_INV, N_INV), \
14444 X(vorn, 0x0300110, N_INV, 0x0800010), \
14445 X(vorr, 0x0200110, N_INV, 0x0800010), \
14446 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14447 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14448 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14449 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14450 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14451 X(vst1, 0x0000000, 0x0800000, N_INV), \
14452 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14453 X(vst2, 0x0000100, 0x0800100, N_INV), \
14454 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14455 X(vst3, 0x0000200, 0x0800200, N_INV), \
14456 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14457 X(vst4, 0x0000300, 0x0800300, N_INV), \
14458 X(vmovn, 0x1b20200, N_INV, N_INV), \
14459 X(vtrn, 0x1b20080, N_INV, N_INV), \
14460 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14461 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14462 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14463 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14464 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14465 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14466 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14467 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14468 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14469 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14470 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14471 X(vseleq, 0xe000a00, N_INV, N_INV), \
14472 X(vselvs, 0xe100a00, N_INV, N_INV), \
14473 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14474 X(vselgt, 0xe300a00, N_INV, N_INV), \
14475 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14476 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14477 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14478 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14479 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14480 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14481 X(sha3op, 0x2000c00, N_INV, N_INV), \
14482 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14483 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14484
14485enum neon_opc
14486{
14487#define X(OPC,I,F,S) N_MNEM_##OPC
14488NEON_ENC_TAB
14489#undef X
14490};
b99bd4ef 14491
5287ad62
JB
14492static const struct neon_tab_entry neon_enc_tab[] =
14493{
14494#define X(OPC,I,F,S) { (I), (F), (S) }
14495NEON_ENC_TAB
14496#undef X
14497};
b99bd4ef 14498
88714cb8
DG
14499/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14500#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14501#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14502#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14503#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14504#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14505#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14506#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14507#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14508#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14509#define NEON_ENC_SINGLE_(X) \
037e8744 14510 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14511#define NEON_ENC_DOUBLE_(X) \
037e8744 14512 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14513#define NEON_ENC_FPV8_(X) \
14514 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14515
88714cb8
DG
14516#define NEON_ENCODE(type, inst) \
14517 do \
14518 { \
14519 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14520 inst.is_neon = 1; \
14521 } \
14522 while (0)
14523
14524#define check_neon_suffixes \
14525 do \
14526 { \
14527 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14528 { \
14529 as_bad (_("invalid neon suffix for non neon instruction")); \
14530 return; \
14531 } \
14532 } \
14533 while (0)
14534
037e8744
JB
14535/* Define shapes for instruction operands. The following mnemonic characters
14536 are used in this table:
5287ad62 14537
037e8744 14538 F - VFP S<n> register
5287ad62
JB
14539 D - Neon D<n> register
14540 Q - Neon Q<n> register
14541 I - Immediate
14542 S - Scalar
14543 R - ARM register
14544 L - D<n> register list
5f4273c7 14545
037e8744
JB
14546 This table is used to generate various data:
14547 - enumerations of the form NS_DDR to be used as arguments to
14548 neon_select_shape.
14549 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14550 - a table used to drive neon_select_shape. */
b99bd4ef 14551
037e8744 14552#define NEON_SHAPE_DEF \
93925576 14553 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14554 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14555 X(4, (R, R, S, S), QUAD), \
14556 X(4, (S, S, R, R), QUAD), \
b409bdb6 14557 X(3, (Q, R, I), QUAD), \
1b883319
AV
14558 X(3, (I, Q, Q), QUAD), \
14559 X(3, (I, Q, R), QUAD), \
a302e574 14560 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14561 X(3, (D, D, D), DOUBLE), \
14562 X(3, (Q, Q, Q), QUAD), \
14563 X(3, (D, D, I), DOUBLE), \
14564 X(3, (Q, Q, I), QUAD), \
14565 X(3, (D, D, S), DOUBLE), \
14566 X(3, (Q, Q, S), QUAD), \
5ee91343 14567 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14568 X(3, (R, R, Q), QUAD), \
14569 X(2, (R, Q), QUAD), \
037e8744
JB
14570 X(2, (D, D), DOUBLE), \
14571 X(2, (Q, Q), QUAD), \
14572 X(2, (D, S), DOUBLE), \
14573 X(2, (Q, S), QUAD), \
14574 X(2, (D, R), DOUBLE), \
14575 X(2, (Q, R), QUAD), \
14576 X(2, (D, I), DOUBLE), \
14577 X(2, (Q, I), QUAD), \
14578 X(3, (D, L, D), DOUBLE), \
14579 X(2, (D, Q), MIXED), \
14580 X(2, (Q, D), MIXED), \
14581 X(3, (D, Q, I), MIXED), \
14582 X(3, (Q, D, I), MIXED), \
14583 X(3, (Q, D, D), MIXED), \
14584 X(3, (D, Q, Q), MIXED), \
14585 X(3, (Q, Q, D), MIXED), \
14586 X(3, (Q, D, S), MIXED), \
14587 X(3, (D, Q, S), MIXED), \
14588 X(4, (D, D, D, I), DOUBLE), \
14589 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14590 X(4, (D, D, S, I), DOUBLE), \
14591 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14592 X(2, (F, F), SINGLE), \
14593 X(3, (F, F, F), SINGLE), \
14594 X(2, (F, I), SINGLE), \
14595 X(2, (F, D), MIXED), \
14596 X(2, (D, F), MIXED), \
14597 X(3, (F, F, I), MIXED), \
14598 X(4, (R, R, F, F), SINGLE), \
14599 X(4, (F, F, R, R), SINGLE), \
14600 X(3, (D, R, R), DOUBLE), \
14601 X(3, (R, R, D), DOUBLE), \
14602 X(2, (S, R), SINGLE), \
14603 X(2, (R, S), SINGLE), \
14604 X(2, (F, R), SINGLE), \
d54af2d0 14605 X(2, (R, F), SINGLE), \
1f6234a3
AV
14606/* Used for MVE tail predicated loop instructions. */\
14607 X(2, (R, R), QUAD), \
d54af2d0
RL
14608/* Half float shape supported so far. */\
14609 X (2, (H, D), MIXED), \
14610 X (2, (D, H), MIXED), \
14611 X (2, (H, F), MIXED), \
14612 X (2, (F, H), MIXED), \
14613 X (2, (H, H), HALF), \
14614 X (2, (H, R), HALF), \
14615 X (2, (R, H), HALF), \
14616 X (2, (H, I), HALF), \
14617 X (3, (H, H, H), HALF), \
14618 X (3, (H, F, I), MIXED), \
dec41383
JW
14619 X (3, (F, H, I), MIXED), \
14620 X (3, (D, H, H), MIXED), \
14621 X (3, (D, H, S), MIXED)
037e8744
JB
14622
14623#define S2(A,B) NS_##A##B
14624#define S3(A,B,C) NS_##A##B##C
14625#define S4(A,B,C,D) NS_##A##B##C##D
14626
14627#define X(N, L, C) S##N L
14628
5287ad62
JB
14629enum neon_shape
14630{
037e8744
JB
14631 NEON_SHAPE_DEF,
14632 NS_NULL
5287ad62 14633};
b99bd4ef 14634
037e8744
JB
14635#undef X
14636#undef S2
14637#undef S3
14638#undef S4
14639
14640enum neon_shape_class
14641{
d54af2d0 14642 SC_HALF,
037e8744
JB
14643 SC_SINGLE,
14644 SC_DOUBLE,
14645 SC_QUAD,
14646 SC_MIXED
14647};
14648
14649#define X(N, L, C) SC_##C
14650
14651static enum neon_shape_class neon_shape_class[] =
14652{
14653 NEON_SHAPE_DEF
14654};
14655
14656#undef X
14657
14658enum neon_shape_el
14659{
d54af2d0 14660 SE_H,
037e8744
JB
14661 SE_F,
14662 SE_D,
14663 SE_Q,
14664 SE_I,
14665 SE_S,
14666 SE_R,
14667 SE_L
14668};
14669
14670/* Register widths of above. */
14671static unsigned neon_shape_el_size[] =
14672{
d54af2d0 14673 16,
037e8744
JB
14674 32,
14675 64,
14676 128,
14677 0,
14678 32,
14679 32,
14680 0
14681};
14682
14683struct neon_shape_info
14684{
14685 unsigned els;
14686 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14687};
14688
14689#define S2(A,B) { SE_##A, SE_##B }
14690#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14691#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14692
14693#define X(N, L, C) { N, S##N L }
14694
14695static struct neon_shape_info neon_shape_tab[] =
14696{
14697 NEON_SHAPE_DEF
14698};
14699
14700#undef X
14701#undef S2
14702#undef S3
14703#undef S4
14704
5287ad62
JB
14705/* Bit masks used in type checking given instructions.
14706 'N_EQK' means the type must be the same as (or based on in some way) the key
14707 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14708 set, various other bits can be set as well in order to modify the meaning of
14709 the type constraint. */
14710
14711enum neon_type_mask
14712{
8e79c3df
CM
14713 N_S8 = 0x0000001,
14714 N_S16 = 0x0000002,
14715 N_S32 = 0x0000004,
14716 N_S64 = 0x0000008,
14717 N_U8 = 0x0000010,
14718 N_U16 = 0x0000020,
14719 N_U32 = 0x0000040,
14720 N_U64 = 0x0000080,
14721 N_I8 = 0x0000100,
14722 N_I16 = 0x0000200,
14723 N_I32 = 0x0000400,
14724 N_I64 = 0x0000800,
14725 N_8 = 0x0001000,
14726 N_16 = 0x0002000,
14727 N_32 = 0x0004000,
14728 N_64 = 0x0008000,
14729 N_P8 = 0x0010000,
14730 N_P16 = 0x0020000,
14731 N_F16 = 0x0040000,
14732 N_F32 = 0x0080000,
14733 N_F64 = 0x0100000,
4f51b4bd 14734 N_P64 = 0x0200000,
c921be7d
NC
14735 N_KEY = 0x1000000, /* Key element (main type specifier). */
14736 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 14737 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 14738 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
14739 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14740 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14741 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14742 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14743 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14744 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14745 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 14746 N_UTYP = 0,
4f51b4bd 14747 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
14748};
14749
dcbf9037
JB
14750#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14751
5287ad62
JB
14752#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14753#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14754#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
14755#define N_S_32 (N_S8 | N_S16 | N_S32)
14756#define N_F_16_32 (N_F16 | N_F32)
14757#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 14758#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 14759#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 14760#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
14761#define N_I_MVE (N_I8 | N_I16 | N_I32)
14762#define N_F_MVE (N_F16 | N_F32)
14763#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
14764
14765/* Pass this as the first type argument to neon_check_type to ignore types
14766 altogether. */
14767#define N_IGNORE_TYPE (N_KEY | N_EQK)
14768
037e8744
JB
14769/* Select a "shape" for the current instruction (describing register types or
14770 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14771 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14772 function of operand parsing, so this function doesn't need to be called.
14773 Shapes should be listed in order of decreasing length. */
5287ad62
JB
14774
14775static enum neon_shape
037e8744 14776neon_select_shape (enum neon_shape shape, ...)
5287ad62 14777{
037e8744
JB
14778 va_list ap;
14779 enum neon_shape first_shape = shape;
5287ad62
JB
14780
14781 /* Fix missing optional operands. FIXME: we don't know at this point how
14782 many arguments we should have, so this makes the assumption that we have
14783 > 1. This is true of all current Neon opcodes, I think, but may not be
14784 true in the future. */
14785 if (!inst.operands[1].present)
14786 inst.operands[1] = inst.operands[0];
14787
037e8744 14788 va_start (ap, shape);
5f4273c7 14789
21d799b5 14790 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
14791 {
14792 unsigned j;
14793 int matches = 1;
14794
14795 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
14796 {
14797 if (!inst.operands[j].present)
14798 {
14799 matches = 0;
14800 break;
14801 }
14802
14803 switch (neon_shape_tab[shape].el[j])
14804 {
d54af2d0
RL
14805 /* If a .f16, .16, .u16, .s16 type specifier is given over
14806 a VFP single precision register operand, it's essentially
14807 means only half of the register is used.
14808
14809 If the type specifier is given after the mnemonics, the
14810 information is stored in inst.vectype. If the type specifier
14811 is given after register operand, the information is stored
14812 in inst.operands[].vectype.
14813
14814 When there is only one type specifier, and all the register
14815 operands are the same type of hardware register, the type
14816 specifier applies to all register operands.
14817
14818 If no type specifier is given, the shape is inferred from
14819 operand information.
14820
14821 for example:
14822 vadd.f16 s0, s1, s2: NS_HHH
14823 vabs.f16 s0, s1: NS_HH
14824 vmov.f16 s0, r1: NS_HR
14825 vmov.f16 r0, s1: NS_RH
14826 vcvt.f16 r0, s1: NS_RH
14827 vcvt.f16.s32 s2, s2, #29: NS_HFI
14828 vcvt.f16.s32 s2, s2: NS_HF
14829 */
14830 case SE_H:
14831 if (!(inst.operands[j].isreg
14832 && inst.operands[j].isvec
14833 && inst.operands[j].issingle
14834 && !inst.operands[j].isquad
14835 && ((inst.vectype.elems == 1
14836 && inst.vectype.el[0].size == 16)
14837 || (inst.vectype.elems > 1
14838 && inst.vectype.el[j].size == 16)
14839 || (inst.vectype.elems == 0
14840 && inst.operands[j].vectype.type != NT_invtype
14841 && inst.operands[j].vectype.size == 16))))
14842 matches = 0;
14843 break;
14844
477330fc
RM
14845 case SE_F:
14846 if (!(inst.operands[j].isreg
14847 && inst.operands[j].isvec
14848 && inst.operands[j].issingle
d54af2d0
RL
14849 && !inst.operands[j].isquad
14850 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14851 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14852 || (inst.vectype.elems == 0
14853 && (inst.operands[j].vectype.size == 32
14854 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
14855 matches = 0;
14856 break;
14857
14858 case SE_D:
14859 if (!(inst.operands[j].isreg
14860 && inst.operands[j].isvec
14861 && !inst.operands[j].isquad
14862 && !inst.operands[j].issingle))
14863 matches = 0;
14864 break;
14865
14866 case SE_R:
14867 if (!(inst.operands[j].isreg
14868 && !inst.operands[j].isvec))
14869 matches = 0;
14870 break;
14871
14872 case SE_Q:
14873 if (!(inst.operands[j].isreg
14874 && inst.operands[j].isvec
14875 && inst.operands[j].isquad
14876 && !inst.operands[j].issingle))
14877 matches = 0;
14878 break;
14879
14880 case SE_I:
14881 if (!(!inst.operands[j].isreg
14882 && !inst.operands[j].isscalar))
14883 matches = 0;
14884 break;
14885
14886 case SE_S:
14887 if (!(!inst.operands[j].isreg
14888 && inst.operands[j].isscalar))
14889 matches = 0;
14890 break;
14891
14892 case SE_L:
14893 break;
14894 }
3fde54a2
JZ
14895 if (!matches)
14896 break;
477330fc 14897 }
ad6cec43
MGD
14898 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
14899 /* We've matched all the entries in the shape table, and we don't
14900 have any left over operands which have not been matched. */
477330fc 14901 break;
037e8744 14902 }
5f4273c7 14903
037e8744 14904 va_end (ap);
5287ad62 14905
037e8744
JB
14906 if (shape == NS_NULL && first_shape != NS_NULL)
14907 first_error (_("invalid instruction shape"));
5287ad62 14908
037e8744
JB
14909 return shape;
14910}
5287ad62 14911
037e8744
JB
14912/* True if SHAPE is predominantly a quadword operation (most of the time, this
14913 means the Q bit should be set). */
14914
14915static int
14916neon_quad (enum neon_shape shape)
14917{
14918 return neon_shape_class[shape] == SC_QUAD;
5287ad62 14919}
037e8744 14920
5287ad62
JB
14921static void
14922neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 14923 unsigned *g_size)
5287ad62
JB
14924{
14925 /* Allow modification to be made to types which are constrained to be
14926 based on the key element, based on bits set alongside N_EQK. */
14927 if ((typebits & N_EQK) != 0)
14928 {
14929 if ((typebits & N_HLF) != 0)
14930 *g_size /= 2;
14931 else if ((typebits & N_DBL) != 0)
14932 *g_size *= 2;
14933 if ((typebits & N_SGN) != 0)
14934 *g_type = NT_signed;
14935 else if ((typebits & N_UNS) != 0)
477330fc 14936 *g_type = NT_unsigned;
5287ad62 14937 else if ((typebits & N_INT) != 0)
477330fc 14938 *g_type = NT_integer;
5287ad62 14939 else if ((typebits & N_FLT) != 0)
477330fc 14940 *g_type = NT_float;
dcbf9037 14941 else if ((typebits & N_SIZ) != 0)
477330fc 14942 *g_type = NT_untyped;
5287ad62
JB
14943 }
14944}
5f4273c7 14945
5287ad62
JB
14946/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
14947 operand type, i.e. the single type specified in a Neon instruction when it
14948 is the only one given. */
14949
14950static struct neon_type_el
14951neon_type_promote (struct neon_type_el *key, unsigned thisarg)
14952{
14953 struct neon_type_el dest = *key;
5f4273c7 14954
9c2799c2 14955 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 14956
5287ad62
JB
14957 neon_modify_type_size (thisarg, &dest.type, &dest.size);
14958
14959 return dest;
14960}
14961
14962/* Convert Neon type and size into compact bitmask representation. */
14963
14964static enum neon_type_mask
14965type_chk_of_el_type (enum neon_el_type type, unsigned size)
14966{
14967 switch (type)
14968 {
14969 case NT_untyped:
14970 switch (size)
477330fc
RM
14971 {
14972 case 8: return N_8;
14973 case 16: return N_16;
14974 case 32: return N_32;
14975 case 64: return N_64;
14976 default: ;
14977 }
5287ad62
JB
14978 break;
14979
14980 case NT_integer:
14981 switch (size)
477330fc
RM
14982 {
14983 case 8: return N_I8;
14984 case 16: return N_I16;
14985 case 32: return N_I32;
14986 case 64: return N_I64;
14987 default: ;
14988 }
5287ad62
JB
14989 break;
14990
14991 case NT_float:
037e8744 14992 switch (size)
477330fc 14993 {
8e79c3df 14994 case 16: return N_F16;
477330fc
RM
14995 case 32: return N_F32;
14996 case 64: return N_F64;
14997 default: ;
14998 }
5287ad62
JB
14999 break;
15000
15001 case NT_poly:
15002 switch (size)
477330fc
RM
15003 {
15004 case 8: return N_P8;
15005 case 16: return N_P16;
4f51b4bd 15006 case 64: return N_P64;
477330fc
RM
15007 default: ;
15008 }
5287ad62
JB
15009 break;
15010
15011 case NT_signed:
15012 switch (size)
477330fc
RM
15013 {
15014 case 8: return N_S8;
15015 case 16: return N_S16;
15016 case 32: return N_S32;
15017 case 64: return N_S64;
15018 default: ;
15019 }
5287ad62
JB
15020 break;
15021
15022 case NT_unsigned:
15023 switch (size)
477330fc
RM
15024 {
15025 case 8: return N_U8;
15026 case 16: return N_U16;
15027 case 32: return N_U32;
15028 case 64: return N_U64;
15029 default: ;
15030 }
5287ad62
JB
15031 break;
15032
15033 default: ;
15034 }
5f4273c7 15035
5287ad62
JB
15036 return N_UTYP;
15037}
15038
15039/* Convert compact Neon bitmask type representation to a type and size. Only
15040 handles the case where a single bit is set in the mask. */
15041
dcbf9037 15042static int
5287ad62 15043el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15044 enum neon_type_mask mask)
5287ad62 15045{
dcbf9037
JB
15046 if ((mask & N_EQK) != 0)
15047 return FAIL;
15048
5287ad62
JB
15049 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15050 *size = 8;
c70a8987 15051 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 15052 *size = 16;
dcbf9037 15053 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15054 *size = 32;
4f51b4bd 15055 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15056 *size = 64;
dcbf9037
JB
15057 else
15058 return FAIL;
15059
5287ad62
JB
15060 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15061 *type = NT_signed;
dcbf9037 15062 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15063 *type = NT_unsigned;
dcbf9037 15064 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15065 *type = NT_integer;
dcbf9037 15066 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15067 *type = NT_untyped;
4f51b4bd 15068 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15069 *type = NT_poly;
d54af2d0 15070 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15071 *type = NT_float;
dcbf9037
JB
15072 else
15073 return FAIL;
5f4273c7 15074
dcbf9037 15075 return SUCCESS;
5287ad62
JB
15076}
15077
15078/* Modify a bitmask of allowed types. This is only needed for type
15079 relaxation. */
15080
15081static unsigned
15082modify_types_allowed (unsigned allowed, unsigned mods)
15083{
15084 unsigned size;
15085 enum neon_el_type type;
15086 unsigned destmask;
15087 int i;
5f4273c7 15088
5287ad62 15089 destmask = 0;
5f4273c7 15090
5287ad62
JB
15091 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15092 {
21d799b5 15093 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15094 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15095 {
15096 neon_modify_type_size (mods, &type, &size);
15097 destmask |= type_chk_of_el_type (type, size);
15098 }
5287ad62 15099 }
5f4273c7 15100
5287ad62
JB
15101 return destmask;
15102}
15103
15104/* Check type and return type classification.
15105 The manual states (paraphrase): If one datatype is given, it indicates the
15106 type given in:
15107 - the second operand, if there is one
15108 - the operand, if there is no second operand
15109 - the result, if there are no operands.
15110 This isn't quite good enough though, so we use a concept of a "key" datatype
15111 which is set on a per-instruction basis, which is the one which matters when
15112 only one data type is written.
15113 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15114 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15115
15116static struct neon_type_el
15117neon_check_type (unsigned els, enum neon_shape ns, ...)
15118{
15119 va_list ap;
15120 unsigned i, pass, key_el = 0;
15121 unsigned types[NEON_MAX_TYPE_ELS];
15122 enum neon_el_type k_type = NT_invtype;
15123 unsigned k_size = -1u;
15124 struct neon_type_el badtype = {NT_invtype, -1};
15125 unsigned key_allowed = 0;
15126
15127 /* Optional registers in Neon instructions are always (not) in operand 1.
15128 Fill in the missing operand here, if it was omitted. */
15129 if (els > 1 && !inst.operands[1].present)
15130 inst.operands[1] = inst.operands[0];
15131
15132 /* Suck up all the varargs. */
15133 va_start (ap, ns);
15134 for (i = 0; i < els; i++)
15135 {
15136 unsigned thisarg = va_arg (ap, unsigned);
15137 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15138 {
15139 va_end (ap);
15140 return badtype;
15141 }
5287ad62
JB
15142 types[i] = thisarg;
15143 if ((thisarg & N_KEY) != 0)
477330fc 15144 key_el = i;
5287ad62
JB
15145 }
15146 va_end (ap);
15147
dcbf9037
JB
15148 if (inst.vectype.elems > 0)
15149 for (i = 0; i < els; i++)
15150 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15151 {
15152 first_error (_("types specified in both the mnemonic and operands"));
15153 return badtype;
15154 }
dcbf9037 15155
5287ad62
JB
15156 /* Duplicate inst.vectype elements here as necessary.
15157 FIXME: No idea if this is exactly the same as the ARM assembler,
15158 particularly when an insn takes one register and one non-register
15159 operand. */
15160 if (inst.vectype.elems == 1 && els > 1)
15161 {
15162 unsigned j;
15163 inst.vectype.elems = els;
15164 inst.vectype.el[key_el] = inst.vectype.el[0];
15165 for (j = 0; j < els; j++)
477330fc
RM
15166 if (j != key_el)
15167 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15168 types[j]);
dcbf9037
JB
15169 }
15170 else if (inst.vectype.elems == 0 && els > 0)
15171 {
15172 unsigned j;
15173 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15174 after each operand. We allow some flexibility here; as long as the
15175 "key" operand has a type, we can infer the others. */
dcbf9037 15176 for (j = 0; j < els; j++)
477330fc
RM
15177 if (inst.operands[j].vectype.type != NT_invtype)
15178 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15179
15180 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15181 {
15182 for (j = 0; j < els; j++)
15183 if (inst.operands[j].vectype.type == NT_invtype)
15184 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15185 types[j]);
15186 }
dcbf9037 15187 else
477330fc
RM
15188 {
15189 first_error (_("operand types can't be inferred"));
15190 return badtype;
15191 }
5287ad62
JB
15192 }
15193 else if (inst.vectype.elems != els)
15194 {
dcbf9037 15195 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15196 return badtype;
15197 }
15198
15199 for (pass = 0; pass < 2; pass++)
15200 {
15201 for (i = 0; i < els; i++)
477330fc
RM
15202 {
15203 unsigned thisarg = types[i];
15204 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15205 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15206 enum neon_el_type g_type = inst.vectype.el[i].type;
15207 unsigned g_size = inst.vectype.el[i].size;
15208
15209 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15210 integer types if sign-specific variants are unavailable. */
477330fc 15211 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15212 && (types_allowed & N_SU_ALL) == 0)
15213 g_type = NT_integer;
15214
477330fc 15215 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15216 them. Some instructions only care about signs for some element
15217 sizes, so handle that properly. */
477330fc 15218 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15219 && ((g_size == 8 && (types_allowed & N_8) != 0)
15220 || (g_size == 16 && (types_allowed & N_16) != 0)
15221 || (g_size == 32 && (types_allowed & N_32) != 0)
15222 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15223 g_type = NT_untyped;
15224
477330fc
RM
15225 if (pass == 0)
15226 {
15227 if ((thisarg & N_KEY) != 0)
15228 {
15229 k_type = g_type;
15230 k_size = g_size;
15231 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15232
15233 /* Check architecture constraint on FP16 extension. */
15234 if (k_size == 16
15235 && k_type == NT_float
15236 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15237 {
15238 inst.error = _(BAD_FP16);
15239 return badtype;
15240 }
477330fc
RM
15241 }
15242 }
15243 else
15244 {
15245 if ((thisarg & N_VFP) != 0)
15246 {
15247 enum neon_shape_el regshape;
15248 unsigned regwidth, match;
99b253c5
NC
15249
15250 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15251 if (ns == NS_NULL)
15252 {
15253 first_error (_("invalid instruction shape"));
15254 return badtype;
15255 }
477330fc
RM
15256 regshape = neon_shape_tab[ns].el[i];
15257 regwidth = neon_shape_el_size[regshape];
15258
15259 /* In VFP mode, operands must match register widths. If we
15260 have a key operand, use its width, else use the width of
15261 the current operand. */
15262 if (k_size != -1u)
15263 match = k_size;
15264 else
15265 match = g_size;
15266
9db2f6b4
RL
15267 /* FP16 will use a single precision register. */
15268 if (regwidth == 32 && match == 16)
15269 {
15270 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15271 match = regwidth;
15272 else
15273 {
15274 inst.error = _(BAD_FP16);
15275 return badtype;
15276 }
15277 }
15278
477330fc
RM
15279 if (regwidth != match)
15280 {
15281 first_error (_("operand size must match register width"));
15282 return badtype;
15283 }
15284 }
15285
15286 if ((thisarg & N_EQK) == 0)
15287 {
15288 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15289
15290 if ((given_type & types_allowed) == 0)
15291 {
a302e574 15292 first_error (BAD_SIMD_TYPE);
477330fc
RM
15293 return badtype;
15294 }
15295 }
15296 else
15297 {
15298 enum neon_el_type mod_k_type = k_type;
15299 unsigned mod_k_size = k_size;
15300 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15301 if (g_type != mod_k_type || g_size != mod_k_size)
15302 {
15303 first_error (_("inconsistent types in Neon instruction"));
15304 return badtype;
15305 }
15306 }
15307 }
15308 }
5287ad62
JB
15309 }
15310
15311 return inst.vectype.el[key_el];
15312}
15313
037e8744 15314/* Neon-style VFP instruction forwarding. */
5287ad62 15315
037e8744
JB
15316/* Thumb VFP instructions have 0xE in the condition field. */
15317
15318static void
15319do_vfp_cond_or_thumb (void)
5287ad62 15320{
88714cb8
DG
15321 inst.is_neon = 1;
15322
5287ad62 15323 if (thumb_mode)
037e8744 15324 inst.instruction |= 0xe0000000;
5287ad62 15325 else
037e8744 15326 inst.instruction |= inst.cond << 28;
5287ad62
JB
15327}
15328
037e8744
JB
15329/* Look up and encode a simple mnemonic, for use as a helper function for the
15330 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15331 etc. It is assumed that operand parsing has already been done, and that the
15332 operands are in the form expected by the given opcode (this isn't necessarily
15333 the same as the form in which they were parsed, hence some massaging must
15334 take place before this function is called).
15335 Checks current arch version against that in the looked-up opcode. */
5287ad62 15336
037e8744
JB
15337static void
15338do_vfp_nsyn_opcode (const char *opname)
5287ad62 15339{
037e8744 15340 const struct asm_opcode *opcode;
5f4273c7 15341
21d799b5 15342 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 15343
037e8744
JB
15344 if (!opcode)
15345 abort ();
5287ad62 15346
037e8744 15347 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15348 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15349 _(BAD_FPU));
5287ad62 15350
88714cb8
DG
15351 inst.is_neon = 1;
15352
037e8744
JB
15353 if (thumb_mode)
15354 {
15355 inst.instruction = opcode->tvalue;
15356 opcode->tencode ();
15357 }
15358 else
15359 {
15360 inst.instruction = (inst.cond << 28) | opcode->avalue;
15361 opcode->aencode ();
15362 }
15363}
5287ad62
JB
15364
15365static void
037e8744 15366do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15367{
037e8744
JB
15368 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15369
9db2f6b4 15370 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15371 {
15372 if (is_add)
477330fc 15373 do_vfp_nsyn_opcode ("fadds");
037e8744 15374 else
477330fc 15375 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15376
15377 /* ARMv8.2 fp16 instruction. */
15378 if (rs == NS_HHH)
15379 do_scalar_fp16_v82_encode ();
037e8744
JB
15380 }
15381 else
15382 {
15383 if (is_add)
477330fc 15384 do_vfp_nsyn_opcode ("faddd");
037e8744 15385 else
477330fc 15386 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15387 }
15388}
15389
15390/* Check operand types to see if this is a VFP instruction, and if so call
15391 PFN (). */
15392
15393static int
15394try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15395{
15396 enum neon_shape rs;
15397 struct neon_type_el et;
15398
15399 switch (args)
15400 {
15401 case 2:
9db2f6b4
RL
15402 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15403 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15404 break;
5f4273c7 15405
037e8744 15406 case 3:
9db2f6b4
RL
15407 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15408 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15409 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15410 break;
15411
15412 default:
15413 abort ();
15414 }
15415
15416 if (et.type != NT_invtype)
15417 {
15418 pfn (rs);
15419 return SUCCESS;
15420 }
037e8744 15421
99b253c5 15422 inst.error = NULL;
037e8744
JB
15423 return FAIL;
15424}
15425
15426static void
15427do_vfp_nsyn_mla_mls (enum neon_shape rs)
15428{
15429 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15430
9db2f6b4 15431 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15432 {
15433 if (is_mla)
477330fc 15434 do_vfp_nsyn_opcode ("fmacs");
037e8744 15435 else
477330fc 15436 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15437
15438 /* ARMv8.2 fp16 instruction. */
15439 if (rs == NS_HHH)
15440 do_scalar_fp16_v82_encode ();
037e8744
JB
15441 }
15442 else
15443 {
15444 if (is_mla)
477330fc 15445 do_vfp_nsyn_opcode ("fmacd");
037e8744 15446 else
477330fc 15447 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15448 }
15449}
15450
62f3b8c8
PB
15451static void
15452do_vfp_nsyn_fma_fms (enum neon_shape rs)
15453{
15454 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15455
9db2f6b4 15456 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15457 {
15458 if (is_fma)
477330fc 15459 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15460 else
477330fc 15461 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15462
15463 /* ARMv8.2 fp16 instruction. */
15464 if (rs == NS_HHH)
15465 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15466 }
15467 else
15468 {
15469 if (is_fma)
477330fc 15470 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15471 else
477330fc 15472 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15473 }
15474}
15475
037e8744
JB
15476static void
15477do_vfp_nsyn_mul (enum neon_shape rs)
15478{
9db2f6b4
RL
15479 if (rs == NS_FFF || rs == NS_HHH)
15480 {
15481 do_vfp_nsyn_opcode ("fmuls");
15482
15483 /* ARMv8.2 fp16 instruction. */
15484 if (rs == NS_HHH)
15485 do_scalar_fp16_v82_encode ();
15486 }
037e8744
JB
15487 else
15488 do_vfp_nsyn_opcode ("fmuld");
15489}
15490
15491static void
15492do_vfp_nsyn_abs_neg (enum neon_shape rs)
15493{
15494 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15495 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15496
9db2f6b4 15497 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15498 {
15499 if (is_neg)
477330fc 15500 do_vfp_nsyn_opcode ("fnegs");
037e8744 15501 else
477330fc 15502 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15503
15504 /* ARMv8.2 fp16 instruction. */
15505 if (rs == NS_HH)
15506 do_scalar_fp16_v82_encode ();
037e8744
JB
15507 }
15508 else
15509 {
15510 if (is_neg)
477330fc 15511 do_vfp_nsyn_opcode ("fnegd");
037e8744 15512 else
477330fc 15513 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15514 }
15515}
15516
15517/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15518 insns belong to Neon, and are handled elsewhere. */
15519
15520static void
15521do_vfp_nsyn_ldm_stm (int is_dbmode)
15522{
15523 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15524 if (is_ldm)
15525 {
15526 if (is_dbmode)
477330fc 15527 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15528 else
477330fc 15529 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15530 }
15531 else
15532 {
15533 if (is_dbmode)
477330fc 15534 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15535 else
477330fc 15536 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15537 }
15538}
15539
037e8744
JB
15540static void
15541do_vfp_nsyn_sqrt (void)
15542{
9db2f6b4
RL
15543 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15544 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15545
9db2f6b4
RL
15546 if (rs == NS_FF || rs == NS_HH)
15547 {
15548 do_vfp_nsyn_opcode ("fsqrts");
15549
15550 /* ARMv8.2 fp16 instruction. */
15551 if (rs == NS_HH)
15552 do_scalar_fp16_v82_encode ();
15553 }
037e8744
JB
15554 else
15555 do_vfp_nsyn_opcode ("fsqrtd");
15556}
15557
15558static void
15559do_vfp_nsyn_div (void)
15560{
9db2f6b4 15561 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15562 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15563 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15564
9db2f6b4
RL
15565 if (rs == NS_FFF || rs == NS_HHH)
15566 {
15567 do_vfp_nsyn_opcode ("fdivs");
15568
15569 /* ARMv8.2 fp16 instruction. */
15570 if (rs == NS_HHH)
15571 do_scalar_fp16_v82_encode ();
15572 }
037e8744
JB
15573 else
15574 do_vfp_nsyn_opcode ("fdivd");
15575}
15576
15577static void
15578do_vfp_nsyn_nmul (void)
15579{
9db2f6b4 15580 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15581 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15582 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15583
9db2f6b4 15584 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15585 {
88714cb8 15586 NEON_ENCODE (SINGLE, inst);
037e8744 15587 do_vfp_sp_dyadic ();
9db2f6b4
RL
15588
15589 /* ARMv8.2 fp16 instruction. */
15590 if (rs == NS_HHH)
15591 do_scalar_fp16_v82_encode ();
037e8744
JB
15592 }
15593 else
15594 {
88714cb8 15595 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15596 do_vfp_dp_rd_rn_rm ();
15597 }
15598 do_vfp_cond_or_thumb ();
9db2f6b4 15599
037e8744
JB
15600}
15601
1b883319
AV
15602/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15603 (0, 1, 2, 3). */
15604
15605static unsigned
15606neon_logbits (unsigned x)
15607{
15608 return ffs (x) - 4;
15609}
15610
15611#define LOW4(R) ((R) & 0xf)
15612#define HI1(R) (((R) >> 4) & 1)
15613
15614static unsigned
15615mve_get_vcmp_vpt_cond (struct neon_type_el et)
15616{
15617 switch (et.type)
15618 {
15619 default:
15620 first_error (BAD_EL_TYPE);
15621 return 0;
15622 case NT_float:
15623 switch (inst.operands[0].imm)
15624 {
15625 default:
15626 first_error (_("invalid condition"));
15627 return 0;
15628 case 0x0:
15629 /* eq. */
15630 return 0;
15631 case 0x1:
15632 /* ne. */
15633 return 1;
15634 case 0xa:
15635 /* ge/ */
15636 return 4;
15637 case 0xb:
15638 /* lt. */
15639 return 5;
15640 case 0xc:
15641 /* gt. */
15642 return 6;
15643 case 0xd:
15644 /* le. */
15645 return 7;
15646 }
15647 case NT_integer:
15648 /* only accept eq and ne. */
15649 if (inst.operands[0].imm > 1)
15650 {
15651 first_error (_("invalid condition"));
15652 return 0;
15653 }
15654 return inst.operands[0].imm;
15655 case NT_unsigned:
15656 if (inst.operands[0].imm == 0x2)
15657 return 2;
15658 else if (inst.operands[0].imm == 0x8)
15659 return 3;
15660 else
15661 {
15662 first_error (_("invalid condition"));
15663 return 0;
15664 }
15665 case NT_signed:
15666 switch (inst.operands[0].imm)
15667 {
15668 default:
15669 first_error (_("invalid condition"));
15670 return 0;
15671 case 0xa:
15672 /* ge. */
15673 return 4;
15674 case 0xb:
15675 /* lt. */
15676 return 5;
15677 case 0xc:
15678 /* gt. */
15679 return 6;
15680 case 0xd:
15681 /* le. */
15682 return 7;
15683 }
15684 }
15685 /* Should be unreachable. */
15686 abort ();
15687}
15688
15689static void
15690do_mve_vpt (void)
15691{
15692 /* We are dealing with a vector predicated block. */
15693 if (inst.operands[0].present)
15694 {
15695 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15696 struct neon_type_el et
15697 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15698 N_EQK);
15699
15700 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15701
15702 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15703
15704 if (et.type == NT_invtype)
15705 return;
15706
15707 if (et.type == NT_float)
15708 {
15709 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15710 BAD_FPU);
15711 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
15712 inst.instruction |= (et.size == 16) << 28;
15713 inst.instruction |= 0x3 << 20;
15714 }
15715 else
15716 {
15717 constraint (et.size != 8 && et.size != 16 && et.size != 32,
15718 BAD_EL_TYPE);
15719 inst.instruction |= 1 << 28;
15720 inst.instruction |= neon_logbits (et.size) << 20;
15721 }
15722
15723 if (inst.operands[2].isquad)
15724 {
15725 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15726 inst.instruction |= LOW4 (inst.operands[2].reg);
15727 inst.instruction |= (fcond & 0x2) >> 1;
15728 }
15729 else
15730 {
15731 if (inst.operands[2].reg == REG_SP)
15732 as_tsktsk (MVE_BAD_SP);
15733 inst.instruction |= 1 << 6;
15734 inst.instruction |= (fcond & 0x2) << 4;
15735 inst.instruction |= inst.operands[2].reg;
15736 }
15737 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15738 inst.instruction |= (fcond & 0x4) << 10;
15739 inst.instruction |= (fcond & 0x1) << 7;
15740
15741 }
15742 set_pred_insn_type (VPT_INSN);
15743 now_pred.cc = 0;
15744 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
15745 | ((inst.instruction & 0xe000) >> 13);
15746 now_pred.warn_deprecated = FALSE;
15747 now_pred.type = VECTOR_PRED;
15748 inst.is_neon = 1;
15749}
15750
15751static void
15752do_mve_vcmp (void)
15753{
15754 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
15755 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
15756 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
15757 if (!inst.operands[2].present)
15758 first_error (_("MVE vector or ARM register expected"));
15759 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15760
15761 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
15762 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
15763 && inst.operands[1].isquad)
15764 {
15765 inst.instruction = N_MNEM_vcmp;
15766 inst.cond = 0x10;
15767 }
15768
15769 if (inst.cond > COND_ALWAYS)
15770 inst.pred_insn_type = INSIDE_VPT_INSN;
15771 else
15772 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15773
15774 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15775 struct neon_type_el et
15776 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15777 N_EQK);
15778
15779 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
15780 && !inst.operands[2].iszr, BAD_PC);
15781
15782 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15783
15784 inst.instruction = 0xee010f00;
15785 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15786 inst.instruction |= (fcond & 0x4) << 10;
15787 inst.instruction |= (fcond & 0x1) << 7;
15788 if (et.type == NT_float)
15789 {
15790 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15791 BAD_FPU);
15792 inst.instruction |= (et.size == 16) << 28;
15793 inst.instruction |= 0x3 << 20;
15794 }
15795 else
15796 {
15797 inst.instruction |= 1 << 28;
15798 inst.instruction |= neon_logbits (et.size) << 20;
15799 }
15800 if (inst.operands[2].isquad)
15801 {
15802 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15803 inst.instruction |= (fcond & 0x2) >> 1;
15804 inst.instruction |= LOW4 (inst.operands[2].reg);
15805 }
15806 else
15807 {
15808 if (inst.operands[2].reg == REG_SP)
15809 as_tsktsk (MVE_BAD_SP);
15810 inst.instruction |= 1 << 6;
15811 inst.instruction |= (fcond & 0x2) << 4;
15812 inst.instruction |= inst.operands[2].reg;
15813 }
15814
15815 inst.is_neon = 1;
15816 return;
15817}
15818
935295b5
AV
15819static void
15820do_mve_vmaxa_vmina (void)
15821{
15822 if (inst.cond > COND_ALWAYS)
15823 inst.pred_insn_type = INSIDE_VPT_INSN;
15824 else
15825 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15826
15827 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
15828 struct neon_type_el et
15829 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
15830
15831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15832 inst.instruction |= neon_logbits (et.size) << 18;
15833 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15834 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15835 inst.instruction |= LOW4 (inst.operands[1].reg);
15836 inst.is_neon = 1;
15837}
15838
f30ee27c
AV
15839static void
15840do_mve_vfmas (void)
15841{
15842 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15843 struct neon_type_el et
15844 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
15845
15846 if (inst.cond > COND_ALWAYS)
15847 inst.pred_insn_type = INSIDE_VPT_INSN;
15848 else
15849 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15850
15851 if (inst.operands[2].reg == REG_SP)
15852 as_tsktsk (MVE_BAD_SP);
15853 else if (inst.operands[2].reg == REG_PC)
15854 as_tsktsk (MVE_BAD_PC);
15855
15856 inst.instruction |= (et.size == 16) << 28;
15857 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15858 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15860 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15861 inst.instruction |= inst.operands[2].reg;
15862 inst.is_neon = 1;
15863}
15864
b409bdb6
AV
15865static void
15866do_mve_viddup (void)
15867{
15868 if (inst.cond > COND_ALWAYS)
15869 inst.pred_insn_type = INSIDE_VPT_INSN;
15870 else
15871 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15872
15873 unsigned imm = inst.relocs[0].exp.X_add_number;
15874 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
15875 _("immediate must be either 1, 2, 4 or 8"));
15876
15877 enum neon_shape rs;
15878 struct neon_type_el et;
15879 unsigned Rm;
15880 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
15881 {
15882 rs = neon_select_shape (NS_QRI, NS_NULL);
15883 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
15884 Rm = 7;
15885 }
15886 else
15887 {
15888 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
15889 if (inst.operands[2].reg == REG_SP)
15890 as_tsktsk (MVE_BAD_SP);
15891 else if (inst.operands[2].reg == REG_PC)
15892 first_error (BAD_PC);
15893
15894 rs = neon_select_shape (NS_QRRI, NS_NULL);
15895 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
15896 Rm = inst.operands[2].reg >> 1;
15897 }
15898 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15899 inst.instruction |= neon_logbits (et.size) << 20;
15900 inst.instruction |= inst.operands[1].reg << 16;
15901 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15902 inst.instruction |= (imm > 2) << 7;
15903 inst.instruction |= Rm << 1;
15904 inst.instruction |= (imm == 2 || imm == 8);
15905 inst.is_neon = 1;
15906}
15907
2d78f95b
AV
15908static void
15909do_mve_vmlas (void)
15910{
15911 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15912 struct neon_type_el et
15913 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
15914
15915 if (inst.operands[2].reg == REG_PC)
15916 as_tsktsk (MVE_BAD_PC);
15917 else if (inst.operands[2].reg == REG_SP)
15918 as_tsktsk (MVE_BAD_SP);
15919
15920 if (inst.cond > COND_ALWAYS)
15921 inst.pred_insn_type = INSIDE_VPT_INSN;
15922 else
15923 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15924
15925 inst.instruction |= (et.type == NT_unsigned) << 28;
15926 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15927 inst.instruction |= neon_logbits (et.size) << 20;
15928 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15929 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15930 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15931 inst.instruction |= inst.operands[2].reg;
15932 inst.is_neon = 1;
15933}
15934
acca5630
AV
15935static void
15936do_mve_vshll (void)
15937{
15938 struct neon_type_el et
15939 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
15940
15941 if (inst.cond > COND_ALWAYS)
15942 inst.pred_insn_type = INSIDE_VPT_INSN;
15943 else
15944 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15945
15946 int imm = inst.operands[2].imm;
15947 constraint (imm < 1 || (unsigned)imm > et.size,
15948 _("immediate value out of range"));
15949
15950 if ((unsigned)imm == et.size)
15951 {
15952 inst.instruction |= neon_logbits (et.size) << 18;
15953 inst.instruction |= 0x110001;
15954 }
15955 else
15956 {
15957 inst.instruction |= (et.size + imm) << 16;
15958 inst.instruction |= 0x800140;
15959 }
15960
15961 inst.instruction |= (et.type == NT_unsigned) << 28;
15962 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15964 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15965 inst.instruction |= LOW4 (inst.operands[1].reg);
15966 inst.is_neon = 1;
15967}
15968
15969static void
15970do_mve_vshlc (void)
15971{
15972 if (inst.cond > COND_ALWAYS)
15973 inst.pred_insn_type = INSIDE_VPT_INSN;
15974 else
15975 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15976
15977 if (inst.operands[1].reg == REG_PC)
15978 as_tsktsk (MVE_BAD_PC);
15979 else if (inst.operands[1].reg == REG_SP)
15980 as_tsktsk (MVE_BAD_SP);
15981
15982 int imm = inst.operands[2].imm;
15983 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
15984
15985 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15986 inst.instruction |= (imm & 0x1f) << 16;
15987 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15988 inst.instruction |= inst.operands[1].reg;
15989 inst.is_neon = 1;
15990}
15991
4aa88b50
AV
15992static void
15993do_mve_vshrn (void)
15994{
15995 unsigned types;
15996 switch (inst.instruction)
15997 {
15998 case M_MNEM_vshrnt:
15999 case M_MNEM_vshrnb:
16000 case M_MNEM_vrshrnt:
16001 case M_MNEM_vrshrnb:
16002 types = N_I16 | N_I32;
16003 break;
16004 case M_MNEM_vqshrnt:
16005 case M_MNEM_vqshrnb:
16006 case M_MNEM_vqrshrnt:
16007 case M_MNEM_vqrshrnb:
16008 types = N_U16 | N_U32 | N_S16 | N_S32;
16009 break;
16010 case M_MNEM_vqshrunt:
16011 case M_MNEM_vqshrunb:
16012 case M_MNEM_vqrshrunt:
16013 case M_MNEM_vqrshrunb:
16014 types = N_S16 | N_S32;
16015 break;
16016 default:
16017 abort ();
16018 }
16019
16020 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16021
16022 if (inst.cond > COND_ALWAYS)
16023 inst.pred_insn_type = INSIDE_VPT_INSN;
16024 else
16025 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16026
16027 unsigned Qd = inst.operands[0].reg;
16028 unsigned Qm = inst.operands[1].reg;
16029 unsigned imm = inst.operands[2].imm;
16030 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16031 et.size == 16
16032 ? _("immediate operand expected in the range [1,8]")
16033 : _("immediate operand expected in the range [1,16]"));
16034
16035 inst.instruction |= (et.type == NT_unsigned) << 28;
16036 inst.instruction |= HI1 (Qd) << 22;
16037 inst.instruction |= (et.size - imm) << 16;
16038 inst.instruction |= LOW4 (Qd) << 12;
16039 inst.instruction |= HI1 (Qm) << 5;
16040 inst.instruction |= LOW4 (Qm);
16041 inst.is_neon = 1;
16042}
16043
1be7aba3
AV
16044static void
16045do_mve_vqmovn (void)
16046{
16047 struct neon_type_el et;
16048 if (inst.instruction == M_MNEM_vqmovnt
16049 || inst.instruction == M_MNEM_vqmovnb)
16050 et = neon_check_type (2, NS_QQ, N_EQK,
16051 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16052 else
16053 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16054
16055 if (inst.cond > COND_ALWAYS)
16056 inst.pred_insn_type = INSIDE_VPT_INSN;
16057 else
16058 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16059
16060 inst.instruction |= (et.type == NT_unsigned) << 28;
16061 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16062 inst.instruction |= (et.size == 32) << 18;
16063 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16064 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16065 inst.instruction |= LOW4 (inst.operands[1].reg);
16066 inst.is_neon = 1;
16067}
16068
3063888e
AV
16069static void
16070do_mve_vpsel (void)
16071{
16072 neon_select_shape (NS_QQQ, NS_NULL);
16073
16074 if (inst.cond > COND_ALWAYS)
16075 inst.pred_insn_type = INSIDE_VPT_INSN;
16076 else
16077 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16078
16079 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16080 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16081 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16082 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16083 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16084 inst.instruction |= LOW4 (inst.operands[2].reg);
16085 inst.is_neon = 1;
16086}
16087
16088static void
16089do_mve_vpnot (void)
16090{
16091 if (inst.cond > COND_ALWAYS)
16092 inst.pred_insn_type = INSIDE_VPT_INSN;
16093 else
16094 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16095}
16096
935295b5
AV
16097static void
16098do_mve_vmaxnma_vminnma (void)
16099{
16100 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16101 struct neon_type_el et
16102 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16103
16104 if (inst.cond > COND_ALWAYS)
16105 inst.pred_insn_type = INSIDE_VPT_INSN;
16106 else
16107 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16108
16109 inst.instruction |= (et.size == 16) << 28;
16110 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16111 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16112 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16113 inst.instruction |= LOW4 (inst.operands[1].reg);
16114 inst.is_neon = 1;
16115}
16116
5d281bf0
AV
16117static void
16118do_mve_vcmul (void)
16119{
16120 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16121 struct neon_type_el et
16122 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16123
16124 if (inst.cond > COND_ALWAYS)
16125 inst.pred_insn_type = INSIDE_VPT_INSN;
16126 else
16127 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16128
16129 unsigned rot = inst.relocs[0].exp.X_add_number;
16130 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16131 _("immediate out of range"));
16132
16133 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16134 || inst.operands[0].reg == inst.operands[2].reg))
16135 as_tsktsk (BAD_MVE_SRCDEST);
16136
16137 inst.instruction |= (et.size == 32) << 28;
16138 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16139 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16140 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16141 inst.instruction |= (rot > 90) << 12;
16142 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16143 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16144 inst.instruction |= LOW4 (inst.operands[2].reg);
16145 inst.instruction |= (rot == 90 || rot == 270);
16146 inst.is_neon = 1;
16147}
16148
1f6234a3
AV
16149/* To handle the Low Overhead Loop instructions
16150 in Armv8.1-M Mainline and MVE. */
16151static void
16152do_t_loloop (void)
16153{
16154 unsigned long insn = inst.instruction;
16155
16156 inst.instruction = THUMB_OP32 (inst.instruction);
16157
16158 if (insn == T_MNEM_lctp)
16159 return;
16160
16161 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16162
16163 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16164 {
16165 struct neon_type_el et
16166 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16167 inst.instruction |= neon_logbits (et.size) << 20;
16168 inst.is_neon = 1;
16169 }
16170
16171 switch (insn)
16172 {
16173 case T_MNEM_letp:
16174 constraint (!inst.operands[0].present,
16175 _("expected LR"));
16176 /* fall through. */
16177 case T_MNEM_le:
16178 /* le <label>. */
16179 if (!inst.operands[0].present)
16180 inst.instruction |= 1 << 21;
16181
16182 v8_1_loop_reloc (TRUE);
16183 break;
16184
16185 case T_MNEM_wls:
16186 case T_MNEM_wlstp:
16187 v8_1_loop_reloc (FALSE);
16188 /* fall through. */
16189 case T_MNEM_dlstp:
16190 case T_MNEM_dls:
16191 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16192
16193 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16194 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16195 else if (inst.operands[1].reg == REG_PC)
16196 as_tsktsk (MVE_BAD_PC);
16197 if (inst.operands[1].reg == REG_SP)
16198 as_tsktsk (MVE_BAD_SP);
16199
16200 inst.instruction |= (inst.operands[1].reg << 16);
16201 break;
16202
16203 default:
16204 abort ();
16205 }
16206}
16207
16208
037e8744
JB
16209static void
16210do_vfp_nsyn_cmp (void)
16211{
9db2f6b4 16212 enum neon_shape rs;
1b883319
AV
16213 if (!inst.operands[0].isreg)
16214 {
16215 do_mve_vcmp ();
16216 return;
16217 }
16218 else
16219 {
16220 constraint (inst.operands[2].present, BAD_SYNTAX);
16221 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16222 BAD_FPU);
16223 }
16224
037e8744
JB
16225 if (inst.operands[1].isreg)
16226 {
9db2f6b4
RL
16227 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16228 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16229
9db2f6b4 16230 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16231 {
16232 NEON_ENCODE (SINGLE, inst);
16233 do_vfp_sp_monadic ();
16234 }
037e8744 16235 else
477330fc
RM
16236 {
16237 NEON_ENCODE (DOUBLE, inst);
16238 do_vfp_dp_rd_rm ();
16239 }
037e8744
JB
16240 }
16241 else
16242 {
9db2f6b4
RL
16243 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16244 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16245
16246 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16247 {
16248 case N_MNEM_vcmp:
16249 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16250 break;
16251 case N_MNEM_vcmpe:
16252 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16253 break;
16254 default:
16255 abort ();
16256 }
5f4273c7 16257
9db2f6b4 16258 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16259 {
16260 NEON_ENCODE (SINGLE, inst);
16261 do_vfp_sp_compare_z ();
16262 }
037e8744 16263 else
477330fc
RM
16264 {
16265 NEON_ENCODE (DOUBLE, inst);
16266 do_vfp_dp_rd ();
16267 }
037e8744
JB
16268 }
16269 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16270
16271 /* ARMv8.2 fp16 instruction. */
16272 if (rs == NS_HI || rs == NS_HH)
16273 do_scalar_fp16_v82_encode ();
037e8744
JB
16274}
16275
16276static void
16277nsyn_insert_sp (void)
16278{
16279 inst.operands[1] = inst.operands[0];
16280 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16281 inst.operands[0].reg = REG_SP;
037e8744
JB
16282 inst.operands[0].isreg = 1;
16283 inst.operands[0].writeback = 1;
16284 inst.operands[0].present = 1;
16285}
16286
16287static void
16288do_vfp_nsyn_push (void)
16289{
16290 nsyn_insert_sp ();
b126985e
NC
16291
16292 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16293 _("register list must contain at least 1 and at most 16 "
16294 "registers"));
16295
037e8744
JB
16296 if (inst.operands[1].issingle)
16297 do_vfp_nsyn_opcode ("fstmdbs");
16298 else
16299 do_vfp_nsyn_opcode ("fstmdbd");
16300}
16301
16302static void
16303do_vfp_nsyn_pop (void)
16304{
16305 nsyn_insert_sp ();
b126985e
NC
16306
16307 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16308 _("register list must contain at least 1 and at most 16 "
16309 "registers"));
16310
037e8744 16311 if (inst.operands[1].issingle)
22b5b651 16312 do_vfp_nsyn_opcode ("fldmias");
037e8744 16313 else
22b5b651 16314 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
16315}
16316
16317/* Fix up Neon data-processing instructions, ORing in the correct bits for
16318 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16319
88714cb8
DG
16320static void
16321neon_dp_fixup (struct arm_it* insn)
037e8744 16322{
88714cb8
DG
16323 unsigned int i = insn->instruction;
16324 insn->is_neon = 1;
16325
037e8744
JB
16326 if (thumb_mode)
16327 {
16328 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16329 if (i & (1 << 24))
477330fc 16330 i |= 1 << 28;
5f4273c7 16331
037e8744 16332 i &= ~(1 << 24);
5f4273c7 16333
037e8744
JB
16334 i |= 0xef000000;
16335 }
16336 else
16337 i |= 0xf2000000;
5f4273c7 16338
88714cb8 16339 insn->instruction = i;
037e8744
JB
16340}
16341
5ee91343 16342static void
7df54120 16343mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16344{
16345 if (inst.operands[2].reg == REG_SP)
16346 as_tsktsk (MVE_BAD_SP);
16347 else if (inst.operands[2].reg == REG_PC)
16348 as_tsktsk (MVE_BAD_PC);
16349
16350 if (fp)
16351 {
16352 /* vadd. */
16353 if (((unsigned)inst.instruction) == 0xd00)
16354 inst.instruction = 0xee300f40;
16355 /* vsub. */
16356 else if (((unsigned)inst.instruction) == 0x200d00)
16357 inst.instruction = 0xee301f40;
a8465a06
AV
16358 /* vmul. */
16359 else if (((unsigned)inst.instruction) == 0x1000d10)
16360 inst.instruction = 0xee310e60;
5ee91343
AV
16361
16362 /* Setting size which is 1 for F16 and 0 for F32. */
16363 inst.instruction |= (size == 16) << 28;
16364 }
16365 else
16366 {
16367 /* vadd. */
16368 if (((unsigned)inst.instruction) == 0x800)
16369 inst.instruction = 0xee010f40;
16370 /* vsub. */
16371 else if (((unsigned)inst.instruction) == 0x1000800)
16372 inst.instruction = 0xee011f40;
7df54120
AV
16373 /* vhadd. */
16374 else if (((unsigned)inst.instruction) == 0)
16375 inst.instruction = 0xee000f40;
16376 /* vhsub. */
16377 else if (((unsigned)inst.instruction) == 0x200)
16378 inst.instruction = 0xee001f40;
a8465a06
AV
16379 /* vmla. */
16380 else if (((unsigned)inst.instruction) == 0x900)
16381 inst.instruction = 0xee010e40;
16382 /* vmul. */
16383 else if (((unsigned)inst.instruction) == 0x910)
16384 inst.instruction = 0xee011e60;
16385 /* vqadd. */
16386 else if (((unsigned)inst.instruction) == 0x10)
16387 inst.instruction = 0xee000f60;
16388 /* vqsub. */
16389 else if (((unsigned)inst.instruction) == 0x210)
16390 inst.instruction = 0xee001f60;
42b16635
AV
16391 /* vqrdmlah. */
16392 else if (((unsigned)inst.instruction) == 0x3000b10)
16393 inst.instruction = 0xee000e40;
16394 /* vqdmulh. */
16395 else if (((unsigned)inst.instruction) == 0x0000b00)
16396 inst.instruction = 0xee010e60;
16397 /* vqrdmulh. */
16398 else if (((unsigned)inst.instruction) == 0x1000b00)
16399 inst.instruction = 0xfe010e60;
7df54120
AV
16400
16401 /* Set U-bit. */
16402 inst.instruction |= U << 28;
16403
5ee91343
AV
16404 /* Setting bits for size. */
16405 inst.instruction |= neon_logbits (size) << 20;
16406 }
16407 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16408 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16409 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16410 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16411 inst.instruction |= inst.operands[2].reg;
16412 inst.is_neon = 1;
16413}
16414
a302e574
AV
16415static void
16416mve_encode_rqq (unsigned bit28, unsigned size)
16417{
16418 inst.instruction |= bit28 << 28;
16419 inst.instruction |= neon_logbits (size) << 20;
16420 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16421 inst.instruction |= inst.operands[0].reg << 12;
16422 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16423 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16424 inst.instruction |= LOW4 (inst.operands[2].reg);
16425 inst.is_neon = 1;
16426}
16427
886e1c73
AV
16428static void
16429mve_encode_qqq (int ubit, int size)
16430{
16431
16432 inst.instruction |= (ubit != 0) << 28;
16433 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16434 inst.instruction |= neon_logbits (size) << 20;
16435 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16436 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16437 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16438 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16439 inst.instruction |= LOW4 (inst.operands[2].reg);
16440
16441 inst.is_neon = 1;
16442}
16443
26c1e780
AV
16444static void
16445mve_encode_rq (unsigned bit28, unsigned size)
16446{
16447 inst.instruction |= bit28 << 28;
16448 inst.instruction |= neon_logbits (size) << 18;
16449 inst.instruction |= inst.operands[0].reg << 12;
16450 inst.instruction |= LOW4 (inst.operands[1].reg);
16451 inst.is_neon = 1;
16452}
886e1c73 16453
93925576
AV
16454static void
16455mve_encode_rrqq (unsigned U, unsigned size)
16456{
16457 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16458
16459 inst.instruction |= U << 28;
16460 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16461 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16462 inst.instruction |= (size == 32) << 16;
16463 inst.instruction |= inst.operands[0].reg << 12;
16464 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16465 inst.instruction |= inst.operands[3].reg;
16466 inst.is_neon = 1;
16467}
16468
037e8744
JB
16469/* Encode insns with bit pattern:
16470
16471 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16472 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16473
037e8744
JB
16474 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16475 different meaning for some instruction. */
16476
16477static void
16478neon_three_same (int isquad, int ubit, int size)
16479{
16480 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16481 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16482 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16483 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16484 inst.instruction |= LOW4 (inst.operands[2].reg);
16485 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16486 inst.instruction |= (isquad != 0) << 6;
16487 inst.instruction |= (ubit != 0) << 24;
16488 if (size != -1)
16489 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16490
88714cb8 16491 neon_dp_fixup (&inst);
037e8744
JB
16492}
16493
16494/* Encode instructions of the form:
16495
16496 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16497 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16498
16499 Don't write size if SIZE == -1. */
16500
16501static void
16502neon_two_same (int qbit, int ubit, int size)
16503{
16504 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16505 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16506 inst.instruction |= LOW4 (inst.operands[1].reg);
16507 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16508 inst.instruction |= (qbit != 0) << 6;
16509 inst.instruction |= (ubit != 0) << 24;
16510
16511 if (size != -1)
16512 inst.instruction |= neon_logbits (size) << 18;
16513
88714cb8 16514 neon_dp_fixup (&inst);
5287ad62
JB
16515}
16516
7df54120
AV
16517enum vfp_or_neon_is_neon_bits
16518{
16519NEON_CHECK_CC = 1,
16520NEON_CHECK_ARCH = 2,
16521NEON_CHECK_ARCH8 = 4
16522};
16523
16524/* Call this function if an instruction which may have belonged to the VFP or
16525 Neon instruction sets, but turned out to be a Neon instruction (due to the
16526 operand types involved, etc.). We have to check and/or fix-up a couple of
16527 things:
16528
16529 - Make sure the user hasn't attempted to make a Neon instruction
16530 conditional.
16531 - Alter the value in the condition code field if necessary.
16532 - Make sure that the arch supports Neon instructions.
16533
16534 Which of these operations take place depends on bits from enum
16535 vfp_or_neon_is_neon_bits.
16536
16537 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16538 current instruction's condition is COND_ALWAYS, the condition field is
16539 changed to inst.uncond_value. This is necessary because instructions shared
16540 between VFP and Neon may be conditional for the VFP variants only, and the
16541 unconditional Neon version must have, e.g., 0xF in the condition field. */
16542
16543static int
16544vfp_or_neon_is_neon (unsigned check)
16545{
16546/* Conditions are always legal in Thumb mode (IT blocks). */
16547if (!thumb_mode && (check & NEON_CHECK_CC))
16548 {
16549 if (inst.cond != COND_ALWAYS)
16550 {
16551 first_error (_(BAD_COND));
16552 return FAIL;
16553 }
16554 if (inst.uncond_value != -1)
16555 inst.instruction |= inst.uncond_value << 28;
16556 }
16557
16558
16559 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16560 || ((check & NEON_CHECK_ARCH8)
16561 && !mark_feature_used (&fpu_neon_ext_armv8)))
16562 {
16563 first_error (_(BAD_FPU));
16564 return FAIL;
16565 }
16566
16567return SUCCESS;
16568}
16569
64c350f2
AV
16570
16571/* Return TRUE if the SIMD instruction is available for the current
16572 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16573 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16574 vfp_or_neon_is_neon for the NEON specific checks. */
16575
16576static bfd_boolean
7df54120
AV
16577check_simd_pred_availability (int fp, unsigned check)
16578{
16579if (inst.cond > COND_ALWAYS)
16580 {
16581 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16582 {
16583 inst.error = BAD_FPU;
64c350f2 16584 return FALSE;
7df54120
AV
16585 }
16586 inst.pred_insn_type = INSIDE_VPT_INSN;
16587 }
16588else if (inst.cond < COND_ALWAYS)
16589 {
16590 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16591 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16592 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16593 return FALSE;
7df54120
AV
16594 }
16595else
16596 {
16597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16598 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16599 return FALSE;
7df54120
AV
16600
16601 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16602 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16603 }
64c350f2 16604return TRUE;
7df54120
AV
16605}
16606
5287ad62
JB
16607/* Neon instruction encoders, in approximate order of appearance. */
16608
16609static void
16610do_neon_dyadic_i_su (void)
16611{
64c350f2 16612 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16613 return;
16614
16615 enum neon_shape rs;
16616 struct neon_type_el et;
16617 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16618 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16619 else
16620 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16621
16622 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16623
16624
16625 if (rs != NS_QQR)
16626 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16627 else
16628 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16629}
16630
16631static void
16632do_neon_dyadic_i64_su (void)
16633{
64c350f2 16634 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16635 return;
16636 enum neon_shape rs;
16637 struct neon_type_el et;
16638 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16639 {
16640 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16641 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16642 }
16643 else
16644 {
16645 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16646 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16647 }
16648 if (rs == NS_QQR)
16649 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16650 else
16651 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16652}
16653
16654static void
16655neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16656 unsigned immbits)
5287ad62
JB
16657{
16658 unsigned size = et.size >> 3;
16659 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16660 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16661 inst.instruction |= LOW4 (inst.operands[1].reg);
16662 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16663 inst.instruction |= (isquad != 0) << 6;
16664 inst.instruction |= immbits << 16;
16665 inst.instruction |= (size >> 3) << 7;
16666 inst.instruction |= (size & 0x7) << 19;
16667 if (write_ubit)
16668 inst.instruction |= (uval != 0) << 24;
16669
88714cb8 16670 neon_dp_fixup (&inst);
5287ad62
JB
16671}
16672
16673static void
5150f0d8 16674do_neon_shl (void)
5287ad62 16675{
64c350f2 16676 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16677 return;
16678
5287ad62
JB
16679 if (!inst.operands[2].isreg)
16680 {
5150f0d8
AV
16681 enum neon_shape rs;
16682 struct neon_type_el et;
16683 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16684 {
16685 rs = neon_select_shape (NS_QQI, NS_NULL);
16686 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16687 }
16688 else
16689 {
16690 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16691 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16692 }
cb3b1e65
JB
16693 int imm = inst.operands[2].imm;
16694
16695 constraint (imm < 0 || (unsigned)imm >= et.size,
16696 _("immediate out of range for shift"));
88714cb8 16697 NEON_ENCODE (IMMED, inst);
cb3b1e65 16698 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16699 }
16700 else
16701 {
5150f0d8
AV
16702 enum neon_shape rs;
16703 struct neon_type_el et;
16704 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16705 {
16706 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16707 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16708 }
16709 else
16710 {
16711 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16712 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16713 }
16714
16715
16716 if (rs == NS_QQR)
16717 {
16718 constraint (inst.operands[0].reg != inst.operands[1].reg,
16719 _("invalid instruction shape"));
16720 if (inst.operands[2].reg == REG_SP)
16721 as_tsktsk (MVE_BAD_SP);
16722 else if (inst.operands[2].reg == REG_PC)
16723 as_tsktsk (MVE_BAD_PC);
16724
16725 inst.instruction = 0xee311e60;
16726 inst.instruction |= (et.type == NT_unsigned) << 28;
16727 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16728 inst.instruction |= neon_logbits (et.size) << 18;
16729 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16730 inst.instruction |= inst.operands[2].reg;
16731 inst.is_neon = 1;
16732 }
16733 else
16734 {
16735 unsigned int tmp;
16736
16737 /* VSHL/VQSHL 3-register variants have syntax such as:
16738 vshl.xx Dd, Dm, Dn
16739 whereas other 3-register operations encoded by neon_three_same have
16740 syntax like:
16741 vadd.xx Dd, Dn, Dm
16742 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
16743 operands[2].reg here. */
16744 tmp = inst.operands[2].reg;
16745 inst.operands[2].reg = inst.operands[1].reg;
16746 inst.operands[1].reg = tmp;
16747 NEON_ENCODE (INTEGER, inst);
16748 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16749 }
5287ad62
JB
16750 }
16751}
16752
16753static void
5150f0d8 16754do_neon_qshl (void)
5287ad62 16755{
64c350f2 16756 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16757 return;
16758
5287ad62
JB
16759 if (!inst.operands[2].isreg)
16760 {
5150f0d8
AV
16761 enum neon_shape rs;
16762 struct neon_type_el et;
16763 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16764 {
16765 rs = neon_select_shape (NS_QQI, NS_NULL);
16766 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
16767 }
16768 else
16769 {
16770 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16771 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16772 }
cb3b1e65 16773 int imm = inst.operands[2].imm;
627907b7 16774
cb3b1e65
JB
16775 constraint (imm < 0 || (unsigned)imm >= et.size,
16776 _("immediate out of range for shift"));
88714cb8 16777 NEON_ENCODE (IMMED, inst);
cb3b1e65 16778 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
16779 }
16780 else
16781 {
5150f0d8
AV
16782 enum neon_shape rs;
16783 struct neon_type_el et;
627907b7 16784
5150f0d8
AV
16785 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16786 {
16787 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16788 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16789 }
16790 else
16791 {
16792 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16793 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16794 }
16795
16796 if (rs == NS_QQR)
16797 {
16798 constraint (inst.operands[0].reg != inst.operands[1].reg,
16799 _("invalid instruction shape"));
16800 if (inst.operands[2].reg == REG_SP)
16801 as_tsktsk (MVE_BAD_SP);
16802 else if (inst.operands[2].reg == REG_PC)
16803 as_tsktsk (MVE_BAD_PC);
16804
16805 inst.instruction = 0xee311ee0;
16806 inst.instruction |= (et.type == NT_unsigned) << 28;
16807 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16808 inst.instruction |= neon_logbits (et.size) << 18;
16809 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16810 inst.instruction |= inst.operands[2].reg;
16811 inst.is_neon = 1;
16812 }
16813 else
16814 {
16815 unsigned int tmp;
16816
16817 /* See note in do_neon_shl. */
16818 tmp = inst.operands[2].reg;
16819 inst.operands[2].reg = inst.operands[1].reg;
16820 inst.operands[1].reg = tmp;
16821 NEON_ENCODE (INTEGER, inst);
16822 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16823 }
5287ad62
JB
16824 }
16825}
16826
627907b7
JB
16827static void
16828do_neon_rshl (void)
16829{
64c350f2 16830 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
16831 return;
16832
16833 enum neon_shape rs;
16834 struct neon_type_el et;
16835 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16836 {
16837 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16838 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16839 }
16840 else
16841 {
16842 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16843 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16844 }
16845
627907b7
JB
16846 unsigned int tmp;
16847
1be7aba3
AV
16848 if (rs == NS_QQR)
16849 {
16850 if (inst.operands[2].reg == REG_PC)
16851 as_tsktsk (MVE_BAD_PC);
16852 else if (inst.operands[2].reg == REG_SP)
16853 as_tsktsk (MVE_BAD_SP);
16854
16855 constraint (inst.operands[0].reg != inst.operands[1].reg,
16856 _("invalid instruction shape"));
16857
16858 if (inst.instruction == 0x0000510)
16859 /* We are dealing with vqrshl. */
16860 inst.instruction = 0xee331ee0;
16861 else
16862 /* We are dealing with vrshl. */
16863 inst.instruction = 0xee331e60;
16864
16865 inst.instruction |= (et.type == NT_unsigned) << 28;
16866 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16867 inst.instruction |= neon_logbits (et.size) << 18;
16868 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16869 inst.instruction |= inst.operands[2].reg;
16870 inst.is_neon = 1;
16871 }
16872 else
16873 {
16874 tmp = inst.operands[2].reg;
16875 inst.operands[2].reg = inst.operands[1].reg;
16876 inst.operands[1].reg = tmp;
16877 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16878 }
627907b7
JB
16879}
16880
5287ad62
JB
16881static int
16882neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
16883{
036dc3f7
PB
16884 /* Handle .I8 pseudo-instructions. */
16885 if (size == 8)
5287ad62 16886 {
5287ad62 16887 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
16888 FIXME is this the intended semantics? There doesn't seem much point in
16889 accepting .I8 if so. */
5287ad62
JB
16890 immediate |= immediate << 8;
16891 size = 16;
036dc3f7
PB
16892 }
16893
16894 if (size >= 32)
16895 {
16896 if (immediate == (immediate & 0x000000ff))
16897 {
16898 *immbits = immediate;
16899 return 0x1;
16900 }
16901 else if (immediate == (immediate & 0x0000ff00))
16902 {
16903 *immbits = immediate >> 8;
16904 return 0x3;
16905 }
16906 else if (immediate == (immediate & 0x00ff0000))
16907 {
16908 *immbits = immediate >> 16;
16909 return 0x5;
16910 }
16911 else if (immediate == (immediate & 0xff000000))
16912 {
16913 *immbits = immediate >> 24;
16914 return 0x7;
16915 }
16916 if ((immediate & 0xffff) != (immediate >> 16))
16917 goto bad_immediate;
16918 immediate &= 0xffff;
5287ad62
JB
16919 }
16920
16921 if (immediate == (immediate & 0x000000ff))
16922 {
16923 *immbits = immediate;
036dc3f7 16924 return 0x9;
5287ad62
JB
16925 }
16926 else if (immediate == (immediate & 0x0000ff00))
16927 {
16928 *immbits = immediate >> 8;
036dc3f7 16929 return 0xb;
5287ad62
JB
16930 }
16931
16932 bad_immediate:
dcbf9037 16933 first_error (_("immediate value out of range"));
5287ad62
JB
16934 return FAIL;
16935}
16936
5287ad62
JB
16937static void
16938do_neon_logic (void)
16939{
16940 if (inst.operands[2].present && inst.operands[2].isreg)
16941 {
037e8744 16942 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 16943 if (rs == NS_QQQ
64c350f2
AV
16944 && !check_simd_pred_availability (FALSE,
16945 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
16946 return;
16947 else if (rs != NS_QQQ
16948 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
16949 first_error (BAD_FPU);
16950
5287ad62
JB
16951 neon_check_type (3, rs, N_IGNORE_TYPE);
16952 /* U bit and size field were set as part of the bitmask. */
88714cb8 16953 NEON_ENCODE (INTEGER, inst);
037e8744 16954 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
16955 }
16956 else
16957 {
4316f0d2
DG
16958 const int three_ops_form = (inst.operands[2].present
16959 && !inst.operands[2].isreg);
16960 const int immoperand = (three_ops_form ? 2 : 1);
16961 enum neon_shape rs = (three_ops_form
16962 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
16963 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
16964 /* Because neon_select_shape makes the second operand a copy of the first
16965 if the second operand is not present. */
16966 if (rs == NS_QQI
64c350f2
AV
16967 && !check_simd_pred_availability (FALSE,
16968 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
16969 return;
16970 else if (rs != NS_QQI
16971 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
16972 first_error (BAD_FPU);
16973
16974 struct neon_type_el et;
16975 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16976 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
16977 else
16978 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
16979 | N_KEY, N_EQK);
16980
16981 if (et.type == NT_invtype)
16982 return;
21d799b5 16983 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
16984 unsigned immbits;
16985 int cmode;
5f4273c7 16986
5f4273c7 16987
4316f0d2
DG
16988 if (three_ops_form)
16989 constraint (inst.operands[0].reg != inst.operands[1].reg,
16990 _("first and second operands shall be the same register"));
16991
88714cb8 16992 NEON_ENCODE (IMMED, inst);
5287ad62 16993
4316f0d2 16994 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
16995 if (et.size == 64)
16996 {
16997 /* .i64 is a pseudo-op, so the immediate must be a repeating
16998 pattern. */
4316f0d2
DG
16999 if (immbits != (inst.operands[immoperand].regisimm ?
17000 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17001 {
17002 /* Set immbits to an invalid constant. */
17003 immbits = 0xdeadbeef;
17004 }
17005 }
17006
5287ad62 17007 switch (opcode)
477330fc
RM
17008 {
17009 case N_MNEM_vbic:
17010 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17011 break;
17012
17013 case N_MNEM_vorr:
17014 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17015 break;
17016
17017 case N_MNEM_vand:
17018 /* Pseudo-instruction for VBIC. */
17019 neon_invert_size (&immbits, 0, et.size);
17020 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17021 break;
17022
17023 case N_MNEM_vorn:
17024 /* Pseudo-instruction for VORR. */
17025 neon_invert_size (&immbits, 0, et.size);
17026 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17027 break;
17028
17029 default:
17030 abort ();
17031 }
5287ad62
JB
17032
17033 if (cmode == FAIL)
477330fc 17034 return;
5287ad62 17035
037e8744 17036 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17037 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17038 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17039 inst.instruction |= cmode << 8;
17040 neon_write_immbits (immbits);
5f4273c7 17041
88714cb8 17042 neon_dp_fixup (&inst);
5287ad62
JB
17043 }
17044}
17045
17046static void
17047do_neon_bitfield (void)
17048{
037e8744 17049 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17050 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17051 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17052}
17053
17054static void
dcbf9037 17055neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17056 unsigned destbits)
5287ad62 17057{
5ee91343 17058 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17059 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17060 types | N_KEY);
5287ad62
JB
17061 if (et.type == NT_float)
17062 {
88714cb8 17063 NEON_ENCODE (FLOAT, inst);
5ee91343 17064 if (rs == NS_QQR)
7df54120 17065 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17066 else
17067 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17068 }
17069 else
17070 {
88714cb8 17071 NEON_ENCODE (INTEGER, inst);
5ee91343 17072 if (rs == NS_QQR)
a8465a06 17073 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17074 else
17075 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17076 }
17077}
17078
5287ad62
JB
17079
17080static void
17081do_neon_dyadic_if_su_d (void)
17082{
17083 /* This version only allow D registers, but that constraint is enforced during
17084 operand parsing so we don't need to do anything extra here. */
dcbf9037 17085 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17086}
17087
5287ad62
JB
17088static void
17089do_neon_dyadic_if_i_d (void)
17090{
428e3f1f
PB
17091 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17092 affected if we specify unsigned args. */
17093 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17094}
17095
f5f10c66
AV
17096static void
17097do_mve_vstr_vldr_QI (int size, int elsize, int load)
17098{
17099 constraint (size < 32, BAD_ADDR_MODE);
17100 constraint (size != elsize, BAD_EL_TYPE);
17101 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17102 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17103 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17104 _("destination register and offset register may not be the"
17105 " same"));
17106
17107 int imm = inst.relocs[0].exp.X_add_number;
17108 int add = 1;
17109 if (imm < 0)
17110 {
17111 add = 0;
17112 imm = -imm;
17113 }
17114 constraint ((imm % (size / 8) != 0)
17115 || imm > (0x7f << neon_logbits (size)),
17116 (size == 32) ? _("immediate must be a multiple of 4 in the"
17117 " range of +/-[0,508]")
17118 : _("immediate must be a multiple of 8 in the"
17119 " range of +/-[0,1016]"));
17120 inst.instruction |= 0x11 << 24;
17121 inst.instruction |= add << 23;
17122 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17123 inst.instruction |= inst.operands[1].writeback << 21;
17124 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17125 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17126 inst.instruction |= 1 << 12;
17127 inst.instruction |= (size == 64) << 8;
17128 inst.instruction &= 0xffffff00;
17129 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17130 inst.instruction |= imm >> neon_logbits (size);
17131}
17132
17133static void
17134do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17135{
17136 unsigned os = inst.operands[1].imm >> 5;
17137 constraint (os != 0 && size == 8,
17138 _("can not shift offsets when accessing less than half-word"));
17139 constraint (os && os != neon_logbits (size),
17140 _("shift immediate must be 1, 2 or 3 for half-word, word"
17141 " or double-word accesses respectively"));
17142 if (inst.operands[1].reg == REG_PC)
17143 as_tsktsk (MVE_BAD_PC);
17144
17145 switch (size)
17146 {
17147 case 8:
17148 constraint (elsize >= 64, BAD_EL_TYPE);
17149 break;
17150 case 16:
17151 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17152 break;
17153 case 32:
17154 case 64:
17155 constraint (elsize != size, BAD_EL_TYPE);
17156 break;
17157 default:
17158 break;
17159 }
17160 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17161 BAD_ADDR_MODE);
17162 if (load)
17163 {
17164 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17165 _("destination register and offset register may not be"
17166 " the same"));
17167 constraint (size == elsize && inst.vectype.el[0].type != NT_unsigned,
17168 BAD_EL_TYPE);
17169 constraint (inst.vectype.el[0].type != NT_unsigned
17170 && inst.vectype.el[0].type != NT_signed, BAD_EL_TYPE);
17171 inst.instruction |= (inst.vectype.el[0].type == NT_unsigned) << 28;
17172 }
17173 else
17174 {
17175 constraint (inst.vectype.el[0].type != NT_untyped, BAD_EL_TYPE);
17176 }
17177
17178 inst.instruction |= 1 << 23;
17179 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17180 inst.instruction |= inst.operands[1].reg << 16;
17181 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17182 inst.instruction |= neon_logbits (elsize) << 7;
17183 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17184 inst.instruction |= LOW4 (inst.operands[1].imm);
17185 inst.instruction |= !!os;
17186}
17187
17188static void
17189do_mve_vstr_vldr_RI (int size, int elsize, int load)
17190{
17191 enum neon_el_type type = inst.vectype.el[0].type;
17192
17193 constraint (size >= 64, BAD_ADDR_MODE);
17194 switch (size)
17195 {
17196 case 16:
17197 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17198 break;
17199 case 32:
17200 constraint (elsize != size, BAD_EL_TYPE);
17201 break;
17202 default:
17203 break;
17204 }
17205 if (load)
17206 {
17207 constraint (elsize != size && type != NT_unsigned
17208 && type != NT_signed, BAD_EL_TYPE);
17209 }
17210 else
17211 {
17212 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17213 }
17214
17215 int imm = inst.relocs[0].exp.X_add_number;
17216 int add = 1;
17217 if (imm < 0)
17218 {
17219 add = 0;
17220 imm = -imm;
17221 }
17222
17223 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17224 {
17225 switch (size)
17226 {
17227 case 8:
17228 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17229 break;
17230 case 16:
17231 constraint (1, _("immediate must be a multiple of 2 in the"
17232 " range of +/-[0,254]"));
17233 break;
17234 case 32:
17235 constraint (1, _("immediate must be a multiple of 4 in the"
17236 " range of +/-[0,508]"));
17237 break;
17238 }
17239 }
17240
17241 if (size != elsize)
17242 {
17243 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17244 constraint (inst.operands[0].reg > 14,
17245 _("MVE vector register in the range [Q0..Q7] expected"));
17246 inst.instruction |= (load && type == NT_unsigned) << 28;
17247 inst.instruction |= (size == 16) << 19;
17248 inst.instruction |= neon_logbits (elsize) << 7;
17249 }
17250 else
17251 {
17252 if (inst.operands[1].reg == REG_PC)
17253 as_tsktsk (MVE_BAD_PC);
17254 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17255 as_tsktsk (MVE_BAD_SP);
17256 inst.instruction |= 1 << 12;
17257 inst.instruction |= neon_logbits (size) << 7;
17258 }
17259 inst.instruction |= inst.operands[1].preind << 24;
17260 inst.instruction |= add << 23;
17261 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17262 inst.instruction |= inst.operands[1].writeback << 21;
17263 inst.instruction |= inst.operands[1].reg << 16;
17264 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17265 inst.instruction &= 0xffffff80;
17266 inst.instruction |= imm >> neon_logbits (size);
17267
17268}
17269
17270static void
17271do_mve_vstr_vldr (void)
17272{
17273 unsigned size;
17274 int load = 0;
17275
17276 if (inst.cond > COND_ALWAYS)
17277 inst.pred_insn_type = INSIDE_VPT_INSN;
17278 else
17279 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17280
17281 switch (inst.instruction)
17282 {
17283 default:
17284 gas_assert (0);
17285 break;
17286 case M_MNEM_vldrb:
17287 load = 1;
17288 /* fall through. */
17289 case M_MNEM_vstrb:
17290 size = 8;
17291 break;
17292 case M_MNEM_vldrh:
17293 load = 1;
17294 /* fall through. */
17295 case M_MNEM_vstrh:
17296 size = 16;
17297 break;
17298 case M_MNEM_vldrw:
17299 load = 1;
17300 /* fall through. */
17301 case M_MNEM_vstrw:
17302 size = 32;
17303 break;
17304 case M_MNEM_vldrd:
17305 load = 1;
17306 /* fall through. */
17307 case M_MNEM_vstrd:
17308 size = 64;
17309 break;
17310 }
17311 unsigned elsize = inst.vectype.el[0].size;
17312
17313 if (inst.operands[1].isquad)
17314 {
17315 /* We are dealing with [Q, imm]{!} cases. */
17316 do_mve_vstr_vldr_QI (size, elsize, load);
17317 }
17318 else
17319 {
17320 if (inst.operands[1].immisreg == 2)
17321 {
17322 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17323 do_mve_vstr_vldr_RQ (size, elsize, load);
17324 }
17325 else if (!inst.operands[1].immisreg)
17326 {
17327 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17328 do_mve_vstr_vldr_RI (size, elsize, load);
17329 }
17330 else
17331 constraint (1, BAD_ADDR_MODE);
17332 }
17333
17334 inst.is_neon = 1;
17335}
17336
35c228db
AV
17337static void
17338do_mve_vst_vld (void)
17339{
17340 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17341 return;
17342
17343 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17344 || inst.relocs[0].exp.X_add_number != 0
17345 || inst.operands[1].immisreg != 0,
17346 BAD_ADDR_MODE);
17347 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17348 if (inst.operands[1].reg == REG_PC)
17349 as_tsktsk (MVE_BAD_PC);
17350 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17351 as_tsktsk (MVE_BAD_SP);
17352
17353
17354 /* These instructions are one of the "exceptions" mentioned in
17355 handle_pred_state. They are MVE instructions that are not VPT compatible
17356 and do not accept a VPT code, thus appending such a code is a syntax
17357 error. */
17358 if (inst.cond > COND_ALWAYS)
17359 first_error (BAD_SYNTAX);
17360 /* If we append a scalar condition code we can set this to
17361 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17362 else if (inst.cond < COND_ALWAYS)
17363 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17364 else
17365 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17366
17367 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17368 inst.instruction |= inst.operands[1].writeback << 21;
17369 inst.instruction |= inst.operands[1].reg << 16;
17370 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17371 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17372 inst.is_neon = 1;
17373}
17374
26c1e780
AV
17375static void
17376do_mve_vaddlv (void)
17377{
17378 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17379 struct neon_type_el et
17380 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17381
17382 if (et.type == NT_invtype)
17383 first_error (BAD_EL_TYPE);
17384
17385 if (inst.cond > COND_ALWAYS)
17386 inst.pred_insn_type = INSIDE_VPT_INSN;
17387 else
17388 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17389
17390 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17391
17392 inst.instruction |= (et.type == NT_unsigned) << 28;
17393 inst.instruction |= inst.operands[1].reg << 19;
17394 inst.instruction |= inst.operands[0].reg << 12;
17395 inst.instruction |= inst.operands[2].reg;
17396 inst.is_neon = 1;
17397}
17398
5287ad62 17399static void
5ee91343 17400do_neon_dyadic_if_su (void)
5287ad62 17401{
5ee91343
AV
17402 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17403 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17404 N_SUF_32 | N_KEY);
17405
935295b5
AV
17406 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17407 || inst.instruction == ((unsigned) N_MNEM_vmin))
17408 && et.type == NT_float
17409 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17410
64c350f2
AV
17411 if (!check_simd_pred_availability (et.type == NT_float,
17412 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17413 return;
17414
5ee91343
AV
17415 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17416}
17417
17418static void
17419do_neon_addsub_if_i (void)
17420{
17421 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17422 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17423 return;
17424
5ee91343
AV
17425 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17426 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17427 N_EQK, N_IF_32 | N_I64 | N_KEY);
17428
17429 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17430 /* If we are parsing Q registers and the element types match MVE, which NEON
17431 also supports, then we must check whether this is an instruction that can
17432 be used by both MVE/NEON. This distinction can be made based on whether
17433 they are predicated or not. */
17434 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17435 {
64c350f2
AV
17436 if (!check_simd_pred_availability (et.type == NT_float,
17437 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17438 return;
17439 }
17440 else
17441 {
17442 /* If they are either in a D register or are using an unsupported. */
17443 if (rs != NS_QQR
17444 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17445 return;
17446 }
17447
5287ad62
JB
17448 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17449 affected if we specify unsigned args. */
dcbf9037 17450 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17451}
17452
17453/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17454 result to be:
17455 V<op> A,B (A is operand 0, B is operand 2)
17456 to mean:
17457 V<op> A,B,A
17458 not:
17459 V<op> A,B,B
17460 so handle that case specially. */
17461
17462static void
17463neon_exchange_operands (void)
17464{
5287ad62
JB
17465 if (inst.operands[1].present)
17466 {
e1fa0163
NC
17467 void *scratch = xmalloc (sizeof (inst.operands[0]));
17468
5287ad62
JB
17469 /* Swap operands[1] and operands[2]. */
17470 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17471 inst.operands[1] = inst.operands[2];
17472 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17473 free (scratch);
5287ad62
JB
17474 }
17475 else
17476 {
17477 inst.operands[1] = inst.operands[2];
17478 inst.operands[2] = inst.operands[0];
17479 }
17480}
17481
17482static void
17483neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17484{
17485 if (inst.operands[2].isreg)
17486 {
17487 if (invert)
477330fc 17488 neon_exchange_operands ();
dcbf9037 17489 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17490 }
17491 else
17492 {
037e8744 17493 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17494 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17495 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17496
88714cb8 17497 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17498 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17499 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17500 inst.instruction |= LOW4 (inst.operands[1].reg);
17501 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17502 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17503 inst.instruction |= (et.type == NT_float) << 10;
17504 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17505
88714cb8 17506 neon_dp_fixup (&inst);
5287ad62
JB
17507 }
17508}
17509
17510static void
17511do_neon_cmp (void)
17512{
cc933301 17513 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17514}
17515
17516static void
17517do_neon_cmp_inv (void)
17518{
cc933301 17519 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17520}
17521
17522static void
17523do_neon_ceq (void)
17524{
17525 neon_compare (N_IF_32, N_IF_32, FALSE);
17526}
17527
17528/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17529 scalars, which are encoded in 5 bits, M : Rm.
17530 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17531 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17532 index in M.
17533
17534 Dot Product instructions are similar to multiply instructions except elsize
17535 should always be 32.
17536
17537 This function translates SCALAR, which is GAS's internal encoding of indexed
17538 scalar register, to raw encoding. There is also register and index range
17539 check based on ELSIZE. */
5287ad62
JB
17540
17541static unsigned
17542neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17543{
dcbf9037
JB
17544 unsigned regno = NEON_SCALAR_REG (scalar);
17545 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17546
17547 switch (elsize)
17548 {
17549 case 16:
17550 if (regno > 7 || elno > 3)
477330fc 17551 goto bad_scalar;
5287ad62 17552 return regno | (elno << 3);
5f4273c7 17553
5287ad62
JB
17554 case 32:
17555 if (regno > 15 || elno > 1)
477330fc 17556 goto bad_scalar;
5287ad62
JB
17557 return regno | (elno << 4);
17558
17559 default:
17560 bad_scalar:
dcbf9037 17561 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17562 }
17563
17564 return 0;
17565}
17566
17567/* Encode multiply / multiply-accumulate scalar instructions. */
17568
17569static void
17570neon_mul_mac (struct neon_type_el et, int ubit)
17571{
dcbf9037
JB
17572 unsigned scalar;
17573
17574 /* Give a more helpful error message if we have an invalid type. */
17575 if (et.type == NT_invtype)
17576 return;
5f4273c7 17577
dcbf9037 17578 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17579 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17580 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17581 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17582 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17583 inst.instruction |= LOW4 (scalar);
17584 inst.instruction |= HI1 (scalar) << 5;
17585 inst.instruction |= (et.type == NT_float) << 8;
17586 inst.instruction |= neon_logbits (et.size) << 20;
17587 inst.instruction |= (ubit != 0) << 24;
17588
88714cb8 17589 neon_dp_fixup (&inst);
5287ad62
JB
17590}
17591
17592static void
17593do_neon_mac_maybe_scalar (void)
17594{
037e8744
JB
17595 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17596 return;
17597
64c350f2 17598 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17599 return;
17600
5287ad62
JB
17601 if (inst.operands[2].isscalar)
17602 {
a8465a06 17603 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17604 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17605 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17606 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17607 NEON_ENCODE (SCALAR, inst);
037e8744 17608 neon_mul_mac (et, neon_quad (rs));
5287ad62 17609 }
a8465a06
AV
17610 else if (!inst.operands[2].isvec)
17611 {
17612 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17613
17614 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17615 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17616
17617 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17618 }
5287ad62 17619 else
428e3f1f 17620 {
a8465a06 17621 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17622 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17623 affected if we specify unsigned args. */
17624 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17625 }
5287ad62
JB
17626}
17627
62f3b8c8
PB
17628static void
17629do_neon_fmac (void)
17630{
d58196e0
AV
17631 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17632 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17633 return;
17634
64c350f2 17635 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17636 return;
17637
d58196e0
AV
17638 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17639 {
17640 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17641 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17642 N_EQK);
17643
17644 if (rs == NS_QQR)
17645 {
17646 if (inst.operands[2].reg == REG_SP)
17647 as_tsktsk (MVE_BAD_SP);
17648 else if (inst.operands[2].reg == REG_PC)
17649 as_tsktsk (MVE_BAD_PC);
17650
17651 inst.instruction = 0xee310e40;
17652 inst.instruction |= (et.size == 16) << 28;
17653 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17654 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17655 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17656 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17657 inst.instruction |= inst.operands[2].reg;
17658 inst.is_neon = 1;
17659 return;
17660 }
17661 }
17662 else
17663 {
17664 constraint (!inst.operands[2].isvec, BAD_FPU);
17665 }
17666
62f3b8c8
PB
17667 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17668}
17669
5287ad62
JB
17670static void
17671do_neon_tst (void)
17672{
037e8744 17673 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
17674 struct neon_type_el et = neon_check_type (3, rs,
17675 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 17676 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
17677}
17678
17679/* VMUL with 3 registers allows the P8 type. The scalar version supports the
17680 same types as the MAC equivalents. The polynomial type for this instruction
17681 is encoded the same as the integer type. */
17682
17683static void
17684do_neon_mul (void)
17685{
037e8744
JB
17686 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
17687 return;
17688
64c350f2 17689 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17690 return;
17691
5287ad62 17692 if (inst.operands[2].isscalar)
a8465a06
AV
17693 {
17694 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17695 do_neon_mac_maybe_scalar ();
17696 }
5287ad62 17697 else
a8465a06
AV
17698 {
17699 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17700 {
17701 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17702 struct neon_type_el et
17703 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
17704 if (et.type == NT_float)
17705 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
17706 BAD_FPU);
17707
17708 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
17709 }
17710 else
17711 {
17712 constraint (!inst.operands[2].isvec, BAD_FPU);
17713 neon_dyadic_misc (NT_poly,
17714 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
17715 }
17716 }
5287ad62
JB
17717}
17718
17719static void
17720do_neon_qdmulh (void)
17721{
64c350f2 17722 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
17723 return;
17724
5287ad62
JB
17725 if (inst.operands[2].isscalar)
17726 {
42b16635 17727 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17728 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17729 struct neon_type_el et = neon_check_type (3, rs,
477330fc 17730 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 17731 NEON_ENCODE (SCALAR, inst);
037e8744 17732 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
17733 }
17734 else
17735 {
42b16635
AV
17736 enum neon_shape rs;
17737 struct neon_type_el et;
17738 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17739 {
17740 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17741 et = neon_check_type (3, rs,
17742 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17743 }
17744 else
17745 {
17746 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17747 et = neon_check_type (3, rs,
17748 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17749 }
17750
88714cb8 17751 NEON_ENCODE (INTEGER, inst);
42b16635
AV
17752 if (rs == NS_QQR)
17753 mve_encode_qqr (et.size, 0, 0);
17754 else
17755 /* The U bit (rounding) comes from bit mask. */
17756 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
17757 }
17758}
17759
26c1e780
AV
17760static void
17761do_mve_vaddv (void)
17762{
17763 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
17764 struct neon_type_el et
17765 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17766
17767 if (et.type == NT_invtype)
17768 first_error (BAD_EL_TYPE);
17769
17770 if (inst.cond > COND_ALWAYS)
17771 inst.pred_insn_type = INSIDE_VPT_INSN;
17772 else
17773 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17774
17775 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17776
17777 mve_encode_rq (et.type == NT_unsigned, et.size);
17778}
17779
7df54120
AV
17780static void
17781do_mve_vhcadd (void)
17782{
17783 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
17784 struct neon_type_el et
17785 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17786
17787 if (inst.cond > COND_ALWAYS)
17788 inst.pred_insn_type = INSIDE_VPT_INSN;
17789 else
17790 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17791
17792 unsigned rot = inst.relocs[0].exp.X_add_number;
17793 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17794
17795 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
17796 as_tsktsk (_("Warning: 32-bit element size and same first and third "
17797 "operand makes instruction UNPREDICTABLE"));
17798
17799 mve_encode_qqq (0, et.size);
17800 inst.instruction |= (rot == 270) << 12;
17801 inst.is_neon = 1;
17802}
17803
35d1cfc2
AV
17804static void
17805do_mve_vqdmull (void)
17806{
17807 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17808 struct neon_type_el et
17809 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17810
17811 if (et.size == 32
17812 && (inst.operands[0].reg == inst.operands[1].reg
17813 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
17814 as_tsktsk (BAD_MVE_SRCDEST);
17815
17816 if (inst.cond > COND_ALWAYS)
17817 inst.pred_insn_type = INSIDE_VPT_INSN;
17818 else
17819 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17820
17821 if (rs == NS_QQQ)
17822 {
17823 mve_encode_qqq (et.size == 32, 64);
17824 inst.instruction |= 1;
17825 }
17826 else
17827 {
17828 mve_encode_qqr (64, et.size == 32, 0);
17829 inst.instruction |= 0x3 << 5;
17830 }
17831}
17832
c2dafc2a
AV
17833static void
17834do_mve_vadc (void)
17835{
17836 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17837 struct neon_type_el et
17838 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
17839
17840 if (et.type == NT_invtype)
17841 first_error (BAD_EL_TYPE);
17842
17843 if (inst.cond > COND_ALWAYS)
17844 inst.pred_insn_type = INSIDE_VPT_INSN;
17845 else
17846 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17847
17848 mve_encode_qqq (0, 64);
17849}
17850
17851static void
17852do_mve_vbrsr (void)
17853{
17854 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17855 struct neon_type_el et
17856 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
17857
17858 if (inst.cond > COND_ALWAYS)
17859 inst.pred_insn_type = INSIDE_VPT_INSN;
17860 else
17861 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17862
7df54120 17863 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
17864}
17865
17866static void
17867do_mve_vsbc (void)
17868{
17869 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
17870
17871 if (inst.cond > COND_ALWAYS)
17872 inst.pred_insn_type = INSIDE_VPT_INSN;
17873 else
17874 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17875
17876 mve_encode_qqq (1, 64);
17877}
17878
2d78f95b
AV
17879static void
17880do_mve_vmulh (void)
17881{
17882 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17883 struct neon_type_el et
17884 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17885
17886 if (inst.cond > COND_ALWAYS)
17887 inst.pred_insn_type = INSIDE_VPT_INSN;
17888 else
17889 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17890
17891 mve_encode_qqq (et.type == NT_unsigned, et.size);
17892}
17893
42b16635
AV
17894static void
17895do_mve_vqdmlah (void)
17896{
17897 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17898 struct neon_type_el et
17899 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17900
17901 if (inst.cond > COND_ALWAYS)
17902 inst.pred_insn_type = INSIDE_VPT_INSN;
17903 else
17904 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17905
17906 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
17907}
8b8b22a4
AV
17908
17909static void
17910do_mve_vqdmladh (void)
17911{
17912 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17913 struct neon_type_el et
17914 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17915
17916 if (inst.cond > COND_ALWAYS)
17917 inst.pred_insn_type = INSIDE_VPT_INSN;
17918 else
17919 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17920
17921 if (et.size == 32
17922 && (inst.operands[0].reg == inst.operands[1].reg
17923 || inst.operands[0].reg == inst.operands[2].reg))
17924 as_tsktsk (BAD_MVE_SRCDEST);
17925
17926 mve_encode_qqq (0, et.size);
17927}
17928
17929
886e1c73
AV
17930static void
17931do_mve_vmull (void)
17932{
17933
17934 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
17935 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
17936 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
17937 && inst.cond == COND_ALWAYS
17938 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
17939 {
17940 if (rs == NS_QQQ)
17941 {
17942
17943 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17944 N_SUF_32 | N_F64 | N_P8
17945 | N_P16 | N_I_MVE | N_KEY);
17946 if (((et.type == NT_poly) && et.size == 8
17947 && ARM_CPU_IS_ANY (cpu_variant))
17948 || (et.type == NT_integer) || (et.type == NT_float))
17949 goto neon_vmul;
17950 }
17951 else
17952 goto neon_vmul;
17953 }
17954
17955 constraint (rs != NS_QQQ, BAD_FPU);
17956 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17957 N_SU_32 | N_P8 | N_P16 | N_KEY);
17958
17959 /* We are dealing with MVE's vmullt. */
17960 if (et.size == 32
17961 && (inst.operands[0].reg == inst.operands[1].reg
17962 || inst.operands[0].reg == inst.operands[2].reg))
17963 as_tsktsk (BAD_MVE_SRCDEST);
17964
17965 if (inst.cond > COND_ALWAYS)
17966 inst.pred_insn_type = INSIDE_VPT_INSN;
17967 else
17968 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17969
17970 if (et.type == NT_poly)
17971 mve_encode_qqq (neon_logbits (et.size), 64);
17972 else
17973 mve_encode_qqq (et.type == NT_unsigned, et.size);
17974
17975 return;
17976
17977neon_vmul:
17978 inst.instruction = N_MNEM_vmul;
17979 inst.cond = 0xb;
17980 if (thumb_mode)
17981 inst.pred_insn_type = INSIDE_IT_INSN;
17982 do_neon_mul ();
17983}
17984
a302e574
AV
17985static void
17986do_mve_vabav (void)
17987{
17988 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
17989
17990 if (rs == NS_NULL)
17991 return;
17992
17993 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17994 return;
17995
17996 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
17997 | N_S16 | N_S32 | N_U8 | N_U16
17998 | N_U32);
17999
18000 if (inst.cond > COND_ALWAYS)
18001 inst.pred_insn_type = INSIDE_VPT_INSN;
18002 else
18003 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18004
18005 mve_encode_rqq (et.type == NT_unsigned, et.size);
18006}
18007
18008static void
18009do_mve_vmladav (void)
18010{
18011 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18012 struct neon_type_el et = neon_check_type (3, rs,
18013 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18014
18015 if (et.type == NT_unsigned
18016 && (inst.instruction == M_MNEM_vmladavx
18017 || inst.instruction == M_MNEM_vmladavax
18018 || inst.instruction == M_MNEM_vmlsdav
18019 || inst.instruction == M_MNEM_vmlsdava
18020 || inst.instruction == M_MNEM_vmlsdavx
18021 || inst.instruction == M_MNEM_vmlsdavax))
18022 first_error (BAD_SIMD_TYPE);
18023
18024 constraint (inst.operands[2].reg > 14,
18025 _("MVE vector register in the range [Q0..Q7] expected"));
18026
18027 if (inst.cond > COND_ALWAYS)
18028 inst.pred_insn_type = INSIDE_VPT_INSN;
18029 else
18030 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18031
18032 if (inst.instruction == M_MNEM_vmlsdav
18033 || inst.instruction == M_MNEM_vmlsdava
18034 || inst.instruction == M_MNEM_vmlsdavx
18035 || inst.instruction == M_MNEM_vmlsdavax)
18036 inst.instruction |= (et.size == 8) << 28;
18037 else
18038 inst.instruction |= (et.size == 8) << 8;
18039
18040 mve_encode_rqq (et.type == NT_unsigned, 64);
18041 inst.instruction |= (et.size == 32) << 16;
18042}
18043
93925576
AV
18044static void
18045do_mve_vmlaldav (void)
18046{
18047 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18048 struct neon_type_el et
18049 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18050 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18051
18052 if (et.type == NT_unsigned
18053 && (inst.instruction == M_MNEM_vmlsldav
18054 || inst.instruction == M_MNEM_vmlsldava
18055 || inst.instruction == M_MNEM_vmlsldavx
18056 || inst.instruction == M_MNEM_vmlsldavax))
18057 first_error (BAD_SIMD_TYPE);
18058
18059 if (inst.cond > COND_ALWAYS)
18060 inst.pred_insn_type = INSIDE_VPT_INSN;
18061 else
18062 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18063
18064 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18065}
18066
18067static void
18068do_mve_vrmlaldavh (void)
18069{
18070 struct neon_type_el et;
18071 if (inst.instruction == M_MNEM_vrmlsldavh
18072 || inst.instruction == M_MNEM_vrmlsldavha
18073 || inst.instruction == M_MNEM_vrmlsldavhx
18074 || inst.instruction == M_MNEM_vrmlsldavhax)
18075 {
18076 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18077 if (inst.operands[1].reg == REG_SP)
18078 as_tsktsk (MVE_BAD_SP);
18079 }
18080 else
18081 {
18082 if (inst.instruction == M_MNEM_vrmlaldavhx
18083 || inst.instruction == M_MNEM_vrmlaldavhax)
18084 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18085 else
18086 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18087 N_U32 | N_S32 | N_KEY);
18088 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18089 with vmax/min instructions, making the use of SP in assembly really
18090 nonsensical, so instead of issuing a warning like we do for other uses
18091 of SP for the odd register operand we error out. */
18092 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18093 }
18094
18095 /* Make sure we still check the second operand is an odd one and that PC is
18096 disallowed. This because we are parsing for any GPR operand, to be able
18097 to distinguish between giving a warning or an error for SP as described
18098 above. */
18099 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18100 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18101
18102 if (inst.cond > COND_ALWAYS)
18103 inst.pred_insn_type = INSIDE_VPT_INSN;
18104 else
18105 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18106
18107 mve_encode_rrqq (et.type == NT_unsigned, 0);
18108}
18109
18110
8cd78170
AV
18111static void
18112do_mve_vmaxnmv (void)
18113{
18114 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18115 struct neon_type_el et
18116 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18117
18118 if (inst.cond > COND_ALWAYS)
18119 inst.pred_insn_type = INSIDE_VPT_INSN;
18120 else
18121 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18122
18123 if (inst.operands[0].reg == REG_SP)
18124 as_tsktsk (MVE_BAD_SP);
18125 else if (inst.operands[0].reg == REG_PC)
18126 as_tsktsk (MVE_BAD_PC);
18127
18128 mve_encode_rq (et.size == 16, 64);
18129}
18130
13ccd4c0
AV
18131static void
18132do_mve_vmaxv (void)
18133{
18134 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18135 struct neon_type_el et;
18136
18137 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18138 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18139 else
18140 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18141
18142 if (inst.cond > COND_ALWAYS)
18143 inst.pred_insn_type = INSIDE_VPT_INSN;
18144 else
18145 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18146
18147 if (inst.operands[0].reg == REG_SP)
18148 as_tsktsk (MVE_BAD_SP);
18149 else if (inst.operands[0].reg == REG_PC)
18150 as_tsktsk (MVE_BAD_PC);
18151
18152 mve_encode_rq (et.type == NT_unsigned, et.size);
18153}
18154
18155
643afb90
MW
18156static void
18157do_neon_qrdmlah (void)
18158{
64c350f2 18159 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18160 return;
18161 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18162 {
42b16635
AV
18163 /* Check we're on the correct architecture. */
18164 if (!mark_feature_used (&fpu_neon_ext_armv8))
18165 inst.error
18166 = _("instruction form not available on this architecture.");
18167 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18168 {
18169 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18170 record_feature_use (&fpu_neon_ext_v8_1);
18171 }
18172 if (inst.operands[2].isscalar)
18173 {
18174 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18175 struct neon_type_el et = neon_check_type (3, rs,
18176 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18177 NEON_ENCODE (SCALAR, inst);
18178 neon_mul_mac (et, neon_quad (rs));
18179 }
18180 else
18181 {
18182 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18183 struct neon_type_el et = neon_check_type (3, rs,
18184 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18185 NEON_ENCODE (INTEGER, inst);
18186 /* The U bit (rounding) comes from bit mask. */
18187 neon_three_same (neon_quad (rs), 0, et.size);
18188 }
643afb90
MW
18189 }
18190 else
18191 {
42b16635
AV
18192 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18193 struct neon_type_el et
18194 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18195
643afb90 18196 NEON_ENCODE (INTEGER, inst);
42b16635 18197 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18198 }
18199}
18200
5287ad62
JB
18201static void
18202do_neon_fcmp_absolute (void)
18203{
037e8744 18204 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18205 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18206 N_F_16_32 | N_KEY);
5287ad62 18207 /* Size field comes from bit mask. */
cc933301 18208 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18209}
18210
18211static void
18212do_neon_fcmp_absolute_inv (void)
18213{
18214 neon_exchange_operands ();
18215 do_neon_fcmp_absolute ();
18216}
18217
18218static void
18219do_neon_step (void)
18220{
037e8744 18221 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18222 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18223 N_F_16_32 | N_KEY);
18224 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18225}
18226
18227static void
18228do_neon_abs_neg (void)
18229{
037e8744
JB
18230 enum neon_shape rs;
18231 struct neon_type_el et;
5f4273c7 18232
037e8744
JB
18233 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18234 return;
18235
037e8744 18236 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18237 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18238
64c350f2
AV
18239 if (!check_simd_pred_availability (et.type == NT_float,
18240 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18241 return;
18242
5287ad62
JB
18243 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18244 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18245 inst.instruction |= LOW4 (inst.operands[1].reg);
18246 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18247 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18248 inst.instruction |= (et.type == NT_float) << 10;
18249 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18250
88714cb8 18251 neon_dp_fixup (&inst);
5287ad62
JB
18252}
18253
18254static void
18255do_neon_sli (void)
18256{
64c350f2 18257 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18258 return;
18259
18260 enum neon_shape rs;
18261 struct neon_type_el et;
18262 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18263 {
18264 rs = neon_select_shape (NS_QQI, NS_NULL);
18265 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18266 }
18267 else
18268 {
18269 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18270 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18271 }
18272
18273
5287ad62
JB
18274 int imm = inst.operands[2].imm;
18275 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18276 _("immediate out of range for insert"));
037e8744 18277 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18278}
18279
18280static void
18281do_neon_sri (void)
18282{
64c350f2 18283 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18284 return;
18285
18286 enum neon_shape rs;
18287 struct neon_type_el et;
18288 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18289 {
18290 rs = neon_select_shape (NS_QQI, NS_NULL);
18291 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18292 }
18293 else
18294 {
18295 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18296 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18297 }
18298
5287ad62
JB
18299 int imm = inst.operands[2].imm;
18300 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18301 _("immediate out of range for insert"));
037e8744 18302 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18303}
18304
18305static void
18306do_neon_qshlu_imm (void)
18307{
64c350f2 18308 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18309 return;
18310
18311 enum neon_shape rs;
18312 struct neon_type_el et;
18313 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18314 {
18315 rs = neon_select_shape (NS_QQI, NS_NULL);
18316 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18317 }
18318 else
18319 {
18320 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18321 et = neon_check_type (2, rs, N_EQK | N_UNS,
18322 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18323 }
18324
5287ad62
JB
18325 int imm = inst.operands[2].imm;
18326 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18327 _("immediate out of range for shift"));
5287ad62
JB
18328 /* Only encodes the 'U present' variant of the instruction.
18329 In this case, signed types have OP (bit 8) set to 0.
18330 Unsigned types have OP set to 1. */
18331 inst.instruction |= (et.type == NT_unsigned) << 8;
18332 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18333 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18334}
18335
18336static void
18337do_neon_qmovn (void)
18338{
18339 struct neon_type_el et = neon_check_type (2, NS_DQ,
18340 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18341 /* Saturating move where operands can be signed or unsigned, and the
18342 destination has the same signedness. */
88714cb8 18343 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18344 if (et.type == NT_unsigned)
18345 inst.instruction |= 0xc0;
18346 else
18347 inst.instruction |= 0x80;
18348 neon_two_same (0, 1, et.size / 2);
18349}
18350
18351static void
18352do_neon_qmovun (void)
18353{
18354 struct neon_type_el et = neon_check_type (2, NS_DQ,
18355 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18356 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18357 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18358 neon_two_same (0, 1, et.size / 2);
18359}
18360
18361static void
18362do_neon_rshift_sat_narrow (void)
18363{
18364 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18365 or unsigned. If operands are unsigned, results must also be unsigned. */
18366 struct neon_type_el et = neon_check_type (2, NS_DQI,
18367 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18368 int imm = inst.operands[2].imm;
18369 /* This gets the bounds check, size encoding and immediate bits calculation
18370 right. */
18371 et.size /= 2;
5f4273c7 18372
5287ad62
JB
18373 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18374 VQMOVN.I<size> <Dd>, <Qm>. */
18375 if (imm == 0)
18376 {
18377 inst.operands[2].present = 0;
18378 inst.instruction = N_MNEM_vqmovn;
18379 do_neon_qmovn ();
18380 return;
18381 }
5f4273c7 18382
5287ad62 18383 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18384 _("immediate out of range"));
5287ad62
JB
18385 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18386}
18387
18388static void
18389do_neon_rshift_sat_narrow_u (void)
18390{
18391 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18392 or unsigned. If operands are unsigned, results must also be unsigned. */
18393 struct neon_type_el et = neon_check_type (2, NS_DQI,
18394 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18395 int imm = inst.operands[2].imm;
18396 /* This gets the bounds check, size encoding and immediate bits calculation
18397 right. */
18398 et.size /= 2;
18399
18400 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18401 VQMOVUN.I<size> <Dd>, <Qm>. */
18402 if (imm == 0)
18403 {
18404 inst.operands[2].present = 0;
18405 inst.instruction = N_MNEM_vqmovun;
18406 do_neon_qmovun ();
18407 return;
18408 }
18409
18410 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18411 _("immediate out of range"));
5287ad62
JB
18412 /* FIXME: The manual is kind of unclear about what value U should have in
18413 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18414 must be 1. */
18415 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18416}
18417
18418static void
18419do_neon_movn (void)
18420{
18421 struct neon_type_el et = neon_check_type (2, NS_DQ,
18422 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18423 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18424 neon_two_same (0, 1, et.size / 2);
18425}
18426
18427static void
18428do_neon_rshift_narrow (void)
18429{
18430 struct neon_type_el et = neon_check_type (2, NS_DQI,
18431 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18432 int imm = inst.operands[2].imm;
18433 /* This gets the bounds check, size encoding and immediate bits calculation
18434 right. */
18435 et.size /= 2;
5f4273c7 18436
5287ad62
JB
18437 /* If immediate is zero then we are a pseudo-instruction for
18438 VMOVN.I<size> <Dd>, <Qm> */
18439 if (imm == 0)
18440 {
18441 inst.operands[2].present = 0;
18442 inst.instruction = N_MNEM_vmovn;
18443 do_neon_movn ();
18444 return;
18445 }
5f4273c7 18446
5287ad62 18447 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18448 _("immediate out of range for narrowing operation"));
5287ad62
JB
18449 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18450}
18451
18452static void
18453do_neon_shll (void)
18454{
18455 /* FIXME: Type checking when lengthening. */
18456 struct neon_type_el et = neon_check_type (2, NS_QDI,
18457 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18458 unsigned imm = inst.operands[2].imm;
18459
18460 if (imm == et.size)
18461 {
18462 /* Maximum shift variant. */
88714cb8 18463 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18464 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18465 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18466 inst.instruction |= LOW4 (inst.operands[1].reg);
18467 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18468 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18469
88714cb8 18470 neon_dp_fixup (&inst);
5287ad62
JB
18471 }
18472 else
18473 {
18474 /* A more-specific type check for non-max versions. */
18475 et = neon_check_type (2, NS_QDI,
477330fc 18476 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18477 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18478 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18479 }
18480}
18481
037e8744 18482/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18483 the current instruction is. */
18484
6b9a8b67
MGD
18485#define CVT_FLAVOUR_VAR \
18486 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18487 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18488 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18489 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18490 /* Half-precision conversions. */ \
cc933301
JW
18491 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18492 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18493 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18494 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18495 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18496 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18497 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18498 Compared with single/double precision variants, only the co-processor \
18499 field is different, so the encoding flow is reused here. */ \
18500 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18501 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18502 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18503 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
18504 /* VFP instructions. */ \
18505 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18506 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18507 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18508 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18509 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18510 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18511 /* VFP instructions with bitshift. */ \
18512 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18513 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18514 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18515 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18516 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18517 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18518 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18519 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18520
18521#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18522 neon_cvt_flavour_##C,
18523
18524/* The different types of conversions we can do. */
18525enum neon_cvt_flavour
18526{
18527 CVT_FLAVOUR_VAR
18528 neon_cvt_flavour_invalid,
18529 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18530};
18531
18532#undef CVT_VAR
18533
18534static enum neon_cvt_flavour
18535get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18536{
6b9a8b67
MGD
18537#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18538 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18539 if (et.type != NT_invtype) \
18540 { \
18541 inst.error = NULL; \
18542 return (neon_cvt_flavour_##C); \
5287ad62 18543 }
6b9a8b67 18544
5287ad62 18545 struct neon_type_el et;
037e8744 18546 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18547 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18548 /* The instruction versions which take an immediate take one register
18549 argument, which is extended to the width of the full register. Thus the
18550 "source" and "destination" registers must have the same width. Hack that
18551 here by making the size equal to the key (wider, in this case) operand. */
18552 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18553
6b9a8b67
MGD
18554 CVT_FLAVOUR_VAR;
18555
18556 return neon_cvt_flavour_invalid;
5287ad62
JB
18557#undef CVT_VAR
18558}
18559
7e8e6784
MGD
18560enum neon_cvt_mode
18561{
18562 neon_cvt_mode_a,
18563 neon_cvt_mode_n,
18564 neon_cvt_mode_p,
18565 neon_cvt_mode_m,
18566 neon_cvt_mode_z,
30bdf752
MGD
18567 neon_cvt_mode_x,
18568 neon_cvt_mode_r
7e8e6784
MGD
18569};
18570
037e8744
JB
18571/* Neon-syntax VFP conversions. */
18572
5287ad62 18573static void
6b9a8b67 18574do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18575{
037e8744 18576 const char *opname = 0;
5f4273c7 18577
d54af2d0
RL
18578 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18579 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18580 {
037e8744
JB
18581 /* Conversions with immediate bitshift. */
18582 const char *enc[] =
477330fc 18583 {
6b9a8b67
MGD
18584#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18585 CVT_FLAVOUR_VAR
18586 NULL
18587#undef CVT_VAR
477330fc 18588 };
037e8744 18589
6b9a8b67 18590 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18591 {
18592 opname = enc[flavour];
18593 constraint (inst.operands[0].reg != inst.operands[1].reg,
18594 _("operands 0 and 1 must be the same register"));
18595 inst.operands[1] = inst.operands[2];
18596 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18597 }
5287ad62
JB
18598 }
18599 else
18600 {
037e8744
JB
18601 /* Conversions without bitshift. */
18602 const char *enc[] =
477330fc 18603 {
6b9a8b67
MGD
18604#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18605 CVT_FLAVOUR_VAR
18606 NULL
18607#undef CVT_VAR
477330fc 18608 };
037e8744 18609
6b9a8b67 18610 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18611 opname = enc[flavour];
037e8744
JB
18612 }
18613
18614 if (opname)
18615 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18616
18617 /* ARMv8.2 fp16 VCVT instruction. */
18618 if (flavour == neon_cvt_flavour_s32_f16
18619 || flavour == neon_cvt_flavour_u32_f16
18620 || flavour == neon_cvt_flavour_f16_u32
18621 || flavour == neon_cvt_flavour_f16_s32)
18622 do_scalar_fp16_v82_encode ();
037e8744
JB
18623}
18624
18625static void
18626do_vfp_nsyn_cvtz (void)
18627{
d54af2d0 18628 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18629 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18630 const char *enc[] =
18631 {
6b9a8b67
MGD
18632#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18633 CVT_FLAVOUR_VAR
18634 NULL
18635#undef CVT_VAR
037e8744
JB
18636 };
18637
6b9a8b67 18638 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18639 do_vfp_nsyn_opcode (enc[flavour]);
18640}
f31fef98 18641
037e8744 18642static void
bacebabc 18643do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18644 enum neon_cvt_mode mode)
18645{
18646 int sz, op;
18647 int rm;
18648
a715796b
TG
18649 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18650 D register operands. */
18651 if (flavour == neon_cvt_flavour_s32_f64
18652 || flavour == neon_cvt_flavour_u32_f64)
18653 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18654 _(BAD_FPU));
18655
9db2f6b4
RL
18656 if (flavour == neon_cvt_flavour_s32_f16
18657 || flavour == neon_cvt_flavour_u32_f16)
18658 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18659 _(BAD_FP16));
18660
5ee91343 18661 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
18662
18663 switch (flavour)
18664 {
18665 case neon_cvt_flavour_s32_f64:
18666 sz = 1;
827f64ff 18667 op = 1;
7e8e6784
MGD
18668 break;
18669 case neon_cvt_flavour_s32_f32:
18670 sz = 0;
18671 op = 1;
18672 break;
9db2f6b4
RL
18673 case neon_cvt_flavour_s32_f16:
18674 sz = 0;
18675 op = 1;
18676 break;
7e8e6784
MGD
18677 case neon_cvt_flavour_u32_f64:
18678 sz = 1;
18679 op = 0;
18680 break;
18681 case neon_cvt_flavour_u32_f32:
18682 sz = 0;
18683 op = 0;
18684 break;
9db2f6b4
RL
18685 case neon_cvt_flavour_u32_f16:
18686 sz = 0;
18687 op = 0;
18688 break;
7e8e6784
MGD
18689 default:
18690 first_error (_("invalid instruction shape"));
18691 return;
18692 }
18693
18694 switch (mode)
18695 {
18696 case neon_cvt_mode_a: rm = 0; break;
18697 case neon_cvt_mode_n: rm = 1; break;
18698 case neon_cvt_mode_p: rm = 2; break;
18699 case neon_cvt_mode_m: rm = 3; break;
18700 default: first_error (_("invalid rounding mode")); return;
18701 }
18702
18703 NEON_ENCODE (FPV8, inst);
18704 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
18705 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
18706 inst.instruction |= sz << 8;
9db2f6b4
RL
18707
18708 /* ARMv8.2 fp16 VCVT instruction. */
18709 if (flavour == neon_cvt_flavour_s32_f16
18710 ||flavour == neon_cvt_flavour_u32_f16)
18711 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
18712 inst.instruction |= op << 7;
18713 inst.instruction |= rm << 16;
18714 inst.instruction |= 0xf0000000;
18715 inst.is_neon = TRUE;
18716}
18717
18718static void
18719do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
18720{
18721 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
18722 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
18723 NS_FH, NS_HF, NS_FHI, NS_HFI,
18724 NS_NULL);
6b9a8b67 18725 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 18726
cc933301
JW
18727 if (flavour == neon_cvt_flavour_invalid)
18728 return;
18729
e3e535bc 18730 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 18731 if (mode == neon_cvt_mode_z
e3e535bc 18732 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
18733 && (flavour == neon_cvt_flavour_s16_f16
18734 || flavour == neon_cvt_flavour_u16_f16
18735 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
18736 || flavour == neon_cvt_flavour_u32_f32
18737 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 18738 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
18739 && (rs == NS_FD || rs == NS_FF))
18740 {
18741 do_vfp_nsyn_cvtz ();
18742 return;
18743 }
18744
9db2f6b4
RL
18745 /* ARMv8.2 fp16 VCVT conversions. */
18746 if (mode == neon_cvt_mode_z
18747 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
18748 && (flavour == neon_cvt_flavour_s32_f16
18749 || flavour == neon_cvt_flavour_u32_f16)
18750 && (rs == NS_FH))
18751 {
18752 do_vfp_nsyn_cvtz ();
18753 do_scalar_fp16_v82_encode ();
18754 return;
18755 }
18756
037e8744 18757 /* VFP rather than Neon conversions. */
6b9a8b67 18758 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 18759 {
7e8e6784
MGD
18760 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
18761 do_vfp_nsyn_cvt (rs, flavour);
18762 else
18763 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
18764
037e8744
JB
18765 return;
18766 }
18767
18768 switch (rs)
18769 {
037e8744 18770 case NS_QQI:
dd9634d9
AV
18771 if (mode == neon_cvt_mode_z
18772 && (flavour == neon_cvt_flavour_f16_s16
18773 || flavour == neon_cvt_flavour_f16_u16
18774 || flavour == neon_cvt_flavour_s16_f16
18775 || flavour == neon_cvt_flavour_u16_f16
18776 || flavour == neon_cvt_flavour_f32_u32
18777 || flavour == neon_cvt_flavour_f32_s32
18778 || flavour == neon_cvt_flavour_s32_f32
18779 || flavour == neon_cvt_flavour_u32_f32))
18780 {
64c350f2
AV
18781 if (!check_simd_pred_availability (TRUE,
18782 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
18783 return;
18784 }
18785 else if (mode == neon_cvt_mode_n)
18786 {
18787 /* We are dealing with vcvt with the 'ne' condition. */
18788 inst.cond = 0x1;
18789 inst.instruction = N_MNEM_vcvt;
18790 do_neon_cvt_1 (neon_cvt_mode_z);
18791 return;
18792 }
18793 /* fall through. */
18794 case NS_DDI:
037e8744 18795 {
477330fc 18796 unsigned immbits;
cc933301
JW
18797 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
18798 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 18799
dd9634d9
AV
18800 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18801 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18802 return;
18803
18804 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18805 {
18806 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
18807 _("immediate value out of range"));
18808 switch (flavour)
18809 {
18810 case neon_cvt_flavour_f16_s16:
18811 case neon_cvt_flavour_f16_u16:
18812 case neon_cvt_flavour_s16_f16:
18813 case neon_cvt_flavour_u16_f16:
18814 constraint (inst.operands[2].imm > 16,
18815 _("immediate value out of range"));
18816 break;
18817 case neon_cvt_flavour_f32_u32:
18818 case neon_cvt_flavour_f32_s32:
18819 case neon_cvt_flavour_s32_f32:
18820 case neon_cvt_flavour_u32_f32:
18821 constraint (inst.operands[2].imm > 32,
18822 _("immediate value out of range"));
18823 break;
18824 default:
18825 inst.error = BAD_FPU;
18826 return;
18827 }
18828 }
037e8744 18829
477330fc
RM
18830 /* Fixed-point conversion with #0 immediate is encoded as an
18831 integer conversion. */
18832 if (inst.operands[2].present && inst.operands[2].imm == 0)
18833 goto int_encode;
477330fc
RM
18834 NEON_ENCODE (IMMED, inst);
18835 if (flavour != neon_cvt_flavour_invalid)
18836 inst.instruction |= enctab[flavour];
18837 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18838 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18839 inst.instruction |= LOW4 (inst.operands[1].reg);
18840 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18841 inst.instruction |= neon_quad (rs) << 6;
18842 inst.instruction |= 1 << 21;
cc933301
JW
18843 if (flavour < neon_cvt_flavour_s16_f16)
18844 {
18845 inst.instruction |= 1 << 21;
18846 immbits = 32 - inst.operands[2].imm;
18847 inst.instruction |= immbits << 16;
18848 }
18849 else
18850 {
18851 inst.instruction |= 3 << 20;
18852 immbits = 16 - inst.operands[2].imm;
18853 inst.instruction |= immbits << 16;
18854 inst.instruction &= ~(1 << 9);
18855 }
477330fc
RM
18856
18857 neon_dp_fixup (&inst);
037e8744
JB
18858 }
18859 break;
18860
037e8744 18861 case NS_QQ:
dd9634d9
AV
18862 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
18863 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
18864 && (flavour == neon_cvt_flavour_s16_f16
18865 || flavour == neon_cvt_flavour_u16_f16
18866 || flavour == neon_cvt_flavour_s32_f32
18867 || flavour == neon_cvt_flavour_u32_f32))
18868 {
64c350f2
AV
18869 if (!check_simd_pred_availability (TRUE,
18870 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
18871 return;
18872 }
18873 else if (mode == neon_cvt_mode_z
18874 && (flavour == neon_cvt_flavour_f16_s16
18875 || flavour == neon_cvt_flavour_f16_u16
18876 || flavour == neon_cvt_flavour_s16_f16
18877 || flavour == neon_cvt_flavour_u16_f16
18878 || flavour == neon_cvt_flavour_f32_u32
18879 || flavour == neon_cvt_flavour_f32_s32
18880 || flavour == neon_cvt_flavour_s32_f32
18881 || flavour == neon_cvt_flavour_u32_f32))
18882 {
64c350f2
AV
18883 if (!check_simd_pred_availability (TRUE,
18884 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
18885 return;
18886 }
18887 /* fall through. */
18888 case NS_DD:
7e8e6784
MGD
18889 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
18890 {
7e8e6784 18891
dd9634d9 18892 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
18893 if (!check_simd_pred_availability (TRUE,
18894 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
18895 return;
18896
18897 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18898 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18899 inst.instruction |= LOW4 (inst.operands[1].reg);
18900 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18901 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
18902 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
18903 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 18904 inst.instruction |= mode << 8;
cc933301
JW
18905 if (flavour == neon_cvt_flavour_u16_f16
18906 || flavour == neon_cvt_flavour_s16_f16)
18907 /* Mask off the original size bits and reencode them. */
18908 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
18909
7e8e6784
MGD
18910 if (thumb_mode)
18911 inst.instruction |= 0xfc000000;
18912 else
18913 inst.instruction |= 0xf0000000;
18914 }
18915 else
18916 {
037e8744 18917 int_encode:
7e8e6784 18918 {
cc933301
JW
18919 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
18920 0x100, 0x180, 0x0, 0x080};
037e8744 18921
7e8e6784 18922 NEON_ENCODE (INTEGER, inst);
037e8744 18923
dd9634d9
AV
18924 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18925 {
18926 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18927 return;
18928 }
037e8744 18929
7e8e6784
MGD
18930 if (flavour != neon_cvt_flavour_invalid)
18931 inst.instruction |= enctab[flavour];
037e8744 18932
7e8e6784
MGD
18933 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18934 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18935 inst.instruction |= LOW4 (inst.operands[1].reg);
18936 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18937 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
18938 if (flavour >= neon_cvt_flavour_s16_f16
18939 && flavour <= neon_cvt_flavour_f16_u16)
18940 /* Half precision. */
18941 inst.instruction |= 1 << 18;
18942 else
18943 inst.instruction |= 2 << 18;
037e8744 18944
7e8e6784
MGD
18945 neon_dp_fixup (&inst);
18946 }
18947 }
18948 break;
037e8744 18949
8e79c3df
CM
18950 /* Half-precision conversions for Advanced SIMD -- neon. */
18951 case NS_QD:
18952 case NS_DQ:
bc52d49c
MM
18953 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18954 return;
8e79c3df
CM
18955
18956 if ((rs == NS_DQ)
18957 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
18958 {
18959 as_bad (_("operand size must match register width"));
18960 break;
18961 }
18962
18963 if ((rs == NS_QD)
18964 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
18965 {
18966 as_bad (_("operand size must match register width"));
18967 break;
18968 }
18969
18970 if (rs == NS_DQ)
477330fc 18971 inst.instruction = 0x3b60600;
8e79c3df
CM
18972 else
18973 inst.instruction = 0x3b60700;
18974
18975 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18976 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18977 inst.instruction |= LOW4 (inst.operands[1].reg);
18978 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 18979 neon_dp_fixup (&inst);
8e79c3df
CM
18980 break;
18981
037e8744
JB
18982 default:
18983 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
18984 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
18985 do_vfp_nsyn_cvt (rs, flavour);
18986 else
18987 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 18988 }
5287ad62
JB
18989}
18990
e3e535bc
NC
18991static void
18992do_neon_cvtr (void)
18993{
7e8e6784 18994 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
18995}
18996
18997static void
18998do_neon_cvt (void)
18999{
7e8e6784
MGD
19000 do_neon_cvt_1 (neon_cvt_mode_z);
19001}
19002
19003static void
19004do_neon_cvta (void)
19005{
19006 do_neon_cvt_1 (neon_cvt_mode_a);
19007}
19008
19009static void
19010do_neon_cvtn (void)
19011{
19012 do_neon_cvt_1 (neon_cvt_mode_n);
19013}
19014
19015static void
19016do_neon_cvtp (void)
19017{
19018 do_neon_cvt_1 (neon_cvt_mode_p);
19019}
19020
19021static void
19022do_neon_cvtm (void)
19023{
19024 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19025}
19026
8e79c3df 19027static void
c70a8987 19028do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19029{
c70a8987
MGD
19030 if (is_double)
19031 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19032
c70a8987
MGD
19033 encode_arm_vfp_reg (inst.operands[0].reg,
19034 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19035 encode_arm_vfp_reg (inst.operands[1].reg,
19036 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19037 inst.instruction |= to ? 0x10000 : 0;
19038 inst.instruction |= t ? 0x80 : 0;
19039 inst.instruction |= is_double ? 0x100 : 0;
19040 do_vfp_cond_or_thumb ();
19041}
8e79c3df 19042
c70a8987
MGD
19043static void
19044do_neon_cvttb_1 (bfd_boolean t)
19045{
d54af2d0 19046 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19047 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19048
c70a8987
MGD
19049 if (rs == NS_NULL)
19050 return;
dd9634d9
AV
19051 else if (rs == NS_QQ || rs == NS_QQI)
19052 {
19053 int single_to_half = 0;
64c350f2 19054 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19055 return;
19056
19057 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19058
19059 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19060 && (flavour == neon_cvt_flavour_u16_f16
19061 || flavour == neon_cvt_flavour_s16_f16
19062 || flavour == neon_cvt_flavour_f16_s16
19063 || flavour == neon_cvt_flavour_f16_u16
19064 || flavour == neon_cvt_flavour_u32_f32
19065 || flavour == neon_cvt_flavour_s32_f32
19066 || flavour == neon_cvt_flavour_f32_s32
19067 || flavour == neon_cvt_flavour_f32_u32))
19068 {
19069 inst.cond = 0xf;
19070 inst.instruction = N_MNEM_vcvt;
19071 set_pred_insn_type (INSIDE_VPT_INSN);
19072 do_neon_cvt_1 (neon_cvt_mode_z);
19073 return;
19074 }
19075 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19076 single_to_half = 1;
19077 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19078 {
19079 first_error (BAD_FPU);
19080 return;
19081 }
19082
19083 inst.instruction = 0xee3f0e01;
19084 inst.instruction |= single_to_half << 28;
19085 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19086 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19087 inst.instruction |= t << 12;
19088 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19089 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19090 inst.is_neon = 1;
19091 }
c70a8987
MGD
19092 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19093 {
19094 inst.error = NULL;
19095 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19096 }
19097 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19098 {
19099 inst.error = NULL;
19100 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19101 }
19102 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19103 {
a715796b
TG
19104 /* The VCVTB and VCVTT instructions with D-register operands
19105 don't work for SP only targets. */
19106 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19107 _(BAD_FPU));
19108
c70a8987
MGD
19109 inst.error = NULL;
19110 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19111 }
19112 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19113 {
a715796b
TG
19114 /* The VCVTB and VCVTT instructions with D-register operands
19115 don't work for SP only targets. */
19116 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19117 _(BAD_FPU));
19118
c70a8987
MGD
19119 inst.error = NULL;
19120 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19121 }
19122 else
19123 return;
19124}
19125
19126static void
19127do_neon_cvtb (void)
19128{
19129 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19130}
19131
19132
19133static void
19134do_neon_cvtt (void)
19135{
c70a8987 19136 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19137}
19138
5287ad62
JB
19139static void
19140neon_move_immediate (void)
19141{
037e8744
JB
19142 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19143 struct neon_type_el et = neon_check_type (2, rs,
19144 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19145 unsigned immlo, immhi = 0, immbits;
c96612cc 19146 int op, cmode, float_p;
5287ad62 19147
037e8744 19148 constraint (et.type == NT_invtype,
477330fc 19149 _("operand size must be specified for immediate VMOV"));
037e8744 19150
5287ad62
JB
19151 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19152 op = (inst.instruction & (1 << 5)) != 0;
19153
19154 immlo = inst.operands[1].imm;
19155 if (inst.operands[1].regisimm)
19156 immhi = inst.operands[1].reg;
19157
19158 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19159 _("immediate has bits set outside the operand size"));
5287ad62 19160
c96612cc
JB
19161 float_p = inst.operands[1].immisfloat;
19162
19163 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19164 et.size, et.type)) == FAIL)
5287ad62
JB
19165 {
19166 /* Invert relevant bits only. */
19167 neon_invert_size (&immlo, &immhi, et.size);
19168 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19169 with one or the other; those cases are caught by
19170 neon_cmode_for_move_imm. */
5287ad62 19171 op = !op;
c96612cc
JB
19172 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19173 &op, et.size, et.type)) == FAIL)
477330fc
RM
19174 {
19175 first_error (_("immediate out of range"));
19176 return;
19177 }
5287ad62
JB
19178 }
19179
19180 inst.instruction &= ~(1 << 5);
19181 inst.instruction |= op << 5;
19182
19183 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19184 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19185 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19186 inst.instruction |= cmode << 8;
19187
19188 neon_write_immbits (immbits);
19189}
19190
19191static void
19192do_neon_mvn (void)
19193{
64c350f2 19194 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19195 return;
19196
5287ad62
JB
19197 if (inst.operands[1].isreg)
19198 {
1a186d29
AV
19199 enum neon_shape rs;
19200 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19201 rs = neon_select_shape (NS_QQ, NS_NULL);
19202 else
19203 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19204
88714cb8 19205 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19206 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19207 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19208 inst.instruction |= LOW4 (inst.operands[1].reg);
19209 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19210 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19211 }
19212 else
19213 {
88714cb8 19214 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19215 neon_move_immediate ();
19216 }
19217
88714cb8 19218 neon_dp_fixup (&inst);
1a186d29
AV
19219
19220 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19221 {
19222 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19223 constraint ((inst.instruction & 0xd00) == 0xd00,
19224 _("immediate value out of range"));
19225 }
5287ad62
JB
19226}
19227
19228/* Encode instructions of form:
19229
19230 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19231 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19232
19233static void
19234neon_mixed_length (struct neon_type_el et, unsigned size)
19235{
19236 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19237 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19238 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19239 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19240 inst.instruction |= LOW4 (inst.operands[2].reg);
19241 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19242 inst.instruction |= (et.type == NT_unsigned) << 24;
19243 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19244
88714cb8 19245 neon_dp_fixup (&inst);
5287ad62
JB
19246}
19247
19248static void
19249do_neon_dyadic_long (void)
19250{
5ee91343
AV
19251 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19252 if (rs == NS_QDD)
19253 {
19254 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19255 return;
19256
19257 NEON_ENCODE (INTEGER, inst);
19258 /* FIXME: Type checking for lengthening op. */
19259 struct neon_type_el et = neon_check_type (3, NS_QDD,
19260 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19261 neon_mixed_length (et, et.size);
19262 }
19263 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19264 && (inst.cond == 0xf || inst.cond == 0x10))
19265 {
19266 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19267 in an IT block with le/lt conditions. */
19268
19269 if (inst.cond == 0xf)
19270 inst.cond = 0xb;
19271 else if (inst.cond == 0x10)
19272 inst.cond = 0xd;
19273
19274 inst.pred_insn_type = INSIDE_IT_INSN;
19275
19276 if (inst.instruction == N_MNEM_vaddl)
19277 {
19278 inst.instruction = N_MNEM_vadd;
19279 do_neon_addsub_if_i ();
19280 }
19281 else if (inst.instruction == N_MNEM_vsubl)
19282 {
19283 inst.instruction = N_MNEM_vsub;
19284 do_neon_addsub_if_i ();
19285 }
19286 else if (inst.instruction == N_MNEM_vabdl)
19287 {
19288 inst.instruction = N_MNEM_vabd;
19289 do_neon_dyadic_if_su ();
19290 }
19291 }
19292 else
19293 first_error (BAD_FPU);
5287ad62
JB
19294}
19295
19296static void
19297do_neon_abal (void)
19298{
19299 struct neon_type_el et = neon_check_type (3, NS_QDD,
19300 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19301 neon_mixed_length (et, et.size);
19302}
19303
19304static void
19305neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19306{
19307 if (inst.operands[2].isscalar)
19308 {
dcbf9037 19309 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19310 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19311 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19312 neon_mul_mac (et, et.type == NT_unsigned);
19313 }
19314 else
19315 {
19316 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19317 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19318 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19319 neon_mixed_length (et, et.size);
19320 }
19321}
19322
19323static void
19324do_neon_mac_maybe_scalar_long (void)
19325{
19326 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19327}
19328
dec41383
JW
19329/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19330 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19331
19332static unsigned
19333neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19334{
19335 unsigned regno = NEON_SCALAR_REG (scalar);
19336 unsigned elno = NEON_SCALAR_INDEX (scalar);
19337
19338 if (quad_p)
19339 {
19340 if (regno > 7 || elno > 3)
19341 goto bad_scalar;
19342
19343 return ((regno & 0x7)
19344 | ((elno & 0x1) << 3)
19345 | (((elno >> 1) & 0x1) << 5));
19346 }
19347 else
19348 {
19349 if (regno > 15 || elno > 1)
19350 goto bad_scalar;
19351
19352 return (((regno & 0x1) << 5)
19353 | ((regno >> 1) & 0x7)
19354 | ((elno & 0x1) << 3));
19355 }
19356
19357bad_scalar:
19358 first_error (_("scalar out of range for multiply instruction"));
19359 return 0;
19360}
19361
19362static void
19363do_neon_fmac_maybe_scalar_long (int subtype)
19364{
19365 enum neon_shape rs;
19366 int high8;
19367 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19368 field (bits[21:20]) has different meaning. For scalar index variant, it's
19369 used to differentiate add and subtract, otherwise it's with fixed value
19370 0x2. */
19371 int size = -1;
19372
19373 if (inst.cond != COND_ALWAYS)
19374 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19375 "behaviour is UNPREDICTABLE"));
19376
01f48020 19377 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
19378 _(BAD_FP16));
19379
19380 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19381 _(BAD_FPU));
19382
19383 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19384 be a scalar index register. */
19385 if (inst.operands[2].isscalar)
19386 {
19387 high8 = 0xfe000000;
19388 if (subtype)
19389 size = 16;
19390 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19391 }
19392 else
19393 {
19394 high8 = 0xfc000000;
19395 size = 32;
19396 if (subtype)
19397 inst.instruction |= (0x1 << 23);
19398 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19399 }
19400
19401 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
19402
19403 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19404 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19405 so we simply pass -1 as size. */
19406 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19407 neon_three_same (quad_p, 0, size);
19408
19409 /* Undo neon_dp_fixup. Redo the high eight bits. */
19410 inst.instruction &= 0x00ffffff;
19411 inst.instruction |= high8;
19412
19413#define LOW1(R) ((R) & 0x1)
19414#define HI4(R) (((R) >> 1) & 0xf)
19415 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19416 whether the instruction is in Q form and whether Vm is a scalar indexed
19417 operand. */
19418 if (inst.operands[2].isscalar)
19419 {
19420 unsigned rm
19421 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19422 inst.instruction &= 0xffffffd0;
19423 inst.instruction |= rm;
19424
19425 if (!quad_p)
19426 {
19427 /* Redo Rn as well. */
19428 inst.instruction &= 0xfff0ff7f;
19429 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19430 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19431 }
19432 }
19433 else if (!quad_p)
19434 {
19435 /* Redo Rn and Rm. */
19436 inst.instruction &= 0xfff0ff50;
19437 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19438 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19439 inst.instruction |= HI4 (inst.operands[2].reg);
19440 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19441 }
19442}
19443
19444static void
19445do_neon_vfmal (void)
19446{
19447 return do_neon_fmac_maybe_scalar_long (0);
19448}
19449
19450static void
19451do_neon_vfmsl (void)
19452{
19453 return do_neon_fmac_maybe_scalar_long (1);
19454}
19455
5287ad62
JB
19456static void
19457do_neon_dyadic_wide (void)
19458{
19459 struct neon_type_el et = neon_check_type (3, NS_QQD,
19460 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19461 neon_mixed_length (et, et.size);
19462}
19463
19464static void
19465do_neon_dyadic_narrow (void)
19466{
19467 struct neon_type_el et = neon_check_type (3, NS_QDD,
19468 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19469 /* Operand sign is unimportant, and the U bit is part of the opcode,
19470 so force the operand type to integer. */
19471 et.type = NT_integer;
5287ad62
JB
19472 neon_mixed_length (et, et.size / 2);
19473}
19474
19475static void
19476do_neon_mul_sat_scalar_long (void)
19477{
19478 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19479}
19480
19481static void
19482do_neon_vmull (void)
19483{
19484 if (inst.operands[2].isscalar)
19485 do_neon_mac_maybe_scalar_long ();
19486 else
19487 {
19488 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19489 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19490
5287ad62 19491 if (et.type == NT_poly)
477330fc 19492 NEON_ENCODE (POLY, inst);
5287ad62 19493 else
477330fc 19494 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19495
19496 /* For polynomial encoding the U bit must be zero, and the size must
19497 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19498 obviously, as 0b10). */
19499 if (et.size == 64)
19500 {
19501 /* Check we're on the correct architecture. */
19502 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19503 inst.error =
19504 _("Instruction form not available on this architecture.");
19505
19506 et.size = 32;
19507 }
19508
5287ad62
JB
19509 neon_mixed_length (et, et.size);
19510 }
19511}
19512
19513static void
19514do_neon_ext (void)
19515{
037e8744 19516 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19517 struct neon_type_el et = neon_check_type (3, rs,
19518 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19519 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19520
19521 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19522 _("shift out of range"));
5287ad62
JB
19523 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19524 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19525 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19526 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19527 inst.instruction |= LOW4 (inst.operands[2].reg);
19528 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19529 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19530 inst.instruction |= imm << 8;
5f4273c7 19531
88714cb8 19532 neon_dp_fixup (&inst);
5287ad62
JB
19533}
19534
19535static void
19536do_neon_rev (void)
19537{
64c350f2 19538 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19539 return;
19540
19541 enum neon_shape rs;
19542 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19543 rs = neon_select_shape (NS_QQ, NS_NULL);
19544 else
19545 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19546
5287ad62
JB
19547 struct neon_type_el et = neon_check_type (2, rs,
19548 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19549
5287ad62
JB
19550 unsigned op = (inst.instruction >> 7) & 3;
19551 /* N (width of reversed regions) is encoded as part of the bitmask. We
19552 extract it here to check the elements to be reversed are smaller.
19553 Otherwise we'd get a reserved instruction. */
19554 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19555
19556 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19557 && inst.operands[0].reg == inst.operands[1].reg)
19558 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19559 " operands makes instruction UNPREDICTABLE"));
19560
9c2799c2 19561 gas_assert (elsize != 0);
5287ad62 19562 constraint (et.size >= elsize,
477330fc 19563 _("elements must be smaller than reversal region"));
037e8744 19564 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19565}
19566
19567static void
19568do_neon_dup (void)
19569{
19570 if (inst.operands[1].isscalar)
19571 {
b409bdb6
AV
19572 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19573 BAD_FPU);
037e8744 19574 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19575 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19576 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19577 unsigned sizebits = et.size >> 3;
dcbf9037 19578 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19579 int logsize = neon_logbits (et.size);
dcbf9037 19580 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19581
19582 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19583 return;
037e8744 19584
88714cb8 19585 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19586 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19587 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19588 inst.instruction |= LOW4 (dm);
19589 inst.instruction |= HI1 (dm) << 5;
037e8744 19590 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19591 inst.instruction |= x << 17;
19592 inst.instruction |= sizebits << 16;
5f4273c7 19593
88714cb8 19594 neon_dp_fixup (&inst);
5287ad62
JB
19595 }
19596 else
19597 {
037e8744
JB
19598 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19599 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19600 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19601 if (rs == NS_QR)
19602 {
64c350f2 19603 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19604 return;
19605 }
19606 else
19607 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19608 BAD_FPU);
19609
19610 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19611 {
19612 if (inst.operands[1].reg == REG_SP)
19613 as_tsktsk (MVE_BAD_SP);
19614 else if (inst.operands[1].reg == REG_PC)
19615 as_tsktsk (MVE_BAD_PC);
19616 }
19617
5287ad62 19618 /* Duplicate ARM register to lanes of vector. */
88714cb8 19619 NEON_ENCODE (ARMREG, inst);
5287ad62 19620 switch (et.size)
477330fc
RM
19621 {
19622 case 8: inst.instruction |= 0x400000; break;
19623 case 16: inst.instruction |= 0x000020; break;
19624 case 32: inst.instruction |= 0x000000; break;
19625 default: break;
19626 }
5287ad62
JB
19627 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19628 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19629 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19630 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19631 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19632 variants, except for the condition field. */
037e8744 19633 do_vfp_cond_or_thumb ();
5287ad62
JB
19634 }
19635}
19636
57785aa2
AV
19637static void
19638do_mve_mov (int toQ)
19639{
19640 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19641 return;
19642 if (inst.cond > COND_ALWAYS)
19643 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19644
19645 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19646 if (toQ)
19647 {
19648 Q0 = 0;
19649 Q1 = 1;
19650 Rt = 2;
19651 Rt2 = 3;
19652 }
19653
19654 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19655 _("Index one must be [2,3] and index two must be two less than"
19656 " index one."));
19657 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
19658 _("General purpose registers may not be the same"));
19659 constraint (inst.operands[Rt].reg == REG_SP
19660 || inst.operands[Rt2].reg == REG_SP,
19661 BAD_SP);
19662 constraint (inst.operands[Rt].reg == REG_PC
19663 || inst.operands[Rt2].reg == REG_PC,
19664 BAD_PC);
19665
19666 inst.instruction = 0xec000f00;
19667 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
19668 inst.instruction |= !!toQ << 20;
19669 inst.instruction |= inst.operands[Rt2].reg << 16;
19670 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
19671 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
19672 inst.instruction |= inst.operands[Rt].reg;
19673}
19674
19675static void
19676do_mve_movn (void)
19677{
19678 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19679 return;
19680
19681 if (inst.cond > COND_ALWAYS)
19682 inst.pred_insn_type = INSIDE_VPT_INSN;
19683 else
19684 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
19685
19686 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
19687 | N_KEY);
19688
19689 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19690 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
19691 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19692 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19693 inst.instruction |= LOW4 (inst.operands[1].reg);
19694 inst.is_neon = 1;
19695
19696}
19697
5287ad62
JB
19698/* VMOV has particularly many variations. It can be one of:
19699 0. VMOV<c><q> <Qd>, <Qm>
19700 1. VMOV<c><q> <Dd>, <Dm>
19701 (Register operations, which are VORR with Rm = Rn.)
19702 2. VMOV<c><q>.<dt> <Qd>, #<imm>
19703 3. VMOV<c><q>.<dt> <Dd>, #<imm>
19704 (Immediate loads.)
19705 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
19706 (ARM register to scalar.)
19707 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
19708 (Two ARM registers to vector.)
19709 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
19710 (Scalar to ARM register.)
19711 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
19712 (Vector to two ARM registers.)
037e8744
JB
19713 8. VMOV.F32 <Sd>, <Sm>
19714 9. VMOV.F64 <Dd>, <Dm>
19715 (VFP register moves.)
19716 10. VMOV.F32 <Sd>, #imm
19717 11. VMOV.F64 <Dd>, #imm
19718 (VFP float immediate load.)
19719 12. VMOV <Rd>, <Sm>
19720 (VFP single to ARM reg.)
19721 13. VMOV <Sd>, <Rm>
19722 (ARM reg to VFP single.)
19723 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
19724 (Two ARM regs to two VFP singles.)
19725 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
19726 (Two VFP singles to two ARM regs.)
57785aa2
AV
19727 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
19728 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
19729 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
19730 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 19731
037e8744
JB
19732 These cases can be disambiguated using neon_select_shape, except cases 1/9
19733 and 3/11 which depend on the operand type too.
5f4273c7 19734
5287ad62 19735 All the encoded bits are hardcoded by this function.
5f4273c7 19736
b7fc2769
JB
19737 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
19738 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 19739
5287ad62 19740 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 19741 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
19742
19743static void
19744do_neon_mov (void)
19745{
57785aa2
AV
19746 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
19747 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
19748 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
19749 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
19750 NS_NULL);
037e8744
JB
19751 struct neon_type_el et;
19752 const char *ldconst = 0;
5287ad62 19753
037e8744 19754 switch (rs)
5287ad62 19755 {
037e8744
JB
19756 case NS_DD: /* case 1/9. */
19757 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19758 /* It is not an error here if no type is given. */
19759 inst.error = NULL;
19760 if (et.type == NT_float && et.size == 64)
477330fc
RM
19761 {
19762 do_vfp_nsyn_opcode ("fcpyd");
19763 break;
19764 }
037e8744 19765 /* fall through. */
5287ad62 19766
037e8744
JB
19767 case NS_QQ: /* case 0/1. */
19768 {
64c350f2
AV
19769 if (!check_simd_pred_availability (FALSE,
19770 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
19771 return;
19772 /* The architecture manual I have doesn't explicitly state which
19773 value the U bit should have for register->register moves, but
19774 the equivalent VORR instruction has U = 0, so do that. */
19775 inst.instruction = 0x0200110;
19776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19778 inst.instruction |= LOW4 (inst.operands[1].reg);
19779 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19780 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19781 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19782 inst.instruction |= neon_quad (rs) << 6;
19783
19784 neon_dp_fixup (&inst);
037e8744
JB
19785 }
19786 break;
5f4273c7 19787
037e8744
JB
19788 case NS_DI: /* case 3/11. */
19789 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19790 inst.error = NULL;
19791 if (et.type == NT_float && et.size == 64)
477330fc
RM
19792 {
19793 /* case 11 (fconstd). */
19794 ldconst = "fconstd";
19795 goto encode_fconstd;
19796 }
037e8744
JB
19797 /* fall through. */
19798
19799 case NS_QI: /* case 2/3. */
64c350f2
AV
19800 if (!check_simd_pred_availability (FALSE,
19801 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 19802 return;
037e8744
JB
19803 inst.instruction = 0x0800010;
19804 neon_move_immediate ();
88714cb8 19805 neon_dp_fixup (&inst);
5287ad62 19806 break;
5f4273c7 19807
037e8744
JB
19808 case NS_SR: /* case 4. */
19809 {
477330fc
RM
19810 unsigned bcdebits = 0;
19811 int logsize;
19812 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
19813 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 19814
05ac0ffb
JB
19815 /* .<size> is optional here, defaulting to .32. */
19816 if (inst.vectype.elems == 0
19817 && inst.operands[0].vectype.type == NT_invtype
19818 && inst.operands[1].vectype.type == NT_invtype)
19819 {
19820 inst.vectype.el[0].type = NT_untyped;
19821 inst.vectype.el[0].size = 32;
19822 inst.vectype.elems = 1;
19823 }
19824
477330fc
RM
19825 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
19826 logsize = neon_logbits (et.size);
19827
57785aa2
AV
19828 if (et.size != 32)
19829 {
19830 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19831 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
19832 return;
19833 }
19834 else
19835 {
19836 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
19837 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
19838 _(BAD_FPU));
19839 }
19840
19841 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19842 {
19843 if (inst.operands[1].reg == REG_SP)
19844 as_tsktsk (MVE_BAD_SP);
19845 else if (inst.operands[1].reg == REG_PC)
19846 as_tsktsk (MVE_BAD_PC);
19847 }
19848 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
19849
477330fc 19850 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
19851 constraint (x >= size / et.size, _("scalar index out of range"));
19852
477330fc
RM
19853
19854 switch (et.size)
19855 {
19856 case 8: bcdebits = 0x8; break;
19857 case 16: bcdebits = 0x1; break;
19858 case 32: bcdebits = 0x0; break;
19859 default: ;
19860 }
19861
57785aa2 19862 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
19863
19864 inst.instruction = 0xe000b10;
19865 do_vfp_cond_or_thumb ();
19866 inst.instruction |= LOW4 (dn) << 16;
19867 inst.instruction |= HI1 (dn) << 7;
19868 inst.instruction |= inst.operands[1].reg << 12;
19869 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
19870 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
19871 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
19872 }
19873 break;
5f4273c7 19874
037e8744 19875 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
19876 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
19877 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 19878 _(BAD_FPU));
b7fc2769 19879
037e8744
JB
19880 inst.instruction = 0xc400b10;
19881 do_vfp_cond_or_thumb ();
19882 inst.instruction |= LOW4 (inst.operands[0].reg);
19883 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
19884 inst.instruction |= inst.operands[1].reg << 12;
19885 inst.instruction |= inst.operands[2].reg << 16;
19886 break;
5f4273c7 19887
037e8744
JB
19888 case NS_RS: /* case 6. */
19889 {
477330fc
RM
19890 unsigned logsize;
19891 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
19892 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
19893 unsigned abcdebits = 0;
037e8744 19894
05ac0ffb
JB
19895 /* .<dt> is optional here, defaulting to .32. */
19896 if (inst.vectype.elems == 0
19897 && inst.operands[0].vectype.type == NT_invtype
19898 && inst.operands[1].vectype.type == NT_invtype)
19899 {
19900 inst.vectype.el[0].type = NT_untyped;
19901 inst.vectype.el[0].size = 32;
19902 inst.vectype.elems = 1;
19903 }
19904
91d6fa6a
NC
19905 et = neon_check_type (2, NS_NULL,
19906 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
19907 logsize = neon_logbits (et.size);
19908
57785aa2
AV
19909 if (et.size != 32)
19910 {
19911 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19912 && vfp_or_neon_is_neon (NEON_CHECK_CC
19913 | NEON_CHECK_ARCH) == FAIL)
19914 return;
19915 }
19916 else
19917 {
19918 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
19919 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
19920 _(BAD_FPU));
19921 }
19922
19923 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19924 {
19925 if (inst.operands[0].reg == REG_SP)
19926 as_tsktsk (MVE_BAD_SP);
19927 else if (inst.operands[0].reg == REG_PC)
19928 as_tsktsk (MVE_BAD_PC);
19929 }
19930
19931 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
19932
477330fc 19933 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 19934 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
19935
19936 switch (et.size)
19937 {
19938 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
19939 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
19940 case 32: abcdebits = 0x00; break;
19941 default: ;
19942 }
19943
57785aa2 19944 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
19945 inst.instruction = 0xe100b10;
19946 do_vfp_cond_or_thumb ();
19947 inst.instruction |= LOW4 (dn) << 16;
19948 inst.instruction |= HI1 (dn) << 7;
19949 inst.instruction |= inst.operands[0].reg << 12;
19950 inst.instruction |= (abcdebits & 3) << 5;
19951 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 19952 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
19953 }
19954 break;
5f4273c7 19955
037e8744 19956 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
19957 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
19958 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 19959 _(BAD_FPU));
037e8744
JB
19960
19961 inst.instruction = 0xc500b10;
19962 do_vfp_cond_or_thumb ();
19963 inst.instruction |= inst.operands[0].reg << 12;
19964 inst.instruction |= inst.operands[1].reg << 16;
19965 inst.instruction |= LOW4 (inst.operands[2].reg);
19966 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19967 break;
5f4273c7 19968
037e8744
JB
19969 case NS_FF: /* case 8 (fcpys). */
19970 do_vfp_nsyn_opcode ("fcpys");
19971 break;
5f4273c7 19972
9db2f6b4 19973 case NS_HI:
037e8744
JB
19974 case NS_FI: /* case 10 (fconsts). */
19975 ldconst = "fconsts";
4ef4710f 19976 encode_fconstd:
58ed5c38
TC
19977 if (!inst.operands[1].immisfloat)
19978 {
4ef4710f 19979 unsigned new_imm;
58ed5c38 19980 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
19981 float imm = (float) inst.operands[1].imm;
19982 memcpy (&new_imm, &imm, sizeof (float));
19983 /* But the assembly may have been written to provide an integer
19984 bit pattern that equates to a float, so check that the
19985 conversion has worked. */
19986 if (is_quarter_float (new_imm))
19987 {
19988 if (is_quarter_float (inst.operands[1].imm))
19989 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
19990
19991 inst.operands[1].imm = new_imm;
19992 inst.operands[1].immisfloat = 1;
19993 }
58ed5c38
TC
19994 }
19995
037e8744 19996 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
19997 {
19998 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
19999 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20000
20001 /* ARMv8.2 fp16 vmov.f16 instruction. */
20002 if (rs == NS_HI)
20003 do_scalar_fp16_v82_encode ();
477330fc 20004 }
5287ad62 20005 else
477330fc 20006 first_error (_("immediate out of range"));
037e8744 20007 break;
5f4273c7 20008
9db2f6b4 20009 case NS_RH:
037e8744
JB
20010 case NS_RF: /* case 12 (fmrs). */
20011 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20012 /* ARMv8.2 fp16 vmov.f16 instruction. */
20013 if (rs == NS_RH)
20014 do_scalar_fp16_v82_encode ();
037e8744 20015 break;
5f4273c7 20016
9db2f6b4 20017 case NS_HR:
037e8744
JB
20018 case NS_FR: /* case 13 (fmsr). */
20019 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20020 /* ARMv8.2 fp16 vmov.f16 instruction. */
20021 if (rs == NS_HR)
20022 do_scalar_fp16_v82_encode ();
037e8744 20023 break;
5f4273c7 20024
57785aa2
AV
20025 case NS_RRSS:
20026 do_mve_mov (0);
20027 break;
20028 case NS_SSRR:
20029 do_mve_mov (1);
20030 break;
20031
037e8744
JB
20032 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20033 (one of which is a list), but we have parsed four. Do some fiddling to
20034 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20035 expect. */
20036 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20037 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20038 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20039 _(BAD_FPU));
037e8744 20040 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20041 _("VFP registers must be adjacent"));
037e8744
JB
20042 inst.operands[2].imm = 2;
20043 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20044 do_vfp_nsyn_opcode ("fmrrs");
20045 break;
5f4273c7 20046
037e8744 20047 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20049 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20050 _(BAD_FPU));
037e8744 20051 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20052 _("VFP registers must be adjacent"));
037e8744
JB
20053 inst.operands[1] = inst.operands[2];
20054 inst.operands[2] = inst.operands[3];
20055 inst.operands[0].imm = 2;
20056 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20057 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20058 break;
5f4273c7 20059
4c261dff
NC
20060 case NS_NULL:
20061 /* neon_select_shape has determined that the instruction
20062 shape is wrong and has already set the error message. */
20063 break;
20064
5287ad62
JB
20065 default:
20066 abort ();
20067 }
20068}
20069
57785aa2
AV
20070static void
20071do_mve_movl (void)
20072{
20073 if (!(inst.operands[0].present && inst.operands[0].isquad
20074 && inst.operands[1].present && inst.operands[1].isquad
20075 && !inst.operands[2].present))
20076 {
20077 inst.instruction = 0;
20078 inst.cond = 0xb;
20079 if (thumb_mode)
20080 set_pred_insn_type (INSIDE_IT_INSN);
20081 do_neon_mov ();
20082 return;
20083 }
20084
20085 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20086 return;
20087
20088 if (inst.cond != COND_ALWAYS)
20089 inst.pred_insn_type = INSIDE_VPT_INSN;
20090
20091 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20092 | N_S16 | N_U16 | N_KEY);
20093
20094 inst.instruction |= (et.type == NT_unsigned) << 28;
20095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20096 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20097 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20098 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20099 inst.instruction |= LOW4 (inst.operands[1].reg);
20100 inst.is_neon = 1;
20101}
20102
5287ad62
JB
20103static void
20104do_neon_rshift_round_imm (void)
20105{
64c350f2 20106 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20107 return;
20108
20109 enum neon_shape rs;
20110 struct neon_type_el et;
20111
20112 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20113 {
20114 rs = neon_select_shape (NS_QQI, NS_NULL);
20115 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20116 }
20117 else
20118 {
20119 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20120 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20121 }
5287ad62
JB
20122 int imm = inst.operands[2].imm;
20123
20124 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20125 if (imm == 0)
20126 {
20127 inst.operands[2].present = 0;
20128 do_neon_mov ();
20129 return;
20130 }
20131
20132 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20133 _("immediate out of range for shift"));
037e8744 20134 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20135 et.size - imm);
5287ad62
JB
20136}
20137
9db2f6b4
RL
20138static void
20139do_neon_movhf (void)
20140{
20141 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20142 constraint (rs != NS_HH, _("invalid suffix"));
20143
7bdf778b
ASDV
20144 if (inst.cond != COND_ALWAYS)
20145 {
20146 if (thumb_mode)
20147 {
20148 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20149 " the behaviour is UNPREDICTABLE"));
20150 }
20151 else
20152 {
20153 inst.error = BAD_COND;
20154 return;
20155 }
20156 }
20157
9db2f6b4
RL
20158 do_vfp_sp_monadic ();
20159
20160 inst.is_neon = 1;
20161 inst.instruction |= 0xf0000000;
20162}
20163
5287ad62
JB
20164static void
20165do_neon_movl (void)
20166{
20167 struct neon_type_el et = neon_check_type (2, NS_QD,
20168 N_EQK | N_DBL, N_SU_32 | N_KEY);
20169 unsigned sizebits = et.size >> 3;
20170 inst.instruction |= sizebits << 19;
20171 neon_two_same (0, et.type == NT_unsigned, -1);
20172}
20173
20174static void
20175do_neon_trn (void)
20176{
037e8744 20177 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20178 struct neon_type_el et = neon_check_type (2, rs,
20179 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20180 NEON_ENCODE (INTEGER, inst);
037e8744 20181 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20182}
20183
20184static void
20185do_neon_zip_uzp (void)
20186{
037e8744 20187 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20188 struct neon_type_el et = neon_check_type (2, rs,
20189 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20190 if (rs == NS_DD && et.size == 32)
20191 {
20192 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20193 inst.instruction = N_MNEM_vtrn;
20194 do_neon_trn ();
20195 return;
20196 }
037e8744 20197 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20198}
20199
20200static void
20201do_neon_sat_abs_neg (void)
20202{
64c350f2 20203 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20204 return;
20205
20206 enum neon_shape rs;
20207 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20208 rs = neon_select_shape (NS_QQ, NS_NULL);
20209 else
20210 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20211 struct neon_type_el et = neon_check_type (2, rs,
20212 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20213 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20214}
20215
20216static void
20217do_neon_pair_long (void)
20218{
037e8744 20219 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20220 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20221 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20222 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20223 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20224}
20225
20226static void
20227do_neon_recip_est (void)
20228{
037e8744 20229 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20230 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20231 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20232 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20233 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20234}
20235
20236static void
20237do_neon_cls (void)
20238{
64c350f2 20239 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20240 return;
20241
20242 enum neon_shape rs;
20243 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20244 rs = neon_select_shape (NS_QQ, NS_NULL);
20245 else
20246 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20247
5287ad62
JB
20248 struct neon_type_el et = neon_check_type (2, rs,
20249 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20250 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20251}
20252
20253static void
20254do_neon_clz (void)
20255{
64c350f2 20256 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20257 return;
20258
20259 enum neon_shape rs;
20260 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20261 rs = neon_select_shape (NS_QQ, NS_NULL);
20262 else
20263 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20264
5287ad62
JB
20265 struct neon_type_el et = neon_check_type (2, rs,
20266 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20267 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20268}
20269
20270static void
20271do_neon_cnt (void)
20272{
037e8744 20273 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20274 struct neon_type_el et = neon_check_type (2, rs,
20275 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20276 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20277}
20278
20279static void
20280do_neon_swp (void)
20281{
037e8744
JB
20282 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20283 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20284}
20285
20286static void
20287do_neon_tbl_tbx (void)
20288{
20289 unsigned listlenbits;
dcbf9037 20290 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20291
5287ad62
JB
20292 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20293 {
dcbf9037 20294 first_error (_("bad list length for table lookup"));
5287ad62
JB
20295 return;
20296 }
5f4273c7 20297
5287ad62
JB
20298 listlenbits = inst.operands[1].imm - 1;
20299 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20300 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20301 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20302 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20303 inst.instruction |= LOW4 (inst.operands[2].reg);
20304 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20305 inst.instruction |= listlenbits << 8;
5f4273c7 20306
88714cb8 20307 neon_dp_fixup (&inst);
5287ad62
JB
20308}
20309
20310static void
20311do_neon_ldm_stm (void)
20312{
20313 /* P, U and L bits are part of bitmask. */
20314 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20315 unsigned offsetbits = inst.operands[1].imm * 2;
20316
037e8744
JB
20317 if (inst.operands[1].issingle)
20318 {
20319 do_vfp_nsyn_ldm_stm (is_dbmode);
20320 return;
20321 }
20322
5287ad62 20323 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20324 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20325
20326 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20327 _("register list must contain at least 1 and at most 16 "
20328 "registers"));
5287ad62
JB
20329
20330 inst.instruction |= inst.operands[0].reg << 16;
20331 inst.instruction |= inst.operands[0].writeback << 21;
20332 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20333 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20334
20335 inst.instruction |= offsetbits;
5f4273c7 20336
037e8744 20337 do_vfp_cond_or_thumb ();
5287ad62
JB
20338}
20339
20340static void
20341do_neon_ldr_str (void)
20342{
5287ad62 20343 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20344
6844b2c2
MGD
20345 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20346 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20347 if (!is_ldr
6844b2c2 20348 && inst.operands[1].reg == REG_PC
ba86b375 20349 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20350 {
94dcf8bf 20351 if (thumb_mode)
6844b2c2 20352 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20353 else if (warn_on_deprecated)
5c3696f8 20354 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20355 }
20356
037e8744
JB
20357 if (inst.operands[0].issingle)
20358 {
cd2f129f 20359 if (is_ldr)
477330fc 20360 do_vfp_nsyn_opcode ("flds");
cd2f129f 20361 else
477330fc 20362 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20363
20364 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20365 if (inst.vectype.el[0].size == 16)
20366 do_scalar_fp16_v82_encode ();
5287ad62
JB
20367 }
20368 else
5287ad62 20369 {
cd2f129f 20370 if (is_ldr)
477330fc 20371 do_vfp_nsyn_opcode ("fldd");
5287ad62 20372 else
477330fc 20373 do_vfp_nsyn_opcode ("fstd");
5287ad62 20374 }
5287ad62
JB
20375}
20376
32c36c3c
AV
20377static void
20378do_t_vldr_vstr_sysreg (void)
20379{
20380 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20381 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20382
20383 /* Use of PC is UNPREDICTABLE. */
20384 if (inst.operands[1].reg == REG_PC)
20385 inst.error = _("Use of PC here is UNPREDICTABLE");
20386
20387 if (inst.operands[1].immisreg)
20388 inst.error = _("instruction does not accept register index");
20389
20390 if (!inst.operands[1].isreg)
20391 inst.error = _("instruction does not accept PC-relative addressing");
20392
20393 if (abs (inst.operands[1].imm) >= (1 << 7))
20394 inst.error = _("immediate value out of range");
20395
20396 inst.instruction = 0xec000f80;
20397 if (is_vldr)
20398 inst.instruction |= 1 << sysreg_vldr_bitno;
20399 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20400 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20401 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20402}
20403
20404static void
20405do_vldr_vstr (void)
20406{
20407 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20408
20409 /* VLDR/VSTR (System Register). */
20410 if (sysreg_op)
20411 {
20412 if (!mark_feature_used (&arm_ext_v8_1m_main))
20413 as_bad (_("Instruction not permitted on this architecture"));
20414
20415 do_t_vldr_vstr_sysreg ();
20416 }
20417 /* VLDR/VSTR. */
20418 else
20419 {
20420 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
20421 as_bad (_("Instruction not permitted on this architecture"));
20422 do_neon_ldr_str ();
20423 }
20424}
20425
5287ad62
JB
20426/* "interleave" version also handles non-interleaving register VLD1/VST1
20427 instructions. */
20428
20429static void
20430do_neon_ld_st_interleave (void)
20431{
037e8744 20432 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20433 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20434 unsigned alignbits = 0;
20435 unsigned idx;
20436 /* The bits in this table go:
20437 0: register stride of one (0) or two (1)
20438 1,2: register list length, minus one (1, 2, 3, 4).
20439 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20440 We use -1 for invalid entries. */
20441 const int typetable[] =
20442 {
20443 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20444 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20445 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20446 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20447 };
20448 int typebits;
20449
dcbf9037
JB
20450 if (et.type == NT_invtype)
20451 return;
20452
5287ad62
JB
20453 if (inst.operands[1].immisalign)
20454 switch (inst.operands[1].imm >> 8)
20455 {
20456 case 64: alignbits = 1; break;
20457 case 128:
477330fc 20458 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20459 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20460 goto bad_alignment;
20461 alignbits = 2;
20462 break;
5287ad62 20463 case 256:
477330fc
RM
20464 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20465 goto bad_alignment;
20466 alignbits = 3;
20467 break;
5287ad62
JB
20468 default:
20469 bad_alignment:
477330fc
RM
20470 first_error (_("bad alignment"));
20471 return;
5287ad62
JB
20472 }
20473
20474 inst.instruction |= alignbits << 4;
20475 inst.instruction |= neon_logbits (et.size) << 6;
20476
20477 /* Bits [4:6] of the immediate in a list specifier encode register stride
20478 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20479 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20480 up the right value for "type" in a table based on this value and the given
20481 list style, then stick it back. */
20482 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20483 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20484
20485 typebits = typetable[idx];
5f4273c7 20486
5287ad62 20487 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20488 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20489 BAD_EL_TYPE);
5287ad62
JB
20490
20491 inst.instruction &= ~0xf00;
20492 inst.instruction |= typebits << 8;
20493}
20494
20495/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20496 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20497 otherwise. The variable arguments are a list of pairs of legal (size, align)
20498 values, terminated with -1. */
20499
20500static int
aa8a0863 20501neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20502{
20503 va_list ap;
20504 int result = FAIL, thissize, thisalign;
5f4273c7 20505
5287ad62
JB
20506 if (!inst.operands[1].immisalign)
20507 {
aa8a0863 20508 *do_alignment = 0;
5287ad62
JB
20509 return SUCCESS;
20510 }
5f4273c7 20511
aa8a0863 20512 va_start (ap, do_alignment);
5287ad62
JB
20513
20514 do
20515 {
20516 thissize = va_arg (ap, int);
20517 if (thissize == -1)
477330fc 20518 break;
5287ad62
JB
20519 thisalign = va_arg (ap, int);
20520
20521 if (size == thissize && align == thisalign)
477330fc 20522 result = SUCCESS;
5287ad62
JB
20523 }
20524 while (result != SUCCESS);
20525
20526 va_end (ap);
20527
20528 if (result == SUCCESS)
aa8a0863 20529 *do_alignment = 1;
5287ad62 20530 else
dcbf9037 20531 first_error (_("unsupported alignment for instruction"));
5f4273c7 20532
5287ad62
JB
20533 return result;
20534}
20535
20536static void
20537do_neon_ld_st_lane (void)
20538{
037e8744 20539 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20540 int align_good, do_alignment = 0;
5287ad62
JB
20541 int logsize = neon_logbits (et.size);
20542 int align = inst.operands[1].imm >> 8;
20543 int n = (inst.instruction >> 8) & 3;
20544 int max_el = 64 / et.size;
5f4273c7 20545
dcbf9037
JB
20546 if (et.type == NT_invtype)
20547 return;
5f4273c7 20548
5287ad62 20549 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20550 _("bad list length"));
5287ad62 20551 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20552 _("scalar index out of range"));
5287ad62 20553 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20554 && et.size == 8,
20555 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20556
5287ad62
JB
20557 switch (n)
20558 {
20559 case 0: /* VLD1 / VST1. */
aa8a0863 20560 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20561 32, 32, -1);
5287ad62 20562 if (align_good == FAIL)
477330fc 20563 return;
aa8a0863 20564 if (do_alignment)
477330fc
RM
20565 {
20566 unsigned alignbits = 0;
20567 switch (et.size)
20568 {
20569 case 16: alignbits = 0x1; break;
20570 case 32: alignbits = 0x3; break;
20571 default: ;
20572 }
20573 inst.instruction |= alignbits << 4;
20574 }
5287ad62
JB
20575 break;
20576
20577 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20578 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20579 16, 32, 32, 64, -1);
5287ad62 20580 if (align_good == FAIL)
477330fc 20581 return;
aa8a0863 20582 if (do_alignment)
477330fc 20583 inst.instruction |= 1 << 4;
5287ad62
JB
20584 break;
20585
20586 case 2: /* VLD3 / VST3. */
20587 constraint (inst.operands[1].immisalign,
477330fc 20588 _("can't use alignment with this instruction"));
5287ad62
JB
20589 break;
20590
20591 case 3: /* VLD4 / VST4. */
aa8a0863 20592 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 20593 16, 64, 32, 64, 32, 128, -1);
5287ad62 20594 if (align_good == FAIL)
477330fc 20595 return;
aa8a0863 20596 if (do_alignment)
477330fc
RM
20597 {
20598 unsigned alignbits = 0;
20599 switch (et.size)
20600 {
20601 case 8: alignbits = 0x1; break;
20602 case 16: alignbits = 0x1; break;
20603 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20604 default: ;
20605 }
20606 inst.instruction |= alignbits << 4;
20607 }
5287ad62
JB
20608 break;
20609
20610 default: ;
20611 }
20612
20613 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
20614 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20615 inst.instruction |= 1 << (4 + logsize);
5f4273c7 20616
5287ad62
JB
20617 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
20618 inst.instruction |= logsize << 10;
20619}
20620
20621/* Encode single n-element structure to all lanes VLD<n> instructions. */
20622
20623static void
20624do_neon_ld_dup (void)
20625{
037e8744 20626 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20627 int align_good, do_alignment = 0;
5287ad62 20628
dcbf9037
JB
20629 if (et.type == NT_invtype)
20630 return;
20631
5287ad62
JB
20632 switch ((inst.instruction >> 8) & 3)
20633 {
20634 case 0: /* VLD1. */
9c2799c2 20635 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 20636 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 20637 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 20638 if (align_good == FAIL)
477330fc 20639 return;
5287ad62 20640 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
20641 {
20642 case 1: break;
20643 case 2: inst.instruction |= 1 << 5; break;
20644 default: first_error (_("bad list length")); return;
20645 }
5287ad62
JB
20646 inst.instruction |= neon_logbits (et.size) << 6;
20647 break;
20648
20649 case 1: /* VLD2. */
20650 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
20651 &do_alignment, 8, 16, 16, 32, 32, 64,
20652 -1);
5287ad62 20653 if (align_good == FAIL)
477330fc 20654 return;
5287ad62 20655 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 20656 _("bad list length"));
5287ad62 20657 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 20658 inst.instruction |= 1 << 5;
5287ad62
JB
20659 inst.instruction |= neon_logbits (et.size) << 6;
20660 break;
20661
20662 case 2: /* VLD3. */
20663 constraint (inst.operands[1].immisalign,
477330fc 20664 _("can't use alignment with this instruction"));
5287ad62 20665 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 20666 _("bad list length"));
5287ad62 20667 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 20668 inst.instruction |= 1 << 5;
5287ad62
JB
20669 inst.instruction |= neon_logbits (et.size) << 6;
20670 break;
20671
20672 case 3: /* VLD4. */
20673 {
477330fc 20674 int align = inst.operands[1].imm >> 8;
aa8a0863 20675 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
20676 16, 64, 32, 64, 32, 128, -1);
20677 if (align_good == FAIL)
20678 return;
20679 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
20680 _("bad list length"));
20681 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20682 inst.instruction |= 1 << 5;
20683 if (et.size == 32 && align == 128)
20684 inst.instruction |= 0x3 << 6;
20685 else
20686 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
20687 }
20688 break;
20689
20690 default: ;
20691 }
20692
aa8a0863 20693 inst.instruction |= do_alignment << 4;
5287ad62
JB
20694}
20695
20696/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
20697 apart from bits [11:4]. */
20698
20699static void
20700do_neon_ldx_stx (void)
20701{
b1a769ed
DG
20702 if (inst.operands[1].isreg)
20703 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
20704
5287ad62
JB
20705 switch (NEON_LANE (inst.operands[0].imm))
20706 {
20707 case NEON_INTERLEAVE_LANES:
88714cb8 20708 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
20709 do_neon_ld_st_interleave ();
20710 break;
5f4273c7 20711
5287ad62 20712 case NEON_ALL_LANES:
88714cb8 20713 NEON_ENCODE (DUP, inst);
2d51fb74
JB
20714 if (inst.instruction == N_INV)
20715 {
20716 first_error ("only loads support such operands");
20717 break;
20718 }
5287ad62
JB
20719 do_neon_ld_dup ();
20720 break;
5f4273c7 20721
5287ad62 20722 default:
88714cb8 20723 NEON_ENCODE (LANE, inst);
5287ad62
JB
20724 do_neon_ld_st_lane ();
20725 }
20726
20727 /* L bit comes from bit mask. */
20728 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20729 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20730 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 20731
5287ad62
JB
20732 if (inst.operands[1].postind)
20733 {
20734 int postreg = inst.operands[1].imm & 0xf;
20735 constraint (!inst.operands[1].immisreg,
477330fc 20736 _("post-index must be a register"));
5287ad62 20737 constraint (postreg == 0xd || postreg == 0xf,
477330fc 20738 _("bad register for post-index"));
5287ad62
JB
20739 inst.instruction |= postreg;
20740 }
4f2374c7 20741 else
5287ad62 20742 {
4f2374c7 20743 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
20744 constraint (inst.relocs[0].exp.X_op != O_constant
20745 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
20746 BAD_ADDR_MODE);
20747
20748 if (inst.operands[1].writeback)
20749 {
20750 inst.instruction |= 0xd;
20751 }
20752 else
20753 inst.instruction |= 0xf;
5287ad62 20754 }
5f4273c7 20755
5287ad62
JB
20756 if (thumb_mode)
20757 inst.instruction |= 0xf9000000;
20758 else
20759 inst.instruction |= 0xf4000000;
20760}
33399f07
MGD
20761
20762/* FP v8. */
20763static void
20764do_vfp_nsyn_fpv8 (enum neon_shape rs)
20765{
a715796b
TG
20766 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20767 D register operands. */
20768 if (neon_shape_class[rs] == SC_DOUBLE)
20769 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20770 _(BAD_FPU));
20771
33399f07
MGD
20772 NEON_ENCODE (FPV8, inst);
20773
9db2f6b4
RL
20774 if (rs == NS_FFF || rs == NS_HHH)
20775 {
20776 do_vfp_sp_dyadic ();
20777
20778 /* ARMv8.2 fp16 instruction. */
20779 if (rs == NS_HHH)
20780 do_scalar_fp16_v82_encode ();
20781 }
33399f07
MGD
20782 else
20783 do_vfp_dp_rd_rn_rm ();
20784
20785 if (rs == NS_DDD)
20786 inst.instruction |= 0x100;
20787
20788 inst.instruction |= 0xf0000000;
20789}
20790
20791static void
20792do_vsel (void)
20793{
5ee91343 20794 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
20795
20796 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
20797 first_error (_("invalid instruction shape"));
20798}
20799
73924fbc
MGD
20800static void
20801do_vmaxnm (void)
20802{
935295b5
AV
20803 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20804 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
20805
20806 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
20807 return;
20808
64c350f2 20809 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
20810 return;
20811
cc933301 20812 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
20813}
20814
30bdf752
MGD
20815static void
20816do_vrint_1 (enum neon_cvt_mode mode)
20817{
9db2f6b4 20818 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
20819 struct neon_type_el et;
20820
20821 if (rs == NS_NULL)
20822 return;
20823
a715796b
TG
20824 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20825 D register operands. */
20826 if (neon_shape_class[rs] == SC_DOUBLE)
20827 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20828 _(BAD_FPU));
20829
9db2f6b4
RL
20830 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
20831 | N_VFP);
30bdf752
MGD
20832 if (et.type != NT_invtype)
20833 {
20834 /* VFP encodings. */
20835 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
20836 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 20837 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
20838
20839 NEON_ENCODE (FPV8, inst);
9db2f6b4 20840 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
20841 do_vfp_sp_monadic ();
20842 else
20843 do_vfp_dp_rd_rm ();
20844
20845 switch (mode)
20846 {
20847 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
20848 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
20849 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
20850 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
20851 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
20852 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
20853 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
20854 default: abort ();
20855 }
20856
20857 inst.instruction |= (rs == NS_DD) << 8;
20858 do_vfp_cond_or_thumb ();
9db2f6b4
RL
20859
20860 /* ARMv8.2 fp16 vrint instruction. */
20861 if (rs == NS_HH)
20862 do_scalar_fp16_v82_encode ();
30bdf752
MGD
20863 }
20864 else
20865 {
20866 /* Neon encodings (or something broken...). */
20867 inst.error = NULL;
cc933301 20868 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
20869
20870 if (et.type == NT_invtype)
20871 return;
20872
64c350f2
AV
20873 if (!check_simd_pred_availability (TRUE,
20874 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
20875 return;
20876
a710b305
AV
20877 NEON_ENCODE (FLOAT, inst);
20878
30bdf752
MGD
20879 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20880 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20881 inst.instruction |= LOW4 (inst.operands[1].reg);
20882 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20883 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
20884 /* Mask off the original size bits and reencode them. */
20885 inst.instruction = ((inst.instruction & 0xfff3ffff)
20886 | neon_logbits (et.size) << 18);
20887
30bdf752
MGD
20888 switch (mode)
20889 {
20890 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
20891 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
20892 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
20893 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
20894 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
20895 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
20896 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
20897 default: abort ();
20898 }
20899
20900 if (thumb_mode)
20901 inst.instruction |= 0xfc000000;
20902 else
20903 inst.instruction |= 0xf0000000;
20904 }
20905}
20906
20907static void
20908do_vrintx (void)
20909{
20910 do_vrint_1 (neon_cvt_mode_x);
20911}
20912
20913static void
20914do_vrintz (void)
20915{
20916 do_vrint_1 (neon_cvt_mode_z);
20917}
20918
20919static void
20920do_vrintr (void)
20921{
20922 do_vrint_1 (neon_cvt_mode_r);
20923}
20924
20925static void
20926do_vrinta (void)
20927{
20928 do_vrint_1 (neon_cvt_mode_a);
20929}
20930
20931static void
20932do_vrintn (void)
20933{
20934 do_vrint_1 (neon_cvt_mode_n);
20935}
20936
20937static void
20938do_vrintp (void)
20939{
20940 do_vrint_1 (neon_cvt_mode_p);
20941}
20942
20943static void
20944do_vrintm (void)
20945{
20946 do_vrint_1 (neon_cvt_mode_m);
20947}
20948
c28eeff2
SN
20949static unsigned
20950neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
20951{
20952 unsigned regno = NEON_SCALAR_REG (opnd);
20953 unsigned elno = NEON_SCALAR_INDEX (opnd);
20954
20955 if (elsize == 16 && elno < 2 && regno < 16)
20956 return regno | (elno << 4);
20957 else if (elsize == 32 && elno == 0)
20958 return regno;
20959
20960 first_error (_("scalar out of range"));
20961 return 0;
20962}
20963
20964static void
20965do_vcmla (void)
20966{
5d281bf0
AV
20967 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
20968 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
20969 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
20970 constraint (inst.relocs[0].exp.X_op != O_constant,
20971 _("expression too complex"));
20972 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
20973 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
20974 _("immediate out of range"));
20975 rot /= 90;
5d281bf0 20976
64c350f2
AV
20977 if (!check_simd_pred_availability (TRUE,
20978 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
20979 return;
20980
c28eeff2
SN
20981 if (inst.operands[2].isscalar)
20982 {
5d281bf0
AV
20983 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
20984 first_error (_("invalid instruction shape"));
c28eeff2
SN
20985 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
20986 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
20987 N_KEY | N_F16 | N_F32).size;
20988 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
20989 inst.is_neon = 1;
20990 inst.instruction = 0xfe000800;
20991 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20992 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20993 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20994 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20995 inst.instruction |= LOW4 (m);
20996 inst.instruction |= HI1 (m) << 5;
20997 inst.instruction |= neon_quad (rs) << 6;
20998 inst.instruction |= rot << 20;
20999 inst.instruction |= (size == 32) << 23;
21000 }
21001 else
21002 {
5d281bf0
AV
21003 enum neon_shape rs;
21004 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21005 rs = neon_select_shape (NS_QQQI, NS_NULL);
21006 else
21007 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21008
c28eeff2
SN
21009 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21010 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21011 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21012 && (inst.operands[0].reg == inst.operands[1].reg
21013 || inst.operands[0].reg == inst.operands[2].reg))
21014 as_tsktsk (BAD_MVE_SRCDEST);
21015
c28eeff2
SN
21016 neon_three_same (neon_quad (rs), 0, -1);
21017 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21018 inst.instruction |= 0xfc200800;
21019 inst.instruction |= rot << 23;
21020 inst.instruction |= (size == 32) << 20;
21021 }
21022}
21023
21024static void
21025do_vcadd (void)
21026{
5d281bf0
AV
21027 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21028 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21029 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21030 constraint (inst.relocs[0].exp.X_op != O_constant,
21031 _("expression too complex"));
5d281bf0 21032
e2b0ab59 21033 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21034 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21035 enum neon_shape rs;
21036 struct neon_type_el et;
21037 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21038 {
21039 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21040 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21041 }
21042 else
21043 {
21044 rs = neon_select_shape (NS_QQQI, NS_NULL);
21045 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21046 | N_I16 | N_I32);
21047 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21048 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21049 "operand makes instruction UNPREDICTABLE"));
21050 }
21051
21052 if (et.type == NT_invtype)
21053 return;
21054
64c350f2
AV
21055 if (!check_simd_pred_availability (et.type == NT_float,
21056 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21057 return;
21058
21059 if (et.type == NT_float)
21060 {
21061 neon_three_same (neon_quad (rs), 0, -1);
21062 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21063 inst.instruction |= 0xfc800800;
21064 inst.instruction |= (rot == 270) << 24;
21065 inst.instruction |= (et.size == 32) << 20;
21066 }
21067 else
21068 {
21069 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21070 inst.instruction = 0xfe000f00;
21071 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21072 inst.instruction |= neon_logbits (et.size) << 20;
21073 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21075 inst.instruction |= (rot == 270) << 12;
21076 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21077 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21078 inst.instruction |= LOW4 (inst.operands[2].reg);
21079 inst.is_neon = 1;
21080 }
c28eeff2
SN
21081}
21082
c604a79a
JW
21083/* Dot Product instructions encoding support. */
21084
21085static void
21086do_neon_dotproduct (int unsigned_p)
21087{
21088 enum neon_shape rs;
21089 unsigned scalar_oprd2 = 0;
21090 int high8;
21091
21092 if (inst.cond != COND_ALWAYS)
21093 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21094 "is UNPREDICTABLE"));
21095
21096 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21097 _(BAD_FPU));
21098
21099 /* Dot Product instructions are in three-same D/Q register format or the third
21100 operand can be a scalar index register. */
21101 if (inst.operands[2].isscalar)
21102 {
21103 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21104 high8 = 0xfe000000;
21105 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21106 }
21107 else
21108 {
21109 high8 = 0xfc000000;
21110 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21111 }
21112
21113 if (unsigned_p)
21114 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21115 else
21116 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21117
21118 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21119 Product instruction, so we pass 0 as the "ubit" parameter. And the
21120 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21121 neon_three_same (neon_quad (rs), 0, 32);
21122
21123 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21124 different NEON three-same encoding. */
21125 inst.instruction &= 0x00ffffff;
21126 inst.instruction |= high8;
21127 /* Encode 'U' bit which indicates signedness. */
21128 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21129 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21130 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21131 the instruction encoding. */
21132 if (inst.operands[2].isscalar)
21133 {
21134 inst.instruction &= 0xffffffd0;
21135 inst.instruction |= LOW4 (scalar_oprd2);
21136 inst.instruction |= HI1 (scalar_oprd2) << 5;
21137 }
21138}
21139
21140/* Dot Product instructions for signed integer. */
21141
21142static void
21143do_neon_dotproduct_s (void)
21144{
21145 return do_neon_dotproduct (0);
21146}
21147
21148/* Dot Product instructions for unsigned integer. */
21149
21150static void
21151do_neon_dotproduct_u (void)
21152{
21153 return do_neon_dotproduct (1);
21154}
21155
91ff7894
MGD
21156/* Crypto v1 instructions. */
21157static void
21158do_crypto_2op_1 (unsigned elttype, int op)
21159{
5ee91343 21160 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
21161
21162 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
21163 == NT_invtype)
21164 return;
21165
21166 inst.error = NULL;
21167
21168 NEON_ENCODE (INTEGER, inst);
21169 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21170 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21171 inst.instruction |= LOW4 (inst.operands[1].reg);
21172 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21173 if (op != -1)
21174 inst.instruction |= op << 6;
21175
21176 if (thumb_mode)
21177 inst.instruction |= 0xfc000000;
21178 else
21179 inst.instruction |= 0xf0000000;
21180}
21181
48adcd8e
MGD
21182static void
21183do_crypto_3op_1 (int u, int op)
21184{
5ee91343 21185 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
21186
21187 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
21188 N_32 | N_UNT | N_KEY).type == NT_invtype)
21189 return;
21190
21191 inst.error = NULL;
21192
21193 NEON_ENCODE (INTEGER, inst);
21194 neon_three_same (1, u, 8 << op);
21195}
21196
91ff7894
MGD
21197static void
21198do_aese (void)
21199{
21200 do_crypto_2op_1 (N_8, 0);
21201}
21202
21203static void
21204do_aesd (void)
21205{
21206 do_crypto_2op_1 (N_8, 1);
21207}
21208
21209static void
21210do_aesmc (void)
21211{
21212 do_crypto_2op_1 (N_8, 2);
21213}
21214
21215static void
21216do_aesimc (void)
21217{
21218 do_crypto_2op_1 (N_8, 3);
21219}
21220
48adcd8e
MGD
21221static void
21222do_sha1c (void)
21223{
21224 do_crypto_3op_1 (0, 0);
21225}
21226
21227static void
21228do_sha1p (void)
21229{
21230 do_crypto_3op_1 (0, 1);
21231}
21232
21233static void
21234do_sha1m (void)
21235{
21236 do_crypto_3op_1 (0, 2);
21237}
21238
21239static void
21240do_sha1su0 (void)
21241{
21242 do_crypto_3op_1 (0, 3);
21243}
91ff7894 21244
48adcd8e
MGD
21245static void
21246do_sha256h (void)
21247{
21248 do_crypto_3op_1 (1, 0);
21249}
21250
21251static void
21252do_sha256h2 (void)
21253{
21254 do_crypto_3op_1 (1, 1);
21255}
21256
21257static void
21258do_sha256su1 (void)
21259{
21260 do_crypto_3op_1 (1, 2);
21261}
3c9017d2
MGD
21262
21263static void
21264do_sha1h (void)
21265{
21266 do_crypto_2op_1 (N_32, -1);
21267}
21268
21269static void
21270do_sha1su1 (void)
21271{
21272 do_crypto_2op_1 (N_32, 0);
21273}
21274
21275static void
21276do_sha256su0 (void)
21277{
21278 do_crypto_2op_1 (N_32, 1);
21279}
dd5181d5
KT
21280
21281static void
21282do_crc32_1 (unsigned int poly, unsigned int sz)
21283{
21284 unsigned int Rd = inst.operands[0].reg;
21285 unsigned int Rn = inst.operands[1].reg;
21286 unsigned int Rm = inst.operands[2].reg;
21287
5ee91343 21288 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
21289 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
21290 inst.instruction |= LOW4 (Rn) << 16;
21291 inst.instruction |= LOW4 (Rm);
21292 inst.instruction |= sz << (thumb_mode ? 4 : 21);
21293 inst.instruction |= poly << (thumb_mode ? 20 : 9);
21294
21295 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
21296 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
21297}
21298
21299static void
21300do_crc32b (void)
21301{
21302 do_crc32_1 (0, 0);
21303}
21304
21305static void
21306do_crc32h (void)
21307{
21308 do_crc32_1 (0, 1);
21309}
21310
21311static void
21312do_crc32w (void)
21313{
21314 do_crc32_1 (0, 2);
21315}
21316
21317static void
21318do_crc32cb (void)
21319{
21320 do_crc32_1 (1, 0);
21321}
21322
21323static void
21324do_crc32ch (void)
21325{
21326 do_crc32_1 (1, 1);
21327}
21328
21329static void
21330do_crc32cw (void)
21331{
21332 do_crc32_1 (1, 2);
21333}
21334
49e8a725
SN
21335static void
21336do_vjcvt (void)
21337{
21338 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21339 _(BAD_FPU));
21340 neon_check_type (2, NS_FD, N_S32, N_F64);
21341 do_vfp_sp_dp_cvt ();
21342 do_vfp_cond_or_thumb ();
21343}
21344
5287ad62
JB
21345\f
21346/* Overall per-instruction processing. */
21347
21348/* We need to be able to fix up arbitrary expressions in some statements.
21349 This is so that we can handle symbols that are an arbitrary distance from
21350 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
21351 which returns part of an address in a form which will be valid for
21352 a data instruction. We do this by pushing the expression into a symbol
21353 in the expr_section, and creating a fix for that. */
21354
21355static void
21356fix_new_arm (fragS * frag,
21357 int where,
21358 short int size,
21359 expressionS * exp,
21360 int pc_rel,
21361 int reloc)
21362{
21363 fixS * new_fix;
21364
21365 switch (exp->X_op)
21366 {
21367 case O_constant:
6e7ce2cd
PB
21368 if (pc_rel)
21369 {
21370 /* Create an absolute valued symbol, so we have something to
477330fc
RM
21371 refer to in the object file. Unfortunately for us, gas's
21372 generic expression parsing will already have folded out
21373 any use of .set foo/.type foo %function that may have
21374 been used to set type information of the target location,
21375 that's being specified symbolically. We have to presume
21376 the user knows what they are doing. */
6e7ce2cd
PB
21377 char name[16 + 8];
21378 symbolS *symbol;
21379
21380 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
21381
21382 symbol = symbol_find_or_make (name);
21383 S_SET_SEGMENT (symbol, absolute_section);
21384 symbol_set_frag (symbol, &zero_address_frag);
21385 S_SET_VALUE (symbol, exp->X_add_number);
21386 exp->X_op = O_symbol;
21387 exp->X_add_symbol = symbol;
21388 exp->X_add_number = 0;
21389 }
21390 /* FALLTHROUGH */
5287ad62
JB
21391 case O_symbol:
21392 case O_add:
21393 case O_subtract:
21d799b5 21394 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 21395 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
21396 break;
21397
21398 default:
21d799b5 21399 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 21400 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
21401 break;
21402 }
21403
21404 /* Mark whether the fix is to a THUMB instruction, or an ARM
21405 instruction. */
21406 new_fix->tc_fix_data = thumb_mode;
21407}
21408
21409/* Create a frg for an instruction requiring relaxation. */
21410static void
21411output_relax_insn (void)
21412{
21413 char * to;
21414 symbolS *sym;
0110f2b8
PB
21415 int offset;
21416
6e1cb1a6
PB
21417 /* The size of the instruction is unknown, so tie the debug info to the
21418 start of the instruction. */
21419 dwarf2_emit_insn (0);
6e1cb1a6 21420
e2b0ab59 21421 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
21422 {
21423 case O_symbol:
e2b0ab59
AV
21424 sym = inst.relocs[0].exp.X_add_symbol;
21425 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
21426 break;
21427 case O_constant:
21428 sym = NULL;
e2b0ab59 21429 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
21430 break;
21431 default:
e2b0ab59 21432 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
21433 offset = 0;
21434 break;
21435 }
21436 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
21437 inst.relax, sym, offset, NULL/*offset, opcode*/);
21438 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
21439}
21440
21441/* Write a 32-bit thumb instruction to buf. */
21442static void
21443put_thumb32_insn (char * buf, unsigned long insn)
21444{
21445 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
21446 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
21447}
21448
b99bd4ef 21449static void
c19d1205 21450output_inst (const char * str)
b99bd4ef 21451{
c19d1205 21452 char * to = NULL;
b99bd4ef 21453
c19d1205 21454 if (inst.error)
b99bd4ef 21455 {
c19d1205 21456 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
21457 return;
21458 }
5f4273c7
NC
21459 if (inst.relax)
21460 {
21461 output_relax_insn ();
0110f2b8 21462 return;
5f4273c7 21463 }
c19d1205
ZW
21464 if (inst.size == 0)
21465 return;
b99bd4ef 21466
c19d1205 21467 to = frag_more (inst.size);
8dc2430f
NC
21468 /* PR 9814: Record the thumb mode into the current frag so that we know
21469 what type of NOP padding to use, if necessary. We override any previous
21470 setting so that if the mode has changed then the NOPS that we use will
21471 match the encoding of the last instruction in the frag. */
cd000bff 21472 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
21473
21474 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 21475 {
9c2799c2 21476 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 21477 put_thumb32_insn (to, inst.instruction);
b99bd4ef 21478 }
c19d1205 21479 else if (inst.size > INSN_SIZE)
b99bd4ef 21480 {
9c2799c2 21481 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
21482 md_number_to_chars (to, inst.instruction, INSN_SIZE);
21483 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 21484 }
c19d1205
ZW
21485 else
21486 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 21487
e2b0ab59
AV
21488 int r;
21489 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
21490 {
21491 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
21492 fix_new_arm (frag_now, to - frag_now->fr_literal,
21493 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
21494 inst.relocs[r].type);
21495 }
b99bd4ef 21496
c19d1205 21497 dwarf2_emit_insn (inst.size);
c19d1205 21498}
b99bd4ef 21499
e07e6e58
NC
21500static char *
21501output_it_inst (int cond, int mask, char * to)
21502{
21503 unsigned long instruction = 0xbf00;
21504
21505 mask &= 0xf;
21506 instruction |= mask;
21507 instruction |= cond << 4;
21508
21509 if (to == NULL)
21510 {
21511 to = frag_more (2);
21512#ifdef OBJ_ELF
21513 dwarf2_emit_insn (2);
21514#endif
21515 }
21516
21517 md_number_to_chars (to, instruction, 2);
21518
21519 return to;
21520}
21521
c19d1205
ZW
21522/* Tag values used in struct asm_opcode's tag field. */
21523enum opcode_tag
21524{
21525 OT_unconditional, /* Instruction cannot be conditionalized.
21526 The ARM condition field is still 0xE. */
21527 OT_unconditionalF, /* Instruction cannot be conditionalized
21528 and carries 0xF in its ARM condition field. */
21529 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
21530 OT_csuffixF, /* Some forms of the instruction take a scalar
21531 conditional suffix, others place 0xF where the
21532 condition field would be, others take a vector
21533 conditional suffix. */
c19d1205
ZW
21534 OT_cinfix3, /* Instruction takes a conditional infix,
21535 beginning at character index 3. (In
21536 unified mode, it becomes a suffix.) */
088fa78e
KH
21537 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
21538 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
21539 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
21540 character index 3, even in unified mode. Used for
21541 legacy instructions where suffix and infix forms
21542 may be ambiguous. */
c19d1205 21543 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 21544 suffix or an infix at character index 3. */
c19d1205
ZW
21545 OT_odd_infix_unc, /* This is the unconditional variant of an
21546 instruction that takes a conditional infix
21547 at an unusual position. In unified mode,
21548 this variant will accept a suffix. */
21549 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
21550 are the conditional variants of instructions that
21551 take conditional infixes in unusual positions.
21552 The infix appears at character index
21553 (tag - OT_odd_infix_0). These are not accepted
21554 in unified mode. */
21555};
b99bd4ef 21556
c19d1205
ZW
21557/* Subroutine of md_assemble, responsible for looking up the primary
21558 opcode from the mnemonic the user wrote. STR points to the
21559 beginning of the mnemonic.
21560
21561 This is not simply a hash table lookup, because of conditional
21562 variants. Most instructions have conditional variants, which are
21563 expressed with a _conditional affix_ to the mnemonic. If we were
21564 to encode each conditional variant as a literal string in the opcode
21565 table, it would have approximately 20,000 entries.
21566
21567 Most mnemonics take this affix as a suffix, and in unified syntax,
21568 'most' is upgraded to 'all'. However, in the divided syntax, some
21569 instructions take the affix as an infix, notably the s-variants of
21570 the arithmetic instructions. Of those instructions, all but six
21571 have the infix appear after the third character of the mnemonic.
21572
21573 Accordingly, the algorithm for looking up primary opcodes given
21574 an identifier is:
21575
21576 1. Look up the identifier in the opcode table.
21577 If we find a match, go to step U.
21578
21579 2. Look up the last two characters of the identifier in the
21580 conditions table. If we find a match, look up the first N-2
21581 characters of the identifier in the opcode table. If we
21582 find a match, go to step CE.
21583
21584 3. Look up the fourth and fifth characters of the identifier in
21585 the conditions table. If we find a match, extract those
21586 characters from the identifier, and look up the remaining
21587 characters in the opcode table. If we find a match, go
21588 to step CM.
21589
21590 4. Fail.
21591
21592 U. Examine the tag field of the opcode structure, in case this is
21593 one of the six instructions with its conditional infix in an
21594 unusual place. If it is, the tag tells us where to find the
21595 infix; look it up in the conditions table and set inst.cond
21596 accordingly. Otherwise, this is an unconditional instruction.
21597 Again set inst.cond accordingly. Return the opcode structure.
21598
21599 CE. Examine the tag field to make sure this is an instruction that
21600 should receive a conditional suffix. If it is not, fail.
21601 Otherwise, set inst.cond from the suffix we already looked up,
21602 and return the opcode structure.
21603
21604 CM. Examine the tag field to make sure this is an instruction that
21605 should receive a conditional infix after the third character.
21606 If it is not, fail. Otherwise, undo the edits to the current
21607 line of input and proceed as for case CE. */
21608
21609static const struct asm_opcode *
21610opcode_lookup (char **str)
21611{
21612 char *end, *base;
21613 char *affix;
21614 const struct asm_opcode *opcode;
21615 const struct asm_cond *cond;
e3cb604e 21616 char save[2];
c19d1205
ZW
21617
21618 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 21619 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 21620 for (base = end = *str; *end != '\0'; end++)
721a8186 21621 if (*end == ' ' || *end == '.')
c19d1205 21622 break;
b99bd4ef 21623
c19d1205 21624 if (end == base)
c921be7d 21625 return NULL;
b99bd4ef 21626
5287ad62 21627 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 21628 if (end[0] == '.')
b99bd4ef 21629 {
5287ad62 21630 int offset = 2;
5f4273c7 21631
267d2029 21632 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 21633 use. */
267d2029 21634 if (unified_syntax && end[1] == 'w')
c19d1205 21635 inst.size_req = 4;
267d2029 21636 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
21637 inst.size_req = 2;
21638 else
477330fc 21639 offset = 0;
5287ad62
JB
21640
21641 inst.vectype.elems = 0;
21642
21643 *str = end + offset;
b99bd4ef 21644
5f4273c7 21645 if (end[offset] == '.')
5287ad62 21646 {
267d2029 21647 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
21648 non-unified ARM syntax mode). */
21649 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 21650 return NULL;
477330fc 21651 }
5287ad62 21652 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 21653 return NULL;
b99bd4ef 21654 }
c19d1205
ZW
21655 else
21656 *str = end;
b99bd4ef 21657
c19d1205 21658 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 21659 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 21660 end - base);
c19d1205 21661 if (opcode)
b99bd4ef 21662 {
c19d1205
ZW
21663 /* step U */
21664 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 21665 {
c19d1205
ZW
21666 inst.cond = COND_ALWAYS;
21667 return opcode;
b99bd4ef 21668 }
b99bd4ef 21669
278df34e 21670 if (warn_on_deprecated && unified_syntax)
5c3696f8 21671 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 21672 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 21673 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 21674 gas_assert (cond);
b99bd4ef 21675
c19d1205
ZW
21676 inst.cond = cond->value;
21677 return opcode;
21678 }
5ee91343
AV
21679 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21680 {
21681 /* Cannot have a conditional suffix on a mnemonic of less than a character.
21682 */
21683 if (end - base < 2)
21684 return NULL;
21685 affix = end - 1;
21686 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
21687 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21688 affix - base);
21689 /* If this opcode can not be vector predicated then don't accept it with a
21690 vector predication code. */
21691 if (opcode && !opcode->mayBeVecPred)
21692 opcode = NULL;
21693 }
21694 if (!opcode || !cond)
21695 {
21696 /* Cannot have a conditional suffix on a mnemonic of less than two
21697 characters. */
21698 if (end - base < 3)
21699 return NULL;
b99bd4ef 21700
5ee91343
AV
21701 /* Look for suffixed mnemonic. */
21702 affix = end - 2;
21703 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
21704 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21705 affix - base);
21706 }
b99bd4ef 21707
c19d1205
ZW
21708 if (opcode && cond)
21709 {
21710 /* step CE */
21711 switch (opcode->tag)
21712 {
e3cb604e
PB
21713 case OT_cinfix3_legacy:
21714 /* Ignore conditional suffixes matched on infix only mnemonics. */
21715 break;
21716
c19d1205 21717 case OT_cinfix3:
088fa78e 21718 case OT_cinfix3_deprecated:
c19d1205
ZW
21719 case OT_odd_infix_unc:
21720 if (!unified_syntax)
0198d5e6 21721 return NULL;
1a0670f3 21722 /* Fall through. */
c19d1205
ZW
21723
21724 case OT_csuffix:
477330fc 21725 case OT_csuffixF:
c19d1205
ZW
21726 case OT_csuf_or_in3:
21727 inst.cond = cond->value;
21728 return opcode;
21729
21730 case OT_unconditional:
21731 case OT_unconditionalF:
dfa9f0d5 21732 if (thumb_mode)
c921be7d 21733 inst.cond = cond->value;
dfa9f0d5
PB
21734 else
21735 {
c921be7d 21736 /* Delayed diagnostic. */
dfa9f0d5
PB
21737 inst.error = BAD_COND;
21738 inst.cond = COND_ALWAYS;
21739 }
c19d1205 21740 return opcode;
b99bd4ef 21741
c19d1205 21742 default:
c921be7d 21743 return NULL;
c19d1205
ZW
21744 }
21745 }
b99bd4ef 21746
c19d1205
ZW
21747 /* Cannot have a usual-position infix on a mnemonic of less than
21748 six characters (five would be a suffix). */
21749 if (end - base < 6)
c921be7d 21750 return NULL;
b99bd4ef 21751
c19d1205
ZW
21752 /* Look for infixed mnemonic in the usual position. */
21753 affix = base + 3;
21d799b5 21754 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 21755 if (!cond)
c921be7d 21756 return NULL;
e3cb604e
PB
21757
21758 memcpy (save, affix, 2);
21759 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 21760 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 21761 (end - base) - 2);
e3cb604e
PB
21762 memmove (affix + 2, affix, (end - affix) - 2);
21763 memcpy (affix, save, 2);
21764
088fa78e
KH
21765 if (opcode
21766 && (opcode->tag == OT_cinfix3
21767 || opcode->tag == OT_cinfix3_deprecated
21768 || opcode->tag == OT_csuf_or_in3
21769 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 21770 {
c921be7d 21771 /* Step CM. */
278df34e 21772 if (warn_on_deprecated && unified_syntax
088fa78e
KH
21773 && (opcode->tag == OT_cinfix3
21774 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 21775 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
21776
21777 inst.cond = cond->value;
21778 return opcode;
b99bd4ef
NC
21779 }
21780
c921be7d 21781 return NULL;
b99bd4ef
NC
21782}
21783
e07e6e58
NC
21784/* This function generates an initial IT instruction, leaving its block
21785 virtually open for the new instructions. Eventually,
5ee91343 21786 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
21787 a new instruction needs to be included in the IT block.
21788 Finally, the block is closed with close_automatic_it_block ().
21789 The block closure can be requested either from md_assemble (),
21790 a tencode (), or due to a label hook. */
21791
21792static void
21793new_automatic_it_block (int cond)
21794{
5ee91343
AV
21795 now_pred.state = AUTOMATIC_PRED_BLOCK;
21796 now_pred.mask = 0x18;
21797 now_pred.cc = cond;
21798 now_pred.block_length = 1;
cd000bff 21799 mapping_state (MAP_THUMB);
5ee91343
AV
21800 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
21801 now_pred.warn_deprecated = FALSE;
21802 now_pred.insn_cond = TRUE;
e07e6e58
NC
21803}
21804
21805/* Close an automatic IT block.
21806 See comments in new_automatic_it_block (). */
21807
21808static void
21809close_automatic_it_block (void)
21810{
5ee91343
AV
21811 now_pred.mask = 0x10;
21812 now_pred.block_length = 0;
e07e6e58
NC
21813}
21814
21815/* Update the mask of the current automatically-generated IT
21816 instruction. See comments in new_automatic_it_block (). */
21817
21818static void
5ee91343 21819now_pred_add_mask (int cond)
e07e6e58
NC
21820{
21821#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
21822#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 21823 | ((bitvalue) << (nbit)))
e07e6e58 21824 const int resulting_bit = (cond & 1);
c921be7d 21825
5ee91343
AV
21826 now_pred.mask &= 0xf;
21827 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 21828 resulting_bit,
5ee91343
AV
21829 (5 - now_pred.block_length));
21830 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 21831 1,
5ee91343
AV
21832 ((5 - now_pred.block_length) - 1));
21833 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
21834
21835#undef CLEAR_BIT
21836#undef SET_BIT_VALUE
e07e6e58
NC
21837}
21838
21839/* The IT blocks handling machinery is accessed through the these functions:
21840 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
21841 set_pred_insn_type () optional, from the tencode functions
21842 set_pred_insn_type_last () ditto
21843 in_pred_block () ditto
e07e6e58 21844 it_fsm_post_encode () from md_assemble ()
33eaf5de 21845 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
21846
21847 Rationale:
21848 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
21849 initializing the IT insn type with a generic initial value depending
21850 on the inst.condition.
e07e6e58 21851 2) During the tencode function, two things may happen:
477330fc 21852 a) The tencode function overrides the IT insn type by
5ee91343
AV
21853 calling either set_pred_insn_type (type) or
21854 set_pred_insn_type_last ().
477330fc 21855 b) The tencode function queries the IT block state by
5ee91343 21856 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 21857
5ee91343
AV
21858 Both set_pred_insn_type and in_pred_block run the internal FSM state
21859 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
21860 type may incur in an invalid state (exiting the function),
21861 and b) querying the state requires the FSM to be updated.
21862 Specifically we want to avoid creating an IT block for conditional
21863 branches, so it_fsm_pre_encode is actually a guess and we can't
21864 determine whether an IT block is required until the tencode () routine
21865 has decided what type of instruction this actually it.
5ee91343
AV
21866 Because of this, if set_pred_insn_type and in_pred_block have to be
21867 used, set_pred_insn_type has to be called first.
477330fc 21868
5ee91343
AV
21869 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
21870 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
21871 When a tencode () routine encodes an instruction that can be
21872 either outside an IT block, or, in the case of being inside, has to be
5ee91343 21873 the last one, set_pred_insn_type_last () will determine the proper
477330fc 21874 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 21875 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
21876 for covering other cases.
21877
5ee91343
AV
21878 Calling handle_pred_state () may not transition the IT block state to
21879 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 21880 still queried. Instead, if the FSM determines that the state should
5ee91343 21881 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
21882 after the tencode () function: that's what it_fsm_post_encode () does.
21883
5ee91343 21884 Since in_pred_block () calls the state handling function to get an
477330fc
RM
21885 updated state, an error may occur (due to invalid insns combination).
21886 In that case, inst.error is set.
21887 Therefore, inst.error has to be checked after the execution of
21888 the tencode () routine.
e07e6e58
NC
21889
21890 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 21891 any pending state change (if any) that didn't take place in
5ee91343 21892 handle_pred_state () as explained above. */
e07e6e58
NC
21893
21894static void
21895it_fsm_pre_encode (void)
21896{
21897 if (inst.cond != COND_ALWAYS)
5ee91343 21898 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 21899 else
5ee91343 21900 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 21901
5ee91343 21902 now_pred.state_handled = 0;
e07e6e58
NC
21903}
21904
21905/* IT state FSM handling function. */
5ee91343
AV
21906/* MVE instructions and non-MVE instructions are handled differently because of
21907 the introduction of VPT blocks.
21908 Specifications say that any non-MVE instruction inside a VPT block is
21909 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
21910 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 21911 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
21912 The error messages provided depending on the different combinations possible
21913 are described in the cases below:
21914 For 'most' MVE instructions:
21915 1) In an IT block, with an IT code: syntax error
21916 2) In an IT block, with a VPT code: error: must be in a VPT block
21917 3) In an IT block, with no code: warning: UNPREDICTABLE
21918 4) In a VPT block, with an IT code: syntax error
21919 5) In a VPT block, with a VPT code: OK!
21920 6) In a VPT block, with no code: error: missing code
21921 7) Outside a pred block, with an IT code: error: syntax error
21922 8) Outside a pred block, with a VPT code: error: should be in a VPT block
21923 9) Outside a pred block, with no code: OK!
21924 For non-MVE instructions:
21925 10) In an IT block, with an IT code: OK!
21926 11) In an IT block, with a VPT code: syntax error
21927 12) In an IT block, with no code: error: missing code
21928 13) In a VPT block, with an IT code: error: should be in an IT block
21929 14) In a VPT block, with a VPT code: syntax error
21930 15) In a VPT block, with no code: UNPREDICTABLE
21931 16) Outside a pred block, with an IT code: error: should be in an IT block
21932 17) Outside a pred block, with a VPT code: syntax error
21933 18) Outside a pred block, with no code: OK!
21934 */
21935
e07e6e58
NC
21936
21937static int
5ee91343 21938handle_pred_state (void)
e07e6e58 21939{
5ee91343
AV
21940 now_pred.state_handled = 1;
21941 now_pred.insn_cond = FALSE;
e07e6e58 21942
5ee91343 21943 switch (now_pred.state)
e07e6e58 21944 {
5ee91343
AV
21945 case OUTSIDE_PRED_BLOCK:
21946 switch (inst.pred_insn_type)
e07e6e58 21947 {
35c228db 21948 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
21949 case MVE_OUTSIDE_PRED_INSN:
21950 if (inst.cond < COND_ALWAYS)
21951 {
21952 /* Case 7: Outside a pred block, with an IT code: error: syntax
21953 error. */
21954 inst.error = BAD_SYNTAX;
21955 return FAIL;
21956 }
21957 /* Case 9: Outside a pred block, with no code: OK! */
21958 break;
21959 case OUTSIDE_PRED_INSN:
21960 if (inst.cond > COND_ALWAYS)
21961 {
21962 /* Case 17: Outside a pred block, with a VPT code: syntax error.
21963 */
21964 inst.error = BAD_SYNTAX;
21965 return FAIL;
21966 }
21967 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
21968 break;
21969
5ee91343
AV
21970 case INSIDE_VPT_INSN:
21971 /* Case 8: Outside a pred block, with a VPT code: error: should be in
21972 a VPT block. */
21973 inst.error = BAD_OUT_VPT;
21974 return FAIL;
21975
e07e6e58
NC
21976 case INSIDE_IT_INSN:
21977 case INSIDE_IT_LAST_INSN:
5ee91343 21978 if (inst.cond < COND_ALWAYS)
e07e6e58 21979 {
5ee91343
AV
21980 /* Case 16: Outside a pred block, with an IT code: error: should
21981 be in an IT block. */
21982 if (thumb_mode == 0)
e07e6e58 21983 {
5ee91343
AV
21984 if (unified_syntax
21985 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
21986 as_tsktsk (_("Warning: conditional outside an IT block"\
21987 " for Thumb."));
e07e6e58
NC
21988 }
21989 else
21990 {
5ee91343
AV
21991 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
21992 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
21993 {
21994 /* Automatically generate the IT instruction. */
21995 new_automatic_it_block (inst.cond);
21996 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
21997 close_automatic_it_block ();
21998 }
21999 else
22000 {
22001 inst.error = BAD_OUT_IT;
22002 return FAIL;
22003 }
e07e6e58 22004 }
5ee91343 22005 break;
e07e6e58 22006 }
5ee91343
AV
22007 else if (inst.cond > COND_ALWAYS)
22008 {
22009 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22010 */
22011 inst.error = BAD_SYNTAX;
22012 return FAIL;
22013 }
22014 else
22015 gas_assert (0);
e07e6e58
NC
22016 case IF_INSIDE_IT_LAST_INSN:
22017 case NEUTRAL_IT_INSN:
22018 break;
22019
5ee91343
AV
22020 case VPT_INSN:
22021 if (inst.cond != COND_ALWAYS)
22022 first_error (BAD_SYNTAX);
22023 now_pred.state = MANUAL_PRED_BLOCK;
22024 now_pred.block_length = 0;
22025 now_pred.type = VECTOR_PRED;
22026 now_pred.cc = 0;
22027 break;
e07e6e58 22028 case IT_INSN:
5ee91343
AV
22029 now_pred.state = MANUAL_PRED_BLOCK;
22030 now_pred.block_length = 0;
22031 now_pred.type = SCALAR_PRED;
e07e6e58
NC
22032 break;
22033 }
22034 break;
22035
5ee91343 22036 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
22037 /* Three things may happen now:
22038 a) We should increment current it block size;
22039 b) We should close current it block (closing insn or 4 insns);
22040 c) We should close current it block and start a new one (due
22041 to incompatible conditions or
22042 4 insns-length block reached). */
22043
5ee91343 22044 switch (inst.pred_insn_type)
e07e6e58 22045 {
5ee91343
AV
22046 case INSIDE_VPT_INSN:
22047 case VPT_INSN:
35c228db 22048 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22049 case MVE_OUTSIDE_PRED_INSN:
22050 gas_assert (0);
22051 case OUTSIDE_PRED_INSN:
2b0f3761 22052 /* The closure of the block shall happen immediately,
5ee91343 22053 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
22054 force_automatic_it_block_close ();
22055 break;
22056
22057 case INSIDE_IT_INSN:
22058 case INSIDE_IT_LAST_INSN:
22059 case IF_INSIDE_IT_LAST_INSN:
5ee91343 22060 now_pred.block_length++;
e07e6e58 22061
5ee91343
AV
22062 if (now_pred.block_length > 4
22063 || !now_pred_compatible (inst.cond))
e07e6e58
NC
22064 {
22065 force_automatic_it_block_close ();
5ee91343 22066 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
22067 new_automatic_it_block (inst.cond);
22068 }
22069 else
22070 {
5ee91343
AV
22071 now_pred.insn_cond = TRUE;
22072 now_pred_add_mask (inst.cond);
e07e6e58
NC
22073 }
22074
5ee91343
AV
22075 if (now_pred.state == AUTOMATIC_PRED_BLOCK
22076 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
22077 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
22078 close_automatic_it_block ();
22079 break;
22080
22081 case NEUTRAL_IT_INSN:
5ee91343
AV
22082 now_pred.block_length++;
22083 now_pred.insn_cond = TRUE;
e07e6e58 22084
5ee91343 22085 if (now_pred.block_length > 4)
e07e6e58
NC
22086 force_automatic_it_block_close ();
22087 else
5ee91343 22088 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
22089 break;
22090
22091 case IT_INSN:
22092 close_automatic_it_block ();
5ee91343 22093 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
22094 break;
22095 }
22096 break;
22097
5ee91343 22098 case MANUAL_PRED_BLOCK:
e07e6e58 22099 {
5ee91343
AV
22100 int cond, is_last;
22101 if (now_pred.type == SCALAR_PRED)
e07e6e58 22102 {
5ee91343
AV
22103 /* Check conditional suffixes. */
22104 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
22105 now_pred.mask <<= 1;
22106 now_pred.mask &= 0x1f;
22107 is_last = (now_pred.mask == 0x10);
22108 }
22109 else
22110 {
22111 now_pred.cc ^= (now_pred.mask >> 4);
22112 cond = now_pred.cc + 0xf;
22113 now_pred.mask <<= 1;
22114 now_pred.mask &= 0x1f;
22115 is_last = now_pred.mask == 0x10;
22116 }
22117 now_pred.insn_cond = TRUE;
e07e6e58 22118
5ee91343
AV
22119 switch (inst.pred_insn_type)
22120 {
22121 case OUTSIDE_PRED_INSN:
22122 if (now_pred.type == SCALAR_PRED)
22123 {
22124 if (inst.cond == COND_ALWAYS)
22125 {
22126 /* Case 12: In an IT block, with no code: error: missing
22127 code. */
22128 inst.error = BAD_NOT_IT;
22129 return FAIL;
22130 }
22131 else if (inst.cond > COND_ALWAYS)
22132 {
22133 /* Case 11: In an IT block, with a VPT code: syntax error.
22134 */
22135 inst.error = BAD_SYNTAX;
22136 return FAIL;
22137 }
22138 else if (thumb_mode)
22139 {
22140 /* This is for some special cases where a non-MVE
22141 instruction is not allowed in an IT block, such as cbz,
22142 but are put into one with a condition code.
22143 You could argue this should be a syntax error, but we
22144 gave the 'not allowed in IT block' diagnostic in the
22145 past so we will keep doing so. */
22146 inst.error = BAD_NOT_IT;
22147 return FAIL;
22148 }
22149 break;
22150 }
22151 else
22152 {
22153 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
22154 as_tsktsk (MVE_NOT_VPT);
22155 return SUCCESS;
22156 }
22157 case MVE_OUTSIDE_PRED_INSN:
22158 if (now_pred.type == SCALAR_PRED)
22159 {
22160 if (inst.cond == COND_ALWAYS)
22161 {
22162 /* Case 3: In an IT block, with no code: warning:
22163 UNPREDICTABLE. */
22164 as_tsktsk (MVE_NOT_IT);
22165 return SUCCESS;
22166 }
22167 else if (inst.cond < COND_ALWAYS)
22168 {
22169 /* Case 1: In an IT block, with an IT code: syntax error.
22170 */
22171 inst.error = BAD_SYNTAX;
22172 return FAIL;
22173 }
22174 else
22175 gas_assert (0);
22176 }
22177 else
22178 {
22179 if (inst.cond < COND_ALWAYS)
22180 {
22181 /* Case 4: In a VPT block, with an IT code: syntax error.
22182 */
22183 inst.error = BAD_SYNTAX;
22184 return FAIL;
22185 }
22186 else if (inst.cond == COND_ALWAYS)
22187 {
22188 /* Case 6: In a VPT block, with no code: error: missing
22189 code. */
22190 inst.error = BAD_NOT_VPT;
22191 return FAIL;
22192 }
22193 else
22194 {
22195 gas_assert (0);
22196 }
22197 }
35c228db
AV
22198 case MVE_UNPREDICABLE_INSN:
22199 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
22200 return SUCCESS;
e07e6e58 22201 case INSIDE_IT_INSN:
5ee91343 22202 if (inst.cond > COND_ALWAYS)
e07e6e58 22203 {
5ee91343
AV
22204 /* Case 11: In an IT block, with a VPT code: syntax error. */
22205 /* Case 14: In a VPT block, with a VPT code: syntax error. */
22206 inst.error = BAD_SYNTAX;
22207 return FAIL;
22208 }
22209 else if (now_pred.type == SCALAR_PRED)
22210 {
22211 /* Case 10: In an IT block, with an IT code: OK! */
22212 if (cond != inst.cond)
22213 {
22214 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
22215 BAD_VPT_COND;
22216 return FAIL;
22217 }
22218 }
22219 else
22220 {
22221 /* Case 13: In a VPT block, with an IT code: error: should be
22222 in an IT block. */
22223 inst.error = BAD_OUT_IT;
e07e6e58
NC
22224 return FAIL;
22225 }
22226 break;
22227
5ee91343
AV
22228 case INSIDE_VPT_INSN:
22229 if (now_pred.type == SCALAR_PRED)
22230 {
22231 /* Case 2: In an IT block, with a VPT code: error: must be in a
22232 VPT block. */
22233 inst.error = BAD_OUT_VPT;
22234 return FAIL;
22235 }
22236 /* Case 5: In a VPT block, with a VPT code: OK! */
22237 else if (cond != inst.cond)
22238 {
22239 inst.error = BAD_VPT_COND;
22240 return FAIL;
22241 }
22242 break;
e07e6e58
NC
22243 case INSIDE_IT_LAST_INSN:
22244 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
22245 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
22246 {
22247 /* Case 4: In a VPT block, with an IT code: syntax error. */
22248 /* Case 11: In an IT block, with a VPT code: syntax error. */
22249 inst.error = BAD_SYNTAX;
22250 return FAIL;
22251 }
22252 else if (cond != inst.cond)
e07e6e58
NC
22253 {
22254 inst.error = BAD_IT_COND;
22255 return FAIL;
22256 }
22257 if (!is_last)
22258 {
22259 inst.error = BAD_BRANCH;
22260 return FAIL;
22261 }
22262 break;
22263
22264 case NEUTRAL_IT_INSN:
5ee91343
AV
22265 /* The BKPT instruction is unconditional even in a IT or VPT
22266 block. */
e07e6e58
NC
22267 break;
22268
22269 case IT_INSN:
5ee91343
AV
22270 if (now_pred.type == SCALAR_PRED)
22271 {
22272 inst.error = BAD_IT_IT;
22273 return FAIL;
22274 }
22275 /* fall through. */
22276 case VPT_INSN:
22277 if (inst.cond == COND_ALWAYS)
22278 {
22279 /* Executing a VPT/VPST instruction inside an IT block or a
22280 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
22281 */
22282 if (now_pred.type == SCALAR_PRED)
22283 as_tsktsk (MVE_NOT_IT);
22284 else
22285 as_tsktsk (MVE_NOT_VPT);
22286 return SUCCESS;
22287 }
22288 else
22289 {
22290 /* VPT/VPST do not accept condition codes. */
22291 inst.error = BAD_SYNTAX;
22292 return FAIL;
22293 }
e07e6e58 22294 }
5ee91343 22295 }
e07e6e58
NC
22296 break;
22297 }
22298
22299 return SUCCESS;
22300}
22301
5a01bb1d
MGD
22302struct depr_insn_mask
22303{
22304 unsigned long pattern;
22305 unsigned long mask;
22306 const char* description;
22307};
22308
22309/* List of 16-bit instruction patterns deprecated in an IT block in
22310 ARMv8. */
22311static const struct depr_insn_mask depr_it_insns[] = {
22312 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
22313 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
22314 { 0xa000, 0xb800, N_("ADR") },
22315 { 0x4800, 0xf800, N_("Literal loads") },
22316 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
22317 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
22318 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
22319 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
22320 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
22321 { 0, 0, NULL }
22322};
22323
e07e6e58
NC
22324static void
22325it_fsm_post_encode (void)
22326{
22327 int is_last;
22328
5ee91343
AV
22329 if (!now_pred.state_handled)
22330 handle_pred_state ();
e07e6e58 22331
5ee91343
AV
22332 if (now_pred.insn_cond
22333 && !now_pred.warn_deprecated
5a01bb1d 22334 && warn_on_deprecated
df9909b8
TP
22335 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
22336 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
22337 {
22338 if (inst.instruction >= 0x10000)
22339 {
5c3696f8 22340 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 22341 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 22342 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22343 }
22344 else
22345 {
22346 const struct depr_insn_mask *p = depr_it_insns;
22347
22348 while (p->mask != 0)
22349 {
22350 if ((inst.instruction & p->mask) == p->pattern)
22351 {
df9909b8
TP
22352 as_tsktsk (_("IT blocks containing 16-bit Thumb "
22353 "instructions of the following class are "
22354 "performance deprecated in ARMv8-A and "
22355 "ARMv8-R: %s"), p->description);
5ee91343 22356 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22357 break;
22358 }
22359
22360 ++p;
22361 }
22362 }
22363
5ee91343 22364 if (now_pred.block_length > 1)
5a01bb1d 22365 {
5c3696f8 22366 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
22367 "instruction are performance deprecated in ARMv8-A and "
22368 "ARMv8-R"));
5ee91343 22369 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
22370 }
22371 }
22372
5ee91343
AV
22373 is_last = (now_pred.mask == 0x10);
22374 if (is_last)
22375 {
22376 now_pred.state = OUTSIDE_PRED_BLOCK;
22377 now_pred.mask = 0;
22378 }
e07e6e58
NC
22379}
22380
22381static void
22382force_automatic_it_block_close (void)
22383{
5ee91343 22384 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
22385 {
22386 close_automatic_it_block ();
5ee91343
AV
22387 now_pred.state = OUTSIDE_PRED_BLOCK;
22388 now_pred.mask = 0;
e07e6e58
NC
22389 }
22390}
22391
22392static int
5ee91343 22393in_pred_block (void)
e07e6e58 22394{
5ee91343
AV
22395 if (!now_pred.state_handled)
22396 handle_pred_state ();
e07e6e58 22397
5ee91343 22398 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
22399}
22400
ff8646ee
TP
22401/* Whether OPCODE only has T32 encoding. Since this function is only used by
22402 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
22403 here, hence the "known" in the function name. */
fc289b0a
TP
22404
22405static bfd_boolean
ff8646ee 22406known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
22407{
22408 /* Original Thumb-1 wide instruction. */
22409 if (opcode->tencode == do_t_blx
22410 || opcode->tencode == do_t_branch23
22411 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
22412 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
22413 return TRUE;
22414
16a1fa25
TP
22415 /* Wide-only instruction added to ARMv8-M Baseline. */
22416 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
22417 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
22418 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
22419 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
22420 return TRUE;
22421
22422 return FALSE;
22423}
22424
22425/* Whether wide instruction variant can be used if available for a valid OPCODE
22426 in ARCH. */
22427
22428static bfd_boolean
22429t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
22430{
22431 if (known_t32_only_insn (opcode))
22432 return TRUE;
22433
22434 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
22435 of variant T3 of B.W is checked in do_t_branch. */
22436 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22437 && opcode->tencode == do_t_branch)
22438 return TRUE;
22439
bada4342
JW
22440 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
22441 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22442 && opcode->tencode == do_t_mov_cmp
22443 /* Make sure CMP instruction is not affected. */
22444 && opcode->aencode == do_mov)
22445 return TRUE;
22446
ff8646ee
TP
22447 /* Wide instruction variants of all instructions with narrow *and* wide
22448 variants become available with ARMv6t2. Other opcodes are either
22449 narrow-only or wide-only and are thus available if OPCODE is valid. */
22450 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
22451 return TRUE;
22452
22453 /* OPCODE with narrow only instruction variant or wide variant not
22454 available. */
fc289b0a
TP
22455 return FALSE;
22456}
22457
c19d1205
ZW
22458void
22459md_assemble (char *str)
b99bd4ef 22460{
c19d1205
ZW
22461 char *p = str;
22462 const struct asm_opcode * opcode;
b99bd4ef 22463
c19d1205
ZW
22464 /* Align the previous label if needed. */
22465 if (last_label_seen != NULL)
b99bd4ef 22466 {
c19d1205
ZW
22467 symbol_set_frag (last_label_seen, frag_now);
22468 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
22469 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
22470 }
22471
c19d1205 22472 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
22473 int r;
22474 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22475 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 22476
c19d1205
ZW
22477 opcode = opcode_lookup (&p);
22478 if (!opcode)
b99bd4ef 22479 {
c19d1205 22480 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 22481 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 22482 if (! create_register_alias (str, p)
477330fc 22483 && ! create_neon_reg_alias (str, p))
c19d1205 22484 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 22485
b99bd4ef
NC
22486 return;
22487 }
22488
278df34e 22489 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 22490 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 22491
037e8744
JB
22492 /* The value which unconditional instructions should have in place of the
22493 condition field. */
22494 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
22495
c19d1205 22496 if (thumb_mode)
b99bd4ef 22497 {
e74cfd16 22498 arm_feature_set variant;
8f06b2d8
PB
22499
22500 variant = cpu_variant;
22501 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
22502 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
22503 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 22504 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
22505 if (!opcode->tvariant
22506 || (thumb_mode == 1
22507 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 22508 {
173205ca
TP
22509 if (opcode->tencode == do_t_swi)
22510 as_bad (_("SVC is not permitted on this architecture"));
22511 else
22512 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
22513 return;
22514 }
c19d1205
ZW
22515 if (inst.cond != COND_ALWAYS && !unified_syntax
22516 && opcode->tencode != do_t_branch)
b99bd4ef 22517 {
c19d1205 22518 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
22519 return;
22520 }
22521
fc289b0a
TP
22522 /* Two things are addressed here:
22523 1) Implicit require narrow instructions on Thumb-1.
22524 This avoids relaxation accidentally introducing Thumb-2
22525 instructions.
22526 2) Reject wide instructions in non Thumb-2 cores.
22527
22528 Only instructions with narrow and wide variants need to be handled
22529 but selecting all non wide-only instructions is easier. */
22530 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 22531 && !t32_insn_ok (variant, opcode))
076d447c 22532 {
fc289b0a
TP
22533 if (inst.size_req == 0)
22534 inst.size_req = 2;
22535 else if (inst.size_req == 4)
752d5da4 22536 {
ff8646ee
TP
22537 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
22538 as_bad (_("selected processor does not support 32bit wide "
22539 "variant of instruction `%s'"), str);
22540 else
22541 as_bad (_("selected processor does not support `%s' in "
22542 "Thumb-2 mode"), str);
fc289b0a 22543 return;
752d5da4 22544 }
076d447c
PB
22545 }
22546
c19d1205
ZW
22547 inst.instruction = opcode->tvalue;
22548
5be8be5d 22549 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 22550 {
5ee91343 22551 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
22552 it. */
22553 it_fsm_pre_encode ();
c19d1205 22554
477330fc 22555 opcode->tencode ();
e07e6e58 22556
477330fc
RM
22557 it_fsm_post_encode ();
22558 }
e27ec89e 22559
0110f2b8 22560 if (!(inst.error || inst.relax))
b99bd4ef 22561 {
9c2799c2 22562 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
22563 inst.size = (inst.instruction > 0xffff ? 4 : 2);
22564 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 22565 {
c19d1205 22566 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
22567 return;
22568 }
22569 }
076d447c
PB
22570
22571 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 22572 instruction. */
9c2799c2 22573 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 22574
e74cfd16
PB
22575 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22576 *opcode->tvariant);
ee065d83 22577 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
22578 set those bits when Thumb-2 32-bit instructions are seen. The impact
22579 of relaxable instructions will be considered later after we finish all
22580 relaxation. */
ff8646ee
TP
22581 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
22582 variant = arm_arch_none;
22583 else
22584 variant = cpu_variant;
22585 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
22586 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22587 arm_ext_v6t2);
cd000bff 22588
88714cb8
DG
22589 check_neon_suffixes;
22590
cd000bff 22591 if (!inst.error)
c877a2f2
NC
22592 {
22593 mapping_state (MAP_THUMB);
22594 }
c19d1205 22595 }
3e9e4fcf 22596 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 22597 {
845b51d6
PB
22598 bfd_boolean is_bx;
22599
22600 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
22601 is_bx = (opcode->aencode == do_bx);
22602
c19d1205 22603 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
22604 if (!(is_bx && fix_v4bx)
22605 && !(opcode->avariant &&
22606 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 22607 {
84b52b66 22608 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 22609 return;
b99bd4ef 22610 }
c19d1205 22611 if (inst.size_req)
b99bd4ef 22612 {
c19d1205
ZW
22613 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
22614 return;
b99bd4ef
NC
22615 }
22616
c19d1205
ZW
22617 inst.instruction = opcode->avalue;
22618 if (opcode->tag == OT_unconditionalF)
eff0bc54 22619 inst.instruction |= 0xFU << 28;
c19d1205
ZW
22620 else
22621 inst.instruction |= inst.cond << 28;
22622 inst.size = INSN_SIZE;
5be8be5d 22623 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
22624 {
22625 it_fsm_pre_encode ();
22626 opcode->aencode ();
22627 it_fsm_post_encode ();
22628 }
ee065d83 22629 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 22630 on a hypothetical non-thumb v5 core. */
845b51d6 22631 if (is_bx)
e74cfd16 22632 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 22633 else
e74cfd16
PB
22634 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
22635 *opcode->avariant);
88714cb8
DG
22636
22637 check_neon_suffixes;
22638
cd000bff 22639 if (!inst.error)
c877a2f2
NC
22640 {
22641 mapping_state (MAP_ARM);
22642 }
b99bd4ef 22643 }
3e9e4fcf
JB
22644 else
22645 {
22646 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
22647 "-- `%s'"), str);
22648 return;
22649 }
c19d1205
ZW
22650 output_inst (str);
22651}
b99bd4ef 22652
e07e6e58 22653static void
5ee91343 22654check_pred_blocks_finished (void)
e07e6e58
NC
22655{
22656#ifdef OBJ_ELF
22657 asection *sect;
22658
22659 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
22660 if (seg_info (sect)->tc_segment_info_data.current_pred.state
22661 == MANUAL_PRED_BLOCK)
e07e6e58 22662 {
5ee91343
AV
22663 if (now_pred.type == SCALAR_PRED)
22664 as_warn (_("section '%s' finished with an open IT block."),
22665 sect->name);
22666 else
22667 as_warn (_("section '%s' finished with an open VPT/VPST block."),
22668 sect->name);
e07e6e58
NC
22669 }
22670#else
5ee91343
AV
22671 if (now_pred.state == MANUAL_PRED_BLOCK)
22672 {
22673 if (now_pred.type == SCALAR_PRED)
22674 as_warn (_("file finished with an open IT block."));
22675 else
22676 as_warn (_("file finished with an open VPT/VPST block."));
22677 }
e07e6e58
NC
22678#endif
22679}
22680
c19d1205
ZW
22681/* Various frobbings of labels and their addresses. */
22682
22683void
22684arm_start_line_hook (void)
22685{
22686 last_label_seen = NULL;
b99bd4ef
NC
22687}
22688
c19d1205
ZW
22689void
22690arm_frob_label (symbolS * sym)
b99bd4ef 22691{
c19d1205 22692 last_label_seen = sym;
b99bd4ef 22693
c19d1205 22694 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 22695
c19d1205
ZW
22696#if defined OBJ_COFF || defined OBJ_ELF
22697 ARM_SET_INTERWORK (sym, support_interwork);
22698#endif
b99bd4ef 22699
e07e6e58
NC
22700 force_automatic_it_block_close ();
22701
5f4273c7 22702 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
22703 as Thumb functions. This is because these labels, whilst
22704 they exist inside Thumb code, are not the entry points for
22705 possible ARM->Thumb calls. Also, these labels can be used
22706 as part of a computed goto or switch statement. eg gcc
22707 can generate code that looks like this:
b99bd4ef 22708
c19d1205
ZW
22709 ldr r2, [pc, .Laaa]
22710 lsl r3, r3, #2
22711 ldr r2, [r3, r2]
22712 mov pc, r2
b99bd4ef 22713
c19d1205
ZW
22714 .Lbbb: .word .Lxxx
22715 .Lccc: .word .Lyyy
22716 ..etc...
22717 .Laaa: .word Lbbb
b99bd4ef 22718
c19d1205
ZW
22719 The first instruction loads the address of the jump table.
22720 The second instruction converts a table index into a byte offset.
22721 The third instruction gets the jump address out of the table.
22722 The fourth instruction performs the jump.
b99bd4ef 22723
c19d1205
ZW
22724 If the address stored at .Laaa is that of a symbol which has the
22725 Thumb_Func bit set, then the linker will arrange for this address
22726 to have the bottom bit set, which in turn would mean that the
22727 address computation performed by the third instruction would end
22728 up with the bottom bit set. Since the ARM is capable of unaligned
22729 word loads, the instruction would then load the incorrect address
22730 out of the jump table, and chaos would ensue. */
22731 if (label_is_thumb_function_name
22732 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
22733 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 22734 {
c19d1205
ZW
22735 /* When the address of a Thumb function is taken the bottom
22736 bit of that address should be set. This will allow
22737 interworking between Arm and Thumb functions to work
22738 correctly. */
b99bd4ef 22739
c19d1205 22740 THUMB_SET_FUNC (sym, 1);
b99bd4ef 22741
c19d1205 22742 label_is_thumb_function_name = FALSE;
b99bd4ef 22743 }
07a53e5c 22744
07a53e5c 22745 dwarf2_emit_label (sym);
b99bd4ef
NC
22746}
22747
c921be7d 22748bfd_boolean
c19d1205 22749arm_data_in_code (void)
b99bd4ef 22750{
c19d1205 22751 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 22752 {
c19d1205
ZW
22753 *input_line_pointer = '/';
22754 input_line_pointer += 5;
22755 *input_line_pointer = 0;
c921be7d 22756 return TRUE;
b99bd4ef
NC
22757 }
22758
c921be7d 22759 return FALSE;
b99bd4ef
NC
22760}
22761
c19d1205
ZW
22762char *
22763arm_canonicalize_symbol_name (char * name)
b99bd4ef 22764{
c19d1205 22765 int len;
b99bd4ef 22766
c19d1205
ZW
22767 if (thumb_mode && (len = strlen (name)) > 5
22768 && streq (name + len - 5, "/data"))
22769 *(name + len - 5) = 0;
b99bd4ef 22770
c19d1205 22771 return name;
b99bd4ef 22772}
c19d1205
ZW
22773\f
22774/* Table of all register names defined by default. The user can
22775 define additional names with .req. Note that all register names
22776 should appear in both upper and lowercase variants. Some registers
22777 also have mixed-case names. */
b99bd4ef 22778
dcbf9037 22779#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 22780#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 22781#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
22782#define REGSET(p,t) \
22783 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
22784 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
22785 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
22786 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
22787#define REGSETH(p,t) \
22788 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
22789 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
22790 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
22791 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
22792#define REGSET2(p,t) \
22793 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
22794 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
22795 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
22796 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
22797#define SPLRBANK(base,bank,t) \
22798 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
22799 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
22800 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
22801 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
22802 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
22803 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 22804
c19d1205 22805static const struct reg_entry reg_names[] =
7ed4c4c5 22806{
c19d1205
ZW
22807 /* ARM integer registers. */
22808 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 22809
c19d1205
ZW
22810 /* ATPCS synonyms. */
22811 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
22812 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
22813 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 22814
c19d1205
ZW
22815 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
22816 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
22817 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 22818
c19d1205
ZW
22819 /* Well-known aliases. */
22820 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
22821 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
22822
22823 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
22824 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
22825
1b883319
AV
22826 /* Defining the new Zero register from ARMv8.1-M. */
22827 REGDEF(zr,15,ZR),
22828 REGDEF(ZR,15,ZR),
22829
c19d1205
ZW
22830 /* Coprocessor numbers. */
22831 REGSET(p, CP), REGSET(P, CP),
22832
22833 /* Coprocessor register numbers. The "cr" variants are for backward
22834 compatibility. */
22835 REGSET(c, CN), REGSET(C, CN),
22836 REGSET(cr, CN), REGSET(CR, CN),
22837
90ec0d68
MGD
22838 /* ARM banked registers. */
22839 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
22840 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
22841 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
22842 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
22843 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
22844 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
22845 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
22846
22847 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
22848 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
22849 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
22850 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
22851 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 22852 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
22853 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
22854 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
22855
22856 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
22857 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
22858 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
22859 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
22860 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
22861 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
22862 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 22863 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
22864 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
22865
c19d1205
ZW
22866 /* FPA registers. */
22867 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
22868 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
22869
22870 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
22871 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
22872
22873 /* VFP SP registers. */
5287ad62
JB
22874 REGSET(s,VFS), REGSET(S,VFS),
22875 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
22876
22877 /* VFP DP Registers. */
5287ad62
JB
22878 REGSET(d,VFD), REGSET(D,VFD),
22879 /* Extra Neon DP registers. */
22880 REGSETH(d,VFD), REGSETH(D,VFD),
22881
22882 /* Neon QP registers. */
22883 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
22884
22885 /* VFP control registers. */
22886 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
22887 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
22888 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
22889 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
22890 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
22891 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 22892 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
22893 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
22894 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
22895 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
22896 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
22897
22898 /* Maverick DSP coprocessor registers. */
22899 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
22900 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
22901
22902 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
22903 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
22904 REGDEF(dspsc,0,DSPSC),
22905
22906 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
22907 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
22908 REGDEF(DSPSC,0,DSPSC),
22909
22910 /* iWMMXt data registers - p0, c0-15. */
22911 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
22912
22913 /* iWMMXt control registers - p1, c0-3. */
22914 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
22915 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
22916 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
22917 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
22918
22919 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
22920 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
22921 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
22922 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
22923 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
22924
22925 /* XScale accumulator registers. */
22926 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
22927};
22928#undef REGDEF
22929#undef REGNUM
22930#undef REGSET
7ed4c4c5 22931
c19d1205
ZW
22932/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
22933 within psr_required_here. */
22934static const struct asm_psr psrs[] =
22935{
22936 /* Backward compatibility notation. Note that "all" is no longer
22937 truly all possible PSR bits. */
22938 {"all", PSR_c | PSR_f},
22939 {"flg", PSR_f},
22940 {"ctl", PSR_c},
22941
22942 /* Individual flags. */
22943 {"f", PSR_f},
22944 {"c", PSR_c},
22945 {"x", PSR_x},
22946 {"s", PSR_s},
59b42a0d 22947
c19d1205
ZW
22948 /* Combinations of flags. */
22949 {"fs", PSR_f | PSR_s},
22950 {"fx", PSR_f | PSR_x},
22951 {"fc", PSR_f | PSR_c},
22952 {"sf", PSR_s | PSR_f},
22953 {"sx", PSR_s | PSR_x},
22954 {"sc", PSR_s | PSR_c},
22955 {"xf", PSR_x | PSR_f},
22956 {"xs", PSR_x | PSR_s},
22957 {"xc", PSR_x | PSR_c},
22958 {"cf", PSR_c | PSR_f},
22959 {"cs", PSR_c | PSR_s},
22960 {"cx", PSR_c | PSR_x},
22961 {"fsx", PSR_f | PSR_s | PSR_x},
22962 {"fsc", PSR_f | PSR_s | PSR_c},
22963 {"fxs", PSR_f | PSR_x | PSR_s},
22964 {"fxc", PSR_f | PSR_x | PSR_c},
22965 {"fcs", PSR_f | PSR_c | PSR_s},
22966 {"fcx", PSR_f | PSR_c | PSR_x},
22967 {"sfx", PSR_s | PSR_f | PSR_x},
22968 {"sfc", PSR_s | PSR_f | PSR_c},
22969 {"sxf", PSR_s | PSR_x | PSR_f},
22970 {"sxc", PSR_s | PSR_x | PSR_c},
22971 {"scf", PSR_s | PSR_c | PSR_f},
22972 {"scx", PSR_s | PSR_c | PSR_x},
22973 {"xfs", PSR_x | PSR_f | PSR_s},
22974 {"xfc", PSR_x | PSR_f | PSR_c},
22975 {"xsf", PSR_x | PSR_s | PSR_f},
22976 {"xsc", PSR_x | PSR_s | PSR_c},
22977 {"xcf", PSR_x | PSR_c | PSR_f},
22978 {"xcs", PSR_x | PSR_c | PSR_s},
22979 {"cfs", PSR_c | PSR_f | PSR_s},
22980 {"cfx", PSR_c | PSR_f | PSR_x},
22981 {"csf", PSR_c | PSR_s | PSR_f},
22982 {"csx", PSR_c | PSR_s | PSR_x},
22983 {"cxf", PSR_c | PSR_x | PSR_f},
22984 {"cxs", PSR_c | PSR_x | PSR_s},
22985 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
22986 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
22987 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
22988 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
22989 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
22990 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
22991 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
22992 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
22993 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
22994 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
22995 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
22996 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
22997 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
22998 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
22999 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23000 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23001 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23002 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23003 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23004 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23005 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23006 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23007 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23008 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23009};
23010
62b3e311
PB
23011/* Table of V7M psr names. */
23012static const struct asm_psr v7m_psrs[] =
23013{
1a336194
TP
23014 {"apsr", 0x0 }, {"APSR", 0x0 },
23015 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23016 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23017 {"psr", 0x3 }, {"PSR", 0x3 },
23018 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23019 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23020 {"epsr", 0x6 }, {"EPSR", 0x6 },
23021 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23022 {"msp", 0x8 }, {"MSP", 0x8 },
23023 {"psp", 0x9 }, {"PSP", 0x9 },
23024 {"msplim", 0xa }, {"MSPLIM", 0xa },
23025 {"psplim", 0xb }, {"PSPLIM", 0xb },
23026 {"primask", 0x10}, {"PRIMASK", 0x10},
23027 {"basepri", 0x11}, {"BASEPRI", 0x11},
23028 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
23029 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23030 {"control", 0x14}, {"CONTROL", 0x14},
23031 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23032 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23033 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
23034 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
23035 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
23036 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
23037 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
23038 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
23039 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
23040};
23041
c19d1205
ZW
23042/* Table of all shift-in-operand names. */
23043static const struct asm_shift_name shift_names [] =
b99bd4ef 23044{
c19d1205
ZW
23045 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
23046 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
23047 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
23048 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
23049 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
23050 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
23051 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 23052};
b99bd4ef 23053
c19d1205
ZW
23054/* Table of all explicit relocation names. */
23055#ifdef OBJ_ELF
23056static struct reloc_entry reloc_names[] =
23057{
23058 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
23059 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
23060 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
23061 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
23062 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
23063 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
23064 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
23065 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
23066 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
23067 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 23068 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
23069 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
23070 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 23071 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 23072 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 23073 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 23074 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
23075 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
23076 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
23077 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
23078 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23079 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23080 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
23081 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
23082 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
23083 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
23084 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
23085};
23086#endif
b99bd4ef 23087
5ee91343 23088/* Table of all conditional affixes. */
c19d1205
ZW
23089static const struct asm_cond conds[] =
23090{
23091 {"eq", 0x0},
23092 {"ne", 0x1},
23093 {"cs", 0x2}, {"hs", 0x2},
23094 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
23095 {"mi", 0x4},
23096 {"pl", 0x5},
23097 {"vs", 0x6},
23098 {"vc", 0x7},
23099 {"hi", 0x8},
23100 {"ls", 0x9},
23101 {"ge", 0xa},
23102 {"lt", 0xb},
23103 {"gt", 0xc},
23104 {"le", 0xd},
23105 {"al", 0xe}
23106};
5ee91343
AV
23107static const struct asm_cond vconds[] =
23108{
23109 {"t", 0xf},
23110 {"e", 0x10}
23111};
bfae80f2 23112
e797f7e0 23113#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
23114 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
23115 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 23116
62b3e311
PB
23117static struct asm_barrier_opt barrier_opt_names[] =
23118{
e797f7e0
MGD
23119 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
23120 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
23121 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
23122 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
23123 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
23124 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
23125 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
23126 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
23127 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
23128 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
23129 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
23130 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
23131 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
23132 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
23133 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
23134 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
23135};
23136
e797f7e0
MGD
23137#undef UL_BARRIER
23138
c19d1205
ZW
23139/* Table of ARM-format instructions. */
23140
23141/* Macros for gluing together operand strings. N.B. In all cases
23142 other than OPS0, the trailing OP_stop comes from default
23143 zero-initialization of the unspecified elements of the array. */
23144#define OPS0() { OP_stop, }
23145#define OPS1(a) { OP_##a, }
23146#define OPS2(a,b) { OP_##a,OP_##b, }
23147#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
23148#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
23149#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
23150#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
23151
5be8be5d
DG
23152/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
23153 This is useful when mixing operands for ARM and THUMB, i.e. using the
23154 MIX_ARM_THUMB_OPERANDS macro.
23155 In order to use these macros, prefix the number of operands with _
23156 e.g. _3. */
23157#define OPS_1(a) { a, }
23158#define OPS_2(a,b) { a,b, }
23159#define OPS_3(a,b,c) { a,b,c, }
23160#define OPS_4(a,b,c,d) { a,b,c,d, }
23161#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
23162#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
23163
c19d1205
ZW
23164/* These macros abstract out the exact format of the mnemonic table and
23165 save some repeated characters. */
23166
23167/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
23168#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23169 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 23170 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23171
23172/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
23173 a T_MNEM_xyz enumerator. */
23174#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23175 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23176#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23177 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
23178
23179/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
23180 infix after the third character. */
23181#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 23182 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 23183 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 23184#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 23185 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 23186 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23187#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23188 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 23189#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 23190 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 23191#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23192 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 23193#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 23194 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 23195
c19d1205 23196/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
23197 field is still 0xE. Many of the Thumb variants can be executed
23198 conditionally, so this is checked separately. */
c19d1205 23199#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 23200 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23201 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 23202
dd5181d5
KT
23203/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
23204 Used by mnemonics that have very minimal differences in the encoding for
23205 ARM and Thumb variants and can be handled in a common function. */
23206#define TUEc(mnem, op, top, nops, ops, en) \
23207 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23208 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 23209
c19d1205
ZW
23210/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
23211 condition code field. */
23212#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 23213 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 23214 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
23215
23216/* ARM-only variants of all the above. */
6a86118a 23217#define CE(mnem, op, nops, ops, ae) \
5ee91343 23218 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23219
23220#define C3(mnem, op, nops, ops, ae) \
5ee91343 23221 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 23222
cf3cf39d
TP
23223/* Thumb-only variants of TCE and TUE. */
23224#define ToC(mnem, top, nops, ops, te) \
23225 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23226 do_##te, 0 }
cf3cf39d
TP
23227
23228#define ToU(mnem, top, nops, ops, te) \
23229 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 23230 NULL, do_##te, 0 }
cf3cf39d 23231
4389b29a
AV
23232/* T_MNEM_xyz enumerator variants of ToC. */
23233#define toC(mnem, top, nops, ops, te) \
23234 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 23235 do_##te, 0 }
4389b29a 23236
f6b2b12d
AV
23237/* T_MNEM_xyz enumerator variants of ToU. */
23238#define toU(mnem, top, nops, ops, te) \
23239 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 23240 NULL, do_##te, 0 }
f6b2b12d 23241
e3cb604e
PB
23242/* Legacy mnemonics that always have conditional infix after the third
23243 character. */
23244#define CL(mnem, op, nops, ops, ae) \
21d799b5 23245 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 23246 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 23247
8f06b2d8
PB
23248/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
23249#define cCE(mnem, op, nops, ops, ae) \
5ee91343 23250 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 23251
57785aa2
AV
23252/* mov instructions that are shared between coprocessor and MVE. */
23253#define mcCE(mnem, op, nops, ops, ae) \
23254 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
23255
e3cb604e
PB
23256/* Legacy coprocessor instructions where conditional infix and conditional
23257 suffix are ambiguous. For consistency this includes all FPA instructions,
23258 not just the potentially ambiguous ones. */
23259#define cCL(mnem, op, nops, ops, ae) \
21d799b5 23260 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 23261 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
23262
23263/* Coprocessor, takes either a suffix or a position-3 infix
23264 (for an FPA corner case). */
23265#define C3E(mnem, op, nops, ops, ae) \
21d799b5 23266 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 23267 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 23268
6a86118a 23269#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
23270 { m1 #m2 m3, OPS##nops ops, \
23271 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 23272 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23273
23274#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
23275 xCM_ (m1, , m2, op, nops, ops, ae), \
23276 xCM_ (m1, eq, m2, op, nops, ops, ae), \
23277 xCM_ (m1, ne, m2, op, nops, ops, ae), \
23278 xCM_ (m1, cs, m2, op, nops, ops, ae), \
23279 xCM_ (m1, hs, m2, op, nops, ops, ae), \
23280 xCM_ (m1, cc, m2, op, nops, ops, ae), \
23281 xCM_ (m1, ul, m2, op, nops, ops, ae), \
23282 xCM_ (m1, lo, m2, op, nops, ops, ae), \
23283 xCM_ (m1, mi, m2, op, nops, ops, ae), \
23284 xCM_ (m1, pl, m2, op, nops, ops, ae), \
23285 xCM_ (m1, vs, m2, op, nops, ops, ae), \
23286 xCM_ (m1, vc, m2, op, nops, ops, ae), \
23287 xCM_ (m1, hi, m2, op, nops, ops, ae), \
23288 xCM_ (m1, ls, m2, op, nops, ops, ae), \
23289 xCM_ (m1, ge, m2, op, nops, ops, ae), \
23290 xCM_ (m1, lt, m2, op, nops, ops, ae), \
23291 xCM_ (m1, gt, m2, op, nops, ops, ae), \
23292 xCM_ (m1, le, m2, op, nops, ops, ae), \
23293 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
23294
23295#define UE(mnem, op, nops, ops, ae) \
5ee91343 23296 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
23297
23298#define UF(mnem, op, nops, ops, ae) \
5ee91343 23299 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 23300
5287ad62
JB
23301/* Neon data-processing. ARM versions are unconditional with cond=0xf.
23302 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
23303 use the same encoding function for each. */
23304#define NUF(mnem, op, nops, ops, enc) \
23305 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 23306 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
23307
23308/* Neon data processing, version which indirects through neon_enc_tab for
23309 the various overloaded versions of opcodes. */
23310#define nUF(mnem, op, nops, ops, enc) \
21d799b5 23311 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 23312 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
23313
23314/* Neon insn with conditional suffix for the ARM version, non-overloaded
23315 version. */
5ee91343 23316#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 23317 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 23318 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 23319
037e8744 23320#define NCE(mnem, op, nops, ops, enc) \
5ee91343 23321 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
23322
23323#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 23324 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 23325
5287ad62 23326/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 23327#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 23328 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 23329 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 23330
037e8744 23331#define nCE(mnem, op, nops, ops, enc) \
5ee91343 23332 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
23333
23334#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
23335 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
23336
23337/* */
23338#define mCEF(mnem, op, nops, ops, enc) \
a302e574 23339 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
23340 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23341
23342
23343/* nCEF but for MVE predicated instructions. */
23344#define mnCEF(mnem, op, nops, ops, enc) \
23345 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
23346
23347/* nCE but for MVE predicated instructions. */
23348#define mnCE(mnem, op, nops, ops, enc) \
23349 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 23350
5ee91343
AV
23351/* NUF but for potentially MVE predicated instructions. */
23352#define MNUF(mnem, op, nops, ops, enc) \
23353 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
23354 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23355
23356/* nUF but for potentially MVE predicated instructions. */
23357#define mnUF(mnem, op, nops, ops, enc) \
23358 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
23359 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23360
23361/* ToC but for potentially MVE predicated instructions. */
23362#define mToC(mnem, top, nops, ops, te) \
23363 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
23364 do_##te, 1 }
23365
23366/* NCE but for MVE predicated instructions. */
23367#define MNCE(mnem, op, nops, ops, enc) \
23368 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
23369
23370/* NCEF but for MVE predicated instructions. */
23371#define MNCEF(mnem, op, nops, ops, enc) \
23372 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
23373#define do_0 0
23374
c19d1205 23375static const struct asm_opcode insns[] =
bfae80f2 23376{
74db7efb
NC
23377#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
23378#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
23379 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
23380 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
23381 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
23382 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
23383 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
23384 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
23385 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
23386 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
23387 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
23388 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
23389 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
23390 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
23391 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
23392 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
23393 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
23394 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
23395
23396 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
23397 for setting PSR flag bits. They are obsolete in V6 and do not
23398 have Thumb equivalents. */
21d799b5
NC
23399 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23400 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23401 CL("tstp", 110f000, 2, (RR, SH), cmp),
23402 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23403 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23404 CL("cmpp", 150f000, 2, (RR, SH), cmp),
23405 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23406 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23407 CL("cmnp", 170f000, 2, (RR, SH), cmp),
23408
23409 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 23410 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
23411 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
23412 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
23413
23414 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
23415 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
23416 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
23417 OP_RRnpc),
23418 OP_ADDRGLDR),ldst, t_ldst),
23419 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
23420
23421 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23422 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23423 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23424 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23425 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23426 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23427
21d799b5
NC
23428 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
23429 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 23430
c19d1205 23431 /* Pseudo ops. */
21d799b5 23432 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 23433 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 23434 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 23435 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
23436
23437 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
23438 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
23439 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
23440 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
23441 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
23442 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
23443 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
23444 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
23445 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
23446 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
23447 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
23448 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
23449 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 23450
16a4cf17 23451 /* These may simplify to neg. */
21d799b5
NC
23452 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
23453 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 23454
173205ca
TP
23455#undef THUMB_VARIANT
23456#define THUMB_VARIANT & arm_ext_os
23457
23458 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
23459 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
23460
c921be7d
NC
23461#undef THUMB_VARIANT
23462#define THUMB_VARIANT & arm_ext_v6
23463
21d799b5 23464 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
23465
23466 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
23467#undef THUMB_VARIANT
23468#define THUMB_VARIANT & arm_ext_v6t2
23469
21d799b5
NC
23470 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23471 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23472 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 23473
5be8be5d
DG
23474 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23475 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23476 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
23477 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 23478
21d799b5
NC
23479 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23480 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 23481
21d799b5
NC
23482 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23483 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
23484
23485 /* V1 instructions with no Thumb analogue at all. */
21d799b5 23486 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
23487 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
23488
23489 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
23490 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
23491 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
23492 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
23493 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
23494 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
23495 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
23496 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
23497
c921be7d
NC
23498#undef ARM_VARIANT
23499#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
23500#undef THUMB_VARIANT
23501#define THUMB_VARIANT & arm_ext_v4t
23502
21d799b5
NC
23503 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
23504 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 23505
c921be7d
NC
23506#undef THUMB_VARIANT
23507#define THUMB_VARIANT & arm_ext_v6t2
23508
21d799b5 23509 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
23510 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
23511
23512 /* Generic coprocessor instructions. */
21d799b5
NC
23513 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23514 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23515 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23516 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23517 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23518 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 23519 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 23520
c921be7d
NC
23521#undef ARM_VARIANT
23522#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
23523
21d799b5 23524 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
23525 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
23526
c921be7d
NC
23527#undef ARM_VARIANT
23528#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
23529#undef THUMB_VARIANT
23530#define THUMB_VARIANT & arm_ext_msr
23531
d2cd1205
JB
23532 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
23533 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 23534
c921be7d
NC
23535#undef ARM_VARIANT
23536#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
23537#undef THUMB_VARIANT
23538#define THUMB_VARIANT & arm_ext_v6t2
23539
21d799b5
NC
23540 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23541 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23542 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23543 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23544 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23545 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23546 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23547 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 23548
c921be7d
NC
23549#undef ARM_VARIANT
23550#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
23551#undef THUMB_VARIANT
23552#define THUMB_VARIANT & arm_ext_v4t
23553
5be8be5d
DG
23554 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23555 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23556 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23557 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
23558 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23559 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 23560
c921be7d
NC
23561#undef ARM_VARIANT
23562#define ARM_VARIANT & arm_ext_v4t_5
23563
c19d1205
ZW
23564 /* ARM Architecture 4T. */
23565 /* Note: bx (and blx) are required on V5, even if the processor does
23566 not support Thumb. */
21d799b5 23567 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 23568
c921be7d
NC
23569#undef ARM_VARIANT
23570#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
23571#undef THUMB_VARIANT
23572#define THUMB_VARIANT & arm_ext_v5t
23573
c19d1205
ZW
23574 /* Note: blx has 2 variants; the .value coded here is for
23575 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
23576 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
23577 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 23578
c921be7d
NC
23579#undef THUMB_VARIANT
23580#define THUMB_VARIANT & arm_ext_v6t2
23581
21d799b5
NC
23582 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
23583 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23584 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23585 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23586 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23587 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23588 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
23589 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 23590
c921be7d 23591#undef ARM_VARIANT
74db7efb
NC
23592#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
23593#undef THUMB_VARIANT
23594#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 23595
21d799b5
NC
23596 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23597 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23598 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23599 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 23600
21d799b5
NC
23601 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23602 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 23603
21d799b5
NC
23604 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23605 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23606 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23607 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 23608
21d799b5
NC
23609 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23610 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23611 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23612 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 23613
21d799b5
NC
23614 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23615 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 23616
03ee1b7f
NC
23617 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23618 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23619 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23620 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 23621
c921be7d 23622#undef ARM_VARIANT
74db7efb
NC
23623#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
23624#undef THUMB_VARIANT
23625#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23626
21d799b5 23627 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
23628 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
23629 ldrd, t_ldstd),
23630 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
23631 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 23632
21d799b5
NC
23633 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23634 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 23635
c921be7d
NC
23636#undef ARM_VARIANT
23637#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
23638
21d799b5 23639 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 23640
c921be7d
NC
23641#undef ARM_VARIANT
23642#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
23643#undef THUMB_VARIANT
23644#define THUMB_VARIANT & arm_ext_v6
23645
21d799b5
NC
23646 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
23647 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
23648 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23649 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23650 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23651 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23652 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23653 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23654 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23655 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 23656
c921be7d 23657#undef THUMB_VARIANT
ff8646ee 23658#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 23659
5be8be5d
DG
23660 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
23661 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
23662 strex, t_strex),
ff8646ee
TP
23663#undef THUMB_VARIANT
23664#define THUMB_VARIANT & arm_ext_v6t2
23665
21d799b5
NC
23666 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23667 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 23668
21d799b5
NC
23669 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
23670 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 23671
9e3c6df6 23672/* ARM V6 not included in V7M. */
c921be7d
NC
23673#undef THUMB_VARIANT
23674#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 23675 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 23676 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
23677 UF(rfeib, 9900a00, 1, (RRw), rfe),
23678 UF(rfeda, 8100a00, 1, (RRw), rfe),
23679 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23680 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
23681 UF(rfefa, 8100a00, 1, (RRw), rfe),
23682 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23683 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 23684 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
23685 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
23686 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 23687 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 23688 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 23689 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 23690 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 23691 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 23692 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 23693 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 23694
9e3c6df6
PB
23695/* ARM V6 not included in V7M (eg. integer SIMD). */
23696#undef THUMB_VARIANT
23697#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
23698 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
23699 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
23700 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23701 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23702 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23703 /* Old name for QASX. */
74db7efb 23704 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 23705 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23706 /* Old name for QSAX. */
74db7efb 23707 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23708 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23709 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23710 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23711 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23712 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23713 /* Old name for SASX. */
74db7efb 23714 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23715 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23716 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23717 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23718 /* Old name for SHASX. */
21d799b5 23719 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23720 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23721 /* Old name for SHSAX. */
21d799b5
NC
23722 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23723 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23724 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23725 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23726 /* Old name for SSAX. */
74db7efb 23727 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23728 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23729 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23730 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23731 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23732 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23733 /* Old name for UASX. */
74db7efb 23734 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23735 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23736 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23737 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23738 /* Old name for UHASX. */
21d799b5
NC
23739 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23740 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23741 /* Old name for UHSAX. */
21d799b5
NC
23742 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23743 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23744 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23745 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23746 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 23747 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23748 /* Old name for UQASX. */
21d799b5
NC
23749 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23750 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23751 /* Old name for UQSAX. */
21d799b5
NC
23752 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23753 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23754 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23755 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23756 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 23757 /* Old name for USAX. */
74db7efb 23758 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 23759 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
23760 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23761 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23762 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23763 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23764 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23765 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23766 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23767 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23768 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23769 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23770 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23771 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23772 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23773 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23774 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23775 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23776 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23777 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23778 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23779 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23780 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23781 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23782 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23783 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23784 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23785 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23786 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
23787 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
23788 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
23789 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23790 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23791 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 23792
c921be7d 23793#undef ARM_VARIANT
55e8aae7 23794#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 23795#undef THUMB_VARIANT
55e8aae7 23796#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 23797
21d799b5
NC
23798 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
23799 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
23800 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
23801 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 23802
c921be7d
NC
23803#undef THUMB_VARIANT
23804#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
23805 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
23806 ldrexd, t_ldrexd),
23807 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
23808 RRnpcb), strexd, t_strexd),
ebdca51a 23809
c921be7d 23810#undef THUMB_VARIANT
ff8646ee 23811#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
23812 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
23813 rd_rn, rd_rn),
23814 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
23815 rd_rn, rd_rn),
23816 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 23817 strex, t_strexbh),
5be8be5d 23818 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 23819 strex, t_strexbh),
21d799b5 23820 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 23821
c921be7d 23822#undef ARM_VARIANT
f4c65163 23823#define ARM_VARIANT & arm_ext_sec
74db7efb 23824#undef THUMB_VARIANT
f4c65163 23825#define THUMB_VARIANT & arm_ext_sec
c921be7d 23826
21d799b5 23827 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 23828
90ec0d68
MGD
23829#undef ARM_VARIANT
23830#define ARM_VARIANT & arm_ext_virt
23831#undef THUMB_VARIANT
23832#define THUMB_VARIANT & arm_ext_virt
23833
23834 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
23835 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
23836
ddfded2f
MW
23837#undef ARM_VARIANT
23838#define ARM_VARIANT & arm_ext_pan
23839#undef THUMB_VARIANT
23840#define THUMB_VARIANT & arm_ext_pan
23841
23842 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
23843
c921be7d 23844#undef ARM_VARIANT
74db7efb 23845#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
23846#undef THUMB_VARIANT
23847#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23848
21d799b5
NC
23849 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
23850 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
23851 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
23852 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 23853
21d799b5 23854 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 23855 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 23856
5be8be5d
DG
23857 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23858 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23859 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
23860 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 23861
91d8b670
JG
23862#undef ARM_VARIANT
23863#define ARM_VARIANT & arm_ext_v3
23864#undef THUMB_VARIANT
23865#define THUMB_VARIANT & arm_ext_v6t2
23866
23867 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
23868 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
23869 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
23870
23871#undef ARM_VARIANT
23872#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
23873#undef THUMB_VARIANT
23874#define THUMB_VARIANT & arm_ext_v6t2_v8m
23875 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
23876 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
23877
bf3eeda7 23878 /* Thumb-only instructions. */
74db7efb 23879#undef ARM_VARIANT
bf3eeda7
NS
23880#define ARM_VARIANT NULL
23881 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
23882 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
23883
23884 /* ARM does not really have an IT instruction, so always allow it.
23885 The opcode is copied from Thumb in order to allow warnings in
23886 -mimplicit-it=[never | arm] modes. */
23887#undef ARM_VARIANT
23888#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
23889#undef THUMB_VARIANT
23890#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 23891
21d799b5
NC
23892 TUE("it", bf08, bf08, 1, (COND), it, t_it),
23893 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
23894 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
23895 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
23896 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
23897 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
23898 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
23899 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
23900 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
23901 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
23902 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
23903 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
23904 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
23905 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
23906 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 23907 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
23908 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
23909 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 23910
92e90b6e 23911 /* Thumb2 only instructions. */
c921be7d
NC
23912#undef ARM_VARIANT
23913#define ARM_VARIANT NULL
92e90b6e 23914
21d799b5
NC
23915 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
23916 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
23917 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
23918 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
23919 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
23920 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 23921
eea54501
MGD
23922 /* Hardware division instructions. */
23923#undef ARM_VARIANT
23924#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
23925#undef THUMB_VARIANT
23926#define THUMB_VARIANT & arm_ext_div
23927
eea54501
MGD
23928 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
23929 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 23930
7e806470 23931 /* ARM V6M/V7 instructions. */
c921be7d
NC
23932#undef ARM_VARIANT
23933#define ARM_VARIANT & arm_ext_barrier
23934#undef THUMB_VARIANT
23935#define THUMB_VARIANT & arm_ext_barrier
23936
ccb84d65
JB
23937 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
23938 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
23939 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 23940
62b3e311 23941 /* ARM V7 instructions. */
c921be7d
NC
23942#undef ARM_VARIANT
23943#define ARM_VARIANT & arm_ext_v7
23944#undef THUMB_VARIANT
23945#define THUMB_VARIANT & arm_ext_v7
23946
21d799b5
NC
23947 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
23948 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 23949
74db7efb 23950#undef ARM_VARIANT
60e5ef9f 23951#define ARM_VARIANT & arm_ext_mp
74db7efb 23952#undef THUMB_VARIANT
60e5ef9f
MGD
23953#define THUMB_VARIANT & arm_ext_mp
23954
23955 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
23956
53c4b28b
MGD
23957 /* AArchv8 instructions. */
23958#undef ARM_VARIANT
23959#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
23960
23961/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 23962#undef THUMB_VARIANT
4ed7ed8d 23963#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 23964
4ed7ed8d
TP
23965 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
23966 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
23967 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
23968 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
23969 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
23970 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 23971 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
23972 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
23973 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
23974 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
23975 stlex, t_stlex),
4b8c8c02
RE
23976 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
23977 stlex, t_stlex),
23978 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
23979 stlex, t_stlex),
4ed7ed8d
TP
23980#undef THUMB_VARIANT
23981#define THUMB_VARIANT & arm_ext_v8
53c4b28b 23982
4ed7ed8d 23983 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
23984 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
23985 ldrexd, t_ldrexd),
23986 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
23987 strexd, t_strexd),
f7dd2fb2
TC
23988
23989/* Defined in V8 but is in undefined encoding space for earlier
23990 architectures. However earlier architectures are required to treat
23991 this instuction as a semihosting trap as well. Hence while not explicitly
23992 defined as such, it is in fact correct to define the instruction for all
23993 architectures. */
23994#undef THUMB_VARIANT
23995#define THUMB_VARIANT & arm_ext_v1
23996#undef ARM_VARIANT
23997#define ARM_VARIANT & arm_ext_v1
23998 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
23999
8884b720 24000 /* ARMv8 T32 only. */
74db7efb 24001#undef ARM_VARIANT
b79f7053
MGD
24002#define ARM_VARIANT NULL
24003 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24004 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24005 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24006
33399f07
MGD
24007 /* FP for ARMv8. */
24008#undef ARM_VARIANT
a715796b 24009#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24010#undef THUMB_VARIANT
a715796b 24011#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24012
24013 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24014 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24015 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24016 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 24017 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
24018 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24019 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24020 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24021 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24022 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24023 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 24024
91ff7894
MGD
24025 /* Crypto v1 extensions. */
24026#undef ARM_VARIANT
24027#define ARM_VARIANT & fpu_crypto_ext_armv8
24028#undef THUMB_VARIANT
24029#define THUMB_VARIANT & fpu_crypto_ext_armv8
24030
24031 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24032 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24033 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
24034 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
24035 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
24036 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
24037 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
24038 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
24039 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
24040 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
24041 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
24042 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
24043 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
24044 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 24045
dd5181d5 24046#undef ARM_VARIANT
74db7efb 24047#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
24048#undef THUMB_VARIANT
24049#define THUMB_VARIANT & crc_ext_armv8
24050 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
24051 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
24052 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
24053 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
24054 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
24055 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
24056
105bde57
MW
24057 /* ARMv8.2 RAS extension. */
24058#undef ARM_VARIANT
4d1464f2 24059#define ARM_VARIANT & arm_ext_ras
105bde57 24060#undef THUMB_VARIANT
4d1464f2 24061#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
24062 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
24063
49e8a725
SN
24064#undef ARM_VARIANT
24065#define ARM_VARIANT & arm_ext_v8_3
24066#undef THUMB_VARIANT
24067#define THUMB_VARIANT & arm_ext_v8_3
24068 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
24069
c604a79a
JW
24070#undef ARM_VARIANT
24071#define ARM_VARIANT & fpu_neon_ext_dotprod
24072#undef THUMB_VARIANT
24073#define THUMB_VARIANT & fpu_neon_ext_dotprod
24074 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
24075 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
24076
c921be7d
NC
24077#undef ARM_VARIANT
24078#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
24079#undef THUMB_VARIANT
24080#define THUMB_VARIANT NULL
c921be7d 24081
21d799b5
NC
24082 cCE("wfs", e200110, 1, (RR), rd),
24083 cCE("rfs", e300110, 1, (RR), rd),
24084 cCE("wfc", e400110, 1, (RR), rd),
24085 cCE("rfc", e500110, 1, (RR), rd),
24086
24087 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
24088 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
24089 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
24090 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
24091
24092 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
24093 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
24094 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
24095 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
24096
24097 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
24098 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
24099 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
24100 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
24101 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
24102 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
24103 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
24104 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
24105 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
24106 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
24107 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
24108 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
24109
24110 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
24111 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
24112 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
24113 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
24114 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
24115 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
24116 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
24117 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
24118 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
24119 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
24120 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
24121 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
24122
24123 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
24124 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
24125 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
24126 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
24127 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
24128 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
24129 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
24130 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
24131 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
24132 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
24133 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
24134 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
24135
24136 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
24137 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
24138 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
24139 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
24140 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
24141 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
24142 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
24143 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
24144 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
24145 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
24146 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
24147 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
24148
24149 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
24150 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
24151 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
24152 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
24153 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
24154 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
24155 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
24156 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
24157 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
24158 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
24159 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
24160 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
24161
24162 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
24163 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
24164 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
24165 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
24166 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
24167 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
24168 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
24169 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
24170 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
24171 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
24172 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
24173 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
24174
24175 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
24176 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
24177 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
24178 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
24179 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
24180 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
24181 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
24182 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
24183 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
24184 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
24185 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
24186 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
24187
24188 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
24189 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
24190 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
24191 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
24192 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
24193 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
24194 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
24195 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
24196 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
24197 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
24198 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
24199 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
24200
24201 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
24202 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
24203 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
24204 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
24205 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
24206 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
24207 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
24208 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
24209 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
24210 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
24211 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
24212 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
24213
24214 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
24215 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
24216 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
24217 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
24218 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
24219 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
24220 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
24221 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
24222 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
24223 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
24224 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
24225 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
24226
24227 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
24228 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
24229 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
24230 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
24231 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
24232 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
24233 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
24234 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
24235 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
24236 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
24237 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
24238 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
24239
24240 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
24241 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
24242 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
24243 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
24244 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
24245 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
24246 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
24247 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
24248 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
24249 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
24250 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
24251 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
24252
24253 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
24254 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
24255 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
24256 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
24257 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
24258 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
24259 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
24260 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
24261 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
24262 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
24263 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
24264 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
24265
24266 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
24267 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
24268 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
24269 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
24270 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
24271 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
24272 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
24273 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
24274 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
24275 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
24276 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
24277 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
24278
24279 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
24280 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
24281 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
24282 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
24283 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
24284 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
24285 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
24286 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
24287 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
24288 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
24289 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
24290 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
24291
24292 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
24293 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
24294 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
24295 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
24296 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
24297 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
24298 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
24299 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
24300 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
24301 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
24302 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
24303 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
24304
24305 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
24306 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
24307 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
24308 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
24309 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
24310 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24311 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24312 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24313 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
24314 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
24315 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
24316 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
24317
24318 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
24319 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
24320 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
24321 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
24322 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
24323 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24324 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24325 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24326 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
24327 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
24328 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
24329 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
24330
24331 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
24332 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
24333 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
24334 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
24335 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
24336 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24337 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24338 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24339 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
24340 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
24341 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
24342 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
24343
24344 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
24345 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
24346 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
24347 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
24348 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
24349 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24350 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24351 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24352 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
24353 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
24354 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
24355 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
24356
24357 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
24358 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
24359 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
24360 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
24361 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
24362 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24363 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24364 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24365 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
24366 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
24367 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
24368 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
24369
24370 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
24371 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
24372 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
24373 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
24374 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
24375 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24376 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24377 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24378 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
24379 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
24380 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
24381 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
24382
24383 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
24384 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
24385 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
24386 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
24387 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
24388 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24389 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24390 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24391 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
24392 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
24393 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
24394 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
24395
24396 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
24397 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
24398 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
24399 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
24400 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
24401 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24402 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24403 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24404 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
24405 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
24406 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
24407 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
24408
24409 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
24410 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
24411 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
24412 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
24413 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
24414 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24415 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24416 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24417 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
24418 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
24419 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
24420 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
24421
24422 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
24423 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
24424 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
24425 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
24426 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
24427 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24428 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24429 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24430 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
24431 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
24432 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
24433 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
24434
24435 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24436 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24437 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24438 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24439 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24440 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24441 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24442 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24443 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24444 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24445 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24446 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24447
24448 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24449 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24450 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24451 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24452 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24453 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24454 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24455 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24456 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24457 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24458 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24459 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24460
24461 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24462 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24463 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24464 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24465 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24466 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24467 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24468 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24469 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24470 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24471 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24472 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24473
24474 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
24475 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
24476 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
24477 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
24478
24479 cCL("flts", e000110, 2, (RF, RR), rn_rd),
24480 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
24481 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
24482 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
24483 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
24484 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
24485 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
24486 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
24487 cCL("flte", e080110, 2, (RF, RR), rn_rd),
24488 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
24489 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
24490 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 24491
c19d1205
ZW
24492 /* The implementation of the FIX instruction is broken on some
24493 assemblers, in that it accepts a precision specifier as well as a
24494 rounding specifier, despite the fact that this is meaningless.
24495 To be more compatible, we accept it as well, though of course it
24496 does not set any bits. */
21d799b5
NC
24497 cCE("fix", e100110, 2, (RR, RF), rd_rm),
24498 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
24499 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
24500 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
24501 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
24502 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
24503 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
24504 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
24505 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
24506 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
24507 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
24508 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
24509 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 24510
c19d1205 24511 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
24512#undef ARM_VARIANT
24513#define ARM_VARIANT & fpu_fpa_ext_v2
24514
21d799b5
NC
24515 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24516 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24517 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24518 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24519 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24520 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 24521
c921be7d
NC
24522#undef ARM_VARIANT
24523#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
24524#undef THUMB_VARIANT
24525#define THUMB_VARIANT & arm_ext_v6t2
24526 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
24527 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
24528#undef THUMB_VARIANT
c921be7d 24529
c19d1205 24530 /* Moves and type conversions. */
21d799b5
NC
24531 cCE("fmstat", ef1fa10, 0, (), noargs),
24532 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
24533 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
24534 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
24535 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24536 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
24537 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24538 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
24539 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
24540
24541 /* Memory operations. */
21d799b5
NC
24542 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24543 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
24544 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24545 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24546 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24547 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24548 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24549 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24550 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24551 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24552 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24553 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24554 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24555 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24556 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24557 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24558 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24559 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 24560
c19d1205 24561 /* Monadic operations. */
21d799b5
NC
24562 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
24563 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
24564 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
24565
24566 /* Dyadic operations. */
21d799b5
NC
24567 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24568 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24569 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24570 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24571 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24572 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24573 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24574 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24575 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 24576
c19d1205 24577 /* Comparisons. */
21d799b5
NC
24578 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
24579 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
24580 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
24581 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 24582
62f3b8c8
PB
24583 /* Double precision load/store are still present on single precision
24584 implementations. */
24585 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24586 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
24587 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24588 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24589 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24590 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24591 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24592 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24593 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24594 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 24595
c921be7d
NC
24596#undef ARM_VARIANT
24597#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
24598
c19d1205 24599 /* Moves and type conversions. */
21d799b5
NC
24600 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24601 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24602 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
24603 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
24604 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
24605 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
24606 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24607 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
24608 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24609 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24610 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24611 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 24612
c19d1205 24613 /* Monadic operations. */
21d799b5
NC
24614 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24615 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24616 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
24617
24618 /* Dyadic operations. */
21d799b5
NC
24619 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24620 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24621 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24622 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24623 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24624 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24625 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24626 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24627 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 24628
c19d1205 24629 /* Comparisons. */
21d799b5
NC
24630 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24631 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
24632 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24633 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 24634
037e8744
JB
24635/* Instructions which may belong to either the Neon or VFP instruction sets.
24636 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
24637#undef ARM_VARIANT
24638#define ARM_VARIANT & fpu_vfp_ext_v1xd
24639#undef THUMB_VARIANT
24640#define THUMB_VARIANT & fpu_vfp_ext_v1xd
24641
037e8744
JB
24642 /* These mnemonics are unique to VFP. */
24643 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
24644 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
24645 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24646 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24647 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
24648 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
24649 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
24650 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
24651
24652 /* Mnemonics shared by Neon and VFP. */
21d799b5 24653 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 24654
55881a11
MGD
24655 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24656 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24657 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24658 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24659 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24660 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
037e8744 24661
dd9634d9 24662 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 24663 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
24664 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
24665 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 24666
037e8744
JB
24667
24668 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
24669 NCE(vmovq, 0, 1, (VMOV), neon_mov),
24670
32c36c3c
AV
24671#undef THUMB_VARIANT
24672/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
24673 by different feature bits. Since we are setting the Thumb guard, we can
24674 require Thumb-1 which makes it a nop guard and set the right feature bit in
24675 do_vldr_vstr (). */
24676#define THUMB_VARIANT & arm_ext_v4t
24677 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24678 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24679
9db2f6b4
RL
24680#undef ARM_VARIANT
24681#define ARM_VARIANT & arm_ext_fp16
24682#undef THUMB_VARIANT
24683#define THUMB_VARIANT & arm_ext_fp16
24684 /* New instructions added from v8.2, allowing the extraction and insertion of
24685 the upper 16 bits of a 32-bit vector register. */
24686 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
24687 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
24688
dec41383
JW
24689 /* New backported fma/fms instructions optional in v8.2. */
24690 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
24691 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
24692
c921be7d
NC
24693#undef THUMB_VARIANT
24694#define THUMB_VARIANT & fpu_neon_ext_v1
24695#undef ARM_VARIANT
24696#define ARM_VARIANT & fpu_neon_ext_v1
24697
5287ad62
JB
24698 /* Data processing with three registers of the same length. */
24699 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
24700 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
24701 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 24702 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 24703 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
24704 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
24705 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 24706 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 24707 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 24708 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 24709 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 24710 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
24711 shl should accept I8 I16 I32 I64,
24712 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
24713 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
24714 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 24715 /* Logic ops, types optional & ignored. */
4316f0d2 24716 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24717 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24718 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24719 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 24720 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
24721 /* Bitfield ops, untyped. */
24722 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24723 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24724 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24725 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24726 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24727 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 24728 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 24729 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 24730 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 24731 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
24732 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
24733 back to neon_dyadic_if_su. */
21d799b5
NC
24734 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24735 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24736 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24737 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24738 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24739 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
24740 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24741 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 24742 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
24743 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
24744 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 24745 /* As above, D registers only. */
21d799b5
NC
24746 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
24747 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 24748 /* Int and float variants, signedness unimportant. */
21d799b5
NC
24749 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24750 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24751 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 24752 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
24753 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
24754 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
24755 /* vtst takes sizes 8, 16, 32. */
24756 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
24757 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
24758 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 24759 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 24760 /* VQD{R}MULH takes S16 S32. */
21d799b5 24761 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 24762 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
24763 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24764 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
24765 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24766 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
24767 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24768 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
24769 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24770 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
24771 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24772 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
24773 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24774 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 24775 /* ARM v8.1 extension. */
643afb90
MW
24776 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
24777 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
24778 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
24779
24780 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 24781 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
24782 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
24783
24784 /* Data processing with two registers and a shift amount. */
24785 /* Right shifts, and variants with rounding.
24786 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 24787 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
24788 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
24789 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24790 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24791 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24792 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24793 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 24794 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
24795 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
24796 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
24797 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
24798 /* Right shift immediate, saturating & narrowing, with rounding variants.
24799 Types accepted S16 S32 S64 U16 U32 U64. */
24800 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24801 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24802 /* As above, unsigned. Types accepted S16 S32 S64. */
24803 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24804 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24805 /* Right shift narrowing. Types accepted I16 I32 I64. */
24806 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24807 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24808 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 24809 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 24810 /* CVT with optional immediate for fixed-point variant. */
21d799b5 24811 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 24812
4316f0d2 24813 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
24814
24815 /* Data processing, three registers of different lengths. */
24816 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
24817 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
24818 /* If not scalar, fall back to neon_dyadic_long.
24819 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
24820 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
24821 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
24822 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
24823 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24824 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24825 /* Dyadic, narrowing insns. Types I16 I32 I64. */
24826 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24827 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24828 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24829 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24830 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
24831 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24832 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24833 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
24834 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
24835 S16 S32 U16 U32. */
21d799b5 24836 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
24837
24838 /* Extract. Size 8. */
3b8d421e
PB
24839 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
24840 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
24841
24842 /* Two registers, miscellaneous. */
24843 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 24844 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 24845 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
24846 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
24847 /* Vector replicate. Sizes 8 16 32. */
21d799b5 24848 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
24849 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
24850 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
24851 /* VMOVN. Types I16 I32 I64. */
21d799b5 24852 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 24853 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 24854 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 24855 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 24856 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
24857 /* VZIP / VUZP. Sizes 8 16 32. */
24858 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
24859 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
24860 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
24861 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
24862 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 24863 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
24864 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
24865 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
24866 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
24867 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
24868 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
24869 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 24870 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
24871 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
24872 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
24873 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
24874 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
24875 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
24876 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
24877 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
24878 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
24879 /* VCNT. Size 8. */
24880 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
24881 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
24882 /* Two address, untyped. */
24883 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
24884 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
24885 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
24886 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
24887 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
24888
24889 /* Table lookup. Size 8. */
24890 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
24891 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
24892
c921be7d
NC
24893#undef THUMB_VARIANT
24894#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
24895#undef ARM_VARIANT
24896#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
24897
5287ad62 24898 /* Neon element/structure load/store. */
21d799b5
NC
24899 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
24900 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
24901 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
24902 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
24903 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
24904 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
24905 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
24906 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 24907
c921be7d 24908#undef THUMB_VARIANT
74db7efb
NC
24909#define THUMB_VARIANT & fpu_vfp_ext_v3xd
24910#undef ARM_VARIANT
24911#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
24912 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
24913 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24914 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24915 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24916 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24917 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24918 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24919 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
24920 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
24921
74db7efb 24922#undef THUMB_VARIANT
c921be7d
NC
24923#define THUMB_VARIANT & fpu_vfp_ext_v3
24924#undef ARM_VARIANT
24925#define ARM_VARIANT & fpu_vfp_ext_v3
24926
21d799b5 24927 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 24928 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24929 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 24930 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24931 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 24932 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24933 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 24934 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 24935 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 24936
74db7efb
NC
24937#undef ARM_VARIANT
24938#define ARM_VARIANT & fpu_vfp_ext_fma
24939#undef THUMB_VARIANT
24940#define THUMB_VARIANT & fpu_vfp_ext_fma
d58196e0 24941 /* Mnemonics shared by Neon, VFP and MVE. These are included in the
62f3b8c8
PB
24942 VFP FMA variant; NEON and VFP FMA always includes the NEON
24943 FMA instructions. */
d58196e0
AV
24944 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
24945 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
24946
62f3b8c8
PB
24947 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
24948 the v form should always be used. */
24949 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24950 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24951 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24952 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24953 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24954 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24955
5287ad62 24956#undef THUMB_VARIANT
c921be7d
NC
24957#undef ARM_VARIANT
24958#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
24959
21d799b5
NC
24960 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24961 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24962 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24963 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24964 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24965 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
24966 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
24967 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 24968
c921be7d
NC
24969#undef ARM_VARIANT
24970#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
24971
21d799b5
NC
24972 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
24973 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
24974 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
24975 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
24976 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
24977 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
24978 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
24979 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
24980 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
24981 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
24982 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
24983 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
24984 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
24985 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
24986 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
24987 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
24988 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
24989 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
24990 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
24991 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
24992 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
24993 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
24994 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
24995 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
24996 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
24997 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
24998 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
24999 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25000 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25001 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25002 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25003 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25004 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25005 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25006 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25007 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25008 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25009 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25010 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25011 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25012 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25013 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25014 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25015 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25016 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25017 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25018 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
25019 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25020 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25021 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25022 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25023 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25024 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25025 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25026 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25027 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25028 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25029 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25030 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25031 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25032 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25033 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25034 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25035 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25036 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25037 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25038 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25039 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25040 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25041 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25042 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25043 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25044 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25045 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25046 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25047 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25048 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25049 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25050 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25051 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25052 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25053 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25054 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25055 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25056 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25057 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25058 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25059 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25060 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
25061 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25062 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25063 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25064 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25065 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
25066 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25067 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25068 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25069 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25070 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25071 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
25072 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25073 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25074 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25075 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25076 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25077 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25078 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25079 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25080 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25081 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25082 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
25083 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25084 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25085 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25086 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25087 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25088 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25089 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25090 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25091 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25092 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25093 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25094 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25095 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25096 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25097 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25098 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25099 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25100 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25101 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25102 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25103 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25104 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25105 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25106 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25107 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25108 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25109 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25110 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25111 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25112 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25113 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25114 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
25115 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
25116 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
25117 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
25118 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
25119 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
25120 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25121 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25122 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25123 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
25124 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
25125 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
25126 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
25127 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
25128 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
25129 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25130 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25131 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25132 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25133 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 25134
c921be7d
NC
25135#undef ARM_VARIANT
25136#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
25137
21d799b5
NC
25138 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
25139 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
25140 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
25141 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
25142 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
25143 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
25144 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25145 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25146 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25147 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25148 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25149 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25150 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25151 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25152 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25153 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25154 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25155 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25156 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25157 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25158 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
25159 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25160 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25161 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25162 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25163 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25164 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25165 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25166 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25167 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25168 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25169 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25170 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25171 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25172 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25173 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25174 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25175 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25176 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25177 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25178 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25179 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25180 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25181 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25182 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25183 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25184 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25185 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25186 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25187 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25188 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25189 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25190 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25191 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25192 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25193 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25194 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 25195
c921be7d
NC
25196#undef ARM_VARIANT
25197#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
25198
21d799b5
NC
25199 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25200 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25201 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25202 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25203 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25204 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25205 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25206 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25207 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
25208 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
25209 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
25210 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
25211 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
25212 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
25213 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
25214 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
25215 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
25216 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
25217 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
25218 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
25219 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
25220 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
25221 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
25222 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
25223 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
25224 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
25225 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
25226 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
25227 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
25228 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
25229 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
25230 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
25231 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
25232 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
25233 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
25234 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
25235 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
25236 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
25237 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
25238 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
25239 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
25240 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
25241 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
25242 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
25243 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
25244 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
25245 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
25246 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
25247 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
25248 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
25249 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
25250 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
25251 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
25252 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
25253 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
25254 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
25255 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
25256 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
25257 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
25258 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
25259 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
25260 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
25261 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
25262 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
25263 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25264 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25265 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25266 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25267 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25268 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25269 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25270 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
25271 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
25272 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
25273 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
25274 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 25275
7fadb25d
SD
25276 /* ARMv8.5-A instructions. */
25277#undef ARM_VARIANT
25278#define ARM_VARIANT & arm_ext_sb
25279#undef THUMB_VARIANT
25280#define THUMB_VARIANT & arm_ext_sb
25281 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
25282
dad0c3bf
SD
25283#undef ARM_VARIANT
25284#define ARM_VARIANT & arm_ext_predres
25285#undef THUMB_VARIANT
25286#define THUMB_VARIANT & arm_ext_predres
25287 CE("cfprctx", e070f93, 1, (RRnpc), rd),
25288 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
25289 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
25290
16a1fa25 25291 /* ARMv8-M instructions. */
4ed7ed8d
TP
25292#undef ARM_VARIANT
25293#define ARM_VARIANT NULL
25294#undef THUMB_VARIANT
25295#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
25296 ToU("sg", e97fe97f, 0, (), noargs),
25297 ToC("blxns", 4784, 1, (RRnpc), t_blx),
25298 ToC("bxns", 4704, 1, (RRnpc), t_bx),
25299 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
25300 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
25301 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
25302 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
25303
25304 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
25305 instructions behave as nop if no VFP is present. */
25306#undef THUMB_VARIANT
25307#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
25308 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
25309 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
25310
25311 /* Armv8.1-M Mainline instructions. */
25312#undef THUMB_VARIANT
25313#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
25314 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25315 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25316 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25317 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25318 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
25319 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
25320 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25321 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25322 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25323
4389b29a 25324 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 25325 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 25326 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 25327 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 25328 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
25329
25330 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
25331 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
25332 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 25333
efd6b359 25334 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
25335 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
25336
25337#undef THUMB_VARIANT
25338#define THUMB_VARIANT & mve_ext
23d00a41
SD
25339 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25340 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25341 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25342 ToC("uqrshll", ea51010d, 3, (RRe, RRo, RRnpcsp), mve_scalar_shift),
25343 ToC("sqrshrl", ea51012d, 3, (RRe, RRo, RRnpcsp), mve_scalar_shift),
25344 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
25345 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25346 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
25347 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
25348 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25349 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25350 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
25351 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
25352 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
25353 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
25354
25355 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25356 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25357 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25358 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25359 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25360 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25361 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25362 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25363 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25364 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25365 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25366 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25367 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25368 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25369 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25370
5ee91343
AV
25371 ToC("vpst", fe710f4d, 0, (), mve_vpt),
25372 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
25373 ToC("vpste", fe718f4d, 0, (), mve_vpt),
25374 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
25375 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
25376 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
25377 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
25378 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
25379 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
25380 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
25381 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
25382 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
25383 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
25384 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
25385 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
25386
a302e574 25387 /* MVE and MVE FP only. */
7df54120 25388 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
c2dafc2a
AV
25389 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
25390 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
25391 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25392 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 25393 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
25394 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
25395 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25396 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25397 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25398 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25399 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25400 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25401 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25402 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25403 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25404 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25405
35c228db
AV
25406 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25407 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25408 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25409 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25410 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25411 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25412 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25413 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25414 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25415 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25416 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25417 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
25418 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25419 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25420 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25421 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25422 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25423 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25424 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25425 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 25426
57785aa2
AV
25427 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
25428 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 25429 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
25430 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
25431 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
25432 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
25433 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
25434 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
25435 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25436 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
25437 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
25438 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25439 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
25440 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
25441 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
25442 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
25443 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 25444
93925576
AV
25445 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25446 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25447 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25448 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25449 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25450 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25451 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25452 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25453 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25454 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25455 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25456 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25457 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25458 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25459 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25460 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25461 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25462 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25463 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25464 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25465
2d78f95b
AV
25466 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
25467 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25468 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
25469 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
25470 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 25471
8b8b22a4
AV
25472 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25473 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25474 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25475 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25476 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25477 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25478 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25479 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
25480 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25481 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25482 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
25483 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25484 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
25485 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
25486 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
25487 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
25488 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 25489
4aa88b50
AV
25490 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25491 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25492 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25493 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25494 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25495 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25496 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25497 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25498 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25499 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25500 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25501 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25502
acca5630
AV
25503 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
25504 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
25505 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
25506
1f6234a3
AV
25507 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
25508 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
25509 toU("letp", _letp, 2, (LR, EXP), t_loloop),
25510 toU("lctp", _lctp, 0, (), t_loloop),
25511
5d281bf0
AV
25512#undef THUMB_VARIANT
25513#define THUMB_VARIANT & mve_fp_ext
25514 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 25515 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
25516 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25517 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
25518 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
25519 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
25520 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
25521 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 25522
5ee91343 25523#undef ARM_VARIANT
57785aa2 25524#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
25525#undef THUMB_VARIANT
25526#define THUMB_VARIANT & arm_ext_v6t2
a8465a06
AV
25527 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
25528 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
5ee91343 25529
57785aa2
AV
25530 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25531
25532#undef ARM_VARIANT
25533#define ARM_VARIANT & fpu_vfp_ext_v1xd
25534
25535 MNCE(vmov, 0, 1, (VMOV), neon_mov),
25536 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
25537 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
25538 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
25539
886e1c73
AV
25540 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
25541 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25542 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 25543
485dee97
AV
25544 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25545 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25546
57785aa2
AV
25547 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
25548 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
25549
1b883319
AV
25550 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25551 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25552
57785aa2
AV
25553#undef ARM_VARIANT
25554#define ARM_VARIANT & fpu_vfp_ext_v2
25555
25556 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
25557 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
25558 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
25559 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
25560
dd9634d9
AV
25561#undef ARM_VARIANT
25562#define ARM_VARIANT & fpu_vfp_ext_armv8xd
25563 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
25564 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
25565 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
25566 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
25567 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25568 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
25569
25570#undef ARM_VARIANT
5ee91343 25571#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 25572 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343
AV
25573 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
25574 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
25575 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
f601a00c
AV
25576 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25577 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25578 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25579 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25580 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
25581 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
25582 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 25583 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
25584 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25585 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
25586 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
25587 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25588 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
25589 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25590 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
25591 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
25592 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25593 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
25594 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
25595 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25596 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
25597 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25598 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
25599 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25600 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25601 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
25602 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
25603 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
25604 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
25605 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
25606 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
25607 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
25608 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
25609
25610#undef ARM_VARIANT
25611#define ARM_VARIANT & arm_ext_v8_3
25612#undef THUMB_VARIANT
25613#define THUMB_VARIANT & arm_ext_v6t2_v8m
25614 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
25615 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
c19d1205
ZW
25616};
25617#undef ARM_VARIANT
25618#undef THUMB_VARIANT
25619#undef TCE
c19d1205
ZW
25620#undef TUE
25621#undef TUF
25622#undef TCC
8f06b2d8 25623#undef cCE
e3cb604e
PB
25624#undef cCL
25625#undef C3E
4389b29a 25626#undef C3
c19d1205
ZW
25627#undef CE
25628#undef CM
4389b29a 25629#undef CL
c19d1205
ZW
25630#undef UE
25631#undef UF
25632#undef UT
5287ad62
JB
25633#undef NUF
25634#undef nUF
25635#undef NCE
25636#undef nCE
c19d1205
ZW
25637#undef OPS0
25638#undef OPS1
25639#undef OPS2
25640#undef OPS3
25641#undef OPS4
25642#undef OPS5
25643#undef OPS6
25644#undef do_0
4389b29a
AV
25645#undef ToC
25646#undef toC
25647#undef ToU
f6b2b12d 25648#undef toU
c19d1205
ZW
25649\f
25650/* MD interface: bits in the object file. */
bfae80f2 25651
c19d1205
ZW
25652/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
25653 for use in the a.out file, and stores them in the array pointed to by buf.
25654 This knows about the endian-ness of the target machine and does
25655 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
25656 2 (short) and 4 (long) Floating numbers are put out as a series of
25657 LITTLENUMS (shorts, here at least). */
b99bd4ef 25658
c19d1205
ZW
25659void
25660md_number_to_chars (char * buf, valueT val, int n)
25661{
25662 if (target_big_endian)
25663 number_to_chars_bigendian (buf, val, n);
25664 else
25665 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
25666}
25667
c19d1205
ZW
25668static valueT
25669md_chars_to_number (char * buf, int n)
bfae80f2 25670{
c19d1205
ZW
25671 valueT result = 0;
25672 unsigned char * where = (unsigned char *) buf;
bfae80f2 25673
c19d1205 25674 if (target_big_endian)
b99bd4ef 25675 {
c19d1205
ZW
25676 while (n--)
25677 {
25678 result <<= 8;
25679 result |= (*where++ & 255);
25680 }
b99bd4ef 25681 }
c19d1205 25682 else
b99bd4ef 25683 {
c19d1205
ZW
25684 while (n--)
25685 {
25686 result <<= 8;
25687 result |= (where[n] & 255);
25688 }
bfae80f2 25689 }
b99bd4ef 25690
c19d1205 25691 return result;
bfae80f2 25692}
b99bd4ef 25693
c19d1205 25694/* MD interface: Sections. */
b99bd4ef 25695
fa94de6b
RM
25696/* Calculate the maximum variable size (i.e., excluding fr_fix)
25697 that an rs_machine_dependent frag may reach. */
25698
25699unsigned int
25700arm_frag_max_var (fragS *fragp)
25701{
25702 /* We only use rs_machine_dependent for variable-size Thumb instructions,
25703 which are either THUMB_SIZE (2) or INSN_SIZE (4).
25704
25705 Note that we generate relaxable instructions even for cases that don't
25706 really need it, like an immediate that's a trivial constant. So we're
25707 overestimating the instruction size for some of those cases. Rather
25708 than putting more intelligence here, it would probably be better to
25709 avoid generating a relaxation frag in the first place when it can be
25710 determined up front that a short instruction will suffice. */
25711
25712 gas_assert (fragp->fr_type == rs_machine_dependent);
25713 return INSN_SIZE;
25714}
25715
0110f2b8
PB
25716/* Estimate the size of a frag before relaxing. Assume everything fits in
25717 2 bytes. */
25718
c19d1205 25719int
0110f2b8 25720md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
25721 segT segtype ATTRIBUTE_UNUSED)
25722{
0110f2b8
PB
25723 fragp->fr_var = 2;
25724 return 2;
25725}
25726
25727/* Convert a machine dependent frag. */
25728
25729void
25730md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
25731{
25732 unsigned long insn;
25733 unsigned long old_op;
25734 char *buf;
25735 expressionS exp;
25736 fixS *fixp;
25737 int reloc_type;
25738 int pc_rel;
25739 int opcode;
25740
25741 buf = fragp->fr_literal + fragp->fr_fix;
25742
25743 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
25744 if (fragp->fr_symbol)
25745 {
0110f2b8
PB
25746 exp.X_op = O_symbol;
25747 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
25748 }
25749 else
25750 {
0110f2b8 25751 exp.X_op = O_constant;
5f4273c7 25752 }
0110f2b8
PB
25753 exp.X_add_number = fragp->fr_offset;
25754 opcode = fragp->fr_subtype;
25755 switch (opcode)
25756 {
25757 case T_MNEM_ldr_pc:
25758 case T_MNEM_ldr_pc2:
25759 case T_MNEM_ldr_sp:
25760 case T_MNEM_str_sp:
25761 case T_MNEM_ldr:
25762 case T_MNEM_ldrb:
25763 case T_MNEM_ldrh:
25764 case T_MNEM_str:
25765 case T_MNEM_strb:
25766 case T_MNEM_strh:
25767 if (fragp->fr_var == 4)
25768 {
5f4273c7 25769 insn = THUMB_OP32 (opcode);
0110f2b8
PB
25770 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
25771 {
25772 insn |= (old_op & 0x700) << 4;
25773 }
25774 else
25775 {
25776 insn |= (old_op & 7) << 12;
25777 insn |= (old_op & 0x38) << 13;
25778 }
25779 insn |= 0x00000c00;
25780 put_thumb32_insn (buf, insn);
25781 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
25782 }
25783 else
25784 {
25785 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
25786 }
25787 pc_rel = (opcode == T_MNEM_ldr_pc2);
25788 break;
25789 case T_MNEM_adr:
25790 if (fragp->fr_var == 4)
25791 {
25792 insn = THUMB_OP32 (opcode);
25793 insn |= (old_op & 0xf0) << 4;
25794 put_thumb32_insn (buf, insn);
25795 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
25796 }
25797 else
25798 {
25799 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25800 exp.X_add_number -= 4;
25801 }
25802 pc_rel = 1;
25803 break;
25804 case T_MNEM_mov:
25805 case T_MNEM_movs:
25806 case T_MNEM_cmp:
25807 case T_MNEM_cmn:
25808 if (fragp->fr_var == 4)
25809 {
25810 int r0off = (opcode == T_MNEM_mov
25811 || opcode == T_MNEM_movs) ? 0 : 8;
25812 insn = THUMB_OP32 (opcode);
25813 insn = (insn & 0xe1ffffff) | 0x10000000;
25814 insn |= (old_op & 0x700) << r0off;
25815 put_thumb32_insn (buf, insn);
25816 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
25817 }
25818 else
25819 {
25820 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
25821 }
25822 pc_rel = 0;
25823 break;
25824 case T_MNEM_b:
25825 if (fragp->fr_var == 4)
25826 {
25827 insn = THUMB_OP32(opcode);
25828 put_thumb32_insn (buf, insn);
25829 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
25830 }
25831 else
25832 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
25833 pc_rel = 1;
25834 break;
25835 case T_MNEM_bcond:
25836 if (fragp->fr_var == 4)
25837 {
25838 insn = THUMB_OP32(opcode);
25839 insn |= (old_op & 0xf00) << 14;
25840 put_thumb32_insn (buf, insn);
25841 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
25842 }
25843 else
25844 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
25845 pc_rel = 1;
25846 break;
25847 case T_MNEM_add_sp:
25848 case T_MNEM_add_pc:
25849 case T_MNEM_inc_sp:
25850 case T_MNEM_dec_sp:
25851 if (fragp->fr_var == 4)
25852 {
25853 /* ??? Choose between add and addw. */
25854 insn = THUMB_OP32 (opcode);
25855 insn |= (old_op & 0xf0) << 4;
25856 put_thumb32_insn (buf, insn);
16805f35
PB
25857 if (opcode == T_MNEM_add_pc)
25858 reloc_type = BFD_RELOC_ARM_T32_IMM12;
25859 else
25860 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
25861 }
25862 else
25863 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25864 pc_rel = 0;
25865 break;
25866
25867 case T_MNEM_addi:
25868 case T_MNEM_addis:
25869 case T_MNEM_subi:
25870 case T_MNEM_subis:
25871 if (fragp->fr_var == 4)
25872 {
25873 insn = THUMB_OP32 (opcode);
25874 insn |= (old_op & 0xf0) << 4;
25875 insn |= (old_op & 0xf) << 16;
25876 put_thumb32_insn (buf, insn);
16805f35
PB
25877 if (insn & (1 << 20))
25878 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
25879 else
25880 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
25881 }
25882 else
25883 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25884 pc_rel = 0;
25885 break;
25886 default:
5f4273c7 25887 abort ();
0110f2b8
PB
25888 }
25889 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 25890 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
25891 fixp->fx_file = fragp->fr_file;
25892 fixp->fx_line = fragp->fr_line;
25893 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
25894
25895 /* Set whether we use thumb-2 ISA based on final relaxation results. */
25896 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
25897 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
25898 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
25899}
25900
25901/* Return the size of a relaxable immediate operand instruction.
25902 SHIFT and SIZE specify the form of the allowable immediate. */
25903static int
25904relax_immediate (fragS *fragp, int size, int shift)
25905{
25906 offsetT offset;
25907 offsetT mask;
25908 offsetT low;
25909
25910 /* ??? Should be able to do better than this. */
25911 if (fragp->fr_symbol)
25912 return 4;
25913
25914 low = (1 << shift) - 1;
25915 mask = (1 << (shift + size)) - (1 << shift);
25916 offset = fragp->fr_offset;
25917 /* Force misaligned offsets to 32-bit variant. */
25918 if (offset & low)
5e77afaa 25919 return 4;
0110f2b8
PB
25920 if (offset & ~mask)
25921 return 4;
25922 return 2;
25923}
25924
5e77afaa
PB
25925/* Get the address of a symbol during relaxation. */
25926static addressT
5f4273c7 25927relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
25928{
25929 fragS *sym_frag;
25930 addressT addr;
25931 symbolS *sym;
25932
25933 sym = fragp->fr_symbol;
25934 sym_frag = symbol_get_frag (sym);
25935 know (S_GET_SEGMENT (sym) != absolute_section
25936 || sym_frag == &zero_address_frag);
25937 addr = S_GET_VALUE (sym) + fragp->fr_offset;
25938
25939 /* If frag has yet to be reached on this pass, assume it will
25940 move by STRETCH just as we did. If this is not so, it will
25941 be because some frag between grows, and that will force
25942 another pass. */
25943
25944 if (stretch != 0
25945 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
25946 {
25947 fragS *f;
25948
25949 /* Adjust stretch for any alignment frag. Note that if have
25950 been expanding the earlier code, the symbol may be
25951 defined in what appears to be an earlier frag. FIXME:
25952 This doesn't handle the fr_subtype field, which specifies
25953 a maximum number of bytes to skip when doing an
25954 alignment. */
25955 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
25956 {
25957 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
25958 {
25959 if (stretch < 0)
25960 stretch = - ((- stretch)
25961 & ~ ((1 << (int) f->fr_offset) - 1));
25962 else
25963 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
25964 if (stretch == 0)
25965 break;
25966 }
25967 }
25968 if (f != NULL)
25969 addr += stretch;
25970 }
5e77afaa
PB
25971
25972 return addr;
25973}
25974
0110f2b8
PB
25975/* Return the size of a relaxable adr pseudo-instruction or PC-relative
25976 load. */
25977static int
5e77afaa 25978relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
25979{
25980 addressT addr;
25981 offsetT val;
25982
25983 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
25984 if (fragp->fr_symbol == NULL
25985 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
25986 || sec != S_GET_SEGMENT (fragp->fr_symbol)
25987 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
25988 return 4;
25989
5f4273c7 25990 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
25991 addr = fragp->fr_address + fragp->fr_fix;
25992 addr = (addr + 4) & ~3;
5e77afaa 25993 /* Force misaligned targets to 32-bit variant. */
0110f2b8 25994 if (val & 3)
5e77afaa 25995 return 4;
0110f2b8
PB
25996 val -= addr;
25997 if (val < 0 || val > 1020)
25998 return 4;
25999 return 2;
26000}
26001
26002/* Return the size of a relaxable add/sub immediate instruction. */
26003static int
26004relax_addsub (fragS *fragp, asection *sec)
26005{
26006 char *buf;
26007 int op;
26008
26009 buf = fragp->fr_literal + fragp->fr_fix;
26010 op = bfd_get_16(sec->owner, buf);
26011 if ((op & 0xf) == ((op >> 4) & 0xf))
26012 return relax_immediate (fragp, 8, 0);
26013 else
26014 return relax_immediate (fragp, 3, 0);
26015}
26016
e83a675f
RE
26017/* Return TRUE iff the definition of symbol S could be pre-empted
26018 (overridden) at link or load time. */
26019static bfd_boolean
26020symbol_preemptible (symbolS *s)
26021{
26022 /* Weak symbols can always be pre-empted. */
26023 if (S_IS_WEAK (s))
26024 return TRUE;
26025
26026 /* Non-global symbols cannot be pre-empted. */
26027 if (! S_IS_EXTERNAL (s))
26028 return FALSE;
26029
26030#ifdef OBJ_ELF
26031 /* In ELF, a global symbol can be marked protected, or private. In that
26032 case it can't be pre-empted (other definitions in the same link unit
26033 would violate the ODR). */
26034 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
26035 return FALSE;
26036#endif
26037
26038 /* Other global symbols might be pre-empted. */
26039 return TRUE;
26040}
0110f2b8
PB
26041
26042/* Return the size of a relaxable branch instruction. BITS is the
26043 size of the offset field in the narrow instruction. */
26044
26045static int
5e77afaa 26046relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
26047{
26048 addressT addr;
26049 offsetT val;
26050 offsetT limit;
26051
26052 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 26053 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
26054 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26055 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
26056 return 4;
26057
267bf995 26058#ifdef OBJ_ELF
e83a675f 26059 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
26060 if (S_IS_DEFINED (fragp->fr_symbol)
26061 && ARM_IS_FUNC (fragp->fr_symbol))
26062 return 4;
e83a675f 26063#endif
0d9b4b55 26064
e83a675f 26065 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 26066 return 4;
267bf995 26067
5f4273c7 26068 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
26069 addr = fragp->fr_address + fragp->fr_fix + 4;
26070 val -= addr;
26071
26072 /* Offset is a signed value *2 */
26073 limit = 1 << bits;
26074 if (val >= limit || val < -limit)
26075 return 4;
26076 return 2;
26077}
26078
26079
26080/* Relax a machine dependent frag. This returns the amount by which
26081 the current size of the frag should change. */
26082
26083int
5e77afaa 26084arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
26085{
26086 int oldsize;
26087 int newsize;
26088
26089 oldsize = fragp->fr_var;
26090 switch (fragp->fr_subtype)
26091 {
26092 case T_MNEM_ldr_pc2:
5f4273c7 26093 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26094 break;
26095 case T_MNEM_ldr_pc:
26096 case T_MNEM_ldr_sp:
26097 case T_MNEM_str_sp:
5f4273c7 26098 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
26099 break;
26100 case T_MNEM_ldr:
26101 case T_MNEM_str:
5f4273c7 26102 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
26103 break;
26104 case T_MNEM_ldrh:
26105 case T_MNEM_strh:
5f4273c7 26106 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
26107 break;
26108 case T_MNEM_ldrb:
26109 case T_MNEM_strb:
5f4273c7 26110 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
26111 break;
26112 case T_MNEM_adr:
5f4273c7 26113 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
26114 break;
26115 case T_MNEM_mov:
26116 case T_MNEM_movs:
26117 case T_MNEM_cmp:
26118 case T_MNEM_cmn:
5f4273c7 26119 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
26120 break;
26121 case T_MNEM_b:
5f4273c7 26122 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
26123 break;
26124 case T_MNEM_bcond:
5f4273c7 26125 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
26126 break;
26127 case T_MNEM_add_sp:
26128 case T_MNEM_add_pc:
26129 newsize = relax_immediate (fragp, 8, 2);
26130 break;
26131 case T_MNEM_inc_sp:
26132 case T_MNEM_dec_sp:
26133 newsize = relax_immediate (fragp, 7, 2);
26134 break;
26135 case T_MNEM_addi:
26136 case T_MNEM_addis:
26137 case T_MNEM_subi:
26138 case T_MNEM_subis:
26139 newsize = relax_addsub (fragp, sec);
26140 break;
26141 default:
5f4273c7 26142 abort ();
0110f2b8 26143 }
5e77afaa
PB
26144
26145 fragp->fr_var = newsize;
26146 /* Freeze wide instructions that are at or before the same location as
26147 in the previous pass. This avoids infinite loops.
5f4273c7
NC
26148 Don't freeze them unconditionally because targets may be artificially
26149 misaligned by the expansion of preceding frags. */
5e77afaa 26150 if (stretch <= 0 && newsize > 2)
0110f2b8 26151 {
0110f2b8 26152 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 26153 frag_wane (fragp);
0110f2b8 26154 }
5e77afaa 26155
0110f2b8 26156 return newsize - oldsize;
c19d1205 26157}
b99bd4ef 26158
c19d1205 26159/* Round up a section size to the appropriate boundary. */
b99bd4ef 26160
c19d1205
ZW
26161valueT
26162md_section_align (segT segment ATTRIBUTE_UNUSED,
26163 valueT size)
26164{
6844c0cc 26165 return size;
bfae80f2 26166}
b99bd4ef 26167
c19d1205
ZW
26168/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
26169 of an rs_align_code fragment. */
26170
26171void
26172arm_handle_align (fragS * fragP)
bfae80f2 26173{
d9235011 26174 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
26175 {
26176 { /* ARMv1 */
26177 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
26178 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
26179 },
26180 { /* ARMv6k */
26181 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
26182 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
26183 },
26184 };
d9235011 26185 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
26186 {
26187 { /* Thumb-1 */
26188 {0xc0, 0x46}, /* LE */
26189 {0x46, 0xc0}, /* BE */
26190 },
26191 { /* Thumb-2 */
26192 {0x00, 0xbf}, /* LE */
26193 {0xbf, 0x00} /* BE */
26194 }
26195 };
d9235011 26196 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
26197 { /* Wide Thumb-2 */
26198 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
26199 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
26200 };
c921be7d 26201
e7495e45 26202 unsigned bytes, fix, noop_size;
c19d1205 26203 char * p;
d9235011
TS
26204 const unsigned char * noop;
26205 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
26206#ifdef OBJ_ELF
26207 enum mstate state;
26208#endif
bfae80f2 26209
c19d1205 26210 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
26211 return;
26212
c19d1205
ZW
26213 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
26214 p = fragP->fr_literal + fragP->fr_fix;
26215 fix = 0;
bfae80f2 26216
c19d1205
ZW
26217 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
26218 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 26219
cd000bff 26220 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 26221
cd000bff 26222 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 26223 {
7f78eb34
JW
26224 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26225 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
26226 {
26227 narrow_noop = thumb_noop[1][target_big_endian];
26228 noop = wide_thumb_noop[target_big_endian];
26229 }
c19d1205 26230 else
e7495e45
NS
26231 noop = thumb_noop[0][target_big_endian];
26232 noop_size = 2;
cd000bff
DJ
26233#ifdef OBJ_ELF
26234 state = MAP_THUMB;
26235#endif
7ed4c4c5
NC
26236 }
26237 else
26238 {
7f78eb34
JW
26239 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26240 ? selected_cpu : arm_arch_none,
26241 arm_ext_v6k) != 0]
e7495e45
NS
26242 [target_big_endian];
26243 noop_size = 4;
cd000bff
DJ
26244#ifdef OBJ_ELF
26245 state = MAP_ARM;
26246#endif
7ed4c4c5 26247 }
c921be7d 26248
e7495e45 26249 fragP->fr_var = noop_size;
c921be7d 26250
c19d1205 26251 if (bytes & (noop_size - 1))
7ed4c4c5 26252 {
c19d1205 26253 fix = bytes & (noop_size - 1);
cd000bff
DJ
26254#ifdef OBJ_ELF
26255 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
26256#endif
c19d1205
ZW
26257 memset (p, 0, fix);
26258 p += fix;
26259 bytes -= fix;
a737bd4d 26260 }
a737bd4d 26261
e7495e45
NS
26262 if (narrow_noop)
26263 {
26264 if (bytes & noop_size)
26265 {
26266 /* Insert a narrow noop. */
26267 memcpy (p, narrow_noop, noop_size);
26268 p += noop_size;
26269 bytes -= noop_size;
26270 fix += noop_size;
26271 }
26272
26273 /* Use wide noops for the remainder */
26274 noop_size = 4;
26275 }
26276
c19d1205 26277 while (bytes >= noop_size)
a737bd4d 26278 {
c19d1205
ZW
26279 memcpy (p, noop, noop_size);
26280 p += noop_size;
26281 bytes -= noop_size;
26282 fix += noop_size;
a737bd4d
NC
26283 }
26284
c19d1205 26285 fragP->fr_fix += fix;
a737bd4d
NC
26286}
26287
c19d1205
ZW
26288/* Called from md_do_align. Used to create an alignment
26289 frag in a code section. */
26290
26291void
26292arm_frag_align_code (int n, int max)
bfae80f2 26293{
c19d1205 26294 char * p;
7ed4c4c5 26295
c19d1205 26296 /* We assume that there will never be a requirement
6ec8e702 26297 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 26298 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
26299 {
26300 char err_msg[128];
26301
fa94de6b 26302 sprintf (err_msg,
477330fc
RM
26303 _("alignments greater than %d bytes not supported in .text sections."),
26304 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 26305 as_fatal ("%s", err_msg);
6ec8e702 26306 }
bfae80f2 26307
c19d1205
ZW
26308 p = frag_var (rs_align_code,
26309 MAX_MEM_FOR_RS_ALIGN_CODE,
26310 1,
26311 (relax_substateT) max,
26312 (symbolS *) NULL,
26313 (offsetT) n,
26314 (char *) NULL);
26315 *p = 0;
26316}
bfae80f2 26317
8dc2430f
NC
26318/* Perform target specific initialisation of a frag.
26319 Note - despite the name this initialisation is not done when the frag
26320 is created, but only when its type is assigned. A frag can be created
26321 and used a long time before its type is set, so beware of assuming that
33eaf5de 26322 this initialisation is performed first. */
bfae80f2 26323
cd000bff
DJ
26324#ifndef OBJ_ELF
26325void
26326arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
26327{
26328 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 26329 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
26330}
26331
26332#else /* OBJ_ELF is defined. */
c19d1205 26333void
cd000bff 26334arm_init_frag (fragS * fragP, int max_chars)
c19d1205 26335{
e8d84ca1 26336 bfd_boolean frag_thumb_mode;
b968d18a 26337
8dc2430f
NC
26338 /* If the current ARM vs THUMB mode has not already
26339 been recorded into this frag then do so now. */
cd000bff 26340 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
26341 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26342
e8d84ca1
NC
26343 /* PR 21809: Do not set a mapping state for debug sections
26344 - it just confuses other tools. */
26345 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
26346 return;
26347
b968d18a 26348 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 26349
f9c1b181
RL
26350 /* Record a mapping symbol for alignment frags. We will delete this
26351 later if the alignment ends up empty. */
26352 switch (fragP->fr_type)
26353 {
26354 case rs_align:
26355 case rs_align_test:
26356 case rs_fill:
26357 mapping_state_2 (MAP_DATA, max_chars);
26358 break;
26359 case rs_align_code:
b968d18a 26360 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
26361 break;
26362 default:
26363 break;
cd000bff 26364 }
bfae80f2
RE
26365}
26366
c19d1205
ZW
26367/* When we change sections we need to issue a new mapping symbol. */
26368
26369void
26370arm_elf_change_section (void)
bfae80f2 26371{
c19d1205
ZW
26372 /* Link an unlinked unwind index table section to the .text section. */
26373 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
26374 && elf_linked_to_section (now_seg) == NULL)
26375 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
26376}
26377
c19d1205
ZW
26378int
26379arm_elf_section_type (const char * str, size_t len)
e45d0630 26380{
c19d1205
ZW
26381 if (len == 5 && strncmp (str, "exidx", 5) == 0)
26382 return SHT_ARM_EXIDX;
e45d0630 26383
c19d1205
ZW
26384 return -1;
26385}
26386\f
26387/* Code to deal with unwinding tables. */
e45d0630 26388
c19d1205 26389static void add_unwind_adjustsp (offsetT);
e45d0630 26390
5f4273c7 26391/* Generate any deferred unwind frame offset. */
e45d0630 26392
bfae80f2 26393static void
c19d1205 26394flush_pending_unwind (void)
bfae80f2 26395{
c19d1205 26396 offsetT offset;
bfae80f2 26397
c19d1205
ZW
26398 offset = unwind.pending_offset;
26399 unwind.pending_offset = 0;
26400 if (offset != 0)
26401 add_unwind_adjustsp (offset);
bfae80f2
RE
26402}
26403
c19d1205
ZW
26404/* Add an opcode to this list for this function. Two-byte opcodes should
26405 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
26406 order. */
26407
bfae80f2 26408static void
c19d1205 26409add_unwind_opcode (valueT op, int length)
bfae80f2 26410{
c19d1205
ZW
26411 /* Add any deferred stack adjustment. */
26412 if (unwind.pending_offset)
26413 flush_pending_unwind ();
bfae80f2 26414
c19d1205 26415 unwind.sp_restored = 0;
bfae80f2 26416
c19d1205 26417 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 26418 {
c19d1205
ZW
26419 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
26420 if (unwind.opcodes)
325801bd
TS
26421 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
26422 unwind.opcode_alloc);
c19d1205 26423 else
325801bd 26424 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 26425 }
c19d1205 26426 while (length > 0)
bfae80f2 26427 {
c19d1205
ZW
26428 length--;
26429 unwind.opcodes[unwind.opcode_count] = op & 0xff;
26430 op >>= 8;
26431 unwind.opcode_count++;
bfae80f2 26432 }
bfae80f2
RE
26433}
26434
c19d1205
ZW
26435/* Add unwind opcodes to adjust the stack pointer. */
26436
bfae80f2 26437static void
c19d1205 26438add_unwind_adjustsp (offsetT offset)
bfae80f2 26439{
c19d1205 26440 valueT op;
bfae80f2 26441
c19d1205 26442 if (offset > 0x200)
bfae80f2 26443 {
c19d1205
ZW
26444 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
26445 char bytes[5];
26446 int n;
26447 valueT o;
bfae80f2 26448
c19d1205
ZW
26449 /* Long form: 0xb2, uleb128. */
26450 /* This might not fit in a word so add the individual bytes,
26451 remembering the list is built in reverse order. */
26452 o = (valueT) ((offset - 0x204) >> 2);
26453 if (o == 0)
26454 add_unwind_opcode (0, 1);
bfae80f2 26455
c19d1205
ZW
26456 /* Calculate the uleb128 encoding of the offset. */
26457 n = 0;
26458 while (o)
26459 {
26460 bytes[n] = o & 0x7f;
26461 o >>= 7;
26462 if (o)
26463 bytes[n] |= 0x80;
26464 n++;
26465 }
26466 /* Add the insn. */
26467 for (; n; n--)
26468 add_unwind_opcode (bytes[n - 1], 1);
26469 add_unwind_opcode (0xb2, 1);
26470 }
26471 else if (offset > 0x100)
bfae80f2 26472 {
c19d1205
ZW
26473 /* Two short opcodes. */
26474 add_unwind_opcode (0x3f, 1);
26475 op = (offset - 0x104) >> 2;
26476 add_unwind_opcode (op, 1);
bfae80f2 26477 }
c19d1205
ZW
26478 else if (offset > 0)
26479 {
26480 /* Short opcode. */
26481 op = (offset - 4) >> 2;
26482 add_unwind_opcode (op, 1);
26483 }
26484 else if (offset < 0)
bfae80f2 26485 {
c19d1205
ZW
26486 offset = -offset;
26487 while (offset > 0x100)
bfae80f2 26488 {
c19d1205
ZW
26489 add_unwind_opcode (0x7f, 1);
26490 offset -= 0x100;
bfae80f2 26491 }
c19d1205
ZW
26492 op = ((offset - 4) >> 2) | 0x40;
26493 add_unwind_opcode (op, 1);
bfae80f2 26494 }
bfae80f2
RE
26495}
26496
c19d1205 26497/* Finish the list of unwind opcodes for this function. */
0198d5e6 26498
c19d1205
ZW
26499static void
26500finish_unwind_opcodes (void)
bfae80f2 26501{
c19d1205 26502 valueT op;
bfae80f2 26503
c19d1205 26504 if (unwind.fp_used)
bfae80f2 26505 {
708587a4 26506 /* Adjust sp as necessary. */
c19d1205
ZW
26507 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
26508 flush_pending_unwind ();
bfae80f2 26509
c19d1205
ZW
26510 /* After restoring sp from the frame pointer. */
26511 op = 0x90 | unwind.fp_reg;
26512 add_unwind_opcode (op, 1);
26513 }
26514 else
26515 flush_pending_unwind ();
bfae80f2
RE
26516}
26517
bfae80f2 26518
c19d1205
ZW
26519/* Start an exception table entry. If idx is nonzero this is an index table
26520 entry. */
bfae80f2
RE
26521
26522static void
c19d1205 26523start_unwind_section (const segT text_seg, int idx)
bfae80f2 26524{
c19d1205
ZW
26525 const char * text_name;
26526 const char * prefix;
26527 const char * prefix_once;
26528 const char * group_name;
c19d1205 26529 char * sec_name;
c19d1205
ZW
26530 int type;
26531 int flags;
26532 int linkonce;
bfae80f2 26533
c19d1205 26534 if (idx)
bfae80f2 26535 {
c19d1205
ZW
26536 prefix = ELF_STRING_ARM_unwind;
26537 prefix_once = ELF_STRING_ARM_unwind_once;
26538 type = SHT_ARM_EXIDX;
bfae80f2 26539 }
c19d1205 26540 else
bfae80f2 26541 {
c19d1205
ZW
26542 prefix = ELF_STRING_ARM_unwind_info;
26543 prefix_once = ELF_STRING_ARM_unwind_info_once;
26544 type = SHT_PROGBITS;
bfae80f2
RE
26545 }
26546
c19d1205
ZW
26547 text_name = segment_name (text_seg);
26548 if (streq (text_name, ".text"))
26549 text_name = "";
26550
26551 if (strncmp (text_name, ".gnu.linkonce.t.",
26552 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 26553 {
c19d1205
ZW
26554 prefix = prefix_once;
26555 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
26556 }
26557
29a2809e 26558 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 26559
c19d1205
ZW
26560 flags = SHF_ALLOC;
26561 linkonce = 0;
26562 group_name = 0;
bfae80f2 26563
c19d1205
ZW
26564 /* Handle COMDAT group. */
26565 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 26566 {
c19d1205
ZW
26567 group_name = elf_group_name (text_seg);
26568 if (group_name == NULL)
26569 {
bd3ba5d1 26570 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
26571 segment_name (text_seg));
26572 ignore_rest_of_line ();
26573 return;
26574 }
26575 flags |= SHF_GROUP;
26576 linkonce = 1;
bfae80f2
RE
26577 }
26578
a91e1603
L
26579 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
26580 linkonce, 0);
bfae80f2 26581
5f4273c7 26582 /* Set the section link for index tables. */
c19d1205
ZW
26583 if (idx)
26584 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
26585}
26586
bfae80f2 26587
c19d1205
ZW
26588/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
26589 personality routine data. Returns zero, or the index table value for
cad0da33 26590 an inline entry. */
c19d1205
ZW
26591
26592static valueT
26593create_unwind_entry (int have_data)
bfae80f2 26594{
c19d1205
ZW
26595 int size;
26596 addressT where;
26597 char *ptr;
26598 /* The current word of data. */
26599 valueT data;
26600 /* The number of bytes left in this word. */
26601 int n;
bfae80f2 26602
c19d1205 26603 finish_unwind_opcodes ();
bfae80f2 26604
c19d1205
ZW
26605 /* Remember the current text section. */
26606 unwind.saved_seg = now_seg;
26607 unwind.saved_subseg = now_subseg;
bfae80f2 26608
c19d1205 26609 start_unwind_section (now_seg, 0);
bfae80f2 26610
c19d1205 26611 if (unwind.personality_routine == NULL)
bfae80f2 26612 {
c19d1205
ZW
26613 if (unwind.personality_index == -2)
26614 {
26615 if (have_data)
5f4273c7 26616 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
26617 return 1; /* EXIDX_CANTUNWIND. */
26618 }
bfae80f2 26619
c19d1205
ZW
26620 /* Use a default personality routine if none is specified. */
26621 if (unwind.personality_index == -1)
26622 {
26623 if (unwind.opcode_count > 3)
26624 unwind.personality_index = 1;
26625 else
26626 unwind.personality_index = 0;
26627 }
bfae80f2 26628
c19d1205
ZW
26629 /* Space for the personality routine entry. */
26630 if (unwind.personality_index == 0)
26631 {
26632 if (unwind.opcode_count > 3)
26633 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 26634
c19d1205
ZW
26635 if (!have_data)
26636 {
26637 /* All the data is inline in the index table. */
26638 data = 0x80;
26639 n = 3;
26640 while (unwind.opcode_count > 0)
26641 {
26642 unwind.opcode_count--;
26643 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26644 n--;
26645 }
bfae80f2 26646
c19d1205
ZW
26647 /* Pad with "finish" opcodes. */
26648 while (n--)
26649 data = (data << 8) | 0xb0;
bfae80f2 26650
c19d1205
ZW
26651 return data;
26652 }
26653 size = 0;
26654 }
26655 else
26656 /* We get two opcodes "free" in the first word. */
26657 size = unwind.opcode_count - 2;
26658 }
26659 else
5011093d 26660 {
cad0da33
NC
26661 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
26662 if (unwind.personality_index != -1)
26663 {
26664 as_bad (_("attempt to recreate an unwind entry"));
26665 return 1;
26666 }
5011093d
NC
26667
26668 /* An extra byte is required for the opcode count. */
26669 size = unwind.opcode_count + 1;
26670 }
bfae80f2 26671
c19d1205
ZW
26672 size = (size + 3) >> 2;
26673 if (size > 0xff)
26674 as_bad (_("too many unwind opcodes"));
bfae80f2 26675
c19d1205
ZW
26676 frag_align (2, 0, 0);
26677 record_alignment (now_seg, 2);
26678 unwind.table_entry = expr_build_dot ();
26679
26680 /* Allocate the table entry. */
26681 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
26682 /* PR 13449: Zero the table entries in case some of them are not used. */
26683 memset (ptr, 0, (size << 2) + 4);
c19d1205 26684 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 26685
c19d1205 26686 switch (unwind.personality_index)
bfae80f2 26687 {
c19d1205
ZW
26688 case -1:
26689 /* ??? Should this be a PLT generating relocation? */
26690 /* Custom personality routine. */
26691 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
26692 BFD_RELOC_ARM_PREL31);
bfae80f2 26693
c19d1205
ZW
26694 where += 4;
26695 ptr += 4;
bfae80f2 26696
c19d1205 26697 /* Set the first byte to the number of additional words. */
5011093d 26698 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
26699 n = 3;
26700 break;
bfae80f2 26701
c19d1205
ZW
26702 /* ABI defined personality routines. */
26703 case 0:
26704 /* Three opcodes bytes are packed into the first word. */
26705 data = 0x80;
26706 n = 3;
26707 break;
bfae80f2 26708
c19d1205
ZW
26709 case 1:
26710 case 2:
26711 /* The size and first two opcode bytes go in the first word. */
26712 data = ((0x80 + unwind.personality_index) << 8) | size;
26713 n = 2;
26714 break;
bfae80f2 26715
c19d1205
ZW
26716 default:
26717 /* Should never happen. */
26718 abort ();
26719 }
bfae80f2 26720
c19d1205
ZW
26721 /* Pack the opcodes into words (MSB first), reversing the list at the same
26722 time. */
26723 while (unwind.opcode_count > 0)
26724 {
26725 if (n == 0)
26726 {
26727 md_number_to_chars (ptr, data, 4);
26728 ptr += 4;
26729 n = 4;
26730 data = 0;
26731 }
26732 unwind.opcode_count--;
26733 n--;
26734 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26735 }
26736
26737 /* Finish off the last word. */
26738 if (n < 4)
26739 {
26740 /* Pad with "finish" opcodes. */
26741 while (n--)
26742 data = (data << 8) | 0xb0;
26743
26744 md_number_to_chars (ptr, data, 4);
26745 }
26746
26747 if (!have_data)
26748 {
26749 /* Add an empty descriptor if there is no user-specified data. */
26750 ptr = frag_more (4);
26751 md_number_to_chars (ptr, 0, 4);
26752 }
26753
26754 return 0;
bfae80f2
RE
26755}
26756
f0927246
NC
26757
26758/* Initialize the DWARF-2 unwind information for this procedure. */
26759
26760void
26761tc_arm_frame_initial_instructions (void)
26762{
26763 cfi_add_CFA_def_cfa (REG_SP, 0);
26764}
26765#endif /* OBJ_ELF */
26766
c19d1205
ZW
26767/* Convert REGNAME to a DWARF-2 register number. */
26768
26769int
1df69f4f 26770tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 26771{
1df69f4f 26772 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
26773 if (reg != FAIL)
26774 return reg;
c19d1205 26775
1f5afe1c
NC
26776 /* PR 16694: Allow VFP registers as well. */
26777 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
26778 if (reg != FAIL)
26779 return 64 + reg;
c19d1205 26780
1f5afe1c
NC
26781 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
26782 if (reg != FAIL)
26783 return reg + 256;
26784
0198d5e6 26785 return FAIL;
bfae80f2
RE
26786}
26787
f0927246 26788#ifdef TE_PE
c19d1205 26789void
f0927246 26790tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 26791{
91d6fa6a 26792 expressionS exp;
bfae80f2 26793
91d6fa6a
NC
26794 exp.X_op = O_secrel;
26795 exp.X_add_symbol = symbol;
26796 exp.X_add_number = 0;
26797 emit_expr (&exp, size);
f0927246
NC
26798}
26799#endif
bfae80f2 26800
c19d1205 26801/* MD interface: Symbol and relocation handling. */
bfae80f2 26802
2fc8bdac
ZW
26803/* Return the address within the segment that a PC-relative fixup is
26804 relative to. For ARM, PC-relative fixups applied to instructions
26805 are generally relative to the location of the fixup plus 8 bytes.
26806 Thumb branches are offset by 4, and Thumb loads relative to PC
26807 require special handling. */
bfae80f2 26808
c19d1205 26809long
2fc8bdac 26810md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 26811{
2fc8bdac
ZW
26812 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
26813
26814 /* If this is pc-relative and we are going to emit a relocation
26815 then we just want to put out any pipeline compensation that the linker
53baae48
NC
26816 will need. Otherwise we want to use the calculated base.
26817 For WinCE we skip the bias for externals as well, since this
26818 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 26819 if (fixP->fx_pcrel
2fc8bdac 26820 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
26821 || (arm_force_relocation (fixP)
26822#ifdef TE_WINCE
26823 && !S_IS_EXTERNAL (fixP->fx_addsy)
26824#endif
26825 )))
2fc8bdac 26826 base = 0;
bfae80f2 26827
267bf995 26828
c19d1205 26829 switch (fixP->fx_r_type)
bfae80f2 26830 {
2fc8bdac
ZW
26831 /* PC relative addressing on the Thumb is slightly odd as the
26832 bottom two bits of the PC are forced to zero for the
26833 calculation. This happens *after* application of the
26834 pipeline offset. However, Thumb adrl already adjusts for
26835 this, so we need not do it again. */
c19d1205 26836 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 26837 return base & ~3;
c19d1205
ZW
26838
26839 case BFD_RELOC_ARM_THUMB_OFFSET:
26840 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 26841 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 26842 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 26843 return (base + 4) & ~3;
c19d1205 26844
2fc8bdac 26845 /* Thumb branches are simply offset by +4. */
e12437dc 26846 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
26847 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26848 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26849 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26850 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 26851 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 26852 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 26853 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 26854 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 26855 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 26856 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 26857 return base + 4;
bfae80f2 26858
267bf995 26859 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
26860 if (fixP->fx_addsy
26861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26862 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 26863 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
26864 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26865 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
26866 return base + 4;
26867
00adf2d4
JB
26868 /* BLX is like branches above, but forces the low two bits of PC to
26869 zero. */
486499d0
CL
26870 case BFD_RELOC_THUMB_PCREL_BLX:
26871 if (fixP->fx_addsy
26872 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26873 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26874 && THUMB_IS_FUNC (fixP->fx_addsy)
26875 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26876 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
26877 return (base + 4) & ~3;
26878
2fc8bdac
ZW
26879 /* ARM mode branches are offset by +8. However, the Windows CE
26880 loader expects the relocation not to take this into account. */
267bf995 26881 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
26882 if (fixP->fx_addsy
26883 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26884 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26885 && ARM_IS_FUNC (fixP->fx_addsy)
26886 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26887 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 26888 return base + 8;
267bf995 26889
486499d0
CL
26890 case BFD_RELOC_ARM_PCREL_CALL:
26891 if (fixP->fx_addsy
26892 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 26893 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
26894 && THUMB_IS_FUNC (fixP->fx_addsy)
26895 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
26896 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 26897 return base + 8;
267bf995 26898
2fc8bdac 26899 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 26900 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 26901 case BFD_RELOC_ARM_PLT32:
c19d1205 26902#ifdef TE_WINCE
5f4273c7 26903 /* When handling fixups immediately, because we have already
477330fc 26904 discovered the value of a symbol, or the address of the frag involved
53baae48 26905 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
26906 see fixup_segment() in write.c
26907 The S_IS_EXTERNAL test handles the case of global symbols.
26908 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
26909 if (fixP->fx_pcrel
26910 && fixP->fx_addsy != NULL
26911 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
26912 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
26913 return base + 8;
2fc8bdac 26914 return base;
c19d1205 26915#else
2fc8bdac 26916 return base + 8;
c19d1205 26917#endif
2fc8bdac 26918
267bf995 26919
2fc8bdac
ZW
26920 /* ARM mode loads relative to PC are also offset by +8. Unlike
26921 branches, the Windows CE loader *does* expect the relocation
26922 to take this into account. */
26923 case BFD_RELOC_ARM_OFFSET_IMM:
26924 case BFD_RELOC_ARM_OFFSET_IMM8:
26925 case BFD_RELOC_ARM_HWLITERAL:
26926 case BFD_RELOC_ARM_LITERAL:
26927 case BFD_RELOC_ARM_CP_OFF_IMM:
26928 return base + 8;
26929
26930
26931 /* Other PC-relative relocations are un-offset. */
26932 default:
26933 return base;
26934 }
bfae80f2
RE
26935}
26936
8b2d793c
NC
26937static bfd_boolean flag_warn_syms = TRUE;
26938
ae8714c2
NC
26939bfd_boolean
26940arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 26941{
8b2d793c
NC
26942 /* PR 18347 - Warn if the user attempts to create a symbol with the same
26943 name as an ARM instruction. Whilst strictly speaking it is allowed, it
26944 does mean that the resulting code might be very confusing to the reader.
26945 Also this warning can be triggered if the user omits an operand before
26946 an immediate address, eg:
26947
26948 LDR =foo
26949
26950 GAS treats this as an assignment of the value of the symbol foo to a
26951 symbol LDR, and so (without this code) it will not issue any kind of
26952 warning or error message.
26953
26954 Note - ARM instructions are case-insensitive but the strings in the hash
26955 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
26956 lower case too. */
26957 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
26958 {
26959 char * nbuf = strdup (name);
26960 char * p;
26961
26962 for (p = nbuf; *p; p++)
26963 *p = TOLOWER (*p);
26964 if (hash_find (arm_ops_hsh, nbuf) != NULL)
26965 {
26966 static struct hash_control * already_warned = NULL;
26967
26968 if (already_warned == NULL)
26969 already_warned = hash_new ();
26970 /* Only warn about the symbol once. To keep the code
26971 simple we let hash_insert do the lookup for us. */
3076e594 26972 if (hash_insert (already_warned, nbuf, NULL) == NULL)
ae8714c2 26973 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
26974 }
26975 else
26976 free (nbuf);
26977 }
3739860c 26978
ae8714c2
NC
26979 return FALSE;
26980}
26981
26982/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
26983 Otherwise we have no need to default values of symbols. */
26984
26985symbolS *
26986md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
26987{
26988#ifdef OBJ_ELF
26989 if (name[0] == '_' && name[1] == 'G'
26990 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
26991 {
26992 if (!GOT_symbol)
26993 {
26994 if (symbol_find (name))
26995 as_bad (_("GOT already in the symbol table"));
26996
26997 GOT_symbol = symbol_new (name, undefined_section,
26998 (valueT) 0, & zero_address_frag);
26999 }
27000
27001 return GOT_symbol;
27002 }
27003#endif
27004
c921be7d 27005 return NULL;
bfae80f2
RE
27006}
27007
55cf6793 27008/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
27009 computed as two separate immediate values, added together. We
27010 already know that this value cannot be computed by just one ARM
27011 instruction. */
27012
27013static unsigned int
27014validate_immediate_twopart (unsigned int val,
27015 unsigned int * highpart)
bfae80f2 27016{
c19d1205
ZW
27017 unsigned int a;
27018 unsigned int i;
bfae80f2 27019
c19d1205
ZW
27020 for (i = 0; i < 32; i += 2)
27021 if (((a = rotate_left (val, i)) & 0xff) != 0)
27022 {
27023 if (a & 0xff00)
27024 {
27025 if (a & ~ 0xffff)
27026 continue;
27027 * highpart = (a >> 8) | ((i + 24) << 7);
27028 }
27029 else if (a & 0xff0000)
27030 {
27031 if (a & 0xff000000)
27032 continue;
27033 * highpart = (a >> 16) | ((i + 16) << 7);
27034 }
27035 else
27036 {
9c2799c2 27037 gas_assert (a & 0xff000000);
c19d1205
ZW
27038 * highpart = (a >> 24) | ((i + 8) << 7);
27039 }
bfae80f2 27040
c19d1205
ZW
27041 return (a & 0xff) | (i << 7);
27042 }
bfae80f2 27043
c19d1205 27044 return FAIL;
bfae80f2
RE
27045}
27046
c19d1205
ZW
27047static int
27048validate_offset_imm (unsigned int val, int hwse)
27049{
27050 if ((hwse && val > 255) || val > 4095)
27051 return FAIL;
27052 return val;
27053}
bfae80f2 27054
55cf6793 27055/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
27056 negative immediate constant by altering the instruction. A bit of
27057 a hack really.
27058 MOV <-> MVN
27059 AND <-> BIC
27060 ADC <-> SBC
27061 by inverting the second operand, and
27062 ADD <-> SUB
27063 CMP <-> CMN
27064 by negating the second operand. */
bfae80f2 27065
c19d1205
ZW
27066static int
27067negate_data_op (unsigned long * instruction,
27068 unsigned long value)
bfae80f2 27069{
c19d1205
ZW
27070 int op, new_inst;
27071 unsigned long negated, inverted;
bfae80f2 27072
c19d1205
ZW
27073 negated = encode_arm_immediate (-value);
27074 inverted = encode_arm_immediate (~value);
bfae80f2 27075
c19d1205
ZW
27076 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
27077 switch (op)
bfae80f2 27078 {
c19d1205
ZW
27079 /* First negates. */
27080 case OPCODE_SUB: /* ADD <-> SUB */
27081 new_inst = OPCODE_ADD;
27082 value = negated;
27083 break;
bfae80f2 27084
c19d1205
ZW
27085 case OPCODE_ADD:
27086 new_inst = OPCODE_SUB;
27087 value = negated;
27088 break;
bfae80f2 27089
c19d1205
ZW
27090 case OPCODE_CMP: /* CMP <-> CMN */
27091 new_inst = OPCODE_CMN;
27092 value = negated;
27093 break;
bfae80f2 27094
c19d1205
ZW
27095 case OPCODE_CMN:
27096 new_inst = OPCODE_CMP;
27097 value = negated;
27098 break;
bfae80f2 27099
c19d1205
ZW
27100 /* Now Inverted ops. */
27101 case OPCODE_MOV: /* MOV <-> MVN */
27102 new_inst = OPCODE_MVN;
27103 value = inverted;
27104 break;
bfae80f2 27105
c19d1205
ZW
27106 case OPCODE_MVN:
27107 new_inst = OPCODE_MOV;
27108 value = inverted;
27109 break;
bfae80f2 27110
c19d1205
ZW
27111 case OPCODE_AND: /* AND <-> BIC */
27112 new_inst = OPCODE_BIC;
27113 value = inverted;
27114 break;
bfae80f2 27115
c19d1205
ZW
27116 case OPCODE_BIC:
27117 new_inst = OPCODE_AND;
27118 value = inverted;
27119 break;
bfae80f2 27120
c19d1205
ZW
27121 case OPCODE_ADC: /* ADC <-> SBC */
27122 new_inst = OPCODE_SBC;
27123 value = inverted;
27124 break;
bfae80f2 27125
c19d1205
ZW
27126 case OPCODE_SBC:
27127 new_inst = OPCODE_ADC;
27128 value = inverted;
27129 break;
bfae80f2 27130
c19d1205
ZW
27131 /* We cannot do anything. */
27132 default:
27133 return FAIL;
b99bd4ef
NC
27134 }
27135
c19d1205
ZW
27136 if (value == (unsigned) FAIL)
27137 return FAIL;
27138
27139 *instruction &= OPCODE_MASK;
27140 *instruction |= new_inst << DATA_OP_SHIFT;
27141 return value;
b99bd4ef
NC
27142}
27143
ef8d22e6
PB
27144/* Like negate_data_op, but for Thumb-2. */
27145
27146static unsigned int
16dd5e42 27147thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
27148{
27149 int op, new_inst;
27150 int rd;
16dd5e42 27151 unsigned int negated, inverted;
ef8d22e6
PB
27152
27153 negated = encode_thumb32_immediate (-value);
27154 inverted = encode_thumb32_immediate (~value);
27155
27156 rd = (*instruction >> 8) & 0xf;
27157 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
27158 switch (op)
27159 {
27160 /* ADD <-> SUB. Includes CMP <-> CMN. */
27161 case T2_OPCODE_SUB:
27162 new_inst = T2_OPCODE_ADD;
27163 value = negated;
27164 break;
27165
27166 case T2_OPCODE_ADD:
27167 new_inst = T2_OPCODE_SUB;
27168 value = negated;
27169 break;
27170
27171 /* ORR <-> ORN. Includes MOV <-> MVN. */
27172 case T2_OPCODE_ORR:
27173 new_inst = T2_OPCODE_ORN;
27174 value = inverted;
27175 break;
27176
27177 case T2_OPCODE_ORN:
27178 new_inst = T2_OPCODE_ORR;
27179 value = inverted;
27180 break;
27181
27182 /* AND <-> BIC. TST has no inverted equivalent. */
27183 case T2_OPCODE_AND:
27184 new_inst = T2_OPCODE_BIC;
27185 if (rd == 15)
27186 value = FAIL;
27187 else
27188 value = inverted;
27189 break;
27190
27191 case T2_OPCODE_BIC:
27192 new_inst = T2_OPCODE_AND;
27193 value = inverted;
27194 break;
27195
27196 /* ADC <-> SBC */
27197 case T2_OPCODE_ADC:
27198 new_inst = T2_OPCODE_SBC;
27199 value = inverted;
27200 break;
27201
27202 case T2_OPCODE_SBC:
27203 new_inst = T2_OPCODE_ADC;
27204 value = inverted;
27205 break;
27206
27207 /* We cannot do anything. */
27208 default:
27209 return FAIL;
27210 }
27211
16dd5e42 27212 if (value == (unsigned int)FAIL)
ef8d22e6
PB
27213 return FAIL;
27214
27215 *instruction &= T2_OPCODE_MASK;
27216 *instruction |= new_inst << T2_DATA_OP_SHIFT;
27217 return value;
27218}
27219
8f06b2d8 27220/* Read a 32-bit thumb instruction from buf. */
0198d5e6 27221
8f06b2d8
PB
27222static unsigned long
27223get_thumb32_insn (char * buf)
27224{
27225 unsigned long insn;
27226 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
27227 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27228
27229 return insn;
27230}
27231
a8bc6c78
PB
27232/* We usually want to set the low bit on the address of thumb function
27233 symbols. In particular .word foo - . should have the low bit set.
27234 Generic code tries to fold the difference of two symbols to
27235 a constant. Prevent this and force a relocation when the first symbols
27236 is a thumb function. */
c921be7d
NC
27237
27238bfd_boolean
a8bc6c78
PB
27239arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
27240{
27241 if (op == O_subtract
27242 && l->X_op == O_symbol
27243 && r->X_op == O_symbol
27244 && THUMB_IS_FUNC (l->X_add_symbol))
27245 {
27246 l->X_op = O_subtract;
27247 l->X_op_symbol = r->X_add_symbol;
27248 l->X_add_number -= r->X_add_number;
c921be7d 27249 return TRUE;
a8bc6c78 27250 }
c921be7d 27251
a8bc6c78 27252 /* Process as normal. */
c921be7d 27253 return FALSE;
a8bc6c78
PB
27254}
27255
4a42ebbc
RR
27256/* Encode Thumb2 unconditional branches and calls. The encoding
27257 for the 2 are identical for the immediate values. */
27258
27259static void
27260encode_thumb2_b_bl_offset (char * buf, offsetT value)
27261{
27262#define T2I1I2MASK ((1 << 13) | (1 << 11))
27263 offsetT newval;
27264 offsetT newval2;
27265 addressT S, I1, I2, lo, hi;
27266
27267 S = (value >> 24) & 0x01;
27268 I1 = (value >> 23) & 0x01;
27269 I2 = (value >> 22) & 0x01;
27270 hi = (value >> 12) & 0x3ff;
fa94de6b 27271 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
27272 newval = md_chars_to_number (buf, THUMB_SIZE);
27273 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27274 newval |= (S << 10) | hi;
27275 newval2 &= ~T2I1I2MASK;
27276 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
27277 md_number_to_chars (buf, newval, THUMB_SIZE);
27278 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
27279}
27280
c19d1205 27281void
55cf6793 27282md_apply_fix (fixS * fixP,
c19d1205
ZW
27283 valueT * valP,
27284 segT seg)
27285{
27286 offsetT value = * valP;
27287 offsetT newval;
27288 unsigned int newimm;
27289 unsigned long temp;
27290 int sign;
27291 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 27292
9c2799c2 27293 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 27294
c19d1205 27295 /* Note whether this will delete the relocation. */
4962c51a 27296
c19d1205
ZW
27297 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
27298 fixP->fx_done = 1;
b99bd4ef 27299
adbaf948 27300 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 27301 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
27302 for emit_reloc. */
27303 value &= 0xffffffff;
27304 value ^= 0x80000000;
5f4273c7 27305 value -= 0x80000000;
adbaf948
ZW
27306
27307 *valP = value;
c19d1205 27308 fixP->fx_addnumber = value;
b99bd4ef 27309
adbaf948
ZW
27310 /* Same treatment for fixP->fx_offset. */
27311 fixP->fx_offset &= 0xffffffff;
27312 fixP->fx_offset ^= 0x80000000;
27313 fixP->fx_offset -= 0x80000000;
27314
c19d1205 27315 switch (fixP->fx_r_type)
b99bd4ef 27316 {
c19d1205
ZW
27317 case BFD_RELOC_NONE:
27318 /* This will need to go in the object file. */
27319 fixP->fx_done = 0;
27320 break;
b99bd4ef 27321
c19d1205
ZW
27322 case BFD_RELOC_ARM_IMMEDIATE:
27323 /* We claim that this fixup has been processed here,
27324 even if in fact we generate an error because we do
27325 not have a reloc for it, so tc_gen_reloc will reject it. */
27326 fixP->fx_done = 1;
b99bd4ef 27327
77db8e2e 27328 if (fixP->fx_addsy)
b99bd4ef 27329 {
77db8e2e 27330 const char *msg = 0;
b99bd4ef 27331
77db8e2e
NC
27332 if (! S_IS_DEFINED (fixP->fx_addsy))
27333 msg = _("undefined symbol %s used as an immediate value");
27334 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27335 msg = _("symbol %s is in a different section");
27336 else if (S_IS_WEAK (fixP->fx_addsy))
27337 msg = _("symbol %s is weak and may be overridden later");
27338
27339 if (msg)
27340 {
27341 as_bad_where (fixP->fx_file, fixP->fx_line,
27342 msg, S_GET_NAME (fixP->fx_addsy));
27343 break;
27344 }
42e5fcbf
AS
27345 }
27346
c19d1205
ZW
27347 temp = md_chars_to_number (buf, INSN_SIZE);
27348
5e73442d
SL
27349 /* If the offset is negative, we should use encoding A2 for ADR. */
27350 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
27351 newimm = negate_data_op (&temp, value);
27352 else
27353 {
27354 newimm = encode_arm_immediate (value);
27355
27356 /* If the instruction will fail, see if we can fix things up by
27357 changing the opcode. */
27358 if (newimm == (unsigned int) FAIL)
27359 newimm = negate_data_op (&temp, value);
bada4342
JW
27360 /* MOV accepts both ARM modified immediate (A1 encoding) and
27361 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
27362 When disassembling, MOV is preferred when there is no encoding
27363 overlap. */
27364 if (newimm == (unsigned int) FAIL
27365 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
27366 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
27367 && !((temp >> SBIT_SHIFT) & 0x1)
27368 && value >= 0 && value <= 0xffff)
27369 {
27370 /* Clear bits[23:20] to change encoding from A1 to A2. */
27371 temp &= 0xff0fffff;
27372 /* Encoding high 4bits imm. Code below will encode the remaining
27373 low 12bits. */
27374 temp |= (value & 0x0000f000) << 4;
27375 newimm = value & 0x00000fff;
27376 }
5e73442d
SL
27377 }
27378
27379 if (newimm == (unsigned int) FAIL)
b99bd4ef 27380 {
c19d1205
ZW
27381 as_bad_where (fixP->fx_file, fixP->fx_line,
27382 _("invalid constant (%lx) after fixup"),
27383 (unsigned long) value);
27384 break;
b99bd4ef 27385 }
b99bd4ef 27386
c19d1205
ZW
27387 newimm |= (temp & 0xfffff000);
27388 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27389 break;
b99bd4ef 27390
c19d1205
ZW
27391 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
27392 {
27393 unsigned int highpart = 0;
27394 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 27395
77db8e2e 27396 if (fixP->fx_addsy)
42e5fcbf 27397 {
77db8e2e 27398 const char *msg = 0;
42e5fcbf 27399
77db8e2e
NC
27400 if (! S_IS_DEFINED (fixP->fx_addsy))
27401 msg = _("undefined symbol %s used as an immediate value");
27402 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27403 msg = _("symbol %s is in a different section");
27404 else if (S_IS_WEAK (fixP->fx_addsy))
27405 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 27406
77db8e2e
NC
27407 if (msg)
27408 {
27409 as_bad_where (fixP->fx_file, fixP->fx_line,
27410 msg, S_GET_NAME (fixP->fx_addsy));
27411 break;
27412 }
27413 }
fa94de6b 27414
c19d1205
ZW
27415 newimm = encode_arm_immediate (value);
27416 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 27417
c19d1205
ZW
27418 /* If the instruction will fail, see if we can fix things up by
27419 changing the opcode. */
27420 if (newimm == (unsigned int) FAIL
27421 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
27422 {
27423 /* No ? OK - try using two ADD instructions to generate
27424 the value. */
27425 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 27426
c19d1205
ZW
27427 /* Yes - then make sure that the second instruction is
27428 also an add. */
27429 if (newimm != (unsigned int) FAIL)
27430 newinsn = temp;
27431 /* Still No ? Try using a negated value. */
27432 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
27433 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
27434 /* Otherwise - give up. */
27435 else
27436 {
27437 as_bad_where (fixP->fx_file, fixP->fx_line,
27438 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
27439 (long) value);
27440 break;
27441 }
b99bd4ef 27442
c19d1205
ZW
27443 /* Replace the first operand in the 2nd instruction (which
27444 is the PC) with the destination register. We have
27445 already added in the PC in the first instruction and we
27446 do not want to do it again. */
27447 newinsn &= ~ 0xf0000;
27448 newinsn |= ((newinsn & 0x0f000) << 4);
27449 }
b99bd4ef 27450
c19d1205
ZW
27451 newimm |= (temp & 0xfffff000);
27452 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 27453
c19d1205
ZW
27454 highpart |= (newinsn & 0xfffff000);
27455 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
27456 }
27457 break;
b99bd4ef 27458
c19d1205 27459 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
27460 if (!fixP->fx_done && seg->use_rela_p)
27461 value = 0;
1a0670f3 27462 /* Fall through. */
00a97672 27463
c19d1205 27464 case BFD_RELOC_ARM_LITERAL:
26d97720 27465 sign = value > 0;
b99bd4ef 27466
c19d1205
ZW
27467 if (value < 0)
27468 value = - value;
b99bd4ef 27469
c19d1205 27470 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 27471 {
c19d1205
ZW
27472 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
27473 as_bad_where (fixP->fx_file, fixP->fx_line,
27474 _("invalid literal constant: pool needs to be closer"));
27475 else
27476 as_bad_where (fixP->fx_file, fixP->fx_line,
27477 _("bad immediate value for offset (%ld)"),
27478 (long) value);
27479 break;
f03698e6
RE
27480 }
27481
c19d1205 27482 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
27483 if (value == 0)
27484 newval &= 0xfffff000;
27485 else
27486 {
27487 newval &= 0xff7ff000;
27488 newval |= value | (sign ? INDEX_UP : 0);
27489 }
c19d1205
ZW
27490 md_number_to_chars (buf, newval, INSN_SIZE);
27491 break;
b99bd4ef 27492
c19d1205
ZW
27493 case BFD_RELOC_ARM_OFFSET_IMM8:
27494 case BFD_RELOC_ARM_HWLITERAL:
26d97720 27495 sign = value > 0;
b99bd4ef 27496
c19d1205
ZW
27497 if (value < 0)
27498 value = - value;
b99bd4ef 27499
c19d1205 27500 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 27501 {
c19d1205
ZW
27502 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
27503 as_bad_where (fixP->fx_file, fixP->fx_line,
27504 _("invalid literal constant: pool needs to be closer"));
27505 else
427d0db6
RM
27506 as_bad_where (fixP->fx_file, fixP->fx_line,
27507 _("bad immediate value for 8-bit offset (%ld)"),
27508 (long) value);
c19d1205 27509 break;
b99bd4ef
NC
27510 }
27511
c19d1205 27512 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
27513 if (value == 0)
27514 newval &= 0xfffff0f0;
27515 else
27516 {
27517 newval &= 0xff7ff0f0;
27518 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
27519 }
c19d1205
ZW
27520 md_number_to_chars (buf, newval, INSN_SIZE);
27521 break;
b99bd4ef 27522
c19d1205
ZW
27523 case BFD_RELOC_ARM_T32_OFFSET_U8:
27524 if (value < 0 || value > 1020 || value % 4 != 0)
27525 as_bad_where (fixP->fx_file, fixP->fx_line,
27526 _("bad immediate value for offset (%ld)"), (long) value);
27527 value /= 4;
b99bd4ef 27528
c19d1205 27529 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
27530 newval |= value;
27531 md_number_to_chars (buf+2, newval, THUMB_SIZE);
27532 break;
b99bd4ef 27533
c19d1205
ZW
27534 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27535 /* This is a complicated relocation used for all varieties of Thumb32
27536 load/store instruction with immediate offset:
27537
27538 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 27539 *4, optional writeback(W)
c19d1205
ZW
27540 (doubleword load/store)
27541
27542 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
27543 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
27544 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
27545 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
27546 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
27547
27548 Uppercase letters indicate bits that are already encoded at
27549 this point. Lowercase letters are our problem. For the
27550 second block of instructions, the secondary opcode nybble
27551 (bits 8..11) is present, and bit 23 is zero, even if this is
27552 a PC-relative operation. */
27553 newval = md_chars_to_number (buf, THUMB_SIZE);
27554 newval <<= 16;
27555 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 27556
c19d1205 27557 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 27558 {
c19d1205
ZW
27559 /* Doubleword load/store: 8-bit offset, scaled by 4. */
27560 if (value >= 0)
27561 newval |= (1 << 23);
27562 else
27563 value = -value;
27564 if (value % 4 != 0)
27565 {
27566 as_bad_where (fixP->fx_file, fixP->fx_line,
27567 _("offset not a multiple of 4"));
27568 break;
27569 }
27570 value /= 4;
216d22bc 27571 if (value > 0xff)
c19d1205
ZW
27572 {
27573 as_bad_where (fixP->fx_file, fixP->fx_line,
27574 _("offset out of range"));
27575 break;
27576 }
27577 newval &= ~0xff;
b99bd4ef 27578 }
c19d1205 27579 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 27580 {
c19d1205
ZW
27581 /* PC-relative, 12-bit offset. */
27582 if (value >= 0)
27583 newval |= (1 << 23);
27584 else
27585 value = -value;
216d22bc 27586 if (value > 0xfff)
c19d1205
ZW
27587 {
27588 as_bad_where (fixP->fx_file, fixP->fx_line,
27589 _("offset out of range"));
27590 break;
27591 }
27592 newval &= ~0xfff;
b99bd4ef 27593 }
c19d1205 27594 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 27595 {
c19d1205
ZW
27596 /* Writeback: 8-bit, +/- offset. */
27597 if (value >= 0)
27598 newval |= (1 << 9);
27599 else
27600 value = -value;
216d22bc 27601 if (value > 0xff)
c19d1205
ZW
27602 {
27603 as_bad_where (fixP->fx_file, fixP->fx_line,
27604 _("offset out of range"));
27605 break;
27606 }
27607 newval &= ~0xff;
b99bd4ef 27608 }
c19d1205 27609 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 27610 {
c19d1205 27611 /* T-instruction: positive 8-bit offset. */
216d22bc 27612 if (value < 0 || value > 0xff)
b99bd4ef 27613 {
c19d1205
ZW
27614 as_bad_where (fixP->fx_file, fixP->fx_line,
27615 _("offset out of range"));
27616 break;
b99bd4ef 27617 }
c19d1205
ZW
27618 newval &= ~0xff;
27619 newval |= value;
b99bd4ef
NC
27620 }
27621 else
b99bd4ef 27622 {
c19d1205
ZW
27623 /* Positive 12-bit or negative 8-bit offset. */
27624 int limit;
27625 if (value >= 0)
b99bd4ef 27626 {
c19d1205
ZW
27627 newval |= (1 << 23);
27628 limit = 0xfff;
27629 }
27630 else
27631 {
27632 value = -value;
27633 limit = 0xff;
27634 }
27635 if (value > limit)
27636 {
27637 as_bad_where (fixP->fx_file, fixP->fx_line,
27638 _("offset out of range"));
27639 break;
b99bd4ef 27640 }
c19d1205 27641 newval &= ~limit;
b99bd4ef 27642 }
b99bd4ef 27643
c19d1205
ZW
27644 newval |= value;
27645 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
27646 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
27647 break;
404ff6b5 27648
c19d1205
ZW
27649 case BFD_RELOC_ARM_SHIFT_IMM:
27650 newval = md_chars_to_number (buf, INSN_SIZE);
27651 if (((unsigned long) value) > 32
27652 || (value == 32
27653 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
27654 {
27655 as_bad_where (fixP->fx_file, fixP->fx_line,
27656 _("shift expression is too large"));
27657 break;
27658 }
404ff6b5 27659
c19d1205
ZW
27660 if (value == 0)
27661 /* Shifts of zero must be done as lsl. */
27662 newval &= ~0x60;
27663 else if (value == 32)
27664 value = 0;
27665 newval &= 0xfffff07f;
27666 newval |= (value & 0x1f) << 7;
27667 md_number_to_chars (buf, newval, INSN_SIZE);
27668 break;
404ff6b5 27669
c19d1205 27670 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 27671 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 27672 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 27673 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
27674 /* We claim that this fixup has been processed here,
27675 even if in fact we generate an error because we do
27676 not have a reloc for it, so tc_gen_reloc will reject it. */
27677 fixP->fx_done = 1;
404ff6b5 27678
c19d1205
ZW
27679 if (fixP->fx_addsy
27680 && ! S_IS_DEFINED (fixP->fx_addsy))
27681 {
27682 as_bad_where (fixP->fx_file, fixP->fx_line,
27683 _("undefined symbol %s used as an immediate value"),
27684 S_GET_NAME (fixP->fx_addsy));
27685 break;
27686 }
404ff6b5 27687
c19d1205
ZW
27688 newval = md_chars_to_number (buf, THUMB_SIZE);
27689 newval <<= 16;
27690 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 27691
16805f35 27692 newimm = FAIL;
bada4342
JW
27693 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
27694 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
27695 Thumb2 modified immediate encoding (T2). */
27696 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 27697 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
27698 {
27699 newimm = encode_thumb32_immediate (value);
27700 if (newimm == (unsigned int) FAIL)
27701 newimm = thumb32_negate_data_op (&newval, value);
27702 }
bada4342 27703 if (newimm == (unsigned int) FAIL)
92e90b6e 27704 {
bada4342 27705 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 27706 {
bada4342
JW
27707 /* Turn add/sum into addw/subw. */
27708 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
27709 newval = (newval & 0xfeffffff) | 0x02000000;
27710 /* No flat 12-bit imm encoding for addsw/subsw. */
27711 if ((newval & 0x00100000) == 0)
40f246e3 27712 {
bada4342
JW
27713 /* 12 bit immediate for addw/subw. */
27714 if (value < 0)
27715 {
27716 value = -value;
27717 newval ^= 0x00a00000;
27718 }
27719 if (value > 0xfff)
27720 newimm = (unsigned int) FAIL;
27721 else
27722 newimm = value;
27723 }
27724 }
27725 else
27726 {
27727 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
27728 UINT16 (T3 encoding), MOVW only accepts UINT16. When
27729 disassembling, MOV is preferred when there is no encoding
db7bf105 27730 overlap. */
bada4342 27731 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
27732 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
27733 but with the Rn field [19:16] set to 1111. */
27734 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
27735 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
27736 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 27737 && value >= 0 && value <= 0xffff)
bada4342
JW
27738 {
27739 /* Toggle bit[25] to change encoding from T2 to T3. */
27740 newval ^= 1 << 25;
27741 /* Clear bits[19:16]. */
27742 newval &= 0xfff0ffff;
27743 /* Encoding high 4bits imm. Code below will encode the
27744 remaining low 12bits. */
27745 newval |= (value & 0x0000f000) << 4;
27746 newimm = value & 0x00000fff;
40f246e3 27747 }
e9f89963 27748 }
92e90b6e 27749 }
cc8a6dd0 27750
c19d1205 27751 if (newimm == (unsigned int)FAIL)
3631a3c8 27752 {
c19d1205
ZW
27753 as_bad_where (fixP->fx_file, fixP->fx_line,
27754 _("invalid constant (%lx) after fixup"),
27755 (unsigned long) value);
27756 break;
3631a3c8
NC
27757 }
27758
c19d1205
ZW
27759 newval |= (newimm & 0x800) << 15;
27760 newval |= (newimm & 0x700) << 4;
27761 newval |= (newimm & 0x0ff);
cc8a6dd0 27762
c19d1205
ZW
27763 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
27764 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
27765 break;
a737bd4d 27766
3eb17e6b 27767 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
27768 if (((unsigned long) value) > 0xffff)
27769 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 27770 _("invalid smc expression"));
2fc8bdac 27771 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
27772 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
27773 md_number_to_chars (buf, newval, INSN_SIZE);
27774 break;
a737bd4d 27775
90ec0d68
MGD
27776 case BFD_RELOC_ARM_HVC:
27777 if (((unsigned long) value) > 0xffff)
27778 as_bad_where (fixP->fx_file, fixP->fx_line,
27779 _("invalid hvc expression"));
27780 newval = md_chars_to_number (buf, INSN_SIZE);
27781 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
27782 md_number_to_chars (buf, newval, INSN_SIZE);
27783 break;
27784
c19d1205 27785 case BFD_RELOC_ARM_SWI:
adbaf948 27786 if (fixP->tc_fix_data != 0)
c19d1205
ZW
27787 {
27788 if (((unsigned long) value) > 0xff)
27789 as_bad_where (fixP->fx_file, fixP->fx_line,
27790 _("invalid swi expression"));
2fc8bdac 27791 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
27792 newval |= value;
27793 md_number_to_chars (buf, newval, THUMB_SIZE);
27794 }
27795 else
27796 {
27797 if (((unsigned long) value) > 0x00ffffff)
27798 as_bad_where (fixP->fx_file, fixP->fx_line,
27799 _("invalid swi expression"));
2fc8bdac 27800 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
27801 newval |= value;
27802 md_number_to_chars (buf, newval, INSN_SIZE);
27803 }
27804 break;
a737bd4d 27805
c19d1205
ZW
27806 case BFD_RELOC_ARM_MULTI:
27807 if (((unsigned long) value) > 0xffff)
27808 as_bad_where (fixP->fx_file, fixP->fx_line,
27809 _("invalid expression in load/store multiple"));
27810 newval = value | md_chars_to_number (buf, INSN_SIZE);
27811 md_number_to_chars (buf, newval, INSN_SIZE);
27812 break;
a737bd4d 27813
c19d1205 27814#ifdef OBJ_ELF
39b41c9c 27815 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
27816
27817 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27818 && fixP->fx_addsy
34e77a92 27819 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27820 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27821 && THUMB_IS_FUNC (fixP->fx_addsy))
27822 /* Flip the bl to blx. This is a simple flip
27823 bit here because we generate PCREL_CALL for
27824 unconditional bls. */
27825 {
27826 newval = md_chars_to_number (buf, INSN_SIZE);
27827 newval = newval | 0x10000000;
27828 md_number_to_chars (buf, newval, INSN_SIZE);
27829 temp = 1;
27830 fixP->fx_done = 1;
27831 }
39b41c9c
PB
27832 else
27833 temp = 3;
27834 goto arm_branch_common;
27835
27836 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
27837 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27838 && fixP->fx_addsy
34e77a92 27839 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27841 && THUMB_IS_FUNC (fixP->fx_addsy))
27842 {
27843 /* This would map to a bl<cond>, b<cond>,
27844 b<always> to a Thumb function. We
27845 need to force a relocation for this particular
27846 case. */
27847 newval = md_chars_to_number (buf, INSN_SIZE);
27848 fixP->fx_done = 0;
27849 }
1a0670f3 27850 /* Fall through. */
267bf995 27851
2fc8bdac 27852 case BFD_RELOC_ARM_PLT32:
c19d1205 27853#endif
39b41c9c
PB
27854 case BFD_RELOC_ARM_PCREL_BRANCH:
27855 temp = 3;
27856 goto arm_branch_common;
a737bd4d 27857
39b41c9c 27858 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 27859
39b41c9c 27860 temp = 1;
267bf995
RR
27861 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27862 && fixP->fx_addsy
34e77a92 27863 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27864 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27865 && ARM_IS_FUNC (fixP->fx_addsy))
27866 {
27867 /* Flip the blx to a bl and warn. */
27868 const char *name = S_GET_NAME (fixP->fx_addsy);
27869 newval = 0xeb000000;
27870 as_warn_where (fixP->fx_file, fixP->fx_line,
27871 _("blx to '%s' an ARM ISA state function changed to bl"),
27872 name);
27873 md_number_to_chars (buf, newval, INSN_SIZE);
27874 temp = 3;
27875 fixP->fx_done = 1;
27876 }
27877
27878#ifdef OBJ_ELF
27879 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 27880 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
27881#endif
27882
39b41c9c 27883 arm_branch_common:
c19d1205 27884 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
27885 instruction, in a 24 bit, signed field. Bits 26 through 32 either
27886 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 27887 also be clear. */
39b41c9c 27888 if (value & temp)
c19d1205 27889 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
27890 _("misaligned branch destination"));
27891 if ((value & (offsetT)0xfe000000) != (offsetT)0
27892 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 27893 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 27894
2fc8bdac 27895 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 27896 {
2fc8bdac
ZW
27897 newval = md_chars_to_number (buf, INSN_SIZE);
27898 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
27899 /* Set the H bit on BLX instructions. */
27900 if (temp == 1)
27901 {
27902 if (value & 2)
27903 newval |= 0x01000000;
27904 else
27905 newval &= ~0x01000000;
27906 }
2fc8bdac 27907 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 27908 }
c19d1205 27909 break;
a737bd4d 27910
25fe350b
MS
27911 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
27912 /* CBZ can only branch forward. */
a737bd4d 27913
738755b0 27914 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
27915 (which, strictly speaking, are prohibited) will be turned into
27916 no-ops.
738755b0
MS
27917
27918 FIXME: It may be better to remove the instruction completely and
27919 perform relaxation. */
27920 if (value == -2)
2fc8bdac
ZW
27921 {
27922 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 27923 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
27924 md_number_to_chars (buf, newval, THUMB_SIZE);
27925 }
738755b0
MS
27926 else
27927 {
27928 if (value & ~0x7e)
08f10d51 27929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 27930
477330fc 27931 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
27932 {
27933 newval = md_chars_to_number (buf, THUMB_SIZE);
27934 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
27935 md_number_to_chars (buf, newval, THUMB_SIZE);
27936 }
27937 }
c19d1205 27938 break;
a737bd4d 27939
c19d1205 27940 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 27941 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 27942 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 27943
2fc8bdac
ZW
27944 if (fixP->fx_done || !seg->use_rela_p)
27945 {
27946 newval = md_chars_to_number (buf, THUMB_SIZE);
27947 newval |= (value & 0x1ff) >> 1;
27948 md_number_to_chars (buf, newval, THUMB_SIZE);
27949 }
c19d1205 27950 break;
a737bd4d 27951
c19d1205 27952 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 27953 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 27954 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 27955
2fc8bdac
ZW
27956 if (fixP->fx_done || !seg->use_rela_p)
27957 {
27958 newval = md_chars_to_number (buf, THUMB_SIZE);
27959 newval |= (value & 0xfff) >> 1;
27960 md_number_to_chars (buf, newval, THUMB_SIZE);
27961 }
c19d1205 27962 break;
a737bd4d 27963
c19d1205 27964 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
27965 if (fixP->fx_addsy
27966 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27967 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
27968 && ARM_IS_FUNC (fixP->fx_addsy)
27969 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27970 {
27971 /* Force a relocation for a branch 20 bits wide. */
27972 fixP->fx_done = 0;
27973 }
08f10d51 27974 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
27975 as_bad_where (fixP->fx_file, fixP->fx_line,
27976 _("conditional branch out of range"));
404ff6b5 27977
2fc8bdac
ZW
27978 if (fixP->fx_done || !seg->use_rela_p)
27979 {
27980 offsetT newval2;
27981 addressT S, J1, J2, lo, hi;
404ff6b5 27982
2fc8bdac
ZW
27983 S = (value & 0x00100000) >> 20;
27984 J2 = (value & 0x00080000) >> 19;
27985 J1 = (value & 0x00040000) >> 18;
27986 hi = (value & 0x0003f000) >> 12;
27987 lo = (value & 0x00000ffe) >> 1;
6c43fab6 27988
2fc8bdac
ZW
27989 newval = md_chars_to_number (buf, THUMB_SIZE);
27990 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27991 newval |= (S << 10) | hi;
27992 newval2 |= (J1 << 13) | (J2 << 11) | lo;
27993 md_number_to_chars (buf, newval, THUMB_SIZE);
27994 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
27995 }
c19d1205 27996 break;
6c43fab6 27997
c19d1205 27998 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
27999 /* If there is a blx from a thumb state function to
28000 another thumb function flip this to a bl and warn
28001 about it. */
28002
28003 if (fixP->fx_addsy
34e77a92 28004 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28005 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28006 && THUMB_IS_FUNC (fixP->fx_addsy))
28007 {
28008 const char *name = S_GET_NAME (fixP->fx_addsy);
28009 as_warn_where (fixP->fx_file, fixP->fx_line,
28010 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
28011 name);
28012 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28013 newval = newval | 0x1000;
28014 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28015 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28016 fixP->fx_done = 1;
28017 }
28018
28019
28020 goto thumb_bl_common;
28021
c19d1205 28022 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
28023 /* A bl from Thumb state ISA to an internal ARM state function
28024 is converted to a blx. */
28025 if (fixP->fx_addsy
28026 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 28027 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28028 && ARM_IS_FUNC (fixP->fx_addsy)
28029 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28030 {
28031 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28032 newval = newval & ~0x1000;
28033 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28034 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
28035 fixP->fx_done = 1;
28036 }
28037
28038 thumb_bl_common:
28039
2fc8bdac
ZW
28040 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28041 /* For a BLX instruction, make sure that the relocation is rounded up
28042 to a word boundary. This follows the semantics of the instruction
28043 which specifies that bit 1 of the target address will come from bit
28044 1 of the base address. */
d406f3e4
JB
28045 value = (value + 3) & ~ 3;
28046
28047#ifdef OBJ_ELF
28048 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
28049 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28050 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28051#endif
404ff6b5 28052
2b2f5df9
NC
28053 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
28054 {
fc289b0a 28055 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
28056 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28057 else if ((value & ~0x1ffffff)
28058 && ((value & ~0x1ffffff) != ~0x1ffffff))
28059 as_bad_where (fixP->fx_file, fixP->fx_line,
28060 _("Thumb2 branch out of range"));
28061 }
4a42ebbc
RR
28062
28063 if (fixP->fx_done || !seg->use_rela_p)
28064 encode_thumb2_b_bl_offset (buf, value);
28065
c19d1205 28066 break;
404ff6b5 28067
c19d1205 28068 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
28069 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
28070 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 28071
2fc8bdac 28072 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 28073 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 28074
2fc8bdac 28075 break;
a737bd4d 28076
2fc8bdac
ZW
28077 case BFD_RELOC_8:
28078 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 28079 *buf = value;
c19d1205 28080 break;
a737bd4d 28081
c19d1205 28082 case BFD_RELOC_16:
2fc8bdac 28083 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28084 md_number_to_chars (buf, value, 2);
c19d1205 28085 break;
a737bd4d 28086
c19d1205 28087#ifdef OBJ_ELF
0855e32b
NS
28088 case BFD_RELOC_ARM_TLS_CALL:
28089 case BFD_RELOC_ARM_THM_TLS_CALL:
28090 case BFD_RELOC_ARM_TLS_DESCSEQ:
28091 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 28092 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
28093 case BFD_RELOC_ARM_TLS_GD32:
28094 case BFD_RELOC_ARM_TLS_LE32:
28095 case BFD_RELOC_ARM_TLS_IE32:
28096 case BFD_RELOC_ARM_TLS_LDM32:
28097 case BFD_RELOC_ARM_TLS_LDO32:
28098 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 28099 break;
6c43fab6 28100
5c5a4843
CL
28101 /* Same handling as above, but with the arm_fdpic guard. */
28102 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
28103 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
28104 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
28105 if (arm_fdpic)
28106 {
28107 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28108 }
28109 else
28110 {
28111 as_bad_where (fixP->fx_file, fixP->fx_line,
28112 _("Relocation supported only in FDPIC mode"));
28113 }
28114 break;
28115
c19d1205
ZW
28116 case BFD_RELOC_ARM_GOT32:
28117 case BFD_RELOC_ARM_GOTOFF:
c19d1205 28118 break;
b43420e6
NC
28119
28120 case BFD_RELOC_ARM_GOT_PREL:
28121 if (fixP->fx_done || !seg->use_rela_p)
477330fc 28122 md_number_to_chars (buf, value, 4);
b43420e6
NC
28123 break;
28124
9a6f4e97
NS
28125 case BFD_RELOC_ARM_TARGET2:
28126 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
28127 addend here for REL targets, because it won't be written out
28128 during reloc processing later. */
9a6f4e97
NS
28129 if (fixP->fx_done || !seg->use_rela_p)
28130 md_number_to_chars (buf, fixP->fx_offset, 4);
28131 break;
188fd7ae
CL
28132
28133 /* Relocations for FDPIC. */
28134 case BFD_RELOC_ARM_GOTFUNCDESC:
28135 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
28136 case BFD_RELOC_ARM_FUNCDESC:
28137 if (arm_fdpic)
28138 {
28139 if (fixP->fx_done || !seg->use_rela_p)
28140 md_number_to_chars (buf, 0, 4);
28141 }
28142 else
28143 {
28144 as_bad_where (fixP->fx_file, fixP->fx_line,
28145 _("Relocation supported only in FDPIC mode"));
28146 }
28147 break;
c19d1205 28148#endif
6c43fab6 28149
c19d1205
ZW
28150 case BFD_RELOC_RVA:
28151 case BFD_RELOC_32:
28152 case BFD_RELOC_ARM_TARGET1:
28153 case BFD_RELOC_ARM_ROSEGREL32:
28154 case BFD_RELOC_ARM_SBREL32:
28155 case BFD_RELOC_32_PCREL:
f0927246
NC
28156#ifdef TE_PE
28157 case BFD_RELOC_32_SECREL:
28158#endif
2fc8bdac 28159 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
28160#ifdef TE_WINCE
28161 /* For WinCE we only do this for pcrel fixups. */
28162 if (fixP->fx_done || fixP->fx_pcrel)
28163#endif
28164 md_number_to_chars (buf, value, 4);
c19d1205 28165 break;
6c43fab6 28166
c19d1205
ZW
28167#ifdef OBJ_ELF
28168 case BFD_RELOC_ARM_PREL31:
2fc8bdac 28169 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
28170 {
28171 newval = md_chars_to_number (buf, 4) & 0x80000000;
28172 if ((value ^ (value >> 1)) & 0x40000000)
28173 {
28174 as_bad_where (fixP->fx_file, fixP->fx_line,
28175 _("rel31 relocation overflow"));
28176 }
28177 newval |= value & 0x7fffffff;
28178 md_number_to_chars (buf, newval, 4);
28179 }
28180 break;
c19d1205 28181#endif
a737bd4d 28182
c19d1205 28183 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 28184 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 28185 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
28186 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
28187 newval = md_chars_to_number (buf, INSN_SIZE);
28188 else
28189 newval = get_thumb32_insn (buf);
28190 if ((newval & 0x0f200f00) == 0x0d000900)
28191 {
28192 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
28193 has permitted values that are multiples of 2, in the range 0
28194 to 510. */
28195 if (value < -510 || value > 510 || (value & 1))
28196 as_bad_where (fixP->fx_file, fixP->fx_line,
28197 _("co-processor offset out of range"));
28198 }
32c36c3c
AV
28199 else if ((newval & 0xfe001f80) == 0xec000f80)
28200 {
28201 if (value < -511 || value > 512 || (value & 3))
28202 as_bad_where (fixP->fx_file, fixP->fx_line,
28203 _("co-processor offset out of range"));
28204 }
9db2f6b4 28205 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
28206 as_bad_where (fixP->fx_file, fixP->fx_line,
28207 _("co-processor offset out of range"));
28208 cp_off_common:
26d97720 28209 sign = value > 0;
c19d1205
ZW
28210 if (value < 0)
28211 value = -value;
8f06b2d8
PB
28212 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28213 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28214 newval = md_chars_to_number (buf, INSN_SIZE);
28215 else
28216 newval = get_thumb32_insn (buf);
26d97720 28217 if (value == 0)
32c36c3c
AV
28218 {
28219 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28220 newval &= 0xffffff80;
28221 else
28222 newval &= 0xffffff00;
28223 }
26d97720
NS
28224 else
28225 {
32c36c3c
AV
28226 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28227 newval &= 0xff7fff80;
28228 else
28229 newval &= 0xff7fff00;
9db2f6b4
RL
28230 if ((newval & 0x0f200f00) == 0x0d000900)
28231 {
28232 /* This is a fp16 vstr/vldr.
28233
28234 It requires the immediate offset in the instruction is shifted
28235 left by 1 to be a half-word offset.
28236
28237 Here, left shift by 1 first, and later right shift by 2
28238 should get the right offset. */
28239 value <<= 1;
28240 }
26d97720
NS
28241 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
28242 }
8f06b2d8
PB
28243 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28244 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28245 md_number_to_chars (buf, newval, INSN_SIZE);
28246 else
28247 put_thumb32_insn (buf, newval);
c19d1205 28248 break;
a737bd4d 28249
c19d1205 28250 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 28251 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
28252 if (value < -255 || value > 255)
28253 as_bad_where (fixP->fx_file, fixP->fx_line,
28254 _("co-processor offset out of range"));
df7849c5 28255 value *= 4;
c19d1205 28256 goto cp_off_common;
6c43fab6 28257
c19d1205
ZW
28258 case BFD_RELOC_ARM_THUMB_OFFSET:
28259 newval = md_chars_to_number (buf, THUMB_SIZE);
28260 /* Exactly what ranges, and where the offset is inserted depends
28261 on the type of instruction, we can establish this from the
28262 top 4 bits. */
28263 switch (newval >> 12)
28264 {
28265 case 4: /* PC load. */
28266 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
28267 forced to zero for these loads; md_pcrel_from has already
28268 compensated for this. */
28269 if (value & 3)
28270 as_bad_where (fixP->fx_file, fixP->fx_line,
28271 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
28272 (((unsigned long) fixP->fx_frag->fr_address
28273 + (unsigned long) fixP->fx_where) & ~3)
28274 + (unsigned long) value);
a737bd4d 28275
c19d1205
ZW
28276 if (value & ~0x3fc)
28277 as_bad_where (fixP->fx_file, fixP->fx_line,
28278 _("invalid offset, value too big (0x%08lX)"),
28279 (long) value);
a737bd4d 28280
c19d1205
ZW
28281 newval |= value >> 2;
28282 break;
a737bd4d 28283
c19d1205
ZW
28284 case 9: /* SP load/store. */
28285 if (value & ~0x3fc)
28286 as_bad_where (fixP->fx_file, fixP->fx_line,
28287 _("invalid offset, value too big (0x%08lX)"),
28288 (long) value);
28289 newval |= value >> 2;
28290 break;
6c43fab6 28291
c19d1205
ZW
28292 case 6: /* Word load/store. */
28293 if (value & ~0x7c)
28294 as_bad_where (fixP->fx_file, fixP->fx_line,
28295 _("invalid offset, value too big (0x%08lX)"),
28296 (long) value);
28297 newval |= value << 4; /* 6 - 2. */
28298 break;
a737bd4d 28299
c19d1205
ZW
28300 case 7: /* Byte load/store. */
28301 if (value & ~0x1f)
28302 as_bad_where (fixP->fx_file, fixP->fx_line,
28303 _("invalid offset, value too big (0x%08lX)"),
28304 (long) value);
28305 newval |= value << 6;
28306 break;
a737bd4d 28307
c19d1205
ZW
28308 case 8: /* Halfword load/store. */
28309 if (value & ~0x3e)
28310 as_bad_where (fixP->fx_file, fixP->fx_line,
28311 _("invalid offset, value too big (0x%08lX)"),
28312 (long) value);
28313 newval |= value << 5; /* 6 - 1. */
28314 break;
a737bd4d 28315
c19d1205
ZW
28316 default:
28317 as_bad_where (fixP->fx_file, fixP->fx_line,
28318 "Unable to process relocation for thumb opcode: %lx",
28319 (unsigned long) newval);
28320 break;
28321 }
28322 md_number_to_chars (buf, newval, THUMB_SIZE);
28323 break;
a737bd4d 28324
c19d1205
ZW
28325 case BFD_RELOC_ARM_THUMB_ADD:
28326 /* This is a complicated relocation, since we use it for all of
28327 the following immediate relocations:
a737bd4d 28328
c19d1205
ZW
28329 3bit ADD/SUB
28330 8bit ADD/SUB
28331 9bit ADD/SUB SP word-aligned
28332 10bit ADD PC/SP word-aligned
a737bd4d 28333
c19d1205
ZW
28334 The type of instruction being processed is encoded in the
28335 instruction field:
a737bd4d 28336
c19d1205
ZW
28337 0x8000 SUB
28338 0x00F0 Rd
28339 0x000F Rs
28340 */
28341 newval = md_chars_to_number (buf, THUMB_SIZE);
28342 {
28343 int rd = (newval >> 4) & 0xf;
28344 int rs = newval & 0xf;
28345 int subtract = !!(newval & 0x8000);
a737bd4d 28346
c19d1205
ZW
28347 /* Check for HI regs, only very restricted cases allowed:
28348 Adjusting SP, and using PC or SP to get an address. */
28349 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
28350 || (rs > 7 && rs != REG_SP && rs != REG_PC))
28351 as_bad_where (fixP->fx_file, fixP->fx_line,
28352 _("invalid Hi register with immediate"));
a737bd4d 28353
c19d1205
ZW
28354 /* If value is negative, choose the opposite instruction. */
28355 if (value < 0)
28356 {
28357 value = -value;
28358 subtract = !subtract;
28359 if (value < 0)
28360 as_bad_where (fixP->fx_file, fixP->fx_line,
28361 _("immediate value out of range"));
28362 }
a737bd4d 28363
c19d1205
ZW
28364 if (rd == REG_SP)
28365 {
75c11999 28366 if (value & ~0x1fc)
c19d1205
ZW
28367 as_bad_where (fixP->fx_file, fixP->fx_line,
28368 _("invalid immediate for stack address calculation"));
28369 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
28370 newval |= value >> 2;
28371 }
28372 else if (rs == REG_PC || rs == REG_SP)
28373 {
c12d2c9d
NC
28374 /* PR gas/18541. If the addition is for a defined symbol
28375 within range of an ADR instruction then accept it. */
28376 if (subtract
28377 && value == 4
28378 && fixP->fx_addsy != NULL)
28379 {
28380 subtract = 0;
28381
28382 if (! S_IS_DEFINED (fixP->fx_addsy)
28383 || S_GET_SEGMENT (fixP->fx_addsy) != seg
28384 || S_IS_WEAK (fixP->fx_addsy))
28385 {
28386 as_bad_where (fixP->fx_file, fixP->fx_line,
28387 _("address calculation needs a strongly defined nearby symbol"));
28388 }
28389 else
28390 {
28391 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
28392
28393 /* Round up to the next 4-byte boundary. */
28394 if (v & 3)
28395 v = (v + 3) & ~ 3;
28396 else
28397 v += 4;
28398 v = S_GET_VALUE (fixP->fx_addsy) - v;
28399
28400 if (v & ~0x3fc)
28401 {
28402 as_bad_where (fixP->fx_file, fixP->fx_line,
28403 _("symbol too far away"));
28404 }
28405 else
28406 {
28407 fixP->fx_done = 1;
28408 value = v;
28409 }
28410 }
28411 }
28412
c19d1205
ZW
28413 if (subtract || value & ~0x3fc)
28414 as_bad_where (fixP->fx_file, fixP->fx_line,
28415 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 28416 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
28417 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
28418 newval |= rd << 8;
28419 newval |= value >> 2;
28420 }
28421 else if (rs == rd)
28422 {
28423 if (value & ~0xff)
28424 as_bad_where (fixP->fx_file, fixP->fx_line,
28425 _("immediate value out of range"));
28426 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
28427 newval |= (rd << 8) | value;
28428 }
28429 else
28430 {
28431 if (value & ~0x7)
28432 as_bad_where (fixP->fx_file, fixP->fx_line,
28433 _("immediate value out of range"));
28434 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
28435 newval |= rd | (rs << 3) | (value << 6);
28436 }
28437 }
28438 md_number_to_chars (buf, newval, THUMB_SIZE);
28439 break;
a737bd4d 28440
c19d1205
ZW
28441 case BFD_RELOC_ARM_THUMB_IMM:
28442 newval = md_chars_to_number (buf, THUMB_SIZE);
28443 if (value < 0 || value > 255)
28444 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 28445 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
28446 (long) value);
28447 newval |= value;
28448 md_number_to_chars (buf, newval, THUMB_SIZE);
28449 break;
a737bd4d 28450
c19d1205
ZW
28451 case BFD_RELOC_ARM_THUMB_SHIFT:
28452 /* 5bit shift value (0..32). LSL cannot take 32. */
28453 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
28454 temp = newval & 0xf800;
28455 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
28456 as_bad_where (fixP->fx_file, fixP->fx_line,
28457 _("invalid shift value: %ld"), (long) value);
28458 /* Shifts of zero must be encoded as LSL. */
28459 if (value == 0)
28460 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
28461 /* Shifts of 32 are encoded as zero. */
28462 else if (value == 32)
28463 value = 0;
28464 newval |= value << 6;
28465 md_number_to_chars (buf, newval, THUMB_SIZE);
28466 break;
a737bd4d 28467
c19d1205
ZW
28468 case BFD_RELOC_VTABLE_INHERIT:
28469 case BFD_RELOC_VTABLE_ENTRY:
28470 fixP->fx_done = 0;
28471 return;
6c43fab6 28472
b6895b4f
PB
28473 case BFD_RELOC_ARM_MOVW:
28474 case BFD_RELOC_ARM_MOVT:
28475 case BFD_RELOC_ARM_THUMB_MOVW:
28476 case BFD_RELOC_ARM_THUMB_MOVT:
28477 if (fixP->fx_done || !seg->use_rela_p)
28478 {
28479 /* REL format relocations are limited to a 16-bit addend. */
28480 if (!fixP->fx_done)
28481 {
39623e12 28482 if (value < -0x8000 || value > 0x7fff)
b6895b4f 28483 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 28484 _("offset out of range"));
b6895b4f
PB
28485 }
28486 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
28487 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28488 {
28489 value >>= 16;
28490 }
28491
28492 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
28493 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28494 {
28495 newval = get_thumb32_insn (buf);
28496 newval &= 0xfbf08f00;
28497 newval |= (value & 0xf000) << 4;
28498 newval |= (value & 0x0800) << 15;
28499 newval |= (value & 0x0700) << 4;
28500 newval |= (value & 0x00ff);
28501 put_thumb32_insn (buf, newval);
28502 }
28503 else
28504 {
28505 newval = md_chars_to_number (buf, 4);
28506 newval &= 0xfff0f000;
28507 newval |= value & 0x0fff;
28508 newval |= (value & 0xf000) << 4;
28509 md_number_to_chars (buf, newval, 4);
28510 }
28511 }
28512 return;
28513
72d98d16
MG
28514 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
28515 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
28516 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
28517 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
28518 gas_assert (!fixP->fx_done);
28519 {
28520 bfd_vma insn;
28521 bfd_boolean is_mov;
28522 bfd_vma encoded_addend = value;
28523
28524 /* Check that addend can be encoded in instruction. */
28525 if (!seg->use_rela_p && (value < 0 || value > 255))
28526 as_bad_where (fixP->fx_file, fixP->fx_line,
28527 _("the offset 0x%08lX is not representable"),
28528 (unsigned long) encoded_addend);
28529
28530 /* Extract the instruction. */
28531 insn = md_chars_to_number (buf, THUMB_SIZE);
28532 is_mov = (insn & 0xf800) == 0x2000;
28533
28534 /* Encode insn. */
28535 if (is_mov)
28536 {
28537 if (!seg->use_rela_p)
28538 insn |= encoded_addend;
28539 }
28540 else
28541 {
28542 int rd, rs;
28543
28544 /* Extract the instruction. */
28545 /* Encoding is the following
28546 0x8000 SUB
28547 0x00F0 Rd
28548 0x000F Rs
28549 */
28550 /* The following conditions must be true :
28551 - ADD
28552 - Rd == Rs
28553 - Rd <= 7
28554 */
28555 rd = (insn >> 4) & 0xf;
28556 rs = insn & 0xf;
28557 if ((insn & 0x8000) || (rd != rs) || rd > 7)
28558 as_bad_where (fixP->fx_file, fixP->fx_line,
28559 _("Unable to process relocation for thumb opcode: %lx"),
28560 (unsigned long) insn);
28561
28562 /* Encode as ADD immediate8 thumb 1 code. */
28563 insn = 0x3000 | (rd << 8);
28564
28565 /* Place the encoded addend into the first 8 bits of the
28566 instruction. */
28567 if (!seg->use_rela_p)
28568 insn |= encoded_addend;
28569 }
28570
28571 /* Update the instruction. */
28572 md_number_to_chars (buf, insn, THUMB_SIZE);
28573 }
28574 break;
28575
4962c51a
MS
28576 case BFD_RELOC_ARM_ALU_PC_G0_NC:
28577 case BFD_RELOC_ARM_ALU_PC_G0:
28578 case BFD_RELOC_ARM_ALU_PC_G1_NC:
28579 case BFD_RELOC_ARM_ALU_PC_G1:
28580 case BFD_RELOC_ARM_ALU_PC_G2:
28581 case BFD_RELOC_ARM_ALU_SB_G0_NC:
28582 case BFD_RELOC_ARM_ALU_SB_G0:
28583 case BFD_RELOC_ARM_ALU_SB_G1_NC:
28584 case BFD_RELOC_ARM_ALU_SB_G1:
28585 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 28586 gas_assert (!fixP->fx_done);
4962c51a
MS
28587 if (!seg->use_rela_p)
28588 {
477330fc
RM
28589 bfd_vma insn;
28590 bfd_vma encoded_addend;
3ca4a8ec 28591 bfd_vma addend_abs = llabs (value);
477330fc
RM
28592
28593 /* Check that the absolute value of the addend can be
28594 expressed as an 8-bit constant plus a rotation. */
28595 encoded_addend = encode_arm_immediate (addend_abs);
28596 if (encoded_addend == (unsigned int) FAIL)
4962c51a 28597 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28598 _("the offset 0x%08lX is not representable"),
28599 (unsigned long) addend_abs);
28600
28601 /* Extract the instruction. */
28602 insn = md_chars_to_number (buf, INSN_SIZE);
28603
28604 /* If the addend is positive, use an ADD instruction.
28605 Otherwise use a SUB. Take care not to destroy the S bit. */
28606 insn &= 0xff1fffff;
28607 if (value < 0)
28608 insn |= 1 << 22;
28609 else
28610 insn |= 1 << 23;
28611
28612 /* Place the encoded addend into the first 12 bits of the
28613 instruction. */
28614 insn &= 0xfffff000;
28615 insn |= encoded_addend;
28616
28617 /* Update the instruction. */
28618 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
28619 }
28620 break;
28621
28622 case BFD_RELOC_ARM_LDR_PC_G0:
28623 case BFD_RELOC_ARM_LDR_PC_G1:
28624 case BFD_RELOC_ARM_LDR_PC_G2:
28625 case BFD_RELOC_ARM_LDR_SB_G0:
28626 case BFD_RELOC_ARM_LDR_SB_G1:
28627 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 28628 gas_assert (!fixP->fx_done);
4962c51a 28629 if (!seg->use_rela_p)
477330fc
RM
28630 {
28631 bfd_vma insn;
3ca4a8ec 28632 bfd_vma addend_abs = llabs (value);
4962c51a 28633
477330fc
RM
28634 /* Check that the absolute value of the addend can be
28635 encoded in 12 bits. */
28636 if (addend_abs >= 0x1000)
4962c51a 28637 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28638 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
28639 (unsigned long) addend_abs);
28640
28641 /* Extract the instruction. */
28642 insn = md_chars_to_number (buf, INSN_SIZE);
28643
28644 /* If the addend is negative, clear bit 23 of the instruction.
28645 Otherwise set it. */
28646 if (value < 0)
28647 insn &= ~(1 << 23);
28648 else
28649 insn |= 1 << 23;
28650
28651 /* Place the absolute value of the addend into the first 12 bits
28652 of the instruction. */
28653 insn &= 0xfffff000;
28654 insn |= addend_abs;
28655
28656 /* Update the instruction. */
28657 md_number_to_chars (buf, insn, INSN_SIZE);
28658 }
4962c51a
MS
28659 break;
28660
28661 case BFD_RELOC_ARM_LDRS_PC_G0:
28662 case BFD_RELOC_ARM_LDRS_PC_G1:
28663 case BFD_RELOC_ARM_LDRS_PC_G2:
28664 case BFD_RELOC_ARM_LDRS_SB_G0:
28665 case BFD_RELOC_ARM_LDRS_SB_G1:
28666 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 28667 gas_assert (!fixP->fx_done);
4962c51a 28668 if (!seg->use_rela_p)
477330fc
RM
28669 {
28670 bfd_vma insn;
3ca4a8ec 28671 bfd_vma addend_abs = llabs (value);
4962c51a 28672
477330fc
RM
28673 /* Check that the absolute value of the addend can be
28674 encoded in 8 bits. */
28675 if (addend_abs >= 0x100)
4962c51a 28676 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28677 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
28678 (unsigned long) addend_abs);
28679
28680 /* Extract the instruction. */
28681 insn = md_chars_to_number (buf, INSN_SIZE);
28682
28683 /* If the addend is negative, clear bit 23 of the instruction.
28684 Otherwise set it. */
28685 if (value < 0)
28686 insn &= ~(1 << 23);
28687 else
28688 insn |= 1 << 23;
28689
28690 /* Place the first four bits of the absolute value of the addend
28691 into the first 4 bits of the instruction, and the remaining
28692 four into bits 8 .. 11. */
28693 insn &= 0xfffff0f0;
28694 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
28695
28696 /* Update the instruction. */
28697 md_number_to_chars (buf, insn, INSN_SIZE);
28698 }
4962c51a
MS
28699 break;
28700
28701 case BFD_RELOC_ARM_LDC_PC_G0:
28702 case BFD_RELOC_ARM_LDC_PC_G1:
28703 case BFD_RELOC_ARM_LDC_PC_G2:
28704 case BFD_RELOC_ARM_LDC_SB_G0:
28705 case BFD_RELOC_ARM_LDC_SB_G1:
28706 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 28707 gas_assert (!fixP->fx_done);
4962c51a 28708 if (!seg->use_rela_p)
477330fc
RM
28709 {
28710 bfd_vma insn;
3ca4a8ec 28711 bfd_vma addend_abs = llabs (value);
4962c51a 28712
477330fc
RM
28713 /* Check that the absolute value of the addend is a multiple of
28714 four and, when divided by four, fits in 8 bits. */
28715 if (addend_abs & 0x3)
4962c51a 28716 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28717 _("bad offset 0x%08lX (must be word-aligned)"),
28718 (unsigned long) addend_abs);
4962c51a 28719
477330fc 28720 if ((addend_abs >> 2) > 0xff)
4962c51a 28721 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
28722 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
28723 (unsigned long) addend_abs);
28724
28725 /* Extract the instruction. */
28726 insn = md_chars_to_number (buf, INSN_SIZE);
28727
28728 /* If the addend is negative, clear bit 23 of the instruction.
28729 Otherwise set it. */
28730 if (value < 0)
28731 insn &= ~(1 << 23);
28732 else
28733 insn |= 1 << 23;
28734
28735 /* Place the addend (divided by four) into the first eight
28736 bits of the instruction. */
28737 insn &= 0xfffffff0;
28738 insn |= addend_abs >> 2;
28739
28740 /* Update the instruction. */
28741 md_number_to_chars (buf, insn, INSN_SIZE);
28742 }
4962c51a
MS
28743 break;
28744
e12437dc
AV
28745 case BFD_RELOC_THUMB_PCREL_BRANCH5:
28746 if (fixP->fx_addsy
28747 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28748 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28749 && ARM_IS_FUNC (fixP->fx_addsy)
28750 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28751 {
28752 /* Force a relocation for a branch 5 bits wide. */
28753 fixP->fx_done = 0;
28754 }
28755 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
28756 as_bad_where (fixP->fx_file, fixP->fx_line,
28757 BAD_BRANCH_OFF);
28758
28759 if (fixP->fx_done || !seg->use_rela_p)
28760 {
28761 addressT boff = value >> 1;
28762
28763 newval = md_chars_to_number (buf, THUMB_SIZE);
28764 newval |= (boff << 7);
28765 md_number_to_chars (buf, newval, THUMB_SIZE);
28766 }
28767 break;
28768
f6b2b12d
AV
28769 case BFD_RELOC_THUMB_PCREL_BFCSEL:
28770 if (fixP->fx_addsy
28771 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28772 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28773 && ARM_IS_FUNC (fixP->fx_addsy)
28774 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28775 {
28776 fixP->fx_done = 0;
28777 }
28778 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
28779 as_bad_where (fixP->fx_file, fixP->fx_line,
28780 _("branch out of range"));
28781
28782 if (fixP->fx_done || !seg->use_rela_p)
28783 {
28784 newval = md_chars_to_number (buf, THUMB_SIZE);
28785
28786 addressT boff = ((newval & 0x0780) >> 7) << 1;
28787 addressT diff = value - boff;
28788
28789 if (diff == 4)
28790 {
28791 newval |= 1 << 1; /* T bit. */
28792 }
28793 else if (diff != 2)
28794 {
28795 as_bad_where (fixP->fx_file, fixP->fx_line,
28796 _("out of range label-relative fixup value"));
28797 }
28798 md_number_to_chars (buf, newval, THUMB_SIZE);
28799 }
28800 break;
28801
e5d6e09e
AV
28802 case BFD_RELOC_ARM_THUMB_BF17:
28803 if (fixP->fx_addsy
28804 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28805 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28806 && ARM_IS_FUNC (fixP->fx_addsy)
28807 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28808 {
28809 /* Force a relocation for a branch 17 bits wide. */
28810 fixP->fx_done = 0;
28811 }
28812
28813 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
28814 as_bad_where (fixP->fx_file, fixP->fx_line,
28815 BAD_BRANCH_OFF);
28816
28817 if (fixP->fx_done || !seg->use_rela_p)
28818 {
28819 offsetT newval2;
28820 addressT immA, immB, immC;
28821
28822 immA = (value & 0x0001f000) >> 12;
28823 immB = (value & 0x00000ffc) >> 2;
28824 immC = (value & 0x00000002) >> 1;
28825
28826 newval = md_chars_to_number (buf, THUMB_SIZE);
28827 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28828 newval |= immA;
28829 newval2 |= (immC << 11) | (immB << 1);
28830 md_number_to_chars (buf, newval, THUMB_SIZE);
28831 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28832 }
28833 break;
28834
1caf72a5
AV
28835 case BFD_RELOC_ARM_THUMB_BF19:
28836 if (fixP->fx_addsy
28837 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28838 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28839 && ARM_IS_FUNC (fixP->fx_addsy)
28840 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28841 {
28842 /* Force a relocation for a branch 19 bits wide. */
28843 fixP->fx_done = 0;
28844 }
28845
28846 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
28847 as_bad_where (fixP->fx_file, fixP->fx_line,
28848 BAD_BRANCH_OFF);
28849
28850 if (fixP->fx_done || !seg->use_rela_p)
28851 {
28852 offsetT newval2;
28853 addressT immA, immB, immC;
28854
28855 immA = (value & 0x0007f000) >> 12;
28856 immB = (value & 0x00000ffc) >> 2;
28857 immC = (value & 0x00000002) >> 1;
28858
28859 newval = md_chars_to_number (buf, THUMB_SIZE);
28860 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28861 newval |= immA;
28862 newval2 |= (immC << 11) | (immB << 1);
28863 md_number_to_chars (buf, newval, THUMB_SIZE);
28864 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28865 }
28866 break;
28867
1889da70
AV
28868 case BFD_RELOC_ARM_THUMB_BF13:
28869 if (fixP->fx_addsy
28870 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28871 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28872 && ARM_IS_FUNC (fixP->fx_addsy)
28873 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28874 {
28875 /* Force a relocation for a branch 13 bits wide. */
28876 fixP->fx_done = 0;
28877 }
28878
28879 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
28880 as_bad_where (fixP->fx_file, fixP->fx_line,
28881 BAD_BRANCH_OFF);
28882
28883 if (fixP->fx_done || !seg->use_rela_p)
28884 {
28885 offsetT newval2;
28886 addressT immA, immB, immC;
28887
28888 immA = (value & 0x00001000) >> 12;
28889 immB = (value & 0x00000ffc) >> 2;
28890 immC = (value & 0x00000002) >> 1;
28891
28892 newval = md_chars_to_number (buf, THUMB_SIZE);
28893 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28894 newval |= immA;
28895 newval2 |= (immC << 11) | (immB << 1);
28896 md_number_to_chars (buf, newval, THUMB_SIZE);
28897 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28898 }
28899 break;
28900
60f993ce
AV
28901 case BFD_RELOC_ARM_THUMB_LOOP12:
28902 if (fixP->fx_addsy
28903 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28904 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28905 && ARM_IS_FUNC (fixP->fx_addsy)
28906 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28907 {
28908 /* Force a relocation for a branch 12 bits wide. */
28909 fixP->fx_done = 0;
28910 }
28911
28912 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 28913 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 28914 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
28915 || ((insn & 0xffffffff) == 0xf02fc001)
28916 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
28917 value = -value;
28918
28919 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
28920 as_bad_where (fixP->fx_file, fixP->fx_line,
28921 BAD_BRANCH_OFF);
28922 if (fixP->fx_done || !seg->use_rela_p)
28923 {
28924 addressT imml, immh;
28925
28926 immh = (value & 0x00000ffc) >> 2;
28927 imml = (value & 0x00000002) >> 1;
28928
28929 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28930 newval |= (imml << 11) | (immh << 1);
28931 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
28932 }
28933 break;
28934
845b51d6
PB
28935 case BFD_RELOC_ARM_V4BX:
28936 /* This will need to go in the object file. */
28937 fixP->fx_done = 0;
28938 break;
28939
c19d1205
ZW
28940 case BFD_RELOC_UNUSED:
28941 default:
28942 as_bad_where (fixP->fx_file, fixP->fx_line,
28943 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
28944 }
6c43fab6
RE
28945}
28946
c19d1205
ZW
28947/* Translate internal representation of relocation info to BFD target
28948 format. */
a737bd4d 28949
c19d1205 28950arelent *
00a97672 28951tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 28952{
c19d1205
ZW
28953 arelent * reloc;
28954 bfd_reloc_code_real_type code;
a737bd4d 28955
325801bd 28956 reloc = XNEW (arelent);
a737bd4d 28957
325801bd 28958 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
28959 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
28960 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 28961
2fc8bdac 28962 if (fixp->fx_pcrel)
00a97672
RS
28963 {
28964 if (section->use_rela_p)
28965 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
28966 else
28967 fixp->fx_offset = reloc->address;
28968 }
c19d1205 28969 reloc->addend = fixp->fx_offset;
a737bd4d 28970
c19d1205 28971 switch (fixp->fx_r_type)
a737bd4d 28972 {
c19d1205
ZW
28973 case BFD_RELOC_8:
28974 if (fixp->fx_pcrel)
28975 {
28976 code = BFD_RELOC_8_PCREL;
28977 break;
28978 }
1a0670f3 28979 /* Fall through. */
a737bd4d 28980
c19d1205
ZW
28981 case BFD_RELOC_16:
28982 if (fixp->fx_pcrel)
28983 {
28984 code = BFD_RELOC_16_PCREL;
28985 break;
28986 }
1a0670f3 28987 /* Fall through. */
6c43fab6 28988
c19d1205
ZW
28989 case BFD_RELOC_32:
28990 if (fixp->fx_pcrel)
28991 {
28992 code = BFD_RELOC_32_PCREL;
28993 break;
28994 }
1a0670f3 28995 /* Fall through. */
a737bd4d 28996
b6895b4f
PB
28997 case BFD_RELOC_ARM_MOVW:
28998 if (fixp->fx_pcrel)
28999 {
29000 code = BFD_RELOC_ARM_MOVW_PCREL;
29001 break;
29002 }
1a0670f3 29003 /* Fall through. */
b6895b4f
PB
29004
29005 case BFD_RELOC_ARM_MOVT:
29006 if (fixp->fx_pcrel)
29007 {
29008 code = BFD_RELOC_ARM_MOVT_PCREL;
29009 break;
29010 }
1a0670f3 29011 /* Fall through. */
b6895b4f
PB
29012
29013 case BFD_RELOC_ARM_THUMB_MOVW:
29014 if (fixp->fx_pcrel)
29015 {
29016 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
29017 break;
29018 }
1a0670f3 29019 /* Fall through. */
b6895b4f
PB
29020
29021 case BFD_RELOC_ARM_THUMB_MOVT:
29022 if (fixp->fx_pcrel)
29023 {
29024 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
29025 break;
29026 }
1a0670f3 29027 /* Fall through. */
b6895b4f 29028
c19d1205
ZW
29029 case BFD_RELOC_NONE:
29030 case BFD_RELOC_ARM_PCREL_BRANCH:
29031 case BFD_RELOC_ARM_PCREL_BLX:
29032 case BFD_RELOC_RVA:
29033 case BFD_RELOC_THUMB_PCREL_BRANCH7:
29034 case BFD_RELOC_THUMB_PCREL_BRANCH9:
29035 case BFD_RELOC_THUMB_PCREL_BRANCH12:
29036 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29037 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29038 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
29039 case BFD_RELOC_VTABLE_ENTRY:
29040 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
29041#ifdef TE_PE
29042 case BFD_RELOC_32_SECREL:
29043#endif
c19d1205
ZW
29044 code = fixp->fx_r_type;
29045 break;
a737bd4d 29046
00adf2d4
JB
29047 case BFD_RELOC_THUMB_PCREL_BLX:
29048#ifdef OBJ_ELF
29049 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
29050 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
29051 else
29052#endif
29053 code = BFD_RELOC_THUMB_PCREL_BLX;
29054 break;
29055
c19d1205
ZW
29056 case BFD_RELOC_ARM_LITERAL:
29057 case BFD_RELOC_ARM_HWLITERAL:
29058 /* If this is called then the a literal has
29059 been referenced across a section boundary. */
29060 as_bad_where (fixp->fx_file, fixp->fx_line,
29061 _("literal referenced across section boundary"));
29062 return NULL;
a737bd4d 29063
c19d1205 29064#ifdef OBJ_ELF
0855e32b
NS
29065 case BFD_RELOC_ARM_TLS_CALL:
29066 case BFD_RELOC_ARM_THM_TLS_CALL:
29067 case BFD_RELOC_ARM_TLS_DESCSEQ:
29068 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
29069 case BFD_RELOC_ARM_GOT32:
29070 case BFD_RELOC_ARM_GOTOFF:
b43420e6 29071 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
29072 case BFD_RELOC_ARM_PLT32:
29073 case BFD_RELOC_ARM_TARGET1:
29074 case BFD_RELOC_ARM_ROSEGREL32:
29075 case BFD_RELOC_ARM_SBREL32:
29076 case BFD_RELOC_ARM_PREL31:
29077 case BFD_RELOC_ARM_TARGET2:
c19d1205 29078 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
29079 case BFD_RELOC_ARM_PCREL_CALL:
29080 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
29081 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29082 case BFD_RELOC_ARM_ALU_PC_G0:
29083 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29084 case BFD_RELOC_ARM_ALU_PC_G1:
29085 case BFD_RELOC_ARM_ALU_PC_G2:
29086 case BFD_RELOC_ARM_LDR_PC_G0:
29087 case BFD_RELOC_ARM_LDR_PC_G1:
29088 case BFD_RELOC_ARM_LDR_PC_G2:
29089 case BFD_RELOC_ARM_LDRS_PC_G0:
29090 case BFD_RELOC_ARM_LDRS_PC_G1:
29091 case BFD_RELOC_ARM_LDRS_PC_G2:
29092 case BFD_RELOC_ARM_LDC_PC_G0:
29093 case BFD_RELOC_ARM_LDC_PC_G1:
29094 case BFD_RELOC_ARM_LDC_PC_G2:
29095 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29096 case BFD_RELOC_ARM_ALU_SB_G0:
29097 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29098 case BFD_RELOC_ARM_ALU_SB_G1:
29099 case BFD_RELOC_ARM_ALU_SB_G2:
29100 case BFD_RELOC_ARM_LDR_SB_G0:
29101 case BFD_RELOC_ARM_LDR_SB_G1:
29102 case BFD_RELOC_ARM_LDR_SB_G2:
29103 case BFD_RELOC_ARM_LDRS_SB_G0:
29104 case BFD_RELOC_ARM_LDRS_SB_G1:
29105 case BFD_RELOC_ARM_LDRS_SB_G2:
29106 case BFD_RELOC_ARM_LDC_SB_G0:
29107 case BFD_RELOC_ARM_LDC_SB_G1:
29108 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 29109 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
29110 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29111 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29112 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29113 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
29114 case BFD_RELOC_ARM_GOTFUNCDESC:
29115 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29116 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 29117 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 29118 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 29119 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
29120 code = fixp->fx_r_type;
29121 break;
a737bd4d 29122
0855e32b 29123 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 29124 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 29125 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 29126 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 29127 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 29128 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 29129 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 29130 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
29131 /* BFD will include the symbol's address in the addend.
29132 But we don't want that, so subtract it out again here. */
29133 if (!S_IS_COMMON (fixp->fx_addsy))
29134 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
29135 code = fixp->fx_r_type;
29136 break;
29137#endif
a737bd4d 29138
c19d1205
ZW
29139 case BFD_RELOC_ARM_IMMEDIATE:
29140 as_bad_where (fixp->fx_file, fixp->fx_line,
29141 _("internal relocation (type: IMMEDIATE) not fixed up"));
29142 return NULL;
a737bd4d 29143
c19d1205
ZW
29144 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
29145 as_bad_where (fixp->fx_file, fixp->fx_line,
29146 _("ADRL used for a symbol not defined in the same file"));
29147 return NULL;
a737bd4d 29148
e12437dc 29149 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 29150 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 29151 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
29152 as_bad_where (fixp->fx_file, fixp->fx_line,
29153 _("%s used for a symbol not defined in the same file"),
29154 bfd_get_reloc_code_name (fixp->fx_r_type));
29155 return NULL;
29156
c19d1205 29157 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
29158 if (section->use_rela_p)
29159 {
29160 code = fixp->fx_r_type;
29161 break;
29162 }
29163
c19d1205
ZW
29164 if (fixp->fx_addsy != NULL
29165 && !S_IS_DEFINED (fixp->fx_addsy)
29166 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 29167 {
c19d1205
ZW
29168 as_bad_where (fixp->fx_file, fixp->fx_line,
29169 _("undefined local label `%s'"),
29170 S_GET_NAME (fixp->fx_addsy));
29171 return NULL;
a737bd4d
NC
29172 }
29173
c19d1205
ZW
29174 as_bad_where (fixp->fx_file, fixp->fx_line,
29175 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
29176 return NULL;
a737bd4d 29177
c19d1205
ZW
29178 default:
29179 {
e0471c16 29180 const char * type;
6c43fab6 29181
c19d1205
ZW
29182 switch (fixp->fx_r_type)
29183 {
29184 case BFD_RELOC_NONE: type = "NONE"; break;
29185 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
29186 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 29187 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
29188 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
29189 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
29190 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 29191 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 29192 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
29193 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
29194 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
29195 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
29196 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
29197 default: type = _("<unknown>"); break;
29198 }
29199 as_bad_where (fixp->fx_file, fixp->fx_line,
29200 _("cannot represent %s relocation in this object file format"),
29201 type);
29202 return NULL;
29203 }
a737bd4d 29204 }
6c43fab6 29205
c19d1205
ZW
29206#ifdef OBJ_ELF
29207 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
29208 && GOT_symbol
29209 && fixp->fx_addsy == GOT_symbol)
29210 {
29211 code = BFD_RELOC_ARM_GOTPC;
29212 reloc->addend = fixp->fx_offset = reloc->address;
29213 }
29214#endif
6c43fab6 29215
c19d1205 29216 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 29217
c19d1205
ZW
29218 if (reloc->howto == NULL)
29219 {
29220 as_bad_where (fixp->fx_file, fixp->fx_line,
29221 _("cannot represent %s relocation in this object file format"),
29222 bfd_get_reloc_code_name (code));
29223 return NULL;
29224 }
6c43fab6 29225
c19d1205
ZW
29226 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
29227 vtable entry to be used in the relocation's section offset. */
29228 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29229 reloc->address = fixp->fx_offset;
6c43fab6 29230
c19d1205 29231 return reloc;
6c43fab6
RE
29232}
29233
c19d1205 29234/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 29235
c19d1205
ZW
29236void
29237cons_fix_new_arm (fragS * frag,
29238 int where,
29239 int size,
62ebcb5c
AM
29240 expressionS * exp,
29241 bfd_reloc_code_real_type reloc)
6c43fab6 29242{
c19d1205 29243 int pcrel = 0;
6c43fab6 29244
c19d1205
ZW
29245 /* Pick a reloc.
29246 FIXME: @@ Should look at CPU word size. */
29247 switch (size)
29248 {
29249 case 1:
62ebcb5c 29250 reloc = BFD_RELOC_8;
c19d1205
ZW
29251 break;
29252 case 2:
62ebcb5c 29253 reloc = BFD_RELOC_16;
c19d1205
ZW
29254 break;
29255 case 4:
29256 default:
62ebcb5c 29257 reloc = BFD_RELOC_32;
c19d1205
ZW
29258 break;
29259 case 8:
62ebcb5c 29260 reloc = BFD_RELOC_64;
c19d1205
ZW
29261 break;
29262 }
6c43fab6 29263
f0927246
NC
29264#ifdef TE_PE
29265 if (exp->X_op == O_secrel)
29266 {
29267 exp->X_op = O_symbol;
62ebcb5c 29268 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
29269 }
29270#endif
29271
62ebcb5c 29272 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 29273}
6c43fab6 29274
4343666d 29275#if defined (OBJ_COFF)
c19d1205
ZW
29276void
29277arm_validate_fix (fixS * fixP)
6c43fab6 29278{
c19d1205
ZW
29279 /* If the destination of the branch is a defined symbol which does not have
29280 the THUMB_FUNC attribute, then we must be calling a function which has
29281 the (interfacearm) attribute. We look for the Thumb entry point to that
29282 function and change the branch to refer to that function instead. */
29283 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
29284 && fixP->fx_addsy != NULL
29285 && S_IS_DEFINED (fixP->fx_addsy)
29286 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 29287 {
c19d1205 29288 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 29289 }
c19d1205
ZW
29290}
29291#endif
6c43fab6 29292
267bf995 29293
c19d1205
ZW
29294int
29295arm_force_relocation (struct fix * fixp)
29296{
29297#if defined (OBJ_COFF) && defined (TE_PE)
29298 if (fixp->fx_r_type == BFD_RELOC_RVA)
29299 return 1;
29300#endif
6c43fab6 29301
267bf995
RR
29302 /* In case we have a call or a branch to a function in ARM ISA mode from
29303 a thumb function or vice-versa force the relocation. These relocations
29304 are cleared off for some cores that might have blx and simple transformations
29305 are possible. */
29306
29307#ifdef OBJ_ELF
29308 switch (fixp->fx_r_type)
29309 {
29310 case BFD_RELOC_ARM_PCREL_JUMP:
29311 case BFD_RELOC_ARM_PCREL_CALL:
29312 case BFD_RELOC_THUMB_PCREL_BLX:
29313 if (THUMB_IS_FUNC (fixp->fx_addsy))
29314 return 1;
29315 break;
29316
29317 case BFD_RELOC_ARM_PCREL_BLX:
29318 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29319 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29320 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29321 if (ARM_IS_FUNC (fixp->fx_addsy))
29322 return 1;
29323 break;
29324
29325 default:
29326 break;
29327 }
29328#endif
29329
b5884301
PB
29330 /* Resolve these relocations even if the symbol is extern or weak.
29331 Technically this is probably wrong due to symbol preemption.
29332 In practice these relocations do not have enough range to be useful
29333 at dynamic link time, and some code (e.g. in the Linux kernel)
29334 expects these references to be resolved. */
c19d1205
ZW
29335 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
29336 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 29337 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 29338 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
29339 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29340 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
29341 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 29342 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
29343 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
29344 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
29345 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
29346 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
29347 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
29348 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 29349 return 0;
a737bd4d 29350
4962c51a
MS
29351 /* Always leave these relocations for the linker. */
29352 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29353 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29354 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29355 return 1;
29356
f0291e4c
PB
29357 /* Always generate relocations against function symbols. */
29358 if (fixp->fx_r_type == BFD_RELOC_32
29359 && fixp->fx_addsy
29360 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
29361 return 1;
29362
c19d1205 29363 return generic_force_reloc (fixp);
404ff6b5
AH
29364}
29365
0ffdc86c 29366#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
29367/* Relocations against function names must be left unadjusted,
29368 so that the linker can use this information to generate interworking
29369 stubs. The MIPS version of this function
c19d1205
ZW
29370 also prevents relocations that are mips-16 specific, but I do not
29371 know why it does this.
404ff6b5 29372
c19d1205
ZW
29373 FIXME:
29374 There is one other problem that ought to be addressed here, but
29375 which currently is not: Taking the address of a label (rather
29376 than a function) and then later jumping to that address. Such
29377 addresses also ought to have their bottom bit set (assuming that
29378 they reside in Thumb code), but at the moment they will not. */
404ff6b5 29379
c19d1205
ZW
29380bfd_boolean
29381arm_fix_adjustable (fixS * fixP)
404ff6b5 29382{
c19d1205
ZW
29383 if (fixP->fx_addsy == NULL)
29384 return 1;
404ff6b5 29385
e28387c3
PB
29386 /* Preserve relocations against symbols with function type. */
29387 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 29388 return FALSE;
e28387c3 29389
c19d1205
ZW
29390 if (THUMB_IS_FUNC (fixP->fx_addsy)
29391 && fixP->fx_subsy == NULL)
c921be7d 29392 return FALSE;
a737bd4d 29393
c19d1205
ZW
29394 /* We need the symbol name for the VTABLE entries. */
29395 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
29396 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 29397 return FALSE;
404ff6b5 29398
c19d1205
ZW
29399 /* Don't allow symbols to be discarded on GOT related relocs. */
29400 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
29401 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
29402 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
29403 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 29404 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
29405 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
29406 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 29407 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 29408 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 29409 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 29410 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
29411 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
29412 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
29413 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
29414 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
29415 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 29416 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 29417 return FALSE;
a737bd4d 29418
4962c51a
MS
29419 /* Similarly for group relocations. */
29420 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29421 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29422 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 29423 return FALSE;
4962c51a 29424
79947c54
CD
29425 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
29426 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
29427 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29428 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
29429 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
29430 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29431 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
29432 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
29433 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 29434 return FALSE;
79947c54 29435
72d98d16
MG
29436 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
29437 offsets, so keep these symbols. */
29438 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
29439 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
29440 return FALSE;
29441
c921be7d 29442 return TRUE;
a737bd4d 29443}
0ffdc86c
NC
29444#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
29445
29446#ifdef OBJ_ELF
c19d1205
ZW
29447const char *
29448elf32_arm_target_format (void)
404ff6b5 29449{
c19d1205
ZW
29450#ifdef TE_SYMBIAN
29451 return (target_big_endian
29452 ? "elf32-bigarm-symbian"
29453 : "elf32-littlearm-symbian");
29454#elif defined (TE_VXWORKS)
29455 return (target_big_endian
29456 ? "elf32-bigarm-vxworks"
29457 : "elf32-littlearm-vxworks");
b38cadfb
NC
29458#elif defined (TE_NACL)
29459 return (target_big_endian
29460 ? "elf32-bigarm-nacl"
29461 : "elf32-littlearm-nacl");
c19d1205 29462#else
18a20338
CL
29463 if (arm_fdpic)
29464 {
29465 if (target_big_endian)
29466 return "elf32-bigarm-fdpic";
29467 else
29468 return "elf32-littlearm-fdpic";
29469 }
c19d1205 29470 else
18a20338
CL
29471 {
29472 if (target_big_endian)
29473 return "elf32-bigarm";
29474 else
29475 return "elf32-littlearm";
29476 }
c19d1205 29477#endif
404ff6b5
AH
29478}
29479
c19d1205
ZW
29480void
29481armelf_frob_symbol (symbolS * symp,
29482 int * puntp)
404ff6b5 29483{
c19d1205
ZW
29484 elf_frob_symbol (symp, puntp);
29485}
29486#endif
404ff6b5 29487
c19d1205 29488/* MD interface: Finalization. */
a737bd4d 29489
c19d1205
ZW
29490void
29491arm_cleanup (void)
29492{
29493 literal_pool * pool;
a737bd4d 29494
5ee91343
AV
29495 /* Ensure that all the predication blocks are properly closed. */
29496 check_pred_blocks_finished ();
e07e6e58 29497
c19d1205
ZW
29498 for (pool = list_of_pools; pool; pool = pool->next)
29499 {
5f4273c7 29500 /* Put it at the end of the relevant section. */
c19d1205
ZW
29501 subseg_set (pool->section, pool->sub_section);
29502#ifdef OBJ_ELF
29503 arm_elf_change_section ();
29504#endif
29505 s_ltorg (0);
29506 }
404ff6b5
AH
29507}
29508
cd000bff
DJ
29509#ifdef OBJ_ELF
29510/* Remove any excess mapping symbols generated for alignment frags in
29511 SEC. We may have created a mapping symbol before a zero byte
29512 alignment; remove it if there's a mapping symbol after the
29513 alignment. */
29514static void
29515check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
29516 void *dummy ATTRIBUTE_UNUSED)
29517{
29518 segment_info_type *seginfo = seg_info (sec);
29519 fragS *fragp;
29520
29521 if (seginfo == NULL || seginfo->frchainP == NULL)
29522 return;
29523
29524 for (fragp = seginfo->frchainP->frch_root;
29525 fragp != NULL;
29526 fragp = fragp->fr_next)
29527 {
29528 symbolS *sym = fragp->tc_frag_data.last_map;
29529 fragS *next = fragp->fr_next;
29530
29531 /* Variable-sized frags have been converted to fixed size by
29532 this point. But if this was variable-sized to start with,
29533 there will be a fixed-size frag after it. So don't handle
29534 next == NULL. */
29535 if (sym == NULL || next == NULL)
29536 continue;
29537
29538 if (S_GET_VALUE (sym) < next->fr_address)
29539 /* Not at the end of this frag. */
29540 continue;
29541 know (S_GET_VALUE (sym) == next->fr_address);
29542
29543 do
29544 {
29545 if (next->tc_frag_data.first_map != NULL)
29546 {
29547 /* Next frag starts with a mapping symbol. Discard this
29548 one. */
29549 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29550 break;
29551 }
29552
29553 if (next->fr_next == NULL)
29554 {
29555 /* This mapping symbol is at the end of the section. Discard
29556 it. */
29557 know (next->fr_fix == 0 && next->fr_var == 0);
29558 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29559 break;
29560 }
29561
29562 /* As long as we have empty frags without any mapping symbols,
29563 keep looking. */
29564 /* If the next frag is non-empty and does not start with a
29565 mapping symbol, then this mapping symbol is required. */
29566 if (next->fr_address != next->fr_next->fr_address)
29567 break;
29568
29569 next = next->fr_next;
29570 }
29571 while (next != NULL);
29572 }
29573}
29574#endif
29575
c19d1205
ZW
29576/* Adjust the symbol table. This marks Thumb symbols as distinct from
29577 ARM ones. */
404ff6b5 29578
c19d1205
ZW
29579void
29580arm_adjust_symtab (void)
404ff6b5 29581{
c19d1205
ZW
29582#ifdef OBJ_COFF
29583 symbolS * sym;
404ff6b5 29584
c19d1205
ZW
29585 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
29586 {
29587 if (ARM_IS_THUMB (sym))
29588 {
29589 if (THUMB_IS_FUNC (sym))
29590 {
29591 /* Mark the symbol as a Thumb function. */
29592 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
29593 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
29594 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 29595
c19d1205
ZW
29596 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
29597 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
29598 else
29599 as_bad (_("%s: unexpected function type: %d"),
29600 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
29601 }
29602 else switch (S_GET_STORAGE_CLASS (sym))
29603 {
29604 case C_EXT:
29605 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
29606 break;
29607 case C_STAT:
29608 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
29609 break;
29610 case C_LABEL:
29611 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
29612 break;
29613 default:
29614 /* Do nothing. */
29615 break;
29616 }
29617 }
a737bd4d 29618
c19d1205
ZW
29619 if (ARM_IS_INTERWORK (sym))
29620 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 29621 }
c19d1205
ZW
29622#endif
29623#ifdef OBJ_ELF
29624 symbolS * sym;
29625 char bind;
404ff6b5 29626
c19d1205 29627 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 29628 {
c19d1205
ZW
29629 if (ARM_IS_THUMB (sym))
29630 {
29631 elf_symbol_type * elf_sym;
404ff6b5 29632
c19d1205
ZW
29633 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
29634 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 29635
b0796911
PB
29636 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
29637 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
29638 {
29639 /* If it's a .thumb_func, declare it as so,
29640 otherwise tag label as .code 16. */
29641 if (THUMB_IS_FUNC (sym))
39d911fc
TP
29642 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
29643 ST_BRANCH_TO_THUMB);
3ba67470 29644 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
29645 elf_sym->internal_elf_sym.st_info =
29646 ELF_ST_INFO (bind, STT_ARM_16BIT);
29647 }
29648 }
29649 }
cd000bff
DJ
29650
29651 /* Remove any overlapping mapping symbols generated by alignment frags. */
29652 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
29653 /* Now do generic ELF adjustments. */
29654 elf_adjust_symtab ();
c19d1205 29655#endif
404ff6b5
AH
29656}
29657
c19d1205 29658/* MD interface: Initialization. */
404ff6b5 29659
a737bd4d 29660static void
c19d1205 29661set_constant_flonums (void)
a737bd4d 29662{
c19d1205 29663 int i;
404ff6b5 29664
c19d1205
ZW
29665 for (i = 0; i < NUM_FLOAT_VALS; i++)
29666 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
29667 abort ();
a737bd4d 29668}
404ff6b5 29669
3e9e4fcf
JB
29670/* Auto-select Thumb mode if it's the only available instruction set for the
29671 given architecture. */
29672
29673static void
29674autoselect_thumb_from_cpu_variant (void)
29675{
29676 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
29677 opcode_select (16);
29678}
29679
c19d1205
ZW
29680void
29681md_begin (void)
a737bd4d 29682{
c19d1205
ZW
29683 unsigned mach;
29684 unsigned int i;
404ff6b5 29685
c19d1205
ZW
29686 if ( (arm_ops_hsh = hash_new ()) == NULL
29687 || (arm_cond_hsh = hash_new ()) == NULL
5ee91343 29688 || (arm_vcond_hsh = hash_new ()) == NULL
c19d1205
ZW
29689 || (arm_shift_hsh = hash_new ()) == NULL
29690 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 29691 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 29692 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
29693 || (arm_reloc_hsh = hash_new ()) == NULL
29694 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
29695 as_fatal (_("virtual memory exhausted"));
29696
29697 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 29698 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 29699 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 29700 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
5ee91343
AV
29701 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
29702 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
c19d1205 29703 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 29704 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 29705 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 29706 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 29707 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 29708 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 29709 (void *) (v7m_psrs + i));
c19d1205 29710 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 29711 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
29712 for (i = 0;
29713 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
29714 i++)
d3ce72d0 29715 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 29716 (void *) (barrier_opt_names + i));
c19d1205 29717#ifdef OBJ_ELF
3da1d841
NC
29718 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
29719 {
29720 struct reloc_entry * entry = reloc_names + i;
29721
29722 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
29723 /* This makes encode_branch() use the EABI versions of this relocation. */
29724 entry->reloc = BFD_RELOC_UNUSED;
29725
29726 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
29727 }
c19d1205
ZW
29728#endif
29729
29730 set_constant_flonums ();
404ff6b5 29731
c19d1205
ZW
29732 /* Set the cpu variant based on the command-line options. We prefer
29733 -mcpu= over -march= if both are set (as for GCC); and we prefer
29734 -mfpu= over any other way of setting the floating point unit.
29735 Use of legacy options with new options are faulted. */
e74cfd16 29736 if (legacy_cpu)
404ff6b5 29737 {
e74cfd16 29738 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
29739 as_bad (_("use of old and new-style options to set CPU type"));
29740
4d354d8b 29741 selected_arch = *legacy_cpu;
404ff6b5 29742 }
4d354d8b
TP
29743 else if (mcpu_cpu_opt)
29744 {
29745 selected_arch = *mcpu_cpu_opt;
29746 selected_ext = *mcpu_ext_opt;
29747 }
29748 else if (march_cpu_opt)
c168ce07 29749 {
4d354d8b
TP
29750 selected_arch = *march_cpu_opt;
29751 selected_ext = *march_ext_opt;
c168ce07 29752 }
4d354d8b 29753 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 29754
e74cfd16 29755 if (legacy_fpu)
c19d1205 29756 {
e74cfd16 29757 if (mfpu_opt)
c19d1205 29758 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 29759
4d354d8b 29760 selected_fpu = *legacy_fpu;
03b1477f 29761 }
4d354d8b
TP
29762 else if (mfpu_opt)
29763 selected_fpu = *mfpu_opt;
29764 else
03b1477f 29765 {
45eb4c1b
NS
29766#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
29767 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
29768 /* Some environments specify a default FPU. If they don't, infer it
29769 from the processor. */
e74cfd16 29770 if (mcpu_fpu_opt)
4d354d8b 29771 selected_fpu = *mcpu_fpu_opt;
e7da50fa 29772 else if (march_fpu_opt)
4d354d8b 29773 selected_fpu = *march_fpu_opt;
39c2da32 29774#else
4d354d8b 29775 selected_fpu = fpu_default;
39c2da32 29776#endif
03b1477f
RE
29777 }
29778
4d354d8b 29779 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 29780 {
4d354d8b
TP
29781 if (!no_cpu_selected ())
29782 selected_fpu = fpu_default;
03b1477f 29783 else
4d354d8b 29784 selected_fpu = fpu_arch_fpa;
03b1477f
RE
29785 }
29786
ee065d83 29787#ifdef CPU_DEFAULT
4d354d8b 29788 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 29789 {
4d354d8b
TP
29790 selected_arch = cpu_default;
29791 selected_cpu = selected_arch;
ee065d83 29792 }
4d354d8b 29793 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 29794#else
4d354d8b
TP
29795 /* Autodection of feature mode: allow all features in cpu_variant but leave
29796 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
29797 after all instruction have been processed and we can decide what CPU
29798 should be selected. */
29799 if (ARM_FEATURE_ZERO (selected_arch))
29800 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 29801 else
4d354d8b 29802 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 29803#endif
03b1477f 29804
3e9e4fcf
JB
29805 autoselect_thumb_from_cpu_variant ();
29806
e74cfd16 29807 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 29808
f17c130b 29809#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 29810 {
7cc69913
NC
29811 unsigned int flags = 0;
29812
29813#if defined OBJ_ELF
29814 flags = meabi_flags;
d507cf36
PB
29815
29816 switch (meabi_flags)
33a392fb 29817 {
d507cf36 29818 case EF_ARM_EABI_UNKNOWN:
7cc69913 29819#endif
d507cf36
PB
29820 /* Set the flags in the private structure. */
29821 if (uses_apcs_26) flags |= F_APCS26;
29822 if (support_interwork) flags |= F_INTERWORK;
29823 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 29824 if (pic_code) flags |= F_PIC;
e74cfd16 29825 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
29826 flags |= F_SOFT_FLOAT;
29827
d507cf36
PB
29828 switch (mfloat_abi_opt)
29829 {
29830 case ARM_FLOAT_ABI_SOFT:
29831 case ARM_FLOAT_ABI_SOFTFP:
29832 flags |= F_SOFT_FLOAT;
29833 break;
33a392fb 29834
d507cf36
PB
29835 case ARM_FLOAT_ABI_HARD:
29836 if (flags & F_SOFT_FLOAT)
29837 as_bad (_("hard-float conflicts with specified fpu"));
29838 break;
29839 }
03b1477f 29840
e74cfd16
PB
29841 /* Using pure-endian doubles (even if soft-float). */
29842 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 29843 flags |= F_VFP_FLOAT;
f17c130b 29844
fde78edd 29845#if defined OBJ_ELF
e74cfd16 29846 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 29847 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
29848 break;
29849
8cb51566 29850 case EF_ARM_EABI_VER4:
3a4a14e9 29851 case EF_ARM_EABI_VER5:
c19d1205 29852 /* No additional flags to set. */
d507cf36
PB
29853 break;
29854
29855 default:
29856 abort ();
29857 }
7cc69913 29858#endif
b99bd4ef
NC
29859 bfd_set_private_flags (stdoutput, flags);
29860
29861 /* We have run out flags in the COFF header to encode the
29862 status of ATPCS support, so instead we create a dummy,
c19d1205 29863 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
29864 if (atpcs)
29865 {
29866 asection * sec;
29867
29868 sec = bfd_make_section (stdoutput, ".arm.atpcs");
29869
29870 if (sec != NULL)
29871 {
29872 bfd_set_section_flags
29873 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
29874 bfd_set_section_size (stdoutput, sec, 0);
29875 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
29876 }
29877 }
7cc69913 29878 }
f17c130b 29879#endif
b99bd4ef
NC
29880
29881 /* Record the CPU type as well. */
2d447fca
JM
29882 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
29883 mach = bfd_mach_arm_iWMMXt2;
29884 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 29885 mach = bfd_mach_arm_iWMMXt;
e74cfd16 29886 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 29887 mach = bfd_mach_arm_XScale;
e74cfd16 29888 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 29889 mach = bfd_mach_arm_ep9312;
e74cfd16 29890 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 29891 mach = bfd_mach_arm_5TE;
e74cfd16 29892 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 29893 {
e74cfd16 29894 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
29895 mach = bfd_mach_arm_5T;
29896 else
29897 mach = bfd_mach_arm_5;
29898 }
e74cfd16 29899 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 29900 {
e74cfd16 29901 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
29902 mach = bfd_mach_arm_4T;
29903 else
29904 mach = bfd_mach_arm_4;
29905 }
e74cfd16 29906 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 29907 mach = bfd_mach_arm_3M;
e74cfd16
PB
29908 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
29909 mach = bfd_mach_arm_3;
29910 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
29911 mach = bfd_mach_arm_2a;
29912 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
29913 mach = bfd_mach_arm_2;
29914 else
29915 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
29916
29917 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
29918}
29919
c19d1205 29920/* Command line processing. */
b99bd4ef 29921
c19d1205
ZW
29922/* md_parse_option
29923 Invocation line includes a switch not recognized by the base assembler.
29924 See if it's a processor-specific option.
b99bd4ef 29925
c19d1205
ZW
29926 This routine is somewhat complicated by the need for backwards
29927 compatibility (since older releases of gcc can't be changed).
29928 The new options try to make the interface as compatible as
29929 possible with GCC.
b99bd4ef 29930
c19d1205 29931 New options (supported) are:
b99bd4ef 29932
c19d1205
ZW
29933 -mcpu=<cpu name> Assemble for selected processor
29934 -march=<architecture name> Assemble for selected architecture
29935 -mfpu=<fpu architecture> Assemble for selected FPU.
29936 -EB/-mbig-endian Big-endian
29937 -EL/-mlittle-endian Little-endian
29938 -k Generate PIC code
29939 -mthumb Start in Thumb mode
29940 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 29941
278df34e 29942 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 29943 -m[no-]warn-syms Warn when symbols match instructions
267bf995 29944
c19d1205 29945 For now we will also provide support for:
b99bd4ef 29946
c19d1205
ZW
29947 -mapcs-32 32-bit Program counter
29948 -mapcs-26 26-bit Program counter
29949 -macps-float Floats passed in FP registers
29950 -mapcs-reentrant Reentrant code
29951 -matpcs
29952 (sometime these will probably be replaced with -mapcs=<list of options>
29953 and -matpcs=<list of options>)
b99bd4ef 29954
c19d1205
ZW
29955 The remaining options are only supported for back-wards compatibility.
29956 Cpu variants, the arm part is optional:
29957 -m[arm]1 Currently not supported.
29958 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
29959 -m[arm]3 Arm 3 processor
29960 -m[arm]6[xx], Arm 6 processors
29961 -m[arm]7[xx][t][[d]m] Arm 7 processors
29962 -m[arm]8[10] Arm 8 processors
29963 -m[arm]9[20][tdmi] Arm 9 processors
29964 -mstrongarm[110[0]] StrongARM processors
29965 -mxscale XScale processors
29966 -m[arm]v[2345[t[e]]] Arm architectures
29967 -mall All (except the ARM1)
29968 FP variants:
29969 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
29970 -mfpe-old (No float load/store multiples)
29971 -mvfpxd VFP Single precision
29972 -mvfp All VFP
29973 -mno-fpu Disable all floating point instructions
b99bd4ef 29974
c19d1205
ZW
29975 The following CPU names are recognized:
29976 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
29977 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
29978 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
29979 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
29980 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
29981 arm10t arm10e, arm1020t, arm1020e, arm10200e,
29982 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 29983
c19d1205 29984 */
b99bd4ef 29985
c19d1205 29986const char * md_shortopts = "m:k";
b99bd4ef 29987
c19d1205
ZW
29988#ifdef ARM_BI_ENDIAN
29989#define OPTION_EB (OPTION_MD_BASE + 0)
29990#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 29991#else
c19d1205
ZW
29992#if TARGET_BYTES_BIG_ENDIAN
29993#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 29994#else
c19d1205
ZW
29995#define OPTION_EL (OPTION_MD_BASE + 1)
29996#endif
b99bd4ef 29997#endif
845b51d6 29998#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 29999#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 30000
c19d1205 30001struct option md_longopts[] =
b99bd4ef 30002{
c19d1205
ZW
30003#ifdef OPTION_EB
30004 {"EB", no_argument, NULL, OPTION_EB},
30005#endif
30006#ifdef OPTION_EL
30007 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 30008#endif
845b51d6 30009 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
30010#ifdef OBJ_ELF
30011 {"fdpic", no_argument, NULL, OPTION_FDPIC},
30012#endif
c19d1205
ZW
30013 {NULL, no_argument, NULL, 0}
30014};
b99bd4ef 30015
c19d1205 30016size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 30017
c19d1205 30018struct arm_option_table
b99bd4ef 30019{
0198d5e6
TC
30020 const char * option; /* Option name to match. */
30021 const char * help; /* Help information. */
30022 int * var; /* Variable to change. */
30023 int value; /* What to change it to. */
30024 const char * deprecated; /* If non-null, print this message. */
c19d1205 30025};
b99bd4ef 30026
c19d1205
ZW
30027struct arm_option_table arm_opts[] =
30028{
30029 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
30030 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
30031 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
30032 &support_interwork, 1, NULL},
30033 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
30034 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
30035 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
30036 1, NULL},
30037 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
30038 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
30039 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
30040 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
30041 NULL},
b99bd4ef 30042
c19d1205
ZW
30043 /* These are recognized by the assembler, but have no affect on code. */
30044 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
30045 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
30046
30047 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
30048 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
30049 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
30050 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
30051 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
30052 {NULL, NULL, NULL, 0, NULL}
30053};
30054
30055struct arm_legacy_option_table
30056{
0198d5e6
TC
30057 const char * option; /* Option name to match. */
30058 const arm_feature_set ** var; /* Variable to change. */
30059 const arm_feature_set value; /* What to change it to. */
30060 const char * deprecated; /* If non-null, print this message. */
e74cfd16 30061};
b99bd4ef 30062
e74cfd16
PB
30063const struct arm_legacy_option_table arm_legacy_opts[] =
30064{
c19d1205
ZW
30065 /* DON'T add any new processors to this list -- we want the whole list
30066 to go away... Add them to the processors table instead. */
e74cfd16
PB
30067 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30068 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30069 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30070 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30071 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30072 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30073 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30074 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30075 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30076 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30077 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30078 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30079 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30080 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30081 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30082 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30083 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30084 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30085 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30086 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30087 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30088 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30089 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30090 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30091 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30092 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30093 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30094 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30095 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30096 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30097 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30098 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30099 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30100 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30101 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30102 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30103 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30104 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30105 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30106 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30107 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30108 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30109 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30110 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30111 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30112 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30113 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30114 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30115 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30116 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30117 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30118 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30119 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30120 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30121 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30122 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30123 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30124 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30125 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30126 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30127 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30128 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30129 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30130 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30131 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30132 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30133 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30134 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30135 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
30136 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30137 N_("use -mcpu=strongarm110")},
e74cfd16 30138 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30139 N_("use -mcpu=strongarm1100")},
e74cfd16 30140 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 30141 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
30142 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
30143 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
30144 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 30145
c19d1205 30146 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
30147 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30148 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30149 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30150 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30151 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30152 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30153 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30154 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30155 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30156 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30157 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30158 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30159 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30160 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30161 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30162 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30163 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30164 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 30165
c19d1205 30166 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
30167 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
30168 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
30169 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
30170 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 30171 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 30172
e74cfd16 30173 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 30174};
7ed4c4c5 30175
c19d1205 30176struct arm_cpu_option_table
7ed4c4c5 30177{
0198d5e6
TC
30178 const char * name;
30179 size_t name_len;
30180 const arm_feature_set value;
30181 const arm_feature_set ext;
c19d1205
ZW
30182 /* For some CPUs we assume an FPU unless the user explicitly sets
30183 -mfpu=... */
0198d5e6 30184 const arm_feature_set default_fpu;
ee065d83
PB
30185 /* The canonical name of the CPU, or NULL to use NAME converted to upper
30186 case. */
0198d5e6 30187 const char * canonical_name;
c19d1205 30188};
7ed4c4c5 30189
c19d1205
ZW
30190/* This list should, at a minimum, contain all the cpu names
30191 recognized by GCC. */
996b5569 30192#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 30193
e74cfd16 30194static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 30195{
996b5569
TP
30196 ARM_CPU_OPT ("all", NULL, ARM_ANY,
30197 ARM_ARCH_NONE,
30198 FPU_ARCH_FPA),
30199 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
30200 ARM_ARCH_NONE,
30201 FPU_ARCH_FPA),
30202 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
30203 ARM_ARCH_NONE,
30204 FPU_ARCH_FPA),
30205 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
30206 ARM_ARCH_NONE,
30207 FPU_ARCH_FPA),
30208 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
30209 ARM_ARCH_NONE,
30210 FPU_ARCH_FPA),
30211 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
30212 ARM_ARCH_NONE,
30213 FPU_ARCH_FPA),
30214 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
30215 ARM_ARCH_NONE,
30216 FPU_ARCH_FPA),
30217 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
30218 ARM_ARCH_NONE,
30219 FPU_ARCH_FPA),
30220 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
30221 ARM_ARCH_NONE,
30222 FPU_ARCH_FPA),
30223 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
30224 ARM_ARCH_NONE,
30225 FPU_ARCH_FPA),
30226 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
30227 ARM_ARCH_NONE,
30228 FPU_ARCH_FPA),
30229 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
30230 ARM_ARCH_NONE,
30231 FPU_ARCH_FPA),
30232 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
30233 ARM_ARCH_NONE,
30234 FPU_ARCH_FPA),
30235 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
30236 ARM_ARCH_NONE,
30237 FPU_ARCH_FPA),
30238 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
30239 ARM_ARCH_NONE,
30240 FPU_ARCH_FPA),
30241 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
30242 ARM_ARCH_NONE,
30243 FPU_ARCH_FPA),
30244 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
30245 ARM_ARCH_NONE,
30246 FPU_ARCH_FPA),
30247 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
30248 ARM_ARCH_NONE,
30249 FPU_ARCH_FPA),
30250 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
30251 ARM_ARCH_NONE,
30252 FPU_ARCH_FPA),
30253 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
30254 ARM_ARCH_NONE,
30255 FPU_ARCH_FPA),
30256 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
30257 ARM_ARCH_NONE,
30258 FPU_ARCH_FPA),
30259 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
30260 ARM_ARCH_NONE,
30261 FPU_ARCH_FPA),
30262 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
30263 ARM_ARCH_NONE,
30264 FPU_ARCH_FPA),
30265 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
30266 ARM_ARCH_NONE,
30267 FPU_ARCH_FPA),
30268 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
30269 ARM_ARCH_NONE,
30270 FPU_ARCH_FPA),
30271 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
30272 ARM_ARCH_NONE,
30273 FPU_ARCH_FPA),
30274 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
30275 ARM_ARCH_NONE,
30276 FPU_ARCH_FPA),
30277 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
30278 ARM_ARCH_NONE,
30279 FPU_ARCH_FPA),
30280 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
30281 ARM_ARCH_NONE,
30282 FPU_ARCH_FPA),
30283 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
30284 ARM_ARCH_NONE,
30285 FPU_ARCH_FPA),
30286 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
30287 ARM_ARCH_NONE,
30288 FPU_ARCH_FPA),
30289 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
30290 ARM_ARCH_NONE,
30291 FPU_ARCH_FPA),
30292 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
30293 ARM_ARCH_NONE,
30294 FPU_ARCH_FPA),
30295 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
30296 ARM_ARCH_NONE,
30297 FPU_ARCH_FPA),
30298 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
30299 ARM_ARCH_NONE,
30300 FPU_ARCH_FPA),
30301 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
30302 ARM_ARCH_NONE,
30303 FPU_ARCH_FPA),
30304 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
30305 ARM_ARCH_NONE,
30306 FPU_ARCH_FPA),
30307 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
30308 ARM_ARCH_NONE,
30309 FPU_ARCH_FPA),
30310 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
30311 ARM_ARCH_NONE,
30312 FPU_ARCH_FPA),
30313 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
30314 ARM_ARCH_NONE,
30315 FPU_ARCH_FPA),
30316 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
30317 ARM_ARCH_NONE,
30318 FPU_ARCH_FPA),
30319 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
30320 ARM_ARCH_NONE,
30321 FPU_ARCH_FPA),
30322 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
30323 ARM_ARCH_NONE,
30324 FPU_ARCH_FPA),
30325 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
30326 ARM_ARCH_NONE,
30327 FPU_ARCH_FPA),
30328 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
30329 ARM_ARCH_NONE,
30330 FPU_ARCH_FPA),
30331 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
30332 ARM_ARCH_NONE,
30333 FPU_ARCH_FPA),
30334
c19d1205
ZW
30335 /* For V5 or later processors we default to using VFP; but the user
30336 should really set the FPU type explicitly. */
996b5569
TP
30337 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
30338 ARM_ARCH_NONE,
30339 FPU_ARCH_VFP_V2),
30340 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
30341 ARM_ARCH_NONE,
30342 FPU_ARCH_VFP_V2),
30343 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30344 ARM_ARCH_NONE,
30345 FPU_ARCH_VFP_V2),
30346 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30347 ARM_ARCH_NONE,
30348 FPU_ARCH_VFP_V2),
30349 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
30350 ARM_ARCH_NONE,
30351 FPU_ARCH_VFP_V2),
30352 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
30353 ARM_ARCH_NONE,
30354 FPU_ARCH_VFP_V2),
30355 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
30356 ARM_ARCH_NONE,
30357 FPU_ARCH_VFP_V2),
30358 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
30359 ARM_ARCH_NONE,
30360 FPU_ARCH_VFP_V2),
30361 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
30362 ARM_ARCH_NONE,
30363 FPU_ARCH_VFP_V2),
30364 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
30365 ARM_ARCH_NONE,
30366 FPU_ARCH_VFP_V2),
30367 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
30368 ARM_ARCH_NONE,
30369 FPU_ARCH_VFP_V2),
30370 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
30371 ARM_ARCH_NONE,
30372 FPU_ARCH_VFP_V2),
30373 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
30374 ARM_ARCH_NONE,
30375 FPU_ARCH_VFP_V1),
30376 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
30377 ARM_ARCH_NONE,
30378 FPU_ARCH_VFP_V1),
30379 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
30380 ARM_ARCH_NONE,
30381 FPU_ARCH_VFP_V2),
30382 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
30383 ARM_ARCH_NONE,
30384 FPU_ARCH_VFP_V2),
30385 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
30386 ARM_ARCH_NONE,
30387 FPU_ARCH_VFP_V1),
30388 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
30389 ARM_ARCH_NONE,
30390 FPU_ARCH_VFP_V2),
30391 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
30392 ARM_ARCH_NONE,
30393 FPU_ARCH_VFP_V2),
30394 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
30395 ARM_ARCH_NONE,
30396 FPU_ARCH_VFP_V2),
30397 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
30398 ARM_ARCH_NONE,
30399 FPU_ARCH_VFP_V2),
30400 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
30401 ARM_ARCH_NONE,
30402 FPU_ARCH_VFP_V2),
30403 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
30404 ARM_ARCH_NONE,
30405 FPU_ARCH_VFP_V2),
30406 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
30407 ARM_ARCH_NONE,
30408 FPU_ARCH_VFP_V2),
30409 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
30410 ARM_ARCH_NONE,
30411 FPU_ARCH_VFP_V2),
30412 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
30413 ARM_ARCH_NONE,
30414 FPU_ARCH_VFP_V2),
30415 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
30416 ARM_ARCH_NONE,
30417 FPU_NONE),
30418 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
30419 ARM_ARCH_NONE,
30420 FPU_NONE),
30421 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
30422 ARM_ARCH_NONE,
30423 FPU_ARCH_VFP_V2),
30424 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
30425 ARM_ARCH_NONE,
30426 FPU_ARCH_VFP_V2),
30427 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
30428 ARM_ARCH_NONE,
30429 FPU_ARCH_VFP_V2),
30430 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
30431 ARM_ARCH_NONE,
30432 FPU_NONE),
30433 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
30434 ARM_ARCH_NONE,
30435 FPU_NONE),
30436 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
30437 ARM_ARCH_NONE,
30438 FPU_ARCH_VFP_V2),
30439 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
30440 ARM_ARCH_NONE,
30441 FPU_NONE),
30442 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
30443 ARM_ARCH_NONE,
30444 FPU_ARCH_VFP_V2),
30445 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
30446 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30447 FPU_NONE),
30448 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
30449 ARM_ARCH_NONE,
30450 FPU_ARCH_NEON_VFP_V4),
30451 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
30452 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
30453 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30454 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
30455 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30456 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30457 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
30458 ARM_ARCH_NONE,
30459 FPU_ARCH_NEON_VFP_V4),
30460 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
30461 ARM_ARCH_NONE,
30462 FPU_ARCH_NEON_VFP_V4),
30463 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
30464 ARM_ARCH_NONE,
30465 FPU_ARCH_NEON_VFP_V4),
30466 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
30467 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30468 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30469 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
30470 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30471 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30472 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
30473 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30474 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
30475 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
30476 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 30477 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
30478 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
30479 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30480 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30481 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
30482 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30483 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30484 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
30485 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30486 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
30487 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
30488 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 30489 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 30490 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
30491 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30492 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
ef8df4ca
KT
30493 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
30494 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30495 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
30496 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
30497 ARM_ARCH_NONE,
30498 FPU_NONE),
30499 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
30500 ARM_ARCH_NONE,
30501 FPU_ARCH_VFP_V3D16),
30502 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
30503 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30504 FPU_NONE),
30505 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
30506 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30507 FPU_ARCH_VFP_V3D16),
30508 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
30509 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30510 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
30511 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
30512 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30513 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
30514 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
30515 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30516 FPU_NONE),
30517 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
30518 ARM_ARCH_NONE,
30519 FPU_NONE),
30520 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
30521 ARM_ARCH_NONE,
30522 FPU_NONE),
30523 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
30524 ARM_ARCH_NONE,
30525 FPU_NONE),
30526 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
30527 ARM_ARCH_NONE,
30528 FPU_NONE),
30529 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
30530 ARM_ARCH_NONE,
30531 FPU_NONE),
30532 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
30533 ARM_ARCH_NONE,
30534 FPU_NONE),
30535 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
30536 ARM_ARCH_NONE,
30537 FPU_NONE),
30538 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
30539 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30540 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
30541 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
30542 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30543 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
c19d1205 30544 /* ??? XSCALE is really an architecture. */
996b5569
TP
30545 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
30546 ARM_ARCH_NONE,
30547 FPU_ARCH_VFP_V2),
30548
c19d1205 30549 /* ??? iwmmxt is not a processor. */
996b5569
TP
30550 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
30551 ARM_ARCH_NONE,
30552 FPU_ARCH_VFP_V2),
30553 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
30554 ARM_ARCH_NONE,
30555 FPU_ARCH_VFP_V2),
30556 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
30557 ARM_ARCH_NONE,
30558 FPU_ARCH_VFP_V2),
30559
0198d5e6 30560 /* Maverick. */
996b5569
TP
30561 ARM_CPU_OPT ("ep9312", "ARM920T",
30562 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
30563 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
30564
da4339ed 30565 /* Marvell processors. */
996b5569
TP
30566 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
30567 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30568 FPU_ARCH_VFP_V3D16),
30569 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
30570 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30571 FPU_ARCH_NEON_VFP_V4),
da4339ed 30572
996b5569
TP
30573 /* APM X-Gene family. */
30574 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
30575 ARM_ARCH_NONE,
30576 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30577 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
30578 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30579 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30580
30581 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 30582};
f3bad469 30583#undef ARM_CPU_OPT
7ed4c4c5 30584
34ef62f4
AV
30585struct arm_ext_table
30586{
30587 const char * name;
30588 size_t name_len;
30589 const arm_feature_set merge;
30590 const arm_feature_set clear;
30591};
30592
c19d1205 30593struct arm_arch_option_table
7ed4c4c5 30594{
34ef62f4
AV
30595 const char * name;
30596 size_t name_len;
30597 const arm_feature_set value;
30598 const arm_feature_set default_fpu;
30599 const struct arm_ext_table * ext_table;
30600};
30601
30602/* Used to add support for +E and +noE extension. */
30603#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
30604/* Used to add support for a +E extension. */
30605#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
30606/* Used to add support for a +noE extension. */
30607#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
30608
30609#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
30610 ~0 & ~FPU_ENDIAN_PURE)
30611
30612static const struct arm_ext_table armv5te_ext_table[] =
30613{
30614 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
30615 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30616};
30617
30618static const struct arm_ext_table armv7_ext_table[] =
30619{
30620 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30621 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30622};
30623
30624static const struct arm_ext_table armv7ve_ext_table[] =
30625{
30626 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
30627 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
30628 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30629 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30630 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30631 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
30632 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30633
30634 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
30635 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30636
30637 /* Aliases for +simd. */
30638 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30639
30640 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30641 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30642 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30643
30644 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30645};
30646
30647static const struct arm_ext_table armv7a_ext_table[] =
30648{
30649 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30650 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30651 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30652 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30653 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30654 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
30655 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30656
30657 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
30658 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30659
30660 /* Aliases for +simd. */
30661 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30662 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30663
30664 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30665 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30666
30667 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
30668 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
30669 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30670};
30671
30672static const struct arm_ext_table armv7r_ext_table[] =
30673{
30674 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
30675 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
30676 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30677 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30678 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
30679 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30680 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
30681 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
30682 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30683};
30684
30685static const struct arm_ext_table armv7em_ext_table[] =
30686{
30687 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
30688 /* Alias for +fp, used to be known as fpv4-sp-d16. */
30689 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
30690 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
30691 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30692 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
30693 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30694};
30695
30696static const struct arm_ext_table armv8a_ext_table[] =
30697{
30698 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30699 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30700 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30701 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30702
30703 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30704 should use the +simd option to turn on FP. */
30705 ARM_REMOVE ("fp", ALL_FP),
30706 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30707 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30708 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30709};
30710
30711
30712static const struct arm_ext_table armv81a_ext_table[] =
30713{
30714 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30715 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30716 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30717
30718 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30719 should use the +simd option to turn on FP. */
30720 ARM_REMOVE ("fp", ALL_FP),
30721 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30722 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30723 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30724};
30725
30726static const struct arm_ext_table armv82a_ext_table[] =
30727{
30728 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30729 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
30730 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
30731 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30732 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30733 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30734
30735 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30736 should use the +simd option to turn on FP. */
30737 ARM_REMOVE ("fp", ALL_FP),
30738 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30739 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30740 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30741};
30742
30743static const struct arm_ext_table armv84a_ext_table[] =
30744{
30745 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30746 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30747 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30748 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30749
30750 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30751 should use the +simd option to turn on FP. */
30752 ARM_REMOVE ("fp", ALL_FP),
30753 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30754 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30755 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30756};
30757
30758static const struct arm_ext_table armv85a_ext_table[] =
30759{
30760 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30761 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30762 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30763 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30764
30765 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30766 should use the +simd option to turn on FP. */
30767 ARM_REMOVE ("fp", ALL_FP),
30768 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30769};
30770
30771static const struct arm_ext_table armv8m_main_ext_table[] =
30772{
30773 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30774 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30775 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
30776 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30777 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30778};
30779
e0991585
AV
30780static const struct arm_ext_table armv8_1m_main_ext_table[] =
30781{
30782 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30783 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30784 ARM_EXT ("fp",
30785 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30786 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
30787 ALL_FP),
30788 ARM_ADD ("fp.dp",
30789 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30790 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
a7ad558c
AV
30791 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
30792 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
30793 ARM_ADD ("mve.fp",
30794 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30795 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
30796 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
e0991585
AV
30797 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30798};
30799
34ef62f4
AV
30800static const struct arm_ext_table armv8r_ext_table[] =
30801{
30802 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30803 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30804 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30805 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30806 ARM_REMOVE ("fp", ALL_FP),
30807 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
30808 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 30809};
7ed4c4c5 30810
c19d1205
ZW
30811/* This list should, at a minimum, contain all the architecture names
30812 recognized by GCC. */
34ef62f4
AV
30813#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
30814#define ARM_ARCH_OPT2(N, V, DF, ext) \
30815 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 30816
e74cfd16 30817static const struct arm_arch_option_table arm_archs[] =
c19d1205 30818{
497d849d
TP
30819 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
30820 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
30821 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
30822 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
30823 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
30824 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
30825 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
30826 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
30827 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
30828 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
30829 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
30830 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
30831 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
30832 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
30833 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
30834 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
30835 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
30836 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30837 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30838 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
30839 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
30840 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
30841 kept to preserve existing behaviour. */
34ef62f4
AV
30842 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
30843 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
30844 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
30845 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
30846 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
30847 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
30848 kept to preserve existing behaviour. */
34ef62f4
AV
30849 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
30850 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
30851 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
30852 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 30853 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
30854 /* The official spelling of the ARMv7 profile variants is the dashed form.
30855 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
30856 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
30857 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
30858 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 30859 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
30860 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
30861 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 30862 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 30863 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 30864 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
30865 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
30866 armv8m_main),
e0991585
AV
30867 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
30868 armv8_1m_main),
34ef62f4
AV
30869 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
30870 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
30871 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
30872 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
30873 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
30874 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
30875 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
497d849d
TP
30876 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
30877 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
30878 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 30879 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 30880};
f3bad469 30881#undef ARM_ARCH_OPT
7ed4c4c5 30882
69133863 30883/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 30884
69133863 30885struct arm_option_extension_value_table
c19d1205 30886{
0198d5e6
TC
30887 const char * name;
30888 size_t name_len;
30889 const arm_feature_set merge_value;
30890 const arm_feature_set clear_value;
d942732e
TP
30891 /* List of architectures for which an extension is available. ARM_ARCH_NONE
30892 indicates that an extension is available for all architectures while
30893 ARM_ANY marks an empty entry. */
0198d5e6 30894 const arm_feature_set allowed_archs[2];
c19d1205 30895};
7ed4c4c5 30896
0198d5e6
TC
30897/* The following table must be in alphabetical order with a NULL last entry. */
30898
d942732e
TP
30899#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
30900#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 30901
34ef62f4
AV
30902/* DEPRECATED: Refrain from using this table to add any new extensions, instead
30903 use the context sensitive approach using arm_ext_table's. */
69133863 30904static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 30905{
823d2571
TG
30906 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30907 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 30908 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
30909 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
30910 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
30911 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
30912 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
30913 ARM_ARCH_V8_2A),
15afaa63
TP
30914 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30915 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30916 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
30917 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
30918 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
30919 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30920 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30921 ARM_ARCH_V8_2A),
01f48020
TC
30922 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30923 | ARM_EXT2_FP16_FML),
30924 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
30925 | ARM_EXT2_FP16_FML),
30926 ARM_ARCH_V8_2A),
d942732e 30927 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 30928 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
30929 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
30930 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
30931 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
30932 Thumb divide instruction. Due to this having the same name as the
30933 previous entry, this will be ignored when doing command-line parsing and
30934 only considered by build attribute selection code. */
30935 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
30936 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
30937 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 30938 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 30939 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 30940 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 30941 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 30942 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
30943 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
30944 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 30945 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
30946 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
30947 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
30948 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
30949 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
30950 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
30951 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
30952 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 30953 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
30954 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
30955 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
30956 ARM_ARCH_V8A),
4d1464f2
MW
30957 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
30958 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 30959 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
30960 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
30961 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 30962 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
30963 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
30964 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
30965 ARM_ARCH_V8A),
d942732e 30966 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 30967 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
30968 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
30969 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
30970 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
30971 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
30972 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
30973 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
30974 | ARM_EXT_DIV),
30975 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
30976 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
30977 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
30978 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
30979 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 30980};
f3bad469 30981#undef ARM_EXT_OPT
69133863
MGD
30982
30983/* ISA floating-point and Advanced SIMD extensions. */
30984struct arm_option_fpu_value_table
30985{
0198d5e6
TC
30986 const char * name;
30987 const arm_feature_set value;
c19d1205 30988};
7ed4c4c5 30989
c19d1205
ZW
30990/* This list should, at a minimum, contain all the fpu names
30991 recognized by GCC. */
69133863 30992static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
30993{
30994 {"softfpa", FPU_NONE},
30995 {"fpe", FPU_ARCH_FPE},
30996 {"fpe2", FPU_ARCH_FPE},
30997 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
30998 {"fpa", FPU_ARCH_FPA},
30999 {"fpa10", FPU_ARCH_FPA},
31000 {"fpa11", FPU_ARCH_FPA},
31001 {"arm7500fe", FPU_ARCH_FPA},
31002 {"softvfp", FPU_ARCH_VFP},
31003 {"softvfp+vfp", FPU_ARCH_VFP_V2},
31004 {"vfp", FPU_ARCH_VFP_V2},
31005 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 31006 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
31007 {"vfp10", FPU_ARCH_VFP_V2},
31008 {"vfp10-r0", FPU_ARCH_VFP_V1},
31009 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
31010 {"vfpv2", FPU_ARCH_VFP_V2},
31011 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 31012 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 31013 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
31014 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
31015 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
31016 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
31017 {"arm1020t", FPU_ARCH_VFP_V1},
31018 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 31019 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
31020 {"arm1136jf-s", FPU_ARCH_VFP_V2},
31021 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 31022 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 31023 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 31024 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
31025 {"vfpv4", FPU_ARCH_VFP_V4},
31026 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 31027 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
31028 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
31029 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 31030 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
31031 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
31032 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
31033 {"crypto-neon-fp-armv8",
31034 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 31035 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
31036 {"crypto-neon-fp-armv8.1",
31037 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
31038 {NULL, ARM_ARCH_NONE}
31039};
31040
31041struct arm_option_value_table
31042{
e0471c16 31043 const char *name;
e74cfd16 31044 long value;
c19d1205 31045};
7ed4c4c5 31046
e74cfd16 31047static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
31048{
31049 {"hard", ARM_FLOAT_ABI_HARD},
31050 {"softfp", ARM_FLOAT_ABI_SOFTFP},
31051 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 31052 {NULL, 0}
c19d1205 31053};
7ed4c4c5 31054
c19d1205 31055#ifdef OBJ_ELF
3a4a14e9 31056/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 31057static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
31058{
31059 {"gnu", EF_ARM_EABI_UNKNOWN},
31060 {"4", EF_ARM_EABI_VER4},
3a4a14e9 31061 {"5", EF_ARM_EABI_VER5},
e74cfd16 31062 {NULL, 0}
c19d1205
ZW
31063};
31064#endif
7ed4c4c5 31065
c19d1205
ZW
31066struct arm_long_option_table
31067{
0198d5e6 31068 const char * option; /* Substring to match. */
e0471c16 31069 const char * help; /* Help information. */
17b9d67d 31070 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 31071 const char * deprecated; /* If non-null, print this message. */
c19d1205 31072};
7ed4c4c5 31073
c921be7d 31074static bfd_boolean
c168ce07 31075arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
31076 arm_feature_set *ext_set,
31077 const struct arm_ext_table *ext_table)
7ed4c4c5 31078{
69133863 31079 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
31080 extensions being added before being removed. We achieve this by having
31081 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 31082 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 31083 or removing it (0) and only allowing it to change in the order
69133863
MGD
31084 -1 -> 1 -> 0. */
31085 const struct arm_option_extension_value_table * opt = NULL;
d942732e 31086 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
31087 int adding_value = -1;
31088
c19d1205 31089 while (str != NULL && *str != 0)
7ed4c4c5 31090 {
82b8a785 31091 const char *ext;
f3bad469 31092 size_t len;
7ed4c4c5 31093
c19d1205
ZW
31094 if (*str != '+')
31095 {
31096 as_bad (_("invalid architectural extension"));
c921be7d 31097 return FALSE;
c19d1205 31098 }
7ed4c4c5 31099
c19d1205
ZW
31100 str++;
31101 ext = strchr (str, '+');
7ed4c4c5 31102
c19d1205 31103 if (ext != NULL)
f3bad469 31104 len = ext - str;
c19d1205 31105 else
f3bad469 31106 len = strlen (str);
7ed4c4c5 31107
f3bad469 31108 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
31109 {
31110 if (adding_value != 0)
31111 {
31112 adding_value = 0;
31113 opt = arm_extensions;
31114 }
31115
f3bad469 31116 len -= 2;
69133863
MGD
31117 str += 2;
31118 }
f3bad469 31119 else if (len > 0)
69133863
MGD
31120 {
31121 if (adding_value == -1)
31122 {
31123 adding_value = 1;
31124 opt = arm_extensions;
31125 }
31126 else if (adding_value != 1)
31127 {
31128 as_bad (_("must specify extensions to add before specifying "
31129 "those to remove"));
31130 return FALSE;
31131 }
31132 }
31133
f3bad469 31134 if (len == 0)
c19d1205
ZW
31135 {
31136 as_bad (_("missing architectural extension"));
c921be7d 31137 return FALSE;
c19d1205 31138 }
7ed4c4c5 31139
69133863
MGD
31140 gas_assert (adding_value != -1);
31141 gas_assert (opt != NULL);
31142
34ef62f4
AV
31143 if (ext_table != NULL)
31144 {
31145 const struct arm_ext_table * ext_opt = ext_table;
31146 bfd_boolean found = FALSE;
31147 for (; ext_opt->name != NULL; ext_opt++)
31148 if (ext_opt->name_len == len
31149 && strncmp (ext_opt->name, str, len) == 0)
31150 {
31151 if (adding_value)
31152 {
31153 if (ARM_FEATURE_ZERO (ext_opt->merge))
31154 /* TODO: Option not supported. When we remove the
31155 legacy table this case should error out. */
31156 continue;
31157
31158 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
31159 }
31160 else
31161 {
31162 if (ARM_FEATURE_ZERO (ext_opt->clear))
31163 /* TODO: Option not supported. When we remove the
31164 legacy table this case should error out. */
31165 continue;
31166 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
31167 }
31168 found = TRUE;
31169 break;
31170 }
31171 if (found)
31172 {
31173 str = ext;
31174 continue;
31175 }
31176 }
31177
69133863
MGD
31178 /* Scan over the options table trying to find an exact match. */
31179 for (; opt->name != NULL; opt++)
f3bad469 31180 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31181 {
d942732e
TP
31182 int i, nb_allowed_archs =
31183 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 31184 /* Check we can apply the extension to this architecture. */
d942732e
TP
31185 for (i = 0; i < nb_allowed_archs; i++)
31186 {
31187 /* Empty entry. */
31188 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
31189 continue;
c168ce07 31190 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
31191 break;
31192 }
31193 if (i == nb_allowed_archs)
69133863
MGD
31194 {
31195 as_bad (_("extension does not apply to the base architecture"));
31196 return FALSE;
31197 }
31198
31199 /* Add or remove the extension. */
31200 if (adding_value)
4d354d8b 31201 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 31202 else
4d354d8b 31203 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 31204
3d030cdb
TP
31205 /* Allowing Thumb division instructions for ARMv7 in autodetection
31206 rely on this break so that duplicate extensions (extensions
31207 with the same name as a previous extension in the list) are not
31208 considered for command-line parsing. */
c19d1205
ZW
31209 break;
31210 }
7ed4c4c5 31211
c19d1205
ZW
31212 if (opt->name == NULL)
31213 {
69133863
MGD
31214 /* Did we fail to find an extension because it wasn't specified in
31215 alphabetical order, or because it does not exist? */
31216
31217 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 31218 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
31219 break;
31220
31221 if (opt->name == NULL)
31222 as_bad (_("unknown architectural extension `%s'"), str);
31223 else
31224 as_bad (_("architectural extensions must be specified in "
31225 "alphabetical order"));
31226
c921be7d 31227 return FALSE;
c19d1205 31228 }
69133863
MGD
31229 else
31230 {
31231 /* We should skip the extension we've just matched the next time
31232 round. */
31233 opt++;
31234 }
7ed4c4c5 31235
c19d1205
ZW
31236 str = ext;
31237 };
7ed4c4c5 31238
c921be7d 31239 return TRUE;
c19d1205 31240}
7ed4c4c5 31241
c921be7d 31242static bfd_boolean
17b9d67d 31243arm_parse_cpu (const char *str)
7ed4c4c5 31244{
f3bad469 31245 const struct arm_cpu_option_table *opt;
82b8a785 31246 const char *ext = strchr (str, '+');
f3bad469 31247 size_t len;
7ed4c4c5 31248
c19d1205 31249 if (ext != NULL)
f3bad469 31250 len = ext - str;
7ed4c4c5 31251 else
f3bad469 31252 len = strlen (str);
7ed4c4c5 31253
f3bad469 31254 if (len == 0)
7ed4c4c5 31255 {
c19d1205 31256 as_bad (_("missing cpu name `%s'"), str);
c921be7d 31257 return FALSE;
7ed4c4c5
NC
31258 }
31259
c19d1205 31260 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 31261 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31262 {
c168ce07 31263 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
31264 if (mcpu_ext_opt == NULL)
31265 mcpu_ext_opt = XNEW (arm_feature_set);
31266 *mcpu_ext_opt = opt->ext;
e74cfd16 31267 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 31268 if (opt->canonical_name)
ef8e6722
JW
31269 {
31270 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
31271 strcpy (selected_cpu_name, opt->canonical_name);
31272 }
ee065d83
PB
31273 else
31274 {
f3bad469 31275 size_t i;
c921be7d 31276
ef8e6722
JW
31277 if (len >= sizeof selected_cpu_name)
31278 len = (sizeof selected_cpu_name) - 1;
31279
f3bad469 31280 for (i = 0; i < len; i++)
ee065d83
PB
31281 selected_cpu_name[i] = TOUPPER (opt->name[i]);
31282 selected_cpu_name[i] = 0;
31283 }
7ed4c4c5 31284
c19d1205 31285 if (ext != NULL)
34ef62f4 31286 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 31287
c921be7d 31288 return TRUE;
c19d1205 31289 }
7ed4c4c5 31290
c19d1205 31291 as_bad (_("unknown cpu `%s'"), str);
c921be7d 31292 return FALSE;
7ed4c4c5
NC
31293}
31294
c921be7d 31295static bfd_boolean
17b9d67d 31296arm_parse_arch (const char *str)
7ed4c4c5 31297{
e74cfd16 31298 const struct arm_arch_option_table *opt;
82b8a785 31299 const char *ext = strchr (str, '+');
f3bad469 31300 size_t len;
7ed4c4c5 31301
c19d1205 31302 if (ext != NULL)
f3bad469 31303 len = ext - str;
7ed4c4c5 31304 else
f3bad469 31305 len = strlen (str);
7ed4c4c5 31306
f3bad469 31307 if (len == 0)
7ed4c4c5 31308 {
c19d1205 31309 as_bad (_("missing architecture name `%s'"), str);
c921be7d 31310 return FALSE;
7ed4c4c5
NC
31311 }
31312
c19d1205 31313 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 31314 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 31315 {
e74cfd16 31316 march_cpu_opt = &opt->value;
4d354d8b
TP
31317 if (march_ext_opt == NULL)
31318 march_ext_opt = XNEW (arm_feature_set);
31319 *march_ext_opt = arm_arch_none;
e74cfd16 31320 march_fpu_opt = &opt->default_fpu;
5f4273c7 31321 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 31322
c19d1205 31323 if (ext != NULL)
34ef62f4
AV
31324 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
31325 opt->ext_table);
7ed4c4c5 31326
c921be7d 31327 return TRUE;
c19d1205
ZW
31328 }
31329
31330 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 31331 return FALSE;
7ed4c4c5 31332}
eb043451 31333
c921be7d 31334static bfd_boolean
17b9d67d 31335arm_parse_fpu (const char * str)
c19d1205 31336{
69133863 31337 const struct arm_option_fpu_value_table * opt;
b99bd4ef 31338
c19d1205
ZW
31339 for (opt = arm_fpus; opt->name != NULL; opt++)
31340 if (streq (opt->name, str))
31341 {
e74cfd16 31342 mfpu_opt = &opt->value;
c921be7d 31343 return TRUE;
c19d1205 31344 }
b99bd4ef 31345
c19d1205 31346 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 31347 return FALSE;
c19d1205
ZW
31348}
31349
c921be7d 31350static bfd_boolean
17b9d67d 31351arm_parse_float_abi (const char * str)
b99bd4ef 31352{
e74cfd16 31353 const struct arm_option_value_table * opt;
b99bd4ef 31354
c19d1205
ZW
31355 for (opt = arm_float_abis; opt->name != NULL; opt++)
31356 if (streq (opt->name, str))
31357 {
31358 mfloat_abi_opt = opt->value;
c921be7d 31359 return TRUE;
c19d1205 31360 }
cc8a6dd0 31361
c19d1205 31362 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 31363 return FALSE;
c19d1205 31364}
b99bd4ef 31365
c19d1205 31366#ifdef OBJ_ELF
c921be7d 31367static bfd_boolean
17b9d67d 31368arm_parse_eabi (const char * str)
c19d1205 31369{
e74cfd16 31370 const struct arm_option_value_table *opt;
cc8a6dd0 31371
c19d1205
ZW
31372 for (opt = arm_eabis; opt->name != NULL; opt++)
31373 if (streq (opt->name, str))
31374 {
31375 meabi_flags = opt->value;
c921be7d 31376 return TRUE;
c19d1205
ZW
31377 }
31378 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 31379 return FALSE;
c19d1205
ZW
31380}
31381#endif
cc8a6dd0 31382
c921be7d 31383static bfd_boolean
17b9d67d 31384arm_parse_it_mode (const char * str)
e07e6e58 31385{
c921be7d 31386 bfd_boolean ret = TRUE;
e07e6e58
NC
31387
31388 if (streq ("arm", str))
31389 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
31390 else if (streq ("thumb", str))
31391 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
31392 else if (streq ("always", str))
31393 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
31394 else if (streq ("never", str))
31395 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
31396 else
31397 {
31398 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 31399 "arm, thumb, always, or never."), str);
c921be7d 31400 ret = FALSE;
e07e6e58
NC
31401 }
31402
31403 return ret;
31404}
31405
2e6976a8 31406static bfd_boolean
17b9d67d 31407arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
31408{
31409 codecomposer_syntax = TRUE;
31410 arm_comment_chars[0] = ';';
31411 arm_line_separator_chars[0] = 0;
31412 return TRUE;
31413}
31414
c19d1205
ZW
31415struct arm_long_option_table arm_long_opts[] =
31416{
31417 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
31418 arm_parse_cpu, NULL},
31419 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
31420 arm_parse_arch, NULL},
31421 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
31422 arm_parse_fpu, NULL},
31423 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
31424 arm_parse_float_abi, NULL},
31425#ifdef OBJ_ELF
7fac0536 31426 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
31427 arm_parse_eabi, NULL},
31428#endif
e07e6e58
NC
31429 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
31430 arm_parse_it_mode, NULL},
2e6976a8
DG
31431 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
31432 arm_ccs_mode, NULL},
c19d1205
ZW
31433 {NULL, NULL, 0, NULL}
31434};
cc8a6dd0 31435
c19d1205 31436int
17b9d67d 31437md_parse_option (int c, const char * arg)
c19d1205
ZW
31438{
31439 struct arm_option_table *opt;
e74cfd16 31440 const struct arm_legacy_option_table *fopt;
c19d1205 31441 struct arm_long_option_table *lopt;
b99bd4ef 31442
c19d1205 31443 switch (c)
b99bd4ef 31444 {
c19d1205
ZW
31445#ifdef OPTION_EB
31446 case OPTION_EB:
31447 target_big_endian = 1;
31448 break;
31449#endif
cc8a6dd0 31450
c19d1205
ZW
31451#ifdef OPTION_EL
31452 case OPTION_EL:
31453 target_big_endian = 0;
31454 break;
31455#endif
b99bd4ef 31456
845b51d6
PB
31457 case OPTION_FIX_V4BX:
31458 fix_v4bx = TRUE;
31459 break;
31460
18a20338
CL
31461#ifdef OBJ_ELF
31462 case OPTION_FDPIC:
31463 arm_fdpic = TRUE;
31464 break;
31465#endif /* OBJ_ELF */
31466
c19d1205
ZW
31467 case 'a':
31468 /* Listing option. Just ignore these, we don't support additional
31469 ones. */
31470 return 0;
b99bd4ef 31471
c19d1205
ZW
31472 default:
31473 for (opt = arm_opts; opt->option != NULL; opt++)
31474 {
31475 if (c == opt->option[0]
31476 && ((arg == NULL && opt->option[1] == 0)
31477 || streq (arg, opt->option + 1)))
31478 {
c19d1205 31479 /* If the option is deprecated, tell the user. */
278df34e 31480 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
31481 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31482 arg ? arg : "", _(opt->deprecated));
b99bd4ef 31483
c19d1205
ZW
31484 if (opt->var != NULL)
31485 *opt->var = opt->value;
cc8a6dd0 31486
c19d1205
ZW
31487 return 1;
31488 }
31489 }
b99bd4ef 31490
e74cfd16
PB
31491 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
31492 {
31493 if (c == fopt->option[0]
31494 && ((arg == NULL && fopt->option[1] == 0)
31495 || streq (arg, fopt->option + 1)))
31496 {
e74cfd16 31497 /* If the option is deprecated, tell the user. */
278df34e 31498 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
31499 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31500 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
31501
31502 if (fopt->var != NULL)
31503 *fopt->var = &fopt->value;
31504
31505 return 1;
31506 }
31507 }
31508
c19d1205
ZW
31509 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31510 {
31511 /* These options are expected to have an argument. */
31512 if (c == lopt->option[0]
31513 && arg != NULL
31514 && strncmp (arg, lopt->option + 1,
31515 strlen (lopt->option + 1)) == 0)
31516 {
c19d1205 31517 /* If the option is deprecated, tell the user. */
278df34e 31518 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
31519 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
31520 _(lopt->deprecated));
b99bd4ef 31521
c19d1205
ZW
31522 /* Call the sup-option parser. */
31523 return lopt->func (arg + strlen (lopt->option) - 1);
31524 }
31525 }
a737bd4d 31526
c19d1205
ZW
31527 return 0;
31528 }
a394c00f 31529
c19d1205
ZW
31530 return 1;
31531}
a394c00f 31532
c19d1205
ZW
31533void
31534md_show_usage (FILE * fp)
a394c00f 31535{
c19d1205
ZW
31536 struct arm_option_table *opt;
31537 struct arm_long_option_table *lopt;
a394c00f 31538
c19d1205 31539 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 31540
c19d1205
ZW
31541 for (opt = arm_opts; opt->option != NULL; opt++)
31542 if (opt->help != NULL)
31543 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 31544
c19d1205
ZW
31545 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31546 if (lopt->help != NULL)
31547 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 31548
c19d1205
ZW
31549#ifdef OPTION_EB
31550 fprintf (fp, _("\
31551 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
31552#endif
31553
c19d1205
ZW
31554#ifdef OPTION_EL
31555 fprintf (fp, _("\
31556 -EL assemble code for a little-endian cpu\n"));
a737bd4d 31557#endif
845b51d6
PB
31558
31559 fprintf (fp, _("\
31560 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
31561
31562#ifdef OBJ_ELF
31563 fprintf (fp, _("\
31564 --fdpic generate an FDPIC object file\n"));
31565#endif /* OBJ_ELF */
c19d1205 31566}
ee065d83 31567
ee065d83 31568#ifdef OBJ_ELF
0198d5e6 31569
62b3e311
PB
31570typedef struct
31571{
31572 int val;
31573 arm_feature_set flags;
31574} cpu_arch_ver_table;
31575
2c6b98ea
TP
31576/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
31577 chronologically for architectures, with an exception for ARMv6-M and
31578 ARMv6S-M due to legacy reasons. No new architecture should have a
31579 special case. This allows for build attribute selection results to be
31580 stable when new architectures are added. */
62b3e311
PB
31581static const cpu_arch_ver_table cpu_arch_ver[] =
31582{
031254f2
AV
31583 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
31584 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
31585 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
31586 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
31587 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
31588 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
31589 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
31590 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
31591 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
31592 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
31593 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
31594 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
31595 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
31596 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
31597 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
31598 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
31599 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
31600 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
31601 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
31602 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
31603 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
31604 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
31605 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
31606 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
31607
31608 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
31609 always selected build attributes to match those of ARMv6-M
31610 (resp. ARMv6S-M). However, due to these architectures being a strict
31611 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
31612 would be selected when fully respecting chronology of architectures.
31613 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
31614 move them before ARMv7 architectures. */
031254f2
AV
31615 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
31616 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
31617
31618 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
31619 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
31620 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
31621 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
31622 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
31623 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
31624 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
31625 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
31626 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
31627 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
31628 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
31629 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
31630 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
31631 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
31632 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
31633 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
31634 {-1, ARM_ARCH_NONE}
62b3e311
PB
31635};
31636
ee3c0378 31637/* Set an attribute if it has not already been set by the user. */
0198d5e6 31638
ee3c0378
AS
31639static void
31640aeabi_set_attribute_int (int tag, int value)
31641{
31642 if (tag < 1
31643 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31644 || !attributes_set_explicitly[tag])
31645 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
31646}
31647
31648static void
31649aeabi_set_attribute_string (int tag, const char *value)
31650{
31651 if (tag < 1
31652 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31653 || !attributes_set_explicitly[tag])
31654 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
31655}
31656
2c6b98ea
TP
31657/* Return whether features in the *NEEDED feature set are available via
31658 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 31659
2c6b98ea
TP
31660static bfd_boolean
31661have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
31662 const arm_feature_set *needed)
31663{
31664 int i, nb_allowed_archs;
31665 arm_feature_set ext_fset;
31666 const struct arm_option_extension_value_table *opt;
31667
31668 ext_fset = arm_arch_none;
31669 for (opt = arm_extensions; opt->name != NULL; opt++)
31670 {
31671 /* Extension does not provide any feature we need. */
31672 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
31673 continue;
31674
31675 nb_allowed_archs =
31676 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
31677 for (i = 0; i < nb_allowed_archs; i++)
31678 {
31679 /* Empty entry. */
31680 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
31681 break;
31682
31683 /* Extension is available, add it. */
31684 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
31685 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
31686 }
31687 }
31688
31689 /* Can we enable all features in *needed? */
31690 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
31691}
31692
31693/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
31694 a given architecture feature set *ARCH_EXT_FSET including extension feature
31695 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
31696 - if true, check for an exact match of the architecture modulo extensions;
31697 - otherwise, select build attribute value of the first superset
31698 architecture released so that results remains stable when new architectures
31699 are added.
31700 For -march/-mcpu=all the build attribute value of the most featureful
31701 architecture is returned. Tag_CPU_arch_profile result is returned in
31702 PROFILE. */
0198d5e6 31703
2c6b98ea
TP
31704static int
31705get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
31706 const arm_feature_set *ext_fset,
31707 char *profile, int exact_match)
31708{
31709 arm_feature_set arch_fset;
31710 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
31711
31712 /* Select most featureful architecture with all its extensions if building
31713 for -march=all as the feature sets used to set build attributes. */
31714 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
31715 {
31716 /* Force revisiting of decision for each new architecture. */
031254f2 31717 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
31718 *profile = 'A';
31719 return TAG_CPU_ARCH_V8;
31720 }
31721
31722 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
31723
31724 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
31725 {
31726 arm_feature_set known_arch_fset;
31727
31728 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
31729 if (exact_match)
31730 {
31731 /* Base architecture match user-specified architecture and
31732 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
31733 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
31734 {
31735 p_ver_ret = p_ver;
31736 goto found;
31737 }
31738 /* Base architecture match user-specified architecture only
31739 (eg. ARMv6-M in the same case as above). Record it in case we
31740 find a match with above condition. */
31741 else if (p_ver_ret == NULL
31742 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
31743 p_ver_ret = p_ver;
31744 }
31745 else
31746 {
31747
31748 /* Architecture has all features wanted. */
31749 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
31750 {
31751 arm_feature_set added_fset;
31752
31753 /* Compute features added by this architecture over the one
31754 recorded in p_ver_ret. */
31755 if (p_ver_ret != NULL)
31756 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
31757 p_ver_ret->flags);
31758 /* First architecture that match incl. with extensions, or the
31759 only difference in features over the recorded match is
31760 features that were optional and are now mandatory. */
31761 if (p_ver_ret == NULL
31762 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
31763 {
31764 p_ver_ret = p_ver;
31765 goto found;
31766 }
31767 }
31768 else if (p_ver_ret == NULL)
31769 {
31770 arm_feature_set needed_ext_fset;
31771
31772 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
31773
31774 /* Architecture has all features needed when using some
31775 extensions. Record it and continue searching in case there
31776 exist an architecture providing all needed features without
31777 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
31778 OS extension). */
31779 if (have_ext_for_needed_feat_p (&known_arch_fset,
31780 &needed_ext_fset))
31781 p_ver_ret = p_ver;
31782 }
31783 }
31784 }
31785
31786 if (p_ver_ret == NULL)
31787 return -1;
31788
31789found:
31790 /* Tag_CPU_arch_profile. */
31791 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
31792 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
31793 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
31794 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
31795 *profile = 'A';
31796 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
31797 *profile = 'R';
31798 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
31799 *profile = 'M';
31800 else
31801 *profile = '\0';
31802 return p_ver_ret->val;
31803}
31804
ee065d83 31805/* Set the public EABI object attributes. */
0198d5e6 31806
c168ce07 31807static void
ee065d83
PB
31808aeabi_set_public_attributes (void)
31809{
b90d5ba0 31810 char profile = '\0';
2c6b98ea 31811 int arch = -1;
90ec0d68 31812 int virt_sec = 0;
bca38921 31813 int fp16_optional = 0;
2c6b98ea
TP
31814 int skip_exact_match = 0;
31815 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 31816
54bab281
TP
31817 /* Autodetection mode, choose the architecture based the instructions
31818 actually used. */
31819 if (no_cpu_selected ())
31820 {
31821 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 31822
54bab281
TP
31823 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
31824 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 31825
54bab281
TP
31826 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
31827 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 31828
54bab281 31829 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
31830 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
31831 flags_ext = arm_arch_none;
31832 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
31833 selected_ext = flags_ext;
54bab281
TP
31834 selected_cpu = flags;
31835 }
31836 /* Otherwise, choose the architecture based on the capabilities of the
31837 requested cpu. */
31838 else
4d354d8b
TP
31839 {
31840 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
31841 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
31842 flags_ext = selected_ext;
31843 flags = selected_cpu;
31844 }
31845 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 31846
ddd7f988 31847 /* Allow the user to override the reported architecture. */
4d354d8b 31848 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 31849 {
4d354d8b 31850 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 31851 flags_ext = arm_arch_none;
7a1d4c38 31852 }
2c6b98ea 31853 else
4d354d8b 31854 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
31855
31856 /* When this function is run again after relaxation has happened there is no
31857 way to determine whether an architecture or CPU was specified by the user:
31858 - selected_cpu is set above for relaxation to work;
31859 - march_cpu_opt is not set if only -mcpu or .cpu is used;
31860 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
31861 Therefore, if not in -march=all case we first try an exact match and fall
31862 back to autodetection. */
31863 if (!skip_exact_match)
31864 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
31865 if (arch == -1)
31866 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
31867 if (arch == -1)
31868 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 31869
ee065d83
PB
31870 /* Tag_CPU_name. */
31871 if (selected_cpu_name[0])
31872 {
91d6fa6a 31873 char *q;
ee065d83 31874
91d6fa6a
NC
31875 q = selected_cpu_name;
31876 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
31877 {
31878 int i;
5f4273c7 31879
91d6fa6a
NC
31880 q += 4;
31881 for (i = 0; q[i]; i++)
31882 q[i] = TOUPPER (q[i]);
ee065d83 31883 }
91d6fa6a 31884 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 31885 }
62f3b8c8 31886
ee065d83 31887 /* Tag_CPU_arch. */
ee3c0378 31888 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 31889
62b3e311 31890 /* Tag_CPU_arch_profile. */
69239280
MGD
31891 if (profile != '\0')
31892 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 31893
15afaa63 31894 /* Tag_DSP_extension. */
4d354d8b 31895 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 31896 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 31897
2c6b98ea 31898 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 31899 /* Tag_ARM_ISA_use. */
ee3c0378 31900 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 31901 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 31902 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 31903
ee065d83 31904 /* Tag_THUMB_ISA_use. */
ee3c0378 31905 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 31906 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
31907 {
31908 int thumb_isa_use;
31909
31910 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 31911 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
31912 thumb_isa_use = 3;
31913 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
31914 thumb_isa_use = 2;
31915 else
31916 thumb_isa_use = 1;
31917 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
31918 }
62f3b8c8 31919
ee065d83 31920 /* Tag_VFP_arch. */
a715796b
TG
31921 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
31922 aeabi_set_attribute_int (Tag_VFP_arch,
31923 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
31924 ? 7 : 8);
bca38921 31925 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
31926 aeabi_set_attribute_int (Tag_VFP_arch,
31927 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
31928 ? 5 : 6);
31929 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
31930 {
31931 fp16_optional = 1;
31932 aeabi_set_attribute_int (Tag_VFP_arch, 3);
31933 }
ada65aa3 31934 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
31935 {
31936 aeabi_set_attribute_int (Tag_VFP_arch, 4);
31937 fp16_optional = 1;
31938 }
ee3c0378
AS
31939 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
31940 aeabi_set_attribute_int (Tag_VFP_arch, 2);
31941 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 31942 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 31943 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 31944
4547cb56
NC
31945 /* Tag_ABI_HardFP_use. */
31946 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
31947 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
31948 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
31949
ee065d83 31950 /* Tag_WMMX_arch. */
ee3c0378
AS
31951 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
31952 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
31953 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
31954 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 31955
ee3c0378 31956 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
31957 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
31958 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
31959 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
31960 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
31961 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
31962 {
31963 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
31964 {
31965 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
31966 }
31967 else
31968 {
31969 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
31970 fp16_optional = 1;
31971 }
31972 }
fa94de6b 31973
a7ad558c
AV
31974 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
31975 aeabi_set_attribute_int (Tag_MVE_arch, 2);
31976 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
31977 aeabi_set_attribute_int (Tag_MVE_arch, 1);
31978
ee3c0378 31979 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 31980 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 31981 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 31982
69239280
MGD
31983 /* Tag_DIV_use.
31984
31985 We set Tag_DIV_use to two when integer divide instructions have been used
31986 in ARM state, or when Thumb integer divide instructions have been used,
31987 but we have no architecture profile set, nor have we any ARM instructions.
31988
4ed7ed8d
TP
31989 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
31990 by the base architecture.
bca38921 31991
69239280 31992 For new architectures we will have to check these tests. */
031254f2 31993 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
31994 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
31995 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
31996 aeabi_set_attribute_int (Tag_DIV_use, 0);
31997 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
31998 || (profile == '\0'
31999 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
32000 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 32001 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
32002
32003 /* Tag_MP_extension_use. */
32004 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
32005 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
32006
32007 /* Tag Virtualization_use. */
32008 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
32009 virt_sec |= 1;
32010 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
32011 virt_sec |= 2;
32012 if (virt_sec != 0)
32013 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
32014}
32015
c168ce07
TP
32016/* Post relaxation hook. Recompute ARM attributes now that relaxation is
32017 finished and free extension feature bits which will not be used anymore. */
0198d5e6 32018
c168ce07
TP
32019void
32020arm_md_post_relax (void)
32021{
32022 aeabi_set_public_attributes ();
4d354d8b
TP
32023 XDELETE (mcpu_ext_opt);
32024 mcpu_ext_opt = NULL;
32025 XDELETE (march_ext_opt);
32026 march_ext_opt = NULL;
c168ce07
TP
32027}
32028
104d59d1 32029/* Add the default contents for the .ARM.attributes section. */
0198d5e6 32030
ee065d83
PB
32031void
32032arm_md_end (void)
32033{
ee065d83
PB
32034 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
32035 return;
32036
32037 aeabi_set_public_attributes ();
ee065d83 32038}
8463be01 32039#endif /* OBJ_ELF */
ee065d83 32040
ee065d83
PB
32041/* Parse a .cpu directive. */
32042
32043static void
32044s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
32045{
e74cfd16 32046 const struct arm_cpu_option_table *opt;
ee065d83
PB
32047 char *name;
32048 char saved_char;
32049
32050 name = input_line_pointer;
5f4273c7 32051 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32052 input_line_pointer++;
32053 saved_char = *input_line_pointer;
32054 *input_line_pointer = 0;
32055
32056 /* Skip the first "all" entry. */
32057 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
32058 if (streq (opt->name, name))
32059 {
4d354d8b
TP
32060 selected_arch = opt->value;
32061 selected_ext = opt->ext;
32062 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 32063 if (opt->canonical_name)
5f4273c7 32064 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
32065 else
32066 {
32067 int i;
32068 for (i = 0; opt->name[i]; i++)
32069 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 32070
ee065d83
PB
32071 selected_cpu_name[i] = 0;
32072 }
4d354d8b
TP
32073 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32074
ee065d83
PB
32075 *input_line_pointer = saved_char;
32076 demand_empty_rest_of_line ();
32077 return;
32078 }
32079 as_bad (_("unknown cpu `%s'"), name);
32080 *input_line_pointer = saved_char;
32081 ignore_rest_of_line ();
32082}
32083
ee065d83
PB
32084/* Parse a .arch directive. */
32085
32086static void
32087s_arm_arch (int ignored ATTRIBUTE_UNUSED)
32088{
e74cfd16 32089 const struct arm_arch_option_table *opt;
ee065d83
PB
32090 char saved_char;
32091 char *name;
32092
32093 name = input_line_pointer;
5f4273c7 32094 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32095 input_line_pointer++;
32096 saved_char = *input_line_pointer;
32097 *input_line_pointer = 0;
32098
32099 /* Skip the first "all" entry. */
32100 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32101 if (streq (opt->name, name))
32102 {
4d354d8b
TP
32103 selected_arch = opt->value;
32104 selected_ext = arm_arch_none;
32105 selected_cpu = selected_arch;
5f4273c7 32106 strcpy (selected_cpu_name, opt->name);
4d354d8b 32107 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
32108 *input_line_pointer = saved_char;
32109 demand_empty_rest_of_line ();
32110 return;
32111 }
32112
32113 as_bad (_("unknown architecture `%s'\n"), name);
32114 *input_line_pointer = saved_char;
32115 ignore_rest_of_line ();
32116}
32117
7a1d4c38
PB
32118/* Parse a .object_arch directive. */
32119
32120static void
32121s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
32122{
32123 const struct arm_arch_option_table *opt;
32124 char saved_char;
32125 char *name;
32126
32127 name = input_line_pointer;
5f4273c7 32128 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
32129 input_line_pointer++;
32130 saved_char = *input_line_pointer;
32131 *input_line_pointer = 0;
32132
32133 /* Skip the first "all" entry. */
32134 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32135 if (streq (opt->name, name))
32136 {
4d354d8b 32137 selected_object_arch = opt->value;
7a1d4c38
PB
32138 *input_line_pointer = saved_char;
32139 demand_empty_rest_of_line ();
32140 return;
32141 }
32142
32143 as_bad (_("unknown architecture `%s'\n"), name);
32144 *input_line_pointer = saved_char;
32145 ignore_rest_of_line ();
32146}
32147
69133863
MGD
32148/* Parse a .arch_extension directive. */
32149
32150static void
32151s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
32152{
32153 const struct arm_option_extension_value_table *opt;
32154 char saved_char;
32155 char *name;
32156 int adding_value = 1;
32157
32158 name = input_line_pointer;
32159 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32160 input_line_pointer++;
32161 saved_char = *input_line_pointer;
32162 *input_line_pointer = 0;
32163
32164 if (strlen (name) >= 2
32165 && strncmp (name, "no", 2) == 0)
32166 {
32167 adding_value = 0;
32168 name += 2;
32169 }
32170
32171 for (opt = arm_extensions; opt->name != NULL; opt++)
32172 if (streq (opt->name, name))
32173 {
d942732e
TP
32174 int i, nb_allowed_archs =
32175 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
32176 for (i = 0; i < nb_allowed_archs; i++)
32177 {
32178 /* Empty entry. */
4d354d8b 32179 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 32180 continue;
4d354d8b 32181 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
32182 break;
32183 }
32184
32185 if (i == nb_allowed_archs)
69133863
MGD
32186 {
32187 as_bad (_("architectural extension `%s' is not allowed for the "
32188 "current base architecture"), name);
32189 break;
32190 }
32191
32192 if (adding_value)
4d354d8b 32193 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 32194 opt->merge_value);
69133863 32195 else
4d354d8b 32196 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 32197
4d354d8b
TP
32198 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32199 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
32200 *input_line_pointer = saved_char;
32201 demand_empty_rest_of_line ();
3d030cdb
TP
32202 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
32203 on this return so that duplicate extensions (extensions with the
32204 same name as a previous extension in the list) are not considered
32205 for command-line parsing. */
69133863
MGD
32206 return;
32207 }
32208
32209 if (opt->name == NULL)
e673710a 32210 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
32211
32212 *input_line_pointer = saved_char;
32213 ignore_rest_of_line ();
32214}
32215
ee065d83
PB
32216/* Parse a .fpu directive. */
32217
32218static void
32219s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
32220{
69133863 32221 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
32222 char saved_char;
32223 char *name;
32224
32225 name = input_line_pointer;
5f4273c7 32226 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
32227 input_line_pointer++;
32228 saved_char = *input_line_pointer;
32229 *input_line_pointer = 0;
5f4273c7 32230
ee065d83
PB
32231 for (opt = arm_fpus; opt->name != NULL; opt++)
32232 if (streq (opt->name, name))
32233 {
4d354d8b
TP
32234 selected_fpu = opt->value;
32235#ifndef CPU_DEFAULT
32236 if (no_cpu_selected ())
32237 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
32238 else
32239#endif
32240 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
32241 *input_line_pointer = saved_char;
32242 demand_empty_rest_of_line ();
32243 return;
32244 }
32245
32246 as_bad (_("unknown floating point format `%s'\n"), name);
32247 *input_line_pointer = saved_char;
32248 ignore_rest_of_line ();
32249}
ee065d83 32250
794ba86a 32251/* Copy symbol information. */
f31fef98 32252
794ba86a
DJ
32253void
32254arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
32255{
32256 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
32257}
e04befd0 32258
f31fef98 32259#ifdef OBJ_ELF
e04befd0
AS
32260/* Given a symbolic attribute NAME, return the proper integer value.
32261 Returns -1 if the attribute is not known. */
f31fef98 32262
e04befd0
AS
32263int
32264arm_convert_symbolic_attribute (const char *name)
32265{
f31fef98
NC
32266 static const struct
32267 {
32268 const char * name;
32269 const int tag;
32270 }
32271 attribute_table[] =
32272 {
32273 /* When you modify this table you should
32274 also modify the list in doc/c-arm.texi. */
e04befd0 32275#define T(tag) {#tag, tag}
f31fef98
NC
32276 T (Tag_CPU_raw_name),
32277 T (Tag_CPU_name),
32278 T (Tag_CPU_arch),
32279 T (Tag_CPU_arch_profile),
32280 T (Tag_ARM_ISA_use),
32281 T (Tag_THUMB_ISA_use),
75375b3e 32282 T (Tag_FP_arch),
f31fef98
NC
32283 T (Tag_VFP_arch),
32284 T (Tag_WMMX_arch),
32285 T (Tag_Advanced_SIMD_arch),
32286 T (Tag_PCS_config),
32287 T (Tag_ABI_PCS_R9_use),
32288 T (Tag_ABI_PCS_RW_data),
32289 T (Tag_ABI_PCS_RO_data),
32290 T (Tag_ABI_PCS_GOT_use),
32291 T (Tag_ABI_PCS_wchar_t),
32292 T (Tag_ABI_FP_rounding),
32293 T (Tag_ABI_FP_denormal),
32294 T (Tag_ABI_FP_exceptions),
32295 T (Tag_ABI_FP_user_exceptions),
32296 T (Tag_ABI_FP_number_model),
75375b3e 32297 T (Tag_ABI_align_needed),
f31fef98 32298 T (Tag_ABI_align8_needed),
75375b3e 32299 T (Tag_ABI_align_preserved),
f31fef98
NC
32300 T (Tag_ABI_align8_preserved),
32301 T (Tag_ABI_enum_size),
32302 T (Tag_ABI_HardFP_use),
32303 T (Tag_ABI_VFP_args),
32304 T (Tag_ABI_WMMX_args),
32305 T (Tag_ABI_optimization_goals),
32306 T (Tag_ABI_FP_optimization_goals),
32307 T (Tag_compatibility),
32308 T (Tag_CPU_unaligned_access),
75375b3e 32309 T (Tag_FP_HP_extension),
f31fef98
NC
32310 T (Tag_VFP_HP_extension),
32311 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
32312 T (Tag_MPextension_use),
32313 T (Tag_DIV_use),
f31fef98
NC
32314 T (Tag_nodefaults),
32315 T (Tag_also_compatible_with),
32316 T (Tag_conformance),
32317 T (Tag_T2EE_use),
32318 T (Tag_Virtualization_use),
15afaa63 32319 T (Tag_DSP_extension),
a7ad558c 32320 T (Tag_MVE_arch),
cd21e546 32321 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 32322#undef T
f31fef98 32323 };
e04befd0
AS
32324 unsigned int i;
32325
32326 if (name == NULL)
32327 return -1;
32328
f31fef98 32329 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 32330 if (streq (name, attribute_table[i].name))
e04befd0
AS
32331 return attribute_table[i].tag;
32332
32333 return -1;
32334}
267bf995 32335
93ef582d
NC
32336/* Apply sym value for relocations only in the case that they are for
32337 local symbols in the same segment as the fixup and you have the
32338 respective architectural feature for blx and simple switches. */
0198d5e6 32339
267bf995 32340int
93ef582d 32341arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
32342{
32343 if (fixP->fx_addsy
32344 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
32345 /* PR 17444: If the local symbol is in a different section then a reloc
32346 will always be generated for it, so applying the symbol value now
32347 will result in a double offset being stored in the relocation. */
32348 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 32349 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
32350 {
32351 switch (fixP->fx_r_type)
32352 {
32353 case BFD_RELOC_ARM_PCREL_BLX:
32354 case BFD_RELOC_THUMB_PCREL_BRANCH23:
32355 if (ARM_IS_FUNC (fixP->fx_addsy))
32356 return 1;
32357 break;
32358
32359 case BFD_RELOC_ARM_PCREL_CALL:
32360 case BFD_RELOC_THUMB_PCREL_BLX:
32361 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 32362 return 1;
267bf995
RR
32363 break;
32364
32365 default:
32366 break;
32367 }
32368
32369 }
32370 return 0;
32371}
f31fef98 32372#endif /* OBJ_ELF */
This page took 4.134812 seconds and 4 git commands to generate.