]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Add libctf to update-copyright.py
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
b3adc24a 2 Copyright (C) 1994-2020 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b 34#include "opcode/arm.h"
f37164d7 35#include "cpu-arm.h"
f263249b 36
b99bd4ef
NC
37#ifdef OBJ_ELF
38#include "elf/arm.h"
a394c00f 39#include "dw2gencfi.h"
b99bd4ef
NC
40#endif
41
f0927246
NC
42#include "dwarf2dbg.h"
43
7ed4c4c5
NC
44#ifdef OBJ_ELF
45/* Must be at least the size of the largest unwind opcode (currently two). */
46#define ARM_OPCODE_CHUNK_SIZE 8
47
48/* This structure holds the unwinding state. */
49
50static struct
51{
c19d1205
ZW
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
7ed4c4c5 56 /* The segment containing the function. */
c19d1205
ZW
57 segT saved_seg;
58 subsegT saved_subseg;
7ed4c4c5
NC
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
c19d1205
ZW
61 int opcode_count;
62 int opcode_alloc;
7ed4c4c5 63 /* The number of bytes pushed to the stack. */
c19d1205 64 offsetT frame_size;
7ed4c4c5
NC
65 /* We don't add stack adjustment opcodes immediately so that we can merge
66 multiple adjustments. We can also omit the final adjustment
67 when using a frame pointer. */
c19d1205 68 offsetT pending_offset;
7ed4c4c5 69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
7ed4c4c5 73 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 74 unsigned fp_used:1;
7ed4c4c5 75 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 76 unsigned sp_restored:1;
7ed4c4c5
NC
77} unwind;
78
18a20338
CL
79/* Whether --fdpic was given. */
80static int arm_fdpic;
81
8b1ad454
NC
82#endif /* OBJ_ELF */
83
4962c51a
MS
84/* Results from operand parsing worker functions. */
85
86typedef enum
87{
88 PARSE_OPERAND_SUCCESS,
89 PARSE_OPERAND_FAIL,
90 PARSE_OPERAND_FAIL_NO_BACKTRACK
91} parse_operand_result;
92
33a392fb
PB
93enum arm_float_abi
94{
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98};
99
c19d1205 100/* Types of processor to assemble for. */
b99bd4ef 101#ifndef CPU_DEFAULT
8a59fff3 102/* The code that was here used to select a default CPU depending on compiler
fa94de6b 103 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
104 changing gas' default behaviour depending upon the build host.
105
106 If you have a target that requires a default CPU option then the you
107 should define CPU_DEFAULT here. */
b99bd4ef
NC
108#endif
109
e8f8842d
TC
110/* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112static bfd_boolean out_of_range_p (offsetT value, offsetT bits)
113 {
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
117}
118
b99bd4ef 119#ifndef FPU_DEFAULT
c820d418
MM
120# ifdef TE_LINUX
121# define FPU_DEFAULT FPU_ARCH_FPA
122# elif defined (TE_NetBSD)
123# ifdef OBJ_ELF
124# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
125# else
126 /* Legacy a.out format. */
127# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
128# endif
4e7fd91e
PB
129# elif defined (TE_VXWORKS)
130# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
131# else
132 /* For backwards compatibility, default to FPA. */
133# define FPU_DEFAULT FPU_ARCH_FPA
134# endif
135#endif /* ifndef FPU_DEFAULT */
b99bd4ef 136
c19d1205 137#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 138
4d354d8b
TP
139/* Current set of feature bits available (CPU+FPU). Different from
140 selected_cpu + selected_fpu in case of autodetection since the CPU
141 feature bits are then all set. */
e74cfd16 142static arm_feature_set cpu_variant;
4d354d8b
TP
143/* Feature bits used in each execution state. Used to set build attribute
144 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
145static arm_feature_set arm_arch_used;
146static arm_feature_set thumb_arch_used;
b99bd4ef 147
b99bd4ef 148/* Flags stored in private area of BFD structure. */
c19d1205
ZW
149static int uses_apcs_26 = FALSE;
150static int atpcs = FALSE;
b34976b6
AM
151static int support_interwork = FALSE;
152static int uses_apcs_float = FALSE;
c19d1205 153static int pic_code = FALSE;
845b51d6 154static int fix_v4bx = FALSE;
278df34e
NS
155/* Warn on using deprecated features. */
156static int warn_on_deprecated = TRUE;
24f19ccb 157static int warn_on_restrict_it = FALSE;
278df34e 158
2e6976a8
DG
159/* Understand CodeComposer Studio assembly syntax. */
160bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
161
162/* Variables that we set while parsing command-line options. Once all
163 options have been read we re-process these values to set the real
164 assembly flags. */
4d354d8b
TP
165
166/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
167 instead of -mcpu=arm1). */
168static const arm_feature_set *legacy_cpu = NULL;
169static const arm_feature_set *legacy_fpu = NULL;
170
171/* CPU, extension and FPU feature bits selected by -mcpu. */
172static const arm_feature_set *mcpu_cpu_opt = NULL;
173static arm_feature_set *mcpu_ext_opt = NULL;
174static const arm_feature_set *mcpu_fpu_opt = NULL;
175
176/* CPU, extension and FPU feature bits selected by -march. */
177static const arm_feature_set *march_cpu_opt = NULL;
178static arm_feature_set *march_ext_opt = NULL;
179static const arm_feature_set *march_fpu_opt = NULL;
180
181/* Feature bits selected by -mfpu. */
182static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
183
184/* Constants for known architecture features. */
185static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 186static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 187static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
188static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
189static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
190static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
191static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 192#ifdef OBJ_ELF
e74cfd16 193static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 194#endif
e74cfd16
PB
195static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
196
197#ifdef CPU_DEFAULT
198static const arm_feature_set cpu_default = CPU_DEFAULT;
199#endif
200
823d2571 201static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 202static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
203static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
204static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
205static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
206static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
207static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
208static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 209static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
211static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
212static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
213static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
214static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
215static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
216static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
217static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
55e8aae7
SP
218/* Only for compatability of hint instructions. */
219static const arm_feature_set arm_ext_v6k_v6t2 =
220 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
823d2571
TG
221static const arm_feature_set arm_ext_v6_notm =
222 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
223static const arm_feature_set arm_ext_v6_dsp =
224 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
225static const arm_feature_set arm_ext_barrier =
226 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
227static const arm_feature_set arm_ext_msr =
228 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
229static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
230static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
231static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
232static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
164446e0 233static const arm_feature_set arm_ext_v8r = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8R);
69c9e028 234#ifdef OBJ_ELF
e7d39ed3 235static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 236#endif
823d2571 237static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 238static const arm_feature_set arm_ext_m =
173205ca 239 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 240 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
241static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
242static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
243static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
244static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
245static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 246static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 247static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
248static const arm_feature_set arm_ext_v8m_main =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
e12437dc
AV
250static const arm_feature_set arm_ext_v8_1m_main =
251ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
16a1fa25
TP
252/* Instructions in ARMv8-M only found in M profile architectures. */
253static const arm_feature_set arm_ext_v8m_m_only =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
255static const arm_feature_set arm_ext_v6t2_v8m =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
257/* Instructions shared between ARMv8-A and ARMv8-M. */
258static const arm_feature_set arm_ext_atomics =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 260#ifdef OBJ_ELF
15afaa63
TP
261/* DSP instructions Tag_DSP_extension refers to. */
262static const arm_feature_set arm_ext_dsp =
263 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 264#endif
4d1464f2
MW
265static const arm_feature_set arm_ext_ras =
266 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
267/* FP16 instructions. */
268static const arm_feature_set arm_ext_fp16 =
269 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
270static const arm_feature_set arm_ext_fp16_fml =
271 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
272static const arm_feature_set arm_ext_v8_2 =
273 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
274static const arm_feature_set arm_ext_v8_3 =
275 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
7fadb25d
SD
276static const arm_feature_set arm_ext_sb =
277 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
dad0c3bf
SD
278static const arm_feature_set arm_ext_predres =
279 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
aab2c27d
MM
280static const arm_feature_set arm_ext_bf16 =
281 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
616ce08e
MM
282static const arm_feature_set arm_ext_i8mm =
283 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
8b301fbb
MI
284static const arm_feature_set arm_ext_crc =
285 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
4934a27c
MM
286static const arm_feature_set arm_ext_cde =
287 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
288static const arm_feature_set arm_ext_cde0 =
289 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
290static const arm_feature_set arm_ext_cde1 =
291 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
292static const arm_feature_set arm_ext_cde2 =
293 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
294static const arm_feature_set arm_ext_cde3 =
295 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
296static const arm_feature_set arm_ext_cde4 =
297 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
298static const arm_feature_set arm_ext_cde5 =
299 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
300static const arm_feature_set arm_ext_cde6 =
301 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
302static const arm_feature_set arm_ext_cde7 =
303 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
e74cfd16
PB
304
305static const arm_feature_set arm_arch_any = ARM_ANY;
2c6b98ea 306static const arm_feature_set fpu_any = FPU_ANY;
f85d59c3 307static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
308static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
309static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
310
2d447fca 311static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 312 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 313static const arm_feature_set arm_cext_iwmmxt =
823d2571 314 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 315static const arm_feature_set arm_cext_xscale =
823d2571 316 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 317static const arm_feature_set arm_cext_maverick =
823d2571
TG
318 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
319static const arm_feature_set fpu_fpa_ext_v1 =
320 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
321static const arm_feature_set fpu_fpa_ext_v2 =
322 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 323static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
324 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
325static const arm_feature_set fpu_vfp_ext_v1 =
326 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
327static const arm_feature_set fpu_vfp_ext_v2 =
328 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
329static const arm_feature_set fpu_vfp_ext_v3xd =
330 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
331static const arm_feature_set fpu_vfp_ext_v3 =
332 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 333static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
334 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
335static const arm_feature_set fpu_neon_ext_v1 =
336 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 337static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 338 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
a7ad558c 339static const arm_feature_set mve_ext =
2da2eaf4 340 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
a7ad558c 341static const arm_feature_set mve_fp_ext =
2da2eaf4 342 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
5aae9ae9
MM
343/* Note: This has more than one bit set, which means using it with
344 mark_feature_used (which returns if *any* of the bits are set in the current
345 cpu variant) can give surprising results. */
346static const arm_feature_set armv8m_fp =
347 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
69c9e028 348#ifdef OBJ_ELF
823d2571
TG
349static const arm_feature_set fpu_vfp_fp16 =
350 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
351static const arm_feature_set fpu_neon_ext_fma =
352 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 353#endif
823d2571
TG
354static const arm_feature_set fpu_vfp_ext_fma =
355 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 356static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 357 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 358static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 359 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 360static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 361 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 362static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 363 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
d6b4b13e 364static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 365 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
366static const arm_feature_set fpu_neon_ext_dotprod =
367 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 368
33a392fb 369static int mfloat_abi_opt = -1;
4d354d8b
TP
370/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
371 directive. */
372static arm_feature_set selected_arch = ARM_ARCH_NONE;
373/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
374 directive. */
375static arm_feature_set selected_ext = ARM_ARCH_NONE;
376/* Feature bits selected by the last -mcpu/-march or by the combination of the
377 last .cpu/.arch directive .arch_extension directives since that
378 directive. */
e74cfd16 379static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
380/* FPU feature bits selected by the last -mfpu or .fpu directive. */
381static arm_feature_set selected_fpu = FPU_NONE;
382/* Feature bits selected by the last .object_arch directive. */
383static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 384/* Must be long enough to hold any of the names in arm_cpus. */
e20f9590 385static const struct arm_ext_table * selected_ctx_ext_table = NULL;
ef8e6722 386static char selected_cpu_name[20];
8d67f500 387
aacf0b33
KT
388extern FLONUM_TYPE generic_floating_point_number;
389
8d67f500
NC
390/* Return if no cpu was selected on command-line. */
391static bfd_boolean
392no_cpu_selected (void)
393{
823d2571 394 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
395}
396
7cc69913 397#ifdef OBJ_ELF
deeaaff8
DJ
398# ifdef EABI_DEFAULT
399static int meabi_flags = EABI_DEFAULT;
400# else
d507cf36 401static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 402# endif
e1da3f5b 403
ee3c0378
AS
404static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
405
e1da3f5b 406bfd_boolean
5f4273c7 407arm_is_eabi (void)
e1da3f5b
PB
408{
409 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
410}
7cc69913 411#endif
b99bd4ef 412
b99bd4ef 413#ifdef OBJ_ELF
c19d1205 414/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
415symbolS * GOT_symbol;
416#endif
417
b99bd4ef
NC
418/* 0: assemble for ARM,
419 1: assemble for Thumb,
420 2: assemble for Thumb even though target CPU does not support thumb
421 instructions. */
422static int thumb_mode = 0;
8dc2430f
NC
423/* A value distinct from the possible values for thumb_mode that we
424 can use to record whether thumb_mode has been copied into the
425 tc_frag_data field of a frag. */
426#define MODE_RECORDED (1 << 4)
b99bd4ef 427
e07e6e58
NC
428/* Specifies the intrinsic IT insn behavior mode. */
429enum implicit_it_mode
430{
431 IMPLICIT_IT_MODE_NEVER = 0x00,
432 IMPLICIT_IT_MODE_ARM = 0x01,
433 IMPLICIT_IT_MODE_THUMB = 0x02,
434 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
435};
436static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
437
c19d1205
ZW
438/* If unified_syntax is true, we are processing the new unified
439 ARM/Thumb syntax. Important differences from the old ARM mode:
440
441 - Immediate operands do not require a # prefix.
442 - Conditional affixes always appear at the end of the
443 instruction. (For backward compatibility, those instructions
444 that formerly had them in the middle, continue to accept them
445 there.)
446 - The IT instruction may appear, and if it does is validated
447 against subsequent conditional affixes. It does not generate
448 machine code.
449
450 Important differences from the old Thumb mode:
451
452 - Immediate operands do not require a # prefix.
453 - Most of the V6T2 instructions are only available in unified mode.
454 - The .N and .W suffixes are recognized and honored (it is an error
455 if they cannot be honored).
456 - All instructions set the flags if and only if they have an 's' affix.
457 - Conditional affixes may be used. They are validated against
458 preceding IT instructions. Unlike ARM mode, you cannot use a
459 conditional affix except in the scope of an IT instruction. */
460
461static bfd_boolean unified_syntax = FALSE;
b99bd4ef 462
bacebabc
RM
463/* An immediate operand can start with #, and ld*, st*, pld operands
464 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
465 before a [, which can appear as the first operand for pld.
466 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
467const char arm_symbol_chars[] = "#[]{}";
bacebabc 468
5287ad62
JB
469enum neon_el_type
470{
dcbf9037 471 NT_invtype,
5287ad62
JB
472 NT_untyped,
473 NT_integer,
474 NT_float,
475 NT_poly,
476 NT_signed,
aab2c27d 477 NT_bfloat,
dcbf9037 478 NT_unsigned
5287ad62
JB
479};
480
481struct neon_type_el
482{
483 enum neon_el_type type;
484 unsigned size;
485};
486
5aae9ae9 487#define NEON_MAX_TYPE_ELS 5
5287ad62
JB
488
489struct neon_type
490{
491 struct neon_type_el el[NEON_MAX_TYPE_ELS];
492 unsigned elems;
493};
494
5ee91343 495enum pred_instruction_type
e07e6e58 496{
5ee91343
AV
497 OUTSIDE_PRED_INSN,
498 INSIDE_VPT_INSN,
e07e6e58
NC
499 INSIDE_IT_INSN,
500 INSIDE_IT_LAST_INSN,
501 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 502 if inside, should be the last one. */
e07e6e58 503 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 504 i.e. BKPT and NOP. */
5ee91343
AV
505 IT_INSN, /* The IT insn has been parsed. */
506 VPT_INSN, /* The VPT/VPST insn has been parsed. */
35c228db 507 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
5ee91343 508 a predication code. */
4934a27c 509 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
e07e6e58
NC
510};
511
ad6cec43
MGD
512/* The maximum number of operands we need. */
513#define ARM_IT_MAX_OPERANDS 6
e2b0ab59 514#define ARM_IT_MAX_RELOCS 3
ad6cec43 515
b99bd4ef
NC
516struct arm_it
517{
c19d1205 518 const char * error;
b99bd4ef 519 unsigned long instruction;
7af67752
AM
520 unsigned int size;
521 unsigned int size_req;
522 unsigned int cond;
037e8744 523 /* "uncond_value" is set to the value in place of the conditional field in
7af67752 524 unconditional versions of the instruction, or -1u if nothing is
037e8744 525 appropriate. */
7af67752 526 unsigned int uncond_value;
5287ad62 527 struct neon_type vectype;
88714cb8
DG
528 /* This does not indicate an actual NEON instruction, only that
529 the mnemonic accepts neon-style type suffixes. */
530 int is_neon;
0110f2b8
PB
531 /* Set to the opcode if the instruction needs relaxation.
532 Zero if the instruction is not relaxed. */
533 unsigned long relax;
b99bd4ef
NC
534 struct
535 {
536 bfd_reloc_code_real_type type;
c19d1205
ZW
537 expressionS exp;
538 int pc_rel;
e2b0ab59 539 } relocs[ARM_IT_MAX_RELOCS];
b99bd4ef 540
5ee91343 541 enum pred_instruction_type pred_insn_type;
e07e6e58 542
c19d1205
ZW
543 struct
544 {
545 unsigned reg;
ca3f61f7 546 signed int imm;
dcbf9037 547 struct neon_type_el vectype;
ca3f61f7
NC
548 unsigned present : 1; /* Operand present. */
549 unsigned isreg : 1; /* Operand was a register. */
f5f10c66
AV
550 unsigned immisreg : 2; /* .imm field is a second register.
551 0: imm, 1: gpr, 2: MVE Q-register. */
57785aa2
AV
552 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
553 0) not scalar,
554 1) Neon scalar,
555 2) MVE scalar. */
5287ad62 556 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 557 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
558 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
559 instructions. This allows us to disambiguate ARM <-> vector insns. */
560 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 561 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5ee91343 562 unsigned isquad : 1; /* Operand is SIMD quad register. */
037e8744 563 unsigned issingle : 1; /* Operand is VFP single-precision register. */
1b883319 564 unsigned iszr : 1; /* Operand is ZR register. */
ca3f61f7
NC
565 unsigned hasreloc : 1; /* Operand has relocation suffix. */
566 unsigned writeback : 1; /* Operand has trailing ! */
567 unsigned preind : 1; /* Preindexed address. */
568 unsigned postind : 1; /* Postindexed address. */
569 unsigned negative : 1; /* Index register was negated. */
570 unsigned shifted : 1; /* Shift applied to operation. */
571 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 572 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
573};
574
c19d1205 575static struct arm_it inst;
b99bd4ef
NC
576
577#define NUM_FLOAT_VALS 8
578
05d2d07e 579const char * fp_const[] =
b99bd4ef
NC
580{
581 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
582};
583
b99bd4ef
NC
584LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
585
586#define FAIL (-1)
587#define SUCCESS (0)
588
589#define SUFF_S 1
590#define SUFF_D 2
591#define SUFF_E 3
592#define SUFF_P 4
593
c19d1205
ZW
594#define CP_T_X 0x00008000
595#define CP_T_Y 0x00400000
b99bd4ef 596
c19d1205
ZW
597#define CONDS_BIT 0x00100000
598#define LOAD_BIT 0x00100000
b99bd4ef
NC
599
600#define DOUBLE_LOAD_FLAG 0x00000001
601
602struct asm_cond
603{
d3ce72d0 604 const char * template_name;
c921be7d 605 unsigned long value;
b99bd4ef
NC
606};
607
c19d1205 608#define COND_ALWAYS 0xE
b99bd4ef 609
b99bd4ef
NC
610struct asm_psr
611{
d3ce72d0 612 const char * template_name;
c921be7d 613 unsigned long field;
b99bd4ef
NC
614};
615
62b3e311
PB
616struct asm_barrier_opt
617{
e797f7e0
MGD
618 const char * template_name;
619 unsigned long value;
620 const arm_feature_set arch;
62b3e311
PB
621};
622
2d2255b5 623/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
624#define SPSR_BIT (1 << 22)
625
c19d1205
ZW
626/* The individual PSR flag bits. */
627#define PSR_c (1 << 16)
628#define PSR_x (1 << 17)
629#define PSR_s (1 << 18)
630#define PSR_f (1 << 19)
b99bd4ef 631
c19d1205 632struct reloc_entry
bfae80f2 633{
0198d5e6 634 const char * name;
c921be7d 635 bfd_reloc_code_real_type reloc;
bfae80f2
RE
636};
637
5287ad62 638enum vfp_reg_pos
bfae80f2 639{
5287ad62
JB
640 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
641 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
642};
643
644enum vfp_ldstm_type
645{
646 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
647};
648
dcbf9037
JB
649/* Bits for DEFINED field in neon_typed_alias. */
650#define NTA_HASTYPE 1
651#define NTA_HASINDEX 2
652
653struct neon_typed_alias
654{
c921be7d
NC
655 unsigned char defined;
656 unsigned char index;
657 struct neon_type_el eltype;
dcbf9037
JB
658};
659
c19d1205 660/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
661 architecture extensions' registers. Each entry should have an error message
662 in reg_expected_msgs below. */
c19d1205 663enum arm_reg_type
bfae80f2 664{
c19d1205
ZW
665 REG_TYPE_RN,
666 REG_TYPE_CP,
667 REG_TYPE_CN,
668 REG_TYPE_FN,
669 REG_TYPE_VFS,
670 REG_TYPE_VFD,
5287ad62 671 REG_TYPE_NQ,
037e8744 672 REG_TYPE_VFSD,
5287ad62 673 REG_TYPE_NDQ,
dec41383 674 REG_TYPE_NSD,
037e8744 675 REG_TYPE_NSDQ,
c19d1205
ZW
676 REG_TYPE_VFC,
677 REG_TYPE_MVF,
678 REG_TYPE_MVD,
679 REG_TYPE_MVFX,
680 REG_TYPE_MVDX,
681 REG_TYPE_MVAX,
5ee91343 682 REG_TYPE_MQ,
c19d1205
ZW
683 REG_TYPE_DSPSC,
684 REG_TYPE_MMXWR,
685 REG_TYPE_MMXWC,
686 REG_TYPE_MMXWCG,
687 REG_TYPE_XSCALE,
5ee91343 688 REG_TYPE_RNB,
1b883319 689 REG_TYPE_ZR
bfae80f2
RE
690};
691
dcbf9037
JB
692/* Structure for a hash table entry for a register.
693 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
694 information which states whether a vector type or index is specified (for a
695 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
696struct reg_entry
697{
c921be7d 698 const char * name;
90ec0d68 699 unsigned int number;
c921be7d
NC
700 unsigned char type;
701 unsigned char builtin;
702 struct neon_typed_alias * neon;
6c43fab6
RE
703};
704
c19d1205 705/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 706const char * const reg_expected_msgs[] =
c19d1205 707{
5aa75429
TP
708 [REG_TYPE_RN] = N_("ARM register expected"),
709 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
710 [REG_TYPE_CN] = N_("co-processor register expected"),
711 [REG_TYPE_FN] = N_("FPA register expected"),
712 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
713 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
714 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
715 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
716 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
717 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
718 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
719 " expected"),
720 [REG_TYPE_VFC] = N_("VFP system register expected"),
721 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
722 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
723 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
724 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
725 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
726 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
727 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
728 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
729 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
730 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
5ee91343 731 [REG_TYPE_MQ] = N_("MVE vector register expected"),
da3ec71f 732 [REG_TYPE_RNB] = ""
6c43fab6
RE
733};
734
c19d1205 735/* Some well known registers that we refer to directly elsewhere. */
bd340a04 736#define REG_R12 12
c19d1205
ZW
737#define REG_SP 13
738#define REG_LR 14
739#define REG_PC 15
404ff6b5 740
b99bd4ef
NC
741/* ARM instructions take 4bytes in the object file, Thumb instructions
742 take 2: */
c19d1205 743#define INSN_SIZE 4
b99bd4ef
NC
744
745struct asm_opcode
746{
747 /* Basic string to match. */
d3ce72d0 748 const char * template_name;
c19d1205
ZW
749
750 /* Parameters to instruction. */
5be8be5d 751 unsigned int operands[8];
c19d1205
ZW
752
753 /* Conditional tag - see opcode_lookup. */
754 unsigned int tag : 4;
b99bd4ef
NC
755
756 /* Basic instruction code. */
a302e574 757 unsigned int avalue;
b99bd4ef 758
c19d1205
ZW
759 /* Thumb-format instruction code. */
760 unsigned int tvalue;
b99bd4ef 761
90e4755a 762 /* Which architecture variant provides this instruction. */
c921be7d
NC
763 const arm_feature_set * avariant;
764 const arm_feature_set * tvariant;
c19d1205
ZW
765
766 /* Function to call to encode instruction in ARM format. */
767 void (* aencode) (void);
b99bd4ef 768
c19d1205
ZW
769 /* Function to call to encode instruction in Thumb format. */
770 void (* tencode) (void);
5ee91343
AV
771
772 /* Indicates whether this instruction may be vector predicated. */
773 unsigned int mayBeVecPred : 1;
b99bd4ef
NC
774};
775
a737bd4d
NC
776/* Defines for various bits that we will want to toggle. */
777#define INST_IMMEDIATE 0x02000000
778#define OFFSET_REG 0x02000000
c19d1205 779#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
780#define SHIFT_BY_REG 0x00000010
781#define PRE_INDEX 0x01000000
782#define INDEX_UP 0x00800000
783#define WRITE_BACK 0x00200000
784#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 785#define CPSI_MMOD 0x00020000
90e4755a 786
a737bd4d
NC
787#define LITERAL_MASK 0xf000f000
788#define OPCODE_MASK 0xfe1fffff
789#define V4_STR_BIT 0x00000020
8335d6aa 790#define VLDR_VMOV_SAME 0x0040f000
90e4755a 791
efd81785
PB
792#define T2_SUBS_PC_LR 0xf3de8f00
793
a737bd4d 794#define DATA_OP_SHIFT 21
bada4342 795#define SBIT_SHIFT 20
90e4755a 796
ef8d22e6
PB
797#define T2_OPCODE_MASK 0xfe1fffff
798#define T2_DATA_OP_SHIFT 21
bada4342 799#define T2_SBIT_SHIFT 20
ef8d22e6 800
6530b175
NC
801#define A_COND_MASK 0xf0000000
802#define A_PUSH_POP_OP_MASK 0x0fff0000
803
804/* Opcodes for pushing/poping registers to/from the stack. */
805#define A1_OPCODE_PUSH 0x092d0000
806#define A2_OPCODE_PUSH 0x052d0004
807#define A2_OPCODE_POP 0x049d0004
808
a737bd4d
NC
809/* Codes to distinguish the arithmetic instructions. */
810#define OPCODE_AND 0
811#define OPCODE_EOR 1
812#define OPCODE_SUB 2
813#define OPCODE_RSB 3
814#define OPCODE_ADD 4
815#define OPCODE_ADC 5
816#define OPCODE_SBC 6
817#define OPCODE_RSC 7
818#define OPCODE_TST 8
819#define OPCODE_TEQ 9
820#define OPCODE_CMP 10
821#define OPCODE_CMN 11
822#define OPCODE_ORR 12
823#define OPCODE_MOV 13
824#define OPCODE_BIC 14
825#define OPCODE_MVN 15
90e4755a 826
ef8d22e6
PB
827#define T2_OPCODE_AND 0
828#define T2_OPCODE_BIC 1
829#define T2_OPCODE_ORR 2
830#define T2_OPCODE_ORN 3
831#define T2_OPCODE_EOR 4
832#define T2_OPCODE_ADD 8
833#define T2_OPCODE_ADC 10
834#define T2_OPCODE_SBC 11
835#define T2_OPCODE_SUB 13
836#define T2_OPCODE_RSB 14
837
a737bd4d
NC
838#define T_OPCODE_MUL 0x4340
839#define T_OPCODE_TST 0x4200
840#define T_OPCODE_CMN 0x42c0
841#define T_OPCODE_NEG 0x4240
842#define T_OPCODE_MVN 0x43c0
90e4755a 843
a737bd4d
NC
844#define T_OPCODE_ADD_R3 0x1800
845#define T_OPCODE_SUB_R3 0x1a00
846#define T_OPCODE_ADD_HI 0x4400
847#define T_OPCODE_ADD_ST 0xb000
848#define T_OPCODE_SUB_ST 0xb080
849#define T_OPCODE_ADD_SP 0xa800
850#define T_OPCODE_ADD_PC 0xa000
851#define T_OPCODE_ADD_I8 0x3000
852#define T_OPCODE_SUB_I8 0x3800
853#define T_OPCODE_ADD_I3 0x1c00
854#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 855
a737bd4d
NC
856#define T_OPCODE_ASR_R 0x4100
857#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
858#define T_OPCODE_LSR_R 0x40c0
859#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
860#define T_OPCODE_ASR_I 0x1000
861#define T_OPCODE_LSL_I 0x0000
862#define T_OPCODE_LSR_I 0x0800
b99bd4ef 863
a737bd4d
NC
864#define T_OPCODE_MOV_I8 0x2000
865#define T_OPCODE_CMP_I8 0x2800
866#define T_OPCODE_CMP_LR 0x4280
867#define T_OPCODE_MOV_HR 0x4600
868#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 869
a737bd4d
NC
870#define T_OPCODE_LDR_PC 0x4800
871#define T_OPCODE_LDR_SP 0x9800
872#define T_OPCODE_STR_SP 0x9000
873#define T_OPCODE_LDR_IW 0x6800
874#define T_OPCODE_STR_IW 0x6000
875#define T_OPCODE_LDR_IH 0x8800
876#define T_OPCODE_STR_IH 0x8000
877#define T_OPCODE_LDR_IB 0x7800
878#define T_OPCODE_STR_IB 0x7000
879#define T_OPCODE_LDR_RW 0x5800
880#define T_OPCODE_STR_RW 0x5000
881#define T_OPCODE_LDR_RH 0x5a00
882#define T_OPCODE_STR_RH 0x5200
883#define T_OPCODE_LDR_RB 0x5c00
884#define T_OPCODE_STR_RB 0x5400
c9b604bd 885
a737bd4d
NC
886#define T_OPCODE_PUSH 0xb400
887#define T_OPCODE_POP 0xbc00
b99bd4ef 888
2fc8bdac 889#define T_OPCODE_BRANCH 0xe000
b99bd4ef 890
a737bd4d 891#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 892#define THUMB_PP_PC_LR 0x0100
c19d1205 893#define THUMB_LOAD_BIT 0x0800
53365c0d 894#define THUMB2_LOAD_BIT 0x00100000
c19d1205 895
5ee91343 896#define BAD_SYNTAX _("syntax error")
c19d1205 897#define BAD_ARGS _("bad arguments to instruction")
fdfde340 898#define BAD_SP _("r13 not allowed here")
c19d1205 899#define BAD_PC _("r15 not allowed here")
a302e574
AV
900#define BAD_ODD _("Odd register not allowed here")
901#define BAD_EVEN _("Even register not allowed here")
c19d1205
ZW
902#define BAD_COND _("instruction cannot be conditional")
903#define BAD_OVERLAP _("registers may not be the same")
904#define BAD_HIREG _("lo register required")
905#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
35c228db 906#define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
dfa9f0d5 907#define BAD_BRANCH _("branch must be last instruction in IT block")
e12437dc 908#define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
4934a27c 909#define BAD_NO_VPT _("instruction not allowed in VPT block")
dfa9f0d5 910#define BAD_NOT_IT _("instruction not allowed in IT block")
5ee91343 911#define BAD_NOT_VPT _("instruction missing MVE vector predication code")
037e8744 912#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58 913#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
5ee91343
AV
914#define BAD_OUT_VPT \
915 _("vector predicated instruction should be in VPT/VPST block")
e07e6e58 916#define BAD_IT_COND _("incorrect condition in IT block")
5ee91343 917#define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
e07e6e58 918#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 919#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
920#define BAD_PC_ADDRESSING \
921 _("cannot use register index with PC-relative addressing")
922#define BAD_PC_WRITEBACK \
923 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
924#define BAD_RANGE _("branch out of range")
925#define BAD_FP16 _("selected processor does not support fp16 instruction")
aab2c27d 926#define BAD_BF16 _("selected processor does not support bf16 instruction")
4934a27c
MM
927#define BAD_CDE _("selected processor does not support cde instruction")
928#define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
dd5181d5 929#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 930#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
5ee91343
AV
931#define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
932 "block")
933#define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
934 "block")
935#define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
936 " operand")
937#define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
938 " operand")
a302e574 939#define BAD_SIMD_TYPE _("bad type in SIMD instruction")
886e1c73
AV
940#define BAD_MVE_AUTO \
941 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
942 " use a valid -march or -mcpu option.")
943#define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
944 "and source operands makes instruction UNPREDICTABLE")
35c228db 945#define BAD_EL_TYPE _("bad element type for instruction")
1b883319 946#define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
c19d1205 947
629310ab
ML
948static htab_t arm_ops_hsh;
949static htab_t arm_cond_hsh;
950static htab_t arm_vcond_hsh;
951static htab_t arm_shift_hsh;
952static htab_t arm_psr_hsh;
953static htab_t arm_v7m_psr_hsh;
954static htab_t arm_reg_hsh;
955static htab_t arm_reloc_hsh;
956static htab_t arm_barrier_opt_hsh;
b99bd4ef 957
b99bd4ef
NC
958/* Stuff needed to resolve the label ambiguity
959 As:
960 ...
961 label: <insn>
962 may differ from:
963 ...
964 label:
5f4273c7 965 <insn> */
b99bd4ef
NC
966
967symbolS * last_label_seen;
b34976b6 968static int label_is_thumb_function_name = FALSE;
e07e6e58 969
3d0c9500
NC
970/* Literal pool structure. Held on a per-section
971 and per-sub-section basis. */
a737bd4d 972
c19d1205 973#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 974typedef struct literal_pool
b99bd4ef 975{
c921be7d
NC
976 expressionS literals [MAX_LITERAL_POOL_SIZE];
977 unsigned int next_free_entry;
978 unsigned int id;
979 symbolS * symbol;
980 segT section;
981 subsegT sub_section;
a8040cf2
NC
982#ifdef OBJ_ELF
983 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
984#endif
c921be7d 985 struct literal_pool * next;
8335d6aa 986 unsigned int alignment;
3d0c9500 987} literal_pool;
b99bd4ef 988
3d0c9500
NC
989/* Pointer to a linked list of literal pools. */
990literal_pool * list_of_pools = NULL;
e27ec89e 991
2e6976a8
DG
992typedef enum asmfunc_states
993{
994 OUTSIDE_ASMFUNC,
995 WAITING_ASMFUNC_NAME,
996 WAITING_ENDASMFUNC
997} asmfunc_states;
998
999static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
1000
e07e6e58 1001#ifdef OBJ_ELF
5ee91343 1002# define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
e07e6e58 1003#else
5ee91343 1004static struct current_pred now_pred;
e07e6e58
NC
1005#endif
1006
1007static inline int
5ee91343 1008now_pred_compatible (int cond)
e07e6e58 1009{
5ee91343 1010 return (cond & ~1) == (now_pred.cc & ~1);
e07e6e58
NC
1011}
1012
1013static inline int
1014conditional_insn (void)
1015{
1016 return inst.cond != COND_ALWAYS;
1017}
1018
5ee91343 1019static int in_pred_block (void);
e07e6e58 1020
5ee91343 1021static int handle_pred_state (void);
e07e6e58
NC
1022
1023static void force_automatic_it_block_close (void);
1024
c921be7d
NC
1025static void it_fsm_post_encode (void);
1026
5ee91343 1027#define set_pred_insn_type(type) \
e07e6e58
NC
1028 do \
1029 { \
5ee91343
AV
1030 inst.pred_insn_type = type; \
1031 if (handle_pred_state () == FAIL) \
477330fc 1032 return; \
e07e6e58
NC
1033 } \
1034 while (0)
1035
5ee91343 1036#define set_pred_insn_type_nonvoid(type, failret) \
c921be7d
NC
1037 do \
1038 { \
5ee91343
AV
1039 inst.pred_insn_type = type; \
1040 if (handle_pred_state () == FAIL) \
477330fc 1041 return failret; \
c921be7d
NC
1042 } \
1043 while(0)
1044
5ee91343 1045#define set_pred_insn_type_last() \
e07e6e58
NC
1046 do \
1047 { \
1048 if (inst.cond == COND_ALWAYS) \
5ee91343 1049 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 1050 else \
5ee91343 1051 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
1052 } \
1053 while (0)
1054
e39c1607
SD
1055/* Toggle value[pos]. */
1056#define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1057
c19d1205 1058/* Pure syntax. */
b99bd4ef 1059
c19d1205
ZW
1060/* This array holds the chars that always start a comment. If the
1061 pre-processor is disabled, these aren't very useful. */
2e6976a8 1062char arm_comment_chars[] = "@";
3d0c9500 1063
c19d1205
ZW
1064/* This array holds the chars that only start a comment at the beginning of
1065 a line. If the line seems to have the form '# 123 filename'
1066 .line and .file directives will appear in the pre-processed output. */
1067/* Note that input_file.c hand checks for '#' at the beginning of the
1068 first line of the input file. This is because the compiler outputs
1069 #NO_APP at the beginning of its output. */
1070/* Also note that comments like this one will always work. */
1071const char line_comment_chars[] = "#";
3d0c9500 1072
2e6976a8 1073char arm_line_separator_chars[] = ";";
b99bd4ef 1074
c19d1205
ZW
1075/* Chars that can be used to separate mant
1076 from exp in floating point numbers. */
1077const char EXP_CHARS[] = "eE";
3d0c9500 1078
c19d1205
ZW
1079/* Chars that mean this number is a floating point constant. */
1080/* As in 0f12.456 */
1081/* or 0d1.2345e12 */
b99bd4ef 1082
5312fe52 1083const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
3d0c9500 1084
c19d1205
ZW
1085/* Prefix characters that indicate the start of an immediate
1086 value. */
1087#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 1088
c19d1205
ZW
1089/* Separator character handling. */
1090
1091#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1092
5312fe52
BW
1093enum fp_16bit_format
1094{
1095 ARM_FP16_FORMAT_IEEE = 0x1,
1096 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1097 ARM_FP16_FORMAT_DEFAULT = 0x3
1098};
1099
1100static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1101
1102
c19d1205
ZW
1103static inline int
1104skip_past_char (char ** str, char c)
1105{
8ab8155f
NC
1106 /* PR gas/14987: Allow for whitespace before the expected character. */
1107 skip_whitespace (*str);
427d0db6 1108
c19d1205
ZW
1109 if (**str == c)
1110 {
1111 (*str)++;
1112 return SUCCESS;
3d0c9500 1113 }
c19d1205
ZW
1114 else
1115 return FAIL;
1116}
c921be7d 1117
c19d1205 1118#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1119
c19d1205
ZW
1120/* Arithmetic expressions (possibly involving symbols). */
1121
1122/* Return TRUE if anything in the expression is a bignum. */
1123
0198d5e6 1124static bfd_boolean
c19d1205
ZW
1125walk_no_bignums (symbolS * sp)
1126{
1127 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1128 return TRUE;
c19d1205
ZW
1129
1130 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1131 {
c19d1205
ZW
1132 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1133 || (symbol_get_value_expression (sp)->X_op_symbol
1134 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1135 }
1136
0198d5e6 1137 return FALSE;
3d0c9500
NC
1138}
1139
0198d5e6 1140static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1141
1142/* Third argument to my_get_expression. */
1143#define GE_NO_PREFIX 0
1144#define GE_IMM_PREFIX 1
1145#define GE_OPT_PREFIX 2
5287ad62
JB
1146/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1147 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1148#define GE_OPT_PREFIX_BIG 3
a737bd4d 1149
b99bd4ef 1150static int
c19d1205 1151my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1152{
c19d1205 1153 char * save_in;
b99bd4ef 1154
c19d1205
ZW
1155 /* In unified syntax, all prefixes are optional. */
1156 if (unified_syntax)
5287ad62 1157 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1158 : GE_OPT_PREFIX;
b99bd4ef 1159
c19d1205 1160 switch (prefix_mode)
b99bd4ef 1161 {
c19d1205
ZW
1162 case GE_NO_PREFIX: break;
1163 case GE_IMM_PREFIX:
1164 if (!is_immediate_prefix (**str))
1165 {
1166 inst.error = _("immediate expression requires a # prefix");
1167 return FAIL;
1168 }
1169 (*str)++;
1170 break;
1171 case GE_OPT_PREFIX:
5287ad62 1172 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1173 if (is_immediate_prefix (**str))
1174 (*str)++;
1175 break;
0198d5e6
TC
1176 default:
1177 abort ();
c19d1205 1178 }
b99bd4ef 1179
c19d1205 1180 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1181
c19d1205
ZW
1182 save_in = input_line_pointer;
1183 input_line_pointer = *str;
0198d5e6 1184 in_my_get_expression = TRUE;
2ac93be7 1185 expression (ep);
0198d5e6 1186 in_my_get_expression = FALSE;
c19d1205 1187
f86adc07 1188 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1189 {
f86adc07 1190 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1191 *str = input_line_pointer;
1192 input_line_pointer = save_in;
1193 if (inst.error == NULL)
f86adc07
NS
1194 inst.error = (ep->X_op == O_absent
1195 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1196 return 1;
1197 }
b99bd4ef 1198
c19d1205
ZW
1199 /* Get rid of any bignums now, so that we don't generate an error for which
1200 we can't establish a line number later on. Big numbers are never valid
1201 in instructions, which is where this routine is always called. */
5287ad62
JB
1202 if (prefix_mode != GE_OPT_PREFIX_BIG
1203 && (ep->X_op == O_big
477330fc 1204 || (ep->X_add_symbol
5287ad62 1205 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1206 || (ep->X_op_symbol
5287ad62 1207 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1208 {
1209 inst.error = _("invalid constant");
1210 *str = input_line_pointer;
1211 input_line_pointer = save_in;
1212 return 1;
1213 }
b99bd4ef 1214
c19d1205
ZW
1215 *str = input_line_pointer;
1216 input_line_pointer = save_in;
0198d5e6 1217 return SUCCESS;
b99bd4ef
NC
1218}
1219
c19d1205
ZW
1220/* Turn a string in input_line_pointer into a floating point constant
1221 of type TYPE, and store the appropriate bytes in *LITP. The number
1222 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1223 returned, or NULL on OK.
b99bd4ef 1224
c19d1205
ZW
1225 Note that fp constants aren't represent in the normal way on the ARM.
1226 In big endian mode, things are as expected. However, in little endian
1227 mode fp constants are big-endian word-wise, and little-endian byte-wise
1228 within the words. For example, (double) 1.1 in big endian mode is
1229 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1230 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1231
c19d1205 1232 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1233
6d4af3c2 1234const char *
c19d1205
ZW
1235md_atof (int type, char * litP, int * sizeP)
1236{
1237 int prec;
1238 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1239 char *t;
1240 int i;
b99bd4ef 1241
c19d1205
ZW
1242 switch (type)
1243 {
5312fe52
BW
1244 case 'H':
1245 case 'h':
1246 prec = 1;
1247 break;
1248
27cce866
MM
1249 /* If this is a bfloat16, then parse it slightly differently, as it
1250 does not follow the IEEE specification for floating point numbers
1251 exactly. */
1252 case 'b':
1253 {
1254 FLONUM_TYPE generic_float;
1255
1256 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1257
1258 if (t)
1259 input_line_pointer = t;
1260 else
1261 return _("invalid floating point number");
1262
1263 switch (generic_float.sign)
1264 {
1265 /* Is +Inf. */
1266 case 'P':
1267 words[0] = 0x7f80;
1268 break;
1269
1270 /* Is -Inf. */
1271 case 'N':
1272 words[0] = 0xff80;
1273 break;
1274
1275 /* Is NaN. */
1276 /* bfloat16 has two types of NaN - quiet and signalling.
1277 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1278 signalling NaN's have bit[0] == 0 && fraction != 0.
1279 Chosen this specific encoding as it is the same form
1280 as used by other IEEE 754 encodings in GAS. */
1281 case 0:
1282 words[0] = 0x7fff;
1283 break;
1284
1285 default:
1286 break;
1287 }
1288
1289 *sizeP = 2;
1290
1291 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1292
1293 return NULL;
1294 }
c19d1205
ZW
1295 case 'f':
1296 case 'F':
1297 case 's':
1298 case 'S':
1299 prec = 2;
1300 break;
b99bd4ef 1301
c19d1205
ZW
1302 case 'd':
1303 case 'D':
1304 case 'r':
1305 case 'R':
1306 prec = 4;
1307 break;
b99bd4ef 1308
c19d1205
ZW
1309 case 'x':
1310 case 'X':
499ac353 1311 prec = 5;
c19d1205 1312 break;
b99bd4ef 1313
c19d1205
ZW
1314 case 'p':
1315 case 'P':
499ac353 1316 prec = 5;
c19d1205 1317 break;
a737bd4d 1318
c19d1205
ZW
1319 default:
1320 *sizeP = 0;
499ac353 1321 return _("Unrecognized or unsupported floating point constant");
c19d1205 1322 }
b99bd4ef 1323
c19d1205
ZW
1324 t = atof_ieee (input_line_pointer, type, words);
1325 if (t)
1326 input_line_pointer = t;
499ac353 1327 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1328
72c03e30
BW
1329 if (target_big_endian || prec == 1)
1330 for (i = 0; i < prec; i++)
1331 {
1332 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1333 litP += sizeof (LITTLENUM_TYPE);
1334 }
1335 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1336 for (i = prec - 1; i >= 0; i--)
1337 {
1338 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1339 litP += sizeof (LITTLENUM_TYPE);
1340 }
c19d1205 1341 else
72c03e30
BW
1342 /* For a 4 byte float the order of elements in `words' is 1 0.
1343 For an 8 byte float the order is 1 0 3 2. */
1344 for (i = 0; i < prec; i += 2)
1345 {
1346 md_number_to_chars (litP, (valueT) words[i + 1],
1347 sizeof (LITTLENUM_TYPE));
1348 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1349 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1350 litP += 2 * sizeof (LITTLENUM_TYPE);
1351 }
b99bd4ef 1352
499ac353 1353 return NULL;
c19d1205 1354}
b99bd4ef 1355
c19d1205
ZW
1356/* We handle all bad expressions here, so that we can report the faulty
1357 instruction in the error message. */
0198d5e6 1358
c19d1205 1359void
91d6fa6a 1360md_operand (expressionS * exp)
c19d1205
ZW
1361{
1362 if (in_my_get_expression)
91d6fa6a 1363 exp->X_op = O_illegal;
b99bd4ef
NC
1364}
1365
c19d1205 1366/* Immediate values. */
b99bd4ef 1367
0198d5e6 1368#ifdef OBJ_ELF
c19d1205
ZW
1369/* Generic immediate-value read function for use in directives.
1370 Accepts anything that 'expression' can fold to a constant.
1371 *val receives the number. */
0198d5e6 1372
c19d1205
ZW
1373static int
1374immediate_for_directive (int *val)
b99bd4ef 1375{
c19d1205
ZW
1376 expressionS exp;
1377 exp.X_op = O_illegal;
b99bd4ef 1378
c19d1205
ZW
1379 if (is_immediate_prefix (*input_line_pointer))
1380 {
1381 input_line_pointer++;
1382 expression (&exp);
1383 }
b99bd4ef 1384
c19d1205
ZW
1385 if (exp.X_op != O_constant)
1386 {
1387 as_bad (_("expected #constant"));
1388 ignore_rest_of_line ();
1389 return FAIL;
1390 }
1391 *val = exp.X_add_number;
1392 return SUCCESS;
b99bd4ef 1393}
c19d1205 1394#endif
b99bd4ef 1395
c19d1205 1396/* Register parsing. */
b99bd4ef 1397
c19d1205
ZW
1398/* Generic register parser. CCP points to what should be the
1399 beginning of a register name. If it is indeed a valid register
1400 name, advance CCP over it and return the reg_entry structure;
1401 otherwise return NULL. Does not issue diagnostics. */
1402
1403static struct reg_entry *
1404arm_reg_parse_multi (char **ccp)
b99bd4ef 1405{
c19d1205
ZW
1406 char *start = *ccp;
1407 char *p;
1408 struct reg_entry *reg;
b99bd4ef 1409
477330fc
RM
1410 skip_whitespace (start);
1411
c19d1205
ZW
1412#ifdef REGISTER_PREFIX
1413 if (*start != REGISTER_PREFIX)
01cfc07f 1414 return NULL;
c19d1205
ZW
1415 start++;
1416#endif
1417#ifdef OPTIONAL_REGISTER_PREFIX
1418 if (*start == OPTIONAL_REGISTER_PREFIX)
1419 start++;
1420#endif
b99bd4ef 1421
c19d1205
ZW
1422 p = start;
1423 if (!ISALPHA (*p) || !is_name_beginner (*p))
1424 return NULL;
b99bd4ef 1425
c19d1205
ZW
1426 do
1427 p++;
1428 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1429
629310ab 1430 reg = (struct reg_entry *) str_hash_find_n (arm_reg_hsh, start, p - start);
c19d1205
ZW
1431
1432 if (!reg)
1433 return NULL;
1434
1435 *ccp = p;
1436 return reg;
b99bd4ef
NC
1437}
1438
1439static int
dcbf9037 1440arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1441 enum arm_reg_type type)
b99bd4ef 1442{
c19d1205
ZW
1443 /* Alternative syntaxes are accepted for a few register classes. */
1444 switch (type)
1445 {
1446 case REG_TYPE_MVF:
1447 case REG_TYPE_MVD:
1448 case REG_TYPE_MVFX:
1449 case REG_TYPE_MVDX:
1450 /* Generic coprocessor register names are allowed for these. */
79134647 1451 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1452 return reg->number;
1453 break;
69b97547 1454
c19d1205
ZW
1455 case REG_TYPE_CP:
1456 /* For backward compatibility, a bare number is valid here. */
1457 {
1458 unsigned long processor = strtoul (start, ccp, 10);
1459 if (*ccp != start && processor <= 15)
1460 return processor;
1461 }
1a0670f3 1462 /* Fall through. */
6057a28f 1463
c19d1205
ZW
1464 case REG_TYPE_MMXWC:
1465 /* WC includes WCG. ??? I'm not sure this is true for all
1466 instructions that take WC registers. */
79134647 1467 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1468 return reg->number;
6057a28f 1469 break;
c19d1205 1470
6057a28f 1471 default:
c19d1205 1472 break;
6057a28f
NC
1473 }
1474
dcbf9037
JB
1475 return FAIL;
1476}
1477
1478/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1479 return value is the register number or FAIL. */
1480
1481static int
1482arm_reg_parse (char **ccp, enum arm_reg_type type)
1483{
1484 char *start = *ccp;
1485 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1486 int ret;
1487
1488 /* Do not allow a scalar (reg+index) to parse as a register. */
1489 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1490 return FAIL;
1491
1492 if (reg && reg->type == type)
1493 return reg->number;
1494
1495 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1496 return ret;
1497
c19d1205
ZW
1498 *ccp = start;
1499 return FAIL;
1500}
69b97547 1501
dcbf9037
JB
1502/* Parse a Neon type specifier. *STR should point at the leading '.'
1503 character. Does no verification at this stage that the type fits the opcode
1504 properly. E.g.,
1505
1506 .i32.i32.s16
1507 .s32.f32
1508 .u16
1509
1510 Can all be legally parsed by this function.
1511
1512 Fills in neon_type struct pointer with parsed information, and updates STR
1513 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1514 type, FAIL if not. */
1515
1516static int
1517parse_neon_type (struct neon_type *type, char **str)
1518{
1519 char *ptr = *str;
1520
1521 if (type)
1522 type->elems = 0;
1523
1524 while (type->elems < NEON_MAX_TYPE_ELS)
1525 {
1526 enum neon_el_type thistype = NT_untyped;
1527 unsigned thissize = -1u;
1528
1529 if (*ptr != '.')
1530 break;
1531
1532 ptr++;
1533
1534 /* Just a size without an explicit type. */
1535 if (ISDIGIT (*ptr))
1536 goto parsesize;
1537
1538 switch (TOLOWER (*ptr))
1539 {
1540 case 'i': thistype = NT_integer; break;
1541 case 'f': thistype = NT_float; break;
1542 case 'p': thistype = NT_poly; break;
1543 case 's': thistype = NT_signed; break;
1544 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1545 case 'd':
1546 thistype = NT_float;
1547 thissize = 64;
1548 ptr++;
1549 goto done;
aab2c27d
MM
1550 case 'b':
1551 thistype = NT_bfloat;
1552 switch (TOLOWER (*(++ptr)))
1553 {
1554 case 'f':
1555 ptr += 1;
1556 thissize = strtoul (ptr, &ptr, 10);
1557 if (thissize != 16)
1558 {
1559 as_bad (_("bad size %d in type specifier"), thissize);
1560 return FAIL;
1561 }
1562 goto done;
1563 case '0': case '1': case '2': case '3': case '4':
1564 case '5': case '6': case '7': case '8': case '9':
1565 case ' ': case '.':
1566 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1567 return FAIL;
1568 default:
1569 break;
1570 }
1571 break;
dcbf9037
JB
1572 default:
1573 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1574 return FAIL;
1575 }
1576
1577 ptr++;
1578
1579 /* .f is an abbreviation for .f32. */
1580 if (thistype == NT_float && !ISDIGIT (*ptr))
1581 thissize = 32;
1582 else
1583 {
1584 parsesize:
1585 thissize = strtoul (ptr, &ptr, 10);
1586
1587 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1588 && thissize != 64)
1589 {
1590 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1591 return FAIL;
1592 }
1593 }
1594
037e8744 1595 done:
dcbf9037 1596 if (type)
477330fc
RM
1597 {
1598 type->el[type->elems].type = thistype;
dcbf9037
JB
1599 type->el[type->elems].size = thissize;
1600 type->elems++;
1601 }
1602 }
1603
1604 /* Empty/missing type is not a successful parse. */
1605 if (type->elems == 0)
1606 return FAIL;
1607
1608 *str = ptr;
1609
1610 return SUCCESS;
1611}
1612
1613/* Errors may be set multiple times during parsing or bit encoding
1614 (particularly in the Neon bits), but usually the earliest error which is set
1615 will be the most meaningful. Avoid overwriting it with later (cascading)
1616 errors by calling this function. */
1617
1618static void
1619first_error (const char *err)
1620{
1621 if (!inst.error)
1622 inst.error = err;
1623}
1624
1625/* Parse a single type, e.g. ".s32", leading period included. */
1626static int
1627parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1628{
1629 char *str = *ccp;
1630 struct neon_type optype;
1631
1632 if (*str == '.')
1633 {
1634 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1635 {
1636 if (optype.elems == 1)
1637 *vectype = optype.el[0];
1638 else
1639 {
1640 first_error (_("only one type should be specified for operand"));
1641 return FAIL;
1642 }
1643 }
dcbf9037 1644 else
477330fc
RM
1645 {
1646 first_error (_("vector type expected"));
1647 return FAIL;
1648 }
dcbf9037
JB
1649 }
1650 else
1651 return FAIL;
5f4273c7 1652
dcbf9037 1653 *ccp = str;
5f4273c7 1654
dcbf9037
JB
1655 return SUCCESS;
1656}
1657
1658/* Special meanings for indices (which have a range of 0-7), which will fit into
1659 a 4-bit integer. */
1660
1661#define NEON_ALL_LANES 15
1662#define NEON_INTERLEAVE_LANES 14
1663
5ee91343
AV
1664/* Record a use of the given feature. */
1665static void
1666record_feature_use (const arm_feature_set *feature)
1667{
1668 if (thumb_mode)
1669 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1670 else
1671 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1672}
1673
1674/* If the given feature available in the selected CPU, mark it as used.
1675 Returns TRUE iff feature is available. */
1676static bfd_boolean
1677mark_feature_used (const arm_feature_set *feature)
1678{
886e1c73
AV
1679
1680 /* Do not support the use of MVE only instructions when in auto-detection or
1681 -march=all. */
1682 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1683 && ARM_CPU_IS_ANY (cpu_variant))
1684 {
1685 first_error (BAD_MVE_AUTO);
1686 return FALSE;
1687 }
5ee91343
AV
1688 /* Ensure the option is valid on the current architecture. */
1689 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1690 return FALSE;
1691
1692 /* Add the appropriate architecture feature for the barrier option used.
1693 */
1694 record_feature_use (feature);
1695
1696 return TRUE;
1697}
1698
dcbf9037
JB
1699/* Parse either a register or a scalar, with an optional type. Return the
1700 register number, and optionally fill in the actual type of the register
1701 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1702 type/index information in *TYPEINFO. */
1703
1704static int
1705parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1706 enum arm_reg_type *rtype,
1707 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1708{
1709 char *str = *ccp;
1710 struct reg_entry *reg = arm_reg_parse_multi (&str);
1711 struct neon_typed_alias atype;
1712 struct neon_type_el parsetype;
1713
1714 atype.defined = 0;
1715 atype.index = -1;
1716 atype.eltype.type = NT_invtype;
1717 atype.eltype.size = -1;
1718
1719 /* Try alternate syntax for some types of register. Note these are mutually
1720 exclusive with the Neon syntax extensions. */
1721 if (reg == NULL)
1722 {
1723 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1724 if (altreg != FAIL)
477330fc 1725 *ccp = str;
dcbf9037 1726 if (typeinfo)
477330fc 1727 *typeinfo = atype;
dcbf9037
JB
1728 return altreg;
1729 }
1730
037e8744
JB
1731 /* Undo polymorphism when a set of register types may be accepted. */
1732 if ((type == REG_TYPE_NDQ
1733 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1734 || (type == REG_TYPE_VFSD
477330fc 1735 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1736 || (type == REG_TYPE_NSDQ
477330fc
RM
1737 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1738 || reg->type == REG_TYPE_NQ))
dec41383
JW
1739 || (type == REG_TYPE_NSD
1740 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1741 || (type == REG_TYPE_MMXWC
1742 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1743 type = (enum arm_reg_type) reg->type;
dcbf9037 1744
5ee91343
AV
1745 if (type == REG_TYPE_MQ)
1746 {
1747 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1748 return FAIL;
1749
1750 if (!reg || reg->type != REG_TYPE_NQ)
1751 return FAIL;
1752
1753 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1754 {
1755 first_error (_("expected MVE register [q0..q7]"));
1756 return FAIL;
1757 }
1758 type = REG_TYPE_NQ;
1759 }
1760 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1761 && (type == REG_TYPE_NQ))
1762 return FAIL;
1763
1764
dcbf9037
JB
1765 if (type != reg->type)
1766 return FAIL;
1767
1768 if (reg->neon)
1769 atype = *reg->neon;
5f4273c7 1770
dcbf9037
JB
1771 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1772 {
1773 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1774 {
1775 first_error (_("can't redefine type for operand"));
1776 return FAIL;
1777 }
dcbf9037
JB
1778 atype.defined |= NTA_HASTYPE;
1779 atype.eltype = parsetype;
1780 }
5f4273c7 1781
dcbf9037
JB
1782 if (skip_past_char (&str, '[') == SUCCESS)
1783 {
dec41383
JW
1784 if (type != REG_TYPE_VFD
1785 && !(type == REG_TYPE_VFS
57785aa2
AV
1786 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1787 && !(type == REG_TYPE_NQ
1788 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc 1789 {
57785aa2
AV
1790 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1791 first_error (_("only D and Q registers may be indexed"));
1792 else
1793 first_error (_("only D registers may be indexed"));
477330fc
RM
1794 return FAIL;
1795 }
5f4273c7 1796
dcbf9037 1797 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1798 {
1799 first_error (_("can't change index for operand"));
1800 return FAIL;
1801 }
dcbf9037
JB
1802
1803 atype.defined |= NTA_HASINDEX;
1804
1805 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1806 atype.index = NEON_ALL_LANES;
dcbf9037 1807 else
477330fc
RM
1808 {
1809 expressionS exp;
dcbf9037 1810
477330fc 1811 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1812
477330fc
RM
1813 if (exp.X_op != O_constant)
1814 {
1815 first_error (_("constant expression required"));
1816 return FAIL;
1817 }
dcbf9037 1818
477330fc
RM
1819 if (skip_past_char (&str, ']') == FAIL)
1820 return FAIL;
dcbf9037 1821
477330fc
RM
1822 atype.index = exp.X_add_number;
1823 }
dcbf9037 1824 }
5f4273c7 1825
dcbf9037
JB
1826 if (typeinfo)
1827 *typeinfo = atype;
5f4273c7 1828
dcbf9037
JB
1829 if (rtype)
1830 *rtype = type;
5f4273c7 1831
dcbf9037 1832 *ccp = str;
5f4273c7 1833
dcbf9037
JB
1834 return reg->number;
1835}
1836
efd6b359 1837/* Like arm_reg_parse, but also allow the following extra features:
dcbf9037
JB
1838 - If RTYPE is non-zero, return the (possibly restricted) type of the
1839 register (e.g. Neon double or quad reg when either has been requested).
1840 - If this is a Neon vector type with additional type information, fill
1841 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1842 This function will fault on encountering a scalar. */
dcbf9037
JB
1843
1844static int
1845arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1846 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1847{
1848 struct neon_typed_alias atype;
1849 char *str = *ccp;
1850 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1851
1852 if (reg == FAIL)
1853 return FAIL;
1854
0855e32b
NS
1855 /* Do not allow regname(... to parse as a register. */
1856 if (*str == '(')
1857 return FAIL;
1858
dcbf9037
JB
1859 /* Do not allow a scalar (reg+index) to parse as a register. */
1860 if ((atype.defined & NTA_HASINDEX) != 0)
1861 {
1862 first_error (_("register operand expected, but got scalar"));
1863 return FAIL;
1864 }
1865
1866 if (vectype)
1867 *vectype = atype.eltype;
1868
1869 *ccp = str;
1870
1871 return reg;
1872}
1873
1874#define NEON_SCALAR_REG(X) ((X) >> 4)
1875#define NEON_SCALAR_INDEX(X) ((X) & 15)
1876
5287ad62
JB
1877/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1878 have enough information to be able to do a good job bounds-checking. So, we
1879 just do easy checks here, and do further checks later. */
1880
1881static int
57785aa2
AV
1882parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1883 arm_reg_type reg_type)
5287ad62 1884{
dcbf9037 1885 int reg;
5287ad62 1886 char *str = *ccp;
dcbf9037 1887 struct neon_typed_alias atype;
57785aa2 1888 unsigned reg_size;
5f4273c7 1889
dec41383 1890 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1891
57785aa2
AV
1892 switch (reg_type)
1893 {
1894 case REG_TYPE_VFS:
1895 reg_size = 32;
1896 break;
1897 case REG_TYPE_VFD:
1898 reg_size = 64;
1899 break;
1900 case REG_TYPE_MQ:
1901 reg_size = 128;
1902 break;
1903 default:
1904 gas_assert (0);
1905 return FAIL;
1906 }
1907
dcbf9037 1908 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1909 return FAIL;
5f4273c7 1910
57785aa2 1911 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
5287ad62 1912 {
dcbf9037 1913 first_error (_("scalar must have an index"));
5287ad62
JB
1914 return FAIL;
1915 }
57785aa2 1916 else if (atype.index >= reg_size / elsize)
5287ad62 1917 {
dcbf9037 1918 first_error (_("scalar index out of range"));
5287ad62
JB
1919 return FAIL;
1920 }
5f4273c7 1921
dcbf9037
JB
1922 if (type)
1923 *type = atype.eltype;
5f4273c7 1924
5287ad62 1925 *ccp = str;
5f4273c7 1926
dcbf9037 1927 return reg * 16 + atype.index;
5287ad62
JB
1928}
1929
4b5a202f
AV
1930/* Types of registers in a list. */
1931
1932enum reg_list_els
1933{
1934 REGLIST_RN,
1935 REGLIST_CLRM,
1936 REGLIST_VFP_S,
efd6b359 1937 REGLIST_VFP_S_VPR,
4b5a202f 1938 REGLIST_VFP_D,
efd6b359 1939 REGLIST_VFP_D_VPR,
4b5a202f
AV
1940 REGLIST_NEON_D
1941};
1942
c19d1205 1943/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1944
c19d1205 1945static long
4b5a202f 1946parse_reg_list (char ** strp, enum reg_list_els etype)
c19d1205 1947{
4b5a202f
AV
1948 char *str = *strp;
1949 long range = 0;
1950 int another_range;
1951
1952 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
a737bd4d 1953
c19d1205
ZW
1954 /* We come back here if we get ranges concatenated by '+' or '|'. */
1955 do
6057a28f 1956 {
477330fc
RM
1957 skip_whitespace (str);
1958
c19d1205 1959 another_range = 0;
a737bd4d 1960
c19d1205
ZW
1961 if (*str == '{')
1962 {
1963 int in_range = 0;
1964 int cur_reg = -1;
a737bd4d 1965
c19d1205
ZW
1966 str++;
1967 do
1968 {
1969 int reg;
4b5a202f
AV
1970 const char apsr_str[] = "apsr";
1971 int apsr_str_len = strlen (apsr_str);
6057a28f 1972
a65b5de6 1973 reg = arm_reg_parse (&str, REG_TYPE_RN);
4b5a202f 1974 if (etype == REGLIST_CLRM)
c19d1205 1975 {
4b5a202f
AV
1976 if (reg == REG_SP || reg == REG_PC)
1977 reg = FAIL;
1978 else if (reg == FAIL
1979 && !strncasecmp (str, apsr_str, apsr_str_len)
1980 && !ISALPHA (*(str + apsr_str_len)))
1981 {
1982 reg = 15;
1983 str += apsr_str_len;
1984 }
1985
1986 if (reg == FAIL)
1987 {
1988 first_error (_("r0-r12, lr or APSR expected"));
1989 return FAIL;
1990 }
1991 }
1992 else /* etype == REGLIST_RN. */
1993 {
1994 if (reg == FAIL)
1995 {
1996 first_error (_(reg_expected_msgs[REGLIST_RN]));
1997 return FAIL;
1998 }
c19d1205 1999 }
a737bd4d 2000
c19d1205
ZW
2001 if (in_range)
2002 {
2003 int i;
a737bd4d 2004
c19d1205
ZW
2005 if (reg <= cur_reg)
2006 {
dcbf9037 2007 first_error (_("bad range in register list"));
c19d1205
ZW
2008 return FAIL;
2009 }
40a18ebd 2010
c19d1205
ZW
2011 for (i = cur_reg + 1; i < reg; i++)
2012 {
2013 if (range & (1 << i))
2014 as_tsktsk
2015 (_("Warning: duplicated register (r%d) in register list"),
2016 i);
2017 else
2018 range |= 1 << i;
2019 }
2020 in_range = 0;
2021 }
a737bd4d 2022
c19d1205
ZW
2023 if (range & (1 << reg))
2024 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2025 reg);
2026 else if (reg <= cur_reg)
2027 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 2028
c19d1205
ZW
2029 range |= 1 << reg;
2030 cur_reg = reg;
2031 }
2032 while (skip_past_comma (&str) != FAIL
2033 || (in_range = 1, *str++ == '-'));
2034 str--;
a737bd4d 2035
d996d970 2036 if (skip_past_char (&str, '}') == FAIL)
c19d1205 2037 {
dcbf9037 2038 first_error (_("missing `}'"));
c19d1205
ZW
2039 return FAIL;
2040 }
2041 }
4b5a202f 2042 else if (etype == REGLIST_RN)
c19d1205 2043 {
91d6fa6a 2044 expressionS exp;
40a18ebd 2045
91d6fa6a 2046 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 2047 return FAIL;
40a18ebd 2048
91d6fa6a 2049 if (exp.X_op == O_constant)
c19d1205 2050 {
91d6fa6a
NC
2051 if (exp.X_add_number
2052 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
2053 {
2054 inst.error = _("invalid register mask");
2055 return FAIL;
2056 }
a737bd4d 2057
91d6fa6a 2058 if ((range & exp.X_add_number) != 0)
c19d1205 2059 {
91d6fa6a 2060 int regno = range & exp.X_add_number;
a737bd4d 2061
c19d1205
ZW
2062 regno &= -regno;
2063 regno = (1 << regno) - 1;
2064 as_tsktsk
2065 (_("Warning: duplicated register (r%d) in register list"),
2066 regno);
2067 }
a737bd4d 2068
91d6fa6a 2069 range |= exp.X_add_number;
c19d1205
ZW
2070 }
2071 else
2072 {
e2b0ab59 2073 if (inst.relocs[0].type != 0)
c19d1205
ZW
2074 {
2075 inst.error = _("expression too complex");
2076 return FAIL;
2077 }
a737bd4d 2078
e2b0ab59
AV
2079 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2080 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2081 inst.relocs[0].pc_rel = 0;
c19d1205
ZW
2082 }
2083 }
a737bd4d 2084
c19d1205
ZW
2085 if (*str == '|' || *str == '+')
2086 {
2087 str++;
2088 another_range = 1;
2089 }
a737bd4d 2090 }
c19d1205 2091 while (another_range);
a737bd4d 2092
c19d1205
ZW
2093 *strp = str;
2094 return range;
a737bd4d
NC
2095}
2096
c19d1205
ZW
2097/* Parse a VFP register list. If the string is invalid return FAIL.
2098 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
2099 register. Parses registers of type ETYPE.
2100 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2101 - Q registers can be used to specify pairs of D registers
2102 - { } can be omitted from around a singleton register list
477330fc
RM
2103 FIXME: This is not implemented, as it would require backtracking in
2104 some cases, e.g.:
2105 vtbl.8 d3,d4,d5
2106 This could be done (the meaning isn't really ambiguous), but doesn't
2107 fit in well with the current parsing framework.
dcbf9037
JB
2108 - 32 D registers may be used (also true for VFPv3).
2109 FIXME: Types are ignored in these register lists, which is probably a
2110 bug. */
6057a28f 2111
c19d1205 2112static int
efd6b359
AV
2113parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2114 bfd_boolean *partial_match)
6057a28f 2115{
037e8744 2116 char *str = *ccp;
c19d1205
ZW
2117 int base_reg;
2118 int new_base;
21d799b5 2119 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 2120 int max_regs = 0;
c19d1205
ZW
2121 int count = 0;
2122 int warned = 0;
2123 unsigned long mask = 0;
a737bd4d 2124 int i;
efd6b359
AV
2125 bfd_boolean vpr_seen = FALSE;
2126 bfd_boolean expect_vpr =
2127 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
6057a28f 2128
477330fc 2129 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
2130 {
2131 inst.error = _("expecting {");
2132 return FAIL;
2133 }
6057a28f 2134
5287ad62 2135 switch (etype)
c19d1205 2136 {
5287ad62 2137 case REGLIST_VFP_S:
efd6b359 2138 case REGLIST_VFP_S_VPR:
c19d1205
ZW
2139 regtype = REG_TYPE_VFS;
2140 max_regs = 32;
5287ad62 2141 break;
5f4273c7 2142
5287ad62 2143 case REGLIST_VFP_D:
efd6b359 2144 case REGLIST_VFP_D_VPR:
5287ad62 2145 regtype = REG_TYPE_VFD;
b7fc2769 2146 break;
5f4273c7 2147
b7fc2769
JB
2148 case REGLIST_NEON_D:
2149 regtype = REG_TYPE_NDQ;
2150 break;
4b5a202f
AV
2151
2152 default:
2153 gas_assert (0);
b7fc2769
JB
2154 }
2155
efd6b359 2156 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
b7fc2769 2157 {
b1cc4aeb
PB
2158 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2159 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
2160 {
2161 max_regs = 32;
2162 if (thumb_mode)
2163 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2164 fpu_vfp_ext_d32);
2165 else
2166 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2167 fpu_vfp_ext_d32);
2168 }
5287ad62 2169 else
477330fc 2170 max_regs = 16;
c19d1205 2171 }
6057a28f 2172
c19d1205 2173 base_reg = max_regs;
efd6b359 2174 *partial_match = FALSE;
a737bd4d 2175
c19d1205
ZW
2176 do
2177 {
7af67752 2178 unsigned int setmask = 1, addregs = 1;
efd6b359 2179 const char vpr_str[] = "vpr";
7af67752 2180 size_t vpr_str_len = strlen (vpr_str);
dcbf9037 2181
037e8744 2182 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 2183
efd6b359
AV
2184 if (expect_vpr)
2185 {
2186 if (new_base == FAIL
2187 && !strncasecmp (str, vpr_str, vpr_str_len)
2188 && !ISALPHA (*(str + vpr_str_len))
2189 && !vpr_seen)
2190 {
2191 vpr_seen = TRUE;
2192 str += vpr_str_len;
2193 if (count == 0)
2194 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2195 }
2196 else if (vpr_seen)
2197 {
2198 first_error (_("VPR expected last"));
2199 return FAIL;
2200 }
2201 else if (new_base == FAIL)
2202 {
2203 if (regtype == REG_TYPE_VFS)
2204 first_error (_("VFP single precision register or VPR "
2205 "expected"));
2206 else /* regtype == REG_TYPE_VFD. */
2207 first_error (_("VFP/Neon double precision register or VPR "
2208 "expected"));
2209 return FAIL;
2210 }
2211 }
2212 else if (new_base == FAIL)
a737bd4d 2213 {
dcbf9037 2214 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
2215 return FAIL;
2216 }
5f4273c7 2217
efd6b359
AV
2218 *partial_match = TRUE;
2219 if (vpr_seen)
2220 continue;
2221
b7fc2769 2222 if (new_base >= max_regs)
477330fc
RM
2223 {
2224 first_error (_("register out of range in list"));
2225 return FAIL;
2226 }
5f4273c7 2227
5287ad62
JB
2228 /* Note: a value of 2 * n is returned for the register Q<n>. */
2229 if (regtype == REG_TYPE_NQ)
477330fc
RM
2230 {
2231 setmask = 3;
2232 addregs = 2;
2233 }
5287ad62 2234
c19d1205
ZW
2235 if (new_base < base_reg)
2236 base_reg = new_base;
a737bd4d 2237
5287ad62 2238 if (mask & (setmask << new_base))
c19d1205 2239 {
dcbf9037 2240 first_error (_("invalid register list"));
c19d1205 2241 return FAIL;
a737bd4d 2242 }
a737bd4d 2243
efd6b359 2244 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
c19d1205
ZW
2245 {
2246 as_tsktsk (_("register list not in ascending order"));
2247 warned = 1;
2248 }
0bbf2aa4 2249
5287ad62
JB
2250 mask |= setmask << new_base;
2251 count += addregs;
0bbf2aa4 2252
037e8744 2253 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
2254 {
2255 int high_range;
0bbf2aa4 2256
037e8744 2257 str++;
0bbf2aa4 2258
037e8744 2259 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 2260 == FAIL)
c19d1205
ZW
2261 {
2262 inst.error = gettext (reg_expected_msgs[regtype]);
2263 return FAIL;
2264 }
0bbf2aa4 2265
477330fc
RM
2266 if (high_range >= max_regs)
2267 {
2268 first_error (_("register out of range in list"));
2269 return FAIL;
2270 }
b7fc2769 2271
477330fc
RM
2272 if (regtype == REG_TYPE_NQ)
2273 high_range = high_range + 1;
5287ad62 2274
c19d1205
ZW
2275 if (high_range <= new_base)
2276 {
2277 inst.error = _("register range not in ascending order");
2278 return FAIL;
2279 }
0bbf2aa4 2280
5287ad62 2281 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 2282 {
5287ad62 2283 if (mask & (setmask << new_base))
0bbf2aa4 2284 {
c19d1205
ZW
2285 inst.error = _("invalid register list");
2286 return FAIL;
0bbf2aa4 2287 }
c19d1205 2288
5287ad62
JB
2289 mask |= setmask << new_base;
2290 count += addregs;
0bbf2aa4 2291 }
0bbf2aa4 2292 }
0bbf2aa4 2293 }
037e8744 2294 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 2295
037e8744 2296 str++;
0bbf2aa4 2297
c19d1205 2298 /* Sanity check -- should have raised a parse error above. */
efd6b359 2299 if ((!vpr_seen && count == 0) || count > max_regs)
c19d1205
ZW
2300 abort ();
2301
2302 *pbase = base_reg;
2303
efd6b359
AV
2304 if (expect_vpr && !vpr_seen)
2305 {
2306 first_error (_("VPR expected last"));
2307 return FAIL;
2308 }
2309
c19d1205
ZW
2310 /* Final test -- the registers must be consecutive. */
2311 mask >>= base_reg;
2312 for (i = 0; i < count; i++)
2313 {
2314 if ((mask & (1u << i)) == 0)
2315 {
2316 inst.error = _("non-contiguous register range");
2317 return FAIL;
2318 }
2319 }
2320
037e8744
JB
2321 *ccp = str;
2322
c19d1205 2323 return count;
b99bd4ef
NC
2324}
2325
dcbf9037
JB
2326/* True if two alias types are the same. */
2327
c921be7d 2328static bfd_boolean
dcbf9037
JB
2329neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2330{
2331 if (!a && !b)
c921be7d 2332 return TRUE;
5f4273c7 2333
dcbf9037 2334 if (!a || !b)
c921be7d 2335 return FALSE;
dcbf9037
JB
2336
2337 if (a->defined != b->defined)
c921be7d 2338 return FALSE;
5f4273c7 2339
dcbf9037
JB
2340 if ((a->defined & NTA_HASTYPE) != 0
2341 && (a->eltype.type != b->eltype.type
477330fc 2342 || a->eltype.size != b->eltype.size))
c921be7d 2343 return FALSE;
dcbf9037
JB
2344
2345 if ((a->defined & NTA_HASINDEX) != 0
2346 && (a->index != b->index))
c921be7d 2347 return FALSE;
5f4273c7 2348
c921be7d 2349 return TRUE;
dcbf9037
JB
2350}
2351
5287ad62
JB
2352/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2353 The base register is put in *PBASE.
dcbf9037 2354 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2355 the return value.
2356 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2357 Bits [6:5] encode the list length (minus one).
2358 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2359
5287ad62 2360#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2361#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2362#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2363
2364static int
dcbf9037 2365parse_neon_el_struct_list (char **str, unsigned *pbase,
35c228db 2366 int mve,
477330fc 2367 struct neon_type_el *eltype)
5287ad62
JB
2368{
2369 char *ptr = *str;
2370 int base_reg = -1;
2371 int reg_incr = -1;
2372 int count = 0;
2373 int lane = -1;
2374 int leading_brace = 0;
2375 enum arm_reg_type rtype = REG_TYPE_NDQ;
35c228db
AV
2376 const char *const incr_error = mve ? _("register stride must be 1") :
2377 _("register stride must be 1 or 2");
20203fb9 2378 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2379 struct neon_typed_alias firsttype;
f85d59c3
KT
2380 firsttype.defined = 0;
2381 firsttype.eltype.type = NT_invtype;
2382 firsttype.eltype.size = -1;
2383 firsttype.index = -1;
5f4273c7 2384
5287ad62
JB
2385 if (skip_past_char (&ptr, '{') == SUCCESS)
2386 leading_brace = 1;
5f4273c7 2387
5287ad62
JB
2388 do
2389 {
dcbf9037 2390 struct neon_typed_alias atype;
35c228db
AV
2391 if (mve)
2392 rtype = REG_TYPE_MQ;
dcbf9037
JB
2393 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2394
5287ad62 2395 if (getreg == FAIL)
477330fc
RM
2396 {
2397 first_error (_(reg_expected_msgs[rtype]));
2398 return FAIL;
2399 }
5f4273c7 2400
5287ad62 2401 if (base_reg == -1)
477330fc
RM
2402 {
2403 base_reg = getreg;
2404 if (rtype == REG_TYPE_NQ)
2405 {
2406 reg_incr = 1;
2407 }
2408 firsttype = atype;
2409 }
5287ad62 2410 else if (reg_incr == -1)
477330fc
RM
2411 {
2412 reg_incr = getreg - base_reg;
2413 if (reg_incr < 1 || reg_incr > 2)
2414 {
2415 first_error (_(incr_error));
2416 return FAIL;
2417 }
2418 }
5287ad62 2419 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2420 {
2421 first_error (_(incr_error));
2422 return FAIL;
2423 }
dcbf9037 2424
c921be7d 2425 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2426 {
2427 first_error (_(type_error));
2428 return FAIL;
2429 }
5f4273c7 2430
5287ad62 2431 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2432 modes. */
5287ad62 2433 if (ptr[0] == '-')
477330fc
RM
2434 {
2435 struct neon_typed_alias htype;
2436 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2437 if (lane == -1)
2438 lane = NEON_INTERLEAVE_LANES;
2439 else if (lane != NEON_INTERLEAVE_LANES)
2440 {
2441 first_error (_(type_error));
2442 return FAIL;
2443 }
2444 if (reg_incr == -1)
2445 reg_incr = 1;
2446 else if (reg_incr != 1)
2447 {
2448 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2449 return FAIL;
2450 }
2451 ptr++;
2452 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2453 if (hireg == FAIL)
2454 {
2455 first_error (_(reg_expected_msgs[rtype]));
2456 return FAIL;
2457 }
2458 if (! neon_alias_types_same (&htype, &firsttype))
2459 {
2460 first_error (_(type_error));
2461 return FAIL;
2462 }
2463 count += hireg + dregs - getreg;
2464 continue;
2465 }
5f4273c7 2466
5287ad62
JB
2467 /* If we're using Q registers, we can't use [] or [n] syntax. */
2468 if (rtype == REG_TYPE_NQ)
477330fc
RM
2469 {
2470 count += 2;
2471 continue;
2472 }
5f4273c7 2473
dcbf9037 2474 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2475 {
2476 if (lane == -1)
2477 lane = atype.index;
2478 else if (lane != atype.index)
2479 {
2480 first_error (_(type_error));
2481 return FAIL;
2482 }
2483 }
5287ad62 2484 else if (lane == -1)
477330fc 2485 lane = NEON_INTERLEAVE_LANES;
5287ad62 2486 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2487 {
2488 first_error (_(type_error));
2489 return FAIL;
2490 }
5287ad62
JB
2491 count++;
2492 }
2493 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2494
5287ad62
JB
2495 /* No lane set by [x]. We must be interleaving structures. */
2496 if (lane == -1)
2497 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2498
5287ad62 2499 /* Sanity check. */
35c228db 2500 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
5287ad62
JB
2501 || (count > 1 && reg_incr == -1))
2502 {
dcbf9037 2503 first_error (_("error parsing element/structure list"));
5287ad62
JB
2504 return FAIL;
2505 }
2506
2507 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2508 {
dcbf9037 2509 first_error (_("expected }"));
5287ad62
JB
2510 return FAIL;
2511 }
5f4273c7 2512
5287ad62
JB
2513 if (reg_incr == -1)
2514 reg_incr = 1;
2515
dcbf9037
JB
2516 if (eltype)
2517 *eltype = firsttype.eltype;
2518
5287ad62
JB
2519 *pbase = base_reg;
2520 *str = ptr;
5f4273c7 2521
5287ad62
JB
2522 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2523}
2524
c19d1205
ZW
2525/* Parse an explicit relocation suffix on an expression. This is
2526 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2527 arm_reloc_hsh contains no entries, so this function can only
2528 succeed if there is no () after the word. Returns -1 on error,
2529 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2530
c19d1205
ZW
2531static int
2532parse_reloc (char **str)
b99bd4ef 2533{
c19d1205
ZW
2534 struct reloc_entry *r;
2535 char *p, *q;
b99bd4ef 2536
c19d1205
ZW
2537 if (**str != '(')
2538 return BFD_RELOC_UNUSED;
b99bd4ef 2539
c19d1205
ZW
2540 p = *str + 1;
2541 q = p;
2542
2543 while (*q && *q != ')' && *q != ',')
2544 q++;
2545 if (*q != ')')
2546 return -1;
2547
21d799b5 2548 if ((r = (struct reloc_entry *)
629310ab 2549 str_hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2550 return -1;
2551
2552 *str = q + 1;
2553 return r->reloc;
b99bd4ef
NC
2554}
2555
c19d1205
ZW
2556/* Directives: register aliases. */
2557
dcbf9037 2558static struct reg_entry *
90ec0d68 2559insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2560{
d3ce72d0 2561 struct reg_entry *new_reg;
c19d1205 2562 const char *name;
b99bd4ef 2563
629310ab 2564 if ((new_reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2565 {
d3ce72d0 2566 if (new_reg->builtin)
c19d1205 2567 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2568
c19d1205
ZW
2569 /* Only warn about a redefinition if it's not defined as the
2570 same register. */
d3ce72d0 2571 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2572 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2573
d929913e 2574 return NULL;
c19d1205 2575 }
b99bd4ef 2576
c19d1205 2577 name = xstrdup (str);
325801bd 2578 new_reg = XNEW (struct reg_entry);
b99bd4ef 2579
d3ce72d0
NC
2580 new_reg->name = name;
2581 new_reg->number = number;
2582 new_reg->type = type;
2583 new_reg->builtin = FALSE;
2584 new_reg->neon = NULL;
b99bd4ef 2585
fe0e921f 2586 str_hash_insert (arm_reg_hsh, name, new_reg, 0);
5f4273c7 2587
d3ce72d0 2588 return new_reg;
dcbf9037
JB
2589}
2590
2591static void
2592insert_neon_reg_alias (char *str, int number, int type,
477330fc 2593 struct neon_typed_alias *atype)
dcbf9037
JB
2594{
2595 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2596
dcbf9037
JB
2597 if (!reg)
2598 {
2599 first_error (_("attempt to redefine typed alias"));
2600 return;
2601 }
5f4273c7 2602
dcbf9037
JB
2603 if (atype)
2604 {
325801bd 2605 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2606 *reg->neon = *atype;
2607 }
c19d1205 2608}
b99bd4ef 2609
c19d1205 2610/* Look for the .req directive. This is of the form:
b99bd4ef 2611
c19d1205 2612 new_register_name .req existing_register_name
b99bd4ef 2613
c19d1205 2614 If we find one, or if it looks sufficiently like one that we want to
d929913e 2615 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2616
d929913e 2617static bfd_boolean
c19d1205
ZW
2618create_register_alias (char * newname, char *p)
2619{
2620 struct reg_entry *old;
2621 char *oldname, *nbuf;
2622 size_t nlen;
b99bd4ef 2623
c19d1205
ZW
2624 /* The input scrubber ensures that whitespace after the mnemonic is
2625 collapsed to single spaces. */
2626 oldname = p;
2627 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2628 return FALSE;
b99bd4ef 2629
c19d1205
ZW
2630 oldname += 6;
2631 if (*oldname == '\0')
d929913e 2632 return FALSE;
b99bd4ef 2633
629310ab 2634 old = (struct reg_entry *) str_hash_find (arm_reg_hsh, oldname);
c19d1205 2635 if (!old)
b99bd4ef 2636 {
c19d1205 2637 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2638 return TRUE;
b99bd4ef
NC
2639 }
2640
c19d1205
ZW
2641 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2642 the desired alias name, and p points to its end. If not, then
2643 the desired alias name is in the global original_case_string. */
2644#ifdef TC_CASE_SENSITIVE
2645 nlen = p - newname;
2646#else
2647 newname = original_case_string;
2648 nlen = strlen (newname);
2649#endif
b99bd4ef 2650
29a2809e 2651 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2652
c19d1205
ZW
2653 /* Create aliases under the new name as stated; an all-lowercase
2654 version of the new name; and an all-uppercase version of the new
2655 name. */
d929913e
NC
2656 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2657 {
2658 for (p = nbuf; *p; p++)
2659 *p = TOUPPER (*p);
c19d1205 2660
d929913e
NC
2661 if (strncmp (nbuf, newname, nlen))
2662 {
2663 /* If this attempt to create an additional alias fails, do not bother
2664 trying to create the all-lower case alias. We will fail and issue
2665 a second, duplicate error message. This situation arises when the
2666 programmer does something like:
2667 foo .req r0
2668 Foo .req r1
2669 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2670 the artificial FOO alias because it has already been created by the
d929913e
NC
2671 first .req. */
2672 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2673 {
2674 free (nbuf);
2675 return TRUE;
2676 }
d929913e 2677 }
c19d1205 2678
d929913e
NC
2679 for (p = nbuf; *p; p++)
2680 *p = TOLOWER (*p);
c19d1205 2681
d929913e
NC
2682 if (strncmp (nbuf, newname, nlen))
2683 insert_reg_alias (nbuf, old->number, old->type);
2684 }
c19d1205 2685
e1fa0163 2686 free (nbuf);
d929913e 2687 return TRUE;
b99bd4ef
NC
2688}
2689
dcbf9037
JB
2690/* Create a Neon typed/indexed register alias using directives, e.g.:
2691 X .dn d5.s32[1]
2692 Y .qn 6.s16
2693 Z .dn d7
2694 T .dn Z[0]
2695 These typed registers can be used instead of the types specified after the
2696 Neon mnemonic, so long as all operands given have types. Types can also be
2697 specified directly, e.g.:
5f4273c7 2698 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2699
c921be7d 2700static bfd_boolean
dcbf9037
JB
2701create_neon_reg_alias (char *newname, char *p)
2702{
2703 enum arm_reg_type basetype;
2704 struct reg_entry *basereg;
2705 struct reg_entry mybasereg;
2706 struct neon_type ntype;
2707 struct neon_typed_alias typeinfo;
12d6b0b7 2708 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2709 int namelen;
5f4273c7 2710
dcbf9037
JB
2711 typeinfo.defined = 0;
2712 typeinfo.eltype.type = NT_invtype;
2713 typeinfo.eltype.size = -1;
2714 typeinfo.index = -1;
5f4273c7 2715
dcbf9037 2716 nameend = p;
5f4273c7 2717
dcbf9037
JB
2718 if (strncmp (p, " .dn ", 5) == 0)
2719 basetype = REG_TYPE_VFD;
2720 else if (strncmp (p, " .qn ", 5) == 0)
2721 basetype = REG_TYPE_NQ;
2722 else
c921be7d 2723 return FALSE;
5f4273c7 2724
dcbf9037 2725 p += 5;
5f4273c7 2726
dcbf9037 2727 if (*p == '\0')
c921be7d 2728 return FALSE;
5f4273c7 2729
dcbf9037
JB
2730 basereg = arm_reg_parse_multi (&p);
2731
2732 if (basereg && basereg->type != basetype)
2733 {
2734 as_bad (_("bad type for register"));
c921be7d 2735 return FALSE;
dcbf9037
JB
2736 }
2737
2738 if (basereg == NULL)
2739 {
2740 expressionS exp;
2741 /* Try parsing as an integer. */
2742 my_get_expression (&exp, &p, GE_NO_PREFIX);
2743 if (exp.X_op != O_constant)
477330fc
RM
2744 {
2745 as_bad (_("expression must be constant"));
2746 return FALSE;
2747 }
dcbf9037
JB
2748 basereg = &mybasereg;
2749 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2750 : exp.X_add_number;
dcbf9037
JB
2751 basereg->neon = 0;
2752 }
2753
2754 if (basereg->neon)
2755 typeinfo = *basereg->neon;
2756
2757 if (parse_neon_type (&ntype, &p) == SUCCESS)
2758 {
2759 /* We got a type. */
2760 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2761 {
2762 as_bad (_("can't redefine the type of a register alias"));
2763 return FALSE;
2764 }
5f4273c7 2765
dcbf9037
JB
2766 typeinfo.defined |= NTA_HASTYPE;
2767 if (ntype.elems != 1)
477330fc
RM
2768 {
2769 as_bad (_("you must specify a single type only"));
2770 return FALSE;
2771 }
dcbf9037
JB
2772 typeinfo.eltype = ntype.el[0];
2773 }
5f4273c7 2774
dcbf9037
JB
2775 if (skip_past_char (&p, '[') == SUCCESS)
2776 {
2777 expressionS exp;
2778 /* We got a scalar index. */
5f4273c7 2779
dcbf9037 2780 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2781 {
2782 as_bad (_("can't redefine the index of a scalar alias"));
2783 return FALSE;
2784 }
5f4273c7 2785
dcbf9037 2786 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2787
dcbf9037 2788 if (exp.X_op != O_constant)
477330fc
RM
2789 {
2790 as_bad (_("scalar index must be constant"));
2791 return FALSE;
2792 }
5f4273c7 2793
dcbf9037
JB
2794 typeinfo.defined |= NTA_HASINDEX;
2795 typeinfo.index = exp.X_add_number;
5f4273c7 2796
dcbf9037 2797 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2798 {
2799 as_bad (_("expecting ]"));
2800 return FALSE;
2801 }
dcbf9037
JB
2802 }
2803
15735687
NS
2804 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2805 the desired alias name, and p points to its end. If not, then
2806 the desired alias name is in the global original_case_string. */
2807#ifdef TC_CASE_SENSITIVE
dcbf9037 2808 namelen = nameend - newname;
15735687
NS
2809#else
2810 newname = original_case_string;
2811 namelen = strlen (newname);
2812#endif
2813
29a2809e 2814 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2815
dcbf9037 2816 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2817 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2818
dcbf9037
JB
2819 /* Insert name in all uppercase. */
2820 for (p = namebuf; *p; p++)
2821 *p = TOUPPER (*p);
5f4273c7 2822
dcbf9037
JB
2823 if (strncmp (namebuf, newname, namelen))
2824 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2825 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2826
dcbf9037
JB
2827 /* Insert name in all lowercase. */
2828 for (p = namebuf; *p; p++)
2829 *p = TOLOWER (*p);
5f4273c7 2830
dcbf9037
JB
2831 if (strncmp (namebuf, newname, namelen))
2832 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2833 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2834
e1fa0163 2835 free (namebuf);
c921be7d 2836 return TRUE;
dcbf9037
JB
2837}
2838
c19d1205
ZW
2839/* Should never be called, as .req goes between the alias and the
2840 register name, not at the beginning of the line. */
c921be7d 2841
b99bd4ef 2842static void
c19d1205 2843s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2844{
c19d1205
ZW
2845 as_bad (_("invalid syntax for .req directive"));
2846}
b99bd4ef 2847
dcbf9037
JB
2848static void
2849s_dn (int a ATTRIBUTE_UNUSED)
2850{
2851 as_bad (_("invalid syntax for .dn directive"));
2852}
2853
2854static void
2855s_qn (int a ATTRIBUTE_UNUSED)
2856{
2857 as_bad (_("invalid syntax for .qn directive"));
2858}
2859
c19d1205
ZW
2860/* The .unreq directive deletes an alias which was previously defined
2861 by .req. For example:
b99bd4ef 2862
c19d1205
ZW
2863 my_alias .req r11
2864 .unreq my_alias */
b99bd4ef
NC
2865
2866static void
c19d1205 2867s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2868{
c19d1205
ZW
2869 char * name;
2870 char saved_char;
b99bd4ef 2871
c19d1205
ZW
2872 name = input_line_pointer;
2873
2874 while (*input_line_pointer != 0
2875 && *input_line_pointer != ' '
2876 && *input_line_pointer != '\n')
2877 ++input_line_pointer;
2878
2879 saved_char = *input_line_pointer;
2880 *input_line_pointer = 0;
2881
2882 if (!*name)
2883 as_bad (_("invalid syntax for .unreq directive"));
2884 else
2885 {
fe0e921f
AM
2886 struct reg_entry *reg
2887 = (struct reg_entry *) str_hash_find (arm_reg_hsh, name);
c19d1205
ZW
2888
2889 if (!reg)
2890 as_bad (_("unknown register alias '%s'"), name);
2891 else if (reg->builtin)
a1727c1a 2892 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2893 name);
2894 else
2895 {
d929913e
NC
2896 char * p;
2897 char * nbuf;
2898
629310ab 2899 str_hash_delete (arm_reg_hsh, name);
c19d1205 2900 free ((char *) reg->name);
9fbb53c7 2901 free (reg->neon);
c19d1205 2902 free (reg);
d929913e
NC
2903
2904 /* Also locate the all upper case and all lower case versions.
2905 Do not complain if we cannot find one or the other as it
2906 was probably deleted above. */
5f4273c7 2907
d929913e
NC
2908 nbuf = strdup (name);
2909 for (p = nbuf; *p; p++)
2910 *p = TOUPPER (*p);
629310ab 2911 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2912 if (reg)
2913 {
629310ab 2914 str_hash_delete (arm_reg_hsh, nbuf);
d929913e 2915 free ((char *) reg->name);
9fbb53c7 2916 free (reg->neon);
d929913e
NC
2917 free (reg);
2918 }
2919
2920 for (p = nbuf; *p; p++)
2921 *p = TOLOWER (*p);
629310ab 2922 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2923 if (reg)
2924 {
629310ab 2925 str_hash_delete (arm_reg_hsh, nbuf);
d929913e 2926 free ((char *) reg->name);
9fbb53c7 2927 free (reg->neon);
d929913e
NC
2928 free (reg);
2929 }
2930
2931 free (nbuf);
c19d1205
ZW
2932 }
2933 }
b99bd4ef 2934
c19d1205 2935 *input_line_pointer = saved_char;
b99bd4ef
NC
2936 demand_empty_rest_of_line ();
2937}
2938
c19d1205
ZW
2939/* Directives: Instruction set selection. */
2940
2941#ifdef OBJ_ELF
2942/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2943 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2944 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2945 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2946
cd000bff
DJ
2947/* Create a new mapping symbol for the transition to STATE. */
2948
2949static void
2950make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2951{
a737bd4d 2952 symbolS * symbolP;
c19d1205
ZW
2953 const char * symname;
2954 int type;
b99bd4ef 2955
c19d1205 2956 switch (state)
b99bd4ef 2957 {
c19d1205
ZW
2958 case MAP_DATA:
2959 symname = "$d";
2960 type = BSF_NO_FLAGS;
2961 break;
2962 case MAP_ARM:
2963 symname = "$a";
2964 type = BSF_NO_FLAGS;
2965 break;
2966 case MAP_THUMB:
2967 symname = "$t";
2968 type = BSF_NO_FLAGS;
2969 break;
c19d1205
ZW
2970 default:
2971 abort ();
2972 }
2973
e01e1cee 2974 symbolP = symbol_new (symname, now_seg, frag, value);
c19d1205
ZW
2975 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2976
2977 switch (state)
2978 {
2979 case MAP_ARM:
2980 THUMB_SET_FUNC (symbolP, 0);
2981 ARM_SET_THUMB (symbolP, 0);
2982 ARM_SET_INTERWORK (symbolP, support_interwork);
2983 break;
2984
2985 case MAP_THUMB:
2986 THUMB_SET_FUNC (symbolP, 1);
2987 ARM_SET_THUMB (symbolP, 1);
2988 ARM_SET_INTERWORK (symbolP, support_interwork);
2989 break;
2990
2991 case MAP_DATA:
2992 default:
cd000bff
DJ
2993 break;
2994 }
2995
2996 /* Save the mapping symbols for future reference. Also check that
2997 we do not place two mapping symbols at the same offset within a
2998 frag. We'll handle overlap between frags in
2de7820f
JZ
2999 check_mapping_symbols.
3000
3001 If .fill or other data filling directive generates zero sized data,
3002 the mapping symbol for the following code will have the same value
3003 as the one generated for the data filling directive. In this case,
3004 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
3005 if (value == 0)
3006 {
2de7820f
JZ
3007 if (frag->tc_frag_data.first_map != NULL)
3008 {
3009 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3010 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3011 }
cd000bff
DJ
3012 frag->tc_frag_data.first_map = symbolP;
3013 }
3014 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
3015 {
3016 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
3017 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3018 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3019 }
cd000bff
DJ
3020 frag->tc_frag_data.last_map = symbolP;
3021}
3022
3023/* We must sometimes convert a region marked as code to data during
3024 code alignment, if an odd number of bytes have to be padded. The
3025 code mapping symbol is pushed to an aligned address. */
3026
3027static void
3028insert_data_mapping_symbol (enum mstate state,
3029 valueT value, fragS *frag, offsetT bytes)
3030{
3031 /* If there was already a mapping symbol, remove it. */
3032 if (frag->tc_frag_data.last_map != NULL
3033 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3034 {
3035 symbolS *symp = frag->tc_frag_data.last_map;
3036
3037 if (value == 0)
3038 {
3039 know (frag->tc_frag_data.first_map == symp);
3040 frag->tc_frag_data.first_map = NULL;
3041 }
3042 frag->tc_frag_data.last_map = NULL;
3043 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 3044 }
cd000bff
DJ
3045
3046 make_mapping_symbol (MAP_DATA, value, frag);
3047 make_mapping_symbol (state, value + bytes, frag);
3048}
3049
3050static void mapping_state_2 (enum mstate state, int max_chars);
3051
3052/* Set the mapping state to STATE. Only call this when about to
3053 emit some STATE bytes to the file. */
3054
4e9aaefb 3055#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
3056void
3057mapping_state (enum mstate state)
3058{
940b5ce0
DJ
3059 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3060
cd000bff
DJ
3061 if (mapstate == state)
3062 /* The mapping symbol has already been emitted.
3063 There is nothing else to do. */
3064 return;
49c62a33
NC
3065
3066 if (state == MAP_ARM || state == MAP_THUMB)
3067 /* PR gas/12931
3068 All ARM instructions require 4-byte alignment.
3069 (Almost) all Thumb instructions require 2-byte alignment.
3070
3071 When emitting instructions into any section, mark the section
3072 appropriately.
3073
3074 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3075 but themselves require 2-byte alignment; this applies to some
33eaf5de 3076 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
3077 literal pool generation or an explicit .align >=2, both of
3078 which will cause the section to me marked with sufficient
3079 alignment. Thus, we don't handle those cases here. */
3080 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3081
3082 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 3083 /* This case will be evaluated later. */
cd000bff 3084 return;
cd000bff
DJ
3085
3086 mapping_state_2 (state, 0);
cd000bff
DJ
3087}
3088
3089/* Same as mapping_state, but MAX_CHARS bytes have already been
3090 allocated. Put the mapping symbol that far back. */
3091
3092static void
3093mapping_state_2 (enum mstate state, int max_chars)
3094{
940b5ce0
DJ
3095 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3096
3097 if (!SEG_NORMAL (now_seg))
3098 return;
3099
cd000bff
DJ
3100 if (mapstate == state)
3101 /* The mapping symbol has already been emitted.
3102 There is nothing else to do. */
3103 return;
3104
4e9aaefb
SA
3105 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3106 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3107 {
3108 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3109 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3110
3111 if (add_symbol)
3112 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3113 }
3114
cd000bff
DJ
3115 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3116 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 3117}
4e9aaefb 3118#undef TRANSITION
c19d1205 3119#else
d3106081
NS
3120#define mapping_state(x) ((void)0)
3121#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
3122#endif
3123
3124/* Find the real, Thumb encoded start of a Thumb function. */
3125
4343666d 3126#ifdef OBJ_COFF
c19d1205
ZW
3127static symbolS *
3128find_real_start (symbolS * symbolP)
3129{
3130 char * real_start;
3131 const char * name = S_GET_NAME (symbolP);
3132 symbolS * new_target;
3133
3134 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3135#define STUB_NAME ".real_start_of"
3136
3137 if (name == NULL)
3138 abort ();
3139
37f6032b
ZW
3140 /* The compiler may generate BL instructions to local labels because
3141 it needs to perform a branch to a far away location. These labels
3142 do not have a corresponding ".real_start_of" label. We check
3143 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3144 the ".real_start_of" convention for nonlocal branches. */
3145 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
3146 return symbolP;
3147
e1fa0163 3148 real_start = concat (STUB_NAME, name, NULL);
c19d1205 3149 new_target = symbol_find (real_start);
e1fa0163 3150 free (real_start);
c19d1205
ZW
3151
3152 if (new_target == NULL)
3153 {
bd3ba5d1 3154 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
3155 new_target = symbolP;
3156 }
3157
c19d1205
ZW
3158 return new_target;
3159}
4343666d 3160#endif
c19d1205
ZW
3161
3162static void
3163opcode_select (int width)
3164{
3165 switch (width)
3166 {
3167 case 16:
3168 if (! thumb_mode)
3169 {
e74cfd16 3170 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
3171 as_bad (_("selected processor does not support THUMB opcodes"));
3172
3173 thumb_mode = 1;
3174 /* No need to force the alignment, since we will have been
3175 coming from ARM mode, which is word-aligned. */
3176 record_alignment (now_seg, 1);
3177 }
c19d1205
ZW
3178 break;
3179
3180 case 32:
3181 if (thumb_mode)
3182 {
e74cfd16 3183 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
3184 as_bad (_("selected processor does not support ARM opcodes"));
3185
3186 thumb_mode = 0;
3187
3188 if (!need_pass_2)
3189 frag_align (2, 0, 0);
3190
3191 record_alignment (now_seg, 1);
3192 }
c19d1205
ZW
3193 break;
3194
3195 default:
3196 as_bad (_("invalid instruction size selected (%d)"), width);
3197 }
3198}
3199
3200static void
3201s_arm (int ignore ATTRIBUTE_UNUSED)
3202{
3203 opcode_select (32);
3204 demand_empty_rest_of_line ();
3205}
3206
3207static void
3208s_thumb (int ignore ATTRIBUTE_UNUSED)
3209{
3210 opcode_select (16);
3211 demand_empty_rest_of_line ();
3212}
3213
3214static void
3215s_code (int unused ATTRIBUTE_UNUSED)
3216{
3217 int temp;
3218
3219 temp = get_absolute_expression ();
3220 switch (temp)
3221 {
3222 case 16:
3223 case 32:
3224 opcode_select (temp);
3225 break;
3226
3227 default:
3228 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3229 }
3230}
3231
3232static void
3233s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3234{
3235 /* If we are not already in thumb mode go into it, EVEN if
3236 the target processor does not support thumb instructions.
3237 This is used by gcc/config/arm/lib1funcs.asm for example
3238 to compile interworking support functions even if the
3239 target processor should not support interworking. */
3240 if (! thumb_mode)
3241 {
3242 thumb_mode = 2;
3243 record_alignment (now_seg, 1);
3244 }
3245
3246 demand_empty_rest_of_line ();
3247}
3248
3249static void
3250s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3251{
3252 s_thumb (0);
3253
3254 /* The following label is the name/address of the start of a Thumb function.
3255 We need to know this for the interworking support. */
3256 label_is_thumb_function_name = TRUE;
3257}
3258
3259/* Perform a .set directive, but also mark the alias as
3260 being a thumb function. */
3261
3262static void
3263s_thumb_set (int equiv)
3264{
3265 /* XXX the following is a duplicate of the code for s_set() in read.c
3266 We cannot just call that code as we need to get at the symbol that
3267 is created. */
3268 char * name;
3269 char delim;
3270 char * end_name;
3271 symbolS * symbolP;
3272
3273 /* Especial apologies for the random logic:
3274 This just grew, and could be parsed much more simply!
3275 Dean - in haste. */
d02603dc 3276 delim = get_symbol_name (& name);
c19d1205 3277 end_name = input_line_pointer;
d02603dc 3278 (void) restore_line_pointer (delim);
c19d1205
ZW
3279
3280 if (*input_line_pointer != ',')
3281 {
3282 *end_name = 0;
3283 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
3284 *end_name = delim;
3285 ignore_rest_of_line ();
3286 return;
3287 }
3288
3289 input_line_pointer++;
3290 *end_name = 0;
3291
3292 if (name[0] == '.' && name[1] == '\0')
3293 {
3294 /* XXX - this should not happen to .thumb_set. */
3295 abort ();
3296 }
3297
3298 if ((symbolP = symbol_find (name)) == NULL
3299 && (symbolP = md_undefined_symbol (name)) == NULL)
3300 {
3301#ifndef NO_LISTING
3302 /* When doing symbol listings, play games with dummy fragments living
3303 outside the normal fragment chain to record the file and line info
c19d1205 3304 for this symbol. */
b99bd4ef
NC
3305 if (listing & LISTING_SYMBOLS)
3306 {
3307 extern struct list_info_struct * listing_tail;
21d799b5 3308 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
3309
3310 memset (dummy_frag, 0, sizeof (fragS));
3311 dummy_frag->fr_type = rs_fill;
3312 dummy_frag->line = listing_tail;
e01e1cee 3313 symbolP = symbol_new (name, undefined_section, dummy_frag, 0);
b99bd4ef
NC
3314 dummy_frag->fr_symbol = symbolP;
3315 }
3316 else
3317#endif
e01e1cee 3318 symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0);
b99bd4ef
NC
3319
3320#ifdef OBJ_COFF
3321 /* "set" symbols are local unless otherwise specified. */
3322 SF_SET_LOCAL (symbolP);
3323#endif /* OBJ_COFF */
3324 } /* Make a new symbol. */
3325
3326 symbol_table_insert (symbolP);
3327
3328 * end_name = delim;
3329
3330 if (equiv
3331 && S_IS_DEFINED (symbolP)
3332 && S_GET_SEGMENT (symbolP) != reg_section)
3333 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3334
3335 pseudo_set (symbolP);
3336
3337 demand_empty_rest_of_line ();
3338
c19d1205 3339 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3340
3341 THUMB_SET_FUNC (symbolP, 1);
3342 ARM_SET_THUMB (symbolP, 1);
3343#if defined OBJ_ELF || defined OBJ_COFF
3344 ARM_SET_INTERWORK (symbolP, support_interwork);
3345#endif
3346}
3347
c19d1205 3348/* Directives: Mode selection. */
b99bd4ef 3349
c19d1205
ZW
3350/* .syntax [unified|divided] - choose the new unified syntax
3351 (same for Arm and Thumb encoding, modulo slight differences in what
3352 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3353static void
c19d1205 3354s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3355{
c19d1205
ZW
3356 char *name, delim;
3357
d02603dc 3358 delim = get_symbol_name (& name);
c19d1205
ZW
3359
3360 if (!strcasecmp (name, "unified"))
3361 unified_syntax = TRUE;
3362 else if (!strcasecmp (name, "divided"))
3363 unified_syntax = FALSE;
3364 else
3365 {
3366 as_bad (_("unrecognized syntax mode \"%s\""), name);
3367 return;
3368 }
d02603dc 3369 (void) restore_line_pointer (delim);
b99bd4ef
NC
3370 demand_empty_rest_of_line ();
3371}
3372
c19d1205
ZW
3373/* Directives: sectioning and alignment. */
3374
c19d1205
ZW
3375static void
3376s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3377{
c19d1205
ZW
3378 /* We don't support putting frags in the BSS segment, we fake it by
3379 marking in_bss, then looking at s_skip for clues. */
3380 subseg_set (bss_section, 0);
3381 demand_empty_rest_of_line ();
cd000bff
DJ
3382
3383#ifdef md_elf_section_change_hook
3384 md_elf_section_change_hook ();
3385#endif
c19d1205 3386}
b99bd4ef 3387
c19d1205
ZW
3388static void
3389s_even (int ignore ATTRIBUTE_UNUSED)
3390{
3391 /* Never make frag if expect extra pass. */
3392 if (!need_pass_2)
3393 frag_align (1, 0, 0);
b99bd4ef 3394
c19d1205 3395 record_alignment (now_seg, 1);
b99bd4ef 3396
c19d1205 3397 demand_empty_rest_of_line ();
b99bd4ef
NC
3398}
3399
2e6976a8
DG
3400/* Directives: CodeComposer Studio. */
3401
3402/* .ref (for CodeComposer Studio syntax only). */
3403static void
3404s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3405{
3406 if (codecomposer_syntax)
3407 ignore_rest_of_line ();
3408 else
3409 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3410}
3411
3412/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3413 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3414static void
3415asmfunc_debug (const char * name)
3416{
3417 static const char * last_name = NULL;
3418
3419 if (name != NULL)
3420 {
3421 gas_assert (last_name == NULL);
3422 last_name = name;
3423
3424 if (debug_type == DEBUG_STABS)
3425 stabs_generate_asm_func (name, name);
3426 }
3427 else
3428 {
3429 gas_assert (last_name != NULL);
3430
3431 if (debug_type == DEBUG_STABS)
3432 stabs_generate_asm_endfunc (last_name, last_name);
3433
3434 last_name = NULL;
3435 }
3436}
3437
3438static void
3439s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3440{
3441 if (codecomposer_syntax)
3442 {
3443 switch (asmfunc_state)
3444 {
3445 case OUTSIDE_ASMFUNC:
3446 asmfunc_state = WAITING_ASMFUNC_NAME;
3447 break;
3448
3449 case WAITING_ASMFUNC_NAME:
3450 as_bad (_(".asmfunc repeated."));
3451 break;
3452
3453 case WAITING_ENDASMFUNC:
3454 as_bad (_(".asmfunc without function."));
3455 break;
3456 }
3457 demand_empty_rest_of_line ();
3458 }
3459 else
3460 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3461}
3462
3463static void
3464s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3465{
3466 if (codecomposer_syntax)
3467 {
3468 switch (asmfunc_state)
3469 {
3470 case OUTSIDE_ASMFUNC:
3471 as_bad (_(".endasmfunc without a .asmfunc."));
3472 break;
3473
3474 case WAITING_ASMFUNC_NAME:
3475 as_bad (_(".endasmfunc without function."));
3476 break;
3477
3478 case WAITING_ENDASMFUNC:
3479 asmfunc_state = OUTSIDE_ASMFUNC;
3480 asmfunc_debug (NULL);
3481 break;
3482 }
3483 demand_empty_rest_of_line ();
3484 }
3485 else
3486 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3487}
3488
3489static void
3490s_ccs_def (int name)
3491{
3492 if (codecomposer_syntax)
3493 s_globl (name);
3494 else
3495 as_bad (_(".def pseudo-op only available with -mccs flag."));
3496}
3497
c19d1205 3498/* Directives: Literal pools. */
a737bd4d 3499
c19d1205
ZW
3500static literal_pool *
3501find_literal_pool (void)
a737bd4d 3502{
c19d1205 3503 literal_pool * pool;
a737bd4d 3504
c19d1205 3505 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3506 {
c19d1205
ZW
3507 if (pool->section == now_seg
3508 && pool->sub_section == now_subseg)
3509 break;
a737bd4d
NC
3510 }
3511
c19d1205 3512 return pool;
a737bd4d
NC
3513}
3514
c19d1205
ZW
3515static literal_pool *
3516find_or_make_literal_pool (void)
a737bd4d 3517{
c19d1205
ZW
3518 /* Next literal pool ID number. */
3519 static unsigned int latest_pool_num = 1;
3520 literal_pool * pool;
a737bd4d 3521
c19d1205 3522 pool = find_literal_pool ();
a737bd4d 3523
c19d1205 3524 if (pool == NULL)
a737bd4d 3525 {
c19d1205 3526 /* Create a new pool. */
325801bd 3527 pool = XNEW (literal_pool);
c19d1205
ZW
3528 if (! pool)
3529 return NULL;
a737bd4d 3530
c19d1205
ZW
3531 pool->next_free_entry = 0;
3532 pool->section = now_seg;
3533 pool->sub_section = now_subseg;
3534 pool->next = list_of_pools;
3535 pool->symbol = NULL;
8335d6aa 3536 pool->alignment = 2;
c19d1205
ZW
3537
3538 /* Add it to the list. */
3539 list_of_pools = pool;
a737bd4d 3540 }
a737bd4d 3541
c19d1205
ZW
3542 /* New pools, and emptied pools, will have a NULL symbol. */
3543 if (pool->symbol == NULL)
a737bd4d 3544 {
c19d1205 3545 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
e01e1cee 3546 &zero_address_frag, 0);
c19d1205 3547 pool->id = latest_pool_num ++;
a737bd4d
NC
3548 }
3549
c19d1205
ZW
3550 /* Done. */
3551 return pool;
a737bd4d
NC
3552}
3553
c19d1205 3554/* Add the literal in the global 'inst'
5f4273c7 3555 structure to the relevant literal pool. */
b99bd4ef
NC
3556
3557static int
8335d6aa 3558add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3559{
8335d6aa
JW
3560#define PADDING_SLOT 0x1
3561#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3562 literal_pool * pool;
8335d6aa
JW
3563 unsigned int entry, pool_size = 0;
3564 bfd_boolean padding_slot_p = FALSE;
e56c722b 3565 unsigned imm1 = 0;
8335d6aa
JW
3566 unsigned imm2 = 0;
3567
3568 if (nbytes == 8)
3569 {
3570 imm1 = inst.operands[1].imm;
3571 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
e2b0ab59 3572 : inst.relocs[0].exp.X_unsigned ? 0
2569ceb0 3573 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3574 if (target_big_endian)
3575 {
3576 imm1 = imm2;
3577 imm2 = inst.operands[1].imm;
3578 }
3579 }
b99bd4ef 3580
c19d1205
ZW
3581 pool = find_or_make_literal_pool ();
3582
3583 /* Check if this literal value is already in the pool. */
3584 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3585 {
8335d6aa
JW
3586 if (nbytes == 4)
3587 {
e2b0ab59
AV
3588 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3589 && (inst.relocs[0].exp.X_op == O_constant)
8335d6aa 3590 && (pool->literals[entry].X_add_number
e2b0ab59 3591 == inst.relocs[0].exp.X_add_number)
8335d6aa
JW
3592 && (pool->literals[entry].X_md == nbytes)
3593 && (pool->literals[entry].X_unsigned
e2b0ab59 3594 == inst.relocs[0].exp.X_unsigned))
8335d6aa
JW
3595 break;
3596
e2b0ab59
AV
3597 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3598 && (inst.relocs[0].exp.X_op == O_symbol)
8335d6aa 3599 && (pool->literals[entry].X_add_number
e2b0ab59 3600 == inst.relocs[0].exp.X_add_number)
8335d6aa 3601 && (pool->literals[entry].X_add_symbol
e2b0ab59 3602 == inst.relocs[0].exp.X_add_symbol)
8335d6aa 3603 && (pool->literals[entry].X_op_symbol
e2b0ab59 3604 == inst.relocs[0].exp.X_op_symbol)
8335d6aa
JW
3605 && (pool->literals[entry].X_md == nbytes))
3606 break;
3607 }
3608 else if ((nbytes == 8)
3609 && !(pool_size & 0x7)
3610 && ((entry + 1) != pool->next_free_entry)
3611 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3612 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa 3613 && (pool->literals[entry].X_unsigned
e2b0ab59 3614 == inst.relocs[0].exp.X_unsigned)
8335d6aa 3615 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3616 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa 3617 && (pool->literals[entry + 1].X_unsigned
e2b0ab59 3618 == inst.relocs[0].exp.X_unsigned))
c19d1205
ZW
3619 break;
3620
8335d6aa
JW
3621 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3622 if (padding_slot_p && (nbytes == 4))
c19d1205 3623 break;
8335d6aa
JW
3624
3625 pool_size += 4;
b99bd4ef
NC
3626 }
3627
c19d1205
ZW
3628 /* Do we need to create a new entry? */
3629 if (entry == pool->next_free_entry)
3630 {
3631 if (entry >= MAX_LITERAL_POOL_SIZE)
3632 {
3633 inst.error = _("literal pool overflow");
3634 return FAIL;
3635 }
3636
8335d6aa
JW
3637 if (nbytes == 8)
3638 {
3639 /* For 8-byte entries, we align to an 8-byte boundary,
3640 and split it into two 4-byte entries, because on 32-bit
3641 host, 8-byte constants are treated as big num, thus
3642 saved in "generic_bignum" which will be overwritten
3643 by later assignments.
3644
3645 We also need to make sure there is enough space for
3646 the split.
3647
3648 We also check to make sure the literal operand is a
3649 constant number. */
e2b0ab59
AV
3650 if (!(inst.relocs[0].exp.X_op == O_constant
3651 || inst.relocs[0].exp.X_op == O_big))
8335d6aa
JW
3652 {
3653 inst.error = _("invalid type for literal pool");
3654 return FAIL;
3655 }
3656 else if (pool_size & 0x7)
3657 {
3658 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3659 {
3660 inst.error = _("literal pool overflow");
3661 return FAIL;
3662 }
3663
e2b0ab59 3664 pool->literals[entry] = inst.relocs[0].exp;
a6684f0d 3665 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3666 pool->literals[entry].X_add_number = 0;
3667 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3668 pool->next_free_entry += 1;
3669 pool_size += 4;
3670 }
3671 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3672 {
3673 inst.error = _("literal pool overflow");
3674 return FAIL;
3675 }
3676
e2b0ab59 3677 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3678 pool->literals[entry].X_op = O_constant;
3679 pool->literals[entry].X_add_number = imm1;
e2b0ab59 3680 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa 3681 pool->literals[entry++].X_md = 4;
e2b0ab59 3682 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3683 pool->literals[entry].X_op = O_constant;
3684 pool->literals[entry].X_add_number = imm2;
e2b0ab59 3685 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
8335d6aa
JW
3686 pool->literals[entry].X_md = 4;
3687 pool->alignment = 3;
3688 pool->next_free_entry += 1;
3689 }
3690 else
3691 {
e2b0ab59 3692 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3693 pool->literals[entry].X_md = 4;
3694 }
3695
a8040cf2
NC
3696#ifdef OBJ_ELF
3697 /* PR ld/12974: Record the location of the first source line to reference
3698 this entry in the literal pool. If it turns out during linking that the
3699 symbol does not exist we will be able to give an accurate line number for
3700 the (first use of the) missing reference. */
3701 if (debug_type == DEBUG_DWARF2)
3702 dwarf2_where (pool->locs + entry);
3703#endif
c19d1205
ZW
3704 pool->next_free_entry += 1;
3705 }
8335d6aa
JW
3706 else if (padding_slot_p)
3707 {
e2b0ab59 3708 pool->literals[entry] = inst.relocs[0].exp;
8335d6aa
JW
3709 pool->literals[entry].X_md = nbytes;
3710 }
b99bd4ef 3711
e2b0ab59
AV
3712 inst.relocs[0].exp.X_op = O_symbol;
3713 inst.relocs[0].exp.X_add_number = pool_size;
3714 inst.relocs[0].exp.X_add_symbol = pool->symbol;
b99bd4ef 3715
c19d1205 3716 return SUCCESS;
b99bd4ef
NC
3717}
3718
2e6976a8 3719bfd_boolean
2e57ce7b 3720tc_start_label_without_colon (void)
2e6976a8
DG
3721{
3722 bfd_boolean ret = TRUE;
3723
3724 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3725 {
2e57ce7b 3726 const char *label = input_line_pointer;
2e6976a8
DG
3727
3728 while (!is_end_of_line[(int) label[-1]])
3729 --label;
3730
3731 if (*label == '.')
3732 {
3733 as_bad (_("Invalid label '%s'"), label);
3734 ret = FALSE;
3735 }
3736
3737 asmfunc_debug (label);
3738
3739 asmfunc_state = WAITING_ENDASMFUNC;
3740 }
3741
3742 return ret;
3743}
3744
c19d1205 3745/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3746 a later date assign it a value. That's what these functions do. */
e16bb312 3747
c19d1205
ZW
3748static void
3749symbol_locate (symbolS * symbolP,
3750 const char * name, /* It is copied, the caller can modify. */
3751 segT segment, /* Segment identifier (SEG_<something>). */
3752 valueT valu, /* Symbol value. */
3753 fragS * frag) /* Associated fragment. */
3754{
e57e6ddc 3755 size_t name_length;
c19d1205 3756 char * preserved_copy_of_name;
e16bb312 3757
c19d1205
ZW
3758 name_length = strlen (name) + 1; /* +1 for \0. */
3759 obstack_grow (&notes, name, name_length);
21d799b5 3760 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3761
c19d1205
ZW
3762#ifdef tc_canonicalize_symbol_name
3763 preserved_copy_of_name =
3764 tc_canonicalize_symbol_name (preserved_copy_of_name);
3765#endif
b99bd4ef 3766
c19d1205 3767 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3768
c19d1205
ZW
3769 S_SET_SEGMENT (symbolP, segment);
3770 S_SET_VALUE (symbolP, valu);
3771 symbol_clear_list_pointers (symbolP);
b99bd4ef 3772
c19d1205 3773 symbol_set_frag (symbolP, frag);
b99bd4ef 3774
c19d1205
ZW
3775 /* Link to end of symbol chain. */
3776 {
3777 extern int symbol_table_frozen;
b99bd4ef 3778
c19d1205
ZW
3779 if (symbol_table_frozen)
3780 abort ();
3781 }
b99bd4ef 3782
c19d1205 3783 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3784
c19d1205 3785 obj_symbol_new_hook (symbolP);
b99bd4ef 3786
c19d1205
ZW
3787#ifdef tc_symbol_new_hook
3788 tc_symbol_new_hook (symbolP);
3789#endif
3790
3791#ifdef DEBUG_SYMS
3792 verify_symbol_chain (symbol_rootP, symbol_lastP);
3793#endif /* DEBUG_SYMS */
b99bd4ef
NC
3794}
3795
c19d1205
ZW
3796static void
3797s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3798{
c19d1205
ZW
3799 unsigned int entry;
3800 literal_pool * pool;
3801 char sym_name[20];
b99bd4ef 3802
c19d1205
ZW
3803 pool = find_literal_pool ();
3804 if (pool == NULL
3805 || pool->symbol == NULL
3806 || pool->next_free_entry == 0)
3807 return;
b99bd4ef 3808
c19d1205
ZW
3809 /* Align pool as you have word accesses.
3810 Only make a frag if we have to. */
3811 if (!need_pass_2)
8335d6aa 3812 frag_align (pool->alignment, 0, 0);
b99bd4ef 3813
c19d1205 3814 record_alignment (now_seg, 2);
b99bd4ef 3815
aaca88ef 3816#ifdef OBJ_ELF
47fc6e36
WN
3817 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3818 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3819#endif
c19d1205 3820 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3821
c19d1205
ZW
3822 symbol_locate (pool->symbol, sym_name, now_seg,
3823 (valueT) frag_now_fix (), frag_now);
3824 symbol_table_insert (pool->symbol);
b99bd4ef 3825
c19d1205 3826 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3827
c19d1205
ZW
3828#if defined OBJ_COFF || defined OBJ_ELF
3829 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3830#endif
6c43fab6 3831
c19d1205 3832 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3833 {
3834#ifdef OBJ_ELF
3835 if (debug_type == DEBUG_DWARF2)
3836 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3837#endif
3838 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3839 emit_expr (&(pool->literals[entry]),
3840 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3841 }
b99bd4ef 3842
c19d1205
ZW
3843 /* Mark the pool as empty. */
3844 pool->next_free_entry = 0;
3845 pool->symbol = NULL;
b99bd4ef
NC
3846}
3847
c19d1205
ZW
3848#ifdef OBJ_ELF
3849/* Forward declarations for functions below, in the MD interface
3850 section. */
3851static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3852static valueT create_unwind_entry (int);
3853static void start_unwind_section (const segT, int);
3854static void add_unwind_opcode (valueT, int);
3855static void flush_pending_unwind (void);
b99bd4ef 3856
c19d1205 3857/* Directives: Data. */
b99bd4ef 3858
c19d1205
ZW
3859static void
3860s_arm_elf_cons (int nbytes)
3861{
3862 expressionS exp;
b99bd4ef 3863
c19d1205
ZW
3864#ifdef md_flush_pending_output
3865 md_flush_pending_output ();
3866#endif
b99bd4ef 3867
c19d1205 3868 if (is_it_end_of_statement ())
b99bd4ef 3869 {
c19d1205
ZW
3870 demand_empty_rest_of_line ();
3871 return;
b99bd4ef
NC
3872 }
3873
c19d1205
ZW
3874#ifdef md_cons_align
3875 md_cons_align (nbytes);
3876#endif
b99bd4ef 3877
c19d1205
ZW
3878 mapping_state (MAP_DATA);
3879 do
b99bd4ef 3880 {
c19d1205
ZW
3881 int reloc;
3882 char *base = input_line_pointer;
b99bd4ef 3883
c19d1205 3884 expression (& exp);
b99bd4ef 3885
c19d1205
ZW
3886 if (exp.X_op != O_symbol)
3887 emit_expr (&exp, (unsigned int) nbytes);
3888 else
3889 {
3890 char *before_reloc = input_line_pointer;
3891 reloc = parse_reloc (&input_line_pointer);
3892 if (reloc == -1)
3893 {
3894 as_bad (_("unrecognized relocation suffix"));
3895 ignore_rest_of_line ();
3896 return;
3897 }
3898 else if (reloc == BFD_RELOC_UNUSED)
3899 emit_expr (&exp, (unsigned int) nbytes);
3900 else
3901 {
21d799b5 3902 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3903 bfd_reloc_type_lookup (stdoutput,
3904 (bfd_reloc_code_real_type) reloc);
c19d1205 3905 int size = bfd_get_reloc_size (howto);
b99bd4ef 3906
2fc8bdac
ZW
3907 if (reloc == BFD_RELOC_ARM_PLT32)
3908 {
3909 as_bad (_("(plt) is only valid on branch targets"));
3910 reloc = BFD_RELOC_UNUSED;
3911 size = 0;
3912 }
3913
c19d1205 3914 if (size > nbytes)
992a06ee
AM
3915 as_bad (ngettext ("%s relocations do not fit in %d byte",
3916 "%s relocations do not fit in %d bytes",
3917 nbytes),
c19d1205
ZW
3918 howto->name, nbytes);
3919 else
3920 {
3921 /* We've parsed an expression stopping at O_symbol.
3922 But there may be more expression left now that we
3923 have parsed the relocation marker. Parse it again.
3924 XXX Surely there is a cleaner way to do this. */
3925 char *p = input_line_pointer;
3926 int offset;
325801bd 3927 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3928
c19d1205
ZW
3929 memcpy (save_buf, base, input_line_pointer - base);
3930 memmove (base + (input_line_pointer - before_reloc),
3931 base, before_reloc - base);
3932
3933 input_line_pointer = base + (input_line_pointer-before_reloc);
3934 expression (&exp);
3935 memcpy (base, save_buf, p - base);
3936
3937 offset = nbytes - size;
4b1a927e
AM
3938 p = frag_more (nbytes);
3939 memset (p, 0, nbytes);
c19d1205 3940 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3941 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3942 free (save_buf);
c19d1205
ZW
3943 }
3944 }
3945 }
b99bd4ef 3946 }
c19d1205 3947 while (*input_line_pointer++ == ',');
b99bd4ef 3948
c19d1205
ZW
3949 /* Put terminator back into stream. */
3950 input_line_pointer --;
3951 demand_empty_rest_of_line ();
b99bd4ef
NC
3952}
3953
c921be7d
NC
3954/* Emit an expression containing a 32-bit thumb instruction.
3955 Implementation based on put_thumb32_insn. */
3956
3957static void
3958emit_thumb32_expr (expressionS * exp)
3959{
3960 expressionS exp_high = *exp;
3961
3962 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3963 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3964 exp->X_add_number &= 0xffff;
3965 emit_expr (exp, (unsigned int) THUMB_SIZE);
3966}
3967
3968/* Guess the instruction size based on the opcode. */
3969
3970static int
3971thumb_insn_size (int opcode)
3972{
3973 if ((unsigned int) opcode < 0xe800u)
3974 return 2;
3975 else if ((unsigned int) opcode >= 0xe8000000u)
3976 return 4;
3977 else
3978 return 0;
3979}
3980
3981static bfd_boolean
3982emit_insn (expressionS *exp, int nbytes)
3983{
3984 int size = 0;
3985
3986 if (exp->X_op == O_constant)
3987 {
3988 size = nbytes;
3989
3990 if (size == 0)
3991 size = thumb_insn_size (exp->X_add_number);
3992
3993 if (size != 0)
3994 {
3995 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3996 {
3997 as_bad (_(".inst.n operand too big. "\
3998 "Use .inst.w instead"));
3999 size = 0;
4000 }
4001 else
4002 {
5ee91343
AV
4003 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4004 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
c921be7d 4005 else
5ee91343 4006 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
c921be7d
NC
4007
4008 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4009 emit_thumb32_expr (exp);
4010 else
4011 emit_expr (exp, (unsigned int) size);
4012
4013 it_fsm_post_encode ();
4014 }
4015 }
4016 else
4017 as_bad (_("cannot determine Thumb instruction size. " \
4018 "Use .inst.n/.inst.w instead"));
4019 }
4020 else
4021 as_bad (_("constant expression required"));
4022
4023 return (size != 0);
4024}
4025
4026/* Like s_arm_elf_cons but do not use md_cons_align and
4027 set the mapping state to MAP_ARM/MAP_THUMB. */
4028
4029static void
4030s_arm_elf_inst (int nbytes)
4031{
4032 if (is_it_end_of_statement ())
4033 {
4034 demand_empty_rest_of_line ();
4035 return;
4036 }
4037
4038 /* Calling mapping_state () here will not change ARM/THUMB,
4039 but will ensure not to be in DATA state. */
4040
4041 if (thumb_mode)
4042 mapping_state (MAP_THUMB);
4043 else
4044 {
4045 if (nbytes != 0)
4046 {
4047 as_bad (_("width suffixes are invalid in ARM mode"));
4048 ignore_rest_of_line ();
4049 return;
4050 }
4051
4052 nbytes = 4;
4053
4054 mapping_state (MAP_ARM);
4055 }
4056
4057 do
4058 {
4059 expressionS exp;
4060
4061 expression (& exp);
4062
4063 if (! emit_insn (& exp, nbytes))
4064 {
4065 ignore_rest_of_line ();
4066 return;
4067 }
4068 }
4069 while (*input_line_pointer++ == ',');
4070
4071 /* Put terminator back into stream. */
4072 input_line_pointer --;
4073 demand_empty_rest_of_line ();
4074}
b99bd4ef 4075
c19d1205 4076/* Parse a .rel31 directive. */
b99bd4ef 4077
c19d1205
ZW
4078static void
4079s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4080{
4081 expressionS exp;
4082 char *p;
4083 valueT highbit;
b99bd4ef 4084
c19d1205
ZW
4085 highbit = 0;
4086 if (*input_line_pointer == '1')
4087 highbit = 0x80000000;
4088 else if (*input_line_pointer != '0')
4089 as_bad (_("expected 0 or 1"));
b99bd4ef 4090
c19d1205
ZW
4091 input_line_pointer++;
4092 if (*input_line_pointer != ',')
4093 as_bad (_("missing comma"));
4094 input_line_pointer++;
b99bd4ef 4095
c19d1205
ZW
4096#ifdef md_flush_pending_output
4097 md_flush_pending_output ();
4098#endif
b99bd4ef 4099
c19d1205
ZW
4100#ifdef md_cons_align
4101 md_cons_align (4);
4102#endif
b99bd4ef 4103
c19d1205 4104 mapping_state (MAP_DATA);
b99bd4ef 4105
c19d1205 4106 expression (&exp);
b99bd4ef 4107
c19d1205
ZW
4108 p = frag_more (4);
4109 md_number_to_chars (p, highbit, 4);
4110 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4111 BFD_RELOC_ARM_PREL31);
b99bd4ef 4112
c19d1205 4113 demand_empty_rest_of_line ();
b99bd4ef
NC
4114}
4115
c19d1205 4116/* Directives: AEABI stack-unwind tables. */
b99bd4ef 4117
c19d1205 4118/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 4119
c19d1205
ZW
4120static void
4121s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4122{
4123 demand_empty_rest_of_line ();
921e5f0a
PB
4124 if (unwind.proc_start)
4125 {
c921be7d 4126 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
4127 return;
4128 }
4129
c19d1205
ZW
4130 /* Mark the start of the function. */
4131 unwind.proc_start = expr_build_dot ();
b99bd4ef 4132
c19d1205
ZW
4133 /* Reset the rest of the unwind info. */
4134 unwind.opcode_count = 0;
4135 unwind.table_entry = NULL;
4136 unwind.personality_routine = NULL;
4137 unwind.personality_index = -1;
4138 unwind.frame_size = 0;
4139 unwind.fp_offset = 0;
fdfde340 4140 unwind.fp_reg = REG_SP;
c19d1205
ZW
4141 unwind.fp_used = 0;
4142 unwind.sp_restored = 0;
4143}
b99bd4ef 4144
b99bd4ef 4145
c19d1205
ZW
4146/* Parse a handlerdata directive. Creates the exception handling table entry
4147 for the function. */
b99bd4ef 4148
c19d1205
ZW
4149static void
4150s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4151{
4152 demand_empty_rest_of_line ();
921e5f0a 4153 if (!unwind.proc_start)
c921be7d 4154 as_bad (MISSING_FNSTART);
921e5f0a 4155
c19d1205 4156 if (unwind.table_entry)
6decc662 4157 as_bad (_("duplicate .handlerdata directive"));
f02232aa 4158
c19d1205
ZW
4159 create_unwind_entry (1);
4160}
a737bd4d 4161
c19d1205 4162/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 4163
c19d1205
ZW
4164static void
4165s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4166{
4167 long where;
4168 char *ptr;
4169 valueT val;
940b5ce0 4170 unsigned int marked_pr_dependency;
f02232aa 4171
c19d1205 4172 demand_empty_rest_of_line ();
f02232aa 4173
921e5f0a
PB
4174 if (!unwind.proc_start)
4175 {
c921be7d 4176 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
4177 return;
4178 }
4179
c19d1205
ZW
4180 /* Add eh table entry. */
4181 if (unwind.table_entry == NULL)
4182 val = create_unwind_entry (0);
4183 else
4184 val = 0;
f02232aa 4185
c19d1205
ZW
4186 /* Add index table entry. This is two words. */
4187 start_unwind_section (unwind.saved_seg, 1);
4188 frag_align (2, 0, 0);
4189 record_alignment (now_seg, 2);
b99bd4ef 4190
c19d1205 4191 ptr = frag_more (8);
5011093d 4192 memset (ptr, 0, 8);
c19d1205 4193 where = frag_now_fix () - 8;
f02232aa 4194
c19d1205
ZW
4195 /* Self relative offset of the function start. */
4196 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4197 BFD_RELOC_ARM_PREL31);
f02232aa 4198
c19d1205
ZW
4199 /* Indicate dependency on EHABI-defined personality routines to the
4200 linker, if it hasn't been done already. */
940b5ce0
DJ
4201 marked_pr_dependency
4202 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
4203 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4204 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4205 {
5f4273c7
NC
4206 static const char *const name[] =
4207 {
4208 "__aeabi_unwind_cpp_pr0",
4209 "__aeabi_unwind_cpp_pr1",
4210 "__aeabi_unwind_cpp_pr2"
4211 };
c19d1205
ZW
4212 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4213 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 4214 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 4215 |= 1 << unwind.personality_index;
c19d1205 4216 }
f02232aa 4217
c19d1205
ZW
4218 if (val)
4219 /* Inline exception table entry. */
4220 md_number_to_chars (ptr + 4, val, 4);
4221 else
4222 /* Self relative offset of the table entry. */
4223 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4224 BFD_RELOC_ARM_PREL31);
f02232aa 4225
c19d1205
ZW
4226 /* Restore the original section. */
4227 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
4228
4229 unwind.proc_start = NULL;
c19d1205 4230}
f02232aa 4231
f02232aa 4232
c19d1205 4233/* Parse an unwind_cantunwind directive. */
b99bd4ef 4234
c19d1205
ZW
4235static void
4236s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4237{
4238 demand_empty_rest_of_line ();
921e5f0a 4239 if (!unwind.proc_start)
c921be7d 4240 as_bad (MISSING_FNSTART);
921e5f0a 4241
c19d1205
ZW
4242 if (unwind.personality_routine || unwind.personality_index != -1)
4243 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 4244
c19d1205
ZW
4245 unwind.personality_index = -2;
4246}
b99bd4ef 4247
b99bd4ef 4248
c19d1205 4249/* Parse a personalityindex directive. */
b99bd4ef 4250
c19d1205
ZW
4251static void
4252s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4253{
4254 expressionS exp;
b99bd4ef 4255
921e5f0a 4256 if (!unwind.proc_start)
c921be7d 4257 as_bad (MISSING_FNSTART);
921e5f0a 4258
c19d1205
ZW
4259 if (unwind.personality_routine || unwind.personality_index != -1)
4260 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 4261
c19d1205 4262 expression (&exp);
b99bd4ef 4263
c19d1205
ZW
4264 if (exp.X_op != O_constant
4265 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 4266 {
c19d1205
ZW
4267 as_bad (_("bad personality routine number"));
4268 ignore_rest_of_line ();
4269 return;
b99bd4ef
NC
4270 }
4271
c19d1205 4272 unwind.personality_index = exp.X_add_number;
b99bd4ef 4273
c19d1205
ZW
4274 demand_empty_rest_of_line ();
4275}
e16bb312 4276
e16bb312 4277
c19d1205 4278/* Parse a personality directive. */
e16bb312 4279
c19d1205
ZW
4280static void
4281s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4282{
4283 char *name, *p, c;
a737bd4d 4284
921e5f0a 4285 if (!unwind.proc_start)
c921be7d 4286 as_bad (MISSING_FNSTART);
921e5f0a 4287
c19d1205
ZW
4288 if (unwind.personality_routine || unwind.personality_index != -1)
4289 as_bad (_("duplicate .personality directive"));
a737bd4d 4290
d02603dc 4291 c = get_symbol_name (& name);
c19d1205 4292 p = input_line_pointer;
d02603dc
NC
4293 if (c == '"')
4294 ++ input_line_pointer;
c19d1205
ZW
4295 unwind.personality_routine = symbol_find_or_make (name);
4296 *p = c;
4297 demand_empty_rest_of_line ();
4298}
e16bb312 4299
e16bb312 4300
c19d1205 4301/* Parse a directive saving core registers. */
e16bb312 4302
c19d1205
ZW
4303static void
4304s_arm_unwind_save_core (void)
e16bb312 4305{
c19d1205
ZW
4306 valueT op;
4307 long range;
4308 int n;
e16bb312 4309
4b5a202f 4310 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
c19d1205 4311 if (range == FAIL)
e16bb312 4312 {
c19d1205
ZW
4313 as_bad (_("expected register list"));
4314 ignore_rest_of_line ();
4315 return;
4316 }
e16bb312 4317
c19d1205 4318 demand_empty_rest_of_line ();
e16bb312 4319
c19d1205
ZW
4320 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4321 into .unwind_save {..., sp...}. We aren't bothered about the value of
4322 ip because it is clobbered by calls. */
4323 if (unwind.sp_restored && unwind.fp_reg == 12
4324 && (range & 0x3000) == 0x1000)
4325 {
4326 unwind.opcode_count--;
4327 unwind.sp_restored = 0;
4328 range = (range | 0x2000) & ~0x1000;
4329 unwind.pending_offset = 0;
4330 }
e16bb312 4331
01ae4198
DJ
4332 /* Pop r4-r15. */
4333 if (range & 0xfff0)
c19d1205 4334 {
01ae4198
DJ
4335 /* See if we can use the short opcodes. These pop a block of up to 8
4336 registers starting with r4, plus maybe r14. */
4337 for (n = 0; n < 8; n++)
4338 {
4339 /* Break at the first non-saved register. */
4340 if ((range & (1 << (n + 4))) == 0)
4341 break;
4342 }
4343 /* See if there are any other bits set. */
4344 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4345 {
4346 /* Use the long form. */
4347 op = 0x8000 | ((range >> 4) & 0xfff);
4348 add_unwind_opcode (op, 2);
4349 }
0dd132b6 4350 else
01ae4198
DJ
4351 {
4352 /* Use the short form. */
4353 if (range & 0x4000)
4354 op = 0xa8; /* Pop r14. */
4355 else
4356 op = 0xa0; /* Do not pop r14. */
4357 op |= (n - 1);
4358 add_unwind_opcode (op, 1);
4359 }
c19d1205 4360 }
0dd132b6 4361
c19d1205
ZW
4362 /* Pop r0-r3. */
4363 if (range & 0xf)
4364 {
4365 op = 0xb100 | (range & 0xf);
4366 add_unwind_opcode (op, 2);
0dd132b6
NC
4367 }
4368
c19d1205
ZW
4369 /* Record the number of bytes pushed. */
4370 for (n = 0; n < 16; n++)
4371 {
4372 if (range & (1 << n))
4373 unwind.frame_size += 4;
4374 }
0dd132b6
NC
4375}
4376
c19d1205
ZW
4377
4378/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4379
4380static void
c19d1205 4381s_arm_unwind_save_fpa (int reg)
b99bd4ef 4382{
c19d1205
ZW
4383 expressionS exp;
4384 int num_regs;
4385 valueT op;
b99bd4ef 4386
c19d1205
ZW
4387 /* Get Number of registers to transfer. */
4388 if (skip_past_comma (&input_line_pointer) != FAIL)
4389 expression (&exp);
4390 else
4391 exp.X_op = O_illegal;
b99bd4ef 4392
c19d1205 4393 if (exp.X_op != O_constant)
b99bd4ef 4394 {
c19d1205
ZW
4395 as_bad (_("expected , <constant>"));
4396 ignore_rest_of_line ();
b99bd4ef
NC
4397 return;
4398 }
4399
c19d1205
ZW
4400 num_regs = exp.X_add_number;
4401
4402 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4403 {
c19d1205
ZW
4404 as_bad (_("number of registers must be in the range [1:4]"));
4405 ignore_rest_of_line ();
b99bd4ef
NC
4406 return;
4407 }
4408
c19d1205 4409 demand_empty_rest_of_line ();
b99bd4ef 4410
c19d1205
ZW
4411 if (reg == 4)
4412 {
4413 /* Short form. */
4414 op = 0xb4 | (num_regs - 1);
4415 add_unwind_opcode (op, 1);
4416 }
b99bd4ef
NC
4417 else
4418 {
c19d1205
ZW
4419 /* Long form. */
4420 op = 0xc800 | (reg << 4) | (num_regs - 1);
4421 add_unwind_opcode (op, 2);
b99bd4ef 4422 }
c19d1205 4423 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4424}
4425
c19d1205 4426
fa073d69
MS
4427/* Parse a directive saving VFP registers for ARMv6 and above. */
4428
4429static void
4430s_arm_unwind_save_vfp_armv6 (void)
4431{
4432 int count;
4433 unsigned int start;
4434 valueT op;
4435 int num_vfpv3_regs = 0;
4436 int num_regs_below_16;
efd6b359 4437 bfd_boolean partial_match;
fa073d69 4438
efd6b359
AV
4439 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4440 &partial_match);
fa073d69
MS
4441 if (count == FAIL)
4442 {
4443 as_bad (_("expected register list"));
4444 ignore_rest_of_line ();
4445 return;
4446 }
4447
4448 demand_empty_rest_of_line ();
4449
4450 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4451 than FSTMX/FLDMX-style ones). */
4452
4453 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4454 if (start >= 16)
4455 num_vfpv3_regs = count;
4456 else if (start + count > 16)
4457 num_vfpv3_regs = start + count - 16;
4458
4459 if (num_vfpv3_regs > 0)
4460 {
4461 int start_offset = start > 16 ? start - 16 : 0;
4462 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4463 add_unwind_opcode (op, 2);
4464 }
4465
4466 /* Generate opcode for registers numbered in the range 0 .. 15. */
4467 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4468 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4469 if (num_regs_below_16 > 0)
4470 {
4471 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4472 add_unwind_opcode (op, 2);
4473 }
4474
4475 unwind.frame_size += count * 8;
4476}
4477
4478
4479/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4480
4481static void
c19d1205 4482s_arm_unwind_save_vfp (void)
b99bd4ef 4483{
c19d1205 4484 int count;
ca3f61f7 4485 unsigned int reg;
c19d1205 4486 valueT op;
efd6b359 4487 bfd_boolean partial_match;
b99bd4ef 4488
efd6b359
AV
4489 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4490 &partial_match);
c19d1205 4491 if (count == FAIL)
b99bd4ef 4492 {
c19d1205
ZW
4493 as_bad (_("expected register list"));
4494 ignore_rest_of_line ();
b99bd4ef
NC
4495 return;
4496 }
4497
c19d1205 4498 demand_empty_rest_of_line ();
b99bd4ef 4499
c19d1205 4500 if (reg == 8)
b99bd4ef 4501 {
c19d1205
ZW
4502 /* Short form. */
4503 op = 0xb8 | (count - 1);
4504 add_unwind_opcode (op, 1);
b99bd4ef 4505 }
c19d1205 4506 else
b99bd4ef 4507 {
c19d1205
ZW
4508 /* Long form. */
4509 op = 0xb300 | (reg << 4) | (count - 1);
4510 add_unwind_opcode (op, 2);
b99bd4ef 4511 }
c19d1205
ZW
4512 unwind.frame_size += count * 8 + 4;
4513}
b99bd4ef 4514
b99bd4ef 4515
c19d1205
ZW
4516/* Parse a directive saving iWMMXt data registers. */
4517
4518static void
4519s_arm_unwind_save_mmxwr (void)
4520{
4521 int reg;
4522 int hi_reg;
4523 int i;
4524 unsigned mask = 0;
4525 valueT op;
b99bd4ef 4526
c19d1205
ZW
4527 if (*input_line_pointer == '{')
4528 input_line_pointer++;
b99bd4ef 4529
c19d1205 4530 do
b99bd4ef 4531 {
dcbf9037 4532 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4533
c19d1205 4534 if (reg == FAIL)
b99bd4ef 4535 {
9b7132d3 4536 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4537 goto error;
b99bd4ef
NC
4538 }
4539
c19d1205
ZW
4540 if (mask >> reg)
4541 as_tsktsk (_("register list not in ascending order"));
4542 mask |= 1 << reg;
b99bd4ef 4543
c19d1205
ZW
4544 if (*input_line_pointer == '-')
4545 {
4546 input_line_pointer++;
dcbf9037 4547 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4548 if (hi_reg == FAIL)
4549 {
9b7132d3 4550 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4551 goto error;
4552 }
4553 else if (reg >= hi_reg)
4554 {
4555 as_bad (_("bad register range"));
4556 goto error;
4557 }
4558 for (; reg < hi_reg; reg++)
4559 mask |= 1 << reg;
4560 }
4561 }
4562 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4563
d996d970 4564 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4565
c19d1205 4566 demand_empty_rest_of_line ();
b99bd4ef 4567
708587a4 4568 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4569 the list. */
4570 flush_pending_unwind ();
b99bd4ef 4571
c19d1205 4572 for (i = 0; i < 16; i++)
b99bd4ef 4573 {
c19d1205
ZW
4574 if (mask & (1 << i))
4575 unwind.frame_size += 8;
b99bd4ef
NC
4576 }
4577
c19d1205
ZW
4578 /* Attempt to combine with a previous opcode. We do this because gcc
4579 likes to output separate unwind directives for a single block of
4580 registers. */
4581 if (unwind.opcode_count > 0)
b99bd4ef 4582 {
c19d1205
ZW
4583 i = unwind.opcodes[unwind.opcode_count - 1];
4584 if ((i & 0xf8) == 0xc0)
4585 {
4586 i &= 7;
4587 /* Only merge if the blocks are contiguous. */
4588 if (i < 6)
4589 {
4590 if ((mask & 0xfe00) == (1 << 9))
4591 {
4592 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4593 unwind.opcode_count--;
4594 }
4595 }
4596 else if (i == 6 && unwind.opcode_count >= 2)
4597 {
4598 i = unwind.opcodes[unwind.opcode_count - 2];
4599 reg = i >> 4;
4600 i &= 0xf;
b99bd4ef 4601
c19d1205
ZW
4602 op = 0xffff << (reg - 1);
4603 if (reg > 0
87a1fd79 4604 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4605 {
4606 op = (1 << (reg + i + 1)) - 1;
4607 op &= ~((1 << reg) - 1);
4608 mask |= op;
4609 unwind.opcode_count -= 2;
4610 }
4611 }
4612 }
b99bd4ef
NC
4613 }
4614
c19d1205
ZW
4615 hi_reg = 15;
4616 /* We want to generate opcodes in the order the registers have been
4617 saved, ie. descending order. */
4618 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4619 {
c19d1205
ZW
4620 /* Save registers in blocks. */
4621 if (reg < 0
4622 || !(mask & (1 << reg)))
4623 {
4624 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4625 preceding block. */
c19d1205
ZW
4626 if (reg != hi_reg)
4627 {
4628 if (reg == 9)
4629 {
4630 /* Short form. */
4631 op = 0xc0 | (hi_reg - 10);
4632 add_unwind_opcode (op, 1);
4633 }
4634 else
4635 {
4636 /* Long form. */
4637 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4638 add_unwind_opcode (op, 2);
4639 }
4640 }
4641 hi_reg = reg - 1;
4642 }
b99bd4ef
NC
4643 }
4644
c19d1205 4645 return;
dc1e8a47 4646 error:
c19d1205 4647 ignore_rest_of_line ();
b99bd4ef
NC
4648}
4649
4650static void
c19d1205 4651s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4652{
c19d1205
ZW
4653 int reg;
4654 int hi_reg;
4655 unsigned mask = 0;
4656 valueT op;
b99bd4ef 4657
c19d1205
ZW
4658 if (*input_line_pointer == '{')
4659 input_line_pointer++;
b99bd4ef 4660
477330fc
RM
4661 skip_whitespace (input_line_pointer);
4662
c19d1205 4663 do
b99bd4ef 4664 {
dcbf9037 4665 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4666
c19d1205
ZW
4667 if (reg == FAIL)
4668 {
9b7132d3 4669 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4670 goto error;
4671 }
b99bd4ef 4672
c19d1205
ZW
4673 reg -= 8;
4674 if (mask >> reg)
4675 as_tsktsk (_("register list not in ascending order"));
4676 mask |= 1 << reg;
b99bd4ef 4677
c19d1205
ZW
4678 if (*input_line_pointer == '-')
4679 {
4680 input_line_pointer++;
dcbf9037 4681 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4682 if (hi_reg == FAIL)
4683 {
9b7132d3 4684 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4685 goto error;
4686 }
4687 else if (reg >= hi_reg)
4688 {
4689 as_bad (_("bad register range"));
4690 goto error;
4691 }
4692 for (; reg < hi_reg; reg++)
4693 mask |= 1 << reg;
4694 }
b99bd4ef 4695 }
c19d1205 4696 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4697
d996d970 4698 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4699
c19d1205
ZW
4700 demand_empty_rest_of_line ();
4701
708587a4 4702 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4703 the list. */
4704 flush_pending_unwind ();
b99bd4ef 4705
c19d1205 4706 for (reg = 0; reg < 16; reg++)
b99bd4ef 4707 {
c19d1205
ZW
4708 if (mask & (1 << reg))
4709 unwind.frame_size += 4;
b99bd4ef 4710 }
c19d1205
ZW
4711 op = 0xc700 | mask;
4712 add_unwind_opcode (op, 2);
4713 return;
dc1e8a47 4714 error:
c19d1205 4715 ignore_rest_of_line ();
b99bd4ef
NC
4716}
4717
c19d1205 4718
fa073d69
MS
4719/* Parse an unwind_save directive.
4720 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4721
b99bd4ef 4722static void
fa073d69 4723s_arm_unwind_save (int arch_v6)
b99bd4ef 4724{
c19d1205
ZW
4725 char *peek;
4726 struct reg_entry *reg;
4727 bfd_boolean had_brace = FALSE;
b99bd4ef 4728
921e5f0a 4729 if (!unwind.proc_start)
c921be7d 4730 as_bad (MISSING_FNSTART);
921e5f0a 4731
c19d1205
ZW
4732 /* Figure out what sort of save we have. */
4733 peek = input_line_pointer;
b99bd4ef 4734
c19d1205 4735 if (*peek == '{')
b99bd4ef 4736 {
c19d1205
ZW
4737 had_brace = TRUE;
4738 peek++;
b99bd4ef
NC
4739 }
4740
c19d1205 4741 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4742
c19d1205 4743 if (!reg)
b99bd4ef 4744 {
c19d1205
ZW
4745 as_bad (_("register expected"));
4746 ignore_rest_of_line ();
b99bd4ef
NC
4747 return;
4748 }
4749
c19d1205 4750 switch (reg->type)
b99bd4ef 4751 {
c19d1205
ZW
4752 case REG_TYPE_FN:
4753 if (had_brace)
4754 {
4755 as_bad (_("FPA .unwind_save does not take a register list"));
4756 ignore_rest_of_line ();
4757 return;
4758 }
93ac2687 4759 input_line_pointer = peek;
c19d1205 4760 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4761 return;
c19d1205 4762
1f5afe1c
NC
4763 case REG_TYPE_RN:
4764 s_arm_unwind_save_core ();
4765 return;
4766
fa073d69
MS
4767 case REG_TYPE_VFD:
4768 if (arch_v6)
477330fc 4769 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4770 else
477330fc 4771 s_arm_unwind_save_vfp ();
fa073d69 4772 return;
1f5afe1c
NC
4773
4774 case REG_TYPE_MMXWR:
4775 s_arm_unwind_save_mmxwr ();
4776 return;
4777
4778 case REG_TYPE_MMXWCG:
4779 s_arm_unwind_save_mmxwcg ();
4780 return;
c19d1205
ZW
4781
4782 default:
4783 as_bad (_(".unwind_save does not support this kind of register"));
4784 ignore_rest_of_line ();
b99bd4ef 4785 }
c19d1205 4786}
b99bd4ef 4787
b99bd4ef 4788
c19d1205
ZW
4789/* Parse an unwind_movsp directive. */
4790
4791static void
4792s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4793{
4794 int reg;
4795 valueT op;
4fa3602b 4796 int offset;
c19d1205 4797
921e5f0a 4798 if (!unwind.proc_start)
c921be7d 4799 as_bad (MISSING_FNSTART);
921e5f0a 4800
dcbf9037 4801 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4802 if (reg == FAIL)
b99bd4ef 4803 {
9b7132d3 4804 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4805 ignore_rest_of_line ();
b99bd4ef
NC
4806 return;
4807 }
4fa3602b
PB
4808
4809 /* Optional constant. */
4810 if (skip_past_comma (&input_line_pointer) != FAIL)
4811 {
4812 if (immediate_for_directive (&offset) == FAIL)
4813 return;
4814 }
4815 else
4816 offset = 0;
4817
c19d1205 4818 demand_empty_rest_of_line ();
b99bd4ef 4819
c19d1205 4820 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4821 {
c19d1205 4822 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4823 return;
4824 }
4825
c19d1205
ZW
4826 if (unwind.fp_reg != REG_SP)
4827 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4828
c19d1205
ZW
4829 /* Generate opcode to restore the value. */
4830 op = 0x90 | reg;
4831 add_unwind_opcode (op, 1);
4832
4833 /* Record the information for later. */
4834 unwind.fp_reg = reg;
4fa3602b 4835 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4836 unwind.sp_restored = 1;
b05fe5cf
ZW
4837}
4838
c19d1205
ZW
4839/* Parse an unwind_pad directive. */
4840
b05fe5cf 4841static void
c19d1205 4842s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4843{
c19d1205 4844 int offset;
b05fe5cf 4845
921e5f0a 4846 if (!unwind.proc_start)
c921be7d 4847 as_bad (MISSING_FNSTART);
921e5f0a 4848
c19d1205
ZW
4849 if (immediate_for_directive (&offset) == FAIL)
4850 return;
b99bd4ef 4851
c19d1205
ZW
4852 if (offset & 3)
4853 {
4854 as_bad (_("stack increment must be multiple of 4"));
4855 ignore_rest_of_line ();
4856 return;
4857 }
b99bd4ef 4858
c19d1205
ZW
4859 /* Don't generate any opcodes, just record the details for later. */
4860 unwind.frame_size += offset;
4861 unwind.pending_offset += offset;
4862
4863 demand_empty_rest_of_line ();
4864}
4865
4866/* Parse an unwind_setfp directive. */
4867
4868static void
4869s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4870{
c19d1205
ZW
4871 int sp_reg;
4872 int fp_reg;
4873 int offset;
4874
921e5f0a 4875 if (!unwind.proc_start)
c921be7d 4876 as_bad (MISSING_FNSTART);
921e5f0a 4877
dcbf9037 4878 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4879 if (skip_past_comma (&input_line_pointer) == FAIL)
4880 sp_reg = FAIL;
4881 else
dcbf9037 4882 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4883
c19d1205
ZW
4884 if (fp_reg == FAIL || sp_reg == FAIL)
4885 {
4886 as_bad (_("expected <reg>, <reg>"));
4887 ignore_rest_of_line ();
4888 return;
4889 }
b99bd4ef 4890
c19d1205
ZW
4891 /* Optional constant. */
4892 if (skip_past_comma (&input_line_pointer) != FAIL)
4893 {
4894 if (immediate_for_directive (&offset) == FAIL)
4895 return;
4896 }
4897 else
4898 offset = 0;
a737bd4d 4899
c19d1205 4900 demand_empty_rest_of_line ();
a737bd4d 4901
fdfde340 4902 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4903 {
c19d1205
ZW
4904 as_bad (_("register must be either sp or set by a previous"
4905 "unwind_movsp directive"));
4906 return;
a737bd4d
NC
4907 }
4908
c19d1205
ZW
4909 /* Don't generate any opcodes, just record the information for later. */
4910 unwind.fp_reg = fp_reg;
4911 unwind.fp_used = 1;
fdfde340 4912 if (sp_reg == REG_SP)
c19d1205
ZW
4913 unwind.fp_offset = unwind.frame_size - offset;
4914 else
4915 unwind.fp_offset -= offset;
a737bd4d
NC
4916}
4917
c19d1205
ZW
4918/* Parse an unwind_raw directive. */
4919
4920static void
4921s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4922{
c19d1205 4923 expressionS exp;
708587a4 4924 /* This is an arbitrary limit. */
c19d1205
ZW
4925 unsigned char op[16];
4926 int count;
a737bd4d 4927
921e5f0a 4928 if (!unwind.proc_start)
c921be7d 4929 as_bad (MISSING_FNSTART);
921e5f0a 4930
c19d1205
ZW
4931 expression (&exp);
4932 if (exp.X_op == O_constant
4933 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4934 {
c19d1205
ZW
4935 unwind.frame_size += exp.X_add_number;
4936 expression (&exp);
4937 }
4938 else
4939 exp.X_op = O_illegal;
a737bd4d 4940
c19d1205
ZW
4941 if (exp.X_op != O_constant)
4942 {
4943 as_bad (_("expected <offset>, <opcode>"));
4944 ignore_rest_of_line ();
4945 return;
4946 }
a737bd4d 4947
c19d1205 4948 count = 0;
a737bd4d 4949
c19d1205
ZW
4950 /* Parse the opcode. */
4951 for (;;)
4952 {
4953 if (count >= 16)
4954 {
4955 as_bad (_("unwind opcode too long"));
4956 ignore_rest_of_line ();
a737bd4d 4957 }
c19d1205 4958 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4959 {
c19d1205
ZW
4960 as_bad (_("invalid unwind opcode"));
4961 ignore_rest_of_line ();
4962 return;
a737bd4d 4963 }
c19d1205 4964 op[count++] = exp.X_add_number;
a737bd4d 4965
c19d1205
ZW
4966 /* Parse the next byte. */
4967 if (skip_past_comma (&input_line_pointer) == FAIL)
4968 break;
a737bd4d 4969
c19d1205
ZW
4970 expression (&exp);
4971 }
b99bd4ef 4972
c19d1205
ZW
4973 /* Add the opcode bytes in reverse order. */
4974 while (count--)
4975 add_unwind_opcode (op[count], 1);
b99bd4ef 4976
c19d1205 4977 demand_empty_rest_of_line ();
b99bd4ef 4978}
ee065d83
PB
4979
4980
4981/* Parse a .eabi_attribute directive. */
4982
4983static void
4984s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4985{
0420f52b 4986 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378 4987
3076e594 4988 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
ee3c0378 4989 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4990}
4991
0855e32b
NS
4992/* Emit a tls fix for the symbol. */
4993
4994static void
4995s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4996{
4997 char *p;
4998 expressionS exp;
4999#ifdef md_flush_pending_output
5000 md_flush_pending_output ();
5001#endif
5002
5003#ifdef md_cons_align
5004 md_cons_align (4);
5005#endif
5006
5007 /* Since we're just labelling the code, there's no need to define a
5008 mapping symbol. */
5009 expression (&exp);
5010 p = obstack_next_free (&frchain_now->frch_obstack);
5011 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5012 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5013 : BFD_RELOC_ARM_TLS_DESCSEQ);
5014}
cdf9ccec 5015#endif /* OBJ_ELF */
0855e32b 5016
ee065d83 5017static void s_arm_arch (int);
7a1d4c38 5018static void s_arm_object_arch (int);
ee065d83
PB
5019static void s_arm_cpu (int);
5020static void s_arm_fpu (int);
69133863 5021static void s_arm_arch_extension (int);
b99bd4ef 5022
f0927246
NC
5023#ifdef TE_PE
5024
5025static void
5f4273c7 5026pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
5027{
5028 expressionS exp;
5029
5030 do
5031 {
5032 expression (&exp);
5033 if (exp.X_op == O_symbol)
5034 exp.X_op = O_secrel;
5035
5036 emit_expr (&exp, 4);
5037 }
5038 while (*input_line_pointer++ == ',');
5039
5040 input_line_pointer--;
5041 demand_empty_rest_of_line ();
5042}
5043#endif /* TE_PE */
5044
5312fe52
BW
5045int
5046arm_is_largest_exponent_ok (int precision)
5047{
5048 /* precision == 1 ensures that this will only return
5049 true for 16 bit floats. */
5050 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5051}
5052
5053static void
5054set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5055{
5056 char saved_char;
5057 char* name;
5058 enum fp_16bit_format new_format;
5059
5060 new_format = ARM_FP16_FORMAT_DEFAULT;
5061
5062 name = input_line_pointer;
5063 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5064 input_line_pointer++;
5065
5066 saved_char = *input_line_pointer;
5067 *input_line_pointer = 0;
5068
5069 if (strcasecmp (name, "ieee") == 0)
5070 new_format = ARM_FP16_FORMAT_IEEE;
5071 else if (strcasecmp (name, "alternative") == 0)
5072 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5073 else
5074 {
5075 as_bad (_("unrecognised float16 format \"%s\""), name);
5076 goto cleanup;
5077 }
5078
5079 /* Only set fp16_format if it is still the default (aka not already
5080 been set yet). */
5081 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5082 fp16_format = new_format;
5083 else
5084 {
5085 if (new_format != fp16_format)
5086 as_warn (_("float16 format cannot be set more than once, ignoring."));
5087 }
5088
dc1e8a47 5089 cleanup:
5312fe52
BW
5090 *input_line_pointer = saved_char;
5091 ignore_rest_of_line ();
5092}
5093
c19d1205
ZW
5094/* This table describes all the machine specific pseudo-ops the assembler
5095 has to support. The fields are:
5096 pseudo-op name without dot
5097 function to call to execute this pseudo-op
5098 Integer arg to pass to the function. */
b99bd4ef 5099
c19d1205 5100const pseudo_typeS md_pseudo_table[] =
b99bd4ef 5101{
c19d1205
ZW
5102 /* Never called because '.req' does not start a line. */
5103 { "req", s_req, 0 },
dcbf9037
JB
5104 /* Following two are likewise never called. */
5105 { "dn", s_dn, 0 },
5106 { "qn", s_qn, 0 },
c19d1205
ZW
5107 { "unreq", s_unreq, 0 },
5108 { "bss", s_bss, 0 },
db2ed2e0 5109 { "align", s_align_ptwo, 2 },
c19d1205
ZW
5110 { "arm", s_arm, 0 },
5111 { "thumb", s_thumb, 0 },
5112 { "code", s_code, 0 },
5113 { "force_thumb", s_force_thumb, 0 },
5114 { "thumb_func", s_thumb_func, 0 },
5115 { "thumb_set", s_thumb_set, 0 },
5116 { "even", s_even, 0 },
5117 { "ltorg", s_ltorg, 0 },
5118 { "pool", s_ltorg, 0 },
5119 { "syntax", s_syntax, 0 },
8463be01
PB
5120 { "cpu", s_arm_cpu, 0 },
5121 { "arch", s_arm_arch, 0 },
7a1d4c38 5122 { "object_arch", s_arm_object_arch, 0 },
8463be01 5123 { "fpu", s_arm_fpu, 0 },
69133863 5124 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 5125#ifdef OBJ_ELF
c921be7d
NC
5126 { "word", s_arm_elf_cons, 4 },
5127 { "long", s_arm_elf_cons, 4 },
5128 { "inst.n", s_arm_elf_inst, 2 },
5129 { "inst.w", s_arm_elf_inst, 4 },
5130 { "inst", s_arm_elf_inst, 0 },
5131 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
5132 { "fnstart", s_arm_unwind_fnstart, 0 },
5133 { "fnend", s_arm_unwind_fnend, 0 },
5134 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5135 { "personality", s_arm_unwind_personality, 0 },
5136 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5137 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5138 { "save", s_arm_unwind_save, 0 },
fa073d69 5139 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
5140 { "movsp", s_arm_unwind_movsp, 0 },
5141 { "pad", s_arm_unwind_pad, 0 },
5142 { "setfp", s_arm_unwind_setfp, 0 },
5143 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 5144 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 5145 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
5146#else
5147 { "word", cons, 4},
f0927246
NC
5148
5149 /* These are used for dwarf. */
5150 {"2byte", cons, 2},
5151 {"4byte", cons, 4},
5152 {"8byte", cons, 8},
5153 /* These are used for dwarf2. */
68d20676 5154 { "file", dwarf2_directive_file, 0 },
f0927246
NC
5155 { "loc", dwarf2_directive_loc, 0 },
5156 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
5157#endif
5158 { "extend", float_cons, 'x' },
5159 { "ldouble", float_cons, 'x' },
5160 { "packed", float_cons, 'p' },
27cce866 5161 { "bfloat16", float_cons, 'b' },
f0927246
NC
5162#ifdef TE_PE
5163 {"secrel32", pe_directive_secrel, 0},
5164#endif
2e6976a8
DG
5165
5166 /* These are for compatibility with CodeComposer Studio. */
5167 {"ref", s_ccs_ref, 0},
5168 {"def", s_ccs_def, 0},
5169 {"asmfunc", s_ccs_asmfunc, 0},
5170 {"endasmfunc", s_ccs_endasmfunc, 0},
5171
5312fe52
BW
5172 {"float16", float_cons, 'h' },
5173 {"float16_format", set_fp16_format, 0 },
5174
c19d1205
ZW
5175 { 0, 0, 0 }
5176};
5312fe52 5177
c19d1205 5178/* Parser functions used exclusively in instruction operands. */
b99bd4ef 5179
c19d1205
ZW
5180/* Generic immediate-value read function for use in insn parsing.
5181 STR points to the beginning of the immediate (the leading #);
5182 VAL receives the value; if the value is outside [MIN, MAX]
5183 issue an error. PREFIX_OPT is true if the immediate prefix is
5184 optional. */
b99bd4ef 5185
c19d1205
ZW
5186static int
5187parse_immediate (char **str, int *val, int min, int max,
5188 bfd_boolean prefix_opt)
5189{
5190 expressionS exp;
0198d5e6 5191
c19d1205
ZW
5192 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5193 if (exp.X_op != O_constant)
b99bd4ef 5194 {
c19d1205
ZW
5195 inst.error = _("constant expression required");
5196 return FAIL;
5197 }
b99bd4ef 5198
c19d1205
ZW
5199 if (exp.X_add_number < min || exp.X_add_number > max)
5200 {
5201 inst.error = _("immediate value out of range");
5202 return FAIL;
5203 }
b99bd4ef 5204
c19d1205
ZW
5205 *val = exp.X_add_number;
5206 return SUCCESS;
5207}
b99bd4ef 5208
5287ad62 5209/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 5210 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
5211 instructions. Puts the result directly in inst.operands[i]. */
5212
5213static int
8335d6aa
JW
5214parse_big_immediate (char **str, int i, expressionS *in_exp,
5215 bfd_boolean allow_symbol_p)
5287ad62
JB
5216{
5217 expressionS exp;
8335d6aa 5218 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
5219 char *ptr = *str;
5220
8335d6aa 5221 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 5222
8335d6aa 5223 if (exp_p->X_op == O_constant)
036dc3f7 5224 {
8335d6aa 5225 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
5226 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5227 O_constant. We have to be careful not to break compilation for
5228 32-bit X_add_number, though. */
8335d6aa 5229 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 5230 {
8335d6aa
JW
5231 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5232 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5233 & 0xffffffff);
036dc3f7
PB
5234 inst.operands[i].regisimm = 1;
5235 }
5236 }
8335d6aa
JW
5237 else if (exp_p->X_op == O_big
5238 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
5239 {
5240 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 5241
5287ad62 5242 /* Bignums have their least significant bits in
477330fc
RM
5243 generic_bignum[0]. Make sure we put 32 bits in imm and
5244 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 5245 gas_assert (parts != 0);
95b75c01
NC
5246
5247 /* Make sure that the number is not too big.
5248 PR 11972: Bignums can now be sign-extended to the
5249 size of a .octa so check that the out of range bits
5250 are all zero or all one. */
8335d6aa 5251 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
5252 {
5253 LITTLENUM_TYPE m = -1;
5254
5255 if (generic_bignum[parts * 2] != 0
5256 && generic_bignum[parts * 2] != m)
5257 return FAIL;
5258
8335d6aa 5259 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
5260 if (generic_bignum[j] != generic_bignum[j-1])
5261 return FAIL;
5262 }
5263
5287ad62
JB
5264 inst.operands[i].imm = 0;
5265 for (j = 0; j < parts; j++, idx++)
7af67752
AM
5266 inst.operands[i].imm |= ((unsigned) generic_bignum[idx]
5267 << (LITTLENUM_NUMBER_OF_BITS * j));
5287ad62
JB
5268 inst.operands[i].reg = 0;
5269 for (j = 0; j < parts; j++, idx++)
7af67752
AM
5270 inst.operands[i].reg |= ((unsigned) generic_bignum[idx]
5271 << (LITTLENUM_NUMBER_OF_BITS * j));
5287ad62
JB
5272 inst.operands[i].regisimm = 1;
5273 }
8335d6aa 5274 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 5275 return FAIL;
5f4273c7 5276
5287ad62
JB
5277 *str = ptr;
5278
5279 return SUCCESS;
5280}
5281
c19d1205
ZW
5282/* Returns the pseudo-register number of an FPA immediate constant,
5283 or FAIL if there isn't a valid constant here. */
b99bd4ef 5284
c19d1205
ZW
5285static int
5286parse_fpa_immediate (char ** str)
5287{
5288 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5289 char * save_in;
5290 expressionS exp;
5291 int i;
5292 int j;
b99bd4ef 5293
c19d1205
ZW
5294 /* First try and match exact strings, this is to guarantee
5295 that some formats will work even for cross assembly. */
b99bd4ef 5296
c19d1205
ZW
5297 for (i = 0; fp_const[i]; i++)
5298 {
5299 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 5300 {
c19d1205 5301 char *start = *str;
b99bd4ef 5302
c19d1205
ZW
5303 *str += strlen (fp_const[i]);
5304 if (is_end_of_line[(unsigned char) **str])
5305 return i + 8;
5306 *str = start;
5307 }
5308 }
b99bd4ef 5309
c19d1205
ZW
5310 /* Just because we didn't get a match doesn't mean that the constant
5311 isn't valid, just that it is in a format that we don't
5312 automatically recognize. Try parsing it with the standard
5313 expression routines. */
b99bd4ef 5314
c19d1205 5315 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 5316
c19d1205
ZW
5317 /* Look for a raw floating point number. */
5318 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5319 && is_end_of_line[(unsigned char) *save_in])
5320 {
5321 for (i = 0; i < NUM_FLOAT_VALS; i++)
5322 {
5323 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 5324 {
c19d1205
ZW
5325 if (words[j] != fp_values[i][j])
5326 break;
b99bd4ef
NC
5327 }
5328
c19d1205 5329 if (j == MAX_LITTLENUMS)
b99bd4ef 5330 {
c19d1205
ZW
5331 *str = save_in;
5332 return i + 8;
b99bd4ef
NC
5333 }
5334 }
5335 }
b99bd4ef 5336
c19d1205
ZW
5337 /* Try and parse a more complex expression, this will probably fail
5338 unless the code uses a floating point prefix (eg "0f"). */
5339 save_in = input_line_pointer;
5340 input_line_pointer = *str;
5341 if (expression (&exp) == absolute_section
5342 && exp.X_op == O_big
5343 && exp.X_add_number < 0)
5344 {
5345 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5346 Ditto for 15. */
ba592044
AM
5347#define X_PRECISION 5
5348#define E_PRECISION 15L
5349 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
5350 {
5351 for (i = 0; i < NUM_FLOAT_VALS; i++)
5352 {
5353 for (j = 0; j < MAX_LITTLENUMS; j++)
5354 {
5355 if (words[j] != fp_values[i][j])
5356 break;
5357 }
b99bd4ef 5358
c19d1205
ZW
5359 if (j == MAX_LITTLENUMS)
5360 {
5361 *str = input_line_pointer;
5362 input_line_pointer = save_in;
5363 return i + 8;
5364 }
5365 }
5366 }
b99bd4ef
NC
5367 }
5368
c19d1205
ZW
5369 *str = input_line_pointer;
5370 input_line_pointer = save_in;
5371 inst.error = _("invalid FPA immediate expression");
5372 return FAIL;
b99bd4ef
NC
5373}
5374
136da414
JB
5375/* Returns 1 if a number has "quarter-precision" float format
5376 0baBbbbbbc defgh000 00000000 00000000. */
5377
5378static int
5379is_quarter_float (unsigned imm)
5380{
5381 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5382 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5383}
5384
aacf0b33
KT
5385
5386/* Detect the presence of a floating point or integer zero constant,
5387 i.e. #0.0 or #0. */
5388
5389static bfd_boolean
5390parse_ifimm_zero (char **in)
5391{
5392 int error_code;
5393
5394 if (!is_immediate_prefix (**in))
3c6452ae
TP
5395 {
5396 /* In unified syntax, all prefixes are optional. */
5397 if (!unified_syntax)
5398 return FALSE;
5399 }
5400 else
5401 ++*in;
0900a05b
JW
5402
5403 /* Accept #0x0 as a synonym for #0. */
5404 if (strncmp (*in, "0x", 2) == 0)
5405 {
5406 int val;
5407 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5408 return FALSE;
5409 return TRUE;
5410 }
5411
aacf0b33
KT
5412 error_code = atof_generic (in, ".", EXP_CHARS,
5413 &generic_floating_point_number);
5414
5415 if (!error_code
5416 && generic_floating_point_number.sign == '+'
5417 && (generic_floating_point_number.low
5418 > generic_floating_point_number.leader))
5419 return TRUE;
5420
5421 return FALSE;
5422}
5423
136da414
JB
5424/* Parse an 8-bit "quarter-precision" floating point number of the form:
5425 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5426 The zero and minus-zero cases need special handling, since they can't be
5427 encoded in the "quarter-precision" float format, but can nonetheless be
5428 loaded as integer constants. */
136da414
JB
5429
5430static unsigned
5431parse_qfloat_immediate (char **ccp, int *immed)
5432{
5433 char *str = *ccp;
c96612cc 5434 char *fpnum;
136da414 5435 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5436 int found_fpchar = 0;
5f4273c7 5437
136da414 5438 skip_past_char (&str, '#');
5f4273c7 5439
c96612cc
JB
5440 /* We must not accidentally parse an integer as a floating-point number. Make
5441 sure that the value we parse is not an integer by checking for special
5442 characters '.' or 'e'.
5443 FIXME: This is a horrible hack, but doing better is tricky because type
5444 information isn't in a very usable state at parse time. */
5445 fpnum = str;
5446 skip_whitespace (fpnum);
5447
5448 if (strncmp (fpnum, "0x", 2) == 0)
5449 return FAIL;
5450 else
5451 {
5452 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5453 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5454 {
5455 found_fpchar = 1;
5456 break;
5457 }
c96612cc
JB
5458
5459 if (!found_fpchar)
477330fc 5460 return FAIL;
c96612cc 5461 }
5f4273c7 5462
136da414
JB
5463 if ((str = atof_ieee (str, 's', words)) != NULL)
5464 {
5465 unsigned fpword = 0;
5466 int i;
5f4273c7 5467
136da414
JB
5468 /* Our FP word must be 32 bits (single-precision FP). */
5469 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5470 {
5471 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5472 fpword |= words[i];
5473 }
5f4273c7 5474
c96612cc 5475 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5476 *immed = fpword;
136da414 5477 else
477330fc 5478 return FAIL;
136da414
JB
5479
5480 *ccp = str;
5f4273c7 5481
136da414
JB
5482 return SUCCESS;
5483 }
5f4273c7 5484
136da414
JB
5485 return FAIL;
5486}
5487
c19d1205
ZW
5488/* Shift operands. */
5489enum shift_kind
b99bd4ef 5490{
f5f10c66 5491 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
c19d1205 5492};
b99bd4ef 5493
c19d1205
ZW
5494struct asm_shift_name
5495{
5496 const char *name;
5497 enum shift_kind kind;
5498};
b99bd4ef 5499
c19d1205
ZW
5500/* Third argument to parse_shift. */
5501enum parse_shift_mode
5502{
5503 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5504 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5505 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5506 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5507 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
f5f10c66 5508 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
c19d1205 5509};
b99bd4ef 5510
c19d1205
ZW
5511/* Parse a <shift> specifier on an ARM data processing instruction.
5512 This has three forms:
b99bd4ef 5513
c19d1205
ZW
5514 (LSL|LSR|ASL|ASR|ROR) Rs
5515 (LSL|LSR|ASL|ASR|ROR) #imm
5516 RRX
b99bd4ef 5517
c19d1205
ZW
5518 Note that ASL is assimilated to LSL in the instruction encoding, and
5519 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5520
c19d1205
ZW
5521static int
5522parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5523{
c19d1205
ZW
5524 const struct asm_shift_name *shift_name;
5525 enum shift_kind shift;
5526 char *s = *str;
5527 char *p = s;
5528 int reg;
b99bd4ef 5529
c19d1205
ZW
5530 for (p = *str; ISALPHA (*p); p++)
5531 ;
b99bd4ef 5532
c19d1205 5533 if (p == *str)
b99bd4ef 5534 {
c19d1205
ZW
5535 inst.error = _("shift expression expected");
5536 return FAIL;
b99bd4ef
NC
5537 }
5538
fe0e921f
AM
5539 shift_name
5540 = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str,
5541 p - *str);
c19d1205
ZW
5542
5543 if (shift_name == NULL)
b99bd4ef 5544 {
c19d1205
ZW
5545 inst.error = _("shift expression expected");
5546 return FAIL;
b99bd4ef
NC
5547 }
5548
c19d1205 5549 shift = shift_name->kind;
b99bd4ef 5550
c19d1205
ZW
5551 switch (mode)
5552 {
5553 case NO_SHIFT_RESTRICT:
f5f10c66
AV
5554 case SHIFT_IMMEDIATE:
5555 if (shift == SHIFT_UXTW)
5556 {
5557 inst.error = _("'UXTW' not allowed here");
5558 return FAIL;
5559 }
5560 break;
b99bd4ef 5561
c19d1205
ZW
5562 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5563 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5564 {
5565 inst.error = _("'LSL' or 'ASR' required");
5566 return FAIL;
5567 }
5568 break;
b99bd4ef 5569
c19d1205
ZW
5570 case SHIFT_LSL_IMMEDIATE:
5571 if (shift != SHIFT_LSL)
5572 {
5573 inst.error = _("'LSL' required");
5574 return FAIL;
5575 }
5576 break;
b99bd4ef 5577
c19d1205
ZW
5578 case SHIFT_ASR_IMMEDIATE:
5579 if (shift != SHIFT_ASR)
5580 {
5581 inst.error = _("'ASR' required");
5582 return FAIL;
5583 }
5584 break;
f5f10c66
AV
5585 case SHIFT_UXTW_IMMEDIATE:
5586 if (shift != SHIFT_UXTW)
5587 {
5588 inst.error = _("'UXTW' required");
5589 return FAIL;
5590 }
5591 break;
b99bd4ef 5592
c19d1205
ZW
5593 default: abort ();
5594 }
b99bd4ef 5595
c19d1205
ZW
5596 if (shift != SHIFT_RRX)
5597 {
5598 /* Whitespace can appear here if the next thing is a bare digit. */
5599 skip_whitespace (p);
b99bd4ef 5600
c19d1205 5601 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5602 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5603 {
5604 inst.operands[i].imm = reg;
5605 inst.operands[i].immisreg = 1;
5606 }
e2b0ab59 5607 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
c19d1205
ZW
5608 return FAIL;
5609 }
5610 inst.operands[i].shift_kind = shift;
5611 inst.operands[i].shifted = 1;
5612 *str = p;
5613 return SUCCESS;
b99bd4ef
NC
5614}
5615
c19d1205 5616/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5617
c19d1205
ZW
5618 #<immediate>
5619 #<immediate>, <rotate>
5620 <Rm>
5621 <Rm>, <shift>
b99bd4ef 5622
c19d1205
ZW
5623 where <shift> is defined by parse_shift above, and <rotate> is a
5624 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5625 is deferred to md_apply_fix. */
b99bd4ef 5626
c19d1205
ZW
5627static int
5628parse_shifter_operand (char **str, int i)
5629{
5630 int value;
91d6fa6a 5631 expressionS exp;
b99bd4ef 5632
dcbf9037 5633 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5634 {
5635 inst.operands[i].reg = value;
5636 inst.operands[i].isreg = 1;
b99bd4ef 5637
c19d1205 5638 /* parse_shift will override this if appropriate */
e2b0ab59
AV
5639 inst.relocs[0].exp.X_op = O_constant;
5640 inst.relocs[0].exp.X_add_number = 0;
b99bd4ef 5641
c19d1205
ZW
5642 if (skip_past_comma (str) == FAIL)
5643 return SUCCESS;
b99bd4ef 5644
c19d1205
ZW
5645 /* Shift operation on register. */
5646 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5647 }
5648
e2b0ab59 5649 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
c19d1205 5650 return FAIL;
b99bd4ef 5651
c19d1205 5652 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5653 {
c19d1205 5654 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5655 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5656 return FAIL;
b99bd4ef 5657
e2b0ab59 5658 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
c19d1205
ZW
5659 {
5660 inst.error = _("constant expression expected");
5661 return FAIL;
5662 }
b99bd4ef 5663
91d6fa6a 5664 value = exp.X_add_number;
c19d1205
ZW
5665 if (value < 0 || value > 30 || value % 2 != 0)
5666 {
5667 inst.error = _("invalid rotation");
5668 return FAIL;
5669 }
e2b0ab59
AV
5670 if (inst.relocs[0].exp.X_add_number < 0
5671 || inst.relocs[0].exp.X_add_number > 255)
c19d1205
ZW
5672 {
5673 inst.error = _("invalid constant");
5674 return FAIL;
5675 }
09d92015 5676
a415b1cd 5677 /* Encode as specified. */
e2b0ab59 5678 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
a415b1cd 5679 return SUCCESS;
09d92015
MM
5680 }
5681
e2b0ab59
AV
5682 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5683 inst.relocs[0].pc_rel = 0;
c19d1205 5684 return SUCCESS;
09d92015
MM
5685}
5686
4962c51a
MS
5687/* Group relocation information. Each entry in the table contains the
5688 textual name of the relocation as may appear in assembler source
5689 and must end with a colon.
5690 Along with this textual name are the relocation codes to be used if
5691 the corresponding instruction is an ALU instruction (ADD or SUB only),
5692 an LDR, an LDRS, or an LDC. */
5693
5694struct group_reloc_table_entry
5695{
5696 const char *name;
5697 int alu_code;
5698 int ldr_code;
5699 int ldrs_code;
5700 int ldc_code;
5701};
5702
5703typedef enum
5704{
5705 /* Varieties of non-ALU group relocation. */
5706
5707 GROUP_LDR,
5708 GROUP_LDRS,
35c228db
AV
5709 GROUP_LDC,
5710 GROUP_MVE
4962c51a
MS
5711} group_reloc_type;
5712
5713static struct group_reloc_table_entry group_reloc_table[] =
5714 { /* Program counter relative: */
5715 { "pc_g0_nc",
5716 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5717 0, /* LDR */
5718 0, /* LDRS */
5719 0 }, /* LDC */
5720 { "pc_g0",
5721 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5722 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5723 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5724 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5725 { "pc_g1_nc",
5726 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5727 0, /* LDR */
5728 0, /* LDRS */
5729 0 }, /* LDC */
5730 { "pc_g1",
5731 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5732 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5733 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5734 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5735 { "pc_g2",
5736 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5737 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5738 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5739 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5740 /* Section base relative */
5741 { "sb_g0_nc",
5742 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5743 0, /* LDR */
5744 0, /* LDRS */
5745 0 }, /* LDC */
5746 { "sb_g0",
5747 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5748 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5749 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5750 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5751 { "sb_g1_nc",
5752 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5753 0, /* LDR */
5754 0, /* LDRS */
5755 0 }, /* LDC */
5756 { "sb_g1",
5757 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5758 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5759 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5760 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5761 { "sb_g2",
5762 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5763 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5764 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5765 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5766 /* Absolute thumb alu relocations. */
5767 { "lower0_7",
5768 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5769 0, /* LDR. */
5770 0, /* LDRS. */
5771 0 }, /* LDC. */
5772 { "lower8_15",
5773 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5774 0, /* LDR. */
5775 0, /* LDRS. */
5776 0 }, /* LDC. */
5777 { "upper0_7",
5778 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5779 0, /* LDR. */
5780 0, /* LDRS. */
5781 0 }, /* LDC. */
5782 { "upper8_15",
5783 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5784 0, /* LDR. */
5785 0, /* LDRS. */
5786 0 } }; /* LDC. */
4962c51a
MS
5787
5788/* Given the address of a pointer pointing to the textual name of a group
5789 relocation as may appear in assembler source, attempt to find its details
5790 in group_reloc_table. The pointer will be updated to the character after
5791 the trailing colon. On failure, FAIL will be returned; SUCCESS
5792 otherwise. On success, *entry will be updated to point at the relevant
5793 group_reloc_table entry. */
5794
5795static int
5796find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5797{
5798 unsigned int i;
5799 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5800 {
5801 int length = strlen (group_reloc_table[i].name);
5802
5f4273c7
NC
5803 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5804 && (*str)[length] == ':')
477330fc
RM
5805 {
5806 *out = &group_reloc_table[i];
5807 *str += (length + 1);
5808 return SUCCESS;
5809 }
4962c51a
MS
5810 }
5811
5812 return FAIL;
5813}
5814
5815/* Parse a <shifter_operand> for an ARM data processing instruction
5816 (as for parse_shifter_operand) where group relocations are allowed:
5817
5818 #<immediate>
5819 #<immediate>, <rotate>
5820 #:<group_reloc>:<expression>
5821 <Rm>
5822 <Rm>, <shift>
5823
5824 where <group_reloc> is one of the strings defined in group_reloc_table.
5825 The hashes are optional.
5826
5827 Everything else is as for parse_shifter_operand. */
5828
5829static parse_operand_result
5830parse_shifter_operand_group_reloc (char **str, int i)
5831{
5832 /* Determine if we have the sequence of characters #: or just :
5833 coming next. If we do, then we check for a group relocation.
5834 If we don't, punt the whole lot to parse_shifter_operand. */
5835
5836 if (((*str)[0] == '#' && (*str)[1] == ':')
5837 || (*str)[0] == ':')
5838 {
5839 struct group_reloc_table_entry *entry;
5840
5841 if ((*str)[0] == '#')
477330fc 5842 (*str) += 2;
4962c51a 5843 else
477330fc 5844 (*str)++;
4962c51a
MS
5845
5846 /* Try to parse a group relocation. Anything else is an error. */
5847 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5848 {
5849 inst.error = _("unknown group relocation");
5850 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5851 }
4962c51a
MS
5852
5853 /* We now have the group relocation table entry corresponding to
477330fc 5854 the name in the assembler source. Next, we parse the expression. */
e2b0ab59 5855 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
477330fc 5856 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5857
5858 /* Record the relocation type (always the ALU variant here). */
e2b0ab59
AV
5859 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5860 gas_assert (inst.relocs[0].type != 0);
4962c51a
MS
5861
5862 return PARSE_OPERAND_SUCCESS;
5863 }
5864 else
5865 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5866 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5867
5868 /* Never reached. */
5869}
5870
8e560766
MGD
5871/* Parse a Neon alignment expression. Information is written to
5872 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5873
8e560766
MGD
5874 align .imm = align << 8, .immisalign=1, .preind=0 */
5875static parse_operand_result
5876parse_neon_alignment (char **str, int i)
5877{
5878 char *p = *str;
5879 expressionS exp;
5880
5881 my_get_expression (&exp, &p, GE_NO_PREFIX);
5882
5883 if (exp.X_op != O_constant)
5884 {
5885 inst.error = _("alignment must be constant");
5886 return PARSE_OPERAND_FAIL;
5887 }
5888
5889 inst.operands[i].imm = exp.X_add_number << 8;
5890 inst.operands[i].immisalign = 1;
5891 /* Alignments are not pre-indexes. */
5892 inst.operands[i].preind = 0;
5893
5894 *str = p;
5895 return PARSE_OPERAND_SUCCESS;
5896}
5897
c19d1205 5898/* Parse all forms of an ARM address expression. Information is written
e2b0ab59 5899 to inst.operands[i] and/or inst.relocs[0].
09d92015 5900
c19d1205 5901 Preindexed addressing (.preind=1):
09d92015 5902
e2b0ab59 5903 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5904 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5905 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5906 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5907
c19d1205 5908 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5909
c19d1205 5910 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5911
e2b0ab59 5912 [Rn], #offset .reg=Rn .relocs[0].exp=offset
c19d1205
ZW
5913 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5914 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
e2b0ab59 5915 .shift_kind=shift .relocs[0].exp=shift_imm
09d92015 5916
c19d1205 5917 Unindexed addressing (.preind=0, .postind=0):
09d92015 5918
c19d1205 5919 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5920
c19d1205 5921 Other:
09d92015 5922
c19d1205 5923 [Rn]{!} shorthand for [Rn,#0]{!}
e2b0ab59
AV
5924 =immediate .isreg=0 .relocs[0].exp=immediate
5925 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
09d92015 5926
c19d1205 5927 It is the caller's responsibility to check for addressing modes not
e2b0ab59 5928 supported by the instruction, and to set inst.relocs[0].type. */
c19d1205 5929
4962c51a
MS
5930static parse_operand_result
5931parse_address_main (char **str, int i, int group_relocations,
477330fc 5932 group_reloc_type group_type)
09d92015 5933{
c19d1205
ZW
5934 char *p = *str;
5935 int reg;
09d92015 5936
c19d1205 5937 if (skip_past_char (&p, '[') == FAIL)
09d92015 5938 {
79248c83
SP
5939 if (group_type == GROUP_MVE
5940 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5941 {
5942 /* [r0-r15] expected as argument but receiving r0-r15 without
5943 [] brackets. */
5944 inst.error = BAD_SYNTAX;
5945 return PARSE_OPERAND_FAIL;
5946 }
5947 else if (skip_past_char (&p, '=') == FAIL)
c19d1205 5948 {
974da60d 5949 /* Bare address - translate to PC-relative offset. */
e2b0ab59 5950 inst.relocs[0].pc_rel = 1;
c19d1205
ZW
5951 inst.operands[i].reg = REG_PC;
5952 inst.operands[i].isreg = 1;
5953 inst.operands[i].preind = 1;
09d92015 5954
e2b0ab59 5955 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
8335d6aa
JW
5956 return PARSE_OPERAND_FAIL;
5957 }
e2b0ab59 5958 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
8335d6aa 5959 /*allow_symbol_p=*/TRUE))
4962c51a 5960 return PARSE_OPERAND_FAIL;
09d92015 5961
c19d1205 5962 *str = p;
4962c51a 5963 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5964 }
5965
8ab8155f
NC
5966 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5967 skip_whitespace (p);
5968
f5f10c66
AV
5969 if (group_type == GROUP_MVE)
5970 {
5971 enum arm_reg_type rtype = REG_TYPE_MQ;
5972 struct neon_type_el et;
5973 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5974 {
5975 inst.operands[i].isquad = 1;
5976 }
5977 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5978 {
5979 inst.error = BAD_ADDR_MODE;
5980 return PARSE_OPERAND_FAIL;
5981 }
5982 }
5983 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5984 {
35c228db
AV
5985 if (group_type == GROUP_MVE)
5986 inst.error = BAD_ADDR_MODE;
5987 else
5988 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5989 return PARSE_OPERAND_FAIL;
09d92015 5990 }
c19d1205
ZW
5991 inst.operands[i].reg = reg;
5992 inst.operands[i].isreg = 1;
09d92015 5993
c19d1205 5994 if (skip_past_comma (&p) == SUCCESS)
09d92015 5995 {
c19d1205 5996 inst.operands[i].preind = 1;
09d92015 5997
c19d1205
ZW
5998 if (*p == '+') p++;
5999 else if (*p == '-') p++, inst.operands[i].negative = 1;
6000
f5f10c66
AV
6001 enum arm_reg_type rtype = REG_TYPE_MQ;
6002 struct neon_type_el et;
6003 if (group_type == GROUP_MVE
6004 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6005 {
6006 inst.operands[i].immisreg = 2;
6007 inst.operands[i].imm = reg;
6008
6009 if (skip_past_comma (&p) == SUCCESS)
6010 {
6011 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6012 {
6013 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6014 inst.relocs[0].exp.X_add_number = 0;
6015 }
6016 else
6017 return PARSE_OPERAND_FAIL;
6018 }
6019 }
6020 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 6021 {
c19d1205
ZW
6022 inst.operands[i].imm = reg;
6023 inst.operands[i].immisreg = 1;
6024
6025 if (skip_past_comma (&p) == SUCCESS)
6026 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6027 return PARSE_OPERAND_FAIL;
c19d1205 6028 }
5287ad62 6029 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
6030 {
6031 /* FIXME: '@' should be used here, but it's filtered out by generic
6032 code before we get to see it here. This may be subject to
6033 change. */
6034 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6035
8e560766
MGD
6036 if (result != PARSE_OPERAND_SUCCESS)
6037 return result;
6038 }
c19d1205
ZW
6039 else
6040 {
6041 if (inst.operands[i].negative)
6042 {
6043 inst.operands[i].negative = 0;
6044 p--;
6045 }
4962c51a 6046
5f4273c7
NC
6047 if (group_relocations
6048 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
6049 {
6050 struct group_reloc_table_entry *entry;
6051
477330fc
RM
6052 /* Skip over the #: or : sequence. */
6053 if (*p == '#')
6054 p += 2;
6055 else
6056 p++;
4962c51a
MS
6057
6058 /* Try to parse a group relocation. Anything else is an
477330fc 6059 error. */
4962c51a
MS
6060 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6061 {
6062 inst.error = _("unknown group relocation");
6063 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6064 }
6065
6066 /* We now have the group relocation table entry corresponding to
6067 the name in the assembler source. Next, we parse the
477330fc 6068 expression. */
e2b0ab59 6069 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
4962c51a
MS
6070 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6071
6072 /* Record the relocation type. */
477330fc
RM
6073 switch (group_type)
6074 {
6075 case GROUP_LDR:
e2b0ab59
AV
6076 inst.relocs[0].type
6077 = (bfd_reloc_code_real_type) entry->ldr_code;
477330fc 6078 break;
4962c51a 6079
477330fc 6080 case GROUP_LDRS:
e2b0ab59
AV
6081 inst.relocs[0].type
6082 = (bfd_reloc_code_real_type) entry->ldrs_code;
477330fc 6083 break;
4962c51a 6084
477330fc 6085 case GROUP_LDC:
e2b0ab59
AV
6086 inst.relocs[0].type
6087 = (bfd_reloc_code_real_type) entry->ldc_code;
477330fc 6088 break;
4962c51a 6089
477330fc
RM
6090 default:
6091 gas_assert (0);
6092 }
4962c51a 6093
e2b0ab59 6094 if (inst.relocs[0].type == 0)
4962c51a
MS
6095 {
6096 inst.error = _("this group relocation is not allowed on this instruction");
6097 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6098 }
477330fc
RM
6099 }
6100 else
26d97720
NS
6101 {
6102 char *q = p;
0198d5e6 6103
e2b0ab59 6104 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
26d97720
NS
6105 return PARSE_OPERAND_FAIL;
6106 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6107 if (inst.relocs[0].exp.X_op == O_constant
6108 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6109 {
6110 skip_whitespace (q);
6111 if (*q == '#')
6112 {
6113 q++;
6114 skip_whitespace (q);
6115 }
6116 if (*q == '-')
6117 inst.operands[i].negative = 1;
6118 }
6119 }
09d92015
MM
6120 }
6121 }
8e560766
MGD
6122 else if (skip_past_char (&p, ':') == SUCCESS)
6123 {
6124 /* FIXME: '@' should be used here, but it's filtered out by generic code
6125 before we get to see it here. This may be subject to change. */
6126 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 6127
8e560766
MGD
6128 if (result != PARSE_OPERAND_SUCCESS)
6129 return result;
6130 }
09d92015 6131
c19d1205 6132 if (skip_past_char (&p, ']') == FAIL)
09d92015 6133 {
c19d1205 6134 inst.error = _("']' expected");
4962c51a 6135 return PARSE_OPERAND_FAIL;
09d92015
MM
6136 }
6137
c19d1205
ZW
6138 if (skip_past_char (&p, '!') == SUCCESS)
6139 inst.operands[i].writeback = 1;
09d92015 6140
c19d1205 6141 else if (skip_past_comma (&p) == SUCCESS)
09d92015 6142 {
c19d1205
ZW
6143 if (skip_past_char (&p, '{') == SUCCESS)
6144 {
6145 /* [Rn], {expr} - unindexed, with option */
6146 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 6147 0, 255, TRUE) == FAIL)
4962c51a 6148 return PARSE_OPERAND_FAIL;
09d92015 6149
c19d1205
ZW
6150 if (skip_past_char (&p, '}') == FAIL)
6151 {
6152 inst.error = _("'}' expected at end of 'option' field");
4962c51a 6153 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6154 }
6155 if (inst.operands[i].preind)
6156 {
6157 inst.error = _("cannot combine index with option");
4962c51a 6158 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6159 }
6160 *str = p;
4962c51a 6161 return PARSE_OPERAND_SUCCESS;
09d92015 6162 }
c19d1205
ZW
6163 else
6164 {
6165 inst.operands[i].postind = 1;
6166 inst.operands[i].writeback = 1;
09d92015 6167
c19d1205
ZW
6168 if (inst.operands[i].preind)
6169 {
6170 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 6171 return PARSE_OPERAND_FAIL;
c19d1205 6172 }
09d92015 6173
c19d1205
ZW
6174 if (*p == '+') p++;
6175 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 6176
f5f10c66
AV
6177 enum arm_reg_type rtype = REG_TYPE_MQ;
6178 struct neon_type_el et;
6179 if (group_type == GROUP_MVE
6180 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6181 {
6182 inst.operands[i].immisreg = 2;
6183 inst.operands[i].imm = reg;
6184 }
6185 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 6186 {
477330fc
RM
6187 /* We might be using the immediate for alignment already. If we
6188 are, OR the register number into the low-order bits. */
6189 if (inst.operands[i].immisalign)
6190 inst.operands[i].imm |= reg;
6191 else
6192 inst.operands[i].imm = reg;
c19d1205 6193 inst.operands[i].immisreg = 1;
a737bd4d 6194
c19d1205
ZW
6195 if (skip_past_comma (&p) == SUCCESS)
6196 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 6197 return PARSE_OPERAND_FAIL;
c19d1205
ZW
6198 }
6199 else
6200 {
26d97720 6201 char *q = p;
0198d5e6 6202
c19d1205
ZW
6203 if (inst.operands[i].negative)
6204 {
6205 inst.operands[i].negative = 0;
6206 p--;
6207 }
e2b0ab59 6208 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
4962c51a 6209 return PARSE_OPERAND_FAIL;
26d97720 6210 /* If the offset is 0, find out if it's a +0 or -0. */
e2b0ab59
AV
6211 if (inst.relocs[0].exp.X_op == O_constant
6212 && inst.relocs[0].exp.X_add_number == 0)
26d97720
NS
6213 {
6214 skip_whitespace (q);
6215 if (*q == '#')
6216 {
6217 q++;
6218 skip_whitespace (q);
6219 }
6220 if (*q == '-')
6221 inst.operands[i].negative = 1;
6222 }
c19d1205
ZW
6223 }
6224 }
a737bd4d
NC
6225 }
6226
c19d1205
ZW
6227 /* If at this point neither .preind nor .postind is set, we have a
6228 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6229 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6230 {
6231 inst.operands[i].preind = 1;
e2b0ab59
AV
6232 inst.relocs[0].exp.X_op = O_constant;
6233 inst.relocs[0].exp.X_add_number = 0;
c19d1205
ZW
6234 }
6235 *str = p;
4962c51a
MS
6236 return PARSE_OPERAND_SUCCESS;
6237}
6238
6239static int
6240parse_address (char **str, int i)
6241{
21d799b5 6242 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 6243 ? SUCCESS : FAIL;
4962c51a
MS
6244}
6245
6246static parse_operand_result
6247parse_address_group_reloc (char **str, int i, group_reloc_type type)
6248{
6249 return parse_address_main (str, i, 1, type);
a737bd4d
NC
6250}
6251
b6895b4f
PB
6252/* Parse an operand for a MOVW or MOVT instruction. */
6253static int
6254parse_half (char **str)
6255{
6256 char * p;
5f4273c7 6257
b6895b4f
PB
6258 p = *str;
6259 skip_past_char (&p, '#');
5f4273c7 6260 if (strncasecmp (p, ":lower16:", 9) == 0)
e2b0ab59 6261 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
b6895b4f 6262 else if (strncasecmp (p, ":upper16:", 9) == 0)
e2b0ab59 6263 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
b6895b4f 6264
e2b0ab59 6265 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
b6895b4f
PB
6266 {
6267 p += 9;
5f4273c7 6268 skip_whitespace (p);
b6895b4f
PB
6269 }
6270
e2b0ab59 6271 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
b6895b4f
PB
6272 return FAIL;
6273
e2b0ab59 6274 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 6275 {
e2b0ab59 6276 if (inst.relocs[0].exp.X_op != O_constant)
b6895b4f
PB
6277 {
6278 inst.error = _("constant expression expected");
6279 return FAIL;
6280 }
e2b0ab59
AV
6281 if (inst.relocs[0].exp.X_add_number < 0
6282 || inst.relocs[0].exp.X_add_number > 0xffff)
b6895b4f
PB
6283 {
6284 inst.error = _("immediate value out of range");
6285 return FAIL;
6286 }
6287 }
6288 *str = p;
6289 return SUCCESS;
6290}
6291
c19d1205 6292/* Miscellaneous. */
a737bd4d 6293
c19d1205
ZW
6294/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6295 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6296static int
d2cd1205 6297parse_psr (char **str, bfd_boolean lhs)
09d92015 6298{
c19d1205
ZW
6299 char *p;
6300 unsigned long psr_field;
62b3e311
PB
6301 const struct asm_psr *psr;
6302 char *start;
d2cd1205 6303 bfd_boolean is_apsr = FALSE;
ac7f631b 6304 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 6305
a4482bb6
NC
6306 /* PR gas/12698: If the user has specified -march=all then m_profile will
6307 be TRUE, but we want to ignore it in this case as we are building for any
6308 CPU type, including non-m variants. */
823d2571 6309 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
6310 m_profile = FALSE;
6311
c19d1205
ZW
6312 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6313 feature for ease of use and backwards compatibility. */
6314 p = *str;
62b3e311 6315 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
6316 {
6317 if (m_profile)
6318 goto unsupported_psr;
fa94de6b 6319
d2cd1205
JB
6320 psr_field = SPSR_BIT;
6321 }
6322 else if (strncasecmp (p, "CPSR", 4) == 0)
6323 {
6324 if (m_profile)
6325 goto unsupported_psr;
6326
6327 psr_field = 0;
6328 }
6329 else if (strncasecmp (p, "APSR", 4) == 0)
6330 {
6331 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6332 and ARMv7-R architecture CPUs. */
6333 is_apsr = TRUE;
6334 psr_field = 0;
6335 }
6336 else if (m_profile)
62b3e311
PB
6337 {
6338 start = p;
6339 do
6340 p++;
6341 while (ISALNUM (*p) || *p == '_');
6342
d2cd1205
JB
6343 if (strncasecmp (start, "iapsr", 5) == 0
6344 || strncasecmp (start, "eapsr", 5) == 0
6345 || strncasecmp (start, "xpsr", 4) == 0
6346 || strncasecmp (start, "psr", 3) == 0)
6347 p = start + strcspn (start, "rR") + 1;
6348
629310ab 6349 psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start,
fe0e921f 6350 p - start);
d2cd1205 6351
62b3e311
PB
6352 if (!psr)
6353 return FAIL;
09d92015 6354
d2cd1205
JB
6355 /* If APSR is being written, a bitfield may be specified. Note that
6356 APSR itself is handled above. */
6357 if (psr->field <= 3)
6358 {
6359 psr_field = psr->field;
6360 is_apsr = TRUE;
6361 goto check_suffix;
6362 }
6363
62b3e311 6364 *str = p;
d2cd1205
JB
6365 /* M-profile MSR instructions have the mask field set to "10", except
6366 *PSR variants which modify APSR, which may use a different mask (and
6367 have been handled already). Do that by setting the PSR_f field
6368 here. */
6369 return psr->field | (lhs ? PSR_f : 0);
62b3e311 6370 }
d2cd1205
JB
6371 else
6372 goto unsupported_psr;
09d92015 6373
62b3e311 6374 p += 4;
dc1e8a47 6375 check_suffix:
c19d1205
ZW
6376 if (*p == '_')
6377 {
6378 /* A suffix follows. */
c19d1205
ZW
6379 p++;
6380 start = p;
a737bd4d 6381
c19d1205
ZW
6382 do
6383 p++;
6384 while (ISALNUM (*p) || *p == '_');
a737bd4d 6385
d2cd1205
JB
6386 if (is_apsr)
6387 {
6388 /* APSR uses a notation for bits, rather than fields. */
6389 unsigned int nzcvq_bits = 0;
6390 unsigned int g_bit = 0;
6391 char *bit;
fa94de6b 6392
d2cd1205
JB
6393 for (bit = start; bit != p; bit++)
6394 {
6395 switch (TOLOWER (*bit))
477330fc 6396 {
d2cd1205
JB
6397 case 'n':
6398 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6399 break;
6400
6401 case 'z':
6402 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6403 break;
6404
6405 case 'c':
6406 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6407 break;
6408
6409 case 'v':
6410 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6411 break;
fa94de6b 6412
d2cd1205
JB
6413 case 'q':
6414 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6415 break;
fa94de6b 6416
d2cd1205
JB
6417 case 'g':
6418 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6419 break;
fa94de6b 6420
d2cd1205
JB
6421 default:
6422 inst.error = _("unexpected bit specified after APSR");
6423 return FAIL;
6424 }
6425 }
fa94de6b 6426
d2cd1205
JB
6427 if (nzcvq_bits == 0x1f)
6428 psr_field |= PSR_f;
fa94de6b 6429
d2cd1205
JB
6430 if (g_bit == 0x1)
6431 {
6432 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 6433 {
d2cd1205
JB
6434 inst.error = _("selected processor does not "
6435 "support DSP extension");
6436 return FAIL;
6437 }
6438
6439 psr_field |= PSR_s;
6440 }
fa94de6b 6441
d2cd1205
JB
6442 if ((nzcvq_bits & 0x20) != 0
6443 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6444 || (g_bit & 0x2) != 0)
6445 {
6446 inst.error = _("bad bitmask specified after APSR");
6447 return FAIL;
6448 }
6449 }
6450 else
477330fc 6451 {
629310ab 6452 psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start,
fe0e921f 6453 p - start);
d2cd1205 6454 if (!psr)
477330fc 6455 goto error;
a737bd4d 6456
d2cd1205
JB
6457 psr_field |= psr->field;
6458 }
a737bd4d 6459 }
c19d1205 6460 else
a737bd4d 6461 {
c19d1205
ZW
6462 if (ISALNUM (*p))
6463 goto error; /* Garbage after "[CS]PSR". */
6464
d2cd1205 6465 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6466 is deprecated, but allow it anyway. */
d2cd1205
JB
6467 if (is_apsr && lhs)
6468 {
6469 psr_field |= PSR_f;
6470 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6471 "deprecated"));
6472 }
6473 else if (!m_profile)
6474 /* These bits are never right for M-profile devices: don't set them
6475 (only code paths which read/write APSR reach here). */
6476 psr_field |= (PSR_c | PSR_f);
a737bd4d 6477 }
c19d1205
ZW
6478 *str = p;
6479 return psr_field;
a737bd4d 6480
d2cd1205
JB
6481 unsupported_psr:
6482 inst.error = _("selected processor does not support requested special "
6483 "purpose register");
6484 return FAIL;
6485
c19d1205
ZW
6486 error:
6487 inst.error = _("flag for {c}psr instruction expected");
6488 return FAIL;
a737bd4d
NC
6489}
6490
32c36c3c
AV
6491static int
6492parse_sys_vldr_vstr (char **str)
6493{
6494 unsigned i;
6495 int val = FAIL;
6496 struct {
6497 const char *name;
6498 int regl;
6499 int regh;
6500 } sysregs[] = {
6501 {"FPSCR", 0x1, 0x0},
6502 {"FPSCR_nzcvqc", 0x2, 0x0},
6503 {"VPR", 0x4, 0x1},
6504 {"P0", 0x5, 0x1},
6505 {"FPCXTNS", 0x6, 0x1},
6506 {"FPCXTS", 0x7, 0x1}
6507 };
6508 char *op_end = strchr (*str, ',');
6509 size_t op_strlen = op_end - *str;
6510
6511 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6512 {
6513 if (!strncmp (*str, sysregs[i].name, op_strlen))
6514 {
6515 val = sysregs[i].regl | (sysregs[i].regh << 3);
6516 *str = op_end;
6517 break;
6518 }
6519 }
6520
6521 return val;
6522}
6523
c19d1205
ZW
6524/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6525 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6526
c19d1205
ZW
6527static int
6528parse_cps_flags (char **str)
a737bd4d 6529{
c19d1205
ZW
6530 int val = 0;
6531 int saw_a_flag = 0;
6532 char *s = *str;
a737bd4d 6533
c19d1205
ZW
6534 for (;;)
6535 switch (*s++)
6536 {
6537 case '\0': case ',':
6538 goto done;
a737bd4d 6539
c19d1205
ZW
6540 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6541 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6542 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6543
c19d1205
ZW
6544 default:
6545 inst.error = _("unrecognized CPS flag");
6546 return FAIL;
6547 }
a737bd4d 6548
c19d1205
ZW
6549 done:
6550 if (saw_a_flag == 0)
a737bd4d 6551 {
c19d1205
ZW
6552 inst.error = _("missing CPS flags");
6553 return FAIL;
a737bd4d 6554 }
a737bd4d 6555
c19d1205
ZW
6556 *str = s - 1;
6557 return val;
a737bd4d
NC
6558}
6559
c19d1205
ZW
6560/* Parse an endian specifier ("BE" or "LE", case insensitive);
6561 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6562
6563static int
c19d1205 6564parse_endian_specifier (char **str)
a737bd4d 6565{
c19d1205
ZW
6566 int little_endian;
6567 char *s = *str;
a737bd4d 6568
c19d1205
ZW
6569 if (strncasecmp (s, "BE", 2))
6570 little_endian = 0;
6571 else if (strncasecmp (s, "LE", 2))
6572 little_endian = 1;
6573 else
a737bd4d 6574 {
c19d1205 6575 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6576 return FAIL;
6577 }
6578
c19d1205 6579 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6580 {
c19d1205 6581 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6582 return FAIL;
6583 }
6584
c19d1205
ZW
6585 *str = s + 2;
6586 return little_endian;
6587}
a737bd4d 6588
c19d1205
ZW
6589/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6590 value suitable for poking into the rotate field of an sxt or sxta
6591 instruction, or FAIL on error. */
6592
6593static int
6594parse_ror (char **str)
6595{
6596 int rot;
6597 char *s = *str;
6598
6599 if (strncasecmp (s, "ROR", 3) == 0)
6600 s += 3;
6601 else
a737bd4d 6602 {
c19d1205 6603 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6604 return FAIL;
6605 }
c19d1205
ZW
6606
6607 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6608 return FAIL;
6609
6610 switch (rot)
a737bd4d 6611 {
c19d1205
ZW
6612 case 0: *str = s; return 0x0;
6613 case 8: *str = s; return 0x1;
6614 case 16: *str = s; return 0x2;
6615 case 24: *str = s; return 0x3;
6616
6617 default:
6618 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6619 return FAIL;
6620 }
c19d1205 6621}
a737bd4d 6622
c19d1205
ZW
6623/* Parse a conditional code (from conds[] below). The value returned is in the
6624 range 0 .. 14, or FAIL. */
6625static int
6626parse_cond (char **str)
6627{
c462b453 6628 char *q;
c19d1205 6629 const struct asm_cond *c;
c462b453
PB
6630 int n;
6631 /* Condition codes are always 2 characters, so matching up to
6632 3 characters is sufficient. */
6633 char cond[3];
a737bd4d 6634
c462b453
PB
6635 q = *str;
6636 n = 0;
6637 while (ISALPHA (*q) && n < 3)
6638 {
e07e6e58 6639 cond[n] = TOLOWER (*q);
c462b453
PB
6640 q++;
6641 n++;
6642 }
a737bd4d 6643
629310ab 6644 c = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6645 if (!c)
a737bd4d 6646 {
c19d1205 6647 inst.error = _("condition required");
a737bd4d
NC
6648 return FAIL;
6649 }
6650
c19d1205
ZW
6651 *str = q;
6652 return c->value;
6653}
6654
62b3e311
PB
6655/* Parse an option for a barrier instruction. Returns the encoding for the
6656 option, or FAIL. */
6657static int
6658parse_barrier (char **str)
6659{
6660 char *p, *q;
6661 const struct asm_barrier_opt *o;
6662
6663 p = q = *str;
6664 while (ISALPHA (*q))
6665 q++;
6666
629310ab 6667 o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p,
fe0e921f 6668 q - p);
62b3e311
PB
6669 if (!o)
6670 return FAIL;
6671
e797f7e0
MGD
6672 if (!mark_feature_used (&o->arch))
6673 return FAIL;
6674
62b3e311
PB
6675 *str = q;
6676 return o->value;
6677}
6678
92e90b6e
PB
6679/* Parse the operands of a table branch instruction. Similar to a memory
6680 operand. */
6681static int
6682parse_tb (char **str)
6683{
6684 char * p = *str;
6685 int reg;
6686
6687 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6688 {
6689 inst.error = _("'[' expected");
6690 return FAIL;
6691 }
92e90b6e 6692
dcbf9037 6693 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6694 {
6695 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6696 return FAIL;
6697 }
6698 inst.operands[0].reg = reg;
6699
6700 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6701 {
6702 inst.error = _("',' expected");
6703 return FAIL;
6704 }
5f4273c7 6705
dcbf9037 6706 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6707 {
6708 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6709 return FAIL;
6710 }
6711 inst.operands[0].imm = reg;
6712
6713 if (skip_past_comma (&p) == SUCCESS)
6714 {
6715 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6716 return FAIL;
e2b0ab59 6717 if (inst.relocs[0].exp.X_add_number != 1)
92e90b6e
PB
6718 {
6719 inst.error = _("invalid shift");
6720 return FAIL;
6721 }
6722 inst.operands[0].shifted = 1;
6723 }
6724
6725 if (skip_past_char (&p, ']') == FAIL)
6726 {
6727 inst.error = _("']' expected");
6728 return FAIL;
6729 }
6730 *str = p;
6731 return SUCCESS;
6732}
6733
5287ad62
JB
6734/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6735 information on the types the operands can take and how they are encoded.
037e8744
JB
6736 Up to four operands may be read; this function handles setting the
6737 ".present" field for each read operand itself.
5287ad62
JB
6738 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6739 else returns FAIL. */
6740
6741static int
6742parse_neon_mov (char **str, int *which_operand)
6743{
6744 int i = *which_operand, val;
6745 enum arm_reg_type rtype;
6746 char *ptr = *str;
dcbf9037 6747 struct neon_type_el optype;
5f4273c7 6748
57785aa2
AV
6749 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6750 {
6751 /* Cases 17 or 19. */
6752 inst.operands[i].reg = val;
6753 inst.operands[i].isvec = 1;
6754 inst.operands[i].isscalar = 2;
6755 inst.operands[i].vectype = optype;
6756 inst.operands[i++].present = 1;
6757
6758 if (skip_past_comma (&ptr) == FAIL)
6759 goto wanted_comma;
6760
6761 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6762 {
6763 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6764 inst.operands[i].reg = val;
6765 inst.operands[i].isreg = 1;
6766 inst.operands[i].present = 1;
6767 }
6768 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6769 {
6770 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6771 inst.operands[i].reg = val;
6772 inst.operands[i].isvec = 1;
6773 inst.operands[i].isscalar = 2;
6774 inst.operands[i].vectype = optype;
6775 inst.operands[i++].present = 1;
6776
6777 if (skip_past_comma (&ptr) == FAIL)
6778 goto wanted_comma;
6779
6780 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6781 goto wanted_arm;
6782
6783 inst.operands[i].reg = val;
6784 inst.operands[i].isreg = 1;
6785 inst.operands[i++].present = 1;
6786
6787 if (skip_past_comma (&ptr) == FAIL)
6788 goto wanted_comma;
6789
6790 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6791 goto wanted_arm;
6792
6793 inst.operands[i].reg = val;
6794 inst.operands[i].isreg = 1;
6795 inst.operands[i].present = 1;
6796 }
6797 else
6798 {
6799 first_error (_("expected ARM or MVE vector register"));
6800 return FAIL;
6801 }
6802 }
6803 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
5287ad62
JB
6804 {
6805 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6806 inst.operands[i].reg = val;
6807 inst.operands[i].isscalar = 1;
dcbf9037 6808 inst.operands[i].vectype = optype;
5287ad62
JB
6809 inst.operands[i++].present = 1;
6810
6811 if (skip_past_comma (&ptr) == FAIL)
477330fc 6812 goto wanted_comma;
5f4273c7 6813
dcbf9037 6814 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6815 goto wanted_arm;
5f4273c7 6816
5287ad62
JB
6817 inst.operands[i].reg = val;
6818 inst.operands[i].isreg = 1;
6819 inst.operands[i].present = 1;
6820 }
57785aa2
AV
6821 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6822 != FAIL)
6823 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6824 != FAIL))
5287ad62
JB
6825 {
6826 /* Cases 0, 1, 2, 3, 5 (D only). */
6827 if (skip_past_comma (&ptr) == FAIL)
477330fc 6828 goto wanted_comma;
5f4273c7 6829
5287ad62
JB
6830 inst.operands[i].reg = val;
6831 inst.operands[i].isreg = 1;
6832 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6833 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6834 inst.operands[i].isvec = 1;
dcbf9037 6835 inst.operands[i].vectype = optype;
5287ad62
JB
6836 inst.operands[i++].present = 1;
6837
dcbf9037 6838 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6839 {
6840 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6841 Case 13: VMOV <Sd>, <Rm> */
6842 inst.operands[i].reg = val;
6843 inst.operands[i].isreg = 1;
6844 inst.operands[i].present = 1;
6845
6846 if (rtype == REG_TYPE_NQ)
6847 {
6848 first_error (_("can't use Neon quad register here"));
6849 return FAIL;
6850 }
6851 else if (rtype != REG_TYPE_VFS)
6852 {
6853 i++;
6854 if (skip_past_comma (&ptr) == FAIL)
6855 goto wanted_comma;
6856 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6857 goto wanted_arm;
6858 inst.operands[i].reg = val;
6859 inst.operands[i].isreg = 1;
6860 inst.operands[i].present = 1;
6861 }
6862 }
c4a23bf8
SP
6863 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6864 &optype)) != FAIL)
6865 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6866 &optype)) != FAIL))
477330fc
RM
6867 {
6868 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6869 Case 1: VMOV<c><q> <Dd>, <Dm>
6870 Case 8: VMOV.F32 <Sd>, <Sm>
6871 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6872
6873 inst.operands[i].reg = val;
6874 inst.operands[i].isreg = 1;
6875 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6876 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6877 inst.operands[i].isvec = 1;
6878 inst.operands[i].vectype = optype;
6879 inst.operands[i].present = 1;
6880
6881 if (skip_past_comma (&ptr) == SUCCESS)
6882 {
6883 /* Case 15. */
6884 i++;
6885
6886 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6887 goto wanted_arm;
6888
6889 inst.operands[i].reg = val;
6890 inst.operands[i].isreg = 1;
6891 inst.operands[i++].present = 1;
6892
6893 if (skip_past_comma (&ptr) == FAIL)
6894 goto wanted_comma;
6895
6896 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6897 goto wanted_arm;
6898
6899 inst.operands[i].reg = val;
6900 inst.operands[i].isreg = 1;
6901 inst.operands[i].present = 1;
6902 }
6903 }
4641781c 6904 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6905 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6906 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6907 Case 10: VMOV.F32 <Sd>, #<imm>
6908 Case 11: VMOV.F64 <Dd>, #<imm> */
6909 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6910 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6911 == SUCCESS)
477330fc
RM
6912 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6913 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6914 ;
5287ad62 6915 else
477330fc
RM
6916 {
6917 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6918 return FAIL;
6919 }
5287ad62 6920 }
dcbf9037 6921 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 6922 {
57785aa2 6923 /* Cases 6, 7, 16, 18. */
5287ad62
JB
6924 inst.operands[i].reg = val;
6925 inst.operands[i].isreg = 1;
6926 inst.operands[i++].present = 1;
5f4273c7 6927
5287ad62 6928 if (skip_past_comma (&ptr) == FAIL)
477330fc 6929 goto wanted_comma;
5f4273c7 6930
57785aa2
AV
6931 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6932 {
6933 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6934 inst.operands[i].reg = val;
6935 inst.operands[i].isscalar = 2;
6936 inst.operands[i].present = 1;
6937 inst.operands[i].vectype = optype;
6938 }
6939 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
477330fc
RM
6940 {
6941 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6942 inst.operands[i].reg = val;
6943 inst.operands[i].isscalar = 1;
6944 inst.operands[i].present = 1;
6945 inst.operands[i].vectype = optype;
6946 }
dcbf9037 6947 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc 6948 {
477330fc
RM
6949 inst.operands[i].reg = val;
6950 inst.operands[i].isreg = 1;
6951 inst.operands[i++].present = 1;
6952
6953 if (skip_past_comma (&ptr) == FAIL)
6954 goto wanted_comma;
6955
6956 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
57785aa2 6957 != FAIL)
477330fc 6958 {
57785aa2 6959 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
477330fc 6960
477330fc
RM
6961 inst.operands[i].reg = val;
6962 inst.operands[i].isreg = 1;
6963 inst.operands[i].isvec = 1;
57785aa2 6964 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
477330fc
RM
6965 inst.operands[i].vectype = optype;
6966 inst.operands[i].present = 1;
57785aa2
AV
6967
6968 if (rtype == REG_TYPE_VFS)
6969 {
6970 /* Case 14. */
6971 i++;
6972 if (skip_past_comma (&ptr) == FAIL)
6973 goto wanted_comma;
6974 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6975 &optype)) == FAIL)
6976 {
6977 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6978 return FAIL;
6979 }
6980 inst.operands[i].reg = val;
6981 inst.operands[i].isreg = 1;
6982 inst.operands[i].isvec = 1;
6983 inst.operands[i].issingle = 1;
6984 inst.operands[i].vectype = optype;
6985 inst.operands[i].present = 1;
6986 }
6987 }
6988 else
6989 {
6990 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6991 != FAIL)
6992 {
6993 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6994 inst.operands[i].reg = val;
6995 inst.operands[i].isvec = 1;
6996 inst.operands[i].isscalar = 2;
6997 inst.operands[i].vectype = optype;
6998 inst.operands[i++].present = 1;
6999
7000 if (skip_past_comma (&ptr) == FAIL)
7001 goto wanted_comma;
7002
7003 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
7004 == FAIL)
7005 {
7006 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
7007 return FAIL;
7008 }
7009 inst.operands[i].reg = val;
7010 inst.operands[i].isvec = 1;
7011 inst.operands[i].isscalar = 2;
7012 inst.operands[i].vectype = optype;
7013 inst.operands[i].present = 1;
7014 }
7015 else
7016 {
7017 first_error (_("VFP single, double or MVE vector register"
7018 " expected"));
7019 return FAIL;
7020 }
477330fc
RM
7021 }
7022 }
037e8744 7023 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
7024 != FAIL)
7025 {
7026 /* Case 13. */
7027 inst.operands[i].reg = val;
7028 inst.operands[i].isreg = 1;
7029 inst.operands[i].isvec = 1;
7030 inst.operands[i].issingle = 1;
7031 inst.operands[i].vectype = optype;
7032 inst.operands[i].present = 1;
7033 }
5287ad62
JB
7034 }
7035 else
7036 {
dcbf9037 7037 first_error (_("parse error"));
5287ad62
JB
7038 return FAIL;
7039 }
7040
7041 /* Successfully parsed the operands. Update args. */
7042 *which_operand = i;
7043 *str = ptr;
7044 return SUCCESS;
7045
5f4273c7 7046 wanted_comma:
dcbf9037 7047 first_error (_("expected comma"));
5287ad62 7048 return FAIL;
5f4273c7
NC
7049
7050 wanted_arm:
dcbf9037 7051 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 7052 return FAIL;
5287ad62
JB
7053}
7054
5be8be5d
DG
7055/* Use this macro when the operand constraints are different
7056 for ARM and THUMB (e.g. ldrd). */
7057#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7058 ((arm_operand) | ((thumb_operand) << 16))
7059
c19d1205
ZW
7060/* Matcher codes for parse_operands. */
7061enum operand_parse_code
7062{
7063 OP_stop, /* end of line */
7064
7065 OP_RR, /* ARM register */
7066 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 7067 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 7068 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 7069 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 7070 optional trailing ! */
c19d1205
ZW
7071 OP_RRw, /* ARM register, not r15, optional trailing ! */
7072 OP_RCP, /* Coprocessor number */
7073 OP_RCN, /* Coprocessor register */
7074 OP_RF, /* FPA register */
7075 OP_RVS, /* VFP single precision register */
5287ad62
JB
7076 OP_RVD, /* VFP double precision register (0..15) */
7077 OP_RND, /* Neon double precision register (0..31) */
5ee91343
AV
7078 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7079 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7080 */
66d1f7cc
AV
7081 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7082 */
5287ad62 7083 OP_RNQ, /* Neon quad precision register */
5ee91343 7084 OP_RNQMQ, /* Neon quad or MVE vector register. */
037e8744 7085 OP_RVSD, /* VFP single or double precision register */
1b883319 7086 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
dd9634d9 7087 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
dec41383 7088 OP_RNSD, /* Neon single or double precision register */
5287ad62 7089 OP_RNDQ, /* Neon double or quad precision register */
5ee91343 7090 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7df54120 7091 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
037e8744 7092 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 7093 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
7094 OP_RVC, /* VFP control register */
7095 OP_RMF, /* Maverick F register */
7096 OP_RMD, /* Maverick D register */
7097 OP_RMFX, /* Maverick FX register */
7098 OP_RMDX, /* Maverick DX register */
7099 OP_RMAX, /* Maverick AX register */
7100 OP_RMDS, /* Maverick DSPSC register */
7101 OP_RIWR, /* iWMMXt wR register */
7102 OP_RIWC, /* iWMMXt wC register */
7103 OP_RIWG, /* iWMMXt wCG register */
7104 OP_RXA, /* XScale accumulator register */
7105
5aae9ae9 7106 OP_RNSDMQ, /* Neon single, double or MVE vector register */
5ee91343
AV
7107 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7108 */
7109 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7110 GPR (no SP/SP) */
a302e574 7111 OP_RMQ, /* MVE vector register. */
1b883319 7112 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
35d1cfc2 7113 OP_RMQRR, /* MVE vector or ARM register. */
a302e574 7114
60f993ce
AV
7115 /* New operands for Armv8.1-M Mainline. */
7116 OP_LR, /* ARM LR register */
a302e574
AV
7117 OP_RRe, /* ARM register, only even numbered. */
7118 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
60f993ce 7119 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
e39c1607 7120 OP_RR_ZR, /* ARM register or ZR but no PC */
60f993ce 7121
c19d1205 7122 OP_REGLST, /* ARM register list */
4b5a202f 7123 OP_CLRMLST, /* CLRM register list */
c19d1205
ZW
7124 OP_VRSLST, /* VFP single-precision register list */
7125 OP_VRDLST, /* VFP double-precision register list */
037e8744 7126 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
7127 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7128 OP_NSTRLST, /* Neon element/structure list */
efd6b359 7129 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
35c228db
AV
7130 OP_MSTRLST2, /* MVE vector list with two elements. */
7131 OP_MSTRLST4, /* MVE vector list with four elements. */
5287ad62 7132
5287ad62 7133 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 7134 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 7135 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
1b883319
AV
7136 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7137 zero. */
5287ad62 7138 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 7139 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 7140 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
886e1c73
AV
7141 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7142 */
a8465a06
AV
7143 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7144 scalar, or ARM register. */
5287ad62 7145 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
42b16635
AV
7146 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7147 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7148 register. */
5d281bf0 7149 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
5287ad62
JB
7150 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7151 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 7152 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
f601a00c
AV
7153 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7154 OP_RNDQMQ_Ibig,
5287ad62 7155 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5150f0d8
AV
7156 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7157 ARM register. */
2d447fca 7158 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
32c36c3c 7159 OP_VLDR, /* VLDR operand. */
5287ad62
JB
7160
7161 OP_I0, /* immediate zero */
c19d1205
ZW
7162 OP_I7, /* immediate value 0 .. 7 */
7163 OP_I15, /* 0 .. 15 */
7164 OP_I16, /* 1 .. 16 */
5287ad62 7165 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
7166 OP_I31, /* 0 .. 31 */
7167 OP_I31w, /* 0 .. 31, optional trailing ! */
7168 OP_I32, /* 1 .. 32 */
5287ad62 7169 OP_I32z, /* 0 .. 32 */
08132bdd 7170 OP_I48_I64, /* 48 or 64 */
5287ad62 7171 OP_I63, /* 0 .. 63 */
c19d1205 7172 OP_I63s, /* -64 .. 63 */
5287ad62
JB
7173 OP_I64, /* 1 .. 64 */
7174 OP_I64z, /* 0 .. 64 */
5aae9ae9 7175 OP_I127, /* 0 .. 127 */
c19d1205 7176 OP_I255, /* 0 .. 255 */
4934a27c 7177 OP_I511, /* 0 .. 511 */
5aae9ae9 7178 OP_I4095, /* 0 .. 4095 */
4934a27c 7179 OP_I8191, /* 0 .. 8191 */
c19d1205
ZW
7180 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7181 OP_I7b, /* 0 .. 7 */
7182 OP_I15b, /* 0 .. 15 */
7183 OP_I31b, /* 0 .. 31 */
7184
7185 OP_SH, /* shifter operand */
4962c51a 7186 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 7187 OP_ADDR, /* Memory address expression (any mode) */
35c228db 7188 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
4962c51a
MS
7189 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7190 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7191 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
7192 OP_EXP, /* arbitrary expression */
7193 OP_EXPi, /* same, with optional immediate prefix */
7194 OP_EXPr, /* same, with optional relocation suffix */
e2b0ab59 7195 OP_EXPs, /* same, with optional non-first operand relocation suffix */
b6895b4f 7196 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
7197 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7198 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
7199
7200 OP_CPSF, /* CPS flags */
7201 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
7202 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7203 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 7204 OP_COND, /* conditional code */
92e90b6e 7205 OP_TB, /* Table branch. */
c19d1205 7206
037e8744
JB
7207 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7208
c19d1205 7209 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 7210 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
7211 OP_RR_EXi, /* ARM register or expression with imm prefix */
7212 OP_RF_IF, /* FPA register or immediate */
7213 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 7214 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
7215
7216 /* Optional operands. */
7217 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7218 OP_oI31b, /* 0 .. 31 */
5287ad62 7219 OP_oI32b, /* 1 .. 32 */
5f1af56b 7220 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
7221 OP_oIffffb, /* 0 .. 65535 */
7222 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7223
7224 OP_oRR, /* ARM register */
60f993ce 7225 OP_oLR, /* ARM LR register */
c19d1205 7226 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 7227 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 7228 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
7229 OP_oRND, /* Optional Neon double precision register */
7230 OP_oRNQ, /* Optional Neon quad precision register */
5ee91343 7231 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
5287ad62 7232 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 7233 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5ee91343
AV
7234 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7235 register. */
66d1f7cc
AV
7236 OP_oRNSDMQ, /* Optional single, double register or MVE vector
7237 register. */
c19d1205
ZW
7238 OP_oSHll, /* LSL immediate */
7239 OP_oSHar, /* ASR immediate */
7240 OP_oSHllar, /* LSL or ASR immediate */
7241 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 7242 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 7243
1b883319
AV
7244 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7245
5be8be5d
DG
7246 /* Some pre-defined mixed (ARM/THUMB) operands. */
7247 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7248 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7249 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7250
c19d1205
ZW
7251 OP_FIRST_OPTIONAL = OP_oI7b
7252};
a737bd4d 7253
c19d1205
ZW
7254/* Generic instruction operand parser. This does no encoding and no
7255 semantic validation; it merely squirrels values away in the inst
7256 structure. Returns SUCCESS or FAIL depending on whether the
7257 specified grammar matched. */
7258static int
5be8be5d 7259parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 7260{
5be8be5d 7261 unsigned const int *upat = pattern;
c19d1205
ZW
7262 char *backtrack_pos = 0;
7263 const char *backtrack_error = 0;
99aad254 7264 int i, val = 0, backtrack_index = 0;
5287ad62 7265 enum arm_reg_type rtype;
4962c51a 7266 parse_operand_result result;
5be8be5d 7267 unsigned int op_parse_code;
efd6b359 7268 bfd_boolean partial_match;
c19d1205 7269
e07e6e58
NC
7270#define po_char_or_fail(chr) \
7271 do \
7272 { \
7273 if (skip_past_char (&str, chr) == FAIL) \
477330fc 7274 goto bad_args; \
e07e6e58
NC
7275 } \
7276 while (0)
c19d1205 7277
e07e6e58
NC
7278#define po_reg_or_fail(regtype) \
7279 do \
dcbf9037 7280 { \
e07e6e58 7281 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 7282 & inst.operands[i].vectype); \
e07e6e58 7283 if (val == FAIL) \
477330fc
RM
7284 { \
7285 first_error (_(reg_expected_msgs[regtype])); \
7286 goto failure; \
7287 } \
e07e6e58
NC
7288 inst.operands[i].reg = val; \
7289 inst.operands[i].isreg = 1; \
7290 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7291 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7292 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
7293 || rtype == REG_TYPE_VFD \
7294 || rtype == REG_TYPE_NQ); \
1b883319 7295 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
dcbf9037 7296 } \
e07e6e58
NC
7297 while (0)
7298
7299#define po_reg_or_goto(regtype, label) \
7300 do \
7301 { \
7302 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7303 & inst.operands[i].vectype); \
7304 if (val == FAIL) \
7305 goto label; \
dcbf9037 7306 \
e07e6e58
NC
7307 inst.operands[i].reg = val; \
7308 inst.operands[i].isreg = 1; \
7309 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7310 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7311 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 7312 || rtype == REG_TYPE_VFD \
e07e6e58 7313 || rtype == REG_TYPE_NQ); \
1b883319 7314 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
e07e6e58
NC
7315 } \
7316 while (0)
7317
7318#define po_imm_or_fail(min, max, popt) \
7319 do \
7320 { \
7321 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7322 goto failure; \
7323 inst.operands[i].imm = val; \
7324 } \
7325 while (0)
7326
08132bdd
SP
7327#define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7328 do \
7329 { \
7330 expressionS exp; \
7331 my_get_expression (&exp, &str, popt); \
7332 if (exp.X_op != O_constant) \
7333 { \
7334 inst.error = _("constant expression required"); \
7335 goto failure; \
7336 } \
7337 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7338 { \
7339 inst.error = _("immediate value 48 or 64 expected"); \
7340 goto failure; \
7341 } \
7342 inst.operands[i].imm = exp.X_add_number; \
7343 } \
7344 while (0)
7345
57785aa2 7346#define po_scalar_or_goto(elsz, label, reg_type) \
e07e6e58
NC
7347 do \
7348 { \
57785aa2
AV
7349 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7350 reg_type); \
e07e6e58
NC
7351 if (val == FAIL) \
7352 goto label; \
7353 inst.operands[i].reg = val; \
7354 inst.operands[i].isscalar = 1; \
7355 } \
7356 while (0)
7357
7358#define po_misc_or_fail(expr) \
7359 do \
7360 { \
7361 if (expr) \
7362 goto failure; \
7363 } \
7364 while (0)
7365
7366#define po_misc_or_fail_no_backtrack(expr) \
7367 do \
7368 { \
7369 result = expr; \
7370 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7371 backtrack_pos = 0; \
7372 if (result != PARSE_OPERAND_SUCCESS) \
7373 goto failure; \
7374 } \
7375 while (0)
4962c51a 7376
52e7f43d
RE
7377#define po_barrier_or_imm(str) \
7378 do \
7379 { \
7380 val = parse_barrier (&str); \
ccb84d65
JB
7381 if (val == FAIL && ! ISALPHA (*str)) \
7382 goto immediate; \
7383 if (val == FAIL \
7384 /* ISB can only take SY as an option. */ \
7385 || ((inst.instruction & 0xf0) == 0x60 \
7386 && val != 0xf)) \
52e7f43d 7387 { \
ccb84d65
JB
7388 inst.error = _("invalid barrier type"); \
7389 backtrack_pos = 0; \
7390 goto failure; \
52e7f43d
RE
7391 } \
7392 } \
7393 while (0)
7394
c19d1205
ZW
7395 skip_whitespace (str);
7396
7397 for (i = 0; upat[i] != OP_stop; i++)
7398 {
5be8be5d
DG
7399 op_parse_code = upat[i];
7400 if (op_parse_code >= 1<<16)
7401 op_parse_code = thumb ? (op_parse_code >> 16)
7402 : (op_parse_code & ((1<<16)-1));
7403
7404 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
7405 {
7406 /* Remember where we are in case we need to backtrack. */
c19d1205
ZW
7407 backtrack_pos = str;
7408 backtrack_error = inst.error;
7409 backtrack_index = i;
7410 }
7411
b6702015 7412 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
7413 po_char_or_fail (',');
7414
5be8be5d 7415 switch (op_parse_code)
c19d1205
ZW
7416 {
7417 /* Registers */
7418 case OP_oRRnpc:
5be8be5d 7419 case OP_oRRnpcsp:
c19d1205 7420 case OP_RRnpc:
5be8be5d 7421 case OP_RRnpcsp:
c19d1205 7422 case OP_oRR:
a302e574
AV
7423 case OP_RRe:
7424 case OP_RRo:
60f993ce
AV
7425 case OP_LR:
7426 case OP_oLR:
c19d1205
ZW
7427 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7428 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7429 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7430 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7431 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7432 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 7433 case OP_oRND:
66d1f7cc
AV
7434 case OP_RNSDMQR:
7435 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7436 break;
7437 try_rndmqr:
5ee91343
AV
7438 case OP_RNDMQR:
7439 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7440 break;
7441 try_rndmq:
7442 case OP_RNDMQ:
7443 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7444 break;
7445 try_rnd:
5287ad62 7446 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
7447 case OP_RVC:
7448 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7449 break;
7450 /* Also accept generic coprocessor regs for unknown registers. */
7451 coproc_reg:
ba6cd17f
SD
7452 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7453 break;
7454 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7455 existing register with a value of 0, this seems like the
7456 best way to parse P0. */
7457 vpr_po:
7458 if (strncasecmp (str, "P0", 2) == 0)
7459 {
7460 str += 2;
7461 inst.operands[i].isreg = 1;
7462 inst.operands[i].reg = 13;
7463 }
7464 else
7465 goto failure;
cd2cf30b 7466 break;
c19d1205
ZW
7467 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7468 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7469 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7470 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7471 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7472 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7473 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7474 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7475 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7476 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 7477 case OP_oRNQ:
5ee91343
AV
7478 case OP_RNQMQ:
7479 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7480 break;
7481 try_nq:
5287ad62 7482 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 7483 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7df54120
AV
7484 case OP_RNDQMQR:
7485 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7486 break;
7487 try_rndqmq:
5ee91343
AV
7488 case OP_oRNDQMQ:
7489 case OP_RNDQMQ:
7490 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7491 break;
7492 try_rndq:
477330fc 7493 case OP_oRNDQ:
5287ad62 7494 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
dd9634d9
AV
7495 case OP_RVSDMQ:
7496 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7497 break;
7498 try_rvsd:
477330fc 7499 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
1b883319
AV
7500 case OP_RVSD_COND:
7501 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7502 break;
66d1f7cc 7503 case OP_oRNSDMQ:
5aae9ae9
MM
7504 case OP_RNSDMQ:
7505 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7506 break;
7507 try_mq2:
7508 po_reg_or_fail (REG_TYPE_MQ);
7509 break;
477330fc
RM
7510 case OP_oRNSDQ:
7511 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5ee91343
AV
7512 case OP_RNSDQMQR:
7513 po_reg_or_goto (REG_TYPE_RN, try_mq);
7514 break;
7515 try_mq:
7516 case OP_oRNSDQMQ:
7517 case OP_RNSDQMQ:
7518 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7519 break;
7520 try_nsdq2:
7521 po_reg_or_fail (REG_TYPE_NSDQ);
7522 inst.error = 0;
7523 break;
35d1cfc2
AV
7524 case OP_RMQRR:
7525 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7526 break;
7527 try_rmq:
a302e574
AV
7528 case OP_RMQ:
7529 po_reg_or_fail (REG_TYPE_MQ);
7530 break;
477330fc
RM
7531 /* Neon scalar. Using an element size of 8 means that some invalid
7532 scalars are accepted here, so deal with those in later code. */
57785aa2 7533 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
477330fc
RM
7534
7535 case OP_RNDQ_I0:
7536 {
7537 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7538 break;
7539 try_imm0:
7540 po_imm_or_fail (0, 0, TRUE);
7541 }
7542 break;
7543
7544 case OP_RVSD_I0:
7545 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7546 break;
7547
1b883319
AV
7548 case OP_RSVDMQ_FI0:
7549 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7550 break;
7551 try_rsvd_fi0:
aacf0b33
KT
7552 case OP_RSVD_FI0:
7553 {
7554 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7555 break;
7556 try_ifimm0:
7557 if (parse_ifimm_zero (&str))
7558 inst.operands[i].imm = 0;
7559 else
7560 {
7561 inst.error
7562 = _("only floating point zero is allowed as immediate value");
7563 goto failure;
7564 }
7565 }
7566 break;
7567
477330fc
RM
7568 case OP_RR_RNSC:
7569 {
57785aa2 7570 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
477330fc
RM
7571 break;
7572 try_rr:
7573 po_reg_or_fail (REG_TYPE_RN);
7574 }
7575 break;
7576
a8465a06
AV
7577 case OP_RNSDQ_RNSC_MQ_RR:
7578 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7579 break;
7580 try_rnsdq_rnsc_mq:
886e1c73
AV
7581 case OP_RNSDQ_RNSC_MQ:
7582 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7583 break;
7584 try_rnsdq_rnsc:
477330fc
RM
7585 case OP_RNSDQ_RNSC:
7586 {
57785aa2
AV
7587 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7588 inst.error = 0;
477330fc
RM
7589 break;
7590 try_nsdq:
7591 po_reg_or_fail (REG_TYPE_NSDQ);
57785aa2 7592 inst.error = 0;
477330fc
RM
7593 }
7594 break;
7595
dec41383
JW
7596 case OP_RNSD_RNSC:
7597 {
57785aa2 7598 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
dec41383
JW
7599 break;
7600 try_s_scalar:
57785aa2 7601 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
dec41383
JW
7602 break;
7603 try_nsd:
7604 po_reg_or_fail (REG_TYPE_NSD);
7605 }
7606 break;
7607
42b16635
AV
7608 case OP_RNDQMQ_RNSC_RR:
7609 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7610 break;
7611 try_rndq_rnsc_rr:
7612 case OP_RNDQ_RNSC_RR:
7613 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7614 break;
5d281bf0
AV
7615 case OP_RNDQMQ_RNSC:
7616 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7617 break;
7618 try_rndq_rnsc:
477330fc
RM
7619 case OP_RNDQ_RNSC:
7620 {
57785aa2 7621 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
477330fc
RM
7622 break;
7623 try_ndq:
7624 po_reg_or_fail (REG_TYPE_NDQ);
7625 }
7626 break;
7627
7628 case OP_RND_RNSC:
7629 {
57785aa2 7630 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
477330fc
RM
7631 break;
7632 try_vfd:
7633 po_reg_or_fail (REG_TYPE_VFD);
7634 }
7635 break;
7636
7637 case OP_VMOV:
7638 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7639 not careful then bad things might happen. */
7640 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7641 break;
7642
f601a00c
AV
7643 case OP_RNDQMQ_Ibig:
7644 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7645 break;
7646 try_rndq_ibig:
477330fc
RM
7647 case OP_RNDQ_Ibig:
7648 {
7649 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7650 break;
7651 try_immbig:
7652 /* There's a possibility of getting a 64-bit immediate here, so
7653 we need special handling. */
8335d6aa
JW
7654 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7655 == FAIL)
477330fc
RM
7656 {
7657 inst.error = _("immediate value is out of range");
7658 goto failure;
7659 }
7660 }
7661 break;
7662
5150f0d8
AV
7663 case OP_RNDQMQ_I63b_RR:
7664 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7665 break;
7666 try_rndq_i63b_rr:
7667 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7668 break;
7669 try_rndq_i63b:
477330fc
RM
7670 case OP_RNDQ_I63b:
7671 {
7672 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7673 break;
7674 try_shimm:
7675 po_imm_or_fail (0, 63, TRUE);
7676 }
7677 break;
c19d1205
ZW
7678
7679 case OP_RRnpcb:
7680 po_char_or_fail ('[');
7681 po_reg_or_fail (REG_TYPE_RN);
7682 po_char_or_fail (']');
7683 break;
a737bd4d 7684
55881a11 7685 case OP_RRnpctw:
c19d1205 7686 case OP_RRw:
b6702015 7687 case OP_oRRw:
c19d1205
ZW
7688 po_reg_or_fail (REG_TYPE_RN);
7689 if (skip_past_char (&str, '!') == SUCCESS)
7690 inst.operands[i].writeback = 1;
7691 break;
7692
7693 /* Immediates */
7694 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7695 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7696 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 7697 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
7698 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7699 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 7700 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
08132bdd 7701 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
c19d1205 7702 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
7703 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7704 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7705 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5aae9ae9 7706 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
c19d1205 7707 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
4934a27c 7708 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
5aae9ae9 7709 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
4934a27c 7710 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
c19d1205
ZW
7711 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7712 case OP_oI7b:
7713 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7714 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7715 case OP_oI31b:
7716 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
7717 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7718 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
7719 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7720
7721 /* Immediate variants */
7722 case OP_oI255c:
7723 po_char_or_fail ('{');
7724 po_imm_or_fail (0, 255, TRUE);
7725 po_char_or_fail ('}');
7726 break;
7727
7728 case OP_I31w:
7729 /* The expression parser chokes on a trailing !, so we have
7730 to find it first and zap it. */
7731 {
7732 char *s = str;
7733 while (*s && *s != ',')
7734 s++;
7735 if (s[-1] == '!')
7736 {
7737 s[-1] = '\0';
7738 inst.operands[i].writeback = 1;
7739 }
7740 po_imm_or_fail (0, 31, TRUE);
7741 if (str == s - 1)
7742 str = s;
7743 }
7744 break;
7745
7746 /* Expressions */
7747 case OP_EXPi: EXPi:
e2b0ab59 7748 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7749 GE_OPT_PREFIX));
7750 break;
7751
7752 case OP_EXP:
e2b0ab59 7753 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205
ZW
7754 GE_NO_PREFIX));
7755 break;
7756
7757 case OP_EXPr: EXPr:
e2b0ab59 7758 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
c19d1205 7759 GE_NO_PREFIX));
e2b0ab59 7760 if (inst.relocs[0].exp.X_op == O_symbol)
a737bd4d 7761 {
c19d1205
ZW
7762 val = parse_reloc (&str);
7763 if (val == -1)
7764 {
7765 inst.error = _("unrecognized relocation suffix");
7766 goto failure;
7767 }
7768 else if (val != BFD_RELOC_UNUSED)
7769 {
7770 inst.operands[i].imm = val;
7771 inst.operands[i].hasreloc = 1;
7772 }
a737bd4d 7773 }
c19d1205 7774 break;
a737bd4d 7775
e2b0ab59
AV
7776 case OP_EXPs:
7777 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7778 GE_NO_PREFIX));
7779 if (inst.relocs[i].exp.X_op == O_symbol)
7780 {
7781 inst.operands[i].hasreloc = 1;
7782 }
7783 else if (inst.relocs[i].exp.X_op == O_constant)
7784 {
7785 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7786 inst.operands[i].hasreloc = 0;
7787 }
7788 break;
7789
b6895b4f
PB
7790 /* Operand for MOVW or MOVT. */
7791 case OP_HALF:
7792 po_misc_or_fail (parse_half (&str));
7793 break;
7794
e07e6e58 7795 /* Register or expression. */
c19d1205
ZW
7796 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7797 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7798
e07e6e58 7799 /* Register or immediate. */
c19d1205
ZW
7800 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7801 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7802
23d00a41
SD
7803 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7804 I32: po_imm_or_fail (1, 32, FALSE); break;
7805
c19d1205
ZW
7806 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7807 IF:
7808 if (!is_immediate_prefix (*str))
7809 goto bad_args;
7810 str++;
7811 val = parse_fpa_immediate (&str);
7812 if (val == FAIL)
7813 goto failure;
7814 /* FPA immediates are encoded as registers 8-15.
7815 parse_fpa_immediate has already applied the offset. */
7816 inst.operands[i].reg = val;
7817 inst.operands[i].isreg = 1;
7818 break;
09d92015 7819
2d447fca
JM
7820 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7821 I32z: po_imm_or_fail (0, 32, FALSE); break;
7822
e07e6e58 7823 /* Two kinds of register. */
c19d1205
ZW
7824 case OP_RIWR_RIWC:
7825 {
7826 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7827 if (!rege
7828 || (rege->type != REG_TYPE_MMXWR
7829 && rege->type != REG_TYPE_MMXWC
7830 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7831 {
7832 inst.error = _("iWMMXt data or control register expected");
7833 goto failure;
7834 }
7835 inst.operands[i].reg = rege->number;
7836 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7837 }
7838 break;
09d92015 7839
41adaa5c
JM
7840 case OP_RIWC_RIWG:
7841 {
7842 struct reg_entry *rege = arm_reg_parse_multi (&str);
7843 if (!rege
7844 || (rege->type != REG_TYPE_MMXWC
7845 && rege->type != REG_TYPE_MMXWCG))
7846 {
7847 inst.error = _("iWMMXt control register expected");
7848 goto failure;
7849 }
7850 inst.operands[i].reg = rege->number;
7851 inst.operands[i].isreg = 1;
7852 }
7853 break;
7854
c19d1205
ZW
7855 /* Misc */
7856 case OP_CPSF: val = parse_cps_flags (&str); break;
7857 case OP_ENDI: val = parse_endian_specifier (&str); break;
7858 case OP_oROR: val = parse_ror (&str); break;
1b883319 7859 try_cond:
c19d1205 7860 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7861 case OP_oBARRIER_I15:
7862 po_barrier_or_imm (str); break;
7863 immediate:
7864 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7865 goto failure;
52e7f43d 7866 break;
c19d1205 7867
fa94de6b 7868 case OP_wPSR:
d2cd1205 7869 case OP_rPSR:
90ec0d68
MGD
7870 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7871 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7872 {
7873 inst.error = _("Banked registers are not available with this "
7874 "architecture.");
7875 goto failure;
7876 }
7877 break;
d2cd1205
JB
7878 try_psr:
7879 val = parse_psr (&str, op_parse_code == OP_wPSR);
7880 break;
037e8744 7881
32c36c3c
AV
7882 case OP_VLDR:
7883 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7884 break;
7885 try_sysreg:
7886 val = parse_sys_vldr_vstr (&str);
7887 break;
7888
477330fc
RM
7889 case OP_APSR_RR:
7890 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7891 break;
7892 try_apsr:
7893 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7894 instruction). */
7895 if (strncasecmp (str, "APSR_", 5) == 0)
7896 {
7897 unsigned found = 0;
7898 str += 5;
7899 while (found < 15)
7900 switch (*str++)
7901 {
7902 case 'c': found = (found & 1) ? 16 : found | 1; break;
7903 case 'n': found = (found & 2) ? 16 : found | 2; break;
7904 case 'z': found = (found & 4) ? 16 : found | 4; break;
7905 case 'v': found = (found & 8) ? 16 : found | 8; break;
7906 default: found = 16;
7907 }
7908 if (found != 15)
7909 goto failure;
7910 inst.operands[i].isvec = 1;
f7c21dc7
NC
7911 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7912 inst.operands[i].reg = REG_PC;
477330fc
RM
7913 }
7914 else
7915 goto failure;
7916 break;
037e8744 7917
92e90b6e
PB
7918 case OP_TB:
7919 po_misc_or_fail (parse_tb (&str));
7920 break;
7921
e07e6e58 7922 /* Register lists. */
c19d1205 7923 case OP_REGLST:
4b5a202f 7924 val = parse_reg_list (&str, REGLIST_RN);
c19d1205
ZW
7925 if (*str == '^')
7926 {
5e0d7f77 7927 inst.operands[i].writeback = 1;
c19d1205
ZW
7928 str++;
7929 }
7930 break;
09d92015 7931
4b5a202f
AV
7932 case OP_CLRMLST:
7933 val = parse_reg_list (&str, REGLIST_CLRM);
7934 break;
7935
c19d1205 7936 case OP_VRSLST:
efd6b359
AV
7937 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7938 &partial_match);
c19d1205 7939 break;
09d92015 7940
c19d1205 7941 case OP_VRDLST:
efd6b359
AV
7942 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7943 &partial_match);
c19d1205 7944 break;
a737bd4d 7945
477330fc
RM
7946 case OP_VRSDLST:
7947 /* Allow Q registers too. */
7948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7949 REGLIST_NEON_D, &partial_match);
477330fc
RM
7950 if (val == FAIL)
7951 {
7952 inst.error = NULL;
7953 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359
AV
7954 REGLIST_VFP_S, &partial_match);
7955 inst.operands[i].issingle = 1;
7956 }
7957 break;
7958
7959 case OP_VRSDVLST:
7960 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7961 REGLIST_VFP_D_VPR, &partial_match);
7962 if (val == FAIL && !partial_match)
7963 {
7964 inst.error = NULL;
7965 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7966 REGLIST_VFP_S_VPR, &partial_match);
477330fc
RM
7967 inst.operands[i].issingle = 1;
7968 }
7969 break;
7970
7971 case OP_NRDLST:
7972 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
efd6b359 7973 REGLIST_NEON_D, &partial_match);
477330fc 7974 break;
5287ad62 7975
35c228db
AV
7976 case OP_MSTRLST4:
7977 case OP_MSTRLST2:
7978 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7979 1, &inst.operands[i].vectype);
7980 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7981 goto failure;
7982 break;
5287ad62 7983 case OP_NSTRLST:
477330fc 7984 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
35c228db 7985 0, &inst.operands[i].vectype);
477330fc 7986 break;
5287ad62 7987
c19d1205 7988 /* Addressing modes */
35c228db
AV
7989 case OP_ADDRMVE:
7990 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7991 break;
7992
c19d1205
ZW
7993 case OP_ADDR:
7994 po_misc_or_fail (parse_address (&str, i));
7995 break;
09d92015 7996
4962c51a
MS
7997 case OP_ADDRGLDR:
7998 po_misc_or_fail_no_backtrack (
477330fc 7999 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
8000 break;
8001
8002 case OP_ADDRGLDRS:
8003 po_misc_or_fail_no_backtrack (
477330fc 8004 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
8005 break;
8006
8007 case OP_ADDRGLDC:
8008 po_misc_or_fail_no_backtrack (
477330fc 8009 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
8010 break;
8011
c19d1205
ZW
8012 case OP_SH:
8013 po_misc_or_fail (parse_shifter_operand (&str, i));
8014 break;
09d92015 8015
4962c51a
MS
8016 case OP_SHG:
8017 po_misc_or_fail_no_backtrack (
477330fc 8018 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
8019 break;
8020
c19d1205
ZW
8021 case OP_oSHll:
8022 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8023 break;
09d92015 8024
c19d1205
ZW
8025 case OP_oSHar:
8026 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8027 break;
09d92015 8028
c19d1205
ZW
8029 case OP_oSHllar:
8030 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8031 break;
09d92015 8032
1b883319
AV
8033 case OP_RMQRZ:
8034 case OP_oRMQRZ:
8035 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8036 break;
e39c1607
SD
8037
8038 case OP_RR_ZR:
1b883319
AV
8039 try_rr_zr:
8040 po_reg_or_goto (REG_TYPE_RN, ZR);
8041 break;
8042 ZR:
8043 po_reg_or_fail (REG_TYPE_ZR);
8044 break;
8045
c19d1205 8046 default:
5be8be5d 8047 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 8048 }
09d92015 8049
c19d1205
ZW
8050 /* Various value-based sanity checks and shared operations. We
8051 do not signal immediate failures for the register constraints;
8052 this allows a syntax error to take precedence. */
5be8be5d 8053 switch (op_parse_code)
c19d1205
ZW
8054 {
8055 case OP_oRRnpc:
8056 case OP_RRnpc:
8057 case OP_RRnpcb:
8058 case OP_RRw:
b6702015 8059 case OP_oRRw:
c19d1205
ZW
8060 case OP_RRnpc_I0:
8061 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8062 inst.error = BAD_PC;
8063 break;
09d92015 8064
5be8be5d
DG
8065 case OP_oRRnpcsp:
8066 case OP_RRnpcsp:
23d00a41 8067 case OP_RRnpcsp_I32:
5be8be5d
DG
8068 if (inst.operands[i].isreg)
8069 {
8070 if (inst.operands[i].reg == REG_PC)
8071 inst.error = BAD_PC;
5c8ed6a4
JW
8072 else if (inst.operands[i].reg == REG_SP
8073 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8074 relaxed since ARMv8-A. */
8075 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8076 {
8077 gas_assert (thumb);
8078 inst.error = BAD_SP;
8079 }
5be8be5d
DG
8080 }
8081 break;
8082
55881a11 8083 case OP_RRnpctw:
fa94de6b
RM
8084 if (inst.operands[i].isreg
8085 && inst.operands[i].reg == REG_PC
55881a11
MGD
8086 && (inst.operands[i].writeback || thumb))
8087 inst.error = BAD_PC;
8088 break;
8089
1b883319 8090 case OP_RVSD_COND:
32c36c3c
AV
8091 case OP_VLDR:
8092 if (inst.operands[i].isreg)
8093 break;
8094 /* fall through. */
1b883319 8095
c19d1205
ZW
8096 case OP_CPSF:
8097 case OP_ENDI:
8098 case OP_oROR:
d2cd1205
JB
8099 case OP_wPSR:
8100 case OP_rPSR:
c19d1205 8101 case OP_COND:
52e7f43d 8102 case OP_oBARRIER_I15:
c19d1205 8103 case OP_REGLST:
4b5a202f 8104 case OP_CLRMLST:
c19d1205
ZW
8105 case OP_VRSLST:
8106 case OP_VRDLST:
477330fc 8107 case OP_VRSDLST:
efd6b359 8108 case OP_VRSDVLST:
477330fc
RM
8109 case OP_NRDLST:
8110 case OP_NSTRLST:
35c228db
AV
8111 case OP_MSTRLST2:
8112 case OP_MSTRLST4:
c19d1205
ZW
8113 if (val == FAIL)
8114 goto failure;
8115 inst.operands[i].imm = val;
8116 break;
a737bd4d 8117
60f993ce
AV
8118 case OP_LR:
8119 case OP_oLR:
8120 if (inst.operands[i].reg != REG_LR)
8121 inst.error = _("operand must be LR register");
8122 break;
8123
1b883319
AV
8124 case OP_RMQRZ:
8125 case OP_oRMQRZ:
e39c1607 8126 case OP_RR_ZR:
1b883319
AV
8127 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8128 inst.error = BAD_PC;
8129 break;
8130
a302e574
AV
8131 case OP_RRe:
8132 if (inst.operands[i].isreg
8133 && (inst.operands[i].reg & 0x00000001) != 0)
8134 inst.error = BAD_ODD;
8135 break;
8136
8137 case OP_RRo:
8138 if (inst.operands[i].isreg)
8139 {
8140 if ((inst.operands[i].reg & 0x00000001) != 1)
8141 inst.error = BAD_EVEN;
8142 else if (inst.operands[i].reg == REG_SP)
8143 as_tsktsk (MVE_BAD_SP);
8144 else if (inst.operands[i].reg == REG_PC)
8145 inst.error = BAD_PC;
8146 }
8147 break;
8148
c19d1205
ZW
8149 default:
8150 break;
8151 }
09d92015 8152
c19d1205
ZW
8153 /* If we get here, this operand was successfully parsed. */
8154 inst.operands[i].present = 1;
8155 continue;
09d92015 8156
c19d1205 8157 bad_args:
09d92015 8158 inst.error = BAD_ARGS;
c19d1205
ZW
8159
8160 failure:
8161 if (!backtrack_pos)
d252fdde
PB
8162 {
8163 /* The parse routine should already have set inst.error, but set a
5f4273c7 8164 default here just in case. */
d252fdde 8165 if (!inst.error)
5ee91343 8166 inst.error = BAD_SYNTAX;
d252fdde
PB
8167 return FAIL;
8168 }
c19d1205
ZW
8169
8170 /* Do not backtrack over a trailing optional argument that
8171 absorbed some text. We will only fail again, with the
8172 'garbage following instruction' error message, which is
8173 probably less helpful than the current one. */
8174 if (backtrack_index == i && backtrack_pos != str
8175 && upat[i+1] == OP_stop)
d252fdde
PB
8176 {
8177 if (!inst.error)
5ee91343 8178 inst.error = BAD_SYNTAX;
d252fdde
PB
8179 return FAIL;
8180 }
c19d1205
ZW
8181
8182 /* Try again, skipping the optional argument at backtrack_pos. */
8183 str = backtrack_pos;
8184 inst.error = backtrack_error;
8185 inst.operands[backtrack_index].present = 0;
8186 i = backtrack_index;
8187 backtrack_pos = 0;
09d92015 8188 }
09d92015 8189
c19d1205
ZW
8190 /* Check that we have parsed all the arguments. */
8191 if (*str != '\0' && !inst.error)
8192 inst.error = _("garbage following instruction");
09d92015 8193
c19d1205 8194 return inst.error ? FAIL : SUCCESS;
09d92015
MM
8195}
8196
c19d1205
ZW
8197#undef po_char_or_fail
8198#undef po_reg_or_fail
8199#undef po_reg_or_goto
8200#undef po_imm_or_fail
5287ad62 8201#undef po_scalar_or_fail
52e7f43d 8202#undef po_barrier_or_imm
e07e6e58 8203
c19d1205 8204/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
8205#define constraint(expr, err) \
8206 do \
c19d1205 8207 { \
e07e6e58
NC
8208 if (expr) \
8209 { \
8210 inst.error = err; \
8211 return; \
8212 } \
c19d1205 8213 } \
e07e6e58 8214 while (0)
c19d1205 8215
fdfde340
JM
8216/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8217 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
8218 is the BadReg predicate in ARM's Thumb-2 documentation.
8219
8220 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8221 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8222#define reject_bad_reg(reg) \
8223 do \
8224 if (reg == REG_PC) \
8225 { \
8226 inst.error = BAD_PC; \
8227 return; \
8228 } \
8229 else if (reg == REG_SP \
8230 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8231 { \
8232 inst.error = BAD_SP; \
8233 return; \
8234 } \
fdfde340
JM
8235 while (0)
8236
94206790
MM
8237/* If REG is R13 (the stack pointer), warn that its use is
8238 deprecated. */
8239#define warn_deprecated_sp(reg) \
8240 do \
8241 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 8242 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
8243 while (0)
8244
c19d1205
ZW
8245/* Functions for operand encoding. ARM, then Thumb. */
8246
d840c081 8247#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 8248
9db2f6b4
RL
8249/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8250
8251 The only binary encoding difference is the Coprocessor number. Coprocessor
8252 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 8253 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
8254 exists for Single-Precision operation. */
8255
8256static void
8257do_scalar_fp16_v82_encode (void)
8258{
5ee91343 8259 if (inst.cond < COND_ALWAYS)
9db2f6b4
RL
8260 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8261 " the behaviour is UNPREDICTABLE"));
8262 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8263 _(BAD_FP16));
8264
8265 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8266 mark_feature_used (&arm_ext_fp16);
8267}
8268
c19d1205
ZW
8269/* If VAL can be encoded in the immediate field of an ARM instruction,
8270 return the encoded form. Otherwise, return FAIL. */
8271
8272static unsigned int
8273encode_arm_immediate (unsigned int val)
09d92015 8274{
c19d1205
ZW
8275 unsigned int a, i;
8276
4f1d6205
L
8277 if (val <= 0xff)
8278 return val;
8279
8280 for (i = 2; i < 32; i += 2)
c19d1205
ZW
8281 if ((a = rotate_left (val, i)) <= 0xff)
8282 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8283
8284 return FAIL;
09d92015
MM
8285}
8286
c19d1205
ZW
8287/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8288 return the encoded form. Otherwise, return FAIL. */
8289static unsigned int
8290encode_thumb32_immediate (unsigned int val)
09d92015 8291{
c19d1205 8292 unsigned int a, i;
09d92015 8293
9c3c69f2 8294 if (val <= 0xff)
c19d1205 8295 return val;
a737bd4d 8296
9c3c69f2 8297 for (i = 1; i <= 24; i++)
09d92015 8298 {
9c3c69f2 8299 a = val >> i;
7af67752 8300 if ((val & ~(0xffU << i)) == 0)
9c3c69f2 8301 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 8302 }
a737bd4d 8303
c19d1205
ZW
8304 a = val & 0xff;
8305 if (val == ((a << 16) | a))
8306 return 0x100 | a;
8307 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8308 return 0x300 | a;
09d92015 8309
c19d1205
ZW
8310 a = val & 0xff00;
8311 if (val == ((a << 16) | a))
8312 return 0x200 | (a >> 8);
a737bd4d 8313
c19d1205 8314 return FAIL;
09d92015 8315}
5287ad62 8316/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
8317
8318static void
5287ad62
JB
8319encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8320{
8321 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8322 && reg > 15)
8323 {
b1cc4aeb 8324 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
8325 {
8326 if (thumb_mode)
8327 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8328 fpu_vfp_ext_d32);
8329 else
8330 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8331 fpu_vfp_ext_d32);
8332 }
5287ad62 8333 else
477330fc
RM
8334 {
8335 first_error (_("D register out of range for selected VFP version"));
8336 return;
8337 }
5287ad62
JB
8338 }
8339
c19d1205 8340 switch (pos)
09d92015 8341 {
c19d1205
ZW
8342 case VFP_REG_Sd:
8343 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8344 break;
8345
8346 case VFP_REG_Sn:
8347 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8348 break;
8349
8350 case VFP_REG_Sm:
8351 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8352 break;
8353
5287ad62
JB
8354 case VFP_REG_Dd:
8355 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8356 break;
5f4273c7 8357
5287ad62
JB
8358 case VFP_REG_Dn:
8359 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8360 break;
5f4273c7 8361
5287ad62
JB
8362 case VFP_REG_Dm:
8363 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8364 break;
8365
c19d1205
ZW
8366 default:
8367 abort ();
09d92015 8368 }
09d92015
MM
8369}
8370
c19d1205 8371/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 8372 if any, is handled by md_apply_fix. */
09d92015 8373static void
c19d1205 8374encode_arm_shift (int i)
09d92015 8375{
008a97ef
RL
8376 /* register-shifted register. */
8377 if (inst.operands[i].immisreg)
8378 {
bf355b69
MR
8379 int op_index;
8380 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 8381 {
5689c942
RL
8382 /* Check the operand only when it's presented. In pre-UAL syntax,
8383 if the destination register is the same as the first operand, two
8384 register form of the instruction can be used. */
bf355b69
MR
8385 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8386 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
8387 as_warn (UNPRED_REG ("r15"));
8388 }
8389
8390 if (inst.operands[i].imm == REG_PC)
8391 as_warn (UNPRED_REG ("r15"));
8392 }
8393
c19d1205
ZW
8394 if (inst.operands[i].shift_kind == SHIFT_RRX)
8395 inst.instruction |= SHIFT_ROR << 5;
8396 else
09d92015 8397 {
c19d1205
ZW
8398 inst.instruction |= inst.operands[i].shift_kind << 5;
8399 if (inst.operands[i].immisreg)
8400 {
8401 inst.instruction |= SHIFT_BY_REG;
8402 inst.instruction |= inst.operands[i].imm << 8;
8403 }
8404 else
e2b0ab59 8405 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 8406 }
c19d1205 8407}
09d92015 8408
c19d1205
ZW
8409static void
8410encode_arm_shifter_operand (int i)
8411{
8412 if (inst.operands[i].isreg)
09d92015 8413 {
c19d1205
ZW
8414 inst.instruction |= inst.operands[i].reg;
8415 encode_arm_shift (i);
09d92015 8416 }
c19d1205 8417 else
a415b1cd
JB
8418 {
8419 inst.instruction |= INST_IMMEDIATE;
e2b0ab59 8420 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
a415b1cd
JB
8421 inst.instruction |= inst.operands[i].imm;
8422 }
09d92015
MM
8423}
8424
c19d1205 8425/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 8426static void
c19d1205 8427encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 8428{
2b2f5df9
NC
8429 /* PR 14260:
8430 Generate an error if the operand is not a register. */
8431 constraint (!inst.operands[i].isreg,
8432 _("Instruction does not support =N addresses"));
8433
c19d1205 8434 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 8435
c19d1205 8436 if (inst.operands[i].preind)
09d92015 8437 {
c19d1205
ZW
8438 if (is_t)
8439 {
8440 inst.error = _("instruction does not accept preindexed addressing");
8441 return;
8442 }
8443 inst.instruction |= PRE_INDEX;
8444 if (inst.operands[i].writeback)
8445 inst.instruction |= WRITE_BACK;
09d92015 8446
c19d1205
ZW
8447 }
8448 else if (inst.operands[i].postind)
8449 {
9c2799c2 8450 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8451 if (is_t)
8452 inst.instruction |= WRITE_BACK;
8453 }
8454 else /* unindexed - only for coprocessor */
09d92015 8455 {
c19d1205 8456 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
8457 return;
8458 }
8459
c19d1205
ZW
8460 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8461 && (((inst.instruction & 0x000f0000) >> 16)
8462 == ((inst.instruction & 0x0000f000) >> 12)))
8463 as_warn ((inst.instruction & LOAD_BIT)
8464 ? _("destination register same as write-back base")
8465 : _("source register same as write-back base"));
09d92015
MM
8466}
8467
c19d1205
ZW
8468/* inst.operands[i] was set up by parse_address. Encode it into an
8469 ARM-format mode 2 load or store instruction. If is_t is true,
8470 reject forms that cannot be used with a T instruction (i.e. not
8471 post-indexed). */
a737bd4d 8472static void
c19d1205 8473encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 8474{
5be8be5d
DG
8475 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8476
c19d1205 8477 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8478
c19d1205 8479 if (inst.operands[i].immisreg)
09d92015 8480 {
5be8be5d
DG
8481 constraint ((inst.operands[i].imm == REG_PC
8482 || (is_pc && inst.operands[i].writeback)),
8483 BAD_PC_ADDRESSING);
c19d1205
ZW
8484 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8485 inst.instruction |= inst.operands[i].imm;
8486 if (!inst.operands[i].negative)
8487 inst.instruction |= INDEX_UP;
8488 if (inst.operands[i].shifted)
8489 {
8490 if (inst.operands[i].shift_kind == SHIFT_RRX)
8491 inst.instruction |= SHIFT_ROR << 5;
8492 else
8493 {
8494 inst.instruction |= inst.operands[i].shift_kind << 5;
e2b0ab59 8495 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
c19d1205
ZW
8496 }
8497 }
09d92015 8498 }
e2b0ab59 8499 else /* immediate offset in inst.relocs[0] */
09d92015 8500 {
e2b0ab59 8501 if (is_pc && !inst.relocs[0].pc_rel)
5be8be5d
DG
8502 {
8503 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
8504
8505 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8506 cannot use PC in addressing.
8507 PC cannot be used in writeback addressing, either. */
8508 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 8509 BAD_PC_ADDRESSING);
23a10334 8510
dc5ec521 8511 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
8512 if (warn_on_deprecated
8513 && !is_load
8514 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 8515 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
8516 }
8517
e2b0ab59 8518 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8519 {
8520 /* Prefer + for zero encoded value. */
8521 if (!inst.operands[i].negative)
8522 inst.instruction |= INDEX_UP;
e2b0ab59 8523 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
26d97720 8524 }
09d92015 8525 }
09d92015
MM
8526}
8527
c19d1205
ZW
8528/* inst.operands[i] was set up by parse_address. Encode it into an
8529 ARM-format mode 3 load or store instruction. Reject forms that
8530 cannot be used with such instructions. If is_t is true, reject
8531 forms that cannot be used with a T instruction (i.e. not
8532 post-indexed). */
8533static void
8534encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 8535{
c19d1205 8536 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 8537 {
c19d1205
ZW
8538 inst.error = _("instruction does not accept scaled register index");
8539 return;
09d92015 8540 }
a737bd4d 8541
c19d1205 8542 encode_arm_addr_mode_common (i, is_t);
a737bd4d 8543
c19d1205
ZW
8544 if (inst.operands[i].immisreg)
8545 {
5be8be5d 8546 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 8547 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 8548 BAD_PC_ADDRESSING);
eb9f3f00
JB
8549 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8550 BAD_PC_WRITEBACK);
c19d1205
ZW
8551 inst.instruction |= inst.operands[i].imm;
8552 if (!inst.operands[i].negative)
8553 inst.instruction |= INDEX_UP;
8554 }
e2b0ab59 8555 else /* immediate offset in inst.relocs[0] */
c19d1205 8556 {
e2b0ab59 8557 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
5be8be5d
DG
8558 && inst.operands[i].writeback),
8559 BAD_PC_WRITEBACK);
c19d1205 8560 inst.instruction |= HWOFFSET_IMM;
e2b0ab59 8561 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
26d97720
NS
8562 {
8563 /* Prefer + for zero encoded value. */
8564 if (!inst.operands[i].negative)
8565 inst.instruction |= INDEX_UP;
8566
e2b0ab59 8567 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
26d97720 8568 }
c19d1205 8569 }
a737bd4d
NC
8570}
8571
8335d6aa
JW
8572/* Write immediate bits [7:0] to the following locations:
8573
8574 |28/24|23 19|18 16|15 4|3 0|
8575 | 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|
8576
8577 This function is used by VMOV/VMVN/VORR/VBIC. */
8578
8579static void
8580neon_write_immbits (unsigned immbits)
8581{
8582 inst.instruction |= immbits & 0xf;
8583 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8584 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8585}
8586
8587/* Invert low-order SIZE bits of XHI:XLO. */
8588
8589static void
8590neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8591{
8592 unsigned immlo = xlo ? *xlo : 0;
8593 unsigned immhi = xhi ? *xhi : 0;
8594
8595 switch (size)
8596 {
8597 case 8:
8598 immlo = (~immlo) & 0xff;
8599 break;
8600
8601 case 16:
8602 immlo = (~immlo) & 0xffff;
8603 break;
8604
8605 case 64:
8606 immhi = (~immhi) & 0xffffffff;
8607 /* fall through. */
8608
8609 case 32:
8610 immlo = (~immlo) & 0xffffffff;
8611 break;
8612
8613 default:
8614 abort ();
8615 }
8616
8617 if (xlo)
8618 *xlo = immlo;
8619
8620 if (xhi)
8621 *xhi = immhi;
8622}
8623
8624/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8625 A, B, C, D. */
09d92015 8626
c19d1205 8627static int
8335d6aa 8628neon_bits_same_in_bytes (unsigned imm)
09d92015 8629{
8335d6aa
JW
8630 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8631 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8632 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8633 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8634}
a737bd4d 8635
8335d6aa 8636/* For immediate of above form, return 0bABCD. */
09d92015 8637
8335d6aa
JW
8638static unsigned
8639neon_squash_bits (unsigned imm)
8640{
8641 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8642 | ((imm & 0x01000000) >> 21);
8643}
8644
8645/* Compress quarter-float representation to 0b...000 abcdefgh. */
8646
8647static unsigned
8648neon_qfloat_bits (unsigned imm)
8649{
8650 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8651}
8652
8653/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8654 the instruction. *OP is passed as the initial value of the op field, and
8655 may be set to a different value depending on the constant (i.e.
8656 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8657 MVN). If the immediate looks like a repeated pattern then also
8658 try smaller element sizes. */
8659
8660static int
8661neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8662 unsigned *immbits, int *op, int size,
8663 enum neon_el_type type)
8664{
8665 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8666 float. */
8667 if (type == NT_float && !float_p)
8668 return FAIL;
8669
8670 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 8671 {
8335d6aa
JW
8672 if (size != 32 || *op == 1)
8673 return FAIL;
8674 *immbits = neon_qfloat_bits (immlo);
8675 return 0xf;
8676 }
8677
8678 if (size == 64)
8679 {
8680 if (neon_bits_same_in_bytes (immhi)
8681 && neon_bits_same_in_bytes (immlo))
c19d1205 8682 {
8335d6aa
JW
8683 if (*op == 1)
8684 return FAIL;
8685 *immbits = (neon_squash_bits (immhi) << 4)
8686 | neon_squash_bits (immlo);
8687 *op = 1;
8688 return 0xe;
c19d1205 8689 }
a737bd4d 8690
8335d6aa
JW
8691 if (immhi != immlo)
8692 return FAIL;
8693 }
a737bd4d 8694
8335d6aa 8695 if (size >= 32)
09d92015 8696 {
8335d6aa 8697 if (immlo == (immlo & 0x000000ff))
c19d1205 8698 {
8335d6aa
JW
8699 *immbits = immlo;
8700 return 0x0;
c19d1205 8701 }
8335d6aa 8702 else if (immlo == (immlo & 0x0000ff00))
c19d1205 8703 {
8335d6aa
JW
8704 *immbits = immlo >> 8;
8705 return 0x2;
c19d1205 8706 }
8335d6aa
JW
8707 else if (immlo == (immlo & 0x00ff0000))
8708 {
8709 *immbits = immlo >> 16;
8710 return 0x4;
8711 }
8712 else if (immlo == (immlo & 0xff000000))
8713 {
8714 *immbits = immlo >> 24;
8715 return 0x6;
8716 }
8717 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8718 {
8719 *immbits = (immlo >> 8) & 0xff;
8720 return 0xc;
8721 }
8722 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8723 {
8724 *immbits = (immlo >> 16) & 0xff;
8725 return 0xd;
8726 }
8727
8728 if ((immlo & 0xffff) != (immlo >> 16))
8729 return FAIL;
8730 immlo &= 0xffff;
09d92015 8731 }
a737bd4d 8732
8335d6aa 8733 if (size >= 16)
4962c51a 8734 {
8335d6aa
JW
8735 if (immlo == (immlo & 0x000000ff))
8736 {
8737 *immbits = immlo;
8738 return 0x8;
8739 }
8740 else if (immlo == (immlo & 0x0000ff00))
8741 {
8742 *immbits = immlo >> 8;
8743 return 0xa;
8744 }
8745
8746 if ((immlo & 0xff) != (immlo >> 8))
8747 return FAIL;
8748 immlo &= 0xff;
4962c51a
MS
8749 }
8750
8335d6aa
JW
8751 if (immlo == (immlo & 0x000000ff))
8752 {
8753 /* Don't allow MVN with 8-bit immediate. */
8754 if (*op == 1)
8755 return FAIL;
8756 *immbits = immlo;
8757 return 0xe;
8758 }
26d97720 8759
8335d6aa 8760 return FAIL;
c19d1205 8761}
a737bd4d 8762
5fc177c8 8763#if defined BFD_HOST_64_BIT
ba592044
AM
8764/* Returns TRUE if double precision value V may be cast
8765 to single precision without loss of accuracy. */
8766
8767static bfd_boolean
7e30b1eb 8768is_double_a_single (bfd_uint64_t v)
ba592044 8769{
7e30b1eb
AM
8770 int exp = (v >> 52) & 0x7FF;
8771 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
ba592044 8772
7e30b1eb
AM
8773 return ((exp == 0 || exp == 0x7FF
8774 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8775 && (mantissa & 0x1FFFFFFFL) == 0);
ba592044
AM
8776}
8777
3739860c 8778/* Returns a double precision value casted to single precision
ba592044
AM
8779 (ignoring the least significant bits in exponent and mantissa). */
8780
8781static int
7e30b1eb 8782double_to_single (bfd_uint64_t v)
ba592044 8783{
7af67752
AM
8784 unsigned int sign = (v >> 63) & 1;
8785 int exp = (v >> 52) & 0x7FF;
7e30b1eb 8786 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
ba592044
AM
8787
8788 if (exp == 0x7FF)
8789 exp = 0xFF;
8790 else
8791 {
8792 exp = exp - 1023 + 127;
8793 if (exp >= 0xFF)
8794 {
8795 /* Infinity. */
8796 exp = 0x7F;
8797 mantissa = 0;
8798 }
8799 else if (exp < 0)
8800 {
8801 /* No denormalized numbers. */
8802 exp = 0;
8803 mantissa = 0;
8804 }
8805 }
8806 mantissa >>= 29;
8807 return (sign << 31) | (exp << 23) | mantissa;
8808}
5fc177c8 8809#endif /* BFD_HOST_64_BIT */
ba592044 8810
8335d6aa
JW
8811enum lit_type
8812{
8813 CONST_THUMB,
8814 CONST_ARM,
8815 CONST_VEC
8816};
8817
ba592044
AM
8818static void do_vfp_nsyn_opcode (const char *);
8819
e2b0ab59 8820/* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
c19d1205
ZW
8821 Determine whether it can be performed with a move instruction; if
8822 it can, convert inst.instruction to that move instruction and
c921be7d
NC
8823 return TRUE; if it can't, convert inst.instruction to a literal-pool
8824 load and return FALSE. If this is not a valid thing to do in the
8825 current context, set inst.error and return TRUE.
a737bd4d 8826
c19d1205
ZW
8827 inst.operands[i] describes the destination register. */
8828
c921be7d 8829static bfd_boolean
8335d6aa 8830move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 8831{
53365c0d 8832 unsigned long tbit;
8335d6aa
JW
8833 bfd_boolean thumb_p = (t == CONST_THUMB);
8834 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
8835
8836 if (thumb_p)
8837 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8838 else
8839 tbit = LOAD_BIT;
8840
8841 if ((inst.instruction & tbit) == 0)
09d92015 8842 {
c19d1205 8843 inst.error = _("invalid pseudo operation");
c921be7d 8844 return TRUE;
09d92015 8845 }
ba592044 8846
e2b0ab59
AV
8847 if (inst.relocs[0].exp.X_op != O_constant
8848 && inst.relocs[0].exp.X_op != O_symbol
8849 && inst.relocs[0].exp.X_op != O_big)
09d92015
MM
8850 {
8851 inst.error = _("constant expression expected");
c921be7d 8852 return TRUE;
09d92015 8853 }
ba592044 8854
e2b0ab59
AV
8855 if (inst.relocs[0].exp.X_op == O_constant
8856 || inst.relocs[0].exp.X_op == O_big)
8335d6aa 8857 {
5fc177c8 8858#if defined BFD_HOST_64_BIT
7e30b1eb 8859 bfd_uint64_t v;
5fc177c8 8860#else
7e30b1eb 8861 valueT v;
5fc177c8 8862#endif
e2b0ab59 8863 if (inst.relocs[0].exp.X_op == O_big)
8335d6aa 8864 {
ba592044
AM
8865 LITTLENUM_TYPE w[X_PRECISION];
8866 LITTLENUM_TYPE * l;
8867
e2b0ab59 8868 if (inst.relocs[0].exp.X_add_number == -1)
8335d6aa 8869 {
ba592044
AM
8870 gen_to_words (w, X_PRECISION, E_PRECISION);
8871 l = w;
8872 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8873 }
ba592044
AM
8874 else
8875 l = generic_bignum;
3739860c 8876
5fc177c8 8877#if defined BFD_HOST_64_BIT
7e30b1eb
AM
8878 v = l[3] & LITTLENUM_MASK;
8879 v <<= LITTLENUM_NUMBER_OF_BITS;
8880 v |= l[2] & LITTLENUM_MASK;
8881 v <<= LITTLENUM_NUMBER_OF_BITS;
8882 v |= l[1] & LITTLENUM_MASK;
8883 v <<= LITTLENUM_NUMBER_OF_BITS;
8884 v |= l[0] & LITTLENUM_MASK;
5fc177c8 8885#else
7e30b1eb
AM
8886 v = l[1] & LITTLENUM_MASK;
8887 v <<= LITTLENUM_NUMBER_OF_BITS;
8888 v |= l[0] & LITTLENUM_MASK;
5fc177c8 8889#endif
8335d6aa 8890 }
ba592044 8891 else
e2b0ab59 8892 v = inst.relocs[0].exp.X_add_number;
ba592044
AM
8893
8894 if (!inst.operands[i].issingle)
8335d6aa 8895 {
12569877 8896 if (thumb_p)
8335d6aa 8897 {
53445554
TP
8898 /* LDR should not use lead in a flag-setting instruction being
8899 chosen so we do not check whether movs can be used. */
12569877 8900
53445554 8901 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8902 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8903 && inst.operands[i].reg != 13
8904 && inst.operands[i].reg != 15)
12569877 8905 {
fc289b0a
TP
8906 /* Check if on thumb2 it can be done with a mov.w, mvn or
8907 movw instruction. */
12569877 8908 unsigned int newimm;
f3da8a96 8909 bfd_boolean isNegated = FALSE;
12569877
AM
8910
8911 newimm = encode_thumb32_immediate (v);
f3da8a96 8912 if (newimm == (unsigned int) FAIL)
12569877 8913 {
582cfe03 8914 newimm = encode_thumb32_immediate (~v);
f3da8a96 8915 isNegated = TRUE;
12569877
AM
8916 }
8917
fc289b0a
TP
8918 /* The number can be loaded with a mov.w or mvn
8919 instruction. */
ff8646ee
TP
8920 if (newimm != (unsigned int) FAIL
8921 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8922 {
fc289b0a 8923 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8924 | (inst.operands[i].reg << 8));
fc289b0a 8925 /* Change to MOVN. */
582cfe03 8926 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8927 inst.instruction |= (newimm & 0x800) << 15;
8928 inst.instruction |= (newimm & 0x700) << 4;
8929 inst.instruction |= (newimm & 0x0ff);
8930 return TRUE;
8931 }
fc289b0a 8932 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8933 else if ((v & ~0xFFFF) == 0
8934 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8935 {
582cfe03 8936 int imm = v & 0xFFFF;
12569877 8937
582cfe03 8938 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8939 inst.instruction |= (inst.operands[i].reg << 8);
8940 inst.instruction |= (imm & 0xf000) << 4;
8941 inst.instruction |= (imm & 0x0800) << 15;
8942 inst.instruction |= (imm & 0x0700) << 4;
8943 inst.instruction |= (imm & 0x00ff);
8fe9a076
AV
8944 /* In case this replacement is being done on Armv8-M
8945 Baseline we need to make sure to disable the
8946 instruction size check, as otherwise GAS will reject
8947 the use of this T32 instruction. */
8948 inst.size_req = 0;
12569877
AM
8949 return TRUE;
8950 }
8951 }
8335d6aa 8952 }
12569877 8953 else if (arm_p)
ba592044
AM
8954 {
8955 int value = encode_arm_immediate (v);
12569877 8956
ba592044
AM
8957 if (value != FAIL)
8958 {
8959 /* This can be done with a mov instruction. */
8960 inst.instruction &= LITERAL_MASK;
8961 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8962 inst.instruction |= value & 0xfff;
8963 return TRUE;
8964 }
8335d6aa 8965
ba592044
AM
8966 value = encode_arm_immediate (~ v);
8967 if (value != FAIL)
8968 {
8969 /* This can be done with a mvn instruction. */
8970 inst.instruction &= LITERAL_MASK;
8971 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8972 inst.instruction |= value & 0xfff;
8973 return TRUE;
8974 }
8975 }
934c2632 8976 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8977 {
ba592044
AM
8978 int op = 0;
8979 unsigned immbits = 0;
8980 unsigned immlo = inst.operands[1].imm;
8981 unsigned immhi = inst.operands[1].regisimm
8982 ? inst.operands[1].reg
e2b0ab59 8983 : inst.relocs[0].exp.X_unsigned
ba592044
AM
8984 ? 0
8985 : ((bfd_int64_t)((int) immlo)) >> 32;
8986 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8987 &op, 64, NT_invtype);
8988
8989 if (cmode == FAIL)
8990 {
8991 neon_invert_size (&immlo, &immhi, 64);
8992 op = !op;
8993 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8994 &op, 64, NT_invtype);
8995 }
8996
8997 if (cmode != FAIL)
8998 {
8999 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
9000 | (1 << 23)
9001 | (cmode << 8)
9002 | (op << 5)
9003 | (1 << 4);
9004
9005 /* Fill other bits in vmov encoding for both thumb and arm. */
9006 if (thumb_mode)
eff0bc54 9007 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 9008 else
eff0bc54 9009 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
9010 neon_write_immbits (immbits);
9011 return TRUE;
9012 }
8335d6aa
JW
9013 }
9014 }
8335d6aa 9015
ba592044
AM
9016 if (t == CONST_VEC)
9017 {
9018 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9019 if (inst.operands[i].issingle
9020 && is_quarter_float (inst.operands[1].imm)
9021 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 9022 {
ba592044
AM
9023 inst.operands[1].imm =
9024 neon_qfloat_bits (v);
9025 do_vfp_nsyn_opcode ("fconsts");
9026 return TRUE;
8335d6aa 9027 }
5fc177c8
NC
9028
9029 /* If our host does not support a 64-bit type then we cannot perform
9030 the following optimization. This mean that there will be a
9031 discrepancy between the output produced by an assembler built for
9032 a 32-bit-only host and the output produced from a 64-bit host, but
9033 this cannot be helped. */
9034#if defined BFD_HOST_64_BIT
ba592044
AM
9035 else if (!inst.operands[1].issingle
9036 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 9037 {
ba592044
AM
9038 if (is_double_a_single (v)
9039 && is_quarter_float (double_to_single (v)))
9040 {
9041 inst.operands[1].imm =
9042 neon_qfloat_bits (double_to_single (v));
9043 do_vfp_nsyn_opcode ("fconstd");
9044 return TRUE;
9045 }
8335d6aa 9046 }
5fc177c8 9047#endif
8335d6aa
JW
9048 }
9049 }
9050
9051 if (add_to_lit_pool ((!inst.operands[i].isvec
9052 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9053 return TRUE;
9054
9055 inst.operands[1].reg = REG_PC;
9056 inst.operands[1].isreg = 1;
9057 inst.operands[1].preind = 1;
e2b0ab59
AV
9058 inst.relocs[0].pc_rel = 1;
9059 inst.relocs[0].type = (thumb_p
8335d6aa
JW
9060 ? BFD_RELOC_ARM_THUMB_OFFSET
9061 : (mode_3
9062 ? BFD_RELOC_ARM_HWLITERAL
9063 : BFD_RELOC_ARM_LITERAL));
9064 return FALSE;
9065}
9066
9067/* inst.operands[i] was set up by parse_address. Encode it into an
9068 ARM-format instruction. Reject all forms which cannot be encoded
9069 into a coprocessor load/store instruction. If wb_ok is false,
9070 reject use of writeback; if unind_ok is false, reject use of
9071 unindexed addressing. If reloc_override is not 0, use it instead
9072 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9073 (in which case it is preserved). */
9074
9075static int
9076encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9077{
9078 if (!inst.operands[i].isreg)
9079 {
99b2a2dd
NC
9080 /* PR 18256 */
9081 if (! inst.operands[0].isvec)
9082 {
9083 inst.error = _("invalid co-processor operand");
9084 return FAIL;
9085 }
8335d6aa
JW
9086 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9087 return SUCCESS;
9088 }
9089
9090 inst.instruction |= inst.operands[i].reg << 16;
9091
9092 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9093
9094 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9095 {
9096 gas_assert (!inst.operands[i].writeback);
9097 if (!unind_ok)
9098 {
9099 inst.error = _("instruction does not support unindexed addressing");
9100 return FAIL;
9101 }
9102 inst.instruction |= inst.operands[i].imm;
9103 inst.instruction |= INDEX_UP;
9104 return SUCCESS;
9105 }
9106
9107 if (inst.operands[i].preind)
9108 inst.instruction |= PRE_INDEX;
9109
9110 if (inst.operands[i].writeback)
09d92015 9111 {
8335d6aa 9112 if (inst.operands[i].reg == REG_PC)
c19d1205 9113 {
8335d6aa
JW
9114 inst.error = _("pc may not be used with write-back");
9115 return FAIL;
c19d1205 9116 }
8335d6aa 9117 if (!wb_ok)
c19d1205 9118 {
8335d6aa
JW
9119 inst.error = _("instruction does not support writeback");
9120 return FAIL;
c19d1205 9121 }
8335d6aa 9122 inst.instruction |= WRITE_BACK;
09d92015
MM
9123 }
9124
8335d6aa 9125 if (reloc_override)
e2b0ab59
AV
9126 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9127 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9128 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9129 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 9130 {
8335d6aa 9131 if (thumb_mode)
e2b0ab59 9132 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8335d6aa 9133 else
e2b0ab59 9134 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 9135 }
8335d6aa
JW
9136
9137 /* Prefer + for zero encoded value. */
9138 if (!inst.operands[i].negative)
9139 inst.instruction |= INDEX_UP;
9140
9141 return SUCCESS;
09d92015
MM
9142}
9143
5f4273c7 9144/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
9145 First some generics; their names are taken from the conventional
9146 bit positions for register arguments in ARM format instructions. */
09d92015 9147
a737bd4d 9148static void
c19d1205 9149do_noargs (void)
09d92015 9150{
c19d1205 9151}
a737bd4d 9152
c19d1205
ZW
9153static void
9154do_rd (void)
9155{
9156 inst.instruction |= inst.operands[0].reg << 12;
9157}
a737bd4d 9158
16a1fa25
TP
9159static void
9160do_rn (void)
9161{
9162 inst.instruction |= inst.operands[0].reg << 16;
9163}
9164
c19d1205
ZW
9165static void
9166do_rd_rm (void)
9167{
9168 inst.instruction |= inst.operands[0].reg << 12;
9169 inst.instruction |= inst.operands[1].reg;
9170}
09d92015 9171
9eb6c0f1
MGD
9172static void
9173do_rm_rn (void)
9174{
9175 inst.instruction |= inst.operands[0].reg;
9176 inst.instruction |= inst.operands[1].reg << 16;
9177}
9178
c19d1205
ZW
9179static void
9180do_rd_rn (void)
9181{
9182 inst.instruction |= inst.operands[0].reg << 12;
9183 inst.instruction |= inst.operands[1].reg << 16;
9184}
a737bd4d 9185
c19d1205
ZW
9186static void
9187do_rn_rd (void)
9188{
9189 inst.instruction |= inst.operands[0].reg << 16;
9190 inst.instruction |= inst.operands[1].reg << 12;
9191}
09d92015 9192
4ed7ed8d
TP
9193static void
9194do_tt (void)
9195{
9196 inst.instruction |= inst.operands[0].reg << 8;
9197 inst.instruction |= inst.operands[1].reg << 16;
9198}
9199
59d09be6
MGD
9200static bfd_boolean
9201check_obsolete (const arm_feature_set *feature, const char *msg)
9202{
9203 if (ARM_CPU_IS_ANY (cpu_variant))
9204 {
5c3696f8 9205 as_tsktsk ("%s", msg);
59d09be6
MGD
9206 return TRUE;
9207 }
9208 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9209 {
9210 as_bad ("%s", msg);
9211 return TRUE;
9212 }
9213
9214 return FALSE;
9215}
9216
c19d1205
ZW
9217static void
9218do_rd_rm_rn (void)
9219{
9a64e435 9220 unsigned Rn = inst.operands[2].reg;
708587a4 9221 /* Enforce restrictions on SWP instruction. */
9a64e435 9222 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
9223 {
9224 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9225 _("Rn must not overlap other operands"));
9226
59d09be6
MGD
9227 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9228 */
9229 if (!check_obsolete (&arm_ext_v8,
9230 _("swp{b} use is obsoleted for ARMv8 and later"))
9231 && warn_on_deprecated
9232 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 9233 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 9234 }
59d09be6 9235
c19d1205
ZW
9236 inst.instruction |= inst.operands[0].reg << 12;
9237 inst.instruction |= inst.operands[1].reg;
9a64e435 9238 inst.instruction |= Rn << 16;
c19d1205 9239}
09d92015 9240
c19d1205
ZW
9241static void
9242do_rd_rn_rm (void)
9243{
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[1].reg << 16;
9246 inst.instruction |= inst.operands[2].reg;
9247}
a737bd4d 9248
c19d1205
ZW
9249static void
9250do_rm_rd_rn (void)
9251{
5be8be5d 9252 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
e2b0ab59
AV
9253 constraint (((inst.relocs[0].exp.X_op != O_constant
9254 && inst.relocs[0].exp.X_op != O_illegal)
9255 || inst.relocs[0].exp.X_add_number != 0),
5be8be5d 9256 BAD_ADDR_MODE);
c19d1205
ZW
9257 inst.instruction |= inst.operands[0].reg;
9258 inst.instruction |= inst.operands[1].reg << 12;
9259 inst.instruction |= inst.operands[2].reg << 16;
9260}
09d92015 9261
c19d1205
ZW
9262static void
9263do_imm0 (void)
9264{
9265 inst.instruction |= inst.operands[0].imm;
9266}
09d92015 9267
c19d1205
ZW
9268static void
9269do_rd_cpaddr (void)
9270{
9271 inst.instruction |= inst.operands[0].reg << 12;
9272 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 9273}
a737bd4d 9274
c19d1205
ZW
9275/* ARM instructions, in alphabetical order by function name (except
9276 that wrapper functions appear immediately after the function they
9277 wrap). */
09d92015 9278
c19d1205
ZW
9279/* This is a pseudo-op of the form "adr rd, label" to be converted
9280 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
9281
9282static void
c19d1205 9283do_adr (void)
09d92015 9284{
c19d1205 9285 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9286
c19d1205
ZW
9287 /* Frag hacking will turn this into a sub instruction if the offset turns
9288 out to be negative. */
e2b0ab59
AV
9289 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9290 inst.relocs[0].pc_rel = 1;
9291 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9292
fc6141f0 9293 if (support_interwork
e2b0ab59
AV
9294 && inst.relocs[0].exp.X_op == O_symbol
9295 && inst.relocs[0].exp.X_add_symbol != NULL
9296 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9297 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9298 inst.relocs[0].exp.X_add_number |= 1;
c19d1205 9299}
b99bd4ef 9300
c19d1205
ZW
9301/* This is a pseudo-op of the form "adrl rd, label" to be converted
9302 into a relative address of the form:
9303 add rd, pc, #low(label-.-8)"
9304 add rd, rd, #high(label-.-8)" */
b99bd4ef 9305
c19d1205
ZW
9306static void
9307do_adrl (void)
9308{
9309 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 9310
c19d1205
ZW
9311 /* Frag hacking will turn this into a sub instruction if the offset turns
9312 out to be negative. */
e2b0ab59
AV
9313 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9314 inst.relocs[0].pc_rel = 1;
c19d1205 9315 inst.size = INSN_SIZE * 2;
e2b0ab59 9316 inst.relocs[0].exp.X_add_number -= 8;
52a86f84 9317
fc6141f0 9318 if (support_interwork
e2b0ab59
AV
9319 && inst.relocs[0].exp.X_op == O_symbol
9320 && inst.relocs[0].exp.X_add_symbol != NULL
9321 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9322 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9323 inst.relocs[0].exp.X_add_number |= 1;
b99bd4ef
NC
9324}
9325
b99bd4ef 9326static void
c19d1205 9327do_arit (void)
b99bd4ef 9328{
e2b0ab59
AV
9329 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9330 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 9331 THUMB1_RELOC_ONLY);
c19d1205
ZW
9332 if (!inst.operands[1].present)
9333 inst.operands[1].reg = inst.operands[0].reg;
9334 inst.instruction |= inst.operands[0].reg << 12;
9335 inst.instruction |= inst.operands[1].reg << 16;
9336 encode_arm_shifter_operand (2);
9337}
b99bd4ef 9338
62b3e311
PB
9339static void
9340do_barrier (void)
9341{
9342 if (inst.operands[0].present)
ccb84d65 9343 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
9344 else
9345 inst.instruction |= 0xf;
9346}
9347
c19d1205
ZW
9348static void
9349do_bfc (void)
9350{
9351 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9352 constraint (msb > 32, _("bit-field extends past end of register"));
9353 /* The instruction encoding stores the LSB and MSB,
9354 not the LSB and width. */
9355 inst.instruction |= inst.operands[0].reg << 12;
9356 inst.instruction |= inst.operands[1].imm << 7;
9357 inst.instruction |= (msb - 1) << 16;
9358}
b99bd4ef 9359
c19d1205
ZW
9360static void
9361do_bfi (void)
9362{
9363 unsigned int msb;
b99bd4ef 9364
c19d1205
ZW
9365 /* #0 in second position is alternative syntax for bfc, which is
9366 the same instruction but with REG_PC in the Rm field. */
9367 if (!inst.operands[1].isreg)
9368 inst.operands[1].reg = REG_PC;
b99bd4ef 9369
c19d1205
ZW
9370 msb = inst.operands[2].imm + inst.operands[3].imm;
9371 constraint (msb > 32, _("bit-field extends past end of register"));
9372 /* The instruction encoding stores the LSB and MSB,
9373 not the LSB and width. */
9374 inst.instruction |= inst.operands[0].reg << 12;
9375 inst.instruction |= inst.operands[1].reg;
9376 inst.instruction |= inst.operands[2].imm << 7;
9377 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
9378}
9379
b99bd4ef 9380static void
c19d1205 9381do_bfx (void)
b99bd4ef 9382{
c19d1205
ZW
9383 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9384 _("bit-field extends past end of register"));
9385 inst.instruction |= inst.operands[0].reg << 12;
9386 inst.instruction |= inst.operands[1].reg;
9387 inst.instruction |= inst.operands[2].imm << 7;
9388 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9389}
09d92015 9390
c19d1205
ZW
9391/* ARM V5 breakpoint instruction (argument parse)
9392 BKPT <16 bit unsigned immediate>
9393 Instruction is not conditional.
9394 The bit pattern given in insns[] has the COND_ALWAYS condition,
9395 and it is an error if the caller tried to override that. */
b99bd4ef 9396
c19d1205
ZW
9397static void
9398do_bkpt (void)
9399{
9400 /* Top 12 of 16 bits to bits 19:8. */
9401 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 9402
c19d1205
ZW
9403 /* Bottom 4 of 16 bits to bits 3:0. */
9404 inst.instruction |= inst.operands[0].imm & 0xf;
9405}
09d92015 9406
c19d1205
ZW
9407static void
9408encode_branch (int default_reloc)
9409{
9410 if (inst.operands[0].hasreloc)
9411 {
0855e32b
NS
9412 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9413 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9414 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
e2b0ab59 9415 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
0855e32b
NS
9416 ? BFD_RELOC_ARM_PLT32
9417 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 9418 }
b99bd4ef 9419 else
e2b0ab59
AV
9420 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9421 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
9422}
9423
b99bd4ef 9424static void
c19d1205 9425do_branch (void)
b99bd4ef 9426{
39b41c9c
PB
9427#ifdef OBJ_ELF
9428 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9429 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9430 else
9431#endif
9432 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9433}
9434
9435static void
9436do_bl (void)
9437{
9438#ifdef OBJ_ELF
9439 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9440 {
9441 if (inst.cond == COND_ALWAYS)
9442 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9443 else
9444 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9445 }
9446 else
9447#endif
9448 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 9449}
b99bd4ef 9450
c19d1205
ZW
9451/* ARM V5 branch-link-exchange instruction (argument parse)
9452 BLX <target_addr> ie BLX(1)
9453 BLX{<condition>} <Rm> ie BLX(2)
9454 Unfortunately, there are two different opcodes for this mnemonic.
9455 So, the insns[].value is not used, and the code here zaps values
9456 into inst.instruction.
9457 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 9458
c19d1205
ZW
9459static void
9460do_blx (void)
9461{
9462 if (inst.operands[0].isreg)
b99bd4ef 9463 {
c19d1205
ZW
9464 /* Arg is a register; the opcode provided by insns[] is correct.
9465 It is not illegal to do "blx pc", just useless. */
9466 if (inst.operands[0].reg == REG_PC)
9467 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 9468
c19d1205
ZW
9469 inst.instruction |= inst.operands[0].reg;
9470 }
9471 else
b99bd4ef 9472 {
c19d1205 9473 /* Arg is an address; this instruction cannot be executed
267bf995
RR
9474 conditionally, and the opcode must be adjusted.
9475 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9476 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 9477 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 9478 inst.instruction = 0xfa000000;
267bf995 9479 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 9480 }
c19d1205
ZW
9481}
9482
9483static void
9484do_bx (void)
9485{
845b51d6
PB
9486 bfd_boolean want_reloc;
9487
c19d1205
ZW
9488 if (inst.operands[0].reg == REG_PC)
9489 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 9490
c19d1205 9491 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
9492 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9493 it is for ARMv4t or earlier. */
9494 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
9495 if (!ARM_FEATURE_ZERO (selected_object_arch)
9496 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
9497 want_reloc = TRUE;
9498
5ad34203 9499#ifdef OBJ_ELF
845b51d6 9500 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 9501#endif
584206db 9502 want_reloc = FALSE;
845b51d6
PB
9503
9504 if (want_reloc)
e2b0ab59 9505 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
09d92015
MM
9506}
9507
c19d1205
ZW
9508
9509/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
9510
9511static void
c19d1205 9512do_bxj (void)
a737bd4d 9513{
c19d1205
ZW
9514 if (inst.operands[0].reg == REG_PC)
9515 as_tsktsk (_("use of r15 in bxj is not really useful"));
9516
9517 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
9518}
9519
c19d1205
ZW
9520/* Co-processor data operation:
9521 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9522 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9523static void
9524do_cdp (void)
9525{
9526 inst.instruction |= inst.operands[0].reg << 8;
9527 inst.instruction |= inst.operands[1].imm << 20;
9528 inst.instruction |= inst.operands[2].reg << 12;
9529 inst.instruction |= inst.operands[3].reg << 16;
9530 inst.instruction |= inst.operands[4].reg;
9531 inst.instruction |= inst.operands[5].imm << 5;
9532}
a737bd4d
NC
9533
9534static void
c19d1205 9535do_cmp (void)
a737bd4d 9536{
c19d1205
ZW
9537 inst.instruction |= inst.operands[0].reg << 16;
9538 encode_arm_shifter_operand (1);
a737bd4d
NC
9539}
9540
c19d1205
ZW
9541/* Transfer between coprocessor and ARM registers.
9542 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9543 MRC2
9544 MCR{cond}
9545 MCR2
9546
9547 No special properties. */
09d92015 9548
dcbd0d71
MGD
9549struct deprecated_coproc_regs_s
9550{
9551 unsigned cp;
9552 int opc1;
9553 unsigned crn;
9554 unsigned crm;
9555 int opc2;
9556 arm_feature_set deprecated;
9557 arm_feature_set obsoleted;
9558 const char *dep_msg;
9559 const char *obs_msg;
9560};
9561
9562#define DEPR_ACCESS_V8 \
9563 N_("This coprocessor register access is deprecated in ARMv8")
9564
9565/* Table of all deprecated coprocessor registers. */
9566static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9567{
9568 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 9569 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9570 DEPR_ACCESS_V8, NULL},
9571 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 9572 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9573 DEPR_ACCESS_V8, NULL},
9574 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 9575 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9576 DEPR_ACCESS_V8, NULL},
9577 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 9578 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9579 DEPR_ACCESS_V8, NULL},
9580 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 9581 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
9582 DEPR_ACCESS_V8, NULL},
9583};
9584
9585#undef DEPR_ACCESS_V8
9586
9587static const size_t deprecated_coproc_reg_count =
9588 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9589
09d92015 9590static void
c19d1205 9591do_co_reg (void)
09d92015 9592{
fdfde340 9593 unsigned Rd;
dcbd0d71 9594 size_t i;
fdfde340
JM
9595
9596 Rd = inst.operands[2].reg;
9597 if (thumb_mode)
9598 {
9599 if (inst.instruction == 0xee000010
9600 || inst.instruction == 0xfe000010)
9601 /* MCR, MCR2 */
9602 reject_bad_reg (Rd);
5c8ed6a4 9603 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
9604 /* MRC, MRC2 */
9605 constraint (Rd == REG_SP, BAD_SP);
9606 }
9607 else
9608 {
9609 /* MCR */
9610 if (inst.instruction == 0xe000010)
9611 constraint (Rd == REG_PC, BAD_PC);
9612 }
9613
dcbd0d71
MGD
9614 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9615 {
9616 const struct deprecated_coproc_regs_s *r =
9617 deprecated_coproc_regs + i;
9618
9619 if (inst.operands[0].reg == r->cp
9620 && inst.operands[1].imm == r->opc1
9621 && inst.operands[3].reg == r->crn
9622 && inst.operands[4].reg == r->crm
9623 && inst.operands[5].imm == r->opc2)
9624 {
b10bf8c5 9625 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 9626 && warn_on_deprecated
dcbd0d71 9627 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 9628 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
9629 }
9630 }
fdfde340 9631
c19d1205
ZW
9632 inst.instruction |= inst.operands[0].reg << 8;
9633 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 9634 inst.instruction |= Rd << 12;
c19d1205
ZW
9635 inst.instruction |= inst.operands[3].reg << 16;
9636 inst.instruction |= inst.operands[4].reg;
9637 inst.instruction |= inst.operands[5].imm << 5;
9638}
09d92015 9639
c19d1205
ZW
9640/* Transfer between coprocessor register and pair of ARM registers.
9641 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9642 MCRR2
9643 MRRC{cond}
9644 MRRC2
b99bd4ef 9645
c19d1205 9646 Two XScale instructions are special cases of these:
09d92015 9647
c19d1205
ZW
9648 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9649 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 9650
5f4273c7 9651 Result unpredictable if Rd or Rn is R15. */
a737bd4d 9652
c19d1205
ZW
9653static void
9654do_co_reg2c (void)
9655{
fdfde340
JM
9656 unsigned Rd, Rn;
9657
9658 Rd = inst.operands[2].reg;
9659 Rn = inst.operands[3].reg;
9660
9661 if (thumb_mode)
9662 {
9663 reject_bad_reg (Rd);
9664 reject_bad_reg (Rn);
9665 }
9666 else
9667 {
9668 constraint (Rd == REG_PC, BAD_PC);
9669 constraint (Rn == REG_PC, BAD_PC);
9670 }
9671
873f10f0
TC
9672 /* Only check the MRRC{2} variants. */
9673 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9674 {
9675 /* If Rd == Rn, error that the operation is
9676 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9677 constraint (Rd == Rn, BAD_OVERLAP);
9678 }
9679
c19d1205
ZW
9680 inst.instruction |= inst.operands[0].reg << 8;
9681 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
9682 inst.instruction |= Rd << 12;
9683 inst.instruction |= Rn << 16;
c19d1205 9684 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
9685}
9686
c19d1205
ZW
9687static void
9688do_cpsi (void)
9689{
9690 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
9691 if (inst.operands[1].present)
9692 {
9693 inst.instruction |= CPSI_MMOD;
9694 inst.instruction |= inst.operands[1].imm;
9695 }
c19d1205 9696}
b99bd4ef 9697
62b3e311
PB
9698static void
9699do_dbg (void)
9700{
9701 inst.instruction |= inst.operands[0].imm;
9702}
9703
eea54501
MGD
9704static void
9705do_div (void)
9706{
9707 unsigned Rd, Rn, Rm;
9708
9709 Rd = inst.operands[0].reg;
9710 Rn = (inst.operands[1].present
9711 ? inst.operands[1].reg : Rd);
9712 Rm = inst.operands[2].reg;
9713
9714 constraint ((Rd == REG_PC), BAD_PC);
9715 constraint ((Rn == REG_PC), BAD_PC);
9716 constraint ((Rm == REG_PC), BAD_PC);
9717
9718 inst.instruction |= Rd << 16;
9719 inst.instruction |= Rn << 0;
9720 inst.instruction |= Rm << 8;
9721}
9722
b99bd4ef 9723static void
c19d1205 9724do_it (void)
b99bd4ef 9725{
c19d1205 9726 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
9727 process it to do the validation as if in
9728 thumb mode, just in case the code gets
9729 assembled for thumb using the unified syntax. */
9730
c19d1205 9731 inst.size = 0;
e07e6e58
NC
9732 if (unified_syntax)
9733 {
5ee91343
AV
9734 set_pred_insn_type (IT_INSN);
9735 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9736 now_pred.cc = inst.operands[0].imm;
e07e6e58 9737 }
09d92015 9738}
b99bd4ef 9739
6530b175
NC
9740/* If there is only one register in the register list,
9741 then return its register number. Otherwise return -1. */
9742static int
9743only_one_reg_in_list (int range)
9744{
9745 int i = ffs (range) - 1;
9746 return (i > 15 || range != (1 << i)) ? -1 : i;
9747}
9748
09d92015 9749static void
6530b175 9750encode_ldmstm(int from_push_pop_mnem)
ea6ef066 9751{
c19d1205
ZW
9752 int base_reg = inst.operands[0].reg;
9753 int range = inst.operands[1].imm;
6530b175 9754 int one_reg;
ea6ef066 9755
c19d1205
ZW
9756 inst.instruction |= base_reg << 16;
9757 inst.instruction |= range;
ea6ef066 9758
c19d1205
ZW
9759 if (inst.operands[1].writeback)
9760 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 9761
c19d1205 9762 if (inst.operands[0].writeback)
ea6ef066 9763 {
c19d1205
ZW
9764 inst.instruction |= WRITE_BACK;
9765 /* Check for unpredictable uses of writeback. */
9766 if (inst.instruction & LOAD_BIT)
09d92015 9767 {
c19d1205
ZW
9768 /* Not allowed in LDM type 2. */
9769 if ((inst.instruction & LDM_TYPE_2_OR_3)
9770 && ((range & (1 << REG_PC)) == 0))
9771 as_warn (_("writeback of base register is UNPREDICTABLE"));
9772 /* Only allowed if base reg not in list for other types. */
9773 else if (range & (1 << base_reg))
9774 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9775 }
9776 else /* STM. */
9777 {
9778 /* Not allowed for type 2. */
9779 if (inst.instruction & LDM_TYPE_2_OR_3)
9780 as_warn (_("writeback of base register is UNPREDICTABLE"));
9781 /* Only allowed if base reg not in list, or first in list. */
9782 else if ((range & (1 << base_reg))
9783 && (range & ((1 << base_reg) - 1)))
9784 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 9785 }
ea6ef066 9786 }
6530b175
NC
9787
9788 /* If PUSH/POP has only one register, then use the A2 encoding. */
9789 one_reg = only_one_reg_in_list (range);
9790 if (from_push_pop_mnem && one_reg >= 0)
9791 {
9792 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9793
4f588891
NC
9794 if (is_push && one_reg == 13 /* SP */)
9795 /* PR 22483: The A2 encoding cannot be used when
9796 pushing the stack pointer as this is UNPREDICTABLE. */
9797 return;
9798
6530b175
NC
9799 inst.instruction &= A_COND_MASK;
9800 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9801 inst.instruction |= one_reg << 12;
9802 }
9803}
9804
9805static void
9806do_ldmstm (void)
9807{
9808 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
9809}
9810
c19d1205
ZW
9811/* ARMv5TE load-consecutive (argument parse)
9812 Mode is like LDRH.
9813
9814 LDRccD R, mode
9815 STRccD R, mode. */
9816
a737bd4d 9817static void
c19d1205 9818do_ldrd (void)
a737bd4d 9819{
c19d1205 9820 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 9821 _("first transfer register must be even"));
c19d1205
ZW
9822 constraint (inst.operands[1].present
9823 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 9824 _("can only transfer two consecutive registers"));
c19d1205
ZW
9825 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9826 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 9827
c19d1205
ZW
9828 if (!inst.operands[1].present)
9829 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 9830
c56791bb
RE
9831 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9832 register and the first register written; we have to diagnose
9833 overlap between the base and the second register written here. */
ea6ef066 9834
c56791bb
RE
9835 if (inst.operands[2].reg == inst.operands[1].reg
9836 && (inst.operands[2].writeback || inst.operands[2].postind))
9837 as_warn (_("base register written back, and overlaps "
9838 "second transfer register"));
b05fe5cf 9839
c56791bb
RE
9840 if (!(inst.instruction & V4_STR_BIT))
9841 {
c19d1205 9842 /* For an index-register load, the index register must not overlap the
c56791bb
RE
9843 destination (even if not write-back). */
9844 if (inst.operands[2].immisreg
9845 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9846 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9847 as_warn (_("index register overlaps transfer register"));
b05fe5cf 9848 }
c19d1205
ZW
9849 inst.instruction |= inst.operands[0].reg << 12;
9850 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
9851}
9852
9853static void
c19d1205 9854do_ldrex (void)
b05fe5cf 9855{
c19d1205
ZW
9856 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9857 || inst.operands[1].postind || inst.operands[1].writeback
9858 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9859 || inst.operands[1].negative
9860 /* This can arise if the programmer has written
9861 strex rN, rM, foo
9862 or if they have mistakenly used a register name as the last
9863 operand, eg:
9864 strex rN, rM, rX
9865 It is very difficult to distinguish between these two cases
9866 because "rX" might actually be a label. ie the register
9867 name has been occluded by a symbol of the same name. So we
9868 just generate a general 'bad addressing mode' type error
9869 message and leave it up to the programmer to discover the
9870 true cause and fix their mistake. */
9871 || (inst.operands[1].reg == REG_PC),
9872 BAD_ADDR_MODE);
b05fe5cf 9873
e2b0ab59
AV
9874 constraint (inst.relocs[0].exp.X_op != O_constant
9875 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9876 _("offset must be zero in ARM encoding"));
b05fe5cf 9877
5be8be5d
DG
9878 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9879
c19d1205
ZW
9880 inst.instruction |= inst.operands[0].reg << 12;
9881 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 9882 inst.relocs[0].type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9883}
9884
9885static void
c19d1205 9886do_ldrexd (void)
b05fe5cf 9887{
c19d1205
ZW
9888 constraint (inst.operands[0].reg % 2 != 0,
9889 _("even register required"));
9890 constraint (inst.operands[1].present
9891 && inst.operands[1].reg != inst.operands[0].reg + 1,
9892 _("can only load two consecutive registers"));
9893 /* If op 1 were present and equal to PC, this function wouldn't
9894 have been called in the first place. */
9895 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9896
c19d1205
ZW
9897 inst.instruction |= inst.operands[0].reg << 12;
9898 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9899}
9900
1be5fd2e
NC
9901/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9902 which is not a multiple of four is UNPREDICTABLE. */
9903static void
9904check_ldr_r15_aligned (void)
9905{
9906 constraint (!(inst.operands[1].immisreg)
9907 && (inst.operands[0].reg == REG_PC
9908 && inst.operands[1].reg == REG_PC
e2b0ab59 9909 && (inst.relocs[0].exp.X_add_number & 0x3)),
de194d85 9910 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9911}
9912
b05fe5cf 9913static void
c19d1205 9914do_ldst (void)
b05fe5cf 9915{
c19d1205
ZW
9916 inst.instruction |= inst.operands[0].reg << 12;
9917 if (!inst.operands[1].isreg)
8335d6aa 9918 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9919 return;
c19d1205 9920 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9921 check_ldr_r15_aligned ();
b05fe5cf
ZW
9922}
9923
9924static void
c19d1205 9925do_ldstt (void)
b05fe5cf 9926{
c19d1205
ZW
9927 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9928 reject [Rn,...]. */
9929 if (inst.operands[1].preind)
b05fe5cf 9930 {
e2b0ab59
AV
9931 constraint (inst.relocs[0].exp.X_op != O_constant
9932 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9933 _("this instruction requires a post-indexed address"));
b05fe5cf 9934
c19d1205
ZW
9935 inst.operands[1].preind = 0;
9936 inst.operands[1].postind = 1;
9937 inst.operands[1].writeback = 1;
b05fe5cf 9938 }
c19d1205
ZW
9939 inst.instruction |= inst.operands[0].reg << 12;
9940 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9941}
b05fe5cf 9942
c19d1205 9943/* Halfword and signed-byte load/store operations. */
b05fe5cf 9944
c19d1205
ZW
9945static void
9946do_ldstv4 (void)
9947{
ff4a8d2b 9948 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9949 inst.instruction |= inst.operands[0].reg << 12;
9950 if (!inst.operands[1].isreg)
8335d6aa 9951 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9952 return;
c19d1205 9953 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9954}
9955
9956static void
c19d1205 9957do_ldsttv4 (void)
b05fe5cf 9958{
c19d1205
ZW
9959 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9960 reject [Rn,...]. */
9961 if (inst.operands[1].preind)
b05fe5cf 9962 {
e2b0ab59
AV
9963 constraint (inst.relocs[0].exp.X_op != O_constant
9964 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 9965 _("this instruction requires a post-indexed address"));
b05fe5cf 9966
c19d1205
ZW
9967 inst.operands[1].preind = 0;
9968 inst.operands[1].postind = 1;
9969 inst.operands[1].writeback = 1;
b05fe5cf 9970 }
c19d1205
ZW
9971 inst.instruction |= inst.operands[0].reg << 12;
9972 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9973}
b05fe5cf 9974
c19d1205
ZW
9975/* Co-processor register load/store.
9976 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9977static void
9978do_lstc (void)
9979{
9980 inst.instruction |= inst.operands[0].reg << 8;
9981 inst.instruction |= inst.operands[1].reg << 12;
9982 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9983}
9984
b05fe5cf 9985static void
c19d1205 9986do_mlas (void)
b05fe5cf 9987{
8fb9d7b9 9988 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9989 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9990 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9991 && !(inst.instruction & 0x00400000))
8fb9d7b9 9992 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9993
c19d1205
ZW
9994 inst.instruction |= inst.operands[0].reg << 16;
9995 inst.instruction |= inst.operands[1].reg;
9996 inst.instruction |= inst.operands[2].reg << 8;
9997 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9998}
b05fe5cf 9999
c19d1205
ZW
10000static void
10001do_mov (void)
10002{
e2b0ab59
AV
10003 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10004 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
a9f02af8 10005 THUMB1_RELOC_ONLY);
c19d1205
ZW
10006 inst.instruction |= inst.operands[0].reg << 12;
10007 encode_arm_shifter_operand (1);
10008}
b05fe5cf 10009
c19d1205
ZW
10010/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10011static void
10012do_mov16 (void)
10013{
b6895b4f
PB
10014 bfd_vma imm;
10015 bfd_boolean top;
10016
10017 top = (inst.instruction & 0x00400000) != 0;
e2b0ab59 10018 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
33eaf5de 10019 _(":lower16: not allowed in this instruction"));
e2b0ab59 10020 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
33eaf5de 10021 _(":upper16: not allowed in this instruction"));
c19d1205 10022 inst.instruction |= inst.operands[0].reg << 12;
e2b0ab59 10023 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 10024 {
e2b0ab59 10025 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
10026 /* The value is in two pieces: 0:11, 16:19. */
10027 inst.instruction |= (imm & 0x00000fff);
10028 inst.instruction |= (imm & 0x0000f000) << 4;
10029 }
b05fe5cf 10030}
b99bd4ef 10031
037e8744
JB
10032static int
10033do_vfp_nsyn_mrs (void)
10034{
10035 if (inst.operands[0].isvec)
10036 {
10037 if (inst.operands[1].reg != 1)
477330fc 10038 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
10039 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10040 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10041 do_vfp_nsyn_opcode ("fmstat");
10042 }
10043 else if (inst.operands[1].isvec)
10044 do_vfp_nsyn_opcode ("fmrx");
10045 else
10046 return FAIL;
5f4273c7 10047
037e8744
JB
10048 return SUCCESS;
10049}
10050
10051static int
10052do_vfp_nsyn_msr (void)
10053{
10054 if (inst.operands[0].isvec)
10055 do_vfp_nsyn_opcode ("fmxr");
10056 else
10057 return FAIL;
10058
10059 return SUCCESS;
10060}
10061
f7c21dc7
NC
10062static void
10063do_vmrs (void)
10064{
10065 unsigned Rt = inst.operands[0].reg;
fa94de6b 10066
16d02dc9 10067 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
10068 {
10069 inst.error = BAD_SP;
10070 return;
10071 }
10072
ba6cd17f
SD
10073 switch (inst.operands[1].reg)
10074 {
10075 /* MVFR2 is only valid for Armv8-A. */
10076 case 5:
10077 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10078 _(BAD_FPU));
10079 break;
10080
10081 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10082 case 1: /* fpscr. */
10083 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10084 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10085 _(BAD_FPU));
10086 break;
10087
10088 case 14: /* fpcxt_ns. */
10089 case 15: /* fpcxt_s. */
10090 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10091 _("selected processor does not support instruction"));
10092 break;
10093
10094 case 2: /* fpscr_nzcvqc. */
10095 case 12: /* vpr. */
10096 case 13: /* p0. */
10097 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10098 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10099 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10100 _("selected processor does not support instruction"));
10101 if (inst.operands[0].reg != 2
10102 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10103 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10104 break;
10105
10106 default:
10107 break;
10108 }
40c7d507 10109
f7c21dc7 10110 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 10111 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
10112 {
10113 inst.error = BAD_PC;
10114 return;
10115 }
10116
16d02dc9
JB
10117 /* If we get through parsing the register name, we just insert the number
10118 generated into the instruction without further validation. */
10119 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
10120 inst.instruction |= (Rt << 12);
10121}
10122
10123static void
10124do_vmsr (void)
10125{
10126 unsigned Rt = inst.operands[1].reg;
fa94de6b 10127
f7c21dc7
NC
10128 if (thumb_mode)
10129 reject_bad_reg (Rt);
10130 else if (Rt == REG_PC)
10131 {
10132 inst.error = BAD_PC;
10133 return;
10134 }
10135
ba6cd17f
SD
10136 switch (inst.operands[0].reg)
10137 {
10138 /* MVFR2 is only valid for Armv8-A. */
10139 case 5:
10140 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10141 _(BAD_FPU));
10142 break;
10143
10144 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10145 case 1: /* fpcr. */
10146 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10147 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10148 _(BAD_FPU));
10149 break;
10150
10151 case 14: /* fpcxt_ns. */
10152 case 15: /* fpcxt_s. */
10153 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10154 _("selected processor does not support instruction"));
10155 break;
10156
10157 case 2: /* fpscr_nzcvqc. */
10158 case 12: /* vpr. */
10159 case 13: /* p0. */
10160 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10161 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10162 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10163 _("selected processor does not support instruction"));
10164 if (inst.operands[0].reg != 2
10165 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10166 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10167 break;
10168
10169 default:
10170 break;
10171 }
40c7d507 10172
16d02dc9
JB
10173 /* If we get through parsing the register name, we just insert the number
10174 generated into the instruction without further validation. */
10175 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
10176 inst.instruction |= (Rt << 12);
10177}
10178
b99bd4ef 10179static void
c19d1205 10180do_mrs (void)
b99bd4ef 10181{
90ec0d68
MGD
10182 unsigned br;
10183
037e8744
JB
10184 if (do_vfp_nsyn_mrs () == SUCCESS)
10185 return;
10186
ff4a8d2b 10187 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 10188 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
10189
10190 if (inst.operands[1].isreg)
10191 {
10192 br = inst.operands[1].reg;
806ab1c0 10193 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
10194 as_bad (_("bad register for mrs"));
10195 }
10196 else
10197 {
10198 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10199 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10200 != (PSR_c|PSR_f),
d2cd1205 10201 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
10202 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10203 }
10204
10205 inst.instruction |= br;
c19d1205 10206}
b99bd4ef 10207
c19d1205
ZW
10208/* Two possible forms:
10209 "{C|S}PSR_<field>, Rm",
10210 "{C|S}PSR_f, #expression". */
b99bd4ef 10211
c19d1205
ZW
10212static void
10213do_msr (void)
10214{
037e8744
JB
10215 if (do_vfp_nsyn_msr () == SUCCESS)
10216 return;
10217
c19d1205
ZW
10218 inst.instruction |= inst.operands[0].imm;
10219 if (inst.operands[1].isreg)
10220 inst.instruction |= inst.operands[1].reg;
10221 else
b99bd4ef 10222 {
c19d1205 10223 inst.instruction |= INST_IMMEDIATE;
e2b0ab59
AV
10224 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10225 inst.relocs[0].pc_rel = 0;
b99bd4ef 10226 }
b99bd4ef
NC
10227}
10228
c19d1205
ZW
10229static void
10230do_mul (void)
a737bd4d 10231{
ff4a8d2b
NC
10232 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10233
c19d1205
ZW
10234 if (!inst.operands[2].present)
10235 inst.operands[2].reg = inst.operands[0].reg;
10236 inst.instruction |= inst.operands[0].reg << 16;
10237 inst.instruction |= inst.operands[1].reg;
10238 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 10239
8fb9d7b9
MS
10240 if (inst.operands[0].reg == inst.operands[1].reg
10241 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10242 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
10243}
10244
c19d1205
ZW
10245/* Long Multiply Parser
10246 UMULL RdLo, RdHi, Rm, Rs
10247 SMULL RdLo, RdHi, Rm, Rs
10248 UMLAL RdLo, RdHi, Rm, Rs
10249 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
10250
10251static void
c19d1205 10252do_mull (void)
b99bd4ef 10253{
c19d1205
ZW
10254 inst.instruction |= inst.operands[0].reg << 12;
10255 inst.instruction |= inst.operands[1].reg << 16;
10256 inst.instruction |= inst.operands[2].reg;
10257 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 10258
682b27ad
PB
10259 /* rdhi and rdlo must be different. */
10260 if (inst.operands[0].reg == inst.operands[1].reg)
10261 as_tsktsk (_("rdhi and rdlo must be different"));
10262
10263 /* rdhi, rdlo and rm must all be different before armv6. */
10264 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 10265 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 10266 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
10267 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10268}
b99bd4ef 10269
c19d1205
ZW
10270static void
10271do_nop (void)
10272{
e7495e45
NS
10273 if (inst.operands[0].present
10274 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
10275 {
10276 /* Architectural NOP hints are CPSR sets with no bits selected. */
10277 inst.instruction &= 0xf0000000;
e7495e45
NS
10278 inst.instruction |= 0x0320f000;
10279 if (inst.operands[0].present)
10280 inst.instruction |= inst.operands[0].imm;
c19d1205 10281 }
b99bd4ef
NC
10282}
10283
c19d1205
ZW
10284/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10285 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10286 Condition defaults to COND_ALWAYS.
10287 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
10288
10289static void
c19d1205 10290do_pkhbt (void)
b99bd4ef 10291{
c19d1205
ZW
10292 inst.instruction |= inst.operands[0].reg << 12;
10293 inst.instruction |= inst.operands[1].reg << 16;
10294 inst.instruction |= inst.operands[2].reg;
10295 if (inst.operands[3].present)
10296 encode_arm_shift (3);
10297}
b99bd4ef 10298
c19d1205 10299/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 10300
c19d1205
ZW
10301static void
10302do_pkhtb (void)
10303{
10304 if (!inst.operands[3].present)
b99bd4ef 10305 {
c19d1205
ZW
10306 /* If the shift specifier is omitted, turn the instruction
10307 into pkhbt rd, rm, rn. */
10308 inst.instruction &= 0xfff00010;
10309 inst.instruction |= inst.operands[0].reg << 12;
10310 inst.instruction |= inst.operands[1].reg;
10311 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10312 }
10313 else
10314 {
c19d1205
ZW
10315 inst.instruction |= inst.operands[0].reg << 12;
10316 inst.instruction |= inst.operands[1].reg << 16;
10317 inst.instruction |= inst.operands[2].reg;
10318 encode_arm_shift (3);
b99bd4ef
NC
10319 }
10320}
10321
c19d1205 10322/* ARMv5TE: Preload-Cache
60e5ef9f 10323 MP Extensions: Preload for write
c19d1205 10324
60e5ef9f 10325 PLD(W) <addr_mode>
c19d1205
ZW
10326
10327 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
10328
10329static void
c19d1205 10330do_pld (void)
b99bd4ef 10331{
c19d1205
ZW
10332 constraint (!inst.operands[0].isreg,
10333 _("'[' expected after PLD mnemonic"));
10334 constraint (inst.operands[0].postind,
10335 _("post-indexed expression used in preload instruction"));
10336 constraint (inst.operands[0].writeback,
10337 _("writeback used in preload instruction"));
10338 constraint (!inst.operands[0].preind,
10339 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
10340 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10341}
b99bd4ef 10342
62b3e311
PB
10343/* ARMv7: PLI <addr_mode> */
10344static void
10345do_pli (void)
10346{
10347 constraint (!inst.operands[0].isreg,
10348 _("'[' expected after PLI mnemonic"));
10349 constraint (inst.operands[0].postind,
10350 _("post-indexed expression used in preload instruction"));
10351 constraint (inst.operands[0].writeback,
10352 _("writeback used in preload instruction"));
10353 constraint (!inst.operands[0].preind,
10354 _("unindexed addressing used in preload instruction"));
10355 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10356 inst.instruction &= ~PRE_INDEX;
10357}
10358
c19d1205
ZW
10359static void
10360do_push_pop (void)
10361{
5e0d7f77
MP
10362 constraint (inst.operands[0].writeback,
10363 _("push/pop do not support {reglist}^"));
c19d1205
ZW
10364 inst.operands[1] = inst.operands[0];
10365 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10366 inst.operands[0].isreg = 1;
10367 inst.operands[0].writeback = 1;
10368 inst.operands[0].reg = REG_SP;
6530b175 10369 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 10370}
b99bd4ef 10371
c19d1205
ZW
10372/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10373 word at the specified address and the following word
10374 respectively.
10375 Unconditionally executed.
10376 Error if Rn is R15. */
b99bd4ef 10377
c19d1205
ZW
10378static void
10379do_rfe (void)
10380{
10381 inst.instruction |= inst.operands[0].reg << 16;
10382 if (inst.operands[0].writeback)
10383 inst.instruction |= WRITE_BACK;
10384}
b99bd4ef 10385
c19d1205 10386/* ARM V6 ssat (argument parse). */
b99bd4ef 10387
c19d1205
ZW
10388static void
10389do_ssat (void)
10390{
10391 inst.instruction |= inst.operands[0].reg << 12;
10392 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10393 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10394
c19d1205
ZW
10395 if (inst.operands[3].present)
10396 encode_arm_shift (3);
b99bd4ef
NC
10397}
10398
c19d1205 10399/* ARM V6 usat (argument parse). */
b99bd4ef
NC
10400
10401static void
c19d1205 10402do_usat (void)
b99bd4ef 10403{
c19d1205
ZW
10404 inst.instruction |= inst.operands[0].reg << 12;
10405 inst.instruction |= inst.operands[1].imm << 16;
10406 inst.instruction |= inst.operands[2].reg;
b99bd4ef 10407
c19d1205
ZW
10408 if (inst.operands[3].present)
10409 encode_arm_shift (3);
b99bd4ef
NC
10410}
10411
c19d1205 10412/* ARM V6 ssat16 (argument parse). */
09d92015
MM
10413
10414static void
c19d1205 10415do_ssat16 (void)
09d92015 10416{
c19d1205
ZW
10417 inst.instruction |= inst.operands[0].reg << 12;
10418 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10419 inst.instruction |= inst.operands[2].reg;
09d92015
MM
10420}
10421
c19d1205
ZW
10422static void
10423do_usat16 (void)
a737bd4d 10424{
c19d1205
ZW
10425 inst.instruction |= inst.operands[0].reg << 12;
10426 inst.instruction |= inst.operands[1].imm << 16;
10427 inst.instruction |= inst.operands[2].reg;
10428}
a737bd4d 10429
c19d1205
ZW
10430/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10431 preserving the other bits.
a737bd4d 10432
c19d1205
ZW
10433 setend <endian_specifier>, where <endian_specifier> is either
10434 BE or LE. */
a737bd4d 10435
c19d1205
ZW
10436static void
10437do_setend (void)
10438{
12e37cbc
MGD
10439 if (warn_on_deprecated
10440 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 10441 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 10442
c19d1205
ZW
10443 if (inst.operands[0].imm)
10444 inst.instruction |= 0x200;
a737bd4d
NC
10445}
10446
10447static void
c19d1205 10448do_shift (void)
a737bd4d 10449{
c19d1205
ZW
10450 unsigned int Rm = (inst.operands[1].present
10451 ? inst.operands[1].reg
10452 : inst.operands[0].reg);
a737bd4d 10453
c19d1205
ZW
10454 inst.instruction |= inst.operands[0].reg << 12;
10455 inst.instruction |= Rm;
10456 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 10457 {
c19d1205
ZW
10458 inst.instruction |= inst.operands[2].reg << 8;
10459 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
10460 /* PR 12854: Error on extraneous shifts. */
10461 constraint (inst.operands[2].shifted,
10462 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
10463 }
10464 else
e2b0ab59 10465 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
10466}
10467
09d92015 10468static void
3eb17e6b 10469do_smc (void)
09d92015 10470{
ba85f98c
BW
10471 unsigned int value = inst.relocs[0].exp.X_add_number;
10472 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10473
e2b0ab59
AV
10474 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10475 inst.relocs[0].pc_rel = 0;
09d92015
MM
10476}
10477
90ec0d68
MGD
10478static void
10479do_hvc (void)
10480{
e2b0ab59
AV
10481 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10482 inst.relocs[0].pc_rel = 0;
90ec0d68
MGD
10483}
10484
09d92015 10485static void
c19d1205 10486do_swi (void)
09d92015 10487{
e2b0ab59
AV
10488 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10489 inst.relocs[0].pc_rel = 0;
09d92015
MM
10490}
10491
ddfded2f
MW
10492static void
10493do_setpan (void)
10494{
10495 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10496 _("selected processor does not support SETPAN instruction"));
10497
10498 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10499}
10500
10501static void
10502do_t_setpan (void)
10503{
10504 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10505 _("selected processor does not support SETPAN instruction"));
10506
10507 inst.instruction |= (inst.operands[0].imm << 3);
10508}
10509
c19d1205
ZW
10510/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10511 SMLAxy{cond} Rd,Rm,Rs,Rn
10512 SMLAWy{cond} Rd,Rm,Rs,Rn
10513 Error if any register is R15. */
e16bb312 10514
c19d1205
ZW
10515static void
10516do_smla (void)
e16bb312 10517{
c19d1205
ZW
10518 inst.instruction |= inst.operands[0].reg << 16;
10519 inst.instruction |= inst.operands[1].reg;
10520 inst.instruction |= inst.operands[2].reg << 8;
10521 inst.instruction |= inst.operands[3].reg << 12;
10522}
a737bd4d 10523
c19d1205
ZW
10524/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10525 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10526 Error if any register is R15.
10527 Warning if Rdlo == Rdhi. */
a737bd4d 10528
c19d1205
ZW
10529static void
10530do_smlal (void)
10531{
10532 inst.instruction |= inst.operands[0].reg << 12;
10533 inst.instruction |= inst.operands[1].reg << 16;
10534 inst.instruction |= inst.operands[2].reg;
10535 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 10536
c19d1205
ZW
10537 if (inst.operands[0].reg == inst.operands[1].reg)
10538 as_tsktsk (_("rdhi and rdlo must be different"));
10539}
a737bd4d 10540
c19d1205
ZW
10541/* ARM V5E (El Segundo) signed-multiply (argument parse)
10542 SMULxy{cond} Rd,Rm,Rs
10543 Error if any register is R15. */
a737bd4d 10544
c19d1205
ZW
10545static void
10546do_smul (void)
10547{
10548 inst.instruction |= inst.operands[0].reg << 16;
10549 inst.instruction |= inst.operands[1].reg;
10550 inst.instruction |= inst.operands[2].reg << 8;
10551}
a737bd4d 10552
b6702015
PB
10553/* ARM V6 srs (argument parse). The variable fields in the encoding are
10554 the same for both ARM and Thumb-2. */
a737bd4d 10555
c19d1205
ZW
10556static void
10557do_srs (void)
10558{
b6702015
PB
10559 int reg;
10560
10561 if (inst.operands[0].present)
10562 {
10563 reg = inst.operands[0].reg;
fdfde340 10564 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
10565 }
10566 else
fdfde340 10567 reg = REG_SP;
b6702015
PB
10568
10569 inst.instruction |= reg << 16;
10570 inst.instruction |= inst.operands[1].imm;
10571 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
10572 inst.instruction |= WRITE_BACK;
10573}
a737bd4d 10574
c19d1205 10575/* ARM V6 strex (argument parse). */
a737bd4d 10576
c19d1205
ZW
10577static void
10578do_strex (void)
10579{
10580 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10581 || inst.operands[2].postind || inst.operands[2].writeback
10582 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
10583 || inst.operands[2].negative
10584 /* See comment in do_ldrex(). */
10585 || (inst.operands[2].reg == REG_PC),
10586 BAD_ADDR_MODE);
a737bd4d 10587
c19d1205
ZW
10588 constraint (inst.operands[0].reg == inst.operands[1].reg
10589 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 10590
e2b0ab59
AV
10591 constraint (inst.relocs[0].exp.X_op != O_constant
10592 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 10593 _("offset must be zero in ARM encoding"));
a737bd4d 10594
c19d1205
ZW
10595 inst.instruction |= inst.operands[0].reg << 12;
10596 inst.instruction |= inst.operands[1].reg;
10597 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 10598 inst.relocs[0].type = BFD_RELOC_UNUSED;
e16bb312
NC
10599}
10600
877807f8
NC
10601static void
10602do_t_strexbh (void)
10603{
10604 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10605 || inst.operands[2].postind || inst.operands[2].writeback
10606 || inst.operands[2].immisreg || inst.operands[2].shifted
10607 || inst.operands[2].negative,
10608 BAD_ADDR_MODE);
10609
10610 constraint (inst.operands[0].reg == inst.operands[1].reg
10611 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10612
10613 do_rm_rd_rn ();
10614}
10615
e16bb312 10616static void
c19d1205 10617do_strexd (void)
e16bb312 10618{
c19d1205
ZW
10619 constraint (inst.operands[1].reg % 2 != 0,
10620 _("even register required"));
10621 constraint (inst.operands[2].present
10622 && inst.operands[2].reg != inst.operands[1].reg + 1,
10623 _("can only store two consecutive registers"));
10624 /* If op 2 were present and equal to PC, this function wouldn't
10625 have been called in the first place. */
10626 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 10627
c19d1205
ZW
10628 constraint (inst.operands[0].reg == inst.operands[1].reg
10629 || inst.operands[0].reg == inst.operands[1].reg + 1
10630 || inst.operands[0].reg == inst.operands[3].reg,
10631 BAD_OVERLAP);
e16bb312 10632
c19d1205
ZW
10633 inst.instruction |= inst.operands[0].reg << 12;
10634 inst.instruction |= inst.operands[1].reg;
10635 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
10636}
10637
9eb6c0f1
MGD
10638/* ARM V8 STRL. */
10639static void
4b8c8c02 10640do_stlex (void)
9eb6c0f1
MGD
10641{
10642 constraint (inst.operands[0].reg == inst.operands[1].reg
10643 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10644
10645 do_rd_rm_rn ();
10646}
10647
10648static void
4b8c8c02 10649do_t_stlex (void)
9eb6c0f1
MGD
10650{
10651 constraint (inst.operands[0].reg == inst.operands[1].reg
10652 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10653
10654 do_rm_rd_rn ();
10655}
10656
c19d1205
ZW
10657/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10658 extends it to 32-bits, and adds the result to a value in another
10659 register. You can specify a rotation by 0, 8, 16, or 24 bits
10660 before extracting the 16-bit value.
10661 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10662 Condition defaults to COND_ALWAYS.
10663 Error if any register uses R15. */
10664
e16bb312 10665static void
c19d1205 10666do_sxtah (void)
e16bb312 10667{
c19d1205
ZW
10668 inst.instruction |= inst.operands[0].reg << 12;
10669 inst.instruction |= inst.operands[1].reg << 16;
10670 inst.instruction |= inst.operands[2].reg;
10671 inst.instruction |= inst.operands[3].imm << 10;
10672}
e16bb312 10673
c19d1205 10674/* ARM V6 SXTH.
e16bb312 10675
c19d1205
ZW
10676 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10677 Condition defaults to COND_ALWAYS.
10678 Error if any register uses R15. */
e16bb312
NC
10679
10680static void
c19d1205 10681do_sxth (void)
e16bb312 10682{
c19d1205
ZW
10683 inst.instruction |= inst.operands[0].reg << 12;
10684 inst.instruction |= inst.operands[1].reg;
10685 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 10686}
c19d1205
ZW
10687\f
10688/* VFP instructions. In a logical order: SP variant first, monad
10689 before dyad, arithmetic then move then load/store. */
e16bb312
NC
10690
10691static void
c19d1205 10692do_vfp_sp_monadic (void)
e16bb312 10693{
57785aa2
AV
10694 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10695 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10696 _(BAD_FPU));
10697
5287ad62
JB
10698 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10700}
10701
10702static void
c19d1205 10703do_vfp_sp_dyadic (void)
e16bb312 10704{
5287ad62
JB
10705 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10706 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10707 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10708}
10709
10710static void
c19d1205 10711do_vfp_sp_compare_z (void)
e16bb312 10712{
5287ad62 10713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
10714}
10715
10716static void
c19d1205 10717do_vfp_dp_sp_cvt (void)
e16bb312 10718{
5287ad62
JB
10719 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10720 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
10721}
10722
10723static void
c19d1205 10724do_vfp_sp_dp_cvt (void)
e16bb312 10725{
5287ad62
JB
10726 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10727 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
10728}
10729
10730static void
c19d1205 10731do_vfp_reg_from_sp (void)
e16bb312 10732{
57785aa2
AV
10733 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10734 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10735 _(BAD_FPU));
10736
c19d1205 10737 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 10738 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
10739}
10740
10741static void
c19d1205 10742do_vfp_reg2_from_sp2 (void)
e16bb312 10743{
c19d1205
ZW
10744 constraint (inst.operands[2].imm != 2,
10745 _("only two consecutive VFP SP registers allowed here"));
10746 inst.instruction |= inst.operands[0].reg << 12;
10747 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 10748 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
10749}
10750
10751static void
c19d1205 10752do_vfp_sp_from_reg (void)
e16bb312 10753{
57785aa2
AV
10754 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10755 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10756 _(BAD_FPU));
10757
5287ad62 10758 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 10759 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
10760}
10761
10762static void
c19d1205 10763do_vfp_sp2_from_reg2 (void)
e16bb312 10764{
c19d1205
ZW
10765 constraint (inst.operands[0].imm != 2,
10766 _("only two consecutive VFP SP registers allowed here"));
5287ad62 10767 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
10768 inst.instruction |= inst.operands[1].reg << 12;
10769 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
10770}
10771
10772static void
c19d1205 10773do_vfp_sp_ldst (void)
e16bb312 10774{
5287ad62 10775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 10776 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10777}
10778
10779static void
c19d1205 10780do_vfp_dp_ldst (void)
e16bb312 10781{
5287ad62 10782 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 10783 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
10784}
10785
c19d1205 10786
e16bb312 10787static void
c19d1205 10788vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10789{
c19d1205
ZW
10790 if (inst.operands[0].writeback)
10791 inst.instruction |= WRITE_BACK;
10792 else
10793 constraint (ldstm_type != VFP_LDSTMIA,
10794 _("this addressing mode requires base-register writeback"));
10795 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10796 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 10797 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
10798}
10799
10800static void
c19d1205 10801vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 10802{
c19d1205 10803 int count;
e16bb312 10804
c19d1205
ZW
10805 if (inst.operands[0].writeback)
10806 inst.instruction |= WRITE_BACK;
10807 else
10808 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10809 _("this addressing mode requires base-register writeback"));
e16bb312 10810
c19d1205 10811 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 10812 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 10813
c19d1205
ZW
10814 count = inst.operands[1].imm << 1;
10815 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10816 count += 1;
e16bb312 10817
c19d1205 10818 inst.instruction |= count;
e16bb312
NC
10819}
10820
10821static void
c19d1205 10822do_vfp_sp_ldstmia (void)
e16bb312 10823{
c19d1205 10824 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10825}
10826
10827static void
c19d1205 10828do_vfp_sp_ldstmdb (void)
e16bb312 10829{
c19d1205 10830 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10831}
10832
10833static void
c19d1205 10834do_vfp_dp_ldstmia (void)
e16bb312 10835{
c19d1205 10836 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
10837}
10838
10839static void
c19d1205 10840do_vfp_dp_ldstmdb (void)
e16bb312 10841{
c19d1205 10842 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
10843}
10844
10845static void
c19d1205 10846do_vfp_xp_ldstmia (void)
e16bb312 10847{
c19d1205
ZW
10848 vfp_dp_ldstm (VFP_LDSTMIAX);
10849}
e16bb312 10850
c19d1205
ZW
10851static void
10852do_vfp_xp_ldstmdb (void)
10853{
10854 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 10855}
5287ad62
JB
10856
10857static void
10858do_vfp_dp_rd_rm (void)
10859{
57785aa2
AV
10860 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10861 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10862 _(BAD_FPU));
10863
5287ad62
JB
10864 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10865 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10866}
10867
10868static void
10869do_vfp_dp_rn_rd (void)
10870{
10871 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10872 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10873}
10874
10875static void
10876do_vfp_dp_rd_rn (void)
10877{
10878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10879 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10880}
10881
10882static void
10883do_vfp_dp_rd_rn_rm (void)
10884{
57785aa2
AV
10885 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10886 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10887 _(BAD_FPU));
10888
5287ad62
JB
10889 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10890 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10891 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10892}
10893
10894static void
10895do_vfp_dp_rd (void)
10896{
10897 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10898}
10899
10900static void
10901do_vfp_dp_rm_rd_rn (void)
10902{
57785aa2
AV
10903 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10904 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10905 _(BAD_FPU));
10906
5287ad62
JB
10907 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10908 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10909 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10910}
10911
10912/* VFPv3 instructions. */
10913static void
10914do_vfp_sp_const (void)
10915{
10916 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
10917 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10918 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10919}
10920
10921static void
10922do_vfp_dp_const (void)
10923{
10924 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
10925 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10926 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
10927}
10928
10929static void
10930vfp_conv (int srcsize)
10931{
5f1af56b
MGD
10932 int immbits = srcsize - inst.operands[1].imm;
10933
fa94de6b
RM
10934 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10935 {
5f1af56b 10936 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 10937 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
10938 inst.error = _("immediate value out of range, expected range [0, 16]");
10939 return;
10940 }
fa94de6b 10941 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
10942 {
10943 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 10944 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
10945 inst.error = _("immediate value out of range, expected range [1, 32]");
10946 return;
10947 }
10948
5287ad62
JB
10949 inst.instruction |= (immbits & 1) << 5;
10950 inst.instruction |= (immbits >> 1);
10951}
10952
10953static void
10954do_vfp_sp_conv_16 (void)
10955{
10956 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10957 vfp_conv (16);
10958}
10959
10960static void
10961do_vfp_dp_conv_16 (void)
10962{
10963 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10964 vfp_conv (16);
10965}
10966
10967static void
10968do_vfp_sp_conv_32 (void)
10969{
10970 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10971 vfp_conv (32);
10972}
10973
10974static void
10975do_vfp_dp_conv_32 (void)
10976{
10977 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10978 vfp_conv (32);
10979}
c19d1205
ZW
10980\f
10981/* FPA instructions. Also in a logical order. */
e16bb312 10982
c19d1205
ZW
10983static void
10984do_fpa_cmp (void)
10985{
10986 inst.instruction |= inst.operands[0].reg << 16;
10987 inst.instruction |= inst.operands[1].reg;
10988}
b99bd4ef
NC
10989
10990static void
c19d1205 10991do_fpa_ldmstm (void)
b99bd4ef 10992{
c19d1205
ZW
10993 inst.instruction |= inst.operands[0].reg << 12;
10994 switch (inst.operands[1].imm)
10995 {
10996 case 1: inst.instruction |= CP_T_X; break;
10997 case 2: inst.instruction |= CP_T_Y; break;
10998 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10999 case 4: break;
11000 default: abort ();
11001 }
b99bd4ef 11002
c19d1205
ZW
11003 if (inst.instruction & (PRE_INDEX | INDEX_UP))
11004 {
11005 /* The instruction specified "ea" or "fd", so we can only accept
11006 [Rn]{!}. The instruction does not really support stacking or
11007 unstacking, so we have to emulate these by setting appropriate
11008 bits and offsets. */
e2b0ab59
AV
11009 constraint (inst.relocs[0].exp.X_op != O_constant
11010 || inst.relocs[0].exp.X_add_number != 0,
c19d1205 11011 _("this instruction does not support indexing"));
b99bd4ef 11012
c19d1205 11013 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
e2b0ab59 11014 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 11015
c19d1205 11016 if (!(inst.instruction & INDEX_UP))
e2b0ab59 11017 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
b99bd4ef 11018
c19d1205
ZW
11019 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11020 {
11021 inst.operands[2].preind = 0;
11022 inst.operands[2].postind = 1;
11023 }
11024 }
b99bd4ef 11025
c19d1205 11026 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 11027}
c19d1205
ZW
11028\f
11029/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 11030
c19d1205
ZW
11031static void
11032do_iwmmxt_tandorc (void)
11033{
11034 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11035}
b99bd4ef 11036
c19d1205
ZW
11037static void
11038do_iwmmxt_textrc (void)
11039{
11040 inst.instruction |= inst.operands[0].reg << 12;
11041 inst.instruction |= inst.operands[1].imm;
11042}
b99bd4ef
NC
11043
11044static void
c19d1205 11045do_iwmmxt_textrm (void)
b99bd4ef 11046{
c19d1205
ZW
11047 inst.instruction |= inst.operands[0].reg << 12;
11048 inst.instruction |= inst.operands[1].reg << 16;
11049 inst.instruction |= inst.operands[2].imm;
11050}
b99bd4ef 11051
c19d1205
ZW
11052static void
11053do_iwmmxt_tinsr (void)
11054{
11055 inst.instruction |= inst.operands[0].reg << 16;
11056 inst.instruction |= inst.operands[1].reg << 12;
11057 inst.instruction |= inst.operands[2].imm;
11058}
b99bd4ef 11059
c19d1205
ZW
11060static void
11061do_iwmmxt_tmia (void)
11062{
11063 inst.instruction |= inst.operands[0].reg << 5;
11064 inst.instruction |= inst.operands[1].reg;
11065 inst.instruction |= inst.operands[2].reg << 12;
11066}
b99bd4ef 11067
c19d1205
ZW
11068static void
11069do_iwmmxt_waligni (void)
11070{
11071 inst.instruction |= inst.operands[0].reg << 12;
11072 inst.instruction |= inst.operands[1].reg << 16;
11073 inst.instruction |= inst.operands[2].reg;
11074 inst.instruction |= inst.operands[3].imm << 20;
11075}
b99bd4ef 11076
2d447fca
JM
11077static void
11078do_iwmmxt_wmerge (void)
11079{
11080 inst.instruction |= inst.operands[0].reg << 12;
11081 inst.instruction |= inst.operands[1].reg << 16;
11082 inst.instruction |= inst.operands[2].reg;
11083 inst.instruction |= inst.operands[3].imm << 21;
11084}
11085
c19d1205
ZW
11086static void
11087do_iwmmxt_wmov (void)
11088{
11089 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11090 inst.instruction |= inst.operands[0].reg << 12;
11091 inst.instruction |= inst.operands[1].reg << 16;
11092 inst.instruction |= inst.operands[1].reg;
11093}
b99bd4ef 11094
c19d1205
ZW
11095static void
11096do_iwmmxt_wldstbh (void)
11097{
8f06b2d8 11098 int reloc;
c19d1205 11099 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
11100 if (thumb_mode)
11101 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11102 else
11103 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11104 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
11105}
11106
c19d1205
ZW
11107static void
11108do_iwmmxt_wldstw (void)
11109{
11110 /* RIWR_RIWC clears .isreg for a control register. */
11111 if (!inst.operands[0].isreg)
11112 {
11113 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11114 inst.instruction |= 0xf0000000;
11115 }
b99bd4ef 11116
c19d1205
ZW
11117 inst.instruction |= inst.operands[0].reg << 12;
11118 encode_arm_cp_address (1, TRUE, TRUE, 0);
11119}
b99bd4ef
NC
11120
11121static void
c19d1205 11122do_iwmmxt_wldstd (void)
b99bd4ef 11123{
c19d1205 11124 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
11125 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11126 && inst.operands[1].immisreg)
11127 {
11128 inst.instruction &= ~0x1a000ff;
eff0bc54 11129 inst.instruction |= (0xfU << 28);
2d447fca
JM
11130 if (inst.operands[1].preind)
11131 inst.instruction |= PRE_INDEX;
11132 if (!inst.operands[1].negative)
11133 inst.instruction |= INDEX_UP;
11134 if (inst.operands[1].writeback)
11135 inst.instruction |= WRITE_BACK;
11136 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 11137 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
2d447fca
JM
11138 inst.instruction |= inst.operands[1].imm;
11139 }
11140 else
11141 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 11142}
b99bd4ef 11143
c19d1205
ZW
11144static void
11145do_iwmmxt_wshufh (void)
11146{
11147 inst.instruction |= inst.operands[0].reg << 12;
11148 inst.instruction |= inst.operands[1].reg << 16;
11149 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11150 inst.instruction |= (inst.operands[2].imm & 0x0f);
11151}
b99bd4ef 11152
c19d1205
ZW
11153static void
11154do_iwmmxt_wzero (void)
11155{
11156 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11157 inst.instruction |= inst.operands[0].reg;
11158 inst.instruction |= inst.operands[0].reg << 12;
11159 inst.instruction |= inst.operands[0].reg << 16;
11160}
2d447fca
JM
11161
11162static void
11163do_iwmmxt_wrwrwr_or_imm5 (void)
11164{
11165 if (inst.operands[2].isreg)
11166 do_rd_rn_rm ();
11167 else {
11168 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11169 _("immediate operand requires iWMMXt2"));
11170 do_rd_rn ();
11171 if (inst.operands[2].imm == 0)
11172 {
11173 switch ((inst.instruction >> 20) & 0xf)
11174 {
11175 case 4:
11176 case 5:
11177 case 6:
5f4273c7 11178 case 7:
2d447fca
JM
11179 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11180 inst.operands[2].imm = 16;
11181 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11182 break;
11183 case 8:
11184 case 9:
11185 case 10:
11186 case 11:
11187 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11188 inst.operands[2].imm = 32;
11189 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11190 break;
11191 case 12:
11192 case 13:
11193 case 14:
11194 case 15:
11195 {
11196 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11197 unsigned long wrn;
11198 wrn = (inst.instruction >> 16) & 0xf;
11199 inst.instruction &= 0xff0fff0f;
11200 inst.instruction |= wrn;
11201 /* Bail out here; the instruction is now assembled. */
11202 return;
11203 }
11204 }
11205 }
11206 /* Map 32 -> 0, etc. */
11207 inst.operands[2].imm &= 0x1f;
eff0bc54 11208 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
11209 }
11210}
c19d1205
ZW
11211\f
11212/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11213 operations first, then control, shift, and load/store. */
b99bd4ef 11214
c19d1205 11215/* Insns like "foo X,Y,Z". */
b99bd4ef 11216
c19d1205
ZW
11217static void
11218do_mav_triple (void)
11219{
11220 inst.instruction |= inst.operands[0].reg << 16;
11221 inst.instruction |= inst.operands[1].reg;
11222 inst.instruction |= inst.operands[2].reg << 12;
11223}
b99bd4ef 11224
c19d1205
ZW
11225/* Insns like "foo W,X,Y,Z".
11226 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 11227
c19d1205
ZW
11228static void
11229do_mav_quad (void)
11230{
11231 inst.instruction |= inst.operands[0].reg << 5;
11232 inst.instruction |= inst.operands[1].reg << 12;
11233 inst.instruction |= inst.operands[2].reg << 16;
11234 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
11235}
11236
c19d1205
ZW
11237/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11238static void
11239do_mav_dspsc (void)
a737bd4d 11240{
c19d1205
ZW
11241 inst.instruction |= inst.operands[1].reg << 12;
11242}
a737bd4d 11243
c19d1205
ZW
11244/* Maverick shift immediate instructions.
11245 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11246 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 11247
c19d1205
ZW
11248static void
11249do_mav_shift (void)
11250{
11251 int imm = inst.operands[2].imm;
a737bd4d 11252
c19d1205
ZW
11253 inst.instruction |= inst.operands[0].reg << 12;
11254 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 11255
c19d1205
ZW
11256 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11257 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11258 Bit 4 should be 0. */
11259 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 11260
c19d1205
ZW
11261 inst.instruction |= imm;
11262}
11263\f
11264/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 11265
c19d1205
ZW
11266/* Xscale multiply-accumulate (argument parse)
11267 MIAcc acc0,Rm,Rs
11268 MIAPHcc acc0,Rm,Rs
11269 MIAxycc acc0,Rm,Rs. */
a737bd4d 11270
c19d1205
ZW
11271static void
11272do_xsc_mia (void)
11273{
11274 inst.instruction |= inst.operands[1].reg;
11275 inst.instruction |= inst.operands[2].reg << 12;
11276}
a737bd4d 11277
c19d1205 11278/* Xscale move-accumulator-register (argument parse)
a737bd4d 11279
c19d1205 11280 MARcc acc0,RdLo,RdHi. */
b99bd4ef 11281
c19d1205
ZW
11282static void
11283do_xsc_mar (void)
11284{
11285 inst.instruction |= inst.operands[1].reg << 12;
11286 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11287}
11288
c19d1205 11289/* Xscale move-register-accumulator (argument parse)
b99bd4ef 11290
c19d1205 11291 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
11292
11293static void
c19d1205 11294do_xsc_mra (void)
b99bd4ef 11295{
c19d1205
ZW
11296 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11297 inst.instruction |= inst.operands[0].reg << 12;
11298 inst.instruction |= inst.operands[1].reg << 16;
11299}
11300\f
11301/* Encoding functions relevant only to Thumb. */
b99bd4ef 11302
c19d1205
ZW
11303/* inst.operands[i] is a shifted-register operand; encode
11304 it into inst.instruction in the format used by Thumb32. */
11305
11306static void
11307encode_thumb32_shifted_operand (int i)
11308{
e2b0ab59 11309 unsigned int value = inst.relocs[0].exp.X_add_number;
c19d1205 11310 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 11311
9c3c69f2
PB
11312 constraint (inst.operands[i].immisreg,
11313 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
11314 inst.instruction |= inst.operands[i].reg;
11315 if (shift == SHIFT_RRX)
11316 inst.instruction |= SHIFT_ROR << 4;
11317 else
b99bd4ef 11318 {
e2b0ab59 11319 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
11320 _("expression too complex"));
11321
11322 constraint (value > 32
11323 || (value == 32 && (shift == SHIFT_LSL
11324 || shift == SHIFT_ROR)),
11325 _("shift expression is too large"));
11326
11327 if (value == 0)
11328 shift = SHIFT_LSL;
11329 else if (value == 32)
11330 value = 0;
11331
11332 inst.instruction |= shift << 4;
11333 inst.instruction |= (value & 0x1c) << 10;
11334 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 11335 }
c19d1205 11336}
b99bd4ef 11337
b99bd4ef 11338
c19d1205
ZW
11339/* inst.operands[i] was set up by parse_address. Encode it into a
11340 Thumb32 format load or store instruction. Reject forms that cannot
11341 be used with such instructions. If is_t is true, reject forms that
11342 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
11343 that cannot be used with a D instruction. If it is a store insn,
11344 reject PC in Rn. */
b99bd4ef 11345
c19d1205
ZW
11346static void
11347encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11348{
5be8be5d 11349 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
11350
11351 constraint (!inst.operands[i].isreg,
53365c0d 11352 _("Instruction does not support =N addresses"));
b99bd4ef 11353
c19d1205
ZW
11354 inst.instruction |= inst.operands[i].reg << 16;
11355 if (inst.operands[i].immisreg)
b99bd4ef 11356 {
5be8be5d 11357 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
11358 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11359 constraint (inst.operands[i].negative,
11360 _("Thumb does not support negative register indexing"));
11361 constraint (inst.operands[i].postind,
11362 _("Thumb does not support register post-indexing"));
11363 constraint (inst.operands[i].writeback,
11364 _("Thumb does not support register indexing with writeback"));
11365 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11366 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 11367
f40d1643 11368 inst.instruction |= inst.operands[i].imm;
c19d1205 11369 if (inst.operands[i].shifted)
b99bd4ef 11370 {
e2b0ab59 11371 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 11372 _("expression too complex"));
e2b0ab59
AV
11373 constraint (inst.relocs[0].exp.X_add_number < 0
11374 || inst.relocs[0].exp.X_add_number > 3,
c19d1205 11375 _("shift out of range"));
e2b0ab59 11376 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
c19d1205 11377 }
e2b0ab59 11378 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205
ZW
11379 }
11380 else if (inst.operands[i].preind)
11381 {
5be8be5d 11382 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 11383 constraint (is_t && inst.operands[i].writeback,
c19d1205 11384 _("cannot use writeback with this instruction"));
4755303e
WN
11385 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11386 BAD_PC_ADDRESSING);
c19d1205
ZW
11387
11388 if (is_d)
11389 {
11390 inst.instruction |= 0x01000000;
11391 if (inst.operands[i].writeback)
11392 inst.instruction |= 0x00200000;
b99bd4ef 11393 }
c19d1205 11394 else
b99bd4ef 11395 {
c19d1205
ZW
11396 inst.instruction |= 0x00000c00;
11397 if (inst.operands[i].writeback)
11398 inst.instruction |= 0x00000100;
b99bd4ef 11399 }
e2b0ab59 11400 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 11401 }
c19d1205 11402 else if (inst.operands[i].postind)
b99bd4ef 11403 {
9c2799c2 11404 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
11405 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11406 constraint (is_t, _("cannot use post-indexing with this instruction"));
11407
11408 if (is_d)
11409 inst.instruction |= 0x00200000;
11410 else
11411 inst.instruction |= 0x00000900;
e2b0ab59 11412 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
c19d1205
ZW
11413 }
11414 else /* unindexed - only for coprocessor */
11415 inst.error = _("instruction does not accept unindexed addressing");
11416}
11417
e39c1607 11418/* Table of Thumb instructions which exist in 16- and/or 32-bit
c19d1205
ZW
11419 encodings (the latter only in post-V6T2 cores). The index is the
11420 value used in the insns table below. When there is more than one
11421 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
11422 holds variant (1).
11423 Also contains several pseudo-instructions used during relaxation. */
c19d1205 11424#define T16_32_TAB \
21d799b5
NC
11425 X(_adc, 4140, eb400000), \
11426 X(_adcs, 4140, eb500000), \
11427 X(_add, 1c00, eb000000), \
11428 X(_adds, 1c00, eb100000), \
11429 X(_addi, 0000, f1000000), \
11430 X(_addis, 0000, f1100000), \
11431 X(_add_pc,000f, f20f0000), \
11432 X(_add_sp,000d, f10d0000), \
11433 X(_adr, 000f, f20f0000), \
11434 X(_and, 4000, ea000000), \
11435 X(_ands, 4000, ea100000), \
11436 X(_asr, 1000, fa40f000), \
11437 X(_asrs, 1000, fa50f000), \
11438 X(_b, e000, f000b000), \
11439 X(_bcond, d000, f0008000), \
4389b29a 11440 X(_bf, 0000, f040e001), \
f6b2b12d 11441 X(_bfcsel,0000, f000e001), \
f1c7f421 11442 X(_bfx, 0000, f060e001), \
65d1bc05 11443 X(_bfl, 0000, f000c001), \
f1c7f421 11444 X(_bflx, 0000, f070e001), \
21d799b5
NC
11445 X(_bic, 4380, ea200000), \
11446 X(_bics, 4380, ea300000), \
e39c1607
SD
11447 X(_cinc, 0000, ea509000), \
11448 X(_cinv, 0000, ea50a000), \
21d799b5
NC
11449 X(_cmn, 42c0, eb100f00), \
11450 X(_cmp, 2800, ebb00f00), \
e39c1607 11451 X(_cneg, 0000, ea50b000), \
21d799b5
NC
11452 X(_cpsie, b660, f3af8400), \
11453 X(_cpsid, b670, f3af8600), \
11454 X(_cpy, 4600, ea4f0000), \
e39c1607
SD
11455 X(_csel, 0000, ea508000), \
11456 X(_cset, 0000, ea5f900f), \
11457 X(_csetm, 0000, ea5fa00f), \
11458 X(_csinc, 0000, ea509000), \
11459 X(_csinv, 0000, ea50a000), \
11460 X(_csneg, 0000, ea50b000), \
21d799b5 11461 X(_dec_sp,80dd, f1ad0d00), \
60f993ce 11462 X(_dls, 0000, f040e001), \
1f6234a3 11463 X(_dlstp, 0000, f000e001), \
21d799b5
NC
11464 X(_eor, 4040, ea800000), \
11465 X(_eors, 4040, ea900000), \
11466 X(_inc_sp,00dd, f10d0d00), \
1f6234a3 11467 X(_lctp, 0000, f00fe001), \
21d799b5
NC
11468 X(_ldmia, c800, e8900000), \
11469 X(_ldr, 6800, f8500000), \
11470 X(_ldrb, 7800, f8100000), \
11471 X(_ldrh, 8800, f8300000), \
11472 X(_ldrsb, 5600, f9100000), \
11473 X(_ldrsh, 5e00, f9300000), \
11474 X(_ldr_pc,4800, f85f0000), \
11475 X(_ldr_pc2,4800, f85f0000), \
11476 X(_ldr_sp,9800, f85d0000), \
60f993ce 11477 X(_le, 0000, f00fc001), \
1f6234a3 11478 X(_letp, 0000, f01fc001), \
21d799b5
NC
11479 X(_lsl, 0000, fa00f000), \
11480 X(_lsls, 0000, fa10f000), \
11481 X(_lsr, 0800, fa20f000), \
11482 X(_lsrs, 0800, fa30f000), \
11483 X(_mov, 2000, ea4f0000), \
11484 X(_movs, 2000, ea5f0000), \
11485 X(_mul, 4340, fb00f000), \
11486 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11487 X(_mvn, 43c0, ea6f0000), \
11488 X(_mvns, 43c0, ea7f0000), \
11489 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11490 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11491 X(_orr, 4300, ea400000), \
11492 X(_orrs, 4300, ea500000), \
11493 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11494 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11495 X(_rev, ba00, fa90f080), \
11496 X(_rev16, ba40, fa90f090), \
11497 X(_revsh, bac0, fa90f0b0), \
11498 X(_ror, 41c0, fa60f000), \
11499 X(_rors, 41c0, fa70f000), \
11500 X(_sbc, 4180, eb600000), \
11501 X(_sbcs, 4180, eb700000), \
11502 X(_stmia, c000, e8800000), \
11503 X(_str, 6000, f8400000), \
11504 X(_strb, 7000, f8000000), \
11505 X(_strh, 8000, f8200000), \
11506 X(_str_sp,9000, f84d0000), \
11507 X(_sub, 1e00, eba00000), \
11508 X(_subs, 1e00, ebb00000), \
11509 X(_subi, 8000, f1a00000), \
11510 X(_subis, 8000, f1b00000), \
11511 X(_sxtb, b240, fa4ff080), \
11512 X(_sxth, b200, fa0ff080), \
11513 X(_tst, 4200, ea100f00), \
11514 X(_uxtb, b2c0, fa5ff080), \
11515 X(_uxth, b280, fa1ff080), \
11516 X(_nop, bf00, f3af8000), \
11517 X(_yield, bf10, f3af8001), \
11518 X(_wfe, bf20, f3af8002), \
11519 X(_wfi, bf30, f3af8003), \
60f993ce 11520 X(_wls, 0000, f040c001), \
1f6234a3 11521 X(_wlstp, 0000, f000c001), \
53c4b28b 11522 X(_sev, bf40, f3af8004), \
74db7efb
NC
11523 X(_sevl, bf50, f3af8005), \
11524 X(_udf, de00, f7f0a000)
c19d1205
ZW
11525
11526/* To catch errors in encoding functions, the codes are all offset by
11527 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11528 as 16-bit instructions. */
21d799b5 11529#define X(a,b,c) T_MNEM##a
c19d1205
ZW
11530enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11531#undef X
11532
11533#define X(a,b,c) 0x##b
11534static const unsigned short thumb_op16[] = { T16_32_TAB };
11535#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11536#undef X
11537
11538#define X(a,b,c) 0x##c
11539static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
11540#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11541#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
11542#undef X
11543#undef T16_32_TAB
11544
11545/* Thumb instruction encoders, in alphabetical order. */
11546
92e90b6e 11547/* ADDW or SUBW. */
c921be7d 11548
92e90b6e
PB
11549static void
11550do_t_add_sub_w (void)
11551{
11552 int Rd, Rn;
11553
11554 Rd = inst.operands[0].reg;
11555 Rn = inst.operands[1].reg;
11556
539d4391
NC
11557 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11558 is the SP-{plus,minus}-immediate form of the instruction. */
11559 if (Rn == REG_SP)
11560 constraint (Rd == REG_PC, BAD_PC);
11561 else
11562 reject_bad_reg (Rd);
fdfde340 11563
92e90b6e 11564 inst.instruction |= (Rn << 16) | (Rd << 8);
e2b0ab59 11565 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
92e90b6e
PB
11566}
11567
c19d1205 11568/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 11569 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
11570
11571static void
11572do_t_add_sub (void)
11573{
11574 int Rd, Rs, Rn;
11575
11576 Rd = inst.operands[0].reg;
11577 Rs = (inst.operands[1].present
11578 ? inst.operands[1].reg /* Rd, Rs, foo */
11579 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11580
e07e6e58 11581 if (Rd == REG_PC)
5ee91343 11582 set_pred_insn_type_last ();
e07e6e58 11583
c19d1205
ZW
11584 if (unified_syntax)
11585 {
0110f2b8
PB
11586 bfd_boolean flags;
11587 bfd_boolean narrow;
11588 int opcode;
11589
11590 flags = (inst.instruction == T_MNEM_adds
11591 || inst.instruction == T_MNEM_subs);
11592 if (flags)
5ee91343 11593 narrow = !in_pred_block ();
0110f2b8 11594 else
5ee91343 11595 narrow = in_pred_block ();
c19d1205 11596 if (!inst.operands[2].isreg)
b99bd4ef 11597 {
16805f35
PB
11598 int add;
11599
5c8ed6a4
JW
11600 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11601 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 11602
16805f35
PB
11603 add = (inst.instruction == T_MNEM_add
11604 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
11605 opcode = 0;
11606 if (inst.size_req != 4)
11607 {
0110f2b8 11608 /* Attempt to use a narrow opcode, with relaxation if
477330fc 11609 appropriate. */
0110f2b8
PB
11610 if (Rd == REG_SP && Rs == REG_SP && !flags)
11611 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11612 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11613 opcode = T_MNEM_add_sp;
11614 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11615 opcode = T_MNEM_add_pc;
11616 else if (Rd <= 7 && Rs <= 7 && narrow)
11617 {
11618 if (flags)
11619 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11620 else
11621 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11622 }
11623 if (opcode)
11624 {
11625 inst.instruction = THUMB_OP16(opcode);
11626 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59
AV
11627 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11628 || (inst.relocs[0].type
11629 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
a9f02af8
MG
11630 {
11631 if (inst.size_req == 2)
e2b0ab59 11632 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
a9f02af8
MG
11633 else
11634 inst.relax = opcode;
11635 }
0110f2b8
PB
11636 }
11637 else
11638 constraint (inst.size_req == 2, BAD_HIREG);
11639 }
11640 if (inst.size_req == 4
11641 || (inst.size_req != 2 && !opcode))
11642 {
e2b0ab59
AV
11643 constraint ((inst.relocs[0].type
11644 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11645 && (inst.relocs[0].type
11646 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8 11647 THUMB1_RELOC_ONLY);
efd81785
PB
11648 if (Rd == REG_PC)
11649 {
fdfde340 11650 constraint (add, BAD_PC);
efd81785
PB
11651 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11652 _("only SUBS PC, LR, #const allowed"));
e2b0ab59 11653 constraint (inst.relocs[0].exp.X_op != O_constant,
efd81785 11654 _("expression too complex"));
e2b0ab59
AV
11655 constraint (inst.relocs[0].exp.X_add_number < 0
11656 || inst.relocs[0].exp.X_add_number > 0xff,
efd81785
PB
11657 _("immediate value out of range"));
11658 inst.instruction = T2_SUBS_PC_LR
e2b0ab59
AV
11659 | inst.relocs[0].exp.X_add_number;
11660 inst.relocs[0].type = BFD_RELOC_UNUSED;
efd81785
PB
11661 return;
11662 }
11663 else if (Rs == REG_PC)
16805f35
PB
11664 {
11665 /* Always use addw/subw. */
11666 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
e2b0ab59 11667 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
16805f35
PB
11668 }
11669 else
11670 {
11671 inst.instruction = THUMB_OP32 (inst.instruction);
11672 inst.instruction = (inst.instruction & 0xe1ffffff)
11673 | 0x10000000;
11674 if (flags)
e2b0ab59 11675 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
16805f35 11676 else
e2b0ab59 11677 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
16805f35 11678 }
dc4503c6
PB
11679 inst.instruction |= Rd << 8;
11680 inst.instruction |= Rs << 16;
0110f2b8 11681 }
b99bd4ef 11682 }
c19d1205
ZW
11683 else
11684 {
e2b0ab59 11685 unsigned int value = inst.relocs[0].exp.X_add_number;
5f4cb198
NC
11686 unsigned int shift = inst.operands[2].shift_kind;
11687
c19d1205
ZW
11688 Rn = inst.operands[2].reg;
11689 /* See if we can do this with a 16-bit instruction. */
11690 if (!inst.operands[2].shifted && inst.size_req != 4)
11691 {
e27ec89e
PB
11692 if (Rd > 7 || Rs > 7 || Rn > 7)
11693 narrow = FALSE;
11694
11695 if (narrow)
c19d1205 11696 {
e27ec89e
PB
11697 inst.instruction = ((inst.instruction == T_MNEM_adds
11698 || inst.instruction == T_MNEM_add)
c19d1205
ZW
11699 ? T_OPCODE_ADD_R3
11700 : T_OPCODE_SUB_R3);
11701 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11702 return;
11703 }
b99bd4ef 11704
7e806470 11705 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 11706 {
7e806470
PB
11707 /* Thumb-1 cores (except v6-M) require at least one high
11708 register in a narrow non flag setting add. */
11709 if (Rd > 7 || Rn > 7
11710 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11711 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 11712 {
7e806470
PB
11713 if (Rd == Rn)
11714 {
11715 Rn = Rs;
11716 Rs = Rd;
11717 }
c19d1205
ZW
11718 inst.instruction = T_OPCODE_ADD_HI;
11719 inst.instruction |= (Rd & 8) << 4;
11720 inst.instruction |= (Rd & 7);
11721 inst.instruction |= Rn << 3;
11722 return;
11723 }
c19d1205
ZW
11724 }
11725 }
c921be7d 11726
fdfde340 11727 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
11728 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11729 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
11730 constraint (Rs == REG_PC, BAD_PC);
11731 reject_bad_reg (Rn);
11732
c19d1205
ZW
11733 /* If we get here, it can't be done in 16 bits. */
11734 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11735 _("shift must be constant"));
11736 inst.instruction = THUMB_OP32 (inst.instruction);
11737 inst.instruction |= Rd << 8;
11738 inst.instruction |= Rs << 16;
5f4cb198
NC
11739 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11740 _("shift value over 3 not allowed in thumb mode"));
11741 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11742 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
11743 encode_thumb32_shifted_operand (2);
11744 }
11745 }
11746 else
11747 {
11748 constraint (inst.instruction == T_MNEM_adds
11749 || inst.instruction == T_MNEM_subs,
11750 BAD_THUMB32);
b99bd4ef 11751
c19d1205 11752 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 11753 {
c19d1205
ZW
11754 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11755 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11756 BAD_HIREG);
11757
11758 inst.instruction = (inst.instruction == T_MNEM_add
11759 ? 0x0000 : 0x8000);
11760 inst.instruction |= (Rd << 4) | Rs;
e2b0ab59 11761 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
11762 return;
11763 }
11764
c19d1205
ZW
11765 Rn = inst.operands[2].reg;
11766 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 11767
c19d1205
ZW
11768 /* We now have Rd, Rs, and Rn set to registers. */
11769 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 11770 {
c19d1205
ZW
11771 /* Can't do this for SUB. */
11772 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11773 inst.instruction = T_OPCODE_ADD_HI;
11774 inst.instruction |= (Rd & 8) << 4;
11775 inst.instruction |= (Rd & 7);
11776 if (Rs == Rd)
11777 inst.instruction |= Rn << 3;
11778 else if (Rn == Rd)
11779 inst.instruction |= Rs << 3;
11780 else
11781 constraint (1, _("dest must overlap one source register"));
11782 }
11783 else
11784 {
11785 inst.instruction = (inst.instruction == T_MNEM_add
11786 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11787 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 11788 }
b99bd4ef 11789 }
b99bd4ef
NC
11790}
11791
c19d1205
ZW
11792static void
11793do_t_adr (void)
11794{
fdfde340
JM
11795 unsigned Rd;
11796
11797 Rd = inst.operands[0].reg;
11798 reject_bad_reg (Rd);
11799
11800 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
11801 {
11802 /* Defer to section relaxation. */
11803 inst.relax = inst.instruction;
11804 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11805 inst.instruction |= Rd << 4;
0110f2b8
PB
11806 }
11807 else if (unified_syntax && inst.size_req != 2)
e9f89963 11808 {
0110f2b8 11809 /* Generate a 32-bit opcode. */
e9f89963 11810 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11811 inst.instruction |= Rd << 8;
e2b0ab59
AV
11812 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11813 inst.relocs[0].pc_rel = 1;
e9f89963
PB
11814 }
11815 else
11816 {
0110f2b8 11817 /* Generate a 16-bit opcode. */
e9f89963 11818 inst.instruction = THUMB_OP16 (inst.instruction);
e2b0ab59
AV
11819 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11820 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11821 inst.relocs[0].pc_rel = 1;
fdfde340 11822 inst.instruction |= Rd << 4;
e9f89963 11823 }
52a86f84 11824
e2b0ab59
AV
11825 if (inst.relocs[0].exp.X_op == O_symbol
11826 && inst.relocs[0].exp.X_add_symbol != NULL
11827 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11828 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11829 inst.relocs[0].exp.X_add_number += 1;
c19d1205 11830}
b99bd4ef 11831
c19d1205
ZW
11832/* Arithmetic instructions for which there is just one 16-bit
11833 instruction encoding, and it allows only two low registers.
11834 For maximal compatibility with ARM syntax, we allow three register
11835 operands even when Thumb-32 instructions are not available, as long
11836 as the first two are identical. For instance, both "sbc r0,r1" and
11837 "sbc r0,r0,r1" are allowed. */
b99bd4ef 11838static void
c19d1205 11839do_t_arit3 (void)
b99bd4ef 11840{
c19d1205 11841 int Rd, Rs, Rn;
b99bd4ef 11842
c19d1205
ZW
11843 Rd = inst.operands[0].reg;
11844 Rs = (inst.operands[1].present
11845 ? inst.operands[1].reg /* Rd, Rs, foo */
11846 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11847 Rn = inst.operands[2].reg;
b99bd4ef 11848
fdfde340
JM
11849 reject_bad_reg (Rd);
11850 reject_bad_reg (Rs);
11851 if (inst.operands[2].isreg)
11852 reject_bad_reg (Rn);
11853
c19d1205 11854 if (unified_syntax)
b99bd4ef 11855 {
c19d1205
ZW
11856 if (!inst.operands[2].isreg)
11857 {
11858 /* For an immediate, we always generate a 32-bit opcode;
11859 section relaxation will shrink it later if possible. */
11860 inst.instruction = THUMB_OP32 (inst.instruction);
11861 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11862 inst.instruction |= Rd << 8;
11863 inst.instruction |= Rs << 16;
e2b0ab59 11864 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
c19d1205
ZW
11865 }
11866 else
11867 {
e27ec89e
PB
11868 bfd_boolean narrow;
11869
c19d1205 11870 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11871 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11872 narrow = !in_pred_block ();
e27ec89e 11873 else
5ee91343 11874 narrow = in_pred_block ();
e27ec89e
PB
11875
11876 if (Rd > 7 || Rn > 7 || Rs > 7)
11877 narrow = FALSE;
11878 if (inst.operands[2].shifted)
11879 narrow = FALSE;
11880 if (inst.size_req == 4)
11881 narrow = FALSE;
11882
11883 if (narrow
c19d1205
ZW
11884 && Rd == Rs)
11885 {
11886 inst.instruction = THUMB_OP16 (inst.instruction);
11887 inst.instruction |= Rd;
11888 inst.instruction |= Rn << 3;
11889 return;
11890 }
b99bd4ef 11891
c19d1205
ZW
11892 /* If we get here, it can't be done in 16 bits. */
11893 constraint (inst.operands[2].shifted
11894 && inst.operands[2].immisreg,
11895 _("shift must be constant"));
11896 inst.instruction = THUMB_OP32 (inst.instruction);
11897 inst.instruction |= Rd << 8;
11898 inst.instruction |= Rs << 16;
11899 encode_thumb32_shifted_operand (2);
11900 }
a737bd4d 11901 }
c19d1205 11902 else
b99bd4ef 11903 {
c19d1205
ZW
11904 /* On its face this is a lie - the instruction does set the
11905 flags. However, the only supported mnemonic in this mode
11906 says it doesn't. */
11907 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11908
c19d1205
ZW
11909 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11910 _("unshifted register required"));
11911 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11912 constraint (Rd != Rs,
11913 _("dest and source1 must be the same register"));
a737bd4d 11914
c19d1205
ZW
11915 inst.instruction = THUMB_OP16 (inst.instruction);
11916 inst.instruction |= Rd;
11917 inst.instruction |= Rn << 3;
b99bd4ef 11918 }
a737bd4d 11919}
b99bd4ef 11920
c19d1205
ZW
11921/* Similarly, but for instructions where the arithmetic operation is
11922 commutative, so we can allow either of them to be different from
11923 the destination operand in a 16-bit instruction. For instance, all
11924 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11925 accepted. */
11926static void
11927do_t_arit3c (void)
a737bd4d 11928{
c19d1205 11929 int Rd, Rs, Rn;
b99bd4ef 11930
c19d1205
ZW
11931 Rd = inst.operands[0].reg;
11932 Rs = (inst.operands[1].present
11933 ? inst.operands[1].reg /* Rd, Rs, foo */
11934 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11935 Rn = inst.operands[2].reg;
c921be7d 11936
fdfde340
JM
11937 reject_bad_reg (Rd);
11938 reject_bad_reg (Rs);
11939 if (inst.operands[2].isreg)
11940 reject_bad_reg (Rn);
a737bd4d 11941
c19d1205 11942 if (unified_syntax)
a737bd4d 11943 {
c19d1205 11944 if (!inst.operands[2].isreg)
b99bd4ef 11945 {
c19d1205
ZW
11946 /* For an immediate, we always generate a 32-bit opcode;
11947 section relaxation will shrink it later if possible. */
11948 inst.instruction = THUMB_OP32 (inst.instruction);
11949 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11950 inst.instruction |= Rd << 8;
11951 inst.instruction |= Rs << 16;
e2b0ab59 11952 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11953 }
c19d1205 11954 else
a737bd4d 11955 {
e27ec89e
PB
11956 bfd_boolean narrow;
11957
c19d1205 11958 /* See if we can do this with a 16-bit instruction. */
e27ec89e 11959 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 11960 narrow = !in_pred_block ();
e27ec89e 11961 else
5ee91343 11962 narrow = in_pred_block ();
e27ec89e
PB
11963
11964 if (Rd > 7 || Rn > 7 || Rs > 7)
11965 narrow = FALSE;
11966 if (inst.operands[2].shifted)
11967 narrow = FALSE;
11968 if (inst.size_req == 4)
11969 narrow = FALSE;
11970
11971 if (narrow)
a737bd4d 11972 {
c19d1205 11973 if (Rd == Rs)
a737bd4d 11974 {
c19d1205
ZW
11975 inst.instruction = THUMB_OP16 (inst.instruction);
11976 inst.instruction |= Rd;
11977 inst.instruction |= Rn << 3;
11978 return;
a737bd4d 11979 }
c19d1205 11980 if (Rd == Rn)
a737bd4d 11981 {
c19d1205
ZW
11982 inst.instruction = THUMB_OP16 (inst.instruction);
11983 inst.instruction |= Rd;
11984 inst.instruction |= Rs << 3;
11985 return;
a737bd4d
NC
11986 }
11987 }
c19d1205
ZW
11988
11989 /* If we get here, it can't be done in 16 bits. */
11990 constraint (inst.operands[2].shifted
11991 && inst.operands[2].immisreg,
11992 _("shift must be constant"));
11993 inst.instruction = THUMB_OP32 (inst.instruction);
11994 inst.instruction |= Rd << 8;
11995 inst.instruction |= Rs << 16;
11996 encode_thumb32_shifted_operand (2);
a737bd4d 11997 }
b99bd4ef 11998 }
c19d1205
ZW
11999 else
12000 {
12001 /* On its face this is a lie - the instruction does set the
12002 flags. However, the only supported mnemonic in this mode
12003 says it doesn't. */
12004 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 12005
c19d1205
ZW
12006 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
12007 _("unshifted register required"));
12008 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
12009
12010 inst.instruction = THUMB_OP16 (inst.instruction);
12011 inst.instruction |= Rd;
12012
12013 if (Rd == Rs)
12014 inst.instruction |= Rn << 3;
12015 else if (Rd == Rn)
12016 inst.instruction |= Rs << 3;
12017 else
12018 constraint (1, _("dest must overlap one source register"));
12019 }
a737bd4d
NC
12020}
12021
c19d1205
ZW
12022static void
12023do_t_bfc (void)
a737bd4d 12024{
fdfde340 12025 unsigned Rd;
c19d1205
ZW
12026 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12027 constraint (msb > 32, _("bit-field extends past end of register"));
12028 /* The instruction encoding stores the LSB and MSB,
12029 not the LSB and width. */
fdfde340
JM
12030 Rd = inst.operands[0].reg;
12031 reject_bad_reg (Rd);
12032 inst.instruction |= Rd << 8;
c19d1205
ZW
12033 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12034 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12035 inst.instruction |= msb - 1;
b99bd4ef
NC
12036}
12037
c19d1205
ZW
12038static void
12039do_t_bfi (void)
b99bd4ef 12040{
fdfde340 12041 int Rd, Rn;
c19d1205 12042 unsigned int msb;
b99bd4ef 12043
fdfde340
JM
12044 Rd = inst.operands[0].reg;
12045 reject_bad_reg (Rd);
12046
c19d1205
ZW
12047 /* #0 in second position is alternative syntax for bfc, which is
12048 the same instruction but with REG_PC in the Rm field. */
12049 if (!inst.operands[1].isreg)
fdfde340
JM
12050 Rn = REG_PC;
12051 else
12052 {
12053 Rn = inst.operands[1].reg;
12054 reject_bad_reg (Rn);
12055 }
b99bd4ef 12056
c19d1205
ZW
12057 msb = inst.operands[2].imm + inst.operands[3].imm;
12058 constraint (msb > 32, _("bit-field extends past end of register"));
12059 /* The instruction encoding stores the LSB and MSB,
12060 not the LSB and width. */
fdfde340
JM
12061 inst.instruction |= Rd << 8;
12062 inst.instruction |= Rn << 16;
c19d1205
ZW
12063 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12064 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12065 inst.instruction |= msb - 1;
b99bd4ef
NC
12066}
12067
c19d1205
ZW
12068static void
12069do_t_bfx (void)
b99bd4ef 12070{
fdfde340
JM
12071 unsigned Rd, Rn;
12072
12073 Rd = inst.operands[0].reg;
12074 Rn = inst.operands[1].reg;
12075
12076 reject_bad_reg (Rd);
12077 reject_bad_reg (Rn);
12078
c19d1205
ZW
12079 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12080 _("bit-field extends past end of register"));
fdfde340
JM
12081 inst.instruction |= Rd << 8;
12082 inst.instruction |= Rn << 16;
c19d1205
ZW
12083 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12084 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12085 inst.instruction |= inst.operands[3].imm - 1;
12086}
b99bd4ef 12087
c19d1205
ZW
12088/* ARM V5 Thumb BLX (argument parse)
12089 BLX <target_addr> which is BLX(1)
12090 BLX <Rm> which is BLX(2)
12091 Unfortunately, there are two different opcodes for this mnemonic.
12092 So, the insns[].value is not used, and the code here zaps values
12093 into inst.instruction.
b99bd4ef 12094
c19d1205
ZW
12095 ??? How to take advantage of the additional two bits of displacement
12096 available in Thumb32 mode? Need new relocation? */
b99bd4ef 12097
c19d1205
ZW
12098static void
12099do_t_blx (void)
12100{
5ee91343 12101 set_pred_insn_type_last ();
e07e6e58 12102
c19d1205 12103 if (inst.operands[0].isreg)
fdfde340
JM
12104 {
12105 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12106 /* We have a register, so this is BLX(2). */
12107 inst.instruction |= inst.operands[0].reg << 3;
12108 }
b99bd4ef
NC
12109 else
12110 {
c19d1205 12111 /* No register. This must be BLX(1). */
2fc8bdac 12112 inst.instruction = 0xf000e800;
0855e32b 12113 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
12114 }
12115}
12116
c19d1205
ZW
12117static void
12118do_t_branch (void)
b99bd4ef 12119{
0110f2b8 12120 int opcode;
dfa9f0d5 12121 int cond;
2fe88214 12122 bfd_reloc_code_real_type reloc;
dfa9f0d5 12123
e07e6e58 12124 cond = inst.cond;
5ee91343 12125 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
e07e6e58 12126
5ee91343 12127 if (in_pred_block ())
dfa9f0d5
PB
12128 {
12129 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 12130 branches. */
dfa9f0d5 12131 cond = COND_ALWAYS;
dfa9f0d5
PB
12132 }
12133 else
12134 cond = inst.cond;
12135
12136 if (cond != COND_ALWAYS)
0110f2b8
PB
12137 opcode = T_MNEM_bcond;
12138 else
12139 opcode = inst.instruction;
12140
12d6b0b7
RS
12141 if (unified_syntax
12142 && (inst.size_req == 4
10960bfb
PB
12143 || (inst.size_req != 2
12144 && (inst.operands[0].hasreloc
e2b0ab59 12145 || inst.relocs[0].exp.X_op == O_constant))))
c19d1205 12146 {
0110f2b8 12147 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 12148 if (cond == COND_ALWAYS)
9ae92b05 12149 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
12150 else
12151 {
ff8646ee
TP
12152 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12153 _("selected architecture does not support "
12154 "wide conditional branch instruction"));
12155
9c2799c2 12156 gas_assert (cond != 0xF);
dfa9f0d5 12157 inst.instruction |= cond << 22;
9ae92b05 12158 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
12159 }
12160 }
b99bd4ef
NC
12161 else
12162 {
0110f2b8 12163 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 12164 if (cond == COND_ALWAYS)
9ae92b05 12165 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 12166 else
b99bd4ef 12167 {
dfa9f0d5 12168 inst.instruction |= cond << 8;
9ae92b05 12169 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 12170 }
0110f2b8
PB
12171 /* Allow section relaxation. */
12172 if (unified_syntax && inst.size_req != 2)
12173 inst.relax = opcode;
b99bd4ef 12174 }
e2b0ab59
AV
12175 inst.relocs[0].type = reloc;
12176 inst.relocs[0].pc_rel = 1;
b99bd4ef
NC
12177}
12178
8884b720 12179/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 12180 between the two is the maximum immediate allowed - which is passed in
8884b720 12181 RANGE. */
b99bd4ef 12182static void
8884b720 12183do_t_bkpt_hlt1 (int range)
b99bd4ef 12184{
dfa9f0d5
PB
12185 constraint (inst.cond != COND_ALWAYS,
12186 _("instruction is always unconditional"));
c19d1205 12187 if (inst.operands[0].present)
b99bd4ef 12188 {
8884b720 12189 constraint (inst.operands[0].imm > range,
c19d1205
ZW
12190 _("immediate value out of range"));
12191 inst.instruction |= inst.operands[0].imm;
b99bd4ef 12192 }
8884b720 12193
5ee91343 12194 set_pred_insn_type (NEUTRAL_IT_INSN);
8884b720
MGD
12195}
12196
12197static void
12198do_t_hlt (void)
12199{
12200 do_t_bkpt_hlt1 (63);
12201}
12202
12203static void
12204do_t_bkpt (void)
12205{
12206 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
12207}
12208
12209static void
c19d1205 12210do_t_branch23 (void)
b99bd4ef 12211{
5ee91343 12212 set_pred_insn_type_last ();
0855e32b 12213 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 12214
0855e32b
NS
12215 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12216 this file. We used to simply ignore the PLT reloc type here --
12217 the branch encoding is now needed to deal with TLSCALL relocs.
12218 So if we see a PLT reloc now, put it back to how it used to be to
12219 keep the preexisting behaviour. */
e2b0ab59
AV
12220 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12221 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 12222
4343666d 12223#if defined(OBJ_COFF)
c19d1205
ZW
12224 /* If the destination of the branch is a defined symbol which does not have
12225 the THUMB_FUNC attribute, then we must be calling a function which has
12226 the (interfacearm) attribute. We look for the Thumb entry point to that
12227 function and change the branch to refer to that function instead. */
e2b0ab59
AV
12228 if ( inst.relocs[0].exp.X_op == O_symbol
12229 && inst.relocs[0].exp.X_add_symbol != NULL
12230 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12231 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12232 inst.relocs[0].exp.X_add_symbol
12233 = find_real_start (inst.relocs[0].exp.X_add_symbol);
4343666d 12234#endif
90e4755a
RE
12235}
12236
12237static void
c19d1205 12238do_t_bx (void)
90e4755a 12239{
5ee91343 12240 set_pred_insn_type_last ();
c19d1205
ZW
12241 inst.instruction |= inst.operands[0].reg << 3;
12242 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12243 should cause the alignment to be checked once it is known. This is
12244 because BX PC only works if the instruction is word aligned. */
12245}
90e4755a 12246
c19d1205
ZW
12247static void
12248do_t_bxj (void)
12249{
fdfde340 12250 int Rm;
90e4755a 12251
5ee91343 12252 set_pred_insn_type_last ();
fdfde340
JM
12253 Rm = inst.operands[0].reg;
12254 reject_bad_reg (Rm);
12255 inst.instruction |= Rm << 16;
90e4755a
RE
12256}
12257
12258static void
c19d1205 12259do_t_clz (void)
90e4755a 12260{
fdfde340
JM
12261 unsigned Rd;
12262 unsigned Rm;
12263
12264 Rd = inst.operands[0].reg;
12265 Rm = inst.operands[1].reg;
12266
12267 reject_bad_reg (Rd);
12268 reject_bad_reg (Rm);
12269
12270 inst.instruction |= Rd << 8;
12271 inst.instruction |= Rm << 16;
12272 inst.instruction |= Rm;
c19d1205 12273}
90e4755a 12274
e39c1607
SD
12275/* For the Armv8.1-M conditional instructions. */
12276static void
12277do_t_cond (void)
12278{
12279 unsigned Rd, Rn, Rm;
12280 signed int cond;
12281
12282 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12283
12284 Rd = inst.operands[0].reg;
12285 switch (inst.instruction)
12286 {
12287 case T_MNEM_csinc:
12288 case T_MNEM_csinv:
12289 case T_MNEM_csneg:
12290 case T_MNEM_csel:
12291 Rn = inst.operands[1].reg;
12292 Rm = inst.operands[2].reg;
12293 cond = inst.operands[3].imm;
12294 constraint (Rn == REG_SP, BAD_SP);
12295 constraint (Rm == REG_SP, BAD_SP);
12296 break;
12297
12298 case T_MNEM_cinc:
12299 case T_MNEM_cinv:
12300 case T_MNEM_cneg:
12301 Rn = inst.operands[1].reg;
12302 cond = inst.operands[2].imm;
12303 /* Invert the last bit to invert the cond. */
12304 cond = TOGGLE_BIT (cond, 0);
12305 constraint (Rn == REG_SP, BAD_SP);
12306 Rm = Rn;
12307 break;
12308
12309 case T_MNEM_csetm:
12310 case T_MNEM_cset:
12311 cond = inst.operands[1].imm;
12312 /* Invert the last bit to invert the cond. */
12313 cond = TOGGLE_BIT (cond, 0);
12314 Rn = REG_PC;
12315 Rm = REG_PC;
12316 break;
12317
12318 default: abort ();
12319 }
12320
12321 set_pred_insn_type (OUTSIDE_PRED_INSN);
12322 inst.instruction = THUMB_OP32 (inst.instruction);
12323 inst.instruction |= Rd << 8;
12324 inst.instruction |= Rn << 16;
12325 inst.instruction |= Rm;
12326 inst.instruction |= cond << 4;
12327}
12328
91d8b670
JG
12329static void
12330do_t_csdb (void)
12331{
5ee91343 12332 set_pred_insn_type (OUTSIDE_PRED_INSN);
91d8b670
JG
12333}
12334
dfa9f0d5
PB
12335static void
12336do_t_cps (void)
12337{
5ee91343 12338 set_pred_insn_type (OUTSIDE_PRED_INSN);
dfa9f0d5
PB
12339 inst.instruction |= inst.operands[0].imm;
12340}
12341
c19d1205
ZW
12342static void
12343do_t_cpsi (void)
12344{
5ee91343 12345 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205 12346 if (unified_syntax
62b3e311
PB
12347 && (inst.operands[1].present || inst.size_req == 4)
12348 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 12349 {
c19d1205
ZW
12350 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12351 inst.instruction = 0xf3af8000;
12352 inst.instruction |= imod << 9;
12353 inst.instruction |= inst.operands[0].imm << 5;
12354 if (inst.operands[1].present)
12355 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 12356 }
c19d1205 12357 else
90e4755a 12358 {
62b3e311
PB
12359 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12360 && (inst.operands[0].imm & 4),
12361 _("selected processor does not support 'A' form "
12362 "of this instruction"));
12363 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
12364 _("Thumb does not support the 2-argument "
12365 "form of this instruction"));
12366 inst.instruction |= inst.operands[0].imm;
90e4755a 12367 }
90e4755a
RE
12368}
12369
c19d1205
ZW
12370/* THUMB CPY instruction (argument parse). */
12371
90e4755a 12372static void
c19d1205 12373do_t_cpy (void)
90e4755a 12374{
c19d1205 12375 if (inst.size_req == 4)
90e4755a 12376 {
c19d1205
ZW
12377 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12378 inst.instruction |= inst.operands[0].reg << 8;
12379 inst.instruction |= inst.operands[1].reg;
90e4755a 12380 }
c19d1205 12381 else
90e4755a 12382 {
c19d1205
ZW
12383 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12384 inst.instruction |= (inst.operands[0].reg & 0x7);
12385 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 12386 }
90e4755a
RE
12387}
12388
90e4755a 12389static void
25fe350b 12390do_t_cbz (void)
90e4755a 12391{
5ee91343 12392 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
12393 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12394 inst.instruction |= inst.operands[0].reg;
e2b0ab59
AV
12395 inst.relocs[0].pc_rel = 1;
12396 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
c19d1205 12397}
90e4755a 12398
62b3e311
PB
12399static void
12400do_t_dbg (void)
12401{
12402 inst.instruction |= inst.operands[0].imm;
12403}
12404
12405static void
12406do_t_div (void)
12407{
fdfde340
JM
12408 unsigned Rd, Rn, Rm;
12409
12410 Rd = inst.operands[0].reg;
12411 Rn = (inst.operands[1].present
12412 ? inst.operands[1].reg : Rd);
12413 Rm = inst.operands[2].reg;
12414
12415 reject_bad_reg (Rd);
12416 reject_bad_reg (Rn);
12417 reject_bad_reg (Rm);
12418
12419 inst.instruction |= Rd << 8;
12420 inst.instruction |= Rn << 16;
12421 inst.instruction |= Rm;
62b3e311
PB
12422}
12423
c19d1205
ZW
12424static void
12425do_t_hint (void)
12426{
12427 if (unified_syntax && inst.size_req == 4)
12428 inst.instruction = THUMB_OP32 (inst.instruction);
12429 else
12430 inst.instruction = THUMB_OP16 (inst.instruction);
12431}
90e4755a 12432
c19d1205
ZW
12433static void
12434do_t_it (void)
12435{
12436 unsigned int cond = inst.operands[0].imm;
e27ec89e 12437
5ee91343
AV
12438 set_pred_insn_type (IT_INSN);
12439 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12440 now_pred.cc = cond;
12441 now_pred.warn_deprecated = FALSE;
12442 now_pred.type = SCALAR_PRED;
e27ec89e
PB
12443
12444 /* If the condition is a negative condition, invert the mask. */
c19d1205 12445 if ((cond & 0x1) == 0x0)
90e4755a 12446 {
c19d1205 12447 unsigned int mask = inst.instruction & 0x000f;
90e4755a 12448
c19d1205 12449 if ((mask & 0x7) == 0)
5a01bb1d
MGD
12450 {
12451 /* No conversion needed. */
5ee91343 12452 now_pred.block_length = 1;
5a01bb1d 12453 }
c19d1205 12454 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
12455 {
12456 mask ^= 0x8;
5ee91343 12457 now_pred.block_length = 2;
5a01bb1d 12458 }
e27ec89e 12459 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
12460 {
12461 mask ^= 0xC;
5ee91343 12462 now_pred.block_length = 3;
5a01bb1d 12463 }
c19d1205 12464 else
5a01bb1d
MGD
12465 {
12466 mask ^= 0xE;
5ee91343 12467 now_pred.block_length = 4;
5a01bb1d 12468 }
90e4755a 12469
e27ec89e
PB
12470 inst.instruction &= 0xfff0;
12471 inst.instruction |= mask;
c19d1205 12472 }
90e4755a 12473
c19d1205
ZW
12474 inst.instruction |= cond << 4;
12475}
90e4755a 12476
3c707909
PB
12477/* Helper function used for both push/pop and ldm/stm. */
12478static void
4b5a202f
AV
12479encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12480 bfd_boolean writeback)
3c707909 12481{
4b5a202f 12482 bfd_boolean load, store;
3c707909 12483
4b5a202f
AV
12484 gas_assert (base != -1 || !do_io);
12485 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12486 store = do_io && !load;
3c707909
PB
12487
12488 if (mask & (1 << 13))
12489 inst.error = _("SP not allowed in register list");
1e5b0379 12490
4b5a202f 12491 if (do_io && (mask & (1 << base)) != 0
1e5b0379
NC
12492 && writeback)
12493 inst.error = _("having the base register in the register list when "
12494 "using write back is UNPREDICTABLE");
12495
3c707909
PB
12496 if (load)
12497 {
e07e6e58 12498 if (mask & (1 << 15))
477330fc
RM
12499 {
12500 if (mask & (1 << 14))
12501 inst.error = _("LR and PC should not both be in register list");
12502 else
5ee91343 12503 set_pred_insn_type_last ();
477330fc 12504 }
3c707909 12505 }
4b5a202f 12506 else if (store)
3c707909
PB
12507 {
12508 if (mask & (1 << 15))
12509 inst.error = _("PC not allowed in register list");
3c707909
PB
12510 }
12511
4b5a202f 12512 if (do_io && ((mask & (mask - 1)) == 0))
3c707909
PB
12513 {
12514 /* Single register transfers implemented as str/ldr. */
12515 if (writeback)
12516 {
12517 if (inst.instruction & (1 << 23))
12518 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12519 else
12520 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12521 }
12522 else
12523 {
12524 if (inst.instruction & (1 << 23))
12525 inst.instruction = 0x00800000; /* ia -> [base] */
12526 else
12527 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12528 }
12529
12530 inst.instruction |= 0xf8400000;
12531 if (load)
12532 inst.instruction |= 0x00100000;
12533
5f4273c7 12534 mask = ffs (mask) - 1;
3c707909
PB
12535 mask <<= 12;
12536 }
12537 else if (writeback)
12538 inst.instruction |= WRITE_BACK;
12539
12540 inst.instruction |= mask;
4b5a202f
AV
12541 if (do_io)
12542 inst.instruction |= base << 16;
3c707909
PB
12543}
12544
c19d1205
ZW
12545static void
12546do_t_ldmstm (void)
12547{
12548 /* This really doesn't seem worth it. */
e2b0ab59 12549 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205
ZW
12550 _("expression too complex"));
12551 constraint (inst.operands[1].writeback,
12552 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 12553
c19d1205
ZW
12554 if (unified_syntax)
12555 {
3c707909
PB
12556 bfd_boolean narrow;
12557 unsigned mask;
12558
12559 narrow = FALSE;
c19d1205
ZW
12560 /* See if we can use a 16-bit instruction. */
12561 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12562 && inst.size_req != 4
3c707909 12563 && !(inst.operands[1].imm & ~0xff))
90e4755a 12564 {
3c707909 12565 mask = 1 << inst.operands[0].reg;
90e4755a 12566
eab4f823 12567 if (inst.operands[0].reg <= 7)
90e4755a 12568 {
3c707909 12569 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
12570 ? inst.operands[0].writeback
12571 : (inst.operands[0].writeback
12572 == !(inst.operands[1].imm & mask)))
477330fc 12573 {
eab4f823
MGD
12574 if (inst.instruction == T_MNEM_stmia
12575 && (inst.operands[1].imm & mask)
12576 && (inst.operands[1].imm & (mask - 1)))
12577 as_warn (_("value stored for r%d is UNKNOWN"),
12578 inst.operands[0].reg);
3c707909 12579
eab4f823
MGD
12580 inst.instruction = THUMB_OP16 (inst.instruction);
12581 inst.instruction |= inst.operands[0].reg << 8;
12582 inst.instruction |= inst.operands[1].imm;
12583 narrow = TRUE;
12584 }
12585 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12586 {
12587 /* This means 1 register in reg list one of 3 situations:
12588 1. Instruction is stmia, but without writeback.
12589 2. lmdia without writeback, but with Rn not in
477330fc 12590 reglist.
eab4f823
MGD
12591 3. ldmia with writeback, but with Rn in reglist.
12592 Case 3 is UNPREDICTABLE behaviour, so we handle
12593 case 1 and 2 which can be converted into a 16-bit
12594 str or ldr. The SP cases are handled below. */
12595 unsigned long opcode;
12596 /* First, record an error for Case 3. */
12597 if (inst.operands[1].imm & mask
12598 && inst.operands[0].writeback)
fa94de6b 12599 inst.error =
eab4f823
MGD
12600 _("having the base register in the register list when "
12601 "using write back is UNPREDICTABLE");
fa94de6b
RM
12602
12603 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
12604 : T_MNEM_ldr);
12605 inst.instruction = THUMB_OP16 (opcode);
12606 inst.instruction |= inst.operands[0].reg << 3;
12607 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12608 narrow = TRUE;
12609 }
90e4755a 12610 }
eab4f823 12611 else if (inst.operands[0] .reg == REG_SP)
90e4755a 12612 {
eab4f823
MGD
12613 if (inst.operands[0].writeback)
12614 {
fa94de6b 12615 inst.instruction =
eab4f823 12616 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12617 ? T_MNEM_push : T_MNEM_pop);
eab4f823 12618 inst.instruction |= inst.operands[1].imm;
477330fc 12619 narrow = TRUE;
eab4f823
MGD
12620 }
12621 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12622 {
fa94de6b 12623 inst.instruction =
eab4f823 12624 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 12625 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 12626 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 12627 narrow = TRUE;
eab4f823 12628 }
90e4755a 12629 }
3c707909
PB
12630 }
12631
12632 if (!narrow)
12633 {
c19d1205
ZW
12634 if (inst.instruction < 0xffff)
12635 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 12636
4b5a202f
AV
12637 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12638 inst.operands[1].imm,
12639 inst.operands[0].writeback);
90e4755a
RE
12640 }
12641 }
c19d1205 12642 else
90e4755a 12643 {
c19d1205
ZW
12644 constraint (inst.operands[0].reg > 7
12645 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
12646 constraint (inst.instruction != T_MNEM_ldmia
12647 && inst.instruction != T_MNEM_stmia,
12648 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 12649 if (inst.instruction == T_MNEM_stmia)
f03698e6 12650 {
c19d1205
ZW
12651 if (!inst.operands[0].writeback)
12652 as_warn (_("this instruction will write back the base register"));
12653 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12654 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 12655 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 12656 inst.operands[0].reg);
f03698e6 12657 }
c19d1205 12658 else
90e4755a 12659 {
c19d1205
ZW
12660 if (!inst.operands[0].writeback
12661 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12662 as_warn (_("this instruction will write back the base register"));
12663 else if (inst.operands[0].writeback
12664 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12665 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
12666 }
12667
c19d1205
ZW
12668 inst.instruction = THUMB_OP16 (inst.instruction);
12669 inst.instruction |= inst.operands[0].reg << 8;
12670 inst.instruction |= inst.operands[1].imm;
12671 }
12672}
e28cd48c 12673
c19d1205
ZW
12674static void
12675do_t_ldrex (void)
12676{
12677 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12678 || inst.operands[1].postind || inst.operands[1].writeback
12679 || inst.operands[1].immisreg || inst.operands[1].shifted
12680 || inst.operands[1].negative,
01cfc07f 12681 BAD_ADDR_MODE);
e28cd48c 12682
5be8be5d
DG
12683 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12684
c19d1205
ZW
12685 inst.instruction |= inst.operands[0].reg << 12;
12686 inst.instruction |= inst.operands[1].reg << 16;
e2b0ab59 12687 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
c19d1205 12688}
e28cd48c 12689
c19d1205
ZW
12690static void
12691do_t_ldrexd (void)
12692{
12693 if (!inst.operands[1].present)
1cac9012 12694 {
c19d1205
ZW
12695 constraint (inst.operands[0].reg == REG_LR,
12696 _("r14 not allowed as first register "
12697 "when second register is omitted"));
12698 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 12699 }
c19d1205
ZW
12700 constraint (inst.operands[0].reg == inst.operands[1].reg,
12701 BAD_OVERLAP);
b99bd4ef 12702
c19d1205
ZW
12703 inst.instruction |= inst.operands[0].reg << 12;
12704 inst.instruction |= inst.operands[1].reg << 8;
12705 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
12706}
12707
12708static void
c19d1205 12709do_t_ldst (void)
b99bd4ef 12710{
0110f2b8
PB
12711 unsigned long opcode;
12712 int Rn;
12713
e07e6e58
NC
12714 if (inst.operands[0].isreg
12715 && !inst.operands[0].preind
12716 && inst.operands[0].reg == REG_PC)
5ee91343 12717 set_pred_insn_type_last ();
e07e6e58 12718
0110f2b8 12719 opcode = inst.instruction;
c19d1205 12720 if (unified_syntax)
b99bd4ef 12721 {
53365c0d
PB
12722 if (!inst.operands[1].isreg)
12723 {
12724 if (opcode <= 0xffff)
12725 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 12726 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
12727 return;
12728 }
0110f2b8
PB
12729 if (inst.operands[1].isreg
12730 && !inst.operands[1].writeback
c19d1205
ZW
12731 && !inst.operands[1].shifted && !inst.operands[1].postind
12732 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
12733 && opcode <= 0xffff
12734 && inst.size_req != 4)
c19d1205 12735 {
0110f2b8
PB
12736 /* Insn may have a 16-bit form. */
12737 Rn = inst.operands[1].reg;
12738 if (inst.operands[1].immisreg)
12739 {
12740 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 12741 /* [Rn, Rik] */
0110f2b8
PB
12742 if (Rn <= 7 && inst.operands[1].imm <= 7)
12743 goto op16;
5be8be5d
DG
12744 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12745 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
12746 }
12747 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12748 && opcode != T_MNEM_ldrsb)
12749 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12750 || (Rn == REG_SP && opcode == T_MNEM_str))
12751 {
12752 /* [Rn, #const] */
12753 if (Rn > 7)
12754 {
12755 if (Rn == REG_PC)
12756 {
e2b0ab59 12757 if (inst.relocs[0].pc_rel)
0110f2b8
PB
12758 opcode = T_MNEM_ldr_pc2;
12759 else
12760 opcode = T_MNEM_ldr_pc;
12761 }
12762 else
12763 {
12764 if (opcode == T_MNEM_ldr)
12765 opcode = T_MNEM_ldr_sp;
12766 else
12767 opcode = T_MNEM_str_sp;
12768 }
12769 inst.instruction = inst.operands[0].reg << 8;
12770 }
12771 else
12772 {
12773 inst.instruction = inst.operands[0].reg;
12774 inst.instruction |= inst.operands[1].reg << 3;
12775 }
12776 inst.instruction |= THUMB_OP16 (opcode);
12777 if (inst.size_req == 2)
e2b0ab59 12778 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
0110f2b8
PB
12779 else
12780 inst.relax = opcode;
12781 return;
12782 }
c19d1205 12783 }
0110f2b8 12784 /* Definitely a 32-bit variant. */
5be8be5d 12785
8d67f500
NC
12786 /* Warning for Erratum 752419. */
12787 if (opcode == T_MNEM_ldr
12788 && inst.operands[0].reg == REG_SP
12789 && inst.operands[1].writeback == 1
12790 && !inst.operands[1].immisreg)
12791 {
12792 if (no_cpu_selected ()
12793 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
12794 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12795 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
12796 as_warn (_("This instruction may be unpredictable "
12797 "if executed on M-profile cores "
12798 "with interrupts enabled."));
12799 }
12800
5be8be5d 12801 /* Do some validations regarding addressing modes. */
1be5fd2e 12802 if (inst.operands[1].immisreg)
5be8be5d
DG
12803 reject_bad_reg (inst.operands[1].imm);
12804
1be5fd2e
NC
12805 constraint (inst.operands[1].writeback == 1
12806 && inst.operands[0].reg == inst.operands[1].reg,
12807 BAD_OVERLAP);
12808
0110f2b8 12809 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
12810 inst.instruction |= inst.operands[0].reg << 12;
12811 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 12812 check_ldr_r15_aligned ();
b99bd4ef
NC
12813 return;
12814 }
12815
c19d1205
ZW
12816 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12817
12818 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 12819 {
c19d1205
ZW
12820 /* Only [Rn,Rm] is acceptable. */
12821 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12822 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12823 || inst.operands[1].postind || inst.operands[1].shifted
12824 || inst.operands[1].negative,
12825 _("Thumb does not support this addressing mode"));
12826 inst.instruction = THUMB_OP16 (inst.instruction);
12827 goto op16;
b99bd4ef 12828 }
5f4273c7 12829
c19d1205
ZW
12830 inst.instruction = THUMB_OP16 (inst.instruction);
12831 if (!inst.operands[1].isreg)
8335d6aa 12832 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 12833 return;
b99bd4ef 12834
c19d1205
ZW
12835 constraint (!inst.operands[1].preind
12836 || inst.operands[1].shifted
12837 || inst.operands[1].writeback,
12838 _("Thumb does not support this addressing mode"));
12839 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 12840 {
c19d1205
ZW
12841 constraint (inst.instruction & 0x0600,
12842 _("byte or halfword not valid for base register"));
12843 constraint (inst.operands[1].reg == REG_PC
12844 && !(inst.instruction & THUMB_LOAD_BIT),
12845 _("r15 based store not allowed"));
12846 constraint (inst.operands[1].immisreg,
12847 _("invalid base register for register offset"));
b99bd4ef 12848
c19d1205
ZW
12849 if (inst.operands[1].reg == REG_PC)
12850 inst.instruction = T_OPCODE_LDR_PC;
12851 else if (inst.instruction & THUMB_LOAD_BIT)
12852 inst.instruction = T_OPCODE_LDR_SP;
12853 else
12854 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 12855
c19d1205 12856 inst.instruction |= inst.operands[0].reg << 8;
e2b0ab59 12857 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12858 return;
12859 }
90e4755a 12860
c19d1205
ZW
12861 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12862 if (!inst.operands[1].immisreg)
12863 {
12864 /* Immediate offset. */
12865 inst.instruction |= inst.operands[0].reg;
12866 inst.instruction |= inst.operands[1].reg << 3;
e2b0ab59 12867 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
c19d1205
ZW
12868 return;
12869 }
90e4755a 12870
c19d1205
ZW
12871 /* Register offset. */
12872 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12873 constraint (inst.operands[1].negative,
12874 _("Thumb does not support this addressing mode"));
90e4755a 12875
c19d1205
ZW
12876 op16:
12877 switch (inst.instruction)
12878 {
12879 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12880 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12881 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12882 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12883 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12884 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12885 case 0x5600 /* ldrsb */:
12886 case 0x5e00 /* ldrsh */: break;
12887 default: abort ();
12888 }
90e4755a 12889
c19d1205
ZW
12890 inst.instruction |= inst.operands[0].reg;
12891 inst.instruction |= inst.operands[1].reg << 3;
12892 inst.instruction |= inst.operands[1].imm << 6;
12893}
90e4755a 12894
c19d1205
ZW
12895static void
12896do_t_ldstd (void)
12897{
12898 if (!inst.operands[1].present)
b99bd4ef 12899 {
c19d1205
ZW
12900 inst.operands[1].reg = inst.operands[0].reg + 1;
12901 constraint (inst.operands[0].reg == REG_LR,
12902 _("r14 not allowed here"));
bd340a04 12903 constraint (inst.operands[0].reg == REG_R12,
477330fc 12904 _("r12 not allowed here"));
b99bd4ef 12905 }
bd340a04
MGD
12906
12907 if (inst.operands[2].writeback
12908 && (inst.operands[0].reg == inst.operands[2].reg
12909 || inst.operands[1].reg == inst.operands[2].reg))
12910 as_warn (_("base register written back, and overlaps "
477330fc 12911 "one of transfer registers"));
bd340a04 12912
c19d1205
ZW
12913 inst.instruction |= inst.operands[0].reg << 12;
12914 inst.instruction |= inst.operands[1].reg << 8;
12915 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
12916}
12917
c19d1205
ZW
12918static void
12919do_t_ldstt (void)
12920{
12921 inst.instruction |= inst.operands[0].reg << 12;
12922 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12923}
a737bd4d 12924
b99bd4ef 12925static void
c19d1205 12926do_t_mla (void)
b99bd4ef 12927{
fdfde340 12928 unsigned Rd, Rn, Rm, Ra;
c921be7d 12929
fdfde340
JM
12930 Rd = inst.operands[0].reg;
12931 Rn = inst.operands[1].reg;
12932 Rm = inst.operands[2].reg;
12933 Ra = inst.operands[3].reg;
12934
12935 reject_bad_reg (Rd);
12936 reject_bad_reg (Rn);
12937 reject_bad_reg (Rm);
12938 reject_bad_reg (Ra);
12939
12940 inst.instruction |= Rd << 8;
12941 inst.instruction |= Rn << 16;
12942 inst.instruction |= Rm;
12943 inst.instruction |= Ra << 12;
c19d1205 12944}
b99bd4ef 12945
c19d1205
ZW
12946static void
12947do_t_mlal (void)
12948{
fdfde340
JM
12949 unsigned RdLo, RdHi, Rn, Rm;
12950
12951 RdLo = inst.operands[0].reg;
12952 RdHi = inst.operands[1].reg;
12953 Rn = inst.operands[2].reg;
12954 Rm = inst.operands[3].reg;
12955
12956 reject_bad_reg (RdLo);
12957 reject_bad_reg (RdHi);
12958 reject_bad_reg (Rn);
12959 reject_bad_reg (Rm);
12960
12961 inst.instruction |= RdLo << 12;
12962 inst.instruction |= RdHi << 8;
12963 inst.instruction |= Rn << 16;
12964 inst.instruction |= Rm;
c19d1205 12965}
b99bd4ef 12966
c19d1205
ZW
12967static void
12968do_t_mov_cmp (void)
12969{
fdfde340
JM
12970 unsigned Rn, Rm;
12971
12972 Rn = inst.operands[0].reg;
12973 Rm = inst.operands[1].reg;
12974
e07e6e58 12975 if (Rn == REG_PC)
5ee91343 12976 set_pred_insn_type_last ();
e07e6e58 12977
c19d1205 12978 if (unified_syntax)
b99bd4ef 12979 {
c19d1205
ZW
12980 int r0off = (inst.instruction == T_MNEM_mov
12981 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 12982 unsigned long opcode;
3d388997
PB
12983 bfd_boolean narrow;
12984 bfd_boolean low_regs;
12985
fdfde340 12986 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 12987 opcode = inst.instruction;
5ee91343 12988 if (in_pred_block ())
0110f2b8 12989 narrow = opcode != T_MNEM_movs;
3d388997 12990 else
0110f2b8 12991 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
12992 if (inst.size_req == 4
12993 || inst.operands[1].shifted)
12994 narrow = FALSE;
12995
efd81785
PB
12996 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12997 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12998 && !inst.operands[1].shifted
fdfde340
JM
12999 && Rn == REG_PC
13000 && Rm == REG_LR)
efd81785
PB
13001 {
13002 inst.instruction = T2_SUBS_PC_LR;
13003 return;
13004 }
13005
fdfde340
JM
13006 if (opcode == T_MNEM_cmp)
13007 {
13008 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
13009 if (narrow)
13010 {
13011 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13012 but valid. */
13013 warn_deprecated_sp (Rm);
13014 /* R15 was documented as a valid choice for Rm in ARMv6,
13015 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13016 tools reject R15, so we do too. */
13017 constraint (Rm == REG_PC, BAD_PC);
13018 }
13019 else
13020 reject_bad_reg (Rm);
fdfde340
JM
13021 }
13022 else if (opcode == T_MNEM_mov
13023 || opcode == T_MNEM_movs)
13024 {
13025 if (inst.operands[1].isreg)
13026 {
13027 if (opcode == T_MNEM_movs)
13028 {
13029 reject_bad_reg (Rn);
13030 reject_bad_reg (Rm);
13031 }
76fa04a4
MGD
13032 else if (narrow)
13033 {
13034 /* This is mov.n. */
13035 if ((Rn == REG_SP || Rn == REG_PC)
13036 && (Rm == REG_SP || Rm == REG_PC))
13037 {
5c3696f8 13038 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
13039 "deprecated when r%u is the destination "
13040 "register."), Rm, Rn);
13041 }
13042 }
13043 else
13044 {
13045 /* This is mov.w. */
13046 constraint (Rn == REG_PC, BAD_PC);
13047 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
13048 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13049 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 13050 }
fdfde340
JM
13051 }
13052 else
13053 reject_bad_reg (Rn);
13054 }
13055
c19d1205
ZW
13056 if (!inst.operands[1].isreg)
13057 {
0110f2b8 13058 /* Immediate operand. */
5ee91343 13059 if (!in_pred_block () && opcode == T_MNEM_mov)
0110f2b8
PB
13060 narrow = 0;
13061 if (low_regs && narrow)
13062 {
13063 inst.instruction = THUMB_OP16 (opcode);
fdfde340 13064 inst.instruction |= Rn << 8;
e2b0ab59
AV
13065 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13066 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 13067 {
a9f02af8 13068 if (inst.size_req == 2)
e2b0ab59 13069 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
13070 else
13071 inst.relax = opcode;
72d98d16 13072 }
0110f2b8
PB
13073 }
13074 else
13075 {
e2b0ab59
AV
13076 constraint ((inst.relocs[0].type
13077 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13078 && (inst.relocs[0].type
13079 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
a9f02af8
MG
13080 THUMB1_RELOC_ONLY);
13081
0110f2b8
PB
13082 inst.instruction = THUMB_OP32 (inst.instruction);
13083 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13084 inst.instruction |= Rn << r0off;
e2b0ab59 13085 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8 13086 }
c19d1205 13087 }
728ca7c9
PB
13088 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13089 && (inst.instruction == T_MNEM_mov
13090 || inst.instruction == T_MNEM_movs))
13091 {
13092 /* Register shifts are encoded as separate shift instructions. */
13093 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13094
5ee91343 13095 if (in_pred_block ())
728ca7c9
PB
13096 narrow = !flags;
13097 else
13098 narrow = flags;
13099
13100 if (inst.size_req == 4)
13101 narrow = FALSE;
13102
13103 if (!low_regs || inst.operands[1].imm > 7)
13104 narrow = FALSE;
13105
fdfde340 13106 if (Rn != Rm)
728ca7c9
PB
13107 narrow = FALSE;
13108
13109 switch (inst.operands[1].shift_kind)
13110 {
13111 case SHIFT_LSL:
13112 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13113 break;
13114 case SHIFT_ASR:
13115 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13116 break;
13117 case SHIFT_LSR:
13118 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13119 break;
13120 case SHIFT_ROR:
13121 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13122 break;
13123 default:
5f4273c7 13124 abort ();
728ca7c9
PB
13125 }
13126
13127 inst.instruction = opcode;
13128 if (narrow)
13129 {
fdfde340 13130 inst.instruction |= Rn;
728ca7c9
PB
13131 inst.instruction |= inst.operands[1].imm << 3;
13132 }
13133 else
13134 {
13135 if (flags)
13136 inst.instruction |= CONDS_BIT;
13137
fdfde340
JM
13138 inst.instruction |= Rn << 8;
13139 inst.instruction |= Rm << 16;
728ca7c9
PB
13140 inst.instruction |= inst.operands[1].imm;
13141 }
13142 }
3d388997 13143 else if (!narrow)
c19d1205 13144 {
728ca7c9
PB
13145 /* Some mov with immediate shift have narrow variants.
13146 Register shifts are handled above. */
13147 if (low_regs && inst.operands[1].shifted
13148 && (inst.instruction == T_MNEM_mov
13149 || inst.instruction == T_MNEM_movs))
13150 {
5ee91343 13151 if (in_pred_block ())
728ca7c9
PB
13152 narrow = (inst.instruction == T_MNEM_mov);
13153 else
13154 narrow = (inst.instruction == T_MNEM_movs);
13155 }
13156
13157 if (narrow)
13158 {
13159 switch (inst.operands[1].shift_kind)
13160 {
13161 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13162 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13163 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13164 default: narrow = FALSE; break;
13165 }
13166 }
13167
13168 if (narrow)
13169 {
fdfde340
JM
13170 inst.instruction |= Rn;
13171 inst.instruction |= Rm << 3;
e2b0ab59 13172 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
728ca7c9
PB
13173 }
13174 else
13175 {
13176 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13177 inst.instruction |= Rn << r0off;
728ca7c9
PB
13178 encode_thumb32_shifted_operand (1);
13179 }
c19d1205
ZW
13180 }
13181 else
13182 switch (inst.instruction)
13183 {
13184 case T_MNEM_mov:
837b3435 13185 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
13186 results. Don't allow this. */
13187 if (low_regs)
13188 {
13189 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13190 "MOV Rd, Rs with two low registers is not "
13191 "permitted on this architecture");
fa94de6b 13192 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
13193 arm_ext_v6);
13194 }
13195
c19d1205 13196 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
13197 inst.instruction |= (Rn & 0x8) << 4;
13198 inst.instruction |= (Rn & 0x7);
13199 inst.instruction |= Rm << 3;
c19d1205 13200 break;
b99bd4ef 13201
c19d1205
ZW
13202 case T_MNEM_movs:
13203 /* We know we have low registers at this point.
941a8a52
MGD
13204 Generate LSLS Rd, Rs, #0. */
13205 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
13206 inst.instruction |= Rn;
13207 inst.instruction |= Rm << 3;
c19d1205
ZW
13208 break;
13209
13210 case T_MNEM_cmp:
3d388997 13211 if (low_regs)
c19d1205
ZW
13212 {
13213 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
13214 inst.instruction |= Rn;
13215 inst.instruction |= Rm << 3;
c19d1205
ZW
13216 }
13217 else
13218 {
13219 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
13220 inst.instruction |= (Rn & 0x8) << 4;
13221 inst.instruction |= (Rn & 0x7);
13222 inst.instruction |= Rm << 3;
c19d1205
ZW
13223 }
13224 break;
13225 }
b99bd4ef
NC
13226 return;
13227 }
13228
c19d1205 13229 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
13230
13231 /* PR 10443: Do not silently ignore shifted operands. */
13232 constraint (inst.operands[1].shifted,
13233 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13234
c19d1205 13235 if (inst.operands[1].isreg)
b99bd4ef 13236 {
fdfde340 13237 if (Rn < 8 && Rm < 8)
b99bd4ef 13238 {
c19d1205
ZW
13239 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13240 since a MOV instruction produces unpredictable results. */
13241 if (inst.instruction == T_OPCODE_MOV_I8)
13242 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 13243 else
c19d1205 13244 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 13245
fdfde340
JM
13246 inst.instruction |= Rn;
13247 inst.instruction |= Rm << 3;
b99bd4ef
NC
13248 }
13249 else
13250 {
c19d1205
ZW
13251 if (inst.instruction == T_OPCODE_MOV_I8)
13252 inst.instruction = T_OPCODE_MOV_HR;
13253 else
13254 inst.instruction = T_OPCODE_CMP_HR;
13255 do_t_cpy ();
b99bd4ef
NC
13256 }
13257 }
c19d1205 13258 else
b99bd4ef 13259 {
fdfde340 13260 constraint (Rn > 7,
c19d1205 13261 _("only lo regs allowed with immediate"));
fdfde340 13262 inst.instruction |= Rn << 8;
e2b0ab59 13263 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
c19d1205
ZW
13264 }
13265}
b99bd4ef 13266
c19d1205
ZW
13267static void
13268do_t_mov16 (void)
13269{
fdfde340 13270 unsigned Rd;
b6895b4f
PB
13271 bfd_vma imm;
13272 bfd_boolean top;
13273
13274 top = (inst.instruction & 0x00800000) != 0;
e2b0ab59 13275 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
b6895b4f 13276 {
33eaf5de 13277 constraint (top, _(":lower16: not allowed in this instruction"));
e2b0ab59 13278 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
b6895b4f 13279 }
e2b0ab59 13280 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
b6895b4f 13281 {
33eaf5de 13282 constraint (!top, _(":upper16: not allowed in this instruction"));
e2b0ab59 13283 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
b6895b4f
PB
13284 }
13285
fdfde340
JM
13286 Rd = inst.operands[0].reg;
13287 reject_bad_reg (Rd);
13288
13289 inst.instruction |= Rd << 8;
e2b0ab59 13290 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
b6895b4f 13291 {
e2b0ab59 13292 imm = inst.relocs[0].exp.X_add_number;
b6895b4f
PB
13293 inst.instruction |= (imm & 0xf000) << 4;
13294 inst.instruction |= (imm & 0x0800) << 15;
13295 inst.instruction |= (imm & 0x0700) << 4;
13296 inst.instruction |= (imm & 0x00ff);
13297 }
c19d1205 13298}
b99bd4ef 13299
c19d1205
ZW
13300static void
13301do_t_mvn_tst (void)
13302{
fdfde340 13303 unsigned Rn, Rm;
c921be7d 13304
fdfde340
JM
13305 Rn = inst.operands[0].reg;
13306 Rm = inst.operands[1].reg;
13307
13308 if (inst.instruction == T_MNEM_cmp
13309 || inst.instruction == T_MNEM_cmn)
13310 constraint (Rn == REG_PC, BAD_PC);
13311 else
13312 reject_bad_reg (Rn);
13313 reject_bad_reg (Rm);
13314
c19d1205
ZW
13315 if (unified_syntax)
13316 {
13317 int r0off = (inst.instruction == T_MNEM_mvn
13318 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
13319 bfd_boolean narrow;
13320
13321 if (inst.size_req == 4
13322 || inst.instruction > 0xffff
13323 || inst.operands[1].shifted
fdfde340 13324 || Rn > 7 || Rm > 7)
3d388997 13325 narrow = FALSE;
fe8b4cc3
KT
13326 else if (inst.instruction == T_MNEM_cmn
13327 || inst.instruction == T_MNEM_tst)
3d388997
PB
13328 narrow = TRUE;
13329 else if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13330 narrow = !in_pred_block ();
3d388997 13331 else
5ee91343 13332 narrow = in_pred_block ();
3d388997 13333
c19d1205 13334 if (!inst.operands[1].isreg)
b99bd4ef 13335 {
c19d1205
ZW
13336 /* For an immediate, we always generate a 32-bit opcode;
13337 section relaxation will shrink it later if possible. */
13338 if (inst.instruction < 0xffff)
13339 inst.instruction = THUMB_OP32 (inst.instruction);
13340 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 13341 inst.instruction |= Rn << r0off;
e2b0ab59 13342 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 13343 }
c19d1205 13344 else
b99bd4ef 13345 {
c19d1205 13346 /* See if we can do this with a 16-bit instruction. */
3d388997 13347 if (narrow)
b99bd4ef 13348 {
c19d1205 13349 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13350 inst.instruction |= Rn;
13351 inst.instruction |= Rm << 3;
b99bd4ef 13352 }
c19d1205 13353 else
b99bd4ef 13354 {
c19d1205
ZW
13355 constraint (inst.operands[1].shifted
13356 && inst.operands[1].immisreg,
13357 _("shift must be constant"));
13358 if (inst.instruction < 0xffff)
13359 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 13360 inst.instruction |= Rn << r0off;
c19d1205 13361 encode_thumb32_shifted_operand (1);
b99bd4ef 13362 }
b99bd4ef
NC
13363 }
13364 }
13365 else
13366 {
c19d1205
ZW
13367 constraint (inst.instruction > 0xffff
13368 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13369 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13370 _("unshifted register required"));
fdfde340 13371 constraint (Rn > 7 || Rm > 7,
c19d1205 13372 BAD_HIREG);
b99bd4ef 13373
c19d1205 13374 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13375 inst.instruction |= Rn;
13376 inst.instruction |= Rm << 3;
b99bd4ef 13377 }
b99bd4ef
NC
13378}
13379
b05fe5cf 13380static void
c19d1205 13381do_t_mrs (void)
b05fe5cf 13382{
fdfde340 13383 unsigned Rd;
037e8744
JB
13384
13385 if (do_vfp_nsyn_mrs () == SUCCESS)
13386 return;
13387
90ec0d68
MGD
13388 Rd = inst.operands[0].reg;
13389 reject_bad_reg (Rd);
13390 inst.instruction |= Rd << 8;
13391
13392 if (inst.operands[1].isreg)
62b3e311 13393 {
90ec0d68
MGD
13394 unsigned br = inst.operands[1].reg;
13395 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13396 as_bad (_("bad register for mrs"));
13397
13398 inst.instruction |= br & (0xf << 16);
13399 inst.instruction |= (br & 0x300) >> 4;
13400 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
13401 }
13402 else
13403 {
90ec0d68 13404 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 13405
d2cd1205 13406 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
13407 {
13408 /* PR gas/12698: The constraint is only applied for m_profile.
13409 If the user has specified -march=all, we want to ignore it as
13410 we are building for any CPU type, including non-m variants. */
823d2571
TG
13411 bfd_boolean m_profile =
13412 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
13413 constraint ((flags != 0) && m_profile, _("selected processor does "
13414 "not support requested special purpose register"));
13415 }
90ec0d68 13416 else
d2cd1205
JB
13417 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13418 devices). */
13419 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13420 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 13421
90ec0d68
MGD
13422 inst.instruction |= (flags & SPSR_BIT) >> 2;
13423 inst.instruction |= inst.operands[1].imm & 0xff;
13424 inst.instruction |= 0xf0000;
13425 }
c19d1205 13426}
b05fe5cf 13427
c19d1205
ZW
13428static void
13429do_t_msr (void)
13430{
62b3e311 13431 int flags;
fdfde340 13432 unsigned Rn;
62b3e311 13433
037e8744
JB
13434 if (do_vfp_nsyn_msr () == SUCCESS)
13435 return;
13436
c19d1205
ZW
13437 constraint (!inst.operands[1].isreg,
13438 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
13439
13440 if (inst.operands[0].isreg)
13441 flags = (int)(inst.operands[0].reg);
13442 else
13443 flags = inst.operands[0].imm;
13444
d2cd1205 13445 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 13446 {
d2cd1205
JB
13447 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13448
1a43faaf 13449 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
13450 If the user has specified -march=all, we want to ignore it as
13451 we are building for any CPU type, including non-m variants. */
823d2571
TG
13452 bfd_boolean m_profile =
13453 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 13454 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
13455 && (bits & ~(PSR_s | PSR_f)) != 0)
13456 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13457 && bits != PSR_f)) && m_profile,
13458 _("selected processor does not support requested special "
13459 "purpose register"));
62b3e311
PB
13460 }
13461 else
d2cd1205
JB
13462 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13463 "requested special purpose register"));
c921be7d 13464
fdfde340
JM
13465 Rn = inst.operands[1].reg;
13466 reject_bad_reg (Rn);
13467
62b3e311 13468 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
13469 inst.instruction |= (flags & 0xf0000) >> 8;
13470 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 13471 inst.instruction |= (flags & 0xff);
fdfde340 13472 inst.instruction |= Rn << 16;
c19d1205 13473}
b05fe5cf 13474
c19d1205
ZW
13475static void
13476do_t_mul (void)
13477{
17828f45 13478 bfd_boolean narrow;
fdfde340 13479 unsigned Rd, Rn, Rm;
17828f45 13480
c19d1205
ZW
13481 if (!inst.operands[2].present)
13482 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 13483
fdfde340
JM
13484 Rd = inst.operands[0].reg;
13485 Rn = inst.operands[1].reg;
13486 Rm = inst.operands[2].reg;
13487
17828f45 13488 if (unified_syntax)
b05fe5cf 13489 {
17828f45 13490 if (inst.size_req == 4
fdfde340
JM
13491 || (Rd != Rn
13492 && Rd != Rm)
13493 || Rn > 7
13494 || Rm > 7)
17828f45
JM
13495 narrow = FALSE;
13496 else if (inst.instruction == T_MNEM_muls)
5ee91343 13497 narrow = !in_pred_block ();
17828f45 13498 else
5ee91343 13499 narrow = in_pred_block ();
b05fe5cf 13500 }
c19d1205 13501 else
b05fe5cf 13502 {
17828f45 13503 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 13504 constraint (Rn > 7 || Rm > 7,
c19d1205 13505 BAD_HIREG);
17828f45
JM
13506 narrow = TRUE;
13507 }
b05fe5cf 13508
17828f45
JM
13509 if (narrow)
13510 {
13511 /* 16-bit MULS/Conditional MUL. */
c19d1205 13512 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 13513 inst.instruction |= Rd;
b05fe5cf 13514
fdfde340
JM
13515 if (Rd == Rn)
13516 inst.instruction |= Rm << 3;
13517 else if (Rd == Rm)
13518 inst.instruction |= Rn << 3;
c19d1205
ZW
13519 else
13520 constraint (1, _("dest must overlap one source register"));
13521 }
17828f45
JM
13522 else
13523 {
e07e6e58
NC
13524 constraint (inst.instruction != T_MNEM_mul,
13525 _("Thumb-2 MUL must not set flags"));
17828f45
JM
13526 /* 32-bit MUL. */
13527 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13528 inst.instruction |= Rd << 8;
13529 inst.instruction |= Rn << 16;
13530 inst.instruction |= Rm << 0;
13531
13532 reject_bad_reg (Rd);
13533 reject_bad_reg (Rn);
13534 reject_bad_reg (Rm);
17828f45 13535 }
c19d1205 13536}
b05fe5cf 13537
c19d1205
ZW
13538static void
13539do_t_mull (void)
13540{
fdfde340 13541 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 13542
fdfde340
JM
13543 RdLo = inst.operands[0].reg;
13544 RdHi = inst.operands[1].reg;
13545 Rn = inst.operands[2].reg;
13546 Rm = inst.operands[3].reg;
13547
13548 reject_bad_reg (RdLo);
13549 reject_bad_reg (RdHi);
13550 reject_bad_reg (Rn);
13551 reject_bad_reg (Rm);
13552
13553 inst.instruction |= RdLo << 12;
13554 inst.instruction |= RdHi << 8;
13555 inst.instruction |= Rn << 16;
13556 inst.instruction |= Rm;
13557
13558 if (RdLo == RdHi)
c19d1205
ZW
13559 as_tsktsk (_("rdhi and rdlo must be different"));
13560}
b05fe5cf 13561
c19d1205
ZW
13562static void
13563do_t_nop (void)
13564{
5ee91343 13565 set_pred_insn_type (NEUTRAL_IT_INSN);
e07e6e58 13566
c19d1205
ZW
13567 if (unified_syntax)
13568 {
13569 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 13570 {
c19d1205
ZW
13571 inst.instruction = THUMB_OP32 (inst.instruction);
13572 inst.instruction |= inst.operands[0].imm;
13573 }
13574 else
13575 {
bc2d1808
NC
13576 /* PR9722: Check for Thumb2 availability before
13577 generating a thumb2 nop instruction. */
afa62d5e 13578 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
13579 {
13580 inst.instruction = THUMB_OP16 (inst.instruction);
13581 inst.instruction |= inst.operands[0].imm << 4;
13582 }
13583 else
13584 inst.instruction = 0x46c0;
c19d1205
ZW
13585 }
13586 }
13587 else
13588 {
13589 constraint (inst.operands[0].present,
13590 _("Thumb does not support NOP with hints"));
13591 inst.instruction = 0x46c0;
13592 }
13593}
b05fe5cf 13594
c19d1205
ZW
13595static void
13596do_t_neg (void)
13597{
13598 if (unified_syntax)
13599 {
3d388997
PB
13600 bfd_boolean narrow;
13601
13602 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13603 narrow = !in_pred_block ();
3d388997 13604 else
5ee91343 13605 narrow = in_pred_block ();
3d388997
PB
13606 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13607 narrow = FALSE;
13608 if (inst.size_req == 4)
13609 narrow = FALSE;
13610
13611 if (!narrow)
c19d1205
ZW
13612 {
13613 inst.instruction = THUMB_OP32 (inst.instruction);
13614 inst.instruction |= inst.operands[0].reg << 8;
13615 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
13616 }
13617 else
13618 {
c19d1205
ZW
13619 inst.instruction = THUMB_OP16 (inst.instruction);
13620 inst.instruction |= inst.operands[0].reg;
13621 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
13622 }
13623 }
13624 else
13625 {
c19d1205
ZW
13626 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13627 BAD_HIREG);
13628 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13629
13630 inst.instruction = THUMB_OP16 (inst.instruction);
13631 inst.instruction |= inst.operands[0].reg;
13632 inst.instruction |= inst.operands[1].reg << 3;
13633 }
13634}
13635
1c444d06
JM
13636static void
13637do_t_orn (void)
13638{
13639 unsigned Rd, Rn;
13640
13641 Rd = inst.operands[0].reg;
13642 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13643
fdfde340
JM
13644 reject_bad_reg (Rd);
13645 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13646 reject_bad_reg (Rn);
13647
1c444d06
JM
13648 inst.instruction |= Rd << 8;
13649 inst.instruction |= Rn << 16;
13650
13651 if (!inst.operands[2].isreg)
13652 {
13653 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13654 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
1c444d06
JM
13655 }
13656 else
13657 {
13658 unsigned Rm;
13659
13660 Rm = inst.operands[2].reg;
fdfde340 13661 reject_bad_reg (Rm);
1c444d06
JM
13662
13663 constraint (inst.operands[2].shifted
13664 && inst.operands[2].immisreg,
13665 _("shift must be constant"));
13666 encode_thumb32_shifted_operand (2);
13667 }
13668}
13669
c19d1205
ZW
13670static void
13671do_t_pkhbt (void)
13672{
fdfde340
JM
13673 unsigned Rd, Rn, Rm;
13674
13675 Rd = inst.operands[0].reg;
13676 Rn = inst.operands[1].reg;
13677 Rm = inst.operands[2].reg;
13678
13679 reject_bad_reg (Rd);
13680 reject_bad_reg (Rn);
13681 reject_bad_reg (Rm);
13682
13683 inst.instruction |= Rd << 8;
13684 inst.instruction |= Rn << 16;
13685 inst.instruction |= Rm;
c19d1205
ZW
13686 if (inst.operands[3].present)
13687 {
e2b0ab59
AV
13688 unsigned int val = inst.relocs[0].exp.X_add_number;
13689 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205
ZW
13690 _("expression too complex"));
13691 inst.instruction |= (val & 0x1c) << 10;
13692 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 13693 }
c19d1205 13694}
b05fe5cf 13695
c19d1205
ZW
13696static void
13697do_t_pkhtb (void)
13698{
13699 if (!inst.operands[3].present)
1ef52f49
NC
13700 {
13701 unsigned Rtmp;
13702
13703 inst.instruction &= ~0x00000020;
13704
13705 /* PR 10168. Swap the Rm and Rn registers. */
13706 Rtmp = inst.operands[1].reg;
13707 inst.operands[1].reg = inst.operands[2].reg;
13708 inst.operands[2].reg = Rtmp;
13709 }
c19d1205 13710 do_t_pkhbt ();
b05fe5cf
ZW
13711}
13712
c19d1205
ZW
13713static void
13714do_t_pld (void)
13715{
fdfde340
JM
13716 if (inst.operands[0].immisreg)
13717 reject_bad_reg (inst.operands[0].imm);
13718
c19d1205
ZW
13719 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13720}
b05fe5cf 13721
c19d1205
ZW
13722static void
13723do_t_push_pop (void)
b99bd4ef 13724{
e9f89963 13725 unsigned mask;
5f4273c7 13726
c19d1205
ZW
13727 constraint (inst.operands[0].writeback,
13728 _("push/pop do not support {reglist}^"));
e2b0ab59 13729 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
c19d1205 13730 _("expression too complex"));
b99bd4ef 13731
e9f89963 13732 mask = inst.operands[0].imm;
d3bfe16e 13733 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 13734 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 13735 else if (inst.size_req != 4
c6025a80 13736 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 13737 ? REG_LR : REG_PC)))
b99bd4ef 13738 {
c19d1205
ZW
13739 inst.instruction = THUMB_OP16 (inst.instruction);
13740 inst.instruction |= THUMB_PP_PC_LR;
3c707909 13741 inst.instruction |= mask & 0xff;
c19d1205
ZW
13742 }
13743 else if (unified_syntax)
13744 {
3c707909 13745 inst.instruction = THUMB_OP32 (inst.instruction);
4b5a202f
AV
13746 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13747 }
13748 else
13749 {
13750 inst.error = _("invalid register list to push/pop instruction");
13751 return;
c19d1205 13752 }
4b5a202f
AV
13753}
13754
13755static void
13756do_t_clrm (void)
13757{
13758 if (unified_syntax)
13759 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
c19d1205
ZW
13760 else
13761 {
13762 inst.error = _("invalid register list to push/pop instruction");
13763 return;
13764 }
c19d1205 13765}
b99bd4ef 13766
efd6b359
AV
13767static void
13768do_t_vscclrm (void)
13769{
13770 if (inst.operands[0].issingle)
13771 {
13772 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13773 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13774 inst.instruction |= inst.operands[0].imm;
13775 }
13776 else
13777 {
13778 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13779 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13780 inst.instruction |= 1 << 8;
13781 inst.instruction |= inst.operands[0].imm << 1;
13782 }
13783}
13784
c19d1205
ZW
13785static void
13786do_t_rbit (void)
13787{
fdfde340
JM
13788 unsigned Rd, Rm;
13789
13790 Rd = inst.operands[0].reg;
13791 Rm = inst.operands[1].reg;
13792
13793 reject_bad_reg (Rd);
13794 reject_bad_reg (Rm);
13795
13796 inst.instruction |= Rd << 8;
13797 inst.instruction |= Rm << 16;
13798 inst.instruction |= Rm;
c19d1205 13799}
b99bd4ef 13800
c19d1205
ZW
13801static void
13802do_t_rev (void)
13803{
fdfde340
JM
13804 unsigned Rd, Rm;
13805
13806 Rd = inst.operands[0].reg;
13807 Rm = inst.operands[1].reg;
13808
13809 reject_bad_reg (Rd);
13810 reject_bad_reg (Rm);
13811
13812 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
13813 && inst.size_req != 4)
13814 {
13815 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13816 inst.instruction |= Rd;
13817 inst.instruction |= Rm << 3;
c19d1205
ZW
13818 }
13819 else if (unified_syntax)
13820 {
13821 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13822 inst.instruction |= Rd << 8;
13823 inst.instruction |= Rm << 16;
13824 inst.instruction |= Rm;
c19d1205
ZW
13825 }
13826 else
13827 inst.error = BAD_HIREG;
13828}
b99bd4ef 13829
1c444d06
JM
13830static void
13831do_t_rrx (void)
13832{
13833 unsigned Rd, Rm;
13834
13835 Rd = inst.operands[0].reg;
13836 Rm = inst.operands[1].reg;
13837
fdfde340
JM
13838 reject_bad_reg (Rd);
13839 reject_bad_reg (Rm);
c921be7d 13840
1c444d06
JM
13841 inst.instruction |= Rd << 8;
13842 inst.instruction |= Rm;
13843}
13844
c19d1205
ZW
13845static void
13846do_t_rsb (void)
13847{
fdfde340 13848 unsigned Rd, Rs;
b99bd4ef 13849
c19d1205
ZW
13850 Rd = inst.operands[0].reg;
13851 Rs = (inst.operands[1].present
13852 ? inst.operands[1].reg /* Rd, Rs, foo */
13853 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 13854
fdfde340
JM
13855 reject_bad_reg (Rd);
13856 reject_bad_reg (Rs);
13857 if (inst.operands[2].isreg)
13858 reject_bad_reg (inst.operands[2].reg);
13859
c19d1205
ZW
13860 inst.instruction |= Rd << 8;
13861 inst.instruction |= Rs << 16;
13862 if (!inst.operands[2].isreg)
13863 {
026d3abb
PB
13864 bfd_boolean narrow;
13865
13866 if ((inst.instruction & 0x00100000) != 0)
5ee91343 13867 narrow = !in_pred_block ();
026d3abb 13868 else
5ee91343 13869 narrow = in_pred_block ();
026d3abb
PB
13870
13871 if (Rd > 7 || Rs > 7)
13872 narrow = FALSE;
13873
13874 if (inst.size_req == 4 || !unified_syntax)
13875 narrow = FALSE;
13876
e2b0ab59
AV
13877 if (inst.relocs[0].exp.X_op != O_constant
13878 || inst.relocs[0].exp.X_add_number != 0)
026d3abb
PB
13879 narrow = FALSE;
13880
13881 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 13882 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
13883 if (narrow)
13884 {
e2b0ab59 13885 inst.relocs[0].type = BFD_RELOC_UNUSED;
026d3abb
PB
13886 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13887 inst.instruction |= Rs << 3;
13888 inst.instruction |= Rd;
13889 }
13890 else
13891 {
13892 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
e2b0ab59 13893 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
026d3abb 13894 }
c19d1205
ZW
13895 }
13896 else
13897 encode_thumb32_shifted_operand (2);
13898}
b99bd4ef 13899
c19d1205
ZW
13900static void
13901do_t_setend (void)
13902{
12e37cbc
MGD
13903 if (warn_on_deprecated
13904 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 13905 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 13906
5ee91343 13907 set_pred_insn_type (OUTSIDE_PRED_INSN);
c19d1205
ZW
13908 if (inst.operands[0].imm)
13909 inst.instruction |= 0x8;
13910}
b99bd4ef 13911
c19d1205
ZW
13912static void
13913do_t_shift (void)
13914{
13915 if (!inst.operands[1].present)
13916 inst.operands[1].reg = inst.operands[0].reg;
13917
13918 if (unified_syntax)
13919 {
3d388997
PB
13920 bfd_boolean narrow;
13921 int shift_kind;
13922
13923 switch (inst.instruction)
13924 {
13925 case T_MNEM_asr:
13926 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13927 case T_MNEM_lsl:
13928 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13929 case T_MNEM_lsr:
13930 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13931 case T_MNEM_ror:
13932 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13933 default: abort ();
13934 }
13935
13936 if (THUMB_SETS_FLAGS (inst.instruction))
5ee91343 13937 narrow = !in_pred_block ();
3d388997 13938 else
5ee91343 13939 narrow = in_pred_block ();
3d388997
PB
13940 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13941 narrow = FALSE;
13942 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13943 narrow = FALSE;
13944 if (inst.operands[2].isreg
13945 && (inst.operands[1].reg != inst.operands[0].reg
13946 || inst.operands[2].reg > 7))
13947 narrow = FALSE;
13948 if (inst.size_req == 4)
13949 narrow = FALSE;
13950
fdfde340
JM
13951 reject_bad_reg (inst.operands[0].reg);
13952 reject_bad_reg (inst.operands[1].reg);
c921be7d 13953
3d388997 13954 if (!narrow)
c19d1205
ZW
13955 {
13956 if (inst.operands[2].isreg)
b99bd4ef 13957 {
fdfde340 13958 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
13959 inst.instruction = THUMB_OP32 (inst.instruction);
13960 inst.instruction |= inst.operands[0].reg << 8;
13961 inst.instruction |= inst.operands[1].reg << 16;
13962 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
13963
13964 /* PR 12854: Error on extraneous shifts. */
13965 constraint (inst.operands[2].shifted,
13966 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
13967 }
13968 else
13969 {
13970 inst.operands[1].shifted = 1;
3d388997 13971 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
13972 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13973 ? T_MNEM_movs : T_MNEM_mov);
13974 inst.instruction |= inst.operands[0].reg << 8;
13975 encode_thumb32_shifted_operand (1);
13976 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
e2b0ab59 13977 inst.relocs[0].type = BFD_RELOC_UNUSED;
b99bd4ef
NC
13978 }
13979 }
13980 else
13981 {
c19d1205 13982 if (inst.operands[2].isreg)
b99bd4ef 13983 {
3d388997 13984 switch (shift_kind)
b99bd4ef 13985 {
3d388997
PB
13986 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13987 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13988 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13989 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 13990 default: abort ();
b99bd4ef 13991 }
5f4273c7 13992
c19d1205
ZW
13993 inst.instruction |= inst.operands[0].reg;
13994 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
13995
13996 /* PR 12854: Error on extraneous shifts. */
13997 constraint (inst.operands[2].shifted,
13998 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
13999 }
14000 else
14001 {
3d388997 14002 switch (shift_kind)
b99bd4ef 14003 {
3d388997
PB
14004 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
14005 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
14006 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 14007 default: abort ();
b99bd4ef 14008 }
e2b0ab59 14009 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14010 inst.instruction |= inst.operands[0].reg;
14011 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14012 }
14013 }
c19d1205
ZW
14014 }
14015 else
14016 {
14017 constraint (inst.operands[0].reg > 7
14018 || inst.operands[1].reg > 7, BAD_HIREG);
14019 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 14020
c19d1205
ZW
14021 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14022 {
14023 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14024 constraint (inst.operands[0].reg != inst.operands[1].reg,
14025 _("source1 and dest must be same register"));
b99bd4ef 14026
c19d1205
ZW
14027 switch (inst.instruction)
14028 {
14029 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14030 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14031 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14032 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14033 default: abort ();
14034 }
5f4273c7 14035
c19d1205
ZW
14036 inst.instruction |= inst.operands[0].reg;
14037 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
14038
14039 /* PR 12854: Error on extraneous shifts. */
14040 constraint (inst.operands[2].shifted,
14041 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
14042 }
14043 else
b99bd4ef 14044 {
c19d1205
ZW
14045 switch (inst.instruction)
14046 {
14047 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14048 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14049 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14050 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14051 default: abort ();
14052 }
e2b0ab59 14053 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
c19d1205
ZW
14054 inst.instruction |= inst.operands[0].reg;
14055 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
14056 }
14057 }
b99bd4ef
NC
14058}
14059
14060static void
c19d1205 14061do_t_simd (void)
b99bd4ef 14062{
fdfde340
JM
14063 unsigned Rd, Rn, Rm;
14064
14065 Rd = inst.operands[0].reg;
14066 Rn = inst.operands[1].reg;
14067 Rm = inst.operands[2].reg;
14068
14069 reject_bad_reg (Rd);
14070 reject_bad_reg (Rn);
14071 reject_bad_reg (Rm);
14072
14073 inst.instruction |= Rd << 8;
14074 inst.instruction |= Rn << 16;
14075 inst.instruction |= Rm;
c19d1205 14076}
b99bd4ef 14077
03ee1b7f
NC
14078static void
14079do_t_simd2 (void)
14080{
14081 unsigned Rd, Rn, Rm;
14082
14083 Rd = inst.operands[0].reg;
14084 Rm = inst.operands[1].reg;
14085 Rn = inst.operands[2].reg;
14086
14087 reject_bad_reg (Rd);
14088 reject_bad_reg (Rn);
14089 reject_bad_reg (Rm);
14090
14091 inst.instruction |= Rd << 8;
14092 inst.instruction |= Rn << 16;
14093 inst.instruction |= Rm;
14094}
14095
c19d1205 14096static void
3eb17e6b 14097do_t_smc (void)
c19d1205 14098{
e2b0ab59 14099 unsigned int value = inst.relocs[0].exp.X_add_number;
f4c65163
MGD
14100 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14101 _("SMC is not permitted on this architecture"));
e2b0ab59 14102 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14103 _("expression too complex"));
ba85f98c
BW
14104 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14105
e2b0ab59 14106 inst.relocs[0].type = BFD_RELOC_UNUSED;
c19d1205 14107 inst.instruction |= (value & 0x000f) << 16;
ba85f98c 14108
24382199 14109 /* PR gas/15623: SMC instructions must be last in an IT block. */
5ee91343 14110 set_pred_insn_type_last ();
c19d1205 14111}
b99bd4ef 14112
90ec0d68
MGD
14113static void
14114do_t_hvc (void)
14115{
e2b0ab59 14116 unsigned int value = inst.relocs[0].exp.X_add_number;
90ec0d68 14117
e2b0ab59 14118 inst.relocs[0].type = BFD_RELOC_UNUSED;
90ec0d68
MGD
14119 inst.instruction |= (value & 0x0fff);
14120 inst.instruction |= (value & 0xf000) << 4;
14121}
14122
c19d1205 14123static void
3a21c15a 14124do_t_ssat_usat (int bias)
c19d1205 14125{
fdfde340
JM
14126 unsigned Rd, Rn;
14127
14128 Rd = inst.operands[0].reg;
14129 Rn = inst.operands[2].reg;
14130
14131 reject_bad_reg (Rd);
14132 reject_bad_reg (Rn);
14133
14134 inst.instruction |= Rd << 8;
3a21c15a 14135 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 14136 inst.instruction |= Rn << 16;
b99bd4ef 14137
c19d1205 14138 if (inst.operands[3].present)
b99bd4ef 14139 {
e2b0ab59 14140 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
3a21c15a 14141
e2b0ab59 14142 inst.relocs[0].type = BFD_RELOC_UNUSED;
3a21c15a 14143
e2b0ab59 14144 constraint (inst.relocs[0].exp.X_op != O_constant,
c19d1205 14145 _("expression too complex"));
b99bd4ef 14146
3a21c15a 14147 if (shift_amount != 0)
6189168b 14148 {
3a21c15a
NC
14149 constraint (shift_amount > 31,
14150 _("shift expression is too large"));
14151
c19d1205 14152 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
14153 inst.instruction |= 0x00200000; /* sh bit. */
14154
14155 inst.instruction |= (shift_amount & 0x1c) << 10;
14156 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
14157 }
14158 }
b99bd4ef 14159}
c921be7d 14160
3a21c15a
NC
14161static void
14162do_t_ssat (void)
14163{
14164 do_t_ssat_usat (1);
14165}
b99bd4ef 14166
0dd132b6 14167static void
c19d1205 14168do_t_ssat16 (void)
0dd132b6 14169{
fdfde340
JM
14170 unsigned Rd, Rn;
14171
14172 Rd = inst.operands[0].reg;
14173 Rn = inst.operands[2].reg;
14174
14175 reject_bad_reg (Rd);
14176 reject_bad_reg (Rn);
14177
14178 inst.instruction |= Rd << 8;
c19d1205 14179 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 14180 inst.instruction |= Rn << 16;
c19d1205 14181}
0dd132b6 14182
c19d1205
ZW
14183static void
14184do_t_strex (void)
14185{
14186 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14187 || inst.operands[2].postind || inst.operands[2].writeback
14188 || inst.operands[2].immisreg || inst.operands[2].shifted
14189 || inst.operands[2].negative,
01cfc07f 14190 BAD_ADDR_MODE);
0dd132b6 14191
5be8be5d
DG
14192 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14193
c19d1205
ZW
14194 inst.instruction |= inst.operands[0].reg << 8;
14195 inst.instruction |= inst.operands[1].reg << 12;
14196 inst.instruction |= inst.operands[2].reg << 16;
e2b0ab59 14197 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
14198}
14199
b99bd4ef 14200static void
c19d1205 14201do_t_strexd (void)
b99bd4ef 14202{
c19d1205
ZW
14203 if (!inst.operands[2].present)
14204 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 14205
c19d1205
ZW
14206 constraint (inst.operands[0].reg == inst.operands[1].reg
14207 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 14208 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 14209 BAD_OVERLAP);
b99bd4ef 14210
c19d1205
ZW
14211 inst.instruction |= inst.operands[0].reg;
14212 inst.instruction |= inst.operands[1].reg << 12;
14213 inst.instruction |= inst.operands[2].reg << 8;
14214 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
14215}
14216
14217static void
c19d1205 14218do_t_sxtah (void)
b99bd4ef 14219{
fdfde340
JM
14220 unsigned Rd, Rn, Rm;
14221
14222 Rd = inst.operands[0].reg;
14223 Rn = inst.operands[1].reg;
14224 Rm = inst.operands[2].reg;
14225
14226 reject_bad_reg (Rd);
14227 reject_bad_reg (Rn);
14228 reject_bad_reg (Rm);
14229
14230 inst.instruction |= Rd << 8;
14231 inst.instruction |= Rn << 16;
14232 inst.instruction |= Rm;
c19d1205
ZW
14233 inst.instruction |= inst.operands[3].imm << 4;
14234}
b99bd4ef 14235
c19d1205
ZW
14236static void
14237do_t_sxth (void)
14238{
fdfde340
JM
14239 unsigned Rd, Rm;
14240
14241 Rd = inst.operands[0].reg;
14242 Rm = inst.operands[1].reg;
14243
14244 reject_bad_reg (Rd);
14245 reject_bad_reg (Rm);
c921be7d
NC
14246
14247 if (inst.instruction <= 0xffff
14248 && inst.size_req != 4
fdfde340 14249 && Rd <= 7 && Rm <= 7
c19d1205 14250 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 14251 {
c19d1205 14252 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
14253 inst.instruction |= Rd;
14254 inst.instruction |= Rm << 3;
b99bd4ef 14255 }
c19d1205 14256 else if (unified_syntax)
b99bd4ef 14257 {
c19d1205
ZW
14258 if (inst.instruction <= 0xffff)
14259 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
14260 inst.instruction |= Rd << 8;
14261 inst.instruction |= Rm;
c19d1205 14262 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 14263 }
c19d1205 14264 else
b99bd4ef 14265 {
c19d1205
ZW
14266 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14267 _("Thumb encoding does not support rotation"));
14268 constraint (1, BAD_HIREG);
b99bd4ef 14269 }
c19d1205 14270}
b99bd4ef 14271
c19d1205
ZW
14272static void
14273do_t_swi (void)
14274{
e2b0ab59 14275 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
c19d1205 14276}
b99bd4ef 14277
92e90b6e
PB
14278static void
14279do_t_tb (void)
14280{
fdfde340 14281 unsigned Rn, Rm;
92e90b6e
PB
14282 int half;
14283
14284 half = (inst.instruction & 0x10) != 0;
5ee91343 14285 set_pred_insn_type_last ();
dfa9f0d5
PB
14286 constraint (inst.operands[0].immisreg,
14287 _("instruction requires register index"));
fdfde340
JM
14288
14289 Rn = inst.operands[0].reg;
14290 Rm = inst.operands[0].imm;
c921be7d 14291
5c8ed6a4
JW
14292 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14293 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
14294 reject_bad_reg (Rm);
14295
92e90b6e
PB
14296 constraint (!half && inst.operands[0].shifted,
14297 _("instruction does not allow shifted index"));
fdfde340 14298 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
14299}
14300
74db7efb
NC
14301static void
14302do_t_udf (void)
14303{
14304 if (!inst.operands[0].present)
14305 inst.operands[0].imm = 0;
14306
14307 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14308 {
14309 constraint (inst.size_req == 2,
14310 _("immediate value out of range"));
14311 inst.instruction = THUMB_OP32 (inst.instruction);
14312 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14313 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14314 }
14315 else
14316 {
14317 inst.instruction = THUMB_OP16 (inst.instruction);
14318 inst.instruction |= inst.operands[0].imm;
14319 }
14320
5ee91343 14321 set_pred_insn_type (NEUTRAL_IT_INSN);
74db7efb
NC
14322}
14323
14324
c19d1205
ZW
14325static void
14326do_t_usat (void)
14327{
3a21c15a 14328 do_t_ssat_usat (0);
b99bd4ef
NC
14329}
14330
14331static void
c19d1205 14332do_t_usat16 (void)
b99bd4ef 14333{
fdfde340
JM
14334 unsigned Rd, Rn;
14335
14336 Rd = inst.operands[0].reg;
14337 Rn = inst.operands[2].reg;
14338
14339 reject_bad_reg (Rd);
14340 reject_bad_reg (Rn);
14341
14342 inst.instruction |= Rd << 8;
c19d1205 14343 inst.instruction |= inst.operands[1].imm;
fdfde340 14344 inst.instruction |= Rn << 16;
b99bd4ef 14345}
c19d1205 14346
e12437dc
AV
14347/* Checking the range of the branch offset (VAL) with NBITS bits
14348 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14349static int
14350v8_1_branch_value_check (int val, int nbits, int is_signed)
14351{
14352 gas_assert (nbits > 0 && nbits <= 32);
14353 if (is_signed)
14354 {
14355 int cmp = (1 << (nbits - 1));
14356 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14357 return FAIL;
14358 }
14359 else
14360 {
14361 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14362 return FAIL;
14363 }
14364 return SUCCESS;
14365}
14366
4389b29a
AV
14367/* For branches in Armv8.1-M Mainline. */
14368static void
14369do_t_branch_future (void)
14370{
14371 unsigned long insn = inst.instruction;
14372
14373 inst.instruction = THUMB_OP32 (inst.instruction);
14374 if (inst.operands[0].hasreloc == 0)
14375 {
14376 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14377 as_bad (BAD_BRANCH_OFF);
14378
14379 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14380 }
14381 else
14382 {
14383 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14384 inst.relocs[0].pc_rel = 1;
14385 }
14386
14387 switch (insn)
14388 {
14389 case T_MNEM_bf:
14390 if (inst.operands[1].hasreloc == 0)
14391 {
14392 int val = inst.operands[1].imm;
14393 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14394 as_bad (BAD_BRANCH_OFF);
14395
14396 int immA = (val & 0x0001f000) >> 12;
14397 int immB = (val & 0x00000ffc) >> 2;
14398 int immC = (val & 0x00000002) >> 1;
14399 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14400 }
14401 else
14402 {
14403 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14404 inst.relocs[1].pc_rel = 1;
14405 }
14406 break;
14407
65d1bc05
AV
14408 case T_MNEM_bfl:
14409 if (inst.operands[1].hasreloc == 0)
14410 {
14411 int val = inst.operands[1].imm;
14412 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14413 as_bad (BAD_BRANCH_OFF);
14414
14415 int immA = (val & 0x0007f000) >> 12;
14416 int immB = (val & 0x00000ffc) >> 2;
14417 int immC = (val & 0x00000002) >> 1;
14418 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14419 }
14420 else
14421 {
14422 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14423 inst.relocs[1].pc_rel = 1;
14424 }
14425 break;
14426
f6b2b12d
AV
14427 case T_MNEM_bfcsel:
14428 /* Operand 1. */
14429 if (inst.operands[1].hasreloc == 0)
14430 {
14431 int val = inst.operands[1].imm;
14432 int immA = (val & 0x00001000) >> 12;
14433 int immB = (val & 0x00000ffc) >> 2;
14434 int immC = (val & 0x00000002) >> 1;
14435 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14436 }
14437 else
14438 {
14439 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14440 inst.relocs[1].pc_rel = 1;
14441 }
14442
14443 /* Operand 2. */
14444 if (inst.operands[2].hasreloc == 0)
14445 {
14446 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14447 int val2 = inst.operands[2].imm;
14448 int val0 = inst.operands[0].imm & 0x1f;
14449 int diff = val2 - val0;
14450 if (diff == 4)
14451 inst.instruction |= 1 << 17; /* T bit. */
14452 else if (diff != 2)
14453 as_bad (_("out of range label-relative fixup value"));
14454 }
14455 else
14456 {
14457 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14458 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14459 inst.relocs[2].pc_rel = 1;
14460 }
14461
14462 /* Operand 3. */
14463 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14464 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14465 break;
14466
f1c7f421
AV
14467 case T_MNEM_bfx:
14468 case T_MNEM_bflx:
14469 inst.instruction |= inst.operands[1].reg << 16;
14470 break;
14471
4389b29a
AV
14472 default: abort ();
14473 }
14474}
14475
60f993ce
AV
14476/* Helper function for do_t_loloop to handle relocations. */
14477static void
14478v8_1_loop_reloc (int is_le)
14479{
14480 if (inst.relocs[0].exp.X_op == O_constant)
14481 {
14482 int value = inst.relocs[0].exp.X_add_number;
14483 value = (is_le) ? -value : value;
14484
14485 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14486 as_bad (BAD_BRANCH_OFF);
14487
14488 int imml, immh;
14489
14490 immh = (value & 0x00000ffc) >> 2;
14491 imml = (value & 0x00000002) >> 1;
14492
14493 inst.instruction |= (imml << 11) | (immh << 1);
14494 }
14495 else
14496 {
14497 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14498 inst.relocs[0].pc_rel = 1;
14499 }
14500}
14501
08132bdd
SP
14502/* For shifts with four operands in MVE. */
14503static void
14504do_mve_scalar_shift1 (void)
14505{
14506 unsigned int value = inst.operands[2].imm;
14507
14508 inst.instruction |= inst.operands[0].reg << 16;
14509 inst.instruction |= inst.operands[1].reg << 8;
14510
14511 /* Setting the bit for saturation. */
14512 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14513
14514 /* Assuming Rm is already checked not to be 11x1. */
14515 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14516 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14517 inst.instruction |= inst.operands[3].reg << 12;
14518}
14519
23d00a41
SD
14520/* For shifts in MVE. */
14521static void
14522do_mve_scalar_shift (void)
14523{
14524 if (!inst.operands[2].present)
14525 {
14526 inst.operands[2] = inst.operands[1];
14527 inst.operands[1].reg = 0xf;
14528 }
14529
14530 inst.instruction |= inst.operands[0].reg << 16;
14531 inst.instruction |= inst.operands[1].reg << 8;
14532
14533 if (inst.operands[2].isreg)
14534 {
14535 /* Assuming Rm is already checked not to be 11x1. */
14536 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14537 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14538 inst.instruction |= inst.operands[2].reg << 12;
14539 }
14540 else
14541 {
14542 /* Assuming imm is already checked as [1,32]. */
14543 unsigned int value = inst.operands[2].imm;
14544 inst.instruction |= (value & 0x1c) << 10;
14545 inst.instruction |= (value & 0x03) << 6;
14546 /* Change last 4 bits from 0xd to 0xf. */
14547 inst.instruction |= 0x2;
14548 }
14549}
14550
a302e574
AV
14551/* MVE instruction encoder helpers. */
14552#define M_MNEM_vabav 0xee800f01
14553#define M_MNEM_vmladav 0xeef00e00
14554#define M_MNEM_vmladava 0xeef00e20
14555#define M_MNEM_vmladavx 0xeef01e00
14556#define M_MNEM_vmladavax 0xeef01e20
14557#define M_MNEM_vmlsdav 0xeef00e01
14558#define M_MNEM_vmlsdava 0xeef00e21
14559#define M_MNEM_vmlsdavx 0xeef01e01
14560#define M_MNEM_vmlsdavax 0xeef01e21
886e1c73
AV
14561#define M_MNEM_vmullt 0xee011e00
14562#define M_MNEM_vmullb 0xee010e00
efd0b310 14563#define M_MNEM_vctp 0xf000e801
35c228db
AV
14564#define M_MNEM_vst20 0xfc801e00
14565#define M_MNEM_vst21 0xfc801e20
14566#define M_MNEM_vst40 0xfc801e01
14567#define M_MNEM_vst41 0xfc801e21
14568#define M_MNEM_vst42 0xfc801e41
14569#define M_MNEM_vst43 0xfc801e61
14570#define M_MNEM_vld20 0xfc901e00
14571#define M_MNEM_vld21 0xfc901e20
14572#define M_MNEM_vld40 0xfc901e01
14573#define M_MNEM_vld41 0xfc901e21
14574#define M_MNEM_vld42 0xfc901e41
14575#define M_MNEM_vld43 0xfc901e61
f5f10c66
AV
14576#define M_MNEM_vstrb 0xec000e00
14577#define M_MNEM_vstrh 0xec000e10
14578#define M_MNEM_vstrw 0xec000e40
14579#define M_MNEM_vstrd 0xec000e50
14580#define M_MNEM_vldrb 0xec100e00
14581#define M_MNEM_vldrh 0xec100e10
14582#define M_MNEM_vldrw 0xec100e40
14583#define M_MNEM_vldrd 0xec100e50
57785aa2
AV
14584#define M_MNEM_vmovlt 0xeea01f40
14585#define M_MNEM_vmovlb 0xeea00f40
14586#define M_MNEM_vmovnt 0xfe311e81
14587#define M_MNEM_vmovnb 0xfe310e81
c2dafc2a
AV
14588#define M_MNEM_vadc 0xee300f00
14589#define M_MNEM_vadci 0xee301f00
14590#define M_MNEM_vbrsr 0xfe011e60
26c1e780
AV
14591#define M_MNEM_vaddlv 0xee890f00
14592#define M_MNEM_vaddlva 0xee890f20
14593#define M_MNEM_vaddv 0xeef10f00
14594#define M_MNEM_vaddva 0xeef10f20
b409bdb6
AV
14595#define M_MNEM_vddup 0xee011f6e
14596#define M_MNEM_vdwdup 0xee011f60
14597#define M_MNEM_vidup 0xee010f6e
14598#define M_MNEM_viwdup 0xee010f60
13ccd4c0
AV
14599#define M_MNEM_vmaxv 0xeee20f00
14600#define M_MNEM_vmaxav 0xeee00f00
14601#define M_MNEM_vminv 0xeee20f80
14602#define M_MNEM_vminav 0xeee00f80
93925576
AV
14603#define M_MNEM_vmlaldav 0xee800e00
14604#define M_MNEM_vmlaldava 0xee800e20
14605#define M_MNEM_vmlaldavx 0xee801e00
14606#define M_MNEM_vmlaldavax 0xee801e20
14607#define M_MNEM_vmlsldav 0xee800e01
14608#define M_MNEM_vmlsldava 0xee800e21
14609#define M_MNEM_vmlsldavx 0xee801e01
14610#define M_MNEM_vmlsldavax 0xee801e21
14611#define M_MNEM_vrmlaldavhx 0xee801f00
14612#define M_MNEM_vrmlaldavhax 0xee801f20
14613#define M_MNEM_vrmlsldavh 0xfe800e01
14614#define M_MNEM_vrmlsldavha 0xfe800e21
14615#define M_MNEM_vrmlsldavhx 0xfe801e01
14616#define M_MNEM_vrmlsldavhax 0xfe801e21
1be7aba3
AV
14617#define M_MNEM_vqmovnt 0xee331e01
14618#define M_MNEM_vqmovnb 0xee330e01
14619#define M_MNEM_vqmovunt 0xee311e81
14620#define M_MNEM_vqmovunb 0xee310e81
4aa88b50
AV
14621#define M_MNEM_vshrnt 0xee801fc1
14622#define M_MNEM_vshrnb 0xee800fc1
14623#define M_MNEM_vrshrnt 0xfe801fc1
14624#define M_MNEM_vqshrnt 0xee801f40
14625#define M_MNEM_vqshrnb 0xee800f40
14626#define M_MNEM_vqshrunt 0xee801fc0
14627#define M_MNEM_vqshrunb 0xee800fc0
14628#define M_MNEM_vrshrnb 0xfe800fc1
14629#define M_MNEM_vqrshrnt 0xee801f41
14630#define M_MNEM_vqrshrnb 0xee800f41
14631#define M_MNEM_vqrshrunt 0xfe801fc0
14632#define M_MNEM_vqrshrunb 0xfe800fc0
a302e574 14633
aab2c27d
MM
14634/* Bfloat16 instruction encoder helpers. */
14635#define B_MNEM_vfmat 0xfc300850
14636#define B_MNEM_vfmab 0xfc300810
14637
5287ad62 14638/* Neon instruction encoder helpers. */
5f4273c7 14639
5287ad62 14640/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 14641
5287ad62
JB
14642/* An "invalid" code for the following tables. */
14643#define N_INV -1u
14644
14645struct neon_tab_entry
b99bd4ef 14646{
5287ad62
JB
14647 unsigned integer;
14648 unsigned float_or_poly;
14649 unsigned scalar_or_imm;
14650};
5f4273c7 14651
5287ad62
JB
14652/* Map overloaded Neon opcodes to their respective encodings. */
14653#define NEON_ENC_TAB \
14654 X(vabd, 0x0000700, 0x1200d00, N_INV), \
5ee91343 14655 X(vabdl, 0x0800700, N_INV, N_INV), \
5287ad62
JB
14656 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14657 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14658 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14659 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14660 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14661 X(vadd, 0x0000800, 0x0000d00, N_INV), \
5ee91343 14662 X(vaddl, 0x0800000, N_INV, N_INV), \
5287ad62 14663 X(vsub, 0x1000800, 0x0200d00, N_INV), \
5ee91343 14664 X(vsubl, 0x0800200, N_INV, N_INV), \
5287ad62
JB
14665 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14666 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14667 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14668 /* Register variants of the following two instructions are encoded as
e07e6e58 14669 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
14670 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14671 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
14672 X(vfma, N_INV, 0x0000c10, N_INV), \
14673 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
14674 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14675 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14676 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14677 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14678 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14679 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14680 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14681 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14682 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14683 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14684 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
14685 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14686 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
14687 X(vshl, 0x0000400, N_INV, 0x0800510), \
14688 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14689 X(vand, 0x0000110, N_INV, 0x0800030), \
14690 X(vbic, 0x0100110, N_INV, 0x0800030), \
14691 X(veor, 0x1000110, N_INV, N_INV), \
14692 X(vorn, 0x0300110, N_INV, 0x0800010), \
14693 X(vorr, 0x0200110, N_INV, 0x0800010), \
14694 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14695 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14696 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14697 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14698 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14699 X(vst1, 0x0000000, 0x0800000, N_INV), \
14700 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14701 X(vst2, 0x0000100, 0x0800100, N_INV), \
14702 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14703 X(vst3, 0x0000200, 0x0800200, N_INV), \
14704 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14705 X(vst4, 0x0000300, 0x0800300, N_INV), \
14706 X(vmovn, 0x1b20200, N_INV, N_INV), \
14707 X(vtrn, 0x1b20080, N_INV, N_INV), \
14708 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
14709 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14710 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
14711 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14712 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
14713 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14714 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
14715 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14716 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14717 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
14718 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14719 X(vseleq, 0xe000a00, N_INV, N_INV), \
14720 X(vselvs, 0xe100a00, N_INV, N_INV), \
14721 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
14722 X(vselgt, 0xe300a00, N_INV, N_INV), \
14723 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 14724 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
14725 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14726 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 14727 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 14728 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
14729 X(sha3op, 0x2000c00, N_INV, N_INV), \
14730 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14731 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
14732
14733enum neon_opc
14734{
14735#define X(OPC,I,F,S) N_MNEM_##OPC
14736NEON_ENC_TAB
14737#undef X
14738};
b99bd4ef 14739
5287ad62
JB
14740static const struct neon_tab_entry neon_enc_tab[] =
14741{
14742#define X(OPC,I,F,S) { (I), (F), (S) }
14743NEON_ENC_TAB
14744#undef X
14745};
b99bd4ef 14746
88714cb8
DG
14747/* Do not use these macros; instead, use NEON_ENCODE defined below. */
14748#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14749#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14750#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14751#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14752#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14753#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14754#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14755#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14756#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14757#define NEON_ENC_SINGLE_(X) \
037e8744 14758 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 14759#define NEON_ENC_DOUBLE_(X) \
037e8744 14760 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
14761#define NEON_ENC_FPV8_(X) \
14762 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 14763
88714cb8
DG
14764#define NEON_ENCODE(type, inst) \
14765 do \
14766 { \
14767 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14768 inst.is_neon = 1; \
14769 } \
14770 while (0)
14771
14772#define check_neon_suffixes \
14773 do \
14774 { \
14775 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14776 { \
14777 as_bad (_("invalid neon suffix for non neon instruction")); \
14778 return; \
14779 } \
14780 } \
14781 while (0)
14782
037e8744
JB
14783/* Define shapes for instruction operands. The following mnemonic characters
14784 are used in this table:
5287ad62 14785
037e8744 14786 F - VFP S<n> register
5287ad62
JB
14787 D - Neon D<n> register
14788 Q - Neon Q<n> register
14789 I - Immediate
14790 S - Scalar
14791 R - ARM register
14792 L - D<n> register list
5f4273c7 14793
037e8744
JB
14794 This table is used to generate various data:
14795 - enumerations of the form NS_DDR to be used as arguments to
14796 neon_select_shape.
14797 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 14798 - a table used to drive neon_select_shape. */
b99bd4ef 14799
037e8744 14800#define NEON_SHAPE_DEF \
93925576 14801 X(4, (R, R, Q, Q), QUAD), \
b409bdb6 14802 X(4, (Q, R, R, I), QUAD), \
57785aa2
AV
14803 X(4, (R, R, S, S), QUAD), \
14804 X(4, (S, S, R, R), QUAD), \
b409bdb6 14805 X(3, (Q, R, I), QUAD), \
1b883319
AV
14806 X(3, (I, Q, Q), QUAD), \
14807 X(3, (I, Q, R), QUAD), \
a302e574 14808 X(3, (R, Q, Q), QUAD), \
037e8744
JB
14809 X(3, (D, D, D), DOUBLE), \
14810 X(3, (Q, Q, Q), QUAD), \
14811 X(3, (D, D, I), DOUBLE), \
14812 X(3, (Q, Q, I), QUAD), \
14813 X(3, (D, D, S), DOUBLE), \
14814 X(3, (Q, Q, S), QUAD), \
5ee91343 14815 X(3, (Q, Q, R), QUAD), \
26c1e780
AV
14816 X(3, (R, R, Q), QUAD), \
14817 X(2, (R, Q), QUAD), \
037e8744
JB
14818 X(2, (D, D), DOUBLE), \
14819 X(2, (Q, Q), QUAD), \
14820 X(2, (D, S), DOUBLE), \
14821 X(2, (Q, S), QUAD), \
14822 X(2, (D, R), DOUBLE), \
14823 X(2, (Q, R), QUAD), \
14824 X(2, (D, I), DOUBLE), \
14825 X(2, (Q, I), QUAD), \
5aae9ae9
MM
14826 X(3, (P, F, I), SINGLE), \
14827 X(3, (P, D, I), DOUBLE), \
14828 X(3, (P, Q, I), QUAD), \
14829 X(4, (P, F, F, I), SINGLE), \
14830 X(4, (P, D, D, I), DOUBLE), \
14831 X(4, (P, Q, Q, I), QUAD), \
14832 X(5, (P, F, F, F, I), SINGLE), \
14833 X(5, (P, D, D, D, I), DOUBLE), \
14834 X(5, (P, Q, Q, Q, I), QUAD), \
037e8744
JB
14835 X(3, (D, L, D), DOUBLE), \
14836 X(2, (D, Q), MIXED), \
14837 X(2, (Q, D), MIXED), \
14838 X(3, (D, Q, I), MIXED), \
14839 X(3, (Q, D, I), MIXED), \
14840 X(3, (Q, D, D), MIXED), \
14841 X(3, (D, Q, Q), MIXED), \
14842 X(3, (Q, Q, D), MIXED), \
14843 X(3, (Q, D, S), MIXED), \
14844 X(3, (D, Q, S), MIXED), \
14845 X(4, (D, D, D, I), DOUBLE), \
14846 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
14847 X(4, (D, D, S, I), DOUBLE), \
14848 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
14849 X(2, (F, F), SINGLE), \
14850 X(3, (F, F, F), SINGLE), \
14851 X(2, (F, I), SINGLE), \
14852 X(2, (F, D), MIXED), \
14853 X(2, (D, F), MIXED), \
14854 X(3, (F, F, I), MIXED), \
14855 X(4, (R, R, F, F), SINGLE), \
14856 X(4, (F, F, R, R), SINGLE), \
14857 X(3, (D, R, R), DOUBLE), \
14858 X(3, (R, R, D), DOUBLE), \
14859 X(2, (S, R), SINGLE), \
14860 X(2, (R, S), SINGLE), \
14861 X(2, (F, R), SINGLE), \
d54af2d0 14862 X(2, (R, F), SINGLE), \
1f6234a3
AV
14863/* Used for MVE tail predicated loop instructions. */\
14864 X(2, (R, R), QUAD), \
d54af2d0
RL
14865/* Half float shape supported so far. */\
14866 X (2, (H, D), MIXED), \
14867 X (2, (D, H), MIXED), \
14868 X (2, (H, F), MIXED), \
14869 X (2, (F, H), MIXED), \
14870 X (2, (H, H), HALF), \
14871 X (2, (H, R), HALF), \
14872 X (2, (R, H), HALF), \
14873 X (2, (H, I), HALF), \
14874 X (3, (H, H, H), HALF), \
14875 X (3, (H, F, I), MIXED), \
dec41383
JW
14876 X (3, (F, H, I), MIXED), \
14877 X (3, (D, H, H), MIXED), \
14878 X (3, (D, H, S), MIXED)
037e8744
JB
14879
14880#define S2(A,B) NS_##A##B
14881#define S3(A,B,C) NS_##A##B##C
14882#define S4(A,B,C,D) NS_##A##B##C##D
5aae9ae9 14883#define S5(A,B,C,D,E) NS_##A##B##C##D##E
037e8744
JB
14884
14885#define X(N, L, C) S##N L
14886
5287ad62
JB
14887enum neon_shape
14888{
037e8744
JB
14889 NEON_SHAPE_DEF,
14890 NS_NULL
5287ad62 14891};
b99bd4ef 14892
037e8744
JB
14893#undef X
14894#undef S2
14895#undef S3
14896#undef S4
5aae9ae9 14897#undef S5
037e8744
JB
14898
14899enum neon_shape_class
14900{
d54af2d0 14901 SC_HALF,
037e8744
JB
14902 SC_SINGLE,
14903 SC_DOUBLE,
14904 SC_QUAD,
14905 SC_MIXED
14906};
14907
14908#define X(N, L, C) SC_##C
14909
14910static enum neon_shape_class neon_shape_class[] =
14911{
14912 NEON_SHAPE_DEF
14913};
14914
14915#undef X
14916
14917enum neon_shape_el
14918{
d54af2d0 14919 SE_H,
037e8744
JB
14920 SE_F,
14921 SE_D,
14922 SE_Q,
14923 SE_I,
14924 SE_S,
14925 SE_R,
5aae9ae9
MM
14926 SE_L,
14927 SE_P
037e8744
JB
14928};
14929
14930/* Register widths of above. */
14931static unsigned neon_shape_el_size[] =
14932{
d54af2d0 14933 16,
037e8744
JB
14934 32,
14935 64,
14936 128,
14937 0,
14938 32,
14939 32,
5aae9ae9 14940 0,
037e8744
JB
14941 0
14942};
14943
14944struct neon_shape_info
14945{
14946 unsigned els;
14947 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14948};
14949
14950#define S2(A,B) { SE_##A, SE_##B }
14951#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14952#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
5aae9ae9 14953#define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
037e8744
JB
14954
14955#define X(N, L, C) { N, S##N L }
14956
14957static struct neon_shape_info neon_shape_tab[] =
14958{
14959 NEON_SHAPE_DEF
14960};
14961
14962#undef X
14963#undef S2
14964#undef S3
14965#undef S4
5aae9ae9 14966#undef S5
037e8744 14967
5287ad62
JB
14968/* Bit masks used in type checking given instructions.
14969 'N_EQK' means the type must be the same as (or based on in some way) the key
14970 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14971 set, various other bits can be set as well in order to modify the meaning of
14972 the type constraint. */
14973
14974enum neon_type_mask
14975{
8e79c3df
CM
14976 N_S8 = 0x0000001,
14977 N_S16 = 0x0000002,
14978 N_S32 = 0x0000004,
14979 N_S64 = 0x0000008,
14980 N_U8 = 0x0000010,
14981 N_U16 = 0x0000020,
14982 N_U32 = 0x0000040,
14983 N_U64 = 0x0000080,
14984 N_I8 = 0x0000100,
14985 N_I16 = 0x0000200,
14986 N_I32 = 0x0000400,
14987 N_I64 = 0x0000800,
14988 N_8 = 0x0001000,
14989 N_16 = 0x0002000,
14990 N_32 = 0x0004000,
14991 N_64 = 0x0008000,
14992 N_P8 = 0x0010000,
14993 N_P16 = 0x0020000,
14994 N_F16 = 0x0040000,
14995 N_F32 = 0x0080000,
14996 N_F64 = 0x0100000,
4f51b4bd 14997 N_P64 = 0x0200000,
aab2c27d 14998 N_BF16 = 0x0400000,
c921be7d
NC
14999 N_KEY = 0x1000000, /* Key element (main type specifier). */
15000 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 15001 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 15002 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
15003 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
15004 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
15005 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
15006 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
15007 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
15008 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
15009 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 15010 N_UTYP = 0,
4f51b4bd 15011 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
15012};
15013
dcbf9037
JB
15014#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15015
5287ad62
JB
15016#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15017#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15018#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
15019#define N_S_32 (N_S8 | N_S16 | N_S32)
15020#define N_F_16_32 (N_F16 | N_F32)
15021#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 15022#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 15023#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 15024#define N_F_ALL (N_F16 | N_F32 | N_F64)
5ee91343
AV
15025#define N_I_MVE (N_I8 | N_I16 | N_I32)
15026#define N_F_MVE (N_F16 | N_F32)
15027#define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
5287ad62
JB
15028
15029/* Pass this as the first type argument to neon_check_type to ignore types
15030 altogether. */
15031#define N_IGNORE_TYPE (N_KEY | N_EQK)
15032
037e8744
JB
15033/* Select a "shape" for the current instruction (describing register types or
15034 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15035 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15036 function of operand parsing, so this function doesn't need to be called.
15037 Shapes should be listed in order of decreasing length. */
5287ad62
JB
15038
15039static enum neon_shape
037e8744 15040neon_select_shape (enum neon_shape shape, ...)
5287ad62 15041{
037e8744
JB
15042 va_list ap;
15043 enum neon_shape first_shape = shape;
5287ad62
JB
15044
15045 /* Fix missing optional operands. FIXME: we don't know at this point how
15046 many arguments we should have, so this makes the assumption that we have
15047 > 1. This is true of all current Neon opcodes, I think, but may not be
15048 true in the future. */
15049 if (!inst.operands[1].present)
15050 inst.operands[1] = inst.operands[0];
15051
037e8744 15052 va_start (ap, shape);
5f4273c7 15053
21d799b5 15054 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
15055 {
15056 unsigned j;
15057 int matches = 1;
15058
15059 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
15060 {
15061 if (!inst.operands[j].present)
15062 {
15063 matches = 0;
15064 break;
15065 }
15066
15067 switch (neon_shape_tab[shape].el[j])
15068 {
d54af2d0
RL
15069 /* If a .f16, .16, .u16, .s16 type specifier is given over
15070 a VFP single precision register operand, it's essentially
15071 means only half of the register is used.
15072
15073 If the type specifier is given after the mnemonics, the
15074 information is stored in inst.vectype. If the type specifier
15075 is given after register operand, the information is stored
15076 in inst.operands[].vectype.
15077
15078 When there is only one type specifier, and all the register
15079 operands are the same type of hardware register, the type
15080 specifier applies to all register operands.
15081
15082 If no type specifier is given, the shape is inferred from
15083 operand information.
15084
15085 for example:
15086 vadd.f16 s0, s1, s2: NS_HHH
15087 vabs.f16 s0, s1: NS_HH
15088 vmov.f16 s0, r1: NS_HR
15089 vmov.f16 r0, s1: NS_RH
15090 vcvt.f16 r0, s1: NS_RH
15091 vcvt.f16.s32 s2, s2, #29: NS_HFI
15092 vcvt.f16.s32 s2, s2: NS_HF
15093 */
15094 case SE_H:
15095 if (!(inst.operands[j].isreg
15096 && inst.operands[j].isvec
15097 && inst.operands[j].issingle
15098 && !inst.operands[j].isquad
15099 && ((inst.vectype.elems == 1
15100 && inst.vectype.el[0].size == 16)
15101 || (inst.vectype.elems > 1
15102 && inst.vectype.el[j].size == 16)
15103 || (inst.vectype.elems == 0
15104 && inst.operands[j].vectype.type != NT_invtype
15105 && inst.operands[j].vectype.size == 16))))
15106 matches = 0;
15107 break;
15108
477330fc
RM
15109 case SE_F:
15110 if (!(inst.operands[j].isreg
15111 && inst.operands[j].isvec
15112 && inst.operands[j].issingle
d54af2d0
RL
15113 && !inst.operands[j].isquad
15114 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15115 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15116 || (inst.vectype.elems == 0
15117 && (inst.operands[j].vectype.size == 32
15118 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
15119 matches = 0;
15120 break;
15121
15122 case SE_D:
15123 if (!(inst.operands[j].isreg
15124 && inst.operands[j].isvec
15125 && !inst.operands[j].isquad
15126 && !inst.operands[j].issingle))
15127 matches = 0;
15128 break;
15129
15130 case SE_R:
15131 if (!(inst.operands[j].isreg
15132 && !inst.operands[j].isvec))
15133 matches = 0;
15134 break;
15135
15136 case SE_Q:
15137 if (!(inst.operands[j].isreg
15138 && inst.operands[j].isvec
15139 && inst.operands[j].isquad
15140 && !inst.operands[j].issingle))
15141 matches = 0;
15142 break;
15143
15144 case SE_I:
15145 if (!(!inst.operands[j].isreg
15146 && !inst.operands[j].isscalar))
15147 matches = 0;
15148 break;
15149
15150 case SE_S:
15151 if (!(!inst.operands[j].isreg
15152 && inst.operands[j].isscalar))
15153 matches = 0;
15154 break;
15155
5aae9ae9 15156 case SE_P:
477330fc
RM
15157 case SE_L:
15158 break;
15159 }
3fde54a2
JZ
15160 if (!matches)
15161 break;
477330fc 15162 }
ad6cec43
MGD
15163 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15164 /* We've matched all the entries in the shape table, and we don't
15165 have any left over operands which have not been matched. */
477330fc 15166 break;
037e8744 15167 }
5f4273c7 15168
037e8744 15169 va_end (ap);
5287ad62 15170
037e8744
JB
15171 if (shape == NS_NULL && first_shape != NS_NULL)
15172 first_error (_("invalid instruction shape"));
5287ad62 15173
037e8744
JB
15174 return shape;
15175}
5287ad62 15176
037e8744
JB
15177/* True if SHAPE is predominantly a quadword operation (most of the time, this
15178 means the Q bit should be set). */
15179
15180static int
15181neon_quad (enum neon_shape shape)
15182{
15183 return neon_shape_class[shape] == SC_QUAD;
5287ad62 15184}
037e8744 15185
5287ad62
JB
15186static void
15187neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 15188 unsigned *g_size)
5287ad62
JB
15189{
15190 /* Allow modification to be made to types which are constrained to be
15191 based on the key element, based on bits set alongside N_EQK. */
15192 if ((typebits & N_EQK) != 0)
15193 {
15194 if ((typebits & N_HLF) != 0)
15195 *g_size /= 2;
15196 else if ((typebits & N_DBL) != 0)
15197 *g_size *= 2;
15198 if ((typebits & N_SGN) != 0)
15199 *g_type = NT_signed;
15200 else if ((typebits & N_UNS) != 0)
477330fc 15201 *g_type = NT_unsigned;
5287ad62 15202 else if ((typebits & N_INT) != 0)
477330fc 15203 *g_type = NT_integer;
5287ad62 15204 else if ((typebits & N_FLT) != 0)
477330fc 15205 *g_type = NT_float;
dcbf9037 15206 else if ((typebits & N_SIZ) != 0)
477330fc 15207 *g_type = NT_untyped;
5287ad62
JB
15208 }
15209}
5f4273c7 15210
5287ad62
JB
15211/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15212 operand type, i.e. the single type specified in a Neon instruction when it
15213 is the only one given. */
15214
15215static struct neon_type_el
15216neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15217{
15218 struct neon_type_el dest = *key;
5f4273c7 15219
9c2799c2 15220 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 15221
5287ad62
JB
15222 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15223
15224 return dest;
15225}
15226
15227/* Convert Neon type and size into compact bitmask representation. */
15228
15229static enum neon_type_mask
15230type_chk_of_el_type (enum neon_el_type type, unsigned size)
15231{
15232 switch (type)
15233 {
15234 case NT_untyped:
15235 switch (size)
477330fc
RM
15236 {
15237 case 8: return N_8;
15238 case 16: return N_16;
15239 case 32: return N_32;
15240 case 64: return N_64;
15241 default: ;
15242 }
5287ad62
JB
15243 break;
15244
15245 case NT_integer:
15246 switch (size)
477330fc
RM
15247 {
15248 case 8: return N_I8;
15249 case 16: return N_I16;
15250 case 32: return N_I32;
15251 case 64: return N_I64;
15252 default: ;
15253 }
5287ad62
JB
15254 break;
15255
15256 case NT_float:
037e8744 15257 switch (size)
477330fc 15258 {
8e79c3df 15259 case 16: return N_F16;
477330fc
RM
15260 case 32: return N_F32;
15261 case 64: return N_F64;
15262 default: ;
15263 }
5287ad62
JB
15264 break;
15265
15266 case NT_poly:
15267 switch (size)
477330fc
RM
15268 {
15269 case 8: return N_P8;
15270 case 16: return N_P16;
4f51b4bd 15271 case 64: return N_P64;
477330fc
RM
15272 default: ;
15273 }
5287ad62
JB
15274 break;
15275
15276 case NT_signed:
15277 switch (size)
477330fc
RM
15278 {
15279 case 8: return N_S8;
15280 case 16: return N_S16;
15281 case 32: return N_S32;
15282 case 64: return N_S64;
15283 default: ;
15284 }
5287ad62
JB
15285 break;
15286
15287 case NT_unsigned:
15288 switch (size)
477330fc
RM
15289 {
15290 case 8: return N_U8;
15291 case 16: return N_U16;
15292 case 32: return N_U32;
15293 case 64: return N_U64;
15294 default: ;
15295 }
5287ad62
JB
15296 break;
15297
aab2c27d
MM
15298 case NT_bfloat:
15299 if (size == 16) return N_BF16;
15300 break;
15301
5287ad62
JB
15302 default: ;
15303 }
5f4273c7 15304
5287ad62
JB
15305 return N_UTYP;
15306}
15307
15308/* Convert compact Neon bitmask type representation to a type and size. Only
15309 handles the case where a single bit is set in the mask. */
15310
dcbf9037 15311static int
5287ad62 15312el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 15313 enum neon_type_mask mask)
5287ad62 15314{
dcbf9037
JB
15315 if ((mask & N_EQK) != 0)
15316 return FAIL;
15317
5287ad62
JB
15318 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15319 *size = 8;
aab2c27d
MM
15320 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15321 != 0)
5287ad62 15322 *size = 16;
dcbf9037 15323 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 15324 *size = 32;
4f51b4bd 15325 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 15326 *size = 64;
dcbf9037
JB
15327 else
15328 return FAIL;
15329
5287ad62
JB
15330 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15331 *type = NT_signed;
dcbf9037 15332 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 15333 *type = NT_unsigned;
dcbf9037 15334 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 15335 *type = NT_integer;
dcbf9037 15336 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 15337 *type = NT_untyped;
4f51b4bd 15338 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 15339 *type = NT_poly;
d54af2d0 15340 else if ((mask & (N_F_ALL)) != 0)
5287ad62 15341 *type = NT_float;
aab2c27d
MM
15342 else if ((mask & (N_BF16)) != 0)
15343 *type = NT_bfloat;
dcbf9037
JB
15344 else
15345 return FAIL;
5f4273c7 15346
dcbf9037 15347 return SUCCESS;
5287ad62
JB
15348}
15349
15350/* Modify a bitmask of allowed types. This is only needed for type
15351 relaxation. */
15352
15353static unsigned
15354modify_types_allowed (unsigned allowed, unsigned mods)
15355{
15356 unsigned size;
15357 enum neon_el_type type;
15358 unsigned destmask;
15359 int i;
5f4273c7 15360
5287ad62 15361 destmask = 0;
5f4273c7 15362
5287ad62
JB
15363 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15364 {
21d799b5 15365 if (el_type_of_type_chk (&type, &size,
477330fc
RM
15366 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15367 {
15368 neon_modify_type_size (mods, &type, &size);
15369 destmask |= type_chk_of_el_type (type, size);
15370 }
5287ad62 15371 }
5f4273c7 15372
5287ad62
JB
15373 return destmask;
15374}
15375
15376/* Check type and return type classification.
15377 The manual states (paraphrase): If one datatype is given, it indicates the
15378 type given in:
15379 - the second operand, if there is one
15380 - the operand, if there is no second operand
15381 - the result, if there are no operands.
15382 This isn't quite good enough though, so we use a concept of a "key" datatype
15383 which is set on a per-instruction basis, which is the one which matters when
15384 only one data type is written.
15385 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 15386 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
15387
15388static struct neon_type_el
15389neon_check_type (unsigned els, enum neon_shape ns, ...)
15390{
15391 va_list ap;
15392 unsigned i, pass, key_el = 0;
15393 unsigned types[NEON_MAX_TYPE_ELS];
15394 enum neon_el_type k_type = NT_invtype;
15395 unsigned k_size = -1u;
15396 struct neon_type_el badtype = {NT_invtype, -1};
15397 unsigned key_allowed = 0;
15398
15399 /* Optional registers in Neon instructions are always (not) in operand 1.
15400 Fill in the missing operand here, if it was omitted. */
15401 if (els > 1 && !inst.operands[1].present)
15402 inst.operands[1] = inst.operands[0];
15403
15404 /* Suck up all the varargs. */
15405 va_start (ap, ns);
15406 for (i = 0; i < els; i++)
15407 {
15408 unsigned thisarg = va_arg (ap, unsigned);
15409 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
15410 {
15411 va_end (ap);
15412 return badtype;
15413 }
5287ad62
JB
15414 types[i] = thisarg;
15415 if ((thisarg & N_KEY) != 0)
477330fc 15416 key_el = i;
5287ad62
JB
15417 }
15418 va_end (ap);
15419
dcbf9037
JB
15420 if (inst.vectype.elems > 0)
15421 for (i = 0; i < els; i++)
15422 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
15423 {
15424 first_error (_("types specified in both the mnemonic and operands"));
15425 return badtype;
15426 }
dcbf9037 15427
5287ad62
JB
15428 /* Duplicate inst.vectype elements here as necessary.
15429 FIXME: No idea if this is exactly the same as the ARM assembler,
15430 particularly when an insn takes one register and one non-register
15431 operand. */
15432 if (inst.vectype.elems == 1 && els > 1)
15433 {
15434 unsigned j;
15435 inst.vectype.elems = els;
15436 inst.vectype.el[key_el] = inst.vectype.el[0];
15437 for (j = 0; j < els; j++)
477330fc
RM
15438 if (j != key_el)
15439 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15440 types[j]);
dcbf9037
JB
15441 }
15442 else if (inst.vectype.elems == 0 && els > 0)
15443 {
15444 unsigned j;
15445 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
15446 after each operand. We allow some flexibility here; as long as the
15447 "key" operand has a type, we can infer the others. */
dcbf9037 15448 for (j = 0; j < els; j++)
477330fc
RM
15449 if (inst.operands[j].vectype.type != NT_invtype)
15450 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
15451
15452 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
15453 {
15454 for (j = 0; j < els; j++)
15455 if (inst.operands[j].vectype.type == NT_invtype)
15456 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15457 types[j]);
15458 }
dcbf9037 15459 else
477330fc
RM
15460 {
15461 first_error (_("operand types can't be inferred"));
15462 return badtype;
15463 }
5287ad62
JB
15464 }
15465 else if (inst.vectype.elems != els)
15466 {
dcbf9037 15467 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
15468 return badtype;
15469 }
15470
15471 for (pass = 0; pass < 2; pass++)
15472 {
15473 for (i = 0; i < els; i++)
477330fc
RM
15474 {
15475 unsigned thisarg = types[i];
15476 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15477 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15478 enum neon_el_type g_type = inst.vectype.el[i].type;
15479 unsigned g_size = inst.vectype.el[i].size;
15480
15481 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 15482 integer types if sign-specific variants are unavailable. */
477330fc 15483 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
15484 && (types_allowed & N_SU_ALL) == 0)
15485 g_type = NT_integer;
15486
477330fc 15487 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
15488 them. Some instructions only care about signs for some element
15489 sizes, so handle that properly. */
477330fc 15490 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
15491 && ((g_size == 8 && (types_allowed & N_8) != 0)
15492 || (g_size == 16 && (types_allowed & N_16) != 0)
15493 || (g_size == 32 && (types_allowed & N_32) != 0)
15494 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
15495 g_type = NT_untyped;
15496
477330fc
RM
15497 if (pass == 0)
15498 {
15499 if ((thisarg & N_KEY) != 0)
15500 {
15501 k_type = g_type;
15502 k_size = g_size;
15503 key_allowed = thisarg & ~N_KEY;
cc933301
JW
15504
15505 /* Check architecture constraint on FP16 extension. */
15506 if (k_size == 16
15507 && k_type == NT_float
15508 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15509 {
15510 inst.error = _(BAD_FP16);
15511 return badtype;
15512 }
477330fc
RM
15513 }
15514 }
15515 else
15516 {
15517 if ((thisarg & N_VFP) != 0)
15518 {
15519 enum neon_shape_el regshape;
15520 unsigned regwidth, match;
99b253c5
NC
15521
15522 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15523 if (ns == NS_NULL)
15524 {
15525 first_error (_("invalid instruction shape"));
15526 return badtype;
15527 }
477330fc
RM
15528 regshape = neon_shape_tab[ns].el[i];
15529 regwidth = neon_shape_el_size[regshape];
15530
15531 /* In VFP mode, operands must match register widths. If we
15532 have a key operand, use its width, else use the width of
15533 the current operand. */
15534 if (k_size != -1u)
15535 match = k_size;
15536 else
15537 match = g_size;
15538
9db2f6b4
RL
15539 /* FP16 will use a single precision register. */
15540 if (regwidth == 32 && match == 16)
15541 {
15542 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15543 match = regwidth;
15544 else
15545 {
15546 inst.error = _(BAD_FP16);
15547 return badtype;
15548 }
15549 }
15550
477330fc
RM
15551 if (regwidth != match)
15552 {
15553 first_error (_("operand size must match register width"));
15554 return badtype;
15555 }
15556 }
15557
15558 if ((thisarg & N_EQK) == 0)
15559 {
15560 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15561
15562 if ((given_type & types_allowed) == 0)
15563 {
a302e574 15564 first_error (BAD_SIMD_TYPE);
477330fc
RM
15565 return badtype;
15566 }
15567 }
15568 else
15569 {
15570 enum neon_el_type mod_k_type = k_type;
15571 unsigned mod_k_size = k_size;
15572 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15573 if (g_type != mod_k_type || g_size != mod_k_size)
15574 {
15575 first_error (_("inconsistent types in Neon instruction"));
15576 return badtype;
15577 }
15578 }
15579 }
15580 }
5287ad62
JB
15581 }
15582
15583 return inst.vectype.el[key_el];
15584}
15585
037e8744 15586/* Neon-style VFP instruction forwarding. */
5287ad62 15587
037e8744
JB
15588/* Thumb VFP instructions have 0xE in the condition field. */
15589
15590static void
15591do_vfp_cond_or_thumb (void)
5287ad62 15592{
88714cb8
DG
15593 inst.is_neon = 1;
15594
5287ad62 15595 if (thumb_mode)
037e8744 15596 inst.instruction |= 0xe0000000;
5287ad62 15597 else
037e8744 15598 inst.instruction |= inst.cond << 28;
5287ad62
JB
15599}
15600
037e8744
JB
15601/* Look up and encode a simple mnemonic, for use as a helper function for the
15602 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15603 etc. It is assumed that operand parsing has already been done, and that the
15604 operands are in the form expected by the given opcode (this isn't necessarily
15605 the same as the form in which they were parsed, hence some massaging must
15606 take place before this function is called).
15607 Checks current arch version against that in the looked-up opcode. */
5287ad62 15608
037e8744
JB
15609static void
15610do_vfp_nsyn_opcode (const char *opname)
5287ad62 15611{
037e8744 15612 const struct asm_opcode *opcode;
5f4273c7 15613
629310ab 15614 opcode = (const struct asm_opcode *) str_hash_find (arm_ops_hsh, opname);
5287ad62 15615
037e8744
JB
15616 if (!opcode)
15617 abort ();
5287ad62 15618
037e8744 15619 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
15620 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15621 _(BAD_FPU));
5287ad62 15622
88714cb8
DG
15623 inst.is_neon = 1;
15624
037e8744
JB
15625 if (thumb_mode)
15626 {
15627 inst.instruction = opcode->tvalue;
15628 opcode->tencode ();
15629 }
15630 else
15631 {
15632 inst.instruction = (inst.cond << 28) | opcode->avalue;
15633 opcode->aencode ();
15634 }
15635}
5287ad62
JB
15636
15637static void
037e8744 15638do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 15639{
037e8744
JB
15640 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15641
9db2f6b4 15642 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15643 {
15644 if (is_add)
477330fc 15645 do_vfp_nsyn_opcode ("fadds");
037e8744 15646 else
477330fc 15647 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
15648
15649 /* ARMv8.2 fp16 instruction. */
15650 if (rs == NS_HHH)
15651 do_scalar_fp16_v82_encode ();
037e8744
JB
15652 }
15653 else
15654 {
15655 if (is_add)
477330fc 15656 do_vfp_nsyn_opcode ("faddd");
037e8744 15657 else
477330fc 15658 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
15659 }
15660}
15661
15662/* Check operand types to see if this is a VFP instruction, and if so call
15663 PFN (). */
15664
15665static int
15666try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15667{
15668 enum neon_shape rs;
15669 struct neon_type_el et;
15670
15671 switch (args)
15672 {
15673 case 2:
9db2f6b4
RL
15674 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15675 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 15676 break;
5f4273c7 15677
037e8744 15678 case 3:
9db2f6b4
RL
15679 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15680 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15681 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
15682 break;
15683
15684 default:
15685 abort ();
15686 }
15687
15688 if (et.type != NT_invtype)
15689 {
15690 pfn (rs);
15691 return SUCCESS;
15692 }
037e8744 15693
99b253c5 15694 inst.error = NULL;
037e8744
JB
15695 return FAIL;
15696}
15697
15698static void
15699do_vfp_nsyn_mla_mls (enum neon_shape rs)
15700{
15701 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 15702
9db2f6b4 15703 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
15704 {
15705 if (is_mla)
477330fc 15706 do_vfp_nsyn_opcode ("fmacs");
037e8744 15707 else
477330fc 15708 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
15709
15710 /* ARMv8.2 fp16 instruction. */
15711 if (rs == NS_HHH)
15712 do_scalar_fp16_v82_encode ();
037e8744
JB
15713 }
15714 else
15715 {
15716 if (is_mla)
477330fc 15717 do_vfp_nsyn_opcode ("fmacd");
037e8744 15718 else
477330fc 15719 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
15720 }
15721}
15722
62f3b8c8
PB
15723static void
15724do_vfp_nsyn_fma_fms (enum neon_shape rs)
15725{
15726 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15727
9db2f6b4 15728 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
15729 {
15730 if (is_fma)
477330fc 15731 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 15732 else
477330fc 15733 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
15734
15735 /* ARMv8.2 fp16 instruction. */
15736 if (rs == NS_HHH)
15737 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
15738 }
15739 else
15740 {
15741 if (is_fma)
477330fc 15742 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 15743 else
477330fc 15744 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
15745 }
15746}
15747
037e8744
JB
15748static void
15749do_vfp_nsyn_mul (enum neon_shape rs)
15750{
9db2f6b4
RL
15751 if (rs == NS_FFF || rs == NS_HHH)
15752 {
15753 do_vfp_nsyn_opcode ("fmuls");
15754
15755 /* ARMv8.2 fp16 instruction. */
15756 if (rs == NS_HHH)
15757 do_scalar_fp16_v82_encode ();
15758 }
037e8744
JB
15759 else
15760 do_vfp_nsyn_opcode ("fmuld");
15761}
15762
15763static void
15764do_vfp_nsyn_abs_neg (enum neon_shape rs)
15765{
15766 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 15767 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 15768
9db2f6b4 15769 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
15770 {
15771 if (is_neg)
477330fc 15772 do_vfp_nsyn_opcode ("fnegs");
037e8744 15773 else
477330fc 15774 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
15775
15776 /* ARMv8.2 fp16 instruction. */
15777 if (rs == NS_HH)
15778 do_scalar_fp16_v82_encode ();
037e8744
JB
15779 }
15780 else
15781 {
15782 if (is_neg)
477330fc 15783 do_vfp_nsyn_opcode ("fnegd");
037e8744 15784 else
477330fc 15785 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
15786 }
15787}
15788
15789/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15790 insns belong to Neon, and are handled elsewhere. */
15791
15792static void
15793do_vfp_nsyn_ldm_stm (int is_dbmode)
15794{
15795 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15796 if (is_ldm)
15797 {
15798 if (is_dbmode)
477330fc 15799 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 15800 else
477330fc 15801 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
15802 }
15803 else
15804 {
15805 if (is_dbmode)
477330fc 15806 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 15807 else
477330fc 15808 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
15809 }
15810}
15811
037e8744
JB
15812static void
15813do_vfp_nsyn_sqrt (void)
15814{
9db2f6b4
RL
15815 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15816 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 15817
9db2f6b4
RL
15818 if (rs == NS_FF || rs == NS_HH)
15819 {
15820 do_vfp_nsyn_opcode ("fsqrts");
15821
15822 /* ARMv8.2 fp16 instruction. */
15823 if (rs == NS_HH)
15824 do_scalar_fp16_v82_encode ();
15825 }
037e8744
JB
15826 else
15827 do_vfp_nsyn_opcode ("fsqrtd");
15828}
15829
15830static void
15831do_vfp_nsyn_div (void)
15832{
9db2f6b4 15833 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15834 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15835 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15836
9db2f6b4
RL
15837 if (rs == NS_FFF || rs == NS_HHH)
15838 {
15839 do_vfp_nsyn_opcode ("fdivs");
15840
15841 /* ARMv8.2 fp16 instruction. */
15842 if (rs == NS_HHH)
15843 do_scalar_fp16_v82_encode ();
15844 }
037e8744
JB
15845 else
15846 do_vfp_nsyn_opcode ("fdivd");
15847}
15848
15849static void
15850do_vfp_nsyn_nmul (void)
15851{
9db2f6b4 15852 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 15853 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 15854 N_F_ALL | N_KEY | N_VFP);
5f4273c7 15855
9db2f6b4 15856 if (rs == NS_FFF || rs == NS_HHH)
037e8744 15857 {
88714cb8 15858 NEON_ENCODE (SINGLE, inst);
037e8744 15859 do_vfp_sp_dyadic ();
9db2f6b4
RL
15860
15861 /* ARMv8.2 fp16 instruction. */
15862 if (rs == NS_HHH)
15863 do_scalar_fp16_v82_encode ();
037e8744
JB
15864 }
15865 else
15866 {
88714cb8 15867 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
15868 do_vfp_dp_rd_rn_rm ();
15869 }
15870 do_vfp_cond_or_thumb ();
9db2f6b4 15871
037e8744
JB
15872}
15873
1b883319
AV
15874/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15875 (0, 1, 2, 3). */
15876
15877static unsigned
15878neon_logbits (unsigned x)
15879{
15880 return ffs (x) - 4;
15881}
15882
15883#define LOW4(R) ((R) & 0xf)
15884#define HI1(R) (((R) >> 4) & 1)
5aae9ae9
MM
15885#define LOW1(R) ((R) & 0x1)
15886#define HI4(R) (((R) >> 1) & 0xf)
1b883319
AV
15887
15888static unsigned
15889mve_get_vcmp_vpt_cond (struct neon_type_el et)
15890{
15891 switch (et.type)
15892 {
15893 default:
15894 first_error (BAD_EL_TYPE);
15895 return 0;
15896 case NT_float:
15897 switch (inst.operands[0].imm)
15898 {
15899 default:
15900 first_error (_("invalid condition"));
15901 return 0;
15902 case 0x0:
15903 /* eq. */
15904 return 0;
15905 case 0x1:
15906 /* ne. */
15907 return 1;
15908 case 0xa:
15909 /* ge/ */
15910 return 4;
15911 case 0xb:
15912 /* lt. */
15913 return 5;
15914 case 0xc:
15915 /* gt. */
15916 return 6;
15917 case 0xd:
15918 /* le. */
15919 return 7;
15920 }
15921 case NT_integer:
15922 /* only accept eq and ne. */
15923 if (inst.operands[0].imm > 1)
15924 {
15925 first_error (_("invalid condition"));
15926 return 0;
15927 }
15928 return inst.operands[0].imm;
15929 case NT_unsigned:
15930 if (inst.operands[0].imm == 0x2)
15931 return 2;
15932 else if (inst.operands[0].imm == 0x8)
15933 return 3;
15934 else
15935 {
15936 first_error (_("invalid condition"));
15937 return 0;
15938 }
15939 case NT_signed:
15940 switch (inst.operands[0].imm)
15941 {
15942 default:
15943 first_error (_("invalid condition"));
15944 return 0;
15945 case 0xa:
15946 /* ge. */
15947 return 4;
15948 case 0xb:
15949 /* lt. */
15950 return 5;
15951 case 0xc:
15952 /* gt. */
15953 return 6;
15954 case 0xd:
15955 /* le. */
15956 return 7;
15957 }
15958 }
15959 /* Should be unreachable. */
15960 abort ();
15961}
15962
efd0b310
SP
15963/* For VCTP (create vector tail predicate) in MVE. */
15964static void
15965do_mve_vctp (void)
15966{
15967 int dt = 0;
15968 unsigned size = 0x0;
15969
15970 if (inst.cond > COND_ALWAYS)
15971 inst.pred_insn_type = INSIDE_VPT_INSN;
15972 else
15973 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15974
15975 /* This is a typical MVE instruction which has no type but have size 8, 16,
15976 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15977 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15978 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15979 dt = inst.vectype.el[0].size;
15980
15981 /* Setting this does not indicate an actual NEON instruction, but only
15982 indicates that the mnemonic accepts neon-style type suffixes. */
15983 inst.is_neon = 1;
15984
15985 switch (dt)
15986 {
15987 case 8:
15988 break;
15989 case 16:
15990 size = 0x1; break;
15991 case 32:
15992 size = 0x2; break;
15993 case 64:
15994 size = 0x3; break;
15995 default:
15996 first_error (_("Type is not allowed for this instruction"));
15997 }
15998 inst.instruction |= size << 20;
15999 inst.instruction |= inst.operands[0].reg << 16;
16000}
16001
1b883319
AV
16002static void
16003do_mve_vpt (void)
16004{
16005 /* We are dealing with a vector predicated block. */
16006 if (inst.operands[0].present)
16007 {
16008 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16009 struct neon_type_el et
16010 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16011 N_EQK);
16012
16013 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16014
16015 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16016
16017 if (et.type == NT_invtype)
16018 return;
16019
16020 if (et.type == NT_float)
16021 {
16022 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16023 BAD_FPU);
16024 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16025 inst.instruction |= (et.size == 16) << 28;
16026 inst.instruction |= 0x3 << 20;
16027 }
16028 else
16029 {
16030 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16031 BAD_EL_TYPE);
16032 inst.instruction |= 1 << 28;
16033 inst.instruction |= neon_logbits (et.size) << 20;
16034 }
16035
16036 if (inst.operands[2].isquad)
16037 {
16038 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16039 inst.instruction |= LOW4 (inst.operands[2].reg);
16040 inst.instruction |= (fcond & 0x2) >> 1;
16041 }
16042 else
16043 {
16044 if (inst.operands[2].reg == REG_SP)
16045 as_tsktsk (MVE_BAD_SP);
16046 inst.instruction |= 1 << 6;
16047 inst.instruction |= (fcond & 0x2) << 4;
16048 inst.instruction |= inst.operands[2].reg;
16049 }
16050 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16051 inst.instruction |= (fcond & 0x4) << 10;
16052 inst.instruction |= (fcond & 0x1) << 7;
16053
16054 }
16055 set_pred_insn_type (VPT_INSN);
16056 now_pred.cc = 0;
16057 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16058 | ((inst.instruction & 0xe000) >> 13);
16059 now_pred.warn_deprecated = FALSE;
16060 now_pred.type = VECTOR_PRED;
16061 inst.is_neon = 1;
16062}
16063
16064static void
16065do_mve_vcmp (void)
16066{
16067 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16068 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16069 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16070 if (!inst.operands[2].present)
16071 first_error (_("MVE vector or ARM register expected"));
16072 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16073
16074 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16075 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16076 && inst.operands[1].isquad)
16077 {
16078 inst.instruction = N_MNEM_vcmp;
16079 inst.cond = 0x10;
16080 }
16081
16082 if (inst.cond > COND_ALWAYS)
16083 inst.pred_insn_type = INSIDE_VPT_INSN;
16084 else
16085 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16086
16087 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16088 struct neon_type_el et
16089 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16090 N_EQK);
16091
16092 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16093 && !inst.operands[2].iszr, BAD_PC);
16094
16095 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16096
16097 inst.instruction = 0xee010f00;
16098 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16099 inst.instruction |= (fcond & 0x4) << 10;
16100 inst.instruction |= (fcond & 0x1) << 7;
16101 if (et.type == NT_float)
16102 {
16103 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16104 BAD_FPU);
16105 inst.instruction |= (et.size == 16) << 28;
16106 inst.instruction |= 0x3 << 20;
16107 }
16108 else
16109 {
16110 inst.instruction |= 1 << 28;
16111 inst.instruction |= neon_logbits (et.size) << 20;
16112 }
16113 if (inst.operands[2].isquad)
16114 {
16115 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16116 inst.instruction |= (fcond & 0x2) >> 1;
16117 inst.instruction |= LOW4 (inst.operands[2].reg);
16118 }
16119 else
16120 {
16121 if (inst.operands[2].reg == REG_SP)
16122 as_tsktsk (MVE_BAD_SP);
16123 inst.instruction |= 1 << 6;
16124 inst.instruction |= (fcond & 0x2) << 4;
16125 inst.instruction |= inst.operands[2].reg;
16126 }
16127
16128 inst.is_neon = 1;
16129 return;
16130}
16131
935295b5
AV
16132static void
16133do_mve_vmaxa_vmina (void)
16134{
16135 if (inst.cond > COND_ALWAYS)
16136 inst.pred_insn_type = INSIDE_VPT_INSN;
16137 else
16138 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16139
16140 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16141 struct neon_type_el et
16142 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16143
16144 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16145 inst.instruction |= neon_logbits (et.size) << 18;
16146 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16147 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16148 inst.instruction |= LOW4 (inst.operands[1].reg);
16149 inst.is_neon = 1;
16150}
16151
f30ee27c
AV
16152static void
16153do_mve_vfmas (void)
16154{
16155 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16156 struct neon_type_el et
16157 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16158
16159 if (inst.cond > COND_ALWAYS)
16160 inst.pred_insn_type = INSIDE_VPT_INSN;
16161 else
16162 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16163
16164 if (inst.operands[2].reg == REG_SP)
16165 as_tsktsk (MVE_BAD_SP);
16166 else if (inst.operands[2].reg == REG_PC)
16167 as_tsktsk (MVE_BAD_PC);
16168
16169 inst.instruction |= (et.size == 16) << 28;
16170 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16171 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16172 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16173 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16174 inst.instruction |= inst.operands[2].reg;
16175 inst.is_neon = 1;
16176}
16177
b409bdb6
AV
16178static void
16179do_mve_viddup (void)
16180{
16181 if (inst.cond > COND_ALWAYS)
16182 inst.pred_insn_type = INSIDE_VPT_INSN;
16183 else
16184 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16185
16186 unsigned imm = inst.relocs[0].exp.X_add_number;
16187 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16188 _("immediate must be either 1, 2, 4 or 8"));
16189
16190 enum neon_shape rs;
16191 struct neon_type_el et;
16192 unsigned Rm;
16193 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16194 {
16195 rs = neon_select_shape (NS_QRI, NS_NULL);
16196 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16197 Rm = 7;
16198 }
16199 else
16200 {
16201 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16202 if (inst.operands[2].reg == REG_SP)
16203 as_tsktsk (MVE_BAD_SP);
16204 else if (inst.operands[2].reg == REG_PC)
16205 first_error (BAD_PC);
16206
16207 rs = neon_select_shape (NS_QRRI, NS_NULL);
16208 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16209 Rm = inst.operands[2].reg >> 1;
16210 }
16211 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16212 inst.instruction |= neon_logbits (et.size) << 20;
16213 inst.instruction |= inst.operands[1].reg << 16;
16214 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16215 inst.instruction |= (imm > 2) << 7;
16216 inst.instruction |= Rm << 1;
16217 inst.instruction |= (imm == 2 || imm == 8);
16218 inst.is_neon = 1;
16219}
16220
2d78f95b
AV
16221static void
16222do_mve_vmlas (void)
16223{
16224 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16225 struct neon_type_el et
16226 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16227
16228 if (inst.operands[2].reg == REG_PC)
16229 as_tsktsk (MVE_BAD_PC);
16230 else if (inst.operands[2].reg == REG_SP)
16231 as_tsktsk (MVE_BAD_SP);
16232
16233 if (inst.cond > COND_ALWAYS)
16234 inst.pred_insn_type = INSIDE_VPT_INSN;
16235 else
16236 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16237
16238 inst.instruction |= (et.type == NT_unsigned) << 28;
16239 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16240 inst.instruction |= neon_logbits (et.size) << 20;
16241 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16242 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16243 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16244 inst.instruction |= inst.operands[2].reg;
16245 inst.is_neon = 1;
16246}
16247
acca5630
AV
16248static void
16249do_mve_vshll (void)
16250{
16251 struct neon_type_el et
16252 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16253
16254 if (inst.cond > COND_ALWAYS)
16255 inst.pred_insn_type = INSIDE_VPT_INSN;
16256 else
16257 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16258
16259 int imm = inst.operands[2].imm;
16260 constraint (imm < 1 || (unsigned)imm > et.size,
16261 _("immediate value out of range"));
16262
16263 if ((unsigned)imm == et.size)
16264 {
16265 inst.instruction |= neon_logbits (et.size) << 18;
16266 inst.instruction |= 0x110001;
16267 }
16268 else
16269 {
16270 inst.instruction |= (et.size + imm) << 16;
16271 inst.instruction |= 0x800140;
16272 }
16273
16274 inst.instruction |= (et.type == NT_unsigned) << 28;
16275 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16276 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16277 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16278 inst.instruction |= LOW4 (inst.operands[1].reg);
16279 inst.is_neon = 1;
16280}
16281
16282static void
16283do_mve_vshlc (void)
16284{
16285 if (inst.cond > COND_ALWAYS)
16286 inst.pred_insn_type = INSIDE_VPT_INSN;
16287 else
16288 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16289
16290 if (inst.operands[1].reg == REG_PC)
16291 as_tsktsk (MVE_BAD_PC);
16292 else if (inst.operands[1].reg == REG_SP)
16293 as_tsktsk (MVE_BAD_SP);
16294
16295 int imm = inst.operands[2].imm;
16296 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16297
16298 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16299 inst.instruction |= (imm & 0x1f) << 16;
16300 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16301 inst.instruction |= inst.operands[1].reg;
16302 inst.is_neon = 1;
16303}
16304
4aa88b50
AV
16305static void
16306do_mve_vshrn (void)
16307{
16308 unsigned types;
16309 switch (inst.instruction)
16310 {
16311 case M_MNEM_vshrnt:
16312 case M_MNEM_vshrnb:
16313 case M_MNEM_vrshrnt:
16314 case M_MNEM_vrshrnb:
16315 types = N_I16 | N_I32;
16316 break;
16317 case M_MNEM_vqshrnt:
16318 case M_MNEM_vqshrnb:
16319 case M_MNEM_vqrshrnt:
16320 case M_MNEM_vqrshrnb:
16321 types = N_U16 | N_U32 | N_S16 | N_S32;
16322 break;
16323 case M_MNEM_vqshrunt:
16324 case M_MNEM_vqshrunb:
16325 case M_MNEM_vqrshrunt:
16326 case M_MNEM_vqrshrunb:
16327 types = N_S16 | N_S32;
16328 break;
16329 default:
16330 abort ();
16331 }
16332
16333 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16334
16335 if (inst.cond > COND_ALWAYS)
16336 inst.pred_insn_type = INSIDE_VPT_INSN;
16337 else
16338 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16339
16340 unsigned Qd = inst.operands[0].reg;
16341 unsigned Qm = inst.operands[1].reg;
16342 unsigned imm = inst.operands[2].imm;
16343 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16344 et.size == 16
16345 ? _("immediate operand expected in the range [1,8]")
16346 : _("immediate operand expected in the range [1,16]"));
16347
16348 inst.instruction |= (et.type == NT_unsigned) << 28;
16349 inst.instruction |= HI1 (Qd) << 22;
16350 inst.instruction |= (et.size - imm) << 16;
16351 inst.instruction |= LOW4 (Qd) << 12;
16352 inst.instruction |= HI1 (Qm) << 5;
16353 inst.instruction |= LOW4 (Qm);
16354 inst.is_neon = 1;
16355}
16356
1be7aba3
AV
16357static void
16358do_mve_vqmovn (void)
16359{
16360 struct neon_type_el et;
16361 if (inst.instruction == M_MNEM_vqmovnt
16362 || inst.instruction == M_MNEM_vqmovnb)
16363 et = neon_check_type (2, NS_QQ, N_EQK,
16364 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16365 else
16366 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16367
16368 if (inst.cond > COND_ALWAYS)
16369 inst.pred_insn_type = INSIDE_VPT_INSN;
16370 else
16371 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16372
16373 inst.instruction |= (et.type == NT_unsigned) << 28;
16374 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16375 inst.instruction |= (et.size == 32) << 18;
16376 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16377 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16378 inst.instruction |= LOW4 (inst.operands[1].reg);
16379 inst.is_neon = 1;
16380}
16381
3063888e
AV
16382static void
16383do_mve_vpsel (void)
16384{
16385 neon_select_shape (NS_QQQ, NS_NULL);
16386
16387 if (inst.cond > COND_ALWAYS)
16388 inst.pred_insn_type = INSIDE_VPT_INSN;
16389 else
16390 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16391
16392 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16393 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16394 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16395 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16396 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16397 inst.instruction |= LOW4 (inst.operands[2].reg);
16398 inst.is_neon = 1;
16399}
16400
16401static void
16402do_mve_vpnot (void)
16403{
16404 if (inst.cond > COND_ALWAYS)
16405 inst.pred_insn_type = INSIDE_VPT_INSN;
16406 else
16407 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16408}
16409
935295b5
AV
16410static void
16411do_mve_vmaxnma_vminnma (void)
16412{
16413 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16414 struct neon_type_el et
16415 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16416
16417 if (inst.cond > COND_ALWAYS)
16418 inst.pred_insn_type = INSIDE_VPT_INSN;
16419 else
16420 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16421
16422 inst.instruction |= (et.size == 16) << 28;
16423 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16425 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16426 inst.instruction |= LOW4 (inst.operands[1].reg);
16427 inst.is_neon = 1;
16428}
16429
5d281bf0
AV
16430static void
16431do_mve_vcmul (void)
16432{
16433 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16434 struct neon_type_el et
16435 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16436
16437 if (inst.cond > COND_ALWAYS)
16438 inst.pred_insn_type = INSIDE_VPT_INSN;
16439 else
16440 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16441
16442 unsigned rot = inst.relocs[0].exp.X_add_number;
16443 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16444 _("immediate out of range"));
16445
16446 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16447 || inst.operands[0].reg == inst.operands[2].reg))
16448 as_tsktsk (BAD_MVE_SRCDEST);
16449
16450 inst.instruction |= (et.size == 32) << 28;
16451 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16452 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16453 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16454 inst.instruction |= (rot > 90) << 12;
16455 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16456 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16457 inst.instruction |= LOW4 (inst.operands[2].reg);
16458 inst.instruction |= (rot == 90 || rot == 270);
16459 inst.is_neon = 1;
16460}
16461
1f6234a3
AV
16462/* To handle the Low Overhead Loop instructions
16463 in Armv8.1-M Mainline and MVE. */
16464static void
16465do_t_loloop (void)
16466{
16467 unsigned long insn = inst.instruction;
16468
16469 inst.instruction = THUMB_OP32 (inst.instruction);
16470
16471 if (insn == T_MNEM_lctp)
16472 return;
16473
16474 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16475
16476 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16477 {
16478 struct neon_type_el et
16479 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16480 inst.instruction |= neon_logbits (et.size) << 20;
16481 inst.is_neon = 1;
16482 }
16483
16484 switch (insn)
16485 {
16486 case T_MNEM_letp:
16487 constraint (!inst.operands[0].present,
16488 _("expected LR"));
16489 /* fall through. */
16490 case T_MNEM_le:
16491 /* le <label>. */
16492 if (!inst.operands[0].present)
16493 inst.instruction |= 1 << 21;
16494
16495 v8_1_loop_reloc (TRUE);
16496 break;
16497
16498 case T_MNEM_wls:
16499 case T_MNEM_wlstp:
16500 v8_1_loop_reloc (FALSE);
16501 /* fall through. */
16502 case T_MNEM_dlstp:
16503 case T_MNEM_dls:
16504 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16505
16506 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16507 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16508 else if (inst.operands[1].reg == REG_PC)
16509 as_tsktsk (MVE_BAD_PC);
16510 if (inst.operands[1].reg == REG_SP)
16511 as_tsktsk (MVE_BAD_SP);
16512
16513 inst.instruction |= (inst.operands[1].reg << 16);
16514 break;
16515
16516 default:
16517 abort ();
16518 }
16519}
16520
16521
037e8744
JB
16522static void
16523do_vfp_nsyn_cmp (void)
16524{
9db2f6b4 16525 enum neon_shape rs;
1b883319
AV
16526 if (!inst.operands[0].isreg)
16527 {
16528 do_mve_vcmp ();
16529 return;
16530 }
16531 else
16532 {
16533 constraint (inst.operands[2].present, BAD_SYNTAX);
16534 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16535 BAD_FPU);
16536 }
16537
037e8744
JB
16538 if (inst.operands[1].isreg)
16539 {
9db2f6b4
RL
16540 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16541 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 16542
9db2f6b4 16543 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
16544 {
16545 NEON_ENCODE (SINGLE, inst);
16546 do_vfp_sp_monadic ();
16547 }
037e8744 16548 else
477330fc
RM
16549 {
16550 NEON_ENCODE (DOUBLE, inst);
16551 do_vfp_dp_rd_rm ();
16552 }
037e8744
JB
16553 }
16554 else
16555 {
9db2f6b4
RL
16556 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16557 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
16558
16559 switch (inst.instruction & 0x0fffffff)
477330fc
RM
16560 {
16561 case N_MNEM_vcmp:
16562 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16563 break;
16564 case N_MNEM_vcmpe:
16565 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16566 break;
16567 default:
16568 abort ();
16569 }
5f4273c7 16570
9db2f6b4 16571 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
16572 {
16573 NEON_ENCODE (SINGLE, inst);
16574 do_vfp_sp_compare_z ();
16575 }
037e8744 16576 else
477330fc
RM
16577 {
16578 NEON_ENCODE (DOUBLE, inst);
16579 do_vfp_dp_rd ();
16580 }
037e8744
JB
16581 }
16582 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16583
16584 /* ARMv8.2 fp16 instruction. */
16585 if (rs == NS_HI || rs == NS_HH)
16586 do_scalar_fp16_v82_encode ();
037e8744
JB
16587}
16588
16589static void
16590nsyn_insert_sp (void)
16591{
16592 inst.operands[1] = inst.operands[0];
16593 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 16594 inst.operands[0].reg = REG_SP;
037e8744
JB
16595 inst.operands[0].isreg = 1;
16596 inst.operands[0].writeback = 1;
16597 inst.operands[0].present = 1;
16598}
16599
037e8744
JB
16600/* Fix up Neon data-processing instructions, ORing in the correct bits for
16601 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16602
88714cb8
DG
16603static void
16604neon_dp_fixup (struct arm_it* insn)
037e8744 16605{
88714cb8
DG
16606 unsigned int i = insn->instruction;
16607 insn->is_neon = 1;
16608
037e8744
JB
16609 if (thumb_mode)
16610 {
16611 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16612 if (i & (1 << 24))
477330fc 16613 i |= 1 << 28;
5f4273c7 16614
037e8744 16615 i &= ~(1 << 24);
5f4273c7 16616
037e8744
JB
16617 i |= 0xef000000;
16618 }
16619 else
16620 i |= 0xf2000000;
5f4273c7 16621
88714cb8 16622 insn->instruction = i;
037e8744
JB
16623}
16624
5ee91343 16625static void
7df54120 16626mve_encode_qqr (int size, int U, int fp)
5ee91343
AV
16627{
16628 if (inst.operands[2].reg == REG_SP)
16629 as_tsktsk (MVE_BAD_SP);
16630 else if (inst.operands[2].reg == REG_PC)
16631 as_tsktsk (MVE_BAD_PC);
16632
16633 if (fp)
16634 {
16635 /* vadd. */
16636 if (((unsigned)inst.instruction) == 0xd00)
16637 inst.instruction = 0xee300f40;
16638 /* vsub. */
16639 else if (((unsigned)inst.instruction) == 0x200d00)
16640 inst.instruction = 0xee301f40;
a8465a06
AV
16641 /* vmul. */
16642 else if (((unsigned)inst.instruction) == 0x1000d10)
16643 inst.instruction = 0xee310e60;
5ee91343
AV
16644
16645 /* Setting size which is 1 for F16 and 0 for F32. */
16646 inst.instruction |= (size == 16) << 28;
16647 }
16648 else
16649 {
16650 /* vadd. */
16651 if (((unsigned)inst.instruction) == 0x800)
16652 inst.instruction = 0xee010f40;
16653 /* vsub. */
16654 else if (((unsigned)inst.instruction) == 0x1000800)
16655 inst.instruction = 0xee011f40;
7df54120
AV
16656 /* vhadd. */
16657 else if (((unsigned)inst.instruction) == 0)
16658 inst.instruction = 0xee000f40;
16659 /* vhsub. */
16660 else if (((unsigned)inst.instruction) == 0x200)
16661 inst.instruction = 0xee001f40;
a8465a06
AV
16662 /* vmla. */
16663 else if (((unsigned)inst.instruction) == 0x900)
16664 inst.instruction = 0xee010e40;
16665 /* vmul. */
16666 else if (((unsigned)inst.instruction) == 0x910)
16667 inst.instruction = 0xee011e60;
16668 /* vqadd. */
16669 else if (((unsigned)inst.instruction) == 0x10)
16670 inst.instruction = 0xee000f60;
16671 /* vqsub. */
16672 else if (((unsigned)inst.instruction) == 0x210)
16673 inst.instruction = 0xee001f60;
42b16635
AV
16674 /* vqrdmlah. */
16675 else if (((unsigned)inst.instruction) == 0x3000b10)
16676 inst.instruction = 0xee000e40;
16677 /* vqdmulh. */
16678 else if (((unsigned)inst.instruction) == 0x0000b00)
16679 inst.instruction = 0xee010e60;
16680 /* vqrdmulh. */
16681 else if (((unsigned)inst.instruction) == 0x1000b00)
16682 inst.instruction = 0xfe010e60;
7df54120
AV
16683
16684 /* Set U-bit. */
16685 inst.instruction |= U << 28;
16686
5ee91343
AV
16687 /* Setting bits for size. */
16688 inst.instruction |= neon_logbits (size) << 20;
16689 }
16690 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16691 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16692 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16693 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16694 inst.instruction |= inst.operands[2].reg;
16695 inst.is_neon = 1;
16696}
16697
a302e574
AV
16698static void
16699mve_encode_rqq (unsigned bit28, unsigned size)
16700{
16701 inst.instruction |= bit28 << 28;
16702 inst.instruction |= neon_logbits (size) << 20;
16703 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16704 inst.instruction |= inst.operands[0].reg << 12;
16705 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16706 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16707 inst.instruction |= LOW4 (inst.operands[2].reg);
16708 inst.is_neon = 1;
16709}
16710
886e1c73
AV
16711static void
16712mve_encode_qqq (int ubit, int size)
16713{
16714
16715 inst.instruction |= (ubit != 0) << 28;
16716 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16717 inst.instruction |= neon_logbits (size) << 20;
16718 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16719 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16720 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16721 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16722 inst.instruction |= LOW4 (inst.operands[2].reg);
16723
16724 inst.is_neon = 1;
16725}
16726
26c1e780
AV
16727static void
16728mve_encode_rq (unsigned bit28, unsigned size)
16729{
16730 inst.instruction |= bit28 << 28;
16731 inst.instruction |= neon_logbits (size) << 18;
16732 inst.instruction |= inst.operands[0].reg << 12;
16733 inst.instruction |= LOW4 (inst.operands[1].reg);
16734 inst.is_neon = 1;
16735}
886e1c73 16736
93925576
AV
16737static void
16738mve_encode_rrqq (unsigned U, unsigned size)
16739{
16740 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16741
16742 inst.instruction |= U << 28;
16743 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16744 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16745 inst.instruction |= (size == 32) << 16;
16746 inst.instruction |= inst.operands[0].reg << 12;
16747 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16748 inst.instruction |= inst.operands[3].reg;
16749 inst.is_neon = 1;
16750}
16751
aab2c27d
MM
16752/* Helper function for neon_three_same handling the operands. */
16753static void
16754neon_three_args (int isquad)
16755{
16756 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16757 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16758 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16759 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16760 inst.instruction |= LOW4 (inst.operands[2].reg);
16761 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16762 inst.instruction |= (isquad != 0) << 6;
16763 inst.is_neon = 1;
16764}
16765
037e8744
JB
16766/* Encode insns with bit pattern:
16767
16768 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16769 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 16770
037e8744
JB
16771 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16772 different meaning for some instruction. */
16773
16774static void
16775neon_three_same (int isquad, int ubit, int size)
16776{
aab2c27d 16777 neon_three_args (isquad);
037e8744
JB
16778 inst.instruction |= (ubit != 0) << 24;
16779 if (size != -1)
16780 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16781
88714cb8 16782 neon_dp_fixup (&inst);
037e8744
JB
16783}
16784
16785/* Encode instructions of the form:
16786
16787 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16788 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
16789
16790 Don't write size if SIZE == -1. */
16791
16792static void
16793neon_two_same (int qbit, int ubit, int size)
16794{
16795 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16796 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16797 inst.instruction |= LOW4 (inst.operands[1].reg);
16798 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16799 inst.instruction |= (qbit != 0) << 6;
16800 inst.instruction |= (ubit != 0) << 24;
16801
16802 if (size != -1)
16803 inst.instruction |= neon_logbits (size) << 18;
16804
88714cb8 16805 neon_dp_fixup (&inst);
5287ad62
JB
16806}
16807
7df54120
AV
16808enum vfp_or_neon_is_neon_bits
16809{
16810NEON_CHECK_CC = 1,
16811NEON_CHECK_ARCH = 2,
16812NEON_CHECK_ARCH8 = 4
16813};
16814
16815/* Call this function if an instruction which may have belonged to the VFP or
16816 Neon instruction sets, but turned out to be a Neon instruction (due to the
16817 operand types involved, etc.). We have to check and/or fix-up a couple of
16818 things:
16819
16820 - Make sure the user hasn't attempted to make a Neon instruction
16821 conditional.
16822 - Alter the value in the condition code field if necessary.
16823 - Make sure that the arch supports Neon instructions.
16824
16825 Which of these operations take place depends on bits from enum
16826 vfp_or_neon_is_neon_bits.
16827
16828 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16829 current instruction's condition is COND_ALWAYS, the condition field is
16830 changed to inst.uncond_value. This is necessary because instructions shared
16831 between VFP and Neon may be conditional for the VFP variants only, and the
16832 unconditional Neon version must have, e.g., 0xF in the condition field. */
16833
16834static int
16835vfp_or_neon_is_neon (unsigned check)
16836{
16837/* Conditions are always legal in Thumb mode (IT blocks). */
16838if (!thumb_mode && (check & NEON_CHECK_CC))
16839 {
16840 if (inst.cond != COND_ALWAYS)
16841 {
16842 first_error (_(BAD_COND));
16843 return FAIL;
16844 }
7af67752 16845 if (inst.uncond_value != -1u)
7df54120
AV
16846 inst.instruction |= inst.uncond_value << 28;
16847 }
16848
16849
16850 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16851 || ((check & NEON_CHECK_ARCH8)
16852 && !mark_feature_used (&fpu_neon_ext_armv8)))
16853 {
16854 first_error (_(BAD_FPU));
16855 return FAIL;
16856 }
16857
16858return SUCCESS;
16859}
16860
64c350f2
AV
16861
16862/* Return TRUE if the SIMD instruction is available for the current
16863 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16864 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16865 vfp_or_neon_is_neon for the NEON specific checks. */
16866
16867static bfd_boolean
7df54120
AV
16868check_simd_pred_availability (int fp, unsigned check)
16869{
16870if (inst.cond > COND_ALWAYS)
16871 {
16872 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16873 {
16874 inst.error = BAD_FPU;
64c350f2 16875 return FALSE;
7df54120
AV
16876 }
16877 inst.pred_insn_type = INSIDE_VPT_INSN;
16878 }
16879else if (inst.cond < COND_ALWAYS)
16880 {
16881 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16882 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16883 else if (vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16884 return FALSE;
7df54120
AV
16885 }
16886else
16887 {
16888 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16889 && vfp_or_neon_is_neon (check) == FAIL)
64c350f2 16890 return FALSE;
7df54120
AV
16891
16892 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16893 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16894 }
64c350f2 16895return TRUE;
7df54120
AV
16896}
16897
5287ad62
JB
16898/* Neon instruction encoders, in approximate order of appearance. */
16899
16900static void
16901do_neon_dyadic_i_su (void)
16902{
64c350f2 16903 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
7df54120
AV
16904 return;
16905
16906 enum neon_shape rs;
16907 struct neon_type_el et;
16908 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16909 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16910 else
16911 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16912
16913 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16914
16915
16916 if (rs != NS_QQR)
16917 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16918 else
16919 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
5287ad62
JB
16920}
16921
16922static void
16923do_neon_dyadic_i64_su (void)
16924{
64c350f2 16925 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
a8465a06
AV
16926 return;
16927 enum neon_shape rs;
16928 struct neon_type_el et;
16929 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16930 {
16931 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16932 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16933 }
16934 else
16935 {
16936 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16937 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16938 }
16939 if (rs == NS_QQR)
16940 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16941 else
16942 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
16943}
16944
16945static void
16946neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 16947 unsigned immbits)
5287ad62
JB
16948{
16949 unsigned size = et.size >> 3;
16950 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16951 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16952 inst.instruction |= LOW4 (inst.operands[1].reg);
16953 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16954 inst.instruction |= (isquad != 0) << 6;
16955 inst.instruction |= immbits << 16;
16956 inst.instruction |= (size >> 3) << 7;
16957 inst.instruction |= (size & 0x7) << 19;
16958 if (write_ubit)
16959 inst.instruction |= (uval != 0) << 24;
16960
88714cb8 16961 neon_dp_fixup (&inst);
5287ad62
JB
16962}
16963
16964static void
5150f0d8 16965do_neon_shl (void)
5287ad62 16966{
64c350f2 16967 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
16968 return;
16969
5287ad62
JB
16970 if (!inst.operands[2].isreg)
16971 {
5150f0d8
AV
16972 enum neon_shape rs;
16973 struct neon_type_el et;
16974 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16975 {
16976 rs = neon_select_shape (NS_QQI, NS_NULL);
16977 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16978 }
16979 else
16980 {
16981 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16982 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16983 }
cb3b1e65
JB
16984 int imm = inst.operands[2].imm;
16985
16986 constraint (imm < 0 || (unsigned)imm >= et.size,
16987 _("immediate out of range for shift"));
88714cb8 16988 NEON_ENCODE (IMMED, inst);
cb3b1e65 16989 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
16990 }
16991 else
16992 {
5150f0d8
AV
16993 enum neon_shape rs;
16994 struct neon_type_el et;
16995 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16996 {
16997 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16998 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16999 }
17000 else
17001 {
17002 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17003 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17004 }
17005
17006
17007 if (rs == NS_QQR)
17008 {
17009 constraint (inst.operands[0].reg != inst.operands[1].reg,
17010 _("invalid instruction shape"));
17011 if (inst.operands[2].reg == REG_SP)
17012 as_tsktsk (MVE_BAD_SP);
17013 else if (inst.operands[2].reg == REG_PC)
17014 as_tsktsk (MVE_BAD_PC);
17015
17016 inst.instruction = 0xee311e60;
17017 inst.instruction |= (et.type == NT_unsigned) << 28;
17018 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17019 inst.instruction |= neon_logbits (et.size) << 18;
17020 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17021 inst.instruction |= inst.operands[2].reg;
17022 inst.is_neon = 1;
17023 }
17024 else
17025 {
17026 unsigned int tmp;
17027
17028 /* VSHL/VQSHL 3-register variants have syntax such as:
17029 vshl.xx Dd, Dm, Dn
17030 whereas other 3-register operations encoded by neon_three_same have
17031 syntax like:
17032 vadd.xx Dd, Dn, Dm
17033 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17034 operands[2].reg here. */
17035 tmp = inst.operands[2].reg;
17036 inst.operands[2].reg = inst.operands[1].reg;
17037 inst.operands[1].reg = tmp;
17038 NEON_ENCODE (INTEGER, inst);
17039 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17040 }
5287ad62
JB
17041 }
17042}
17043
17044static void
5150f0d8 17045do_neon_qshl (void)
5287ad62 17046{
64c350f2 17047 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
17048 return;
17049
5287ad62
JB
17050 if (!inst.operands[2].isreg)
17051 {
5150f0d8
AV
17052 enum neon_shape rs;
17053 struct neon_type_el et;
17054 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17055 {
17056 rs = neon_select_shape (NS_QQI, NS_NULL);
17057 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17058 }
17059 else
17060 {
17061 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17062 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17063 }
cb3b1e65 17064 int imm = inst.operands[2].imm;
627907b7 17065
cb3b1e65
JB
17066 constraint (imm < 0 || (unsigned)imm >= et.size,
17067 _("immediate out of range for shift"));
88714cb8 17068 NEON_ENCODE (IMMED, inst);
cb3b1e65 17069 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
17070 }
17071 else
17072 {
5150f0d8
AV
17073 enum neon_shape rs;
17074 struct neon_type_el et;
627907b7 17075
5150f0d8
AV
17076 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17077 {
17078 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17079 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17080 }
17081 else
17082 {
17083 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17084 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17085 }
17086
17087 if (rs == NS_QQR)
17088 {
17089 constraint (inst.operands[0].reg != inst.operands[1].reg,
17090 _("invalid instruction shape"));
17091 if (inst.operands[2].reg == REG_SP)
17092 as_tsktsk (MVE_BAD_SP);
17093 else if (inst.operands[2].reg == REG_PC)
17094 as_tsktsk (MVE_BAD_PC);
17095
17096 inst.instruction = 0xee311ee0;
17097 inst.instruction |= (et.type == NT_unsigned) << 28;
17098 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17099 inst.instruction |= neon_logbits (et.size) << 18;
17100 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17101 inst.instruction |= inst.operands[2].reg;
17102 inst.is_neon = 1;
17103 }
17104 else
17105 {
17106 unsigned int tmp;
17107
17108 /* See note in do_neon_shl. */
17109 tmp = inst.operands[2].reg;
17110 inst.operands[2].reg = inst.operands[1].reg;
17111 inst.operands[1].reg = tmp;
17112 NEON_ENCODE (INTEGER, inst);
17113 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17114 }
5287ad62
JB
17115 }
17116}
17117
627907b7
JB
17118static void
17119do_neon_rshl (void)
17120{
64c350f2 17121 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
1be7aba3
AV
17122 return;
17123
17124 enum neon_shape rs;
17125 struct neon_type_el et;
17126 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17127 {
17128 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17129 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17130 }
17131 else
17132 {
17133 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17134 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17135 }
17136
627907b7
JB
17137 unsigned int tmp;
17138
1be7aba3
AV
17139 if (rs == NS_QQR)
17140 {
17141 if (inst.operands[2].reg == REG_PC)
17142 as_tsktsk (MVE_BAD_PC);
17143 else if (inst.operands[2].reg == REG_SP)
17144 as_tsktsk (MVE_BAD_SP);
17145
17146 constraint (inst.operands[0].reg != inst.operands[1].reg,
17147 _("invalid instruction shape"));
17148
17149 if (inst.instruction == 0x0000510)
17150 /* We are dealing with vqrshl. */
17151 inst.instruction = 0xee331ee0;
17152 else
17153 /* We are dealing with vrshl. */
17154 inst.instruction = 0xee331e60;
17155
17156 inst.instruction |= (et.type == NT_unsigned) << 28;
17157 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17158 inst.instruction |= neon_logbits (et.size) << 18;
17159 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17160 inst.instruction |= inst.operands[2].reg;
17161 inst.is_neon = 1;
17162 }
17163 else
17164 {
17165 tmp = inst.operands[2].reg;
17166 inst.operands[2].reg = inst.operands[1].reg;
17167 inst.operands[1].reg = tmp;
17168 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17169 }
627907b7
JB
17170}
17171
5287ad62
JB
17172static int
17173neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17174{
036dc3f7
PB
17175 /* Handle .I8 pseudo-instructions. */
17176 if (size == 8)
5287ad62 17177 {
5287ad62 17178 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
17179 FIXME is this the intended semantics? There doesn't seem much point in
17180 accepting .I8 if so. */
5287ad62
JB
17181 immediate |= immediate << 8;
17182 size = 16;
036dc3f7
PB
17183 }
17184
17185 if (size >= 32)
17186 {
17187 if (immediate == (immediate & 0x000000ff))
17188 {
17189 *immbits = immediate;
17190 return 0x1;
17191 }
17192 else if (immediate == (immediate & 0x0000ff00))
17193 {
17194 *immbits = immediate >> 8;
17195 return 0x3;
17196 }
17197 else if (immediate == (immediate & 0x00ff0000))
17198 {
17199 *immbits = immediate >> 16;
17200 return 0x5;
17201 }
17202 else if (immediate == (immediate & 0xff000000))
17203 {
17204 *immbits = immediate >> 24;
17205 return 0x7;
17206 }
17207 if ((immediate & 0xffff) != (immediate >> 16))
17208 goto bad_immediate;
17209 immediate &= 0xffff;
5287ad62
JB
17210 }
17211
17212 if (immediate == (immediate & 0x000000ff))
17213 {
17214 *immbits = immediate;
036dc3f7 17215 return 0x9;
5287ad62
JB
17216 }
17217 else if (immediate == (immediate & 0x0000ff00))
17218 {
17219 *immbits = immediate >> 8;
036dc3f7 17220 return 0xb;
5287ad62
JB
17221 }
17222
17223 bad_immediate:
dcbf9037 17224 first_error (_("immediate value out of range"));
5287ad62
JB
17225 return FAIL;
17226}
17227
5287ad62
JB
17228static void
17229do_neon_logic (void)
17230{
17231 if (inst.operands[2].present && inst.operands[2].isreg)
17232 {
037e8744 17233 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
f601a00c 17234 if (rs == NS_QQQ
64c350f2
AV
17235 && !check_simd_pred_availability (FALSE,
17236 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17237 return;
17238 else if (rs != NS_QQQ
17239 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17240 first_error (BAD_FPU);
17241
5287ad62
JB
17242 neon_check_type (3, rs, N_IGNORE_TYPE);
17243 /* U bit and size field were set as part of the bitmask. */
88714cb8 17244 NEON_ENCODE (INTEGER, inst);
037e8744 17245 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17246 }
17247 else
17248 {
4316f0d2
DG
17249 const int three_ops_form = (inst.operands[2].present
17250 && !inst.operands[2].isreg);
17251 const int immoperand = (three_ops_form ? 2 : 1);
17252 enum neon_shape rs = (three_ops_form
17253 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17254 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
f601a00c
AV
17255 /* Because neon_select_shape makes the second operand a copy of the first
17256 if the second operand is not present. */
17257 if (rs == NS_QQI
64c350f2
AV
17258 && !check_simd_pred_availability (FALSE,
17259 NEON_CHECK_ARCH | NEON_CHECK_CC))
f601a00c
AV
17260 return;
17261 else if (rs != NS_QQI
17262 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17263 first_error (BAD_FPU);
17264
17265 struct neon_type_el et;
17266 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17267 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17268 else
17269 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17270 | N_KEY, N_EQK);
17271
17272 if (et.type == NT_invtype)
17273 return;
21d799b5 17274 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
17275 unsigned immbits;
17276 int cmode;
5f4273c7 17277
5f4273c7 17278
4316f0d2
DG
17279 if (three_ops_form)
17280 constraint (inst.operands[0].reg != inst.operands[1].reg,
17281 _("first and second operands shall be the same register"));
17282
88714cb8 17283 NEON_ENCODE (IMMED, inst);
5287ad62 17284
4316f0d2 17285 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
17286 if (et.size == 64)
17287 {
17288 /* .i64 is a pseudo-op, so the immediate must be a repeating
17289 pattern. */
4316f0d2
DG
17290 if (immbits != (inst.operands[immoperand].regisimm ?
17291 inst.operands[immoperand].reg : 0))
036dc3f7
PB
17292 {
17293 /* Set immbits to an invalid constant. */
17294 immbits = 0xdeadbeef;
17295 }
17296 }
17297
5287ad62 17298 switch (opcode)
477330fc
RM
17299 {
17300 case N_MNEM_vbic:
17301 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17302 break;
17303
17304 case N_MNEM_vorr:
17305 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17306 break;
17307
17308 case N_MNEM_vand:
17309 /* Pseudo-instruction for VBIC. */
17310 neon_invert_size (&immbits, 0, et.size);
17311 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17312 break;
17313
17314 case N_MNEM_vorn:
17315 /* Pseudo-instruction for VORR. */
17316 neon_invert_size (&immbits, 0, et.size);
17317 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17318 break;
17319
17320 default:
17321 abort ();
17322 }
5287ad62
JB
17323
17324 if (cmode == FAIL)
477330fc 17325 return;
5287ad62 17326
037e8744 17327 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17329 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17330 inst.instruction |= cmode << 8;
17331 neon_write_immbits (immbits);
5f4273c7 17332
88714cb8 17333 neon_dp_fixup (&inst);
5287ad62
JB
17334 }
17335}
17336
17337static void
17338do_neon_bitfield (void)
17339{
037e8744 17340 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 17341 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 17342 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
17343}
17344
17345static void
dcbf9037 17346neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 17347 unsigned destbits)
5287ad62 17348{
5ee91343 17349 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
dcbf9037 17350 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 17351 types | N_KEY);
5287ad62
JB
17352 if (et.type == NT_float)
17353 {
88714cb8 17354 NEON_ENCODE (FLOAT, inst);
5ee91343 17355 if (rs == NS_QQR)
7df54120 17356 mve_encode_qqr (et.size, 0, 1);
5ee91343
AV
17357 else
17358 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
17359 }
17360 else
17361 {
88714cb8 17362 NEON_ENCODE (INTEGER, inst);
5ee91343 17363 if (rs == NS_QQR)
a8465a06 17364 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
5ee91343
AV
17365 else
17366 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
17367 }
17368}
17369
5287ad62
JB
17370
17371static void
17372do_neon_dyadic_if_su_d (void)
17373{
17374 /* This version only allow D registers, but that constraint is enforced during
17375 operand parsing so we don't need to do anything extra here. */
dcbf9037 17376 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
17377}
17378
5287ad62
JB
17379static void
17380do_neon_dyadic_if_i_d (void)
17381{
428e3f1f
PB
17382 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17383 affected if we specify unsigned args. */
17384 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
17385}
17386
f5f10c66
AV
17387static void
17388do_mve_vstr_vldr_QI (int size, int elsize, int load)
17389{
17390 constraint (size < 32, BAD_ADDR_MODE);
17391 constraint (size != elsize, BAD_EL_TYPE);
17392 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17393 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17394 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17395 _("destination register and offset register may not be the"
17396 " same"));
17397
17398 int imm = inst.relocs[0].exp.X_add_number;
17399 int add = 1;
17400 if (imm < 0)
17401 {
17402 add = 0;
17403 imm = -imm;
17404 }
17405 constraint ((imm % (size / 8) != 0)
17406 || imm > (0x7f << neon_logbits (size)),
17407 (size == 32) ? _("immediate must be a multiple of 4 in the"
17408 " range of +/-[0,508]")
17409 : _("immediate must be a multiple of 8 in the"
17410 " range of +/-[0,1016]"));
17411 inst.instruction |= 0x11 << 24;
17412 inst.instruction |= add << 23;
17413 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17414 inst.instruction |= inst.operands[1].writeback << 21;
17415 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17416 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17417 inst.instruction |= 1 << 12;
17418 inst.instruction |= (size == 64) << 8;
17419 inst.instruction &= 0xffffff00;
17420 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17421 inst.instruction |= imm >> neon_logbits (size);
17422}
17423
17424static void
17425do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17426{
17427 unsigned os = inst.operands[1].imm >> 5;
e449ea97 17428 unsigned type = inst.vectype.el[0].type;
f5f10c66
AV
17429 constraint (os != 0 && size == 8,
17430 _("can not shift offsets when accessing less than half-word"));
17431 constraint (os && os != neon_logbits (size),
17432 _("shift immediate must be 1, 2 or 3 for half-word, word"
17433 " or double-word accesses respectively"));
17434 if (inst.operands[1].reg == REG_PC)
17435 as_tsktsk (MVE_BAD_PC);
17436
17437 switch (size)
17438 {
17439 case 8:
17440 constraint (elsize >= 64, BAD_EL_TYPE);
17441 break;
17442 case 16:
17443 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17444 break;
17445 case 32:
17446 case 64:
17447 constraint (elsize != size, BAD_EL_TYPE);
17448 break;
17449 default:
17450 break;
17451 }
17452 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17453 BAD_ADDR_MODE);
17454 if (load)
17455 {
17456 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17457 _("destination register and offset register may not be"
17458 " the same"));
e449ea97
SP
17459 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17460 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
f5f10c66 17461 BAD_EL_TYPE);
e449ea97 17462 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
f5f10c66
AV
17463 }
17464 else
17465 {
e449ea97 17466 constraint (type != NT_untyped, BAD_EL_TYPE);
f5f10c66
AV
17467 }
17468
17469 inst.instruction |= 1 << 23;
17470 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17471 inst.instruction |= inst.operands[1].reg << 16;
17472 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17473 inst.instruction |= neon_logbits (elsize) << 7;
17474 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17475 inst.instruction |= LOW4 (inst.operands[1].imm);
17476 inst.instruction |= !!os;
17477}
17478
17479static void
17480do_mve_vstr_vldr_RI (int size, int elsize, int load)
17481{
17482 enum neon_el_type type = inst.vectype.el[0].type;
17483
17484 constraint (size >= 64, BAD_ADDR_MODE);
17485 switch (size)
17486 {
17487 case 16:
17488 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17489 break;
17490 case 32:
17491 constraint (elsize != size, BAD_EL_TYPE);
17492 break;
17493 default:
17494 break;
17495 }
17496 if (load)
17497 {
17498 constraint (elsize != size && type != NT_unsigned
17499 && type != NT_signed, BAD_EL_TYPE);
17500 }
17501 else
17502 {
17503 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17504 }
17505
17506 int imm = inst.relocs[0].exp.X_add_number;
17507 int add = 1;
17508 if (imm < 0)
17509 {
17510 add = 0;
17511 imm = -imm;
17512 }
17513
17514 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17515 {
17516 switch (size)
17517 {
17518 case 8:
17519 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17520 break;
17521 case 16:
17522 constraint (1, _("immediate must be a multiple of 2 in the"
17523 " range of +/-[0,254]"));
17524 break;
17525 case 32:
17526 constraint (1, _("immediate must be a multiple of 4 in the"
17527 " range of +/-[0,508]"));
17528 break;
17529 }
17530 }
17531
17532 if (size != elsize)
17533 {
17534 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17535 constraint (inst.operands[0].reg > 14,
17536 _("MVE vector register in the range [Q0..Q7] expected"));
17537 inst.instruction |= (load && type == NT_unsigned) << 28;
17538 inst.instruction |= (size == 16) << 19;
17539 inst.instruction |= neon_logbits (elsize) << 7;
17540 }
17541 else
17542 {
17543 if (inst.operands[1].reg == REG_PC)
17544 as_tsktsk (MVE_BAD_PC);
17545 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17546 as_tsktsk (MVE_BAD_SP);
17547 inst.instruction |= 1 << 12;
17548 inst.instruction |= neon_logbits (size) << 7;
17549 }
17550 inst.instruction |= inst.operands[1].preind << 24;
17551 inst.instruction |= add << 23;
17552 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17553 inst.instruction |= inst.operands[1].writeback << 21;
17554 inst.instruction |= inst.operands[1].reg << 16;
17555 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17556 inst.instruction &= 0xffffff80;
17557 inst.instruction |= imm >> neon_logbits (size);
17558
17559}
17560
17561static void
17562do_mve_vstr_vldr (void)
17563{
17564 unsigned size;
17565 int load = 0;
17566
17567 if (inst.cond > COND_ALWAYS)
17568 inst.pred_insn_type = INSIDE_VPT_INSN;
17569 else
17570 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17571
17572 switch (inst.instruction)
17573 {
17574 default:
17575 gas_assert (0);
17576 break;
17577 case M_MNEM_vldrb:
17578 load = 1;
17579 /* fall through. */
17580 case M_MNEM_vstrb:
17581 size = 8;
17582 break;
17583 case M_MNEM_vldrh:
17584 load = 1;
17585 /* fall through. */
17586 case M_MNEM_vstrh:
17587 size = 16;
17588 break;
17589 case M_MNEM_vldrw:
17590 load = 1;
17591 /* fall through. */
17592 case M_MNEM_vstrw:
17593 size = 32;
17594 break;
17595 case M_MNEM_vldrd:
17596 load = 1;
17597 /* fall through. */
17598 case M_MNEM_vstrd:
17599 size = 64;
17600 break;
17601 }
17602 unsigned elsize = inst.vectype.el[0].size;
17603
17604 if (inst.operands[1].isquad)
17605 {
17606 /* We are dealing with [Q, imm]{!} cases. */
17607 do_mve_vstr_vldr_QI (size, elsize, load);
17608 }
17609 else
17610 {
17611 if (inst.operands[1].immisreg == 2)
17612 {
17613 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17614 do_mve_vstr_vldr_RQ (size, elsize, load);
17615 }
17616 else if (!inst.operands[1].immisreg)
17617 {
17618 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17619 do_mve_vstr_vldr_RI (size, elsize, load);
17620 }
17621 else
17622 constraint (1, BAD_ADDR_MODE);
17623 }
17624
17625 inst.is_neon = 1;
17626}
17627
35c228db
AV
17628static void
17629do_mve_vst_vld (void)
17630{
17631 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17632 return;
17633
17634 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17635 || inst.relocs[0].exp.X_add_number != 0
17636 || inst.operands[1].immisreg != 0,
17637 BAD_ADDR_MODE);
17638 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17639 if (inst.operands[1].reg == REG_PC)
17640 as_tsktsk (MVE_BAD_PC);
17641 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17642 as_tsktsk (MVE_BAD_SP);
17643
17644
17645 /* These instructions are one of the "exceptions" mentioned in
17646 handle_pred_state. They are MVE instructions that are not VPT compatible
17647 and do not accept a VPT code, thus appending such a code is a syntax
17648 error. */
17649 if (inst.cond > COND_ALWAYS)
17650 first_error (BAD_SYNTAX);
17651 /* If we append a scalar condition code we can set this to
17652 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17653 else if (inst.cond < COND_ALWAYS)
17654 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17655 else
17656 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17657
17658 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17659 inst.instruction |= inst.operands[1].writeback << 21;
17660 inst.instruction |= inst.operands[1].reg << 16;
17661 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17662 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17663 inst.is_neon = 1;
17664}
17665
26c1e780
AV
17666static void
17667do_mve_vaddlv (void)
17668{
17669 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17670 struct neon_type_el et
17671 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17672
17673 if (et.type == NT_invtype)
17674 first_error (BAD_EL_TYPE);
17675
17676 if (inst.cond > COND_ALWAYS)
17677 inst.pred_insn_type = INSIDE_VPT_INSN;
17678 else
17679 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17680
17681 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17682
17683 inst.instruction |= (et.type == NT_unsigned) << 28;
17684 inst.instruction |= inst.operands[1].reg << 19;
17685 inst.instruction |= inst.operands[0].reg << 12;
17686 inst.instruction |= inst.operands[2].reg;
17687 inst.is_neon = 1;
17688}
17689
5287ad62 17690static void
5ee91343 17691do_neon_dyadic_if_su (void)
5287ad62 17692{
5ee91343
AV
17693 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17694 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17695 N_SUF_32 | N_KEY);
17696
935295b5
AV
17697 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17698 || inst.instruction == ((unsigned) N_MNEM_vmin))
17699 && et.type == NT_float
17700 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17701
64c350f2
AV
17702 if (!check_simd_pred_availability (et.type == NT_float,
17703 NEON_CHECK_ARCH | NEON_CHECK_CC))
037e8744
JB
17704 return;
17705
5ee91343
AV
17706 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17707}
17708
17709static void
17710do_neon_addsub_if_i (void)
17711{
17712 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17713 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
037e8744
JB
17714 return;
17715
5ee91343
AV
17716 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17717 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17718 N_EQK, N_IF_32 | N_I64 | N_KEY);
17719
17720 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17721 /* If we are parsing Q registers and the element types match MVE, which NEON
17722 also supports, then we must check whether this is an instruction that can
17723 be used by both MVE/NEON. This distinction can be made based on whether
17724 they are predicated or not. */
17725 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17726 {
64c350f2
AV
17727 if (!check_simd_pred_availability (et.type == NT_float,
17728 NEON_CHECK_ARCH | NEON_CHECK_CC))
5ee91343
AV
17729 return;
17730 }
17731 else
17732 {
17733 /* If they are either in a D register or are using an unsupported. */
17734 if (rs != NS_QQR
17735 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17736 return;
17737 }
17738
5287ad62
JB
17739 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17740 affected if we specify unsigned args. */
dcbf9037 17741 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
17742}
17743
17744/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17745 result to be:
17746 V<op> A,B (A is operand 0, B is operand 2)
17747 to mean:
17748 V<op> A,B,A
17749 not:
17750 V<op> A,B,B
17751 so handle that case specially. */
17752
17753static void
17754neon_exchange_operands (void)
17755{
5287ad62
JB
17756 if (inst.operands[1].present)
17757 {
e1fa0163
NC
17758 void *scratch = xmalloc (sizeof (inst.operands[0]));
17759
5287ad62
JB
17760 /* Swap operands[1] and operands[2]. */
17761 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17762 inst.operands[1] = inst.operands[2];
17763 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 17764 free (scratch);
5287ad62
JB
17765 }
17766 else
17767 {
17768 inst.operands[1] = inst.operands[2];
17769 inst.operands[2] = inst.operands[0];
17770 }
17771}
17772
17773static void
17774neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17775{
17776 if (inst.operands[2].isreg)
17777 {
17778 if (invert)
477330fc 17779 neon_exchange_operands ();
dcbf9037 17780 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
17781 }
17782 else
17783 {
037e8744 17784 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 17785 struct neon_type_el et = neon_check_type (2, rs,
477330fc 17786 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 17787
88714cb8 17788 NEON_ENCODE (IMMED, inst);
5287ad62
JB
17789 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17790 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17791 inst.instruction |= LOW4 (inst.operands[1].reg);
17792 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 17793 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
17794 inst.instruction |= (et.type == NT_float) << 10;
17795 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 17796
88714cb8 17797 neon_dp_fixup (&inst);
5287ad62
JB
17798 }
17799}
17800
17801static void
17802do_neon_cmp (void)
17803{
cc933301 17804 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
17805}
17806
17807static void
17808do_neon_cmp_inv (void)
17809{
cc933301 17810 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
17811}
17812
17813static void
17814do_neon_ceq (void)
17815{
17816 neon_compare (N_IF_32, N_IF_32, FALSE);
17817}
17818
17819/* For multiply instructions, we have the possibility of 16-bit or 32-bit
17820 scalars, which are encoded in 5 bits, M : Rm.
17821 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17822 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
17823 index in M.
17824
17825 Dot Product instructions are similar to multiply instructions except elsize
17826 should always be 32.
17827
17828 This function translates SCALAR, which is GAS's internal encoding of indexed
17829 scalar register, to raw encoding. There is also register and index range
17830 check based on ELSIZE. */
5287ad62
JB
17831
17832static unsigned
17833neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17834{
dcbf9037
JB
17835 unsigned regno = NEON_SCALAR_REG (scalar);
17836 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
17837
17838 switch (elsize)
17839 {
17840 case 16:
17841 if (regno > 7 || elno > 3)
477330fc 17842 goto bad_scalar;
5287ad62 17843 return regno | (elno << 3);
5f4273c7 17844
5287ad62
JB
17845 case 32:
17846 if (regno > 15 || elno > 1)
477330fc 17847 goto bad_scalar;
5287ad62
JB
17848 return regno | (elno << 4);
17849
17850 default:
17851 bad_scalar:
dcbf9037 17852 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
17853 }
17854
17855 return 0;
17856}
17857
17858/* Encode multiply / multiply-accumulate scalar instructions. */
17859
17860static void
17861neon_mul_mac (struct neon_type_el et, int ubit)
17862{
dcbf9037
JB
17863 unsigned scalar;
17864
17865 /* Give a more helpful error message if we have an invalid type. */
17866 if (et.type == NT_invtype)
17867 return;
5f4273c7 17868
dcbf9037 17869 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
17870 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17871 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17872 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17873 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17874 inst.instruction |= LOW4 (scalar);
17875 inst.instruction |= HI1 (scalar) << 5;
17876 inst.instruction |= (et.type == NT_float) << 8;
17877 inst.instruction |= neon_logbits (et.size) << 20;
17878 inst.instruction |= (ubit != 0) << 24;
17879
88714cb8 17880 neon_dp_fixup (&inst);
5287ad62
JB
17881}
17882
17883static void
17884do_neon_mac_maybe_scalar (void)
17885{
037e8744
JB
17886 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17887 return;
17888
64c350f2 17889 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
17890 return;
17891
5287ad62
JB
17892 if (inst.operands[2].isscalar)
17893 {
a8465a06 17894 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 17895 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 17896 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 17897 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 17898 NEON_ENCODE (SCALAR, inst);
037e8744 17899 neon_mul_mac (et, neon_quad (rs));
5287ad62 17900 }
a8465a06
AV
17901 else if (!inst.operands[2].isvec)
17902 {
17903 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17904
17905 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17906 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17907
17908 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17909 }
5287ad62 17910 else
428e3f1f 17911 {
a8465a06 17912 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
428e3f1f
PB
17913 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17914 affected if we specify unsigned args. */
17915 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17916 }
5287ad62
JB
17917}
17918
aab2c27d
MM
17919static void
17920do_bfloat_vfma (void)
17921{
17922 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17923 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17924 enum neon_shape rs;
17925 int t_bit = 0;
17926
17927 if (inst.instruction != B_MNEM_vfmab)
17928 {
17929 t_bit = 1;
17930 inst.instruction = B_MNEM_vfmat;
17931 }
17932
17933 if (inst.operands[2].isscalar)
17934 {
17935 rs = neon_select_shape (NS_QQS, NS_NULL);
17936 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17937
17938 inst.instruction |= (1 << 25);
17939 int index = inst.operands[2].reg & 0xf;
17940 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17941 inst.operands[2].reg >>= 4;
17942 constraint (!(inst.operands[2].reg < 8),
17943 _("indexed register must be less than 8"));
17944 neon_three_args (t_bit);
17945 inst.instruction |= ((index & 1) << 3);
17946 inst.instruction |= ((index & 2) << 4);
17947 }
17948 else
17949 {
17950 rs = neon_select_shape (NS_QQQ, NS_NULL);
17951 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17952 neon_three_args (t_bit);
17953 }
17954
17955}
17956
62f3b8c8
PB
17957static void
17958do_neon_fmac (void)
17959{
d58196e0
AV
17960 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17961 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
62f3b8c8
PB
17962 return;
17963
64c350f2 17964 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
62f3b8c8
PB
17965 return;
17966
d58196e0
AV
17967 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17968 {
17969 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17970 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17971 N_EQK);
17972
17973 if (rs == NS_QQR)
17974 {
aab2c27d 17975
d58196e0
AV
17976 if (inst.operands[2].reg == REG_SP)
17977 as_tsktsk (MVE_BAD_SP);
17978 else if (inst.operands[2].reg == REG_PC)
17979 as_tsktsk (MVE_BAD_PC);
17980
17981 inst.instruction = 0xee310e40;
17982 inst.instruction |= (et.size == 16) << 28;
17983 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17984 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17985 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17986 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17987 inst.instruction |= inst.operands[2].reg;
17988 inst.is_neon = 1;
17989 return;
17990 }
17991 }
17992 else
17993 {
17994 constraint (!inst.operands[2].isvec, BAD_FPU);
17995 }
17996
62f3b8c8
PB
17997 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17998}
17999
aab2c27d
MM
18000static void
18001do_mve_vfma (void)
18002{
18003 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
18004 inst.cond == COND_ALWAYS)
18005 {
18006 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18007 inst.instruction = N_MNEM_vfma;
18008 inst.pred_insn_type = INSIDE_VPT_INSN;
18009 inst.cond = 0xf;
18010 return do_neon_fmac();
18011 }
18012 else
18013 {
18014 do_bfloat_vfma();
18015 }
18016}
18017
5287ad62
JB
18018static void
18019do_neon_tst (void)
18020{
037e8744 18021 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
18022 struct neon_type_el et = neon_check_type (3, rs,
18023 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 18024 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18025}
18026
18027/* VMUL with 3 registers allows the P8 type. The scalar version supports the
18028 same types as the MAC equivalents. The polynomial type for this instruction
18029 is encoded the same as the integer type. */
18030
18031static void
18032do_neon_mul (void)
18033{
037e8744
JB
18034 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18035 return;
18036
64c350f2 18037 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
037e8744
JB
18038 return;
18039
5287ad62 18040 if (inst.operands[2].isscalar)
a8465a06
AV
18041 {
18042 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18043 do_neon_mac_maybe_scalar ();
18044 }
5287ad62 18045 else
a8465a06
AV
18046 {
18047 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18048 {
18049 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18050 struct neon_type_el et
18051 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18052 if (et.type == NT_float)
18053 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18054 BAD_FPU);
18055
18056 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18057 }
18058 else
18059 {
18060 constraint (!inst.operands[2].isvec, BAD_FPU);
18061 neon_dyadic_misc (NT_poly,
18062 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18063 }
18064 }
5287ad62
JB
18065}
18066
18067static void
18068do_neon_qdmulh (void)
18069{
64c350f2 18070 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18071 return;
18072
5287ad62
JB
18073 if (inst.operands[2].isscalar)
18074 {
42b16635 18075 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
037e8744 18076 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 18077 struct neon_type_el et = neon_check_type (3, rs,
477330fc 18078 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 18079 NEON_ENCODE (SCALAR, inst);
037e8744 18080 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
18081 }
18082 else
18083 {
42b16635
AV
18084 enum neon_shape rs;
18085 struct neon_type_el et;
18086 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18087 {
18088 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18089 et = neon_check_type (3, rs,
18090 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18091 }
18092 else
18093 {
18094 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18095 et = neon_check_type (3, rs,
18096 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18097 }
18098
88714cb8 18099 NEON_ENCODE (INTEGER, inst);
42b16635
AV
18100 if (rs == NS_QQR)
18101 mve_encode_qqr (et.size, 0, 0);
18102 else
18103 /* The U bit (rounding) comes from bit mask. */
18104 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
18105 }
18106}
18107
26c1e780
AV
18108static void
18109do_mve_vaddv (void)
18110{
18111 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18112 struct neon_type_el et
18113 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18114
18115 if (et.type == NT_invtype)
18116 first_error (BAD_EL_TYPE);
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 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18124
18125 mve_encode_rq (et.type == NT_unsigned, et.size);
18126}
18127
7df54120
AV
18128static void
18129do_mve_vhcadd (void)
18130{
18131 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18132 struct neon_type_el et
18133 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18134
18135 if (inst.cond > COND_ALWAYS)
18136 inst.pred_insn_type = INSIDE_VPT_INSN;
18137 else
18138 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18139
18140 unsigned rot = inst.relocs[0].exp.X_add_number;
18141 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18142
18143 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18144 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18145 "operand makes instruction UNPREDICTABLE"));
18146
18147 mve_encode_qqq (0, et.size);
18148 inst.instruction |= (rot == 270) << 12;
18149 inst.is_neon = 1;
18150}
18151
35d1cfc2
AV
18152static void
18153do_mve_vqdmull (void)
18154{
18155 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18156 struct neon_type_el et
18157 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18158
18159 if (et.size == 32
18160 && (inst.operands[0].reg == inst.operands[1].reg
18161 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18162 as_tsktsk (BAD_MVE_SRCDEST);
18163
18164 if (inst.cond > COND_ALWAYS)
18165 inst.pred_insn_type = INSIDE_VPT_INSN;
18166 else
18167 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18168
18169 if (rs == NS_QQQ)
18170 {
18171 mve_encode_qqq (et.size == 32, 64);
18172 inst.instruction |= 1;
18173 }
18174 else
18175 {
18176 mve_encode_qqr (64, et.size == 32, 0);
18177 inst.instruction |= 0x3 << 5;
18178 }
18179}
18180
c2dafc2a
AV
18181static void
18182do_mve_vadc (void)
18183{
18184 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18185 struct neon_type_el et
18186 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18187
18188 if (et.type == NT_invtype)
18189 first_error (BAD_EL_TYPE);
18190
18191 if (inst.cond > COND_ALWAYS)
18192 inst.pred_insn_type = INSIDE_VPT_INSN;
18193 else
18194 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18195
18196 mve_encode_qqq (0, 64);
18197}
18198
18199static void
18200do_mve_vbrsr (void)
18201{
18202 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18203 struct neon_type_el et
18204 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18205
18206 if (inst.cond > COND_ALWAYS)
18207 inst.pred_insn_type = INSIDE_VPT_INSN;
18208 else
18209 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18210
7df54120 18211 mve_encode_qqr (et.size, 0, 0);
c2dafc2a
AV
18212}
18213
18214static void
18215do_mve_vsbc (void)
18216{
18217 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18218
18219 if (inst.cond > COND_ALWAYS)
18220 inst.pred_insn_type = INSIDE_VPT_INSN;
18221 else
18222 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18223
18224 mve_encode_qqq (1, 64);
18225}
18226
2d78f95b
AV
18227static void
18228do_mve_vmulh (void)
18229{
18230 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18231 struct neon_type_el et
18232 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18233
18234 if (inst.cond > COND_ALWAYS)
18235 inst.pred_insn_type = INSIDE_VPT_INSN;
18236 else
18237 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18238
18239 mve_encode_qqq (et.type == NT_unsigned, et.size);
18240}
18241
42b16635
AV
18242static void
18243do_mve_vqdmlah (void)
18244{
18245 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18246 struct neon_type_el et
23d188c7 18247 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635
AV
18248
18249 if (inst.cond > COND_ALWAYS)
18250 inst.pred_insn_type = INSIDE_VPT_INSN;
18251 else
18252 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18253
18254 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18255}
8b8b22a4
AV
18256
18257static void
18258do_mve_vqdmladh (void)
18259{
18260 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18261 struct neon_type_el et
18262 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18263
18264 if (inst.cond > COND_ALWAYS)
18265 inst.pred_insn_type = INSIDE_VPT_INSN;
18266 else
18267 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18268
8b8b22a4
AV
18269 mve_encode_qqq (0, et.size);
18270}
18271
18272
886e1c73
AV
18273static void
18274do_mve_vmull (void)
18275{
18276
18277 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18278 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
fe05f369 18279 if (inst.cond == COND_ALWAYS
886e1c73
AV
18280 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18281 {
fe05f369 18282
886e1c73
AV
18283 if (rs == NS_QQQ)
18284 {
fe05f369 18285 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
886e1c73
AV
18286 goto neon_vmul;
18287 }
18288 else
18289 goto neon_vmul;
18290 }
18291
18292 constraint (rs != NS_QQQ, BAD_FPU);
18293 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18294 N_SU_32 | N_P8 | N_P16 | N_KEY);
18295
18296 /* We are dealing with MVE's vmullt. */
18297 if (et.size == 32
18298 && (inst.operands[0].reg == inst.operands[1].reg
18299 || inst.operands[0].reg == inst.operands[2].reg))
18300 as_tsktsk (BAD_MVE_SRCDEST);
18301
18302 if (inst.cond > COND_ALWAYS)
18303 inst.pred_insn_type = INSIDE_VPT_INSN;
18304 else
18305 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18306
18307 if (et.type == NT_poly)
18308 mve_encode_qqq (neon_logbits (et.size), 64);
18309 else
18310 mve_encode_qqq (et.type == NT_unsigned, et.size);
18311
18312 return;
18313
dc1e8a47 18314 neon_vmul:
886e1c73
AV
18315 inst.instruction = N_MNEM_vmul;
18316 inst.cond = 0xb;
18317 if (thumb_mode)
18318 inst.pred_insn_type = INSIDE_IT_INSN;
18319 do_neon_mul ();
18320}
18321
a302e574
AV
18322static void
18323do_mve_vabav (void)
18324{
18325 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18326
18327 if (rs == NS_NULL)
18328 return;
18329
18330 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18331 return;
18332
18333 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18334 | N_S16 | N_S32 | N_U8 | N_U16
18335 | N_U32);
18336
18337 if (inst.cond > COND_ALWAYS)
18338 inst.pred_insn_type = INSIDE_VPT_INSN;
18339 else
18340 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18341
18342 mve_encode_rqq (et.type == NT_unsigned, et.size);
18343}
18344
18345static void
18346do_mve_vmladav (void)
18347{
18348 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18349 struct neon_type_el et = neon_check_type (3, rs,
18350 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18351
18352 if (et.type == NT_unsigned
18353 && (inst.instruction == M_MNEM_vmladavx
18354 || inst.instruction == M_MNEM_vmladavax
18355 || inst.instruction == M_MNEM_vmlsdav
18356 || inst.instruction == M_MNEM_vmlsdava
18357 || inst.instruction == M_MNEM_vmlsdavx
18358 || inst.instruction == M_MNEM_vmlsdavax))
18359 first_error (BAD_SIMD_TYPE);
18360
18361 constraint (inst.operands[2].reg > 14,
18362 _("MVE vector register in the range [Q0..Q7] expected"));
18363
18364 if (inst.cond > COND_ALWAYS)
18365 inst.pred_insn_type = INSIDE_VPT_INSN;
18366 else
18367 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18368
18369 if (inst.instruction == M_MNEM_vmlsdav
18370 || inst.instruction == M_MNEM_vmlsdava
18371 || inst.instruction == M_MNEM_vmlsdavx
18372 || inst.instruction == M_MNEM_vmlsdavax)
18373 inst.instruction |= (et.size == 8) << 28;
18374 else
18375 inst.instruction |= (et.size == 8) << 8;
18376
18377 mve_encode_rqq (et.type == NT_unsigned, 64);
18378 inst.instruction |= (et.size == 32) << 16;
18379}
18380
93925576
AV
18381static void
18382do_mve_vmlaldav (void)
18383{
18384 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18385 struct neon_type_el et
18386 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18387 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18388
18389 if (et.type == NT_unsigned
18390 && (inst.instruction == M_MNEM_vmlsldav
18391 || inst.instruction == M_MNEM_vmlsldava
18392 || inst.instruction == M_MNEM_vmlsldavx
18393 || inst.instruction == M_MNEM_vmlsldavax))
18394 first_error (BAD_SIMD_TYPE);
18395
18396 if (inst.cond > COND_ALWAYS)
18397 inst.pred_insn_type = INSIDE_VPT_INSN;
18398 else
18399 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18400
18401 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18402}
18403
18404static void
18405do_mve_vrmlaldavh (void)
18406{
18407 struct neon_type_el et;
18408 if (inst.instruction == M_MNEM_vrmlsldavh
18409 || inst.instruction == M_MNEM_vrmlsldavha
18410 || inst.instruction == M_MNEM_vrmlsldavhx
18411 || inst.instruction == M_MNEM_vrmlsldavhax)
18412 {
18413 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18414 if (inst.operands[1].reg == REG_SP)
18415 as_tsktsk (MVE_BAD_SP);
18416 }
18417 else
18418 {
18419 if (inst.instruction == M_MNEM_vrmlaldavhx
18420 || inst.instruction == M_MNEM_vrmlaldavhax)
18421 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18422 else
18423 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18424 N_U32 | N_S32 | N_KEY);
18425 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18426 with vmax/min instructions, making the use of SP in assembly really
18427 nonsensical, so instead of issuing a warning like we do for other uses
18428 of SP for the odd register operand we error out. */
18429 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18430 }
18431
18432 /* Make sure we still check the second operand is an odd one and that PC is
18433 disallowed. This because we are parsing for any GPR operand, to be able
18434 to distinguish between giving a warning or an error for SP as described
18435 above. */
18436 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18437 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18438
18439 if (inst.cond > COND_ALWAYS)
18440 inst.pred_insn_type = INSIDE_VPT_INSN;
18441 else
18442 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18443
18444 mve_encode_rrqq (et.type == NT_unsigned, 0);
18445}
18446
18447
8cd78170
AV
18448static void
18449do_mve_vmaxnmv (void)
18450{
18451 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18452 struct neon_type_el et
18453 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18454
18455 if (inst.cond > COND_ALWAYS)
18456 inst.pred_insn_type = INSIDE_VPT_INSN;
18457 else
18458 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18459
18460 if (inst.operands[0].reg == REG_SP)
18461 as_tsktsk (MVE_BAD_SP);
18462 else if (inst.operands[0].reg == REG_PC)
18463 as_tsktsk (MVE_BAD_PC);
18464
18465 mve_encode_rq (et.size == 16, 64);
18466}
18467
13ccd4c0
AV
18468static void
18469do_mve_vmaxv (void)
18470{
18471 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18472 struct neon_type_el et;
18473
18474 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18475 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18476 else
18477 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18478
18479 if (inst.cond > COND_ALWAYS)
18480 inst.pred_insn_type = INSIDE_VPT_INSN;
18481 else
18482 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18483
18484 if (inst.operands[0].reg == REG_SP)
18485 as_tsktsk (MVE_BAD_SP);
18486 else if (inst.operands[0].reg == REG_PC)
18487 as_tsktsk (MVE_BAD_PC);
18488
18489 mve_encode_rq (et.type == NT_unsigned, et.size);
18490}
18491
18492
643afb90
MW
18493static void
18494do_neon_qrdmlah (void)
18495{
64c350f2 18496 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
42b16635
AV
18497 return;
18498 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
643afb90 18499 {
42b16635
AV
18500 /* Check we're on the correct architecture. */
18501 if (!mark_feature_used (&fpu_neon_ext_armv8))
18502 inst.error
18503 = _("instruction form not available on this architecture.");
18504 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18505 {
18506 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18507 record_feature_use (&fpu_neon_ext_v8_1);
18508 }
18509 if (inst.operands[2].isscalar)
18510 {
18511 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18512 struct neon_type_el et = neon_check_type (3, rs,
18513 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18514 NEON_ENCODE (SCALAR, inst);
18515 neon_mul_mac (et, neon_quad (rs));
18516 }
18517 else
18518 {
18519 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18520 struct neon_type_el et = neon_check_type (3, rs,
18521 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18522 NEON_ENCODE (INTEGER, inst);
18523 /* The U bit (rounding) comes from bit mask. */
18524 neon_three_same (neon_quad (rs), 0, et.size);
18525 }
643afb90
MW
18526 }
18527 else
18528 {
42b16635
AV
18529 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18530 struct neon_type_el et
23d188c7 18531 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
42b16635 18532
643afb90 18533 NEON_ENCODE (INTEGER, inst);
42b16635 18534 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
643afb90
MW
18535 }
18536}
18537
5287ad62
JB
18538static void
18539do_neon_fcmp_absolute (void)
18540{
037e8744 18541 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18542 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18543 N_F_16_32 | N_KEY);
5287ad62 18544 /* Size field comes from bit mask. */
cc933301 18545 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18546}
18547
18548static void
18549do_neon_fcmp_absolute_inv (void)
18550{
18551 neon_exchange_operands ();
18552 do_neon_fcmp_absolute ();
18553}
18554
18555static void
18556do_neon_step (void)
18557{
037e8744 18558 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
18559 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18560 N_F_16_32 | N_KEY);
18561 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
18562}
18563
18564static void
18565do_neon_abs_neg (void)
18566{
037e8744
JB
18567 enum neon_shape rs;
18568 struct neon_type_el et;
5f4273c7 18569
037e8744
JB
18570 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18571 return;
18572
037e8744 18573 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 18574 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 18575
64c350f2
AV
18576 if (!check_simd_pred_availability (et.type == NT_float,
18577 NEON_CHECK_ARCH | NEON_CHECK_CC))
485dee97
AV
18578 return;
18579
5287ad62
JB
18580 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18581 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18582 inst.instruction |= LOW4 (inst.operands[1].reg);
18583 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 18584 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
18585 inst.instruction |= (et.type == NT_float) << 10;
18586 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18587
88714cb8 18588 neon_dp_fixup (&inst);
5287ad62
JB
18589}
18590
18591static void
18592do_neon_sli (void)
18593{
64c350f2 18594 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18595 return;
18596
18597 enum neon_shape rs;
18598 struct neon_type_el et;
18599 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18600 {
18601 rs = neon_select_shape (NS_QQI, NS_NULL);
18602 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18603 }
18604 else
18605 {
18606 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18607 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18608 }
18609
18610
5287ad62
JB
18611 int imm = inst.operands[2].imm;
18612 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18613 _("immediate out of range for insert"));
037e8744 18614 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18615}
18616
18617static void
18618do_neon_sri (void)
18619{
64c350f2 18620 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
18621 return;
18622
18623 enum neon_shape rs;
18624 struct neon_type_el et;
18625 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18626 {
18627 rs = neon_select_shape (NS_QQI, NS_NULL);
18628 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18629 }
18630 else
18631 {
18632 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18633 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18634 }
18635
5287ad62
JB
18636 int imm = inst.operands[2].imm;
18637 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18638 _("immediate out of range for insert"));
037e8744 18639 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
18640}
18641
18642static void
18643do_neon_qshlu_imm (void)
18644{
64c350f2 18645 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
5150f0d8
AV
18646 return;
18647
18648 enum neon_shape rs;
18649 struct neon_type_el et;
18650 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18651 {
18652 rs = neon_select_shape (NS_QQI, NS_NULL);
18653 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18654 }
18655 else
18656 {
18657 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18658 et = neon_check_type (2, rs, N_EQK | N_UNS,
18659 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18660 }
18661
5287ad62
JB
18662 int imm = inst.operands[2].imm;
18663 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 18664 _("immediate out of range for shift"));
5287ad62
JB
18665 /* Only encodes the 'U present' variant of the instruction.
18666 In this case, signed types have OP (bit 8) set to 0.
18667 Unsigned types have OP set to 1. */
18668 inst.instruction |= (et.type == NT_unsigned) << 8;
18669 /* The rest of the bits are the same as other immediate shifts. */
037e8744 18670 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
18671}
18672
18673static void
18674do_neon_qmovn (void)
18675{
18676 struct neon_type_el et = neon_check_type (2, NS_DQ,
18677 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18678 /* Saturating move where operands can be signed or unsigned, and the
18679 destination has the same signedness. */
88714cb8 18680 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18681 if (et.type == NT_unsigned)
18682 inst.instruction |= 0xc0;
18683 else
18684 inst.instruction |= 0x80;
18685 neon_two_same (0, 1, et.size / 2);
18686}
18687
18688static void
18689do_neon_qmovun (void)
18690{
18691 struct neon_type_el et = neon_check_type (2, NS_DQ,
18692 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18693 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 18694 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18695 neon_two_same (0, 1, et.size / 2);
18696}
18697
18698static void
18699do_neon_rshift_sat_narrow (void)
18700{
18701 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18702 or unsigned. If operands are unsigned, results must also be unsigned. */
18703 struct neon_type_el et = neon_check_type (2, NS_DQI,
18704 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18705 int imm = inst.operands[2].imm;
18706 /* This gets the bounds check, size encoding and immediate bits calculation
18707 right. */
18708 et.size /= 2;
5f4273c7 18709
5287ad62
JB
18710 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18711 VQMOVN.I<size> <Dd>, <Qm>. */
18712 if (imm == 0)
18713 {
18714 inst.operands[2].present = 0;
18715 inst.instruction = N_MNEM_vqmovn;
18716 do_neon_qmovn ();
18717 return;
18718 }
5f4273c7 18719
5287ad62 18720 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18721 _("immediate out of range"));
5287ad62
JB
18722 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18723}
18724
18725static void
18726do_neon_rshift_sat_narrow_u (void)
18727{
18728 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18729 or unsigned. If operands are unsigned, results must also be unsigned. */
18730 struct neon_type_el et = neon_check_type (2, NS_DQI,
18731 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18732 int imm = inst.operands[2].imm;
18733 /* This gets the bounds check, size encoding and immediate bits calculation
18734 right. */
18735 et.size /= 2;
18736
18737 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18738 VQMOVUN.I<size> <Dd>, <Qm>. */
18739 if (imm == 0)
18740 {
18741 inst.operands[2].present = 0;
18742 inst.instruction = N_MNEM_vqmovun;
18743 do_neon_qmovun ();
18744 return;
18745 }
18746
18747 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18748 _("immediate out of range"));
5287ad62
JB
18749 /* FIXME: The manual is kind of unclear about what value U should have in
18750 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18751 must be 1. */
18752 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18753}
18754
18755static void
18756do_neon_movn (void)
18757{
18758 struct neon_type_el et = neon_check_type (2, NS_DQ,
18759 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 18760 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18761 neon_two_same (0, 1, et.size / 2);
18762}
18763
18764static void
18765do_neon_rshift_narrow (void)
18766{
18767 struct neon_type_el et = neon_check_type (2, NS_DQI,
18768 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18769 int imm = inst.operands[2].imm;
18770 /* This gets the bounds check, size encoding and immediate bits calculation
18771 right. */
18772 et.size /= 2;
5f4273c7 18773
5287ad62
JB
18774 /* If immediate is zero then we are a pseudo-instruction for
18775 VMOVN.I<size> <Dd>, <Qm> */
18776 if (imm == 0)
18777 {
18778 inst.operands[2].present = 0;
18779 inst.instruction = N_MNEM_vmovn;
18780 do_neon_movn ();
18781 return;
18782 }
5f4273c7 18783
5287ad62 18784 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 18785 _("immediate out of range for narrowing operation"));
5287ad62
JB
18786 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18787}
18788
18789static void
18790do_neon_shll (void)
18791{
18792 /* FIXME: Type checking when lengthening. */
18793 struct neon_type_el et = neon_check_type (2, NS_QDI,
18794 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18795 unsigned imm = inst.operands[2].imm;
18796
18797 if (imm == et.size)
18798 {
18799 /* Maximum shift variant. */
88714cb8 18800 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
18801 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18802 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18803 inst.instruction |= LOW4 (inst.operands[1].reg);
18804 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18805 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 18806
88714cb8 18807 neon_dp_fixup (&inst);
5287ad62
JB
18808 }
18809 else
18810 {
18811 /* A more-specific type check for non-max versions. */
18812 et = neon_check_type (2, NS_QDI,
477330fc 18813 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 18814 NEON_ENCODE (IMMED, inst);
5287ad62
JB
18815 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18816 }
18817}
18818
037e8744 18819/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
18820 the current instruction is. */
18821
6b9a8b67
MGD
18822#define CVT_FLAVOUR_VAR \
18823 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18824 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18825 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18826 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18827 /* Half-precision conversions. */ \
cc933301
JW
18828 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18829 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18830 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18831 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18832 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18833 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
18834 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18835 Compared with single/double precision variants, only the co-processor \
18836 field is different, so the encoding flow is reused here. */ \
18837 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18838 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18839 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18840 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
aab2c27d 18841 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
18842 /* VFP instructions. */ \
18843 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18844 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18845 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18846 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18847 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18848 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18849 /* VFP instructions with bitshift. */ \
18850 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18851 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18852 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18853 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18854 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18855 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18856 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18857 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18858
18859#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18860 neon_cvt_flavour_##C,
18861
18862/* The different types of conversions we can do. */
18863enum neon_cvt_flavour
18864{
18865 CVT_FLAVOUR_VAR
18866 neon_cvt_flavour_invalid,
18867 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18868};
18869
18870#undef CVT_VAR
18871
18872static enum neon_cvt_flavour
18873get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 18874{
6b9a8b67
MGD
18875#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18876 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18877 if (et.type != NT_invtype) \
18878 { \
18879 inst.error = NULL; \
18880 return (neon_cvt_flavour_##C); \
5287ad62 18881 }
6b9a8b67 18882
5287ad62 18883 struct neon_type_el et;
037e8744 18884 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 18885 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
18886 /* The instruction versions which take an immediate take one register
18887 argument, which is extended to the width of the full register. Thus the
18888 "source" and "destination" registers must have the same width. Hack that
18889 here by making the size equal to the key (wider, in this case) operand. */
18890 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 18891
6b9a8b67
MGD
18892 CVT_FLAVOUR_VAR;
18893
18894 return neon_cvt_flavour_invalid;
5287ad62
JB
18895#undef CVT_VAR
18896}
18897
7e8e6784
MGD
18898enum neon_cvt_mode
18899{
18900 neon_cvt_mode_a,
18901 neon_cvt_mode_n,
18902 neon_cvt_mode_p,
18903 neon_cvt_mode_m,
18904 neon_cvt_mode_z,
30bdf752
MGD
18905 neon_cvt_mode_x,
18906 neon_cvt_mode_r
7e8e6784
MGD
18907};
18908
037e8744
JB
18909/* Neon-syntax VFP conversions. */
18910
5287ad62 18911static void
6b9a8b67 18912do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 18913{
037e8744 18914 const char *opname = 0;
5f4273c7 18915
d54af2d0
RL
18916 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18917 || rs == NS_FHI || rs == NS_HFI)
5287ad62 18918 {
037e8744
JB
18919 /* Conversions with immediate bitshift. */
18920 const char *enc[] =
477330fc 18921 {
6b9a8b67
MGD
18922#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18923 CVT_FLAVOUR_VAR
18924 NULL
18925#undef CVT_VAR
477330fc 18926 };
037e8744 18927
6b9a8b67 18928 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
18929 {
18930 opname = enc[flavour];
18931 constraint (inst.operands[0].reg != inst.operands[1].reg,
18932 _("operands 0 and 1 must be the same register"));
18933 inst.operands[1] = inst.operands[2];
18934 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18935 }
5287ad62
JB
18936 }
18937 else
18938 {
037e8744
JB
18939 /* Conversions without bitshift. */
18940 const char *enc[] =
477330fc 18941 {
6b9a8b67
MGD
18942#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18943 CVT_FLAVOUR_VAR
18944 NULL
18945#undef CVT_VAR
477330fc 18946 };
037e8744 18947
6b9a8b67 18948 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 18949 opname = enc[flavour];
037e8744
JB
18950 }
18951
18952 if (opname)
18953 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
18954
18955 /* ARMv8.2 fp16 VCVT instruction. */
18956 if (flavour == neon_cvt_flavour_s32_f16
18957 || flavour == neon_cvt_flavour_u32_f16
18958 || flavour == neon_cvt_flavour_f16_u32
18959 || flavour == neon_cvt_flavour_f16_s32)
18960 do_scalar_fp16_v82_encode ();
037e8744
JB
18961}
18962
18963static void
18964do_vfp_nsyn_cvtz (void)
18965{
d54af2d0 18966 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 18967 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
18968 const char *enc[] =
18969 {
6b9a8b67
MGD
18970#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18971 CVT_FLAVOUR_VAR
18972 NULL
18973#undef CVT_VAR
037e8744
JB
18974 };
18975
6b9a8b67 18976 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
18977 do_vfp_nsyn_opcode (enc[flavour]);
18978}
f31fef98 18979
037e8744 18980static void
bacebabc 18981do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
18982 enum neon_cvt_mode mode)
18983{
18984 int sz, op;
18985 int rm;
18986
a715796b
TG
18987 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18988 D register operands. */
18989 if (flavour == neon_cvt_flavour_s32_f64
18990 || flavour == neon_cvt_flavour_u32_f64)
18991 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18992 _(BAD_FPU));
18993
9db2f6b4
RL
18994 if (flavour == neon_cvt_flavour_s32_f16
18995 || flavour == neon_cvt_flavour_u32_f16)
18996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18997 _(BAD_FP16));
18998
5ee91343 18999 set_pred_insn_type (OUTSIDE_PRED_INSN);
7e8e6784
MGD
19000
19001 switch (flavour)
19002 {
19003 case neon_cvt_flavour_s32_f64:
19004 sz = 1;
827f64ff 19005 op = 1;
7e8e6784
MGD
19006 break;
19007 case neon_cvt_flavour_s32_f32:
19008 sz = 0;
19009 op = 1;
19010 break;
9db2f6b4
RL
19011 case neon_cvt_flavour_s32_f16:
19012 sz = 0;
19013 op = 1;
19014 break;
7e8e6784
MGD
19015 case neon_cvt_flavour_u32_f64:
19016 sz = 1;
19017 op = 0;
19018 break;
19019 case neon_cvt_flavour_u32_f32:
19020 sz = 0;
19021 op = 0;
19022 break;
9db2f6b4
RL
19023 case neon_cvt_flavour_u32_f16:
19024 sz = 0;
19025 op = 0;
19026 break;
7e8e6784
MGD
19027 default:
19028 first_error (_("invalid instruction shape"));
19029 return;
19030 }
19031
19032 switch (mode)
19033 {
19034 case neon_cvt_mode_a: rm = 0; break;
19035 case neon_cvt_mode_n: rm = 1; break;
19036 case neon_cvt_mode_p: rm = 2; break;
19037 case neon_cvt_mode_m: rm = 3; break;
19038 default: first_error (_("invalid rounding mode")); return;
19039 }
19040
19041 NEON_ENCODE (FPV8, inst);
19042 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19043 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19044 inst.instruction |= sz << 8;
9db2f6b4
RL
19045
19046 /* ARMv8.2 fp16 VCVT instruction. */
19047 if (flavour == neon_cvt_flavour_s32_f16
19048 ||flavour == neon_cvt_flavour_u32_f16)
19049 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
19050 inst.instruction |= op << 7;
19051 inst.instruction |= rm << 16;
19052 inst.instruction |= 0xf0000000;
19053 inst.is_neon = TRUE;
19054}
19055
19056static void
19057do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
19058{
19059 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
19060 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19061 NS_FH, NS_HF, NS_FHI, NS_HFI,
19062 NS_NULL);
6b9a8b67 19063 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 19064
cc933301
JW
19065 if (flavour == neon_cvt_flavour_invalid)
19066 return;
19067
e3e535bc 19068 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 19069 if (mode == neon_cvt_mode_z
e3e535bc 19070 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
19071 && (flavour == neon_cvt_flavour_s16_f16
19072 || flavour == neon_cvt_flavour_u16_f16
19073 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
19074 || flavour == neon_cvt_flavour_u32_f32
19075 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 19076 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
19077 && (rs == NS_FD || rs == NS_FF))
19078 {
19079 do_vfp_nsyn_cvtz ();
19080 return;
19081 }
19082
9db2f6b4
RL
19083 /* ARMv8.2 fp16 VCVT conversions. */
19084 if (mode == neon_cvt_mode_z
19085 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19086 && (flavour == neon_cvt_flavour_s32_f16
19087 || flavour == neon_cvt_flavour_u32_f16)
19088 && (rs == NS_FH))
19089 {
19090 do_vfp_nsyn_cvtz ();
19091 do_scalar_fp16_v82_encode ();
19092 return;
19093 }
19094
225f1684
JR
19095 if ((rs == NS_FD || rs == NS_QQI) && mode == neon_cvt_mode_n
19096 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19097 {
19098 /* We are dealing with vcvt with the 'ne' condition. */
19099 inst.cond = 0x1;
19100 inst.instruction = N_MNEM_vcvt;
19101 do_neon_cvt_1 (neon_cvt_mode_z);
19102 return;
19103 }
19104
037e8744 19105 /* VFP rather than Neon conversions. */
6b9a8b67 19106 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 19107 {
7e8e6784
MGD
19108 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19109 do_vfp_nsyn_cvt (rs, flavour);
19110 else
19111 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19112
037e8744
JB
19113 return;
19114 }
19115
19116 switch (rs)
19117 {
037e8744 19118 case NS_QQI:
dd9634d9
AV
19119 if (mode == neon_cvt_mode_z
19120 && (flavour == neon_cvt_flavour_f16_s16
19121 || flavour == neon_cvt_flavour_f16_u16
19122 || flavour == neon_cvt_flavour_s16_f16
19123 || flavour == neon_cvt_flavour_u16_f16
19124 || flavour == neon_cvt_flavour_f32_u32
19125 || flavour == neon_cvt_flavour_f32_s32
19126 || flavour == neon_cvt_flavour_s32_f32
19127 || flavour == neon_cvt_flavour_u32_f32))
19128 {
64c350f2
AV
19129 if (!check_simd_pred_availability (TRUE,
19130 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19131 return;
19132 }
dd9634d9
AV
19133 /* fall through. */
19134 case NS_DDI:
037e8744 19135 {
477330fc 19136 unsigned immbits;
cc933301
JW
19137 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19138 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 19139
dd9634d9
AV
19140 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19141 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19142 return;
19143
19144 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19145 {
19146 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19147 _("immediate value out of range"));
19148 switch (flavour)
19149 {
19150 case neon_cvt_flavour_f16_s16:
19151 case neon_cvt_flavour_f16_u16:
19152 case neon_cvt_flavour_s16_f16:
19153 case neon_cvt_flavour_u16_f16:
19154 constraint (inst.operands[2].imm > 16,
19155 _("immediate value out of range"));
19156 break;
19157 case neon_cvt_flavour_f32_u32:
19158 case neon_cvt_flavour_f32_s32:
19159 case neon_cvt_flavour_s32_f32:
19160 case neon_cvt_flavour_u32_f32:
19161 constraint (inst.operands[2].imm > 32,
19162 _("immediate value out of range"));
19163 break;
19164 default:
19165 inst.error = BAD_FPU;
19166 return;
19167 }
19168 }
037e8744 19169
477330fc
RM
19170 /* Fixed-point conversion with #0 immediate is encoded as an
19171 integer conversion. */
19172 if (inst.operands[2].present && inst.operands[2].imm == 0)
19173 goto int_encode;
477330fc
RM
19174 NEON_ENCODE (IMMED, inst);
19175 if (flavour != neon_cvt_flavour_invalid)
19176 inst.instruction |= enctab[flavour];
19177 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19178 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19179 inst.instruction |= LOW4 (inst.operands[1].reg);
19180 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19181 inst.instruction |= neon_quad (rs) << 6;
19182 inst.instruction |= 1 << 21;
cc933301
JW
19183 if (flavour < neon_cvt_flavour_s16_f16)
19184 {
19185 inst.instruction |= 1 << 21;
19186 immbits = 32 - inst.operands[2].imm;
19187 inst.instruction |= immbits << 16;
19188 }
19189 else
19190 {
19191 inst.instruction |= 3 << 20;
19192 immbits = 16 - inst.operands[2].imm;
19193 inst.instruction |= immbits << 16;
19194 inst.instruction &= ~(1 << 9);
19195 }
477330fc
RM
19196
19197 neon_dp_fixup (&inst);
037e8744
JB
19198 }
19199 break;
19200
037e8744 19201 case NS_QQ:
dd9634d9
AV
19202 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19203 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19204 && (flavour == neon_cvt_flavour_s16_f16
19205 || flavour == neon_cvt_flavour_u16_f16
19206 || flavour == neon_cvt_flavour_s32_f32
19207 || flavour == neon_cvt_flavour_u32_f32))
19208 {
64c350f2
AV
19209 if (!check_simd_pred_availability (TRUE,
19210 NEON_CHECK_CC | NEON_CHECK_ARCH8))
dd9634d9
AV
19211 return;
19212 }
19213 else if (mode == neon_cvt_mode_z
19214 && (flavour == neon_cvt_flavour_f16_s16
19215 || flavour == neon_cvt_flavour_f16_u16
19216 || flavour == neon_cvt_flavour_s16_f16
19217 || flavour == neon_cvt_flavour_u16_f16
19218 || flavour == neon_cvt_flavour_f32_u32
19219 || flavour == neon_cvt_flavour_f32_s32
19220 || flavour == neon_cvt_flavour_s32_f32
19221 || flavour == neon_cvt_flavour_u32_f32))
19222 {
64c350f2
AV
19223 if (!check_simd_pred_availability (TRUE,
19224 NEON_CHECK_CC | NEON_CHECK_ARCH))
dd9634d9
AV
19225 return;
19226 }
19227 /* fall through. */
19228 case NS_DD:
7e8e6784
MGD
19229 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19230 {
7e8e6784 19231
dd9634d9 19232 NEON_ENCODE (FLOAT, inst);
64c350f2
AV
19233 if (!check_simd_pred_availability (TRUE,
19234 NEON_CHECK_CC | NEON_CHECK_ARCH8))
7e8e6784
MGD
19235 return;
19236
19237 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19238 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19239 inst.instruction |= LOW4 (inst.operands[1].reg);
19240 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19241 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19242 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19243 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 19244 inst.instruction |= mode << 8;
cc933301
JW
19245 if (flavour == neon_cvt_flavour_u16_f16
19246 || flavour == neon_cvt_flavour_s16_f16)
19247 /* Mask off the original size bits and reencode them. */
19248 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19249
7e8e6784
MGD
19250 if (thumb_mode)
19251 inst.instruction |= 0xfc000000;
19252 else
19253 inst.instruction |= 0xf0000000;
19254 }
19255 else
19256 {
037e8744 19257 int_encode:
7e8e6784 19258 {
cc933301
JW
19259 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19260 0x100, 0x180, 0x0, 0x080};
037e8744 19261
7e8e6784 19262 NEON_ENCODE (INTEGER, inst);
037e8744 19263
dd9634d9
AV
19264 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19265 {
19266 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19267 return;
19268 }
037e8744 19269
7e8e6784
MGD
19270 if (flavour != neon_cvt_flavour_invalid)
19271 inst.instruction |= enctab[flavour];
037e8744 19272
7e8e6784
MGD
19273 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19274 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19275 inst.instruction |= LOW4 (inst.operands[1].reg);
19276 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19277 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
19278 if (flavour >= neon_cvt_flavour_s16_f16
19279 && flavour <= neon_cvt_flavour_f16_u16)
19280 /* Half precision. */
19281 inst.instruction |= 1 << 18;
19282 else
19283 inst.instruction |= 2 << 18;
037e8744 19284
7e8e6784
MGD
19285 neon_dp_fixup (&inst);
19286 }
19287 }
19288 break;
037e8744 19289
8e79c3df
CM
19290 /* Half-precision conversions for Advanced SIMD -- neon. */
19291 case NS_QD:
19292 case NS_DQ:
bc52d49c
MM
19293 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19294 return;
8e79c3df
CM
19295
19296 if ((rs == NS_DQ)
19297 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19298 {
19299 as_bad (_("operand size must match register width"));
19300 break;
19301 }
19302
19303 if ((rs == NS_QD)
19304 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19305 {
19306 as_bad (_("operand size must match register width"));
19307 break;
19308 }
19309
19310 if (rs == NS_DQ)
aab2c27d
MM
19311 {
19312 if (flavour == neon_cvt_flavour_bf16_f32)
19313 {
19314 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19315 return;
19316 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19317 /* VCVT.bf16.f32. */
19318 inst.instruction = 0x11b60640;
19319 }
19320 else
19321 /* VCVT.f16.f32. */
19322 inst.instruction = 0x3b60600;
19323 }
8e79c3df 19324 else
aab2c27d 19325 /* VCVT.f32.f16. */
8e79c3df
CM
19326 inst.instruction = 0x3b60700;
19327
19328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19329 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19330 inst.instruction |= LOW4 (inst.operands[1].reg);
19331 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 19332 neon_dp_fixup (&inst);
8e79c3df
CM
19333 break;
19334
037e8744
JB
19335 default:
19336 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
19337 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19338 do_vfp_nsyn_cvt (rs, flavour);
19339 else
19340 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 19341 }
5287ad62
JB
19342}
19343
e3e535bc
NC
19344static void
19345do_neon_cvtr (void)
19346{
7e8e6784 19347 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
19348}
19349
19350static void
19351do_neon_cvt (void)
19352{
7e8e6784
MGD
19353 do_neon_cvt_1 (neon_cvt_mode_z);
19354}
19355
19356static void
19357do_neon_cvta (void)
19358{
19359 do_neon_cvt_1 (neon_cvt_mode_a);
19360}
19361
19362static void
19363do_neon_cvtn (void)
19364{
19365 do_neon_cvt_1 (neon_cvt_mode_n);
19366}
19367
19368static void
19369do_neon_cvtp (void)
19370{
19371 do_neon_cvt_1 (neon_cvt_mode_p);
19372}
19373
19374static void
19375do_neon_cvtm (void)
19376{
19377 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
19378}
19379
8e79c3df 19380static void
c70a8987 19381do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 19382{
c70a8987
MGD
19383 if (is_double)
19384 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 19385
c70a8987
MGD
19386 encode_arm_vfp_reg (inst.operands[0].reg,
19387 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19388 encode_arm_vfp_reg (inst.operands[1].reg,
19389 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19390 inst.instruction |= to ? 0x10000 : 0;
19391 inst.instruction |= t ? 0x80 : 0;
19392 inst.instruction |= is_double ? 0x100 : 0;
19393 do_vfp_cond_or_thumb ();
19394}
8e79c3df 19395
c70a8987
MGD
19396static void
19397do_neon_cvttb_1 (bfd_boolean t)
19398{
d54af2d0 19399 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
dd9634d9 19400 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
8e79c3df 19401
c70a8987
MGD
19402 if (rs == NS_NULL)
19403 return;
dd9634d9
AV
19404 else if (rs == NS_QQ || rs == NS_QQI)
19405 {
19406 int single_to_half = 0;
64c350f2 19407 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
dd9634d9
AV
19408 return;
19409
19410 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19411
19412 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19413 && (flavour == neon_cvt_flavour_u16_f16
19414 || flavour == neon_cvt_flavour_s16_f16
19415 || flavour == neon_cvt_flavour_f16_s16
19416 || flavour == neon_cvt_flavour_f16_u16
19417 || flavour == neon_cvt_flavour_u32_f32
19418 || flavour == neon_cvt_flavour_s32_f32
19419 || flavour == neon_cvt_flavour_f32_s32
19420 || flavour == neon_cvt_flavour_f32_u32))
19421 {
19422 inst.cond = 0xf;
19423 inst.instruction = N_MNEM_vcvt;
19424 set_pred_insn_type (INSIDE_VPT_INSN);
19425 do_neon_cvt_1 (neon_cvt_mode_z);
19426 return;
19427 }
19428 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19429 single_to_half = 1;
19430 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19431 {
19432 first_error (BAD_FPU);
19433 return;
19434 }
19435
19436 inst.instruction = 0xee3f0e01;
19437 inst.instruction |= single_to_half << 28;
19438 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19439 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19440 inst.instruction |= t << 12;
19441 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19442 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19443 inst.is_neon = 1;
19444 }
c70a8987
MGD
19445 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19446 {
19447 inst.error = NULL;
19448 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19449 }
19450 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19451 {
19452 inst.error = NULL;
19453 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19454 }
19455 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19456 {
a715796b
TG
19457 /* The VCVTB and VCVTT instructions with D-register operands
19458 don't work for SP only targets. */
19459 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19460 _(BAD_FPU));
19461
c70a8987
MGD
19462 inst.error = NULL;
19463 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19464 }
19465 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19466 {
a715796b
TG
19467 /* The VCVTB and VCVTT instructions with D-register operands
19468 don't work for SP only targets. */
19469 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19470 _(BAD_FPU));
19471
c70a8987
MGD
19472 inst.error = NULL;
19473 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19474 }
aab2c27d
MM
19475 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19476 {
19477 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19478 inst.error = NULL;
19479 inst.instruction |= (1 << 8);
19480 inst.instruction &= ~(1 << 9);
19481 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19482 }
c70a8987
MGD
19483 else
19484 return;
19485}
19486
19487static void
19488do_neon_cvtb (void)
19489{
19490 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
19491}
19492
19493
19494static void
19495do_neon_cvtt (void)
19496{
c70a8987 19497 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
19498}
19499
5287ad62
JB
19500static void
19501neon_move_immediate (void)
19502{
037e8744
JB
19503 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19504 struct neon_type_el et = neon_check_type (2, rs,
19505 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 19506 unsigned immlo, immhi = 0, immbits;
c96612cc 19507 int op, cmode, float_p;
5287ad62 19508
037e8744 19509 constraint (et.type == NT_invtype,
477330fc 19510 _("operand size must be specified for immediate VMOV"));
037e8744 19511
5287ad62
JB
19512 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19513 op = (inst.instruction & (1 << 5)) != 0;
19514
19515 immlo = inst.operands[1].imm;
19516 if (inst.operands[1].regisimm)
19517 immhi = inst.operands[1].reg;
19518
19519 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 19520 _("immediate has bits set outside the operand size"));
5287ad62 19521
c96612cc
JB
19522 float_p = inst.operands[1].immisfloat;
19523
19524 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 19525 et.size, et.type)) == FAIL)
5287ad62
JB
19526 {
19527 /* Invert relevant bits only. */
19528 neon_invert_size (&immlo, &immhi, et.size);
19529 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
19530 with one or the other; those cases are caught by
19531 neon_cmode_for_move_imm. */
5287ad62 19532 op = !op;
c96612cc
JB
19533 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19534 &op, et.size, et.type)) == FAIL)
477330fc
RM
19535 {
19536 first_error (_("immediate out of range"));
19537 return;
19538 }
5287ad62
JB
19539 }
19540
19541 inst.instruction &= ~(1 << 5);
19542 inst.instruction |= op << 5;
19543
19544 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19545 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 19546 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19547 inst.instruction |= cmode << 8;
19548
19549 neon_write_immbits (immbits);
19550}
19551
19552static void
19553do_neon_mvn (void)
19554{
64c350f2 19555 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
19556 return;
19557
5287ad62
JB
19558 if (inst.operands[1].isreg)
19559 {
1a186d29
AV
19560 enum neon_shape rs;
19561 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19562 rs = neon_select_shape (NS_QQ, NS_NULL);
19563 else
19564 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 19565
250dd99f
AM
19566 if (rs == NS_NULL)
19567 return;
19568
88714cb8 19569 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19570 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19571 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19572 inst.instruction |= LOW4 (inst.operands[1].reg);
19573 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 19574 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19575 }
19576 else
19577 {
88714cb8 19578 NEON_ENCODE (IMMED, inst);
5287ad62
JB
19579 neon_move_immediate ();
19580 }
19581
88714cb8 19582 neon_dp_fixup (&inst);
1a186d29
AV
19583
19584 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19585 {
19586 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
1a186d29 19587 }
5287ad62
JB
19588}
19589
19590/* Encode instructions of form:
19591
19592 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 19593 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
19594
19595static void
19596neon_mixed_length (struct neon_type_el et, unsigned size)
19597{
19598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19600 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19601 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19602 inst.instruction |= LOW4 (inst.operands[2].reg);
19603 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19604 inst.instruction |= (et.type == NT_unsigned) << 24;
19605 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 19606
88714cb8 19607 neon_dp_fixup (&inst);
5287ad62
JB
19608}
19609
19610static void
19611do_neon_dyadic_long (void)
19612{
66d1f7cc 19613 enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL);
5ee91343
AV
19614 if (rs == NS_QDD)
19615 {
19616 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19617 return;
19618
19619 NEON_ENCODE (INTEGER, inst);
19620 /* FIXME: Type checking for lengthening op. */
19621 struct neon_type_el et = neon_check_type (3, NS_QDD,
19622 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19623 neon_mixed_length (et, et.size);
19624 }
19625 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19626 && (inst.cond == 0xf || inst.cond == 0x10))
19627 {
19628 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19629 in an IT block with le/lt conditions. */
19630
19631 if (inst.cond == 0xf)
19632 inst.cond = 0xb;
19633 else if (inst.cond == 0x10)
19634 inst.cond = 0xd;
19635
19636 inst.pred_insn_type = INSIDE_IT_INSN;
19637
19638 if (inst.instruction == N_MNEM_vaddl)
19639 {
19640 inst.instruction = N_MNEM_vadd;
19641 do_neon_addsub_if_i ();
19642 }
19643 else if (inst.instruction == N_MNEM_vsubl)
19644 {
19645 inst.instruction = N_MNEM_vsub;
19646 do_neon_addsub_if_i ();
19647 }
19648 else if (inst.instruction == N_MNEM_vabdl)
19649 {
19650 inst.instruction = N_MNEM_vabd;
19651 do_neon_dyadic_if_su ();
19652 }
19653 }
19654 else
19655 first_error (BAD_FPU);
5287ad62
JB
19656}
19657
19658static void
19659do_neon_abal (void)
19660{
19661 struct neon_type_el et = neon_check_type (3, NS_QDD,
19662 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19663 neon_mixed_length (et, et.size);
19664}
19665
19666static void
19667neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19668{
19669 if (inst.operands[2].isscalar)
19670 {
dcbf9037 19671 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 19672 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 19673 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19674 neon_mul_mac (et, et.type == NT_unsigned);
19675 }
19676 else
19677 {
19678 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19679 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 19680 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
19681 neon_mixed_length (et, et.size);
19682 }
19683}
19684
19685static void
19686do_neon_mac_maybe_scalar_long (void)
19687{
19688 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19689}
19690
dec41383
JW
19691/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19692 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19693
19694static unsigned
19695neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19696{
19697 unsigned regno = NEON_SCALAR_REG (scalar);
19698 unsigned elno = NEON_SCALAR_INDEX (scalar);
19699
19700 if (quad_p)
19701 {
19702 if (regno > 7 || elno > 3)
19703 goto bad_scalar;
19704
19705 return ((regno & 0x7)
19706 | ((elno & 0x1) << 3)
19707 | (((elno >> 1) & 0x1) << 5));
19708 }
19709 else
19710 {
19711 if (regno > 15 || elno > 1)
19712 goto bad_scalar;
19713
19714 return (((regno & 0x1) << 5)
19715 | ((regno >> 1) & 0x7)
19716 | ((elno & 0x1) << 3));
19717 }
19718
dc1e8a47 19719 bad_scalar:
dec41383
JW
19720 first_error (_("scalar out of range for multiply instruction"));
19721 return 0;
19722}
19723
19724static void
19725do_neon_fmac_maybe_scalar_long (int subtype)
19726{
19727 enum neon_shape rs;
19728 int high8;
19729 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19730 field (bits[21:20]) has different meaning. For scalar index variant, it's
19731 used to differentiate add and subtract, otherwise it's with fixed value
19732 0x2. */
19733 int size = -1;
19734
dec41383
JW
19735 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19736 be a scalar index register. */
19737 if (inst.operands[2].isscalar)
19738 {
19739 high8 = 0xfe000000;
19740 if (subtype)
19741 size = 16;
19742 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19743 }
19744 else
19745 {
19746 high8 = 0xfc000000;
19747 size = 32;
19748 if (subtype)
19749 inst.instruction |= (0x1 << 23);
19750 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19751 }
19752
aab2c27d
MM
19753
19754 if (inst.cond != COND_ALWAYS)
19755 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19756 "behaviour is UNPREDICTABLE"));
19757
19758 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19759 _(BAD_FP16));
19760
19761 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19762 _(BAD_FPU));
dec41383
JW
19763
19764 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19765 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19766 so we simply pass -1 as size. */
19767 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19768 neon_three_same (quad_p, 0, size);
19769
19770 /* Undo neon_dp_fixup. Redo the high eight bits. */
19771 inst.instruction &= 0x00ffffff;
19772 inst.instruction |= high8;
19773
dec41383
JW
19774 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19775 whether the instruction is in Q form and whether Vm is a scalar indexed
19776 operand. */
19777 if (inst.operands[2].isscalar)
19778 {
19779 unsigned rm
19780 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19781 inst.instruction &= 0xffffffd0;
19782 inst.instruction |= rm;
19783
19784 if (!quad_p)
19785 {
19786 /* Redo Rn as well. */
19787 inst.instruction &= 0xfff0ff7f;
19788 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19789 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19790 }
19791 }
19792 else if (!quad_p)
19793 {
19794 /* Redo Rn and Rm. */
19795 inst.instruction &= 0xfff0ff50;
19796 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19797 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19798 inst.instruction |= HI4 (inst.operands[2].reg);
19799 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19800 }
19801}
19802
19803static void
19804do_neon_vfmal (void)
19805{
19806 return do_neon_fmac_maybe_scalar_long (0);
19807}
19808
19809static void
19810do_neon_vfmsl (void)
19811{
19812 return do_neon_fmac_maybe_scalar_long (1);
19813}
19814
5287ad62
JB
19815static void
19816do_neon_dyadic_wide (void)
19817{
19818 struct neon_type_el et = neon_check_type (3, NS_QQD,
19819 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19820 neon_mixed_length (et, et.size);
19821}
19822
19823static void
19824do_neon_dyadic_narrow (void)
19825{
19826 struct neon_type_el et = neon_check_type (3, NS_QDD,
19827 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
19828 /* Operand sign is unimportant, and the U bit is part of the opcode,
19829 so force the operand type to integer. */
19830 et.type = NT_integer;
5287ad62
JB
19831 neon_mixed_length (et, et.size / 2);
19832}
19833
19834static void
19835do_neon_mul_sat_scalar_long (void)
19836{
19837 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19838}
19839
19840static void
19841do_neon_vmull (void)
19842{
19843 if (inst.operands[2].isscalar)
19844 do_neon_mac_maybe_scalar_long ();
19845 else
19846 {
19847 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 19848 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 19849
5287ad62 19850 if (et.type == NT_poly)
477330fc 19851 NEON_ENCODE (POLY, inst);
5287ad62 19852 else
477330fc 19853 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
19854
19855 /* For polynomial encoding the U bit must be zero, and the size must
19856 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19857 obviously, as 0b10). */
19858 if (et.size == 64)
19859 {
19860 /* Check we're on the correct architecture. */
19861 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19862 inst.error =
19863 _("Instruction form not available on this architecture.");
19864
19865 et.size = 32;
19866 }
19867
5287ad62
JB
19868 neon_mixed_length (et, et.size);
19869 }
19870}
19871
19872static void
19873do_neon_ext (void)
19874{
037e8744 19875 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
19876 struct neon_type_el et = neon_check_type (3, rs,
19877 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19878 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
19879
19880 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19881 _("shift out of range"));
5287ad62
JB
19882 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19883 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19884 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19885 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19886 inst.instruction |= LOW4 (inst.operands[2].reg);
19887 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 19888 inst.instruction |= neon_quad (rs) << 6;
5287ad62 19889 inst.instruction |= imm << 8;
5f4273c7 19890
88714cb8 19891 neon_dp_fixup (&inst);
5287ad62
JB
19892}
19893
19894static void
19895do_neon_rev (void)
19896{
64c350f2 19897 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
19898 return;
19899
19900 enum neon_shape rs;
19901 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19902 rs = neon_select_shape (NS_QQ, NS_NULL);
19903 else
19904 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19905
5287ad62
JB
19906 struct neon_type_el et = neon_check_type (2, rs,
19907 N_EQK, N_8 | N_16 | N_32 | N_KEY);
4401c241 19908
5287ad62
JB
19909 unsigned op = (inst.instruction >> 7) & 3;
19910 /* N (width of reversed regions) is encoded as part of the bitmask. We
19911 extract it here to check the elements to be reversed are smaller.
19912 Otherwise we'd get a reserved instruction. */
19913 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
4401c241
AV
19914
19915 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19916 && inst.operands[0].reg == inst.operands[1].reg)
19917 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19918 " operands makes instruction UNPREDICTABLE"));
19919
9c2799c2 19920 gas_assert (elsize != 0);
5287ad62 19921 constraint (et.size >= elsize,
477330fc 19922 _("elements must be smaller than reversal region"));
037e8744 19923 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
19924}
19925
19926static void
19927do_neon_dup (void)
19928{
19929 if (inst.operands[1].isscalar)
19930 {
b409bdb6
AV
19931 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19932 BAD_FPU);
037e8744 19933 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 19934 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19935 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 19936 unsigned sizebits = et.size >> 3;
dcbf9037 19937 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 19938 int logsize = neon_logbits (et.size);
dcbf9037 19939 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
19940
19941 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 19942 return;
037e8744 19943
88714cb8 19944 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
19945 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19946 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19947 inst.instruction |= LOW4 (dm);
19948 inst.instruction |= HI1 (dm) << 5;
037e8744 19949 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
19950 inst.instruction |= x << 17;
19951 inst.instruction |= sizebits << 16;
5f4273c7 19952
88714cb8 19953 neon_dp_fixup (&inst);
5287ad62
JB
19954 }
19955 else
19956 {
037e8744
JB
19957 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19958 struct neon_type_el et = neon_check_type (2, rs,
477330fc 19959 N_8 | N_16 | N_32 | N_KEY, N_EQK);
b409bdb6
AV
19960 if (rs == NS_QR)
19961 {
64c350f2 19962 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
b409bdb6
AV
19963 return;
19964 }
19965 else
19966 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19967 BAD_FPU);
19968
19969 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19970 {
19971 if (inst.operands[1].reg == REG_SP)
19972 as_tsktsk (MVE_BAD_SP);
19973 else if (inst.operands[1].reg == REG_PC)
19974 as_tsktsk (MVE_BAD_PC);
19975 }
19976
5287ad62 19977 /* Duplicate ARM register to lanes of vector. */
88714cb8 19978 NEON_ENCODE (ARMREG, inst);
5287ad62 19979 switch (et.size)
477330fc
RM
19980 {
19981 case 8: inst.instruction |= 0x400000; break;
19982 case 16: inst.instruction |= 0x000020; break;
19983 case 32: inst.instruction |= 0x000000; break;
19984 default: break;
19985 }
5287ad62
JB
19986 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19987 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19988 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 19989 inst.instruction |= neon_quad (rs) << 21;
5287ad62 19990 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 19991 variants, except for the condition field. */
037e8744 19992 do_vfp_cond_or_thumb ();
5287ad62
JB
19993 }
19994}
19995
57785aa2
AV
19996static void
19997do_mve_mov (int toQ)
19998{
19999 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20000 return;
20001 if (inst.cond > COND_ALWAYS)
20002 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
20003
20004 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
20005 if (toQ)
20006 {
20007 Q0 = 0;
20008 Q1 = 1;
20009 Rt = 2;
20010 Rt2 = 3;
20011 }
20012
20013 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
20014 _("Index one must be [2,3] and index two must be two less than"
20015 " index one."));
20016 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
20017 _("General purpose registers may not be the same"));
20018 constraint (inst.operands[Rt].reg == REG_SP
20019 || inst.operands[Rt2].reg == REG_SP,
20020 BAD_SP);
20021 constraint (inst.operands[Rt].reg == REG_PC
20022 || inst.operands[Rt2].reg == REG_PC,
20023 BAD_PC);
20024
20025 inst.instruction = 0xec000f00;
20026 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20027 inst.instruction |= !!toQ << 20;
20028 inst.instruction |= inst.operands[Rt2].reg << 16;
20029 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20030 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20031 inst.instruction |= inst.operands[Rt].reg;
20032}
20033
20034static void
20035do_mve_movn (void)
20036{
20037 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20038 return;
20039
20040 if (inst.cond > COND_ALWAYS)
20041 inst.pred_insn_type = INSIDE_VPT_INSN;
20042 else
20043 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20044
20045 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20046 | N_KEY);
20047
20048 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20049 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20050 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20051 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20052 inst.instruction |= LOW4 (inst.operands[1].reg);
20053 inst.is_neon = 1;
20054
20055}
20056
5287ad62
JB
20057/* VMOV has particularly many variations. It can be one of:
20058 0. VMOV<c><q> <Qd>, <Qm>
20059 1. VMOV<c><q> <Dd>, <Dm>
20060 (Register operations, which are VORR with Rm = Rn.)
20061 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20062 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20063 (Immediate loads.)
20064 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20065 (ARM register to scalar.)
20066 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20067 (Two ARM registers to vector.)
20068 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20069 (Scalar to ARM register.)
20070 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20071 (Vector to two ARM registers.)
037e8744
JB
20072 8. VMOV.F32 <Sd>, <Sm>
20073 9. VMOV.F64 <Dd>, <Dm>
20074 (VFP register moves.)
20075 10. VMOV.F32 <Sd>, #imm
20076 11. VMOV.F64 <Dd>, #imm
20077 (VFP float immediate load.)
20078 12. VMOV <Rd>, <Sm>
20079 (VFP single to ARM reg.)
20080 13. VMOV <Sd>, <Rm>
20081 (ARM reg to VFP single.)
20082 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20083 (Two ARM regs to two VFP singles.)
20084 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20085 (Two VFP singles to two ARM regs.)
57785aa2
AV
20086 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20087 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20088 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20089 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
5f4273c7 20090
037e8744
JB
20091 These cases can be disambiguated using neon_select_shape, except cases 1/9
20092 and 3/11 which depend on the operand type too.
5f4273c7 20093
5287ad62 20094 All the encoded bits are hardcoded by this function.
5f4273c7 20095
b7fc2769
JB
20096 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20097 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 20098
5287ad62 20099 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 20100 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
20101
20102static void
20103do_neon_mov (void)
20104{
57785aa2
AV
20105 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20106 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20107 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20108 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20109 NS_NULL);
037e8744
JB
20110 struct neon_type_el et;
20111 const char *ldconst = 0;
5287ad62 20112
037e8744 20113 switch (rs)
5287ad62 20114 {
037e8744
JB
20115 case NS_DD: /* case 1/9. */
20116 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20117 /* It is not an error here if no type is given. */
20118 inst.error = NULL;
1c1e0fe5
SP
20119
20120 /* In MVE we interpret the following instructions as same, so ignoring
20121 the following type (float) and size (64) checks.
20122 a: VMOV<c><q> <Dd>, <Dm>
20123 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20124 if ((et.type == NT_float && et.size == 64)
20125 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
477330fc
RM
20126 {
20127 do_vfp_nsyn_opcode ("fcpyd");
20128 break;
20129 }
037e8744 20130 /* fall through. */
5287ad62 20131
037e8744
JB
20132 case NS_QQ: /* case 0/1. */
20133 {
64c350f2
AV
20134 if (!check_simd_pred_availability (FALSE,
20135 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc
RM
20136 return;
20137 /* The architecture manual I have doesn't explicitly state which
20138 value the U bit should have for register->register moves, but
20139 the equivalent VORR instruction has U = 0, so do that. */
20140 inst.instruction = 0x0200110;
20141 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20142 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20143 inst.instruction |= LOW4 (inst.operands[1].reg);
20144 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20145 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20146 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20147 inst.instruction |= neon_quad (rs) << 6;
20148
20149 neon_dp_fixup (&inst);
037e8744
JB
20150 }
20151 break;
5f4273c7 20152
037e8744
JB
20153 case NS_DI: /* case 3/11. */
20154 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20155 inst.error = NULL;
20156 if (et.type == NT_float && et.size == 64)
477330fc
RM
20157 {
20158 /* case 11 (fconstd). */
20159 ldconst = "fconstd";
20160 goto encode_fconstd;
20161 }
037e8744
JB
20162 /* fall through. */
20163
20164 case NS_QI: /* case 2/3. */
64c350f2
AV
20165 if (!check_simd_pred_availability (FALSE,
20166 NEON_CHECK_CC | NEON_CHECK_ARCH))
477330fc 20167 return;
037e8744
JB
20168 inst.instruction = 0x0800010;
20169 neon_move_immediate ();
88714cb8 20170 neon_dp_fixup (&inst);
5287ad62 20171 break;
5f4273c7 20172
037e8744
JB
20173 case NS_SR: /* case 4. */
20174 {
477330fc
RM
20175 unsigned bcdebits = 0;
20176 int logsize;
20177 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20178 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 20179
05ac0ffb
JB
20180 /* .<size> is optional here, defaulting to .32. */
20181 if (inst.vectype.elems == 0
20182 && inst.operands[0].vectype.type == NT_invtype
20183 && inst.operands[1].vectype.type == NT_invtype)
20184 {
20185 inst.vectype.el[0].type = NT_untyped;
20186 inst.vectype.el[0].size = 32;
20187 inst.vectype.elems = 1;
20188 }
20189
477330fc
RM
20190 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20191 logsize = neon_logbits (et.size);
20192
57785aa2
AV
20193 if (et.size != 32)
20194 {
20195 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20196 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20197 return;
20198 }
20199 else
20200 {
20201 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20202 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20203 _(BAD_FPU));
20204 }
20205
20206 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20207 {
20208 if (inst.operands[1].reg == REG_SP)
20209 as_tsktsk (MVE_BAD_SP);
20210 else if (inst.operands[1].reg == REG_PC)
20211 as_tsktsk (MVE_BAD_PC);
20212 }
20213 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20214
477330fc 20215 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2
AV
20216 constraint (x >= size / et.size, _("scalar index out of range"));
20217
477330fc
RM
20218
20219 switch (et.size)
20220 {
20221 case 8: bcdebits = 0x8; break;
20222 case 16: bcdebits = 0x1; break;
20223 case 32: bcdebits = 0x0; break;
20224 default: ;
20225 }
20226
57785aa2 20227 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20228
20229 inst.instruction = 0xe000b10;
20230 do_vfp_cond_or_thumb ();
20231 inst.instruction |= LOW4 (dn) << 16;
20232 inst.instruction |= HI1 (dn) << 7;
20233 inst.instruction |= inst.operands[1].reg << 12;
20234 inst.instruction |= (bcdebits & 3) << 5;
57785aa2
AV
20235 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20236 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20237 }
20238 break;
5f4273c7 20239
037e8744 20240 case NS_DRR: /* case 5 (fmdrr). */
57785aa2
AV
20241 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20242 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20243 _(BAD_FPU));
b7fc2769 20244
037e8744
JB
20245 inst.instruction = 0xc400b10;
20246 do_vfp_cond_or_thumb ();
20247 inst.instruction |= LOW4 (inst.operands[0].reg);
20248 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20249 inst.instruction |= inst.operands[1].reg << 12;
20250 inst.instruction |= inst.operands[2].reg << 16;
20251 break;
5f4273c7 20252
037e8744
JB
20253 case NS_RS: /* case 6. */
20254 {
477330fc
RM
20255 unsigned logsize;
20256 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20257 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20258 unsigned abcdebits = 0;
037e8744 20259
05ac0ffb
JB
20260 /* .<dt> is optional here, defaulting to .32. */
20261 if (inst.vectype.elems == 0
20262 && inst.operands[0].vectype.type == NT_invtype
20263 && inst.operands[1].vectype.type == NT_invtype)
20264 {
20265 inst.vectype.el[0].type = NT_untyped;
20266 inst.vectype.el[0].size = 32;
20267 inst.vectype.elems = 1;
20268 }
20269
91d6fa6a
NC
20270 et = neon_check_type (2, NS_NULL,
20271 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
20272 logsize = neon_logbits (et.size);
20273
57785aa2
AV
20274 if (et.size != 32)
20275 {
20276 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20277 && vfp_or_neon_is_neon (NEON_CHECK_CC
20278 | NEON_CHECK_ARCH) == FAIL)
20279 return;
20280 }
20281 else
20282 {
20283 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20284 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20285 _(BAD_FPU));
20286 }
20287
20288 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20289 {
20290 if (inst.operands[0].reg == REG_SP)
20291 as_tsktsk (MVE_BAD_SP);
20292 else if (inst.operands[0].reg == REG_PC)
20293 as_tsktsk (MVE_BAD_PC);
20294 }
20295
20296 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20297
477330fc 20298 constraint (et.type == NT_invtype, _("bad type for scalar"));
57785aa2 20299 constraint (x >= size / et.size, _("scalar index out of range"));
477330fc
RM
20300
20301 switch (et.size)
20302 {
20303 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20304 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20305 case 32: abcdebits = 0x00; break;
20306 default: ;
20307 }
20308
57785aa2 20309 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
477330fc
RM
20310 inst.instruction = 0xe100b10;
20311 do_vfp_cond_or_thumb ();
20312 inst.instruction |= LOW4 (dn) << 16;
20313 inst.instruction |= HI1 (dn) << 7;
20314 inst.instruction |= inst.operands[0].reg << 12;
20315 inst.instruction |= (abcdebits & 3) << 5;
20316 inst.instruction |= (abcdebits >> 2) << 21;
57785aa2 20317 inst.instruction |= (x >> (3-logsize)) << 16;
037e8744
JB
20318 }
20319 break;
5f4273c7 20320
037e8744 20321 case NS_RRD: /* case 7 (fmrrd). */
57785aa2
AV
20322 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20323 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
477330fc 20324 _(BAD_FPU));
037e8744
JB
20325
20326 inst.instruction = 0xc500b10;
20327 do_vfp_cond_or_thumb ();
20328 inst.instruction |= inst.operands[0].reg << 12;
20329 inst.instruction |= inst.operands[1].reg << 16;
20330 inst.instruction |= LOW4 (inst.operands[2].reg);
20331 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20332 break;
5f4273c7 20333
037e8744
JB
20334 case NS_FF: /* case 8 (fcpys). */
20335 do_vfp_nsyn_opcode ("fcpys");
20336 break;
5f4273c7 20337
9db2f6b4 20338 case NS_HI:
037e8744
JB
20339 case NS_FI: /* case 10 (fconsts). */
20340 ldconst = "fconsts";
4ef4710f 20341 encode_fconstd:
58ed5c38
TC
20342 if (!inst.operands[1].immisfloat)
20343 {
4ef4710f 20344 unsigned new_imm;
58ed5c38 20345 /* Immediate has to fit in 8 bits so float is enough. */
4ef4710f
NC
20346 float imm = (float) inst.operands[1].imm;
20347 memcpy (&new_imm, &imm, sizeof (float));
20348 /* But the assembly may have been written to provide an integer
20349 bit pattern that equates to a float, so check that the
20350 conversion has worked. */
20351 if (is_quarter_float (new_imm))
20352 {
20353 if (is_quarter_float (inst.operands[1].imm))
20354 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20355
20356 inst.operands[1].imm = new_imm;
20357 inst.operands[1].immisfloat = 1;
20358 }
58ed5c38
TC
20359 }
20360
037e8744 20361 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
20362 {
20363 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20364 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
20365
20366 /* ARMv8.2 fp16 vmov.f16 instruction. */
20367 if (rs == NS_HI)
20368 do_scalar_fp16_v82_encode ();
477330fc 20369 }
5287ad62 20370 else
477330fc 20371 first_error (_("immediate out of range"));
037e8744 20372 break;
5f4273c7 20373
9db2f6b4 20374 case NS_RH:
037e8744
JB
20375 case NS_RF: /* case 12 (fmrs). */
20376 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
20377 /* ARMv8.2 fp16 vmov.f16 instruction. */
20378 if (rs == NS_RH)
20379 do_scalar_fp16_v82_encode ();
037e8744 20380 break;
5f4273c7 20381
9db2f6b4 20382 case NS_HR:
037e8744
JB
20383 case NS_FR: /* case 13 (fmsr). */
20384 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
20385 /* ARMv8.2 fp16 vmov.f16 instruction. */
20386 if (rs == NS_HR)
20387 do_scalar_fp16_v82_encode ();
037e8744 20388 break;
5f4273c7 20389
57785aa2
AV
20390 case NS_RRSS:
20391 do_mve_mov (0);
20392 break;
20393 case NS_SSRR:
20394 do_mve_mov (1);
20395 break;
20396
037e8744
JB
20397 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20398 (one of which is a list), but we have parsed four. Do some fiddling to
20399 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20400 expect. */
20401 case NS_RRFF: /* case 14 (fmrrs). */
57785aa2
AV
20402 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20403 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20404 _(BAD_FPU));
037e8744 20405 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 20406 _("VFP registers must be adjacent"));
037e8744
JB
20407 inst.operands[2].imm = 2;
20408 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20409 do_vfp_nsyn_opcode ("fmrrs");
20410 break;
5f4273c7 20411
037e8744 20412 case NS_FFRR: /* case 15 (fmsrr). */
57785aa2
AV
20413 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20414 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20415 _(BAD_FPU));
037e8744 20416 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 20417 _("VFP registers must be adjacent"));
037e8744
JB
20418 inst.operands[1] = inst.operands[2];
20419 inst.operands[2] = inst.operands[3];
20420 inst.operands[0].imm = 2;
20421 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20422 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 20423 break;
5f4273c7 20424
4c261dff
NC
20425 case NS_NULL:
20426 /* neon_select_shape has determined that the instruction
20427 shape is wrong and has already set the error message. */
20428 break;
20429
5287ad62
JB
20430 default:
20431 abort ();
20432 }
20433}
20434
57785aa2
AV
20435static void
20436do_mve_movl (void)
20437{
20438 if (!(inst.operands[0].present && inst.operands[0].isquad
20439 && inst.operands[1].present && inst.operands[1].isquad
20440 && !inst.operands[2].present))
20441 {
20442 inst.instruction = 0;
20443 inst.cond = 0xb;
20444 if (thumb_mode)
20445 set_pred_insn_type (INSIDE_IT_INSN);
20446 do_neon_mov ();
20447 return;
20448 }
20449
20450 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20451 return;
20452
20453 if (inst.cond != COND_ALWAYS)
20454 inst.pred_insn_type = INSIDE_VPT_INSN;
20455
20456 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20457 | N_S16 | N_U16 | N_KEY);
20458
20459 inst.instruction |= (et.type == NT_unsigned) << 28;
20460 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20461 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20462 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20463 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20464 inst.instruction |= LOW4 (inst.operands[1].reg);
20465 inst.is_neon = 1;
20466}
20467
5287ad62
JB
20468static void
20469do_neon_rshift_round_imm (void)
20470{
64c350f2 20471 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
4401c241
AV
20472 return;
20473
20474 enum neon_shape rs;
20475 struct neon_type_el et;
20476
20477 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20478 {
20479 rs = neon_select_shape (NS_QQI, NS_NULL);
20480 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20481 }
20482 else
20483 {
20484 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20485 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20486 }
5287ad62
JB
20487 int imm = inst.operands[2].imm;
20488
20489 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20490 if (imm == 0)
20491 {
20492 inst.operands[2].present = 0;
20493 do_neon_mov ();
20494 return;
20495 }
20496
20497 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 20498 _("immediate out of range for shift"));
037e8744 20499 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 20500 et.size - imm);
5287ad62
JB
20501}
20502
9db2f6b4
RL
20503static void
20504do_neon_movhf (void)
20505{
20506 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20507 constraint (rs != NS_HH, _("invalid suffix"));
20508
7bdf778b
ASDV
20509 if (inst.cond != COND_ALWAYS)
20510 {
20511 if (thumb_mode)
20512 {
20513 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20514 " the behaviour is UNPREDICTABLE"));
20515 }
20516 else
20517 {
20518 inst.error = BAD_COND;
20519 return;
20520 }
20521 }
20522
9db2f6b4
RL
20523 do_vfp_sp_monadic ();
20524
20525 inst.is_neon = 1;
20526 inst.instruction |= 0xf0000000;
20527}
20528
5287ad62
JB
20529static void
20530do_neon_movl (void)
20531{
20532 struct neon_type_el et = neon_check_type (2, NS_QD,
20533 N_EQK | N_DBL, N_SU_32 | N_KEY);
20534 unsigned sizebits = et.size >> 3;
20535 inst.instruction |= sizebits << 19;
20536 neon_two_same (0, et.type == NT_unsigned, -1);
20537}
20538
20539static void
20540do_neon_trn (void)
20541{
037e8744 20542 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20543 struct neon_type_el et = neon_check_type (2, rs,
20544 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 20545 NEON_ENCODE (INTEGER, inst);
037e8744 20546 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20547}
20548
20549static void
20550do_neon_zip_uzp (void)
20551{
037e8744 20552 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20553 struct neon_type_el et = neon_check_type (2, rs,
20554 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20555 if (rs == NS_DD && et.size == 32)
20556 {
20557 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20558 inst.instruction = N_MNEM_vtrn;
20559 do_neon_trn ();
20560 return;
20561 }
037e8744 20562 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20563}
20564
20565static void
20566do_neon_sat_abs_neg (void)
20567{
64c350f2 20568 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
1a186d29
AV
20569 return;
20570
20571 enum neon_shape rs;
20572 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20573 rs = neon_select_shape (NS_QQ, NS_NULL);
20574 else
20575 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20576 struct neon_type_el et = neon_check_type (2, rs,
20577 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20578 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20579}
20580
20581static void
20582do_neon_pair_long (void)
20583{
037e8744 20584 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20585 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20586 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20587 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 20588 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20589}
20590
20591static void
20592do_neon_recip_est (void)
20593{
037e8744 20594 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 20595 struct neon_type_el et = neon_check_type (2, rs,
cc933301 20596 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 20597 inst.instruction |= (et.type == NT_float) << 8;
037e8744 20598 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20599}
20600
20601static void
20602do_neon_cls (void)
20603{
64c350f2 20604 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20605 return;
20606
20607 enum neon_shape rs;
20608 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20609 rs = neon_select_shape (NS_QQ, NS_NULL);
20610 else
20611 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20612
5287ad62
JB
20613 struct neon_type_el et = neon_check_type (2, rs,
20614 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 20615 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20616}
20617
20618static void
20619do_neon_clz (void)
20620{
64c350f2 20621 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
f30ee27c
AV
20622 return;
20623
20624 enum neon_shape rs;
20625 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20626 rs = neon_select_shape (NS_QQ, NS_NULL);
20627 else
20628 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20629
5287ad62
JB
20630 struct neon_type_el et = neon_check_type (2, rs,
20631 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 20632 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20633}
20634
20635static void
20636do_neon_cnt (void)
20637{
037e8744 20638 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
20639 struct neon_type_el et = neon_check_type (2, rs,
20640 N_EQK | N_INT, N_8 | N_KEY);
037e8744 20641 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
20642}
20643
20644static void
20645do_neon_swp (void)
20646{
037e8744 20647 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
250dd99f
AM
20648 if (rs == NS_NULL)
20649 return;
037e8744 20650 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
20651}
20652
20653static void
20654do_neon_tbl_tbx (void)
20655{
20656 unsigned listlenbits;
dcbf9037 20657 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 20658
5287ad62
JB
20659 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20660 {
dcbf9037 20661 first_error (_("bad list length for table lookup"));
5287ad62
JB
20662 return;
20663 }
5f4273c7 20664
5287ad62
JB
20665 listlenbits = inst.operands[1].imm - 1;
20666 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20667 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20668 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20669 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20670 inst.instruction |= LOW4 (inst.operands[2].reg);
20671 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20672 inst.instruction |= listlenbits << 8;
5f4273c7 20673
88714cb8 20674 neon_dp_fixup (&inst);
5287ad62
JB
20675}
20676
20677static void
20678do_neon_ldm_stm (void)
20679{
ef8f595f
MI
20680 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20681 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20682 _(BAD_FPU));
5287ad62
JB
20683 /* P, U and L bits are part of bitmask. */
20684 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20685 unsigned offsetbits = inst.operands[1].imm * 2;
20686
037e8744
JB
20687 if (inst.operands[1].issingle)
20688 {
20689 do_vfp_nsyn_ldm_stm (is_dbmode);
20690 return;
20691 }
20692
5287ad62 20693 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 20694 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
20695
20696 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
20697 _("register list must contain at least 1 and at most 16 "
20698 "registers"));
5287ad62
JB
20699
20700 inst.instruction |= inst.operands[0].reg << 16;
20701 inst.instruction |= inst.operands[0].writeback << 21;
20702 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20703 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20704
20705 inst.instruction |= offsetbits;
5f4273c7 20706
037e8744 20707 do_vfp_cond_or_thumb ();
5287ad62
JB
20708}
20709
ef8f595f
MI
20710static void
20711do_vfp_nsyn_pop (void)
20712{
20713 nsyn_insert_sp ();
20714 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20715 return do_vfp_nsyn_opcode ("vldm");
20716 }
20717
20718 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20719 _(BAD_FPU));
20720
20721 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20722 _("register list must contain at least 1 and at most 16 "
20723 "registers"));
20724
20725 if (inst.operands[1].issingle)
20726 do_vfp_nsyn_opcode ("fldmias");
20727 else
20728 do_vfp_nsyn_opcode ("fldmiad");
20729}
20730
20731static void
20732do_vfp_nsyn_push (void)
20733{
20734 nsyn_insert_sp ();
20735 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20736 return do_vfp_nsyn_opcode ("vstmdb");
20737 }
20738
20739 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20740 _(BAD_FPU));
20741
20742 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20743 _("register list must contain at least 1 and at most 16 "
20744 "registers"));
20745
20746 if (inst.operands[1].issingle)
20747 do_vfp_nsyn_opcode ("fstmdbs");
20748 else
20749 do_vfp_nsyn_opcode ("fstmdbd");
20750}
20751
20752
5287ad62
JB
20753static void
20754do_neon_ldr_str (void)
20755{
5287ad62 20756 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 20757
6844b2c2
MGD
20758 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20759 And is UNPREDICTABLE in thumb mode. */
fa94de6b 20760 if (!is_ldr
6844b2c2 20761 && inst.operands[1].reg == REG_PC
ba86b375 20762 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 20763 {
94dcf8bf 20764 if (thumb_mode)
6844b2c2 20765 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 20766 else if (warn_on_deprecated)
5c3696f8 20767 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
20768 }
20769
037e8744
JB
20770 if (inst.operands[0].issingle)
20771 {
cd2f129f 20772 if (is_ldr)
477330fc 20773 do_vfp_nsyn_opcode ("flds");
cd2f129f 20774 else
477330fc 20775 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
20776
20777 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20778 if (inst.vectype.el[0].size == 16)
20779 do_scalar_fp16_v82_encode ();
5287ad62
JB
20780 }
20781 else
5287ad62 20782 {
cd2f129f 20783 if (is_ldr)
477330fc 20784 do_vfp_nsyn_opcode ("fldd");
5287ad62 20785 else
477330fc 20786 do_vfp_nsyn_opcode ("fstd");
5287ad62 20787 }
5287ad62
JB
20788}
20789
32c36c3c
AV
20790static void
20791do_t_vldr_vstr_sysreg (void)
20792{
20793 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20794 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20795
20796 /* Use of PC is UNPREDICTABLE. */
20797 if (inst.operands[1].reg == REG_PC)
20798 inst.error = _("Use of PC here is UNPREDICTABLE");
20799
20800 if (inst.operands[1].immisreg)
20801 inst.error = _("instruction does not accept register index");
20802
20803 if (!inst.operands[1].isreg)
20804 inst.error = _("instruction does not accept PC-relative addressing");
20805
20806 if (abs (inst.operands[1].imm) >= (1 << 7))
20807 inst.error = _("immediate value out of range");
20808
20809 inst.instruction = 0xec000f80;
20810 if (is_vldr)
20811 inst.instruction |= 1 << sysreg_vldr_bitno;
20812 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20813 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20814 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20815}
20816
20817static void
20818do_vldr_vstr (void)
20819{
20820 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20821
20822 /* VLDR/VSTR (System Register). */
20823 if (sysreg_op)
20824 {
20825 if (!mark_feature_used (&arm_ext_v8_1m_main))
20826 as_bad (_("Instruction not permitted on this architecture"));
20827
20828 do_t_vldr_vstr_sysreg ();
20829 }
20830 /* VLDR/VSTR. */
20831 else
20832 {
ef8f595f
MI
20833 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20834 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
32c36c3c
AV
20835 as_bad (_("Instruction not permitted on this architecture"));
20836 do_neon_ldr_str ();
20837 }
20838}
20839
5287ad62
JB
20840/* "interleave" version also handles non-interleaving register VLD1/VST1
20841 instructions. */
20842
20843static void
20844do_neon_ld_st_interleave (void)
20845{
037e8744 20846 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 20847 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
20848 unsigned alignbits = 0;
20849 unsigned idx;
20850 /* The bits in this table go:
20851 0: register stride of one (0) or two (1)
20852 1,2: register list length, minus one (1, 2, 3, 4).
20853 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20854 We use -1 for invalid entries. */
20855 const int typetable[] =
20856 {
20857 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20858 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20859 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20860 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20861 };
20862 int typebits;
20863
dcbf9037
JB
20864 if (et.type == NT_invtype)
20865 return;
20866
5287ad62
JB
20867 if (inst.operands[1].immisalign)
20868 switch (inst.operands[1].imm >> 8)
20869 {
20870 case 64: alignbits = 1; break;
20871 case 128:
477330fc 20872 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 20873 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
20874 goto bad_alignment;
20875 alignbits = 2;
20876 break;
5287ad62 20877 case 256:
477330fc
RM
20878 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20879 goto bad_alignment;
20880 alignbits = 3;
20881 break;
5287ad62
JB
20882 default:
20883 bad_alignment:
477330fc
RM
20884 first_error (_("bad alignment"));
20885 return;
5287ad62
JB
20886 }
20887
20888 inst.instruction |= alignbits << 4;
20889 inst.instruction |= neon_logbits (et.size) << 6;
20890
20891 /* Bits [4:6] of the immediate in a list specifier encode register stride
20892 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20893 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20894 up the right value for "type" in a table based on this value and the given
20895 list style, then stick it back. */
20896 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 20897 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
20898
20899 typebits = typetable[idx];
5f4273c7 20900
5287ad62 20901 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c 20902 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
35c228db 20903 BAD_EL_TYPE);
5287ad62
JB
20904
20905 inst.instruction &= ~0xf00;
20906 inst.instruction |= typebits << 8;
20907}
20908
20909/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20910 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20911 otherwise. The variable arguments are a list of pairs of legal (size, align)
20912 values, terminated with -1. */
20913
20914static int
aa8a0863 20915neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
20916{
20917 va_list ap;
20918 int result = FAIL, thissize, thisalign;
5f4273c7 20919
5287ad62
JB
20920 if (!inst.operands[1].immisalign)
20921 {
aa8a0863 20922 *do_alignment = 0;
5287ad62
JB
20923 return SUCCESS;
20924 }
5f4273c7 20925
aa8a0863 20926 va_start (ap, do_alignment);
5287ad62
JB
20927
20928 do
20929 {
20930 thissize = va_arg (ap, int);
20931 if (thissize == -1)
477330fc 20932 break;
5287ad62
JB
20933 thisalign = va_arg (ap, int);
20934
20935 if (size == thissize && align == thisalign)
477330fc 20936 result = SUCCESS;
5287ad62
JB
20937 }
20938 while (result != SUCCESS);
20939
20940 va_end (ap);
20941
20942 if (result == SUCCESS)
aa8a0863 20943 *do_alignment = 1;
5287ad62 20944 else
dcbf9037 20945 first_error (_("unsupported alignment for instruction"));
5f4273c7 20946
5287ad62
JB
20947 return result;
20948}
20949
20950static void
20951do_neon_ld_st_lane (void)
20952{
037e8744 20953 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 20954 int align_good, do_alignment = 0;
5287ad62
JB
20955 int logsize = neon_logbits (et.size);
20956 int align = inst.operands[1].imm >> 8;
20957 int n = (inst.instruction >> 8) & 3;
20958 int max_el = 64 / et.size;
5f4273c7 20959
dcbf9037
JB
20960 if (et.type == NT_invtype)
20961 return;
5f4273c7 20962
5287ad62 20963 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 20964 _("bad list length"));
5287ad62 20965 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 20966 _("scalar index out of range"));
5287ad62 20967 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
20968 && et.size == 8,
20969 _("stride of 2 unavailable when element size is 8"));
5f4273c7 20970
5287ad62
JB
20971 switch (n)
20972 {
20973 case 0: /* VLD1 / VST1. */
aa8a0863 20974 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 20975 32, 32, -1);
5287ad62 20976 if (align_good == FAIL)
477330fc 20977 return;
aa8a0863 20978 if (do_alignment)
477330fc
RM
20979 {
20980 unsigned alignbits = 0;
20981 switch (et.size)
20982 {
20983 case 16: alignbits = 0x1; break;
20984 case 32: alignbits = 0x3; break;
20985 default: ;
20986 }
20987 inst.instruction |= alignbits << 4;
20988 }
5287ad62
JB
20989 break;
20990
20991 case 1: /* VLD2 / VST2. */
aa8a0863
TS
20992 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20993 16, 32, 32, 64, -1);
5287ad62 20994 if (align_good == FAIL)
477330fc 20995 return;
aa8a0863 20996 if (do_alignment)
477330fc 20997 inst.instruction |= 1 << 4;
5287ad62
JB
20998 break;
20999
21000 case 2: /* VLD3 / VST3. */
21001 constraint (inst.operands[1].immisalign,
477330fc 21002 _("can't use alignment with this instruction"));
5287ad62
JB
21003 break;
21004
21005 case 3: /* VLD4 / VST4. */
aa8a0863 21006 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 21007 16, 64, 32, 64, 32, 128, -1);
5287ad62 21008 if (align_good == FAIL)
477330fc 21009 return;
aa8a0863 21010 if (do_alignment)
477330fc
RM
21011 {
21012 unsigned alignbits = 0;
21013 switch (et.size)
21014 {
21015 case 8: alignbits = 0x1; break;
21016 case 16: alignbits = 0x1; break;
21017 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21018 default: ;
21019 }
21020 inst.instruction |= alignbits << 4;
21021 }
5287ad62
JB
21022 break;
21023
21024 default: ;
21025 }
21026
21027 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21028 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21029 inst.instruction |= 1 << (4 + logsize);
5f4273c7 21030
5287ad62
JB
21031 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21032 inst.instruction |= logsize << 10;
21033}
21034
21035/* Encode single n-element structure to all lanes VLD<n> instructions. */
21036
21037static void
21038do_neon_ld_dup (void)
21039{
037e8744 21040 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 21041 int align_good, do_alignment = 0;
5287ad62 21042
dcbf9037
JB
21043 if (et.type == NT_invtype)
21044 return;
21045
5287ad62
JB
21046 switch ((inst.instruction >> 8) & 3)
21047 {
21048 case 0: /* VLD1. */
9c2799c2 21049 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 21050 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 21051 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 21052 if (align_good == FAIL)
477330fc 21053 return;
5287ad62 21054 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
21055 {
21056 case 1: break;
21057 case 2: inst.instruction |= 1 << 5; break;
21058 default: first_error (_("bad list length")); return;
21059 }
5287ad62
JB
21060 inst.instruction |= neon_logbits (et.size) << 6;
21061 break;
21062
21063 case 1: /* VLD2. */
21064 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
21065 &do_alignment, 8, 16, 16, 32, 32, 64,
21066 -1);
5287ad62 21067 if (align_good == FAIL)
477330fc 21068 return;
5287ad62 21069 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 21070 _("bad list length"));
5287ad62 21071 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21072 inst.instruction |= 1 << 5;
5287ad62
JB
21073 inst.instruction |= neon_logbits (et.size) << 6;
21074 break;
21075
21076 case 2: /* VLD3. */
21077 constraint (inst.operands[1].immisalign,
477330fc 21078 _("can't use alignment with this instruction"));
5287ad62 21079 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 21080 _("bad list length"));
5287ad62 21081 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 21082 inst.instruction |= 1 << 5;
5287ad62
JB
21083 inst.instruction |= neon_logbits (et.size) << 6;
21084 break;
21085
21086 case 3: /* VLD4. */
21087 {
477330fc 21088 int align = inst.operands[1].imm >> 8;
aa8a0863 21089 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
21090 16, 64, 32, 64, 32, 128, -1);
21091 if (align_good == FAIL)
21092 return;
21093 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21094 _("bad list length"));
21095 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21096 inst.instruction |= 1 << 5;
21097 if (et.size == 32 && align == 128)
21098 inst.instruction |= 0x3 << 6;
21099 else
21100 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
21101 }
21102 break;
21103
21104 default: ;
21105 }
21106
aa8a0863 21107 inst.instruction |= do_alignment << 4;
5287ad62
JB
21108}
21109
21110/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21111 apart from bits [11:4]. */
21112
21113static void
21114do_neon_ldx_stx (void)
21115{
b1a769ed
DG
21116 if (inst.operands[1].isreg)
21117 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21118
5287ad62
JB
21119 switch (NEON_LANE (inst.operands[0].imm))
21120 {
21121 case NEON_INTERLEAVE_LANES:
88714cb8 21122 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
21123 do_neon_ld_st_interleave ();
21124 break;
5f4273c7 21125
5287ad62 21126 case NEON_ALL_LANES:
88714cb8 21127 NEON_ENCODE (DUP, inst);
2d51fb74
JB
21128 if (inst.instruction == N_INV)
21129 {
21130 first_error ("only loads support such operands");
21131 break;
21132 }
5287ad62
JB
21133 do_neon_ld_dup ();
21134 break;
5f4273c7 21135
5287ad62 21136 default:
88714cb8 21137 NEON_ENCODE (LANE, inst);
5287ad62
JB
21138 do_neon_ld_st_lane ();
21139 }
21140
21141 /* L bit comes from bit mask. */
21142 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21143 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21144 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 21145
5287ad62
JB
21146 if (inst.operands[1].postind)
21147 {
21148 int postreg = inst.operands[1].imm & 0xf;
21149 constraint (!inst.operands[1].immisreg,
477330fc 21150 _("post-index must be a register"));
5287ad62 21151 constraint (postreg == 0xd || postreg == 0xf,
477330fc 21152 _("bad register for post-index"));
5287ad62
JB
21153 inst.instruction |= postreg;
21154 }
4f2374c7 21155 else
5287ad62 21156 {
4f2374c7 21157 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
e2b0ab59
AV
21158 constraint (inst.relocs[0].exp.X_op != O_constant
21159 || inst.relocs[0].exp.X_add_number != 0,
4f2374c7
WN
21160 BAD_ADDR_MODE);
21161
21162 if (inst.operands[1].writeback)
21163 {
21164 inst.instruction |= 0xd;
21165 }
21166 else
21167 inst.instruction |= 0xf;
5287ad62 21168 }
5f4273c7 21169
5287ad62
JB
21170 if (thumb_mode)
21171 inst.instruction |= 0xf9000000;
21172 else
21173 inst.instruction |= 0xf4000000;
21174}
33399f07
MGD
21175
21176/* FP v8. */
21177static void
21178do_vfp_nsyn_fpv8 (enum neon_shape rs)
21179{
a715796b
TG
21180 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21181 D register operands. */
21182 if (neon_shape_class[rs] == SC_DOUBLE)
21183 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21184 _(BAD_FPU));
21185
33399f07
MGD
21186 NEON_ENCODE (FPV8, inst);
21187
9db2f6b4
RL
21188 if (rs == NS_FFF || rs == NS_HHH)
21189 {
21190 do_vfp_sp_dyadic ();
21191
21192 /* ARMv8.2 fp16 instruction. */
21193 if (rs == NS_HHH)
21194 do_scalar_fp16_v82_encode ();
21195 }
33399f07
MGD
21196 else
21197 do_vfp_dp_rd_rn_rm ();
21198
21199 if (rs == NS_DDD)
21200 inst.instruction |= 0x100;
21201
21202 inst.instruction |= 0xf0000000;
21203}
21204
21205static void
21206do_vsel (void)
21207{
5ee91343 21208 set_pred_insn_type (OUTSIDE_PRED_INSN);
33399f07
MGD
21209
21210 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21211 first_error (_("invalid instruction shape"));
21212}
21213
73924fbc
MGD
21214static void
21215do_vmaxnm (void)
21216{
935295b5
AV
21217 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21218 set_pred_insn_type (OUTSIDE_PRED_INSN);
73924fbc
MGD
21219
21220 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21221 return;
21222
64c350f2 21223 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
73924fbc
MGD
21224 return;
21225
cc933301 21226 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
21227}
21228
30bdf752
MGD
21229static void
21230do_vrint_1 (enum neon_cvt_mode mode)
21231{
9db2f6b4 21232 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
21233 struct neon_type_el et;
21234
21235 if (rs == NS_NULL)
21236 return;
21237
a715796b
TG
21238 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21239 D register operands. */
21240 if (neon_shape_class[rs] == SC_DOUBLE)
21241 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21242 _(BAD_FPU));
21243
9db2f6b4
RL
21244 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21245 | N_VFP);
30bdf752
MGD
21246 if (et.type != NT_invtype)
21247 {
21248 /* VFP encodings. */
21249 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21250 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
5ee91343 21251 set_pred_insn_type (OUTSIDE_PRED_INSN);
30bdf752
MGD
21252
21253 NEON_ENCODE (FPV8, inst);
9db2f6b4 21254 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
21255 do_vfp_sp_monadic ();
21256 else
21257 do_vfp_dp_rd_rm ();
21258
21259 switch (mode)
21260 {
21261 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21262 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21263 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21264 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21265 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21266 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21267 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21268 default: abort ();
21269 }
21270
21271 inst.instruction |= (rs == NS_DD) << 8;
21272 do_vfp_cond_or_thumb ();
9db2f6b4
RL
21273
21274 /* ARMv8.2 fp16 vrint instruction. */
21275 if (rs == NS_HH)
21276 do_scalar_fp16_v82_encode ();
30bdf752
MGD
21277 }
21278 else
21279 {
21280 /* Neon encodings (or something broken...). */
21281 inst.error = NULL;
cc933301 21282 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
21283
21284 if (et.type == NT_invtype)
21285 return;
21286
64c350f2
AV
21287 if (!check_simd_pred_availability (TRUE,
21288 NEON_CHECK_CC | NEON_CHECK_ARCH8))
30bdf752
MGD
21289 return;
21290
a710b305
AV
21291 NEON_ENCODE (FLOAT, inst);
21292
30bdf752
MGD
21293 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21294 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21295 inst.instruction |= LOW4 (inst.operands[1].reg);
21296 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21297 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
21298 /* Mask off the original size bits and reencode them. */
21299 inst.instruction = ((inst.instruction & 0xfff3ffff)
21300 | neon_logbits (et.size) << 18);
21301
30bdf752
MGD
21302 switch (mode)
21303 {
21304 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21305 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21306 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21307 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21308 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21309 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21310 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21311 default: abort ();
21312 }
21313
21314 if (thumb_mode)
21315 inst.instruction |= 0xfc000000;
21316 else
21317 inst.instruction |= 0xf0000000;
21318 }
21319}
21320
21321static void
21322do_vrintx (void)
21323{
21324 do_vrint_1 (neon_cvt_mode_x);
21325}
21326
21327static void
21328do_vrintz (void)
21329{
21330 do_vrint_1 (neon_cvt_mode_z);
21331}
21332
21333static void
21334do_vrintr (void)
21335{
21336 do_vrint_1 (neon_cvt_mode_r);
21337}
21338
21339static void
21340do_vrinta (void)
21341{
21342 do_vrint_1 (neon_cvt_mode_a);
21343}
21344
21345static void
21346do_vrintn (void)
21347{
21348 do_vrint_1 (neon_cvt_mode_n);
21349}
21350
21351static void
21352do_vrintp (void)
21353{
21354 do_vrint_1 (neon_cvt_mode_p);
21355}
21356
21357static void
21358do_vrintm (void)
21359{
21360 do_vrint_1 (neon_cvt_mode_m);
21361}
21362
c28eeff2
SN
21363static unsigned
21364neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21365{
21366 unsigned regno = NEON_SCALAR_REG (opnd);
21367 unsigned elno = NEON_SCALAR_INDEX (opnd);
21368
21369 if (elsize == 16 && elno < 2 && regno < 16)
21370 return regno | (elno << 4);
21371 else if (elsize == 32 && elno == 0)
21372 return regno;
21373
21374 first_error (_("scalar out of range"));
21375 return 0;
21376}
21377
21378static void
21379do_vcmla (void)
21380{
5d281bf0
AV
21381 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21382 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21383 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21384 constraint (inst.relocs[0].exp.X_op != O_constant,
21385 _("expression too complex"));
21386 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2
SN
21387 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21388 _("immediate out of range"));
21389 rot /= 90;
5d281bf0 21390
64c350f2
AV
21391 if (!check_simd_pred_availability (TRUE,
21392 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21393 return;
21394
c28eeff2
SN
21395 if (inst.operands[2].isscalar)
21396 {
5d281bf0
AV
21397 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21398 first_error (_("invalid instruction shape"));
c28eeff2
SN
21399 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21400 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21401 N_KEY | N_F16 | N_F32).size;
21402 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21403 inst.is_neon = 1;
21404 inst.instruction = 0xfe000800;
21405 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21406 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21407 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21408 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21409 inst.instruction |= LOW4 (m);
21410 inst.instruction |= HI1 (m) << 5;
21411 inst.instruction |= neon_quad (rs) << 6;
21412 inst.instruction |= rot << 20;
21413 inst.instruction |= (size == 32) << 23;
21414 }
21415 else
21416 {
5d281bf0
AV
21417 enum neon_shape rs;
21418 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21419 rs = neon_select_shape (NS_QQQI, NS_NULL);
21420 else
21421 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21422
c28eeff2
SN
21423 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21424 N_KEY | N_F16 | N_F32).size;
5d281bf0
AV
21425 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21426 && (inst.operands[0].reg == inst.operands[1].reg
21427 || inst.operands[0].reg == inst.operands[2].reg))
21428 as_tsktsk (BAD_MVE_SRCDEST);
21429
c28eeff2
SN
21430 neon_three_same (neon_quad (rs), 0, -1);
21431 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21432 inst.instruction |= 0xfc200800;
21433 inst.instruction |= rot << 23;
21434 inst.instruction |= (size == 32) << 20;
21435 }
21436}
21437
21438static void
21439do_vcadd (void)
21440{
5d281bf0
AV
21441 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21442 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21443 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
e2b0ab59
AV
21444 constraint (inst.relocs[0].exp.X_op != O_constant,
21445 _("expression too complex"));
5d281bf0 21446
e2b0ab59 21447 unsigned rot = inst.relocs[0].exp.X_add_number;
c28eeff2 21448 constraint (rot != 90 && rot != 270, _("immediate out of range"));
5d281bf0
AV
21449 enum neon_shape rs;
21450 struct neon_type_el et;
21451 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21452 {
21453 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21454 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21455 }
21456 else
21457 {
21458 rs = neon_select_shape (NS_QQQI, NS_NULL);
21459 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21460 | N_I16 | N_I32);
21461 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21462 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21463 "operand makes instruction UNPREDICTABLE"));
21464 }
21465
21466 if (et.type == NT_invtype)
21467 return;
21468
64c350f2
AV
21469 if (!check_simd_pred_availability (et.type == NT_float,
21470 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
5d281bf0
AV
21471 return;
21472
21473 if (et.type == NT_float)
21474 {
21475 neon_three_same (neon_quad (rs), 0, -1);
21476 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21477 inst.instruction |= 0xfc800800;
21478 inst.instruction |= (rot == 270) << 24;
21479 inst.instruction |= (et.size == 32) << 20;
21480 }
21481 else
21482 {
21483 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21484 inst.instruction = 0xfe000f00;
21485 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21486 inst.instruction |= neon_logbits (et.size) << 20;
21487 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21488 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21489 inst.instruction |= (rot == 270) << 12;
21490 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21491 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21492 inst.instruction |= LOW4 (inst.operands[2].reg);
21493 inst.is_neon = 1;
21494 }
c28eeff2
SN
21495}
21496
c604a79a
JW
21497/* Dot Product instructions encoding support. */
21498
21499static void
21500do_neon_dotproduct (int unsigned_p)
21501{
21502 enum neon_shape rs;
21503 unsigned scalar_oprd2 = 0;
21504 int high8;
21505
21506 if (inst.cond != COND_ALWAYS)
21507 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21508 "is UNPREDICTABLE"));
21509
21510 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21511 _(BAD_FPU));
21512
21513 /* Dot Product instructions are in three-same D/Q register format or the third
21514 operand can be a scalar index register. */
21515 if (inst.operands[2].isscalar)
21516 {
21517 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21518 high8 = 0xfe000000;
21519 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21520 }
21521 else
21522 {
21523 high8 = 0xfc000000;
21524 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21525 }
21526
21527 if (unsigned_p)
21528 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21529 else
21530 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21531
21532 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21533 Product instruction, so we pass 0 as the "ubit" parameter. And the
21534 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21535 neon_three_same (neon_quad (rs), 0, 32);
21536
21537 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21538 different NEON three-same encoding. */
21539 inst.instruction &= 0x00ffffff;
21540 inst.instruction |= high8;
21541 /* Encode 'U' bit which indicates signedness. */
21542 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21543 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21544 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21545 the instruction encoding. */
21546 if (inst.operands[2].isscalar)
21547 {
21548 inst.instruction &= 0xffffffd0;
21549 inst.instruction |= LOW4 (scalar_oprd2);
21550 inst.instruction |= HI1 (scalar_oprd2) << 5;
21551 }
21552}
21553
21554/* Dot Product instructions for signed integer. */
21555
21556static void
21557do_neon_dotproduct_s (void)
21558{
21559 return do_neon_dotproduct (0);
21560}
21561
21562/* Dot Product instructions for unsigned integer. */
21563
21564static void
21565do_neon_dotproduct_u (void)
21566{
21567 return do_neon_dotproduct (1);
21568}
21569
616ce08e
MM
21570static void
21571do_vusdot (void)
21572{
21573 enum neon_shape rs;
21574 set_pred_insn_type (OUTSIDE_PRED_INSN);
21575 if (inst.operands[2].isscalar)
21576 {
21577 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21578 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21579
21580 inst.instruction |= (1 << 25);
21581 int index = inst.operands[2].reg & 0xf;
21582 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21583 inst.operands[2].reg >>= 4;
21584 constraint (!(inst.operands[2].reg < 16),
21585 _("indexed register must be less than 16"));
21586 neon_three_args (rs == NS_QQS);
21587 inst.instruction |= (index << 5);
21588 }
21589 else
21590 {
21591 inst.instruction |= (1 << 21);
21592 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21593 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21594 neon_three_args (rs == NS_QQQ);
21595 }
21596}
21597
21598static void
21599do_vsudot (void)
21600{
21601 enum neon_shape rs;
21602 set_pred_insn_type (OUTSIDE_PRED_INSN);
21603 if (inst.operands[2].isscalar)
21604 {
21605 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21606 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21607
21608 inst.instruction |= (1 << 25);
21609 int index = inst.operands[2].reg & 0xf;
21610 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21611 inst.operands[2].reg >>= 4;
21612 constraint (!(inst.operands[2].reg < 16),
21613 _("indexed register must be less than 16"));
21614 neon_three_args (rs == NS_QQS);
21615 inst.instruction |= (index << 5);
21616 }
21617}
21618
21619static void
21620do_vsmmla (void)
21621{
21622 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21623 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21624
21625 set_pred_insn_type (OUTSIDE_PRED_INSN);
21626
21627 neon_three_args (1);
21628
21629}
21630
21631static void
21632do_vummla (void)
21633{
21634 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21635 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21636
21637 set_pred_insn_type (OUTSIDE_PRED_INSN);
21638
21639 neon_three_args (1);
21640
21641}
21642
4934a27c
MM
21643static void
21644check_cde_operand (size_t index, int is_dual)
21645{
21646 unsigned Rx = inst.operands[index].reg;
21647 bfd_boolean isvec = inst.operands[index].isvec;
21648 if (is_dual == 0 && thumb_mode)
21649 constraint (
21650 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21651 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21652 else
21653 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21654 _("Register must be an even register between r0-r10."));
21655}
21656
21657static bfd_boolean
21658cde_coproc_enabled (unsigned coproc)
21659{
21660 switch (coproc)
21661 {
21662 case 0: return mark_feature_used (&arm_ext_cde0);
21663 case 1: return mark_feature_used (&arm_ext_cde1);
21664 case 2: return mark_feature_used (&arm_ext_cde2);
21665 case 3: return mark_feature_used (&arm_ext_cde3);
21666 case 4: return mark_feature_used (&arm_ext_cde4);
21667 case 5: return mark_feature_used (&arm_ext_cde5);
21668 case 6: return mark_feature_used (&arm_ext_cde6);
21669 case 7: return mark_feature_used (&arm_ext_cde7);
21670 default: return FALSE;
21671 }
21672}
21673
21674#define cde_coproc_pos 8
21675static void
21676cde_handle_coproc (void)
21677{
21678 unsigned coproc = inst.operands[0].reg;
21679 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21680 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21681 inst.instruction |= coproc << cde_coproc_pos;
21682}
21683#undef cde_coproc_pos
21684
21685static void
21686cxn_handle_predication (bfd_boolean is_accum)
21687{
cceb53b8
MM
21688 if (is_accum && conditional_insn ())
21689 set_pred_insn_type (INSIDE_IT_INSN);
21690 else if (conditional_insn ())
21691 /* conditional_insn essentially checks for a suffix, not whether the
21692 instruction is inside an IT block or not.
21693 The non-accumulator versions should not have suffixes. */
4934a27c 21694 inst.error = BAD_SYNTAX;
4934a27c
MM
21695 else
21696 set_pred_insn_type (OUTSIDE_PRED_INSN);
21697}
21698
21699static void
21700do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21701{
21702
21703 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21704
21705 unsigned imm, Rd;
21706
21707 Rd = inst.operands[1].reg;
21708 check_cde_operand (1, is_dual);
21709
21710 if (is_dual == 1)
21711 {
21712 constraint (inst.operands[2].reg != Rd + 1,
21713 _("cx1d requires consecutive destination registers."));
21714 imm = inst.operands[3].imm;
21715 }
21716 else if (is_dual == 0)
21717 imm = inst.operands[2].imm;
21718 else
21719 abort ();
21720
21721 inst.instruction |= Rd << 12;
21722 inst.instruction |= (imm & 0x1F80) << 9;
21723 inst.instruction |= (imm & 0x0040) << 1;
21724 inst.instruction |= (imm & 0x003f);
21725
21726 cde_handle_coproc ();
21727 cxn_handle_predication (is_accum);
21728}
21729
21730static void
21731do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21732{
21733
21734 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21735
21736 unsigned imm, Rd, Rn;
21737
21738 Rd = inst.operands[1].reg;
21739
21740 if (is_dual == 1)
21741 {
21742 constraint (inst.operands[2].reg != Rd + 1,
21743 _("cx2d requires consecutive destination registers."));
21744 imm = inst.operands[4].imm;
21745 Rn = inst.operands[3].reg;
21746 }
21747 else if (is_dual == 0)
21748 {
21749 imm = inst.operands[3].imm;
21750 Rn = inst.operands[2].reg;
21751 }
21752 else
21753 abort ();
21754
21755 check_cde_operand (2 + is_dual, /* is_dual = */0);
21756 check_cde_operand (1, is_dual);
21757
21758 inst.instruction |= Rd << 12;
21759 inst.instruction |= Rn << 16;
21760
21761 inst.instruction |= (imm & 0x0380) << 13;
21762 inst.instruction |= (imm & 0x0040) << 1;
21763 inst.instruction |= (imm & 0x003f);
21764
21765 cde_handle_coproc ();
21766 cxn_handle_predication (is_accum);
21767}
21768
21769static void
21770do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21771{
21772
21773 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21774
21775 unsigned imm, Rd, Rn, Rm;
21776
21777 Rd = inst.operands[1].reg;
21778
21779 if (is_dual == 1)
21780 {
21781 constraint (inst.operands[2].reg != Rd + 1,
21782 _("cx3d requires consecutive destination registers."));
21783 imm = inst.operands[5].imm;
21784 Rn = inst.operands[3].reg;
21785 Rm = inst.operands[4].reg;
21786 }
21787 else if (is_dual == 0)
21788 {
21789 imm = inst.operands[4].imm;
21790 Rn = inst.operands[2].reg;
21791 Rm = inst.operands[3].reg;
21792 }
21793 else
21794 abort ();
21795
21796 check_cde_operand (1, is_dual);
21797 check_cde_operand (2 + is_dual, /* is_dual = */0);
21798 check_cde_operand (3 + is_dual, /* is_dual = */0);
21799
21800 inst.instruction |= Rd;
21801 inst.instruction |= Rn << 16;
21802 inst.instruction |= Rm << 12;
21803
21804 inst.instruction |= (imm & 0x0038) << 17;
21805 inst.instruction |= (imm & 0x0004) << 5;
21806 inst.instruction |= (imm & 0x0003) << 4;
21807
21808 cde_handle_coproc ();
21809 cxn_handle_predication (is_accum);
21810}
21811
21812static void
21813do_cx1 (void)
21814{
21815 return do_custom_instruction_1 (0, 0);
21816}
21817
21818static void
21819do_cx1a (void)
21820{
21821 return do_custom_instruction_1 (0, 1);
21822}
21823
21824static void
21825do_cx1d (void)
21826{
21827 return do_custom_instruction_1 (1, 0);
21828}
21829
21830static void
21831do_cx1da (void)
21832{
21833 return do_custom_instruction_1 (1, 1);
21834}
21835
21836static void
21837do_cx2 (void)
21838{
21839 return do_custom_instruction_2 (0, 0);
21840}
21841
21842static void
21843do_cx2a (void)
21844{
21845 return do_custom_instruction_2 (0, 1);
21846}
21847
21848static void
21849do_cx2d (void)
21850{
21851 return do_custom_instruction_2 (1, 0);
21852}
21853
21854static void
21855do_cx2da (void)
21856{
21857 return do_custom_instruction_2 (1, 1);
21858}
21859
21860static void
21861do_cx3 (void)
21862{
21863 return do_custom_instruction_3 (0, 0);
21864}
21865
21866static void
21867do_cx3a (void)
21868{
21869 return do_custom_instruction_3 (0, 1);
21870}
21871
21872static void
21873do_cx3d (void)
21874{
21875 return do_custom_instruction_3 (1, 0);
21876}
21877
21878static void
21879do_cx3da (void)
21880{
21881 return do_custom_instruction_3 (1, 1);
21882}
21883
5aae9ae9
MM
21884static void
21885vcx_assign_vec_d (unsigned regnum)
21886{
21887 inst.instruction |= HI4 (regnum) << 12;
21888 inst.instruction |= LOW1 (regnum) << 22;
21889}
21890
21891static void
21892vcx_assign_vec_m (unsigned regnum)
21893{
21894 inst.instruction |= HI4 (regnum);
21895 inst.instruction |= LOW1 (regnum) << 5;
21896}
21897
21898static void
21899vcx_assign_vec_n (unsigned regnum)
21900{
21901 inst.instruction |= HI4 (regnum) << 16;
21902 inst.instruction |= LOW1 (regnum) << 7;
21903}
21904
21905enum vcx_reg_type {
21906 q_reg,
21907 d_reg,
21908 s_reg
21909};
21910
21911static enum vcx_reg_type
21912vcx_get_reg_type (enum neon_shape ns)
21913{
21914 gas_assert (ns == NS_PQI
21915 || ns == NS_PDI
21916 || ns == NS_PFI
21917 || ns == NS_PQQI
21918 || ns == NS_PDDI
21919 || ns == NS_PFFI
21920 || ns == NS_PQQQI
21921 || ns == NS_PDDDI
21922 || ns == NS_PFFFI);
21923 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21924 return q_reg;
21925 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21926 return d_reg;
21927 return s_reg;
21928}
21929
21930#define vcx_size_pos 24
21931#define vcx_vec_pos 6
21932static unsigned
21933vcx_handle_shape (enum vcx_reg_type reg_type)
21934{
21935 unsigned mult = 2;
21936 if (reg_type == q_reg)
21937 inst.instruction |= 1 << vcx_vec_pos;
21938 else if (reg_type == d_reg)
21939 inst.instruction |= 1 << vcx_size_pos;
21940 else
21941 mult = 1;
21942 /* NOTE:
21943 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21944 bits (or equivalent for N and M registers).
21945 Similarly the D registers are encoded as N in D:Vd bits.
21946 While the S registers are encoded as N in the Vd:D bits.
21947
21948 Taking into account the maximum values of these registers we can see a
21949 nicer pattern for calculation:
21950 Q -> 7, D -> 15, S -> 31
21951
21952 If we say that everything is encoded in the Vd:D bits, then we can say
21953 that Q is encoded as 4*N, and D is encoded as 2*N.
21954 This way the bits will end up the same, and calculation is simpler.
21955 (calculation is now:
21956 1. Multiply by a number determined by the register letter.
21957 2. Encode resulting number in Vd:D bits.)
21958
21959 This is made a little more complicated by automatic handling of 'Q'
21960 registers elsewhere, which means the register number is already 2*N where
21961 N is the number the user wrote after the register letter.
21962 */
21963 return mult;
21964}
21965#undef vcx_vec_pos
21966#undef vcx_size_pos
21967
21968static void
21969vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21970{
21971 if (reg_type == q_reg)
21972 {
21973 gas_assert (R % 2 == 0);
21974 constraint (R >= 16, _("'q' register must be in range 0-7"));
21975 }
21976 else if (reg_type == d_reg)
21977 constraint (R >= 16, _("'d' register must be in range 0-15"));
21978 else
21979 constraint (R >= 32, _("'s' register must be in range 0-31"));
21980}
21981
21982static void (*vcx_assign_vec[3]) (unsigned) = {
21983 vcx_assign_vec_d,
21984 vcx_assign_vec_m,
21985 vcx_assign_vec_n
21986};
21987
21988static void
21989vcx_handle_register_arguments (unsigned num_registers,
21990 enum vcx_reg_type reg_type)
21991{
1ed818b4 21992 unsigned R, i;
5aae9ae9 21993 unsigned reg_mult = vcx_handle_shape (reg_type);
1ed818b4 21994 for (i = 0; i < num_registers; i++)
5aae9ae9
MM
21995 {
21996 R = inst.operands[i+1].reg;
21997 vcx_ensure_register_in_range (R, reg_type);
21998 if (num_registers == 3 && i > 0)
21999 {
22000 if (i == 2)
22001 vcx_assign_vec[1] (R * reg_mult);
22002 else
22003 vcx_assign_vec[2] (R * reg_mult);
22004 continue;
22005 }
22006 vcx_assign_vec[i](R * reg_mult);
22007 }
22008}
22009
22010static void
22011vcx_handle_insn_block (enum vcx_reg_type reg_type)
22012{
22013 if (reg_type == q_reg)
22014 if (inst.cond > COND_ALWAYS)
22015 inst.pred_insn_type = INSIDE_VPT_INSN;
22016 else
22017 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22018 else if (inst.cond == COND_ALWAYS)
22019 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22020 else
22021 inst.error = BAD_NOT_IT;
22022}
22023
22024static void
22025vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22026{
22027 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22028 cde_handle_coproc ();
22029 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22030 vcx_handle_register_arguments (num_args, reg_type);
22031 vcx_handle_insn_block (reg_type);
22032 if (reg_type == q_reg)
22033 constraint (!mark_feature_used (&mve_ext),
22034 _("vcx instructions with Q registers require MVE"));
22035 else
22036 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22037 && mark_feature_used (&armv8m_fp))
22038 && !mark_feature_used (&mve_ext),
22039 _("vcx instructions with S or D registers require either MVE"
ddc73fa9 22040 " or Armv8-M floating point extension."));
5aae9ae9
MM
22041}
22042
22043static void
22044do_vcx1 (void)
22045{
22046 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22047 vcx_handle_common_checks (1, rs);
22048
22049 unsigned imm = inst.operands[2].imm;
22050 inst.instruction |= (imm & 0x03f);
22051 inst.instruction |= (imm & 0x040) << 1;
22052 inst.instruction |= (imm & 0x780) << 9;
22053 if (rs != NS_PQI)
22054 constraint (imm >= 2048,
22055 _("vcx1 with S or D registers takes immediate within 0-2047"));
22056 inst.instruction |= (imm & 0x800) << 13;
22057}
22058
22059static void
22060do_vcx2 (void)
22061{
22062 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22063 vcx_handle_common_checks (2, rs);
22064
22065 unsigned imm = inst.operands[3].imm;
22066 inst.instruction |= (imm & 0x01) << 4;
22067 inst.instruction |= (imm & 0x02) << 6;
22068 inst.instruction |= (imm & 0x3c) << 14;
22069 if (rs != NS_PQQI)
22070 constraint (imm >= 64,
22071 _("vcx2 with S or D registers takes immediate within 0-63"));
22072 inst.instruction |= (imm & 0x40) << 18;
22073}
22074
22075static void
22076do_vcx3 (void)
22077{
22078 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22079 vcx_handle_common_checks (3, rs);
22080
22081 unsigned imm = inst.operands[4].imm;
22082 inst.instruction |= (imm & 0x1) << 4;
22083 inst.instruction |= (imm & 0x6) << 19;
22084 if (rs != NS_PQQQI)
22085 constraint (imm >= 8,
22086 _("vcx2 with S or D registers takes immediate within 0-7"));
22087 inst.instruction |= (imm & 0x8) << 21;
22088}
22089
91ff7894
MGD
22090/* Crypto v1 instructions. */
22091static void
22092do_crypto_2op_1 (unsigned elttype, int op)
22093{
5ee91343 22094 set_pred_insn_type (OUTSIDE_PRED_INSN);
91ff7894
MGD
22095
22096 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22097 == NT_invtype)
22098 return;
22099
22100 inst.error = NULL;
22101
22102 NEON_ENCODE (INTEGER, inst);
22103 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22104 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22105 inst.instruction |= LOW4 (inst.operands[1].reg);
22106 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22107 if (op != -1)
22108 inst.instruction |= op << 6;
22109
22110 if (thumb_mode)
22111 inst.instruction |= 0xfc000000;
22112 else
22113 inst.instruction |= 0xf0000000;
22114}
22115
48adcd8e
MGD
22116static void
22117do_crypto_3op_1 (int u, int op)
22118{
5ee91343 22119 set_pred_insn_type (OUTSIDE_PRED_INSN);
48adcd8e
MGD
22120
22121 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22122 N_32 | N_UNT | N_KEY).type == NT_invtype)
22123 return;
22124
22125 inst.error = NULL;
22126
22127 NEON_ENCODE (INTEGER, inst);
22128 neon_three_same (1, u, 8 << op);
22129}
22130
91ff7894
MGD
22131static void
22132do_aese (void)
22133{
22134 do_crypto_2op_1 (N_8, 0);
22135}
22136
22137static void
22138do_aesd (void)
22139{
22140 do_crypto_2op_1 (N_8, 1);
22141}
22142
22143static void
22144do_aesmc (void)
22145{
22146 do_crypto_2op_1 (N_8, 2);
22147}
22148
22149static void
22150do_aesimc (void)
22151{
22152 do_crypto_2op_1 (N_8, 3);
22153}
22154
48adcd8e
MGD
22155static void
22156do_sha1c (void)
22157{
22158 do_crypto_3op_1 (0, 0);
22159}
22160
22161static void
22162do_sha1p (void)
22163{
22164 do_crypto_3op_1 (0, 1);
22165}
22166
22167static void
22168do_sha1m (void)
22169{
22170 do_crypto_3op_1 (0, 2);
22171}
22172
22173static void
22174do_sha1su0 (void)
22175{
22176 do_crypto_3op_1 (0, 3);
22177}
91ff7894 22178
48adcd8e
MGD
22179static void
22180do_sha256h (void)
22181{
22182 do_crypto_3op_1 (1, 0);
22183}
22184
22185static void
22186do_sha256h2 (void)
22187{
22188 do_crypto_3op_1 (1, 1);
22189}
22190
22191static void
22192do_sha256su1 (void)
22193{
22194 do_crypto_3op_1 (1, 2);
22195}
3c9017d2
MGD
22196
22197static void
22198do_sha1h (void)
22199{
22200 do_crypto_2op_1 (N_32, -1);
22201}
22202
22203static void
22204do_sha1su1 (void)
22205{
22206 do_crypto_2op_1 (N_32, 0);
22207}
22208
22209static void
22210do_sha256su0 (void)
22211{
22212 do_crypto_2op_1 (N_32, 1);
22213}
dd5181d5
KT
22214
22215static void
22216do_crc32_1 (unsigned int poly, unsigned int sz)
22217{
22218 unsigned int Rd = inst.operands[0].reg;
22219 unsigned int Rn = inst.operands[1].reg;
22220 unsigned int Rm = inst.operands[2].reg;
22221
5ee91343 22222 set_pred_insn_type (OUTSIDE_PRED_INSN);
dd5181d5
KT
22223 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22224 inst.instruction |= LOW4 (Rn) << 16;
22225 inst.instruction |= LOW4 (Rm);
22226 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22227 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22228
22229 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22230 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
22231}
22232
22233static void
22234do_crc32b (void)
22235{
22236 do_crc32_1 (0, 0);
22237}
22238
22239static void
22240do_crc32h (void)
22241{
22242 do_crc32_1 (0, 1);
22243}
22244
22245static void
22246do_crc32w (void)
22247{
22248 do_crc32_1 (0, 2);
22249}
22250
22251static void
22252do_crc32cb (void)
22253{
22254 do_crc32_1 (1, 0);
22255}
22256
22257static void
22258do_crc32ch (void)
22259{
22260 do_crc32_1 (1, 1);
22261}
22262
22263static void
22264do_crc32cw (void)
22265{
22266 do_crc32_1 (1, 2);
22267}
22268
49e8a725
SN
22269static void
22270do_vjcvt (void)
22271{
22272 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22273 _(BAD_FPU));
22274 neon_check_type (2, NS_FD, N_S32, N_F64);
22275 do_vfp_sp_dp_cvt ();
22276 do_vfp_cond_or_thumb ();
22277}
22278
aab2c27d
MM
22279static void
22280do_vdot (void)
22281{
22282 enum neon_shape rs;
22283 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22284 set_pred_insn_type (OUTSIDE_PRED_INSN);
22285 if (inst.operands[2].isscalar)
22286 {
22287 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22288 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22289
22290 inst.instruction |= (1 << 25);
22291 int index = inst.operands[2].reg & 0xf;
22292 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22293 inst.operands[2].reg >>= 4;
22294 constraint (!(inst.operands[2].reg < 16),
22295 _("indexed register must be less than 16"));
22296 neon_three_args (rs == NS_QQS);
22297 inst.instruction |= (index << 5);
22298 }
22299 else
22300 {
22301 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22302 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22303 neon_three_args (rs == NS_QQQ);
22304 }
22305}
22306
22307static void
22308do_vmmla (void)
22309{
22310 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22311 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22312
22313 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22314 set_pred_insn_type (OUTSIDE_PRED_INSN);
22315
22316 neon_three_args (1);
22317}
22318
5287ad62
JB
22319\f
22320/* Overall per-instruction processing. */
22321
22322/* We need to be able to fix up arbitrary expressions in some statements.
22323 This is so that we can handle symbols that are an arbitrary distance from
22324 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22325 which returns part of an address in a form which will be valid for
22326 a data instruction. We do this by pushing the expression into a symbol
22327 in the expr_section, and creating a fix for that. */
22328
22329static void
22330fix_new_arm (fragS * frag,
22331 int where,
22332 short int size,
22333 expressionS * exp,
22334 int pc_rel,
22335 int reloc)
22336{
22337 fixS * new_fix;
22338
22339 switch (exp->X_op)
22340 {
22341 case O_constant:
6e7ce2cd
PB
22342 if (pc_rel)
22343 {
22344 /* Create an absolute valued symbol, so we have something to
477330fc
RM
22345 refer to in the object file. Unfortunately for us, gas's
22346 generic expression parsing will already have folded out
22347 any use of .set foo/.type foo %function that may have
22348 been used to set type information of the target location,
22349 that's being specified symbolically. We have to presume
22350 the user knows what they are doing. */
6e7ce2cd
PB
22351 char name[16 + 8];
22352 symbolS *symbol;
22353
22354 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22355
22356 symbol = symbol_find_or_make (name);
22357 S_SET_SEGMENT (symbol, absolute_section);
22358 symbol_set_frag (symbol, &zero_address_frag);
22359 S_SET_VALUE (symbol, exp->X_add_number);
22360 exp->X_op = O_symbol;
22361 exp->X_add_symbol = symbol;
22362 exp->X_add_number = 0;
22363 }
22364 /* FALLTHROUGH */
5287ad62
JB
22365 case O_symbol:
22366 case O_add:
22367 case O_subtract:
21d799b5 22368 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 22369 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22370 break;
22371
22372 default:
21d799b5 22373 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 22374 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
22375 break;
22376 }
22377
22378 /* Mark whether the fix is to a THUMB instruction, or an ARM
22379 instruction. */
22380 new_fix->tc_fix_data = thumb_mode;
22381}
22382
22383/* Create a frg for an instruction requiring relaxation. */
22384static void
22385output_relax_insn (void)
22386{
22387 char * to;
22388 symbolS *sym;
0110f2b8
PB
22389 int offset;
22390
6e1cb1a6
PB
22391 /* The size of the instruction is unknown, so tie the debug info to the
22392 start of the instruction. */
22393 dwarf2_emit_insn (0);
6e1cb1a6 22394
e2b0ab59 22395 switch (inst.relocs[0].exp.X_op)
0110f2b8
PB
22396 {
22397 case O_symbol:
e2b0ab59
AV
22398 sym = inst.relocs[0].exp.X_add_symbol;
22399 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22400 break;
22401 case O_constant:
22402 sym = NULL;
e2b0ab59 22403 offset = inst.relocs[0].exp.X_add_number;
0110f2b8
PB
22404 break;
22405 default:
e2b0ab59 22406 sym = make_expr_symbol (&inst.relocs[0].exp);
0110f2b8
PB
22407 offset = 0;
22408 break;
22409 }
22410 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22411 inst.relax, sym, offset, NULL/*offset, opcode*/);
22412 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
22413}
22414
22415/* Write a 32-bit thumb instruction to buf. */
22416static void
22417put_thumb32_insn (char * buf, unsigned long insn)
22418{
22419 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22420 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22421}
22422
b99bd4ef 22423static void
c19d1205 22424output_inst (const char * str)
b99bd4ef 22425{
c19d1205 22426 char * to = NULL;
b99bd4ef 22427
c19d1205 22428 if (inst.error)
b99bd4ef 22429 {
c19d1205 22430 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
22431 return;
22432 }
5f4273c7
NC
22433 if (inst.relax)
22434 {
22435 output_relax_insn ();
0110f2b8 22436 return;
5f4273c7 22437 }
c19d1205
ZW
22438 if (inst.size == 0)
22439 return;
b99bd4ef 22440
c19d1205 22441 to = frag_more (inst.size);
8dc2430f
NC
22442 /* PR 9814: Record the thumb mode into the current frag so that we know
22443 what type of NOP padding to use, if necessary. We override any previous
22444 setting so that if the mode has changed then the NOPS that we use will
22445 match the encoding of the last instruction in the frag. */
cd000bff 22446 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
22447
22448 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 22449 {
9c2799c2 22450 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 22451 put_thumb32_insn (to, inst.instruction);
b99bd4ef 22452 }
c19d1205 22453 else if (inst.size > INSN_SIZE)
b99bd4ef 22454 {
9c2799c2 22455 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
22456 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22457 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 22458 }
c19d1205
ZW
22459 else
22460 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 22461
e2b0ab59
AV
22462 int r;
22463 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22464 {
22465 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22466 fix_new_arm (frag_now, to - frag_now->fr_literal,
22467 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22468 inst.relocs[r].type);
22469 }
b99bd4ef 22470
c19d1205 22471 dwarf2_emit_insn (inst.size);
c19d1205 22472}
b99bd4ef 22473
e07e6e58
NC
22474static char *
22475output_it_inst (int cond, int mask, char * to)
22476{
22477 unsigned long instruction = 0xbf00;
22478
22479 mask &= 0xf;
22480 instruction |= mask;
22481 instruction |= cond << 4;
22482
22483 if (to == NULL)
22484 {
22485 to = frag_more (2);
22486#ifdef OBJ_ELF
22487 dwarf2_emit_insn (2);
22488#endif
22489 }
22490
22491 md_number_to_chars (to, instruction, 2);
22492
22493 return to;
22494}
22495
c19d1205
ZW
22496/* Tag values used in struct asm_opcode's tag field. */
22497enum opcode_tag
22498{
22499 OT_unconditional, /* Instruction cannot be conditionalized.
22500 The ARM condition field is still 0xE. */
22501 OT_unconditionalF, /* Instruction cannot be conditionalized
22502 and carries 0xF in its ARM condition field. */
22503 OT_csuffix, /* Instruction takes a conditional suffix. */
5ee91343
AV
22504 OT_csuffixF, /* Some forms of the instruction take a scalar
22505 conditional suffix, others place 0xF where the
22506 condition field would be, others take a vector
22507 conditional suffix. */
c19d1205
ZW
22508 OT_cinfix3, /* Instruction takes a conditional infix,
22509 beginning at character index 3. (In
22510 unified mode, it becomes a suffix.) */
088fa78e
KH
22511 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22512 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
22513 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22514 character index 3, even in unified mode. Used for
22515 legacy instructions where suffix and infix forms
22516 may be ambiguous. */
c19d1205 22517 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 22518 suffix or an infix at character index 3. */
c19d1205
ZW
22519 OT_odd_infix_unc, /* This is the unconditional variant of an
22520 instruction that takes a conditional infix
22521 at an unusual position. In unified mode,
22522 this variant will accept a suffix. */
22523 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22524 are the conditional variants of instructions that
22525 take conditional infixes in unusual positions.
22526 The infix appears at character index
22527 (tag - OT_odd_infix_0). These are not accepted
22528 in unified mode. */
22529};
b99bd4ef 22530
c19d1205
ZW
22531/* Subroutine of md_assemble, responsible for looking up the primary
22532 opcode from the mnemonic the user wrote. STR points to the
22533 beginning of the mnemonic.
22534
22535 This is not simply a hash table lookup, because of conditional
22536 variants. Most instructions have conditional variants, which are
22537 expressed with a _conditional affix_ to the mnemonic. If we were
22538 to encode each conditional variant as a literal string in the opcode
22539 table, it would have approximately 20,000 entries.
22540
22541 Most mnemonics take this affix as a suffix, and in unified syntax,
22542 'most' is upgraded to 'all'. However, in the divided syntax, some
22543 instructions take the affix as an infix, notably the s-variants of
22544 the arithmetic instructions. Of those instructions, all but six
22545 have the infix appear after the third character of the mnemonic.
22546
22547 Accordingly, the algorithm for looking up primary opcodes given
22548 an identifier is:
22549
22550 1. Look up the identifier in the opcode table.
22551 If we find a match, go to step U.
22552
22553 2. Look up the last two characters of the identifier in the
22554 conditions table. If we find a match, look up the first N-2
22555 characters of the identifier in the opcode table. If we
22556 find a match, go to step CE.
22557
22558 3. Look up the fourth and fifth characters of the identifier in
22559 the conditions table. If we find a match, extract those
22560 characters from the identifier, and look up the remaining
22561 characters in the opcode table. If we find a match, go
22562 to step CM.
22563
22564 4. Fail.
22565
22566 U. Examine the tag field of the opcode structure, in case this is
22567 one of the six instructions with its conditional infix in an
22568 unusual place. If it is, the tag tells us where to find the
22569 infix; look it up in the conditions table and set inst.cond
22570 accordingly. Otherwise, this is an unconditional instruction.
22571 Again set inst.cond accordingly. Return the opcode structure.
22572
22573 CE. Examine the tag field to make sure this is an instruction that
22574 should receive a conditional suffix. If it is not, fail.
22575 Otherwise, set inst.cond from the suffix we already looked up,
22576 and return the opcode structure.
22577
22578 CM. Examine the tag field to make sure this is an instruction that
22579 should receive a conditional infix after the third character.
22580 If it is not, fail. Otherwise, undo the edits to the current
22581 line of input and proceed as for case CE. */
22582
22583static const struct asm_opcode *
22584opcode_lookup (char **str)
22585{
22586 char *end, *base;
22587 char *affix;
22588 const struct asm_opcode *opcode;
22589 const struct asm_cond *cond;
e3cb604e 22590 char save[2];
c19d1205
ZW
22591
22592 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 22593 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 22594 for (base = end = *str; *end != '\0'; end++)
721a8186 22595 if (*end == ' ' || *end == '.')
c19d1205 22596 break;
b99bd4ef 22597
c19d1205 22598 if (end == base)
c921be7d 22599 return NULL;
b99bd4ef 22600
5287ad62 22601 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 22602 if (end[0] == '.')
b99bd4ef 22603 {
5287ad62 22604 int offset = 2;
5f4273c7 22605
267d2029 22606 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 22607 use. */
267d2029 22608 if (unified_syntax && end[1] == 'w')
c19d1205 22609 inst.size_req = 4;
267d2029 22610 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
22611 inst.size_req = 2;
22612 else
477330fc 22613 offset = 0;
5287ad62
JB
22614
22615 inst.vectype.elems = 0;
22616
22617 *str = end + offset;
b99bd4ef 22618
5f4273c7 22619 if (end[offset] == '.')
5287ad62 22620 {
267d2029 22621 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
22622 non-unified ARM syntax mode). */
22623 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 22624 return NULL;
477330fc 22625 }
5287ad62 22626 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 22627 return NULL;
b99bd4ef 22628 }
c19d1205
ZW
22629 else
22630 *str = end;
b99bd4ef 22631
c19d1205 22632 /* Look for unaffixed or special-case affixed mnemonic. */
629310ab 22633 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22634 end - base);
f3da8a96 22635 cond = NULL;
c19d1205 22636 if (opcode)
b99bd4ef 22637 {
c19d1205
ZW
22638 /* step U */
22639 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 22640 {
c19d1205
ZW
22641 inst.cond = COND_ALWAYS;
22642 return opcode;
b99bd4ef 22643 }
b99bd4ef 22644
278df34e 22645 if (warn_on_deprecated && unified_syntax)
5c3696f8 22646 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 22647 affix = base + (opcode->tag - OT_odd_infix_0);
629310ab 22648 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 22649 gas_assert (cond);
b99bd4ef 22650
c19d1205
ZW
22651 inst.cond = cond->value;
22652 return opcode;
22653 }
5ee91343
AV
22654 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22655 {
22656 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22657 */
22658 if (end - base < 2)
22659 return NULL;
22660 affix = end - 1;
629310ab
ML
22661 cond = (const struct asm_cond *) str_hash_find_n (arm_vcond_hsh, affix, 1);
22662 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22663 affix - base);
5ee91343
AV
22664 /* If this opcode can not be vector predicated then don't accept it with a
22665 vector predication code. */
22666 if (opcode && !opcode->mayBeVecPred)
22667 opcode = NULL;
22668 }
22669 if (!opcode || !cond)
22670 {
22671 /* Cannot have a conditional suffix on a mnemonic of less than two
22672 characters. */
22673 if (end - base < 3)
22674 return NULL;
b99bd4ef 22675
5ee91343
AV
22676 /* Look for suffixed mnemonic. */
22677 affix = end - 2;
629310ab
ML
22678 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22679 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22680 affix - base);
5ee91343 22681 }
b99bd4ef 22682
c19d1205
ZW
22683 if (opcode && cond)
22684 {
22685 /* step CE */
22686 switch (opcode->tag)
22687 {
e3cb604e
PB
22688 case OT_cinfix3_legacy:
22689 /* Ignore conditional suffixes matched on infix only mnemonics. */
22690 break;
22691
c19d1205 22692 case OT_cinfix3:
088fa78e 22693 case OT_cinfix3_deprecated:
c19d1205
ZW
22694 case OT_odd_infix_unc:
22695 if (!unified_syntax)
0198d5e6 22696 return NULL;
1a0670f3 22697 /* Fall through. */
c19d1205
ZW
22698
22699 case OT_csuffix:
477330fc 22700 case OT_csuffixF:
c19d1205
ZW
22701 case OT_csuf_or_in3:
22702 inst.cond = cond->value;
22703 return opcode;
22704
22705 case OT_unconditional:
22706 case OT_unconditionalF:
dfa9f0d5 22707 if (thumb_mode)
c921be7d 22708 inst.cond = cond->value;
dfa9f0d5
PB
22709 else
22710 {
c921be7d 22711 /* Delayed diagnostic. */
dfa9f0d5
PB
22712 inst.error = BAD_COND;
22713 inst.cond = COND_ALWAYS;
22714 }
c19d1205 22715 return opcode;
b99bd4ef 22716
c19d1205 22717 default:
c921be7d 22718 return NULL;
c19d1205
ZW
22719 }
22720 }
b99bd4ef 22721
c19d1205
ZW
22722 /* Cannot have a usual-position infix on a mnemonic of less than
22723 six characters (five would be a suffix). */
22724 if (end - base < 6)
c921be7d 22725 return NULL;
b99bd4ef 22726
c19d1205
ZW
22727 /* Look for infixed mnemonic in the usual position. */
22728 affix = base + 3;
629310ab 22729 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 22730 if (!cond)
c921be7d 22731 return NULL;
e3cb604e
PB
22732
22733 memcpy (save, affix, 2);
22734 memmove (affix, affix + 2, (end - affix) - 2);
629310ab 22735 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
fe0e921f 22736 (end - base) - 2);
e3cb604e
PB
22737 memmove (affix + 2, affix, (end - affix) - 2);
22738 memcpy (affix, save, 2);
22739
088fa78e
KH
22740 if (opcode
22741 && (opcode->tag == OT_cinfix3
22742 || opcode->tag == OT_cinfix3_deprecated
22743 || opcode->tag == OT_csuf_or_in3
22744 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 22745 {
c921be7d 22746 /* Step CM. */
278df34e 22747 if (warn_on_deprecated && unified_syntax
088fa78e
KH
22748 && (opcode->tag == OT_cinfix3
22749 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 22750 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
22751
22752 inst.cond = cond->value;
22753 return opcode;
b99bd4ef
NC
22754 }
22755
c921be7d 22756 return NULL;
b99bd4ef
NC
22757}
22758
e07e6e58
NC
22759/* This function generates an initial IT instruction, leaving its block
22760 virtually open for the new instructions. Eventually,
5ee91343 22761 the mask will be updated by now_pred_add_mask () each time
e07e6e58
NC
22762 a new instruction needs to be included in the IT block.
22763 Finally, the block is closed with close_automatic_it_block ().
22764 The block closure can be requested either from md_assemble (),
22765 a tencode (), or due to a label hook. */
22766
22767static void
22768new_automatic_it_block (int cond)
22769{
5ee91343
AV
22770 now_pred.state = AUTOMATIC_PRED_BLOCK;
22771 now_pred.mask = 0x18;
22772 now_pred.cc = cond;
22773 now_pred.block_length = 1;
cd000bff 22774 mapping_state (MAP_THUMB);
5ee91343
AV
22775 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22776 now_pred.warn_deprecated = FALSE;
22777 now_pred.insn_cond = TRUE;
e07e6e58
NC
22778}
22779
22780/* Close an automatic IT block.
22781 See comments in new_automatic_it_block (). */
22782
22783static void
22784close_automatic_it_block (void)
22785{
5ee91343
AV
22786 now_pred.mask = 0x10;
22787 now_pred.block_length = 0;
e07e6e58
NC
22788}
22789
22790/* Update the mask of the current automatically-generated IT
22791 instruction. See comments in new_automatic_it_block (). */
22792
22793static void
5ee91343 22794now_pred_add_mask (int cond)
e07e6e58
NC
22795{
22796#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22797#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 22798 | ((bitvalue) << (nbit)))
e07e6e58 22799 const int resulting_bit = (cond & 1);
c921be7d 22800
5ee91343
AV
22801 now_pred.mask &= 0xf;
22802 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22803 resulting_bit,
5ee91343
AV
22804 (5 - now_pred.block_length));
22805 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
477330fc 22806 1,
5ee91343
AV
22807 ((5 - now_pred.block_length) - 1));
22808 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
e07e6e58
NC
22809
22810#undef CLEAR_BIT
22811#undef SET_BIT_VALUE
e07e6e58
NC
22812}
22813
22814/* The IT blocks handling machinery is accessed through the these functions:
22815 it_fsm_pre_encode () from md_assemble ()
5ee91343
AV
22816 set_pred_insn_type () optional, from the tencode functions
22817 set_pred_insn_type_last () ditto
22818 in_pred_block () ditto
e07e6e58 22819 it_fsm_post_encode () from md_assemble ()
33eaf5de 22820 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
22821
22822 Rationale:
22823 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
22824 initializing the IT insn type with a generic initial value depending
22825 on the inst.condition.
e07e6e58 22826 2) During the tencode function, two things may happen:
477330fc 22827 a) The tencode function overrides the IT insn type by
5ee91343
AV
22828 calling either set_pred_insn_type (type) or
22829 set_pred_insn_type_last ().
477330fc 22830 b) The tencode function queries the IT block state by
5ee91343 22831 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
477330fc 22832
5ee91343
AV
22833 Both set_pred_insn_type and in_pred_block run the internal FSM state
22834 handling function (handle_pred_state), because: a) setting the IT insn
477330fc
RM
22835 type may incur in an invalid state (exiting the function),
22836 and b) querying the state requires the FSM to be updated.
22837 Specifically we want to avoid creating an IT block for conditional
22838 branches, so it_fsm_pre_encode is actually a guess and we can't
22839 determine whether an IT block is required until the tencode () routine
22840 has decided what type of instruction this actually it.
5ee91343
AV
22841 Because of this, if set_pred_insn_type and in_pred_block have to be
22842 used, set_pred_insn_type has to be called first.
477330fc 22843
5ee91343
AV
22844 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22845 that determines the insn IT type depending on the inst.cond code.
477330fc
RM
22846 When a tencode () routine encodes an instruction that can be
22847 either outside an IT block, or, in the case of being inside, has to be
5ee91343 22848 the last one, set_pred_insn_type_last () will determine the proper
477330fc 22849 IT instruction type based on the inst.cond code. Otherwise,
5ee91343 22850 set_pred_insn_type can be called for overriding that logic or
477330fc
RM
22851 for covering other cases.
22852
5ee91343
AV
22853 Calling handle_pred_state () may not transition the IT block state to
22854 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
477330fc 22855 still queried. Instead, if the FSM determines that the state should
5ee91343 22856 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
477330fc
RM
22857 after the tencode () function: that's what it_fsm_post_encode () does.
22858
5ee91343 22859 Since in_pred_block () calls the state handling function to get an
477330fc
RM
22860 updated state, an error may occur (due to invalid insns combination).
22861 In that case, inst.error is set.
22862 Therefore, inst.error has to be checked after the execution of
22863 the tencode () routine.
e07e6e58
NC
22864
22865 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc 22866 any pending state change (if any) that didn't take place in
5ee91343 22867 handle_pred_state () as explained above. */
e07e6e58
NC
22868
22869static void
22870it_fsm_pre_encode (void)
22871{
22872 if (inst.cond != COND_ALWAYS)
5ee91343 22873 inst.pred_insn_type = INSIDE_IT_INSN;
e07e6e58 22874 else
5ee91343 22875 inst.pred_insn_type = OUTSIDE_PRED_INSN;
e07e6e58 22876
5ee91343 22877 now_pred.state_handled = 0;
e07e6e58
NC
22878}
22879
22880/* IT state FSM handling function. */
5ee91343
AV
22881/* MVE instructions and non-MVE instructions are handled differently because of
22882 the introduction of VPT blocks.
22883 Specifications say that any non-MVE instruction inside a VPT block is
22884 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22885 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
35c228db 22886 few exceptions we have MVE_UNPREDICABLE_INSN.
5ee91343
AV
22887 The error messages provided depending on the different combinations possible
22888 are described in the cases below:
22889 For 'most' MVE instructions:
22890 1) In an IT block, with an IT code: syntax error
22891 2) In an IT block, with a VPT code: error: must be in a VPT block
22892 3) In an IT block, with no code: warning: UNPREDICTABLE
22893 4) In a VPT block, with an IT code: syntax error
22894 5) In a VPT block, with a VPT code: OK!
22895 6) In a VPT block, with no code: error: missing code
22896 7) Outside a pred block, with an IT code: error: syntax error
22897 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22898 9) Outside a pred block, with no code: OK!
22899 For non-MVE instructions:
22900 10) In an IT block, with an IT code: OK!
22901 11) In an IT block, with a VPT code: syntax error
22902 12) In an IT block, with no code: error: missing code
22903 13) In a VPT block, with an IT code: error: should be in an IT block
22904 14) In a VPT block, with a VPT code: syntax error
22905 15) In a VPT block, with no code: UNPREDICTABLE
22906 16) Outside a pred block, with an IT code: error: should be in an IT block
22907 17) Outside a pred block, with a VPT code: syntax error
22908 18) Outside a pred block, with no code: OK!
22909 */
22910
e07e6e58
NC
22911
22912static int
5ee91343 22913handle_pred_state (void)
e07e6e58 22914{
5ee91343
AV
22915 now_pred.state_handled = 1;
22916 now_pred.insn_cond = FALSE;
e07e6e58 22917
5ee91343 22918 switch (now_pred.state)
e07e6e58 22919 {
5ee91343
AV
22920 case OUTSIDE_PRED_BLOCK:
22921 switch (inst.pred_insn_type)
e07e6e58 22922 {
35c228db 22923 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
22924 case MVE_OUTSIDE_PRED_INSN:
22925 if (inst.cond < COND_ALWAYS)
22926 {
22927 /* Case 7: Outside a pred block, with an IT code: error: syntax
22928 error. */
22929 inst.error = BAD_SYNTAX;
22930 return FAIL;
22931 }
22932 /* Case 9: Outside a pred block, with no code: OK! */
22933 break;
22934 case OUTSIDE_PRED_INSN:
22935 if (inst.cond > COND_ALWAYS)
22936 {
22937 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22938 */
22939 inst.error = BAD_SYNTAX;
22940 return FAIL;
22941 }
22942 /* Case 18: Outside a pred block, with no code: OK! */
e07e6e58
NC
22943 break;
22944
5ee91343
AV
22945 case INSIDE_VPT_INSN:
22946 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22947 a VPT block. */
22948 inst.error = BAD_OUT_VPT;
22949 return FAIL;
22950
e07e6e58
NC
22951 case INSIDE_IT_INSN:
22952 case INSIDE_IT_LAST_INSN:
5ee91343 22953 if (inst.cond < COND_ALWAYS)
e07e6e58 22954 {
5ee91343
AV
22955 /* Case 16: Outside a pred block, with an IT code: error: should
22956 be in an IT block. */
22957 if (thumb_mode == 0)
e07e6e58 22958 {
5ee91343
AV
22959 if (unified_syntax
22960 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22961 as_tsktsk (_("Warning: conditional outside an IT block"\
22962 " for Thumb."));
e07e6e58
NC
22963 }
22964 else
22965 {
5ee91343
AV
22966 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22967 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22968 {
22969 /* Automatically generate the IT instruction. */
22970 new_automatic_it_block (inst.cond);
22971 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22972 close_automatic_it_block ();
22973 }
22974 else
22975 {
22976 inst.error = BAD_OUT_IT;
22977 return FAIL;
22978 }
e07e6e58 22979 }
5ee91343 22980 break;
e07e6e58 22981 }
5ee91343
AV
22982 else if (inst.cond > COND_ALWAYS)
22983 {
22984 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22985 */
22986 inst.error = BAD_SYNTAX;
22987 return FAIL;
22988 }
22989 else
22990 gas_assert (0);
e07e6e58
NC
22991 case IF_INSIDE_IT_LAST_INSN:
22992 case NEUTRAL_IT_INSN:
22993 break;
22994
5ee91343
AV
22995 case VPT_INSN:
22996 if (inst.cond != COND_ALWAYS)
22997 first_error (BAD_SYNTAX);
22998 now_pred.state = MANUAL_PRED_BLOCK;
22999 now_pred.block_length = 0;
23000 now_pred.type = VECTOR_PRED;
23001 now_pred.cc = 0;
23002 break;
e07e6e58 23003 case IT_INSN:
5ee91343
AV
23004 now_pred.state = MANUAL_PRED_BLOCK;
23005 now_pred.block_length = 0;
23006 now_pred.type = SCALAR_PRED;
e07e6e58
NC
23007 break;
23008 }
23009 break;
23010
5ee91343 23011 case AUTOMATIC_PRED_BLOCK:
e07e6e58
NC
23012 /* Three things may happen now:
23013 a) We should increment current it block size;
23014 b) We should close current it block (closing insn or 4 insns);
23015 c) We should close current it block and start a new one (due
23016 to incompatible conditions or
23017 4 insns-length block reached). */
23018
5ee91343 23019 switch (inst.pred_insn_type)
e07e6e58 23020 {
5ee91343
AV
23021 case INSIDE_VPT_INSN:
23022 case VPT_INSN:
35c228db 23023 case MVE_UNPREDICABLE_INSN:
5ee91343
AV
23024 case MVE_OUTSIDE_PRED_INSN:
23025 gas_assert (0);
23026 case OUTSIDE_PRED_INSN:
2b0f3761 23027 /* The closure of the block shall happen immediately,
5ee91343 23028 so any in_pred_block () call reports the block as closed. */
e07e6e58
NC
23029 force_automatic_it_block_close ();
23030 break;
23031
23032 case INSIDE_IT_INSN:
23033 case INSIDE_IT_LAST_INSN:
23034 case IF_INSIDE_IT_LAST_INSN:
5ee91343 23035 now_pred.block_length++;
e07e6e58 23036
5ee91343
AV
23037 if (now_pred.block_length > 4
23038 || !now_pred_compatible (inst.cond))
e07e6e58
NC
23039 {
23040 force_automatic_it_block_close ();
5ee91343 23041 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
e07e6e58
NC
23042 new_automatic_it_block (inst.cond);
23043 }
23044 else
23045 {
5ee91343
AV
23046 now_pred.insn_cond = TRUE;
23047 now_pred_add_mask (inst.cond);
e07e6e58
NC
23048 }
23049
5ee91343
AV
23050 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23051 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23052 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
e07e6e58
NC
23053 close_automatic_it_block ();
23054 break;
23055
4934a27c 23056 /* Fallthrough. */
e07e6e58 23057 case NEUTRAL_IT_INSN:
5ee91343
AV
23058 now_pred.block_length++;
23059 now_pred.insn_cond = TRUE;
e07e6e58 23060
5ee91343 23061 if (now_pred.block_length > 4)
e07e6e58
NC
23062 force_automatic_it_block_close ();
23063 else
5ee91343 23064 now_pred_add_mask (now_pred.cc & 1);
e07e6e58
NC
23065 break;
23066
23067 case IT_INSN:
23068 close_automatic_it_block ();
5ee91343 23069 now_pred.state = MANUAL_PRED_BLOCK;
e07e6e58
NC
23070 break;
23071 }
23072 break;
23073
5ee91343 23074 case MANUAL_PRED_BLOCK:
e07e6e58 23075 {
7af67752
AM
23076 unsigned int cond;
23077 int is_last;
5ee91343 23078 if (now_pred.type == SCALAR_PRED)
e07e6e58 23079 {
5ee91343
AV
23080 /* Check conditional suffixes. */
23081 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23082 now_pred.mask <<= 1;
23083 now_pred.mask &= 0x1f;
23084 is_last = (now_pred.mask == 0x10);
23085 }
23086 else
23087 {
23088 now_pred.cc ^= (now_pred.mask >> 4);
23089 cond = now_pred.cc + 0xf;
23090 now_pred.mask <<= 1;
23091 now_pred.mask &= 0x1f;
23092 is_last = now_pred.mask == 0x10;
23093 }
23094 now_pred.insn_cond = TRUE;
e07e6e58 23095
5ee91343
AV
23096 switch (inst.pred_insn_type)
23097 {
23098 case OUTSIDE_PRED_INSN:
23099 if (now_pred.type == SCALAR_PRED)
23100 {
23101 if (inst.cond == COND_ALWAYS)
23102 {
23103 /* Case 12: In an IT block, with no code: error: missing
23104 code. */
23105 inst.error = BAD_NOT_IT;
23106 return FAIL;
23107 }
23108 else if (inst.cond > COND_ALWAYS)
23109 {
23110 /* Case 11: In an IT block, with a VPT code: syntax error.
23111 */
23112 inst.error = BAD_SYNTAX;
23113 return FAIL;
23114 }
23115 else if (thumb_mode)
23116 {
23117 /* This is for some special cases where a non-MVE
23118 instruction is not allowed in an IT block, such as cbz,
23119 but are put into one with a condition code.
23120 You could argue this should be a syntax error, but we
23121 gave the 'not allowed in IT block' diagnostic in the
23122 past so we will keep doing so. */
23123 inst.error = BAD_NOT_IT;
23124 return FAIL;
23125 }
23126 break;
23127 }
23128 else
23129 {
23130 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23131 as_tsktsk (MVE_NOT_VPT);
23132 return SUCCESS;
23133 }
23134 case MVE_OUTSIDE_PRED_INSN:
23135 if (now_pred.type == SCALAR_PRED)
23136 {
23137 if (inst.cond == COND_ALWAYS)
23138 {
23139 /* Case 3: In an IT block, with no code: warning:
23140 UNPREDICTABLE. */
23141 as_tsktsk (MVE_NOT_IT);
23142 return SUCCESS;
23143 }
23144 else if (inst.cond < COND_ALWAYS)
23145 {
23146 /* Case 1: In an IT block, with an IT code: syntax error.
23147 */
23148 inst.error = BAD_SYNTAX;
23149 return FAIL;
23150 }
23151 else
23152 gas_assert (0);
23153 }
23154 else
23155 {
23156 if (inst.cond < COND_ALWAYS)
23157 {
23158 /* Case 4: In a VPT block, with an IT code: syntax error.
23159 */
23160 inst.error = BAD_SYNTAX;
23161 return FAIL;
23162 }
23163 else if (inst.cond == COND_ALWAYS)
23164 {
23165 /* Case 6: In a VPT block, with no code: error: missing
23166 code. */
23167 inst.error = BAD_NOT_VPT;
23168 return FAIL;
23169 }
23170 else
23171 {
23172 gas_assert (0);
23173 }
23174 }
35c228db
AV
23175 case MVE_UNPREDICABLE_INSN:
23176 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23177 return SUCCESS;
e07e6e58 23178 case INSIDE_IT_INSN:
5ee91343 23179 if (inst.cond > COND_ALWAYS)
e07e6e58 23180 {
5ee91343
AV
23181 /* Case 11: In an IT block, with a VPT code: syntax error. */
23182 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23183 inst.error = BAD_SYNTAX;
23184 return FAIL;
23185 }
23186 else if (now_pred.type == SCALAR_PRED)
23187 {
23188 /* Case 10: In an IT block, with an IT code: OK! */
23189 if (cond != inst.cond)
23190 {
23191 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23192 BAD_VPT_COND;
23193 return FAIL;
23194 }
23195 }
23196 else
23197 {
23198 /* Case 13: In a VPT block, with an IT code: error: should be
23199 in an IT block. */
23200 inst.error = BAD_OUT_IT;
e07e6e58
NC
23201 return FAIL;
23202 }
23203 break;
23204
5ee91343
AV
23205 case INSIDE_VPT_INSN:
23206 if (now_pred.type == SCALAR_PRED)
23207 {
23208 /* Case 2: In an IT block, with a VPT code: error: must be in a
23209 VPT block. */
23210 inst.error = BAD_OUT_VPT;
23211 return FAIL;
23212 }
23213 /* Case 5: In a VPT block, with a VPT code: OK! */
23214 else if (cond != inst.cond)
23215 {
23216 inst.error = BAD_VPT_COND;
23217 return FAIL;
23218 }
23219 break;
e07e6e58
NC
23220 case INSIDE_IT_LAST_INSN:
23221 case IF_INSIDE_IT_LAST_INSN:
5ee91343
AV
23222 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23223 {
23224 /* Case 4: In a VPT block, with an IT code: syntax error. */
23225 /* Case 11: In an IT block, with a VPT code: syntax error. */
23226 inst.error = BAD_SYNTAX;
23227 return FAIL;
23228 }
23229 else if (cond != inst.cond)
e07e6e58
NC
23230 {
23231 inst.error = BAD_IT_COND;
23232 return FAIL;
23233 }
23234 if (!is_last)
23235 {
23236 inst.error = BAD_BRANCH;
23237 return FAIL;
23238 }
23239 break;
23240
23241 case NEUTRAL_IT_INSN:
5ee91343
AV
23242 /* The BKPT instruction is unconditional even in a IT or VPT
23243 block. */
e07e6e58
NC
23244 break;
23245
23246 case IT_INSN:
5ee91343
AV
23247 if (now_pred.type == SCALAR_PRED)
23248 {
23249 inst.error = BAD_IT_IT;
23250 return FAIL;
23251 }
23252 /* fall through. */
23253 case VPT_INSN:
23254 if (inst.cond == COND_ALWAYS)
23255 {
23256 /* Executing a VPT/VPST instruction inside an IT block or a
23257 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23258 */
23259 if (now_pred.type == SCALAR_PRED)
23260 as_tsktsk (MVE_NOT_IT);
23261 else
23262 as_tsktsk (MVE_NOT_VPT);
23263 return SUCCESS;
23264 }
23265 else
23266 {
23267 /* VPT/VPST do not accept condition codes. */
23268 inst.error = BAD_SYNTAX;
23269 return FAIL;
23270 }
e07e6e58 23271 }
5ee91343 23272 }
e07e6e58
NC
23273 break;
23274 }
23275
23276 return SUCCESS;
23277}
23278
5a01bb1d
MGD
23279struct depr_insn_mask
23280{
23281 unsigned long pattern;
23282 unsigned long mask;
23283 const char* description;
23284};
23285
23286/* List of 16-bit instruction patterns deprecated in an IT block in
23287 ARMv8. */
23288static const struct depr_insn_mask depr_it_insns[] = {
23289 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23290 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23291 { 0xa000, 0xb800, N_("ADR") },
23292 { 0x4800, 0xf800, N_("Literal loads") },
23293 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23294 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
23295 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23296 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23297 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
23298 { 0, 0, NULL }
23299};
23300
e07e6e58
NC
23301static void
23302it_fsm_post_encode (void)
23303{
23304 int is_last;
23305
5ee91343
AV
23306 if (!now_pred.state_handled)
23307 handle_pred_state ();
e07e6e58 23308
5ee91343 23309 if (now_pred.insn_cond
24f19ccb 23310 && warn_on_restrict_it
5ee91343 23311 && !now_pred.warn_deprecated
5a01bb1d 23312 && warn_on_deprecated
164446e0
AF
23313 && (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23314 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8r))
df9909b8 23315 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
23316 {
23317 if (inst.instruction >= 0x10000)
23318 {
5c3696f8 23319 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 23320 "performance deprecated in ARMv8-A and ARMv8-R"));
5ee91343 23321 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23322 }
23323 else
23324 {
23325 const struct depr_insn_mask *p = depr_it_insns;
23326
23327 while (p->mask != 0)
23328 {
23329 if ((inst.instruction & p->mask) == p->pattern)
23330 {
df9909b8
TP
23331 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23332 "instructions of the following class are "
23333 "performance deprecated in ARMv8-A and "
23334 "ARMv8-R: %s"), p->description);
5ee91343 23335 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23336 break;
23337 }
23338
23339 ++p;
23340 }
23341 }
23342
5ee91343 23343 if (now_pred.block_length > 1)
5a01bb1d 23344 {
5c3696f8 23345 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
23346 "instruction are performance deprecated in ARMv8-A and "
23347 "ARMv8-R"));
5ee91343 23348 now_pred.warn_deprecated = TRUE;
5a01bb1d
MGD
23349 }
23350 }
23351
5ee91343
AV
23352 is_last = (now_pred.mask == 0x10);
23353 if (is_last)
23354 {
23355 now_pred.state = OUTSIDE_PRED_BLOCK;
23356 now_pred.mask = 0;
23357 }
e07e6e58
NC
23358}
23359
23360static void
23361force_automatic_it_block_close (void)
23362{
5ee91343 23363 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
e07e6e58
NC
23364 {
23365 close_automatic_it_block ();
5ee91343
AV
23366 now_pred.state = OUTSIDE_PRED_BLOCK;
23367 now_pred.mask = 0;
e07e6e58
NC
23368 }
23369}
23370
23371static int
5ee91343 23372in_pred_block (void)
e07e6e58 23373{
5ee91343
AV
23374 if (!now_pred.state_handled)
23375 handle_pred_state ();
e07e6e58 23376
5ee91343 23377 return now_pred.state != OUTSIDE_PRED_BLOCK;
e07e6e58
NC
23378}
23379
ff8646ee
TP
23380/* Whether OPCODE only has T32 encoding. Since this function is only used by
23381 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23382 here, hence the "known" in the function name. */
fc289b0a
TP
23383
23384static bfd_boolean
ff8646ee 23385known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
23386{
23387 /* Original Thumb-1 wide instruction. */
23388 if (opcode->tencode == do_t_blx
23389 || opcode->tencode == do_t_branch23
23390 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23391 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23392 return TRUE;
23393
16a1fa25
TP
23394 /* Wide-only instruction added to ARMv8-M Baseline. */
23395 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
23396 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23397 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23398 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23399 return TRUE;
23400
23401 return FALSE;
23402}
23403
23404/* Whether wide instruction variant can be used if available for a valid OPCODE
23405 in ARCH. */
23406
23407static bfd_boolean
23408t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23409{
23410 if (known_t32_only_insn (opcode))
23411 return TRUE;
23412
23413 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23414 of variant T3 of B.W is checked in do_t_branch. */
23415 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23416 && opcode->tencode == do_t_branch)
23417 return TRUE;
23418
bada4342
JW
23419 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23420 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23421 && opcode->tencode == do_t_mov_cmp
23422 /* Make sure CMP instruction is not affected. */
23423 && opcode->aencode == do_mov)
23424 return TRUE;
23425
ff8646ee
TP
23426 /* Wide instruction variants of all instructions with narrow *and* wide
23427 variants become available with ARMv6t2. Other opcodes are either
23428 narrow-only or wide-only and are thus available if OPCODE is valid. */
23429 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23430 return TRUE;
23431
23432 /* OPCODE with narrow only instruction variant or wide variant not
23433 available. */
fc289b0a
TP
23434 return FALSE;
23435}
23436
c19d1205
ZW
23437void
23438md_assemble (char *str)
b99bd4ef 23439{
c19d1205
ZW
23440 char *p = str;
23441 const struct asm_opcode * opcode;
b99bd4ef 23442
c19d1205
ZW
23443 /* Align the previous label if needed. */
23444 if (last_label_seen != NULL)
b99bd4ef 23445 {
c19d1205
ZW
23446 symbol_set_frag (last_label_seen, frag_now);
23447 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23448 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
23449 }
23450
c19d1205 23451 memset (&inst, '\0', sizeof (inst));
e2b0ab59
AV
23452 int r;
23453 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23454 inst.relocs[r].type = BFD_RELOC_UNUSED;
b99bd4ef 23455
c19d1205
ZW
23456 opcode = opcode_lookup (&p);
23457 if (!opcode)
b99bd4ef 23458 {
c19d1205 23459 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 23460 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 23461 if (! create_register_alias (str, p)
477330fc 23462 && ! create_neon_reg_alias (str, p))
c19d1205 23463 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 23464
b99bd4ef
NC
23465 return;
23466 }
23467
278df34e 23468 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 23469 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 23470
037e8744
JB
23471 /* The value which unconditional instructions should have in place of the
23472 condition field. */
7af67752 23473 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1u;
037e8744 23474
c19d1205 23475 if (thumb_mode)
b99bd4ef 23476 {
e74cfd16 23477 arm_feature_set variant;
8f06b2d8
PB
23478
23479 variant = cpu_variant;
23480 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
23481 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23482 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 23483 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
23484 if (!opcode->tvariant
23485 || (thumb_mode == 1
23486 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 23487 {
173205ca
TP
23488 if (opcode->tencode == do_t_swi)
23489 as_bad (_("SVC is not permitted on this architecture"));
23490 else
23491 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
23492 return;
23493 }
c19d1205
ZW
23494 if (inst.cond != COND_ALWAYS && !unified_syntax
23495 && opcode->tencode != do_t_branch)
b99bd4ef 23496 {
c19d1205 23497 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
23498 return;
23499 }
23500
fc289b0a
TP
23501 /* Two things are addressed here:
23502 1) Implicit require narrow instructions on Thumb-1.
23503 This avoids relaxation accidentally introducing Thumb-2
23504 instructions.
23505 2) Reject wide instructions in non Thumb-2 cores.
23506
23507 Only instructions with narrow and wide variants need to be handled
23508 but selecting all non wide-only instructions is easier. */
23509 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 23510 && !t32_insn_ok (variant, opcode))
076d447c 23511 {
fc289b0a
TP
23512 if (inst.size_req == 0)
23513 inst.size_req = 2;
23514 else if (inst.size_req == 4)
752d5da4 23515 {
ff8646ee
TP
23516 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23517 as_bad (_("selected processor does not support 32bit wide "
23518 "variant of instruction `%s'"), str);
23519 else
23520 as_bad (_("selected processor does not support `%s' in "
23521 "Thumb-2 mode"), str);
fc289b0a 23522 return;
752d5da4 23523 }
076d447c
PB
23524 }
23525
c19d1205
ZW
23526 inst.instruction = opcode->tvalue;
23527
5be8be5d 23528 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc 23529 {
5ee91343 23530 /* Prepare the pred_insn_type for those encodings that don't set
477330fc
RM
23531 it. */
23532 it_fsm_pre_encode ();
c19d1205 23533
477330fc 23534 opcode->tencode ();
e07e6e58 23535
477330fc
RM
23536 it_fsm_post_encode ();
23537 }
e27ec89e 23538
0110f2b8 23539 if (!(inst.error || inst.relax))
b99bd4ef 23540 {
9c2799c2 23541 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
23542 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23543 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 23544 {
c19d1205 23545 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
23546 return;
23547 }
23548 }
076d447c
PB
23549
23550 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 23551 instruction. */
9c2799c2 23552 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 23553
e74cfd16
PB
23554 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23555 *opcode->tvariant);
ee065d83 23556 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
23557 set those bits when Thumb-2 32-bit instructions are seen. The impact
23558 of relaxable instructions will be considered later after we finish all
23559 relaxation. */
ff8646ee
TP
23560 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23561 variant = arm_arch_none;
23562 else
23563 variant = cpu_variant;
23564 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
23565 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23566 arm_ext_v6t2);
cd000bff 23567
88714cb8
DG
23568 check_neon_suffixes;
23569
cd000bff 23570 if (!inst.error)
c877a2f2
NC
23571 {
23572 mapping_state (MAP_THUMB);
23573 }
c19d1205 23574 }
3e9e4fcf 23575 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 23576 {
845b51d6
PB
23577 bfd_boolean is_bx;
23578
23579 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23580 is_bx = (opcode->aencode == do_bx);
23581
c19d1205 23582 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
23583 if (!(is_bx && fix_v4bx)
23584 && !(opcode->avariant &&
23585 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 23586 {
84b52b66 23587 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 23588 return;
b99bd4ef 23589 }
c19d1205 23590 if (inst.size_req)
b99bd4ef 23591 {
c19d1205
ZW
23592 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23593 return;
b99bd4ef
NC
23594 }
23595
c19d1205
ZW
23596 inst.instruction = opcode->avalue;
23597 if (opcode->tag == OT_unconditionalF)
eff0bc54 23598 inst.instruction |= 0xFU << 28;
c19d1205
ZW
23599 else
23600 inst.instruction |= inst.cond << 28;
23601 inst.size = INSN_SIZE;
5be8be5d 23602 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
23603 {
23604 it_fsm_pre_encode ();
23605 opcode->aencode ();
23606 it_fsm_post_encode ();
23607 }
ee065d83 23608 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 23609 on a hypothetical non-thumb v5 core. */
845b51d6 23610 if (is_bx)
e74cfd16 23611 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 23612 else
e74cfd16
PB
23613 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23614 *opcode->avariant);
88714cb8
DG
23615
23616 check_neon_suffixes;
23617
cd000bff 23618 if (!inst.error)
c877a2f2
NC
23619 {
23620 mapping_state (MAP_ARM);
23621 }
b99bd4ef 23622 }
3e9e4fcf
JB
23623 else
23624 {
23625 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23626 "-- `%s'"), str);
23627 return;
23628 }
c19d1205
ZW
23629 output_inst (str);
23630}
b99bd4ef 23631
e07e6e58 23632static void
5ee91343 23633check_pred_blocks_finished (void)
e07e6e58
NC
23634{
23635#ifdef OBJ_ELF
23636 asection *sect;
23637
23638 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
5ee91343
AV
23639 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23640 == MANUAL_PRED_BLOCK)
e07e6e58 23641 {
5ee91343
AV
23642 if (now_pred.type == SCALAR_PRED)
23643 as_warn (_("section '%s' finished with an open IT block."),
23644 sect->name);
23645 else
23646 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23647 sect->name);
e07e6e58
NC
23648 }
23649#else
5ee91343
AV
23650 if (now_pred.state == MANUAL_PRED_BLOCK)
23651 {
23652 if (now_pred.type == SCALAR_PRED)
23653 as_warn (_("file finished with an open IT block."));
23654 else
23655 as_warn (_("file finished with an open VPT/VPST block."));
23656 }
e07e6e58
NC
23657#endif
23658}
23659
c19d1205
ZW
23660/* Various frobbings of labels and their addresses. */
23661
23662void
23663arm_start_line_hook (void)
23664{
23665 last_label_seen = NULL;
b99bd4ef
NC
23666}
23667
c19d1205
ZW
23668void
23669arm_frob_label (symbolS * sym)
b99bd4ef 23670{
c19d1205 23671 last_label_seen = sym;
b99bd4ef 23672
c19d1205 23673 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 23674
c19d1205
ZW
23675#if defined OBJ_COFF || defined OBJ_ELF
23676 ARM_SET_INTERWORK (sym, support_interwork);
23677#endif
b99bd4ef 23678
e07e6e58
NC
23679 force_automatic_it_block_close ();
23680
5f4273c7 23681 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
23682 as Thumb functions. This is because these labels, whilst
23683 they exist inside Thumb code, are not the entry points for
23684 possible ARM->Thumb calls. Also, these labels can be used
23685 as part of a computed goto or switch statement. eg gcc
23686 can generate code that looks like this:
b99bd4ef 23687
c19d1205
ZW
23688 ldr r2, [pc, .Laaa]
23689 lsl r3, r3, #2
23690 ldr r2, [r3, r2]
23691 mov pc, r2
b99bd4ef 23692
c19d1205
ZW
23693 .Lbbb: .word .Lxxx
23694 .Lccc: .word .Lyyy
23695 ..etc...
23696 .Laaa: .word Lbbb
b99bd4ef 23697
c19d1205
ZW
23698 The first instruction loads the address of the jump table.
23699 The second instruction converts a table index into a byte offset.
23700 The third instruction gets the jump address out of the table.
23701 The fourth instruction performs the jump.
b99bd4ef 23702
c19d1205
ZW
23703 If the address stored at .Laaa is that of a symbol which has the
23704 Thumb_Func bit set, then the linker will arrange for this address
23705 to have the bottom bit set, which in turn would mean that the
23706 address computation performed by the third instruction would end
23707 up with the bottom bit set. Since the ARM is capable of unaligned
23708 word loads, the instruction would then load the incorrect address
23709 out of the jump table, and chaos would ensue. */
23710 if (label_is_thumb_function_name
23711 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
fd361982 23712 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
b99bd4ef 23713 {
c19d1205
ZW
23714 /* When the address of a Thumb function is taken the bottom
23715 bit of that address should be set. This will allow
23716 interworking between Arm and Thumb functions to work
23717 correctly. */
b99bd4ef 23718
c19d1205 23719 THUMB_SET_FUNC (sym, 1);
b99bd4ef 23720
c19d1205 23721 label_is_thumb_function_name = FALSE;
b99bd4ef 23722 }
07a53e5c 23723
07a53e5c 23724 dwarf2_emit_label (sym);
b99bd4ef
NC
23725}
23726
c921be7d 23727bfd_boolean
c19d1205 23728arm_data_in_code (void)
b99bd4ef 23729{
c19d1205 23730 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 23731 {
c19d1205
ZW
23732 *input_line_pointer = '/';
23733 input_line_pointer += 5;
23734 *input_line_pointer = 0;
c921be7d 23735 return TRUE;
b99bd4ef
NC
23736 }
23737
c921be7d 23738 return FALSE;
b99bd4ef
NC
23739}
23740
c19d1205
ZW
23741char *
23742arm_canonicalize_symbol_name (char * name)
b99bd4ef 23743{
c19d1205 23744 int len;
b99bd4ef 23745
c19d1205
ZW
23746 if (thumb_mode && (len = strlen (name)) > 5
23747 && streq (name + len - 5, "/data"))
23748 *(name + len - 5) = 0;
b99bd4ef 23749
c19d1205 23750 return name;
b99bd4ef 23751}
c19d1205
ZW
23752\f
23753/* Table of all register names defined by default. The user can
23754 define additional names with .req. Note that all register names
23755 should appear in both upper and lowercase variants. Some registers
23756 also have mixed-case names. */
b99bd4ef 23757
dcbf9037 23758#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 23759#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 23760#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
23761#define REGSET(p,t) \
23762 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23763 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23764 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23765 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
23766#define REGSETH(p,t) \
23767 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23768 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23769 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23770 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23771#define REGSET2(p,t) \
23772 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23773 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23774 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23775 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
23776#define SPLRBANK(base,bank,t) \
23777 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23778 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23779 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23780 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23781 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23782 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 23783
c19d1205 23784static const struct reg_entry reg_names[] =
7ed4c4c5 23785{
c19d1205
ZW
23786 /* ARM integer registers. */
23787 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 23788
c19d1205
ZW
23789 /* ATPCS synonyms. */
23790 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23791 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23792 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 23793
c19d1205
ZW
23794 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23795 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23796 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 23797
c19d1205
ZW
23798 /* Well-known aliases. */
23799 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23800 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23801
23802 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23803 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23804
1b883319
AV
23805 /* Defining the new Zero register from ARMv8.1-M. */
23806 REGDEF(zr,15,ZR),
23807 REGDEF(ZR,15,ZR),
23808
c19d1205
ZW
23809 /* Coprocessor numbers. */
23810 REGSET(p, CP), REGSET(P, CP),
23811
23812 /* Coprocessor register numbers. The "cr" variants are for backward
23813 compatibility. */
23814 REGSET(c, CN), REGSET(C, CN),
23815 REGSET(cr, CN), REGSET(CR, CN),
23816
90ec0d68
MGD
23817 /* ARM banked registers. */
23818 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23819 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23820 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23821 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23822 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23823 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23824 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23825
23826 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23827 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23828 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23829 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23830 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 23831 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
23832 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23833 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23834
23835 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23836 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23837 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23838 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23839 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23840 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23841 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 23842 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
23843 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23844
c19d1205
ZW
23845 /* FPA registers. */
23846 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23847 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23848
23849 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23850 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23851
23852 /* VFP SP registers. */
5287ad62
JB
23853 REGSET(s,VFS), REGSET(S,VFS),
23854 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
23855
23856 /* VFP DP Registers. */
5287ad62
JB
23857 REGSET(d,VFD), REGSET(D,VFD),
23858 /* Extra Neon DP registers. */
23859 REGSETH(d,VFD), REGSETH(D,VFD),
23860
23861 /* Neon QP registers. */
23862 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
23863
23864 /* VFP control registers. */
23865 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23866 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
23867 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23868 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23869 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23870 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 23871 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
ba6cd17f
SD
23872 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23873 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23874 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23875 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
c19d1205
ZW
23876
23877 /* Maverick DSP coprocessor registers. */
23878 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23879 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23880
23881 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23882 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23883 REGDEF(dspsc,0,DSPSC),
23884
23885 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23886 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23887 REGDEF(DSPSC,0,DSPSC),
23888
23889 /* iWMMXt data registers - p0, c0-15. */
23890 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23891
23892 /* iWMMXt control registers - p1, c0-3. */
23893 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23894 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23895 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23896 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23897
23898 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23899 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23900 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23901 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23902 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23903
23904 /* XScale accumulator registers. */
23905 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23906};
23907#undef REGDEF
23908#undef REGNUM
23909#undef REGSET
7ed4c4c5 23910
c19d1205
ZW
23911/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23912 within psr_required_here. */
23913static const struct asm_psr psrs[] =
23914{
23915 /* Backward compatibility notation. Note that "all" is no longer
23916 truly all possible PSR bits. */
23917 {"all", PSR_c | PSR_f},
23918 {"flg", PSR_f},
23919 {"ctl", PSR_c},
23920
23921 /* Individual flags. */
23922 {"f", PSR_f},
23923 {"c", PSR_c},
23924 {"x", PSR_x},
23925 {"s", PSR_s},
59b42a0d 23926
c19d1205
ZW
23927 /* Combinations of flags. */
23928 {"fs", PSR_f | PSR_s},
23929 {"fx", PSR_f | PSR_x},
23930 {"fc", PSR_f | PSR_c},
23931 {"sf", PSR_s | PSR_f},
23932 {"sx", PSR_s | PSR_x},
23933 {"sc", PSR_s | PSR_c},
23934 {"xf", PSR_x | PSR_f},
23935 {"xs", PSR_x | PSR_s},
23936 {"xc", PSR_x | PSR_c},
23937 {"cf", PSR_c | PSR_f},
23938 {"cs", PSR_c | PSR_s},
23939 {"cx", PSR_c | PSR_x},
23940 {"fsx", PSR_f | PSR_s | PSR_x},
23941 {"fsc", PSR_f | PSR_s | PSR_c},
23942 {"fxs", PSR_f | PSR_x | PSR_s},
23943 {"fxc", PSR_f | PSR_x | PSR_c},
23944 {"fcs", PSR_f | PSR_c | PSR_s},
23945 {"fcx", PSR_f | PSR_c | PSR_x},
23946 {"sfx", PSR_s | PSR_f | PSR_x},
23947 {"sfc", PSR_s | PSR_f | PSR_c},
23948 {"sxf", PSR_s | PSR_x | PSR_f},
23949 {"sxc", PSR_s | PSR_x | PSR_c},
23950 {"scf", PSR_s | PSR_c | PSR_f},
23951 {"scx", PSR_s | PSR_c | PSR_x},
23952 {"xfs", PSR_x | PSR_f | PSR_s},
23953 {"xfc", PSR_x | PSR_f | PSR_c},
23954 {"xsf", PSR_x | PSR_s | PSR_f},
23955 {"xsc", PSR_x | PSR_s | PSR_c},
23956 {"xcf", PSR_x | PSR_c | PSR_f},
23957 {"xcs", PSR_x | PSR_c | PSR_s},
23958 {"cfs", PSR_c | PSR_f | PSR_s},
23959 {"cfx", PSR_c | PSR_f | PSR_x},
23960 {"csf", PSR_c | PSR_s | PSR_f},
23961 {"csx", PSR_c | PSR_s | PSR_x},
23962 {"cxf", PSR_c | PSR_x | PSR_f},
23963 {"cxs", PSR_c | PSR_x | PSR_s},
23964 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23965 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23966 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23967 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23968 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23969 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23970 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23971 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23972 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23973 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23974 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23975 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23976 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23977 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23978 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23979 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23980 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23981 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23982 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23983 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23984 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23985 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23986 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23987 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23988};
23989
62b3e311
PB
23990/* Table of V7M psr names. */
23991static const struct asm_psr v7m_psrs[] =
23992{
1a336194
TP
23993 {"apsr", 0x0 }, {"APSR", 0x0 },
23994 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23995 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23996 {"psr", 0x3 }, {"PSR", 0x3 },
23997 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23998 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23999 {"epsr", 0x6 }, {"EPSR", 0x6 },
24000 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
24001 {"msp", 0x8 }, {"MSP", 0x8 },
24002 {"psp", 0x9 }, {"PSP", 0x9 },
24003 {"msplim", 0xa }, {"MSPLIM", 0xa },
24004 {"psplim", 0xb }, {"PSPLIM", 0xb },
24005 {"primask", 0x10}, {"PRIMASK", 0x10},
24006 {"basepri", 0x11}, {"BASEPRI", 0x11},
24007 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
24008 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24009 {"control", 0x14}, {"CONTROL", 0x14},
24010 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24011 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24012 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24013 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24014 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24015 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24016 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24017 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24018 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
24019};
24020
c19d1205
ZW
24021/* Table of all shift-in-operand names. */
24022static const struct asm_shift_name shift_names [] =
b99bd4ef 24023{
c19d1205
ZW
24024 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24025 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24026 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24027 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24028 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
f5f10c66
AV
24029 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24030 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
c19d1205 24031};
b99bd4ef 24032
c19d1205
ZW
24033/* Table of all explicit relocation names. */
24034#ifdef OBJ_ELF
24035static struct reloc_entry reloc_names[] =
24036{
24037 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24038 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24039 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24040 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24041 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24042 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24043 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24044 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24045 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24046 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 24047 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
24048 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24049 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 24050 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 24051 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 24052 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 24053 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
188fd7ae
CL
24054 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24055 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24056 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24057 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24058 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24059 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
5c5a4843
CL
24060 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24061 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24062 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24063 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
c19d1205
ZW
24064};
24065#endif
b99bd4ef 24066
5ee91343 24067/* Table of all conditional affixes. */
c19d1205
ZW
24068static const struct asm_cond conds[] =
24069{
24070 {"eq", 0x0},
24071 {"ne", 0x1},
24072 {"cs", 0x2}, {"hs", 0x2},
24073 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24074 {"mi", 0x4},
24075 {"pl", 0x5},
24076 {"vs", 0x6},
24077 {"vc", 0x7},
24078 {"hi", 0x8},
24079 {"ls", 0x9},
24080 {"ge", 0xa},
24081 {"lt", 0xb},
24082 {"gt", 0xc},
24083 {"le", 0xd},
24084 {"al", 0xe}
24085};
5ee91343
AV
24086static const struct asm_cond vconds[] =
24087{
24088 {"t", 0xf},
24089 {"e", 0x10}
24090};
bfae80f2 24091
e797f7e0 24092#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
24093 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24094 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 24095
62b3e311
PB
24096static struct asm_barrier_opt barrier_opt_names[] =
24097{
e797f7e0
MGD
24098 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24099 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24100 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24101 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24102 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24103 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24104 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24105 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24106 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24107 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24108 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24109 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24110 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24111 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24112 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24113 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
24114};
24115
e797f7e0
MGD
24116#undef UL_BARRIER
24117
c19d1205
ZW
24118/* Table of ARM-format instructions. */
24119
24120/* Macros for gluing together operand strings. N.B. In all cases
24121 other than OPS0, the trailing OP_stop comes from default
24122 zero-initialization of the unspecified elements of the array. */
24123#define OPS0() { OP_stop, }
24124#define OPS1(a) { OP_##a, }
24125#define OPS2(a,b) { OP_##a,OP_##b, }
24126#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24127#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24128#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24129#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24130
5be8be5d
DG
24131/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24132 This is useful when mixing operands for ARM and THUMB, i.e. using the
24133 MIX_ARM_THUMB_OPERANDS macro.
24134 In order to use these macros, prefix the number of operands with _
24135 e.g. _3. */
24136#define OPS_1(a) { a, }
24137#define OPS_2(a,b) { a,b, }
24138#define OPS_3(a,b,c) { a,b,c, }
24139#define OPS_4(a,b,c,d) { a,b,c,d, }
24140#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24141#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24142
c19d1205
ZW
24143/* These macros abstract out the exact format of the mnemonic table and
24144 save some repeated characters. */
24145
24146/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24147#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24148 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
5ee91343 24149 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24150
24151/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24152 a T_MNEM_xyz enumerator. */
24153#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24154 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24155#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24156 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
24157
24158/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24159 infix after the third character. */
24160#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 24161 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
5ee91343 24162 THUMB_VARIANT, do_##ae, do_##te, 0 }
088fa78e 24163#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 24164 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
5ee91343 24165 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24166#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24167 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 24168#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 24169 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 24170#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24171 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 24172#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 24173 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 24174
c19d1205 24175/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
24176 field is still 0xE. Many of the Thumb variants can be executed
24177 conditionally, so this is checked separately. */
c19d1205 24178#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 24179 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24180 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205 24181
dd5181d5
KT
24182/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24183 Used by mnemonics that have very minimal differences in the encoding for
24184 ARM and Thumb variants and can be handled in a common function. */
24185#define TUEc(mnem, op, top, nops, ops, en) \
24186 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24187 THUMB_VARIANT, do_##en, do_##en, 0 }
dd5181d5 24188
c19d1205
ZW
24189/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24190 condition code field. */
24191#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 24192 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
5ee91343 24193 THUMB_VARIANT, do_##ae, do_##te, 0 }
c19d1205
ZW
24194
24195/* ARM-only variants of all the above. */
6a86118a 24196#define CE(mnem, op, nops, ops, ae) \
5ee91343 24197 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24198
24199#define C3(mnem, op, nops, ops, ae) \
5ee91343 24200 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24201
cf3cf39d
TP
24202/* Thumb-only variants of TCE and TUE. */
24203#define ToC(mnem, top, nops, ops, te) \
24204 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24205 do_##te, 0 }
cf3cf39d
TP
24206
24207#define ToU(mnem, top, nops, ops, te) \
24208 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
5ee91343 24209 NULL, do_##te, 0 }
cf3cf39d 24210
4389b29a
AV
24211/* T_MNEM_xyz enumerator variants of ToC. */
24212#define toC(mnem, top, nops, ops, te) \
24213 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
5ee91343 24214 do_##te, 0 }
4389b29a 24215
f6b2b12d
AV
24216/* T_MNEM_xyz enumerator variants of ToU. */
24217#define toU(mnem, top, nops, ops, te) \
24218 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
5ee91343 24219 NULL, do_##te, 0 }
f6b2b12d 24220
e3cb604e
PB
24221/* Legacy mnemonics that always have conditional infix after the third
24222 character. */
24223#define CL(mnem, op, nops, ops, ae) \
21d799b5 24224 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24225 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
e3cb604e 24226
8f06b2d8
PB
24227/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24228#define cCE(mnem, op, nops, ops, ae) \
5ee91343 24229 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24230
57785aa2
AV
24231/* mov instructions that are shared between coprocessor and MVE. */
24232#define mcCE(mnem, op, nops, ops, ae) \
24233 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24234
e3cb604e
PB
24235/* Legacy coprocessor instructions where conditional infix and conditional
24236 suffix are ambiguous. For consistency this includes all FPA instructions,
24237 not just the potentially ambiguous ones. */
24238#define cCL(mnem, op, nops, ops, ae) \
21d799b5 24239 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
5ee91343 24240 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
e3cb604e
PB
24241
24242/* Coprocessor, takes either a suffix or a position-3 infix
24243 (for an FPA corner case). */
24244#define C3E(mnem, op, nops, ops, ae) \
21d799b5 24245 { mnem, OPS##nops ops, OT_csuf_or_in3, \
5ee91343 24246 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
8f06b2d8 24247
6a86118a 24248#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
24249 { m1 #m2 m3, OPS##nops ops, \
24250 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
5ee91343 24251 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24252
24253#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
24254 xCM_ (m1, , m2, op, nops, ops, ae), \
24255 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24256 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24257 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24258 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24259 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24260 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24261 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24262 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24263 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24264 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24265 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24266 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24267 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24268 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24269 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24270 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24271 xCM_ (m1, le, m2, op, nops, ops, ae), \
24272 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
24273
24274#define UE(mnem, op, nops, ops, ae) \
5ee91343 24275 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a
NC
24276
24277#define UF(mnem, op, nops, ops, ae) \
5ee91343 24278 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
6a86118a 24279
5287ad62
JB
24280/* Neon data-processing. ARM versions are unconditional with cond=0xf.
24281 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24282 use the same encoding function for each. */
24283#define NUF(mnem, op, nops, ops, enc) \
24284 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
5ee91343 24285 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24286
24287/* Neon data processing, version which indirects through neon_enc_tab for
24288 the various overloaded versions of opcodes. */
24289#define nUF(mnem, op, nops, ops, enc) \
21d799b5 24290 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5ee91343 24291 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
5287ad62
JB
24292
24293/* Neon insn with conditional suffix for the ARM version, non-overloaded
24294 version. */
5ee91343 24295#define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
037e8744 24296 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5ee91343 24297 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24298
037e8744 24299#define NCE(mnem, op, nops, ops, enc) \
5ee91343 24300 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24301
24302#define NCEF(mnem, op, nops, ops, enc) \
5ee91343 24303 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
037e8744 24304
5287ad62 24305/* Neon insn with conditional suffix for the ARM version, overloaded types. */
5ee91343 24306#define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
21d799b5 24307 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5ee91343 24308 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
5287ad62 24309
037e8744 24310#define nCE(mnem, op, nops, ops, enc) \
5ee91343 24311 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
037e8744
JB
24312
24313#define nCEF(mnem, op, nops, ops, enc) \
5ee91343
AV
24314 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24315
24316/* */
24317#define mCEF(mnem, op, nops, ops, enc) \
a302e574 24318 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
5ee91343
AV
24319 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24320
24321
24322/* nCEF but for MVE predicated instructions. */
24323#define mnCEF(mnem, op, nops, ops, enc) \
24324 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24325
24326/* nCE but for MVE predicated instructions. */
24327#define mnCE(mnem, op, nops, ops, enc) \
24328 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
037e8744 24329
5ee91343
AV
24330/* NUF but for potentially MVE predicated instructions. */
24331#define MNUF(mnem, op, nops, ops, enc) \
24332 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24333 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24334
24335/* nUF but for potentially MVE predicated instructions. */
24336#define mnUF(mnem, op, nops, ops, enc) \
24337 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24338 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24339
24340/* ToC but for potentially MVE predicated instructions. */
24341#define mToC(mnem, top, nops, ops, te) \
24342 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24343 do_##te, 1 }
24344
24345/* NCE but for MVE predicated instructions. */
24346#define MNCE(mnem, op, nops, ops, enc) \
24347 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24348
24349/* NCEF but for MVE predicated instructions. */
24350#define MNCEF(mnem, op, nops, ops, enc) \
24351 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
c19d1205
ZW
24352#define do_0 0
24353
c19d1205 24354static const struct asm_opcode insns[] =
bfae80f2 24355{
74db7efb
NC
24356#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24357#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
24358 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24359 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24360 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24361 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24362 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24363 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24364 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24365 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24366 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24367 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24368 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24369 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24370 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24371 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24372 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24373 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
24374
24375 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24376 for setting PSR flag bits. They are obsolete in V6 and do not
24377 have Thumb equivalents. */
21d799b5
NC
24378 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24379 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24380 CL("tstp", 110f000, 2, (RR, SH), cmp),
24381 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24382 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24383 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24384 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24385 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24386 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24387
24388 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 24389 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
24390 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24391 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24392
24393 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
24394 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24395 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24396 OP_RRnpc),
24397 OP_ADDRGLDR),ldst, t_ldst),
24398 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
24399
24400 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24401 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24402 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24403 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24404 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24405 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24406
21d799b5
NC
24407 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24408 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 24409
c19d1205 24410 /* Pseudo ops. */
21d799b5 24411 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 24412 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 24413 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 24414 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
24415
24416 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
24417 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24418 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24419 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24420 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24421 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24422 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24423 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24424 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24425 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24426 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24427 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24428 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 24429
16a4cf17 24430 /* These may simplify to neg. */
21d799b5
NC
24431 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24432 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 24433
173205ca
TP
24434#undef THUMB_VARIANT
24435#define THUMB_VARIANT & arm_ext_os
24436
24437 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24438 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24439
c921be7d
NC
24440#undef THUMB_VARIANT
24441#define THUMB_VARIANT & arm_ext_v6
24442
21d799b5 24443 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
24444
24445 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
24446#undef THUMB_VARIANT
24447#define THUMB_VARIANT & arm_ext_v6t2
24448
21d799b5
NC
24449 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24450 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24451 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 24452
5be8be5d
DG
24453 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24454 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24455 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24456 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 24457
21d799b5
NC
24458 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24459 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 24460
21d799b5
NC
24461 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24462 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
24463
24464 /* V1 instructions with no Thumb analogue at all. */
21d799b5 24465 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
24466 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24467
24468 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24469 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24470 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24471 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24472 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24473 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24474 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24475 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24476
c921be7d
NC
24477#undef ARM_VARIANT
24478#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24479#undef THUMB_VARIANT
24480#define THUMB_VARIANT & arm_ext_v4t
24481
21d799b5
NC
24482 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24483 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 24484
c921be7d
NC
24485#undef THUMB_VARIANT
24486#define THUMB_VARIANT & arm_ext_v6t2
24487
21d799b5 24488 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
24489 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24490
24491 /* Generic coprocessor instructions. */
21d799b5
NC
24492 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24493 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24494 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24495 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24496 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24497 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 24498 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24499
c921be7d
NC
24500#undef ARM_VARIANT
24501#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24502
21d799b5 24503 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
24504 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24505
c921be7d
NC
24506#undef ARM_VARIANT
24507#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24508#undef THUMB_VARIANT
24509#define THUMB_VARIANT & arm_ext_msr
24510
d2cd1205
JB
24511 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24512 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 24513
c921be7d
NC
24514#undef ARM_VARIANT
24515#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24516#undef THUMB_VARIANT
24517#define THUMB_VARIANT & arm_ext_v6t2
24518
21d799b5
NC
24519 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24520 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24521 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24522 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24523 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24524 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24525 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24526 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 24527
c921be7d
NC
24528#undef ARM_VARIANT
24529#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24530#undef THUMB_VARIANT
24531#define THUMB_VARIANT & arm_ext_v4t
24532
5be8be5d
DG
24533 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24534 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24535 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24536 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
24537 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24538 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 24539
c921be7d
NC
24540#undef ARM_VARIANT
24541#define ARM_VARIANT & arm_ext_v4t_5
24542
c19d1205
ZW
24543 /* ARM Architecture 4T. */
24544 /* Note: bx (and blx) are required on V5, even if the processor does
24545 not support Thumb. */
21d799b5 24546 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 24547
c921be7d
NC
24548#undef ARM_VARIANT
24549#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24550#undef THUMB_VARIANT
24551#define THUMB_VARIANT & arm_ext_v5t
24552
c19d1205
ZW
24553 /* Note: blx has 2 variants; the .value coded here is for
24554 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
24555 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24556 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 24557
c921be7d
NC
24558#undef THUMB_VARIANT
24559#define THUMB_VARIANT & arm_ext_v6t2
24560
21d799b5
NC
24561 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24562 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24563 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24564 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24565 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24566 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24567 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24568 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 24569
c921be7d 24570#undef ARM_VARIANT
74db7efb
NC
24571#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24572#undef THUMB_VARIANT
24573#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 24574
21d799b5
NC
24575 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24576 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24577 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24578 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24579
21d799b5
NC
24580 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24581 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 24582
21d799b5
NC
24583 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24584 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24585 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24586 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 24587
21d799b5
NC
24588 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24589 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24590 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24591 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24592
21d799b5
NC
24593 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24594 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 24595
03ee1b7f
NC
24596 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24597 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24598 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24599 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 24600
c921be7d 24601#undef ARM_VARIANT
74db7efb
NC
24602#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24603#undef THUMB_VARIANT
24604#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24605
21d799b5 24606 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
24607 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24608 ldrd, t_ldstd),
24609 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24610 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 24611
21d799b5
NC
24612 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24613 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 24614
c921be7d
NC
24615#undef ARM_VARIANT
24616#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24617
21d799b5 24618 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 24619
c921be7d
NC
24620#undef ARM_VARIANT
24621#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24622#undef THUMB_VARIANT
24623#define THUMB_VARIANT & arm_ext_v6
24624
21d799b5
NC
24625 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24626 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24627 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24628 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24629 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24630 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24631 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24632 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24633 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24634 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 24635
c921be7d 24636#undef THUMB_VARIANT
ff8646ee 24637#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 24638
5be8be5d
DG
24639 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24640 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24641 strex, t_strex),
ff8646ee
TP
24642#undef THUMB_VARIANT
24643#define THUMB_VARIANT & arm_ext_v6t2
24644
21d799b5
NC
24645 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24646 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 24647
21d799b5
NC
24648 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24649 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 24650
9e3c6df6 24651/* ARM V6 not included in V7M. */
c921be7d
NC
24652#undef THUMB_VARIANT
24653#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 24654 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 24655 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
24656 UF(rfeib, 9900a00, 1, (RRw), rfe),
24657 UF(rfeda, 8100a00, 1, (RRw), rfe),
24658 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24659 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
24660 UF(rfefa, 8100a00, 1, (RRw), rfe),
24661 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24662 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 24663 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
24664 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24665 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 24666 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 24667 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 24668 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 24669 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 24670 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 24671 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 24672 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 24673
9e3c6df6
PB
24674/* ARM V6 not included in V7M (eg. integer SIMD). */
24675#undef THUMB_VARIANT
24676#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
24677 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24678 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24679 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24680 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24681 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24682 /* Old name for QASX. */
74db7efb 24683 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24684 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24685 /* Old name for QSAX. */
74db7efb 24686 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24687 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24688 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24689 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24690 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24691 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24692 /* Old name for SASX. */
74db7efb 24693 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24694 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24695 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24696 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24697 /* Old name for SHASX. */
21d799b5 24698 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24699 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24700 /* Old name for SHSAX. */
21d799b5
NC
24701 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24703 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24704 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24705 /* Old name for SSAX. */
74db7efb 24706 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24707 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24708 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24709 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24712 /* Old name for UASX. */
74db7efb 24713 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24714 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24715 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24716 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24717 /* Old name for UHASX. */
21d799b5
NC
24718 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24719 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24720 /* Old name for UHSAX. */
21d799b5
NC
24721 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24722 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24723 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24724 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 24726 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24727 /* Old name for UQASX. */
21d799b5
NC
24728 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24729 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24730 /* Old name for UQSAX. */
21d799b5
NC
24731 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24732 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24733 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24734 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24735 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 24736 /* Old name for USAX. */
74db7efb 24737 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 24738 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
24739 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24740 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24741 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24742 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24743 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24744 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24745 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24746 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24747 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24748 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24749 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24750 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24751 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24752 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24753 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24754 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24755 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24756 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24757 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24758 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24759 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24760 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24761 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24762 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24763 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24764 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24765 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
24766 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24767 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24768 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24769 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24770 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 24771
c921be7d 24772#undef ARM_VARIANT
55e8aae7 24773#define ARM_VARIANT & arm_ext_v6k_v6t2
c921be7d 24774#undef THUMB_VARIANT
55e8aae7 24775#define THUMB_VARIANT & arm_ext_v6k_v6t2
c921be7d 24776
21d799b5
NC
24777 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24778 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24779 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24780 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 24781
c921be7d
NC
24782#undef THUMB_VARIANT
24783#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
24784 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24785 ldrexd, t_ldrexd),
24786 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24787 RRnpcb), strexd, t_strexd),
ebdca51a 24788
c921be7d 24789#undef THUMB_VARIANT
ff8646ee 24790#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
24791 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24792 rd_rn, rd_rn),
24793 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24794 rd_rn, rd_rn),
24795 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24796 strex, t_strexbh),
5be8be5d 24797 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 24798 strex, t_strexbh),
21d799b5 24799 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 24800
c921be7d 24801#undef ARM_VARIANT
f4c65163 24802#define ARM_VARIANT & arm_ext_sec
74db7efb 24803#undef THUMB_VARIANT
f4c65163 24804#define THUMB_VARIANT & arm_ext_sec
c921be7d 24805
21d799b5 24806 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 24807
90ec0d68
MGD
24808#undef ARM_VARIANT
24809#define ARM_VARIANT & arm_ext_virt
24810#undef THUMB_VARIANT
24811#define THUMB_VARIANT & arm_ext_virt
24812
24813 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24814 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24815
ddfded2f
MW
24816#undef ARM_VARIANT
24817#define ARM_VARIANT & arm_ext_pan
24818#undef THUMB_VARIANT
24819#define THUMB_VARIANT & arm_ext_pan
24820
24821 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24822
c921be7d 24823#undef ARM_VARIANT
74db7efb 24824#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
24825#undef THUMB_VARIANT
24826#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24827
21d799b5
NC
24828 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24829 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24830 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24831 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 24832
21d799b5 24833 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 24834 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 24835
5be8be5d
DG
24836 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24837 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24838 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24839 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 24840
91d8b670
JG
24841#undef ARM_VARIANT
24842#define ARM_VARIANT & arm_ext_v3
24843#undef THUMB_VARIANT
24844#define THUMB_VARIANT & arm_ext_v6t2
24845
24846 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
c597cc3d
SD
24847 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24848 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
91d8b670
JG
24849
24850#undef ARM_VARIANT
24851#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
24852#undef THUMB_VARIANT
24853#define THUMB_VARIANT & arm_ext_v6t2_v8m
24854 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24855 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24856
bf3eeda7 24857 /* Thumb-only instructions. */
74db7efb 24858#undef ARM_VARIANT
bf3eeda7
NS
24859#define ARM_VARIANT NULL
24860 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24861 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
24862
24863 /* ARM does not really have an IT instruction, so always allow it.
24864 The opcode is copied from Thumb in order to allow warnings in
24865 -mimplicit-it=[never | arm] modes. */
24866#undef ARM_VARIANT
24867#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
24868#undef THUMB_VARIANT
24869#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 24870
21d799b5
NC
24871 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24872 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24873 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24874 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24875 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24876 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24877 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24878 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24879 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24880 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24881 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24882 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24883 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24884 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24885 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 24886 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
24887 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24888 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 24889
92e90b6e 24890 /* Thumb2 only instructions. */
c921be7d
NC
24891#undef ARM_VARIANT
24892#define ARM_VARIANT NULL
92e90b6e 24893
21d799b5
NC
24894 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24895 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24896 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24897 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24898 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24899 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 24900
eea54501
MGD
24901 /* Hardware division instructions. */
24902#undef ARM_VARIANT
24903#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
24904#undef THUMB_VARIANT
24905#define THUMB_VARIANT & arm_ext_div
24906
eea54501
MGD
24907 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24908 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 24909
7e806470 24910 /* ARM V6M/V7 instructions. */
c921be7d
NC
24911#undef ARM_VARIANT
24912#define ARM_VARIANT & arm_ext_barrier
24913#undef THUMB_VARIANT
24914#define THUMB_VARIANT & arm_ext_barrier
24915
ccb84d65
JB
24916 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24917 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24918 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 24919
62b3e311 24920 /* ARM V7 instructions. */
c921be7d
NC
24921#undef ARM_VARIANT
24922#define ARM_VARIANT & arm_ext_v7
24923#undef THUMB_VARIANT
24924#define THUMB_VARIANT & arm_ext_v7
24925
21d799b5
NC
24926 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24927 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 24928
74db7efb 24929#undef ARM_VARIANT
60e5ef9f 24930#define ARM_VARIANT & arm_ext_mp
74db7efb 24931#undef THUMB_VARIANT
60e5ef9f
MGD
24932#define THUMB_VARIANT & arm_ext_mp
24933
24934 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24935
53c4b28b
MGD
24936 /* AArchv8 instructions. */
24937#undef ARM_VARIANT
24938#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
24939
24940/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 24941#undef THUMB_VARIANT
4ed7ed8d 24942#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 24943
4ed7ed8d
TP
24944 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24945 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24946 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24947 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24948 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24949 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 24950 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
24951 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24952 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24953 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24954 stlex, t_stlex),
4b8c8c02
RE
24955 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24956 stlex, t_stlex),
24957 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24958 stlex, t_stlex),
4ed7ed8d
TP
24959#undef THUMB_VARIANT
24960#define THUMB_VARIANT & arm_ext_v8
53c4b28b 24961
4ed7ed8d 24962 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
4ed7ed8d
TP
24963 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24964 ldrexd, t_ldrexd),
24965 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24966 strexd, t_strexd),
26417f19
AC
24967#undef THUMB_VARIANT
24968#define THUMB_VARIANT & arm_ext_v8r
24969#undef ARM_VARIANT
24970#define ARM_VARIANT & arm_ext_v8r
24971
24972/* ARMv8-R instructions. */
24973 TUF("dfb", 57ff04c, f3bf8f4c, 0, (), noargs, noargs),
f7dd2fb2
TC
24974
24975/* Defined in V8 but is in undefined encoding space for earlier
24976 architectures. However earlier architectures are required to treat
24977 this instuction as a semihosting trap as well. Hence while not explicitly
24978 defined as such, it is in fact correct to define the instruction for all
24979 architectures. */
24980#undef THUMB_VARIANT
24981#define THUMB_VARIANT & arm_ext_v1
24982#undef ARM_VARIANT
24983#define ARM_VARIANT & arm_ext_v1
24984 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24985
8884b720 24986 /* ARMv8 T32 only. */
74db7efb 24987#undef ARM_VARIANT
b79f7053
MGD
24988#define ARM_VARIANT NULL
24989 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24990 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24991 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24992
33399f07
MGD
24993 /* FP for ARMv8. */
24994#undef ARM_VARIANT
a715796b 24995#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 24996#undef THUMB_VARIANT
a715796b 24997#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
24998
24999 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
25000 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
25001 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
25002 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
30bdf752 25003 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
a710b305
AV
25004 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
25005 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
25006 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
25007 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
25008 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
25009 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
33399f07 25010
91ff7894
MGD
25011 /* Crypto v1 extensions. */
25012#undef ARM_VARIANT
25013#define ARM_VARIANT & fpu_crypto_ext_armv8
25014#undef THUMB_VARIANT
25015#define THUMB_VARIANT & fpu_crypto_ext_armv8
25016
25017 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25018 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25019 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25020 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
25021 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25022 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25023 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25024 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25025 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25026 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25027 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
25028 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25029 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25030 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 25031
dd5181d5 25032#undef ARM_VARIANT
8b301fbb 25033#define ARM_VARIANT & arm_ext_crc
dd5181d5 25034#undef THUMB_VARIANT
8b301fbb 25035#define THUMB_VARIANT & arm_ext_crc
dd5181d5
KT
25036 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25037 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25038 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25039 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25040 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25041 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25042
105bde57
MW
25043 /* ARMv8.2 RAS extension. */
25044#undef ARM_VARIANT
4d1464f2 25045#define ARM_VARIANT & arm_ext_ras
105bde57 25046#undef THUMB_VARIANT
4d1464f2 25047#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
25048 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25049
49e8a725
SN
25050#undef ARM_VARIANT
25051#define ARM_VARIANT & arm_ext_v8_3
25052#undef THUMB_VARIANT
25053#define THUMB_VARIANT & arm_ext_v8_3
25054 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25055
c604a79a
JW
25056#undef ARM_VARIANT
25057#define ARM_VARIANT & fpu_neon_ext_dotprod
25058#undef THUMB_VARIANT
25059#define THUMB_VARIANT & fpu_neon_ext_dotprod
25060 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25061 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25062
c921be7d
NC
25063#undef ARM_VARIANT
25064#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
25065#undef THUMB_VARIANT
25066#define THUMB_VARIANT NULL
c921be7d 25067
21d799b5
NC
25068 cCE("wfs", e200110, 1, (RR), rd),
25069 cCE("rfs", e300110, 1, (RR), rd),
25070 cCE("wfc", e400110, 1, (RR), rd),
25071 cCE("rfc", e500110, 1, (RR), rd),
25072
25073 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25074 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25075 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25076 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25077
25078 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25079 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25080 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25081 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25082
25083 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25084 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25085 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25086 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25087 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25088 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25089 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25090 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25091 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25092 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25093 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25094 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25095
25096 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25097 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25098 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25099 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25100 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25101 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25102 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25103 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25104 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25105 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25106 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25107 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25108
25109 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25110 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25111 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25112 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25113 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25114 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25115 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25116 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25117 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25118 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25119 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25120 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25121
25122 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25123 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25124 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25125 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25126 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25127 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25128 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25129 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25130 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25131 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25132 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25133 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25134
25135 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25136 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25137 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25138 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25139 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25140 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25141 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25142 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25143 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25144 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25145 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25146 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25147
25148 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25149 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25150 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25151 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25152 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25153 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25154 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25155 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25156 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25157 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25158 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25159 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25160
25161 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25162 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25163 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25164 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25165 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25166 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25167 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25168 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25169 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25170 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25171 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25172 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25173
25174 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25175 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25176 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25177 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25178 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25179 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25180 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25181 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25182 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25183 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25184 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25185 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25186
25187 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25188 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25189 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25190 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25191 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25192 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25193 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25194 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25195 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25196 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25197 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25198 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25199
25200 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25201 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25202 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25203 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25204 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25205 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25206 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25207 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25208 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25209 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25210 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25211 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25212
25213 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25214 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25215 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25216 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25217 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25218 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25219 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25220 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25221 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25222 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25223 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25224 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25225
25226 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25227 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25228 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25229 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25230 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25231 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25232 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25233 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25234 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25235 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25236 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25237 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25238
25239 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25240 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25241 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25242 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25243 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25244 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25245 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25246 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25247 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25248 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25249 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25250 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25251
25252 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25253 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25254 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25255 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25256 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25257 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25258 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25259 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25260 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25261 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25262 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25263 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25264
25265 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25266 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25267 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25268 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25269 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25270 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25271 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25272 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25273 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25274 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25275 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25276 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25277
25278 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25279 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25280 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25281 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25282 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25283 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25284 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25285 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25286 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25287 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25288 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25289 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25290
25291 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25295 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25296 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25297 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25298 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25299 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25302 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25303
25304 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25309 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25311 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25312 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25316
25317 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25322 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25324 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25325 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25329
25330 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25335 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25337 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25338 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25342
25343 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25348 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25350 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25351 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25355
25356 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25361 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25363 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25364 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25368
25369 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25374 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25376 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25377 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25381
25382 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25387 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25389 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25390 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25394
25395 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25400 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25402 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25403 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25407
25408 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25413 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25415 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25416 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25420
25421 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25426 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25428 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25429 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25433
25434 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25439 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25441 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25442 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25445 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25446
25447 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25448 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25449 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25450 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25451 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25452 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25453 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25454 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25455 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25456 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25457 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25458 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25459
25460 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25461 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25462 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25463 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25464
25465 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25466 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25467 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25468 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25469 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25470 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25471 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25472 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25473 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25474 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25475 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25476 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 25477
c19d1205
ZW
25478 /* The implementation of the FIX instruction is broken on some
25479 assemblers, in that it accepts a precision specifier as well as a
25480 rounding specifier, despite the fact that this is meaningless.
25481 To be more compatible, we accept it as well, though of course it
25482 does not set any bits. */
21d799b5
NC
25483 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25484 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25485 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25486 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25487 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25488 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25489 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25490 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25491 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25492 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25493 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25494 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25495 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 25496
c19d1205 25497 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
25498#undef ARM_VARIANT
25499#define ARM_VARIANT & fpu_fpa_ext_v2
25500
21d799b5
NC
25501 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25502 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25503 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25504 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25505 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25506 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 25507
c921be7d
NC
25508#undef ARM_VARIANT
25509#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
ba6cd17f
SD
25510#undef THUMB_VARIANT
25511#define THUMB_VARIANT & arm_ext_v6t2
25512 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25513 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
ef8f595f
MI
25514 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25515 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25516 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25517 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
90e9955a
SP
25518
25519 /* Memory operations. */
25520 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25521 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25522 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25523 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
ba6cd17f 25524#undef THUMB_VARIANT
c921be7d 25525
c19d1205 25526 /* Moves and type conversions. */
21d799b5
NC
25527 cCE("fmstat", ef1fa10, 0, (), noargs),
25528 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25529 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25530 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25531 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25532 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25533 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25534 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25535 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
25536
25537 /* Memory operations. */
55881a11 25538 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25539 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25540 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25541 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25542 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25543 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
55881a11 25544 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
55881a11
MGD
25545 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25546 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25547 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25548 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25549 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 25550
c19d1205 25551 /* Monadic operations. */
21d799b5
NC
25552 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25553 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25554 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
25555
25556 /* Dyadic operations. */
21d799b5
NC
25557 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25558 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25559 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25560 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25561 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25562 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25563 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25564 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25565 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 25566
c19d1205 25567 /* Comparisons. */
21d799b5
NC
25568 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25569 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25570 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25571 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 25572
62f3b8c8
PB
25573 /* Double precision load/store are still present on single precision
25574 implementations. */
55881a11
MGD
25575 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25576 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25577 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25578 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25579 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25580 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25581 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25582 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 25583
c921be7d
NC
25584#undef ARM_VARIANT
25585#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25586
c19d1205 25587 /* Moves and type conversions. */
21d799b5
NC
25588 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25589 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25590 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25591 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25592 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25593 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25594 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25595 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25596 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25597 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25598 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25599 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 25600
c19d1205 25601 /* Monadic operations. */
21d799b5
NC
25602 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25603 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25604 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
25605
25606 /* Dyadic operations. */
21d799b5
NC
25607 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25608 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25609 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25610 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25611 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25612 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25613 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25614 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25615 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 25616
c19d1205 25617 /* Comparisons. */
21d799b5
NC
25618 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25619 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25620 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25621 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 25622
037e8744
JB
25623/* Instructions which may belong to either the Neon or VFP instruction sets.
25624 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
25625#undef ARM_VARIANT
25626#define ARM_VARIANT & fpu_vfp_ext_v1xd
ef8f595f
MI
25627#undef THUMB_VARIANT
25628#define THUMB_VARIANT & arm_ext_v6t2
25629
25630 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25631 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25632 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25633 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25634 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25635 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25636
25637 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25638 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25639
c921be7d
NC
25640#undef THUMB_VARIANT
25641#define THUMB_VARIANT & fpu_vfp_ext_v1xd
25642
037e8744
JB
25643 /* These mnemonics are unique to VFP. */
25644 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25645 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
25646 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25647 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25648 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
037e8744
JB
25649 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25650
25651 /* Mnemonics shared by Neon and VFP. */
21d799b5 25652 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 25653
dd9634d9 25654 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
e3e535bc 25655 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
dd9634d9
AV
25656 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25657 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
f31fef98 25658
037e8744
JB
25659
25660 /* NOTE: All VMOV encoding is special-cased! */
037e8744
JB
25661 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25662
32c36c3c
AV
25663#undef THUMB_VARIANT
25664/* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25665 by different feature bits. Since we are setting the Thumb guard, we can
25666 require Thumb-1 which makes it a nop guard and set the right feature bit in
25667 do_vldr_vstr (). */
25668#define THUMB_VARIANT & arm_ext_v4t
25669 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25670 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25671
9db2f6b4
RL
25672#undef ARM_VARIANT
25673#define ARM_VARIANT & arm_ext_fp16
25674#undef THUMB_VARIANT
25675#define THUMB_VARIANT & arm_ext_fp16
25676 /* New instructions added from v8.2, allowing the extraction and insertion of
25677 the upper 16 bits of a 32-bit vector register. */
25678 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25679 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25680
dec41383 25681 /* New backported fma/fms instructions optional in v8.2. */
aab2c27d
MM
25682 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25683 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
dec41383 25684
c921be7d
NC
25685#undef THUMB_VARIANT
25686#define THUMB_VARIANT & fpu_neon_ext_v1
25687#undef ARM_VARIANT
25688#define ARM_VARIANT & fpu_neon_ext_v1
25689
5287ad62
JB
25690 /* Data processing with three registers of the same length. */
25691 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25692 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25693 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
5287ad62 25694 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62 25695 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
5287ad62
JB
25696 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25697 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25698 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
5287ad62 25699 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7 25700 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
627907b7 25701 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62 25702 /* If not immediate, fall back to neon_dyadic_i64_su.
5150f0d8
AV
25703 shl should accept I8 I16 I32 I64,
25704 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25705 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25706 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
5287ad62 25707 /* Logic ops, types optional & ignored. */
4316f0d2 25708 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25709 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25710 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25711 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
4316f0d2 25712 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
25713 /* Bitfield ops, untyped. */
25714 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25715 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25716 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25717 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25718 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25719 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 25720 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5 25721 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25722 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21d799b5 25723 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
25724 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25725 back to neon_dyadic_if_su. */
21d799b5
NC
25726 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25727 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25728 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25729 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25730 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25731 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25732 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25733 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 25734 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
25735 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25736 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 25737 /* As above, D registers only. */
21d799b5
NC
25738 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25739 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 25740 /* Int and float variants, signedness unimportant. */
21d799b5
NC
25741 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25742 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25743 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 25744 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
25745 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25746 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
25747 /* vtst takes sizes 8, 16, 32. */
25748 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25749 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25750 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 25751 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 25752 /* VQD{R}MULH takes S16 S32. */
21d799b5 25753 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21d799b5 25754 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
25755 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25756 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25757 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25758 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
25759 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25760 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25761 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25762 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
25763 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25764 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25765 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25766 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 25767 /* ARM v8.1 extension. */
643afb90
MW
25768 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25769 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25770 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
25771
25772 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 25773 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
25774 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25775
25776 /* Data processing with two registers and a shift amount. */
25777 /* Right shifts, and variants with rounding.
25778 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62 25779 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
5287ad62
JB
25780 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25781 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25782 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25783 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25784 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25785 /* Shift and insert. Sizes accepted 8 16 32 64. */
5287ad62 25786 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
5287ad62
JB
25787 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25788 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
5287ad62
JB
25789 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25790 /* Right shift immediate, saturating & narrowing, with rounding variants.
25791 Types accepted S16 S32 S64 U16 U32 U64. */
25792 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25793 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25794 /* As above, unsigned. Types accepted S16 S32 S64. */
25795 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25796 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25797 /* Right shift narrowing. Types accepted I16 I32 I64. */
25798 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25799 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25800 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 25801 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 25802 /* CVT with optional immediate for fixed-point variant. */
21d799b5 25803 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 25804
4316f0d2 25805 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
25806
25807 /* Data processing, three registers of different lengths. */
25808 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25809 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
5287ad62
JB
25810 /* If not scalar, fall back to neon_dyadic_long.
25811 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
25812 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25813 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
25814 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25815 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25816 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25817 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25818 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25819 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25820 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25821 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25822 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
25823 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25824 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25825 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
25826 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25827 S16 S32 U16 U32. */
21d799b5 25828 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
25829
25830 /* Extract. Size 8. */
3b8d421e
PB
25831 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25832 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
25833
25834 /* Two registers, miscellaneous. */
25835 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
5287ad62 25836 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
5287ad62 25837 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
5287ad62
JB
25838 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25839 /* Vector replicate. Sizes 8 16 32. */
21d799b5 25840 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
25841 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25842 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25843 /* VMOVN. Types I16 I32 I64. */
21d799b5 25844 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 25845 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 25846 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 25847 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 25848 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
25849 /* VZIP / VUZP. Sizes 8 16 32. */
25850 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25851 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25852 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25853 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25854 /* VQABS / VQNEG. Types S8 S16 S32. */
5287ad62 25855 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
5287ad62
JB
25856 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25857 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25858 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25859 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25860 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25861 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 25862 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
25863 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25864 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25865 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25866 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25867 /* VCLS. Types S8 S16 S32. */
5287ad62
JB
25868 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25869 /* VCLZ. Types I8 I16 I32. */
5287ad62
JB
25870 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25871 /* VCNT. Size 8. */
25872 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25873 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25874 /* Two address, untyped. */
25875 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25876 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25877 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
25878 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25879 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
25880
25881 /* Table lookup. Size 8. */
25882 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25883 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25884
c921be7d
NC
25885#undef THUMB_VARIANT
25886#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25887#undef ARM_VARIANT
25888#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25889
5287ad62 25890 /* Neon element/structure load/store. */
21d799b5
NC
25891 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25892 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25893 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25894 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25895 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25896 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25897 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25898 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 25899
c921be7d 25900#undef THUMB_VARIANT
74db7efb
NC
25901#define THUMB_VARIANT & fpu_vfp_ext_v3xd
25902#undef ARM_VARIANT
25903#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
25904 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25905 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25906 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25907 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25908 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25909 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25910 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25911 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25912 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25913
74db7efb 25914#undef THUMB_VARIANT
c921be7d
NC
25915#define THUMB_VARIANT & fpu_vfp_ext_v3
25916#undef ARM_VARIANT
25917#define ARM_VARIANT & fpu_vfp_ext_v3
25918
21d799b5 25919 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 25920 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25921 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25922 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25923 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25924 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25925 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 25926 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 25927 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 25928
74db7efb
NC
25929#undef ARM_VARIANT
25930#define ARM_VARIANT & fpu_vfp_ext_fma
25931#undef THUMB_VARIANT
25932#define THUMB_VARIANT & fpu_vfp_ext_fma
aab2c27d 25933 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
62f3b8c8
PB
25934 VFP FMA variant; NEON and VFP FMA always includes the NEON
25935 FMA instructions. */
d58196e0 25936 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
aab2c27d 25937 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
d58196e0
AV
25938 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25939
62f3b8c8
PB
25940 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25941 the v form should always be used. */
25942 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25943 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25944 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25945 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25946 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25947 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25948
5287ad62 25949#undef THUMB_VARIANT
c921be7d
NC
25950#undef ARM_VARIANT
25951#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25952
21d799b5
NC
25953 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25954 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25955 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25956 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25957 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25958 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25959 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25960 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 25961
c921be7d
NC
25962#undef ARM_VARIANT
25963#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25964
21d799b5
NC
25965 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25966 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25967 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25968 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25969 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25970 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25971 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25972 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25973 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
25974 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25975 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25976 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25977 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25978 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25979 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
25980 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25981 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25982 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25983 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25984 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25985 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25986 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25987 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25988 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25989 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25990 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
25991 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25992 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25993 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
25994 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25995 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25996 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25997 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25998 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25999 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
26000 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
26001 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
26002 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26004 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26005 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26007 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26008 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26011 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
26012 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26013 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26014 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26015 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26016 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26020 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26025 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26026 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26027 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26028 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26029 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26030 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26031 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26032 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26033 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26034 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26035 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26046 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26047 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26048 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26049 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26051 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26054 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26056 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26057 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26058 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
26059 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26060 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26061 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26062 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26063 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26064 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
26065 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26066 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26067 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26068 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26069 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26070 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26071 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26072 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26073 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26074 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26075 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26076 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26077 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26078 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26079 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26080 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26081 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26082 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26083 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26084 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26085 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26086 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26087 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26088 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26089 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26090 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26091 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26092 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26093 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26094 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26095 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26096 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26097 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26098 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26099 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26100 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26101 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26102 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26103 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26104 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26105 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26106 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26107 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26108 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26109 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26110 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26111 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26112 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26113 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26114 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26115 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26116 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26117 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26118 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26119 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26120 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26121 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26122 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26123 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26124 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26125 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26126 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 26127
c921be7d
NC
26128#undef ARM_VARIANT
26129#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26130
21d799b5
NC
26131 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26132 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26133 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26134 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26135 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26136 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26137 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26144 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26147 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26152 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26175 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26176 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26177 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26178 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26179 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26180 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26181 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26182 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26183 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26184 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26185 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26186 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26187 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 26188
c921be7d
NC
26189#undef ARM_VARIANT
26190#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26191
21d799b5
NC
26192 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26193 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26194 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26195 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26196 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26197 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26198 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26199 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26200 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26201 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26202 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26203 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26204 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26205 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
26206 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26207 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26208 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26209 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26210 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26211 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26212 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26213 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26214 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26215 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
26216 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26217 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26218 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26219 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
26220 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26221 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
26222 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26223 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26224 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26225 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
26226 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26227 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26228 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26229 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26230 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26231 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
26232 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26233 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
26234 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26235 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
26236 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26237 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26238 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26239 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26240 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26241 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26242 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26243 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26244 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26245 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26246 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26247 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26248 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26249 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26250 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26251 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26252 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26253 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26254 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26255 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26256 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26257 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26258 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26259 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26260 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26261 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26262 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26263 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
26264 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26265 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
26266 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26267 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 26268
7fadb25d
SD
26269 /* ARMv8.5-A instructions. */
26270#undef ARM_VARIANT
26271#define ARM_VARIANT & arm_ext_sb
26272#undef THUMB_VARIANT
26273#define THUMB_VARIANT & arm_ext_sb
26274 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26275
dad0c3bf
SD
26276#undef ARM_VARIANT
26277#define ARM_VARIANT & arm_ext_predres
26278#undef THUMB_VARIANT
26279#define THUMB_VARIANT & arm_ext_predres
26280 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26281 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26282 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26283
16a1fa25 26284 /* ARMv8-M instructions. */
4ed7ed8d
TP
26285#undef ARM_VARIANT
26286#define ARM_VARIANT NULL
26287#undef THUMB_VARIANT
26288#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
26289 ToU("sg", e97fe97f, 0, (), noargs),
26290 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26291 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26292 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26293 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26294 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26295 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
26296
26297 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26298 instructions behave as nop if no VFP is present. */
26299#undef THUMB_VARIANT
26300#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
26301 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26302 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
4389b29a
AV
26303
26304 /* Armv8.1-M Mainline instructions. */
26305#undef THUMB_VARIANT
26306#define THUMB_VARIANT & arm_ext_v8_1m_main
e39c1607
SD
26307 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26308 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26309 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26310 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26311 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26312 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26313 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26314 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26315 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26316
4389b29a 26317 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
f6b2b12d 26318 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
f1c7f421 26319 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
65d1bc05 26320 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
f1c7f421 26321 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
60f993ce
AV
26322
26323 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26324 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26325 toU("le", _le, 2, (oLR, EXP), t_loloop),
4b5a202f 26326
efd6b359 26327 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
5ee91343
AV
26328 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26329
26330#undef THUMB_VARIANT
26331#define THUMB_VARIANT & mve_ext
23d00a41
SD
26332 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26333 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26334 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
08132bdd
SP
26335 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26336 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
23d00a41
SD
26337 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26338 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26339 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26340 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26341 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26342 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26343 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26344 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26345 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26346 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
1b883319
AV
26347
26348 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26349 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26350 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26351 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26352 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26353 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26354 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26355 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26356 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26357 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26358 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26359 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26360 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26361 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26362 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26363
5ee91343
AV
26364 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26365 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26366 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26367 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26368 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26369 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26370 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26371 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26372 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26373 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26374 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26375 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26376 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26377 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26378 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26379
a302e574 26380 /* MVE and MVE FP only. */
7df54120 26381 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
efd0b310 26382 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
c2dafc2a
AV
26383 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26384 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26385 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26386 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
886e1c73 26387 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
a302e574
AV
26388 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26389 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26390 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26391 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26392 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26393 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26394 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26395 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26396 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26397 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26398 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26399
35c228db
AV
26400 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26401 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26402 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26403 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26404 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26405 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26406 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26407 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26408 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26409 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26410 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26411 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
f5f10c66
AV
26412 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26413 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26414 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26415 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26416 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26417 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26418 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26419 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
35c228db 26420
57785aa2
AV
26421 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26422 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
c2dafc2a 26423 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26c1e780
AV
26424 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26425 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26426 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26427 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
b409bdb6
AV
26428 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26429 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26430 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26431 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
935295b5
AV
26432 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26433 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
13ccd4c0
AV
26434 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26435 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26436 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26437 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
57785aa2 26438
93925576
AV
26439 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26440 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26441 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26442 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26443 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26444 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26445 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26446 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26447 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26448 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26449 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26450 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26451 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26452 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26453 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26454 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26455 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26456 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26457 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26458 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26459
2d78f95b
AV
26460 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26461 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26462 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
3063888e
AV
26463 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26464 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
2d78f95b 26465
8b8b22a4
AV
26466 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26467 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26468 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26469 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26470 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26471 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26472 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26473 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
42b16635
AV
26474 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26475 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26476 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
35d1cfc2
AV
26477 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26478 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
1be7aba3
AV
26479 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26480 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26481 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26482 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
8b8b22a4 26483
4aa88b50
AV
26484 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26485 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26486 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26487 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26488 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26489 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26490 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26491 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26492 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26493 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26494 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26495 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26496
acca5630
AV
26497 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26498 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26499 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26500
1f6234a3
AV
26501 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26502 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26503 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26504 toU("lctp", _lctp, 0, (), t_loloop),
26505
5d281bf0
AV
26506#undef THUMB_VARIANT
26507#define THUMB_VARIANT & mve_fp_ext
26508 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
f30ee27c 26509 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
935295b5
AV
26510 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26511 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
8cd78170
AV
26512 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26513 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26514 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26515 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
5d281bf0 26516
5ee91343 26517#undef ARM_VARIANT
57785aa2 26518#define ARM_VARIANT & fpu_vfp_ext_v1
5ee91343
AV
26519#undef THUMB_VARIANT
26520#define THUMB_VARIANT & arm_ext_v6t2
26521
57785aa2
AV
26522 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26523
26524#undef ARM_VARIANT
26525#define ARM_VARIANT & fpu_vfp_ext_v1xd
26526
48f4d8ce
AV
26527 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26528 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
57785aa2
AV
26529 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26530 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26531 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26532 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26533
886e1c73
AV
26534 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26535 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26536 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
5ee91343 26537
485dee97
AV
26538 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26539 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26540
57785aa2
AV
26541 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26542 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26543
1b883319
AV
26544 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26545 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26546
57785aa2
AV
26547#undef ARM_VARIANT
26548#define ARM_VARIANT & fpu_vfp_ext_v2
26549
26550 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26551 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26552 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26553 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26554
dd9634d9
AV
26555#undef ARM_VARIANT
26556#define ARM_VARIANT & fpu_vfp_ext_armv8xd
26557 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26558 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26559 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26560 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
935295b5
AV
26561 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26562 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
dd9634d9
AV
26563
26564#undef ARM_VARIANT
5ee91343 26565#define ARM_VARIANT & fpu_neon_ext_v1
f601a00c 26566 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
5ee91343 26567 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
66d1f7cc
AV
26568 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26569 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
f601a00c
AV
26570 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26571 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26572 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26573 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26574 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
f30ee27c
AV
26575 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26576 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
b409bdb6 26577 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
7df54120
AV
26578 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26579 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26580 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
935295b5
AV
26581 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26582 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
a8465a06
AV
26583 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26584 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
1a186d29
AV
26585 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26586 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26587 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
42b16635
AV
26588 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26589 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26590 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
1be7aba3
AV
26591 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26592 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
4401c241
AV
26593 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26594 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26595 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26596 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26597 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26598 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26599 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
5150f0d8
AV
26600 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26601 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26602 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
5d281bf0
AV
26603
26604#undef ARM_VARIANT
26605#define ARM_VARIANT & arm_ext_v8_3
26606#undef THUMB_VARIANT
26607#define THUMB_VARIANT & arm_ext_v6t2_v8m
26608 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26609 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
aab2c27d
MM
26610
26611#undef ARM_VARIANT
26612#define ARM_VARIANT &arm_ext_bf16
26613#undef THUMB_VARIANT
26614#define THUMB_VARIANT &arm_ext_bf16
26615 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26616 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26617 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26618
26619#undef ARM_VARIANT
26620#define ARM_VARIANT &arm_ext_i8mm
26621#undef THUMB_VARIANT
26622#define THUMB_VARIANT &arm_ext_i8mm
26623 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26624 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
616ce08e 26625 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
aab2c27d
MM
26626 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26627 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
4934a27c
MM
26628
26629#undef ARM_VARIANT
26630#undef THUMB_VARIANT
26631#define THUMB_VARIANT &arm_ext_cde
26632 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26633 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26634 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26635 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26636
26637 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26638 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26639 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26640 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26641
26642 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26643 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26644 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26645 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
5aae9ae9
MM
26646
26647 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26648 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26649
26650 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26651 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26652
26653 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26654 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
c19d1205 26655};
5aae9ae9 26656
c19d1205
ZW
26657#undef ARM_VARIANT
26658#undef THUMB_VARIANT
26659#undef TCE
c19d1205
ZW
26660#undef TUE
26661#undef TUF
26662#undef TCC
8f06b2d8 26663#undef cCE
e3cb604e
PB
26664#undef cCL
26665#undef C3E
4389b29a 26666#undef C3
c19d1205
ZW
26667#undef CE
26668#undef CM
4389b29a 26669#undef CL
c19d1205
ZW
26670#undef UE
26671#undef UF
26672#undef UT
5287ad62
JB
26673#undef NUF
26674#undef nUF
26675#undef NCE
26676#undef nCE
c19d1205
ZW
26677#undef OPS0
26678#undef OPS1
26679#undef OPS2
26680#undef OPS3
26681#undef OPS4
26682#undef OPS5
26683#undef OPS6
26684#undef do_0
4389b29a
AV
26685#undef ToC
26686#undef toC
26687#undef ToU
f6b2b12d 26688#undef toU
c19d1205
ZW
26689\f
26690/* MD interface: bits in the object file. */
bfae80f2 26691
c19d1205
ZW
26692/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26693 for use in the a.out file, and stores them in the array pointed to by buf.
26694 This knows about the endian-ness of the target machine and does
26695 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26696 2 (short) and 4 (long) Floating numbers are put out as a series of
26697 LITTLENUMS (shorts, here at least). */
b99bd4ef 26698
c19d1205
ZW
26699void
26700md_number_to_chars (char * buf, valueT val, int n)
26701{
26702 if (target_big_endian)
26703 number_to_chars_bigendian (buf, val, n);
26704 else
26705 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
26706}
26707
c19d1205
ZW
26708static valueT
26709md_chars_to_number (char * buf, int n)
bfae80f2 26710{
c19d1205
ZW
26711 valueT result = 0;
26712 unsigned char * where = (unsigned char *) buf;
bfae80f2 26713
c19d1205 26714 if (target_big_endian)
b99bd4ef 26715 {
c19d1205
ZW
26716 while (n--)
26717 {
26718 result <<= 8;
26719 result |= (*where++ & 255);
26720 }
b99bd4ef 26721 }
c19d1205 26722 else
b99bd4ef 26723 {
c19d1205
ZW
26724 while (n--)
26725 {
26726 result <<= 8;
26727 result |= (where[n] & 255);
26728 }
bfae80f2 26729 }
b99bd4ef 26730
c19d1205 26731 return result;
bfae80f2 26732}
b99bd4ef 26733
c19d1205 26734/* MD interface: Sections. */
b99bd4ef 26735
fa94de6b
RM
26736/* Calculate the maximum variable size (i.e., excluding fr_fix)
26737 that an rs_machine_dependent frag may reach. */
26738
26739unsigned int
26740arm_frag_max_var (fragS *fragp)
26741{
26742 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26743 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26744
26745 Note that we generate relaxable instructions even for cases that don't
26746 really need it, like an immediate that's a trivial constant. So we're
26747 overestimating the instruction size for some of those cases. Rather
26748 than putting more intelligence here, it would probably be better to
26749 avoid generating a relaxation frag in the first place when it can be
26750 determined up front that a short instruction will suffice. */
26751
26752 gas_assert (fragp->fr_type == rs_machine_dependent);
26753 return INSN_SIZE;
26754}
26755
0110f2b8
PB
26756/* Estimate the size of a frag before relaxing. Assume everything fits in
26757 2 bytes. */
26758
c19d1205 26759int
0110f2b8 26760md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
26761 segT segtype ATTRIBUTE_UNUSED)
26762{
0110f2b8
PB
26763 fragp->fr_var = 2;
26764 return 2;
26765}
26766
26767/* Convert a machine dependent frag. */
26768
26769void
26770md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26771{
26772 unsigned long insn;
26773 unsigned long old_op;
26774 char *buf;
26775 expressionS exp;
26776 fixS *fixp;
26777 int reloc_type;
26778 int pc_rel;
26779 int opcode;
26780
26781 buf = fragp->fr_literal + fragp->fr_fix;
26782
26783 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
26784 if (fragp->fr_symbol)
26785 {
0110f2b8
PB
26786 exp.X_op = O_symbol;
26787 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
26788 }
26789 else
26790 {
0110f2b8 26791 exp.X_op = O_constant;
5f4273c7 26792 }
0110f2b8
PB
26793 exp.X_add_number = fragp->fr_offset;
26794 opcode = fragp->fr_subtype;
26795 switch (opcode)
26796 {
26797 case T_MNEM_ldr_pc:
26798 case T_MNEM_ldr_pc2:
26799 case T_MNEM_ldr_sp:
26800 case T_MNEM_str_sp:
26801 case T_MNEM_ldr:
26802 case T_MNEM_ldrb:
26803 case T_MNEM_ldrh:
26804 case T_MNEM_str:
26805 case T_MNEM_strb:
26806 case T_MNEM_strh:
26807 if (fragp->fr_var == 4)
26808 {
5f4273c7 26809 insn = THUMB_OP32 (opcode);
0110f2b8
PB
26810 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26811 {
26812 insn |= (old_op & 0x700) << 4;
26813 }
26814 else
26815 {
26816 insn |= (old_op & 7) << 12;
26817 insn |= (old_op & 0x38) << 13;
26818 }
26819 insn |= 0x00000c00;
26820 put_thumb32_insn (buf, insn);
26821 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26822 }
26823 else
26824 {
26825 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26826 }
26827 pc_rel = (opcode == T_MNEM_ldr_pc2);
26828 break;
26829 case T_MNEM_adr:
26830 if (fragp->fr_var == 4)
26831 {
26832 insn = THUMB_OP32 (opcode);
26833 insn |= (old_op & 0xf0) << 4;
26834 put_thumb32_insn (buf, insn);
26835 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26836 }
26837 else
26838 {
26839 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26840 exp.X_add_number -= 4;
26841 }
26842 pc_rel = 1;
26843 break;
26844 case T_MNEM_mov:
26845 case T_MNEM_movs:
26846 case T_MNEM_cmp:
26847 case T_MNEM_cmn:
26848 if (fragp->fr_var == 4)
26849 {
26850 int r0off = (opcode == T_MNEM_mov
26851 || opcode == T_MNEM_movs) ? 0 : 8;
26852 insn = THUMB_OP32 (opcode);
26853 insn = (insn & 0xe1ffffff) | 0x10000000;
26854 insn |= (old_op & 0x700) << r0off;
26855 put_thumb32_insn (buf, insn);
26856 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26857 }
26858 else
26859 {
26860 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26861 }
26862 pc_rel = 0;
26863 break;
26864 case T_MNEM_b:
26865 if (fragp->fr_var == 4)
26866 {
26867 insn = THUMB_OP32(opcode);
26868 put_thumb32_insn (buf, insn);
26869 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26870 }
26871 else
26872 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26873 pc_rel = 1;
26874 break;
26875 case T_MNEM_bcond:
26876 if (fragp->fr_var == 4)
26877 {
26878 insn = THUMB_OP32(opcode);
26879 insn |= (old_op & 0xf00) << 14;
26880 put_thumb32_insn (buf, insn);
26881 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26882 }
26883 else
26884 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26885 pc_rel = 1;
26886 break;
26887 case T_MNEM_add_sp:
26888 case T_MNEM_add_pc:
26889 case T_MNEM_inc_sp:
26890 case T_MNEM_dec_sp:
26891 if (fragp->fr_var == 4)
26892 {
26893 /* ??? Choose between add and addw. */
26894 insn = THUMB_OP32 (opcode);
26895 insn |= (old_op & 0xf0) << 4;
26896 put_thumb32_insn (buf, insn);
16805f35
PB
26897 if (opcode == T_MNEM_add_pc)
26898 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26899 else
26900 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
26901 }
26902 else
26903 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26904 pc_rel = 0;
26905 break;
26906
26907 case T_MNEM_addi:
26908 case T_MNEM_addis:
26909 case T_MNEM_subi:
26910 case T_MNEM_subis:
26911 if (fragp->fr_var == 4)
26912 {
26913 insn = THUMB_OP32 (opcode);
26914 insn |= (old_op & 0xf0) << 4;
26915 insn |= (old_op & 0xf) << 16;
26916 put_thumb32_insn (buf, insn);
16805f35
PB
26917 if (insn & (1 << 20))
26918 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26919 else
26920 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
26921 }
26922 else
26923 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26924 pc_rel = 0;
26925 break;
26926 default:
5f4273c7 26927 abort ();
0110f2b8
PB
26928 }
26929 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 26930 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
26931 fixp->fx_file = fragp->fr_file;
26932 fixp->fx_line = fragp->fr_line;
26933 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
26934
26935 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26936 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26937 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26938 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
26939}
26940
26941/* Return the size of a relaxable immediate operand instruction.
26942 SHIFT and SIZE specify the form of the allowable immediate. */
26943static int
26944relax_immediate (fragS *fragp, int size, int shift)
26945{
26946 offsetT offset;
26947 offsetT mask;
26948 offsetT low;
26949
26950 /* ??? Should be able to do better than this. */
26951 if (fragp->fr_symbol)
26952 return 4;
26953
26954 low = (1 << shift) - 1;
26955 mask = (1 << (shift + size)) - (1 << shift);
26956 offset = fragp->fr_offset;
26957 /* Force misaligned offsets to 32-bit variant. */
26958 if (offset & low)
5e77afaa 26959 return 4;
0110f2b8
PB
26960 if (offset & ~mask)
26961 return 4;
26962 return 2;
26963}
26964
5e77afaa
PB
26965/* Get the address of a symbol during relaxation. */
26966static addressT
5f4273c7 26967relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
26968{
26969 fragS *sym_frag;
26970 addressT addr;
26971 symbolS *sym;
26972
26973 sym = fragp->fr_symbol;
26974 sym_frag = symbol_get_frag (sym);
26975 know (S_GET_SEGMENT (sym) != absolute_section
26976 || sym_frag == &zero_address_frag);
26977 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26978
26979 /* If frag has yet to be reached on this pass, assume it will
26980 move by STRETCH just as we did. If this is not so, it will
26981 be because some frag between grows, and that will force
26982 another pass. */
26983
26984 if (stretch != 0
26985 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
26986 {
26987 fragS *f;
26988
26989 /* Adjust stretch for any alignment frag. Note that if have
26990 been expanding the earlier code, the symbol may be
26991 defined in what appears to be an earlier frag. FIXME:
26992 This doesn't handle the fr_subtype field, which specifies
26993 a maximum number of bytes to skip when doing an
26994 alignment. */
26995 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26996 {
26997 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26998 {
26999 if (stretch < 0)
27000 stretch = - ((- stretch)
27001 & ~ ((1 << (int) f->fr_offset) - 1));
27002 else
27003 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
27004 if (stretch == 0)
27005 break;
27006 }
27007 }
27008 if (f != NULL)
27009 addr += stretch;
27010 }
5e77afaa
PB
27011
27012 return addr;
27013}
27014
0110f2b8
PB
27015/* Return the size of a relaxable adr pseudo-instruction or PC-relative
27016 load. */
27017static int
5e77afaa 27018relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
27019{
27020 addressT addr;
27021 offsetT val;
27022
27023 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
27024 if (fragp->fr_symbol == NULL
27025 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27026 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27027 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27028 return 4;
27029
5f4273c7 27030 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27031 addr = fragp->fr_address + fragp->fr_fix;
27032 addr = (addr + 4) & ~3;
5e77afaa 27033 /* Force misaligned targets to 32-bit variant. */
0110f2b8 27034 if (val & 3)
5e77afaa 27035 return 4;
0110f2b8
PB
27036 val -= addr;
27037 if (val < 0 || val > 1020)
27038 return 4;
27039 return 2;
27040}
27041
27042/* Return the size of a relaxable add/sub immediate instruction. */
27043static int
27044relax_addsub (fragS *fragp, asection *sec)
27045{
27046 char *buf;
27047 int op;
27048
27049 buf = fragp->fr_literal + fragp->fr_fix;
27050 op = bfd_get_16(sec->owner, buf);
27051 if ((op & 0xf) == ((op >> 4) & 0xf))
27052 return relax_immediate (fragp, 8, 0);
27053 else
27054 return relax_immediate (fragp, 3, 0);
27055}
27056
e83a675f
RE
27057/* Return TRUE iff the definition of symbol S could be pre-empted
27058 (overridden) at link or load time. */
27059static bfd_boolean
27060symbol_preemptible (symbolS *s)
27061{
27062 /* Weak symbols can always be pre-empted. */
27063 if (S_IS_WEAK (s))
27064 return TRUE;
27065
27066 /* Non-global symbols cannot be pre-empted. */
27067 if (! S_IS_EXTERNAL (s))
27068 return FALSE;
27069
27070#ifdef OBJ_ELF
27071 /* In ELF, a global symbol can be marked protected, or private. In that
27072 case it can't be pre-empted (other definitions in the same link unit
27073 would violate the ODR). */
27074 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27075 return FALSE;
27076#endif
27077
27078 /* Other global symbols might be pre-empted. */
27079 return TRUE;
27080}
0110f2b8
PB
27081
27082/* Return the size of a relaxable branch instruction. BITS is the
27083 size of the offset field in the narrow instruction. */
27084
27085static int
5e77afaa 27086relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
27087{
27088 addressT addr;
27089 offsetT val;
27090 offsetT limit;
27091
27092 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 27093 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
27094 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27095 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
27096 return 4;
27097
267bf995 27098#ifdef OBJ_ELF
e83a675f 27099 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
27100 if (S_IS_DEFINED (fragp->fr_symbol)
27101 && ARM_IS_FUNC (fragp->fr_symbol))
27102 return 4;
e83a675f 27103#endif
0d9b4b55 27104
e83a675f 27105 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 27106 return 4;
267bf995 27107
5f4273c7 27108 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
27109 addr = fragp->fr_address + fragp->fr_fix + 4;
27110 val -= addr;
27111
27112 /* Offset is a signed value *2 */
27113 limit = 1 << bits;
27114 if (val >= limit || val < -limit)
27115 return 4;
27116 return 2;
27117}
27118
27119
27120/* Relax a machine dependent frag. This returns the amount by which
27121 the current size of the frag should change. */
27122
27123int
5e77afaa 27124arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
27125{
27126 int oldsize;
27127 int newsize;
27128
27129 oldsize = fragp->fr_var;
27130 switch (fragp->fr_subtype)
27131 {
27132 case T_MNEM_ldr_pc2:
5f4273c7 27133 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27134 break;
27135 case T_MNEM_ldr_pc:
27136 case T_MNEM_ldr_sp:
27137 case T_MNEM_str_sp:
5f4273c7 27138 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
27139 break;
27140 case T_MNEM_ldr:
27141 case T_MNEM_str:
5f4273c7 27142 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
27143 break;
27144 case T_MNEM_ldrh:
27145 case T_MNEM_strh:
5f4273c7 27146 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
27147 break;
27148 case T_MNEM_ldrb:
27149 case T_MNEM_strb:
5f4273c7 27150 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
27151 break;
27152 case T_MNEM_adr:
5f4273c7 27153 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
27154 break;
27155 case T_MNEM_mov:
27156 case T_MNEM_movs:
27157 case T_MNEM_cmp:
27158 case T_MNEM_cmn:
5f4273c7 27159 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
27160 break;
27161 case T_MNEM_b:
5f4273c7 27162 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
27163 break;
27164 case T_MNEM_bcond:
5f4273c7 27165 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
27166 break;
27167 case T_MNEM_add_sp:
27168 case T_MNEM_add_pc:
27169 newsize = relax_immediate (fragp, 8, 2);
27170 break;
27171 case T_MNEM_inc_sp:
27172 case T_MNEM_dec_sp:
27173 newsize = relax_immediate (fragp, 7, 2);
27174 break;
27175 case T_MNEM_addi:
27176 case T_MNEM_addis:
27177 case T_MNEM_subi:
27178 case T_MNEM_subis:
27179 newsize = relax_addsub (fragp, sec);
27180 break;
27181 default:
5f4273c7 27182 abort ();
0110f2b8 27183 }
5e77afaa
PB
27184
27185 fragp->fr_var = newsize;
27186 /* Freeze wide instructions that are at or before the same location as
27187 in the previous pass. This avoids infinite loops.
5f4273c7
NC
27188 Don't freeze them unconditionally because targets may be artificially
27189 misaligned by the expansion of preceding frags. */
5e77afaa 27190 if (stretch <= 0 && newsize > 2)
0110f2b8 27191 {
0110f2b8 27192 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 27193 frag_wane (fragp);
0110f2b8 27194 }
5e77afaa 27195
0110f2b8 27196 return newsize - oldsize;
c19d1205 27197}
b99bd4ef 27198
c19d1205 27199/* Round up a section size to the appropriate boundary. */
b99bd4ef 27200
c19d1205
ZW
27201valueT
27202md_section_align (segT segment ATTRIBUTE_UNUSED,
27203 valueT size)
27204{
6844c0cc 27205 return size;
bfae80f2 27206}
b99bd4ef 27207
c19d1205
ZW
27208/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27209 of an rs_align_code fragment. */
27210
27211void
27212arm_handle_align (fragS * fragP)
bfae80f2 27213{
d9235011 27214 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
27215 {
27216 { /* ARMv1 */
27217 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27218 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27219 },
27220 { /* ARMv6k */
27221 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27222 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27223 },
27224 };
d9235011 27225 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
27226 {
27227 { /* Thumb-1 */
27228 {0xc0, 0x46}, /* LE */
27229 {0x46, 0xc0}, /* BE */
27230 },
27231 { /* Thumb-2 */
27232 {0x00, 0xbf}, /* LE */
27233 {0xbf, 0x00} /* BE */
27234 }
27235 };
d9235011 27236 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
27237 { /* Wide Thumb-2 */
27238 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27239 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27240 };
c921be7d 27241
e7495e45 27242 unsigned bytes, fix, noop_size;
c19d1205 27243 char * p;
d9235011
TS
27244 const unsigned char * noop;
27245 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
27246#ifdef OBJ_ELF
27247 enum mstate state;
27248#endif
bfae80f2 27249
c19d1205 27250 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
27251 return;
27252
c19d1205
ZW
27253 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27254 p = fragP->fr_literal + fragP->fr_fix;
27255 fix = 0;
bfae80f2 27256
c19d1205
ZW
27257 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27258 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 27259
cd000bff 27260 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 27261
cd000bff 27262 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 27263 {
7f78eb34
JW
27264 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27265 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
27266 {
27267 narrow_noop = thumb_noop[1][target_big_endian];
27268 noop = wide_thumb_noop[target_big_endian];
27269 }
c19d1205 27270 else
e7495e45
NS
27271 noop = thumb_noop[0][target_big_endian];
27272 noop_size = 2;
cd000bff
DJ
27273#ifdef OBJ_ELF
27274 state = MAP_THUMB;
27275#endif
7ed4c4c5
NC
27276 }
27277 else
27278 {
7f78eb34
JW
27279 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27280 ? selected_cpu : arm_arch_none,
27281 arm_ext_v6k) != 0]
e7495e45
NS
27282 [target_big_endian];
27283 noop_size = 4;
cd000bff
DJ
27284#ifdef OBJ_ELF
27285 state = MAP_ARM;
27286#endif
7ed4c4c5 27287 }
c921be7d 27288
e7495e45 27289 fragP->fr_var = noop_size;
c921be7d 27290
c19d1205 27291 if (bytes & (noop_size - 1))
7ed4c4c5 27292 {
c19d1205 27293 fix = bytes & (noop_size - 1);
cd000bff
DJ
27294#ifdef OBJ_ELF
27295 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27296#endif
c19d1205
ZW
27297 memset (p, 0, fix);
27298 p += fix;
27299 bytes -= fix;
a737bd4d 27300 }
a737bd4d 27301
e7495e45
NS
27302 if (narrow_noop)
27303 {
27304 if (bytes & noop_size)
27305 {
27306 /* Insert a narrow noop. */
27307 memcpy (p, narrow_noop, noop_size);
27308 p += noop_size;
27309 bytes -= noop_size;
27310 fix += noop_size;
27311 }
27312
27313 /* Use wide noops for the remainder */
27314 noop_size = 4;
27315 }
27316
c19d1205 27317 while (bytes >= noop_size)
a737bd4d 27318 {
c19d1205
ZW
27319 memcpy (p, noop, noop_size);
27320 p += noop_size;
27321 bytes -= noop_size;
27322 fix += noop_size;
a737bd4d
NC
27323 }
27324
c19d1205 27325 fragP->fr_fix += fix;
a737bd4d
NC
27326}
27327
c19d1205
ZW
27328/* Called from md_do_align. Used to create an alignment
27329 frag in a code section. */
27330
27331void
27332arm_frag_align_code (int n, int max)
bfae80f2 27333{
c19d1205 27334 char * p;
7ed4c4c5 27335
c19d1205 27336 /* We assume that there will never be a requirement
6ec8e702 27337 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 27338 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
27339 {
27340 char err_msg[128];
27341
fa94de6b 27342 sprintf (err_msg,
477330fc
RM
27343 _("alignments greater than %d bytes not supported in .text sections."),
27344 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 27345 as_fatal ("%s", err_msg);
6ec8e702 27346 }
bfae80f2 27347
c19d1205
ZW
27348 p = frag_var (rs_align_code,
27349 MAX_MEM_FOR_RS_ALIGN_CODE,
27350 1,
27351 (relax_substateT) max,
27352 (symbolS *) NULL,
27353 (offsetT) n,
27354 (char *) NULL);
27355 *p = 0;
27356}
bfae80f2 27357
8dc2430f
NC
27358/* Perform target specific initialisation of a frag.
27359 Note - despite the name this initialisation is not done when the frag
27360 is created, but only when its type is assigned. A frag can be created
27361 and used a long time before its type is set, so beware of assuming that
33eaf5de 27362 this initialisation is performed first. */
bfae80f2 27363
cd000bff
DJ
27364#ifndef OBJ_ELF
27365void
27366arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27367{
27368 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 27369 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
27370}
27371
27372#else /* OBJ_ELF is defined. */
c19d1205 27373void
cd000bff 27374arm_init_frag (fragS * fragP, int max_chars)
c19d1205 27375{
e8d84ca1 27376 bfd_boolean frag_thumb_mode;
b968d18a 27377
8dc2430f
NC
27378 /* If the current ARM vs THUMB mode has not already
27379 been recorded into this frag then do so now. */
cd000bff 27380 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
27381 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27382
e8d84ca1
NC
27383 /* PR 21809: Do not set a mapping state for debug sections
27384 - it just confuses other tools. */
fd361982 27385 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
e8d84ca1
NC
27386 return;
27387
b968d18a 27388 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 27389
f9c1b181
RL
27390 /* Record a mapping symbol for alignment frags. We will delete this
27391 later if the alignment ends up empty. */
27392 switch (fragP->fr_type)
27393 {
27394 case rs_align:
27395 case rs_align_test:
27396 case rs_fill:
27397 mapping_state_2 (MAP_DATA, max_chars);
27398 break;
27399 case rs_align_code:
b968d18a 27400 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
27401 break;
27402 default:
27403 break;
cd000bff 27404 }
bfae80f2
RE
27405}
27406
c19d1205
ZW
27407/* When we change sections we need to issue a new mapping symbol. */
27408
27409void
27410arm_elf_change_section (void)
bfae80f2 27411{
c19d1205
ZW
27412 /* Link an unlinked unwind index table section to the .text section. */
27413 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27414 && elf_linked_to_section (now_seg) == NULL)
27415 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
27416}
27417
c19d1205
ZW
27418int
27419arm_elf_section_type (const char * str, size_t len)
e45d0630 27420{
c19d1205
ZW
27421 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27422 return SHT_ARM_EXIDX;
e45d0630 27423
c19d1205
ZW
27424 return -1;
27425}
27426\f
27427/* Code to deal with unwinding tables. */
e45d0630 27428
c19d1205 27429static void add_unwind_adjustsp (offsetT);
e45d0630 27430
5f4273c7 27431/* Generate any deferred unwind frame offset. */
e45d0630 27432
bfae80f2 27433static void
c19d1205 27434flush_pending_unwind (void)
bfae80f2 27435{
c19d1205 27436 offsetT offset;
bfae80f2 27437
c19d1205
ZW
27438 offset = unwind.pending_offset;
27439 unwind.pending_offset = 0;
27440 if (offset != 0)
27441 add_unwind_adjustsp (offset);
bfae80f2
RE
27442}
27443
c19d1205
ZW
27444/* Add an opcode to this list for this function. Two-byte opcodes should
27445 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27446 order. */
27447
bfae80f2 27448static void
c19d1205 27449add_unwind_opcode (valueT op, int length)
bfae80f2 27450{
c19d1205
ZW
27451 /* Add any deferred stack adjustment. */
27452 if (unwind.pending_offset)
27453 flush_pending_unwind ();
bfae80f2 27454
c19d1205 27455 unwind.sp_restored = 0;
bfae80f2 27456
c19d1205 27457 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 27458 {
c19d1205
ZW
27459 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27460 if (unwind.opcodes)
325801bd
TS
27461 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27462 unwind.opcode_alloc);
c19d1205 27463 else
325801bd 27464 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 27465 }
c19d1205 27466 while (length > 0)
bfae80f2 27467 {
c19d1205
ZW
27468 length--;
27469 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27470 op >>= 8;
27471 unwind.opcode_count++;
bfae80f2 27472 }
bfae80f2
RE
27473}
27474
c19d1205
ZW
27475/* Add unwind opcodes to adjust the stack pointer. */
27476
bfae80f2 27477static void
c19d1205 27478add_unwind_adjustsp (offsetT offset)
bfae80f2 27479{
c19d1205 27480 valueT op;
bfae80f2 27481
c19d1205 27482 if (offset > 0x200)
bfae80f2 27483 {
c19d1205
ZW
27484 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27485 char bytes[5];
27486 int n;
27487 valueT o;
bfae80f2 27488
c19d1205
ZW
27489 /* Long form: 0xb2, uleb128. */
27490 /* This might not fit in a word so add the individual bytes,
27491 remembering the list is built in reverse order. */
27492 o = (valueT) ((offset - 0x204) >> 2);
27493 if (o == 0)
27494 add_unwind_opcode (0, 1);
bfae80f2 27495
c19d1205
ZW
27496 /* Calculate the uleb128 encoding of the offset. */
27497 n = 0;
27498 while (o)
27499 {
27500 bytes[n] = o & 0x7f;
27501 o >>= 7;
27502 if (o)
27503 bytes[n] |= 0x80;
27504 n++;
27505 }
27506 /* Add the insn. */
27507 for (; n; n--)
27508 add_unwind_opcode (bytes[n - 1], 1);
27509 add_unwind_opcode (0xb2, 1);
27510 }
27511 else if (offset > 0x100)
bfae80f2 27512 {
c19d1205
ZW
27513 /* Two short opcodes. */
27514 add_unwind_opcode (0x3f, 1);
27515 op = (offset - 0x104) >> 2;
27516 add_unwind_opcode (op, 1);
bfae80f2 27517 }
c19d1205
ZW
27518 else if (offset > 0)
27519 {
27520 /* Short opcode. */
27521 op = (offset - 4) >> 2;
27522 add_unwind_opcode (op, 1);
27523 }
27524 else if (offset < 0)
bfae80f2 27525 {
c19d1205
ZW
27526 offset = -offset;
27527 while (offset > 0x100)
bfae80f2 27528 {
c19d1205
ZW
27529 add_unwind_opcode (0x7f, 1);
27530 offset -= 0x100;
bfae80f2 27531 }
c19d1205
ZW
27532 op = ((offset - 4) >> 2) | 0x40;
27533 add_unwind_opcode (op, 1);
bfae80f2 27534 }
bfae80f2
RE
27535}
27536
c19d1205 27537/* Finish the list of unwind opcodes for this function. */
0198d5e6 27538
c19d1205
ZW
27539static void
27540finish_unwind_opcodes (void)
bfae80f2 27541{
c19d1205 27542 valueT op;
bfae80f2 27543
c19d1205 27544 if (unwind.fp_used)
bfae80f2 27545 {
708587a4 27546 /* Adjust sp as necessary. */
c19d1205
ZW
27547 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27548 flush_pending_unwind ();
bfae80f2 27549
c19d1205
ZW
27550 /* After restoring sp from the frame pointer. */
27551 op = 0x90 | unwind.fp_reg;
27552 add_unwind_opcode (op, 1);
27553 }
27554 else
27555 flush_pending_unwind ();
bfae80f2
RE
27556}
27557
bfae80f2 27558
c19d1205
ZW
27559/* Start an exception table entry. If idx is nonzero this is an index table
27560 entry. */
bfae80f2
RE
27561
27562static void
c19d1205 27563start_unwind_section (const segT text_seg, int idx)
bfae80f2 27564{
c19d1205
ZW
27565 const char * text_name;
27566 const char * prefix;
27567 const char * prefix_once;
a8c4d40b 27568 struct elf_section_match match;
c19d1205 27569 char * sec_name;
c19d1205
ZW
27570 int type;
27571 int flags;
27572 int linkonce;
bfae80f2 27573
c19d1205 27574 if (idx)
bfae80f2 27575 {
c19d1205
ZW
27576 prefix = ELF_STRING_ARM_unwind;
27577 prefix_once = ELF_STRING_ARM_unwind_once;
27578 type = SHT_ARM_EXIDX;
bfae80f2 27579 }
c19d1205 27580 else
bfae80f2 27581 {
c19d1205
ZW
27582 prefix = ELF_STRING_ARM_unwind_info;
27583 prefix_once = ELF_STRING_ARM_unwind_info_once;
27584 type = SHT_PROGBITS;
bfae80f2
RE
27585 }
27586
c19d1205
ZW
27587 text_name = segment_name (text_seg);
27588 if (streq (text_name, ".text"))
27589 text_name = "";
27590
27591 if (strncmp (text_name, ".gnu.linkonce.t.",
27592 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 27593 {
c19d1205
ZW
27594 prefix = prefix_once;
27595 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
27596 }
27597
29a2809e 27598 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 27599
c19d1205
ZW
27600 flags = SHF_ALLOC;
27601 linkonce = 0;
a8c4d40b 27602 memset (&match, 0, sizeof (match));
bfae80f2 27603
c19d1205
ZW
27604 /* Handle COMDAT group. */
27605 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 27606 {
a8c4d40b
L
27607 match.group_name = elf_group_name (text_seg);
27608 if (match.group_name == NULL)
c19d1205 27609 {
bd3ba5d1 27610 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
27611 segment_name (text_seg));
27612 ignore_rest_of_line ();
27613 return;
27614 }
27615 flags |= SHF_GROUP;
27616 linkonce = 1;
bfae80f2
RE
27617 }
27618
a8c4d40b 27619 obj_elf_change_section (sec_name, type, flags, 0, &match,
a91e1603 27620 linkonce, 0);
bfae80f2 27621
5f4273c7 27622 /* Set the section link for index tables. */
c19d1205
ZW
27623 if (idx)
27624 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
27625}
27626
bfae80f2 27627
c19d1205
ZW
27628/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27629 personality routine data. Returns zero, or the index table value for
cad0da33 27630 an inline entry. */
c19d1205
ZW
27631
27632static valueT
27633create_unwind_entry (int have_data)
bfae80f2 27634{
c19d1205
ZW
27635 int size;
27636 addressT where;
27637 char *ptr;
27638 /* The current word of data. */
27639 valueT data;
27640 /* The number of bytes left in this word. */
27641 int n;
bfae80f2 27642
c19d1205 27643 finish_unwind_opcodes ();
bfae80f2 27644
c19d1205
ZW
27645 /* Remember the current text section. */
27646 unwind.saved_seg = now_seg;
27647 unwind.saved_subseg = now_subseg;
bfae80f2 27648
c19d1205 27649 start_unwind_section (now_seg, 0);
bfae80f2 27650
c19d1205 27651 if (unwind.personality_routine == NULL)
bfae80f2 27652 {
c19d1205
ZW
27653 if (unwind.personality_index == -2)
27654 {
27655 if (have_data)
5f4273c7 27656 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
27657 return 1; /* EXIDX_CANTUNWIND. */
27658 }
bfae80f2 27659
c19d1205
ZW
27660 /* Use a default personality routine if none is specified. */
27661 if (unwind.personality_index == -1)
27662 {
27663 if (unwind.opcode_count > 3)
27664 unwind.personality_index = 1;
27665 else
27666 unwind.personality_index = 0;
27667 }
bfae80f2 27668
c19d1205
ZW
27669 /* Space for the personality routine entry. */
27670 if (unwind.personality_index == 0)
27671 {
27672 if (unwind.opcode_count > 3)
27673 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 27674
c19d1205
ZW
27675 if (!have_data)
27676 {
27677 /* All the data is inline in the index table. */
27678 data = 0x80;
27679 n = 3;
27680 while (unwind.opcode_count > 0)
27681 {
27682 unwind.opcode_count--;
27683 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27684 n--;
27685 }
bfae80f2 27686
c19d1205
ZW
27687 /* Pad with "finish" opcodes. */
27688 while (n--)
27689 data = (data << 8) | 0xb0;
bfae80f2 27690
c19d1205
ZW
27691 return data;
27692 }
27693 size = 0;
27694 }
27695 else
27696 /* We get two opcodes "free" in the first word. */
27697 size = unwind.opcode_count - 2;
27698 }
27699 else
5011093d 27700 {
cad0da33
NC
27701 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27702 if (unwind.personality_index != -1)
27703 {
27704 as_bad (_("attempt to recreate an unwind entry"));
27705 return 1;
27706 }
5011093d
NC
27707
27708 /* An extra byte is required for the opcode count. */
27709 size = unwind.opcode_count + 1;
27710 }
bfae80f2 27711
c19d1205
ZW
27712 size = (size + 3) >> 2;
27713 if (size > 0xff)
27714 as_bad (_("too many unwind opcodes"));
bfae80f2 27715
c19d1205
ZW
27716 frag_align (2, 0, 0);
27717 record_alignment (now_seg, 2);
27718 unwind.table_entry = expr_build_dot ();
27719
27720 /* Allocate the table entry. */
27721 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
27722 /* PR 13449: Zero the table entries in case some of them are not used. */
27723 memset (ptr, 0, (size << 2) + 4);
c19d1205 27724 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 27725
c19d1205 27726 switch (unwind.personality_index)
bfae80f2 27727 {
c19d1205
ZW
27728 case -1:
27729 /* ??? Should this be a PLT generating relocation? */
27730 /* Custom personality routine. */
27731 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27732 BFD_RELOC_ARM_PREL31);
bfae80f2 27733
c19d1205
ZW
27734 where += 4;
27735 ptr += 4;
bfae80f2 27736
c19d1205 27737 /* Set the first byte to the number of additional words. */
5011093d 27738 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
27739 n = 3;
27740 break;
bfae80f2 27741
c19d1205
ZW
27742 /* ABI defined personality routines. */
27743 case 0:
27744 /* Three opcodes bytes are packed into the first word. */
27745 data = 0x80;
27746 n = 3;
27747 break;
bfae80f2 27748
c19d1205
ZW
27749 case 1:
27750 case 2:
27751 /* The size and first two opcode bytes go in the first word. */
27752 data = ((0x80 + unwind.personality_index) << 8) | size;
27753 n = 2;
27754 break;
bfae80f2 27755
c19d1205
ZW
27756 default:
27757 /* Should never happen. */
27758 abort ();
27759 }
bfae80f2 27760
c19d1205
ZW
27761 /* Pack the opcodes into words (MSB first), reversing the list at the same
27762 time. */
27763 while (unwind.opcode_count > 0)
27764 {
27765 if (n == 0)
27766 {
27767 md_number_to_chars (ptr, data, 4);
27768 ptr += 4;
27769 n = 4;
27770 data = 0;
27771 }
27772 unwind.opcode_count--;
27773 n--;
27774 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27775 }
27776
27777 /* Finish off the last word. */
27778 if (n < 4)
27779 {
27780 /* Pad with "finish" opcodes. */
27781 while (n--)
27782 data = (data << 8) | 0xb0;
27783
27784 md_number_to_chars (ptr, data, 4);
27785 }
27786
27787 if (!have_data)
27788 {
27789 /* Add an empty descriptor if there is no user-specified data. */
27790 ptr = frag_more (4);
27791 md_number_to_chars (ptr, 0, 4);
27792 }
27793
27794 return 0;
bfae80f2
RE
27795}
27796
f0927246
NC
27797
27798/* Initialize the DWARF-2 unwind information for this procedure. */
27799
27800void
27801tc_arm_frame_initial_instructions (void)
27802{
27803 cfi_add_CFA_def_cfa (REG_SP, 0);
27804}
27805#endif /* OBJ_ELF */
27806
c19d1205
ZW
27807/* Convert REGNAME to a DWARF-2 register number. */
27808
27809int
1df69f4f 27810tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 27811{
1df69f4f 27812 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
27813 if (reg != FAIL)
27814 return reg;
c19d1205 27815
1f5afe1c
NC
27816 /* PR 16694: Allow VFP registers as well. */
27817 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27818 if (reg != FAIL)
27819 return 64 + reg;
c19d1205 27820
1f5afe1c
NC
27821 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27822 if (reg != FAIL)
27823 return reg + 256;
27824
0198d5e6 27825 return FAIL;
bfae80f2
RE
27826}
27827
f0927246 27828#ifdef TE_PE
c19d1205 27829void
f0927246 27830tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 27831{
91d6fa6a 27832 expressionS exp;
bfae80f2 27833
91d6fa6a
NC
27834 exp.X_op = O_secrel;
27835 exp.X_add_symbol = symbol;
27836 exp.X_add_number = 0;
27837 emit_expr (&exp, size);
f0927246
NC
27838}
27839#endif
bfae80f2 27840
c19d1205 27841/* MD interface: Symbol and relocation handling. */
bfae80f2 27842
2fc8bdac
ZW
27843/* Return the address within the segment that a PC-relative fixup is
27844 relative to. For ARM, PC-relative fixups applied to instructions
27845 are generally relative to the location of the fixup plus 8 bytes.
27846 Thumb branches are offset by 4, and Thumb loads relative to PC
27847 require special handling. */
bfae80f2 27848
c19d1205 27849long
2fc8bdac 27850md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 27851{
2fc8bdac
ZW
27852 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27853
27854 /* If this is pc-relative and we are going to emit a relocation
27855 then we just want to put out any pipeline compensation that the linker
53baae48
NC
27856 will need. Otherwise we want to use the calculated base.
27857 For WinCE we skip the bias for externals as well, since this
27858 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 27859 if (fixP->fx_pcrel
2fc8bdac 27860 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
27861 || (arm_force_relocation (fixP)
27862#ifdef TE_WINCE
27863 && !S_IS_EXTERNAL (fixP->fx_addsy)
27864#endif
27865 )))
2fc8bdac 27866 base = 0;
bfae80f2 27867
267bf995 27868
c19d1205 27869 switch (fixP->fx_r_type)
bfae80f2 27870 {
2fc8bdac
ZW
27871 /* PC relative addressing on the Thumb is slightly odd as the
27872 bottom two bits of the PC are forced to zero for the
27873 calculation. This happens *after* application of the
27874 pipeline offset. However, Thumb adrl already adjusts for
27875 this, so we need not do it again. */
c19d1205 27876 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 27877 return base & ~3;
c19d1205
ZW
27878
27879 case BFD_RELOC_ARM_THUMB_OFFSET:
27880 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 27881 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 27882 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 27883 return (base + 4) & ~3;
c19d1205 27884
2fc8bdac 27885 /* Thumb branches are simply offset by +4. */
e12437dc 27886 case BFD_RELOC_THUMB_PCREL_BRANCH5:
2fc8bdac
ZW
27887 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27888 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27889 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27890 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 27891 case BFD_RELOC_THUMB_PCREL_BRANCH25:
f6b2b12d 27892 case BFD_RELOC_THUMB_PCREL_BFCSEL:
e5d6e09e 27893 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 27894 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 27895 case BFD_RELOC_ARM_THUMB_BF13:
60f993ce 27896 case BFD_RELOC_ARM_THUMB_LOOP12:
2fc8bdac 27897 return base + 4;
bfae80f2 27898
267bf995 27899 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
27900 if (fixP->fx_addsy
27901 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27902 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 27903 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
27904 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27905 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
27906 return base + 4;
27907
00adf2d4
JB
27908 /* BLX is like branches above, but forces the low two bits of PC to
27909 zero. */
486499d0
CL
27910 case BFD_RELOC_THUMB_PCREL_BLX:
27911 if (fixP->fx_addsy
27912 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27913 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27914 && THUMB_IS_FUNC (fixP->fx_addsy)
27915 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27916 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
27917 return (base + 4) & ~3;
27918
2fc8bdac
ZW
27919 /* ARM mode branches are offset by +8. However, the Windows CE
27920 loader expects the relocation not to take this into account. */
267bf995 27921 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
27922 if (fixP->fx_addsy
27923 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27924 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27925 && ARM_IS_FUNC (fixP->fx_addsy)
27926 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27927 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27928 return base + 8;
267bf995 27929
486499d0
CL
27930 case BFD_RELOC_ARM_PCREL_CALL:
27931 if (fixP->fx_addsy
27932 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 27933 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
27934 && THUMB_IS_FUNC (fixP->fx_addsy)
27935 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27936 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 27937 return base + 8;
267bf995 27938
2fc8bdac 27939 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 27940 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 27941 case BFD_RELOC_ARM_PLT32:
c19d1205 27942#ifdef TE_WINCE
5f4273c7 27943 /* When handling fixups immediately, because we have already
477330fc 27944 discovered the value of a symbol, or the address of the frag involved
53baae48 27945 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
27946 see fixup_segment() in write.c
27947 The S_IS_EXTERNAL test handles the case of global symbols.
27948 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
27949 if (fixP->fx_pcrel
27950 && fixP->fx_addsy != NULL
27951 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27952 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27953 return base + 8;
2fc8bdac 27954 return base;
c19d1205 27955#else
2fc8bdac 27956 return base + 8;
c19d1205 27957#endif
2fc8bdac 27958
267bf995 27959
2fc8bdac
ZW
27960 /* ARM mode loads relative to PC are also offset by +8. Unlike
27961 branches, the Windows CE loader *does* expect the relocation
27962 to take this into account. */
27963 case BFD_RELOC_ARM_OFFSET_IMM:
27964 case BFD_RELOC_ARM_OFFSET_IMM8:
27965 case BFD_RELOC_ARM_HWLITERAL:
27966 case BFD_RELOC_ARM_LITERAL:
27967 case BFD_RELOC_ARM_CP_OFF_IMM:
27968 return base + 8;
27969
27970
27971 /* Other PC-relative relocations are un-offset. */
27972 default:
27973 return base;
27974 }
bfae80f2
RE
27975}
27976
8b2d793c
NC
27977static bfd_boolean flag_warn_syms = TRUE;
27978
ae8714c2
NC
27979bfd_boolean
27980arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 27981{
8b2d793c
NC
27982 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27983 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27984 does mean that the resulting code might be very confusing to the reader.
27985 Also this warning can be triggered if the user omits an operand before
27986 an immediate address, eg:
27987
27988 LDR =foo
27989
27990 GAS treats this as an assignment of the value of the symbol foo to a
27991 symbol LDR, and so (without this code) it will not issue any kind of
27992 warning or error message.
27993
27994 Note - ARM instructions are case-insensitive but the strings in the hash
27995 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
27996 lower case too. */
27997 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
27998 {
27999 char * nbuf = strdup (name);
28000 char * p;
28001
28002 for (p = nbuf; *p; p++)
28003 *p = TOLOWER (*p);
629310ab 28004 if (str_hash_find (arm_ops_hsh, nbuf) != NULL)
8b2d793c 28005 {
629310ab 28006 static htab_t already_warned = NULL;
8b2d793c
NC
28007
28008 if (already_warned == NULL)
629310ab 28009 already_warned = str_htab_create ();
8b2d793c 28010 /* Only warn about the symbol once. To keep the code
629310ab
ML
28011 simple we let str_hash_insert do the lookup for us. */
28012 if (str_hash_find (already_warned, nbuf) == NULL)
28013 {
28014 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
fe0e921f 28015 str_hash_insert (already_warned, nbuf, NULL, 0);
629310ab 28016 }
8b2d793c
NC
28017 }
28018 else
28019 free (nbuf);
28020 }
3739860c 28021
ae8714c2
NC
28022 return FALSE;
28023}
28024
28025/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28026 Otherwise we have no need to default values of symbols. */
28027
28028symbolS *
28029md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28030{
28031#ifdef OBJ_ELF
28032 if (name[0] == '_' && name[1] == 'G'
28033 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28034 {
28035 if (!GOT_symbol)
28036 {
28037 if (symbol_find (name))
28038 as_bad (_("GOT already in the symbol table"));
28039
28040 GOT_symbol = symbol_new (name, undefined_section,
e01e1cee 28041 &zero_address_frag, 0);
ae8714c2
NC
28042 }
28043
28044 return GOT_symbol;
28045 }
28046#endif
28047
c921be7d 28048 return NULL;
bfae80f2
RE
28049}
28050
55cf6793 28051/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
28052 computed as two separate immediate values, added together. We
28053 already know that this value cannot be computed by just one ARM
28054 instruction. */
28055
28056static unsigned int
28057validate_immediate_twopart (unsigned int val,
28058 unsigned int * highpart)
bfae80f2 28059{
c19d1205
ZW
28060 unsigned int a;
28061 unsigned int i;
bfae80f2 28062
c19d1205
ZW
28063 for (i = 0; i < 32; i += 2)
28064 if (((a = rotate_left (val, i)) & 0xff) != 0)
28065 {
28066 if (a & 0xff00)
28067 {
28068 if (a & ~ 0xffff)
28069 continue;
28070 * highpart = (a >> 8) | ((i + 24) << 7);
28071 }
28072 else if (a & 0xff0000)
28073 {
28074 if (a & 0xff000000)
28075 continue;
28076 * highpart = (a >> 16) | ((i + 16) << 7);
28077 }
28078 else
28079 {
9c2799c2 28080 gas_assert (a & 0xff000000);
c19d1205
ZW
28081 * highpart = (a >> 24) | ((i + 8) << 7);
28082 }
bfae80f2 28083
c19d1205
ZW
28084 return (a & 0xff) | (i << 7);
28085 }
bfae80f2 28086
c19d1205 28087 return FAIL;
bfae80f2
RE
28088}
28089
c19d1205
ZW
28090static int
28091validate_offset_imm (unsigned int val, int hwse)
28092{
28093 if ((hwse && val > 255) || val > 4095)
28094 return FAIL;
28095 return val;
28096}
bfae80f2 28097
55cf6793 28098/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
28099 negative immediate constant by altering the instruction. A bit of
28100 a hack really.
28101 MOV <-> MVN
28102 AND <-> BIC
28103 ADC <-> SBC
28104 by inverting the second operand, and
28105 ADD <-> SUB
28106 CMP <-> CMN
28107 by negating the second operand. */
bfae80f2 28108
c19d1205
ZW
28109static int
28110negate_data_op (unsigned long * instruction,
28111 unsigned long value)
bfae80f2 28112{
c19d1205
ZW
28113 int op, new_inst;
28114 unsigned long negated, inverted;
bfae80f2 28115
c19d1205
ZW
28116 negated = encode_arm_immediate (-value);
28117 inverted = encode_arm_immediate (~value);
bfae80f2 28118
c19d1205
ZW
28119 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28120 switch (op)
bfae80f2 28121 {
c19d1205
ZW
28122 /* First negates. */
28123 case OPCODE_SUB: /* ADD <-> SUB */
28124 new_inst = OPCODE_ADD;
28125 value = negated;
28126 break;
bfae80f2 28127
c19d1205
ZW
28128 case OPCODE_ADD:
28129 new_inst = OPCODE_SUB;
28130 value = negated;
28131 break;
bfae80f2 28132
c19d1205
ZW
28133 case OPCODE_CMP: /* CMP <-> CMN */
28134 new_inst = OPCODE_CMN;
28135 value = negated;
28136 break;
bfae80f2 28137
c19d1205
ZW
28138 case OPCODE_CMN:
28139 new_inst = OPCODE_CMP;
28140 value = negated;
28141 break;
bfae80f2 28142
c19d1205
ZW
28143 /* Now Inverted ops. */
28144 case OPCODE_MOV: /* MOV <-> MVN */
28145 new_inst = OPCODE_MVN;
28146 value = inverted;
28147 break;
bfae80f2 28148
c19d1205
ZW
28149 case OPCODE_MVN:
28150 new_inst = OPCODE_MOV;
28151 value = inverted;
28152 break;
bfae80f2 28153
c19d1205
ZW
28154 case OPCODE_AND: /* AND <-> BIC */
28155 new_inst = OPCODE_BIC;
28156 value = inverted;
28157 break;
bfae80f2 28158
c19d1205
ZW
28159 case OPCODE_BIC:
28160 new_inst = OPCODE_AND;
28161 value = inverted;
28162 break;
bfae80f2 28163
c19d1205
ZW
28164 case OPCODE_ADC: /* ADC <-> SBC */
28165 new_inst = OPCODE_SBC;
28166 value = inverted;
28167 break;
bfae80f2 28168
c19d1205
ZW
28169 case OPCODE_SBC:
28170 new_inst = OPCODE_ADC;
28171 value = inverted;
28172 break;
bfae80f2 28173
c19d1205
ZW
28174 /* We cannot do anything. */
28175 default:
28176 return FAIL;
b99bd4ef
NC
28177 }
28178
c19d1205
ZW
28179 if (value == (unsigned) FAIL)
28180 return FAIL;
28181
28182 *instruction &= OPCODE_MASK;
28183 *instruction |= new_inst << DATA_OP_SHIFT;
28184 return value;
b99bd4ef
NC
28185}
28186
ef8d22e6
PB
28187/* Like negate_data_op, but for Thumb-2. */
28188
28189static unsigned int
7af67752 28190thumb32_negate_data_op (valueT *instruction, unsigned int value)
ef8d22e6 28191{
7af67752
AM
28192 unsigned int op, new_inst;
28193 unsigned int rd;
16dd5e42 28194 unsigned int negated, inverted;
ef8d22e6
PB
28195
28196 negated = encode_thumb32_immediate (-value);
28197 inverted = encode_thumb32_immediate (~value);
28198
28199 rd = (*instruction >> 8) & 0xf;
28200 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28201 switch (op)
28202 {
28203 /* ADD <-> SUB. Includes CMP <-> CMN. */
28204 case T2_OPCODE_SUB:
28205 new_inst = T2_OPCODE_ADD;
28206 value = negated;
28207 break;
28208
28209 case T2_OPCODE_ADD:
28210 new_inst = T2_OPCODE_SUB;
28211 value = negated;
28212 break;
28213
28214 /* ORR <-> ORN. Includes MOV <-> MVN. */
28215 case T2_OPCODE_ORR:
28216 new_inst = T2_OPCODE_ORN;
28217 value = inverted;
28218 break;
28219
28220 case T2_OPCODE_ORN:
28221 new_inst = T2_OPCODE_ORR;
28222 value = inverted;
28223 break;
28224
28225 /* AND <-> BIC. TST has no inverted equivalent. */
28226 case T2_OPCODE_AND:
28227 new_inst = T2_OPCODE_BIC;
28228 if (rd == 15)
28229 value = FAIL;
28230 else
28231 value = inverted;
28232 break;
28233
28234 case T2_OPCODE_BIC:
28235 new_inst = T2_OPCODE_AND;
28236 value = inverted;
28237 break;
28238
28239 /* ADC <-> SBC */
28240 case T2_OPCODE_ADC:
28241 new_inst = T2_OPCODE_SBC;
28242 value = inverted;
28243 break;
28244
28245 case T2_OPCODE_SBC:
28246 new_inst = T2_OPCODE_ADC;
28247 value = inverted;
28248 break;
28249
28250 /* We cannot do anything. */
28251 default:
28252 return FAIL;
28253 }
28254
16dd5e42 28255 if (value == (unsigned int)FAIL)
ef8d22e6
PB
28256 return FAIL;
28257
28258 *instruction &= T2_OPCODE_MASK;
28259 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28260 return value;
28261}
28262
8f06b2d8 28263/* Read a 32-bit thumb instruction from buf. */
0198d5e6 28264
8f06b2d8
PB
28265static unsigned long
28266get_thumb32_insn (char * buf)
28267{
28268 unsigned long insn;
28269 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28270 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28271
28272 return insn;
28273}
28274
a8bc6c78
PB
28275/* We usually want to set the low bit on the address of thumb function
28276 symbols. In particular .word foo - . should have the low bit set.
28277 Generic code tries to fold the difference of two symbols to
28278 a constant. Prevent this and force a relocation when the first symbols
28279 is a thumb function. */
c921be7d
NC
28280
28281bfd_boolean
a8bc6c78
PB
28282arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28283{
28284 if (op == O_subtract
28285 && l->X_op == O_symbol
28286 && r->X_op == O_symbol
28287 && THUMB_IS_FUNC (l->X_add_symbol))
28288 {
28289 l->X_op = O_subtract;
28290 l->X_op_symbol = r->X_add_symbol;
28291 l->X_add_number -= r->X_add_number;
c921be7d 28292 return TRUE;
a8bc6c78 28293 }
c921be7d 28294
a8bc6c78 28295 /* Process as normal. */
c921be7d 28296 return FALSE;
a8bc6c78
PB
28297}
28298
4a42ebbc
RR
28299/* Encode Thumb2 unconditional branches and calls. The encoding
28300 for the 2 are identical for the immediate values. */
28301
28302static void
28303encode_thumb2_b_bl_offset (char * buf, offsetT value)
28304{
28305#define T2I1I2MASK ((1 << 13) | (1 << 11))
28306 offsetT newval;
28307 offsetT newval2;
28308 addressT S, I1, I2, lo, hi;
28309
28310 S = (value >> 24) & 0x01;
28311 I1 = (value >> 23) & 0x01;
28312 I2 = (value >> 22) & 0x01;
28313 hi = (value >> 12) & 0x3ff;
fa94de6b 28314 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
28315 newval = md_chars_to_number (buf, THUMB_SIZE);
28316 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28317 newval |= (S << 10) | hi;
28318 newval2 &= ~T2I1I2MASK;
28319 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28320 md_number_to_chars (buf, newval, THUMB_SIZE);
28321 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28322}
28323
c19d1205 28324void
55cf6793 28325md_apply_fix (fixS * fixP,
c19d1205
ZW
28326 valueT * valP,
28327 segT seg)
28328{
7af67752
AM
28329 valueT value = * valP;
28330 valueT newval;
c19d1205
ZW
28331 unsigned int newimm;
28332 unsigned long temp;
28333 int sign;
28334 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 28335
9c2799c2 28336 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 28337
c19d1205 28338 /* Note whether this will delete the relocation. */
4962c51a 28339
c19d1205
ZW
28340 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28341 fixP->fx_done = 1;
b99bd4ef 28342
adbaf948 28343 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 28344 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
28345 for emit_reloc. */
28346 value &= 0xffffffff;
28347 value ^= 0x80000000;
5f4273c7 28348 value -= 0x80000000;
adbaf948
ZW
28349
28350 *valP = value;
c19d1205 28351 fixP->fx_addnumber = value;
b99bd4ef 28352
adbaf948
ZW
28353 /* Same treatment for fixP->fx_offset. */
28354 fixP->fx_offset &= 0xffffffff;
28355 fixP->fx_offset ^= 0x80000000;
28356 fixP->fx_offset -= 0x80000000;
28357
c19d1205 28358 switch (fixP->fx_r_type)
b99bd4ef 28359 {
c19d1205
ZW
28360 case BFD_RELOC_NONE:
28361 /* This will need to go in the object file. */
28362 fixP->fx_done = 0;
28363 break;
b99bd4ef 28364
c19d1205
ZW
28365 case BFD_RELOC_ARM_IMMEDIATE:
28366 /* We claim that this fixup has been processed here,
28367 even if in fact we generate an error because we do
28368 not have a reloc for it, so tc_gen_reloc will reject it. */
28369 fixP->fx_done = 1;
b99bd4ef 28370
77db8e2e 28371 if (fixP->fx_addsy)
b99bd4ef 28372 {
77db8e2e 28373 const char *msg = 0;
b99bd4ef 28374
77db8e2e
NC
28375 if (! S_IS_DEFINED (fixP->fx_addsy))
28376 msg = _("undefined symbol %s used as an immediate value");
28377 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28378 msg = _("symbol %s is in a different section");
28379 else if (S_IS_WEAK (fixP->fx_addsy))
28380 msg = _("symbol %s is weak and may be overridden later");
28381
28382 if (msg)
28383 {
28384 as_bad_where (fixP->fx_file, fixP->fx_line,
28385 msg, S_GET_NAME (fixP->fx_addsy));
28386 break;
28387 }
42e5fcbf
AS
28388 }
28389
c19d1205
ZW
28390 temp = md_chars_to_number (buf, INSN_SIZE);
28391
5e73442d 28392 /* If the offset is negative, we should use encoding A2 for ADR. */
7af67752 28393 if ((temp & 0xfff0000) == 0x28f0000 && (offsetT) value < 0)
5e73442d
SL
28394 newimm = negate_data_op (&temp, value);
28395 else
28396 {
28397 newimm = encode_arm_immediate (value);
28398
28399 /* If the instruction will fail, see if we can fix things up by
28400 changing the opcode. */
28401 if (newimm == (unsigned int) FAIL)
28402 newimm = negate_data_op (&temp, value);
bada4342
JW
28403 /* MOV accepts both ARM modified immediate (A1 encoding) and
28404 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28405 When disassembling, MOV is preferred when there is no encoding
28406 overlap. */
28407 if (newimm == (unsigned int) FAIL
28408 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28409 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28410 && !((temp >> SBIT_SHIFT) & 0x1)
7af67752 28411 && value <= 0xffff)
bada4342
JW
28412 {
28413 /* Clear bits[23:20] to change encoding from A1 to A2. */
28414 temp &= 0xff0fffff;
28415 /* Encoding high 4bits imm. Code below will encode the remaining
28416 low 12bits. */
28417 temp |= (value & 0x0000f000) << 4;
28418 newimm = value & 0x00000fff;
28419 }
5e73442d
SL
28420 }
28421
28422 if (newimm == (unsigned int) FAIL)
b99bd4ef 28423 {
c19d1205
ZW
28424 as_bad_where (fixP->fx_file, fixP->fx_line,
28425 _("invalid constant (%lx) after fixup"),
28426 (unsigned long) value);
28427 break;
b99bd4ef 28428 }
b99bd4ef 28429
c19d1205
ZW
28430 newimm |= (temp & 0xfffff000);
28431 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28432 break;
b99bd4ef 28433
c19d1205
ZW
28434 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28435 {
28436 unsigned int highpart = 0;
28437 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 28438
77db8e2e 28439 if (fixP->fx_addsy)
42e5fcbf 28440 {
77db8e2e 28441 const char *msg = 0;
42e5fcbf 28442
77db8e2e
NC
28443 if (! S_IS_DEFINED (fixP->fx_addsy))
28444 msg = _("undefined symbol %s used as an immediate value");
28445 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28446 msg = _("symbol %s is in a different section");
28447 else if (S_IS_WEAK (fixP->fx_addsy))
28448 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 28449
77db8e2e
NC
28450 if (msg)
28451 {
28452 as_bad_where (fixP->fx_file, fixP->fx_line,
28453 msg, S_GET_NAME (fixP->fx_addsy));
28454 break;
28455 }
28456 }
fa94de6b 28457
c19d1205
ZW
28458 newimm = encode_arm_immediate (value);
28459 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 28460
c19d1205
ZW
28461 /* If the instruction will fail, see if we can fix things up by
28462 changing the opcode. */
28463 if (newimm == (unsigned int) FAIL
28464 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28465 {
28466 /* No ? OK - try using two ADD instructions to generate
28467 the value. */
28468 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 28469
c19d1205
ZW
28470 /* Yes - then make sure that the second instruction is
28471 also an add. */
28472 if (newimm != (unsigned int) FAIL)
28473 newinsn = temp;
28474 /* Still No ? Try using a negated value. */
28475 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28476 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28477 /* Otherwise - give up. */
28478 else
28479 {
28480 as_bad_where (fixP->fx_file, fixP->fx_line,
28481 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28482 (long) value);
28483 break;
28484 }
b99bd4ef 28485
c19d1205
ZW
28486 /* Replace the first operand in the 2nd instruction (which
28487 is the PC) with the destination register. We have
28488 already added in the PC in the first instruction and we
28489 do not want to do it again. */
28490 newinsn &= ~ 0xf0000;
28491 newinsn |= ((newinsn & 0x0f000) << 4);
28492 }
b99bd4ef 28493
c19d1205
ZW
28494 newimm |= (temp & 0xfffff000);
28495 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 28496
c19d1205
ZW
28497 highpart |= (newinsn & 0xfffff000);
28498 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28499 }
28500 break;
b99bd4ef 28501
c19d1205 28502 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
28503 if (!fixP->fx_done && seg->use_rela_p)
28504 value = 0;
1a0670f3 28505 /* Fall through. */
00a97672 28506
c19d1205 28507 case BFD_RELOC_ARM_LITERAL:
7af67752 28508 sign = (offsetT) value > 0;
b99bd4ef 28509
7af67752 28510 if ((offsetT) value < 0)
c19d1205 28511 value = - value;
b99bd4ef 28512
c19d1205 28513 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 28514 {
c19d1205
ZW
28515 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28516 as_bad_where (fixP->fx_file, fixP->fx_line,
28517 _("invalid literal constant: pool needs to be closer"));
28518 else
28519 as_bad_where (fixP->fx_file, fixP->fx_line,
28520 _("bad immediate value for offset (%ld)"),
28521 (long) value);
28522 break;
f03698e6
RE
28523 }
28524
c19d1205 28525 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28526 if (value == 0)
28527 newval &= 0xfffff000;
28528 else
28529 {
28530 newval &= 0xff7ff000;
28531 newval |= value | (sign ? INDEX_UP : 0);
28532 }
c19d1205
ZW
28533 md_number_to_chars (buf, newval, INSN_SIZE);
28534 break;
b99bd4ef 28535
c19d1205
ZW
28536 case BFD_RELOC_ARM_OFFSET_IMM8:
28537 case BFD_RELOC_ARM_HWLITERAL:
7af67752 28538 sign = (offsetT) value > 0;
b99bd4ef 28539
7af67752 28540 if ((offsetT) value < 0)
c19d1205 28541 value = - value;
b99bd4ef 28542
c19d1205 28543 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 28544 {
c19d1205
ZW
28545 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28546 as_bad_where (fixP->fx_file, fixP->fx_line,
28547 _("invalid literal constant: pool needs to be closer"));
28548 else
427d0db6
RM
28549 as_bad_where (fixP->fx_file, fixP->fx_line,
28550 _("bad immediate value for 8-bit offset (%ld)"),
28551 (long) value);
c19d1205 28552 break;
b99bd4ef
NC
28553 }
28554
c19d1205 28555 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
28556 if (value == 0)
28557 newval &= 0xfffff0f0;
28558 else
28559 {
28560 newval &= 0xff7ff0f0;
28561 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28562 }
c19d1205
ZW
28563 md_number_to_chars (buf, newval, INSN_SIZE);
28564 break;
b99bd4ef 28565
c19d1205 28566 case BFD_RELOC_ARM_T32_OFFSET_U8:
7af67752 28567 if (value > 1020 || value % 4 != 0)
c19d1205
ZW
28568 as_bad_where (fixP->fx_file, fixP->fx_line,
28569 _("bad immediate value for offset (%ld)"), (long) value);
28570 value /= 4;
b99bd4ef 28571
c19d1205 28572 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
28573 newval |= value;
28574 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28575 break;
b99bd4ef 28576
c19d1205
ZW
28577 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28578 /* This is a complicated relocation used for all varieties of Thumb32
28579 load/store instruction with immediate offset:
28580
28581 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 28582 *4, optional writeback(W)
c19d1205
ZW
28583 (doubleword load/store)
28584
28585 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28586 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28587 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28588 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28589 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28590
28591 Uppercase letters indicate bits that are already encoded at
28592 this point. Lowercase letters are our problem. For the
28593 second block of instructions, the secondary opcode nybble
28594 (bits 8..11) is present, and bit 23 is zero, even if this is
28595 a PC-relative operation. */
28596 newval = md_chars_to_number (buf, THUMB_SIZE);
28597 newval <<= 16;
28598 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 28599
c19d1205 28600 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 28601 {
c19d1205 28602 /* Doubleword load/store: 8-bit offset, scaled by 4. */
7af67752 28603 if ((offsetT) value >= 0)
c19d1205
ZW
28604 newval |= (1 << 23);
28605 else
28606 value = -value;
28607 if (value % 4 != 0)
28608 {
28609 as_bad_where (fixP->fx_file, fixP->fx_line,
28610 _("offset not a multiple of 4"));
28611 break;
28612 }
28613 value /= 4;
216d22bc 28614 if (value > 0xff)
c19d1205
ZW
28615 {
28616 as_bad_where (fixP->fx_file, fixP->fx_line,
28617 _("offset out of range"));
28618 break;
28619 }
28620 newval &= ~0xff;
b99bd4ef 28621 }
c19d1205 28622 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 28623 {
c19d1205 28624 /* PC-relative, 12-bit offset. */
7af67752 28625 if ((offsetT) value >= 0)
c19d1205
ZW
28626 newval |= (1 << 23);
28627 else
28628 value = -value;
216d22bc 28629 if (value > 0xfff)
c19d1205
ZW
28630 {
28631 as_bad_where (fixP->fx_file, fixP->fx_line,
28632 _("offset out of range"));
28633 break;
28634 }
28635 newval &= ~0xfff;
b99bd4ef 28636 }
c19d1205 28637 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 28638 {
c19d1205 28639 /* Writeback: 8-bit, +/- offset. */
7af67752 28640 if ((offsetT) value >= 0)
c19d1205
ZW
28641 newval |= (1 << 9);
28642 else
28643 value = -value;
216d22bc 28644 if (value > 0xff)
c19d1205
ZW
28645 {
28646 as_bad_where (fixP->fx_file, fixP->fx_line,
28647 _("offset out of range"));
28648 break;
28649 }
28650 newval &= ~0xff;
b99bd4ef 28651 }
c19d1205 28652 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 28653 {
c19d1205 28654 /* T-instruction: positive 8-bit offset. */
7af67752 28655 if (value > 0xff)
b99bd4ef 28656 {
c19d1205
ZW
28657 as_bad_where (fixP->fx_file, fixP->fx_line,
28658 _("offset out of range"));
28659 break;
b99bd4ef 28660 }
c19d1205
ZW
28661 newval &= ~0xff;
28662 newval |= value;
b99bd4ef
NC
28663 }
28664 else
b99bd4ef 28665 {
c19d1205 28666 /* Positive 12-bit or negative 8-bit offset. */
7af67752
AM
28667 unsigned int limit;
28668 if ((offsetT) value >= 0)
b99bd4ef 28669 {
c19d1205
ZW
28670 newval |= (1 << 23);
28671 limit = 0xfff;
28672 }
28673 else
28674 {
28675 value = -value;
28676 limit = 0xff;
28677 }
28678 if (value > limit)
28679 {
28680 as_bad_where (fixP->fx_file, fixP->fx_line,
28681 _("offset out of range"));
28682 break;
b99bd4ef 28683 }
c19d1205 28684 newval &= ~limit;
b99bd4ef 28685 }
b99bd4ef 28686
c19d1205
ZW
28687 newval |= value;
28688 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28689 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28690 break;
404ff6b5 28691
c19d1205
ZW
28692 case BFD_RELOC_ARM_SHIFT_IMM:
28693 newval = md_chars_to_number (buf, INSN_SIZE);
7af67752 28694 if (value > 32
c19d1205
ZW
28695 || (value == 32
28696 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28697 {
28698 as_bad_where (fixP->fx_file, fixP->fx_line,
28699 _("shift expression is too large"));
28700 break;
28701 }
404ff6b5 28702
c19d1205
ZW
28703 if (value == 0)
28704 /* Shifts of zero must be done as lsl. */
28705 newval &= ~0x60;
28706 else if (value == 32)
28707 value = 0;
28708 newval &= 0xfffff07f;
28709 newval |= (value & 0x1f) << 7;
28710 md_number_to_chars (buf, newval, INSN_SIZE);
28711 break;
404ff6b5 28712
c19d1205 28713 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 28714 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 28715 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 28716 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
28717 /* We claim that this fixup has been processed here,
28718 even if in fact we generate an error because we do
28719 not have a reloc for it, so tc_gen_reloc will reject it. */
28720 fixP->fx_done = 1;
404ff6b5 28721
c19d1205
ZW
28722 if (fixP->fx_addsy
28723 && ! S_IS_DEFINED (fixP->fx_addsy))
28724 {
28725 as_bad_where (fixP->fx_file, fixP->fx_line,
28726 _("undefined symbol %s used as an immediate value"),
28727 S_GET_NAME (fixP->fx_addsy));
28728 break;
28729 }
404ff6b5 28730
c19d1205
ZW
28731 newval = md_chars_to_number (buf, THUMB_SIZE);
28732 newval <<= 16;
28733 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 28734
16805f35 28735 newimm = FAIL;
bada4342
JW
28736 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28737 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28738 Thumb2 modified immediate encoding (T2). */
28739 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 28740 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
28741 {
28742 newimm = encode_thumb32_immediate (value);
28743 if (newimm == (unsigned int) FAIL)
28744 newimm = thumb32_negate_data_op (&newval, value);
28745 }
bada4342 28746 if (newimm == (unsigned int) FAIL)
92e90b6e 28747 {
bada4342 28748 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 28749 {
bada4342
JW
28750 /* Turn add/sum into addw/subw. */
28751 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28752 newval = (newval & 0xfeffffff) | 0x02000000;
28753 /* No flat 12-bit imm encoding for addsw/subsw. */
28754 if ((newval & 0x00100000) == 0)
40f246e3 28755 {
bada4342 28756 /* 12 bit immediate for addw/subw. */
7af67752 28757 if ((offsetT) value < 0)
bada4342
JW
28758 {
28759 value = -value;
28760 newval ^= 0x00a00000;
28761 }
28762 if (value > 0xfff)
28763 newimm = (unsigned int) FAIL;
28764 else
28765 newimm = value;
28766 }
28767 }
28768 else
28769 {
28770 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28771 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28772 disassembling, MOV is preferred when there is no encoding
db7bf105 28773 overlap. */
bada4342 28774 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
28775 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28776 but with the Rn field [19:16] set to 1111. */
28777 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
28778 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28779 && !((newval >> T2_SBIT_SHIFT) & 0x1)
7af67752 28780 && value <= 0xffff)
bada4342
JW
28781 {
28782 /* Toggle bit[25] to change encoding from T2 to T3. */
28783 newval ^= 1 << 25;
28784 /* Clear bits[19:16]. */
28785 newval &= 0xfff0ffff;
28786 /* Encoding high 4bits imm. Code below will encode the
28787 remaining low 12bits. */
28788 newval |= (value & 0x0000f000) << 4;
28789 newimm = value & 0x00000fff;
40f246e3 28790 }
e9f89963 28791 }
92e90b6e 28792 }
cc8a6dd0 28793
c19d1205 28794 if (newimm == (unsigned int)FAIL)
3631a3c8 28795 {
c19d1205
ZW
28796 as_bad_where (fixP->fx_file, fixP->fx_line,
28797 _("invalid constant (%lx) after fixup"),
28798 (unsigned long) value);
28799 break;
3631a3c8
NC
28800 }
28801
c19d1205
ZW
28802 newval |= (newimm & 0x800) << 15;
28803 newval |= (newimm & 0x700) << 4;
28804 newval |= (newimm & 0x0ff);
cc8a6dd0 28805
c19d1205
ZW
28806 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28807 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28808 break;
a737bd4d 28809
3eb17e6b 28810 case BFD_RELOC_ARM_SMC:
7af67752 28811 if (value > 0xf)
c19d1205 28812 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 28813 _("invalid smc expression"));
ba85f98c 28814
2fc8bdac 28815 newval = md_chars_to_number (buf, INSN_SIZE);
ba85f98c 28816 newval |= (value & 0xf);
c19d1205
ZW
28817 md_number_to_chars (buf, newval, INSN_SIZE);
28818 break;
a737bd4d 28819
90ec0d68 28820 case BFD_RELOC_ARM_HVC:
7af67752 28821 if (value > 0xffff)
90ec0d68
MGD
28822 as_bad_where (fixP->fx_file, fixP->fx_line,
28823 _("invalid hvc expression"));
28824 newval = md_chars_to_number (buf, INSN_SIZE);
28825 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28826 md_number_to_chars (buf, newval, INSN_SIZE);
28827 break;
28828
c19d1205 28829 case BFD_RELOC_ARM_SWI:
adbaf948 28830 if (fixP->tc_fix_data != 0)
c19d1205 28831 {
7af67752 28832 if (value > 0xff)
c19d1205
ZW
28833 as_bad_where (fixP->fx_file, fixP->fx_line,
28834 _("invalid swi expression"));
2fc8bdac 28835 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
28836 newval |= value;
28837 md_number_to_chars (buf, newval, THUMB_SIZE);
28838 }
28839 else
28840 {
7af67752 28841 if (value > 0x00ffffff)
c19d1205
ZW
28842 as_bad_where (fixP->fx_file, fixP->fx_line,
28843 _("invalid swi expression"));
2fc8bdac 28844 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
28845 newval |= value;
28846 md_number_to_chars (buf, newval, INSN_SIZE);
28847 }
28848 break;
a737bd4d 28849
c19d1205 28850 case BFD_RELOC_ARM_MULTI:
7af67752 28851 if (value > 0xffff)
c19d1205
ZW
28852 as_bad_where (fixP->fx_file, fixP->fx_line,
28853 _("invalid expression in load/store multiple"));
28854 newval = value | md_chars_to_number (buf, INSN_SIZE);
28855 md_number_to_chars (buf, newval, INSN_SIZE);
28856 break;
a737bd4d 28857
c19d1205 28858#ifdef OBJ_ELF
39b41c9c 28859 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
28860
28861 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28862 && fixP->fx_addsy
34e77a92 28863 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28864 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28865 && THUMB_IS_FUNC (fixP->fx_addsy))
28866 /* Flip the bl to blx. This is a simple flip
28867 bit here because we generate PCREL_CALL for
28868 unconditional bls. */
28869 {
28870 newval = md_chars_to_number (buf, INSN_SIZE);
28871 newval = newval | 0x10000000;
28872 md_number_to_chars (buf, newval, INSN_SIZE);
28873 temp = 1;
28874 fixP->fx_done = 1;
28875 }
39b41c9c
PB
28876 else
28877 temp = 3;
28878 goto arm_branch_common;
28879
28880 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
28881 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28882 && fixP->fx_addsy
34e77a92 28883 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28884 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28885 && THUMB_IS_FUNC (fixP->fx_addsy))
28886 {
28887 /* This would map to a bl<cond>, b<cond>,
28888 b<always> to a Thumb function. We
28889 need to force a relocation for this particular
28890 case. */
28891 newval = md_chars_to_number (buf, INSN_SIZE);
28892 fixP->fx_done = 0;
28893 }
1a0670f3 28894 /* Fall through. */
267bf995 28895
2fc8bdac 28896 case BFD_RELOC_ARM_PLT32:
c19d1205 28897#endif
39b41c9c
PB
28898 case BFD_RELOC_ARM_PCREL_BRANCH:
28899 temp = 3;
28900 goto arm_branch_common;
a737bd4d 28901
39b41c9c 28902 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 28903
39b41c9c 28904 temp = 1;
267bf995
RR
28905 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28906 && fixP->fx_addsy
34e77a92 28907 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
28908 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28909 && ARM_IS_FUNC (fixP->fx_addsy))
28910 {
28911 /* Flip the blx to a bl and warn. */
28912 const char *name = S_GET_NAME (fixP->fx_addsy);
28913 newval = 0xeb000000;
28914 as_warn_where (fixP->fx_file, fixP->fx_line,
28915 _("blx to '%s' an ARM ISA state function changed to bl"),
28916 name);
28917 md_number_to_chars (buf, newval, INSN_SIZE);
28918 temp = 3;
28919 fixP->fx_done = 1;
28920 }
28921
28922#ifdef OBJ_ELF
28923 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 28924 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
28925#endif
28926
39b41c9c 28927 arm_branch_common:
c19d1205 28928 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
28929 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28930 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 28931 also be clear. */
39b41c9c 28932 if (value & temp)
c19d1205 28933 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac 28934 _("misaligned branch destination"));
7af67752
AM
28935 if ((value & 0xfe000000) != 0
28936 && (value & 0xfe000000) != 0xfe000000)
08f10d51 28937 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28938
2fc8bdac 28939 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 28940 {
2fc8bdac
ZW
28941 newval = md_chars_to_number (buf, INSN_SIZE);
28942 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
28943 /* Set the H bit on BLX instructions. */
28944 if (temp == 1)
28945 {
28946 if (value & 2)
28947 newval |= 0x01000000;
28948 else
28949 newval &= ~0x01000000;
28950 }
2fc8bdac 28951 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 28952 }
c19d1205 28953 break;
a737bd4d 28954
25fe350b
MS
28955 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28956 /* CBZ can only branch forward. */
a737bd4d 28957
738755b0 28958 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
28959 (which, strictly speaking, are prohibited) will be turned into
28960 no-ops.
738755b0
MS
28961
28962 FIXME: It may be better to remove the instruction completely and
28963 perform relaxation. */
7af67752 28964 if ((offsetT) value == -2)
2fc8bdac
ZW
28965 {
28966 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 28967 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
28968 md_number_to_chars (buf, newval, THUMB_SIZE);
28969 }
738755b0
MS
28970 else
28971 {
28972 if (value & ~0x7e)
08f10d51 28973 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 28974
477330fc 28975 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
28976 {
28977 newval = md_chars_to_number (buf, THUMB_SIZE);
28978 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28979 md_number_to_chars (buf, newval, THUMB_SIZE);
28980 }
28981 }
c19d1205 28982 break;
a737bd4d 28983
c19d1205 28984 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
e8f8842d 28985 if (out_of_range_p (value, 8))
08f10d51 28986 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28987
2fc8bdac
ZW
28988 if (fixP->fx_done || !seg->use_rela_p)
28989 {
28990 newval = md_chars_to_number (buf, THUMB_SIZE);
28991 newval |= (value & 0x1ff) >> 1;
28992 md_number_to_chars (buf, newval, THUMB_SIZE);
28993 }
c19d1205 28994 break;
a737bd4d 28995
c19d1205 28996 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
e8f8842d 28997 if (out_of_range_p (value, 11))
08f10d51 28998 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 28999
2fc8bdac
ZW
29000 if (fixP->fx_done || !seg->use_rela_p)
29001 {
29002 newval = md_chars_to_number (buf, THUMB_SIZE);
29003 newval |= (value & 0xfff) >> 1;
29004 md_number_to_chars (buf, newval, THUMB_SIZE);
29005 }
c19d1205 29006 break;
a737bd4d 29007
e8f8842d 29008 /* This relocation is misnamed, it should be BRANCH21. */
c19d1205 29009 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
29010 if (fixP->fx_addsy
29011 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 29012 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29013 && ARM_IS_FUNC (fixP->fx_addsy)
29014 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29015 {
29016 /* Force a relocation for a branch 20 bits wide. */
29017 fixP->fx_done = 0;
29018 }
e8f8842d 29019 if (out_of_range_p (value, 20))
2fc8bdac
ZW
29020 as_bad_where (fixP->fx_file, fixP->fx_line,
29021 _("conditional branch out of range"));
404ff6b5 29022
2fc8bdac
ZW
29023 if (fixP->fx_done || !seg->use_rela_p)
29024 {
29025 offsetT newval2;
29026 addressT S, J1, J2, lo, hi;
404ff6b5 29027
2fc8bdac
ZW
29028 S = (value & 0x00100000) >> 20;
29029 J2 = (value & 0x00080000) >> 19;
29030 J1 = (value & 0x00040000) >> 18;
29031 hi = (value & 0x0003f000) >> 12;
29032 lo = (value & 0x00000ffe) >> 1;
6c43fab6 29033
2fc8bdac
ZW
29034 newval = md_chars_to_number (buf, THUMB_SIZE);
29035 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29036 newval |= (S << 10) | hi;
29037 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29038 md_number_to_chars (buf, newval, THUMB_SIZE);
29039 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29040 }
c19d1205 29041 break;
6c43fab6 29042
c19d1205 29043 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
29044 /* If there is a blx from a thumb state function to
29045 another thumb function flip this to a bl and warn
29046 about it. */
29047
29048 if (fixP->fx_addsy
34e77a92 29049 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29050 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29051 && THUMB_IS_FUNC (fixP->fx_addsy))
29052 {
29053 const char *name = S_GET_NAME (fixP->fx_addsy);
29054 as_warn_where (fixP->fx_file, fixP->fx_line,
29055 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29056 name);
29057 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29058 newval = newval | 0x1000;
29059 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29060 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29061 fixP->fx_done = 1;
29062 }
29063
29064
29065 goto thumb_bl_common;
29066
c19d1205 29067 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
29068 /* A bl from Thumb state ISA to an internal ARM state function
29069 is converted to a blx. */
29070 if (fixP->fx_addsy
29071 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 29072 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
29073 && ARM_IS_FUNC (fixP->fx_addsy)
29074 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29075 {
29076 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29077 newval = newval & ~0x1000;
29078 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29079 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29080 fixP->fx_done = 1;
29081 }
29082
29083 thumb_bl_common:
29084
2fc8bdac
ZW
29085 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29086 /* For a BLX instruction, make sure that the relocation is rounded up
29087 to a word boundary. This follows the semantics of the instruction
29088 which specifies that bit 1 of the target address will come from bit
29089 1 of the base address. */
d406f3e4
JB
29090 value = (value + 3) & ~ 3;
29091
29092#ifdef OBJ_ELF
29093 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29094 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29095 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29096#endif
404ff6b5 29097
e8f8842d 29098 if (out_of_range_p (value, 22))
2b2f5df9 29099 {
fc289b0a 29100 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9 29101 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
e8f8842d 29102 else if (out_of_range_p (value, 24))
2b2f5df9
NC
29103 as_bad_where (fixP->fx_file, fixP->fx_line,
29104 _("Thumb2 branch out of range"));
29105 }
4a42ebbc
RR
29106
29107 if (fixP->fx_done || !seg->use_rela_p)
29108 encode_thumb2_b_bl_offset (buf, value);
29109
c19d1205 29110 break;
404ff6b5 29111
c19d1205 29112 case BFD_RELOC_THUMB_PCREL_BRANCH25:
e8f8842d 29113 if (out_of_range_p (value, 24))
08f10d51 29114 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 29115
2fc8bdac 29116 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 29117 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 29118
2fc8bdac 29119 break;
a737bd4d 29120
2fc8bdac
ZW
29121 case BFD_RELOC_8:
29122 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 29123 *buf = value;
c19d1205 29124 break;
a737bd4d 29125
c19d1205 29126 case BFD_RELOC_16:
2fc8bdac 29127 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 29128 md_number_to_chars (buf, value, 2);
c19d1205 29129 break;
a737bd4d 29130
c19d1205 29131#ifdef OBJ_ELF
0855e32b
NS
29132 case BFD_RELOC_ARM_TLS_CALL:
29133 case BFD_RELOC_ARM_THM_TLS_CALL:
29134 case BFD_RELOC_ARM_TLS_DESCSEQ:
29135 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 29136 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
29137 case BFD_RELOC_ARM_TLS_GD32:
29138 case BFD_RELOC_ARM_TLS_LE32:
29139 case BFD_RELOC_ARM_TLS_IE32:
29140 case BFD_RELOC_ARM_TLS_LDM32:
29141 case BFD_RELOC_ARM_TLS_LDO32:
29142 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 29143 break;
6c43fab6 29144
5c5a4843
CL
29145 /* Same handling as above, but with the arm_fdpic guard. */
29146 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29147 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29148 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29149 if (arm_fdpic)
29150 {
29151 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29152 }
29153 else
29154 {
29155 as_bad_where (fixP->fx_file, fixP->fx_line,
29156 _("Relocation supported only in FDPIC mode"));
29157 }
29158 break;
29159
c19d1205
ZW
29160 case BFD_RELOC_ARM_GOT32:
29161 case BFD_RELOC_ARM_GOTOFF:
c19d1205 29162 break;
b43420e6
NC
29163
29164 case BFD_RELOC_ARM_GOT_PREL:
29165 if (fixP->fx_done || !seg->use_rela_p)
477330fc 29166 md_number_to_chars (buf, value, 4);
b43420e6
NC
29167 break;
29168
9a6f4e97
NS
29169 case BFD_RELOC_ARM_TARGET2:
29170 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
29171 addend here for REL targets, because it won't be written out
29172 during reloc processing later. */
9a6f4e97
NS
29173 if (fixP->fx_done || !seg->use_rela_p)
29174 md_number_to_chars (buf, fixP->fx_offset, 4);
29175 break;
188fd7ae
CL
29176
29177 /* Relocations for FDPIC. */
29178 case BFD_RELOC_ARM_GOTFUNCDESC:
29179 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29180 case BFD_RELOC_ARM_FUNCDESC:
29181 if (arm_fdpic)
29182 {
29183 if (fixP->fx_done || !seg->use_rela_p)
29184 md_number_to_chars (buf, 0, 4);
29185 }
29186 else
29187 {
29188 as_bad_where (fixP->fx_file, fixP->fx_line,
29189 _("Relocation supported only in FDPIC mode"));
29190 }
29191 break;
c19d1205 29192#endif
6c43fab6 29193
c19d1205
ZW
29194 case BFD_RELOC_RVA:
29195 case BFD_RELOC_32:
29196 case BFD_RELOC_ARM_TARGET1:
29197 case BFD_RELOC_ARM_ROSEGREL32:
29198 case BFD_RELOC_ARM_SBREL32:
29199 case BFD_RELOC_32_PCREL:
f0927246
NC
29200#ifdef TE_PE
29201 case BFD_RELOC_32_SECREL:
29202#endif
2fc8bdac 29203 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
29204#ifdef TE_WINCE
29205 /* For WinCE we only do this for pcrel fixups. */
29206 if (fixP->fx_done || fixP->fx_pcrel)
29207#endif
29208 md_number_to_chars (buf, value, 4);
c19d1205 29209 break;
6c43fab6 29210
c19d1205
ZW
29211#ifdef OBJ_ELF
29212 case BFD_RELOC_ARM_PREL31:
2fc8bdac 29213 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
29214 {
29215 newval = md_chars_to_number (buf, 4) & 0x80000000;
29216 if ((value ^ (value >> 1)) & 0x40000000)
29217 {
29218 as_bad_where (fixP->fx_file, fixP->fx_line,
29219 _("rel31 relocation overflow"));
29220 }
29221 newval |= value & 0x7fffffff;
29222 md_number_to_chars (buf, newval, 4);
29223 }
29224 break;
c19d1205 29225#endif
a737bd4d 29226
c19d1205 29227 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 29228 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
32c36c3c 29229 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
9db2f6b4
RL
29230 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29231 newval = md_chars_to_number (buf, INSN_SIZE);
29232 else
29233 newval = get_thumb32_insn (buf);
29234 if ((newval & 0x0f200f00) == 0x0d000900)
29235 {
29236 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
7af67752 29237 has permitted values that are multiples of 2, in the range -510
9db2f6b4 29238 to 510. */
7af67752 29239 if (value + 510 > 510 + 510 || (value & 1))
9db2f6b4
RL
29240 as_bad_where (fixP->fx_file, fixP->fx_line,
29241 _("co-processor offset out of range"));
29242 }
32c36c3c
AV
29243 else if ((newval & 0xfe001f80) == 0xec000f80)
29244 {
7af67752 29245 if (value + 511 > 512 + 511 || (value & 3))
32c36c3c
AV
29246 as_bad_where (fixP->fx_file, fixP->fx_line,
29247 _("co-processor offset out of range"));
29248 }
7af67752 29249 else if (value + 1023 > 1023 + 1023 || (value & 3))
c19d1205
ZW
29250 as_bad_where (fixP->fx_file, fixP->fx_line,
29251 _("co-processor offset out of range"));
29252 cp_off_common:
7af67752
AM
29253 sign = (offsetT) value > 0;
29254 if ((offsetT) value < 0)
c19d1205 29255 value = -value;
8f06b2d8
PB
29256 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29257 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29258 newval = md_chars_to_number (buf, INSN_SIZE);
29259 else
29260 newval = get_thumb32_insn (buf);
26d97720 29261 if (value == 0)
32c36c3c
AV
29262 {
29263 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29264 newval &= 0xffffff80;
29265 else
29266 newval &= 0xffffff00;
29267 }
26d97720
NS
29268 else
29269 {
32c36c3c
AV
29270 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29271 newval &= 0xff7fff80;
29272 else
29273 newval &= 0xff7fff00;
9db2f6b4
RL
29274 if ((newval & 0x0f200f00) == 0x0d000900)
29275 {
29276 /* This is a fp16 vstr/vldr.
29277
29278 It requires the immediate offset in the instruction is shifted
29279 left by 1 to be a half-word offset.
29280
29281 Here, left shift by 1 first, and later right shift by 2
29282 should get the right offset. */
29283 value <<= 1;
29284 }
26d97720
NS
29285 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29286 }
8f06b2d8
PB
29287 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29288 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29289 md_number_to_chars (buf, newval, INSN_SIZE);
29290 else
29291 put_thumb32_insn (buf, newval);
c19d1205 29292 break;
a737bd4d 29293
c19d1205 29294 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 29295 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
7af67752 29296 if (value + 255 > 255 + 255)
c19d1205
ZW
29297 as_bad_where (fixP->fx_file, fixP->fx_line,
29298 _("co-processor offset out of range"));
df7849c5 29299 value *= 4;
c19d1205 29300 goto cp_off_common;
6c43fab6 29301
c19d1205
ZW
29302 case BFD_RELOC_ARM_THUMB_OFFSET:
29303 newval = md_chars_to_number (buf, THUMB_SIZE);
29304 /* Exactly what ranges, and where the offset is inserted depends
29305 on the type of instruction, we can establish this from the
29306 top 4 bits. */
29307 switch (newval >> 12)
29308 {
29309 case 4: /* PC load. */
29310 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29311 forced to zero for these loads; md_pcrel_from has already
29312 compensated for this. */
29313 if (value & 3)
29314 as_bad_where (fixP->fx_file, fixP->fx_line,
29315 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
29316 (((unsigned long) fixP->fx_frag->fr_address
29317 + (unsigned long) fixP->fx_where) & ~3)
29318 + (unsigned long) value);
749479c8
AO
29319 else if (get_recorded_alignment (seg) < 2)
29320 as_warn_where (fixP->fx_file, fixP->fx_line,
29321 _("section does not have enough alignment to ensure safe PC-relative loads"));
a737bd4d 29322
c19d1205
ZW
29323 if (value & ~0x3fc)
29324 as_bad_where (fixP->fx_file, fixP->fx_line,
29325 _("invalid offset, value too big (0x%08lX)"),
29326 (long) value);
a737bd4d 29327
c19d1205
ZW
29328 newval |= value >> 2;
29329 break;
a737bd4d 29330
c19d1205
ZW
29331 case 9: /* SP load/store. */
29332 if (value & ~0x3fc)
29333 as_bad_where (fixP->fx_file, fixP->fx_line,
29334 _("invalid offset, value too big (0x%08lX)"),
29335 (long) value);
29336 newval |= value >> 2;
29337 break;
6c43fab6 29338
c19d1205
ZW
29339 case 6: /* Word load/store. */
29340 if (value & ~0x7c)
29341 as_bad_where (fixP->fx_file, fixP->fx_line,
29342 _("invalid offset, value too big (0x%08lX)"),
29343 (long) value);
29344 newval |= value << 4; /* 6 - 2. */
29345 break;
a737bd4d 29346
c19d1205
ZW
29347 case 7: /* Byte load/store. */
29348 if (value & ~0x1f)
29349 as_bad_where (fixP->fx_file, fixP->fx_line,
29350 _("invalid offset, value too big (0x%08lX)"),
29351 (long) value);
29352 newval |= value << 6;
29353 break;
a737bd4d 29354
c19d1205
ZW
29355 case 8: /* Halfword load/store. */
29356 if (value & ~0x3e)
29357 as_bad_where (fixP->fx_file, fixP->fx_line,
29358 _("invalid offset, value too big (0x%08lX)"),
29359 (long) value);
29360 newval |= value << 5; /* 6 - 1. */
29361 break;
a737bd4d 29362
c19d1205
ZW
29363 default:
29364 as_bad_where (fixP->fx_file, fixP->fx_line,
29365 "Unable to process relocation for thumb opcode: %lx",
29366 (unsigned long) newval);
29367 break;
29368 }
29369 md_number_to_chars (buf, newval, THUMB_SIZE);
29370 break;
a737bd4d 29371
c19d1205
ZW
29372 case BFD_RELOC_ARM_THUMB_ADD:
29373 /* This is a complicated relocation, since we use it for all of
29374 the following immediate relocations:
a737bd4d 29375
c19d1205
ZW
29376 3bit ADD/SUB
29377 8bit ADD/SUB
29378 9bit ADD/SUB SP word-aligned
29379 10bit ADD PC/SP word-aligned
a737bd4d 29380
c19d1205
ZW
29381 The type of instruction being processed is encoded in the
29382 instruction field:
a737bd4d 29383
c19d1205
ZW
29384 0x8000 SUB
29385 0x00F0 Rd
29386 0x000F Rs
29387 */
29388 newval = md_chars_to_number (buf, THUMB_SIZE);
29389 {
29390 int rd = (newval >> 4) & 0xf;
29391 int rs = newval & 0xf;
29392 int subtract = !!(newval & 0x8000);
a737bd4d 29393
c19d1205
ZW
29394 /* Check for HI regs, only very restricted cases allowed:
29395 Adjusting SP, and using PC or SP to get an address. */
29396 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29397 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29398 as_bad_where (fixP->fx_file, fixP->fx_line,
29399 _("invalid Hi register with immediate"));
a737bd4d 29400
c19d1205 29401 /* If value is negative, choose the opposite instruction. */
7af67752 29402 if ((offsetT) value < 0)
c19d1205
ZW
29403 {
29404 value = -value;
29405 subtract = !subtract;
7af67752 29406 if ((offsetT) value < 0)
c19d1205
ZW
29407 as_bad_where (fixP->fx_file, fixP->fx_line,
29408 _("immediate value out of range"));
29409 }
a737bd4d 29410
c19d1205
ZW
29411 if (rd == REG_SP)
29412 {
75c11999 29413 if (value & ~0x1fc)
c19d1205
ZW
29414 as_bad_where (fixP->fx_file, fixP->fx_line,
29415 _("invalid immediate for stack address calculation"));
29416 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29417 newval |= value >> 2;
29418 }
29419 else if (rs == REG_PC || rs == REG_SP)
29420 {
c12d2c9d
NC
29421 /* PR gas/18541. If the addition is for a defined symbol
29422 within range of an ADR instruction then accept it. */
29423 if (subtract
29424 && value == 4
29425 && fixP->fx_addsy != NULL)
29426 {
29427 subtract = 0;
29428
29429 if (! S_IS_DEFINED (fixP->fx_addsy)
29430 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29431 || S_IS_WEAK (fixP->fx_addsy))
29432 {
29433 as_bad_where (fixP->fx_file, fixP->fx_line,
29434 _("address calculation needs a strongly defined nearby symbol"));
29435 }
29436 else
29437 {
29438 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29439
29440 /* Round up to the next 4-byte boundary. */
29441 if (v & 3)
29442 v = (v + 3) & ~ 3;
29443 else
29444 v += 4;
29445 v = S_GET_VALUE (fixP->fx_addsy) - v;
29446
29447 if (v & ~0x3fc)
29448 {
29449 as_bad_where (fixP->fx_file, fixP->fx_line,
29450 _("symbol too far away"));
29451 }
29452 else
29453 {
29454 fixP->fx_done = 1;
29455 value = v;
29456 }
29457 }
29458 }
29459
c19d1205
ZW
29460 if (subtract || value & ~0x3fc)
29461 as_bad_where (fixP->fx_file, fixP->fx_line,
29462 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 29463 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
29464 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29465 newval |= rd << 8;
29466 newval |= value >> 2;
29467 }
29468 else if (rs == rd)
29469 {
29470 if (value & ~0xff)
29471 as_bad_where (fixP->fx_file, fixP->fx_line,
29472 _("immediate value out of range"));
29473 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29474 newval |= (rd << 8) | value;
29475 }
29476 else
29477 {
29478 if (value & ~0x7)
29479 as_bad_where (fixP->fx_file, fixP->fx_line,
29480 _("immediate value out of range"));
29481 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29482 newval |= rd | (rs << 3) | (value << 6);
29483 }
29484 }
29485 md_number_to_chars (buf, newval, THUMB_SIZE);
29486 break;
a737bd4d 29487
c19d1205
ZW
29488 case BFD_RELOC_ARM_THUMB_IMM:
29489 newval = md_chars_to_number (buf, THUMB_SIZE);
7af67752 29490 if (value > 255)
c19d1205 29491 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 29492 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
29493 (long) value);
29494 newval |= value;
29495 md_number_to_chars (buf, newval, THUMB_SIZE);
29496 break;
a737bd4d 29497
c19d1205
ZW
29498 case BFD_RELOC_ARM_THUMB_SHIFT:
29499 /* 5bit shift value (0..32). LSL cannot take 32. */
29500 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29501 temp = newval & 0xf800;
7af67752 29502 if (value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
c19d1205
ZW
29503 as_bad_where (fixP->fx_file, fixP->fx_line,
29504 _("invalid shift value: %ld"), (long) value);
29505 /* Shifts of zero must be encoded as LSL. */
29506 if (value == 0)
29507 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29508 /* Shifts of 32 are encoded as zero. */
29509 else if (value == 32)
29510 value = 0;
29511 newval |= value << 6;
29512 md_number_to_chars (buf, newval, THUMB_SIZE);
29513 break;
a737bd4d 29514
c19d1205
ZW
29515 case BFD_RELOC_VTABLE_INHERIT:
29516 case BFD_RELOC_VTABLE_ENTRY:
29517 fixP->fx_done = 0;
29518 return;
6c43fab6 29519
b6895b4f
PB
29520 case BFD_RELOC_ARM_MOVW:
29521 case BFD_RELOC_ARM_MOVT:
29522 case BFD_RELOC_ARM_THUMB_MOVW:
29523 case BFD_RELOC_ARM_THUMB_MOVT:
29524 if (fixP->fx_done || !seg->use_rela_p)
29525 {
29526 /* REL format relocations are limited to a 16-bit addend. */
29527 if (!fixP->fx_done)
29528 {
7af67752 29529 if (value + 0x8000 > 0x7fff + 0x8000)
b6895b4f 29530 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 29531 _("offset out of range"));
b6895b4f
PB
29532 }
29533 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29534 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29535 {
29536 value >>= 16;
29537 }
29538
29539 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29540 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29541 {
29542 newval = get_thumb32_insn (buf);
29543 newval &= 0xfbf08f00;
29544 newval |= (value & 0xf000) << 4;
29545 newval |= (value & 0x0800) << 15;
29546 newval |= (value & 0x0700) << 4;
29547 newval |= (value & 0x00ff);
29548 put_thumb32_insn (buf, newval);
29549 }
29550 else
29551 {
29552 newval = md_chars_to_number (buf, 4);
29553 newval &= 0xfff0f000;
29554 newval |= value & 0x0fff;
29555 newval |= (value & 0xf000) << 4;
29556 md_number_to_chars (buf, newval, 4);
29557 }
29558 }
29559 return;
29560
72d98d16
MG
29561 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29562 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29563 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29564 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29565 gas_assert (!fixP->fx_done);
29566 {
29567 bfd_vma insn;
29568 bfd_boolean is_mov;
29569 bfd_vma encoded_addend = value;
29570
29571 /* Check that addend can be encoded in instruction. */
7af67752 29572 if (!seg->use_rela_p && value > 255)
72d98d16
MG
29573 as_bad_where (fixP->fx_file, fixP->fx_line,
29574 _("the offset 0x%08lX is not representable"),
29575 (unsigned long) encoded_addend);
29576
29577 /* Extract the instruction. */
29578 insn = md_chars_to_number (buf, THUMB_SIZE);
29579 is_mov = (insn & 0xf800) == 0x2000;
29580
29581 /* Encode insn. */
29582 if (is_mov)
29583 {
29584 if (!seg->use_rela_p)
29585 insn |= encoded_addend;
29586 }
29587 else
29588 {
29589 int rd, rs;
29590
29591 /* Extract the instruction. */
29592 /* Encoding is the following
29593 0x8000 SUB
29594 0x00F0 Rd
29595 0x000F Rs
29596 */
29597 /* The following conditions must be true :
29598 - ADD
29599 - Rd == Rs
29600 - Rd <= 7
29601 */
29602 rd = (insn >> 4) & 0xf;
29603 rs = insn & 0xf;
29604 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29605 as_bad_where (fixP->fx_file, fixP->fx_line,
29606 _("Unable to process relocation for thumb opcode: %lx"),
29607 (unsigned long) insn);
29608
29609 /* Encode as ADD immediate8 thumb 1 code. */
29610 insn = 0x3000 | (rd << 8);
29611
29612 /* Place the encoded addend into the first 8 bits of the
29613 instruction. */
29614 if (!seg->use_rela_p)
29615 insn |= encoded_addend;
29616 }
29617
29618 /* Update the instruction. */
29619 md_number_to_chars (buf, insn, THUMB_SIZE);
29620 }
29621 break;
29622
4962c51a
MS
29623 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29624 case BFD_RELOC_ARM_ALU_PC_G0:
29625 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29626 case BFD_RELOC_ARM_ALU_PC_G1:
29627 case BFD_RELOC_ARM_ALU_PC_G2:
29628 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29629 case BFD_RELOC_ARM_ALU_SB_G0:
29630 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29631 case BFD_RELOC_ARM_ALU_SB_G1:
29632 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 29633 gas_assert (!fixP->fx_done);
4962c51a
MS
29634 if (!seg->use_rela_p)
29635 {
477330fc
RM
29636 bfd_vma insn;
29637 bfd_vma encoded_addend;
7af67752 29638 bfd_vma addend_abs = llabs ((offsetT) value);
477330fc
RM
29639
29640 /* Check that the absolute value of the addend can be
29641 expressed as an 8-bit constant plus a rotation. */
29642 encoded_addend = encode_arm_immediate (addend_abs);
29643 if (encoded_addend == (unsigned int) FAIL)
4962c51a 29644 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29645 _("the offset 0x%08lX is not representable"),
29646 (unsigned long) addend_abs);
29647
29648 /* Extract the instruction. */
29649 insn = md_chars_to_number (buf, INSN_SIZE);
29650
29651 /* If the addend is positive, use an ADD instruction.
29652 Otherwise use a SUB. Take care not to destroy the S bit. */
29653 insn &= 0xff1fffff;
7af67752 29654 if ((offsetT) value < 0)
477330fc
RM
29655 insn |= 1 << 22;
29656 else
29657 insn |= 1 << 23;
29658
29659 /* Place the encoded addend into the first 12 bits of the
29660 instruction. */
29661 insn &= 0xfffff000;
29662 insn |= encoded_addend;
29663
29664 /* Update the instruction. */
29665 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
29666 }
29667 break;
29668
29669 case BFD_RELOC_ARM_LDR_PC_G0:
29670 case BFD_RELOC_ARM_LDR_PC_G1:
29671 case BFD_RELOC_ARM_LDR_PC_G2:
29672 case BFD_RELOC_ARM_LDR_SB_G0:
29673 case BFD_RELOC_ARM_LDR_SB_G1:
29674 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 29675 gas_assert (!fixP->fx_done);
4962c51a 29676 if (!seg->use_rela_p)
477330fc
RM
29677 {
29678 bfd_vma insn;
7af67752 29679 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29680
477330fc
RM
29681 /* Check that the absolute value of the addend can be
29682 encoded in 12 bits. */
29683 if (addend_abs >= 0x1000)
4962c51a 29684 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29685 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29686 (unsigned long) addend_abs);
29687
29688 /* Extract the instruction. */
29689 insn = md_chars_to_number (buf, INSN_SIZE);
29690
29691 /* If the addend is negative, clear bit 23 of the instruction.
29692 Otherwise set it. */
7af67752 29693 if ((offsetT) value < 0)
477330fc
RM
29694 insn &= ~(1 << 23);
29695 else
29696 insn |= 1 << 23;
29697
29698 /* Place the absolute value of the addend into the first 12 bits
29699 of the instruction. */
29700 insn &= 0xfffff000;
29701 insn |= addend_abs;
29702
29703 /* Update the instruction. */
29704 md_number_to_chars (buf, insn, INSN_SIZE);
29705 }
4962c51a
MS
29706 break;
29707
29708 case BFD_RELOC_ARM_LDRS_PC_G0:
29709 case BFD_RELOC_ARM_LDRS_PC_G1:
29710 case BFD_RELOC_ARM_LDRS_PC_G2:
29711 case BFD_RELOC_ARM_LDRS_SB_G0:
29712 case BFD_RELOC_ARM_LDRS_SB_G1:
29713 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 29714 gas_assert (!fixP->fx_done);
4962c51a 29715 if (!seg->use_rela_p)
477330fc
RM
29716 {
29717 bfd_vma insn;
7af67752 29718 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29719
477330fc
RM
29720 /* Check that the absolute value of the addend can be
29721 encoded in 8 bits. */
29722 if (addend_abs >= 0x100)
4962c51a 29723 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29724 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29725 (unsigned long) addend_abs);
29726
29727 /* Extract the instruction. */
29728 insn = md_chars_to_number (buf, INSN_SIZE);
29729
29730 /* If the addend is negative, clear bit 23 of the instruction.
29731 Otherwise set it. */
7af67752 29732 if ((offsetT) value < 0)
477330fc
RM
29733 insn &= ~(1 << 23);
29734 else
29735 insn |= 1 << 23;
29736
29737 /* Place the first four bits of the absolute value of the addend
29738 into the first 4 bits of the instruction, and the remaining
29739 four into bits 8 .. 11. */
29740 insn &= 0xfffff0f0;
29741 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29742
29743 /* Update the instruction. */
29744 md_number_to_chars (buf, insn, INSN_SIZE);
29745 }
4962c51a
MS
29746 break;
29747
29748 case BFD_RELOC_ARM_LDC_PC_G0:
29749 case BFD_RELOC_ARM_LDC_PC_G1:
29750 case BFD_RELOC_ARM_LDC_PC_G2:
29751 case BFD_RELOC_ARM_LDC_SB_G0:
29752 case BFD_RELOC_ARM_LDC_SB_G1:
29753 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 29754 gas_assert (!fixP->fx_done);
4962c51a 29755 if (!seg->use_rela_p)
477330fc
RM
29756 {
29757 bfd_vma insn;
7af67752 29758 bfd_vma addend_abs = llabs ((offsetT) value);
4962c51a 29759
477330fc
RM
29760 /* Check that the absolute value of the addend is a multiple of
29761 four and, when divided by four, fits in 8 bits. */
29762 if (addend_abs & 0x3)
4962c51a 29763 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29764 _("bad offset 0x%08lX (must be word-aligned)"),
29765 (unsigned long) addend_abs);
4962c51a 29766
477330fc 29767 if ((addend_abs >> 2) > 0xff)
4962c51a 29768 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
29769 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29770 (unsigned long) addend_abs);
29771
29772 /* Extract the instruction. */
29773 insn = md_chars_to_number (buf, INSN_SIZE);
29774
29775 /* If the addend is negative, clear bit 23 of the instruction.
29776 Otherwise set it. */
7af67752 29777 if ((offsetT) value < 0)
477330fc
RM
29778 insn &= ~(1 << 23);
29779 else
29780 insn |= 1 << 23;
29781
29782 /* Place the addend (divided by four) into the first eight
29783 bits of the instruction. */
29784 insn &= 0xfffffff0;
29785 insn |= addend_abs >> 2;
29786
29787 /* Update the instruction. */
29788 md_number_to_chars (buf, insn, INSN_SIZE);
29789 }
4962c51a
MS
29790 break;
29791
e12437dc
AV
29792 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29793 if (fixP->fx_addsy
29794 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29795 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29796 && ARM_IS_FUNC (fixP->fx_addsy)
29797 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29798 {
29799 /* Force a relocation for a branch 5 bits wide. */
29800 fixP->fx_done = 0;
29801 }
29802 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29803 as_bad_where (fixP->fx_file, fixP->fx_line,
29804 BAD_BRANCH_OFF);
29805
29806 if (fixP->fx_done || !seg->use_rela_p)
29807 {
29808 addressT boff = value >> 1;
29809
29810 newval = md_chars_to_number (buf, THUMB_SIZE);
29811 newval |= (boff << 7);
29812 md_number_to_chars (buf, newval, THUMB_SIZE);
29813 }
29814 break;
29815
f6b2b12d
AV
29816 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29817 if (fixP->fx_addsy
29818 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29819 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29820 && ARM_IS_FUNC (fixP->fx_addsy)
29821 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29822 {
29823 fixP->fx_done = 0;
29824 }
7af67752 29825 if ((value & ~0x7f) && ((value & ~0x3f) != (valueT) ~0x3f))
f6b2b12d
AV
29826 as_bad_where (fixP->fx_file, fixP->fx_line,
29827 _("branch out of range"));
29828
29829 if (fixP->fx_done || !seg->use_rela_p)
29830 {
29831 newval = md_chars_to_number (buf, THUMB_SIZE);
29832
29833 addressT boff = ((newval & 0x0780) >> 7) << 1;
29834 addressT diff = value - boff;
29835
29836 if (diff == 4)
29837 {
29838 newval |= 1 << 1; /* T bit. */
29839 }
29840 else if (diff != 2)
29841 {
29842 as_bad_where (fixP->fx_file, fixP->fx_line,
29843 _("out of range label-relative fixup value"));
29844 }
29845 md_number_to_chars (buf, newval, THUMB_SIZE);
29846 }
29847 break;
29848
e5d6e09e
AV
29849 case BFD_RELOC_ARM_THUMB_BF17:
29850 if (fixP->fx_addsy
29851 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29852 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29853 && ARM_IS_FUNC (fixP->fx_addsy)
29854 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29855 {
29856 /* Force a relocation for a branch 17 bits wide. */
29857 fixP->fx_done = 0;
29858 }
29859
29860 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29861 as_bad_where (fixP->fx_file, fixP->fx_line,
29862 BAD_BRANCH_OFF);
29863
29864 if (fixP->fx_done || !seg->use_rela_p)
29865 {
29866 offsetT newval2;
29867 addressT immA, immB, immC;
29868
29869 immA = (value & 0x0001f000) >> 12;
29870 immB = (value & 0x00000ffc) >> 2;
29871 immC = (value & 0x00000002) >> 1;
29872
29873 newval = md_chars_to_number (buf, THUMB_SIZE);
29874 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29875 newval |= immA;
29876 newval2 |= (immC << 11) | (immB << 1);
29877 md_number_to_chars (buf, newval, THUMB_SIZE);
29878 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29879 }
29880 break;
29881
1caf72a5
AV
29882 case BFD_RELOC_ARM_THUMB_BF19:
29883 if (fixP->fx_addsy
29884 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29885 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29886 && ARM_IS_FUNC (fixP->fx_addsy)
29887 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29888 {
29889 /* Force a relocation for a branch 19 bits wide. */
29890 fixP->fx_done = 0;
29891 }
29892
29893 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29894 as_bad_where (fixP->fx_file, fixP->fx_line,
29895 BAD_BRANCH_OFF);
29896
29897 if (fixP->fx_done || !seg->use_rela_p)
29898 {
29899 offsetT newval2;
29900 addressT immA, immB, immC;
29901
29902 immA = (value & 0x0007f000) >> 12;
29903 immB = (value & 0x00000ffc) >> 2;
29904 immC = (value & 0x00000002) >> 1;
29905
29906 newval = md_chars_to_number (buf, THUMB_SIZE);
29907 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29908 newval |= immA;
29909 newval2 |= (immC << 11) | (immB << 1);
29910 md_number_to_chars (buf, newval, THUMB_SIZE);
29911 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29912 }
29913 break;
29914
1889da70
AV
29915 case BFD_RELOC_ARM_THUMB_BF13:
29916 if (fixP->fx_addsy
29917 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29918 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29919 && ARM_IS_FUNC (fixP->fx_addsy)
29920 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29921 {
29922 /* Force a relocation for a branch 13 bits wide. */
29923 fixP->fx_done = 0;
29924 }
29925
29926 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29927 as_bad_where (fixP->fx_file, fixP->fx_line,
29928 BAD_BRANCH_OFF);
29929
29930 if (fixP->fx_done || !seg->use_rela_p)
29931 {
29932 offsetT newval2;
29933 addressT immA, immB, immC;
29934
29935 immA = (value & 0x00001000) >> 12;
29936 immB = (value & 0x00000ffc) >> 2;
29937 immC = (value & 0x00000002) >> 1;
29938
29939 newval = md_chars_to_number (buf, THUMB_SIZE);
29940 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29941 newval |= immA;
29942 newval2 |= (immC << 11) | (immB << 1);
29943 md_number_to_chars (buf, newval, THUMB_SIZE);
29944 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29945 }
29946 break;
29947
60f993ce
AV
29948 case BFD_RELOC_ARM_THUMB_LOOP12:
29949 if (fixP->fx_addsy
29950 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29951 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29952 && ARM_IS_FUNC (fixP->fx_addsy)
29953 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29954 {
29955 /* Force a relocation for a branch 12 bits wide. */
29956 fixP->fx_done = 0;
29957 }
29958
29959 bfd_vma insn = get_thumb32_insn (buf);
1f6234a3 29960 /* le lr, <label>, le <label> or letp lr, <label> */
60f993ce 29961 if (((insn & 0xffffffff) == 0xf00fc001)
1f6234a3
AV
29962 || ((insn & 0xffffffff) == 0xf02fc001)
29963 || ((insn & 0xffffffff) == 0xf01fc001))
60f993ce
AV
29964 value = -value;
29965
29966 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29967 as_bad_where (fixP->fx_file, fixP->fx_line,
29968 BAD_BRANCH_OFF);
29969 if (fixP->fx_done || !seg->use_rela_p)
29970 {
29971 addressT imml, immh;
29972
29973 immh = (value & 0x00000ffc) >> 2;
29974 imml = (value & 0x00000002) >> 1;
29975
29976 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29977 newval |= (imml << 11) | (immh << 1);
29978 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29979 }
29980 break;
29981
845b51d6
PB
29982 case BFD_RELOC_ARM_V4BX:
29983 /* This will need to go in the object file. */
29984 fixP->fx_done = 0;
29985 break;
29986
c19d1205
ZW
29987 case BFD_RELOC_UNUSED:
29988 default:
29989 as_bad_where (fixP->fx_file, fixP->fx_line,
29990 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29991 }
6c43fab6
RE
29992}
29993
c19d1205
ZW
29994/* Translate internal representation of relocation info to BFD target
29995 format. */
a737bd4d 29996
c19d1205 29997arelent *
00a97672 29998tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 29999{
c19d1205
ZW
30000 arelent * reloc;
30001 bfd_reloc_code_real_type code;
a737bd4d 30002
325801bd 30003 reloc = XNEW (arelent);
a737bd4d 30004
325801bd 30005 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
30006 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
30007 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 30008
2fc8bdac 30009 if (fixp->fx_pcrel)
00a97672
RS
30010 {
30011 if (section->use_rela_p)
30012 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
30013 else
30014 fixp->fx_offset = reloc->address;
30015 }
c19d1205 30016 reloc->addend = fixp->fx_offset;
a737bd4d 30017
c19d1205 30018 switch (fixp->fx_r_type)
a737bd4d 30019 {
c19d1205
ZW
30020 case BFD_RELOC_8:
30021 if (fixp->fx_pcrel)
30022 {
30023 code = BFD_RELOC_8_PCREL;
30024 break;
30025 }
1a0670f3 30026 /* Fall through. */
a737bd4d 30027
c19d1205
ZW
30028 case BFD_RELOC_16:
30029 if (fixp->fx_pcrel)
30030 {
30031 code = BFD_RELOC_16_PCREL;
30032 break;
30033 }
1a0670f3 30034 /* Fall through. */
6c43fab6 30035
c19d1205
ZW
30036 case BFD_RELOC_32:
30037 if (fixp->fx_pcrel)
30038 {
30039 code = BFD_RELOC_32_PCREL;
30040 break;
30041 }
1a0670f3 30042 /* Fall through. */
a737bd4d 30043
b6895b4f
PB
30044 case BFD_RELOC_ARM_MOVW:
30045 if (fixp->fx_pcrel)
30046 {
30047 code = BFD_RELOC_ARM_MOVW_PCREL;
30048 break;
30049 }
1a0670f3 30050 /* Fall through. */
b6895b4f
PB
30051
30052 case BFD_RELOC_ARM_MOVT:
30053 if (fixp->fx_pcrel)
30054 {
30055 code = BFD_RELOC_ARM_MOVT_PCREL;
30056 break;
30057 }
1a0670f3 30058 /* Fall through. */
b6895b4f
PB
30059
30060 case BFD_RELOC_ARM_THUMB_MOVW:
30061 if (fixp->fx_pcrel)
30062 {
30063 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30064 break;
30065 }
1a0670f3 30066 /* Fall through. */
b6895b4f
PB
30067
30068 case BFD_RELOC_ARM_THUMB_MOVT:
30069 if (fixp->fx_pcrel)
30070 {
30071 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30072 break;
30073 }
1a0670f3 30074 /* Fall through. */
b6895b4f 30075
c19d1205
ZW
30076 case BFD_RELOC_NONE:
30077 case BFD_RELOC_ARM_PCREL_BRANCH:
30078 case BFD_RELOC_ARM_PCREL_BLX:
30079 case BFD_RELOC_RVA:
30080 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30081 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30082 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30083 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30084 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30085 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
30086 case BFD_RELOC_VTABLE_ENTRY:
30087 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
30088#ifdef TE_PE
30089 case BFD_RELOC_32_SECREL:
30090#endif
c19d1205
ZW
30091 code = fixp->fx_r_type;
30092 break;
a737bd4d 30093
00adf2d4
JB
30094 case BFD_RELOC_THUMB_PCREL_BLX:
30095#ifdef OBJ_ELF
30096 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30097 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30098 else
30099#endif
30100 code = BFD_RELOC_THUMB_PCREL_BLX;
30101 break;
30102
c19d1205
ZW
30103 case BFD_RELOC_ARM_LITERAL:
30104 case BFD_RELOC_ARM_HWLITERAL:
30105 /* If this is called then the a literal has
30106 been referenced across a section boundary. */
30107 as_bad_where (fixp->fx_file, fixp->fx_line,
30108 _("literal referenced across section boundary"));
30109 return NULL;
a737bd4d 30110
c19d1205 30111#ifdef OBJ_ELF
0855e32b
NS
30112 case BFD_RELOC_ARM_TLS_CALL:
30113 case BFD_RELOC_ARM_THM_TLS_CALL:
30114 case BFD_RELOC_ARM_TLS_DESCSEQ:
30115 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
30116 case BFD_RELOC_ARM_GOT32:
30117 case BFD_RELOC_ARM_GOTOFF:
b43420e6 30118 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
30119 case BFD_RELOC_ARM_PLT32:
30120 case BFD_RELOC_ARM_TARGET1:
30121 case BFD_RELOC_ARM_ROSEGREL32:
30122 case BFD_RELOC_ARM_SBREL32:
30123 case BFD_RELOC_ARM_PREL31:
30124 case BFD_RELOC_ARM_TARGET2:
c19d1205 30125 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
30126 case BFD_RELOC_ARM_PCREL_CALL:
30127 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
30128 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30129 case BFD_RELOC_ARM_ALU_PC_G0:
30130 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30131 case BFD_RELOC_ARM_ALU_PC_G1:
30132 case BFD_RELOC_ARM_ALU_PC_G2:
30133 case BFD_RELOC_ARM_LDR_PC_G0:
30134 case BFD_RELOC_ARM_LDR_PC_G1:
30135 case BFD_RELOC_ARM_LDR_PC_G2:
30136 case BFD_RELOC_ARM_LDRS_PC_G0:
30137 case BFD_RELOC_ARM_LDRS_PC_G1:
30138 case BFD_RELOC_ARM_LDRS_PC_G2:
30139 case BFD_RELOC_ARM_LDC_PC_G0:
30140 case BFD_RELOC_ARM_LDC_PC_G1:
30141 case BFD_RELOC_ARM_LDC_PC_G2:
30142 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30143 case BFD_RELOC_ARM_ALU_SB_G0:
30144 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30145 case BFD_RELOC_ARM_ALU_SB_G1:
30146 case BFD_RELOC_ARM_ALU_SB_G2:
30147 case BFD_RELOC_ARM_LDR_SB_G0:
30148 case BFD_RELOC_ARM_LDR_SB_G1:
30149 case BFD_RELOC_ARM_LDR_SB_G2:
30150 case BFD_RELOC_ARM_LDRS_SB_G0:
30151 case BFD_RELOC_ARM_LDRS_SB_G1:
30152 case BFD_RELOC_ARM_LDRS_SB_G2:
30153 case BFD_RELOC_ARM_LDC_SB_G0:
30154 case BFD_RELOC_ARM_LDC_SB_G1:
30155 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 30156 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
30157 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30158 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30159 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30160 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
188fd7ae
CL
30161 case BFD_RELOC_ARM_GOTFUNCDESC:
30162 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30163 case BFD_RELOC_ARM_FUNCDESC:
e5d6e09e 30164 case BFD_RELOC_ARM_THUMB_BF17:
1caf72a5 30165 case BFD_RELOC_ARM_THUMB_BF19:
1889da70 30166 case BFD_RELOC_ARM_THUMB_BF13:
c19d1205
ZW
30167 code = fixp->fx_r_type;
30168 break;
a737bd4d 30169
0855e32b 30170 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 30171 case BFD_RELOC_ARM_TLS_GD32:
5c5a4843 30172 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
75c11999 30173 case BFD_RELOC_ARM_TLS_LE32:
c19d1205 30174 case BFD_RELOC_ARM_TLS_IE32:
5c5a4843 30175 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
c19d1205 30176 case BFD_RELOC_ARM_TLS_LDM32:
5c5a4843 30177 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
c19d1205
ZW
30178 /* BFD will include the symbol's address in the addend.
30179 But we don't want that, so subtract it out again here. */
30180 if (!S_IS_COMMON (fixp->fx_addsy))
30181 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30182 code = fixp->fx_r_type;
30183 break;
30184#endif
a737bd4d 30185
c19d1205
ZW
30186 case BFD_RELOC_ARM_IMMEDIATE:
30187 as_bad_where (fixp->fx_file, fixp->fx_line,
30188 _("internal relocation (type: IMMEDIATE) not fixed up"));
30189 return NULL;
a737bd4d 30190
c19d1205
ZW
30191 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30192 as_bad_where (fixp->fx_file, fixp->fx_line,
30193 _("ADRL used for a symbol not defined in the same file"));
30194 return NULL;
a737bd4d 30195
e12437dc 30196 case BFD_RELOC_THUMB_PCREL_BRANCH5:
f6b2b12d 30197 case BFD_RELOC_THUMB_PCREL_BFCSEL:
60f993ce 30198 case BFD_RELOC_ARM_THUMB_LOOP12:
e12437dc
AV
30199 as_bad_where (fixp->fx_file, fixp->fx_line,
30200 _("%s used for a symbol not defined in the same file"),
30201 bfd_get_reloc_code_name (fixp->fx_r_type));
30202 return NULL;
30203
c19d1205 30204 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
30205 if (section->use_rela_p)
30206 {
30207 code = fixp->fx_r_type;
30208 break;
30209 }
30210
c19d1205
ZW
30211 if (fixp->fx_addsy != NULL
30212 && !S_IS_DEFINED (fixp->fx_addsy)
30213 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 30214 {
c19d1205
ZW
30215 as_bad_where (fixp->fx_file, fixp->fx_line,
30216 _("undefined local label `%s'"),
30217 S_GET_NAME (fixp->fx_addsy));
30218 return NULL;
a737bd4d
NC
30219 }
30220
c19d1205
ZW
30221 as_bad_where (fixp->fx_file, fixp->fx_line,
30222 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30223 return NULL;
a737bd4d 30224
c19d1205
ZW
30225 default:
30226 {
e0471c16 30227 const char * type;
6c43fab6 30228
c19d1205
ZW
30229 switch (fixp->fx_r_type)
30230 {
30231 case BFD_RELOC_NONE: type = "NONE"; break;
30232 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30233 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 30234 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
30235 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30236 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30237 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 30238 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 30239 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
30240 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30241 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30242 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30243 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30244 default: type = _("<unknown>"); break;
30245 }
30246 as_bad_where (fixp->fx_file, fixp->fx_line,
30247 _("cannot represent %s relocation in this object file format"),
30248 type);
30249 return NULL;
30250 }
a737bd4d 30251 }
6c43fab6 30252
c19d1205
ZW
30253#ifdef OBJ_ELF
30254 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30255 && GOT_symbol
30256 && fixp->fx_addsy == GOT_symbol)
30257 {
30258 code = BFD_RELOC_ARM_GOTPC;
30259 reloc->addend = fixp->fx_offset = reloc->address;
30260 }
30261#endif
6c43fab6 30262
c19d1205 30263 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 30264
c19d1205
ZW
30265 if (reloc->howto == NULL)
30266 {
30267 as_bad_where (fixp->fx_file, fixp->fx_line,
30268 _("cannot represent %s relocation in this object file format"),
30269 bfd_get_reloc_code_name (code));
30270 return NULL;
30271 }
6c43fab6 30272
c19d1205
ZW
30273 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30274 vtable entry to be used in the relocation's section offset. */
30275 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30276 reloc->address = fixp->fx_offset;
6c43fab6 30277
c19d1205 30278 return reloc;
6c43fab6
RE
30279}
30280
c19d1205 30281/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 30282
c19d1205
ZW
30283void
30284cons_fix_new_arm (fragS * frag,
30285 int where,
30286 int size,
62ebcb5c
AM
30287 expressionS * exp,
30288 bfd_reloc_code_real_type reloc)
6c43fab6 30289{
c19d1205 30290 int pcrel = 0;
6c43fab6 30291
c19d1205
ZW
30292 /* Pick a reloc.
30293 FIXME: @@ Should look at CPU word size. */
30294 switch (size)
30295 {
30296 case 1:
62ebcb5c 30297 reloc = BFD_RELOC_8;
c19d1205
ZW
30298 break;
30299 case 2:
62ebcb5c 30300 reloc = BFD_RELOC_16;
c19d1205
ZW
30301 break;
30302 case 4:
30303 default:
62ebcb5c 30304 reloc = BFD_RELOC_32;
c19d1205
ZW
30305 break;
30306 case 8:
62ebcb5c 30307 reloc = BFD_RELOC_64;
c19d1205
ZW
30308 break;
30309 }
6c43fab6 30310
f0927246
NC
30311#ifdef TE_PE
30312 if (exp->X_op == O_secrel)
30313 {
30314 exp->X_op = O_symbol;
62ebcb5c 30315 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
30316 }
30317#endif
30318
62ebcb5c 30319 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 30320}
6c43fab6 30321
4343666d 30322#if defined (OBJ_COFF)
c19d1205
ZW
30323void
30324arm_validate_fix (fixS * fixP)
6c43fab6 30325{
c19d1205
ZW
30326 /* If the destination of the branch is a defined symbol which does not have
30327 the THUMB_FUNC attribute, then we must be calling a function which has
30328 the (interfacearm) attribute. We look for the Thumb entry point to that
30329 function and change the branch to refer to that function instead. */
30330 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30331 && fixP->fx_addsy != NULL
30332 && S_IS_DEFINED (fixP->fx_addsy)
30333 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 30334 {
c19d1205 30335 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 30336 }
c19d1205
ZW
30337}
30338#endif
6c43fab6 30339
267bf995 30340
c19d1205
ZW
30341int
30342arm_force_relocation (struct fix * fixp)
30343{
30344#if defined (OBJ_COFF) && defined (TE_PE)
30345 if (fixp->fx_r_type == BFD_RELOC_RVA)
30346 return 1;
30347#endif
6c43fab6 30348
267bf995
RR
30349 /* In case we have a call or a branch to a function in ARM ISA mode from
30350 a thumb function or vice-versa force the relocation. These relocations
30351 are cleared off for some cores that might have blx and simple transformations
30352 are possible. */
30353
30354#ifdef OBJ_ELF
30355 switch (fixp->fx_r_type)
30356 {
30357 case BFD_RELOC_ARM_PCREL_JUMP:
30358 case BFD_RELOC_ARM_PCREL_CALL:
30359 case BFD_RELOC_THUMB_PCREL_BLX:
30360 if (THUMB_IS_FUNC (fixp->fx_addsy))
30361 return 1;
30362 break;
30363
30364 case BFD_RELOC_ARM_PCREL_BLX:
30365 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30366 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30367 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30368 if (ARM_IS_FUNC (fixp->fx_addsy))
30369 return 1;
30370 break;
30371
30372 default:
30373 break;
30374 }
30375#endif
30376
b5884301
PB
30377 /* Resolve these relocations even if the symbol is extern or weak.
30378 Technically this is probably wrong due to symbol preemption.
30379 In practice these relocations do not have enough range to be useful
30380 at dynamic link time, and some code (e.g. in the Linux kernel)
30381 expects these references to be resolved. */
c19d1205
ZW
30382 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30383 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 30384 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 30385 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
30386 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30387 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30388 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
b59d128a 30389 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH12
16805f35 30390 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
30391 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30392 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
30393 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30394 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30395 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30396 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 30397 return 0;
a737bd4d 30398
4962c51a
MS
30399 /* Always leave these relocations for the linker. */
30400 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30401 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30402 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30403 return 1;
30404
f0291e4c
PB
30405 /* Always generate relocations against function symbols. */
30406 if (fixp->fx_r_type == BFD_RELOC_32
30407 && fixp->fx_addsy
30408 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30409 return 1;
30410
c19d1205 30411 return generic_force_reloc (fixp);
404ff6b5
AH
30412}
30413
0ffdc86c 30414#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
30415/* Relocations against function names must be left unadjusted,
30416 so that the linker can use this information to generate interworking
30417 stubs. The MIPS version of this function
c19d1205
ZW
30418 also prevents relocations that are mips-16 specific, but I do not
30419 know why it does this.
404ff6b5 30420
c19d1205
ZW
30421 FIXME:
30422 There is one other problem that ought to be addressed here, but
30423 which currently is not: Taking the address of a label (rather
30424 than a function) and then later jumping to that address. Such
30425 addresses also ought to have their bottom bit set (assuming that
30426 they reside in Thumb code), but at the moment they will not. */
404ff6b5 30427
c19d1205
ZW
30428bfd_boolean
30429arm_fix_adjustable (fixS * fixP)
404ff6b5 30430{
c19d1205
ZW
30431 if (fixP->fx_addsy == NULL)
30432 return 1;
404ff6b5 30433
e28387c3
PB
30434 /* Preserve relocations against symbols with function type. */
30435 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 30436 return FALSE;
e28387c3 30437
c19d1205
ZW
30438 if (THUMB_IS_FUNC (fixP->fx_addsy)
30439 && fixP->fx_subsy == NULL)
c921be7d 30440 return FALSE;
a737bd4d 30441
c19d1205
ZW
30442 /* We need the symbol name for the VTABLE entries. */
30443 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30444 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 30445 return FALSE;
404ff6b5 30446
c19d1205
ZW
30447 /* Don't allow symbols to be discarded on GOT related relocs. */
30448 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30449 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30450 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30451 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
5c5a4843 30452 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
c19d1205
ZW
30453 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30454 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
5c5a4843 30455 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
c19d1205 30456 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
5c5a4843 30457 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
c19d1205 30458 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
30459 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30460 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30461 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30462 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30463 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 30464 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 30465 return FALSE;
a737bd4d 30466
4962c51a
MS
30467 /* Similarly for group relocations. */
30468 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30469 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30470 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 30471 return FALSE;
4962c51a 30472
79947c54
CD
30473 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30474 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30475 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30476 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30477 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30478 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30479 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30480 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30481 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 30482 return FALSE;
79947c54 30483
72d98d16
MG
30484 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30485 offsets, so keep these symbols. */
30486 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30487 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30488 return FALSE;
30489
c921be7d 30490 return TRUE;
a737bd4d 30491}
0ffdc86c
NC
30492#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30493
30494#ifdef OBJ_ELF
c19d1205
ZW
30495const char *
30496elf32_arm_target_format (void)
404ff6b5 30497{
c19d1205
ZW
30498#ifdef TE_SYMBIAN
30499 return (target_big_endian
30500 ? "elf32-bigarm-symbian"
30501 : "elf32-littlearm-symbian");
30502#elif defined (TE_VXWORKS)
30503 return (target_big_endian
30504 ? "elf32-bigarm-vxworks"
30505 : "elf32-littlearm-vxworks");
b38cadfb
NC
30506#elif defined (TE_NACL)
30507 return (target_big_endian
30508 ? "elf32-bigarm-nacl"
30509 : "elf32-littlearm-nacl");
c19d1205 30510#else
18a20338
CL
30511 if (arm_fdpic)
30512 {
30513 if (target_big_endian)
30514 return "elf32-bigarm-fdpic";
30515 else
30516 return "elf32-littlearm-fdpic";
30517 }
c19d1205 30518 else
18a20338
CL
30519 {
30520 if (target_big_endian)
30521 return "elf32-bigarm";
30522 else
30523 return "elf32-littlearm";
30524 }
c19d1205 30525#endif
404ff6b5
AH
30526}
30527
c19d1205
ZW
30528void
30529armelf_frob_symbol (symbolS * symp,
30530 int * puntp)
404ff6b5 30531{
c19d1205
ZW
30532 elf_frob_symbol (symp, puntp);
30533}
30534#endif
404ff6b5 30535
c19d1205 30536/* MD interface: Finalization. */
a737bd4d 30537
c19d1205
ZW
30538void
30539arm_cleanup (void)
30540{
30541 literal_pool * pool;
a737bd4d 30542
5ee91343
AV
30543 /* Ensure that all the predication blocks are properly closed. */
30544 check_pred_blocks_finished ();
e07e6e58 30545
c19d1205
ZW
30546 for (pool = list_of_pools; pool; pool = pool->next)
30547 {
5f4273c7 30548 /* Put it at the end of the relevant section. */
c19d1205
ZW
30549 subseg_set (pool->section, pool->sub_section);
30550#ifdef OBJ_ELF
30551 arm_elf_change_section ();
30552#endif
30553 s_ltorg (0);
30554 }
404ff6b5
AH
30555}
30556
cd000bff
DJ
30557#ifdef OBJ_ELF
30558/* Remove any excess mapping symbols generated for alignment frags in
30559 SEC. We may have created a mapping symbol before a zero byte
30560 alignment; remove it if there's a mapping symbol after the
30561 alignment. */
30562static void
30563check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30564 void *dummy ATTRIBUTE_UNUSED)
30565{
30566 segment_info_type *seginfo = seg_info (sec);
30567 fragS *fragp;
30568
30569 if (seginfo == NULL || seginfo->frchainP == NULL)
30570 return;
30571
30572 for (fragp = seginfo->frchainP->frch_root;
30573 fragp != NULL;
30574 fragp = fragp->fr_next)
30575 {
30576 symbolS *sym = fragp->tc_frag_data.last_map;
30577 fragS *next = fragp->fr_next;
30578
30579 /* Variable-sized frags have been converted to fixed size by
30580 this point. But if this was variable-sized to start with,
30581 there will be a fixed-size frag after it. So don't handle
30582 next == NULL. */
30583 if (sym == NULL || next == NULL)
30584 continue;
30585
30586 if (S_GET_VALUE (sym) < next->fr_address)
30587 /* Not at the end of this frag. */
30588 continue;
30589 know (S_GET_VALUE (sym) == next->fr_address);
30590
30591 do
30592 {
30593 if (next->tc_frag_data.first_map != NULL)
30594 {
30595 /* Next frag starts with a mapping symbol. Discard this
30596 one. */
30597 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30598 break;
30599 }
30600
30601 if (next->fr_next == NULL)
30602 {
30603 /* This mapping symbol is at the end of the section. Discard
30604 it. */
30605 know (next->fr_fix == 0 && next->fr_var == 0);
30606 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30607 break;
30608 }
30609
30610 /* As long as we have empty frags without any mapping symbols,
30611 keep looking. */
30612 /* If the next frag is non-empty and does not start with a
30613 mapping symbol, then this mapping symbol is required. */
30614 if (next->fr_address != next->fr_next->fr_address)
30615 break;
30616
30617 next = next->fr_next;
30618 }
30619 while (next != NULL);
30620 }
30621}
30622#endif
30623
c19d1205
ZW
30624/* Adjust the symbol table. This marks Thumb symbols as distinct from
30625 ARM ones. */
404ff6b5 30626
c19d1205
ZW
30627void
30628arm_adjust_symtab (void)
404ff6b5 30629{
c19d1205
ZW
30630#ifdef OBJ_COFF
30631 symbolS * sym;
404ff6b5 30632
c19d1205
ZW
30633 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30634 {
30635 if (ARM_IS_THUMB (sym))
30636 {
30637 if (THUMB_IS_FUNC (sym))
30638 {
30639 /* Mark the symbol as a Thumb function. */
30640 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30641 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30642 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 30643
c19d1205
ZW
30644 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30645 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30646 else
30647 as_bad (_("%s: unexpected function type: %d"),
30648 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30649 }
30650 else switch (S_GET_STORAGE_CLASS (sym))
30651 {
30652 case C_EXT:
30653 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30654 break;
30655 case C_STAT:
30656 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30657 break;
30658 case C_LABEL:
30659 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30660 break;
30661 default:
30662 /* Do nothing. */
30663 break;
30664 }
30665 }
a737bd4d 30666
c19d1205
ZW
30667 if (ARM_IS_INTERWORK (sym))
30668 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 30669 }
c19d1205
ZW
30670#endif
30671#ifdef OBJ_ELF
30672 symbolS * sym;
30673 char bind;
404ff6b5 30674
c19d1205 30675 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 30676 {
c19d1205
ZW
30677 if (ARM_IS_THUMB (sym))
30678 {
30679 elf_symbol_type * elf_sym;
404ff6b5 30680
c19d1205
ZW
30681 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30682 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 30683
b0796911
PB
30684 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30685 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
30686 {
30687 /* If it's a .thumb_func, declare it as so,
30688 otherwise tag label as .code 16. */
30689 if (THUMB_IS_FUNC (sym))
39d911fc
TP
30690 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30691 ST_BRANCH_TO_THUMB);
3ba67470 30692 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
30693 elf_sym->internal_elf_sym.st_info =
30694 ELF_ST_INFO (bind, STT_ARM_16BIT);
30695 }
30696 }
30697 }
cd000bff
DJ
30698
30699 /* Remove any overlapping mapping symbols generated by alignment frags. */
30700 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
30701 /* Now do generic ELF adjustments. */
30702 elf_adjust_symtab ();
c19d1205 30703#endif
404ff6b5
AH
30704}
30705
c19d1205 30706/* MD interface: Initialization. */
404ff6b5 30707
a737bd4d 30708static void
c19d1205 30709set_constant_flonums (void)
a737bd4d 30710{
c19d1205 30711 int i;
404ff6b5 30712
c19d1205
ZW
30713 for (i = 0; i < NUM_FLOAT_VALS; i++)
30714 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30715 abort ();
a737bd4d 30716}
404ff6b5 30717
3e9e4fcf
JB
30718/* Auto-select Thumb mode if it's the only available instruction set for the
30719 given architecture. */
30720
30721static void
30722autoselect_thumb_from_cpu_variant (void)
30723{
30724 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30725 opcode_select (16);
30726}
30727
c19d1205
ZW
30728void
30729md_begin (void)
a737bd4d 30730{
c19d1205
ZW
30731 unsigned mach;
30732 unsigned int i;
404ff6b5 30733
f16c3d4f
AM
30734 arm_ops_hsh = str_htab_create ();
30735 arm_cond_hsh = str_htab_create ();
30736 arm_vcond_hsh = str_htab_create ();
30737 arm_shift_hsh = str_htab_create ();
30738 arm_psr_hsh = str_htab_create ();
30739 arm_v7m_psr_hsh = str_htab_create ();
30740 arm_reg_hsh = str_htab_create ();
30741 arm_reloc_hsh = str_htab_create ();
30742 arm_barrier_opt_hsh = str_htab_create ();
c19d1205
ZW
30743
30744 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
629310ab 30745 if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL)
fe0e921f 30746 str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0);
c19d1205 30747 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
fe0e921f 30748 str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0);
5ee91343 30749 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
fe0e921f 30750 str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0);
c19d1205 30751 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
fe0e921f 30752 str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0);
c19d1205 30753 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
fe0e921f 30754 str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0);
62b3e311 30755 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
629310ab 30756 str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
fe0e921f 30757 v7m_psrs + i, 0);
c19d1205 30758 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
fe0e921f 30759 str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0);
62b3e311
PB
30760 for (i = 0;
30761 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30762 i++)
629310ab 30763 str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
fe0e921f 30764 barrier_opt_names + i, 0);
c19d1205 30765#ifdef OBJ_ELF
3da1d841
NC
30766 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30767 {
30768 struct reloc_entry * entry = reloc_names + i;
30769
30770 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30771 /* This makes encode_branch() use the EABI versions of this relocation. */
30772 entry->reloc = BFD_RELOC_UNUSED;
30773
fe0e921f 30774 str_hash_insert (arm_reloc_hsh, entry->name, entry, 0);
3da1d841 30775 }
c19d1205
ZW
30776#endif
30777
30778 set_constant_flonums ();
404ff6b5 30779
c19d1205
ZW
30780 /* Set the cpu variant based on the command-line options. We prefer
30781 -mcpu= over -march= if both are set (as for GCC); and we prefer
30782 -mfpu= over any other way of setting the floating point unit.
30783 Use of legacy options with new options are faulted. */
e74cfd16 30784 if (legacy_cpu)
404ff6b5 30785 {
e74cfd16 30786 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
30787 as_bad (_("use of old and new-style options to set CPU type"));
30788
4d354d8b 30789 selected_arch = *legacy_cpu;
404ff6b5 30790 }
4d354d8b
TP
30791 else if (mcpu_cpu_opt)
30792 {
30793 selected_arch = *mcpu_cpu_opt;
30794 selected_ext = *mcpu_ext_opt;
30795 }
30796 else if (march_cpu_opt)
c168ce07 30797 {
4d354d8b
TP
30798 selected_arch = *march_cpu_opt;
30799 selected_ext = *march_ext_opt;
c168ce07 30800 }
4d354d8b 30801 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 30802
e74cfd16 30803 if (legacy_fpu)
c19d1205 30804 {
e74cfd16 30805 if (mfpu_opt)
c19d1205 30806 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 30807
4d354d8b 30808 selected_fpu = *legacy_fpu;
03b1477f 30809 }
4d354d8b
TP
30810 else if (mfpu_opt)
30811 selected_fpu = *mfpu_opt;
30812 else
03b1477f 30813 {
45eb4c1b
NS
30814#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30815 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
30816 /* Some environments specify a default FPU. If they don't, infer it
30817 from the processor. */
e74cfd16 30818 if (mcpu_fpu_opt)
4d354d8b 30819 selected_fpu = *mcpu_fpu_opt;
e7da50fa 30820 else if (march_fpu_opt)
4d354d8b 30821 selected_fpu = *march_fpu_opt;
39c2da32 30822#else
4d354d8b 30823 selected_fpu = fpu_default;
39c2da32 30824#endif
03b1477f
RE
30825 }
30826
4d354d8b 30827 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 30828 {
4d354d8b
TP
30829 if (!no_cpu_selected ())
30830 selected_fpu = fpu_default;
03b1477f 30831 else
4d354d8b 30832 selected_fpu = fpu_arch_fpa;
03b1477f
RE
30833 }
30834
ee065d83 30835#ifdef CPU_DEFAULT
4d354d8b 30836 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 30837 {
4d354d8b
TP
30838 selected_arch = cpu_default;
30839 selected_cpu = selected_arch;
ee065d83 30840 }
4d354d8b 30841 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 30842#else
4d354d8b
TP
30843 /* Autodection of feature mode: allow all features in cpu_variant but leave
30844 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30845 after all instruction have been processed and we can decide what CPU
30846 should be selected. */
30847 if (ARM_FEATURE_ZERO (selected_arch))
30848 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 30849 else
4d354d8b 30850 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 30851#endif
03b1477f 30852
3e9e4fcf
JB
30853 autoselect_thumb_from_cpu_variant ();
30854
e74cfd16 30855 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 30856
f17c130b 30857#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 30858 {
7cc69913
NC
30859 unsigned int flags = 0;
30860
30861#if defined OBJ_ELF
30862 flags = meabi_flags;
d507cf36
PB
30863
30864 switch (meabi_flags)
33a392fb 30865 {
d507cf36 30866 case EF_ARM_EABI_UNKNOWN:
7cc69913 30867#endif
d507cf36
PB
30868 /* Set the flags in the private structure. */
30869 if (uses_apcs_26) flags |= F_APCS26;
30870 if (support_interwork) flags |= F_INTERWORK;
30871 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 30872 if (pic_code) flags |= F_PIC;
e74cfd16 30873 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
30874 flags |= F_SOFT_FLOAT;
30875
d507cf36
PB
30876 switch (mfloat_abi_opt)
30877 {
30878 case ARM_FLOAT_ABI_SOFT:
30879 case ARM_FLOAT_ABI_SOFTFP:
30880 flags |= F_SOFT_FLOAT;
30881 break;
33a392fb 30882
d507cf36
PB
30883 case ARM_FLOAT_ABI_HARD:
30884 if (flags & F_SOFT_FLOAT)
30885 as_bad (_("hard-float conflicts with specified fpu"));
30886 break;
30887 }
03b1477f 30888
e74cfd16
PB
30889 /* Using pure-endian doubles (even if soft-float). */
30890 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 30891 flags |= F_VFP_FLOAT;
f17c130b 30892
fde78edd 30893#if defined OBJ_ELF
e74cfd16 30894 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 30895 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
30896 break;
30897
8cb51566 30898 case EF_ARM_EABI_VER4:
3a4a14e9 30899 case EF_ARM_EABI_VER5:
c19d1205 30900 /* No additional flags to set. */
d507cf36
PB
30901 break;
30902
30903 default:
30904 abort ();
30905 }
7cc69913 30906#endif
b99bd4ef
NC
30907 bfd_set_private_flags (stdoutput, flags);
30908
30909 /* We have run out flags in the COFF header to encode the
30910 status of ATPCS support, so instead we create a dummy,
c19d1205 30911 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
30912 if (atpcs)
30913 {
30914 asection * sec;
30915
30916 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30917
30918 if (sec != NULL)
30919 {
fd361982
AM
30920 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30921 bfd_set_section_size (sec, 0);
b99bd4ef
NC
30922 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30923 }
30924 }
7cc69913 30925 }
f17c130b 30926#endif
b99bd4ef
NC
30927
30928 /* Record the CPU type as well. */
2d447fca
JM
30929 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30930 mach = bfd_mach_arm_iWMMXt2;
30931 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 30932 mach = bfd_mach_arm_iWMMXt;
e74cfd16 30933 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 30934 mach = bfd_mach_arm_XScale;
e74cfd16 30935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 30936 mach = bfd_mach_arm_ep9312;
e74cfd16 30937 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 30938 mach = bfd_mach_arm_5TE;
e74cfd16 30939 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 30940 {
e74cfd16 30941 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30942 mach = bfd_mach_arm_5T;
30943 else
30944 mach = bfd_mach_arm_5;
30945 }
e74cfd16 30946 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 30947 {
e74cfd16 30948 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
30949 mach = bfd_mach_arm_4T;
30950 else
30951 mach = bfd_mach_arm_4;
30952 }
e74cfd16 30953 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 30954 mach = bfd_mach_arm_3M;
e74cfd16
PB
30955 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30956 mach = bfd_mach_arm_3;
30957 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30958 mach = bfd_mach_arm_2a;
30959 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30960 mach = bfd_mach_arm_2;
30961 else
30962 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
30963
30964 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30965}
30966
c19d1205 30967/* Command line processing. */
b99bd4ef 30968
c19d1205
ZW
30969/* md_parse_option
30970 Invocation line includes a switch not recognized by the base assembler.
30971 See if it's a processor-specific option.
b99bd4ef 30972
c19d1205
ZW
30973 This routine is somewhat complicated by the need for backwards
30974 compatibility (since older releases of gcc can't be changed).
30975 The new options try to make the interface as compatible as
30976 possible with GCC.
b99bd4ef 30977
c19d1205 30978 New options (supported) are:
b99bd4ef 30979
c19d1205
ZW
30980 -mcpu=<cpu name> Assemble for selected processor
30981 -march=<architecture name> Assemble for selected architecture
30982 -mfpu=<fpu architecture> Assemble for selected FPU.
30983 -EB/-mbig-endian Big-endian
30984 -EL/-mlittle-endian Little-endian
30985 -k Generate PIC code
30986 -mthumb Start in Thumb mode
30987 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 30988
278df34e 30989 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 30990 -m[no-]warn-syms Warn when symbols match instructions
267bf995 30991
c19d1205 30992 For now we will also provide support for:
b99bd4ef 30993
c19d1205
ZW
30994 -mapcs-32 32-bit Program counter
30995 -mapcs-26 26-bit Program counter
30996 -macps-float Floats passed in FP registers
30997 -mapcs-reentrant Reentrant code
30998 -matpcs
30999 (sometime these will probably be replaced with -mapcs=<list of options>
31000 and -matpcs=<list of options>)
b99bd4ef 31001
c19d1205
ZW
31002 The remaining options are only supported for back-wards compatibility.
31003 Cpu variants, the arm part is optional:
31004 -m[arm]1 Currently not supported.
31005 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
31006 -m[arm]3 Arm 3 processor
31007 -m[arm]6[xx], Arm 6 processors
31008 -m[arm]7[xx][t][[d]m] Arm 7 processors
31009 -m[arm]8[10] Arm 8 processors
31010 -m[arm]9[20][tdmi] Arm 9 processors
31011 -mstrongarm[110[0]] StrongARM processors
31012 -mxscale XScale processors
31013 -m[arm]v[2345[t[e]]] Arm architectures
31014 -mall All (except the ARM1)
31015 FP variants:
31016 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
31017 -mfpe-old (No float load/store multiples)
31018 -mvfpxd VFP Single precision
31019 -mvfp All VFP
31020 -mno-fpu Disable all floating point instructions
b99bd4ef 31021
c19d1205
ZW
31022 The following CPU names are recognized:
31023 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31024 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31025 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31026 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31027 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31028 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31029 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 31030
c19d1205 31031 */
b99bd4ef 31032
c19d1205 31033const char * md_shortopts = "m:k";
b99bd4ef 31034
c19d1205
ZW
31035#ifdef ARM_BI_ENDIAN
31036#define OPTION_EB (OPTION_MD_BASE + 0)
31037#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 31038#else
c19d1205
ZW
31039#if TARGET_BYTES_BIG_ENDIAN
31040#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 31041#else
c19d1205
ZW
31042#define OPTION_EL (OPTION_MD_BASE + 1)
31043#endif
b99bd4ef 31044#endif
845b51d6 31045#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
18a20338 31046#define OPTION_FDPIC (OPTION_MD_BASE + 3)
b99bd4ef 31047
c19d1205 31048struct option md_longopts[] =
b99bd4ef 31049{
c19d1205
ZW
31050#ifdef OPTION_EB
31051 {"EB", no_argument, NULL, OPTION_EB},
31052#endif
31053#ifdef OPTION_EL
31054 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 31055#endif
845b51d6 31056 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
18a20338
CL
31057#ifdef OBJ_ELF
31058 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31059#endif
c19d1205
ZW
31060 {NULL, no_argument, NULL, 0}
31061};
b99bd4ef 31062
c19d1205 31063size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 31064
c19d1205 31065struct arm_option_table
b99bd4ef 31066{
0198d5e6
TC
31067 const char * option; /* Option name to match. */
31068 const char * help; /* Help information. */
31069 int * var; /* Variable to change. */
31070 int value; /* What to change it to. */
31071 const char * deprecated; /* If non-null, print this message. */
c19d1205 31072};
b99bd4ef 31073
c19d1205
ZW
31074struct arm_option_table arm_opts[] =
31075{
31076 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31077 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31078 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31079 &support_interwork, 1, NULL},
31080 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31081 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31082 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31083 1, NULL},
31084 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31085 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31086 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31087 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31088 NULL},
b99bd4ef 31089
c19d1205
ZW
31090 /* These are recognized by the assembler, but have no affect on code. */
31091 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31092 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
31093
31094 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31095 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31096 &warn_on_deprecated, 0, NULL},
24f19ccb
AV
31097
31098 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31099 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31100 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31101
8b2d793c
NC
31102 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31103 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
31104 {NULL, NULL, NULL, 0, NULL}
31105};
31106
31107struct arm_legacy_option_table
31108{
0198d5e6
TC
31109 const char * option; /* Option name to match. */
31110 const arm_feature_set ** var; /* Variable to change. */
31111 const arm_feature_set value; /* What to change it to. */
31112 const char * deprecated; /* If non-null, print this message. */
e74cfd16 31113};
b99bd4ef 31114
e74cfd16
PB
31115const struct arm_legacy_option_table arm_legacy_opts[] =
31116{
c19d1205
ZW
31117 /* DON'T add any new processors to this list -- we want the whole list
31118 to go away... Add them to the processors table instead. */
e74cfd16
PB
31119 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31120 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31121 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31122 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31123 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31124 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31125 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31126 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31127 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31128 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31129 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31130 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31131 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31132 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31133 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31134 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31135 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31136 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31137 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31138 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31139 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31140 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31141 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31142 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31143 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31144 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31145 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31146 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31147 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31148 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31149 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31150 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31151 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31152 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31153 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31154 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31155 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31156 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31157 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31158 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31159 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31160 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31161 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31162 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31163 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31164 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31165 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31166 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31167 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31168 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31169 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31170 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31171 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31172 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31173 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31174 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31175 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31176 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31177 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31178 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31179 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31180 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31181 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31182 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31183 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31184 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31185 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31186 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31187 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31188 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31189 N_("use -mcpu=strongarm110")},
e74cfd16 31190 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31191 N_("use -mcpu=strongarm1100")},
e74cfd16 31192 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 31193 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
31194 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31195 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31196 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 31197
c19d1205 31198 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
31199 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31200 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31201 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31202 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31203 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31204 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31205 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31206 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31207 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31208 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31209 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31210 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31211 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31212 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31213 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31214 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31215 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31216 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 31217
c19d1205 31218 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
31219 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31220 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31221 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31222 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 31223 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 31224
e74cfd16 31225 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 31226};
7ed4c4c5 31227
c19d1205 31228struct arm_cpu_option_table
7ed4c4c5 31229{
0198d5e6
TC
31230 const char * name;
31231 size_t name_len;
31232 const arm_feature_set value;
31233 const arm_feature_set ext;
c19d1205
ZW
31234 /* For some CPUs we assume an FPU unless the user explicitly sets
31235 -mfpu=... */
0198d5e6 31236 const arm_feature_set default_fpu;
ee065d83
PB
31237 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31238 case. */
0198d5e6 31239 const char * canonical_name;
c19d1205 31240};
7ed4c4c5 31241
c19d1205
ZW
31242/* This list should, at a minimum, contain all the cpu names
31243 recognized by GCC. */
996b5569 31244#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 31245
e74cfd16 31246static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 31247{
996b5569
TP
31248 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31249 ARM_ARCH_NONE,
31250 FPU_ARCH_FPA),
31251 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31252 ARM_ARCH_NONE,
31253 FPU_ARCH_FPA),
31254 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31255 ARM_ARCH_NONE,
31256 FPU_ARCH_FPA),
31257 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31258 ARM_ARCH_NONE,
31259 FPU_ARCH_FPA),
31260 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31261 ARM_ARCH_NONE,
31262 FPU_ARCH_FPA),
31263 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31264 ARM_ARCH_NONE,
31265 FPU_ARCH_FPA),
31266 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31267 ARM_ARCH_NONE,
31268 FPU_ARCH_FPA),
31269 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31270 ARM_ARCH_NONE,
31271 FPU_ARCH_FPA),
31272 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31273 ARM_ARCH_NONE,
31274 FPU_ARCH_FPA),
31275 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31276 ARM_ARCH_NONE,
31277 FPU_ARCH_FPA),
31278 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31279 ARM_ARCH_NONE,
31280 FPU_ARCH_FPA),
31281 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31282 ARM_ARCH_NONE,
31283 FPU_ARCH_FPA),
31284 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31285 ARM_ARCH_NONE,
31286 FPU_ARCH_FPA),
31287 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31288 ARM_ARCH_NONE,
31289 FPU_ARCH_FPA),
31290 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31291 ARM_ARCH_NONE,
31292 FPU_ARCH_FPA),
31293 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31294 ARM_ARCH_NONE,
31295 FPU_ARCH_FPA),
31296 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31297 ARM_ARCH_NONE,
31298 FPU_ARCH_FPA),
31299 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31300 ARM_ARCH_NONE,
31301 FPU_ARCH_FPA),
31302 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31303 ARM_ARCH_NONE,
31304 FPU_ARCH_FPA),
31305 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31306 ARM_ARCH_NONE,
31307 FPU_ARCH_FPA),
31308 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31309 ARM_ARCH_NONE,
31310 FPU_ARCH_FPA),
31311 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31312 ARM_ARCH_NONE,
31313 FPU_ARCH_FPA),
31314 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31315 ARM_ARCH_NONE,
31316 FPU_ARCH_FPA),
31317 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31318 ARM_ARCH_NONE,
31319 FPU_ARCH_FPA),
31320 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31321 ARM_ARCH_NONE,
31322 FPU_ARCH_FPA),
31323 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31324 ARM_ARCH_NONE,
31325 FPU_ARCH_FPA),
31326 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31327 ARM_ARCH_NONE,
31328 FPU_ARCH_FPA),
31329 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31330 ARM_ARCH_NONE,
31331 FPU_ARCH_FPA),
31332 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31333 ARM_ARCH_NONE,
31334 FPU_ARCH_FPA),
31335 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31336 ARM_ARCH_NONE,
31337 FPU_ARCH_FPA),
31338 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31339 ARM_ARCH_NONE,
31340 FPU_ARCH_FPA),
31341 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31342 ARM_ARCH_NONE,
31343 FPU_ARCH_FPA),
31344 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31345 ARM_ARCH_NONE,
31346 FPU_ARCH_FPA),
31347 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31348 ARM_ARCH_NONE,
31349 FPU_ARCH_FPA),
31350 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31351 ARM_ARCH_NONE,
31352 FPU_ARCH_FPA),
31353 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31354 ARM_ARCH_NONE,
31355 FPU_ARCH_FPA),
31356 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31357 ARM_ARCH_NONE,
31358 FPU_ARCH_FPA),
31359 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31360 ARM_ARCH_NONE,
31361 FPU_ARCH_FPA),
31362 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31363 ARM_ARCH_NONE,
31364 FPU_ARCH_FPA),
31365 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31366 ARM_ARCH_NONE,
31367 FPU_ARCH_FPA),
31368 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31369 ARM_ARCH_NONE,
31370 FPU_ARCH_FPA),
31371 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31372 ARM_ARCH_NONE,
31373 FPU_ARCH_FPA),
31374 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31375 ARM_ARCH_NONE,
31376 FPU_ARCH_FPA),
31377 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31378 ARM_ARCH_NONE,
31379 FPU_ARCH_FPA),
31380 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31381 ARM_ARCH_NONE,
31382 FPU_ARCH_FPA),
31383 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31384 ARM_ARCH_NONE,
31385 FPU_ARCH_FPA),
31386
c19d1205
ZW
31387 /* For V5 or later processors we default to using VFP; but the user
31388 should really set the FPU type explicitly. */
996b5569
TP
31389 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31390 ARM_ARCH_NONE,
31391 FPU_ARCH_VFP_V2),
31392 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31393 ARM_ARCH_NONE,
31394 FPU_ARCH_VFP_V2),
31395 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31396 ARM_ARCH_NONE,
31397 FPU_ARCH_VFP_V2),
31398 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31399 ARM_ARCH_NONE,
31400 FPU_ARCH_VFP_V2),
31401 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31402 ARM_ARCH_NONE,
31403 FPU_ARCH_VFP_V2),
31404 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31405 ARM_ARCH_NONE,
31406 FPU_ARCH_VFP_V2),
31407 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31408 ARM_ARCH_NONE,
31409 FPU_ARCH_VFP_V2),
31410 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31411 ARM_ARCH_NONE,
31412 FPU_ARCH_VFP_V2),
31413 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31414 ARM_ARCH_NONE,
31415 FPU_ARCH_VFP_V2),
31416 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31417 ARM_ARCH_NONE,
31418 FPU_ARCH_VFP_V2),
31419 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31420 ARM_ARCH_NONE,
31421 FPU_ARCH_VFP_V2),
31422 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31423 ARM_ARCH_NONE,
31424 FPU_ARCH_VFP_V2),
31425 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31426 ARM_ARCH_NONE,
31427 FPU_ARCH_VFP_V1),
31428 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31429 ARM_ARCH_NONE,
31430 FPU_ARCH_VFP_V1),
31431 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31432 ARM_ARCH_NONE,
31433 FPU_ARCH_VFP_V2),
31434 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31435 ARM_ARCH_NONE,
31436 FPU_ARCH_VFP_V2),
31437 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31438 ARM_ARCH_NONE,
31439 FPU_ARCH_VFP_V1),
31440 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31441 ARM_ARCH_NONE,
31442 FPU_ARCH_VFP_V2),
31443 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31444 ARM_ARCH_NONE,
31445 FPU_ARCH_VFP_V2),
31446 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31447 ARM_ARCH_NONE,
31448 FPU_ARCH_VFP_V2),
31449 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31450 ARM_ARCH_NONE,
31451 FPU_ARCH_VFP_V2),
31452 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31453 ARM_ARCH_NONE,
31454 FPU_ARCH_VFP_V2),
31455 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31456 ARM_ARCH_NONE,
31457 FPU_ARCH_VFP_V2),
31458 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31459 ARM_ARCH_NONE,
31460 FPU_ARCH_VFP_V2),
31461 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31462 ARM_ARCH_NONE,
31463 FPU_ARCH_VFP_V2),
31464 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31465 ARM_ARCH_NONE,
31466 FPU_ARCH_VFP_V2),
31467 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31468 ARM_ARCH_NONE,
31469 FPU_NONE),
31470 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31471 ARM_ARCH_NONE,
31472 FPU_NONE),
31473 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31474 ARM_ARCH_NONE,
31475 FPU_ARCH_VFP_V2),
31476 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31477 ARM_ARCH_NONE,
31478 FPU_ARCH_VFP_V2),
31479 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31480 ARM_ARCH_NONE,
31481 FPU_ARCH_VFP_V2),
31482 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31483 ARM_ARCH_NONE,
31484 FPU_NONE),
31485 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31486 ARM_ARCH_NONE,
31487 FPU_NONE),
31488 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31489 ARM_ARCH_NONE,
31490 FPU_ARCH_VFP_V2),
31491 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31492 ARM_ARCH_NONE,
31493 FPU_NONE),
31494 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31495 ARM_ARCH_NONE,
31496 FPU_ARCH_VFP_V2),
31497 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31498 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31499 FPU_NONE),
31500 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31501 ARM_ARCH_NONE,
31502 FPU_ARCH_NEON_VFP_V4),
31503 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31504 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31505 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31506 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31507 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31508 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31509 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31510 ARM_ARCH_NONE,
31511 FPU_ARCH_NEON_VFP_V4),
31512 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31513 ARM_ARCH_NONE,
31514 FPU_ARCH_NEON_VFP_V4),
31515 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31516 ARM_ARCH_NONE,
31517 FPU_ARCH_NEON_VFP_V4),
31518 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
8b301fbb 31519 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31520 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31521 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
8b301fbb 31522 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31523 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31524 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
8b301fbb 31525 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31526 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31527 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31528 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31529 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569 31530 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
8b301fbb 31531 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31532 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31533 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
8b301fbb 31534 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31536 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
8b301fbb 31537 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31538 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
31539 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31540 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 31541 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
7ebd1359 31542 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31543 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31544 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
0535e5d7
DZ
31545 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31546 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31547 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31548 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31549 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31550 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
42c36b73
PW
31551 ARM_CPU_OPT ("cortex-a78", "Cortex-A78", ARM_ARCH_V8_2A,
31552 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31553 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31554 ARM_CPU_OPT ("cortex-a78ae", "Cortex-A78AE", ARM_ARCH_V8_2A,
31555 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31556 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
1bbda94f
PW
31557 ARM_CPU_OPT ("cortex-a78c", "Cortex-A78C", ARM_ARCH_V8_2A,
31558 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31559 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
ef8df4ca
KT
31560 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31561 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31562 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
31563 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31564 ARM_ARCH_NONE,
31565 FPU_NONE),
31566 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31567 ARM_ARCH_NONE,
31568 FPU_ARCH_VFP_V3D16),
31569 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31570 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31571 FPU_NONE),
31572 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31573 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31574 FPU_ARCH_VFP_V3D16),
31575 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31576 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31577 FPU_ARCH_VFP_V3D16),
0cda1e19 31578 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
8b301fbb 31579 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
0cda1e19 31580 FPU_ARCH_NEON_VFP_ARMV8),
0535e5d7
DZ
31581 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31582 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31583 FPU_NONE),
996b5569
TP
31584 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31585 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31586 FPU_NONE),
31587 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31588 ARM_ARCH_NONE,
31589 FPU_NONE),
31590 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31591 ARM_ARCH_NONE,
31592 FPU_NONE),
31593 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31594 ARM_ARCH_NONE,
31595 FPU_NONE),
31596 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31597 ARM_ARCH_NONE,
31598 FPU_NONE),
31599 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31600 ARM_ARCH_NONE,
31601 FPU_NONE),
31602 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31603 ARM_ARCH_NONE,
31604 FPU_NONE),
31605 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31606 ARM_ARCH_NONE,
31607 FPU_NONE),
394e9bf6 31608 ARM_CPU_OPT ("cortex-x1", "Cortex-X1", ARM_ARCH_V8_2A,
a417e439 31609 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
394e9bf6 31610 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
996b5569 31611 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
8b301fbb 31612 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569 31613 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
83f43c83
KT
31614 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31615 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31616 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
f3034e25
AC
31617 ARM_CPU_OPT ("neoverse-n2", "Neoverse N2", ARM_ARCH_V8_5A,
31618 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31619 | ARM_EXT2_BF16
31620 | ARM_EXT2_I8MM),
31621 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
6eee0315 31622 ARM_CPU_OPT ("neoverse-v1", "Neoverse V1", ARM_ARCH_V8_4A,
9bede61c
AC
31623 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31624 | ARM_EXT2_BF16
31625 | ARM_EXT2_I8MM),
6eee0315 31626 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
c19d1205 31627 /* ??? XSCALE is really an architecture. */
996b5569
TP
31628 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31629 ARM_ARCH_NONE,
31630 FPU_ARCH_VFP_V2),
31631
c19d1205 31632 /* ??? iwmmxt is not a processor. */
996b5569
TP
31633 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31634 ARM_ARCH_NONE,
31635 FPU_ARCH_VFP_V2),
31636 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31637 ARM_ARCH_NONE,
31638 FPU_ARCH_VFP_V2),
31639 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31640 ARM_ARCH_NONE,
31641 FPU_ARCH_VFP_V2),
31642
0198d5e6 31643 /* Maverick. */
996b5569
TP
31644 ARM_CPU_OPT ("ep9312", "ARM920T",
31645 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31646 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31647
da4339ed 31648 /* Marvell processors. */
996b5569
TP
31649 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31650 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31651 FPU_ARCH_VFP_V3D16),
31652 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31653 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31654 FPU_ARCH_NEON_VFP_V4),
da4339ed 31655
996b5569
TP
31656 /* APM X-Gene family. */
31657 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31658 ARM_ARCH_NONE,
31659 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31660 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
8b301fbb 31661 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
996b5569
TP
31662 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31663
31664 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31665};
f3bad469 31666#undef ARM_CPU_OPT
7ed4c4c5 31667
34ef62f4
AV
31668struct arm_ext_table
31669{
31670 const char * name;
31671 size_t name_len;
31672 const arm_feature_set merge;
31673 const arm_feature_set clear;
31674};
31675
c19d1205 31676struct arm_arch_option_table
7ed4c4c5 31677{
34ef62f4
AV
31678 const char * name;
31679 size_t name_len;
31680 const arm_feature_set value;
31681 const arm_feature_set default_fpu;
31682 const struct arm_ext_table * ext_table;
31683};
31684
31685/* Used to add support for +E and +noE extension. */
31686#define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31687/* Used to add support for a +E extension. */
31688#define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31689/* Used to add support for a +noE extension. */
31690#define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31691
31692#define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31693 ~0 & ~FPU_ENDIAN_PURE)
31694
31695static const struct arm_ext_table armv5te_ext_table[] =
31696{
31697 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31698 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31699};
31700
31701static const struct arm_ext_table armv7_ext_table[] =
31702{
31703 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31704 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31705};
31706
31707static const struct arm_ext_table armv7ve_ext_table[] =
31708{
31709 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31710 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31711 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31712 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31713 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31714 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31715 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31716
31717 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31718 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31719
31720 /* Aliases for +simd. */
31721 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31722
31723 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31724 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31725 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31726
31727 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31728};
31729
31730static const struct arm_ext_table armv7a_ext_table[] =
31731{
31732 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31733 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31734 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31735 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31736 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31737 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31738 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31739
31740 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31741 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31742
31743 /* Aliases for +simd. */
31744 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31745 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31746
31747 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31748 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31749
31750 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31751 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31752 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31753};
31754
31755static const struct arm_ext_table armv7r_ext_table[] =
31756{
31757 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31758 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31759 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31760 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31761 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31762 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31763 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31764 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31765 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31766};
31767
31768static const struct arm_ext_table armv7em_ext_table[] =
31769{
31770 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31771 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31772 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31773 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31774 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31775 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31776 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31777};
31778
31779static const struct arm_ext_table armv8a_ext_table[] =
31780{
8b301fbb 31781 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31782 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31783 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31784 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31785
31786 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31787 should use the +simd option to turn on FP. */
31788 ARM_REMOVE ("fp", ALL_FP),
31789 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31790 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31791 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31792};
31793
31794
31795static const struct arm_ext_table armv81a_ext_table[] =
31796{
31797 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31798 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31799 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31800
31801 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31802 should use the +simd option to turn on FP. */
31803 ARM_REMOVE ("fp", ALL_FP),
31804 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31805 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31806 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31807};
31808
31809static const struct arm_ext_table armv82a_ext_table[] =
31810{
31811 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31812 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31813 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
616ce08e
MM
31814 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31815 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31816 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31817 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31818 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31819
31820 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31821 should use the +simd option to turn on FP. */
31822 ARM_REMOVE ("fp", ALL_FP),
31823 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31824 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31825 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31826};
31827
31828static const struct arm_ext_table armv84a_ext_table[] =
31829{
31830 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31831 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31832 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31833 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31834 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31835 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31836
31837 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31838 should use the +simd option to turn on FP. */
31839 ARM_REMOVE ("fp", ALL_FP),
31840 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31841 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31842 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31843};
31844
31845static const struct arm_ext_table armv85a_ext_table[] =
31846{
31847 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31848 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
616ce08e
MM
31849 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31850 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
34ef62f4
AV
31851 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31852 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31853
31854 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31855 should use the +simd option to turn on FP. */
31856 ARM_REMOVE ("fp", ALL_FP),
31857 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31858};
31859
aab2c27d
MM
31860static const struct arm_ext_table armv86a_ext_table[] =
31861{
616ce08e 31862 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
aab2c27d
MM
31863 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31864};
31865
4934a27c
MM
31866#define CDE_EXTENSIONS \
31867 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31868 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31869 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31870 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31871 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31872 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31873 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31874 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31875
34ef62f4
AV
31876static const struct arm_ext_table armv8m_main_ext_table[] =
31877{
92169145
AV
31878 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31879 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
34ef62f4
AV
31880 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31881 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
4934a27c 31882 CDE_EXTENSIONS,
34ef62f4
AV
31883 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31884};
31885
92169145 31886
e0991585
AV
31887static const struct arm_ext_table armv8_1m_main_ext_table[] =
31888{
92169145
AV
31889 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31890 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
e0991585
AV
31891 ARM_EXT ("fp",
31892 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31893 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31894 ALL_FP),
31895 ARM_ADD ("fp.dp",
31896 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31897 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
92169145 31898 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
2da2eaf4 31899 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
a7ad558c 31900 ARM_ADD ("mve.fp",
92169145
AV
31901 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31902 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
2da2eaf4 31903 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
4934a27c 31904 CDE_EXTENSIONS,
e0991585
AV
31905 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31906};
31907
4934a27c
MM
31908#undef CDE_EXTENSIONS
31909
34ef62f4
AV
31910static const struct arm_ext_table armv8r_ext_table[] =
31911{
8b301fbb 31912 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
34ef62f4
AV
31913 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31914 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31915 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31916 ARM_REMOVE ("fp", ALL_FP),
31917 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31918 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 31919};
7ed4c4c5 31920
c19d1205
ZW
31921/* This list should, at a minimum, contain all the architecture names
31922 recognized by GCC. */
34ef62f4
AV
31923#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31924#define ARM_ARCH_OPT2(N, V, DF, ext) \
31925 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
0198d5e6 31926
e74cfd16 31927static const struct arm_arch_option_table arm_archs[] =
c19d1205 31928{
497d849d
TP
31929 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31930 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31931 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31932 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31933 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31934 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31935 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31936 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31937 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31938 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31939 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31940 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31941 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31942 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
34ef62f4
AV
31943 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31944 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31945 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31946 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31947 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31948 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31949 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31950 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31951 kept to preserve existing behaviour. */
34ef62f4
AV
31952 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31953 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31954 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31955 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31956 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
f33026a9
MW
31957 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31958 kept to preserve existing behaviour. */
34ef62f4
AV
31959 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31960 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
497d849d
TP
31961 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31962 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
34ef62f4 31963 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
c450d570
PB
31964 /* The official spelling of the ARMv7 profile variants is the dashed form.
31965 Accept the non-dashed form for compatibility with old toolchains. */
34ef62f4
AV
31966 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31967 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31968 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31969 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4
AV
31970 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31971 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
497d849d 31972 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
34ef62f4 31973 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
497d849d 31974 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
34ef62f4
AV
31975 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31976 armv8m_main),
e0991585
AV
31977 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31978 armv8_1m_main),
34ef62f4
AV
31979 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31980 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31981 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31982 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31983 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31984 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31985 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
aab2c27d 31986 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
497d849d
TP
31987 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31988 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31989 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
34ef62f4 31990 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 31991};
f3bad469 31992#undef ARM_ARCH_OPT
7ed4c4c5 31993
69133863 31994/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 31995
69133863 31996struct arm_option_extension_value_table
c19d1205 31997{
0198d5e6
TC
31998 const char * name;
31999 size_t name_len;
32000 const arm_feature_set merge_value;
32001 const arm_feature_set clear_value;
d942732e
TP
32002 /* List of architectures for which an extension is available. ARM_ARCH_NONE
32003 indicates that an extension is available for all architectures while
32004 ARM_ANY marks an empty entry. */
0198d5e6 32005 const arm_feature_set allowed_archs[2];
c19d1205 32006};
7ed4c4c5 32007
0198d5e6
TC
32008/* The following table must be in alphabetical order with a NULL last entry. */
32009
d942732e
TP
32010#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
32011#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 32012
34ef62f4
AV
32013/* DEPRECATED: Refrain from using this table to add any new extensions, instead
32014 use the context sensitive approach using arm_ext_table's. */
69133863 32015static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 32016{
8b301fbb
MI
32017 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
32018 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
823d2571 32019 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 32020 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
32021 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
32022 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
32023 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
32024 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
32025 ARM_ARCH_V8_2A),
15afaa63
TP
32026 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32027 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32028 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
32029 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
32030 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
32031 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32032 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32033 ARM_ARCH_V8_2A),
01f48020
TC
32034 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32035 | ARM_EXT2_FP16_FML),
32036 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32037 | ARM_EXT2_FP16_FML),
32038 ARM_ARCH_V8_2A),
d942732e 32039 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 32040 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
32041 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32042 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
32043 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32044 Thumb divide instruction. Due to this having the same name as the
32045 previous entry, this will be ignored when doing command-line parsing and
32046 only considered by build attribute selection code. */
32047 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32048 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32049 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 32050 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 32051 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 32052 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 32053 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 32054 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
32055 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32056 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 32057 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
32058 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32059 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
32060 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32061 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32062 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
32063 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32064 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 32065 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
dad0c3bf
SD
32066 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32067 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32068 ARM_ARCH_V8A),
4d1464f2
MW
32069 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32070 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 32071 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
32072 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32073 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 32074 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
7fadb25d
SD
32075 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32076 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32077 ARM_ARCH_V8A),
d942732e 32078 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 32079 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
32080 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32081 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
32082 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32083 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32084 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
32085 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32086 | ARM_EXT_DIV),
32087 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32088 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32089 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
32090 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32091 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 32092};
f3bad469 32093#undef ARM_EXT_OPT
69133863
MGD
32094
32095/* ISA floating-point and Advanced SIMD extensions. */
32096struct arm_option_fpu_value_table
32097{
0198d5e6
TC
32098 const char * name;
32099 const arm_feature_set value;
c19d1205 32100};
7ed4c4c5 32101
c19d1205
ZW
32102/* This list should, at a minimum, contain all the fpu names
32103 recognized by GCC. */
69133863 32104static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
32105{
32106 {"softfpa", FPU_NONE},
32107 {"fpe", FPU_ARCH_FPE},
32108 {"fpe2", FPU_ARCH_FPE},
32109 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32110 {"fpa", FPU_ARCH_FPA},
32111 {"fpa10", FPU_ARCH_FPA},
32112 {"fpa11", FPU_ARCH_FPA},
32113 {"arm7500fe", FPU_ARCH_FPA},
32114 {"softvfp", FPU_ARCH_VFP},
32115 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32116 {"vfp", FPU_ARCH_VFP_V2},
32117 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 32118 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
32119 {"vfp10", FPU_ARCH_VFP_V2},
32120 {"vfp10-r0", FPU_ARCH_VFP_V1},
32121 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
32122 {"vfpv2", FPU_ARCH_VFP_V2},
32123 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 32124 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 32125 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
32126 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32127 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32128 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
32129 {"arm1020t", FPU_ARCH_VFP_V1},
32130 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 32131 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
32132 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32133 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 32134 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 32135 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 32136 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
32137 {"vfpv4", FPU_ARCH_VFP_V4},
32138 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 32139 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
32140 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32141 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 32142 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
32143 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32144 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32145 {"crypto-neon-fp-armv8",
32146 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 32147 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
32148 {"crypto-neon-fp-armv8.1",
32149 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
32150 {NULL, ARM_ARCH_NONE}
32151};
32152
32153struct arm_option_value_table
32154{
e0471c16 32155 const char *name;
e74cfd16 32156 long value;
c19d1205 32157};
7ed4c4c5 32158
e74cfd16 32159static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
32160{
32161 {"hard", ARM_FLOAT_ABI_HARD},
32162 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32163 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 32164 {NULL, 0}
c19d1205 32165};
7ed4c4c5 32166
c19d1205 32167#ifdef OBJ_ELF
3a4a14e9 32168/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 32169static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
32170{
32171 {"gnu", EF_ARM_EABI_UNKNOWN},
32172 {"4", EF_ARM_EABI_VER4},
3a4a14e9 32173 {"5", EF_ARM_EABI_VER5},
e74cfd16 32174 {NULL, 0}
c19d1205
ZW
32175};
32176#endif
7ed4c4c5 32177
c19d1205
ZW
32178struct arm_long_option_table
32179{
0198d5e6 32180 const char * option; /* Substring to match. */
e0471c16 32181 const char * help; /* Help information. */
17b9d67d 32182 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 32183 const char * deprecated; /* If non-null, print this message. */
c19d1205 32184};
7ed4c4c5 32185
c921be7d 32186static bfd_boolean
c168ce07 32187arm_parse_extension (const char *str, const arm_feature_set *opt_set,
34ef62f4
AV
32188 arm_feature_set *ext_set,
32189 const struct arm_ext_table *ext_table)
7ed4c4c5 32190{
69133863 32191 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
32192 extensions being added before being removed. We achieve this by having
32193 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 32194 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 32195 or removing it (0) and only allowing it to change in the order
69133863
MGD
32196 -1 -> 1 -> 0. */
32197 const struct arm_option_extension_value_table * opt = NULL;
d942732e 32198 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
32199 int adding_value = -1;
32200
c19d1205 32201 while (str != NULL && *str != 0)
7ed4c4c5 32202 {
82b8a785 32203 const char *ext;
f3bad469 32204 size_t len;
7ed4c4c5 32205
c19d1205
ZW
32206 if (*str != '+')
32207 {
32208 as_bad (_("invalid architectural extension"));
c921be7d 32209 return FALSE;
c19d1205 32210 }
7ed4c4c5 32211
c19d1205
ZW
32212 str++;
32213 ext = strchr (str, '+');
7ed4c4c5 32214
c19d1205 32215 if (ext != NULL)
f3bad469 32216 len = ext - str;
c19d1205 32217 else
f3bad469 32218 len = strlen (str);
7ed4c4c5 32219
f3bad469 32220 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
32221 {
32222 if (adding_value != 0)
32223 {
32224 adding_value = 0;
32225 opt = arm_extensions;
32226 }
32227
f3bad469 32228 len -= 2;
69133863
MGD
32229 str += 2;
32230 }
f3bad469 32231 else if (len > 0)
69133863
MGD
32232 {
32233 if (adding_value == -1)
32234 {
32235 adding_value = 1;
32236 opt = arm_extensions;
32237 }
32238 else if (adding_value != 1)
32239 {
32240 as_bad (_("must specify extensions to add before specifying "
32241 "those to remove"));
32242 return FALSE;
32243 }
32244 }
32245
f3bad469 32246 if (len == 0)
c19d1205
ZW
32247 {
32248 as_bad (_("missing architectural extension"));
c921be7d 32249 return FALSE;
c19d1205 32250 }
7ed4c4c5 32251
69133863
MGD
32252 gas_assert (adding_value != -1);
32253 gas_assert (opt != NULL);
32254
34ef62f4
AV
32255 if (ext_table != NULL)
32256 {
32257 const struct arm_ext_table * ext_opt = ext_table;
32258 bfd_boolean found = FALSE;
32259 for (; ext_opt->name != NULL; ext_opt++)
32260 if (ext_opt->name_len == len
32261 && strncmp (ext_opt->name, str, len) == 0)
32262 {
32263 if (adding_value)
32264 {
32265 if (ARM_FEATURE_ZERO (ext_opt->merge))
32266 /* TODO: Option not supported. When we remove the
32267 legacy table this case should error out. */
32268 continue;
32269
32270 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32271 }
32272 else
32273 {
32274 if (ARM_FEATURE_ZERO (ext_opt->clear))
32275 /* TODO: Option not supported. When we remove the
32276 legacy table this case should error out. */
32277 continue;
32278 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32279 }
32280 found = TRUE;
32281 break;
32282 }
32283 if (found)
32284 {
32285 str = ext;
32286 continue;
32287 }
32288 }
32289
69133863
MGD
32290 /* Scan over the options table trying to find an exact match. */
32291 for (; opt->name != NULL; opt++)
f3bad469 32292 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32293 {
d942732e
TP
32294 int i, nb_allowed_archs =
32295 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 32296 /* Check we can apply the extension to this architecture. */
d942732e
TP
32297 for (i = 0; i < nb_allowed_archs; i++)
32298 {
32299 /* Empty entry. */
32300 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32301 continue;
c168ce07 32302 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
32303 break;
32304 }
32305 if (i == nb_allowed_archs)
69133863
MGD
32306 {
32307 as_bad (_("extension does not apply to the base architecture"));
32308 return FALSE;
32309 }
32310
32311 /* Add or remove the extension. */
32312 if (adding_value)
4d354d8b 32313 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 32314 else
4d354d8b 32315 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 32316
3d030cdb
TP
32317 /* Allowing Thumb division instructions for ARMv7 in autodetection
32318 rely on this break so that duplicate extensions (extensions
32319 with the same name as a previous extension in the list) are not
32320 considered for command-line parsing. */
c19d1205
ZW
32321 break;
32322 }
7ed4c4c5 32323
c19d1205
ZW
32324 if (opt->name == NULL)
32325 {
69133863
MGD
32326 /* Did we fail to find an extension because it wasn't specified in
32327 alphabetical order, or because it does not exist? */
32328
32329 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 32330 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
32331 break;
32332
32333 if (opt->name == NULL)
32334 as_bad (_("unknown architectural extension `%s'"), str);
32335 else
32336 as_bad (_("architectural extensions must be specified in "
32337 "alphabetical order"));
32338
c921be7d 32339 return FALSE;
c19d1205 32340 }
69133863
MGD
32341 else
32342 {
32343 /* We should skip the extension we've just matched the next time
32344 round. */
32345 opt++;
32346 }
7ed4c4c5 32347
c19d1205
ZW
32348 str = ext;
32349 };
7ed4c4c5 32350
c921be7d 32351 return TRUE;
c19d1205 32352}
7ed4c4c5 32353
5312fe52
BW
32354static bfd_boolean
32355arm_parse_fp16_opt (const char *str)
32356{
32357 if (strcasecmp (str, "ieee") == 0)
32358 fp16_format = ARM_FP16_FORMAT_IEEE;
32359 else if (strcasecmp (str, "alternative") == 0)
32360 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32361 else
32362 {
32363 as_bad (_("unrecognised float16 format \"%s\""), str);
32364 return FALSE;
32365 }
32366
32367 return TRUE;
32368}
32369
c921be7d 32370static bfd_boolean
17b9d67d 32371arm_parse_cpu (const char *str)
7ed4c4c5 32372{
f3bad469 32373 const struct arm_cpu_option_table *opt;
82b8a785 32374 const char *ext = strchr (str, '+');
f3bad469 32375 size_t len;
7ed4c4c5 32376
c19d1205 32377 if (ext != NULL)
f3bad469 32378 len = ext - str;
7ed4c4c5 32379 else
f3bad469 32380 len = strlen (str);
7ed4c4c5 32381
f3bad469 32382 if (len == 0)
7ed4c4c5 32383 {
c19d1205 32384 as_bad (_("missing cpu name `%s'"), str);
c921be7d 32385 return FALSE;
7ed4c4c5
NC
32386 }
32387
c19d1205 32388 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 32389 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32390 {
c168ce07 32391 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
32392 if (mcpu_ext_opt == NULL)
32393 mcpu_ext_opt = XNEW (arm_feature_set);
32394 *mcpu_ext_opt = opt->ext;
e74cfd16 32395 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 32396 if (opt->canonical_name)
ef8e6722
JW
32397 {
32398 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32399 strcpy (selected_cpu_name, opt->canonical_name);
32400 }
ee065d83
PB
32401 else
32402 {
f3bad469 32403 size_t i;
c921be7d 32404
ef8e6722
JW
32405 if (len >= sizeof selected_cpu_name)
32406 len = (sizeof selected_cpu_name) - 1;
32407
f3bad469 32408 for (i = 0; i < len; i++)
ee065d83
PB
32409 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32410 selected_cpu_name[i] = 0;
32411 }
7ed4c4c5 32412
c19d1205 32413 if (ext != NULL)
34ef62f4 32414 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
7ed4c4c5 32415
c921be7d 32416 return TRUE;
c19d1205 32417 }
7ed4c4c5 32418
c19d1205 32419 as_bad (_("unknown cpu `%s'"), str);
c921be7d 32420 return FALSE;
7ed4c4c5
NC
32421}
32422
c921be7d 32423static bfd_boolean
17b9d67d 32424arm_parse_arch (const char *str)
7ed4c4c5 32425{
e74cfd16 32426 const struct arm_arch_option_table *opt;
82b8a785 32427 const char *ext = strchr (str, '+');
f3bad469 32428 size_t len;
7ed4c4c5 32429
c19d1205 32430 if (ext != NULL)
f3bad469 32431 len = ext - str;
7ed4c4c5 32432 else
f3bad469 32433 len = strlen (str);
7ed4c4c5 32434
f3bad469 32435 if (len == 0)
7ed4c4c5 32436 {
c19d1205 32437 as_bad (_("missing architecture name `%s'"), str);
c921be7d 32438 return FALSE;
7ed4c4c5
NC
32439 }
32440
c19d1205 32441 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 32442 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 32443 {
e74cfd16 32444 march_cpu_opt = &opt->value;
4d354d8b
TP
32445 if (march_ext_opt == NULL)
32446 march_ext_opt = XNEW (arm_feature_set);
32447 *march_ext_opt = arm_arch_none;
e74cfd16 32448 march_fpu_opt = &opt->default_fpu;
e20f9590 32449 selected_ctx_ext_table = opt->ext_table;
5f4273c7 32450 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 32451
c19d1205 32452 if (ext != NULL)
34ef62f4
AV
32453 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32454 opt->ext_table);
7ed4c4c5 32455
c921be7d 32456 return TRUE;
c19d1205
ZW
32457 }
32458
32459 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 32460 return FALSE;
7ed4c4c5 32461}
eb043451 32462
c921be7d 32463static bfd_boolean
17b9d67d 32464arm_parse_fpu (const char * str)
c19d1205 32465{
69133863 32466 const struct arm_option_fpu_value_table * opt;
b99bd4ef 32467
c19d1205
ZW
32468 for (opt = arm_fpus; opt->name != NULL; opt++)
32469 if (streq (opt->name, str))
32470 {
e74cfd16 32471 mfpu_opt = &opt->value;
c921be7d 32472 return TRUE;
c19d1205 32473 }
b99bd4ef 32474
c19d1205 32475 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 32476 return FALSE;
c19d1205
ZW
32477}
32478
c921be7d 32479static bfd_boolean
17b9d67d 32480arm_parse_float_abi (const char * str)
b99bd4ef 32481{
e74cfd16 32482 const struct arm_option_value_table * opt;
b99bd4ef 32483
c19d1205
ZW
32484 for (opt = arm_float_abis; opt->name != NULL; opt++)
32485 if (streq (opt->name, str))
32486 {
32487 mfloat_abi_opt = opt->value;
c921be7d 32488 return TRUE;
c19d1205 32489 }
cc8a6dd0 32490
c19d1205 32491 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 32492 return FALSE;
c19d1205 32493}
b99bd4ef 32494
c19d1205 32495#ifdef OBJ_ELF
c921be7d 32496static bfd_boolean
17b9d67d 32497arm_parse_eabi (const char * str)
c19d1205 32498{
e74cfd16 32499 const struct arm_option_value_table *opt;
cc8a6dd0 32500
c19d1205
ZW
32501 for (opt = arm_eabis; opt->name != NULL; opt++)
32502 if (streq (opt->name, str))
32503 {
32504 meabi_flags = opt->value;
c921be7d 32505 return TRUE;
c19d1205
ZW
32506 }
32507 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 32508 return FALSE;
c19d1205
ZW
32509}
32510#endif
cc8a6dd0 32511
c921be7d 32512static bfd_boolean
17b9d67d 32513arm_parse_it_mode (const char * str)
e07e6e58 32514{
c921be7d 32515 bfd_boolean ret = TRUE;
e07e6e58
NC
32516
32517 if (streq ("arm", str))
32518 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32519 else if (streq ("thumb", str))
32520 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32521 else if (streq ("always", str))
32522 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32523 else if (streq ("never", str))
32524 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32525 else
32526 {
32527 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 32528 "arm, thumb, always, or never."), str);
c921be7d 32529 ret = FALSE;
e07e6e58
NC
32530 }
32531
32532 return ret;
32533}
32534
2e6976a8 32535static bfd_boolean
17b9d67d 32536arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
32537{
32538 codecomposer_syntax = TRUE;
32539 arm_comment_chars[0] = ';';
32540 arm_line_separator_chars[0] = 0;
32541 return TRUE;
32542}
32543
c19d1205
ZW
32544struct arm_long_option_table arm_long_opts[] =
32545{
32546 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32547 arm_parse_cpu, NULL},
32548 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32549 arm_parse_arch, NULL},
32550 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32551 arm_parse_fpu, NULL},
32552 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32553 arm_parse_float_abi, NULL},
32554#ifdef OBJ_ELF
7fac0536 32555 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
32556 arm_parse_eabi, NULL},
32557#endif
e07e6e58
NC
32558 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32559 arm_parse_it_mode, NULL},
2e6976a8
DG
32560 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32561 arm_ccs_mode, NULL},
5312fe52
BW
32562 {"mfp16-format=",
32563 N_("[ieee|alternative]\n\
32564 set the encoding for half precision floating point "
32565 "numbers to IEEE\n\
32566 or Arm alternative format."),
32567 arm_parse_fp16_opt, NULL },
c19d1205
ZW
32568 {NULL, NULL, 0, NULL}
32569};
cc8a6dd0 32570
c19d1205 32571int
17b9d67d 32572md_parse_option (int c, const char * arg)
c19d1205
ZW
32573{
32574 struct arm_option_table *opt;
e74cfd16 32575 const struct arm_legacy_option_table *fopt;
c19d1205 32576 struct arm_long_option_table *lopt;
b99bd4ef 32577
c19d1205 32578 switch (c)
b99bd4ef 32579 {
c19d1205
ZW
32580#ifdef OPTION_EB
32581 case OPTION_EB:
32582 target_big_endian = 1;
32583 break;
32584#endif
cc8a6dd0 32585
c19d1205
ZW
32586#ifdef OPTION_EL
32587 case OPTION_EL:
32588 target_big_endian = 0;
32589 break;
32590#endif
b99bd4ef 32591
845b51d6
PB
32592 case OPTION_FIX_V4BX:
32593 fix_v4bx = TRUE;
32594 break;
32595
18a20338
CL
32596#ifdef OBJ_ELF
32597 case OPTION_FDPIC:
32598 arm_fdpic = TRUE;
32599 break;
32600#endif /* OBJ_ELF */
32601
c19d1205
ZW
32602 case 'a':
32603 /* Listing option. Just ignore these, we don't support additional
32604 ones. */
32605 return 0;
b99bd4ef 32606
c19d1205
ZW
32607 default:
32608 for (opt = arm_opts; opt->option != NULL; opt++)
32609 {
32610 if (c == opt->option[0]
32611 && ((arg == NULL && opt->option[1] == 0)
32612 || streq (arg, opt->option + 1)))
32613 {
c19d1205 32614 /* If the option is deprecated, tell the user. */
278df34e 32615 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
32616 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32617 arg ? arg : "", _(opt->deprecated));
b99bd4ef 32618
c19d1205
ZW
32619 if (opt->var != NULL)
32620 *opt->var = opt->value;
cc8a6dd0 32621
c19d1205
ZW
32622 return 1;
32623 }
32624 }
b99bd4ef 32625
e74cfd16
PB
32626 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32627 {
32628 if (c == fopt->option[0]
32629 && ((arg == NULL && fopt->option[1] == 0)
32630 || streq (arg, fopt->option + 1)))
32631 {
e74cfd16 32632 /* If the option is deprecated, tell the user. */
278df34e 32633 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
32634 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32635 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
32636
32637 if (fopt->var != NULL)
32638 *fopt->var = &fopt->value;
32639
32640 return 1;
32641 }
32642 }
32643
c19d1205
ZW
32644 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32645 {
32646 /* These options are expected to have an argument. */
32647 if (c == lopt->option[0]
32648 && arg != NULL
32649 && strncmp (arg, lopt->option + 1,
32650 strlen (lopt->option + 1)) == 0)
32651 {
c19d1205 32652 /* If the option is deprecated, tell the user. */
278df34e 32653 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
32654 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32655 _(lopt->deprecated));
b99bd4ef 32656
c19d1205
ZW
32657 /* Call the sup-option parser. */
32658 return lopt->func (arg + strlen (lopt->option) - 1);
32659 }
32660 }
a737bd4d 32661
c19d1205
ZW
32662 return 0;
32663 }
a394c00f 32664
c19d1205
ZW
32665 return 1;
32666}
a394c00f 32667
c19d1205
ZW
32668void
32669md_show_usage (FILE * fp)
a394c00f 32670{
c19d1205
ZW
32671 struct arm_option_table *opt;
32672 struct arm_long_option_table *lopt;
a394c00f 32673
c19d1205 32674 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 32675
c19d1205
ZW
32676 for (opt = arm_opts; opt->option != NULL; opt++)
32677 if (opt->help != NULL)
32678 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 32679
c19d1205
ZW
32680 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32681 if (lopt->help != NULL)
32682 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 32683
c19d1205
ZW
32684#ifdef OPTION_EB
32685 fprintf (fp, _("\
32686 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
32687#endif
32688
c19d1205
ZW
32689#ifdef OPTION_EL
32690 fprintf (fp, _("\
32691 -EL assemble code for a little-endian cpu\n"));
a737bd4d 32692#endif
845b51d6
PB
32693
32694 fprintf (fp, _("\
32695 --fix-v4bx Allow BX in ARMv4 code\n"));
18a20338
CL
32696
32697#ifdef OBJ_ELF
32698 fprintf (fp, _("\
32699 --fdpic generate an FDPIC object file\n"));
32700#endif /* OBJ_ELF */
c19d1205 32701}
ee065d83 32702
ee065d83 32703#ifdef OBJ_ELF
0198d5e6 32704
62b3e311
PB
32705typedef struct
32706{
32707 int val;
32708 arm_feature_set flags;
32709} cpu_arch_ver_table;
32710
2c6b98ea
TP
32711/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32712 chronologically for architectures, with an exception for ARMv6-M and
32713 ARMv6S-M due to legacy reasons. No new architecture should have a
32714 special case. This allows for build attribute selection results to be
32715 stable when new architectures are added. */
62b3e311
PB
32716static const cpu_arch_ver_table cpu_arch_ver[] =
32717{
031254f2
AV
32718 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32719 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32720 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32721 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32722 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32723 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32724 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32725 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32726 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32727 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32728 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32729 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32730 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32731 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32732 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32733 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32734 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32735 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32736 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32737 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32738 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32739 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32740 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32741 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
2c6b98ea
TP
32742
32743 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32744 always selected build attributes to match those of ARMv6-M
32745 (resp. ARMv6S-M). However, due to these architectures being a strict
32746 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32747 would be selected when fully respecting chronology of architectures.
32748 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32749 move them before ARMv7 architectures. */
031254f2
AV
32750 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32751 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32752
32753 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32754 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32755 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32756 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32757 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32758 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32759 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32760 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32761 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32762 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32763 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32764 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32765 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32766 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32767 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32768 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
aab2c27d
MM
32769 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32770 {-1, ARM_ARCH_NONE}
62b3e311
PB
32771};
32772
ee3c0378 32773/* Set an attribute if it has not already been set by the user. */
0198d5e6 32774
ee3c0378
AS
32775static void
32776aeabi_set_attribute_int (int tag, int value)
32777{
32778 if (tag < 1
32779 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32780 || !attributes_set_explicitly[tag])
32781 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32782}
32783
32784static void
32785aeabi_set_attribute_string (int tag, const char *value)
32786{
32787 if (tag < 1
32788 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32789 || !attributes_set_explicitly[tag])
32790 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32791}
32792
2c6b98ea
TP
32793/* Return whether features in the *NEEDED feature set are available via
32794 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 32795
2c6b98ea
TP
32796static bfd_boolean
32797have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32798 const arm_feature_set *needed)
32799{
32800 int i, nb_allowed_archs;
32801 arm_feature_set ext_fset;
32802 const struct arm_option_extension_value_table *opt;
32803
32804 ext_fset = arm_arch_none;
32805 for (opt = arm_extensions; opt->name != NULL; opt++)
32806 {
32807 /* Extension does not provide any feature we need. */
32808 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32809 continue;
32810
32811 nb_allowed_archs =
32812 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32813 for (i = 0; i < nb_allowed_archs; i++)
32814 {
32815 /* Empty entry. */
32816 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32817 break;
32818
32819 /* Extension is available, add it. */
32820 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32821 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32822 }
32823 }
32824
32825 /* Can we enable all features in *needed? */
32826 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32827}
32828
32829/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32830 a given architecture feature set *ARCH_EXT_FSET including extension feature
32831 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32832 - if true, check for an exact match of the architecture modulo extensions;
32833 - otherwise, select build attribute value of the first superset
32834 architecture released so that results remains stable when new architectures
32835 are added.
32836 For -march/-mcpu=all the build attribute value of the most featureful
32837 architecture is returned. Tag_CPU_arch_profile result is returned in
32838 PROFILE. */
0198d5e6 32839
2c6b98ea
TP
32840static int
32841get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32842 const arm_feature_set *ext_fset,
32843 char *profile, int exact_match)
32844{
32845 arm_feature_set arch_fset;
32846 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32847
32848 /* Select most featureful architecture with all its extensions if building
32849 for -march=all as the feature sets used to set build attributes. */
32850 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32851 {
32852 /* Force revisiting of decision for each new architecture. */
031254f2 32853 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
2c6b98ea
TP
32854 *profile = 'A';
32855 return TAG_CPU_ARCH_V8;
32856 }
32857
32858 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32859
32860 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32861 {
32862 arm_feature_set known_arch_fset;
32863
32864 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32865 if (exact_match)
32866 {
32867 /* Base architecture match user-specified architecture and
32868 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32869 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32870 {
32871 p_ver_ret = p_ver;
32872 goto found;
32873 }
32874 /* Base architecture match user-specified architecture only
32875 (eg. ARMv6-M in the same case as above). Record it in case we
32876 find a match with above condition. */
32877 else if (p_ver_ret == NULL
32878 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32879 p_ver_ret = p_ver;
32880 }
32881 else
32882 {
32883
32884 /* Architecture has all features wanted. */
32885 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32886 {
32887 arm_feature_set added_fset;
32888
32889 /* Compute features added by this architecture over the one
32890 recorded in p_ver_ret. */
32891 if (p_ver_ret != NULL)
32892 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32893 p_ver_ret->flags);
32894 /* First architecture that match incl. with extensions, or the
32895 only difference in features over the recorded match is
32896 features that were optional and are now mandatory. */
32897 if (p_ver_ret == NULL
32898 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32899 {
32900 p_ver_ret = p_ver;
32901 goto found;
32902 }
32903 }
32904 else if (p_ver_ret == NULL)
32905 {
32906 arm_feature_set needed_ext_fset;
32907
32908 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32909
32910 /* Architecture has all features needed when using some
32911 extensions. Record it and continue searching in case there
32912 exist an architecture providing all needed features without
32913 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32914 OS extension). */
32915 if (have_ext_for_needed_feat_p (&known_arch_fset,
32916 &needed_ext_fset))
32917 p_ver_ret = p_ver;
32918 }
32919 }
32920 }
32921
32922 if (p_ver_ret == NULL)
32923 return -1;
32924
dc1e8a47 32925 found:
2c6b98ea 32926 /* Tag_CPU_arch_profile. */
164446e0
AF
32927 if (!ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r)
32928 && (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32929 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32930 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32931 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))))
2c6b98ea 32932 *profile = 'A';
164446e0
AF
32933 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)
32934 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r))
2c6b98ea
TP
32935 *profile = 'R';
32936 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32937 *profile = 'M';
32938 else
32939 *profile = '\0';
32940 return p_ver_ret->val;
32941}
32942
ee065d83 32943/* Set the public EABI object attributes. */
0198d5e6 32944
c168ce07 32945static void
ee065d83
PB
32946aeabi_set_public_attributes (void)
32947{
b90d5ba0 32948 char profile = '\0';
2c6b98ea 32949 int arch = -1;
90ec0d68 32950 int virt_sec = 0;
bca38921 32951 int fp16_optional = 0;
2c6b98ea
TP
32952 int skip_exact_match = 0;
32953 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 32954
54bab281
TP
32955 /* Autodetection mode, choose the architecture based the instructions
32956 actually used. */
32957 if (no_cpu_selected ())
32958 {
32959 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 32960
54bab281
TP
32961 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32962 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 32963
54bab281
TP
32964 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32965 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 32966
54bab281 32967 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
32968 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32969 flags_ext = arm_arch_none;
32970 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32971 selected_ext = flags_ext;
54bab281
TP
32972 selected_cpu = flags;
32973 }
32974 /* Otherwise, choose the architecture based on the capabilities of the
32975 requested cpu. */
32976 else
4d354d8b
TP
32977 {
32978 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32979 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32980 flags_ext = selected_ext;
32981 flags = selected_cpu;
32982 }
32983 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 32984
ddd7f988 32985 /* Allow the user to override the reported architecture. */
4d354d8b 32986 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 32987 {
4d354d8b 32988 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 32989 flags_ext = arm_arch_none;
7a1d4c38 32990 }
2c6b98ea 32991 else
4d354d8b 32992 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
32993
32994 /* When this function is run again after relaxation has happened there is no
32995 way to determine whether an architecture or CPU was specified by the user:
32996 - selected_cpu is set above for relaxation to work;
32997 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32998 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32999 Therefore, if not in -march=all case we first try an exact match and fall
33000 back to autodetection. */
33001 if (!skip_exact_match)
33002 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
33003 if (arch == -1)
33004 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
33005 if (arch == -1)
33006 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 33007
ee065d83
PB
33008 /* Tag_CPU_name. */
33009 if (selected_cpu_name[0])
33010 {
91d6fa6a 33011 char *q;
ee065d83 33012
91d6fa6a
NC
33013 q = selected_cpu_name;
33014 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
33015 {
33016 int i;
5f4273c7 33017
91d6fa6a
NC
33018 q += 4;
33019 for (i = 0; q[i]; i++)
33020 q[i] = TOUPPER (q[i]);
ee065d83 33021 }
91d6fa6a 33022 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 33023 }
62f3b8c8 33024
ee065d83 33025 /* Tag_CPU_arch. */
ee3c0378 33026 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 33027
62b3e311 33028 /* Tag_CPU_arch_profile. */
69239280
MGD
33029 if (profile != '\0')
33030 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 33031
15afaa63 33032 /* Tag_DSP_extension. */
4d354d8b 33033 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 33034 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 33035
2c6b98ea 33036 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 33037 /* Tag_ARM_ISA_use. */
ee3c0378 33038 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 33039 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 33040 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 33041
ee065d83 33042 /* Tag_THUMB_ISA_use. */
ee3c0378 33043 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 33044 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
33045 {
33046 int thumb_isa_use;
33047
33048 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 33049 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
33050 thumb_isa_use = 3;
33051 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33052 thumb_isa_use = 2;
33053 else
33054 thumb_isa_use = 1;
33055 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33056 }
62f3b8c8 33057
ee065d83 33058 /* Tag_VFP_arch. */
a715796b
TG
33059 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33060 aeabi_set_attribute_int (Tag_VFP_arch,
33061 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33062 ? 7 : 8);
bca38921 33063 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
33064 aeabi_set_attribute_int (Tag_VFP_arch,
33065 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33066 ? 5 : 6);
33067 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
33068 {
33069 fp16_optional = 1;
33070 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33071 }
ada65aa3 33072 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
33073 {
33074 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33075 fp16_optional = 1;
33076 }
ee3c0378
AS
33077 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33078 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33079 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 33080 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 33081 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 33082
4547cb56
NC
33083 /* Tag_ABI_HardFP_use. */
33084 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33085 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33086 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33087
ee065d83 33088 /* Tag_WMMX_arch. */
ee3c0378
AS
33089 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33090 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33091 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33092 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 33093
ee3c0378 33094 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
33095 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33096 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33097 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
33098 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33099 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33100 {
33101 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33102 {
33103 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33104 }
33105 else
33106 {
33107 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33108 fp16_optional = 1;
33109 }
33110 }
fa94de6b 33111
a7ad558c
AV
33112 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33113 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33114 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33115 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33116
ee3c0378 33117 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 33118 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 33119 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 33120
69239280
MGD
33121 /* Tag_DIV_use.
33122
33123 We set Tag_DIV_use to two when integer divide instructions have been used
33124 in ARM state, or when Thumb integer divide instructions have been used,
33125 but we have no architecture profile set, nor have we any ARM instructions.
33126
4ed7ed8d
TP
33127 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33128 by the base architecture.
bca38921 33129
69239280 33130 For new architectures we will have to check these tests. */
031254f2 33131 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
4ed7ed8d
TP
33132 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33133 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
33134 aeabi_set_attribute_int (Tag_DIV_use, 0);
33135 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33136 || (profile == '\0'
33137 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33138 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 33139 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
33140
33141 /* Tag_MP_extension_use. */
33142 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33143 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
33144
33145 /* Tag Virtualization_use. */
33146 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
33147 virt_sec |= 1;
33148 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33149 virt_sec |= 2;
33150 if (virt_sec != 0)
33151 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
5312fe52
BW
33152
33153 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33154 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
ee065d83
PB
33155}
33156
c168ce07
TP
33157/* Post relaxation hook. Recompute ARM attributes now that relaxation is
33158 finished and free extension feature bits which will not be used anymore. */
0198d5e6 33159
c168ce07
TP
33160void
33161arm_md_post_relax (void)
33162{
33163 aeabi_set_public_attributes ();
4d354d8b
TP
33164 XDELETE (mcpu_ext_opt);
33165 mcpu_ext_opt = NULL;
33166 XDELETE (march_ext_opt);
33167 march_ext_opt = NULL;
c168ce07
TP
33168}
33169
104d59d1 33170/* Add the default contents for the .ARM.attributes section. */
0198d5e6 33171
ee065d83
PB
33172void
33173arm_md_end (void)
33174{
ee065d83
PB
33175 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33176 return;
33177
33178 aeabi_set_public_attributes ();
ee065d83 33179}
8463be01 33180#endif /* OBJ_ELF */
ee065d83 33181
ee065d83
PB
33182/* Parse a .cpu directive. */
33183
33184static void
33185s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33186{
e74cfd16 33187 const struct arm_cpu_option_table *opt;
ee065d83
PB
33188 char *name;
33189 char saved_char;
33190
33191 name = input_line_pointer;
5f4273c7 33192 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33193 input_line_pointer++;
33194 saved_char = *input_line_pointer;
33195 *input_line_pointer = 0;
33196
33197 /* Skip the first "all" entry. */
33198 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33199 if (streq (opt->name, name))
33200 {
4d354d8b
TP
33201 selected_arch = opt->value;
33202 selected_ext = opt->ext;
33203 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 33204 if (opt->canonical_name)
5f4273c7 33205 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
33206 else
33207 {
33208 int i;
33209 for (i = 0; opt->name[i]; i++)
33210 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 33211
ee065d83
PB
33212 selected_cpu_name[i] = 0;
33213 }
4d354d8b
TP
33214 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33215
ee065d83
PB
33216 *input_line_pointer = saved_char;
33217 demand_empty_rest_of_line ();
33218 return;
33219 }
33220 as_bad (_("unknown cpu `%s'"), name);
33221 *input_line_pointer = saved_char;
33222 ignore_rest_of_line ();
33223}
33224
ee065d83
PB
33225/* Parse a .arch directive. */
33226
33227static void
33228s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33229{
e74cfd16 33230 const struct arm_arch_option_table *opt;
ee065d83
PB
33231 char saved_char;
33232 char *name;
33233
33234 name = input_line_pointer;
5f4273c7 33235 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33236 input_line_pointer++;
33237 saved_char = *input_line_pointer;
33238 *input_line_pointer = 0;
33239
33240 /* Skip the first "all" entry. */
33241 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33242 if (streq (opt->name, name))
33243 {
4d354d8b 33244 selected_arch = opt->value;
0e7aaa72 33245 selected_ctx_ext_table = opt->ext_table;
4d354d8b
TP
33246 selected_ext = arm_arch_none;
33247 selected_cpu = selected_arch;
5f4273c7 33248 strcpy (selected_cpu_name, opt->name);
4d354d8b 33249 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33250 *input_line_pointer = saved_char;
33251 demand_empty_rest_of_line ();
33252 return;
33253 }
33254
33255 as_bad (_("unknown architecture `%s'\n"), name);
33256 *input_line_pointer = saved_char;
33257 ignore_rest_of_line ();
33258}
33259
7a1d4c38
PB
33260/* Parse a .object_arch directive. */
33261
33262static void
33263s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33264{
33265 const struct arm_arch_option_table *opt;
33266 char saved_char;
33267 char *name;
33268
33269 name = input_line_pointer;
5f4273c7 33270 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
33271 input_line_pointer++;
33272 saved_char = *input_line_pointer;
33273 *input_line_pointer = 0;
33274
33275 /* Skip the first "all" entry. */
33276 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33277 if (streq (opt->name, name))
33278 {
4d354d8b 33279 selected_object_arch = opt->value;
7a1d4c38
PB
33280 *input_line_pointer = saved_char;
33281 demand_empty_rest_of_line ();
33282 return;
33283 }
33284
33285 as_bad (_("unknown architecture `%s'\n"), name);
33286 *input_line_pointer = saved_char;
33287 ignore_rest_of_line ();
33288}
33289
69133863
MGD
33290/* Parse a .arch_extension directive. */
33291
33292static void
33293s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33294{
33295 const struct arm_option_extension_value_table *opt;
33296 char saved_char;
33297 char *name;
33298 int adding_value = 1;
33299
33300 name = input_line_pointer;
33301 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33302 input_line_pointer++;
33303 saved_char = *input_line_pointer;
33304 *input_line_pointer = 0;
33305
33306 if (strlen (name) >= 2
33307 && strncmp (name, "no", 2) == 0)
33308 {
33309 adding_value = 0;
33310 name += 2;
33311 }
33312
e20f9590
MI
33313 /* Check the context specific extension table */
33314 if (selected_ctx_ext_table)
33315 {
33316 const struct arm_ext_table * ext_opt;
33317 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33318 {
33319 if (streq (ext_opt->name, name))
33320 {
33321 if (adding_value)
33322 {
33323 if (ARM_FEATURE_ZERO (ext_opt->merge))
33324 /* TODO: Option not supported. When we remove the
33325 legacy table this case should error out. */
33326 continue;
33327 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33328 ext_opt->merge);
33329 }
33330 else
33331 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33332
33333 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33334 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33335 *input_line_pointer = saved_char;
33336 demand_empty_rest_of_line ();
33337 return;
33338 }
33339 }
33340 }
33341
69133863
MGD
33342 for (opt = arm_extensions; opt->name != NULL; opt++)
33343 if (streq (opt->name, name))
33344 {
d942732e
TP
33345 int i, nb_allowed_archs =
33346 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33347 for (i = 0; i < nb_allowed_archs; i++)
33348 {
33349 /* Empty entry. */
4d354d8b 33350 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 33351 continue;
4d354d8b 33352 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
33353 break;
33354 }
33355
33356 if (i == nb_allowed_archs)
69133863
MGD
33357 {
33358 as_bad (_("architectural extension `%s' is not allowed for the "
33359 "current base architecture"), name);
33360 break;
33361 }
33362
33363 if (adding_value)
4d354d8b 33364 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 33365 opt->merge_value);
69133863 33366 else
4d354d8b 33367 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 33368
4d354d8b
TP
33369 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33370 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
33371 *input_line_pointer = saved_char;
33372 demand_empty_rest_of_line ();
3d030cdb
TP
33373 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33374 on this return so that duplicate extensions (extensions with the
33375 same name as a previous extension in the list) are not considered
33376 for command-line parsing. */
69133863
MGD
33377 return;
33378 }
33379
33380 if (opt->name == NULL)
e673710a 33381 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
33382
33383 *input_line_pointer = saved_char;
33384 ignore_rest_of_line ();
33385}
33386
ee065d83
PB
33387/* Parse a .fpu directive. */
33388
33389static void
33390s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33391{
69133863 33392 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
33393 char saved_char;
33394 char *name;
33395
33396 name = input_line_pointer;
5f4273c7 33397 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
33398 input_line_pointer++;
33399 saved_char = *input_line_pointer;
33400 *input_line_pointer = 0;
5f4273c7 33401
ee065d83
PB
33402 for (opt = arm_fpus; opt->name != NULL; opt++)
33403 if (streq (opt->name, name))
33404 {
4d354d8b 33405 selected_fpu = opt->value;
f4399880 33406 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
4d354d8b
TP
33407#ifndef CPU_DEFAULT
33408 if (no_cpu_selected ())
33409 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33410 else
33411#endif
33412 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
33413 *input_line_pointer = saved_char;
33414 demand_empty_rest_of_line ();
33415 return;
33416 }
33417
33418 as_bad (_("unknown floating point format `%s'\n"), name);
33419 *input_line_pointer = saved_char;
33420 ignore_rest_of_line ();
33421}
ee065d83 33422
794ba86a 33423/* Copy symbol information. */
f31fef98 33424
794ba86a
DJ
33425void
33426arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33427{
33428 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33429}
e04befd0 33430
f31fef98 33431#ifdef OBJ_ELF
e04befd0
AS
33432/* Given a symbolic attribute NAME, return the proper integer value.
33433 Returns -1 if the attribute is not known. */
f31fef98 33434
e04befd0
AS
33435int
33436arm_convert_symbolic_attribute (const char *name)
33437{
f31fef98
NC
33438 static const struct
33439 {
33440 const char * name;
33441 const int tag;
33442 }
33443 attribute_table[] =
33444 {
33445 /* When you modify this table you should
33446 also modify the list in doc/c-arm.texi. */
e04befd0 33447#define T(tag) {#tag, tag}
f31fef98
NC
33448 T (Tag_CPU_raw_name),
33449 T (Tag_CPU_name),
33450 T (Tag_CPU_arch),
33451 T (Tag_CPU_arch_profile),
33452 T (Tag_ARM_ISA_use),
33453 T (Tag_THUMB_ISA_use),
75375b3e 33454 T (Tag_FP_arch),
f31fef98
NC
33455 T (Tag_VFP_arch),
33456 T (Tag_WMMX_arch),
33457 T (Tag_Advanced_SIMD_arch),
33458 T (Tag_PCS_config),
33459 T (Tag_ABI_PCS_R9_use),
33460 T (Tag_ABI_PCS_RW_data),
33461 T (Tag_ABI_PCS_RO_data),
33462 T (Tag_ABI_PCS_GOT_use),
33463 T (Tag_ABI_PCS_wchar_t),
33464 T (Tag_ABI_FP_rounding),
33465 T (Tag_ABI_FP_denormal),
33466 T (Tag_ABI_FP_exceptions),
33467 T (Tag_ABI_FP_user_exceptions),
33468 T (Tag_ABI_FP_number_model),
75375b3e 33469 T (Tag_ABI_align_needed),
f31fef98 33470 T (Tag_ABI_align8_needed),
75375b3e 33471 T (Tag_ABI_align_preserved),
f31fef98
NC
33472 T (Tag_ABI_align8_preserved),
33473 T (Tag_ABI_enum_size),
33474 T (Tag_ABI_HardFP_use),
33475 T (Tag_ABI_VFP_args),
33476 T (Tag_ABI_WMMX_args),
33477 T (Tag_ABI_optimization_goals),
33478 T (Tag_ABI_FP_optimization_goals),
33479 T (Tag_compatibility),
33480 T (Tag_CPU_unaligned_access),
75375b3e 33481 T (Tag_FP_HP_extension),
f31fef98
NC
33482 T (Tag_VFP_HP_extension),
33483 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
33484 T (Tag_MPextension_use),
33485 T (Tag_DIV_use),
f31fef98
NC
33486 T (Tag_nodefaults),
33487 T (Tag_also_compatible_with),
33488 T (Tag_conformance),
33489 T (Tag_T2EE_use),
33490 T (Tag_Virtualization_use),
15afaa63 33491 T (Tag_DSP_extension),
a7ad558c 33492 T (Tag_MVE_arch),
cd21e546 33493 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 33494#undef T
f31fef98 33495 };
e04befd0
AS
33496 unsigned int i;
33497
33498 if (name == NULL)
33499 return -1;
33500
f31fef98 33501 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 33502 if (streq (name, attribute_table[i].name))
e04befd0
AS
33503 return attribute_table[i].tag;
33504
33505 return -1;
33506}
267bf995 33507
93ef582d
NC
33508/* Apply sym value for relocations only in the case that they are for
33509 local symbols in the same segment as the fixup and you have the
33510 respective architectural feature for blx and simple switches. */
0198d5e6 33511
267bf995 33512int
93ef582d 33513arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
33514{
33515 if (fixP->fx_addsy
33516 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
33517 /* PR 17444: If the local symbol is in a different section then a reloc
33518 will always be generated for it, so applying the symbol value now
33519 will result in a double offset being stored in the relocation. */
33520 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 33521 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
33522 {
33523 switch (fixP->fx_r_type)
33524 {
33525 case BFD_RELOC_ARM_PCREL_BLX:
33526 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33527 if (ARM_IS_FUNC (fixP->fx_addsy))
33528 return 1;
33529 break;
33530
33531 case BFD_RELOC_ARM_PCREL_CALL:
33532 case BFD_RELOC_THUMB_PCREL_BLX:
33533 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 33534 return 1;
267bf995
RR
33535 break;
33536
33537 default:
33538 break;
33539 }
33540
33541 }
33542 return 0;
33543}
f31fef98 33544#endif /* OBJ_ELF */